-
-
Notifications
You must be signed in to change notification settings - Fork 111
feat: standard (json) schema compliance #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis 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 Changes
Estimated code review effortπ― 4 (Complex) | β±οΈ ~45 minutes
Poem
Pre-merge checks and finishing touchesβ Passed checks (3 passed)
β¨ Finishing touches
π§ͺ Generate unit tests (beta)
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. Comment |
|
View your CI Pipeline Execution β for commit 6840646
βοΈ Nx Cloud last updated this comment at |
@tanstack/ai
@tanstack/ai-anthropic
@tanstack/ai-client
@tanstack/ai-devtools-core
@tanstack/ai-gemini
@tanstack/ai-ollama
@tanstack/ai-openai
@tanstack/ai-react
@tanstack/ai-react-ui
@tanstack/ai-solid
@tanstack/ai-solid-ui
@tanstack/ai-svelte
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
commit: |
There was a problem hiding this 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 !== nullcheck sinceschema !== nullwas already verified on line 37. The check on line 41 forschema['~standard'] !== nullis 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, orallOfthat may contain nested objects. If these constructs are used withforStructuredOutput: 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.
parseWithStandardSchemathrows if the schema only supports async validation. SincerunAgenticStructuredOutputis already an async function, usingvalidateWithStandardSchemawould 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
validateWithStandardSchemato the imports on line 14.
π Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
β Files ignored due to path filters (1)
pnpm-lock.yamlis 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 devorpnpm install && pnpm dev
Files:
examples/ts-solid-chat/package.jsonexamples/ts-vue-chat/package.jsonexamples/ts-svelte-chat/package.jsonexamples/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/adapterssubpath rather than monolithic adapters
Use Zod for runtime schema validation and type inference, particularly for tool input/output definitions withtoolDefinition()and Zod schema inference
Implement isomorphic tool system usingtoolDefinition()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.tspackages/typescript/ai/src/index.tspackages/typescript/ai-ollama/src/adapters/text.tspackages/typescript/ai/tests/standard-converter.test.tspackages/typescript/ai/src/activities/chat/tools/schema-converter.tspackages/typescript/ai/src/activities/chat/tools/tool-definition.tspackages/typescript/ai/src/activities/chat/index.tspackages/typescript/ai/src/types.tspackages/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.tspackages/typescript/ai/src/index.tspackages/typescript/ai-ollama/src/adapters/text.tspackages/typescript/ai/tests/standard-converter.test.tspackages/typescript/ai/src/activities/chat/tools/schema-converter.tspackages/typescript/ai/src/activities/chat/tools/tool-definition.tspackages/typescript/ai/src/activities/chat/index.tspackages/typescript/ai/src/types.tspackages/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.tsnaming 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.jsonexamples/ts-solid-chat/package.jsonpackages/typescript/smoke-tests/adapters/package.jsontesting/panel/package.jsonpackages/typescript/ai-anthropic/src/tools/custom-tool.tspackages/typescript/ai-react/package.jsonpackages/typescript/ai/package.jsonpackages/typescript/ai/src/index.tspackages/typescript/ai-ollama/src/adapters/text.tspackages/typescript/ai/tests/standard-converter.test.tspackages/typescript/ai-vue/package.jsonexamples/ts-react-chat/package.jsonpackages/typescript/ai/src/activities/chat/tools/schema-converter.tspackages/typescript/ai/src/activities/chat/tools/tool-definition.tspackages/typescript/ai/src/activities/chat/index.tspackages/typescript/ai/src/types.tspackages/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.jsonpackages/typescript/ai-anthropic/src/tools/custom-tool.tspackages/typescript/ai-solid/package.jsonpackages/typescript/ai-react/package.jsonpackages/typescript/ai/package.jsonpackages/typescript/ai/src/index.tspackages/typescript/ai-ollama/src/adapters/text.tspackages/typescript/ai-svelte/package.jsonpackages/typescript/ai-vue/package.jsonpackages/typescript/ai/src/activities/chat/tools/schema-converter.ts.changeset/honest-bugs-tell.mdpackages/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.jsonpackages/typescript/ai-ollama/src/adapters/text.tspackages/typescript/ai/src/activities/chat/tools/schema-converter.ts.changeset/honest-bugs-tell.mdpackages/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.jsonpackages/typescript/ai-ollama/src/adapters/text.ts.changeset/honest-bugs-tell.mdpackages/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.tspackages/typescript/ai-ollama/src/adapters/text.tspackages/typescript/ai/src/activities/chat/tools/tool-definition.tspackages/typescript/ai/src/activities/chat/index.tspackages/typescript/ai/src/types.tspackages/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.jsonpackages/typescript/ai-react/package.jsonpackages/typescript/ai/package.jsonpackages/typescript/ai-svelte/package.jsonpackages/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.jsonpackages/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.tspackages/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
zoddependency 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
zoddependency frompackages/typescript/ai-vue/package.jsonaligns 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/aiand@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
StandardJSONSchemaV1from@standard-schema/specproperly enables the Standard JSON Schema support as intended by this PR.
34-34: Good practice: Usingunknowninstead ofany.Changing the metadata type from
Record<string, any>toRecord<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 tounknown(equivalent toany) 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 asanyas 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., stricttype: stringvalues). 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 assertionAlternatively, 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
convertZodToJsonSchematoconvertSchemaToJsonSchemais 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
SchemaInputand removes the Zod-specific import, aligning with the PR's Standard Schema migration objective.
55-55: Type change broadens schema support.Changing from
z.ZodTypetoSchemaInputallows 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
peerDependenciestodevDependenciesis 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/specprovides 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
itemsSchemais not an array before accessing thetypeproperty. 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
isStandardJSONSchemaandisStandardSchemaprovide 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
parseWithStandardSchemaandvalidateWithStandardSchemacover:
- 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:
argstype changed fromanytounknownfor better type safety- Validation updated to use
isStandardSchemaandparseWithStandardSchema- Error handling properly typed with
unknownand type guards- 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
unknownerrors (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
executeToolCallsfunction applies the same type safety improvements and Standard Schema validation patterns seen in theexecuteToolsmethod, 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, andexamplestounknowntypes, and the index signature[key: string]: unknownappropriately allows additional JSON Schema properties for extensibility.
76-85: LGTM! SchemaInput and InferSchemaType are well-designed.The
SchemaInputunion correctly accepts both Standard JSON Schema compliant schemas and plain JSON Schema objects.InferSchemaTypeappropriately extracts the input type from Standard schemas and falls back tounknownfor plain JSON Schema (which is safer thananysince types can't be inferred at compile time).
328-331: LGTM! Tool interface generics properly updated.The generic parameters
TInputandTOutputnow correctly extendSchemaInputwith 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
outputSchemaproperty now acceptsSchemaInput, 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
StandardJSONSchemaV1a 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
~standardproperty, version 1, and the presence of thejsonSchema.inputfunction which is the key differentiator for Standard JSON Schema compliance.
199-262: LGTM! convertSchemaToJsonSchema is well-implemented.The function correctly:
- Extracts JSON Schema from Standard JSON Schema using the
~standard.jsonSchema.input()method withtarget: 'draft-07'- Removes the
$schemaproperty not needed by LLM providers- Normalizes object schemas to ensure
type,properties, andrequiredare present- Applies structured output transformations conditionally
- Passes through plain JSON Schema objects unchanged
271-296: LGTM! validateWithStandardSchema correctly handles async validation.The function properly:
- Returns data as-is for non-Standard Schema inputs (graceful fallback)
- Awaits the validation result
- Maps validation issues to a simplified format with optional path
308-332: LGTM! parseWithStandardSchema provides synchronous validation with proper async detection.The function correctly:
- Handles non-Standard Schema by returning data as-is
- Detects async-only schemas and throws a helpful error directing users to
validateWithStandardSchema- 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, andparseWithStandardSchemafor use in the chat activity.
55-58: LGTM! Generic types and TextActivityResult correctly updated.The
TSchemageneric now extendsSchemaInput | undefined, andTextActivityResultcorrectly usesInferSchemaType<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
inputSchemaandoutputSchemausingconvertSchemaToJsonSchemabefore 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:
- Converts the schema to JSON Schema for the adapter call
- Uses
isStandardSchemato determine if runtime validation should be applied- Uses
parseWithStandardSchemafor Standard Schema to validate/transform the result- Falls back to returning raw data for plain JSON Schema (as documented in types.ts)
This aligns with the note in
Tool.outputSchemadocumentation that "Plain JSON Schema output validation is not performed at runtime."
1069-1072: LGTM! Good use ofRecord<string, unknown>for stricter typing.Changing from
Record<string, any>toRecord<string, unknown>improves type safety by requiring explicit type assertions when accessing properties.
* 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>
π― Changes
Standard schema compliance PR

β Checklist
pnpm run test:pr.π Release Impact
Summary by CodeRabbit
Release Notes
New Features
Chores
βοΈ Tip: You can customize this high-level summary in your review settings.