@assistant-ui/mcp-docs-server 0.1.7 → 0.1.9
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.
- package/.docs/organized/code-examples/with-ai-sdk-v5.md +24 -15
- package/.docs/organized/code-examples/with-assistant-transport.md +1599 -0
- package/.docs/organized/code-examples/with-cloud.md +12 -10
- package/.docs/organized/code-examples/with-external-store.md +10 -8
- package/.docs/organized/code-examples/with-ffmpeg.md +17 -14
- package/.docs/organized/code-examples/with-langgraph.md +83 -47
- package/.docs/organized/code-examples/with-parent-id-grouping.md +10 -8
- package/.docs/organized/code-examples/with-react-hook-form.md +17 -14
- package/.docs/raw/docs/api-reference/integrations/react-data-stream.mdx +194 -0
- package/.docs/raw/docs/api-reference/overview.mdx +6 -0
- package/.docs/raw/docs/api-reference/primitives/Composer.mdx +31 -0
- package/.docs/raw/docs/api-reference/primitives/Message.mdx +108 -3
- package/.docs/raw/docs/api-reference/primitives/Thread.mdx +59 -0
- package/.docs/raw/docs/api-reference/primitives/ThreadList.mdx +128 -0
- package/.docs/raw/docs/api-reference/primitives/ThreadListItem.mdx +160 -0
- package/.docs/raw/docs/api-reference/runtimes/AssistantRuntime.mdx +0 -11
- package/.docs/raw/docs/api-reference/runtimes/ComposerRuntime.mdx +3 -3
- package/.docs/raw/docs/copilots/assistant-frame.mdx +399 -0
- package/.docs/raw/docs/devtools.mdx +51 -0
- package/.docs/raw/docs/getting-started.mdx +20 -19
- package/.docs/raw/docs/guides/Attachments.mdx +6 -13
- package/.docs/raw/docs/guides/Tools.mdx +56 -13
- package/.docs/raw/docs/guides/context-api.mdx +574 -0
- package/.docs/raw/docs/migrations/v0-12.mdx +125 -0
- package/.docs/raw/docs/runtimes/ai-sdk/use-chat.mdx +2 -2
- package/.docs/raw/docs/runtimes/custom/local.mdx +17 -4
- package/.docs/raw/docs/runtimes/data-stream.mdx +287 -0
- package/.docs/raw/docs/runtimes/mastra/full-stack-integration.mdx +6 -5
- package/.docs/raw/docs/runtimes/mastra/overview.mdx +3 -3
- package/.docs/raw/docs/runtimes/mastra/separate-server-integration.mdx +13 -13
- package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +5 -0
- package/.docs/raw/docs/ui/ThreadList.mdx +54 -16
- package/dist/{chunk-L4K23SWI.js → chunk-NVNFQ5ZO.js} +4 -1
- package/dist/index.js +1 -1
- package/dist/prepare-docs/prepare.js +1 -1
- package/dist/stdio.js +1 -1
- package/package.json +7 -7
- package/.docs/raw/docs/concepts/architecture.mdx +0 -19
- package/.docs/raw/docs/concepts/runtime-layer.mdx +0 -163
- package/.docs/raw/docs/concepts/why.mdx +0 -9
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: ThreadListItemPrimitive
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
A single thread item within a thread list.
|
|
6
|
+
|
|
7
|
+
import { ParametersTable } from "@/components/docs";
|
|
8
|
+
|
|
9
|
+
## Anatomy
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { ThreadListItemPrimitive } from "@assistant-ui/react";
|
|
13
|
+
|
|
14
|
+
const ThreadListItem = () => (
|
|
15
|
+
<ThreadListItemPrimitive.Root>
|
|
16
|
+
<ThreadListItemPrimitive.Trigger>
|
|
17
|
+
<ThreadListItemPrimitive.Title />
|
|
18
|
+
</ThreadListItemPrimitive.Trigger>
|
|
19
|
+
<ThreadListItemPrimitive.Archive />
|
|
20
|
+
<ThreadListItemPrimitive.Unarchive />
|
|
21
|
+
<ThreadListItemPrimitive.Delete />
|
|
22
|
+
</ThreadListItemPrimitive.Root>
|
|
23
|
+
);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## API Reference
|
|
27
|
+
|
|
28
|
+
### Root
|
|
29
|
+
|
|
30
|
+
Contains all parts of the thread list item.
|
|
31
|
+
|
|
32
|
+
This primitive renders a `<div>` element unless `asChild` is set. It automatically adds `data-active="true"` and `aria-current="true"` attributes when the thread is the currently active thread.
|
|
33
|
+
|
|
34
|
+
<ParametersTable
|
|
35
|
+
type="ThreadListItemPrimitiveRootProps"
|
|
36
|
+
parameters={[
|
|
37
|
+
{
|
|
38
|
+
name: "asChild",
|
|
39
|
+
},
|
|
40
|
+
]}
|
|
41
|
+
/>
|
|
42
|
+
|
|
43
|
+
### Trigger
|
|
44
|
+
|
|
45
|
+
A button that switches to the thread when clicked.
|
|
46
|
+
|
|
47
|
+
This primitive renders a `<button>` element unless `asChild` is set.
|
|
48
|
+
|
|
49
|
+
<ParametersTable
|
|
50
|
+
type="ThreadListItemPrimitiveTriggerProps"
|
|
51
|
+
parameters={[
|
|
52
|
+
{
|
|
53
|
+
name: "asChild",
|
|
54
|
+
},
|
|
55
|
+
]}
|
|
56
|
+
/>
|
|
57
|
+
|
|
58
|
+
### Title
|
|
59
|
+
|
|
60
|
+
Displays the title of the thread.
|
|
61
|
+
|
|
62
|
+
This primitive renders a `<span>` element unless `asChild` is set. The title is automatically derived from the first user message in the thread.
|
|
63
|
+
|
|
64
|
+
<ParametersTable
|
|
65
|
+
type="ThreadListItemPrimitiveTitleProps"
|
|
66
|
+
parameters={[
|
|
67
|
+
{
|
|
68
|
+
name: "asChild",
|
|
69
|
+
},
|
|
70
|
+
]}
|
|
71
|
+
/>
|
|
72
|
+
|
|
73
|
+
### Archive
|
|
74
|
+
|
|
75
|
+
A button to archive the thread. Only shown for non-archived threads.
|
|
76
|
+
|
|
77
|
+
This primitive renders a `<button>` element unless `asChild` is set.
|
|
78
|
+
|
|
79
|
+
<ParametersTable
|
|
80
|
+
type="ThreadListItemPrimitiveArchiveProps"
|
|
81
|
+
parameters={[
|
|
82
|
+
{
|
|
83
|
+
name: "asChild",
|
|
84
|
+
},
|
|
85
|
+
]}
|
|
86
|
+
/>
|
|
87
|
+
|
|
88
|
+
### Unarchive
|
|
89
|
+
|
|
90
|
+
A button to unarchive the thread. Only shown for archived threads.
|
|
91
|
+
|
|
92
|
+
This primitive renders a `<button>` element unless `asChild` is set.
|
|
93
|
+
|
|
94
|
+
<ParametersTable
|
|
95
|
+
type="ThreadListItemPrimitiveUnarchiveProps"
|
|
96
|
+
parameters={[
|
|
97
|
+
{
|
|
98
|
+
name: "asChild",
|
|
99
|
+
},
|
|
100
|
+
]}
|
|
101
|
+
/>
|
|
102
|
+
|
|
103
|
+
### Delete
|
|
104
|
+
|
|
105
|
+
A button to permanently delete the thread.
|
|
106
|
+
|
|
107
|
+
This primitive renders a `<button>` element unless `asChild` is set.
|
|
108
|
+
|
|
109
|
+
<ParametersTable
|
|
110
|
+
type="ThreadListItemPrimitiveDeleteProps"
|
|
111
|
+
parameters={[
|
|
112
|
+
{
|
|
113
|
+
name: "asChild",
|
|
114
|
+
},
|
|
115
|
+
]}
|
|
116
|
+
/>
|
|
117
|
+
|
|
118
|
+
## Examples
|
|
119
|
+
|
|
120
|
+
### Basic Thread List Item
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
const MyThreadListItem = () => {
|
|
124
|
+
return (
|
|
125
|
+
<ThreadListItemPrimitive.Root className="thread-item">
|
|
126
|
+
<ThreadListItemPrimitive.Trigger className="thread-trigger">
|
|
127
|
+
<ThreadListItemPrimitive.Title />
|
|
128
|
+
</ThreadListItemPrimitive.Trigger>
|
|
129
|
+
<div className="thread-actions">
|
|
130
|
+
<ThreadListItemPrimitive.Archive>
|
|
131
|
+
Archive
|
|
132
|
+
</ThreadListItemPrimitive.Archive>
|
|
133
|
+
<ThreadListItemPrimitive.Delete>
|
|
134
|
+
Delete
|
|
135
|
+
</ThreadListItemPrimitive.Delete>
|
|
136
|
+
</div>
|
|
137
|
+
</ThreadListItemPrimitive.Root>
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Archived Thread List Item
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
const ArchivedThreadListItem = () => {
|
|
146
|
+
return (
|
|
147
|
+
<ThreadListItemPrimitive.Root className="archived-thread-item">
|
|
148
|
+
<ThreadListItemPrimitive.Trigger>
|
|
149
|
+
<ThreadListItemPrimitive.Title />
|
|
150
|
+
</ThreadListItemPrimitive.Trigger>
|
|
151
|
+
<ThreadListItemPrimitive.Unarchive>
|
|
152
|
+
Restore
|
|
153
|
+
</ThreadListItemPrimitive.Unarchive>
|
|
154
|
+
<ThreadListItemPrimitive.Delete>
|
|
155
|
+
Delete Permanently
|
|
156
|
+
</ThreadListItemPrimitive.Delete>
|
|
157
|
+
</ThreadListItemPrimitive.Root>
|
|
158
|
+
);
|
|
159
|
+
};
|
|
160
|
+
```
|
|
@@ -20,14 +20,3 @@ const runtime = useAssistantRuntime();
|
|
|
20
20
|
### Tool UI Registry
|
|
21
21
|
|
|
22
22
|
The tool UI registry is part of the assistant runtime. It allows you to display custom UI for tool calls, enabling generative UI.
|
|
23
|
-
|
|
24
|
-
#### `useToolUIs`
|
|
25
|
-
|
|
26
|
-
```tsx
|
|
27
|
-
import { useToolUIs } from "@assistant-ui/react";
|
|
28
|
-
|
|
29
|
-
const toolUIs = useToolUIs();
|
|
30
|
-
const webSearchToolUI = useToolUIs((m) => m.getToolUI("web_search"));
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
<ParametersTable {...AssistantToolUIsState} />
|
|
@@ -7,15 +7,15 @@ The composer runtime allows you to view or edit anything related to how new info
|
|
|
7
7
|
import { ParametersTable } from "@/components/docs";
|
|
8
8
|
import { ComposerRuntime, ThreadComposerRuntime, ThreadComposerState, EditComposerState } from "@/generated/typeDocs";
|
|
9
9
|
|
|
10
|
-
### `
|
|
10
|
+
### `useComposerRuntime`
|
|
11
11
|
|
|
12
12
|
Grabs the nearest composer (whether it’s the edit composer or the thread’s composer):
|
|
13
13
|
|
|
14
14
|
```tsx
|
|
15
15
|
// Example
|
|
16
|
-
import {
|
|
16
|
+
import { useComposerRuntime } from "@assistant-ui/react";
|
|
17
17
|
|
|
18
|
-
const composerRuntime =
|
|
18
|
+
const composerRuntime = useComposerRuntime();
|
|
19
19
|
|
|
20
20
|
// set the text
|
|
21
21
|
composerRuntime.setText("Hello from the composer runtime");
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Assistant Frame API
|
|
3
|
+
description: Share model context across iframe boundaries
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
The Assistant Frame API enables iframes to provide model context (tools and instructions) to a parent window's assistant. This is particularly useful for embedded applications, plugins, or sandboxed components that need to contribute capabilities to the main assistant.
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
The Assistant Frame system consists of two main components:
|
|
11
|
+
|
|
12
|
+
- **AssistantFrameProvider**: Runs inside the iframe and provides model context
|
|
13
|
+
- **AssistantFrameHost**: Runs in the parent window and consumes context from iframes
|
|
14
|
+
|
|
15
|
+
## Basic Usage
|
|
16
|
+
|
|
17
|
+
### In the iframe (Provider)
|
|
18
|
+
|
|
19
|
+
The iframe acts as a provider of model context using `AssistantFrameProvider`:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
// iframe.tsx
|
|
23
|
+
import { AssistantFrameProvider } from "@assistant-ui/react";
|
|
24
|
+
import { ModelContextRegistry } from "@assistant-ui/react";
|
|
25
|
+
import { z } from "zod";
|
|
26
|
+
|
|
27
|
+
// Create a registry to manage your model context
|
|
28
|
+
const registry = new ModelContextRegistry();
|
|
29
|
+
|
|
30
|
+
// Expose the registry to the parent window
|
|
31
|
+
AssistantFrameProvider.addModelContextProvider(registry);
|
|
32
|
+
|
|
33
|
+
// Add tools that will be available to the parent assistant
|
|
34
|
+
registry.addTool({
|
|
35
|
+
toolName: "searchProducts",
|
|
36
|
+
description: "Search for products in the catalog",
|
|
37
|
+
parameters: z.object({
|
|
38
|
+
query: z.string(),
|
|
39
|
+
category: z.string().optional(),
|
|
40
|
+
}),
|
|
41
|
+
execute: async ({ query, category }) => {
|
|
42
|
+
// Tool implementation runs in the iframe
|
|
43
|
+
const results = await searchAPI(query, category);
|
|
44
|
+
return { products: results };
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Add system instructions
|
|
49
|
+
const instructionHandle = registry.addInstruction(
|
|
50
|
+
"You are a helpful assistant.",
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
// update the instruction
|
|
54
|
+
instructionHandle.update("You have access to a product catalog search tool.");
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### In the parent window (Host)
|
|
58
|
+
|
|
59
|
+
The parent window consumes the iframe's context using `AssistantFrameHost`:
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
// parent.tsx
|
|
63
|
+
import { useAssistantFrameHost } from "@assistant-ui/react";
|
|
64
|
+
import { useRef } from "react";
|
|
65
|
+
|
|
66
|
+
function ParentComponent() {
|
|
67
|
+
const iframeRef = useRef<HTMLIFrameElement>(null);
|
|
68
|
+
|
|
69
|
+
// Connect to the iframe's model context
|
|
70
|
+
useAssistantFrameHost({
|
|
71
|
+
iframeRef,
|
|
72
|
+
targetOrigin: "https://trusted-iframe-domain.com", // optional for increased security
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div>
|
|
77
|
+
<Thread /> {/* Your assistant-ui */}
|
|
78
|
+
<iframe
|
|
79
|
+
ref={iframeRef}
|
|
80
|
+
src="https://trusted-iframe-domain.com/embed"
|
|
81
|
+
title="Embedded App"
|
|
82
|
+
/>
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Advanced Usage
|
|
89
|
+
|
|
90
|
+
### ModelContextRegistry
|
|
91
|
+
|
|
92
|
+
The `ModelContextRegistry` provides a flexible way to manage model context dynamically:
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
const registry = new ModelContextRegistry();
|
|
96
|
+
|
|
97
|
+
// Add a tool with handle for updates
|
|
98
|
+
const toolHandle = registry.addTool({
|
|
99
|
+
toolName: "convertCurrency",
|
|
100
|
+
description: "Convert between currencies",
|
|
101
|
+
parameters: z.object({
|
|
102
|
+
amount: z.number(),
|
|
103
|
+
from: z.string(),
|
|
104
|
+
to: z.string(),
|
|
105
|
+
}),
|
|
106
|
+
execute: async ({ amount, from, to }) => {
|
|
107
|
+
const rate = await fetchExchangeRate(from, to);
|
|
108
|
+
return { result: amount * rate, currency: to };
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Update the tool later
|
|
113
|
+
toolHandle.update({
|
|
114
|
+
toolName: "convertCurrency",
|
|
115
|
+
description: "Convert between currencies with live rates", // Updated description
|
|
116
|
+
parameters: z.object({
|
|
117
|
+
amount: z.number(),
|
|
118
|
+
from: z.string(),
|
|
119
|
+
to: z.string(),
|
|
120
|
+
includesFees: z.boolean().optional(),
|
|
121
|
+
}),
|
|
122
|
+
execute: async ({ amount, from, to, includesFees }) => {
|
|
123
|
+
const rate = await fetchExchangeRate(from, to);
|
|
124
|
+
const fee = includesFees ? 0.02 : 0; // 2% fee
|
|
125
|
+
return {
|
|
126
|
+
result: amount * rate * (1 - fee),
|
|
127
|
+
currency: to,
|
|
128
|
+
fee: includesFees ? amount * rate * fee : 0,
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Remove the tool when no longer needed
|
|
134
|
+
toolHandle.remove();
|
|
135
|
+
|
|
136
|
+
// Add multiple instructions
|
|
137
|
+
const instruction1 = registry.addInstruction("Be helpful and concise.");
|
|
138
|
+
const instruction2 = registry.addInstruction("Use metric units.");
|
|
139
|
+
|
|
140
|
+
// Remove instructions
|
|
141
|
+
instruction1.remove();
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Multiple Providers
|
|
145
|
+
|
|
146
|
+
You can register multiple model context providers in the same iframe:
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
const catalogRegistry = new ModelContextRegistry();
|
|
150
|
+
const analyticsRegistry = new ModelContextRegistry();
|
|
151
|
+
|
|
152
|
+
// Add different tools to each registry
|
|
153
|
+
catalogRegistry.addTool({
|
|
154
|
+
/* ... */
|
|
155
|
+
});
|
|
156
|
+
analyticsRegistry.addTool({
|
|
157
|
+
/* ... */
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Register both providers
|
|
161
|
+
const unsubscribe1 =
|
|
162
|
+
AssistantFrameProvider.addModelContextProvider(catalogRegistry);
|
|
163
|
+
const unsubscribe2 =
|
|
164
|
+
AssistantFrameProvider.addModelContextProvider(analyticsRegistry);
|
|
165
|
+
|
|
166
|
+
// Later, unsubscribe if needed
|
|
167
|
+
unsubscribe1();
|
|
168
|
+
unsubscribe2();
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Security Considerations
|
|
172
|
+
|
|
173
|
+
#### Origin Validation
|
|
174
|
+
|
|
175
|
+
Both the provider and host can specify allowed origins for security:
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
// In iframe - only accept messages from specific parent
|
|
179
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
180
|
+
registry,
|
|
181
|
+
"https://parent-app.com",
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
// In parent - only accept messages from specific iframe
|
|
185
|
+
useAssistantFrameHost({
|
|
186
|
+
iframeRef,
|
|
187
|
+
targetOrigin: "https://iframe-app.com",
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
#### Tool Execution
|
|
192
|
+
|
|
193
|
+
Tools are executed in the iframe's context, keeping sensitive operations sandboxed:
|
|
194
|
+
|
|
195
|
+
```tsx
|
|
196
|
+
registry.addTool({
|
|
197
|
+
toolName: "accessDatabase",
|
|
198
|
+
description: "Query the database",
|
|
199
|
+
parameters: z.object({ query: z.string() }),
|
|
200
|
+
execute: async ({ query }) => {
|
|
201
|
+
// This runs in the iframe with iframe's permissions
|
|
202
|
+
// Parent cannot directly access the database
|
|
203
|
+
const results = await db.query(query);
|
|
204
|
+
return results;
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## API Reference
|
|
210
|
+
|
|
211
|
+
### AssistantFrameProvider
|
|
212
|
+
|
|
213
|
+
Static class that manages model context providers in an iframe.
|
|
214
|
+
|
|
215
|
+
#### Methods
|
|
216
|
+
|
|
217
|
+
##### `addModelContextProvider(provider, targetOrigin?)`
|
|
218
|
+
|
|
219
|
+
Registers a model context provider to share with parent windows.
|
|
220
|
+
|
|
221
|
+
```tsx
|
|
222
|
+
const unsubscribe = AssistantFrameProvider.addModelContextProvider(
|
|
223
|
+
registry,
|
|
224
|
+
"https://parent-domain.com", // Optional origin restriction
|
|
225
|
+
);
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
##### `dispose()`
|
|
229
|
+
|
|
230
|
+
Cleans up all resources and removes all providers.
|
|
231
|
+
|
|
232
|
+
```tsx
|
|
233
|
+
AssistantFrameProvider.dispose();
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### AssistantFrameHost
|
|
237
|
+
|
|
238
|
+
Class that connects to an iframe's model context providers.
|
|
239
|
+
|
|
240
|
+
#### Constructor
|
|
241
|
+
|
|
242
|
+
```tsx
|
|
243
|
+
const host = new AssistantFrameHost(
|
|
244
|
+
iframeWindow,
|
|
245
|
+
targetOrigin? // Optional origin restriction
|
|
246
|
+
);
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
#### Methods
|
|
250
|
+
|
|
251
|
+
##### `getModelContext()`
|
|
252
|
+
|
|
253
|
+
Returns the current merged model context from the iframe.
|
|
254
|
+
|
|
255
|
+
```tsx
|
|
256
|
+
const context = host.getModelContext();
|
|
257
|
+
// { system: "...", tools: { ... } }
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
##### `subscribe(callback)`
|
|
261
|
+
|
|
262
|
+
Subscribes to model context changes.
|
|
263
|
+
|
|
264
|
+
```tsx
|
|
265
|
+
const unsubscribe = host.subscribe(() => {
|
|
266
|
+
console.log("Context updated:", host.getModelContext());
|
|
267
|
+
});
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
##### `dispose()`
|
|
271
|
+
|
|
272
|
+
Cleans up the connection to the iframe.
|
|
273
|
+
|
|
274
|
+
```tsx
|
|
275
|
+
host.dispose();
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### useAssistantFrameHost
|
|
279
|
+
|
|
280
|
+
React hook that manages the lifecycle of an AssistantFrameHost.
|
|
281
|
+
|
|
282
|
+
```tsx
|
|
283
|
+
useAssistantFrameHost({
|
|
284
|
+
iframeRef: RefObject<HTMLIFrameElement>,
|
|
285
|
+
targetOrigin?: string,
|
|
286
|
+
});
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### ModelContextRegistry
|
|
290
|
+
|
|
291
|
+
A flexible registry for managing model context with dynamic updates.
|
|
292
|
+
|
|
293
|
+
#### Methods
|
|
294
|
+
|
|
295
|
+
##### `addTool(tool)`
|
|
296
|
+
|
|
297
|
+
Adds a tool and returns a handle for updates/removal.
|
|
298
|
+
|
|
299
|
+
```tsx
|
|
300
|
+
const handle = registry.addTool({
|
|
301
|
+
toolName: string,
|
|
302
|
+
description?: string,
|
|
303
|
+
parameters: ZodSchema | JSONSchema,
|
|
304
|
+
execute: (args, context) => Promise<any>,
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
handle.update(newTool); // Update the tool
|
|
308
|
+
handle.remove(); // Remove the tool
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
##### `addInstruction(instruction)`
|
|
312
|
+
|
|
313
|
+
Adds a system instruction and returns a handle.
|
|
314
|
+
|
|
315
|
+
```tsx
|
|
316
|
+
const handle = registry.addInstruction("Be concise.");
|
|
317
|
+
handle.update("Be detailed."); // Update instruction
|
|
318
|
+
handle.remove(); // Remove instruction
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
##### `addProvider(provider)`
|
|
322
|
+
|
|
323
|
+
Adds another model context provider.
|
|
324
|
+
|
|
325
|
+
```tsx
|
|
326
|
+
const handle = registry.addProvider(anotherProvider);
|
|
327
|
+
handle.remove(); // Remove provider
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## Use Cases
|
|
331
|
+
|
|
332
|
+
### Embedded Analytics Dashboard
|
|
333
|
+
|
|
334
|
+
An analytics iframe can provide data query tools to the parent assistant:
|
|
335
|
+
|
|
336
|
+
```tsx
|
|
337
|
+
// In analytics iframe
|
|
338
|
+
registry.addTool({
|
|
339
|
+
toolName: "queryMetrics",
|
|
340
|
+
description: "Query analytics data",
|
|
341
|
+
parameters: z.object({
|
|
342
|
+
metric: z.string(),
|
|
343
|
+
timeRange: z.string(),
|
|
344
|
+
}),
|
|
345
|
+
execute: async ({ metric, timeRange }) => {
|
|
346
|
+
const data = await analyticsAPI.query(metric, timeRange);
|
|
347
|
+
return { data, visualization: createChart(data) };
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### Plugin System
|
|
353
|
+
|
|
354
|
+
Third-party plugins can extend the assistant's capabilities:
|
|
355
|
+
|
|
356
|
+
```tsx
|
|
357
|
+
// In plugin iframe
|
|
358
|
+
registry.addTool({
|
|
359
|
+
toolName: "translateText",
|
|
360
|
+
description: "Translate text to another language",
|
|
361
|
+
parameters: z.object({
|
|
362
|
+
text: z.string(),
|
|
363
|
+
targetLanguage: z.string(),
|
|
364
|
+
}),
|
|
365
|
+
execute: async ({ text, targetLanguage }) => {
|
|
366
|
+
return await pluginAPI.translate(text, targetLanguage);
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### Data Visualization
|
|
372
|
+
|
|
373
|
+
Provide data visualization tools in an iframe:
|
|
374
|
+
|
|
375
|
+
```tsx
|
|
376
|
+
// In visualization iframe
|
|
377
|
+
registry.addTool({
|
|
378
|
+
toolName: "createChart",
|
|
379
|
+
description: "Generate a chart from data",
|
|
380
|
+
parameters: z.object({
|
|
381
|
+
data: z.array(
|
|
382
|
+
z.object({
|
|
383
|
+
label: z.string(),
|
|
384
|
+
value: z.number(),
|
|
385
|
+
}),
|
|
386
|
+
),
|
|
387
|
+
chartType: z.enum(["bar", "line", "pie"]),
|
|
388
|
+
title: z.string().optional(),
|
|
389
|
+
}),
|
|
390
|
+
execute: async ({ data, chartType, title }) => {
|
|
391
|
+
// Generate chart using a library like Chart.js or D3
|
|
392
|
+
const chartUrl = await generateChart(data, chartType, title);
|
|
393
|
+
return {
|
|
394
|
+
chartUrl,
|
|
395
|
+
summary: `Created ${chartType} chart with ${data.length} data points`,
|
|
396
|
+
};
|
|
397
|
+
},
|
|
398
|
+
});
|
|
399
|
+
```
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: DevTools
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
import { Step, Steps } from "fumadocs-ui/components/steps";
|
|
6
|
+
|
|
7
|
+
Hey, the assistant-ui DevTools allows you to debug the assistant-ui state and context, and events without resorting to `console.log`. It's an easy way to see how data flows to the assistant-ui's runtime layer.
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
<Steps>
|
|
14
|
+
<Step>
|
|
15
|
+
|
|
16
|
+
### Install the DevTools package
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @assistant-ui/react-devtools
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
</Step>
|
|
23
|
+
<Step>
|
|
24
|
+
|
|
25
|
+
### Mount the DevTools modal
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { AssistantRuntimeProvider } from "@assistant-ui/react";
|
|
29
|
+
import { DevToolsModal } from "@assistant-ui/react-devtools";
|
|
30
|
+
|
|
31
|
+
export function AssistantApp() {
|
|
32
|
+
return (
|
|
33
|
+
<AssistantRuntimeProvider>
|
|
34
|
+
<DevToolsModal />
|
|
35
|
+
{/* ...your assistant-ui... */}
|
|
36
|
+
</AssistantRuntimeProvider>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
</Step>
|
|
42
|
+
<Step>
|
|
43
|
+
|
|
44
|
+
### Verify the DevTools overlay
|
|
45
|
+
|
|
46
|
+
That's it! In development builds you should now see the DevTools in the lower-right corner of your site.
|
|
47
|
+
|
|
48
|
+

|
|
49
|
+
|
|
50
|
+
</Step>
|
|
51
|
+
</Steps>
|
|
@@ -22,7 +22,10 @@ import { Card, Cards } from "fumadocs-ui/components/card";
|
|
|
22
22
|
# Create a new project with the default template
|
|
23
23
|
npx assistant-ui@latest create
|
|
24
24
|
|
|
25
|
-
# Or
|
|
25
|
+
# Or choose one of the following templates:
|
|
26
|
+
# Assistant Cloud for baked in persistence and thread management
|
|
27
|
+
npx assistant-ui@latest create -t cloud
|
|
28
|
+
|
|
26
29
|
# LangGraph
|
|
27
30
|
npx assistant-ui@latest create -t langgraph
|
|
28
31
|
|
|
@@ -686,11 +689,11 @@ import { ComponentPropsWithoutRef, forwardRef } from "react";
|
|
|
686
689
|
import {
|
|
687
690
|
Tooltip,
|
|
688
691
|
TooltipContent,
|
|
689
|
-
TooltipProvider,
|
|
690
692
|
TooltipTrigger,
|
|
691
693
|
} from "@/components/ui/tooltip";
|
|
692
694
|
import { Button } from "@/components/ui/button";
|
|
693
695
|
import { cn } from "@/lib/utils";
|
|
696
|
+
import { Slottable } from "@radix-ui/react-slot";
|
|
694
697
|
|
|
695
698
|
export type TooltipIconButtonProps = ComponentPropsWithoutRef<typeof Button> & {
|
|
696
699
|
tooltip: string;
|
|
@@ -702,23 +705,21 @@ export const TooltipIconButton = forwardRef<
|
|
|
702
705
|
TooltipIconButtonProps
|
|
703
706
|
>(({ children, tooltip, side = "bottom", className, ...rest }, ref) => {
|
|
704
707
|
return (
|
|
705
|
-
<
|
|
706
|
-
<
|
|
707
|
-
<
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
>
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
</Tooltip>
|
|
721
|
-
</TooltipProvider>
|
|
708
|
+
<Tooltip>
|
|
709
|
+
<TooltipTrigger asChild>
|
|
710
|
+
<Button
|
|
711
|
+
variant="ghost"
|
|
712
|
+
size="icon"
|
|
713
|
+
{...rest}
|
|
714
|
+
className={cn("aui-button-icon", className)}
|
|
715
|
+
ref={ref}
|
|
716
|
+
>
|
|
717
|
+
<Slottable>{children}</Slottable>
|
|
718
|
+
<span className="aui-sr-only">{tooltip}</span>
|
|
719
|
+
</Button>
|
|
720
|
+
</TooltipTrigger>
|
|
721
|
+
<TooltipContent side={side}>{tooltip}</TooltipContent>
|
|
722
|
+
</Tooltip>
|
|
722
723
|
);
|
|
723
724
|
});
|
|
724
725
|
|