@v0-sdk/ai-tools 0.3.7 → 3.0.0-canary.bf3a020

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