@assistant-ui/mcp-docs-server 0.1.32 → 0.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/.docs/organized/code-examples/waterfall.md +15 -17
  2. package/.docs/organized/code-examples/with-a2a.md +19 -19
  3. package/.docs/organized/code-examples/with-ag-ui.md +25 -20
  4. package/.docs/organized/code-examples/with-ai-sdk-v6.md +6 -4
  5. package/.docs/organized/code-examples/with-artifacts.md +34 -28
  6. package/.docs/organized/code-examples/with-assistant-transport.md +59 -47
  7. package/.docs/organized/code-examples/with-browser-extension.md +17 -5
  8. package/.docs/organized/code-examples/with-chain-of-thought.md +376 -78
  9. package/.docs/organized/code-examples/with-cloud-standalone.md +20 -19
  10. package/.docs/organized/code-examples/with-cloud.md +6 -4
  11. package/.docs/organized/code-examples/with-custom-thread-list.md +9 -7
  12. package/.docs/organized/code-examples/with-elevenlabs-conversational.md +18 -16
  13. package/.docs/organized/code-examples/with-elevenlabs-scribe.md +9 -8
  14. package/.docs/organized/code-examples/with-expo.md +23 -17
  15. package/.docs/organized/code-examples/with-external-store.md +4 -2
  16. package/.docs/organized/code-examples/with-ffmpeg.md +317 -280
  17. package/.docs/organized/code-examples/with-generative-ui.md +1018 -214
  18. package/.docs/organized/code-examples/with-google-adk.md +4 -2
  19. package/.docs/organized/code-examples/with-heat-graph.md +8 -6
  20. package/.docs/organized/code-examples/with-image-generation.md +19 -17
  21. package/.docs/organized/code-examples/with-interactables.md +312 -234
  22. package/.docs/organized/code-examples/with-langchain.md +9 -7
  23. package/.docs/organized/code-examples/with-langgraph.md +82 -78
  24. package/.docs/organized/code-examples/with-livekit.md +19 -17
  25. package/.docs/organized/code-examples/with-mcp.md +13 -7
  26. package/.docs/organized/code-examples/with-opencode.md +61 -61
  27. package/.docs/organized/code-examples/with-react-hook-form.md +14 -12
  28. package/.docs/organized/code-examples/with-react-ink.md +2 -2
  29. package/.docs/organized/code-examples/with-react-router.md +11 -9
  30. package/.docs/organized/code-examples/with-resumable-stream.md +10 -9
  31. package/.docs/organized/code-examples/with-store.md +14 -12
  32. package/.docs/organized/code-examples/with-tanstack.md +8 -9
  33. package/.docs/organized/code-examples/with-tap-runtime.md +21 -19
  34. package/.docs/raw/docs/(docs)/architecture.mdx +43 -2
  35. package/.docs/raw/docs/(docs)/cli.mdx +1 -2
  36. package/.docs/raw/docs/(docs)/copilots/model-context.mdx +34 -26
  37. package/.docs/raw/docs/(docs)/copilots/motivation.mdx +32 -26
  38. package/.docs/raw/docs/(docs)/installation.mdx +1 -1
  39. package/.docs/raw/docs/(reference)/api-reference/adapters/persistence.mdx +5 -1
  40. package/.docs/raw/docs/(reference)/api-reference/external-store/message-conversion.mdx +14 -14
  41. package/.docs/raw/docs/(reference)/api-reference/external-store/runtime.mdx +11 -1
  42. package/.docs/raw/docs/(reference)/api-reference/generative-ui/index.mdx +18 -0
  43. package/.docs/raw/docs/(reference)/api-reference/generative-ui/rendering.mdx +33 -0
  44. package/.docs/raw/docs/(reference)/api-reference/generative-ui/spec.mdx +45 -0
  45. package/.docs/raw/docs/(reference)/api-reference/hooks/composer-triggers.mdx +41 -41
  46. package/.docs/raw/docs/(reference)/api-reference/hooks/model-context.mdx +19 -1
  47. package/.docs/raw/docs/(reference)/api-reference/hooks/primitives.mdx +122 -122
  48. package/.docs/raw/docs/(reference)/api-reference/integrations/react-ai-sdk.mdx +32 -2
  49. package/.docs/raw/docs/(reference)/api-reference/model-context/context.mdx +6 -0
  50. package/.docs/raw/docs/(reference)/api-reference/overview.mdx +4 -6
  51. package/.docs/raw/docs/(reference)/api-reference/primitives/message.mdx +30 -0
  52. package/.docs/raw/docs/(reference)/api-reference/tools/component-tools.mdx +20 -3
  53. package/.docs/raw/docs/(reference)/api-reference/tools/index.mdx +8 -8
  54. package/.docs/raw/docs/(reference)/api-reference/tools/rendering.mdx +52 -4
  55. package/.docs/raw/docs/(reference)/api-reference/tools/toolkits.mdx +6 -7
  56. package/.docs/raw/docs/(reference)/api-reference/utilities/miscellaneous.mdx +58 -46
  57. package/.docs/raw/docs/cloud/ai-sdk.mdx +0 -2
  58. package/.docs/raw/docs/guides/chain-of-thought.mdx +7 -9
  59. package/.docs/raw/docs/guides/context-api.mdx +2 -1
  60. package/.docs/raw/docs/guides/index.mdx +3 -12
  61. package/.docs/raw/docs/guides/mentions.mdx +4 -4
  62. package/.docs/raw/docs/guides/slash-commands.mdx +1 -1
  63. package/.docs/raw/docs/guides/suggestions.mdx +1 -1
  64. package/.docs/raw/docs/ink/hooks.mdx +98 -85
  65. package/.docs/raw/docs/ink/migration.mdx +1 -1
  66. package/.docs/raw/docs/ink/primitives.mdx +2 -2
  67. package/.docs/raw/docs/integrations/frameworks/ai-sdk.mdx +1 -1
  68. package/.docs/raw/docs/integrations/index.mdx +2 -2
  69. package/.docs/raw/docs/integrations/persistence/custom-adapter.mdx +17 -2
  70. package/.docs/raw/docs/migrations/toolkit-tools.mdx +226 -0
  71. package/.docs/raw/docs/primitives/chain-of-thought.mdx +10 -16
  72. package/.docs/raw/docs/primitives/message.mdx +9 -10
  73. package/.docs/raw/docs/react-native/hooks.mdx +57 -82
  74. package/.docs/raw/docs/react-native/migration.mdx +1 -1
  75. package/.docs/raw/docs/react-native/primitives.mdx +2 -2
  76. package/.docs/raw/docs/runtimes/a2a/client-and-hooks.mdx +3 -0
  77. package/.docs/raw/docs/runtimes/ai-sdk/v6.mdx +122 -1
  78. package/.docs/raw/docs/runtimes/concepts/threads.mdx +7 -1
  79. package/.docs/raw/docs/runtimes/custom/local-runtime.mdx +18 -7
  80. package/.docs/raw/docs/runtimes/google-adk/hooks.mdx +108 -38
  81. package/.docs/raw/docs/runtimes/langgraph/generative-ui.mdx +2 -2
  82. package/.docs/raw/docs/runtimes/langgraph/streaming.mdx +1 -1
  83. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +64 -50
  84. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +98 -86
  85. package/.docs/raw/docs/tools/backend.mdx +136 -0
  86. package/.docs/raw/docs/tools/defining-tools.mdx +413 -0
  87. package/.docs/raw/docs/tools/dynamic-tools.mdx +110 -0
  88. package/.docs/raw/docs/tools/generative-ui.mdx +214 -0
  89. package/.docs/raw/docs/tools/index.mdx +76 -0
  90. package/.docs/raw/docs/{guides → tools}/interactables.mdx +1 -1
  91. package/.docs/raw/docs/{integrations/tools → tools}/mcp.mdx +77 -50
  92. package/.docs/raw/docs/{guides → tools}/multi-agent.mdx +17 -19
  93. package/.docs/raw/docs/tools/tool-ui.mdx +967 -0
  94. package/.docs/raw/docs/{integrations/tools/react-mcp.mdx → tools/user-managed-mcp.mdx} +3 -3
  95. package/.docs/raw/docs/ui/directive-text.mdx +3 -3
  96. package/.docs/raw/docs/ui/mcp-config.mdx +4 -4
  97. package/.docs/raw/docs/ui/part-grouping.mdx +84 -50
  98. package/.docs/raw/docs/ui/reasoning.mdx +4 -5
  99. package/.docs/raw/docs/ui/tool-group.mdx +5 -6
  100. package/.docs/raw/docs/utilities/heat-graph.mdx +1 -1
  101. package/dist/index.d.ts.map +1 -1
  102. package/dist/prepare-docs/code-examples.d.ts.map +1 -1
  103. package/dist/prepare-docs/copy-raw.d.ts.map +1 -1
  104. package/dist/utils/paths.d.ts.map +1 -1
  105. package/package.json +3 -3
  106. package/.docs/organized/code-examples/with-parent-id-grouping.md +0 -596
  107. package/.docs/raw/docs/(docs)/copilots/make-assistant-tool-ui.mdx +0 -151
  108. package/.docs/raw/docs/(docs)/copilots/make-assistant-tool.mdx +0 -230
  109. package/.docs/raw/docs/guides/generative-ui.mdx +0 -142
  110. package/.docs/raw/docs/guides/tool-ui.mdx +0 -858
  111. package/.docs/raw/docs/guides/tools.mdx +0 -736
  112. /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.