@tambo-ai/react 0.25.0 → 0.26.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 +155 -116
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,75 +1,103 @@
|
|
|
1
|
-
# tambo
|
|
1
|
+
# tambo-ai
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A React package for adding generative React UI components to your AI assistant, copilot, or agent.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
<img src="../assets/tambo-animation.gif" alt="tambo ai Octo Juggling">
|
|
7
|
-
</p>
|
|
5
|
+
## Build with MCP and Generative UI
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
[](https://youtu.be/6zDDPfr7Aoo)
|
|
10
8
|
|
|
11
|
-
tambo
|
|
9
|
+
[Source code](https://github.com/tambo-ai/mcp-template)
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
Create a new project using our MCP template:
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
- AI Orchestration
|
|
19
|
-
- A Compatible React UI Library
|
|
13
|
+
```bash
|
|
14
|
+
npx tambo create-app -t mcp tambo-mcp-app
|
|
15
|
+
```
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
## How does tambo-ai work?
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
[](https://github.com/tambo-ai/tambo/blob/main/LICENSE)
|
|
25
|
-
[](https://github.com/tambo-ai/tambo/commits/main)
|
|
26
|
-
[](https://discord.gg/dJNvPEHth6)
|
|
19
|
+
tambo-ai is a client-side registry of React components that can be used by an LLM.
|
|
27
20
|
|
|
28
|
-
|
|
21
|
+
### 1. Register your components
|
|
29
22
|
|
|
30
|
-
```
|
|
31
|
-
|
|
23
|
+
```tsx
|
|
24
|
+
const components: TamboComponent[] = [
|
|
25
|
+
{
|
|
26
|
+
name: "Graph",
|
|
27
|
+
description:
|
|
28
|
+
"A component that renders various types of charts (bar, line, pie) using Recharts. Supports customizable data visualization with labels, datasets, and styling options.",
|
|
29
|
+
component: Graph,
|
|
30
|
+
propsSchema: graphSchema, // zod schema
|
|
31
|
+
},
|
|
32
|
+
// Add more components
|
|
33
|
+
];
|
|
32
34
|
```
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
### 2. Wrap your app in a TamboProvider
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
```tsx
|
|
39
|
+
// In your chat page
|
|
40
|
+
<TamboProvider
|
|
41
|
+
apiKey={process.env.NEXT_PUBLIC_TAMBO_API_KEY!}
|
|
42
|
+
components={components}
|
|
43
|
+
>
|
|
44
|
+
<MessageThreadFull contextKey="tambo-template" />
|
|
45
|
+
</TamboProvider>
|
|
46
|
+
```
|
|
37
47
|
|
|
38
|
-
|
|
39
|
-
git clone https://github.com/tambo-ai/tambo-template.git && cd tambo-template && npm install && npx tambo init
|
|
48
|
+
### 3. Submit user messages
|
|
40
49
|
|
|
41
|
-
|
|
50
|
+
```tsx
|
|
51
|
+
const { submit } = useTamboThreadInput(contextKey);
|
|
52
|
+
|
|
53
|
+
await submit({
|
|
54
|
+
contextKey,
|
|
55
|
+
streamResponse: true,
|
|
56
|
+
});
|
|
42
57
|
```
|
|
43
58
|
|
|
44
|
-
|
|
59
|
+
### 4. Render AI-generated components
|
|
45
60
|
|
|
46
|
-
```
|
|
47
|
-
|
|
61
|
+
```tsx
|
|
62
|
+
const { message } = useMessageContext();
|
|
63
|
+
|
|
64
|
+
// Render the component
|
|
65
|
+
<div>{message.renderedComponent}</div>;
|
|
48
66
|
```
|
|
49
67
|
|
|
50
|
-
|
|
68
|
+
We provide components that use these hooks for you in our templates and in our component library at [ui.tambo.co](https://ui.tambo.co).
|
|
51
69
|
|
|
52
|
-
|
|
70
|
+
## Getting Started
|
|
53
71
|
|
|
54
|
-
|
|
55
|
-
import { TamboProvider } from "@tambo-ai/react";
|
|
72
|
+
### Quick Start
|
|
56
73
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
74
|
+
Create a new tambo app:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm create tambo-app my-tambo-app
|
|
78
|
+
cd my-tambo-app
|
|
79
|
+
npm run dev
|
|
64
80
|
```
|
|
65
81
|
|
|
66
|
-
|
|
82
|
+
### Templates
|
|
83
|
+
|
|
84
|
+
| App | Description |
|
|
85
|
+
| ---------------------------------------------------------------------- | -------------------------------------- |
|
|
86
|
+
| [MCP](https://github.com/tambo-ai/mcp-template) (new!) | Get started with MCP + Generative UX |
|
|
87
|
+
| [Regular Tools](https://github.com/tambo-ai/tambo-template) | Get started with Generative UX |
|
|
88
|
+
| [Conversational Form](https://github.com/tambo-ai/conversational-form) | Collect information with generative UX |
|
|
89
|
+
|
|
90
|
+
Check out our UI library [tambo-ui](https://ui.tambo.co) for components that leverage tambo.
|
|
91
|
+
|
|
92
|
+
### Basic Usage
|
|
93
|
+
|
|
94
|
+
#### 1. Displaying a message thread:
|
|
67
95
|
|
|
68
96
|
```jsx
|
|
69
97
|
import { useTambo, useTamboThreadInput } from "@tambo-ai/react";
|
|
70
98
|
|
|
71
99
|
function ChatInterface() {
|
|
72
|
-
const { thread
|
|
100
|
+
const { thread } = useTambo();
|
|
73
101
|
const { value, setValue, submit } = useTamboThreadInput();
|
|
74
102
|
|
|
75
103
|
return (
|
|
@@ -105,26 +133,42 @@ function ChatInterface() {
|
|
|
105
133
|
}
|
|
106
134
|
```
|
|
107
135
|
|
|
108
|
-
|
|
136
|
+
#### 2. Adding AI-Generated Components:
|
|
109
137
|
|
|
110
|
-
|
|
138
|
+
Create components that can be dynamically generated by the AI:
|
|
111
139
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
140
|
+
```jsx
|
|
141
|
+
// components/WeatherCard.jsx
|
|
142
|
+
import { useTamboComponentState } from "@tambo-ai/react";
|
|
143
|
+
|
|
144
|
+
export function WeatherCard() {
|
|
145
|
+
const [weatherState, setWeatherState, { isPending }] = useTamboComponentState(
|
|
146
|
+
"weather",
|
|
147
|
+
{
|
|
148
|
+
temperature: 0,
|
|
149
|
+
condition: "",
|
|
150
|
+
location: "",
|
|
151
|
+
},
|
|
152
|
+
);
|
|
118
153
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
154
|
+
if (isPending) {
|
|
155
|
+
return <div>Loading weather data...</div>;
|
|
156
|
+
}
|
|
122
157
|
|
|
123
|
-
|
|
158
|
+
return (
|
|
159
|
+
<div>
|
|
160
|
+
<h3>{weatherState.location}</h3>
|
|
161
|
+
<div>{weatherState.temperature}°C</div>
|
|
162
|
+
<div>{weatherState.condition}</div>
|
|
163
|
+
</div>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
```
|
|
124
167
|
|
|
125
|
-
|
|
168
|
+
#### 3. Register your components:
|
|
126
169
|
|
|
127
170
|
```jsx
|
|
171
|
+
// App.jsx
|
|
128
172
|
import { TamboProvider } from "@tambo-ai/react";
|
|
129
173
|
import { WeatherCard } from "./components/WeatherCard";
|
|
130
174
|
import { z } from "zod";
|
|
@@ -153,79 +197,70 @@ function App() {
|
|
|
153
197
|
}
|
|
154
198
|
```
|
|
155
199
|
|
|
156
|
-
|
|
200
|
+
### Adding Tools for the AI
|
|
157
201
|
|
|
158
|
-
|
|
159
|
-
import { z } from "zod";
|
|
160
|
-
|
|
161
|
-
schema = z.object({
|
|
162
|
-
data: z.object({
|
|
163
|
-
labels: z.array(z.string()).describe("Use single words or short phrases."),
|
|
164
|
-
values: z.array(z.number()).describe("Use whole numbers."),
|
|
165
|
-
}),
|
|
166
|
-
type: z
|
|
167
|
-
.enum(["bar", "line", "pie"])
|
|
168
|
-
.describe(
|
|
169
|
-
"Use a chart type that is appropriate for the data. Only use pie charts when less than 5 values.",
|
|
170
|
-
),
|
|
171
|
-
});
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
## Tool Integration
|
|
175
|
-
|
|
176
|
-
Connect your data sources without writing complex integration code:
|
|
202
|
+
Register tools to make them available to the AI:
|
|
177
203
|
|
|
178
204
|
```jsx
|
|
179
|
-
|
|
180
|
-
import { WeatherCard } from "./components/WeatherCard";
|
|
181
|
-
import { z } from "zod";
|
|
182
|
-
|
|
183
|
-
// Define a tool with Zod schema
|
|
184
|
-
const dataTool = {
|
|
185
|
-
name: "fetchData",
|
|
186
|
-
description: "Fetch data for visualization",
|
|
187
|
-
tool: async ({ dataType }) => {
|
|
188
|
-
/* fetch data */
|
|
189
|
-
},
|
|
190
|
-
toolSchema: z
|
|
191
|
-
.function()
|
|
192
|
-
.args(z.object({ dataType: z.string() }))
|
|
193
|
-
.returns(z.any()),
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
// Define your components with associated tools
|
|
197
|
-
const components = [
|
|
205
|
+
const tools: TamboTool[] = [
|
|
198
206
|
{
|
|
199
|
-
name: "
|
|
200
|
-
description: "
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
207
|
+
name: "getWeather",
|
|
208
|
+
description: "Fetches current weather data for a given location",
|
|
209
|
+
tool: async (location: string, units: string = "celsius") => {
|
|
210
|
+
// Example implementation
|
|
211
|
+
const weather = await fetchWeatherData(location);
|
|
212
|
+
return {
|
|
213
|
+
temperature: weather.temp,
|
|
214
|
+
condition: weather.condition,
|
|
215
|
+
location: weather.city,
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
toolSchema: z
|
|
219
|
+
.function()
|
|
220
|
+
.args(
|
|
221
|
+
z.string().describe("Location name (city)"),
|
|
222
|
+
z
|
|
223
|
+
.string()
|
|
224
|
+
.optional()
|
|
225
|
+
.describe("Temperature units (celsius/fahrenheit)"),
|
|
226
|
+
)
|
|
227
|
+
.returns(
|
|
228
|
+
z.object({
|
|
229
|
+
temperature: z.number(),
|
|
230
|
+
condition: z.string(),
|
|
231
|
+
location: z.string(),
|
|
232
|
+
}),
|
|
233
|
+
),
|
|
208
234
|
},
|
|
209
235
|
];
|
|
210
236
|
|
|
211
|
-
// Pass
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
<YourApp />
|
|
216
|
-
</TamboProvider>
|
|
217
|
-
);
|
|
218
|
-
}
|
|
237
|
+
// Pass tools to the provider
|
|
238
|
+
<TamboProvider apiKey="your-api-key" tools={tools}>
|
|
239
|
+
<YourApp />
|
|
240
|
+
</TamboProvider>;
|
|
219
241
|
```
|
|
220
242
|
|
|
221
|
-
|
|
243
|
+
### Using MCP Servers
|
|
222
244
|
|
|
223
|
-
|
|
224
|
-
|
|
245
|
+
```tsx
|
|
246
|
+
const mcpServers = [
|
|
247
|
+
{
|
|
248
|
+
url: "https://mcp-server-1.com",
|
|
249
|
+
transport: "http",
|
|
250
|
+
name: "mcp-server-1",
|
|
251
|
+
},
|
|
252
|
+
];
|
|
225
253
|
|
|
226
|
-
|
|
254
|
+
// Pass MCP servers to the provider
|
|
255
|
+
<TamboProvider
|
|
256
|
+
apiKey={process.env.NEXT_PUBLIC_TAMBO_API_KEY!}
|
|
257
|
+
components={components}
|
|
258
|
+
>
|
|
259
|
+
<TamboMcpProvider mcpServers={mcpServers}>{children}</TamboMcpProvider>
|
|
260
|
+
</TamboProvider>;
|
|
261
|
+
```
|
|
227
262
|
|
|
228
|
-
|
|
263
|
+
[Read our full documentation](https://tambo.co/docs)
|
|
229
264
|
|
|
230
265
|
## Join the Community
|
|
231
266
|
|
|
@@ -234,3 +269,7 @@ We're building tools for the future of user interfaces. Your contributions matte
|
|
|
234
269
|
**[Star this repo](https://github.com/tambo-ai/tambo)** to support our work.
|
|
235
270
|
|
|
236
271
|
**[Join our Discord](https://discord.gg/dJNvPEHth6)** to connect with other developers.
|
|
272
|
+
|
|
273
|
+
<p align="center">
|
|
274
|
+
<img src="../assets/tambo-animation.gif" alt="tambo ai Octo Juggling">
|
|
275
|
+
</p>
|