diff --git a/.changeset/fix-reasoning-streaming-ag-ui.md b/.changeset/fix-reasoning-streaming-ag-ui.md new file mode 100644 index 00000000..592bb3f1 --- /dev/null +++ b/.changeset/fix-reasoning-streaming-ag-ui.md @@ -0,0 +1,13 @@ +--- +'@tanstack/ai-openai': patch +'@tanstack/ai': patch +--- + +Fix reasoning token streaming for gpt-5-mini and gpt-5-nano models (AG-UI) + +- Added OpenAIReasoningOptions to gpt-5-mini and gpt-5-nano models +- Fixed summary option placement (inside reasoning object) +- Added handler for response.reasoning_summary_text.delta events +- Emits AG-UI STEP_STARTED/STEP_FINISHED events for reasoning summaries +- Added OpenAIReasoningOptionsWithConcise for computer-use-preview model +- Serialize tool result to string in handleToolCallEndEvent for consistent event format diff --git a/docs/adapters/openai.md b/docs/adapters/openai.md index 093d3f53..de210551 100644 --- a/docs/adapters/openai.md +++ b/docs/adapters/openai.md @@ -145,15 +145,17 @@ Enable reasoning for models that support it (e.g., GPT-5). This allows the model ```typescript providerOptions: { reasoning: { - effort: "medium", // "minimal" | "low" | "medium" | "high" + effort: "medium", // "none" | "minimal" | "low" | "medium" | "high" + summary: "detailed", // "auto" | "detailed" (optional) }, } ``` **Supported Models:** -- `gpt-5` - Supports reasoning with configurable effort +- `gpt-5.1`, `gpt-5`, `gpt-5-mini`, `gpt-5-nano` - Supports reasoning with configurable effort - `o3`, `o3-pro`, `o3-mini` - Support reasoning +- `computer-use-preview` - Supports reasoning with `summary: "concise"` option (only model that supports `concise`) When reasoning is enabled, the model's reasoning process is streamed separately from the response text and appears as a collapsible thinking section in the UI. diff --git a/docs/reference/classes/BaseAdapter.md b/docs/reference/classes/BaseAdapter.md new file mode 100644 index 00000000..1127e644 --- /dev/null +++ b/docs/reference/classes/BaseAdapter.md @@ -0,0 +1,310 @@ +--- +id: BaseAdapter +title: BaseAdapter +--- + +# Abstract Class: BaseAdapter\ + +Defined in: [base-adapter.ts:26](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L26) + +Base adapter class with support for endpoint-specific models and provider options. + +Generic parameters: +- TChatModels: Models that support chat/text completion +- TEmbeddingModels: Models that support embeddings +- TChatProviderOptions: Provider-specific options for chat endpoint +- TEmbeddingProviderOptions: Provider-specific options for embedding endpoint +- TModelProviderOptionsByName: Provider-specific options for model by name +- TModelInputModalitiesByName: Map from model name to its supported input modalities +- TMessageMetadataByModality: Map from modality type to adapter-specific metadata types + +## Type Parameters + +### TChatModels + +`TChatModels` *extends* `ReadonlyArray`\<`string`\> = `ReadonlyArray`\<`string`\> + +### TEmbeddingModels + +`TEmbeddingModels` *extends* `ReadonlyArray`\<`string`\> = `ReadonlyArray`\<`string`\> + +### TChatProviderOptions + +`TChatProviderOptions` *extends* `Record`\<`string`, `any`\> = `Record`\<`string`, `any`\> + +### TEmbeddingProviderOptions + +`TEmbeddingProviderOptions` *extends* `Record`\<`string`, `any`\> = `Record`\<`string`, `any`\> + +### TModelProviderOptionsByName + +`TModelProviderOptionsByName` *extends* `Record`\<`string`, `any`\> = `Record`\<`string`, `any`\> + +### TModelInputModalitiesByName + +`TModelInputModalitiesByName` *extends* `Record`\<`string`, `ReadonlyArray`\<[`Modality`](../type-aliases/Modality.md)\>\> = `Record`\<`string`, `ReadonlyArray`\<[`Modality`](../type-aliases/Modality.md)\>\> + +### TMessageMetadataByModality + +`TMessageMetadataByModality` *extends* `object` = [`DefaultMessageMetadataByModality`](../interfaces/DefaultMessageMetadataByModality.md) + +## Implements + +- [`AIAdapter`](../interfaces/AIAdapter.md)\<`TChatModels`, `TEmbeddingModels`, `TChatProviderOptions`, `TEmbeddingProviderOptions`, `TModelProviderOptionsByName`, `TModelInputModalitiesByName`, `TMessageMetadataByModality`\> + +## Constructors + +### Constructor + +```ts +new BaseAdapter(config): BaseAdapter; +``` + +Defined in: [base-adapter.ts:70](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L70) + +#### Parameters + +##### config + +[`AIAdapterConfig`](../interfaces/AIAdapterConfig.md) = `{}` + +#### Returns + +`BaseAdapter`\<`TChatModels`, `TEmbeddingModels`, `TChatProviderOptions`, `TEmbeddingProviderOptions`, `TModelProviderOptionsByName`, `TModelInputModalitiesByName`, `TMessageMetadataByModality`\> + +## Properties + +### \_chatProviderOptions? + +```ts +optional _chatProviderOptions: TChatProviderOptions; +``` + +Defined in: [base-adapter.ts:61](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L61) + +#### Implementation of + +[`AIAdapter`](../interfaces/AIAdapter.md).[`_chatProviderOptions`](../interfaces/AIAdapter.md#_chatprovideroptions) + +*** + +### \_embeddingProviderOptions? + +```ts +optional _embeddingProviderOptions: TEmbeddingProviderOptions; +``` + +Defined in: [base-adapter.ts:62](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L62) + +#### Implementation of + +[`AIAdapter`](../interfaces/AIAdapter.md).[`_embeddingProviderOptions`](../interfaces/AIAdapter.md#_embeddingprovideroptions) + +*** + +### \_messageMetadataByModality? + +```ts +optional _messageMetadataByModality: TMessageMetadataByModality; +``` + +Defined in: [base-adapter.ts:68](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L68) + +Type-only map from modality type to adapter-specific metadata types. +Used to provide type-safe autocomplete for metadata on content parts. + +#### Implementation of + +[`AIAdapter`](../interfaces/AIAdapter.md).[`_messageMetadataByModality`](../interfaces/AIAdapter.md#_messagemetadatabymodality) + +*** + +### \_modelInputModalitiesByName? + +```ts +optional _modelInputModalitiesByName: TModelInputModalitiesByName; +``` + +Defined in: [base-adapter.ts:66](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L66) + +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. +Must be provided by all adapters. + +#### Implementation of + +[`AIAdapter`](../interfaces/AIAdapter.md).[`_modelInputModalitiesByName`](../interfaces/AIAdapter.md#_modelinputmodalitiesbyname) + +*** + +### \_modelProviderOptionsByName + +```ts +_modelProviderOptionsByName: TModelProviderOptionsByName; +``` + +Defined in: [base-adapter.ts:64](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L64) + +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. +Must be provided by all adapters. + +#### Implementation of + +[`AIAdapter`](../interfaces/AIAdapter.md).[`_modelProviderOptionsByName`](../interfaces/AIAdapter.md#_modelprovideroptionsbyname) + +*** + +### \_providerOptions? + +```ts +optional _providerOptions: TChatProviderOptions; +``` + +Defined in: [base-adapter.ts:60](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L60) + +#### Implementation of + +[`AIAdapter`](../interfaces/AIAdapter.md).[`_providerOptions`](../interfaces/AIAdapter.md#_provideroptions) + +*** + +### config + +```ts +protected config: AIAdapterConfig; +``` + +Defined in: [base-adapter.ts:57](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L57) + +*** + +### embeddingModels? + +```ts +optional embeddingModels: TEmbeddingModels; +``` + +Defined in: [base-adapter.ts:56](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L56) + +Models that support embeddings + +#### Implementation of + +[`AIAdapter`](../interfaces/AIAdapter.md).[`embeddingModels`](../interfaces/AIAdapter.md#embeddingmodels) + +*** + +### models + +```ts +abstract models: TChatModels; +``` + +Defined in: [base-adapter.ts:55](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L55) + +Models that support chat/text completion + +#### Implementation of + +[`AIAdapter`](../interfaces/AIAdapter.md).[`models`](../interfaces/AIAdapter.md#models) + +*** + +### name + +```ts +abstract name: string; +``` + +Defined in: [base-adapter.ts:54](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L54) + +#### Implementation of + +[`AIAdapter`](../interfaces/AIAdapter.md).[`name`](../interfaces/AIAdapter.md#name) + +## Methods + +### chatStream() + +```ts +abstract chatStream(options): AsyncIterable; +``` + +Defined in: [base-adapter.ts:74](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L74) + +#### Parameters + +##### options + +[`ChatOptions`](../interfaces/ChatOptions.md) + +#### Returns + +`AsyncIterable`\<[`StreamChunk`](../type-aliases/StreamChunk.md)\> + +#### Implementation of + +[`AIAdapter`](../interfaces/AIAdapter.md).[`chatStream`](../interfaces/AIAdapter.md#chatstream) + +*** + +### createEmbeddings() + +```ts +abstract createEmbeddings(options): Promise; +``` + +Defined in: [base-adapter.ts:79](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L79) + +#### Parameters + +##### options + +[`EmbeddingOptions`](../interfaces/EmbeddingOptions.md) + +#### Returns + +`Promise`\<[`EmbeddingResult`](../interfaces/EmbeddingResult.md)\> + +#### Implementation of + +[`AIAdapter`](../interfaces/AIAdapter.md).[`createEmbeddings`](../interfaces/AIAdapter.md#createembeddings) + +*** + +### generateId() + +```ts +protected generateId(): string; +``` + +Defined in: [base-adapter.ts:81](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L81) + +#### Returns + +`string` + +*** + +### summarize() + +```ts +abstract summarize(options): Promise; +``` + +Defined in: [base-adapter.ts:76](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/base-adapter.ts#L76) + +#### Parameters + +##### options + +[`SummarizationOptions`](../interfaces/SummarizationOptions.md) + +#### Returns + +`Promise`\<[`SummarizationResult`](../interfaces/SummarizationResult.md)\> + +#### Implementation of + +[`AIAdapter`](../interfaces/AIAdapter.md).[`summarize`](../interfaces/AIAdapter.md#summarize) diff --git a/docs/reference/classes/BatchStrategy.md b/docs/reference/classes/BatchStrategy.md new file mode 100644 index 00000000..a437b0aa --- /dev/null +++ b/docs/reference/classes/BatchStrategy.md @@ -0,0 +1,87 @@ +--- +id: BatchStrategy +title: BatchStrategy +--- + +# Class: BatchStrategy + +Defined in: [stream/strategies.ts:34](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/strategies.ts#L34) + +Batch Strategy - emit every N chunks +Useful for reducing UI update frequency + +## Implements + +- [`ChunkStrategy`](../interfaces/ChunkStrategy.md) + +## Constructors + +### Constructor + +```ts +new BatchStrategy(batchSize): BatchStrategy; +``` + +Defined in: [stream/strategies.ts:37](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/strategies.ts#L37) + +#### Parameters + +##### batchSize + +`number` = `5` + +#### Returns + +`BatchStrategy` + +## Methods + +### reset() + +```ts +reset(): void; +``` + +Defined in: [stream/strategies.ts:48](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/strategies.ts#L48) + +Optional: Reset strategy state (called when streaming starts) + +#### Returns + +`void` + +#### Implementation of + +[`ChunkStrategy`](../interfaces/ChunkStrategy.md).[`reset`](../interfaces/ChunkStrategy.md#reset) + +*** + +### shouldEmit() + +```ts +shouldEmit(_chunk, _accumulated): boolean; +``` + +Defined in: [stream/strategies.ts:39](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/strategies.ts#L39) + +Called for each text chunk received + +#### Parameters + +##### \_chunk + +`string` + +##### \_accumulated + +`string` + +#### Returns + +`boolean` + +true if an update should be emitted now + +#### Implementation of + +[`ChunkStrategy`](../interfaces/ChunkStrategy.md).[`shouldEmit`](../interfaces/ChunkStrategy.md#shouldemit) diff --git a/docs/reference/classes/CompositeStrategy.md b/docs/reference/classes/CompositeStrategy.md new file mode 100644 index 00000000..5c6f71e3 --- /dev/null +++ b/docs/reference/classes/CompositeStrategy.md @@ -0,0 +1,91 @@ +--- +id: CompositeStrategy +title: CompositeStrategy +--- + +# Class: CompositeStrategy + +Defined in: [stream/strategies.ts:68](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/strategies.ts#L68) + +Composite Strategy - combine multiple strategies (OR logic) +Emits if ANY strategy says to emit + +## Implements + +- [`ChunkStrategy`](../interfaces/ChunkStrategy.md) + +## Constructors + +### Constructor + +```ts +new CompositeStrategy(strategies): CompositeStrategy; +``` + +Defined in: [stream/strategies.ts:69](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/strategies.ts#L69) + +#### Parameters + +##### strategies + +[`ChunkStrategy`](../interfaces/ChunkStrategy.md)[] + +#### Returns + +`CompositeStrategy` + +## Methods + +### reset() + +```ts +reset(): void; +``` + +Defined in: [stream/strategies.ts:75](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/strategies.ts#L75) + +Optional: Reset strategy state (called when streaming starts) + +#### Returns + +`void` + +#### Implementation of + +[`ChunkStrategy`](../interfaces/ChunkStrategy.md).[`reset`](../interfaces/ChunkStrategy.md#reset) + +*** + +### shouldEmit() + +```ts +shouldEmit(chunk, accumulated): boolean; +``` + +Defined in: [stream/strategies.ts:71](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/strategies.ts#L71) + +Called for each text chunk received + +#### Parameters + +##### chunk + +`string` + +The new chunk of text (delta) + +##### accumulated + +`string` + +All text accumulated so far + +#### Returns + +`boolean` + +true if an update should be emitted now + +#### Implementation of + +[`ChunkStrategy`](../interfaces/ChunkStrategy.md).[`shouldEmit`](../interfaces/ChunkStrategy.md#shouldemit) diff --git a/docs/reference/classes/ImmediateStrategy.md b/docs/reference/classes/ImmediateStrategy.md new file mode 100644 index 00000000..fcf89ea0 --- /dev/null +++ b/docs/reference/classes/ImmediateStrategy.md @@ -0,0 +1,58 @@ +--- +id: ImmediateStrategy +title: ImmediateStrategy +--- + +# Class: ImmediateStrategy + +Defined in: [stream/strategies.ts:12](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/strategies.ts#L12) + +Immediate Strategy - emit on every chunk (default behavior) + +## Implements + +- [`ChunkStrategy`](../interfaces/ChunkStrategy.md) + +## Constructors + +### Constructor + +```ts +new ImmediateStrategy(): ImmediateStrategy; +``` + +#### Returns + +`ImmediateStrategy` + +## Methods + +### shouldEmit() + +```ts +shouldEmit(_chunk, _accumulated): boolean; +``` + +Defined in: [stream/strategies.ts:13](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/strategies.ts#L13) + +Called for each text chunk received + +#### Parameters + +##### \_chunk + +`string` + +##### \_accumulated + +`string` + +#### Returns + +`boolean` + +true if an update should be emitted now + +#### Implementation of + +[`ChunkStrategy`](../interfaces/ChunkStrategy.md).[`shouldEmit`](../interfaces/ChunkStrategy.md#shouldemit) diff --git a/docs/reference/classes/PartialJSONParser.md b/docs/reference/classes/PartialJSONParser.md new file mode 100644 index 00000000..59fdcfb0 --- /dev/null +++ b/docs/reference/classes/PartialJSONParser.md @@ -0,0 +1,57 @@ +--- +id: PartialJSONParser +title: PartialJSONParser +--- + +# Class: PartialJSONParser + +Defined in: [stream/json-parser.ts:25](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/json-parser.ts#L25) + +Partial JSON Parser implementation using the partial-json library +This parser can handle incomplete JSON strings during streaming + +## Implements + +- [`JSONParser`](../interfaces/JSONParser.md) + +## Constructors + +### Constructor + +```ts +new PartialJSONParser(): PartialJSONParser; +``` + +#### Returns + +`PartialJSONParser` + +## Methods + +### parse() + +```ts +parse(jsonString): any; +``` + +Defined in: [stream/json-parser.ts:31](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/json-parser.ts#L31) + +Parse a potentially incomplete JSON string + +#### Parameters + +##### jsonString + +`string` + +The JSON string to parse (may be incomplete) + +#### Returns + +`any` + +The parsed object, or undefined if parsing fails + +#### Implementation of + +[`JSONParser`](../interfaces/JSONParser.md).[`parse`](../interfaces/JSONParser.md#parse) diff --git a/docs/reference/classes/PunctuationStrategy.md b/docs/reference/classes/PunctuationStrategy.md new file mode 100644 index 00000000..f5e1ebe4 --- /dev/null +++ b/docs/reference/classes/PunctuationStrategy.md @@ -0,0 +1,61 @@ +--- +id: PunctuationStrategy +title: PunctuationStrategy +--- + +# Class: PunctuationStrategy + +Defined in: [stream/strategies.ts:22](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/strategies.ts#L22) + +Punctuation Strategy - emit when chunk contains punctuation +Useful for natural text flow in UI + +## Implements + +- [`ChunkStrategy`](../interfaces/ChunkStrategy.md) + +## Constructors + +### Constructor + +```ts +new PunctuationStrategy(): PunctuationStrategy; +``` + +#### Returns + +`PunctuationStrategy` + +## Methods + +### shouldEmit() + +```ts +shouldEmit(chunk, _accumulated): boolean; +``` + +Defined in: [stream/strategies.ts:25](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/strategies.ts#L25) + +Called for each text chunk received + +#### Parameters + +##### chunk + +`string` + +The new chunk of text (delta) + +##### \_accumulated + +`string` + +#### Returns + +`boolean` + +true if an update should be emitted now + +#### Implementation of + +[`ChunkStrategy`](../interfaces/ChunkStrategy.md).[`shouldEmit`](../interfaces/ChunkStrategy.md#shouldemit) diff --git a/docs/reference/classes/StreamProcessor.md b/docs/reference/classes/StreamProcessor.md new file mode 100644 index 00000000..d7d3e141 --- /dev/null +++ b/docs/reference/classes/StreamProcessor.md @@ -0,0 +1,407 @@ +--- +id: StreamProcessor +title: StreamProcessor +--- + +# Class: StreamProcessor + +Defined in: [stream/processor.ts:171](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L171) + +StreamProcessor - State machine for processing AI response streams + +Manages the full UIMessage[] conversation and emits events on changes. + +State tracking: +- Full message array +- Current assistant message being streamed +- Text content accumulation +- Multiple parallel tool calls +- Tool call completion detection + +Tool call completion is detected when: +1. A new tool call starts at a different index +2. Text content arrives +3. Stream ends + +## Constructors + +### Constructor + +```ts +new StreamProcessor(options): StreamProcessor; +``` + +Defined in: [stream/processor.ts:200](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L200) + +#### Parameters + +##### options + +[`StreamProcessorOptions`](../interfaces/StreamProcessorOptions.md) = `{}` + +#### Returns + +`StreamProcessor` + +## Methods + +### addToolApprovalResponse() + +```ts +addToolApprovalResponse(approvalId, approved): void; +``` + +Defined in: [stream/processor.ts:314](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L314) + +Add an approval response (called by client after handling onApprovalRequest) + +#### Parameters + +##### approvalId + +`string` + +##### approved + +`boolean` + +#### Returns + +`void` + +*** + +### addToolResult() + +```ts +addToolResult( + toolCallId, + output, + error?): void; +``` + +Defined in: [stream/processor.ts:270](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L270) + +Add a tool result (called by client after handling onToolCall) + +#### Parameters + +##### toolCallId + +`string` + +##### output + +`any` + +##### error? + +`string` + +#### Returns + +`void` + +*** + +### addUserMessage() + +```ts +addUserMessage(content): UIMessage; +``` + +Defined in: [stream/processor.ts:228](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L228) + +Add a user message to the conversation + +#### Parameters + +##### content + +`string` + +#### Returns + +[`UIMessage`](../interfaces/UIMessage.md) + +*** + +### areAllToolsComplete() + +```ts +areAllToolsComplete(): boolean; +``` + +Defined in: [stream/processor.ts:345](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L345) + +Check if all tool calls in the last assistant message are complete +Useful for auto-continue logic + +#### Returns + +`boolean` + +*** + +### clearMessages() + +```ts +clearMessages(): void; +``` + +Defined in: [stream/processor.ts:377](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L377) + +Clear all messages + +#### Returns + +`void` + +*** + +### finalizeStream() + +```ts +finalizeStream(): void; +``` + +Defined in: [stream/processor.ts:1033](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L1033) + +Finalize the stream - complete all pending operations + +#### Returns + +`void` + +*** + +### getMessages() + +```ts +getMessages(): UIMessage[]; +``` + +Defined in: [stream/processor.ts:337](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L337) + +Get current messages + +#### Returns + +[`UIMessage`](../interfaces/UIMessage.md)[] + +*** + +### getRecording() + +```ts +getRecording(): ChunkRecording | null; +``` + +Defined in: [stream/processor.ts:1533](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L1533) + +Get the current recording + +#### Returns + +[`ChunkRecording`](../interfaces/ChunkRecording.md) \| `null` + +*** + +### getState() + +```ts +getState(): ProcessorState; +``` + +Defined in: [stream/processor.ts:1092](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L1092) + +Get current processor state (legacy) + +#### Returns + +[`ProcessorState`](../interfaces/ProcessorState.md) + +*** + +### process() + +```ts +process(stream): Promise; +``` + +Defined in: [stream/processor.ts:390](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L390) + +Process a stream and emit events through handlers + +#### Parameters + +##### stream + +`AsyncIterable`\<`any`\> + +#### Returns + +`Promise`\<[`ProcessorResult`](../interfaces/ProcessorResult.md)\> + +*** + +### processChunk() + +```ts +processChunk(chunk): void; +``` + +Defined in: [stream/processor.ts:418](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L418) + +Process a single chunk from the stream + +#### Parameters + +##### chunk + +[`StreamChunk`](../type-aliases/StreamChunk.md) + +#### Returns + +`void` + +*** + +### removeMessagesAfter() + +```ts +removeMessagesAfter(index): void; +``` + +Defined in: [stream/processor.ts:369](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L369) + +Remove messages after a certain index (for reload/retry) + +#### Parameters + +##### index + +`number` + +#### Returns + +`void` + +*** + +### reset() + +```ts +reset(): void; +``` + +Defined in: [stream/processor.ts:1556](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L1556) + +Full reset (including messages) + +#### Returns + +`void` + +*** + +### setMessages() + +```ts +setMessages(messages): void; +``` + +Defined in: [stream/processor.ts:220](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L220) + +Set the messages array (e.g., from persisted state) + +#### Parameters + +##### messages + +[`UIMessage`](../interfaces/UIMessage.md)[] + +#### Returns + +`void` + +*** + +### startAssistantMessage() + +```ts +startAssistantMessage(): string; +``` + +Defined in: [stream/processor.ts:246](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L246) + +Start streaming a new assistant message +Returns the message ID + +#### Returns + +`string` + +*** + +### startRecording() + +```ts +startRecording(): void; +``` + +Defined in: [stream/processor.ts:1520](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L1520) + +Start recording chunks + +#### Returns + +`void` + +*** + +### toModelMessages() + +```ts +toModelMessages(): ModelMessage< + | string + | ContentPart[] + | null>[]; +``` + +Defined in: [stream/processor.ts:326](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L326) + +Get the conversation as ModelMessages (for sending to LLM) + +#### Returns + +[`ModelMessage`](../interfaces/ModelMessage.md)\< + \| `string` + \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[] + \| `null`\>[] + +*** + +### replay() + +```ts +static replay(recording, options?): Promise; +``` + +Defined in: [stream/processor.ts:1565](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L1565) + +Replay a recording through the processor + +#### Parameters + +##### recording + +[`ChunkRecording`](../interfaces/ChunkRecording.md) + +##### options? + +[`StreamProcessorOptions`](../interfaces/StreamProcessorOptions.md) + +#### Returns + +`Promise`\<[`ProcessorResult`](../interfaces/ProcessorResult.md)\> diff --git a/docs/reference/classes/ToolCallManager.md b/docs/reference/classes/ToolCallManager.md new file mode 100644 index 00000000..419325cb --- /dev/null +++ b/docs/reference/classes/ToolCallManager.md @@ -0,0 +1,270 @@ +--- +id: ToolCallManager +title: ToolCallManager +--- + +# Class: ToolCallManager + +Defined in: [tools/tool-calls.ts:43](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L43) + +Manages tool call accumulation and execution for the chat() method's automatic tool execution loop. + +Responsibilities: +- Accumulates streaming tool call chunks (ID, name, arguments) +- Validates tool calls (filters out incomplete ones) +- Executes tool `execute` functions with parsed arguments +- Emits `tool_result` chunks for client visibility +- Returns tool result messages for conversation history + +This class is used internally by the AI.chat() method to handle the automatic +tool execution loop. It can also be used independently for custom tool execution logic. + +## Example + +```typescript +const manager = new ToolCallManager(tools); + +// During streaming, accumulate tool calls +for await (const chunk of stream) { + if (chunk.type === "tool_call") { + manager.addToolCallChunk(chunk); + } +} + +// After stream completes, execute tools +if (manager.hasToolCalls()) { + const toolResults = yield* manager.executeTools(doneChunk); + messages = [...messages, ...toolResults]; + manager.clear(); +} +``` + +## Constructors + +### Constructor + +```ts +new ToolCallManager(tools): ToolCallManager; +``` + +Defined in: [tools/tool-calls.ts:47](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L47) + +#### Parameters + +##### tools + +readonly [`Tool`](../interfaces/Tool.md)\<`ZodType`\<`unknown`, `unknown`, `$ZodTypeInternals`\<`unknown`, `unknown`\>\>, `ZodType`\<`unknown`, `unknown`, `$ZodTypeInternals`\<`unknown`, `unknown`\>\>, `string`\>[] + +#### Returns + +`ToolCallManager` + +## Methods + +### addToolCallArgsEvent() + +```ts +addToolCallArgsEvent(chunk): void; +``` + +Defined in: [tools/tool-calls.ts:69](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L69) + +Add a TOOL_CALL_ARGS event to accumulate arguments + +#### Parameters + +##### chunk + +[`ToolCallArgsEvent`](../interfaces/ToolCallArgsEvent.md) + +#### Returns + +`void` + +*** + +### ~~addToolCallChunk()~~ + +```ts +addToolCallChunk(chunk): void; +``` + +Defined in: [tools/tool-calls.ts:96](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L96) + +Add a tool call chunk to the accumulator (legacy format) +Handles streaming tool calls by accumulating arguments + +#### Parameters + +##### chunk + +###### index + +`number` + +###### toolCall + +\{ + `function`: \{ + `arguments`: `string`; + `name`: `string`; + \}; + `id`: `string`; + `type`: `"function"`; +\} + +###### toolCall.function + +\{ + `arguments`: `string`; + `name`: `string`; +\} + +###### toolCall.function.arguments + +`string` + +###### toolCall.function.name + +`string` + +###### toolCall.id + +`string` + +###### toolCall.type + +`"function"` + +#### Returns + +`void` + +#### Deprecated + +Use addToolCallStartEvent and addToolCallArgsEvent instead + +*** + +### addToolCallStartEvent() + +```ts +addToolCallStartEvent(chunk): void; +``` + +Defined in: [tools/tool-calls.ts:54](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L54) + +Add a TOOL_CALL_START event to begin tracking a tool call + +#### Parameters + +##### chunk + +[`ToolCallStartEvent`](../interfaces/ToolCallStartEvent.md) + +#### Returns + +`void` + +*** + +### clear() + +```ts +clear(): void; +``` + +Defined in: [tools/tool-calls.ts:236](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L236) + +Clear the tool calls map for the next iteration + +#### Returns + +`void` + +*** + +### completeToolCall() + +```ts +completeToolCall(toolCallId, input?): void; +``` + +Defined in: [tools/tool-calls.ts:82](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L82) + +Complete a tool call with its final input + +#### Parameters + +##### toolCallId + +`string` + +##### input? + +`any` + +#### Returns + +`void` + +*** + +### executeTools() + +```ts +executeTools(doneChunk): AsyncGenerator[] +| null>[], void>; +``` + +Defined in: [tools/tool-calls.ts:154](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L154) + +Execute all tool calls and return tool result messages +Also yields TOOL_CALL_END events for streaming + +#### Parameters + +##### doneChunk + +[`RunFinishedEvent`](../interfaces/RunFinishedEvent.md) + +#### Returns + +`AsyncGenerator`\<[`ToolCallEndEvent`](../interfaces/ToolCallEndEvent.md), [`ModelMessage`](../interfaces/ModelMessage.md)\< + \| `string` + \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[] + \| `null`\>[], `void`\> + +*** + +### getToolCalls() + +```ts +getToolCalls(): ToolCall[]; +``` + +Defined in: [tools/tool-calls.ts:144](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L144) + +Get all complete tool calls (filtered for valid ID and name) + +#### Returns + +[`ToolCall`](../interfaces/ToolCall.md)[] + +*** + +### hasToolCalls() + +```ts +hasToolCalls(): boolean; +``` + +Defined in: [tools/tool-calls.ts:137](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-calls.ts#L137) + +Check if there are any complete tool calls to execute + +#### Returns + +`boolean` diff --git a/docs/reference/classes/WordBoundaryStrategy.md b/docs/reference/classes/WordBoundaryStrategy.md new file mode 100644 index 00000000..985ce4f6 --- /dev/null +++ b/docs/reference/classes/WordBoundaryStrategy.md @@ -0,0 +1,61 @@ +--- +id: WordBoundaryStrategy +title: WordBoundaryStrategy +--- + +# Class: WordBoundaryStrategy + +Defined in: [stream/strategies.ts:57](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/strategies.ts#L57) + +Word Boundary Strategy - emit at word boundaries +Prevents cutting words in half + +## Implements + +- [`ChunkStrategy`](../interfaces/ChunkStrategy.md) + +## Constructors + +### Constructor + +```ts +new WordBoundaryStrategy(): WordBoundaryStrategy; +``` + +#### Returns + +`WordBoundaryStrategy` + +## Methods + +### shouldEmit() + +```ts +shouldEmit(chunk, _accumulated): boolean; +``` + +Defined in: [stream/strategies.ts:58](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/strategies.ts#L58) + +Called for each text chunk received + +#### Parameters + +##### chunk + +`string` + +The new chunk of text (delta) + +##### \_accumulated + +`string` + +#### Returns + +`boolean` + +true if an update should be emitted now + +#### Implementation of + +[`ChunkStrategy`](../interfaces/ChunkStrategy.md).[`shouldEmit`](../interfaces/ChunkStrategy.md#shouldemit) diff --git a/docs/reference/functions/chat.md b/docs/reference/functions/chat.md new file mode 100644 index 00000000..2e8f5b51 --- /dev/null +++ b/docs/reference/functions/chat.md @@ -0,0 +1,55 @@ +--- +id: chat +title: chat +--- + +# Function: chat() + +```ts +function chat(options): AsyncIterable; +``` + +Defined in: [core/chat.ts:882](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/core/chat.ts#L882) + +Standalone chat streaming function with type inference from adapter +Returns an async iterable of StreamChunks for streaming responses +Includes automatic tool execution loop + +## Type Parameters + +### TAdapter + +`TAdapter` *extends* [`AIAdapter`](../interfaces/AIAdapter.md)\<`any`, `any`, `any`, `any`, `any`, `any`, [`DefaultMessageMetadataByModality`](../interfaces/DefaultMessageMetadataByModality.md)\> + +### TModel + +`TModel` *extends* `any` + +## Parameters + +### options + +[`ChatStreamOptionsForModel`](../type-aliases/ChatStreamOptionsForModel.md)\<`TAdapter`, `TModel`\> + +Chat options + +## Returns + +`AsyncIterable`\<[`StreamChunk`](../type-aliases/StreamChunk.md)\> + +## Example + +```typescript +const stream = chat({ + adapter: openai(), + model: 'gpt-4o', + messages: [{ role: 'user', content: 'Hello!' }], + tools: [weatherTool], // Optional: auto-executed when called +}); + +for await (const chunk of stream) { + if (chunk.type === 'content') { + console.log(chunk.delta); + } +} +``` diff --git a/docs/reference/functions/chatOptions.md b/docs/reference/functions/chatOptions.md new file mode 100644 index 00000000..d776680b --- /dev/null +++ b/docs/reference/functions/chatOptions.md @@ -0,0 +1,32 @@ +--- +id: chatOptions +title: chatOptions +--- + +# Function: chatOptions() + +```ts +function chatOptions(options): Omit, "model" | "providerOptions" | "messages" | "abortController"> & object; +``` + +Defined in: [utilities/chat-options.ts:3](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/utilities/chat-options.ts#L3) + +## Type Parameters + +### TAdapter + +`TAdapter` *extends* [`AIAdapter`](../interfaces/AIAdapter.md)\<`any`, `any`, `any`, `any`, `any`, `Record`\<`string`, readonly [`Modality`](../type-aliases/Modality.md)[]\>, [`DefaultMessageMetadataByModality`](../interfaces/DefaultMessageMetadataByModality.md)\> + +### TModel + +`TModel` *extends* `any` + +## Parameters + +### options + +`Omit`\<[`ChatStreamOptionsUnion`](../type-aliases/ChatStreamOptionsUnion.md)\<`TAdapter`\>, `"model"` \| `"providerOptions"` \| `"messages"` \| `"abortController"`\> & `object` + +## Returns + +`Omit`\<[`ChatStreamOptionsUnion`](../type-aliases/ChatStreamOptionsUnion.md)\<`TAdapter`\>, `"model"` \| `"providerOptions"` \| `"messages"` \| `"abortController"`\> & `object` diff --git a/docs/reference/functions/combineStrategies.md b/docs/reference/functions/combineStrategies.md new file mode 100644 index 00000000..454a0f33 --- /dev/null +++ b/docs/reference/functions/combineStrategies.md @@ -0,0 +1,44 @@ +--- +id: combineStrategies +title: combineStrategies +--- + +# Function: combineStrategies() + +```ts +function combineStrategies(strategies): AgentLoopStrategy; +``` + +Defined in: [utilities/agent-loop-strategies.ts:79](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/utilities/agent-loop-strategies.ts#L79) + +Creates a strategy that combines multiple strategies with AND logic +All strategies must return true to continue + +## Parameters + +### strategies + +[`AgentLoopStrategy`](../type-aliases/AgentLoopStrategy.md)[] + +Array of strategies to combine + +## Returns + +[`AgentLoopStrategy`](../type-aliases/AgentLoopStrategy.md) + +AgentLoopStrategy that continues only if all strategies return true + +## Example + +```typescript +const stream = chat({ + adapter: openai(), + model: "gpt-4o", + messages: [...], + tools: [weatherTool], + agentLoopStrategy: combineStrategies([ + maxIterations(10), + ({ messages }) => messages.length < 100, + ]), +}); +``` diff --git a/docs/reference/functions/convertMessagesToModelMessages.md b/docs/reference/functions/convertMessagesToModelMessages.md new file mode 100644 index 00000000..00224ace --- /dev/null +++ b/docs/reference/functions/convertMessagesToModelMessages.md @@ -0,0 +1,35 @@ +--- +id: convertMessagesToModelMessages +title: convertMessagesToModelMessages +--- + +# Function: convertMessagesToModelMessages() + +```ts +function convertMessagesToModelMessages(messages): ModelMessage< + | string + | ContentPart[] + | null>[]; +``` + +Defined in: [message-converters.ts:38](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/message-converters.ts#L38) + +Convert UIMessages or ModelMessages to ModelMessages + +## Parameters + +### messages + +( + \| [`UIMessage`](../interfaces/UIMessage.md) + \| [`ModelMessage`](../interfaces/ModelMessage.md)\< + \| `string` + \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[] + \| `null`\>)[] + +## Returns + +[`ModelMessage`](../interfaces/ModelMessage.md)\< + \| `string` + \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[] + \| `null`\>[] diff --git a/docs/reference/functions/convertZodToJsonSchema.md b/docs/reference/functions/convertZodToJsonSchema.md new file mode 100644 index 00000000..8b0526ab --- /dev/null +++ b/docs/reference/functions/convertZodToJsonSchema.md @@ -0,0 +1,50 @@ +--- +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/createReplayStream.md b/docs/reference/functions/createReplayStream.md new file mode 100644 index 00000000..6df2e4e5 --- /dev/null +++ b/docs/reference/functions/createReplayStream.md @@ -0,0 +1,24 @@ +--- +id: createReplayStream +title: createReplayStream +--- + +# Function: createReplayStream() + +```ts +function createReplayStream(recording): AsyncIterable; +``` + +Defined in: [stream/processor.ts:1577](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L1577) + +Create an async iterable from a recording + +## Parameters + +### recording + +[`ChunkRecording`](../interfaces/ChunkRecording.md) + +## Returns + +`AsyncIterable`\<[`StreamChunk`](../type-aliases/StreamChunk.md)\> diff --git a/docs/reference/functions/embedding.md b/docs/reference/functions/embedding.md new file mode 100644 index 00000000..058e3ff4 --- /dev/null +++ b/docs/reference/functions/embedding.md @@ -0,0 +1,30 @@ +--- +id: embedding +title: embedding +--- + +# Function: embedding() + +```ts +function embedding(options): Promise; +``` + +Defined in: [core/embedding.ts:16](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/core/embedding.ts#L16) + +Standalone embedding function with type inference from adapter + +## Type Parameters + +### TAdapter + +`TAdapter` *extends* [`AIAdapter`](../interfaces/AIAdapter.md)\<`any`, `any`, `any`, `any`, `any`, `Record`\<`string`, readonly [`Modality`](../type-aliases/Modality.md)[]\>, [`DefaultMessageMetadataByModality`](../interfaces/DefaultMessageMetadataByModality.md)\> + +## Parameters + +### options + +`Omit`\<[`EmbeddingOptions`](../interfaces/EmbeddingOptions.md), `"model"`\> & `object` + +## Returns + +`Promise`\<[`EmbeddingResult`](../interfaces/EmbeddingResult.md)\> diff --git a/docs/reference/functions/generateMessageId.md b/docs/reference/functions/generateMessageId.md new file mode 100644 index 00000000..44568ce3 --- /dev/null +++ b/docs/reference/functions/generateMessageId.md @@ -0,0 +1,18 @@ +--- +id: generateMessageId +title: generateMessageId +--- + +# Function: generateMessageId() + +```ts +function generateMessageId(): string; +``` + +Defined in: [message-converters.ts:283](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/message-converters.ts#L283) + +Generate a unique message ID + +## Returns + +`string` diff --git a/docs/reference/functions/maxIterations.md b/docs/reference/functions/maxIterations.md new file mode 100644 index 00000000..1ab98cda --- /dev/null +++ b/docs/reference/functions/maxIterations.md @@ -0,0 +1,40 @@ +--- +id: maxIterations +title: maxIterations +--- + +# Function: maxIterations() + +```ts +function maxIterations(max): AgentLoopStrategy; +``` + +Defined in: [utilities/agent-loop-strategies.ts:20](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/utilities/agent-loop-strategies.ts#L20) + +Creates a strategy that continues for a maximum number of iterations + +## Parameters + +### max + +`number` + +Maximum number of iterations to allow + +## Returns + +[`AgentLoopStrategy`](../type-aliases/AgentLoopStrategy.md) + +AgentLoopStrategy that stops after max iterations + +## Example + +```typescript +const stream = chat({ + adapter: openai(), + model: "gpt-4o", + messages: [...], + tools: [weatherTool], + agentLoopStrategy: maxIterations(3), // Max 3 iterations +}); +``` diff --git a/docs/reference/functions/messages.md b/docs/reference/functions/messages.md new file mode 100644 index 00000000..b426dc57 --- /dev/null +++ b/docs/reference/functions/messages.md @@ -0,0 +1,94 @@ +--- +id: messages +title: messages +--- + +# Function: messages() + +```ts +function messages(_options, msgs): TAdapter extends AIAdapter ? TModel extends keyof ModelInputModalities ? ModelInputModalities[TModel] extends readonly Modality[] ? ConstrainedModelMessage[] : ModelMessage< + | string + | ContentPart[] + | null>[] : ModelMessage< + | string + | ContentPart[] + | null>[] : ModelMessage< + | string + | ContentPart[] + | null>[]; +``` + +Defined in: [utilities/messages.ts:33](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/utilities/messages.ts#L33) + +Type-safe helper to create a messages array constrained by a model's supported modalities. + +This function provides compile-time checking that your messages only contain +content types supported by the specified model. It's particularly useful when +combining typed messages with untyped data (like from request.json()). + +## Type Parameters + +### TAdapter + +`TAdapter` *extends* [`AIAdapter`](../interfaces/AIAdapter.md)\<`any`, `any`, `any`, `any`, `any`, `any`, [`DefaultMessageMetadataByModality`](../interfaces/DefaultMessageMetadataByModality.md)\> + +### TModel + +`TModel` *extends* `any` + +## Parameters + +### \_options + +#### adapter + +`TAdapter` + +#### model + +`TModel` + +### msgs + +`TAdapter` *extends* [`AIAdapter`](../interfaces/AIAdapter.md)\<`any`, `any`, `any`, `any`, `any`, `ModelInputModalities`, [`DefaultMessageMetadataByModality`](../interfaces/DefaultMessageMetadataByModality.md)\> ? `TModel` *extends* keyof `ModelInputModalities` ? `ModelInputModalities`\[`TModel`\<`TModel`\>\] *extends* readonly [`Modality`](../type-aliases/Modality.md)[] ? [`ConstrainedModelMessage`](../type-aliases/ConstrainedModelMessage.md)\<`any`\[`any`\]\>[] : [`ModelMessage`](../interfaces/ModelMessage.md)\< + \| `string` + \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[] + \| `null`\>[] : [`ModelMessage`](../interfaces/ModelMessage.md)\< + \| `string` + \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[] + \| `null`\>[] : [`ModelMessage`](../interfaces/ModelMessage.md)\< + \| `string` + \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[] + \| `null`\>[] + +## Returns + +`TAdapter` *extends* [`AIAdapter`](../interfaces/AIAdapter.md)\<`any`, `any`, `any`, `any`, `any`, `ModelInputModalities`, [`DefaultMessageMetadataByModality`](../interfaces/DefaultMessageMetadataByModality.md)\> ? `TModel` *extends* keyof `ModelInputModalities` ? `ModelInputModalities`\[`TModel`\<`TModel`\>\] *extends* readonly [`Modality`](../type-aliases/Modality.md)[] ? [`ConstrainedModelMessage`](../type-aliases/ConstrainedModelMessage.md)\<`any`\[`any`\]\>[] : [`ModelMessage`](../interfaces/ModelMessage.md)\< + \| `string` + \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[] + \| `null`\>[] : [`ModelMessage`](../interfaces/ModelMessage.md)\< + \| `string` + \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[] + \| `null`\>[] : [`ModelMessage`](../interfaces/ModelMessage.md)\< + \| `string` + \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[] + \| `null`\>[] + +## Example + +```typescript +import { messages, chat } from '@tanstack/ai' +import { openai } from '@tanstack/ai-openai' + +const adapter = openai() + +// This will error at compile time because gpt-4o only supports text+image +const msgs = messages({ adapter, model: 'gpt-4o' }, [ + { + role: 'user', + content: [ + { type: 'video', source: { type: 'url', value: '...' } } // Error! + ] + } +]) +``` diff --git a/docs/reference/functions/modelMessageToUIMessage.md b/docs/reference/functions/modelMessageToUIMessage.md new file mode 100644 index 00000000..02e80f8d --- /dev/null +++ b/docs/reference/functions/modelMessageToUIMessage.md @@ -0,0 +1,39 @@ +--- +id: modelMessageToUIMessage +title: modelMessageToUIMessage +--- + +# Function: modelMessageToUIMessage() + +```ts +function modelMessageToUIMessage(modelMessage, id?): UIMessage; +``` + +Defined in: [message-converters.ts:158](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/message-converters.ts#L158) + +Convert a ModelMessage to UIMessage + +This conversion creates a parts-based structure: +- content field → TextPart +- toolCalls array → ToolCallPart[] +- role="tool" messages should be converted separately and merged + +## Parameters + +### modelMessage + +[`ModelMessage`](../interfaces/ModelMessage.md) + +The ModelMessage to convert + +### id? + +`string` + +Optional ID for the UIMessage (generated if not provided) + +## Returns + +[`UIMessage`](../interfaces/UIMessage.md) + +A UIMessage with parts diff --git a/docs/reference/functions/modelMessagesToUIMessages.md b/docs/reference/functions/modelMessagesToUIMessages.md new file mode 100644 index 00000000..dd50df71 --- /dev/null +++ b/docs/reference/functions/modelMessagesToUIMessages.md @@ -0,0 +1,33 @@ +--- +id: modelMessagesToUIMessages +title: modelMessagesToUIMessages +--- + +# Function: modelMessagesToUIMessages() + +```ts +function modelMessagesToUIMessages(modelMessages): UIMessage[]; +``` + +Defined in: [message-converters.ts:211](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/message-converters.ts#L211) + +Convert an array of ModelMessages to UIMessages + +This handles merging tool result messages with their corresponding assistant messages + +## Parameters + +### modelMessages + +[`ModelMessage`](../interfaces/ModelMessage.md)\< + \| `string` + \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[] + \| `null`\>[] + +Array of ModelMessages to convert + +## Returns + +[`UIMessage`](../interfaces/UIMessage.md)[] + +Array of UIMessages diff --git a/docs/reference/functions/normalizeToUIMessage.md b/docs/reference/functions/normalizeToUIMessage.md new file mode 100644 index 00000000..a42310e3 --- /dev/null +++ b/docs/reference/functions/normalizeToUIMessage.md @@ -0,0 +1,38 @@ +--- +id: normalizeToUIMessage +title: normalizeToUIMessage +--- + +# Function: normalizeToUIMessage() + +```ts +function normalizeToUIMessage(message, generateId): UIMessage; +``` + +Defined in: [message-converters.ts:260](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/message-converters.ts#L260) + +Normalize a message (UIMessage or ModelMessage) to a UIMessage +Ensures the message has an ID and createdAt timestamp + +## Parameters + +### message + +Either a UIMessage or ModelMessage + +[`UIMessage`](../interfaces/UIMessage.md) | [`ModelMessage`](../interfaces/ModelMessage.md)\< +\| `string` +\| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[] +\| `null`\> + +### generateId + +() => `string` + +Function to generate a message ID if needed + +## Returns + +[`UIMessage`](../interfaces/UIMessage.md) + +A UIMessage with guaranteed id and createdAt diff --git a/docs/reference/functions/parsePartialJSON.md b/docs/reference/functions/parsePartialJSON.md new file mode 100644 index 00000000..c3fb3806 --- /dev/null +++ b/docs/reference/functions/parsePartialJSON.md @@ -0,0 +1,28 @@ +--- +id: parsePartialJSON +title: parsePartialJSON +--- + +# Function: parsePartialJSON() + +```ts +function parsePartialJSON(jsonString): any; +``` + +Defined in: [stream/json-parser.ts:56](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/json-parser.ts#L56) + +Parse partial JSON string (convenience function) + +## Parameters + +### jsonString + +`string` + +The JSON string to parse (may be incomplete) + +## Returns + +`any` + +The parsed object, or undefined if parsing fails diff --git a/docs/reference/functions/summarize.md b/docs/reference/functions/summarize.md new file mode 100644 index 00000000..2ae9aead --- /dev/null +++ b/docs/reference/functions/summarize.md @@ -0,0 +1,30 @@ +--- +id: summarize +title: summarize +--- + +# Function: summarize() + +```ts +function summarize(options): Promise; +``` + +Defined in: [core/summarize.ts:16](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/core/summarize.ts#L16) + +Standalone summarize function with type inference from adapter + +## Type Parameters + +### TAdapter + +`TAdapter` *extends* [`AIAdapter`](../interfaces/AIAdapter.md)\<`any`, `any`, `any`, `any`, `any`, `Record`\<`string`, readonly [`Modality`](../type-aliases/Modality.md)[]\>, [`DefaultMessageMetadataByModality`](../interfaces/DefaultMessageMetadataByModality.md)\> + +## Parameters + +### options + +`Omit`\<[`SummarizationOptions`](../interfaces/SummarizationOptions.md), `"model"`\> & `object` + +## Returns + +`Promise`\<[`SummarizationResult`](../interfaces/SummarizationResult.md)\> diff --git a/docs/reference/functions/toServerSentEventsStream.md b/docs/reference/functions/toServerSentEventsStream.md new file mode 100644 index 00000000..65582450 --- /dev/null +++ b/docs/reference/functions/toServerSentEventsStream.md @@ -0,0 +1,47 @@ +--- +id: toServerSentEventsStream +title: toServerSentEventsStream +--- + +# Function: toServerSentEventsStream() + +```ts +function toServerSentEventsStream(stream, abortController?): ReadableStream>; +``` + +Defined in: [utilities/stream-to-response.ts:22](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/utilities/stream-to-response.ts#L22) + +Convert a StreamChunk async iterable to a ReadableStream in Server-Sent Events format + +This creates a ReadableStream that emits chunks in SSE format: +- Each chunk is prefixed with "data: " +- Each chunk is followed by "\n\n" +- Stream ends with "data: [DONE]\n\n" + +## Parameters + +### stream + +`AsyncIterable`\<[`StreamChunk`](../type-aliases/StreamChunk.md)\> + +AsyncIterable of StreamChunks from chat() + +### abortController? + +`AbortController` + +Optional AbortController to abort when stream is cancelled + +## Returns + +`ReadableStream`\<`Uint8Array`\<`ArrayBufferLike`\>\> + +ReadableStream in Server-Sent Events format + +## Example + +```typescript +const stream = chat({ adapter: openai(), model: "gpt-4o", messages: [...] }); +const readableStream = toServerSentEventsStream(stream); +// Use with Response, or any API that accepts ReadableStream +``` diff --git a/docs/reference/functions/toStreamResponse.md b/docs/reference/functions/toStreamResponse.md new file mode 100644 index 00000000..3d920408 --- /dev/null +++ b/docs/reference/functions/toStreamResponse.md @@ -0,0 +1,51 @@ +--- +id: toStreamResponse +title: toStreamResponse +--- + +# Function: toStreamResponse() + +```ts +function toStreamResponse(stream, init?): Response; +``` + +Defined in: [utilities/stream-to-response.ts:103](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/utilities/stream-to-response.ts#L103) + +Create a streaming HTTP response from a StreamChunk async iterable +Includes proper headers for Server-Sent Events + +## Parameters + +### stream + +`AsyncIterable`\<[`StreamChunk`](../type-aliases/StreamChunk.md)\> + +AsyncIterable of StreamChunks from chat() + +### init? + +`ResponseInit` & `object` + +Optional Response initialization options + +## Returns + +`Response` + +Response object with SSE headers and streaming body + +## Example + +```typescript +export async function POST(request: Request) { + const { messages } = await request.json(); + const abortController = new AbortController(); + const stream = chat({ + adapter: openai(), + model: "gpt-4o", + messages, + options: { abortSignal: abortController.signal } + }); + return toStreamResponse(stream, undefined, abortController); +} +``` diff --git a/docs/reference/functions/toolDefinition.md b/docs/reference/functions/toolDefinition.md new file mode 100644 index 00000000..46017b07 --- /dev/null +++ b/docs/reference/functions/toolDefinition.md @@ -0,0 +1,87 @@ +--- +id: toolDefinition +title: toolDefinition +--- + +# Function: toolDefinition() + +```ts +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) + +Create an isomorphic tool definition that can be used directly or instantiated for server/client + +The definition contains all tool metadata (name, description, schemas) and can be: +1. Used directly in chat() on the server (as a tool definition without execute) +2. Instantiated as a server tool with .server() +3. Instantiated as a client tool with .client() + +## Type Parameters + +### TInput + +`TInput` *extends* `ZodType`\<`unknown`, `unknown`, `$ZodTypeInternals`\<`unknown`, `unknown`\>\> = `ZodAny` + +### TOutput + +`TOutput` *extends* `ZodType`\<`unknown`, `unknown`, `$ZodTypeInternals`\<`unknown`, `unknown`\>\> = `ZodAny` + +### TName + +`TName` *extends* `string` = `string` + +## Parameters + +### config + +[`ToolDefinitionConfig`](../interfaces/ToolDefinitionConfig.md)\<`TInput`, `TOutput`, `TName`\> + +## Returns + +[`ToolDefinition`](../interfaces/ToolDefinition.md)\<`TInput`, `TOutput`, `TName`\> + +## Example + +```typescript +import { toolDefinition } from '@tanstack/ai'; +import { z } from 'zod'; + +const addToCartTool = toolDefinition({ + name: 'addToCart', + description: 'Add a guitar to the shopping cart (requires approval)', + needsApproval: true, + inputSchema: z.object({ + guitarId: z.string(), + quantity: z.number(), + }), + outputSchema: z.object({ + success: z.boolean(), + cartId: z.string(), + totalItems: z.number(), + }), +}); + +// Use directly in chat (server-side, no execute function) +chat({ + tools: [addToCartTool], + // ... +}); + +// Or create server-side implementation +const addToCartServer = addToCartTool.server(async (args) => { + // args is typed as { guitarId: string; quantity: number } + return { + success: true, + cartId: 'CART_' + Date.now(), + totalItems: args.quantity, + }; +}); + +// Or create client-side implementation +const addToCartClient = addToCartTool.client(async (args) => { + // Client-specific logic (e.g., localStorage) + return { success: true, cartId: 'local', totalItems: 1 }; +}); +``` diff --git a/docs/reference/functions/uiMessageToModelMessages.md b/docs/reference/functions/uiMessageToModelMessages.md new file mode 100644 index 00000000..9b295ad6 --- /dev/null +++ b/docs/reference/functions/uiMessageToModelMessages.md @@ -0,0 +1,39 @@ +--- +id: uiMessageToModelMessages +title: uiMessageToModelMessages +--- + +# Function: uiMessageToModelMessages() + +```ts +function uiMessageToModelMessages(uiMessage): ModelMessage< + | string + | ContentPart[] + | null>[]; +``` + +Defined in: [message-converters.ts:65](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/message-converters.ts#L65) + +Convert a UIMessage to ModelMessage(s) + +This conversion handles the parts-based structure: +- Text parts → content field +- ToolCall parts → toolCalls array +- ToolResult parts → separate role="tool" messages + +## Parameters + +### uiMessage + +[`UIMessage`](../interfaces/UIMessage.md) + +The UIMessage to convert + +## Returns + +[`ModelMessage`](../interfaces/ModelMessage.md)\< + \| `string` + \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[] + \| `null`\>[] + +An array of ModelMessages (may be multiple if tool results are present) diff --git a/docs/reference/functions/untilFinishReason.md b/docs/reference/functions/untilFinishReason.md new file mode 100644 index 00000000..2522b3f0 --- /dev/null +++ b/docs/reference/functions/untilFinishReason.md @@ -0,0 +1,40 @@ +--- +id: untilFinishReason +title: untilFinishReason +--- + +# Function: untilFinishReason() + +```ts +function untilFinishReason(stopReasons): AgentLoopStrategy; +``` + +Defined in: [utilities/agent-loop-strategies.ts:41](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/utilities/agent-loop-strategies.ts#L41) + +Creates a strategy that continues until a specific finish reason is encountered + +## Parameters + +### stopReasons + +`string`[] + +Finish reasons that should stop the loop + +## Returns + +[`AgentLoopStrategy`](../type-aliases/AgentLoopStrategy.md) + +AgentLoopStrategy that stops on specific finish reasons + +## Example + +```typescript +const stream = chat({ + adapter: openai(), + model: "gpt-4o", + messages: [...], + tools: [weatherTool], + agentLoopStrategy: untilFinishReason(["stop", "length"]), +}); +``` diff --git a/docs/reference/index.md b/docs/reference/index.md new file mode 100644 index 00000000..3ae6ba60 --- /dev/null +++ b/docs/reference/index.md @@ -0,0 +1,135 @@ +--- +id: "@tanstack/ai" +title: "@tanstack/ai" +--- + +# @tanstack/ai + +## Classes + +- [BaseAdapter](classes/BaseAdapter.md) +- [BatchStrategy](classes/BatchStrategy.md) +- [CompositeStrategy](classes/CompositeStrategy.md) +- [ImmediateStrategy](classes/ImmediateStrategy.md) +- [PartialJSONParser](classes/PartialJSONParser.md) +- [PunctuationStrategy](classes/PunctuationStrategy.md) +- [StreamProcessor](classes/StreamProcessor.md) +- [ToolCallManager](classes/ToolCallManager.md) +- [WordBoundaryStrategy](classes/WordBoundaryStrategy.md) + +## Interfaces + +- [AgentLoopState](interfaces/AgentLoopState.md) +- [AIAdapter](interfaces/AIAdapter.md) +- [AIAdapterConfig](interfaces/AIAdapterConfig.md) +- [~~ApprovalRequestedStreamChunk~~](interfaces/ApprovalRequestedStreamChunk.md) +- [AudioPart](interfaces/AudioPart.md) +- [BaseEvent](interfaces/BaseEvent.md) +- [ChatCompletionChunk](interfaces/ChatCompletionChunk.md) +- [ChatOptions](interfaces/ChatOptions.md) +- [ChunkRecording](interfaces/ChunkRecording.md) +- [ChunkStrategy](interfaces/ChunkStrategy.md) +- [ClientTool](interfaces/ClientTool.md) +- [ContentPartSource](interfaces/ContentPartSource.md) +- [~~ContentStreamChunk~~](interfaces/ContentStreamChunk.md) +- [CustomEvent](interfaces/CustomEvent.md) +- [DefaultMessageMetadataByModality](interfaces/DefaultMessageMetadataByModality.md) +- [DocumentPart](interfaces/DocumentPart.md) +- [~~DoneStreamChunk~~](interfaces/DoneStreamChunk.md) +- [EmbeddingOptions](interfaces/EmbeddingOptions.md) +- [EmbeddingResult](interfaces/EmbeddingResult.md) +- [~~ErrorStreamChunk~~](interfaces/ErrorStreamChunk.md) +- [ImagePart](interfaces/ImagePart.md) +- [InternalToolCallState](interfaces/InternalToolCallState.md) +- [JSONParser](interfaces/JSONParser.md) +- [ModelMessage](interfaces/ModelMessage.md) +- [ProcessorResult](interfaces/ProcessorResult.md) +- [ProcessorState](interfaces/ProcessorState.md) +- [ResponseFormat](interfaces/ResponseFormat.md) +- [RunErrorEvent](interfaces/RunErrorEvent.md) +- [RunFinishedEvent](interfaces/RunFinishedEvent.md) +- [RunStartedEvent](interfaces/RunStartedEvent.md) +- [ServerTool](interfaces/ServerTool.md) +- [StateDeltaEvent](interfaces/StateDeltaEvent.md) +- [StateSnapshotEvent](interfaces/StateSnapshotEvent.md) +- [StepFinishedEvent](interfaces/StepFinishedEvent.md) +- [StepStartedEvent](interfaces/StepStartedEvent.md) +- [StreamProcessorEvents](interfaces/StreamProcessorEvents.md) +- [StreamProcessorHandlers](interfaces/StreamProcessorHandlers.md) +- [StreamProcessorOptions](interfaces/StreamProcessorOptions.md) +- [SummarizationOptions](interfaces/SummarizationOptions.md) +- [SummarizationResult](interfaces/SummarizationResult.md) +- [TextMessageContentEvent](interfaces/TextMessageContentEvent.md) +- [TextMessageEndEvent](interfaces/TextMessageEndEvent.md) +- [TextMessageStartEvent](interfaces/TextMessageStartEvent.md) +- [TextPart](interfaces/TextPart.md) +- [ThinkingPart](interfaces/ThinkingPart.md) +- [~~ThinkingStreamChunk~~](interfaces/ThinkingStreamChunk.md) +- [Tool](interfaces/Tool.md) +- [ToolCall](interfaces/ToolCall.md) +- [ToolCallArgsEvent](interfaces/ToolCallArgsEvent.md) +- [ToolCallEndEvent](interfaces/ToolCallEndEvent.md) +- [ToolCallPart](interfaces/ToolCallPart.md) +- [ToolCallStartEvent](interfaces/ToolCallStartEvent.md) +- [~~ToolCallStreamChunk~~](interfaces/ToolCallStreamChunk.md) +- [ToolConfig](interfaces/ToolConfig.md) +- [ToolDefinition](interfaces/ToolDefinition.md) +- [ToolDefinitionConfig](interfaces/ToolDefinitionConfig.md) +- [ToolDefinitionInstance](interfaces/ToolDefinitionInstance.md) +- [~~ToolInputAvailableStreamChunk~~](interfaces/ToolInputAvailableStreamChunk.md) +- [ToolResultPart](interfaces/ToolResultPart.md) +- [~~ToolResultStreamChunk~~](interfaces/ToolResultStreamChunk.md) +- [UIMessage](interfaces/UIMessage.md) +- [VideoPart](interfaces/VideoPart.md) + +## Type Aliases + +- [AgentLoopStrategy](type-aliases/AgentLoopStrategy.md) +- [AnyClientTool](type-aliases/AnyClientTool.md) +- [ChatStreamOptionsForModel](type-aliases/ChatStreamOptionsForModel.md) +- [ChatStreamOptionsUnion](type-aliases/ChatStreamOptionsUnion.md) +- [ConstrainedContent](type-aliases/ConstrainedContent.md) +- [ConstrainedModelMessage](type-aliases/ConstrainedModelMessage.md) +- [ContentPart](type-aliases/ContentPart.md) +- [ContentPartForModalities](type-aliases/ContentPartForModalities.md) +- [EventType](type-aliases/EventType.md) +- [ExtractModalitiesForModel](type-aliases/ExtractModalitiesForModel.md) +- [ExtractModelsFromAdapter](type-aliases/ExtractModelsFromAdapter.md) +- [InferToolInput](type-aliases/InferToolInput.md) +- [InferToolName](type-aliases/InferToolName.md) +- [InferToolOutput](type-aliases/InferToolOutput.md) +- [MessagePart](type-aliases/MessagePart.md) +- [ModalitiesArrayToUnion](type-aliases/ModalitiesArrayToUnion.md) +- [Modality](type-aliases/Modality.md) +- [StreamChunk](type-aliases/StreamChunk.md) +- [StreamChunkType](type-aliases/StreamChunkType.md) +- [ToolCallState](type-aliases/ToolCallState.md) +- [ToolResultState](type-aliases/ToolResultState.md) + +## Variables + +- [aiEventClient](variables/aiEventClient.md) +- [defaultJSONParser](variables/defaultJSONParser.md) + +## Functions + +- [chat](functions/chat.md) +- [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) +- [maxIterations](functions/maxIterations.md) +- [messages](functions/messages.md) +- [modelMessagesToUIMessages](functions/modelMessagesToUIMessages.md) +- [modelMessageToUIMessage](functions/modelMessageToUIMessage.md) +- [normalizeToUIMessage](functions/normalizeToUIMessage.md) +- [parsePartialJSON](functions/parsePartialJSON.md) +- [summarize](functions/summarize.md) +- [toolDefinition](functions/toolDefinition.md) +- [toServerSentEventsStream](functions/toServerSentEventsStream.md) +- [toStreamResponse](functions/toStreamResponse.md) +- [uiMessageToModelMessages](functions/uiMessageToModelMessages.md) +- [untilFinishReason](functions/untilFinishReason.md) diff --git a/docs/reference/interfaces/AIAdapter.md b/docs/reference/interfaces/AIAdapter.md new file mode 100644 index 00000000..4052a0e8 --- /dev/null +++ b/docs/reference/interfaces/AIAdapter.md @@ -0,0 +1,214 @@ +--- +id: AIAdapter +title: AIAdapter +--- + +# Interface: AIAdapter\ + +Defined in: [types.ts:946](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L946) + +AI adapter interface with support for endpoint-specific models and provider options. + +Generic parameters: +- TChatModels: Models that support chat/text completion +- TEmbeddingModels: Models that support embeddings +- TChatProviderOptions: Provider-specific options for chat endpoint +- TEmbeddingProviderOptions: Provider-specific options for embedding endpoint +- TModelProviderOptionsByName: Map from model name to its specific provider options +- TModelInputModalitiesByName: Map from model name to its supported input modalities +- TMessageMetadataByModality: Map from modality type to adapter-specific metadata types + +## Type Parameters + +### TChatModels + +`TChatModels` *extends* `ReadonlyArray`\<`string`\> = `ReadonlyArray`\<`string`\> + +### TEmbeddingModels + +`TEmbeddingModels` *extends* `ReadonlyArray`\<`string`\> = `ReadonlyArray`\<`string`\> + +### TChatProviderOptions + +`TChatProviderOptions` *extends* `Record`\<`string`, `any`\> = `Record`\<`string`, `any`\> + +### TEmbeddingProviderOptions + +`TEmbeddingProviderOptions` *extends* `Record`\<`string`, `any`\> = `Record`\<`string`, `any`\> + +### TModelProviderOptionsByName + +`TModelProviderOptionsByName` *extends* `Record`\<`string`, `any`\> = `Record`\<`string`, `any`\> + +### TModelInputModalitiesByName + +`TModelInputModalitiesByName` *extends* `Record`\<`string`, `ReadonlyArray`\<[`Modality`](../type-aliases/Modality.md)\>\> = `Record`\<`string`, `ReadonlyArray`\<[`Modality`](../type-aliases/Modality.md)\>\> + +### TMessageMetadataByModality + +`TMessageMetadataByModality` *extends* `object` = [`DefaultMessageMetadataByModality`](DefaultMessageMetadataByModality.md) + +## Properties + +### \_chatProviderOptions? + +```ts +optional _chatProviderOptions: TChatProviderOptions; +``` + +Defined in: [types.ts:973](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L973) + +*** + +### \_embeddingProviderOptions? + +```ts +optional _embeddingProviderOptions: TEmbeddingProviderOptions; +``` + +Defined in: [types.ts:974](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L974) + +*** + +### \_messageMetadataByModality? + +```ts +optional _messageMetadataByModality: TMessageMetadataByModality; +``` + +Defined in: [types.ts:991](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L991) + +Type-only map from modality type to adapter-specific metadata types. +Used to provide type-safe autocomplete for metadata on content parts. + +*** + +### \_modelInputModalitiesByName? + +```ts +optional _modelInputModalitiesByName: TModelInputModalitiesByName; +``` + +Defined in: [types.ts:986](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L986) + +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. +Must be provided by all adapters. + +*** + +### \_modelProviderOptionsByName + +```ts +_modelProviderOptionsByName: TModelProviderOptionsByName; +``` + +Defined in: [types.ts:980](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L980) + +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. +Must be provided by all adapters. + +*** + +### \_providerOptions? + +```ts +optional _providerOptions: TChatProviderOptions; +``` + +Defined in: [types.ts:972](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L972) + +*** + +### chatStream() + +```ts +chatStream: (options) => AsyncIterable; +``` + +Defined in: [types.ts:994](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L994) + +#### Parameters + +##### options + +[`ChatOptions`](ChatOptions.md)\<`string`, `TChatProviderOptions`\> + +#### Returns + +`AsyncIterable`\<[`StreamChunk`](../type-aliases/StreamChunk.md)\> + +*** + +### createEmbeddings() + +```ts +createEmbeddings: (options) => Promise; +``` + +Defined in: [types.ts:1002](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L1002) + +#### Parameters + +##### options + +[`EmbeddingOptions`](EmbeddingOptions.md) + +#### Returns + +`Promise`\<[`EmbeddingResult`](EmbeddingResult.md)\> + +*** + +### embeddingModels? + +```ts +optional embeddingModels: TEmbeddingModels; +``` + +Defined in: [types.ts:969](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L969) + +Models that support embeddings + +*** + +### models + +```ts +models: TChatModels; +``` + +Defined in: [types.ts:966](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L966) + +Models that support chat/text completion + +*** + +### name + +```ts +name: string; +``` + +Defined in: [types.ts:964](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L964) + +*** + +### summarize() + +```ts +summarize: (options) => Promise; +``` + +Defined in: [types.ts:999](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L999) + +#### Parameters + +##### options + +[`SummarizationOptions`](SummarizationOptions.md) + +#### Returns + +`Promise`\<[`SummarizationResult`](SummarizationResult.md)\> diff --git a/docs/reference/interfaces/AIAdapterConfig.md b/docs/reference/interfaces/AIAdapterConfig.md new file mode 100644 index 00000000..4d238783 --- /dev/null +++ b/docs/reference/interfaces/AIAdapterConfig.md @@ -0,0 +1,58 @@ +--- +id: AIAdapterConfig +title: AIAdapterConfig +--- + +# Interface: AIAdapterConfig + +Defined in: [types.ts:1005](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L1005) + +## Properties + +### apiKey? + +```ts +optional apiKey: string; +``` + +Defined in: [types.ts:1006](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L1006) + +*** + +### baseUrl? + +```ts +optional baseUrl: string; +``` + +Defined in: [types.ts:1007](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L1007) + +*** + +### headers? + +```ts +optional headers: Record; +``` + +Defined in: [types.ts:1010](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L1010) + +*** + +### maxRetries? + +```ts +optional maxRetries: number; +``` + +Defined in: [types.ts:1009](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L1009) + +*** + +### timeout? + +```ts +optional timeout: number; +``` + +Defined in: [types.ts:1008](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L1008) diff --git a/docs/reference/interfaces/AgentLoopState.md b/docs/reference/interfaces/AgentLoopState.md new file mode 100644 index 00000000..9c117b02 --- /dev/null +++ b/docs/reference/interfaces/AgentLoopState.md @@ -0,0 +1,49 @@ +--- +id: AgentLoopState +title: AgentLoopState +--- + +# Interface: AgentLoopState + +Defined in: [types.ts:450](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L450) + +State passed to agent loop strategy for determining whether to continue + +## Properties + +### finishReason + +```ts +finishReason: string | null; +``` + +Defined in: [types.ts:456](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L456) + +Finish reason from the last response + +*** + +### iterationCount + +```ts +iterationCount: number; +``` + +Defined in: [types.ts:452](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L452) + +Current iteration count (0-indexed) + +*** + +### messages + +```ts +messages: ModelMessage< + | string + | ContentPart[] + | null>[]; +``` + +Defined in: [types.ts:454](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L454) + +Current messages array diff --git a/docs/reference/interfaces/ApprovalRequestedStreamChunk.md b/docs/reference/interfaces/ApprovalRequestedStreamChunk.md new file mode 100644 index 00000000..d11f61c8 --- /dev/null +++ b/docs/reference/interfaces/ApprovalRequestedStreamChunk.md @@ -0,0 +1,104 @@ +--- +id: ApprovalRequestedStreamChunk +title: ApprovalRequestedStreamChunk +--- + +# ~~Interface: ApprovalRequestedStreamChunk~~ + +Defined in: [types.ts:845](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L845) + +## Deprecated + +Use CustomEvent with name='approval-requested' instead + +## Properties + +### ~~approval?~~ + +```ts +optional approval: object; +``` + +Defined in: [types.ts:853](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L853) + +#### ~~id~~ + +```ts +id: string; +``` + +#### ~~needsApproval~~ + +```ts +needsApproval: true; +``` + +*** + +### ~~id~~ + +```ts +id: string; +``` + +Defined in: [types.ts:847](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L847) + +*** + +### ~~input~~ + +```ts +input: Record; +``` + +Defined in: [types.ts:852](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L852) + +*** + +### ~~model~~ + +```ts +model: string; +``` + +Defined in: [types.ts:848](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L848) + +*** + +### ~~timestamp~~ + +```ts +timestamp: number; +``` + +Defined in: [types.ts:849](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L849) + +*** + +### ~~toolCallId~~ + +```ts +toolCallId: string; +``` + +Defined in: [types.ts:850](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L850) + +*** + +### ~~toolName~~ + +```ts +toolName: string; +``` + +Defined in: [types.ts:851](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L851) + +*** + +### ~~type~~ + +```ts +type: "approval-requested"; +``` + +Defined in: [types.ts:846](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L846) diff --git a/docs/reference/interfaces/AudioPart.md b/docs/reference/interfaces/AudioPart.md new file mode 100644 index 00000000..b4e8dc02 --- /dev/null +++ b/docs/reference/interfaces/AudioPart.md @@ -0,0 +1,52 @@ +--- +id: AudioPart +title: AudioPart +--- + +# Interface: AudioPart\ + +Defined in: [types.ts:63](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L63) + +Audio content part for multimodal messages. + +## Type Parameters + +### TMetadata + +`TMetadata` = `unknown` + +Provider-specific metadata type + +## Properties + +### metadata? + +```ts +optional metadata: TMetadata; +``` + +Defined in: [types.ts:68](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L68) + +Provider-specific metadata (e.g., format, sample rate) + +*** + +### source + +```ts +source: ContentPartSource; +``` + +Defined in: [types.ts:66](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L66) + +Source of the audio content + +*** + +### type + +```ts +type: "audio"; +``` + +Defined in: [types.ts:64](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L64) diff --git a/docs/reference/interfaces/BaseEvent.md b/docs/reference/interfaces/BaseEvent.md new file mode 100644 index 00000000..1700628f --- /dev/null +++ b/docs/reference/interfaces/BaseEvent.md @@ -0,0 +1,72 @@ +--- +id: BaseEvent +title: BaseEvent +--- + +# Interface: BaseEvent + +Defined in: [types.ts:553](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L553) + +Base structure for all AG-UI events. +Extends AG-UI spec with TanStack AI additions (model field). + +## Extended by + +- [`RunStartedEvent`](RunStartedEvent.md) +- [`RunFinishedEvent`](RunFinishedEvent.md) +- [`RunErrorEvent`](RunErrorEvent.md) +- [`TextMessageStartEvent`](TextMessageStartEvent.md) +- [`TextMessageContentEvent`](TextMessageContentEvent.md) +- [`TextMessageEndEvent`](TextMessageEndEvent.md) +- [`ToolCallStartEvent`](ToolCallStartEvent.md) +- [`ToolCallArgsEvent`](ToolCallArgsEvent.md) +- [`ToolCallEndEvent`](ToolCallEndEvent.md) +- [`StepStartedEvent`](StepStartedEvent.md) +- [`StepFinishedEvent`](StepFinishedEvent.md) +- [`StateSnapshotEvent`](StateSnapshotEvent.md) +- [`StateDeltaEvent`](StateDeltaEvent.md) +- [`CustomEvent`](CustomEvent.md) + +## Properties + +### model? + +```ts +optional model: string; +``` + +Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) + +TanStack AI addition: Model identifier for multi-model support + +*** + +### rawEvent? + +```ts +optional rawEvent: unknown; +``` + +Defined in: [types.ts:559](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L559) + +Original provider event for debugging/advanced use cases + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) + +*** + +### type + +```ts +type: EventType; +``` + +Defined in: [types.ts:554](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L554) diff --git a/docs/reference/interfaces/ChatCompletionChunk.md b/docs/reference/interfaces/ChatCompletionChunk.md new file mode 100644 index 00000000..65bf19e8 --- /dev/null +++ b/docs/reference/interfaces/ChatCompletionChunk.md @@ -0,0 +1,86 @@ +--- +id: ChatCompletionChunk +title: ChatCompletionChunk +--- + +# Interface: ChatCompletionChunk + +Defined in: [types.ts:874](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L874) + +## Properties + +### content + +```ts +content: string; +``` + +Defined in: [types.ts:877](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L877) + +*** + +### finishReason? + +```ts +optional finishReason: "length" | "stop" | "content_filter" | null; +``` + +Defined in: [types.ts:879](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L879) + +*** + +### id + +```ts +id: string; +``` + +Defined in: [types.ts:875](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L875) + +*** + +### model + +```ts +model: string; +``` + +Defined in: [types.ts:876](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L876) + +*** + +### role? + +```ts +optional role: "assistant"; +``` + +Defined in: [types.ts:878](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L878) + +*** + +### usage? + +```ts +optional usage: object; +``` + +Defined in: [types.ts:880](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L880) + +#### completionTokens + +```ts +completionTokens: number; +``` + +#### promptTokens + +```ts +promptTokens: number; +``` + +#### totalTokens + +```ts +totalTokens: number; +``` diff --git a/docs/reference/interfaces/ChatOptions.md b/docs/reference/interfaces/ChatOptions.md new file mode 100644 index 00000000..9a3efbf8 --- /dev/null +++ b/docs/reference/interfaces/ChatOptions.md @@ -0,0 +1,161 @@ +--- +id: ChatOptions +title: ChatOptions +--- + +# Interface: ChatOptions\ + +Defined in: [types.ts:476](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L476) + +Options passed into the SDK and further piped to the AI provider. + +## Type Parameters + +### TModel + +`TModel` *extends* `string` = `string` + +### TProviderOptionsSuperset + +`TProviderOptionsSuperset` *extends* `Record`\<`string`, `any`\> = `Record`\<`string`, `any`\> + +### TOutput + +`TOutput` *extends* [`ResponseFormat`](ResponseFormat.md)\<`any`\> \| `undefined` = `undefined` + +### TProviderOptionsForModel + +`TProviderOptionsForModel` = `TProviderOptionsSuperset` + +## Properties + +### abortController? + +```ts +optional abortController: AbortController; +``` + +Defined in: [types.ts:509](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L509) + +AbortController for request cancellation. + +Allows you to cancel an in-progress request using an AbortController. +Useful for implementing timeouts or user-initiated cancellations. + +#### Example + +```ts +const abortController = new AbortController(); +setTimeout(() => abortController.abort(), 5000); // Cancel after 5 seconds +await chat({ ..., abortController }); +``` + +#### See + +https://developer.mozilla.org/en-US/docs/Web/API/AbortController + +*** + +### agentLoopStrategy? + +```ts +optional agentLoopStrategy: AgentLoopStrategy; +``` + +Defined in: [types.ts:486](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L486) + +*** + +### conversationId? + +```ts +optional conversationId: string; +``` + +Defined in: [types.ts:495](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L495) + +Conversation ID for correlating client and server-side devtools events. +When provided, server-side events will be linked to the client conversation in devtools. + +*** + +### messages + +```ts +messages: ModelMessage< + | string + | ContentPart[] + | null>[]; +``` + +Defined in: [types.ts:483](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L483) + +*** + +### model + +```ts +model: TModel; +``` + +Defined in: [types.ts:482](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L482) + +*** + +### options? + +```ts +optional options: CommonOptions; +``` + +Defined in: [types.ts:487](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L487) + +*** + +### output? + +```ts +optional output: TOutput; +``` + +Defined in: [types.ts:490](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L490) + +*** + +### providerOptions? + +```ts +optional providerOptions: TProviderOptionsForModel; +``` + +Defined in: [types.ts:488](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L488) + +*** + +### request? + +```ts +optional request: Request | RequestInit; +``` + +Defined in: [types.ts:489](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L489) + +*** + +### systemPrompts? + +```ts +optional systemPrompts: string[]; +``` + +Defined in: [types.ts:485](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L485) + +*** + +### tools? + +```ts +optional tools: Tool>, ZodType>, string>[]; +``` + +Defined in: [types.ts:484](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L484) diff --git a/docs/reference/interfaces/ChunkRecording.md b/docs/reference/interfaces/ChunkRecording.md new file mode 100644 index 00000000..3833f041 --- /dev/null +++ b/docs/reference/interfaces/ChunkRecording.md @@ -0,0 +1,88 @@ +--- +id: ChunkRecording +title: ChunkRecording +--- + +# Interface: ChunkRecording + +Defined in: [stream/types.ts:83](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L83) + +Recording format for replay testing + +## Properties + +### chunks + +```ts +chunks: object[]; +``` + +Defined in: [stream/types.ts:88](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L88) + +#### chunk + +```ts +chunk: StreamChunk; +``` + +#### index + +```ts +index: number; +``` + +#### timestamp + +```ts +timestamp: number; +``` + +*** + +### model? + +```ts +optional model: string; +``` + +Defined in: [stream/types.ts:86](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L86) + +*** + +### provider? + +```ts +optional provider: string; +``` + +Defined in: [stream/types.ts:87](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L87) + +*** + +### result? + +```ts +optional result: ProcessorResult; +``` + +Defined in: [stream/types.ts:93](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L93) + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [stream/types.ts:85](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L85) + +*** + +### version + +```ts +version: "1.0"; +``` + +Defined in: [stream/types.ts:84](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L84) diff --git a/docs/reference/interfaces/ChunkStrategy.md b/docs/reference/interfaces/ChunkStrategy.md new file mode 100644 index 00000000..c9b06168 --- /dev/null +++ b/docs/reference/interfaces/ChunkStrategy.md @@ -0,0 +1,58 @@ +--- +id: ChunkStrategy +title: ChunkStrategy +--- + +# Interface: ChunkStrategy + +Defined in: [stream/types.ts:43](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L43) + +Strategy for determining when to emit text updates + +## Properties + +### reset()? + +```ts +optional reset: () => void; +``` + +Defined in: [stream/types.ts:55](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L55) + +Optional: Reset strategy state (called when streaming starts) + +#### Returns + +`void` + +*** + +### shouldEmit() + +```ts +shouldEmit: (chunk, accumulated) => boolean; +``` + +Defined in: [stream/types.ts:50](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L50) + +Called for each text chunk received + +#### Parameters + +##### chunk + +`string` + +The new chunk of text (delta) + +##### accumulated + +`string` + +All text accumulated so far + +#### Returns + +`boolean` + +true if an update should be emitted now diff --git a/docs/reference/interfaces/ClientTool.md b/docs/reference/interfaces/ClientTool.md new file mode 100644 index 00000000..819d729d --- /dev/null +++ b/docs/reference/interfaces/ClientTool.md @@ -0,0 +1,114 @@ +--- +id: ClientTool +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) + +Marker type for client-side tools + +## Type Parameters + +### TInput + +`TInput` *extends* `z.ZodType` = `z.ZodType` + +### TOutput + +`TOutput` *extends* `z.ZodType` = `z.ZodType` + +### TName + +`TName` *extends* `string` = `string` + +## Properties + +### \_\_toolSide + +```ts +__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) + +*** + +### description + +```ts +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) + +*** + +### execute()? + +```ts +optional execute: (args) => output | Promise>; +``` + +Defined in: [tools/tool-definition.ts:30](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L30) + +#### Parameters + +##### args + +`output`\<`TInput`\> + +#### Returns + +`output`\<`TOutput`\> \| `Promise`\<`output`\<`TOutput`\>\> + +*** + +### inputSchema? + +```ts +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) + +*** + +### metadata? + +```ts +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) + +*** + +### name + +```ts +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) + +*** + +### needsApproval? + +```ts +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) + +*** + +### outputSchema? + +```ts +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) diff --git a/docs/reference/interfaces/ContentPartSource.md b/docs/reference/interfaces/ContentPartSource.md new file mode 100644 index 00000000..54c2839c --- /dev/null +++ b/docs/reference/interfaces/ContentPartSource.md @@ -0,0 +1,39 @@ +--- +id: ContentPartSource +title: ContentPartSource +--- + +# Interface: ContentPartSource + +Defined in: [types.ts:32](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L32) + +Source specification for multimodal content. +Supports both inline data (base64) and URL-based content. + +## Properties + +### type + +```ts +type: "data" | "url"; +``` + +Defined in: [types.ts:38](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L38) + +The type of source: +- 'data': Inline data (typically base64 encoded) +- 'url': URL reference to the content + +*** + +### value + +```ts +value: string; +``` + +Defined in: [types.ts:44](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L44) + +The actual content value: +- For 'data': base64-encoded string +- For 'url': HTTP(S) URL or data URI diff --git a/docs/reference/interfaces/ContentStreamChunk.md b/docs/reference/interfaces/ContentStreamChunk.md new file mode 100644 index 00000000..e0b00834 --- /dev/null +++ b/docs/reference/interfaces/ContentStreamChunk.md @@ -0,0 +1,88 @@ +--- +id: ContentStreamChunk +title: ContentStreamChunk +--- + +# ~~Interface: ContentStreamChunk~~ + +Defined in: [types.ts:761](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L761) + +## Deprecated + +Use TextMessageContentEvent instead + +## Properties + +### ~~content~~ + +```ts +content: string; +``` + +Defined in: [types.ts:769](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L769) + +Full accumulated content so far + +*** + +### ~~delta~~ + +```ts +delta: string; +``` + +Defined in: [types.ts:767](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L767) + +Incremental text delta + +*** + +### ~~id~~ + +```ts +id: string; +``` + +Defined in: [types.ts:763](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L763) + +*** + +### ~~model~~ + +```ts +model: string; +``` + +Defined in: [types.ts:764](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L764) + +*** + +### ~~role?~~ + +```ts +optional role: "assistant"; +``` + +Defined in: [types.ts:771](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L771) + +Role of the message + +*** + +### ~~timestamp~~ + +```ts +timestamp: number; +``` + +Defined in: [types.ts:765](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L765) + +*** + +### ~~type~~ + +```ts +type: "content"; +``` + +Defined in: [types.ts:762](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L762) diff --git a/docs/reference/interfaces/CustomEvent.md b/docs/reference/interfaces/CustomEvent.md new file mode 100644 index 00000000..62da01ab --- /dev/null +++ b/docs/reference/interfaces/CustomEvent.md @@ -0,0 +1,95 @@ +--- +id: CustomEvent +title: CustomEvent +--- + +# Interface: CustomEvent + +Defined in: [types.ts:711](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L711) + +Custom event for extensibility. +Used for features not covered by standard AG-UI events (e.g., approval flows). + +## Extends + +- [`BaseEvent`](BaseEvent.md) + +## Properties + +### model? + +```ts +optional model: string; +``` + +Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) + +TanStack AI addition: Model identifier for multi-model support + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`model`](BaseEvent.md#model) + +*** + +### name + +```ts +name: string; +``` + +Defined in: [types.ts:713](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L713) + +*** + +### rawEvent? + +```ts +optional rawEvent: unknown; +``` + +Defined in: [types.ts:559](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L559) + +Original provider event for debugging/advanced use cases + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`rawEvent`](BaseEvent.md#rawevent) + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`timestamp`](BaseEvent.md#timestamp) + +*** + +### type + +```ts +type: "CUSTOM"; +``` + +Defined in: [types.ts:712](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L712) + +#### Overrides + +[`BaseEvent`](BaseEvent.md).[`type`](BaseEvent.md#type) + +*** + +### value + +```ts +value: unknown; +``` + +Defined in: [types.ts:714](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L714) diff --git a/docs/reference/interfaces/DefaultMessageMetadataByModality.md b/docs/reference/interfaces/DefaultMessageMetadataByModality.md new file mode 100644 index 00000000..bf3e6224 --- /dev/null +++ b/docs/reference/interfaces/DefaultMessageMetadataByModality.md @@ -0,0 +1,61 @@ +--- +id: DefaultMessageMetadataByModality +title: DefaultMessageMetadataByModality +--- + +# Interface: DefaultMessageMetadataByModality + +Defined in: [types.ts:926](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L926) + +Default metadata type for adapters that don't define custom metadata. +Uses unknown for all modalities. + +## Properties + +### audio + +```ts +audio: unknown; +``` + +Defined in: [types.ts:929](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L929) + +*** + +### document + +```ts +document: unknown; +``` + +Defined in: [types.ts:931](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L931) + +*** + +### image + +```ts +image: unknown; +``` + +Defined in: [types.ts:928](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L928) + +*** + +### text + +```ts +text: unknown; +``` + +Defined in: [types.ts:927](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L927) + +*** + +### video + +```ts +video: unknown; +``` + +Defined in: [types.ts:930](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L930) diff --git a/docs/reference/interfaces/DocumentPart.md b/docs/reference/interfaces/DocumentPart.md new file mode 100644 index 00000000..3ee9232e --- /dev/null +++ b/docs/reference/interfaces/DocumentPart.md @@ -0,0 +1,52 @@ +--- +id: DocumentPart +title: DocumentPart +--- + +# Interface: DocumentPart\ + +Defined in: [types.ts:87](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L87) + +Document content part for multimodal messages (e.g., PDFs). + +## Type Parameters + +### TMetadata + +`TMetadata` = `unknown` + +Provider-specific metadata type (e.g., Anthropic's media_type) + +## Properties + +### metadata? + +```ts +optional metadata: TMetadata; +``` + +Defined in: [types.ts:92](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L92) + +Provider-specific metadata (e.g., media_type for PDFs) + +*** + +### source + +```ts +source: ContentPartSource; +``` + +Defined in: [types.ts:90](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L90) + +Source of the document content + +*** + +### type + +```ts +type: "document"; +``` + +Defined in: [types.ts:88](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L88) diff --git a/docs/reference/interfaces/DoneStreamChunk.md b/docs/reference/interfaces/DoneStreamChunk.md new file mode 100644 index 00000000..d9033366 --- /dev/null +++ b/docs/reference/interfaces/DoneStreamChunk.md @@ -0,0 +1,90 @@ +--- +id: DoneStreamChunk +title: DoneStreamChunk +--- + +# ~~Interface: DoneStreamChunk~~ + +Defined in: [types.ts:777](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L777) + +## Deprecated + +Use RunFinishedEvent instead + +## Properties + +### ~~finishReason?~~ + +```ts +optional finishReason: "length" | "stop" | "content_filter" | "tool_calls" | null; +``` + +Defined in: [types.ts:782](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L782) + +*** + +### ~~id~~ + +```ts +id: string; +``` + +Defined in: [types.ts:779](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L779) + +*** + +### ~~model~~ + +```ts +model: string; +``` + +Defined in: [types.ts:780](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L780) + +*** + +### ~~timestamp~~ + +```ts +timestamp: number; +``` + +Defined in: [types.ts:781](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L781) + +*** + +### ~~type~~ + +```ts +type: "done"; +``` + +Defined in: [types.ts:778](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L778) + +*** + +### ~~usage?~~ + +```ts +optional usage: object; +``` + +Defined in: [types.ts:783](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L783) + +#### ~~completionTokens~~ + +```ts +completionTokens: number; +``` + +#### ~~promptTokens~~ + +```ts +promptTokens: number; +``` + +#### ~~totalTokens~~ + +```ts +totalTokens: number; +``` diff --git a/docs/reference/interfaces/EmbeddingOptions.md b/docs/reference/interfaces/EmbeddingOptions.md new file mode 100644 index 00000000..a938df25 --- /dev/null +++ b/docs/reference/interfaces/EmbeddingOptions.md @@ -0,0 +1,38 @@ +--- +id: EmbeddingOptions +title: EmbeddingOptions +--- + +# Interface: EmbeddingOptions + +Defined in: [types.ts:906](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L906) + +## Properties + +### dimensions? + +```ts +optional dimensions: number; +``` + +Defined in: [types.ts:909](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L909) + +*** + +### input + +```ts +input: string | string[]; +``` + +Defined in: [types.ts:908](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L908) + +*** + +### model + +```ts +model: string; +``` + +Defined in: [types.ts:907](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L907) diff --git a/docs/reference/interfaces/EmbeddingResult.md b/docs/reference/interfaces/EmbeddingResult.md new file mode 100644 index 00000000..40b046ce --- /dev/null +++ b/docs/reference/interfaces/EmbeddingResult.md @@ -0,0 +1,60 @@ +--- +id: EmbeddingResult +title: EmbeddingResult +--- + +# Interface: EmbeddingResult + +Defined in: [types.ts:912](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L912) + +## Properties + +### embeddings + +```ts +embeddings: number[][]; +``` + +Defined in: [types.ts:915](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L915) + +*** + +### id + +```ts +id: string; +``` + +Defined in: [types.ts:913](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L913) + +*** + +### model + +```ts +model: string; +``` + +Defined in: [types.ts:914](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L914) + +*** + +### usage + +```ts +usage: object; +``` + +Defined in: [types.ts:916](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L916) + +#### promptTokens + +```ts +promptTokens: number; +``` + +#### totalTokens + +```ts +totalTokens: number; +``` diff --git a/docs/reference/interfaces/ErrorStreamChunk.md b/docs/reference/interfaces/ErrorStreamChunk.md new file mode 100644 index 00000000..1cfc0fb4 --- /dev/null +++ b/docs/reference/interfaces/ErrorStreamChunk.md @@ -0,0 +1,77 @@ +--- +id: ErrorStreamChunk +title: ErrorStreamChunk +--- + +# ~~Interface: ErrorStreamChunk~~ + +Defined in: [types.ts:793](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L793) + +## Deprecated + +Use RunErrorEvent instead + +## Properties + +### ~~code?~~ + +```ts +optional code: string; +``` + +Defined in: [types.ts:799](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L799) + +*** + +### ~~error~~ + +```ts +error: + | string + | { + code?: string; + message: string; +}; +``` + +Defined in: [types.ts:798](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L798) + +*** + +### ~~id~~ + +```ts +id: string; +``` + +Defined in: [types.ts:795](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L795) + +*** + +### ~~model~~ + +```ts +model: string; +``` + +Defined in: [types.ts:796](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L796) + +*** + +### ~~timestamp~~ + +```ts +timestamp: number; +``` + +Defined in: [types.ts:797](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L797) + +*** + +### ~~type~~ + +```ts +type: "error"; +``` + +Defined in: [types.ts:794](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L794) diff --git a/docs/reference/interfaces/ImagePart.md b/docs/reference/interfaces/ImagePart.md new file mode 100644 index 00000000..2111598b --- /dev/null +++ b/docs/reference/interfaces/ImagePart.md @@ -0,0 +1,52 @@ +--- +id: ImagePart +title: ImagePart +--- + +# Interface: ImagePart\ + +Defined in: [types.ts:51](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L51) + +Image content part for multimodal messages. + +## Type Parameters + +### TMetadata + +`TMetadata` = `unknown` + +Provider-specific metadata type (e.g., OpenAI's detail level) + +## Properties + +### metadata? + +```ts +optional metadata: TMetadata; +``` + +Defined in: [types.ts:56](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L56) + +Provider-specific metadata (e.g., OpenAI's detail: 'auto' | 'low' | 'high') + +*** + +### source + +```ts +source: ContentPartSource; +``` + +Defined in: [types.ts:54](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L54) + +Source of the image content + +*** + +### type + +```ts +type: "image"; +``` + +Defined in: [types.ts:52](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L52) diff --git a/docs/reference/interfaces/InternalToolCallState.md b/docs/reference/interfaces/InternalToolCallState.md new file mode 100644 index 00000000..e8607bce --- /dev/null +++ b/docs/reference/interfaces/InternalToolCallState.md @@ -0,0 +1,70 @@ +--- +id: InternalToolCallState +title: InternalToolCallState +--- + +# Interface: InternalToolCallState + +Defined in: [stream/types.ts:31](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L31) + +Internal state for a tool call being tracked + +## Properties + +### arguments + +```ts +arguments: string; +``` + +Defined in: [stream/types.ts:34](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L34) + +*** + +### id + +```ts +id: string; +``` + +Defined in: [stream/types.ts:32](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L32) + +*** + +### index + +```ts +index: number; +``` + +Defined in: [stream/types.ts:37](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L37) + +*** + +### name + +```ts +name: string; +``` + +Defined in: [stream/types.ts:33](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L33) + +*** + +### parsedArguments? + +```ts +optional parsedArguments: any; +``` + +Defined in: [stream/types.ts:36](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L36) + +*** + +### state + +```ts +state: ToolCallState; +``` + +Defined in: [stream/types.ts:35](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L35) diff --git a/docs/reference/interfaces/JSONParser.md b/docs/reference/interfaces/JSONParser.md new file mode 100644 index 00000000..228cd1a2 --- /dev/null +++ b/docs/reference/interfaces/JSONParser.md @@ -0,0 +1,36 @@ +--- +id: JSONParser +title: JSONParser +--- + +# Interface: JSONParser + +Defined in: [stream/json-parser.ts:12](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/json-parser.ts#L12) + +JSON Parser interface - allows for custom parser implementations + +## Properties + +### parse() + +```ts +parse: (jsonString) => any; +``` + +Defined in: [stream/json-parser.ts:18](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/json-parser.ts#L18) + +Parse a JSON string (may be incomplete/partial) + +#### Parameters + +##### jsonString + +`string` + +The JSON string to parse + +#### Returns + +`any` + +The parsed object, or undefined if parsing fails diff --git a/docs/reference/interfaces/ModelMessage.md b/docs/reference/interfaces/ModelMessage.md new file mode 100644 index 00000000..4495276a --- /dev/null +++ b/docs/reference/interfaces/ModelMessage.md @@ -0,0 +1,64 @@ +--- +id: ModelMessage +title: ModelMessage +--- + +# Interface: ModelMessage\ + +Defined in: [types.ts:163](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L163) + +## Type Parameters + +### TContent + +`TContent` *extends* `string` \| `null` \| [`ContentPart`](../type-aliases/ContentPart.md)[] = `string` \| `null` \| [`ContentPart`](../type-aliases/ContentPart.md)[] + +## Properties + +### content + +```ts +content: TContent; +``` + +Defined in: [types.ts:170](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L170) + +*** + +### name? + +```ts +optional name: string; +``` + +Defined in: [types.ts:171](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L171) + +*** + +### role + +```ts +role: "user" | "assistant" | "tool"; +``` + +Defined in: [types.ts:169](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L169) + +*** + +### toolCallId? + +```ts +optional toolCallId: string; +``` + +Defined in: [types.ts:173](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L173) + +*** + +### toolCalls? + +```ts +optional toolCalls: ToolCall[]; +``` + +Defined in: [types.ts:172](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L172) diff --git a/docs/reference/interfaces/ProcessorResult.md b/docs/reference/interfaces/ProcessorResult.md new file mode 100644 index 00000000..9fb65250 --- /dev/null +++ b/docs/reference/interfaces/ProcessorResult.md @@ -0,0 +1,50 @@ +--- +id: ProcessorResult +title: ProcessorResult +--- + +# Interface: ProcessorResult + +Defined in: [stream/types.ts:61](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L61) + +Result from processing a stream + +## Properties + +### content + +```ts +content: string; +``` + +Defined in: [stream/types.ts:62](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L62) + +*** + +### finishReason? + +```ts +optional finishReason: string | null; +``` + +Defined in: [stream/types.ts:65](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L65) + +*** + +### thinking? + +```ts +optional thinking: string; +``` + +Defined in: [stream/types.ts:63](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L63) + +*** + +### toolCalls? + +```ts +optional toolCalls: ToolCall[]; +``` + +Defined in: [stream/types.ts:64](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L64) diff --git a/docs/reference/interfaces/ProcessorState.md b/docs/reference/interfaces/ProcessorState.md new file mode 100644 index 00000000..7ef5bba6 --- /dev/null +++ b/docs/reference/interfaces/ProcessorState.md @@ -0,0 +1,70 @@ +--- +id: ProcessorState +title: ProcessorState +--- + +# Interface: ProcessorState + +Defined in: [stream/types.ts:71](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L71) + +Current state of the processor + +## Properties + +### content + +```ts +content: string; +``` + +Defined in: [stream/types.ts:72](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L72) + +*** + +### done + +```ts +done: boolean; +``` + +Defined in: [stream/types.ts:77](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L77) + +*** + +### finishReason + +```ts +finishReason: string | null; +``` + +Defined in: [stream/types.ts:76](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L76) + +*** + +### thinking + +```ts +thinking: string; +``` + +Defined in: [stream/types.ts:73](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L73) + +*** + +### toolCallOrder + +```ts +toolCallOrder: string[]; +``` + +Defined in: [stream/types.ts:75](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L75) + +*** + +### toolCalls + +```ts +toolCalls: Map; +``` + +Defined in: [stream/types.ts:74](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L74) diff --git a/docs/reference/interfaces/ResponseFormat.md b/docs/reference/interfaces/ResponseFormat.md new file mode 100644 index 00000000..2d5f2962 --- /dev/null +++ b/docs/reference/interfaces/ResponseFormat.md @@ -0,0 +1,151 @@ +--- +id: ResponseFormat +title: ResponseFormat +--- + +# Interface: ResponseFormat\ + +Defined in: [types.ts:366](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L366) + +Structured output format specification. + +Constrains the model's output to match a specific JSON structure. +Useful for extracting structured data, form filling, or ensuring consistent response formats. + +## See + + - https://platform.openai.com/docs/guides/structured-outputs + - https://sdk.vercel.ai/docs/ai-sdk-core/structured-outputs + +## Type Parameters + +### TData + +`TData` = `any` + +TypeScript type of the expected data structure (for type safety) + +## Properties + +### \_\_data? + +```ts +optional __data: TData; +``` + +Defined in: [types.ts:444](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L444) + +**`Internal`** + +Type-only property to carry the inferred data type. + +This is never set at runtime - it only exists for TypeScript type inference. +Allows the SDK to know what type to expect when parsing the response. + +*** + +### json\_schema? + +```ts +optional json_schema: object; +``` + +Defined in: [types.ts:383](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L383) + +JSON schema specification (required when type is "json_schema"). + +Defines the exact structure the model's output must conform to. +OpenAI's structured outputs will guarantee the output matches this schema. + +#### description? + +```ts +optional description: string; +``` + +Optional description of what the schema represents. + +Helps document the purpose of this structured output. + +##### Example + +```ts +"User profile information including name, email, and preferences" +``` + +#### name + +```ts +name: string; +``` + +Unique name for the schema. + +Used to identify the schema in logs and debugging. +Should be descriptive (e.g., "user_profile", "search_results"). + +#### schema + +```ts +schema: Record; +``` + +JSON Schema definition for the expected output structure. + +Must be a valid JSON Schema (draft 2020-12 or compatible). +The model's output will be validated against this schema. + +##### See + +https://json-schema.org/ + +##### Example + +```ts +{ + * type: "object", + * properties: { + * name: { type: "string" }, + * age: { type: "number" }, + * email: { type: "string", format: "email" } + * }, + * required: ["name", "email"], + * additionalProperties: false + * } +``` + +#### strict? + +```ts +optional strict: boolean; +``` + +Whether to enforce strict schema validation. + +When true (recommended), the model guarantees output will match the schema exactly. +When false, the model will "best effort" match the schema. + +Default: true (for providers that support it) + +##### See + +https://platform.openai.com/docs/guides/structured-outputs#strict-mode + +*** + +### type + +```ts +type: "json_object" | "json_schema"; +``` + +Defined in: [types.ts:375](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L375) + +Type of structured output. + +- "json_object": Forces the model to output valid JSON (any structure) +- "json_schema": Validates output against a provided JSON Schema (strict structure) + +#### See + +https://platform.openai.com/docs/api-reference/chat/create#chat-create-response_format diff --git a/docs/reference/interfaces/RunErrorEvent.md b/docs/reference/interfaces/RunErrorEvent.md new file mode 100644 index 00000000..3b0027f1 --- /dev/null +++ b/docs/reference/interfaces/RunErrorEvent.md @@ -0,0 +1,106 @@ +--- +id: RunErrorEvent +title: RunErrorEvent +--- + +# Interface: RunErrorEvent + +Defined in: [types.ts:588](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L588) + +Emitted when an error occurs during a run. + +## Extends + +- [`BaseEvent`](BaseEvent.md) + +## Properties + +### error + +```ts +error: object; +``` + +Defined in: [types.ts:591](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L591) + +#### code? + +```ts +optional code: string; +``` + +#### message + +```ts +message: string; +``` + +*** + +### model? + +```ts +optional model: string; +``` + +Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) + +TanStack AI addition: Model identifier for multi-model support + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`model`](BaseEvent.md#model) + +*** + +### rawEvent? + +```ts +optional rawEvent: unknown; +``` + +Defined in: [types.ts:559](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L559) + +Original provider event for debugging/advanced use cases + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`rawEvent`](BaseEvent.md#rawevent) + +*** + +### runId? + +```ts +optional runId: string; +``` + +Defined in: [types.ts:590](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L590) + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`timestamp`](BaseEvent.md#timestamp) + +*** + +### type + +```ts +type: "RUN_ERROR"; +``` + +Defined in: [types.ts:589](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L589) + +#### Overrides + +[`BaseEvent`](BaseEvent.md).[`type`](BaseEvent.md#type) diff --git a/docs/reference/interfaces/RunFinishedEvent.md b/docs/reference/interfaces/RunFinishedEvent.md new file mode 100644 index 00000000..97e59f83 --- /dev/null +++ b/docs/reference/interfaces/RunFinishedEvent.md @@ -0,0 +1,122 @@ +--- +id: RunFinishedEvent +title: RunFinishedEvent +--- + +# Interface: RunFinishedEvent + +Defined in: [types.ts:574](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L574) + +Emitted when a run completes successfully. + +## Extends + +- [`BaseEvent`](BaseEvent.md) + +## Properties + +### finishReason + +```ts +finishReason: "length" | "stop" | "content_filter" | "tool_calls" | null; +``` + +Defined in: [types.ts:577](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L577) + +*** + +### model? + +```ts +optional model: string; +``` + +Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) + +TanStack AI addition: Model identifier for multi-model support + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`model`](BaseEvent.md#model) + +*** + +### rawEvent? + +```ts +optional rawEvent: unknown; +``` + +Defined in: [types.ts:559](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L559) + +Original provider event for debugging/advanced use cases + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`rawEvent`](BaseEvent.md#rawevent) + +*** + +### runId + +```ts +runId: string; +``` + +Defined in: [types.ts:576](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L576) + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`timestamp`](BaseEvent.md#timestamp) + +*** + +### type + +```ts +type: "RUN_FINISHED"; +``` + +Defined in: [types.ts:575](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L575) + +#### Overrides + +[`BaseEvent`](BaseEvent.md).[`type`](BaseEvent.md#type) + +*** + +### usage? + +```ts +optional usage: object; +``` + +Defined in: [types.ts:578](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L578) + +#### completionTokens + +```ts +completionTokens: number; +``` + +#### promptTokens + +```ts +promptTokens: number; +``` + +#### totalTokens + +```ts +totalTokens: number; +``` diff --git a/docs/reference/interfaces/RunStartedEvent.md b/docs/reference/interfaces/RunStartedEvent.md new file mode 100644 index 00000000..f03dc122 --- /dev/null +++ b/docs/reference/interfaces/RunStartedEvent.md @@ -0,0 +1,94 @@ +--- +id: RunStartedEvent +title: RunStartedEvent +--- + +# Interface: RunStartedEvent + +Defined in: [types.ts:565](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L565) + +Emitted when a run starts. + +## Extends + +- [`BaseEvent`](BaseEvent.md) + +## Properties + +### model? + +```ts +optional model: string; +``` + +Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) + +TanStack AI addition: Model identifier for multi-model support + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`model`](BaseEvent.md#model) + +*** + +### rawEvent? + +```ts +optional rawEvent: unknown; +``` + +Defined in: [types.ts:559](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L559) + +Original provider event for debugging/advanced use cases + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`rawEvent`](BaseEvent.md#rawevent) + +*** + +### runId + +```ts +runId: string; +``` + +Defined in: [types.ts:567](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L567) + +*** + +### threadId? + +```ts +optional threadId: string; +``` + +Defined in: [types.ts:568](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L568) + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`timestamp`](BaseEvent.md#timestamp) + +*** + +### type + +```ts +type: "RUN_STARTED"; +``` + +Defined in: [types.ts:566](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L566) + +#### Overrides + +[`BaseEvent`](BaseEvent.md).[`type`](BaseEvent.md#type) diff --git a/docs/reference/interfaces/ServerTool.md b/docs/reference/interfaces/ServerTool.md new file mode 100644 index 00000000..7dc40927 --- /dev/null +++ b/docs/reference/interfaces/ServerTool.md @@ -0,0 +1,231 @@ +--- +id: ServerTool +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) + +Marker type for server-side tools + +## Extends + +- [`Tool`](Tool.md)\<`TInput`, `TOutput`, `TName`\> + +## Type Parameters + +### TInput + +`TInput` *extends* `z.ZodType` = `z.ZodType` + +### TOutput + +`TOutput` *extends* `z.ZodType` = `z.ZodType` + +### TName + +`TName` *extends* `string` = `string` + +## Properties + +### \_\_toolSide + +```ts +__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) + +*** + +### description + +```ts +description: string; +``` + +Defined in: [types.ts:286](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L286) + +Clear description of what the tool does. + +This is crucial - the model uses this to decide when to call the tool. +Be specific about what the tool does, what parameters it needs, and what it returns. + +#### Example + +```ts +"Get the current weather in a given location. Returns temperature, conditions, and forecast." +``` + +#### Inherited from + +[`Tool`](Tool.md).[`description`](Tool.md#description) + +*** + +### execute()? + +```ts +optional execute: (args) => any; +``` + +Defined in: [types.ts:342](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L342) + +Optional function to execute when the model calls this tool. + +If provided, the SDK will automatically execute the function with the model's arguments +and feed the result back to the model. This enables autonomous tool use loops. + +Can return any value - will be automatically stringified if needed. + +#### Parameters + +##### args + +`any` + +The arguments parsed from the model's tool call (validated against inputSchema) + +#### Returns + +`any` + +Result to send back to the model (validated against outputSchema if provided) + +#### Example + +```ts +execute: async (args) => { + const weather = await fetchWeather(args.location); + return weather; // Can return object or string +} +``` + +#### Inherited from + +[`Tool`](Tool.md).[`execute`](Tool.md#execute) + +*** + +### inputSchema? + +```ts +optional inputSchema: TInput; +``` + +Defined in: [types.ts:305](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L305) + +Zod 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/ + +#### Example + +```ts +import { z } from 'zod'; + +z.object({ + location: z.string().describe("City name or coordinates"), + unit: z.enum(["celsius", "fahrenheit"]).optional() +}) +``` + +#### Inherited from + +[`Tool`](Tool.md).[`inputSchema`](Tool.md#inputschema) + +*** + +### metadata? + +```ts +optional metadata: Record; +``` + +Defined in: [types.ts:348](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L348) + +Additional metadata for adapters or custom extensions + +#### Inherited from + +[`Tool`](Tool.md).[`metadata`](Tool.md#metadata) + +*** + +### name + +```ts +name: TName; +``` + +Defined in: [types.ts:276](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L276) + +Unique name of the tool (used by the model to call it). + +Should be descriptive and follow naming conventions (e.g., snake_case or camelCase). +Must be unique within the tools array. + +#### Example + +```ts +"get_weather", "search_database", "sendEmail" +``` + +#### Inherited from + +[`Tool`](Tool.md).[`name`](Tool.md#name) + +*** + +### needsApproval? + +```ts +optional needsApproval: boolean; +``` + +Defined in: [types.ts:345](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L345) + +If true, tool execution requires user approval before running. Works with both server and client tools. + +#### Inherited from + +[`Tool`](Tool.md).[`needsApproval`](Tool.md#needsapproval) + +*** + +### outputSchema? + +```ts +optional outputSchema: TOutput; +``` + +Defined in: [types.ts:323](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L323) + +Optional Zod 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 +and ensures consistent output formatting. + +Note: This is client-side validation only - not sent to LLM providers. + +#### Example + +```ts +z.object({ + temperature: z.number(), + conditions: z.string(), + forecast: z.array(z.string()).optional() +}) +``` + +#### Inherited from + +[`Tool`](Tool.md).[`outputSchema`](Tool.md#outputschema) diff --git a/docs/reference/interfaces/StateDeltaEvent.md b/docs/reference/interfaces/StateDeltaEvent.md new file mode 100644 index 00000000..834955bc --- /dev/null +++ b/docs/reference/interfaces/StateDeltaEvent.md @@ -0,0 +1,102 @@ +--- +id: StateDeltaEvent +title: StateDeltaEvent +--- + +# Interface: StateDeltaEvent + +Defined in: [types.ts:698](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L698) + +Emitted for incremental state updates. + +## Extends + +- [`BaseEvent`](BaseEvent.md) + +## Properties + +### delta + +```ts +delta: object[]; +``` + +Defined in: [types.ts:700](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L700) + +#### op + +```ts +op: "add" | "remove" | "replace"; +``` + +#### path + +```ts +path: string; +``` + +#### value? + +```ts +optional value: unknown; +``` + +*** + +### model? + +```ts +optional model: string; +``` + +Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) + +TanStack AI addition: Model identifier for multi-model support + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`model`](BaseEvent.md#model) + +*** + +### rawEvent? + +```ts +optional rawEvent: unknown; +``` + +Defined in: [types.ts:559](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L559) + +Original provider event for debugging/advanced use cases + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`rawEvent`](BaseEvent.md#rawevent) + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`timestamp`](BaseEvent.md#timestamp) + +*** + +### type + +```ts +type: "STATE_DELTA"; +``` + +Defined in: [types.ts:699](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L699) + +#### Overrides + +[`BaseEvent`](BaseEvent.md).[`type`](BaseEvent.md#type) diff --git a/docs/reference/interfaces/StateSnapshotEvent.md b/docs/reference/interfaces/StateSnapshotEvent.md new file mode 100644 index 00000000..6dc93330 --- /dev/null +++ b/docs/reference/interfaces/StateSnapshotEvent.md @@ -0,0 +1,84 @@ +--- +id: StateSnapshotEvent +title: StateSnapshotEvent +--- + +# Interface: StateSnapshotEvent + +Defined in: [types.ts:690](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L690) + +Emitted for full state synchronization. + +## Extends + +- [`BaseEvent`](BaseEvent.md) + +## Properties + +### model? + +```ts +optional model: string; +``` + +Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) + +TanStack AI addition: Model identifier for multi-model support + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`model`](BaseEvent.md#model) + +*** + +### rawEvent? + +```ts +optional rawEvent: unknown; +``` + +Defined in: [types.ts:559](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L559) + +Original provider event for debugging/advanced use cases + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`rawEvent`](BaseEvent.md#rawevent) + +*** + +### state + +```ts +state: Record; +``` + +Defined in: [types.ts:692](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L692) + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`timestamp`](BaseEvent.md#timestamp) + +*** + +### type + +```ts +type: "STATE_SNAPSHOT"; +``` + +Defined in: [types.ts:691](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L691) + +#### Overrides + +[`BaseEvent`](BaseEvent.md).[`type`](BaseEvent.md#type) diff --git a/docs/reference/interfaces/StepFinishedEvent.md b/docs/reference/interfaces/StepFinishedEvent.md new file mode 100644 index 00000000..afd4f6bc --- /dev/null +++ b/docs/reference/interfaces/StepFinishedEvent.md @@ -0,0 +1,108 @@ +--- +id: StepFinishedEvent +title: StepFinishedEvent +--- + +# Interface: StepFinishedEvent + +Defined in: [types.ts:678](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L678) + +Emitted when a reasoning/thinking step completes or streams content. + +## Extends + +- [`BaseEvent`](BaseEvent.md) + +## Properties + +### content + +```ts +content: string; +``` + +Defined in: [types.ts:684](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L684) + +Full accumulated thinking content + +*** + +### delta? + +```ts +optional delta: string; +``` + +Defined in: [types.ts:682](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L682) + +Incremental thinking token + +*** + +### model? + +```ts +optional model: string; +``` + +Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) + +TanStack AI addition: Model identifier for multi-model support + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`model`](BaseEvent.md#model) + +*** + +### rawEvent? + +```ts +optional rawEvent: unknown; +``` + +Defined in: [types.ts:559](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L559) + +Original provider event for debugging/advanced use cases + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`rawEvent`](BaseEvent.md#rawevent) + +*** + +### stepId + +```ts +stepId: string; +``` + +Defined in: [types.ts:680](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L680) + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`timestamp`](BaseEvent.md#timestamp) + +*** + +### type + +```ts +type: "STEP_FINISHED"; +``` + +Defined in: [types.ts:679](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L679) + +#### Overrides + +[`BaseEvent`](BaseEvent.md).[`type`](BaseEvent.md#type) diff --git a/docs/reference/interfaces/StepStartedEvent.md b/docs/reference/interfaces/StepStartedEvent.md new file mode 100644 index 00000000..ff111051 --- /dev/null +++ b/docs/reference/interfaces/StepStartedEvent.md @@ -0,0 +1,94 @@ +--- +id: StepStartedEvent +title: StepStartedEvent +--- + +# Interface: StepStartedEvent + +Defined in: [types.ts:669](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L669) + +Emitted when a reasoning/thinking step starts. + +## Extends + +- [`BaseEvent`](BaseEvent.md) + +## Properties + +### model? + +```ts +optional model: string; +``` + +Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) + +TanStack AI addition: Model identifier for multi-model support + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`model`](BaseEvent.md#model) + +*** + +### rawEvent? + +```ts +optional rawEvent: unknown; +``` + +Defined in: [types.ts:559](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L559) + +Original provider event for debugging/advanced use cases + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`rawEvent`](BaseEvent.md#rawevent) + +*** + +### stepId + +```ts +stepId: string; +``` + +Defined in: [types.ts:671](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L671) + +*** + +### stepType + +```ts +stepType: "thinking" | "reasoning" | "planning"; +``` + +Defined in: [types.ts:672](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L672) + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`timestamp`](BaseEvent.md#timestamp) + +*** + +### type + +```ts +type: "STEP_STARTED"; +``` + +Defined in: [types.ts:670](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L670) + +#### Overrides + +[`BaseEvent`](BaseEvent.md).[`type`](BaseEvent.md#type) diff --git a/docs/reference/interfaces/StreamProcessorEvents.md b/docs/reference/interfaces/StreamProcessorEvents.md new file mode 100644 index 00000000..313e1987 --- /dev/null +++ b/docs/reference/interfaces/StreamProcessorEvents.md @@ -0,0 +1,228 @@ +--- +id: StreamProcessorEvents +title: StreamProcessorEvents +--- + +# Interface: StreamProcessorEvents + +Defined in: [stream/processor.ts:51](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L51) + +Events emitted by the StreamProcessor + +## Properties + +### onApprovalRequest()? + +```ts +optional onApprovalRequest: (args) => void; +``` + +Defined in: [stream/processor.ts:66](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L66) + +#### Parameters + +##### args + +###### approvalId + +`string` + +###### input + +`any` + +###### toolCallId + +`string` + +###### toolName + +`string` + +#### Returns + +`void` + +*** + +### onError()? + +```ts +optional onError: (error) => void; +``` + +Defined in: [stream/processor.ts:58](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L58) + +#### Parameters + +##### error + +`Error` + +#### Returns + +`void` + +*** + +### onMessagesChange()? + +```ts +optional onMessagesChange: (messages) => void; +``` + +Defined in: [stream/processor.ts:53](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L53) + +#### Parameters + +##### messages + +[`UIMessage`](UIMessage.md)[] + +#### Returns + +`void` + +*** + +### onStreamEnd()? + +```ts +optional onStreamEnd: (message) => void; +``` + +Defined in: [stream/processor.ts:57](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L57) + +#### Parameters + +##### message + +[`UIMessage`](UIMessage.md) + +#### Returns + +`void` + +*** + +### onStreamStart()? + +```ts +optional onStreamStart: () => void; +``` + +Defined in: [stream/processor.ts:56](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L56) + +#### Returns + +`void` + +*** + +### onTextUpdate()? + +```ts +optional onTextUpdate: (messageId, content) => void; +``` + +Defined in: [stream/processor.ts:74](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L74) + +#### Parameters + +##### messageId + +`string` + +##### content + +`string` + +#### Returns + +`void` + +*** + +### onThinkingUpdate()? + +```ts +optional onThinkingUpdate: (messageId, content) => void; +``` + +Defined in: [stream/processor.ts:81](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L81) + +#### Parameters + +##### messageId + +`string` + +##### content + +`string` + +#### Returns + +`void` + +*** + +### onToolCall()? + +```ts +optional onToolCall: (args) => void; +``` + +Defined in: [stream/processor.ts:61](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L61) + +#### Parameters + +##### args + +###### input + +`any` + +###### toolCallId + +`string` + +###### toolName + +`string` + +#### Returns + +`void` + +*** + +### onToolCallStateChange()? + +```ts +optional onToolCallStateChange: (messageId, toolCallId, state, args) => void; +``` + +Defined in: [stream/processor.ts:75](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L75) + +#### Parameters + +##### messageId + +`string` + +##### toolCallId + +`string` + +##### state + +[`ToolCallState`](../type-aliases/ToolCallState.md) + +##### args + +`string` + +#### Returns + +`void` diff --git a/docs/reference/interfaces/StreamProcessorHandlers.md b/docs/reference/interfaces/StreamProcessorHandlers.md new file mode 100644 index 00000000..c4e50f56 --- /dev/null +++ b/docs/reference/interfaces/StreamProcessorHandlers.md @@ -0,0 +1,317 @@ +--- +id: StreamProcessorHandlers +title: StreamProcessorHandlers +--- + +# Interface: StreamProcessorHandlers + +Defined in: [stream/processor.ts:88](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L88) + +Legacy handlers for backward compatibility +These are the old callback-style handlers + +## Properties + +### onApprovalRequested()? + +```ts +optional onApprovalRequested: (toolCallId, toolName, input, approvalId) => void; +``` + +Defined in: [stream/processor.ts:119](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L119) + +#### Parameters + +##### toolCallId + +`string` + +##### toolName + +`string` + +##### input + +`any` + +##### approvalId + +`string` + +#### Returns + +`void` + +*** + +### onError()? + +```ts +optional onError: (error) => void; +``` + +Defined in: [stream/processor.ts:133](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L133) + +#### Parameters + +##### error + +###### code? + +`string` + +###### message + +`string` + +#### Returns + +`void` + +*** + +### onStreamEnd()? + +```ts +optional onStreamEnd: (content, toolCalls?) => void; +``` + +Defined in: [stream/processor.ts:132](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L132) + +#### Parameters + +##### content + +`string` + +##### toolCalls? + +[`ToolCall`](ToolCall.md)[] + +#### Returns + +`void` + +*** + +### onTextUpdate()? + +```ts +optional onTextUpdate: (content) => void; +``` + +Defined in: [stream/processor.ts:89](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L89) + +#### Parameters + +##### content + +`string` + +#### Returns + +`void` + +*** + +### onThinkingUpdate()? + +```ts +optional onThinkingUpdate: (content) => void; +``` + +Defined in: [stream/processor.ts:90](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L90) + +#### Parameters + +##### content + +`string` + +#### Returns + +`void` + +*** + +### onToolCallComplete()? + +```ts +optional onToolCallComplete: (index, id, name, args) => void; +``` + +Defined in: [stream/processor.ts:95](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L95) + +#### Parameters + +##### index + +`number` + +##### id + +`string` + +##### name + +`string` + +##### args + +`string` + +#### Returns + +`void` + +*** + +### onToolCallDelta()? + +```ts +optional onToolCallDelta: (index, args) => void; +``` + +Defined in: [stream/processor.ts:94](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L94) + +#### Parameters + +##### index + +`number` + +##### args + +`string` + +#### Returns + +`void` + +*** + +### onToolCallStart()? + +```ts +optional onToolCallStart: (index, id, name) => void; +``` + +Defined in: [stream/processor.ts:93](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L93) + +#### Parameters + +##### index + +`number` + +##### id + +`string` + +##### name + +`string` + +#### Returns + +`void` + +*** + +### onToolCallStateChange()? + +```ts +optional onToolCallStateChange: (index, id, name, state, args, parsedArgs?) => void; +``` + +Defined in: [stream/processor.ts:101](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L101) + +#### Parameters + +##### index + +`number` + +##### id + +`string` + +##### name + +`string` + +##### state + +[`ToolCallState`](../type-aliases/ToolCallState.md) + +##### args + +`string` + +##### parsedArgs? + +`any` + +#### Returns + +`void` + +*** + +### onToolInputAvailable()? + +```ts +optional onToolInputAvailable: (toolCallId, toolName, input) => void; +``` + +Defined in: [stream/processor.ts:125](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L125) + +#### Parameters + +##### toolCallId + +`string` + +##### toolName + +`string` + +##### input + +`any` + +#### Returns + +`void` + +*** + +### onToolResultStateChange()? + +```ts +optional onToolResultStateChange: (toolCallId, content, state, error?) => void; +``` + +Defined in: [stream/processor.ts:111](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L111) + +#### Parameters + +##### toolCallId + +`string` + +##### content + +`string` + +##### state + +[`ToolResultState`](../type-aliases/ToolResultState.md) + +##### error? + +`string` + +#### Returns + +`void` diff --git a/docs/reference/interfaces/StreamProcessorOptions.md b/docs/reference/interfaces/StreamProcessorOptions.md new file mode 100644 index 00000000..ebe37672 --- /dev/null +++ b/docs/reference/interfaces/StreamProcessorOptions.md @@ -0,0 +1,94 @@ +--- +id: StreamProcessorOptions +title: StreamProcessorOptions +--- + +# Interface: StreamProcessorOptions + +Defined in: [stream/processor.ts:139](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L139) + +Options for StreamProcessor + +## Properties + +### chunkStrategy? + +```ts +optional chunkStrategy: ChunkStrategy; +``` + +Defined in: [stream/processor.ts:140](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L140) + +*** + +### events? + +```ts +optional events: StreamProcessorEvents; +``` + +Defined in: [stream/processor.ts:142](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L142) + +New event-driven handlers + +*** + +### handlers? + +```ts +optional handlers: StreamProcessorHandlers; +``` + +Defined in: [stream/processor.ts:144](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L144) + +Legacy callback handlers (for backward compatibility) + +*** + +### initialMessages? + +```ts +optional initialMessages: UIMessage[]; +``` + +Defined in: [stream/processor.ts:151](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L151) + +Initial messages to populate the processor + +*** + +### jsonParser? + +```ts +optional jsonParser: object; +``` + +Defined in: [stream/processor.ts:145](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L145) + +#### parse() + +```ts +parse: (jsonString) => any; +``` + +##### Parameters + +###### jsonString + +`string` + +##### Returns + +`any` + +*** + +### recording? + +```ts +optional recording: boolean; +``` + +Defined in: [stream/processor.ts:149](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/processor.ts#L149) + +Enable recording for replay testing diff --git a/docs/reference/interfaces/SummarizationOptions.md b/docs/reference/interfaces/SummarizationOptions.md new file mode 100644 index 00000000..5cd74038 --- /dev/null +++ b/docs/reference/interfaces/SummarizationOptions.md @@ -0,0 +1,58 @@ +--- +id: SummarizationOptions +title: SummarizationOptions +--- + +# Interface: SummarizationOptions + +Defined in: [types.ts:887](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L887) + +## Properties + +### focus? + +```ts +optional focus: string[]; +``` + +Defined in: [types.ts:892](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L892) + +*** + +### maxLength? + +```ts +optional maxLength: number; +``` + +Defined in: [types.ts:890](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L890) + +*** + +### model + +```ts +model: string; +``` + +Defined in: [types.ts:888](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L888) + +*** + +### style? + +```ts +optional style: "bullet-points" | "paragraph" | "concise"; +``` + +Defined in: [types.ts:891](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L891) + +*** + +### text + +```ts +text: string; +``` + +Defined in: [types.ts:889](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L889) diff --git a/docs/reference/interfaces/SummarizationResult.md b/docs/reference/interfaces/SummarizationResult.md new file mode 100644 index 00000000..ad421107 --- /dev/null +++ b/docs/reference/interfaces/SummarizationResult.md @@ -0,0 +1,66 @@ +--- +id: SummarizationResult +title: SummarizationResult +--- + +# Interface: SummarizationResult + +Defined in: [types.ts:895](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L895) + +## Properties + +### id + +```ts +id: string; +``` + +Defined in: [types.ts:896](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L896) + +*** + +### model + +```ts +model: string; +``` + +Defined in: [types.ts:897](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L897) + +*** + +### summary + +```ts +summary: string; +``` + +Defined in: [types.ts:898](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L898) + +*** + +### usage + +```ts +usage: object; +``` + +Defined in: [types.ts:899](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L899) + +#### completionTokens + +```ts +completionTokens: number; +``` + +#### promptTokens + +```ts +promptTokens: number; +``` + +#### totalTokens + +```ts +totalTokens: number; +``` diff --git a/docs/reference/interfaces/TextMessageContentEvent.md b/docs/reference/interfaces/TextMessageContentEvent.md new file mode 100644 index 00000000..14e84577 --- /dev/null +++ b/docs/reference/interfaces/TextMessageContentEvent.md @@ -0,0 +1,106 @@ +--- +id: TextMessageContentEvent +title: TextMessageContentEvent +--- + +# Interface: TextMessageContentEvent + +Defined in: [types.ts:609](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L609) + +Emitted when text content is generated (streaming tokens). + +## Extends + +- [`BaseEvent`](BaseEvent.md) + +## Properties + +### content? + +```ts +optional content: string; +``` + +Defined in: [types.ts:614](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L614) + +TanStack AI addition: Full accumulated content so far + +*** + +### delta + +```ts +delta: string; +``` + +Defined in: [types.ts:612](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L612) + +*** + +### messageId + +```ts +messageId: string; +``` + +Defined in: [types.ts:611](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L611) + +*** + +### model? + +```ts +optional model: string; +``` + +Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) + +TanStack AI addition: Model identifier for multi-model support + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`model`](BaseEvent.md#model) + +*** + +### rawEvent? + +```ts +optional rawEvent: unknown; +``` + +Defined in: [types.ts:559](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L559) + +Original provider event for debugging/advanced use cases + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`rawEvent`](BaseEvent.md#rawevent) + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`timestamp`](BaseEvent.md#timestamp) + +*** + +### type + +```ts +type: "TEXT_MESSAGE_CONTENT"; +``` + +Defined in: [types.ts:610](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L610) + +#### Overrides + +[`BaseEvent`](BaseEvent.md).[`type`](BaseEvent.md#type) diff --git a/docs/reference/interfaces/TextMessageEndEvent.md b/docs/reference/interfaces/TextMessageEndEvent.md new file mode 100644 index 00000000..62c0e792 --- /dev/null +++ b/docs/reference/interfaces/TextMessageEndEvent.md @@ -0,0 +1,84 @@ +--- +id: TextMessageEndEvent +title: TextMessageEndEvent +--- + +# Interface: TextMessageEndEvent + +Defined in: [types.ts:620](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L620) + +Emitted when a text message completes. + +## Extends + +- [`BaseEvent`](BaseEvent.md) + +## Properties + +### messageId + +```ts +messageId: string; +``` + +Defined in: [types.ts:622](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L622) + +*** + +### model? + +```ts +optional model: string; +``` + +Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) + +TanStack AI addition: Model identifier for multi-model support + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`model`](BaseEvent.md#model) + +*** + +### rawEvent? + +```ts +optional rawEvent: unknown; +``` + +Defined in: [types.ts:559](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L559) + +Original provider event for debugging/advanced use cases + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`rawEvent`](BaseEvent.md#rawevent) + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`timestamp`](BaseEvent.md#timestamp) + +*** + +### type + +```ts +type: "TEXT_MESSAGE_END"; +``` + +Defined in: [types.ts:621](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L621) + +#### Overrides + +[`BaseEvent`](BaseEvent.md).[`type`](BaseEvent.md#type) diff --git a/docs/reference/interfaces/TextMessageStartEvent.md b/docs/reference/interfaces/TextMessageStartEvent.md new file mode 100644 index 00000000..4e46c191 --- /dev/null +++ b/docs/reference/interfaces/TextMessageStartEvent.md @@ -0,0 +1,94 @@ +--- +id: TextMessageStartEvent +title: TextMessageStartEvent +--- + +# Interface: TextMessageStartEvent + +Defined in: [types.ts:600](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L600) + +Emitted when a text message starts. + +## Extends + +- [`BaseEvent`](BaseEvent.md) + +## Properties + +### messageId + +```ts +messageId: string; +``` + +Defined in: [types.ts:602](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L602) + +*** + +### model? + +```ts +optional model: string; +``` + +Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) + +TanStack AI addition: Model identifier for multi-model support + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`model`](BaseEvent.md#model) + +*** + +### rawEvent? + +```ts +optional rawEvent: unknown; +``` + +Defined in: [types.ts:559](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L559) + +Original provider event for debugging/advanced use cases + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`rawEvent`](BaseEvent.md#rawevent) + +*** + +### role + +```ts +role: "assistant"; +``` + +Defined in: [types.ts:603](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L603) + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`timestamp`](BaseEvent.md#timestamp) + +*** + +### type + +```ts +type: "TEXT_MESSAGE_START"; +``` + +Defined in: [types.ts:601](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L601) + +#### Overrides + +[`BaseEvent`](BaseEvent.md).[`type`](BaseEvent.md#type) diff --git a/docs/reference/interfaces/TextPart.md b/docs/reference/interfaces/TextPart.md new file mode 100644 index 00000000..34df956e --- /dev/null +++ b/docs/reference/interfaces/TextPart.md @@ -0,0 +1,46 @@ +--- +id: TextPart +title: TextPart +--- + +# Interface: TextPart\ + +Defined in: [types.ts:179](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L179) + +Message parts - building blocks of UIMessage + +## Type Parameters + +### TMetadata + +`TMetadata` = `unknown` + +## Properties + +### content + +```ts +content: string; +``` + +Defined in: [types.ts:181](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L181) + +*** + +### metadata? + +```ts +optional metadata: TMetadata; +``` + +Defined in: [types.ts:182](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L182) + +*** + +### type + +```ts +type: "text"; +``` + +Defined in: [types.ts:180](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L180) diff --git a/docs/reference/interfaces/ThinkingPart.md b/docs/reference/interfaces/ThinkingPart.md new file mode 100644 index 00000000..2b226b21 --- /dev/null +++ b/docs/reference/interfaces/ThinkingPart.md @@ -0,0 +1,28 @@ +--- +id: ThinkingPart +title: ThinkingPart +--- + +# Interface: ThinkingPart + +Defined in: [types.ts:209](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L209) + +## Properties + +### content + +```ts +content: string; +``` + +Defined in: [types.ts:211](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L211) + +*** + +### type + +```ts +type: "thinking"; +``` + +Defined in: [types.ts:210](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L210) diff --git a/docs/reference/interfaces/ThinkingStreamChunk.md b/docs/reference/interfaces/ThinkingStreamChunk.md new file mode 100644 index 00000000..feeaa559 --- /dev/null +++ b/docs/reference/interfaces/ThinkingStreamChunk.md @@ -0,0 +1,72 @@ +--- +id: ThinkingStreamChunk +title: ThinkingStreamChunk +--- + +# ~~Interface: ThinkingStreamChunk~~ + +Defined in: [types.ts:833](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L833) + +## Deprecated + +Use StepStartedEvent/StepFinishedEvent instead + +## Properties + +### ~~content~~ + +```ts +content: string; +``` + +Defined in: [types.ts:839](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L839) + +*** + +### ~~delta?~~ + +```ts +optional delta: string; +``` + +Defined in: [types.ts:838](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L838) + +*** + +### ~~id~~ + +```ts +id: string; +``` + +Defined in: [types.ts:835](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L835) + +*** + +### ~~model~~ + +```ts +model: string; +``` + +Defined in: [types.ts:836](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L836) + +*** + +### ~~timestamp~~ + +```ts +timestamp: number; +``` + +Defined in: [types.ts:837](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L837) + +*** + +### ~~type~~ + +```ts +type: "thinking"; +``` + +Defined in: [types.ts:834](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L834) diff --git a/docs/reference/interfaces/Tool.md b/docs/reference/interfaces/Tool.md new file mode 100644 index 00000000..3841b042 --- /dev/null +++ b/docs/reference/interfaces/Tool.md @@ -0,0 +1,204 @@ +--- +id: Tool +title: Tool +--- + +# Interface: Tool\ + +Defined in: [types.ts:263](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L263) + +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. + +## See + + - https://platform.openai.com/docs/guides/function-calling + - https://docs.anthropic.com/claude/docs/tool-use + +## Extended by + +- [`ToolDefinitionInstance`](ToolDefinitionInstance.md) +- [`ServerTool`](ServerTool.md) + +## Type Parameters + +### TInput + +`TInput` *extends* `z.ZodType` = `z.ZodType` + +### TOutput + +`TOutput` *extends* `z.ZodType` = `z.ZodType` + +### TName + +`TName` *extends* `string` = `string` + +## Properties + +### description + +```ts +description: string; +``` + +Defined in: [types.ts:286](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L286) + +Clear description of what the tool does. + +This is crucial - the model uses this to decide when to call the tool. +Be specific about what the tool does, what parameters it needs, and what it returns. + +#### Example + +```ts +"Get the current weather in a given location. Returns temperature, conditions, and forecast." +``` + +*** + +### execute()? + +```ts +optional execute: (args) => any; +``` + +Defined in: [types.ts:342](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L342) + +Optional function to execute when the model calls this tool. + +If provided, the SDK will automatically execute the function with the model's arguments +and feed the result back to the model. This enables autonomous tool use loops. + +Can return any value - will be automatically stringified if needed. + +#### Parameters + +##### args + +`any` + +The arguments parsed from the model's tool call (validated against inputSchema) + +#### Returns + +`any` + +Result to send back to the model (validated against outputSchema if provided) + +#### Example + +```ts +execute: async (args) => { + const weather = await fetchWeather(args.location); + return weather; // Can return object or string +} +``` + +*** + +### inputSchema? + +```ts +optional inputSchema: TInput; +``` + +Defined in: [types.ts:305](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L305) + +Zod 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/ + +#### Example + +```ts +import { z } from 'zod'; + +z.object({ + location: z.string().describe("City name or coordinates"), + unit: z.enum(["celsius", "fahrenheit"]).optional() +}) +``` + +*** + +### metadata? + +```ts +optional metadata: Record; +``` + +Defined in: [types.ts:348](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L348) + +Additional metadata for adapters or custom extensions + +*** + +### name + +```ts +name: TName; +``` + +Defined in: [types.ts:276](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L276) + +Unique name of the tool (used by the model to call it). + +Should be descriptive and follow naming conventions (e.g., snake_case or camelCase). +Must be unique within the tools array. + +#### Example + +```ts +"get_weather", "search_database", "sendEmail" +``` + +*** + +### needsApproval? + +```ts +optional needsApproval: boolean; +``` + +Defined in: [types.ts:345](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L345) + +If true, tool execution requires user approval before running. Works with both server and client tools. + +*** + +### outputSchema? + +```ts +optional outputSchema: TOutput; +``` + +Defined in: [types.ts:323](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L323) + +Optional Zod 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 +and ensures consistent output formatting. + +Note: This is client-side validation only - not sent to LLM providers. + +#### Example + +```ts +z.object({ + temperature: z.number(), + conditions: z.string(), + forecast: z.array(z.string()).optional() +}) +``` diff --git a/docs/reference/interfaces/ToolCall.md b/docs/reference/interfaces/ToolCall.md new file mode 100644 index 00000000..ac9a60d0 --- /dev/null +++ b/docs/reference/interfaces/ToolCall.md @@ -0,0 +1,50 @@ +--- +id: ToolCall +title: ToolCall +--- + +# Interface: ToolCall + +Defined in: [types.ts:5](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L5) + +## Properties + +### function + +```ts +function: object; +``` + +Defined in: [types.ts:8](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L8) + +#### arguments + +```ts +arguments: string; +``` + +#### name + +```ts +name: string; +``` + +*** + +### id + +```ts +id: string; +``` + +Defined in: [types.ts:6](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L6) + +*** + +### type + +```ts +type: "function"; +``` + +Defined in: [types.ts:7](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L7) diff --git a/docs/reference/interfaces/ToolCallArgsEvent.md b/docs/reference/interfaces/ToolCallArgsEvent.md new file mode 100644 index 00000000..f42c5445 --- /dev/null +++ b/docs/reference/interfaces/ToolCallArgsEvent.md @@ -0,0 +1,108 @@ +--- +id: ToolCallArgsEvent +title: ToolCallArgsEvent +--- + +# Interface: ToolCallArgsEvent + +Defined in: [types.ts:644](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L644) + +Emitted when tool call arguments are streaming. + +## Extends + +- [`BaseEvent`](BaseEvent.md) + +## Properties + +### args? + +```ts +optional args: string; +``` + +Defined in: [types.ts:650](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L650) + +Full accumulated arguments so far + +*** + +### delta + +```ts +delta: string; +``` + +Defined in: [types.ts:648](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L648) + +Incremental JSON arguments delta + +*** + +### model? + +```ts +optional model: string; +``` + +Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) + +TanStack AI addition: Model identifier for multi-model support + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`model`](BaseEvent.md#model) + +*** + +### rawEvent? + +```ts +optional rawEvent: unknown; +``` + +Defined in: [types.ts:559](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L559) + +Original provider event for debugging/advanced use cases + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`rawEvent`](BaseEvent.md#rawevent) + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`timestamp`](BaseEvent.md#timestamp) + +*** + +### toolCallId + +```ts +toolCallId: string; +``` + +Defined in: [types.ts:646](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L646) + +*** + +### type + +```ts +type: "TOOL_CALL_ARGS"; +``` + +Defined in: [types.ts:645](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L645) + +#### Overrides + +[`BaseEvent`](BaseEvent.md).[`type`](BaseEvent.md#type) diff --git a/docs/reference/interfaces/ToolCallEndEvent.md b/docs/reference/interfaces/ToolCallEndEvent.md new file mode 100644 index 00000000..07046226 --- /dev/null +++ b/docs/reference/interfaces/ToolCallEndEvent.md @@ -0,0 +1,118 @@ +--- +id: ToolCallEndEvent +title: ToolCallEndEvent +--- + +# Interface: ToolCallEndEvent + +Defined in: [types.ts:656](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L656) + +Emitted when a tool call completes (with optional result). + +## Extends + +- [`BaseEvent`](BaseEvent.md) + +## Properties + +### input? + +```ts +optional input: unknown; +``` + +Defined in: [types.ts:661](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L661) + +Final parsed input arguments + +*** + +### model? + +```ts +optional model: string; +``` + +Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) + +TanStack AI addition: Model identifier for multi-model support + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`model`](BaseEvent.md#model) + +*** + +### rawEvent? + +```ts +optional rawEvent: unknown; +``` + +Defined in: [types.ts:559](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L559) + +Original provider event for debugging/advanced use cases + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`rawEvent`](BaseEvent.md#rawevent) + +*** + +### result? + +```ts +optional result: unknown; +``` + +Defined in: [types.ts:663](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L663) + +Tool execution result (present when tool has executed) + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`timestamp`](BaseEvent.md#timestamp) + +*** + +### toolCallId + +```ts +toolCallId: string; +``` + +Defined in: [types.ts:658](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L658) + +*** + +### toolName + +```ts +toolName: string; +``` + +Defined in: [types.ts:659](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L659) + +*** + +### type + +```ts +type: "TOOL_CALL_END"; +``` + +Defined in: [types.ts:657](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L657) + +#### Overrides + +[`BaseEvent`](BaseEvent.md).[`type`](BaseEvent.md#type) diff --git a/docs/reference/interfaces/ToolCallPart.md b/docs/reference/interfaces/ToolCallPart.md new file mode 100644 index 00000000..66052c25 --- /dev/null +++ b/docs/reference/interfaces/ToolCallPart.md @@ -0,0 +1,100 @@ +--- +id: ToolCallPart +title: ToolCallPart +--- + +# Interface: ToolCallPart + +Defined in: [types.ts:185](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L185) + +## Properties + +### approval? + +```ts +optional approval: object; +``` + +Defined in: [types.ts:192](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L192) + +Approval metadata if tool requires user approval + +#### approved? + +```ts +optional approved: boolean; +``` + +#### id + +```ts +id: string; +``` + +#### needsApproval + +```ts +needsApproval: boolean; +``` + +*** + +### arguments + +```ts +arguments: string; +``` + +Defined in: [types.ts:189](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L189) + +*** + +### id + +```ts +id: string; +``` + +Defined in: [types.ts:187](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L187) + +*** + +### name + +```ts +name: string; +``` + +Defined in: [types.ts:188](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L188) + +*** + +### output? + +```ts +optional output: any; +``` + +Defined in: [types.ts:198](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L198) + +Tool execution output (for client tools or after approval) + +*** + +### state + +```ts +state: ToolCallState; +``` + +Defined in: [types.ts:190](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L190) + +*** + +### type + +```ts +type: "tool-call"; +``` + +Defined in: [types.ts:186](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L186) diff --git a/docs/reference/interfaces/ToolCallStartEvent.md b/docs/reference/interfaces/ToolCallStartEvent.md new file mode 100644 index 00000000..9eba52d2 --- /dev/null +++ b/docs/reference/interfaces/ToolCallStartEvent.md @@ -0,0 +1,130 @@ +--- +id: ToolCallStartEvent +title: ToolCallStartEvent +--- + +# Interface: ToolCallStartEvent + +Defined in: [types.ts:628](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L628) + +Emitted when a tool call starts. + +## Extends + +- [`BaseEvent`](BaseEvent.md) + +## Properties + +### approval? + +```ts +optional approval: object; +``` + +Defined in: [types.ts:635](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L635) + +Approval metadata if tool requires user approval + +#### id + +```ts +id: string; +``` + +#### needsApproval + +```ts +needsApproval: true; +``` + +*** + +### index? + +```ts +optional index: number; +``` + +Defined in: [types.ts:633](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L633) + +Index for parallel tool calls + +*** + +### model? + +```ts +optional model: string; +``` + +Defined in: [types.ts:557](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L557) + +TanStack AI addition: Model identifier for multi-model support + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`model`](BaseEvent.md#model) + +*** + +### rawEvent? + +```ts +optional rawEvent: unknown; +``` + +Defined in: [types.ts:559](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L559) + +Original provider event for debugging/advanced use cases + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`rawEvent`](BaseEvent.md#rawevent) + +*** + +### timestamp + +```ts +timestamp: number; +``` + +Defined in: [types.ts:555](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L555) + +#### Inherited from + +[`BaseEvent`](BaseEvent.md).[`timestamp`](BaseEvent.md#timestamp) + +*** + +### toolCallId + +```ts +toolCallId: string; +``` + +Defined in: [types.ts:630](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L630) + +*** + +### toolName + +```ts +toolName: string; +``` + +Defined in: [types.ts:631](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L631) + +*** + +### type + +```ts +type: "TOOL_CALL_START"; +``` + +Defined in: [types.ts:629](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L629) + +#### Overrides + +[`BaseEvent`](BaseEvent.md).[`type`](BaseEvent.md#type) diff --git a/docs/reference/interfaces/ToolCallStreamChunk.md b/docs/reference/interfaces/ToolCallStreamChunk.md new file mode 100644 index 00000000..b8c1853c --- /dev/null +++ b/docs/reference/interfaces/ToolCallStreamChunk.md @@ -0,0 +1,94 @@ +--- +id: ToolCallStreamChunk +title: ToolCallStreamChunk +--- + +# ~~Interface: ToolCallStreamChunk~~ + +Defined in: [types.ts:805](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L805) + +## Deprecated + +Use ToolCallStartEvent and ToolCallArgsEvent instead + +## Properties + +### ~~approval?~~ + +```ts +optional approval: object; +``` + +Defined in: [types.ts:812](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L812) + +#### ~~id~~ + +```ts +id: string; +``` + +#### ~~needsApproval~~ + +```ts +needsApproval: true; +``` + +*** + +### ~~id~~ + +```ts +id: string; +``` + +Defined in: [types.ts:807](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L807) + +*** + +### ~~index~~ + +```ts +index: number; +``` + +Defined in: [types.ts:811](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L811) + +*** + +### ~~model~~ + +```ts +model: string; +``` + +Defined in: [types.ts:808](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L808) + +*** + +### ~~timestamp~~ + +```ts +timestamp: number; +``` + +Defined in: [types.ts:809](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L809) + +*** + +### ~~toolCall~~ + +```ts +toolCall: ToolCall; +``` + +Defined in: [types.ts:810](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L810) + +*** + +### ~~type~~ + +```ts +type: "tool_call"; +``` + +Defined in: [types.ts:806](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L806) diff --git a/docs/reference/interfaces/ToolConfig.md b/docs/reference/interfaces/ToolConfig.md new file mode 100644 index 00000000..4af8fcf8 --- /dev/null +++ b/docs/reference/interfaces/ToolConfig.md @@ -0,0 +1,14 @@ +--- +id: ToolConfig +title: ToolConfig +--- + +# Interface: ToolConfig + +Defined in: [types.ts:351](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L351) + +## Indexable + +```ts +[key: string]: Tool>, ZodType>, string> +``` diff --git a/docs/reference/interfaces/ToolDefinition.md b/docs/reference/interfaces/ToolDefinition.md new file mode 100644 index 00000000..ee4ccf6a --- /dev/null +++ b/docs/reference/interfaces/ToolDefinition.md @@ -0,0 +1,279 @@ +--- +id: ToolDefinition +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) + +Tool definition builder that allows creating server or client tools from a shared definition + +## Extends + +- [`ToolDefinitionInstance`](ToolDefinitionInstance.md)\<`TInput`, `TOutput`, `TName`\> + +## Type Parameters + +### TInput + +`TInput` *extends* `z.ZodType` = `z.ZodType` + +### TOutput + +`TOutput` *extends* `z.ZodType` = `z.ZodType` + +### TName + +`TName` *extends* `string` = `string` + +## Properties + +### \_\_toolSide + +```ts +__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) + +#### Inherited from + +[`ToolDefinitionInstance`](ToolDefinitionInstance.md).[`__toolSide`](ToolDefinitionInstance.md#__toolside) + +*** + +### client() + +```ts +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) + +Create a client-side tool with optional execute function + +#### Parameters + +##### execute? + +(`args`) => `output`\<`TOutput`\> \| `Promise`\<`output`\<`TOutput`\>\> + +#### Returns + +[`ClientTool`](ClientTool.md)\<`TInput`, `TOutput`, `TName`\> + +*** + +### description + +```ts +description: string; +``` + +Defined in: [types.ts:286](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L286) + +Clear description of what the tool does. + +This is crucial - the model uses this to decide when to call the tool. +Be specific about what the tool does, what parameters it needs, and what it returns. + +#### Example + +```ts +"Get the current weather in a given location. Returns temperature, conditions, and forecast." +``` + +#### Inherited from + +[`ToolDefinitionInstance`](ToolDefinitionInstance.md).[`description`](ToolDefinitionInstance.md#description) + +*** + +### execute()? + +```ts +optional execute: (args) => any; +``` + +Defined in: [types.ts:342](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L342) + +Optional function to execute when the model calls this tool. + +If provided, the SDK will automatically execute the function with the model's arguments +and feed the result back to the model. This enables autonomous tool use loops. + +Can return any value - will be automatically stringified if needed. + +#### Parameters + +##### args + +`any` + +The arguments parsed from the model's tool call (validated against inputSchema) + +#### Returns + +`any` + +Result to send back to the model (validated against outputSchema if provided) + +#### Example + +```ts +execute: async (args) => { + const weather = await fetchWeather(args.location); + return weather; // Can return object or string +} +``` + +#### Inherited from + +[`ToolDefinitionInstance`](ToolDefinitionInstance.md).[`execute`](ToolDefinitionInstance.md#execute) + +*** + +### inputSchema? + +```ts +optional inputSchema: TInput; +``` + +Defined in: [types.ts:305](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L305) + +Zod 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/ + +#### Example + +```ts +import { z } from 'zod'; + +z.object({ + location: z.string().describe("City name or coordinates"), + unit: z.enum(["celsius", "fahrenheit"]).optional() +}) +``` + +#### Inherited from + +[`ToolDefinitionInstance`](ToolDefinitionInstance.md).[`inputSchema`](ToolDefinitionInstance.md#inputschema) + +*** + +### metadata? + +```ts +optional metadata: Record; +``` + +Defined in: [types.ts:348](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L348) + +Additional metadata for adapters or custom extensions + +#### Inherited from + +[`ToolDefinitionInstance`](ToolDefinitionInstance.md).[`metadata`](ToolDefinitionInstance.md#metadata) + +*** + +### name + +```ts +name: TName; +``` + +Defined in: [types.ts:276](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L276) + +Unique name of the tool (used by the model to call it). + +Should be descriptive and follow naming conventions (e.g., snake_case or camelCase). +Must be unique within the tools array. + +#### Example + +```ts +"get_weather", "search_database", "sendEmail" +``` + +#### Inherited from + +[`ToolDefinitionInstance`](ToolDefinitionInstance.md).[`name`](ToolDefinitionInstance.md#name) + +*** + +### needsApproval? + +```ts +optional needsApproval: boolean; +``` + +Defined in: [types.ts:345](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L345) + +If true, tool execution requires user approval before running. Works with both server and client tools. + +#### Inherited from + +[`ToolDefinitionInstance`](ToolDefinitionInstance.md).[`needsApproval`](ToolDefinitionInstance.md#needsapproval) + +*** + +### outputSchema? + +```ts +optional outputSchema: TOutput; +``` + +Defined in: [types.ts:323](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L323) + +Optional Zod 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 +and ensures consistent output formatting. + +Note: This is client-side validation only - not sent to LLM providers. + +#### Example + +```ts +z.object({ + temperature: z.number(), + conditions: z.string(), + forecast: z.array(z.string()).optional() +}) +``` + +#### Inherited from + +[`ToolDefinitionInstance`](ToolDefinitionInstance.md).[`outputSchema`](ToolDefinitionInstance.md#outputschema) + +*** + +### server() + +```ts +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) + +Create a server-side tool with execute function + +#### Parameters + +##### execute + +(`args`) => `output`\<`TOutput`\> \| `Promise`\<`output`\<`TOutput`\>\> + +#### Returns + +[`ServerTool`](ServerTool.md)\<`TInput`, `TOutput`, `TName`\> diff --git a/docs/reference/interfaces/ToolDefinitionConfig.md b/docs/reference/interfaces/ToolDefinitionConfig.md new file mode 100644 index 00000000..df55b556 --- /dev/null +++ b/docs/reference/interfaces/ToolDefinitionConfig.md @@ -0,0 +1,84 @@ +--- +id: ToolDefinitionConfig +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) + +Tool definition configuration + +## Type Parameters + +### TInput + +`TInput` *extends* `z.ZodType` = `z.ZodType` + +### TOutput + +`TOutput` *extends* `z.ZodType` = `z.ZodType` + +### TName + +`TName` *extends* `string` = `string` + +## Properties + +### description + +```ts +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) + +*** + +### inputSchema? + +```ts +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) + +*** + +### metadata? + +```ts +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) + +*** + +### name + +```ts +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) + +*** + +### needsApproval? + +```ts +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) + +*** + +### outputSchema? + +```ts +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) diff --git a/docs/reference/interfaces/ToolDefinitionInstance.md b/docs/reference/interfaces/ToolDefinitionInstance.md new file mode 100644 index 00000000..6884845c --- /dev/null +++ b/docs/reference/interfaces/ToolDefinitionInstance.md @@ -0,0 +1,235 @@ +--- +id: ToolDefinitionInstance +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) + +Tool definition that can be used directly or instantiated for server/client + +## Extends + +- [`Tool`](Tool.md)\<`TInput`, `TOutput`, `TName`\> + +## Extended by + +- [`ToolDefinition`](ToolDefinition.md) + +## Type Parameters + +### TInput + +`TInput` *extends* `z.ZodType` = `z.ZodType` + +### TOutput + +`TOutput` *extends* `z.ZodType` = `z.ZodType` + +### TName + +`TName` *extends* `string` = `string` + +## Properties + +### \_\_toolSide + +```ts +__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) + +*** + +### description + +```ts +description: string; +``` + +Defined in: [types.ts:286](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L286) + +Clear description of what the tool does. + +This is crucial - the model uses this to decide when to call the tool. +Be specific about what the tool does, what parameters it needs, and what it returns. + +#### Example + +```ts +"Get the current weather in a given location. Returns temperature, conditions, and forecast." +``` + +#### Inherited from + +[`Tool`](Tool.md).[`description`](Tool.md#description) + +*** + +### execute()? + +```ts +optional execute: (args) => any; +``` + +Defined in: [types.ts:342](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L342) + +Optional function to execute when the model calls this tool. + +If provided, the SDK will automatically execute the function with the model's arguments +and feed the result back to the model. This enables autonomous tool use loops. + +Can return any value - will be automatically stringified if needed. + +#### Parameters + +##### args + +`any` + +The arguments parsed from the model's tool call (validated against inputSchema) + +#### Returns + +`any` + +Result to send back to the model (validated against outputSchema if provided) + +#### Example + +```ts +execute: async (args) => { + const weather = await fetchWeather(args.location); + return weather; // Can return object or string +} +``` + +#### Inherited from + +[`Tool`](Tool.md).[`execute`](Tool.md#execute) + +*** + +### inputSchema? + +```ts +optional inputSchema: TInput; +``` + +Defined in: [types.ts:305](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L305) + +Zod 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/ + +#### Example + +```ts +import { z } from 'zod'; + +z.object({ + location: z.string().describe("City name or coordinates"), + unit: z.enum(["celsius", "fahrenheit"]).optional() +}) +``` + +#### Inherited from + +[`Tool`](Tool.md).[`inputSchema`](Tool.md#inputschema) + +*** + +### metadata? + +```ts +optional metadata: Record; +``` + +Defined in: [types.ts:348](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L348) + +Additional metadata for adapters or custom extensions + +#### Inherited from + +[`Tool`](Tool.md).[`metadata`](Tool.md#metadata) + +*** + +### name + +```ts +name: TName; +``` + +Defined in: [types.ts:276](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L276) + +Unique name of the tool (used by the model to call it). + +Should be descriptive and follow naming conventions (e.g., snake_case or camelCase). +Must be unique within the tools array. + +#### Example + +```ts +"get_weather", "search_database", "sendEmail" +``` + +#### Inherited from + +[`Tool`](Tool.md).[`name`](Tool.md#name) + +*** + +### needsApproval? + +```ts +optional needsApproval: boolean; +``` + +Defined in: [types.ts:345](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L345) + +If true, tool execution requires user approval before running. Works with both server and client tools. + +#### Inherited from + +[`Tool`](Tool.md).[`needsApproval`](Tool.md#needsapproval) + +*** + +### outputSchema? + +```ts +optional outputSchema: TOutput; +``` + +Defined in: [types.ts:323](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L323) + +Optional Zod 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 +and ensures consistent output formatting. + +Note: This is client-side validation only - not sent to LLM providers. + +#### Example + +```ts +z.object({ + temperature: z.number(), + conditions: z.string(), + forecast: z.array(z.string()).optional() +}) +``` + +#### Inherited from + +[`Tool`](Tool.md).[`outputSchema`](Tool.md#outputschema) diff --git a/docs/reference/interfaces/ToolInputAvailableStreamChunk.md b/docs/reference/interfaces/ToolInputAvailableStreamChunk.md new file mode 100644 index 00000000..65406412 --- /dev/null +++ b/docs/reference/interfaces/ToolInputAvailableStreamChunk.md @@ -0,0 +1,82 @@ +--- +id: ToolInputAvailableStreamChunk +title: ToolInputAvailableStreamChunk +--- + +# ~~Interface: ToolInputAvailableStreamChunk~~ + +Defined in: [types.ts:862](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L862) + +## Deprecated + +Use CustomEvent with name='tool-input-available' instead + +## Properties + +### ~~id~~ + +```ts +id: string; +``` + +Defined in: [types.ts:864](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L864) + +*** + +### ~~input~~ + +```ts +input: Record; +``` + +Defined in: [types.ts:869](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L869) + +*** + +### ~~model~~ + +```ts +model: string; +``` + +Defined in: [types.ts:865](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L865) + +*** + +### ~~timestamp~~ + +```ts +timestamp: number; +``` + +Defined in: [types.ts:866](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L866) + +*** + +### ~~toolCallId~~ + +```ts +toolCallId: string; +``` + +Defined in: [types.ts:867](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L867) + +*** + +### ~~toolName~~ + +```ts +toolName: string; +``` + +Defined in: [types.ts:868](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L868) + +*** + +### ~~type~~ + +```ts +type: "tool-input-available"; +``` + +Defined in: [types.ts:863](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L863) diff --git a/docs/reference/interfaces/ToolResultPart.md b/docs/reference/interfaces/ToolResultPart.md new file mode 100644 index 00000000..35204171 --- /dev/null +++ b/docs/reference/interfaces/ToolResultPart.md @@ -0,0 +1,58 @@ +--- +id: ToolResultPart +title: ToolResultPart +--- + +# Interface: ToolResultPart + +Defined in: [types.ts:201](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L201) + +## Properties + +### content + +```ts +content: string; +``` + +Defined in: [types.ts:204](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L204) + +*** + +### error? + +```ts +optional error: string; +``` + +Defined in: [types.ts:206](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L206) + +*** + +### state + +```ts +state: ToolResultState; +``` + +Defined in: [types.ts:205](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L205) + +*** + +### toolCallId + +```ts +toolCallId: string; +``` + +Defined in: [types.ts:203](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L203) + +*** + +### type + +```ts +type: "tool-result"; +``` + +Defined in: [types.ts:202](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L202) diff --git a/docs/reference/interfaces/ToolResultStreamChunk.md b/docs/reference/interfaces/ToolResultStreamChunk.md new file mode 100644 index 00000000..7e091327 --- /dev/null +++ b/docs/reference/interfaces/ToolResultStreamChunk.md @@ -0,0 +1,72 @@ +--- +id: ToolResultStreamChunk +title: ToolResultStreamChunk +--- + +# ~~Interface: ToolResultStreamChunk~~ + +Defined in: [types.ts:821](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L821) + +## Deprecated + +Use ToolCallEndEvent instead + +## Properties + +### ~~content~~ + +```ts +content: string; +``` + +Defined in: [types.ts:827](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L827) + +*** + +### ~~id~~ + +```ts +id: string; +``` + +Defined in: [types.ts:823](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L823) + +*** + +### ~~model~~ + +```ts +model: string; +``` + +Defined in: [types.ts:824](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L824) + +*** + +### ~~timestamp~~ + +```ts +timestamp: number; +``` + +Defined in: [types.ts:825](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L825) + +*** + +### ~~toolCallId~~ + +```ts +toolCallId: string; +``` + +Defined in: [types.ts:826](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L826) + +*** + +### ~~type~~ + +```ts +type: "tool_result"; +``` + +Defined in: [types.ts:822](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L822) diff --git a/docs/reference/interfaces/UIMessage.md b/docs/reference/interfaces/UIMessage.md new file mode 100644 index 00000000..8bbe7522 --- /dev/null +++ b/docs/reference/interfaces/UIMessage.md @@ -0,0 +1,51 @@ +--- +id: UIMessage +title: UIMessage +--- + +# Interface: UIMessage + +Defined in: [types.ts:224](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L224) + +UIMessage - Domain-specific message format optimized for building chat UIs +Contains parts that can be text, tool calls, or tool results + +## Properties + +### createdAt? + +```ts +optional createdAt: Date; +``` + +Defined in: [types.ts:228](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L228) + +*** + +### id + +```ts +id: string; +``` + +Defined in: [types.ts:225](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L225) + +*** + +### parts + +```ts +parts: MessagePart[]; +``` + +Defined in: [types.ts:227](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L227) + +*** + +### role + +```ts +role: "user" | "assistant" | "system"; +``` + +Defined in: [types.ts:226](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L226) diff --git a/docs/reference/interfaces/VideoPart.md b/docs/reference/interfaces/VideoPart.md new file mode 100644 index 00000000..8768b04d --- /dev/null +++ b/docs/reference/interfaces/VideoPart.md @@ -0,0 +1,52 @@ +--- +id: VideoPart +title: VideoPart +--- + +# Interface: VideoPart\ + +Defined in: [types.ts:75](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L75) + +Video content part for multimodal messages. + +## Type Parameters + +### TMetadata + +`TMetadata` = `unknown` + +Provider-specific metadata type + +## Properties + +### metadata? + +```ts +optional metadata: TMetadata; +``` + +Defined in: [types.ts:80](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L80) + +Provider-specific metadata (e.g., duration, resolution) + +*** + +### source + +```ts +source: ContentPartSource; +``` + +Defined in: [types.ts:78](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L78) + +Source of the video content + +*** + +### type + +```ts +type: "video"; +``` + +Defined in: [types.ts:76](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L76) diff --git a/docs/reference/type-aliases/AgentLoopStrategy.md b/docs/reference/type-aliases/AgentLoopStrategy.md new file mode 100644 index 00000000..c16fe5be --- /dev/null +++ b/docs/reference/type-aliases/AgentLoopStrategy.md @@ -0,0 +1,35 @@ +--- +id: AgentLoopStrategy +title: AgentLoopStrategy +--- + +# Type Alias: AgentLoopStrategy() + +```ts +type AgentLoopStrategy = (state) => boolean; +``` + +Defined in: [types.ts:471](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L471) + +Strategy function that determines whether the agent loop should continue + +## Parameters + +### state + +[`AgentLoopState`](../interfaces/AgentLoopState.md) + +Current state of the agent loop + +## Returns + +`boolean` + +true to continue looping, false to stop + +## Example + +```typescript +// Continue for up to 5 iterations +const strategy: AgentLoopStrategy = ({ iterationCount }) => iterationCount < 5; +``` diff --git a/docs/reference/type-aliases/AnyClientTool.md b/docs/reference/type-aliases/AnyClientTool.md new file mode 100644 index 00000000..4f395412 --- /dev/null +++ b/docs/reference/type-aliases/AnyClientTool.md @@ -0,0 +1,16 @@ +--- +id: AnyClientTool +title: AnyClientTool +--- + +# Type Alias: AnyClientTool + +```ts +type AnyClientTool = + | ClientTool +| ToolDefinitionInstance; +``` + +Defined in: [tools/tool-definition.ts:49](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/tools/tool-definition.ts#L49) + +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 new file mode 100644 index 00000000..71b5aebc --- /dev/null +++ b/docs/reference/type-aliases/ChatStreamOptionsForModel.md @@ -0,0 +1,26 @@ +--- +id: ChatStreamOptionsForModel +title: ChatStreamOptionsForModel +--- + +# Type Alias: ChatStreamOptionsForModel\ + +```ts +type ChatStreamOptionsForModel = TAdapter extends AIAdapter ? Omit & object : never; +``` + +Defined in: [types.ts:1073](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L1073) + +Chat options constrained by a specific model's capabilities. +Unlike ChatStreamOptionsUnion which creates a union over all models, +this type takes a specific model and constrains messages accordingly. + +## Type Parameters + +### TAdapter + +`TAdapter` *extends* [`AIAdapter`](../interfaces/AIAdapter.md)\<`any`, `any`, `any`, `any`, `any`, `any`, `any`\> + +### TModel + +`TModel` *extends* `string` diff --git a/docs/reference/type-aliases/ChatStreamOptionsUnion.md b/docs/reference/type-aliases/ChatStreamOptionsUnion.md new file mode 100644 index 00000000..92d3173b --- /dev/null +++ b/docs/reference/type-aliases/ChatStreamOptionsUnion.md @@ -0,0 +1,18 @@ +--- +id: ChatStreamOptionsUnion +title: ChatStreamOptionsUnion +--- + +# Type Alias: ChatStreamOptionsUnion\ + +```ts +type ChatStreamOptionsUnion = TAdapter extends AIAdapter ? Models[number] extends infer TModel ? TModel extends string ? Omit & object : never : never : never; +``` + +Defined in: [types.ts:1013](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L1013) + +## Type Parameters + +### TAdapter + +`TAdapter` *extends* [`AIAdapter`](../interfaces/AIAdapter.md)\<`any`, `any`, `any`, `any`, `any`, `any`, `any`\> diff --git a/docs/reference/type-aliases/ConstrainedContent.md b/docs/reference/type-aliases/ConstrainedContent.md new file mode 100644 index 00000000..781ee84d --- /dev/null +++ b/docs/reference/type-aliases/ConstrainedContent.md @@ -0,0 +1,44 @@ +--- +id: ConstrainedContent +title: ConstrainedContent +--- + +# Type Alias: ConstrainedContent\ + +```ts +type ConstrainedContent = + | string + | null + | ContentPartForModalities, TImageMeta, TAudioMeta, TVideoMeta, TDocumentMeta, TTextMeta>[]; +``` + +Defined in: [types.ts:142](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L142) + +Type for message content constrained by supported modalities. +When modalities is ['text', 'image'], only TextPart and ImagePart are allowed in the array. + +## Type Parameters + +### TModalities + +`TModalities` *extends* `ReadonlyArray`\<[`Modality`](Modality.md)\> + +### TImageMeta + +`TImageMeta` = `unknown` + +### TAudioMeta + +`TAudioMeta` = `unknown` + +### TVideoMeta + +`TVideoMeta` = `unknown` + +### TDocumentMeta + +`TDocumentMeta` = `unknown` + +### TTextMeta + +`TTextMeta` = `unknown` diff --git a/docs/reference/type-aliases/ConstrainedModelMessage.md b/docs/reference/type-aliases/ConstrainedModelMessage.md new file mode 100644 index 00000000..c67448d9 --- /dev/null +++ b/docs/reference/type-aliases/ConstrainedModelMessage.md @@ -0,0 +1,49 @@ +--- +id: ConstrainedModelMessage +title: ConstrainedModelMessage +--- + +# Type Alias: ConstrainedModelMessage\ + +```ts +type ConstrainedModelMessage = Omit & object; +``` + +Defined in: [types.ts:234](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L234) + +A ModelMessage with content constrained to only allow content parts +matching the specified input modalities. + +## Type Declaration + +### content + +```ts +content: ConstrainedContent; +``` + +## Type Parameters + +### TModalities + +`TModalities` *extends* `ReadonlyArray`\<[`Modality`](Modality.md)\> + +### TImageMeta + +`TImageMeta` = `unknown` + +### TAudioMeta + +`TAudioMeta` = `unknown` + +### TVideoMeta + +`TVideoMeta` = `unknown` + +### TDocumentMeta + +`TDocumentMeta` = `unknown` + +### TTextMeta + +`TTextMeta` = `unknown` diff --git a/docs/reference/type-aliases/ContentPart.md b/docs/reference/type-aliases/ContentPart.md new file mode 100644 index 00000000..9ebc9aa4 --- /dev/null +++ b/docs/reference/type-aliases/ContentPart.md @@ -0,0 +1,49 @@ +--- +id: ContentPart +title: ContentPart +--- + +# Type Alias: ContentPart\ + +```ts +type ContentPart = + | TextPart + | ImagePart + | AudioPart + | VideoPart +| DocumentPart; +``` + +Defined in: [types.ts:102](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L102) + +Union type for all multimodal content parts. + +## Type Parameters + +### TImageMeta + +`TImageMeta` = `unknown` + +Provider-specific image metadata type + +### TAudioMeta + +`TAudioMeta` = `unknown` + +Provider-specific audio metadata type + +### TVideoMeta + +`TVideoMeta` = `unknown` + +Provider-specific video metadata type + +### TDocumentMeta + +`TDocumentMeta` = `unknown` + +Provider-specific document metadata type + +### TTextMeta + +`TTextMeta` = `unknown` diff --git a/docs/reference/type-aliases/ContentPartForModalities.md b/docs/reference/type-aliases/ContentPartForModalities.md new file mode 100644 index 00000000..648c53f5 --- /dev/null +++ b/docs/reference/type-aliases/ContentPartForModalities.md @@ -0,0 +1,43 @@ +--- +id: ContentPartForModalities +title: ContentPartForModalities +--- + +# Type Alias: ContentPartForModalities\ + +```ts +type ContentPartForModalities = Extract, { + type: TModalities; +}>; +``` + +Defined in: [types.ts:119](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L119) + +Helper type to filter ContentPart union to only include specific modalities. +Used to constrain message content based on model capabilities. + +## Type Parameters + +### TModalities + +`TModalities` *extends* [`Modality`](Modality.md) + +### TImageMeta + +`TImageMeta` = `unknown` + +### TAudioMeta + +`TAudioMeta` = `unknown` + +### TVideoMeta + +`TVideoMeta` = `unknown` + +### TDocumentMeta + +`TDocumentMeta` = `unknown` + +### TTextMeta + +`TTextMeta` = `unknown` diff --git a/docs/reference/type-aliases/EventType.md b/docs/reference/type-aliases/EventType.md new file mode 100644 index 00000000..44fa42d3 --- /dev/null +++ b/docs/reference/type-aliases/EventType.md @@ -0,0 +1,43 @@ +--- +id: EventType +title: EventType +--- + +# Type Alias: EventType + +```ts +type EventType = + | "RUN_STARTED" + | "RUN_FINISHED" + | "RUN_ERROR" + | "TEXT_MESSAGE_START" + | "TEXT_MESSAGE_CONTENT" + | "TEXT_MESSAGE_END" + | "TOOL_CALL_START" + | "TOOL_CALL_ARGS" + | "TOOL_CALL_END" + | "STEP_STARTED" + | "STEP_FINISHED" + | "STATE_SNAPSHOT" + | "STATE_DELTA" + | "CUSTOM" + | "content" + | "done" + | "error" + | "tool_call" + | "tool_result" + | "thinking" + | "approval-requested" + | "tool-input-available"; +``` + +Defined in: [types.ts:523](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L523) + +AG-UI Protocol event types. +Based on the AG-UI specification for agent-user interaction. + +## See + +https://docs.ag-ui.com/concepts/events + +Includes legacy type aliases for backward compatibility during migration. diff --git a/docs/reference/type-aliases/ExtractModalitiesForModel.md b/docs/reference/type-aliases/ExtractModalitiesForModel.md new file mode 100644 index 00000000..fc5a7043 --- /dev/null +++ b/docs/reference/type-aliases/ExtractModalitiesForModel.md @@ -0,0 +1,24 @@ +--- +id: ExtractModalitiesForModel +title: ExtractModalitiesForModel +--- + +# Type Alias: ExtractModalitiesForModel\ + +```ts +type ExtractModalitiesForModel = TAdapter extends AIAdapter ? TModel extends keyof ModelInputModalities ? ModelInputModalities[TModel] : ReadonlyArray : ReadonlyArray; +``` + +Defined in: [types.ts:1132](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L1132) + +Extract the supported input modalities for a specific model from an adapter. + +## Type Parameters + +### TAdapter + +`TAdapter` *extends* [`AIAdapter`](../interfaces/AIAdapter.md)\<`any`, `any`, `any`, `any`, `any`, `any`\> + +### TModel + +`TModel` *extends* `string` diff --git a/docs/reference/type-aliases/ExtractModelsFromAdapter.md b/docs/reference/type-aliases/ExtractModelsFromAdapter.md new file mode 100644 index 00000000..5eb7bcf4 --- /dev/null +++ b/docs/reference/type-aliases/ExtractModelsFromAdapter.md @@ -0,0 +1,18 @@ +--- +id: ExtractModelsFromAdapter +title: ExtractModelsFromAdapter +--- + +# Type Alias: ExtractModelsFromAdapter\ + +```ts +type ExtractModelsFromAdapter = T extends AIAdapter ? M[number] : never; +``` + +Defined in: [types.ts:1126](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L1126) + +## Type Parameters + +### T + +`T` diff --git a/docs/reference/type-aliases/InferToolInput.md b/docs/reference/type-aliases/InferToolInput.md new file mode 100644 index 00000000..0a3cc815 --- /dev/null +++ b/docs/reference/type-aliases/InferToolInput.md @@ -0,0 +1,20 @@ +--- +id: InferToolInput +title: InferToolInput +--- + +# Type Alias: InferToolInput\ + +```ts +type InferToolInput = T extends object ? TInput extends z.ZodType ? z.infer : 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) + +Extract the input type from a tool (inferred from Zod schema) + +## Type Parameters + +### T + +`T` diff --git a/docs/reference/type-aliases/InferToolName.md b/docs/reference/type-aliases/InferToolName.md new file mode 100644 index 00000000..25b0aa93 --- /dev/null +++ b/docs/reference/type-aliases/InferToolName.md @@ -0,0 +1,20 @@ +--- +id: InferToolName +title: InferToolName +--- + +# Type Alias: InferToolName\ + +```ts +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) + +Extract the tool name as a literal type + +## Type Parameters + +### T + +`T` diff --git a/docs/reference/type-aliases/InferToolOutput.md b/docs/reference/type-aliases/InferToolOutput.md new file mode 100644 index 00000000..f88a7393 --- /dev/null +++ b/docs/reference/type-aliases/InferToolOutput.md @@ -0,0 +1,20 @@ +--- +id: InferToolOutput +title: InferToolOutput +--- + +# Type Alias: InferToolOutput\ + +```ts +type InferToolOutput = T extends object ? TOutput extends z.ZodType ? z.infer : 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) + +Extract the output type from a tool (inferred from Zod schema) + +## Type Parameters + +### T + +`T` diff --git a/docs/reference/type-aliases/MessagePart.md b/docs/reference/type-aliases/MessagePart.md new file mode 100644 index 00000000..ab63fa58 --- /dev/null +++ b/docs/reference/type-aliases/MessagePart.md @@ -0,0 +1,16 @@ +--- +id: MessagePart +title: MessagePart +--- + +# Type Alias: MessagePart + +```ts +type MessagePart = + | TextPart + | ToolCallPart + | ToolResultPart + | ThinkingPart; +``` + +Defined in: [types.ts:214](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L214) diff --git a/docs/reference/type-aliases/ModalitiesArrayToUnion.md b/docs/reference/type-aliases/ModalitiesArrayToUnion.md new file mode 100644 index 00000000..6190668d --- /dev/null +++ b/docs/reference/type-aliases/ModalitiesArrayToUnion.md @@ -0,0 +1,21 @@ +--- +id: ModalitiesArrayToUnion +title: ModalitiesArrayToUnion +--- + +# Type Alias: ModalitiesArrayToUnion\ + +```ts +type ModalitiesArrayToUnion = T[number]; +``` + +Defined in: [types.ts:135](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L135) + +Helper type to convert a readonly array of modalities to a union type. +e.g., readonly ['text', 'image'] -> 'text' | 'image' + +## Type Parameters + +### T + +`T` *extends* `ReadonlyArray`\<[`Modality`](Modality.md)\> diff --git a/docs/reference/type-aliases/Modality.md b/docs/reference/type-aliases/Modality.md new file mode 100644 index 00000000..8c8e527e --- /dev/null +++ b/docs/reference/type-aliases/Modality.md @@ -0,0 +1,19 @@ +--- +id: Modality +title: Modality +--- + +# Type Alias: Modality + +```ts +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) + +Supported input modality types for multimodal content. +- 'text': Plain text content +- 'image': Image content (base64 or URL) +- 'audio': Audio content (base64 or URL) +- 'video': Video content (base64 or URL) +- 'document': Document content like PDFs (base64 or URL) diff --git a/docs/reference/type-aliases/StreamChunk.md b/docs/reference/type-aliases/StreamChunk.md new file mode 100644 index 00000000..cd750dda --- /dev/null +++ b/docs/reference/type-aliases/StreamChunk.md @@ -0,0 +1,38 @@ +--- +id: StreamChunk +title: StreamChunk +--- + +# Type Alias: StreamChunk + +```ts +type StreamChunk = + | RunStartedEvent + | RunFinishedEvent + | RunErrorEvent + | TextMessageStartEvent + | TextMessageContentEvent + | TextMessageEndEvent + | ToolCallStartEvent + | ToolCallArgsEvent + | ToolCallEndEvent + | StepStartedEvent + | StepFinishedEvent + | StateSnapshotEvent + | StateDeltaEvent + | CustomEvent + | ContentStreamChunk + | DoneStreamChunk + | ErrorStreamChunk + | ToolCallStreamChunk + | ToolResultStreamChunk + | ThinkingStreamChunk + | ApprovalRequestedStreamChunk + | ToolInputAvailableStreamChunk; +``` + +Defined in: [types.ts:722](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L722) + +Union type for all AG-UI events. +This is the primary type for streaming chat completions. +Includes legacy types for backward compatibility. diff --git a/docs/reference/type-aliases/StreamChunkType.md b/docs/reference/type-aliases/StreamChunkType.md new file mode 100644 index 00000000..01d942ea --- /dev/null +++ b/docs/reference/type-aliases/StreamChunkType.md @@ -0,0 +1,12 @@ +--- +id: StreamChunkType +title: StreamChunkType +--- + +# Type Alias: StreamChunkType + +```ts +type StreamChunkType = EventType; +``` + +Defined in: [types.ts:749](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L749) diff --git a/docs/reference/type-aliases/ToolCallState.md b/docs/reference/type-aliases/ToolCallState.md new file mode 100644 index 00000000..7ff8e334 --- /dev/null +++ b/docs/reference/type-aliases/ToolCallState.md @@ -0,0 +1,19 @@ +--- +id: ToolCallState +title: ToolCallState +--- + +# Type Alias: ToolCallState + +```ts +type ToolCallState = + | "awaiting-input" + | "input-streaming" + | "input-complete" + | "approval-requested" + | "approval-responded"; +``` + +Defined in: [stream/types.ts:13](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L13) + +Tool call states - track the lifecycle of a tool call diff --git a/docs/reference/type-aliases/ToolResultState.md b/docs/reference/type-aliases/ToolResultState.md new file mode 100644 index 00000000..d9d29e6e --- /dev/null +++ b/docs/reference/type-aliases/ToolResultState.md @@ -0,0 +1,14 @@ +--- +id: ToolResultState +title: ToolResultState +--- + +# Type Alias: ToolResultState + +```ts +type ToolResultState = "streaming" | "complete" | "error"; +``` + +Defined in: [stream/types.ts:23](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/types.ts#L23) + +Tool result states - track the lifecycle of a tool result diff --git a/docs/reference/variables/aiEventClient.md b/docs/reference/variables/aiEventClient.md new file mode 100644 index 00000000..b7d52031 --- /dev/null +++ b/docs/reference/variables/aiEventClient.md @@ -0,0 +1,12 @@ +--- +id: aiEventClient +title: aiEventClient +--- + +# Variable: aiEventClient + +```ts +const aiEventClient: AiEventClient; +``` + +Defined in: [event-client.ts:387](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/event-client.ts#L387) diff --git a/docs/reference/variables/defaultJSONParser.md b/docs/reference/variables/defaultJSONParser.md new file mode 100644 index 00000000..e5e32dad --- /dev/null +++ b/docs/reference/variables/defaultJSONParser.md @@ -0,0 +1,14 @@ +--- +id: defaultJSONParser +title: defaultJSONParser +--- + +# Variable: defaultJSONParser + +```ts +const defaultJSONParser: PartialJSONParser; +``` + +Defined in: [stream/json-parser.ts:49](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream/json-parser.ts#L49) + +Default parser instance diff --git a/packages/typescript/ai-openai/src/model-meta.ts b/packages/typescript/ai-openai/src/model-meta.ts index 67458882..024a6c1a 100644 --- a/packages/typescript/ai-openai/src/model-meta.ts +++ b/packages/typescript/ai-openai/src/model-meta.ts @@ -2,6 +2,7 @@ import type { OpenAIBaseOptions, OpenAIMetadataOptions, OpenAIReasoningOptions, + OpenAIReasoningOptionsWithConcise, OpenAIStreamingOptions, OpenAIStructuredOutputOptions, OpenAIToolsOptions, @@ -198,6 +199,7 @@ const GPT5_MINI = { }, } as const satisfies ModelMeta< OpenAIBaseOptions & + OpenAIReasoningOptions & OpenAIStructuredOutputOptions & OpenAIToolsOptions & OpenAIStreamingOptions & @@ -233,6 +235,7 @@ const GPT5_NANO = { }, } as const satisfies ModelMeta< OpenAIBaseOptions & + OpenAIReasoningOptions & OpenAIStructuredOutputOptions & OpenAIToolsOptions & OpenAIStreamingOptions & @@ -815,6 +818,7 @@ const COMPUTER_USE_PREVIEW = { }, } as const satisfies ModelMeta< OpenAIBaseOptions & + OpenAIReasoningOptionsWithConcise & OpenAIToolsOptions & OpenAIStreamingOptions & OpenAIMetadataOptions @@ -1787,11 +1791,13 @@ export type OpenAIChatModelProviderOptionsByName = { OpenAIStreamingOptions & OpenAIMetadataOptions [GPT5_MINI.name]: OpenAIBaseOptions & + OpenAIReasoningOptions & OpenAIStructuredOutputOptions & OpenAIToolsOptions & OpenAIStreamingOptions & OpenAIMetadataOptions [GPT5_NANO.name]: OpenAIBaseOptions & + OpenAIReasoningOptions & OpenAIStructuredOutputOptions & OpenAIToolsOptions & OpenAIStreamingOptions & @@ -1920,6 +1926,7 @@ export type OpenAIChatModelProviderOptionsByName = { // Special models [COMPUTER_USE_PREVIEW.name]: OpenAIBaseOptions & + OpenAIReasoningOptionsWithConcise & OpenAIToolsOptions & OpenAIStreamingOptions & OpenAIMetadataOptions diff --git a/packages/typescript/ai-openai/src/openai-adapter.ts b/packages/typescript/ai-openai/src/openai-adapter.ts index fbd8b537..ef9d586e 100644 --- a/packages/typescript/ai-openai/src/openai-adapter.ts +++ b/packages/typescript/ai-openai/src/openai-adapter.ts @@ -384,6 +384,41 @@ export class OpenAI extends BaseAdapter< } } + // Handle reasoning summary deltas (when using reasoning.summary option) + // response.reasoning_summary_text.delta provides incremental summary updates + if ( + chunk.type === 'response.reasoning_summary_text.delta' && + chunk.delta + ) { + const summaryDelta = + typeof chunk.delta === 'string' ? chunk.delta : '' + + if (summaryDelta) { + // Emit STEP_STARTED on first reasoning content (reuse existing flag) + if (!hasEmittedStepStarted) { + hasEmittedStepStarted = true + yield { + type: 'STEP_STARTED', + stepId: stepId || generateId(), + model: model || options.model, + timestamp, + stepType: 'thinking', + } + } + + accumulatedReasoning += summaryDelta + hasStreamedReasoningDeltas = true + yield { + type: 'STEP_FINISHED', + stepId: stepId || generateId(), + model: model || options.model, + timestamp, + delta: summaryDelta, + content: accumulatedReasoning, + } + } + } + // handle content_part added events for text, reasoning and refusals if (chunk.type === 'response.content_part.added') { const contentPart = chunk.part diff --git a/packages/typescript/ai-openai/src/text/text-provider-options.ts b/packages/typescript/ai-openai/src/text/text-provider-options.ts index 23fdf0fa..85424f00 100644 --- a/packages/typescript/ai-openai/src/text/text-provider-options.ts +++ b/packages/typescript/ai-openai/src/text/text-provider-options.ts @@ -125,6 +125,14 @@ https://platform.openai.com/docs/api-reference/responses/create#responses_create } // Feature fragments that can be stitched per-model + +// Shared base types for reasoning options +type ReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' +type ReasoningSummary = 'auto' | 'detailed' + +/** + * Reasoning options for most models (excludes 'concise' summary). + */ export interface OpenAIReasoningOptions { /** * Reasoning controls for models that support it. @@ -138,13 +146,39 @@ export interface OpenAIReasoningOptions { * All models before gpt-5.1 default to medium reasoning effort, and do not support none. * The gpt-5-pro model defaults to (and only supports) high reasoning effort. */ - effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' + effort?: ReasoningEffort + /** + * A summary of the reasoning performed by the model. This can be useful for debugging and understanding the model's reasoning process. + * https://platform.openai.com/docs/api-reference/responses/create#responses_create-reasoning-summary + */ + summary?: ReasoningSummary } +} + +/** + * Reasoning options for computer-use-preview model (includes 'concise' summary). + */ +export interface OpenAIReasoningOptionsWithConcise { /** - * A summary of the reasoning performed by the model. This can be useful for debugging and understanding the model's reasoning process - * https://platform.openai.com/docs/api-reference/responses/create#responses_create-reasoning-summary + * Reasoning controls for models that support it. + * Lets you guide how much chain-of-thought computation to spend. + * https://platform.openai.com/docs/api-reference/responses/create#responses_create-reasoning + * https://platform.openai.com/docs/guides/reasoning */ - summary?: 'auto' | 'concise' | 'detailed' + reasoning?: { + /** + * gpt-5.1 defaults to none, which does not perform reasoning. The supported reasoning values for gpt-5.1 are none, low, medium, and high. Tool calls are supported for all reasoning values in gpt-5.1. + * All models before gpt-5.1 default to medium reasoning effort, and do not support none. + * The gpt-5-pro model defaults to (and only supports) high reasoning effort. + */ + effort?: ReasoningEffort + /** + * A summary of the reasoning performed by the model. This can be useful for debugging and understanding the model's reasoning process. + * `concise` is only supported for `computer-use-preview` models. + * https://platform.openai.com/docs/api-reference/responses/create#responses_create-reasoning-summary + */ + summary?: ReasoningSummary | 'concise' + } } export interface OpenAIStructuredOutputOptions { diff --git a/packages/typescript/ai-openai/tests/model-meta.test.ts b/packages/typescript/ai-openai/tests/model-meta.test.ts index bd8f316e..84af55dc 100644 --- a/packages/typescript/ai-openai/tests/model-meta.test.ts +++ b/packages/typescript/ai-openai/tests/model-meta.test.ts @@ -6,6 +6,7 @@ import type { import type { OpenAIBaseOptions, OpenAIReasoningOptions, + OpenAIReasoningOptionsWithConcise, OpenAIStructuredOutputOptions, OpenAIToolsOptions, OpenAIStreamingOptions, @@ -111,12 +112,12 @@ describe('OpenAI Chat Model Provider Options Type Assertions', () => { }) }) - describe('Models WITH structured output AND tools but WITHOUT reasoning (Standard)', () => { - it('gpt-5-mini should have structured output and tools but NOT reasoning', () => { + describe('Models WITH reasoning AND structured output AND tools (gpt-5-mini/nano)', () => { + it('gpt-5-mini should have reasoning, structured output and tools', () => { type Options = OpenAIChatModelProviderOptionsByName['gpt-5-mini'] - // Should NOT have reasoning options - expectTypeOf().not.toExtend() + // Should have reasoning options + expectTypeOf().toExtend() // Should have structured output options expectTypeOf().toExtend() @@ -131,16 +132,18 @@ describe('OpenAI Chat Model Provider Options Type Assertions', () => { expectTypeOf().toExtend() }) - it('gpt-5-nano should have structured output and tools but NOT reasoning', () => { + it('gpt-5-nano should have reasoning, structured output and tools', () => { type Options = OpenAIChatModelProviderOptionsByName['gpt-5-nano'] - expectTypeOf().not.toExtend() + expectTypeOf().toExtend() expectTypeOf().toExtend() expectTypeOf().toExtend() expectTypeOf().toExtend() expectTypeOf().toExtend() }) + }) + describe('Models WITH structured output AND tools but WITHOUT reasoning (Standard)', () => { it('gpt-5-codex should have structured output and tools but NOT reasoning', () => { type Options = OpenAIChatModelProviderOptionsByName['gpt-5-codex'] @@ -439,11 +442,12 @@ describe('OpenAI Chat Model Provider Options Type Assertions', () => { expectTypeOf().toExtend() }) - it('computer-use-preview should have tools but NOT structured output', () => { + it('computer-use-preview should have tools and reasoning with concise but NOT structured output', () => { type Options = OpenAIChatModelProviderOptionsByName['computer-use-preview'] - expectTypeOf().not.toExtend() + // Should have reasoning options with 'concise' summary support + expectTypeOf().toExtend() expectTypeOf().not.toExtend() expectTypeOf().toExtend() expectTypeOf().toExtend() @@ -462,8 +466,6 @@ describe('OpenAI Chat Model Provider Options Type Assertions', () => { expectTypeOf<'gpt-5-pro'>().toExtend() // Standard models (structured output + tools, no reasoning) - expectTypeOf<'gpt-5-mini'>().toExtend() - expectTypeOf<'gpt-5-nano'>().toExtend() expectTypeOf<'gpt-5-codex'>().toExtend() expectTypeOf<'gpt-4.1'>().toExtend() expectTypeOf<'gpt-4.1-mini'>().toExtend() @@ -696,15 +698,15 @@ describe('OpenAI Chat Model Provider Options Type Assertions', () => { expectTypeOf< OpenAIChatModelProviderOptionsByName['gpt-5-pro'] >().toExtend() - }) - - it('standard models should NOT extend reasoning options but should extend structured output and tools', () => { expectTypeOf< OpenAIChatModelProviderOptionsByName['gpt-5-mini'] - >().toExtend() + >().toExtend() expectTypeOf< OpenAIChatModelProviderOptionsByName['gpt-5-nano'] - >().toExtend() + >().toExtend() + }) + + it('standard models should NOT extend reasoning options but should extend structured output and tools', () => { expectTypeOf< OpenAIChatModelProviderOptionsByName['gpt-4.1'] >().toExtend() @@ -719,9 +721,6 @@ describe('OpenAI Chat Model Provider Options Type Assertions', () => { >().toExtend() // Verify these do NOT extend reasoning options (discrimination already tested above) - expectTypeOf< - OpenAIChatModelProviderOptionsByName['gpt-5-mini'] - >().not.toExtend() expectTypeOf< OpenAIChatModelProviderOptionsByName['gpt-4.1'] >().not.toExtend() diff --git a/packages/typescript/ai/src/core/chat.ts b/packages/typescript/ai/src/core/chat.ts index 9d5346d1..2c48ba94 100644 --- a/packages/typescript/ai/src/core/chat.ts +++ b/packages/typescript/ai/src/core/chat.ts @@ -315,11 +315,16 @@ class ChatEngine< ): void { this.toolCallManager.completeToolCall(chunk.toolCallId, chunk.input) if (chunk.result !== undefined) { + // Serialize result to string + const resultString = + typeof chunk.result === 'string' + ? chunk.result + : JSON.stringify(chunk.result) aiEventClient.emit('stream:chunk:tool-result', { streamId: this.streamId, messageId: this.currentMessageId || undefined, toolCallId: chunk.toolCallId, - result: chunk.result, + result: resultString, timestamp: Date.now(), }) } diff --git a/packages/typescript/ai/tests/ai-chat.test.ts b/packages/typescript/ai/tests/ai-chat.test.ts index 44fae68f..be8da054 100644 --- a/packages/typescript/ai/tests/ai-chat.test.ts +++ b/packages/typescript/ai/tests/ai-chat.test.ts @@ -2420,6 +2420,7 @@ describe('chat() - Comprehensive Logic Path Coverage', () => { this.trackStreamCall(options) yield { type: 'TEXT_MESSAGE_CONTENT', + messageId: 'test-msg-id', model: 'test-model', timestamp: Date.now(), delta: 'Using tool', @@ -2460,9 +2461,9 @@ describe('chat() - Comprehensive Logic Path Coverage', () => { ) expect(toolResultEvents.length).toBeGreaterThan(0) expect(toolResultEvents[0]?.data.toolCallId).toBe('call-previous') - expect(toolResultEvents[0]?.data.result).toEqual({ - result: 'previous result', - }) + expect(toolResultEvents[0]?.data.result).toBe( + JSON.stringify({ result: 'previous result' }), + ) }) })