fix(zod): infer parsed tool callback arguments#1992
Conversation
jbeckwith-oai
left a comment
There was a problem hiding this comment.
Reviewed the type flow for both Zod tool helpers and the new regression coverage. InferZodType<Parameters> matches the value returned by parseZodObject() and now propagates the parsed output type consistently through $callback, $parseRaw, and __arguments for both Chat Completions and Responses. The compareType assertions are exact, so they would fail if these properties regressed back to the schema object type.
I also validated the PR commit locally with the focused Zod suite (26 tests), pnpm build, and the full pnpm lint pipeline; all passed. No blocking issues found.
…-zod-tool-callback-types
jbeckwith-oai
left a comment
There was a problem hiding this comment.
Reviewed the current head (48903fd) after its merge with main. The corrected arguments: InferZodType<Parameters> generic now matches the value produced by parseZodObject() and consistently fixes $callback, $parseRaw, and __arguments for both Chat Completions and Responses tools. The exact type assertions cover all six affected surfaces, and the emitted CJS/ESM declarations retain the corrected inferred output type. No runtime behavior changes.
Local validation passed: focused Zod suite (26/26) and the full pnpm lint pipeline (Prettier, ESLint, CJS/ESM+Deno builds, tsc, Are The Types Wrong, publint, JSR dry-run). Current CI is green across Node 20/22/24/26.2, ecosystem tests, Agents SDK regressions, breaking-change detection, examples, and CodeQL. No blocking issues found.
Changes being requested
Fixes #1244.
zodFunction()andzodResponsesFunction()already infer the parsed Zod output for the callback supplied in their options, but their returned auto-parseable tool types recorded the raw Zod schema type asarguments. BecauseAutoParseableToolandAutoParseableResponseTooluse that field for their helper properties, callers saw$callback,$parseRaw, and__argumentstyped as the schema object instead of the parsed tool arguments.This updates both Zod helper return types to use
InferZodType<Parameters>forarguments. The change is type-only and does not alter parsing or callback behavior at runtime.The type regression checks now verify the inferred parsed argument type for
$callback,$parseRaw, and__argumentson both chat completion and Responses API tools.Additional context & links
pnpm test --runInBand tests/helpers/zod.test.tspnpm lintpnpm test --runInBand