Skip to content

add support for StandardJSONSchemaV1#2901

Open
phryneas wants to merge 4 commits intoCopilotKit:mainfrom
phryneas:pr/standard-json-schema
Open

add support for StandardJSONSchemaV1#2901
phryneas wants to merge 4 commits intoCopilotKit:mainfrom
phryneas:pr/standard-json-schema

Conversation

@phryneas
Copy link

@phryneas phryneas commented Dec 19, 2025

What does this PR do?

Adds support for Standard JSON Schema, which enables a lot of other validation libraries like ArkType, Valibot etc.

Note that the separate handling of zod is only in place to support old versions of zod - modern versions (>=4.2) support Standard JSON Schema.

I'm not sure how to best test this since I don't know what your policies on new dependencies are.

Related PRs and Issues

Checklist

  • I have read the Contribution Guide
  • If the PR changes or adds functionality, I have updated the relevant documentation

Summary by CodeRabbit

  • New Features

    • Public APIs for tools and renderers now accept Standard JSON Schema–compatible definitions in addition to Zod, and runtime validation for those schemas is supported.
    • Added a helper and schema-detection utility to enable conversion/validation of standard schemas at runtime.
  • Documentation

    • Updated reference and design docs and examples to show the new Standard JSON Schema–compatible parameter type and usage.

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

@vercel
Copy link
Contributor

vercel bot commented Dec 19, 2025

@phryneas is attempting to deploy a commit to the CopilotKit Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 19, 2025

Walkthrough

Adds first-class support for a StandardSchemaWithJSON schema alongside Zod for tool/renderer parameter definitions, including type changes, a runtime type-guard, conditional schema generation, helper to produce runtime Schema, dependency updates, and aligned documentation edits. (47 words)

Changes

Cohort / File(s) Summary
Documentation updates
src/v2.x/apps/docs/reference/frontend-tool.mdx, src/v2.x/apps/docs/reference/use-frontend-tool.mdx, src/v2.x/apps/docs/reference/use-human-in-the-loop.mdx, src/v2.x/docs/ANGULAR_DESIGN.md
Replace parameter/args type references from z.ZodType<T> to StandardSchemaWithJSON<T> (or union with Zod where applicable); update descriptive text and examples to reference StandardJSONSchemaV1-compatible schemas.
Dependency and manifest updates
src/v2.x/packages/agent/package.json, src/v2.x/packages/core/package.json
Add @standard-schema/spec and other new deps; bump @ai-sdk/mcp and ai; add @copilotkitnext/core, @ai-sdk/provider-utils as needed.
Core types
src/v2.x/packages/core/src/types.ts
Add CombinedProps and StandardSchemaWithJSON types; widen FrontendTool.parameters to `StandardSchemaWithJSON
Type-guard utility
src/v2.x/packages/core/src/utils/isStandardSchemaWithJSON.ts
New exported isStandardSchemaWithJSON(obj: object): obj is StandardSchemaWithJSON runtime type-guard.
Core exports
src/v2.x/packages/core/src/index.ts
Re-export isStandardSchemaWithJSON.
Runtime schema handling
src/v2.x/packages/core/src/core/run-handler.ts
Conditional JSON schema generation: use parameters["~standard"].jsonSchema.input(...) when isStandardSchemaWithJSON(parameters) is true; otherwise fall back to zodToJsonSchema.
Agent tool definitions & conversion
src/v2.x/packages/agent/src/index.ts
Change ToolDefinition/defineTool generics to Args; `parameters?: StandardSchemaWithJSON
Angular tool interfaces
src/v2.x/packages/angular/src/lib/tools.ts
Broaden RenderToolCallConfig.args, FrontendToolConfig.parameters, and HumanInTheLoopConfig.parameters to accept `StandardSchemaWithJSON
Utility and helper usage
src/v2.x/packages/agent/src/index.ts, src/v2.x/packages/core/src/index.ts
Add imports/usage of Schema, jsonSchema, StandardSchemaWithJSON, isStandardSchemaWithJSON; introduce standardSchema helper for runtime interop.

Sequence Diagram(s)

sequenceDiagram
  participant Dev as Developer code (ToolDefinition)
  participant Agent as Agent.convertToolDefinitionsToVercelAITools
  participant SchemaHelper as standardSchema / zodToJsonSchema
  participant Provider as ProviderUtils (Schema/jsonSchema)
  participant Vercel as Vercel AI ToolSet

  Dev->>Agent: supply ToolDefinition (parameters)
  Agent->>SchemaHelper: isStandardSchemaWithJSON? (runtime type-guard)
  alt standard schema
    SchemaHelper->>Provider: parameters["~standard"].jsonSchema.input({target:"draft-07"})
    Provider-->>Agent: JSON schema (from standard)
  else zod schema
    SchemaHelper->>Provider: zodToJsonSchema(parameters)
    Provider-->>Agent: JSON schema (from zod)
  end
  Agent->>Vercel: build ToolSet with resolved JSON schema
  Vercel-->>Agent: ToolSet ready
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–25 minutes

Suggested labels

preview

Suggested reviewers

  • mme
  • ataibarkai
  • ranst91
  • tylerslaton

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective of the changeset: adding support for StandardJSONSchemaV1 across multiple packages and documentation files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
src/v2.x/apps/docs/reference/use-frontend-tool.mdx (1)

81-101: Update documentation to reflect StandardSchemaWithJSON support.

The type annotation changed to StandardSchemaWithJSON<T>, but the description on line 83 still states "A Zod schema defining the tool's input parameters." This is inconsistent and misleading since StandardSchemaWithJSON is designed to support other validation libraries like ArkType and Valibot (per PR objectives).

🔎 Suggested documentation update

Update the description to clarify that StandardSchemaWithJSON accepts schemas from multiple validation libraries:

 ### parameters
 
 `StandardSchemaWithJSON<T>` **(optional)**
 
-A Zod schema defining the tool's input parameters. Provides type safety and automatic validation.
+A JSON-standard schema (e.g., from Zod, ArkType, or Valibot) defining the tool's input parameters. Provides type safety and automatic validation.

Consider adding an example demonstrating usage with a non-Zod schema library to illustrate the broader compatibility.

src/v2.x/apps/docs/reference/use-human-in-the-loop.mdx (1)

90-106: Update documentation to reflect StandardSchemaWithJSON support.

The type annotation changed to StandardSchemaWithJSON<T>, but the description on line 92 still states "A Zod schema defining the parameters the agent will provide when requesting human input." This is inconsistent with the type change and doesn't reflect the PR's goal of supporting multiple validation libraries (Zod, ArkType, Valibot).

🔎 Suggested documentation update

Update the description to clarify that StandardSchemaWithJSON accepts schemas from multiple validation libraries:

 ### parameters
 
 `StandardSchemaWithJSON<T>` **(optional)**
 
-A Zod schema defining the parameters the agent will provide when requesting human input.
+A JSON-standard schema (e.g., from Zod, ArkType, or Valibot) defining the parameters the agent will provide when requesting human input.
src/v2.x/docs/ANGULAR_DESIGN.md (1)

346-354: Design documentation inconsistent with implementation.

The design document shows args: StandardSchemaWithJSON<Args> on line 350, but the actual implementation in src/v2.x/packages/angular/src/lib/tools.ts uses a union type: args: z.ZodType<Args> | StandardSchemaWithJSON<Args> (line 61).

This design document should reflect the actual implementation to maintain accuracy and help future contributors understand the correct interface.

🔎 Suggested fix
 interface ToolCallRendererConfig<
   Args extends Record<string, unknown> = Record<string, unknown>,
 > {
   name: string;
-  args: StandardSchemaWithJSON<Args>;
+  args: z.ZodType<Args> | StandardSchemaWithJSON<Args>;
   component: Type<ClientToolRenderer<Args>>;
   agentId?: string;
 }
src/v2.x/packages/agent/src/index.ts (1)

229-241: Fix return type mismatch in defineTool.

The defineTool function returns ToolDefinition<TParameters>, but ToolDefinition<Args> expects Args to be the argument type (the validated data type), not the schema type. This should be ToolDefinition<z.infer<TParameters>> to match the updated generic signature.

🔎 Proposed fix
 export function defineTool<TParameters extends z.ZodTypeAny>(config: {
   name: string;
   description: string;
   parameters: TParameters;
   execute: (args: z.infer<TParameters>) => Promise<unknown>;
-}): ToolDefinition<TParameters> {
+}): ToolDefinition<z.infer<TParameters>> {
   return {
     name: config.name,
     description: config.description,
     parameters: config.parameters,
     execute: config.execute,
   };
 }
🧹 Nitpick comments (2)
src/v2.x/packages/agent/src/index.ts (2)

48-48: Remove unused import.

The StandardTypedV1 import doesn't appear to be used anywhere in this file.

🔎 Suggested cleanup
-import { StandardSchemaWithJSON, isStandardSchemaWithJSON } from "@copilotkitnext/core";
-import { StandardTypedV1 } from "@standard-schema/spec";
+import { StandardSchemaWithJSON, isStandardSchemaWithJSON } from "@copilotkitnext/core";

750-753: Consider simplifying the type assertion.

The pattern satisfies ToolSet as ToolSet is redundant. If mcpTools satisfies ToolSet, the additional as ToolSet cast is unnecessary. You can use either satisfies for type checking or as for casting, but both together is redundant.

🔎 Suggested simplification
                 streamTextParams.tools = {
                   ...streamTextParams.tools,
-                  ...(mcpTools satisfies ToolSet as ToolSet),
+                  ...mcpTools,
                 };

Or if you want to keep the type check:

                 streamTextParams.tools = {
                   ...streamTextParams.tools,
-                  ...(mcpTools satisfies ToolSet as ToolSet),
+                  ...(mcpTools satisfies ToolSet),
                 };
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb4f809 and b218924.

⛔ Files ignored due to path filters (1)
  • src/v2.x/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • src/v2.x/apps/docs/reference/frontend-tool.mdx (2 hunks)
  • src/v2.x/apps/docs/reference/use-frontend-tool.mdx (1 hunks)
  • src/v2.x/apps/docs/reference/use-human-in-the-loop.mdx (1 hunks)
  • src/v2.x/docs/ANGULAR_DESIGN.md (1 hunks)
  • src/v2.x/packages/agent/package.json (1 hunks)
  • src/v2.x/packages/agent/src/index.ts (7 hunks)
  • src/v2.x/packages/angular/src/lib/tools.ts (3 hunks)
  • src/v2.x/packages/core/package.json (1 hunks)
  • src/v2.x/packages/core/src/core/run-handler.ts (2 hunks)
  • src/v2.x/packages/core/src/index.ts (1 hunks)
  • src/v2.x/packages/core/src/types.ts (2 hunks)
  • src/v2.x/packages/core/src/utils/isStandardSchemaWithJSON.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
src/v2.x/**/package.json

📄 CodeRabbit inference engine (src/v2.x/.cursor/rules/10-repo-conventions.always.mdc)

src/v2.x/**/package.json: Keep scripts standardized: build, dev, lint, check-types, test, and test:watch.
All packages publish within the workspace using pnpm workspaces.

Files:

  • src/v2.x/packages/core/package.json
  • src/v2.x/packages/agent/package.json
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/frontend-development.mdc)

**/*.{ts,tsx}: Import and use CopilotProvider from '@copilotkit/react-core' as the main provider component at the root of your React application
Use useCopilotChat hook from '@copilotkit/react-core' for implementing chat functionality
Use useCopilotAction hook from '@copilotkit/react-core' to define actions that agents can execute
Use useCopilotReadable hook from '@copilotkit/react-core' to expose application state to agents
Use CopilotChat component from '@copilotkit/react-ui' for implementing pre-built chat interface UI
Use CopilotPopup component from '@copilotkit/react-ui' for implementing popup chat interface
Use CopilotSidebar component from '@copilotkit/react-ui' for implementing sidebar chat interface
Use CopilotTextarea component from '@copilotkit/react-textarea' for implementing AI-enhanced textarea with auto-completion and suggestions

Always use the provided hooks and functions to modify suggestions state - never modify suggestions state directly

Files:

  • src/v2.x/packages/angular/src/lib/tools.ts
  • src/v2.x/packages/core/src/types.ts
  • src/v2.x/packages/core/src/index.ts
  • src/v2.x/packages/core/src/core/run-handler.ts
  • src/v2.x/packages/core/src/utils/isStandardSchemaWithJSON.ts
  • src/v2.x/packages/agent/src/index.ts
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/frontend-development.mdc)

Use TypeScript for component development to ensure better type safety

Files:

  • src/v2.x/packages/angular/src/lib/tools.ts
  • src/v2.x/packages/core/src/types.ts
  • src/v2.x/packages/core/src/index.ts
  • src/v2.x/packages/core/src/core/run-handler.ts
  • src/v2.x/packages/core/src/utils/isStandardSchemaWithJSON.ts
  • src/v2.x/packages/agent/src/index.ts
**/*.{tsx,ts,jsx,js}

📄 CodeRabbit inference engine (.cursor/rules/quick-reference.mdc)

For building a simple Copilot, start with copilot-chat-with-your-data example, use react-core package for basic integration, and add react-ui package for pre-built components

Files:

  • src/v2.x/packages/angular/src/lib/tools.ts
  • src/v2.x/packages/core/src/types.ts
  • src/v2.x/packages/core/src/index.ts
  • src/v2.x/packages/core/src/core/run-handler.ts
  • src/v2.x/packages/core/src/utils/isStandardSchemaWithJSON.ts
  • src/v2.x/packages/agent/src/index.ts
src/v2.x/**/*.{ts,tsx}

📄 CodeRabbit inference engine (src/v2.x/.cursor/rules/20-typescript.auto.mdc)

src/v2.x/**/*.{ts,tsx}: Prefer type aliases over interface for data structures in TypeScript
Avoid any in TypeScript; use explicit generics or unknown where necessary
Files should be named in kebab-case.ts or kebab-case.tsx with a single export per file

Files:

  • src/v2.x/packages/angular/src/lib/tools.ts
  • src/v2.x/packages/core/src/types.ts
  • src/v2.x/packages/core/src/index.ts
  • src/v2.x/packages/core/src/core/run-handler.ts
  • src/v2.x/packages/core/src/utils/isStandardSchemaWithJSON.ts
  • src/v2.x/packages/agent/src/index.ts
🧠 Learnings (13)
📚 Learning: 2025-12-18T18:11:31.601Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/.cursor/rules/10-repo-conventions.always.mdc:0-0
Timestamp: 2025-12-18T18:11:31.601Z
Learning: Applies to src/v2.x/**/package.json : Keep scripts standardized: `build`, `dev`, `lint`, `check-types`, `test`, and `test:watch`.

Applied to files:

  • src/v2.x/packages/core/package.json
  • src/v2.x/packages/core/src/index.ts
  • src/v2.x/packages/core/src/core/run-handler.ts
  • src/v2.x/packages/core/src/utils/isStandardSchemaWithJSON.ts
📚 Learning: 2025-12-18T18:10:03.431Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/agent-development.mdc:0-0
Timestamp: 2025-12-18T18:10:03.431Z
Learning: Applies to **/agent-js/{package.json,tsconfig.json} : JavaScript agent setup should install `copilotkit/sdk-js` package and configure TypeScript with proper types

Applied to files:

  • src/v2.x/packages/core/package.json
  • src/v2.x/packages/core/src/index.ts
  • src/v2.x/packages/core/src/core/run-handler.ts
  • src/v2.x/packages/agent/package.json
  • src/v2.x/packages/agent/src/index.ts
📚 Learning: 2025-12-18T18:11:01.653Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-12-18T18:11:01.653Z
Learning: Applies to {src/v1.x/package.json,src/v1.x/scripts/**/*.{js,ts},src/v1.x/utilities/**/*.{js,ts}} : For setting up development environment, review src/v1.x/package.json for workspace setup, use scripts in src/v1.x/scripts, and check utilities for shared configurations

Applied to files:

  • src/v2.x/packages/core/package.json
  • src/v2.x/packages/core/src/index.ts
  • src/v2.x/packages/core/src/core/run-handler.ts
📚 Learning: 2025-12-18T18:09:47.478Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/CLAUDE.md:0-0
Timestamp: 2025-12-18T18:09:47.478Z
Learning: Use `pnpm` for package management (never use `npm`). Add workspace dependencies with `pnpm add -w <pkg>`. Keep scripts standardized across packages: `build`, `dev`, `lint`, `check-types`, `test`, `test:watch`.

Applied to files:

  • src/v2.x/packages/core/package.json
📚 Learning: 2025-12-18T18:11:01.653Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-12-18T18:11:01.653Z
Learning: Applies to **/*.{tsx,ts,jsx,js} : For building a simple Copilot, start with copilot-chat-with-your-data example, use react-core package for basic integration, and add react-ui package for pre-built components

Applied to files:

  • src/v2.x/packages/core/package.json
  • src/v2.x/packages/core/src/core/run-handler.ts
  • src/v2.x/packages/agent/package.json
📚 Learning: 2025-12-18T18:10:15.706Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/copilotkit-architecture.mdc:0-0
Timestamp: 2025-12-18T18:10:15.706Z
Learning: Examples should use local packages via workspace references as defined in package.json workspace configuration

Applied to files:

  • src/v2.x/packages/core/package.json
📚 Learning: 2025-12-18T18:11:58.438Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/packages/runtime/.cursor/rules/runtime.always.mdc:0-0
Timestamp: 2025-12-18T18:11:58.438Z
Learning: Applies to src/v2.x/packages/runtime/src/index.ts : Exported APIs live under `src/index.ts`

Applied to files:

  • src/v2.x/packages/core/src/index.ts
📚 Learning: 2025-12-18T18:11:58.438Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/packages/runtime/.cursor/rules/runtime.always.mdc:0-0
Timestamp: 2025-12-18T18:11:58.438Z
Learning: Applies to src/v2.x/packages/runtime/src/**/*.{ts,tsx} : Node-targeted code compiled from `src/` to `dist/` using TypeScript

Applied to files:

  • src/v2.x/packages/core/src/index.ts
📚 Learning: 2025-12-18T18:11:36.534Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/.cursor/rules/20-typescript.auto.mdc:0-0
Timestamp: 2025-12-18T18:11:36.534Z
Learning: Applies to src/v2.x/**/*.{ts,tsx} : Files should be named in `kebab-case.ts` or `kebab-case.tsx` with a single export per file

Applied to files:

  • src/v2.x/packages/core/src/index.ts
📚 Learning: 2025-12-18T18:11:01.653Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-12-18T18:11:01.653Z
Learning: Applies to src/v1.x/packages/sdk-js/**/*.{ts,tsx,js,jsx} : For developing JavaScript agents, use sdk-js package and reference coagents-starter/agent-js for examples

Applied to files:

  • src/v2.x/packages/core/src/index.ts
  • src/v2.x/packages/core/src/core/run-handler.ts
  • src/v2.x/packages/agent/package.json
  • src/v2.x/packages/agent/src/index.ts
📚 Learning: 2025-12-18T18:10:03.431Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/agent-development.mdc:0-0
Timestamp: 2025-12-18T18:10:03.431Z
Learning: Applies to **/agent-js/**/*.{js,ts} : JavaScript agents should be located in folders named `agent-js/` and use the sdk-js package

Applied to files:

  • src/v2.x/packages/core/src/index.ts
📚 Learning: 2025-12-18T18:10:47.795Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-12-18T18:10:47.795Z
Learning: Applies to **/*.{ts,tsx} : Use `useCopilotReadable` hook from 'copilotkit/react-core' to expose application state to agents

Applied to files:

  • src/v2.x/packages/core/src/index.ts
  • src/v2.x/packages/core/src/core/run-handler.ts
📚 Learning: 2025-12-18T18:10:47.795Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-12-18T18:10:47.795Z
Learning: Applies to **/*.{ts,tsx} : Use `useCopilotAction` hook from 'copilotkit/react-core' to define actions that agents can execute

Applied to files:

  • src/v2.x/packages/core/src/core/run-handler.ts
🧬 Code graph analysis (4)
src/v2.x/packages/angular/src/lib/tools.ts (1)
src/v2.x/packages/core/src/types.ts (1)
  • StandardSchemaWithJSON (12-14)
src/v2.x/packages/core/src/core/run-handler.ts (1)
src/v2.x/packages/core/src/utils/isStandardSchemaWithJSON.ts (1)
  • isStandardSchemaWithJSON (3-17)
src/v2.x/packages/core/src/utils/isStandardSchemaWithJSON.ts (1)
src/v2.x/packages/core/src/types.ts (1)
  • StandardSchemaWithJSON (12-14)
src/v2.x/packages/agent/src/index.ts (3)
src/v2.x/packages/core/src/types.ts (1)
  • StandardSchemaWithJSON (12-14)
src/v2.x/packages/core/src/core/run-handler.ts (1)
  • tools (36-38)
src/v2.x/packages/core/src/utils/isStandardSchemaWithJSON.ts (1)
  • isStandardSchemaWithJSON (3-17)
🔇 Additional comments (12)
src/v2.x/packages/core/src/index.ts (1)

5-5: LGTM!

The re-export of the isStandardSchemaWithJSON utility follows the established pattern and correctly exposes the new functionality to package consumers.

src/v2.x/packages/angular/src/lib/tools.ts (2)

5-5: LGTM!

The import of StandardSchemaWithJSON from @copilotkitnext/core is correct and follows the package structure.


61-81: Type broadening is consistent and maintains backward compatibility.

The changes correctly widen the accepted types for schema parameters across all three configuration interfaces:

  • RenderToolCallConfig.args (line 61)
  • FrontendToolConfig.parameters (line 69)
  • HumanInTheLoopConfig.parameters (line 78)

By using union types (z.ZodType<Args> | StandardSchemaWithJSON<Args>), the changes maintain full backward compatibility while enabling support for additional validation libraries.

src/v2.x/packages/agent/package.json (1)

42-48: Dependency versions contain inaccuracies.

@ai-sdk/provider-utils latest version is 3.0.17, not 3.0.19. @standard-schema/spec latest version is 1.0.0, not 1.1.0. @ai-sdk/mcp 0.0.12 exists, and ai 5.0.115 exists. Correct the version specifications to match available releases on npm.

Likely an incorrect or invalid review comment.

src/v2.x/packages/core/package.json (1)

41-41: Change @standard-schema/spec version from 1.1.0 to 1.0.0.

The latest version of @standard-schema/spec is 1.0.0. Version 1.1.0 does not exist and will cause dependency resolution failures. Update the dependency to "@standard-schema/spec": "^1.0.0" to ensure correct package resolution.

⛔ Skipped due to learnings
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/.cursor/rules/10-repo-conventions.always.mdc:0-0
Timestamp: 2025-12-18T18:11:31.601Z
Learning: Applies to src/v2.x/**/package.json : Keep scripts standardized: `build`, `dev`, `lint`, `check-types`, `test`, and `test:watch`.
src/v2.x/packages/core/src/utils/isStandardSchemaWithJSON.ts (1)

3-17: LGTM! Thorough type guard implementation.

The runtime checks correctly validate the shape of StandardSchemaWithJSON by verifying all required nested properties and their types. This will properly discriminate between standard schemas and Zod types at runtime.

src/v2.x/packages/core/src/types.ts (2)

3-14: Well-structured type definitions for standard schema support.

The CombinedProps interface cleanly combines both StandardSchemaV1 and StandardJSONSchemaV1 properties, and StandardSchemaWithJSON follows the standard-schema convention with the "~standard" property marker. This provides a solid foundation for interoperability with multiple validation libraries.


30-30: LGTM! Union type enables multi-library support.

The updated parameters signature allows both StandardSchemaWithJSON<T> and z.ZodType<T>, providing flexibility for users to choose their preferred validation library while maintaining backward compatibility with existing Zod-based code.

src/v2.x/packages/agent/src/index.ts (4)

214-219: LGTM! Cleaner generic design for ToolDefinition.

The updated generic signature ToolDefinition<Args> is more intuitive than the previous ToolDefinition<TParameters extends z.ZodTypeAny>, and the union type for parameters enables multi-library support while maintaining type safety.


411-435: Good temporary implementation with proper error handling.

The standardSchema helper correctly converts StandardSchemaWithJSON to the Vercel AI SDK's Schema format by extracting the JSON schema and implementing validation. The async validation properly handles the result format and wraps errors in TypeValidationError.

Good to see the comment noting this will be replaced by asSchema from @ai-sdk/provider-utils once it's available.


440-455: LGTM! Runtime schema type detection and conversion.

The updated function correctly handles both StandardSchemaWithJSON and Zod schemas using runtime type checking. The isStandardSchemaWithJSON guard properly routes to the appropriate schema conversion path.


524-524: Correct generic parameter for heterogeneous tools array.

Using ToolDefinition<any>[] is appropriate here since the tools array can contain tools with different argument types. This aligns with the updated generic signature.

Comment on lines +563 to +570
const parameters = tool.parameters;
const rawSchema = isStandardSchemaWithJSON(parameters)
? parameters["~standard"].jsonSchema.input({
target: "draft-07",
})
: zodToJsonSchema(parameters as z.ZodType, {
$refStrategy: "none",
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

JSON Schema Draft-07 target causes compatibility issues with downstream consumers

The schema conversion logic correctly handles both StandardSchemaWithJSON and Zod schema types, but hardcoding target: "draft-07" creates compatibility problems:

  • Anthropic's modern MCP clients require strict compliance with JSON Schema draft-2020-12
  • Anthropic production API rejects schemas that aren't Draft 2020-12

The implementation should either:

  • Use JSON Schema draft-2020-12 as the target instead of draft-07
  • Make the schema version configurable to support multiple downstream consumers
  • Document the limitation and add support for modern schema versions
🤖 Prompt for AI Agents
In src/v2.x/packages/core/src/core/run-handler.ts around lines 563 to 570, the
JSON Schema generation is hardcoded to target "draft-07", which breaks
compatibility with downstream consumers that require draft-2020-12; update the
code to target "draft-2020-12" instead, or better: introduce a configurable
schemaVersion option (defaulting to "draft-2020-12") that is passed into the
StandardSchemaWithJSON.jsonSchema.input call and used as the target for Zod ->
JSON Schema conversion so callers can override when needed; ensure the new
option is plumbed from the handler config, validate acceptable values, and keep
draft-2020-12 as the default to preserve Anthropic compatibility.

Copy link
Author

Choose a reason for hiding this comment

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

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/v2.x/packages/agent/src/index.ts (1)

213-240: Update defineTool to support StandardSchemaWithJSON.

The ToolDefinition interface (lines 213-218) now accepts StandardSchemaWithJSON<Args> | z.ZodType<Args>, but the defineTool helper function (lines 228-240) still only accepts Zod schemas. This inconsistency means developers cannot use defineTool to create tools with StandardSchemaWithJSON and must manually construct ToolDefinition objects instead.

🔎 Proposed fix to support both schema types

Update the function to accept either schema type:

 /**
  * Define a tool for use with BuiltInAgent
  * @param name - The name of the tool
  * @param description - Description of what the tool does
- * @param parameters - Zod schema for the tool's input parameters
+ * @param parameters - Schema for the tool's input parameters (Zod or StandardSchemaWithJSON)
  * @param execute - Function to execute the tool server-side
  * @returns Tool definition
  */
-export function defineTool<TParameters extends z.ZodTypeAny>(config: {
+export function defineTool<Args>(config: {
   name: string;
   description: string;
-  parameters: TParameters;
-  execute: (args: z.infer<TParameters>) => Promise<unknown>;
-}): ToolDefinition<TParameters> {
+  parameters: StandardSchemaWithJSON<Args> | z.ZodType<Args>;
+  execute: (args: Args) => Promise<unknown>;
+}): ToolDefinition<Args> {
   return {
     name: config.name,
     description: config.description,
     parameters: config.parameters,
     execute: config.execute,
   };
 }
🧹 Nitpick comments (2)
src/v2.x/packages/agent/src/index.ts (2)

439-454: Consider using unknown instead of any for better type safety.

The parameter type ToolDefinition<any>[] and the cast (tool.parameters as any as z.ZodTypeAny) violate the coding guideline to avoid any. While the implementation works correctly at runtime, using unknown would provide better type safety.

🔎 Proposed refactor for better type safety
-export function convertToolDefinitionsToVercelAITools(tools: ToolDefinition<any>[]): ToolSet {
+export function convertToolDefinitionsToVercelAITools(tools: ToolDefinition<unknown>[]): ToolSet {
   // eslint-disable-next-line @typescript-eslint/no-explicit-any
   const result: Record<string, any> = {};
 
   for (const tool of tools) {
     result[tool.name] = createVercelAISDKTool({
       description: tool.description,
       inputSchema: isStandardSchemaWithJSON(tool.parameters)
         ? standardSchema(tool.parameters)
-        : (tool.parameters as any as z.ZodTypeAny),
+        : (tool.parameters as z.ZodTypeAny),
       execute: tool.execute,
     });
   }
 
   return result;
 }

Note: If the single cast still raises type errors, you may need to adjust the ToolDefinition generic constraint, but unknown is preferable to any.

As per coding guidelines, prefer explicit generics or unknown over any.


784-784: Minor: String literal style consistency.

Changed from single quotes to double quotes. While this has no functional impact, you may want to establish a consistent quote style across the file for maintainability.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a0ea1b0 and aaeebbd.

📒 Files selected for processing (1)
  • src/v2.x/packages/agent/src/index.ts
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/frontend-development.mdc)

**/*.{ts,tsx}: Import and use CopilotProvider from '@copilotkit/react-core' as the main provider component at the root of your React application
Use useCopilotChat hook from '@copilotkit/react-core' for implementing chat functionality
Use useCopilotAction hook from '@copilotkit/react-core' to define actions that agents can execute
Use useCopilotReadable hook from '@copilotkit/react-core' to expose application state to agents
Use CopilotChat component from '@copilotkit/react-ui' for implementing pre-built chat interface UI
Use CopilotPopup component from '@copilotkit/react-ui' for implementing popup chat interface
Use CopilotSidebar component from '@copilotkit/react-ui' for implementing sidebar chat interface
Use CopilotTextarea component from '@copilotkit/react-textarea' for implementing AI-enhanced textarea with auto-completion and suggestions

Always use the provided hooks and functions to modify suggestions state - never modify suggestions state directly

Files:

  • src/v2.x/packages/agent/src/index.ts
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/frontend-development.mdc)

Use TypeScript for component development to ensure better type safety

Files:

  • src/v2.x/packages/agent/src/index.ts
**/*.{tsx,ts,jsx,js}

📄 CodeRabbit inference engine (.cursor/rules/quick-reference.mdc)

For building a simple Copilot, start with copilot-chat-with-your-data example, use react-core package for basic integration, and add react-ui package for pre-built components

Files:

  • src/v2.x/packages/agent/src/index.ts
src/v2.x/**/*.{ts,tsx}

📄 CodeRabbit inference engine (src/v2.x/.cursor/rules/20-typescript.auto.mdc)

src/v2.x/**/*.{ts,tsx}: Prefer type aliases over interface for data structures in TypeScript
Avoid any in TypeScript; use explicit generics or unknown where necessary
Files should be named in kebab-case.ts or kebab-case.tsx with a single export per file

Files:

  • src/v2.x/packages/agent/src/index.ts
🧠 Learnings (3)
📚 Learning: 2025-12-18T18:10:03.431Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/agent-development.mdc:0-0
Timestamp: 2025-12-18T18:10:03.431Z
Learning: Applies to **/agent-js/{package.json,tsconfig.json} : JavaScript agent setup should install `copilotkit/sdk-js` package and configure TypeScript with proper types

Applied to files:

  • src/v2.x/packages/agent/src/index.ts
📚 Learning: 2025-12-18T18:11:01.653Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-12-18T18:11:01.653Z
Learning: Applies to src/v1.x/packages/sdk-js/**/*.{ts,tsx,js,jsx} : For developing JavaScript agents, use sdk-js package and reference coagents-starter/agent-js for examples

Applied to files:

  • src/v2.x/packages/agent/src/index.ts
📚 Learning: 2025-12-18T18:11:58.438Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/packages/runtime/.cursor/rules/runtime.always.mdc:0-0
Timestamp: 2025-12-18T18:11:58.438Z
Learning: Applies to src/v2.x/packages/runtime/src/**/*.{ts,tsx} : Node-targeted code compiled from `src/` to `dist/` using TypeScript

Applied to files:

  • src/v2.x/packages/agent/src/index.ts
🧬 Code graph analysis (1)
src/v2.x/packages/agent/src/index.ts (2)
src/v2.x/packages/core/src/types.ts (1)
  • StandardSchemaWithJSON (12-14)
src/v2.x/packages/core/src/utils/isStandardSchemaWithJSON.ts (1)
  • isStandardSchemaWithJSON (3-17)
🔇 Additional comments (5)
src/v2.x/packages/agent/src/index.ts (5)

32-47: LGTM! New imports support StandardSchemaWithJSON.

The new imports correctly support the StandardJSONSchemaV1 feature, enabling runtime detection and validation of standard schemas alongside Zod.


523-523: Type consistency with convertToolDefinitionsToVercelAITools.

This type change to ToolDefinition<any>[] is consistent with the function signature at line 439. However, both should preferably use unknown instead of any (see previous comment on lines 439-454).


749-752: LGTM! Formatting improvement.

The multi-line spread improves readability without changing functionality.


410-434: The standardSchema function is not a temporary implementation awaiting upgrade to @ai-sdk/provider-utils@4.0.0-beta.53. The project currently depends on @ai-sdk/provider-utils@^3.0.19 (stable), with no evidence of planned upgrades to beta versions. The function serves as a workaround to support StandardSchemaWithJSON with the current stable version and should remain in place.

Likely an incorrect or invalid review comment.


47-47: Add integration tests for StandardSchemaWithJSON with ArkType and Valibot.

The StandardSchemaWithJSON interface correctly requires both validation (StandardSchemaV1.Props) and JSON schema conversion (StandardJSONSchemaV1.Props), and isStandardSchemaWithJSON properly checks for the ~standard property with both validate() and jsonSchema methods. However, there is no test coverage verifying end-to-end integration with ArkType and Valibot schemas, which are listed as supported in the PR objectives. Add tests to confirm that schemas from these libraries, which support Standard Schema, are correctly identified and processed through the conversion pipeline.

@changesets-bot-copilotkit
Copy link

⏭️ Changeset Not Required

Latest commit: d284392

No changes in this PR affected the @copilitkit/* packages. Merging this PR will not cause a version bump for any packages.

Changeset is not required for this PR.

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 (2)
src/v2.x/packages/agent/src/index.ts (2)

410-434: Document the temporary nature and removal timeline for this polyfill.

This is a well-implemented polyfill for asSchema functionality. However, consider adding:

  1. A TODO comment indicating when this can be removed (e.g., "TODO: Remove once @ai-sdk/provider-utils is upgraded to >=4.0.0-beta.53")
  2. A clearer indication that this is temporary scaffolding

This will help future maintainers know when to clean up the polyfill.

🔎 Suggested documentation enhancement
 /*
- * supported in "@ai-sdk/provider-utils@"4.0.0-beta.53" by `asSchema`, copied here for now
+ * TODO: Remove this polyfill once @ai-sdk/provider-utils is upgraded to >=4.0.0-beta.53
+ * This functionality is available as `asSchema` in the newer version.
+ * Temporary polyfill copied from the expected API.
  */
 function standardSchema<OBJECT>(standardSchema: StandardSchemaWithJSON<OBJECT>): Schema<OBJECT> {

446-448: Consider refining the type cast to avoid double casting.

The double cast as any as z.ZodTypeAny on line 448 bypasses TypeScript's type checking. While this may be necessary for the current API constraints, consider if there's a cleaner approach:

  1. Define a helper type that represents the union of possible input schemas
  2. Use a type assertion function instead of casting
  3. Add a runtime check to ensure the schema is actually a Zod schema
🔎 Alternative approach using type predicate
function isZodType<T>(schema: StandardSchemaWithJSON<T> | z.ZodType<T>): schema is z.ZodType<T> {
  return !isStandardSchemaWithJSON(schema);
}

// Then in the function:
inputSchema: isStandardSchemaWithJSON(tool.parameters)
  ? standardSchema(tool.parameters)
  : tool.parameters as z.ZodTypeAny, // Single cast with type guard above
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aaeebbd and d284392.

📒 Files selected for processing (1)
  • src/v2.x/packages/agent/src/index.ts
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/frontend-development.mdc)

**/*.{ts,tsx}: Import and use CopilotProvider from '@copilotkit/react-core' as the main provider component at the root of your React application
Use useCopilotChat hook from '@copilotkit/react-core' for implementing chat functionality
Use useCopilotAction hook from '@copilotkit/react-core' to define actions that agents can execute
Use useCopilotReadable hook from '@copilotkit/react-core' to expose application state to agents
Use CopilotChat component from '@copilotkit/react-ui' for implementing pre-built chat interface UI
Use CopilotPopup component from '@copilotkit/react-ui' for implementing popup chat interface
Use CopilotSidebar component from '@copilotkit/react-ui' for implementing sidebar chat interface
Use CopilotTextarea component from '@copilotkit/react-textarea' for implementing AI-enhanced textarea with auto-completion and suggestions

Always use the provided hooks and functions to modify suggestions state - never modify suggestions state directly

Files:

  • src/v2.x/packages/agent/src/index.ts
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/frontend-development.mdc)

Use TypeScript for component development to ensure better type safety

Files:

  • src/v2.x/packages/agent/src/index.ts
**/*.{tsx,ts,jsx,js}

📄 CodeRabbit inference engine (.cursor/rules/quick-reference.mdc)

For building a simple Copilot, start with copilot-chat-with-your-data example, use react-core package for basic integration, and add react-ui package for pre-built components

Files:

  • src/v2.x/packages/agent/src/index.ts
src/v2.x/**/*.{ts,tsx}

📄 CodeRabbit inference engine (src/v2.x/.cursor/rules/20-typescript.auto.mdc)

src/v2.x/**/*.{ts,tsx}: Prefer type aliases over interface for data structures in TypeScript
Avoid any in TypeScript; use explicit generics or unknown where necessary
Files should be named in kebab-case.ts or kebab-case.tsx with a single export per file

Files:

  • src/v2.x/packages/agent/src/index.ts
🧠 Learnings (6)
📚 Learning: 2025-12-18T18:10:03.431Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/agent-development.mdc:0-0
Timestamp: 2025-12-18T18:10:03.431Z
Learning: Applies to **/agent-js/{package.json,tsconfig.json} : JavaScript agent setup should install `copilotkit/sdk-js` package and configure TypeScript with proper types

Applied to files:

  • src/v2.x/packages/agent/src/index.ts
📚 Learning: 2025-12-18T18:11:01.653Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-12-18T18:11:01.653Z
Learning: Applies to src/v1.x/packages/sdk-js/**/*.{ts,tsx,js,jsx} : For developing JavaScript agents, use sdk-js package and reference coagents-starter/agent-js for examples

Applied to files:

  • src/v2.x/packages/agent/src/index.ts
📚 Learning: 2025-12-18T18:11:01.653Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-12-18T18:11:01.653Z
Learning: Applies to {src/v1.x/package.json,src/v1.x/scripts/**/*.{js,ts},src/v1.x/utilities/**/*.{js,ts}} : For setting up development environment, review src/v1.x/package.json for workspace setup, use scripts in src/v1.x/scripts, and check utilities for shared configurations

Applied to files:

  • src/v2.x/packages/agent/src/index.ts
📚 Learning: 2025-12-18T18:11:31.601Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/.cursor/rules/10-repo-conventions.always.mdc:0-0
Timestamp: 2025-12-18T18:11:31.601Z
Learning: Applies to src/v2.x/**/package.json : Keep scripts standardized: `build`, `dev`, `lint`, `check-types`, `test`, and `test:watch`.

Applied to files:

  • src/v2.x/packages/agent/src/index.ts
📚 Learning: 2025-12-18T18:11:58.438Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/packages/runtime/.cursor/rules/runtime.always.mdc:0-0
Timestamp: 2025-12-18T18:11:58.438Z
Learning: Applies to src/v2.x/packages/runtime/src/index.ts : Exported APIs live under `src/index.ts`

Applied to files:

  • src/v2.x/packages/agent/src/index.ts
📚 Learning: 2025-12-18T18:11:58.438Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/packages/runtime/.cursor/rules/runtime.always.mdc:0-0
Timestamp: 2025-12-18T18:11:58.438Z
Learning: Applies to src/v2.x/packages/runtime/src/**/*.{ts,tsx} : Node-targeted code compiled from `src/` to `dist/` using TypeScript

Applied to files:

  • src/v2.x/packages/agent/src/index.ts
🧬 Code graph analysis (1)
src/v2.x/packages/agent/src/index.ts (3)
src/v2.x/packages/core/src/types.ts (1)
  • StandardSchemaWithJSON (12-14)
src/v2.x/packages/core/src/core/run-handler.ts (1)
  • tools (36-38)
src/v2.x/packages/core/src/utils/isStandardSchemaWithJSON.ts (1)
  • isStandardSchemaWithJSON (3-17)
🔇 Additional comments (6)
src/v2.x/packages/agent/src/index.ts (6)

213-218: LGTM! Generic type simplified for dual schema support.

The interface correctly supports both StandardSchemaWithJSON<Args> and z.ZodType<Args> for parameters. The generic type simplification from TParameters extends z.ZodTypeAny to Args is appropriate for enabling interoperability with multiple validation libraries while maintaining type safety through the union type.


228-240: LGTM! Proper use of NoInfer for type safety.

The function signature correctly uses NoInfer<Args> in the execute parameter to prevent reverse inference, ensuring that Args is always derived from the parameters schema. The updated JSDoc clearly documents support for both schema types.


523-523: Type relaxation is necessary for dual schema support.

The change from a Zod-constrained generic to ToolDefinition<any>[] is a necessary trade-off to support both StandardSchemaWithJSON and z.ZodType schemas. Type safety is still maintained at the individual ToolDefinition level through the union type in the interface.


749-752: Good formatting improvement for readability.

The multi-line object spread makes the MCP tools merge more readable and easier to maintain.


784-784: String literal consistency improvement.

Changing from single quotes to double quotes improves consistency with other case statements in the switch block.


32-47: Verify current versions of @ai-sdk/provider-utils and ai packages to assess polyfill necessity.

The current stable version of @ai-sdk/provider-utils is 3.0.17. The code includes a polyfill with a comment suggesting it's "supported in '@ai-sdk/provider-utils@4.0.0-beta.53' by asSchema", but this cannot be verified through available documentation. TypeValidationError from the ai package is valid, and Schema/jsonSchema imports are correctly used. Confirm the actual project versions in package.json and whether the beta version and asSchema export actually exist before deciding if the polyfill can be removed.

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