vidnavigator 1.0.3 → 1.0.5

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
@@ -26,7 +26,7 @@ const errors_1 = require("./errors");
26
26
  __exportStar(require("./models"), exports);
27
27
  __exportStar(require("./errors"), exports);
28
28
  /** SDK version (keep in sync with package.json) */
29
- exports.SDK_VERSION = '1.0.2';
29
+ exports.SDK_VERSION = '1.0.5';
30
30
  //endregion
31
31
  function parseApiErrorPayload(data) {
32
32
  const errorField = data?.error;
@@ -35,6 +35,33 @@ function parseApiErrorPayload(data) {
35
35
  (typeof errorField === 'object' ? errorField?.message : undefined);
36
36
  return { errorCode, errorMessage, details: data };
37
37
  }
38
+ function appendOptionalFormField(form, name, value) {
39
+ if (value !== undefined) {
40
+ form.append(name, String(value));
41
+ }
42
+ }
43
+ function buildTikTokPollParams(query) {
44
+ if (!query)
45
+ return undefined;
46
+ const params = {};
47
+ if (query.cursor !== undefined)
48
+ params.cursor = query.cursor;
49
+ if (query.limit !== undefined)
50
+ params.limit = query.limit;
51
+ // The TikTok pollers expect include_usage as a query string value.
52
+ if (query.include_usage)
53
+ params.include_usage = 'true';
54
+ return params;
55
+ }
56
+ const _deprecationWarned = new Set();
57
+ function warnDeprecated(oldName, newName) {
58
+ if (_deprecationWarned.has(oldName))
59
+ return;
60
+ _deprecationWarned.add(oldName);
61
+ if (typeof console !== 'undefined' && typeof console.warn === 'function') {
62
+ console.warn(`[vidnavigator] ${oldName}() is deprecated and will be removed in a future release; use ${newName}() instead.`);
63
+ }
64
+ }
38
65
  class VidNavigatorClient {
39
66
  constructor(config) {
40
67
  if (!config?.apiKey) {
@@ -95,33 +122,44 @@ class VidNavigatorClient {
95
122
  }
96
123
  }
97
124
  //region --- Transcripts ---
125
+ /**
126
+ * Get a transcript for any supported video. The endpoint auto-detects the
127
+ * platform (YouTube, Vimeo, X/Twitter, TikTok, Facebook, Dailymotion, Loom, etc.)
128
+ * from `video_url`. For Instagram, use {@link VidNavigatorClient.transcribeVideo}.
129
+ */
98
130
  async getTranscript(payload) {
99
131
  const response = await this.request('POST', '/transcript', payload);
100
132
  return {
101
133
  video_info: models_1.VideoInfo.fromJSON(response.data.video_info),
102
134
  transcript: (0, models_1.transcriptFromJSON)(response.data.transcript),
135
+ usage: response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined,
103
136
  };
104
137
  }
138
+ /**
139
+ * @deprecated There is now a single `/transcript` endpoint that auto-detects the
140
+ * platform. Use {@link VidNavigatorClient.getTranscript} instead. This alias
141
+ * forwards to `getTranscript` and will be removed in a future release.
142
+ */
105
143
  async getYouTubeTranscript(payload) {
106
- const response = await this.request('POST', '/youtube/transcript', payload);
107
- return {
108
- video_info: models_1.VideoInfo.fromJSON(response.data.video_info),
109
- transcript: (0, models_1.transcriptFromJSON)(response.data.transcript),
110
- };
144
+ warnDeprecated('getYouTubeTranscript', 'getTranscript');
145
+ return this.getTranscript(payload);
111
146
  }
112
147
  async transcribeVideo(payload) {
113
148
  const response = await this.request('POST', '/transcribe', payload);
114
149
  const inner = response.data;
150
+ const usage = response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined;
115
151
  if ('videos' in inner && 'carousel_info' in inner) {
116
152
  return {
117
153
  carousel_info: models_1.CarouselInfo.fromJSON(inner.carousel_info),
118
154
  videos: inner.videos.map((v) => models_1.CarouselVideoResult.fromJSON(v)),
155
+ usage,
119
156
  };
120
157
  }
121
158
  const single = inner;
122
159
  return {
123
160
  video_info: models_1.VideoInfo.fromJSON(single.video_info),
124
161
  transcript: (0, models_1.transcriptFromJSON)(single.transcript),
162
+ usage,
125
163
  };
126
164
  }
127
165
  //endregion
@@ -131,8 +169,22 @@ class VidNavigatorClient {
131
169
  return models_1.TikTokProfileScrapeSubmission.fromJSON(response.data);
132
170
  }
133
171
  async getTikTokProfileScrape(task_id, query) {
134
- const response = await this.request('GET', `/tiktok/profile/${task_id}`, undefined, query);
135
- return models_1.TikTokProfileTask.fromJSON(response.data);
172
+ const response = await this.request('GET', `/tiktok/profile/${task_id}`, undefined, buildTikTokPollParams(query));
173
+ const task = models_1.TikTokProfileTask.fromJSON(response.data);
174
+ if (response.usage)
175
+ task.usage = models_1.UsageBlock.fromJSON(response.usage);
176
+ return task;
177
+ }
178
+ async submitTikTokSearch(payload) {
179
+ const response = await this.request('POST', '/tiktok/search', payload);
180
+ return models_1.TikTokSearchSubmission.fromJSON(response.data);
181
+ }
182
+ async getTikTokSearch(task_id, query) {
183
+ const response = await this.request('GET', `/tiktok/search/${task_id}`, undefined, buildTikTokPollParams(query));
184
+ const task = models_1.TikTokSearchTask.fromJSON(response.data);
185
+ if (response.usage)
186
+ task.usage = models_1.UsageBlock.fromJSON(response.usage);
187
+ return task;
136
188
  }
137
189
  //endregion
138
190
  //region --- Files ---
@@ -262,6 +314,7 @@ class VidNavigatorClient {
262
314
  video_info: models_1.VideoInfo.fromJSON(response.data.video_info),
263
315
  transcript: (0, models_1.transcriptFromJSON)(response.data.transcript),
264
316
  transcript_analysis: models_1.AnalysisResult.fromJSON(response.data.transcript_analysis),
317
+ usage: response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined,
265
318
  };
266
319
  }
267
320
  async analyzeFile(payload) {
@@ -270,6 +323,7 @@ class VidNavigatorClient {
270
323
  file_info: models_1.FileInfo.fromJSON(response.data.file_info),
271
324
  transcript: (0, models_1.transcriptFromJSON)(response.data.transcript),
272
325
  transcript_analysis: models_1.AnalysisResult.fromJSON(response.data.transcript_analysis),
326
+ usage: response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined,
273
327
  };
274
328
  }
275
329
  async getTweetStatement(payload) {
@@ -279,32 +333,91 @@ class VidNavigatorClient {
279
333
  //endregion
280
334
  //region --- Extraction ---
281
335
  async extractVideoData(payload) {
336
+ if ('schemaFilePath' in payload) {
337
+ const form = new form_data_1.default();
338
+ form.append('video_url', payload.video_url);
339
+ form.append('schema', fs_1.default.createReadStream(payload.schemaFilePath));
340
+ appendOptionalFormField(form, 'what_to_extract', payload.what_to_extract);
341
+ appendOptionalFormField(form, 'transcribe', payload.transcribe);
342
+ appendOptionalFormField(form, 'include_usage', payload.include_usage);
343
+ const body = await this.request('POST', '/extract/video', form, undefined, form.getHeaders());
344
+ return {
345
+ data: body.data,
346
+ video_info: body.video_info ? models_1.VideoInfo.fromJSON(body.video_info) : undefined,
347
+ usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
348
+ };
349
+ }
282
350
  const body = await this.request('POST', '/extract/video', payload);
283
351
  return {
284
352
  data: body.data,
285
353
  video_info: body.video_info ? models_1.VideoInfo.fromJSON(body.video_info) : undefined,
286
- usage: body.usage ? models_1.ExtractionTokenUsage.fromJSON(body.usage) : undefined,
354
+ usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
287
355
  };
288
356
  }
289
357
  async extractFileData(payload) {
358
+ if ('schemaFilePath' in payload) {
359
+ const form = new form_data_1.default();
360
+ form.append('file_id', payload.file_id);
361
+ form.append('schema', fs_1.default.createReadStream(payload.schemaFilePath));
362
+ appendOptionalFormField(form, 'what_to_extract', payload.what_to_extract);
363
+ appendOptionalFormField(form, 'include_usage', payload.include_usage);
364
+ const body = await this.request('POST', '/extract/file', form, undefined, form.getHeaders());
365
+ return {
366
+ data: body.data,
367
+ file_info: body.file_info ? models_1.FileInfo.fromJSON(body.file_info) : undefined,
368
+ usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
369
+ };
370
+ }
290
371
  const body = await this.request('POST', '/extract/file', payload);
291
372
  return {
292
373
  data: body.data,
293
374
  file_info: body.file_info ? models_1.FileInfo.fromJSON(body.file_info) : undefined,
294
- usage: body.usage ? models_1.ExtractionTokenUsage.fromJSON(body.usage) : undefined,
375
+ usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
295
376
  };
296
377
  }
297
378
  //endregion
298
379
  //region --- Search ---
299
- async searchVideos(payload) {
300
- const response = await this.request('POST', '/search/video', payload);
380
+ /**
381
+ * Search YouTube for videos with AI analysis and ranking.
382
+ *
383
+ * If the account runs out of `residential_request` credits mid-search, the API
384
+ * returns HTTP 402 with `status: "partial"` and the videos analysed so far. The
385
+ * SDK surfaces that partial payload (results, `status: "partial"`, `error_code`,
386
+ * and `usage` when requested) instead of throwing.
387
+ */
388
+ async searchYouTube(payload) {
389
+ let response;
390
+ try {
391
+ response = await this.request('POST', '/youtube/search', payload);
392
+ }
393
+ catch (error) {
394
+ const body = error?.details;
395
+ if (error instanceof errors_1.PaymentRequiredError && body?.status === 'partial' && body?.data) {
396
+ response = body;
397
+ }
398
+ else {
399
+ throw error;
400
+ }
401
+ }
301
402
  return {
302
- results: response.data.results.map(models_1.VideoSearchResult.fromJSON),
403
+ results: (response.data.results ?? []).map(models_1.VideoSearchResult.fromJSON),
303
404
  query: response.data.query,
304
405
  total_found: response.data.total_found,
305
406
  explanation: response.data.explanation,
407
+ usage: response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined,
408
+ status: response.status,
409
+ error_code: response.error_code,
306
410
  };
307
411
  }
412
+ /**
413
+ * @deprecated `/search/video` moved to `/youtube/search`. Use
414
+ * {@link VidNavigatorClient.searchYouTube} instead. This alias forwards to
415
+ * `searchYouTube` and will be removed in a future release.
416
+ */
417
+ async searchVideos(payload) {
418
+ warnDeprecated('searchVideos', 'searchYouTube');
419
+ return this.searchYouTube(payload);
420
+ }
308
421
  async searchFiles(payload) {
309
422
  const response = await this.request('POST', '/search/file', payload);
310
423
  return {
@@ -312,6 +425,7 @@ class VidNavigatorClient {
312
425
  query: response.data.query,
313
426
  total_found: response.data.total_found,
314
427
  explanation: response.data.explanation,
428
+ usage: response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined,
315
429
  };
316
430
  }
317
431
  //endregion
@@ -1,3 +1,4 @@
1
+ import { UsageBlock } from './Usage';
1
2
  export interface TikTokProfileScrapeRequest {
2
3
  profile_url: string;
3
4
  max_posts?: number;
@@ -8,6 +9,19 @@ export interface TikTokProfileScrapeRequest {
8
9
  min_likes?: number;
9
10
  max_likes?: number;
10
11
  }
12
+ export interface TikTokSearchRequest {
13
+ query: string;
14
+ max_results?: number;
15
+ parallel_search_slices?: number;
16
+ /** Format: YYYY-MM-DD or ISO datetime with timezone */
17
+ after_datetime?: string;
18
+ /** Format: YYYY-MM-DD or ISO datetime with timezone */
19
+ before_datetime?: string;
20
+ min_likes?: number;
21
+ max_likes?: number;
22
+ min_views?: number;
23
+ max_views?: number;
24
+ }
11
25
  export interface TikTokProfileScrapeSubmissionJSON {
12
26
  task_id: string;
13
27
  task_status: 'processing';
@@ -26,6 +40,30 @@ export declare class TikTokProfileScrapeSubmission {
26
40
  constructor(data: TikTokProfileScrapeSubmissionJSON);
27
41
  static fromJSON(json: TikTokProfileScrapeSubmissionJSON): TikTokProfileScrapeSubmission;
28
42
  }
43
+ export interface TikTokSearchSubmissionJSON {
44
+ task_id: string;
45
+ task_status: 'processing';
46
+ query: string;
47
+ max_results?: number;
48
+ parallel_search_slices?: number;
49
+ filters?: Record<string, unknown>;
50
+ expires_at?: string;
51
+ check_status_url?: string;
52
+ message?: string;
53
+ }
54
+ export declare class TikTokSearchSubmission {
55
+ task_id: string;
56
+ task_status: 'processing';
57
+ query: string;
58
+ max_results?: number;
59
+ parallel_search_slices?: number;
60
+ filters?: Record<string, unknown>;
61
+ expires_at?: string;
62
+ check_status_url?: string;
63
+ message?: string;
64
+ constructor(data: TikTokSearchSubmissionJSON);
65
+ static fromJSON(json: TikTokSearchSubmissionJSON): TikTokSearchSubmission;
66
+ }
29
67
  export interface TikTokVideoJSON {
30
68
  id?: string;
31
69
  track?: string | null;
@@ -81,6 +119,66 @@ export interface TikTokProfilePagination {
81
119
  next_cursor?: string | null;
82
120
  prev_cursor?: string | null;
83
121
  }
122
+ export interface TikTokSearchAuthor {
123
+ id?: string | null;
124
+ unique_id?: string | null;
125
+ nickname?: string | null;
126
+ sec_uid?: string | null;
127
+ }
128
+ export interface TikTokSearchResultStats {
129
+ views?: number | null;
130
+ likes?: number | null;
131
+ comments?: number | null;
132
+ shares?: number | null;
133
+ collects?: number | null;
134
+ }
135
+ export interface TikTokSearchMusic {
136
+ id?: string | null;
137
+ title?: string | null;
138
+ author_name?: string | null;
139
+ duration?: number | null;
140
+ }
141
+ export interface TikTokSearchResultJSON {
142
+ id?: string | null;
143
+ item_type?: number | null;
144
+ description?: string | null;
145
+ timestamp?: number | null;
146
+ published_at?: string | null;
147
+ author?: TikTokSearchAuthor;
148
+ stats?: TikTokSearchResultStats;
149
+ music?: TikTokSearchMusic;
150
+ duration?: number | null;
151
+ hashtags?: string[];
152
+ url?: string | null;
153
+ }
154
+ export declare class TikTokSearchResult {
155
+ id?: string | null;
156
+ item_type?: number | null;
157
+ description?: string | null;
158
+ timestamp?: number | null;
159
+ published_at?: Date | null;
160
+ author?: TikTokSearchAuthor;
161
+ stats?: TikTokSearchResultStats;
162
+ music?: TikTokSearchMusic;
163
+ duration?: number | null;
164
+ hashtags?: string[];
165
+ url?: string | null;
166
+ constructor(data: TikTokSearchResultJSON);
167
+ static fromJSON(json: TikTokSearchResultJSON): TikTokSearchResult;
168
+ }
169
+ export interface TikTokSearchFilters {
170
+ after_datetime?: string | null;
171
+ before_datetime?: string | null;
172
+ min_likes?: number | null;
173
+ max_likes?: number | null;
174
+ min_views?: number | null;
175
+ max_views?: number | null;
176
+ }
177
+ export interface TikTokSearchStats {
178
+ pages_fetched?: number;
179
+ results_count?: number;
180
+ next_search_cursor?: number | null;
181
+ }
84
182
  export interface TikTokProfileTaskJSON {
85
183
  task_id: string;
86
184
  task_status: 'processing' | 'completed' | 'failed';
@@ -110,6 +208,42 @@ export declare class TikTokProfileTask {
110
208
  created_at?: string | null;
111
209
  completed_at?: string | null;
112
210
  expires_at?: string | null;
211
+ /** Per-call usage, populated only when polled with `include_usage=true` and `task_status=completed`. */
212
+ usage?: UsageBlock;
113
213
  constructor(data: TikTokProfileTaskJSON);
114
214
  static fromJSON(json: TikTokProfileTaskJSON): TikTokProfileTask;
115
215
  }
216
+ export interface TikTokSearchTaskJSON {
217
+ task_id: string;
218
+ task_status: 'processing' | 'completed' | 'failed';
219
+ query?: string;
220
+ parallel_search_slices?: number;
221
+ filters?: TikTokSearchFilters;
222
+ stats?: TikTokSearchStats;
223
+ results?: TikTokSearchResultJSON[];
224
+ pagination?: TikTokProfilePagination;
225
+ download_url?: string | null;
226
+ error_message?: string | null;
227
+ created_at?: string | null;
228
+ completed_at?: string | null;
229
+ expires_at?: string | null;
230
+ }
231
+ export declare class TikTokSearchTask {
232
+ task_id: string;
233
+ task_status: 'processing' | 'completed' | 'failed';
234
+ query?: string;
235
+ parallel_search_slices?: number;
236
+ filters?: TikTokSearchFilters;
237
+ stats?: TikTokSearchStats;
238
+ results: TikTokSearchResult[];
239
+ pagination?: TikTokProfilePagination;
240
+ download_url?: string | null;
241
+ error_message?: string | null;
242
+ created_at?: string | null;
243
+ completed_at?: string | null;
244
+ expires_at?: string | null;
245
+ /** Per-call usage, populated only when polled with `include_usage=true` and `task_status=completed`. */
246
+ usage?: UsageBlock;
247
+ constructor(data: TikTokSearchTaskJSON);
248
+ static fromJSON(json: TikTokSearchTaskJSON): TikTokSearchTask;
249
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TikTokProfileTask = exports.TikTokVideo = exports.TikTokProfileScrapeSubmission = void 0;
3
+ exports.TikTokSearchTask = exports.TikTokProfileTask = exports.TikTokSearchResult = exports.TikTokVideo = exports.TikTokSearchSubmission = exports.TikTokProfileScrapeSubmission = void 0;
4
4
  function toInteger(value) {
5
5
  if (value === null || value === undefined)
6
6
  return value;
@@ -28,6 +28,18 @@ function normalizeFilters(filters) {
28
28
  max_likes: toInteger(filters.max_likes),
29
29
  };
30
30
  }
31
+ function normalizeSearchFilters(filters) {
32
+ if (!filters)
33
+ return undefined;
34
+ return {
35
+ after_datetime: filters.after_datetime,
36
+ before_datetime: filters.before_datetime,
37
+ min_likes: toInteger(filters.min_likes),
38
+ max_likes: toInteger(filters.max_likes),
39
+ min_views: toInteger(filters.min_views),
40
+ max_views: toInteger(filters.max_views),
41
+ };
42
+ }
31
43
  function normalizeStats(stats) {
32
44
  if (!stats)
33
45
  return undefined;
@@ -37,6 +49,15 @@ function normalizeStats(stats) {
37
49
  pages_consumed: toOptionalInteger(stats.pages_consumed),
38
50
  };
39
51
  }
52
+ function normalizeSearchStats(stats) {
53
+ if (!stats)
54
+ return undefined;
55
+ return {
56
+ pages_fetched: toOptionalInteger(stats.pages_fetched),
57
+ results_count: toOptionalInteger(stats.results_count),
58
+ next_search_cursor: toInteger(stats.next_search_cursor),
59
+ };
60
+ }
40
61
  function normalizePagination(pagination) {
41
62
  if (!pagination)
42
63
  return undefined;
@@ -64,6 +85,23 @@ class TikTokProfileScrapeSubmission {
64
85
  }
65
86
  }
66
87
  exports.TikTokProfileScrapeSubmission = TikTokProfileScrapeSubmission;
88
+ class TikTokSearchSubmission {
89
+ constructor(data) {
90
+ this.task_id = data.task_id;
91
+ this.task_status = data.task_status;
92
+ this.query = data.query;
93
+ this.max_results = toOptionalInteger(data.max_results);
94
+ this.parallel_search_slices = toOptionalInteger(data.parallel_search_slices);
95
+ this.filters = data.filters;
96
+ this.expires_at = data.expires_at;
97
+ this.check_status_url = data.check_status_url;
98
+ this.message = data.message;
99
+ }
100
+ static fromJSON(json) {
101
+ return new TikTokSearchSubmission(json);
102
+ }
103
+ }
104
+ exports.TikTokSearchSubmission = TikTokSearchSubmission;
67
105
  class TikTokVideo {
68
106
  constructor(data) {
69
107
  this.id = data.id;
@@ -86,6 +124,38 @@ class TikTokVideo {
86
124
  }
87
125
  }
88
126
  exports.TikTokVideo = TikTokVideo;
127
+ class TikTokSearchResult {
128
+ constructor(data) {
129
+ this.id = data.id;
130
+ this.item_type = toInteger(data.item_type);
131
+ this.description = data.description;
132
+ this.timestamp = toInteger(data.timestamp);
133
+ this.published_at = toNullableDate(data.published_at);
134
+ this.author = data.author;
135
+ this.stats = data.stats
136
+ ? {
137
+ views: toInteger(data.stats.views),
138
+ likes: toInteger(data.stats.likes),
139
+ comments: toInteger(data.stats.comments),
140
+ shares: toInteger(data.stats.shares),
141
+ collects: toInteger(data.stats.collects),
142
+ }
143
+ : undefined;
144
+ this.music = data.music
145
+ ? {
146
+ ...data.music,
147
+ duration: toInteger(data.music.duration),
148
+ }
149
+ : undefined;
150
+ this.duration = toInteger(data.duration);
151
+ this.hashtags = data.hashtags;
152
+ this.url = data.url;
153
+ }
154
+ static fromJSON(json) {
155
+ return new TikTokSearchResult(json);
156
+ }
157
+ }
158
+ exports.TikTokSearchResult = TikTokSearchResult;
89
159
  class TikTokProfileTask {
90
160
  constructor(data) {
91
161
  this.task_id = data.task_id;
@@ -107,3 +177,24 @@ class TikTokProfileTask {
107
177
  }
108
178
  }
109
179
  exports.TikTokProfileTask = TikTokProfileTask;
180
+ class TikTokSearchTask {
181
+ constructor(data) {
182
+ this.task_id = data.task_id;
183
+ this.task_status = data.task_status;
184
+ this.query = data.query;
185
+ this.parallel_search_slices = toOptionalInteger(data.parallel_search_slices);
186
+ this.filters = normalizeSearchFilters(data.filters);
187
+ this.stats = normalizeSearchStats(data.stats);
188
+ this.results = data.results?.map(TikTokSearchResult.fromJSON) ?? [];
189
+ this.pagination = normalizePagination(data.pagination);
190
+ this.download_url = data.download_url;
191
+ this.error_message = data.error_message;
192
+ this.created_at = data.created_at;
193
+ this.completed_at = data.completed_at;
194
+ this.expires_at = data.expires_at;
195
+ }
196
+ static fromJSON(json) {
197
+ return new TikTokSearchTask(json);
198
+ }
199
+ }
200
+ exports.TikTokSearchTask = TikTokSearchTask;
@@ -1,4 +1,75 @@
1
1
  export type UnlimitedOrNumber = number | 'unlimited';
2
+ /** Meters that can appear in a per-call {@link UsageBlock}. */
3
+ export type UsageServiceType = 'standard_request' | 'residential_request' | 'transcription_hour' | 'analysis_request' | 'search_request' | 'scene_analysis_hour';
4
+ export interface UsageTokens {
5
+ prompt_tokens?: number;
6
+ completion_tokens?: number;
7
+ total_tokens?: number;
8
+ }
9
+ export interface UsageChargeJSON {
10
+ service_type: UsageServiceType;
11
+ quantity: number;
12
+ credits: number;
13
+ waived?: boolean;
14
+ credits_saved?: number;
15
+ tokens?: UsageTokens;
16
+ }
17
+ /** A single consolidated meter charge within a per-call usage block. */
18
+ export declare class UsageCharge {
19
+ service_type: UsageServiceType;
20
+ quantity: number;
21
+ credits: number;
22
+ waived?: boolean;
23
+ credits_saved?: number;
24
+ tokens?: UsageTokens;
25
+ constructor(data: UsageChargeJSON);
26
+ static fromJSON(json: UsageChargeJSON): UsageCharge;
27
+ }
28
+ export interface UsageBlockJSON {
29
+ charges?: UsageChargeJSON[];
30
+ total_credits?: number;
31
+ credits_remaining_after?: number;
32
+ waived?: {
33
+ credits_saved: number;
34
+ };
35
+ /** Legacy flat token fields. Some /extract/* responses may still echo these. */
36
+ prompt_tokens?: number;
37
+ completion_tokens?: number;
38
+ total_tokens?: number;
39
+ }
40
+ /**
41
+ * Per-call usage disclosure returned when a request is made with `include_usage=true`.
42
+ * Lists every meter charged during the request plus the credits actually deducted.
43
+ *
44
+ * LLM token counts live nested inside the `analysis_request` charge; use the
45
+ * {@link UsageBlock.analysis_tokens} accessor to read them (it falls back to the
46
+ * legacy flat token fields when present).
47
+ */
48
+ export declare class UsageBlock {
49
+ charges: UsageCharge[];
50
+ total_credits?: number;
51
+ credits_remaining_after?: number;
52
+ waived?: {
53
+ credits_saved: number;
54
+ };
55
+ /** Legacy flat token fields, only present on some /extract/* responses. */
56
+ prompt_tokens?: number;
57
+ completion_tokens?: number;
58
+ total_tokens?: number;
59
+ constructor(data: UsageBlockJSON);
60
+ /** Return the consolidated charge entry for a given meter, if present. */
61
+ charge_for(service_type: UsageServiceType): UsageCharge | undefined;
62
+ /** camelCase alias for {@link UsageBlock.charge_for}. */
63
+ chargeFor(service_type: UsageServiceType): UsageCharge | undefined;
64
+ /**
65
+ * LLM token tally for this request. Reads the `tokens` object from the
66
+ * `analysis_request` charge, falling back to legacy flat token fields.
67
+ */
68
+ get analysis_tokens(): UsageTokens | undefined;
69
+ /** camelCase alias for {@link UsageBlock.analysis_tokens}. */
70
+ get analysisTokens(): UsageTokens | undefined;
71
+ static fromJSON(json: UsageBlockJSON): UsageBlock;
72
+ }
2
73
  export interface CreditsInfoJSON {
3
74
  monthly_total: UnlimitedOrNumber;
4
75
  monthly_remaining: UnlimitedOrNumber;
@@ -1,6 +1,75 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UsageData = exports.StorageUsage = exports.CapacityMetric = exports.ActivityCount = exports.CreditsInfo = void 0;
3
+ exports.UsageData = exports.StorageUsage = exports.CapacityMetric = exports.ActivityCount = exports.CreditsInfo = exports.UsageBlock = exports.UsageCharge = void 0;
4
+ /** A single consolidated meter charge within a per-call usage block. */
5
+ class UsageCharge {
6
+ constructor(data) {
7
+ this.service_type = data.service_type;
8
+ this.quantity = data.quantity;
9
+ this.credits = data.credits;
10
+ this.waived = data.waived;
11
+ this.credits_saved = data.credits_saved;
12
+ this.tokens = data.tokens;
13
+ }
14
+ static fromJSON(json) {
15
+ return new UsageCharge(json);
16
+ }
17
+ }
18
+ exports.UsageCharge = UsageCharge;
19
+ /**
20
+ * Per-call usage disclosure returned when a request is made with `include_usage=true`.
21
+ * Lists every meter charged during the request plus the credits actually deducted.
22
+ *
23
+ * LLM token counts live nested inside the `analysis_request` charge; use the
24
+ * {@link UsageBlock.analysis_tokens} accessor to read them (it falls back to the
25
+ * legacy flat token fields when present).
26
+ */
27
+ class UsageBlock {
28
+ constructor(data) {
29
+ this.charges = (data.charges ?? []).map(UsageCharge.fromJSON);
30
+ this.total_credits = data.total_credits;
31
+ this.credits_remaining_after = data.credits_remaining_after;
32
+ this.waived = data.waived;
33
+ this.prompt_tokens = data.prompt_tokens;
34
+ this.completion_tokens = data.completion_tokens;
35
+ this.total_tokens = data.total_tokens;
36
+ }
37
+ /** Return the consolidated charge entry for a given meter, if present. */
38
+ charge_for(service_type) {
39
+ return this.charges.find((c) => c.service_type === service_type);
40
+ }
41
+ /** camelCase alias for {@link UsageBlock.charge_for}. */
42
+ chargeFor(service_type) {
43
+ return this.charge_for(service_type);
44
+ }
45
+ /**
46
+ * LLM token tally for this request. Reads the `tokens` object from the
47
+ * `analysis_request` charge, falling back to legacy flat token fields.
48
+ */
49
+ get analysis_tokens() {
50
+ const analysis = this.charge_for('analysis_request');
51
+ if (analysis?.tokens)
52
+ return analysis.tokens;
53
+ if (this.prompt_tokens !== undefined ||
54
+ this.completion_tokens !== undefined ||
55
+ this.total_tokens !== undefined) {
56
+ return {
57
+ prompt_tokens: this.prompt_tokens,
58
+ completion_tokens: this.completion_tokens,
59
+ total_tokens: this.total_tokens,
60
+ };
61
+ }
62
+ return undefined;
63
+ }
64
+ /** camelCase alias for {@link UsageBlock.analysis_tokens}. */
65
+ get analysisTokens() {
66
+ return this.analysis_tokens;
67
+ }
68
+ static fromJSON(json) {
69
+ return new UsageBlock(json);
70
+ }
71
+ }
72
+ exports.UsageBlock = UsageBlock;
4
73
  class CreditsInfo {
5
74
  constructor(data) {
6
75
  this.monthly_total = data.monthly_total;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vidnavigator",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Official JavaScript SDK for the VidNavigator Developer API",
5
5
  "author": "VidNavigator",
6
6
  "license": "Apache-2.0",