diff --git a/.changeset/social-waves-film.md b/.changeset/social-waves-film.md new file mode 100644 index 00000000..479efe52 --- /dev/null +++ b/.changeset/social-waves-film.md @@ -0,0 +1,9 @@ +--- +'@tanstack/ai-anthropic': minor +'@tanstack/ai-gemini': minor +'@tanstack/ai-ollama': minor +'@tanstack/ai-openai': minor +'@tanstack/ai': minor +--- + +Add in standard schema support instead of zod diff --git a/docs/getting-started/overview.md b/docs/getting-started/overview.md index 67395478..b48a61cb 100644 --- a/docs/getting-started/overview.md +++ b/docs/getting-started/overview.md @@ -28,10 +28,13 @@ TanStack AI lets you define a tool once and provide environment-specific impleme ```typescript import { toolDefinition } from '@tanstack/ai' +import { convertZodToJsonSchema } from "@tanstack/ai/zod"; +import { z } from 'zod' // Define a tool const getProductsDef = toolDefinition({ name: 'getProducts', + toJsonSchema: convertZodToJsonSchema, inputSchema: z.object({ query: z.string() }), outputSchema: z.array(z.object({ id: z.string(), name: z.string() })), }) diff --git a/docs/getting-started/quick-start.md b/docs/getting-started/quick-start.md index 79160b94..b3ee50ea 100644 --- a/docs/getting-started/quick-start.md +++ b/docs/getting-started/quick-start.md @@ -174,9 +174,13 @@ Since TanStack AI is framework-agnostic, you can define and use tools in any env ```typescript import { toolDefinition } from '@tanstack/ai' +import { convertZodToJsonSchema } from "@tanstack/ai/zod"; +import { z } from 'zod' + const getProductsDef = toolDefinition({ name: 'getProducts', + toJsonSchema: convertZodToJsonSchema, inputSchema: z.object({ query: z.string() }), }) diff --git a/docs/guides/agentic-cycle.md b/docs/guides/agentic-cycle.md index 2e68c1e7..bc0ab8cb 100644 --- a/docs/guides/agentic-cycle.md +++ b/docs/guides/agentic-cycle.md @@ -89,6 +89,7 @@ Here's a real-world example of the agentic cycle: const getWeatherDef = toolDefinition({ name: "get_weather", description: "Get current weather for a city", + toJsonSchema: convertZodToJsonSchema, inputSchema: z.object({ city: z.string(), }), @@ -97,6 +98,7 @@ const getWeatherDef = toolDefinition({ const getClothingAdviceDef = toolDefinition({ name: "get_clothing_advice", description: "Get clothing recommendations based on weather", + toJsonSchema: convertZodToJsonSchema, inputSchema: z.object({ temperature: z.number(), conditions: z.string(), diff --git a/docs/guides/client-tools.md b/docs/guides/client-tools.md index a7b19cb5..05540e20 100644 --- a/docs/guides/client-tools.md +++ b/docs/guides/client-tools.md @@ -58,6 +58,7 @@ Client tools use the same `toolDefinition()` API but with the `.client()` method ```typescript // tools/definitions.ts - Shared between server and client import { toolDefinition } from "@tanstack/ai"; +import { convertZodToJsonSchema } from "@tanstack/ai/zod"; import { z } from "zod"; export const updateUIDef = toolDefinition({ @@ -67,6 +68,7 @@ export const updateUIDef = toolDefinition({ message: z.string().describe("Message to display"), type: z.enum(["success", "error", "info"]).describe("Message type"), }), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ success: z.boolean(), }), @@ -79,6 +81,7 @@ export const saveToLocalStorageDef = toolDefinition({ key: z.string().describe("Storage key"), value: z.string().describe("Value to store"), }), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ saved: z.boolean(), }), @@ -274,6 +277,7 @@ const addToCartDef = toolDefinition({ itemId: z.string(), quantity: z.number(), }), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ success: z.boolean(), cartId: z.string(), diff --git a/docs/guides/server-tools.md b/docs/guides/server-tools.md index 8e159d45..4683b027 100644 --- a/docs/guides/server-tools.md +++ b/docs/guides/server-tools.md @@ -165,6 +165,7 @@ For better organization, define tool schemas and implementations separately: ```typescript // tools/definitions.ts import { toolDefinition } from "@tanstack/ai"; +import { convertZodToJsonSchema } from "@tanstack/ai/zod"; import { z } from "zod"; export const getUserDataDef = toolDefinition({ @@ -173,6 +174,7 @@ export const getUserDataDef = toolDefinition({ inputSchema: z.object({ userId: z.string(), }), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ name: z.string(), email: z.string(), @@ -182,6 +184,7 @@ export const getUserDataDef = toolDefinition({ export const searchProductsDef = toolDefinition({ name: "search_products", description: "Search products", + toJsonSchema: convertZodToJsonSchema, inputSchema: z.object({ query: z.string(), }), @@ -236,6 +239,7 @@ const getUserDataDef = toolDefinition({ inputSchema: z.object({ userId: z.string(), }), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ name: z.string().optional(), email: z.string().optional(), diff --git a/docs/guides/tools.md b/docs/guides/tools.md index 3ad897bd..8b8bb5ef 100644 --- a/docs/guides/tools.md +++ b/docs/guides/tools.md @@ -41,6 +41,7 @@ Tools are defined using `toolDefinition()` from `@tanstack/ai`: ```typescript import { toolDefinition } from "@tanstack/ai"; +import { convertZodToJsonSchema } from "@tanstack/ai/zod"; import { z } from "zod"; // Step 1: Define the tool schema @@ -51,6 +52,8 @@ const getWeatherDef = toolDefinition({ location: z.string().describe("The city and state, e.g. San Francisco, CA"), unit: z.enum(["celsius", "fahrenheit"]).optional(), }), + // Do not forget to pass in the toJsonSchema function to convert it to JSON Schema + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ temperature: z.number(), conditions: z.string(), @@ -74,6 +77,13 @@ const getWeatherServer = getWeatherDef.server(async ({ location, unit }) => { }); ``` +## Tool validation + +We support ANY validation library by requiring you to provide a `toJsonSchema` function when defining your tool. +This function converts your input and output schemas to JSON Schema, which is the format used for tool calling with LLMs. +In the example above, we use `convertZodToJsonSchema` from `@tanstack/ai/zod` to convert Zod schemas to JSON Schema. +You can implement similar functions for other validation libraries if needed. + ## Using Tools in Chat ### Server-Side @@ -158,6 +168,7 @@ const addToCartDef = toolDefinition({ itemId: z.string(), quantity: z.number(), }), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ success: z.boolean(), cartId: z.string(), diff --git a/docs/reference/classes/ToolCallManager.md b/docs/reference/classes/ToolCallManager.md index e0ae159c..fdb408ee 100644 --- a/docs/reference/classes/ToolCallManager.md +++ b/docs/reference/classes/ToolCallManager.md @@ -5,7 +5,7 @@ title: ToolCallManager # Class: ToolCallManager -Defined in: [tools/tool-calls.ts:41](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L41) +Defined in: [tools/tool-calls.ts:80](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L80) Manages tool call accumulation and execution for the chat() method's automatic tool execution loop. @@ -47,13 +47,13 @@ if (manager.hasToolCalls()) { new ToolCallManager(tools): ToolCallManager; ``` -Defined in: [tools/tool-calls.ts:45](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L45) +Defined in: [tools/tool-calls.ts:84](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L84) #### Parameters ##### tools -readonly [`Tool`](../interfaces/Tool.md)\<`ZodType`\<`unknown`, `unknown`, `$ZodTypeInternals`\<`unknown`, `unknown`\>\>, `ZodType`\<`unknown`, `unknown`, `$ZodTypeInternals`\<`unknown`, `unknown`\>\>, `string`\>[] +readonly [`Tool`](../interfaces/Tool.md)\<`StandardSchemaV1`\<`unknown`, `unknown`\>, `StandardSchemaV1`\<`unknown`, `unknown`\>, `string`\>[] #### Returns @@ -67,7 +67,7 @@ readonly [`Tool`](../interfaces/Tool.md)\<`ZodType`\<`unknown`, `unknown`, `$Zod addToolCallChunk(chunk): void; ``` -Defined in: [tools/tool-calls.ts:53](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L53) +Defined in: [tools/tool-calls.ts:92](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L92) Add a tool call chunk to the accumulator Handles streaming tool calls by accumulating arguments @@ -126,7 +126,7 @@ Handles streaming tool calls by accumulating arguments clear(): void; ``` -Defined in: [tools/tool-calls.ts:193](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L193) +Defined in: [tools/tool-calls.ts:232](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L232) Clear the tool calls map for the next iteration @@ -145,7 +145,7 @@ executeTools(doneChunk): AsyncGenerator[], void>; ``` -Defined in: [tools/tool-calls.ts:111](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L111) +Defined in: [tools/tool-calls.ts:150](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L150) Execute all tool calls and return tool result messages Also yields tool_result chunks for streaming @@ -171,7 +171,7 @@ Also yields tool_result chunks for streaming getToolCalls(): ToolCall[]; ``` -Defined in: [tools/tool-calls.ts:101](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L101) +Defined in: [tools/tool-calls.ts:140](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L140) Get all complete tool calls (filtered for valid ID and name) @@ -187,7 +187,7 @@ Get all complete tool calls (filtered for valid ID and name) hasToolCalls(): boolean; ``` -Defined in: [tools/tool-calls.ts:94](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L94) +Defined in: [tools/tool-calls.ts:133](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L133) Check if there are any complete tool calls to execute diff --git a/docs/reference/functions/convertZodToJsonSchema.md b/docs/reference/functions/convertZodToJsonSchema.md deleted file mode 100644 index 8b0526ab..00000000 --- a/docs/reference/functions/convertZodToJsonSchema.md +++ /dev/null @@ -1,50 +0,0 @@ ---- -id: convertZodToJsonSchema -title: convertZodToJsonSchema ---- - -# Function: convertZodToJsonSchema() - -```ts -function convertZodToJsonSchema(schema): Record | undefined; -``` - -Defined in: [tools/zod-converter.ts:31](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/zod-converter.ts#L31) - -Converts a Zod schema to JSON Schema format compatible with LLM providers. - -## Parameters - -### schema - -Zod schema to convert - -`ZodType`\<`unknown`, `unknown`, `$ZodTypeInternals`\<`unknown`, `unknown`\>\> | `undefined` - -## Returns - -`Record`\<`string`, `any`\> \| `undefined` - -JSON Schema object that can be sent to LLM providers - -## Example - -```typescript -import { z } from 'zod'; - -const schema = z.object({ - location: z.string().describe('City name'), - unit: z.enum(['celsius', 'fahrenheit']).optional() -}); - -const jsonSchema = convertZodToJsonSchema(schema); -// Returns: -// { -// type: 'object', -// properties: { -// location: { type: 'string', description: 'City name' }, -// unit: { type: 'string', enum: ['celsius', 'fahrenheit'] } -// }, -// required: ['location'] -// } -``` diff --git a/docs/reference/functions/toolDefinition.md b/docs/reference/functions/toolDefinition.md index 46017b07..dc546a56 100644 --- a/docs/reference/functions/toolDefinition.md +++ b/docs/reference/functions/toolDefinition.md @@ -9,7 +9,7 @@ title: toolDefinition function toolDefinition(config): ToolDefinition; ``` -Defined in: [tools/tool-definition.ts:170](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L170) +Defined in: [tools/tool-definition.ts:193](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L193) Create an isomorphic tool definition that can be used directly or instantiated for server/client @@ -18,15 +18,17 @@ The definition contains all tool metadata (name, description, schemas) and can b 2. Instantiated as a server tool with .server() 3. Instantiated as a client tool with .client() +This function supports any Standard Schema compliant library (Zod, Valibot, ArkType, etc.) + ## Type Parameters ### TInput -`TInput` *extends* `ZodType`\<`unknown`, `unknown`, `$ZodTypeInternals`\<`unknown`, `unknown`\>\> = `ZodAny` +`TInput` *extends* `StandardSchemaV1`\<`unknown`, `unknown`\> = `StandardSchemaV1`\<`unknown`, `unknown`\> ### TOutput -`TOutput` *extends* `ZodType`\<`unknown`, `unknown`, `$ZodTypeInternals`\<`unknown`, `unknown`\>\> = `ZodAny` +`TOutput` *extends* `StandardSchemaV1`\<`unknown`, `unknown`\> = `StandardSchemaV1`\<`unknown`, `unknown`\> ### TName @@ -48,6 +50,7 @@ The definition contains all tool metadata (name, description, schemas) and can b import { toolDefinition } from '@tanstack/ai'; import { z } from 'zod'; +// Using Zod (Standard Schema compliant) const addToCartTool = toolDefinition({ name: 'addToCart', description: 'Add a guitar to the shopping cart (requires approval)', @@ -63,6 +66,18 @@ const addToCartTool = toolDefinition({ }), }); +// Using Valibot (Standard Schema compliant) +import * as v from 'valibot'; + +const searchTool = toolDefinition({ + name: 'search', + description: 'Search the database', + inputSchema: v.object({ + query: v.string(), + limit: v.optional(v.number()), + }), +}); + // Use directly in chat (server-side, no execute function) chat({ tools: [addToCartTool], diff --git a/docs/reference/index.md b/docs/reference/index.md index 118e4642..05b13b9f 100644 --- a/docs/reference/index.md +++ b/docs/reference/index.md @@ -102,7 +102,6 @@ title: "@tanstack/ai" - [chatOptions](functions/chatOptions.md) - [combineStrategies](functions/combineStrategies.md) - [convertMessagesToModelMessages](functions/convertMessagesToModelMessages.md) -- [convertZodToJsonSchema](functions/convertZodToJsonSchema.md) - [createReplayStream](functions/createReplayStream.md) - [embedding](functions/embedding.md) - [generateMessageId](functions/generateMessageId.md) diff --git a/docs/reference/interfaces/AIAdapter.md b/docs/reference/interfaces/AIAdapter.md index f0e61468..64828034 100644 --- a/docs/reference/interfaces/AIAdapter.md +++ b/docs/reference/interfaces/AIAdapter.md @@ -5,7 +5,7 @@ title: AIAdapter # Interface: AIAdapter\ -Defined in: [types.ts:684](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L684) +Defined in: [types.ts:724](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L724) AI adapter interface with support for endpoint-specific models and provider options. @@ -56,7 +56,7 @@ Generic parameters: optional _chatProviderOptions: TChatProviderOptions; ``` -Defined in: [types.ts:711](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L711) +Defined in: [types.ts:751](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L751) *** @@ -66,7 +66,7 @@ Defined in: [types.ts:711](https://github.com/TanStack/ai/blob/main/packages/typ optional _embeddingProviderOptions: TEmbeddingProviderOptions; ``` -Defined in: [types.ts:712](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L712) +Defined in: [types.ts:752](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L752) *** @@ -76,7 +76,7 @@ Defined in: [types.ts:712](https://github.com/TanStack/ai/blob/main/packages/typ optional _messageMetadataByModality: TMessageMetadataByModality; ``` -Defined in: [types.ts:729](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L729) +Defined in: [types.ts:769](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L769) Type-only map from modality type to adapter-specific metadata types. Used to provide type-safe autocomplete for metadata on content parts. @@ -89,7 +89,7 @@ Used to provide type-safe autocomplete for metadata on content parts. optional _modelInputModalitiesByName: TModelInputModalitiesByName; ``` -Defined in: [types.ts:724](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L724) +Defined in: [types.ts:764](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L764) Type-only map from model name to its supported input modalities. Used by the core AI types to narrow ContentPart types based on the selected model. @@ -103,7 +103,7 @@ Must be provided by all adapters. _modelProviderOptionsByName: TModelProviderOptionsByName; ``` -Defined in: [types.ts:718](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L718) +Defined in: [types.ts:758](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L758) Type-only map from model name to its specific provider options. Used by the core AI types to narrow providerOptions based on the selected model. @@ -117,7 +117,7 @@ Must be provided by all adapters. optional _providerOptions: TChatProviderOptions; ``` -Defined in: [types.ts:710](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L710) +Defined in: [types.ts:750](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L750) *** @@ -127,7 +127,7 @@ Defined in: [types.ts:710](https://github.com/TanStack/ai/blob/main/packages/typ chatStream: (options) => AsyncIterable; ``` -Defined in: [types.ts:732](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L732) +Defined in: [types.ts:772](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L772) #### Parameters @@ -147,7 +147,7 @@ Defined in: [types.ts:732](https://github.com/TanStack/ai/blob/main/packages/typ createEmbeddings: (options) => Promise; ``` -Defined in: [types.ts:740](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L740) +Defined in: [types.ts:780](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L780) #### Parameters @@ -167,7 +167,7 @@ Defined in: [types.ts:740](https://github.com/TanStack/ai/blob/main/packages/typ optional embeddingModels: TEmbeddingModels; ``` -Defined in: [types.ts:707](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L707) +Defined in: [types.ts:747](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L747) Models that support embeddings @@ -179,7 +179,7 @@ Models that support embeddings models: TChatModels; ``` -Defined in: [types.ts:704](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L704) +Defined in: [types.ts:744](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L744) Models that support chat/text completion @@ -191,7 +191,7 @@ Models that support chat/text completion name: string; ``` -Defined in: [types.ts:702](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L702) +Defined in: [types.ts:742](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L742) *** @@ -201,7 +201,7 @@ Defined in: [types.ts:702](https://github.com/TanStack/ai/blob/main/packages/typ summarize: (options) => Promise; ``` -Defined in: [types.ts:737](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L737) +Defined in: [types.ts:777](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L777) #### Parameters diff --git a/docs/reference/interfaces/AIAdapterConfig.md b/docs/reference/interfaces/AIAdapterConfig.md index 20ecbd53..75e6cb0a 100644 --- a/docs/reference/interfaces/AIAdapterConfig.md +++ b/docs/reference/interfaces/AIAdapterConfig.md @@ -5,7 +5,7 @@ title: AIAdapterConfig # Interface: AIAdapterConfig -Defined in: [types.ts:743](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L743) +Defined in: [types.ts:783](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L783) ## Properties @@ -15,7 +15,7 @@ Defined in: [types.ts:743](https://github.com/TanStack/ai/blob/main/packages/typ optional apiKey: string; ``` -Defined in: [types.ts:744](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L744) +Defined in: [types.ts:784](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L784) *** @@ -25,7 +25,7 @@ Defined in: [types.ts:744](https://github.com/TanStack/ai/blob/main/packages/typ optional baseUrl: string; ``` -Defined in: [types.ts:745](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L745) +Defined in: [types.ts:785](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L785) *** @@ -35,7 +35,7 @@ Defined in: [types.ts:745](https://github.com/TanStack/ai/blob/main/packages/typ optional headers: Record; ``` -Defined in: [types.ts:748](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L748) +Defined in: [types.ts:788](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L788) *** @@ -45,7 +45,7 @@ Defined in: [types.ts:748](https://github.com/TanStack/ai/blob/main/packages/typ optional maxRetries: number; ``` -Defined in: [types.ts:747](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L747) +Defined in: [types.ts:787](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L787) *** @@ -55,4 +55,4 @@ Defined in: [types.ts:747](https://github.com/TanStack/ai/blob/main/packages/typ optional timeout: number; ``` -Defined in: [types.ts:746](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L746) +Defined in: [types.ts:786](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L786) diff --git a/docs/reference/interfaces/AgentLoopState.md b/docs/reference/interfaces/AgentLoopState.md index 9c117b02..c2ef467f 100644 --- a/docs/reference/interfaces/AgentLoopState.md +++ b/docs/reference/interfaces/AgentLoopState.md @@ -5,7 +5,7 @@ title: AgentLoopState # Interface: AgentLoopState -Defined in: [types.ts:450](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L450) +Defined in: [types.ts:490](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L490) State passed to agent loop strategy for determining whether to continue @@ -17,7 +17,7 @@ State passed to agent loop strategy for determining whether to continue finishReason: string | null; ``` -Defined in: [types.ts:456](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L456) +Defined in: [types.ts:496](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L496) Finish reason from the last response @@ -29,7 +29,7 @@ Finish reason from the last response iterationCount: number; ``` -Defined in: [types.ts:452](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L452) +Defined in: [types.ts:492](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L492) Current iteration count (0-indexed) @@ -44,6 +44,6 @@ messages: ModelMessage< | null>[]; ``` -Defined in: [types.ts:454](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L454) +Defined in: [types.ts:494](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L494) Current messages array diff --git a/docs/reference/interfaces/ApprovalRequestedStreamChunk.md b/docs/reference/interfaces/ApprovalRequestedStreamChunk.md index f596477c..bfbea7c0 100644 --- a/docs/reference/interfaces/ApprovalRequestedStreamChunk.md +++ b/docs/reference/interfaces/ApprovalRequestedStreamChunk.md @@ -5,7 +5,7 @@ title: ApprovalRequestedStreamChunk # Interface: ApprovalRequestedStreamChunk -Defined in: [types.ts:573](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L573) +Defined in: [types.ts:613](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L613) ## Extends @@ -19,7 +19,7 @@ Defined in: [types.ts:573](https://github.com/TanStack/ai/blob/main/packages/typ approval: object; ``` -Defined in: [types.ts:578](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L578) +Defined in: [types.ts:618](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L618) #### id @@ -41,7 +41,7 @@ needsApproval: true; id: string; ``` -Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L524) +Defined in: [types.ts:564](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L564) #### Inherited from @@ -55,7 +55,7 @@ Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typ input: any; ``` -Defined in: [types.ts:577](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L577) +Defined in: [types.ts:617](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L617) *** @@ -65,7 +65,7 @@ Defined in: [types.ts:577](https://github.com/TanStack/ai/blob/main/packages/typ model: string; ``` -Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L525) +Defined in: [types.ts:565](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L565) #### Inherited from @@ -79,7 +79,7 @@ Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typ timestamp: number; ``` -Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L526) +Defined in: [types.ts:566](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L566) #### Inherited from @@ -93,7 +93,7 @@ Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typ toolCallId: string; ``` -Defined in: [types.ts:575](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L575) +Defined in: [types.ts:615](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L615) *** @@ -103,7 +103,7 @@ Defined in: [types.ts:575](https://github.com/TanStack/ai/blob/main/packages/typ toolName: string; ``` -Defined in: [types.ts:576](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L576) +Defined in: [types.ts:616](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L616) *** @@ -113,7 +113,7 @@ Defined in: [types.ts:576](https://github.com/TanStack/ai/blob/main/packages/typ type: "approval-requested"; ``` -Defined in: [types.ts:574](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L574) +Defined in: [types.ts:614](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L614) #### Overrides diff --git a/docs/reference/interfaces/AudioPart.md b/docs/reference/interfaces/AudioPart.md index b4e8dc02..2a3c300e 100644 --- a/docs/reference/interfaces/AudioPart.md +++ b/docs/reference/interfaces/AudioPart.md @@ -5,7 +5,7 @@ title: AudioPart # Interface: AudioPart\ -Defined in: [types.ts:63](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L63) +Defined in: [types.ts:66](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L66) Audio content part for multimodal messages. @@ -25,7 +25,7 @@ Provider-specific metadata type optional metadata: TMetadata; ``` -Defined in: [types.ts:68](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L68) +Defined in: [types.ts:71](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L71) Provider-specific metadata (e.g., format, sample rate) @@ -37,7 +37,7 @@ Provider-specific metadata (e.g., format, sample rate) source: ContentPartSource; ``` -Defined in: [types.ts:66](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L66) +Defined in: [types.ts:69](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L69) Source of the audio content @@ -49,4 +49,4 @@ Source of the audio content type: "audio"; ``` -Defined in: [types.ts:64](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L64) +Defined in: [types.ts:67](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L67) diff --git a/docs/reference/interfaces/BaseStreamChunk.md b/docs/reference/interfaces/BaseStreamChunk.md index b8af3289..c160c891 100644 --- a/docs/reference/interfaces/BaseStreamChunk.md +++ b/docs/reference/interfaces/BaseStreamChunk.md @@ -5,7 +5,7 @@ title: BaseStreamChunk # Interface: BaseStreamChunk -Defined in: [types.ts:522](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L522) +Defined in: [types.ts:562](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L562) ## Extended by @@ -26,7 +26,7 @@ Defined in: [types.ts:522](https://github.com/TanStack/ai/blob/main/packages/typ id: string; ``` -Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L524) +Defined in: [types.ts:564](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L564) *** @@ -36,7 +36,7 @@ Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typ model: string; ``` -Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L525) +Defined in: [types.ts:565](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L565) *** @@ -46,7 +46,7 @@ Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typ timestamp: number; ``` -Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L526) +Defined in: [types.ts:566](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L566) *** @@ -56,4 +56,4 @@ Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typ type: StreamChunkType; ``` -Defined in: [types.ts:523](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L523) +Defined in: [types.ts:563](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L563) diff --git a/docs/reference/interfaces/ChatCompletionChunk.md b/docs/reference/interfaces/ChatCompletionChunk.md index dec3e35c..b7643a4c 100644 --- a/docs/reference/interfaces/ChatCompletionChunk.md +++ b/docs/reference/interfaces/ChatCompletionChunk.md @@ -5,7 +5,7 @@ title: ChatCompletionChunk # Interface: ChatCompletionChunk -Defined in: [types.ts:612](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L612) +Defined in: [types.ts:652](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L652) ## Properties @@ -15,7 +15,7 @@ Defined in: [types.ts:612](https://github.com/TanStack/ai/blob/main/packages/typ content: string; ``` -Defined in: [types.ts:615](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L615) +Defined in: [types.ts:655](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L655) *** @@ -25,7 +25,7 @@ Defined in: [types.ts:615](https://github.com/TanStack/ai/blob/main/packages/typ optional finishReason: "length" | "stop" | "content_filter" | null; ``` -Defined in: [types.ts:617](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L617) +Defined in: [types.ts:657](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L657) *** @@ -35,7 +35,7 @@ Defined in: [types.ts:617](https://github.com/TanStack/ai/blob/main/packages/typ id: string; ``` -Defined in: [types.ts:613](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L613) +Defined in: [types.ts:653](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L653) *** @@ -45,7 +45,7 @@ Defined in: [types.ts:613](https://github.com/TanStack/ai/blob/main/packages/typ model: string; ``` -Defined in: [types.ts:614](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L614) +Defined in: [types.ts:654](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L654) *** @@ -55,7 +55,7 @@ Defined in: [types.ts:614](https://github.com/TanStack/ai/blob/main/packages/typ optional role: "assistant"; ``` -Defined in: [types.ts:616](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L616) +Defined in: [types.ts:656](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L656) *** @@ -65,7 +65,7 @@ Defined in: [types.ts:616](https://github.com/TanStack/ai/blob/main/packages/typ optional usage: object; ``` -Defined in: [types.ts:618](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L618) +Defined in: [types.ts:658](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L658) #### completionTokens diff --git a/docs/reference/interfaces/ChatOptions.md b/docs/reference/interfaces/ChatOptions.md index 9a3efbf8..23045507 100644 --- a/docs/reference/interfaces/ChatOptions.md +++ b/docs/reference/interfaces/ChatOptions.md @@ -5,7 +5,7 @@ title: ChatOptions # Interface: ChatOptions\ -Defined in: [types.ts:476](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L476) +Defined in: [types.ts:516](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L516) Options passed into the SDK and further piped to the AI provider. @@ -35,7 +35,7 @@ Options passed into the SDK and further piped to the AI provider. optional abortController: AbortController; ``` -Defined in: [types.ts:509](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L509) +Defined in: [types.ts:549](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L549) AbortController for request cancellation. @@ -62,7 +62,7 @@ https://developer.mozilla.org/en-US/docs/Web/API/AbortController optional agentLoopStrategy: AgentLoopStrategy; ``` -Defined in: [types.ts:486](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L486) +Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L526) *** @@ -72,7 +72,7 @@ Defined in: [types.ts:486](https://github.com/TanStack/ai/blob/main/packages/typ optional conversationId: string; ``` -Defined in: [types.ts:495](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L495) +Defined in: [types.ts:535](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L535) Conversation ID for correlating client and server-side devtools events. When provided, server-side events will be linked to the client conversation in devtools. @@ -88,7 +88,7 @@ messages: ModelMessage< | null>[]; ``` -Defined in: [types.ts:483](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L483) +Defined in: [types.ts:523](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L523) *** @@ -98,7 +98,7 @@ Defined in: [types.ts:483](https://github.com/TanStack/ai/blob/main/packages/typ model: TModel; ``` -Defined in: [types.ts:482](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L482) +Defined in: [types.ts:522](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L522) *** @@ -108,7 +108,7 @@ Defined in: [types.ts:482](https://github.com/TanStack/ai/blob/main/packages/typ optional options: CommonOptions; ``` -Defined in: [types.ts:487](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L487) +Defined in: [types.ts:527](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L527) *** @@ -118,7 +118,7 @@ Defined in: [types.ts:487](https://github.com/TanStack/ai/blob/main/packages/typ optional output: TOutput; ``` -Defined in: [types.ts:490](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L490) +Defined in: [types.ts:530](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L530) *** @@ -128,7 +128,7 @@ Defined in: [types.ts:490](https://github.com/TanStack/ai/blob/main/packages/typ optional providerOptions: TProviderOptionsForModel; ``` -Defined in: [types.ts:488](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L488) +Defined in: [types.ts:528](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L528) *** @@ -138,7 +138,7 @@ Defined in: [types.ts:488](https://github.com/TanStack/ai/blob/main/packages/typ optional request: Request | RequestInit; ``` -Defined in: [types.ts:489](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L489) +Defined in: [types.ts:529](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L529) *** @@ -148,14 +148,14 @@ Defined in: [types.ts:489](https://github.com/TanStack/ai/blob/main/packages/typ optional systemPrompts: string[]; ``` -Defined in: [types.ts:485](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L485) +Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L525) *** ### tools? ```ts -optional tools: Tool>, ZodType>, string>[]; +optional tools: Tool, StandardSchemaV1, string>[]; ``` -Defined in: [types.ts:484](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L484) +Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L524) diff --git a/docs/reference/interfaces/ClientTool.md b/docs/reference/interfaces/ClientTool.md index 819d729d..349a144a 100644 --- a/docs/reference/interfaces/ClientTool.md +++ b/docs/reference/interfaces/ClientTool.md @@ -5,7 +5,7 @@ title: ClientTool # Interface: ClientTool\ -Defined in: [tools/tool-definition.ts:18](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L18) +Defined in: [tools/tool-definition.ts:23](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L23) Marker type for client-side tools @@ -13,11 +13,11 @@ Marker type for client-side tools ### TInput -`TInput` *extends* `z.ZodType` = `z.ZodType` +`TInput` *extends* `StandardSchemaV1` = `StandardSchemaV1` ### TOutput -`TOutput` *extends* `z.ZodType` = `z.ZodType` +`TOutput` *extends* `StandardSchemaV1` = `StandardSchemaV1` ### TName @@ -31,7 +31,7 @@ Marker type for client-side tools __toolSide: "client"; ``` -Defined in: [tools/tool-definition.ts:23](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L23) +Defined in: [tools/tool-definition.ts:28](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L28) *** @@ -41,27 +41,27 @@ Defined in: [tools/tool-definition.ts:23](https://github.com/TanStack/ai/blob/ma description: string; ``` -Defined in: [tools/tool-definition.ts:25](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L25) +Defined in: [tools/tool-definition.ts:30](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L30) *** ### execute()? ```ts -optional execute: (args) => output | Promise>; +optional execute: (args) => InferOutput | Promise>; ``` -Defined in: [tools/tool-definition.ts:30](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L30) +Defined in: [tools/tool-definition.ts:35](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L35) #### Parameters ##### args -`output`\<`TInput`\> +`InferOutput`\<`TInput`\> #### Returns -`output`\<`TOutput`\> \| `Promise`\<`output`\<`TOutput`\>\> +`InferOutput`\<`TOutput`\> \| `Promise`\<`InferOutput`\<`TOutput`\>\> *** @@ -71,7 +71,7 @@ Defined in: [tools/tool-definition.ts:30](https://github.com/TanStack/ai/blob/ma optional inputSchema: TInput; ``` -Defined in: [tools/tool-definition.ts:26](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L26) +Defined in: [tools/tool-definition.ts:31](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L31) *** @@ -81,7 +81,7 @@ Defined in: [tools/tool-definition.ts:26](https://github.com/TanStack/ai/blob/ma optional metadata: Record; ``` -Defined in: [tools/tool-definition.ts:29](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L29) +Defined in: [tools/tool-definition.ts:34](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L34) *** @@ -91,7 +91,7 @@ Defined in: [tools/tool-definition.ts:29](https://github.com/TanStack/ai/blob/ma name: TName; ``` -Defined in: [tools/tool-definition.ts:24](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L24) +Defined in: [tools/tool-definition.ts:29](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L29) *** @@ -101,7 +101,7 @@ Defined in: [tools/tool-definition.ts:24](https://github.com/TanStack/ai/blob/ma optional needsApproval: boolean; ``` -Defined in: [tools/tool-definition.ts:28](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L28) +Defined in: [tools/tool-definition.ts:33](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L33) *** @@ -111,4 +111,4 @@ Defined in: [tools/tool-definition.ts:28](https://github.com/TanStack/ai/blob/ma optional outputSchema: TOutput; ``` -Defined in: [tools/tool-definition.ts:27](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L27) +Defined in: [tools/tool-definition.ts:32](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L32) diff --git a/docs/reference/interfaces/ContentPartSource.md b/docs/reference/interfaces/ContentPartSource.md index 54c2839c..0626faef 100644 --- a/docs/reference/interfaces/ContentPartSource.md +++ b/docs/reference/interfaces/ContentPartSource.md @@ -5,7 +5,7 @@ title: ContentPartSource # Interface: ContentPartSource -Defined in: [types.ts:32](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L32) +Defined in: [types.ts:35](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L35) Source specification for multimodal content. Supports both inline data (base64) and URL-based content. @@ -18,7 +18,7 @@ Supports both inline data (base64) and URL-based content. type: "data" | "url"; ``` -Defined in: [types.ts:38](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L38) +Defined in: [types.ts:41](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L41) The type of source: - 'data': Inline data (typically base64 encoded) @@ -32,7 +32,7 @@ The type of source: value: string; ``` -Defined in: [types.ts:44](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L44) +Defined in: [types.ts:47](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L47) The actual content value: - For 'data': base64-encoded string diff --git a/docs/reference/interfaces/ContentStreamChunk.md b/docs/reference/interfaces/ContentStreamChunk.md index 1763ca48..70b1c91b 100644 --- a/docs/reference/interfaces/ContentStreamChunk.md +++ b/docs/reference/interfaces/ContentStreamChunk.md @@ -5,7 +5,7 @@ title: ContentStreamChunk # Interface: ContentStreamChunk -Defined in: [types.ts:529](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L529) +Defined in: [types.ts:569](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L569) ## Extends @@ -19,7 +19,7 @@ Defined in: [types.ts:529](https://github.com/TanStack/ai/blob/main/packages/typ content: string; ``` -Defined in: [types.ts:532](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L532) +Defined in: [types.ts:572](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L572) *** @@ -29,7 +29,7 @@ Defined in: [types.ts:532](https://github.com/TanStack/ai/blob/main/packages/typ delta: string; ``` -Defined in: [types.ts:531](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L531) +Defined in: [types.ts:571](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L571) *** @@ -39,7 +39,7 @@ Defined in: [types.ts:531](https://github.com/TanStack/ai/blob/main/packages/typ id: string; ``` -Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L524) +Defined in: [types.ts:564](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L564) #### Inherited from @@ -53,7 +53,7 @@ Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typ model: string; ``` -Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L525) +Defined in: [types.ts:565](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L565) #### Inherited from @@ -67,7 +67,7 @@ Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typ optional role: "assistant"; ``` -Defined in: [types.ts:533](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L533) +Defined in: [types.ts:573](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L573) *** @@ -77,7 +77,7 @@ Defined in: [types.ts:533](https://github.com/TanStack/ai/blob/main/packages/typ timestamp: number; ``` -Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L526) +Defined in: [types.ts:566](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L566) #### Inherited from @@ -91,7 +91,7 @@ Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typ type: "content"; ``` -Defined in: [types.ts:530](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L530) +Defined in: [types.ts:570](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L570) #### Overrides diff --git a/docs/reference/interfaces/DefaultMessageMetadataByModality.md b/docs/reference/interfaces/DefaultMessageMetadataByModality.md index 6b4593d5..faeab905 100644 --- a/docs/reference/interfaces/DefaultMessageMetadataByModality.md +++ b/docs/reference/interfaces/DefaultMessageMetadataByModality.md @@ -5,7 +5,7 @@ title: DefaultMessageMetadataByModality # Interface: DefaultMessageMetadataByModality -Defined in: [types.ts:664](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L664) +Defined in: [types.ts:704](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L704) Default metadata type for adapters that don't define custom metadata. Uses unknown for all modalities. @@ -18,7 +18,7 @@ Uses unknown for all modalities. audio: unknown; ``` -Defined in: [types.ts:667](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L667) +Defined in: [types.ts:707](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L707) *** @@ -28,7 +28,7 @@ Defined in: [types.ts:667](https://github.com/TanStack/ai/blob/main/packages/typ document: unknown; ``` -Defined in: [types.ts:669](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L669) +Defined in: [types.ts:709](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L709) *** @@ -38,7 +38,7 @@ Defined in: [types.ts:669](https://github.com/TanStack/ai/blob/main/packages/typ image: unknown; ``` -Defined in: [types.ts:666](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L666) +Defined in: [types.ts:706](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L706) *** @@ -48,7 +48,7 @@ Defined in: [types.ts:666](https://github.com/TanStack/ai/blob/main/packages/typ text: unknown; ``` -Defined in: [types.ts:665](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L665) +Defined in: [types.ts:705](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L705) *** @@ -58,4 +58,4 @@ Defined in: [types.ts:665](https://github.com/TanStack/ai/blob/main/packages/typ video: unknown; ``` -Defined in: [types.ts:668](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L668) +Defined in: [types.ts:708](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L708) diff --git a/docs/reference/interfaces/DocumentPart.md b/docs/reference/interfaces/DocumentPart.md index 3ee9232e..0590a4fa 100644 --- a/docs/reference/interfaces/DocumentPart.md +++ b/docs/reference/interfaces/DocumentPart.md @@ -5,7 +5,7 @@ title: DocumentPart # Interface: DocumentPart\ -Defined in: [types.ts:87](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L87) +Defined in: [types.ts:90](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L90) Document content part for multimodal messages (e.g., PDFs). @@ -25,7 +25,7 @@ Provider-specific metadata type (e.g., Anthropic's media_type) optional metadata: TMetadata; ``` -Defined in: [types.ts:92](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L92) +Defined in: [types.ts:95](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L95) Provider-specific metadata (e.g., media_type for PDFs) @@ -37,7 +37,7 @@ Provider-specific metadata (e.g., media_type for PDFs) source: ContentPartSource; ``` -Defined in: [types.ts:90](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L90) +Defined in: [types.ts:93](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L93) Source of the document content @@ -49,4 +49,4 @@ Source of the document content type: "document"; ``` -Defined in: [types.ts:88](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L88) +Defined in: [types.ts:91](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L91) diff --git a/docs/reference/interfaces/DoneStreamChunk.md b/docs/reference/interfaces/DoneStreamChunk.md index 1f6343c9..8278d0d6 100644 --- a/docs/reference/interfaces/DoneStreamChunk.md +++ b/docs/reference/interfaces/DoneStreamChunk.md @@ -5,7 +5,7 @@ title: DoneStreamChunk # Interface: DoneStreamChunk -Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) +Defined in: [types.ts:595](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L595) ## Extends @@ -19,7 +19,7 @@ Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typ finishReason: "length" | "stop" | "content_filter" | "tool_calls" | null; ``` -Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) +Defined in: [types.ts:597](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L597) *** @@ -29,7 +29,7 @@ Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typ id: string; ``` -Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L524) +Defined in: [types.ts:564](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L564) #### Inherited from @@ -43,7 +43,7 @@ Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typ model: string; ``` -Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L525) +Defined in: [types.ts:565](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L565) #### Inherited from @@ -57,7 +57,7 @@ Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typ timestamp: number; ``` -Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L526) +Defined in: [types.ts:566](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L566) #### Inherited from @@ -71,7 +71,7 @@ Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typ type: "done"; ``` -Defined in: [types.ts:556](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L556) +Defined in: [types.ts:596](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L596) #### Overrides @@ -85,7 +85,7 @@ Defined in: [types.ts:556](https://github.com/TanStack/ai/blob/main/packages/typ optional usage: object; ``` -Defined in: [types.ts:558](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L558) +Defined in: [types.ts:598](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L598) #### completionTokens diff --git a/docs/reference/interfaces/EmbeddingOptions.md b/docs/reference/interfaces/EmbeddingOptions.md index 3e65e0a5..efb71e2c 100644 --- a/docs/reference/interfaces/EmbeddingOptions.md +++ b/docs/reference/interfaces/EmbeddingOptions.md @@ -5,7 +5,7 @@ title: EmbeddingOptions # Interface: EmbeddingOptions -Defined in: [types.ts:644](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L644) +Defined in: [types.ts:684](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L684) ## Properties @@ -15,7 +15,7 @@ Defined in: [types.ts:644](https://github.com/TanStack/ai/blob/main/packages/typ optional dimensions: number; ``` -Defined in: [types.ts:647](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L647) +Defined in: [types.ts:687](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L687) *** @@ -25,7 +25,7 @@ Defined in: [types.ts:647](https://github.com/TanStack/ai/blob/main/packages/typ input: string | string[]; ``` -Defined in: [types.ts:646](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L646) +Defined in: [types.ts:686](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L686) *** @@ -35,4 +35,4 @@ Defined in: [types.ts:646](https://github.com/TanStack/ai/blob/main/packages/typ model: string; ``` -Defined in: [types.ts:645](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L645) +Defined in: [types.ts:685](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L685) diff --git a/docs/reference/interfaces/EmbeddingResult.md b/docs/reference/interfaces/EmbeddingResult.md index e45be9ba..5c9b1b0d 100644 --- a/docs/reference/interfaces/EmbeddingResult.md +++ b/docs/reference/interfaces/EmbeddingResult.md @@ -5,7 +5,7 @@ title: EmbeddingResult # Interface: EmbeddingResult -Defined in: [types.ts:650](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L650) +Defined in: [types.ts:690](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L690) ## Properties @@ -15,7 +15,7 @@ Defined in: [types.ts:650](https://github.com/TanStack/ai/blob/main/packages/typ embeddings: number[][]; ``` -Defined in: [types.ts:653](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L653) +Defined in: [types.ts:693](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L693) *** @@ -25,7 +25,7 @@ Defined in: [types.ts:653](https://github.com/TanStack/ai/blob/main/packages/typ id: string; ``` -Defined in: [types.ts:651](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L651) +Defined in: [types.ts:691](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L691) *** @@ -35,7 +35,7 @@ Defined in: [types.ts:651](https://github.com/TanStack/ai/blob/main/packages/typ model: string; ``` -Defined in: [types.ts:652](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L652) +Defined in: [types.ts:692](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L692) *** @@ -45,7 +45,7 @@ Defined in: [types.ts:652](https://github.com/TanStack/ai/blob/main/packages/typ usage: object; ``` -Defined in: [types.ts:654](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L654) +Defined in: [types.ts:694](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L694) #### promptTokens diff --git a/docs/reference/interfaces/ErrorStreamChunk.md b/docs/reference/interfaces/ErrorStreamChunk.md index 96682fc6..bd5180e8 100644 --- a/docs/reference/interfaces/ErrorStreamChunk.md +++ b/docs/reference/interfaces/ErrorStreamChunk.md @@ -5,7 +5,7 @@ title: ErrorStreamChunk # Interface: ErrorStreamChunk -Defined in: [types.ts:565](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L565) +Defined in: [types.ts:605](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L605) ## Extends @@ -19,7 +19,7 @@ Defined in: [types.ts:565](https://github.com/TanStack/ai/blob/main/packages/typ error: object; ``` -Defined in: [types.ts:567](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L567) +Defined in: [types.ts:607](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L607) #### code? @@ -41,7 +41,7 @@ message: string; id: string; ``` -Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L524) +Defined in: [types.ts:564](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L564) #### Inherited from @@ -55,7 +55,7 @@ Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typ model: string; ``` -Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L525) +Defined in: [types.ts:565](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L565) #### Inherited from @@ -69,7 +69,7 @@ Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typ timestamp: number; ``` -Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L526) +Defined in: [types.ts:566](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L566) #### Inherited from @@ -83,7 +83,7 @@ Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typ type: "error"; ``` -Defined in: [types.ts:566](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L566) +Defined in: [types.ts:606](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L606) #### Overrides diff --git a/docs/reference/interfaces/ImagePart.md b/docs/reference/interfaces/ImagePart.md index 2111598b..1a3e1844 100644 --- a/docs/reference/interfaces/ImagePart.md +++ b/docs/reference/interfaces/ImagePart.md @@ -5,7 +5,7 @@ title: ImagePart # Interface: ImagePart\ -Defined in: [types.ts:51](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L51) +Defined in: [types.ts:54](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L54) Image content part for multimodal messages. @@ -25,7 +25,7 @@ Provider-specific metadata type (e.g., OpenAI's detail level) optional metadata: TMetadata; ``` -Defined in: [types.ts:56](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L56) +Defined in: [types.ts:59](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L59) Provider-specific metadata (e.g., OpenAI's detail: 'auto' | 'low' | 'high') @@ -37,7 +37,7 @@ Provider-specific metadata (e.g., OpenAI's detail: 'auto' | 'low' | 'high') source: ContentPartSource; ``` -Defined in: [types.ts:54](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L54) +Defined in: [types.ts:57](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L57) Source of the image content @@ -49,4 +49,4 @@ Source of the image content type: "image"; ``` -Defined in: [types.ts:52](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L52) +Defined in: [types.ts:55](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L55) diff --git a/docs/reference/interfaces/ModelMessage.md b/docs/reference/interfaces/ModelMessage.md index 4495276a..566878a6 100644 --- a/docs/reference/interfaces/ModelMessage.md +++ b/docs/reference/interfaces/ModelMessage.md @@ -5,7 +5,7 @@ title: ModelMessage # Interface: ModelMessage\ -Defined in: [types.ts:163](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L163) +Defined in: [types.ts:166](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L166) ## Type Parameters @@ -21,7 +21,7 @@ Defined in: [types.ts:163](https://github.com/TanStack/ai/blob/main/packages/typ content: TContent; ``` -Defined in: [types.ts:170](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L170) +Defined in: [types.ts:173](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L173) *** @@ -31,7 +31,7 @@ Defined in: [types.ts:170](https://github.com/TanStack/ai/blob/main/packages/typ optional name: string; ``` -Defined in: [types.ts:171](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L171) +Defined in: [types.ts:174](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L174) *** @@ -41,7 +41,7 @@ Defined in: [types.ts:171](https://github.com/TanStack/ai/blob/main/packages/typ role: "user" | "assistant" | "tool"; ``` -Defined in: [types.ts:169](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L169) +Defined in: [types.ts:172](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L172) *** @@ -51,7 +51,7 @@ Defined in: [types.ts:169](https://github.com/TanStack/ai/blob/main/packages/typ optional toolCallId: string; ``` -Defined in: [types.ts:173](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L173) +Defined in: [types.ts:176](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L176) *** @@ -61,4 +61,4 @@ Defined in: [types.ts:173](https://github.com/TanStack/ai/blob/main/packages/typ optional toolCalls: ToolCall[]; ``` -Defined in: [types.ts:172](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L172) +Defined in: [types.ts:175](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L175) diff --git a/docs/reference/interfaces/ResponseFormat.md b/docs/reference/interfaces/ResponseFormat.md index 2d5f2962..9c34eee6 100644 --- a/docs/reference/interfaces/ResponseFormat.md +++ b/docs/reference/interfaces/ResponseFormat.md @@ -5,7 +5,7 @@ title: ResponseFormat # Interface: ResponseFormat\ -Defined in: [types.ts:366](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L366) +Defined in: [types.ts:406](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L406) Structured output format specification. @@ -33,7 +33,7 @@ TypeScript type of the expected data structure (for type safety) optional __data: TData; ``` -Defined in: [types.ts:444](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L444) +Defined in: [types.ts:484](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L484) **`Internal`** @@ -50,7 +50,7 @@ Allows the SDK to know what type to expect when parsing the response. optional json_schema: object; ``` -Defined in: [types.ts:383](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L383) +Defined in: [types.ts:423](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L423) JSON schema specification (required when type is "json_schema"). @@ -139,7 +139,7 @@ https://platform.openai.com/docs/guides/structured-outputs#strict-mode type: "json_object" | "json_schema"; ``` -Defined in: [types.ts:375](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L375) +Defined in: [types.ts:415](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L415) Type of structured output. diff --git a/docs/reference/interfaces/ServerTool.md b/docs/reference/interfaces/ServerTool.md index 7dc40927..1a507bc3 100644 --- a/docs/reference/interfaces/ServerTool.md +++ b/docs/reference/interfaces/ServerTool.md @@ -5,7 +5,7 @@ title: ServerTool # Interface: ServerTool\ -Defined in: [tools/tool-definition.ts:7](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L7) +Defined in: [tools/tool-definition.ts:12](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L12) Marker type for server-side tools @@ -17,11 +17,11 @@ Marker type for server-side tools ### TInput -`TInput` *extends* `z.ZodType` = `z.ZodType` +`TInput` *extends* `StandardSchemaV1` = `StandardSchemaV1` ### TOutput -`TOutput` *extends* `z.ZodType` = `z.ZodType` +`TOutput` *extends* `StandardSchemaV1` = `StandardSchemaV1` ### TName @@ -35,7 +35,7 @@ Marker type for server-side tools __toolSide: "server"; ``` -Defined in: [tools/tool-definition.ts:12](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L12) +Defined in: [tools/tool-definition.ts:17](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L17) *** @@ -45,7 +45,7 @@ Defined in: [tools/tool-definition.ts:12](https://github.com/TanStack/ai/blob/ma description: string; ``` -Defined in: [types.ts:286](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L286) +Defined in: [types.ts:291](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L291) Clear description of what the tool does. @@ -70,7 +70,7 @@ Be specific about what the tool does, what parameters it needs, and what it retu optional execute: (args) => any; ``` -Defined in: [types.ts:342](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L342) +Defined in: [types.ts:359](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L359) Optional function to execute when the model calls this tool. @@ -114,21 +114,24 @@ execute: async (args) => { optional inputSchema: TInput; ``` -Defined in: [types.ts:305](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L305) +Defined in: [types.ts:322](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L322) -Zod schema describing the tool's input parameters. +Standard Schema describing the tool's input parameters. Defines the structure and types of arguments the tool accepts. The model will generate arguments matching this schema. The schema is converted to JSON Schema for LLM providers. +Supports any Standard Schema compliant library (Zod, Valibot, ArkType, etc.) + #### See -https://zod.dev/ +https://github.com/standard-schema/standard-schema -#### Example +#### Examples ```ts +// Using Zod import { z } from 'zod'; z.object({ @@ -137,6 +140,16 @@ z.object({ }) ``` +```ts +// Using Valibot +import * as v from 'valibot'; + +v.object({ + location: v.string(), + unit: v.optional(v.picklist(["celsius", "fahrenheit"])) +}) +``` + #### Inherited from [`Tool`](Tool.md).[`inputSchema`](Tool.md#inputschema) @@ -149,7 +162,7 @@ z.object({ optional metadata: Record; ``` -Defined in: [types.ts:348](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L348) +Defined in: [types.ts:365](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L365) Additional metadata for adapters or custom extensions @@ -165,7 +178,7 @@ Additional metadata for adapters or custom extensions name: TName; ``` -Defined in: [types.ts:276](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L276) +Defined in: [types.ts:281](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L281) Unique name of the tool (used by the model to call it). @@ -190,7 +203,7 @@ Must be unique within the tools array. optional needsApproval: boolean; ``` -Defined in: [types.ts:345](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L345) +Defined in: [types.ts:362](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L362) If true, tool execution requires user approval before running. Works with both server and client tools. @@ -206,9 +219,9 @@ If true, tool execution requires user approval before running. Works with both s optional outputSchema: TOutput; ``` -Defined in: [types.ts:323](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L323) +Defined in: [types.ts:340](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L340) -Optional Zod schema for validating tool output. +Optional Standard Schema for validating tool output. If provided, tool results will be validated against this schema before being sent back to the model. This catches bugs in tool implementations @@ -229,3 +242,49 @@ z.object({ #### Inherited from [`Tool`](Tool.md).[`outputSchema`](Tool.md#outputschema) + +*** + +### toJsonSchema()? + +```ts +optional toJsonSchema: (inputSchema) => Record | undefined; +``` + +Defined in: [types.ts:386](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L386) + +Optional function to convert the inputSchema to JSON Schema format. + +This allows tools to use any schema library (Zod, Valibot, ArkType, etc.) +and provide their own conversion logic. Each adapter will call this function +to get the JSON Schema representation of the tool's parameters. + +#### Parameters + +##### inputSchema + +`StandardSchemaV1` + +The Standard Schema input schema to convert + +#### Returns + +`Record`\<`string`, `any`\> \| `undefined` + +JSON Schema object describing the tool's input parameters, or undefined + +#### Example + +```ts +// With Zod +import { toJSONSchema } from 'zod'; +toJsonSchema: (schema) => toJSONSchema(schema) + +// With Valibot +import { toJSONSchema } from '@valibot/to-json-schema'; +toJsonSchema: (schema) => toJSONSchema(schema) +``` + +#### Inherited from + +[`Tool`](Tool.md).[`toJsonSchema`](Tool.md#tojsonschema) diff --git a/docs/reference/interfaces/SummarizationOptions.md b/docs/reference/interfaces/SummarizationOptions.md index 3007ea69..e7da5b5d 100644 --- a/docs/reference/interfaces/SummarizationOptions.md +++ b/docs/reference/interfaces/SummarizationOptions.md @@ -5,7 +5,7 @@ title: SummarizationOptions # Interface: SummarizationOptions -Defined in: [types.ts:625](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L625) +Defined in: [types.ts:665](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L665) ## Properties @@ -15,7 +15,7 @@ Defined in: [types.ts:625](https://github.com/TanStack/ai/blob/main/packages/typ optional focus: string[]; ``` -Defined in: [types.ts:630](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L630) +Defined in: [types.ts:670](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L670) *** @@ -25,7 +25,7 @@ Defined in: [types.ts:630](https://github.com/TanStack/ai/blob/main/packages/typ optional maxLength: number; ``` -Defined in: [types.ts:628](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L628) +Defined in: [types.ts:668](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L668) *** @@ -35,7 +35,7 @@ Defined in: [types.ts:628](https://github.com/TanStack/ai/blob/main/packages/typ model: string; ``` -Defined in: [types.ts:626](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L626) +Defined in: [types.ts:666](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L666) *** @@ -45,7 +45,7 @@ Defined in: [types.ts:626](https://github.com/TanStack/ai/blob/main/packages/typ optional style: "bullet-points" | "paragraph" | "concise"; ``` -Defined in: [types.ts:629](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L629) +Defined in: [types.ts:669](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L669) *** @@ -55,4 +55,4 @@ Defined in: [types.ts:629](https://github.com/TanStack/ai/blob/main/packages/typ text: string; ``` -Defined in: [types.ts:627](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L627) +Defined in: [types.ts:667](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L667) diff --git a/docs/reference/interfaces/SummarizationResult.md b/docs/reference/interfaces/SummarizationResult.md index fa025fe6..b561f9d3 100644 --- a/docs/reference/interfaces/SummarizationResult.md +++ b/docs/reference/interfaces/SummarizationResult.md @@ -5,7 +5,7 @@ title: SummarizationResult # Interface: SummarizationResult -Defined in: [types.ts:633](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L633) +Defined in: [types.ts:673](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L673) ## Properties @@ -15,7 +15,7 @@ Defined in: [types.ts:633](https://github.com/TanStack/ai/blob/main/packages/typ id: string; ``` -Defined in: [types.ts:634](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L634) +Defined in: [types.ts:674](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L674) *** @@ -25,7 +25,7 @@ Defined in: [types.ts:634](https://github.com/TanStack/ai/blob/main/packages/typ model: string; ``` -Defined in: [types.ts:635](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L635) +Defined in: [types.ts:675](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L675) *** @@ -35,7 +35,7 @@ Defined in: [types.ts:635](https://github.com/TanStack/ai/blob/main/packages/typ summary: string; ``` -Defined in: [types.ts:636](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L636) +Defined in: [types.ts:676](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L676) *** @@ -45,7 +45,7 @@ Defined in: [types.ts:636](https://github.com/TanStack/ai/blob/main/packages/typ usage: object; ``` -Defined in: [types.ts:637](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L637) +Defined in: [types.ts:677](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L677) #### completionTokens diff --git a/docs/reference/interfaces/TextPart.md b/docs/reference/interfaces/TextPart.md index 34df956e..3928ea37 100644 --- a/docs/reference/interfaces/TextPart.md +++ b/docs/reference/interfaces/TextPart.md @@ -5,7 +5,7 @@ title: TextPart # Interface: TextPart\ -Defined in: [types.ts:179](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L179) +Defined in: [types.ts:182](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L182) Message parts - building blocks of UIMessage @@ -23,7 +23,7 @@ Message parts - building blocks of UIMessage content: string; ``` -Defined in: [types.ts:181](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L181) +Defined in: [types.ts:184](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L184) *** @@ -33,7 +33,7 @@ Defined in: [types.ts:181](https://github.com/TanStack/ai/blob/main/packages/typ optional metadata: TMetadata; ``` -Defined in: [types.ts:182](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L182) +Defined in: [types.ts:185](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L185) *** @@ -43,4 +43,4 @@ Defined in: [types.ts:182](https://github.com/TanStack/ai/blob/main/packages/typ type: "text"; ``` -Defined in: [types.ts:180](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L180) +Defined in: [types.ts:183](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L183) diff --git a/docs/reference/interfaces/ThinkingPart.md b/docs/reference/interfaces/ThinkingPart.md index 2b226b21..ce5a8232 100644 --- a/docs/reference/interfaces/ThinkingPart.md +++ b/docs/reference/interfaces/ThinkingPart.md @@ -5,7 +5,7 @@ title: ThinkingPart # Interface: ThinkingPart -Defined in: [types.ts:209](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L209) +Defined in: [types.ts:212](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L212) ## Properties @@ -15,7 +15,7 @@ Defined in: [types.ts:209](https://github.com/TanStack/ai/blob/main/packages/typ content: string; ``` -Defined in: [types.ts:211](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L211) +Defined in: [types.ts:214](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L214) *** @@ -25,4 +25,4 @@ Defined in: [types.ts:211](https://github.com/TanStack/ai/blob/main/packages/typ type: "thinking"; ``` -Defined in: [types.ts:210](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L210) +Defined in: [types.ts:213](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L213) diff --git a/docs/reference/interfaces/ThinkingStreamChunk.md b/docs/reference/interfaces/ThinkingStreamChunk.md index 05828450..4a5efc30 100644 --- a/docs/reference/interfaces/ThinkingStreamChunk.md +++ b/docs/reference/interfaces/ThinkingStreamChunk.md @@ -5,7 +5,7 @@ title: ThinkingStreamChunk # Interface: ThinkingStreamChunk -Defined in: [types.ts:591](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L591) +Defined in: [types.ts:631](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L631) ## Extends @@ -19,7 +19,7 @@ Defined in: [types.ts:591](https://github.com/TanStack/ai/blob/main/packages/typ content: string; ``` -Defined in: [types.ts:594](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L594) +Defined in: [types.ts:634](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L634) *** @@ -29,7 +29,7 @@ Defined in: [types.ts:594](https://github.com/TanStack/ai/blob/main/packages/typ optional delta: string; ``` -Defined in: [types.ts:593](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L593) +Defined in: [types.ts:633](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L633) *** @@ -39,7 +39,7 @@ Defined in: [types.ts:593](https://github.com/TanStack/ai/blob/main/packages/typ id: string; ``` -Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L524) +Defined in: [types.ts:564](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L564) #### Inherited from @@ -53,7 +53,7 @@ Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typ model: string; ``` -Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L525) +Defined in: [types.ts:565](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L565) #### Inherited from @@ -67,7 +67,7 @@ Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typ timestamp: number; ``` -Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L526) +Defined in: [types.ts:566](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L566) #### Inherited from @@ -81,7 +81,7 @@ Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typ type: "thinking"; ``` -Defined in: [types.ts:592](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L592) +Defined in: [types.ts:632](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L632) #### Overrides diff --git a/docs/reference/interfaces/Tool.md b/docs/reference/interfaces/Tool.md index 3841b042..d65405ab 100644 --- a/docs/reference/interfaces/Tool.md +++ b/docs/reference/interfaces/Tool.md @@ -5,19 +5,21 @@ title: Tool # Interface: Tool\ -Defined in: [types.ts:263](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L263) +Defined in: [types.ts:268](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L268) Tool/Function definition for function calling. Tools allow the model to interact with external systems, APIs, or perform computations. The model will decide when to call tools based on the user's request and the tool descriptions. -Tools use Zod schemas for runtime validation and type safety. +Tools use Standard Schema for runtime validation and type safety, supporting any +compliant schema library (Zod, Valibot, ArkType, etc.). ## See - https://platform.openai.com/docs/guides/function-calling - https://docs.anthropic.com/claude/docs/tool-use + - https://github.com/standard-schema/standard-schema ## Extended by @@ -28,11 +30,11 @@ Tools use Zod schemas for runtime validation and type safety. ### TInput -`TInput` *extends* `z.ZodType` = `z.ZodType` +`TInput` *extends* `StandardSchemaV1` = `StandardSchemaV1` ### TOutput -`TOutput` *extends* `z.ZodType` = `z.ZodType` +`TOutput` *extends* `StandardSchemaV1` = `StandardSchemaV1` ### TName @@ -46,7 +48,7 @@ Tools use Zod schemas for runtime validation and type safety. description: string; ``` -Defined in: [types.ts:286](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L286) +Defined in: [types.ts:291](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L291) Clear description of what the tool does. @@ -67,7 +69,7 @@ Be specific about what the tool does, what parameters it needs, and what it retu optional execute: (args) => any; ``` -Defined in: [types.ts:342](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L342) +Defined in: [types.ts:359](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L359) Optional function to execute when the model calls this tool. @@ -107,21 +109,24 @@ execute: async (args) => { optional inputSchema: TInput; ``` -Defined in: [types.ts:305](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L305) +Defined in: [types.ts:322](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L322) -Zod schema describing the tool's input parameters. +Standard Schema describing the tool's input parameters. Defines the structure and types of arguments the tool accepts. The model will generate arguments matching this schema. The schema is converted to JSON Schema for LLM providers. +Supports any Standard Schema compliant library (Zod, Valibot, ArkType, etc.) + #### See -https://zod.dev/ +https://github.com/standard-schema/standard-schema -#### Example +#### Examples ```ts +// Using Zod import { z } from 'zod'; z.object({ @@ -130,6 +135,16 @@ z.object({ }) ``` +```ts +// Using Valibot +import * as v from 'valibot'; + +v.object({ + location: v.string(), + unit: v.optional(v.picklist(["celsius", "fahrenheit"])) +}) +``` + *** ### metadata? @@ -138,7 +153,7 @@ z.object({ optional metadata: Record; ``` -Defined in: [types.ts:348](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L348) +Defined in: [types.ts:365](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L365) Additional metadata for adapters or custom extensions @@ -150,7 +165,7 @@ Additional metadata for adapters or custom extensions name: TName; ``` -Defined in: [types.ts:276](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L276) +Defined in: [types.ts:281](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L281) Unique name of the tool (used by the model to call it). @@ -171,7 +186,7 @@ Must be unique within the tools array. optional needsApproval: boolean; ``` -Defined in: [types.ts:345](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L345) +Defined in: [types.ts:362](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L362) If true, tool execution requires user approval before running. Works with both server and client tools. @@ -183,9 +198,9 @@ If true, tool execution requires user approval before running. Works with both s optional outputSchema: TOutput; ``` -Defined in: [types.ts:323](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L323) +Defined in: [types.ts:340](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L340) -Optional Zod schema for validating tool output. +Optional Standard Schema for validating tool output. If provided, tool results will be validated against this schema before being sent back to the model. This catches bugs in tool implementations @@ -202,3 +217,45 @@ z.object({ forecast: z.array(z.string()).optional() }) ``` + +*** + +### toJsonSchema()? + +```ts +optional toJsonSchema: (inputSchema) => Record | undefined; +``` + +Defined in: [types.ts:386](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L386) + +Optional function to convert the inputSchema to JSON Schema format. + +This allows tools to use any schema library (Zod, Valibot, ArkType, etc.) +and provide their own conversion logic. Each adapter will call this function +to get the JSON Schema representation of the tool's parameters. + +#### Parameters + +##### inputSchema + +`StandardSchemaV1` + +The Standard Schema input schema to convert + +#### Returns + +`Record`\<`string`, `any`\> \| `undefined` + +JSON Schema object describing the tool's input parameters, or undefined + +#### Example + +```ts +// With Zod +import { toJSONSchema } from 'zod'; +toJsonSchema: (schema) => toJSONSchema(schema) + +// With Valibot +import { toJSONSchema } from '@valibot/to-json-schema'; +toJsonSchema: (schema) => toJSONSchema(schema) +``` diff --git a/docs/reference/interfaces/ToolCall.md b/docs/reference/interfaces/ToolCall.md index ac9a60d0..b7efdc7f 100644 --- a/docs/reference/interfaces/ToolCall.md +++ b/docs/reference/interfaces/ToolCall.md @@ -5,7 +5,7 @@ title: ToolCall # Interface: ToolCall -Defined in: [types.ts:5](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L5) +Defined in: [types.ts:8](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L8) ## Properties @@ -15,7 +15,7 @@ Defined in: [types.ts:5](https://github.com/TanStack/ai/blob/main/packages/types function: object; ``` -Defined in: [types.ts:8](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L8) +Defined in: [types.ts:11](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L11) #### arguments @@ -37,7 +37,7 @@ name: string; id: string; ``` -Defined in: [types.ts:6](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L6) +Defined in: [types.ts:9](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L9) *** @@ -47,4 +47,4 @@ Defined in: [types.ts:6](https://github.com/TanStack/ai/blob/main/packages/types type: "function"; ``` -Defined in: [types.ts:7](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L7) +Defined in: [types.ts:10](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L10) diff --git a/docs/reference/interfaces/ToolCallPart.md b/docs/reference/interfaces/ToolCallPart.md index 66052c25..6ef7ef44 100644 --- a/docs/reference/interfaces/ToolCallPart.md +++ b/docs/reference/interfaces/ToolCallPart.md @@ -5,7 +5,7 @@ title: ToolCallPart # Interface: ToolCallPart -Defined in: [types.ts:185](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L185) +Defined in: [types.ts:188](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L188) ## Properties @@ -15,7 +15,7 @@ Defined in: [types.ts:185](https://github.com/TanStack/ai/blob/main/packages/typ optional approval: object; ``` -Defined in: [types.ts:192](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L192) +Defined in: [types.ts:195](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L195) Approval metadata if tool requires user approval @@ -45,7 +45,7 @@ needsApproval: boolean; arguments: string; ``` -Defined in: [types.ts:189](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L189) +Defined in: [types.ts:192](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L192) *** @@ -55,7 +55,7 @@ Defined in: [types.ts:189](https://github.com/TanStack/ai/blob/main/packages/typ id: string; ``` -Defined in: [types.ts:187](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L187) +Defined in: [types.ts:190](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L190) *** @@ -65,7 +65,7 @@ Defined in: [types.ts:187](https://github.com/TanStack/ai/blob/main/packages/typ name: string; ``` -Defined in: [types.ts:188](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L188) +Defined in: [types.ts:191](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L191) *** @@ -75,7 +75,7 @@ Defined in: [types.ts:188](https://github.com/TanStack/ai/blob/main/packages/typ optional output: any; ``` -Defined in: [types.ts:198](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L198) +Defined in: [types.ts:201](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L201) Tool execution output (for client tools or after approval) @@ -87,7 +87,7 @@ Tool execution output (for client tools or after approval) state: ToolCallState; ``` -Defined in: [types.ts:190](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L190) +Defined in: [types.ts:193](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L193) *** @@ -97,4 +97,4 @@ Defined in: [types.ts:190](https://github.com/TanStack/ai/blob/main/packages/typ type: "tool-call"; ``` -Defined in: [types.ts:186](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L186) +Defined in: [types.ts:189](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L189) diff --git a/docs/reference/interfaces/ToolCallStreamChunk.md b/docs/reference/interfaces/ToolCallStreamChunk.md index 85be420d..e8177067 100644 --- a/docs/reference/interfaces/ToolCallStreamChunk.md +++ b/docs/reference/interfaces/ToolCallStreamChunk.md @@ -5,7 +5,7 @@ title: ToolCallStreamChunk # Interface: ToolCallStreamChunk -Defined in: [types.ts:536](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L536) +Defined in: [types.ts:576](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L576) ## Extends @@ -19,7 +19,7 @@ Defined in: [types.ts:536](https://github.com/TanStack/ai/blob/main/packages/typ id: string; ``` -Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L524) +Defined in: [types.ts:564](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L564) #### Inherited from @@ -33,7 +33,7 @@ Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typ index: number; ``` -Defined in: [types.ts:546](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L546) +Defined in: [types.ts:586](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L586) *** @@ -43,7 +43,7 @@ Defined in: [types.ts:546](https://github.com/TanStack/ai/blob/main/packages/typ model: string; ``` -Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L525) +Defined in: [types.ts:565](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L565) #### Inherited from @@ -57,7 +57,7 @@ Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typ timestamp: number; ``` -Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L526) +Defined in: [types.ts:566](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L566) #### Inherited from @@ -71,7 +71,7 @@ Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typ toolCall: object; ``` -Defined in: [types.ts:538](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L538) +Defined in: [types.ts:578](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L578) #### function @@ -111,7 +111,7 @@ type: "function"; type: "tool_call"; ``` -Defined in: [types.ts:537](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L537) +Defined in: [types.ts:577](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L577) #### Overrides diff --git a/docs/reference/interfaces/ToolConfig.md b/docs/reference/interfaces/ToolConfig.md index 4af8fcf8..939d7f99 100644 --- a/docs/reference/interfaces/ToolConfig.md +++ b/docs/reference/interfaces/ToolConfig.md @@ -5,10 +5,10 @@ title: ToolConfig # Interface: ToolConfig -Defined in: [types.ts:351](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L351) +Defined in: [types.ts:391](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L391) ## Indexable ```ts -[key: string]: Tool>, ZodType>, string> +[key: string]: Tool, StandardSchemaV1, string> ``` diff --git a/docs/reference/interfaces/ToolDefinition.md b/docs/reference/interfaces/ToolDefinition.md index ee4ccf6a..82809a7e 100644 --- a/docs/reference/interfaces/ToolDefinition.md +++ b/docs/reference/interfaces/ToolDefinition.md @@ -5,7 +5,7 @@ title: ToolDefinition # Interface: ToolDefinition\ -Defined in: [tools/tool-definition.ts:95](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L95) +Defined in: [tools/tool-definition.ts:103](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L103) Tool definition builder that allows creating server or client tools from a shared definition @@ -17,11 +17,11 @@ Tool definition builder that allows creating server or client tools from a share ### TInput -`TInput` *extends* `z.ZodType` = `z.ZodType` +`TInput` *extends* `StandardSchemaV1` = `StandardSchemaV1` ### TOutput -`TOutput` *extends* `z.ZodType` = `z.ZodType` +`TOutput` *extends* `StandardSchemaV1` = `StandardSchemaV1` ### TName @@ -35,7 +35,7 @@ Tool definition builder that allows creating server or client tools from a share __toolSide: "definition"; ``` -Defined in: [tools/tool-definition.ts:43](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L43) +Defined in: [tools/tool-definition.ts:48](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L48) #### Inherited from @@ -49,7 +49,7 @@ Defined in: [tools/tool-definition.ts:43](https://github.com/TanStack/ai/blob/ma client: (execute?) => ClientTool; ``` -Defined in: [tools/tool-definition.ts:112](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L112) +Defined in: [tools/tool-definition.ts:120](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L120) Create a client-side tool with optional execute function @@ -57,7 +57,7 @@ Create a client-side tool with optional execute function ##### execute? -(`args`) => `output`\<`TOutput`\> \| `Promise`\<`output`\<`TOutput`\>\> +(`args`) => `InferOutput`\<`TOutput`\> \| `Promise`\<`InferOutput`\<`TOutput`\>\> #### Returns @@ -71,7 +71,7 @@ Create a client-side tool with optional execute function description: string; ``` -Defined in: [types.ts:286](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L286) +Defined in: [types.ts:291](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L291) Clear description of what the tool does. @@ -96,7 +96,7 @@ Be specific about what the tool does, what parameters it needs, and what it retu optional execute: (args) => any; ``` -Defined in: [types.ts:342](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L342) +Defined in: [types.ts:359](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L359) Optional function to execute when the model calls this tool. @@ -140,21 +140,24 @@ execute: async (args) => { optional inputSchema: TInput; ``` -Defined in: [types.ts:305](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L305) +Defined in: [types.ts:322](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L322) -Zod schema describing the tool's input parameters. +Standard Schema describing the tool's input parameters. Defines the structure and types of arguments the tool accepts. The model will generate arguments matching this schema. The schema is converted to JSON Schema for LLM providers. +Supports any Standard Schema compliant library (Zod, Valibot, ArkType, etc.) + #### See -https://zod.dev/ +https://github.com/standard-schema/standard-schema -#### Example +#### Examples ```ts +// Using Zod import { z } from 'zod'; z.object({ @@ -163,6 +166,16 @@ z.object({ }) ``` +```ts +// Using Valibot +import * as v from 'valibot'; + +v.object({ + location: v.string(), + unit: v.optional(v.picklist(["celsius", "fahrenheit"])) +}) +``` + #### Inherited from [`ToolDefinitionInstance`](ToolDefinitionInstance.md).[`inputSchema`](ToolDefinitionInstance.md#inputschema) @@ -175,7 +188,7 @@ z.object({ optional metadata: Record; ``` -Defined in: [types.ts:348](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L348) +Defined in: [types.ts:365](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L365) Additional metadata for adapters or custom extensions @@ -191,7 +204,7 @@ Additional metadata for adapters or custom extensions name: TName; ``` -Defined in: [types.ts:276](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L276) +Defined in: [types.ts:281](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L281) Unique name of the tool (used by the model to call it). @@ -216,7 +229,7 @@ Must be unique within the tools array. optional needsApproval: boolean; ``` -Defined in: [types.ts:345](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L345) +Defined in: [types.ts:362](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L362) If true, tool execution requires user approval before running. Works with both server and client tools. @@ -232,9 +245,9 @@ If true, tool execution requires user approval before running. Works with both s optional outputSchema: TOutput; ``` -Defined in: [types.ts:323](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L323) +Defined in: [types.ts:340](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L340) -Optional Zod schema for validating tool output. +Optional Standard Schema for validating tool output. If provided, tool results will be validated against this schema before being sent back to the model. This catches bugs in tool implementations @@ -264,7 +277,7 @@ z.object({ server: (execute) => ServerTool; ``` -Defined in: [tools/tool-definition.ts:103](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L103) +Defined in: [tools/tool-definition.ts:111](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L111) Create a server-side tool with execute function @@ -272,8 +285,54 @@ Create a server-side tool with execute function ##### execute -(`args`) => `output`\<`TOutput`\> \| `Promise`\<`output`\<`TOutput`\>\> +(`args`) => `InferOutput`\<`TOutput`\> \| `Promise`\<`InferOutput`\<`TOutput`\>\> #### Returns [`ServerTool`](ServerTool.md)\<`TInput`, `TOutput`, `TName`\> + +*** + +### toJsonSchema()? + +```ts +optional toJsonSchema: (inputSchema) => Record | undefined; +``` + +Defined in: [types.ts:386](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L386) + +Optional function to convert the inputSchema to JSON Schema format. + +This allows tools to use any schema library (Zod, Valibot, ArkType, etc.) +and provide their own conversion logic. Each adapter will call this function +to get the JSON Schema representation of the tool's parameters. + +#### Parameters + +##### inputSchema + +`StandardSchemaV1` + +The Standard Schema input schema to convert + +#### Returns + +`Record`\<`string`, `any`\> \| `undefined` + +JSON Schema object describing the tool's input parameters, or undefined + +#### Example + +```ts +// With Zod +import { toJSONSchema } from 'zod'; +toJsonSchema: (schema) => toJSONSchema(schema) + +// With Valibot +import { toJSONSchema } from '@valibot/to-json-schema'; +toJsonSchema: (schema) => toJSONSchema(schema) +``` + +#### Inherited from + +[`ToolDefinitionInstance`](ToolDefinitionInstance.md).[`toJsonSchema`](ToolDefinitionInstance.md#tojsonschema) diff --git a/docs/reference/interfaces/ToolDefinitionConfig.md b/docs/reference/interfaces/ToolDefinitionConfig.md index df55b556..3d019ede 100644 --- a/docs/reference/interfaces/ToolDefinitionConfig.md +++ b/docs/reference/interfaces/ToolDefinitionConfig.md @@ -5,7 +5,7 @@ title: ToolDefinitionConfig # Interface: ToolDefinitionConfig\ -Defined in: [tools/tool-definition.ts:79](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L79) +Defined in: [tools/tool-definition.ts:84](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L84) Tool definition configuration @@ -13,11 +13,11 @@ Tool definition configuration ### TInput -`TInput` *extends* `z.ZodType` = `z.ZodType` +`TInput` *extends* `StandardSchemaV1` = `StandardSchemaV1` ### TOutput -`TOutput` *extends* `z.ZodType` = `z.ZodType` +`TOutput` *extends* `StandardSchemaV1` = `StandardSchemaV1` ### TName @@ -31,7 +31,7 @@ Tool definition configuration description: string; ``` -Defined in: [tools/tool-definition.ts:85](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L85) +Defined in: [tools/tool-definition.ts:90](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L90) *** @@ -41,7 +41,7 @@ Defined in: [tools/tool-definition.ts:85](https://github.com/TanStack/ai/blob/ma optional inputSchema: TInput; ``` -Defined in: [tools/tool-definition.ts:86](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L86) +Defined in: [tools/tool-definition.ts:91](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L91) *** @@ -51,7 +51,7 @@ Defined in: [tools/tool-definition.ts:86](https://github.com/TanStack/ai/blob/ma optional metadata: Record; ``` -Defined in: [tools/tool-definition.ts:89](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L89) +Defined in: [tools/tool-definition.ts:97](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L97) *** @@ -61,7 +61,7 @@ Defined in: [tools/tool-definition.ts:89](https://github.com/TanStack/ai/blob/ma name: TName; ``` -Defined in: [tools/tool-definition.ts:84](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L84) +Defined in: [tools/tool-definition.ts:89](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L89) *** @@ -71,7 +71,7 @@ Defined in: [tools/tool-definition.ts:84](https://github.com/TanStack/ai/blob/ma optional needsApproval: boolean; ``` -Defined in: [tools/tool-definition.ts:88](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L88) +Defined in: [tools/tool-definition.ts:96](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L96) *** @@ -81,4 +81,24 @@ Defined in: [tools/tool-definition.ts:88](https://github.com/TanStack/ai/blob/ma optional outputSchema: TOutput; ``` -Defined in: [tools/tool-definition.ts:87](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L87) +Defined in: [tools/tool-definition.ts:92](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L92) + +*** + +### toJsonSchema()? + +```ts +optional toJsonSchema: (inputSchema) => Record | undefined; +``` + +Defined in: [tools/tool-definition.ts:93](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L93) + +#### Parameters + +##### inputSchema + +`StandardSchemaV1` + +#### Returns + +`Record`\<`string`, `any`\> \| `undefined` diff --git a/docs/reference/interfaces/ToolDefinitionInstance.md b/docs/reference/interfaces/ToolDefinitionInstance.md index 6884845c..706f95a1 100644 --- a/docs/reference/interfaces/ToolDefinitionInstance.md +++ b/docs/reference/interfaces/ToolDefinitionInstance.md @@ -5,7 +5,7 @@ title: ToolDefinitionInstance # Interface: ToolDefinitionInstance\ -Defined in: [tools/tool-definition.ts:38](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L38) +Defined in: [tools/tool-definition.ts:43](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L43) Tool definition that can be used directly or instantiated for server/client @@ -21,11 +21,11 @@ Tool definition that can be used directly or instantiated for server/client ### TInput -`TInput` *extends* `z.ZodType` = `z.ZodType` +`TInput` *extends* `StandardSchemaV1` = `StandardSchemaV1` ### TOutput -`TOutput` *extends* `z.ZodType` = `z.ZodType` +`TOutput` *extends* `StandardSchemaV1` = `StandardSchemaV1` ### TName @@ -39,7 +39,7 @@ Tool definition that can be used directly or instantiated for server/client __toolSide: "definition"; ``` -Defined in: [tools/tool-definition.ts:43](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L43) +Defined in: [tools/tool-definition.ts:48](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L48) *** @@ -49,7 +49,7 @@ Defined in: [tools/tool-definition.ts:43](https://github.com/TanStack/ai/blob/ma description: string; ``` -Defined in: [types.ts:286](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L286) +Defined in: [types.ts:291](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L291) Clear description of what the tool does. @@ -74,7 +74,7 @@ Be specific about what the tool does, what parameters it needs, and what it retu optional execute: (args) => any; ``` -Defined in: [types.ts:342](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L342) +Defined in: [types.ts:359](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L359) Optional function to execute when the model calls this tool. @@ -118,21 +118,24 @@ execute: async (args) => { optional inputSchema: TInput; ``` -Defined in: [types.ts:305](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L305) +Defined in: [types.ts:322](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L322) -Zod schema describing the tool's input parameters. +Standard Schema describing the tool's input parameters. Defines the structure and types of arguments the tool accepts. The model will generate arguments matching this schema. The schema is converted to JSON Schema for LLM providers. +Supports any Standard Schema compliant library (Zod, Valibot, ArkType, etc.) + #### See -https://zod.dev/ +https://github.com/standard-schema/standard-schema -#### Example +#### Examples ```ts +// Using Zod import { z } from 'zod'; z.object({ @@ -141,6 +144,16 @@ z.object({ }) ``` +```ts +// Using Valibot +import * as v from 'valibot'; + +v.object({ + location: v.string(), + unit: v.optional(v.picklist(["celsius", "fahrenheit"])) +}) +``` + #### Inherited from [`Tool`](Tool.md).[`inputSchema`](Tool.md#inputschema) @@ -153,7 +166,7 @@ z.object({ optional metadata: Record; ``` -Defined in: [types.ts:348](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L348) +Defined in: [types.ts:365](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L365) Additional metadata for adapters or custom extensions @@ -169,7 +182,7 @@ Additional metadata for adapters or custom extensions name: TName; ``` -Defined in: [types.ts:276](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L276) +Defined in: [types.ts:281](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L281) Unique name of the tool (used by the model to call it). @@ -194,7 +207,7 @@ Must be unique within the tools array. optional needsApproval: boolean; ``` -Defined in: [types.ts:345](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L345) +Defined in: [types.ts:362](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L362) If true, tool execution requires user approval before running. Works with both server and client tools. @@ -210,9 +223,9 @@ If true, tool execution requires user approval before running. Works with both s optional outputSchema: TOutput; ``` -Defined in: [types.ts:323](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L323) +Defined in: [types.ts:340](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L340) -Optional Zod schema for validating tool output. +Optional Standard Schema for validating tool output. If provided, tool results will be validated against this schema before being sent back to the model. This catches bugs in tool implementations @@ -233,3 +246,49 @@ z.object({ #### Inherited from [`Tool`](Tool.md).[`outputSchema`](Tool.md#outputschema) + +*** + +### toJsonSchema()? + +```ts +optional toJsonSchema: (inputSchema) => Record | undefined; +``` + +Defined in: [types.ts:386](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L386) + +Optional function to convert the inputSchema to JSON Schema format. + +This allows tools to use any schema library (Zod, Valibot, ArkType, etc.) +and provide their own conversion logic. Each adapter will call this function +to get the JSON Schema representation of the tool's parameters. + +#### Parameters + +##### inputSchema + +`StandardSchemaV1` + +The Standard Schema input schema to convert + +#### Returns + +`Record`\<`string`, `any`\> \| `undefined` + +JSON Schema object describing the tool's input parameters, or undefined + +#### Example + +```ts +// With Zod +import { toJSONSchema } from 'zod'; +toJsonSchema: (schema) => toJSONSchema(schema) + +// With Valibot +import { toJSONSchema } from '@valibot/to-json-schema'; +toJsonSchema: (schema) => toJSONSchema(schema) +``` + +#### Inherited from + +[`Tool`](Tool.md).[`toJsonSchema`](Tool.md#tojsonschema) diff --git a/docs/reference/interfaces/ToolInputAvailableStreamChunk.md b/docs/reference/interfaces/ToolInputAvailableStreamChunk.md index a22783a7..4613127a 100644 --- a/docs/reference/interfaces/ToolInputAvailableStreamChunk.md +++ b/docs/reference/interfaces/ToolInputAvailableStreamChunk.md @@ -5,7 +5,7 @@ title: ToolInputAvailableStreamChunk # Interface: ToolInputAvailableStreamChunk -Defined in: [types.ts:584](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L584) +Defined in: [types.ts:624](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L624) ## Extends @@ -19,7 +19,7 @@ Defined in: [types.ts:584](https://github.com/TanStack/ai/blob/main/packages/typ id: string; ``` -Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L524) +Defined in: [types.ts:564](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L564) #### Inherited from @@ -33,7 +33,7 @@ Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typ input: any; ``` -Defined in: [types.ts:588](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L588) +Defined in: [types.ts:628](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L628) *** @@ -43,7 +43,7 @@ Defined in: [types.ts:588](https://github.com/TanStack/ai/blob/main/packages/typ model: string; ``` -Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L525) +Defined in: [types.ts:565](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L565) #### Inherited from @@ -57,7 +57,7 @@ Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typ timestamp: number; ``` -Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L526) +Defined in: [types.ts:566](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L566) #### Inherited from @@ -71,7 +71,7 @@ Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typ toolCallId: string; ``` -Defined in: [types.ts:586](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L586) +Defined in: [types.ts:626](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L626) *** @@ -81,7 +81,7 @@ Defined in: [types.ts:586](https://github.com/TanStack/ai/blob/main/packages/typ toolName: string; ``` -Defined in: [types.ts:587](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L587) +Defined in: [types.ts:627](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L627) *** @@ -91,7 +91,7 @@ Defined in: [types.ts:587](https://github.com/TanStack/ai/blob/main/packages/typ type: "tool-input-available"; ``` -Defined in: [types.ts:585](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L585) +Defined in: [types.ts:625](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L625) #### Overrides diff --git a/docs/reference/interfaces/ToolResultPart.md b/docs/reference/interfaces/ToolResultPart.md index 35204171..4f5d98cf 100644 --- a/docs/reference/interfaces/ToolResultPart.md +++ b/docs/reference/interfaces/ToolResultPart.md @@ -5,7 +5,7 @@ title: ToolResultPart # Interface: ToolResultPart -Defined in: [types.ts:201](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L201) +Defined in: [types.ts:204](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L204) ## Properties @@ -15,7 +15,7 @@ Defined in: [types.ts:201](https://github.com/TanStack/ai/blob/main/packages/typ content: string; ``` -Defined in: [types.ts:204](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L204) +Defined in: [types.ts:207](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L207) *** @@ -25,7 +25,7 @@ Defined in: [types.ts:204](https://github.com/TanStack/ai/blob/main/packages/typ optional error: string; ``` -Defined in: [types.ts:206](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L206) +Defined in: [types.ts:209](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L209) *** @@ -35,7 +35,7 @@ Defined in: [types.ts:206](https://github.com/TanStack/ai/blob/main/packages/typ state: ToolResultState; ``` -Defined in: [types.ts:205](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L205) +Defined in: [types.ts:208](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L208) *** @@ -45,7 +45,7 @@ Defined in: [types.ts:205](https://github.com/TanStack/ai/blob/main/packages/typ toolCallId: string; ``` -Defined in: [types.ts:203](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L203) +Defined in: [types.ts:206](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L206) *** @@ -55,4 +55,4 @@ Defined in: [types.ts:203](https://github.com/TanStack/ai/blob/main/packages/typ type: "tool-result"; ``` -Defined in: [types.ts:202](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L202) +Defined in: [types.ts:205](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L205) diff --git a/docs/reference/interfaces/ToolResultStreamChunk.md b/docs/reference/interfaces/ToolResultStreamChunk.md index c6911e59..8d2ef80e 100644 --- a/docs/reference/interfaces/ToolResultStreamChunk.md +++ b/docs/reference/interfaces/ToolResultStreamChunk.md @@ -5,7 +5,7 @@ title: ToolResultStreamChunk # Interface: ToolResultStreamChunk -Defined in: [types.ts:549](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L549) +Defined in: [types.ts:589](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L589) ## Extends @@ -19,7 +19,7 @@ Defined in: [types.ts:549](https://github.com/TanStack/ai/blob/main/packages/typ content: string; ``` -Defined in: [types.ts:552](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L552) +Defined in: [types.ts:592](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L592) *** @@ -29,7 +29,7 @@ Defined in: [types.ts:552](https://github.com/TanStack/ai/blob/main/packages/typ id: string; ``` -Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L524) +Defined in: [types.ts:564](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L564) #### Inherited from @@ -43,7 +43,7 @@ Defined in: [types.ts:524](https://github.com/TanStack/ai/blob/main/packages/typ model: string; ``` -Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L525) +Defined in: [types.ts:565](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L565) #### Inherited from @@ -57,7 +57,7 @@ Defined in: [types.ts:525](https://github.com/TanStack/ai/blob/main/packages/typ timestamp: number; ``` -Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L526) +Defined in: [types.ts:566](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L566) #### Inherited from @@ -71,7 +71,7 @@ Defined in: [types.ts:526](https://github.com/TanStack/ai/blob/main/packages/typ toolCallId: string; ``` -Defined in: [types.ts:551](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L551) +Defined in: [types.ts:591](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L591) *** @@ -81,7 +81,7 @@ Defined in: [types.ts:551](https://github.com/TanStack/ai/blob/main/packages/typ type: "tool_result"; ``` -Defined in: [types.ts:550](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L550) +Defined in: [types.ts:590](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L590) #### Overrides diff --git a/docs/reference/interfaces/UIMessage.md b/docs/reference/interfaces/UIMessage.md index 8bbe7522..3a061ea2 100644 --- a/docs/reference/interfaces/UIMessage.md +++ b/docs/reference/interfaces/UIMessage.md @@ -5,7 +5,7 @@ title: UIMessage # Interface: UIMessage -Defined in: [types.ts:224](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L224) +Defined in: [types.ts:227](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L227) UIMessage - Domain-specific message format optimized for building chat UIs Contains parts that can be text, tool calls, or tool results @@ -18,7 +18,7 @@ Contains parts that can be text, tool calls, or tool results optional createdAt: Date; ``` -Defined in: [types.ts:228](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L228) +Defined in: [types.ts:231](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L231) *** @@ -28,7 +28,7 @@ Defined in: [types.ts:228](https://github.com/TanStack/ai/blob/main/packages/typ id: string; ``` -Defined in: [types.ts:225](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L225) +Defined in: [types.ts:228](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L228) *** @@ -38,7 +38,7 @@ Defined in: [types.ts:225](https://github.com/TanStack/ai/blob/main/packages/typ parts: MessagePart[]; ``` -Defined in: [types.ts:227](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L227) +Defined in: [types.ts:230](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L230) *** @@ -48,4 +48,4 @@ Defined in: [types.ts:227](https://github.com/TanStack/ai/blob/main/packages/typ role: "user" | "assistant" | "system"; ``` -Defined in: [types.ts:226](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L226) +Defined in: [types.ts:229](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L229) diff --git a/docs/reference/interfaces/VideoPart.md b/docs/reference/interfaces/VideoPart.md index 8768b04d..8d82e667 100644 --- a/docs/reference/interfaces/VideoPart.md +++ b/docs/reference/interfaces/VideoPart.md @@ -5,7 +5,7 @@ title: VideoPart # Interface: VideoPart\ -Defined in: [types.ts:75](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L75) +Defined in: [types.ts:78](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L78) Video content part for multimodal messages. @@ -25,7 +25,7 @@ Provider-specific metadata type optional metadata: TMetadata; ``` -Defined in: [types.ts:80](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L80) +Defined in: [types.ts:83](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L83) Provider-specific metadata (e.g., duration, resolution) @@ -37,7 +37,7 @@ Provider-specific metadata (e.g., duration, resolution) source: ContentPartSource; ``` -Defined in: [types.ts:78](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L78) +Defined in: [types.ts:81](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L81) Source of the video content @@ -49,4 +49,4 @@ Source of the video content type: "video"; ``` -Defined in: [types.ts:76](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L76) +Defined in: [types.ts:79](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L79) diff --git a/docs/reference/type-aliases/AgentLoopStrategy.md b/docs/reference/type-aliases/AgentLoopStrategy.md index c16fe5be..d592cf6c 100644 --- a/docs/reference/type-aliases/AgentLoopStrategy.md +++ b/docs/reference/type-aliases/AgentLoopStrategy.md @@ -9,7 +9,7 @@ title: AgentLoopStrategy type AgentLoopStrategy = (state) => boolean; ``` -Defined in: [types.ts:471](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L471) +Defined in: [types.ts:511](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L511) Strategy function that determines whether the agent loop should continue diff --git a/docs/reference/type-aliases/AnyClientTool.md b/docs/reference/type-aliases/AnyClientTool.md index 4f395412..939784ed 100644 --- a/docs/reference/type-aliases/AnyClientTool.md +++ b/docs/reference/type-aliases/AnyClientTool.md @@ -11,6 +11,6 @@ type AnyClientTool = | ToolDefinitionInstance; ``` -Defined in: [tools/tool-definition.ts:49](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L49) +Defined in: [tools/tool-definition.ts:54](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L54) Union type for any kind of client-side tool (client tool or definition) diff --git a/docs/reference/type-aliases/ChatStreamOptionsForModel.md b/docs/reference/type-aliases/ChatStreamOptionsForModel.md index 48bad9c2..917f5c79 100644 --- a/docs/reference/type-aliases/ChatStreamOptionsForModel.md +++ b/docs/reference/type-aliases/ChatStreamOptionsForModel.md @@ -9,7 +9,7 @@ title: ChatStreamOptionsForModel type ChatStreamOptionsForModel = TAdapter extends AIAdapter ? Omit & object : never; ``` -Defined in: [types.ts:811](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L811) +Defined in: [types.ts:851](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L851) Chat options constrained by a specific model's capabilities. Unlike ChatStreamOptionsUnion which creates a union over all models, diff --git a/docs/reference/type-aliases/ChatStreamOptionsUnion.md b/docs/reference/type-aliases/ChatStreamOptionsUnion.md index e35ec3cd..beb92c2e 100644 --- a/docs/reference/type-aliases/ChatStreamOptionsUnion.md +++ b/docs/reference/type-aliases/ChatStreamOptionsUnion.md @@ -9,7 +9,7 @@ title: ChatStreamOptionsUnion type ChatStreamOptionsUnion = TAdapter extends AIAdapter ? Models[number] extends infer TModel ? TModel extends string ? Omit & object : never : never : never; ``` -Defined in: [types.ts:751](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L751) +Defined in: [types.ts:791](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L791) ## Type Parameters diff --git a/docs/reference/type-aliases/ConstrainedContent.md b/docs/reference/type-aliases/ConstrainedContent.md index 781ee84d..47d3fa8b 100644 --- a/docs/reference/type-aliases/ConstrainedContent.md +++ b/docs/reference/type-aliases/ConstrainedContent.md @@ -12,7 +12,7 @@ type ConstrainedContent, TImageMeta, TAudioMeta, TVideoMeta, TDocumentMeta, TTextMeta>[]; ``` -Defined in: [types.ts:142](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L142) +Defined in: [types.ts:145](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L145) Type for message content constrained by supported modalities. When modalities is ['text', 'image'], only TextPart and ImagePart are allowed in the array. diff --git a/docs/reference/type-aliases/ConstrainedModelMessage.md b/docs/reference/type-aliases/ConstrainedModelMessage.md index c67448d9..a16fc08a 100644 --- a/docs/reference/type-aliases/ConstrainedModelMessage.md +++ b/docs/reference/type-aliases/ConstrainedModelMessage.md @@ -9,7 +9,7 @@ title: ConstrainedModelMessage type ConstrainedModelMessage = Omit & object; ``` -Defined in: [types.ts:234](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L234) +Defined in: [types.ts:237](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L237) A ModelMessage with content constrained to only allow content parts matching the specified input modalities. diff --git a/docs/reference/type-aliases/ContentPart.md b/docs/reference/type-aliases/ContentPart.md index 9ebc9aa4..d87094b2 100644 --- a/docs/reference/type-aliases/ContentPart.md +++ b/docs/reference/type-aliases/ContentPart.md @@ -14,7 +14,7 @@ type ContentPart = | DocumentPart; ``` -Defined in: [types.ts:102](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L102) +Defined in: [types.ts:105](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L105) Union type for all multimodal content parts. diff --git a/docs/reference/type-aliases/ContentPartForModalities.md b/docs/reference/type-aliases/ContentPartForModalities.md index 648c53f5..ae2b5cf3 100644 --- a/docs/reference/type-aliases/ContentPartForModalities.md +++ b/docs/reference/type-aliases/ContentPartForModalities.md @@ -11,7 +11,7 @@ type ContentPartForModalities; ``` -Defined in: [types.ts:119](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L119) +Defined in: [types.ts:122](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L122) Helper type to filter ContentPart union to only include specific modalities. Used to constrain message content based on model capabilities. diff --git a/docs/reference/type-aliases/ExtractModalitiesForModel.md b/docs/reference/type-aliases/ExtractModalitiesForModel.md index fe6e500e..9dbbab75 100644 --- a/docs/reference/type-aliases/ExtractModalitiesForModel.md +++ b/docs/reference/type-aliases/ExtractModalitiesForModel.md @@ -9,7 +9,7 @@ title: ExtractModalitiesForModel type ExtractModalitiesForModel = TAdapter extends AIAdapter ? TModel extends keyof ModelInputModalities ? ModelInputModalities[TModel] : ReadonlyArray : ReadonlyArray; ``` -Defined in: [types.ts:870](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L870) +Defined in: [types.ts:910](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L910) Extract the supported input modalities for a specific model from an adapter. diff --git a/docs/reference/type-aliases/ExtractModelsFromAdapter.md b/docs/reference/type-aliases/ExtractModelsFromAdapter.md index a35e672f..c5940782 100644 --- a/docs/reference/type-aliases/ExtractModelsFromAdapter.md +++ b/docs/reference/type-aliases/ExtractModelsFromAdapter.md @@ -9,7 +9,7 @@ title: ExtractModelsFromAdapter type ExtractModelsFromAdapter = T extends AIAdapter ? M[number] : never; ``` -Defined in: [types.ts:864](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L864) +Defined in: [types.ts:904](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L904) ## Type Parameters diff --git a/docs/reference/type-aliases/InferToolInput.md b/docs/reference/type-aliases/InferToolInput.md index 0a3cc815..4efb5109 100644 --- a/docs/reference/type-aliases/InferToolInput.md +++ b/docs/reference/type-aliases/InferToolInput.md @@ -6,12 +6,12 @@ title: InferToolInput # Type Alias: InferToolInput\ ```ts -type InferToolInput = T extends object ? TInput extends z.ZodType ? z.infer : any : any; +type InferToolInput = T extends object ? TInput extends StandardSchemaV1 ? InferOutput : any : any; ``` -Defined in: [tools/tool-definition.ts:61](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L61) +Defined in: [tools/tool-definition.ts:66](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L66) -Extract the input type from a tool (inferred from Zod schema) +Extract the input type from a tool (inferred from Standard Schema) ## Type Parameters diff --git a/docs/reference/type-aliases/InferToolName.md b/docs/reference/type-aliases/InferToolName.md index 25b0aa93..7c2486ef 100644 --- a/docs/reference/type-aliases/InferToolName.md +++ b/docs/reference/type-aliases/InferToolName.md @@ -9,7 +9,7 @@ title: InferToolName type InferToolName = T extends object ? N : never; ``` -Defined in: [tools/tool-definition.ts:56](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L56) +Defined in: [tools/tool-definition.ts:61](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L61) Extract the tool name as a literal type diff --git a/docs/reference/type-aliases/InferToolOutput.md b/docs/reference/type-aliases/InferToolOutput.md index f88a7393..8b985f09 100644 --- a/docs/reference/type-aliases/InferToolOutput.md +++ b/docs/reference/type-aliases/InferToolOutput.md @@ -6,12 +6,12 @@ title: InferToolOutput # Type Alias: InferToolOutput\ ```ts -type InferToolOutput = T extends object ? TOutput extends z.ZodType ? z.infer : any : any; +type InferToolOutput = T extends object ? TOutput extends StandardSchemaV1 ? InferOutput : any : any; ``` -Defined in: [tools/tool-definition.ts:70](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L70) +Defined in: [tools/tool-definition.ts:75](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L75) -Extract the output type from a tool (inferred from Zod schema) +Extract the output type from a tool (inferred from Standard Schema) ## Type Parameters diff --git a/docs/reference/type-aliases/MessagePart.md b/docs/reference/type-aliases/MessagePart.md index ab63fa58..15b70a70 100644 --- a/docs/reference/type-aliases/MessagePart.md +++ b/docs/reference/type-aliases/MessagePart.md @@ -13,4 +13,4 @@ type MessagePart = | ThinkingPart; ``` -Defined in: [types.ts:214](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L214) +Defined in: [types.ts:217](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L217) diff --git a/docs/reference/type-aliases/ModalitiesArrayToUnion.md b/docs/reference/type-aliases/ModalitiesArrayToUnion.md index 6190668d..53aca007 100644 --- a/docs/reference/type-aliases/ModalitiesArrayToUnion.md +++ b/docs/reference/type-aliases/ModalitiesArrayToUnion.md @@ -9,7 +9,7 @@ title: ModalitiesArrayToUnion type ModalitiesArrayToUnion = T[number]; ``` -Defined in: [types.ts:135](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L135) +Defined in: [types.ts:138](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L138) Helper type to convert a readonly array of modalities to a union type. e.g., readonly ['text', 'image'] -> 'text' | 'image' diff --git a/docs/reference/type-aliases/Modality.md b/docs/reference/type-aliases/Modality.md index 8c8e527e..44d5c351 100644 --- a/docs/reference/type-aliases/Modality.md +++ b/docs/reference/type-aliases/Modality.md @@ -9,7 +9,7 @@ title: Modality type Modality = "text" | "image" | "audio" | "video" | "document"; ``` -Defined in: [types.ts:26](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L26) +Defined in: [types.ts:29](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L29) Supported input modality types for multimodal content. - 'text': Plain text content diff --git a/docs/reference/type-aliases/StreamChunk.md b/docs/reference/type-aliases/StreamChunk.md index e809e93d..67dfdf01 100644 --- a/docs/reference/type-aliases/StreamChunk.md +++ b/docs/reference/type-aliases/StreamChunk.md @@ -17,6 +17,6 @@ type StreamChunk = | ThinkingStreamChunk; ``` -Defined in: [types.ts:600](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L600) +Defined in: [types.ts:640](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L640) Chunk returned by the sdk during streaming chat completions. diff --git a/docs/reference/type-aliases/StreamChunkType.md b/docs/reference/type-aliases/StreamChunkType.md index 0587e96a..f3afb4b2 100644 --- a/docs/reference/type-aliases/StreamChunkType.md +++ b/docs/reference/type-aliases/StreamChunkType.md @@ -17,4 +17,4 @@ type StreamChunkType = | "thinking"; ``` -Defined in: [types.ts:512](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L512) +Defined in: [types.ts:552](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L552) diff --git a/examples/ts-react-chat/src/lib/guitar-tools.ts b/examples/ts-react-chat/src/lib/guitar-tools.ts index cbff42ee..4941465f 100644 --- a/examples/ts-react-chat/src/lib/guitar-tools.ts +++ b/examples/ts-react-chat/src/lib/guitar-tools.ts @@ -1,4 +1,5 @@ import { toolDefinition } from '@tanstack/ai' +import { convertZodToJsonSchema } from '@tanstack/ai/zod' import { z } from 'zod' import guitars from '@/data/example-guitars' @@ -7,6 +8,7 @@ export const getGuitarsToolDef = toolDefinition({ name: 'getGuitars', description: 'Get all products from the database', inputSchema: z.object({}), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.array( z.object({ id: z.number(), @@ -34,6 +36,7 @@ export const recommendGuitarToolDef = toolDefinition({ 'The ID of the guitar to recommend (from the getGuitars results)', ), }), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ id: z.number(), }), @@ -45,6 +48,7 @@ export const getPersonalGuitarPreferenceToolDef = toolDefinition({ description: "Get the user's guitar preference from their local browser storage", inputSchema: z.object({}), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ preference: z.string(), }), @@ -57,6 +61,7 @@ export const addToWishListToolDef = toolDefinition({ inputSchema: z.object({ guitarId: z.string(), }), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ success: z.boolean(), guitarId: z.string(), @@ -73,6 +78,7 @@ export const addToCartToolDef = toolDefinition({ guitarId: z.string(), quantity: z.number(), }), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ success: z.boolean(), cartId: z.string(), diff --git a/examples/ts-solid-chat/src/lib/guitar-tools.ts b/examples/ts-solid-chat/src/lib/guitar-tools.ts index b5536079..4385e205 100644 --- a/examples/ts-solid-chat/src/lib/guitar-tools.ts +++ b/examples/ts-solid-chat/src/lib/guitar-tools.ts @@ -1,4 +1,5 @@ import { toolDefinition } from '@tanstack/ai' +import { convertZodToJsonSchema } from '@tanstack/ai/zod' import { clientTools as createClientTools } from '@tanstack/ai-client' import { z } from 'zod' import guitars from '@/data/example-guitars' @@ -8,6 +9,7 @@ export const getGuitarsToolDef = toolDefinition({ name: 'getGuitars', description: 'Get all products from the database', inputSchema: z.object({}), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.array( z.object({ id: z.number(), @@ -28,6 +30,7 @@ export const recommendGuitarTool = toolDefinition({ name: 'recommendGuitar', description: 'REQUIRED tool to display a guitar recommendation to the user. This tool MUST be used whenever recommending a guitar - do NOT write recommendations yourself. This displays the guitar in a special appealing format with a buy button.', + toJsonSchema: convertZodToJsonSchema, inputSchema: z.object({ id: z .string() @@ -52,6 +55,7 @@ export const getPersonalGuitarPreferenceTool = toolDefinition({ description: "Get the user's guitar preference from their local browser storage", inputSchema: z.object({}), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ preference: z.string(), }), @@ -69,6 +73,7 @@ export const addToWishListTool = toolDefinition({ inputSchema: z.object({ guitarId: z.string(), }), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ success: z.boolean(), guitarId: z.string(), @@ -96,6 +101,7 @@ export const addToCartTool = toolDefinition({ guitarId: z.string(), quantity: z.number(), }), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ success: z.boolean(), cartId: z.string(), diff --git a/examples/ts-vue-chat/src/lib/guitar-tools.ts b/examples/ts-vue-chat/src/lib/guitar-tools.ts index fa3abe72..f1d54b95 100644 --- a/examples/ts-vue-chat/src/lib/guitar-tools.ts +++ b/examples/ts-vue-chat/src/lib/guitar-tools.ts @@ -1,4 +1,5 @@ import { toolDefinition } from '@tanstack/ai' +import { convertZodToJsonSchema } from '@tanstack/ai/zod' import { z } from 'zod' // Tool definition for getting guitars @@ -6,6 +7,7 @@ export const getGuitarsToolDef = toolDefinition({ name: 'getGuitars', description: 'Get all products from the database', inputSchema: z.object({}), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.array( z.object({ id: z.number(), @@ -30,6 +32,7 @@ export const recommendGuitarToolDef = toolDefinition({ 'The ID of the guitar to recommend (from the getGuitars results)', ), }), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ id: z.number(), }), @@ -41,6 +44,7 @@ export const getPersonalGuitarPreferenceToolDef = toolDefinition({ description: "Get the user's guitar preference from their local browser storage", inputSchema: z.object({}), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ preference: z.string(), }), @@ -53,6 +57,7 @@ export const addToWishListToolDef = toolDefinition({ inputSchema: z.object({ guitarId: z.string(), }), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ success: z.boolean(), guitarId: z.string(), @@ -69,6 +74,7 @@ export const addToCartToolDef = toolDefinition({ guitarId: z.string(), quantity: z.number(), }), + toJsonSchema: convertZodToJsonSchema, outputSchema: z.object({ success: z.boolean(), cartId: z.string(), diff --git a/knip.json b/knip.json index 8f2913dc..984974ea 100644 --- a/knip.json +++ b/knip.json @@ -2,6 +2,9 @@ "$schema": "https://unpkg.com/knip@5/schema.json", "ignoreDependencies": ["@faker-js/faker"], "ignoreWorkspaces": ["examples/**", "testing/**", "**/smoke-tests/**"], + "ignoreIssues": { + "packages/typescript/ai/package.json": ["optionalPeerDependencies"] + }, "ignore": [ "packages/typescript/ai-openai/live-tests/**", "packages/typescript/ai-openai/src/**/*.test.ts", diff --git a/packages/typescript/ai-anthropic/src/tools/custom-tool.ts b/packages/typescript/ai-anthropic/src/tools/custom-tool.ts index 07ac10a3..a102d2a7 100644 --- a/packages/typescript/ai-anthropic/src/tools/custom-tool.ts +++ b/packages/typescript/ai-anthropic/src/tools/custom-tool.ts @@ -1,6 +1,4 @@ -import { convertZodToJsonSchema } from '@tanstack/ai' -import type { Tool } from '@tanstack/ai' -import type { z } from 'zod' +import type { StandardSchemaV1, Tool } from '@tanstack/ai' import type { CacheControl } from '../text/text-provider-options' export interface CustomTool { @@ -29,8 +27,11 @@ export function convertCustomToolToAdapterFormat(tool: Tool): CustomTool { const metadata = (tool.metadata as { cacheControl?: CacheControl | null } | undefined) || {} - // Convert Zod schema to JSON Schema - const jsonSchema = convertZodToJsonSchema(tool.inputSchema) + // Get JSON Schema from tool's converter function + const jsonSchema = + tool.inputSchema && tool.toJsonSchema + ? tool.toJsonSchema(tool.inputSchema) + : undefined const inputSchema = { type: 'object' as const, @@ -50,7 +51,7 @@ export function convertCustomToolToAdapterFormat(tool: Tool): CustomTool { export function customTool( name: string, description: string, - inputSchema: z.ZodType, + inputSchema: StandardSchemaV1, cacheControl?: CacheControl | null, ): Tool { return { diff --git a/packages/typescript/ai-gemini/src/tools/tool-converter.ts b/packages/typescript/ai-gemini/src/tools/tool-converter.ts index f0a239ca..f66a6874 100644 --- a/packages/typescript/ai-gemini/src/tools/tool-converter.ts +++ b/packages/typescript/ai-gemini/src/tools/tool-converter.ts @@ -1,4 +1,3 @@ -import { convertZodToJsonSchema } from '@tanstack/ai' import { convertCodeExecutionToolToAdapterFormat } from './code-execution-tool' import { convertComputerUseToolToAdapterFormat } from './computer-use-tool' import { convertFileSearchToolToAdapterFormat } from './file-search-tool' @@ -76,8 +75,11 @@ export function convertToolsToProviderFormat( ) } - // Convert Zod schema to JSON Schema - const jsonSchema = convertZodToJsonSchema(tool.inputSchema) + // Get JSON Schema from tool's converter function + const jsonSchema = + tool.inputSchema && tool.toJsonSchema + ? tool.toJsonSchema(tool.inputSchema) + : undefined functionDeclarations.push({ name: tool.name, diff --git a/packages/typescript/ai-ollama/src/ollama-adapter.ts b/packages/typescript/ai-ollama/src/ollama-adapter.ts index fc6080c0..3b1d6ba8 100644 --- a/packages/typescript/ai-ollama/src/ollama-adapter.ts +++ b/packages/typescript/ai-ollama/src/ollama-adapter.ts @@ -1,5 +1,5 @@ import { Ollama as OllamaSDK } from 'ollama' -import { BaseAdapter, convertZodToJsonSchema } from '@tanstack/ai' +import { BaseAdapter } from '@tanstack/ai' import type { AbortableAsyncIterator, ChatRequest, @@ -373,7 +373,10 @@ export class Ollama extends BaseAdapter< function: { name: tool.name, description: tool.description, - parameters: convertZodToJsonSchema(tool.inputSchema), + parameters: + tool.inputSchema && tool.toJsonSchema + ? tool.toJsonSchema(tool.inputSchema) + : undefined, }, })) } diff --git a/packages/typescript/ai-openai/src/tools/function-tool.ts b/packages/typescript/ai-openai/src/tools/function-tool.ts index 60737b4c..98672f79 100644 --- a/packages/typescript/ai-openai/src/tools/function-tool.ts +++ b/packages/typescript/ai-openai/src/tools/function-tool.ts @@ -1,4 +1,3 @@ -import { convertZodToJsonSchema } from '@tanstack/ai' import type { Tool } from '@tanstack/ai' import type OpenAI from 'openai' @@ -8,10 +7,11 @@ export type FunctionTool = OpenAI.Responses.FunctionTool * Converts a standard Tool to OpenAI FunctionTool format */ export function convertFunctionToolToAdapterFormat(tool: Tool): FunctionTool { - // Convert Zod schema to JSON Schema - const jsonSchema = tool.inputSchema - ? convertZodToJsonSchema(tool.inputSchema) - : undefined + // Get JSON Schema from tool's converter function + const jsonSchema = + tool.inputSchema && tool.toJsonSchema + ? tool.toJsonSchema(tool.inputSchema) + : undefined // Determine if we can use strict mode // Strict mode requires all properties to be in the required array diff --git a/packages/typescript/ai/package.json b/packages/typescript/ai/package.json index 1a532e5e..86efa7b8 100644 --- a/packages/typescript/ai/package.json +++ b/packages/typescript/ai/package.json @@ -20,6 +20,10 @@ "./event-client": { "types": "./dist/esm/event-client.d.ts", "import": "./dist/esm/event-client.js" + }, + "./zod": { + "types": "./dist/esm/tools/zod-converter.d.ts", + "import": "./dist/esm/tools/zod-converter.js" } }, "sideEffects": false, @@ -51,15 +55,19 @@ "embeddings" ], "dependencies": { + "@standard-schema/spec": "^1.0.0", "@tanstack/devtools-event-client": "^0.3.5", "partial-json": "^0.1.7" }, "peerDependencies": { - "@alcyone-labs/zod-to-json-schema": "^4.0.0", "zod": "^3.0.0 || ^4.0.0" }, + "peerDependenciesMeta": { + "zod": { + "optional": true + } + }, "devDependencies": { - "@vitest/coverage-v8": "4.0.14", - "zod": "^4.1.13" + "@vitest/coverage-v8": "4.0.14" } } diff --git a/packages/typescript/ai/src/index.ts b/packages/typescript/ai/src/index.ts index b91778c4..51764304 100644 --- a/packages/typescript/ai/src/index.ts +++ b/packages/typescript/ai/src/index.ts @@ -13,7 +13,6 @@ export { type InferToolInput, type InferToolOutput, } from './tools/tool-definition' -export { convertZodToJsonSchema } from './tools/zod-converter' export { toServerSentEventsStream, toStreamResponse, diff --git a/packages/typescript/ai/src/tools/tool-calls.ts b/packages/typescript/ai/src/tools/tool-calls.ts index 4329f6dc..849150b6 100644 --- a/packages/typescript/ai/src/tools/tool-calls.ts +++ b/packages/typescript/ai/src/tools/tool-calls.ts @@ -1,3 +1,4 @@ +import type { StandardSchemaV1 } from '@standard-schema/spec' import type { DoneStreamChunk, ModelMessage, @@ -6,6 +7,44 @@ import type { ToolResultStreamChunk, } from '../types' +/** + * Validate a value against a Standard Schema. + * Returns the validated/transformed value on success, throws on failure. + */ +async function validateSchema( + schema: T, + value: unknown, +): Promise> { + const result = await schema['~standard'].validate(value) + if (result.issues) { + const message = result.issues.map((issue) => issue.message).join('; ') + throw new Error(message) + } + return result.value as StandardSchemaV1.InferOutput +} + +/** + * Validate a value against a Standard Schema safely. + * Returns { success: true, data } on success, { success: false, error } on failure. + */ +async function safeValidateSchema( + schema: T, + value: unknown, +): Promise< + | { success: true; data: StandardSchemaV1.InferOutput } + | { success: false; error: { message: string } } +> { + const result = await schema['~standard'].validate(value) + if (result.issues) { + const message = result.issues.map((issue) => issue.message).join('; ') + return { success: false, error: { message } } + } + return { + success: true, + data: result.value as StandardSchemaV1.InferOutput, + } +} + /** * Manages tool call accumulation and execution for the chat() method's automatic tool execution loop. * @@ -133,7 +172,7 @@ export class ToolCallManager { // Validate input against inputSchema if (tool.inputSchema) { try { - args = tool.inputSchema.parse(args) + args = await validateSchema(tool.inputSchema, args) } catch (validationError: any) { throw new Error( `Input validation failed for tool ${tool.name}: ${validationError.message}`, @@ -147,7 +186,7 @@ export class ToolCallManager { // Validate output against outputSchema if provided if (tool.outputSchema && result !== undefined && result !== null) { try { - result = tool.outputSchema.parse(result) + result = await validateSchema(tool.outputSchema, result) } catch (validationError: any) { throw new Error( `Output validation failed for tool ${tool.name}: ${validationError.message}`, @@ -285,7 +324,7 @@ export async function executeToolCalls( // Validate input against inputSchema if (tool.inputSchema) { try { - input = tool.inputSchema.parse(input) + input = await validateSchema(tool.inputSchema, input) } catch (validationError: any) { results.push({ toolCallId: toolCall.id, @@ -380,7 +419,7 @@ export async function executeToolCalls( // Validate output against outputSchema if provided if (tool.outputSchema && result !== undefined && result !== null) { - const parsed = tool.outputSchema.safeParse(result) + const parsed = await safeValidateSchema(tool.outputSchema, result) if (parsed.success) { result = parsed.data } else { @@ -438,7 +477,7 @@ export async function executeToolCalls( // Validate output against outputSchema if provided if (tool.outputSchema && result !== undefined && result !== null) { - const parsed = tool.outputSchema.safeParse(result) + const parsed = await safeValidateSchema(tool.outputSchema, result) if (parsed.success) { result = parsed.data } else { diff --git a/packages/typescript/ai/src/tools/tool-definition.ts b/packages/typescript/ai/src/tools/tool-definition.ts index 83685f0d..0c8cac82 100644 --- a/packages/typescript/ai/src/tools/tool-definition.ts +++ b/packages/typescript/ai/src/tools/tool-definition.ts @@ -1,12 +1,17 @@ -import type { z } from 'zod' +import type { StandardSchemaV1 } from '@standard-schema/spec' import type { Tool } from '../types' +/** + * Infer the output type from a Standard Schema + */ +type InferOutput = T extends StandardSchemaV1 ? O : never + /** * Marker type for server-side tools */ export interface ServerTool< - TInput extends z.ZodType = z.ZodType, - TOutput extends z.ZodType = z.ZodType, + TInput extends StandardSchemaV1 = StandardSchemaV1, + TOutput extends StandardSchemaV1 = StandardSchemaV1, TName extends string = string, > extends Tool { __toolSide: 'server' @@ -16,8 +21,8 @@ export interface ServerTool< * Marker type for client-side tools */ export interface ClientTool< - TInput extends z.ZodType = z.ZodType, - TOutput extends z.ZodType = z.ZodType, + TInput extends StandardSchemaV1 = StandardSchemaV1, + TOutput extends StandardSchemaV1 = StandardSchemaV1, TName extends string = string, > { __toolSide: 'client' @@ -28,16 +33,16 @@ export interface ClientTool< needsApproval?: boolean metadata?: Record execute?: ( - args: z.infer, - ) => Promise> | z.infer + args: InferOutput, + ) => Promise> | InferOutput } /** * Tool definition that can be used directly or instantiated for server/client */ export interface ToolDefinitionInstance< - TInput extends z.ZodType = z.ZodType, - TOutput extends z.ZodType = z.ZodType, + TInput extends StandardSchemaV1 = StandardSchemaV1, + TOutput extends StandardSchemaV1 = StandardSchemaV1, TName extends string = string, > extends Tool { __toolSide: 'definition' @@ -56,20 +61,20 @@ export type AnyClientTool = export type InferToolName = T extends { name: infer N } ? N : never /** - * Extract the input type from a tool (inferred from Zod schema) + * Extract the input type from a tool (inferred from Standard Schema) */ export type InferToolInput = T extends { inputSchema?: infer TInput } - ? TInput extends z.ZodType - ? z.infer + ? TInput extends StandardSchemaV1 + ? InferOutput : any : any /** - * Extract the output type from a tool (inferred from Zod schema) + * Extract the output type from a tool (inferred from Standard Schema) */ export type InferToolOutput = T extends { outputSchema?: infer TOutput } - ? TOutput extends z.ZodType - ? z.infer + ? TOutput extends StandardSchemaV1 + ? InferOutput : any : any @@ -77,14 +82,17 @@ export type InferToolOutput = T extends { outputSchema?: infer TOutput } * Tool definition configuration */ export interface ToolDefinitionConfig< - TInput extends z.ZodType = z.ZodType, - TOutput extends z.ZodType = z.ZodType, + TInput extends StandardSchemaV1 = StandardSchemaV1, + TOutput extends StandardSchemaV1 = StandardSchemaV1, TName extends string = string, > { name: TName description: string inputSchema?: TInput outputSchema?: TOutput + toJsonSchema?: ( + inputSchema: StandardSchemaV1, + ) => Record | undefined needsApproval?: boolean metadata?: Record } @@ -93,8 +101,8 @@ export interface ToolDefinitionConfig< * Tool definition builder that allows creating server or client tools from a shared definition */ export interface ToolDefinition< - TInput extends z.ZodType = z.ZodType, - TOutput extends z.ZodType = z.ZodType, + TInput extends StandardSchemaV1 = StandardSchemaV1, + TOutput extends StandardSchemaV1 = StandardSchemaV1, TName extends string = string, > extends ToolDefinitionInstance { /** @@ -102,8 +110,8 @@ export interface ToolDefinition< */ server: ( execute: ( - args: z.infer, - ) => Promise> | z.infer, + args: InferOutput, + ) => Promise> | InferOutput, ) => ServerTool /** @@ -111,8 +119,8 @@ export interface ToolDefinition< */ client: ( execute?: ( - args: z.infer, - ) => Promise> | z.infer, + args: InferOutput, + ) => Promise> | InferOutput, ) => ClientTool } @@ -124,11 +132,14 @@ export interface ToolDefinition< * 2. Instantiated as a server tool with .server() * 3. Instantiated as a client tool with .client() * + * This function supports any Standard Schema compliant library (Zod, Valibot, ArkType, etc.) + * * @example * ```typescript * import { toolDefinition } from '@tanstack/ai'; * import { z } from 'zod'; * + * // Using Zod (Standard Schema compliant) * const addToCartTool = toolDefinition({ * name: 'addToCart', * description: 'Add a guitar to the shopping cart (requires approval)', @@ -144,6 +155,18 @@ export interface ToolDefinition< * }), * }); * + * // Using Valibot (Standard Schema compliant) + * import * as v from 'valibot'; + * + * const searchTool = toolDefinition({ + * name: 'search', + * description: 'Search the database', + * inputSchema: v.object({ + * query: v.string(), + * limit: v.optional(v.number()), + * }), + * }); + * * // Use directly in chat (server-side, no execute function) * chat({ * tools: [addToCartTool], @@ -168,8 +191,8 @@ export interface ToolDefinition< * ``` */ export function toolDefinition< - TInput extends z.ZodType = z.ZodAny, - TOutput extends z.ZodType = z.ZodAny, + TInput extends StandardSchemaV1 = StandardSchemaV1, + TOutput extends StandardSchemaV1 = StandardSchemaV1, TName extends string = string, >( config: ToolDefinitionConfig, @@ -179,8 +202,8 @@ export function toolDefinition< ...config, server( execute: ( - args: z.infer, - ) => Promise> | z.infer, + args: InferOutput, + ) => Promise> | InferOutput, ): ServerTool { return { __toolSide: 'server', @@ -191,8 +214,8 @@ export function toolDefinition< client( execute?: ( - args: z.infer, - ) => Promise> | z.infer, + args: InferOutput, + ) => Promise> | InferOutput, ): ClientTool { return { __toolSide: 'client', diff --git a/packages/typescript/ai/src/tools/zod-converter.ts b/packages/typescript/ai/src/tools/zod-converter.ts index 6104a5f3..42f756d2 100644 --- a/packages/typescript/ai/src/tools/zod-converter.ts +++ b/packages/typescript/ai/src/tools/zod-converter.ts @@ -1,10 +1,13 @@ import { toJSONSchema } from 'zod' +import type { StandardSchemaV1 } from '@standard-schema/spec' import type { z } from 'zod' /** * Converts a Zod schema to JSON Schema format compatible with LLM providers. * + * Accepts StandardSchemaV1 for compatibility with the toJsonSchema callback, + * but internally expects a Zod schema. * - * @param schema - Zod schema to convert + * @param schema - Zod schema to convert (typed as StandardSchemaV1 for compatibility) * @returns JSON Schema object that can be sent to LLM providers * * @example @@ -29,12 +32,15 @@ import type { z } from 'zod' * ``` */ export function convertZodToJsonSchema( - schema: z.ZodType | undefined, + schema: StandardSchemaV1 | undefined, ): Record | undefined { if (!schema) return undefined + // Cast to z.ZodType since we know this function is only used with Zod schemas + const zodSchema = schema as z.ZodType + // Use Alcyone Labs fork which is compatible with Zod v4 - const jsonSchema = toJSONSchema(schema, { + const jsonSchema = toJSONSchema(zodSchema, { target: 'openapi-3.0', reused: 'ref', }) @@ -51,9 +57,9 @@ export function convertZodToJsonSchema( if (typeof result === 'object') { // Check if the input schema is a ZodObject by inspecting its internal structure const isZodObject = - typeof schema === 'object' && - 'def' in schema && - schema.def.type === 'object' + typeof zodSchema === 'object' && + 'def' in zodSchema && + (zodSchema as any).def.type === 'object' // If we know it's a ZodObject but result doesn't have type, set it if (isZodObject && !result.type) { diff --git a/packages/typescript/ai/src/types.ts b/packages/typescript/ai/src/types.ts index 8f96fcfe..b9bb43c3 100644 --- a/packages/typescript/ai/src/types.ts +++ b/packages/typescript/ai/src/types.ts @@ -1,7 +1,10 @@ import type { CommonOptions } from './core/chat-common-options' -import type { z } from 'zod' +import type { StandardSchemaV1 } from '@standard-schema/spec' import type { ToolCallState, ToolResultState } from './stream/types' +// Re-export StandardSchemaV1 for convenience +export type { StandardSchemaV1 } from '@standard-schema/spec' + export interface ToolCall { id: string type: 'function' @@ -255,14 +258,16 @@ export type ConstrainedModelMessage< * Tools allow the model to interact with external systems, APIs, or perform computations. * The model will decide when to call tools based on the user's request and the tool descriptions. * - * Tools use Zod schemas for runtime validation and type safety. + * Tools use Standard Schema for runtime validation and type safety, supporting any + * compliant schema library (Zod, Valibot, ArkType, etc.). * * @see https://platform.openai.com/docs/guides/function-calling * @see https://docs.anthropic.com/claude/docs/tool-use + * @see https://github.com/standard-schema/standard-schema */ export interface Tool< - TInput extends z.ZodType = z.ZodType, - TOutput extends z.ZodType = z.ZodType, + TInput extends StandardSchemaV1 = StandardSchemaV1, + TOutput extends StandardSchemaV1 = StandardSchemaV1, TName extends string = string, > { /** @@ -286,26 +291,38 @@ export interface Tool< description: string /** - * Zod schema describing the tool's input parameters. + * Standard Schema describing the tool's input parameters. * * Defines the structure and types of arguments the tool accepts. * The model will generate arguments matching this schema. * The schema is converted to JSON Schema for LLM providers. * - * @see https://zod.dev/ + * Supports any Standard Schema compliant library (Zod, Valibot, ArkType, etc.) + * + * @see https://github.com/standard-schema/standard-schema * * @example + * // Using Zod * import { z } from 'zod'; * * z.object({ * location: z.string().describe("City name or coordinates"), * unit: z.enum(["celsius", "fahrenheit"]).optional() * }) + * + * @example + * // Using Valibot + * import * as v from 'valibot'; + * + * v.object({ + * location: v.string(), + * unit: v.optional(v.picklist(["celsius", "fahrenheit"])) + * }) */ inputSchema?: TInput /** - * Optional Zod schema for validating tool output. + * Optional Standard Schema for validating tool output. * * If provided, tool results will be validated against this schema before * being sent back to the model. This catches bugs in tool implementations @@ -346,6 +363,29 @@ export interface Tool< /** Additional metadata for adapters or custom extensions */ metadata?: Record + + /** + * Optional function to convert the inputSchema to JSON Schema format. + * + * This allows tools to use any schema library (Zod, Valibot, ArkType, etc.) + * and provide their own conversion logic. Each adapter will call this function + * to get the JSON Schema representation of the tool's parameters. + * + * @param inputSchema - The Standard Schema input schema to convert + * @returns JSON Schema object describing the tool's input parameters, or undefined + * + * @example + * // With Zod + * import { toJSONSchema } from 'zod'; + * toJsonSchema: (schema) => toJSONSchema(schema) + * + * // With Valibot + * import { toJSONSchema } from '@valibot/to-json-schema'; + * toJsonSchema: (schema) => toJSONSchema(schema) + */ + toJsonSchema?: ( + inputSchema: StandardSchemaV1, + ) => Record | undefined } export interface ToolConfig { diff --git a/packages/typescript/ai/vite.config.ts b/packages/typescript/ai/vite.config.ts index c6c899af..e761a043 100644 --- a/packages/typescript/ai/vite.config.ts +++ b/packages/typescript/ai/vite.config.ts @@ -29,7 +29,11 @@ const config = defineConfig({ export default mergeConfig( config, tanstackViteConfig({ - entry: ['./src/index.ts', './src/event-client.ts'], + entry: [ + './src/index.ts', + './src/event-client.ts', + './src/tools/zod-converter.ts', + ], srcDir: './src', cjs: false, }), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c0c4a417..78007f12 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -523,22 +523,22 @@ importers: packages/typescript/ai: dependencies: - '@alcyone-labs/zod-to-json-schema': - specifier: ^4.0.0 - version: 4.0.10(zod@4.1.13) + '@standard-schema/spec': + specifier: ^1.0.0 + version: 1.0.0 '@tanstack/devtools-event-client': specifier: ^0.3.5 version: 0.3.5 partial-json: specifier: ^0.1.7 version: 0.1.7 + zod: + specifier: ^3.0.0 || ^4.0.0 + version: 4.1.13 devDependencies: '@vitest/coverage-v8': specifier: 4.0.14 version: 4.0.14(vitest@4.0.14(@types/node@24.10.1)(happy-dom@20.0.10)(jiti@2.6.1)(jsdom@27.2.0(postcss@8.5.6))(lightningcss@1.30.2)(terser@5.44.0)(tsx@4.20.6)(yaml@2.8.1)) - zod: - specifier: ^4.1.13 - version: 4.1.13 packages/typescript/ai-anthropic: dependencies: