From 636156f5da0ed709ae2c466d0166751a69929032 Mon Sep 17 00:00:00 2001 From: zhsama Date: Wed, 28 Jan 2026 18:23:56 +0800 Subject: [PATCH] fix: Fix workflow inspect vars to include parent nodes in subgraph mode --- .../hooks/use-fetch-workflow-inspect-vars.ts | 18 +++++++++++---- .../workflow-panel/last-run/use-last-run.ts | 23 +++++++++++++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts b/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts index f56fc25aae..769db2a449 100644 --- a/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts +++ b/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts @@ -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 = {} - 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) } diff --git a/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts b/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts index 8c5e33f9a6..bc430a7779 100644 --- a/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts +++ b/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts @@ -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 = ({ 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])