v0-sdk 0.0.10 → 0.0.12

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 CHANGED
@@ -1,275 +1,282 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
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;
3
+ function createFetcher(config = {}) {
4
+ const baseUrl = config.baseUrl || 'https://api.v0.dev/v1';
5
+ const apiKey = config.apiKey || process.env.V0_API_KEY;
8
6
  if (!apiKey) {
9
- throw new Error('V0_API_KEY environment variable is required');
7
+ throw new Error('API key is required. Provide it via config.apiKey or V0_API_KEY environment variable');
10
8
  }
11
- const hasBody = method !== 'GET' && params.body;
12
- const headers = {
13
- Authorization: `Bearer ${apiKey}`,
14
- ...params.headers
9
+ return async function fetcher(url, method, params = {}) {
10
+ const queryString = params.query ? '?' + new URLSearchParams(params.query).toString() : '';
11
+ const finalUrl = baseUrl + url + queryString;
12
+ const hasBody = method !== 'GET' && params.body;
13
+ const headers = {
14
+ Authorization: `Bearer ${apiKey}`,
15
+ ...params.headers
16
+ };
17
+ if (hasBody) {
18
+ headers['Content-Type'] = 'application/json';
19
+ }
20
+ const res = await fetch(finalUrl, {
21
+ method,
22
+ headers,
23
+ body: hasBody ? JSON.stringify(params.body) : undefined
24
+ });
25
+ if (!res.ok) {
26
+ const text = await res.text();
27
+ throw new Error(`HTTP ${res.status}: ${text}`);
28
+ }
29
+ return res.json();
15
30
  };
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
31
  }
30
32
 
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', {
33
+ function createClient(config = {}) {
34
+ const fetcher = createFetcher(config);
35
+ return {
36
+ chats: {
37
+ async create (params) {
38
+ const body = {
39
+ message: params.message,
40
+ attachments: params.attachments,
41
+ system: params.system,
42
+ chatPrivacy: params.chatPrivacy,
43
+ projectId: params.projectId,
44
+ modelConfiguration: params.modelConfiguration
45
+ };
46
+ return fetcher(`/chats`, 'POST', {
47
+ body
64
48
  });
65
- },
66
- async getById (params) {
67
- const pathParams = {
68
- chatId: params.chatId
69
- };
70
- return fetcher(`/chats/${pathParams.chatId}`, 'GET', {
49
+ },
50
+ async find (params) {
51
+ const query = params ? Object.fromEntries(Object.entries({
52
+ limit: params.limit,
53
+ offset: params.offset,
54
+ isFavorite: params.isFavorite
55
+ }).filter(([_, value])=>value !== undefined)) : {};
56
+ const hasQuery = Object.keys(query).length > 0;
57
+ return fetcher(`/chats`, 'GET', {
58
+ ...hasQuery ? {
59
+ query
60
+ } : {}
71
61
  });
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', {
62
+ },
63
+ async delete (params) {
64
+ const pathParams = {
65
+ chatId: params.chatId
66
+ };
67
+ return fetcher(`/chats/${pathParams.chatId}`, 'DELETE', {
68
+ pathParams
125
69
  });
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', {
70
+ },
71
+ async getById (params) {
72
+ const pathParams = {
73
+ chatId: params.chatId
74
+ };
75
+ return fetcher(`/chats/${pathParams.chatId}`, 'GET', {
76
+ pathParams
133
77
  });
134
- },
135
- async getMetadata (params) {
136
- const pathParams = {
137
- chatId: params.chatId
138
- };
139
- return fetcher(`/chats/${pathParams.chatId}/metadata`, 'GET', {
78
+ },
79
+ async update (params) {
80
+ const pathParams = {
81
+ chatId: params.chatId
82
+ };
83
+ const body = {
84
+ privacy: params.privacy
85
+ };
86
+ return fetcher(`/chats/${pathParams.chatId}`, 'PATCH', {
87
+ pathParams,
88
+ body
140
89
  });
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', {
90
+ },
91
+ async favorite (params) {
92
+ const pathParams = {
93
+ chatId: params.chatId
94
+ };
95
+ const body = {
96
+ isFavorite: params.isFavorite
97
+ };
98
+ return fetcher(`/chats/${pathParams.chatId}/favorite`, 'PUT', {
99
+ pathParams,
100
+ body
159
101
  });
160
- }
161
- },
162
- projects: {
163
- async getByChatId (params) {
164
- const pathParams = {
165
- chatId: params.chatId
166
- };
167
- return fetcher(`/chats/${pathParams.chatId}/project`, 'GET', {
102
+ },
103
+ async fork (params) {
104
+ const pathParams = {
105
+ chatId: params.chatId
106
+ };
107
+ const body = {
108
+ versionId: params.versionId
109
+ };
110
+ return fetcher(`/chats/${pathParams.chatId}/fork`, 'POST', {
111
+ pathParams,
112
+ body
168
113
  });
114
+ },
115
+ async createMessage (params) {
116
+ const pathParams = {
117
+ chatId: params.chatId
118
+ };
119
+ const body = {
120
+ message: params.message,
121
+ attachments: params.attachments,
122
+ modelConfiguration: params.modelConfiguration
123
+ };
124
+ return fetcher(`/chats/${pathParams.chatId}/messages`, 'POST', {
125
+ pathParams,
126
+ body
127
+ });
128
+ },
129
+ async getMetadata (params) {
130
+ const pathParams = {
131
+ chatId: params.chatId
132
+ };
133
+ return fetcher(`/chats/${pathParams.chatId}/metadata`, 'GET', {
134
+ pathParams
135
+ });
136
+ },
137
+ async resume (params) {
138
+ const pathParams = {
139
+ chatId: params.chatId,
140
+ messageId: params.messageId
141
+ };
142
+ return fetcher(`/chats/${pathParams.chatId}/messages/${pathParams.messageId}/resume`, 'POST', {
143
+ pathParams
144
+ });
145
+ }
169
146
  },
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
- });
147
+ projects: {
148
+ async getByChatId (params) {
149
+ const pathParams = {
150
+ chatId: params.chatId
151
+ };
152
+ return fetcher(`/chats/${pathParams.chatId}/project`, 'GET', {
153
+ pathParams
154
+ });
155
+ },
156
+ async find () {
157
+ return fetcher(`/projects`, 'GET', {});
158
+ },
159
+ async create (params) {
160
+ const body = {
161
+ name: params.name,
162
+ description: params.description,
163
+ icon: params.icon,
164
+ environmentVariables: params.environmentVariables,
165
+ instructions: params.instructions
166
+ };
167
+ return fetcher(`/projects`, 'POST', {
168
+ body
169
+ });
170
+ },
171
+ async assign (params) {
172
+ const pathParams = {
173
+ projectId: params.projectId
174
+ };
175
+ const body = {
176
+ chatId: params.chatId
177
+ };
178
+ return fetcher(`/projects/${pathParams.projectId}/assign`, 'POST', {
179
+ pathParams,
180
+ body
181
+ });
182
+ }
211
183
  },
212
- async findErrors (params) {
213
- const pathParams = {
214
- deploymentId: params.deploymentId
215
- };
216
- return fetcher(`/deployments/${pathParams.deploymentId}/errors`, 'GET', {
184
+ deployments: {
185
+ async findLogs (params) {
186
+ const pathParams = {
187
+ deploymentId: params.deploymentId
188
+ };
189
+ const query = Object.fromEntries(Object.entries({
190
+ since: params.since
191
+ }).filter(([_, value])=>value !== undefined));
192
+ const hasQuery = Object.keys(query).length > 0;
193
+ return fetcher(`/deployments/${pathParams.deploymentId}/logs`, 'GET', {
194
+ pathParams,
195
+ ...hasQuery ? {
196
+ query
197
+ } : {}
217
198
  });
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
- });
199
+ },
200
+ async findErrors (params) {
201
+ const pathParams = {
202
+ deploymentId: params.deploymentId
203
+ };
204
+ return fetcher(`/deployments/${pathParams.deploymentId}/errors`, 'GET', {
205
+ pathParams
206
+ });
207
+ }
208
+ },
209
+ integrations: {
210
+ vercel: {
211
+ projects: {
212
+ async find () {
213
+ return fetcher(`/integrations/vercel/projects`, 'GET', {});
214
+ },
215
+ async create (params) {
216
+ const body = {
217
+ projectId: params.projectId,
218
+ name: params.name
219
+ };
220
+ return fetcher(`/integrations/vercel/projects`, 'POST', {
221
+ body
222
+ });
223
+ }
234
224
  }
235
225
  }
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
226
  },
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
- });
227
+ rateLimits: {
228
+ async find (params) {
229
+ const query = params ? Object.fromEntries(Object.entries({
230
+ scope: params.scope
231
+ }).filter(([_, value])=>value !== undefined)) : {};
232
+ const hasQuery = Object.keys(query).length > 0;
233
+ return fetcher(`/rate-limits`, 'GET', {
234
+ ...hasQuery ? {
235
+ query
236
+ } : {}
237
+ });
238
+ }
265
239
  },
266
- async getPlan () {
267
- return fetcher(`/user/plan`, 'GET', {});
240
+ user: {
241
+ async get () {
242
+ return fetcher(`/user`, 'GET', {});
243
+ },
244
+ async getBilling (params) {
245
+ const query = params ? Object.fromEntries(Object.entries({
246
+ scope: params.scope
247
+ }).filter(([_, value])=>value !== undefined)) : {};
248
+ const hasQuery = Object.keys(query).length > 0;
249
+ return fetcher(`/user/billing`, 'GET', {
250
+ ...hasQuery ? {
251
+ query
252
+ } : {}
253
+ });
254
+ },
255
+ async getPlan () {
256
+ return fetcher(`/user/plan`, 'GET', {});
257
+ },
258
+ async getScopes () {
259
+ return fetcher(`/user/scopes`, 'GET', {});
260
+ }
268
261
  },
269
- async getScopes () {
270
- return fetcher(`/user/scopes`, 'GET', {});
262
+ notifications: {
263
+ deviceToken: {
264
+ deviceId: {
265
+ async delete (params) {
266
+ const pathParams = {
267
+ deviceId: params.deviceId
268
+ };
269
+ return fetcher(`/notifications/device-token/${pathParams.deviceId}`, 'DELETE', {
270
+ pathParams
271
+ });
272
+ }
273
+ }
274
+ }
271
275
  }
272
- }
273
- };
276
+ };
277
+ }
278
+ // Default client for backward compatibility
279
+ const v0 = createClient();
274
280
 
281
+ exports.createClient = createClient;
275
282
  exports.v0 = v0;