fix(tool): bridge custom tool zod metadata (#27770)

This commit is contained in:
Aiden Cline
2026-05-15 14:50:21 -05:00
committed by GitHub
parent 0df2f5b45f
commit 48122b31cc
3 changed files with 31 additions and 18 deletions

View File

@@ -48,13 +48,7 @@ export function tool<Args extends z.ZodRawShape>(input: {
args: Args
execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<ToolResult>
}) {
return {
...input,
// Generate JSON Schema here with the same Zod instance that created
// `tool.schema` args. Zod metadata such as `.describe()` is stored in a
// module-local registry, so converting later from opencode can lose it.
jsonSchema: z.toJSONSchema(z.object(input.args), { target: "draft-7", io: "input" }),
}
return input
}
tool.schema = z