@assistant-ui/mcp-docs-server 0.1.31 → 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.
- package/.docs/organized/code-examples/waterfall.md +23 -25
- package/.docs/organized/code-examples/with-a2a.md +28 -28
- package/.docs/organized/code-examples/with-ag-ui.md +35 -30
- package/.docs/organized/code-examples/with-ai-sdk-v6.md +16 -14
- package/.docs/organized/code-examples/with-artifacts.md +44 -38
- package/.docs/organized/code-examples/with-assistant-transport.md +68 -56
- package/.docs/organized/code-examples/with-browser-extension.md +357 -0
- package/.docs/organized/code-examples/with-chain-of-thought.md +425 -90
- package/.docs/organized/code-examples/with-cloud-standalone.md +30 -29
- package/.docs/organized/code-examples/with-cloud.md +16 -14
- package/.docs/organized/code-examples/with-custom-thread-list.md +19 -17
- package/.docs/organized/code-examples/with-elevenlabs-conversational.md +29 -26
- package/.docs/organized/code-examples/with-elevenlabs-scribe.md +20 -18
- package/.docs/organized/code-examples/with-expo.md +37 -31
- package/.docs/organized/code-examples/with-external-store.md +13 -11
- package/.docs/organized/code-examples/with-ffmpeg.md +327 -290
- package/.docs/organized/code-examples/with-generative-ui.md +1195 -194
- package/.docs/organized/code-examples/with-google-adk.md +13 -11
- package/.docs/organized/code-examples/with-heat-graph.md +16 -14
- package/.docs/organized/code-examples/with-image-generation.md +456 -0
- package/.docs/organized/code-examples/with-interactables.md +322 -244
- package/.docs/organized/code-examples/with-langchain.md +18 -16
- package/.docs/organized/code-examples/with-langgraph.md +95 -88
- package/.docs/organized/code-examples/with-livekit.md +30 -27
- package/.docs/organized/code-examples/with-mcp.md +754 -0
- package/.docs/organized/code-examples/with-opencode.md +70 -70
- package/.docs/organized/code-examples/with-react-hook-form.md +24 -22
- package/.docs/organized/code-examples/with-react-ink.md +4 -4
- package/.docs/organized/code-examples/with-react-router.md +20 -18
- package/.docs/organized/code-examples/with-resumable-stream.md +661 -0
- package/.docs/organized/code-examples/with-store.md +22 -20
- package/.docs/organized/code-examples/with-tanstack.md +18 -19
- package/.docs/organized/code-examples/with-tap-runtime.md +31 -28
- package/.docs/raw/docs/(docs)/architecture.mdx +43 -2
- package/.docs/raw/docs/(docs)/cli.mdx +2 -2
- package/.docs/raw/docs/(docs)/copilots/model-context.mdx +34 -26
- package/.docs/raw/docs/(docs)/copilots/motivation.mdx +32 -26
- package/.docs/raw/docs/(docs)/index.mdx +2 -2
- package/.docs/raw/docs/(docs)/installation.mdx +2 -2
- package/.docs/raw/docs/(reference)/api-reference/adapters/attachments.mdx +26 -24
- package/.docs/raw/docs/(reference)/api-reference/adapters/feedback.mdx +20 -0
- package/.docs/raw/docs/(reference)/api-reference/adapters/index.mdx +20 -12
- package/.docs/raw/docs/(reference)/api-reference/adapters/model.mdx +44 -0
- package/.docs/raw/docs/(reference)/api-reference/adapters/persistence.mdx +41 -16
- package/.docs/raw/docs/(reference)/api-reference/adapters/runtime.mdx +12 -23
- package/.docs/raw/docs/(reference)/api-reference/adapters/suggestions.mdx +20 -0
- package/.docs/raw/docs/(reference)/api-reference/context-providers/assistant-runtime-provider.mdx +37 -8
- package/.docs/raw/docs/(reference)/api-reference/context-providers/index.mdx +11 -9
- package/.docs/raw/docs/(reference)/api-reference/context-providers/scoped-providers.mdx +64 -0
- package/.docs/raw/docs/(reference)/api-reference/external-store/index.mdx +22 -0
- package/.docs/raw/docs/(reference)/api-reference/external-store/message-conversion.mdx +52 -0
- package/.docs/raw/docs/(reference)/api-reference/external-store/runtime.mdx +46 -0
- 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 +98 -0
- package/.docs/raw/docs/(reference)/api-reference/hooks/index.mdx +18 -13
- package/.docs/raw/docs/(reference)/api-reference/hooks/model-context.mdx +31 -52
- package/.docs/raw/docs/(reference)/api-reference/hooks/primitives.mdx +640 -0
- package/.docs/raw/docs/(reference)/api-reference/hooks/runtimes.mdx +15 -28
- package/.docs/raw/docs/(reference)/api-reference/hooks/state.mdx +64 -18
- package/.docs/raw/docs/(reference)/api-reference/hooks/utilities.mdx +434 -0
- package/.docs/raw/docs/(reference)/api-reference/integrations/cloud-ai-sdk.mdx +24 -0
- package/.docs/raw/docs/(reference)/api-reference/integrations/index.mdx +11 -12
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-ai-sdk.mdx +109 -0
- package/.docs/raw/docs/(reference)/api-reference/model-context/context.mdx +58 -0
- package/.docs/raw/docs/(reference)/api-reference/model-context/index.mdx +22 -0
- package/.docs/raw/docs/(reference)/api-reference/model-context/registry.mdx +20 -0
- package/.docs/raw/docs/(reference)/api-reference/overview.mdx +109 -132
- package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar-more.mdx +78 -221
- package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar.mdx +127 -242
- package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-if.mdx +39 -20
- package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-modal.mdx +66 -87
- package/.docs/raw/docs/(reference)/api-reference/primitives/attachment.mdx +50 -58
- package/.docs/raw/docs/(reference)/api-reference/primitives/branch-picker.mdx +80 -48
- package/.docs/raw/docs/(reference)/api-reference/primitives/chain-of-thought.mdx +67 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/composer.mdx +323 -461
- package/.docs/raw/docs/(reference)/api-reference/primitives/error.mdx +36 -43
- package/.docs/raw/docs/(reference)/api-reference/primitives/index.mdx +29 -24
- package/.docs/raw/docs/(reference)/api-reference/primitives/message-part.mdx +63 -245
- package/.docs/raw/docs/(reference)/api-reference/primitives/message.mdx +202 -588
- package/.docs/raw/docs/(reference)/api-reference/primitives/queue-item.mdx +65 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/selection-toolbar.mdx +35 -22
- package/.docs/raw/docs/(reference)/api-reference/primitives/suggestion.mdx +57 -140
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item-more.mdx +70 -161
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item.mdx +84 -108
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list.mdx +77 -96
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread.mdx +173 -349
- package/.docs/raw/docs/(reference)/api-reference/runtimes/assistant-runtime.mdx +9 -21
- package/.docs/raw/docs/(reference)/api-reference/runtimes/attachment-runtime.mdx +10 -21
- package/.docs/raw/docs/(reference)/api-reference/runtimes/composer-runtime.mdx +15 -70
- package/.docs/raw/docs/(reference)/api-reference/runtimes/index.mdx +18 -13
- package/.docs/raw/docs/(reference)/api-reference/runtimes/message-part-runtime.mdx +25 -28
- package/.docs/raw/docs/(reference)/api-reference/runtimes/message-runtime.mdx +11 -63
- package/.docs/raw/docs/(reference)/api-reference/runtimes/queue-state.mdx +20 -0
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-item-runtime.mdx +11 -48
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-runtime.mdx +10 -47
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-runtime.mdx +18 -30
- package/.docs/raw/docs/(reference)/api-reference/tools/component-tools.mdx +85 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/index.mdx +39 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/rendering.mdx +127 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/status.mdx +42 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/toolkits.mdx +91 -0
- package/.docs/raw/docs/(reference)/api-reference/transport/assistant-transport.mdx +48 -0
- package/.docs/raw/docs/(reference)/api-reference/transport/frame.mdx +62 -0
- package/.docs/raw/docs/(reference)/api-reference/transport/index.mdx +22 -0
- package/.docs/raw/docs/(reference)/api-reference/utilities/index.mdx +19 -0
- package/.docs/raw/docs/(reference)/api-reference/utilities/miscellaneous.mdx +143 -0
- package/.docs/raw/docs/(reference)/api-reference/voice/index.mdx +22 -0
- package/.docs/raw/docs/(reference)/api-reference/voice/session.mdx +54 -0
- package/.docs/raw/docs/(reference)/api-reference/voice/speech-dictation.mdx +36 -0
- package/.docs/raw/docs/cloud/ai-sdk.mdx +1 -3
- package/.docs/raw/docs/cloud/index.mdx +2 -2
- package/.docs/raw/docs/guides/attachments.mdx +4 -4
- package/.docs/raw/docs/guides/branching.mdx +1 -1
- package/.docs/raw/docs/guides/chain-of-thought.mdx +12 -14
- package/.docs/raw/docs/guides/context-api.mdx +6 -5
- package/.docs/raw/docs/guides/dictation.mdx +2 -2
- package/.docs/raw/docs/guides/editing.mdx +1 -1
- package/.docs/raw/docs/guides/image-generation.mdx +74 -0
- package/.docs/raw/docs/guides/index.mdx +5 -14
- package/.docs/raw/docs/guides/latex.mdx +2 -2
- package/.docs/raw/docs/guides/mentions.mdx +6 -6
- package/.docs/raw/docs/guides/message-timing.mdx +38 -5
- package/.docs/raw/docs/guides/quoting.mdx +1 -1
- package/.docs/raw/docs/guides/resumable-stream-deployment.mdx +212 -0
- package/.docs/raw/docs/guides/resumable-stream-stores.mdx +152 -0
- package/.docs/raw/docs/guides/resumable-streams.mdx +210 -0
- package/.docs/raw/docs/guides/slash-commands.mdx +2 -2
- package/.docs/raw/docs/guides/speech.mdx +2 -2
- package/.docs/raw/docs/guides/suggestions.mdx +89 -5
- package/.docs/raw/docs/guides/voice.mdx +2 -2
- package/.docs/raw/docs/ink/adapters.mdx +37 -1
- package/.docs/raw/docs/ink/custom-backend.mdx +59 -8
- package/.docs/raw/docs/ink/hooks.mdx +98 -85
- package/.docs/raw/docs/ink/index.mdx +10 -11
- package/.docs/raw/docs/ink/migration.mdx +1 -1
- package/.docs/raw/docs/ink/primitives.mdx +350 -9
- package/.docs/raw/docs/integrations/auth/better-auth.mdx +1 -1
- package/.docs/raw/docs/integrations/auth/clerk.mdx +1 -1
- package/.docs/raw/docs/integrations/auth/next-auth.mdx +1 -1
- package/.docs/raw/docs/integrations/frameworks/ai-sdk.mdx +3 -3
- package/.docs/raw/docs/integrations/frameworks/cloudflare-agents/overview.mdx +282 -0
- package/.docs/raw/docs/integrations/frameworks/mastra/overview.mdx +2 -2
- package/.docs/raw/docs/integrations/frameworks/mastra/separate-server.mdx +1 -1
- package/.docs/raw/docs/integrations/gateways/index.mdx +9 -4
- package/.docs/raw/docs/integrations/index.mdx +17 -5
- package/.docs/raw/docs/integrations/observability/langfuse.mdx +8 -1
- package/.docs/raw/docs/integrations/observability/langsmith.mdx +8 -4
- package/.docs/raw/docs/integrations/persistence/custom-adapter.mdx +17 -2
- package/.docs/raw/docs/migrations/toolkit-tools.mdx +226 -0
- package/.docs/raw/docs/primitives/chain-of-thought.mdx +10 -16
- package/.docs/raw/docs/primitives/composer.mdx +53 -0
- package/.docs/raw/docs/primitives/index.mdx +2 -2
- package/.docs/raw/docs/primitives/message.mdx +9 -10
- package/.docs/raw/docs/primitives/suggestion.mdx +9 -0
- package/.docs/raw/docs/react-native/hooks.mdx +57 -82
- package/.docs/raw/docs/react-native/index.mdx +4 -4
- 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 +7 -4
- package/.docs/raw/docs/runtimes/a2a/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/ag-ui/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/ag-ui/runtime-options.mdx +32 -1
- package/.docs/raw/docs/runtimes/ai-sdk/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +7 -2
- package/.docs/raw/docs/runtimes/ai-sdk/v5-legacy.mdx +1 -1
- package/.docs/raw/docs/runtimes/ai-sdk/v6.mdx +129 -1
- package/.docs/raw/docs/runtimes/concepts/threads.mdx +7 -1
- package/.docs/raw/docs/runtimes/custom/data-stream.mdx +27 -2
- package/.docs/raw/docs/runtimes/custom/external-store.mdx +9 -1
- package/.docs/raw/docs/runtimes/custom/local-runtime.mdx +18 -7
- package/.docs/raw/docs/runtimes/custom/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/google-adk/hooks.mdx +108 -38
- package/.docs/raw/docs/runtimes/google-adk/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/langchain.mdx +2 -2
- package/.docs/raw/docs/runtimes/langgraph/generative-ui.mdx +2 -2
- package/.docs/raw/docs/runtimes/langgraph/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/langgraph/streaming.mdx +1 -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/runtimes/opencode/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/opencode/quickstart.mdx +1 -1
- package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +12 -5
- package/.docs/raw/docs/tools/backend.mdx +136 -0
- package/.docs/raw/docs/tools/defining-tools.mdx +413 -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 +76 -0
- package/.docs/raw/docs/{guides → tools}/interactables.mdx +3 -3
- package/.docs/raw/docs/tools/mcp-apps.mdx +231 -0
- package/.docs/raw/docs/{integrations/tools → tools}/mcp.mdx +77 -50
- package/.docs/raw/docs/{guides → tools}/multi-agent.mdx +19 -21
- package/.docs/raw/docs/tools/tool-ui.mdx +967 -0
- package/.docs/raw/docs/tools/user-managed-mcp.mdx +337 -0
- package/.docs/raw/docs/ui/composer-trigger-popover.mdx +11 -1
- package/.docs/raw/docs/ui/directive-text.mdx +3 -3
- package/.docs/raw/docs/ui/mcp-config.mdx +102 -0
- package/.docs/raw/docs/ui/model-selector.mdx +8 -8
- package/.docs/raw/docs/ui/part-grouping.mdx +84 -50
- package/.docs/raw/docs/ui/reasoning.mdx +4 -5
- package/.docs/raw/docs/ui/sources.mdx +17 -0
- package/.docs/raw/docs/ui/streamdown.mdx +34 -2
- package/.docs/raw/docs/ui/thread-list.mdx +2 -2
- package/.docs/raw/docs/ui/thread.mdx +2 -2
- package/.docs/raw/docs/ui/tool-group.mdx +5 -6
- package/.docs/raw/docs/utilities/heat-graph.mdx +1 -1
- package/README.md +14 -72
- package/dist/constants.d.ts +12 -9
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +13 -9
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -24
- package/dist/index.js.map +1 -1
- package/dist/prepare-docs/code-examples.d.ts +4 -1
- package/dist/prepare-docs/code-examples.d.ts.map +1 -1
- package/dist/prepare-docs/code-examples.js +109 -121
- package/dist/prepare-docs/code-examples.js.map +1 -1
- package/dist/prepare-docs/copy-raw.d.ts +4 -1
- package/dist/prepare-docs/copy-raw.d.ts.map +1 -1
- package/dist/prepare-docs/copy-raw.js +45 -42
- package/dist/prepare-docs/copy-raw.js.map +1 -1
- package/dist/prepare-docs/prepare.d.ts +1 -2
- package/dist/prepare-docs/prepare.js +17 -17
- package/dist/prepare-docs/prepare.js.map +1 -1
- package/dist/stdio.d.ts +1 -3
- package/dist/stdio.js +6 -3
- package/dist/stdio.js.map +1 -1
- package/dist/tools/docs.d.ts +20 -15
- package/dist/tools/docs.d.ts.map +1 -1
- package/dist/tools/docs.js +140 -161
- package/dist/tools/docs.js.map +1 -1
- package/dist/tools/examples.d.ts +20 -15
- package/dist/tools/examples.d.ts.map +1 -1
- package/dist/tools/examples.js +74 -86
- package/dist/tools/examples.js.map +1 -1
- package/dist/tools/tests/test-setup.d.ts +5 -2
- package/dist/tools/tests/test-setup.d.ts.map +1 -1
- package/dist/tools/tests/test-setup.js +21 -28
- package/dist/tools/tests/test-setup.js.map +1 -1
- package/dist/utils/logger.d.ts +8 -5
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +17 -17
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/mcp-format.d.ts +8 -5
- package/dist/utils/mcp-format.d.ts.map +1 -1
- package/dist/utils/mcp-format.js +9 -9
- package/dist/utils/mcp-format.js.map +1 -1
- package/dist/utils/mdx.d.ts +8 -6
- package/dist/utils/mdx.d.ts.map +1 -1
- package/dist/utils/mdx.js +22 -22
- package/dist/utils/mdx.js.map +1 -1
- package/dist/utils/paths.d.ts +9 -6
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +66 -76
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/security.d.ts +4 -1
- package/dist/utils/security.d.ts.map +1 -1
- package/dist/utils/security.js +19 -40
- package/dist/utils/security.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/(reference)/api-reference/adapters/feedback-speech.mdx +0 -41
- package/.docs/raw/docs/(reference)/api-reference/context-providers/text-message-part-provider.mdx +0 -40
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-data-stream.mdx +0 -260
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-hook-form.mdx +0 -103
- package/.docs/raw/docs/(reference)/api-reference/integrations/vercel-ai-sdk.mdx +0 -254
- package/.docs/raw/docs/guides/tool-ui.mdx +0 -858
- package/.docs/raw/docs/guides/tools.mdx +0 -675
- package/dist/prepare-docs/prepare.d.ts.map +0 -1
- package/dist/stdio.d.ts.map +0 -1
- /package/.docs/raw/docs/{(reference)/migrations → migrations}/deprecation-policy.mdx +0 -0
- /package/.docs/raw/docs/{(reference) → migrations}/react-compatibility.mdx +0 -0
- /package/.docs/raw/docs/{(reference)/migrations → migrations}/react-langgraph-v0-7.mdx +0 -0
- /package/.docs/raw/docs/{(reference)/migrations → migrations}/v0-11.mdx +0 -0
- /package/.docs/raw/docs/{(reference)/migrations → migrations}/v0-12.mdx +0 -0
- /package/.docs/raw/docs/{(reference)/migrations → migrations}/v0-14.mdx +0 -0
|
@@ -1,675 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Tools
|
|
3
|
-
description: Give your assistant actions like API calls, database queries, and more.
|
|
4
|
-
platforms: ["react"]
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
Tools enable LLMs to take actions and interact with external systems. assistant-ui provides a comprehensive toolkit for creating, managing, and visualizing tool interactions in real-time.
|
|
8
|
-
|
|
9
|
-
## Overview
|
|
10
|
-
|
|
11
|
-
Tools in assistant-ui are functions that the LLM can call to perform specific tasks. They bridge the gap between the LLM's reasoning capabilities and real-world actions like:
|
|
12
|
-
|
|
13
|
-
- Fetching data from APIs
|
|
14
|
-
- Performing calculations
|
|
15
|
-
- Interacting with databases
|
|
16
|
-
- Controlling UI elements
|
|
17
|
-
- Executing workflows
|
|
18
|
-
|
|
19
|
-
When tools are executed, you can display custom generative UI components that provide rich, interactive visualizations of the tool's execution and results. Learn more in the [Generative UI guide](/docs/guides/tool-ui).
|
|
20
|
-
|
|
21
|
-
<Callout type="tip">
|
|
22
|
-
If you haven't provided a custom UI for a tool, assistant-ui offers a
|
|
23
|
-
[`ToolFallback`](/docs/ui/tool-fallback) component that you can add to your
|
|
24
|
-
codebase to render a default UI for tool executions. You can customize this by
|
|
25
|
-
creating your own Tool UI component for the tool's name.
|
|
26
|
-
</Callout>
|
|
27
|
-
|
|
28
|
-
## Tools() API
|
|
29
|
-
|
|
30
|
-
The `Tools()` API is the recommended starting point for registering tools in assistant-ui. It provides centralized tool registration that prevents duplicate registrations and works seamlessly with all runtimes. For tools whose availability depends on a specific part of your UI being mounted, see the [component-based APIs](#component-based-apis) below; both styles are supported and can be mixed in the same app.
|
|
31
|
-
|
|
32
|
-
### Quick Start
|
|
33
|
-
|
|
34
|
-
Create a toolkit object containing all your tools, then register it using `useAui()`:
|
|
35
|
-
|
|
36
|
-
```tsx
|
|
37
|
-
import { useAui, Tools, type Toolkit } from "@assistant-ui/react";
|
|
38
|
-
import { z } from "zod";
|
|
39
|
-
|
|
40
|
-
// Define your toolkit
|
|
41
|
-
const myToolkit: Toolkit = {
|
|
42
|
-
getWeather: {
|
|
43
|
-
description: "Get current weather for a location",
|
|
44
|
-
parameters: z.object({
|
|
45
|
-
location: z.string().describe("City name or zip code"),
|
|
46
|
-
unit: z.enum(["celsius", "fahrenheit"]).default("celsius"),
|
|
47
|
-
}),
|
|
48
|
-
execute: async ({ location, unit }) => {
|
|
49
|
-
const weather = await fetchWeatherAPI(location, unit);
|
|
50
|
-
return weather;
|
|
51
|
-
},
|
|
52
|
-
render: ({ args, result }) => {
|
|
53
|
-
if (!result) return <div>Fetching weather for {args.location}...</div>;
|
|
54
|
-
return (
|
|
55
|
-
<div className="weather-card">
|
|
56
|
-
<h3>{args.location}</h3>
|
|
57
|
-
<p>{result.temperature}° {args.unit}</p>
|
|
58
|
-
<p>{result.conditions}</p>
|
|
59
|
-
</div>
|
|
60
|
-
);
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
// Add more tools here
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// Register tools in your runtime provider
|
|
67
|
-
function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
|
|
68
|
-
const runtime = useChatRuntime();
|
|
69
|
-
|
|
70
|
-
// Register all tools
|
|
71
|
-
const aui = useAui({
|
|
72
|
-
tools: Tools({ toolkit: myToolkit }),
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
<AssistantRuntimeProvider aui={aui} runtime={runtime}>
|
|
77
|
-
{children}
|
|
78
|
-
</AssistantRuntimeProvider>
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### Benefits
|
|
84
|
-
|
|
85
|
-
- **No Duplicate Registrations**: Tools are registered once, preventing the "tool already exists" error
|
|
86
|
-
- **Centralized Definition**: All your tools in one place, easier to manage and test
|
|
87
|
-
- **Type-Safe**: Full TypeScript support with proper type inference
|
|
88
|
-
- **Flexible**: Works with all runtimes (AI SDK, LangGraph, custom, etc.)
|
|
89
|
-
- **Composable**: Easily split toolkits across files and merge them
|
|
90
|
-
|
|
91
|
-
### Tool Definition
|
|
92
|
-
|
|
93
|
-
Each tool in the toolkit is a `ToolDefinition` object with these properties:
|
|
94
|
-
|
|
95
|
-
```tsx
|
|
96
|
-
type ToolDefinition =
|
|
97
|
-
| {
|
|
98
|
-
// Frontend tool: executes in the browser
|
|
99
|
-
type?: "frontend";
|
|
100
|
-
description?: string;
|
|
101
|
-
parameters: StandardSchemaV1 | JSONSchema7; // e.g. a Zod schema
|
|
102
|
-
execute: (args, context) => Promise<any>;
|
|
103
|
-
render?: (props) => React.ReactNode;
|
|
104
|
-
}
|
|
105
|
-
| {
|
|
106
|
-
// Human tool: pauses for user input (render is required)
|
|
107
|
-
type: "human";
|
|
108
|
-
description?: string;
|
|
109
|
-
parameters: StandardSchemaV1 | JSONSchema7;
|
|
110
|
-
render: (props) => React.ReactNode;
|
|
111
|
-
}
|
|
112
|
-
| {
|
|
113
|
-
// Backend tool: execution happens server-side (no execute/parameters needed)
|
|
114
|
-
type: "backend";
|
|
115
|
-
render?: (props) => React.ReactNode;
|
|
116
|
-
};
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### Organizing Large Toolkits
|
|
120
|
-
|
|
121
|
-
For larger applications, split tools across multiple files:
|
|
122
|
-
|
|
123
|
-
```tsx
|
|
124
|
-
// lib/tools/weather.tsx
|
|
125
|
-
export const weatherTools: Toolkit = {
|
|
126
|
-
getWeather: { /* ... */ },
|
|
127
|
-
getWeatherForecast: { /* ... */ },
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
// lib/tools/database.tsx
|
|
131
|
-
export const databaseTools: Toolkit = {
|
|
132
|
-
queryData: { /* ... */ },
|
|
133
|
-
insertData: { /* ... */ },
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
// lib/toolkit.tsx
|
|
137
|
-
import { weatherTools } from "./tools/weather";
|
|
138
|
-
import { databaseTools } from "./tools/database";
|
|
139
|
-
|
|
140
|
-
export const appToolkit: Toolkit = {
|
|
141
|
-
...weatherTools,
|
|
142
|
-
...databaseTools,
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
// App.tsx
|
|
146
|
-
import { appToolkit } from "./lib/toolkit";
|
|
147
|
-
|
|
148
|
-
function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
|
|
149
|
-
const runtime = useChatRuntime();
|
|
150
|
-
|
|
151
|
-
const aui = useAui({
|
|
152
|
-
tools: Tools({ toolkit: appToolkit }),
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
return (
|
|
156
|
-
<AssistantRuntimeProvider aui={aui} runtime={runtime}>
|
|
157
|
-
{children}
|
|
158
|
-
</AssistantRuntimeProvider>
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
### UI-Only Tools
|
|
164
|
-
|
|
165
|
-
For tools where execution happens elsewhere (e.g., backend MCP tools), omit the `execute` function:
|
|
166
|
-
|
|
167
|
-
```tsx
|
|
168
|
-
const uiOnlyToolkit: Toolkit = {
|
|
169
|
-
webSearch: {
|
|
170
|
-
description: "Search the web",
|
|
171
|
-
parameters: z.object({
|
|
172
|
-
query: z.string(),
|
|
173
|
-
}),
|
|
174
|
-
// No execute - handled by backend
|
|
175
|
-
render: ({ args, result }) => {
|
|
176
|
-
return (
|
|
177
|
-
<div>
|
|
178
|
-
<h3>Search: {args.query}</h3>
|
|
179
|
-
{result?.results.map((item) => (
|
|
180
|
-
<div key={item.id}>
|
|
181
|
-
<a href={item.url}>{item.title}</a>
|
|
182
|
-
</div>
|
|
183
|
-
))}
|
|
184
|
-
</div>
|
|
185
|
-
);
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
};
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### Tool Execution Context
|
|
192
|
-
|
|
193
|
-
Tools receive additional context during execution:
|
|
194
|
-
|
|
195
|
-
```tsx
|
|
196
|
-
execute: async (args, context) => {
|
|
197
|
-
// context.abortSignal - AbortSignal for cancellation
|
|
198
|
-
// context.toolCallId - Unique identifier for this invocation
|
|
199
|
-
// context.human - Function to request human input
|
|
200
|
-
|
|
201
|
-
// Example: Respect cancellation
|
|
202
|
-
const response = await fetch(url, { signal: context.abortSignal });
|
|
203
|
-
|
|
204
|
-
// Example: Request user confirmation
|
|
205
|
-
const userResponse = await context.human({
|
|
206
|
-
message: "Are you sure?",
|
|
207
|
-
});
|
|
208
|
-
};
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
### Cancellation
|
|
212
|
-
|
|
213
|
-
`context.abortSignal` is an `AbortSignal` that fires when the user stops the run. Pass it to any async I/O so the work stops immediately:
|
|
214
|
-
|
|
215
|
-
```tsx
|
|
216
|
-
execute: async ({ query }, { abortSignal }) => {
|
|
217
|
-
const res = await fetch(`/api/search?q=${query}`, { signal: abortSignal });
|
|
218
|
-
return res.json();
|
|
219
|
-
},
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
When using LangGraph with `unstable_createLangGraphStream`, the default `onDisconnect` value is already `"cancel"`, which tells the LangGraph server to cancel the run on abort:
|
|
223
|
-
|
|
224
|
-
```ts
|
|
225
|
-
import { unstable_createLangGraphStream } from "@assistant-ui/react-langgraph";
|
|
226
|
-
|
|
227
|
-
const stream = unstable_createLangGraphStream({
|
|
228
|
-
client,
|
|
229
|
-
assistantId,
|
|
230
|
-
// onDisconnect defaults to "cancel"; the server cancels the run when the
|
|
231
|
-
// client disconnects or the user stops the message.
|
|
232
|
-
});
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
See the [LangGraph quickstart](/docs/runtimes/langgraph/quickstart) for full setup.
|
|
236
|
-
|
|
237
|
-
### Human-in-the-Loop
|
|
238
|
-
|
|
239
|
-
Tools can pause execution to request user input or approval:
|
|
240
|
-
|
|
241
|
-
```tsx
|
|
242
|
-
const confirmationToolkit: Toolkit = {
|
|
243
|
-
sendEmail: {
|
|
244
|
-
description: "Send an email with confirmation",
|
|
245
|
-
parameters: z.object({
|
|
246
|
-
to: z.string(),
|
|
247
|
-
subject: z.string(),
|
|
248
|
-
body: z.string(),
|
|
249
|
-
}),
|
|
250
|
-
execute: async ({ to, subject, body }, { human }) => {
|
|
251
|
-
// Request user confirmation before sending
|
|
252
|
-
const confirmed = await human({
|
|
253
|
-
type: "confirmation",
|
|
254
|
-
action: "send-email",
|
|
255
|
-
details: { to, subject },
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
if (!confirmed) {
|
|
259
|
-
return { status: "cancelled" };
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
await sendEmail({ to, subject, body });
|
|
263
|
-
return { status: "sent" };
|
|
264
|
-
},
|
|
265
|
-
render: ({ args, result, interrupt, resume }) => {
|
|
266
|
-
// Show confirmation dialog when waiting for user input
|
|
267
|
-
if (interrupt) {
|
|
268
|
-
return (
|
|
269
|
-
<div>
|
|
270
|
-
<h3>Confirm Email</h3>
|
|
271
|
-
<p>Send to: {interrupt.payload.details.to}</p>
|
|
272
|
-
<p>Subject: {interrupt.payload.details.subject}</p>
|
|
273
|
-
<button onClick={() => resume(true)}>Confirm</button>
|
|
274
|
-
<button onClick={() => resume(false)}>Cancel</button>
|
|
275
|
-
</div>
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// Show result
|
|
280
|
-
if (result) {
|
|
281
|
-
return <div>Status: {result.status}</div>;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return <div>Preparing email...</div>;
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
};
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
### Streaming Tool Args
|
|
291
|
-
|
|
292
|
-
While a tool is running, its arguments arrive as partial JSON. Use `useToolArgsStatus` inside a tool UI render function to react to each top-level field as it streams in. The hook is exported from `@assistant-ui/react`.
|
|
293
|
-
|
|
294
|
-
```tsx
|
|
295
|
-
import { useToolArgsStatus } from "@assistant-ui/react";
|
|
296
|
-
|
|
297
|
-
const SearchToolUI = makeAssistantToolUI<{ query: string; limit: number }, unknown>({
|
|
298
|
-
toolName: "search",
|
|
299
|
-
render: ({ args }) => {
|
|
300
|
-
const { propStatus } = useToolArgsStatus<{ query: string; limit: number }>();
|
|
301
|
-
|
|
302
|
-
return (
|
|
303
|
-
<div>
|
|
304
|
-
<span className={propStatus.query === "streaming" ? "animate-pulse" : ""}>
|
|
305
|
-
{args.query ?? "..."}
|
|
306
|
-
</span>
|
|
307
|
-
{propStatus.limit === "complete" && <span> (limit: {args.limit})</span>}
|
|
308
|
-
</div>
|
|
309
|
-
);
|
|
310
|
-
},
|
|
311
|
-
});
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
`propStatus` maps each top-level key in the args object to `"streaming"` while it is still being parsed and to `"complete"` once that field is fully present.
|
|
315
|
-
|
|
316
|
-
## Component-Based APIs
|
|
317
|
-
|
|
318
|
-
`makeAssistantTool`, `useAssistantTool`, and `makeAssistantToolUI` are component-and-hook-based APIs that coexist with the [`Tools()`](#tools-api) toolkit pattern. They are fully supported and the natural fit for the [intelligent components](/docs/copilots/motivation) pattern, where each part of your UI registers the tools it owns when it is mounted, for example a product-specific tool that should only be exposed while that product's screen is open.
|
|
319
|
-
|
|
320
|
-
<Callout type="info">
|
|
321
|
-
Be careful not to register the same tool from both APIs at once: each API
|
|
322
|
-
registers under `toolName`, and duplicate registrations will be rejected.
|
|
323
|
-
</Callout>
|
|
324
|
-
|
|
325
|
-
<Callout type="warn">
|
|
326
|
-
Tool **execution** can be registered dynamically (when a component mounts),
|
|
327
|
-
but tool **UI** should generally be pre-registered. A `render` function that
|
|
328
|
-
is only registered while a specific component is mounted will not render
|
|
329
|
-
when chat history is replayed or during server-side rendering. Either
|
|
330
|
-
declare the tool's `render` in a `Tools()` toolkit, or mount
|
|
331
|
-
`makeAssistantToolUI` near the root of your tree.
|
|
332
|
-
</Callout>
|
|
333
|
-
|
|
334
|
-
### Using `makeAssistantTool`
|
|
335
|
-
|
|
336
|
-
Register tools with the assistant context. Returns a React component that registers the tool when rendered:
|
|
337
|
-
|
|
338
|
-
```tsx
|
|
339
|
-
import { makeAssistantTool, tool } from "@assistant-ui/react";
|
|
340
|
-
import { z } from "zod";
|
|
341
|
-
|
|
342
|
-
const weatherTool = tool({
|
|
343
|
-
description: "Get current weather for a location",
|
|
344
|
-
parameters: z.object({
|
|
345
|
-
location: z.string(),
|
|
346
|
-
}),
|
|
347
|
-
execute: async ({ location }) => {
|
|
348
|
-
const weather = await fetchWeatherAPI(location);
|
|
349
|
-
return weather;
|
|
350
|
-
},
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
const WeatherTool = makeAssistantTool({
|
|
354
|
-
...weatherTool,
|
|
355
|
-
toolName: "getWeather",
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
// Place inside AssistantRuntimeProvider
|
|
359
|
-
function App() {
|
|
360
|
-
return (
|
|
361
|
-
<AssistantRuntimeProvider runtime={runtime}>
|
|
362
|
-
<WeatherTool />
|
|
363
|
-
<Thread />
|
|
364
|
-
</AssistantRuntimeProvider>
|
|
365
|
-
);
|
|
366
|
-
}
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
Tradeoff: component-based registration is tied to React lifecycle, so the tool is registered when the component mounts and unregistered when it unmounts. Take care not to remount it accidentally if you also register the same tool elsewhere.
|
|
370
|
-
|
|
371
|
-
### Using the `useAssistantTool` Hook
|
|
372
|
-
|
|
373
|
-
Register tools dynamically using React hooks:
|
|
374
|
-
|
|
375
|
-
```tsx
|
|
376
|
-
import { useAssistantTool } from "@assistant-ui/react";
|
|
377
|
-
import { z } from "zod";
|
|
378
|
-
|
|
379
|
-
function DynamicTools() {
|
|
380
|
-
useAssistantTool({
|
|
381
|
-
toolName: "searchData",
|
|
382
|
-
description: "Search through the data",
|
|
383
|
-
parameters: z.object({
|
|
384
|
-
query: z.string(),
|
|
385
|
-
}),
|
|
386
|
-
execute: async ({ query }) => {
|
|
387
|
-
return await searchDatabase(query);
|
|
388
|
-
},
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
return null;
|
|
392
|
-
}
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
Tradeoff: like `makeAssistantTool`, the registration follows the component lifecycle. Useful for dynamic tools that depend on component state or props.
|
|
396
|
-
|
|
397
|
-
### Using `makeAssistantToolUI`
|
|
398
|
-
|
|
399
|
-
Create UI-only components for tools defined elsewhere:
|
|
400
|
-
|
|
401
|
-
```tsx
|
|
402
|
-
import { makeAssistantToolUI } from "@assistant-ui/react";
|
|
403
|
-
|
|
404
|
-
const SearchResultsUI = makeAssistantToolUI<
|
|
405
|
-
{ query: string },
|
|
406
|
-
{ results: Array<any> }
|
|
407
|
-
>({
|
|
408
|
-
toolName: "webSearch",
|
|
409
|
-
render: ({ args, result }) => {
|
|
410
|
-
return (
|
|
411
|
-
<div>
|
|
412
|
-
<h3>Search: {args.query}</h3>
|
|
413
|
-
{result.results.map((item) => (
|
|
414
|
-
<div key={item.id}>{item.title}</div>
|
|
415
|
-
))}
|
|
416
|
-
</div>
|
|
417
|
-
);
|
|
418
|
-
},
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
function App() {
|
|
422
|
-
return (
|
|
423
|
-
<AssistantRuntimeProvider runtime={runtime}>
|
|
424
|
-
<SearchResultsUI />
|
|
425
|
-
<Thread />
|
|
426
|
-
</AssistantRuntimeProvider>
|
|
427
|
-
);
|
|
428
|
-
}
|
|
429
|
-
```
|
|
430
|
-
|
|
431
|
-
Tradeoff: like the other component-based APIs, the UI is registered while the component is mounted. Useful when the tool UI needs access to surrounding component state or context.
|
|
432
|
-
|
|
433
|
-
## Tool Paradigms
|
|
434
|
-
|
|
435
|
-
### Frontend Tools
|
|
436
|
-
|
|
437
|
-
Tools that execute in the browser:
|
|
438
|
-
|
|
439
|
-
```tsx
|
|
440
|
-
const frontendToolkit: Toolkit = {
|
|
441
|
-
screenshot: {
|
|
442
|
-
description: "Capture a screenshot of the current page",
|
|
443
|
-
parameters: z.object({
|
|
444
|
-
selector: z.string().optional(),
|
|
445
|
-
}),
|
|
446
|
-
execute: async ({ selector }) => {
|
|
447
|
-
const element = selector ? document.querySelector(selector) : document.body;
|
|
448
|
-
const screenshot = await captureElement(element);
|
|
449
|
-
return { dataUrl: screenshot };
|
|
450
|
-
},
|
|
451
|
-
},
|
|
452
|
-
};
|
|
453
|
-
```
|
|
454
|
-
|
|
455
|
-
### Backend Tools
|
|
456
|
-
|
|
457
|
-
Tools executed server-side live in your API route. A minimal example with the AI SDK:
|
|
458
|
-
|
|
459
|
-
```ts title="@/app/api/chat/route.ts"
|
|
460
|
-
import { openai } from "@ai-sdk/openai";
|
|
461
|
-
import { streamText, convertToModelMessages, tool, zodSchema } from "ai";
|
|
462
|
-
import { z } from "zod";
|
|
463
|
-
|
|
464
|
-
export async function POST(req: Request) {
|
|
465
|
-
const { messages } = await req.json();
|
|
466
|
-
const result = streamText({
|
|
467
|
-
model: openai("gpt-4o"),
|
|
468
|
-
messages: await convertToModelMessages(messages),
|
|
469
|
-
tools: {
|
|
470
|
-
queryDatabase: tool({
|
|
471
|
-
description: "Query the application database",
|
|
472
|
-
inputSchema: zodSchema(z.object({ query: z.string(), table: z.string() })),
|
|
473
|
-
execute: async ({ query, table }) => db.query(query, { table }),
|
|
474
|
-
}),
|
|
475
|
-
},
|
|
476
|
-
});
|
|
477
|
-
return result.toUIMessageStreamResponse();
|
|
478
|
-
}
|
|
479
|
-
```
|
|
480
|
-
|
|
481
|
-
For the full AI SDK v6 backend setup including multi-step tool calls, frontend tools, history persistence with `withFormat`, and more, see the [AI SDK v6 guide](/docs/runtimes/ai-sdk/v6).
|
|
482
|
-
|
|
483
|
-
### Client-Defined Tools with frontendTools
|
|
484
|
-
|
|
485
|
-
The Vercel AI SDK adapter implements automatic serialization of client-defined tools. Tools registered via the `Tools()` API are automatically included in API requests:
|
|
486
|
-
|
|
487
|
-
```tsx
|
|
488
|
-
// Frontend: Define tools with Tools() API
|
|
489
|
-
const clientToolkit: Toolkit = {
|
|
490
|
-
calculate: {
|
|
491
|
-
description: "Perform calculations",
|
|
492
|
-
parameters: z.object({
|
|
493
|
-
expression: z.string(),
|
|
494
|
-
}),
|
|
495
|
-
execute: async ({ expression }) => {
|
|
496
|
-
return eval(expression); // Use proper parser in production
|
|
497
|
-
},
|
|
498
|
-
},
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
|
|
502
|
-
const runtime = useChatRuntime();
|
|
503
|
-
|
|
504
|
-
const aui = useAui({
|
|
505
|
-
tools: Tools({ toolkit: clientToolkit }),
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
return (
|
|
509
|
-
<AssistantRuntimeProvider aui={aui} runtime={runtime}>
|
|
510
|
-
{children}
|
|
511
|
-
</AssistantRuntimeProvider>
|
|
512
|
-
);
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// Backend: Use frontendTools to receive client tools
|
|
516
|
-
import { frontendTools } from "@assistant-ui/react-ai-sdk";
|
|
517
|
-
|
|
518
|
-
export async function POST(req: Request) {
|
|
519
|
-
const { messages, tools } = await req.json();
|
|
520
|
-
|
|
521
|
-
const result = streamText({
|
|
522
|
-
model: openai("gpt-4o"),
|
|
523
|
-
messages: await convertToModelMessages(messages),
|
|
524
|
-
tools: {
|
|
525
|
-
...frontendTools(tools), // Client-defined tools
|
|
526
|
-
// Additional server-side tools
|
|
527
|
-
queryDatabase: {
|
|
528
|
-
description: "Query the database",
|
|
529
|
-
inputSchema: zodSchema(z.object({ query: z.string() })),
|
|
530
|
-
execute: async ({ query }) => {
|
|
531
|
-
return await db.query(query);
|
|
532
|
-
},
|
|
533
|
-
},
|
|
534
|
-
},
|
|
535
|
-
});
|
|
536
|
-
|
|
537
|
-
return result.toUIMessageStreamResponse();
|
|
538
|
-
}
|
|
539
|
-
```
|
|
540
|
-
|
|
541
|
-
### MCP (Model Context Protocol) Tools
|
|
542
|
-
|
|
543
|
-
Integration with MCP servers using AI SDK's experimental MCP support:
|
|
544
|
-
|
|
545
|
-
```tsx
|
|
546
|
-
import { experimental_createMCPClient, streamText } from "ai";
|
|
547
|
-
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
548
|
-
|
|
549
|
-
export async function POST(req: Request) {
|
|
550
|
-
const client = await experimental_createMCPClient({
|
|
551
|
-
transport: new StdioClientTransport({
|
|
552
|
-
command: "npx",
|
|
553
|
-
args: ["@modelcontextprotocol/server-github"],
|
|
554
|
-
}),
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
try {
|
|
558
|
-
const tools = await client.tools();
|
|
559
|
-
|
|
560
|
-
const result = streamText({
|
|
561
|
-
model: openai("gpt-4o"),
|
|
562
|
-
tools,
|
|
563
|
-
messages: await convertToModelMessages(messages),
|
|
564
|
-
});
|
|
565
|
-
|
|
566
|
-
return result.toUIMessageStreamResponse();
|
|
567
|
-
} finally {
|
|
568
|
-
await client.close();
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
```
|
|
572
|
-
|
|
573
|
-
## LangGraph subgraph events
|
|
574
|
-
|
|
575
|
-
When a LangGraph graph contains sub-agents (nested subgraphs), events from those subgraphs arrive with a `metadata.namespace` field identifying the originating subgraph. Pass event handlers to `useLangGraphRuntime` (or `useLangGraphMessages`) to react to them:
|
|
576
|
-
|
|
577
|
-
```ts
|
|
578
|
-
const runtime = useLangGraphRuntime({
|
|
579
|
-
stream,
|
|
580
|
-
eventHandlers: {
|
|
581
|
-
onSubgraphValues: (namespace, values) => {
|
|
582
|
-
console.log("subgraph", namespace, "state:", values);
|
|
583
|
-
},
|
|
584
|
-
onSubgraphUpdates: (namespace, updates) => {
|
|
585
|
-
console.log("subgraph", namespace, "updates:", updates);
|
|
586
|
-
},
|
|
587
|
-
onSubgraphError: (namespace, error) => {
|
|
588
|
-
console.error("subgraph", namespace, "error:", error);
|
|
589
|
-
},
|
|
590
|
-
},
|
|
591
|
-
});
|
|
592
|
-
```
|
|
593
|
-
|
|
594
|
-
`namespace` is a pipe-separated string like `"parent|child_agent"`. Messages emitted by a subgraph include `metadata.namespace` so you can attribute tool results to the correct sub-agent.
|
|
595
|
-
|
|
596
|
-
## `useLangChainState`
|
|
597
|
-
|
|
598
|
-
When using `@assistant-ui/react-langchain` (`useStreamRuntime`), the `useLangChainState` hook lets you read any key from the current LangChain/LangGraph state on the client without a separate API call:
|
|
599
|
-
|
|
600
|
-
```tsx
|
|
601
|
-
import { useLangChainState } from "@assistant-ui/react-langchain";
|
|
602
|
-
|
|
603
|
-
function TodoSidebar() {
|
|
604
|
-
const todos = useLangChainState<string[]>("todos", []);
|
|
605
|
-
return <ul>{todos.map((t) => <li key={t}>{t}</li>)}</ul>;
|
|
606
|
-
}
|
|
607
|
-
```
|
|
608
|
-
|
|
609
|
-
The second argument is an optional default value. The hook re-renders whenever the state key changes during a stream.
|
|
610
|
-
|
|
611
|
-
## Best Practices
|
|
612
|
-
|
|
613
|
-
1. **Pick one registration style per tool**: avoid registering the same tool through both the `Tools()` toolkit and a component-based API; both routes will register, and duplicates are rejected
|
|
614
|
-
2. **Centralize Definitions**: Keep all tools in a toolkit file for easy management
|
|
615
|
-
3. **Clear Descriptions**: Write descriptive tool descriptions that help the LLM understand when to use each tool
|
|
616
|
-
4. **Parameter Validation**: Use Zod schemas to ensure type safety
|
|
617
|
-
5. **Error Handling**: Handle errors gracefully with user-friendly messages
|
|
618
|
-
6. **Loading States**: Provide visual feedback during tool execution
|
|
619
|
-
7. **Security**: Validate permissions and sanitize inputs
|
|
620
|
-
8. **Performance**: Use abort signals for cancellable operations
|
|
621
|
-
9. **Testing**: Test tools in isolation and with the full assistant flow
|
|
622
|
-
|
|
623
|
-
## Switching from Component-Based to Toolkit
|
|
624
|
-
|
|
625
|
-
If you prefer the toolkit shape, switching is mechanical:
|
|
626
|
-
|
|
627
|
-
1. **Create a toolkit object** with all your tools
|
|
628
|
-
2. **Move tool definitions** from `makeAssistantTool`/`useAssistantTool` calls into the toolkit
|
|
629
|
-
3. **Register once** using `useAui({ tools: Tools({ toolkit }) })` in your runtime provider
|
|
630
|
-
4. **Remove component registrations** (`<WeatherTool />`, etc.)
|
|
631
|
-
5. **Test** to ensure all tools work as expected
|
|
632
|
-
|
|
633
|
-
Example migration:
|
|
634
|
-
|
|
635
|
-
```tsx
|
|
636
|
-
// Component-based API
|
|
637
|
-
const WeatherTool = makeAssistantTool({
|
|
638
|
-
toolName: "getWeather",
|
|
639
|
-
description: "Get weather",
|
|
640
|
-
parameters: z.object({ location: z.string() }),
|
|
641
|
-
execute: async ({ location }) => { /* ... */ },
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
function App() {
|
|
645
|
-
return (
|
|
646
|
-
<AssistantRuntimeProvider runtime={runtime}>
|
|
647
|
-
<WeatherTool />
|
|
648
|
-
<Thread />
|
|
649
|
-
</AssistantRuntimeProvider>
|
|
650
|
-
);
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
// Toolkit API
|
|
654
|
-
const toolkit: Toolkit = {
|
|
655
|
-
getWeather: {
|
|
656
|
-
description: "Get weather",
|
|
657
|
-
parameters: z.object({ location: z.string() }),
|
|
658
|
-
execute: async ({ location }) => { /* ... */ },
|
|
659
|
-
},
|
|
660
|
-
};
|
|
661
|
-
|
|
662
|
-
function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
|
|
663
|
-
const runtime = useChatRuntime();
|
|
664
|
-
|
|
665
|
-
const aui = useAui({
|
|
666
|
-
tools: Tools({ toolkit }),
|
|
667
|
-
});
|
|
668
|
-
|
|
669
|
-
return (
|
|
670
|
-
<AssistantRuntimeProvider aui={aui} runtime={runtime}>
|
|
671
|
-
{children}
|
|
672
|
-
</AssistantRuntimeProvider>
|
|
673
|
-
);
|
|
674
|
-
}
|
|
675
|
-
```
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prepare.d.ts","sourceRoot":"","sources":["../../src/prepare-docs/prepare.ts"],"names":[],"mappings":""}
|
package/dist/stdio.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|