From bc76886178b4307f0b83ddc5a51dba7bade79eee Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Thu, 26 Sep 2024 01:09:35 +0100 Subject: [PATCH] Bugfix/Enable Custom Tool Optional Input Schema (#3258) * prevent streaming of chatflow tool and chain tool * enable optional input schema --- packages/components/src/utils.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/components/src/utils.ts b/packages/components/src/utils.ts index 3604e3841..609ce1931 100644 --- a/packages/components/src/utils.ts +++ b/packages/components/src/utils.ts @@ -701,14 +701,23 @@ export const convertSchemaToZod = (schema: string | object): ICommonObject => { const zodObj: ICommonObject = {} for (const sch of parsedSchema) { if (sch.type === 'string') { - if (sch.required) z.string({ required_error: `${sch.property} required` }).describe(sch.description) - zodObj[sch.property] = z.string().describe(sch.description) + if (sch.required) { + zodObj[sch.property] = z.string({ required_error: `${sch.property} required` }).describe(sch.description) + } else { + zodObj[sch.property] = z.string().describe(sch.description).optional() + } } else if (sch.type === 'number') { - if (sch.required) z.number({ required_error: `${sch.property} required` }).describe(sch.description) - zodObj[sch.property] = z.number().describe(sch.description) + if (sch.required) { + zodObj[sch.property] = z.number({ required_error: `${sch.property} required` }).describe(sch.description) + } else { + zodObj[sch.property] = z.number().describe(sch.description).optional() + } } else if (sch.type === 'boolean') { - if (sch.required) z.boolean({ required_error: `${sch.property} required` }).describe(sch.description) - zodObj[sch.property] = z.boolean().describe(sch.description) + if (sch.required) { + zodObj[sch.property] = z.boolean({ required_error: `${sch.property} required` }).describe(sch.description) + } else { + zodObj[sch.property] = z.boolean().describe(sch.description).optional() + } } } return zodObj