fix(web): 修复变量校验没有包含入参

This commit is contained in:
v-zhangjc9
2025-07-11 14:43:26 +08:00
parent bf37c163fb
commit eae0d8dacd
4 changed files with 10 additions and 9 deletions

View File

@@ -68,7 +68,7 @@ export const nodeTypeNotFound = () => new CheckError(302, '节点类型不存在
export const nodeError = (nodeId: string, reason?: string) => new CheckError(303, reason ?? `节点配置存在错误:${nodeId}`) export const nodeError = (nodeId: string, reason?: string) => new CheckError(303, reason ?? `节点配置存在错误:${nodeId}`)
// @ts-ignore // @ts-ignore
export const checkSave: (nodes: Node[], edges: Edge[], data: any) => void = (nodes, edges, data) => { export const checkSave: (inputSchema: Record<string, Record<string, any>>, nodes: Node[], edges: Edge[], data: any) => void = (inputSchema, nodes, edges, data) => {
if (isEmpty(nodes)) { if (isEmpty(nodes)) {
throw atLeastOneNode() throw atLeastOneNode()
} }
@@ -85,7 +85,7 @@ export const checkSave: (nodes: Node[], edges: Edge[], data: any) => void = (nod
let nodeType = node.type! let nodeType = node.type!
let nodeDefine = NodeRegistry[nodeType] let nodeDefine = NodeRegistry[nodeType]
for (let checker of nodeDefine.checkers) { for (let checker of nodeDefine.checkers) {
let checkResult = checker(nodeId, nodes, edges, data) let checkResult = checker(nodeId, inputSchema, nodes, edges, data)
if (checkResult.error) { if (checkResult.error) {
throw nodeError(nodeId, checkResult.message) throw nodeError(nodeId, checkResult.message)
} }

View File

@@ -65,7 +65,7 @@ function FlowEditor(props: FlowEditorProps) {
onConnect, onConnect,
} = useFlowStore() } = useFlowStore()
const {setInputSchema} = useContextStore() const {inputSchema, setInputSchema} = useContextStore()
useEffect(() => { useEffect(() => {
// language=JSON // language=JSON
@@ -142,7 +142,7 @@ function FlowEditor(props: FlowEditorProps) {
if (commonInfo.debug) { if (commonInfo.debug) {
console.info('Save', JSON.stringify({nodes, edges, data})) console.info('Save', JSON.stringify({nodes, edges, data}))
} }
checkSave(nodes, edges, data) checkSave(inputSchema, nodes, edges, data)
props.onGraphDataChange({nodes, edges, data}) props.onGraphDataChange({nodes, edges, data})
} catch (e) { } catch (e) {
// @ts-ignore // @ts-ignore

View File

@@ -7,14 +7,15 @@ import OutputNode from './node/OutputNode.tsx'
import SwitchNode from './node/SwitchNode.tsx' import SwitchNode from './node/SwitchNode.tsx'
import type {NodeChecker} from './types.ts' 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] ?? {} let nodeData = data[id] ?? {}
if (has(nodeData, 'inputs')) { if (has(nodeData, 'inputs')) {
let inputs = nodeData?.inputs ?? {} let inputs = nodeData?.inputs ?? {}
if (!isEmpty(inputs)) { if (!isEmpty(inputs)) {
let outputVariables = new Set( let outputVariables = new Set([
getAllIncomerNodeOutputVariables(id, nodes, edges, data).map(i => `${i.id}.${i.variable}`), ...getAllIncomerNodeOutputVariables(id, nodes, edges, data).map(i => `${i.id}.${i.variable}`),
) ...Object.keys(inputSchema)
])
for (const key of Object.keys(inputs)) { for (const key of Object.keys(inputs)) {
let variable = inputs[key]?.variable ?? '' let variable = inputs[key]?.variable ?? ''
if (!outputVariables.has(variable)) { if (!outputVariables.has(variable)) {

View File

@@ -15,7 +15,7 @@ export type NodeError = {
message?: string, message?: string,
} }
export type NodeChecker = (id: string, nodes: Node[], edges: Edge[], data: any) => NodeError export type NodeChecker = (id: string, inputSchema: Record<string, Record<string, any>>, nodes: Node[], edges: Edge[], data: any) => NodeError
export type GraphData = { nodes: Node[], edges: Edge[], data: any } export type GraphData = { nodes: Node[], edges: Edge[], data: any }