mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 01:45:52 +08:00
feat: support detect env and sys var
This commit is contained in:
parent
0cd6e55bde
commit
d0dd99bd46
@ -28,6 +28,7 @@ import { BlockEnum } from '@/app/components/workflow/types'
|
|||||||
import {
|
import {
|
||||||
useNodesSyncDraft,
|
useNodesSyncDraft,
|
||||||
} from '@/app/components/workflow/hooks'
|
} from '@/app/components/workflow/hooks'
|
||||||
|
import useInspectVarsCrud from '@/app/components/workflow/hooks/use-inspect-vars-crud'
|
||||||
|
|
||||||
const singleRunFormParamsHooks: Record<BlockEnum, any> = {
|
const singleRunFormParamsHooks: Record<BlockEnum, any> = {
|
||||||
[BlockEnum.LLM]: useLLMSingleRunFormParams,
|
[BlockEnum.LLM]: useLLMSingleRunFormParams,
|
||||||
@ -101,6 +102,7 @@ type Params<T> = OneStepRunParams<T>
|
|||||||
const useLastRun = <T>({
|
const useLastRun = <T>({
|
||||||
...oneStepRunParams
|
...oneStepRunParams
|
||||||
}: Params<T>) => {
|
}: Params<T>) => {
|
||||||
|
const { conversationVars } = useInspectVarsCrud()
|
||||||
const blockType = oneStepRunParams.data.type
|
const blockType = oneStepRunParams.data.type
|
||||||
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
|
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
|
||||||
const {
|
const {
|
||||||
@ -167,41 +169,20 @@ const useLastRun = <T>({
|
|||||||
|
|
||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
const {
|
const {
|
||||||
getInspectVar,
|
hasSetInspectVar,
|
||||||
} = workflowStore.getState()
|
} = workflowStore.getState()
|
||||||
const getExistVarValuesInForms = (forms: FormProps[]) => {
|
const getExistVarValuesInForms = (forms: FormProps[]) => {
|
||||||
if (!forms || forms.length === 0)
|
if (!forms || forms.length === 0)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
const valuesArr = forms.map((form) => {
|
const valuesArr = forms.map((form) => {
|
||||||
const values: Record<string, any> = {}
|
const values: Record<string, boolean> = {}
|
||||||
form.inputs.forEach(({ variable }) => {
|
form.inputs.forEach(({ variable }) => {
|
||||||
// #nodeId.path1?.path2?...# => [nodeId, path1]
|
|
||||||
// TODO: conversation vars and envs
|
|
||||||
const selector = variable.slice(1, -1).split('.')
|
const selector = variable.slice(1, -1).split('.')
|
||||||
const [nodeId, varName] = selector.slice(0, 2)
|
const [nodeId, varName] = selector.slice(0, 2)
|
||||||
const inspectVarValue = getInspectVar(nodeId, varName)
|
const inspectVarValue = hasSetInspectVar(nodeId, varName, conversationVars) // also detect system var , env and conversation var
|
||||||
if (inspectVarValue !== undefined) {
|
if (inspectVarValue)
|
||||||
const subPathArr = selector.slice(2)
|
values[variable] = true
|
||||||
if (subPathArr.length > 0) {
|
|
||||||
let current = inspectVarValue.value
|
|
||||||
let invalid = false
|
|
||||||
subPathArr.forEach((subPath) => {
|
|
||||||
if (invalid)
|
|
||||||
return
|
|
||||||
|
|
||||||
if (current && typeof current === 'object' && subPath in current) {
|
|
||||||
current = current[subPath]
|
|
||||||
return
|
|
||||||
}
|
|
||||||
invalid = true
|
|
||||||
})
|
|
||||||
values[variable] = current
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
values[variable] = inspectVarValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
return values
|
return values
|
||||||
})
|
})
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import type { StateCreator } from 'zustand'
|
import type { StateCreator } from 'zustand'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
import type { NodeWithVar, VarInInspect } from '@/types/workflow'
|
import type { NodeWithVar, VarInInspect } from '@/types/workflow'
|
||||||
import type { ValueSelector } from '../../../types'
|
import { BlockEnum, type ValueSelector } from '../../../types'
|
||||||
import type { Node } from '@/app/components/workflow/types'
|
import type { Node } from '@/app/components/workflow/types'
|
||||||
|
import { isConversationVar, isENV, isSystemVar } from '../../../nodes/_base/components/variable/utils'
|
||||||
|
|
||||||
type InspectVarsState = {
|
type InspectVarsState = {
|
||||||
currentFocusNodeId: string | null
|
currentFocusNodeId: string | null
|
||||||
@ -25,6 +26,7 @@ type InspectVarsActions = {
|
|||||||
renameInspectVarName: (nodeId: string, varId: string, selector: ValueSelector) => void
|
renameInspectVarName: (nodeId: string, varId: string, selector: ValueSelector) => void
|
||||||
deleteInspectVar: (nodeId: string, varId: string) => void
|
deleteInspectVar: (nodeId: string, varId: string) => void
|
||||||
getInspectVar: (nodeId: string, name: string) => any
|
getInspectVar: (nodeId: string, name: string) => any
|
||||||
|
hasSetInspectVar: (nodeId: string, name: string, conversationVars: VarInInspect[]) => boolean
|
||||||
isInspectVarEdited: (nodeId: string, name: string) => boolean
|
isInspectVarEdited: (nodeId: string, name: string) => boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,6 +174,22 @@ export const createInspectVarsSlice: StateCreator<InspectVarsSliceShape> = (set,
|
|||||||
})?.value
|
})?.value
|
||||||
return variable
|
return variable
|
||||||
},
|
},
|
||||||
|
hasSetInspectVar: (nodeId, name, conversationVars: VarInInspect[]) => {
|
||||||
|
const isEnv = isENV([nodeId])
|
||||||
|
if (isEnv) // always have value
|
||||||
|
return true
|
||||||
|
const isSys = isSystemVar([nodeId])
|
||||||
|
if (isSys) {
|
||||||
|
const isStartNodeRun = get().nodesWithInspectVars.some((node) => {
|
||||||
|
return node.nodeType === BlockEnum.Start
|
||||||
|
})
|
||||||
|
return isStartNodeRun
|
||||||
|
}
|
||||||
|
const isChatVar = isConversationVar([nodeId])
|
||||||
|
if (isChatVar)
|
||||||
|
return conversationVars.some(varItem => varItem.selector?.[1] === name)
|
||||||
|
return get().getInspectVar(nodeId, name) !== undefined
|
||||||
|
},
|
||||||
isInspectVarEdited: (nodeId, name) => {
|
isInspectVarEdited: (nodeId, name) => {
|
||||||
const inspectVar = get().getInspectVar(nodeId, name)
|
const inspectVar = get().getInspectVar(nodeId, name)
|
||||||
if (!inspectVar)
|
if (!inspectVar)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user