@assistant-ui/mcp-docs-server 0.1.36 → 0.1.39

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.
Files changed (246) hide show
  1. package/.docs/organized/code-examples/waterfall.md +8 -9
  2. package/.docs/organized/code-examples/with-a2a.md +16 -11
  3. package/.docs/organized/code-examples/with-ag-ui.md +16 -11
  4. package/.docs/organized/code-examples/{with-ai-sdk-v6.md → with-ai-sdk-v7.md} +32 -21
  5. package/.docs/organized/code-examples/with-artifacts.md +17 -10
  6. package/.docs/organized/code-examples/with-assistant-transport.md +15 -8
  7. package/.docs/organized/code-examples/with-browser-extension.md +15 -8
  8. package/.docs/organized/code-examples/with-chain-of-thought.md +17 -10
  9. package/.docs/organized/code-examples/with-cloud-standalone.md +10 -9
  10. package/.docs/organized/code-examples/with-cloud.md +18 -13
  11. package/.docs/organized/code-examples/with-custom-thread-list.md +17 -10
  12. package/.docs/organized/code-examples/with-elevenlabs-conversational.md +20 -13
  13. package/.docs/organized/code-examples/with-elevenlabs-scribe.md +20 -13
  14. package/.docs/organized/code-examples/with-eve.md +16 -9
  15. package/.docs/organized/code-examples/with-expo.md +26 -23
  16. package/.docs/organized/code-examples/with-external-store.md +16 -11
  17. package/.docs/organized/code-examples/with-ffmpeg.md +18 -13
  18. package/.docs/organized/code-examples/with-generative-ui.md +20 -15
  19. package/.docs/organized/code-examples/with-google-adk.md +16 -9
  20. package/.docs/organized/code-examples/with-heat-graph.md +8 -9
  21. package/.docs/organized/code-examples/with-image-generation.md +17 -10
  22. package/.docs/organized/code-examples/with-interactables.md +19 -15
  23. package/.docs/organized/code-examples/with-langchain.md +17 -10
  24. package/.docs/organized/code-examples/with-langgraph.md +17 -10
  25. package/.docs/organized/code-examples/with-livekit.md +21 -14
  26. package/.docs/organized/code-examples/with-mcp.md +40 -18
  27. package/.docs/organized/code-examples/with-opencode.md +22 -17
  28. package/.docs/organized/code-examples/with-pi.md +47 -12
  29. package/.docs/organized/code-examples/with-react-hook-form.md +19 -14
  30. package/.docs/organized/code-examples/with-react-ink-web.md +6 -6
  31. package/.docs/organized/code-examples/with-react-ink.md +2 -2
  32. package/.docs/organized/code-examples/with-react-router.md +20 -15
  33. package/.docs/organized/code-examples/with-resumable-stream.md +19 -12
  34. package/.docs/organized/code-examples/with-store.md +8 -9
  35. package/.docs/organized/code-examples/with-tanstack.md +17 -11
  36. package/.docs/organized/code-examples/with-tap-runtime.md +16 -11
  37. package/.docs/organized/code-examples/with-virtualized-thread.md +17 -12
  38. package/.docs/raw/docs/(docs)/base-ui.mdx +39 -0
  39. package/.docs/raw/docs/(docs)/cli.mdx +18 -2
  40. package/.docs/raw/docs/(docs)/installation.mdx +15 -1
  41. package/.docs/raw/docs/(docs)/rtl.mdx +2 -4
  42. package/.docs/raw/docs/(reference)/api-reference/generative-ui/actions.mdx +56 -0
  43. package/.docs/raw/docs/(reference)/api-reference/generative-ui/components.mdx +86 -0
  44. package/.docs/raw/docs/(reference)/api-reference/generative-ui/index.mdx +19 -1
  45. package/.docs/raw/docs/(reference)/api-reference/generative-ui/json-generative-ui.mdx +42 -0
  46. package/.docs/raw/docs/(reference)/api-reference/generative-ui/rendering.mdx +53 -2
  47. package/.docs/raw/docs/(reference)/api-reference/generative-ui/slack.mdx +81 -0
  48. package/.docs/raw/docs/(reference)/api-reference/generative-ui/teams.mdx +86 -0
  49. package/.docs/raw/docs/(reference)/api-reference/generative-ui/tokens.mdx +62 -0
  50. package/.docs/raw/docs/(reference)/api-reference/integrations/index.mdx +4 -1
  51. package/.docs/raw/docs/(reference)/api-reference/integrations/react-ai-sdk.mdx +4 -2
  52. package/.docs/raw/docs/(reference)/api-reference/integrations/react-data-stream.mdx +37 -0
  53. package/.docs/raw/docs/(reference)/api-reference/overview.mdx +1 -0
  54. package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-if.mdx +29 -29
  55. package/.docs/raw/docs/(reference)/api-reference/primitives/composition.mdx +1 -0
  56. package/.docs/raw/docs/(reference)/api-reference/primitives/index.mdx +3 -0
  57. package/.docs/raw/docs/(reference)/api-reference/primitives/selection-toolbar.mdx +2 -0
  58. package/.docs/raw/docs/(reference)/api-reference/tools/status.mdx +0 -2
  59. package/.docs/raw/docs/(reference)/api-reference/tools/toolkits.mdx +12 -9
  60. package/.docs/raw/docs/(reference)/api-reference/utilities/miscellaneous.mdx +4 -0
  61. package/.docs/raw/docs/cloud/ai-sdk-assistant-ui.mdx +7 -1
  62. package/.docs/raw/docs/cloud/langgraph.mdx +4 -2
  63. package/.docs/raw/docs/guides/chatgpt-subscription.mdx +108 -0
  64. package/.docs/raw/docs/guides/dictation.mdx +185 -257
  65. package/.docs/raw/docs/guides/index.mdx +10 -0
  66. package/.docs/raw/docs/guides/mentions.mdx +31 -3
  67. package/.docs/raw/docs/guides/resumable-streams.mdx +12 -1
  68. package/.docs/raw/docs/guides/speech.mdx +47 -29
  69. package/.docs/raw/docs/guides/suggestions.mdx +70 -1
  70. package/.docs/raw/docs/guides/voice.mdx +197 -267
  71. package/.docs/raw/docs/ink/primitives.mdx +35 -1
  72. package/.docs/raw/docs/integrations/frameworks/ai-sdk.mdx +13 -7
  73. package/.docs/raw/docs/integrations/frameworks/cloudflare-agents/overview.mdx +3 -3
  74. package/.docs/raw/docs/integrations/frameworks/mastra/full-stack.mdx +1 -1
  75. package/.docs/raw/docs/integrations/frameworks/mastra/overview.mdx +3 -3
  76. package/.docs/raw/docs/integrations/frameworks/mastra/separate-server.mdx +1 -1
  77. package/.docs/raw/docs/integrations/gateways/index.mdx +2 -2
  78. package/.docs/raw/docs/integrations/index.mdx +1 -1
  79. package/.docs/raw/docs/integrations/observability/helicone.mdx +1 -1
  80. package/.docs/raw/docs/integrations/observability/langfuse.mdx +1 -1
  81. package/.docs/raw/docs/integrations/observability/langsmith.mdx +3 -3
  82. package/.docs/raw/docs/migrations/index.mdx +50 -0
  83. package/.docs/raw/docs/migrations/react-langgraph-v0-7.mdx +2 -2
  84. package/.docs/raw/docs/migrations/toolkit-tools.mdx +4 -2
  85. package/.docs/raw/docs/primitives/chain-of-thought.mdx +6 -1
  86. package/.docs/raw/docs/primitives/composer.mdx +16 -0
  87. package/.docs/raw/docs/primitives/selection-toolbar.mdx +25 -0
  88. package/.docs/raw/docs/primitives/thread-list.mdx +30 -6
  89. package/.docs/raw/docs/react-native/primitives.mdx +23 -0
  90. package/.docs/raw/docs/runtimes/a2a/quickstart.mdx +1 -1
  91. package/.docs/raw/docs/runtimes/ag-ui/agent-state.mdx +124 -0
  92. package/.docs/raw/docs/runtimes/ag-ui/quickstart.mdx +1 -1
  93. package/.docs/raw/docs/runtimes/ag-ui/runtime-options.mdx +13 -2
  94. package/.docs/raw/docs/runtimes/ai-sdk/overview.mdx +13 -4
  95. package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +11 -11
  96. package/.docs/raw/docs/runtimes/ai-sdk/v5-legacy.mdx +5 -5
  97. package/.docs/raw/docs/runtimes/ai-sdk/{v6.mdx → v6-legacy.mdx} +8 -6
  98. package/.docs/raw/docs/runtimes/ai-sdk/v7.mdx +717 -0
  99. package/.docs/raw/docs/runtimes/concepts/adapters.mdx +1 -1
  100. package/.docs/raw/docs/runtimes/concepts/architecture.mdx +1 -1
  101. package/.docs/raw/docs/runtimes/custom/data-stream.mdx +10 -19
  102. package/.docs/raw/docs/runtimes/custom/external-store.mdx +1 -1
  103. package/.docs/raw/docs/runtimes/custom/local-runtime.mdx +2 -0
  104. package/.docs/raw/docs/runtimes/eve/overview.mdx +1 -1
  105. package/.docs/raw/docs/runtimes/google-adk/quickstart.mdx +1 -1
  106. package/.docs/raw/docs/runtimes/langchain.mdx +2 -2
  107. package/.docs/raw/docs/runtimes/langgraph/agent-state.mdx +181 -0
  108. package/.docs/raw/docs/runtimes/opencode/hooks.mdx +1 -1
  109. package/.docs/raw/docs/tools/backend.mdx +6 -3
  110. package/.docs/raw/docs/tools/defining-tools.mdx +12 -1
  111. package/.docs/raw/docs/tools/generative-ui.mdx +95 -0
  112. package/.docs/raw/docs/tools/mcp-apps.mdx +37 -10
  113. package/.docs/raw/docs/tools/mcp.mdx +105 -3
  114. package/.docs/raw/docs/tools/tool-ui.mdx +6 -4
  115. package/.docs/raw/docs/tools/user-managed-mcp.mdx +41 -4
  116. package/.docs/raw/docs/ui/accordion.mdx +16 -10
  117. package/.docs/raw/docs/ui/assistant-modal.mdx +8 -4
  118. package/.docs/raw/docs/ui/attachment.mdx +5 -1
  119. package/.docs/raw/docs/ui/badge.mdx +23 -12
  120. package/.docs/raw/docs/ui/follow-up-suggestions.mdx +80 -0
  121. package/.docs/raw/docs/ui/model-selector.mdx +69 -6
  122. package/.docs/raw/docs/ui/select.mdx +22 -14
  123. package/.docs/raw/docs/ui/sources.mdx +1 -1
  124. package/.docs/raw/docs/ui/tabs.mdx +25 -14
  125. package/.docs/raw/docs/utilities/heat-graph.mdx +2 -2
  126. package/README.md +1 -1
  127. package/dist/constants.d.ts +2 -1
  128. package/dist/constants.d.ts.map +1 -1
  129. package/dist/constants.js +2 -1
  130. package/dist/constants.js.map +1 -1
  131. package/dist/index.d.ts +0 -1
  132. package/dist/index.d.ts.map +1 -1
  133. package/dist/index.js +51 -0
  134. package/dist/index.js.map +1 -1
  135. package/dist/prepare-docs/code-examples.d.ts.map +1 -1
  136. package/dist/prepare-docs/copy-raw.d.ts.map +1 -1
  137. package/dist/prepare-docs/copy-raw.js +0 -4
  138. package/dist/prepare-docs/copy-raw.js.map +1 -1
  139. package/dist/prompts/xulux-playground.d.ts +12 -0
  140. package/dist/prompts/xulux-playground.d.ts.map +1 -0
  141. package/dist/prompts/xulux-playground.js +33 -0
  142. package/dist/prompts/xulux-playground.js.map +1 -0
  143. package/dist/tools/docs.d.ts +2 -4
  144. package/dist/tools/docs.d.ts.map +1 -1
  145. package/dist/tools/docs.js +38 -10
  146. package/dist/tools/docs.js.map +1 -1
  147. package/dist/tools/examples.d.ts +5 -5
  148. package/dist/tools/examples.d.ts.map +1 -1
  149. package/dist/tools/examples.js +10 -7
  150. package/dist/tools/examples.js.map +1 -1
  151. package/dist/tools/resources.d.ts +6 -0
  152. package/dist/tools/resources.d.ts.map +1 -0
  153. package/dist/tools/resources.js +74 -0
  154. package/dist/tools/resources.js.map +1 -0
  155. package/dist/tools/search.d.ts +30 -0
  156. package/dist/tools/search.d.ts.map +1 -0
  157. package/dist/tools/search.js +39 -0
  158. package/dist/tools/search.js.map +1 -0
  159. package/dist/tools/tests/test-setup.d.ts.map +1 -1
  160. package/dist/tools/tests/test-setup.js +7 -1
  161. package/dist/tools/tests/test-setup.js.map +1 -1
  162. package/dist/tools/xulux-templates.d.ts +72 -0
  163. package/dist/tools/xulux-templates.d.ts.map +1 -0
  164. package/dist/tools/xulux-templates.js +82 -0
  165. package/dist/tools/xulux-templates.js.map +1 -0
  166. package/dist/utils/cache.d.ts +5 -0
  167. package/dist/utils/cache.d.ts.map +1 -0
  168. package/dist/utils/cache.js +18 -0
  169. package/dist/utils/cache.js.map +1 -0
  170. package/dist/utils/logger.d.ts.map +1 -1
  171. package/dist/utils/mcp-format.d.ts +1 -0
  172. package/dist/utils/mcp-format.d.ts.map +1 -1
  173. package/dist/utils/mcp-format.js +7 -4
  174. package/dist/utils/mcp-format.js.map +1 -1
  175. package/dist/utils/mdx.d.ts +2 -1
  176. package/dist/utils/mdx.d.ts.map +1 -1
  177. package/dist/utils/mdx.js +19 -2
  178. package/dist/utils/mdx.js.map +1 -1
  179. package/dist/utils/paths.d.ts +2 -1
  180. package/dist/utils/paths.d.ts.map +1 -1
  181. package/dist/utils/paths.js +20 -1
  182. package/dist/utils/paths.js.map +1 -1
  183. package/dist/utils/search.d.ts +10 -0
  184. package/dist/utils/search.d.ts.map +1 -0
  185. package/dist/utils/search.js +97 -0
  186. package/dist/utils/search.js.map +1 -0
  187. package/dist/utils/security.d.ts.map +1 -1
  188. package/dist/xulux/catalog-client.d.ts +14 -0
  189. package/dist/xulux/catalog-client.d.ts.map +1 -0
  190. package/dist/xulux/catalog-client.js +67 -0
  191. package/dist/xulux/catalog-client.js.map +1 -0
  192. package/dist/xulux/fallback-catalog.d.ts +7 -0
  193. package/dist/xulux/fallback-catalog.d.ts.map +1 -0
  194. package/dist/xulux/fallback-catalog.js +47 -0
  195. package/dist/xulux/fallback-catalog.js.map +1 -0
  196. package/dist/xulux/fetch-sandbox.d.ts +5 -0
  197. package/dist/xulux/fetch-sandbox.d.ts.map +1 -0
  198. package/dist/xulux/fetch-sandbox.js +40 -0
  199. package/dist/xulux/fetch-sandbox.js.map +1 -0
  200. package/dist/xulux/template-service.d.ts +84 -0
  201. package/dist/xulux/template-service.d.ts.map +1 -0
  202. package/dist/xulux/template-service.js +223 -0
  203. package/dist/xulux/template-service.js.map +1 -0
  204. package/dist/xulux/types.d.ts +55 -0
  205. package/dist/xulux/types.d.ts.map +1 -0
  206. package/dist/xulux/types.js +6 -0
  207. package/dist/xulux/types.js.map +1 -0
  208. package/package.json +5 -5
  209. package/src/constants.ts +2 -0
  210. package/src/index.ts +67 -0
  211. package/src/prepare-docs/copy-raw.ts +0 -5
  212. package/src/prompts/xulux-playground.ts +36 -0
  213. package/src/tools/docs.ts +52 -4
  214. package/src/tools/examples.ts +18 -11
  215. package/src/tools/resources.ts +114 -0
  216. package/src/tools/search.ts +46 -0
  217. package/src/tools/tests/completions.test.ts +46 -0
  218. package/src/tools/tests/directory-size-cap.test.ts +50 -0
  219. package/src/tools/tests/docs.test.ts +20 -0
  220. package/src/tools/tests/examples.test.ts +5 -5
  221. package/src/tools/tests/listings-cache.test.ts +19 -0
  222. package/src/tools/tests/mcp-protocol.test.ts +92 -1
  223. package/src/tools/tests/resources.test.ts +102 -0
  224. package/src/tools/tests/search.test.ts +37 -0
  225. package/src/tools/tests/test-setup.ts +10 -0
  226. package/src/tools/tests/xulux-templates.test.ts +262 -0
  227. package/src/tools/xulux-templates.ts +141 -0
  228. package/src/utils/cache.ts +20 -0
  229. package/src/utils/mcp-format.ts +8 -6
  230. package/src/utils/mdx.ts +21 -1
  231. package/src/utils/paths.ts +25 -0
  232. package/src/utils/search.ts +131 -0
  233. package/src/utils/tests/cache.test.ts +51 -0
  234. package/src/utils/tests/mcp-format.test.ts +22 -0
  235. package/src/utils/tests/security.test.ts +1 -1
  236. package/src/xulux/catalog-client.ts +105 -0
  237. package/src/xulux/fallback-catalog.ts +63 -0
  238. package/src/xulux/fetch-sandbox.ts +56 -0
  239. package/src/xulux/template-service.ts +406 -0
  240. package/src/xulux/types.ts +60 -0
  241. package/.docs/raw/blog/2024-07-29-hello/index.mdx +0 -64
  242. package/.docs/raw/blog/2024-09-11/index.mdx +0 -10
  243. package/.docs/raw/blog/2024-12-15/index.mdx +0 -10
  244. package/.docs/raw/blog/2025-01-31-changelog/index.mdx +0 -127
  245. package/.docs/raw/blog/2026-03-launch-week/index.mdx +0 -258
  246. package/.docs/raw/docs/(reference)/api-reference/hooks/utilities.mdx +0 -464
@@ -0,0 +1,717 @@
1
+ ---
2
+ title: AI SDK v7
3
+ description: Integrate Vercel AI SDK v7 with assistant-ui for streaming chat.
4
+ ---
5
+
6
+ Current-version integration. Requires `ai@^7` and `@ai-sdk/react@^4`. For older versions see the [overview](/docs/runtimes/ai-sdk).
7
+
8
+ ## Quickstart
9
+
10
+ <Steps>
11
+ <Step>
12
+
13
+ ### Create a project
14
+
15
+ <PlatformTabs>
16
+ <Tab value="React">
17
+
18
+ ```sh
19
+ npx create-next-app@latest my-app
20
+ cd my-app
21
+ ```
22
+
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>
45
+
46
+ ### Install dependencies
47
+
48
+ <PlatformTabs>
49
+ <Tab value="React">
50
+
51
+ <InstallCommand npm={["@assistant-ui/react", "@assistant-ui/react-ai-sdk", "ai@^7", "@ai-sdk/react@^4", "@ai-sdk/openai", "zod"]} />
52
+
53
+ </Tab>
54
+ <Tab value="React Native">
55
+
56
+ <InstallCommand expo={["@assistant-ui/react-native", "@assistant-ui/react-ai-sdk", "ai@^7", "@ai-sdk/react@^4", "@ai-sdk/openai", "zod"]} />
57
+
58
+ </Tab>
59
+ <Tab value="React Ink">
60
+
61
+ <InstallCommand npm={["@assistant-ui/react-ink", "@assistant-ui/react-ai-sdk", "ai@^7", "@ai-sdk/react@^4", "@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"
75
+ import { openai } from "@ai-sdk/openai";
76
+ import {
77
+ streamText,
78
+ convertToModelMessages,
79
+ tool,
80
+ zodSchema,
81
+ createUIMessageStreamResponse,
82
+ toUIMessageStream,
83
+ } from "ai";
84
+ import type { UIMessage } from "ai";
85
+ import { z } from "zod";
86
+
87
+ export const maxDuration = 30;
88
+
89
+ export async function POST(req: Request) {
90
+ const { messages }: { messages: UIMessage[] } = await req.json();
91
+
92
+ const result = streamText({
93
+ model: openai("gpt-5.4-mini"),
94
+ messages: await convertToModelMessages(messages), // async in v7
95
+ tools: {
96
+ get_current_weather: tool({
97
+ description: "Get the current weather",
98
+ inputSchema: zodSchema(z.object({ city: z.string() })),
99
+ execute: async ({ city }) => {
100
+ return `The weather in ${city} is sunny`;
101
+ },
102
+ }),
103
+ },
104
+ });
105
+
106
+ return createUIMessageStreamResponse({
107
+ stream: toUIMessageStream({ stream: result.stream }),
108
+ });
109
+ }
110
+ ```
111
+
112
+ </Step>
113
+ <Step>
114
+
115
+ ### Set up the frontend
116
+
117
+ <PlatformTabs>
118
+ <Tab value="React">
119
+
120
+ ```tsx title="@/app/page.tsx"
121
+ "use client";
122
+
123
+ import { Thread } from "@/components/assistant-ui/thread";
124
+ import { AssistantRuntimeProvider } from "@assistant-ui/react";
125
+ import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
126
+
127
+ export default function Home() {
128
+ const runtime = useChatRuntime();
129
+ return (
130
+ <AssistantRuntimeProvider runtime={runtime}>
131
+ <div className="h-full">
132
+ <Thread />
133
+ </div>
134
+ </AssistantRuntimeProvider>
135
+ );
136
+ }
137
+ ```
138
+
139
+ </Tab>
140
+ <Tab value="React Native">
141
+
142
+ ```tsx title="app/index.tsx"
143
+ import { AssistantRuntimeProvider } from "@assistant-ui/react-native";
144
+ import {
145
+ AssistantChatTransport,
146
+ useChatRuntime,
147
+ } from "@assistant-ui/react-ai-sdk";
148
+ import { View } from "react-native";
149
+ import { Thread } from "@/components/assistant-ui/thread";
150
+
151
+ const API_URL = process.env.EXPO_PUBLIC_API_URL ?? "http://localhost:3000";
152
+
153
+ export default function Home() {
154
+ const runtime = useChatRuntime({
155
+ transport: new AssistantChatTransport({
156
+ api: `${API_URL}/api/chat`,
157
+ }),
158
+ });
159
+ return (
160
+ <AssistantRuntimeProvider runtime={runtime}>
161
+ <View style={{ flex: 1 }}>
162
+ <Thread />
163
+ </View>
164
+ </AssistantRuntimeProvider>
165
+ );
166
+ }
167
+ ```
168
+
169
+ </Tab>
170
+ <Tab value="React Ink">
171
+
172
+ ```tsx title="app.tsx"
173
+ import { AssistantRuntimeProvider } from "@assistant-ui/react-ink";
174
+ import {
175
+ AssistantChatTransport,
176
+ useChatRuntime,
177
+ } from "@assistant-ui/react-ai-sdk";
178
+ import { Box } from "ink";
179
+ import { Thread } from "./components/thread.js";
180
+
181
+ export function App() {
182
+ const runtime = useChatRuntime({
183
+ transport: new AssistantChatTransport({
184
+ api: "http://localhost:3000/api/chat",
185
+ }),
186
+ });
187
+ return (
188
+ <AssistantRuntimeProvider runtime={runtime}>
189
+ <Box flexDirection="column">
190
+ <Thread />
191
+ </Box>
192
+ </AssistantRuntimeProvider>
193
+ );
194
+ }
195
+ ```
196
+
197
+ </Tab>
198
+ </PlatformTabs>
199
+
200
+ </Step>
201
+ <Step>
202
+
203
+ ### Set up UI components
204
+
205
+ <PlatformTabs>
206
+ <Tab value="React">
207
+
208
+ Follow the [UI Components guide](/docs/ui/thread) to wire up the Thread, composer, and supporting primitives.
209
+
210
+ </Tab>
211
+ <Tab value="React Native">
212
+
213
+ Follow the [React Native setup](/docs/react-native) to add a native Thread, composer, and supporting primitives.
214
+
215
+ </Tab>
216
+ <Tab value="React Ink">
217
+
218
+ Follow the [Ink setup](/docs/ink) to add a terminal Thread, composer, and supporting primitives.
219
+
220
+ </Tab>
221
+ </PlatformTabs>
222
+
223
+ </Step>
224
+ </Steps>
225
+
226
+ ## Frontend tools and system messages
227
+
228
+ `AssistantChatTransport` (used by default) forwards system messages and frontend tools to your backend on every request. Consume them with `frontendTools`:
229
+
230
+ ```ts title="@/app/api/chat/route.ts"
231
+ import { openai } from "@ai-sdk/openai";
232
+ import { streamText, convertToModelMessages, zodSchema, createUIMessageStreamResponse, toUIMessageStream } from "ai";
233
+ import type { UIMessage } from "ai";
234
+ import { frontendTools } from "@assistant-ui/react-ai-sdk";
235
+
236
+ export async function POST(req: Request) {
237
+ const {
238
+ messages,
239
+ system,
240
+ tools,
241
+ }: {
242
+ messages: UIMessage[];
243
+ system?: string;
244
+ tools?: any;
245
+ } = await req.json();
246
+
247
+ const result = streamText({
248
+ model: openai("gpt-5.4-mini"),
249
+ system,
250
+ messages: await convertToModelMessages(messages),
251
+ tools: {
252
+ ...frontendTools(tools),
253
+ // your backend tools...
254
+ },
255
+ });
256
+
257
+ return createUIMessageStreamResponse({
258
+ stream: toUIMessageStream({ stream: result.stream }),
259
+ });
260
+ }
261
+ ```
262
+
263
+ Frontend tools are registered through `useAui` (see the [tools guide](/docs/tools/defining-tools)) and serialized for the backend via `frontendTools`.
264
+
265
+ ## Multi-step tool calls
266
+
267
+ AI SDK v7 supports running multiple tool-call rounds in a single request via `stopWhen`. Use `stepCountIs(N)` to cap iterations:
268
+
269
+ ```ts title="@/app/api/chat/route.ts"
270
+ import { openai } from "@ai-sdk/openai";
271
+ import {
272
+ streamText,
273
+ convertToModelMessages,
274
+ stepCountIs,
275
+ createUIMessageStreamResponse,
276
+ toUIMessageStream,
277
+ } from "ai";
278
+
279
+ export async function POST(req: Request) {
280
+ const { messages } = await req.json();
281
+
282
+ const result = streamText({
283
+ model: openai("gpt-5.4-mini"),
284
+ messages: await convertToModelMessages(messages),
285
+ tools: {
286
+ /* ... */
287
+ },
288
+ stopWhen: stepCountIs(10), // cap at 10 tool-call iterations
289
+ });
290
+
291
+ return createUIMessageStreamResponse({
292
+ stream: toUIMessageStream({ stream: result.stream }),
293
+ });
294
+ }
295
+ ```
296
+
297
+ 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.
298
+
299
+ ## Server-side tool approval
300
+
301
+ AI SDK v7 gates tool execution with the call-level `toolApproval` option. The server pauses, emits an `approval-requested` part, and resumes once the client posts an approval response. assistant-ui surfaces the gate as `approval` on the tool part and adds a `respondToApproval` prop on the renderer, so tool components stay decoupled from `chatHelpers`.
302
+
303
+ On the backend, configure the gate with the call-level `toolApproval` option (per-tool status or function):
304
+
305
+ ```ts title="@/app/api/chat/route.ts"
306
+ import { openai } from "@ai-sdk/openai";
307
+ import { streamText, convertToModelMessages, tool, createUIMessageStreamResponse, toUIMessageStream } from "ai";
308
+ import { z } from "zod";
309
+
310
+ export async function POST(req: Request) {
311
+ const { messages } = await req.json();
312
+
313
+ const result = streamText({
314
+ model: openai("gpt-5.4-mini"),
315
+ messages: await convertToModelMessages(messages),
316
+ tools: {
317
+ deploy: tool({
318
+ description: "Deploy the current build to an environment.",
319
+ inputSchema: z.object({ target: z.string() }),
320
+ execute: async ({ target }) => ({ deployed: target }),
321
+ }),
322
+ },
323
+ toolApproval: {
324
+ deploy: (input) =>
325
+ input.target === "production" ? "user-approval" : "not-applicable",
326
+ },
327
+ });
328
+
329
+ return createUIMessageStreamResponse({
330
+ stream: toUIMessageStream({ stream: result.stream }),
331
+ });
332
+ }
333
+ ```
334
+
335
+ On the client, configure `useChat` with `sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses` so the response is sent back to the server when the user decides:
336
+
337
+ ```tsx title="@/app/page.tsx"
338
+ "use client";
339
+
340
+ import { useChat } from "@ai-sdk/react";
341
+ import {
342
+ AssistantRuntimeProvider,
343
+ useAISDKRuntime,
344
+ } from "@assistant-ui/react-ai-sdk";
345
+ import { lastAssistantMessageIsCompleteWithApprovalResponses } from "ai";
346
+ import { Thread } from "@/components/assistant-ui/thread";
347
+
348
+ export default function Page() {
349
+ const chat = useChat({
350
+ api: "/api/chat",
351
+ sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses,
352
+ });
353
+ const runtime = useAISDKRuntime(chat);
354
+
355
+ return (
356
+ <AssistantRuntimeProvider runtime={runtime}>
357
+ <Thread />
358
+ </AssistantRuntimeProvider>
359
+ );
360
+ }
361
+ ```
362
+
363
+ Render the gate with a toolkit entry. The `approval` field carries the gate state, and `respondToApproval` is the only correct way to acknowledge it (it reads the approval id from the part):
364
+
365
+ ```tsx title="@/app/page.tsx"
366
+ "use client";
367
+
368
+ import { useChat } from "@ai-sdk/react";
369
+ import {
370
+ AssistantRuntimeProvider,
371
+ defineToolkit,
372
+ Tools,
373
+ useAui,
374
+ } from "@assistant-ui/react";
375
+ import { useAISDKRuntime } from "@assistant-ui/react-ai-sdk";
376
+ import { lastAssistantMessageIsCompleteWithApprovalResponses } from "ai";
377
+ import { Thread } from "@/components/assistant-ui/thread";
378
+
379
+ const toolkit = defineToolkit({
380
+ deploy: {
381
+ type: "backend",
382
+ render: ({ args, approval, respondToApproval, result }) => {
383
+ if (approval?.approved === undefined) {
384
+ return (
385
+ <div>
386
+ <p>Approve deploy to {args.target}?</p>
387
+ <button onClick={() => respondToApproval({ approved: true })}>
388
+ Approve
389
+ </button>
390
+ <button
391
+ onClick={() =>
392
+ respondToApproval({ approved: false, reason: "user denied" })
393
+ }
394
+ >
395
+ Deny
396
+ </button>
397
+ </div>
398
+ );
399
+ }
400
+ if (approval?.approved === false) return <p>Denied</p>;
401
+ if (result === undefined) return <p>Approved, deploying…</p>;
402
+ return <p>Deployed {result.deployed}</p>;
403
+ },
404
+ },
405
+ });
406
+
407
+ export default function Page() {
408
+ const chat = useChat({
409
+ api: "/api/chat",
410
+ sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses,
411
+ });
412
+ const runtime = useAISDKRuntime(chat);
413
+ const aui = useAui({ tools: Tools({ toolkit }) });
414
+
415
+ return (
416
+ <AssistantRuntimeProvider aui={aui} runtime={runtime}>
417
+ <Thread />
418
+ </AssistantRuntimeProvider>
419
+ );
420
+ }
421
+ ```
422
+
423
+ See the [tool UI guide](/docs/tools/tool-ui#server-side-approval-gates) for the full three-state semantics of `approval.approved` and the `isAutomatic` flag.
424
+
425
+ ## Quote context
426
+
427
+ 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:
428
+
429
+ ```ts title="@/app/api/chat/route.ts"
430
+ import {
431
+ streamText,
432
+ convertToModelMessages,
433
+ createUIMessageStreamResponse,
434
+ toUIMessageStream,
435
+ } from "ai";
436
+ import { injectQuoteContext } from "@assistant-ui/react-ai-sdk";
437
+ import { openai } from "@ai-sdk/openai";
438
+
439
+ export async function POST(req: Request) {
440
+ const { messages } = await req.json();
441
+ const result = streamText({
442
+ model: openai("gpt-5.4-mini"),
443
+ messages: await convertToModelMessages(injectQuoteContext(messages)),
444
+ });
445
+ return createUIMessageStreamResponse({
446
+ stream: toUIMessageStream({ stream: result.stream }),
447
+ });
448
+ }
449
+ ```
450
+
451
+ `injectQuoteContext` is idempotent: if the blockquote prefix is already present, it is not duplicated.
452
+
453
+ ## Token usage
454
+
455
+ `useThreadTokenUsage` exposes thread-level token usage on the client. Attach `usage` and `modelId` via `messageMetadata` on the server:
456
+
457
+ ```ts title="@/app/api/chat/route.ts"
458
+ import { streamText, convertToModelMessages, createUIMessageStreamResponse, toUIMessageStream } from "ai";
459
+ import { frontendTools } from "@assistant-ui/react-ai-sdk";
460
+
461
+ export async function POST(req: Request) {
462
+ const { messages, tools, config } = await req.json();
463
+ const result = streamText({
464
+ model: getModel(config?.modelName),
465
+ messages: await convertToModelMessages(messages),
466
+ tools: frontendTools(tools),
467
+ });
468
+ return createUIMessageStreamResponse({
469
+ stream: toUIMessageStream({
470
+ stream: result.stream,
471
+ messageMetadata: ({ part }) => {
472
+ if (part.type === "finish") {
473
+ return { usage: part.totalUsage };
474
+ }
475
+ if (part.type === "finish-step") {
476
+ return { modelId: part.response.modelId };
477
+ }
478
+ return undefined;
479
+ },
480
+ }),
481
+ });
482
+ }
483
+ ```
484
+
485
+ ```tsx title="@/components/TokenCounter.tsx"
486
+ "use client";
487
+
488
+ import { useThreadTokenUsage } from "@assistant-ui/react-ai-sdk";
489
+
490
+ export function TokenCounter() {
491
+ const usage = useThreadTokenUsage();
492
+ if (!usage) return null;
493
+ return <div>{usage.totalTokens} total tokens</div>;
494
+ }
495
+ ```
496
+
497
+ `getThreadMessageTokenUsage(message)` returns per-message usage if you need to show it inline.
498
+
499
+ ## Attachments
500
+
501
+ Attachments work through the standard [attachment adapter](/docs/runtimes/concepts/adapters#attachment-adapter). Pass it via `useChatRuntime`:
502
+
503
+ ```tsx
504
+ const runtime = useChatRuntime({
505
+ adapters: { attachments: myAttachmentAdapter },
506
+ });
507
+ ```
508
+
509
+ Your attachment adapter's `send` should return `content` parts in the AI SDK shape, e.g. for files:
510
+
511
+ ```ts
512
+ return {
513
+ ...attachment,
514
+ status: { type: "complete" },
515
+ content: [
516
+ {
517
+ type: "file",
518
+ mimeType: attachment.contentType ?? "",
519
+ filename: attachment.name,
520
+ data: await getFileDataURL(attachment.file),
521
+ },
522
+ ],
523
+ };
524
+ ```
525
+
526
+ For images, use `{ type: "image", image: <data url or remote url> }`. AI SDK will pass these to providers that accept multimodal content.
527
+
528
+ ## Persisting chat history
529
+
530
+ By default, messages live only in memory and reset on reload. To persist and restore history per thread, provide a `ThreadHistoryAdapter` via `adapters.history`.
531
+
532
+ <Callout type="warn">
533
+ 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.
534
+ </Callout>
535
+
536
+ <Callout type="info">
537
+ For server-side cloud persistence with zero adapter code, see the [AssistantCloud integration](/docs/cloud/ai-sdk-assistant-ui).
538
+ </Callout>
539
+
540
+ ```tsx
541
+ "use client";
542
+
543
+ import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
544
+ import type { ThreadHistoryAdapter } from "@assistant-ui/react";
545
+
546
+ const historyAdapter: ThreadHistoryAdapter = {
547
+ // Required by the type — unused by useChatRuntime.
548
+ async load() {
549
+ return { headId: null, messages: [] };
550
+ },
551
+ async append() {},
552
+
553
+ // fmt encodes UIMessage <-> storage rows (ai-sdk/v6 format).
554
+ withFormat: (fmt) => ({
555
+ async load() {
556
+ const rows = await fetch("/api/history").then((r) => r.json());
557
+ return { messages: rows.map(fmt.decode) };
558
+ },
559
+ async append(item) {
560
+ await fetch("/api/history", {
561
+ method: "POST",
562
+ body: JSON.stringify({
563
+ id: fmt.getId(item.message),
564
+ parent_id: item.parentId,
565
+ format: fmt.format,
566
+ content: fmt.encode(item),
567
+ }),
568
+ });
569
+ },
570
+ }),
571
+ };
572
+
573
+ function Chat() {
574
+ const runtime = useChatRuntime({ adapters: { history: historyAdapter } });
575
+ // ...
576
+ }
577
+ ```
578
+
579
+ 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.
580
+
581
+ ## Custom transport
582
+
583
+ `AssistantChatTransport` is the default. To point at a non-default endpoint, instantiate it with a custom `api`:
584
+
585
+ ```tsx
586
+ import {
587
+ useChatRuntime,
588
+ AssistantChatTransport,
589
+ } from "@assistant-ui/react-ai-sdk";
590
+
591
+ const runtime = useChatRuntime({
592
+ transport: new AssistantChatTransport({ api: "/my-custom-api/chat" }),
593
+ });
594
+ ```
595
+
596
+ 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.
597
+
598
+ ## Runtime options
599
+
600
+ Beyond transports and adapters, `useChatRuntime` accepts options that control thread routing, message grouping, and run resumption.
601
+
602
+ ### onThreadIdChange
603
+
604
+ Called whenever the active thread's settled ID changes, e.g. to sync the active thread to a URL query param:
605
+
606
+ ```tsx
607
+ const runtime = useChatRuntime({
608
+ onThreadIdChange: (threadId) => {
609
+ const url = new URL(window.location.href);
610
+ if (threadId) {
611
+ url.searchParams.set("thread", threadId);
612
+ } else {
613
+ url.searchParams.delete("thread");
614
+ }
615
+ window.history.replaceState(null, "", url);
616
+ },
617
+ });
618
+ ```
619
+
620
+ Only the settled ID is emitted: while a freshly created thread has not been initialized yet, the value is `undefined`, and the real ID is emitted once the thread initializes (with [AssistantCloud](/docs/cloud/ai-sdk-assistant-ui), this is the cloud thread ID). The transient local ID is never surfaced.
621
+
622
+ ### joinStrategy
623
+
624
+ Controls how consecutive assistant messages are rendered:
625
+
626
+ ```tsx
627
+ const runtime = useChatRuntime({
628
+ joinStrategy: "none",
629
+ });
630
+ ```
631
+
632
+ `"concat-content"` (the default) merges consecutive assistant messages into a single thread message. `"none"` keeps each assistant message as its own thread message, which is useful when a backend persists proactive or consecutive assistant messages as separate entries. See the [external store guide](/docs/runtimes/custom/external-store#useexternalmessageconverter-with-join-strategy) for the underlying join semantics.
633
+
634
+ ### onResume
635
+
636
+ Called when `runtime.thread.resumeRun(config)` is invoked. Provide it to bridge resume invocations into a custom replay channel, for example an SSE reconnect endpoint keyed by turn id:
637
+
638
+ ```tsx
639
+ const runtime = useChatRuntime({
640
+ onResume: async (config) => {
641
+ await reconnectToRun(config.runConfig);
642
+ },
643
+ });
644
+ ```
645
+
646
+ When omitted, `resumeRun` throws `"Runtime does not support resuming runs."`. For streams that should survive a page reload without a custom channel, use the built-in transport-level path instead: see [Resumable streams](/docs/guides/resumable-streams), which reconnects automatically on mount and reports failures via `onResumeError`.
647
+
648
+ ## Advanced: useAISDKRuntime
649
+
650
+ When you need direct access to the `useChat` instance (e.g. to share it with non-assistant-ui code), drop down to `useAISDKRuntime`:
651
+
652
+ ```tsx
653
+ import { useChat } from "@ai-sdk/react";
654
+ import { useAISDKRuntime } from "@assistant-ui/react-ai-sdk";
655
+
656
+ const chat = useChat();
657
+ const runtime = useAISDKRuntime(chat);
658
+ ```
659
+
660
+ `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.
661
+
662
+ `useAISDKRuntime` accepts `joinStrategy` and `onResume` (see [Runtime options](#runtime-options)) plus one option of its own, `cancelPendingToolCallsOnSend`:
663
+
664
+ ```tsx
665
+ const runtime = useAISDKRuntime(chat, {
666
+ cancelPendingToolCallsOnSend: false,
667
+ });
668
+ ```
669
+
670
+ When enabled (the default), sending a new message marks any pending interactive tool calls as failed with an error indicating the user cancelled them. Set it to `false` to leave pending tool calls untouched when the user sends a new message.
671
+
672
+ ## Adapter support
673
+
674
+ | Adapter | Supported via |
675
+ | --- | --- |
676
+ | Attachments | `adapters.attachments` |
677
+ | Speech | `adapters.speech` |
678
+ | Dictation | `adapters.dictation` |
679
+ | Feedback | `adapters.feedback` |
680
+ | History | `adapters.history` (must implement `withFormat`) |
681
+ | threadList | Via `cloud` (managed) or [RemoteThreadListRuntime](/docs/runtimes/concepts/threads) (custom DB) |
682
+
683
+ ## Key changes from v5
684
+
685
+ | Feature | v5 | v7 |
686
+ | --- | --- | --- |
687
+ | `ai` package | `ai@^5` | `ai@^7` |
688
+ | `@ai-sdk/react` | `@ai-sdk/react@^2` | `@ai-sdk/react@^4` |
689
+ | `convertToModelMessages` | Sync | Async (`await`) |
690
+ | Tool schema | `parameters: z.object({...})` | `inputSchema: zodSchema(z.object({...}))` |
691
+ | Response | `toDataStreamResponse()` | `createUIMessageStreamResponse()` |
692
+
693
+ ## Example
694
+
695
+ [`examples/with-ai-sdk-v7`](https://github.com/assistant-ui/assistant-ui/tree/main/examples/with-ai-sdk-v7) shows a complete reference implementation.
696
+
697
+ For responses that should survive a page reload mid-stream, see [Resumable streams](/docs/guides/resumable-streams), which wraps the same v7 byte stream in `assistant-stream/resumable`.
698
+
699
+ ## Next
700
+
701
+ <Cards>
702
+ <Card
703
+ title="Adapters"
704
+ description="Attachments, speech, feedback, history, suggestions; one source of truth."
705
+ href="/docs/runtimes/concepts/adapters"
706
+ />
707
+ <Card
708
+ title="Threads"
709
+ description="Single-thread, AssistantCloud, custom thread list."
710
+ href="/docs/runtimes/concepts/threads"
711
+ />
712
+ <Card
713
+ title="Resumable streams"
714
+ description="Survive page reloads and connection drops mid-response."
715
+ href="/docs/guides/resumable-streams"
716
+ />
717
+ </Cards>