fix(tool): preserve custom tool arg descriptions (#27750)

Co-authored-by: khimaros <231498+khimaros@users.noreply.github.com>
This commit is contained in:
Aiden Cline
2026-05-15 10:11:01 -05:00
committed by GitHub
parent eb630075c3
commit ef7d801271
3 changed files with 81 additions and 3 deletions

View File

@@ -48,7 +48,13 @@ export function tool<Args extends z.ZodRawShape>(input: {
args: Args
execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<ToolResult>
}) {
return input
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" }),
}
}
tool.schema = z