@assistant-ui/mcp-docs-server 0.1.32 → 0.1.34
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/waterfall.md +20 -22
- package/.docs/organized/code-examples/with-a2a.md +24 -24
- package/.docs/organized/code-examples/with-ag-ui.md +30 -25
- package/.docs/organized/code-examples/with-ai-sdk-v6.md +11 -9
- package/.docs/organized/code-examples/with-artifacts.md +49 -37
- package/.docs/organized/code-examples/with-assistant-transport.md +63 -51
- package/.docs/organized/code-examples/with-browser-extension.md +22 -10
- package/.docs/organized/code-examples/with-chain-of-thought.md +406 -87
- package/.docs/organized/code-examples/with-cloud-standalone.md +25 -24
- package/.docs/organized/code-examples/with-cloud.md +11 -9
- package/.docs/organized/code-examples/with-custom-thread-list.md +14 -12
- package/.docs/organized/code-examples/with-elevenlabs-conversational.md +23 -21
- package/.docs/organized/code-examples/with-elevenlabs-scribe.md +14 -13
- package/.docs/organized/code-examples/with-expo.md +44 -29
- package/.docs/organized/code-examples/with-external-store.md +9 -7
- package/.docs/organized/code-examples/with-ffmpeg.md +322 -285
- package/.docs/organized/code-examples/with-generative-ui.md +1066 -256
- package/.docs/organized/code-examples/with-google-adk.md +10 -8
- package/.docs/organized/code-examples/with-heat-graph.md +13 -11
- package/.docs/organized/code-examples/with-image-generation.md +19 -17
- package/.docs/organized/code-examples/with-interactables.md +317 -239
- package/.docs/organized/code-examples/with-langchain.md +14 -12
- package/.docs/organized/code-examples/with-langgraph.md +91 -83
- package/.docs/organized/code-examples/with-livekit.md +24 -22
- package/.docs/organized/code-examples/with-mcp.md +18 -12
- package/.docs/organized/code-examples/with-opencode.md +66 -66
- package/.docs/organized/code-examples/with-react-hook-form.md +19 -17
- package/.docs/organized/code-examples/with-react-ink.md +297 -102
- package/.docs/organized/code-examples/with-react-router.md +17 -15
- package/.docs/organized/code-examples/with-resumable-stream.md +15 -14
- package/.docs/organized/code-examples/with-store.md +78 -76
- package/.docs/organized/code-examples/with-tanstack.md +13 -14
- package/.docs/organized/code-examples/with-tap-runtime.md +26 -24
- package/.docs/raw/docs/(docs)/architecture.mdx +94 -42
- package/.docs/raw/docs/(docs)/cli.mdx +1 -2
- package/.docs/raw/docs/(docs)/installation.mdx +1 -1
- package/.docs/raw/docs/(reference)/api-reference/adapters/persistence.mdx +5 -1
- package/.docs/raw/docs/(reference)/api-reference/external-store/message-conversion.mdx +15 -15
- package/.docs/raw/docs/(reference)/api-reference/external-store/runtime.mdx +14 -1
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/index.mdx +18 -0
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/rendering.mdx +33 -0
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/spec.mdx +45 -0
- package/.docs/raw/docs/(reference)/api-reference/hooks/composer-triggers.mdx +41 -41
- package/.docs/raw/docs/(reference)/api-reference/hooks/model-context.mdx +19 -1
- package/.docs/raw/docs/(reference)/api-reference/hooks/primitives.mdx +122 -122
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-ai-sdk.mdx +43 -2
- package/.docs/raw/docs/(reference)/api-reference/model-context/context.mdx +6 -0
- package/.docs/raw/docs/(reference)/api-reference/overview.mdx +4 -6
- package/.docs/raw/docs/(reference)/api-reference/primitives/message.mdx +30 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/component-tools.mdx +20 -3
- package/.docs/raw/docs/(reference)/api-reference/tools/index.mdx +8 -8
- package/.docs/raw/docs/(reference)/api-reference/tools/rendering.mdx +52 -4
- package/.docs/raw/docs/(reference)/api-reference/tools/toolkits.mdx +100 -10
- package/.docs/raw/docs/(reference)/api-reference/utilities/miscellaneous.mdx +7 -59
- package/.docs/raw/docs/cloud/ai-sdk.mdx +0 -2
- package/.docs/raw/docs/{(docs)/copilots → copilots}/model-context.mdx +34 -26
- package/.docs/raw/docs/{(docs)/copilots → copilots}/motivation.mdx +32 -26
- package/.docs/raw/docs/guides/chain-of-thought.mdx +7 -9
- package/.docs/raw/docs/guides/context-api.mdx +2 -1
- package/.docs/raw/docs/guides/index.mdx +3 -12
- package/.docs/raw/docs/guides/mentions.mdx +4 -4
- package/.docs/raw/docs/guides/slash-commands.mdx +1 -1
- package/.docs/raw/docs/guides/suggestions.mdx +1 -1
- package/.docs/raw/docs/ink/adapters.mdx +23 -1
- package/.docs/raw/docs/ink/hooks.mdx +101 -85
- package/.docs/raw/docs/ink/migration.mdx +1 -1
- package/.docs/raw/docs/ink/primitives.mdx +2 -2
- package/.docs/raw/docs/integrations/frameworks/ai-sdk.mdx +1 -1
- package/.docs/raw/docs/integrations/index.mdx +2 -2
- package/.docs/raw/docs/integrations/persistence/custom-adapter.mdx +17 -2
- package/.docs/raw/docs/migrations/toolkit-tools.mdx +232 -0
- package/.docs/raw/docs/primitives/chain-of-thought.mdx +10 -16
- package/.docs/raw/docs/primitives/message.mdx +9 -10
- package/.docs/raw/docs/react-native/hooks.mdx +62 -79
- package/.docs/raw/docs/react-native/migration.mdx +1 -1
- package/.docs/raw/docs/react-native/primitives.mdx +2 -2
- package/.docs/raw/docs/runtimes/a2a/client-and-hooks.mdx +3 -0
- package/.docs/raw/docs/runtimes/ag-ui/runtime-options.mdx +41 -0
- package/.docs/raw/docs/runtimes/ai-sdk/v6.mdx +122 -1
- package/.docs/raw/docs/runtimes/concepts/architecture.mdx +46 -4
- package/.docs/raw/docs/runtimes/concepts/threads.mdx +7 -1
- package/.docs/raw/docs/runtimes/custom/assistant-transport.mdx +54 -12
- package/.docs/raw/docs/runtimes/custom/external-store.mdx +62 -4
- package/.docs/raw/docs/runtimes/custom/local-runtime.mdx +30 -7
- package/.docs/raw/docs/runtimes/google-adk/hooks.mdx +108 -38
- package/.docs/raw/docs/runtimes/langgraph/generative-ui.mdx +2 -2
- package/.docs/raw/docs/runtimes/langgraph/streaming.mdx +14 -1
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +64 -50
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +98 -86
- package/.docs/raw/docs/tools/backend.mdx +144 -0
- package/.docs/raw/docs/tools/defining-tools.mdx +538 -0
- package/.docs/raw/docs/tools/dynamic-tools.mdx +110 -0
- package/.docs/raw/docs/tools/generative-ui.mdx +214 -0
- package/.docs/raw/docs/tools/index.mdx +71 -0
- package/.docs/raw/docs/{guides → tools}/interactables.mdx +1 -1
- package/.docs/raw/docs/{integrations/tools → tools}/mcp.mdx +145 -50
- package/.docs/raw/docs/{guides → tools}/multi-agent.mdx +15 -17
- package/.docs/raw/docs/tools/tool-ui.mdx +967 -0
- package/.docs/raw/docs/{integrations/tools/react-mcp.mdx → tools/user-managed-mcp.mdx} +7 -7
- package/.docs/raw/docs/ui/directive-text.mdx +3 -3
- package/.docs/raw/docs/ui/mcp-config.mdx +4 -4
- package/.docs/raw/docs/ui/mermaid.mdx +16 -9
- package/.docs/raw/docs/ui/part-grouping.mdx +84 -50
- package/.docs/raw/docs/ui/reasoning.mdx +4 -5
- package/.docs/raw/docs/ui/tool-fallback.mdx +16 -0
- package/.docs/raw/docs/ui/tool-group.mdx +5 -6
- package/.docs/raw/docs/utilities/heat-graph.mdx +1 -1
- package/.docs/raw/docs/utilities/react-o11y.mdx +2 -2
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/prepare-docs/code-examples.d.ts.map +1 -1
- package/dist/prepare-docs/code-examples.js.map +1 -1
- package/dist/prepare-docs/copy-raw.d.ts.map +1 -1
- package/dist/prepare-docs/copy-raw.js.map +1 -1
- package/dist/prepare-docs/prepare.js.map +1 -1
- package/dist/stdio.js.map +1 -1
- package/dist/tools/docs.js.map +1 -1
- package/dist/tools/examples.js.map +1 -1
- package/dist/tools/tests/test-setup.js.map +1 -1
- package/dist/utils/mdx.js.map +1 -1
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js.map +1 -1
- package/package.json +5 -5
- package/.docs/organized/code-examples/with-parent-id-grouping.md +0 -596
- package/.docs/raw/docs/(docs)/copilots/make-assistant-tool-ui.mdx +0 -151
- package/.docs/raw/docs/(docs)/copilots/make-assistant-tool.mdx +0 -230
- package/.docs/raw/docs/guides/generative-ui.mdx +0 -142
- package/.docs/raw/docs/guides/tool-ui.mdx +0 -858
- package/.docs/raw/docs/guides/tools.mdx +0 -736
- /package/.docs/raw/docs/{(docs)/copilots → copilots}/assistant-frame.mdx +0 -0
- /package/.docs/raw/docs/{(docs)/copilots → copilots}/make-assistant-visible.mdx +0 -0
- /package/.docs/raw/docs/{(docs)/copilots → copilots}/use-assistant-instructions.mdx +0 -0
- /package/.docs/raw/docs/{guides → tools}/mcp-apps.mdx +0 -0
|
@@ -1,858 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Generative UI
|
|
3
|
-
description: Render AI tool calls as interactive React components — charts, forms, maps, and custom widgets. Build generative UI patterns in chat with assistant-ui.
|
|
4
|
-
platforms: ["react"]
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
import { ToolUISample } from "@/components/docs/samples/tool-ui";
|
|
8
|
-
|
|
9
|
-
Create custom UI components for AI tool calls, providing visual feedback and interactive experiences when tools are executed.
|
|
10
|
-
|
|
11
|
-
<ToolUISample />
|
|
12
|
-
|
|
13
|
-
## Overview
|
|
14
|
-
|
|
15
|
-
Tool UIs in assistant-ui allow you to create custom interfaces that appear when AI tools are called. These generative UI components enhance the user experience by:
|
|
16
|
-
|
|
17
|
-
- **Visualizing tool execution** with loading states and progress indicators
|
|
18
|
-
- **Displaying results** in rich, formatted layouts
|
|
19
|
-
- **Enabling user interaction** through forms and controls
|
|
20
|
-
- **Providing error feedback** with helpful recovery options
|
|
21
|
-
|
|
22
|
-
This guide demonstrates building tool UIs with the **Vercel AI SDK**.
|
|
23
|
-
|
|
24
|
-
## Creating Tool UIs
|
|
25
|
-
|
|
26
|
-
There are two main approaches to creating tool UIs in assistant-ui:
|
|
27
|
-
|
|
28
|
-
### 1. Client-Defined Tools (`makeAssistantTool`)
|
|
29
|
-
|
|
30
|
-
If you're creating tools on the client side, use `makeAssistantTool` to register them with the assistant context. Then create a UI component with `makeAssistantToolUI`. This component-based API coexists with the [Tools()](/docs/guides/tools) toolkit API; pick whichever fits your codebase better.
|
|
31
|
-
|
|
32
|
-
```tsx
|
|
33
|
-
import { makeAssistantTool, tool } from "@assistant-ui/react";
|
|
34
|
-
import { z } from "zod";
|
|
35
|
-
|
|
36
|
-
// Define the tool
|
|
37
|
-
const weatherTool = tool({
|
|
38
|
-
description: "Get current weather for a location",
|
|
39
|
-
parameters: z.object({
|
|
40
|
-
location: z.string(),
|
|
41
|
-
unit: z.enum(["celsius", "fahrenheit"]),
|
|
42
|
-
}),
|
|
43
|
-
execute: async ({ location, unit }) => {
|
|
44
|
-
const weather = await fetchWeatherAPI(location, unit);
|
|
45
|
-
return weather;
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// Register the tool
|
|
50
|
-
const WeatherTool = makeAssistantTool({
|
|
51
|
-
...weatherTool,
|
|
52
|
-
toolName: "getWeather",
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// Create the UI
|
|
56
|
-
const WeatherToolUI = makeAssistantToolUI<
|
|
57
|
-
{ location: string; unit: "celsius" | "fahrenheit" },
|
|
58
|
-
{ temperature: number; description: string }
|
|
59
|
-
>({
|
|
60
|
-
toolName: "getWeather",
|
|
61
|
-
render: ({ args, result, status }) => {
|
|
62
|
-
if (status.type === "running") {
|
|
63
|
-
return <div>Checking weather in {args.location}...</div>;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<div className="weather-card">
|
|
68
|
-
<h3>{args.location}</h3>
|
|
69
|
-
<p>
|
|
70
|
-
{result.temperature}°{args.unit === "celsius" ? "C" : "F"}
|
|
71
|
-
</p>
|
|
72
|
-
<p>{result.description}</p>
|
|
73
|
-
</div>
|
|
74
|
-
);
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
<Callout type="tip">
|
|
80
|
-
Tools defined with `makeAssistantTool` can be passed to your backend using the
|
|
81
|
-
`frontendTools` utility
|
|
82
|
-
</Callout>
|
|
83
|
-
|
|
84
|
-
Learn more about creating tools in the [Tools Guide](/docs/guides/tools).
|
|
85
|
-
|
|
86
|
-
### 2. UI-Only for Existing Tools (`makeAssistantToolUI`)
|
|
87
|
-
|
|
88
|
-
If your tool is defined elsewhere (e.g., in your backend API, MCP server, or LangGraph), use `makeAssistantToolUI` to create just the UI component:
|
|
89
|
-
|
|
90
|
-
```tsx
|
|
91
|
-
import { makeAssistantToolUI } from "@assistant-ui/react";
|
|
92
|
-
|
|
93
|
-
const WeatherToolUI = makeAssistantToolUI<
|
|
94
|
-
{ location: string; unit: "celsius" | "fahrenheit" },
|
|
95
|
-
{ temperature: number; description: string }
|
|
96
|
-
>({
|
|
97
|
-
toolName: "getWeather", // Must match the backend tool name
|
|
98
|
-
render: ({ args, result, status }) => {
|
|
99
|
-
// UI rendering logic only
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
## Quick Start Example
|
|
105
|
-
|
|
106
|
-
This example shows how to implement the UI-only approach using `makeAssistantToolUI`:
|
|
107
|
-
|
|
108
|
-
<Steps>
|
|
109
|
-
<Step>
|
|
110
|
-
|
|
111
|
-
### Create a Tool UI Component
|
|
112
|
-
|
|
113
|
-
```tsx
|
|
114
|
-
import { makeAssistantToolUI } from "@assistant-ui/react";
|
|
115
|
-
import { z } from "zod";
|
|
116
|
-
|
|
117
|
-
type WeatherArgs = {
|
|
118
|
-
location: string;
|
|
119
|
-
unit: "celsius" | "fahrenheit";
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
type WeatherResult = {
|
|
123
|
-
temperature: number;
|
|
124
|
-
description: string;
|
|
125
|
-
humidity: number;
|
|
126
|
-
windSpeed: number;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const WeatherToolUI = makeAssistantToolUI<WeatherArgs, WeatherResult>({
|
|
130
|
-
toolName: "getWeather",
|
|
131
|
-
render: ({ args, status, result }) => {
|
|
132
|
-
if (status.type === "running") {
|
|
133
|
-
return (
|
|
134
|
-
<div className="flex items-center gap-2">
|
|
135
|
-
<Spinner />
|
|
136
|
-
<span>Checking weather in {args.location}...</span>
|
|
137
|
-
</div>
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (status.type === "incomplete" && status.reason === "error") {
|
|
142
|
-
return (
|
|
143
|
-
<div className="text-red-500">
|
|
144
|
-
Failed to get weather for {args.location}
|
|
145
|
-
</div>
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return (
|
|
150
|
-
<div className="weather-card rounded-lg bg-blue-50 p-4">
|
|
151
|
-
<h3 className="text-lg font-bold">{args.location}</h3>
|
|
152
|
-
<div className="mt-2 grid grid-cols-2 gap-4">
|
|
153
|
-
<div>
|
|
154
|
-
<p className="text-2xl">
|
|
155
|
-
{result.temperature}°{args.unit === "celsius" ? "C" : "F"}
|
|
156
|
-
</p>
|
|
157
|
-
<p className="text-gray-600">{result.description}</p>
|
|
158
|
-
</div>
|
|
159
|
-
<div className="text-sm">
|
|
160
|
-
<p>Humidity: {result.humidity}%</p>
|
|
161
|
-
<p>Wind: {result.windSpeed} km/h</p>
|
|
162
|
-
</div>
|
|
163
|
-
</div>
|
|
164
|
-
</div>
|
|
165
|
-
);
|
|
166
|
-
},
|
|
167
|
-
});
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
</Step>
|
|
171
|
-
<Step>
|
|
172
|
-
|
|
173
|
-
### Register the Tool UI
|
|
174
|
-
|
|
175
|
-
Place the component inside your `AssistantRuntimeProvider`:
|
|
176
|
-
|
|
177
|
-
```tsx
|
|
178
|
-
function App() {
|
|
179
|
-
return (
|
|
180
|
-
<AssistantRuntimeProvider runtime={runtime}>
|
|
181
|
-
<Thread />
|
|
182
|
-
<WeatherToolUI />
|
|
183
|
-
</AssistantRuntimeProvider>
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
</Step>
|
|
189
|
-
<Step>
|
|
190
|
-
|
|
191
|
-
### Define the Backend Tool (Vercel AI SDK)
|
|
192
|
-
|
|
193
|
-
When using the Vercel AI SDK, define the corresponding tool in your API route:
|
|
194
|
-
|
|
195
|
-
```tsx title="/app/api/chat/route.ts"
|
|
196
|
-
import { streamText, tool, zodSchema } from "ai";
|
|
197
|
-
import { z } from "zod";
|
|
198
|
-
|
|
199
|
-
export async function POST(req: Request) {
|
|
200
|
-
const { messages } = await req.json();
|
|
201
|
-
|
|
202
|
-
const result = streamText({
|
|
203
|
-
model: openai("gpt-5.4-nano"),
|
|
204
|
-
messages: await convertToModelMessages(messages),
|
|
205
|
-
tools: {
|
|
206
|
-
getWeather: tool({
|
|
207
|
-
description: "Get current weather for a location",
|
|
208
|
-
inputSchema: zodSchema(
|
|
209
|
-
z.object({
|
|
210
|
-
location: z.string(),
|
|
211
|
-
unit: z.enum(["celsius", "fahrenheit"]),
|
|
212
|
-
}),
|
|
213
|
-
),
|
|
214
|
-
execute: async ({ location, unit }) => {
|
|
215
|
-
const weather = await fetchWeatherAPI(location);
|
|
216
|
-
return {
|
|
217
|
-
temperature: weather.temp,
|
|
218
|
-
description: weather.condition,
|
|
219
|
-
humidity: weather.humidity,
|
|
220
|
-
windSpeed: weather.wind,
|
|
221
|
-
};
|
|
222
|
-
},
|
|
223
|
-
}),
|
|
224
|
-
},
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
return result.toUIMessageStreamResponse();
|
|
228
|
-
}
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
</Step>
|
|
232
|
-
</Steps>
|
|
233
|
-
|
|
234
|
-
## Tool UI Patterns
|
|
235
|
-
|
|
236
|
-
### Component Pattern
|
|
237
|
-
|
|
238
|
-
Create standalone tool UI components:
|
|
239
|
-
|
|
240
|
-
```tsx
|
|
241
|
-
export const WebSearchToolUI = makeAssistantToolUI<
|
|
242
|
-
{ query: string },
|
|
243
|
-
{ results: SearchResult[] }
|
|
244
|
-
>({
|
|
245
|
-
toolName: "webSearch",
|
|
246
|
-
render: ({ args, status, result }) => {
|
|
247
|
-
return (
|
|
248
|
-
<div className="search-container">
|
|
249
|
-
<div className="mb-3 flex items-center gap-2">
|
|
250
|
-
<SearchIcon />
|
|
251
|
-
<span>Search results for: "{args.query}"</span>
|
|
252
|
-
</div>
|
|
253
|
-
|
|
254
|
-
{status.type === "running" && <LoadingSpinner />}
|
|
255
|
-
|
|
256
|
-
{result && (
|
|
257
|
-
<div className="space-y-2">
|
|
258
|
-
{result.results.map((item, index) => (
|
|
259
|
-
<div key={index} className="rounded border p-3">
|
|
260
|
-
<a href={item.url} className="font-medium text-blue-600">
|
|
261
|
-
{item.title}
|
|
262
|
-
</a>
|
|
263
|
-
<p className="text-sm text-gray-600">{item.snippet}</p>
|
|
264
|
-
</div>
|
|
265
|
-
))}
|
|
266
|
-
</div>
|
|
267
|
-
)}
|
|
268
|
-
</div>
|
|
269
|
-
);
|
|
270
|
-
},
|
|
271
|
-
});
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
### Hook Pattern
|
|
275
|
-
|
|
276
|
-
Use hooks for dynamic tool UI registration:
|
|
277
|
-
|
|
278
|
-
<Callout type="tip">
|
|
279
|
-
Use the `useAssistantToolUI` hook directly in your component for dynamic tool UI registration. This allows access to local component state and props when rendering the tool UI.
|
|
280
|
-
</Callout>
|
|
281
|
-
|
|
282
|
-
```tsx
|
|
283
|
-
import { useAssistantToolUI } from "@assistant-ui/react";
|
|
284
|
-
|
|
285
|
-
function DynamicToolUI() {
|
|
286
|
-
const [theme, setTheme] = useState("light");
|
|
287
|
-
|
|
288
|
-
useAssistantToolUI({
|
|
289
|
-
toolName: "analyzeData",
|
|
290
|
-
render: ({ args, result, status }) => {
|
|
291
|
-
// Hook allows access to component state
|
|
292
|
-
return (
|
|
293
|
-
<DataVisualization
|
|
294
|
-
data={result}
|
|
295
|
-
theme={theme}
|
|
296
|
-
loading={status.type === "running"}
|
|
297
|
-
/>
|
|
298
|
-
);
|
|
299
|
-
},
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
return null;
|
|
303
|
-
}
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
### Inline Pattern
|
|
307
|
-
|
|
308
|
-
For tools that need access to parent component props:
|
|
309
|
-
|
|
310
|
-
<Callout type="tip">
|
|
311
|
-
**Why `useInlineRender`?** By default, a tool UI's `render` function is
|
|
312
|
-
static. Use `useInlineRender` when your UI needs access to dynamic component
|
|
313
|
-
props (for example, to pass in an `id` or other contextual data).
|
|
314
|
-
</Callout>
|
|
315
|
-
|
|
316
|
-
```tsx
|
|
317
|
-
import { useAssistantToolUI, useInlineRender } from "@assistant-ui/react";
|
|
318
|
-
|
|
319
|
-
function ProductPage({ productId, productName }) {
|
|
320
|
-
useAssistantToolUI({
|
|
321
|
-
toolName: "checkInventory",
|
|
322
|
-
render: useInlineRender(({ args, result }) => {
|
|
323
|
-
// Access parent component props
|
|
324
|
-
return (
|
|
325
|
-
<div className="inventory-status">
|
|
326
|
-
<h4>{productName} Inventory</h4>
|
|
327
|
-
<p>
|
|
328
|
-
Stock for {productId}: {result.quantity} units
|
|
329
|
-
</p>
|
|
330
|
-
<p>Location: {result.warehouse}</p>
|
|
331
|
-
</div>
|
|
332
|
-
);
|
|
333
|
-
}),
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
return <div>Product details...</div>;
|
|
337
|
-
}
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
## Interactive Tool UIs
|
|
341
|
-
|
|
342
|
-
### User Input Collection
|
|
343
|
-
|
|
344
|
-
Create tools that collect user input during execution:
|
|
345
|
-
|
|
346
|
-
<Callout type="tip">
|
|
347
|
-
**Pro tip:** Call `addResult(...)` exactly once to complete the tool call.
|
|
348
|
-
After it's invoked, the assistant will resume the conversation with your
|
|
349
|
-
provided data.
|
|
350
|
-
</Callout>
|
|
351
|
-
|
|
352
|
-
```tsx
|
|
353
|
-
const DatePickerToolUI = makeAssistantToolUI<
|
|
354
|
-
{ prompt: string },
|
|
355
|
-
{ date: string }
|
|
356
|
-
>({
|
|
357
|
-
toolName: "selectDate",
|
|
358
|
-
render: ({ args, result, addResult }) => {
|
|
359
|
-
if (result) {
|
|
360
|
-
return (
|
|
361
|
-
<div className="rounded bg-green-50 p-3">
|
|
362
|
-
✅ Selected date: {new Date(result.date).toLocaleDateString()}
|
|
363
|
-
</div>
|
|
364
|
-
);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
return (
|
|
368
|
-
<div className="rounded border p-4">
|
|
369
|
-
<p className="mb-3">{args.prompt}</p>
|
|
370
|
-
<DatePicker
|
|
371
|
-
onChange={(date) => {
|
|
372
|
-
addResult({ date: date.toISOString() });
|
|
373
|
-
}}
|
|
374
|
-
/>
|
|
375
|
-
</div>
|
|
376
|
-
);
|
|
377
|
-
},
|
|
378
|
-
});
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
### Multi-Step Interactions
|
|
382
|
-
|
|
383
|
-
Build complex workflows with human-in-the-loop patterns for multi-step user interactions:
|
|
384
|
-
|
|
385
|
-
```tsx
|
|
386
|
-
const DeleteProjectTool = makeAssistantTool({
|
|
387
|
-
toolName: "deleteProject",
|
|
388
|
-
parameters: z.object({
|
|
389
|
-
projectId: z.string(),
|
|
390
|
-
}),
|
|
391
|
-
execute: async ({ projectId }, { human }) => {
|
|
392
|
-
const response = await human({ action, details });
|
|
393
|
-
if (!response.approved) throw new Error("Project deletion cancelled");
|
|
394
|
-
|
|
395
|
-
await deleteProject(projectId);
|
|
396
|
-
return { success: true };
|
|
397
|
-
},
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
const ApprovalTool = makeAssistantTool({
|
|
401
|
-
...tool({
|
|
402
|
-
description: "Request user approval for an action",
|
|
403
|
-
parameters: z.object({
|
|
404
|
-
action: z.string(),
|
|
405
|
-
details: z.any(),
|
|
406
|
-
}),
|
|
407
|
-
execute: async ({ action, details }, { human }) => {
|
|
408
|
-
// Request approval from user
|
|
409
|
-
const response = await human({ action, details });
|
|
410
|
-
|
|
411
|
-
return {
|
|
412
|
-
approved: response.approved,
|
|
413
|
-
reason: response.reason,
|
|
414
|
-
};
|
|
415
|
-
},
|
|
416
|
-
}),
|
|
417
|
-
toolName: "requestApproval",
|
|
418
|
-
render: ({ args, result, interrupt, resume }) => {
|
|
419
|
-
const [reason, setReason] = useState("");
|
|
420
|
-
|
|
421
|
-
// Show result after approval/rejection
|
|
422
|
-
if (result) {
|
|
423
|
-
return (
|
|
424
|
-
<div className={result.approved ? "text-green-600" : "text-red-600"}>
|
|
425
|
-
{result.approved ? "✅ Approved" : `❌ Rejected: ${result.reason}`}
|
|
426
|
-
</div>
|
|
427
|
-
);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
// Show approval UI when waiting for user input
|
|
431
|
-
if (interrupt) {
|
|
432
|
-
return (
|
|
433
|
-
<div className="rounded border-2 border-yellow-400 p-4">
|
|
434
|
-
<h4 className="font-bold">Approval Required</h4>
|
|
435
|
-
<p className="my-2">{interrupt.payload.action}</p>
|
|
436
|
-
<pre className="rounded bg-gray-100 p-2 text-sm">
|
|
437
|
-
{JSON.stringify(interrupt.payload.details, null, 2)}
|
|
438
|
-
</pre>
|
|
439
|
-
|
|
440
|
-
<div className="mt-4 flex gap-2">
|
|
441
|
-
<button
|
|
442
|
-
onClick={() => resume({ approved: true })}
|
|
443
|
-
className="rounded bg-green-500 px-4 py-2 text-white"
|
|
444
|
-
>
|
|
445
|
-
Approve
|
|
446
|
-
</button>
|
|
447
|
-
<button
|
|
448
|
-
onClick={() => resume({ approved: false, reason })}
|
|
449
|
-
className="rounded bg-red-500 px-4 py-2 text-white"
|
|
450
|
-
>
|
|
451
|
-
Reject
|
|
452
|
-
</button>
|
|
453
|
-
<input
|
|
454
|
-
type="text"
|
|
455
|
-
placeholder="Rejection reason..."
|
|
456
|
-
value={reason}
|
|
457
|
-
onChange={(e) => setReason(e.target.value)}
|
|
458
|
-
className="flex-1 rounded border px-2"
|
|
459
|
-
/>
|
|
460
|
-
</div>
|
|
461
|
-
</div>
|
|
462
|
-
);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
return <div>Processing...</div>;
|
|
466
|
-
},
|
|
467
|
-
});
|
|
468
|
-
```
|
|
469
|
-
|
|
470
|
-
<Callout type="tip">
|
|
471
|
-
Use tool human input (`human()` / `resume()`) for workflows that need to
|
|
472
|
-
pause tool execution and wait for user input. Use `addResult()` for "human
|
|
473
|
-
tools" where the AI requests a tool call but the entire execution happens
|
|
474
|
-
through user interaction.
|
|
475
|
-
</Callout>
|
|
476
|
-
|
|
477
|
-
## Advanced Features
|
|
478
|
-
|
|
479
|
-
### Tool Status Handling
|
|
480
|
-
|
|
481
|
-
The `status` prop provides detailed execution state:
|
|
482
|
-
|
|
483
|
-
```tsx
|
|
484
|
-
render: ({ status, args }) => {
|
|
485
|
-
switch (status.type) {
|
|
486
|
-
case "running":
|
|
487
|
-
return <LoadingState />;
|
|
488
|
-
|
|
489
|
-
case "requires-action":
|
|
490
|
-
return <UserInputRequired reason={status.reason} />;
|
|
491
|
-
|
|
492
|
-
case "incomplete":
|
|
493
|
-
if (status.reason === "cancelled") {
|
|
494
|
-
return <div>Operation cancelled</div>;
|
|
495
|
-
}
|
|
496
|
-
if (status.reason === "error") {
|
|
497
|
-
return <ErrorDisplay error={status.error} />;
|
|
498
|
-
}
|
|
499
|
-
return <div>Failed: {status.reason}</div>;
|
|
500
|
-
|
|
501
|
-
case "complete":
|
|
502
|
-
return <SuccessDisplay />;
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
```
|
|
506
|
-
|
|
507
|
-
### Deferred Rendering
|
|
508
|
-
|
|
509
|
-
<Callout type="info">
|
|
510
|
-
This section applies when the model **drives** the component through a tool call (args arrive incrementally and you want to wait for the final shape). If your backend or orchestrator pushes the component instead, prefer [Data-Part Generative UI](#data-part-generative-ui) with `makeAssistantDataUI`. Data parts arrive as terminal events, so the renderer only fires once with the final data, no deferred rendering needed.
|
|
511
|
-
</Callout>
|
|
512
|
-
|
|
513
|
-
Sometimes you want to capture a tool call's streaming arguments but only render the final UI once the call completes. This is useful when partial args would render misleading or jarring intermediate states (a chart that flashes through half-populated data), when the component is expensive to mount (heavy visualizations, embedded iframes, third-party widgets), or when the model controls *whether* the component appears at all.
|
|
514
|
-
|
|
515
|
-
#### Inline at the end of streaming
|
|
516
|
-
|
|
517
|
-
Return `null` from the tool UI's `render` until `status.type === "complete"`. The streaming args still arrive in `args` as the model emits them, you just ignore them until the call is done:
|
|
518
|
-
|
|
519
|
-
```tsx
|
|
520
|
-
const ChartToolUI = makeAssistantToolUI<
|
|
521
|
-
{ title: string; series: number[] },
|
|
522
|
-
void
|
|
523
|
-
>({
|
|
524
|
-
toolName: "renderChart",
|
|
525
|
-
render: ({ args, status }) => {
|
|
526
|
-
if (status.type !== "complete") return null;
|
|
527
|
-
return <Chart title={args.title} data={args.series} />;
|
|
528
|
-
},
|
|
529
|
-
});
|
|
530
|
-
```
|
|
531
|
-
|
|
532
|
-
The chart mounts once, with the final args, after streaming finishes. No re-renders during the stream.
|
|
533
|
-
|
|
534
|
-
The same `render` shape works inside the [`Tools()`](/docs/guides/tools) toolkit's `render` field, with `useAssistantToolUI`, and with `MessagePrimitive.Parts`'s inline `tools.by_name` overrides. The deferred-rendering pattern applies regardless of how you registered the tool UI.
|
|
535
|
-
|
|
536
|
-
#### Below the message body
|
|
537
|
-
|
|
538
|
-
If the component should sit *outside* the message parts (for example, a card attached under the avatar block rather than inline with text), gate at the message level with [`AuiIf`](/docs/api-reference/primitives/assistant-if) and read `s.message.status`:
|
|
539
|
-
|
|
540
|
-
```tsx
|
|
541
|
-
import { MessagePrimitive, AuiIf, useAuiState } from "@assistant-ui/react";
|
|
542
|
-
|
|
543
|
-
function PostMessageCard() {
|
|
544
|
-
const parts = useAuiState((s) => s.message.parts);
|
|
545
|
-
const chartCall = parts.find(
|
|
546
|
-
(p) => p.type === "tool-call" && p.toolName === "renderChart",
|
|
547
|
-
);
|
|
548
|
-
if (!chartCall) return null;
|
|
549
|
-
return <Chart {...chartCall.args} />;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
<MessagePrimitive.Root>
|
|
553
|
-
<MessagePrimitive.Parts />
|
|
554
|
-
|
|
555
|
-
<AuiIf
|
|
556
|
-
condition={(s) =>
|
|
557
|
-
s.message.role === "assistant" &&
|
|
558
|
-
s.message.status?.type === "complete"
|
|
559
|
-
}
|
|
560
|
-
>
|
|
561
|
-
<PostMessageCard />
|
|
562
|
-
</AuiIf>
|
|
563
|
-
</MessagePrimitive.Root>;
|
|
564
|
-
```
|
|
565
|
-
|
|
566
|
-
The `AuiIf` predicate fires whenever the assistant state changes; children mount only when both checks pass. `PostMessageCard` then reads the captured tool-call part from `s.message.parts` and renders from its args.
|
|
567
|
-
|
|
568
|
-
For the opposite pattern (showing partial data as it streams in), see [Field-Level Streaming State](#field-level-streaming-state) and [Partial Results & Streaming](#partial-results--streaming) below.
|
|
569
|
-
|
|
570
|
-
### Field-Level Streaming State
|
|
571
|
-
|
|
572
|
-
Use `useToolArgsStatus` to react to per-field streaming state. The hook returns a `propStatus` map where each top-level key in the args object resolves from `"streaming"` to `"complete"` as the partial JSON arrives. Call it inside a tool-call message part context:
|
|
573
|
-
|
|
574
|
-
```tsx
|
|
575
|
-
import { useToolArgsStatus } from "@assistant-ui/react";
|
|
576
|
-
|
|
577
|
-
const FormToolUI = makeAssistantToolUI<{ email: string; phone: string }, unknown>({
|
|
578
|
-
toolName: "submitForm",
|
|
579
|
-
render: ({ args }) => {
|
|
580
|
-
const { propStatus } = useToolArgsStatus<{ email: string; phone: string }>();
|
|
581
|
-
|
|
582
|
-
return (
|
|
583
|
-
<form className="space-y-4">
|
|
584
|
-
<div>
|
|
585
|
-
<input
|
|
586
|
-
type="email"
|
|
587
|
-
value={args.email ?? ""}
|
|
588
|
-
className={propStatus.email === "streaming" ? "loading" : ""}
|
|
589
|
-
disabled
|
|
590
|
-
/>
|
|
591
|
-
</div>
|
|
592
|
-
|
|
593
|
-
<div>
|
|
594
|
-
<input
|
|
595
|
-
type="tel"
|
|
596
|
-
value={args.phone ?? ""}
|
|
597
|
-
className={propStatus.phone === "streaming" ? "loading" : ""}
|
|
598
|
-
disabled
|
|
599
|
-
/>
|
|
600
|
-
</div>
|
|
601
|
-
</form>
|
|
602
|
-
);
|
|
603
|
-
},
|
|
604
|
-
});
|
|
605
|
-
```
|
|
606
|
-
|
|
607
|
-
### Partial Results & Streaming
|
|
608
|
-
|
|
609
|
-
Display results as they stream in:
|
|
610
|
-
|
|
611
|
-
```tsx
|
|
612
|
-
const AnalysisToolUI = makeAssistantToolUI<
|
|
613
|
-
{ data: string },
|
|
614
|
-
{ progress: number; insights: string[] }
|
|
615
|
-
>({
|
|
616
|
-
toolName: "analyzeData",
|
|
617
|
-
render: ({ result, status }) => {
|
|
618
|
-
const progress = result?.progress || 0;
|
|
619
|
-
const insights = result?.insights || [];
|
|
620
|
-
|
|
621
|
-
return (
|
|
622
|
-
<div className="analysis-container">
|
|
623
|
-
{status.type === "running" && (
|
|
624
|
-
<div className="mb-4">
|
|
625
|
-
<div className="mb-1 flex justify-between">
|
|
626
|
-
<span>Analyzing...</span>
|
|
627
|
-
<span>{progress}%</span>
|
|
628
|
-
</div>
|
|
629
|
-
<div className="w-full rounded bg-gray-200">
|
|
630
|
-
<div
|
|
631
|
-
className="h-2 rounded bg-blue-500"
|
|
632
|
-
style={{ width: `${progress}%` }}
|
|
633
|
-
/>
|
|
634
|
-
</div>
|
|
635
|
-
</div>
|
|
636
|
-
)}
|
|
637
|
-
|
|
638
|
-
<div className="space-y-2">
|
|
639
|
-
{insights.map((insight, i) => (
|
|
640
|
-
<div key={i} className="rounded bg-gray-50 p-2">
|
|
641
|
-
{insight}
|
|
642
|
-
</div>
|
|
643
|
-
))}
|
|
644
|
-
</div>
|
|
645
|
-
</div>
|
|
646
|
-
);
|
|
647
|
-
},
|
|
648
|
-
});
|
|
649
|
-
```
|
|
650
|
-
|
|
651
|
-
### Custom Tool Fallback
|
|
652
|
-
|
|
653
|
-
For tools that have no dedicated UI, add the `ToolFallback` shadcn component to your project. See the [ToolFallback install guide](/docs/ui/tool-fallback) for setup instructions and the [ToolGroup guide](/docs/ui/tool-group) for grouping consecutive tool calls into a collapsible container.
|
|
654
|
-
|
|
655
|
-
## Execution Context
|
|
656
|
-
|
|
657
|
-
Generative UI components have access to execution context through props:
|
|
658
|
-
|
|
659
|
-
```tsx
|
|
660
|
-
type ToolCallMessagePartProps<TArgs, TResult> = {
|
|
661
|
-
// Tool arguments
|
|
662
|
-
args: TArgs;
|
|
663
|
-
argsText: string; // JSON stringified args
|
|
664
|
-
|
|
665
|
-
// Execution status
|
|
666
|
-
status: ToolCallMessagePartStatus;
|
|
667
|
-
isError?: boolean;
|
|
668
|
-
|
|
669
|
-
// Tool result (may be partial during streaming)
|
|
670
|
-
result?: TResult;
|
|
671
|
-
|
|
672
|
-
// Tool metadata
|
|
673
|
-
toolName: string;
|
|
674
|
-
toolCallId: string;
|
|
675
|
-
|
|
676
|
-
// Interactive callbacks
|
|
677
|
-
addResult: (result: TResult | ToolResponse<TResult>) => void;
|
|
678
|
-
resume: (payload: unknown) => void;
|
|
679
|
-
|
|
680
|
-
// Interrupt state
|
|
681
|
-
interrupt?: { type: "human"; payload: unknown }; // Payload from context.human()
|
|
682
|
-
|
|
683
|
-
// Optional artifact data
|
|
684
|
-
artifact?: unknown;
|
|
685
|
-
};
|
|
686
|
-
```
|
|
687
|
-
|
|
688
|
-
### Human Input Handling
|
|
689
|
-
|
|
690
|
-
When a tool calls `human()` during execution, the payload becomes available in the render function as `interrupt.payload`:
|
|
691
|
-
|
|
692
|
-
```tsx
|
|
693
|
-
const ConfirmationToolUI = makeAssistantToolUI<
|
|
694
|
-
{ action: string },
|
|
695
|
-
{ confirmed: boolean }
|
|
696
|
-
>({
|
|
697
|
-
toolName: "confirmAction",
|
|
698
|
-
render: ({ args, result, interrupt, resume }) => {
|
|
699
|
-
// Tool is waiting for user input
|
|
700
|
-
if (interrupt) {
|
|
701
|
-
return (
|
|
702
|
-
<div className="confirmation-dialog">
|
|
703
|
-
<p>Confirm: {interrupt.payload.message}</p>
|
|
704
|
-
<button onClick={() => resume(true)}>Yes</button>
|
|
705
|
-
<button onClick={() => resume(false)}>No</button>
|
|
706
|
-
</div>
|
|
707
|
-
);
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
// Tool completed
|
|
711
|
-
if (result) {
|
|
712
|
-
return <div>Action {result.confirmed ? "confirmed" : "cancelled"}</div>;
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
return <div>Processing...</div>;
|
|
716
|
-
},
|
|
717
|
-
});
|
|
718
|
-
```
|
|
719
|
-
|
|
720
|
-
Learn more about tool human input in the [Tools Guide](/docs/guides/tools#human-in-the-loop).
|
|
721
|
-
|
|
722
|
-
## Best Practices
|
|
723
|
-
|
|
724
|
-
### 1. Handle All Status States
|
|
725
|
-
|
|
726
|
-
Always handle loading, error, and success states:
|
|
727
|
-
|
|
728
|
-
```tsx
|
|
729
|
-
render: ({ status, result, args }) => {
|
|
730
|
-
if (status.type === "running") return <Skeleton />;
|
|
731
|
-
if (status.type === "incomplete") return <ErrorState />;
|
|
732
|
-
if (!result) return null;
|
|
733
|
-
return <ResultDisplay result={result} />;
|
|
734
|
-
};
|
|
735
|
-
```
|
|
736
|
-
|
|
737
|
-
### 2. Provide Visual Feedback
|
|
738
|
-
|
|
739
|
-
Use animations and transitions for better UX:
|
|
740
|
-
|
|
741
|
-
```tsx
|
|
742
|
-
<div
|
|
743
|
-
className={cn(
|
|
744
|
-
"transition-all duration-300",
|
|
745
|
-
status.type === "running" && "opacity-50",
|
|
746
|
-
status.type === "complete" && "opacity-100",
|
|
747
|
-
)}
|
|
748
|
-
>
|
|
749
|
-
{/* Tool UI content */}
|
|
750
|
-
</div>
|
|
751
|
-
```
|
|
752
|
-
|
|
753
|
-
### 3. Make UIs Accessible
|
|
754
|
-
|
|
755
|
-
Ensure keyboard navigation and screen reader support:
|
|
756
|
-
|
|
757
|
-
```tsx
|
|
758
|
-
<button
|
|
759
|
-
onClick={() => addResult(value)}
|
|
760
|
-
aria-label="Confirm selection"
|
|
761
|
-
className="focus:outline-none focus:ring-2"
|
|
762
|
-
>
|
|
763
|
-
Confirm
|
|
764
|
-
</button>
|
|
765
|
-
```
|
|
766
|
-
|
|
767
|
-
### 4. Optimize Performance
|
|
768
|
-
|
|
769
|
-
Use `useInlineRender` to prevent unnecessary re-renders:
|
|
770
|
-
|
|
771
|
-
```tsx
|
|
772
|
-
useAssistantToolUI({
|
|
773
|
-
toolName: "heavyComputation",
|
|
774
|
-
render: useInlineRender(({ result }) => {
|
|
775
|
-
// Expensive rendering logic
|
|
776
|
-
return <ComplexVisualization data={result} />;
|
|
777
|
-
}),
|
|
778
|
-
});
|
|
779
|
-
```
|
|
780
|
-
|
|
781
|
-
<Callout>
|
|
782
|
-
Generative UI components are only displayed in the chat interface. The actual
|
|
783
|
-
tool execution happens on the backend. This separation allows you to create
|
|
784
|
-
rich, interactive experiences while keeping sensitive logic secure on the
|
|
785
|
-
server.
|
|
786
|
-
</Callout>
|
|
787
|
-
|
|
788
|
-
## Per-Property Streaming Status
|
|
789
|
-
|
|
790
|
-
When rendering a tool UI, you can track which arguments have finished streaming using `useToolArgsStatus`. This must be used inside a tool-call message part context.
|
|
791
|
-
|
|
792
|
-
```tsx
|
|
793
|
-
import { useToolArgsStatus } from "@assistant-ui/react";
|
|
794
|
-
|
|
795
|
-
const WeatherUI = makeAssistantToolUI({
|
|
796
|
-
toolName: "weather",
|
|
797
|
-
render: ({ args }) => {
|
|
798
|
-
const { status, propStatus } = useToolArgsStatus<{
|
|
799
|
-
location: string;
|
|
800
|
-
unit: string;
|
|
801
|
-
}>();
|
|
802
|
-
|
|
803
|
-
return (
|
|
804
|
-
<div>
|
|
805
|
-
<span className={propStatus.location === "streaming" ? "animate-pulse" : ""}>
|
|
806
|
-
{args.location ?? "..."}
|
|
807
|
-
</span>
|
|
808
|
-
{status === "complete" && <WeatherChart data={args} />}
|
|
809
|
-
</div>
|
|
810
|
-
);
|
|
811
|
-
},
|
|
812
|
-
});
|
|
813
|
-
```
|
|
814
|
-
|
|
815
|
-
`propStatus` maps each key to `"streaming"` | `"complete"` once the key appears in the partial JSON. Keys not yet present in the stream are absent from `propStatus`.
|
|
816
|
-
|
|
817
|
-
## Data-Part Generative UI
|
|
818
|
-
|
|
819
|
-
Alongside tool-call rendering, assistant-ui supports a second generative UI mechanism based on `DataMessagePart`. Instead of attaching UI to a tool invocation, the backend (or the LangGraph graph) emits named data events that are appended as `{ type: "data", name, data }` parts on the parent assistant message.
|
|
820
|
-
|
|
821
|
-
**When to choose which:**
|
|
822
|
-
|
|
823
|
-
- **Tool UI**: the **model** decides what to render by calling a tool whose args become the component's data. Register the renderer via the [`Tools()`](/docs/guides/tools) toolkit's `render` field (recommended), or standalone with `makeAssistantToolUI` / `useAssistantToolUI` when the tool itself is defined elsewhere (backend, MCP, LangGraph). Args stream incrementally, so you observe partial state via `status` / `useToolArgsStatus` and may need [Deferred Rendering](#deferred-rendering) for components that should only mount with final data.
|
|
824
|
-
- **Data UI** (`makeAssistantDataUI`): the **backend or orchestrator** decides what to render and pushes a named data event onto the assistant message. Data parts arrive as terminal events with no streaming partials, so the renderer naturally fires once with the final data.
|
|
825
|
-
|
|
826
|
-
If you want a component to appear only after the message is complete and you control the backend, Data UI is usually the more direct fit; reach for Tool UI's deferred pattern when the model itself must drive the choice.
|
|
827
|
-
|
|
828
|
-
Use `makeAssistantDataUI` to register a renderer for a named data part:
|
|
829
|
-
|
|
830
|
-
```tsx
|
|
831
|
-
import { makeAssistantDataUI } from "@assistant-ui/react";
|
|
832
|
-
|
|
833
|
-
type ChartProps = { series: number[]; title: string };
|
|
834
|
-
|
|
835
|
-
export const ChartUI = makeAssistantDataUI<ChartProps>({
|
|
836
|
-
name: "chart",
|
|
837
|
-
render: ({ data }) => (
|
|
838
|
-
<div>
|
|
839
|
-
<h3>{data.title}</h3>
|
|
840
|
-
<Chart series={data.series} />
|
|
841
|
-
</div>
|
|
842
|
-
),
|
|
843
|
-
});
|
|
844
|
-
```
|
|
845
|
-
|
|
846
|
-
Mount `<ChartUI />` once inside the `AssistantRuntimeProvider` tree; it renders nothing itself and only registers the renderer.
|
|
847
|
-
|
|
848
|
-
For LangGraph-specific patterns (emitting UI from a Python/TypeScript graph node via `push_ui_message` / `typedUi`, dynamic loading with `LoadExternalComponent`, and the `useLangGraphUIMessages` escape hatch), see [LangGraph Generative UI](/docs/runtimes/langgraph/generative-ui).
|
|
849
|
-
|
|
850
|
-
A fallback renderer for unmatched data parts is available internally but `setFallbackDataUI` is not yet a public API.
|
|
851
|
-
|
|
852
|
-
## Related Guides
|
|
853
|
-
|
|
854
|
-
- [Tools Guide](/docs/guides/tools) - Learn how to create and use tools with AI models
|
|
855
|
-
- [Multi-Agent](/docs/guides/multi-agent) - Render sub-agent conversations inside tool call UIs
|
|
856
|
-
- [Tool Fallback](/docs/ui/tool-fallback) - Default UI for tools without custom components
|
|
857
|
-
- [API Reference](/docs/api-reference/primitives/message-part) - Detailed type definitions and component APIs
|
|
858
|
-
- [Message Primitive](/docs/api-reference/primitives/message) - Complete Message component documentation
|