@assistant-ui/mcp-docs-server 0.1.30 → 0.1.31

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 (208) hide show
  1. package/.docs/organized/code-examples/waterfall.md +1 -1
  2. package/.docs/organized/code-examples/with-a2a.md +2 -2
  3. package/.docs/organized/code-examples/with-ag-ui.md +3 -3
  4. package/.docs/organized/code-examples/with-ai-sdk-v6.md +5 -5
  5. package/.docs/organized/code-examples/with-artifacts.md +5 -5
  6. package/.docs/organized/code-examples/with-assistant-transport.md +3 -3
  7. package/.docs/organized/code-examples/with-chain-of-thought.md +79 -50
  8. package/.docs/organized/code-examples/with-cloud-standalone.md +4 -4
  9. package/.docs/organized/code-examples/with-cloud.md +4 -4
  10. package/.docs/organized/code-examples/with-custom-thread-list.md +56 -11
  11. package/.docs/organized/code-examples/with-elevenlabs-conversational.md +7 -7
  12. package/.docs/organized/code-examples/with-elevenlabs-scribe.md +7 -7
  13. package/.docs/organized/code-examples/with-expo.md +16 -16
  14. package/.docs/organized/code-examples/with-external-store.md +2 -2
  15. package/.docs/organized/code-examples/with-ffmpeg.md +5 -5
  16. package/.docs/organized/code-examples/with-generative-ui.md +5 -5
  17. package/.docs/organized/code-examples/with-google-adk.md +4 -4
  18. package/.docs/organized/code-examples/with-heat-graph.md +1 -1
  19. package/.docs/organized/code-examples/with-interactables.md +5 -5
  20. package/.docs/organized/code-examples/with-langchain.md +3 -3
  21. package/.docs/organized/code-examples/with-langgraph.md +3 -3
  22. package/.docs/organized/code-examples/with-livekit.md +8 -8
  23. package/.docs/organized/code-examples/with-opencode.md +99 -54
  24. package/.docs/organized/code-examples/with-parent-id-grouping.md +4 -4
  25. package/.docs/organized/code-examples/with-react-hook-form.md +5 -5
  26. package/.docs/organized/code-examples/with-react-ink.md +1 -1
  27. package/.docs/organized/code-examples/with-react-router.md +8 -8
  28. package/.docs/organized/code-examples/with-store.md +1 -1
  29. package/.docs/organized/code-examples/with-tanstack.md +5 -5
  30. package/.docs/organized/code-examples/with-tap-runtime.md +2 -2
  31. package/.docs/raw/docs/(docs)/cli.mdx +2 -1
  32. package/.docs/raw/docs/(docs)/copilots/assistant-frame.mdx +1 -0
  33. package/.docs/raw/docs/(docs)/copilots/make-assistant-tool-ui.mdx +10 -3
  34. package/.docs/raw/docs/(docs)/copilots/make-assistant-tool.mdx +8 -3
  35. package/.docs/raw/docs/(docs)/copilots/make-assistant-visible.mdx +1 -0
  36. package/.docs/raw/docs/(docs)/copilots/model-context.mdx +1 -0
  37. package/.docs/raw/docs/(docs)/copilots/motivation.mdx +1 -0
  38. package/.docs/raw/docs/(docs)/copilots/use-assistant-instructions.mdx +1 -0
  39. package/.docs/raw/docs/(docs)/devtools.mdx +1 -0
  40. package/.docs/raw/docs/(docs)/index.mdx +1 -0
  41. package/.docs/raw/docs/(docs)/installation.mdx +1 -0
  42. package/.docs/raw/docs/(docs)/rtl.mdx +1 -0
  43. package/.docs/raw/docs/(reference)/api-reference/adapters/attachments.mdx +34 -0
  44. package/.docs/raw/docs/(reference)/api-reference/adapters/feedback-speech.mdx +41 -0
  45. package/.docs/raw/docs/(reference)/api-reference/adapters/index.mdx +26 -0
  46. package/.docs/raw/docs/(reference)/api-reference/adapters/persistence.mdx +34 -0
  47. package/.docs/raw/docs/(reference)/api-reference/adapters/runtime.mdx +31 -0
  48. package/.docs/raw/docs/(reference)/api-reference/context-providers/index.mdx +20 -0
  49. package/.docs/raw/docs/(reference)/api-reference/hooks/index.mdx +26 -0
  50. package/.docs/raw/docs/(reference)/api-reference/hooks/model-context.mdx +72 -0
  51. package/.docs/raw/docs/(reference)/api-reference/hooks/runtimes.mdx +41 -0
  52. package/.docs/raw/docs/(reference)/api-reference/hooks/state.mdx +48 -0
  53. package/.docs/raw/docs/(reference)/api-reference/hooks/utilities.mdx +30 -0
  54. package/.docs/raw/docs/(reference)/api-reference/integrations/index.mdx +23 -0
  55. package/.docs/raw/docs/(reference)/api-reference/overview.mdx +21 -0
  56. package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-if.mdx +7 -0
  57. package/.docs/raw/docs/(reference)/api-reference/primitives/index.mdx +65 -0
  58. package/.docs/raw/docs/(reference)/api-reference/primitives/message.mdx +50 -6
  59. package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list.mdx +15 -0
  60. package/.docs/raw/docs/(reference)/api-reference/primitives/thread.mdx +36 -1
  61. package/.docs/raw/docs/(reference)/api-reference/runtimes/index.mdx +38 -0
  62. package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-runtime.mdx +5 -0
  63. package/.docs/raw/docs/(reference)/migrations/v0-14.mdx +144 -6
  64. package/.docs/raw/docs/cloud/ai-sdk-assistant-ui.mdx +230 -2
  65. package/.docs/raw/docs/cloud/ai-sdk.mdx +221 -3
  66. package/.docs/raw/docs/cloud/langgraph.mdx +274 -2
  67. package/.docs/raw/docs/{(docs)/guides → guides}/attachments.mdx +41 -36
  68. package/.docs/raw/docs/guides/branching.mdx +76 -0
  69. package/.docs/raw/docs/guides/chain-of-thought.mdx +166 -0
  70. package/.docs/raw/docs/{(docs)/guides → guides}/context-api.mdx +50 -22
  71. package/.docs/raw/docs/{(docs)/guides → guides}/dictation.mdx +2 -0
  72. package/.docs/raw/docs/guides/editing.mdx +102 -0
  73. package/.docs/raw/docs/guides/index.mdx +103 -0
  74. package/.docs/raw/docs/{(docs)/guides → guides}/interactables.mdx +49 -0
  75. package/.docs/raw/docs/{(docs)/guides → guides}/latex.mdx +51 -8
  76. package/.docs/raw/docs/{(docs)/guides → guides}/mentions.mdx +61 -86
  77. package/.docs/raw/docs/{(docs)/guides → guides}/message-timing.mdx +8 -2
  78. package/.docs/raw/docs/{(docs)/guides → guides}/multi-agent.mdx +64 -4
  79. package/.docs/raw/docs/{(docs)/guides → guides}/quoting.mdx +10 -17
  80. package/.docs/raw/docs/{(docs)/guides → guides}/slash-commands.mdx +103 -37
  81. package/.docs/raw/docs/guides/speech.mdx +156 -0
  82. package/.docs/raw/docs/{(docs)/guides → guides}/suggestions.mdx +21 -83
  83. package/.docs/raw/docs/{(docs)/guides → guides}/tool-ui.mdx +108 -36
  84. package/.docs/raw/docs/{(docs)/guides → guides}/tools.mdx +131 -35
  85. package/.docs/raw/docs/{(docs)/guides → guides}/voice.mdx +39 -0
  86. package/.docs/raw/docs/ink/index.mdx +1 -3
  87. package/.docs/raw/docs/ink/migration.mdx +1 -3
  88. package/.docs/raw/docs/ink/primitives.mdx +37 -1
  89. package/.docs/raw/docs/integrations/attachments/custom-adapter.mdx +520 -0
  90. package/.docs/raw/docs/integrations/auth/better-auth.mdx +191 -0
  91. package/.docs/raw/docs/integrations/auth/clerk.mdx +172 -0
  92. package/.docs/raw/docs/integrations/auth/next-auth.mdx +196 -0
  93. package/.docs/raw/docs/integrations/frameworks/ai-sdk.mdx +79 -0
  94. package/.docs/raw/docs/integrations/frameworks/mastra/full-stack.mdx +188 -0
  95. package/.docs/raw/docs/integrations/frameworks/mastra/overview.mdx +57 -0
  96. package/.docs/raw/docs/integrations/frameworks/mastra/separate-server.mdx +201 -0
  97. package/.docs/raw/docs/integrations/gateways/index.mdx +157 -0
  98. package/.docs/raw/docs/integrations/index.mdx +173 -0
  99. package/.docs/raw/docs/integrations/observability/helicone.mdx +130 -0
  100. package/.docs/raw/docs/integrations/observability/langfuse.mdx +156 -0
  101. package/.docs/raw/docs/integrations/observability/langsmith.mdx +146 -0
  102. package/.docs/raw/docs/integrations/persistence/custom-adapter.mdx +712 -0
  103. package/.docs/raw/docs/integrations/tools/mcp.mdx +267 -0
  104. package/.docs/raw/docs/primitives/action-bar.mdx +1 -0
  105. package/.docs/raw/docs/primitives/assistant-modal.mdx +1 -0
  106. package/.docs/raw/docs/primitives/attachment.mdx +1 -0
  107. package/.docs/raw/docs/primitives/branch-picker.mdx +1 -0
  108. package/.docs/raw/docs/primitives/chain-of-thought.mdx +90 -85
  109. package/.docs/raw/docs/primitives/composer.mdx +2 -1
  110. package/.docs/raw/docs/primitives/error.mdx +1 -0
  111. package/.docs/raw/docs/primitives/index.mdx +2 -1
  112. package/.docs/raw/docs/primitives/message.mdx +68 -5
  113. package/.docs/raw/docs/primitives/selection-toolbar.mdx +1 -0
  114. package/.docs/raw/docs/primitives/suggestion.mdx +1 -0
  115. package/.docs/raw/docs/primitives/thread-list.mdx +39 -0
  116. package/.docs/raw/docs/primitives/thread.mdx +16 -13
  117. package/.docs/raw/docs/react-native/index.mdx +1 -3
  118. package/.docs/raw/docs/react-native/migration.mdx +1 -3
  119. package/.docs/raw/docs/runtimes/a2a/client-and-hooks.mdx +396 -0
  120. package/.docs/raw/docs/runtimes/a2a/overview.mdx +60 -0
  121. package/.docs/raw/docs/runtimes/a2a/quickstart.mdx +216 -0
  122. package/.docs/raw/docs/runtimes/ag-ui/overview.mdx +70 -0
  123. package/.docs/raw/docs/runtimes/ag-ui/quickstart.mdx +243 -0
  124. package/.docs/raw/docs/runtimes/ag-ui/runtime-options.mdx +123 -0
  125. package/.docs/raw/docs/runtimes/ai-sdk/overview.mdx +52 -0
  126. package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +71 -131
  127. package/.docs/raw/docs/runtimes/ai-sdk/v5-legacy.mdx +69 -63
  128. package/.docs/raw/docs/runtimes/ai-sdk/v6.mdx +330 -123
  129. package/.docs/raw/docs/runtimes/concepts/adapters.mdx +265 -0
  130. package/.docs/raw/docs/runtimes/concepts/architecture.mdx +125 -0
  131. package/.docs/raw/docs/runtimes/concepts/stability.mdx +67 -0
  132. package/.docs/raw/docs/runtimes/concepts/threads.mdx +428 -0
  133. package/.docs/raw/docs/runtimes/custom/assistant-transport.mdx +703 -0
  134. package/.docs/raw/docs/runtimes/custom/data-stream.mdx +323 -0
  135. package/.docs/raw/docs/runtimes/custom/external-store.mdx +253 -1236
  136. package/.docs/raw/docs/runtimes/custom/local-runtime.mdx +746 -0
  137. package/.docs/raw/docs/runtimes/custom/overview.mdx +71 -0
  138. package/.docs/raw/docs/runtimes/google-adk/api.mdx +256 -0
  139. package/.docs/raw/docs/runtimes/google-adk/hooks.mdx +717 -0
  140. package/.docs/raw/docs/runtimes/google-adk/overview.mdx +69 -0
  141. package/.docs/raw/docs/runtimes/google-adk/quickstart.mdx +229 -0
  142. package/.docs/raw/docs/runtimes/langchain.mdx +533 -0
  143. package/.docs/raw/docs/runtimes/langgraph/generative-ui.mdx +305 -0
  144. package/.docs/raw/docs/runtimes/langgraph/interrupts.mdx +104 -0
  145. package/.docs/raw/docs/runtimes/langgraph/overview.mdx +84 -0
  146. package/.docs/raw/docs/runtimes/langgraph/quickstart.mdx +496 -0
  147. package/.docs/raw/docs/runtimes/langgraph/streaming.mdx +127 -0
  148. package/.docs/raw/docs/runtimes/langgraph/threads.mdx +113 -0
  149. package/.docs/raw/docs/runtimes/langgraph/tutorial/introduction.mdx +3 -3
  150. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-1.mdx +0 -23
  151. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +1 -1
  152. package/.docs/raw/docs/runtimes/opencode/hooks.mdx +191 -0
  153. package/.docs/raw/docs/runtimes/opencode/overview.mdx +48 -0
  154. package/.docs/raw/docs/runtimes/opencode/quickstart.mdx +119 -0
  155. package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +71 -203
  156. package/.docs/raw/docs/ui/accordion.mdx +1 -0
  157. package/.docs/raw/docs/ui/assistant-modal.mdx +1 -0
  158. package/.docs/raw/docs/ui/assistant-sidebar.mdx +1 -0
  159. package/.docs/raw/docs/ui/attachment.mdx +1 -0
  160. package/.docs/raw/docs/ui/badge.mdx +1 -0
  161. package/.docs/raw/docs/ui/composer-trigger-popover.mdx +1 -0
  162. package/.docs/raw/docs/ui/context-display.mdx +1 -0
  163. package/.docs/raw/docs/ui/diff-viewer.mdx +1 -0
  164. package/.docs/raw/docs/ui/directive-text.mdx +1 -0
  165. package/.docs/raw/docs/ui/file.mdx +1 -0
  166. package/.docs/raw/docs/ui/image.mdx +1 -0
  167. package/.docs/raw/docs/ui/markdown.mdx +2 -14
  168. package/.docs/raw/docs/ui/mermaid.mdx +1 -0
  169. package/.docs/raw/docs/ui/message-timing.mdx +3 -2
  170. package/.docs/raw/docs/ui/model-selector.mdx +1 -0
  171. package/.docs/raw/docs/ui/part-grouping.mdx +325 -313
  172. package/.docs/raw/docs/ui/quote.mdx +1 -0
  173. package/.docs/raw/docs/ui/reasoning.mdx +66 -33
  174. package/.docs/raw/docs/ui/scrollbar.mdx +1 -0
  175. package/.docs/raw/docs/ui/select.mdx +1 -0
  176. package/.docs/raw/docs/ui/sources.mdx +1 -0
  177. package/.docs/raw/docs/ui/streamdown.mdx +1 -0
  178. package/.docs/raw/docs/ui/syntax-highlighting.mdx +1 -0
  179. package/.docs/raw/docs/ui/tabs.mdx +1 -0
  180. package/.docs/raw/docs/ui/thread-list.mdx +17 -0
  181. package/.docs/raw/docs/ui/thread.mdx +56 -1
  182. package/.docs/raw/docs/ui/tool-fallback.mdx +1 -0
  183. package/.docs/raw/docs/ui/tool-group.mdx +39 -11
  184. package/.docs/raw/docs/ui/voice.mdx +1 -0
  185. package/.docs/raw/docs/utilities/heat-graph.mdx +1 -0
  186. package/.docs/raw/docs/utilities/react-o11y.mdx +278 -0
  187. package/.docs/raw/docs/utilities/tw-shimmer.mdx +1 -0
  188. package/package.json +3 -3
  189. package/src/tools/tests/path-traversal.test.ts +1 -1
  190. package/.docs/raw/docs/(docs)/guides/branching.mdx +0 -65
  191. package/.docs/raw/docs/(docs)/guides/chain-of-thought.mdx +0 -164
  192. package/.docs/raw/docs/(docs)/guides/editing.mdx +0 -66
  193. package/.docs/raw/docs/(docs)/guides/speech.mdx +0 -38
  194. package/.docs/raw/docs/runtimes/a2a/index.mdx +0 -298
  195. package/.docs/raw/docs/runtimes/assistant-transport.mdx +0 -1033
  196. package/.docs/raw/docs/runtimes/custom/custom-thread-list.mdx +0 -314
  197. package/.docs/raw/docs/runtimes/custom/local.mdx +0 -1464
  198. package/.docs/raw/docs/runtimes/data-stream.mdx +0 -422
  199. package/.docs/raw/docs/runtimes/google-adk/index.mdx +0 -686
  200. package/.docs/raw/docs/runtimes/helicone.mdx +0 -61
  201. package/.docs/raw/docs/runtimes/langchain/comparison.mdx +0 -60
  202. package/.docs/raw/docs/runtimes/langchain/index.mdx +0 -210
  203. package/.docs/raw/docs/runtimes/langgraph/index.mdx +0 -699
  204. package/.docs/raw/docs/runtimes/langgraph/tutorial/index.mdx +0 -12
  205. package/.docs/raw/docs/runtimes/langserve.mdx +0 -116
  206. package/.docs/raw/docs/runtimes/mastra/full-stack-integration.mdx +0 -218
  207. package/.docs/raw/docs/runtimes/mastra/overview.mdx +0 -18
  208. package/.docs/raw/docs/runtimes/mastra/separate-server-integration.mdx +0 -217
@@ -0,0 +1,428 @@
1
+ ---
2
+ title: Threads
3
+ description: Single-thread, cloud, and custom-database thread management.
4
+ ---
5
+
6
+ Every assistant-ui runtime starts with a single in-memory thread. Multi-thread support is added through one of three mechanisms depending on which runtime you are using and where you want threads to live.
7
+
8
+ ## Single thread (default)
9
+
10
+ With no thread configuration, the runtime renders one thread that resets when the page reloads. Fine for prototypes, demos, and stateless interactions.
11
+
12
+ If you only want session persistence (single thread, durable across reloads), provide a [history adapter](/docs/runtimes/concepts/adapters#history-adapter) instead of going to multi-thread.
13
+
14
+ ## Multi-thread paths
15
+
16
+ Three options. Choose based on what you want to own.
17
+
18
+ | Path | Runtime | Who owns thread metadata | Best for |
19
+ | --- | --- | --- | --- |
20
+ | AssistantCloud | LocalRuntime and adapters built on it | assistant-cloud | You want it managed; auth, sync, persistence handled |
21
+ | RemoteThreadListRuntime | LocalRuntime and adapters built on it | Your database | You have your own backend and want full control |
22
+ | ExternalStoreThreadListAdapter | ExternalStoreRuntime only | Your store | You keep state in redux, zustand, etc. |
23
+
24
+ ## AssistantCloud
25
+
26
+ `AssistantCloud` is the managed multi-thread service. Pass an instance to `useLocalRuntime` (or any adapter built on it) and threads, persistence, sync, and titles are handled for you.
27
+
28
+ ```tsx
29
+ import { useLocalRuntime } from "@assistant-ui/react";
30
+ import { AssistantCloud } from "assistant-cloud";
31
+
32
+ const cloud = new AssistantCloud({
33
+ baseUrl: process.env.NEXT_PUBLIC_ASSISTANT_BASE_URL,
34
+ anonymous: true,
35
+ });
36
+
37
+ const runtime = useLocalRuntime(modelAdapter, { cloud });
38
+ ```
39
+
40
+ Framework adapters take `cloud` directly:
41
+
42
+ ```tsx
43
+ const runtime = useChatRuntime({ cloud });
44
+ const runtime = useLangGraphRuntime({ cloud /* stream, load, ... */ });
45
+ const runtime = useAdkRuntime({ cloud, stream });
46
+ ```
47
+
48
+ See the [cloud documentation](/docs/cloud) for setup, auth, and self-host options.
49
+
50
+ ## RemoteThreadListRuntime (custom database)
51
+
52
+ `useRemoteThreadListRuntime` lets you back the thread list with any database while keeping the per-thread runtime simple. You provide a `RemoteThreadListAdapter` describing how to list, create, rename, archive, and delete threads.
53
+
54
+ Works with any `LocalRuntime`-based runtime, including framework adapters that build on it (`react-ai-sdk`, `react-google-adk`, `react-a2a`, `useDataStreamRuntime`).
55
+
56
+ ```tsx title="app/MyProvider.tsx"
57
+ "use client";
58
+
59
+ import {
60
+ AssistantRuntimeProvider,
61
+ useLocalRuntime,
62
+ useRemoteThreadListRuntime,
63
+ type RemoteThreadListAdapter,
64
+ } from "@assistant-ui/react";
65
+ import { createAssistantStream } from "assistant-stream";
66
+ import { modelAdapter } from "./model-adapter";
67
+
68
+ const adapter: RemoteThreadListAdapter = {
69
+ async list() {
70
+ const threads = await fetch("/api/threads").then((r) => r.json());
71
+ return {
72
+ threads: threads.map((t: any) => ({
73
+ status: t.archived ? "archived" : "regular",
74
+ remoteId: t.id,
75
+ title: t.title,
76
+ })),
77
+ };
78
+ },
79
+ async initialize(localId) {
80
+ const t = await fetch("/api/threads", {
81
+ method: "POST",
82
+ body: JSON.stringify({ localId }),
83
+ }).then((r) => r.json());
84
+ return { remoteId: t.id };
85
+ },
86
+ async rename(remoteId, title) {
87
+ await fetch(`/api/threads/${remoteId}`, {
88
+ method: "PATCH",
89
+ body: JSON.stringify({ title }),
90
+ });
91
+ },
92
+ async archive(remoteId) {
93
+ await fetch(`/api/threads/${remoteId}/archive`, { method: "POST" });
94
+ },
95
+ async unarchive(remoteId) {
96
+ await fetch(`/api/threads/${remoteId}/unarchive`, { method: "POST" });
97
+ },
98
+ async delete(remoteId) {
99
+ await fetch(`/api/threads/${remoteId}`, { method: "DELETE" });
100
+ },
101
+ async fetch(remoteId) {
102
+ const t = await fetch(`/api/threads/${remoteId}`).then((r) => r.json());
103
+ return {
104
+ status: t.archived ? "archived" : "regular",
105
+ remoteId: t.id,
106
+ title: t.title,
107
+ };
108
+ },
109
+ async generateTitle(remoteId, messages) {
110
+ return createAssistantStream(async (controller) => {
111
+ const { title } = await fetch(`/api/threads/${remoteId}/title`, {
112
+ method: "POST",
113
+ body: JSON.stringify({ messages }),
114
+ }).then((r) => r.json());
115
+ controller.appendText(title);
116
+ });
117
+ },
118
+ };
119
+
120
+ export function MyProvider({ children }: { children: React.ReactNode }) {
121
+ const runtime = useRemoteThreadListRuntime({
122
+ runtimeHook: () => useLocalRuntime(modelAdapter),
123
+ adapter,
124
+ });
125
+ return (
126
+ <AssistantRuntimeProvider runtime={runtime}>
127
+ {children}
128
+ </AssistantRuntimeProvider>
129
+ );
130
+ }
131
+ ```
132
+
133
+ ### Persisting messages with `unstable_Provider`
134
+
135
+ `RemoteThreadListAdapter` only manages thread metadata. To persist messages within each thread, expose a thread-scoped history adapter via the optional `unstable_Provider`:
136
+
137
+ ```tsx
138
+ import {
139
+ RuntimeAdapterProvider,
140
+ useAui,
141
+ type ThreadHistoryAdapter,
142
+ } from "@assistant-ui/react";
143
+ import { useMemo } from "react";
144
+
145
+ const adapterWithHistory: RemoteThreadListAdapter = {
146
+ // ...metadata methods above...
147
+ unstable_Provider({ children }) {
148
+ const aui = useAui();
149
+ const history = useMemo<ThreadHistoryAdapter>(
150
+ () => ({
151
+ async load() {
152
+ const { remoteId } = aui.threadListItem().getState();
153
+ if (!remoteId) return { messages: [] };
154
+ const rows = await fetch(
155
+ `/api/threads/${remoteId}/messages`,
156
+ ).then((r) => r.json());
157
+ return { messages: rows.map(toThreadMessage) };
158
+ },
159
+ async append({ message, parentId }) {
160
+ const { remoteId } = await aui.threadListItem().initialize();
161
+ await fetch(`/api/threads/${remoteId}/messages`, {
162
+ method: "POST",
163
+ body: JSON.stringify({ message, parentId }),
164
+ });
165
+ },
166
+ }),
167
+ [aui],
168
+ );
169
+ return (
170
+ <RuntimeAdapterProvider adapters={{ history }}>
171
+ {children}
172
+ </RuntimeAdapterProvider>
173
+ );
174
+ },
175
+ };
176
+ ```
177
+
178
+ <Callout type="warn">
179
+ `unstable_Provider` must render `children` synchronously on first commit. Do not gate `children` behind a loading state, suspense, or `useEffect`. If you need to load data before the thread is usable, do it inside an always-rendered child (for example via the history adapter), not by withholding `children`.
180
+ </Callout>
181
+
182
+ ### Avoiding the first-message race
183
+
184
+ `append` may be called before the thread record exists in your backend. Always await `aui.threadListItem().initialize()` before writing:
185
+
186
+ ```ts
187
+ async append({ message, parentId }) {
188
+ const { remoteId } = await aui.threadListItem().initialize();
189
+ await saveMessage(remoteId, parentId, message);
190
+ }
191
+ ```
192
+
193
+ `initialize()` is safe to call multiple times. It always resolves to the same `remoteId` for the active thread.
194
+
195
+ ### Reloading after async authentication
196
+
197
+ If your adapter depends on a user that resolves asynchronously (oidc, `next-auth`, `better-auth`), the initial `list()` may run before the user is available. Call `aui.threads().reload()` after auth completes:
198
+
199
+ ```tsx
200
+ function ReloadOnAuth() {
201
+ const aui = useAui();
202
+ const { isLoading, user } = useAuth();
203
+ useEffect(() => {
204
+ if (!isLoading && user) aui.threads().reload();
205
+ }, [isLoading, user?.id]);
206
+ return null;
207
+ }
208
+ ```
209
+
210
+ `reload()` discards in-flight responses from superseded calls, so it is safe to invoke on every auth transition.
211
+
212
+ ### Paginating the thread list
213
+
214
+ If your backend returns thread pages, return a `nextCursor` from `list()` and consume `aui.threads().hasMore` plus `aui.threads().loadMore()` in the UI. The runtime threads `params.after` back through `list()` on every `loadMore()`; the initial call passes no `params`, so treat a missing `after` as "first page". `reload()` resets the cursor so the next load starts from page 1 again.
215
+
216
+ ```ts title="threadListAdapter.ts (excerpt)"
217
+ async list({ after } = {}) {
218
+ const url = new URL("/api/threads", location.origin);
219
+ if (after) url.searchParams.set("after", after);
220
+ const response = await fetch(url);
221
+ const { threads, next_cursor } = await response.json();
222
+ return {
223
+ threads: threads.map((thread) => ({
224
+ remoteId: thread.id,
225
+ status: thread.is_archived ? "archived" : "regular",
226
+ title: thread.title ?? undefined,
227
+ })),
228
+ nextCursor: next_cursor ?? undefined,
229
+ };
230
+ },
231
+ ```
232
+
233
+ For a button-driven UI, drop `<ThreadListPrimitive.LoadMore>` at the bottom of your list. It ships disabled while the runtime is loading or when no `nextCursor` is available. To trigger it on scroll instead, wrap the same primitive in an `IntersectionObserver` at the application layer; assistant-ui leaves visibility-driven loading to userland by design.
234
+
235
+ ```tsx title="ThreadList.tsx"
236
+ import {
237
+ ThreadListPrimitive,
238
+ ThreadListItemPrimitive,
239
+ } from "@assistant-ui/react";
240
+
241
+ export function ThreadList() {
242
+ return (
243
+ <ThreadListPrimitive.Root>
244
+ <ThreadListPrimitive.Items>
245
+ {() => (
246
+ <ThreadListItemPrimitive.Root>
247
+ <ThreadListItemPrimitive.Trigger>
248
+ <ThreadListItemPrimitive.Title />
249
+ </ThreadListItemPrimitive.Trigger>
250
+ </ThreadListItemPrimitive.Root>
251
+ )}
252
+ </ThreadListPrimitive.Items>
253
+ <ThreadListPrimitive.LoadMore>Load more</ThreadListPrimitive.LoadMore>
254
+ </ThreadListPrimitive.Root>
255
+ );
256
+ }
257
+ ```
258
+
259
+ A few invariants worth knowing when wiring a custom UI on top of `loadMore()`:
260
+
261
+ - **Empty-string cursors collapse to "no more pages".** `nextCursor: ""` is treated the same as `nextCursor: undefined`, so an off-by-one in your backend that returns an empty cursor will not loop forever.
262
+ - **Concurrent `loadMore()` calls are deduped.** The runtime keeps a single in-flight promise per page, so calling `loadMore()` from a sentinel and a button at the same time issues only one network request.
263
+ - **Page errors are swallowed.** If `list({ after })` rejects, the cursor is preserved and the next `loadMore()` retries with the same `after` value. The promise returned to the caller resolves regardless. Surface adapter errors yourself if you need user-visible feedback.
264
+
265
+ ### Adapter contract
266
+
267
+ <ParametersTable
268
+ type="RemoteThreadListAdapter"
269
+ parameters={[
270
+ {
271
+ name: "list",
272
+ type: "(params?: { after?: string }) => Promise<{ threads: RemoteThreadMetadata[]; nextCursor?: string }>",
273
+ description:
274
+ "Hydrate threads on mount. Each thread must include status and remoteId; title, externalId, and custom are optional. Return a `nextCursor` to enable `aui.threads().loadMore()`; the runtime will pass it back as `params.after` on the next call.",
275
+ required: true,
276
+ },
277
+ {
278
+ name: "initialize",
279
+ type: "(localId: string) => Promise<{ remoteId: string; externalId?: string }>",
280
+ description:
281
+ "Create a new remote record when the user starts a conversation. Return the canonical ids.",
282
+ required: true,
283
+ },
284
+ {
285
+ name: "rename",
286
+ type: "(remoteId: string, title: string) => Promise<void>",
287
+ description: "Persist title changes from the UI.",
288
+ required: true,
289
+ },
290
+ {
291
+ name: "archive",
292
+ type: "(remoteId: string) => Promise<void>",
293
+ description: "Mark thread archived.",
294
+ required: true,
295
+ },
296
+ {
297
+ name: "unarchive",
298
+ type: "(remoteId: string) => Promise<void>",
299
+ description: "Restore an archived thread.",
300
+ required: true,
301
+ },
302
+ {
303
+ name: "delete",
304
+ type: "(remoteId: string) => Promise<void>",
305
+ description: "Permanently remove the thread.",
306
+ required: true,
307
+ },
308
+ {
309
+ name: "fetch",
310
+ type: "(threadId: string) => Promise<RemoteThreadMetadata>",
311
+ description: "Fetch metadata for a single thread when switching.",
312
+ required: true,
313
+ },
314
+ {
315
+ name: "generateTitle",
316
+ type: "(remoteId: string, messages: readonly ThreadMessage[]) => Promise<AssistantStream>",
317
+ description:
318
+ "Stream a title back. Use createAssistantStream and controller.appendText.",
319
+ required: true,
320
+ },
321
+ {
322
+ name: "unstable_Provider",
323
+ type: "ComponentType<PropsWithChildren>",
324
+ description:
325
+ "Optional wrapper rendered around each active thread. Inject thread-scoped adapters (history, attachments) here.",
326
+ },
327
+ ]}
328
+ />
329
+
330
+ ### Custom metadata
331
+
332
+ `RemoteThreadMetadata` includes an optional `custom?: Record<string, unknown>` slot for backend-specific fields (timestamps, owner ids, workspace ids, tags, model name). Whatever you return from `list()` and `fetch()` flows through to the thread list item state and is reachable from any UI primitive via `useAuiState`.
333
+
334
+ ```ts
335
+ type MyThreadMetadata = RemoteThreadMetadata & {
336
+ readonly custom: {
337
+ readonly createdAt: string;
338
+ readonly ownerId: string;
339
+ };
340
+ };
341
+ ```
342
+
343
+ ```tsx
344
+ import { useAuiState } from "@assistant-ui/react";
345
+
346
+ function ThreadListItemMeta() {
347
+ const custom = useAuiState(
348
+ (s) => s.threadListItem.custom as MyThreadMetadata["custom"] | undefined,
349
+ );
350
+ return (
351
+ <span>
352
+ {custom?.ownerId} · {custom?.createdAt}
353
+ </span>
354
+ );
355
+ }
356
+ ```
357
+
358
+ `custom` is preserved across `rename`, `archive`, `unarchive`, and `generateTitle`. To mutate it, return updated values from a subsequent `fetch()` or call `runtime.threads.reload()`.
359
+
360
+ ## ExternalStoreThreadListAdapter
361
+
362
+ For `ExternalStoreRuntime` users only. Wires multi-thread support into an external state store.
363
+
364
+ ```tsx
365
+ const threadListAdapter: ExternalStoreThreadListAdapter = {
366
+ threadId: currentThreadId,
367
+ threads: threadList.filter((t) => t.status === "regular"),
368
+ archivedThreads: threadList.filter((t) => t.status === "archived"),
369
+ onSwitchToNewThread: () => {
370
+ /* create + switch */
371
+ },
372
+ onSwitchToThread: (id) => setCurrentThreadId(id),
373
+ onRename: (id, title) => {
374
+ /* update */
375
+ },
376
+ onArchive: (id) => {
377
+ /* archive */
378
+ },
379
+ onUnarchive: (id) => {
380
+ /* unarchive */
381
+ },
382
+ onDelete: (id) => {
383
+ /* delete */
384
+ },
385
+ };
386
+
387
+ const runtime = useExternalStoreRuntime({
388
+ messages: threads.get(currentThreadId) ?? [],
389
+ setMessages: (messages) =>
390
+ setThreads((m) => new Map(m).set(currentThreadId, messages)),
391
+ onNew,
392
+ adapters: { threadList: threadListAdapter },
393
+ });
394
+ ```
395
+
396
+ Unlike `RemoteThreadListAdapter`, this adapter is synchronous and inline. You keep thread metadata and messages in your own store; the runtime just renders what you provide.
397
+
398
+ <Callout type="warn">
399
+ The runtime's `currentThreadId` and your store's selected thread must stay in sync. Mismatched thread ids cause messages to appear in the wrong thread or vanish entirely. Centralize thread id state in a context, never in component-local state.
400
+ </Callout>
401
+
402
+ ## Choosing
403
+
404
+ Ask three questions in order:
405
+
406
+ 1. **Do you want it managed?** Use `AssistantCloud`. You do not write database code.
407
+ 2. **Do you have your own backend?** Use `RemoteThreadListRuntime` if you are on `LocalRuntime` (or any adapter built on it). You implement the adapter, you own the data.
408
+ 3. **Are you on `ExternalStoreRuntime`?** Use `ExternalStoreThreadListAdapter`. Threads live in your store next to messages.
409
+
410
+ ## Related
411
+
412
+ <Cards>
413
+ <Card
414
+ title="Adapters"
415
+ description="The shared adapter contracts (attachments, history, speech, feedback)."
416
+ href="/docs/runtimes/concepts/adapters"
417
+ />
418
+ <Card
419
+ title="Architecture"
420
+ description="The three-layer runtime model and how threads flow through it."
421
+ href="/docs/runtimes/concepts/architecture"
422
+ />
423
+ <Card
424
+ title="AssistantCloud"
425
+ description="The managed multi-thread service."
426
+ href="/docs/cloud"
427
+ />
428
+ </Cards>