Skip to content

Conversation

@AlemTuzlak
Copy link
Contributor

@AlemTuzlak AlemTuzlak commented Dec 20, 2025

🎯 Changes

Standard schema compliance PR
image

βœ… Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

πŸš€ Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

Release Notes

  • New Features

    • Added Standard Schema / Standard JSON Schema support for flexible schema validation, enabling compatibility with multiple schema libraries (Zod v4+, ArkType, Valibot) and plain JSON Schema across TanStack AI packages.
  • Chores

    • Updated dependencies and minor version bumps across packages.

✏️ Tip: You can customize this high-level summary in your review settings.

@AlemTuzlak AlemTuzlak requested a review from a team December 20, 2025 14:00
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 20, 2025

Walkthrough

This PR migrates TanStack AI from Zod-specific schema handling to Standard JSON Schema support. It introduces a new schema-converter module with type guards and validation utilities, replaces Zod types (z.ZodType, z.infer) with Standard Schema types (SchemaInput, InferSchemaType) across core interfaces, removes the zod-converter module, and updates dependencies to use zod ^4.2.0 with the new @standard-schema/spec package.

Changes

Cohort / File(s) Summary
Dependency Updates
.changeset/honest-bugs-tell.md, examples/ts-*/package.json, packages/typescript/ai-client/package.json, packages/typescript/smoke-tests/adapters/package.json, testing/panel/package.json
Minor version bumps across TanStack AI packages. Zod upgraded from ^4.1.13 to ^4.2.0 in dev/runtime dependencies. Adds changeset documenting Standard Schema support.
Core Dependencies
packages/typescript/ai/package.json
Removes peerDependencies block (@alcyone-labs/zod-to-json-schema, zod). Adds @standard-schema/spec ^1.1.0 as devDependency. Updates zod to ^4.2.0 in devDependencies.
Package.json Removals
packages/typescript/ai-react/package.json, packages/typescript/ai-svelte/package.json, packages/typescript/ai-solid/package.json, packages/typescript/ai-vue/package.json
Removes zod from devDependencies or transitive dependencies.
Type System Migration
packages/typescript/ai/src/types.ts
Replaces z.ZodType with StandardJSONSchemaV1 in SchemaInput union. Updates InferSchemaType to derive from StandardJSONSchemaV1 instead of z.infer. Broadens JSONSchema properties (enum, const, default, examples) from any to unknown. Updates Tool generic defaults and documentation.
Tool Definition Updates
packages/typescript/ai/src/activities/chat/tools/tool-definition.ts
Replaces Zod generics with SchemaInput across ServerTool, ClientTool, ToolDefinitionInstance. Updates InferToolInput and InferToolOutput to use StandardJSONSchemaV1. Changes metadata type from Record<string, any> to Record<string, unknown>. Expands documentation for Standard JSON Schema library support.
Chat Activity Refactor
packages/typescript/ai/src/activities/chat/index.ts
Replaces z.ZodType with SchemaInput in type parameters. Swaps convertZodToJsonSchema for convertSchemaToJsonSchema. Implements validation using parseWithStandardSchema instead of Zod safeParse. Updates runAgenticStructuredOutput to return InferSchemaType.
Schema Converter Utilities
packages/typescript/ai/src/activities/chat/tools/schema-converter.ts
New module providing type guards (isStandardJSONSchema, isStandardSchema), validation helpers (validateWithStandardSchema, parseWithStandardSchema), and conversion (convertSchemaToJsonSchema). Includes internal helper makeStructuredOutputCompatible for OpenAI structured output adaptation.
Tool Calls Validation
packages/typescript/ai/src/activities/chat/tools/tool-calls.ts
Replaces isZodSchema and Zod.parse with isStandardSchema and parseWithStandardSchema. Updates error handling for unknown validation errors. Removes Zod-specific code paths for both streaming and non-streaming tool execution.
Removed Zod Converter
packages/typescript/ai/src/activities/chat/tools/zod-converter.ts
Removes entire module containing Zod-to-JSON Schema conversion and structured output transformation logic.
Export Updates
packages/typescript/ai/src/index.ts
Replaces export of convertZodToJsonSchema with convertSchemaToJsonSchema. Adds comment documenting Standard JSON Schema usage.
Adapter Updates
packages/typescript/ai-anthropic/src/tools/custom-tool.ts, packages/typescript/ai-ollama/src/adapters/text.ts
Updates customTool signature to use SchemaInput instead of z.ZodType. Adds type assertion for Ollama tool parameters to ensure JSON Schema compatibility.
Test Updates
packages/typescript/ai/tests/standard-converter.test.ts
Migrates from convertZodToJsonSchema to convertSchemaToJsonSchema. Adds test coverage for new type guards (isStandardJSONSchema, isStandardSchema) and validation utilities.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • schema-converter.ts: New module with multiple type guards and validation utilities; review logic for StandardJSONSchemaV1 detection, validation result mapping, and structured output transformation
  • Type system changes (types.ts, tool-definition.ts): Widespread generic parameter updates; verify StandardJSONSchemaV1 inference logic replaces z.infer correctly
  • Validation refactoring (tool-calls.ts, chat/index.ts): Critical changes to error handling and schema validation paths; ensure parseWithStandardSchema behavior matches previous Zod safeParse semantics
  • Removed zod-converter.ts: Verify all logic (structured output transformation) is properly replicated in schema-converter.ts
  • Cross-package consistency: Ensure all dependent packages (ai-anthropic, ai-ollama) align with new SchemaInput types

Poem

🐰 From Zod's strict path to schemas free,
Standard JSON Schema's the key,
Type guards and converters dance with grace,
Validation runs at every place,
TanStack AI finds broader space! πŸŽ‰

Pre-merge checks and finishing touches

βœ… Passed checks (3 passed)
Check name Status Explanation
Title check βœ… Passed The title 'feat: standard (json) schema compliance' clearly and specifically describes the main change: adding Standard Schema and JSON Schema compliance to the TanStack AI packages.
Description check βœ… Passed The description includes a brief summary, completes all checklist items (contributing guide followed, local testing done, changeset generated), and follows the required template structure with proper sections.
Docstring Coverage βœ… Passed Docstring coverage is 91.67% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/standard-schema-compliant

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Dec 20, 2025

View your CI Pipeline Execution β†— for commit 6840646

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... βœ… Succeeded 2m 34s View β†—
nx run-many --targets=build --exclude=examples/** βœ… Succeeded 1m 1s View β†—

☁️ Nx Cloud last updated this comment at 2025-12-20 14:07:57 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 20, 2025

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@165

@tanstack/ai-anthropic

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@165

@tanstack/ai-client

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@165

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@165

@tanstack/ai-gemini

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@165

@tanstack/ai-ollama

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@165

@tanstack/ai-openai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@165

@tanstack/ai-react

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@165

@tanstack/ai-react-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@165

@tanstack/ai-solid

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@165

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@165

@tanstack/ai-svelte

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@165

@tanstack/ai-vue

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@165

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@165

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@165

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@165

commit: 6840646

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/typescript/ai/src/activities/chat/tools/schema-converter.ts (2)

34-47: Minor redundancy in null checks.

Line 40 has a redundant schema !== null check since schema !== null was already verified on line 37. The check on line 41 for schema['~standard'] !== null is the correct one.

πŸ”Ž Proposed fix to remove redundant check
 export function isStandardSchema(schema: unknown): schema is StandardSchemaV1 {
   return (
     typeof schema === 'object' &&
     schema !== null &&
     '~standard' in schema &&
     typeof schema['~standard'] === 'object' &&
-    schema !== null &&
     schema['~standard'] !== null &&
     'version' in schema['~standard'] &&
     schema['~standard'].version === 1 &&
     'validate' in schema['~standard'] &&
     typeof schema['~standard'].validate === 'function'
   )
 }

60-122: Consider handling additional schema constructs for structured output compatibility.

The function correctly handles basic object and array types, but doesn't process complex schema constructs like anyOf, oneOf, or allOf that may contain nested objects. If these constructs are used with forStructuredOutput: true, their nested schemas won't be transformed.

This may be acceptable if such complex schemas aren't commonly used with OpenAI structured output, but worth noting for future enhancement.

packages/typescript/ai/src/activities/chat/index.ts (1)

1108-1114: Consider using async validation for robustness.

parseWithStandardSchema throws if the schema only supports async validation. Since runAgenticStructuredOutput is already an async function, using validateWithStandardSchema would handle both sync and async schemas gracefully.

πŸ”Ž Proposed fix to use async validation
   // Validate the result against the schema if it's a Standard Schema
   if (isStandardSchema(outputSchema)) {
-    return parseWithStandardSchema<InferSchemaType<TSchema>>(
+    const validationResult = await validateWithStandardSchema<InferSchemaType<TSchema>>(
       outputSchema,
       result.data,
     )
+    if (!validationResult.success) {
+      const errorMessages = validationResult.issues
+        .map((issue) => issue.message)
+        .join(', ')
+      throw new Error(`Validation failed: ${errorMessages}`)
+    }
+    return validationResult.data
   }

This would also require adding validateWithStandardSchema to the imports on line 14.

πŸ“œ Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 254b248 and 6840646.

β›” Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
πŸ“’ Files selected for processing (23)
  • .changeset/honest-bugs-tell.md (1 hunks)
  • examples/ts-react-chat/package.json (1 hunks)
  • examples/ts-solid-chat/package.json (1 hunks)
  • examples/ts-svelte-chat/package.json (1 hunks)
  • examples/ts-vue-chat/package.json (1 hunks)
  • packages/typescript/ai-anthropic/src/tools/custom-tool.ts (2 hunks)
  • packages/typescript/ai-client/package.json (1 hunks)
  • packages/typescript/ai-ollama/src/adapters/text.ts (1 hunks)
  • packages/typescript/ai-react/package.json (1 hunks)
  • packages/typescript/ai-solid/package.json (1 hunks)
  • packages/typescript/ai-svelte/package.json (1 hunks)
  • packages/typescript/ai-vue/package.json (1 hunks)
  • packages/typescript/ai/package.json (1 hunks)
  • packages/typescript/ai/src/activities/chat/index.ts (13 hunks)
  • packages/typescript/ai/src/activities/chat/tools/schema-converter.ts (1 hunks)
  • packages/typescript/ai/src/activities/chat/tools/tool-calls.ts (9 hunks)
  • packages/typescript/ai/src/activities/chat/tools/tool-definition.ts (8 hunks)
  • packages/typescript/ai/src/activities/chat/tools/zod-converter.ts (0 hunks)
  • packages/typescript/ai/src/index.ts (1 hunks)
  • packages/typescript/ai/src/types.ts (7 hunks)
  • packages/typescript/ai/tests/standard-converter.test.ts (33 hunks)
  • packages/typescript/smoke-tests/adapters/package.json (1 hunks)
  • testing/panel/package.json (1 hunks)
πŸ’€ Files with no reviewable changes (1)
  • packages/typescript/ai/src/activities/chat/tools/zod-converter.ts
🧰 Additional context used
πŸ““ Path-based instructions (6)
examples/**

πŸ“„ CodeRabbit inference engine (CLAUDE.md)

Examples are not built by Nx and should be run independently from their directories with pnpm dev or pnpm install && pnpm dev

Files:

  • examples/ts-solid-chat/package.json
  • examples/ts-vue-chat/package.json
  • examples/ts-svelte-chat/package.json
  • examples/ts-react-chat/package.json
**/*.{ts,tsx}

πŸ“„ CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Use tree-shakeable adapter architecture for provider implementations - export specialized adapters (text, embedding, summarize, image) as separate imports from /adapters subpath rather than monolithic adapters
Use Zod for runtime schema validation and type inference, particularly for tool input/output definitions with toolDefinition() and Zod schema inference
Implement isomorphic tool system using toolDefinition() with .server() and .client() implementations for dual-environment execution
Use type-safe per-model configuration with provider options typed based on selected model to ensure compile-time safety
Implement stream processing with StreamProcessor for handling chunked responses and support partial JSON parsing for streaming AI responses

Files:

  • packages/typescript/ai-anthropic/src/tools/custom-tool.ts
  • packages/typescript/ai/src/index.ts
  • packages/typescript/ai-ollama/src/adapters/text.ts
  • packages/typescript/ai/tests/standard-converter.test.ts
  • packages/typescript/ai/src/activities/chat/tools/schema-converter.ts
  • packages/typescript/ai/src/activities/chat/tools/tool-definition.ts
  • packages/typescript/ai/src/activities/chat/index.ts
  • packages/typescript/ai/src/types.ts
  • packages/typescript/ai/src/activities/chat/tools/tool-calls.ts
**/*.{ts,tsx,js,jsx}

πŸ“„ CodeRabbit inference engine (CLAUDE.md)

Use camelCase for function and variable names throughout the codebase

Files:

  • packages/typescript/ai-anthropic/src/tools/custom-tool.ts
  • packages/typescript/ai/src/index.ts
  • packages/typescript/ai-ollama/src/adapters/text.ts
  • packages/typescript/ai/tests/standard-converter.test.ts
  • packages/typescript/ai/src/activities/chat/tools/schema-converter.ts
  • packages/typescript/ai/src/activities/chat/tools/tool-definition.ts
  • packages/typescript/ai/src/activities/chat/index.ts
  • packages/typescript/ai/src/types.ts
  • packages/typescript/ai/src/activities/chat/tools/tool-calls.ts
packages/typescript/*/src/index.ts

πŸ“„ CodeRabbit inference engine (CLAUDE.md)

Export tree-shakeable adapters with clear subpath exports in package.json (e.g., @tanstack/ai/adapters, @tanstack/ai-openai/adapters) to minimize bundle size

Files:

  • packages/typescript/ai/src/index.ts
packages/typescript/*/src/adapters/*.ts

πŸ“„ CodeRabbit inference engine (CLAUDE.md)

Create individual adapter implementations for each provider capability (text, embed, summarize, image) with separate exports to enable tree-shaking

Files:

  • packages/typescript/ai-ollama/src/adapters/text.ts
**/*.test.ts

πŸ“„ CodeRabbit inference engine (CLAUDE.md)

Write unit tests using Vitest alongside source files with .test.ts naming convention

Files:

  • packages/typescript/ai/tests/standard-converter.test.ts
🧠 Learnings (12)
πŸ““ Common learnings
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to **/*.{ts,tsx} : Use Zod for runtime schema validation and type inference, particularly for tool input/output definitions with `toolDefinition()` and Zod schema inference
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to **/*.{ts,tsx} : Use Zod for runtime schema validation and type inference, particularly for tool input/output definitions with `toolDefinition()` and Zod schema inference

Applied to files:

  • packages/typescript/ai-client/package.json
  • examples/ts-solid-chat/package.json
  • packages/typescript/smoke-tests/adapters/package.json
  • testing/panel/package.json
  • packages/typescript/ai-anthropic/src/tools/custom-tool.ts
  • packages/typescript/ai-react/package.json
  • packages/typescript/ai/package.json
  • packages/typescript/ai/src/index.ts
  • packages/typescript/ai-ollama/src/adapters/text.ts
  • packages/typescript/ai/tests/standard-converter.test.ts
  • packages/typescript/ai-vue/package.json
  • examples/ts-react-chat/package.json
  • packages/typescript/ai/src/activities/chat/tools/schema-converter.ts
  • packages/typescript/ai/src/activities/chat/tools/tool-definition.ts
  • packages/typescript/ai/src/activities/chat/index.ts
  • packages/typescript/ai/src/types.ts
  • packages/typescript/ai/src/activities/chat/tools/tool-calls.ts
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to **/*.test.ts : Write unit tests using Vitest alongside source files with `.test.ts` naming convention

Applied to files:

  • packages/typescript/ai-client/package.json
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to packages/typescript/*/src/index.ts : Export tree-shakeable adapters with clear subpath exports in package.json (e.g., `tanstack/ai/adapters`, `tanstack/ai-openai/adapters`) to minimize bundle size

Applied to files:

  • packages/typescript/smoke-tests/adapters/package.json
  • packages/typescript/ai-anthropic/src/tools/custom-tool.ts
  • packages/typescript/ai-solid/package.json
  • packages/typescript/ai-react/package.json
  • packages/typescript/ai/package.json
  • packages/typescript/ai/src/index.ts
  • packages/typescript/ai-ollama/src/adapters/text.ts
  • packages/typescript/ai-svelte/package.json
  • packages/typescript/ai-vue/package.json
  • packages/typescript/ai/src/activities/chat/tools/schema-converter.ts
  • .changeset/honest-bugs-tell.md
  • packages/typescript/ai/src/types.ts
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to packages/typescript/*/src/adapters/*.ts : Create individual adapter implementations for each provider capability (text, embed, summarize, image) with separate exports to enable tree-shaking

Applied to files:

  • packages/typescript/smoke-tests/adapters/package.json
  • packages/typescript/ai-ollama/src/adapters/text.ts
  • packages/typescript/ai/src/activities/chat/tools/schema-converter.ts
  • .changeset/honest-bugs-tell.md
  • packages/typescript/ai/src/activities/chat/index.ts
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to **/*.{ts,tsx} : Use tree-shakeable adapter architecture for provider implementations - export specialized adapters (text, embedding, summarize, image) as separate imports from `/adapters` subpath rather than monolithic adapters

Applied to files:

  • packages/typescript/smoke-tests/adapters/package.json
  • packages/typescript/ai-ollama/src/adapters/text.ts
  • .changeset/honest-bugs-tell.md
  • packages/typescript/ai/src/activities/chat/index.ts
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to **/*.{ts,tsx} : Implement isomorphic tool system using `toolDefinition()` with `.server()` and `.client()` implementations for dual-environment execution

Applied to files:

  • packages/typescript/ai-anthropic/src/tools/custom-tool.ts
  • packages/typescript/ai-ollama/src/adapters/text.ts
  • packages/typescript/ai/src/activities/chat/tools/tool-definition.ts
  • packages/typescript/ai/src/activities/chat/index.ts
  • packages/typescript/ai/src/types.ts
  • packages/typescript/ai/src/activities/chat/tools/tool-calls.ts
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to packages/*/package.json : Use `workspace:*` protocol for internal package dependencies in package.json (e.g., `"tanstack/ai": "workspace:*"`)

Applied to files:

  • packages/typescript/ai-solid/package.json
  • packages/typescript/ai-react/package.json
  • packages/typescript/ai/package.json
  • packages/typescript/ai-svelte/package.json
  • packages/typescript/ai-vue/package.json
  • .changeset/honest-bugs-tell.md
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Implement framework integrations using the headless `tanstack/ai-client` for state management with framework-specific hooks (useChat) on top

Applied to files:

  • packages/typescript/ai-solid/package.json
  • packages/typescript/ai-vue/package.json
  • .changeset/honest-bugs-tell.md
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to packages/typescript/*/src/model-meta.ts : Maintain model metadata files that define provider options and capabilities per model for per-model type safety

Applied to files:

  • packages/typescript/ai/src/activities/chat/tools/schema-converter.ts
  • packages/typescript/ai/src/activities/chat/tools/tool-definition.ts
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to .eslintrc* : Use ESLint with custom TanStack config for linting all TypeScript and JavaScript files

Applied to files:

  • .changeset/honest-bugs-tell.md
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to **/*.{ts,tsx} : Implement stream processing with StreamProcessor for handling chunked responses and support partial JSON parsing for streaming AI responses

Applied to files:

  • packages/typescript/ai/src/activities/chat/index.ts
🧬 Code graph analysis (5)
packages/typescript/ai-anthropic/src/tools/custom-tool.ts (1)
packages/typescript/ai/src/types.ts (1)
  • SchemaInput (77-77)
packages/typescript/ai/tests/standard-converter.test.ts (2)
packages/typescript/ai/src/activities/chat/tools/schema-converter.ts (5)
  • convertSchemaToJsonSchema (199-262)
  • isStandardJSONSchema (14-28)
  • isStandardSchema (34-47)
  • parseWithStandardSchema (308-332)
  • validateWithStandardSchema (271-296)
packages/typescript/ai/src/index.ts (1)
  • convertSchemaToJsonSchema (52-52)
packages/typescript/ai/src/activities/chat/tools/schema-converter.ts (2)
packages/typescript/ai/src/index.ts (1)
  • convertSchemaToJsonSchema (52-52)
packages/typescript/ai/src/types.ts (2)
  • SchemaInput (77-77)
  • JSONSchema (25-64)
packages/typescript/ai/src/activities/chat/index.ts (2)
packages/typescript/ai/src/types.ts (2)
  • SchemaInput (77-77)
  • InferSchemaType (84-85)
packages/typescript/ai/src/activities/chat/tools/schema-converter.ts (3)
  • convertSchemaToJsonSchema (199-262)
  • isStandardSchema (34-47)
  • parseWithStandardSchema (308-332)
packages/typescript/ai/src/activities/chat/tools/tool-calls.ts (1)
packages/typescript/ai/src/activities/chat/tools/schema-converter.ts (2)
  • isStandardSchema (34-47)
  • parseWithStandardSchema (308-332)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Preview
  • GitHub Check: Test
πŸ”‡ Additional comments (48)
packages/typescript/smoke-tests/adapters/package.json (1)

27-27: Zod version bump to 4.2.0 aligns with PR migration goals.

The patch-level bump from ^4.1.13 to ^4.2.0 is appropriate for this test package and aligns with the PR's broader migration to Standard JSON Schema compliance. Since you've confirmed local testing with pnpm run test:pr, the smoke tests should validate compatibility with the new Zod version.

packages/typescript/ai-solid/package.json (1)

41-43: Source code properly updatedβ€”Zod dependencies removed.

Verified that all Zod imports and type references have been removed from the ai-solid package source code. The removal of the zod dependency aligns with the PR's migration to Standard JSON Schema support, and the source files have been fully updated accordingly.

packages/typescript/ai-vue/package.json (1)

41-44: Zod dependency removal is complete in ai-vue package.

The removal of the zod dependency from packages/typescript/ai-vue/package.json aligns with the PR's migration to Standard JSON Schema support. Verification confirms no remaining zod imports or references exist in the source code, and the workspace dependencies (@tanstack/ai and @tanstack/ai-client) provide the necessary schema functionality.

packages/typescript/ai/src/activities/chat/tools/tool-definition.ts (4)

1-1: LGTM: Standard Schema integration.

The import of StandardJSONSchemaV1 from @standard-schema/spec properly enables the Standard JSON Schema support as intended by this PR.


34-34: Good practice: Using unknown instead of any.

Changing the metadata type from Record<string, any> to Record<string, unknown> improves type safety by requiring explicit type assertions when accessing metadata values.


136-138: LGTM: Documentation updated for Standard Schema support.

The JSDoc correctly documents support for Standard JSON Schema compliant libraries (Zod v4+, ArkType, Valibot) and plain JSON Schema objects, aligning with the PR's migration goals.


64-83: Backward compatibility is fully preserved.

Plain JSON Schema objects continue to work correctly with toolDefinition(). The type inference logic correctly prioritizes StandardJSONSchemaV1 for inference while gracefully falling back to unknown (equivalent to any) for plain JSONSchema objectsβ€”exactly as documented in docs/guides/tools.md. The implementation includes working examples demonstrating that tool definitions with plain JSONSchema objects function properly, with arguments typed as any as expected. Existing code using plain JSONSchema objects will continue to work without breaking changes.

packages/typescript/ai-client/package.json (1)

51-51: Minor version upgrade within stable Zod 4 release.

Zod 4.2.0 introduces new features (z.fromJSONSchema, z.xor, z.looseRecord) rather than breaking changes. The breaking changes previously mentioned (error customization, default value logic) were from the Zod 3β†’4 migration, not this minor upgrade. Verify test compatibility with the new minor version, but the concerns about major architectural changes do not apply here.

packages/typescript/ai-react/package.json (1)

52-52: Zod was not used by ai-react tests.

The ai-react package does not import or use Zod for schema validation. Its tests rely on simple TypeScript interfaces and mock adapters (createMockConnectionAdapter, createTextChunks, createToolCallChunks) rather than Zod schemas. Zod is available transitively from @tanstack/ai (which has it as a devDependency) if the package needs it in the future. The removal from ai-react's devDependencies is correct.

examples/ts-react-chat/package.json (1)

41-41: Example is compatible with Zod 4.2.0 β€” no breaking changes detected in current schema patterns.

The example uses only standard Zod patterns (z.object, z.array, primitive validators, z.union, .describe) that remain unchanged in Zod 4. No usage of breaking-change APIs like z.function(), z.nonempty(), top-level string validators (z.email(), etc.), or z.record().

packages/typescript/ai-svelte/package.json (1)

59-59: Zod removal from ai-svelte is validβ€”no action needed.

The ai-svelte package is a client-side Svelte wrapper that does not directly use Zod. The test suite tests only the chat interface and requires no Zod dependency. Tool definitions with Zod schemas are server-side code in @tanstack/ai, not part of ai-svelte. Zod is listed as a devDependency (not production) in @tanstack/ai and @tanstack/ai-client, making it unavailable transitively to ai-svelte consumers anyway. Tests will pass without this dependency.

examples/ts-svelte-chat/package.json (1)

26-26: No Zod compatibility issues found. The example uses only basic, stable Zod features that are fully compatible with version 4.2.0 and will not break in future 4.x releases.

packages/typescript/ai-ollama/src/adapters/text.ts (1)

297-312: Verify schema compatibility between ai layer and Ollama's JSON Schema expectations.

The type assertion as OllamaTool['function']['parameters'] bypasses TypeScript checking for schema format compliance. While Zod schemas are converted to JSON Schema for LLM providers, Ollama's tool parameters only support a limited subset of JSON Schema (e.g., strict type: string values). The fallback default provides some safety, but adding explicit validation of the schema structure before assertion would catch incompatibilities earlier:

// Validate that converted schema conforms to Ollama's stricter expectations
// before applying the type assertion

Alternatively, document the specific JSON Schema constraints that Ollama enforces to clarify the schema conversion contract between the ai layer and this adapter.

examples/ts-vue-chat/package.json (1)

24-24: The example application is compatible with Zod 4.2.0. The code uses only basic, stable schema definition APIs (z.object(), z.array(), z.string(), z.number(), z.boolean(), z.union(), and .describe()), which remain unchanged across Zod v4. Breaking changes in Zod v4 primarily affect error handling and customization patterns, not the fundamental schema building APIs used in this example.

Likely an incorrect or invalid review comment.

examples/ts-solid-chat/package.json (1)

38-38: Zod version update aligns with migration.

The zod upgrade to ^4.2.0 is consistent with the broader Standard Schema migration. See verification request in testing/panel/package.json for compatibility checks.

.changeset/honest-bugs-tell.md (1)

1-15: LGTM! Clear and comprehensive changeset.

The changeset correctly identifies all affected packages and documents the Standard Schema support feature. The minor version bumps are appropriate for this new capability.

packages/typescript/ai/src/index.ts (1)

51-52: Confirm breaking API change is intentional.

The export name change from convertZodToJsonSchema to convertSchemaToJsonSchema is a breaking change that will require users to update their imports. The new name better reflects the Standard Schema compliance.

This appears intentional given the PR's migration objective. Ensure this breaking change is documented in migration guides or release notes.

packages/typescript/ai-anthropic/src/tools/custom-tool.ts (2)

1-1: Import updated to support Standard Schema.

The import change correctly adds SchemaInput and removes the Zod-specific import, aligning with the PR's Standard Schema migration objective.


55-55: Type change broadens schema support.

Changing from z.ZodType to SchemaInput allows the function to accept both Standard JSON Schema and plain JSON Schema objects, improving flexibility while maintaining backward compatibility through the type union.

packages/typescript/ai/package.json (1)

62-64: Peer dependency removal improves flexibility.

Moving zod from peerDependencies to devDependencies is a significant improvement. Users are no longer required to install zod specificallyβ€”they can use any Standard Schema-compliant validation library. The addition of @standard-schema/spec provides the standard interface definitions.

This change aligns well with the PR's objective of Standard Schema compliance and reduces the library's opinionated dependencies.

packages/typescript/ai/tests/standard-converter.test.ts (5)

1-9: LGTM! Imports updated for new schema converter API.

The import changes correctly reflect the migration from Zod-specific to Standard Schema-based utilities, including all new helper functions.


184-186: Improved array items handling.

The updated assertion correctly handles both single schema and tuple schema cases by checking if itemsSchema is not an array before accessing the type property. This prevents potential runtime errors with tuple schemas.


201-206: Consistent array items handling for nested objects.

The guard check !Array.isArray(usersItems) ensures type safety when accessing nested properties, matching the pattern established in the previous test case.


560-604: Comprehensive type guard test coverage.

The new test suites for isStandardJSONSchema and isStandardSchema provide thorough coverage of both positive cases (Zod v4 schemas) and negative cases (plain objects, null, undefined, primitives).


606-688: Well-structured validation utility tests.

The test suites for parseWithStandardSchema and validateWithStandardSchema cover:

  • Valid data parsing/validation
  • Invalid data error handling
  • Passthrough behavior for non-Standard Schema inputs

This ensures the utilities handle both Standard Schema and legacy inputs correctly.

packages/typescript/ai/src/activities/chat/tools/tool-calls.ts (7)

1-1: Import updated to Standard Schema utilities.

The import change correctly brings in the new Standard Schema validation utilities, removing the previous Zod-specific dependencies.


125-147: Excellent type safety improvements.

The changes demonstrate multiple improvements:

  1. args type changed from any to unknown for better type safety
  2. Validation updated to use isStandardSchema and parseWithStandardSchema
  3. Error handling properly typed with unknown and type guards
  4. Clear, descriptive error messages

152-170: Consistent output validation pattern.

The output validation follows the same pattern as input validation, ensuring consistent behavior and error handling throughout the tool execution flow.


174-182: Improved error handling with proper type guards.

The error handling correctly:

  • Catches unknown errors (best practice)
  • Uses type guard to safely extract error message
  • Provides fallback for non-Error objects
  • Includes descriptive error message for missing execute function

290-320: Type safety and validation consistency maintained.

The executeToolCalls function applies the same type safety improvements and Standard Schema validation patterns seen in the executeTools method, ensuring consistency across the codebase.


401-409: Output validation consistently applied.

Output schema validation is properly applied in both approval-required and immediate execution paths, ensuring data integrity regardless of the execution path.

Also applies to: 459-467


420-430: Robust error handling across all execution paths.

Error handling is consistently implemented across all tool execution paths with proper type guards and fallback messages, improving reliability and debuggability.

Also applies to: 476-485

testing/panel/package.json (1)

35-35: Zod 4.2.0 is stable and fully compatible with Standard Schema.

Zod 4 is now stable, and version 4.2.0 was released December 15, 2025. Zod 4.2.0 implements Standard Schema support. Note: Standard Schema versioning uses "StandardSchemaV1" rather than "1.1.0"β€”Standard Schema 1.0 is the specification implemented by Zod and other validation libraries.

packages/typescript/ai/src/types.ts (6)

23-64: LGTM! JSONSchema interface properly broadened for flexibility.

The updates correctly broaden enum, const, default, and examples to unknown types, and the index signature [key: string]: unknown appropriately allows additional JSON Schema properties for extensibility.


76-85: LGTM! SchemaInput and InferSchemaType are well-designed.

The SchemaInput union correctly accepts both Standard JSON Schema compliant schemas and plain JSON Schema objects. InferSchemaType appropriately extracts the input type from Standard schemas and falls back to unknown for plain JSON Schema (which is safer than any since types can't be inferred at compile time).


328-331: LGTM! Tool interface generics properly updated.

The generic parameters TInput and TOutput now correctly extend SchemaInput with appropriate defaults, enabling support for any Standard JSON Schema compliant library while maintaining type safety.


396-403: Good documentation on runtime validation limitations.

The explicit note that "Plain JSON Schema output validation is not performed at runtime" is helpful for users to understand the behavioral difference between Standard Schema and plain JSON Schema. This is an important distinction.


623-630: LGTM! TextOptions.outputSchema updated correctly.

The outputSchema property now accepts SchemaInput, enabling structured output with any Standard JSON Schema compliant library or plain JSON Schema.


1-1: Import from @standard-schema/spec is appropriate.

The @standard-schema/spec package is at version 1.0.0 and contains no runtime code and only exports types. The package guarantees no breaking changes without a major version bump, making StandardJSONSchemaV1 a stable type import for Standard Schema compliance.

packages/typescript/ai/src/activities/chat/tools/schema-converter.ts (4)

14-28: LGTM! isStandardJSONSchema type guard is comprehensive.

The type guard correctly checks for the ~standard property, version 1, and the presence of the jsonSchema.input function which is the key differentiator for Standard JSON Schema compliance.


199-262: LGTM! convertSchemaToJsonSchema is well-implemented.

The function correctly:

  1. Extracts JSON Schema from Standard JSON Schema using the ~standard.jsonSchema.input() method with target: 'draft-07'
  2. Removes the $schema property not needed by LLM providers
  3. Normalizes object schemas to ensure type, properties, and required are present
  4. Applies structured output transformations conditionally
  5. Passes through plain JSON Schema objects unchanged

271-296: LGTM! validateWithStandardSchema correctly handles async validation.

The function properly:

  1. Returns data as-is for non-Standard Schema inputs (graceful fallback)
  2. Awaits the validation result
  3. Maps validation issues to a simplified format with optional path

308-332: LGTM! parseWithStandardSchema provides synchronous validation with proper async detection.

The function correctly:

  1. Handles non-Standard Schema by returning data as-is
  2. Detects async-only schemas and throws a helpful error directing users to validateWithStandardSchema
  3. Aggregates all validation issues into a single error message
packages/typescript/ai/src/activities/chat/index.ts (5)

11-15: LGTM! Schema converter utilities properly imported.

The imports correctly bring in convertSchemaToJsonSchema, isStandardSchema, and parseWithStandardSchema for use in the chat activity.


55-58: LGTM! Generic types and TextActivityResult correctly updated.

The TSchema generic now extends SchemaInput | undefined, and TextActivityResult correctly uses InferSchemaType<TSchema> for the structured output case. This maintains type safety while supporting the new schema flexibility.

Also applies to: 168-175


376-385: LGTM! Tool schemas correctly converted before adapter call.

The code properly maps over tools and converts inputSchema and outputSchema using convertSchemaToJsonSchema before passing to the adapter. This ensures adapters receive plain JSON Schema regardless of the original schema type.


1091-1118: LGTM! Structured output validation correctly implemented.

The implementation properly:

  1. Converts the schema to JSON Schema for the adapter call
  2. Uses isStandardSchema to determine if runtime validation should be applied
  3. Uses parseWithStandardSchema for Standard Schema to validate/transform the result
  4. Falls back to returning raw data for plain JSON Schema (as documented in types.ts)

This aligns with the note in Tool.outputSchema documentation that "Plain JSON Schema output validation is not performed at runtime."


1069-1072: LGTM! Good use of Record<string, unknown> for stricter typing.

Changing from Record<string, any> to Record<string, unknown> improves type safety by requiring explicit type assertions when accessing properties.

@AlemTuzlak AlemTuzlak merged commit c5df33c into main Dec 20, 2025
6 checks passed
@AlemTuzlak AlemTuzlak deleted the feat/standard-schema-compliant branch December 20, 2025 19:50
@github-actions github-actions bot mentioned this pull request Dec 20, 2025
LuggaPugga pushed a commit to LuggaPugga/ai that referenced this pull request Jan 5, 2026
* feat: standard (json) schema compliance

* add changeset

* update lock

* ci: apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
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