@assistant-ui/mcp-docs-server 0.1.7 → 0.1.8

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 (34) hide show
  1. package/.docs/organized/code-examples/with-ai-sdk-v5.md +3 -1
  2. package/.docs/organized/code-examples/with-cloud.md +3 -1
  3. package/.docs/organized/code-examples/with-external-store.md +3 -1
  4. package/.docs/organized/code-examples/with-ffmpeg.md +3 -1
  5. package/.docs/organized/code-examples/with-langgraph.md +66 -38
  6. package/.docs/organized/code-examples/with-parent-id-grouping.md +3 -1
  7. package/.docs/organized/code-examples/with-react-hook-form.md +3 -1
  8. package/.docs/raw/docs/api-reference/integrations/react-data-stream.mdx +194 -0
  9. package/.docs/raw/docs/api-reference/overview.mdx +6 -0
  10. package/.docs/raw/docs/api-reference/primitives/Composer.mdx +31 -0
  11. package/.docs/raw/docs/api-reference/primitives/Message.mdx +108 -3
  12. package/.docs/raw/docs/api-reference/primitives/Thread.mdx +59 -0
  13. package/.docs/raw/docs/api-reference/primitives/ThreadList.mdx +128 -0
  14. package/.docs/raw/docs/api-reference/primitives/ThreadListItem.mdx +160 -0
  15. package/.docs/raw/docs/api-reference/runtimes/AssistantRuntime.mdx +0 -11
  16. package/.docs/raw/docs/api-reference/runtimes/ComposerRuntime.mdx +3 -3
  17. package/.docs/raw/docs/copilots/assistant-frame.mdx +397 -0
  18. package/.docs/raw/docs/getting-started.mdx +20 -19
  19. package/.docs/raw/docs/guides/Attachments.mdx +6 -13
  20. package/.docs/raw/docs/guides/Tools.mdx +56 -13
  21. package/.docs/raw/docs/guides/context-api.mdx +574 -0
  22. package/.docs/raw/docs/migrations/v0-12.mdx +125 -0
  23. package/.docs/raw/docs/runtimes/custom/local.mdx +16 -3
  24. package/.docs/raw/docs/runtimes/data-stream.mdx +287 -0
  25. package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +5 -0
  26. package/.docs/raw/docs/ui/ThreadList.mdx +54 -16
  27. package/dist/{chunk-L4K23SWI.js → chunk-NVNFQ5ZO.js} +4 -1
  28. package/dist/index.js +1 -1
  29. package/dist/prepare-docs/prepare.js +1 -1
  30. package/dist/stdio.js +1 -1
  31. package/package.json +2 -2
  32. package/.docs/raw/docs/concepts/architecture.mdx +0 -19
  33. package/.docs/raw/docs/concepts/runtime-layer.mdx +0 -163
  34. package/.docs/raw/docs/concepts/why.mdx +0 -9
@@ -414,6 +414,8 @@ import {
414
414
  type RemoteThreadListAdapter,
415
415
  type ThreadHistoryAdapter,
416
416
  } from "@assistant-ui/react";
417
+ import { createAssistantStream } from "assistant-stream";
418
+ import { useMemo } from "react";
417
419
 
418
420
  // Implement your custom adapter with proper message persistence
419
421
  const myDatabaseAdapter: RemoteThreadListAdapter = {
@@ -453,9 +455,16 @@ const myDatabaseAdapter: RemoteThreadListAdapter = {
453
455
 
454
456
  async generateTitle(remoteId, messages) {
455
457
  // Generate title from messages using your AI
456
- const title = await generateTitle(messages);
457
- await db.threads.update(remoteId, { title });
458
- return new ReadableStream(); // Return empty stream
458
+ const newTitle = await generateTitle(messages);
459
+
460
+ // Persist the title in your DB
461
+ await db.threads.update(remoteId, { title: newTitle });
462
+
463
+ // IMPORTANT: Return an AssistantStream so the UI updates
464
+ return createAssistantStream((controller) => {
465
+ controller.appendText(newTitle);
466
+ controller.close();
467
+ });
459
468
  },
460
469
  };
461
470
 
@@ -528,6 +537,10 @@ export function MyRuntimeProvider({ children }) {
528
537
  }
529
538
  ```
530
539
 
540
+ <Callout type="info" title="Returning a title from generateTitle">
541
+ The `generateTitle` method must return an <code>AssistantStream</code> containing the title text. The easiest, type-safe way is to use <code>createAssistantStream</code> and call <code>controller.appendText(newTitle)</code> followed by <code>controller.close()</code>. Returning a raw <code>ReadableStream</code> won't update the thread list UI.
542
+ </Callout>
543
+
531
544
  #### Understanding the Architecture
532
545
 
533
546
  <Callout type="info">
@@ -0,0 +1,287 @@
1
+ ---
2
+ title: Data Stream Protocol
3
+ ---
4
+
5
+ import { Step, Steps } from "fumadocs-ui/components/steps";
6
+ import { Callout } from "fumadocs-ui/components/callout";
7
+
8
+ The `@assistant-ui/react-data-stream` package provides integration with data stream protocol endpoints, enabling streaming AI responses with tool support and state management.
9
+
10
+ ## Overview
11
+
12
+ The data stream protocol is a standardized format for streaming AI responses that supports:
13
+
14
+ - **Streaming text responses** with real-time updates
15
+ - **Tool calling** with structured parameters and results
16
+ - **State management** for conversation context
17
+ - **Error handling** and cancellation support
18
+ - **Attachment support** for multimodal interactions
19
+
20
+ ## Installation
21
+
22
+ ```bash npm2yarn
23
+ npm install @assistant-ui/react-data-stream
24
+ ```
25
+
26
+ ## Basic Usage
27
+
28
+ <Steps>
29
+
30
+ <Step>
31
+
32
+ ### Set up the Runtime
33
+
34
+ Use `useDataStreamRuntime` to connect to your data stream endpoint:
35
+
36
+ ```tsx title="app/page.tsx"
37
+ "use client";
38
+ import { useDataStreamRuntime } from "@assistant-ui/react-data-stream";
39
+ import { AssistantRuntimeProvider } from "@assistant-ui/react";
40
+ import { Thread } from "@/components/assistant-ui/thread";
41
+
42
+ export default function ChatPage() {
43
+ const runtime = useDataStreamRuntime({
44
+ api: "/api/chat",
45
+ });
46
+
47
+ return (
48
+ <AssistantRuntimeProvider runtime={runtime}>
49
+ <Thread />
50
+ </AssistantRuntimeProvider>
51
+ );
52
+ }
53
+ ```
54
+
55
+ </Step>
56
+
57
+ <Step>
58
+
59
+ ### Create Backend Endpoint
60
+
61
+ Your backend endpoint should accept POST requests and return data stream responses:
62
+
63
+ ```typescript title="app/api/chat/route.ts"
64
+ import { DataStreamResponse } from "assistant-stream";
65
+
66
+ export async function POST(request: Request) {
67
+ const { messages, tools, system } = await request.json();
68
+
69
+ // Process the request with your AI provider
70
+ const stream = await processWithAI({
71
+ messages,
72
+ tools,
73
+ system,
74
+ });
75
+
76
+ return new DataStreamResponse(stream);
77
+ }
78
+ ```
79
+
80
+ </Step>
81
+
82
+ </Steps>
83
+
84
+ ## Advanced Configuration
85
+
86
+ ### Custom Headers and Authentication
87
+
88
+ ```tsx
89
+ const runtime = useDataStreamRuntime({
90
+ api: "/api/chat",
91
+ headers: {
92
+ "Authorization": "Bearer " + token,
93
+ "X-Custom-Header": "value",
94
+ },
95
+ credentials: "include",
96
+ });
97
+ ```
98
+
99
+ ### Dynamic Headers
100
+
101
+ ```tsx
102
+ const runtime = useDataStreamRuntime({
103
+ api: "/api/chat",
104
+ headers: async () => {
105
+ const token = await getAuthToken();
106
+ return {
107
+ "Authorization": "Bearer " + token,
108
+ };
109
+ },
110
+ });
111
+ ```
112
+
113
+ ### Event Callbacks
114
+
115
+ ```tsx
116
+ const runtime = useDataStreamRuntime({
117
+ api: "/api/chat",
118
+ onResponse: (response) => {
119
+ console.log("Response received:", response.status);
120
+ },
121
+ onFinish: (message) => {
122
+ console.log("Message completed:", message);
123
+ },
124
+ onError: (error) => {
125
+ console.error("Error occurred:", error);
126
+ },
127
+ onCancel: () => {
128
+ console.log("Request cancelled");
129
+ },
130
+ });
131
+ ```
132
+
133
+ ## Tool Integration
134
+
135
+ ### Frontend Tools
136
+
137
+ Use the `frontendTools` helper to serialize client-side tools:
138
+
139
+ ```tsx
140
+ import { frontendTools } from "@assistant-ui/react-data-stream";
141
+ import { makeAssistantTool } from "@assistant-ui/react";
142
+
143
+ const weatherTool = makeAssistantTool({
144
+ toolName: "get_weather",
145
+ description: "Get current weather",
146
+ parameters: z.object({
147
+ location: z.string(),
148
+ }),
149
+ execute: async ({ location }) => {
150
+ const weather = await fetchWeather(location);
151
+ return `Weather in ${location}: ${weather}`;
152
+ },
153
+ });
154
+
155
+ const runtime = useDataStreamRuntime({
156
+ api: "/api/chat",
157
+ body: {
158
+ tools: frontendTools({
159
+ get_weather: weatherTool,
160
+ }),
161
+ },
162
+ });
163
+ ```
164
+
165
+ ### Backend Tool Processing
166
+
167
+ Your backend should handle tool calls and return results:
168
+
169
+ ```typescript title="Backend tool handling"
170
+ // Tools are automatically forwarded to your endpoint
171
+ const { tools } = await request.json();
172
+
173
+ // Process tools with your AI provider
174
+ const response = await ai.generateText({
175
+ messages,
176
+ tools,
177
+ // Tool results are streamed back automatically
178
+ });
179
+ ```
180
+
181
+ ## Assistant Cloud Integration
182
+
183
+ For Assistant Cloud deployments, use `useCloudRuntime`:
184
+
185
+ ```tsx
186
+ import { useCloudRuntime } from "@assistant-ui/react-data-stream";
187
+
188
+ const runtime = useCloudRuntime({
189
+ cloud: assistantCloud,
190
+ assistantId: "my-assistant-id",
191
+ });
192
+ ```
193
+
194
+ <Callout type="info">
195
+ The `useCloudRuntime` hook is currently under active development and not yet ready for production use.
196
+ </Callout>
197
+
198
+ ## Message Conversion
199
+
200
+ The package includes utilities for converting between message formats:
201
+
202
+ ```tsx
203
+ import { toLanguageModelMessages } from "@assistant-ui/react-data-stream";
204
+
205
+ // Convert assistant-ui messages to language model format
206
+ const languageModelMessages = toLanguageModelMessages(messages, {
207
+ unstable_includeId: true, // Include message IDs
208
+ });
209
+ ```
210
+
211
+ ## Error Handling
212
+
213
+ The runtime automatically handles common error scenarios:
214
+
215
+ - **Network errors**: Automatically retried with exponential backoff
216
+ - **Stream interruptions**: Gracefully handled with partial content preservation
217
+ - **Tool execution errors**: Displayed in the UI with error states
218
+ - **Cancellation**: Clean abort signal handling
219
+
220
+ ## Best Practices
221
+
222
+ ### Performance Optimization
223
+
224
+ ```tsx
225
+ // Use React.memo for expensive components
226
+ const OptimizedThread = React.memo(Thread);
227
+
228
+ // Memoize runtime configuration
229
+ const runtimeConfig = useMemo(() => ({
230
+ api: "/api/chat",
231
+ headers: { "Authorization": `Bearer ${token}` },
232
+ }), [token]);
233
+
234
+ const runtime = useDataStreamRuntime(runtimeConfig);
235
+ ```
236
+
237
+ ### Error Boundaries
238
+
239
+ ```tsx
240
+ import { ErrorBoundary } from "react-error-boundary";
241
+
242
+ function ChatErrorFallback({ error, resetErrorBoundary }) {
243
+ return (
244
+ <div role="alert">
245
+ <h2>Something went wrong:</h2>
246
+ <pre>{error.message}</pre>
247
+ <button onClick={resetErrorBoundary}>Try again</button>
248
+ </div>
249
+ );
250
+ }
251
+
252
+ export default function App() {
253
+ return (
254
+ <ErrorBoundary FallbackComponent={ChatErrorFallback}>
255
+ <AssistantRuntimeProvider runtime={runtime}>
256
+ <Thread />
257
+ </AssistantRuntimeProvider>
258
+ </ErrorBoundary>
259
+ );
260
+ }
261
+ ```
262
+
263
+ ### State Persistence
264
+
265
+ ```tsx
266
+ const runtime = useDataStreamRuntime({
267
+ api: "/api/chat",
268
+ body: {
269
+ // Include conversation state
270
+ state: conversationState,
271
+ },
272
+ onFinish: (message) => {
273
+ // Save state after each message
274
+ saveConversationState(message.metadata.unstable_state);
275
+ },
276
+ });
277
+ ```
278
+
279
+ ## Examples
280
+
281
+ - **[Basic Data Stream Example](https://github.com/assistant-ui/assistant-ui/tree/main/examples/with-data-stream)** - Simple streaming chat
282
+ - **[Tool Integration Example](https://github.com/assistant-ui/assistant-ui/tree/main/examples/with-data-stream-tools)** - Frontend and backend tools
283
+ - **[Authentication Example](https://github.com/assistant-ui/assistant-ui/tree/main/examples/with-data-stream-auth)** - Secure endpoints
284
+
285
+ ## API Reference
286
+
287
+ For detailed API documentation, see the [`@assistant-ui/react-data-stream` API Reference](/docs/api-reference/integrations/react-data-stream).
@@ -48,6 +48,11 @@ For popular frameworks, we provide ready-to-use integrations built on top of our
48
48
  description="For useChat and useAssistant hooks - streaming with all major providers"
49
49
  href="/docs/runtimes/ai-sdk/use-chat"
50
50
  />
51
+ <Card
52
+ title="Data Stream Protocol"
53
+ description="For custom backends using the data stream protocol standard"
54
+ href="/docs/runtimes/data-stream"
55
+ />
51
56
  <Card
52
57
  title="LangGraph"
53
58
  description="For complex agent workflows with LangChain's graph framework"
@@ -3,6 +3,8 @@ title: ThreadList
3
3
  ---
4
4
 
5
5
  import { Steps, Step } from "fumadocs-ui/components/steps";
6
+ import { Callout } from "fumadocs-ui/components/callout";
7
+ import { Tabs, Tab } from "fumadocs-ui/components/tabs";
6
8
  import { ThreadListSample } from "../../../components/samples/threadlist-sample";
7
9
 
8
10
  ## Overview
@@ -11,37 +13,73 @@ The ThreadList component lets the user switch between threads.
11
13
 
12
14
  <ThreadListSample />
13
15
 
16
+ <Callout>
17
+ This demo uses **ThreadListSidebar**, which includes `thread-list` as a dependency and provides a complete sidebar layout. For custom implementations, you can use `thread-list` directly.
18
+ </Callout>
19
+
14
20
  ## Getting Started
15
21
 
16
22
  <Steps>
17
23
  <Step>
18
24
 
19
- ### Add `thread-list`
25
+ ### Add the component
20
26
 
21
27
  ```sh
28
+ # Complete thread-list sidebar layout
29
+ npx shadcn@latest add "https://r.assistant-ui.com/threadlist-sidebar"
30
+
31
+ # Just the thread-list for custom layouts
22
32
  npx shadcn@latest add "https://r.assistant-ui.com/thread-list"
23
33
  ```
24
34
 
25
- This adds a `/components/assistant-ui/thread-list.tsx` file to your project, which you can adjust as needed.
26
-
27
35
  </Step>
28
36
  <Step>
29
37
 
30
38
  ### Use in your application
31
39
 
32
- ```tsx title="/app/page.tsx" {1,5-6}
33
- import { Thread } from "@/components/assistant-ui/thread";
34
- import { ThreadList } from "@/components/assistant-ui/thread-list";
35
-
36
- export default function Home() {
37
- return (
38
- <div className="grid h-full grid-cols-[200px_1fr]">
39
- <ThreadList />
40
- <Thread />
41
- </div>
42
- );
43
- }
44
- ```
40
+ <Tabs items={["With Sidebar", "Without Sidebar"]}>
41
+ <Tab value="With Sidebar">
42
+ ```tsx title="/app/assistant.tsx"
43
+ import { Thread } from "@/components/assistant-ui/thread";
44
+ import { ThreadListSidebar } from "@/components/assistant-ui/threadlist-sidebar";
45
+ import {
46
+ SidebarProvider,
47
+ SidebarInset,
48
+ SidebarTrigger
49
+ } from "@/components/ui/sidebar";
50
+
51
+ export default function Assistant() {
52
+ return (
53
+ <SidebarProvider>
54
+ <div className="flex h-dvh w-full">
55
+ <ThreadListSidebar />
56
+ <SidebarInset>
57
+ {/* Add sidebar trigger, location can be customized */}
58
+ <SidebarTrigger className="absolute top-4 left-4" />
59
+ <Thread />
60
+ </SidebarInset>
61
+ </div>
62
+ </SidebarProvider>
63
+ );
64
+ }
65
+ ```
66
+ </Tab>
67
+ <Tab value="Without Sidebar">
68
+ ```tsx title="/app/assistant.tsx"
69
+ import { Thread } from "@/components/assistant-ui/thread";
70
+ import { ThreadList } from "@/components/assistant-ui/thread-list";
71
+
72
+ export default function Assistant() {
73
+ return (
74
+ <div className="grid h-full grid-cols-[200px_1fr]">
75
+ <ThreadList />
76
+ <Thread />
77
+ </div>
78
+ );
79
+ }
80
+ ```
81
+ </Tab>
82
+ </Tabs>
45
83
 
46
84
  </Step>
47
85
  </Steps>
@@ -109,6 +109,9 @@ function sanitizePath(userPath) {
109
109
  if (!userPath || typeof userPath !== "string") {
110
110
  throw new Error("Invalid path: Path must be a non-empty string");
111
111
  }
112
+ if (userPath.includes("../") || userPath.includes("..\\")) {
113
+ throw new Error("Invalid path: Directory traversal attempt detected");
114
+ }
112
115
  const normalized = normalize(userPath);
113
116
  if (path.isAbsolute(normalized)) {
114
117
  throw new Error("Invalid path: Absolute paths are not allowed");
@@ -138,7 +141,7 @@ function sanitizePath(userPath) {
138
141
  throw new Error("Invalid path: Hidden files are not allowed");
139
142
  }
140
143
  }
141
- return relativePath;
144
+ return relativePath.replace(/\\/g, "/");
142
145
  }
143
146
 
144
147
  // src/tools/docs.ts
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { runServer, server } from './chunk-L4K23SWI.js';
1
+ export { runServer, server } from './chunk-NVNFQ5ZO.js';
@@ -153,7 +153,7 @@ _Note: Additional files truncated due to size limits_
153
153
  `;
154
154
  break;
155
155
  }
156
- markdown += `## ${file.path}
156
+ markdown += `## ${file.path.replace(/\\/g, "/")}
157
157
 
158
158
  `;
159
159
  markdown += `\`\`\`${getFileType(file.path)}
package/dist/stdio.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { runServer } from './chunk-L4K23SWI.js';
2
+ import { runServer } from './chunk-NVNFQ5ZO.js';
3
3
 
4
4
  // src/stdio.ts
5
5
  void runServer().catch((error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assistant-ui/mcp-docs-server",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "MCP server for assistant-ui documentation and examples",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -30,7 +30,7 @@
30
30
  "access": "public"
31
31
  },
32
32
  "scripts": {
33
- "clean": "rm -rf dist .docs",
33
+ "clean": "tsx scripts/clean.mts",
34
34
  "prepare-docs": "cross-env PREPARE=true node ./dist/prepare-docs/prepare.js",
35
35
  "build:cli": "tsup src/stdio.ts src/prepare-docs/prepare.ts src/index.ts --format esm --treeshake=smallest --splitting",
36
36
  "build": "pnpm clean && pnpm build:cli && pnpm prepare-docs",
@@ -1,19 +0,0 @@
1
- ---
2
- title: Architecture
3
- ---
4
-
5
- import Image from "next/image";
6
- import architecture from "@/assets/docs/architecture.png";
7
-
8
- ### Architecture
9
-
10
- `assistant-ui` consists of two parts, **_Runtime_** and **_UI Components_**.
11
-
12
- <Image
13
- src={architecture}
14
- alt="Architecture diagram, UI components connected to the runtime layer and the runtime layer connected to LLM and tools"
15
- height={300}
16
- className="mx-auto my-2 dark:hue-rotate-180 dark:invert"
17
- />
18
-
19
- The Runtime and UI Components each require independent setup and both must be set up.
@@ -1,163 +0,0 @@
1
- ---
2
- title: Runtime Layer
3
- ---
4
-
5
- assistant-ui components are full stack components. This means that they include both the UI presentation, but also logic to communicate with an external system. This logic is handled by the runtime layer and APIs.
6
-
7
- You interact with the runtime layer in two ways:
8
-
9
- - defining a runtime for your app
10
- - using the runtime APIs to interact with the runtime
11
-
12
- ## Defining a runtime
13
-
14
- assistant-ui ships with two low-level runtimes:
15
-
16
- - `useLocalRuntime`
17
- - `useExternalStoreRuntime`
18
-
19
- Both of these runtimes let you implement your own runtime. The conceptual difference between the two is that `useLocalRuntime` takes ownership of the data layer, while `useExternalStoreRuntime` does not.
20
-
21
- If you have a stateful API to integrate, use `useExternalStoreRuntime`, if you have a stateless API to integrate, use `useLocalRuntime`.
22
-
23
- ### Higher level runtimes
24
-
25
- For many services and APIs, assistant-ui provides deeper integrations. These are built with the two low-level runtimes mentioned above.
26
-
27
- - `useChatRuntime`: Connect to Vercel AI SDK backends
28
- - `useVercelUseChatRuntime`: Integrate with Vercel AI SDK's `useChat` hook
29
- - `useVercelUseAssistantRuntime`: Integrate with Vercel AI SDK's `useAssistant` hook (OpenAI Assistants API)
30
- - `useVercelRSCRuntime`: Integrate with Vercel AI SDK React Server Components
31
- - `useLangGraphRuntime`: Connect to LangGraph Cloud
32
- - ...
33
-
34
- ### Runtime Providers
35
-
36
- The following components accept a `runtime` prop:
37
-
38
- - `AssistantRuntimeProvider`
39
- - `Thread`
40
-
41
- These components put the Runtime in the React Context, so that all child components can access the runtime.
42
-
43
- ### Runtime Adapters
44
-
45
- Most runtimes accept additional adapters to configure extra integrations:
46
-
47
- - ChatModelAdapter: Configures the backend API
48
- - AttachmentAdapter: Configures the file/media attachment API
49
- - SpeechSynthesisAdapter: Configures the speech API
50
- - FeedbackAdapter: Configures the feedback API
51
- - SuggestionAdapter: Configures dynamic suggestion generation based on conversation context
52
-
53
- ## Using the runtime APIs
54
-
55
- The same API used by the assistant-ui components is also available to you. This allows you to build your own UI components and integrate them with the runtime layer.
56
-
57
- ### Runtime Hierarchy
58
-
59
- The runtime API is nested as such:
60
-
61
- import { File, Folder, Files } from "fumadocs-ui/components/files";
62
-
63
- <Files>
64
- <Folder name="AssistantRuntime" defaultOpen>
65
- <Folder name="ThreadListRuntime" defaultOpen>
66
- <Folder name="ThreadRuntime" defaultOpen>
67
- <Folder name="MessageRuntime" defaultOpen>
68
- <Folder
69
- name="MessagePartRuntime (Text / Reasoning / Image / Audio / Tool-Call / UI)"
70
- defaultOpen
71
- ></Folder>
72
- <Folder name="MessageAttachmentRuntime" defaultOpen></Folder>
73
- <Folder name="EditComposerRuntime" defaultOpen>
74
- <Folder name="EditComposerAttachmentRuntime" defaultOpen></Folder>
75
- </Folder>
76
- </Folder>
77
- <Folder name="ThreadComposerRuntime" defaultOpen>
78
- <Folder name="ThreadComposerAttachmentRuntime" defaultOpen></Folder>
79
- </Folder>
80
- </Folder>
81
- </Folder>
82
- </Folder>
83
- </Files>
84
-
85
- The AssistantRuntime (which encompasses everything), is sometimes simply called `Runtime`.
86
-
87
- ### Runtime Context Provider Components
88
-
89
- The following components provide the runtime APIs:
90
-
91
- ```tsx
92
- // provides AssistantRuntime, ThreadListRuntime, ThreadRuntime, ComposerRuntime (ThreadComposer)
93
- <AssistantRuntimeProvider runtime={runtime} />
94
-
95
- // renders every message, provides MessageRuntime, ComposerRuntime (EditComposer)
96
- <ThreadPrimitive.Messages components={{ Message, ... }} />
97
-
98
- // renders every message part, provides MessagePartRuntime
99
- <MessagePrimitive.Parts components={{ Text, Reasoning, Image, Audio, UI, tools }} />
100
-
101
- // renders every attachment, provides AttachmentRuntime (Thread or EditComposer)
102
- <ComposerPrimitive.Attachments components={{ Attachment, ... }} />
103
-
104
- // renders every attachment, provides AtatchmentRuntime (Message)
105
- <MessagePrimitive.Attachments components={{ Attachment, ... }} />
106
-
107
- // provides a custom TextMessagePartRuntime
108
- <TextMessagePartProvider text="Hello!" />
109
- ```
110
-
111
- ### Accessing runtime APIs
112
-
113
- You can access the runtime APIs with react hooks:
114
-
115
- ```tsx
116
- const runtime = useAssistantRuntime();
117
- const threadRuntime = useThreadRuntime();
118
- const messageRuntime = useMessageRuntime();
119
- const MessagePartRuntime = useMessagePartRuntime();
120
-
121
- // thread manager has no separate hook (1:1 relationship with assistant runtime)
122
- const ThreadListRuntime = useAssistantRuntime().threads;
123
-
124
- // composer runtime is multi-use
125
- const composerRuntime = useComposerRuntime(); // refers to edit composer if available, otherwise thread composer
126
-
127
- // thread manager has no separate hook (1:1 relationship with assistant runtime)
128
- const threadComposer = useThreadRuntime().composer;
129
-
130
- // thread manager has no separate hook (1:1 relationship with assistant runtime)
131
- const editComposerRuntime = useMessageRuntime().composer;
132
-
133
- // attachment runtime is multi-use
134
- const attachmentRuntime = useAttachmentRuntime(); // refers to the closest attachment runtime
135
- const threadComposerAttachmentRuntime = useThreadComposerAttachmentRuntime();
136
- const editComposerAttachmentRuntime = useEditComposerAttachmentRuntime();
137
- const messageAttachmentRuntime = useMessageAttachmentRuntime();
138
- ```
139
-
140
- ### Accessing runtime state
141
-
142
- Most runtimes also expose a state through two methods `getState` and `subscribe`. The following helper hooks subscribe to the state, so that your component is updated when the state changes:
143
-
144
- ```tsx
145
- useThreadList(); // get thread manager state
146
- useThread(); // get thread state
147
- useMessage(); // get message state
148
- useMessagePart(); // get message part state
149
- useComposer(); // get composer state
150
- useThreadComposer(); // get thread composer state
151
- useEditComposer(); // get edit composer state
152
- useAttachment(); // get attachment state
153
- useThreadComposerAttachment(); // get thread composer attachment state
154
- useEditComposerAttachment(); // get edit composer attachment state
155
- useMessageAttachment(); // get message attachment state
156
- ```
157
-
158
- You might not want to subscribe to evey update. In that case, pass a callback selector to the hook:
159
-
160
- ```tsx
161
- // only subscribe to role changes
162
- const role = useMessage((state) => message.role);
163
- ```
@@ -1,9 +0,0 @@
1
- ---
2
- title: Why assistant-ui?
3
- ---
4
-
5
- assistant-ui is a collection of powerful, modular primitives to build AI chat interfaces.
6
-
7
- The modular approach means that you can incrementally adopt assistant-ui (e.g. use the backend connectors and bring your own components, or use the frontend compoents and bring your own backend).
8
- You can also partially opt out of assistant-ui whenever you hit any limitation in the library.
9
-