@aviaryhq/cloudglue-js 0.4.11 → 0.4.13
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/generated/Chat.d.ts +8 -8
- package/dist/generated/Chat.js +30 -30
- package/dist/generated/Collections.d.ts +25 -23
- package/dist/generated/Collections.js +266 -264
- package/dist/generated/Describe.d.ts +7 -7
- package/dist/generated/Describe.js +58 -58
- package/dist/generated/Extract.d.ts +6 -6
- package/dist/generated/Extract.js +52 -52
- package/dist/generated/Face_Detection.d.ts +6 -6
- package/dist/generated/Face_Detection.js +25 -25
- package/dist/generated/Face_Match.d.ts +6 -6
- package/dist/generated/Face_Match.js +26 -26
- package/dist/generated/Files.d.ts +1009 -10
- package/dist/generated/Files.js +247 -115
- package/dist/generated/Frames.d.ts +2 -2
- package/dist/generated/Frames.js +17 -17
- package/dist/generated/Search.d.ts +212 -19
- package/dist/generated/Search.js +143 -30
- package/dist/generated/Segmentations.d.ts +208 -2
- package/dist/generated/Segmentations.js +34 -29
- package/dist/generated/Segments.d.ts +13 -13
- package/dist/generated/Segments.js +49 -49
- package/dist/generated/Tags.d.ts +660 -0
- package/dist/generated/Tags.js +160 -0
- package/dist/generated/Transcribe.d.ts +7 -7
- package/dist/generated/Transcribe.js +46 -46
- package/dist/generated/Webhooks.d.ts +5 -5
- package/dist/generated/Webhooks.js +61 -61
- package/dist/generated/common.d.ts +391 -11
- package/dist/generated/common.js +63 -28
- package/dist/generated/index.d.ts +14 -13
- package/dist/generated/index.js +3 -1
- package/dist/src/api/chat-completion.api.d.ts +38 -0
- package/dist/src/api/chat-completion.api.js +15 -0
- package/dist/src/api/collections.api.d.ts +666 -0
- package/dist/src/api/collections.api.js +134 -0
- package/dist/src/api/describe.api.d.ts +153 -0
- package/dist/src/api/describe.api.js +57 -0
- package/dist/src/api/extract.api.d.ts +144 -0
- package/dist/src/api/extract.api.js +55 -0
- package/dist/src/api/face-detection.api.d.ts +77 -0
- package/dist/src/api/face-detection.api.js +41 -0
- package/dist/src/api/face-match.api.d.ts +94 -0
- package/dist/src/api/face-match.api.js +41 -0
- package/dist/src/api/files.api.d.ts +705 -0
- package/dist/src/api/files.api.js +146 -0
- package/dist/src/api/frame-extraction.api.d.ts +264 -0
- package/dist/src/api/frame-extraction.api.js +37 -0
- package/dist/src/api/search.api.d.ts +316 -0
- package/dist/src/api/search.api.js +22 -0
- package/dist/src/api/segmentations.api.d.ts +395 -0
- package/dist/src/api/segmentations.api.js +36 -0
- package/dist/src/api/segments.api.d.ts +141 -0
- package/dist/src/api/segments.api.js +40 -0
- package/dist/src/api/tags.api.d.ts +71 -0
- package/dist/src/api/tags.api.js +31 -0
- package/dist/src/api/transcribe.api.d.ts +150 -0
- package/dist/src/api/transcribe.api.js +65 -0
- package/dist/src/api/webhooks.api.d.ts +69 -0
- package/dist/src/api/webhooks.api.js +28 -0
- package/dist/src/client.d.ts +20 -2967
- package/dist/src/client.js +55 -643
- package/dist/src/error.d.ts +7 -0
- package/dist/src/error.js +14 -0
- package/dist/src/types.d.ts +20 -8
- package/package.json +2 -1
package/dist/src/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CloudGlue =
|
|
3
|
+
exports.CloudGlue = void 0;
|
|
4
4
|
const Files_1 = require("../generated/Files");
|
|
5
5
|
const Collections_1 = require("../generated/Collections");
|
|
6
6
|
const Chat_1 = require("../generated/Chat");
|
|
@@ -14,644 +14,39 @@ const Webhooks_1 = require("../generated/Webhooks");
|
|
|
14
14
|
const Frames_1 = require("../generated/Frames");
|
|
15
15
|
const Face_Detection_1 = require("../generated/Face_Detection");
|
|
16
16
|
const Face_Match_1 = require("../generated/Face_Match");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
async listFiles(params = {}) {
|
|
34
|
-
const { filter, ...otherParams } = params;
|
|
35
|
-
// Convert filter object to JSON string if provided
|
|
36
|
-
const queries = { ...otherParams };
|
|
37
|
-
if (filter) {
|
|
38
|
-
try {
|
|
39
|
-
queries.filter = JSON.stringify(filter);
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
throw new CloudGlueError(`Failed to serialize filter object: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return this.api.listFiles({ queries });
|
|
46
|
-
}
|
|
47
|
-
async uploadFile(params) {
|
|
48
|
-
// File uploads require special handling for multipart/form-data that the generated Zodios client doesn't handle automatically.
|
|
49
|
-
// We need to:
|
|
50
|
-
// 1. Create a FormData object and append the file with the correct field name
|
|
51
|
-
// 2. JSON stringify the metadata if present
|
|
52
|
-
// 3. Set the correct Content-Type header
|
|
53
|
-
// This is why we use axios directly instead of the generated client method.
|
|
54
|
-
const formData = new FormData();
|
|
55
|
-
formData.append("file", params.file);
|
|
56
|
-
// Add metadata if provided
|
|
57
|
-
if (params.metadata) {
|
|
58
|
-
try {
|
|
59
|
-
formData.append("metadata", JSON.stringify(params.metadata));
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
throw new CloudGlueError(`Failed to serialize metadata object: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (params.enable_segment_thumbnails !== undefined) {
|
|
66
|
-
formData.append("enable_segment_thumbnails", params.enable_segment_thumbnails.toString());
|
|
67
|
-
}
|
|
68
|
-
// Use axios directly to bypass Zodios validation
|
|
69
|
-
return this.api.axios({
|
|
70
|
-
method: "post",
|
|
71
|
-
url: "/files",
|
|
72
|
-
data: formData,
|
|
73
|
-
headers: {
|
|
74
|
-
"Content-Type": "multipart/form-data",
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
async getFile(fileId) {
|
|
79
|
-
return this.api.getFile({ params: { file_id: fileId } });
|
|
80
|
-
}
|
|
81
|
-
async deleteFile(fileId) {
|
|
82
|
-
return this.api.deleteFile(undefined, {
|
|
83
|
-
params: { file_id: fileId },
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
async updateFile(fileId, params) {
|
|
87
|
-
return this.api.updateFile({ ...params, filename: params.filename ?? undefined }, { params: { file_id: fileId } });
|
|
88
|
-
}
|
|
89
|
-
async listFileSegmentations(fileId, params = {}) {
|
|
90
|
-
return this.api.listFileSegmentations({
|
|
91
|
-
params: { file_id: fileId },
|
|
92
|
-
queries: params,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Get thumbnails for a file. If a segmentationId is provided, the thumbnails will be for a specific segmentation.
|
|
97
|
-
* @param fileId - The ID of the file
|
|
98
|
-
* @param params - Optional parameters
|
|
99
|
-
* @returns The thumbnails for the file
|
|
100
|
-
*/
|
|
101
|
-
async getFileThumbnails(fileId, params = {}) {
|
|
102
|
-
return this.api.getThumbnails({
|
|
103
|
-
params: { file_id: fileId },
|
|
104
|
-
queries: {
|
|
105
|
-
...params,
|
|
106
|
-
is_default: params.isDefault ?? false,
|
|
107
|
-
segmentation_id: params.segmentationId ?? undefined,
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
async createFileSegmentation(fileId, params) {
|
|
112
|
-
return this.api.createFileSegmentation(params, {
|
|
113
|
-
params: { file_id: fileId },
|
|
114
|
-
body: params,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
async createFileFrameExtraction(fileId, params) {
|
|
118
|
-
return this.api.createFileFrameExtraction(params, {
|
|
119
|
-
params: { file_id: fileId }
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Waits for a file to finish processing by polling the getFile endpoint until the file
|
|
124
|
-
* reaches a terminal state (completed, failed, or not_applicable) or until maxAttempts is reached.
|
|
125
|
-
*
|
|
126
|
-
* @param fileId - The ID of the file to wait for
|
|
127
|
-
* @param options - Optional configuration for polling behavior
|
|
128
|
-
* @returns The final file object
|
|
129
|
-
* @throws {CloudGlueError} If the file fails to process or maxAttempts is reached
|
|
130
|
-
*/
|
|
131
|
-
async waitForReady(fileId, options = {}) {
|
|
132
|
-
const { pollingInterval = 5000, maxAttempts = 36 } = options;
|
|
133
|
-
let attempts = 0;
|
|
134
|
-
while (attempts < maxAttempts) {
|
|
135
|
-
const file = await this.getFile(fileId);
|
|
136
|
-
// If we've reached a terminal state, return the file
|
|
137
|
-
if (["completed", "failed", "not_applicable"].includes(file.status)) {
|
|
138
|
-
if (file.status === "failed") {
|
|
139
|
-
throw new CloudGlueError(`File processing failed: ${fileId}`);
|
|
140
|
-
}
|
|
141
|
-
return file;
|
|
142
|
-
}
|
|
143
|
-
// Wait for the polling interval before trying again
|
|
144
|
-
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
145
|
-
attempts++;
|
|
146
|
-
}
|
|
147
|
-
throw new CloudGlueError(`Timeout waiting for file ${fileId} to process after ${maxAttempts} attempts`);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
class EnhancedCollectionsApi {
|
|
151
|
-
constructor(api) {
|
|
152
|
-
this.api = api;
|
|
153
|
-
}
|
|
154
|
-
async listCollections(params = {}) {
|
|
155
|
-
return this.api.listCollections({ queries: params });
|
|
156
|
-
}
|
|
157
|
-
async createCollection(params) {
|
|
158
|
-
return this.api.createCollection(params);
|
|
159
|
-
}
|
|
160
|
-
async getCollection(collectionId) {
|
|
161
|
-
return this.api.getCollection({
|
|
162
|
-
params: { collection_id: collectionId },
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
async deleteCollection(collectionId) {
|
|
166
|
-
return this.api.deleteCollection(undefined, { params: { collection_id: collectionId } });
|
|
167
|
-
}
|
|
168
|
-
async updateCollection(collectionId, params) {
|
|
169
|
-
return this.api.updateCollection(params, { params: { collection_id: collectionId } });
|
|
170
|
-
}
|
|
171
|
-
async addVideoByUrl({ collectionId, url, params }) {
|
|
172
|
-
return this.api.addVideo({ url, ...params }, { params: { collection_id: collectionId, ...params } });
|
|
173
|
-
}
|
|
174
|
-
async addVideo(collectionId, fileId, params = {}) {
|
|
175
|
-
return this.api.addVideo({ file_id: fileId, ...params }, { params: { collection_id: collectionId, ...params } });
|
|
176
|
-
}
|
|
177
|
-
async listVideos(collectionId, params = {}) {
|
|
178
|
-
const { filter, ...otherParams } = params;
|
|
179
|
-
// Convert filter object to JSON string if provided
|
|
180
|
-
const queries = { ...otherParams };
|
|
181
|
-
if (filter) {
|
|
182
|
-
try {
|
|
183
|
-
queries.filter = JSON.stringify(filter);
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
throw new CloudGlueError(`Failed to serialize filter object: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return this.api.listVideos({
|
|
190
|
-
params: { collection_id: collectionId },
|
|
191
|
-
queries,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
async getVideo(collectionId, fileId) {
|
|
195
|
-
return this.api.getVideo({
|
|
196
|
-
params: { collection_id: collectionId, file_id: fileId },
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
async deleteVideo(collectionId, fileId) {
|
|
200
|
-
return this.api.deleteVideo(undefined, { params: { collection_id: collectionId, file_id: fileId } });
|
|
201
|
-
}
|
|
202
|
-
async getEntities(collectionId, fileId, params = {}) {
|
|
203
|
-
return this.api.getEntities({
|
|
204
|
-
params: { collection_id: collectionId, file_id: fileId },
|
|
205
|
-
queries: params
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
async getTranscripts(collectionId, fileId, options = {}) {
|
|
209
|
-
return this.api.getTranscripts({
|
|
210
|
-
params: { collection_id: collectionId, file_id: fileId },
|
|
211
|
-
queries: { ...options },
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
async listEntities(collectionId, params = {}) {
|
|
215
|
-
return this.api.listCollectionEntities({
|
|
216
|
-
params: { collection_id: collectionId },
|
|
217
|
-
queries: params,
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
async listRichTranscripts(collectionId, params = {}) {
|
|
221
|
-
return this.api.listCollectionRichTranscripts({
|
|
222
|
-
params: { collection_id: collectionId },
|
|
223
|
-
queries: params,
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
async getMediaDescriptions(collectionId, fileId, options = {}) {
|
|
227
|
-
return this.api.getMediaDescriptions({
|
|
228
|
-
params: { collection_id: collectionId, file_id: fileId },
|
|
229
|
-
queries: { ...options },
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
async getFaceDetections(collectionId, fileId, params = {}) {
|
|
233
|
-
return this.api.getFaceDetections({
|
|
234
|
-
params: { collection_id: collectionId, file_id: fileId },
|
|
235
|
-
queries: params
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
async listMediaDescriptions(collectionId, params = {}) {
|
|
239
|
-
return this.api.listCollectionMediaDescriptions({
|
|
240
|
-
params: { collection_id: collectionId },
|
|
241
|
-
queries: params,
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Waits for a video in a collection to be ready by polling the getVideo endpoint until
|
|
246
|
-
* the video reaches a terminal state (completed, failed, or not_applicable) or until maxAttempts is reached.
|
|
247
|
-
*
|
|
248
|
-
* @param collectionId - The ID of the collection containing the video
|
|
249
|
-
* @param fileId - The ID of the video file to wait for
|
|
250
|
-
* @param options - Optional configuration for polling behavior
|
|
251
|
-
* @returns The final collection file object
|
|
252
|
-
* @throws {CloudGlueError} If the video fails to process or maxAttempts is reached
|
|
253
|
-
*/
|
|
254
|
-
async waitForReady(collectionId, fileId, options = {}) {
|
|
255
|
-
const { pollingInterval = 5000, maxAttempts = 36 } = options;
|
|
256
|
-
let attempts = 0;
|
|
257
|
-
while (attempts < maxAttempts) {
|
|
258
|
-
const video = await this.getVideo(collectionId, fileId);
|
|
259
|
-
// If we've reached a terminal state, return the video
|
|
260
|
-
if (["completed", "failed", "not_applicable"].includes(video.status)) {
|
|
261
|
-
if (video.status === "failed") {
|
|
262
|
-
throw new CloudGlueError(`Video processing failed: ${fileId} in collection ${collectionId}`);
|
|
263
|
-
}
|
|
264
|
-
return video;
|
|
265
|
-
}
|
|
266
|
-
// Wait for the polling interval before trying again
|
|
267
|
-
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
268
|
-
attempts++;
|
|
269
|
-
}
|
|
270
|
-
throw new CloudGlueError(`Timeout waiting for video ${fileId} in collection ${collectionId} to process after ${maxAttempts} attempts`);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
class EnhancedChatApi {
|
|
274
|
-
constructor(api) {
|
|
275
|
-
this.api = api;
|
|
276
|
-
}
|
|
277
|
-
async createCompletion(params) {
|
|
278
|
-
return this.api.createCompletion({
|
|
279
|
-
model: params.model || "nimbus-001",
|
|
280
|
-
...params,
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* @deprecated
|
|
286
|
-
*/
|
|
287
|
-
class EnhancedTranscribeApi {
|
|
288
|
-
constructor(api) {
|
|
289
|
-
this.api = api;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* @deprecated use createDescribe instead
|
|
293
|
-
*/
|
|
294
|
-
async createTranscribe(url, options = {}) {
|
|
295
|
-
return this.api.createTranscribe({
|
|
296
|
-
url,
|
|
297
|
-
...options,
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* @deprecated use getDescribe instead
|
|
302
|
-
*/
|
|
303
|
-
async getTranscribe(jobId, options = {}) {
|
|
304
|
-
return this.api.getTranscribe({
|
|
305
|
-
params: { job_id: jobId },
|
|
306
|
-
queries: { response_format: options.response_format },
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* @deprecated use listDescribes instead
|
|
311
|
-
*/
|
|
312
|
-
async listTranscribes(params = {}) {
|
|
313
|
-
return this.api.listTranscribes({ queries: params });
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Waits for a transcription job to be ready by polling the getTranscribe endpoint until
|
|
317
|
-
* the job reaches a terminal state (completed, failed, or not_applicable) or until maxAttempts is reached.
|
|
318
|
-
*
|
|
319
|
-
* @param jobId - The ID of the transcription job to wait for
|
|
320
|
-
* @param options - Optional configuration for polling behavior and response format
|
|
321
|
-
* @returns The final transcription job object
|
|
322
|
-
* @throws {CloudGlueError} If the job fails to process or maxAttempts is reached
|
|
323
|
-
* @deprecated
|
|
324
|
-
*/
|
|
325
|
-
async waitForReady(jobId, options = {}) {
|
|
326
|
-
const { pollingInterval = 5000, maxAttempts = 36, response_format, } = options;
|
|
327
|
-
let attempts = 0;
|
|
328
|
-
while (attempts < maxAttempts) {
|
|
329
|
-
const job = await this.getTranscribe(jobId, { response_format });
|
|
330
|
-
// If we've reached a terminal state, return the job
|
|
331
|
-
if (["completed", "failed", "not_applicable"].includes(job.status)) {
|
|
332
|
-
if (job.status === "failed") {
|
|
333
|
-
throw new CloudGlueError(`Transcription job failed: ${jobId}`);
|
|
334
|
-
}
|
|
335
|
-
return job;
|
|
336
|
-
}
|
|
337
|
-
// Wait for the polling interval before trying again
|
|
338
|
-
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
339
|
-
attempts++;
|
|
340
|
-
}
|
|
341
|
-
throw new CloudGlueError(`Timeout waiting for transcription job ${jobId} to process after ${maxAttempts} attempts`);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
class EnhancedExtractApi {
|
|
345
|
-
constructor(api) {
|
|
346
|
-
this.api = api;
|
|
347
|
-
}
|
|
348
|
-
async createExtract(url, options) {
|
|
349
|
-
return this.api.createExtract({
|
|
350
|
-
url,
|
|
351
|
-
...options,
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
async getExtract(jobId, params = {}) {
|
|
355
|
-
return this.api.getExtract({
|
|
356
|
-
params: { job_id: jobId },
|
|
357
|
-
queries: params
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
async listExtracts(params = {}) {
|
|
361
|
-
return this.api.listExtracts({ queries: params });
|
|
362
|
-
}
|
|
363
|
-
async deleteExtract(jobId) {
|
|
364
|
-
return this.api.deleteExtract(undefined, { params: { job_id: jobId } });
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Waits for an extraction job to be ready by polling the getExtract endpoint until
|
|
368
|
-
* the job reaches a terminal state (completed, failed, or not_applicable) or until maxAttempts is reached.
|
|
369
|
-
*
|
|
370
|
-
* @param jobId - The ID of the extraction job to wait for
|
|
371
|
-
* @param options - Optional configuration for polling behavior
|
|
372
|
-
* @returns The final extraction job object
|
|
373
|
-
* @throws {CloudGlueError} If the job fails to process or maxAttempts is reached
|
|
374
|
-
*/
|
|
375
|
-
async waitForReady(jobId, options = {}) {
|
|
376
|
-
const { pollingInterval = 5000, maxAttempts = 36 } = options;
|
|
377
|
-
let attempts = 0;
|
|
378
|
-
while (attempts < maxAttempts) {
|
|
379
|
-
const job = await this.getExtract(jobId);
|
|
380
|
-
// If we've reached a terminal state, return the job
|
|
381
|
-
if (["completed", "failed", "not_applicable"].includes(job.status)) {
|
|
382
|
-
if (job.status === "failed") {
|
|
383
|
-
throw new CloudGlueError(`Extraction job failed: ${jobId}`);
|
|
384
|
-
}
|
|
385
|
-
return job;
|
|
386
|
-
}
|
|
387
|
-
// Wait for the polling interval before trying again
|
|
388
|
-
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
389
|
-
attempts++;
|
|
390
|
-
}
|
|
391
|
-
throw new CloudGlueError(`Timeout waiting for extraction job ${jobId} to process after ${maxAttempts} attempts`);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
class EnhancedSegmentationsApi {
|
|
395
|
-
constructor(api) {
|
|
396
|
-
this.api = api;
|
|
397
|
-
}
|
|
398
|
-
async getSegmentation(segmentationId, params = {}) {
|
|
399
|
-
return this.api.getSegmentation({
|
|
400
|
-
params: { segmentation_id: segmentationId },
|
|
401
|
-
queries: params,
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
async deleteSegmentation(segmentationId) {
|
|
405
|
-
return this.api.deleteSegmentation(undefined, {
|
|
406
|
-
params: { segmentation_id: segmentationId },
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
/**
|
|
410
|
-
* Get thumbnails for a specific segmentation
|
|
411
|
-
* @param segmentationId - The ID of the segmentation
|
|
412
|
-
* @param params - Optional parameters
|
|
413
|
-
* @returns The thumbnails for the segmentation
|
|
414
|
-
*/
|
|
415
|
-
async getSegmentationThumbnails(segmentationId, params = {}) {
|
|
416
|
-
return this.api.getSegmentationThumbnails({
|
|
417
|
-
params: { segmentation_id: segmentationId },
|
|
418
|
-
queries: {
|
|
419
|
-
...params,
|
|
420
|
-
segment_ids: params.segment_ids?.join(","),
|
|
421
|
-
},
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
class EnhancedSearchApi {
|
|
426
|
-
constructor(api) {
|
|
427
|
-
this.api = api;
|
|
428
|
-
}
|
|
429
|
-
async searchContent(params) {
|
|
430
|
-
return this.api.searchContent(params);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
class EnhancedDescribeApi {
|
|
434
|
-
constructor(api) {
|
|
435
|
-
this.api = api;
|
|
436
|
-
}
|
|
437
|
-
async createDescribe(url, options = {}) {
|
|
438
|
-
return this.api.createDescribe({
|
|
439
|
-
url,
|
|
440
|
-
...options,
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
async getDescribe(jobId, options = {
|
|
444
|
-
response_format: "json",
|
|
445
|
-
}) {
|
|
446
|
-
return this.api.getDescribe({
|
|
447
|
-
params: { job_id: jobId },
|
|
448
|
-
queries: { ...options },
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
async listDescribes(params = {}) {
|
|
452
|
-
return this.api.listDescribes({ queries: params });
|
|
453
|
-
}
|
|
454
|
-
async deleteDescribe(jobId) {
|
|
455
|
-
return this.api.deleteDescribe(undefined, { params: { job_id: jobId } });
|
|
456
|
-
}
|
|
457
|
-
/**
|
|
458
|
-
* Waits for a description job to be ready by polling the getDescribe endpoint until
|
|
459
|
-
* the job reaches a terminal state (completed, failed, or not_applicable) or until maxAttempts is reached.
|
|
460
|
-
*
|
|
461
|
-
* @param jobId - The ID of the description job to wait for
|
|
462
|
-
* @param options - Optional configuration for polling behavior and response format
|
|
463
|
-
* @returns The final description job object
|
|
464
|
-
* @throws {CloudGlueError} If the job fails to process or maxAttempts is reached
|
|
465
|
-
*/
|
|
466
|
-
async waitForReady(jobId, options = {}) {
|
|
467
|
-
const { pollingInterval = 5000, maxAttempts = 36, response_format, } = options;
|
|
468
|
-
let attempts = 0;
|
|
469
|
-
while (attempts < maxAttempts) {
|
|
470
|
-
const job = await this.getDescribe(jobId, { response_format });
|
|
471
|
-
// If we've reached a terminal state, return the job
|
|
472
|
-
if (["completed", "failed", "not_applicable"].includes(job.status)) {
|
|
473
|
-
if (job.status === "failed") {
|
|
474
|
-
throw new CloudGlueError(`Description job failed: ${jobId}`);
|
|
475
|
-
}
|
|
476
|
-
return job;
|
|
477
|
-
}
|
|
478
|
-
// Wait for the polling interval before trying again
|
|
479
|
-
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
480
|
-
attempts++;
|
|
481
|
-
}
|
|
482
|
-
throw new CloudGlueError(`Timeout waiting for description job ${jobId} to process after ${maxAttempts} attempts`);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
class EnhancedSegmentsApi {
|
|
486
|
-
constructor(api) {
|
|
487
|
-
this.api = api;
|
|
488
|
-
}
|
|
489
|
-
async listSegmentJobs(data) {
|
|
490
|
-
return this.api.listSegments({ queries: data });
|
|
491
|
-
}
|
|
492
|
-
async getSegmentJob(jobId) {
|
|
493
|
-
return this.api.getSegments({ params: { job_id: jobId } });
|
|
494
|
-
}
|
|
495
|
-
async createSegmentJob(params) {
|
|
496
|
-
return this.api.createSegments(params);
|
|
497
|
-
}
|
|
498
|
-
async deleteSegmentJob(jobId) {
|
|
499
|
-
return this.api.deleteSegments(undefined, { params: { job_id: jobId } });
|
|
500
|
-
}
|
|
501
|
-
async waitForReady(jobId, options = {}) {
|
|
502
|
-
const { pollingInterval = 5000, maxAttempts = 36, } = options;
|
|
503
|
-
let attempts = 0;
|
|
504
|
-
while (attempts < maxAttempts) {
|
|
505
|
-
const job = await this.getSegmentJob(jobId);
|
|
506
|
-
// If we've reached a terminal state, return the job
|
|
507
|
-
if (["completed", "failed", "not_applicable"].includes(job.status)) {
|
|
508
|
-
if (job.status === "failed") {
|
|
509
|
-
throw new CloudGlueError(`Segment job failed: ${jobId}`);
|
|
510
|
-
}
|
|
511
|
-
return job;
|
|
512
|
-
}
|
|
513
|
-
// Wait for the polling interval before trying again
|
|
514
|
-
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
515
|
-
attempts++;
|
|
516
|
-
}
|
|
517
|
-
throw new CloudGlueError(`Timeout waiting for segment job ${jobId} to process after ${maxAttempts} attempts`);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
class EnhancedWebhooksApi {
|
|
521
|
-
constructor(api) {
|
|
522
|
-
this.api = api;
|
|
523
|
-
}
|
|
524
|
-
async listWebhooks(params = {}) {
|
|
525
|
-
return this.api.listWebhooks({ queries: params });
|
|
526
|
-
}
|
|
527
|
-
async getWebhook(webhookId) {
|
|
528
|
-
return this.api.getWebhookById({ params: { webhook_id: webhookId } });
|
|
529
|
-
}
|
|
530
|
-
async createWebhook(params) {
|
|
531
|
-
return this.api.createWebhook(params);
|
|
532
|
-
}
|
|
533
|
-
async updateWebhook(webhookId, params) {
|
|
534
|
-
return this.api.updateWebhook(params, { params: { webhook_id: webhookId, } });
|
|
535
|
-
}
|
|
536
|
-
async deleteWebhook(webhookId) {
|
|
537
|
-
return this.api.deleteWebhook(undefined, { params: { webhook_id: webhookId } });
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
class EnhancedFramesApi {
|
|
541
|
-
constructor(api) {
|
|
542
|
-
this.api = api;
|
|
543
|
-
}
|
|
544
|
-
async getFrameExtraction(frameExtractionId, params = {}) {
|
|
545
|
-
return this.api.getFrameExtraction({
|
|
546
|
-
params: { frame_extraction_id: frameExtractionId },
|
|
547
|
-
queries: params
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
async deleteFrameExtraction(frameExtractionId) {
|
|
551
|
-
return this.api.deleteFrameExtraction(undefined, { params: { frame_extraction_id: frameExtractionId } });
|
|
552
|
-
}
|
|
553
|
-
async waitForReady(frameExtractionId, options = {}) {
|
|
554
|
-
const { pollingInterval = 5000, maxAttempts = 36 } = options;
|
|
555
|
-
let attempts = 0;
|
|
556
|
-
while (attempts < maxAttempts) {
|
|
557
|
-
const job = await this.getFrameExtraction(frameExtractionId);
|
|
558
|
-
if (["completed", "failed"].includes(job.status)) {
|
|
559
|
-
if (job.status === "failed") {
|
|
560
|
-
throw new CloudGlueError(`Frame extraction job failed: ${frameExtractionId}`);
|
|
561
|
-
}
|
|
562
|
-
return job;
|
|
563
|
-
}
|
|
564
|
-
await new Promise(resolve => setTimeout(resolve, pollingInterval));
|
|
565
|
-
attempts++;
|
|
566
|
-
}
|
|
567
|
-
throw new CloudGlueError(`Frame extraction job did not complete within ${maxAttempts * pollingInterval / 1000} seconds: ${frameExtractionId}`);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
class EnhancedFaceDetectionApi {
|
|
571
|
-
constructor(api) {
|
|
572
|
-
this.api = api;
|
|
573
|
-
}
|
|
574
|
-
async createFaceDetection(params) {
|
|
575
|
-
return this.api.createFaceDetection(params);
|
|
576
|
-
}
|
|
577
|
-
async getFaceDetection(faceDetectionId, params = {}) {
|
|
578
|
-
const { limit, offset } = params;
|
|
579
|
-
return this.api.getFaceDetection({
|
|
580
|
-
params: { face_detection_id: faceDetectionId },
|
|
581
|
-
queries: { limit, offset }
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
async deleteFaceDetection(faceDetectionId) {
|
|
585
|
-
return this.api.deleteFaceDetection(undefined, { params: { face_detection_id: faceDetectionId } });
|
|
586
|
-
}
|
|
587
|
-
async waitForReady(faceDetectionId, options = {}) {
|
|
588
|
-
const { pollingInterval = 5000, maxAttempts = 36 } = options;
|
|
589
|
-
let attempts = 0;
|
|
590
|
-
while (attempts < maxAttempts) {
|
|
591
|
-
const job = await this.getFaceDetection(faceDetectionId);
|
|
592
|
-
if (["completed", "failed"].includes(job.status)) {
|
|
593
|
-
if (job.status === "failed") {
|
|
594
|
-
throw new CloudGlueError(`Face detection job failed: ${faceDetectionId}`);
|
|
595
|
-
}
|
|
596
|
-
return job;
|
|
597
|
-
}
|
|
598
|
-
await new Promise(resolve => setTimeout(resolve, pollingInterval));
|
|
599
|
-
attempts++;
|
|
600
|
-
}
|
|
601
|
-
throw new CloudGlueError(`Face detection job did not complete within ${maxAttempts * pollingInterval / 1000} seconds: ${faceDetectionId}`);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
class EnhancedFaceMatchApi {
|
|
605
|
-
constructor(api) {
|
|
606
|
-
this.api = api;
|
|
607
|
-
}
|
|
608
|
-
async createFaceMatch(params) {
|
|
609
|
-
return this.api.createFaceMatch(params);
|
|
610
|
-
}
|
|
611
|
-
async getFaceMatch(faceMatchId, params = {}) {
|
|
612
|
-
const { limit, offset } = params;
|
|
613
|
-
return this.api.getFaceMatch({
|
|
614
|
-
params: { face_match_id: faceMatchId },
|
|
615
|
-
queries: { limit, offset }
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
async deleteFaceMatch(faceMatchId) {
|
|
619
|
-
return this.api.deleteFaceMatch(undefined, { params: { face_match_id: faceMatchId } });
|
|
620
|
-
}
|
|
621
|
-
async waitForReady(faceMatchId, options = {}) {
|
|
622
|
-
const { pollingInterval = 5000, maxAttempts = 36 } = options;
|
|
623
|
-
let attempts = 0;
|
|
624
|
-
while (attempts < maxAttempts) {
|
|
625
|
-
const job = await this.getFaceMatch(faceMatchId);
|
|
626
|
-
if (["completed", "failed"].includes(job.status)) {
|
|
627
|
-
if (job.status === "failed") {
|
|
628
|
-
throw new CloudGlueError(`Face match job failed: ${faceMatchId}`);
|
|
629
|
-
}
|
|
630
|
-
return job;
|
|
631
|
-
}
|
|
632
|
-
await new Promise(resolve => setTimeout(resolve, pollingInterval));
|
|
633
|
-
attempts++;
|
|
634
|
-
}
|
|
635
|
-
throw new CloudGlueError(`Face match job did not complete within ${maxAttempts * pollingInterval / 1000} seconds: ${faceMatchId}`);
|
|
636
|
-
}
|
|
637
|
-
}
|
|
17
|
+
const Tags_1 = require("../generated/Tags");
|
|
18
|
+
const webhooks_api_1 = require("./api/webhooks.api");
|
|
19
|
+
const tags_api_1 = require("./api/tags.api");
|
|
20
|
+
const error_1 = require("./error");
|
|
21
|
+
const files_api_1 = require("./api/files.api");
|
|
22
|
+
const describe_api_1 = require("./api/describe.api");
|
|
23
|
+
const extract_api_1 = require("./api/extract.api");
|
|
24
|
+
const face_detection_api_1 = require("./api/face-detection.api");
|
|
25
|
+
const face_match_api_1 = require("./api/face-match.api");
|
|
26
|
+
const frame_extraction_api_1 = require("./api/frame-extraction.api");
|
|
27
|
+
const search_api_1 = require("./api/search.api");
|
|
28
|
+
const segmentations_api_1 = require("./api/segmentations.api");
|
|
29
|
+
const segments_api_1 = require("./api/segments.api");
|
|
30
|
+
const transcribe_api_1 = require("./api/transcribe.api");
|
|
31
|
+
const chat_completion_api_1 = require("./api/chat-completion.api");
|
|
32
|
+
const collections_api_1 = require("./api/collections.api");
|
|
638
33
|
/**
|
|
639
34
|
* Main CloudGlue client class that provides access to all API functionality
|
|
640
35
|
* through enhanced, user-friendly interfaces
|
|
641
36
|
*/
|
|
642
37
|
class CloudGlue {
|
|
643
38
|
constructor(config = {}) {
|
|
644
|
-
this.apiKey = config.apiKey || process.env.CLOUDGLUE_API_KEY ||
|
|
645
|
-
this.baseUrl = config.baseUrl ||
|
|
39
|
+
this.apiKey = config.apiKey || process.env.CLOUDGLUE_API_KEY || '';
|
|
40
|
+
this.baseUrl = config.baseUrl || 'https://api.cloudglue.dev/v1';
|
|
646
41
|
this.timeout = config.timeout || undefined;
|
|
647
42
|
if (!this.apiKey) {
|
|
648
|
-
throw new Error(
|
|
43
|
+
throw new Error('API key is required. Please provide an API key via constructor or CLOUDGLUE_API_KEY environment variable.');
|
|
649
44
|
}
|
|
650
45
|
const axiosConfig = {
|
|
651
46
|
headers: {
|
|
652
47
|
Authorization: `Bearer ${this.apiKey}`,
|
|
653
48
|
'x-sdk-client': 'cloudglue-js',
|
|
654
|
-
'x-sdk-version': '0.4.
|
|
49
|
+
'x-sdk-version': '0.4.13',
|
|
655
50
|
},
|
|
656
51
|
baseURL: this.baseUrl,
|
|
657
52
|
timeout: this.timeout,
|
|
@@ -676,39 +71,56 @@ class CloudGlue {
|
|
|
676
71
|
const faceDetectionApi = (0, Face_Detection_1.createApiClient)(this.baseUrl, sharedConfig);
|
|
677
72
|
const faceMatchApi = (0, Face_Match_1.createApiClient)(this.baseUrl, sharedConfig);
|
|
678
73
|
const webhooksApi = (0, Webhooks_1.createApiClient)(this.baseUrl, sharedConfig);
|
|
74
|
+
const tagsApi = (0, Tags_1.createApiClient)(this.baseUrl, sharedConfig);
|
|
679
75
|
// Configure base URL and axios config for all clients
|
|
680
|
-
[
|
|
76
|
+
[
|
|
77
|
+
filesApi,
|
|
78
|
+
collectionsApi,
|
|
79
|
+
chatApi,
|
|
80
|
+
transcribeApi,
|
|
81
|
+
extractApi,
|
|
82
|
+
segmentationsApi,
|
|
83
|
+
searchApi,
|
|
84
|
+
describeApi,
|
|
85
|
+
segmentsApi,
|
|
86
|
+
framesApi,
|
|
87
|
+
faceDetectionApi,
|
|
88
|
+
faceMatchApi,
|
|
89
|
+
webhooksApi,
|
|
90
|
+
tagsApi,
|
|
91
|
+
].forEach((client) => {
|
|
681
92
|
Object.assign(client.axios.defaults, axiosConfig);
|
|
682
93
|
client.axios.interceptors.response.use((response) => {
|
|
683
94
|
return response;
|
|
684
95
|
}, (error) => {
|
|
685
96
|
if (error.code === 'ECONNABORTED') {
|
|
686
|
-
return Promise.reject(new CloudGlueError(error.message, 408, error.config.data, error.response?.headers ?? error.headers, error.response?.data));
|
|
97
|
+
return Promise.reject(new error_1.CloudGlueError(error.message, 408, error.config.data, error.response?.headers ?? error.headers, error.response?.data));
|
|
687
98
|
}
|
|
688
99
|
else if (error.response) {
|
|
689
100
|
// The request was made and the server responded with a status code
|
|
690
101
|
// that falls out of the range of 2xx
|
|
691
102
|
const data = error.response.data;
|
|
692
|
-
return Promise.reject(new CloudGlueError(data.error, error.response.status, error.config.data, error.response.headers, error.response.data));
|
|
103
|
+
return Promise.reject(new error_1.CloudGlueError(data.error, error.response.status, error.config.data, error.response.headers, error.response.data));
|
|
693
104
|
}
|
|
694
105
|
// Something happened in setting up the request that triggered an Error
|
|
695
|
-
return Promise.reject(new CloudGlueError(error.message, error.statusCode ?? 500, error.data, error.headers, error.response?.data));
|
|
106
|
+
return Promise.reject(new error_1.CloudGlueError(error.message, error.statusCode ?? 500, error.data, error.headers, error.response?.data));
|
|
696
107
|
});
|
|
697
108
|
});
|
|
698
109
|
// Create enhanced API clients
|
|
699
|
-
this.files = new EnhancedFilesApi(filesApi);
|
|
700
|
-
this.collections = new EnhancedCollectionsApi(collectionsApi);
|
|
701
|
-
this.chat = new EnhancedChatApi(chatApi);
|
|
702
|
-
this.transcribe = new EnhancedTranscribeApi(transcribeApi);
|
|
703
|
-
this.extract = new EnhancedExtractApi(extractApi);
|
|
704
|
-
this.segmentations = new EnhancedSegmentationsApi(segmentationsApi);
|
|
705
|
-
this.search = new EnhancedSearchApi(searchApi);
|
|
706
|
-
this.describe = new EnhancedDescribeApi(describeApi);
|
|
707
|
-
this.segments = new EnhancedSegmentsApi(segmentsApi);
|
|
708
|
-
this.frames = new EnhancedFramesApi(framesApi);
|
|
709
|
-
this.faceDetection = new EnhancedFaceDetectionApi(faceDetectionApi);
|
|
710
|
-
this.faceMatch = new EnhancedFaceMatchApi(faceMatchApi);
|
|
711
|
-
this.webhooks = new EnhancedWebhooksApi(webhooksApi);
|
|
110
|
+
this.files = new files_api_1.EnhancedFilesApi(filesApi);
|
|
111
|
+
this.collections = new collections_api_1.EnhancedCollectionsApi(collectionsApi);
|
|
112
|
+
this.chat = new chat_completion_api_1.EnhancedChatApi(chatApi);
|
|
113
|
+
this.transcribe = new transcribe_api_1.EnhancedTranscribeApi(transcribeApi);
|
|
114
|
+
this.extract = new extract_api_1.EnhancedExtractApi(extractApi);
|
|
115
|
+
this.segmentations = new segmentations_api_1.EnhancedSegmentationsApi(segmentationsApi);
|
|
116
|
+
this.search = new search_api_1.EnhancedSearchApi(searchApi);
|
|
117
|
+
this.describe = new describe_api_1.EnhancedDescribeApi(describeApi);
|
|
118
|
+
this.segments = new segments_api_1.EnhancedSegmentsApi(segmentsApi);
|
|
119
|
+
this.frames = new frame_extraction_api_1.EnhancedFramesApi(framesApi);
|
|
120
|
+
this.faceDetection = new face_detection_api_1.EnhancedFaceDetectionApi(faceDetectionApi);
|
|
121
|
+
this.faceMatch = new face_match_api_1.EnhancedFaceMatchApi(faceMatchApi);
|
|
122
|
+
this.webhooks = new webhooks_api_1.EnhancedWebhooksApi(webhooksApi);
|
|
123
|
+
this.tags = new tags_api_1.EnhancedTagsApi(tagsApi);
|
|
712
124
|
}
|
|
713
125
|
}
|
|
714
126
|
exports.CloudGlue = CloudGlue;
|