@assistant-ui/mcp-docs-server 0.1.24 → 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 +8 -6
- package/.docs/organized/code-examples/with-a2a.md +676 -0
- package/.docs/organized/code-examples/with-ag-ui.md +10 -11
- package/.docs/organized/code-examples/with-ai-sdk-v6.md +31 -19
- package/.docs/organized/code-examples/with-artifacts.md +8 -8
- package/.docs/organized/code-examples/with-assistant-transport.md +6 -6
- package/.docs/organized/code-examples/with-chain-of-thought.md +37 -29
- package/.docs/organized/code-examples/with-cloud-standalone.md +14 -11
- package/.docs/organized/code-examples/with-cloud.md +8 -8
- package/.docs/organized/code-examples/with-custom-thread-list.md +10 -10
- package/.docs/organized/code-examples/with-elevenlabs-scribe.md +11 -11
- package/.docs/organized/code-examples/with-expo.md +571 -520
- package/.docs/organized/code-examples/with-external-store.md +6 -6
- package/.docs/organized/code-examples/with-ffmpeg.md +8 -8
- package/.docs/organized/code-examples/with-google-adk.md +353 -0
- package/.docs/organized/code-examples/with-heat-graph.md +304 -0
- package/.docs/organized/code-examples/with-interactables.md +778 -0
- package/.docs/organized/code-examples/with-langgraph.md +28 -26
- package/.docs/organized/code-examples/with-parent-id-grouping.md +7 -7
- package/.docs/organized/code-examples/with-react-hook-form.md +9 -9
- package/.docs/organized/code-examples/with-react-ink.md +265 -0
- package/.docs/organized/code-examples/with-react-router.md +12 -12
- package/.docs/organized/code-examples/with-store.md +33 -22
- package/.docs/organized/code-examples/with-tanstack.md +10 -10
- package/.docs/organized/code-examples/with-tap-runtime.md +12 -10
- package/.docs/raw/blog/2025-01-31-changelog/index.mdx +1 -1
- package/.docs/raw/blog/2026-03-launch-week/index.mdx +258 -0
- package/.docs/raw/docs/(docs)/architecture.mdx +1 -1
- package/.docs/raw/docs/(docs)/cli.mdx +74 -9
- package/.docs/raw/docs/(docs)/copilots/make-assistant-tool-ui.mdx +8 -3
- package/.docs/raw/docs/(docs)/copilots/make-assistant-tool.mdx +5 -1
- package/.docs/raw/docs/(docs)/copilots/{make-assistant-readable.mdx → make-assistant-visible.mdx} +14 -5
- package/.docs/raw/docs/(docs)/copilots/model-context.mdx +11 -11
- package/.docs/raw/docs/(docs)/copilots/motivation.mdx +2 -2
- package/.docs/raw/docs/(docs)/devtools.mdx +3 -2
- package/.docs/raw/docs/(docs)/guides/attachments.mdx +74 -15
- package/.docs/raw/docs/(docs)/guides/branching.mdx +11 -6
- package/.docs/raw/docs/(docs)/guides/chain-of-thought.mdx +18 -16
- package/.docs/raw/docs/(docs)/guides/context-api.mdx +81 -43
- package/.docs/raw/docs/(docs)/guides/dictation.mdx +5 -5
- package/.docs/raw/docs/(docs)/guides/editing.mdx +16 -7
- package/.docs/raw/docs/(docs)/guides/interactables.mdx +292 -0
- package/.docs/raw/docs/(docs)/guides/latex.mdx +3 -0
- package/.docs/raw/docs/(docs)/guides/message-timing.mdx +5 -4
- package/.docs/raw/docs/(docs)/guides/multi-agent.mdx +174 -0
- package/.docs/raw/docs/(docs)/guides/quoting.mdx +55 -206
- package/.docs/raw/docs/(docs)/guides/speech.mdx +1 -4
- package/.docs/raw/docs/(docs)/guides/suggestions.mdx +9 -15
- package/.docs/raw/docs/(docs)/guides/tool-ui.mdx +17 -7
- package/.docs/raw/docs/(docs)/guides/tools.mdx +24 -9
- package/.docs/raw/docs/(docs)/index.mdx +3 -3
- package/.docs/raw/docs/(docs)/installation.mdx +69 -46
- package/.docs/raw/docs/(reference)/api-reference/context-providers/text-message-part-provider.mdx +20 -6
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-data-stream.mdx +24 -4
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-hook-form.mdx +1 -1
- package/.docs/raw/docs/(reference)/api-reference/integrations/vercel-ai-sdk.mdx +20 -19
- package/.docs/raw/docs/(reference)/api-reference/overview.mdx +28 -53
- package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar.mdx +4 -4
- package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-modal.mdx +7 -1
- package/.docs/raw/docs/(reference)/api-reference/primitives/attachment.mdx +20 -14
- package/.docs/raw/docs/(reference)/api-reference/primitives/branch-picker.mdx +1 -1
- package/.docs/raw/docs/(reference)/api-reference/primitives/composer.mdx +226 -44
- package/.docs/raw/docs/(reference)/api-reference/primitives/message-part.mdx +52 -40
- package/.docs/raw/docs/(reference)/api-reference/primitives/message.mdx +343 -23
- package/.docs/raw/docs/(reference)/api-reference/primitives/suggestion.mdx +4 -6
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item.mdx +4 -2
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list.mdx +3 -5
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread.mdx +169 -22
- package/.docs/raw/docs/(reference)/api-reference/runtimes/assistant-runtime.mdx +14 -4
- package/.docs/raw/docs/(reference)/api-reference/runtimes/attachment-runtime.mdx +15 -26
- package/.docs/raw/docs/(reference)/api-reference/runtimes/composer-runtime.mdx +39 -21
- package/.docs/raw/docs/(reference)/api-reference/runtimes/message-part-runtime.mdx +33 -9
- package/.docs/raw/docs/(reference)/api-reference/runtimes/message-runtime.mdx +48 -21
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-item-runtime.mdx +36 -7
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-runtime.mdx +30 -10
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-runtime.mdx +12 -10
- package/.docs/raw/docs/(reference)/migrations/deprecation-policy.mdx +1 -1
- package/.docs/raw/docs/(reference)/migrations/react-langgraph-v0-7.mdx +9 -4
- package/.docs/raw/docs/(reference)/migrations/v0-11.mdx +7 -5
- package/.docs/raw/docs/(reference)/migrations/v0-12.mdx +9 -7
- package/.docs/raw/docs/(reference)/migrations/v0-14.mdx +159 -0
- package/.docs/raw/docs/(reference)/react-compatibility.mdx +5 -134
- package/.docs/raw/docs/cloud/ai-sdk-assistant-ui.mdx +90 -6
- package/.docs/raw/docs/cloud/ai-sdk.mdx +95 -5
- package/.docs/raw/docs/cloud/langgraph.mdx +13 -3
- package/.docs/raw/docs/ink/adapters.mdx +41 -0
- package/.docs/raw/docs/ink/custom-backend.mdx +203 -0
- package/.docs/raw/docs/ink/hooks.mdx +448 -0
- package/.docs/raw/docs/ink/index.mdx +239 -0
- package/.docs/raw/docs/ink/migration.mdx +140 -0
- package/.docs/raw/docs/ink/primitives.mdx +840 -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/react-native/adapters.mdx +63 -87
- package/.docs/raw/docs/react-native/custom-backend.mdx +11 -14
- package/.docs/raw/docs/react-native/hooks.mdx +214 -232
- package/.docs/raw/docs/react-native/index.mdx +118 -159
- package/.docs/raw/docs/react-native/migration.mdx +144 -0
- package/.docs/raw/docs/react-native/primitives.mdx +431 -302
- package/.docs/raw/docs/runtimes/a2a/index.mdx +294 -0
- package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +9 -9
- package/.docs/raw/docs/runtimes/ai-sdk/v5-legacy.mdx +14 -3
- package/.docs/raw/docs/runtimes/assistant-transport.mdx +59 -25
- package/.docs/raw/docs/runtimes/custom/custom-thread-list.mdx +13 -6
- package/.docs/raw/docs/runtimes/custom/external-store.mdx +138 -38
- package/.docs/raw/docs/runtimes/custom/local.mdx +184 -42
- package/.docs/raw/docs/runtimes/data-stream.mdx +92 -19
- package/.docs/raw/docs/runtimes/google-adk/index.mdx +624 -0
- package/.docs/raw/docs/runtimes/helicone.mdx +6 -6
- package/.docs/raw/docs/runtimes/langgraph/index.mdx +38 -27
- package/.docs/raw/docs/runtimes/langgraph/tutorial/introduction.mdx +1 -1
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-1.mdx +15 -20
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +7 -11
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +8 -11
- package/.docs/raw/docs/runtimes/langserve.mdx +6 -7
- package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +18 -3
- package/.docs/raw/docs/ui/file.mdx +5 -4
- package/.docs/raw/docs/ui/image.mdx +5 -4
- package/.docs/raw/docs/ui/markdown.mdx +3 -1
- package/.docs/raw/docs/ui/mention.mdx +168 -0
- package/.docs/raw/docs/ui/model-selector.mdx +8 -8
- package/.docs/raw/docs/ui/part-grouping.mdx +7 -10
- package/.docs/raw/docs/ui/quote.mdx +210 -0
- package/.docs/raw/docs/ui/reasoning.mdx +12 -11
- package/.docs/raw/docs/ui/sources.mdx +88 -17
- package/.docs/raw/docs/ui/streamdown.mdx +16 -7
- package/.docs/raw/docs/ui/thread-list.mdx +11 -13
- package/.docs/raw/docs/ui/thread.mdx +28 -33
- package/.docs/raw/docs/ui/tool-fallback.mdx +5 -6
- package/.docs/raw/docs/ui/tool-group.mdx +9 -8
- package/.docs/raw/docs/utilities/heat-graph.mdx +236 -0
- package/.docs/raw/docs/utilities/tw-shimmer.mdx +211 -0
- package/package.json +5 -5
- package/.docs/raw/docs/(reference)/legacy/styled/assistant-modal.mdx +0 -77
- package/.docs/raw/docs/(reference)/legacy/styled/decomposition.mdx +0 -635
- package/.docs/raw/docs/(reference)/legacy/styled/markdown.mdx +0 -77
- package/.docs/raw/docs/(reference)/legacy/styled/scrollbar.mdx +0 -72
- package/.docs/raw/docs/(reference)/legacy/styled/thread-width.mdx +0 -22
- package/.docs/raw/docs/(reference)/legacy/styled/thread.mdx +0 -77
- /package/.docs/raw/docs/cloud/{overview.mdx → index.mdx} +0 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Attachment
|
|
3
|
+
description: File and image attachment rendering for the composer and messages.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { AttachmentSample } from "@/components/docs/samples/attachment";
|
|
7
|
+
|
|
8
|
+
The Attachment primitive renders file and image attachments. It appears in two places: inside the composer for pending uploads (with a remove button), and inside messages for sent attachments (read-only). You provide the layout and styling.
|
|
9
|
+
|
|
10
|
+
<Tabs items={["Preview", "Code"]}>
|
|
11
|
+
<Tab>
|
|
12
|
+
<AttachmentSample />
|
|
13
|
+
</Tab>
|
|
14
|
+
<Tab>
|
|
15
|
+
```tsx
|
|
16
|
+
import {
|
|
17
|
+
AttachmentPrimitive,
|
|
18
|
+
ComposerPrimitive,
|
|
19
|
+
} from "@assistant-ui/react";
|
|
20
|
+
import { XIcon } from "lucide-react";
|
|
21
|
+
|
|
22
|
+
function ComposerAttachment() {
|
|
23
|
+
return (
|
|
24
|
+
<AttachmentPrimitive.Root className="flex items-center gap-2 rounded-lg border p-2">
|
|
25
|
+
<AttachmentPrimitive.unstable_Thumb className="flex size-10 items-center justify-center rounded bg-muted text-xs" />
|
|
26
|
+
<span className="text-sm">
|
|
27
|
+
<AttachmentPrimitive.Name />
|
|
28
|
+
</span>
|
|
29
|
+
<AttachmentPrimitive.Remove className="ml-auto rounded-full p-1 hover:bg-muted">
|
|
30
|
+
<XIcon className="size-3" />
|
|
31
|
+
</AttachmentPrimitive.Remove>
|
|
32
|
+
</AttachmentPrimitive.Root>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
</Tab>
|
|
37
|
+
</Tabs>
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
An attachment inside a composer:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { AttachmentPrimitive, ComposerPrimitive } from "@assistant-ui/react";
|
|
45
|
+
|
|
46
|
+
<ComposerPrimitive.Root>
|
|
47
|
+
<ComposerPrimitive.Attachments>
|
|
48
|
+
{() => <MyAttachment />}
|
|
49
|
+
</ComposerPrimitive.Attachments>
|
|
50
|
+
<ComposerPrimitive.Input placeholder="Ask anything..." />
|
|
51
|
+
<ComposerPrimitive.Send>Send</ComposerPrimitive.Send>
|
|
52
|
+
</ComposerPrimitive.Root>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`Root` renders a `<div>`, `unstable_Thumb` renders a `<div>` showing the file extension with a leading dot (e.g., `.pdf`), `Name` renders plain text, and `Remove` renders a `<button>`.
|
|
56
|
+
|
|
57
|
+
<Callout type="info">
|
|
58
|
+
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).
|
|
59
|
+
</Callout>
|
|
60
|
+
|
|
61
|
+
## Core Concepts
|
|
62
|
+
|
|
63
|
+
### Two Contexts
|
|
64
|
+
|
|
65
|
+
Attachments appear in two different contexts:
|
|
66
|
+
|
|
67
|
+
- **Composer**: via `ComposerPrimitive.Attachments`. These are pending uploads that can be removed before sending.
|
|
68
|
+
- **Messages**: via `MessagePrimitive.Attachments`. These are sent attachments, displayed read-only (the iterator renders attachments for user messages).
|
|
69
|
+
|
|
70
|
+
The same `AttachmentPrimitive` parts work in both contexts. The difference is behavioral: `Remove` only works in the composer context.
|
|
71
|
+
|
|
72
|
+
### Iterator Pattern
|
|
73
|
+
|
|
74
|
+
You don't loop over attachments yourself. Instead, use the children render function:
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
// Composer attachments
|
|
78
|
+
<ComposerPrimitive.Attachments>
|
|
79
|
+
{({ attachment }) => {
|
|
80
|
+
if (attachment.type === "image") return <ImageAttachment />;
|
|
81
|
+
if (attachment.type === "document") return <DocumentAttachment />;
|
|
82
|
+
return <GenericAttachment />;
|
|
83
|
+
}}
|
|
84
|
+
</ComposerPrimitive.Attachments>
|
|
85
|
+
|
|
86
|
+
// Message attachments
|
|
87
|
+
<MessagePrimitive.Attachments>
|
|
88
|
+
{({ attachment }) => {
|
|
89
|
+
if (attachment.type === "image") return <ImageAttachment />;
|
|
90
|
+
if (attachment.type === "document") return <DocumentAttachment />;
|
|
91
|
+
return <GenericAttachment />;
|
|
92
|
+
}}
|
|
93
|
+
</MessagePrimitive.Attachments>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Each component receives its attachment context automatically, with no props to pass. `components` is deprecated — use the `children` render function instead.
|
|
97
|
+
|
|
98
|
+
### Remove Button
|
|
99
|
+
|
|
100
|
+
`Remove` calls the attachment runtime remove action. In composer attachments it removes the attachment from the pending message. In message attachments, this action is not supported and clicking `Remove` will throw `"Message attachments cannot be removed"`. Only render `Remove` in composer UIs.
|
|
101
|
+
|
|
102
|
+
### Name as Text
|
|
103
|
+
|
|
104
|
+
`Name` renders plain text with no wrapper element. Wrap it in a `<span>` or other element for styling:
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
<span className="text-sm font-medium">
|
|
108
|
+
<AttachmentPrimitive.Name />
|
|
109
|
+
</span>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Parts
|
|
113
|
+
|
|
114
|
+
### Root
|
|
115
|
+
|
|
116
|
+
Container for a single attachment item. Renders a `<div>` element unless `asChild` is set.
|
|
117
|
+
|
|
118
|
+
```tsx
|
|
119
|
+
<AttachmentPrimitive.Root className="flex items-center gap-2 rounded-lg border p-2">
|
|
120
|
+
<AttachmentPrimitive.Name />
|
|
121
|
+
</AttachmentPrimitive.Root>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### unstable_Thumb
|
|
125
|
+
|
|
126
|
+
Thumbnail slot for attachment previews. Renders a `<div>` element unless `asChild` is set.
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
<AttachmentPrimitive.unstable_Thumb className="flex size-10 items-center justify-center rounded bg-muted text-xs" />
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Name
|
|
133
|
+
|
|
134
|
+
Renders the attachment filename text.
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
<AttachmentPrimitive.Name />
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Remove
|
|
141
|
+
|
|
142
|
+
Button that removes the current attachment when used in a removable attachment context. Renders a `<button>` element unless `asChild` is set.
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
<AttachmentPrimitive.Remove className="rounded-full p-1 hover:bg-muted">
|
|
146
|
+
<XIcon className="size-3" />
|
|
147
|
+
</AttachmentPrimitive.Remove>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Patterns
|
|
151
|
+
|
|
152
|
+
### Composer Attachment with Remove
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
function ComposerAttachmentItem() {
|
|
156
|
+
return (
|
|
157
|
+
<AttachmentPrimitive.Root className="flex items-center gap-2 rounded-lg border p-2">
|
|
158
|
+
<AttachmentPrimitive.unstable_Thumb className="flex size-10 items-center justify-center rounded bg-muted text-xs font-mono" />
|
|
159
|
+
<span className="min-w-0 flex-1 truncate text-sm">
|
|
160
|
+
<AttachmentPrimitive.Name />
|
|
161
|
+
</span>
|
|
162
|
+
<AttachmentPrimitive.Remove className="rounded-full p-1 hover:bg-muted">
|
|
163
|
+
<XIcon className="size-3" />
|
|
164
|
+
</AttachmentPrimitive.Remove>
|
|
165
|
+
</AttachmentPrimitive.Root>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
<ComposerPrimitive.Root>
|
|
170
|
+
<ComposerPrimitive.Attachments
|
|
171
|
+
components={{ Attachment: ComposerAttachmentItem }}
|
|
172
|
+
/>
|
|
173
|
+
<ComposerPrimitive.Input placeholder="Ask anything..." />
|
|
174
|
+
<ComposerPrimitive.Send>Send</ComposerPrimitive.Send>
|
|
175
|
+
</ComposerPrimitive.Root>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Message Attachment (Read-Only)
|
|
179
|
+
|
|
180
|
+
```tsx
|
|
181
|
+
function MessageAttachment() {
|
|
182
|
+
return (
|
|
183
|
+
<AttachmentPrimitive.Root className="flex items-center gap-2 rounded-lg border p-2">
|
|
184
|
+
<AttachmentPrimitive.unstable_Thumb className="flex size-10 items-center justify-center rounded bg-muted text-xs font-mono" />
|
|
185
|
+
<span className="text-sm">
|
|
186
|
+
<AttachmentPrimitive.Name />
|
|
187
|
+
</span>
|
|
188
|
+
</AttachmentPrimitive.Root>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Custom Layout with asChild
|
|
194
|
+
|
|
195
|
+
```tsx
|
|
196
|
+
<AttachmentPrimitive.Root asChild>
|
|
197
|
+
<li className="flex items-center gap-3 py-1">
|
|
198
|
+
<AttachmentPrimitive.unstable_Thumb className="size-8 rounded bg-muted text-xs" />
|
|
199
|
+
<span className="text-sm">
|
|
200
|
+
<AttachmentPrimitive.Name />
|
|
201
|
+
</span>
|
|
202
|
+
</li>
|
|
203
|
+
</AttachmentPrimitive.Root>
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Relationship to Components
|
|
207
|
+
|
|
208
|
+
The shadcn [Attachment](/docs/ui/attachment) component wraps these primitives with styled thumbnails, tooltip filenames, remove buttons, and image preview dialogs. Start there for a prebuilt attachment UI.
|
|
209
|
+
|
|
210
|
+
## API Reference
|
|
211
|
+
|
|
212
|
+
For full prop details on every part, see the [AttachmentPrimitive API Reference](/docs/api-reference/primitives/attachment).
|
|
213
|
+
|
|
214
|
+
Related:
|
|
215
|
+
- [ComposerPrimitive API Reference](/docs/api-reference/primitives/composer)
|
|
216
|
+
- [MessagePrimitive API Reference](/docs/api-reference/primitives/message)
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: BranchPicker
|
|
3
|
+
description: Navigate between message branches, which are alternative responses the user can flip through.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { BranchPickerPrimitiveSample } from "@/components/docs/samples/branch-picker-primitive";
|
|
7
|
+
import { BranchPickerPrimitive as BranchPickerPrimitiveDocs } from "@/generated/primitiveDocs";
|
|
8
|
+
|
|
9
|
+
The BranchPicker primitive lets users navigate between message branches, which are alternative responses generated by editing a message or regenerating a reply. It's used alongside ActionBar inside message components.
|
|
10
|
+
|
|
11
|
+
<Tabs items={["Preview", "Code"]}>
|
|
12
|
+
<Tab>
|
|
13
|
+
<BranchPickerPrimitiveSample />
|
|
14
|
+
</Tab>
|
|
15
|
+
<Tab>
|
|
16
|
+
```tsx
|
|
17
|
+
import {
|
|
18
|
+
BranchPickerPrimitive,
|
|
19
|
+
MessagePrimitive,
|
|
20
|
+
} from "@assistant-ui/react";
|
|
21
|
+
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
|
|
22
|
+
|
|
23
|
+
function AssistantMessage() {
|
|
24
|
+
return (
|
|
25
|
+
<MessagePrimitive.Root className="flex flex-col items-start gap-1">
|
|
26
|
+
<div className="rounded-2xl bg-muted px-4 py-2.5 text-sm">
|
|
27
|
+
<MessagePrimitive.Parts />
|
|
28
|
+
</div>
|
|
29
|
+
<BranchPickerPrimitive.Root className="inline-flex items-center gap-0.5 text-xs">
|
|
30
|
+
<BranchPickerPrimitive.Previous className="flex size-6 items-center justify-center rounded-md disabled:opacity-30">
|
|
31
|
+
<ChevronLeftIcon className="size-3.5" />
|
|
32
|
+
</BranchPickerPrimitive.Previous>
|
|
33
|
+
<span>
|
|
34
|
+
<BranchPickerPrimitive.Number /> / <BranchPickerPrimitive.Count />
|
|
35
|
+
</span>
|
|
36
|
+
<BranchPickerPrimitive.Next className="flex size-6 items-center justify-center rounded-md disabled:opacity-30">
|
|
37
|
+
<ChevronRightIcon className="size-3.5" />
|
|
38
|
+
</BranchPickerPrimitive.Next>
|
|
39
|
+
</BranchPickerPrimitive.Root>
|
|
40
|
+
</MessagePrimitive.Root>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
</Tab>
|
|
45
|
+
</Tabs>
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
Minimal example:
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
import { BranchPickerPrimitive } from "@assistant-ui/react";
|
|
53
|
+
|
|
54
|
+
<BranchPickerPrimitive.Root>
|
|
55
|
+
<BranchPickerPrimitive.Previous>←</BranchPickerPrimitive.Previous>
|
|
56
|
+
<BranchPickerPrimitive.Number /> / <BranchPickerPrimitive.Count />
|
|
57
|
+
<BranchPickerPrimitive.Next>→</BranchPickerPrimitive.Next>
|
|
58
|
+
</BranchPickerPrimitive.Root>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`Root` renders a `<div>`, `Previous` and `Next` render `<button>` elements that auto-disable at boundaries. `Number` and `Count` render plain text (the current branch index and total count).
|
|
62
|
+
|
|
63
|
+
<Callout type="info">
|
|
64
|
+
BranchPicker must be placed inside a `MessagePrimitive.Root` because it reads branch state from the nearest message context.
|
|
65
|
+
</Callout>
|
|
66
|
+
|
|
67
|
+
<Callout type="info">
|
|
68
|
+
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).
|
|
69
|
+
</Callout>
|
|
70
|
+
|
|
71
|
+
## Core Concepts
|
|
72
|
+
|
|
73
|
+
### Branch Navigation
|
|
74
|
+
|
|
75
|
+
`Previous` and `Next` buttons automatically disable at boundaries. `Previous` is disabled on the first branch, and `Next` is disabled on the last. Both also disable while the thread is running if the runtime doesn't support `switchBranchDuringRun`.
|
|
76
|
+
|
|
77
|
+
### Number & Count
|
|
78
|
+
|
|
79
|
+
`Number` and `Count` are text-only primitives that render raw numbers with no wrapping element. Use a `<span>` if you need to style them:
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
<span className="tabular-nums">
|
|
83
|
+
<BranchPickerPrimitive.Number /> / <BranchPickerPrimitive.Count />
|
|
84
|
+
</span>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### hideWhenSingleBranch
|
|
88
|
+
|
|
89
|
+
The `hideWhenSingleBranch` prop on `Root` hides the entire picker when there's only one branch. This is a common production pattern to reduce visual clutter:
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
<BranchPickerPrimitive.Root hideWhenSingleBranch>
|
|
93
|
+
<BranchPickerPrimitive.Previous>←</BranchPickerPrimitive.Previous>
|
|
94
|
+
<BranchPickerPrimitive.Number /> / <BranchPickerPrimitive.Count />
|
|
95
|
+
<BranchPickerPrimitive.Next>→</BranchPickerPrimitive.Next>
|
|
96
|
+
</BranchPickerPrimitive.Root>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Context Requirement
|
|
100
|
+
|
|
101
|
+
BranchPicker reads branch state from the nearest message context. It must be placed inside a `MessagePrimitive.Root`, either directly or nested inside your message component.
|
|
102
|
+
|
|
103
|
+
## Parts
|
|
104
|
+
|
|
105
|
+
### Root
|
|
106
|
+
|
|
107
|
+
Container with optional `hideWhenSingleBranch`. Renders a `<div>` element unless `asChild` is set.
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
<BranchPickerPrimitive.Root hideWhenSingleBranch className="inline-flex items-center gap-1">
|
|
111
|
+
<BranchPickerPrimitive.Previous>←</BranchPickerPrimitive.Previous>
|
|
112
|
+
<BranchPickerPrimitive.Number /> / <BranchPickerPrimitive.Count />
|
|
113
|
+
<BranchPickerPrimitive.Next>→</BranchPickerPrimitive.Next>
|
|
114
|
+
</BranchPickerPrimitive.Root>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
<PrimitivesTypeTable type="BranchPickerPrimitiveRootProps" parameters={BranchPickerPrimitiveDocs.Root.props.filter(p => p.name !== "asChild")} />
|
|
118
|
+
|
|
119
|
+
### Previous
|
|
120
|
+
|
|
121
|
+
Button that selects the previous branch. Renders a `<button>` element unless `asChild` is set.
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
<BranchPickerPrimitive.Previous>Previous</BranchPickerPrimitive.Previous>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Next
|
|
128
|
+
|
|
129
|
+
Button that selects the next branch. Renders a `<button>` element unless `asChild` is set.
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
<BranchPickerPrimitive.Next>Next</BranchPickerPrimitive.Next>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Number
|
|
136
|
+
|
|
137
|
+
Displays the current branch number.
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
<BranchPickerPrimitive.Number />
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Count
|
|
144
|
+
|
|
145
|
+
Displays the total number of branches for the current message.
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
<BranchPickerPrimitive.Count />
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Patterns
|
|
152
|
+
|
|
153
|
+
### Standard Picker with Icons
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
|
|
157
|
+
|
|
158
|
+
<BranchPickerPrimitive.Root
|
|
159
|
+
hideWhenSingleBranch
|
|
160
|
+
className="inline-flex items-center gap-1 text-xs text-muted-foreground"
|
|
161
|
+
>
|
|
162
|
+
<BranchPickerPrimitive.Previous className="size-6 rounded-md hover:bg-muted disabled:opacity-30">
|
|
163
|
+
<ChevronLeftIcon className="size-3.5" />
|
|
164
|
+
</BranchPickerPrimitive.Previous>
|
|
165
|
+
<span className="tabular-nums">
|
|
166
|
+
<BranchPickerPrimitive.Number /> / <BranchPickerPrimitive.Count />
|
|
167
|
+
</span>
|
|
168
|
+
<BranchPickerPrimitive.Next className="size-6 rounded-md hover:bg-muted disabled:opacity-30">
|
|
169
|
+
<ChevronRightIcon className="size-3.5" />
|
|
170
|
+
</BranchPickerPrimitive.Next>
|
|
171
|
+
</BranchPickerPrimitive.Root>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Custom Elements with asChild
|
|
175
|
+
|
|
176
|
+
```tsx
|
|
177
|
+
<BranchPickerPrimitive.Previous asChild>
|
|
178
|
+
<MyIconButton tooltip="Previous branch">
|
|
179
|
+
<ChevronLeftIcon />
|
|
180
|
+
</MyIconButton>
|
|
181
|
+
</BranchPickerPrimitive.Previous>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The primitive's disabled state and click handler merge onto your element.
|
|
185
|
+
|
|
186
|
+
### Inside a Message Footer
|
|
187
|
+
|
|
188
|
+
The most common pattern places the BranchPicker alongside an ActionBar in a message footer:
|
|
189
|
+
|
|
190
|
+
```tsx
|
|
191
|
+
function AssistantMessage() {
|
|
192
|
+
return (
|
|
193
|
+
<MessagePrimitive.Root>
|
|
194
|
+
<div className="rounded-xl bg-muted p-3">
|
|
195
|
+
<MessagePrimitive.Parts />
|
|
196
|
+
</div>
|
|
197
|
+
<div className="flex items-center justify-between">
|
|
198
|
+
<BranchPickerPrimitive.Root hideWhenSingleBranch>
|
|
199
|
+
{/* prev / number / count / next */}
|
|
200
|
+
</BranchPickerPrimitive.Root>
|
|
201
|
+
<ActionBarPrimitive.Root>
|
|
202
|
+
<ActionBarPrimitive.Copy>Copy</ActionBarPrimitive.Copy>
|
|
203
|
+
<ActionBarPrimitive.Reload>Reload</ActionBarPrimitive.Reload>
|
|
204
|
+
</ActionBarPrimitive.Root>
|
|
205
|
+
</div>
|
|
206
|
+
</MessagePrimitive.Root>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Relationship to Components
|
|
212
|
+
|
|
213
|
+
The shadcn [Thread](/docs/ui/thread) component includes a BranchPicker in both AssistantMessage and UserMessage footers, with `hideWhenSingleBranch` enabled. If the default layout works, use the component. Reach for `BranchPickerPrimitive` directly when you need a custom position, different styling, or a non-standard branch navigation experience.
|
|
214
|
+
|
|
215
|
+
## API Reference
|
|
216
|
+
|
|
217
|
+
For full prop details on every part, see the [BranchPickerPrimitive API Reference](/docs/api-reference/primitives/branch-picker).
|
|
218
|
+
|
|
219
|
+
Related:
|
|
220
|
+
- [ActionBarPrimitive API Reference](/docs/api-reference/primitives/action-bar)
|
|
221
|
+
- [MessagePrimitive API Reference](/docs/api-reference/primitives/message)
|