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