From 9231c197a52de18246d2215001627b0db1e1ab79 Mon Sep 17 00:00:00 2001 From: crazywoola <100913391+crazywoola@users.noreply.github.com> Date: Tue, 6 May 2025 10:26:44 +0800 Subject: [PATCH] fix: s.filter is not a function (#19250) --- .../nodes/_base/components/variable/utils.ts | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 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 efbd663630..d56c636f55 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -134,18 +134,33 @@ const findExceptVarInObject = (obj: any, filterVar: (payload: Var, selector: Val const { children } = obj const isStructuredOutput = !!(children as StructuredOutput)?.schema?.properties + let childrenResult: Var[] | StructuredOutput | undefined + + if (isStructuredOutput) { + childrenResult = findExceptVarInStructuredOutput(children, filterVar) + } + else if (Array.isArray(children)) { + childrenResult = children.filter((item: Var) => { + const { children: itemChildren } = item + const currSelector = [...value_selector, item.variable] + + if (!itemChildren) + return filterVar(item, currSelector) + + const filteredObj = findExceptVarInObject(item, filterVar, currSelector, false) // File doesn't contain file children + return filteredObj.children && (filteredObj.children as Var[])?.length > 0 + }) + } + else { + childrenResult = [] + } + const res: Var = { variable: obj.variable, type: isFile ? VarType.file : VarType.object, - children: isStructuredOutput ? findExceptVarInStructuredOutput(children, filterVar) : children.filter((item: Var) => { - const { children } = item - const currSelector = [...value_selector, item.variable] - if (!children) - return filterVar(item, currSelector) - const obj = findExceptVarInObject(item, filterVar, currSelector, false) // File doesn't contains file children - return obj.children && (obj.children as Var[])?.length > 0 - }), + children: childrenResult, } + return res }