Skip to content

Conversation

@mattapperson
Copy link
Collaborator

Summary

  • Fixes type incompatibility when users define tools with plain zod imports
  • The SDK was importing types from zod/v4, but users typically import from zod, causing TypeScript errors due to internal type metadata differences

Changes

  • Import ZodType, ZodObject, ZodRawShape from zod instead of zod/v4 in tool-types.ts, tool.ts, and tool-executor.ts
  • Keep runtime imports (toJSONSchema, ZodError) from zod/v4 as they're only available there
  • Use type assertion in convertZodToJsonSchema to bridge the type gap between zod and zod/v4
  • Update toJSONSchema target from openapi-3.0 to draft-7 (former isn't supported in current Zod version)
  • Update tests to use draft-7 target

Error Before Fix

No overload matches this call.
Type ZodObject<{ channel: ZodString; timestamp: ZodString; name: ZodString; }, strip> is not assignable to type ZodObject<Readonly<{ [k: string]: ZodType<unknown, unknown, ZodTypeInternals<unknown, unknown>>; }>, strip>.
The types of '_zod.version.minor' are incompatible between these types.
Type 1 is not assignable to type 0.

Test plan

  • Build passes (pnpm run build)
  • All tests pass (npx vitest --run)
  • Verified tool definition works with plain zod imports

@mattapperson mattapperson force-pushed the fix-tool-type branch 2 times, most recently from e1ab37e to d2269f7 Compare December 28, 2025 23:13
louisgv
louisgv previously approved these changes Dec 28, 2025
Copy link
Contributor

@louisgv louisgv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

The tool system was importing types from 'zod/v4' explicitly, but users
typically import from plain 'zod'. This caused TypeScript type errors
due to internal type metadata differences (_zod.version.minor) between
the two import paths.

Changes:
- Import ZodType, ZodObject, ZodRawShape from 'zod' instead of 'zod/v4'
  in tool-types.ts, tool.ts, and tool-executor.ts
- Keep runtime imports (toJSONSchema, ZodError) from 'zod/v4' as they're
  only available there
- Use type assertion in convertZodToJsonSchema to bridge the type gap
- Update toJSONSchema target from 'openapi-3.0' to 'draft-7' as the
  former isn't supported in current Zod version
- Update tests to use 'draft-7' target
@mattapperson mattapperson merged commit d3d485c into main Dec 28, 2025
1 check passed
@mattapperson mattapperson deleted the fix-tool-type branch December 28, 2025 23:17
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.

3 participants