fix: fallback to zod-to-json-schema when Zod v4 toJSONSchema is missing · Pull Request #1859 · browserbase/stagehand
When a Zod v4 schema is detected but the root zod import doesn't expose z.toJSONSchema() (e.g., due to bundler resolution or older Zod v4 builds), the code threw "Zod v4 toJSONSchema method not found". Fall back to the zod-to-json-schema library instead of throwing, since it can handle both v3 and v4 schemas. Fixes #1845
The previous fallback to zod-to-json-schema does not support Zod v4 schemas at runtime (ZodFirstPartyTypeKind was removed in v4). Instead, import toJSONSchema directly from "zod" as a named import so it is resolved at module load time and cannot be stripped by bundlers.
Reverts the static named import which breaks when Zod v3 is installed (toJSONSchema doesn't exist in v3). Instead, keep the original runtime check on the z namespace and fall back to zod-to-json-schema when it's not available.
ghost
closed this by deleting the head repository
This pull request was closed.
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