Skip to content

Fix zod 4 incompatibility in loggerSchema (closes #17)#18

Merged
ben-vargas merged 2 commits into
ben-vargas:ai-sdk-v5from
bjcoombs:ai-sdk-v5-zod4-fix
Apr 14, 2026
Merged

Fix zod 4 incompatibility in loggerSchema (closes #17)#18
ben-vargas merged 2 commits into
ben-vargas:ai-sdk-v5from
bjcoombs:ai-sdk-v5-zod4-fix

Conversation

@bjcoombs

Copy link
Copy Markdown

Summary

Fixes #17: `ai-sdk-v5` tag line (`v0.0.2`) crashes at module-load under zod 4 because `loggerSchema` uses zod 3's `z.function().args().returns()` API, which was removed in zod 4.

Changes

  • `src/validation.ts`: Replace `z.function()`-based logger schemas with `z.custom(v => typeof v === 'function')`. Identical behaviour across zod 3 and zod 4, matching the package's declared `zod@^3 || ^4` peer range.

Why `z.custom` rather than `z.function({ input, output })`

`z.function({ input, output })` is zod 4 only and would break zod 3 consumers. `z.custom` is stable across both majors and captures exactly the runtime guarantee this schema needs — "this value is a function". The original `.args(z.string())` signature declaration was never actually validating call-sites anyway; it was documentation in type form, which the TypeScript `Logger` interface already provides.

Testing

  • `npm run build` — clean
  • `npx tsc --noEmit` — clean
  • `npm test` — 269 tests pass
  • Verified module loads successfully under both `zod@^3.24.0` and `zod@^4.1.0`:
    ```bash
    npm install --no-save zod@^4.1.0 && node -e "require('./dist/index.cjs').createOpencode({})"

    loaded OK

    ```

Context

I hit this while integrating the provider into claude-task-master#1685. Task Master uses AI SDK v5 which pulls zod 4 through `@ai-sdk/*` packages, so any consumer in that ecosystem is affected.

Test plan

  • Build passes
  • Typecheck clean
  • Existing vitest suite (269 tests) passes
  • Verified load under zod 3 and zod 4
  • Maintainer review

bjcoombs and others added 2 commits April 14, 2026 15:57
`z.function().args().returns()` is zod 3 syntax and was removed in zod 4
(replaced by `z.function({ input, output })`). Because the package's peer
range declares `zod@^3 || ^4`, importing under zod 4 crashed at module-load:

  TypeError: z.function(...).args is not a function

Replace with `z.custom<Fn>(v => typeof v === 'function')`, which is
identical across both major versions and captures the same intent for a
logger-like contract (runtime function guard).
@ben-vargas ben-vargas merged commit 82fdaf7 into ben-vargas:ai-sdk-v5 Apr 14, 2026
bjcoombs added a commit to bjcoombs/claude-task-master that referenced this pull request Apr 14, 2026
… hint

- ben-vargas/ai-sdk-provider-opencode-sdk#18 released as v0.0.3 fixes
  the zod 4 incompat. Bump the dep so OpenCode selection actually works
  end-to-end
- Add OPENCODE case to setModel's providerHint cascade in
  scripts/modules/task-manager/models.js so --opencode is accepted
bjcoombs added a commit to bjcoombs/claude-task-master that referenced this pull request Apr 14, 2026
… hint

- ben-vargas/ai-sdk-provider-opencode-sdk#18 released as v0.0.3 fixes
  the zod 4 incompat. Bump the dep so OpenCode selection actually works
  end-to-end
- Add OPENCODE case to setModel's providerHint cascade in
  scripts/modules/task-manager/models.js so --opencode is accepted
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.

2 participants