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/README.md +52 -18
- package/dist/index.cjs +259 -225
- package/dist/index.d.ts +102 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +259 -226
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -1,246 +1,279 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
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
|
|
5
|
+
throw new Error('API key is required. Provide it via config.apiKey or V0_API_KEY environment variable');
|
|
8
6
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
238
|
-
|
|
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
|
-
|
|
241
|
-
|
|
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
|
|
4
|
-
"description": "TypeScript SDK for the v0
|
|
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",
|