@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/dist/index.js
ADDED
|
@@ -0,0 +1,1003 @@
|
|
|
1
|
+
import { tool } from 'ai';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { createClient } from '@v0/sdk';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates chat-related AI SDK tools
|
|
7
|
+
*/ function createChatTools(config = {}) {
|
|
8
|
+
const client = createClient(config);
|
|
9
|
+
const createChat = tool({
|
|
10
|
+
description: 'Create a new chat with v0',
|
|
11
|
+
inputSchema: z.object({
|
|
12
|
+
message: z.string().describe('The initial message to start the chat'),
|
|
13
|
+
system: z.string().optional().describe('System prompt for the chat'),
|
|
14
|
+
attachments: z.array(z.object({
|
|
15
|
+
url: z.string().describe('URL of the attachment')
|
|
16
|
+
})).optional().describe('File attachments for the chat'),
|
|
17
|
+
chatPrivacy: z.enum([
|
|
18
|
+
'public',
|
|
19
|
+
'private',
|
|
20
|
+
'team-edit',
|
|
21
|
+
'team',
|
|
22
|
+
'unlisted'
|
|
23
|
+
]).optional().describe('Privacy setting for the chat'),
|
|
24
|
+
projectId: z.string().optional().describe('Project ID to associate with the chat'),
|
|
25
|
+
modelConfiguration: z.object({
|
|
26
|
+
modelId: z.enum([
|
|
27
|
+
'v0-1.5-sm',
|
|
28
|
+
'v0-1.5-md',
|
|
29
|
+
'v0-1.5-lg',
|
|
30
|
+
'v0-gpt-5'
|
|
31
|
+
]).describe('Model to use for the chat'),
|
|
32
|
+
imageGenerations: z.boolean().optional().describe('Enable image generations'),
|
|
33
|
+
thinking: z.boolean().optional().describe('Enable thinking mode')
|
|
34
|
+
}).optional().describe('Model configuration for the chat'),
|
|
35
|
+
responseMode: z.enum([
|
|
36
|
+
'sync',
|
|
37
|
+
'async'
|
|
38
|
+
]).optional().describe('Response mode for the chat')
|
|
39
|
+
}),
|
|
40
|
+
execute: async ({ message, system, attachments, chatPrivacy, projectId, modelConfiguration, responseMode })=>{
|
|
41
|
+
const result = await client.chats.create({
|
|
42
|
+
message,
|
|
43
|
+
system,
|
|
44
|
+
attachments,
|
|
45
|
+
chatPrivacy,
|
|
46
|
+
projectId,
|
|
47
|
+
modelConfiguration,
|
|
48
|
+
responseMode
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
chatId: result.id,
|
|
52
|
+
webUrl: result.webUrl,
|
|
53
|
+
apiUrl: result.apiUrl,
|
|
54
|
+
privacy: result.privacy,
|
|
55
|
+
name: result.name,
|
|
56
|
+
favorite: result.favorite,
|
|
57
|
+
latestVersion: result.latestVersion,
|
|
58
|
+
createdAt: result.createdAt
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const sendMessage = tool({
|
|
63
|
+
description: 'Send a message to an existing chat',
|
|
64
|
+
inputSchema: z.object({
|
|
65
|
+
chatId: z.string().describe('ID of the chat to send message to'),
|
|
66
|
+
message: z.string().describe('Message content to send'),
|
|
67
|
+
attachments: z.array(z.object({
|
|
68
|
+
url: z.string().describe('URL of the attachment')
|
|
69
|
+
})).optional().describe('File attachments for the message'),
|
|
70
|
+
modelConfiguration: z.object({
|
|
71
|
+
modelId: z.enum([
|
|
72
|
+
'v0-1.5-sm',
|
|
73
|
+
'v0-1.5-md',
|
|
74
|
+
'v0-1.5-lg',
|
|
75
|
+
'v0-gpt-5'
|
|
76
|
+
]).describe('Model to use'),
|
|
77
|
+
imageGenerations: z.boolean().optional().describe('Enable image generations'),
|
|
78
|
+
thinking: z.boolean().optional().describe('Enable thinking mode')
|
|
79
|
+
}).optional().describe('Model configuration'),
|
|
80
|
+
responseMode: z.enum([
|
|
81
|
+
'sync',
|
|
82
|
+
'async'
|
|
83
|
+
]).optional().describe('Response mode')
|
|
84
|
+
}),
|
|
85
|
+
execute: async ({ chatId, message, attachments, modelConfiguration, responseMode })=>{
|
|
86
|
+
const result = await client.chats.sendMessage({
|
|
87
|
+
chatId,
|
|
88
|
+
message,
|
|
89
|
+
attachments,
|
|
90
|
+
modelConfiguration,
|
|
91
|
+
responseMode
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
chatId: result.id,
|
|
95
|
+
webUrl: result.webUrl,
|
|
96
|
+
latestVersion: result.latestVersion,
|
|
97
|
+
updatedAt: result.updatedAt
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
const getChat = tool({
|
|
102
|
+
description: 'Get details of an existing chat',
|
|
103
|
+
inputSchema: z.object({
|
|
104
|
+
chatId: z.string().describe('ID of the chat to retrieve')
|
|
105
|
+
}),
|
|
106
|
+
execute: async (params)=>{
|
|
107
|
+
const { chatId } = params;
|
|
108
|
+
const result = await client.chats.getById({
|
|
109
|
+
chatId
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
chatId: result.id,
|
|
113
|
+
name: result.name,
|
|
114
|
+
privacy: result.privacy,
|
|
115
|
+
webUrl: result.webUrl,
|
|
116
|
+
favorite: result.favorite,
|
|
117
|
+
createdAt: result.createdAt,
|
|
118
|
+
updatedAt: result.updatedAt,
|
|
119
|
+
latestVersion: result.latestVersion,
|
|
120
|
+
messagesCount: result.messages.length
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
const updateChat = tool({
|
|
125
|
+
description: 'Update properties of an existing chat',
|
|
126
|
+
inputSchema: z.object({
|
|
127
|
+
chatId: z.string().describe('ID of the chat to update'),
|
|
128
|
+
name: z.string().optional().describe('New name for the chat'),
|
|
129
|
+
privacy: z.enum([
|
|
130
|
+
'public',
|
|
131
|
+
'private',
|
|
132
|
+
'team',
|
|
133
|
+
'team-edit',
|
|
134
|
+
'unlisted'
|
|
135
|
+
]).optional().describe('New privacy setting')
|
|
136
|
+
}),
|
|
137
|
+
execute: async (params)=>{
|
|
138
|
+
const { chatId, name, privacy } = params;
|
|
139
|
+
const result = await client.chats.update({
|
|
140
|
+
chatId,
|
|
141
|
+
name,
|
|
142
|
+
privacy
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
chatId: result.id,
|
|
146
|
+
name: result.name,
|
|
147
|
+
privacy: result.privacy,
|
|
148
|
+
updatedAt: result.updatedAt
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
const deleteChat = tool({
|
|
153
|
+
description: 'Delete an existing chat',
|
|
154
|
+
inputSchema: z.object({
|
|
155
|
+
chatId: z.string().describe('ID of the chat to delete')
|
|
156
|
+
}),
|
|
157
|
+
execute: async (params)=>{
|
|
158
|
+
const { chatId } = params;
|
|
159
|
+
const result = await client.chats.delete({
|
|
160
|
+
chatId
|
|
161
|
+
});
|
|
162
|
+
return {
|
|
163
|
+
chatId: result.id,
|
|
164
|
+
deleted: result.deleted
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
const favoriteChat = tool({
|
|
169
|
+
description: 'Toggle favorite status of a chat',
|
|
170
|
+
inputSchema: z.object({
|
|
171
|
+
chatId: z.string().describe('ID of the chat'),
|
|
172
|
+
isFavorite: z.boolean().describe('Whether to mark as favorite or not')
|
|
173
|
+
}),
|
|
174
|
+
execute: async (params)=>{
|
|
175
|
+
const { chatId, isFavorite } = params;
|
|
176
|
+
const result = await client.chats.favorite({
|
|
177
|
+
chatId,
|
|
178
|
+
isFavorite
|
|
179
|
+
});
|
|
180
|
+
return {
|
|
181
|
+
chatId: result.id,
|
|
182
|
+
favorited: result.favorited
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
const forkChat = tool({
|
|
187
|
+
description: 'Fork an existing chat to create a new version',
|
|
188
|
+
inputSchema: z.object({
|
|
189
|
+
chatId: z.string().describe('ID of the chat to fork'),
|
|
190
|
+
versionId: z.string().optional().describe('Specific version ID to fork from'),
|
|
191
|
+
privacy: z.enum([
|
|
192
|
+
'public',
|
|
193
|
+
'private',
|
|
194
|
+
'team',
|
|
195
|
+
'team-edit',
|
|
196
|
+
'unlisted'
|
|
197
|
+
]).optional().describe('Privacy setting for the forked chat')
|
|
198
|
+
}),
|
|
199
|
+
execute: async (params)=>{
|
|
200
|
+
const { chatId, versionId, privacy } = params;
|
|
201
|
+
const result = await client.chats.fork({
|
|
202
|
+
chatId,
|
|
203
|
+
versionId,
|
|
204
|
+
privacy
|
|
205
|
+
});
|
|
206
|
+
return {
|
|
207
|
+
originalChatId: chatId,
|
|
208
|
+
newChatId: result.id,
|
|
209
|
+
webUrl: result.webUrl,
|
|
210
|
+
privacy: result.privacy,
|
|
211
|
+
createdAt: result.createdAt
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
const listChats = tool({
|
|
216
|
+
description: 'List all chats',
|
|
217
|
+
inputSchema: z.object({
|
|
218
|
+
limit: z.string().optional().describe('Number of chats to return'),
|
|
219
|
+
offset: z.string().optional().describe('Offset for pagination'),
|
|
220
|
+
isFavorite: z.string().optional().describe('Filter by favorite status')
|
|
221
|
+
}),
|
|
222
|
+
execute: async (params)=>{
|
|
223
|
+
const { limit, offset, isFavorite } = params;
|
|
224
|
+
const result = await client.chats.find({
|
|
225
|
+
limit,
|
|
226
|
+
offset,
|
|
227
|
+
isFavorite
|
|
228
|
+
});
|
|
229
|
+
return {
|
|
230
|
+
chats: result.data.map((chat)=>({
|
|
231
|
+
chatId: chat.id,
|
|
232
|
+
name: chat.name,
|
|
233
|
+
privacy: chat.privacy,
|
|
234
|
+
webUrl: chat.webUrl,
|
|
235
|
+
favorite: chat.favorite,
|
|
236
|
+
createdAt: chat.createdAt,
|
|
237
|
+
updatedAt: chat.updatedAt
|
|
238
|
+
}))
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
return {
|
|
243
|
+
createChat,
|
|
244
|
+
sendMessage,
|
|
245
|
+
getChat,
|
|
246
|
+
updateChat,
|
|
247
|
+
deleteChat,
|
|
248
|
+
favoriteChat,
|
|
249
|
+
forkChat,
|
|
250
|
+
listChats
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Creates project-related AI SDK tools
|
|
256
|
+
*/ function createProjectTools(config = {}) {
|
|
257
|
+
const client = createClient(config);
|
|
258
|
+
const createProject = tool({
|
|
259
|
+
description: 'Create a new project in v0',
|
|
260
|
+
inputSchema: z.object({
|
|
261
|
+
name: z.string().describe('Name of the project'),
|
|
262
|
+
description: z.string().optional().describe('Description of the project'),
|
|
263
|
+
icon: z.string().optional().describe('Icon for the project'),
|
|
264
|
+
environmentVariables: z.array(z.object({
|
|
265
|
+
key: z.string().describe('Environment variable key'),
|
|
266
|
+
value: z.string().describe('Environment variable value')
|
|
267
|
+
})).optional().describe('Environment variables for the project'),
|
|
268
|
+
instructions: z.string().optional().describe('Custom instructions for the project'),
|
|
269
|
+
vercelProjectId: z.string().optional().describe('Associated Vercel project ID'),
|
|
270
|
+
privacy: z.enum([
|
|
271
|
+
'private',
|
|
272
|
+
'team'
|
|
273
|
+
]).optional().describe('Privacy setting for the project')
|
|
274
|
+
}),
|
|
275
|
+
execute: async ({ name, description, icon, environmentVariables, instructions, vercelProjectId, privacy })=>{
|
|
276
|
+
const result = await client.projects.create({
|
|
277
|
+
name,
|
|
278
|
+
description,
|
|
279
|
+
icon,
|
|
280
|
+
environmentVariables,
|
|
281
|
+
instructions,
|
|
282
|
+
vercelProjectId,
|
|
283
|
+
privacy
|
|
284
|
+
});
|
|
285
|
+
return {
|
|
286
|
+
projectId: result.id,
|
|
287
|
+
name: result.name,
|
|
288
|
+
description: result.description,
|
|
289
|
+
privacy: result.privacy,
|
|
290
|
+
webUrl: result.webUrl,
|
|
291
|
+
apiUrl: result.apiUrl,
|
|
292
|
+
createdAt: result.createdAt,
|
|
293
|
+
vercelProjectId: result.vercelProjectId
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
const getProject = tool({
|
|
298
|
+
description: 'Get details of an existing project',
|
|
299
|
+
inputSchema: z.object({
|
|
300
|
+
projectId: z.string().describe('ID of the project to retrieve')
|
|
301
|
+
}),
|
|
302
|
+
execute: async (params)=>{
|
|
303
|
+
const { projectId } = params;
|
|
304
|
+
const result = await client.projects.getById({
|
|
305
|
+
projectId
|
|
306
|
+
});
|
|
307
|
+
return {
|
|
308
|
+
projectId: result.id,
|
|
309
|
+
name: result.name,
|
|
310
|
+
description: result.description,
|
|
311
|
+
instructions: result.instructions,
|
|
312
|
+
privacy: result.privacy,
|
|
313
|
+
webUrl: result.webUrl,
|
|
314
|
+
apiUrl: result.apiUrl,
|
|
315
|
+
createdAt: result.createdAt,
|
|
316
|
+
updatedAt: result.updatedAt,
|
|
317
|
+
vercelProjectId: result.vercelProjectId,
|
|
318
|
+
chatsCount: result.chats.length
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
const updateProject = tool({
|
|
323
|
+
description: 'Update properties of an existing project',
|
|
324
|
+
inputSchema: z.object({
|
|
325
|
+
projectId: z.string().describe('ID of the project to update'),
|
|
326
|
+
name: z.string().optional().describe('New name for the project'),
|
|
327
|
+
description: z.string().optional().describe('New description for the project'),
|
|
328
|
+
instructions: z.string().optional().describe('New instructions for the project'),
|
|
329
|
+
privacy: z.enum([
|
|
330
|
+
'private',
|
|
331
|
+
'team'
|
|
332
|
+
]).optional().describe('New privacy setting')
|
|
333
|
+
}),
|
|
334
|
+
execute: async ({ projectId, name, description, instructions, privacy })=>{
|
|
335
|
+
const result = await client.projects.update({
|
|
336
|
+
projectId,
|
|
337
|
+
name,
|
|
338
|
+
description,
|
|
339
|
+
instructions,
|
|
340
|
+
privacy
|
|
341
|
+
});
|
|
342
|
+
return {
|
|
343
|
+
projectId: result.id,
|
|
344
|
+
name: result.name,
|
|
345
|
+
description: result.description,
|
|
346
|
+
instructions: result.instructions,
|
|
347
|
+
privacy: result.privacy,
|
|
348
|
+
updatedAt: result.updatedAt
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
const listProjects = tool({
|
|
353
|
+
description: 'List all projects',
|
|
354
|
+
inputSchema: z.object({}),
|
|
355
|
+
execute: async ()=>{
|
|
356
|
+
const result = await client.projects.find();
|
|
357
|
+
return {
|
|
358
|
+
projects: result.data.map((project)=>({
|
|
359
|
+
projectId: project.id,
|
|
360
|
+
name: project.name,
|
|
361
|
+
privacy: project.privacy,
|
|
362
|
+
webUrl: project.webUrl,
|
|
363
|
+
createdAt: project.createdAt,
|
|
364
|
+
updatedAt: project.updatedAt,
|
|
365
|
+
vercelProjectId: project.vercelProjectId
|
|
366
|
+
}))
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
const assignChatToProject = tool({
|
|
371
|
+
description: 'Assign a chat to a project',
|
|
372
|
+
inputSchema: z.object({
|
|
373
|
+
projectId: z.string().describe('ID of the project'),
|
|
374
|
+
chatId: z.string().describe('ID of the chat to assign')
|
|
375
|
+
}),
|
|
376
|
+
execute: async (params)=>{
|
|
377
|
+
const { projectId, chatId } = params;
|
|
378
|
+
const result = await client.projects.assign({
|
|
379
|
+
projectId,
|
|
380
|
+
chatId
|
|
381
|
+
});
|
|
382
|
+
return {
|
|
383
|
+
projectId: result.id,
|
|
384
|
+
assigned: result.assigned
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
const getProjectByChat = tool({
|
|
389
|
+
description: 'Get project details by chat ID',
|
|
390
|
+
inputSchema: z.object({
|
|
391
|
+
chatId: z.string().describe('ID of the chat')
|
|
392
|
+
}),
|
|
393
|
+
execute: async (params)=>{
|
|
394
|
+
const { chatId } = params;
|
|
395
|
+
const result = await client.projects.getByChatId({
|
|
396
|
+
chatId
|
|
397
|
+
});
|
|
398
|
+
return {
|
|
399
|
+
projectId: result.id,
|
|
400
|
+
name: result.name,
|
|
401
|
+
description: result.description,
|
|
402
|
+
privacy: result.privacy,
|
|
403
|
+
webUrl: result.webUrl,
|
|
404
|
+
createdAt: result.createdAt,
|
|
405
|
+
chatsCount: result.chats.length
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
// Environment Variables Tools
|
|
410
|
+
const createEnvironmentVariables = tool({
|
|
411
|
+
description: 'Create environment variables for a project',
|
|
412
|
+
inputSchema: z.object({
|
|
413
|
+
projectId: z.string().describe('ID of the project'),
|
|
414
|
+
environmentVariables: z.array(z.object({
|
|
415
|
+
key: z.string().describe('Environment variable key'),
|
|
416
|
+
value: z.string().describe('Environment variable value')
|
|
417
|
+
})).describe('Environment variables to create'),
|
|
418
|
+
upsert: z.boolean().optional().describe('Whether to upsert existing variables'),
|
|
419
|
+
decrypted: z.string().optional().describe('Whether to return decrypted values')
|
|
420
|
+
}),
|
|
421
|
+
execute: async (params)=>{
|
|
422
|
+
const { projectId, environmentVariables, upsert, decrypted } = params;
|
|
423
|
+
const result = await client.projects.createEnvVars({
|
|
424
|
+
projectId,
|
|
425
|
+
environmentVariables,
|
|
426
|
+
upsert,
|
|
427
|
+
decrypted
|
|
428
|
+
});
|
|
429
|
+
return {
|
|
430
|
+
environmentVariables: result.data.map((envVar)=>({
|
|
431
|
+
id: envVar.id,
|
|
432
|
+
key: envVar.key,
|
|
433
|
+
value: envVar.value,
|
|
434
|
+
decrypted: envVar.decrypted,
|
|
435
|
+
createdAt: envVar.createdAt
|
|
436
|
+
}))
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
const listEnvironmentVariables = tool({
|
|
441
|
+
description: 'List environment variables for a project',
|
|
442
|
+
inputSchema: z.object({
|
|
443
|
+
projectId: z.string().describe('ID of the project'),
|
|
444
|
+
decrypted: z.string().optional().describe('Whether to return decrypted values')
|
|
445
|
+
}),
|
|
446
|
+
execute: async (params)=>{
|
|
447
|
+
const { projectId, decrypted } = params;
|
|
448
|
+
const result = await client.projects.findEnvVars({
|
|
449
|
+
projectId,
|
|
450
|
+
decrypted
|
|
451
|
+
});
|
|
452
|
+
return {
|
|
453
|
+
environmentVariables: result.data.map((envVar)=>({
|
|
454
|
+
id: envVar.id,
|
|
455
|
+
key: envVar.key,
|
|
456
|
+
value: envVar.value,
|
|
457
|
+
decrypted: envVar.decrypted,
|
|
458
|
+
createdAt: envVar.createdAt,
|
|
459
|
+
updatedAt: envVar.updatedAt
|
|
460
|
+
}))
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
const updateEnvironmentVariables = tool({
|
|
465
|
+
description: 'Update environment variables for a project',
|
|
466
|
+
inputSchema: z.object({
|
|
467
|
+
projectId: z.string().describe('ID of the project'),
|
|
468
|
+
environmentVariables: z.array(z.object({
|
|
469
|
+
id: z.string().describe('Environment variable ID'),
|
|
470
|
+
value: z.string().describe('New environment variable value')
|
|
471
|
+
})).describe('Environment variables to update'),
|
|
472
|
+
decrypted: z.string().optional().describe('Whether to return decrypted values')
|
|
473
|
+
}),
|
|
474
|
+
execute: async (params)=>{
|
|
475
|
+
const { projectId, environmentVariables, decrypted } = params;
|
|
476
|
+
const result = await client.projects.updateEnvVars({
|
|
477
|
+
projectId,
|
|
478
|
+
environmentVariables,
|
|
479
|
+
decrypted
|
|
480
|
+
});
|
|
481
|
+
return {
|
|
482
|
+
environmentVariables: result.data.map((envVar)=>({
|
|
483
|
+
id: envVar.id,
|
|
484
|
+
key: envVar.key,
|
|
485
|
+
value: envVar.value,
|
|
486
|
+
decrypted: envVar.decrypted,
|
|
487
|
+
updatedAt: envVar.updatedAt
|
|
488
|
+
}))
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
const deleteEnvironmentVariables = tool({
|
|
493
|
+
description: 'Delete environment variables from a project',
|
|
494
|
+
inputSchema: z.object({
|
|
495
|
+
projectId: z.string().describe('ID of the project'),
|
|
496
|
+
environmentVariableIds: z.array(z.string()).describe('IDs of environment variables to delete')
|
|
497
|
+
}),
|
|
498
|
+
execute: async (params)=>{
|
|
499
|
+
const { projectId, environmentVariableIds } = params;
|
|
500
|
+
const result = await client.projects.deleteEnvVars({
|
|
501
|
+
projectId,
|
|
502
|
+
environmentVariableIds
|
|
503
|
+
});
|
|
504
|
+
return {
|
|
505
|
+
deletedVariables: result.data.map((envVar)=>({
|
|
506
|
+
id: envVar.id,
|
|
507
|
+
deleted: envVar.deleted
|
|
508
|
+
}))
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
return {
|
|
513
|
+
createProject,
|
|
514
|
+
getProject,
|
|
515
|
+
updateProject,
|
|
516
|
+
listProjects,
|
|
517
|
+
assignChatToProject,
|
|
518
|
+
getProjectByChat,
|
|
519
|
+
createEnvironmentVariables,
|
|
520
|
+
listEnvironmentVariables,
|
|
521
|
+
updateEnvironmentVariables,
|
|
522
|
+
deleteEnvironmentVariables
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Creates deployment-related AI SDK tools
|
|
528
|
+
*/ function createDeploymentTools(config = {}) {
|
|
529
|
+
const client = createClient(config);
|
|
530
|
+
const createDeployment = tool({
|
|
531
|
+
description: 'Create a new deployment from a chat version',
|
|
532
|
+
inputSchema: z.object({
|
|
533
|
+
projectId: z.string().describe('ID of the project to deploy to'),
|
|
534
|
+
chatId: z.string().describe('ID of the chat to deploy'),
|
|
535
|
+
versionId: z.string().describe('ID of the specific version to deploy')
|
|
536
|
+
}),
|
|
537
|
+
execute: async (params)=>{
|
|
538
|
+
const { projectId, chatId, versionId } = params;
|
|
539
|
+
const result = await client.deployments.create({
|
|
540
|
+
projectId,
|
|
541
|
+
chatId,
|
|
542
|
+
versionId
|
|
543
|
+
});
|
|
544
|
+
return {
|
|
545
|
+
deploymentId: result.id,
|
|
546
|
+
projectId: result.projectId,
|
|
547
|
+
chatId: result.chatId,
|
|
548
|
+
versionId: result.versionId,
|
|
549
|
+
inspectorUrl: result.inspectorUrl,
|
|
550
|
+
webUrl: result.webUrl,
|
|
551
|
+
apiUrl: result.apiUrl
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
const getDeployment = tool({
|
|
556
|
+
description: 'Get details of an existing deployment',
|
|
557
|
+
inputSchema: z.object({
|
|
558
|
+
deploymentId: z.string().describe('ID of the deployment to retrieve')
|
|
559
|
+
}),
|
|
560
|
+
execute: async (params)=>{
|
|
561
|
+
const { deploymentId } = params;
|
|
562
|
+
const result = await client.deployments.getById({
|
|
563
|
+
deploymentId
|
|
564
|
+
});
|
|
565
|
+
return {
|
|
566
|
+
deploymentId: result.id,
|
|
567
|
+
projectId: result.projectId,
|
|
568
|
+
chatId: result.chatId,
|
|
569
|
+
versionId: result.versionId,
|
|
570
|
+
inspectorUrl: result.inspectorUrl,
|
|
571
|
+
webUrl: result.webUrl,
|
|
572
|
+
apiUrl: result.apiUrl
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
const deleteDeployment = tool({
|
|
577
|
+
description: 'Delete an existing deployment',
|
|
578
|
+
inputSchema: z.object({
|
|
579
|
+
deploymentId: z.string().describe('ID of the deployment to delete')
|
|
580
|
+
}),
|
|
581
|
+
execute: async (params)=>{
|
|
582
|
+
const { deploymentId } = params;
|
|
583
|
+
const result = await client.deployments.delete({
|
|
584
|
+
deploymentId
|
|
585
|
+
});
|
|
586
|
+
return {
|
|
587
|
+
deploymentId: result.id,
|
|
588
|
+
deleted: result.deleted
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
const listDeployments = tool({
|
|
593
|
+
description: 'List deployments by project, chat, and version',
|
|
594
|
+
inputSchema: z.object({
|
|
595
|
+
projectId: z.string().describe('ID of the project'),
|
|
596
|
+
chatId: z.string().describe('ID of the chat'),
|
|
597
|
+
versionId: z.string().describe('ID of the version')
|
|
598
|
+
}),
|
|
599
|
+
execute: async (params)=>{
|
|
600
|
+
const { projectId, chatId, versionId } = params;
|
|
601
|
+
const result = await client.deployments.find({
|
|
602
|
+
projectId,
|
|
603
|
+
chatId,
|
|
604
|
+
versionId
|
|
605
|
+
});
|
|
606
|
+
return {
|
|
607
|
+
deployments: result.data.map((deployment)=>({
|
|
608
|
+
deploymentId: deployment.id,
|
|
609
|
+
projectId: deployment.projectId,
|
|
610
|
+
chatId: deployment.chatId,
|
|
611
|
+
versionId: deployment.versionId,
|
|
612
|
+
inspectorUrl: deployment.inspectorUrl,
|
|
613
|
+
webUrl: deployment.webUrl,
|
|
614
|
+
apiUrl: deployment.apiUrl
|
|
615
|
+
}))
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
const getDeploymentLogs = tool({
|
|
620
|
+
description: 'Get logs for a deployment',
|
|
621
|
+
inputSchema: z.object({
|
|
622
|
+
deploymentId: z.string().describe('ID of the deployment'),
|
|
623
|
+
since: z.string().optional().describe('Timestamp to get logs since')
|
|
624
|
+
}),
|
|
625
|
+
execute: async (params)=>{
|
|
626
|
+
const { deploymentId, since } = params;
|
|
627
|
+
const result = await client.deployments.findLogs({
|
|
628
|
+
deploymentId,
|
|
629
|
+
since
|
|
630
|
+
});
|
|
631
|
+
return {
|
|
632
|
+
logs: result.logs,
|
|
633
|
+
error: result.error,
|
|
634
|
+
nextSince: result.nextSince
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
const getDeploymentErrors = tool({
|
|
639
|
+
description: 'Get errors for a deployment',
|
|
640
|
+
inputSchema: z.object({
|
|
641
|
+
deploymentId: z.string().describe('ID of the deployment')
|
|
642
|
+
}),
|
|
643
|
+
execute: async (params)=>{
|
|
644
|
+
const { deploymentId } = params;
|
|
645
|
+
const result = await client.deployments.findErrors({
|
|
646
|
+
deploymentId
|
|
647
|
+
});
|
|
648
|
+
return {
|
|
649
|
+
error: result.error,
|
|
650
|
+
fullErrorText: result.fullErrorText,
|
|
651
|
+
errorType: result.errorType,
|
|
652
|
+
formattedError: result.formattedError
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
return {
|
|
657
|
+
createDeployment,
|
|
658
|
+
getDeployment,
|
|
659
|
+
deleteDeployment,
|
|
660
|
+
listDeployments,
|
|
661
|
+
getDeploymentLogs,
|
|
662
|
+
getDeploymentErrors
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Creates user-related AI SDK tools
|
|
668
|
+
*/ function createUserTools(config = {}) {
|
|
669
|
+
const client = createClient(config);
|
|
670
|
+
const getCurrentUser = tool({
|
|
671
|
+
description: 'Get current user information',
|
|
672
|
+
inputSchema: z.object({}),
|
|
673
|
+
execute: async ()=>{
|
|
674
|
+
const result = await client.user.get();
|
|
675
|
+
return {
|
|
676
|
+
userId: result.id,
|
|
677
|
+
name: result.name,
|
|
678
|
+
email: result.email,
|
|
679
|
+
avatar: result.avatar
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
const getUserBilling = tool({
|
|
684
|
+
description: 'Get current user billing information',
|
|
685
|
+
inputSchema: z.object({
|
|
686
|
+
scope: z.string().optional().describe('Scope for billing information')
|
|
687
|
+
}),
|
|
688
|
+
execute: async (params)=>{
|
|
689
|
+
const { scope } = params;
|
|
690
|
+
const result = await client.user.getBilling({
|
|
691
|
+
scope
|
|
692
|
+
});
|
|
693
|
+
if (result.billingType === 'token') {
|
|
694
|
+
return {
|
|
695
|
+
billingType: result.billingType,
|
|
696
|
+
plan: result.data.plan,
|
|
697
|
+
role: result.data.role,
|
|
698
|
+
billingMode: result.data.billingMode,
|
|
699
|
+
billingCycle: {
|
|
700
|
+
start: result.data.billingCycle.start,
|
|
701
|
+
end: result.data.billingCycle.end
|
|
702
|
+
},
|
|
703
|
+
balance: {
|
|
704
|
+
remaining: result.data.balance.remaining,
|
|
705
|
+
total: result.data.balance.total
|
|
706
|
+
},
|
|
707
|
+
onDemand: {
|
|
708
|
+
balance: result.data.onDemand.balance,
|
|
709
|
+
blocks: result.data.onDemand.blocks
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
} else {
|
|
713
|
+
return {
|
|
714
|
+
billingType: result.billingType,
|
|
715
|
+
remaining: result.data.remaining,
|
|
716
|
+
reset: result.data.reset,
|
|
717
|
+
limit: result.data.limit
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
const getUserPlan = tool({
|
|
723
|
+
description: 'Get current user plan information',
|
|
724
|
+
inputSchema: z.object({}),
|
|
725
|
+
execute: async ()=>{
|
|
726
|
+
const result = await client.user.getPlan();
|
|
727
|
+
return {
|
|
728
|
+
plan: result.plan,
|
|
729
|
+
billingCycle: {
|
|
730
|
+
start: result.billingCycle.start,
|
|
731
|
+
end: result.billingCycle.end
|
|
732
|
+
},
|
|
733
|
+
balance: {
|
|
734
|
+
remaining: result.balance.remaining,
|
|
735
|
+
total: result.balance.total
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
});
|
|
740
|
+
const getUserScopes = tool({
|
|
741
|
+
description: 'Get user scopes/permissions',
|
|
742
|
+
inputSchema: z.object({}),
|
|
743
|
+
execute: async ()=>{
|
|
744
|
+
const result = await client.user.getScopes();
|
|
745
|
+
return {
|
|
746
|
+
scopes: result.data.map((scope)=>({
|
|
747
|
+
id: scope.id,
|
|
748
|
+
name: scope.name
|
|
749
|
+
}))
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
const getRateLimits = tool({
|
|
754
|
+
description: 'Get current rate limit information',
|
|
755
|
+
inputSchema: z.object({
|
|
756
|
+
scope: z.string().optional().describe('Scope for rate limit information')
|
|
757
|
+
}),
|
|
758
|
+
execute: async (params)=>{
|
|
759
|
+
const { scope } = params;
|
|
760
|
+
const result = await client.rateLimits.find({
|
|
761
|
+
scope
|
|
762
|
+
});
|
|
763
|
+
return {
|
|
764
|
+
remaining: result.remaining,
|
|
765
|
+
reset: result.reset,
|
|
766
|
+
limit: result.limit
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
return {
|
|
771
|
+
getCurrentUser,
|
|
772
|
+
getUserBilling,
|
|
773
|
+
getUserPlan,
|
|
774
|
+
getUserScopes,
|
|
775
|
+
getRateLimits
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* Creates webhook-related AI SDK tools
|
|
781
|
+
*/ function createHookTools(config = {}) {
|
|
782
|
+
const client = createClient(config);
|
|
783
|
+
const createHook = tool({
|
|
784
|
+
description: 'Create a new webhook for v0 events',
|
|
785
|
+
inputSchema: z.object({
|
|
786
|
+
name: z.string().describe('Name of the webhook'),
|
|
787
|
+
url: z.string().describe('URL to send webhook events to'),
|
|
788
|
+
events: z.array(z.enum([
|
|
789
|
+
'chat.created',
|
|
790
|
+
'chat.updated',
|
|
791
|
+
'chat.deleted',
|
|
792
|
+
'message.created',
|
|
793
|
+
'message.updated',
|
|
794
|
+
'message.deleted'
|
|
795
|
+
])).describe('Events to listen for'),
|
|
796
|
+
chatId: z.string().optional().describe('Specific chat ID to listen to events for')
|
|
797
|
+
}),
|
|
798
|
+
execute: async (params)=>{
|
|
799
|
+
const { name, url, events, chatId } = params;
|
|
800
|
+
const result = await client.hooks.create({
|
|
801
|
+
name,
|
|
802
|
+
url,
|
|
803
|
+
events,
|
|
804
|
+
chatId
|
|
805
|
+
});
|
|
806
|
+
return {
|
|
807
|
+
hookId: result.id,
|
|
808
|
+
name: result.name,
|
|
809
|
+
url: result.url,
|
|
810
|
+
events: result.events,
|
|
811
|
+
chatId: result.chatId
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
const getHook = tool({
|
|
816
|
+
description: 'Get details of an existing webhook',
|
|
817
|
+
inputSchema: z.object({
|
|
818
|
+
hookId: z.string().describe('ID of the webhook to retrieve')
|
|
819
|
+
}),
|
|
820
|
+
execute: async (params)=>{
|
|
821
|
+
const { hookId } = params;
|
|
822
|
+
const result = await client.hooks.getById({
|
|
823
|
+
hookId
|
|
824
|
+
});
|
|
825
|
+
return {
|
|
826
|
+
hookId: result.id,
|
|
827
|
+
name: result.name,
|
|
828
|
+
url: result.url,
|
|
829
|
+
events: result.events,
|
|
830
|
+
chatId: result.chatId
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
const updateHook = tool({
|
|
835
|
+
description: 'Update properties of an existing webhook',
|
|
836
|
+
inputSchema: z.object({
|
|
837
|
+
hookId: z.string().describe('ID of the webhook to update'),
|
|
838
|
+
name: z.string().optional().describe('New name for the webhook'),
|
|
839
|
+
url: z.string().optional().describe('New URL for the webhook'),
|
|
840
|
+
events: z.array(z.enum([
|
|
841
|
+
'chat.created',
|
|
842
|
+
'chat.updated',
|
|
843
|
+
'chat.deleted',
|
|
844
|
+
'message.created',
|
|
845
|
+
'message.updated',
|
|
846
|
+
'message.deleted'
|
|
847
|
+
])).optional().describe('New events to listen for')
|
|
848
|
+
}),
|
|
849
|
+
execute: async (params)=>{
|
|
850
|
+
const { hookId, name, url, events } = params;
|
|
851
|
+
const result = await client.hooks.update({
|
|
852
|
+
hookId,
|
|
853
|
+
name,
|
|
854
|
+
url,
|
|
855
|
+
events
|
|
856
|
+
});
|
|
857
|
+
return {
|
|
858
|
+
hookId: result.id,
|
|
859
|
+
name: result.name,
|
|
860
|
+
url: result.url,
|
|
861
|
+
events: result.events,
|
|
862
|
+
chatId: result.chatId
|
|
863
|
+
};
|
|
864
|
+
}
|
|
865
|
+
});
|
|
866
|
+
const deleteHook = tool({
|
|
867
|
+
description: 'Delete an existing webhook',
|
|
868
|
+
inputSchema: z.object({
|
|
869
|
+
hookId: z.string().describe('ID of the webhook to delete')
|
|
870
|
+
}),
|
|
871
|
+
execute: async (params)=>{
|
|
872
|
+
const { hookId } = params;
|
|
873
|
+
const result = await client.hooks.delete({
|
|
874
|
+
hookId
|
|
875
|
+
});
|
|
876
|
+
return {
|
|
877
|
+
hookId: result.id,
|
|
878
|
+
deleted: result.deleted
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
const listHooks = tool({
|
|
883
|
+
description: 'List all webhooks',
|
|
884
|
+
inputSchema: z.object({}),
|
|
885
|
+
execute: async ()=>{
|
|
886
|
+
const result = await client.hooks.find();
|
|
887
|
+
return {
|
|
888
|
+
hooks: result.data.map((hook)=>({
|
|
889
|
+
hookId: hook.id,
|
|
890
|
+
name: hook.name
|
|
891
|
+
}))
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
});
|
|
895
|
+
return {
|
|
896
|
+
createHook,
|
|
897
|
+
getHook,
|
|
898
|
+
updateHook,
|
|
899
|
+
deleteHook,
|
|
900
|
+
listHooks
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
/**
|
|
905
|
+
* Creates all v0 AI SDK tools as a flat object.
|
|
906
|
+
*
|
|
907
|
+
* ⚠️ Note: This includes ALL available tools (~20+ tools) which adds significant context.
|
|
908
|
+
* Consider using v0ToolsByCategory() to select only the tools you need.
|
|
909
|
+
*
|
|
910
|
+
* @param config Configuration for v0 client
|
|
911
|
+
* @returns Flat object with all v0 tools ready to use with AI SDK
|
|
912
|
+
*
|
|
913
|
+
* @example
|
|
914
|
+
* ```typescript
|
|
915
|
+
* import { generateText } from 'ai'
|
|
916
|
+
* import { openai } from '@ai-sdk/openai'
|
|
917
|
+
* import { v0Tools } from '@v0-sdk/ai-tools'
|
|
918
|
+
*
|
|
919
|
+
* const result = await generateText({
|
|
920
|
+
* model: openai('gpt-4'),
|
|
921
|
+
* prompt: 'Create a new React component',
|
|
922
|
+
* tools: v0Tools({
|
|
923
|
+
* apiKey: process.env.V0_API_KEY
|
|
924
|
+
* })
|
|
925
|
+
* })
|
|
926
|
+
* ```
|
|
927
|
+
*/ function v0Tools(config = {}) {
|
|
928
|
+
// Use environment variable if apiKey not provided
|
|
929
|
+
const clientConfig = {
|
|
930
|
+
...config,
|
|
931
|
+
apiKey: config.apiKey || process.env.V0_API_KEY
|
|
932
|
+
};
|
|
933
|
+
const chatTools = createChatTools(clientConfig);
|
|
934
|
+
const projectTools = createProjectTools(clientConfig);
|
|
935
|
+
const deploymentTools = createDeploymentTools(clientConfig);
|
|
936
|
+
const userTools = createUserTools(clientConfig);
|
|
937
|
+
const hookTools = createHookTools(clientConfig);
|
|
938
|
+
return {
|
|
939
|
+
...chatTools,
|
|
940
|
+
...projectTools,
|
|
941
|
+
...deploymentTools,
|
|
942
|
+
...userTools,
|
|
943
|
+
...hookTools
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Creates v0 tools organized by category for selective usage (recommended).
|
|
948
|
+
* This allows you to include only the tools you need, reducing context size.
|
|
949
|
+
*
|
|
950
|
+
* @param config Configuration for v0 client
|
|
951
|
+
* @returns Object containing all v0 tools organized by category
|
|
952
|
+
*
|
|
953
|
+
* @example
|
|
954
|
+
* ```typescript
|
|
955
|
+
* import { generateText } from 'ai'
|
|
956
|
+
* import { openai } from '@ai-sdk/openai'
|
|
957
|
+
* import { v0ToolsByCategory } from '@v0-sdk/ai-tools'
|
|
958
|
+
*
|
|
959
|
+
* const tools = v0ToolsByCategory({
|
|
960
|
+
* apiKey: process.env.V0_API_KEY
|
|
961
|
+
* })
|
|
962
|
+
*
|
|
963
|
+
* // Only include chat and project tools
|
|
964
|
+
* const result = await generateText({
|
|
965
|
+
* model: openai('gpt-4'),
|
|
966
|
+
* prompt: 'Create a new React component',
|
|
967
|
+
* tools: {
|
|
968
|
+
* ...tools.chat,
|
|
969
|
+
* ...tools.project
|
|
970
|
+
* }
|
|
971
|
+
* })
|
|
972
|
+
* ```
|
|
973
|
+
*/ function v0ToolsByCategory(config = {}) {
|
|
974
|
+
// Use environment variable if apiKey not provided
|
|
975
|
+
const clientConfig = {
|
|
976
|
+
...config,
|
|
977
|
+
apiKey: config.apiKey || process.env.V0_API_KEY
|
|
978
|
+
};
|
|
979
|
+
return {
|
|
980
|
+
/**
|
|
981
|
+
* Chat-related tools for creating, managing, and interacting with v0 chats
|
|
982
|
+
*/ chat: createChatTools(clientConfig),
|
|
983
|
+
/**
|
|
984
|
+
* Project-related tools for creating and managing v0 projects
|
|
985
|
+
*/ project: createProjectTools(clientConfig),
|
|
986
|
+
/**
|
|
987
|
+
* Deployment-related tools for creating and managing deployments
|
|
988
|
+
*/ deployment: createDeploymentTools(clientConfig),
|
|
989
|
+
/**
|
|
990
|
+
* User-related tools for getting user information, billing, and rate limits
|
|
991
|
+
*/ user: createUserTools(clientConfig),
|
|
992
|
+
/**
|
|
993
|
+
* Webhook tools for creating and managing event hooks
|
|
994
|
+
*/ hook: createHookTools(clientConfig)
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* @deprecated Use v0Tools instead (now returns flat structure by default)
|
|
999
|
+
*/ function v0ToolsFlat(config = {}) {
|
|
1000
|
+
return v0Tools(config);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
export { createChatTools, createDeploymentTools, createHookTools, createProjectTools, createUserTools, v0Tools as default, v0Tools, v0ToolsByCategory, v0ToolsFlat };
|