fix(tool): tolerate plugin tool defs with missing args (#28357)

This commit is contained in:
Kit Langton
2026-05-19 11:07:28 -04:00
committed by GitHub
parent 8dd6448c90
commit c79a9634d3
2 changed files with 92 additions and 7 deletions

View File

@@ -145,9 +145,12 @@ export const layer: Layer.Layer<
function fromPlugin(id: string, def: ToolDefinition): Tool.Def {
// Plugin tools still expose Zod args publicly; keep that compatibility
// boxed at the registry boundary and give the LLM the original JSON Schema.
const entries = Object.entries(def.args)
// Normalize missing args to `{}` once — pre-1.14.49 the code was
// `z.object(def.args)` and Zod silently tolerated undefined (#27451, #27630).
const args = def.args ?? {}
const entries = Object.entries(args)
const allZod = entries.every((entry) => isZodType(entry[1]))
const zodParams = allZod ? z.object(def.args) : undefined
const zodParams = allZod ? z.object(args) : undefined
const jsonSchema = zodParams ? zodJsonSchema(zodParams) : legacyJsonSchema(entries)
const parameters = zodParams
? Schema.declare<unknown>((u): u is unknown => zodParams.safeParse(u).success)