ugcinc 4.20.0 → 4.22.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.
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mediaAnalysisResultSchema = exports.videoTextResultSchema = exports.imageTextResultSchema = exports.textLineSchema = exports.textRegionSchema = exports.readVideoTextSchema = exports.readImageTextSchema = exports.scenesResultSchema = exports.framesResultSchema = exports.analysisSourceSchema = exports.mediaAnalysisStatusSchema = exports.extractFramesSchema = exports.detectScenesSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const videoUrl = zod_1.z.string().url().max(8192).refine(value => {
6
+ const url = new URL(value);
7
+ return url.protocol === 'https:' && !url.username && !url.password && !url.hash;
8
+ }, 'Expected an HTTPS video URL without credentials or fragment');
9
+ const time = zod_1.z.number().finite().nonnegative();
10
+ exports.detectScenesSchema = zod_1.z.object({ url: videoUrl }).strict();
11
+ exports.extractFramesSchema = zod_1.z.object({
12
+ url: videoUrl,
13
+ timestampsMs: zod_1.z.array(time).min(1).max(48).optional(),
14
+ range: zod_1.z.object({ startMs: time, endMs: time, intervalMs: zod_1.z.number().finite().positive() }).strict().optional(),
15
+ selection: zod_1.z.enum(['nearest', 'before', 'after']).default('nearest'),
16
+ contactSheet: zod_1.z.boolean().default(true),
17
+ }).strict().superRefine((value, ctx) => {
18
+ if (Boolean(value.timestampsMs) === Boolean(value.range))
19
+ ctx.addIssue({ code: 'custom', message: 'Provide timestampsMs or range, exclusively' });
20
+ const r = value.range;
21
+ if (r && (r.endMs <= r.startMs || Math.ceil((r.endMs - r.startMs) / r.intervalMs) > 48))
22
+ ctx.addIssue({ code: 'custom', message: 'Range must contain 1 to 48 samples with an exclusive end' });
23
+ });
24
+ exports.mediaAnalysisStatusSchema = zod_1.z.object({ jobId: zod_1.z.string().uuid() }).strict();
25
+ exports.analysisSourceSchema = zod_1.z.object({
26
+ encodedWidth: zod_1.z.number(), encodedHeight: zod_1.z.number(), displayWidth: zod_1.z.number(), displayHeight: zod_1.z.number(), rotationDegrees: zod_1.z.number(),
27
+ sampleAspectRatio: zod_1.z.string(), durationMs: zod_1.z.number(), timeBase: zod_1.z.string(), startPts: zod_1.z.string(), startTimeMs: zod_1.z.number(), frameCount: zod_1.z.number(), variableFrameRate: zod_1.z.boolean(), sha256: zod_1.z.string(), bytes: zod_1.z.number(),
28
+ });
29
+ const frameSchema = zod_1.z.object({ index: zod_1.z.number(), requestedTimeMs: zod_1.z.number(), timeMs: zod_1.z.number(), sourcePts: zod_1.z.string(), frameIndex: zod_1.z.number(), width: zod_1.z.number(), height: zod_1.z.number(), url: zod_1.z.string().url() });
30
+ const boxSchema = zod_1.z.object({ x: zod_1.z.number(), y: zod_1.z.number(), width: zod_1.z.number(), height: zod_1.z.number() });
31
+ exports.framesResultSchema = zod_1.z.object({ version: zod_1.z.literal(1), operation: zod_1.z.literal('extract_frames'), source: exports.analysisSourceSchema, selection: zod_1.z.enum(['nearest', 'before', 'after']), frames: zod_1.z.array(frameSchema),
32
+ contactSheet: zod_1.z.object({ url: zod_1.z.string().url(), width: zod_1.z.number(), height: zod_1.z.number(), cells: zod_1.z.array(zod_1.z.object({ frameIndex: zod_1.z.number(), box: boxSchema, frameUrl: zod_1.z.string().url() })) }).nullable(), manifestUrl: zod_1.z.string().url() });
33
+ exports.scenesResultSchema = zod_1.z.object({ version: zod_1.z.literal(1), operation: zod_1.z.literal('detect_scenes'), source: exports.analysisSourceSchema,
34
+ scenes: zod_1.z.array(zod_1.z.object({ index: zod_1.z.number(), startFrameIndex: zod_1.z.number(), endFrameIndexExclusive: zod_1.z.number(), startMs: zod_1.z.number(), endMs: zod_1.z.number(), startPts: zod_1.z.string(), endPts: zod_1.z.string().nullable() })),
35
+ detector: zod_1.z.object({ name: zod_1.z.string(), version: zod_1.z.string(), settings: zod_1.z.record(zod_1.z.number()) }), warnings: zod_1.z.array(zod_1.z.string()), manifestUrl: zod_1.z.string().url() });
36
+ exports.readImageTextSchema = zod_1.z.object({ url: videoUrl }).strict();
37
+ exports.readVideoTextSchema = zod_1.z.object({
38
+ url: videoUrl, mode: zod_1.z.enum(['fast', 'frame_scan']).default('fast'),
39
+ range: zod_1.z.object({ startMs: time, endMs: time }).strict().optional(),
40
+ intervalMs: zod_1.z.number().finite().min(100).max(120000).optional(),
41
+ }).strict().superRefine((v, ctx) => {
42
+ if (v.mode === 'frame_scan' && v.intervalMs !== undefined)
43
+ ctx.addIssue({ code: 'custom', message: 'intervalMs applies only to fast mode' });
44
+ if (v.range && (v.range.endMs <= v.range.startMs || v.range.endMs - v.range.startMs > 120000))
45
+ ctx.addIssue({ code: 'custom', message: 'OCR range must be positive and at most 120 seconds' });
46
+ });
47
+ const pointSchema = zod_1.z.object({ x: zod_1.z.number().finite(), y: zod_1.z.number().finite() });
48
+ const textFields = { text: zod_1.z.string().nullable(), rawText: zod_1.z.string(), confidence: zod_1.z.number().min(0).max(1), status: zod_1.z.enum(['readable', 'unreadable']) };
49
+ exports.textRegionSchema = zod_1.z.object({ id: zod_1.z.string(), polygon: zod_1.z.array(pointSchema).length(4), box: boxSchema, ...textFields });
50
+ exports.textLineSchema = zod_1.z.object({ id: zod_1.z.string(), readingOrder: zod_1.z.number().int().nonnegative(), regionIds: zod_1.z.array(zod_1.z.string()), box: boxSchema, ...textFields });
51
+ const ocrModelSchema = zod_1.z.object({ name: zod_1.z.string(), runtime: zod_1.z.string(), device: zod_1.z.literal('cpu'), modelHashes: zod_1.z.record(zod_1.z.string()), orientationClassifier: zod_1.z.string(), recognitionThreshold: zod_1.z.number(), coordinates: zod_1.z.literal('display-oriented-source-pixels') });
52
+ const textContent = { regions: zod_1.z.array(exports.textRegionSchema), lines: zod_1.z.array(exports.textLineSchema) };
53
+ exports.imageTextResultSchema = zod_1.z.object({ version: zod_1.z.literal(1), operation: zod_1.z.literal('read_image_text'),
54
+ source: zod_1.z.object({ encodedWidth: zod_1.z.number(), encodedHeight: zod_1.z.number(), displayWidth: zod_1.z.number(), displayHeight: zod_1.z.number(), exifOrientation: zod_1.z.number(), alphaBackground: zod_1.z.literal('white'), sha256: zod_1.z.string(), bytes: zod_1.z.number() }),
55
+ ...textContent, model: ocrModelSchema, warnings: zod_1.z.array(zod_1.z.string()), previewUrl: zod_1.z.string().url(), manifestUrl: zod_1.z.string().url() });
56
+ const intervalSchema = zod_1.z.object({ startMs: time, endMs: time });
57
+ exports.videoTextResultSchema = zod_1.z.object({ version: zod_1.z.literal(1), operation: zod_1.z.literal('read_video_text'), source: exports.analysisSourceSchema,
58
+ model: ocrModelSchema, warnings: zod_1.z.array(zod_1.z.string()), manifestUrl: zod_1.z.string().url(),
59
+ frames: zod_1.z.array(zod_1.z.object({ frameIndex: zod_1.z.number().int(), sourcePts: zod_1.z.string(), timeMs: time, endMs: time, ...textContent, sceneChange: zod_1.z.boolean(), previewUrl: zod_1.z.string().url().optional() })),
60
+ tracks: zod_1.z.array(zod_1.z.object({ id: zod_1.z.string(), text: zod_1.z.string().nullable(), rawText: zod_1.z.string(), firstObservedMs: time, lastObservedEndMs: time,
61
+ observations: zod_1.z.array(zod_1.z.object({ sampleIndex: zod_1.z.number().int(), frameIndex: zod_1.z.number().int(), sourcePts: zod_1.z.string(), timeMs: time, endMs: time, lineId: zod_1.z.string(), box: boxSchema, confidence: zod_1.z.number() })) })),
62
+ coverage: zod_1.z.object({ mode: zod_1.z.enum(['fast', 'frame_scan']), range: intervalSchema, complete: zod_1.z.boolean(), uninspected: zod_1.z.array(intervalSchema),
63
+ inspected: zod_1.z.array(intervalSchema.extend({ frameIndex: zod_1.z.number().int(), sourcePts: zod_1.z.string() })) }),
64
+ });
65
+ exports.mediaAnalysisResultSchema = zod_1.z.discriminatedUnion('operation', [exports.framesResultSchema, exports.scenesResultSchema, exports.imageTextResultSchema, exports.videoTextResultSchema]);
package/dist/media.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { BaseClient } from './base';
2
+ import type { ExtractFramesParams, DetectScenesParams, ReadImageTextParams, ReadVideoTextParams, MediaAnalysisJob } from './media-analysis';
2
3
  import type { ListProfilePostsParams, ListProfilePostsResult, DownloadSocialPostParams, DownloadSocialPostResult } from './social-acquisition';
3
4
  import type { ApiResponse } from './types';
4
5
  export interface UserMedia {
@@ -199,6 +200,16 @@ export interface OwnedUploadResponse {
199
200
  * Client for managing media files
200
201
  */
201
202
  export declare class MediaClient extends BaseClient {
203
+ /** Read English text with source-coordinate polygons and an annotated preview. */
204
+ readImageText(params: ReadImageTextParams): Promise<ApiResponse<MediaAnalysisJob>>;
205
+ readVideoText(params: ReadVideoTextParams): Promise<ApiResponse<MediaAnalysisJob>>;
206
+ extractFrames(params: ExtractFramesParams): Promise<ApiResponse<MediaAnalysisJob>>;
207
+ /** Detect scene ranges without exporting video clips. */
208
+ detectScenes(params: DetectScenesParams): Promise<ApiResponse<MediaAnalysisJob>>;
209
+ getMediaAnalysis(params: {
210
+ jobId: string;
211
+ }): Promise<ApiResponse<MediaAnalysisJob>>;
212
+ private waitForAnalysis;
202
213
  /** List a bounded page of TikTok/Instagram references; does not download media. */
203
214
  listProfilePosts(params: ListProfilePostsParams): Promise<ApiResponse<ListProfilePostsResult>>;
204
215
  /** Import actual post assets to owned media. Continuations are checkpointed server-side. */
package/dist/media.js CHANGED
@@ -6,6 +6,35 @@ const base_1 = require("./base");
6
6
  * Client for managing media files
7
7
  */
8
8
  class MediaClient extends base_1.BaseClient {
9
+ /** Read English text with source-coordinate polygons and an annotated preview. */
10
+ async readImageText(params) {
11
+ return this.waitForAnalysis(await this.post('/media/analysis/read-image-text', params));
12
+ }
13
+ async readVideoText(params) {
14
+ return this.waitForAnalysis(await this.post('/media/analysis/read-video-text', params));
15
+ }
16
+ async extractFrames(params) {
17
+ return this.waitForAnalysis(await this.post('/media/analysis/extract-frames', params));
18
+ }
19
+ /** Detect scene ranges without exporting video clips. */
20
+ async detectScenes(params) {
21
+ return this.waitForAnalysis(await this.post('/media/analysis/detect-scenes', params));
22
+ }
23
+ async getMediaAnalysis(params) {
24
+ return this.post('/media/analysis/status', params);
25
+ }
26
+ async waitForAnalysis(initial) {
27
+ let response = initial;
28
+ for (let attempt = 0; attempt < 180 && response.ok && ['pending', 'processing'].includes(response.data.status); attempt++) {
29
+ await new Promise(resolve => setTimeout(resolve, 2000));
30
+ const next = await this.getMediaAnalysis({ jobId: response.data.jobId });
31
+ // Preserve the job handle if a transient polling failure interrupts the wait.
32
+ if (!next.ok)
33
+ return response;
34
+ response = next;
35
+ }
36
+ return response;
37
+ }
9
38
  /** List a bounded page of TikTok/Instagram references; does not download media. */
10
39
  async listProfilePosts(params) {
11
40
  return this.post('/media/social/list-profile-posts', params);
@@ -384,14 +384,14 @@ export declare const iMessageDmPropsSchema: z.ZodObject<{
384
384
  imageUrl: z.ZodOptional<z.ZodString>;
385
385
  groupWithPrevious: z.ZodOptional<z.ZodBoolean>;
386
386
  }, "strip", z.ZodTypeAny, {
387
- text: string;
388
387
  id: string;
388
+ text: string;
389
389
  sender: "user" | "recipient";
390
390
  imageUrl?: string | undefined;
391
391
  groupWithPrevious?: boolean | undefined;
392
392
  }, {
393
- text: string;
394
393
  id: string;
394
+ text: string;
395
395
  sender: "user" | "recipient";
396
396
  imageUrl?: string | undefined;
397
397
  groupWithPrevious?: boolean | undefined;
@@ -399,21 +399,21 @@ export declare const iMessageDmPropsSchema: z.ZodObject<{
399
399
  dynamicCrop: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
400
400
  cropVerticalCenter: z.ZodOptional<z.ZodBoolean>;
401
401
  }, "strip", z.ZodTypeAny, {
402
+ width?: number | undefined;
403
+ height?: number | undefined;
402
404
  time?: string | undefined;
403
405
  backgroundColor?: string | undefined;
404
406
  lightMode?: boolean | undefined;
405
407
  username?: string | undefined;
406
408
  profilePicUrl?: string | undefined;
407
409
  messages?: {
408
- text: string;
409
410
  id: string;
411
+ text: string;
410
412
  sender: "user" | "recipient";
411
413
  imageUrl?: string | undefined;
412
414
  groupWithPrevious?: boolean | undefined;
413
415
  }[] | undefined;
414
416
  dynamicCrop?: Record<string, any> | undefined;
415
- width?: number | undefined;
416
- height?: number | undefined;
417
417
  fps?: number | undefined;
418
418
  durationInFrames?: number | undefined;
419
419
  showDebugOverlay?: boolean | undefined;
@@ -582,21 +582,21 @@ export declare const iMessageDmPropsSchema: z.ZodObject<{
582
582
  readReceiptLeft?: number | undefined;
583
583
  readReceiptRight?: number | undefined;
584
584
  }, {
585
+ width?: number | undefined;
586
+ height?: number | undefined;
585
587
  time?: string | undefined;
586
588
  backgroundColor?: string | undefined;
587
589
  lightMode?: boolean | undefined;
588
590
  username?: string | undefined;
589
591
  profilePicUrl?: string | undefined;
590
592
  messages?: {
591
- text: string;
592
593
  id: string;
594
+ text: string;
593
595
  sender: "user" | "recipient";
594
596
  imageUrl?: string | undefined;
595
597
  groupWithPrevious?: boolean | undefined;
596
598
  }[] | undefined;
597
599
  dynamicCrop?: Record<string, any> | undefined;
598
- width?: number | undefined;
599
- height?: number | undefined;
600
600
  fps?: number | undefined;
601
601
  durationInFrames?: number | undefined;
602
602
  showDebugOverlay?: boolean | undefined;
@@ -8,16 +8,16 @@ export declare const remotionCompositionSchema: z.ZodObject<{
8
8
  durationInFrames: z.ZodNumber;
9
9
  inputProps: z.ZodRecord<z.ZodString, z.ZodUnknown>;
10
10
  }, "strict", z.ZodTypeAny, {
11
- source: string;
12
11
  width: number;
13
12
  height: number;
13
+ source: string;
14
14
  fps: number;
15
15
  durationInFrames: number;
16
16
  inputProps: Record<string, unknown>;
17
17
  }, {
18
- source: string;
19
18
  width: number;
20
19
  height: number;
20
+ source: string;
21
21
  fps: number;
22
22
  durationInFrames: number;
23
23
  inputProps: Record<string, unknown>;
@@ -29,12 +29,12 @@ export declare const remotionCompositionPortSchema: z.ZodObject<{
29
29
  isArray: z.ZodBoolean;
30
30
  required: z.ZodBoolean;
31
31
  }, "strict", z.ZodTypeAny, {
32
- type: "number" | "boolean" | "object" | "video" | "image" | "audio" | "text";
32
+ type: "number" | "boolean" | "object" | "video" | "image" | "text" | "audio";
33
33
  id: string;
34
34
  isArray: boolean;
35
35
  required: boolean;
36
36
  }, {
37
- type: "number" | "boolean" | "object" | "video" | "image" | "audio" | "text";
37
+ type: "number" | "boolean" | "object" | "video" | "image" | "text" | "audio";
38
38
  id: string;
39
39
  isArray: boolean;
40
40
  required: boolean;
@@ -54,22 +54,22 @@ export declare const remotionCompositionNodeSchema: z.ZodObject<{
54
54
  isArray: z.ZodBoolean;
55
55
  required: z.ZodBoolean;
56
56
  }, "strict", z.ZodTypeAny, {
57
- type: "number" | "boolean" | "object" | "video" | "image" | "audio" | "text";
57
+ type: "number" | "boolean" | "object" | "video" | "image" | "text" | "audio";
58
58
  id: string;
59
59
  isArray: boolean;
60
60
  required: boolean;
61
61
  }, {
62
- type: "number" | "boolean" | "object" | "video" | "image" | "audio" | "text";
62
+ type: "number" | "boolean" | "object" | "video" | "image" | "text" | "audio";
63
63
  id: string;
64
64
  isArray: boolean;
65
65
  required: boolean;
66
66
  }>, "many">, {
67
- type: "number" | "boolean" | "object" | "video" | "image" | "audio" | "text";
67
+ type: "number" | "boolean" | "object" | "video" | "image" | "text" | "audio";
68
68
  id: string;
69
69
  isArray: boolean;
70
70
  required: boolean;
71
71
  }[], {
72
- type: "number" | "boolean" | "object" | "video" | "image" | "audio" | "text";
72
+ type: "number" | "boolean" | "object" | "video" | "image" | "text" | "audio";
73
73
  id: string;
74
74
  isArray: boolean;
75
75
  required: boolean;
@@ -77,33 +77,33 @@ export declare const remotionCompositionNodeSchema: z.ZodObject<{
77
77
  outputMode: z.ZodEnum<["single", "per-input"]>;
78
78
  selectionMode: z.ZodNull;
79
79
  }, "strict", z.ZodTypeAny, {
80
+ width: number;
81
+ height: number;
80
82
  source: string;
81
83
  outputMode: "per-input" | "single";
82
84
  selectionMode: null;
83
85
  outputType: "video" | "image";
84
86
  inputs: {
85
- type: "number" | "boolean" | "object" | "video" | "image" | "audio" | "text";
87
+ type: "number" | "boolean" | "object" | "video" | "image" | "text" | "audio";
86
88
  id: string;
87
89
  isArray: boolean;
88
90
  required: boolean;
89
91
  }[];
90
- width: number;
91
- height: number;
92
92
  fps: number;
93
93
  durationInFrames: number;
94
94
  inputProps: Record<string, unknown>;
95
95
  }, {
96
+ width: number;
97
+ height: number;
96
98
  source: string;
97
99
  outputMode: "per-input" | "single";
98
100
  selectionMode: null;
99
101
  inputs: {
100
- type: "number" | "boolean" | "object" | "video" | "image" | "audio" | "text";
102
+ type: "number" | "boolean" | "object" | "video" | "image" | "text" | "audio";
101
103
  id: string;
102
104
  isArray: boolean;
103
105
  required: boolean;
104
106
  }[];
105
- width: number;
106
- height: number;
107
107
  fps: number;
108
108
  durationInFrames: number;
109
109
  inputProps: Record<string, unknown>;
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mediaTools = void 0;
4
+ const media_analysis_1 = require("../media-analysis");
4
5
  const zod_1 = require("zod");
5
6
  exports.mediaTools = [
7
+ { name: 'read_image_text', description: 'Read English image text with raw recognition, polygons in display-oriented source pixels, inferred lines/order and confidence. Includes annotated preview. Empty output does not prove no text. If pending, use get_media_analysis.', schema: media_analysis_1.readImageTextSchema, execute: async (client, params) => client.media.readImageText(params) },
8
+ { name: 'read_video_text', description: 'Read English video text and positional changes. fast samples frames (default 1000ms); frame_scan inspects every decoded frame in range. Returns source PTS, observed text tracks and explicit uninspected gaps. At most 240 inspected frames and 120 seconds per request. Sampling cannot guarantee exact appearance/disappearance. If pending, use get_media_analysis.', schema: media_analysis_1.readVideoTextSchema, execute: async (client, params) => client.media.readVideoText(params) },
9
+ { name: 'extract_frames', description: 'Extract video frames at timestampsMs or a range {startMs,endMs,intervalMs}; milliseconds relative to the first displayed frame. Returns actual decoded times and optional contact sheet. At most 48 samples. If pending, use get_media_analysis with jobId.', schema: media_analysis_1.extractFramesSchema, execute: async (client, params) => client.media.extractFrames(params) },
10
+ { name: 'detect_scenes', description: 'Detect scene ranges in a video using the existing adaptive/fade detector, without exporting clips. Times are source-relative milliseconds. If pending, use get_media_analysis with jobId.', schema: media_analysis_1.detectScenesSchema, execute: async (client, params) => client.media.detectScenes(params) },
11
+ { name: 'get_media_analysis', description: 'Read the status/result of a frame extraction or scene detection job in the current organization.', schema: media_analysis_1.mediaAnalysisStatusSchema, execute: async (client, params) => client.media.getMediaAnalysis(params) },
6
12
  {
7
13
  name: 'list_profile_posts',
8
14
  description: 'List a page of TikTok or Instagram profile posts, with metadata and an opaque continuation cursor. Does not download files; provider-visible history may be incomplete.',
package/dist/types.d.ts CHANGED
@@ -20,3 +20,4 @@ export interface ErrorResponse {
20
20
  export type ApiResponse<T> = SuccessResponse<T> | ErrorResponse;
21
21
  export type { PublicPostFailureCode, PublicPostRecovery, PublicPostNextAction, PublicPostFailure } from './post-failure';
22
22
  export type { ListProfilePostsParams, ListProfilePostsResult, DownloadSocialPostParams, DownloadSocialPostResult, SocialReferencePost, SocialReferenceAsset } from './social-acquisition';
23
+ export type { ReadImageTextParams, ReadVideoTextParams, ImageTextResult, VideoTextResult, ExtractFramesParams, DetectScenesParams, FramesResult, ScenesResult, MediaAnalysisResult, MediaAnalysisJob } from "./media-analysis";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugcinc",
3
- "version": "4.20.0",
3
+ "version": "4.22.0",
4
4
  "description": "TypeScript/JavaScript client for the UGC Inc API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",