Skip to content

Commit bc76886

Browse files
authored
Bugfix/Enable Custom Tool Optional Input Schema (#3258)
* prevent streaming of chatflow tool and chain tool * enable optional input schema
1 parent b7cb8be commit bc76886

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

packages/components/src/utils.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -701,14 +701,23 @@ export const convertSchemaToZod = (schema: string | object): ICommonObject => {
701701
const zodObj: ICommonObject = {}
702702
for (const sch of parsedSchema) {
703703
if (sch.type === 'string') {
704-
if (sch.required) z.string({ required_error: `${sch.property} required` }).describe(sch.description)
705-
zodObj[sch.property] = z.string().describe(sch.description)
704+
if (sch.required) {
705+
zodObj[sch.property] = z.string({ required_error: `${sch.property} required` }).describe(sch.description)
706+
} else {
707+
zodObj[sch.property] = z.string().describe(sch.description).optional()
708+
}
706709
} else if (sch.type === 'number') {
707-
if (sch.required) z.number({ required_error: `${sch.property} required` }).describe(sch.description)
708-
zodObj[sch.property] = z.number().describe(sch.description)
710+
if (sch.required) {
711+
zodObj[sch.property] = z.number({ required_error: `${sch.property} required` }).describe(sch.description)
712+
} else {
713+
zodObj[sch.property] = z.number().describe(sch.description).optional()
714+
}
709715
} else if (sch.type === 'boolean') {
710-
if (sch.required) z.boolean({ required_error: `${sch.property} required` }).describe(sch.description)
711-
zodObj[sch.property] = z.boolean().describe(sch.description)
716+
if (sch.required) {
717+
zodObj[sch.property] = z.boolean({ required_error: `${sch.property} required` }).describe(sch.description)
718+
} else {
719+
zodObj[sch.property] = z.boolean().describe(sch.description).optional()
720+
}
712721
}
713722
}
714723
return zodObj

0 commit comments

Comments
 (0)