Skip to content

fix: custom realtime models broken under zod 4.4+#126

Merged
AdirAmsalem merged 1 commit intomainfrom
realtime-input-schema-error
Apr 30, 2026
Merged

fix: custom realtime models broken under zod 4.4+#126
AdirAmsalem merged 1 commit intomainfrom
realtime-input-schema-error

Conversation

@AdirAmsalem
Copy link
Copy Markdown
Contributor

@AdirAmsalem AdirAmsalem commented Apr 30, 2026

Summary

A fresh install of @decartai/sdk started failing realtime connect for users who pass a custom model definition without an inputSchema. The error surfaces as:

[ { code: "invalid_type", expected: "nonoptional",
    path: ["model","inputSchema"],
    message: "Invalid input: expected nonoptional, received undefined" } ]

This regression is triggered by zod 4.4, which stopped treating z.any() as implicitly optional inside object schemas. Built-in models (models.realtime("lucy-2.1"), etc.) were unaffected because they always set inputSchema. Users following our own examples/sdk-core/realtime/custom-model.ts pattern were broken.

The fix aligns the runtime schema with the existing TypeScript type (CustomModelDefinition.inputSchema?) and works under zod 4.0–4.4+.

Usage (unchanged, now actually works on zod 4.4+)

const customModel: CustomModelDefinition = {
  name: "my-preview-model",
  urlPath: "/v1/stream",
  fps: 20,
  width: 1280,
  height: 720,
};

await client.realtime.connect(stream, { model: customModel, onRemoteStream });

Test plan

  • Reproduce the user error against zod@4.4.1 with the old schema (matches reported error verbatim)
  • Verify fixed schema accepts custom models with and without inputSchema under zod@4.4.1
  • Verify built-in models still validate
  • Verify the schema still rejects truly-invalid model definitions (missing fps, etc.)
  • pnpm --filter @decartai/sdk typecheck
  • pnpm --filter @decartai/sdk test (175/175 pass)

Note

Low Risk
Low risk, single-field validation change that relaxes runtime model definition parsing to match existing TS types; main impact is allowing previously-rejected custom realtime model configs under newer Zod versions.

Overview
Fixes a regression in @decartai/sdk model validation by making modelDefinitionSchema.inputSchema optional, aligning runtime Zod validation with CustomModelDefinition.inputSchema?.

This restores compatibility for custom model definitions (notably realtime connect) that omit inputSchema, which started failing validation under Zod 4.4+.

Reviewed by Cursor Bugbot for commit 27d52eb. Bugbot is set up for automated code reviews on this repo. Configure here.

Zod 4.4 stopped treating `z.any()` as implicitly optional inside
`z.object`, so omitting `inputSchema` on a `CustomModelDefinition`
started failing realtime connect validation. Mark `inputSchema` as
explicitly optional to match the TypeScript type and keep custom
models working across zod 4.0–4.4+.
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 30, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@decartai/sdk@126

commit: 27d52eb

@AdirAmsalem AdirAmsalem merged commit f946a90 into main Apr 30, 2026
5 checks passed
@AdirAmsalem AdirAmsalem deleted the realtime-input-schema-error branch April 30, 2026 08:58
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