mirror of
https://github.com/langgenius/dify.git
synced 2026-05-02 00:18:03 +08:00
fix: Fix workflow inspect vars to include parent nodes in subgraph mode
This commit is contained in:
@ -41,6 +41,7 @@ export const useSetWorkflowVarsWithValue = ({
|
||||
const { data: workflowTools } = useAllWorkflowTools()
|
||||
const { data: mcpTools } = useAllMCPTools()
|
||||
const dataSourceList = useStore(s => s.dataSourceList)
|
||||
const parentAvailableNodes = useStore(s => s.parentAvailableNodes) || []
|
||||
const allPluginInfoList = {
|
||||
buildInTools: buildInTools || [],
|
||||
customTools: customTools || [],
|
||||
@ -54,10 +55,17 @@ export const useSetWorkflowVarsWithValue = ({
|
||||
const { getNodes } = store.getState()
|
||||
|
||||
const nodeArr = getNodes()
|
||||
const allNodesOutputVars = toNodeOutputVars(nodeArr, false, () => true, [], [], [], passedInAllPluginInfoList || allPluginInfoList, passedInSchemaTypeDefinitions || schemaTypeDefinitions)
|
||||
const parentNodeIds = new Set(parentAvailableNodes.map(node => node.id))
|
||||
const nodeMap = new Map(nodeArr.map(node => [node.id, node]))
|
||||
parentAvailableNodes.forEach((node) => {
|
||||
if (!nodeMap.has(node.id))
|
||||
nodeMap.set(node.id, node)
|
||||
})
|
||||
const allNodes = Array.from(nodeMap.values())
|
||||
const allNodesOutputVars = toNodeOutputVars(allNodes, false, () => true, [], [], [], passedInAllPluginInfoList || allPluginInfoList, passedInSchemaTypeDefinitions || schemaTypeDefinitions)
|
||||
|
||||
const nodesKeyValue: Record<string, Node> = {}
|
||||
nodeArr.forEach((node) => {
|
||||
allNodes.forEach((node) => {
|
||||
nodesKeyValue[node.id] = node
|
||||
})
|
||||
|
||||
@ -74,8 +82,10 @@ export const useSetWorkflowVarsWithValue = ({
|
||||
return nodesKeyValue[nodeId]
|
||||
})
|
||||
|
||||
const resolvedInteractionMode = interactionMode ?? InteractionMode.Default
|
||||
const res: NodeWithVar[] = withValueNodes.map((node) => {
|
||||
const nodeId = node.id
|
||||
const isParentNode = resolvedInteractionMode === InteractionMode.Subgraph && parentNodeIds.has(nodeId)
|
||||
const varsUnderTheNode = inspectVars.filter((varItem) => {
|
||||
return varItem.selector[0] === nodeId
|
||||
})
|
||||
@ -95,12 +105,12 @@ export const useSetWorkflowVarsWithValue = ({
|
||||
}),
|
||||
isSingRunRunning: false,
|
||||
isValueFetched: false,
|
||||
isHidden: isParentNode,
|
||||
}
|
||||
return nodeWithVar
|
||||
})
|
||||
const resolvedInteractionMode = interactionMode ?? InteractionMode.Default
|
||||
const shouldApplyAlias = resolvedInteractionMode !== InteractionMode.Subgraph
|
||||
const nextNodes = shouldApplyAlias ? applyAgentSubgraphInspectVars(res, nodeArr) : res
|
||||
const nextNodes = shouldApplyAlias ? applyAgentSubgraphInspectVars(res, allNodes) : res
|
||||
setNodesWithInspectVars(nextNodes)
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ import useToolSingleRunFormParams from '@/app/components/workflow/nodes/tool/use
|
||||
import useTriggerPluginGetDataForCheckMore from '@/app/components/workflow/nodes/trigger-plugin/use-check-params'
|
||||
import useVariableAggregatorSingleRunFormParams from '@/app/components/workflow/nodes/variable-assigner/use-single-run-form-params'
|
||||
import { useStore, useWorkflowStore } from '@/app/components/workflow/store'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
import { BlockEnum, isPromptMessageContext } from '@/app/components/workflow/types'
|
||||
import { isSupportCustomRunForm } from '@/app/components/workflow/utils'
|
||||
import { VALUE_SELECTOR_DELIMITER as DELIMITER } from '@/config'
|
||||
import { useInvalidLastRun } from '@/service/use-workflow'
|
||||
@ -251,10 +251,23 @@ const useLastRun = <T>({
|
||||
if (blockType !== BlockEnum.LLM)
|
||||
return true
|
||||
const llmData = data as unknown as LLMNodeType
|
||||
const contextSelector = llmData.context?.variable_selector
|
||||
if (!Array.isArray(contextSelector) || contextSelector.length === 0) {
|
||||
Toast.notify({ type: 'error', message: t('nodes.llm.contextMissing', { ns: 'workflow' }) })
|
||||
return false
|
||||
const promptTemplate = llmData.prompt_template
|
||||
if (!Array.isArray(promptTemplate))
|
||||
return true
|
||||
const contextSelectors = promptTemplate
|
||||
.filter(isPromptMessageContext)
|
||||
.map(item => item.$context)
|
||||
.filter(selector => Array.isArray(selector) && selector.length >= 2)
|
||||
if (contextSelectors.length === 0)
|
||||
return true
|
||||
const uniqueSelectors = new Set(contextSelectors.map(selector => `${selector[0]}::${selector[1]}`))
|
||||
for (const selectorKey of uniqueSelectors) {
|
||||
const [nodeId, varName] = selectorKey.split('::')
|
||||
const inspectVarValue = hasSetInspectVar(nodeId, varName, systemVars, conversationVars)
|
||||
if (!inspectVarValue) {
|
||||
Toast.notify({ type: 'error', message: t('nodes.llm.contextMissing', { ns: 'workflow' }) })
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}, [blockType, data, t])
|
||||
|
||||
Reference in New Issue
Block a user