fix: s.filter is not a function (#19250)
This commit is contained in:
parent
8ac3a223a8
commit
9231c197a5
1 changed files with 23 additions and 8 deletions
|
|
@ -134,18 +134,33 @@ const findExceptVarInObject = (obj: any, filterVar: (payload: Var, selector: Val
|
||||||
const { children } = obj
|
const { children } = obj
|
||||||
const isStructuredOutput = !!(children as StructuredOutput)?.schema?.properties
|
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 = {
|
const res: Var = {
|
||||||
variable: obj.variable,
|
variable: obj.variable,
|
||||||
type: isFile ? VarType.file : VarType.object,
|
type: isFile ? VarType.file : VarType.object,
|
||||||
children: isStructuredOutput ? findExceptVarInStructuredOutput(children, filterVar) : children.filter((item: Var) => {
|
children: childrenResult,
|
||||||
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
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue