fix(core): fall back to zod/v4 JSON schema converter#2140
Open
pragnyanramtha wants to merge 1 commit into
Open
fix(core): fall back to zod/v4 JSON schema converter#2140pragnyanramtha wants to merge 1 commit into
pragnyanramtha wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: c065d0f The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run. |
Contributor
There was a problem hiding this comment.
No issues found across 3 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant Caller as Schema Caller
participant zodCompat as toJsonSchema()
participant ZodRoot as zod (root)
participant ZodV4 as zod/v4
participant ZodToJson as zod-to-json-schema
Note over Caller,ZodToJson: Schema Type Detection
Caller->>zodCompat: Call toJsonSchema(schema)
zodCompat->>zodCompat: Check _zod property
alt V3 Schema (no _zod)
zodCompat->>ZodToJson: Convert using zod-to-json-schema
ZodToJson-->>zodCompat: Return v3 JSON Schema
zodCompat-->>Caller: Return JSON Schema
else V4 Schema (_zod present)
Note over zodCompat,ZodV4: Try zod/v4 first
zodCompat->>ZodV4: Check .toJSONSchema exists
alt Has toJSONSchema
zodCompat->>ZodV4: Call toJSONSchema(schema)
ZodV4-->>zodCompat: Return v4 JSON Schema
zodCompat-->>Caller: Return JSON Schema
else No toJSONSchema on zod/v4
Note over zodCompat,ZodRoot: Fallback to root zod
zodCompat->>ZodRoot: Check .toJSONSchema exists
alt Has toJSONSchema
zodCompat->>ZodRoot: Call toJSONSchema(schema)
ZodRoot-->>zodCompat: Return v4 JSON Schema
zodCompat-->>Caller: Return JSON Schema
else No toJSONSchema on root zod
Note over zodCompat: Both converters missing
zodCompat->>zodCompat: Throw "Zod v4 toJSONSchema method not found"
zodCompat-->>Caller: Error thrown
end
end
end
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
why
Fixes #1845. Stagehand detects v4-shaped schemas by
_zod, buttoJsonSchema()assumed the rootzodimport always exposestoJSONSchema(). In bundled/deployed environments where rootzodresolves to the transitional v3 surface while user schemas come fromzod/v4, extraction can throwZod v4 toJSONSchema method not found.what changed
zod/v4subpath converter and try it before the rootzodconverter for v4 schemas.zod-to-json-schemapath unchanged.zodwithouttoJSONSchema()whilezod/v4provides it.@browserbasehq/stagehand.test plan
pnpm --filter @browserbasehq/stagehand run build:esmpnpm exec vitest run --config vitest.esm.config.mjs dist/esm/tests/unit/zod-compat.test.jsfrompackages/corepnpm --filter @browserbasehq/stagehand run typecheckpnpm --filter @browserbasehq/stagehand exec eslint lib/v3/zodCompat.ts tests/unit/zod-compat.test.tspnpm --filter @browserbasehq/stagehand exec prettier --check lib/v3/zodCompat.ts tests/unit/zod-compat.test.ts ../../.changeset/zod-v4-json-schema-fallback.mdgit diff --checkSummary by cubic
Add a fallback to the
zod/v4JSON schema converter when the rootzodlackstoJSONSchema, preventing “Zod v4 toJSONSchema method not found” errors in bundled builds. Fixes #1845.zod/v4’stoJSONSchemabefore the rootzodfor v4-shaped schemas.zod-to-json-schemapath unchanged.zodwithouttoJSONSchemaand verifies thezod/v4path.@browserbasehq/stagehand.Written for commit c065d0f. Summary will update on new commits. Review in cubic