Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/adapters/elevenlabs.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const token = await realtimeToken({

### React (useRealtimeChat)

```typescript
```tsx
import { useRealtimeChat } from '@tanstack/ai-react'
import { elevenlabsRealtime } from '@tanstack/ai-elevenlabs'

Expand Down
8 changes: 4 additions & 4 deletions docs/api/ai-preact.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ npm install @tanstack/ai-preact

Main hook for managing chat state in Preact with full type safety.

```typescript
```tsx
import { useChat, fetchServerSentEvents } from "@tanstack/ai-preact";
import {
clientTools,
Expand Down Expand Up @@ -119,7 +119,7 @@ import {

## Example: Basic Chat

```typescript
```tsx
import { useState } from "preact/hooks";
import { useChat, fetchServerSentEvents } from "@tanstack/ai-preact";

Expand Down Expand Up @@ -177,7 +177,7 @@ export function Chat() {

## Example: Tool Approval

```typescript
```tsx
import { useChat, fetchServerSentEvents } from "@tanstack/ai-preact";

export function ChatWithApproval() {
Expand Down Expand Up @@ -230,7 +230,7 @@ export function ChatWithApproval() {

## Example: Client Tools with Type Safety

```typescript
```tsx
import { useChat, fetchServerSentEvents } from "@tanstack/ai-preact";
import {
clientTools,
Expand Down
8 changes: 4 additions & 4 deletions docs/api/ai-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ npm install @tanstack/ai-react

Main hook for managing chat state in React with full type safety.

```typescript
```tsx
import { useChat, fetchServerSentEvents } from "@tanstack/ai-react";
import {
clientTools,
Expand Down Expand Up @@ -144,7 +144,7 @@ For error narrowing, import `UnsupportedResponseStreamError` and

## Example: Basic Chat

```typescript
```tsx
import { useState } from "react";
import { useChat, fetchServerSentEvents } from "@tanstack/ai-react";

Expand Down Expand Up @@ -202,7 +202,7 @@ export function Chat() {

## Example: Tool Approval

```typescript
```tsx
import { useChat, fetchServerSentEvents } from "@tanstack/ai-react";

export function ChatWithApproval() {
Expand Down Expand Up @@ -255,7 +255,7 @@ export function ChatWithApproval() {

## Example: Client Tools with Type Safety

```typescript
```tsx
import { useChat, fetchServerSentEvents } from "@tanstack/ai-react";
import {
clientTools,
Expand Down
8 changes: 4 additions & 4 deletions docs/api/ai-solid.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ npm install @tanstack/ai-solid

Main primitive for managing chat state in SolidJS with full type safety.

```typescript
```tsx
import { useChat, fetchServerSentEvents } from "@tanstack/ai-solid";
import {
clientTools,
Expand Down Expand Up @@ -122,7 +122,7 @@ import {

## Example: Basic Chat

```typescript
```tsx
import { createSignal, For } from "solid-js";
import { useChat, fetchServerSentEvents } from "@tanstack/ai-solid";

Expand Down Expand Up @@ -184,7 +184,7 @@ export function Chat() {

## Example: Tool Approval

```typescript
```tsx
import { For, Show } from "solid-js";
import { useChat, fetchServerSentEvents } from "@tanstack/ai-solid";

Expand Down Expand Up @@ -241,7 +241,7 @@ export function ChatWithApproval() {

## Example: Client Tools with Type Safety

```typescript
```tsx
import { useChat, fetchServerSentEvents } from "@tanstack/ai-solid";
import {
clientTools,
Expand Down
4 changes: 2 additions & 2 deletions docs/code-mode/client-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Events are keyed by `toolCallId` so each `execute_typescript` call gets its own

When rendering messages, check for `execute_typescript` tool calls and display their events:

```typescript
```tsx
function MessageList({
messages,
toolCallEvents,
Expand Down Expand Up @@ -142,7 +142,7 @@ function MessageList({

Here's a complete `CodeExecutionPanel` component that shows the generated code, live event stream, and final result:

```typescript
```tsx
function CodeExecutionPanel({
code,
events,
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export async function POST(request: Request) {

To use the chat API from your React frontend, create a `Chat` component:

```typescript
```tsx
// components/Chat.tsx
import { useState } from "react";
import { useChat, fetchServerSentEvents } from "@tanstack/ai-react";
Expand Down
8 changes: 4 additions & 4 deletions docs/media/realtime-chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const getRealtimeToken = createServerFn({ method: 'POST' })

### 2. Connect from the Client (React)

```typescript
```tsx
import { useRealtimeChat } from '@tanstack/ai-react'
import { openaiRealtime } from '@tanstack/ai-openai'

Expand Down Expand Up @@ -194,7 +194,7 @@ const { startListening, stopListening, vadMode, setVADMode } = useRealtimeChat({

With `manual` VAD mode, use push-to-talk style interactions:

```typescript
```tsx
<button onMouseDown={startListening} onMouseUp={stopListening}>
Hold to talk
</button>
Expand Down Expand Up @@ -283,13 +283,13 @@ The `inputLevel` and `outputLevel` values update on every animation frame while

**Simple level meter:**

```typescript
```tsx
<div style={{ width: `${inputLevel * 100}%`, height: 4, background: 'green' }} />
```

**Pulsing audio indicator:**

```typescript
```tsx
function AudioIndicator({ level }: { level: number }) {
return (
<div
Expand Down
14 changes: 7 additions & 7 deletions docs/migration/migration-from-vercel-ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ const stream = chat({

#### Before (Vercel AI SDK v5+)

```typescript
```tsx
import { useChat } from '@ai-sdk/react'
import { DefaultChatTransport } from 'ai'
import { useState } from 'react'
Expand Down Expand Up @@ -309,7 +309,7 @@ export function Chat() {

#### After (TanStack AI)

```typescript
```tsx
import { useState } from 'react'
import { useChat, fetchServerSentEvents } from '@tanstack/ai-react'

Expand Down Expand Up @@ -442,7 +442,7 @@ type ToolResultState = 'streaming' | 'complete' | 'error'

#### Before (Vercel AI SDK)

```typescript
```tsx
{messages.map((m) => (
<div key={m.id}>
{m.role}: {m.content}
Expand All @@ -457,7 +457,7 @@ type ToolResultState = 'streaming' | 'complete' | 'error'

#### After (TanStack AI)

```typescript
```tsx
{messages.map((message) => (
<div key={message.id}>
{message.role}:{' '}
Expand Down Expand Up @@ -634,7 +634,7 @@ const { messages, addToolApprovalResponse } = useChat({

#### After (TanStack AI)

```typescript
```tsx
// Built-in approval support
const bookFlightDef = toolDefinition({
name: 'bookFlight',
Expand Down Expand Up @@ -1316,7 +1316,7 @@ Vercel's `maxRetries` / `timeout` options have no direct `chat()` equivalent. Us

### Before (Vercel AI SDK v5+)

```typescript
```tsx
// server/api/chat.ts
import { streamText, tool, convertToModelMessages } from 'ai'
import { openai } from '@ai-sdk/openai'
Expand Down Expand Up @@ -1383,7 +1383,7 @@ export function Chat() {

### After (TanStack AI)

```typescript
```tsx
// server/api/chat.ts
import { chat, toServerSentEventsResponse, toolDefinition } from '@tanstack/ai'
import { openaiText } from '@tanstack/ai-openai'
Expand Down
4 changes: 2 additions & 2 deletions docs/tools/client-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export async function POST(request: Request) {

Create client implementations with automatic execution and full type safety:

```typescript
```tsx
// app/chat.tsx
import { useChat, fetchServerSentEvents } from "@tanstack/ai-react";
import {
Expand Down Expand Up @@ -277,7 +277,7 @@ A `tool-call` part moves through a small set of observable `ToolCallState` value

The `ToolCallState` union includes a `complete` value, but the runtime never transitions a tool-call part to it — a finished call settles at `input-complete`. Once the tool runs, the result appears two ways: `part.output` becomes populated on the tool-call part, and a sibling `tool-result` part is emitted whose own `state` is `complete` or `error` (the `error` case carries `part.error`). Use the tool-call states for loading/streaming progress and the tool-result part for final success/error feedback.

```typescript
```tsx
import type { ToolCallPart } from "@tanstack/ai-client";

function ToolCallDisplay({ part }: { part: ToolCallPart }) {
Expand Down
6 changes: 3 additions & 3 deletions docs/tools/tool-approval.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export async function POST(request: Request) {

The client receives approval requests and can respond:

```typescript
```tsx
import { useChat, fetchServerSentEvents } from "@tanstack/ai-react";

function ChatComponent() {
Expand Down Expand Up @@ -148,7 +148,7 @@ function ChatComponent() {

Here's a more complete approval UI component:

```typescript
```tsx
import type { ToolCallPart } from "@tanstack/ai-client";

function ApprovalPrompt({
Expand Down Expand Up @@ -195,7 +195,7 @@ function ApprovalPrompt({

Wire it up from your message renderer. Note the `id` you pass is the **approval id** (`part.approval.id`), not the tool call id:

```typescript
```tsx
{part.type === "tool-call" &&
part.state === "approval-requested" &&
part.approval && (
Expand Down
6 changes: 3 additions & 3 deletions docs/tools/tool-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function POST(request: Request) {

**Client (React Component):**

```typescript
```tsx
import { useState } from "react";
import { useChat, fetchServerSentEvents } from "@tanstack/ai-react";

Expand Down Expand Up @@ -180,7 +180,7 @@ stateDiagram-v2

### Monitoring Tool States in React

```typescript
```tsx
import { useChat, fetchServerSentEvents } from "@tanstack/ai-react";
import { clientTools, createChatClientOptions } from "@tanstack/ai-client";
import { getWeather, sendEmail } from "./tools";
Expand Down Expand Up @@ -285,7 +285,7 @@ const sendEmail = sendEmailDef.server(async ({ to, subject, body }) => {

**Handle approval in client:**

```typescript
```tsx
const { messages, addToolApprovalResponse } = useChat({
connection: fetchServerSentEvents("/api/chat"),
});
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export async function POST(request: Request) {

### Client-Side with Type Safety

```typescript
```tsx
import { useChat, fetchServerSentEvents } from "@tanstack/ai-react";
import {
clientTools,
Expand Down
Loading