samsar-js 0.48.26 → 0.48.28
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 +70 -9
- package/dist/express-video-pricing.d.ts +24 -0
- package/dist/express-video-pricing.js +34 -0
- package/dist/index.d.ts +225 -2
- package/dist/index.js +166 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ const videoFromImages = await samsar.createVideoFromImageList(
|
|
|
77
77
|
await samsar.createVideoFromImageList({
|
|
78
78
|
image_urls: ['https://example.com/a.jpg', 'https://example.com/b.jpg'],
|
|
79
79
|
prompt: 'Product launch teaser with a clean final CTA',
|
|
80
|
-
video_model: '
|
|
80
|
+
video_model: 'KLINGIMGTOVID3PRO',
|
|
81
81
|
aspect_ratio: '16:9',
|
|
82
82
|
outro_image_url: 'https://cdn.example.com/outro.png',
|
|
83
83
|
add_outro_animation: true,
|
|
@@ -94,6 +94,7 @@ await samsar.createVideoFromImageList({
|
|
|
94
94
|
prompt: 'Travel offer reel with a scannable booking outro',
|
|
95
95
|
video_model: 'RUNWAYML',
|
|
96
96
|
aspect_ratio: '9:16',
|
|
97
|
+
add_narrator_avatar: true,
|
|
97
98
|
generate_outro_image: true,
|
|
98
99
|
cta_url: 'https://example.com/book',
|
|
99
100
|
cta_text_top: 'Scan to book',
|
|
@@ -434,6 +435,7 @@ const platform = new SamsarClient({
|
|
|
434
435
|
|
|
435
436
|
const externalUser = {
|
|
436
437
|
provider: 'whop',
|
|
438
|
+
unique_key: 'whop:usr_123',
|
|
437
439
|
external_user_id: 'usr_123',
|
|
438
440
|
external_app_id: 'app_abc',
|
|
439
441
|
username: 'roy24x7',
|
|
@@ -544,25 +546,29 @@ console.log(externalLibrary.data.requests.map((request) => request.request_id));
|
|
|
544
546
|
```
|
|
545
547
|
|
|
546
548
|
Video model support notes:
|
|
547
|
-
- `createVideoFromText` image model keys include: `GPTIMAGE2`, `IMAGEN4`, `SEEDREAM`, `
|
|
548
|
-
- `createVideoFromText` supports
|
|
549
|
+
- `createVideoFromText` image model keys include: `GPTIMAGE2`, `IMAGEN4`, `SEEDREAM`, `NANOBANANA2`, `CUSTOM_TEXT_TO_IMAGE`.
|
|
550
|
+
- `createVideoFromText` supports these video models: `RUNWAYML`, `VEO3.1I2V`, `VEO3.1I2VFAST`, `SEEDANCEI2V` (Seedance 1.5), `KLINGIMGTOVID3PRO`, and `CUSTOM_IMAGE_TO_VIDEO`.
|
|
549
551
|
- `createVideoFromText` accepts either a provided outro (`outro_image_url`) or server-generated QR outro (`generate_outro_image: true` with `cta_url`). It can also render bottom CTA footer QR cards with `add_footer_animation` and `footer_metadata`; one footer item applies to every generated scene, while multiple items map by scene index.
|
|
550
|
-
- `createVideoFromImageList` supports `VEO3.1I2V`, `SEEDANCEI2V`, `
|
|
552
|
+
- `createVideoFromImageList` supports `RUNWAYML`, `VEO3.1I2V`, `VEO3.1I2VFAST`, `SEEDANCEI2V`, `KLINGIMGTOVID3PRO`, and `CUSTOM_IMAGE_TO_VIDEO` via `video_model`; if omitted, it defaults to `RUNWAYML`. Use `aspect_ratio: '16:9'` or `'9:16'`; omitted or invalid values fall back to `16:9`.
|
|
551
553
|
- `createVideoFromImageList` accepts either a provided outro (`outro_image_url`) or server-generated QR outro (`generate_outro_image: true` with `cta_url`). Do not combine the two modes in a single request.
|
|
552
554
|
- `createVideoFromImageList` can render per-scene footer QR cards by setting `add_footer_animation: true` and providing one `footer_metadata` item per image scene.
|
|
555
|
+
- `createVideoFromImageList` accepts `limit_single_narrator: true` to keep all narration under one narrator identity. `add_narrator_avatar: true` automatically enables `limit_single_narrator`, generates an influencer-style human narrator avatar, and overlays it bottom-center or centered in the footer row when footer metadata is present.
|
|
553
556
|
- `updateVideoOutroImage` accepts either a replacement outro image URL (`outro_image_url`, `outroImageUrl`, `new_outro_image_url`) or a generated QR CTA outro (`generate_outro_image: true` with `cta_url`, or just `cta_url` when no outro image URL is supplied). Generated outro updates reuse the existing session image layers for tiling and only queue frame/video regeneration.
|
|
554
557
|
- `updateVideoFooterImage` updates the footer CTA on a cloned session with `cta_text`, `cta_logo`, and/or `cta_url`, or removes all scene footers with `remove_footer: true`. Footer updates queue only frame/video regeneration.
|
|
555
558
|
- `cloneVideo` creates a deep copy of a completed session and queues only the final video render so the clone receives a new rendered video path and URL. It does not charge credits.
|
|
556
559
|
- Main video methods and external-user methods accept the same generated outro and footer parameters. The API can resolve either internal session ids or external `extreq_...` ids on repeated video routes, so client code can keep using `translateVideo`, `joinVideos`, `addSubtitles`, `removeSubtitles`, `addVideoOutroImage`, `updateVideoOutroImage`, and `updateVideoFooterImage`; the explicit external variants are available when you want to call `/external_users/*` directly. Do not strip the `extreq_` prefix.
|
|
557
560
|
- Completed video status, latest-version, and completed-session list responses expose `has_subtitles` and `result_language` when the session metadata is available.
|
|
558
561
|
- `publishPublication`, `editPublication`, and `revokePublication` manage public feed publications for completed sessions through free `/publications/*` endpoints. They work with account API keys, customer sub-account API keys, and client auth tokens when the session belongs to the authenticated actor.
|
|
559
|
-
-
|
|
562
|
+
- Text-to-video and image-list video pricing use the same per-rendered-second rates for standard express models: `VEO3.1I2V` is 60 credits/sec, `VEO3.1I2VFAST` is 36 credits/sec, `SEEDANCEI2V` is 30 credits/sec, `KLINGIMGTOVID3PRO` is 36 credits/sec, and `RUNWAYML` is 30 credits/sec. Image-list narrator avatar generation adds 4 credits/sec when `add_narrator_avatar` is true.
|
|
563
|
+
- Standard express video models expose a per-second pricing distribution through `EXPRESS_VIDEO_PRICING_DISTRIBUTION_PER_SECOND_BY_MODEL`: pipeline 4, inference 4, image gen/edit 2, speech 2, music 2, effects and lipsync 2, and video as the model-specific remainder.
|
|
560
564
|
|
|
561
565
|
Upcoming `/v2` omni route adapters:
|
|
562
566
|
- `/v2` is additive; `/v1` is not deprecated.
|
|
563
|
-
- `createV2VideoFromText`, `createV2VideoFromImageList`, `translateV2Video`, `cloneV2Video`, `updateV2VideoOutroImage`, `updateV2VideoFooterImage`, `addV2VideoOutroImage`, `getV2Status`, `getV2Credits`, `listV2Requests`, and `createV2Session` call the new omni route surface.
|
|
564
|
-
-
|
|
565
|
-
-
|
|
567
|
+
- `createV2VideoFromText`, `createV2VideoFromImageList`, `translateV2Video`, `cloneV2Video`, `updateV2VideoOutroImage`, `updateV2VideoFooterImage`, `addV2VideoOutroImage`, `getV2Status`, `getV2StatusDetailed`, `getV2Credits`, `listV2Requests`, and `createV2Session` call the new omni route surface.
|
|
568
|
+
- Step-controlled video helpers include `createV2StepVideoFromText`, `createV2StepTextToVideo`, `createV2StepVideoFromImage`, `createV2StepImageToVideo`, `getV2StepVideoStatus`, `getV2StepVideoStatusDetailed`, and `processNextV2StepVideo`.
|
|
569
|
+
- Programmatic user helpers include `createV2ExternalUser`, `createV2UserRechargeCredits`, `refreshV2UserToken`, `createV2UserAppKey`, `refreshV2UserAppKey`, `getV2UserCredits`, `getV2UserUsageLogs`, and `getV2UserPaymentStatus`.
|
|
570
|
+
- Omit `externalUser` for internal account billing, pass `externalUser` to scope an external user with the account API key, or authenticate the client directly with an external-user auth token/API key. V2 external users can be referenced by `unique_key`; if `unique_key` is omitted during creation, the server uses `external_user_id` as the key.
|
|
571
|
+
- Detailed status adapters return the normal status payload plus a normalized `session` preview shape with `layers`, `audioLayers`, `globalAudioLayers`, and `globalVideos`. Layer timing uses `startTime` and `endTime` so clients can preview generated images, scene clips, and speech before final render completion.
|
|
566
572
|
|
|
567
573
|
```ts
|
|
568
574
|
const v2Video = await platform.createV2VideoFromImageList({
|
|
@@ -576,7 +582,7 @@ const v2Video = await platform.createV2VideoFromImageList({
|
|
|
576
582
|
const v2ExternalVideo = await platform.createV2VideoFromImageList(
|
|
577
583
|
{
|
|
578
584
|
image_urls: ['https://cdn.example.com/a.png', 'https://cdn.example.com/b.png'],
|
|
579
|
-
video_model: '
|
|
585
|
+
video_model: 'KLINGIMGTOVID3PRO',
|
|
580
586
|
},
|
|
581
587
|
{ externalUser },
|
|
582
588
|
);
|
|
@@ -595,6 +601,61 @@ const v2Clone = await platform.cloneV2Video({
|
|
|
595
601
|
|
|
596
602
|
const v2Status = await platform.getV2Status(v2Video.data.request_id!);
|
|
597
603
|
console.log(v2Status.data.status);
|
|
604
|
+
|
|
605
|
+
const v2Detailed = await platform.getV2StatusDetailed(v2Video.data.request_id!);
|
|
606
|
+
console.log(v2Detailed.data.session?.previewStage, v2Detailed.data.session?.layers?.[0]?.preview?.url);
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
Step-controlled video generation pauses after each completed stage until you call `processNextV2StepVideo`:
|
|
610
|
+
|
|
611
|
+
```ts
|
|
612
|
+
const stepVideo = await platform.createV2StepVideoFromText({
|
|
613
|
+
prompt: 'A 20 second launch teaser for a new travel app',
|
|
614
|
+
image_model: 'GPTIMAGE2',
|
|
615
|
+
video_model: 'RUNWAYML',
|
|
616
|
+
duration: 20,
|
|
617
|
+
aspect_ratio: '16:9',
|
|
618
|
+
enable_subtitles: true,
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
let stepStatus = await platform.getV2StepVideoStatus(stepVideo.data.request_id);
|
|
622
|
+
if (stepStatus.data.step_status === 'COMPLETED') {
|
|
623
|
+
console.log(stepStatus.data.current_step, stepStatus.data.current_step_resources);
|
|
624
|
+
const stepDetailed = await platform.getV2StepVideoStatusDetailed(stepVideo.data.request_id);
|
|
625
|
+
console.log(stepDetailed.data.session?.previewStage, stepDetailed.data.session?.layers?.[0]?.preview?.url);
|
|
626
|
+
stepStatus = await platform.processNextV2StepVideo(stepVideo.data.request_id);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
const stepImageVideo = await platform.createV2StepVideoFromImage({
|
|
630
|
+
image_url: 'https://cdn.example.com/product-frame.png',
|
|
631
|
+
prompt: 'Turn this product frame into a cinematic ad',
|
|
632
|
+
video_model: 'KLINGIMGTOVID3PRO',
|
|
633
|
+
aspect_ratio: '16:9',
|
|
634
|
+
});
|
|
635
|
+
console.log(stepImageVideo.data.step?.current_step);
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
Create and reference a V2 external user:
|
|
639
|
+
|
|
640
|
+
```ts
|
|
641
|
+
const createdExternalUser = await platform.createV2ExternalUser({
|
|
642
|
+
unique_key: 'wallet:0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
|
|
643
|
+
email: 'member@example.com',
|
|
644
|
+
display_name: 'Member Name',
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
const v2RegisteredExternalVideo = await platform.createV2VideoFromImageList(
|
|
648
|
+
{
|
|
649
|
+
image_urls: ['https://cdn.example.com/a.png', 'https://cdn.example.com/b.png'],
|
|
650
|
+
video_model: 'RUNWAYML',
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
externalUser: {
|
|
654
|
+
unique_key: createdExternalUser.data.unique_key!,
|
|
655
|
+
},
|
|
656
|
+
},
|
|
657
|
+
);
|
|
658
|
+
console.log(v2RegisteredExternalVideo.data.request_id);
|
|
598
659
|
```
|
|
599
660
|
|
|
600
661
|
Programmatic user recharge and OAuth-style refresh token rotation:
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const EXPRESS_VIDEO_FIXED_PRICING_COMPONENTS_PER_SECOND: {
|
|
2
|
+
readonly pipeline: 4;
|
|
3
|
+
readonly inference: 4;
|
|
4
|
+
readonly image_gen_edit: 2;
|
|
5
|
+
readonly speech: 2;
|
|
6
|
+
readonly music: 2;
|
|
7
|
+
readonly effects_and_lipsync: 2;
|
|
8
|
+
};
|
|
9
|
+
export type ExpressVideoPricingDistribution = typeof EXPRESS_VIDEO_FIXED_PRICING_COMPONENTS_PER_SECOND & {
|
|
10
|
+
video: number;
|
|
11
|
+
total: number;
|
|
12
|
+
};
|
|
13
|
+
export declare const EXPRESS_VIDEO_FIXED_COMPONENTS_TOTAL_PER_SECOND: number;
|
|
14
|
+
export declare const EXPRESS_VIDEO_CREDITS_PER_SECOND_BY_MODEL: {
|
|
15
|
+
readonly 'VEO3.1I2V': 60;
|
|
16
|
+
readonly 'VEO3.1I2VFAST': 36;
|
|
17
|
+
readonly SEEDANCEI2V: 30;
|
|
18
|
+
readonly KLINGIMGTOVID3PRO: 36;
|
|
19
|
+
readonly KLINGIMGTOVIDTURBO: 36;
|
|
20
|
+
readonly RUNWAYML: 30;
|
|
21
|
+
};
|
|
22
|
+
export declare const EXPRESS_VIDEO_PRICING_DISTRIBUTION_PER_SECOND_BY_MODEL: Record<string, ExpressVideoPricingDistribution>;
|
|
23
|
+
export declare function getExpressVideoCreditsPerSecond(model: string | null | undefined): 60 | 36 | 30;
|
|
24
|
+
export declare function getExpressVideoPricingDistributionPerSecond(model: string | null | undefined): ExpressVideoPricingDistribution;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const EXPRESS_VIDEO_FIXED_PRICING_COMPONENTS_PER_SECOND = {
|
|
2
|
+
pipeline: 4,
|
|
3
|
+
inference: 4,
|
|
4
|
+
image_gen_edit: 2,
|
|
5
|
+
speech: 2,
|
|
6
|
+
music: 2,
|
|
7
|
+
effects_and_lipsync: 2,
|
|
8
|
+
};
|
|
9
|
+
export const EXPRESS_VIDEO_FIXED_COMPONENTS_TOTAL_PER_SECOND = Object.values(EXPRESS_VIDEO_FIXED_PRICING_COMPONENTS_PER_SECOND).reduce((total, value) => total + value, 0);
|
|
10
|
+
export const EXPRESS_VIDEO_CREDITS_PER_SECOND_BY_MODEL = {
|
|
11
|
+
'VEO3.1I2V': 60,
|
|
12
|
+
'VEO3.1I2VFAST': 36,
|
|
13
|
+
SEEDANCEI2V: 30,
|
|
14
|
+
KLINGIMGTOVID3PRO: 36,
|
|
15
|
+
KLINGIMGTOVIDTURBO: 36,
|
|
16
|
+
RUNWAYML: 30,
|
|
17
|
+
};
|
|
18
|
+
export const EXPRESS_VIDEO_PRICING_DISTRIBUTION_PER_SECOND_BY_MODEL = Object.fromEntries(Object.entries(EXPRESS_VIDEO_CREDITS_PER_SECOND_BY_MODEL)
|
|
19
|
+
.map(([model, total]) => [
|
|
20
|
+
model,
|
|
21
|
+
{
|
|
22
|
+
...EXPRESS_VIDEO_FIXED_PRICING_COMPONENTS_PER_SECOND,
|
|
23
|
+
video: total - EXPRESS_VIDEO_FIXED_COMPONENTS_TOTAL_PER_SECOND,
|
|
24
|
+
total,
|
|
25
|
+
},
|
|
26
|
+
]));
|
|
27
|
+
export function getExpressVideoCreditsPerSecond(model) {
|
|
28
|
+
const modelKey = typeof model === 'string' ? model.trim().toUpperCase() : '';
|
|
29
|
+
return EXPRESS_VIDEO_CREDITS_PER_SECOND_BY_MODEL[modelKey] ?? null;
|
|
30
|
+
}
|
|
31
|
+
export function getExpressVideoPricingDistributionPerSecond(model) {
|
|
32
|
+
const modelKey = typeof model === 'string' ? model.trim().toUpperCase() : '';
|
|
33
|
+
return EXPRESS_VIDEO_PRICING_DISTRIBUTION_PER_SECOND_BY_MODEL[modelKey] ?? null;
|
|
34
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { EXPRESS_VIDEO_CREDITS_PER_SECOND_BY_MODEL, EXPRESS_VIDEO_FIXED_COMPONENTS_TOTAL_PER_SECOND, EXPRESS_VIDEO_FIXED_PRICING_COMPONENTS_PER_SECOND, EXPRESS_VIDEO_PRICING_DISTRIBUTION_PER_SECOND_BY_MODEL, getExpressVideoCreditsPerSecond, getExpressVideoPricingDistributionPerSecond, } from './express-video-pricing.js';
|
|
2
|
+
export type { ExpressVideoPricingDistribution } from './express-video-pricing.js';
|
|
1
3
|
type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
2
4
|
type QueryValue = string | number | boolean | null | undefined;
|
|
3
5
|
type QueryParams = Record<string, QueryValue>;
|
|
@@ -109,7 +111,7 @@ export interface FooterMetadataItem {
|
|
|
109
111
|
footerLogoImagePath?: string;
|
|
110
112
|
}
|
|
111
113
|
export type ImageListToVideoAspectRatio = '16:9' | '9:16';
|
|
112
|
-
export type ImageListToVideoModel = 'VEO3.1I2V' | '
|
|
114
|
+
export type ImageListToVideoModel = 'RUNWAYML' | 'VEO3.1I2V' | 'VEO3.1I2VFAST' | 'SEEDANCEI2V' | 'KLINGIMGTOVID3PRO' | 'CUSTOM_IMAGE_TO_VIDEO';
|
|
113
115
|
export interface ImageListToVideoItem {
|
|
114
116
|
image_url?: string;
|
|
115
117
|
imageUrl?: string;
|
|
@@ -182,6 +184,10 @@ export interface CreateVideoFromImageListInput {
|
|
|
182
184
|
addFooterAnimation?: boolean;
|
|
183
185
|
footer_metadata?: FooterMetadataItem[];
|
|
184
186
|
footerMetadata?: FooterMetadataItem[];
|
|
187
|
+
limit_single_narrator?: boolean;
|
|
188
|
+
limitSingleNarrator?: boolean;
|
|
189
|
+
add_narrator_avatar?: boolean;
|
|
190
|
+
addNarratorAvatar?: boolean;
|
|
185
191
|
[key: string]: unknown;
|
|
186
192
|
}
|
|
187
193
|
export interface TranscriptBuilderPayload {
|
|
@@ -203,6 +209,12 @@ export interface CreateVideoFromImageListResponse {
|
|
|
203
209
|
remainingCredits?: number | null;
|
|
204
210
|
[key: string]: unknown;
|
|
205
211
|
}
|
|
212
|
+
export interface CreateV2StepImageToVideoInput extends Omit<CreateVideoFromImageListInput, 'image_urls'> {
|
|
213
|
+
image_urls?: Array<string | ImageListToVideoItem>;
|
|
214
|
+
image_url?: string;
|
|
215
|
+
imageUrl?: string;
|
|
216
|
+
image?: string;
|
|
217
|
+
}
|
|
206
218
|
export interface TranslateVideoInput {
|
|
207
219
|
videoSessionId?: string;
|
|
208
220
|
video_session_id?: string;
|
|
@@ -552,6 +564,7 @@ export interface SupportedTextToVideoModelOption {
|
|
|
552
564
|
label: string;
|
|
553
565
|
value: string;
|
|
554
566
|
basePrice: number | null;
|
|
567
|
+
pricingDistribution?: Record<string, number> | null;
|
|
555
568
|
[key: string]: unknown;
|
|
556
569
|
}
|
|
557
570
|
export interface EnhanceMessageRequest {
|
|
@@ -1197,6 +1210,8 @@ export interface GlobalStatusResponse {
|
|
|
1197
1210
|
}
|
|
1198
1211
|
export interface ExternalUserIdentity {
|
|
1199
1212
|
provider: string;
|
|
1213
|
+
unique_key?: string;
|
|
1214
|
+
uniqueKey?: string;
|
|
1200
1215
|
external_user_id?: string;
|
|
1201
1216
|
externalUserId?: string;
|
|
1202
1217
|
external_app_id?: string;
|
|
@@ -1222,6 +1237,7 @@ export interface ExternalUserSummary {
|
|
|
1222
1237
|
id?: string | null;
|
|
1223
1238
|
provider?: string;
|
|
1224
1239
|
external_user_id?: string;
|
|
1240
|
+
unique_key?: string | null;
|
|
1225
1241
|
external_app_id?: string | null;
|
|
1226
1242
|
external_company_id?: string | null;
|
|
1227
1243
|
email?: string | null;
|
|
@@ -1392,9 +1408,173 @@ export interface ExternalRequestsListResponse {
|
|
|
1392
1408
|
[key: string]: unknown;
|
|
1393
1409
|
}
|
|
1394
1410
|
export interface V2RequestOptions extends SamsarRequestOptions {
|
|
1395
|
-
externalUser?:
|
|
1411
|
+
externalUser?: V2ExternalUserIdentity | null;
|
|
1396
1412
|
webhookUrl?: string;
|
|
1397
1413
|
}
|
|
1414
|
+
export type V2StepVideoStage = 'prompt_generation' | 'image_generation' | 'speech_generation' | 'music_generation' | 'audio_generation' | 'ai_video_generation' | 'lip_sync_generation' | 'sound_effect_generation' | 'narrator_avatar_generation' | 'delete_reflow' | 'timeline_reflowed' | 'transcript_generation' | 'frame_generation' | 'video_generation';
|
|
1415
|
+
export type V2StepVideoStatus = 'INIT' | 'PENDING' | 'COMPLETED' | 'FAILED' | string;
|
|
1416
|
+
export interface VideoSessionPreviewAsset {
|
|
1417
|
+
status?: V2StepVideoStatus;
|
|
1418
|
+
url?: string | null;
|
|
1419
|
+
editStatus?: string | null;
|
|
1420
|
+
description?: string | null;
|
|
1421
|
+
[key: string]: unknown;
|
|
1422
|
+
}
|
|
1423
|
+
export interface VideoSessionLayerPreview {
|
|
1424
|
+
stage?: V2StepVideoStage | 'user_video' | string;
|
|
1425
|
+
type?: 'image' | 'video' | 'audio' | string;
|
|
1426
|
+
url?: string | null;
|
|
1427
|
+
[key: string]: unknown;
|
|
1428
|
+
}
|
|
1429
|
+
export interface VideoSessionPreviewLayer {
|
|
1430
|
+
index: number;
|
|
1431
|
+
id?: string | null;
|
|
1432
|
+
startTime: number;
|
|
1433
|
+
endTime?: number | null;
|
|
1434
|
+
duration?: number | null;
|
|
1435
|
+
status?: string | null;
|
|
1436
|
+
prompt?: string | null;
|
|
1437
|
+
videoPrompt?: string | null;
|
|
1438
|
+
aiVideoType?: string | null;
|
|
1439
|
+
baseImageType?: string | null;
|
|
1440
|
+
soundEffectPrompt?: string | null;
|
|
1441
|
+
image?: VideoSessionPreviewAsset;
|
|
1442
|
+
aiVideo?: VideoSessionPreviewAsset | null;
|
|
1443
|
+
lipSyncVideo?: VideoSessionPreviewAsset | null;
|
|
1444
|
+
soundEffectVideo?: VideoSessionPreviewAsset | null;
|
|
1445
|
+
userVideo?: VideoSessionPreviewAsset | null;
|
|
1446
|
+
preview?: VideoSessionLayerPreview | null;
|
|
1447
|
+
[key: string]: unknown;
|
|
1448
|
+
}
|
|
1449
|
+
export interface VideoSessionPreviewAudioLayer {
|
|
1450
|
+
index: number;
|
|
1451
|
+
id?: string | null;
|
|
1452
|
+
type?: string;
|
|
1453
|
+
status?: V2StepVideoStatus;
|
|
1454
|
+
startTime: number;
|
|
1455
|
+
endTime?: number | null;
|
|
1456
|
+
duration?: number | null;
|
|
1457
|
+
sourceTrimStartTime?: number | null;
|
|
1458
|
+
prompt?: string | null;
|
|
1459
|
+
url?: string | null;
|
|
1460
|
+
remoteAudioLinks?: string[];
|
|
1461
|
+
volume?: number | null;
|
|
1462
|
+
isEnabled?: boolean | null;
|
|
1463
|
+
defaultSelected?: boolean | null;
|
|
1464
|
+
speaker?: string | null;
|
|
1465
|
+
provider?: string | null;
|
|
1466
|
+
speakerCharacterName?: string | null;
|
|
1467
|
+
lyrics?: string | null;
|
|
1468
|
+
connectedLayerId?: string | null;
|
|
1469
|
+
connectedLayerIndex?: number | null;
|
|
1470
|
+
audioBindingMode?: string | null;
|
|
1471
|
+
bindToLayer?: boolean | null;
|
|
1472
|
+
addSubtitles?: boolean | null;
|
|
1473
|
+
subtitleFont?: string | null;
|
|
1474
|
+
subtitleWordAnimation?: string | null;
|
|
1475
|
+
transcriptAlignment?: Record<string, unknown> | null;
|
|
1476
|
+
[key: string]: unknown;
|
|
1477
|
+
}
|
|
1478
|
+
export interface VideoSessionPreviewGlobalVideo {
|
|
1479
|
+
index: number;
|
|
1480
|
+
id?: string | null;
|
|
1481
|
+
type?: 'video' | string;
|
|
1482
|
+
source?: string | null;
|
|
1483
|
+
title?: string | null;
|
|
1484
|
+
status?: V2StepVideoStatus;
|
|
1485
|
+
startTime: number;
|
|
1486
|
+
endTime?: number | null;
|
|
1487
|
+
duration?: number | null;
|
|
1488
|
+
url?: string | null;
|
|
1489
|
+
framesPerSecond?: number | null;
|
|
1490
|
+
[key: string]: unknown;
|
|
1491
|
+
}
|
|
1492
|
+
export interface VideoSessionPreviewResult {
|
|
1493
|
+
url?: string | null;
|
|
1494
|
+
remoteURL?: string | null;
|
|
1495
|
+
videoLink?: string | null;
|
|
1496
|
+
hasSubtitles?: boolean;
|
|
1497
|
+
hasFooter?: boolean;
|
|
1498
|
+
language?: string | null;
|
|
1499
|
+
[key: string]: unknown;
|
|
1500
|
+
}
|
|
1501
|
+
export interface VideoStatusDetailedSession {
|
|
1502
|
+
id?: string | null;
|
|
1503
|
+
requestId?: string | null;
|
|
1504
|
+
type?: 'video' | string;
|
|
1505
|
+
routeType?: 'express' | 'step' | string;
|
|
1506
|
+
aspectRatio?: string | null;
|
|
1507
|
+
framesPerSecond?: number | null;
|
|
1508
|
+
duration?: number;
|
|
1509
|
+
language?: string | null;
|
|
1510
|
+
languageString?: string | null;
|
|
1511
|
+
hasSubtitles?: boolean;
|
|
1512
|
+
hasFooter?: boolean;
|
|
1513
|
+
inputPrompt?: string | null;
|
|
1514
|
+
generationType?: string | null;
|
|
1515
|
+
provider?: string | null;
|
|
1516
|
+
currentStage?: V2StepVideoStage | string;
|
|
1517
|
+
previewStage?: V2StepVideoStage | string;
|
|
1518
|
+
completedStages?: Array<V2StepVideoStage | string>;
|
|
1519
|
+
stages?: Record<string, V2StepVideoStatus | unknown>;
|
|
1520
|
+
layers?: VideoSessionPreviewLayer[];
|
|
1521
|
+
audioLayers?: VideoSessionPreviewAudioLayer[];
|
|
1522
|
+
globalAudioLayers?: VideoSessionPreviewAudioLayer[];
|
|
1523
|
+
globalVideos?: VideoSessionPreviewGlobalVideo[];
|
|
1524
|
+
result?: VideoSessionPreviewResult;
|
|
1525
|
+
createdAt?: string | null;
|
|
1526
|
+
updatedAt?: string | null;
|
|
1527
|
+
[key: string]: unknown;
|
|
1528
|
+
}
|
|
1529
|
+
export interface GlobalStatusDetailedResponse extends GlobalStatusResponse {
|
|
1530
|
+
status_detail_schema?: 'video_session_preview.v1' | string;
|
|
1531
|
+
session?: VideoStatusDetailedSession | null;
|
|
1532
|
+
}
|
|
1533
|
+
export interface ExternalStatusDetailedResponse extends ExternalStatusResponse {
|
|
1534
|
+
status_detail_schema?: 'video_session_preview.v1' | string;
|
|
1535
|
+
session?: VideoStatusDetailedSession | null;
|
|
1536
|
+
}
|
|
1537
|
+
export interface V2StepVideoState {
|
|
1538
|
+
enabled?: boolean;
|
|
1539
|
+
route_type?: 'text_to_video' | 'image_to_video' | string | null;
|
|
1540
|
+
status?: V2StepVideoStatus;
|
|
1541
|
+
current_step?: V2StepVideoStage | string | null;
|
|
1542
|
+
current_step_label?: string | null;
|
|
1543
|
+
next_step?: V2StepVideoStage | string | null;
|
|
1544
|
+
waiting_for_process_next?: boolean;
|
|
1545
|
+
updated_at?: string | null;
|
|
1546
|
+
[key: string]: unknown;
|
|
1547
|
+
}
|
|
1548
|
+
export interface V2StepVideoResourceBlock {
|
|
1549
|
+
step?: V2StepVideoStage | string;
|
|
1550
|
+
label?: string;
|
|
1551
|
+
status?: V2StepVideoStatus;
|
|
1552
|
+
completed_at?: string | null;
|
|
1553
|
+
resources?: Record<string, unknown>;
|
|
1554
|
+
[key: string]: unknown;
|
|
1555
|
+
}
|
|
1556
|
+
export interface V2StepVideoStatusResponse extends GlobalStatusResponse {
|
|
1557
|
+
step_status?: V2StepVideoStatus;
|
|
1558
|
+
current_step?: V2StepVideoStage | string | null;
|
|
1559
|
+
current_step_label?: string | null;
|
|
1560
|
+
next_step?: V2StepVideoStage | string | null;
|
|
1561
|
+
waiting_for_process_next?: boolean;
|
|
1562
|
+
process_next_url?: string;
|
|
1563
|
+
step?: V2StepVideoState;
|
|
1564
|
+
current_step_resources?: V2StepVideoResourceBlock | null;
|
|
1565
|
+
completed_step_resources?: Record<string, V2StepVideoResourceBlock>;
|
|
1566
|
+
}
|
|
1567
|
+
export interface V2StepVideoDetailedStatusResponse extends V2StepVideoStatusResponse {
|
|
1568
|
+
status_detail_schema?: 'video_session_preview.v1' | string;
|
|
1569
|
+
session?: VideoStatusDetailedSession | null;
|
|
1570
|
+
}
|
|
1571
|
+
export interface V2StepVideoCreateResponse extends CreateVideoResponse {
|
|
1572
|
+
status?: V2StepVideoStatus;
|
|
1573
|
+
step?: V2StepVideoState;
|
|
1574
|
+
}
|
|
1575
|
+
export interface V2ExternalUserIdentity extends Omit<ExternalUserIdentity, 'provider'> {
|
|
1576
|
+
provider?: string;
|
|
1577
|
+
}
|
|
1398
1578
|
export interface V2SessionResponse {
|
|
1399
1579
|
account_type?: 'internal' | 'external' | string;
|
|
1400
1580
|
auth_type?: string;
|
|
@@ -1450,6 +1630,27 @@ export interface V2UserTokenResponse {
|
|
|
1450
1630
|
refreshTokenExpiresAt?: string;
|
|
1451
1631
|
[key: string]: unknown;
|
|
1452
1632
|
}
|
|
1633
|
+
export interface V2CreateExternalUserRequest extends V2ExternalUserIdentity {
|
|
1634
|
+
external_user?: V2ExternalUserIdentity | null;
|
|
1635
|
+
externalUser?: V2ExternalUserIdentity | null;
|
|
1636
|
+
}
|
|
1637
|
+
export interface V2CreateExternalUserReference {
|
|
1638
|
+
provider?: string | null;
|
|
1639
|
+
unique_key?: string | null;
|
|
1640
|
+
external_user_id?: string | null;
|
|
1641
|
+
external_app_id?: string | null;
|
|
1642
|
+
[key: string]: unknown;
|
|
1643
|
+
}
|
|
1644
|
+
export interface V2CreateExternalUserResponse {
|
|
1645
|
+
unique_key?: string | null;
|
|
1646
|
+
provider?: string | null;
|
|
1647
|
+
external_user_id?: string | null;
|
|
1648
|
+
external_app_id?: string | null;
|
|
1649
|
+
external_user?: ExternalUserSummary | null;
|
|
1650
|
+
externalUser?: ExternalUserSummary | null;
|
|
1651
|
+
reference?: V2CreateExternalUserReference;
|
|
1652
|
+
[key: string]: unknown;
|
|
1653
|
+
}
|
|
1453
1654
|
export interface V2UserAppKeyRequest {
|
|
1454
1655
|
secret?: string;
|
|
1455
1656
|
appSecret?: string;
|
|
@@ -1592,6 +1793,7 @@ export interface VerifiedClientSessionResponse {
|
|
|
1592
1793
|
avatarUrl?: string | null;
|
|
1593
1794
|
provider?: string | null;
|
|
1594
1795
|
externalUserId?: string | null;
|
|
1796
|
+
uniqueKey?: string | null;
|
|
1595
1797
|
externalAppId?: string | null;
|
|
1596
1798
|
externalCompanyId?: string | null;
|
|
1597
1799
|
generationCredits?: number;
|
|
@@ -1728,6 +1930,7 @@ export declare class SamsarClient {
|
|
|
1728
1930
|
limit?: number;
|
|
1729
1931
|
}): Promise<SamsarResult<UsageLogsResponse>>;
|
|
1730
1932
|
listV2Requests(options?: V2RequestOptions): Promise<SamsarResult<V2RequestsListResponse>>;
|
|
1933
|
+
createV2ExternalUser(payload: V2CreateExternalUserRequest, options?: V2RequestOptions): Promise<SamsarResult<V2CreateExternalUserResponse>>;
|
|
1731
1934
|
createV2UserRechargeCredits(payload: V2UserRechargeCreditsRequest, options?: V2RequestOptions): Promise<SamsarResult<V2UserRechargeCreditsResponse>>;
|
|
1732
1935
|
refreshV2UserToken(payload: string | V2UserTokenRefreshRequest, options?: V2RequestOptions): Promise<SamsarResult<V2UserTokenResponse>>;
|
|
1733
1936
|
refreshV2UserAuthToken(payload: string | V2UserTokenRefreshRequest, options?: V2RequestOptions): Promise<SamsarResult<V2UserTokenResponse>>;
|
|
@@ -1741,6 +1944,14 @@ export declare class SamsarClient {
|
|
|
1741
1944
|
}): Promise<SamsarResult<CreateLoginTokenResponse | ExternalCreateLoginTokenResponse>>;
|
|
1742
1945
|
createV2VideoFromText(input: CreateVideoFromTextInput, options?: V2RequestOptions): Promise<SamsarResult<CreateVideoResponse | ExternalRequestResponse>>;
|
|
1743
1946
|
createV2VideoFromImageList(input: CreateVideoFromImageListInput, options?: V2RequestOptions): Promise<SamsarResult<CreateVideoFromImageListResponse | ExternalRequestResponse>>;
|
|
1947
|
+
createV2StepVideoFromText(input: CreateVideoFromTextInput, options?: V2RequestOptions): Promise<SamsarResult<V2StepVideoCreateResponse>>;
|
|
1948
|
+
createV2StepTextToVideo(input: CreateVideoFromTextInput, options?: V2RequestOptions): Promise<SamsarResult<V2StepVideoCreateResponse>>;
|
|
1949
|
+
createV2StepVideoFromImage(input: CreateV2StepImageToVideoInput, options?: V2RequestOptions): Promise<SamsarResult<V2StepVideoCreateResponse>>;
|
|
1950
|
+
createV2StepImageToVideo(input: CreateV2StepImageToVideoInput, options?: V2RequestOptions): Promise<SamsarResult<V2StepVideoCreateResponse>>;
|
|
1951
|
+
getV2StepVideoStatus(requestId: string, options?: V2RequestOptions): Promise<SamsarResult<V2StepVideoStatusResponse>>;
|
|
1952
|
+
getV2StepVideoStatusDetailed(requestId: string, options?: V2RequestOptions): Promise<SamsarResult<V2StepVideoDetailedStatusResponse>>;
|
|
1953
|
+
getV2StepVideoDetailedStatus(requestId: string, options?: V2RequestOptions): Promise<SamsarResult<V2StepVideoDetailedStatusResponse>>;
|
|
1954
|
+
processNextV2StepVideo(requestId: string, options?: V2RequestOptions): Promise<SamsarResult<V2StepVideoStatusResponse>>;
|
|
1744
1955
|
translateV2Video(input: TranslateVideoInput, options?: V2RequestOptions): Promise<SamsarResult<TranslateVideoResponse | ExternalRequestResponse>>;
|
|
1745
1956
|
cloneV2Video(input: CloneVideoInput, options?: V2RequestOptions): Promise<SamsarResult<CloneVideoResponse>>;
|
|
1746
1957
|
uploadV2ImageData(imageData: string[], options?: V2RequestOptions): Promise<SamsarResult<{
|
|
@@ -1752,6 +1963,12 @@ export declare class SamsarClient {
|
|
|
1752
1963
|
getV2Status(requestId: string, options?: V2RequestOptions & {
|
|
1753
1964
|
queryParams?: QueryParams;
|
|
1754
1965
|
}): Promise<SamsarResult<GlobalStatusResponse | ExternalStatusResponse>>;
|
|
1966
|
+
getV2StatusDetailed(requestId: string, options?: V2RequestOptions & {
|
|
1967
|
+
queryParams?: QueryParams;
|
|
1968
|
+
}): Promise<SamsarResult<GlobalStatusDetailedResponse | ExternalStatusDetailedResponse>>;
|
|
1969
|
+
getV2DetailedStatus(requestId: string, options?: V2RequestOptions & {
|
|
1970
|
+
queryParams?: QueryParams;
|
|
1971
|
+
}): Promise<SamsarResult<GlobalStatusDetailedResponse | ExternalStatusDetailedResponse>>;
|
|
1755
1972
|
/**
|
|
1756
1973
|
* Create a new video generation job from text.
|
|
1757
1974
|
*/
|
|
@@ -2127,6 +2344,12 @@ export declare class SamsarClient {
|
|
|
2127
2344
|
getExternalStatus(requestId: string, options?: SamsarRequestOptions & {
|
|
2128
2345
|
queryParams?: QueryParams;
|
|
2129
2346
|
}): Promise<SamsarResult<ExternalStatusResponse>>;
|
|
2347
|
+
/**
|
|
2348
|
+
* Retrieve external-user status plus normalized video-session preview data.
|
|
2349
|
+
*/
|
|
2350
|
+
getExternalStatusDetailed(requestId: string, options?: SamsarRequestOptions & {
|
|
2351
|
+
queryParams?: QueryParams;
|
|
2352
|
+
}): Promise<SamsarResult<ExternalStatusDetailedResponse>>;
|
|
2130
2353
|
/**
|
|
2131
2354
|
* Retrieve the status of an image request (maps to GET /image/status).
|
|
2132
2355
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const DEFAULT_BASE_URL = 'https://api.samsar.one/v1';
|
|
2
|
+
export { EXPRESS_VIDEO_CREDITS_PER_SECOND_BY_MODEL, EXPRESS_VIDEO_FIXED_COMPONENTS_TOTAL_PER_SECOND, EXPRESS_VIDEO_FIXED_PRICING_COMPONENTS_PER_SECOND, EXPRESS_VIDEO_PRICING_DISTRIBUTION_PER_SECOND_BY_MODEL, getExpressVideoCreditsPerSecond, getExpressVideoPricingDistributionPerSecond, } from './express-video-pricing.js';
|
|
2
3
|
const DEBUG = (() => {
|
|
3
4
|
const env = globalThis?.process?.env;
|
|
4
5
|
return env?.SAMSAR_SDK_DEBUG === '1';
|
|
@@ -101,6 +102,8 @@ function normalizeCreateVideoFromImageListInput(input) {
|
|
|
101
102
|
['cta_logo', ['cta_logo', 'ctaLogo']],
|
|
102
103
|
['add_footer_animation', ['add_footer_animation', 'addFooterAnimation']],
|
|
103
104
|
['footer_metadata', ['footer_metadata', 'footerMetadata']],
|
|
105
|
+
['limit_single_narrator', ['limit_single_narrator', 'limitSingleNarrator']],
|
|
106
|
+
['add_narrator_avatar', ['add_narrator_avatar', 'addNarratorAvatar']],
|
|
104
107
|
['enable_subtitles', ['enable_subtitles', 'enableSubtitles']],
|
|
105
108
|
['font_key', ['font_key', 'fontKey']],
|
|
106
109
|
];
|
|
@@ -115,6 +118,11 @@ function normalizeCreateVideoFromImageListInput(input) {
|
|
|
115
118
|
assertOptionalBoolean(normalized.add_outro_focus_area, 'add_outro_focus_area');
|
|
116
119
|
assertOptionalBoolean(normalized.generate_outro_image, 'generate_outro_image');
|
|
117
120
|
assertOptionalBoolean(normalized.add_footer_animation, 'add_footer_animation');
|
|
121
|
+
assertOptionalBoolean(normalized.limit_single_narrator, 'limit_single_narrator');
|
|
122
|
+
assertOptionalBoolean(normalized.add_narrator_avatar, 'add_narrator_avatar');
|
|
123
|
+
if (normalized.add_narrator_avatar === true) {
|
|
124
|
+
normalized.limit_single_narrator = true;
|
|
125
|
+
}
|
|
118
126
|
if (normalized.generate_outro_image === true) {
|
|
119
127
|
const ctaUrl = typeof normalized.cta_url === 'string' ? normalized.cta_url.trim() : '';
|
|
120
128
|
if (!ctaUrl) {
|
|
@@ -126,6 +134,23 @@ function normalizeCreateVideoFromImageListInput(input) {
|
|
|
126
134
|
}
|
|
127
135
|
return normalized;
|
|
128
136
|
}
|
|
137
|
+
function normalizeCreateV2StepImageToVideoInput(input) {
|
|
138
|
+
const raw = input;
|
|
139
|
+
const normalized = { ...input };
|
|
140
|
+
if (!Array.isArray(input.image_urls) || input.image_urls.length === 0) {
|
|
141
|
+
const imageUrl = getTrimmedString(raw.image_url) ??
|
|
142
|
+
getTrimmedString(raw.imageUrl) ??
|
|
143
|
+
getTrimmedString(raw.image);
|
|
144
|
+
if (!imageUrl) {
|
|
145
|
+
throw new Error('image_url or image_urls is required for createV2StepVideoFromImage');
|
|
146
|
+
}
|
|
147
|
+
normalized.image_urls = [imageUrl];
|
|
148
|
+
}
|
|
149
|
+
delete normalized.image_url;
|
|
150
|
+
delete normalized.imageUrl;
|
|
151
|
+
delete normalized.image;
|
|
152
|
+
return normalizeCreateVideoFromImageListInput(normalized);
|
|
153
|
+
}
|
|
129
154
|
function normalizeTranslateVideoInput(input, context = 'translateVideo') {
|
|
130
155
|
const raw = input;
|
|
131
156
|
const videoSessionId = raw.videoSessionId ??
|
|
@@ -416,7 +441,9 @@ export class SamsarClient {
|
|
|
416
441
|
*/
|
|
417
442
|
async getV2(path, options) {
|
|
418
443
|
const query = {
|
|
419
|
-
...(options?.externalUser
|
|
444
|
+
...(options?.externalUser
|
|
445
|
+
? buildExternalUserQuery(options.externalUser, { requireProvider: false })
|
|
446
|
+
: {}),
|
|
420
447
|
...(options?.query ?? {}),
|
|
421
448
|
};
|
|
422
449
|
return this.get(this.buildV2Url(path), { ...(options ?? {}), query });
|
|
@@ -451,6 +478,27 @@ export class SamsarClient {
|
|
|
451
478
|
async listV2Requests(options) {
|
|
452
479
|
return this.getV2('requests', options);
|
|
453
480
|
}
|
|
481
|
+
async createV2ExternalUser(payload, options) {
|
|
482
|
+
const input = payload ?? {};
|
|
483
|
+
const nestedExternalUser = (input.external_user ?? input.externalUser ?? {});
|
|
484
|
+
const uniqueKey = getTrimmedString(nestedExternalUser.unique_key ??
|
|
485
|
+
nestedExternalUser.uniqueKey ??
|
|
486
|
+
input.unique_key ??
|
|
487
|
+
input.uniqueKey);
|
|
488
|
+
const externalUserId = getTrimmedString(nestedExternalUser.external_user_id ??
|
|
489
|
+
nestedExternalUser.externalUserId ??
|
|
490
|
+
input.external_user_id ??
|
|
491
|
+
input.externalUserId);
|
|
492
|
+
const referenceKey = uniqueKey ?? externalUserId;
|
|
493
|
+
if (!referenceKey) {
|
|
494
|
+
throw new Error('unique_key or external_user_id is required');
|
|
495
|
+
}
|
|
496
|
+
return this.postV2('user/create_external_user', {
|
|
497
|
+
...input,
|
|
498
|
+
unique_key: referenceKey,
|
|
499
|
+
...(externalUserId ? { external_user_id: externalUserId } : {}),
|
|
500
|
+
}, options);
|
|
501
|
+
}
|
|
454
502
|
async createV2UserRechargeCredits(payload, options) {
|
|
455
503
|
const amount = Number(payload?.amount);
|
|
456
504
|
if (!Number.isFinite(amount) || amount <= 0) {
|
|
@@ -556,6 +604,50 @@ export class SamsarClient {
|
|
|
556
604
|
webhookUrl: options?.webhookUrl,
|
|
557
605
|
}, options);
|
|
558
606
|
}
|
|
607
|
+
async createV2StepVideoFromText(input, options) {
|
|
608
|
+
const normalizedInput = normalizeCreateVideoFromTextInput(input);
|
|
609
|
+
return this.postV2('video/step/text_to_video', {
|
|
610
|
+
input: normalizedInput,
|
|
611
|
+
webhookUrl: options?.webhookUrl,
|
|
612
|
+
}, options);
|
|
613
|
+
}
|
|
614
|
+
async createV2StepTextToVideo(input, options) {
|
|
615
|
+
return this.createV2StepVideoFromText(input, options);
|
|
616
|
+
}
|
|
617
|
+
async createV2StepVideoFromImage(input, options) {
|
|
618
|
+
const normalizedInput = normalizeCreateV2StepImageToVideoInput(input);
|
|
619
|
+
return this.postV2('video/step/image_to_video', {
|
|
620
|
+
input: normalizedInput,
|
|
621
|
+
webhookUrl: options?.webhookUrl,
|
|
622
|
+
}, options);
|
|
623
|
+
}
|
|
624
|
+
async createV2StepImageToVideo(input, options) {
|
|
625
|
+
return this.createV2StepVideoFromImage(input, options);
|
|
626
|
+
}
|
|
627
|
+
async getV2StepVideoStatus(requestId, options) {
|
|
628
|
+
const normalizedRequestId = getTrimmedString(requestId);
|
|
629
|
+
if (!normalizedRequestId) {
|
|
630
|
+
throw new Error('requestId is required');
|
|
631
|
+
}
|
|
632
|
+
return this.getV2(`video/step/${encodeURIComponent(normalizedRequestId)}/status`, options);
|
|
633
|
+
}
|
|
634
|
+
async getV2StepVideoStatusDetailed(requestId, options) {
|
|
635
|
+
const normalizedRequestId = getTrimmedString(requestId);
|
|
636
|
+
if (!normalizedRequestId) {
|
|
637
|
+
throw new Error('requestId is required');
|
|
638
|
+
}
|
|
639
|
+
return this.getV2(`video/step/${encodeURIComponent(normalizedRequestId)}/status_detailed`, options);
|
|
640
|
+
}
|
|
641
|
+
async getV2StepVideoDetailedStatus(requestId, options) {
|
|
642
|
+
return this.getV2StepVideoStatusDetailed(requestId, options);
|
|
643
|
+
}
|
|
644
|
+
async processNextV2StepVideo(requestId, options) {
|
|
645
|
+
const normalizedRequestId = getTrimmedString(requestId);
|
|
646
|
+
if (!normalizedRequestId) {
|
|
647
|
+
throw new Error('requestId is required');
|
|
648
|
+
}
|
|
649
|
+
return this.postV2(`video/step/${encodeURIComponent(normalizedRequestId)}/process_next`, {}, options);
|
|
650
|
+
}
|
|
559
651
|
async translateV2Video(input, options) {
|
|
560
652
|
const normalizedInput = normalizeTranslateVideoInput(input, 'translateV2Video');
|
|
561
653
|
return this.postV2('translate_video', {
|
|
@@ -602,7 +694,9 @@ export class SamsarClient {
|
|
|
602
694
|
}
|
|
603
695
|
async getV2Status(requestId, options) {
|
|
604
696
|
const queryParams = {
|
|
605
|
-
...(options?.externalUser
|
|
697
|
+
...(options?.externalUser
|
|
698
|
+
? buildExternalUserQuery(options.externalUser, { requireProvider: false })
|
|
699
|
+
: {}),
|
|
606
700
|
...(options?.queryParams ?? {}),
|
|
607
701
|
};
|
|
608
702
|
return this.getStatus(requestId, {
|
|
@@ -611,6 +705,22 @@ export class SamsarClient {
|
|
|
611
705
|
queryParams,
|
|
612
706
|
});
|
|
613
707
|
}
|
|
708
|
+
async getV2StatusDetailed(requestId, options) {
|
|
709
|
+
const queryParams = {
|
|
710
|
+
...(options?.externalUser
|
|
711
|
+
? buildExternalUserQuery(options.externalUser, { requireProvider: false })
|
|
712
|
+
: {}),
|
|
713
|
+
...(options?.queryParams ?? {}),
|
|
714
|
+
};
|
|
715
|
+
return this.getStatus(requestId, {
|
|
716
|
+
...options,
|
|
717
|
+
path: this.buildV2Url('status_detailed'),
|
|
718
|
+
queryParams,
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
async getV2DetailedStatus(requestId, options) {
|
|
722
|
+
return this.getV2StatusDetailed(requestId, options);
|
|
723
|
+
}
|
|
614
724
|
/**
|
|
615
725
|
* Create a new video generation job from text.
|
|
616
726
|
*/
|
|
@@ -1876,6 +1986,16 @@ export class SamsarClient {
|
|
|
1876
1986
|
});
|
|
1877
1987
|
return response;
|
|
1878
1988
|
}
|
|
1989
|
+
/**
|
|
1990
|
+
* Retrieve external-user status plus normalized video-session preview data.
|
|
1991
|
+
*/
|
|
1992
|
+
async getExternalStatusDetailed(requestId, options) {
|
|
1993
|
+
const response = await this.getStatus(requestId, {
|
|
1994
|
+
...options,
|
|
1995
|
+
path: 'external_users/status_detailed',
|
|
1996
|
+
});
|
|
1997
|
+
return response;
|
|
1998
|
+
}
|
|
1879
1999
|
/**
|
|
1880
2000
|
* Retrieve the status of an image request (maps to GET /image/status).
|
|
1881
2001
|
*/
|
|
@@ -2015,9 +2135,29 @@ export class SamsarClient {
|
|
|
2015
2135
|
if (!options?.externalUser) {
|
|
2016
2136
|
return body;
|
|
2017
2137
|
}
|
|
2138
|
+
const externalUser = normalizeExternalUserIdentity(options.externalUser, {
|
|
2139
|
+
requireProvider: false,
|
|
2140
|
+
});
|
|
2141
|
+
if (!externalUser.provider) {
|
|
2142
|
+
const referenceKey = externalUser.unique_key ?? externalUser.external_user_id;
|
|
2143
|
+
return {
|
|
2144
|
+
...body,
|
|
2145
|
+
unique_key: referenceKey,
|
|
2146
|
+
...(externalUser.external_user_id ? { external_user_id: externalUser.external_user_id } : {}),
|
|
2147
|
+
...(externalUser.external_app_id ? { external_app_id: externalUser.external_app_id } : {}),
|
|
2148
|
+
...(externalUser.external_company_id ? { external_company_id: externalUser.external_company_id } : {}),
|
|
2149
|
+
...(externalUser.external_account_id ? { external_account_id: externalUser.external_account_id } : {}),
|
|
2150
|
+
...(externalUser.email ? { email: externalUser.email } : {}),
|
|
2151
|
+
...(externalUser.username ? { username: externalUser.username } : {}),
|
|
2152
|
+
...(externalUser.display_name ? { display_name: externalUser.display_name } : {}),
|
|
2153
|
+
...(externalUser.avatar_url ? { avatar_url: externalUser.avatar_url } : {}),
|
|
2154
|
+
...(externalUser.user_type ? { user_type: externalUser.user_type } : {}),
|
|
2155
|
+
...(externalUser.metadata ? { metadata: externalUser.metadata } : {}),
|
|
2156
|
+
};
|
|
2157
|
+
}
|
|
2018
2158
|
return {
|
|
2019
2159
|
...body,
|
|
2020
|
-
external_user:
|
|
2160
|
+
external_user: externalUser,
|
|
2021
2161
|
};
|
|
2022
2162
|
}
|
|
2023
2163
|
buildV2Url(path) {
|
|
@@ -2066,6 +2206,13 @@ function parseNumber(value) {
|
|
|
2066
2206
|
const num = value !== undefined ? Number(value) : NaN;
|
|
2067
2207
|
return Number.isFinite(num) ? num : undefined;
|
|
2068
2208
|
}
|
|
2209
|
+
function getTrimmedString(value) {
|
|
2210
|
+
if (typeof value !== 'string') {
|
|
2211
|
+
return undefined;
|
|
2212
|
+
}
|
|
2213
|
+
const trimmed = value.trim();
|
|
2214
|
+
return trimmed || undefined;
|
|
2215
|
+
}
|
|
2069
2216
|
function removeEmptyHeaders(headers) {
|
|
2070
2217
|
const normalized = {};
|
|
2071
2218
|
for (const [key, value] of Object.entries(headers)) {
|
|
@@ -2075,15 +2222,22 @@ function removeEmptyHeaders(headers) {
|
|
|
2075
2222
|
}
|
|
2076
2223
|
return normalized;
|
|
2077
2224
|
}
|
|
2078
|
-
function normalizeExternalUserIdentity(externalUser) {
|
|
2079
|
-
const
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2225
|
+
function normalizeExternalUserIdentity(externalUser, { requireProvider = true } = {}) {
|
|
2226
|
+
const provider = getTrimmedString(externalUser.provider);
|
|
2227
|
+
const uniqueKey = getTrimmedString(externalUser.unique_key ??
|
|
2228
|
+
externalUser.uniqueKey);
|
|
2229
|
+
const externalUserId = getTrimmedString(externalUser.external_user_id) ??
|
|
2230
|
+
getTrimmedString(externalUser.externalUserId) ??
|
|
2231
|
+
uniqueKey;
|
|
2232
|
+
if ((requireProvider && !provider) || !externalUserId) {
|
|
2233
|
+
throw new Error(requireProvider
|
|
2234
|
+
? 'externalUser.provider and externalUser.external_user_id or externalUser.unique_key are required'
|
|
2235
|
+
: 'externalUser.external_user_id or externalUser.unique_key is required');
|
|
2083
2236
|
}
|
|
2084
2237
|
return {
|
|
2085
|
-
provider:
|
|
2238
|
+
...(provider ? { provider } : {}),
|
|
2086
2239
|
external_user_id: externalUserId,
|
|
2240
|
+
...(uniqueKey ? { unique_key: uniqueKey } : {}),
|
|
2087
2241
|
...(externalUser.external_app_id || externalUser.externalAppId
|
|
2088
2242
|
? { external_app_id: externalUser.external_app_id ?? externalUser.externalAppId }
|
|
2089
2243
|
: {}),
|
|
@@ -2112,11 +2266,12 @@ function normalizeExternalUserIdentity(externalUser) {
|
|
|
2112
2266
|
...(externalUser.metadata ? { metadata: externalUser.metadata } : {}),
|
|
2113
2267
|
};
|
|
2114
2268
|
}
|
|
2115
|
-
function buildExternalUserQuery(externalUser) {
|
|
2116
|
-
const normalized = normalizeExternalUserIdentity(externalUser);
|
|
2269
|
+
function buildExternalUserQuery(externalUser, { requireProvider = true } = {}) {
|
|
2270
|
+
const normalized = normalizeExternalUserIdentity(externalUser, { requireProvider });
|
|
2117
2271
|
return {
|
|
2118
2272
|
provider: normalized.provider,
|
|
2119
2273
|
external_user_id: normalized.external_user_id,
|
|
2274
|
+
unique_key: normalized.unique_key ?? undefined,
|
|
2120
2275
|
external_app_id: normalized.external_app_id ?? undefined,
|
|
2121
2276
|
external_company_id: normalized.external_company_id ?? undefined,
|
|
2122
2277
|
external_account_id: normalized.external_account_id ?? undefined,
|