Skip to content

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.

Chat: hidden tab keeps reading slowly and announces in its title, stalled job card, whitebox...

Bowen Xueeb4f6f557ba4
diff --git a/freevideo_engine/agent/productions.py b/freevideo_engine/agent/productions.py
index 416d76d..2e4f63e 100644
--- a/freevideo_engine/agent/productions.py
+++ b/freevideo_engine/agent/productions.py
@@ -404,6 +404,24 @@ class Productions:
except Exception: # Timing is optional; a forecast failure must not reject a film or job.
return dict(seconds=None, basis=None, reason='unavailable')
+ def _shape(self, state, only=None):
+ """Size and length of what a confirmation asks to make: the first shot's canvas, every shot's seconds added up."""
+ try:
+ rows = []
+ for shot in state['shots']:
+ take = next((t for s, t in self._takes(state) if s is shot and not t['stale'] and t['state'] != 'cancelled'), None)
+ if take is None or only not in (None, shot['id']):
+ continue
+ item = deepcopy(take['spec'])
+ if shot['continues']:
+ item['continue_from'] = dict(from_job='j000000000000')
+ rows.append(spec.normalize(item, port=self.jobs.port))
+ if not rows:
+ return {}
+ return dict(width=rows[0]['width'], height=rows[0]['height'], seconds=round(sum(row['seconds'] for row in rows), 3))
+ except Exception: # The card is complete without it; a failure here must not reject a film.
+ return {}
+
def _join_estimate(self, state, previous=None):
"""Use only successful local joins with the same input geometry and transition."""
shapes = []
@@ -580,6 +598,7 @@ class Productions:
self._prepare_estimates(record)
if self.gate is not None:
self.gate('start', by=by, estimate_seconds=self._progress(record)['estimate_seconds'],
+ shape=self._shape(state),
refs={}, # the film gets its ID only when the approved call repeats
question='Start shooting %s (%d shots)?' % (_quoted(state['title']), len(state['shots'])))
result = self._view(record)
@@ -734,7 +753,7 @@ class Productions:
if self.gate is not None:
shot = next(s for s in state['shots'] if s['id'] == values['shot'])
self.gate('reshoot', by=by, estimate_seconds=sum(estimates) if known else None,
- refs=dict(drama=identity, shot=shot['id']),
+ refs=dict(drama=identity, shot=shot['id']), shape=self._shape(state, shot['id']),
question='Reshoot shot %d of %s?' % (shot['index'], _quoted(state['title'])))
if ref:
draft['receipts'].append(dict(key=ref, digest=digest, result=result,
diff --git a/freevideo_engine/agent/routes.py b/freevideo_engine/agent/routes.py
index f0da626..a776671 100644
--- a/freevideo_engine/agent/routes.py
+++ b/freevideo_engine/agent/routes.py
@@ -912,7 +912,8 @@ def register():
elif row['type'] == 'confirm':
if row['state'] == 'asked':
item = dict(base, id=row['id'], question=row.get('question'),
- estimate_seconds=row.get('estimate_seconds'), state='asked')
+ estimate_seconds=row.get('estimate_seconds'), state='asked',
+ **{key: row[key] for key in ('width', 'height', 'seconds') if row.get(key) is not None})
fold['asked'][row['id']] = item
fold['items'].append(item)
elif row['id'] in fold['asked']:
diff --git a/freevideo_engine/agent/schema.py b/freevideo_engine/agent/schema.py
index 31a41fb..050a13c 100644
--- a/freevideo_engine/agent/schema.py
+++ b/freevideo_engine/agent/schema.py
@@ -851,6 +851,7 @@ def session_event(*, stored=False, agent_only=False):
why=text, error=enum(ERRORS)), ('type', 'tool', 'summary', 'state', *(['id'] if stored else []))),
obj(dict(type={'const': 'confirm'}, id=string(12, pattern=r'^cf[0-9a-f]{10}$'),
question=text, estimate_seconds=number(0), state=enum(('asked', 'approved', 'declined')),
+ width=number(0, integer=True), height=number(0, integer=True), seconds=number(0),
action=enum(('start', 'reshoot')), refs=obj(dict(drama=PRODUCTION, shot=SLUG)),
whitebox=obj(dict(work=SAVED, seconds=number(0), summary=text), ('work',),
description='The rendered white-model preview the user is asked to approve.'),
diff --git a/freevideo_engine/agent/sessions.py b/freevideo_engine/agent/sessions.py
index ae6250f..ab5f9c8 100644
--- a/freevideo_engine/agent/sessions.py
+++ b/freevideo_engine/agent/sessions.py
@@ -511,7 +511,7 @@ class Confirmations:
os.replace(temporary, self.path)
return value
- def gate(self, action, *, by, estimate_seconds, refs, question):
+ def gate(self, action, *, by, estimate_seconds, refs, question, shape=None):
sid, digest = errors.SESSION.get(), errors.CONFIRM.get()
if by != 'agent' or sid is None or digest is None:
return
@@ -532,6 +532,8 @@ class Confirmations:
refs=refs, digest=digest, state='asked')
if estimate_seconds is not None:
event['estimate_seconds'] = round(estimate_seconds)
+ # What is about to be made, for the card the user answers; only what is known is written.
+ event.update({key: shape[key] for key in ('width', 'height', 'seconds') if shape and shape.get(key) is not None})
row = self.sessions.append(sid, event, by='system')
raise SessionError('needs_confirmation', 'Waiting for the user',
details=[dict(confirm=row['id'], seconds=row.get('estimate_seconds'))])
diff --git a/web/autopilot_chat.js b/web/autopilot_chat.js
index 06569fa..26e5562 100644
--- a/web/autopilot_chat.js
+++ b/web/autopilot_chat.js
@@ -133,6 +133,18 @@ export function cardLine(said, job, t) {
if (job.status === 'running' && (stepped(p) || SAVING.includes(p.phase))) said.last = job;
return jobLine(said.last || job, t);
}
+// The generation page's rule: three minutes without a new step or stage and the card says it is still going.
+export const STALL_MS = 180000;
+export const progressKey = job => { const p = job.progress || {}; return JSON.stringify([job.status, p.phase, p.step, p.block, p.fraction]); };
+// The one thing a hidden tab announces in its title, most pressing first: a question, a failure, a finished job.
+// `seen` holds the finished jobs the user already had in front of them when the tab was hidden.
+export function tabNotice(jobs, asked, seen) {
+ if (asked) return 'ask';
+ const fresh = Object.values(jobs).filter(job => !QUIET[job.kind] && !WORKING.includes(job.status) && !seen.has(job.id));
+ if (fresh.some(job => jobMode(job) === 'failed')) return 'failed';
+ return fresh.some(job => jobMode(job) === 'done') ? 'done' : null;
+}
+const TAB_PREFIX = {ask: ['Needs your OK · ', '要确认 · '], failed: ['Failed · ', '出错了 · '], done: ['Done · ', '已完成 · ']};
export function jobMeta(job, t) {
const parts = [];
if (job.width > 0 && job.height > 0) parts.push(`${job.width} × ${job.height}`);
@@ -659,6 +671,8 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()
return row ? row.seconds : null;
}
const active = () => !stopped && element.isConnected && !document.hidden && shown();
+ // A hidden page keeps reading, slowly, so that its title can tell what happened.
+ const reading = () => !stopped && element.isConnected && shown();
const inSelectedChat = () => !creating && (!selectedSession || selectedSession === state.session);
const composeAllowed = () => inSelectedChat() && state.agent.connected === true;
const sendingAllowed = () => inSelectedChat() && canSend(state);
@@ -732,6 +746,13 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()
const stop = press('fv-chat-stop', null, () => void cancelJobs([job.id]));
foot.append(left, stop); info.append(head, middle, foot); item.replaceChildren(box, info);
const said = {};
+ // Three minutes without a new step or stage: the card says so, once, in the line that names the stage.
+ let signature = null, changed = performance.now(), quiet = false;
+ const stalled = next => {
+ const key = progressKey(next);
+ if (key !== signature) { signature = key; changed = performance.now(); }
+ return next.status === 'running' && performance.now() - changed >= STALL_MS;
+ };
// 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);
@@ -742,8 +763,9 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()
const seconds = leftOf(next);
left.textContent = seconds === null ? '' : about(seconds, t);
};
- item.tick = () => level(state.jobs[job.id] || job);
- return next => {
+ let current = job, draw = null;
+ item.tick = () => { current = state.jobs[job.id] || job; level(current); if (stalled(current) !== quiet) draw?.(current); };
+ return draw = next => {
const cells = jobParts(next);
level(next);
name.textContent = jobName(next, t); meta.textContent = jobMeta(next, t); meta.hidden = !meta.textContent;
@@ -753,8 +775,10 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()
parts.hidden = !cells.length;
const block = next.progress?.block;
const where = cardLine(said, next, t);
- part.textContent = cells.length ? t(`Part ${block.index} / ${block.total}`, `第 ${block.index} / ${block.total} 段`) : where;
- step.textContent = cells.length ? where : '';
+ quiet = stalled(next);
+ const waiting = t('Progress has not updated recently; generation is still running.', '进度暂未更新,仍在生成中。');
+ part.textContent = cells.length ? t(`Part ${block.index} / ${block.total}`, `第 ${block.index} / ${block.total} 段`) : quiet ? waiting : where;
+ step.textContent = cells.length ? quiet ? waiting : where : '';
const going = stopping.has(next.id) || next.status === 'cancelling';
stop.disabled = going; stop.textContent = going ? t('Stopping…', '正在停止…') : t('Stop', '停止');
stop.setAttribute('aria-busy', String(going));
@@ -935,7 +959,13 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()
};
buttons.append(press('fv-chat-yes fv-primary', t(...WHITEBOX.generate), answer(true)),
press('fv-whitebox-edit', t(...WHITEBOX.edit), () => {
- if (!disabled && whiteboxState(entry) === 'asked') input.focus();
+ if (disabled || whiteboxState(entry) !== 'asked') return;
+ // The summary goes into an empty box with the cursor after it; what the user has already typed stays.
+ const text = entry.whitebox.summary || entry.whitebox.scene_summary || '';
+ if (text && !input.value.trim()) { input.value = text; input.dispatchEvent(new Event('input')); }
+ input.focus();
+ input.setSelectionRange(input.value.length, input.value.length);
+ input.scrollTop = input.scrollHeight;
}), press('fv-chat-no fv-quiet', t(...WHITEBOX.decline), answer(false)));
item.replaceChildren(preview, summary, seconds, buttons, status, error);
return {update(next) {
@@ -994,7 +1024,9 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()
buttons.querySelectorAll('button').forEach(button => { button.disabled = disabled; });
const question = el('p', null, entry.question);
const estimate = el('p', 'fv-chat-meta', entry.estimate_seconds > 0 ? about(entry.estimate_seconds, t) : ''); estimate.hidden = !estimate.textContent;
- item.replaceChildren(question, estimate, buttons);
+ // What is about to be made, written as on the job card; a question that carries no size or length shows only the time.
+ const shape = el('p', 'fv-chat-meta', jobMeta(entry, t)); shape.hidden = !shape.textContent;
+ item.replaceChildren(question, shape, estimate, buttons);
if (error) {
const notice = el('p', 'fv-chat-error', error); notice.setAttribute('role', 'alert');
item.append(notice, issueButton(t, () => ({where: CHAT_ISSUE, message: error})));
@@ -1212,9 +1244,9 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()
clearTimeout(timer); timer = null;
if (stopped) return;
if (busy) { reread = true; return; }
- if (!active()) return;
+ if (!reading()) return;
busy = true; reread = false;
- void readConversations();
+ if (!document.hidden) void readConversations();
const readSelection = selection, requested = selectedSession;
let again = false;
try {
@@ -1262,8 +1294,8 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()
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, chatDelay({idle, interval, failures}));
- render(); report();
+ timer = setTimeout(poll, chatDelay({hidden: document.hidden, idle, interval, failures}));
+ render(); report(); tab();
if (sendingAllowed()) for (const entry of [...pending]) {
if (entry.session !== state.session || !entry.automatic || entry.sending || entry.acknowledged) continue;
await send(entry.text, entry, entry.draft, true);
@@ -1276,7 +1308,27 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()
for (const item of log.children) item.tick?.();
report();
}, 250);
- const visible = () => { if (!document.hidden) sync(); };
+ // The title of a hidden tab carries one fixed prefix: no flashing, no counts. It is the page's own title again when the user returns.
+ let titleBase = null, titleShown = null, seen = null;
+ const finished = () => new Set(Object.values(state.jobs).filter(job => !WORKING.includes(job.status)).map(job => job.id));
+ const asking = () => [...state.items.values()].some(entry => entry.type === 'confirm'
+ && (entry.whitebox ? whiteboxState(entry) : answers.get(cardKey(state.session, entry.id)) || state.confirms[entry.id] || entry.state || 'asked') === 'asked');
+ function tab() {
+ if (titleShown !== null && document.title !== titleShown) titleBase = titleShown = null;
+ if (stopped || !document.hidden || !known) {
+ if (titleShown !== null && document.title === titleShown) document.title = titleBase;
+ titleBase = titleShown = null; seen = null; return;
+ }
+ seen ||= finished();
+ const notice = tabNotice(state.jobs, asking(), seen);
+ if (!notice) {
+ if (titleShown !== null) document.title = titleBase;
+ titleBase = titleShown = null; return;
+ }
+ if (titleBase === null) titleBase = document.title;
+ document.title = titleShown = t(...TAB_PREFIX[notice]) + titleBase;
+ }
+ const visible = () => { if (document.hidden) { seen = finished(); tab(); } else { tab(); if (reading()) void poll(); } };
document.addEventListener('visibilitychange', visible);
function sync() {
if (pinned) scroller.scrollTop = scroller.scrollHeight;
@@ -1296,7 +1348,7 @@ export function agentChat(t, api, {open, edit, shown = () => true, changed = ()
try { await cancelJobs(ids); }
finally { bulkStopping = false; if (!stopped) { report(); void poll(); } }
},
- stop() { closeMenu(); stopped = true; dismissImage?.(); closed.abort(); clearInterval(moving); clearTimeout(timer); timer = null;
+ stop() { closeMenu(); stopped = true; tab(); dismissImage?.(); closed.abort(); clearInterval(moving); clearTimeout(timer); timer = null;
document.removeEventListener('visibilitychange', visible); document.removeEventListener('pointerdown', outside, true);
document.removeEventListener('keydown', keys, true); window.removeEventListener('resize', resize); list.removeEventListener('scroll', listScroll);
log.querySelectorAll('video').forEach(video => video.pause()); }};
diff --git a/web/chat_data.js b/web/chat_data.js
index 9d510c3..592c74a 100644
--- a/web/chat_data.js
+++ b/web/chat_data.js
@@ -101,7 +101,9 @@ export function chatData(api) {
};
}
export function chatDelay({hidden = false, phone = false, idle = false, interval = 1500, failures = 0} = {}) {
- return phone ? (hidden ? 10000 : 2000) : (idle ? Math.max(interval, 3000) : interval) * Math.min(4, 1 + failures);
+ // A page nobody is looking at asks less often; it only has to notice what the tab title announces.
+ if (phone) return hidden ? 10000 : 2000;
+ return Math.max(hidden ? 10000 : 0, idle ? Math.max(interval, 3000) : interval) * Math.min(4, 1 + failures);
}
// Serial polling, visibility rescheduling and disposal work without a browser.
export function chatPoller(read, {delay = () => 2000, error = () => {}, clock = globalThis} = {}) {