fix(opencode): replace zodToJsonSchema with z.toJSONSchema for Zod v4 compat#20809
fix(opencode): replace zodToJsonSchema with z.toJSONSchema for Zod v4 compat#20809jbmml wants to merge 1 commit intoanomalyco:devfrom
Conversation
… compat
zodToJsonSchema from zod-to-json-schema@3.x produces incorrect output
with Zod v4 schemas (returns {"type":"string"} for object schemas,
losing all properties and descriptions). Switch the experimental tools
API endpoint to z.toJSONSchema() which is Zod v4's built-in converter
and correctly preserves .describe() metadata.
Fixes anomalyco#20807
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The following comment was made by an LLM, it may be inaccurate: Based on the search results, I found related PRs but they appear to be older attempts addressing similar issues with tool descriptions. However, PR #20809 is the current PR being analyzed, so I need to verify if any of the found PRs are still open and potentially duplicate: The most relevant related PRs are:
These appear to be previous attempts at fixing similar issues. The current PR #20809 is a more targeted fix for the experimental tools endpoint using the Zod v4 built-in No duplicate PRs found |
|
Re: the bot-flagged related PRs — I investigated all four:
This PR (#20809) fixes a different code path — the experimental HTTP API endpoint, which was the only remaining call site for the broken |
Applies both open PRs (anomalyco#20805, anomalyco#20809) to current dev for local use: - task tool: accept agent/agent_type as aliases for subagent_type - experimental.ts: replace broken zodToJsonSchema with z.toJSONSchema Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Quick note for reviewers: this PR is independent of #19916 (plugin cross-instance Zod metadata rehydration). This fixes a narrower issue — I previously linked this to a broader re-architecture RFC (#20922) which I've since closed — the unification premise didn't hold up under analysis. This fix stands on its own. |
Issue for this PR
Fixes #20807
Related: #4357
Type of change
What does this PR do?
The experimental tools endpoint (
GET /experimental/tools) useszodToJsonSchema()fromzod-to-json-schema@3.24.5to convert tool parameter schemas. This library is incompatible with Zod v4 — for an object schema with two described string properties, it returns{"type":"string"}instead of the correct object schema. All properties, descriptions, and required fields are lost.The fix switches to
z.toJSONSchema()(Zod v4 built-in), which is already used insession/prompt.tsfor the same purpose and correctly preserves.describe()metadata. The Zod-vs-plain detection also changes from_def(Zod v3 internals) totypeof parse === "function"which works reliably with Zod v4.I confirmed the original bug reported in #4357 (tool descriptions lost) is already fixed in the prompt path by the Zod v4 migration. This PR fixes the same issue in the experimental API path.
How did you verify your code works?
z.toJSONSchema()produces correct output with descriptions,zodToJsonSchema()returns garbage{"type":"string"}Checklist