From eae0d8dacd0b8d7a74c3a082997406b52ae375ac Mon Sep 17 00:00:00 2001 From: v-zhangjc9 Date: Fri, 11 Jul 2025 14:43:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(web):=20=E4=BF=AE=E5=A4=8D=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E6=A0=A1=E9=AA=8C=E6=B2=A1=E6=9C=89=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E5=85=A5=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service-web/client/src/components/flow/FlowChecker.tsx | 4 ++-- service-web/client/src/components/flow/FlowEditor.tsx | 4 ++-- service-web/client/src/components/flow/NodeRegistry.tsx | 9 +++++---- service-web/client/src/components/flow/types.ts | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/service-web/client/src/components/flow/FlowChecker.tsx b/service-web/client/src/components/flow/FlowChecker.tsx index 18b335b..bdbae18 100644 --- a/service-web/client/src/components/flow/FlowChecker.tsx +++ b/service-web/client/src/components/flow/FlowChecker.tsx @@ -68,7 +68,7 @@ export const nodeTypeNotFound = () => new CheckError(302, '节点类型不存在 export const nodeError = (nodeId: string, reason?: string) => new CheckError(303, reason ?? `节点配置存在错误:${nodeId}`) // @ts-ignore -export const checkSave: (nodes: Node[], edges: Edge[], data: any) => void = (nodes, edges, data) => { +export const checkSave: (inputSchema: Record>, nodes: Node[], edges: Edge[], data: any) => void = (inputSchema, nodes, edges, data) => { if (isEmpty(nodes)) { throw atLeastOneNode() } @@ -85,7 +85,7 @@ export const checkSave: (nodes: Node[], edges: Edge[], data: any) => void = (nod let nodeType = node.type! let nodeDefine = NodeRegistry[nodeType] for (let checker of nodeDefine.checkers) { - let checkResult = checker(nodeId, nodes, edges, data) + let checkResult = checker(nodeId, inputSchema, nodes, edges, data) if (checkResult.error) { throw nodeError(nodeId, checkResult.message) } diff --git a/service-web/client/src/components/flow/FlowEditor.tsx b/service-web/client/src/components/flow/FlowEditor.tsx index c06dec0..bf97b69 100644 --- a/service-web/client/src/components/flow/FlowEditor.tsx +++ b/service-web/client/src/components/flow/FlowEditor.tsx @@ -65,7 +65,7 @@ function FlowEditor(props: FlowEditorProps) { onConnect, } = useFlowStore() - const {setInputSchema} = useContextStore() + const {inputSchema, setInputSchema} = useContextStore() useEffect(() => { // language=JSON @@ -142,7 +142,7 @@ function FlowEditor(props: FlowEditorProps) { if (commonInfo.debug) { console.info('Save', JSON.stringify({nodes, edges, data})) } - checkSave(nodes, edges, data) + checkSave(inputSchema, nodes, edges, data) props.onGraphDataChange({nodes, edges, data}) } catch (e) { // @ts-ignore diff --git a/service-web/client/src/components/flow/NodeRegistry.tsx b/service-web/client/src/components/flow/NodeRegistry.tsx index 2826c3f..f5f8aa8 100644 --- a/service-web/client/src/components/flow/NodeRegistry.tsx +++ b/service-web/client/src/components/flow/NodeRegistry.tsx @@ -7,14 +7,15 @@ import OutputNode from './node/OutputNode.tsx' import SwitchNode from './node/SwitchNode.tsx' import type {NodeChecker} from './types.ts' -const inputVariableChecker: NodeChecker = (id, nodes, edges, data) => { +const inputVariableChecker: NodeChecker = (id, inputSchema, nodes, edges, data) => { let nodeData = data[id] ?? {} if (has(nodeData, 'inputs')) { let inputs = nodeData?.inputs ?? {} if (!isEmpty(inputs)) { - let outputVariables = new Set( - getAllIncomerNodeOutputVariables(id, nodes, edges, data).map(i => `${i.id}.${i.variable}`), - ) + let outputVariables = new Set([ + ...getAllIncomerNodeOutputVariables(id, nodes, edges, data).map(i => `${i.id}.${i.variable}`), + ...Object.keys(inputSchema) + ]) for (const key of Object.keys(inputs)) { let variable = inputs[key]?.variable ?? '' if (!outputVariables.has(variable)) { diff --git a/service-web/client/src/components/flow/types.ts b/service-web/client/src/components/flow/types.ts index 257fd85..6b0c5a2 100644 --- a/service-web/client/src/components/flow/types.ts +++ b/service-web/client/src/components/flow/types.ts @@ -15,7 +15,7 @@ export type NodeError = { message?: string, } -export type NodeChecker = (id: string, nodes: Node[], edges: Edge[], data: any) => NodeError +export type NodeChecker = (id: string, inputSchema: Record>, nodes: Node[], edges: Edge[], data: any) => NodeError export type GraphData = { nodes: Node[], edges: Edge[], data: any }