Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.
Autopilot conversation: progress moves the way the creation panel's does
Bowen Xue56dee3cdf7d1
diff --git a/web/autopilot.js b/web/autopilot.jsindex 3b333f5..df07286 100644--- a/web/autopilot.js+++ b/web/autopilot.js@@ -1,7 +1,7 @@// The Agent's own page, beside the studio and the editing view: the card that connects one, then the conversation with it.import { api } from '../../scripts/api.js';import { agentConnectCard, connectionLabel } from './agent_connect.js';-import { about, agentChat, jobFraction, jobName } from './autopilot_chat.js';+import { about, agentChat, jobName } from './autopilot_chat.js';import { openEditorView } from './editor_loader.js';import { closeDialog } from './motion.js';import { openSetup } from './setup.js';@@ -46,7 +46,7 @@ export function openAutopilotView(node, {studio = null} = {}) {const closed = () => dialog.open ? new Promise(done => { dialog.addEventListener('close', done, {once: true}); closeDialog(dialog); }) : null;const chat = agentChat(t, api, {shown: inSight,// A finished video opens as its work in Creations. Continuing it there belongs to the studio, so this page gives way first.- open: async job => (await import('./library.js')).openLibrary(t, {selectedWork: job.work, back: t('Back to Autopilot', '返回 AI 全自动'),+ open: async job => (await import('./library.js')).openLibrary(t, {selectedWork: job.work, back: t('Back to chat', '返回对话'),extend: async record => { await closed(); return extendVideo(record, node); }}),edit: job => leave(() => openEditorView(node, {studio: studio?.open ? studio : undefined, work: {id: job.work, video: `FreeVideo/${job.work}/video.mp4`, geometry: {width: job.width, height: job.height, seconds: job.seconds}}})),changed: view => { last = view; show(); }});@@ -60,15 +60,16 @@ export function openAutopilotView(node, {studio = null} = {}) {// The card gives way to the conversation: typing can start at once.const arrived = talking && chat.element.hidden && (card.element.contains(document.activeElement) || document.activeElement === lamp);card.element.hidden = !ready || talking; chat.element.hidden = !talking;- if (arrived) chat.input.focus();body.dataset.view = talking ? 'chat' : 'connect';+ if (talking) chat.sync();+ if (arrived) chat.input.focus();lamp.hidden = !ready; lamp.dataset.color = label.color; lampText.textContent = label.text; lamp.disabled = connected || !last.any;const job = talking ? last.current : null;now.hidden = !job; line.dataset.on = String(!!job);if (job) {- const fraction = jobFraction(job), running = job.status === 'running';+ const fraction = last.fraction || 0, running = job.status === 'running';currentId = job.id; name.textContent = jobName(job, t); more.textContent = last.active > 1 ? `+${last.active - 1}` : '';- percent.textContent = running ? `${Math.round(fraction * 100)}%` : '';+ percent.textContent = running && fraction >= .01 ? `${Math.floor(fraction * 100)}%` : '';eta.textContent = running && job.progress?.remaining_seconds > 0 ? about(job.progress.remaining_seconds, t) : '';ring.style.setProperty('--p', String(fraction * 100)); line.style.width = `${fraction * 100}%`;}diff --git a/web/autopilot_chat.css b/web/autopilot_chat.cssindex a8035b8..eea7bf4 100644--- a/web/autopilot_chat.css+++ b/web/autopilot_chat.css@@ -3,7 +3,7 @@.fv-chat[hidden],.fv-chat [hidden]{display:none}.fv-chat-scroll{min-height:0;overflow:auto;margin:0 -40px;padding:24px 40px 2px;scrollbar-gutter:stable both-edges}.fv-chat-log{list-style:none;margin:0 auto;padding:0;width:100%;max-width:720px;display:grid;grid-template-columns:minmax(0,1fr);align-content:start;gap:18px}-.fv-chat-log>li{min-width:0}.fv-chat-log p{margin:0}+.fv-chat-log>li{min-width:0}.fv-chat-log p{margin:0;line-height:1.6}.fv-chat-me{justify-self:end;max-width:min(500px,88%)}.fv-chat-me>p{background:#1d3550;border-radius:14px 14px 4px 14px;padding:10px 14px;white-space:pre-wrap;overflow-wrap:anywhere;transition:opacity var(--fv-base) var(--fv-ease)}.fv-chat-me[data-taken=false]>p{opacity:.7}@@ -18,16 +18,17 @@.fv-chat-job{box-sizing:border-box;justify-self:start;width:100%;max-width:560px;display:grid;grid-template-columns:auto minmax(0,1fr);gap:14px;padding:12px;border:1px solid var(--fv-border);border-radius:14px;background:var(--fv-card)}.fv-chat-job:is([data-mode=stopped],[data-mode=failed],[data-mode=quiet]){width:auto;display:flex;align-items:center;gap:10px;padding:0;border:0;background:none;color:var(--fv-muted);font-size:13.5px}.fv-chat-preview{position:relative;align-self:start;width:124px;aspect-ratio:16/9;border-radius:9px;overflow:hidden;background:#0c121a}-.fv-chat-preview[data-shape=wide]{width:196px}+.fv-chat-preview[data-shape=wide]{width:240px}.fv-chat-preview>:is(img,video){position:absolute;inset:0;width:100%;height:100%;object-fit:contain;display:block}.fv-chat-preview>img{animation:fv-chat-in .3s var(--fv-ease)}.fv-chat-preview[data-video]>img{display:none}@keyframes fv-chat-in{from{opacity:0}}-.fv-chat-water{position:absolute;left:0;right:0;bottom:0;background:linear-gradient(180deg,#4f9dff66,#2a6fc955 60%,#1d4f9566);transition:height .6s var(--fv-ease)}+.fv-chat-water{position:absolute;left:0;right:0;bottom:0;height:var(--level,0%);background:linear-gradient(180deg,#4f9dff66,#2a6fc955 60%,#1d4f9566);transition:height .6s var(--fv-ease)}.fv-chat-water::before{content:"";position:absolute;left:0;right:0;top:-18px;height:18px;background:linear-gradient(180deg,transparent,#4f9dff2e)}.fv-chat-water::after{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:linear-gradient(90deg,#9fd2ff,#e3f2ff 45%,#9fd2ff) 0 0/200% 100%;box-shadow:0 0 10px #7cc4ff;animation:fv-chat-shine 5s linear infinite}@keyframes fv-chat-shine{to{background-position:-200% 0}}-.fv-chat-percent{position:absolute;left:0;right:0;top:50%;transform:translateY(-50%);text-align:center;font-size:26px;line-height:1;font-weight:700;font-variant-numeric:tabular-nums;text-shadow:0 2px 10px #000a}+.fv-chat-percent{position:absolute;left:0;right:0;bottom:calc(var(--level,0%) + 6px);transition:bottom .6s var(--fv-ease);text-align:center;font-size:26px;line-height:1;font-weight:700;font-variant-numeric:tabular-nums;text-shadow:0 2px 10px #000a}.fv-chat-length{position:absolute;right:7px;bottom:6px;font-size:11.5px;line-height:1.5;color:#fff;background:#0009;border-radius:4px;padding:0 5px;font-variant-numeric:tabular-nums;pointer-events:none}+.fv-chat-preview[data-under=true] .fv-chat-percent{bottom:calc(var(--level,0%) - 6px - 1em)}.fv-chat-preview[data-video] .fv-chat-length{bottom:16px}.fv-studio .fv-chat-play{position:absolute;inset:0;width:100%;height:100%;min-height:0;padding:0;border:0;border-radius:0;background:transparent}.fv-studio .fv-chat-play:hover{background:transparent}@@ -70,4 +71,4 @@.fv-studio .fv-chat-send:focus-visible{outline-offset:2px}@media(max-width:480px){.fv-chat{padding:0 14px 14px}.fv-chat-scroll{margin:0 -14px;padding:16px 14px 2px}.fv-chat-hello{padding-top:32px}.fv-chat-job{max-width:none;gap:12px}.fv-chat-confirm{max-width:none}.fv-chat-preview,.fv-chat-preview[data-shape=wide]{width:98px}.fv-chat-percent{font-size:22px}.fv-studio.fv-autopilot .fv-chat-input textarea{font-size:16px}.fv-studio .fv-chat-down{right:14px;bottom:84px}}-@media(prefers-reduced-motion:reduce){.fv-chat-water,.fv-chat-parts>i::after{transition:none}.fv-chat-water::after,.fv-chat-dots>i,.fv-chat-preview>img{animation:none}}+@media(prefers-reduced-motion:reduce){.fv-chat-water,.fv-chat-percent,.fv-chat-parts>i::after{transition:none}.fv-chat-water::after,.fv-chat-dots>i,.fv-chat-preview>img{animation:none}}diff --git a/web/autopilot_chat.js b/web/autopilot_chat.jsindex a39ed7a..29ea994 100644--- a/web/autopilot_chat.js+++ b/web/autopilot_chat.js@@ -1,6 +1,7 @@// The conversation with the connected agent: what the user says, what the agent answers, and the agent's jobs as// cards at the place they happened. Reads and sends use the page session; the agent's token never enters the page.import {agentGet, agentPost} from './agent_session.js';+import { estimatedFraction } from './generation_progress.js';const css = document.createElement('link'); css.rel = 'stylesheet'; css.href = new URL('./autopilot_chat.css', import.meta.url).href; document.head.append(css);@@ -15,19 +16,27 @@ const press = (cls, text, action) => { const b = el('button', cls, text); b.typeconst WORKING = ['running', 'queued', 'waiting'], VIDEOS = ['generate', 'assemble'];// What a job with no picture of its own is doing, in the reader's language.-const QUIET = {vlm: ['Checking', '检查中'], enhance: ['Writing the prompt', '润色提示词']};+const QUIET = {vlm: ['Checking', '检查中'], enhance: ['Polishing', '润色中']};export const about = (seconds, t) => seconds >= 60 ? t(`About ${Math.ceil(seconds / 60)} min`, `约 ${Math.ceil(seconds / 60)} 分钟`) : t('Under 1 min', '不到 1 分钟');export function clock(seconds) { const s = Math.max(0, Math.round(seconds)); return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`; }export const jobName = (job, t) => job.label || t('Video', '视频');export const jobFraction = job => Math.max(0, Math.min(1, Number(job.progress?.fraction) || 0));+// What a job's last progress stands for `age` seconds after it was made, by the creation panel's rule. Without the+// engine's estimate the reported fraction moves toward the end over the time the engine said is left.+export function jobEstimate(job, age) {+ const p = job.progress || {}, e = p.estimate;+ if (e?.overall) return estimatedFraction(e, e.overall, age, age) ?? jobFraction(job);+ const raw = jobFraction(job);+ return p.remaining_seconds > 0 ? raw + (1 - raw) * Math.min(.9, Math.max(0, age) / p.remaining_seconds) : raw;+}// working, done, stopped or failed: which card a job shows.export const jobMode = job => WORKING.includes(job.status) ? 'working' : job.status === 'succeeded' ? 'done' : job.status === 'cancelled' ? 'stopped' : 'failed';// The one line that says where a job is. No step count is written unless the engine gave one.export function jobLine(job, t) {const p = job.progress || {};if (job.status !== 'running') return t('Queued', '排队中');- if (p.phase === 'sampling' && p.step?.total) return t(`Step ${p.step.done} / ${p.step.total}`, `生成 ${p.step.done} / ${p.step.total}`);+ if (p.phase === 'sampling' && p.step?.total && p.step.done >= 1) return t(`Step ${p.step.done} / ${p.step.total}`, `生成 ${p.step.done} / ${p.step.total}`);if (['decode', 'finishing', 'assembling'].includes(p.phase)) return t('Saving', '保存中');return t('Preparing', '准备中');}@@ -86,7 +95,22 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()form.append(input, sendButton); scroller.append(log); element.append(scroller, down, form);let state = emptyChat(), pending = [], known = false, stopped = false, timer = null, busy = false, failures = 0;+ // Whether the reader is at the newest entry. It holds while the conversation is out of sight, which forgets where it was scrolled.+ let pinned = true;+ const closed = new AbortController();const nodes = new Map(), answers = new Map(), stopping = new Set();+ // The fraction each job shows: the estimate, never backwards, short of 100% until the video is saved.+ const levels = new Map();+ function fractionOf(job) {+ const p = job.progress || {}, {age_seconds: sent, ...sample} = p.estimate || {fraction: p.fraction};+ const key = JSON.stringify(sample), time = performance.now() / 1000;+ let row = levels.get(job.id);+ if (!row) levels.set(job.id, row = {key: null, at: 0, job: null, value: 0});+ // remaining_seconds counts down between samples; the one that came with the sample is the one to move by.+ if (row.key !== key) { row.key = key; row.at = time - (sent > 0 ? sent : 0); row.job = job; }+ if (job.status === 'running') row.value = Math.max(row.value, Math.min(.99, jobEstimate(row.job, time - row.at)));+ return row.value;+ }const active = () => !stopped && element.isConnected && !document.hidden && shown();// ---- one entry of the conversation each ----@@ -112,9 +136,18 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()poll();});foot.append(left, stop); info.append(head, middle, foot); item.replaceChildren(box, info);+ // The number rides on the water, and goes under the line once there is no room left above it.+ const level = next => {+ const fraction = fractionOf(next);+ box.style.setProperty('--level', `${fraction * 100}%`);+ percent.textContent = next.status === 'running' && fraction >= .01 ? `${Math.floor(fraction * 100)}%` : '';+ const high = box.clientHeight;+ box.dataset.under = String(high > 0 && high * (1 - fraction) < percent.offsetHeight + 10);+ };+ item.tick = () => level(state.jobs[job.id] || job);return next => {- const fraction = jobFraction(next), cells = jobParts(next), queued = next.status !== 'running';- water.style.height = `${fraction * 100}%`; percent.textContent = queued ? '' : `${Math.round(fraction * 100)}%`;+ const cells = jobParts(next), queued = next.status !== 'running';+ level(next);name.textContent = jobName(next, t); meta.textContent = jobMeta(next, t); meta.hidden = !meta.textContent;while (parts.children.length > cells.length) parts.lastChild.remove();while (parts.children.length < cells.length) parts.append(el('i'));@@ -266,7 +299,7 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()if (tail?.type !== 'job' && tail?.type !== 'confirm' && (pending.length || tail?.role === 'user') && state.agent.connected === true&& (state.agent.listening !== false || tail.taken === true)) wanted.push(['dots', 'dots', null]);- const stick = follow || scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < 48;+ const stick = follow || pinned;const before = log.children.length, keep = new Set(wanted.map(([key]) => key));for (const [key, node] of nodes) if (!keep.has(key)) { node.element.remove(); nodes.delete(key); }wanted.forEach(([key, kind, value, extra], index) => {@@ -279,13 +312,18 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()input.disabled = state.agent.connected !== true;input.placeholder = state.agent.connected === true && !sendable ? t('Ask your agent to keep listening', '回到 Agent 那边让它继续') : t('Message the agent…', '对 Agent 说…');sendButton.disabled = !sendable || !input.value.trim();- if (stick) { scroller.scrollTop = scroller.scrollHeight; down.hidden = true; }+ if (stick) { pinned = true; scroller.scrollTop = scroller.scrollHeight; down.hidden = true; }else if (log.children.length > before) down.hidden = false;}- scroller.addEventListener('scroll', () => { if (scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < 48) down.hidden = true; }, {passive: true});+ scroller.addEventListener('scroll', () => {+ if (!scroller.clientHeight) return;+ pinned = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < 48;+ if (pinned) down.hidden = true;+ }, {passive: true});function report() {- changed({known, agent: state.agent, current: state.current ? state.jobs[state.current] || null : null, active: state.active,+ const current = state.current ? state.jobs[state.current] || null : null;+ changed({known, agent: state.agent, current, fraction: current ? fractionOf(current) : 0, active: state.active,any: state.items.size > 0 || pending.length > 0});}async function send(text) {@@ -330,7 +368,7 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()let again = false;try {const after = state.session ? state.last : 0;- const response = await agentGet(api, '/freevideo/agent/chat' + (after ? `?after=${after}` : ''));+ const response = await agentGet(api, '/freevideo/agent/chat' + (after ? `?after=${after}` : ''), {signal: closed.signal});if (stopped) return;if (response.ok) {const data = await response.json();@@ -345,13 +383,24 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()finally { busy = false; }if (stopped) return;if (again) return poll();- known = true; render(); report();+ known = true;+ // The next read is booked before the page hears of this one, so the page's sync() does not start another.const idle = state.agent.connected !== true && !state.active;timer = setTimeout(poll, (idle ? Math.max(interval, 3000) : interval) * Math.min(4, 1 + failures));+ render(); report();}+ // Between reads the estimate keeps moving, on the cards and in the page's header alike.+ const moving = setInterval(() => {+ if (!active() || !Object.values(state.jobs).some(job => job.status === 'running')) return;+ for (const item of log.children) item.tick?.();+ report();+ }, 250);const visible = () => { if (!document.hidden) sync(); };document.addEventListener('visibilitychange', visible);- function sync() { if (active() && !timer && !busy) poll(); }+ function sync() {+ if (pinned) scroller.scrollTop = scroller.scrollHeight;+ if (active() && !timer && !busy) poll();+ }render();return {element, input, sync, refresh: poll,scrollToJob(id) { log.querySelector(`[data-job="${CSS.escape(id)}"]`)?.scrollIntoView({block: 'center', behavior: 'smooth'}); },@@ -361,5 +410,5 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()await Promise.allSettled(ids.map(id => agentPost(api, '/freevideo/agent/activity/cancel', {id})));poll();},- stop() { stopped = true; clearTimeout(timer); timer = null; document.removeEventListener('visibilitychange', visible); log.querySelectorAll('video').forEach(video => video.pause()); }};+ stop() { stopped = true; closed.abort(); clearInterval(moving); clearTimeout(timer); timer = null; document.removeEventListener('visibilitychange', visible); log.querySelectorAll('video').forEach(video => video.pause()); }};}diff --git a/web/generation_progress.js b/web/generation_progress.jsindex f14a1db..ccf9085 100644--- a/web/generation_progress.js+++ b/web/generation_progress.js@@ -216,6 +216,45 @@ export function referenceTrimText(row, t) {`${name} 比生成的视频长,已截取前 ${used} 秒${rule}`);}+// The whole-video fraction the engine's last message stands for now: its estimate moved on by the seconds since the+// step sample (stateAge) and the whole-video sample (overallAge) arrived. Null when the message carries none.+export function estimatedFraction(state, overall, stateAge, overallAge) {+ const fraction = value => Math.min(1, Math.max(0, value));+ const counted = Number.isInteger(state.total) && state.total > 0 && Number.isInteger(state.done)+ && state.done >= 0 && state.done <= state.total;+ let candidate = valid(overall.fraction) ? fraction(overall.fraction) : null;+ const canEstimate = overall.status !== 'failed' && overall.estimated === true+ && valid(overall.phase_start_fraction) && valid(overall.phase_weight);+ if (canEstimate) {+ let local = null;+ if (state.phase === 'sampling' && counted && !overall.sampling_time_weighted) {+ local = valid(state.display_fraction) ? fraction(state.display_fraction) : state.done / state.total;+ if (state.done < state.total && valid(state.estimated_step_seconds) && state.estimated_step_seconds > 0) {+ const stepElapsed = (valid(state.step_elapsed_seconds) ? state.step_elapsed_seconds : 0)+ + Math.max(0, stateAge);+ local = Math.max(local, (state.done + Math.min(.88, .88 * stepElapsed / state.estimated_step_seconds)) / state.total);+ } else if (valid(overall.phase_seconds) && overall.phase_seconds > 0+ && valid(overall.phase_elapsed_seconds)) {+ // Before the first warm NFE supplies a per-step duration,+ // use the report-weighted sampling estimate as a smooth+ // visual guide. The synchronized NFE counter remains the+ // source of truth and this estimate stops short of 100%.+ const phaseElapsed = overall.phase_elapsed_seconds+ + Math.max(0, overallAge);+ local = Math.max(local, Math.min(.95, phaseElapsed / overall.phase_seconds));+ }+ } else if (valid(overall.phase_seconds) && overall.phase_seconds > 0 && valid(overall.phase_elapsed_seconds)) {+ const phaseElapsed = overall.phase_elapsed_seconds + Math.max(0, overallAge);+ // Time can move the estimate, but only an engine transition+ // finishes a phase. Long phases stop short of their boundary.+ local = Math.min(.95, phaseElapsed / overall.phase_seconds);+ }+ if (local !== null) candidate = Math.max(candidate ?? 0,+ canEstimate ? overall.phase_start_fraction + overall.phase_weight * local : local);+ }+ return candidate;+}+export function createGenerationProgress(t, now = () => Date.now(), {compact = false, api = null, onLayout = null} = {}) {const element = el('section', 'fv-generation-progress'); element.hidden = true;if (compact) element.classList.add('fv-generation-compact');@@ -330,36 +369,7 @@ export function createGenerationProgress(t, now = () => Date.now(), {compact = freturn;}const complete = overall.status === 'complete';- let candidate = valid(overall.fraction) ? fraction(overall.fraction) : null;- const canEstimate = overall.status !== 'failed' && overall.estimated === true- && valid(overall.phase_start_fraction) && valid(overall.phase_weight);- if (canEstimate) {- let local = null;- if (state.phase === 'sampling' && counted(state) && !overall.sampling_time_weighted) {- local = valid(state.display_fraction) ? fraction(state.display_fraction) : state.done / state.total;- if (state.done < state.total && valid(state.estimated_step_seconds) && state.estimated_step_seconds > 0) {- const stepElapsed = (valid(state.step_elapsed_seconds) ? state.step_elapsed_seconds : 0)- + Math.max(0, (now() - sampledAt) / 1000);- local = Math.max(local, (state.done + Math.min(.88, .88 * stepElapsed / state.estimated_step_seconds)) / state.total);- } else if (valid(overall.phase_seconds) && overall.phase_seconds > 0- && valid(overall.phase_elapsed_seconds)) {- // Before the first warm NFE supplies a per-step duration,- // use the report-weighted sampling estimate as a smooth- // visual guide. The synchronized NFE counter remains the- // source of truth and this estimate stops short of 100%.- const phaseElapsed = overall.phase_elapsed_seconds- + Math.max(0, (now() - overallAt) / 1000);- local = Math.max(local, Math.min(.95, phaseElapsed / overall.phase_seconds));- }- } else if (valid(overall.phase_seconds) && overall.phase_seconds > 0 && valid(overall.phase_elapsed_seconds)) {- const phaseElapsed = overall.phase_elapsed_seconds + Math.max(0, (now() - overallAt) / 1000);- // Time can move the estimate, but only an engine transition- // finishes a phase. Long phases stop short of their boundary.- local = Math.min(.95, phaseElapsed / overall.phase_seconds);- }- if (local !== null) candidate = Math.max(candidate ?? 0,- canEstimate ? overall.phase_start_fraction + overall.phase_weight * local : local);- }+ const candidate = estimatedFraction(state, overall, (now() - sampledAt) / 1000, (now() - overallAt) / 1000);// A retry or a new phase cannot rewind the whole-video bar. Even a// complete sampling phase is not a completed/saved video.if (complete) shownFraction = 1;