@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.
Files changed (151) hide show
  1. package/.docs/organized/code-examples/waterfall.md +8 -6
  2. package/.docs/organized/code-examples/with-a2a.md +676 -0
  3. package/.docs/organized/code-examples/with-ag-ui.md +10 -11
  4. package/.docs/organized/code-examples/with-ai-sdk-v6.md +31 -19
  5. package/.docs/organized/code-examples/with-artifacts.md +8 -8
  6. package/.docs/organized/code-examples/with-assistant-transport.md +6 -6
  7. package/.docs/organized/code-examples/with-chain-of-thought.md +37 -29
  8. package/.docs/organized/code-examples/with-cloud-standalone.md +14 -11
  9. package/.docs/organized/code-examples/with-cloud.md +8 -8
  10. package/.docs/organized/code-examples/with-custom-thread-list.md +10 -10
  11. package/.docs/organized/code-examples/with-elevenlabs-scribe.md +11 -11
  12. package/.docs/organized/code-examples/with-expo.md +571 -520
  13. package/.docs/organized/code-examples/with-external-store.md +6 -6
  14. package/.docs/organized/code-examples/with-ffmpeg.md +8 -8
  15. package/.docs/organized/code-examples/with-google-adk.md +353 -0
  16. package/.docs/organized/code-examples/with-heat-graph.md +304 -0
  17. package/.docs/organized/code-examples/with-interactables.md +778 -0
  18. package/.docs/organized/code-examples/with-langgraph.md +28 -26
  19. package/.docs/organized/code-examples/with-parent-id-grouping.md +7 -7
  20. package/.docs/organized/code-examples/with-react-hook-form.md +9 -9
  21. package/.docs/organized/code-examples/with-react-ink.md +265 -0
  22. package/.docs/organized/code-examples/with-react-router.md +12 -12
  23. package/.docs/organized/code-examples/with-store.md +33 -22
  24. package/.docs/organized/code-examples/with-tanstack.md +10 -10
  25. package/.docs/organized/code-examples/with-tap-runtime.md +12 -10
  26. package/.docs/raw/blog/2025-01-31-changelog/index.mdx +1 -1
  27. package/.docs/raw/blog/2026-03-launch-week/index.mdx +258 -0
  28. package/.docs/raw/docs/(docs)/architecture.mdx +1 -1
  29. package/.docs/raw/docs/(docs)/cli.mdx +74 -9
  30. package/.docs/raw/docs/(docs)/copilots/make-assistant-tool-ui.mdx +8 -3
  31. package/.docs/raw/docs/(docs)/copilots/make-assistant-tool.mdx +5 -1
  32. package/.docs/raw/docs/(docs)/copilots/{make-assistant-readable.mdx → make-assistant-visible.mdx} +14 -5
  33. package/.docs/raw/docs/(docs)/copilots/model-context.mdx +11 -11
  34. package/.docs/raw/docs/(docs)/copilots/motivation.mdx +2 -2
  35. package/.docs/raw/docs/(docs)/devtools.mdx +3 -2
  36. package/.docs/raw/docs/(docs)/guides/attachments.mdx +74 -15
  37. package/.docs/raw/docs/(docs)/guides/branching.mdx +11 -6
  38. package/.docs/raw/docs/(docs)/guides/chain-of-thought.mdx +18 -16
  39. package/.docs/raw/docs/(docs)/guides/context-api.mdx +81 -43
  40. package/.docs/raw/docs/(docs)/guides/dictation.mdx +5 -5
  41. package/.docs/raw/docs/(docs)/guides/editing.mdx +16 -7
  42. package/.docs/raw/docs/(docs)/guides/interactables.mdx +292 -0
  43. package/.docs/raw/docs/(docs)/guides/latex.mdx +3 -0
  44. package/.docs/raw/docs/(docs)/guides/message-timing.mdx +5 -4
  45. package/.docs/raw/docs/(docs)/guides/multi-agent.mdx +174 -0
  46. package/.docs/raw/docs/(docs)/guides/quoting.mdx +55 -206
  47. package/.docs/raw/docs/(docs)/guides/speech.mdx +1 -4
  48. package/.docs/raw/docs/(docs)/guides/suggestions.mdx +9 -15
  49. package/.docs/raw/docs/(docs)/guides/tool-ui.mdx +17 -7
  50. package/.docs/raw/docs/(docs)/guides/tools.mdx +24 -9
  51. package/.docs/raw/docs/(docs)/index.mdx +3 -3
  52. package/.docs/raw/docs/(docs)/installation.mdx +69 -46
  53. package/.docs/raw/docs/(reference)/api-reference/context-providers/text-message-part-provider.mdx +20 -6
  54. package/.docs/raw/docs/(reference)/api-reference/integrations/react-data-stream.mdx +24 -4
  55. package/.docs/raw/docs/(reference)/api-reference/integrations/react-hook-form.mdx +1 -1
  56. package/.docs/raw/docs/(reference)/api-reference/integrations/vercel-ai-sdk.mdx +20 -19
  57. package/.docs/raw/docs/(reference)/api-reference/overview.mdx +28 -53
  58. package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar.mdx +4 -4
  59. package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-modal.mdx +7 -1
  60. package/.docs/raw/docs/(reference)/api-reference/primitives/attachment.mdx +20 -14
  61. package/.docs/raw/docs/(reference)/api-reference/primitives/branch-picker.mdx +1 -1
  62. package/.docs/raw/docs/(reference)/api-reference/primitives/composer.mdx +226 -44
  63. package/.docs/raw/docs/(reference)/api-reference/primitives/message-part.mdx +52 -40
  64. package/.docs/raw/docs/(reference)/api-reference/primitives/message.mdx +343 -23
  65. package/.docs/raw/docs/(reference)/api-reference/primitives/suggestion.mdx +4 -6
  66. package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item.mdx +4 -2
  67. package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list.mdx +3 -5
  68. package/.docs/raw/docs/(reference)/api-reference/primitives/thread.mdx +169 -22
  69. package/.docs/raw/docs/(reference)/api-reference/runtimes/assistant-runtime.mdx +14 -4
  70. package/.docs/raw/docs/(reference)/api-reference/runtimes/attachment-runtime.mdx +15 -26
  71. package/.docs/raw/docs/(reference)/api-reference/runtimes/composer-runtime.mdx +39 -21
  72. package/.docs/raw/docs/(reference)/api-reference/runtimes/message-part-runtime.mdx +33 -9
  73. package/.docs/raw/docs/(reference)/api-reference/runtimes/message-runtime.mdx +48 -21
  74. package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-item-runtime.mdx +36 -7
  75. package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-runtime.mdx +30 -10
  76. package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-runtime.mdx +12 -10
  77. package/.docs/raw/docs/(reference)/migrations/deprecation-policy.mdx +1 -1
  78. package/.docs/raw/docs/(reference)/migrations/react-langgraph-v0-7.mdx +9 -4
  79. package/.docs/raw/docs/(reference)/migrations/v0-11.mdx +7 -5
  80. package/.docs/raw/docs/(reference)/migrations/v0-12.mdx +9 -7
  81. package/.docs/raw/docs/(reference)/migrations/v0-14.mdx +159 -0
  82. package/.docs/raw/docs/(reference)/react-compatibility.mdx +5 -134
  83. package/.docs/raw/docs/cloud/ai-sdk-assistant-ui.mdx +90 -6
  84. package/.docs/raw/docs/cloud/ai-sdk.mdx +95 -5
  85. package/.docs/raw/docs/cloud/langgraph.mdx +13 -3
  86. package/.docs/raw/docs/ink/adapters.mdx +41 -0
  87. package/.docs/raw/docs/ink/custom-backend.mdx +203 -0
  88. package/.docs/raw/docs/ink/hooks.mdx +448 -0
  89. package/.docs/raw/docs/ink/index.mdx +239 -0
  90. package/.docs/raw/docs/ink/migration.mdx +140 -0
  91. package/.docs/raw/docs/ink/primitives.mdx +840 -0
  92. package/.docs/raw/docs/primitives/action-bar.mdx +351 -0
  93. package/.docs/raw/docs/primitives/assistant-modal.mdx +215 -0
  94. package/.docs/raw/docs/primitives/attachment.mdx +216 -0
  95. package/.docs/raw/docs/primitives/branch-picker.mdx +221 -0
  96. package/.docs/raw/docs/primitives/chain-of-thought.mdx +311 -0
  97. package/.docs/raw/docs/primitives/composer.mdx +526 -0
  98. package/.docs/raw/docs/primitives/error.mdx +141 -0
  99. package/.docs/raw/docs/primitives/index.mdx +98 -0
  100. package/.docs/raw/docs/primitives/message.mdx +524 -0
  101. package/.docs/raw/docs/primitives/selection-toolbar.mdx +165 -0
  102. package/.docs/raw/docs/primitives/suggestion.mdx +242 -0
  103. package/.docs/raw/docs/primitives/thread-list.mdx +404 -0
  104. package/.docs/raw/docs/primitives/thread.mdx +482 -0
  105. package/.docs/raw/docs/react-native/adapters.mdx +63 -87
  106. package/.docs/raw/docs/react-native/custom-backend.mdx +11 -14
  107. package/.docs/raw/docs/react-native/hooks.mdx +214 -232
  108. package/.docs/raw/docs/react-native/index.mdx +118 -159
  109. package/.docs/raw/docs/react-native/migration.mdx +144 -0
  110. package/.docs/raw/docs/react-native/primitives.mdx +431 -302
  111. package/.docs/raw/docs/runtimes/a2a/index.mdx +294 -0
  112. package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +9 -9
  113. package/.docs/raw/docs/runtimes/ai-sdk/v5-legacy.mdx +14 -3
  114. package/.docs/raw/docs/runtimes/assistant-transport.mdx +59 -25
  115. package/.docs/raw/docs/runtimes/custom/custom-thread-list.mdx +13 -6
  116. package/.docs/raw/docs/runtimes/custom/external-store.mdx +138 -38
  117. package/.docs/raw/docs/runtimes/custom/local.mdx +184 -42
  118. package/.docs/raw/docs/runtimes/data-stream.mdx +92 -19
  119. package/.docs/raw/docs/runtimes/google-adk/index.mdx +624 -0
  120. package/.docs/raw/docs/runtimes/helicone.mdx +6 -6
  121. package/.docs/raw/docs/runtimes/langgraph/index.mdx +38 -27
  122. package/.docs/raw/docs/runtimes/langgraph/tutorial/introduction.mdx +1 -1
  123. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-1.mdx +15 -20
  124. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +7 -11
  125. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +8 -11
  126. package/.docs/raw/docs/runtimes/langserve.mdx +6 -7
  127. package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +18 -3
  128. package/.docs/raw/docs/ui/file.mdx +5 -4
  129. package/.docs/raw/docs/ui/image.mdx +5 -4
  130. package/.docs/raw/docs/ui/markdown.mdx +3 -1
  131. package/.docs/raw/docs/ui/mention.mdx +168 -0
  132. package/.docs/raw/docs/ui/model-selector.mdx +8 -8
  133. package/.docs/raw/docs/ui/part-grouping.mdx +7 -10
  134. package/.docs/raw/docs/ui/quote.mdx +210 -0
  135. package/.docs/raw/docs/ui/reasoning.mdx +12 -11
  136. package/.docs/raw/docs/ui/sources.mdx +88 -17
  137. package/.docs/raw/docs/ui/streamdown.mdx +16 -7
  138. package/.docs/raw/docs/ui/thread-list.mdx +11 -13
  139. package/.docs/raw/docs/ui/thread.mdx +28 -33
  140. package/.docs/raw/docs/ui/tool-fallback.mdx +5 -6
  141. package/.docs/raw/docs/ui/tool-group.mdx +9 -8
  142. package/.docs/raw/docs/utilities/heat-graph.mdx +236 -0
  143. package/.docs/raw/docs/utilities/tw-shimmer.mdx +211 -0
  144. package/package.json +5 -5
  145. package/.docs/raw/docs/(reference)/legacy/styled/assistant-modal.mdx +0 -77
  146. package/.docs/raw/docs/(reference)/legacy/styled/decomposition.mdx +0 -635
  147. package/.docs/raw/docs/(reference)/legacy/styled/markdown.mdx +0 -77
  148. package/.docs/raw/docs/(reference)/legacy/styled/scrollbar.mdx +0 -72
  149. package/.docs/raw/docs/(reference)/legacy/styled/thread-width.mdx +0 -22
  150. package/.docs/raw/docs/(reference)/legacy/styled/thread.mdx +0 -77
  151. /package/.docs/raw/docs/cloud/{overview.mdx → index.mdx} +0 -0
@@ -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)
@@ -1,118 +1,94 @@
1
1
  ---
2
2
  title: Adapters
3
- description: Storage and title generation adapters for React Native.
3
+ description: Persistence and title generation adapters for React Native.
4
4
  ---
5
5
 
6
- Adapters customize how the local runtime persists threads and generates titles. Pass them to `useLocalRuntime` via options.
6
+ Adapters customize runtime behavior. They can be passed as options to `useLocalRuntime` or `useRemoteThreadListRuntime`.
7
7
 
8
- ```tsx
9
- import AsyncStorage from "@react-native-async-storage/async-storage";
10
- import {
11
- useLocalRuntime,
12
- createSimpleTitleAdapter,
13
- } from "@assistant-ui/react-native";
14
-
15
- const runtime = useLocalRuntime(chatModel, {
16
- storage: AsyncStorage,
17
- titleGenerator: createSimpleTitleAdapter(),
18
- });
19
- ```
8
+ ## Persistence
20
9
 
21
- ## Storage
22
-
23
- The `storage` option accepts any object with `getItem`, `setItem`, and `removeItem` methods (matching the `AsyncStorage` interface). When provided, threads and messages are persisted across app restarts.
24
-
25
- ```tsx
26
- type AsyncStorageLike = {
27
- getItem(key: string): Promise<string | null>;
28
- setItem(key: string, value: string): Promise<void>;
29
- removeItem(key: string): Promise<void>;
30
- };
31
- ```
10
+ By default, `useLocalRuntime` stores threads and messages in memory only -- they are lost when the app restarts. To persist data, use one of these approaches:
32
11
 
33
- ### AsyncStorage
12
+ ### Assistant Cloud
34
13
 
35
- The most common choice for React Native:
14
+ The simplest way to add persistence. Pass a `cloud` option to `useLocalRuntime`:
36
15
 
37
16
  ```tsx
38
- import AsyncStorage from "@react-native-async-storage/async-storage";
17
+ import { useLocalRuntime } from "@assistant-ui/react-native";
18
+ import { AssistantCloud } from "@assistant-ui/cloud";
39
19
 
40
- const runtime = useLocalRuntime(chatModel, {
41
- storage: AsyncStorage,
20
+ const cloud = new AssistantCloud({
21
+ baseUrl: "https://backend.assistant-ui.com",
22
+ authToken: () => fetchTokenFromYourBackend(),
42
23
  });
43
- ```
44
-
45
- An optional `storagePrefix` parameter namespaces the keys:
46
24
 
47
- ```tsx
48
- const runtime = useLocalRuntime(chatModel, {
49
- storage: AsyncStorage,
50
- storagePrefix: "chat:",
51
- // Keys: "chat:threads", "chat:messages:<threadId>", ...
52
- });
25
+ const runtime = useLocalRuntime(chatModel, { cloud });
53
26
  ```
54
27
 
55
- ### No storage (default)
56
-
57
- When `storage` is omitted, threads live in memory only — lost on app restart.
58
-
59
- ```tsx
60
- const runtime = useLocalRuntime(chatModel);
61
- ```
28
+ This gives you multi-thread support with server-side persistence, cross-device sync, and automatic title generation.
62
29
 
63
- ### Advanced: createLocalStorageAdapter
30
+ ### History adapter
64
31
 
65
- For more control, use `createLocalStorageAdapter` directly to create a `RemoteThreadListAdapter`:
32
+ For custom persistence (e.g. saving message history to your own backend), pass a `ThreadHistoryAdapter` via `adapters.history`:
66
33
 
67
34
  ```tsx
68
- import AsyncStorage from "@react-native-async-storage/async-storage";
69
- import {
70
- createLocalStorageAdapter,
71
- createSimpleTitleAdapter,
72
- } from "@assistant-ui/react-native";
73
-
74
- const adapter = createLocalStorageAdapter({
75
- storage: AsyncStorage,
76
- prefix: "chat:",
77
- titleGenerator: createSimpleTitleAdapter(),
78
- });
79
- ```
80
-
81
- ## TitleGenerationAdapter
82
-
83
- Generates a title for a thread based on its messages.
35
+ import { useLocalRuntime } from "@assistant-ui/react-native";
36
+ import type { ThreadHistoryAdapter } from "@assistant-ui/react-native";
37
+
38
+ const myHistoryAdapter: ThreadHistoryAdapter = {
39
+ async load() {
40
+ // Load saved messages from your storage
41
+ const data = await fetchMessagesFromBackend();
42
+ return data; // { headId, messages }
43
+ },
44
+ async append(item) {
45
+ // Persist a new message
46
+ await saveMessageToBackend(item);
47
+ },
48
+ };
84
49
 
85
- ```tsx
86
- interface TitleGenerationAdapter {
87
- generateTitle(messages: ThreadMessage[]): Promise<string>;
88
- }
50
+ const runtime = useLocalRuntime(chatModel, {
51
+ adapters: {
52
+ history: myHistoryAdapter,
53
+ },
54
+ });
89
55
  ```
90
56
 
91
- ### Built-in implementations
57
+ ### RemoteThreadListAdapter
92
58
 
93
- #### Simple title adapter
59
+ For full backend thread management (thread list, archiving, cross-device sync), use `useRemoteThreadListRuntime`. See the [Custom Backend](/docs/react-native/custom-backend) page for a full example.
94
60
 
95
- Returns the first 50 characters of the first user message.
61
+ ## RemoteThreadListAdapter
96
62
 
97
- ```tsx
98
- import { createSimpleTitleAdapter } from "@assistant-ui/react-native";
99
-
100
- const titleGenerator = createSimpleTitleAdapter();
101
- ```
102
-
103
- ### Custom implementation
63
+ Title generation is configured via the `generateTitle` method on `RemoteThreadListAdapter`. See the [Custom Backend](/docs/react-native/custom-backend) page for a full example.
104
64
 
105
65
  ```tsx
106
- import type { TitleGenerationAdapter } from "@assistant-ui/react-native";
107
-
108
- const aiTitleGenerator: TitleGenerationAdapter = {
109
- async generateTitle(messages) {
110
- const response = await fetch("/api/generate-title", {
111
- method: "POST",
112
- body: JSON.stringify({ messages }),
66
+ import type { RemoteThreadListAdapter } from "@assistant-ui/react-native";
67
+ import { createAssistantStream } from "assistant-stream";
68
+
69
+ const myAdapter: RemoteThreadListAdapter = {
70
+ // ... other methods ...
71
+
72
+ async generateTitle(remoteId, unstable_messages) {
73
+ return createAssistantStream(async (controller) => {
74
+ const res = await fetch(`/api/threads/${remoteId}/title`, {
75
+ method: "POST",
76
+ headers: { "Content-Type": "application/json" },
77
+ body: JSON.stringify({ messages: unstable_messages }),
78
+ });
79
+ const { title } = await res.json();
80
+ controller.appendText(title);
113
81
  });
114
- const { title } = await response.json();
115
- return title;
116
82
  },
117
83
  };
118
84
  ```
85
+
86
+ ## Which option to choose?
87
+
88
+ | | ChatModelAdapter + `useLocalRuntime` | RemoteThreadListAdapter + `useRemoteThreadListRuntime` |
89
+ |---|---|---|
90
+ | **Thread storage** | In-memory (or cloud) | Your backend |
91
+ | **Message storage** | In-memory (can add history adapter) | In-memory (can add history adapter for server-side) |
92
+ | **Cross-device sync** | Only with cloud | Yes |
93
+ | **Setup complexity** | Minimal | Moderate |
94
+ | **Best for** | Single-device apps, prototypes | Production apps with user accounts |