Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Respect video duration constraints without treating fallbacks as limits
Codex release-state testa600e6905e1b
diff --git a/docs/providers-and-models.md b/docs/providers-and-models.mdindex 89fcd7780..9b7510ca8 100644--- a/docs/providers-and-models.md+++ b/docs/providers-and-models.md@@ -327,10 +327,15 @@ body has, its listed clip lengths (sent as listed, such as `6`, `"6"` orlisted aspect ratios and resolutions (matched without regard to case and sent aslisted, such as `768P`). When fal.ai's catalog has no readable clip lengths,WebBrain also tries its public OpenAPI endpoint without credentials. If clip-lengths remain unavailable, scenes use the schema's stated duration default,-or an 8-second fallback. A one-minute request can therefore use eight distinct+lengths remain unavailable, an unspecified clip length uses the schema's valid+duration default, or a whole-second fallback starting at 8 seconds that meets+the published minimum, maximum and step size. A one-minute request can use eight distinct8-second scenes, aiming for 64 seconds; the output is measured separately.-Fallback lengths are attempts, not advertised model limits. String duration+Fallback lengths are attempts, not advertised model limits. Explicit clip and+scene lengths can exceed the default or fallback when the published constraints+allow them; scene lengths round up as needed to satisfy those constraints.+When no valid whole-second length fits the 120-second cap, the request fails+before generation with an actionable error. String durationinputs keep their declared encoding; a schema with no duration field uses theprovider's default without adding that field. Real submission errors stillstop the request, while missing metadata alone does not. A localdiff --git a/src/chrome/src/agent/generative-media.js b/src/chrome/src/agent/generative-media.jsindex 343482ba4..03678f50f 100644--- a/src/chrome/src/agent/generative-media.js+++ b/src/chrome/src/agent/generative-media.js@@ -342,11 +342,13 @@ export function videoInputCapabilities(openapi) {if (defaultSeconds !== undefined) break;}if (defaultSeconds !== undefined) entry.default_duration = defaultSeconds;- const admitsType = (form, allowed) => form.every(schema => schema.type === undefined- || [].concat(schema.type).some(type => allowed.includes(type)));- const stringOnly = durationForms.some(form => admitsType(form, ['string']))- && !durationForms.some(form => admitsType(form, ['integer', 'number']));- entry.encodeDuration = seconds => seconds === defaultSeconds ? defaultValue : stringOnly ? String(seconds) : seconds;+ entry.encodeDuration = seconds => {+ const candidates = seconds === defaultSeconds ? [defaultValue, seconds, String(seconds)] : [seconds, String(seconds)];+ // A missing type does not justify converting to text to evade numeric bounds.+ return candidates.find(value => durationForms.some(form => formAllows(form, value)+ && (typeof value !== 'string' || value === defaultValue+ || form.some(schema => [].concat(schema.type ?? []).includes('string')))));+ };}const aspectRatios = listed('aspect_ratio');if (aspectRatios) entry.supported_aspect_ratios = aspectRatios;@@ -358,7 +360,26 @@ export function videoInputCapabilities(openapi) {// A clip's length as the model takes it, ready to merge into its request.function clipLength(entry, clip) {if (clip.duration === undefined || (entry?.inputs && !entry.inputs.includes('duration'))) return {};- return { duration: entry?.encodeDuration ? entry.encodeDuration(clip.duration) : clip.duration };+ const duration = entry?.encodeDuration ? entry.encodeDuration(clip.duration) : clip.duration;+ if (duration === undefined) throw new Error(`This video model's published duration constraints do not allow a ${clip.duration} s clip. Choose a supported duration.`);+ return { duration };+}++// Unbounded schemas can still have a minimum or step size. Choose whole seconds+// that satisfy those constraints without turning the fallback into a maximum.+function nextVideoDuration(entry, minimum) {+ for (let seconds = Math.ceil(minimum); seconds <= MAX_VIDEO_SECONDS; seconds++) {+ if (!entry?.encodeDuration || entry.encodeDuration(seconds) !== undefined) return seconds;+ }+ return undefined;+}++function fallbackVideoDuration(entry) {+ const preferred = entry?.default_duration;+ if (preferred > 0 && preferred <= MAX_VIDEO_SECONDS && nextVideoDuration(entry, preferred) === preferred) return preferred;+ const duration = nextVideoDuration(entry, FALLBACK_VIDEO_CLIP_SECONDS) ?? nextVideoDuration(entry, 1);+ if (duration === undefined) throw new Error(`The published duration constraints provide no usable whole-second clip within WebBrain's ${MAX_VIDEO_SECONDS} s limit. Choose a model that accepts a duration within that limit.`);+ return duration;}/**@@ -368,26 +389,26 @@ function clipLength(entry, clip) {* the model would make the same clip twice. Refuses more than `maxSeconds` in* total or `maxClips`.*/-export function planVideoClips(scenes, durations, { maxSeconds = MAX_VIDEO_SECONDS, maxClips = MAX_VIDEO_CLIPS, fallbackSeconds = FALLBACK_VIDEO_CLIP_SECONDS } = {}) {+export function planVideoClips(scenes, durations, { maxSeconds = MAX_VIDEO_SECONDS, maxClips = MAX_VIDEO_CLIPS, fallbackSeconds = FALLBACK_VIDEO_CLIP_SECONDS,+ selectDuration = seconds => seconds ?? fallbackSeconds } = {}) {const lengths = durations?.length ? durations : [fallbackSeconds];const longest = lengths[lengths.length - 1];const clips = scenes.map((scene, index) => {const prompt = String(scene?.prompt || '').trim();if (!prompt) throw new Error(`Scene ${index + 1} needs a prompt.`);- if (scene.duration > longest) {- if (!durations?.length) {- throw new Error(`Scene ${index + 1} is ${scene.duration} s. Published clip lengths are unavailable, so WebBrain is using ${longest} s as a fallback, not a confirmed model limit. Retry with distinct scenes of up to ${longest} s that cover the full requested duration; WebBrain will generate and join them.`);- }+ if (durations?.length && scene.duration > longest) {throw new Error(`Scene ${index + 1} is ${scene.duration} s, and this model makes clips of up to ${longest} s. Split it into scenes of up to ${longest} s, each with its own prompt for its part, so no clip repeats another.`);}- return { prompt, duration: lengths.find(value => value >= scene.duration) ?? longest };+ const duration = durations?.length ? lengths.find(value => value >= scene.duration) ?? longest : selectDuration(scene.duration);+ if (duration === undefined) throw new Error(`Scene ${index + 1} has no supported whole-second duration within WebBrain's ${maxSeconds} s limit. Shorten the scene or choose another video model.`);+ return { prompt, duration };});const total = clips.reduce((sum, clip) => sum + clip.duration, 0);if (clips.length > maxClips) {throw new Error(`These scenes need ${clips.length} clips and WebBrain makes at most ${maxClips}. Use fewer, longer scenes.`);}if (total > maxSeconds) {- throw new Error(`These scenes come to ${total} s with the ${durations?.length ? "model's clip lengths" : 'fallback clip length'} (${lengths.join(', ')} s), and WebBrain makes videos up to ${maxSeconds} s. Shorten or merge scenes.`);+ throw new Error(`These scenes come to ${total} s with the ${durations?.length ? "model's clip lengths" : 'planned clip lengths'} (${[...new Set(clips.map(clip => clip.duration))].join(', ')} s), and WebBrain makes videos up to ${maxSeconds} s. Shorten or merge scenes.`);}return { clips, total };}@@ -396,22 +417,25 @@ export function planVideoClips(scenes, durations, { maxSeconds = MAX_VIDEO_SECON// clips of its scenes.function planVideo(prompt, video, entry) {const durations = clipDurations(entry);- const fallbackSeconds = entry?.default_duration || FALLBACK_VIDEO_CLIP_SECONDS;- const fallback = durations ? {} : { fallbackClipSeconds: fallbackSeconds };const shape = videoShape(entry, video);const scenes = Array.isArray(video?.scenes) ? video.scenes : null;+ const needsFallback = !durations && (scenes?.length || (video?.duration === undefined && video?.estimated_duration !== undefined));+ const fallbackSeconds = needsFallback ? fallbackVideoDuration(entry) : undefined;+ const fallback = fallbackSeconds === undefined ? {} : { fallbackClipSeconds: fallbackSeconds };if (scenes?.length) {if (video.duration !== undefined) throw new Error('With scenes, give each scene its duration instead of duration.');if (video.estimated_duration === undefined) {throw new Error('With scenes, give estimated_duration: how many seconds the requested video needs before fitting it to the 120 s maximum.');}- const { clips, total } = planVideoClips(scenes, durations, { fallbackSeconds });+ const { clips, total } = planVideoClips(scenes, durations, {+ fallbackSeconds, selectDuration: seconds => nextVideoDuration(entry, seconds ?? fallbackSeconds),+ });if (video.estimated_duration <= MAX_VIDEO_SECONDS && total < video.estimated_duration) {throw new Error(`These scenes provide ${total} s, but the requested video needs ${video.estimated_duration} s. Add or lengthen scenes to cover the requested duration before generating.`);}return {scenes: true,- ...fallback,+ ...(clips.some(clip => clip.duration === fallbackSeconds) ? fallback : {}),total,estimated: video.estimated_duration,shape,@@ -420,15 +444,16 @@ function planVideo(prompt, video, entry) {clips: clips.map(clip => ({ ...clip, prompt: `${prompt}\n\n${clip.prompt}` })),};}- const longest = durations?.[durations.length - 1] ?? fallbackSeconds;+ const longest = durations?.[durations.length - 1];const wanted = video?.estimated_duration === undefined? video?.duration : Math.max(video.estimated_duration, video.duration ?? 0);if (wanted !== undefined && longest && wanted > longest) {- if (!durations) {- throw new Error(`A ${formatSeconds(wanted)} video needs multiple clips with WebBrain's ${longest} s fallback. Published clip lengths are unavailable. Retry with distinct scenes of up to ${longest} s covering the full requested duration, and keep estimated_duration: ${video?.estimated_duration ?? wanted}. WebBrain will generate and join them.`);- }throw new Error(`A ${formatSeconds(wanted)} video needs more than one clip: this model makes clips of up to ${longest} s. Describe it as scenes of up to ${longest} s each, ${MAX_VIDEO_SECONDS} s in total, with estimated_duration.`);}+ if (wanted > MAX_VIDEO_SECONDS) throw new Error(`WebBrain makes videos up to ${MAX_VIDEO_SECONDS} s. Describe a shorter version as scenes and keep estimated_duration: ${wanted} so WebBrain can ask before generating it.`);+ if (fallbackSeconds !== undefined && wanted > fallbackSeconds) {+ throw new Error(`A ${formatSeconds(wanted)} video needs multiple clips with WebBrain's ${fallbackSeconds} s fallback. Published clip lengths are unavailable. Retry with distinct scenes covering the full requested duration, using ${fallbackSeconds} s per scene as a starting point, and keep estimated_duration: ${video?.estimated_duration ?? wanted}. WebBrain will generate and join them.`);+ }if (video?.duration !== undefined && video?.estimated_duration !== undefined && video.duration < video.estimated_duration) {throw new Error(`The requested video needs ${video.estimated_duration} s, but duration specifies only ${video.duration} s. Increase the clip duration or describe the full video as scenes before generating.`);}@@ -439,8 +464,9 @@ function planVideo(prompt, video, entry) {throw new Error(`This video model does not make ${video.duration} s clips. Supported: ${durations.join(', ')} s.`);}duration = video.duration;+ clipLength(entry, { duration });} else if (wanted !== undefined) {- duration = durations?.find(value => value >= wanted) ?? longest;+ duration = durations?.find(value => value >= wanted) ?? fallbackSeconds;}return { scenes: false, shape, ...(duration !== undefined ? fallback : {}), clips: [{ prompt, ...(duration !== undefined ? { duration } : {}) }] };}diff --git a/src/firefox/src/agent/generative-media.js b/src/firefox/src/agent/generative-media.jsindex 343482ba4..03678f50f 100644--- a/src/firefox/src/agent/generative-media.js+++ b/src/firefox/src/agent/generative-media.js@@ -342,11 +342,13 @@ export function videoInputCapabilities(openapi) {if (defaultSeconds !== undefined) break;}if (defaultSeconds !== undefined) entry.default_duration = defaultSeconds;- const admitsType = (form, allowed) => form.every(schema => schema.type === undefined- || [].concat(schema.type).some(type => allowed.includes(type)));- const stringOnly = durationForms.some(form => admitsType(form, ['string']))- && !durationForms.some(form => admitsType(form, ['integer', 'number']));- entry.encodeDuration = seconds => seconds === defaultSeconds ? defaultValue : stringOnly ? String(seconds) : seconds;+ entry.encodeDuration = seconds => {+ const candidates = seconds === defaultSeconds ? [defaultValue, seconds, String(seconds)] : [seconds, String(seconds)];+ // A missing type does not justify converting to text to evade numeric bounds.+ return candidates.find(value => durationForms.some(form => formAllows(form, value)+ && (typeof value !== 'string' || value === defaultValue+ || form.some(schema => [].concat(schema.type ?? []).includes('string')))));+ };}const aspectRatios = listed('aspect_ratio');if (aspectRatios) entry.supported_aspect_ratios = aspectRatios;@@ -358,7 +360,26 @@ export function videoInputCapabilities(openapi) {// A clip's length as the model takes it, ready to merge into its request.function clipLength(entry, clip) {if (clip.duration === undefined || (entry?.inputs && !entry.inputs.includes('duration'))) return {};- return { duration: entry?.encodeDuration ? entry.encodeDuration(clip.duration) : clip.duration };+ const duration = entry?.encodeDuration ? entry.encodeDuration(clip.duration) : clip.duration;+ if (duration === undefined) throw new Error(`This video model's published duration constraints do not allow a ${clip.duration} s clip. Choose a supported duration.`);+ return { duration };+}++// Unbounded schemas can still have a minimum or step size. Choose whole seconds+// that satisfy those constraints without turning the fallback into a maximum.+function nextVideoDuration(entry, minimum) {+ for (let seconds = Math.ceil(minimum); seconds <= MAX_VIDEO_SECONDS; seconds++) {+ if (!entry?.encodeDuration || entry.encodeDuration(seconds) !== undefined) return seconds;+ }+ return undefined;+}++function fallbackVideoDuration(entry) {+ const preferred = entry?.default_duration;+ if (preferred > 0 && preferred <= MAX_VIDEO_SECONDS && nextVideoDuration(entry, preferred) === preferred) return preferred;+ const duration = nextVideoDuration(entry, FALLBACK_VIDEO_CLIP_SECONDS) ?? nextVideoDuration(entry, 1);+ if (duration === undefined) throw new Error(`The published duration constraints provide no usable whole-second clip within WebBrain's ${MAX_VIDEO_SECONDS} s limit. Choose a model that accepts a duration within that limit.`);+ return duration;}/**@@ -368,26 +389,26 @@ function clipLength(entry, clip) {* the model would make the same clip twice. Refuses more than `maxSeconds` in* total or `maxClips`.*/-export function planVideoClips(scenes, durations, { maxSeconds = MAX_VIDEO_SECONDS, maxClips = MAX_VIDEO_CLIPS, fallbackSeconds = FALLBACK_VIDEO_CLIP_SECONDS } = {}) {+export function planVideoClips(scenes, durations, { maxSeconds = MAX_VIDEO_SECONDS, maxClips = MAX_VIDEO_CLIPS, fallbackSeconds = FALLBACK_VIDEO_CLIP_SECONDS,+ selectDuration = seconds => seconds ?? fallbackSeconds } = {}) {const lengths = durations?.length ? durations : [fallbackSeconds];const longest = lengths[lengths.length - 1];const clips = scenes.map((scene, index) => {const prompt = String(scene?.prompt || '').trim();if (!prompt) throw new Error(`Scene ${index + 1} needs a prompt.`);- if (scene.duration > longest) {- if (!durations?.length) {- throw new Error(`Scene ${index + 1} is ${scene.duration} s. Published clip lengths are unavailable, so WebBrain is using ${longest} s as a fallback, not a confirmed model limit. Retry with distinct scenes of up to ${longest} s that cover the full requested duration; WebBrain will generate and join them.`);- }+ if (durations?.length && scene.duration > longest) {throw new Error(`Scene ${index + 1} is ${scene.duration} s, and this model makes clips of up to ${longest} s. Split it into scenes of up to ${longest} s, each with its own prompt for its part, so no clip repeats another.`);}- return { prompt, duration: lengths.find(value => value >= scene.duration) ?? longest };+ const duration = durations?.length ? lengths.find(value => value >= scene.duration) ?? longest : selectDuration(scene.duration);+ if (duration === undefined) throw new Error(`Scene ${index + 1} has no supported whole-second duration within WebBrain's ${maxSeconds} s limit. Shorten the scene or choose another video model.`);+ return { prompt, duration };});const total = clips.reduce((sum, clip) => sum + clip.duration, 0);if (clips.length > maxClips) {throw new Error(`These scenes need ${clips.length} clips and WebBrain makes at most ${maxClips}. Use fewer, longer scenes.`);}if (total > maxSeconds) {- throw new Error(`These scenes come to ${total} s with the ${durations?.length ? "model's clip lengths" : 'fallback clip length'} (${lengths.join(', ')} s), and WebBrain makes videos up to ${maxSeconds} s. Shorten or merge scenes.`);+ throw new Error(`These scenes come to ${total} s with the ${durations?.length ? "model's clip lengths" : 'planned clip lengths'} (${[...new Set(clips.map(clip => clip.duration))].join(', ')} s), and WebBrain makes videos up to ${maxSeconds} s. Shorten or merge scenes.`);}return { clips, total };}@@ -396,22 +417,25 @@ export function planVideoClips(scenes, durations, { maxSeconds = MAX_VIDEO_SECON// clips of its scenes.function planVideo(prompt, video, entry) {const durations = clipDurations(entry);- const fallbackSeconds = entry?.default_duration || FALLBACK_VIDEO_CLIP_SECONDS;- const fallback = durations ? {} : { fallbackClipSeconds: fallbackSeconds };const shape = videoShape(entry, video);const scenes = Array.isArray(video?.scenes) ? video.scenes : null;+ const needsFallback = !durations && (scenes?.length || (video?.duration === undefined && video?.estimated_duration !== undefined));+ const fallbackSeconds = needsFallback ? fallbackVideoDuration(entry) : undefined;+ const fallback = fallbackSeconds === undefined ? {} : { fallbackClipSeconds: fallbackSeconds };if (scenes?.length) {if (video.duration !== undefined) throw new Error('With scenes, give each scene its duration instead of duration.');if (video.estimated_duration === undefined) {throw new Error('With scenes, give estimated_duration: how many seconds the requested video needs before fitting it to the 120 s maximum.');}- const { clips, total } = planVideoClips(scenes, durations, { fallbackSeconds });+ const { clips, total } = planVideoClips(scenes, durations, {+ fallbackSeconds, selectDuration: seconds => nextVideoDuration(entry, seconds ?? fallbackSeconds),+ });if (video.estimated_duration <= MAX_VIDEO_SECONDS && total < video.estimated_duration) {throw new Error(`These scenes provide ${total} s, but the requested video needs ${video.estimated_duration} s. Add or lengthen scenes to cover the requested duration before generating.`);}return {scenes: true,- ...fallback,+ ...(clips.some(clip => clip.duration === fallbackSeconds) ? fallback : {}),total,estimated: video.estimated_duration,shape,@@ -420,15 +444,16 @@ function planVideo(prompt, video, entry) {clips: clips.map(clip => ({ ...clip, prompt: `${prompt}\n\n${clip.prompt}` })),};}- const longest = durations?.[durations.length - 1] ?? fallbackSeconds;+ const longest = durations?.[durations.length - 1];const wanted = video?.estimated_duration === undefined? video?.duration : Math.max(video.estimated_duration, video.duration ?? 0);if (wanted !== undefined && longest && wanted > longest) {- if (!durations) {- throw new Error(`A ${formatSeconds(wanted)} video needs multiple clips with WebBrain's ${longest} s fallback. Published clip lengths are unavailable. Retry with distinct scenes of up to ${longest} s covering the full requested duration, and keep estimated_duration: ${video?.estimated_duration ?? wanted}. WebBrain will generate and join them.`);- }throw new Error(`A ${formatSeconds(wanted)} video needs more than one clip: this model makes clips of up to ${longest} s. Describe it as scenes of up to ${longest} s each, ${MAX_VIDEO_SECONDS} s in total, with estimated_duration.`);}+ if (wanted > MAX_VIDEO_SECONDS) throw new Error(`WebBrain makes videos up to ${MAX_VIDEO_SECONDS} s. Describe a shorter version as scenes and keep estimated_duration: ${wanted} so WebBrain can ask before generating it.`);+ if (fallbackSeconds !== undefined && wanted > fallbackSeconds) {+ throw new Error(`A ${formatSeconds(wanted)} video needs multiple clips with WebBrain's ${fallbackSeconds} s fallback. Published clip lengths are unavailable. Retry with distinct scenes covering the full requested duration, using ${fallbackSeconds} s per scene as a starting point, and keep estimated_duration: ${video?.estimated_duration ?? wanted}. WebBrain will generate and join them.`);+ }if (video?.duration !== undefined && video?.estimated_duration !== undefined && video.duration < video.estimated_duration) {throw new Error(`The requested video needs ${video.estimated_duration} s, but duration specifies only ${video.duration} s. Increase the clip duration or describe the full video as scenes before generating.`);}@@ -439,8 +464,9 @@ function planVideo(prompt, video, entry) {throw new Error(`This video model does not make ${video.duration} s clips. Supported: ${durations.join(', ')} s.`);}duration = video.duration;+ clipLength(entry, { duration });} else if (wanted !== undefined) {- duration = durations?.find(value => value >= wanted) ?? longest;+ duration = durations?.find(value => value >= wanted) ?? fallbackSeconds;}return { scenes: false, shape, ...(duration !== undefined ? fallback : {}), clips: [{ prompt, ...(duration !== undefined ? { duration } : {}) }] };}diff --git a/test/generative-media-fal-schema.mjs b/test/generative-media-fal-schema.mjsindex 75e98d72b..77168be14 100644--- a/test/generative-media-fal-schema.mjs+++ b/test/generative-media-fal-schema.mjs@@ -137,6 +137,95 @@ for (const build of ['chrome', 'firefox']) {assert.equal(mock.calls.submits[0].duration, 8);});+ test(`${build}: fallback lengths and published defaults do not cap explicit clip durations`, async () => {+ for (const [durationSchema, requested] of [+ [null, 15],+ [{ type: 'integer', minimum: 1, default: 5 }, 8],+ [{ type: 'string', default: '5' }, 15],+ ]) {+ const mock = api({+ catalog: () => durationSchema ? listing(schema({ duration: durationSchema })) : json({}, 404),+ direct: () => json({}, 404),+ });+ const result = await run(mock, { video: { duration: requested } });+ assert.deepEqual(mock.calls.submits.map(body => body.duration),+ [durationSchema?.type === 'string' ? String(requested) : requested]);+ assert.equal(result.totalSeconds, requested);+ }+ });++ test(`${build}: automatic fallback lengths satisfy published unbounded duration constraints`, async () => {+ for (const [durationSchema, expected] of [+ [{ type: 'integer', minimum: 10 }, 10],+ [{ minimum: 10 }, 10],+ [{ type: 'integer', minimum: 5, multipleOf: 5 }, 10],+ [{ type: 'integer', exclusiveMinimum: 8 }, 9],+ [{ type: 'integer', minimum: 10, default: 5 }, 10],+ [{ type: 'integer', minimum: 10, default: 15 }, 15],+ [{ type: 'integer', minimum: 10, default: 180 }, 10],+ ]) {+ const mock = api({+ catalog: () => listing(schema({ duration: durationSchema })),+ direct: () => json({}, 404),+ });+ const result = await run(mock, { video: { estimated_duration: 5 } });+ assert.deepEqual(mock.calls.submits.map(body => body.duration), [expected], JSON.stringify(durationSchema));+ assert.equal(result.totalSeconds, expected);+ assert.equal(result.fallbackClipSeconds, expected);+ }+ });++ test(`${build}: explicit durations that violate unbounded schema constraints fail before a paid request`, async () => {+ for (const durationSchema of [+ { type: 'integer', minimum: 10 },+ { minimum: 10 },+ { type: 'integer', minimum: 5, multipleOf: 5 },+ { type: 'integer', exclusiveMinimum: 8 },+ ]) {+ const mock = api({+ catalog: () => listing(schema({ duration: durationSchema })),+ direct: () => json({}, 404),+ });+ await assert.rejects(run(mock, { video: { duration: 8 } }), /duration|length|clip/i);+ assert.equal(mock.calls.submits.length, 0, JSON.stringify(durationSchema));+ }+ });++ test(`${build}: contradictory published duration constraints do not permit an invalid fallback`, async () => {+ const mock = api({+ catalog: () => listing(schema({ duration: { type: 'integer', minimum: 10, maximum: 5 } })),+ direct: () => json({}, 404),+ });+ await assert.rejects(run(mock, { video: { estimated_duration: 5 } }), /duration|length|clip/i);+ assert.equal(mock.calls.submits.length, 0);+ });++ test(`${build}: symbolic-only duration options cannot stand in for requested seconds`, async () => {+ const mock = api({+ catalog: () => listing(schema({ duration: { type: 'string', enum: ['auto'], default: 'auto' } })),+ direct: () => json({}, 404),+ });+ for (const video of [{ estimated_duration: 5 }, { duration: 8 }]) {+ await assert.rejects(run(mock, { video }), /duration|length|clip/i);+ assert.equal(mock.calls.submits.length, 0);+ }+ await run(mock, { media: 'video', video: undefined });+ assert.equal(mock.calls.submits.length, 1, 'a video with no duration obligation may use the provider default');+ assert.equal(Object.hasOwn(mock.calls.submits[0], 'duration'), false);+ });++ test(`${build}: absent metadata does not let explicit clips bypass the two-minute limit`, async () => {+ const mock = api({ catalog: () => json({}, 404), direct: () => json({}, 404) });+ await assert.rejects(run(mock, { video: { duration: 121 } }), /120 s/);+ assert.equal(mock.calls.submits.length, 0);+ });++ test(`${build}: an unspecified long clip still requires distinct scenes when model limits are unknown`, async () => {+ const mock = api({ catalog: () => json({}, 404), direct: () => json({}, 404) });+ await assert.rejects(run(mock, { video: { estimated_duration: 60 } }), /distinct scenes.*estimated_duration: 60/);+ assert.equal(mock.calls.submits.length, 0);+ });+test(`${build}: fal schema authorization failures remain errors`, async () => {for (const status of [401, 403]) {const mock = api({ catalog: () => json({ error: { message: 'Access denied' } }, status) });@@ -201,6 +290,20 @@ for (const build of ['chrome', 'firefox']) {}});+ test(`${build}: Comfy Router honors explicit lengths and constrained automatic fallbacks`, async () => {+ for (const [durationSchema, video, expected] of [+ [null, { duration: 15 }, 15],+ [{ type: 'integer', minimum: 1, default: 5 }, { duration: 15 }, 15],+ [{ type: 'integer', minimum: 10 }, { estimated_duration: 5 }, 10],+ [{ type: 'integer', minimum: 5, multipleOf: 5 }, { estimated_duration: 5 }, 10],+ ]) {+ const mock = comfyApi(() => durationSchema ? json(schema({ duration: durationSchema })) : json({}, 404));+ const result = await run(mock, { config: comfyConfig, video });+ assert.deepEqual(mock.calls.submits.map(body => body.duration), [expected], JSON.stringify(durationSchema));+ assert.equal(result.totalSeconds, expected);+ }+ });+test(`${build}: Comfy Router metadata authorization and cancellation still stop generation`, async () => {for (const status of [401, 403]) {const mock = comfyApi(() => json({ error: { message: 'Access denied' } }, status));diff --git a/test/generative-media-video.mjs b/test/generative-media-video.mjsindex 459be03d3..442f49142 100644--- a/test/generative-media-video.mjs+++ b/test/generative-media-video.mjs@@ -549,9 +549,10 @@ for (const build of ['chrome', 'firefox']) {assert.throws(() => media.planVideoClips(scenes(9, 15), grok.supported_durations), /up to 120 s/);assert.throws(() => media.planVideoClips(scenes(25, 4), grok.supported_durations), /at most 24/);assert.deepEqual(media.planVideoClips(scenes(2, 5), null), {- clips: scenes(2, 8), total: 16,+ clips: scenes(2, 5), total: 10,});- assert.throws(() => media.planVideoClips(scenes(4, 15), null), /8 s as a fallback, not a confirmed model limit.*Retry with distinct scenes/);+ assert.deepEqual(media.planVideoClips(scenes(4, 15), null), { clips: scenes(4, 15), total: 60 });+ assert.throws(() => media.planVideoClips(scenes(9, 15), null), /up to 120 s/);assert.throws(() => media.planVideoClips([{ prompt: ' ', duration: 5 }], [5]), /Scene 1 needs a prompt/);});@@ -850,6 +851,24 @@ for (const build of ['chrome', 'firefox']) {assert.deepEqual(rejected.calls.downloads, []);});+ test(`${build}: explicit scenes exceed fallback lengths and still respect unbounded constraints`, async () => {+ for (const [duration, requested, expected] of [+ [undefined, 15, 15],+ [{ type: 'integer', minimum: 1, default: 5 }, 15, 15],+ [{ type: 'integer', minimum: 10 }, 5, 10],+ [{ type: 'integer', minimum: 5, multipleOf: 5 }, 8, 10],+ ]) {+ const model = { id: 'provider/video', schema: duration ? falSchema({ duration }) : null };+ const api = falApi({ model: model.id, schema: model.schema });+ const result = await generate({ prompt: 'Story', scenes: scenes(4, requested), estimated_duration: requested * 4 },+ { config: falConfig(model), fetchImpl: api.fetchImpl, pollIntervalMs: 1 });+ assert.equal(result.success, true, result.error);+ assert.deepEqual(api.calls.submits.map(body => body.duration), Array(4).fill(expected));+ assert.equal(result.plannedSeconds, expected * 4);+ assert.equal(result.estimatedSeconds, requested * 4);+ }+ });+test(`${build}: Comfy Router scenes take each clip's length over the saved model input`, async () => {const api = comfyRouterApi({ model: rayTwo.id, schema: rayTwo.schema, clip: index => fixtures[index ? 'h264-aac-2' : 'h264-aac-1'] });const config = { provider: 'comfyrouter', apiKey: 'comfy-key', model: 'bfl/flux-2-pro', videoModel: rayTwo.id,diff --git a/test/video-duration-contract.mjs b/test/video-duration-contract.mjsindex 84763b3da..a56ae7ee5 100644--- a/test/video-duration-contract.mjs+++ b/test/video-duration-contract.mjs@@ -63,13 +63,17 @@ for (const build of ['chrome', 'firefox']) {assert.equal(pin({ media: 'video', video_id: 'explainer', estimated_duration: 5 }, approved).args.estimated_duration, 120);});- test(`${build}: actual trace retry never dispatches a default short paid clip`, async () => {+ test(`${build}: a rejected scene generation cannot retry as a default short paid clip`, async () => {const { agent, tab, guard } = fixture();const originalFetch = globalThis.fetch;let submits = 0, saved = 0;agent._persistNow = async () => { saved++; return { ok: true }; };globalThis.fetch = async (url, init = {}) => {- if (init.method === 'POST') { submits++; assert.fail('A target-losing retry must not submit a paid clip'); }+ if (init.method === 'POST') {+ submits++;+ assert.equal(JSON.parse(init.body).duration, 15, 'only the original full scene plan may be submitted');+ return new Response(JSON.stringify({ error: 'Fixture provider rejected this clip length.' }), { status: 422 });+ }if (url.startsWith('https://api.fal.ai/')) return json({ models: [] });assert.ok(url.startsWith('https://fal.ai/api/openapi/queue/openapi.json'));return json({});@@ -82,14 +86,16 @@ for (const build of ['chrome', 'firefox']) {}, () => {}, context);assert.equal(first.success, false);assert.equal(guard.videoDurationContract.requestedSeconds, 60);- assert.match(first.error, /8 s/);+ assert.match(first.error, /422/);+ const firstSubmits = submits;+ assert.ok(firstSubmits > 0, 'missing metadata no longer prevents the explicit scene plan');for (const retry of [{ prompt: 'Explain the Minkowski sum.' }, { media: 'video', prompt: 'Explain the Minkowski sum.' },{ media: 'video', prompt: 'Explain it.', duration: 5, estimated_duration: 5 }]) {const result = await agent._executeToolImpl(tab, 'generate_image', retry, () => {}, context);assert.equal(result.success, false);- assert.match(result.error, /estimated_duration: 60/);+ assert.match(result.error, /estimated_duration: 60|requested video needs 60 s/);}- assert.equal(submits, 0);+ assert.equal(submits, firstSubmits, 'target-losing retries never submit another paid clip');assert.equal(saved, 8, 'save target before each attempt and its result afterward');} finally { globalThis.fetch = originalFetch; }});