mirror of
https://github.com/langgenius/dify.git
synced 2026-02-26 08:04:33 -05:00
feat(workflow): refine variable validation and scoping for workflow nodes, remove redundant End block checks
This commit is contained in:
@@ -70,14 +70,27 @@ const WorkflowVariableBlockComponent = ({
|
||||
)()
|
||||
const [localWorkflowNodesMap, setLocalWorkflowNodesMap] = useState<WorkflowNodesMap>(workflowNodesMap)
|
||||
const [localNodeOutputVars, setLocalNodeOutputVars] = useState<NodeOutPutVar[]>(nodeOutputVars || [])
|
||||
const scopedNodeOutputVars = useMemo(() => {
|
||||
if (!localNodeOutputVars.length)
|
||||
return []
|
||||
|
||||
const candidateNodeIds = [variables[0], variables[1]].filter(Boolean)
|
||||
if (!candidateNodeIds.length)
|
||||
return localNodeOutputVars
|
||||
|
||||
return localNodeOutputVars.filter(item => candidateNodeIds.includes(item.nodeId))
|
||||
}, [localNodeOutputVars, variables])
|
||||
const node = localWorkflowNodesMap![variables[isRagVar ? 1 : 0]]
|
||||
const isContextVariable = (node?.type === BlockEnum.Agent || node?.type === BlockEnum.LLM)
|
||||
&& variables[variablesLength - 1] === 'context'
|
||||
|
||||
const isException = isExceptionVariable(varName, node?.type)
|
||||
const variableValid = useMemo(() => {
|
||||
if (localNodeOutputVars.length)
|
||||
return isValueSelectorInNodeOutputVars(variables, localNodeOutputVars)
|
||||
if (localNodeOutputVars.length) {
|
||||
if (!scopedNodeOutputVars.length)
|
||||
return false
|
||||
return isValueSelectorInNodeOutputVars(variables, scopedNodeOutputVars)
|
||||
}
|
||||
|
||||
let variableValid = true
|
||||
const isEnv = isENV(variables)
|
||||
@@ -102,7 +115,7 @@ const WorkflowVariableBlockComponent = ({
|
||||
variableValid = !!node
|
||||
}
|
||||
return variableValid
|
||||
}, [variables, node, environmentVariables, conversationVariables, isRagVar, ragVariables, localNodeOutputVars])
|
||||
}, [variables, node, environmentVariables, conversationVariables, isRagVar, ragVariables, localNodeOutputVars, scopedNodeOutputVars])
|
||||
|
||||
const reactflow = useReactFlow()
|
||||
const store = useStoreApi()
|
||||
|
||||
@@ -30,7 +30,7 @@ export const useAvailableBlocks = (nodeType?: BlockEnum, inContainer?: boolean)
|
||||
return availableNodesType
|
||||
}, [availableNodesType, nodeType])
|
||||
const availableNextBlocks = useMemo(() => {
|
||||
if (!nodeType || nodeType === BlockEnum.End || nodeType === BlockEnum.LoopEnd || nodeType === BlockEnum.KnowledgeBase)
|
||||
if (!nodeType || nodeType === BlockEnum.LoopEnd || nodeType === BlockEnum.KnowledgeBase)
|
||||
return []
|
||||
|
||||
return availableNodesType
|
||||
@@ -42,7 +42,7 @@ export const useAvailableBlocks = (nodeType?: BlockEnum, inContainer?: boolean)
|
||||
availablePrevBlocks = []
|
||||
|
||||
let availableNextBlocks = availableNodesType
|
||||
if (!nodeType || nodeType === BlockEnum.End || nodeType === BlockEnum.LoopEnd || nodeType === BlockEnum.KnowledgeBase)
|
||||
if (!nodeType || nodeType === BlockEnum.LoopEnd || nodeType === BlockEnum.KnowledgeBase)
|
||||
availableNextBlocks = []
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user