v0-sdk 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,275 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ let BASE_URL = 'https://api.v0.dev/v1';
4
+ async function fetcher(url, method, params = {}) {
5
+ const queryString = params.query ? '?' + new URLSearchParams(params.query).toString() : '';
6
+ const finalUrl = BASE_URL + url + queryString;
7
+ const apiKey = process.env.V0_API_KEY;
8
+ if (!apiKey) {
9
+ throw new Error('V0_API_KEY environment variable is required');
10
+ }
11
+ const hasBody = method !== 'GET' && params.body;
12
+ const headers = {
13
+ Authorization: `Bearer ${apiKey}`,
14
+ ...params.headers
15
+ };
16
+ if (hasBody) {
17
+ headers['Content-Type'] = 'application/json';
18
+ }
19
+ const res = await fetch(finalUrl, {
20
+ method,
21
+ headers,
22
+ body: hasBody ? JSON.stringify(params.body) : undefined
23
+ });
24
+ if (!res.ok) {
25
+ const text = await res.text();
26
+ throw new Error(`HTTP ${res.status}: ${text}`);
27
+ }
28
+ return res.json();
29
+ }
30
+
31
+ const v0 = {
32
+ chats: {
33
+ async create (params) {
34
+ const body = {
35
+ message: params.message,
36
+ attachments: params.attachments,
37
+ system: params.system,
38
+ chatPrivacy: params.chatPrivacy,
39
+ projectId: params.projectId,
40
+ modelConfiguration: params.modelConfiguration
41
+ };
42
+ return fetcher(`/chats`, 'POST', {
43
+ body
44
+ });
45
+ },
46
+ async find (params) {
47
+ const query = params ? Object.fromEntries(Object.entries({
48
+ limit: params.limit,
49
+ offset: params.offset,
50
+ isFavorite: params.isFavorite
51
+ }).filter(([_, value])=>value !== undefined)) : {};
52
+ const hasQuery = Object.keys(query).length > 0;
53
+ return fetcher(`/chats`, 'GET', {
54
+ ...hasQuery ? {
55
+ query
56
+ } : {}
57
+ });
58
+ },
59
+ async delete (params) {
60
+ const pathParams = {
61
+ chatId: params.chatId
62
+ };
63
+ return fetcher(`/chats/${pathParams.chatId}`, 'DELETE', {
64
+ });
65
+ },
66
+ async getById (params) {
67
+ const pathParams = {
68
+ chatId: params.chatId
69
+ };
70
+ return fetcher(`/chats/${pathParams.chatId}`, 'GET', {
71
+ });
72
+ },
73
+ async update (params) {
74
+ const pathParams = {
75
+ chatId: params.chatId
76
+ };
77
+ const body = {
78
+ privacy: params.privacy
79
+ };
80
+ return fetcher(`/chats/${pathParams.chatId}`, 'PATCH', {
81
+ body
82
+ });
83
+ },
84
+ async favorite (params) {
85
+ const pathParams = {
86
+ chatId: params.chatId
87
+ };
88
+ const body = {
89
+ isFavorite: params.isFavorite
90
+ };
91
+ return fetcher(`/chats/${pathParams.chatId}/favorite`, 'PUT', {
92
+ body
93
+ });
94
+ },
95
+ async fork (params) {
96
+ const pathParams = {
97
+ chatId: params.chatId
98
+ };
99
+ const body = {
100
+ versionId: params.versionId
101
+ };
102
+ return fetcher(`/chats/${pathParams.chatId}/fork`, 'POST', {
103
+ body
104
+ });
105
+ },
106
+ async createMessage (params) {
107
+ const pathParams = {
108
+ chatId: params.chatId
109
+ };
110
+ const body = {
111
+ message: params.message,
112
+ attachments: params.attachments,
113
+ modelConfiguration: params.modelConfiguration
114
+ };
115
+ return fetcher(`/chats/${pathParams.chatId}/messages`, 'POST', {
116
+ body
117
+ });
118
+ },
119
+ async findIframe (params) {
120
+ const pathParams = {
121
+ chatId: params.chatId,
122
+ versionId: params.versionId
123
+ };
124
+ return fetcher(`/chats/${pathParams.chatId}/versions/${pathParams.versionId}/iframe`, 'GET', {
125
+ });
126
+ },
127
+ async getVersionFrameToken (params) {
128
+ const pathParams = {
129
+ chatId: params.chatId,
130
+ versionId: params.versionId
131
+ };
132
+ return fetcher(`/chats/${pathParams.chatId}/versions/${pathParams.versionId}/frame-token`, 'GET', {
133
+ });
134
+ },
135
+ async getMetadata (params) {
136
+ const pathParams = {
137
+ chatId: params.chatId
138
+ };
139
+ return fetcher(`/chats/${pathParams.chatId}/metadata`, 'GET', {
140
+ });
141
+ },
142
+ async upload (params) {
143
+ const pathParams = {
144
+ chatId: params.chatId
145
+ };
146
+ const body = {
147
+ file: params.file
148
+ };
149
+ return fetcher(`/chats/${pathParams.chatId}/upload`, 'POST', {
150
+ body
151
+ });
152
+ },
153
+ async resume (params) {
154
+ const pathParams = {
155
+ chatId: params.chatId,
156
+ messageId: params.messageId
157
+ };
158
+ return fetcher(`/chats/${pathParams.chatId}/messages/${pathParams.messageId}/resume`, 'POST', {
159
+ });
160
+ }
161
+ },
162
+ projects: {
163
+ async getByChatId (params) {
164
+ const pathParams = {
165
+ chatId: params.chatId
166
+ };
167
+ return fetcher(`/chats/${pathParams.chatId}/project`, 'GET', {
168
+ });
169
+ },
170
+ async find () {
171
+ return fetcher(`/projects`, 'GET', {});
172
+ },
173
+ async create (params) {
174
+ const body = {
175
+ name: params.name,
176
+ description: params.description,
177
+ icon: params.icon,
178
+ environmentVariables: params.environmentVariables,
179
+ instructions: params.instructions
180
+ };
181
+ return fetcher(`/projects`, 'POST', {
182
+ body
183
+ });
184
+ },
185
+ async assign (params) {
186
+ const pathParams = {
187
+ projectId: params.projectId
188
+ };
189
+ const body = {
190
+ chatId: params.chatId
191
+ };
192
+ return fetcher(`/projects/${pathParams.projectId}/assign`, 'POST', {
193
+ body
194
+ });
195
+ }
196
+ },
197
+ deployments: {
198
+ async findLogs (params) {
199
+ const pathParams = {
200
+ deploymentId: params.deploymentId
201
+ };
202
+ const query = Object.fromEntries(Object.entries({
203
+ since: params.since
204
+ }).filter(([_, value])=>value !== undefined));
205
+ const hasQuery = Object.keys(query).length > 0;
206
+ return fetcher(`/deployments/${pathParams.deploymentId}/logs`, 'GET', {
207
+ ...hasQuery ? {
208
+ query
209
+ } : {}
210
+ });
211
+ },
212
+ async findErrors (params) {
213
+ const pathParams = {
214
+ deploymentId: params.deploymentId
215
+ };
216
+ return fetcher(`/deployments/${pathParams.deploymentId}/errors`, 'GET', {
217
+ });
218
+ }
219
+ },
220
+ integrations: {
221
+ vercel: {
222
+ projects: {
223
+ async find () {
224
+ return fetcher(`/integrations/vercel/projects`, 'GET', {});
225
+ },
226
+ async create (params) {
227
+ const body = {
228
+ projectId: params.projectId,
229
+ name: params.name
230
+ };
231
+ return fetcher(`/integrations/vercel/projects`, 'POST', {
232
+ body
233
+ });
234
+ }
235
+ }
236
+ }
237
+ },
238
+ rateLimits: {
239
+ async find (params) {
240
+ const query = params ? Object.fromEntries(Object.entries({
241
+ scope: params.scope
242
+ }).filter(([_, value])=>value !== undefined)) : {};
243
+ const hasQuery = Object.keys(query).length > 0;
244
+ return fetcher(`/rate-limits`, 'GET', {
245
+ ...hasQuery ? {
246
+ query
247
+ } : {}
248
+ });
249
+ }
250
+ },
251
+ user: {
252
+ async get () {
253
+ return fetcher(`/user`, 'GET', {});
254
+ },
255
+ async getBilling (params) {
256
+ const query = params ? Object.fromEntries(Object.entries({
257
+ scope: params.scope
258
+ }).filter(([_, value])=>value !== undefined)) : {};
259
+ const hasQuery = Object.keys(query).length > 0;
260
+ return fetcher(`/user/billing`, 'GET', {
261
+ ...hasQuery ? {
262
+ query
263
+ } : {}
264
+ });
265
+ },
266
+ async getPlan () {
267
+ return fetcher(`/user/plan`, 'GET', {});
268
+ },
269
+ async getScopes () {
270
+ return fetcher(`/user/scopes`, 'GET', {});
271
+ }
272
+ }
273
+ };
274
+
275
+ exports.v0 = v0;
@@ -0,0 +1,355 @@
1
+ type ChatDetail = {
2
+ id: string;
3
+ object: 'chat';
4
+ url: string;
5
+ shareable: boolean;
6
+ privacy?: 'public' | 'private' | 'team' | 'team-edit' | 'unlisted';
7
+ title?: string;
8
+ updatedAt?: string;
9
+ favorite: boolean;
10
+ authorId: string;
11
+ latestBlockId?: string;
12
+ messages: {
13
+ id: string;
14
+ object: 'message';
15
+ content: string;
16
+ createdAt: string;
17
+ type: 'message' | 'refinement' | 'forked-block' | 'forked-chat' | 'open-in-v0' | 'added-environment-variables' | 'added-integration' | 'deleted-file' | 'moved-file' | 'renamed-file' | 'edited-file' | 'replace-src' | 'reverted-block' | 'fix-with-v0' | 'sync-git';
18
+ }[];
19
+ };
20
+ interface ChatSummary {
21
+ id: string;
22
+ object: 'chat';
23
+ shareable: boolean;
24
+ privacy: string;
25
+ title?: string;
26
+ updatedAt: string;
27
+ favorite: boolean;
28
+ authorId: string;
29
+ latestVersionId?: string;
30
+ }
31
+ type MessageDetail = {
32
+ id: string;
33
+ object: 'message';
34
+ chatId: string;
35
+ url: string;
36
+ files?: {
37
+ lang: string;
38
+ meta: Record<string, any>;
39
+ source: string;
40
+ }[];
41
+ demo?: string;
42
+ text: string;
43
+ modelConfiguration: {
44
+ modelId: 'v0-1.5-sm' | 'v0-1.5-md' | 'v0-1.5-lg';
45
+ imageGenerations?: boolean;
46
+ thinking?: boolean;
47
+ };
48
+ };
49
+ interface ProjectDetail {
50
+ id: string;
51
+ object: 'project';
52
+ name: string;
53
+ vercelProjectId?: string;
54
+ }
55
+ interface ScopeSummary {
56
+ id: string;
57
+ object: 'scope';
58
+ name?: string;
59
+ }
60
+ interface UserDetail {
61
+ id: string;
62
+ object: 'user';
63
+ name?: string;
64
+ email: string;
65
+ avatar: string;
66
+ }
67
+ interface VercelProjectDetail {
68
+ id: string;
69
+ object: 'vercel_project';
70
+ name: string;
71
+ }
72
+ interface ChatsCreateRequest {
73
+ message: string;
74
+ attachments?: {
75
+ url: string;
76
+ }[];
77
+ system?: string;
78
+ chatPrivacy?: 'public' | 'private' | 'team-edit' | 'team' | 'unlisted';
79
+ projectId?: string;
80
+ modelConfiguration?: {
81
+ modelId: 'v0-1.5-sm' | 'v0-1.5-md' | 'v0-1.5-lg';
82
+ imageGenerations?: boolean;
83
+ thinking?: boolean;
84
+ };
85
+ }
86
+ type ChatsCreateResponse = {
87
+ id: string;
88
+ object: 'chat';
89
+ url: string;
90
+ files?: {
91
+ lang: string;
92
+ meta: Record<string, any>;
93
+ source: string;
94
+ }[];
95
+ demo?: string;
96
+ text: string;
97
+ modelConfiguration: {
98
+ modelId: 'v0-1.5-sm' | 'v0-1.5-md' | 'v0-1.5-lg';
99
+ imageGenerations?: boolean;
100
+ thinking?: boolean;
101
+ };
102
+ };
103
+ interface ChatsFindResponse {
104
+ object: 'list';
105
+ data: ChatSummary[];
106
+ }
107
+ interface ChatsDeleteResponse {
108
+ id: string;
109
+ object: 'chat';
110
+ deleted: true;
111
+ }
112
+ type ChatsGetByIdResponse = ChatDetail;
113
+ interface ChatsUpdateRequest {
114
+ privacy?: 'public' | 'private' | 'team' | 'team-edit' | 'unlisted';
115
+ }
116
+ type ChatsUpdateResponse = ChatDetail;
117
+ interface ChatsFavoriteRequest {
118
+ isFavorite: boolean;
119
+ }
120
+ interface ChatsFavoriteResponse {
121
+ id: string;
122
+ object: 'chat';
123
+ favorited: boolean;
124
+ }
125
+ interface ChatsForkRequest {
126
+ versionId: string;
127
+ }
128
+ type ChatsForkResponse = ChatDetail;
129
+ type ProjectsGetByChatIdResponse = ProjectDetail;
130
+ interface ChatsCreateMessageRequest {
131
+ message: string;
132
+ attachments?: {
133
+ url: string;
134
+ }[];
135
+ modelConfiguration?: {
136
+ modelId: 'v0-1.5-sm' | 'v0-1.5-md' | 'v0-1.5-lg';
137
+ imageGenerations?: boolean;
138
+ thinking?: boolean;
139
+ };
140
+ }
141
+ type ChatsCreateMessageResponse = MessageDetail;
142
+ interface ChatsFindIframeResponse {
143
+ id: string;
144
+ object: 'iframe';
145
+ url: string;
146
+ }
147
+ interface ChatsGetVersionFrameTokenResponse {
148
+ token: string;
149
+ }
150
+ interface ChatsGetMetadataResponse {
151
+ git: {
152
+ branch: string;
153
+ commit: string;
154
+ };
155
+ deployment: {
156
+ id: string;
157
+ };
158
+ project: {
159
+ id: string;
160
+ name: string;
161
+ url: string;
162
+ };
163
+ }
164
+ interface ChatsUploadRequest {
165
+ file: any;
166
+ }
167
+ interface ChatsUploadResponse {
168
+ url: string;
169
+ }
170
+ type ChatsResumeResponse = MessageDetail;
171
+ interface DeploymentsFindLogsResponse {
172
+ error?: string;
173
+ logs: string[];
174
+ nextSince?: number;
175
+ }
176
+ interface DeploymentsFindErrorsResponse {
177
+ error?: string;
178
+ fullErrorText?: string;
179
+ errorType?: string;
180
+ formattedError?: string;
181
+ }
182
+ interface IntegrationsVercelProjectsFindResponse {
183
+ object: 'list';
184
+ data: VercelProjectDetail[];
185
+ }
186
+ interface IntegrationsVercelProjectsCreateRequest {
187
+ projectId: string;
188
+ name: string;
189
+ }
190
+ type IntegrationsVercelProjectsCreateResponse = VercelProjectDetail;
191
+ interface ProjectsFindResponse {
192
+ object: 'list';
193
+ data: ProjectDetail[];
194
+ }
195
+ interface ProjectsCreateRequest {
196
+ name: string;
197
+ description?: string;
198
+ icon?: string;
199
+ environmentVariables?: {
200
+ key: string;
201
+ value: string;
202
+ }[];
203
+ instructions?: string;
204
+ }
205
+ type ProjectsCreateResponse = ProjectDetail;
206
+ interface ProjectsAssignRequest {
207
+ chatId: string;
208
+ }
209
+ interface ProjectsAssignResponse {
210
+ object: 'project';
211
+ id: string;
212
+ assigned: true;
213
+ }
214
+ interface RateLimitsFindResponse {
215
+ remaining?: number;
216
+ reset?: number;
217
+ limit: number;
218
+ }
219
+ type UserGetResponse = UserDetail;
220
+ type UserGetBillingResponse = {
221
+ billingType: 'token';
222
+ data: {
223
+ plan: string;
224
+ billingMode?: 'test';
225
+ role: string;
226
+ billingCycle: {
227
+ start: number;
228
+ end: number;
229
+ };
230
+ balance: {
231
+ remaining: number;
232
+ total: number;
233
+ };
234
+ onDemand: {
235
+ balance: number;
236
+ blocks?: {
237
+ expirationDate?: number;
238
+ effectiveDate: number;
239
+ originalBalance: number;
240
+ currentBalance: number;
241
+ }[];
242
+ };
243
+ };
244
+ } | {
245
+ billingType: 'legacy';
246
+ data: {
247
+ remaining?: number;
248
+ reset?: number;
249
+ limit: number;
250
+ };
251
+ };
252
+ interface UserGetPlanResponse {
253
+ object: 'plan';
254
+ plan: string;
255
+ billingCycle: {
256
+ start: number;
257
+ end: number;
258
+ };
259
+ balance: {
260
+ remaining: number;
261
+ total: number;
262
+ };
263
+ }
264
+ interface UserGetScopesResponse {
265
+ object: 'list';
266
+ data: ScopeSummary[];
267
+ }
268
+ declare const v0: {
269
+ chats: {
270
+ create(params: ChatsCreateRequest): Promise<ChatsCreateResponse>;
271
+ find(params?: {
272
+ limit?: string;
273
+ offset?: string;
274
+ isFavorite?: string;
275
+ }): Promise<ChatsFindResponse>;
276
+ delete(params: {
277
+ chatId: string;
278
+ }): Promise<ChatsDeleteResponse>;
279
+ getById(params: {
280
+ chatId: string;
281
+ }): Promise<ChatsGetByIdResponse>;
282
+ update(params: {
283
+ chatId: string;
284
+ } & ChatsUpdateRequest): Promise<ChatsUpdateResponse>;
285
+ favorite(params: {
286
+ chatId: string;
287
+ } & ChatsFavoriteRequest): Promise<ChatsFavoriteResponse>;
288
+ fork(params: {
289
+ chatId: string;
290
+ } & ChatsForkRequest): Promise<ChatsForkResponse>;
291
+ createMessage(params: {
292
+ chatId: string;
293
+ } & ChatsCreateMessageRequest): Promise<ChatsCreateMessageResponse>;
294
+ findIframe(params: {
295
+ chatId: string;
296
+ versionId: string;
297
+ }): Promise<ChatsFindIframeResponse>;
298
+ getVersionFrameToken(params: {
299
+ chatId: string;
300
+ versionId: string;
301
+ }): Promise<ChatsGetVersionFrameTokenResponse>;
302
+ getMetadata(params: {
303
+ chatId: string;
304
+ }): Promise<ChatsGetMetadataResponse>;
305
+ upload(params: {
306
+ chatId: string;
307
+ } & ChatsUploadRequest): Promise<ChatsUploadResponse>;
308
+ resume(params: {
309
+ chatId: string;
310
+ messageId: string;
311
+ }): Promise<ChatsResumeResponse>;
312
+ };
313
+ projects: {
314
+ getByChatId(params: {
315
+ chatId: string;
316
+ }): Promise<ProjectsGetByChatIdResponse>;
317
+ find(): Promise<ProjectsFindResponse>;
318
+ create(params: ProjectsCreateRequest): Promise<ProjectsCreateResponse>;
319
+ assign(params: {
320
+ projectId: string;
321
+ } & ProjectsAssignRequest): Promise<ProjectsAssignResponse>;
322
+ };
323
+ deployments: {
324
+ findLogs(params: {
325
+ deploymentId: string;
326
+ since?: string;
327
+ }): Promise<DeploymentsFindLogsResponse>;
328
+ findErrors(params: {
329
+ deploymentId: string;
330
+ }): Promise<DeploymentsFindErrorsResponse>;
331
+ };
332
+ integrations: {
333
+ vercel: {
334
+ projects: {
335
+ find(): Promise<IntegrationsVercelProjectsFindResponse>;
336
+ create(params: IntegrationsVercelProjectsCreateRequest): Promise<IntegrationsVercelProjectsCreateResponse>;
337
+ };
338
+ };
339
+ };
340
+ rateLimits: {
341
+ find(params?: {
342
+ scope?: string;
343
+ }): Promise<RateLimitsFindResponse>;
344
+ };
345
+ user: {
346
+ get(): Promise<UserGetResponse>;
347
+ getBilling(params?: {
348
+ scope?: string;
349
+ }): Promise<UserGetBillingResponse>;
350
+ getPlan(): Promise<UserGetPlanResponse>;
351
+ getScopes(): Promise<UserGetScopesResponse>;
352
+ };
353
+ };
354
+
355
+ export { v0 };