@assistant-ui/mcp-docs-server 0.2.2 → 0.3.0
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/README.md +16 -43
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -91
- package/dist/index.js.map +1 -1
- package/dist/proxy.d.ts +9 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/proxy.js +76 -0
- package/dist/proxy.js.map +1 -0
- package/package.json +9 -13
- package/src/index.ts +3 -115
- package/src/proxy.test.ts +250 -0
- package/src/proxy.ts +111 -0
- package/.docs/organized/code-examples/waterfall.md +0 -807
- package/.docs/organized/code-examples/with-a2a.md +0 -674
- package/.docs/organized/code-examples/with-ag-ui.md +0 -552
- package/.docs/organized/code-examples/with-ai-sdk-v7.md +0 -465
- package/.docs/organized/code-examples/with-artifacts.md +0 -814
- package/.docs/organized/code-examples/with-assistant-transport.md +0 -575
- package/.docs/organized/code-examples/with-browser-extension.md +0 -371
- package/.docs/organized/code-examples/with-chain-of-thought.md +0 -960
- package/.docs/organized/code-examples/with-cloud-standalone.md +0 -681
- package/.docs/organized/code-examples/with-cloud.md +0 -438
- package/.docs/organized/code-examples/with-custom-thread-list.md +0 -568
- package/.docs/organized/code-examples/with-elevenlabs-conversational.md +0 -526
- package/.docs/organized/code-examples/with-elevenlabs-scribe.md +0 -696
- package/.docs/organized/code-examples/with-eve.md +0 -404
- package/.docs/organized/code-examples/with-expo.md +0 -2063
- package/.docs/organized/code-examples/with-external-store.md +0 -420
- package/.docs/organized/code-examples/with-ffmpeg.md +0 -828
- package/.docs/organized/code-examples/with-generative-ui.md +0 -1812
- package/.docs/organized/code-examples/with-google-adk.md +0 -367
- package/.docs/organized/code-examples/with-heat-graph.md +0 -304
- package/.docs/organized/code-examples/with-image-generation.md +0 -462
- package/.docs/organized/code-examples/with-interactables.md +0 -732
- package/.docs/organized/code-examples/with-langchain.md +0 -445
- package/.docs/organized/code-examples/with-langgraph.md +0 -854
- package/.docs/organized/code-examples/with-livekit.md +0 -642
- package/.docs/organized/code-examples/with-mcp.md +0 -780
- package/.docs/organized/code-examples/with-nuxt.md +0 -2428
- package/.docs/organized/code-examples/with-opencode.md +0 -1974
- package/.docs/organized/code-examples/with-openui.md +0 -449
- package/.docs/organized/code-examples/with-pi.md +0 -2083
- package/.docs/organized/code-examples/with-react-hook-form.md +0 -724
- package/.docs/organized/code-examples/with-react-ink-web.md +0 -690
- package/.docs/organized/code-examples/with-react-ink.md +0 -472
- package/.docs/organized/code-examples/with-react-router.md +0 -935
- package/.docs/organized/code-examples/with-resumable-stream.md +0 -667
- package/.docs/organized/code-examples/with-store.md +0 -679
- package/.docs/organized/code-examples/with-svelte.md +0 -415
- package/.docs/organized/code-examples/with-sveltekit.md +0 -1061
- package/.docs/organized/code-examples/with-tanstack.md +0 -811
- package/.docs/organized/code-examples/with-tap-runtime.md +0 -812
- package/.docs/organized/code-examples/with-virtualized-thread.md +0 -680
- package/.docs/organized/code-examples/with-vue.md +0 -408
- package/.docs/raw/docs/(docs)/architecture.mdx +0 -146
- package/.docs/raw/docs/(docs)/base-ui.mdx +0 -39
- package/.docs/raw/docs/(docs)/cli.mdx +0 -542
- package/.docs/raw/docs/(docs)/devtools.mdx +0 -79
- package/.docs/raw/docs/(docs)/index.mdx +0 -21
- package/.docs/raw/docs/(docs)/installation.mdx +0 -483
- package/.docs/raw/docs/(docs)/llm.mdx +0 -211
- package/.docs/raw/docs/(docs)/rtl.mdx +0 -78
- package/.docs/raw/docs/(reference)/api-reference/adapters/attachments.mdx +0 -36
- package/.docs/raw/docs/(reference)/api-reference/adapters/feedback.mdx +0 -20
- package/.docs/raw/docs/(reference)/api-reference/adapters/index.mdx +0 -34
- package/.docs/raw/docs/(reference)/api-reference/adapters/model.mdx +0 -44
- package/.docs/raw/docs/(reference)/api-reference/adapters/persistence.mdx +0 -59
- package/.docs/raw/docs/(reference)/api-reference/adapters/runtime.mdx +0 -20
- package/.docs/raw/docs/(reference)/api-reference/adapters/suggestions.mdx +0 -20
- package/.docs/raw/docs/(reference)/api-reference/context-providers/assistant-runtime-provider.mdx +0 -84
- package/.docs/raw/docs/(reference)/api-reference/context-providers/index.mdx +0 -22
- package/.docs/raw/docs/(reference)/api-reference/context-providers/scoped-providers.mdx +0 -64
- package/.docs/raw/docs/(reference)/api-reference/external-store/index.mdx +0 -22
- package/.docs/raw/docs/(reference)/api-reference/external-store/message-conversion.mdx +0 -52
- package/.docs/raw/docs/(reference)/api-reference/external-store/runtime.mdx +0 -49
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/a2ui.mdx +0 -40
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/actions.mdx +0 -56
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/components.mdx +0 -86
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/index.mdx +0 -39
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/json-generative-ui.mdx +0 -42
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/rendering.mdx +0 -84
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/slack.mdx +0 -85
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/spec.mdx +0 -45
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/teams.mdx +0 -93
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/tokens.mdx +0 -62
- package/.docs/raw/docs/(reference)/api-reference/hooks/composer-triggers.mdx +0 -129
- package/.docs/raw/docs/(reference)/api-reference/hooks/index.mdx +0 -31
- package/.docs/raw/docs/(reference)/api-reference/hooks/model-context.mdx +0 -34
- package/.docs/raw/docs/(reference)/api-reference/hooks/primitives.mdx +0 -350
- package/.docs/raw/docs/(reference)/api-reference/hooks/runtimes.mdx +0 -28
- package/.docs/raw/docs/(reference)/api-reference/hooks/state.mdx +0 -97
- package/.docs/raw/docs/(reference)/api-reference/integrations/cloud-ai-sdk.mdx +0 -24
- package/.docs/raw/docs/(reference)/api-reference/integrations/eve.mdx +0 -97
- package/.docs/raw/docs/(reference)/api-reference/integrations/index.mdx +0 -28
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-ai-sdk.mdx +0 -200
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-data-stream.mdx +0 -37
- package/.docs/raw/docs/(reference)/api-reference/model-context/context.mdx +0 -50
- package/.docs/raw/docs/(reference)/api-reference/model-context/index.mdx +0 -22
- package/.docs/raw/docs/(reference)/api-reference/model-context/registry.mdx +0 -20
- package/.docs/raw/docs/(reference)/api-reference/overview.mdx +0 -566
- package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar-more.mdx +0 -152
- package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar.mdx +0 -239
- package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-if.mdx +0 -208
- package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-modal.mdx +0 -108
- package/.docs/raw/docs/(reference)/api-reference/primitives/attachment.mdx +0 -99
- package/.docs/raw/docs/(reference)/api-reference/primitives/branch-picker.mdx +0 -145
- package/.docs/raw/docs/(reference)/api-reference/primitives/chain-of-thought.mdx +0 -82
- package/.docs/raw/docs/(reference)/api-reference/primitives/composer.mdx +0 -619
- package/.docs/raw/docs/(reference)/api-reference/primitives/composition.mdx +0 -22
- package/.docs/raw/docs/(reference)/api-reference/primitives/error.mdx +0 -65
- package/.docs/raw/docs/(reference)/api-reference/primitives/index.mdx +0 -73
- package/.docs/raw/docs/(reference)/api-reference/primitives/message-part.mdx +0 -117
- package/.docs/raw/docs/(reference)/api-reference/primitives/message.mdx +0 -339
- package/.docs/raw/docs/(reference)/api-reference/primitives/queue-item.mdx +0 -77
- package/.docs/raw/docs/(reference)/api-reference/primitives/selection-toolbar.mdx +0 -88
- package/.docs/raw/docs/(reference)/api-reference/primitives/suggestion.mdx +0 -81
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item-more.mdx +0 -129
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item.mdx +0 -138
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list.mdx +0 -122
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread.mdx +0 -289
- package/.docs/raw/docs/(reference)/api-reference/runtimes/assistant-runtime.mdx +0 -20
- package/.docs/raw/docs/(reference)/api-reference/runtimes/attachment-runtime.mdx +0 -24
- package/.docs/raw/docs/(reference)/api-reference/runtimes/composer-runtime.mdx +0 -32
- package/.docs/raw/docs/(reference)/api-reference/runtimes/index.mdx +0 -43
- package/.docs/raw/docs/(reference)/api-reference/runtimes/message-part-runtime.mdx +0 -43
- package/.docs/raw/docs/(reference)/api-reference/runtimes/message-runtime.mdx +0 -24
- package/.docs/raw/docs/(reference)/api-reference/runtimes/queue-state.mdx +0 -20
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-item-runtime.mdx +0 -24
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-runtime.mdx +0 -24
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-runtime.mdx +0 -36
- package/.docs/raw/docs/(reference)/api-reference/tools/component-tools.mdx +0 -85
- package/.docs/raw/docs/(reference)/api-reference/tools/index.mdx +0 -45
- package/.docs/raw/docs/(reference)/api-reference/tools/interactables-legacy.mdx +0 -55
- package/.docs/raw/docs/(reference)/api-reference/tools/interactables.mdx +0 -151
- package/.docs/raw/docs/(reference)/api-reference/tools/rendering.mdx +0 -106
- package/.docs/raw/docs/(reference)/api-reference/tools/status.mdx +0 -62
- package/.docs/raw/docs/(reference)/api-reference/tools/toolkits.mdx +0 -178
- package/.docs/raw/docs/(reference)/api-reference/transport/assistant-transport.mdx +0 -48
- package/.docs/raw/docs/(reference)/api-reference/transport/frame.mdx +0 -62
- package/.docs/raw/docs/(reference)/api-reference/transport/index.mdx +0 -22
- package/.docs/raw/docs/(reference)/api-reference/utilities/index.mdx +0 -19
- package/.docs/raw/docs/(reference)/api-reference/utilities/miscellaneous.mdx +0 -149
- package/.docs/raw/docs/(reference)/api-reference/voice/index.mdx +0 -22
- package/.docs/raw/docs/(reference)/api-reference/voice/session.mdx +0 -54
- package/.docs/raw/docs/(reference)/api-reference/voice/speech-dictation.mdx +0 -36
- package/.docs/raw/docs/cloud/ai-sdk-assistant-ui.mdx +0 -527
- package/.docs/raw/docs/cloud/ai-sdk.mdx +0 -602
- package/.docs/raw/docs/cloud/authorization.mdx +0 -252
- package/.docs/raw/docs/cloud/index.mdx +0 -46
- package/.docs/raw/docs/cloud/langgraph.mdx +0 -554
- package/.docs/raw/docs/copilots/assistant-frame.mdx +0 -400
- package/.docs/raw/docs/copilots/make-assistant-visible.mdx +0 -82
- package/.docs/raw/docs/copilots/model-context.mdx +0 -156
- package/.docs/raw/docs/copilots/motivation.mdx +0 -202
- package/.docs/raw/docs/copilots/use-assistant-instructions.mdx +0 -64
- package/.docs/raw/docs/guides/attachments.mdx +0 -619
- package/.docs/raw/docs/guides/branching.mdx +0 -76
- package/.docs/raw/docs/guides/chain-of-thought.mdx +0 -164
- package/.docs/raw/docs/guides/chatgpt-subscription.mdx +0 -108
- package/.docs/raw/docs/guides/context-api.mdx +0 -619
- package/.docs/raw/docs/guides/dictation.mdx +0 -298
- package/.docs/raw/docs/guides/editing.mdx +0 -102
- package/.docs/raw/docs/guides/electron.mdx +0 -369
- package/.docs/raw/docs/guides/headless-composer-input.mdx +0 -113
- package/.docs/raw/docs/guides/image-generation.mdx +0 -74
- package/.docs/raw/docs/guides/index.mdx +0 -117
- package/.docs/raw/docs/guides/input-history.mdx +0 -55
- package/.docs/raw/docs/guides/latex.mdx +0 -158
- package/.docs/raw/docs/guides/mentions.mdx +0 -575
- package/.docs/raw/docs/guides/message-timing.mdx +0 -209
- package/.docs/raw/docs/guides/quoting.mdx +0 -169
- package/.docs/raw/docs/guides/resumable-stream-deployment.mdx +0 -212
- package/.docs/raw/docs/guides/resumable-stream-stores.mdx +0 -152
- package/.docs/raw/docs/guides/resumable-streams.mdx +0 -292
- package/.docs/raw/docs/guides/slash-commands.mdx +0 -358
- package/.docs/raw/docs/guides/speech.mdx +0 -172
- package/.docs/raw/docs/guides/suggestions.mdx +0 -384
- package/.docs/raw/docs/guides/virtualization.mdx +0 -133
- package/.docs/raw/docs/guides/voice.mdx +0 -310
- package/.docs/raw/docs/ink/adapters.mdx +0 -99
- package/.docs/raw/docs/ink/custom-backend.mdx +0 -254
- package/.docs/raw/docs/ink/hooks.mdx +0 -469
- package/.docs/raw/docs/ink/index.mdx +0 -236
- package/.docs/raw/docs/ink/migration.mdx +0 -138
- package/.docs/raw/docs/ink/primitives.mdx +0 -1259
- package/.docs/raw/docs/integrations/attachments/custom-adapter.mdx +0 -528
- package/.docs/raw/docs/integrations/auth/better-auth.mdx +0 -188
- package/.docs/raw/docs/integrations/auth/clerk.mdx +0 -166
- package/.docs/raw/docs/integrations/auth/next-auth.mdx +0 -191
- package/.docs/raw/docs/integrations/frameworks/ai-sdk.mdx +0 -88
- package/.docs/raw/docs/integrations/frameworks/cloudflare-agents/overview.mdx +0 -282
- package/.docs/raw/docs/integrations/frameworks/mastra/full-stack.mdx +0 -188
- package/.docs/raw/docs/integrations/frameworks/mastra/overview.mdx +0 -57
- package/.docs/raw/docs/integrations/frameworks/mastra/separate-server.mdx +0 -201
- package/.docs/raw/docs/integrations/gateways/index.mdx +0 -162
- package/.docs/raw/docs/integrations/index.mdx +0 -178
- package/.docs/raw/docs/integrations/observability/helicone.mdx +0 -129
- package/.docs/raw/docs/integrations/observability/langfuse.mdx +0 -161
- package/.docs/raw/docs/integrations/observability/langsmith.mdx +0 -151
- package/.docs/raw/docs/integrations/persistence/custom-adapter.mdx +0 -773
- package/.docs/raw/docs/migrations/deprecation-policy.mdx +0 -42
- package/.docs/raw/docs/migrations/index.mdx +0 -50
- package/.docs/raw/docs/migrations/react-compatibility.mdx +0 -74
- package/.docs/raw/docs/migrations/react-langgraph-v0-7.mdx +0 -328
- package/.docs/raw/docs/migrations/toolkit-tools.mdx +0 -236
- package/.docs/raw/docs/migrations/v0-11.mdx +0 -172
- package/.docs/raw/docs/migrations/v0-12.mdx +0 -302
- package/.docs/raw/docs/migrations/v0-14.mdx +0 -297
- package/.docs/raw/docs/migrations/v0-15.mdx +0 -270
- package/.docs/raw/docs/primitives/action-bar.mdx +0 -352
- package/.docs/raw/docs/primitives/assistant-modal.mdx +0 -216
- package/.docs/raw/docs/primitives/attachment.mdx +0 -217
- package/.docs/raw/docs/primitives/branch-picker.mdx +0 -222
- package/.docs/raw/docs/primitives/chain-of-thought.mdx +0 -315
- package/.docs/raw/docs/primitives/composer.mdx +0 -659
- package/.docs/raw/docs/primitives/error.mdx +0 -142
- package/.docs/raw/docs/primitives/index.mdx +0 -99
- package/.docs/raw/docs/primitives/message.mdx +0 -618
- package/.docs/raw/docs/primitives/selection-toolbar.mdx +0 -191
- package/.docs/raw/docs/primitives/suggestion.mdx +0 -254
- package/.docs/raw/docs/primitives/thread-list.mdx +0 -467
- package/.docs/raw/docs/primitives/thread.mdx +0 -509
- package/.docs/raw/docs/react-native/adapters.mdx +0 -94
- package/.docs/raw/docs/react-native/custom-backend.mdx +0 -207
- package/.docs/raw/docs/react-native/hooks.mdx +0 -339
- package/.docs/raw/docs/react-native/index.mdx +0 -289
- package/.docs/raw/docs/react-native/migration.mdx +0 -142
- package/.docs/raw/docs/react-native/primitives.mdx +0 -839
- package/.docs/raw/docs/runtimes/a2a/client-and-hooks.mdx +0 -399
- package/.docs/raw/docs/runtimes/a2a/overview.mdx +0 -60
- package/.docs/raw/docs/runtimes/a2a/quickstart.mdx +0 -216
- package/.docs/raw/docs/runtimes/ag-ui/agent-state.mdx +0 -124
- package/.docs/raw/docs/runtimes/ag-ui/overview.mdx +0 -70
- package/.docs/raw/docs/runtimes/ag-ui/quickstart.mdx +0 -243
- package/.docs/raw/docs/runtimes/ag-ui/runtime-options.mdx +0 -255
- package/.docs/raw/docs/runtimes/ai-sdk/overview.mdx +0 -61
- package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +0 -122
- package/.docs/raw/docs/runtimes/ai-sdk/v5-legacy.mdx +0 -135
- package/.docs/raw/docs/runtimes/ai-sdk/v6-legacy.mdx +0 -636
- package/.docs/raw/docs/runtimes/ai-sdk/v7.mdx +0 -716
- package/.docs/raw/docs/runtimes/claude-managed-agents.mdx +0 -118
- package/.docs/raw/docs/runtimes/concepts/adapters.mdx +0 -265
- package/.docs/raw/docs/runtimes/concepts/architecture.mdx +0 -167
- package/.docs/raw/docs/runtimes/concepts/stability.mdx +0 -68
- package/.docs/raw/docs/runtimes/concepts/threads.mdx +0 -513
- package/.docs/raw/docs/runtimes/custom/assistant-transport.mdx +0 -763
- package/.docs/raw/docs/runtimes/custom/data-stream.mdx +0 -339
- package/.docs/raw/docs/runtimes/custom/external-store.mdx +0 -957
- package/.docs/raw/docs/runtimes/custom/local-runtime.mdx +0 -902
- package/.docs/raw/docs/runtimes/custom/overview.mdx +0 -71
- package/.docs/raw/docs/runtimes/eve/overview.mdx +0 -151
- package/.docs/raw/docs/runtimes/eve/quickstart.mdx +0 -192
- package/.docs/raw/docs/runtimes/google-adk/api.mdx +0 -256
- package/.docs/raw/docs/runtimes/google-adk/hooks.mdx +0 -784
- package/.docs/raw/docs/runtimes/google-adk/overview.mdx +0 -69
- package/.docs/raw/docs/runtimes/google-adk/quickstart.mdx +0 -229
- package/.docs/raw/docs/runtimes/langchain.mdx +0 -901
- package/.docs/raw/docs/runtimes/langgraph/agent-state.mdx +0 -181
- package/.docs/raw/docs/runtimes/langgraph/generative-ui.mdx +0 -305
- package/.docs/raw/docs/runtimes/langgraph/interrupts.mdx +0 -104
- package/.docs/raw/docs/runtimes/langgraph/overview.mdx +0 -84
- package/.docs/raw/docs/runtimes/langgraph/quickstart.mdx +0 -496
- package/.docs/raw/docs/runtimes/langgraph/streaming.mdx +0 -144
- package/.docs/raw/docs/runtimes/langgraph/threads.mdx +0 -113
- package/.docs/raw/docs/runtimes/langgraph/tutorial/introduction.mdx +0 -29
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-1.mdx +0 -93
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +0 -347
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +0 -393
- package/.docs/raw/docs/runtimes/opencode/hooks.mdx +0 -194
- package/.docs/raw/docs/runtimes/opencode/overview.mdx +0 -58
- package/.docs/raw/docs/runtimes/opencode/quickstart.mdx +0 -119
- package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +0 -133
- package/.docs/raw/docs/tools/a2ui.mdx +0 -107
- package/.docs/raw/docs/tools/backend.mdx +0 -147
- package/.docs/raw/docs/tools/defining-tools.mdx +0 -574
- package/.docs/raw/docs/tools/dynamic-tools.mdx +0 -112
- package/.docs/raw/docs/tools/generative-ui-primitive.mdx +0 -180
- package/.docs/raw/docs/tools/generative-ui-slack.mdx +0 -167
- package/.docs/raw/docs/tools/generative-ui-teams.mdx +0 -160
- package/.docs/raw/docs/tools/generative-ui.mdx +0 -322
- package/.docs/raw/docs/tools/index.mdx +0 -72
- package/.docs/raw/docs/tools/interactables.mdx +0 -1084
- package/.docs/raw/docs/tools/mcp-apps.mdx +0 -346
- package/.docs/raw/docs/tools/mcp.mdx +0 -466
- package/.docs/raw/docs/tools/multi-agent.mdx +0 -237
- package/.docs/raw/docs/tools/openui.mdx +0 -175
- package/.docs/raw/docs/tools/tool-ui.mdx +0 -1008
- package/.docs/raw/docs/tools/user-managed-mcp.mdx +0 -428
- package/.docs/raw/docs/ui/accordion.mdx +0 -266
- package/.docs/raw/docs/ui/assistant-modal.mdx +0 -166
- package/.docs/raw/docs/ui/assistant-sidebar.mdx +0 -89
- package/.docs/raw/docs/ui/attachment.mdx +0 -259
- package/.docs/raw/docs/ui/badge.mdx +0 -150
- package/.docs/raw/docs/ui/composer-trigger-popover.mdx +0 -212
- package/.docs/raw/docs/ui/context-display.mdx +0 -148
- package/.docs/raw/docs/ui/diff-viewer.mdx +0 -280
- package/.docs/raw/docs/ui/directive-text.mdx +0 -114
- package/.docs/raw/docs/ui/dot-matrix.mdx +0 -133
- package/.docs/raw/docs/ui/file.mdx +0 -159
- package/.docs/raw/docs/ui/follow-up-suggestions.mdx +0 -82
- package/.docs/raw/docs/ui/image.mdx +0 -102
- package/.docs/raw/docs/ui/markdown.mdx +0 -64
- package/.docs/raw/docs/ui/mcp-config.mdx +0 -107
- package/.docs/raw/docs/ui/mermaid.mdx +0 -92
- package/.docs/raw/docs/ui/message-timing.mdx +0 -93
- package/.docs/raw/docs/ui/model-selector.mdx +0 -455
- package/.docs/raw/docs/ui/number-roll.mdx +0 -154
- package/.docs/raw/docs/ui/part-grouping.mdx +0 -614
- package/.docs/raw/docs/ui/quote.mdx +0 -211
- package/.docs/raw/docs/ui/reasoning.mdx +0 -186
- package/.docs/raw/docs/ui/scrollbar.mdx +0 -77
- package/.docs/raw/docs/ui/select.mdx +0 -254
- package/.docs/raw/docs/ui/sources.mdx +0 -177
- package/.docs/raw/docs/ui/streamdown.mdx +0 -392
- package/.docs/raw/docs/ui/syntax-highlighting.mdx +0 -205
- package/.docs/raw/docs/ui/tabs.mdx +0 -271
- package/.docs/raw/docs/ui/thread-list.mdx +0 -372
- package/.docs/raw/docs/ui/thread.mdx +0 -512
- package/.docs/raw/docs/ui/tool-fallback.mdx +0 -127
- package/.docs/raw/docs/ui/tool-group.mdx +0 -240
- package/.docs/raw/docs/ui/voice.mdx +0 -173
- package/.docs/raw/docs/utilities/heat-graph.mdx +0 -237
- package/.docs/raw/docs/utilities/react-o11y.mdx +0 -362
- package/.docs/raw/docs/utilities/tw-shimmer.mdx +0 -212
- package/dist/constants.d.ts +0 -14
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -19
- package/dist/constants.js.map +0 -1
- package/dist/prepare-docs/code-examples.d.ts +0 -5
- package/dist/prepare-docs/code-examples.d.ts.map +0 -1
- package/dist/prepare-docs/code-examples.js +0 -117
- package/dist/prepare-docs/code-examples.js.map +0 -1
- package/dist/prepare-docs/copy-raw.d.ts +0 -5
- package/dist/prepare-docs/copy-raw.d.ts.map +0 -1
- package/dist/prepare-docs/copy-raw.js +0 -49
- package/dist/prepare-docs/copy-raw.js.map +0 -1
- package/dist/prepare-docs/prepare.d.ts +0 -1
- package/dist/prepare-docs/prepare.js +0 -22
- package/dist/prepare-docs/prepare.js.map +0 -1
- package/dist/prompts/xulux-playground.d.ts +0 -12
- package/dist/prompts/xulux-playground.d.ts.map +0 -1
- package/dist/prompts/xulux-playground.js +0 -33
- package/dist/prompts/xulux-playground.js.map +0 -1
- package/dist/tools/docs.d.ts +0 -22
- package/dist/tools/docs.d.ts.map +0 -1
- package/dist/tools/docs.js +0 -177
- package/dist/tools/docs.js.map +0 -1
- package/dist/tools/examples.d.ts +0 -24
- package/dist/tools/examples.d.ts.map +0 -1
- package/dist/tools/examples.js +0 -87
- package/dist/tools/examples.js.map +0 -1
- package/dist/tools/resources.d.ts +0 -6
- package/dist/tools/resources.d.ts.map +0 -1
- package/dist/tools/resources.js +0 -75
- package/dist/tools/resources.js.map +0 -1
- package/dist/tools/search.d.ts +0 -24
- package/dist/tools/search.d.ts.map +0 -1
- package/dist/tools/search.js +0 -39
- package/dist/tools/search.js.map +0 -1
- package/dist/tools/tests/mcp-test-client.d.ts +0 -15
- package/dist/tools/tests/mcp-test-client.d.ts.map +0 -1
- package/dist/tools/tests/mcp-test-client.js +0 -68
- package/dist/tools/tests/mcp-test-client.js.map +0 -1
- package/dist/tools/tests/test-setup.d.ts +0 -7
- package/dist/tools/tests/test-setup.d.ts.map +0 -1
- package/dist/tools/tests/test-setup.js +0 -36
- package/dist/tools/tests/test-setup.js.map +0 -1
- package/dist/tools/xulux-templates.d.ts +0 -58
- package/dist/tools/xulux-templates.d.ts.map +0 -1
- package/dist/tools/xulux-templates.js +0 -84
- package/dist/tools/xulux-templates.js.map +0 -1
- package/dist/utils/cache.d.ts +0 -5
- package/dist/utils/cache.d.ts.map +0 -1
- package/dist/utils/cache.js +0 -18
- package/dist/utils/cache.js.map +0 -1
- package/dist/utils/logger.d.ts +0 -10
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -20
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/mcp-format.d.ts +0 -11
- package/dist/utils/mcp-format.d.ts.map +0 -1
- package/dist/utils/mcp-format.js +0 -14
- package/dist/utils/mcp-format.js.map +0 -1
- package/dist/utils/mdx.d.ts +0 -12
- package/dist/utils/mdx.d.ts.map +0 -1
- package/dist/utils/mdx.js +0 -45
- package/dist/utils/mdx.js.map +0 -1
- package/dist/utils/paths.d.ts +0 -12
- package/dist/utils/paths.d.ts.map +0 -1
- package/dist/utils/paths.js +0 -93
- package/dist/utils/paths.js.map +0 -1
- package/dist/utils/search.d.ts +0 -10
- package/dist/utils/search.d.ts.map +0 -1
- package/dist/utils/search.js +0 -97
- package/dist/utils/search.js.map +0 -1
- package/dist/utils/security.d.ts +0 -5
- package/dist/utils/security.d.ts.map +0 -1
- package/dist/utils/security.js +0 -22
- package/dist/utils/security.js.map +0 -1
- package/dist/xulux/catalog-client.d.ts +0 -14
- package/dist/xulux/catalog-client.d.ts.map +0 -1
- package/dist/xulux/catalog-client.js +0 -67
- package/dist/xulux/catalog-client.js.map +0 -1
- package/dist/xulux/fallback-catalog.d.ts +0 -7
- package/dist/xulux/fallback-catalog.d.ts.map +0 -1
- package/dist/xulux/fallback-catalog.js +0 -47
- package/dist/xulux/fallback-catalog.js.map +0 -1
- package/dist/xulux/fetch-sandbox.d.ts +0 -5
- package/dist/xulux/fetch-sandbox.d.ts.map +0 -1
- package/dist/xulux/fetch-sandbox.js +0 -40
- package/dist/xulux/fetch-sandbox.js.map +0 -1
- package/dist/xulux/template-service.d.ts +0 -84
- package/dist/xulux/template-service.d.ts.map +0 -1
- package/dist/xulux/template-service.js +0 -223
- package/dist/xulux/template-service.js.map +0 -1
- package/dist/xulux/types.d.ts +0 -55
- package/dist/xulux/types.d.ts.map +0 -1
- package/dist/xulux/types.js +0 -6
- package/dist/xulux/types.js.map +0 -1
- package/src/constants.ts +0 -24
- package/src/prepare-docs/code-examples.ts +0 -158
- package/src/prepare-docs/copy-raw.ts +0 -50
- package/src/prepare-docs/prepare.ts +0 -24
- package/src/prompts/xulux-playground.ts +0 -36
- package/src/tools/docs.ts +0 -255
- package/src/tools/examples.ts +0 -114
- package/src/tools/resources.ts +0 -111
- package/src/tools/search.ts +0 -46
- package/src/tools/tests/completions.test.ts +0 -60
- package/src/tools/tests/directory-size-cap.test.ts +0 -50
- package/src/tools/tests/docs.test.ts +0 -144
- package/src/tools/tests/examples.test.ts +0 -94
- package/src/tools/tests/integration.test.ts +0 -45
- package/src/tools/tests/json-parsing.test.ts +0 -23
- package/src/tools/tests/listings-cache.test.ts +0 -19
- package/src/tools/tests/mcp-protocol.test.ts +0 -216
- package/src/tools/tests/mcp-test-client.ts +0 -111
- package/src/tools/tests/path-traversal.test.ts +0 -81
- package/src/tools/tests/resources.test.ts +0 -133
- package/src/tools/tests/search.test.ts +0 -37
- package/src/tools/tests/test-setup.ts +0 -50
- package/src/tools/tests/xulux-templates.test.ts +0 -262
- package/src/tools/xulux-templates.ts +0 -141
- package/src/utils/cache.ts +0 -20
- package/src/utils/logger.ts +0 -20
- package/src/utils/mcp-format.ts +0 -14
- package/src/utils/mdx.ts +0 -59
- package/src/utils/paths.ts +0 -139
- package/src/utils/search.ts +0 -131
- package/src/utils/security.ts +0 -52
- package/src/utils/tests/cache.test.ts +0 -51
- package/src/utils/tests/mcp-format.test.ts +0 -22
- package/src/utils/tests/security.test.ts +0 -119
- package/src/xulux/catalog-client.ts +0 -105
- package/src/xulux/fallback-catalog.ts +0 -63
- package/src/xulux/fetch-sandbox.ts +0 -56
- package/src/xulux/template-service.ts +0 -406
- package/src/xulux/types.ts +0 -60
|
@@ -1,1008 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Tool UI
|
|
3
|
-
description: Render AI tool calls as custom React components — show loading, result, and interactive states for each tool invocation in 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
|
-
To let the model compose UI from a vocabulary instead of binding one component per tool, see [Generative UI](/docs/tools/generative-ui).
|
|
25
|
-
|
|
26
|
-
## Creating Tool UIs
|
|
27
|
-
|
|
28
|
-
Tool UI is registered on toolkit entries. The same entry can define a browser-executed frontend tool, a human tool that completes through `addResult`, or a render-only backend tool whose schema and execution live on the server.
|
|
29
|
-
|
|
30
|
-
### 1. Client-Defined Tools
|
|
31
|
-
|
|
32
|
-
If you're creating tools on the client side, register them in a toolkit with `Tools({ toolkit })`.
|
|
33
|
-
|
|
34
|
-
```tsx title="app/toolkit.tsx"
|
|
35
|
-
"use generative";
|
|
36
|
-
|
|
37
|
-
import { defineToolkit } from "@assistant-ui/react";
|
|
38
|
-
import { z } from "zod";
|
|
39
|
-
|
|
40
|
-
export default defineToolkit({
|
|
41
|
-
getWeather: {
|
|
42
|
-
description: "Get current weather for a location",
|
|
43
|
-
parameters: z.object({
|
|
44
|
-
location: z.string(),
|
|
45
|
-
unit: z.enum(["celsius", "fahrenheit"]),
|
|
46
|
-
}),
|
|
47
|
-
execute: async ({ location, unit }) => {
|
|
48
|
-
"use client";
|
|
49
|
-
return fetchWeatherAPI(location, unit);
|
|
50
|
-
},
|
|
51
|
-
render: ({ args, result, status }) => {
|
|
52
|
-
if (status.type === "running") {
|
|
53
|
-
return <div>Checking weather in {args.location}...</div>;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<div className="weather-card">
|
|
58
|
-
<h3>{args.location}</h3>
|
|
59
|
-
<p>
|
|
60
|
-
{result.temperature}°{args.unit === "celsius" ? "C" : "F"}
|
|
61
|
-
</p>
|
|
62
|
-
<p>{result.description}</p>
|
|
63
|
-
</div>
|
|
64
|
-
);
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
```tsx title="app/MyRuntimeProvider.tsx"
|
|
71
|
-
import { AssistantRuntimeProvider, AuiConfig, Tools } from "@assistant-ui/react";
|
|
72
|
-
import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
|
|
73
|
-
import toolkit from "./toolkit";
|
|
74
|
-
|
|
75
|
-
function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
|
|
76
|
-
const runtime = useChatRuntime();
|
|
77
|
-
const config = AuiConfig({ tools: Tools({ toolkit }) });
|
|
78
|
-
return (
|
|
79
|
-
<AssistantRuntimeProvider runtime={runtime} config={config}>
|
|
80
|
-
{children}
|
|
81
|
-
</AssistantRuntimeProvider>
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
`useChatRuntime()` targets `/api/chat` by default. To point at a different endpoint or customize requests, see [Custom transport](/docs/runtimes/ai-sdk/v7#custom-transport).
|
|
87
|
-
|
|
88
|
-
<Callout type="tip">
|
|
89
|
-
Frontend toolkit entries can be passed to your backend using the
|
|
90
|
-
`frontendTools` utility.
|
|
91
|
-
</Callout>
|
|
92
|
-
|
|
93
|
-
Learn more about creating tools in the [Tools Guide](/docs/tools/defining-tools).
|
|
94
|
-
|
|
95
|
-
### 2. UI-Only for Existing Tools
|
|
96
|
-
|
|
97
|
-
If your tool is defined elsewhere (e.g., in your backend API, MCP server, or LangGraph), register a backend toolkit entry with just `render`:
|
|
98
|
-
|
|
99
|
-
```tsx
|
|
100
|
-
const toolkit = defineToolkit({
|
|
101
|
-
getWeather: {
|
|
102
|
-
type: "backend",
|
|
103
|
-
render: ({ args, result, status }) => {
|
|
104
|
-
// UI rendering logic only
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
## Quick Start Example
|
|
111
|
-
|
|
112
|
-
This example shows how to implement the UI-only approach with a backend toolkit entry:
|
|
113
|
-
|
|
114
|
-
<Steps>
|
|
115
|
-
<Step>
|
|
116
|
-
|
|
117
|
-
### Create a Tool UI Renderer
|
|
118
|
-
|
|
119
|
-
```tsx
|
|
120
|
-
import type { ToolCallMessagePartComponent } from "@assistant-ui/react";
|
|
121
|
-
import { z } from "zod";
|
|
122
|
-
|
|
123
|
-
type WeatherArgs = {
|
|
124
|
-
location: string;
|
|
125
|
-
unit: "celsius" | "fahrenheit";
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
type WeatherResult = {
|
|
129
|
-
temperature: number;
|
|
130
|
-
description: string;
|
|
131
|
-
humidity: number;
|
|
132
|
-
windSpeed: number;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const WeatherToolUI: ToolCallMessagePartComponent<
|
|
136
|
-
WeatherArgs,
|
|
137
|
-
WeatherResult
|
|
138
|
-
> = ({ args, status, result }) => {
|
|
139
|
-
if (status.type === "running") {
|
|
140
|
-
return (
|
|
141
|
-
<div className="flex items-center gap-2">
|
|
142
|
-
<Spinner />
|
|
143
|
-
<span>Checking weather in {args.location}...</span>
|
|
144
|
-
</div>
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (status.type === "incomplete" && status.reason === "error") {
|
|
149
|
-
return (
|
|
150
|
-
<div className="text-red-500">
|
|
151
|
-
Failed to get weather for {args.location}
|
|
152
|
-
</div>
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return (
|
|
157
|
-
<div className="weather-card rounded-lg bg-blue-50 p-4">
|
|
158
|
-
<h3 className="text-lg font-bold">{args.location}</h3>
|
|
159
|
-
<div className="mt-2 grid grid-cols-2 gap-4">
|
|
160
|
-
<div>
|
|
161
|
-
<p className="text-2xl">
|
|
162
|
-
{result.temperature}°{args.unit === "celsius" ? "C" : "F"}
|
|
163
|
-
</p>
|
|
164
|
-
<p className="text-gray-600">{result.description}</p>
|
|
165
|
-
</div>
|
|
166
|
-
<div className="text-sm">
|
|
167
|
-
<p>Humidity: {result.humidity}%</p>
|
|
168
|
-
<p>Wind: {result.windSpeed} km/h</p>
|
|
169
|
-
</div>
|
|
170
|
-
</div>
|
|
171
|
-
</div>
|
|
172
|
-
);
|
|
173
|
-
};
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
</Step>
|
|
177
|
-
<Step>
|
|
178
|
-
|
|
179
|
-
### Register the Tool UI
|
|
180
|
-
|
|
181
|
-
Put the renderer on the matching backend toolkit entry:
|
|
182
|
-
|
|
183
|
-
```tsx
|
|
184
|
-
const toolkit = defineToolkit({
|
|
185
|
-
getWeather: {
|
|
186
|
-
type: "backend",
|
|
187
|
-
render: WeatherToolUI,
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
function App({ runtime }: { runtime: AssistantRuntime }) {
|
|
192
|
-
const config = AuiConfig({ tools: Tools({ toolkit }) });
|
|
193
|
-
return (
|
|
194
|
-
<AssistantRuntimeProvider runtime={runtime} config={config}>
|
|
195
|
-
<Thread />
|
|
196
|
-
</AssistantRuntimeProvider>
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
</Step>
|
|
202
|
-
<Step>
|
|
203
|
-
|
|
204
|
-
### Define the Backend Tool (Vercel AI SDK)
|
|
205
|
-
|
|
206
|
-
When using the Vercel AI SDK, define the corresponding tool in your API route:
|
|
207
|
-
|
|
208
|
-
```tsx title="/app/api/chat/route.ts"
|
|
209
|
-
import { streamText, tool, zodSchema } from "ai";
|
|
210
|
-
import { z } from "zod";
|
|
211
|
-
|
|
212
|
-
export async function POST(req: Request) {
|
|
213
|
-
const { messages } = await req.json();
|
|
214
|
-
|
|
215
|
-
const result = streamText({
|
|
216
|
-
model: openai("gpt-5.6-luna"),
|
|
217
|
-
messages: await convertToModelMessages(messages),
|
|
218
|
-
tools: {
|
|
219
|
-
getWeather: tool({
|
|
220
|
-
description: "Get current weather for a location",
|
|
221
|
-
inputSchema: zodSchema(
|
|
222
|
-
z.object({
|
|
223
|
-
location: z.string(),
|
|
224
|
-
unit: z.enum(["celsius", "fahrenheit"]),
|
|
225
|
-
}),
|
|
226
|
-
),
|
|
227
|
-
execute: async ({ location, unit }) => {
|
|
228
|
-
const weather = await fetchWeatherAPI(location);
|
|
229
|
-
return {
|
|
230
|
-
temperature: weather.temp,
|
|
231
|
-
description: weather.condition,
|
|
232
|
-
humidity: weather.humidity,
|
|
233
|
-
windSpeed: weather.wind,
|
|
234
|
-
};
|
|
235
|
-
},
|
|
236
|
-
}),
|
|
237
|
-
},
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
return result.toUIMessageStreamResponse();
|
|
241
|
-
}
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
</Step>
|
|
245
|
-
</Steps>
|
|
246
|
-
|
|
247
|
-
## Tool UI Patterns
|
|
248
|
-
|
|
249
|
-
### Component Pattern
|
|
250
|
-
|
|
251
|
-
Create standalone tool UI components:
|
|
252
|
-
|
|
253
|
-
```tsx
|
|
254
|
-
import type { ToolCallMessagePartComponent } from "@assistant-ui/react";
|
|
255
|
-
|
|
256
|
-
export const WebSearchToolUI: ToolCallMessagePartComponent<
|
|
257
|
-
{ query: string },
|
|
258
|
-
{ results: SearchResult[] }
|
|
259
|
-
> = ({ args, status, result }) => {
|
|
260
|
-
return (
|
|
261
|
-
<div className="search-container">
|
|
262
|
-
<div className="mb-3 flex items-center gap-2">
|
|
263
|
-
<SearchIcon />
|
|
264
|
-
<span>Search results for: "{args.query}"</span>
|
|
265
|
-
</div>
|
|
266
|
-
|
|
267
|
-
{status.type === "running" && <LoadingSpinner />}
|
|
268
|
-
|
|
269
|
-
{result && (
|
|
270
|
-
<div className="space-y-2">
|
|
271
|
-
{result.results.map((item, index) => (
|
|
272
|
-
<div key={index} className="rounded border p-3">
|
|
273
|
-
<a href={item.url} className="font-medium text-blue-600">
|
|
274
|
-
{item.title}
|
|
275
|
-
</a>
|
|
276
|
-
<p className="text-sm text-gray-600">{item.snippet}</p>
|
|
277
|
-
</div>
|
|
278
|
-
))}
|
|
279
|
-
</div>
|
|
280
|
-
)}
|
|
281
|
-
</div>
|
|
282
|
-
);
|
|
283
|
-
};
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
Register it on the toolkit:
|
|
287
|
-
|
|
288
|
-
```tsx
|
|
289
|
-
const toolkit = defineToolkit({
|
|
290
|
-
webSearch: {
|
|
291
|
-
type: "backend",
|
|
292
|
-
render: WebSearchToolUI,
|
|
293
|
-
},
|
|
294
|
-
});
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
### Dynamic Toolkit Pattern
|
|
298
|
-
|
|
299
|
-
Use a toolkit hook in its own file when the renderer needs component state:
|
|
300
|
-
|
|
301
|
-
```tsx title="analyze-data-toolkit.tsx"
|
|
302
|
-
"use client";
|
|
303
|
-
|
|
304
|
-
import { defineToolkit, useInlineRender } from "@assistant-ui/react";
|
|
305
|
-
import { useMemo } from "react";
|
|
306
|
-
|
|
307
|
-
export function useAnalyzeDataToolkit(theme: "light" | "dark") {
|
|
308
|
-
const renderAnalyzeData = useInlineRender(({ result, status }) => {
|
|
309
|
-
return (
|
|
310
|
-
<DataVisualization
|
|
311
|
-
data={result}
|
|
312
|
-
theme={theme}
|
|
313
|
-
loading={status.type === "running"}
|
|
314
|
-
/>
|
|
315
|
-
);
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
return useMemo(
|
|
319
|
-
() =>
|
|
320
|
-
defineToolkit({
|
|
321
|
-
analyzeData: {
|
|
322
|
-
type: "backend",
|
|
323
|
-
render: renderAnalyzeData,
|
|
324
|
-
},
|
|
325
|
-
}),
|
|
326
|
-
[renderAnalyzeData],
|
|
327
|
-
);
|
|
328
|
-
}
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
```tsx title="DynamicToolUI.tsx"
|
|
332
|
-
import { AuiConfig, AuiProvider, Tools, useAui } from "@assistant-ui/react";
|
|
333
|
-
import { useState } from "react";
|
|
334
|
-
import { useAnalyzeDataToolkit } from "./analyze-data-toolkit";
|
|
335
|
-
|
|
336
|
-
function DynamicToolUI({ children }: { children: React.ReactNode }) {
|
|
337
|
-
const [theme] = useState<"light" | "dark">("light");
|
|
338
|
-
const toolkit = useAnalyzeDataToolkit(theme);
|
|
339
|
-
const aui = useAui();
|
|
340
|
-
const config = AuiConfig({ tools: Tools({ toolkit }) });
|
|
341
|
-
|
|
342
|
-
return (
|
|
343
|
-
<AuiProvider extends={aui} config={config}>
|
|
344
|
-
{children}
|
|
345
|
-
</AuiProvider>
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
### Inline Pattern
|
|
351
|
-
|
|
352
|
-
For tools that need access to parent component props:
|
|
353
|
-
|
|
354
|
-
<Callout type="tip">
|
|
355
|
-
**Why `useInlineRender`?** By default, a tool UI's `render` function is
|
|
356
|
-
static. Use `useInlineRender` when your UI needs access to dynamic component
|
|
357
|
-
props (for example, to pass in an `id` or other contextual data).
|
|
358
|
-
</Callout>
|
|
359
|
-
|
|
360
|
-
```tsx title="inventory-toolkit.tsx"
|
|
361
|
-
"use client";
|
|
362
|
-
|
|
363
|
-
import { defineToolkit, useInlineRender } from "@assistant-ui/react";
|
|
364
|
-
import { useMemo } from "react";
|
|
365
|
-
|
|
366
|
-
export function useInventoryToolkit(productId: string, productName: string) {
|
|
367
|
-
const renderInventory = useInlineRender(({ result }) => {
|
|
368
|
-
return (
|
|
369
|
-
<div className="inventory-status">
|
|
370
|
-
<h4>{productName} Inventory</h4>
|
|
371
|
-
<p>
|
|
372
|
-
Stock for {productId}: {result.quantity} units
|
|
373
|
-
</p>
|
|
374
|
-
<p>Location: {result.warehouse}</p>
|
|
375
|
-
</div>
|
|
376
|
-
);
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
return useMemo(
|
|
380
|
-
() =>
|
|
381
|
-
defineToolkit({
|
|
382
|
-
checkInventory: {
|
|
383
|
-
type: "backend",
|
|
384
|
-
render: renderInventory,
|
|
385
|
-
},
|
|
386
|
-
}),
|
|
387
|
-
[renderInventory],
|
|
388
|
-
);
|
|
389
|
-
}
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
```tsx title="ProductPage.tsx"
|
|
393
|
-
import { AuiConfig, AuiProvider, Tools, useAui } from "@assistant-ui/react";
|
|
394
|
-
import { useInventoryToolkit } from "./inventory-toolkit";
|
|
395
|
-
|
|
396
|
-
function ProductPage({ productId, productName }) {
|
|
397
|
-
const toolkit = useInventoryToolkit(productId, productName);
|
|
398
|
-
const aui = useAui();
|
|
399
|
-
const config = AuiConfig({ tools: Tools({ toolkit }) });
|
|
400
|
-
|
|
401
|
-
return (
|
|
402
|
-
<AuiProvider extends={aui} config={config}>
|
|
403
|
-
<div>Product details...</div>
|
|
404
|
-
</AuiProvider>
|
|
405
|
-
);
|
|
406
|
-
}
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
## Interactive Tool UIs
|
|
410
|
-
|
|
411
|
-
### User Input Collection
|
|
412
|
-
|
|
413
|
-
Create tools that collect user input during execution:
|
|
414
|
-
|
|
415
|
-
<Callout type="tip">
|
|
416
|
-
**Pro tip:** Call `addResult(...)` exactly once to complete the tool call.
|
|
417
|
-
After it's invoked, the assistant will resume the conversation with your
|
|
418
|
-
provided data.
|
|
419
|
-
</Callout>
|
|
420
|
-
|
|
421
|
-
```tsx
|
|
422
|
-
const toolkit = defineToolkit({
|
|
423
|
-
selectDate: {
|
|
424
|
-
type: "human",
|
|
425
|
-
description: "Ask the user to select a date.",
|
|
426
|
-
parameters: z.object({ prompt: z.string() }),
|
|
427
|
-
render: ({ args, result, addResult }) => {
|
|
428
|
-
if (result) {
|
|
429
|
-
return (
|
|
430
|
-
<div className="rounded bg-green-50 p-3">
|
|
431
|
-
✅ Selected date: {new Date(result.date).toLocaleDateString()}
|
|
432
|
-
</div>
|
|
433
|
-
);
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
return (
|
|
437
|
-
<div className="rounded border p-4">
|
|
438
|
-
<p className="mb-3">{args.prompt}</p>
|
|
439
|
-
<DatePicker
|
|
440
|
-
onChange={(date) => {
|
|
441
|
-
addResult({ date: date.toISOString() });
|
|
442
|
-
}}
|
|
443
|
-
/>
|
|
444
|
-
</div>
|
|
445
|
-
);
|
|
446
|
-
},
|
|
447
|
-
},
|
|
448
|
-
});
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
### Multi-Step Interactions
|
|
452
|
-
|
|
453
|
-
Build complex workflows with human-in-the-loop patterns for multi-step user interactions:
|
|
454
|
-
|
|
455
|
-
```tsx title="app/approval-toolkit.tsx"
|
|
456
|
-
"use generative";
|
|
457
|
-
|
|
458
|
-
import { defineToolkit } from "@assistant-ui/react";
|
|
459
|
-
import { z } from "zod";
|
|
460
|
-
|
|
461
|
-
export default defineToolkit({
|
|
462
|
-
requestApproval: {
|
|
463
|
-
description: "Request user approval for an action",
|
|
464
|
-
parameters: z.object({
|
|
465
|
-
action: z.string(),
|
|
466
|
-
details: z.any(),
|
|
467
|
-
}),
|
|
468
|
-
execute: async ({ action, details }, { human }) => {
|
|
469
|
-
"use client";
|
|
470
|
-
// Request approval from user
|
|
471
|
-
const response = await human({ action, details });
|
|
472
|
-
|
|
473
|
-
return {
|
|
474
|
-
approved: response.approved,
|
|
475
|
-
reason: response.reason,
|
|
476
|
-
};
|
|
477
|
-
},
|
|
478
|
-
render: ({ args, result, interrupt, resume }) => {
|
|
479
|
-
const [reason, setReason] = useState("");
|
|
480
|
-
|
|
481
|
-
// Show result after approval/rejection
|
|
482
|
-
if (result) {
|
|
483
|
-
return (
|
|
484
|
-
<div className={result.approved ? "text-green-600" : "text-red-600"}>
|
|
485
|
-
{result.approved ? "✅ Approved" : `❌ Rejected: ${result.reason}`}
|
|
486
|
-
</div>
|
|
487
|
-
);
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
// Show approval UI when waiting for user input
|
|
491
|
-
if (interrupt) {
|
|
492
|
-
return (
|
|
493
|
-
<div className="rounded border-2 border-yellow-400 p-4">
|
|
494
|
-
<h4 className="font-bold">Approval Required</h4>
|
|
495
|
-
<p className="my-2">{interrupt.payload.action}</p>
|
|
496
|
-
<pre className="rounded bg-gray-100 p-2 text-sm">
|
|
497
|
-
{JSON.stringify(interrupt.payload.details, null, 2)}
|
|
498
|
-
</pre>
|
|
499
|
-
|
|
500
|
-
<div className="mt-4 flex gap-2">
|
|
501
|
-
<button
|
|
502
|
-
onClick={() => resume({ approved: true })}
|
|
503
|
-
className="rounded bg-green-500 px-4 py-2 text-white"
|
|
504
|
-
>
|
|
505
|
-
Approve
|
|
506
|
-
</button>
|
|
507
|
-
<button
|
|
508
|
-
onClick={() => resume({ approved: false, reason })}
|
|
509
|
-
className="rounded bg-red-500 px-4 py-2 text-white"
|
|
510
|
-
>
|
|
511
|
-
Reject
|
|
512
|
-
</button>
|
|
513
|
-
<input
|
|
514
|
-
type="text"
|
|
515
|
-
placeholder="Rejection reason..."
|
|
516
|
-
value={reason}
|
|
517
|
-
onChange={(e) => setReason(e.target.value)}
|
|
518
|
-
className="flex-1 rounded border px-2"
|
|
519
|
-
/>
|
|
520
|
-
</div>
|
|
521
|
-
</div>
|
|
522
|
-
);
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
return <div>Processing...</div>;
|
|
526
|
-
},
|
|
527
|
-
},
|
|
528
|
-
});
|
|
529
|
-
```
|
|
530
|
-
|
|
531
|
-
<Callout type="tip">
|
|
532
|
-
Use tool human input (`human()` / `resume()`) for workflows that need to
|
|
533
|
-
pause tool execution and wait for user input. Use `addResult()` for "human
|
|
534
|
-
tools" where the AI requests a tool call but the entire execution happens
|
|
535
|
-
through user interaction.
|
|
536
|
-
</Callout>
|
|
537
|
-
|
|
538
|
-
### Server-side approval gates
|
|
539
|
-
|
|
540
|
-
Some runtimes (notably AI SDK v7's `toolApproval`-gated tools) pause on the server and emit an approval request that the client must acknowledge before the tool runs. assistant-ui surfaces this on the tool part as `approval` and exposes `respondToApproval({ approved, reason? })` on the renderer:
|
|
541
|
-
|
|
542
|
-
```tsx
|
|
543
|
-
const toolkit = defineToolkit({
|
|
544
|
-
deploy: {
|
|
545
|
-
type: "backend",
|
|
546
|
-
render: ({ args, approval, respondToApproval, result }) => {
|
|
547
|
-
if (approval?.approved === undefined) {
|
|
548
|
-
return (
|
|
549
|
-
<div>
|
|
550
|
-
<p>Approve deploy to {args.target}?</p>
|
|
551
|
-
<button onClick={() => respondToApproval({ approved: true })}>
|
|
552
|
-
Approve
|
|
553
|
-
</button>
|
|
554
|
-
<button
|
|
555
|
-
onClick={() =>
|
|
556
|
-
respondToApproval({ approved: false, reason: "user denied" })
|
|
557
|
-
}
|
|
558
|
-
>
|
|
559
|
-
Deny
|
|
560
|
-
</button>
|
|
561
|
-
</div>
|
|
562
|
-
);
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
if (approval?.approved === false) {
|
|
566
|
-
return <p>Denied{approval.reason ? `: ${approval.reason}` : ""}</p>;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
if (result === undefined) return <p>Approved, running…</p>;
|
|
570
|
-
return <p>Deployed</p>;
|
|
571
|
-
},
|
|
572
|
-
},
|
|
573
|
-
});
|
|
574
|
-
```
|
|
575
|
-
|
|
576
|
-
`approval.approved` is a three-state signal:
|
|
577
|
-
|
|
578
|
-
- `undefined`: gate is open, the renderer should ask the user. This is the only state in which `respondToApproval` is legal.
|
|
579
|
-
- `true`: decision recorded as allow. The server is producing the result (or has produced one, available on `result`).
|
|
580
|
-
- `false`: decision recorded as deny. The runtime records an error result (`isError`) and exposes `approval.reason`.
|
|
581
|
-
|
|
582
|
-
`approval.isAutomatic` is `true` when the runtime granted the decision from a server-side policy rather than the user; render a "auto-approved" badge instead of buttons in that case.
|
|
583
|
-
|
|
584
|
-
Approval gates require a runtime that implements them: the AI SDK v7 runtime emits them for `toolApproval`-gated tools, and `LocalRuntime` supports gates emitted by your `ChatModelAdapter`; see [LocalRuntime approval gates](/docs/runtimes/custom/local-runtime#approval-gates). For tools where the user supplies the result itself, use `unstable_humanToolNames` with `addResult` instead; see [human-in-the-loop tools](/docs/runtimes/custom/local-runtime#human-in-the-loop-tools).
|
|
585
|
-
|
|
586
|
-
For the wire-side setup (`needsApproval`, `sendAutomaticallyWhen`), see [AI SDK v7 server-side tool approval](/docs/runtimes/ai-sdk/v7#server-side-tool-approval).
|
|
587
|
-
|
|
588
|
-
### Approval options
|
|
589
|
-
|
|
590
|
-
Beyond the plain allow / deny pair, the host can attach a list of decision options to an approval, for example "allow once", "allow for this session", and "always allow". Each option carries a machine-readable `kind` (`"allow-once"`, `"allow-always"`, `"reject-once"`, `"reject-always"`); scope semantics like session versus global belong to the option's `id` and `label`, which only the host interprets:
|
|
591
|
-
|
|
592
|
-
```ts
|
|
593
|
-
const approval = {
|
|
594
|
-
id: "a1",
|
|
595
|
-
options: [
|
|
596
|
-
{ id: "once", kind: "allow-once" },
|
|
597
|
-
{ id: "session", kind: "allow-always", label: "Allow for this session" },
|
|
598
|
-
{
|
|
599
|
-
id: "always",
|
|
600
|
-
kind: "allow-always",
|
|
601
|
-
label: "Always allow",
|
|
602
|
-
grants: ["git *"],
|
|
603
|
-
confirm: true,
|
|
604
|
-
},
|
|
605
|
-
{ id: "deny", kind: "reject-once" },
|
|
606
|
-
],
|
|
607
|
-
};
|
|
608
|
-
```
|
|
609
|
-
|
|
610
|
-
Renderers respond with the chosen option instead of a boolean; the option's kind resolves the decision:
|
|
611
|
-
|
|
612
|
-
```tsx
|
|
613
|
-
respondToApproval({ optionId: "session" });
|
|
614
|
-
```
|
|
615
|
-
|
|
616
|
-
The runtime receives `{ approvalId, approved, optionId, reason? }`, so a host that persists "always allow" decisions can key its store off `optionId`. Persistence is entirely host-owned: assistant-ui never stores a decision and never auto-answers future approvals. `grants` lists the patterns an option would persist (shown to the user before they commit), and `confirm` opts the option into a confirmation step. Options with custom `_`-prefixed kinds are skipped by the default `ToolFallback` bar and must be answered with an explicit `approved` value, optionally alongside the `optionId` so the chosen option is still recorded.
|
|
617
|
-
|
|
618
|
-
Approvals that end without a decision (a cancelled run or an expired request) are recorded by the host as `approval.resolution: "cancelled" | "expired"`, which closes the gate without recording a deny.
|
|
619
|
-
|
|
620
|
-
The default `ToolFallback` component renders supplied options automatically, including the confirmation step.
|
|
621
|
-
|
|
622
|
-
## Advanced Features
|
|
623
|
-
|
|
624
|
-
### Tool Status Handling
|
|
625
|
-
|
|
626
|
-
The `status` prop provides detailed execution state:
|
|
627
|
-
|
|
628
|
-
```tsx
|
|
629
|
-
render: ({ status, args }) => {
|
|
630
|
-
switch (status.type) {
|
|
631
|
-
case "running":
|
|
632
|
-
return <LoadingState />;
|
|
633
|
-
|
|
634
|
-
case "requires-action":
|
|
635
|
-
return <UserInputRequired reason={status.reason} />;
|
|
636
|
-
|
|
637
|
-
case "incomplete":
|
|
638
|
-
if (status.reason === "cancelled") {
|
|
639
|
-
return <div>Operation cancelled</div>;
|
|
640
|
-
}
|
|
641
|
-
if (status.reason === "error") {
|
|
642
|
-
return <ErrorDisplay error={status.error} />;
|
|
643
|
-
}
|
|
644
|
-
return <div>Failed: {status.reason}</div>;
|
|
645
|
-
|
|
646
|
-
case "complete":
|
|
647
|
-
return <SuccessDisplay />;
|
|
648
|
-
}
|
|
649
|
-
};
|
|
650
|
-
```
|
|
651
|
-
|
|
652
|
-
### Deferred Rendering
|
|
653
|
-
|
|
654
|
-
<Callout type="info">
|
|
655
|
-
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.
|
|
656
|
-
</Callout>
|
|
657
|
-
|
|
658
|
-
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.
|
|
659
|
-
|
|
660
|
-
#### Inline at the end of streaming
|
|
661
|
-
|
|
662
|
-
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:
|
|
663
|
-
|
|
664
|
-
```tsx
|
|
665
|
-
const toolkit = defineToolkit({
|
|
666
|
-
renderChart: {
|
|
667
|
-
type: "backend",
|
|
668
|
-
render: ({ args, status }) => {
|
|
669
|
-
if (status.type !== "complete") return null;
|
|
670
|
-
return <Chart title={args.title} data={args.series} />;
|
|
671
|
-
},
|
|
672
|
-
},
|
|
673
|
-
});
|
|
674
|
-
```
|
|
675
|
-
|
|
676
|
-
The chart mounts once, with the final args, after streaming finishes. No re-renders during the stream.
|
|
677
|
-
|
|
678
|
-
The same `render` shape works inside the [`Tools()`](/docs/tools/defining-tools) toolkit's `render` field and with `MessagePrimitive.Parts`'s inline `tools.by_name` overrides.
|
|
679
|
-
|
|
680
|
-
#### Below the message body
|
|
681
|
-
|
|
682
|
-
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`:
|
|
683
|
-
|
|
684
|
-
```tsx
|
|
685
|
-
import { MessagePrimitive, AuiIf, useAuiState } from "@assistant-ui/react";
|
|
686
|
-
|
|
687
|
-
function PostMessageCard() {
|
|
688
|
-
const parts = useAuiState((s) => s.message.parts);
|
|
689
|
-
const chartCall = parts.find(
|
|
690
|
-
(p) => p.type === "tool-call" && p.toolName === "renderChart",
|
|
691
|
-
);
|
|
692
|
-
if (!chartCall) return null;
|
|
693
|
-
return <Chart {...chartCall.args} />;
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
<MessagePrimitive.Root>
|
|
697
|
-
<MessagePrimitive.Parts />
|
|
698
|
-
|
|
699
|
-
<AuiIf
|
|
700
|
-
condition={(s) =>
|
|
701
|
-
s.message.role === "assistant" &&
|
|
702
|
-
s.message.status?.type === "complete"
|
|
703
|
-
}
|
|
704
|
-
>
|
|
705
|
-
<PostMessageCard />
|
|
706
|
-
</AuiIf>
|
|
707
|
-
</MessagePrimitive.Root>;
|
|
708
|
-
```
|
|
709
|
-
|
|
710
|
-
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.
|
|
711
|
-
|
|
712
|
-
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.
|
|
713
|
-
|
|
714
|
-
### Field-Level Streaming State
|
|
715
|
-
|
|
716
|
-
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:
|
|
717
|
-
|
|
718
|
-
```tsx
|
|
719
|
-
import { useToolArgsStatus } from "@assistant-ui/react";
|
|
720
|
-
|
|
721
|
-
const toolkit = defineToolkit({
|
|
722
|
-
submitForm: {
|
|
723
|
-
type: "backend",
|
|
724
|
-
render: ({ args }) => {
|
|
725
|
-
const { propStatus } = useToolArgsStatus<{
|
|
726
|
-
email: string;
|
|
727
|
-
phone: string;
|
|
728
|
-
}>();
|
|
729
|
-
|
|
730
|
-
return (
|
|
731
|
-
<form className="space-y-4">
|
|
732
|
-
<div>
|
|
733
|
-
<input
|
|
734
|
-
type="email"
|
|
735
|
-
value={args.email ?? ""}
|
|
736
|
-
className={propStatus.email === "streaming" ? "loading" : ""}
|
|
737
|
-
disabled
|
|
738
|
-
/>
|
|
739
|
-
</div>
|
|
740
|
-
|
|
741
|
-
<div>
|
|
742
|
-
<input
|
|
743
|
-
type="tel"
|
|
744
|
-
value={args.phone ?? ""}
|
|
745
|
-
className={propStatus.phone === "streaming" ? "loading" : ""}
|
|
746
|
-
disabled
|
|
747
|
-
/>
|
|
748
|
-
</div>
|
|
749
|
-
</form>
|
|
750
|
-
);
|
|
751
|
-
},
|
|
752
|
-
},
|
|
753
|
-
});
|
|
754
|
-
```
|
|
755
|
-
|
|
756
|
-
### Partial Results & Streaming
|
|
757
|
-
|
|
758
|
-
Display results as they stream in:
|
|
759
|
-
|
|
760
|
-
```tsx
|
|
761
|
-
const toolkit = defineToolkit({
|
|
762
|
-
analyzeData: {
|
|
763
|
-
type: "backend",
|
|
764
|
-
render: ({ result, status }) => {
|
|
765
|
-
const progress = result?.progress || 0;
|
|
766
|
-
const insights = result?.insights || [];
|
|
767
|
-
|
|
768
|
-
return (
|
|
769
|
-
<div className="analysis-container">
|
|
770
|
-
{status.type === "running" && (
|
|
771
|
-
<div className="mb-4">
|
|
772
|
-
<div className="mb-1 flex justify-between">
|
|
773
|
-
<span>Analyzing...</span>
|
|
774
|
-
<span>{progress}%</span>
|
|
775
|
-
</div>
|
|
776
|
-
<div className="w-full rounded bg-gray-200">
|
|
777
|
-
<div
|
|
778
|
-
className="h-2 rounded bg-blue-500"
|
|
779
|
-
style={{ width: `${progress}%` }}
|
|
780
|
-
/>
|
|
781
|
-
</div>
|
|
782
|
-
</div>
|
|
783
|
-
)}
|
|
784
|
-
|
|
785
|
-
<div className="space-y-2">
|
|
786
|
-
{insights.map((insight, i) => (
|
|
787
|
-
<div key={i} className="rounded bg-gray-50 p-2">
|
|
788
|
-
{insight}
|
|
789
|
-
</div>
|
|
790
|
-
))}
|
|
791
|
-
</div>
|
|
792
|
-
</div>
|
|
793
|
-
);
|
|
794
|
-
},
|
|
795
|
-
},
|
|
796
|
-
});
|
|
797
|
-
```
|
|
798
|
-
|
|
799
|
-
### Custom Tool Fallback
|
|
800
|
-
|
|
801
|
-
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.
|
|
802
|
-
|
|
803
|
-
## Execution Context
|
|
804
|
-
|
|
805
|
-
Generative UI components have access to execution context through props:
|
|
806
|
-
|
|
807
|
-
```tsx
|
|
808
|
-
type ToolCallMessagePartProps<TArgs, TResult> = {
|
|
809
|
-
// Tool arguments
|
|
810
|
-
args: TArgs;
|
|
811
|
-
argsText: string; // JSON stringified args
|
|
812
|
-
|
|
813
|
-
// Execution status
|
|
814
|
-
status: ToolCallMessagePartStatus;
|
|
815
|
-
isError?: boolean;
|
|
816
|
-
|
|
817
|
-
// Tool result (may be partial during streaming)
|
|
818
|
-
result?: TResult;
|
|
819
|
-
|
|
820
|
-
// Tool metadata
|
|
821
|
-
toolName: string;
|
|
822
|
-
toolCallId: string;
|
|
823
|
-
|
|
824
|
-
// Interactive callbacks
|
|
825
|
-
addResult: (result: TResult | ToolResponse<TResult>) => void;
|
|
826
|
-
resume: (payload: unknown) => void;
|
|
827
|
-
|
|
828
|
-
// Interrupt state
|
|
829
|
-
interrupt?: { type: "human"; payload: unknown }; // Payload from context.human()
|
|
830
|
-
|
|
831
|
-
// Optional artifact data
|
|
832
|
-
artifact?: unknown;
|
|
833
|
-
};
|
|
834
|
-
```
|
|
835
|
-
|
|
836
|
-
### Human Input Handling
|
|
837
|
-
|
|
838
|
-
When a tool calls `human()` during execution, the payload becomes available in the render function as `interrupt.payload`:
|
|
839
|
-
|
|
840
|
-
```tsx
|
|
841
|
-
const toolkit = defineToolkit({
|
|
842
|
-
confirmAction: {
|
|
843
|
-
type: "backend",
|
|
844
|
-
render: ({ args, result, interrupt, resume }) => {
|
|
845
|
-
// Tool is waiting for user input
|
|
846
|
-
if (interrupt) {
|
|
847
|
-
return (
|
|
848
|
-
<div className="confirmation-dialog">
|
|
849
|
-
<p>Confirm: {interrupt.payload.message}</p>
|
|
850
|
-
<button onClick={() => resume(true)}>Yes</button>
|
|
851
|
-
<button onClick={() => resume(false)}>No</button>
|
|
852
|
-
</div>
|
|
853
|
-
);
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
// Tool completed
|
|
857
|
-
if (result) {
|
|
858
|
-
return <div>Action {result.confirmed ? "confirmed" : "cancelled"}</div>;
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
return <div>Processing...</div>;
|
|
862
|
-
},
|
|
863
|
-
},
|
|
864
|
-
});
|
|
865
|
-
```
|
|
866
|
-
|
|
867
|
-
Learn more about tool human input in the [Tools Guide](/docs/tools/defining-tools#human-tools).
|
|
868
|
-
|
|
869
|
-
## Best Practices
|
|
870
|
-
|
|
871
|
-
### 1. Handle All Status States
|
|
872
|
-
|
|
873
|
-
Always handle loading, error, and success states:
|
|
874
|
-
|
|
875
|
-
```tsx
|
|
876
|
-
render: ({ status, result, args }) => {
|
|
877
|
-
if (status.type === "running") return <Skeleton />;
|
|
878
|
-
if (status.type === "incomplete") return <ErrorState />;
|
|
879
|
-
if (!result) return null;
|
|
880
|
-
return <ResultDisplay result={result} />;
|
|
881
|
-
};
|
|
882
|
-
```
|
|
883
|
-
|
|
884
|
-
### 2. Provide Visual Feedback
|
|
885
|
-
|
|
886
|
-
Use animations and transitions for better UX:
|
|
887
|
-
|
|
888
|
-
```tsx
|
|
889
|
-
<div
|
|
890
|
-
className={cn(
|
|
891
|
-
"transition-all duration-300",
|
|
892
|
-
status.type === "running" && "opacity-50",
|
|
893
|
-
status.type === "complete" && "opacity-100",
|
|
894
|
-
)}
|
|
895
|
-
>
|
|
896
|
-
{/* Tool UI content */}
|
|
897
|
-
</div>
|
|
898
|
-
```
|
|
899
|
-
|
|
900
|
-
### 3. Make UIs Accessible
|
|
901
|
-
|
|
902
|
-
Ensure keyboard navigation and screen reader support:
|
|
903
|
-
|
|
904
|
-
```tsx
|
|
905
|
-
<button
|
|
906
|
-
onClick={() => addResult(value)}
|
|
907
|
-
aria-label="Confirm selection"
|
|
908
|
-
className="focus:outline-none focus:ring-2"
|
|
909
|
-
>
|
|
910
|
-
Confirm
|
|
911
|
-
</button>
|
|
912
|
-
```
|
|
913
|
-
|
|
914
|
-
### 4. Optimize Performance
|
|
915
|
-
|
|
916
|
-
Use `useInlineRender` to prevent unnecessary re-renders:
|
|
917
|
-
|
|
918
|
-
```tsx title="heavy-computation-toolkit.tsx"
|
|
919
|
-
"use client";
|
|
920
|
-
|
|
921
|
-
import { defineToolkit, useInlineRender } from "@assistant-ui/react";
|
|
922
|
-
import { useMemo } from "react";
|
|
923
|
-
|
|
924
|
-
export function useHeavyComputationToolkit() {
|
|
925
|
-
const renderHeavyComputation = useInlineRender(({ result }) => {
|
|
926
|
-
return <ComplexVisualization data={result} />;
|
|
927
|
-
});
|
|
928
|
-
|
|
929
|
-
return useMemo(
|
|
930
|
-
() =>
|
|
931
|
-
defineToolkit({
|
|
932
|
-
heavyComputation: {
|
|
933
|
-
type: "backend",
|
|
934
|
-
render: renderHeavyComputation,
|
|
935
|
-
},
|
|
936
|
-
}),
|
|
937
|
-
[renderHeavyComputation],
|
|
938
|
-
);
|
|
939
|
-
}
|
|
940
|
-
```
|
|
941
|
-
|
|
942
|
-
```tsx title="HeavyComputationToolProvider.tsx"
|
|
943
|
-
import { AuiConfig, AuiProvider, Tools, useAui } from "@assistant-ui/react";
|
|
944
|
-
import type { ReactNode } from "react";
|
|
945
|
-
import { useHeavyComputationToolkit } from "./heavy-computation-toolkit";
|
|
946
|
-
|
|
947
|
-
function HeavyComputationToolProvider({ children }: { children: ReactNode }) {
|
|
948
|
-
const toolkit = useHeavyComputationToolkit();
|
|
949
|
-
const aui = useAui();
|
|
950
|
-
const config = AuiConfig({ tools: Tools({ toolkit }) });
|
|
951
|
-
|
|
952
|
-
return (
|
|
953
|
-
<AuiProvider extends={aui} config={config}>
|
|
954
|
-
{children}
|
|
955
|
-
</AuiProvider>
|
|
956
|
-
);
|
|
957
|
-
}
|
|
958
|
-
```
|
|
959
|
-
|
|
960
|
-
<Callout>
|
|
961
|
-
Generative UI components are only displayed in the chat interface. The actual
|
|
962
|
-
tool execution happens on the backend. This separation allows you to create
|
|
963
|
-
rich, interactive experiences while keeping sensitive logic secure on the
|
|
964
|
-
server.
|
|
965
|
-
</Callout>
|
|
966
|
-
|
|
967
|
-
## Data-Part Generative UI
|
|
968
|
-
|
|
969
|
-
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.
|
|
970
|
-
|
|
971
|
-
**When to choose which:**
|
|
972
|
-
|
|
973
|
-
- **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/tools/defining-tools) toolkit's `render` field. 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.
|
|
974
|
-
- **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.
|
|
975
|
-
|
|
976
|
-
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.
|
|
977
|
-
|
|
978
|
-
Use `makeAssistantDataUI` to register a renderer for a named data part:
|
|
979
|
-
|
|
980
|
-
```tsx
|
|
981
|
-
import { makeAssistantDataUI } from "@assistant-ui/react";
|
|
982
|
-
|
|
983
|
-
type ChartProps = { series: number[]; title: string };
|
|
984
|
-
|
|
985
|
-
export const ChartUI = makeAssistantDataUI<ChartProps>({
|
|
986
|
-
name: "chart",
|
|
987
|
-
render: ({ data }) => (
|
|
988
|
-
<div>
|
|
989
|
-
<h3>{data.title}</h3>
|
|
990
|
-
<Chart series={data.series} />
|
|
991
|
-
</div>
|
|
992
|
-
),
|
|
993
|
-
});
|
|
994
|
-
```
|
|
995
|
-
|
|
996
|
-
Mount `<ChartUI />` once inside the `AssistantRuntimeProvider` tree; it renders nothing itself and only registers the renderer.
|
|
997
|
-
|
|
998
|
-
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).
|
|
999
|
-
|
|
1000
|
-
A fallback renderer for unmatched data parts is available internally but `setFallbackDataUI` is not yet a public API.
|
|
1001
|
-
|
|
1002
|
-
## Related Guides
|
|
1003
|
-
|
|
1004
|
-
- [Tools Guide](/docs/tools/defining-tools) - Learn how to create and use tools with AI models
|
|
1005
|
-
- [Multi-Agent](/docs/tools/multi-agent) - Render sub-agent conversations inside tool call UIs
|
|
1006
|
-
- [Tool Fallback](/docs/ui/tool-fallback) - Default UI for tools without custom components
|
|
1007
|
-
- [API Reference](/docs/api-reference/primitives/message-part) - Detailed type definitions and component APIs
|
|
1008
|
-
- [Message Primitive](/docs/api-reference/primitives/message) - Complete Message component documentation
|