From ee9317540e6b6daf2dd3eb708cd23e8e10044bfb Mon Sep 17 00:00:00 2001 From: twwu Date: Fri, 28 Mar 2025 15:39:22 +0800 Subject: [PATCH] fix: simplify array handling in jsonToSchema and checkJsonDepth functions --- web/app/components/workflow/nodes/llm/utils.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/app/components/workflow/nodes/llm/utils.ts b/web/app/components/workflow/nodes/llm/utils.ts index a9e69ff7a3..4592deb535 100644 --- a/web/app/components/workflow/nodes/llm/utils.ts +++ b/web/app/components/workflow/nodes/llm/utils.ts @@ -52,7 +52,7 @@ export const jsonToSchema = (json: any): Field => { schema.required!.push(key) }) } - else if (schema.type === Type.array && json.length > 0) { + else if (schema.type === Type.array) { schema.items = jsonToSchema(json[0]) as ArrayItems } @@ -65,8 +65,9 @@ export const checkJsonDepth = (json: any) => { let maxDepth = 0 - if (Array.isArray(json) && json[0] && typeof json[0] === 'object') { - maxDepth = checkJsonDepth(json[0]) + 1 + if (Array.isArray(json)) { + if (json[0] && typeof json[0] === 'object') + maxDepth = checkJsonDepth(json[0]) } else if (typeof json === 'object') { const propertyDepths = Object.values(json).map(value => checkJsonDepth(value))