vidnavigator 2.5.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 +52 -24
- package/dist/index.d.ts +15 -5
- package/dist/index.js +17 -1
- package/dist/models/AsyncJob.d.ts +5 -0
- package/dist/models/AsyncJob.js +1 -0
- package/dist/models/Extraction.d.ts +24 -6
- package/dist/webhooks.d.ts +2 -0
- package/package.json +1 -1
- package/src/index.ts +33 -5
- package/src/models/AsyncJob.ts +6 -0
- package/src/models/Extraction.ts +24 -13
- package/src/webhooks.ts +2 -0
package/README.md
CHANGED
|
@@ -258,8 +258,11 @@ results.forEach((r, i) => console.log(urls[i], r.status === 'fulfilled' ? r.valu
|
|
|
258
258
|
const job = await vn.extractVideo.submit({
|
|
259
259
|
video_url: 'https://www.facebook.com/watch/?v=1234567890',
|
|
260
260
|
schema: {
|
|
261
|
-
|
|
262
|
-
|
|
261
|
+
type: 'object',
|
|
262
|
+
properties: {
|
|
263
|
+
speakers: { type: 'array', description: 'Names of everyone who speaks', items: { type: 'string' } },
|
|
264
|
+
verdict: { type: 'string', description: 'The final conclusion of the video' },
|
|
265
|
+
},
|
|
263
266
|
},
|
|
264
267
|
});
|
|
265
268
|
|
|
@@ -492,12 +495,15 @@ for (const video of videos) {
|
|
|
492
495
|
const { data } = await vn.extractVideoData({
|
|
493
496
|
video_url: video.url,
|
|
494
497
|
schema: {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
type: '
|
|
499
|
-
|
|
500
|
-
|
|
498
|
+
type: 'object',
|
|
499
|
+
properties: {
|
|
500
|
+
hook: { type: 'string', description: 'The opening hook or premise' },
|
|
501
|
+
products: { type: 'array', description: 'Products or brands mentioned', items: { type: 'string' } },
|
|
502
|
+
sentiment: {
|
|
503
|
+
type: 'string',
|
|
504
|
+
description: 'Overall sentiment',
|
|
505
|
+
enum: ['positive', 'negative', 'neutral', 'mixed'],
|
|
506
|
+
},
|
|
501
507
|
},
|
|
502
508
|
},
|
|
503
509
|
what_to_extract: 'Extract creator messaging and product mentions.',
|
|
@@ -748,7 +754,7 @@ console.log(`${scenes?.length} scenes from ${frames_analyzed} frames`);
|
|
|
748
754
|
|
|
749
755
|
- When the picture cannot be read, the analysis is made from the transcript alone: `scenes` is empty and `scenes_error` says why. A video without a transcript is analyzed from its scenes, and `transcript_error` says why the transcript is missing.
|
|
750
756
|
- With scenes, the segments an answer refers to (`best_segment_index`, `relevant_segments`) are counted among the transcript segments and the scenes together, in chronological order. Use `transcript_analysis.timestamp` to locate the moment.
|
|
751
|
-
- With `include_usage: true`, the frames are the `frame_analysis` charge of the `usage` block: 1 credit per
|
|
757
|
+
- With `include_usage: true`, the frames are the `frame_analysis` charge of the `usage` block: 1 credit per 2,000 frames analyzed, with at least 667 frames per hour of video; for an uploaded file the frames are charged once, when its scenes are analyzed.
|
|
752
758
|
|
|
753
759
|
`analyzeVideo()` waits on a single HTTP request. With `include_scenes` on a video longer than about 10 minutes, use `vn.analyze()`: it runs the same analysis as a [background job](#3-background-jobs-one-call-or-many-at-once) and returns the same result.
|
|
754
760
|
|
|
@@ -766,17 +772,19 @@ const later = await vn.analyze.resume(job.task_id).result();
|
|
|
766
772
|
|
|
767
773
|
### 9. Extract structured data
|
|
768
774
|
|
|
769
|
-
Define a schema and get back clean, structured data extracted from any video or file transcript.
|
|
775
|
+
Define a schema, as a standard JSON Schema, and get back clean, structured data extracted from any video or file transcript. Or skip the schema and say what you want in plain words with `what_to_extract`. Per-call usage tracking included (see [Per-call usage](#per-call-usage)).
|
|
770
776
|
|
|
771
777
|
```ts
|
|
772
778
|
const { data, usage } = await vn.extractVideoData({
|
|
773
779
|
video_url: 'https://youtube.com/watch?v=dQw4w9WgXcQ',
|
|
774
780
|
schema: {
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
781
|
+
type: 'object',
|
|
782
|
+
properties: {
|
|
783
|
+
topic: { type: 'string', description: 'Main topic of the video' },
|
|
784
|
+
language: { type: 'string', description: 'Primary spoken language (ISO 639-1)' },
|
|
785
|
+
tone: { type: 'string', description: 'Overall tone', enum: ['positive', 'negative', 'neutral', 'mixed'] },
|
|
786
|
+
key_quotes: { type: 'array', description: 'Top 3 memorable quotes', items: { type: 'string' } },
|
|
787
|
+
},
|
|
780
788
|
},
|
|
781
789
|
what_to_extract: 'Determine the topic, language, tone, and notable quotes.',
|
|
782
790
|
include_usage: true,
|
|
@@ -801,10 +809,12 @@ Also works on uploaded files:
|
|
|
801
809
|
const { data } = await vn.extractFileData({
|
|
802
810
|
file_id: 'your-file-id',
|
|
803
811
|
schema: {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
812
|
+
type: 'object',
|
|
813
|
+
properties: {
|
|
814
|
+
action_items: { type: 'array', description: 'List of action items from the meeting', items: { type: 'string' } },
|
|
815
|
+
next_meeting: { type: 'string', description: 'When is the next meeting scheduled?' },
|
|
816
|
+
sentiment: { type: 'string', description: 'Overall meeting mood', enum: ['productive', 'tense', 'casual', 'urgent'] },
|
|
817
|
+
},
|
|
808
818
|
},
|
|
809
819
|
});
|
|
810
820
|
```
|
|
@@ -825,8 +835,11 @@ Pass `include_scenes: true` to extract from what the video shows as well as what
|
|
|
825
835
|
const { data, frames_analyzed } = await vn.extractVideoData({
|
|
826
836
|
video_url: 'https://www.tiktok.com/@user/video/1234567890',
|
|
827
837
|
schema: {
|
|
828
|
-
|
|
829
|
-
|
|
838
|
+
type: 'object',
|
|
839
|
+
properties: {
|
|
840
|
+
dish: { type: 'string', description: 'Name of the dish' },
|
|
841
|
+
ingredients: { type: 'array', description: 'Every ingredient with its quantity', items: { type: 'string' } },
|
|
842
|
+
},
|
|
830
843
|
},
|
|
831
844
|
include_scenes: true,
|
|
832
845
|
});
|
|
@@ -836,11 +849,21 @@ console.log(data, frames_analyzed); // quantities that are only written on scree
|
|
|
836
849
|
|
|
837
850
|
When the picture cannot be read, the fields are extracted from the transcript alone and the result has a `scenes_error`; a video without a transcript is extracted from its scenes, with a `transcript_error`. The same option works on an uploaded file, `vn.extractFileData({ file_id, schema, include_scenes: true })`, once the file has its scenes (see [Scenes of an uploaded file](#8b-scenes-of-an-uploaded-file)).
|
|
838
851
|
|
|
839
|
-
**
|
|
852
|
+
**Schema format:** a standard JSON Schema whose root is an object, `{ type: 'object', properties: { ... } }`. Property types: `string`, `number`, `integer`, `boolean`, `array` (with `items`, the schema of one element) and `object` (with its own `properties`); `enum` restricts a property to a list of values. Give each property a `description`: it tells what to put in it. At most 10 fields per level and 3 levels of nesting. A Zod schema converted with `zod-to-json-schema` works as it is. `required` and `additionalProperties` change nothing: a field the video does not give comes back as `null`. An invalid schema is rejected with a `BadRequestError` before anything runs.
|
|
853
|
+
|
|
854
|
+
**Without a schema:** pass `what_to_extract` alone. The schema is written for you and comes back as `schema` on the result; pass it as `schema` next time to get the same fields.
|
|
855
|
+
|
|
856
|
+
```ts
|
|
857
|
+
const { data, schema } = await vn.extractVideoData({
|
|
858
|
+
video_url: 'https://youtube.com/watch?v=dQw4w9WgXcQ',
|
|
859
|
+
what_to_extract: 'The mood of the song and every topic it touches on',
|
|
860
|
+
});
|
|
840
861
|
|
|
841
|
-
|
|
862
|
+
console.log(data); // { mood: "upbeat", topics: ["love", "commitment"] }
|
|
863
|
+
console.log(schema); // { type: "object", properties: { mood: {...}, topics: {...} }, ... }
|
|
864
|
+
```
|
|
842
865
|
|
|
843
|
-
> `extractVideoData()` runs as a background job, so videos of any length work. For many extractions at once, use `vn.extractVideo.submit()` (see [Background jobs](#3-background-jobs-one-call-or-many-at-once)). The result has `data` (the extracted fields), `video_info` (the video's metadata), `frames_analyzed` with `include_scenes`, and `usage` when requested.
|
|
866
|
+
> `extractVideoData()` runs as a background job, so videos of any length work. For many extractions at once, use `vn.extractVideo.submit()` (see [Background jobs](#3-background-jobs-one-call-or-many-at-once)). The result has `data` (the extracted fields), `video_info` (the video's metadata), `frames_analyzed` with `include_scenes`, `schema` when it was written from `what_to_extract`, and `usage` when requested.
|
|
844
867
|
|
|
845
868
|
### 10. Semantic search
|
|
846
869
|
|
|
@@ -1173,6 +1196,11 @@ All API responses are parsed into typed classes with static `fromJSON()` constru
|
|
|
1173
1196
|
| `TikTokLiveRoomDetail` | A `TikTokLiveRoom` from `getTikTokLiveRoom`: `status` / `isLive`, `ended_at`, `stats.new_followers`, `author.bio`, `share_url`, `chat_enabled`, `subscribers_only`, `products` |
|
|
1174
1197
|
| `TweetStatement` | Structured X/Twitter claim analysis, topics, entities, tone, intent, and source text |
|
|
1175
1198
|
|
|
1199
|
+
## What's new in 2.6.0
|
|
1200
|
+
|
|
1201
|
+
- **Extraction takes a standard JSON Schema**, the only schema format the API accepts now: `{ type: 'object', properties: { ... } }`, with lowercase types. A Zod schema converted with `zod-to-json-schema` can be passed as it is. The former format (`{ field: { type: 'String', ... } }`) is refused with `invalid_schema`. The `ExtractionSchema` and `ExtractionField` types describe the new format.
|
|
1202
|
+
- **Extraction without a schema:** `extractVideoData`, `vn.extractVideo` and `extractFileData` take `what_to_extract` alone; the schema written for it comes back as `schema` on the result (and on the `extract_video.completed` webhook event).
|
|
1203
|
+
|
|
1176
1204
|
## What's new in 2.5.0
|
|
1177
1205
|
|
|
1178
1206
|
- **Scenes in analysis and extraction:** `include_scenes: true` on `analyzeVideo()`, `analyzeFile()`, `extractVideo()` / `extractVideoData()` and `extractFileData()` makes the analysis or the extraction from what the video shows as well as what it says. Analysis results gain `scenes` and `frames_analyzed`, extraction results gain `frames_analyzed`; `scenes_error` and `transcript_error` say when one of the two could not be had.
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export * from './webhooks';
|
|
|
7
7
|
export { Job } from './jobs';
|
|
8
8
|
export type { TaskStatus, PollableTask, PollOptions, JobOperation, SubmitOptions, RunOptions, JobInfo } from './jobs';
|
|
9
9
|
/** SDK version (keep in sync with package.json) */
|
|
10
|
-
export declare const SDK_VERSION = "2.
|
|
10
|
+
export declare const SDK_VERSION = "2.6.0";
|
|
11
11
|
export interface SDKConfig {
|
|
12
12
|
apiKey: string;
|
|
13
13
|
baseURL?: string;
|
|
@@ -75,10 +75,16 @@ export type AnalyzeVideoInput = {
|
|
|
75
75
|
/** Return the transcript as a single string instead of segments. */
|
|
76
76
|
transcript_text?: boolean;
|
|
77
77
|
} & WebhookOption;
|
|
78
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* Input for {@link VidNavigatorClient.extractVideo}: a JSON Schema `schema`, or a JSON/YAML
|
|
80
|
+
* `schemaFilePath`, or neither with `what_to_extract`: the schema is then written from that text
|
|
81
|
+
* and comes back as `schema` on the result.
|
|
82
|
+
*/
|
|
79
83
|
export type ExtractVideoInput = ({
|
|
80
84
|
video_url: string;
|
|
81
|
-
|
|
85
|
+
/** The fields to extract, as a standard JSON Schema. Optional when `what_to_extract` is given. */
|
|
86
|
+
schema?: ExtractionSchema;
|
|
87
|
+
/** What to extract, in plain words. Guides the extraction, or alone, writes the schema. */
|
|
82
88
|
what_to_extract?: string;
|
|
83
89
|
/** Speech-to-text the audio when no platform transcript exists. Default true. */
|
|
84
90
|
transcribe?: boolean;
|
|
@@ -185,6 +191,8 @@ export type GetFileResult = {
|
|
|
185
191
|
};
|
|
186
192
|
export interface ExtractDataResult {
|
|
187
193
|
data: Record<string, unknown>;
|
|
194
|
+
/** When the request had no schema: the schema written from `what_to_extract`, to pass as `schema` next time. */
|
|
195
|
+
schema?: ExtractionSchema;
|
|
188
196
|
video_info?: VideoInfo;
|
|
189
197
|
file_info?: FileInfo;
|
|
190
198
|
/** With `include_scenes: true`: number of frames that were analyzed to produce the scenes. */
|
|
@@ -295,7 +303,8 @@ export type AnalyzeFileResult = {
|
|
|
295
303
|
};
|
|
296
304
|
export type ExtractVideoDataPayload = {
|
|
297
305
|
video_url: string;
|
|
298
|
-
|
|
306
|
+
/** A standard JSON Schema. Optional when `what_to_extract` is given. */
|
|
307
|
+
schema?: ExtractionSchema;
|
|
299
308
|
what_to_extract?: string;
|
|
300
309
|
transcribe?: boolean;
|
|
301
310
|
/**
|
|
@@ -319,7 +328,8 @@ export type TweetStatementPayload = {
|
|
|
319
328
|
} & WebhookOption;
|
|
320
329
|
export type ExtractFileDataPayload = {
|
|
321
330
|
file_id: string;
|
|
322
|
-
|
|
331
|
+
/** A standard JSON Schema. Optional when `what_to_extract` is given. */
|
|
332
|
+
schema?: ExtractionSchema;
|
|
323
333
|
what_to_extract?: string;
|
|
324
334
|
/**
|
|
325
335
|
* Default false. `true` extracts from the transcript of the file and its scenes together. The
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ __exportStar(require("./webhooks"), exports);
|
|
|
31
31
|
var jobs_2 = require("./jobs");
|
|
32
32
|
Object.defineProperty(exports, "Job", { enumerable: true, get: function () { return jobs_2.Job; } });
|
|
33
33
|
/** SDK version (keep in sync with package.json) */
|
|
34
|
-
exports.SDK_VERSION = '2.
|
|
34
|
+
exports.SDK_VERSION = '2.6.0';
|
|
35
35
|
/**
|
|
36
36
|
* A LIVE room usually answers in 1-5 s, up to ~30 s when the API has to open a TikTok page, and two
|
|
37
37
|
* minutes at worst. A shorter configured axios timeout is raised to this for that call only.
|
|
@@ -53,6 +53,18 @@ function parseTranscribeData(inner, usage) {
|
|
|
53
53
|
usage,
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* An extraction needs a schema (`schema` or `schemaFilePath`) or, without one, `what_to_extract`,
|
|
58
|
+
* from which the API writes the schema. Checked before anything is sent.
|
|
59
|
+
*/
|
|
60
|
+
function checkSchemaInput(input) {
|
|
61
|
+
if (input.schema !== undefined && input.schemaFilePath !== undefined) {
|
|
62
|
+
throw new Error('Pass at most one of schema or schemaFilePath.');
|
|
63
|
+
}
|
|
64
|
+
if (input.schema === undefined && input.schemaFilePath === undefined && !input.what_to_extract?.trim()) {
|
|
65
|
+
throw new Error('Pass schema, schemaFilePath or what_to_extract.');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
56
68
|
// The scene fields are set only when the response carries them, so a result asked without
|
|
57
69
|
// `include_scenes` keeps the shape it always had.
|
|
58
70
|
function pickSceneNotes(raw) {
|
|
@@ -178,6 +190,7 @@ class VidNavigatorClient {
|
|
|
178
190
|
data: requireResult(task),
|
|
179
191
|
video_info: task.video_info,
|
|
180
192
|
...pickSceneNotes(task),
|
|
193
|
+
...(task.schema ? { schema: task.schema } : {}),
|
|
181
194
|
usage: task.usage,
|
|
182
195
|
}),
|
|
183
196
|
});
|
|
@@ -239,6 +252,7 @@ class VidNavigatorClient {
|
|
|
239
252
|
return { ...accepted, job_type: accepted.job_type ?? url.split('/')[1] };
|
|
240
253
|
}
|
|
241
254
|
submitExtractVideo(input) {
|
|
255
|
+
checkSchemaInput(input);
|
|
242
256
|
if ('schemaFilePath' in input) {
|
|
243
257
|
const form = new form_data_1.default();
|
|
244
258
|
form.append('video_url', input.video_url);
|
|
@@ -578,6 +592,7 @@ class VidNavigatorClient {
|
|
|
578
592
|
* is refused with `ScenesNotAvailableError` (HTTP 409).
|
|
579
593
|
*/
|
|
580
594
|
async extractFileData(payload) {
|
|
595
|
+
checkSchemaInput(payload);
|
|
581
596
|
let body;
|
|
582
597
|
if ('schemaFilePath' in payload) {
|
|
583
598
|
const form = new form_data_1.default();
|
|
@@ -595,6 +610,7 @@ class VidNavigatorClient {
|
|
|
595
610
|
data: body.data,
|
|
596
611
|
file_info: body.file_info ? models_1.FileInfo.fromJSON(body.file_info) : undefined,
|
|
597
612
|
...pickSceneNotes(body),
|
|
613
|
+
...(body.schema ? { schema: body.schema } : {}),
|
|
598
614
|
usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
|
|
599
615
|
};
|
|
600
616
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ExtractionSchema } from './Extraction';
|
|
1
2
|
import { UsageBlock } from './Usage';
|
|
2
3
|
import { VideoInfo, VideoInfoJSON } from './VideoInfo';
|
|
3
4
|
import { ScenesError, WatchTranscriptError } from './Watch';
|
|
@@ -71,6 +72,8 @@ export interface AsyncJobJSON {
|
|
|
71
72
|
frames_analyzed?: number;
|
|
72
73
|
scenes_error?: ScenesError;
|
|
73
74
|
transcript_error?: WatchTranscriptError;
|
|
75
|
+
/** `extract_video` jobs, once completed, when the request had no schema: the schema written from `what_to_extract`. */
|
|
76
|
+
schema?: ExtractionSchema;
|
|
74
77
|
error?: AsyncJobError | null;
|
|
75
78
|
}
|
|
76
79
|
/**
|
|
@@ -100,6 +103,8 @@ export declare class AsyncJob<TResult> {
|
|
|
100
103
|
scenes_error?: ScenesError;
|
|
101
104
|
/** `extract_video` jobs with `include_scenes`: why there is no transcript. The fields were then extracted from the scenes alone. */
|
|
102
105
|
transcript_error?: WatchTranscriptError;
|
|
106
|
+
/** `extract_video` jobs, once completed, when the request had no schema: the schema written from `what_to_extract`, to pass as `schema` next time. */
|
|
107
|
+
schema?: ExtractionSchema;
|
|
103
108
|
error: AsyncJobError | null;
|
|
104
109
|
/** Per-call usage, populated only when polled with `include_usage: true` and `task_status === 'completed'`. */
|
|
105
110
|
usage?: UsageBlock;
|
package/dist/models/AsyncJob.js
CHANGED
|
@@ -41,6 +41,7 @@ class AsyncJob {
|
|
|
41
41
|
this.frames_analyzed = data.frames_analyzed;
|
|
42
42
|
this.scenes_error = data.scenes_error;
|
|
43
43
|
this.transcript_error = data.transcript_error;
|
|
44
|
+
this.schema = data.schema;
|
|
44
45
|
this.error = data.error ?? null;
|
|
45
46
|
}
|
|
46
47
|
static fromJSON(json, parseResult) {
|
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
import { FileInfoJSON } from './FileInfo';
|
|
2
2
|
import { VideoInfoJSON } from './VideoInfo';
|
|
3
3
|
import { ScenesError, WatchTranscriptError } from './Watch';
|
|
4
|
-
|
|
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
|
+
*/
|
|
5
11
|
export interface ExtractionField {
|
|
6
|
-
type
|
|
7
|
-
description
|
|
12
|
+
type?: ExtractionFieldType | Array<ExtractionFieldType | 'null'>;
|
|
13
|
+
description?: string;
|
|
8
14
|
properties?: Record<string, ExtractionField>;
|
|
9
15
|
items?: ExtractionField;
|
|
10
|
-
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;
|
|
11
29
|
}
|
|
12
|
-
/** Custom schema: field name -> field definition */
|
|
13
|
-
export type ExtractionSchema = Record<string, ExtractionField>;
|
|
14
30
|
export interface ExtractionTokenUsageJSON {
|
|
15
31
|
prompt_tokens?: number;
|
|
16
32
|
completion_tokens?: number;
|
|
@@ -25,6 +41,8 @@ export interface ExtractionResponseJSON {
|
|
|
25
41
|
frames_analyzed?: number;
|
|
26
42
|
scenes_error?: ScenesError;
|
|
27
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;
|
|
28
46
|
usage?: ExtractionTokenUsageJSON;
|
|
29
47
|
}
|
|
30
48
|
export declare class ExtractionTokenUsage {
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -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/index.ts
CHANGED
|
@@ -72,7 +72,7 @@ export { Job } from './jobs';
|
|
|
72
72
|
export type { TaskStatus, PollableTask, PollOptions, JobOperation, SubmitOptions, RunOptions, JobInfo } from './jobs';
|
|
73
73
|
|
|
74
74
|
/** SDK version (keep in sync with package.json) */
|
|
75
|
-
export const SDK_VERSION = '2.
|
|
75
|
+
export const SDK_VERSION = '2.6.0';
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* A LIVE room usually answers in 1-5 s, up to ~30 s when the API has to open a TikTok page, and two
|
|
@@ -159,11 +159,17 @@ export type AnalyzeVideoInput = {
|
|
|
159
159
|
transcript_text?: boolean;
|
|
160
160
|
} & WebhookOption;
|
|
161
161
|
|
|
162
|
-
/**
|
|
162
|
+
/**
|
|
163
|
+
* Input for {@link VidNavigatorClient.extractVideo}: a JSON Schema `schema`, or a JSON/YAML
|
|
164
|
+
* `schemaFilePath`, or neither with `what_to_extract`: the schema is then written from that text
|
|
165
|
+
* and comes back as `schema` on the result.
|
|
166
|
+
*/
|
|
163
167
|
export type ExtractVideoInput =
|
|
164
168
|
| ({
|
|
165
169
|
video_url: string;
|
|
166
|
-
|
|
170
|
+
/** The fields to extract, as a standard JSON Schema. Optional when `what_to_extract` is given. */
|
|
171
|
+
schema?: ExtractionSchema;
|
|
172
|
+
/** What to extract, in plain words. Guides the extraction, or alone, writes the schema. */
|
|
167
173
|
what_to_extract?: string;
|
|
168
174
|
/** Speech-to-text the audio when no platform transcript exists. Default true. */
|
|
169
175
|
transcribe?: boolean;
|
|
@@ -286,6 +292,8 @@ export type GetFileResult = {
|
|
|
286
292
|
|
|
287
293
|
export interface ExtractDataResult {
|
|
288
294
|
data: Record<string, unknown>;
|
|
295
|
+
/** When the request had no schema: the schema written from `what_to_extract`, to pass as `schema` next time. */
|
|
296
|
+
schema?: ExtractionSchema;
|
|
289
297
|
video_info?: VideoInfo;
|
|
290
298
|
file_info?: FileInfo;
|
|
291
299
|
/** With `include_scenes: true`: number of frames that were analyzed to produce the scenes. */
|
|
@@ -406,7 +414,8 @@ export type AnalyzeFileResult = {
|
|
|
406
414
|
|
|
407
415
|
export type ExtractVideoDataPayload = {
|
|
408
416
|
video_url: string;
|
|
409
|
-
|
|
417
|
+
/** A standard JSON Schema. Optional when `what_to_extract` is given. */
|
|
418
|
+
schema?: ExtractionSchema;
|
|
410
419
|
what_to_extract?: string;
|
|
411
420
|
transcribe?: boolean;
|
|
412
421
|
/**
|
|
@@ -431,7 +440,8 @@ export type TweetStatementPayload = { tweet_id: string } & WebhookOption;
|
|
|
431
440
|
|
|
432
441
|
export type ExtractFileDataPayload = {
|
|
433
442
|
file_id: string;
|
|
434
|
-
|
|
443
|
+
/** A standard JSON Schema. Optional when `what_to_extract` is given. */
|
|
444
|
+
schema?: ExtractionSchema;
|
|
435
445
|
what_to_extract?: string;
|
|
436
446
|
/**
|
|
437
447
|
* Default false. `true` extracts from the transcript of the file and its scenes together. The
|
|
@@ -474,6 +484,19 @@ function parseTranscribeData(
|
|
|
474
484
|
};
|
|
475
485
|
}
|
|
476
486
|
|
|
487
|
+
/**
|
|
488
|
+
* An extraction needs a schema (`schema` or `schemaFilePath`) or, without one, `what_to_extract`,
|
|
489
|
+
* from which the API writes the schema. Checked before anything is sent.
|
|
490
|
+
*/
|
|
491
|
+
function checkSchemaInput(input: { schema?: unknown; schemaFilePath?: string; what_to_extract?: string }): void {
|
|
492
|
+
if (input.schema !== undefined && input.schemaFilePath !== undefined) {
|
|
493
|
+
throw new Error('Pass at most one of schema or schemaFilePath.');
|
|
494
|
+
}
|
|
495
|
+
if (input.schema === undefined && input.schemaFilePath === undefined && !input.what_to_extract?.trim()) {
|
|
496
|
+
throw new Error('Pass schema, schemaFilePath or what_to_extract.');
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
477
500
|
/** What `include_scenes` adds beside the scenes themselves. */
|
|
478
501
|
interface SceneNotes {
|
|
479
502
|
frames_analyzed?: number;
|
|
@@ -722,6 +745,7 @@ export class VidNavigatorClient {
|
|
|
722
745
|
data: requireResult(task),
|
|
723
746
|
video_info: task.video_info,
|
|
724
747
|
...pickSceneNotes(task),
|
|
748
|
+
...(task.schema ? { schema: task.schema } : {}),
|
|
725
749
|
usage: task.usage,
|
|
726
750
|
}),
|
|
727
751
|
});
|
|
@@ -820,6 +844,7 @@ export class VidNavigatorClient {
|
|
|
820
844
|
}
|
|
821
845
|
|
|
822
846
|
private submitExtractVideo(input: ExtractVideoInput): Promise<JobInfo> {
|
|
847
|
+
checkSchemaInput(input);
|
|
823
848
|
if ('schemaFilePath' in input) {
|
|
824
849
|
const form = new FormData();
|
|
825
850
|
form.append('video_url', input.video_url);
|
|
@@ -1350,10 +1375,12 @@ export class VidNavigatorClient {
|
|
|
1350
1375
|
async extractFileData(
|
|
1351
1376
|
payload: ExtractFileDataPayload | ExtractFileDataMultipartPayload
|
|
1352
1377
|
): Promise<ExtractDataResult> {
|
|
1378
|
+
checkSchemaInput(payload);
|
|
1353
1379
|
type ExtractFileBody = {
|
|
1354
1380
|
status: 'success';
|
|
1355
1381
|
data: Record<string, unknown>;
|
|
1356
1382
|
file_info?: FileInfoJSON;
|
|
1383
|
+
schema?: ExtractionSchema;
|
|
1357
1384
|
usage?: UsageBlockJSON;
|
|
1358
1385
|
} & SceneNotes;
|
|
1359
1386
|
let body: ExtractFileBody;
|
|
@@ -1374,6 +1401,7 @@ export class VidNavigatorClient {
|
|
|
1374
1401
|
data: body.data,
|
|
1375
1402
|
file_info: body.file_info ? FileInfo.fromJSON(body.file_info) : undefined,
|
|
1376
1403
|
...pickSceneNotes(body),
|
|
1404
|
+
...(body.schema ? { schema: body.schema } : {}),
|
|
1377
1405
|
usage: body.usage ? UsageBlock.fromJSON(body.usage) : undefined,
|
|
1378
1406
|
};
|
|
1379
1407
|
}
|
package/src/models/AsyncJob.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ExtractionSchema } from './Extraction';
|
|
1
2
|
import { UsageBlock } from './Usage';
|
|
2
3
|
import { VideoInfo, VideoInfoJSON } from './VideoInfo';
|
|
3
4
|
import { ScenesError, WatchTranscriptError } from './Watch';
|
|
@@ -91,6 +92,8 @@ export interface AsyncJobJSON {
|
|
|
91
92
|
frames_analyzed?: number;
|
|
92
93
|
scenes_error?: ScenesError;
|
|
93
94
|
transcript_error?: WatchTranscriptError;
|
|
95
|
+
/** `extract_video` jobs, once completed, when the request had no schema: the schema written from `what_to_extract`. */
|
|
96
|
+
schema?: ExtractionSchema;
|
|
94
97
|
error?: AsyncJobError | null;
|
|
95
98
|
}
|
|
96
99
|
|
|
@@ -121,6 +124,8 @@ export class AsyncJob<TResult> {
|
|
|
121
124
|
scenes_error?: ScenesError;
|
|
122
125
|
/** `extract_video` jobs with `include_scenes`: why there is no transcript. The fields were then extracted from the scenes alone. */
|
|
123
126
|
transcript_error?: WatchTranscriptError;
|
|
127
|
+
/** `extract_video` jobs, once completed, when the request had no schema: the schema written from `what_to_extract`, to pass as `schema` next time. */
|
|
128
|
+
schema?: ExtractionSchema;
|
|
124
129
|
error: AsyncJobError | null;
|
|
125
130
|
/** Per-call usage, populated only when polled with `include_usage: true` and `task_status === 'completed'`. */
|
|
126
131
|
usage?: UsageBlock;
|
|
@@ -141,6 +146,7 @@ export class AsyncJob<TResult> {
|
|
|
141
146
|
this.frames_analyzed = data.frames_analyzed;
|
|
142
147
|
this.scenes_error = data.scenes_error;
|
|
143
148
|
this.transcript_error = data.transcript_error;
|
|
149
|
+
this.schema = data.schema;
|
|
144
150
|
this.error = data.error ?? null;
|
|
145
151
|
}
|
|
146
152
|
|
package/src/models/Extraction.ts
CHANGED
|
@@ -2,25 +2,34 @@ import { FileInfoJSON } from './FileInfo';
|
|
|
2
2
|
import { VideoInfoJSON } from './VideoInfo';
|
|
3
3
|
import { ScenesError, WatchTranscriptError } from './Watch';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
| 'Number'
|
|
8
|
-
| 'Boolean'
|
|
9
|
-
| 'Integer'
|
|
10
|
-
| 'Object'
|
|
11
|
-
| 'Array'
|
|
12
|
-
| 'Enum';
|
|
5
|
+
/** JSON Schema types a property of an extraction schema can have. */
|
|
6
|
+
export type ExtractionFieldType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
|
|
13
7
|
|
|
8
|
+
/**
|
|
9
|
+
* One property of an extraction schema, in standard JSON Schema. Give it a `type` and a
|
|
10
|
+
* `description` (what to put in it); `enum` restricts it to a list of values. Other JSON Schema
|
|
11
|
+
* keywords are accepted (`$ref`, `format`, `minimum`, ...).
|
|
12
|
+
*/
|
|
14
13
|
export interface ExtractionField {
|
|
15
|
-
type
|
|
16
|
-
description
|
|
14
|
+
type?: ExtractionFieldType | Array<ExtractionFieldType | 'null'>;
|
|
15
|
+
description?: string;
|
|
17
16
|
properties?: Record<string, ExtractionField>;
|
|
18
17
|
items?: ExtractionField;
|
|
19
|
-
enum?: string
|
|
18
|
+
enum?: Array<string | number | boolean | null>;
|
|
19
|
+
[keyword: string]: unknown;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
* The fields to extract, as a standard JSON Schema whose root is an object, for example what
|
|
24
|
+
* `zod-to-json-schema` or Pydantic's `model_json_schema()` produce. At most 10 fields per level
|
|
25
|
+
* and 3 levels of nesting.
|
|
26
|
+
*/
|
|
27
|
+
export interface ExtractionSchema {
|
|
28
|
+
type: 'object';
|
|
29
|
+
properties: Record<string, ExtractionField>;
|
|
30
|
+
required?: string[];
|
|
31
|
+
[keyword: string]: unknown;
|
|
32
|
+
}
|
|
24
33
|
|
|
25
34
|
export interface ExtractionTokenUsageJSON {
|
|
26
35
|
prompt_tokens?: number;
|
|
@@ -37,6 +46,8 @@ export interface ExtractionResponseJSON {
|
|
|
37
46
|
frames_analyzed?: number;
|
|
38
47
|
scenes_error?: ScenesError;
|
|
39
48
|
transcript_error?: WatchTranscriptError;
|
|
49
|
+
/** When the request had no schema: the schema written from `what_to_extract`, to pass as `schema` next time. */
|
|
50
|
+
schema?: ExtractionSchema;
|
|
40
51
|
usage?: ExtractionTokenUsageJSON;
|
|
41
52
|
}
|
|
42
53
|
|
package/src/webhooks.ts
CHANGED
|
@@ -52,6 +52,8 @@ export interface WebhookEvent {
|
|
|
52
52
|
result_truncated?: boolean;
|
|
53
53
|
/** `extract_video.completed` only: raw `video_info` of the video. Sent even when `result_truncated` is true. */
|
|
54
54
|
video_info?: Record<string, unknown>;
|
|
55
|
+
/** `extract_video.completed` only, when the request had no schema: the schema written from `what_to_extract`. */
|
|
56
|
+
schema?: Record<string, unknown>;
|
|
55
57
|
error?: AsyncJobError | null;
|
|
56
58
|
};
|
|
57
59
|
}
|