@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.
- package/.docs/organized/code-examples/with-ag-ui.md +172 -1633
- package/.docs/organized/code-examples/with-ai-sdk-v6.md +42 -1640
- package/.docs/organized/code-examples/with-assistant-transport.md +40 -1743
- package/.docs/organized/code-examples/with-cloud.md +71 -1745
- package/.docs/organized/code-examples/with-custom-thread-list.md +87 -1723
- package/.docs/organized/code-examples/with-elevenlabs-scribe.md +70 -1637
- package/.docs/organized/code-examples/with-external-store.md +67 -1624
- package/.docs/organized/code-examples/with-ffmpeg.md +71 -1629
- package/.docs/organized/code-examples/with-langgraph.md +95 -1893
- package/.docs/organized/code-examples/with-parent-id-grouping.md +57 -1654
- package/.docs/organized/code-examples/with-react-hook-form.md +220 -2163
- package/.docs/organized/code-examples/with-react-router.md +66 -1318
- package/.docs/organized/code-examples/with-store.md +31 -31
- package/.docs/organized/code-examples/with-tanstack.md +77 -861
- package/.docs/organized/code-examples/with-tap-runtime.md +812 -0
- package/.docs/raw/docs/(docs)/cli.mdx +66 -0
- package/.docs/raw/docs/(docs)/copilots/make-assistant-tool-ui.mdx +0 -1
- package/.docs/raw/docs/(docs)/copilots/make-assistant-tool.mdx +0 -1
- package/.docs/raw/docs/(docs)/copilots/model-context.mdx +4 -4
- package/.docs/raw/docs/(docs)/copilots/motivation.mdx +3 -3
- package/.docs/raw/docs/(docs)/devtools.mdx +0 -1
- package/.docs/raw/docs/(docs)/guides/attachments.mdx +2 -3
- package/.docs/raw/docs/(docs)/guides/context-api.mdx +117 -117
- package/.docs/raw/docs/(docs)/guides/suggestions.mdx +296 -0
- package/.docs/raw/docs/(docs)/guides/tools.mdx +336 -513
- package/.docs/raw/docs/(docs)/index.mdx +33 -410
- package/.docs/raw/docs/(docs)/installation.mdx +450 -0
- package/.docs/raw/docs/(docs)/llm.mdx +209 -0
- package/.docs/raw/docs/(reference)/api-reference/context-providers/assistant-runtime-provider.mdx +0 -1
- package/.docs/raw/docs/(reference)/api-reference/context-providers/text-message-part-provider.mdx +0 -1
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-data-stream.mdx +48 -3
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-hook-form.mdx +0 -1
- package/.docs/raw/docs/(reference)/api-reference/integrations/vercel-ai-sdk.mdx +0 -1
- package/.docs/raw/docs/(reference)/api-reference/overview.mdx +9 -3
- package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar-more.mdx +20 -52
- package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar.mdx +16 -39
- package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-if.mdx +49 -50
- package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-modal.mdx +3 -11
- package/.docs/raw/docs/(reference)/api-reference/primitives/attachment.mdx +0 -3
- package/.docs/raw/docs/(reference)/api-reference/primitives/branch-picker.mdx +0 -1
- package/.docs/raw/docs/(reference)/api-reference/primitives/composer.mdx +5 -16
- package/.docs/raw/docs/(reference)/api-reference/primitives/composition.mdx +0 -1
- package/.docs/raw/docs/(reference)/api-reference/primitives/error.mdx +0 -1
- package/.docs/raw/docs/(reference)/api-reference/primitives/message-part.mdx +1 -2
- package/.docs/raw/docs/(reference)/api-reference/primitives/message.mdx +0 -1
- package/.docs/raw/docs/(reference)/api-reference/primitives/suggestion.mdx +152 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item-more.mdx +0 -1
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item.mdx +1 -2
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list.mdx +1 -2
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread.mdx +28 -40
- package/.docs/raw/docs/(reference)/api-reference/runtimes/assistant-runtime.mdx +0 -1
- package/.docs/raw/docs/(reference)/api-reference/runtimes/attachment-runtime.mdx +1 -2
- package/.docs/raw/docs/(reference)/api-reference/runtimes/composer-runtime.mdx +2 -3
- package/.docs/raw/docs/(reference)/api-reference/runtimes/message-part-runtime.mdx +1 -2
- package/.docs/raw/docs/(reference)/api-reference/runtimes/message-runtime.mdx +1 -2
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-item-runtime.mdx +0 -1
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-runtime.mdx +0 -1
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-runtime.mdx +1 -2
- package/.docs/raw/docs/(reference)/legacy/styled/assistant-modal.mdx +0 -1
- package/.docs/raw/docs/(reference)/legacy/styled/decomposition.mdx +5 -5
- package/.docs/raw/docs/(reference)/legacy/styled/markdown.mdx +0 -1
- package/.docs/raw/docs/(reference)/legacy/styled/thread.mdx +0 -1
- package/.docs/raw/docs/(reference)/migrations/v0-12.mdx +207 -33
- package/.docs/raw/docs/(reference)/react-compatibility.mdx +0 -1
- package/.docs/raw/docs/cloud/persistence/ai-sdk.mdx +0 -1
- package/.docs/raw/docs/cloud/persistence/langgraph.mdx +0 -1
- package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +0 -1
- package/.docs/raw/docs/runtimes/ai-sdk/v5-legacy.mdx +118 -0
- package/.docs/raw/docs/runtimes/ai-sdk/v6.mdx +198 -0
- package/.docs/raw/docs/runtimes/assistant-transport.mdx +3 -3
- package/.docs/raw/docs/runtimes/custom/custom-thread-list.mdx +5 -6
- package/.docs/raw/docs/runtimes/custom/external-store.mdx +9 -11
- package/.docs/raw/docs/runtimes/custom/local.mdx +43 -36
- package/.docs/raw/docs/runtimes/data-stream.mdx +35 -3
- package/.docs/raw/docs/runtimes/langgraph/index.mdx +1 -2
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +0 -1
- package/.docs/raw/docs/runtimes/langserve.mdx +0 -1
- package/.docs/raw/docs/runtimes/mastra/full-stack-integration.mdx +0 -1
- package/.docs/raw/docs/runtimes/mastra/separate-server-integration.mdx +0 -1
- package/.docs/raw/docs/ui/accordion.mdx +259 -0
- package/.docs/raw/docs/ui/assistant-modal.mdx +1 -3
- package/.docs/raw/docs/ui/assistant-sidebar.mdx +1 -3
- package/.docs/raw/docs/ui/attachment.mdx +0 -2
- package/.docs/raw/docs/ui/badge.mdx +138 -0
- package/.docs/raw/docs/ui/diff-viewer.mdx +279 -0
- package/.docs/raw/docs/ui/file.mdx +152 -0
- package/.docs/raw/docs/ui/image.mdx +100 -0
- package/.docs/raw/docs/ui/markdown.mdx +0 -1
- package/.docs/raw/docs/ui/mermaid.mdx +0 -1
- package/.docs/raw/docs/ui/model-selector.mdx +224 -0
- package/.docs/raw/docs/ui/part-grouping.mdx +4 -5
- package/.docs/raw/docs/ui/reasoning.mdx +6 -5
- package/.docs/raw/docs/ui/scrollbar.mdx +26 -9
- package/.docs/raw/docs/ui/select.mdx +245 -0
- package/.docs/raw/docs/ui/sources.mdx +6 -5
- package/.docs/raw/docs/ui/streamdown.mdx +348 -0
- package/.docs/raw/docs/ui/syntax-highlighting.mdx +8 -63
- package/.docs/raw/docs/ui/tabs.mdx +259 -0
- package/.docs/raw/docs/ui/thread-list.mdx +98 -16
- package/.docs/raw/docs/ui/thread.mdx +57 -73
- package/.docs/raw/docs/ui/tool-fallback.mdx +0 -1
- package/.docs/raw/docs/ui/tool-group.mdx +1 -3
- package/README.md +3 -3
- package/package.json +4 -4
- package/src/tools/tests/examples.test.ts +1 -1
- package/.docs/raw/docs/(docs)/about-assistantui.mdx +0 -54
- package/.docs/raw/docs/(docs)/mcp-docs-server.mdx +0 -321
- package/.docs/raw/docs/runtimes/ai-sdk/use-chat.mdx +0 -219
|
@@ -7,11 +7,108 @@ description: Unified state API replaces individual context hooks.
|
|
|
7
7
|
|
|
8
8
|
Version 0.12 introduces a complete rewrite of the state management system with a more consistent API.
|
|
9
9
|
|
|
10
|
+
## Automatic Migration
|
|
11
|
+
|
|
12
|
+
We provide a codemod to automatically migrate your code:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx assistant-ui@latest upgrade
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
This will automatically handle the hook renames and update your imports.
|
|
19
|
+
|
|
10
20
|
## Breaking Changes
|
|
11
21
|
|
|
12
|
-
### 1.
|
|
22
|
+
### 1. Assistant API Hooks Renamed
|
|
23
|
+
|
|
24
|
+
The core hooks have been renamed for consistency and clarity:
|
|
25
|
+
|
|
26
|
+
- `useAssistantApi` → `useAui`
|
|
27
|
+
- `useAssistantState` → `useAuiState`
|
|
28
|
+
- `useAssistantEvent` → `useAuiEvent`
|
|
29
|
+
|
|
30
|
+
The variable naming convention has also changed from `api` to `aui`.
|
|
31
|
+
|
|
32
|
+
#### Migration
|
|
33
|
+
|
|
34
|
+
**Before:**
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import {
|
|
38
|
+
useAssistantApi,
|
|
39
|
+
useAssistantState,
|
|
40
|
+
useAssistantEvent,
|
|
41
|
+
} from "@assistant-ui/react";
|
|
42
|
+
|
|
43
|
+
function MyComponent() {
|
|
44
|
+
const api = useAssistantApi();
|
|
45
|
+
const isRunning = useAssistantState(({ thread }) => thread.isRunning);
|
|
46
|
+
|
|
47
|
+
useAssistantEvent("thread.started", () => {
|
|
48
|
+
console.log("Thread started");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const handleSend = () => {
|
|
52
|
+
api.composer().send();
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return <button onClick={handleSend}>Send</button>;
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**After:**
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
import { useAui, useAuiState, useAuiEvent } from "@assistant-ui/react";
|
|
63
|
+
|
|
64
|
+
function MyComponent() {
|
|
65
|
+
const aui = useAui();
|
|
66
|
+
const isRunning = useAuiState(({ thread }) => thread.isRunning);
|
|
67
|
+
|
|
68
|
+
useAuiEvent("thread.started", () => {
|
|
69
|
+
console.log("Thread started");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const handleSend = () => {
|
|
73
|
+
aui.composer().send();
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
return <button onClick={handleSend}>Send</button>;
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Automatic Migration:**
|
|
81
|
+
|
|
82
|
+
Run the codemod to automatically update your code:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npx assistant-ui@latest upgrade
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The codemod will:
|
|
89
|
+
- Rename all hook imports (`useAssistantApi` → `useAui`, etc.)
|
|
90
|
+
- Rename `const api = useAui()` declarations to `const aui = useAui()`
|
|
91
|
+
- Update all references to the `api` variable throughout your codebase
|
|
92
|
+
- Correctly handle scoping (won't rename `api` variables from other sources)
|
|
93
|
+
|
|
94
|
+
**Backwards Compatibility:**
|
|
95
|
+
|
|
96
|
+
The old names are still available as deprecated exports until v0.13:
|
|
13
97
|
|
|
14
|
-
|
|
98
|
+
```tsx
|
|
99
|
+
// Still works, but deprecated
|
|
100
|
+
import {
|
|
101
|
+
useAssistantApi,
|
|
102
|
+
useAssistantState,
|
|
103
|
+
useAssistantEvent,
|
|
104
|
+
} from "@assistant-ui/react";
|
|
105
|
+
|
|
106
|
+
const api = useAssistantApi(); // deprecated but functional
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 2. Context Hooks Replaced with Unified State API
|
|
110
|
+
|
|
111
|
+
All individual context hooks have been replaced with a single `useAuiState` hook and `useAui` for actions.
|
|
15
112
|
|
|
16
113
|
#### What changed
|
|
17
114
|
|
|
@@ -19,30 +116,30 @@ The following hooks have been removed:
|
|
|
19
116
|
|
|
20
117
|
**Removed Hooks:**
|
|
21
118
|
|
|
22
|
-
- `useMessageUtils` → Use `
|
|
23
|
-
- `useMessageUtilsStore` → Use `
|
|
24
|
-
- `useToolUIs` → Use `
|
|
25
|
-
- `useToolUIsStore` → Use `
|
|
119
|
+
- `useMessageUtils` → Use `useAuiState(({ message }) => message.isHovering)` / `useAuiState(({ message }) => message.isCopied)`
|
|
120
|
+
- `useMessageUtilsStore` → Use `useAui()` with `aui.message().setIsHovering()` / `aui.message().setIsCopied()`
|
|
121
|
+
- `useToolUIs` → Use `useAuiState(({ tools }) => tools)` and `useAui()` with `aui.tools()`
|
|
122
|
+
- `useToolUIsStore` → Use `useAui()` with `aui.tools()`
|
|
26
123
|
|
|
27
124
|
**Deprecated Hooks:**
|
|
28
125
|
|
|
29
|
-
- `useAssistantRuntime` → Use `
|
|
30
|
-
- `useThread` → Use `
|
|
31
|
-
- `useThreadRuntime` → Use `
|
|
32
|
-
- `useMessage` → Use `
|
|
33
|
-
- `useMessageRuntime` → Use `
|
|
34
|
-
- `useComposer` → Use `
|
|
35
|
-
- `useComposerRuntime` → Use `
|
|
36
|
-
- `useEditComposer` → Use `
|
|
37
|
-
- `useThreadListItem` → Use `
|
|
38
|
-
- `useThreadListItemRuntime` → Use `
|
|
39
|
-
- `useMessagePart` → Use `
|
|
40
|
-
- `useMessagePartRuntime` → Use `
|
|
41
|
-
- `useAttachment` → Use `
|
|
42
|
-
- `useAttachmentRuntime` → Use `
|
|
43
|
-
- `useThreadModelContext` / `useThreadModelConfig` → Use `
|
|
44
|
-
- `useThreadComposer` → Use `
|
|
45
|
-
- `useThreadList` → Use `
|
|
126
|
+
- `useAssistantRuntime` → Use `useAui()`
|
|
127
|
+
- `useThread` → Use `useAuiState(({ thread }) => thread)`
|
|
128
|
+
- `useThreadRuntime` → Use `useAui()` with `aui.thread()`
|
|
129
|
+
- `useMessage` → Use `useAuiState(({ message }) => message)`
|
|
130
|
+
- `useMessageRuntime` → Use `useAui()` with `aui.message()`
|
|
131
|
+
- `useComposer` → Use `useAuiState(({ composer }) => composer)`
|
|
132
|
+
- `useComposerRuntime` → Use `useAui()` with `aui.composer()`
|
|
133
|
+
- `useEditComposer` → Use `useAuiState(({ message }) => message.composer)`
|
|
134
|
+
- `useThreadListItem` → Use `useAuiState(({ threadListItem }) => threadListItem)`
|
|
135
|
+
- `useThreadListItemRuntime` → Use `useAui()` with `aui.threadListItem()`
|
|
136
|
+
- `useMessagePart` → Use `useAuiState(({ part }) => part)`
|
|
137
|
+
- `useMessagePartRuntime` → Use `useAui()` with `aui.part()`
|
|
138
|
+
- `useAttachment` → Use `useAuiState(({ attachment }) => attachment)`
|
|
139
|
+
- `useAttachmentRuntime` → Use `useAui()` with `aui.attachment()`
|
|
140
|
+
- `useThreadModelContext` / `useThreadModelConfig` → Use `useAuiState(({ thread }) => thread.modelContext)`
|
|
141
|
+
- `useThreadComposer` → Use `useAuiState(({ thread }) => thread.composer)`
|
|
142
|
+
- `useThreadList` → Use `useAuiState(({ threads }) => threads)`
|
|
46
143
|
|
|
47
144
|
#### Migration Examples
|
|
48
145
|
|
|
@@ -89,34 +186,111 @@ function MyComponent() {
|
|
|
89
186
|
**After:**
|
|
90
187
|
|
|
91
188
|
```tsx
|
|
92
|
-
import {
|
|
189
|
+
import { useAuiState, useAui } from "@assistant-ui/react";
|
|
93
190
|
|
|
94
191
|
function MyComponent() {
|
|
95
192
|
// Reading state - all through single hook
|
|
96
|
-
const messages =
|
|
97
|
-
const isRunning =
|
|
98
|
-
const composerText =
|
|
99
|
-
const messageRole =
|
|
193
|
+
const messages = useAuiState(({ thread }) => thread.messages);
|
|
194
|
+
const isRunning = useAuiState(({ thread }) => thread.isRunning);
|
|
195
|
+
const composerText = useAuiState(({ composer }) => composer.text);
|
|
196
|
+
const messageRole = useAuiState(({ message }) => message.role);
|
|
100
197
|
|
|
101
|
-
// Using
|
|
102
|
-
const
|
|
198
|
+
// Using client for actions
|
|
199
|
+
const aui = useAui();
|
|
103
200
|
|
|
104
201
|
const handleSend = () => {
|
|
105
|
-
|
|
202
|
+
aui.composer().send();
|
|
106
203
|
};
|
|
107
204
|
|
|
108
205
|
const handleReload = () => {
|
|
109
|
-
|
|
206
|
+
aui.message().reload();
|
|
110
207
|
};
|
|
111
208
|
|
|
112
209
|
const handleCancel = () => {
|
|
113
|
-
|
|
210
|
+
aui.thread().cancelRun();
|
|
114
211
|
};
|
|
115
212
|
|
|
116
213
|
return null;
|
|
117
214
|
}
|
|
118
215
|
```
|
|
119
216
|
|
|
217
|
+
### 3. Event Names Changed to camelCase
|
|
218
|
+
|
|
219
|
+
Event names used with `useAuiEvent` have been standardized to use camelCase instead of kebab-case.
|
|
220
|
+
|
|
221
|
+
#### What changed
|
|
222
|
+
|
|
223
|
+
The following event names have been updated:
|
|
224
|
+
|
|
225
|
+
| Old Name (kebab-case) | New Name (camelCase) |
|
|
226
|
+
| ----------------------------------- | ---------------------------------- |
|
|
227
|
+
| `thread.run-start` | `thread.runStart` |
|
|
228
|
+
| `thread.run-end` | `thread.runEnd` |
|
|
229
|
+
| `thread.model-context-update` | `thread.modelContextUpdate` |
|
|
230
|
+
| `composer.attachment-add` | `composer.attachmentAdd` |
|
|
231
|
+
| `thread-list-item.switched-to` | `threadListItem.switchedTo` |
|
|
232
|
+
| `thread-list-item.switched-away` | `threadListItem.switchedAway` |
|
|
233
|
+
|
|
234
|
+
Events that remain unchanged:
|
|
235
|
+
- `thread.initialize`
|
|
236
|
+
- `composer.send`
|
|
237
|
+
|
|
238
|
+
#### Migration
|
|
239
|
+
|
|
240
|
+
**Before:**
|
|
241
|
+
|
|
242
|
+
```tsx
|
|
243
|
+
import { useAuiEvent } from "@assistant-ui/react";
|
|
244
|
+
|
|
245
|
+
function MyComponent() {
|
|
246
|
+
useAuiEvent("thread.run-start", () => {
|
|
247
|
+
console.log("Thread started running");
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
useAuiEvent("thread.run-end", () => {
|
|
251
|
+
console.log("Thread finished running");
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
useAuiEvent("composer.attachment-add", () => {
|
|
255
|
+
console.log("Attachment added");
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
**After:**
|
|
263
|
+
|
|
264
|
+
```tsx
|
|
265
|
+
import { useAuiEvent } from "@assistant-ui/react";
|
|
266
|
+
|
|
267
|
+
function MyComponent() {
|
|
268
|
+
useAuiEvent("thread.runStart", () => {
|
|
269
|
+
console.log("Thread started running");
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
useAuiEvent("thread.runEnd", () => {
|
|
273
|
+
console.log("Thread finished running");
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
useAuiEvent("composer.attachmentAdd", () => {
|
|
277
|
+
console.log("Attachment added");
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
**Automatic Migration:**
|
|
285
|
+
|
|
286
|
+
Run the codemod to automatically update event names:
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
npx assistant-ui@latest upgrade
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
The codemod will automatically replace all occurrences of the old kebab-case event names with their new camelCase equivalents.
|
|
293
|
+
|
|
120
294
|
## Getting Help
|
|
121
295
|
|
|
122
296
|
If you encounter issues during migration:
|
|
@@ -3,7 +3,6 @@ title: Using old React versions
|
|
|
3
3
|
description: Compatibility notes for React 18, 17, and 16.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
import { InstallCommand } from "@/components/docs/fumadocs/install/install-command";
|
|
7
6
|
|
|
8
7
|
<Callout type="warning" title="Older React Versions">
|
|
9
8
|
Older React versions are not continuously tested. If you encounter any issues
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: AI SDK v5 (Legacy)
|
|
3
|
+
description: Integrate Vercel AI SDK v5 with useChatRuntime for streaming chat.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<Callout type="error">
|
|
7
|
+
AI SDK v5 is no longer supported. The `@assistant-ui/react-ai-sdk` package now requires AI SDK v6+.
|
|
8
|
+
Please upgrade to [AI SDK v6](/docs/runtimes/ai-sdk/v6).
|
|
9
|
+
</Callout>
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
This documentation is preserved for reference. For new projects, use [AI SDK v6](/docs/runtimes/ai-sdk/v6).
|
|
14
|
+
|
|
15
|
+
## Getting Started
|
|
16
|
+
|
|
17
|
+
<Steps>
|
|
18
|
+
<Step>
|
|
19
|
+
### Create a Next.js project
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npx create-next-app@latest my-app
|
|
23
|
+
cd my-app
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
</Step>
|
|
27
|
+
<Step>
|
|
28
|
+
|
|
29
|
+
### Install AI SDK v5 and `@assistant-ui/react`
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npm install @assistant-ui/react @assistant-ui/react-ai-sdk@0.x ai@^5 @ai-sdk/openai@^1 zod
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
</Step>
|
|
36
|
+
<Step>
|
|
37
|
+
|
|
38
|
+
### Setup a backend route under `/api/chat`
|
|
39
|
+
|
|
40
|
+
`@/app/api/chat/route.ts`
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import { openai } from "@ai-sdk/openai";
|
|
44
|
+
import { streamText, tool } from "ai";
|
|
45
|
+
import type { Message } from "ai";
|
|
46
|
+
import { z } from "zod";
|
|
47
|
+
|
|
48
|
+
export const maxDuration = 30;
|
|
49
|
+
|
|
50
|
+
export async function POST(req: Request) {
|
|
51
|
+
const { messages }: { messages: Message[] } = await req.json();
|
|
52
|
+
|
|
53
|
+
const result = streamText({
|
|
54
|
+
model: openai("gpt-4o"),
|
|
55
|
+
messages,
|
|
56
|
+
tools: {
|
|
57
|
+
get_current_weather: tool({
|
|
58
|
+
description: "Get the current weather",
|
|
59
|
+
parameters: z.object({
|
|
60
|
+
city: z.string(),
|
|
61
|
+
}),
|
|
62
|
+
execute: async ({ city }) => {
|
|
63
|
+
return `The weather in ${city} is sunny`;
|
|
64
|
+
},
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return result.toDataStreamResponse();
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
</Step>
|
|
74
|
+
<Step>
|
|
75
|
+
|
|
76
|
+
### Setup the frontend
|
|
77
|
+
|
|
78
|
+
`@/app/page.tsx`
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
"use client";
|
|
82
|
+
|
|
83
|
+
import { Thread } from "@/components/assistant-ui/thread";
|
|
84
|
+
import { AssistantRuntimeProvider } from "@assistant-ui/react";
|
|
85
|
+
import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
|
|
86
|
+
|
|
87
|
+
export default function Home() {
|
|
88
|
+
const runtime = useChatRuntime({
|
|
89
|
+
api: "/api/chat",
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<AssistantRuntimeProvider runtime={runtime}>
|
|
94
|
+
<div className="h-full">
|
|
95
|
+
<Thread />
|
|
96
|
+
</div>
|
|
97
|
+
</AssistantRuntimeProvider>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
</Step>
|
|
103
|
+
</Steps>
|
|
104
|
+
|
|
105
|
+
## Key Differences from v6
|
|
106
|
+
|
|
107
|
+
| Feature | v5 | v6 |
|
|
108
|
+
|---------|----|----|
|
|
109
|
+
| **ai package** | `ai@^5` | `ai@^6` |
|
|
110
|
+
| **@ai-sdk/openai** | `@ai-sdk/openai@^1` | `@ai-sdk/openai@^3` |
|
|
111
|
+
| **Message type** | `Message` | `UIMessage` |
|
|
112
|
+
| **convertToModelMessages** | Sync | Async (`await`) |
|
|
113
|
+
| **Tool schema** | `parameters: z.object({...})` | `inputSchema: zodSchema(z.object({...}))` |
|
|
114
|
+
| **Response** | `toDataStreamResponse()` | `toUIMessageStreamResponse()` |
|
|
115
|
+
|
|
116
|
+
## Migration to v6
|
|
117
|
+
|
|
118
|
+
See the [AI SDK v6 documentation](/docs/runtimes/ai-sdk/v6) for the latest integration guide.
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: AI SDK v6
|
|
3
|
+
description: Integrate Vercel AI SDK v6 with assistant-ui for streaming chat.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
Integration with the Vercel AI SDK v6 using the `useChatRuntime` hook from `@assistant-ui/react-ai-sdk`.
|
|
10
|
+
|
|
11
|
+
## Getting Started
|
|
12
|
+
|
|
13
|
+
<Steps>
|
|
14
|
+
<Step>
|
|
15
|
+
### Create a Next.js project
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npx create-next-app@latest my-app
|
|
19
|
+
cd my-app
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
</Step>
|
|
23
|
+
<Step>
|
|
24
|
+
|
|
25
|
+
### Install dependencies
|
|
26
|
+
|
|
27
|
+
<InstallCommand npm={["@assistant-ui/react", "@assistant-ui/react-ai-sdk", "ai@^6", "@ai-sdk/react@^3", "@ai-sdk/openai", "zod"]} />
|
|
28
|
+
|
|
29
|
+
</Step>
|
|
30
|
+
<Step>
|
|
31
|
+
|
|
32
|
+
### Setup a backend route under `/api/chat`
|
|
33
|
+
|
|
34
|
+
`@/app/api/chat/route.ts`
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import { openai } from "@ai-sdk/openai";
|
|
38
|
+
import {
|
|
39
|
+
streamText,
|
|
40
|
+
convertToModelMessages,
|
|
41
|
+
tool,
|
|
42
|
+
zodSchema,
|
|
43
|
+
} from "ai";
|
|
44
|
+
import type { UIMessage } from "ai";
|
|
45
|
+
import { z } from "zod";
|
|
46
|
+
|
|
47
|
+
export const maxDuration = 30;
|
|
48
|
+
|
|
49
|
+
export async function POST(req: Request) {
|
|
50
|
+
const { messages }: { messages: UIMessage[] } = await req.json();
|
|
51
|
+
|
|
52
|
+
const result = streamText({
|
|
53
|
+
model: openai("gpt-4o"),
|
|
54
|
+
messages: await convertToModelMessages(messages), // Note: async in v6
|
|
55
|
+
tools: {
|
|
56
|
+
get_current_weather: tool({
|
|
57
|
+
description: "Get the current weather",
|
|
58
|
+
inputSchema: zodSchema(
|
|
59
|
+
z.object({
|
|
60
|
+
city: z.string(),
|
|
61
|
+
}),
|
|
62
|
+
),
|
|
63
|
+
execute: async ({ city }) => {
|
|
64
|
+
return `The weather in ${city} is sunny`;
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return result.toUIMessageStreamResponse();
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
</Step>
|
|
75
|
+
<Step>
|
|
76
|
+
|
|
77
|
+
### Setup the frontend
|
|
78
|
+
|
|
79
|
+
`@/app/page.tsx`
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
"use client";
|
|
83
|
+
|
|
84
|
+
import { Thread } from "@/components/assistant-ui/thread";
|
|
85
|
+
import { AssistantRuntimeProvider } from "@assistant-ui/react";
|
|
86
|
+
import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
|
|
87
|
+
|
|
88
|
+
export default function Home() {
|
|
89
|
+
const runtime = useChatRuntime();
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<AssistantRuntimeProvider runtime={runtime}>
|
|
93
|
+
<div className="h-full">
|
|
94
|
+
<Thread />
|
|
95
|
+
</div>
|
|
96
|
+
</AssistantRuntimeProvider>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
</Step>
|
|
102
|
+
</Steps>
|
|
103
|
+
|
|
104
|
+
## Key Changes from v5
|
|
105
|
+
|
|
106
|
+
| Feature | v5 | v6 |
|
|
107
|
+
|---------|----|----|
|
|
108
|
+
| **ai package** | `ai@^5` | `ai@^6` |
|
|
109
|
+
| **@ai-sdk/react** | `@ai-sdk/react@^2` | `@ai-sdk/react@^3` |
|
|
110
|
+
| **convertToModelMessages** | Sync | Async (`await`) |
|
|
111
|
+
| **Tool schema** | `parameters: z.object({...})` | `inputSchema: zodSchema(z.object({...}))` |
|
|
112
|
+
|
|
113
|
+
## API Reference
|
|
114
|
+
|
|
115
|
+
### useChatRuntime
|
|
116
|
+
|
|
117
|
+
Creates a runtime integrated with AI SDK's `useChat` hook.
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
|
|
121
|
+
|
|
122
|
+
const runtime = useChatRuntime({
|
|
123
|
+
api: "/api/chat", // optional, defaults to "/api/chat"
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Custom API URL
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
const runtime = useChatRuntime({
|
|
131
|
+
api: "/my-custom-api/chat",
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Forwarding System Messages and Frontend Tools
|
|
136
|
+
|
|
137
|
+
Use `AssistantChatTransport` to automatically forward system messages and frontend tools to your backend:
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
"use client";
|
|
141
|
+
|
|
142
|
+
import { useChatRuntime, AssistantChatTransport } from "@assistant-ui/react-ai-sdk";
|
|
143
|
+
|
|
144
|
+
const runtime = useChatRuntime({
|
|
145
|
+
transport: new AssistantChatTransport({
|
|
146
|
+
api: "/api/chat",
|
|
147
|
+
}),
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Backend route with system/tools forwarding:
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
import { openai } from "@ai-sdk/openai";
|
|
155
|
+
import { streamText, convertToModelMessages, zodSchema } from "ai";
|
|
156
|
+
import type { UIMessage } from "ai";
|
|
157
|
+
import { frontendTools } from "@assistant-ui/react-ai-sdk";
|
|
158
|
+
|
|
159
|
+
export async function POST(req: Request) {
|
|
160
|
+
const {
|
|
161
|
+
messages,
|
|
162
|
+
system,
|
|
163
|
+
tools,
|
|
164
|
+
}: {
|
|
165
|
+
messages: UIMessage[];
|
|
166
|
+
system?: string;
|
|
167
|
+
tools?: any;
|
|
168
|
+
} = await req.json();
|
|
169
|
+
|
|
170
|
+
const result = streamText({
|
|
171
|
+
model: openai("gpt-4o"),
|
|
172
|
+
system,
|
|
173
|
+
messages: await convertToModelMessages(messages),
|
|
174
|
+
tools: {
|
|
175
|
+
...frontendTools(tools),
|
|
176
|
+
// your backend tools...
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
return result.toUIMessageStreamResponse();
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### useAISDKRuntime (Advanced)
|
|
185
|
+
|
|
186
|
+
For advanced use cases where you need direct access to the `useChat` hook:
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
import { useChat } from "@ai-sdk/react";
|
|
190
|
+
import { useAISDKRuntime } from "@assistant-ui/react-ai-sdk";
|
|
191
|
+
|
|
192
|
+
const chat = useChat();
|
|
193
|
+
const runtime = useAISDKRuntime(chat);
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Example
|
|
197
|
+
|
|
198
|
+
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.
|
|
@@ -503,7 +503,7 @@ To enable resumability, you need to:
|
|
|
503
503
|
2. Use the `unstable_resumeRun` API to resume a conversation
|
|
504
504
|
|
|
505
505
|
```typescript
|
|
506
|
-
import {
|
|
506
|
+
import { useAui } from "@assistant-ui/react";
|
|
507
507
|
|
|
508
508
|
const runtime = useAssistantTransportRuntime({
|
|
509
509
|
// ... other options
|
|
@@ -513,8 +513,8 @@ const runtime = useAssistantTransportRuntime({
|
|
|
513
513
|
});
|
|
514
514
|
|
|
515
515
|
// Typically called on thread switch or mount to check if sync server has anything to resume
|
|
516
|
-
const
|
|
517
|
-
|
|
516
|
+
const aui = useAui();
|
|
517
|
+
aui.thread().unstable_resumeRun({
|
|
518
518
|
parentId: null, // Ignored (will be removed in a future version)
|
|
519
519
|
});
|
|
520
520
|
```
|
|
@@ -3,7 +3,6 @@ title: Custom Thread List
|
|
|
3
3
|
description: Plug a custom thread database for multi-thread persistence.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
import { ParametersTable } from "@/components/docs/tables/ParametersTable";
|
|
7
6
|
|
|
8
7
|
## Overview
|
|
9
8
|
|
|
@@ -222,26 +221,26 @@ When the hook mounts it calls `list()` on your adapter, hydrates existing thread
|
|
|
222
221
|
When implementing a custom history adapter, you must await thread initialization before saving messages. Failing to do so can cause the first message to be lost due to a race condition.
|
|
223
222
|
</Callout>
|
|
224
223
|
|
|
225
|
-
If you're building a history adapter that persists messages to your own database, use `
|
|
224
|
+
If you're building a history adapter that persists messages to your own database, use `aui.threadListItem().initialize()` to ensure the thread is fully initialized before saving:
|
|
226
225
|
|
|
227
226
|
```tsx
|
|
228
|
-
import {
|
|
227
|
+
import { useAui } from "@assistant-ui/react";
|
|
229
228
|
|
|
230
229
|
// Inside your unstable_Provider component
|
|
231
|
-
const
|
|
230
|
+
const aui = useAui();
|
|
232
231
|
|
|
233
232
|
const history = useMemo<ThreadHistoryAdapter>(
|
|
234
233
|
() => ({
|
|
235
234
|
async append(message) {
|
|
236
235
|
// Wait for initialization to complete and get the remoteId
|
|
237
|
-
const { remoteId } = await
|
|
236
|
+
const { remoteId } = await aui.threadListItem().initialize();
|
|
238
237
|
|
|
239
238
|
// Now safe to save the message using the remoteId
|
|
240
239
|
await saveMessageToDatabase(remoteId, message);
|
|
241
240
|
},
|
|
242
241
|
// ...
|
|
243
242
|
}),
|
|
244
|
-
[
|
|
243
|
+
[aui],
|
|
245
244
|
);
|
|
246
245
|
```
|
|
247
246
|
|