@sogni-ai/sogni-creative-agent-skill 3.52.4 → 3.54.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/.agents/skills/sogni-creative-agent-skill/SKILL.md +5 -2
- package/.agents/skills/sogni-creative-agent-skill/references/hosted-api.md +53 -2
- package/.agents/skills/sogni-creative-agent-skill/references/long-jobs-and-queues.md +79 -0
- package/.agents/skills/sogni-creative-agent-skill/references/models.md +50 -2
- package/.agents/skills/sogni-creative-agent-skill/references/video-prompting.md +79 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +29 -0
- package/README.md +11 -2
- package/SKILL.md +14 -14
- package/desktop-extension/manifest.json +1 -1
- package/desktop-extension/server/tools.mjs +28 -0
- package/generated/creative-agent-runtime.mjs +9 -6
- package/llm.txt +4 -2
- package/openclaw.plugin.json +1 -1
- package/package.json +3 -3
- package/plugin-skills/sogni-creative-agent/SKILL.md +3 -0
- package/references/hosted-api.md +53 -2
- package/references/long-jobs-and-queues.md +79 -0
- package/references/models.md +50 -2
- package/references/video-prompting.md +79 -1
- package/scripts/sync-hermes-skill.mjs +1 -0
- package/skill-package.json +2 -2
- package/skills/video_editing.md +1 -0
- package/skills/video_generation.md +1 -0
- package/sogni-agent.mjs +786 -24
- package/version.mjs +1 -1
package/sogni-agent.mjs
CHANGED
|
@@ -104,7 +104,15 @@ import {
|
|
|
104
104
|
isMinimaxH3TwoStageModelId,
|
|
105
105
|
minimaxH3TwoStageCanvasShortEdge,
|
|
106
106
|
minimaxH3TwoStageDeliveredSize,
|
|
107
|
-
prepareSeedanceV2VSourceVideo as prepareSharedSeedanceV2VSourceVideo
|
|
107
|
+
prepareSeedanceV2VSourceVideo as prepareSharedSeedanceV2VSourceVideo,
|
|
108
|
+
getWan22VideoSizeRefusal,
|
|
109
|
+
WAN22_MAX_VIDEO_PIXELS,
|
|
110
|
+
// MiniMax H3 intermediate keyframes: the frame math and checks every
|
|
111
|
+
// surface shares (Intelligence Client with SDK 5.58.0 keyframes support).
|
|
112
|
+
checkMinimaxH3Keyframes,
|
|
113
|
+
isMinimaxH3KeyframeModelId,
|
|
114
|
+
minimaxH3KeyframeFrameIndex,
|
|
115
|
+
MINIMAX_H3_MAX_KEYFRAMES
|
|
108
116
|
} from '@sogni-ai/sogni-intelligence-client/media';
|
|
109
117
|
import {
|
|
110
118
|
HAPPYHORSE_REFERENCE_LIMITS,
|
|
@@ -821,9 +829,32 @@ function classifyCliError(error, context = {}) {
|
|
|
821
829
|
if (happyhorseClassified) return happyhorseClassified;
|
|
822
830
|
}
|
|
823
831
|
|
|
832
|
+
// Socket 4100: no online worker serving this model can pin MiniMax H3
|
|
833
|
+
// keyframes yet. That is capacity, not a defect in the request: retryable.
|
|
834
|
+
if (isMiniMaxH3KeyframesUnavailableError(error)) {
|
|
835
|
+
const socketMessage = /keyframe/i.test(rawMessage) ? rawMessage : null;
|
|
836
|
+
return {
|
|
837
|
+
error_type: 'MODEL_UNAVAILABLE',
|
|
838
|
+
category: 'model_unavailable',
|
|
839
|
+
message: socketMessage || MINIMAX_H3_KEYFRAMES_UNAVAILABLE_MESSAGE,
|
|
840
|
+
retryable: true,
|
|
841
|
+
...(!socketMessage && rawMessage ? { technicalError: rawMessage } : {})
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
|
|
824
845
|
return classifySkillError(error);
|
|
825
846
|
}
|
|
826
847
|
|
|
848
|
+
const MINIMAX_H3_KEYFRAMES_UNAVAILABLE_CODE = '4100';
|
|
849
|
+
const MINIMAX_H3_KEYFRAMES_UNAVAILABLE_MESSAGE = 'No worker that can pin MiniMax H3 keyframes is online for this model right now. '
|
|
850
|
+
+ 'Try again shortly, or render without --keyframe.';
|
|
851
|
+
|
|
852
|
+
function isMiniMaxH3KeyframesUnavailableError(error) {
|
|
853
|
+
if (!error || typeof error !== 'object') return false;
|
|
854
|
+
return [error.code, error.errorCode, error.error_code, error.originalCode, error.payload?.errorCode, error.payload?.error_code]
|
|
855
|
+
.some((code) => code !== undefined && code !== null && String(code) === MINIMAX_H3_KEYFRAMES_UNAVAILABLE_CODE);
|
|
856
|
+
}
|
|
857
|
+
|
|
827
858
|
function addCanonicalErrorFields(payload, error, context = {}) {
|
|
828
859
|
const classified = classifyCliError(error, context);
|
|
829
860
|
payload.error = classified.message;
|
|
@@ -1049,6 +1080,7 @@ function applyCreativeBrainPreflight() {
|
|
|
1049
1080
|
options.height = plan.height;
|
|
1050
1081
|
widthFromPrompt = true;
|
|
1051
1082
|
heightFromPrompt = true;
|
|
1083
|
+
exactPixelsFromPrompt = true;
|
|
1052
1084
|
}
|
|
1053
1085
|
// The planner reports a stated aspect even when --target-resolution keeps it
|
|
1054
1086
|
// from sizing the canvas itself (dimensionSource stays unset then). The aspect
|
|
@@ -1228,6 +1260,8 @@ function computePromptHashSeed(opts) {
|
|
|
1228
1260
|
loraStrengths: opts.loraStrengths || [],
|
|
1229
1261
|
refImage: opts.refImage || '',
|
|
1230
1262
|
refImageEnd: opts.refImageEnd || '',
|
|
1263
|
+
// Only when present, so seeds of requests without keyframes never change.
|
|
1264
|
+
...(opts.keyframes?.length ? { keyframes: opts.keyframes.map(({ image, seconds }) => [image, seconds]) } : {}),
|
|
1231
1265
|
refAudio: opts.refAudio || '',
|
|
1232
1266
|
audioStart: opts.audioStart ?? null,
|
|
1233
1267
|
audioDuration: opts.audioDuration ?? null,
|
|
@@ -2501,6 +2535,46 @@ function miniMaxH3FramesForDuration(durationSeconds) {
|
|
|
2501
2535
|
return Math.max(min, Math.min(max, min + Math.round((desiredFrames - min) / step) * step));
|
|
2502
2536
|
}
|
|
2503
2537
|
|
|
2538
|
+
// MiniMax H3 intermediate keyframes: still images the worker pins at chosen
|
|
2539
|
+
// frames strictly between the first and the last frame (repeatable
|
|
2540
|
+
// --keyframe <image>@<seconds>). They are in addition to --ref/--ref-end, never
|
|
2541
|
+
// a replacement. The image-to-video, first/last-frame, Sound to Video (FastH3
|
|
2542
|
+
// audio guide) and Reference to Video ids take them (isMinimaxH3KeyframeModelId);
|
|
2543
|
+
// text-to-video never does.
|
|
2544
|
+
const MINIMAX_H3_KEYFRAME_MODELS_HINT = 'Keyframes work on the MiniMax H3 image-to-video and first/last-frame models '
|
|
2545
|
+
+ '(minimax-h3-i2v, minimax-h3-flf2v and their -balanced, -turbo, -fasth3 and two-stage forms), '
|
|
2546
|
+
+ 'the FastH3 Sound to Video models (minimax-h3-fasth3-ia2v-turbo, -flfa2v-turbo, -a2v-turbo and their -2stage forms) '
|
|
2547
|
+
+ 'and Reference to Video (minimax-h3-r2v and its -balanced, -turbo and two-stage forms).';
|
|
2548
|
+
|
|
2549
|
+
// A pinned frame's time as an H3 cut-marker clock (MM:SS.mmm), rounded down to
|
|
2550
|
+
// the millisecond so a cut written at it never lands after the keyframe.
|
|
2551
|
+
function formatMiniMaxH3KeyframeClock(frameIndex) {
|
|
2552
|
+
const millis = Math.floor((frameIndex * 1000) / MINIMAX_H3_FRAME_GRID.fps);
|
|
2553
|
+
const minutes = String(Math.floor(millis / 60000)).padStart(2, '0');
|
|
2554
|
+
const seconds = String(Math.floor((millis % 60000) / 1000)).padStart(2, '0');
|
|
2555
|
+
return `${minutes}:${seconds}.${String(millis % 1000).padStart(3, '0')}`;
|
|
2556
|
+
}
|
|
2557
|
+
|
|
2558
|
+
// `--keyframe <image>@<seconds>`: the last "@" separates the time, so a path or
|
|
2559
|
+
// URL that itself contains "@" still parses. A trailing "s" is accepted.
|
|
2560
|
+
function parseKeyframeFlagValue(raw, flag = '--keyframe') {
|
|
2561
|
+
const text = String(raw ?? '').trim();
|
|
2562
|
+
const at = text.lastIndexOf('@');
|
|
2563
|
+
const imagePart = at > 0 ? text.slice(0, at).trim() : '';
|
|
2564
|
+
const timeMatch = at > 0 ? /^(\d+(?:\.\d+)?|\.\d+)s?$/i.exec(text.slice(at + 1).trim()) : null;
|
|
2565
|
+
if (!imagePart || !timeMatch) {
|
|
2566
|
+
fatalCliError(
|
|
2567
|
+
`${flag} takes <image>@<seconds>: the image, then when the video lands on it (got "${text}").`,
|
|
2568
|
+
{
|
|
2569
|
+
code: 'INVALID_ARGUMENT',
|
|
2570
|
+
details: { flag, value: text },
|
|
2571
|
+
hint: `Example: ${flag} ./turn.png@3.5 pins turn.png 3.5 seconds into the clip. Repeat ${flag} for up to ${MINIMAX_H3_MAX_KEYFRAMES} keyframes.`
|
|
2572
|
+
}
|
|
2573
|
+
);
|
|
2574
|
+
}
|
|
2575
|
+
return { image: expandHomePath(imagePart), seconds: Number(timeMatch[1]) };
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2504
2578
|
const LTX23_10EROS_FIXED_SETTINGS = Object.freeze({
|
|
2505
2579
|
steps: 9,
|
|
2506
2580
|
guidance: 1,
|
|
@@ -3077,6 +3151,12 @@ const options = {
|
|
|
3077
3151
|
json: false,
|
|
3078
3152
|
quiet: false,
|
|
3079
3153
|
timeout: 30000,
|
|
3154
|
+
// Stop waiting without cancelling: --detach returns right after submission;
|
|
3155
|
+
// a timeout leaves the project running unless --cancel-on-timeout is set.
|
|
3156
|
+
detach: false,
|
|
3157
|
+
cancelOnTimeout: false,
|
|
3158
|
+
// --status <id> | --result <id> | --recent [hours]
|
|
3159
|
+
projectLookup: null,
|
|
3080
3160
|
strictSize: false,
|
|
3081
3161
|
quality: null, // Quality tier: fast|hq|pro — auto-selects model, steps, dimensions
|
|
3082
3162
|
tokenType: null,
|
|
@@ -3146,6 +3226,7 @@ const options = {
|
|
|
3146
3226
|
angles360Video: null,
|
|
3147
3227
|
refImage: null, // Reference image for video (start frame)
|
|
3148
3228
|
refImageEnd: null, // End frame for video interpolation
|
|
3229
|
+
keyframes: [], // MiniMax H3 intermediate keyframes from repeatable --keyframe <image>@<seconds>: [{ image, seconds, frameIndex }]
|
|
3149
3230
|
refAudio: null, // Uploaded/generated audio for ia2v/a2v, or s2v lip-sync (primary)
|
|
3150
3231
|
refAudios: [], // Additional Seedance loose audio refs; first --ref-audio fills refAudio, subsequent calls append here
|
|
3151
3232
|
audioStart: null, // Optional start offset into reference audio
|
|
@@ -3345,6 +3426,7 @@ const cliSet = {
|
|
|
3345
3426
|
videoModel: false,
|
|
3346
3427
|
refImage: false,
|
|
3347
3428
|
refImageEnd: false,
|
|
3429
|
+
keyframes: false,
|
|
3348
3430
|
refAudio: false,
|
|
3349
3431
|
refAudios: false,
|
|
3350
3432
|
audioStart: false,
|
|
@@ -3713,6 +3795,11 @@ for (let i = 0; i < args.length; i++) {
|
|
|
3713
3795
|
i++;
|
|
3714
3796
|
options.refImageEnd = raw;
|
|
3715
3797
|
cliSet.refImageEnd = true;
|
|
3798
|
+
} else if (arg === '--keyframe') {
|
|
3799
|
+
const raw = requireFlagValue(args, i, arg);
|
|
3800
|
+
i++;
|
|
3801
|
+
options.keyframes.push(parseKeyframeFlagValue(raw, arg));
|
|
3802
|
+
cliSet.keyframes = true;
|
|
3716
3803
|
} else if (arg === '--ref-audio' || arg === '--audio') {
|
|
3717
3804
|
const raw = expandHomePath(requireFlagValue(args, i, arg));
|
|
3718
3805
|
i++;
|
|
@@ -4395,6 +4482,29 @@ for (let i = 0; i < args.length; i++) {
|
|
|
4395
4482
|
options._lastImagePath = lastImagePath;
|
|
4396
4483
|
}
|
|
4397
4484
|
}
|
|
4485
|
+
} else if (arg === '--detach' || arg === '--no-wait') {
|
|
4486
|
+
options.detach = true;
|
|
4487
|
+
} else if (arg === '--cancel-on-timeout') {
|
|
4488
|
+
options.cancelOnTimeout = true;
|
|
4489
|
+
} else if (arg === '--status' || arg === '--result') {
|
|
4490
|
+
const projectId = requireFlagValue(args, i, arg);
|
|
4491
|
+
i++;
|
|
4492
|
+
options.projectLookup = { action: arg.slice(2), projectId };
|
|
4493
|
+
} else if (arg === '--recent') {
|
|
4494
|
+
// Optional look-back in hours: `--recent` or `--recent 6`.
|
|
4495
|
+
const next = args[i + 1];
|
|
4496
|
+
let hours = 24;
|
|
4497
|
+
if (next !== undefined && /^\d+(\.\d+)?$/.test(next)) {
|
|
4498
|
+
hours = Number(next);
|
|
4499
|
+
i++;
|
|
4500
|
+
if (!(hours > 0) || hours > 168) {
|
|
4501
|
+
fatalCliError('--recent hours must be between 0 and 168 (7 days).', {
|
|
4502
|
+
code: 'INVALID_ARGUMENT',
|
|
4503
|
+
details: { flag: '--recent', value: next }
|
|
4504
|
+
});
|
|
4505
|
+
}
|
|
4506
|
+
}
|
|
4507
|
+
options.projectLookup = { action: 'recent', hours };
|
|
4398
4508
|
} else if (arg === '--last') {
|
|
4399
4509
|
// Show last render info. Use CLI_WANTS_JSON (precomputed from raw argv)
|
|
4400
4510
|
// because --json may appear after --last in the argument list.
|
|
@@ -4556,6 +4666,11 @@ Video Options:
|
|
|
4556
4666
|
--ref-end <path|url> End frame for interpolation/morphing; with --ref it
|
|
4557
4667
|
defaults to the LTX-2.5 i2v first/last-frame workflow
|
|
4558
4668
|
(last frame on Seedance; L2VA endpoint on MiniMax H3 i2v)
|
|
4669
|
+
--keyframe <image>@<sec> MiniMax H3 only: pin an image (path or URL) at that time inside the clip,
|
|
4670
|
+
in addition to --ref/--ref-end. Repeatable, up to 8, strictly between the
|
|
4671
|
+
first and last frame. H3 i2v/flf2v, FastH3 Sound to Video and Ref2VA models.
|
|
4672
|
+
Describe what each keyframe shows in the prompt at its time. Two keyframes
|
|
4673
|
+
are included in the price; each extra one adds a little.
|
|
4559
4674
|
--ref-audio <path|url> Audio reference. Repeatable on Seedance and H3 r2v (up to 3 total);
|
|
4560
4675
|
first entry is the primary, extras must be HTTPS URLs in CLI
|
|
4561
4676
|
direct-gen for Seedance; H3 r2v uploads local/remote files.
|
|
@@ -4652,7 +4767,18 @@ Hosted API Modes:
|
|
|
4652
4767
|
--api-base-url <url> Sogni API base URL (default: ${DEFAULT_API_BASE_URL})
|
|
4653
4768
|
|
|
4654
4769
|
General:
|
|
4655
|
-
-t, --timeout <sec>
|
|
4770
|
+
-t, --timeout <sec> Stop waiting after this many seconds (default: 30, video: 1800, music: 600).
|
|
4771
|
+
Counted from submission; time the account's own plan concurrency limit
|
|
4772
|
+
holds the project is not counted. The project is NOT cancelled; fetch it
|
|
4773
|
+
later with --result
|
|
4774
|
+
--cancel-on-timeout Cancel the project when --timeout runs out (the pre-3.53 behavior)
|
|
4775
|
+
--detach, --no-wait Submit, print the project id, and exit without waiting. The project keeps
|
|
4776
|
+
running; use --status / --result to follow it
|
|
4777
|
+
--status <projectId> Show a project's state and, while queued, why it is waiting
|
|
4778
|
+
--result <projectId> Fetch a finished project's media (saved to -o when given), including one
|
|
4779
|
+
that finished after an earlier run stopped waiting
|
|
4780
|
+
--recent [hours] List this account's completed projects from the last N hours
|
|
4781
|
+
(default 24, max 168); fetch one with --result
|
|
4656
4782
|
--steps <num> Override steps (model-dependent)
|
|
4657
4783
|
--guidance <num> Override guidance (model-dependent)
|
|
4658
4784
|
--token-type <type> Token type: spark|sogni|auto (default: spark, auto retries with alternate)
|
|
@@ -4926,6 +5052,7 @@ let fpsFromConfig = false;
|
|
|
4926
5052
|
let widthFromPrompt = false;
|
|
4927
5053
|
let heightFromPrompt = false;
|
|
4928
5054
|
let targetResolutionFromPrompt = false;
|
|
5055
|
+
let exactPixelsFromPrompt = false;
|
|
4929
5056
|
let durationFromPrompt = false;
|
|
4930
5057
|
let aspectRatioFromPrompt = null;
|
|
4931
5058
|
let configuredDefaultVideoWorkflow = null;
|
|
@@ -6079,10 +6206,28 @@ const wan3HasMediaInput = isWan3ModelLocal(options.model) && Boolean(
|
|
|
6079
6206
|
|| options.wan3ReferenceFileUrl
|
|
6080
6207
|
|| options.wan3ReferenceLinkUrl
|
|
6081
6208
|
);
|
|
6082
|
-
if (!options.prompt && !wan3HasMediaInput && !options.segmentImage && !options.imageTo3d && !options.removeBackground && !options.upscaleImage && !options.upscaleVideo && !options.apiChat && !apiWorkflowUtilityAction && !apiWorkflowStartAction && !apiModelUtilityAction && !liveModelUtilityAction && !loraCatalogUtilityAction && !apiReplayUtilityAction && !contractUtilityAction && !storyboardPlanUtilityAction && !options.estimateVideoCost && !options.multiAngle && !options.showBalance && !options.showVersion && !options.doctor && !options.extractLastFrame && !options.extractFirstFrame && !options.extractFrameAt && !options.trimVideo && !options.verifyVideo && !options.concatVideos && !options.sourceReelDir && !options.remixAudio && !options.listMedia && !options.memoryAction && !options.personalityAction && !personaUtilityAction) {
|
|
6209
|
+
if (!options.prompt && !options.projectLookup && !wan3HasMediaInput && !options.segmentImage && !options.imageTo3d && !options.removeBackground && !options.upscaleImage && !options.upscaleVideo && !options.apiChat && !apiWorkflowUtilityAction && !apiWorkflowStartAction && !apiModelUtilityAction && !liveModelUtilityAction && !loraCatalogUtilityAction && !apiReplayUtilityAction && !contractUtilityAction && !storyboardPlanUtilityAction && !options.estimateVideoCost && !options.multiAngle && !options.showBalance && !options.showVersion && !options.doctor && !options.extractLastFrame && !options.extractFirstFrame && !options.extractFrameAt && !options.trimVideo && !options.verifyVideo && !options.concatVideos && !options.sourceReelDir && !options.remixAudio && !options.listMedia && !options.memoryAction && !options.personalityAction && !personaUtilityAction) {
|
|
6083
6210
|
fatalCliError('No prompt provided. Use --help for usage.', { code: 'INVALID_ARGUMENT' });
|
|
6084
6211
|
}
|
|
6085
6212
|
|
|
6213
|
+
// --detach returns after the first submission, so it only fits a run that
|
|
6214
|
+
// submits one project up front; these flows submit more after the first ends.
|
|
6215
|
+
if (options.detach) {
|
|
6216
|
+
const multiStage = [
|
|
6217
|
+
['--looping', options.looping],
|
|
6218
|
+
['--multi-angle', options.multiAngle],
|
|
6219
|
+
['--source-reel', options.sourceReelDir],
|
|
6220
|
+
['--api-chat', options.apiChat],
|
|
6221
|
+
['hosted workflows', options.apiWorkflowAction]
|
|
6222
|
+
].find(([, enabled]) => enabled);
|
|
6223
|
+
if (multiStage) {
|
|
6224
|
+
fatalCliError(`--detach cannot be combined with ${multiStage[0]}, which submits more than one project in sequence.`, {
|
|
6225
|
+
code: 'INVALID_ARGUMENT',
|
|
6226
|
+
details: { flag: '--detach', conflictsWith: multiStage[0] }
|
|
6227
|
+
});
|
|
6228
|
+
}
|
|
6229
|
+
}
|
|
6230
|
+
|
|
6086
6231
|
if (contractUtilityAction && options.contractAction === 'dispatch' && !options.contractToolName) {
|
|
6087
6232
|
fatalCliError('--dispatch-tool requires a tool name.', { code: 'INVALID_ARGUMENT' });
|
|
6088
6233
|
}
|
|
@@ -6320,6 +6465,24 @@ if (options.video) {
|
|
|
6320
6465
|
details: { targetResolution: options.targetResolution }
|
|
6321
6466
|
});
|
|
6322
6467
|
}
|
|
6468
|
+
// Wan 2.2 renders at most 1,048,576 pixels per frame (1024x1024), so its
|
|
6469
|
+
// short side can never exceed 1024: 1080p, 1440p and 4K cannot fit. Refuse the
|
|
6470
|
+
// named resolution instead of rendering it smaller without saying so.
|
|
6471
|
+
if (
|
|
6472
|
+
isWanVideoModelId(options.model) &&
|
|
6473
|
+
(cliSet.targetResolution || targetResolutionFromPrompt) &&
|
|
6474
|
+
Number(options.targetResolution) > 1024
|
|
6475
|
+
) {
|
|
6476
|
+
fatalCliError(
|
|
6477
|
+
`Wan 2.2 cannot render ${options.targetResolution}p. It renders at most 1,048,576 pixels per frame (1024×1024), ` +
|
|
6478
|
+
'so its short side is at most 1024 pixels.',
|
|
6479
|
+
{
|
|
6480
|
+
code: 'INVALID_ARGUMENT',
|
|
6481
|
+
details: { model: options.model, targetResolution: options.targetResolution, maxPixels: WAN22_MAX_VIDEO_PIXELS },
|
|
6482
|
+
hint: `Use --target-resolution 720 (or 768), -w 1024 -h 1024, or -m ltx25 for ${options.targetResolution}p.`
|
|
6483
|
+
}
|
|
6484
|
+
);
|
|
6485
|
+
}
|
|
6323
6486
|
if (isWan3Video && cliSet.targetResolution && !WAN3_SUPPORTED_RESOLUTIONS.has(options.targetResolution)) {
|
|
6324
6487
|
fatalCliError('Wan 3 --target-resolution must be 480, 720, or 1080.', {
|
|
6325
6488
|
code: 'INVALID_ARGUMENT',
|
|
@@ -6926,6 +7089,112 @@ if (options.video && !options.frames) {
|
|
|
6926
7089
|
options.fps = h3Fps;
|
|
6927
7090
|
}
|
|
6928
7091
|
|
|
7092
|
+
// MiniMax H3 intermediate keyframes (--keyframe <image>@<seconds>), checked once
|
|
7093
|
+
// the model and the frame count are final so every error names the clip it was
|
|
7094
|
+
// checked against. Direct renders pin each time to a frame of the job's 24fps
|
|
7095
|
+
// grid; hosted chat uploads the images for the agent to pin, and the hosted
|
|
7096
|
+
// tool checks the times against the length it picks. Nothing is clamped or dropped.
|
|
7097
|
+
function validateMiniMaxH3KeyframeOptions() {
|
|
7098
|
+
const keyframes = options.keyframes;
|
|
7099
|
+
if (keyframes.length === 0) return;
|
|
7100
|
+
const fail = (message, details = {}, hint = undefined) => fatalCliError(message, {
|
|
7101
|
+
code: 'INVALID_ARGUMENT',
|
|
7102
|
+
details: { flag: '--keyframe', ...details },
|
|
7103
|
+
...(hint ? { hint } : {})
|
|
7104
|
+
});
|
|
7105
|
+
if (options.apiWorkflowAction) {
|
|
7106
|
+
fail(
|
|
7107
|
+
'--keyframe does not apply to --api-workflow. Put keyframes: [{ "imageIndex": -1, "atSeconds": 3.5 }] in the '
|
|
7108
|
+
+ 'animate_photo, sound_to_video or generate_video step arguments of --workflow-input, and attach the images with -c/--context.',
|
|
7109
|
+
{ apiWorkflow: true }
|
|
7110
|
+
);
|
|
7111
|
+
}
|
|
7112
|
+
if (!options.apiChat && !options.video) {
|
|
7113
|
+
fail('--keyframe requires --video with a MiniMax H3 model (or --api-chat / --durable-chat).');
|
|
7114
|
+
}
|
|
7115
|
+
const conflict = [
|
|
7116
|
+
['--looping', options.looping],
|
|
7117
|
+
['--angles-360-video', options.angles360Video],
|
|
7118
|
+
['--source-reel', options.sourceReelDir],
|
|
7119
|
+
['--multi-angle', options.multiAngle]
|
|
7120
|
+
].find(([, enabled]) => enabled);
|
|
7121
|
+
if (conflict) {
|
|
7122
|
+
fail(`--keyframe cannot be combined with ${conflict[0]}, which renders more than one clip.`, { conflictsWith: conflict[0] });
|
|
7123
|
+
}
|
|
7124
|
+
if (keyframes.length > MINIMAX_H3_MAX_KEYFRAMES) {
|
|
7125
|
+
fail(
|
|
7126
|
+
`MiniMax H3 pins at most ${MINIMAX_H3_MAX_KEYFRAMES} keyframes (got ${keyframes.length}).`,
|
|
7127
|
+
{ count: keyframes.length, maximum: MINIMAX_H3_MAX_KEYFRAMES }
|
|
7128
|
+
);
|
|
7129
|
+
}
|
|
7130
|
+
for (const keyframe of keyframes) {
|
|
7131
|
+
if (!isHttpUrl(keyframe.image) && !existsSync(keyframe.image)) {
|
|
7132
|
+
fatalCliError(`Keyframe image not found: ${keyframe.image}`, {
|
|
7133
|
+
code: 'MISSING_FILE',
|
|
7134
|
+
details: { flag: '--keyframe', path: keyframe.image, seconds: keyframe.seconds },
|
|
7135
|
+
hint: 'Check the path, or pass an http(s) URL.'
|
|
7136
|
+
});
|
|
7137
|
+
}
|
|
7138
|
+
}
|
|
7139
|
+
|
|
7140
|
+
// Direct renders know the model and the frame count the job renders (a Sound
|
|
7141
|
+
// to Video window is always the clip length). Hosted chat does not: the agent
|
|
7142
|
+
// picks both, so only what holds for every H3 clip is checked here.
|
|
7143
|
+
let frames;
|
|
7144
|
+
let edgeHint;
|
|
7145
|
+
if (!options.apiChat) {
|
|
7146
|
+
if (!isMinimaxH3KeyframeModelId(options.model)) {
|
|
7147
|
+
const textToVideo = isMiniMaxH3Model(options.model);
|
|
7148
|
+
fail(
|
|
7149
|
+
textToVideo
|
|
7150
|
+
? `${options.model} is MiniMax H3 text-to-video, which cannot pin keyframes. Add --ref (or --ref-end) for image-to-video, or pick a Sound to Video or Reference to Video model.`
|
|
7151
|
+
: `--keyframe is MiniMax H3 only; ${options.model} does not take keyframes.`,
|
|
7152
|
+
{ model: options.model },
|
|
7153
|
+
MINIMAX_H3_KEYFRAME_MODELS_HINT
|
|
7154
|
+
);
|
|
7155
|
+
}
|
|
7156
|
+
frames = options.frames;
|
|
7157
|
+
edgeHint = {
|
|
7158
|
+
i2v: 'the first and last frames come from --ref and --ref-end',
|
|
7159
|
+
flf2v: 'the first and last frames come from --ref and --ref-end',
|
|
7160
|
+
flfa2v: 'the first and last frames come from --ref and --ref-end',
|
|
7161
|
+
ia2v: 'the first frame comes from --ref, and the last frame cannot be pinned',
|
|
7162
|
+
a2v: 'audio-only clips cannot pin their first or last frame',
|
|
7163
|
+
r2v: 'reference-to-video cannot pin its first or last frame'
|
|
7164
|
+
}[miniMaxH3ModeFromModelId(options.model)];
|
|
7165
|
+
}
|
|
7166
|
+
|
|
7167
|
+
// The shared check names entries by position; the CLI names them by the
|
|
7168
|
+
// order the --keyframe flags were given.
|
|
7169
|
+
const check = checkMinimaxH3Keyframes(
|
|
7170
|
+
keyframes.map(({ seconds }, index) => ({ imageIndex: index, atSeconds: seconds })),
|
|
7171
|
+
{
|
|
7172
|
+
...(frames ? {
|
|
7173
|
+
frames,
|
|
7174
|
+
framesSource: cliSet.frames ? `--frames ${frames}` : `--duration ${options.duration} renders ${frames} frames`,
|
|
7175
|
+
suggestDuration: true
|
|
7176
|
+
} : {}),
|
|
7177
|
+
...(edgeHint ? { edgeHint } : {})
|
|
7178
|
+
}
|
|
7179
|
+
);
|
|
7180
|
+
if (!check.ok) {
|
|
7181
|
+
const message = check.errors
|
|
7182
|
+
.map((error) => error
|
|
7183
|
+
.replace(/keyframes\[(\d+)\]/g, (_match, index) => `keyframe ${Number(index) + 1} (${keyframes[Number(index)].image})`)
|
|
7184
|
+
.replace('or set duration to', 'or set --duration to'))
|
|
7185
|
+
.map((error) => `${error.charAt(0).toUpperCase()}${error.slice(1)}`)
|
|
7186
|
+
.join(' ');
|
|
7187
|
+
fail(message, {
|
|
7188
|
+
keyframes: keyframes.map(({ image, seconds }) => ({ image, seconds })),
|
|
7189
|
+
...(frames ? { frames } : {})
|
|
7190
|
+
});
|
|
7191
|
+
}
|
|
7192
|
+
// Time order is the order the keyframes are uploaded, pinned and described in.
|
|
7193
|
+
options.keyframes = check.keyframes.map(({ imageIndex, frameIndex }) => ({ ...keyframes[imageIndex], frameIndex }));
|
|
7194
|
+
}
|
|
7195
|
+
|
|
7196
|
+
validateMiniMaxH3KeyframeOptions();
|
|
7197
|
+
|
|
6929
7198
|
// Video dimensions:
|
|
6930
7199
|
// - Sogni video pipelines have model-specific min/max dimensions and divisors.
|
|
6931
7200
|
// - When using i2v (or any ref-based workflow), the Sogni client wrapper will *resize the reference image*
|
|
@@ -7015,6 +7284,26 @@ if (options.video) {
|
|
|
7015
7284
|
const originalVideoWidth = options.width;
|
|
7016
7285
|
const originalVideoHeight = options.height;
|
|
7017
7286
|
const normalizedVideoDims = normalizeVideoDimensionsLikeWrapper(options.width, options.height, videoDimensionRules);
|
|
7287
|
+
// Wan 2.2 renders at most 1,048,576 pixels per frame, with each side between
|
|
7288
|
+
// 480 and 1536. Since 2026-09-26 the network scales a larger request down to
|
|
7289
|
+
// about 1 MP (a side below 480 is still refused, error 4101). A size the user
|
|
7290
|
+
// asked for (-w/-h or exact pixels in the prompt) is refused here instead of
|
|
7291
|
+
// being shrunk without asking; sizes the CLI chooses itself are fitted by the
|
|
7292
|
+
// rules above.
|
|
7293
|
+
if (isWanVideoModelId(options.model) && (cliSet.width || cliSet.height || exactPixelsFromPrompt)) {
|
|
7294
|
+
const refusal = getWan22VideoSizeRefusal(originalVideoWidth, originalVideoHeight);
|
|
7295
|
+
if (refusal) {
|
|
7296
|
+
fatalCliError(refusal, {
|
|
7297
|
+
code: 'INVALID_VIDEO_SIZE',
|
|
7298
|
+
details: {
|
|
7299
|
+
model: options.model,
|
|
7300
|
+
requested: { width: originalVideoWidth, height: originalVideoHeight },
|
|
7301
|
+
maxPixels: WAN22_MAX_VIDEO_PIXELS
|
|
7302
|
+
},
|
|
7303
|
+
hint: `Try: --width ${normalizedVideoDims.width} --height ${normalizedVideoDims.height}, or -m ltx25 for a larger size.`
|
|
7304
|
+
});
|
|
7305
|
+
}
|
|
7306
|
+
}
|
|
7018
7307
|
options.width = normalizedVideoDims.width;
|
|
7019
7308
|
options.height = normalizedVideoDims.height;
|
|
7020
7309
|
if (isMiniMaxH3Model(options.model) && options.width * options.height > 1344 * 768) {
|
|
@@ -7634,6 +7923,16 @@ function getApiModeMediaReferences() {
|
|
|
7634
7923
|
}
|
|
7635
7924
|
if (options.refImage) refs.push({ flag: '--ref', value: options.refImage, kind: 'image' });
|
|
7636
7925
|
if (options.refImageEnd) refs.push({ flag: '--ref-end', value: options.refImageEnd, kind: 'image' });
|
|
7926
|
+
// MiniMax H3 keyframes follow the frame images, in time order, so the hosted
|
|
7927
|
+
// agent can pin each one by its upload index (-1 is the first image upload).
|
|
7928
|
+
for (const [index, keyframe] of options.keyframes.entries()) {
|
|
7929
|
+
refs.push({
|
|
7930
|
+
flag: '--keyframe',
|
|
7931
|
+
value: keyframe.image,
|
|
7932
|
+
kind: 'image',
|
|
7933
|
+
keyframe: { slot: index + 1, seconds: keyframe.seconds, frameIndex: keyframe.frameIndex }
|
|
7934
|
+
});
|
|
7935
|
+
}
|
|
7637
7936
|
if (options.refAudio) refs.push({ flag: '--ref-audio', value: options.refAudio, kind: 'audio' });
|
|
7638
7937
|
for (const value of options.refAudios || []) {
|
|
7639
7938
|
if (value) refs.push({ flag: '--ref-audio', value, kind: 'audio' });
|
|
@@ -7711,6 +8010,7 @@ function apiMediaReferenceUploadType(ref, index) {
|
|
|
7711
8010
|
if (ref.kind === 'audio') return 'referenceAudio';
|
|
7712
8011
|
if (ref.kind === 'video') return 'referenceVideo';
|
|
7713
8012
|
if (ref.flag === '--ref-end') return 'referenceImageEnd';
|
|
8013
|
+
if (ref.flag === '--keyframe') return `keyframeImage${ref.keyframe.slot}`;
|
|
7714
8014
|
if (ref.flag === '--mask') return `contextImage${Math.min(index + 1, 16)}`;
|
|
7715
8015
|
if (ref.flag === '-c/--context') return `contextImage${Math.min(index + 1, 16)}`;
|
|
7716
8016
|
return 'referenceImage';
|
|
@@ -7981,6 +8281,29 @@ function formatApiMediaReferencesForPrompt(mediaReferences) {
|
|
|
7981
8281
|
return `API media references:\n${lines.join('\n')}`;
|
|
7982
8282
|
}
|
|
7983
8283
|
|
|
8284
|
+
// The --keyframe request in the hosted tools' own terms. Negative imageIndex
|
|
8285
|
+
// counts image uploads only, in media_references order (-1 is the first), so
|
|
8286
|
+
// each keyframe is named by its position among the image references.
|
|
8287
|
+
function formatApiKeyframePlanForPrompt(imageRefs) {
|
|
8288
|
+
const keyframes = imageRefs
|
|
8289
|
+
.map((ref, position) => (ref.keyframe ? { ref, imageIndex: -(position + 1) } : null))
|
|
8290
|
+
.filter(Boolean);
|
|
8291
|
+
if (keyframes.length === 0) return '';
|
|
8292
|
+
const argument = JSON.stringify(keyframes.map(({ ref, imageIndex }) => ({
|
|
8293
|
+
imageIndex,
|
|
8294
|
+
atSeconds: ref.keyframe.seconds
|
|
8295
|
+
})));
|
|
8296
|
+
const clocks = keyframes
|
|
8297
|
+
.map(({ ref }) => formatMiniMaxH3KeyframeClock(ref.keyframe.frameIndex ?? minimaxH3KeyframeFrameIndex(ref.keyframe.seconds)))
|
|
8298
|
+
.join(', ');
|
|
8299
|
+
return [
|
|
8300
|
+
'MiniMax H3 keyframes: pin these uploaded images inside the video, in addition to any first or last frame, '
|
|
8301
|
+
+ `with the keyframes argument ${argument}.`,
|
|
8302
|
+
'Use a MiniMax H3 image-to-video, first/last-frame, Sound to Video or Reference to Video model, keep the clip '
|
|
8303
|
+
+ `longer than the last keyframe, and describe in the video prompt what each keyframe shows at its time (${clocks}).`
|
|
8304
|
+
].join('\n');
|
|
8305
|
+
}
|
|
8306
|
+
|
|
7984
8307
|
function extractApiEnvelopeData(payload) {
|
|
7985
8308
|
return payload?.data && typeof payload.data === 'object' ? payload.data : payload;
|
|
7986
8309
|
}
|
|
@@ -8131,7 +8454,8 @@ async function buildApiChatMessages(apiMediaRefs, apiMediaReferences) {
|
|
|
8131
8454
|
const nonImageRefs = apiMediaReferences.filter(ref => ref.kind !== 'image');
|
|
8132
8455
|
const promptText = [
|
|
8133
8456
|
options.prompt || 'Describe the attached media.',
|
|
8134
|
-
formatApiMediaReferencesForPrompt(nonImageRefs)
|
|
8457
|
+
formatApiMediaReferencesForPrompt(nonImageRefs),
|
|
8458
|
+
formatApiKeyframePlanForPrompt(imageRefs)
|
|
8135
8459
|
].filter(Boolean).join('\n\n');
|
|
8136
8460
|
|
|
8137
8461
|
const messages = [{ role: 'system', content: system }];
|
|
@@ -11448,7 +11772,7 @@ function roundToMultiple(value, multiple) {
|
|
|
11448
11772
|
return Math.max(multiple, Math.round(value / multiple) * multiple);
|
|
11449
11773
|
}
|
|
11450
11774
|
|
|
11451
|
-
function inferSourceReelDimensions(metadata, targetShortSide) {
|
|
11775
|
+
function inferSourceReelDimensions(metadata, targetShortSide, model = SOURCE_REEL_DEFAULT_MODEL) {
|
|
11452
11776
|
const rawWidth = Number(metadata?.width) || targetShortSide;
|
|
11453
11777
|
const rawHeight = Number(metadata?.height) || targetShortSide;
|
|
11454
11778
|
const aspect = rawWidth > 0 && rawHeight > 0 ? rawWidth / rawHeight : 1;
|
|
@@ -11475,10 +11799,16 @@ function inferSourceReelDimensions(metadata, targetShortSide) {
|
|
|
11475
11799
|
height *= scale;
|
|
11476
11800
|
}
|
|
11477
11801
|
|
|
11478
|
-
|
|
11479
|
-
|
|
11480
|
-
|
|
11481
|
-
|
|
11802
|
+
let roundedWidth = roundToMultiple(width, 16);
|
|
11803
|
+
let roundedHeight = roundToMultiple(height, 16);
|
|
11804
|
+
// Wan 2.2 (the default reel model) renders at most 1,048,576 pixels per
|
|
11805
|
+
// frame, so a size chosen for it is fitted inside that budget.
|
|
11806
|
+
if (isWanVideoModelId(model) && roundedWidth * roundedHeight > WAN22_MAX_VIDEO_PIXELS) {
|
|
11807
|
+
const scale = Math.sqrt(WAN22_MAX_VIDEO_PIXELS / (roundedWidth * roundedHeight));
|
|
11808
|
+
roundedWidth = Math.max(480, Math.floor((roundedWidth * scale) / 16) * 16);
|
|
11809
|
+
roundedHeight = Math.max(480, Math.floor((roundedHeight * scale) / 16) * 16);
|
|
11810
|
+
}
|
|
11811
|
+
return { width: roundedWidth, height: roundedHeight };
|
|
11482
11812
|
}
|
|
11483
11813
|
|
|
11484
11814
|
function uniqueSourceReelWorkdir(sourceDir) {
|
|
@@ -11589,6 +11919,18 @@ function buildSourceReelPlan() {
|
|
|
11589
11919
|
const transitionBasePrompt = options.sourceReelTransitionPrompt || SOURCE_REEL_DEFAULT_TRANSITION_PROMPT;
|
|
11590
11920
|
const promptOverrides = loadSourceReelTransitionPromptOverrides(options.sourceReelTransitionPrompts);
|
|
11591
11921
|
const model = options.sourceReelModel || (cliSet.model ? options.model : null) || SOURCE_REEL_DEFAULT_MODEL;
|
|
11922
|
+
// Wan 2.2's short side can never exceed 1024 inside its 1,048,576-pixel budget.
|
|
11923
|
+
if (isWanVideoModelId(model) && Number(options.sourceReelTargetResolution) > 1024) {
|
|
11924
|
+
fatalCliError(
|
|
11925
|
+
`Wan 2.2 cannot render ${options.sourceReelTargetResolution}p. It renders at most 1,048,576 pixels per frame ` +
|
|
11926
|
+
'(1024×1024), so its short side is at most 1024 pixels.',
|
|
11927
|
+
{
|
|
11928
|
+
code: 'INVALID_ARGUMENT',
|
|
11929
|
+
details: { model, sourceReelTargetResolution: options.sourceReelTargetResolution, maxPixels: WAN22_MAX_VIDEO_PIXELS },
|
|
11930
|
+
hint: 'Use --reel-target-resolution 768 (the default) or pick another --reel-model.'
|
|
11931
|
+
}
|
|
11932
|
+
);
|
|
11933
|
+
}
|
|
11592
11934
|
const fps = cliSet.fps ? options.fps : 32;
|
|
11593
11935
|
const concurrency = options.sourceReelConcurrency || 2;
|
|
11594
11936
|
|
|
@@ -11690,7 +12032,7 @@ async function prepareSourceReelReferenceImages(plan, log) {
|
|
|
11690
12032
|
let dimensions = plan.dimensions;
|
|
11691
12033
|
if (!dimensions) {
|
|
11692
12034
|
const metadata = await sharp(plan.clips[0].path).rotate().metadata();
|
|
11693
|
-
dimensions = inferSourceReelDimensions(metadata, plan.targetResolution);
|
|
12035
|
+
dimensions = inferSourceReelDimensions(metadata, plan.targetResolution, plan.model);
|
|
11694
12036
|
plan.dimensions = dimensions;
|
|
11695
12037
|
}
|
|
11696
12038
|
|
|
@@ -11929,13 +12271,373 @@ async function runSourceReel(log) {
|
|
|
11929
12271
|
}
|
|
11930
12272
|
}
|
|
11931
12273
|
|
|
12274
|
+
// Reasons the server gives for queued work that is held by the account's own
|
|
12275
|
+
// plan (or payment tier) concurrency limit, not by a shortage of workers.
|
|
12276
|
+
const PLAN_LIMIT_WAITING_REASONS = new Set(['concurrency_limit', 'model_concurrency_limit']);
|
|
12277
|
+
|
|
12278
|
+
/** The @sogni-ai/sogni-client instance behind the intelligence-client wrapper. */
|
|
12279
|
+
function sdkClientOf(wrapper) {
|
|
12280
|
+
return wrapper?.client || null;
|
|
12281
|
+
}
|
|
12282
|
+
|
|
12283
|
+
/** Which plan or payment tier a concurrency limit belongs to (same wording as sogni-web). */
|
|
12284
|
+
function waitingLimitScope(waitingReason) {
|
|
12285
|
+
if (waitingReason.paymentModel === 'subscription' || waitingReason.reason === 'model_concurrency_limit') {
|
|
12286
|
+
if (waitingReason.subscriptionTier === 'unlimited_pro') return 'Unlimited Pro plan';
|
|
12287
|
+
if (waitingReason.subscriptionTier === 'unlimited') return 'Unlimited plan';
|
|
12288
|
+
return 'plan';
|
|
12289
|
+
}
|
|
12290
|
+
if (waitingReason.paymentModel === 'paid_spark') return 'Premium Spark';
|
|
12291
|
+
if (waitingReason.paymentModel === 'free_spark') return 'Free Spark';
|
|
12292
|
+
return 'account';
|
|
12293
|
+
}
|
|
12294
|
+
|
|
12295
|
+
/**
|
|
12296
|
+
* Why a project is waiting, as one line for the agent and its user. Mirrors
|
|
12297
|
+
* sogni-web: a plan limit is named as the account's own limit (the project
|
|
12298
|
+
* starts by itself when one of the account's running jobs finishes), never as
|
|
12299
|
+
* a shortage of workers. Returns null for no reason.
|
|
12300
|
+
*/
|
|
12301
|
+
function describeWaitingReason(waitingReason) {
|
|
12302
|
+
if (!waitingReason || typeof waitingReason !== 'object') return null;
|
|
12303
|
+
switch (waitingReason.reason) {
|
|
12304
|
+
case 'concurrency_limit':
|
|
12305
|
+
case 'model_concurrency_limit': {
|
|
12306
|
+
const modelLimit = waitingReason.reason === 'model_concurrency_limit';
|
|
12307
|
+
const media = modelLimit
|
|
12308
|
+
? (waitingReason.modelFamily === 'minimax_h3' ? 'MiniMax H3 videos' : 'videos using this model')
|
|
12309
|
+
: (waitingReason.mediaType === 'video' ? 'videos' : 'generations');
|
|
12310
|
+
return `Queued: you've reached your ${waitingLimitScope(waitingReason)} limit for simultaneous ${media}. ` +
|
|
12311
|
+
'It will start automatically when one of your running jobs finishes. This is your plan\'s limit, ' +
|
|
12312
|
+
'not a shortage of workers, so do not resubmit it.';
|
|
12313
|
+
}
|
|
12314
|
+
case 'payment_pending':
|
|
12315
|
+
return 'Confirming payment before this project can start.';
|
|
12316
|
+
case 'no_workers':
|
|
12317
|
+
return 'Waiting for an available worker to take this project.';
|
|
12318
|
+
case 'queued':
|
|
12319
|
+
return typeof waitingReason.message === 'string' && waitingReason.message ? `Queued: ${waitingReason.message}` : 'Queued.';
|
|
12320
|
+
default:
|
|
12321
|
+
return typeof waitingReason.message === 'string' && waitingReason.message ? waitingReason.message : null;
|
|
12322
|
+
}
|
|
12323
|
+
}
|
|
12324
|
+
|
|
12325
|
+
function isPlanLimitWait(waitingReason) {
|
|
12326
|
+
return PLAN_LIMIT_WAITING_REASONS.has(waitingReason?.reason);
|
|
12327
|
+
}
|
|
12328
|
+
|
|
12329
|
+
/** The shell command that fetches a project's results later. */
|
|
12330
|
+
function resultCommandFor(projectId) {
|
|
12331
|
+
return `sogni-agent --result ${projectId}`;
|
|
12332
|
+
}
|
|
12333
|
+
|
|
12334
|
+
/**
|
|
12335
|
+
* Wait bookkeeping for one run's projects. It announces each project id as
|
|
12336
|
+
* soon as the project is submitted, reports why a project is queued in the
|
|
12337
|
+
* server's own terms, and runs the --timeout clock only for time that is the
|
|
12338
|
+
* run's to count: from submission (uploads excluded), minus any time the
|
|
12339
|
+
* account's own plan concurrency limit held a project, since such a project
|
|
12340
|
+
* starts by itself when one of the account's running jobs finishes. A guard
|
|
12341
|
+
* still ends a run whose submission never completes.
|
|
12342
|
+
*/
|
|
12343
|
+
function createProjectWaitTracker(client, log, timeoutMs = options.timeout) {
|
|
12344
|
+
const projects = new Map();
|
|
12345
|
+
const reasons = new Map();
|
|
12346
|
+
const described = new Map();
|
|
12347
|
+
const sdkProjects = sdkClientOf(client)?.projects;
|
|
12348
|
+
let onTimeout = () => {};
|
|
12349
|
+
let timer = null;
|
|
12350
|
+
let stopped = false;
|
|
12351
|
+
let startedAt = null;
|
|
12352
|
+
let heldMs = 0;
|
|
12353
|
+
let heldSince = null;
|
|
12354
|
+
|
|
12355
|
+
const reasonFor = (projectId) => reasons.get(projectId) ?? projects.get(projectId)?.waitingReason ?? null;
|
|
12356
|
+
const updateHold = () => {
|
|
12357
|
+
const now = Date.now();
|
|
12358
|
+
const held = [...projects.keys()].some((projectId) => isPlanLimitWait(reasonFor(projectId)));
|
|
12359
|
+
if (held && heldSince === null) heldSince = now;
|
|
12360
|
+
if (!held && heldSince !== null) {
|
|
12361
|
+
heldMs += now - heldSince;
|
|
12362
|
+
heldSince = null;
|
|
12363
|
+
}
|
|
12364
|
+
};
|
|
12365
|
+
const countedMs = () => {
|
|
12366
|
+
const now = Date.now();
|
|
12367
|
+
return now - startedAt - heldMs - (heldSince === null ? 0 : now - heldSince);
|
|
12368
|
+
};
|
|
12369
|
+
const cleanup = () => {
|
|
12370
|
+
clearTimeout(timer);
|
|
12371
|
+
if (typeof sdkProjects?.off === 'function') sdkProjects.off('queueChanged', onQueueChanged);
|
|
12372
|
+
};
|
|
12373
|
+
const schedule = (ms) => {
|
|
12374
|
+
clearTimeout(timer);
|
|
12375
|
+
timer = setTimeout(fire, Math.max(0, ms));
|
|
12376
|
+
};
|
|
12377
|
+
function fire() {
|
|
12378
|
+
if (stopped) return;
|
|
12379
|
+
if (startedAt !== null) {
|
|
12380
|
+
updateHold();
|
|
12381
|
+
const remaining = timeoutMs - countedMs();
|
|
12382
|
+
if (remaining > 0) {
|
|
12383
|
+
schedule(remaining);
|
|
12384
|
+
return;
|
|
12385
|
+
}
|
|
12386
|
+
}
|
|
12387
|
+
stopped = true;
|
|
12388
|
+
cleanup();
|
|
12389
|
+
onTimeout();
|
|
12390
|
+
}
|
|
12391
|
+
const report = (projectId) => {
|
|
12392
|
+
const text = describeWaitingReason(reasonFor(projectId));
|
|
12393
|
+
if (!text || described.get(projectId) === text) return;
|
|
12394
|
+
described.set(projectId, text);
|
|
12395
|
+
log(text);
|
|
12396
|
+
};
|
|
12397
|
+
function onQueueChanged(event) {
|
|
12398
|
+
if (!event?.projectId || !projects.has(event.projectId)) return;
|
|
12399
|
+
reasons.set(event.projectId, event.waitingReason ?? null);
|
|
12400
|
+
updateHold();
|
|
12401
|
+
report(event.projectId);
|
|
12402
|
+
}
|
|
12403
|
+
if (typeof sdkProjects?.on === 'function') sdkProjects.on('queueChanged', onQueueChanged);
|
|
12404
|
+
// Submission guard: uploads can be slow, but a run that never gets a project
|
|
12405
|
+
// submitted still ends.
|
|
12406
|
+
schedule(Math.max(timeoutMs, 30 * 60 * 1000));
|
|
12407
|
+
|
|
12408
|
+
return {
|
|
12409
|
+
track(project) {
|
|
12410
|
+
if (stopped || !project?.id || projects.has(project.id)) return;
|
|
12411
|
+
projects.set(project.id, project);
|
|
12412
|
+
log(`Submitted Sogni project ${project.id}. If this run stops before it finishes, the project keeps going; fetch it with: ${resultCommandFor(project.id)}`);
|
|
12413
|
+
updateHold();
|
|
12414
|
+
report(project.id);
|
|
12415
|
+
if (startedAt === null) {
|
|
12416
|
+
startedAt = Date.now();
|
|
12417
|
+
schedule(timeoutMs);
|
|
12418
|
+
}
|
|
12419
|
+
},
|
|
12420
|
+
onTimeout(fn) {
|
|
12421
|
+
onTimeout = fn;
|
|
12422
|
+
},
|
|
12423
|
+
stop() {
|
|
12424
|
+
stopped = true;
|
|
12425
|
+
cleanup();
|
|
12426
|
+
},
|
|
12427
|
+
waitingReasonFor: reasonFor,
|
|
12428
|
+
projectIds() {
|
|
12429
|
+
return [...projects.keys()];
|
|
12430
|
+
}
|
|
12431
|
+
};
|
|
12432
|
+
}
|
|
12433
|
+
|
|
12434
|
+
/**
|
|
12435
|
+
* Report projects submitted with --detach: they keep running on Sogni, and
|
|
12436
|
+
* --status / --result fetch them later, including after the socket has stopped
|
|
12437
|
+
* holding a finished project for this client (one hour).
|
|
12438
|
+
*/
|
|
12439
|
+
function reportDetachedProjects(projects, projectWait) {
|
|
12440
|
+
const projectIds = [...new Set(projects.map((project) => project?.id).filter(Boolean))];
|
|
12441
|
+
const entries = projectIds.map((projectId) => {
|
|
12442
|
+
const waitingReason = projectWait.waitingReasonFor(projectId);
|
|
12443
|
+
return {
|
|
12444
|
+
projectId,
|
|
12445
|
+
waitingReason,
|
|
12446
|
+
message: describeWaitingReason(waitingReason),
|
|
12447
|
+
statusCommand: `sogni-agent --status ${projectId}`,
|
|
12448
|
+
resultCommand: resultCommandFor(projectId)
|
|
12449
|
+
};
|
|
12450
|
+
});
|
|
12451
|
+
if (options.json) {
|
|
12452
|
+
console.log(JSON.stringify({
|
|
12453
|
+
success: true,
|
|
12454
|
+
detached: true,
|
|
12455
|
+
projectIds,
|
|
12456
|
+
projects: entries,
|
|
12457
|
+
note: 'Submitted and still running on Sogni. Nothing was cancelled. Check it with the statusCommand and fetch it with the resultCommand when it finishes; do not resubmit it.'
|
|
12458
|
+
}));
|
|
12459
|
+
return;
|
|
12460
|
+
}
|
|
12461
|
+
for (const entry of entries) {
|
|
12462
|
+
console.log(`Submitted Sogni project ${entry.projectId}; it keeps running on Sogni.`);
|
|
12463
|
+
if (entry.message) console.log(entry.message);
|
|
12464
|
+
console.log(`Check it: ${entry.statusCommand}`);
|
|
12465
|
+
console.log(`Fetch the result when it finishes: ${entry.resultCommand}`);
|
|
12466
|
+
}
|
|
12467
|
+
}
|
|
12468
|
+
|
|
12469
|
+
function projectLookupSummary(result) {
|
|
12470
|
+
const message = describeWaitingReason(result.waitingReason);
|
|
12471
|
+
return {
|
|
12472
|
+
projectId: result.id,
|
|
12473
|
+
status: result.status,
|
|
12474
|
+
finished: result.finished,
|
|
12475
|
+
...(result.modelId ? { model: result.modelId } : {}),
|
|
12476
|
+
waitingReason: result.waitingReason ?? null,
|
|
12477
|
+
...(message ? { message } : {}),
|
|
12478
|
+
jobs: (result.jobs || []).map((job) => ({
|
|
12479
|
+
id: job.id,
|
|
12480
|
+
status: job.status,
|
|
12481
|
+
...(job.reason ? { reason: job.reason } : {}),
|
|
12482
|
+
...(job.kind ? { kind: job.kind } : {}),
|
|
12483
|
+
...(job.url ? { url: job.url } : {}),
|
|
12484
|
+
...(job.urlUnavailable ? { urlUnavailable: job.urlUnavailable } : {})
|
|
12485
|
+
}))
|
|
12486
|
+
};
|
|
12487
|
+
}
|
|
12488
|
+
|
|
12489
|
+
function printProjectStatus(result) {
|
|
12490
|
+
const summary = projectLookupSummary(result);
|
|
12491
|
+
if (options.json) {
|
|
12492
|
+
console.log(JSON.stringify({ success: true, ...summary }));
|
|
12493
|
+
return;
|
|
12494
|
+
}
|
|
12495
|
+
const done = summary.jobs.filter((job) => job.status === 'completed').length;
|
|
12496
|
+
console.log(`Project ${summary.projectId}: ${summary.status}${summary.finished ? ` (${done}/${summary.jobs.length} render(s) completed)` : ''}`);
|
|
12497
|
+
if (summary.message) console.log(summary.message);
|
|
12498
|
+
for (const job of summary.jobs) {
|
|
12499
|
+
if (job.status !== 'completed') console.log(` ${job.id}: ${job.status}${job.reason ? ` (${job.reason})` : ''}`);
|
|
12500
|
+
}
|
|
12501
|
+
if (summary.finished && done > 0) console.log(`Fetch the media with: ${resultCommandFor(summary.projectId)}`);
|
|
12502
|
+
}
|
|
12503
|
+
|
|
12504
|
+
/** --result: the project's media, saved to -o like a normal run when given. */
|
|
12505
|
+
async function saveProjectResult(result) {
|
|
12506
|
+
const summary = projectLookupSummary(result);
|
|
12507
|
+
if (!summary.finished) {
|
|
12508
|
+
if (options.json) {
|
|
12509
|
+
console.log(JSON.stringify({ success: true, ...summary, note: 'Not finished yet; it is still running on Sogni. Check again later; do not resubmit it.' }));
|
|
12510
|
+
} else {
|
|
12511
|
+
console.log(`Project ${summary.projectId} is not finished yet (${summary.status}); it is still running on Sogni.`);
|
|
12512
|
+
if (summary.message) console.log(summary.message);
|
|
12513
|
+
console.log(`Check again later with: ${resultCommandFor(summary.projectId)}`);
|
|
12514
|
+
}
|
|
12515
|
+
return;
|
|
12516
|
+
}
|
|
12517
|
+
const urls = summary.jobs.map((job) => job.url).filter(Boolean);
|
|
12518
|
+
const localPaths = [];
|
|
12519
|
+
if (options.output) {
|
|
12520
|
+
const extension = extname(options.output);
|
|
12521
|
+
for (const [index, url] of urls.entries()) {
|
|
12522
|
+
const path = index === 0
|
|
12523
|
+
? options.output
|
|
12524
|
+
: options.output.slice(0, options.output.length - extension.length) + `-${index + 1}` + extension;
|
|
12525
|
+
await downloadUrlToFile(url, path);
|
|
12526
|
+
localPaths.push(path);
|
|
12527
|
+
}
|
|
12528
|
+
}
|
|
12529
|
+
if (options.json) {
|
|
12530
|
+
console.log(JSON.stringify({ success: true, ...summary, urls, ...(localPaths.length ? { localPaths } : {}) }));
|
|
12531
|
+
return;
|
|
12532
|
+
}
|
|
12533
|
+
console.log(`Project ${summary.projectId}: ${summary.status}`);
|
|
12534
|
+
if (localPaths.length) {
|
|
12535
|
+
for (const path of localPaths) console.log(`Saved to ${path}`);
|
|
12536
|
+
} else {
|
|
12537
|
+
for (const url of urls) console.log(url);
|
|
12538
|
+
}
|
|
12539
|
+
for (const job of summary.jobs) {
|
|
12540
|
+
if (job.urlUnavailable === 'sensitiveContent') console.log(` ${job.id}: withheld by the Sensitive Content Filter`);
|
|
12541
|
+
else if (job.status !== 'completed') console.log(` ${job.id}: ${job.status}${job.reason ? ` (${job.reason})` : ''}`);
|
|
12542
|
+
}
|
|
12543
|
+
}
|
|
12544
|
+
|
|
12545
|
+
function printRecentProjects(projects, hours) {
|
|
12546
|
+
if (options.json) {
|
|
12547
|
+
console.log(JSON.stringify({ success: true, sinceHours: hours, projects }));
|
|
12548
|
+
return;
|
|
12549
|
+
}
|
|
12550
|
+
if (!projects.length) {
|
|
12551
|
+
console.log(`No completed Sogni projects in the last ${hours} hour(s).`);
|
|
12552
|
+
return;
|
|
12553
|
+
}
|
|
12554
|
+
console.log(`Completed Sogni projects in the last ${hours} hour(s), newest first:`);
|
|
12555
|
+
for (const project of projects) {
|
|
12556
|
+
const when = project.finishedAt ? new Date(project.finishedAt).toISOString() : 'unknown time';
|
|
12557
|
+
const ready = project.jobs.filter((job) => job.status === 'completed' && !job.sensitiveContentWithheld).length;
|
|
12558
|
+
console.log(` ${when} ${project.id} ${project.modelName || project.modelId || 'unknown model'} ${ready} result(s)${project.appSource ? ` [${project.appSource}]` : ''}`);
|
|
12559
|
+
}
|
|
12560
|
+
console.log('Fetch one with: sogni-agent --result <projectId>');
|
|
12561
|
+
}
|
|
12562
|
+
|
|
12563
|
+
/**
|
|
12564
|
+
* Before a video is submitted, say how many of this account's other video
|
|
12565
|
+
* projects are already queued or rendering (other runs, apps or devices).
|
|
12566
|
+
* Plans run a limited number at once -- the Unlimited plan runs one standard
|
|
12567
|
+
* MiniMax H3 video at a time -- so the new one may wait for them. Best effort:
|
|
12568
|
+
* it never blocks the run.
|
|
12569
|
+
*/
|
|
12570
|
+
async function warnAboutInFlightProjects(client, log) {
|
|
12571
|
+
const projectsApi = sdkClientOf(client)?.projects;
|
|
12572
|
+
if (typeof projectsApi?.listProjectsElsewhere !== 'function') return;
|
|
12573
|
+
let inFlight;
|
|
12574
|
+
try {
|
|
12575
|
+
inFlight = await projectsApi.listProjectsElsewhere();
|
|
12576
|
+
} catch {
|
|
12577
|
+
return;
|
|
12578
|
+
}
|
|
12579
|
+
const videos = (inFlight || []).filter((project) => !project?.model?.type || project.model.type === 'video');
|
|
12580
|
+
if (!videos.length) return;
|
|
12581
|
+
const count = videos.length === 1 ? '1 other video project is' : `${videos.length} other video projects are`;
|
|
12582
|
+
log(`Note: ${count} already queued or rendering on this account (from other runs, apps or devices). ` +
|
|
12583
|
+
'Plans run a limited number of videos at once (the Unlimited plan runs one standard MiniMax H3 video at a time), ' +
|
|
12584
|
+
'so this one may wait for them. If it does, it starts by itself; do not resubmit it.');
|
|
12585
|
+
}
|
|
12586
|
+
|
|
12587
|
+
/** --status <id>, --result <id>, --recent [hours]. */
|
|
12588
|
+
async function runProjectLookup(client, lookup) {
|
|
12589
|
+
const projectsApi = sdkClientOf(client)?.projects;
|
|
12590
|
+
const method = lookup.action === 'recent' ? 'listRecent' : 'getResult';
|
|
12591
|
+
if (typeof projectsApi?.[method] !== 'function') {
|
|
12592
|
+
const error = new Error(`--${lookup.action} needs @sogni-ai/sogni-client 5.57.0 or later (projects.${method}). Update the Sogni skill.`);
|
|
12593
|
+
error.code = 'SDK_UPDATE_REQUIRED';
|
|
12594
|
+
throw error;
|
|
12595
|
+
}
|
|
12596
|
+
if (lookup.action === 'recent') {
|
|
12597
|
+
const projects = await projectsApi.listRecent({ since: Date.now() - lookup.hours * 3600 * 1000, limit: 100 });
|
|
12598
|
+
printRecentProjects(projects, lookup.hours);
|
|
12599
|
+
return;
|
|
12600
|
+
}
|
|
12601
|
+
const result = await projectsApi.getResult(lookup.projectId);
|
|
12602
|
+
if (lookup.action === 'status') printProjectStatus(result);
|
|
12603
|
+
else await saveProjectResult(result);
|
|
12604
|
+
}
|
|
12605
|
+
|
|
12606
|
+
/**
|
|
12607
|
+
* What to do when a run stops waiting before its projects finish. By default
|
|
12608
|
+
* nothing is cancelled: the projects keep going on Sogni and their results can
|
|
12609
|
+
* be fetched later with --result (or found with --recent). Before 3.53, a
|
|
12610
|
+
* timeout cancelled them, which threw away work that was only queued behind the
|
|
12611
|
+
* account's own plan limit. --cancel-on-timeout keeps that behaviour.
|
|
12612
|
+
*/
|
|
11932
12613
|
async function buildProjectTimeoutError(projects, timeoutMs, label = 'Project') {
|
|
11933
12614
|
const timeoutSeconds = timeoutMs / 1000;
|
|
11934
|
-
const
|
|
11935
|
-
|
|
11936
|
-
const projectIds =
|
|
11937
|
-
|
|
11938
|
-
|
|
12615
|
+
const trackedProjects = [...new Set((projects || []).filter(Boolean))];
|
|
12616
|
+
const cancellableProjects = trackedProjects.filter((project) => typeof project.cancel === 'function');
|
|
12617
|
+
const projectIds = [...new Set(trackedProjects.map((project) => project.id).filter(Boolean))];
|
|
12618
|
+
|
|
12619
|
+
if (!options.cancelOnTimeout) {
|
|
12620
|
+
const waiting = trackedProjects.map((project) => project.waitingReason).find(Boolean) || null;
|
|
12621
|
+
const waitingText = describeWaitingReason(waiting);
|
|
12622
|
+
const resultCommands = projectIds.map(resultCommandFor);
|
|
12623
|
+
const error = new Error(
|
|
12624
|
+
`Stopped waiting after ${timeoutSeconds}s; Sogni ${label.toLowerCase()} ` +
|
|
12625
|
+
`${projectIds.join(', ') || '(unknown id)'} is still running and was not cancelled. ` +
|
|
12626
|
+
(waitingText ? `${waitingText} ` : '') +
|
|
12627
|
+
(resultCommands.length
|
|
12628
|
+
? `Fetch the result when it finishes with: ${resultCommands.join('; ')}`
|
|
12629
|
+
: 'Find it when it finishes with: sogni-agent --recent')
|
|
12630
|
+
);
|
|
12631
|
+
error.code = 'PROJECT_TIMEOUT_STILL_RUNNING';
|
|
12632
|
+
error.details = {
|
|
12633
|
+
timeoutSeconds,
|
|
12634
|
+
projectIds,
|
|
12635
|
+
canceled: false,
|
|
12636
|
+
waitingReason: waiting,
|
|
12637
|
+
resultCommands
|
|
12638
|
+
};
|
|
12639
|
+
return error;
|
|
12640
|
+
}
|
|
11939
12641
|
|
|
11940
12642
|
if (cancellableProjects.length === 0) {
|
|
11941
12643
|
const error = new Error(
|
|
@@ -12406,6 +13108,35 @@ function videoWorkflowHasFrameAnchors() {
|
|
|
12406
13108
|
|| (options.videoWorkflow === 'ia2v' && isMiniMaxH3AudioGuideModel(options.model));
|
|
12407
13109
|
}
|
|
12408
13110
|
|
|
13111
|
+
// The keyframes a render pinned, for --json output and render info.
|
|
13112
|
+
function describeKeyframesForOutput() {
|
|
13113
|
+
return options.keyframes.map(({ image, seconds, frameIndex }) => ({
|
|
13114
|
+
image,
|
|
13115
|
+
seconds,
|
|
13116
|
+
frameIndex,
|
|
13117
|
+
clock: formatMiniMaxH3KeyframeClock(frameIndex)
|
|
13118
|
+
}));
|
|
13119
|
+
}
|
|
13120
|
+
|
|
13121
|
+
// Load each --keyframe image as SDK keyframes, in time order. The Intelligence
|
|
13122
|
+
// Client wrapper cover-crops each one onto the canvas the job renders exactly
|
|
13123
|
+
// like the last frame (twice the canvas on two-stage models); with asset
|
|
13124
|
+
// auto-resize off, the worker makes the same centred crop.
|
|
13125
|
+
async function prepareMiniMaxH3Keyframes() {
|
|
13126
|
+
return Promise.all(options.keyframes.map(async (keyframe) => {
|
|
13127
|
+
const image = await fetchMediaBuffer(keyframe.image);
|
|
13128
|
+
const dims = await getVideoImageDimensionsFromBuffer(image);
|
|
13129
|
+
if (!dims?.width || !dims?.height) {
|
|
13130
|
+
const err = new Error(`Keyframe image ${keyframe.image} is not a readable image.`);
|
|
13131
|
+
err.code = 'INVALID_ARGUMENT';
|
|
13132
|
+
err.hint = 'Pass a PNG, JPEG or WebP still for each --keyframe.';
|
|
13133
|
+
err.details = { flag: '--keyframe', image: keyframe.image, seconds: keyframe.seconds };
|
|
13134
|
+
throw err;
|
|
13135
|
+
}
|
|
13136
|
+
return { image, frameIndex: keyframe.frameIndex };
|
|
13137
|
+
}));
|
|
13138
|
+
}
|
|
13139
|
+
|
|
12409
13140
|
function miniMaxH3R2vReferenceImageCount() {
|
|
12410
13141
|
if (!isMiniMaxH3R2vModel(options.model)) return undefined;
|
|
12411
13142
|
return (options.refImage ? 1 : 0)
|
|
@@ -12427,7 +13158,9 @@ async function buildVideoEstimateParams({ tokenType, steps }) {
|
|
|
12427
13158
|
tokenType,
|
|
12428
13159
|
...(Number.isFinite(steps) && steps > 0 ? { steps } : {}),
|
|
12429
13160
|
...(options.frames ? { frames: options.frames } : { duration: options.duration }),
|
|
12430
|
-
...(referenceImageCount !== undefined ? { referenceImageCount } : {})
|
|
13161
|
+
...(referenceImageCount !== undefined ? { referenceImageCount } : {}),
|
|
13162
|
+
// MiniMax H3 keyframes: two are included, each extra one adds output time.
|
|
13163
|
+
...(options.keyframes.length > 0 ? { keyframeCount: options.keyframes.length } : {})
|
|
12431
13164
|
};
|
|
12432
13165
|
|
|
12433
13166
|
if ((isSeedanceVideo || isWan3Video || isMiniMaxH3R2v) && videoSources.length > 0) {
|
|
@@ -13229,6 +13962,11 @@ async function main() {
|
|
|
13229
13962
|
await disableLiveModelAvailabilityEvents(client);
|
|
13230
13963
|
log('Connected.');
|
|
13231
13964
|
|
|
13965
|
+
if (options.projectLookup) {
|
|
13966
|
+
await runProjectLookup(client, options.projectLookup);
|
|
13967
|
+
return;
|
|
13968
|
+
}
|
|
13969
|
+
|
|
13232
13970
|
if (options.showBalance) {
|
|
13233
13971
|
const balance = await client.getBalance();
|
|
13234
13972
|
const spark = Number.parseFloat(balance?.spark);
|
|
@@ -13323,6 +14061,7 @@ async function main() {
|
|
|
13323
14061
|
tokenType: options.tokenType || 'spark',
|
|
13324
14062
|
count: options.count,
|
|
13325
14063
|
...(delivered ? { deliveredWidth: delivered.width, deliveredHeight: delivered.height } : {}),
|
|
14064
|
+
...(options.keyframes.length > 0 ? { keyframeCount: options.keyframes.length } : {}),
|
|
13326
14065
|
estimate
|
|
13327
14066
|
}));
|
|
13328
14067
|
} else {
|
|
@@ -13343,16 +14082,20 @@ async function main() {
|
|
|
13343
14082
|
let completedJobs = 0;
|
|
13344
14083
|
let loopingStartImageBuffer;
|
|
13345
14084
|
const activeProjects = new Set();
|
|
14085
|
+
const projectWait = createProjectWaitTracker(client, log);
|
|
13346
14086
|
const trackProjectResult = (projectResult) => {
|
|
13347
|
-
if (projectResult?.project)
|
|
14087
|
+
if (projectResult?.project) {
|
|
14088
|
+
activeProjects.add(projectResult.project);
|
|
14089
|
+
projectWait.track(projectResult.project);
|
|
14090
|
+
}
|
|
13348
14091
|
return projectResult;
|
|
13349
14092
|
};
|
|
13350
14093
|
|
|
13351
14094
|
const completionPromise = new Promise((resolve, reject) => {
|
|
13352
|
-
|
|
14095
|
+
projectWait.onTimeout(() => {
|
|
13353
14096
|
void buildProjectTimeoutError([...activeProjects], options.timeout)
|
|
13354
14097
|
.then(reject);
|
|
13355
|
-
}
|
|
14098
|
+
});
|
|
13356
14099
|
|
|
13357
14100
|
client.on(ClientEvent.JOB_COMPLETED, (data) => {
|
|
13358
14101
|
const jobData = data.job?.data || {};
|
|
@@ -13369,30 +14112,30 @@ async function main() {
|
|
|
13369
14112
|
log(`${options.speech ? 'Speech' : options.imageTo3d ? '3D model' : options.music ? 'Music' : (options.video || options.upscaleVideo) ? 'Video' : 'Image'} ${completedJobs}/${options.count} completed`);
|
|
13370
14113
|
|
|
13371
14114
|
if (completedJobs >= options.count) {
|
|
13372
|
-
|
|
14115
|
+
projectWait.stop();
|
|
13373
14116
|
resolve();
|
|
13374
14117
|
}
|
|
13375
14118
|
});
|
|
13376
14119
|
|
|
13377
14120
|
client.on(ClientEvent.JOB_FAILED, (data) => {
|
|
13378
|
-
|
|
14121
|
+
projectWait.stop();
|
|
13379
14122
|
reject(buildProjectResultError(data, 'Job failed'));
|
|
13380
14123
|
});
|
|
13381
14124
|
|
|
13382
14125
|
client.on(ClientEvent.PROJECT_FAILED, (data) => {
|
|
13383
|
-
|
|
14126
|
+
projectWait.stop();
|
|
13384
14127
|
reject(buildProjectResultError(data));
|
|
13385
14128
|
});
|
|
13386
14129
|
|
|
13387
14130
|
client.on(ClientEvent.PROJECT_EVENT, (event) => {
|
|
13388
14131
|
if (event?.type !== 'error') return;
|
|
13389
|
-
|
|
14132
|
+
projectWait.stop();
|
|
13390
14133
|
reject(buildProjectResultError(event));
|
|
13391
14134
|
});
|
|
13392
14135
|
|
|
13393
14136
|
client.on(ClientEvent.JOB_EVENT, (event) => {
|
|
13394
14137
|
if (event?.type !== 'error') return;
|
|
13395
|
-
|
|
14138
|
+
projectWait.stop();
|
|
13396
14139
|
reject(buildProjectResultError(event, 'Job failed'));
|
|
13397
14140
|
});
|
|
13398
14141
|
|
|
@@ -13411,6 +14154,9 @@ async function main() {
|
|
|
13411
14154
|
log(`Generating video (${options.videoWorkflow}) with ${options.model}...`);
|
|
13412
14155
|
if (options.refImage) log(`Reference image: ${options.refImage}`);
|
|
13413
14156
|
if (options.refImageEnd) log(`End frame: ${options.refImageEnd}`);
|
|
14157
|
+
for (const keyframe of options.keyframes) {
|
|
14158
|
+
log(`Keyframe at ${formatMiniMaxH3KeyframeClock(keyframe.frameIndex)} (frame ${keyframe.frameIndex}): ${keyframe.image}`);
|
|
14159
|
+
}
|
|
13414
14160
|
if (options.refAudio) log(`Reference audio: ${options.refAudio}`);
|
|
13415
14161
|
for (const referenceAudio of options.refAudios) log(`Additional reference audio: ${referenceAudio}`);
|
|
13416
14162
|
if (options.referenceAudioIdentity) log(`Voice identity: ${options._voicePersonaResolvedName || options.referenceAudioIdentity}`);
|
|
@@ -13925,6 +14671,10 @@ async function main() {
|
|
|
13925
14671
|
if (contextImageBuffers.length > 0) {
|
|
13926
14672
|
projectConfig.contextImages = contextImageBuffers;
|
|
13927
14673
|
}
|
|
14674
|
+
// MiniMax H3 intermediate keyframes, in time order.
|
|
14675
|
+
if (options.keyframes.length > 0) {
|
|
14676
|
+
projectConfig.keyframes = await prepareMiniMaxH3Keyframes();
|
|
14677
|
+
}
|
|
13928
14678
|
applyLtxTransitionLora(
|
|
13929
14679
|
projectConfig,
|
|
13930
14680
|
options.model,
|
|
@@ -14037,6 +14787,7 @@ async function main() {
|
|
|
14037
14787
|
projectConfig.loraStrengths = options.loraStrengths;
|
|
14038
14788
|
}
|
|
14039
14789
|
|
|
14790
|
+
await warnAboutInFlightProjects(client, log);
|
|
14040
14791
|
const videoResult = trackProjectResult(
|
|
14041
14792
|
await client.createVideoProject(withBillingMode(projectConfig))
|
|
14042
14793
|
);
|
|
@@ -14435,6 +15186,12 @@ async function main() {
|
|
|
14435
15186
|
}
|
|
14436
15187
|
}
|
|
14437
15188
|
|
|
15189
|
+
if (options.detach) {
|
|
15190
|
+
projectWait.stop();
|
|
15191
|
+
reportDetachedProjects([...activeProjects], projectWait);
|
|
15192
|
+
return;
|
|
15193
|
+
}
|
|
15194
|
+
|
|
14438
15195
|
// Wait for completion via events
|
|
14439
15196
|
await completionPromise;
|
|
14440
15197
|
|
|
@@ -14518,6 +15275,7 @@ async function main() {
|
|
|
14518
15275
|
}
|
|
14519
15276
|
renderInfo.refImage = options.refImage;
|
|
14520
15277
|
renderInfo.refImageEnd = options.refImageEnd;
|
|
15278
|
+
if (options.keyframes.length > 0) renderInfo.keyframes = describeKeyframesForOutput();
|
|
14521
15279
|
if (options.refAudio) {
|
|
14522
15280
|
renderInfo.refAudio = options.refAudio;
|
|
14523
15281
|
if (options.audioStart !== null) renderInfo.audioStart = options.audioStart;
|
|
@@ -14795,6 +15553,7 @@ async function main() {
|
|
|
14795
15553
|
}
|
|
14796
15554
|
if (options.refImage) output.refImage = options.refImage;
|
|
14797
15555
|
if (options.refImageEnd) output.refImageEnd = options.refImageEnd;
|
|
15556
|
+
if (options.keyframes.length > 0) output.keyframes = describeKeyframesForOutput();
|
|
14798
15557
|
if (options.refAudio) {
|
|
14799
15558
|
output.refAudio = options.refAudio;
|
|
14800
15559
|
if (options.audioStart !== null) output.audioStart = options.audioStart;
|
|
@@ -14914,6 +15673,9 @@ async function main() {
|
|
|
14914
15673
|
autoResizeVideoAssets: options.video ? (options.autoResizeVideoAssets ?? null) : null,
|
|
14915
15674
|
refImage: options.video ? (options.refImage ?? null) : null,
|
|
14916
15675
|
refImageEnd: options.video ? (options.refImageEnd ?? null) : null,
|
|
15676
|
+
...(options.video && options.keyframes.length > 0
|
|
15677
|
+
? { keyframes: options.keyframes.map(({ image, seconds, frameIndex }) => ({ image, seconds, frameIndex: frameIndex ?? null })) }
|
|
15678
|
+
: {}),
|
|
14917
15679
|
refAudio: options.video ? (options.refAudio ?? null) : null,
|
|
14918
15680
|
referenceAudioIdentity: options.video ? (options.referenceAudioIdentity ?? null) : null,
|
|
14919
15681
|
refVideo: options.video ? (options.refVideo ?? null) : null,
|