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
long video generation fix
Codex release-state test8ffafb4b41ec
diff --git a/docs/providers-and-models.md b/docs/providers-and-models.mdindex 3fc64fdc3..df3779f40 100644--- a/docs/providers-and-models.md+++ b/docs/providers-and-models.md@@ -346,8 +346,16 @@ unattended run generates nothing. Clips that cannot be joined this way(different encodings, edit lists or timing the joined file cannot reproduce, ormore than 160 MB together) are kept as separate clips and shown in order, andthe tool result says why (`joinError`), which traces show. The model never sees-the video, so the tool result gives it the video's real length-(`durationSeconds`) and `clipCount` to report. Before writing scenes, the agent can load the default Video scenes+the video, so the tool result gives it the video's measured length+(`durationSeconds`) and `clipCount` when available. Plans that knowingly fall+short of `estimated_duration` within the 120-second cap are rejected before+submission; missing clip-length metadata must not silently fall back to a+default short clip. Results retain the original estimate (`estimatedSeconds`),+accepted plan (`plannedSeconds`), and `durationStatus`: `short`, `enough`,+or `unverified`. A measured shortfall keeps the generated asset and reports+incomplete delivery; hosted clips without a measured length stay unverified.+These fields guide reporting, not a hard block on the agent's `done` call.+Before writing scenes, the agent can load the default Video scenesskill (`skills/video-scenes.md`), which asks for a shared cast and set sheet in`prompt`, one filmable action per scene, and demonstrations instead of diagramsor on-screen text; it is loaded only for such videos.diff --git a/src/chrome/skills/video-scenes.md b/src/chrome/skills/video-scenes.mdindex 0e6c1bc69..abde7593a 100644--- a/src/chrome/skills/video-scenes.md+++ b/src/chrome/skills/video-scenes.md@@ -10,6 +10,8 @@Use this skill before calling `generate_image` with `scenes`. The video model makes each scene as a separate clip from its text alone, without seeing the other clips; WebBrain then joins the clips into one video.+Keep the user's full requested length in `estimated_duration`. A 60-second video can use four 15-second scenes when the model supports that clip length. The per-clip limit does not limit the whole video, and no separate joining tool is needed. If WebBrain cannot read supported clip lengths, report that capability lookup problem without replacing the requested video with one short default clip.+## The shared prompt`prompt` is repeated in front of every scene, so it is the only thing the clips share. Anything it leaves open will change from clip to clip. Write it as a short cast and set sheet:diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex b781adfce..f0bb7f210 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -43436,9 +43436,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (result?.success && result?.provider && (result.inlineMedia || /^data:(image|video|audio)\//.test(result.url || ''))) {const clips = Array.isArray(result.clips)? result.clips.map(({ mediaId: _mediaId, ...clip }) => clip) : undefined;- const note = 'Generated media is displayed in the chat with a save link. Tell the user it is ready. You have not seen it: '+ const note = 'Generated media is displayed in the chat with a save link. Report the generated asset and any remaining duration or joining problem. You have not seen it: '+ 'describe it only by what you asked for and by its durationSeconds and clipCount when present, never by its contents; '+ 'do not invent a hosted URL.'+ + (result.notice ? ` ${result.notice}` : '')+ (result.joined === false ? ' Its clips could not be joined into one file, so the chat shows them one after another.' : '');result = { ...result, url: undefined, mediaId: undefined, clips, inlineMedia: true, note };}diff --git a/src/chrome/src/agent/generative-media.js b/src/chrome/src/agent/generative-media.jsindex 24f7b8fe1..7aa131900 100644--- a/src/chrome/src/agent/generative-media.js+++ b/src/chrome/src/agent/generative-media.js@@ -344,7 +344,7 @@ function clipLength(entry, clip) {*/export function planVideoClips(scenes, durations, { maxSeconds = MAX_VIDEO_SECONDS, maxClips = MAX_VIDEO_CLIPS } = {}) {if (!durations?.length) {- throw new Error('This video model does not list the clip lengths it supports, so WebBrain cannot make a video from scenes with it. Generate one clip instead.');+ throw new Error('This video model does not list the clip lengths it supports. WebBrain can join scene clips, but cannot determine their supported lengths from this model\'s schema. No clips were generated; use a video model with published clip lengths to make the requested video.');}const longest = durations[durations.length - 1];const clips = scenes.map((scene, index) => {@@ -377,6 +377,9 @@ function planVideo(prompt, video, entry) {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);+ 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,total,@@ -388,10 +391,17 @@ function planVideo(prompt, video, entry) {};}const longest = durations?.[durations.length - 1];- const wanted = video?.duration ?? video?.estimated_duration;+ const wanted = video?.estimated_duration === undefined+ ? video?.duration : Math.max(video.estimated_duration, video.duration ?? 0);if (wanted !== undefined && longest && wanted > longest) {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 (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.`);+ }+ if (video?.estimated_duration !== undefined && video?.duration === undefined && !durations) {+ throw new Error(`WebBrain cannot determine a supported clip length for the requested ${video.estimated_duration} s video from this model's schema. No clip was generated; use a video model with published clip lengths or supply a supported duration explicitly.`);+ }let duration;if (video?.duration !== undefined) {if (entry?.inputs && !entry.inputs.includes('duration')) throw new Error('This video model does not take duration.');@@ -505,7 +515,11 @@ async function mapWithConcurrency(items, limit, signal, task) {*/async function runVideo({ model, entry, text, video, signal, onProgress, confirmVideoLength, single, clip }) {const plan = planVideo(text, video, entry);- if (!plan.scenes) return { ...(await single(plan.clips[0], plan.shape)), model };+ if (!plan.scenes) return {+ ...(await single(plan.clips[0], plan.shape)), model,+ ...(video?.estimated_duration !== undefined ? { estimatedSeconds: video.estimated_duration } : {}),+ ...(plan.clips[0].duration !== undefined ? { totalSeconds: plan.clips[0].duration } : {}),+ };// The user decides on the card whether a shorter version is worth// generating, before anything is submitted. The card is outside the@@ -738,6 +752,28 @@ export async function readMediaConfig() {const roundSeconds = seconds => (Number.isFinite(seconds) && seconds > 0 ? Math.round(seconds * 10) / 10 : undefined);+// Keep the declared target, accepted plan and measured output distinct. Paid+// assets remain successful results even if the provider delivered too little;+// the agent must report the shortfall instead of calling the whole task ready.+function videoDeliveryDetails(result, asset) {+ const plannedSeconds = roundSeconds(result.totalSeconds);+ if (!plannedSeconds) return {};+ const actual = asset.durationSeconds;+ // Allow a quarter second for container/frame boundary rounding.+ const durationStatus = Number.isFinite(actual)+ ? (actual + 0.25 < plannedSeconds ? 'short' : 'enough') : 'unverified';+ return {+ estimatedSeconds: roundSeconds(result.estimatedSeconds) || plannedSeconds,+ plannedSeconds,+ durationStatus,+ ...(durationStatus === 'short' ? {+ notice: `Generated ${actual} s of the planned ${plannedSeconds} s. Keep the generated asset, but report the duration shortfall; the requested video is incomplete. Do not claim it is complete.`,+ } : durationStatus === 'unverified' ? {+ notice: 'The output duration has not been measured. Do not report plannedSeconds as the actual video length.',+ } : {}),+ };+}+function declinedVideoMessage({ answer, estimatedSeconds, totalSeconds }) {const length = `The video needs about ${formatSeconds(estimatedSeconds)}, and WebBrain makes videos up to ${formatSeconds(MAX_VIDEO_SECONDS)}`;if (answer === 'deny') return `${length}. The user chose not to generate the ${formatSeconds(totalSeconds)} version, so nothing was generated. Ask what they would like instead.`;@@ -792,16 +828,19 @@ export async function generateImage(args, options = {}) {return { success: false, declined: true, provider, model: result.model, error: declinedVideoMessage(result) };}if (Array.isArray(result.clips)) {- return { success: true, model: result.model, provider, ...(await storeVideoClips(result.clips, options.onProgress)) };+ const asset = await storeVideoClips(result.clips, options.onProgress);+ return { success: true, model: result.model, provider, ...asset, ...videoDeliveryDetails(result, asset) };}if (result.url.startsWith('data:')) {const asset = await storeGeneratedMedia(result.url);// A clip's real length, so the agent can say how long the video is.const video = asset.mimeType === 'video/mp4' ? dataUrlBytes(result.url) : null;const durationSeconds = video ? roundSeconds(mp4DurationSeconds(video.bytes)) : undefined;- return { success: true, model: result.model, provider, ...asset, ...(durationSeconds ? { durationSeconds } : {}) };+ const delivered = { ...asset, ...(durationSeconds ? { durationSeconds } : {}) };+ return { success: true, model: result.model, provider, ...delivered, ...videoDeliveryDetails(result, delivered) };}- return { success: true, ...result, provider };+ const { estimatedSeconds, totalSeconds, ...hosted } = result;+ return { success: true, ...hosted, provider, ...videoDeliveryDetails(result, hosted) };} catch (error) { return { success: false, error: error.message }; }}diff --git a/src/chrome/src/agent/tools.js b/src/chrome/src/agent/tools.jsindex eb45bf407..f8f573f72 100644--- a/src/chrome/src/agent/tools.js+++ b/src/chrome/src/agent/tools.js@@ -36,7 +36,8 @@ const DONE_REQUIRED_WITH_OUTCOME = ['summary', 'outcome'];export const SYSTEM_PROMPT_GENERATIVE_MEDIA = `GENERATIVE MEDIA:- generate_image: Create an image, or with media "video" a video, directly from a text prompt through the user's configured image and video models. When the user asks to GENERATE media ("generate an image of a red apple", "make a logo", "create a video clip"), call this tool — do NOT navigate to third-party image sites (Midjourney, DALL·E, Bing Images, etc.). Not available in Ask mode.-- Videos: set media to "video" and estimate how long the requested video should run. One that needs more than one clip (an explainer, a story) is one call with scenes, at most 120 s in total, and estimated_duration set to the full length it needs; WebBrain joins the clips into one video and asks the user first when that estimate is longer than 120 s. You never see the result: report its length and clip count from the tool result, not its contents.`;+- Videos: set media to "video" and estimate how long the requested video should run. One that needs more than one clip (an explainer, a story) is one call with scenes, at most 120 s in total, and estimated_duration set to the full length it needs; WebBrain joins the clips into one video and asks the user first when that estimate is longer than 120 s. You never see the result: report its length and clip count from the tool result, not its contents.+- A model's clip limit applies to each scene. Joining is built into generate_image; no separate joining tool is needed. For a one-minute request keep estimated_duration:60 and plan scenes covering 60 seconds, for example four 15-second scenes when supported. If a scene exceeds the reported clip limit, split it into distinct scenes and retry. Missing clip-length metadata is a capability lookup problem: do not claim the model cannot make scenes or substitute a shorter default clip. Report any durationStatus "short" or joined:false result as incomplete, preserving the generated assets.`;export const SYSTEM_PROMPT_BATCHING = `BATCHING:- Use browser_batch for predictable steps on the current page with targets you already observed, such as filling known fields or opening a menu and choosing a known item. A navigation followed by a page read can also share one batch.@@ -1494,13 +1495,13 @@ export const AGENT_TOOLS = [properties: {prompt: { type: 'string', description: 'Text prompt describing the media to generate. With scenes: the look, subject and style every clip shares.' },media: { type: 'string', enum: ['image', 'video'], description: '"image" (default) uses the image model; "video" uses the video model. The video options below imply "video".' },- estimated_duration: { type: 'integer', minimum: 1, description: 'Video only: seconds the requested video needs, estimated before fitting it to the 120 s maximum. Required with scenes.' },+ estimated_duration: { type: 'integer', minimum: 1, description: 'Video only: full seconds the user requested, or an estimate when unspecified, before fitting it to the 120 s maximum. Keep this target when retrying; never replace it with the per-clip limit. Required with scenes.' },duration: { type: 'integer', minimum: 1, description: 'Video only: seconds for a single clip.' },aspect_ratio: { type: 'string', description: 'Video only, for example "16:9" or "9:16".' },resolution: { type: 'string', description: 'Video only, for example "720p".' },scenes: {type: 'array',- description: 'Video only: the scenes of a video longer than one clip, in order, at most 120 seconds in total. Load the video-scenes skill first when it is listed.',+ description: 'Video only: scenes in order covering the requested duration, at most 120 seconds in total. This tool generates and joins the clips automatically; no separate join tool is needed. Load the video-scenes skill first when it is listed.',items: {type: 'object',properties: {diff --git a/src/chrome/src/run-ui-journal.js b/src/chrome/src/run-ui-journal.jsindex f01795778..2b41254e3 100644--- a/src/chrome/src/run-ui-journal.js+++ b/src/chrome/src/run-ui-journal.js@@ -101,9 +101,10 @@ function compactRunUiToolResult(result, name) {if (typeof source[key] === 'string') compacted[key] = source[key];}if (source.inlineMedia === true) compacted.inlineMedia = true;- for (const key of ['durationSeconds', 'clipCount']) {+ for (const key of ['durationSeconds', 'clipCount', 'estimatedSeconds', 'plannedSeconds']) {if (Number.isFinite(source[key])) compacted[key] = source[key];}+ if (['short', 'enough', 'unverified'].includes(source.durationStatus)) compacted.durationStatus = source.durationStatus;// Clips of a video that could not be joined into one file, shown in order.if (source.joined === false && Array.isArray(source.clips)) {compacted.joined = false;diff --git a/src/firefox/skills/video-scenes.md b/src/firefox/skills/video-scenes.mdindex 0e6c1bc69..abde7593a 100644--- a/src/firefox/skills/video-scenes.md+++ b/src/firefox/skills/video-scenes.md@@ -10,6 +10,8 @@Use this skill before calling `generate_image` with `scenes`. The video model makes each scene as a separate clip from its text alone, without seeing the other clips; WebBrain then joins the clips into one video.+Keep the user's full requested length in `estimated_duration`. A 60-second video can use four 15-second scenes when the model supports that clip length. The per-clip limit does not limit the whole video, and no separate joining tool is needed. If WebBrain cannot read supported clip lengths, report that capability lookup problem without replacing the requested video with one short default clip.+## The shared prompt`prompt` is repeated in front of every scene, so it is the only thing the clips share. Anything it leaves open will change from clip to clip. Write it as a short cast and set sheet:diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex a5173da88..dc8d55654 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -39912,9 +39912,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (result?.success && result?.provider && (result.inlineMedia || /^data:(image|video|audio)\//.test(result.url || ''))) {const clips = Array.isArray(result.clips)? result.clips.map(({ mediaId: _mediaId, ...clip }) => clip) : undefined;- const note = 'Generated media is displayed in the chat with a save link. Tell the user it is ready. You have not seen it: '+ const note = 'Generated media is displayed in the chat with a save link. Report the generated asset and any remaining duration or joining problem. You have not seen it: '+ 'describe it only by what you asked for and by its durationSeconds and clipCount when present, never by its contents; '+ 'do not invent a hosted URL.'+ + (result.notice ? ` ${result.notice}` : '')+ (result.joined === false ? ' Its clips could not be joined into one file, so the chat shows them one after another.' : '');result = { ...result, url: undefined, mediaId: undefined, clips, inlineMedia: true, note };}diff --git a/src/firefox/src/agent/generative-media.js b/src/firefox/src/agent/generative-media.jsindex 24f7b8fe1..7aa131900 100644--- a/src/firefox/src/agent/generative-media.js+++ b/src/firefox/src/agent/generative-media.js@@ -344,7 +344,7 @@ function clipLength(entry, clip) {*/export function planVideoClips(scenes, durations, { maxSeconds = MAX_VIDEO_SECONDS, maxClips = MAX_VIDEO_CLIPS } = {}) {if (!durations?.length) {- throw new Error('This video model does not list the clip lengths it supports, so WebBrain cannot make a video from scenes with it. Generate one clip instead.');+ throw new Error('This video model does not list the clip lengths it supports. WebBrain can join scene clips, but cannot determine their supported lengths from this model\'s schema. No clips were generated; use a video model with published clip lengths to make the requested video.');}const longest = durations[durations.length - 1];const clips = scenes.map((scene, index) => {@@ -377,6 +377,9 @@ function planVideo(prompt, video, entry) {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);+ 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,total,@@ -388,10 +391,17 @@ function planVideo(prompt, video, entry) {};}const longest = durations?.[durations.length - 1];- const wanted = video?.duration ?? video?.estimated_duration;+ const wanted = video?.estimated_duration === undefined+ ? video?.duration : Math.max(video.estimated_duration, video.duration ?? 0);if (wanted !== undefined && longest && wanted > longest) {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 (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.`);+ }+ if (video?.estimated_duration !== undefined && video?.duration === undefined && !durations) {+ throw new Error(`WebBrain cannot determine a supported clip length for the requested ${video.estimated_duration} s video from this model's schema. No clip was generated; use a video model with published clip lengths or supply a supported duration explicitly.`);+ }let duration;if (video?.duration !== undefined) {if (entry?.inputs && !entry.inputs.includes('duration')) throw new Error('This video model does not take duration.');@@ -505,7 +515,11 @@ async function mapWithConcurrency(items, limit, signal, task) {*/async function runVideo({ model, entry, text, video, signal, onProgress, confirmVideoLength, single, clip }) {const plan = planVideo(text, video, entry);- if (!plan.scenes) return { ...(await single(plan.clips[0], plan.shape)), model };+ if (!plan.scenes) return {+ ...(await single(plan.clips[0], plan.shape)), model,+ ...(video?.estimated_duration !== undefined ? { estimatedSeconds: video.estimated_duration } : {}),+ ...(plan.clips[0].duration !== undefined ? { totalSeconds: plan.clips[0].duration } : {}),+ };// The user decides on the card whether a shorter version is worth// generating, before anything is submitted. The card is outside the@@ -738,6 +752,28 @@ export async function readMediaConfig() {const roundSeconds = seconds => (Number.isFinite(seconds) && seconds > 0 ? Math.round(seconds * 10) / 10 : undefined);+// Keep the declared target, accepted plan and measured output distinct. Paid+// assets remain successful results even if the provider delivered too little;+// the agent must report the shortfall instead of calling the whole task ready.+function videoDeliveryDetails(result, asset) {+ const plannedSeconds = roundSeconds(result.totalSeconds);+ if (!plannedSeconds) return {};+ const actual = asset.durationSeconds;+ // Allow a quarter second for container/frame boundary rounding.+ const durationStatus = Number.isFinite(actual)+ ? (actual + 0.25 < plannedSeconds ? 'short' : 'enough') : 'unverified';+ return {+ estimatedSeconds: roundSeconds(result.estimatedSeconds) || plannedSeconds,+ plannedSeconds,+ durationStatus,+ ...(durationStatus === 'short' ? {+ notice: `Generated ${actual} s of the planned ${plannedSeconds} s. Keep the generated asset, but report the duration shortfall; the requested video is incomplete. Do not claim it is complete.`,+ } : durationStatus === 'unverified' ? {+ notice: 'The output duration has not been measured. Do not report plannedSeconds as the actual video length.',+ } : {}),+ };+}+function declinedVideoMessage({ answer, estimatedSeconds, totalSeconds }) {const length = `The video needs about ${formatSeconds(estimatedSeconds)}, and WebBrain makes videos up to ${formatSeconds(MAX_VIDEO_SECONDS)}`;if (answer === 'deny') return `${length}. The user chose not to generate the ${formatSeconds(totalSeconds)} version, so nothing was generated. Ask what they would like instead.`;@@ -792,16 +828,19 @@ export async function generateImage(args, options = {}) {return { success: false, declined: true, provider, model: result.model, error: declinedVideoMessage(result) };}if (Array.isArray(result.clips)) {- return { success: true, model: result.model, provider, ...(await storeVideoClips(result.clips, options.onProgress)) };+ const asset = await storeVideoClips(result.clips, options.onProgress);+ return { success: true, model: result.model, provider, ...asset, ...videoDeliveryDetails(result, asset) };}if (result.url.startsWith('data:')) {const asset = await storeGeneratedMedia(result.url);// A clip's real length, so the agent can say how long the video is.const video = asset.mimeType === 'video/mp4' ? dataUrlBytes(result.url) : null;const durationSeconds = video ? roundSeconds(mp4DurationSeconds(video.bytes)) : undefined;- return { success: true, model: result.model, provider, ...asset, ...(durationSeconds ? { durationSeconds } : {}) };+ const delivered = { ...asset, ...(durationSeconds ? { durationSeconds } : {}) };+ return { success: true, model: result.model, provider, ...delivered, ...videoDeliveryDetails(result, delivered) };}- return { success: true, ...result, provider };+ const { estimatedSeconds, totalSeconds, ...hosted } = result;+ return { success: true, ...hosted, provider, ...videoDeliveryDetails(result, hosted) };} catch (error) { return { success: false, error: error.message }; }}diff --git a/src/firefox/src/agent/tools.js b/src/firefox/src/agent/tools.jsindex 41efc0213..35a78cec0 100644--- a/src/firefox/src/agent/tools.js+++ b/src/firefox/src/agent/tools.js@@ -36,7 +36,8 @@ const DONE_REQUIRED_WITH_OUTCOME = ['summary', 'outcome'];export const SYSTEM_PROMPT_GENERATIVE_MEDIA = `GENERATIVE MEDIA:- generate_image: Create an image, or with media "video" a video, directly from a text prompt through the user's configured image and video models. When the user asks to GENERATE media ("generate an image of a red apple", "make a logo", "create a video clip"), call this tool — do NOT navigate to third-party image sites (Midjourney, DALL·E, Bing Images, etc.). Not available in Ask mode.-- Videos: set media to "video" and estimate how long the requested video should run. One that needs more than one clip (an explainer, a story) is one call with scenes, at most 120 s in total, and estimated_duration set to the full length it needs; WebBrain joins the clips into one video and asks the user first when that estimate is longer than 120 s. You never see the result: report its length and clip count from the tool result, not its contents.`;+- Videos: set media to "video" and estimate how long the requested video should run. One that needs more than one clip (an explainer, a story) is one call with scenes, at most 120 s in total, and estimated_duration set to the full length it needs; WebBrain joins the clips into one video and asks the user first when that estimate is longer than 120 s. You never see the result: report its length and clip count from the tool result, not its contents.+- A model's clip limit applies to each scene. Joining is built into generate_image; no separate joining tool is needed. For a one-minute request keep estimated_duration:60 and plan scenes covering 60 seconds, for example four 15-second scenes when supported. If a scene exceeds the reported clip limit, split it into distinct scenes and retry. Missing clip-length metadata is a capability lookup problem: do not claim the model cannot make scenes or substitute a shorter default clip. Report any durationStatus "short" or joined:false result as incomplete, preserving the generated assets.`;export const SYSTEM_PROMPT_BATCHING = `BATCHING:- Use browser_batch for predictable steps on the current page with targets you already observed, such as filling known fields or opening a menu and choosing a known item. A navigation followed by a page read can also share one batch.@@ -1349,13 +1350,13 @@ export const AGENT_TOOLS = [properties: {prompt: { type: 'string', description: 'Text prompt describing the media to generate. With scenes: the look, subject and style every clip shares.' },media: { type: 'string', enum: ['image', 'video'], description: '"image" (default) uses the image model; "video" uses the video model. The video options below imply "video".' },- estimated_duration: { type: 'integer', minimum: 1, description: 'Video only: seconds the requested video needs, estimated before fitting it to the 120 s maximum. Required with scenes.' },+ estimated_duration: { type: 'integer', minimum: 1, description: 'Video only: full seconds the user requested, or an estimate when unspecified, before fitting it to the 120 s maximum. Keep this target when retrying; never replace it with the per-clip limit. Required with scenes.' },duration: { type: 'integer', minimum: 1, description: 'Video only: seconds for a single clip.' },aspect_ratio: { type: 'string', description: 'Video only, for example "16:9" or "9:16".' },resolution: { type: 'string', description: 'Video only, for example "720p".' },scenes: {type: 'array',- description: 'Video only: the scenes of a video longer than one clip, in order, at most 120 seconds in total. Load the video-scenes skill first when it is listed.',+ description: 'Video only: scenes in order covering the requested duration, at most 120 seconds in total. This tool generates and joins the clips automatically; no separate join tool is needed. Load the video-scenes skill first when it is listed.',items: {type: 'object',properties: {diff --git a/src/firefox/src/run-ui-journal.js b/src/firefox/src/run-ui-journal.jsindex f01795778..2b41254e3 100644--- a/src/firefox/src/run-ui-journal.js+++ b/src/firefox/src/run-ui-journal.js@@ -101,9 +101,10 @@ function compactRunUiToolResult(result, name) {if (typeof source[key] === 'string') compacted[key] = source[key];}if (source.inlineMedia === true) compacted.inlineMedia = true;- for (const key of ['durationSeconds', 'clipCount']) {+ for (const key of ['durationSeconds', 'clipCount', 'estimatedSeconds', 'plannedSeconds']) {if (Number.isFinite(source[key])) compacted[key] = source[key];}+ if (['short', 'enough', 'unverified'].includes(source.durationStatus)) compacted.durationStatus = source.durationStatus;// Clips of a video that could not be joined into one file, shown in order.if (source.joined === false && Array.isArray(source.clips)) {compacted.joined = false;diff --git a/test/generative-media-video.mjs b/test/generative-media-video.mjsindex f7c31b3ec..4a90a9494 100644--- a/test/generative-media-video.mjs+++ b/test/generative-media-video.mjs@@ -542,7 +542,12 @@ for (const build of ['chrome', 'firefox']) {assert.equal(media.planVideoClips(scenes(8, 15), grok.supported_durations).total, 120);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.throws(() => media.planVideoClips(scenes(2, 5), null), /does not list the clip lengths/);+ assert.throws(() => media.planVideoClips(scenes(2, 5), null), error => {+ assert.match(error.message, /does not list the clip lengths/);+ assert.match(error.message, /WebBrain can join scene clips/);+ assert.doesNotMatch(error.message, /Generate one clip instead/);+ return true;+ });assert.throws(() => media.planVideoClips([{ prompt: ' ', duration: 5 }], [5]), /Scene 1 needs a prompt/);});@@ -586,6 +591,29 @@ for (const build of ['chrome', 'firefox']) {fetchImpl: async url => assert.fail(url) }), /do not work with a local ComfyUI workflow/);});+ test(`${build}: video estimates cannot silently become shorter plans`, async () => {+ const cases = [+ [{ duration: 10, estimated_duration: 60 }, /A 1:00 video needs more than one clip/],+ [{ duration: 8, estimated_duration: 10 }, /requested video needs 10 s, but duration specifies only 8 s/],+ [{ scenes: scenes(1, 10), estimated_duration: 60 }, /scenes provide 10 s, but the requested video needs 60 s/],+ [{ scenes: scenes(7, 15), estimated_duration: 120 }, /scenes provide 105 s, but the requested video needs 120 s/],+ ];+ for (const provider of ['openrouter', 'fal']) for (const [video, pattern] of cases) {+ const api = provider === 'fal' ? falApi({ model: h3Max.id, schema: h3Max.schema }) : videoApi({ entry: grok });+ await assert.rejects(media.runMediaGeneration({ prompt: 'Explainer', video,+ config: provider === 'fal' ? falConfig(h3Max) : config, fetchImpl: api.fetchImpl, pollIntervalMs: 1 }), pattern);+ assert.equal(api.calls.submits.length, 0, `${provider}: a shorter plan spends nothing`);+ }+ for (const provider of ['openrouter', 'fal']) {+ const api = provider === 'fal' ? falApi({ model: h3Max.id, schema: null })+ : videoApi({ entry: { ...grok, supported_durations: undefined } });+ await assert.rejects(media.runMediaGeneration({ prompt: 'Explainer', video: { estimated_duration: 60 },+ config: provider === 'fal' ? falConfig(h3Max) : config, fetchImpl: api.fetchImpl, pollIntervalMs: 1 }),+ /cannot determine a supported clip length for the requested 60 s video/);+ assert.equal(api.calls.submits.length, 0, `${provider}: an unknown length does not use a default clip`);+ }+ });+test(`${build}: a video of two minutes or less generates without asking`, async () => {const api = videoApi({ entry: grok });const progress = [];@@ -632,6 +660,15 @@ for (const build of ['chrome', 'firefox']) {assert.equal(approved.success, true, approved.error);assert.equal(api.calls.submits.length, 8);assert.equal(approved.clipCount, 8);+ // The user's approved shorter version need not fill the entire 120 s cap.+ const shorterApi = videoApi({ entry: grok });+ const shorter = await media.runMediaGeneration({ prompt: 'Explainer', video: { scenes: scenes(6, 15), estimated_duration: 330 },+ config, fetchImpl: shorterApi.fetchImpl, confirmVideoLength: async details => {+ assert.equal(details.totalSeconds, 90);+ return 'once';+ } });+ assert.equal(shorter.clips.length, 6);+ assert.equal(shorterApi.calls.submits.length, 6);const withoutCard = videoApi({ entry: grok });const unasked = await generate({ prompt: 'Explainer', scenes: scenes(8, 15), estimated_duration: 330 }, { fetchImpl: withoutCard.fetchImpl });assert.equal(unasked.declined, true, 'without a card nothing is generated');@@ -1133,6 +1170,58 @@ for (const build of ['chrome', 'firefox']) {} finally { await page.close(); }});+ test(`${build}: video delivery preserves the target and reports measured shortfalls without losing assets`, async () => {+ const api = falApi({ model: h3Max.id, schema: h3Max.schema });+ const result = await generate({+ prompt: 'Consistent cast', media: 'video', scenes: scenes(4, 15), estimated_duration: 60,+ }, { config: falConfig(h3Max), fetchImpl: api.fetchImpl, pollIntervalMs: 1 });+ assert.equal(result.success, true, result.error);+ assert.deepEqual([result.estimatedSeconds, result.plannedSeconds, result.durationSeconds, result.durationStatus],+ [60, 60, 4, 'short'], 'provider fixtures return only one second per requested 15-second clip');+ assert.equal(api.calls.submits.length, 4, 'no extra paid generation to repair the shortfall');+ assert.ok((await storedBytes(result.mediaId)).length, 'the generated asset is still downloadable');+ const agent = new Agent({ getActive: () => chatProvider });+ const forModel = JSON.parse(agent._limitToolResult(result));+ assert.match(forModel.note, /planned 60 s/);+ assert.match(forModel.note, /incomplete/);+ assert.doesNotMatch(forModel.note, /Tell the user it is ready/);+ const compacted = journal.compactRunUiData('tool_result', { name: 'generate_image', result });+ for (const key of ['estimatedSeconds', 'plannedSeconds', 'durationSeconds', 'durationStatus', 'notice']) {+ assert.equal(compacted.result[key], result[key], key);+ }+ const incompatible = falApi({ model: h3Max.id, schema: h3Max.schema,+ clip: index => fixtures[index ? 'h264-aac-48px' : 'h264-aac-1'] });+ const separate = await generate({ prompt: 'Story', scenes: scenes(2, 15), estimated_duration: 30 },+ { config: falConfig(h3Max), fetchImpl: incompatible.fetchImpl, pollIntervalMs: 1 });+ assert.equal(separate.success, true, separate.error);+ assert.equal(separate.joined, false);+ assert.equal(separate.durationStatus, 'short');+ for (const clip of separate.clips) assert.ok((await storedBytes(clip.mediaId)).length);+ const separateForModel = JSON.parse(agent._limitToolResult(separate));+ assert.match(separateForModel.note, /incomplete/);+ assert.match(separateForModel.note, /could not be joined/);+ });++ test(`${build}: video delivery distinguishes a measured approved plan from an unmeasured hosted clip`, async () => {+ const api = videoApi({ entry: { ...grok, supported_durations: [1] } });+ const approved = await generate({+ prompt: 'Short version', scenes: scenes(2, 1), estimated_duration: 330,+ }, { fetchImpl: api.fetchImpl, confirmVideoLength: async () => 'once' });+ assert.equal(approved.success, true, approved.error);+ assert.deepEqual([approved.estimatedSeconds, approved.plannedSeconds, approved.durationSeconds, approved.durationStatus],+ [330, 2, 2, 'enough'], 'delivery is measured against the explicitly approved shorter plan');+ assert.equal(approved.notice, undefined);++ const fal = falApi({ model: h3Max.id, schema: h3Max.schema });+ const hosted = await generate({ prompt: 'A short clip', media: 'video', duration: 10, estimated_duration: 10 },+ { config: falConfig(h3Max), fetchImpl: fal.fetchImpl, pollIntervalMs: 1 });+ assert.equal(hosted.success, true, hosted.error);+ assert.deepEqual([hosted.estimatedSeconds, hosted.plannedSeconds, hosted.durationSeconds, hosted.durationStatus],+ [10, 10, undefined, 'unverified']);+ assert.match(hosted.notice, /has not been measured/);+ assert.deepEqual(fal.calls.downloads, [], 'a hosted single clip remains a hosted result');+ });+test(`${build}: the model reports a joined video's length, never its contents`, () => {const agent = new Agent({ getActive: () => chatProvider });const forModel = JSON.parse(agent._limitToolResult({ success: true, provider: 'openrouter', model: grok.id,