vidnavigator 0.1.6 → 1.0.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 +375 -77
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +35 -1
- package/dist/index.d.ts +110 -20
- package/dist/index.js +150 -31
- package/dist/models/Carousel.d.ts +30 -0
- package/dist/models/Carousel.js +21 -0
- package/dist/models/CarouselVideoResult.d.ts +28 -0
- package/dist/models/CarouselVideoResult.js +21 -0
- package/dist/models/Extraction.d.ts +27 -0
- package/dist/models/Extraction.js +14 -0
- package/dist/models/FileInfo.d.ts +5 -0
- package/dist/models/FileInfo.js +3 -0
- package/dist/models/Namespace.d.ts +29 -0
- package/dist/models/Namespace.js +37 -0
- package/dist/models/SearchResult.d.ts +29 -0
- package/dist/models/SearchResult.js +12 -0
- package/dist/models/TranscriptSegment.d.ts +7 -0
- package/dist/models/TranscriptSegment.js +11 -0
- package/dist/models/Usage.d.ts +43 -18
- package/dist/models/Usage.js +33 -11
- package/dist/models/VideoInfo.d.ts +6 -1
- package/dist/models/VideoInfo.js +9 -1
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +4 -0
- package/package.json +1 -1
- package/src/errors.ts +43 -0
- package/src/index.ts +450 -114
- package/src/models/Carousel.ts +45 -0
- package/src/models/CarouselVideoResult.ts +44 -0
- package/src/models/Extraction.ts +47 -0
- package/src/models/FileInfo.ts +8 -0
- package/src/models/Namespace.ts +60 -0
- package/src/models/SearchResult.ts +45 -1
- package/src/models/TranscriptSegment.ts +16 -0
- package/src/models/Usage.ts +180 -134
- package/src/models/VideoInfo.ts +15 -2
- package/src/models/index.ts +4 -0
package/src/index.ts
CHANGED
|
@@ -4,8 +4,9 @@ import fs from 'fs';
|
|
|
4
4
|
import {
|
|
5
5
|
VideoInfo,
|
|
6
6
|
VideoInfoJSON,
|
|
7
|
-
TranscriptSegment,
|
|
8
7
|
TranscriptSegmentJSON,
|
|
8
|
+
TranscriptOutput,
|
|
9
|
+
transcriptFromJSON,
|
|
9
10
|
FileInfo,
|
|
10
11
|
FileInfoJSON,
|
|
11
12
|
AnalysisResult,
|
|
@@ -16,6 +17,17 @@ import {
|
|
|
16
17
|
FileSearchResultJSON,
|
|
17
18
|
UsageData,
|
|
18
19
|
UsageDataJSON,
|
|
20
|
+
Namespace,
|
|
21
|
+
NamespaceJSON,
|
|
22
|
+
NamespaceRef,
|
|
23
|
+
NamespaceRefJSON,
|
|
24
|
+
ExtractionSchema,
|
|
25
|
+
ExtractionTokenUsage,
|
|
26
|
+
ExtractionTokenUsageJSON,
|
|
27
|
+
CarouselInfo,
|
|
28
|
+
CarouselInfoJSON,
|
|
29
|
+
CarouselVideoResult,
|
|
30
|
+
CarouselVideoResultJSON,
|
|
19
31
|
} from './models';
|
|
20
32
|
import {
|
|
21
33
|
VidNavigatorError,
|
|
@@ -26,11 +38,17 @@ import {
|
|
|
26
38
|
RateLimitExceededError,
|
|
27
39
|
PaymentRequiredError,
|
|
28
40
|
ServerError,
|
|
41
|
+
StorageQuotaExceededError,
|
|
42
|
+
GeoRestrictedError,
|
|
43
|
+
SystemOverloadError,
|
|
29
44
|
} from './errors';
|
|
30
45
|
|
|
31
46
|
export * from './models';
|
|
32
47
|
export * from './errors';
|
|
33
48
|
|
|
49
|
+
/** SDK version (keep in sync with package.json) */
|
|
50
|
+
export const SDK_VERSION = '1.0.0';
|
|
51
|
+
|
|
34
52
|
//region --- Interfaces ---
|
|
35
53
|
export interface SDKConfig {
|
|
36
54
|
apiKey: string;
|
|
@@ -42,8 +60,74 @@ interface ApiSuccessResponse<T> {
|
|
|
42
60
|
status: 'success';
|
|
43
61
|
data: T;
|
|
44
62
|
}
|
|
63
|
+
|
|
64
|
+
export type TranscriptRequestPayload = {
|
|
65
|
+
video_url: string;
|
|
66
|
+
language?: string;
|
|
67
|
+
metadata_only?: boolean;
|
|
68
|
+
fallback_to_metadata?: boolean;
|
|
69
|
+
transcript_text?: boolean;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type TranscribeVideoPayload = {
|
|
73
|
+
video_url: string;
|
|
74
|
+
transcript_text?: boolean;
|
|
75
|
+
all_videos?: boolean;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type TranscribeVideoSingleResult = {
|
|
79
|
+
video_info: VideoInfo;
|
|
80
|
+
transcript: TranscriptOutput;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type TranscribeVideoCarouselResult = {
|
|
84
|
+
carousel_info: CarouselInfo;
|
|
85
|
+
videos: CarouselVideoResult[];
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export type TranscribeVideoResult = TranscribeVideoSingleResult | TranscribeVideoCarouselResult;
|
|
89
|
+
|
|
90
|
+
export type UploadFileSuccessResult = {
|
|
91
|
+
status: 'success';
|
|
92
|
+
file_id: string;
|
|
93
|
+
file_name: string;
|
|
94
|
+
file_status: 'processing' | 'completed';
|
|
95
|
+
message: string;
|
|
96
|
+
file_info: FileInfo;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export type UploadFileAcceptedResult = {
|
|
100
|
+
status: 'accepted';
|
|
101
|
+
file_id: string;
|
|
102
|
+
file_name: string;
|
|
103
|
+
file_status: 'processing';
|
|
104
|
+
message: string;
|
|
105
|
+
note?: string;
|
|
106
|
+
file_info?: FileInfo;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export type UploadFileResult = UploadFileSuccessResult | UploadFileAcceptedResult;
|
|
110
|
+
|
|
111
|
+
export interface ExtractDataResult {
|
|
112
|
+
data: Record<string, unknown>;
|
|
113
|
+
usage?: ExtractionTokenUsage;
|
|
114
|
+
}
|
|
45
115
|
//endregion
|
|
46
116
|
|
|
117
|
+
function parseApiErrorPayload(data: any): {
|
|
118
|
+
errorCode?: string;
|
|
119
|
+
errorMessage?: string;
|
|
120
|
+
details?: any;
|
|
121
|
+
} {
|
|
122
|
+
const errorField = data?.error;
|
|
123
|
+
const errorCode =
|
|
124
|
+
typeof errorField === 'string' ? errorField : errorField?.code;
|
|
125
|
+
const errorMessage =
|
|
126
|
+
data?.message ??
|
|
127
|
+
(typeof errorField === 'object' ? errorField?.message : undefined);
|
|
128
|
+
return { errorCode, errorMessage, details: data };
|
|
129
|
+
}
|
|
130
|
+
|
|
47
131
|
export class VidNavigatorClient {
|
|
48
132
|
private client: AxiosInstance;
|
|
49
133
|
|
|
@@ -56,13 +140,19 @@ export class VidNavigatorClient {
|
|
|
56
140
|
baseURL: config.baseURL ?? 'https://api.vidnavigator.com/v1',
|
|
57
141
|
headers: {
|
|
58
142
|
'X-API-Key': config.apiKey,
|
|
59
|
-
'User-Agent': `vidnavigator-js
|
|
143
|
+
'User-Agent': `vidnavigator-js/${SDK_VERSION}`,
|
|
60
144
|
},
|
|
61
145
|
...config.axiosConfig,
|
|
62
146
|
});
|
|
63
147
|
}
|
|
64
148
|
|
|
65
|
-
private async request<T>(
|
|
149
|
+
private async request<T>(
|
|
150
|
+
method: 'GET' | 'POST' | 'DELETE' | 'PUT',
|
|
151
|
+
url: string,
|
|
152
|
+
data?: any,
|
|
153
|
+
params?: any,
|
|
154
|
+
extraHeaders?: any
|
|
155
|
+
): Promise<T> {
|
|
66
156
|
try {
|
|
67
157
|
const response = await this.client.request<T>({
|
|
68
158
|
method,
|
|
@@ -75,227 +165,463 @@ export class VidNavigatorClient {
|
|
|
75
165
|
} catch (error: any) {
|
|
76
166
|
if (axios.isAxiosError(error) && error.response) {
|
|
77
167
|
const { status, data } = error.response;
|
|
78
|
-
const errorCode = data
|
|
79
|
-
const errorMessage = data?.error?.message;
|
|
80
|
-
const errorDetails = data?.error?.details;
|
|
168
|
+
const { errorCode, errorMessage, details } = parseApiErrorPayload(data);
|
|
81
169
|
const message = `API request failed with status ${status}: ${errorMessage || error.message}`;
|
|
82
170
|
|
|
83
171
|
switch (status) {
|
|
84
172
|
case 400:
|
|
85
|
-
throw new BadRequestError(message, status, errorCode, errorMessage,
|
|
173
|
+
throw new BadRequestError(message, status, errorCode, errorMessage, details);
|
|
86
174
|
case 401:
|
|
87
|
-
throw new AuthenticationError(message, status, errorCode, errorMessage,
|
|
175
|
+
throw new AuthenticationError(message, status, errorCode, errorMessage, details);
|
|
176
|
+
case 402:
|
|
177
|
+
throw new PaymentRequiredError(message, status, errorCode, errorMessage, details);
|
|
88
178
|
case 403:
|
|
89
|
-
throw new AccessDeniedError(message, status, errorCode, errorMessage,
|
|
179
|
+
throw new AccessDeniedError(message, status, errorCode, errorMessage, details);
|
|
90
180
|
case 404:
|
|
91
|
-
throw new NotFoundError(message, status, errorCode, errorMessage,
|
|
181
|
+
throw new NotFoundError(message, status, errorCode, errorMessage, details);
|
|
182
|
+
case 413:
|
|
183
|
+
throw new StorageQuotaExceededError(message, status, errorCode, errorMessage, details);
|
|
92
184
|
case 429:
|
|
93
|
-
throw new RateLimitExceededError(message, status, errorCode, errorMessage,
|
|
94
|
-
case
|
|
95
|
-
throw new
|
|
185
|
+
throw new RateLimitExceededError(message, status, errorCode, errorMessage, details);
|
|
186
|
+
case 451:
|
|
187
|
+
throw new GeoRestrictedError(message, status, errorCode, errorMessage, details);
|
|
188
|
+
case 503:
|
|
189
|
+
throw new SystemOverloadError(
|
|
190
|
+
message,
|
|
191
|
+
status,
|
|
192
|
+
errorCode,
|
|
193
|
+
errorMessage,
|
|
194
|
+
details,
|
|
195
|
+
data?.retry_after_seconds
|
|
196
|
+
);
|
|
96
197
|
default:
|
|
97
198
|
if (status >= 500) {
|
|
98
|
-
throw new ServerError(message, status, errorCode, errorMessage,
|
|
199
|
+
throw new ServerError(message, status, errorCode, errorMessage, details);
|
|
99
200
|
}
|
|
100
|
-
throw new VidNavigatorError(message, status, errorCode, errorMessage,
|
|
201
|
+
throw new VidNavigatorError(message, status, errorCode, errorMessage, details);
|
|
101
202
|
}
|
|
102
203
|
}
|
|
103
|
-
// Re-throw other errors (e.g., network errors)
|
|
104
204
|
throw new VidNavigatorError(error.message);
|
|
105
205
|
}
|
|
106
206
|
}
|
|
107
207
|
|
|
108
208
|
//region --- Transcripts ---
|
|
109
|
-
async getTranscript(payload:
|
|
209
|
+
async getTranscript(payload: TranscriptRequestPayload): Promise<{
|
|
110
210
|
video_info: VideoInfo;
|
|
111
|
-
transcript:
|
|
211
|
+
transcript: TranscriptOutput;
|
|
112
212
|
}> {
|
|
113
|
-
const response = await this.request<
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
213
|
+
const response = await this.request<
|
|
214
|
+
ApiSuccessResponse<{
|
|
215
|
+
video_info: VideoInfoJSON;
|
|
216
|
+
transcript: TranscriptSegmentJSON[] | string;
|
|
217
|
+
}>
|
|
218
|
+
>('POST', '/transcript', payload);
|
|
117
219
|
|
|
118
220
|
return {
|
|
119
221
|
video_info: VideoInfo.fromJSON(response.data.video_info),
|
|
120
|
-
transcript: response.data.transcript
|
|
222
|
+
transcript: transcriptFromJSON(response.data.transcript)!,
|
|
121
223
|
};
|
|
122
224
|
}
|
|
123
225
|
|
|
124
|
-
async
|
|
226
|
+
async getYouTubeTranscript(payload: TranscriptRequestPayload): Promise<{
|
|
125
227
|
video_info: VideoInfo;
|
|
126
|
-
transcript:
|
|
228
|
+
transcript: TranscriptOutput;
|
|
127
229
|
}> {
|
|
128
|
-
const response = await this.request<
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
230
|
+
const response = await this.request<
|
|
231
|
+
ApiSuccessResponse<{
|
|
232
|
+
video_info: VideoInfoJSON;
|
|
233
|
+
transcript: TranscriptSegmentJSON[] | string;
|
|
234
|
+
}>
|
|
235
|
+
>('POST', '/transcript/youtube', payload);
|
|
132
236
|
|
|
133
237
|
return {
|
|
134
238
|
video_info: VideoInfo.fromJSON(response.data.video_info),
|
|
135
|
-
transcript: response.data.transcript
|
|
239
|
+
transcript: transcriptFromJSON(response.data.transcript)!,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
async transcribeVideo(payload: TranscribeVideoPayload): Promise<TranscribeVideoResult> {
|
|
244
|
+
const response = await this.request<
|
|
245
|
+
| ApiSuccessResponse<{
|
|
246
|
+
video_info: VideoInfoJSON;
|
|
247
|
+
transcript: TranscriptSegmentJSON[] | string;
|
|
248
|
+
}>
|
|
249
|
+
| ApiSuccessResponse<{
|
|
250
|
+
carousel_info: CarouselInfoJSON;
|
|
251
|
+
videos: CarouselVideoResultJSON[];
|
|
252
|
+
}>
|
|
253
|
+
>('POST', '/transcribe', payload);
|
|
254
|
+
|
|
255
|
+
const inner = response.data;
|
|
256
|
+
if ('videos' in inner && 'carousel_info' in inner) {
|
|
257
|
+
return {
|
|
258
|
+
carousel_info: CarouselInfo.fromJSON(inner.carousel_info),
|
|
259
|
+
videos: inner.videos.map((v) => CarouselVideoResult.fromJSON(v)),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
const single = inner as {
|
|
263
|
+
video_info: VideoInfoJSON;
|
|
264
|
+
transcript: TranscriptSegmentJSON[] | string;
|
|
265
|
+
};
|
|
266
|
+
return {
|
|
267
|
+
video_info: VideoInfo.fromJSON(single.video_info),
|
|
268
|
+
transcript: transcriptFromJSON(single.transcript)!,
|
|
136
269
|
};
|
|
137
270
|
}
|
|
138
271
|
//endregion
|
|
139
272
|
|
|
140
273
|
//region --- Files ---
|
|
141
|
-
async getFiles(query?: {
|
|
274
|
+
async getFiles(query?: {
|
|
275
|
+
limit?: number;
|
|
276
|
+
offset?: number;
|
|
277
|
+
status?: 'processing' | 'completed' | 'failed' | 'cancelled';
|
|
278
|
+
namespace_id?: string;
|
|
279
|
+
}): Promise<{
|
|
142
280
|
files: FileInfo[];
|
|
143
281
|
total_count: number;
|
|
282
|
+
limit: number;
|
|
283
|
+
offset: number;
|
|
144
284
|
has_more: boolean;
|
|
145
285
|
}> {
|
|
146
|
-
const response = await this.request<
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
286
|
+
const response = await this.request<
|
|
287
|
+
ApiSuccessResponse<{
|
|
288
|
+
files: FileInfoJSON[];
|
|
289
|
+
total_count: number;
|
|
290
|
+
limit: number;
|
|
291
|
+
offset: number;
|
|
292
|
+
has_more: boolean;
|
|
293
|
+
}>
|
|
294
|
+
>('GET', '/files', undefined, query);
|
|
151
295
|
|
|
152
296
|
return {
|
|
153
297
|
files: response.data.files.map(FileInfo.fromJSON),
|
|
154
298
|
total_count: response.data.total_count,
|
|
299
|
+
limit: response.data.limit,
|
|
300
|
+
offset: response.data.offset,
|
|
155
301
|
has_more: response.data.has_more,
|
|
156
302
|
};
|
|
157
303
|
}
|
|
158
304
|
|
|
159
|
-
async getFile(
|
|
160
|
-
|
|
305
|
+
async getFile(
|
|
306
|
+
file_id: string,
|
|
307
|
+
query?: { transcript_text?: boolean }
|
|
308
|
+
): Promise<{ file_info: FileInfo; transcript?: TranscriptOutput }> {
|
|
309
|
+
const response = await this.request<
|
|
310
|
+
ApiSuccessResponse<{
|
|
161
311
|
file_info: FileInfoJSON;
|
|
162
|
-
transcript?: TranscriptSegmentJSON[];
|
|
163
|
-
|
|
312
|
+
transcript?: TranscriptSegmentJSON[] | string;
|
|
313
|
+
}>
|
|
314
|
+
>('GET', `/file/${file_id}`, undefined, query);
|
|
164
315
|
|
|
165
316
|
return {
|
|
166
|
-
|
|
167
|
-
|
|
317
|
+
file_info: FileInfo.fromJSON(response.data.file_info),
|
|
318
|
+
transcript: transcriptFromJSON(response.data.transcript),
|
|
168
319
|
};
|
|
169
320
|
}
|
|
170
321
|
|
|
171
|
-
async uploadFile(options: {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}> {
|
|
322
|
+
async uploadFile(options: {
|
|
323
|
+
filePath: string;
|
|
324
|
+
wait_for_completion?: boolean;
|
|
325
|
+
namespace_ids?: string[];
|
|
326
|
+
}): Promise<UploadFileResult> {
|
|
176
327
|
const form = new FormData();
|
|
177
328
|
form.append('file', fs.createReadStream(options.filePath));
|
|
178
329
|
if (options.wait_for_completion) {
|
|
179
330
|
form.append('wait_for_completion', 'true');
|
|
180
331
|
}
|
|
332
|
+
if (options.namespace_ids?.length) {
|
|
333
|
+
form.append('namespace_ids', JSON.stringify(options.namespace_ids));
|
|
334
|
+
}
|
|
181
335
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
336
|
+
try {
|
|
337
|
+
const response = await this.client.post<{
|
|
338
|
+
status: 'success' | 'accepted';
|
|
339
|
+
file_id: string;
|
|
340
|
+
file_name: string;
|
|
341
|
+
file_status: 'processing' | 'completed';
|
|
342
|
+
message: string;
|
|
343
|
+
note?: string;
|
|
344
|
+
data?: { file_info: FileInfoJSON };
|
|
345
|
+
}>('/upload/file', form, { headers: form.getHeaders() });
|
|
187
346
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
347
|
+
const body = response.data;
|
|
348
|
+
const fileInfo = body.data?.file_info ? FileInfo.fromJSON(body.data.file_info) : undefined;
|
|
349
|
+
if (body.status === 'accepted') {
|
|
350
|
+
return {
|
|
351
|
+
status: 'accepted',
|
|
352
|
+
file_id: body.file_id,
|
|
353
|
+
file_name: body.file_name,
|
|
354
|
+
file_status: body.file_status as 'processing',
|
|
355
|
+
message: body.message,
|
|
356
|
+
note: body.note,
|
|
357
|
+
file_info: fileInfo,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
return {
|
|
361
|
+
status: 'success',
|
|
362
|
+
file_id: body.file_id,
|
|
363
|
+
file_name: body.file_name,
|
|
364
|
+
file_status: body.file_status,
|
|
365
|
+
message: body.message,
|
|
366
|
+
file_info: fileInfo!,
|
|
367
|
+
};
|
|
368
|
+
} catch (error: any) {
|
|
369
|
+
if (axios.isAxiosError(error) && error.response) {
|
|
370
|
+
const { status, data } = error.response;
|
|
371
|
+
const { errorCode, errorMessage, details } = parseApiErrorPayload(data);
|
|
372
|
+
const message = `API request failed with status ${status}: ${errorMessage || error.message}`;
|
|
373
|
+
switch (status) {
|
|
374
|
+
case 400:
|
|
375
|
+
throw new BadRequestError(message, status, errorCode, errorMessage, details);
|
|
376
|
+
case 401:
|
|
377
|
+
throw new AuthenticationError(message, status, errorCode, errorMessage, details);
|
|
378
|
+
case 402:
|
|
379
|
+
throw new PaymentRequiredError(message, status, errorCode, errorMessage, details);
|
|
380
|
+
case 413:
|
|
381
|
+
throw new StorageQuotaExceededError(message, status, errorCode, errorMessage, details);
|
|
382
|
+
case 503:
|
|
383
|
+
throw new SystemOverloadError(
|
|
384
|
+
message,
|
|
385
|
+
status,
|
|
386
|
+
errorCode,
|
|
387
|
+
errorMessage,
|
|
388
|
+
details,
|
|
389
|
+
data?.retry_after_seconds
|
|
390
|
+
);
|
|
391
|
+
default:
|
|
392
|
+
if (status >= 500) {
|
|
393
|
+
throw new ServerError(message, status, errorCode, errorMessage, details);
|
|
394
|
+
}
|
|
395
|
+
throw new VidNavigatorError(message, status, errorCode, errorMessage, details);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
throw new VidNavigatorError(error.message);
|
|
399
|
+
}
|
|
193
400
|
}
|
|
194
|
-
|
|
195
|
-
async deleteFile(file_id: string): Promise<{ file_id: string; message: string }> {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return response.data;
|
|
401
|
+
|
|
402
|
+
async deleteFile(file_id: string): Promise<{ file_id: string; file_name: string; message: string }> {
|
|
403
|
+
const response = await this.request<
|
|
404
|
+
ApiSuccessResponse<{ file_id: string; file_name: string; message: string }>
|
|
405
|
+
>('DELETE', `/file/${file_id}/delete`);
|
|
406
|
+
return response.data;
|
|
201
407
|
}
|
|
202
408
|
|
|
203
409
|
async getFileUrl(file_id: string): Promise<{ file_id: string; file_url: string }> {
|
|
204
|
-
const response = await this.request<
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
);
|
|
410
|
+
const response = await this.request<
|
|
411
|
+
ApiSuccessResponse<{ file_id: string; file_url: string }>
|
|
412
|
+
>('GET', `/file/${file_id}/url`);
|
|
208
413
|
return response.data;
|
|
209
414
|
}
|
|
210
415
|
|
|
211
|
-
async retryFileProcessing(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
416
|
+
async retryFileProcessing(
|
|
417
|
+
file_id: string
|
|
418
|
+
): Promise<{ file_id: string; file_name: string; file_status: string; message: string }> {
|
|
419
|
+
const response = await this.request<
|
|
420
|
+
ApiSuccessResponse<{
|
|
421
|
+
file_id: string;
|
|
422
|
+
file_name: string;
|
|
423
|
+
file_status: string;
|
|
424
|
+
message: string;
|
|
425
|
+
}>
|
|
426
|
+
>('POST', `/file/${file_id}/retry`);
|
|
427
|
+
return response.data;
|
|
217
428
|
}
|
|
218
429
|
|
|
219
|
-
async cancelFileUpload(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
430
|
+
async cancelFileUpload(
|
|
431
|
+
file_id: string
|
|
432
|
+
): Promise<{ file_id: string; file_name: string; message: string }> {
|
|
433
|
+
const response = await this.request<
|
|
434
|
+
ApiSuccessResponse<{ file_id: string; file_name: string; message: string }>
|
|
435
|
+
>('POST', `/file/${file_id}/cancel`);
|
|
436
|
+
return response.data;
|
|
437
|
+
}
|
|
438
|
+
//endregion
|
|
439
|
+
|
|
440
|
+
//region --- Namespaces ---
|
|
441
|
+
async getNamespaces(): Promise<Namespace[]> {
|
|
442
|
+
const response = await this.request<ApiSuccessResponse<NamespaceJSON[]>>('GET', '/namespaces');
|
|
443
|
+
return response.data.map((n) => Namespace.fromJSON(n));
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
async createNamespace(payload: { name: string }): Promise<Namespace> {
|
|
447
|
+
const response = await this.request<ApiSuccessResponse<NamespaceJSON>>('POST', '/namespaces', payload);
|
|
448
|
+
return Namespace.fromJSON(response.data);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
async updateNamespace(namespace_id: string, payload: { name: string }): Promise<{ message: string }> {
|
|
452
|
+
const body = await this.request<{ status: string; message: string }>(
|
|
453
|
+
'PUT',
|
|
454
|
+
`/namespaces/${namespace_id}`,
|
|
455
|
+
payload
|
|
456
|
+
);
|
|
457
|
+
return { message: body.message };
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
async deleteNamespace(namespace_id: string): Promise<{ message: string }> {
|
|
461
|
+
const body = await this.request<{ status: string; message: string }>(
|
|
462
|
+
'DELETE',
|
|
463
|
+
`/namespaces/${namespace_id}`
|
|
464
|
+
);
|
|
465
|
+
return { message: body.message };
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
async updateFileNamespaces(
|
|
469
|
+
file_id: string,
|
|
470
|
+
payload: { namespace_ids: string[] }
|
|
471
|
+
): Promise<{ message: string; namespace_ids: string[]; namespaces: NamespaceRef[] }> {
|
|
472
|
+
const body = await this.request<{
|
|
473
|
+
status: string;
|
|
474
|
+
message: string;
|
|
475
|
+
data: { namespace_ids: string[]; namespaces: NamespaceRefJSON[] };
|
|
476
|
+
}>('PUT', `/file/${file_id}/namespaces`, payload);
|
|
477
|
+
return {
|
|
478
|
+
message: body.message,
|
|
479
|
+
namespace_ids: body.data.namespace_ids,
|
|
480
|
+
namespaces: body.data.namespaces.map(NamespaceRef.fromJSON),
|
|
481
|
+
};
|
|
225
482
|
}
|
|
226
483
|
//endregion
|
|
227
484
|
|
|
228
485
|
//region --- Analysis ---
|
|
229
|
-
async analyzeVideo(payload: {
|
|
486
|
+
async analyzeVideo(payload: {
|
|
487
|
+
video_url: string;
|
|
488
|
+
query?: string;
|
|
489
|
+
transcript_text?: boolean;
|
|
490
|
+
}): Promise<{
|
|
230
491
|
video_info: VideoInfo;
|
|
231
|
-
transcript:
|
|
492
|
+
transcript: TranscriptOutput;
|
|
232
493
|
transcript_analysis: AnalysisResult;
|
|
233
494
|
}> {
|
|
234
|
-
const response = await this.request<
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
495
|
+
const response = await this.request<
|
|
496
|
+
ApiSuccessResponse<{
|
|
497
|
+
video_info: VideoInfoJSON;
|
|
498
|
+
transcript: TranscriptSegmentJSON[] | string;
|
|
499
|
+
transcript_analysis: AnalysisResultJSON;
|
|
500
|
+
}>
|
|
501
|
+
>('POST', '/analyze/video', payload);
|
|
239
502
|
|
|
240
503
|
return {
|
|
241
504
|
video_info: VideoInfo.fromJSON(response.data.video_info),
|
|
242
|
-
transcript: response.data.transcript
|
|
505
|
+
transcript: transcriptFromJSON(response.data.transcript)!,
|
|
243
506
|
transcript_analysis: AnalysisResult.fromJSON(response.data.transcript_analysis),
|
|
244
507
|
};
|
|
245
508
|
}
|
|
246
509
|
|
|
247
|
-
async analyzeFile(payload: {
|
|
510
|
+
async analyzeFile(payload: {
|
|
511
|
+
file_id: string;
|
|
512
|
+
query?: string;
|
|
513
|
+
transcript_text?: boolean;
|
|
514
|
+
}): Promise<{
|
|
248
515
|
file_info: FileInfo;
|
|
249
|
-
transcript:
|
|
516
|
+
transcript: TranscriptOutput;
|
|
250
517
|
transcript_analysis: AnalysisResult;
|
|
251
518
|
}> {
|
|
252
|
-
const response = await this.request<
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
519
|
+
const response = await this.request<
|
|
520
|
+
ApiSuccessResponse<{
|
|
521
|
+
file_info: FileInfoJSON;
|
|
522
|
+
transcript: TranscriptSegmentJSON[] | string;
|
|
523
|
+
transcript_analysis: AnalysisResultJSON;
|
|
524
|
+
}>
|
|
525
|
+
>('POST', '/analyze/file', payload);
|
|
257
526
|
|
|
258
527
|
return {
|
|
259
528
|
file_info: FileInfo.fromJSON(response.data.file_info),
|
|
260
|
-
transcript: response.data.transcript
|
|
529
|
+
transcript: transcriptFromJSON(response.data.transcript)!,
|
|
261
530
|
transcript_analysis: AnalysisResult.fromJSON(response.data.transcript_analysis),
|
|
262
531
|
};
|
|
263
532
|
}
|
|
264
533
|
//endregion
|
|
265
534
|
|
|
535
|
+
//region --- Extraction ---
|
|
536
|
+
async extractVideoData(payload: {
|
|
537
|
+
video_url: string;
|
|
538
|
+
schema: ExtractionSchema;
|
|
539
|
+
what_to_extract?: string;
|
|
540
|
+
include_usage?: boolean;
|
|
541
|
+
}): Promise<ExtractDataResult> {
|
|
542
|
+
const body = await this.request<{
|
|
543
|
+
status: 'success';
|
|
544
|
+
data: Record<string, unknown>;
|
|
545
|
+
usage?: ExtractionTokenUsageJSON;
|
|
546
|
+
}>('POST', '/extract/video', payload);
|
|
547
|
+
return {
|
|
548
|
+
data: body.data,
|
|
549
|
+
usage: body.usage ? ExtractionTokenUsage.fromJSON(body.usage) : undefined,
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
async extractFileData(payload: {
|
|
554
|
+
file_id: string;
|
|
555
|
+
schema: ExtractionSchema;
|
|
556
|
+
what_to_extract?: string;
|
|
557
|
+
include_usage?: boolean;
|
|
558
|
+
}): Promise<ExtractDataResult> {
|
|
559
|
+
const body = await this.request<{
|
|
560
|
+
status: 'success';
|
|
561
|
+
data: Record<string, unknown>;
|
|
562
|
+
usage?: ExtractionTokenUsageJSON;
|
|
563
|
+
}>('POST', '/extract/file', payload);
|
|
564
|
+
return {
|
|
565
|
+
data: body.data,
|
|
566
|
+
usage: body.usage ? ExtractionTokenUsage.fromJSON(body.usage) : undefined,
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
//endregion
|
|
570
|
+
|
|
266
571
|
//region --- Search ---
|
|
267
572
|
async searchVideos(payload: {
|
|
268
573
|
query: string;
|
|
269
574
|
use_enhanced_search?: boolean;
|
|
270
575
|
start_year?: number;
|
|
271
576
|
end_year?: number;
|
|
272
|
-
focus?: 'relevance'|'popularity'|'brevity';
|
|
577
|
+
focus?: 'relevance' | 'popularity' | 'brevity';
|
|
273
578
|
duration?: number;
|
|
274
|
-
}): Promise<{
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
579
|
+
}): Promise<{
|
|
580
|
+
results: VideoSearchResult[];
|
|
581
|
+
query: string;
|
|
582
|
+
total_found: number;
|
|
583
|
+
explanation?: string;
|
|
584
|
+
}> {
|
|
585
|
+
const response = await this.request<
|
|
586
|
+
ApiSuccessResponse<{
|
|
587
|
+
results: VideoSearchResultJSON[];
|
|
588
|
+
query: string;
|
|
589
|
+
total_found: number;
|
|
590
|
+
explanation?: string;
|
|
591
|
+
}>
|
|
592
|
+
>('POST', '/search/video', payload);
|
|
593
|
+
|
|
281
594
|
return {
|
|
282
595
|
results: response.data.results.map(VideoSearchResult.fromJSON),
|
|
596
|
+
query: response.data.query,
|
|
283
597
|
total_found: response.data.total_found,
|
|
284
|
-
explanation: response.data.explanation
|
|
598
|
+
explanation: response.data.explanation,
|
|
285
599
|
};
|
|
286
600
|
}
|
|
287
601
|
|
|
288
|
-
async searchFiles(payload: {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
602
|
+
async searchFiles(payload: {
|
|
603
|
+
query: string;
|
|
604
|
+
namespace_ids?: string[];
|
|
605
|
+
}): Promise<{
|
|
606
|
+
results: FileSearchResult[];
|
|
607
|
+
query: string;
|
|
608
|
+
total_found: number;
|
|
609
|
+
explanation?: string;
|
|
610
|
+
}> {
|
|
611
|
+
const response = await this.request<
|
|
612
|
+
ApiSuccessResponse<{
|
|
613
|
+
results: FileSearchResultJSON[];
|
|
614
|
+
query: string;
|
|
615
|
+
total_found: number;
|
|
616
|
+
explanation?: string;
|
|
617
|
+
}>
|
|
618
|
+
>('POST', '/search/file', payload);
|
|
294
619
|
|
|
295
620
|
return {
|
|
296
621
|
results: response.data.results.map(FileSearchResult.fromJSON),
|
|
622
|
+
query: response.data.query,
|
|
297
623
|
total_found: response.data.total_found,
|
|
298
|
-
explanation: response.data.explanation
|
|
624
|
+
explanation: response.data.explanation,
|
|
299
625
|
};
|
|
300
626
|
}
|
|
301
627
|
//endregion
|
|
@@ -306,9 +632,19 @@ export class VidNavigatorClient {
|
|
|
306
632
|
return UsageData.fromJSON(response.data);
|
|
307
633
|
}
|
|
308
634
|
|
|
309
|
-
async healthCheck(): Promise<
|
|
635
|
+
async healthCheck(): Promise<{
|
|
636
|
+
status?: string;
|
|
637
|
+
message?: string;
|
|
638
|
+
version?: string;
|
|
639
|
+
endpoints?: Array<{
|
|
640
|
+
path?: string;
|
|
641
|
+
method?: string;
|
|
642
|
+
description?: string;
|
|
643
|
+
auth_required?: boolean;
|
|
644
|
+
}>;
|
|
645
|
+
}> {
|
|
310
646
|
const response = await this.client.get('/health');
|
|
311
647
|
return response.data;
|
|
312
648
|
}
|
|
313
649
|
//endregion
|
|
314
|
-
}
|
|
650
|
+
}
|