@assistant-ui/mcp-docs-server 0.1.29 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/code-examples/waterfall.md +15 -7
- package/.docs/organized/code-examples/with-a2a.md +9 -21
- package/.docs/organized/code-examples/with-ag-ui.md +11 -8
- package/.docs/organized/code-examples/with-ai-sdk-v6.md +10 -10
- package/.docs/organized/code-examples/with-artifacts.md +12 -10
- package/.docs/organized/code-examples/with-assistant-transport.md +11 -12
- package/.docs/organized/code-examples/with-chain-of-thought.md +83 -54
- package/.docs/organized/code-examples/with-cloud-standalone.md +14 -11
- package/.docs/organized/code-examples/with-cloud.md +9 -10
- package/.docs/organized/code-examples/with-custom-thread-list.md +61 -16
- package/.docs/organized/code-examples/with-elevenlabs-conversational.md +17 -12
- package/.docs/organized/code-examples/with-elevenlabs-scribe.md +13 -13
- package/.docs/organized/code-examples/with-expo.md +25 -21
- package/.docs/organized/code-examples/with-external-store.md +8 -8
- package/.docs/organized/code-examples/with-ffmpeg.md +17 -12
- package/.docs/organized/code-examples/with-generative-ui.md +9 -9
- package/.docs/organized/code-examples/with-google-adk.md +8 -8
- package/.docs/organized/code-examples/with-heat-graph.md +5 -5
- package/.docs/organized/code-examples/with-interactables.md +10 -25
- package/.docs/organized/code-examples/with-langchain.md +437 -0
- package/.docs/organized/code-examples/with-langgraph.md +16 -16
- package/.docs/organized/code-examples/with-livekit.md +18 -13
- package/.docs/organized/code-examples/with-opencode.md +105 -62
- package/.docs/organized/code-examples/with-parent-id-grouping.md +10 -10
- package/.docs/organized/code-examples/with-react-hook-form.md +220 -148
- package/.docs/organized/code-examples/with-react-ink.md +2 -2
- package/.docs/organized/code-examples/with-react-router.md +12 -12
- package/.docs/organized/code-examples/with-store.md +8 -5
- package/.docs/organized/code-examples/with-tanstack.md +10 -10
- package/.docs/organized/code-examples/with-tap-runtime.md +10 -6
- package/.docs/raw/docs/(docs)/cli.mdx +2 -1
- package/.docs/raw/docs/(docs)/copilots/assistant-frame.mdx +1 -0
- package/.docs/raw/docs/(docs)/copilots/make-assistant-tool-ui.mdx +10 -3
- package/.docs/raw/docs/(docs)/copilots/make-assistant-tool.mdx +8 -3
- package/.docs/raw/docs/(docs)/copilots/make-assistant-visible.mdx +1 -0
- package/.docs/raw/docs/(docs)/copilots/model-context.mdx +1 -0
- package/.docs/raw/docs/(docs)/copilots/motivation.mdx +1 -0
- package/.docs/raw/docs/(docs)/copilots/use-assistant-instructions.mdx +1 -0
- package/.docs/raw/docs/(docs)/devtools.mdx +1 -0
- package/.docs/raw/docs/(docs)/index.mdx +1 -0
- package/.docs/raw/docs/(docs)/installation.mdx +1 -0
- package/.docs/raw/docs/(docs)/rtl.mdx +80 -0
- package/.docs/raw/docs/(reference)/api-reference/adapters/attachments.mdx +34 -0
- package/.docs/raw/docs/(reference)/api-reference/adapters/feedback-speech.mdx +41 -0
- package/.docs/raw/docs/(reference)/api-reference/adapters/index.mdx +26 -0
- package/.docs/raw/docs/(reference)/api-reference/adapters/persistence.mdx +34 -0
- package/.docs/raw/docs/(reference)/api-reference/adapters/runtime.mdx +31 -0
- package/.docs/raw/docs/(reference)/api-reference/context-providers/index.mdx +20 -0
- package/.docs/raw/docs/(reference)/api-reference/hooks/index.mdx +26 -0
- package/.docs/raw/docs/(reference)/api-reference/hooks/model-context.mdx +72 -0
- package/.docs/raw/docs/(reference)/api-reference/hooks/runtimes.mdx +41 -0
- package/.docs/raw/docs/(reference)/api-reference/hooks/state.mdx +48 -0
- package/.docs/raw/docs/(reference)/api-reference/hooks/utilities.mdx +30 -0
- package/.docs/raw/docs/(reference)/api-reference/integrations/index.mdx +23 -0
- package/.docs/raw/docs/(reference)/api-reference/overview.mdx +21 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-if.mdx +7 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/composer.mdx +149 -40
- package/.docs/raw/docs/(reference)/api-reference/primitives/index.mdx +65 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/message-part.mdx +2 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/message.mdx +50 -6
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list.mdx +15 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread.mdx +36 -1
- package/.docs/raw/docs/(reference)/api-reference/runtimes/index.mdx +38 -0
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-runtime.mdx +9 -0
- package/.docs/raw/docs/(reference)/migrations/v0-14.mdx +144 -6
- package/.docs/raw/docs/cloud/ai-sdk-assistant-ui.mdx +231 -3
- package/.docs/raw/docs/cloud/ai-sdk.mdx +221 -3
- package/.docs/raw/docs/cloud/langgraph.mdx +274 -2
- package/.docs/raw/docs/{(docs)/guides → guides}/attachments.mdx +41 -36
- package/.docs/raw/docs/guides/branching.mdx +76 -0
- package/.docs/raw/docs/guides/chain-of-thought.mdx +166 -0
- package/.docs/raw/docs/{(docs)/guides → guides}/context-api.mdx +50 -22
- package/.docs/raw/docs/{(docs)/guides → guides}/dictation.mdx +2 -0
- package/.docs/raw/docs/guides/editing.mdx +102 -0
- package/.docs/raw/docs/guides/index.mdx +103 -0
- package/.docs/raw/docs/{(docs)/guides → guides}/interactables.mdx +49 -0
- package/.docs/raw/docs/{(docs)/guides → guides}/latex.mdx +51 -8
- package/.docs/raw/docs/guides/mentions.mdx +520 -0
- package/.docs/raw/docs/{(docs)/guides → guides}/message-timing.mdx +8 -2
- package/.docs/raw/docs/{(docs)/guides → guides}/multi-agent.mdx +64 -4
- package/.docs/raw/docs/{(docs)/guides → guides}/quoting.mdx +10 -17
- package/.docs/raw/docs/guides/slash-commands.mdx +361 -0
- package/.docs/raw/docs/guides/speech.mdx +156 -0
- package/.docs/raw/docs/{(docs)/guides → guides}/suggestions.mdx +21 -83
- package/.docs/raw/docs/{(docs)/guides → guides}/tool-ui.mdx +108 -36
- package/.docs/raw/docs/{(docs)/guides → guides}/tools.mdx +131 -35
- package/.docs/raw/docs/{(docs)/guides → guides}/voice.mdx +39 -0
- package/.docs/raw/docs/ink/index.mdx +1 -3
- package/.docs/raw/docs/ink/migration.mdx +1 -3
- package/.docs/raw/docs/ink/primitives.mdx +37 -1
- package/.docs/raw/docs/integrations/attachments/custom-adapter.mdx +520 -0
- package/.docs/raw/docs/integrations/auth/better-auth.mdx +191 -0
- package/.docs/raw/docs/integrations/auth/clerk.mdx +172 -0
- package/.docs/raw/docs/integrations/auth/next-auth.mdx +196 -0
- package/.docs/raw/docs/integrations/frameworks/ai-sdk.mdx +79 -0
- package/.docs/raw/docs/integrations/frameworks/mastra/full-stack.mdx +188 -0
- package/.docs/raw/docs/integrations/frameworks/mastra/overview.mdx +57 -0
- package/.docs/raw/docs/integrations/frameworks/mastra/separate-server.mdx +201 -0
- package/.docs/raw/docs/integrations/gateways/index.mdx +157 -0
- package/.docs/raw/docs/integrations/index.mdx +173 -0
- package/.docs/raw/docs/integrations/observability/helicone.mdx +130 -0
- package/.docs/raw/docs/integrations/observability/langfuse.mdx +156 -0
- package/.docs/raw/docs/integrations/observability/langsmith.mdx +146 -0
- package/.docs/raw/docs/integrations/persistence/custom-adapter.mdx +712 -0
- package/.docs/raw/docs/integrations/tools/mcp.mdx +267 -0
- package/.docs/raw/docs/primitives/action-bar.mdx +1 -0
- package/.docs/raw/docs/primitives/assistant-modal.mdx +1 -0
- package/.docs/raw/docs/primitives/attachment.mdx +1 -0
- package/.docs/raw/docs/primitives/branch-picker.mdx +1 -0
- package/.docs/raw/docs/primitives/chain-of-thought.mdx +90 -85
- package/.docs/raw/docs/primitives/composer.mdx +96 -63
- package/.docs/raw/docs/primitives/error.mdx +1 -0
- package/.docs/raw/docs/primitives/index.mdx +2 -1
- package/.docs/raw/docs/primitives/message.mdx +68 -5
- package/.docs/raw/docs/primitives/selection-toolbar.mdx +1 -0
- package/.docs/raw/docs/primitives/suggestion.mdx +1 -0
- package/.docs/raw/docs/primitives/thread-list.mdx +39 -0
- package/.docs/raw/docs/primitives/thread.mdx +16 -13
- package/.docs/raw/docs/react-native/index.mdx +1 -3
- package/.docs/raw/docs/react-native/migration.mdx +1 -3
- package/.docs/raw/docs/runtimes/a2a/client-and-hooks.mdx +396 -0
- package/.docs/raw/docs/runtimes/a2a/overview.mdx +60 -0
- package/.docs/raw/docs/runtimes/a2a/quickstart.mdx +216 -0
- package/.docs/raw/docs/runtimes/ag-ui/overview.mdx +70 -0
- package/.docs/raw/docs/runtimes/ag-ui/quickstart.mdx +243 -0
- package/.docs/raw/docs/runtimes/ag-ui/runtime-options.mdx +123 -0
- package/.docs/raw/docs/runtimes/ai-sdk/overview.mdx +52 -0
- package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +71 -131
- package/.docs/raw/docs/runtimes/ai-sdk/v5-legacy.mdx +69 -63
- package/.docs/raw/docs/runtimes/ai-sdk/v6.mdx +365 -101
- package/.docs/raw/docs/runtimes/concepts/adapters.mdx +265 -0
- package/.docs/raw/docs/runtimes/concepts/architecture.mdx +125 -0
- package/.docs/raw/docs/runtimes/concepts/stability.mdx +67 -0
- package/.docs/raw/docs/runtimes/concepts/threads.mdx +428 -0
- package/.docs/raw/docs/runtimes/custom/assistant-transport.mdx +703 -0
- package/.docs/raw/docs/runtimes/custom/data-stream.mdx +323 -0
- package/.docs/raw/docs/runtimes/custom/external-store.mdx +253 -1236
- package/.docs/raw/docs/runtimes/custom/local-runtime.mdx +746 -0
- package/.docs/raw/docs/runtimes/custom/overview.mdx +71 -0
- package/.docs/raw/docs/runtimes/google-adk/api.mdx +256 -0
- package/.docs/raw/docs/runtimes/google-adk/hooks.mdx +717 -0
- package/.docs/raw/docs/runtimes/google-adk/overview.mdx +69 -0
- package/.docs/raw/docs/runtimes/google-adk/quickstart.mdx +229 -0
- package/.docs/raw/docs/runtimes/langchain.mdx +533 -0
- package/.docs/raw/docs/runtimes/langgraph/generative-ui.mdx +305 -0
- package/.docs/raw/docs/runtimes/langgraph/interrupts.mdx +104 -0
- package/.docs/raw/docs/runtimes/langgraph/overview.mdx +84 -0
- package/.docs/raw/docs/runtimes/langgraph/quickstart.mdx +496 -0
- package/.docs/raw/docs/runtimes/langgraph/streaming.mdx +127 -0
- package/.docs/raw/docs/runtimes/langgraph/threads.mdx +113 -0
- package/.docs/raw/docs/runtimes/langgraph/tutorial/introduction.mdx +3 -3
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-1.mdx +0 -23
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +1 -1
- package/.docs/raw/docs/runtimes/opencode/hooks.mdx +191 -0
- package/.docs/raw/docs/runtimes/opencode/overview.mdx +48 -0
- package/.docs/raw/docs/runtimes/opencode/quickstart.mdx +119 -0
- package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +74 -198
- package/.docs/raw/docs/ui/accordion.mdx +1 -0
- package/.docs/raw/docs/ui/assistant-modal.mdx +1 -0
- package/.docs/raw/docs/ui/assistant-sidebar.mdx +1 -0
- package/.docs/raw/docs/ui/attachment.mdx +1 -0
- package/.docs/raw/docs/ui/badge.mdx +1 -0
- package/.docs/raw/docs/ui/composer-trigger-popover.mdx +200 -0
- package/.docs/raw/docs/ui/context-display.mdx +1 -0
- package/.docs/raw/docs/ui/diff-viewer.mdx +1 -0
- package/.docs/raw/docs/ui/directive-text.mdx +114 -0
- package/.docs/raw/docs/ui/file.mdx +1 -0
- package/.docs/raw/docs/ui/image.mdx +1 -0
- package/.docs/raw/docs/ui/markdown.mdx +2 -14
- package/.docs/raw/docs/ui/mermaid.mdx +1 -0
- package/.docs/raw/docs/ui/message-timing.mdx +3 -2
- package/.docs/raw/docs/ui/model-selector.mdx +1 -0
- package/.docs/raw/docs/ui/part-grouping.mdx +325 -313
- package/.docs/raw/docs/ui/quote.mdx +1 -0
- package/.docs/raw/docs/ui/reasoning.mdx +69 -32
- package/.docs/raw/docs/ui/scrollbar.mdx +1 -0
- package/.docs/raw/docs/ui/select.mdx +1 -0
- package/.docs/raw/docs/ui/sources.mdx +1 -0
- package/.docs/raw/docs/ui/streamdown.mdx +1 -0
- package/.docs/raw/docs/ui/syntax-highlighting.mdx +1 -0
- package/.docs/raw/docs/ui/tabs.mdx +1 -0
- package/.docs/raw/docs/ui/thread-list.mdx +17 -0
- package/.docs/raw/docs/ui/thread.mdx +56 -1
- package/.docs/raw/docs/ui/tool-fallback.mdx +1 -0
- package/.docs/raw/docs/ui/tool-group.mdx +39 -11
- package/.docs/raw/docs/ui/voice.mdx +1 -0
- package/.docs/raw/docs/utilities/heat-graph.mdx +1 -0
- package/.docs/raw/docs/utilities/react-o11y.mdx +278 -0
- package/.docs/raw/docs/utilities/tw-shimmer.mdx +1 -0
- package/dist/utils/logger.js +1 -1
- package/dist/utils/logger.js.map +1 -1
- package/package.json +4 -4
- package/src/tools/tests/path-traversal.test.ts +1 -1
- package/src/utils/logger.ts +1 -1
- package/.docs/raw/docs/(docs)/guides/branching.mdx +0 -65
- package/.docs/raw/docs/(docs)/guides/chain-of-thought.mdx +0 -164
- package/.docs/raw/docs/(docs)/guides/editing.mdx +0 -66
- package/.docs/raw/docs/(docs)/guides/mentions.mdx +0 -406
- package/.docs/raw/docs/(docs)/guides/slash-commands.mdx +0 -275
- package/.docs/raw/docs/(docs)/guides/speech.mdx +0 -38
- package/.docs/raw/docs/runtimes/a2a/index.mdx +0 -298
- package/.docs/raw/docs/runtimes/assistant-transport.mdx +0 -1033
- package/.docs/raw/docs/runtimes/custom/custom-thread-list.mdx +0 -268
- package/.docs/raw/docs/runtimes/custom/local.mdx +0 -1464
- package/.docs/raw/docs/runtimes/data-stream.mdx +0 -422
- package/.docs/raw/docs/runtimes/google-adk/index.mdx +0 -686
- package/.docs/raw/docs/runtimes/helicone.mdx +0 -61
- package/.docs/raw/docs/runtimes/langgraph/index.mdx +0 -607
- package/.docs/raw/docs/runtimes/langgraph/tutorial/index.mdx +0 -12
- package/.docs/raw/docs/runtimes/langserve.mdx +0 -116
- package/.docs/raw/docs/runtimes/mastra/full-stack-integration.mdx +0 -218
- package/.docs/raw/docs/runtimes/mastra/overview.mdx +0 -18
- package/.docs/raw/docs/runtimes/mastra/separate-server-integration.mdx +0 -217
- package/.docs/raw/docs/ui/mention.mdx +0 -168
|
@@ -3,37 +3,75 @@ title: AI SDK v6
|
|
|
3
3
|
description: Integrate Vercel AI SDK v6 with assistant-ui for streaming chat.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
Current-version integration. Requires `ai@^6` and `@ai-sdk/react@^3`. For older versions see the [overview](/docs/runtimes/ai-sdk).
|
|
6
7
|
|
|
7
|
-
##
|
|
8
|
+
## Quickstart
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
<Steps>
|
|
11
|
+
<Step>
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
### Create a project
|
|
12
14
|
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
### Create a Next.js project
|
|
15
|
+
<PlatformTabs>
|
|
16
|
+
<Tab value="React">
|
|
16
17
|
|
|
17
18
|
```sh
|
|
18
19
|
npx create-next-app@latest my-app
|
|
19
20
|
cd my-app
|
|
20
21
|
```
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
</Tab>
|
|
24
|
+
<Tab value="React Native">
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
npx create-expo-app@latest my-app
|
|
28
|
+
cd my-app
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
</Tab>
|
|
32
|
+
<Tab value="React Ink">
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
mkdir my-app
|
|
36
|
+
cd my-app
|
|
37
|
+
npm init -y
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
</Tab>
|
|
41
|
+
</PlatformTabs>
|
|
42
|
+
|
|
43
|
+
</Step>
|
|
44
|
+
<Step>
|
|
24
45
|
|
|
25
46
|
### Install dependencies
|
|
26
47
|
|
|
48
|
+
<PlatformTabs>
|
|
49
|
+
<Tab value="React">
|
|
50
|
+
|
|
27
51
|
<InstallCommand npm={["@assistant-ui/react", "@assistant-ui/react-ai-sdk", "ai@^6", "@ai-sdk/react@^3", "@ai-sdk/openai", "zod"]} />
|
|
28
52
|
|
|
29
|
-
|
|
30
|
-
|
|
53
|
+
</Tab>
|
|
54
|
+
<Tab value="React Native">
|
|
31
55
|
|
|
32
|
-
|
|
56
|
+
<InstallCommand expo={["@assistant-ui/react-native", "@assistant-ui/react-ai-sdk", "ai@^6", "@ai-sdk/react@^3", "@ai-sdk/openai", "zod"]} />
|
|
33
57
|
|
|
34
|
-
|
|
58
|
+
</Tab>
|
|
59
|
+
<Tab value="React Ink">
|
|
35
60
|
|
|
36
|
-
|
|
61
|
+
<InstallCommand npm={["@assistant-ui/react-ink", "@assistant-ui/react-ai-sdk", "ai@^6", "@ai-sdk/react@^3", "@ai-sdk/openai", "zod", "ink", "react"]} />
|
|
62
|
+
|
|
63
|
+
</Tab>
|
|
64
|
+
</PlatformTabs>
|
|
65
|
+
|
|
66
|
+
</Step>
|
|
67
|
+
<Step>
|
|
68
|
+
|
|
69
|
+
### Set up the backend route
|
|
70
|
+
|
|
71
|
+
For React Native and Ink, host this route in a separate backend project and
|
|
72
|
+
point the client runtime at its absolute URL.
|
|
73
|
+
|
|
74
|
+
```ts title="@/app/api/chat/route.ts"
|
|
37
75
|
import { openai } from "@ai-sdk/openai";
|
|
38
76
|
import {
|
|
39
77
|
streamText,
|
|
@@ -50,16 +88,12 @@ export async function POST(req: Request) {
|
|
|
50
88
|
const { messages }: { messages: UIMessage[] } = await req.json();
|
|
51
89
|
|
|
52
90
|
const result = streamText({
|
|
53
|
-
model: openai("gpt-
|
|
54
|
-
messages: await convertToModelMessages(messages), //
|
|
91
|
+
model: openai("gpt-5.4-mini"),
|
|
92
|
+
messages: await convertToModelMessages(messages), // async in v6
|
|
55
93
|
tools: {
|
|
56
94
|
get_current_weather: tool({
|
|
57
95
|
description: "Get the current weather",
|
|
58
|
-
inputSchema: zodSchema(
|
|
59
|
-
z.object({
|
|
60
|
-
city: z.string(),
|
|
61
|
-
}),
|
|
62
|
-
),
|
|
96
|
+
inputSchema: zodSchema(z.object({ city: z.string() })),
|
|
63
97
|
execute: async ({ city }) => {
|
|
64
98
|
return `The weather in ${city} is sunny`;
|
|
65
99
|
},
|
|
@@ -71,14 +105,15 @@ export async function POST(req: Request) {
|
|
|
71
105
|
}
|
|
72
106
|
```
|
|
73
107
|
|
|
74
|
-
|
|
75
|
-
|
|
108
|
+
</Step>
|
|
109
|
+
<Step>
|
|
76
110
|
|
|
77
|
-
###
|
|
111
|
+
### Set up the frontend
|
|
78
112
|
|
|
79
|
-
|
|
113
|
+
<PlatformTabs>
|
|
114
|
+
<Tab value="React">
|
|
80
115
|
|
|
81
|
-
```tsx
|
|
116
|
+
```tsx title="@/app/page.tsx"
|
|
82
117
|
"use client";
|
|
83
118
|
|
|
84
119
|
import { Thread } from "@/components/assistant-ui/thread";
|
|
@@ -87,7 +122,6 @@ import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
|
|
|
87
122
|
|
|
88
123
|
export default function Home() {
|
|
89
124
|
const runtime = useChatRuntime();
|
|
90
|
-
|
|
91
125
|
return (
|
|
92
126
|
<AssistantRuntimeProvider runtime={runtime}>
|
|
93
127
|
<div className="h-full">
|
|
@@ -98,18 +132,192 @@ export default function Home() {
|
|
|
98
132
|
}
|
|
99
133
|
```
|
|
100
134
|
|
|
101
|
-
|
|
135
|
+
</Tab>
|
|
136
|
+
<Tab value="React Native">
|
|
137
|
+
|
|
138
|
+
```tsx title="app/index.tsx"
|
|
139
|
+
import { AssistantRuntimeProvider } from "@assistant-ui/react-native";
|
|
140
|
+
import {
|
|
141
|
+
AssistantChatTransport,
|
|
142
|
+
useChatRuntime,
|
|
143
|
+
} from "@assistant-ui/react-ai-sdk";
|
|
144
|
+
import { View } from "react-native";
|
|
145
|
+
import { Thread } from "@/components/assistant-ui/thread";
|
|
146
|
+
|
|
147
|
+
const API_URL = process.env.EXPO_PUBLIC_API_URL ?? "http://localhost:3000";
|
|
148
|
+
|
|
149
|
+
export default function Home() {
|
|
150
|
+
const runtime = useChatRuntime({
|
|
151
|
+
transport: new AssistantChatTransport({
|
|
152
|
+
api: `${API_URL}/api/chat`,
|
|
153
|
+
}),
|
|
154
|
+
});
|
|
155
|
+
return (
|
|
156
|
+
<AssistantRuntimeProvider runtime={runtime}>
|
|
157
|
+
<View style={{ flex: 1 }}>
|
|
158
|
+
<Thread />
|
|
159
|
+
</View>
|
|
160
|
+
</AssistantRuntimeProvider>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
</Tab>
|
|
166
|
+
<Tab value="React Ink">
|
|
167
|
+
|
|
168
|
+
```tsx title="app.tsx"
|
|
169
|
+
import { AssistantRuntimeProvider } from "@assistant-ui/react-ink";
|
|
170
|
+
import {
|
|
171
|
+
AssistantChatTransport,
|
|
172
|
+
useChatRuntime,
|
|
173
|
+
} from "@assistant-ui/react-ai-sdk";
|
|
174
|
+
import { Box } from "ink";
|
|
175
|
+
import { Thread } from "./components/thread.js";
|
|
176
|
+
|
|
177
|
+
export function App() {
|
|
178
|
+
const runtime = useChatRuntime({
|
|
179
|
+
transport: new AssistantChatTransport({
|
|
180
|
+
api: "http://localhost:3000/api/chat",
|
|
181
|
+
}),
|
|
182
|
+
});
|
|
183
|
+
return (
|
|
184
|
+
<AssistantRuntimeProvider runtime={runtime}>
|
|
185
|
+
<Box flexDirection="column">
|
|
186
|
+
<Thread />
|
|
187
|
+
</Box>
|
|
188
|
+
</AssistantRuntimeProvider>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
</Tab>
|
|
194
|
+
</PlatformTabs>
|
|
195
|
+
|
|
196
|
+
</Step>
|
|
197
|
+
<Step>
|
|
198
|
+
|
|
199
|
+
### Set up UI components
|
|
200
|
+
|
|
201
|
+
<PlatformTabs>
|
|
202
|
+
<Tab value="React">
|
|
203
|
+
|
|
204
|
+
Follow the [UI Components guide](/docs/ui/thread) to wire up the Thread, composer, and supporting primitives.
|
|
205
|
+
|
|
206
|
+
</Tab>
|
|
207
|
+
<Tab value="React Native">
|
|
208
|
+
|
|
209
|
+
Follow the [React Native setup](/docs/react-native) to add a native Thread, composer, and supporting primitives.
|
|
210
|
+
|
|
211
|
+
</Tab>
|
|
212
|
+
<Tab value="React Ink">
|
|
213
|
+
|
|
214
|
+
Follow the [Ink setup](/docs/ink) to add a terminal Thread, composer, and supporting primitives.
|
|
215
|
+
|
|
216
|
+
</Tab>
|
|
217
|
+
</PlatformTabs>
|
|
218
|
+
|
|
219
|
+
</Step>
|
|
102
220
|
</Steps>
|
|
103
221
|
|
|
104
|
-
##
|
|
222
|
+
## Frontend tools and system messages
|
|
105
223
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
224
|
+
`AssistantChatTransport` (used by default) forwards system messages and frontend tools to your backend on every request. Consume them with `frontendTools`:
|
|
225
|
+
|
|
226
|
+
```ts title="@/app/api/chat/route.ts"
|
|
227
|
+
import { openai } from "@ai-sdk/openai";
|
|
228
|
+
import { streamText, convertToModelMessages, zodSchema } from "ai";
|
|
229
|
+
import type { UIMessage } from "ai";
|
|
230
|
+
import { frontendTools } from "@assistant-ui/react-ai-sdk";
|
|
231
|
+
|
|
232
|
+
export async function POST(req: Request) {
|
|
233
|
+
const {
|
|
234
|
+
messages,
|
|
235
|
+
system,
|
|
236
|
+
tools,
|
|
237
|
+
}: {
|
|
238
|
+
messages: UIMessage[];
|
|
239
|
+
system?: string;
|
|
240
|
+
tools?: any;
|
|
241
|
+
} = await req.json();
|
|
242
|
+
|
|
243
|
+
const result = streamText({
|
|
244
|
+
model: openai("gpt-5.4-mini"),
|
|
245
|
+
system,
|
|
246
|
+
messages: await convertToModelMessages(messages),
|
|
247
|
+
tools: {
|
|
248
|
+
...frontendTools(tools),
|
|
249
|
+
// your backend tools...
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
return result.toUIMessageStreamResponse();
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Frontend tools are registered through `useAui` (see the [tools guide](/docs/guides/tools)) and serialized for the backend via `frontendTools`.
|
|
258
|
+
|
|
259
|
+
## Multi-step tool calls
|
|
260
|
+
|
|
261
|
+
AI SDK v6 supports running multiple tool-call rounds in a single request via `stopWhen`. Use `stepCountIs(N)` to cap iterations:
|
|
262
|
+
|
|
263
|
+
```ts title="@/app/api/chat/route.ts"
|
|
264
|
+
import { openai } from "@ai-sdk/openai";
|
|
265
|
+
import {
|
|
266
|
+
streamText,
|
|
267
|
+
convertToModelMessages,
|
|
268
|
+
stepCountIs,
|
|
269
|
+
} from "ai";
|
|
270
|
+
|
|
271
|
+
export async function POST(req: Request) {
|
|
272
|
+
const { messages } = await req.json();
|
|
273
|
+
|
|
274
|
+
const result = streamText({
|
|
275
|
+
model: openai("gpt-5.4-mini"),
|
|
276
|
+
messages: await convertToModelMessages(messages),
|
|
277
|
+
tools: {
|
|
278
|
+
/* ... */
|
|
279
|
+
},
|
|
280
|
+
stopWhen: stepCountIs(10), // cap at 10 tool-call iterations
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
return result.toUIMessageStreamResponse();
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Without a `stopWhen`, AI SDK runs a single inference step. Set `stepCountIs` (or one of AI SDK's other stop conditions) when your tools chain multiple calls.
|
|
288
|
+
|
|
289
|
+
## Quote context
|
|
290
|
+
|
|
291
|
+
assistant-ui's composer can attach quote metadata to user messages (e.g. when the user selects text and clicks "Quote"). On the server, `injectQuoteContext` flattens that metadata into a markdown blockquote prefix so the LLM sees the quoted text:
|
|
292
|
+
|
|
293
|
+
```ts title="@/app/api/chat/route.ts"
|
|
294
|
+
import {
|
|
295
|
+
streamText,
|
|
296
|
+
convertToModelMessages,
|
|
297
|
+
} from "ai";
|
|
298
|
+
import { injectQuoteContext } from "@assistant-ui/react-ai-sdk";
|
|
299
|
+
import { openai } from "@ai-sdk/openai";
|
|
300
|
+
|
|
301
|
+
export async function POST(req: Request) {
|
|
302
|
+
const { messages } = await req.json();
|
|
303
|
+
const result = streamText({
|
|
304
|
+
model: openai("gpt-5.4-mini"),
|
|
305
|
+
messages: await convertToModelMessages(injectQuoteContext(messages)),
|
|
306
|
+
});
|
|
307
|
+
return result.toUIMessageStreamResponse();
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
`injectQuoteContext` is idempotent: if the blockquote prefix is already present, it is not duplicated.
|
|
312
|
+
|
|
313
|
+
## Token usage
|
|
314
|
+
|
|
315
|
+
`useThreadTokenUsage` exposes thread-level token usage on the client. Attach `usage` and `modelId` via `messageMetadata` on the server:
|
|
316
|
+
|
|
317
|
+
```ts title="@/app/api/chat/route.ts"
|
|
111
318
|
import { streamText, convertToModelMessages } from "ai";
|
|
112
319
|
import { frontendTools } from "@assistant-ui/react-ai-sdk";
|
|
320
|
+
|
|
113
321
|
export async function POST(req: Request) {
|
|
114
322
|
const { messages, tools, config } = await req.json();
|
|
115
323
|
const result = streamText({
|
|
@@ -120,115 +328,133 @@ export async function POST(req: Request) {
|
|
|
120
328
|
return result.toUIMessageStreamResponse({
|
|
121
329
|
messageMetadata: ({ part }) => {
|
|
122
330
|
if (part.type === "finish") {
|
|
123
|
-
return {
|
|
124
|
-
usage: part.totalUsage,
|
|
125
|
-
};
|
|
331
|
+
return { usage: part.totalUsage };
|
|
126
332
|
}
|
|
127
333
|
if (part.type === "finish-step") {
|
|
128
|
-
return {
|
|
129
|
-
modelId: part.response.modelId,
|
|
130
|
-
};
|
|
334
|
+
return { modelId: part.response.modelId };
|
|
131
335
|
}
|
|
132
336
|
return undefined;
|
|
133
337
|
},
|
|
134
338
|
});
|
|
135
339
|
}
|
|
136
340
|
```
|
|
137
|
-
</Step>
|
|
138
|
-
<Step>
|
|
139
|
-
Use `useThreadTokenUsage` to render token usage on the client.
|
|
140
341
|
|
|
141
|
-
```tsx
|
|
342
|
+
```tsx title="@/components/TokenCounter.tsx"
|
|
142
343
|
"use client";
|
|
143
344
|
|
|
144
345
|
import { useThreadTokenUsage } from "@assistant-ui/react-ai-sdk";
|
|
145
346
|
|
|
146
347
|
export function TokenCounter() {
|
|
147
348
|
const usage = useThreadTokenUsage();
|
|
148
|
-
|
|
149
349
|
if (!usage) return null;
|
|
150
|
-
|
|
151
350
|
return <div>{usage.totalTokens} total tokens</div>;
|
|
152
351
|
}
|
|
153
352
|
```
|
|
154
|
-
</Step>
|
|
155
|
-
</Steps>
|
|
156
|
-
|
|
157
|
-
## Key Changes from v5
|
|
158
|
-
|
|
159
|
-
| Feature | v5 | v6 |
|
|
160
|
-
|---------|----|----|
|
|
161
|
-
| **ai package** | `ai@^5` | `ai@^6` |
|
|
162
|
-
| **@ai-sdk/react** | `@ai-sdk/react@^2` | `@ai-sdk/react@^3` |
|
|
163
|
-
| **convertToModelMessages** | Sync | Async (`await`) |
|
|
164
|
-
| **Tool schema** | `parameters: z.object({...})` | `inputSchema: zodSchema(z.object({...}))` |
|
|
165
353
|
|
|
166
|
-
|
|
354
|
+
`getThreadMessageTokenUsage(message)` returns per-message usage if you need to show it inline.
|
|
167
355
|
|
|
168
|
-
|
|
356
|
+
## Attachments
|
|
169
357
|
|
|
170
|
-
|
|
358
|
+
Attachments work through the standard [attachment adapter](/docs/runtimes/concepts/adapters#attachment-adapter). Pass it via `useChatRuntime`:
|
|
171
359
|
|
|
172
360
|
```tsx
|
|
173
|
-
|
|
361
|
+
const runtime = useChatRuntime({
|
|
362
|
+
adapters: { attachments: myAttachmentAdapter },
|
|
363
|
+
});
|
|
364
|
+
```
|
|
174
365
|
|
|
175
|
-
|
|
366
|
+
Your attachment adapter's `send` should return `content` parts in the AI SDK shape, e.g. for files:
|
|
367
|
+
|
|
368
|
+
```ts
|
|
369
|
+
return {
|
|
370
|
+
...attachment,
|
|
371
|
+
status: { type: "complete" },
|
|
372
|
+
content: [
|
|
373
|
+
{
|
|
374
|
+
type: "file",
|
|
375
|
+
mimeType: attachment.contentType ?? "",
|
|
376
|
+
filename: attachment.name,
|
|
377
|
+
data: await getFileDataURL(attachment.file),
|
|
378
|
+
},
|
|
379
|
+
],
|
|
380
|
+
};
|
|
176
381
|
```
|
|
177
382
|
|
|
178
|
-
|
|
383
|
+
For images, use `{ type: "image", image: <data url or remote url> }`. AI SDK will pass these to providers that accept multimodal content.
|
|
179
384
|
|
|
180
|
-
|
|
385
|
+
## Persisting chat history
|
|
386
|
+
|
|
387
|
+
By default, messages live only in memory and reset on reload. To persist and restore history per thread, provide a `ThreadHistoryAdapter` via `adapters.history`.
|
|
388
|
+
|
|
389
|
+
<Callout type="warn">
|
|
390
|
+
The adapter **must** implement `withFormat`. `useChatRuntime` persists history through `withFormat(fmt)` so messages round-trip as AI SDK `UIMessage` objects. An adapter without `withFormat` throws at runtime; `load` and `append` on the top level are unused in the AI SDK path.
|
|
391
|
+
</Callout>
|
|
392
|
+
|
|
393
|
+
<Callout type="info">
|
|
394
|
+
For server-side cloud persistence with zero adapter code, see the [AssistantCloud integration](/docs/cloud/ai-sdk-assistant-ui).
|
|
395
|
+
</Callout>
|
|
181
396
|
|
|
182
397
|
```tsx
|
|
183
|
-
|
|
398
|
+
"use client";
|
|
184
399
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
400
|
+
import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
|
|
401
|
+
import type { ThreadHistoryAdapter } from "@assistant-ui/react";
|
|
402
|
+
|
|
403
|
+
const historyAdapter: ThreadHistoryAdapter = {
|
|
404
|
+
// Required by the type — unused by useChatRuntime.
|
|
405
|
+
async load() {
|
|
406
|
+
return { headId: null, messages: [] };
|
|
407
|
+
},
|
|
408
|
+
async append() {},
|
|
409
|
+
|
|
410
|
+
// fmt encodes UIMessage <-> storage rows (ai-sdk/v6 format).
|
|
411
|
+
withFormat: (fmt) => ({
|
|
412
|
+
async load() {
|
|
413
|
+
const rows = await fetch("/api/history").then((r) => r.json());
|
|
414
|
+
return { messages: rows.map(fmt.decode) };
|
|
415
|
+
},
|
|
416
|
+
async append(item) {
|
|
417
|
+
await fetch("/api/history", {
|
|
418
|
+
method: "POST",
|
|
419
|
+
body: JSON.stringify({
|
|
420
|
+
id: fmt.getId(item.message),
|
|
421
|
+
parent_id: item.parentId,
|
|
422
|
+
format: fmt.format,
|
|
423
|
+
content: fmt.encode(item),
|
|
424
|
+
}),
|
|
425
|
+
});
|
|
426
|
+
},
|
|
188
427
|
}),
|
|
189
|
-
}
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
function Chat() {
|
|
431
|
+
const runtime = useChatRuntime({ adapters: { history: historyAdapter } });
|
|
432
|
+
// ...
|
|
433
|
+
}
|
|
190
434
|
```
|
|
191
435
|
|
|
192
|
-
|
|
436
|
+
Each persisted row follows `{ id, parent_id, format, content }`. `fmt.encode` produces the `content` payload and `fmt.decode` reverses it, so your backend never needs to know about `UIMessage` internals.
|
|
193
437
|
|
|
194
|
-
|
|
438
|
+
## Custom transport
|
|
195
439
|
|
|
196
|
-
|
|
440
|
+
`AssistantChatTransport` is the default. To point at a non-default endpoint, instantiate it with a custom `api`:
|
|
197
441
|
|
|
198
442
|
```tsx
|
|
199
|
-
import {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
export async function POST(req: Request) {
|
|
205
|
-
const {
|
|
206
|
-
messages,
|
|
207
|
-
system,
|
|
208
|
-
tools,
|
|
209
|
-
}: {
|
|
210
|
-
messages: UIMessage[];
|
|
211
|
-
system?: string;
|
|
212
|
-
tools?: any;
|
|
213
|
-
} = await req.json();
|
|
214
|
-
|
|
215
|
-
const result = streamText({
|
|
216
|
-
model: openai("gpt-4o"),
|
|
217
|
-
system,
|
|
218
|
-
messages: await convertToModelMessages(messages),
|
|
219
|
-
tools: {
|
|
220
|
-
...frontendTools(tools),
|
|
221
|
-
// your backend tools...
|
|
222
|
-
},
|
|
223
|
-
});
|
|
443
|
+
import {
|
|
444
|
+
useChatRuntime,
|
|
445
|
+
AssistantChatTransport,
|
|
446
|
+
} from "@assistant-ui/react-ai-sdk";
|
|
224
447
|
|
|
225
|
-
|
|
226
|
-
}
|
|
448
|
+
const runtime = useChatRuntime({
|
|
449
|
+
transport: new AssistantChatTransport({ api: "/my-custom-api/chat" }),
|
|
450
|
+
});
|
|
227
451
|
```
|
|
228
452
|
|
|
229
|
-
|
|
453
|
+
If you need a transport that does not inherit from `AssistantChatTransport`, you forfeit automatic system-message and frontend-tool forwarding; the transport is then a regular AI SDK `ChatTransport` and you control everything explicitly.
|
|
454
|
+
|
|
455
|
+
## Advanced: useAISDKRuntime
|
|
230
456
|
|
|
231
|
-
|
|
457
|
+
When you need direct access to the `useChat` instance (e.g. to share it with non-assistant-ui code), drop down to `useAISDKRuntime`:
|
|
232
458
|
|
|
233
459
|
```tsx
|
|
234
460
|
import { useChat } from "@ai-sdk/react";
|
|
@@ -238,6 +464,44 @@ const chat = useChat();
|
|
|
238
464
|
const runtime = useAISDKRuntime(chat);
|
|
239
465
|
```
|
|
240
466
|
|
|
467
|
+
`useAISDKRuntime` does not provide `cloud` or the higher-level adapter slots; those are part of `useChatRuntime`. If you need both your own `useChat` access AND cloud thread support, you generally want `useChatRuntime` and to read the chat state through assistant-ui hooks instead.
|
|
468
|
+
|
|
469
|
+
## Adapter support
|
|
470
|
+
|
|
471
|
+
| Adapter | Supported via |
|
|
472
|
+
| --- | --- |
|
|
473
|
+
| Attachments | `adapters.attachments` |
|
|
474
|
+
| Speech | `adapters.speech` |
|
|
475
|
+
| Dictation | `adapters.dictation` |
|
|
476
|
+
| Feedback | `adapters.feedback` |
|
|
477
|
+
| History | `adapters.history` (must implement `withFormat`) |
|
|
478
|
+
| threadList | Via `cloud` (managed) or [RemoteThreadListRuntime](/docs/runtimes/concepts/threads) (custom DB) |
|
|
479
|
+
|
|
480
|
+
## Key changes from v5
|
|
481
|
+
|
|
482
|
+
| Feature | v5 | v6 |
|
|
483
|
+
| --- | --- | --- |
|
|
484
|
+
| `ai` package | `ai@^5` | `ai@^6` |
|
|
485
|
+
| `@ai-sdk/react` | `@ai-sdk/react@^2` | `@ai-sdk/react@^3` |
|
|
486
|
+
| `convertToModelMessages` | Sync | Async (`await`) |
|
|
487
|
+
| Tool schema | `parameters: z.object({...})` | `inputSchema: zodSchema(z.object({...}))` |
|
|
488
|
+
| Response | `toDataStreamResponse()` | `toUIMessageStreamResponse()` |
|
|
489
|
+
|
|
241
490
|
## Example
|
|
242
491
|
|
|
243
|
-
|
|
492
|
+
[`examples/with-ai-sdk-v6`](https://github.com/assistant-ui/assistant-ui/tree/main/examples/with-ai-sdk-v6) shows a complete reference implementation.
|
|
493
|
+
|
|
494
|
+
## Next
|
|
495
|
+
|
|
496
|
+
<Cards>
|
|
497
|
+
<Card
|
|
498
|
+
title="Adapters"
|
|
499
|
+
description="Attachments, speech, feedback, history, suggestions; one source of truth."
|
|
500
|
+
href="/docs/runtimes/concepts/adapters"
|
|
501
|
+
/>
|
|
502
|
+
<Card
|
|
503
|
+
title="Threads"
|
|
504
|
+
description="Single-thread, AssistantCloud, custom thread list."
|
|
505
|
+
href="/docs/runtimes/concepts/threads"
|
|
506
|
+
/>
|
|
507
|
+
</Cards>
|