vidnavigator 2.4.0 → 2.6.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 +185 -40
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +17 -4
- package/dist/http.js +5 -0
- package/dist/index.d.ts +169 -11
- package/dist/index.js +122 -17
- package/dist/models/AsyncJob.d.ts +18 -2
- package/dist/models/AsyncJob.js +4 -0
- package/dist/models/Extraction.d.ts +29 -6
- package/dist/models/FileInfo.d.ts +15 -0
- package/dist/models/FileInfo.js +3 -0
- package/dist/models/Watch.d.ts +7 -2
- package/dist/models/Watch.js +1 -1
- package/dist/webhooks.d.ts +5 -3
- package/package.json +1 -1
- package/src/errors.ts +29 -0
- package/src/http.ts +14 -0
- package/src/index.ts +293 -51
- package/src/models/AsyncJob.ts +22 -2
- package/src/models/Extraction.ts +68 -52
- package/src/models/FileInfo.ts +19 -0
- package/src/models/Watch.ts +8 -2
- package/src/webhooks.ts +6 -2
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import { FileInfoJSON } from './FileInfo';
|
|
2
2
|
import { VideoInfoJSON } from './VideoInfo';
|
|
3
|
-
|
|
3
|
+
import { ScenesError, WatchTranscriptError } from './Watch';
|
|
4
|
+
/** JSON Schema types a property of an extraction schema can have. */
|
|
5
|
+
export type ExtractionFieldType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
|
|
6
|
+
/**
|
|
7
|
+
* One property of an extraction schema, in standard JSON Schema. Give it a `type` and a
|
|
8
|
+
* `description` (what to put in it); `enum` restricts it to a list of values. Other JSON Schema
|
|
9
|
+
* keywords are accepted (`$ref`, `format`, `minimum`, ...).
|
|
10
|
+
*/
|
|
4
11
|
export interface ExtractionField {
|
|
5
|
-
type
|
|
6
|
-
description
|
|
12
|
+
type?: ExtractionFieldType | Array<ExtractionFieldType | 'null'>;
|
|
13
|
+
description?: string;
|
|
7
14
|
properties?: Record<string, ExtractionField>;
|
|
8
15
|
items?: ExtractionField;
|
|
9
|
-
enum?: string
|
|
16
|
+
enum?: Array<string | number | boolean | null>;
|
|
17
|
+
[keyword: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The fields to extract, as a standard JSON Schema whose root is an object, for example what
|
|
21
|
+
* `zod-to-json-schema` or Pydantic's `model_json_schema()` produce. At most 10 fields per level
|
|
22
|
+
* and 3 levels of nesting.
|
|
23
|
+
*/
|
|
24
|
+
export interface ExtractionSchema {
|
|
25
|
+
type: 'object';
|
|
26
|
+
properties: Record<string, ExtractionField>;
|
|
27
|
+
required?: string[];
|
|
28
|
+
[keyword: string]: unknown;
|
|
10
29
|
}
|
|
11
|
-
/** Custom schema: field name -> field definition */
|
|
12
|
-
export type ExtractionSchema = Record<string, ExtractionField>;
|
|
13
30
|
export interface ExtractionTokenUsageJSON {
|
|
14
31
|
prompt_tokens?: number;
|
|
15
32
|
completion_tokens?: number;
|
|
@@ -20,6 +37,12 @@ export interface ExtractionResponseJSON {
|
|
|
20
37
|
data: Record<string, unknown>;
|
|
21
38
|
video_info?: VideoInfoJSON;
|
|
22
39
|
file_info?: FileInfoJSON;
|
|
40
|
+
/** With `include_scenes`: number of frames that were analyzed to produce the scenes. */
|
|
41
|
+
frames_analyzed?: number;
|
|
42
|
+
scenes_error?: ScenesError;
|
|
43
|
+
transcript_error?: WatchTranscriptError;
|
|
44
|
+
/** When the request had no schema: the schema written from `what_to_extract`, to pass as `schema` next time. */
|
|
45
|
+
schema?: ExtractionSchema;
|
|
23
46
|
usage?: ExtractionTokenUsageJSON;
|
|
24
47
|
}
|
|
25
48
|
export declare class ExtractionTokenUsage {
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { NamespaceRef, NamespaceRefJSON } from './Namespace';
|
|
2
|
+
import { ScenesError } from './Watch';
|
|
2
3
|
export type FileStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled';
|
|
4
|
+
/**
|
|
5
|
+
* Where the scene analysis of a file stands. `none`: never asked for. `completed`: the scenes are
|
|
6
|
+
* returned by `getFile()`. `failed`: see `scenes_error`.
|
|
7
|
+
*/
|
|
8
|
+
export type FileScenesStatus = 'none' | 'processing' | 'completed' | 'failed';
|
|
3
9
|
export interface FileInfoJSON {
|
|
4
10
|
id: string;
|
|
5
11
|
name: string;
|
|
@@ -12,6 +18,9 @@ export interface FileInfoJSON {
|
|
|
12
18
|
original_file_date?: string;
|
|
13
19
|
has_transcript?: boolean;
|
|
14
20
|
error_message?: string;
|
|
21
|
+
scenes_status?: FileScenesStatus;
|
|
22
|
+
frames_analyzed?: number;
|
|
23
|
+
scenes_error?: ScenesError;
|
|
15
24
|
namespace_ids?: string[];
|
|
16
25
|
namespaces?: NamespaceRefJSON[];
|
|
17
26
|
}
|
|
@@ -30,6 +39,12 @@ export declare class FileInfo {
|
|
|
30
39
|
original_file_date?: string;
|
|
31
40
|
has_transcript?: boolean;
|
|
32
41
|
error_message?: string;
|
|
42
|
+
/** Where the scene analysis of the file stands. */
|
|
43
|
+
scenes_status?: FileScenesStatus;
|
|
44
|
+
/** Number of frames that were analyzed to produce the scenes. Present when `scenes_status` is `completed`. */
|
|
45
|
+
frames_analyzed?: number;
|
|
46
|
+
/** Present when `scenes_status` is `failed`. `frames_not_available` means the file has no picture (an audio file). */
|
|
47
|
+
scenes_error?: ScenesError;
|
|
33
48
|
namespace_ids?: string[];
|
|
34
49
|
namespaces?: NamespaceRef[];
|
|
35
50
|
constructor(data: FileInfoJSON);
|
package/dist/models/FileInfo.js
CHANGED
|
@@ -18,6 +18,9 @@ class FileInfo {
|
|
|
18
18
|
this.original_file_date = data.original_file_date;
|
|
19
19
|
this.has_transcript = data.has_transcript;
|
|
20
20
|
this.error_message = data.error_message;
|
|
21
|
+
this.scenes_status = data.scenes_status;
|
|
22
|
+
this.frames_analyzed = data.frames_analyzed;
|
|
23
|
+
this.scenes_error = data.scenes_error;
|
|
21
24
|
this.namespace_ids = data.namespace_ids;
|
|
22
25
|
this.namespaces = data.namespaces?.map(Namespace_1.NamespaceRef.fromJSON);
|
|
23
26
|
}
|
package/dist/models/Watch.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface VideoSceneJSON {
|
|
|
7
7
|
description?: string;
|
|
8
8
|
on_screen_text?: string;
|
|
9
9
|
}
|
|
10
|
-
/** What a video shows between `start` and `end`. */
|
|
10
|
+
/** What a video, or an uploaded file, shows between `start` and `end`. */
|
|
11
11
|
export declare class VideoScene {
|
|
12
12
|
/** Start of the scene, in seconds from the beginning of the video. */
|
|
13
13
|
start: number;
|
|
@@ -20,11 +20,16 @@ export declare class VideoScene {
|
|
|
20
20
|
constructor(data: VideoSceneJSON);
|
|
21
21
|
static fromJSON(json: VideoSceneJSON): VideoScene;
|
|
22
22
|
}
|
|
23
|
-
/** Why a
|
|
23
|
+
/** Why a video or a file came back without a transcript (e.g. `transcript_not_available`). */
|
|
24
24
|
export interface WatchTranscriptError {
|
|
25
25
|
error?: string;
|
|
26
26
|
message?: string;
|
|
27
27
|
}
|
|
28
|
+
/** Why the scenes of a video or a file could not be had (e.g. `frames_not_available`). */
|
|
29
|
+
export interface ScenesError {
|
|
30
|
+
error?: string;
|
|
31
|
+
message?: string;
|
|
32
|
+
}
|
|
28
33
|
export interface WatchResultJSON {
|
|
29
34
|
video_info: VideoInfoJSON;
|
|
30
35
|
transcript?: TranscriptOutputJSON;
|
package/dist/models/Watch.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WatchResult = exports.VideoScene = void 0;
|
|
4
4
|
const VideoInfo_1 = require("./VideoInfo");
|
|
5
5
|
const TranscriptSegment_1 = require("./TranscriptSegment");
|
|
6
|
-
/** What a video shows between `start` and `end`. */
|
|
6
|
+
/** What a video, or an uploaded file, shows between `start` and `end`. */
|
|
7
7
|
class VideoScene {
|
|
8
8
|
constructor(data) {
|
|
9
9
|
this.start = data.start;
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncJobError } from './models';
|
|
2
2
|
/** Event types delivered to a `webhook_url` when an async job reaches a terminal state. */
|
|
3
|
-
export type WebhookEventType = 'transcribe.completed' | 'transcribe.failed' | 'watch.completed' | 'watch.failed' | 'extract_video.completed' | 'extract_video.failed' | 'tweet_statement.completed' | 'tweet_statement.failed' | 'tiktok_profile.completed' | 'tiktok_profile.failed' | 'tiktok_search.completed' | 'tiktok_search.failed' | 'tiktok_live_search.completed' | 'tiktok_live_search.failed';
|
|
3
|
+
export type WebhookEventType = 'transcribe.completed' | 'transcribe.failed' | 'watch.completed' | 'watch.failed' | 'analyze_video.completed' | 'analyze_video.failed' | 'extract_video.completed' | 'extract_video.failed' | 'tweet_statement.completed' | 'tweet_statement.failed' | 'tiktok_profile.completed' | 'tiktok_profile.failed' | 'tiktok_search.completed' | 'tiktok_search.failed' | 'tiktok_live_search.completed' | 'tiktok_live_search.failed';
|
|
4
4
|
/** `data.result` of a `tiktok_profile.*` / `tiktok_search.*` / `tiktok_live_search.*` event: a summary, not the items. */
|
|
5
5
|
export interface TikTokWebhookResult {
|
|
6
6
|
/** Same fields as the task's `stats` (e.g. `videos_matched`, or `results_count` / `sort_by` for searches). */
|
|
@@ -21,8 +21,8 @@ export interface WebhookEvent {
|
|
|
21
21
|
job_type?: string;
|
|
22
22
|
check_status_url?: string;
|
|
23
23
|
/**
|
|
24
|
-
* Raw (unparsed) result of the completed job. For transcription, watch, extraction and tweet
|
|
25
|
-
* it is the same data the job's `result()` parses. For TikTok tasks it is a summary only,
|
|
24
|
+
* Raw (unparsed) result of the completed job. For transcription, watch, analysis, extraction and tweet
|
|
25
|
+
* jobs it is the same data the job's `result()` parses. For TikTok tasks it is a summary only,
|
|
26
26
|
* {@link TikTokWebhookResult} (a scrape can hold thousands of videos); fetch the videos with
|
|
27
27
|
* `vn.tiktokProfile.resume(task_id).result()`. Omitted when `result_truncated` is true.
|
|
28
28
|
*/
|
|
@@ -31,6 +31,8 @@ export interface WebhookEvent {
|
|
|
31
31
|
result_truncated?: boolean;
|
|
32
32
|
/** `extract_video.completed` only: raw `video_info` of the video. Sent even when `result_truncated` is true. */
|
|
33
33
|
video_info?: Record<string, unknown>;
|
|
34
|
+
/** `extract_video.completed` only, when the request had no schema: the schema written from `what_to_extract`. */
|
|
35
|
+
schema?: Record<string, unknown>;
|
|
34
36
|
error?: AsyncJobError | null;
|
|
35
37
|
};
|
|
36
38
|
}
|
package/package.json
CHANGED
package/src/errors.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Custom exception classes for VidNavigator SDK.
|
|
3
3
|
*/
|
|
4
|
+
import { FileScenesStatus, ScenesError } from './models';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Base class for all VidNavigator SDK errors.
|
|
@@ -181,6 +182,34 @@ export class TooManyActiveJobsError extends RateLimitExceededError {
|
|
|
181
182
|
}
|
|
182
183
|
}
|
|
183
184
|
|
|
185
|
+
/**
|
|
186
|
+
* Raised when `include_scenes` was asked on an uploaded file that has no scenes to read
|
|
187
|
+
* (HTTP 409, `scenes_not_available`). `scenes_status` says where their analysis stands: `none`
|
|
188
|
+
* (never asked for: start it with `analyzeFileScenes(file_id)`), `processing` (call again once
|
|
189
|
+
* `getFile()` reports `completed`) or `failed` (see `scenes_error`).
|
|
190
|
+
*/
|
|
191
|
+
export class ScenesNotAvailableError extends VidNavigatorError {
|
|
192
|
+
public readonly scenes_status?: Exclude<FileScenesStatus, 'completed'>;
|
|
193
|
+
/** Present when `scenes_status` is `failed`, e.g. `frames_not_available` for an audio file. */
|
|
194
|
+
public readonly scenes_error?: ScenesError;
|
|
195
|
+
|
|
196
|
+
constructor(
|
|
197
|
+
message: string,
|
|
198
|
+
status_code?: number,
|
|
199
|
+
error_code?: string,
|
|
200
|
+
error_message?: string,
|
|
201
|
+
details?: any,
|
|
202
|
+
scenes_status?: Exclude<FileScenesStatus, 'completed'>,
|
|
203
|
+
scenes_error?: ScenesError
|
|
204
|
+
) {
|
|
205
|
+
super(message, status_code, error_code, error_message, details);
|
|
206
|
+
this.name = 'ScenesNotAvailableError';
|
|
207
|
+
this.scenes_status = scenes_status;
|
|
208
|
+
this.scenes_error = scenes_error;
|
|
209
|
+
Object.setPrototypeOf(this, ScenesNotAvailableError.prototype);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
184
213
|
/**
|
|
185
214
|
* Raised when waiting for a job exceeds `timeoutMs`. Always carries `task_id`: the job keeps
|
|
186
215
|
* running server-side and its result stays readable for 1 hour after it finishes, so resume it
|
package/src/http.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
SystemOverloadError,
|
|
16
16
|
InsufficientCreditsError,
|
|
17
17
|
TooManyActiveJobsError,
|
|
18
|
+
ScenesNotAvailableError,
|
|
18
19
|
} from './errors';
|
|
19
20
|
|
|
20
21
|
export function parseApiErrorPayload(data: any): {
|
|
@@ -50,6 +51,19 @@ export function buildApiError(status: number, data: any, fallbackMessage?: strin
|
|
|
50
51
|
return new AccessDeniedError(message, status, errorCode, errorMessage, details);
|
|
51
52
|
case 404:
|
|
52
53
|
return new NotFoundError(message, status, errorCode, errorMessage, details);
|
|
54
|
+
case 409:
|
|
55
|
+
if (errorCode === 'scenes_not_available') {
|
|
56
|
+
return new ScenesNotAvailableError(
|
|
57
|
+
message,
|
|
58
|
+
status,
|
|
59
|
+
errorCode,
|
|
60
|
+
errorMessage,
|
|
61
|
+
details,
|
|
62
|
+
data?.scenes_status,
|
|
63
|
+
data?.scenes_error
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return new VidNavigatorError(message, status, errorCode, errorMessage, details);
|
|
53
67
|
case 413:
|
|
54
68
|
return new StorageQuotaExceededError(message, status, errorCode, errorMessage, details);
|
|
55
69
|
case 429:
|