From 601e888fde8e432586d752ce447d400a9f88926a Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 18 Mar 2024 20:40:38 +0800 Subject: [PATCH] feat: handle sys var to run --- .../workflow/nodes/_base/components/variable/utils.ts | 7 ++++++- .../workflow/nodes/_base/hooks/use-one-step-run.ts | 5 ++++- web/app/components/workflow/nodes/http/panel.tsx | 2 +- web/app/components/workflow/types.ts | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.ts index 9526f77f69..98e6b5ed9a 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -152,7 +152,12 @@ const formatItem = (item: any, isChatMode: boolean, filterVar: (payload: Var, se export const toNodeOutputVars = (nodes: any[], isChatMode: boolean, filterVar = (_payload: Var, _selector: ValueSelector) => true): NodeOutPutVar[] => { const res = nodes .filter(node => SUPPORT_OUTPUT_VARS_NODE.includes(node.data.type)) - .map(node => formatItem(node, isChatMode, filterVar)) + .map((node) => { + return { + ...formatItem(node, isChatMode, filterVar), + isStartNode: node.data.type === BlockEnum.Start, + } + }) .filter(item => item.vars.length > 0) return res } diff --git a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts index 37755fddb6..42d8cce551 100644 --- a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts +++ b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts @@ -62,9 +62,12 @@ const useOneStepRun = ({ const allOutputVars = toNodeOutputVars(getBeforeNodesInSameBranch(id), isChatMode) const getVar = (valueSelector: ValueSelector): Var | undefined => { let res: Var | undefined - const targetVar = allOutputVars.find(v => v.nodeId === valueSelector[0]) + const isSystem = valueSelector[0] === 'sys' + const targetVar = isSystem ? allOutputVars.find(item => !!item.isStartNode) : allOutputVars.find(v => v.nodeId === valueSelector[0]) if (!targetVar) return undefined + if (isSystem) + return targetVar.vars.find(item => item.variable.split('.')[1] === valueSelector[1]) let curr: any = targetVar.vars valueSelector.slice(1).forEach((key, i) => { diff --git a/web/app/components/workflow/nodes/http/panel.tsx b/web/app/components/workflow/nodes/http/panel.tsx index b7f749e886..0a214d142a 100644 --- a/web/app/components/workflow/nodes/http/panel.tsx +++ b/web/app/components/workflow/nodes/http/panel.tsx @@ -160,7 +160,7 @@ const Panel: FC> = ({ /> diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index 20cd9946d0..67e20139b7 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -157,6 +157,7 @@ export type NodeOutPutVar = { nodeId: string title: string vars: Var[] + isStartNode?: boolean } export type Block = {