@v0-sdk/ai-tools 0.1.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/LICENSE +13 -0
- package/README.md +274 -0
- package/dist/index.cjs +1013 -0
- package/dist/index.d.ts +1944 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1003 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2025 Vercel, Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# @v0-sdk/ai-tools
|
|
2
|
+
|
|
3
|
+
> **⚠️ Developer Preview**: This SDK is currently in beta and is subject to change. Use in production at your own risk.
|
|
4
|
+
|
|
5
|
+
AI SDK tools for the v0 Platform API. This package provides a comprehensive collection of tools that can be used with the AI SDK to interact with v0's API endpoints, enabling AI agents to create, manage, and deploy v0 projects and chats.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- **AI SDK**: ^5.0.0
|
|
10
|
+
- **Zod**: ^3.23.8 (required for AI SDK 5 compatibility)
|
|
11
|
+
- **Node.js**: >=22
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @v0-sdk/ai-tools ai zod@^3.23.8
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { generateText } from 'ai'
|
|
23
|
+
import { openai } from '@ai-sdk/openai'
|
|
24
|
+
import { v0Tools } from '@v0-sdk/ai-tools'
|
|
25
|
+
|
|
26
|
+
const result = await generateText({
|
|
27
|
+
model: openai('gpt-4'),
|
|
28
|
+
prompt: 'Create a new React component for a todo list',
|
|
29
|
+
tools: v0Tools({
|
|
30
|
+
apiKey: process.env.V0_API_KEY,
|
|
31
|
+
}),
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
That's it! `v0Tools()` returns all available tools in a flat structure ready to use with the AI SDK.
|
|
36
|
+
|
|
37
|
+
## Usage Patterns
|
|
38
|
+
|
|
39
|
+
### Organized by Category (Recommended - Better Context Management)
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { v0ToolsByCategory } from '@v0-sdk/ai-tools'
|
|
43
|
+
|
|
44
|
+
const tools = v0ToolsByCategory({ apiKey: process.env.V0_API_KEY })
|
|
45
|
+
|
|
46
|
+
const result = await generateText({
|
|
47
|
+
model: openai('gpt-4'),
|
|
48
|
+
prompt: 'Help me manage my v0 projects',
|
|
49
|
+
tools: {
|
|
50
|
+
// Only include specific categories you need
|
|
51
|
+
...tools.chat,
|
|
52
|
+
...tools.project,
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### All Tools (High Context Usage)
|
|
58
|
+
|
|
59
|
+
⚠️ **Note**: This includes all ~20+ tools which adds significant context to your AI calls.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { v0Tools } from '@v0-sdk/ai-tools'
|
|
63
|
+
|
|
64
|
+
const result = await generateText({
|
|
65
|
+
model: openai('gpt-4'),
|
|
66
|
+
prompt: 'Complete workflow: create project, chat, and deploy',
|
|
67
|
+
tools: v0Tools({ apiKey: process.env.V0_API_KEY }), // All tools available
|
|
68
|
+
})
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Organized by Category (Alternative Pattern)
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { v0ToolsByCategory } from '@v0-sdk/ai-tools'
|
|
75
|
+
|
|
76
|
+
const tools = v0ToolsByCategory({ apiKey: process.env.V0_API_KEY })
|
|
77
|
+
|
|
78
|
+
const result = await generateText({
|
|
79
|
+
model: openai('gpt-4'),
|
|
80
|
+
prompt: 'Help me manage my v0 projects',
|
|
81
|
+
tools: {
|
|
82
|
+
// Only include specific categories
|
|
83
|
+
...tools.chat,
|
|
84
|
+
...tools.project,
|
|
85
|
+
},
|
|
86
|
+
})
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Individual Tool Creators (For Granular Control)
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { createChatTools, createProjectTools } from '@v0-sdk/ai-tools'
|
|
93
|
+
|
|
94
|
+
const chatTools = createChatTools({ apiKey: process.env.V0_API_KEY })
|
|
95
|
+
const projectTools = createProjectTools({ apiKey: process.env.V0_API_KEY })
|
|
96
|
+
|
|
97
|
+
const result = await generateText({
|
|
98
|
+
model: openai('gpt-4'),
|
|
99
|
+
prompt: 'Create a chat in my existing project',
|
|
100
|
+
tools: {
|
|
101
|
+
// Pick specific tools
|
|
102
|
+
createChat: chatTools.createChat,
|
|
103
|
+
sendMessage: chatTools.sendMessage,
|
|
104
|
+
getProject: projectTools.getProject,
|
|
105
|
+
assignChatToProject: projectTools.assignChatToProject,
|
|
106
|
+
},
|
|
107
|
+
})
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Available Tools
|
|
111
|
+
|
|
112
|
+
### Chat Tools (`tools.chat`)
|
|
113
|
+
|
|
114
|
+
| Tool | Description |
|
|
115
|
+
| -------------- | --------------------------------------------- |
|
|
116
|
+
| `createChat` | Create a new chat with v0 |
|
|
117
|
+
| `sendMessage` | Send a message to an existing chat |
|
|
118
|
+
| `getChat` | Get details of an existing chat |
|
|
119
|
+
| `updateChat` | Update chat properties (name, privacy) |
|
|
120
|
+
| `deleteChat` | Delete an existing chat |
|
|
121
|
+
| `favoriteChat` | Toggle favorite status of a chat |
|
|
122
|
+
| `forkChat` | Fork an existing chat to create a new version |
|
|
123
|
+
| `listChats` | List all chats with filtering options |
|
|
124
|
+
|
|
125
|
+
### Project Tools (`tools.project`)
|
|
126
|
+
|
|
127
|
+
| Tool | Description |
|
|
128
|
+
| ---------------------------- | ------------------------------------------ |
|
|
129
|
+
| `createProject` | Create a new project in v0 |
|
|
130
|
+
| `getProject` | Get details of an existing project |
|
|
131
|
+
| `updateProject` | Update project properties |
|
|
132
|
+
| `listProjects` | List all projects |
|
|
133
|
+
| `assignChatToProject` | Assign a chat to a project |
|
|
134
|
+
| `getProjectByChat` | Get project details by chat ID |
|
|
135
|
+
| `createEnvironmentVariables` | Create environment variables for a project |
|
|
136
|
+
| `listEnvironmentVariables` | List environment variables for a project |
|
|
137
|
+
| `updateEnvironmentVariables` | Update environment variables |
|
|
138
|
+
| `deleteEnvironmentVariables` | Delete environment variables |
|
|
139
|
+
|
|
140
|
+
### Deployment Tools (`tools.deployment`)
|
|
141
|
+
|
|
142
|
+
| Tool | Description |
|
|
143
|
+
| --------------------- | ---------------------------------------------- |
|
|
144
|
+
| `createDeployment` | Create a new deployment from a chat version |
|
|
145
|
+
| `getDeployment` | Get details of an existing deployment |
|
|
146
|
+
| `deleteDeployment` | Delete an existing deployment |
|
|
147
|
+
| `listDeployments` | List deployments by project, chat, and version |
|
|
148
|
+
| `getDeploymentLogs` | Get logs for a deployment |
|
|
149
|
+
| `getDeploymentErrors` | Get errors for a deployment |
|
|
150
|
+
|
|
151
|
+
### User Tools (`tools.user`)
|
|
152
|
+
|
|
153
|
+
| Tool | Description |
|
|
154
|
+
| ---------------- | ------------------------------------ |
|
|
155
|
+
| `getCurrentUser` | Get current user information |
|
|
156
|
+
| `getUserBilling` | Get current user billing information |
|
|
157
|
+
| `getUserPlan` | Get current user plan information |
|
|
158
|
+
| `getUserScopes` | Get user scopes/permissions |
|
|
159
|
+
| `getRateLimits` | Get current rate limit information |
|
|
160
|
+
|
|
161
|
+
### Hook Tools (`tools.hook`)
|
|
162
|
+
|
|
163
|
+
| Tool | Description |
|
|
164
|
+
| ------------ | ---------------------------------------- |
|
|
165
|
+
| `createHook` | Create a new webhook for v0 events |
|
|
166
|
+
| `getHook` | Get details of an existing webhook |
|
|
167
|
+
| `updateHook` | Update properties of an existing webhook |
|
|
168
|
+
| `deleteHook` | Delete an existing webhook |
|
|
169
|
+
| `listHooks` | List all webhooks |
|
|
170
|
+
|
|
171
|
+
## Configuration
|
|
172
|
+
|
|
173
|
+
### Environment Variables
|
|
174
|
+
|
|
175
|
+
Set your v0 API key as an environment variable:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
export V0_API_KEY=your_api_key_here
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Direct Configuration
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { v0Tools } from '@v0-sdk/ai-tools'
|
|
185
|
+
|
|
186
|
+
const tools = v0Tools({
|
|
187
|
+
apiKey: 'your_api_key_here',
|
|
188
|
+
baseUrl: 'https://api.v0.dev', // optional, defaults to v0's API
|
|
189
|
+
})
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Examples
|
|
193
|
+
|
|
194
|
+
### Complete Workflow Example
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
import { generateText } from 'ai'
|
|
198
|
+
import { openai } from '@ai-sdk/openai'
|
|
199
|
+
import { v0Tools } from '@v0-sdk/ai-tools'
|
|
200
|
+
|
|
201
|
+
const result = await generateText({
|
|
202
|
+
model: openai('gpt-4'),
|
|
203
|
+
prompt: `Help me with a complete v0 workflow:
|
|
204
|
+
1. Create a new project for an e-commerce site
|
|
205
|
+
2. Create a chat in that project to design a product catalog
|
|
206
|
+
3. Send a message asking for a React component
|
|
207
|
+
4. Deploy the result
|
|
208
|
+
5. Check deployment logs`,
|
|
209
|
+
tools: v0Tools({
|
|
210
|
+
apiKey: process.env.V0_API_KEY,
|
|
211
|
+
}),
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
console.log(result.text)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Project Management Example
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
import { generateText } from 'ai'
|
|
221
|
+
import { openai } from '@ai-sdk/openai'
|
|
222
|
+
import { v0ToolsByCategory } from '@v0-sdk/ai-tools'
|
|
223
|
+
|
|
224
|
+
const tools = v0ToolsByCategory({ apiKey: process.env.V0_API_KEY })
|
|
225
|
+
|
|
226
|
+
const result = await generateText({
|
|
227
|
+
model: openai('gpt-4'),
|
|
228
|
+
prompt:
|
|
229
|
+
'Create a new project called "My Portfolio" with environment variables for API keys',
|
|
230
|
+
tools: {
|
|
231
|
+
// Only include project tools for this specific task
|
|
232
|
+
...tools.project,
|
|
233
|
+
},
|
|
234
|
+
})
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## TypeScript Support
|
|
238
|
+
|
|
239
|
+
The package is written in TypeScript and provides full type safety:
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
import type { V0ToolsConfig } from '@v0-sdk/ai-tools'
|
|
243
|
+
|
|
244
|
+
const config: V0ToolsConfig = {
|
|
245
|
+
apiKey: process.env.V0_API_KEY,
|
|
246
|
+
baseUrl: 'https://api.v0.dev',
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const tools = v0Tools(config)
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Error Handling
|
|
253
|
+
|
|
254
|
+
All tools include proper error handling and will throw descriptive errors if the v0 API returns an error:
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
try {
|
|
258
|
+
const result = await generateText({
|
|
259
|
+
model: openai('gpt-4'),
|
|
260
|
+
prompt: 'Create a chat',
|
|
261
|
+
tools: v0Tools({ apiKey: 'invalid-key' }),
|
|
262
|
+
})
|
|
263
|
+
} catch (error) {
|
|
264
|
+
console.error('Error:', error.message)
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Contributing
|
|
269
|
+
|
|
270
|
+
This package is part of the v0 SDK monorepo. See the main repository for contribution guidelines.
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
Apache 2.0
|