@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,712 @@
1
+ ---
2
+ title: Custom thread persistence
3
+ description: Persist threads and messages to your own database with RemoteThreadListAdapter and ThreadHistoryAdapter.
4
+ ---
5
+
6
+ When [AssistantCloud](/docs/cloud) doesn't fit (self-hosting, compliance, threads alongside existing app data), back the multi-thread runtime with your own database. This page is the worked example: schema, route handlers, and adapter wiring with Postgres + Drizzle. The shape is identical for any SQL or document store.
7
+
8
+ For the high-level adapter contract, see [threads](/docs/runtimes/concepts/threads). This page focuses on the storage layer and how `withFormat` round-trips AI SDK messages.
9
+
10
+ ## Prerequisites
11
+
12
+ The route handlers below import `auth` from `@/auth` and `db` from `@/db`. This guide assumes:
13
+
14
+ - A working [Drizzle setup](https://orm.drizzle.team/docs/get-started-postgresql) at `db/index.ts` exporting a `db` instance.
15
+ - An auth solution with a server-side `auth()` helper exposing `session.user.id`. See [Auth.js (next-auth)](/docs/integrations/auth/next-auth) for the canonical setup, including the callback that populates `session.user.id`.
16
+
17
+ If you're rolling your own auth, replace `auth()` calls with whatever your stack uses to resolve the current user.
18
+
19
+ ## How it works
20
+
21
+ ```
22
+ client ──► /api/threads/* (RemoteThreadListAdapter) ──► threads table
23
+ /api/messages/* (ThreadHistoryAdapter) ──► messages table
24
+ ```
25
+
26
+ Two adapters, two tables:
27
+
28
+ - **`RemoteThreadListAdapter`** owns thread *metadata*: list, create, rename, archive, delete.
29
+ - **`ThreadHistoryAdapter`** owns *messages* per thread. The `withFormat` variant is required by `useChatRuntime` and converts AI SDK `UIMessage` to and from a fixed row shape: `{ id, parent_id, format, content }`.
30
+
31
+ ## Schema
32
+
33
+ ```ts title="db/schema.ts"
34
+ import { pgTable, text, timestamp, jsonb, index } from "drizzle-orm/pg-core";
35
+
36
+ export const threads = pgTable(
37
+ "threads",
38
+ {
39
+ id: text("id").primaryKey(),
40
+ userId: text("user_id").notNull(),
41
+ title: text("title"),
42
+ status: text("status", { enum: ["regular", "archived"] })
43
+ .notNull()
44
+ .default("regular"),
45
+ custom: jsonb("custom").$type<Record<string, unknown>>(),
46
+ createdAt: timestamp("created_at").notNull().defaultNow(),
47
+ updatedAt: timestamp("updated_at").notNull().defaultNow(),
48
+ },
49
+ (t) => [index("threads_user_idx").on(t.userId)],
50
+ );
51
+
52
+ export const messages = pgTable(
53
+ "messages",
54
+ {
55
+ id: text("id").primaryKey(),
56
+ threadId: text("thread_id")
57
+ .notNull()
58
+ .references(() => threads.id, { onDelete: "cascade" }),
59
+ parentId: text("parent_id"),
60
+ format: text("format").notNull(),
61
+ content: jsonb("content").notNull(),
62
+ createdAt: timestamp("created_at").notNull().defaultNow(),
63
+ },
64
+ (t) => [index("messages_thread_idx").on(t.threadId)],
65
+ );
66
+ ```
67
+
68
+ The four message columns (`id`, `parent_id`, `format`, `content`) are the contract `withFormat` writes against. `format` lets multiple runtimes coexist on one row (e.g., `"aisdk-v6"` from `useChatRuntime`, a different value from another runtime).
69
+
70
+ ## Setup
71
+
72
+ <Steps>
73
+ <Step>
74
+
75
+ ### Install dependencies
76
+
77
+ <InstallCommand npm={["drizzle-orm", "postgres", "drizzle-kit"]} />
78
+
79
+ Configure Drizzle and run the migration. See the [Drizzle quickstart](https://orm.drizzle.team/docs/get-started-postgresql) for the full setup.
80
+
81
+ </Step>
82
+ <Step>
83
+
84
+ ### Build the thread list endpoints
85
+
86
+ Each method on `RemoteThreadListAdapter` maps to one route. Always scope by `userId` from the session so users see only their own threads.
87
+
88
+ ```ts title="app/api/threads/route.ts"
89
+ import { db } from "@/db";
90
+ import { threads } from "@/db/schema";
91
+ import { auth } from "@/auth";
92
+ import { and, desc, eq } from "drizzle-orm";
93
+ import { generateId } from "ai";
94
+
95
+ export async function GET() {
96
+ const session = await auth();
97
+ if (!session?.user) return new Response(null, { status: 401 });
98
+
99
+ const rows = await db
100
+ .select()
101
+ .from(threads)
102
+ .where(eq(threads.userId, session.user.id))
103
+ .orderBy(desc(threads.updatedAt));
104
+
105
+ return Response.json(rows);
106
+ }
107
+
108
+ export async function POST(req: Request) {
109
+ const session = await auth();
110
+ if (!session?.user) return new Response(null, { status: 401 });
111
+
112
+ const id = generateId();
113
+ await db.insert(threads).values({ id, userId: session.user.id });
114
+ return Response.json({ id });
115
+ }
116
+ ```
117
+
118
+ Implement the per-thread routes the same way under `app/api/threads/[id]/route.ts`. `PATCH` updates `title` or `status` (used by `rename`, `archive`, `unarchive`); `DELETE` deletes the thread; `GET` returns one thread (used by `fetch`). Always check `userId` on every handler:
119
+
120
+ ```ts title="app/api/threads/[id]/route.ts"
121
+ import { db } from "@/db";
122
+ import { threads } from "@/db/schema";
123
+ import { auth } from "@/auth";
124
+ import { and, eq } from "drizzle-orm";
125
+
126
+ export async function PATCH(
127
+ req: Request,
128
+ { params }: { params: Promise<{ id: string }> },
129
+ ) {
130
+ const { id } = await params;
131
+ const session = await auth();
132
+ if (!session?.user) return new Response(null, { status: 401 });
133
+
134
+ const patch = (await req.json()) as { title?: string; status?: "regular" | "archived" };
135
+ await db
136
+ .update(threads)
137
+ .set({ ...patch, updatedAt: new Date() })
138
+ .where(and(eq(threads.id, id), eq(threads.userId, session.user.id)));
139
+
140
+ return new Response(null, { status: 204 });
141
+ }
142
+ ```
143
+
144
+ A `POST /api/threads/[id]/title` endpoint that calls your model with the first few messages and returns `{ title }` completes the set. The shape mirrors the others; treat it as `streamText` plus a JSON response.
145
+
146
+ </Step>
147
+ <Step>
148
+
149
+ ### Build the message endpoints
150
+
151
+ Two routes: list messages for a thread and append one. Both check thread ownership before touching the messages table.
152
+
153
+ ```ts title="app/api/threads/[id]/messages/route.ts"
154
+ import { db } from "@/db";
155
+ import { threads, messages } from "@/db/schema";
156
+ import { auth } from "@/auth";
157
+ import { and, asc, eq } from "drizzle-orm";
158
+
159
+ export async function GET(
160
+ _req: Request,
161
+ { params }: { params: Promise<{ id: string }> },
162
+ ) {
163
+ const { id } = await params;
164
+ const session = await auth();
165
+ if (!session?.user) return new Response(null, { status: 401 });
166
+
167
+ const [thread] = await db
168
+ .select()
169
+ .from(threads)
170
+ .where(and(eq(threads.id, id), eq(threads.userId, session.user.id)));
171
+ if (!thread) return new Response(null, { status: 404 });
172
+
173
+ const rows = await db
174
+ .select()
175
+ .from(messages)
176
+ .where(eq(messages.threadId, id))
177
+ .orderBy(asc(messages.createdAt));
178
+
179
+ return Response.json(rows);
180
+ }
181
+
182
+ export async function POST(
183
+ req: Request,
184
+ { params }: { params: Promise<{ id: string }> },
185
+ ) {
186
+ const { id } = await params;
187
+ const session = await auth();
188
+ if (!session?.user) return new Response(null, { status: 401 });
189
+
190
+ const body = (await req.json()) as {
191
+ id: string;
192
+ parent_id: string | null;
193
+ format: string;
194
+ content: Record<string, unknown>;
195
+ };
196
+
197
+ await db.insert(messages).values({
198
+ id: body.id,
199
+ threadId: id,
200
+ parentId: body.parent_id,
201
+ format: body.format,
202
+ content: body.content,
203
+ });
204
+
205
+ return new Response(null, { status: 204 });
206
+ }
207
+ ```
208
+
209
+ </Step>
210
+ <Step>
211
+
212
+ ### Implement `RemoteThreadListAdapter`
213
+
214
+ The adapter calls your endpoints. `unstable_Provider` injects the per-thread history adapter so messages persist alongside metadata.
215
+
216
+ <PlatformTabs>
217
+ <Tab value="React">
218
+
219
+ ```tsx title="app/runtime/thread-adapter.tsx"
220
+ "use client";
221
+
222
+ import {
223
+ RuntimeAdapterProvider,
224
+ useAui,
225
+ type RemoteThreadListAdapter,
226
+ type ThreadHistoryAdapter,
227
+ } from "@assistant-ui/react";
228
+ import { createAssistantStream } from "assistant-stream";
229
+ import { useMemo } from "react";
230
+
231
+ export const threadListAdapter: RemoteThreadListAdapter = {
232
+ async list() {
233
+ const rows = await fetch("/api/threads").then((r) => r.json());
234
+ return {
235
+ threads: rows.map((t: any) => ({
236
+ status: t.status,
237
+ remoteId: t.id,
238
+ title: t.title ?? undefined,
239
+ })),
240
+ };
241
+ },
242
+ async initialize() {
243
+ const { id } = await fetch("/api/threads", { method: "POST" }).then((r) =>
244
+ r.json(),
245
+ );
246
+ return { remoteId: id };
247
+ },
248
+ async rename(remoteId, title) {
249
+ await fetch(`/api/threads/${remoteId}`, {
250
+ method: "PATCH",
251
+ body: JSON.stringify({ title }),
252
+ });
253
+ },
254
+ async archive(remoteId) {
255
+ await fetch(`/api/threads/${remoteId}`, {
256
+ method: "PATCH",
257
+ body: JSON.stringify({ status: "archived" }),
258
+ });
259
+ },
260
+ async unarchive(remoteId) {
261
+ await fetch(`/api/threads/${remoteId}`, {
262
+ method: "PATCH",
263
+ body: JSON.stringify({ status: "regular" }),
264
+ });
265
+ },
266
+ async delete(remoteId) {
267
+ await fetch(`/api/threads/${remoteId}`, { method: "DELETE" });
268
+ },
269
+ async fetch(remoteId) {
270
+ const t = await fetch(`/api/threads/${remoteId}`).then((r) => r.json());
271
+ return { status: t.status, remoteId: t.id, title: t.title };
272
+ },
273
+ async generateTitle(remoteId, messages) {
274
+ return createAssistantStream(async (controller) => {
275
+ const { title } = await fetch(`/api/threads/${remoteId}/title`, {
276
+ method: "POST",
277
+ body: JSON.stringify({ messages }),
278
+ }).then((r) => r.json());
279
+ controller.appendText(title);
280
+ });
281
+ },
282
+ unstable_Provider({ children }) {
283
+ const aui = useAui();
284
+ const history = useMemo<ThreadHistoryAdapter>(
285
+ () => ({
286
+ async load() {
287
+ return { messages: [] };
288
+ },
289
+ async append() {},
290
+ withFormat: (fmt) => ({
291
+ async load() {
292
+ const { remoteId } = aui.threadListItem().getState();
293
+ if (!remoteId) return { messages: [] };
294
+ const rows = await fetch(
295
+ `/api/threads/${remoteId}/messages`,
296
+ ).then((r) => r.json());
297
+ return {
298
+ messages: rows.map((row: any) =>
299
+ fmt.decode({
300
+ id: row.id,
301
+ parent_id: row.parent_id,
302
+ format: row.format,
303
+ content: row.content,
304
+ }),
305
+ ),
306
+ };
307
+ },
308
+ async append(item) {
309
+ const { remoteId } = await aui.threadListItem().initialize();
310
+ await fetch(`/api/threads/${remoteId}/messages`, {
311
+ method: "POST",
312
+ body: JSON.stringify({
313
+ id: fmt.getId(item.message),
314
+ parent_id: item.parentId,
315
+ format: fmt.format,
316
+ content: fmt.encode(item),
317
+ }),
318
+ });
319
+ },
320
+ }),
321
+ }),
322
+ [aui],
323
+ );
324
+ return (
325
+ <RuntimeAdapterProvider adapters={{ history }}>
326
+ {children}
327
+ </RuntimeAdapterProvider>
328
+ );
329
+ },
330
+ };
331
+ ```
332
+
333
+ </Tab>
334
+ <Tab value="React Native">
335
+
336
+ ```tsx title="runtime/thread-adapter.tsx"
337
+ import {
338
+ RuntimeAdapterProvider,
339
+ useAui,
340
+ type RemoteThreadListAdapter,
341
+ type ThreadHistoryAdapter,
342
+ } from "@assistant-ui/react-native";
343
+ import { createAssistantStream } from "assistant-stream";
344
+ import { useMemo } from "react";
345
+
346
+ export const threadListAdapter: RemoteThreadListAdapter = {
347
+ async list() {
348
+ const rows = await fetch(`${API_URL}/threads`).then((r) => r.json());
349
+ return {
350
+ threads: rows.map((t: any) => ({
351
+ status: t.status,
352
+ remoteId: t.id,
353
+ title: t.title ?? undefined,
354
+ })),
355
+ };
356
+ },
357
+ async initialize() {
358
+ const { id } = await fetch(`${API_URL}/threads`, { method: "POST" }).then(
359
+ (r) => r.json(),
360
+ );
361
+ return { remoteId: id };
362
+ },
363
+ async rename(remoteId, title) {
364
+ await fetch(`${API_URL}/threads/${remoteId}`, {
365
+ method: "PATCH",
366
+ body: JSON.stringify({ title }),
367
+ });
368
+ },
369
+ async archive(remoteId) {
370
+ await fetch(`${API_URL}/threads/${remoteId}`, {
371
+ method: "PATCH",
372
+ body: JSON.stringify({ status: "archived" }),
373
+ });
374
+ },
375
+ async unarchive(remoteId) {
376
+ await fetch(`${API_URL}/threads/${remoteId}`, {
377
+ method: "PATCH",
378
+ body: JSON.stringify({ status: "regular" }),
379
+ });
380
+ },
381
+ async delete(remoteId) {
382
+ await fetch(`${API_URL}/threads/${remoteId}`, { method: "DELETE" });
383
+ },
384
+ async fetch(remoteId) {
385
+ const t = await fetch(`${API_URL}/threads/${remoteId}`).then((r) =>
386
+ r.json(),
387
+ );
388
+ return { status: t.status, remoteId: t.id, title: t.title };
389
+ },
390
+ async generateTitle(remoteId, messages) {
391
+ return createAssistantStream(async (controller) => {
392
+ const { title } = await fetch(`${API_URL}/threads/${remoteId}/title`, {
393
+ method: "POST",
394
+ body: JSON.stringify({ messages }),
395
+ }).then((r) => r.json());
396
+ controller.appendText(title);
397
+ });
398
+ },
399
+ unstable_Provider({ children }) {
400
+ const aui = useAui();
401
+ const history = useMemo<ThreadHistoryAdapter>(
402
+ () => ({
403
+ async load() {
404
+ return { messages: [] };
405
+ },
406
+ async append() {},
407
+ withFormat: (fmt) => ({
408
+ async load() {
409
+ const { remoteId } = aui.threadListItem().getState();
410
+ if (!remoteId) return { messages: [] };
411
+ const rows = await fetch(
412
+ `${API_URL}/threads/${remoteId}/messages`,
413
+ ).then((r) => r.json());
414
+ return {
415
+ messages: rows.map((row: any) =>
416
+ fmt.decode({
417
+ id: row.id,
418
+ parent_id: row.parent_id,
419
+ format: row.format,
420
+ content: row.content,
421
+ }),
422
+ ),
423
+ };
424
+ },
425
+ async append(item) {
426
+ const { remoteId } = await aui.threadListItem().initialize();
427
+ await fetch(`${API_URL}/threads/${remoteId}/messages`, {
428
+ method: "POST",
429
+ body: JSON.stringify({
430
+ id: fmt.getId(item.message),
431
+ parent_id: item.parentId,
432
+ format: fmt.format,
433
+ content: fmt.encode(item),
434
+ }),
435
+ });
436
+ },
437
+ }),
438
+ }),
439
+ [aui],
440
+ );
441
+ return (
442
+ <RuntimeAdapterProvider adapters={{ history }}>
443
+ {children}
444
+ </RuntimeAdapterProvider>
445
+ );
446
+ },
447
+ };
448
+ ```
449
+
450
+ `API_URL` points at the backend that hosts the route handlers above (e.g. `https://your-app.example`). Set it from your env. `fetch` is global on React Native; no polyfill required.
451
+
452
+ </Tab>
453
+ <Tab value="React Ink">
454
+
455
+ ```tsx title="runtime/thread-adapter.tsx"
456
+ import {
457
+ RuntimeAdapterProvider,
458
+ useAui,
459
+ type RemoteThreadListAdapter,
460
+ type ThreadHistoryAdapter,
461
+ } from "@assistant-ui/react-ink";
462
+ import { createAssistantStream } from "assistant-stream";
463
+ import { useMemo } from "react";
464
+
465
+ export const threadListAdapter: RemoteThreadListAdapter = {
466
+ async list() {
467
+ const rows = await fetch(`${API_URL}/threads`).then((r) => r.json());
468
+ return {
469
+ threads: rows.map((t: any) => ({
470
+ status: t.status,
471
+ remoteId: t.id,
472
+ title: t.title ?? undefined,
473
+ })),
474
+ };
475
+ },
476
+ async initialize() {
477
+ const { id } = await fetch(`${API_URL}/threads`, { method: "POST" }).then(
478
+ (r) => r.json(),
479
+ );
480
+ return { remoteId: id };
481
+ },
482
+ async rename(remoteId, title) {
483
+ await fetch(`${API_URL}/threads/${remoteId}`, {
484
+ method: "PATCH",
485
+ body: JSON.stringify({ title }),
486
+ });
487
+ },
488
+ async archive(remoteId) {
489
+ await fetch(`${API_URL}/threads/${remoteId}`, {
490
+ method: "PATCH",
491
+ body: JSON.stringify({ status: "archived" }),
492
+ });
493
+ },
494
+ async unarchive(remoteId) {
495
+ await fetch(`${API_URL}/threads/${remoteId}`, {
496
+ method: "PATCH",
497
+ body: JSON.stringify({ status: "regular" }),
498
+ });
499
+ },
500
+ async delete(remoteId) {
501
+ await fetch(`${API_URL}/threads/${remoteId}`, { method: "DELETE" });
502
+ },
503
+ async fetch(remoteId) {
504
+ const t = await fetch(`${API_URL}/threads/${remoteId}`).then((r) =>
505
+ r.json(),
506
+ );
507
+ return { status: t.status, remoteId: t.id, title: t.title };
508
+ },
509
+ async generateTitle(remoteId, messages) {
510
+ return createAssistantStream(async (controller) => {
511
+ const { title } = await fetch(`${API_URL}/threads/${remoteId}/title`, {
512
+ method: "POST",
513
+ body: JSON.stringify({ messages }),
514
+ }).then((r) => r.json());
515
+ controller.appendText(title);
516
+ });
517
+ },
518
+ unstable_Provider({ children }) {
519
+ const aui = useAui();
520
+ const history = useMemo<ThreadHistoryAdapter>(
521
+ () => ({
522
+ async load() {
523
+ return { messages: [] };
524
+ },
525
+ async append() {},
526
+ withFormat: (fmt) => ({
527
+ async load() {
528
+ const { remoteId } = aui.threadListItem().getState();
529
+ if (!remoteId) return { messages: [] };
530
+ const rows = await fetch(
531
+ `${API_URL}/threads/${remoteId}/messages`,
532
+ ).then((r) => r.json());
533
+ return {
534
+ messages: rows.map((row: any) =>
535
+ fmt.decode({
536
+ id: row.id,
537
+ parent_id: row.parent_id,
538
+ format: row.format,
539
+ content: row.content,
540
+ }),
541
+ ),
542
+ };
543
+ },
544
+ async append(item) {
545
+ const { remoteId } = await aui.threadListItem().initialize();
546
+ await fetch(`${API_URL}/threads/${remoteId}/messages`, {
547
+ method: "POST",
548
+ body: JSON.stringify({
549
+ id: fmt.getId(item.message),
550
+ parent_id: item.parentId,
551
+ format: fmt.format,
552
+ content: fmt.encode(item),
553
+ }),
554
+ });
555
+ },
556
+ }),
557
+ }),
558
+ [aui],
559
+ );
560
+ return (
561
+ <RuntimeAdapterProvider adapters={{ history }}>
562
+ {children}
563
+ </RuntimeAdapterProvider>
564
+ );
565
+ },
566
+ };
567
+ ```
568
+
569
+ `API_URL` points at the backend that hosts the route handlers above. Node 20+ exposes `fetch` globally; no extra dependency needed.
570
+
571
+ </Tab>
572
+ </PlatformTabs>
573
+
574
+ The top-level `load`/`append` on the history adapter are required by the type but unused by `useChatRuntime`. The AI SDK code path always goes through `withFormat`.
575
+
576
+ </Step>
577
+ <Step>
578
+
579
+ ### Mount the runtime
580
+
581
+ Wrap the app in a `useRemoteThreadListRuntime` that delegates per-thread runtime to `useChatRuntime`:
582
+
583
+ <PlatformTabs>
584
+ <Tab value="React">
585
+
586
+ ```tsx title="app/runtime/MyProvider.tsx"
587
+ "use client";
588
+
589
+ import {
590
+ AssistantRuntimeProvider,
591
+ useRemoteThreadListRuntime,
592
+ } from "@assistant-ui/react";
593
+ import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
594
+ import { threadListAdapter } from "./thread-adapter";
595
+
596
+ export function MyProvider({ children }: { children: React.ReactNode }) {
597
+ const runtime = useRemoteThreadListRuntime({
598
+ runtimeHook: () => useChatRuntime(),
599
+ adapter: threadListAdapter,
600
+ });
601
+ return (
602
+ <AssistantRuntimeProvider runtime={runtime}>
603
+ {children}
604
+ </AssistantRuntimeProvider>
605
+ );
606
+ }
607
+ ```
608
+
609
+ </Tab>
610
+ <Tab value="React Native">
611
+
612
+ ```tsx title="runtime/MyProvider.tsx"
613
+ import {
614
+ AssistantRuntimeProvider,
615
+ useRemoteThreadListRuntime,
616
+ } from "@assistant-ui/react-native";
617
+ import {
618
+ AssistantChatTransport,
619
+ useChatRuntime,
620
+ } from "@assistant-ui/react-ai-sdk";
621
+ import { threadListAdapter } from "./thread-adapter";
622
+
623
+ export function MyProvider({ children }: { children: React.ReactNode }) {
624
+ const runtime = useRemoteThreadListRuntime({
625
+ runtimeHook: () =>
626
+ useChatRuntime({
627
+ transport: new AssistantChatTransport({ api: `${API_URL}/chat` }),
628
+ }),
629
+ adapter: threadListAdapter,
630
+ });
631
+ return (
632
+ <AssistantRuntimeProvider runtime={runtime}>
633
+ {children}
634
+ </AssistantRuntimeProvider>
635
+ );
636
+ }
637
+ ```
638
+
639
+ </Tab>
640
+ <Tab value="React Ink">
641
+
642
+ ```tsx title="runtime/MyProvider.tsx"
643
+ import {
644
+ AssistantRuntimeProvider,
645
+ useRemoteThreadListRuntime,
646
+ } from "@assistant-ui/react-ink";
647
+ import {
648
+ AssistantChatTransport,
649
+ useChatRuntime,
650
+ } from "@assistant-ui/react-ai-sdk";
651
+ import { threadListAdapter } from "./thread-adapter";
652
+
653
+ export function MyProvider({ children }: { children: React.ReactNode }) {
654
+ const runtime = useRemoteThreadListRuntime({
655
+ runtimeHook: () =>
656
+ useChatRuntime({
657
+ transport: new AssistantChatTransport({ api: `${API_URL}/chat` }),
658
+ }),
659
+ adapter: threadListAdapter,
660
+ });
661
+ return (
662
+ <AssistantRuntimeProvider runtime={runtime}>
663
+ {children}
664
+ </AssistantRuntimeProvider>
665
+ );
666
+ }
667
+ ```
668
+
669
+ </Tab>
670
+ </PlatformTabs>
671
+
672
+ </Step>
673
+ <Step>
674
+
675
+ ### Run and verify
676
+
677
+ Send a message in a fresh thread. Check the database:
678
+
679
+ - The `threads` table has a new row with the current `userId`.
680
+ - The `messages` table has at least two rows (user + assistant) for that thread.
681
+ - `format` is `"aisdk-v6"` (or whatever AI SDK's current format string is).
682
+ - Reload the page; the thread list and the messages survive.
683
+
684
+ </Step>
685
+ </Steps>
686
+
687
+ ## Notes
688
+
689
+ - **First-message race.** `append` may fire before the thread row exists. The `unstable_Provider` example above always awaits `aui.threadListItem().initialize()` before writing; do the same in any custom implementation.
690
+ - **Reload after async auth.** If `auth()` resolves after the initial `list()` call, threads won't appear until the user refreshes. Call `aui.threads().reload()` from a `useEffect` watching the session. Pattern is documented in [threads](/docs/runtimes/concepts/threads#reloading-after-async-authentication).
691
+ - **Format string.** The `format` column is *not* a free-text label; it identifies the on-disk shape so multiple runtimes can coexist. Don't strip it. Don't make assumptions about its value (`useChatRuntime` is responsible for setting and decoding it).
692
+ - **`unstable_Provider` synchronous-children rule.** The Provider must render `children` on first commit; do not gate them behind suspense, loading state, or `useEffect`. Load data inside an always-rendered child.
693
+
694
+ ## Related
695
+
696
+ <Cards>
697
+ <Card
698
+ title="Threads (concepts)"
699
+ description="Adapter contract, custom metadata, and ExternalStoreThreadListAdapter."
700
+ href="/docs/runtimes/concepts/threads"
701
+ />
702
+ <Card
703
+ title="Adapters"
704
+ description="The other adapter slots (history, attachments, speech, feedback)."
705
+ href="/docs/runtimes/concepts/adapters"
706
+ />
707
+ <Card
708
+ title="AssistantCloud"
709
+ description="The managed alternative if you don't need to own the data."
710
+ href="/docs/cloud"
711
+ />
712
+ </Cards>