@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,113 @@
1
+ ---
2
+ title: Threads
3
+ description: Basic thread support, AssistantCloud, and custom thread list adapter.
4
+ ---
5
+
6
+ `useLangGraphRuntime` supports the same three-path thread model documented in [threads](/docs/runtimes/concepts/threads), tailored for LangGraph thread ids. This page covers the LangGraph-specific wiring.
7
+
8
+ ## Basic thread support
9
+
10
+ `useLangGraphRuntime` includes built-in thread management:
11
+
12
+ ```ts
13
+ const runtime = useLangGraphRuntime({
14
+ stream: async (messages, { initialize, ...config }) => {
15
+ // initialize() creates or loads a thread and returns its IDs
16
+ const { remoteId, externalId } = await initialize();
17
+ // Use externalId (your backend's thread ID) for API calls
18
+ return sendMessage({ threadId: externalId, messages, config });
19
+ },
20
+ create: async () => {
21
+ // Called when creating a new thread
22
+ const { thread_id } = await createThread();
23
+ return { externalId: thread_id };
24
+ },
25
+ load: async (externalId) => {
26
+ // Called when loading an existing thread
27
+ const state = await getThreadState(externalId);
28
+ return {
29
+ messages: state.values.messages,
30
+ interrupts: state.tasks[0]?.interrupts,
31
+ };
32
+ },
33
+ });
34
+ ```
35
+
36
+ ## Cloud persistence
37
+
38
+ For managed multi-thread support, persistence, sync, and titles, pass an `AssistantCloud` instance:
39
+
40
+ ```ts
41
+ const runtime = useLangGraphRuntime({
42
+ cloud, // see "AssistantCloud" in /docs/runtimes/concepts/threads
43
+ // ... stream, create, load functions
44
+ });
45
+ ```
46
+
47
+ See the [cloud persistence guide](/docs/cloud/langgraph) for setup details.
48
+
49
+ ## Custom thread list
50
+
51
+ To surface pre-existing LangGraph `thread_id`s in the thread picker without running assistant-cloud, pass a `RemoteThreadListAdapter` via `unstable_threadListAdapter`. A common implementation backs `list()` with `client.threads.search()` and `initialize()` with `client.threads.create()`.
52
+
53
+ ```ts
54
+ import type { RemoteThreadListAdapter } from "@assistant-ui/react";
55
+ import { Client } from "@langchain/langgraph-sdk";
56
+
57
+ const client = new Client({
58
+ apiUrl: process.env.NEXT_PUBLIC_LANGGRAPH_API_URL,
59
+ });
60
+
61
+ const threadListAdapter: RemoteThreadListAdapter = {
62
+ async list() {
63
+ const threads = await client.threads.search({ limit: 50 });
64
+ return {
65
+ threads: threads.map((t) => ({
66
+ status: "regular",
67
+ remoteId: t.thread_id,
68
+ externalId: t.thread_id,
69
+ title: (t.metadata as { title?: string } | undefined)?.title,
70
+ })),
71
+ };
72
+ },
73
+ async initialize() {
74
+ const t = await client.threads.create();
75
+ return { remoteId: t.thread_id, externalId: t.thread_id };
76
+ },
77
+ async delete(remoteId) {
78
+ await client.threads.delete(remoteId);
79
+ },
80
+ // rename, archive, unarchive, fetch, generateTitle — see the threads concept page
81
+ };
82
+
83
+ const runtime = useLangGraphRuntime({
84
+ stream: async function* (messages, { initialize }) {
85
+ /* ... */
86
+ },
87
+ load: async (externalId) => {
88
+ /* ... */
89
+ },
90
+ unstable_threadListAdapter: threadListAdapter,
91
+ });
92
+ ```
93
+
94
+ Setting `remoteId === externalId` keeps the ids assistant-ui stores aligned with the LangGraph thread ids your `load` and `stream` callbacks receive. See [threads](/docs/runtimes/concepts/threads) for the full adapter contract.
95
+
96
+ <Callout type="info">
97
+ When `unstable_threadListAdapter` is provided, the `cloud`, `create`, and `delete` options are ignored; the adapter owns the full thread-list lifecycle.
98
+ </Callout>
99
+
100
+ ## Next
101
+
102
+ <Cards>
103
+ <Card
104
+ title="Streaming"
105
+ description="Event handlers, message metadata, generative UI."
106
+ href="/docs/runtimes/langgraph/streaming"
107
+ />
108
+ <Card
109
+ title="Threads (concept)"
110
+ description="General multi-thread model across runtimes."
111
+ href="/docs/runtimes/concepts/threads"
112
+ />
113
+ </Cards>
@@ -1,5 +1,5 @@
1
1
  ---
2
- title: "Introduction"
2
+ title: Introduction
3
3
  description: Build a stockbroker assistant with LangGraph and assistant-ui.
4
4
  ---
5
5
 
@@ -19,11 +19,11 @@ This agent leverages the following features:
19
19
 
20
20
  - Node.js 24 or higher
21
21
 
22
- ## Final Result
22
+ ## Final result
23
23
 
24
24
  - Demo: https://assistant-ui-stockbroker.vercel.app/
25
25
  - Source Code: https://github.com/assistant-ui/assistant-ui-stockbroker
26
26
 
27
- ## Get Started
27
+ ## Get started
28
28
 
29
29
  Begin Part 1 of the tutorial by [setting up the frontend](/docs/runtimes/langgraph/tutorial/part-1).
@@ -91,26 +91,3 @@ This means you'll see tokens appear smoothly as they're generated by the LLM, wi
91
91
 
92
92
  Rich text rendering using Markdown is enabled by default.
93
93
 
94
- ## Add conversation starter messages
95
-
96
- In order to help users understand what the assistant can do, we can add some conversation starter messages.
97
-
98
- import Image from "next/image";
99
- import starter from "./images/conversation-starters.png";
100
-
101
- <Image
102
- src={starter}
103
- alt="Conversation starters"
104
- width={600}
105
- className="mx-auto rounded-lg border shadow"
106
- />
107
-
108
- ```tsx title="@/app/page.tsx"
109
- export default function Home() {
110
- return (
111
- <div className="flex h-full flex-col">
112
- <Thread />
113
- </div>
114
- );
115
- }
116
- ```
@@ -17,7 +17,7 @@ import price from "./images/acme-price.png";
17
17
  className="mx-auto rounded-lg border shadow"
18
18
  />
19
19
 
20
- For reference, this the corresponding code in the backend:
20
+ For reference, this is the corresponding code in the backend:
21
21
 
22
22
  https://github.com/assistant-ui/assistant-ui-stockbroker/blob/main/backend/src/tools.ts#L193C1-L216C3
23
23
 
@@ -0,0 +1,191 @@
1
+ ---
2
+ title: Hooks
3
+ description: Permissions, questions, session state, runtime extras.
4
+ ---
5
+
6
+ import { OpenCodeIcon } from "@/components/icons/opencode";
7
+
8
+ OpenCode-specific React hooks for interacting with the running session. All hooks must be used inside the runtime context (a tree wrapped in `AssistantRuntimeProvider` from a `useOpenCodeRuntime` setup).
9
+
10
+ ## Permissions
11
+
12
+ OpenCode pauses tool execution to ask the user for permission (e.g. running shell commands, writing files). `useOpenCodePermissions` returns the pending permission requests and a reply function:
13
+
14
+ ```tsx
15
+ import { useOpenCodePermissions } from "@assistant-ui/react-opencode";
16
+
17
+ function PermissionPrompt() {
18
+ const { pending, reply } = useOpenCodePermissions();
19
+
20
+ return pending.map((req) => (
21
+ <div key={req.id}>
22
+ <p>
23
+ Allow <code>{req.toolName}</code>: {req.title ?? req.permission}?
24
+ </p>
25
+ <button onClick={() => reply(req.id, "once")}>Allow once</button>
26
+ <button onClick={() => reply(req.id, "always")}>Always allow</button>
27
+ <button onClick={() => reply(req.id, "reject")}>Reject</button>
28
+ </div>
29
+ ));
30
+ }
31
+ ```
32
+
33
+ Return shape:
34
+
35
+ | Field | Type | Description |
36
+ | --- | --- | --- |
37
+ | `pending` | `OpenCodePermissionRequest[]` | Permission requests waiting for a reply. |
38
+ | `reply` | `(id, response) => Promise<void>` | Send a reply for a pending permission. |
39
+
40
+ Reply values:
41
+
42
+ | Reply | Meaning |
43
+ | --- | --- |
44
+ | `"once"` | Approve this single permission request. |
45
+ | `"always"` | Approve this permission and remember the choice. |
46
+ | `"reject"` | Deny the permission; the tool call is cancelled. |
47
+
48
+ ## Questions
49
+
50
+ OpenCode can ask interactive questions during a run. `useOpenCodeQuestions` returns the pending questions as an array:
51
+
52
+ ```tsx
53
+ import {
54
+ useOpenCodeQuestions,
55
+ useOpenCodeRuntimeExtras,
56
+ } from "@assistant-ui/react-opencode";
57
+
58
+ function QuestionPrompt() {
59
+ const questions = useOpenCodeQuestions();
60
+ const { replyToQuestion, rejectQuestion } = useOpenCodeRuntimeExtras();
61
+
62
+ return questions.map((req) => (
63
+ <div key={req.id}>
64
+ <p>{req.text}</p>
65
+ <button
66
+ onClick={() =>
67
+ replyToQuestion(req.id, [
68
+ /* QuestionAnswer[] from @opencode-ai/sdk */
69
+ ])
70
+ }
71
+ >
72
+ Answer
73
+ </button>
74
+ <button onClick={() => rejectQuestion(req.id)}>Skip</button>
75
+ </div>
76
+ ));
77
+ }
78
+ ```
79
+
80
+ To reply, use `replyToQuestion(id, answers)` or `rejectQuestion(id)` from [`useOpenCodeRuntimeExtras`](#runtime-extras).
81
+
82
+ ## Session
83
+
84
+ `useOpenCodeSession` returns the current OpenCode `Session` object (server-side session metadata):
85
+
86
+ ```tsx
87
+ import { useOpenCodeSession } from "@assistant-ui/react-opencode";
88
+
89
+ function SessionInfo() {
90
+ const session = useOpenCodeSession();
91
+ if (!session) return null;
92
+ return <div>Session: {session.id}</div>;
93
+ }
94
+ ```
95
+
96
+ ## Thread state
97
+
98
+ `useOpenCodeThreadState` returns the full projected thread state (messages, run state, interactions, sync metadata). Use it for advanced custom views; most apps don't need it.
99
+
100
+ ```tsx
101
+ import { useOpenCodeThreadState } from "@assistant-ui/react-opencode";
102
+
103
+ function RunStatus() {
104
+ const state = useOpenCodeThreadState();
105
+ return <div>Run: {state.runState.type}</div>;
106
+ }
107
+ ```
108
+
109
+ The returned `OpenCodeThreadState` includes:
110
+
111
+ - `sessionId`, `session`, `sessionStatus`, `loadState`, `runState`
112
+ - `messageOrder`, `messagesById`, `pendingUserMessages`
113
+ - `interactions.permissions` (pending + resolved), `interactions.questions` (pending + answered + rejected)
114
+ - `unhandledEvents`, `sync` timestamps
115
+
116
+ You can also pass a selector to read a specific slice:
117
+
118
+ ```tsx
119
+ const isStreaming = useOpenCodeThreadState((s) => s.runState.type === "streaming");
120
+ ```
121
+
122
+ ## Runtime extras
123
+
124
+ `useOpenCodeRuntimeExtras` exposes session-level imperative actions:
125
+
126
+ ```tsx
127
+ import { useOpenCodeRuntimeExtras } from "@assistant-ui/react-opencode";
128
+
129
+ function SessionActions() {
130
+ const {
131
+ fork,
132
+ revert,
133
+ unrevert,
134
+ cancel,
135
+ refresh,
136
+ replyToPermission,
137
+ replyToQuestion,
138
+ rejectQuestion,
139
+ } = useOpenCodeRuntimeExtras();
140
+ // ...
141
+ }
142
+ ```
143
+
144
+ | Action | Description |
145
+ | --- | --- |
146
+ | `fork(messageId)` | Create a new session forked from the given message; returns the new session id. |
147
+ | `revert(messageId)` | Revert the session to the state at the given message. |
148
+ | `unrevert()` | Undo the last revert. |
149
+ | `cancel()` | Cancel an in-flight run. |
150
+ | `refresh()` | Force re-fetch of session messages. |
151
+ | `replyToPermission(id, response)` | Reply to a permission request (`"once"`, `"always"`, `"reject"`). |
152
+ | `replyToQuestion(id, answers)` | Answer a pending question. |
153
+ | `rejectQuestion(id)` | Reject a pending question. |
154
+
155
+ `useOpenCodePermissions` and `useOpenCodeQuestions` are sugar over `replyToPermission` / `replyToQuestion` / `rejectQuestion` plus the `pending` slices of state.
156
+
157
+ ## Lower-level building blocks
158
+
159
+ For custom integrations that bypass `useOpenCodeRuntime`:
160
+
161
+ | Export | Purpose |
162
+ | --- | --- |
163
+ | `OpenCodeEventSource` | Wraps the OpenCode server's event stream into a typed subscription. |
164
+ | `OpenCodeThreadController` | Per-session controller managing message state. |
165
+ | `createOpenCodeThreadState`, `reduceOpenCodeThreadState` | Pure state reducers if you want to drive the state machine yourself. |
166
+ | `projectOpenCodeThreadMessages` | Project raw OpenCode messages into assistant-ui thread messages. |
167
+ | `createOpencodeClient` (re-exported from `@opencode-ai/sdk`) | Build a client with custom config. |
168
+
169
+ These are only needed for advanced cases; most apps should use `useOpenCodeRuntime` directly.
170
+
171
+ ## Related
172
+
173
+ <Cards>
174
+ <Card
175
+ icon={<OpenCodeIcon width={20} height={20} />}
176
+ title="OpenCode overview"
177
+ description="What OpenCode is and when to pick it."
178
+ href="/docs/runtimes/opencode"
179
+ />
180
+ <Card
181
+ title="Quickstart"
182
+ description="Minimal runtime + Thread setup."
183
+ href="/docs/runtimes/opencode/quickstart"
184
+ />
185
+ <Card
186
+ icon={<OpenCodeIcon width={20} height={20} />}
187
+ title="OpenCode docs"
188
+ description="The OpenCode server itself."
189
+ href="https://opencode.ai/"
190
+ />
191
+ </Cards>
@@ -0,0 +1,48 @@
1
+ ---
2
+ title: Overview
3
+ description: Connect to an OpenCode coding-agent server.
4
+ ---
5
+
6
+ `@assistant-ui/react-opencode` is a runtime adapter for [OpenCode](https://opencode.ai/), an open-source AI coding agent. It wires the OpenCode server's session and event APIs into an assistant-ui thread, including tool permissions, interactive questions, and session state.
7
+
8
+ <Callout type="warn">
9
+ This adapter is at v0.0.3 and is experimental. The runtime API and exported hooks may change without notice.
10
+ </Callout>
11
+
12
+ ## When to use it
13
+
14
+ Pick the OpenCode runtime when:
15
+
16
+ - You are building a UI on top of an OpenCode agent server.
17
+ - You need first-class support for OpenCode's permission and question flows.
18
+ - You want session-aware features: fork, revert, unrevert, refresh.
19
+
20
+ If your backend is not OpenCode-based, see [picking a runtime](/docs/runtimes/pick-a-runtime) for alternatives.
21
+
22
+ ## Architecture
23
+
24
+ `@assistant-ui/react-opencode` is layered on `ExternalStoreRuntime` plus a `RemoteThreadList` for session-backed thread management (see [architecture](/docs/runtimes/concepts/architecture)). OpenCode sessions map to assistant-ui threads; the runtime subscribes to a server-sent event stream and projects messages into the thread.
25
+
26
+ ## Requirements
27
+
28
+ - A running [OpenCode](https://opencode.ai/) server (defaults to `http://localhost:4096`).
29
+ - React 18 or 19.
30
+
31
+ ## Install
32
+
33
+ <InstallCommand npm={["@assistant-ui/react", "@assistant-ui/react-opencode", "@opencode-ai/sdk"]} />
34
+
35
+ ## Next
36
+
37
+ <Cards>
38
+ <Card
39
+ title="Quickstart"
40
+ description="Minimal useOpenCodeRuntime setup against a local OpenCode server."
41
+ href="/docs/runtimes/opencode/quickstart"
42
+ />
43
+ <Card
44
+ title="Hooks"
45
+ description="Permissions, questions, session state, runtime extras."
46
+ href="/docs/runtimes/opencode/hooks"
47
+ />
48
+ </Cards>
@@ -0,0 +1,119 @@
1
+ ---
2
+ title: Quickstart
3
+ description: Minimal useOpenCodeRuntime setup against a local OpenCode server.
4
+ ---
5
+
6
+ Three steps to a working chat against a local OpenCode server. Assumes you have OpenCode running; if not, follow [opencode.ai](https://opencode.ai/) to install and start the server first.
7
+
8
+ <Steps>
9
+ <Step>
10
+
11
+ ### Wire up the runtime provider
12
+
13
+ ```tsx title="app/MyRuntimeProvider.tsx"
14
+ "use client";
15
+
16
+ import { AssistantRuntimeProvider } from "@assistant-ui/react";
17
+ import { useOpenCodeRuntime } from "@assistant-ui/react-opencode";
18
+
19
+ export function MyRuntimeProvider({
20
+ children,
21
+ }: {
22
+ children: React.ReactNode;
23
+ }) {
24
+ const runtime = useOpenCodeRuntime({
25
+ baseUrl: "http://localhost:4096",
26
+ });
27
+
28
+ return (
29
+ <AssistantRuntimeProvider runtime={runtime}>
30
+ {children}
31
+ </AssistantRuntimeProvider>
32
+ );
33
+ }
34
+ ```
35
+
36
+ `baseUrl` defaults to `http://localhost:4096` if omitted.
37
+
38
+ </Step>
39
+ <Step>
40
+
41
+ ### Render the Thread
42
+
43
+ ```tsx title="app/page.tsx"
44
+ import { Thread } from "@assistant-ui/react";
45
+ import { MyRuntimeProvider } from "./MyRuntimeProvider";
46
+
47
+ export default function Page() {
48
+ return (
49
+ <MyRuntimeProvider>
50
+ <Thread />
51
+ </MyRuntimeProvider>
52
+ );
53
+ }
54
+ ```
55
+
56
+ </Step>
57
+ <Step>
58
+
59
+ ### Set up UI components
60
+
61
+ Follow the [UI Components guide](/docs/ui/thread) to wire up the Thread, composer, and supporting primitives.
62
+
63
+ </Step>
64
+ </Steps>
65
+
66
+ The runtime opens an SSE event stream against the OpenCode server, listens for session and message events, and projects them into the thread. Each OpenCode session corresponds to one thread; the thread list reflects sessions on the server.
67
+
68
+ ## Default model and agent
69
+
70
+ Pin a default model or agent when starting new sessions:
71
+
72
+ ```tsx
73
+ const runtime = useOpenCodeRuntime({
74
+ baseUrl: "http://localhost:4096",
75
+ defaultModel: { providerID: "anthropic", modelID: "claude-sonnet-4" },
76
+ defaultAgent: "coder",
77
+ });
78
+ ```
79
+
80
+ ## Bring your own client
81
+
82
+ If you need a pre-configured `OpencodeClient` (e.g. for auth headers), pass it directly:
83
+
84
+ ```tsx
85
+ import { createOpencodeClient } from "@assistant-ui/react-opencode";
86
+
87
+ const client = createOpencodeClient({
88
+ baseUrl: "http://localhost:4096",
89
+ // additional client config...
90
+ });
91
+
92
+ const runtime = useOpenCodeRuntime({ client });
93
+ ```
94
+
95
+ ## Resuming a session
96
+
97
+ Pass `initialSessionId` to open the runtime against an existing session on first load:
98
+
99
+ ```tsx
100
+ const runtime = useOpenCodeRuntime({
101
+ baseUrl: "http://localhost:4096",
102
+ initialSessionId: "ses_abc123",
103
+ });
104
+ ```
105
+
106
+ ## Next
107
+
108
+ <Cards>
109
+ <Card
110
+ title="Hooks"
111
+ description="Permissions, questions, session state, runtime extras."
112
+ href="/docs/runtimes/opencode/hooks"
113
+ />
114
+ <Card
115
+ title="Pick a runtime"
116
+ description="Compare OpenCode to other runtime options."
117
+ href="/docs/runtimes/pick-a-runtime"
118
+ />
119
+ </Cards>