Skip to content

chore: migrate to zod v4 and refactor schema conversion#117

Open
k35o wants to merge 3 commits intovercel:mainfrom
k35o:upgrade-zod
Open

chore: migrate to zod v4 and refactor schema conversion#117
k35o wants to merge 3 commits intovercel:mainfrom
k35o:upgrade-zod

Conversation

@k35o
Copy link

@k35o k35o commented Jan 23, 2026

Upgrades Zod from v3 (3.25.76) to v4 (4.3.6) and updates code to use the new v4 APIs.

Changes

Dependencies:

  • zod: 3.25.76 → 4.3.6
  • @anthropic-ai/claude-agent-sdk: 0.1.15 → 0.2.12

Code changes:

  • Replace manual zodSchemaToJsonSchema implementation with Zod v4's built-in z.toJSONSchema() method
  • Replace deprecated .isOptional() with safeParse(undefined).success for optional parameter detection
  • Simplify type definitions and reduce code complexity

Migration Details

Zod v4 deprecated the .isOptional() method. The new approach uses safeParse(undefined) to detect optional parameters:

  • Required parameters: safeParse(undefined).success === false
  • Optional parameters: safeParse(undefined).success === true

This change has been tested and behaves identically to the v3 implementation.

Benefits

  • Cleaner code: Leveraging Zod's native JSON Schema conversion.
  • Future-proof: Aligns with Zod v4 standards and avoids upcoming v3 deprecation.
  • Reduced maintenance: Removed ~40 lines of manual schema conversion logic.

k35o added 2 commits January 23, 2026 15:28
- zod: 3.25.76 -> 4.3.6
- @anthropic-ai/claude-agent-sdk: 0.1.15 -> 0.2.17
- Replace manual zodSchemaToJsonSchema implementation with Zod v4's built-in z.toJSONSchema()
- Replace deprecated .isOptional() with safeParse(undefined) for optional parameter detection
@socket-security
Copy link

socket-security bot commented Jan 23, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​anthropic-ai/​claude-agent-sdk@​0.1.15 ⏵ 0.2.1293 -510087 +1100 +370
Updatedzod@​3.25.76 ⏵ 4.3.6100 +210010096100

View full report

Downgrade @anthropic-ai/claude-agent-sdk from 0.2.17 to 0.2.12 to improve
Supply Chain Security score (from 73 to potentially higher based on Socket
Security analysis in PR vercel#117).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant