@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,151 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: makeAssistantToolUI
|
|
3
|
-
description: Register custom UI components to render tool executions and their status.
|
|
4
|
-
platforms: ["react"]
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
<Callout type="info">
|
|
8
|
-
Prefer pre-registering tool UIs via the [`Tools()` API](/docs/guides/tools)
|
|
9
|
-
(set `render` on the tool definition) or by mounting `makeAssistantToolUI`
|
|
10
|
-
near the root of your tree. A tool UI that is only registered while a
|
|
11
|
-
specific component is mounted will not appear when chat history is replayed
|
|
12
|
-
or during server-side rendering, since the registering component may not be
|
|
13
|
-
mounted at that point. Tool execution can still be registered dynamically
|
|
14
|
-
via [`makeAssistantTool`](/docs/copilots/make-assistant-tool); this caveat
|
|
15
|
-
applies specifically to the UI render function.
|
|
16
|
-
</Callout>
|
|
17
|
-
|
|
18
|
-
The `makeAssistantToolUI` utility is used to register a tool UI component with the Assistant.
|
|
19
|
-
|
|
20
|
-
## Usage
|
|
21
|
-
|
|
22
|
-
```tsx
|
|
23
|
-
import { makeAssistantToolUI } from "@assistant-ui/react";
|
|
24
|
-
|
|
25
|
-
const MyToolUI = makeAssistantToolUI({
|
|
26
|
-
toolName: "myTool",
|
|
27
|
-
render: ({ args, result, status }) => {
|
|
28
|
-
// render your tool UI here
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## API
|
|
34
|
-
|
|
35
|
-
### Parameters
|
|
36
|
-
|
|
37
|
-
<ParametersTable
|
|
38
|
-
type="AssistantToolUIProps<TArgs, TResult>"
|
|
39
|
-
parameters={[
|
|
40
|
-
{
|
|
41
|
-
name: "toolName",
|
|
42
|
-
type: "string",
|
|
43
|
-
description:
|
|
44
|
-
"The name of the tool. This must match the name of the tool defined in the assistant.",
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
name: "render",
|
|
48
|
-
type: "ComponentType<ToolCallMessagePartProps<TArgs, TResult>>",
|
|
49
|
-
description:
|
|
50
|
-
"A React component that renders the tool UI. Receives the following props:",
|
|
51
|
-
required: true,
|
|
52
|
-
children: [
|
|
53
|
-
{
|
|
54
|
-
type: "ToolCallMessagePartProps<TArgs, TResult>",
|
|
55
|
-
parameters: [
|
|
56
|
-
{
|
|
57
|
-
name: "type",
|
|
58
|
-
type: '"tool-call"',
|
|
59
|
-
description: "The message part type",
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: "toolCallId",
|
|
63
|
-
type: "string",
|
|
64
|
-
description: "Unique identifier for this tool call",
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: "toolName",
|
|
68
|
-
type: "string",
|
|
69
|
-
description: "The name of the tool being called",
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
name: "args",
|
|
73
|
-
type: "TArgs",
|
|
74
|
-
description: "The arguments passed to the tool",
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
name: "argsText",
|
|
78
|
-
type: "string",
|
|
79
|
-
description: "String representation of the arguments",
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
name: "result",
|
|
83
|
-
type: "TResult | undefined",
|
|
84
|
-
description: "The result of the tool execution (if complete)",
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
name: "isError",
|
|
88
|
-
type: "boolean | undefined",
|
|
89
|
-
description: "Whether the result is an error",
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
name: "status",
|
|
93
|
-
type: "ToolCallMessagePartStatus",
|
|
94
|
-
description:
|
|
95
|
-
'The execution status object with a type property: "running", "complete", "incomplete", or "requires-action"',
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
name: "addResult",
|
|
99
|
-
type: "(result: TResult | ToolResponse<TResult>) => void",
|
|
100
|
-
description:
|
|
101
|
-
"Function to add a result (useful for human-in-the-loop tools)",
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
name: "artifact",
|
|
105
|
-
type: "unknown",
|
|
106
|
-
description:
|
|
107
|
-
"Optional artifact data associated with the tool call",
|
|
108
|
-
},
|
|
109
|
-
],
|
|
110
|
-
},
|
|
111
|
-
],
|
|
112
|
-
},
|
|
113
|
-
]}
|
|
114
|
-
/>
|
|
115
|
-
|
|
116
|
-
### Returns
|
|
117
|
-
|
|
118
|
-
A React functional component that should be included in your component tree. This component doesn't render anything itself, but it registers the tool UI with the Assistant.
|
|
119
|
-
|
|
120
|
-
## Example
|
|
121
|
-
|
|
122
|
-
```tsx
|
|
123
|
-
import { makeAssistantToolUI } from "@assistant-ui/react";
|
|
124
|
-
import { AssistantRuntimeProvider } from "@assistant-ui/react";
|
|
125
|
-
|
|
126
|
-
const GetWeatherUI = makeAssistantToolUI({
|
|
127
|
-
toolName: "get_weather",
|
|
128
|
-
render: ({ args, result, status }) => {
|
|
129
|
-
if (status.type === "requires-action")
|
|
130
|
-
return <p>Getting weather for {args.location}...</p>;
|
|
131
|
-
if (status.type === "running") return <p>Loading...</p>;
|
|
132
|
-
if (status.type === "incomplete" && status.reason === "error")
|
|
133
|
-
return <p>Error getting weather.</p>;
|
|
134
|
-
if (status.type === "complete")
|
|
135
|
-
return <p>The weather is {result.weather}.</p>;
|
|
136
|
-
return null;
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
function App() {
|
|
141
|
-
const runtime = /* your runtime setup */;
|
|
142
|
-
return (
|
|
143
|
-
<AssistantRuntimeProvider runtime={runtime}>
|
|
144
|
-
{/* ...your other components */}
|
|
145
|
-
<GetWeatherUI />
|
|
146
|
-
</AssistantRuntimeProvider>
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
This example shows how to create a simple UI for a `get_weather` tool. The UI will display different messages depending on the status of the tool execution.
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: makeAssistantTool
|
|
3
|
-
description: Create React components that provide reusable tools to the assistant.
|
|
4
|
-
platforms: ["react"]
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
<Callout type="info">
|
|
8
|
-
For most apps, the [`Tools()` API](/docs/guides/tools) is an easier starting
|
|
9
|
-
point: tool definitions live in a toolkit object rather than the component
|
|
10
|
-
tree. `makeAssistantTool` is fully supported and remains a good fit when a
|
|
11
|
-
tool's availability is tied to a component being mounted, for example a
|
|
12
|
-
product-specific tool that should only be exposed while that product's UI is
|
|
13
|
-
on screen (the [intelligent components](/docs/copilots/motivation) pattern).
|
|
14
|
-
</Callout>
|
|
15
|
-
|
|
16
|
-
`makeAssistantTool` creates a React component that provides a tool to the assistant. This is useful for defining reusable tools that can be composed into your application.
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
```tsx
|
|
21
|
-
import { makeAssistantTool, tool } from "@assistant-ui/react";
|
|
22
|
-
import { z } from "zod";
|
|
23
|
-
|
|
24
|
-
// Define the tool using the tool() helper
|
|
25
|
-
const submitForm = tool({
|
|
26
|
-
parameters: z.object({
|
|
27
|
-
email: z.string().email(),
|
|
28
|
-
name: z.string(),
|
|
29
|
-
}),
|
|
30
|
-
execute: async ({ email, name }) => {
|
|
31
|
-
// Implementation
|
|
32
|
-
return { success: true };
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// Create a tool component
|
|
37
|
-
const SubmitFormTool = makeAssistantTool({
|
|
38
|
-
...submitForm,
|
|
39
|
-
toolName: "submitForm",
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// Use in your component
|
|
43
|
-
function Form() {
|
|
44
|
-
return (
|
|
45
|
-
<div>
|
|
46
|
-
<form>{/* form fields */}</form>
|
|
47
|
-
<SubmitFormTool />
|
|
48
|
-
</div>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## API Reference
|
|
54
|
-
|
|
55
|
-
### Parameters
|
|
56
|
-
|
|
57
|
-
<ParametersTable
|
|
58
|
-
type="AssistantToolProps<TArgs, TResult>"
|
|
59
|
-
parameters={[
|
|
60
|
-
{
|
|
61
|
-
name: "toolName",
|
|
62
|
-
type: "string",
|
|
63
|
-
description: "The unique identifier for the tool",
|
|
64
|
-
required: true,
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: "parameters",
|
|
68
|
-
type: "StandardSchemaV1<TArgs> | JSONSchema7",
|
|
69
|
-
description:
|
|
70
|
-
"Schema defining the tool's parameters (typically a Zod schema)",
|
|
71
|
-
required: true,
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
name: "execute",
|
|
75
|
-
type: "(args: TArgs, context: ToolExecutionContext) => TResult | Promise<TResult>",
|
|
76
|
-
description:
|
|
77
|
-
"Function that implements the tool's behavior (required for frontend tools)",
|
|
78
|
-
required: true,
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
name: "description",
|
|
82
|
-
type: "string",
|
|
83
|
-
description: "Optional description of the tool's purpose",
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
name: "render",
|
|
87
|
-
type: "ComponentType<ToolCallMessagePartProps<TArgs, TResult>>",
|
|
88
|
-
description:
|
|
89
|
-
"Optional custom UI component for rendering the tool execution. Receives the following props:",
|
|
90
|
-
children: [
|
|
91
|
-
{
|
|
92
|
-
type: "ToolCallMessagePartProps<TArgs, TResult>",
|
|
93
|
-
parameters: [
|
|
94
|
-
{
|
|
95
|
-
name: "type",
|
|
96
|
-
type: '"tool-call"',
|
|
97
|
-
description: "The message part type",
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
name: "toolCallId",
|
|
101
|
-
type: "string",
|
|
102
|
-
description: "Unique identifier for this tool call",
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
name: "toolName",
|
|
106
|
-
type: "string",
|
|
107
|
-
description: "The name of the tool being called",
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
name: "args",
|
|
111
|
-
type: "TArgs",
|
|
112
|
-
description: "The arguments passed to the tool",
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
name: "argsText",
|
|
116
|
-
type: "string",
|
|
117
|
-
description: "String representation of the arguments",
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
name: "result",
|
|
121
|
-
type: "TResult | undefined",
|
|
122
|
-
description: "The result of the tool execution (if complete)",
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
name: "isError",
|
|
126
|
-
type: "boolean | undefined",
|
|
127
|
-
description: "Whether the result is an error",
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
name: "status",
|
|
131
|
-
type: "ToolCallMessagePartStatus",
|
|
132
|
-
description:
|
|
133
|
-
'The execution status object with a type property: "running", "complete", "incomplete", or "requires-action"',
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
name: "addResult",
|
|
137
|
-
type: "(result: TResult | ToolResponse<TResult>) => void",
|
|
138
|
-
description:
|
|
139
|
-
"Function to add a result (useful for human-in-the-loop tools)",
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
name: "artifact",
|
|
143
|
-
type: "unknown",
|
|
144
|
-
description:
|
|
145
|
-
"Optional artifact data associated with the tool call",
|
|
146
|
-
},
|
|
147
|
-
],
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
},
|
|
151
|
-
]}
|
|
152
|
-
/>
|
|
153
|
-
|
|
154
|
-
### Returns
|
|
155
|
-
|
|
156
|
-
Returns a React component that:
|
|
157
|
-
|
|
158
|
-
- Provides the tool to the assistant when mounted
|
|
159
|
-
- Automatically removes the tool when unmounted
|
|
160
|
-
- Renders nothing in the DOM (returns null)
|
|
161
|
-
|
|
162
|
-
## Example with Multiple Tools
|
|
163
|
-
|
|
164
|
-
```tsx
|
|
165
|
-
import { makeAssistantTool, tool } from "@assistant-ui/react";
|
|
166
|
-
import { z } from "zod";
|
|
167
|
-
|
|
168
|
-
// Define tools
|
|
169
|
-
const validateEmail = tool({
|
|
170
|
-
parameters: z.object({
|
|
171
|
-
email: z.string(),
|
|
172
|
-
}),
|
|
173
|
-
execute: ({ email }) => {
|
|
174
|
-
const isValid = email.includes("@");
|
|
175
|
-
return { isValid, reason: isValid ? "Valid email" : "Missing @" };
|
|
176
|
-
},
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
const sendEmail = tool({
|
|
180
|
-
parameters: z.object({
|
|
181
|
-
to: z.string().email(),
|
|
182
|
-
subject: z.string(),
|
|
183
|
-
body: z.string(),
|
|
184
|
-
}),
|
|
185
|
-
execute: async (params) => {
|
|
186
|
-
// Tool logic
|
|
187
|
-
return { sent: true };
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
// Create tool components
|
|
192
|
-
const EmailValidator = makeAssistantTool({
|
|
193
|
-
...validateEmail,
|
|
194
|
-
toolName: "validateEmail",
|
|
195
|
-
});
|
|
196
|
-
const EmailSender = makeAssistantTool({
|
|
197
|
-
...sendEmail,
|
|
198
|
-
toolName: "sendEmail",
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// Use together
|
|
202
|
-
function EmailForm() {
|
|
203
|
-
return (
|
|
204
|
-
<div>
|
|
205
|
-
<form>{/* form fields */}</form>
|
|
206
|
-
<EmailValidator />
|
|
207
|
-
<EmailSender />
|
|
208
|
-
</div>
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
## Best Practices
|
|
214
|
-
|
|
215
|
-
1. **Parameter Validation**
|
|
216
|
-
|
|
217
|
-
- Always use Zod schemas to define parameters
|
|
218
|
-
- Be specific about parameter types and constraints
|
|
219
|
-
- Add helpful error messages to schema validations
|
|
220
|
-
|
|
221
|
-
2. **Error Handling**
|
|
222
|
-
|
|
223
|
-
- Return meaningful error messages
|
|
224
|
-
- Consider returning partial results when possible
|
|
225
|
-
- Handle async errors appropriately
|
|
226
|
-
|
|
227
|
-
3. **Composition**
|
|
228
|
-
- Break complex tools into smaller, focused ones
|
|
229
|
-
- Consider tool dependencies and interactions
|
|
230
|
-
- Use multiple tools together for complex functionality
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Generative UI
|
|
3
|
-
description: Render agent-described React UI from a JSON spec with a consumer-provided component allowlist.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
`MessagePrimitive.GenerativeUI` is a first-class primitive for rendering UI
|
|
7
|
-
described by the agent at runtime as a JSON spec. Instead of hard-coding a
|
|
8
|
-
component per tool, the agent emits a `generative-ui` message part containing
|
|
9
|
-
a tree of components by name. assistant-ui resolves each name against a
|
|
10
|
-
**consumer-provided allowlist** and renders the result.
|
|
11
|
-
|
|
12
|
-
> The allowlist controls **which** components the agent may render: any name
|
|
13
|
-
> not in it throws a typed `GenerativeUIRenderError` (no implicit fallback). It
|
|
14
|
-
> does not constrain the props passed to those components; see [Security](#security).
|
|
15
|
-
|
|
16
|
-
## Quick start
|
|
17
|
-
|
|
18
|
-
### 1. Define your component allowlist
|
|
19
|
-
|
|
20
|
-
```tsx title="components/gui.tsx"
|
|
21
|
-
const Card = ({ title, children }) => (
|
|
22
|
-
<div className="rounded-xl border bg-card p-4 shadow-sm">
|
|
23
|
-
<div className="text-base font-semibold">{title}</div>
|
|
24
|
-
<div className="mt-2">{children}</div>
|
|
25
|
-
</div>
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
const Button = ({ label }) => (
|
|
29
|
-
<button className="rounded-md bg-primary px-3 py-1.5 text-primary-foreground">
|
|
30
|
-
{label}
|
|
31
|
-
</button>
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
export const componentsAllowlist = { Card, Button };
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### 2. Wire the primitive into your message renderer
|
|
38
|
-
|
|
39
|
-
```tsx title="components/assistant-message.tsx"
|
|
40
|
-
import { MessagePrimitive } from "@assistant-ui/react";
|
|
41
|
-
import { componentsAllowlist } from "./gui";
|
|
42
|
-
|
|
43
|
-
export function AssistantMessage() {
|
|
44
|
-
return (
|
|
45
|
-
<MessagePrimitive.Parts
|
|
46
|
-
components={{
|
|
47
|
-
generativeUI: { components: componentsAllowlist },
|
|
48
|
-
}}
|
|
49
|
-
/>
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
You can also use the standalone primitive form:
|
|
55
|
-
|
|
56
|
-
```tsx
|
|
57
|
-
<MessagePrimitive.GenerativeUI components={componentsAllowlist} />
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### 3. Have the agent emit a `generative-ui` part
|
|
61
|
-
|
|
62
|
-
A `GenerativeUIMessagePart` carries a JSON spec:
|
|
63
|
-
|
|
64
|
-
```ts
|
|
65
|
-
{
|
|
66
|
-
type: "generative-ui",
|
|
67
|
-
spec: {
|
|
68
|
-
root: {
|
|
69
|
-
component: "Card",
|
|
70
|
-
props: { title: "Welcome" },
|
|
71
|
-
children: [
|
|
72
|
-
{ component: "Button", props: { label: "Get started" } },
|
|
73
|
-
],
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
Bare strings act as inline text leaves.
|
|
80
|
-
|
|
81
|
-
## Spec shape
|
|
82
|
-
|
|
83
|
-
```ts
|
|
84
|
-
type GenerativeUINode =
|
|
85
|
-
| string
|
|
86
|
-
| {
|
|
87
|
-
component: string; // resolved against the allowlist
|
|
88
|
-
props?: Record<string, unknown>;
|
|
89
|
-
children?: GenerativeUINode[];
|
|
90
|
-
key?: string; // optional stable React key
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
type GenerativeUISpec = {
|
|
94
|
-
root: GenerativeUINode | GenerativeUINode[];
|
|
95
|
-
};
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
The spec is plain JSON — easy for any agent to emit, and easy to validate
|
|
99
|
-
on the server before delivery.
|
|
100
|
-
|
|
101
|
-
## Streaming
|
|
102
|
-
|
|
103
|
-
The primitive is stream-friendly: any partial spec renders progressively. As
|
|
104
|
-
new nodes arrive (filling in `children`, refining `props`), the rendered tree
|
|
105
|
-
updates without reflows or lost local state for already-mounted children.
|
|
106
|
-
|
|
107
|
-
## Security
|
|
108
|
-
|
|
109
|
-
The allowlist is the boundary on **which** components render: a spec can only instantiate components you put in the registry, with no `eval` and no dynamic import (names are looked up in the registry and nothing else). An unknown name throws `GenerativeUIRenderError` or invokes your `Fallback`.
|
|
110
|
-
|
|
111
|
-
It does **not** constrain the `props` the agent supplies. Spec props are spread directly onto your allowlisted components, so treat every allowlisted component as receiving untrusted input: never forward agent-supplied props into `dangerouslySetInnerHTML`, validate or reject `href` / `src` values (for example block `javascript:` URLs), and avoid passing spec props anywhere they become executable. The safest allowlisted components accept only primitive, display-oriented props.
|
|
112
|
-
|
|
113
|
-
## Error handling
|
|
114
|
-
|
|
115
|
-
Unknown component names throw `GenerativeUIRenderError` with a typed
|
|
116
|
-
`componentName` field. Catch it with a React error boundary, or pass a
|
|
117
|
-
`Fallback` component to opt into a soft-fail UX:
|
|
118
|
-
|
|
119
|
-
```tsx
|
|
120
|
-
<MessagePrimitive.GenerativeUI
|
|
121
|
-
components={componentsAllowlist}
|
|
122
|
-
Fallback={({ component }) => (
|
|
123
|
-
<span className="rounded bg-muted px-1.5 py-0.5 font-mono text-xs">
|
|
124
|
-
unknown component: {component}
|
|
125
|
-
</span>
|
|
126
|
-
)}
|
|
127
|
-
/>
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
## Composing with other primitives
|
|
131
|
-
|
|
132
|
-
`generative-ui` is a regular `MessagePart` type, so it composes cleanly with
|
|
133
|
-
`MessagePrimitive.Parts`, `MessagePrimitive.PartByIndex`, and
|
|
134
|
-
`MessagePrimitive.GroupedParts`. Render it alongside text, tool calls, and
|
|
135
|
-
reasoning in the same message.
|
|
136
|
-
|
|
137
|
-
## Why a primitive (not just a tool)
|
|
138
|
-
|
|
139
|
-
Tool-call UI is great when the agent already invoked a known tool. Generative
|
|
140
|
-
UI flips it: the agent _composes_ UI from a vocabulary you ship. Useful for
|
|
141
|
-
forms, dashboards, status panels, multi-step flows, and anywhere the
|
|
142
|
-
component library you want is broader than a single tool's render surface.
|