v0-sdk 0.0.5 → 0.0.7
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 +269 -93
- package/dist/index.cjs +275 -0
- package/dist/index.d.ts +355 -0
- package/dist/index.js +266 -98
- package/package.json +23 -5
package/README.md
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
# v0 Chat SDK
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A TypeScript SDK for interacting with the v0 API to create and manage AI-powered chat conversations, projects, integrations, and more.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Full TypeScript support with complete type definitions
|
|
8
|
+
- Chat management - Create, manage, and interact with AI chats
|
|
9
|
+
- Project operations - Create and manage v0 projects
|
|
10
|
+
- Vercel integrations - Seamless Vercel project integration
|
|
11
|
+
- User management - Access user information and billing
|
|
12
|
+
- Deployment logs - Monitor and retrieve deployment information
|
|
13
|
+
- Comprehensive testing - Extensive test coverage for all functions
|
|
14
|
+
- Error handling - Robust error handling with detailed error types
|
|
4
15
|
|
|
5
16
|
## Installation
|
|
6
17
|
|
|
7
|
-
```
|
|
18
|
+
```bash
|
|
8
19
|
npm install v0-sdk
|
|
9
20
|
# or
|
|
10
21
|
yarn add v0-sdk
|
|
@@ -14,25 +25,23 @@ pnpm add v0-sdk
|
|
|
14
25
|
|
|
15
26
|
## Quick Start
|
|
16
27
|
|
|
17
|
-
Get your API key from [v0.dev/chat/settings/keys](https://v0.dev/chat/settings/keys)
|
|
18
|
-
|
|
19
|
-
```javascript
|
|
20
|
-
import { V0Client } from 'v0-sdk'
|
|
28
|
+
Get your API key from [v0.dev/chat/settings/keys](https://v0.dev/chat/settings/keys).
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
```typescript
|
|
31
|
+
import { v0 } from 'v0-sdk'
|
|
24
32
|
|
|
25
33
|
// Create a new chat
|
|
26
|
-
const chat = await
|
|
34
|
+
const chat = await v0.chats.create({
|
|
27
35
|
message: 'Create a responsive navbar with Tailwind CSS',
|
|
28
36
|
system: 'You are an expert React developer',
|
|
29
37
|
})
|
|
30
38
|
|
|
31
39
|
console.log(`Chat created: ${chat.url}`)
|
|
32
|
-
console.log(`Generated code: ${chat.files
|
|
40
|
+
console.log(`Generated code: ${chat.files?.length} files`)
|
|
33
41
|
|
|
34
42
|
// Add a message to the chat
|
|
35
|
-
const response = await
|
|
43
|
+
const response = await v0.chats.createMessage({
|
|
44
|
+
chatId: chat.chatId,
|
|
36
45
|
message: 'Add a dropdown menu to the navbar',
|
|
37
46
|
})
|
|
38
47
|
|
|
@@ -43,22 +52,24 @@ console.log(`AI response: ${response.text}`)
|
|
|
43
52
|
|
|
44
53
|
The client requires a v0 API key, which you can create at [v0.dev/chat/settings/keys](https://v0.dev/chat/settings/keys).
|
|
45
54
|
|
|
46
|
-
```
|
|
47
|
-
//
|
|
48
|
-
|
|
55
|
+
```typescript
|
|
56
|
+
// Set your API key as an environment variable
|
|
57
|
+
process.env.V0_API_KEY = 'your_v0_api_key'
|
|
49
58
|
|
|
50
|
-
// Or
|
|
51
|
-
|
|
59
|
+
// Or pass custom base URL
|
|
60
|
+
// The SDK will automatically use the V0_API_KEY environment variable
|
|
52
61
|
```
|
|
53
62
|
|
|
54
63
|
## API Reference
|
|
55
64
|
|
|
56
|
-
###
|
|
65
|
+
### Chat Operations
|
|
66
|
+
|
|
67
|
+
#### Create a Chat
|
|
57
68
|
|
|
58
69
|
Create a new chat conversation with the AI.
|
|
59
70
|
|
|
60
|
-
```
|
|
61
|
-
const result = await
|
|
71
|
+
```typescript
|
|
72
|
+
const result = await v0.chats.create({
|
|
62
73
|
message: 'Create a login form with validation',
|
|
63
74
|
system: 'You are an expert in React and form validation',
|
|
64
75
|
chatPrivacy: 'private',
|
|
@@ -70,95 +81,194 @@ const result = await client.createChat({
|
|
|
70
81
|
})
|
|
71
82
|
```
|
|
72
83
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
```
|
|
76
|
-
{
|
|
77
|
-
|
|
78
|
-
url: 'https://v0.dev/chat/abc123',
|
|
79
|
-
text: 'I'll create a login form with validation...',
|
|
80
|
-
files: [
|
|
81
|
-
{
|
|
82
|
-
name: 'login-form.tsx',
|
|
83
|
-
content: '...',
|
|
84
|
-
type: 'component'
|
|
85
|
-
}
|
|
86
|
-
],
|
|
87
|
-
demo: 'https://v0.dev/demo/abc123'
|
|
88
|
-
}
|
|
84
|
+
#### Get Chat by ID
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const chat = await v0.chats.getById({ chatId: 'chat_id' })
|
|
88
|
+
console.log(chat.messages) // Fully typed message array
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
#### Manage Chat Favorites
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
// Favorite a chat
|
|
95
|
+
await v0.chats.favorite({ chatId: 'chat_id' })
|
|
96
|
+
|
|
97
|
+
// Unfavorite a chat
|
|
98
|
+
await v0.chats.unfavorite({ chatId: 'chat_id' })
|
|
99
|
+
|
|
100
|
+
// Get favorite chats
|
|
101
|
+
const favorites = await v0.chats.find()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### Chat History and Management
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
// Get chat history
|
|
108
|
+
const chats = await v0.chats.find()
|
|
92
109
|
|
|
93
|
-
|
|
110
|
+
// Delete a chat
|
|
111
|
+
await v0.chats.delete({ chatId: 'chat_id' })
|
|
94
112
|
|
|
95
|
-
|
|
96
|
-
const
|
|
113
|
+
// Get chat's associated project
|
|
114
|
+
const project = await v0.chats.getProject({ chatId: 'chat_id' })
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### Add Messages to Chat
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
const response = await v0.chats.createMessage({
|
|
121
|
+
chatId: 'chat_id',
|
|
97
122
|
message: 'Add password strength indicator',
|
|
98
123
|
attachments: [{ url: 'https://example.com/mockup.jpg' }],
|
|
99
|
-
modelConfiguration: {
|
|
124
|
+
modelConfiguration: {
|
|
125
|
+
imageGenerations: true,
|
|
126
|
+
},
|
|
127
|
+
})
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
#### Get Version Frame Token
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
const token = await v0.chats.getVersionFrameToken({
|
|
134
|
+
chatId: 'chat_id',
|
|
135
|
+
versionId: 'version_id',
|
|
136
|
+
})
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Project Operations
|
|
140
|
+
|
|
141
|
+
#### Create a Project
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
const project = await v0.projects.create({
|
|
145
|
+
name: 'My New Project',
|
|
146
|
+
description: 'A sample project',
|
|
147
|
+
environmentVariables: [{ key: 'API_KEY', value: 'secret_value' }],
|
|
148
|
+
icon: 'https://example.com/icon.png',
|
|
149
|
+
})
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### Find Projects
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
const projects = await v0.projects.find()
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Vercel Integration
|
|
159
|
+
|
|
160
|
+
#### Create Vercel Integration Project
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
const integration = await v0.integrations.vercel.projects.create({
|
|
164
|
+
projectId: 'vercel_project_id',
|
|
165
|
+
name: 'project_name',
|
|
166
|
+
})
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### Find Vercel Projects
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
const projects = await v0.integrations.vercel.projects.find()
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### User Management
|
|
176
|
+
|
|
177
|
+
#### Get User Information
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
const userResponse = await v0.user.get()
|
|
181
|
+
console.log(userResponse.user.name, userResponse.user.email)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### Get User Plan and Billing
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
const planResponse = await v0.user.getPlan()
|
|
188
|
+
console.log(planResponse.plan, planResponse.balance)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Deployment and Monitoring
|
|
192
|
+
|
|
193
|
+
#### Find Deployment Logs
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
const logs = await v0.deployments.findLogs({
|
|
197
|
+
deploymentId: 'deployment_id',
|
|
100
198
|
})
|
|
101
199
|
```
|
|
102
200
|
|
|
103
|
-
###
|
|
201
|
+
### Scopes and Rate Limits
|
|
202
|
+
|
|
203
|
+
#### Find Scopes
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
const scopesResponse = await v0.scopes.find()
|
|
207
|
+
console.log(scopesResponse.scopes)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### Check Rate Limits
|
|
104
211
|
|
|
105
|
-
|
|
212
|
+
```typescript
|
|
213
|
+
const rateLimits = await v0.rateLimits.find()
|
|
214
|
+
console.log(rateLimits.remaining, rateLimits.reset)
|
|
215
|
+
```
|
|
106
216
|
|
|
107
217
|
## Working with Attachments
|
|
108
218
|
|
|
109
|
-
The
|
|
219
|
+
The SDK supports URL and base64-encoded attachments:
|
|
110
220
|
|
|
111
|
-
```
|
|
221
|
+
```typescript
|
|
112
222
|
// URL attachment
|
|
113
|
-
const response = await
|
|
223
|
+
const response = await v0.chats.create({
|
|
114
224
|
message: 'Create a component based on this design',
|
|
115
225
|
attachments: [{ url: 'https://example.com/design.png' }],
|
|
116
226
|
})
|
|
117
227
|
|
|
118
|
-
// Base64 attachment
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
.addEventListener('change', async e => {
|
|
122
|
-
const file = e.target.files[0]
|
|
123
|
-
const reader = new FileReader()
|
|
228
|
+
// Base64 attachment
|
|
229
|
+
const handleFileUpload = async (file: File) => {
|
|
230
|
+
const reader = new FileReader()
|
|
124
231
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
232
|
+
reader.onload = async () => {
|
|
233
|
+
const response = await v0.chats.create({
|
|
234
|
+
message: 'Create a component based on this image',
|
|
235
|
+
attachments: [{ url: reader.result as string }],
|
|
236
|
+
})
|
|
130
237
|
|
|
131
|
-
|
|
132
|
-
|
|
238
|
+
console.log(response)
|
|
239
|
+
}
|
|
133
240
|
|
|
134
|
-
|
|
135
|
-
|
|
241
|
+
reader.readAsDataURL(file)
|
|
242
|
+
}
|
|
136
243
|
```
|
|
137
244
|
|
|
138
|
-
##
|
|
245
|
+
## TypeScript Support
|
|
139
246
|
|
|
140
|
-
|
|
247
|
+
The SDK includes complete type definitions for all API operations:
|
|
141
248
|
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
249
|
+
```typescript
|
|
250
|
+
import type {
|
|
251
|
+
ChatsCreateRequest,
|
|
252
|
+
ChatsCreateResponse,
|
|
253
|
+
User,
|
|
254
|
+
Project,
|
|
255
|
+
ScopeSummary,
|
|
256
|
+
} from 'v0-sdk'
|
|
148
257
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
258
|
+
// All request and response types are fully typed
|
|
259
|
+
const createChatRequest: ChatsCreateRequest = {
|
|
260
|
+
message: 'Create a component',
|
|
261
|
+
system: 'You are a helpful assistant',
|
|
262
|
+
}
|
|
153
263
|
```
|
|
154
264
|
|
|
155
265
|
## Error Handling
|
|
156
266
|
|
|
157
|
-
The
|
|
267
|
+
The SDK provides detailed error information:
|
|
158
268
|
|
|
159
|
-
```
|
|
269
|
+
```typescript
|
|
160
270
|
try {
|
|
161
|
-
const chat = await
|
|
271
|
+
const chat = await v0.chats.create({
|
|
162
272
|
message: 'Create a component',
|
|
163
273
|
})
|
|
164
274
|
} catch (error) {
|
|
@@ -172,18 +282,86 @@ try {
|
|
|
172
282
|
}
|
|
173
283
|
```
|
|
174
284
|
|
|
285
|
+
## Testing
|
|
286
|
+
|
|
287
|
+
The SDK includes comprehensive test coverage. Run tests with:
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
npm test
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Test Structure
|
|
294
|
+
|
|
295
|
+
Tests are organized by functionality:
|
|
296
|
+
|
|
297
|
+
```
|
|
298
|
+
tests/
|
|
299
|
+
├── chats/
|
|
300
|
+
│ ├── create.test.ts
|
|
301
|
+
│ ├── find.test.ts
|
|
302
|
+
│ ├── delete.test.ts
|
|
303
|
+
│ ├── getById.test.ts
|
|
304
|
+
│ ├── favorite.test.ts
|
|
305
|
+
│ ├── unfavorite.test.ts
|
|
306
|
+
│ ├── getProject.test.ts
|
|
307
|
+
│ ├── createMessage.test.ts
|
|
308
|
+
│ └── getVersionFrameToken.test.ts
|
|
309
|
+
├── projects/
|
|
310
|
+
│ ├── create.test.ts
|
|
311
|
+
│ └── find.test.ts
|
|
312
|
+
├── integrations/vercel/projects/
|
|
313
|
+
│ ├── create.test.ts
|
|
314
|
+
│ └── find.test.ts
|
|
315
|
+
├── user/
|
|
316
|
+
│ ├── get.test.ts
|
|
317
|
+
│ └── getPlan.test.ts
|
|
318
|
+
├── deployments/
|
|
319
|
+
│ └── findLogs.test.ts
|
|
320
|
+
├── scopes/
|
|
321
|
+
│ └── find.test.ts
|
|
322
|
+
└── rateLimits/
|
|
323
|
+
└── find.test.ts
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## Development
|
|
327
|
+
|
|
328
|
+
### Building
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
npm run build
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Generating SDK
|
|
335
|
+
|
|
336
|
+
The SDK is generated from the OpenAPI specification:
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
npm run generate
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Running Tests
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
npm test
|
|
346
|
+
```
|
|
347
|
+
|
|
175
348
|
## Advanced Usage
|
|
176
349
|
|
|
177
|
-
###
|
|
350
|
+
### Custom Configuration
|
|
178
351
|
|
|
179
|
-
|
|
352
|
+
```typescript
|
|
353
|
+
const client = new V0Client('your_api_key', 'https://custom-api.example.com', {
|
|
354
|
+
timeout: 30000,
|
|
355
|
+
retries: 3,
|
|
356
|
+
})
|
|
357
|
+
```
|
|
180
358
|
|
|
181
359
|
### Team Collaboration
|
|
182
360
|
|
|
183
361
|
Share chats with your team:
|
|
184
362
|
|
|
185
|
-
```
|
|
186
|
-
const chat = await
|
|
363
|
+
```typescript
|
|
364
|
+
const chat = await v0.chats.create({
|
|
187
365
|
message: 'Create a component for our design system',
|
|
188
366
|
chatPrivacy: 'team-edit',
|
|
189
367
|
teamId: 'your-team-id',
|
|
@@ -197,22 +375,20 @@ console.log(`Team chat URL: ${chat.url}`)
|
|
|
197
375
|
|
|
198
376
|
### Rate Limiting
|
|
199
377
|
|
|
200
|
-
The API has rate limits
|
|
378
|
+
The API has rate limits. Check your current limits:
|
|
201
379
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
- **404 Not Found**: Ensure the chat ID exists and is accessible to your API key.
|
|
207
|
-
- **413 Payload Too Large**: Reduce attachment size (max 10MB per attachment).
|
|
208
|
-
|
|
209
|
-
### Debugging
|
|
380
|
+
```typescript
|
|
381
|
+
const limits = await v0.rateLimits.find()
|
|
382
|
+
console.log(`Remaining requests: ${limits.remaining}`)
|
|
383
|
+
```
|
|
210
384
|
|
|
211
|
-
|
|
385
|
+
### Common Errors
|
|
212
386
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
387
|
+
- **403 Forbidden**: Check your API key and ensure you have a valid subscription
|
|
388
|
+
- **400 Bad Request**: Verify your request parameters match the API requirements
|
|
389
|
+
- **404 Not Found**: Ensure the resource ID exists and is accessible to your API key
|
|
390
|
+
- **413 Payload Too Large**: Reduce attachment size (max 10MB per attachment)
|
|
391
|
+
- **429 Too Many Requests**: You've hit the rate limit, wait before making more requests
|
|
216
392
|
|
|
217
393
|
## Resources
|
|
218
394
|
|