@assistant-ui/mcp-docs-server 0.1.1
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/local-ollama.md +1135 -0
- package/.docs/organized/code-examples/search-agent-for-e-commerce.md +1721 -0
- package/.docs/organized/code-examples/with-ai-sdk.md +1081 -0
- package/.docs/organized/code-examples/with-cloud.md +1164 -0
- package/.docs/organized/code-examples/with-external-store.md +1064 -0
- package/.docs/organized/code-examples/with-ffmpeg.md +1305 -0
- package/.docs/organized/code-examples/with-langgraph.md +1819 -0
- package/.docs/organized/code-examples/with-openai-assistants.md +1175 -0
- package/.docs/organized/code-examples/with-react-hook-form.md +1727 -0
- package/.docs/organized/code-examples/with-vercel-ai-rsc.md +1157 -0
- package/.docs/raw/blog/2024-07-29-hello/index.mdx +65 -0
- package/.docs/raw/blog/2024-09-11/index.mdx +10 -0
- package/.docs/raw/blog/2024-12-15/index.mdx +10 -0
- package/.docs/raw/blog/2025-01-31-changelog/index.mdx +129 -0
- package/.docs/raw/docs/about-assistantui.mdx +44 -0
- package/.docs/raw/docs/api-reference/context-providers/AssistantRuntimeProvider.mdx +30 -0
- package/.docs/raw/docs/api-reference/context-providers/TextContentPartProvider.mdx +26 -0
- package/.docs/raw/docs/api-reference/integrations/react-hook-form.mdx +103 -0
- package/.docs/raw/docs/api-reference/integrations/vercel-ai-sdk.mdx +145 -0
- package/.docs/raw/docs/api-reference/overview.mdx +583 -0
- package/.docs/raw/docs/api-reference/primitives/ActionBar.mdx +264 -0
- package/.docs/raw/docs/api-reference/primitives/AssistantModal.mdx +129 -0
- package/.docs/raw/docs/api-reference/primitives/Attachment.mdx +96 -0
- package/.docs/raw/docs/api-reference/primitives/BranchPicker.mdx +87 -0
- package/.docs/raw/docs/api-reference/primitives/Composer.mdx +204 -0
- package/.docs/raw/docs/api-reference/primitives/ContentPart.mdx +173 -0
- package/.docs/raw/docs/api-reference/primitives/Error.mdx +70 -0
- package/.docs/raw/docs/api-reference/primitives/Message.mdx +181 -0
- package/.docs/raw/docs/api-reference/primitives/Thread.mdx +197 -0
- package/.docs/raw/docs/api-reference/primitives/composition.mdx +21 -0
- package/.docs/raw/docs/api-reference/runtimes/AssistantRuntime.mdx +33 -0
- package/.docs/raw/docs/api-reference/runtimes/AttachmentRuntime.mdx +46 -0
- package/.docs/raw/docs/api-reference/runtimes/ComposerRuntime.mdx +69 -0
- package/.docs/raw/docs/api-reference/runtimes/ContentPartRuntime.mdx +22 -0
- package/.docs/raw/docs/api-reference/runtimes/MessageRuntime.mdx +49 -0
- package/.docs/raw/docs/api-reference/runtimes/ThreadListItemRuntime.mdx +32 -0
- package/.docs/raw/docs/api-reference/runtimes/ThreadListRuntime.mdx +31 -0
- package/.docs/raw/docs/api-reference/runtimes/ThreadRuntime.mdx +48 -0
- package/.docs/raw/docs/architecture.mdx +92 -0
- package/.docs/raw/docs/cloud/authorization.mdx +152 -0
- package/.docs/raw/docs/cloud/overview.mdx +55 -0
- package/.docs/raw/docs/cloud/persistence/ai-sdk.mdx +54 -0
- package/.docs/raw/docs/cloud/persistence/langgraph.mdx +123 -0
- package/.docs/raw/docs/concepts/architecture.mdx +19 -0
- package/.docs/raw/docs/concepts/runtime-layer.mdx +163 -0
- package/.docs/raw/docs/concepts/why.mdx +9 -0
- package/.docs/raw/docs/copilots/make-assistant-readable.mdx +71 -0
- package/.docs/raw/docs/copilots/make-assistant-tool-ui.mdx +76 -0
- package/.docs/raw/docs/copilots/make-assistant-tool.mdx +117 -0
- package/.docs/raw/docs/copilots/model-context.mdx +135 -0
- package/.docs/raw/docs/copilots/motivation.mdx +191 -0
- package/.docs/raw/docs/copilots/use-assistant-instructions.mdx +62 -0
- package/.docs/raw/docs/getting-started.mdx +1133 -0
- package/.docs/raw/docs/guides/Attachments.mdx +640 -0
- package/.docs/raw/docs/guides/Branching.mdx +59 -0
- package/.docs/raw/docs/guides/Editing.mdx +56 -0
- package/.docs/raw/docs/guides/Speech.mdx +43 -0
- package/.docs/raw/docs/guides/ToolUI.mdx +663 -0
- package/.docs/raw/docs/guides/Tools.mdx +496 -0
- package/.docs/raw/docs/index.mdx +7 -0
- package/.docs/raw/docs/legacy/styled/AssistantModal.mdx +85 -0
- package/.docs/raw/docs/legacy/styled/Decomposition.mdx +633 -0
- package/.docs/raw/docs/legacy/styled/Markdown.mdx +86 -0
- package/.docs/raw/docs/legacy/styled/Scrollbar.mdx +71 -0
- package/.docs/raw/docs/legacy/styled/Thread.mdx +84 -0
- package/.docs/raw/docs/legacy/styled/ThreadWidth.mdx +21 -0
- package/.docs/raw/docs/mcp-docs-server.mdx +324 -0
- package/.docs/raw/docs/migrations/deprecation-policy.mdx +41 -0
- package/.docs/raw/docs/migrations/v0-7.mdx +188 -0
- package/.docs/raw/docs/migrations/v0-8.mdx +160 -0
- package/.docs/raw/docs/migrations/v0-9.mdx +75 -0
- package/.docs/raw/docs/react-compatibility.mdx +208 -0
- package/.docs/raw/docs/runtimes/ai-sdk/rsc.mdx +226 -0
- package/.docs/raw/docs/runtimes/ai-sdk/use-assistant-hook.mdx +195 -0
- package/.docs/raw/docs/runtimes/ai-sdk/use-chat-hook.mdx +138 -0
- package/.docs/raw/docs/runtimes/ai-sdk/use-chat.mdx +136 -0
- package/.docs/raw/docs/runtimes/custom/external-store.mdx +1624 -0
- package/.docs/raw/docs/runtimes/custom/local.mdx +1185 -0
- package/.docs/raw/docs/runtimes/helicone.mdx +60 -0
- package/.docs/raw/docs/runtimes/langgraph/index.mdx +320 -0
- package/.docs/raw/docs/runtimes/langgraph/tutorial/index.mdx +11 -0
- package/.docs/raw/docs/runtimes/langgraph/tutorial/introduction.mdx +28 -0
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-1.mdx +120 -0
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +336 -0
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +385 -0
- package/.docs/raw/docs/runtimes/langserve.mdx +126 -0
- package/.docs/raw/docs/runtimes/mastra/full-stack-integration.mdx +218 -0
- package/.docs/raw/docs/runtimes/mastra/overview.mdx +17 -0
- package/.docs/raw/docs/runtimes/mastra/separate-server-integration.mdx +196 -0
- package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +222 -0
- package/.docs/raw/docs/ui/AssistantModal.mdx +46 -0
- package/.docs/raw/docs/ui/AssistantSidebar.mdx +42 -0
- package/.docs/raw/docs/ui/Attachment.mdx +82 -0
- package/.docs/raw/docs/ui/Markdown.mdx +72 -0
- package/.docs/raw/docs/ui/Mermaid.mdx +79 -0
- package/.docs/raw/docs/ui/Scrollbar.mdx +59 -0
- package/.docs/raw/docs/ui/SyntaxHighlighting.mdx +253 -0
- package/.docs/raw/docs/ui/Thread.mdx +47 -0
- package/.docs/raw/docs/ui/ThreadList.mdx +49 -0
- package/.docs/raw/docs/ui/ToolFallback.mdx +64 -0
- package/.docs/raw/docs/ui/primitives/Thread.mdx +197 -0
- package/LICENSE +21 -0
- package/README.md +128 -0
- package/dist/chunk-C7O7EFKU.js +38 -0
- package/dist/chunk-CZCDQ3YH.js +420 -0
- package/dist/index.js +1 -0
- package/dist/prepare-docs/prepare.js +199 -0
- package/dist/stdio.js +8 -0
- package/package.json +43 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: makeAssistantToolUI
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
import { ParametersTable } from "@/components/docs";
|
|
6
|
+
|
|
7
|
+
# `makeAssistantToolUI`
|
|
8
|
+
|
|
9
|
+
The `makeAssistantToolUI` utility is used to register a tool UI component with the Assistant.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { makeAssistantToolUI } from "assistant-ui/react";
|
|
15
|
+
|
|
16
|
+
const MyToolUI = makeAssistantToolUI({
|
|
17
|
+
toolName: "myTool",
|
|
18
|
+
render: ({ args, result, status }) => {
|
|
19
|
+
// render your tool UI here
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## API
|
|
25
|
+
|
|
26
|
+
### `makeAssistantToolUI(tool)`
|
|
27
|
+
|
|
28
|
+
#### Parameters
|
|
29
|
+
|
|
30
|
+
<ParametersTable
|
|
31
|
+
type="AssistantToolUIProps<TArgs, TResult>"
|
|
32
|
+
parameters={[
|
|
33
|
+
{
|
|
34
|
+
name: "toolName",
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "The name of the tool. This must match the name of the tool defined in the assistant.",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "render",
|
|
40
|
+
type: "function",
|
|
41
|
+
description: "A function that renders the tool UI. It receives an object with the following properties: `args` (any): The arguments passed to the tool. `result` (any): The result of the tool execution. `status` (\"requires_action\" | \"in_progress\" | \"complete\" | \"error\"): The status of the tool execution.",
|
|
42
|
+
},
|
|
43
|
+
]}
|
|
44
|
+
/>
|
|
45
|
+
|
|
46
|
+
#### Returns
|
|
47
|
+
|
|
48
|
+
A React functional component that should be included in your component tree. This component doesn't render anything itself, but it registers the tool UI with the Assistant.
|
|
49
|
+
|
|
50
|
+
## Example
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { makeAssistantToolUI } from "assistant-ui/react";
|
|
54
|
+
import { AssistantRuntimeProvider } from "assistant-ui/react";
|
|
55
|
+
|
|
56
|
+
const GetWeatherUI = makeAssistantToolUI({
|
|
57
|
+
toolName: "get_weather",
|
|
58
|
+
render: ({ args, result, status }) => {
|
|
59
|
+
if (status === "requires_action") return <p>Getting weather for {args.location}...</p>;
|
|
60
|
+
if (status === "in_progress") return <p>Loading...</p>;
|
|
61
|
+
if (status === "error") return <p>Error getting weather.</p>;
|
|
62
|
+
if (status === "complete") return <p>The weather is {result.weather}.</p>;
|
|
63
|
+
return null;
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
function App() {
|
|
68
|
+
return (
|
|
69
|
+
<AssistantRuntimeProvider>
|
|
70
|
+
{/* ...your other components */}
|
|
71
|
+
<GetWeatherUI />
|
|
72
|
+
</AssistantRuntimeProvider>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
This example shows how to create a simple UI for a `get_weather` tool. The UI will display different messages depending on the status of the tool execution.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: makeAssistantTool
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
`makeAssistantTool` creates a React component that provides a tool to the assistant. This is useful for defining reusable tools that can be composed into your application.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { makeAssistantTool, tool } from "@assistant-ui/react";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
|
|
13
|
+
// Define the tool using the tool() helper
|
|
14
|
+
const submitForm = tool({
|
|
15
|
+
parameters: z.object({
|
|
16
|
+
email: z.string().email(),
|
|
17
|
+
name: z.string(),
|
|
18
|
+
}),
|
|
19
|
+
execute: async ({ email, name }) => {
|
|
20
|
+
// Implementation
|
|
21
|
+
return { success: true };
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Create a tool component
|
|
26
|
+
const SubmitFormTool = makeAssistantTool(submitForm);
|
|
27
|
+
|
|
28
|
+
// Use in your component
|
|
29
|
+
function Form() {
|
|
30
|
+
return (
|
|
31
|
+
<div>
|
|
32
|
+
<form>{/* form fields */}</form>
|
|
33
|
+
<SubmitFormTool />
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## API Reference
|
|
40
|
+
|
|
41
|
+
### Parameters
|
|
42
|
+
|
|
43
|
+
- `tool`: A tool definition created using the `tool()` helper function
|
|
44
|
+
- `parameters`: Zod schema defining the tool's parameters
|
|
45
|
+
- `execute`: Function that implements the tool's behavior
|
|
46
|
+
|
|
47
|
+
### Returns
|
|
48
|
+
|
|
49
|
+
Returns a React component that:
|
|
50
|
+
|
|
51
|
+
- Provides the tool to the assistant when mounted
|
|
52
|
+
- Automatically removes the tool when unmounted
|
|
53
|
+
- Renders nothing in the DOM (returns null)
|
|
54
|
+
|
|
55
|
+
## Example with Multiple Tools
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import { makeAssistantTool, tool } from "@assistant-ui/react";
|
|
59
|
+
import { z } from "zod";
|
|
60
|
+
|
|
61
|
+
// Define tools
|
|
62
|
+
const validateEmail = tool({
|
|
63
|
+
parameters: z.object({
|
|
64
|
+
email: z.string(),
|
|
65
|
+
}),
|
|
66
|
+
execute: ({ email }) => {
|
|
67
|
+
const isValid = email.includes("@");
|
|
68
|
+
return { isValid, reason: isValid ? "Valid email" : "Missing @" };
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const sendEmail = tool({
|
|
73
|
+
parameters: z.object({
|
|
74
|
+
to: z.string().email(),
|
|
75
|
+
subject: z.string(),
|
|
76
|
+
body: z.string(),
|
|
77
|
+
}),
|
|
78
|
+
execute: async (params) => {
|
|
79
|
+
// Implementation
|
|
80
|
+
return { sent: true };
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Create tool components
|
|
85
|
+
const EmailValidator = makeAssistantTool(validateEmail);
|
|
86
|
+
const EmailSender = makeAssistantTool(sendEmail);
|
|
87
|
+
|
|
88
|
+
// Use together
|
|
89
|
+
function EmailForm() {
|
|
90
|
+
return (
|
|
91
|
+
<div>
|
|
92
|
+
<form>{/* form fields */}</form>
|
|
93
|
+
<EmailValidator />
|
|
94
|
+
<EmailSender />
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Best Practices
|
|
101
|
+
|
|
102
|
+
1. **Parameter Validation**
|
|
103
|
+
|
|
104
|
+
- Always use Zod schemas to define parameters
|
|
105
|
+
- Be specific about parameter types and constraints
|
|
106
|
+
- Add helpful error messages to schema validations
|
|
107
|
+
|
|
108
|
+
2. **Error Handling**
|
|
109
|
+
|
|
110
|
+
- Return meaningful error messages
|
|
111
|
+
- Consider returning partial results when possible
|
|
112
|
+
- Handle async errors appropriately
|
|
113
|
+
|
|
114
|
+
3. **Composition**
|
|
115
|
+
- Break complex tools into smaller, focused ones
|
|
116
|
+
- Consider tool dependencies and interactions
|
|
117
|
+
- Use multiple tools together for complex functionality
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Model Context
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Model Context is the foundation of intelligence in assistant-ui components. It provides configuration and capabilities to the assistant through a context provider system.
|
|
6
|
+
|
|
7
|
+
## Core Concepts
|
|
8
|
+
|
|
9
|
+
### System Instructions
|
|
10
|
+
|
|
11
|
+
System instructions define the base behavior and knowledge available to the assistant. These can be provided in several ways:
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import {
|
|
15
|
+
useAssistantInstructions,
|
|
16
|
+
makeAssistantVisible,
|
|
17
|
+
} from "@assistant-ui/react";
|
|
18
|
+
|
|
19
|
+
// Via useAssistantInstructions
|
|
20
|
+
useAssistantInstructions("You are a helpful assistant...");
|
|
21
|
+
|
|
22
|
+
// Via makeAssistantVisible
|
|
23
|
+
const ReadableComponent = makeAssistantVisible(MyComponent);
|
|
24
|
+
// Automatically provides component HTML as system context
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Tools
|
|
28
|
+
|
|
29
|
+
Tools are functions that the assistant can use to interact with your application. They can be provided through various mechanisms:
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import {
|
|
33
|
+
makeAssistantVisible,
|
|
34
|
+
makeAssistantTool,
|
|
35
|
+
tool,
|
|
36
|
+
useAssistantRuntime,
|
|
37
|
+
} from "@assistant-ui/react";
|
|
38
|
+
import { z } from "zod";
|
|
39
|
+
|
|
40
|
+
// Via makeAssistantVisible's clickable option
|
|
41
|
+
const ClickableButton = makeAssistantVisible(Button, {
|
|
42
|
+
clickable: true, // Provides a click tool
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Via makeAssistantTool
|
|
46
|
+
const submitForm = tool({
|
|
47
|
+
parameters: z.object({
|
|
48
|
+
email: z.string().email(),
|
|
49
|
+
name: z.string(),
|
|
50
|
+
}),
|
|
51
|
+
execute: async ({ email, name }) => {
|
|
52
|
+
// Implementation
|
|
53
|
+
return { success: true };
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const SubmitFormTool = makeAssistantTool(submitForm);
|
|
58
|
+
|
|
59
|
+
// Use in your component
|
|
60
|
+
function Form() {
|
|
61
|
+
return (
|
|
62
|
+
<div>
|
|
63
|
+
<form>{/* form fields */}</form>
|
|
64
|
+
<SubmitFormTool />
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Context Provider System
|
|
71
|
+
|
|
72
|
+
The context provider system allows components to contribute to the model context. Here's a typical usage pattern:
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { useAssistantRuntime, tool } from "@assistant-ui/react";
|
|
76
|
+
import { useEffect } from "react";
|
|
77
|
+
import { z } from "zod";
|
|
78
|
+
|
|
79
|
+
function MyComponent() {
|
|
80
|
+
const assistantRuntime = useAssistantRuntime();
|
|
81
|
+
|
|
82
|
+
// Define tool using the tool() helper
|
|
83
|
+
const myTool = tool({
|
|
84
|
+
parameters: z.object({
|
|
85
|
+
query: z.string(),
|
|
86
|
+
}),
|
|
87
|
+
execute: async ({ query }) => {
|
|
88
|
+
const result = await searchDatabase(query);
|
|
89
|
+
return { result };
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
// Register context provider
|
|
95
|
+
return assistantRuntime.registerModelContextProvider({
|
|
96
|
+
getModelContext: () => ({
|
|
97
|
+
system: "You are a helpful search assistant...",
|
|
98
|
+
tools: { myTool },
|
|
99
|
+
}),
|
|
100
|
+
});
|
|
101
|
+
}, [assistantRuntime]); // Re-register if runtime changes
|
|
102
|
+
|
|
103
|
+
return <div>{/* component content */}</div>;
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Provider Composition
|
|
108
|
+
|
|
109
|
+
Multiple providers can be registered, and their contexts will be composed:
|
|
110
|
+
|
|
111
|
+
- System instructions are concatenated
|
|
112
|
+
- Tool sets are merged
|
|
113
|
+
- Nested readable components only contribute their context at the outermost level
|
|
114
|
+
|
|
115
|
+
## Best Practices
|
|
116
|
+
|
|
117
|
+
1. **System Instructions**
|
|
118
|
+
|
|
119
|
+
- Keep them focused and specific to the component's purpose
|
|
120
|
+
- Use useAssistantInstructions for explicit instructions
|
|
121
|
+
- Let makeAssistantVisible handle component structure
|
|
122
|
+
|
|
123
|
+
2. **Tools**
|
|
124
|
+
|
|
125
|
+
- Use the tool() helper to define tool schemas and behavior
|
|
126
|
+
- Prefer makeAssistantTool for reusable tools
|
|
127
|
+
- Handle errors gracefully
|
|
128
|
+
- Consider async operations and loading states
|
|
129
|
+
- Use the built-in click tool when possible
|
|
130
|
+
|
|
131
|
+
3. **Context Management**
|
|
132
|
+
- Register providers in useEffect for proper cleanup
|
|
133
|
+
- Clean up providers when components unmount
|
|
134
|
+
- Avoid deeply nested readable components
|
|
135
|
+
- Consider performance implications of large HTML structures
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Intelligent Components
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
React revolutionized web development with components that combine logic, structure, and style. Now, with assistant-ui, we're adding a fourth dimension: intelligence. Let's learn how to build smart components through a practical banking app example.
|
|
6
|
+
|
|
7
|
+
## The Evolution of Components
|
|
8
|
+
|
|
9
|
+
Traditional React components combine three elements:
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Traditional React Component
|
|
13
|
+
function TransactionHistory({ transactions }) {
|
|
14
|
+
// 1. Logic (JavaScript/TypeScript)
|
|
15
|
+
const handleRefund = (transactionId) => {
|
|
16
|
+
// Process refund...
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// 2. Structure (JSX/TSX)
|
|
20
|
+
return (
|
|
21
|
+
// 3. Style (CSS via className)
|
|
22
|
+
<div className="transaction-list">
|
|
23
|
+
{transactions.map((transaction) => (
|
|
24
|
+
<div key={transaction.id} className="transaction-item">
|
|
25
|
+
<span>${transaction.amount}</span>
|
|
26
|
+
<span>{transaction.merchant}</span>
|
|
27
|
+
<button onClick={() => handleRefund(transaction.id)}>
|
|
28
|
+
Request Refund
|
|
29
|
+
</button>
|
|
30
|
+
</div>
|
|
31
|
+
))}
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Adding Intelligence
|
|
38
|
+
|
|
39
|
+
With assistant-ui, we can enhance this component with intelligence using four powerful APIs:
|
|
40
|
+
|
|
41
|
+
### 1. Making Components Readable (makeAssistantVisible)
|
|
42
|
+
|
|
43
|
+
First, let's make our buttons "readable" and interactive:
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import { makeAssistantVisible } from "@assistant-ui/react";
|
|
47
|
+
|
|
48
|
+
// Make the refund button intelligent
|
|
49
|
+
const SmartButton = makeAssistantVisible(
|
|
50
|
+
({ onClick, children }) => <button onClick={onClick}>{children}</button>,
|
|
51
|
+
{
|
|
52
|
+
clickable: true, // Allow the assistant to click the button
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
function TransactionHistory({ transactions }) {
|
|
57
|
+
return (
|
|
58
|
+
<div className="transaction-list">
|
|
59
|
+
{transactions.map((transaction) => (
|
|
60
|
+
<div key={transaction.id} className="transaction-item">
|
|
61
|
+
<span>${transaction.amount}</span>
|
|
62
|
+
<span>{transaction.merchant}</span>
|
|
63
|
+
<SmartButton onClick={() => handleRefund(transaction.id)}>
|
|
64
|
+
Request Refund
|
|
65
|
+
</SmartButton>
|
|
66
|
+
</div>
|
|
67
|
+
))}
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Now the assistant can:
|
|
74
|
+
|
|
75
|
+
- Understand the transaction history structure
|
|
76
|
+
- Interact with refund buttons
|
|
77
|
+
- Help users manage their transactions
|
|
78
|
+
|
|
79
|
+
### 2. Adding System Instructions (useAssistantInstructions)
|
|
80
|
+
|
|
81
|
+
Next, let's give the assistant specific instructions about its role:
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
import { useAssistantInstructions } from "@assistant-ui/react";
|
|
85
|
+
|
|
86
|
+
function SmartTransactionHistory() {
|
|
87
|
+
useAssistantInstructions(`
|
|
88
|
+
You are a helpful banking assistant that:
|
|
89
|
+
1. Helps users understand their transactions
|
|
90
|
+
2. Explains refund policies
|
|
91
|
+
3. Identifies suspicious transactions
|
|
92
|
+
4. Guides users through the refund process
|
|
93
|
+
`);
|
|
94
|
+
|
|
95
|
+
return <TransactionHistory transactions={transactions} />;
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 3. Creating Tools (makeAssistantTool)
|
|
100
|
+
|
|
101
|
+
Let's add transaction-specific tools for the assistant:
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
import { makeAssistantTool, tool } from "@assistant-ui/react";
|
|
105
|
+
import { z } from "zod";
|
|
106
|
+
|
|
107
|
+
// Define a tool to analyze transactions
|
|
108
|
+
const analyzeTransaction = tool({
|
|
109
|
+
parameters: z.object({
|
|
110
|
+
transactionId: z.string(),
|
|
111
|
+
merchantName: z.string(),
|
|
112
|
+
}),
|
|
113
|
+
execute: async ({ transactionId, merchantName }) => {
|
|
114
|
+
// Analyze transaction patterns, merchant reputation, etc.
|
|
115
|
+
return {
|
|
116
|
+
isSuspicious: false,
|
|
117
|
+
merchantRating: 4.5,
|
|
118
|
+
similarTransactions: 3,
|
|
119
|
+
refundEligible: true,
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Create a tool component
|
|
125
|
+
const TransactionAnalyzer = makeAssistantTool(analyzeTransaction);
|
|
126
|
+
|
|
127
|
+
function SmartTransactionHistory() {
|
|
128
|
+
// Previous instructions...
|
|
129
|
+
return (
|
|
130
|
+
<>
|
|
131
|
+
<TransactionHistory transactions={transactions} />
|
|
132
|
+
<TransactionAnalyzer />
|
|
133
|
+
</>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### 4. Adding Custom Context (Model Context)
|
|
139
|
+
|
|
140
|
+
Finally, let's add dynamic context based on the user's transaction patterns:
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
import { useAssistantRuntime } from "@assistant-ui/react";
|
|
144
|
+
import { useEffect } from "react";
|
|
145
|
+
|
|
146
|
+
function SmartTransactionHistory({ userProfile }) {
|
|
147
|
+
const assistantRuntime = useAssistantRuntime();
|
|
148
|
+
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
return assistantRuntime.registerModelContextProvider({
|
|
151
|
+
getModelContext: () => ({
|
|
152
|
+
system: `
|
|
153
|
+
User spending patterns:
|
|
154
|
+
- Average transaction: ${userProfile.avgTransaction}
|
|
155
|
+
- Common merchants: ${userProfile.frequentMerchants.join(", ")}
|
|
156
|
+
- Refund history: ${userProfile.refundCount} requests
|
|
157
|
+
`,
|
|
158
|
+
}),
|
|
159
|
+
});
|
|
160
|
+
}, [assistantRuntime, userProfile]);
|
|
161
|
+
|
|
162
|
+
// Previous components...
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## The Result: An Intelligent Banking Experience
|
|
167
|
+
|
|
168
|
+
This enhanced component now provides:
|
|
169
|
+
|
|
170
|
+
- Natural language interaction with transaction history
|
|
171
|
+
- Contextual help for understanding transactions
|
|
172
|
+
- Automated transaction analysis
|
|
173
|
+
- Smart refund assistance
|
|
174
|
+
|
|
175
|
+
The assistant can now:
|
|
176
|
+
|
|
177
|
+
1. Read and understand transaction details
|
|
178
|
+
2. Follow banking-specific guidelines
|
|
179
|
+
3. Use tools to analyze transactions
|
|
180
|
+
4. Access user patterns for personalized help
|
|
181
|
+
|
|
182
|
+
This creates a more intuitive and safer banking experience while maintaining the familiar React component model.
|
|
183
|
+
|
|
184
|
+
## Next Steps
|
|
185
|
+
|
|
186
|
+
Learn more about each API:
|
|
187
|
+
|
|
188
|
+
- [makeAssistantVisible](make-assistant-readable) for component understanding
|
|
189
|
+
- [makeAssistantTool](make-assistant-tool) for transaction analysis
|
|
190
|
+
- [useAssistantInstructions](use-assistant-instructions) for behavior guidance
|
|
191
|
+
- [Model Context](model-context) for dynamic context management
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: useAssistantInstructions
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
`useAssistantInstructions` is a React hook that allows you to set system instructions for your assistant-ui components.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { useAssistantInstructions } from "@assistant-ui/react";
|
|
11
|
+
|
|
12
|
+
function MyComponent() {
|
|
13
|
+
// Simple string usage
|
|
14
|
+
useAssistantInstructions("You are a helpful form assistant...");
|
|
15
|
+
|
|
16
|
+
// With configuration object
|
|
17
|
+
useAssistantInstructions({
|
|
18
|
+
instruction: "You are a helpful form assistant...",
|
|
19
|
+
disabled: false, // Optional: disable the instructions
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return <div>My Component</div>;
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## API Reference
|
|
27
|
+
|
|
28
|
+
### Parameters
|
|
29
|
+
|
|
30
|
+
The hook accepts either:
|
|
31
|
+
|
|
32
|
+
- A string containing the system instructions
|
|
33
|
+
- A configuration object with:
|
|
34
|
+
- `instruction`: The system instructions
|
|
35
|
+
- `disabled`: Optional boolean to disable the instructions
|
|
36
|
+
|
|
37
|
+
### Behavior
|
|
38
|
+
|
|
39
|
+
The hook will:
|
|
40
|
+
|
|
41
|
+
1. Register the provided instructions as system instructions in the model context
|
|
42
|
+
2. Automatically clean up when the component unmounts
|
|
43
|
+
3. Update when the instructions change
|
|
44
|
+
4. Do nothing if disabled is set to true
|
|
45
|
+
|
|
46
|
+
## Example
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
function SmartForm() {
|
|
50
|
+
useAssistantInstructions({
|
|
51
|
+
instruction: `
|
|
52
|
+
You are a form assistant that:
|
|
53
|
+
- Validates user input
|
|
54
|
+
- Provides helpful suggestions
|
|
55
|
+
- Explains any errors
|
|
56
|
+
- Guides users through complex fields
|
|
57
|
+
`,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return <form>{/* Your form fields here */}</form>;
|
|
61
|
+
}
|
|
62
|
+
```
|