Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

refactor: build each video backend submission in its own function (#11094)

Adam Eivyaa23668b880c
diff --git a/client/src/lib/videoGenSubmission.js b/client/src/lib/videoGenSubmission.js
index afc3d867bb..42507336fe 100644
--- a/client/src/lib/videoGenSubmission.js
+++ b/client/src/lib/videoGenSubmission.js
@@ -44,127 +44,161 @@ export function envelopVideoPrompt(text, {
: composed.prompt;
}
-export function buildVideoGenSubmission({
- isGrok, grokDuration, isFal, falDuration, falModelId, falResolution, falGenerateAudio,
- isReactor, reactorClipId, reactorSeconds, reactorSeed, reactorAspect, remoteSubmissionFields,
- displaySleepEnabled,
- prompt, negativePrompt, stylePreset, selectedUniverse,
+// Hosted lanes (Grok, fal, reactor) take only text or image mode, and the
+// source pair is meaningful only in image mode. '' is the wire value otherwise.
+const hostedImageFields = (mode, sourceImageFile, sourceImageUpload) => {
+ const isImage = mode === 'image';
+ return {
+ mode: isImage ? 'image' : 'text',
+ sourceImageFile: isImage ? (sourceImageFile || '') : '',
+ sourceImage: isImage ? (sourceImageUpload || '') : '',
+ };
+};
+
+const clampedSize = (width, height, bounds = VIDEO_EDGE_BOUNDS) => ({
+ width: clampImageEdge(width, bounds),
+ height: clampImageEdge(height, bounds),
+});
+
+// A seed of 0 is a real value; only an unset seed is omitted.
+const omitReactorSeed = (reactorSeed) => (
+ reactorSeed === '' || reactorSeed === null || reactorSeed === undefined ? undefined : reactorSeed
+);
+
+function grokVideoSubmission({
+ composed, grokDuration, width, height, mode, sourceImageFile, sourceImageUpload,
+}) {
+ return {
+ backend: 'grok',
+ prompt: composed.prompt,
+ negativePrompt: composed.negativePrompt,
+ grokDuration,
+ ...clampedSize(width, height),
+ ...hostedImageFields(mode, sourceImageFile, sourceImageUpload),
+ };
+}
+
+function falVideoSubmission({
+ composed, falDuration, falModelId, falResolution, falGenerateAudio,
width, height, mode, sourceImageFile, sourceImageUpload,
- numFrames, fps, steps, guidanceScale, seed, batchSize = 1,
- currentModel, models, modelId, tiling, textEncoderId, speedProfileId, draftDecode, streamingMode,
- disableAudio, noMusic, imageStrength, i2vReferenceMode,
- keyframesActive, keyframes, loraFamily, selectedLoras,
- lastImageFile, lastImageUpload, extendFromVideoId, audioFile,
- icModeActive, icImageKind, icReferenceFile, icReferenceVideoId,
- icReferenceImageFiles, icStrength, icSkipStage2,
- chainingActive, chunks, chunkPrompts, contextFrames,
}) {
- const composed = composeStyledPrompt(prompt, negativePrompt, stylePresetsFor(selectedUniverse, stylePreset));
- const effectiveDisableAudio = supportsVideoAudioControls(currentModel) && disableAudio;
- const withEnvelope = (text) => envelopVideoPrompt(text, {
- currentModel, negativePrompt, stylePreset, selectedUniverse, noMusic, disableAudio,
- });
- // The backing array is deliberately not truncated as chunks change. Only
- // slice live chunks at the wire boundary.
- const beats = chainingActive
- ? chunkPrompts.slice(0, chunks).map((beat) => (beat?.trim() ? withEnvelope(beat) : ''))
- : [];
-
- if (isGrok) {
- return {
- backend: 'grok',
- prompt: composed.prompt,
- negativePrompt: composed.negativePrompt,
- grokDuration,
- width: clampImageEdge(width, VIDEO_EDGE_BOUNDS),
- height: clampImageEdge(height, VIDEO_EDGE_BOUNDS),
- mode: mode === 'image' ? 'image' : 'text',
- sourceImageFile: mode === 'image' ? (sourceImageFile || '') : '',
- sourceImage: mode === 'image' ? (sourceImageUpload || '') : '',
- };
- }
-
- if (isFal) {
- return {
- backend: 'fal',
- prompt: composed.prompt,
- // No negativePrompt: fal's buildRequestBody never sends one, so posting it
- // only stamped a promise on the history record that nothing honored.
- falDuration,
- falModelId: falModelId || undefined,
- ...(falResolution ? { falResolution } : {}),
- ...(falGenerateAudio ? { falGenerateAudio: true } : {}),
- width: clampImageEdge(width, VIDEO_EDGE_BOUNDS),
- height: clampImageEdge(height, VIDEO_EDGE_BOUNDS),
- mode: mode === 'image' ? 'image' : 'text',
- sourceImageFile: mode === 'image' ? (sourceImageFile || '') : '',
- sourceImage: mode === 'image' ? (sourceImageUpload || '') : '',
- };
- }
-
- if (isReactor) {
- return {
- backend: 'reactor',
- prompt: composed.prompt,
- // No negativePrompt: fast-h3's enqueue command has no such field (same as
- // the fal lane above).
- // The clip id chains this render onto a previous reactor clip via
- // continue_from_clip_id; the picker only offers ids off completed reactor
- // history records. Dropped in Image mode because continuation and a
- // starting frame are exclusive — the service rejects a request carrying
- // both, and the picker is already disabled there.
- reactorClipId: (mode === 'image' ? '' : reactorClipId) || undefined,
- reactorSeconds: reactorSeconds || undefined,
- // Unlike falDuration/falModelId, a seed of 0 is a real, meaningful
- // value — `|| undefined` would silently drop it (the reactor route
- // and reactor.js's own buildRequestBody already preserve 0 correctly,
- // so only the client-side send needs the nullish check).
- reactorSeed: reactorSeed === '' || reactorSeed === null || reactorSeed === undefined ? undefined : reactorSeed,
- // No width/height: fast-h3's resolution is its session CANVAS, and every
- // canvas holds a 768px short edge, so the aspect string is the whole
- // choice. '' is the picker's Auto entry — sending nothing asks the server
- // to derive the canvas from the starting frame instead of opening the
- // 16:9 session that squeezed a portrait image into a landscape render.
- reactorAspect: reactorAspect || undefined,
- mode: mode === 'image' ? 'image' : 'text',
- sourceImageFile: mode === 'image' ? (sourceImageFile || '') : '',
- sourceImage: mode === 'image' ? (sourceImageUpload || '') : '',
- };
- }
-
- if (remoteSubmissionFields) {
- return {
- backend: 'local',
- mode: 'text',
- prompt: composed.prompt,
- negativePrompt: composed.negativePrompt,
- width: clampImageEdge(width, VIDEO_EDGE_BOUNDS),
- height: clampImageEdge(height, VIDEO_EDGE_BOUNDS),
- numFrames,
- fps,
- steps: steps || '',
- guidanceScale: guidanceScale || '',
- seed: seed ?? '',
- ...remoteSubmissionFields,
- };
- }
+ return {
+ backend: 'fal',
+ prompt: composed.prompt,
+ // No negativePrompt: fal's buildRequestBody never sends one, so posting it
+ // only stamped a promise on the history record that nothing honored.
+ falDuration,
+ falModelId: falModelId || undefined,
+ ...(falResolution ? { falResolution } : {}),
+ ...(falGenerateAudio ? { falGenerateAudio: true } : {}),
+ ...clampedSize(width, height),
+ ...hostedImageFields(mode, sourceImageFile, sourceImageUpload),
+ };
+}
- const legacyFflf = mode === 'fflf' && !keyframesActive;
- const localEdgeBounds = videoEdgeBoundsForModel(currentModel);
+function reactorVideoSubmission({
+ composed, reactorClipId, reactorSeconds, reactorSeed, reactorAspect,
+ mode, sourceImageFile, sourceImageUpload,
+}) {
+ return {
+ backend: 'reactor',
+ prompt: composed.prompt,
+ // No negativePrompt: fast-h3's enqueue command has no such field (same as
+ // the fal lane above).
+ // The clip id chains this render onto a previous reactor clip via
+ // continue_from_clip_id; the picker only offers ids off completed reactor
+ // history records. Dropped in Image mode because continuation and a
+ // starting frame are exclusive — the service rejects a request carrying
+ // both, and the picker is already disabled there.
+ reactorClipId: (mode === 'image' ? '' : reactorClipId) || undefined,
+ reactorSeconds: reactorSeconds || undefined,
+ // Unlike falDuration/falModelId, a seed of 0 is a real, meaningful
+ // value — `|| undefined` would silently drop it.
+ reactorSeed: omitReactorSeed(reactorSeed),
+ // No width/height: fast-h3's resolution is its session CANVAS, and every
+ // canvas holds a 768px short edge, so the aspect string is the whole
+ // choice. '' is the picker's Auto entry — sending nothing asks the server
+ // to derive the canvas from the starting frame instead of opening the
+ // 16:9 session that squeezed a portrait image into a landscape render.
+ reactorAspect: reactorAspect || undefined,
+ ...hostedImageFields(mode, sourceImageFile, sourceImageUpload),
+ };
+}
+
+function remoteVideoSubmission({
+ composed, remoteSubmissionFields, width, height, numFrames, fps, steps, guidanceScale, seed,
+}) {
return {
backend: 'local',
- prompt: withEnvelope(prompt),
- negativePrompt: currentModel?.supportsNegativePrompt === false ? '' : composed.negativePrompt,
- modelId,
- width: clampImageEdge(width, localEdgeBounds),
- height: clampImageEdge(height, localEdgeBounds),
+ mode: 'text',
+ prompt: composed.prompt,
+ negativePrompt: composed.negativePrompt,
+ ...clampedSize(width, height),
numFrames,
fps,
steps: steps || '',
guidanceScale: guidanceScale || '',
seed: seed ?? '',
- ...(currentModel?.supportsWarmBatch && !chainingActive && batchSize > 1 ? { batchSize } : {}),
- tiling: currentModel?.supportsTiling === false ? 'auto' : tiling,
+ ...remoteSubmissionFields,
+ };
+}
+
+const attachesStartFrame = (mode, runtime, legacyFflf) => (
+ mode === 'image' || mode === 'a2v' || legacyFflf
+ || (mode === 'extend' && !isLtx2FamilyRuntime(runtime))
+);
+
+// The inline-upload half of the start frame: an extend on a non-LTX-2 runtime
+// reuses a stored file only, so it never carries an upload.
+const attachesStartUpload = (mode, legacyFflf) => mode === 'image' || mode === 'a2v' || legacyFflf;
+
+// LTX-2 extends continue a prior render by id instead of a start frame.
+const attachesExtendSource = (mode, runtime) => mode === 'extend' && isLtx2FamilyRuntime(runtime);
+
+function frameSourceFields({
+ mode, runtime, legacyFflf, sourceImageFile, sourceImageUpload,
+ lastImageFile, lastImageUpload, extendFromVideoId, audioFile,
+}) {
+ return {
+ sourceImageFile: attachesStartFrame(mode, runtime, legacyFflf) ? (sourceImageFile || '') : '',
+ sourceImage: attachesStartUpload(mode, legacyFflf) ? (sourceImageUpload || '') : '',
+ lastImageFile: legacyFflf ? (lastImageFile || '') : '',
+ lastImage: legacyFflf ? (lastImageUpload || '') : '',
+ extendFromVideoId: attachesExtendSource(mode, runtime) ? (extendFromVideoId || '') : '',
+ audioFile: mode === 'a2v' ? (audioFile || '') : '',
+ };
+}
+
+// IC-LoRA references: a video reference (file wins over a stored video id) and
+// image references are mutually exclusive by `icImageKind`.
+function icReferenceFields({
+ icModeActive, icImageKind, icReferenceFile, icReferenceVideoId,
+ icReferenceImageFiles, icStrength, icSkipStage2,
+}) {
+ const videoKind = icModeActive && !icImageKind;
+ return {
+ icReference: videoKind ? (icReferenceFile || '') : '',
+ icReferenceVideoIds: (videoKind && !icReferenceFile) ? (icReferenceVideoId || '') : '',
+ icReferenceImageFiles: icImageKind ? icReferenceImageFiles.filter(Boolean) : undefined,
+ icStrength: icModeActive ? icStrength : '',
+ icSkipStage2: icModeActive && icSkipStage2 ? 'true' : '',
+ };
+}
+
+function chunkFields({ chainingActive, chunks, beats, contextFrames }) {
+ return {
+ chunks: chainingActive ? chunks : '',
+ chunkPrompts: beats.some((beat) => beat.trim()) ? JSON.stringify(beats) : '',
+ contextFrames: chainingActive ? String(contextFrames) : '',
+ };
+}
+
+// Request-only knobs whose absence (undefined) means "server default".
+function localOptionalFields({
+ currentModel, models, textEncoderId, speedProfileId, draftDecode, streamingMode,
+ mode, chainingActive, contextFrames,
+}) {
+ return {
textEncoderId: normalizeTextEncoderForModel(textEncoderId, currentModel) === STOCK_TEXT_ENCODER_ID
? undefined
: textEncoderId,
@@ -188,34 +222,88 @@ export function buildVideoGenSubmission({
streamingMode: (isLtx2FamilyRuntime(currentModel?.runtime) && !isDefaultVideoStreamingMode(streamingMode))
? streamingMode
: undefined,
- disableAudio: effectiveDisableAudio ? 'true' : 'false',
- // Only meaningful on a runtime the GPU-watchdog mitigation applies to —
- // absent otherwise so an unrelated model's render never carries a stale
- // choice. The grok/fal/reactor/remote branches above already returned, so
- // reaching here already means none of those apply.
- ...(currentModel?.sleepsDisplayDuringRender ? { displaySleep: displaySleepEnabled ? 'true' : 'false' } : {}),
+ };
+}
+
+function loraFields({ loraFamily, selectedLoras }) {
+ const hasLoras = loraFamily && selectedLoras.length;
+ return {
+ loraFilenames: hasLoras ? selectedLoras.map((lora) => lora.filename) : undefined,
+ loraScales: hasLoras ? selectedLoras.map((lora) => lora.scale) : undefined,
+ };
+}
+
+function conditioningFields({ mode, imageStrength, i2vReferenceMode, keyframesActive, keyframes }) {
+ return {
mode,
imageStrength: imageStrength || '',
i2vReferenceMode: isDefaultI2vReferenceMode(i2vReferenceMode) ? '' : i2vReferenceMode,
keyframes: keyframesActive ? JSON.stringify(keyframes) : '',
- loraFilenames: (loraFamily && selectedLoras.length) ? selectedLoras.map((lora) => lora.filename) : undefined,
- loraScales: (loraFamily && selectedLoras.length) ? selectedLoras.map((lora) => lora.scale) : undefined,
- sourceImageFile: (mode === 'image' || mode === 'a2v' || legacyFflf
- || (mode === 'extend' && !isLtx2FamilyRuntime(currentModel?.runtime)))
- ? (sourceImageFile || '') : '',
- sourceImage: (mode === 'image' || mode === 'a2v' || legacyFflf) ? (sourceImageUpload || '') : '',
- lastImageFile: legacyFflf ? (lastImageFile || '') : '',
- lastImage: legacyFflf ? (lastImageUpload || '') : '',
- extendFromVideoId: (mode === 'extend' && isLtx2FamilyRuntime(currentModel?.runtime))
- ? (extendFromVideoId || '') : '',
- audioFile: mode === 'a2v' ? (audioFile || '') : '',
- icReference: (icModeActive && !icImageKind) ? (icReferenceFile || '') : '',
- icReferenceVideoIds: (icModeActive && !icImageKind && !icReferenceFile) ? (icReferenceVideoId || '') : '',
- icReferenceImageFiles: icImageKind ? icReferenceImageFiles.filter(Boolean) : undefined,
- icStrength: icModeActive ? icStrength : '',
- icSkipStage2: icModeActive && icSkipStage2 ? 'true' : '',
- chunks: chainingActive ? chunks : '',
- chunkPrompts: beats.some((beat) => beat.trim()) ? JSON.stringify(beats) : '',
- contextFrames: chainingActive ? String(contextFrames) : '',
};
}
+
+function localVideoSubmission(args, { composed, withEnvelope, effectiveDisableAudio, beats }) {
+ const {
+ prompt, width, height, mode, numFrames, fps, steps, guidanceScale, seed, batchSize = 1,
+ currentModel, modelId, tiling, displaySleepEnabled, keyframesActive,
+ chainingActive, chunks, contextFrames,
+ } = args;
+ const legacyFflf = mode === 'fflf' && !keyframesActive;
+ return {
+ backend: 'local',
+ prompt: withEnvelope(prompt),
+ negativePrompt: currentModel?.supportsNegativePrompt === false ? '' : composed.negativePrompt,
+ modelId,
+ ...clampedSize(width, height, videoEdgeBoundsForModel(currentModel)),
+ numFrames,
+ fps,
+ steps: steps || '',
+ guidanceScale: guidanceScale || '',
+ seed: seed ?? '',
+ ...(currentModel?.supportsWarmBatch && !chainingActive && batchSize > 1 ? { batchSize } : {}),
+ tiling: currentModel?.supportsTiling === false ? 'auto' : tiling,
+ ...localOptionalFields(args),
+ disableAudio: effectiveDisableAudio ? 'true' : 'false',
+ // Only meaningful on a runtime the GPU-watchdog mitigation applies to —
+ // absent otherwise so an unrelated model's render never carries a stale
+ // choice.
+ ...(currentModel?.sleepsDisplayDuringRender ? { displaySleep: displaySleepEnabled ? 'true' : 'false' } : {}),
+ ...conditioningFields(args),
+ ...loraFields(args),
+ ...frameSourceFields({ ...args, runtime: currentModel?.runtime, legacyFflf }),
+ ...icReferenceFields(args),
+ ...chunkFields({ chainingActive, chunks, beats, contextFrames }),
+ };
+}
+
+// The backing array is deliberately not truncated as chunks change. Only
+// slice live chunks at the wire boundary.
+const liveBeats = (chainingActive, chunkPrompts, chunks, withEnvelope) => (
+ chainingActive
+ ? chunkPrompts.slice(0, chunks).map((beat) => (beat?.trim() ? withEnvelope(beat) : ''))
+ : []
+);
+
+export function buildVideoGenSubmission(args) {
+ const {
+ isGrok, isFal, isReactor, remoteSubmissionFields,
+ prompt, negativePrompt, stylePreset, selectedUniverse,
+ currentModel, disableAudio, noMusic, chainingActive, chunks, chunkPrompts,
+ } = args;
+ const composed = composeStyledPrompt(prompt, negativePrompt, stylePresetsFor(selectedUniverse, stylePreset));
+ const withEnvelope = (text) => envelopVideoPrompt(text, {
+ currentModel, negativePrompt, stylePreset, selectedUniverse, noMusic, disableAudio,
+ });
+ const shared = { ...args, composed };
+
+ if (isGrok) return grokVideoSubmission(shared);
+ if (isFal) return falVideoSubmission(shared);
+ if (isReactor) return reactorVideoSubmission(shared);
+ if (remoteSubmissionFields) return remoteVideoSubmission(shared);
+ return localVideoSubmission(args, {
+ composed,
+ withEnvelope,
+ effectiveDisableAudio: supportsVideoAudioControls(currentModel) && disableAudio,
+ beats: liveBeats(chainingActive, chunkPrompts, chunks, withEnvelope),
+ });
+}
diff --git a/client/src/lib/videoGenSubmission.test.js b/client/src/lib/videoGenSubmission.test.js
index fbb2c21ca8..a6a1599b92 100644
--- a/client/src/lib/videoGenSubmission.test.js
+++ b/client/src/lib/videoGenSubmission.test.js
@@ -74,3 +74,171 @@ describe('buildVideoGenSubmission — fal options (#9232)', () => {
expect(payload).not.toHaveProperty('falGenerateAudio');
});
});
+
+describe('buildVideoGenSubmission — hosted image-mode source', () => {
+ const source = { sourceImageFile: 'frame.png', sourceImageUpload: 'data:image/png;base64,AAA' };
+ const lanes = { grok: { isGrok: true }, fal: { isFal: true }, reactor: { isReactor: true } };
+
+ for (const [backend, flag] of Object.entries(lanes)) {
+ it(`${backend}: image mode copies the source, text mode sends empty strings`, () => {
+ expect(buildVideoGenSubmission(baseArgs({ ...flag, ...source, mode: 'image' })))
+ .toMatchObject({ backend, mode: 'image', sourceImageFile: 'frame.png', sourceImage: 'data:image/png;base64,AAA' });
+ expect(buildVideoGenSubmission(baseArgs({ ...flag, ...source, mode: 'text' })))
+ .toMatchObject({ backend, mode: 'text', sourceImageFile: '', sourceImage: '' });
+ // Any non-image mode collapses to text on hosted lanes.
+ expect(buildVideoGenSubmission(baseArgs({ ...flag, ...source, mode: 'a2v' })))
+ .toMatchObject({ mode: 'text', sourceImageFile: '', sourceImage: '' });
+ });
+
+ it(`${backend}: image mode with no source sends empty strings`, () => {
+ expect(buildVideoGenSubmission(baseArgs({ ...flag, mode: 'image' })))
+ .toMatchObject({ mode: 'image', sourceImageFile: '', sourceImage: '' });
+ });
+ }
+
+ it('fal and reactor never send a negative prompt; grok does', () => {
+ const args = { negativePrompt: 'blurry' };
+ expect(buildVideoGenSubmission(baseArgs({ isFal: true, ...args }))).not.toHaveProperty('negativePrompt');
+ expect(buildVideoGenSubmission(baseArgs({ isReactor: true, ...args }))).not.toHaveProperty('negativePrompt');
+ expect(buildVideoGenSubmission(baseArgs({ isGrok: true, ...args }))).toHaveProperty('negativePrompt');
+ });
+
+ it('fal omits an unset model id', () => {
+ expect(buildVideoGenSubmission(baseArgs({ isFal: true, falModelId: '' })).falModelId).toBeUndefined();
+ expect(buildVideoGenSubmission(baseArgs({ isFal: true, falModelId: 'm1' })).falModelId).toBe('m1');
+ });
+});
+
+describe('buildVideoGenSubmission — reactor fields', () => {
+ const reactor = (o) => buildVideoGenSubmission(baseArgs({ isReactor: true, ...o }));
+
+ it('sends a seed of 0 and omits an unset seed', () => {
+ expect(reactor({ reactorSeed: 0 }).reactorSeed).toBe(0);
+ expect(reactor({ reactorSeed: 42 }).reactorSeed).toBe(42);
+ expect(reactor({ reactorSeed: '' }).reactorSeed).toBeUndefined();
+ expect(reactor({ reactorSeed: null }).reactorSeed).toBeUndefined();
+ expect(reactor({ reactorSeed: undefined }).reactorSeed).toBeUndefined();
+ });
+
+ it('drops the continuation clip id in image mode and omits empty seconds/aspect', () => {
+ expect(reactor({ reactorClipId: 'c1', mode: 'text' }).reactorClipId).toBe('c1');
+ expect(reactor({ reactorClipId: 'c1', mode: 'image' }).reactorClipId).toBeUndefined();
+ expect(reactor({ reactorClipId: '' }).reactorClipId).toBeUndefined();
+ const p = reactor({ reactorSeconds: 0, reactorAspect: '' });
+ expect(p.reactorSeconds).toBeUndefined();
+ expect(p.reactorAspect).toBeUndefined();
+ expect(p).not.toHaveProperty('width');
+ expect(reactor({ reactorSeconds: 5, reactorAspect: '9:16' })).toMatchObject({ reactorSeconds: 5, reactorAspect: '9:16' });
+ });
+});
+
+describe('buildVideoGenSubmission — remote lane', () => {
+ it('spreads remote fields over a text-mode local payload', () => {
+ const p = buildVideoGenSubmission(baseArgs({
+ remoteSubmissionFields: { modelId: 'remote-1', remoteInstanceId: 'peer' },
+ steps: 0, guidanceScale: 0, seed: 0,
+ }));
+ expect(p).toMatchObject({
+ backend: 'local', mode: 'text', modelId: 'remote-1', remoteInstanceId: 'peer',
+ steps: '', guidanceScale: '', seed: 0, numFrames: 121, fps: 24,
+ });
+ expect(p).not.toHaveProperty('tiling');
+ });
+});
+
+describe('buildVideoGenSubmission — local frame sources', () => {
+ const ltx = { runtime: 'ltx2' };
+ const other = { runtime: 'mlx_video' };
+ const src = { sourceImageFile: 'a.png', sourceImageUpload: 'up', lastImageFile: 'z.png', lastImageUpload: 'zup', extendFromVideoId: 'v1', audioFile: 'a.wav' };
+ const local = (o) => buildVideoGenSubmission(baseArgs({ currentModel: other, ...src, ...o }));
+
+ it('attaches the start frame for image mode', () => {
+ expect(local({ mode: 'image' })).toMatchObject({ sourceImageFile: 'a.png', sourceImage: 'up', lastImageFile: '', lastImage: '', extendFromVideoId: '', audioFile: '' });
+ });
+
+ it('attaches the start frame and audio for a2v', () => {
+ expect(local({ mode: 'a2v' })).toMatchObject({ sourceImageFile: 'a.png', sourceImage: 'up', audioFile: 'a.wav', extendFromVideoId: '' });
+ });
+
+ it('attaches both frames for legacy first-last-frame, not when keyframes are active', () => {
+ expect(local({ mode: 'fflf', keyframesActive: false }))
+ .toMatchObject({ sourceImageFile: 'a.png', sourceImage: 'up', lastImageFile: 'z.png', lastImage: 'zup' });
+ expect(local({ mode: 'fflf', keyframesActive: true, keyframes: [{ a: 1 }] }))
+ .toMatchObject({ sourceImageFile: '', sourceImage: '', lastImageFile: '', lastImage: '', keyframes: '[{"a":1}]' });
+ });
+
+ it('extend on a non-LTX-2 runtime attaches the file only (no upload, no video id)', () => {
+ expect(local({ mode: 'extend' })).toMatchObject({ sourceImageFile: 'a.png', sourceImage: '', extendFromVideoId: '' });
+ });
+
+ it('extend on LTX-2 uses extendFromVideoId and no start frame', () => {
+ expect(local({ mode: 'extend', currentModel: ltx })).toMatchObject({ sourceImageFile: '', sourceImage: '', extendFromVideoId: 'v1' });
+ });
+
+ it('text mode sends empty strings for every frame/audio/extend field', () => {
+ expect(local({ mode: 'text' })).toMatchObject({
+ sourceImageFile: '', sourceImage: '', lastImageFile: '', lastImage: '', extendFromVideoId: '', audioFile: '', keyframes: '',
+ });
+ });
+
+ it('missing sources fall back to empty strings', () => {
+ expect(buildVideoGenSubmission(baseArgs({ currentModel: other, mode: 'fflf' })))
+ .toMatchObject({ sourceImageFile: '', sourceImage: '', lastImageFile: '', lastImage: '' });
+ });
+});
+
+describe('buildVideoGenSubmission — local IC-LoRA, chunks and misc', () => {
+ const local = (o) => buildVideoGenSubmission(baseArgs({ currentModel: { runtime: 'ltx2' }, ...o }));
+
+ it('inactive IC mode sends empty reference fields', () => {
+ expect(local({ icReferenceFile: 'r.mp4', icReferenceVideoId: 'v' })).toMatchObject({
+ icReference: '', icReferenceVideoIds: '', icStrength: '', icSkipStage2: '',
+ });
+ expect(local({})).toHaveProperty('icReferenceImageFiles', undefined);
+ });
+
+ it('video reference: file wins over video id; video id used when no file', () => {
+ expect(local({ icModeActive: true, icReferenceFile: 'r.mp4', icReferenceVideoId: 'v', icStrength: 0.5, icSkipStage2: true }))
+ .toMatchObject({ icReference: 'r.mp4', icReferenceVideoIds: '', icStrength: 0.5, icSkipStage2: 'true' });
+ expect(local({ icModeActive: true, icReferenceVideoId: 'v' }))
+ .toMatchObject({ icReference: '', icReferenceVideoIds: 'v', icSkipStage2: '' });
+ expect(local({ icModeActive: true }).icReferenceImageFiles).toBeUndefined();
+ });
+
+ it('image reference kind sends filtered image files and no video fields', () => {
+ expect(local({
+ icModeActive: true, icImageKind: true, icReferenceFile: 'r.mp4', icReferenceVideoId: 'v',
+ icReferenceImageFiles: ['a.png', '', 'b.png'],
+ })).toMatchObject({ icReference: '', icReferenceVideoIds: '', icReferenceImageFiles: ['a.png', 'b.png'] });
+ });
+
+ it('inactive chunking sends empty strings; active chunking slices live beats', () => {
+ expect(local({ chunkPrompts: ['x'], chunks: 2, contextFrames: 9 }))
+ .toMatchObject({ chunks: '', chunkPrompts: '', contextFrames: '' });
+ const p = local({ chainingActive: true, chunks: 2, chunkPrompts: ['one', 'two', 'stale'], contextFrames: 9 });
+ expect(p).toMatchObject({ chunks: 2, contextFrames: '9' });
+ expect(JSON.parse(p.chunkPrompts)).toEqual(['one', 'two']);
+ expect(local({ chainingActive: true, chunks: 2, chunkPrompts: ['', ' '] }).chunkPrompts).toBe('');
+ });
+
+ it('batch size, loras, display sleep and negative prompt follow model support', () => {
+ expect(local({ currentModel: { runtime: 'ltx2', supportsWarmBatch: true }, batchSize: 3 }).batchSize).toBe(3);
+ expect(local({ currentModel: { runtime: 'ltx2', supportsWarmBatch: true }, batchSize: 3, chainingActive: true })).not.toHaveProperty('batchSize');
+ expect(local({ batchSize: 3 })).not.toHaveProperty('batchSize');
+ const loras = local({ loraFamily: 'ltx', selectedLoras: [{ filename: 'f.safetensors', scale: 0.8 }] });
+ expect(loras.loraFilenames).toEqual(['f.safetensors']);
+ expect(loras.loraScales).toEqual([0.8]);
+ expect(local({ loraFamily: 'ltx', selectedLoras: [] }).loraFilenames).toBeUndefined();
+ expect(local({ currentModel: { runtime: 'ltx2', sleepsDisplayDuringRender: true }, displaySleepEnabled: true }).displaySleep).toBe('true');
+ expect(local({ currentModel: { runtime: 'ltx2', sleepsDisplayDuringRender: true }, displaySleepEnabled: false }).displaySleep).toBe('false');
+ expect(local({})).not.toHaveProperty('displaySleep');
+ expect(local({ currentModel: { runtime: 'ltx2', supportsNegativePrompt: false }, negativePrompt: 'x' }).negativePrompt).toBe('');
+ expect(local({ currentModel: { runtime: 'ltx2', supportsTiling: false }, tiling: 'on' }).tiling).toBe('auto');
+ expect(local({ tiling: 'on' }).tiling).toBe('on');
+ });
+
+ it('steps, guidance and seed keep 0 seed but blank 0 steps/guidance', () => {
+ expect(local({ steps: 0, guidanceScale: 0, seed: 0 })).toMatchObject({ steps: '', guidanceScale: '', seed: 0 });
+ expect(local({ steps: 8, guidanceScale: 3, seed: null })).toMatchObject({ steps: 8, guidanceScale: 3, seed: '' });
+ });
+});