@assistant-ui/mcp-docs-server 0.1.25 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/code-examples/waterfall.md +4 -4
- package/.docs/organized/code-examples/with-a2a.md +5 -5
- package/.docs/organized/code-examples/with-ag-ui.md +6 -6
- package/.docs/organized/code-examples/with-ai-sdk-v6.md +7 -7
- package/.docs/organized/code-examples/with-artifacts.md +7 -7
- package/.docs/organized/code-examples/with-assistant-transport.md +5 -5
- package/.docs/organized/code-examples/with-chain-of-thought.md +7 -7
- package/.docs/organized/code-examples/with-cloud-standalone.md +8 -8
- package/.docs/organized/code-examples/with-cloud.md +7 -7
- package/.docs/organized/code-examples/with-custom-thread-list.md +7 -7
- package/.docs/organized/code-examples/with-elevenlabs-scribe.md +10 -10
- package/.docs/organized/code-examples/with-expo.md +14 -14
- package/.docs/organized/code-examples/with-external-store.md +5 -5
- package/.docs/organized/code-examples/with-ffmpeg.md +7 -7
- package/.docs/organized/code-examples/with-google-adk.md +5 -5
- package/.docs/organized/code-examples/with-heat-graph.md +4 -4
- package/.docs/organized/code-examples/with-interactables.md +778 -0
- package/.docs/organized/code-examples/with-langgraph.md +6 -6
- package/.docs/organized/code-examples/with-parent-id-grouping.md +6 -6
- package/.docs/organized/code-examples/with-react-hook-form.md +8 -8
- package/.docs/organized/code-examples/with-react-ink.md +2 -2
- package/.docs/organized/code-examples/with-react-router.md +10 -10
- package/.docs/organized/code-examples/with-store.md +5 -5
- package/.docs/organized/code-examples/with-tanstack.md +8 -8
- package/.docs/organized/code-examples/with-tap-runtime.md +8 -8
- package/.docs/raw/blog/2026-03-launch-week/index.mdx +31 -0
- package/.docs/raw/docs/(docs)/cli.mdx +60 -0
- package/.docs/raw/docs/(docs)/guides/attachments.mdx +65 -4
- package/.docs/raw/docs/(docs)/guides/interactables.mdx +292 -0
- package/.docs/raw/docs/(docs)/guides/message-timing.mdx +3 -3
- package/.docs/raw/docs/(docs)/guides/multi-agent.mdx +1 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/composer.mdx +128 -0
- package/.docs/raw/docs/cloud/ai-sdk-assistant-ui.mdx +6 -0
- package/.docs/raw/docs/cloud/ai-sdk.mdx +81 -1
- package/.docs/raw/docs/ink/primitives.mdx +141 -0
- package/.docs/raw/docs/primitives/action-bar.mdx +351 -0
- package/.docs/raw/docs/primitives/assistant-modal.mdx +215 -0
- package/.docs/raw/docs/primitives/attachment.mdx +216 -0
- package/.docs/raw/docs/primitives/branch-picker.mdx +221 -0
- package/.docs/raw/docs/primitives/chain-of-thought.mdx +311 -0
- package/.docs/raw/docs/primitives/composer.mdx +526 -0
- package/.docs/raw/docs/primitives/error.mdx +141 -0
- package/.docs/raw/docs/primitives/index.mdx +98 -0
- package/.docs/raw/docs/primitives/message.mdx +524 -0
- package/.docs/raw/docs/primitives/selection-toolbar.mdx +165 -0
- package/.docs/raw/docs/primitives/suggestion.mdx +242 -0
- package/.docs/raw/docs/primitives/thread-list.mdx +404 -0
- package/.docs/raw/docs/primitives/thread.mdx +482 -0
- package/.docs/raw/docs/ui/mention.mdx +168 -0
- package/package.json +3 -3
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Thread
|
|
3
|
+
description: Build custom scrollable message containers with auto-scroll, empty states, and message rendering.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { ThreadPrimitiveSample } from "@/components/docs/samples/thread-primitive";
|
|
7
|
+
import { ThreadPrimitive as ThreadPrimitiveDocs } from "@/generated/primitiveDocs";
|
|
8
|
+
|
|
9
|
+
The Thread primitive is the scrollable message container, and the backbone of any chat interface. It handles viewport management, auto-scrolling, empty states, message rendering, and suggestions. You provide the layout and styling.
|
|
10
|
+
|
|
11
|
+
<Tabs items={["Preview", "Code"]}>
|
|
12
|
+
<Tab>
|
|
13
|
+
<ThreadPrimitiveSample />
|
|
14
|
+
</Tab>
|
|
15
|
+
<Tab>
|
|
16
|
+
```tsx
|
|
17
|
+
import {
|
|
18
|
+
AuiIf,
|
|
19
|
+
ComposerPrimitive,
|
|
20
|
+
ThreadPrimitive,
|
|
21
|
+
MessagePrimitive,
|
|
22
|
+
} from "@assistant-ui/react";
|
|
23
|
+
import { ArrowUpIcon } from "lucide-react";
|
|
24
|
+
|
|
25
|
+
function MinimalThread() {
|
|
26
|
+
return (
|
|
27
|
+
<ThreadPrimitive.Root className="flex h-full flex-col">
|
|
28
|
+
<ThreadPrimitive.Viewport className="flex flex-1 flex-col gap-3 overflow-y-auto p-3">
|
|
29
|
+
<AuiIf condition={(s) => s.thread.isEmpty}>
|
|
30
|
+
<p>Welcome! Ask a question to get started.</p>
|
|
31
|
+
</AuiIf>
|
|
32
|
+
|
|
33
|
+
<ThreadPrimitive.Messages>
|
|
34
|
+
{({ message }) => {
|
|
35
|
+
if (message.role === "user") return <UserMessage />;
|
|
36
|
+
return <AssistantMessage />;
|
|
37
|
+
}}
|
|
38
|
+
</ThreadPrimitive.Messages>
|
|
39
|
+
|
|
40
|
+
<ThreadPrimitive.ViewportFooter className="sticky bottom-0 pt-2">
|
|
41
|
+
<ComposerPrimitive.Root className="flex w-full flex-col rounded-3xl border bg-muted">
|
|
42
|
+
<ComposerPrimitive.Input
|
|
43
|
+
placeholder="Ask anything..."
|
|
44
|
+
className="min-h-10 w-full resize-none bg-transparent px-5 pt-3.5 pb-2.5 text-sm focus:outline-none"
|
|
45
|
+
rows={1}
|
|
46
|
+
/>
|
|
47
|
+
<div className="flex items-center justify-end px-2.5 pb-2.5">
|
|
48
|
+
<ComposerPrimitive.Send className="flex size-8 items-center justify-center rounded-full bg-primary text-primary-foreground disabled:opacity-30">
|
|
49
|
+
<ArrowUpIcon className="size-4" />
|
|
50
|
+
</ComposerPrimitive.Send>
|
|
51
|
+
</div>
|
|
52
|
+
</ComposerPrimitive.Root>
|
|
53
|
+
</ThreadPrimitive.ViewportFooter>
|
|
54
|
+
</ThreadPrimitive.Viewport>
|
|
55
|
+
</ThreadPrimitive.Root>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function UserMessage() {
|
|
60
|
+
return (
|
|
61
|
+
<MessagePrimitive.Root className="flex justify-end">
|
|
62
|
+
<div className="max-w-[80%] rounded-2xl bg-primary px-4 py-2.5 text-sm text-primary-foreground">
|
|
63
|
+
<MessagePrimitive.Parts />
|
|
64
|
+
</div>
|
|
65
|
+
</MessagePrimitive.Root>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function AssistantMessage() {
|
|
70
|
+
return (
|
|
71
|
+
<MessagePrimitive.Root className="flex justify-start">
|
|
72
|
+
<div className="max-w-[80%] rounded-2xl bg-muted px-4 py-2.5 text-sm">
|
|
73
|
+
<MessagePrimitive.Parts />
|
|
74
|
+
</div>
|
|
75
|
+
</MessagePrimitive.Root>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
</Tab>
|
|
80
|
+
</Tabs>
|
|
81
|
+
|
|
82
|
+
## Quick Start
|
|
83
|
+
|
|
84
|
+
Minimal example:
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
import { ThreadPrimitive } from "@assistant-ui/react";
|
|
88
|
+
|
|
89
|
+
<ThreadPrimitive.Root>
|
|
90
|
+
<ThreadPrimitive.Viewport>
|
|
91
|
+
<ThreadPrimitive.Messages>
|
|
92
|
+
{() => <MyMessage />}
|
|
93
|
+
</ThreadPrimitive.Messages>
|
|
94
|
+
</ThreadPrimitive.Viewport>
|
|
95
|
+
</ThreadPrimitive.Root>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`Root` renders a `<div>`, `Viewport` renders a scrollable `<div>`, and `Messages` iterates over the thread's messages. Add your own styles and components; the primitive handles the rest.
|
|
99
|
+
|
|
100
|
+
<Callout type="info">
|
|
101
|
+
Runtime setup: primitives require runtime context. Wrap your UI in `AssistantRuntimeProvider` with a runtime (for example `useLocalRuntime(...)`). See [Pick a Runtime](/docs/runtimes/pick-a-runtime).
|
|
102
|
+
</Callout>
|
|
103
|
+
|
|
104
|
+
## Core Concepts
|
|
105
|
+
|
|
106
|
+
### Viewport & Auto-Scroll
|
|
107
|
+
|
|
108
|
+
`Viewport` is the scrollable container. It auto-scrolls to the bottom as new content streams in, but only if the user hasn't scrolled up manually. Set `autoScroll={false}` to disable this entirely.
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
<ThreadPrimitive.Viewport autoScroll={true}>
|
|
112
|
+
{/* messages */}
|
|
113
|
+
</ThreadPrimitive.Viewport>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Turn Anchor
|
|
117
|
+
|
|
118
|
+
By default, new messages appear at the bottom and scroll down. With `turnAnchor="top"`, the user's message anchors to the top of the viewport. This creates the modern reading experience where you see the question at the top and the response flowing below it.
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
<ThreadPrimitive.Viewport turnAnchor="top">
|
|
122
|
+
{/* messages */}
|
|
123
|
+
</ThreadPrimitive.Viewport>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
This is what the shadcn Thread component uses by default. For scroll anchoring to work correctly, `ViewportSlack` is needed on the last assistant message to provide enough min-height for the user message to anchor at the top. This is included automatically in the shadcn component.
|
|
127
|
+
|
|
128
|
+
### Viewport Scroll Options
|
|
129
|
+
|
|
130
|
+
`ThreadPrimitive.Viewport` has three event-specific scroll controls:
|
|
131
|
+
|
|
132
|
+
- `scrollToBottomOnRunStart` (default `true`): scrolls when `thread.runStart` fires
|
|
133
|
+
- `scrollToBottomOnInitialize` (default `true`): scrolls when `thread.initialize` fires
|
|
134
|
+
- `scrollToBottomOnThreadSwitch` (default `true`): scrolls when `threadListItem.switchedTo` fires
|
|
135
|
+
|
|
136
|
+
These work alongside `autoScroll`. If `autoScroll` is omitted, it defaults to `true` for `turnAnchor="bottom"` and `false` for `turnAnchor="top"`.
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
<ThreadPrimitive.Viewport
|
|
140
|
+
turnAnchor="top"
|
|
141
|
+
autoScroll={false}
|
|
142
|
+
scrollToBottomOnRunStart={true}
|
|
143
|
+
scrollToBottomOnInitialize={false}
|
|
144
|
+
scrollToBottomOnThreadSwitch={true}
|
|
145
|
+
>
|
|
146
|
+
<ThreadPrimitive.Messages>
|
|
147
|
+
{({ message }) => {
|
|
148
|
+
if (message.role === "user") return <UserMessage />;
|
|
149
|
+
return <AssistantMessage />;
|
|
150
|
+
}}
|
|
151
|
+
</ThreadPrimitive.Messages>
|
|
152
|
+
</ThreadPrimitive.Viewport>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### ViewportFooter
|
|
156
|
+
|
|
157
|
+
`ViewportFooter` sticks to the bottom of the viewport and registers its height so the auto-scroll system accounts for it. This is where you place your composer:
|
|
158
|
+
|
|
159
|
+
```tsx
|
|
160
|
+
<ThreadPrimitive.Viewport>
|
|
161
|
+
<ThreadPrimitive.Messages>
|
|
162
|
+
{() => <MyMessage />}
|
|
163
|
+
</ThreadPrimitive.Messages>
|
|
164
|
+
<ThreadPrimitive.ViewportFooter className="sticky bottom-0">
|
|
165
|
+
<MyComposer />
|
|
166
|
+
</ThreadPrimitive.ViewportFooter>
|
|
167
|
+
</ThreadPrimitive.Viewport>
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Empty State
|
|
171
|
+
|
|
172
|
+
<Callout type="warn">
|
|
173
|
+
`ThreadPrimitive.Empty` is deprecated. Use [`AuiIf`](/docs/api-reference/primitives/assistant-if) instead.
|
|
174
|
+
</Callout>
|
|
175
|
+
|
|
176
|
+
```tsx
|
|
177
|
+
<AuiIf condition={(s) => s.thread.isEmpty}>
|
|
178
|
+
<div className="flex flex-col items-center gap-2 text-center">
|
|
179
|
+
<h2>Welcome!</h2>
|
|
180
|
+
<p>How can I help you today?</p>
|
|
181
|
+
</div>
|
|
182
|
+
</AuiIf>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Messages Iterator
|
|
186
|
+
|
|
187
|
+
`Messages` now prefers a children render function. It gives you the current message state so you can branch inline:
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
<ThreadPrimitive.Messages>
|
|
191
|
+
{({ message }) => {
|
|
192
|
+
if (message.composer.isEditing) return <MyEditComposer />;
|
|
193
|
+
if (message.role === "user") return <MyUserMessage />;
|
|
194
|
+
return <MyAssistantMessage />;
|
|
195
|
+
}}
|
|
196
|
+
</ThreadPrimitive.Messages>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
`components` is deprecated. Use the `children` render function instead.
|
|
200
|
+
|
|
201
|
+
### Suggestions Iterator
|
|
202
|
+
|
|
203
|
+
`Suggestions` follows the same pattern. Prefer the children render function when rendering custom suggestion UIs:
|
|
204
|
+
|
|
205
|
+
```tsx
|
|
206
|
+
<ThreadPrimitive.Suggestions>
|
|
207
|
+
{() => <MySuggestionButton />}
|
|
208
|
+
</ThreadPrimitive.Suggestions>
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Parts
|
|
212
|
+
|
|
213
|
+
### Root
|
|
214
|
+
|
|
215
|
+
Top-level container for a thread layout. Renders a `<div>` element unless `asChild` is set.
|
|
216
|
+
|
|
217
|
+
```tsx
|
|
218
|
+
<ThreadPrimitive.Root className="flex h-full flex-col">
|
|
219
|
+
<ThreadPrimitive.Viewport>
|
|
220
|
+
<ThreadPrimitive.Messages>
|
|
221
|
+
{() => <MyMessage />}
|
|
222
|
+
</ThreadPrimitive.Messages>
|
|
223
|
+
</ThreadPrimitive.Viewport>
|
|
224
|
+
</ThreadPrimitive.Root>
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Viewport
|
|
228
|
+
|
|
229
|
+
The scrollable area with auto-scroll behavior. Renders a `<div>` element unless `asChild` is set.
|
|
230
|
+
|
|
231
|
+
```tsx
|
|
232
|
+
<ThreadPrimitive.Viewport
|
|
233
|
+
turnAnchor="top"
|
|
234
|
+
autoScroll={false}
|
|
235
|
+
scrollToBottomOnRunStart={true}
|
|
236
|
+
>
|
|
237
|
+
<ThreadPrimitive.Messages>
|
|
238
|
+
{({ message }) => {
|
|
239
|
+
if (message.role === "user") return <UserMessage />;
|
|
240
|
+
return <AssistantMessage />;
|
|
241
|
+
}}
|
|
242
|
+
</ThreadPrimitive.Messages>
|
|
243
|
+
</ThreadPrimitive.Viewport>
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
<PrimitivesTypeTable type="ThreadPrimitiveViewportProps" parameters={ThreadPrimitiveDocs.Viewport.props.filter(p => p.name !== "asChild")} />
|
|
247
|
+
|
|
248
|
+
### ViewportFooter
|
|
249
|
+
|
|
250
|
+
Footer container that registers its height with the viewport scroll system. Renders a `<div>` element unless `asChild` is set.
|
|
251
|
+
|
|
252
|
+
```tsx
|
|
253
|
+
<ThreadPrimitive.ViewportFooter className="sticky bottom-0 pt-2">
|
|
254
|
+
<ComposerPrimitive.Root>...</ComposerPrimitive.Root>
|
|
255
|
+
</ThreadPrimitive.ViewportFooter>
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### ViewportProvider
|
|
259
|
+
|
|
260
|
+
Provides viewport context without rendering a scrollable element. Use this when you have a custom scroll container.
|
|
261
|
+
|
|
262
|
+
```tsx
|
|
263
|
+
<ThreadPrimitive.ViewportProvider>
|
|
264
|
+
<div className="flex-1 overflow-y-auto">
|
|
265
|
+
<ThreadPrimitive.Messages>
|
|
266
|
+
{() => <MyMessage />}
|
|
267
|
+
</ThreadPrimitive.Messages>
|
|
268
|
+
<ThreadPrimitive.ViewportFooter>
|
|
269
|
+
<MyComposer />
|
|
270
|
+
</ThreadPrimitive.ViewportFooter>
|
|
271
|
+
</div>
|
|
272
|
+
</ThreadPrimitive.ViewportProvider>
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### ViewportSlack
|
|
276
|
+
|
|
277
|
+
Adds min-height for scroll anchoring with `turnAnchor="top"`. It wraps its child element via `Slot` and does not render a DOM element of its own.
|
|
278
|
+
|
|
279
|
+
```tsx
|
|
280
|
+
<MessagePrimitive.Root>
|
|
281
|
+
<MessagePrimitive.Parts />
|
|
282
|
+
<ThreadPrimitive.ViewportSlack>
|
|
283
|
+
<div className="min-h-[40vh]" />
|
|
284
|
+
</ThreadPrimitive.ViewportSlack>
|
|
285
|
+
</MessagePrimitive.Root>
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Props: `fillClampThreshold` and `fillClampOffset` control how the slack height is calculated. `children` is required.
|
|
289
|
+
|
|
290
|
+
### Messages
|
|
291
|
+
|
|
292
|
+
Renders a component for each message in the thread, resolved by role and edit state.
|
|
293
|
+
|
|
294
|
+
```tsx
|
|
295
|
+
<ThreadPrimitive.Messages>
|
|
296
|
+
{({ message }) => {
|
|
297
|
+
if (message.composer.isEditing) return <MyEditComposer />;
|
|
298
|
+
if (message.role === "user") return <MyUserMessage />;
|
|
299
|
+
return <MyAssistantMessage />;
|
|
300
|
+
}}
|
|
301
|
+
</ThreadPrimitive.Messages>
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
<PrimitivesTypeTable type="ThreadPrimitiveMessagesProps" parameters={ThreadPrimitiveDocs.Messages.props} />
|
|
305
|
+
|
|
306
|
+
### MessageByIndex
|
|
307
|
+
|
|
308
|
+
Renders a single message at a specific index in the thread.
|
|
309
|
+
|
|
310
|
+
```tsx
|
|
311
|
+
<ThreadPrimitive.MessageByIndex
|
|
312
|
+
index={0}
|
|
313
|
+
components={{ Message: MyMessage }}
|
|
314
|
+
/>
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
<PrimitivesTypeTable type="ThreadPrimitiveMessageByIndexProps" parameters={ThreadPrimitiveDocs.MessageByIndex.props} />
|
|
318
|
+
|
|
319
|
+
### ScrollToBottom
|
|
320
|
+
|
|
321
|
+
Scrolls the viewport to the bottom. Automatically disabled when already at the bottom. Renders a `<button>` element unless `asChild` is set.
|
|
322
|
+
|
|
323
|
+
```tsx
|
|
324
|
+
<ThreadPrimitive.ScrollToBottom className="rounded-full bg-background p-2 shadow-md">
|
|
325
|
+
<ArrowDownIcon />
|
|
326
|
+
</ThreadPrimitive.ScrollToBottom>
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
<PrimitivesTypeTable type="ThreadPrimitiveScrollToBottomProps" parameters={ThreadPrimitiveDocs.ScrollToBottom.props.filter(p => p.name !== "asChild")} />
|
|
330
|
+
|
|
331
|
+
### Suggestions
|
|
332
|
+
|
|
333
|
+
Renders suggestion prompts via a component.
|
|
334
|
+
|
|
335
|
+
```tsx
|
|
336
|
+
<ThreadPrimitive.Suggestions>
|
|
337
|
+
{({ suggestion }) => <MySuggestionButton prompt={suggestion.prompt} />}
|
|
338
|
+
</ThreadPrimitive.Suggestions>
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
<PrimitivesTypeTable type="ThreadPrimitiveSuggestionsProps" parameters={ThreadPrimitiveDocs.Suggestions.props} />
|
|
342
|
+
|
|
343
|
+
### SuggestionByIndex
|
|
344
|
+
|
|
345
|
+
Renders a single suggestion at a specific index.
|
|
346
|
+
|
|
347
|
+
```tsx
|
|
348
|
+
<ThreadPrimitive.SuggestionByIndex
|
|
349
|
+
index={0}
|
|
350
|
+
components={{ Suggestion: MySuggestion }}
|
|
351
|
+
/>
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
<PrimitivesTypeTable type="ThreadPrimitiveSuggestionByIndexProps" parameters={ThreadPrimitiveDocs.SuggestionByIndex.props} />
|
|
355
|
+
|
|
356
|
+
### Suggestion
|
|
357
|
+
|
|
358
|
+
Self-contained suggestion button. Renders a `<button>` element unless `asChild` is set. *(Legacy -- prefer `Suggestions` iterator.)*
|
|
359
|
+
|
|
360
|
+
```tsx
|
|
361
|
+
<ThreadPrimitive.Suggestion prompt="Write a blog post" send />
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
<PrimitivesTypeTable type="ThreadPrimitiveSuggestionProps" parameters={ThreadPrimitiveDocs.Suggestion.props.filter(p => p.name !== "asChild")} />
|
|
365
|
+
|
|
366
|
+
### Empty
|
|
367
|
+
|
|
368
|
+
<Callout type="warn">
|
|
369
|
+
Deprecated. Use [`AuiIf`](/docs/api-reference/primitives/assistant-if) with `s.thread.isEmpty` instead.
|
|
370
|
+
</Callout>
|
|
371
|
+
|
|
372
|
+
Legacy helper that only renders its children when the thread is empty.
|
|
373
|
+
|
|
374
|
+
```tsx
|
|
375
|
+
<ThreadPrimitive.Empty>
|
|
376
|
+
<div className="text-center text-muted-foreground">
|
|
377
|
+
No messages yet.
|
|
378
|
+
</div>
|
|
379
|
+
</ThreadPrimitive.Empty>
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### If (deprecated)
|
|
383
|
+
|
|
384
|
+
<Callout type="warn">
|
|
385
|
+
Deprecated. Use [`AuiIf`](/docs/api-reference/primitives/assistant-if) instead.
|
|
386
|
+
</Callout>
|
|
387
|
+
|
|
388
|
+
```tsx
|
|
389
|
+
// Before (deprecated)
|
|
390
|
+
<ThreadPrimitive.If empty>...</ThreadPrimitive.If>
|
|
391
|
+
<ThreadPrimitive.If running>...</ThreadPrimitive.If>
|
|
392
|
+
<ThreadPrimitive.If disabled>...</ThreadPrimitive.If>
|
|
393
|
+
|
|
394
|
+
// After
|
|
395
|
+
<AuiIf condition={(s) => s.thread.isEmpty}>...</AuiIf>
|
|
396
|
+
<AuiIf condition={(s) => s.thread.isRunning}>...</AuiIf>
|
|
397
|
+
<AuiIf condition={(s) => s.thread.isDisabled}>...</AuiIf>
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
## Patterns
|
|
401
|
+
|
|
402
|
+
### Welcome Screen with Suggestions
|
|
403
|
+
|
|
404
|
+
```tsx
|
|
405
|
+
<AuiIf condition={(s) => s.thread.isEmpty}>
|
|
406
|
+
<div className="flex flex-col items-center gap-4 text-center">
|
|
407
|
+
<h2>What can I help with?</h2>
|
|
408
|
+
<div className="grid grid-cols-2 gap-2">
|
|
409
|
+
<ThreadPrimitive.Suggestions>
|
|
410
|
+
{() => <MySuggestionButton />}
|
|
411
|
+
</ThreadPrimitive.Suggestions>
|
|
412
|
+
</div>
|
|
413
|
+
</div>
|
|
414
|
+
</AuiIf>
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
### Scroll-to-Bottom Button
|
|
418
|
+
|
|
419
|
+
```tsx
|
|
420
|
+
<ThreadPrimitive.ScrollToBottom className="fixed bottom-24 right-4 rounded-full bg-background p-2 shadow-md">
|
|
421
|
+
<ArrowDownIcon />
|
|
422
|
+
</ThreadPrimitive.ScrollToBottom>
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
The button is automatically disabled when the viewport is already scrolled to the bottom.
|
|
426
|
+
|
|
427
|
+
### Turn Anchor Top Layout
|
|
428
|
+
|
|
429
|
+
```tsx
|
|
430
|
+
<ThreadPrimitive.Root className="flex h-full flex-col">
|
|
431
|
+
<ThreadPrimitive.Viewport turnAnchor="top" className="flex-1 overflow-y-auto">
|
|
432
|
+
<ThreadPrimitive.Messages>
|
|
433
|
+
{({ message }) => {
|
|
434
|
+
if (message.role === "user") return <UserMessage />;
|
|
435
|
+
return <AssistantMessage />;
|
|
436
|
+
}}
|
|
437
|
+
</ThreadPrimitive.Messages>
|
|
438
|
+
<ThreadPrimitive.ViewportFooter className="sticky bottom-0">
|
|
439
|
+
<MyComposer />
|
|
440
|
+
</ThreadPrimitive.ViewportFooter>
|
|
441
|
+
</ThreadPrimitive.Viewport>
|
|
442
|
+
</ThreadPrimitive.Root>
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### Custom Message Components
|
|
446
|
+
|
|
447
|
+
```tsx
|
|
448
|
+
<ThreadPrimitive.Messages>
|
|
449
|
+
{({ message }) => {
|
|
450
|
+
if (message.role === "user") {
|
|
451
|
+
return (
|
|
452
|
+
<MessagePrimitive.Root>
|
|
453
|
+
<div className="ml-auto rounded-xl bg-blue-500 p-3 text-white">
|
|
454
|
+
<MessagePrimitive.Parts />
|
|
455
|
+
</div>
|
|
456
|
+
</MessagePrimitive.Root>
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
return (
|
|
461
|
+
<MessagePrimitive.Root>
|
|
462
|
+
<div className="rounded-xl bg-gray-100 p-3">
|
|
463
|
+
<MessagePrimitive.Parts />
|
|
464
|
+
</div>
|
|
465
|
+
</MessagePrimitive.Root>
|
|
466
|
+
);
|
|
467
|
+
}}
|
|
468
|
+
</ThreadPrimitive.Messages>
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
## Relationship to Components
|
|
472
|
+
|
|
473
|
+
The [Thread](/docs/ui/thread) component is a full chat interface built from these primitives with Tailwind styling. Start there for a default implementation. Reach for `ThreadPrimitive` when you need a custom layout, different scroll behavior, or a non-standard thread structure.
|
|
474
|
+
|
|
475
|
+
## API Reference
|
|
476
|
+
|
|
477
|
+
For full prop details on every part, see the [ThreadPrimitive API Reference](/docs/api-reference/primitives/thread).
|
|
478
|
+
|
|
479
|
+
Related:
|
|
480
|
+
- [MessagePrimitive API Reference](/docs/api-reference/primitives/message)
|
|
481
|
+
- [ComposerPrimitive API Reference](/docs/api-reference/primitives/composer)
|
|
482
|
+
- [ThreadListPrimitive API Reference](/docs/api-reference/primitives/thread-list)
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Mention
|
|
3
|
+
description: Let users @-mention tools in the composer with a keyboard-navigable popover picker and inline chips.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Getting Started
|
|
7
|
+
|
|
8
|
+
<Steps>
|
|
9
|
+
<Step>
|
|
10
|
+
|
|
11
|
+
### Add `composer-mention`
|
|
12
|
+
|
|
13
|
+
<InstallCommand shadcn={["composer-mention"]} />
|
|
14
|
+
|
|
15
|
+
This adds a `/components/assistant-ui/composer-mention.tsx` file with `ComposerMentionPopover`, `ComposerMentionRoot`, and `DirectiveText`.
|
|
16
|
+
|
|
17
|
+
</Step>
|
|
18
|
+
<Step>
|
|
19
|
+
|
|
20
|
+
### Wrap the Composer
|
|
21
|
+
|
|
22
|
+
Wrap your composer with `ComposerMentionPopover.Root` and add `<ComposerMentionPopover />` inside:
|
|
23
|
+
|
|
24
|
+
```tsx title="components/assistant-ui/thread.tsx" {1,7,10}
|
|
25
|
+
import { ComposerMentionPopover } from "@/components/assistant-ui/composer-mention";
|
|
26
|
+
|
|
27
|
+
const Composer = () => {
|
|
28
|
+
return (
|
|
29
|
+
<ComposerMentionPopover.Root>
|
|
30
|
+
<ComposerPrimitive.Root>
|
|
31
|
+
<ComposerPrimitive.Input placeholder="Type @ to mention a tool..." />
|
|
32
|
+
<ComposerPrimitive.Send />
|
|
33
|
+
<ComposerMentionPopover />
|
|
34
|
+
</ComposerPrimitive.Root>
|
|
35
|
+
</ComposerMentionPopover.Root>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The popover automatically shows registered tools when the user types `@`.
|
|
41
|
+
|
|
42
|
+
</Step>
|
|
43
|
+
<Step>
|
|
44
|
+
|
|
45
|
+
### Render Mentions in User Messages
|
|
46
|
+
|
|
47
|
+
Use `DirectiveText` as the `Text` component for **user messages** so mention directives render as inline chips instead of raw `:tool[label]` syntax:
|
|
48
|
+
|
|
49
|
+
```tsx title="components/assistant-ui/thread.tsx" {1,8}
|
|
50
|
+
import { DirectiveText } from "@/components/assistant-ui/composer-mention";
|
|
51
|
+
|
|
52
|
+
const UserMessage = () => {
|
|
53
|
+
return (
|
|
54
|
+
<MessagePrimitive.Root>
|
|
55
|
+
<MessagePrimitive.Parts
|
|
56
|
+
components={{
|
|
57
|
+
Text: DirectiveText,
|
|
58
|
+
}}
|
|
59
|
+
/>
|
|
60
|
+
</MessagePrimitive.Root>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
<Callout>
|
|
66
|
+
`DirectiveText` renders plain text with mention chips. For assistant messages
|
|
67
|
+
that contain markdown, keep using your markdown renderer (e.g. `MarkdownText`).
|
|
68
|
+
</Callout>
|
|
69
|
+
|
|
70
|
+
</Step>
|
|
71
|
+
</Steps>
|
|
72
|
+
|
|
73
|
+
## With Lexical Rich Editor
|
|
74
|
+
|
|
75
|
+
For inline mention chips in the composer (not just the popover), use `LexicalComposerInput` from `@assistant-ui/react-lexical`:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm install @assistant-ui/react-lexical lexical @lexical/react
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Replace `ComposerPrimitive.Input` with `LexicalComposerInput`:
|
|
82
|
+
|
|
83
|
+
```tsx title="components/assistant-ui/thread.tsx" {1,8}
|
|
84
|
+
import { LexicalComposerInput } from "@assistant-ui/react-lexical";
|
|
85
|
+
|
|
86
|
+
const Composer = () => {
|
|
87
|
+
return (
|
|
88
|
+
<ComposerMentionPopover.Root>
|
|
89
|
+
<ComposerPrimitive.Root>
|
|
90
|
+
<LexicalComposerInput placeholder="Type @ to mention a tool..." />
|
|
91
|
+
<ComposerPrimitive.Send />
|
|
92
|
+
<ComposerMentionPopover />
|
|
93
|
+
</ComposerPrimitive.Root>
|
|
94
|
+
</ComposerMentionPopover.Root>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`LexicalComposerInput` auto-wires to `MentionContext` — no extra props needed. Selected mentions appear as inline chips that are treated as atomic units (select, delete, undo as a whole).
|
|
100
|
+
|
|
101
|
+
## Custom Formatter
|
|
102
|
+
|
|
103
|
+
The default directive format is `:type[label]{name=id}`. To use a custom format, pass a `formatter` to both the mention root and the message renderer:
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
import { ComposerMentionPopover } from "@/components/assistant-ui/composer-mention";
|
|
107
|
+
import { createDirectiveText } from "@/components/assistant-ui/composer-mention";
|
|
108
|
+
|
|
109
|
+
const myFormatter = {
|
|
110
|
+
serialize: (item) => `@${item.id}`,
|
|
111
|
+
parse: (text) => [{ kind: "text", text }], // implement your parsing
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// In composer (textarea path):
|
|
115
|
+
<ComposerMentionPopover.Root formatter={myFormatter}>
|
|
116
|
+
...
|
|
117
|
+
</ComposerMentionPopover.Root>
|
|
118
|
+
|
|
119
|
+
// In composer (Lexical path — also pass formatter):
|
|
120
|
+
<ComposerMentionPopover.Root formatter={myFormatter}>
|
|
121
|
+
<ComposerPrimitive.Root>
|
|
122
|
+
<LexicalComposerInput formatter={myFormatter} />
|
|
123
|
+
...
|
|
124
|
+
</ComposerPrimitive.Root>
|
|
125
|
+
</ComposerMentionPopover.Root>
|
|
126
|
+
|
|
127
|
+
// In user messages:
|
|
128
|
+
const MyDirectiveText = createDirectiveText(myFormatter);
|
|
129
|
+
<MessagePrimitive.Parts components={{ Text: MyDirectiveText }} />
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Keyboard Navigation
|
|
133
|
+
|
|
134
|
+
The mention popover supports full keyboard navigation out of the box:
|
|
135
|
+
|
|
136
|
+
| Key | Action |
|
|
137
|
+
| --- | --- |
|
|
138
|
+
| <Kbd>ArrowDown</Kbd> | Highlight next item |
|
|
139
|
+
| <Kbd>ArrowUp</Kbd> | Highlight previous item |
|
|
140
|
+
| <Kbd>Enter</Kbd> | Select highlighted item / drill into category |
|
|
141
|
+
| <Kbd>Escape</Kbd> | Close popover |
|
|
142
|
+
| <Kbd>Backspace</Kbd> | Go back to categories (when query is empty) |
|
|
143
|
+
|
|
144
|
+
## Components
|
|
145
|
+
|
|
146
|
+
### `ComposerMentionPopover.Root`
|
|
147
|
+
|
|
148
|
+
Wraps the composer with mention context and a tool mention adapter. Provides the `@`-trigger detection, keyboard navigation, and popover state.
|
|
149
|
+
|
|
150
|
+
| Prop | Type | Default | Description |
|
|
151
|
+
| --- | --- | --- | --- |
|
|
152
|
+
| `adapter` | `Unstable_MentionAdapter` | Tool adapter | Custom mention adapter |
|
|
153
|
+
| `trigger` | `string` | `"@"` | Character(s) that open the popover |
|
|
154
|
+
| `formatter` | `Unstable_DirectiveFormatter` | Default | Custom directive serializer/parser |
|
|
155
|
+
| `formatLabel` | `(name: string) => string` | Title case | Format tool names for display |
|
|
156
|
+
| `categoryLabel` | `string` | `"Tools"` | Label for the tools category |
|
|
157
|
+
|
|
158
|
+
### `ComposerMentionPopover`
|
|
159
|
+
|
|
160
|
+
Pre-built popover containing categories and items lists. Only renders when the `@` trigger is active.
|
|
161
|
+
|
|
162
|
+
### `DirectiveText`
|
|
163
|
+
|
|
164
|
+
A `TextMessagePartComponent` that parses `:type[label]{name=id}` directives and renders them as styled inline chips.
|
|
165
|
+
|
|
166
|
+
### `createDirectiveText(formatter)`
|
|
167
|
+
|
|
168
|
+
Factory function that creates a `TextMessagePartComponent` using a custom `Unstable_DirectiveFormatter`.
|
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.26",
|
|
4
4
|
"description": "MCP server for assistant-ui documentation and examples",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
],
|
|
34
34
|
"sideEffects": false,
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
36
|
+
"@modelcontextprotocol/sdk": "^1.28.0",
|
|
37
37
|
"gray-matter": "^4.0.3",
|
|
38
38
|
"zod": "^4.3.6"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "^25.5.0",
|
|
42
42
|
"tsx": "^4.21.0",
|
|
43
|
-
"vitest": "^4.1.
|
|
43
|
+
"vitest": "^4.1.1",
|
|
44
44
|
"@assistant-ui/x-buildutils": "0.0.3"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|