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