@assistant-ui/mcp-docs-server 0.1.20 → 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 +112 -16
- package/.docs/organized/code-examples/with-ai-sdk-v6.md +5 -5
- package/.docs/organized/code-examples/with-assistant-transport.md +3 -3
- package/.docs/organized/code-examples/with-cloud.md +5 -5
- package/.docs/organized/code-examples/with-custom-thread-list.md +5 -5
- package/.docs/organized/code-examples/with-elevenlabs-scribe.md +8 -8
- package/.docs/organized/code-examples/with-external-store.md +4 -4
- package/.docs/organized/code-examples/with-ffmpeg.md +5 -5
- package/.docs/organized/code-examples/with-langgraph.md +3 -3
- package/.docs/organized/code-examples/with-parent-id-grouping.md +4 -4
- package/.docs/organized/code-examples/with-react-hook-form.md +6 -6
- package/.docs/organized/code-examples/with-react-router.md +4 -4
- package/.docs/organized/code-examples/with-store.md +3 -3
- package/.docs/organized/code-examples/with-tanstack.md +6 -6
- package/.docs/organized/code-examples/with-tap-runtime.md +812 -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)/devtools.mdx +0 -1
- package/.docs/raw/docs/(docs)/guides/attachments.mdx +0 -1
- package/.docs/raw/docs/(docs)/installation.mdx +0 -1
- 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 +1 -2
- 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/primitives/action-bar-more.mdx +13 -45
- package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar.mdx +12 -35
- package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-if.mdx +0 -1
- 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 +0 -1
- 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 +0 -1
- 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/markdown.mdx +0 -1
- package/.docs/raw/docs/(reference)/legacy/styled/thread.mdx +0 -1
- 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/custom/custom-thread-list.mdx +0 -1
- package/.docs/raw/docs/runtimes/custom/external-store.mdx +9 -11
- package/.docs/raw/docs/runtimes/custom/local.mdx +0 -2
- package/.docs/raw/docs/runtimes/data-stream.mdx +0 -1
- 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 +0 -2
- 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 +0 -2
- package/.docs/raw/docs/ui/diff-viewer.mdx +279 -0
- package/.docs/raw/docs/ui/file.mdx +0 -1
- package/.docs/raw/docs/ui/image.mdx +0 -1
- 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 +0 -2
- package/.docs/raw/docs/ui/part-grouping.mdx +2 -3
- package/.docs/raw/docs/ui/reasoning.mdx +2 -3
- package/.docs/raw/docs/ui/scrollbar.mdx +26 -9
- package/.docs/raw/docs/ui/select.mdx +0 -2
- package/.docs/raw/docs/ui/sources.mdx +0 -1
- package/.docs/raw/docs/ui/syntax-highlighting.mdx +8 -63
- package/.docs/raw/docs/ui/tabs.mdx +0 -2
- package/.docs/raw/docs/ui/thread-list.mdx +98 -16
- package/.docs/raw/docs/ui/thread.mdx +1 -3
- package/.docs/raw/docs/ui/tool-fallback.mdx +0 -1
- package/.docs/raw/docs/ui/tool-group.mdx +1 -3
- package/package.json +2 -2
- package/.docs/raw/docs/runtimes/ai-sdk/use-chat.mdx +0 -219
|
@@ -3,14 +3,12 @@ title: ThreadList
|
|
|
3
3
|
description: Switch between conversations. Supports sidebar or dropdown layouts.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
import { ParametersTable } from "@/components/docs/tables/ParametersTable";
|
|
7
|
-
import { InstallCommand } from "@/components/docs/fumadocs/install/install-command";
|
|
8
6
|
import { ThreadListSample } from "@/components/docs/samples/threadlist";
|
|
9
7
|
|
|
10
8
|
<ThreadListSample />
|
|
11
9
|
|
|
12
10
|
<Callout>
|
|
13
|
-
This demo uses
|
|
11
|
+
This demo uses `ThreadListSidebar`, which includes `thread-list` as a dependency and provides a complete sidebar layout. For custom implementations, you can use `thread-list` directly.
|
|
14
12
|
</Callout>
|
|
15
13
|
|
|
16
14
|
## Getting Started
|
|
@@ -40,10 +38,10 @@ Use `threadlist-sidebar` for a complete sidebar layout or `thread-list` for cust
|
|
|
40
38
|
```tsx title="/app/assistant.tsx"
|
|
41
39
|
import { Thread } from "@/components/assistant-ui/thread";
|
|
42
40
|
import { ThreadListSidebar } from "@/components/assistant-ui/threadlist-sidebar";
|
|
43
|
-
import {
|
|
44
|
-
SidebarProvider,
|
|
41
|
+
import {
|
|
42
|
+
SidebarProvider,
|
|
45
43
|
SidebarInset,
|
|
46
|
-
SidebarTrigger
|
|
44
|
+
SidebarTrigger
|
|
47
45
|
} from "@/components/ui/sidebar";
|
|
48
46
|
|
|
49
47
|
export default function Assistant() {
|
|
@@ -84,7 +82,7 @@ Use `threadlist-sidebar` for a complete sidebar layout or `thread-list` for cust
|
|
|
84
82
|
|
|
85
83
|
## Anatomy
|
|
86
84
|
|
|
87
|
-
The ThreadList component is built with the following primitives:
|
|
85
|
+
The `ThreadList` component is built with the following primitives:
|
|
88
86
|
|
|
89
87
|
```tsx
|
|
90
88
|
import { ThreadListPrimitive, ThreadListItemPrimitive } from "@assistant-ui/react";
|
|
@@ -242,6 +240,18 @@ A button to archive the thread.
|
|
|
242
240
|
|
|
243
241
|
A button to restore an archived thread.
|
|
244
242
|
|
|
243
|
+
<ParametersTable
|
|
244
|
+
type="ThreadListItemPrimitiveUnarchiveProps"
|
|
245
|
+
parameters={[
|
|
246
|
+
{
|
|
247
|
+
name: "asChild",
|
|
248
|
+
type: "boolean",
|
|
249
|
+
default: "false",
|
|
250
|
+
description: "Merge props with child element instead of rendering a wrapper button.",
|
|
251
|
+
},
|
|
252
|
+
]}
|
|
253
|
+
/>
|
|
254
|
+
|
|
245
255
|
### ThreadListItemPrimitive.Delete
|
|
246
256
|
|
|
247
257
|
A button to permanently delete the thread.
|
|
@@ -258,18 +268,90 @@ A button to permanently delete the thread.
|
|
|
258
268
|
]}
|
|
259
269
|
/>
|
|
260
270
|
|
|
261
|
-
###
|
|
271
|
+
### ThreadListItemMorePrimitive
|
|
262
272
|
|
|
263
|
-
A dropdown menu for additional thread actions, built on Radix UI DropdownMenu
|
|
273
|
+
A dropdown menu for additional thread actions, built on Radix UI DropdownMenu.
|
|
264
274
|
|
|
265
|
-
|
|
266
|
-
- `ThreadListItemMorePrimitive.Trigger` - Button to open the menu
|
|
267
|
-
- `ThreadListItemMorePrimitive.Content` - Menu content container
|
|
268
|
-
- `ThreadListItemMorePrimitive.Item` - Individual menu item
|
|
269
|
-
- `ThreadListItemMorePrimitive.Separator` - Visual separator between items
|
|
275
|
+
#### ThreadListItemMorePrimitive.Root
|
|
270
276
|
|
|
271
|
-
|
|
277
|
+
Menu container that manages dropdown state.
|
|
272
278
|
|
|
273
|
-
|
|
279
|
+
<ParametersTable
|
|
280
|
+
type="ThreadListItemMorePrimitiveRootProps"
|
|
281
|
+
parameters={[
|
|
282
|
+
{
|
|
283
|
+
name: "asChild",
|
|
284
|
+
type: "boolean",
|
|
285
|
+
default: "false",
|
|
286
|
+
description: "Merge props with child element instead of rendering a wrapper div.",
|
|
287
|
+
},
|
|
288
|
+
]}
|
|
289
|
+
/>
|
|
274
290
|
|
|
291
|
+
#### ThreadListItemMorePrimitive.Trigger
|
|
275
292
|
|
|
293
|
+
Button to open the menu.
|
|
294
|
+
|
|
295
|
+
<ParametersTable
|
|
296
|
+
type="ThreadListItemMorePrimitiveTriggerProps"
|
|
297
|
+
parameters={[
|
|
298
|
+
{
|
|
299
|
+
name: "asChild",
|
|
300
|
+
type: "boolean",
|
|
301
|
+
default: "false",
|
|
302
|
+
description: "Merge props with child element instead of rendering a wrapper button.",
|
|
303
|
+
},
|
|
304
|
+
]}
|
|
305
|
+
/>
|
|
306
|
+
|
|
307
|
+
#### ThreadListItemMorePrimitive.Content
|
|
308
|
+
|
|
309
|
+
Menu content container.
|
|
310
|
+
|
|
311
|
+
<ParametersTable
|
|
312
|
+
type="ThreadListItemMorePrimitiveContentProps"
|
|
313
|
+
parameters={[
|
|
314
|
+
{
|
|
315
|
+
name: "asChild",
|
|
316
|
+
type: "boolean",
|
|
317
|
+
default: "false",
|
|
318
|
+
description: "Merge props with child element instead of rendering a wrapper div.",
|
|
319
|
+
},
|
|
320
|
+
]}
|
|
321
|
+
/>
|
|
322
|
+
|
|
323
|
+
#### ThreadListItemMorePrimitive.Item
|
|
324
|
+
|
|
325
|
+
Individual menu item.
|
|
326
|
+
|
|
327
|
+
<ParametersTable
|
|
328
|
+
type="ThreadListItemMorePrimitiveItemProps"
|
|
329
|
+
parameters={[
|
|
330
|
+
{
|
|
331
|
+
name: "asChild",
|
|
332
|
+
type: "boolean",
|
|
333
|
+
default: "false",
|
|
334
|
+
description: "Merge props with child element instead of rendering a wrapper div.",
|
|
335
|
+
},
|
|
336
|
+
]}
|
|
337
|
+
/>
|
|
338
|
+
|
|
339
|
+
#### ThreadListItemMorePrimitive.Separator
|
|
340
|
+
|
|
341
|
+
Visual separator between items.
|
|
342
|
+
|
|
343
|
+
<ParametersTable
|
|
344
|
+
type="ThreadListItemMorePrimitiveSeparatorProps"
|
|
345
|
+
parameters={[
|
|
346
|
+
{
|
|
347
|
+
name: "asChild",
|
|
348
|
+
type: "boolean",
|
|
349
|
+
default: "false",
|
|
350
|
+
description: "Merge props with child element instead of rendering a wrapper div.",
|
|
351
|
+
},
|
|
352
|
+
]}
|
|
353
|
+
/>
|
|
354
|
+
|
|
355
|
+
## Related Components
|
|
356
|
+
|
|
357
|
+
- [Thread](/docs/ui/thread) - The main chat interface displayed alongside the list
|
|
@@ -3,8 +3,6 @@ title: Thread
|
|
|
3
3
|
description: The main chat container with messages, composer, and auto-scroll.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
import { ParametersTable } from "@/components/docs/tables/ParametersTable";
|
|
7
|
-
import { InstallCommand } from "@/components/docs/fumadocs/install/install-command";
|
|
8
6
|
import { ThreadSample } from "@/components/docs/samples/thread";
|
|
9
7
|
|
|
10
8
|
A complete chat interface that combines message rendering, auto-scrolling, composer input,
|
|
@@ -15,7 +13,7 @@ attachments, and conditional UI states. Fully customizable and composable.
|
|
|
15
13
|
|
|
16
14
|
## Anatomy
|
|
17
15
|
|
|
18
|
-
The Thread component is built with the following primitives:
|
|
16
|
+
The `Thread` component is built with the following primitives:
|
|
19
17
|
|
|
20
18
|
```tsx
|
|
21
19
|
import { ThreadPrimitive, AuiIf } from "@assistant-ui/react";
|
|
@@ -3,8 +3,6 @@ title: ToolGroup
|
|
|
3
3
|
description: Wrapper for consecutive tool calls with collapsible and styled options.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
import { InstallCommand } from "@/components/docs/fumadocs/install/install-command";
|
|
7
|
-
import { ParametersTable } from "@/components/docs/tables/ParametersTable";
|
|
8
6
|
import {
|
|
9
7
|
ToolGroupSample,
|
|
10
8
|
ToolGroupStreamingSample,
|
|
@@ -70,7 +68,7 @@ Use the `variant` prop on `ToolGroup.Root` to change the visual style:
|
|
|
70
68
|
|
|
71
69
|
### Streaming Demo (Custom UI + Fallback)
|
|
72
70
|
|
|
73
|
-
Interactive demo showing tool group with **custom tool UIs** and
|
|
71
|
+
Interactive demo showing tool group with **custom tool UIs** and `ToolFallback` working together. Watch as weather cards stream in with loading states, followed by a search tool using the fallback UI.
|
|
74
72
|
|
|
75
73
|
<ToolGroupStreamingSample />
|
|
76
74
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/mcp-docs-server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "MCP server for assistant-ui documentation and examples",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"zod": "^4.3.6"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@types/node": "^25.0
|
|
41
|
+
"@types/node": "^25.2.0",
|
|
42
42
|
"tsx": "^4.21.0",
|
|
43
43
|
"vitest": "^4.0.18",
|
|
44
44
|
"@assistant-ui/x-buildutils": "0.0.1"
|
|
@@ -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.
|