@assistant-ui/mcp-docs-server 0.1.19 → 0.1.21

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 (108) hide show
  1. package/.docs/organized/code-examples/with-ag-ui.md +172 -1633
  2. package/.docs/organized/code-examples/with-ai-sdk-v6.md +42 -1640
  3. package/.docs/organized/code-examples/with-assistant-transport.md +40 -1743
  4. package/.docs/organized/code-examples/with-cloud.md +71 -1745
  5. package/.docs/organized/code-examples/with-custom-thread-list.md +87 -1723
  6. package/.docs/organized/code-examples/with-elevenlabs-scribe.md +70 -1637
  7. package/.docs/organized/code-examples/with-external-store.md +67 -1624
  8. package/.docs/organized/code-examples/with-ffmpeg.md +71 -1629
  9. package/.docs/organized/code-examples/with-langgraph.md +95 -1893
  10. package/.docs/organized/code-examples/with-parent-id-grouping.md +57 -1654
  11. package/.docs/organized/code-examples/with-react-hook-form.md +220 -2163
  12. package/.docs/organized/code-examples/with-react-router.md +66 -1318
  13. package/.docs/organized/code-examples/with-store.md +31 -31
  14. package/.docs/organized/code-examples/with-tanstack.md +77 -861
  15. package/.docs/organized/code-examples/with-tap-runtime.md +812 -0
  16. package/.docs/raw/docs/(docs)/cli.mdx +66 -0
  17. package/.docs/raw/docs/(docs)/copilots/make-assistant-tool-ui.mdx +0 -1
  18. package/.docs/raw/docs/(docs)/copilots/make-assistant-tool.mdx +0 -1
  19. package/.docs/raw/docs/(docs)/copilots/model-context.mdx +4 -4
  20. package/.docs/raw/docs/(docs)/copilots/motivation.mdx +3 -3
  21. package/.docs/raw/docs/(docs)/devtools.mdx +0 -1
  22. package/.docs/raw/docs/(docs)/guides/attachments.mdx +2 -3
  23. package/.docs/raw/docs/(docs)/guides/context-api.mdx +117 -117
  24. package/.docs/raw/docs/(docs)/guides/suggestions.mdx +296 -0
  25. package/.docs/raw/docs/(docs)/guides/tools.mdx +336 -513
  26. package/.docs/raw/docs/(docs)/index.mdx +33 -410
  27. package/.docs/raw/docs/(docs)/installation.mdx +450 -0
  28. package/.docs/raw/docs/(docs)/llm.mdx +209 -0
  29. package/.docs/raw/docs/(reference)/api-reference/context-providers/assistant-runtime-provider.mdx +0 -1
  30. package/.docs/raw/docs/(reference)/api-reference/context-providers/text-message-part-provider.mdx +0 -1
  31. package/.docs/raw/docs/(reference)/api-reference/integrations/react-data-stream.mdx +48 -3
  32. package/.docs/raw/docs/(reference)/api-reference/integrations/react-hook-form.mdx +0 -1
  33. package/.docs/raw/docs/(reference)/api-reference/integrations/vercel-ai-sdk.mdx +0 -1
  34. package/.docs/raw/docs/(reference)/api-reference/overview.mdx +9 -3
  35. package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar-more.mdx +20 -52
  36. package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar.mdx +16 -39
  37. package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-if.mdx +49 -50
  38. package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-modal.mdx +3 -11
  39. package/.docs/raw/docs/(reference)/api-reference/primitives/attachment.mdx +0 -3
  40. package/.docs/raw/docs/(reference)/api-reference/primitives/branch-picker.mdx +0 -1
  41. package/.docs/raw/docs/(reference)/api-reference/primitives/composer.mdx +5 -16
  42. package/.docs/raw/docs/(reference)/api-reference/primitives/composition.mdx +0 -1
  43. package/.docs/raw/docs/(reference)/api-reference/primitives/error.mdx +0 -1
  44. package/.docs/raw/docs/(reference)/api-reference/primitives/message-part.mdx +1 -2
  45. package/.docs/raw/docs/(reference)/api-reference/primitives/message.mdx +0 -1
  46. package/.docs/raw/docs/(reference)/api-reference/primitives/suggestion.mdx +152 -0
  47. package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item-more.mdx +0 -1
  48. package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item.mdx +1 -2
  49. package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list.mdx +1 -2
  50. package/.docs/raw/docs/(reference)/api-reference/primitives/thread.mdx +28 -40
  51. package/.docs/raw/docs/(reference)/api-reference/runtimes/assistant-runtime.mdx +0 -1
  52. package/.docs/raw/docs/(reference)/api-reference/runtimes/attachment-runtime.mdx +1 -2
  53. package/.docs/raw/docs/(reference)/api-reference/runtimes/composer-runtime.mdx +2 -3
  54. package/.docs/raw/docs/(reference)/api-reference/runtimes/message-part-runtime.mdx +1 -2
  55. package/.docs/raw/docs/(reference)/api-reference/runtimes/message-runtime.mdx +1 -2
  56. package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-item-runtime.mdx +0 -1
  57. package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-runtime.mdx +0 -1
  58. package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-runtime.mdx +1 -2
  59. package/.docs/raw/docs/(reference)/legacy/styled/assistant-modal.mdx +0 -1
  60. package/.docs/raw/docs/(reference)/legacy/styled/decomposition.mdx +5 -5
  61. package/.docs/raw/docs/(reference)/legacy/styled/markdown.mdx +0 -1
  62. package/.docs/raw/docs/(reference)/legacy/styled/thread.mdx +0 -1
  63. package/.docs/raw/docs/(reference)/migrations/v0-12.mdx +207 -33
  64. package/.docs/raw/docs/(reference)/react-compatibility.mdx +0 -1
  65. package/.docs/raw/docs/cloud/persistence/ai-sdk.mdx +0 -1
  66. package/.docs/raw/docs/cloud/persistence/langgraph.mdx +0 -1
  67. package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +0 -1
  68. package/.docs/raw/docs/runtimes/ai-sdk/v5-legacy.mdx +118 -0
  69. package/.docs/raw/docs/runtimes/ai-sdk/v6.mdx +198 -0
  70. package/.docs/raw/docs/runtimes/assistant-transport.mdx +3 -3
  71. package/.docs/raw/docs/runtimes/custom/custom-thread-list.mdx +5 -6
  72. package/.docs/raw/docs/runtimes/custom/external-store.mdx +9 -11
  73. package/.docs/raw/docs/runtimes/custom/local.mdx +43 -36
  74. package/.docs/raw/docs/runtimes/data-stream.mdx +35 -3
  75. package/.docs/raw/docs/runtimes/langgraph/index.mdx +1 -2
  76. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +0 -1
  77. package/.docs/raw/docs/runtimes/langserve.mdx +0 -1
  78. package/.docs/raw/docs/runtimes/mastra/full-stack-integration.mdx +0 -1
  79. package/.docs/raw/docs/runtimes/mastra/separate-server-integration.mdx +0 -1
  80. package/.docs/raw/docs/ui/accordion.mdx +259 -0
  81. package/.docs/raw/docs/ui/assistant-modal.mdx +1 -3
  82. package/.docs/raw/docs/ui/assistant-sidebar.mdx +1 -3
  83. package/.docs/raw/docs/ui/attachment.mdx +0 -2
  84. package/.docs/raw/docs/ui/badge.mdx +138 -0
  85. package/.docs/raw/docs/ui/diff-viewer.mdx +279 -0
  86. package/.docs/raw/docs/ui/file.mdx +152 -0
  87. package/.docs/raw/docs/ui/image.mdx +100 -0
  88. package/.docs/raw/docs/ui/markdown.mdx +0 -1
  89. package/.docs/raw/docs/ui/mermaid.mdx +0 -1
  90. package/.docs/raw/docs/ui/model-selector.mdx +224 -0
  91. package/.docs/raw/docs/ui/part-grouping.mdx +4 -5
  92. package/.docs/raw/docs/ui/reasoning.mdx +6 -5
  93. package/.docs/raw/docs/ui/scrollbar.mdx +26 -9
  94. package/.docs/raw/docs/ui/select.mdx +245 -0
  95. package/.docs/raw/docs/ui/sources.mdx +6 -5
  96. package/.docs/raw/docs/ui/streamdown.mdx +348 -0
  97. package/.docs/raw/docs/ui/syntax-highlighting.mdx +8 -63
  98. package/.docs/raw/docs/ui/tabs.mdx +259 -0
  99. package/.docs/raw/docs/ui/thread-list.mdx +98 -16
  100. package/.docs/raw/docs/ui/thread.mdx +57 -73
  101. package/.docs/raw/docs/ui/tool-fallback.mdx +0 -1
  102. package/.docs/raw/docs/ui/tool-group.mdx +1 -3
  103. package/README.md +3 -3
  104. package/package.json +4 -4
  105. package/src/tools/tests/examples.test.ts +1 -1
  106. package/.docs/raw/docs/(docs)/about-assistantui.mdx +0 -54
  107. package/.docs/raw/docs/(docs)/mcp-docs-server.mdx +0 -321
  108. package/.docs/raw/docs/runtimes/ai-sdk/use-chat.mdx +0 -219
@@ -1,321 +0,0 @@
1
- ---
2
- title: "MCP Docs Server"
3
- description: Access assistant-ui docs and examples directly in your IDE via MCP.
4
- ---
5
-
6
-
7
- `@assistant-ui/mcp-docs-server` provides direct access to assistant-ui's documentation and examples in Cursor, Windsurf, VSCode, Zed, Claude Code, or any other IDE or tool that supports MCP.
8
-
9
- The MCP server tools have been designed to allow an agent to query the specific information it needs to complete an assistant-ui related task - for example: implementing chat components, integrating with different runtimes, understanding component architecture, and troubleshooting issues.
10
-
11
- ## How it works
12
-
13
- Once it's installed in your IDE you can write prompts and assume the agent will understand everything about assistant-ui.
14
-
15
- ### Add features
16
-
17
- - "Add a chat interface with streaming support to my app"
18
- - "Implement branching conversations with the BranchPicker component"
19
- - "Add attachment support to my assistant using the Attachment primitive"
20
-
21
- ### Ask about integrations
22
-
23
- - "How do I integrate assistant-ui with the Vercel AI SDK?
24
- Show me a working example for my Next.js app"
25
- - "Does assistant-ui support React Server Components? How do I use it?"
26
- - "Can I use assistant-ui with LangGraph? Show me how to set up the runtime"
27
-
28
- ### Debug or update existing code
29
-
30
- - "My Thread component isn't updating when new messages arrive, what could be wrong?"
31
- - "How do I customize the styling of the AssistantModal component?"
32
- - "I need to add tool UI rendering to my assistant, show me how to implement it"
33
-
34
- **And more** - if you have a question, try asking your IDE and let it look it up for you.
35
-
36
- ## Installation
37
-
38
- Choose your IDE or tool to get started with the assistant-ui MCP docs server.
39
-
40
- ### Claude Code
41
-
42
- Add the MCP server using the Claude Code CLI:
43
-
44
- ```bash
45
- # Add to current project only
46
- claude mcp add assistant-ui -- npx -y @assistant-ui/mcp-docs-server
47
-
48
- # Or add globally for all projects
49
- claude mcp add --scope user assistant-ui -- npx -y @assistant-ui/mcp-docs-server
50
- ```
51
-
52
- To manage the server:
53
- ```bash
54
- # View configured servers
55
- claude mcp list
56
-
57
- # Get server details
58
- claude mcp get assistant-ui
59
-
60
- # Remove the server
61
- claude mcp remove assistant-ui
62
- ```
63
-
64
- ### Claude Desktop
65
-
66
- Add to your Claude Desktop configuration:
67
- - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
68
- - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
69
-
70
- ```json
71
- {
72
- "mcpServers": {
73
- "assistant-ui": {
74
- "command": "npx",
75
- "args": ["-y", "@assistant-ui/mcp-docs-server"]
76
- }
77
- }
78
- }
79
- ```
80
-
81
- ### IDEs
82
-
83
- For Cursor, Windsurf, VSCode, and Zed, manually add the following configuration:
84
-
85
- - **Cursor**: Edit `.cursor/mcp.json` in your project root, or `~/.cursor/mcp.json` for global configuration
86
- - **Windsurf**: Edit `~/.codeium/windsurf/mcp_config.json` (only supports global configuration)
87
- - **VSCode**: Edit `~/.vscode/mcp.json` in your project root
88
- - **Zed**: Edit `settings.json` (open via `cmd+,` or `zed: open settings`)
89
-
90
- ### MacOS/Linux
91
-
92
- {/*
93
- LLM CONTEXT: This Tabs component shows MCP server configuration for different IDEs on MacOS/Linux.
94
- Each tab displays the JSON configuration needed to set up the assistant-ui MCP docs server in that specific IDE.
95
- The tabs help users find the correct configuration format for their IDE (Cursor, Windsurf, VSCode, or Zed).
96
- Each tab shows the exact JSON structure and file paths needed for that IDE's MCP configuration.
97
- */}
98
-
99
- <Tabs items={["cursor", "windsurf", "vscode", "zed"]}>
100
- <Tab>
101
- ```json
102
- {
103
- "mcpServers": {
104
- "assistant-ui": {
105
- "command": "npx",
106
- "args": ["-y", "@assistant-ui/mcp-docs-server"]
107
- }
108
- }
109
- }
110
- ```
111
- </Tab>
112
- <Tab>
113
- ```json
114
- {
115
- "mcpServers": {
116
- "assistant-ui": {
117
- "command": "npx",
118
- "args": ["-y", "@assistant-ui/mcp-docs-server"]
119
- }
120
- }
121
- }
122
- ```
123
- </Tab>
124
- <Tab>
125
- ```json
126
- {
127
- "servers": {
128
- "assistant-ui": {
129
- "command": "npx",
130
- "args": ["-y", "@assistant-ui/mcp-docs-server"],
131
- "type": "stdio"
132
- }
133
- }
134
- }
135
- ```
136
- </Tab>
137
- <Tab>
138
- ```json
139
- {
140
- "context_servers": {
141
- "assistant-ui": {
142
- "command": {
143
- "path": "npx",
144
- "args": ["-y", "@assistant-ui/mcp-docs-server"],
145
- "env": {}
146
- },
147
- "settings": {}
148
- }
149
- }
150
- }
151
- ```
152
- </Tab>
153
- </Tabs>
154
-
155
- ### Windows
156
-
157
- {/*
158
- LLM CONTEXT: This Tabs component shows MCP server configuration for different IDEs on Windows.
159
- Each tab displays the Windows-specific JSON configuration needed to set up the assistant-ui MCP docs server.
160
- The tabs help Windows users find the correct configuration format for their IDE, using cmd instead of direct npx.
161
- Each tab shows the Windows-specific command structure needed for that IDE's MCP configuration.
162
- On latest Windsurf and Cursor the direct npx command works, while it's still unconfirmed if this has been fixed for VSCode.
163
- */}
164
-
165
- <Tabs items={["cursor", "windsurf", "vscode", "zed"]}>
166
- <Tab>
167
- ```json
168
- {
169
- "mcpServers": {
170
- "assistant-ui": {
171
- "command": "npx",
172
- "args": ["-y", "@assistant-ui/mcp-docs-server"]
173
- }
174
- }
175
- }
176
- ```
177
- </Tab>
178
- <Tab>
179
- ```json
180
- {
181
- "mcpServers": {
182
- "assistant-ui": {
183
- "command": "npx",
184
- "args": ["-y", "@assistant-ui/mcp-docs-server"]
185
- }
186
- }
187
- }
188
- ```
189
- </Tab>
190
- <Tab>
191
- ```json
192
- {
193
- "servers": {
194
- "assistant-ui": {
195
- "command": "cmd",
196
- "args": ["/c", "npx", "-y", "@assistant-ui/mcp-docs-server"],
197
- "type": "stdio"
198
- }
199
- }
200
- }
201
- ```
202
- </Tab>
203
- <Tab>
204
- ```json
205
- {
206
- "context_servers": {
207
- "assistant-ui": {
208
- "command": {
209
- "path": "cmd",
210
- "args": ["/c", "npx", "-y", "@assistant-ui/mcp-docs-server"],
211
- "env": {}
212
- },
213
- "settings": {}
214
- }
215
- }
216
- }
217
- ```
218
- </Tab>
219
- </Tabs>
220
-
221
- ## After Configuration
222
-
223
- ### Claude Code
224
-
225
- The MCP server starts automatically once added. You can verify it's working by mentioning assistant-ui in your prompts - Claude will have direct access to the documentation and examples.
226
-
227
- ### Claude Desktop
228
-
229
- 1. Restart Claude Desktop after updating the configuration
230
- 2. The MCP server will start automatically when Claude Desktop launches
231
- 3. You can verify it's working by asking about assistant-ui - Claude will have direct access to the documentation and examples
232
-
233
- ### Cursor
234
-
235
- 1. Open Cursor settings by pressing `Cmd/Ctrl + ,`
236
- 2. Navigate to the MCP settings section
237
- 3. Find "assistant-ui" in the list of MCP servers and click "enable"
238
- 4. The server should start automatically. You'll see a status indicator showing it's running
239
- 5. If you have an agent chat open, you'll need to re-open it or start a new chat to use the MCP server
240
-
241
- The MCP server will automatically start whenever you open Cursor. You can verify it's working by mentioning assistant-ui documentation or examples in your prompts - the agent should now have direct access to this information.
242
-
243
- ### Windsurf
244
-
245
- 1. Fully quit and re-open Windsurf
246
- 2. The MCP server should start automatically. You can verify this in the MCP settings panel
247
- 3. If tool calls start failing, go to Windsurf's MCP settings and re-start the MCP server. This is a common Windsurf MCP issue and isn't specific to this server. Currently, Cursor's MCP implementation tends to be more stable than Windsurf's
248
-
249
- In both IDEs it may take a minute for the MCP server to start the first time as it needs to download the package from npm.
250
-
251
- ### VSCode
252
-
253
- 1. Open VSCode settings by pressing `Cmd/Ctrl + ,`
254
- 2. Search for "MCP" in the settings search bar
255
- 3. Enable the "Chat > MCP" option by checking the checkbox
256
- 4. Open GitHub Copilot Chat and switch to "Agent" mode (MCP only works in Agent mode)
257
- 5. Open the `mcp.json` file and click the "start" button that appears in the editor
258
- 6. Once started, you can click the tools button in the Copilot pane to see available tools
259
-
260
- The tools button should show "assistantUIDocs" and "assistantUIExamples" as available tools when the server is running correctly.
261
-
262
- ### Zed
263
-
264
- 1. Open Zed settings by pressing `Cmd/Ctrl + ,` or using `zed: open settings`
265
- 2. The MCP server configuration should be in your `settings.json` under the `context_servers` key
266
- 3. The server will start automatically when you use the Assistant Panel
267
- 4. You can also add servers through the Agent Panel's Settings view (accessible via `agent: open configuration`)
268
- 5. In the Assistant Panel, you can verify the server is available by checking the tools dropdown
269
-
270
- Zed will automatically start the MCP server when needed. The assistant-ui documentation and examples will be available to the AI assistant in your conversations.
271
-
272
- ### Claude Desktop
273
-
274
- 1. Restart Claude Desktop after updating the configuration
275
- 2. The MCP server will start automatically when Claude Desktop launches
276
- 3. You can verify it's working by asking about assistant-ui - Claude will have direct access to the documentation and examples
277
-
278
- ## Available Agent Tools
279
-
280
- ### assistantUIDocs
281
-
282
- Access assistant-ui's complete documentation:
283
-
284
- - Getting started guides and installation instructions
285
- - Component API references (Thread, AssistantModal, Composer, etc.)
286
- - Runtime documentation (AI SDK, LangGraph, OpenAI Assistants)
287
- - Integration guides and best practices
288
- - Architecture and concept explanations
289
-
290
- ### assistantUIExamples
291
-
292
- Browse complete code examples:
293
-
294
- - Integration with Vercel AI SDK
295
- - React Server Components implementation
296
- - LangGraph runtime setup
297
- - OpenAI Assistants integration
298
- - Local Ollama usage
299
- - External store management
300
- - React Hook Form integration
301
- - Tool UI implementation patterns
302
-
303
- Each example includes full source code, configuration files, and implementation details that can be directly referenced or adapted for your project.
304
-
305
- ## Common Issues
306
-
307
- 1. **Server Not Starting**
308
-
309
- - Ensure npx is installed and working
310
- - Check for conflicting MCP servers
311
- - Verify your configuration file syntax
312
- - On Windows, make sure to use the Windows-specific configuration
313
-
314
- 2. **Tool Calls Failing**
315
- - Restart the MCP server and/or your IDE
316
- - Update to the latest version of your IDE
317
-
318
- {/*
319
- Attribution:
320
- This docs page, and `@assistant-ui/mcp-docs-server`, is inspired by and based on Mastra's excellent mcp docs server and docs page: https://github.com/mastra/mcp-docs-server/blob/main/docs/mcp-docs-server.mdx
321
- */}
@@ -1,219 +0,0 @@
1
- ---
2
- title: AI SDK v5
3
- description: Integrate Vercel AI SDK v5 with useChatRuntime for streaming chat.
4
- ---
5
-
6
- import { InstallCommand } from "@/components/docs/fumadocs/install/install-command";
7
-
8
- ## Overview
9
-
10
- Integration with the Vercel AI SDK v5 using the new `useChatRuntime` hook from `@assistant-ui/react-ai-sdk`.
11
- This provides a streamlined way to integrate AI SDK v5 features including the new streamText API and improved TypeScript support.
12
-
13
- ## Getting Started
14
-
15
-
16
- <Steps>
17
- <Step>
18
- ### Create a Next.JS project
19
-
20
- ```sh
21
- npx create-next-app@latest my-app
22
- cd my-app
23
- ```
24
-
25
- </Step>
26
- <Step>
27
-
28
- ### Install AI SDK v5 and `@assistant-ui/react`
29
-
30
- <InstallCommand npm={["@assistant-ui/react", "@assistant-ui/react-ai-sdk", "ai", "@ai-sdk/openai"]} />
31
-
32
- </Step>
33
- <Step>
34
-
35
- ### Setup a backend route under `/api/chat`
36
-
37
- `@/app/api/chat/route.ts`
38
-
39
- ```tsx
40
- import { openai } from "@ai-sdk/openai";
41
- import { streamText, UIMessage, convertToModelMessages, tool, zodSchema } from "ai";
42
- import { frontendTools } from "@assistant-ui/react-ai-sdk";
43
- import { z } from "zod";
44
-
45
- // Allow streaming responses up to 30 seconds
46
- export const maxDuration = 30;
47
-
48
- export async function POST(req: Request) {
49
- const {
50
- messages,
51
- system,
52
- tools,
53
- }: {
54
- messages: UIMessage[];
55
- system?: string; // System message forwarded from AssistantChatTransport
56
- tools?: any; // Frontend tools forwarded from AssistantChatTransport
57
- } = await req.json();
58
-
59
- const result = streamText({
60
- model: openai("gpt-4o"),
61
- system, // Use the system message from the frontend if provided
62
- messages: convertToModelMessages(messages),
63
- tools: {
64
- // Wrap frontend tools with frontendTools helper
65
- ...frontendTools(tools),
66
- // Backend tools
67
- get_current_weather: tool({
68
- description: "Get the current weather",
69
- inputSchema: zodSchema(
70
- z.object({
71
- city: z.string(),
72
- }),
73
- ),
74
- execute: async ({ city }) => {
75
- return `The weather in ${city} is sunny`;
76
- },
77
- }),
78
- },
79
- });
80
-
81
- return result.toUIMessageStreamResponse();
82
- }
83
- ```
84
-
85
- </Step>
86
- <Step>
87
-
88
- ### Wrap your app with `AssistantRuntimeProvider` using `useChatRuntime`
89
-
90
- `@/app/page.tsx`
91
-
92
- ```tsx
93
- "use client";
94
-
95
- import { Thread } from "@/components/assistant-ui/thread";
96
- import { AssistantRuntimeProvider } from "@assistant-ui/react";
97
- import { useChatRuntime, AssistantChatTransport } from "@assistant-ui/react-ai-sdk";
98
-
99
- export default function Home() {
100
- const runtime = useChatRuntime({
101
- transport: new AssistantChatTransport({
102
- api: "/api/chat",
103
- }),
104
- });
105
-
106
- return (
107
- <AssistantRuntimeProvider runtime={runtime}>
108
- <div className="h-full">
109
- <Thread />
110
- </div>
111
- </AssistantRuntimeProvider>
112
- );
113
- }
114
- ```
115
-
116
- </Step>
117
- </Steps>
118
-
119
- ## API Reference
120
-
121
- ### useChatRuntime
122
-
123
- Creates a runtime directly with AI SDK v5's `useChat` hook integration.
124
-
125
- ```tsx
126
- import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
127
-
128
- const runtime = useChatRuntime({
129
- api: "/api/chat",
130
- // All standard useChat options are supported
131
- });
132
- ```
133
-
134
- <Callout type="info">
135
- By default, `useChatRuntime` uses `AssistantChatTransport` which automatically
136
- forwards system messages and frontend tools to your backend API. This enables
137
- your backend to receive the full context from the assistant-ui.
138
- </Callout>
139
-
140
- ### Custom Transport Configuration
141
-
142
- If you need to customize the transport configuration:
143
-
144
- ```tsx
145
- import { DefaultChatTransport } from "ai";
146
- import { AssistantChatTransport } from "@assistant-ui/react-ai-sdk";
147
- import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
148
-
149
- // Example 1: Custom API URL while keeping system/tools forwarding
150
- const runtime = useChatRuntime({
151
- transport: new AssistantChatTransport({
152
- api: "/my-custom-api/chat", // Custom API URL with forwarding
153
- }),
154
- });
155
-
156
- // Example 2: Disable system/tools forwarding
157
- const runtime = useChatRuntime({
158
- api: "/api/chat",
159
- transport: new DefaultChatTransport(), // Standard AI SDK transport without forwarding
160
- });
161
- ```
162
-
163
- <Callout type="warning">
164
- When customizing the API URL, you must explicitly use `AssistantChatTransport`
165
- if you want to keep frontend system messages and tools forwarding. Simply
166
- passing `api` to `useChatRuntime` will use the default transport
167
- configuration.
168
- </Callout>
169
-
170
- #### Transport Options
171
-
172
- - **`AssistantChatTransport`** (default): Automatically forwards system messages and frontend tools from the assistant-ui context to your backend
173
- - **`DefaultChatTransport`**: Standard AI SDK transport without automatic forwarding
174
-
175
- ### Using Frontend Tools with `frontendTools`
176
-
177
- When using `AssistantChatTransport`, frontend tools are forwarded to your backend. Use the `frontendTools` helper to properly integrate them:
178
-
179
- ```tsx
180
- import { frontendTools } from "@assistant-ui/react-ai-sdk";
181
-
182
- export async function POST(req: Request) {
183
- const { messages, system, tools } = await req.json();
184
-
185
- const result = streamText({
186
- model: openai("gpt-4o"),
187
- system,
188
- messages: convertToModelMessages(messages),
189
- tools: {
190
- // Wrap frontend tools with the helper
191
- ...frontendTools(tools),
192
- // Your backend tools
193
- myBackendTool: tool({
194
- // ...
195
- }),
196
- },
197
- });
198
-
199
- return result.toUIMessageStreamResponse();
200
- }
201
- ```
202
-
203
- The `frontendTools` helper converts frontend tool definitions to the AI SDK format and ensures they are properly handled by the streaming response.
204
-
205
- ### useAISDKRuntime (Advanced)
206
-
207
- For advanced use cases where you need direct access to the `useChat` hook:
208
-
209
- ```tsx
210
- import { useChat } from "@ai-sdk/react";
211
- import { useAISDKRuntime } from "@assistant-ui/react-ai-sdk";
212
-
213
- const chat = useChat();
214
- const runtime = useAISDKRuntime(chat);
215
- ```
216
-
217
- ## Example
218
-
219
- For a complete example, check out the [AI SDK v6 example](https://github.com/assistant-ui/assistant-ui/tree/main/examples/with-ai-sdk-v6) in our repository.