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.

Keep the Autopilot entry when its check fails

Bowen Xue7741d0e9c844
diff --git a/scripts/test_freevideo_entry.mjs b/scripts/test_freevideo_entry.mjs
index 8a28957..8e25a9f 100644
--- a/scripts/test_freevideo_entry.mjs
+++ b/scripts/test_freevideo_entry.mjs
@@ -141,7 +141,7 @@ test('main browser entry registers both views and preserves node hooks', async t
.replace("import { imageGenerationSupported } from './image_generation.js';", 'const imageGenerationSupported = () => true;')
.replace("import { uploadMedia } from './media_upload.js';", 'const {uploadMedia} = globalThis.__freevideoEntryTest;')
.replace("import { createCastLibrary } from './cast_library.js';", 'const {createCastLibrary} = globalThis.__freevideoEntryTest;')
- .replace("import { agentInterfaceEnabled } from './agent_connect.js';", 'const agentInterfaceEnabled = async () => false;')
+ .replace("import { agentInterfaceState } from './agent_connect.js';", "const agentInterfaceState = async () => 'off';")
.replace("import { installNativeErrorGuard } from './native_errors.js';", 'const installNativeErrorGuard = () => {};')
.replace("import { installTranslateGuard } from './translate_guard.js';", 'const installTranslateGuard = () => {};');
await import('data:text/javascript;base64,' + Buffer.from(source).toString('base64'));
diff --git a/web/agent_connect.js b/web/agent_connect.js
index 1bee48b..605438f 100644
--- a/web/agent_connect.js
+++ b/web/agent_connect.js
@@ -12,14 +12,19 @@ export function connectionSentence(address, t) {
return t(`Connect to FreeVideo: open ${url} and follow the instructions.`, `请连接 FreeVideo:打开 ${url} 并按说明操作。`);
}
-// Whether this FreeVideo has the Agent interface on. Any failure counts as off: the surface shows nothing.
-export async function agentInterfaceEnabled(api) {
+// Whether this FreeVideo has the Agent interface on: 'on', 'off' or 'unknown'. Only an explicit `enabled: false`
+// is off; a check that failed (no answer, an error status, an unreadable reply) is not an answer.
+export async function agentInterfaceState(api) {
try {
const response = await api.fetchApi('/freevideo/agent', {cache: 'no-store'});
- return response.ok && (await response.json()).enabled === true;
- } catch { return false; }
+ if (!response.ok) return 'unknown';
+ const enabled = (await response.json())?.enabled;
+ return enabled === true ? 'on' : enabled === false ? 'off' : 'unknown';
+ } catch { return 'unknown'; }
}
+export async function agentInterfaceEnabled(api) { return await agentInterfaceState(api) === 'on'; }
+
const ICONS = {plug: ['M9 7V3M15 7V3M7 7h10v4a5 5 0 0 1-10 0V7zM12 16v5', 1.8], copy: ['M11 9h7a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2h-7a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2zM5 15V5a2 2 0 0 1 2-2h8', 2]};
function icon(name) {
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
@@ -32,7 +37,9 @@ function icon(name) {
// The card alone: who can connect and one button that copies the sentence to paste to the agent. The sentence
// stays out of sight; it shows, selected, only when the browser refuses the clipboard. shown() says whether the
// user can see the card now; the surface calls sync() whenever that may have changed.
-export function agentConnectCard(t, api, shown = () => true) {
+// A failed check leaves the card up, so its own retry is the way back; an address that loads then asks again and
+// reports the answer to changed().
+export function agentConnectCard(t, api, shown = () => true, changed = () => {}) {
const css = document.createElement('link'); css.rel = 'stylesheet'; css.href = new URL('./agent_connect.css', import.meta.url).href; document.head.append(css);
const body = el('section', 'fv-agent-connect-body');
const mark = el('span', 'fv-agent-connect-icon'); mark.append(icon('plug'));
@@ -94,6 +101,7 @@ export function agentConnectCard(t, api, shown = () => true) {
if (!connect?.address) throw new Error('Missing address');
text = connectionSentence(connect.address, t);
failures = 0; render();
+ if (await state === 'unknown') { state = agentInterfaceState(api); changed(await state); }
} catch { if (current === generation) { failures++; render(); } }
finally {
if (current === generation) {
@@ -106,7 +114,8 @@ export function agentConnectCard(t, api, shown = () => true) {
if (!active()) { stop(); return; }
if (!text && failures < 3 && !controller && !timer) load();
}
- // Resolves to whether this FreeVideo has the Agent interface on; a surface shows nothing when it is off.
- const enabled = agentInterfaceEnabled(api);
- return {element: body, enabled, sync, stop};
+ // `state` is the first answer; `enabled` resolves to whether it is on.
+ let state = agentInterfaceState(api);
+ const first = state, enabled = first.then(value => value === 'on');
+ return {element: body, state: first, enabled, sync, stop};
}
diff --git a/web/autopilot.js b/web/autopilot.js
index ee9302f..7fe1155 100644
--- a/web/autopilot.js
+++ b/web/autopilot.js
@@ -10,7 +10,7 @@ import { productVersion } from './updates.js';
import { openSetup } from './setup.js';
import { feedbackButton } from './feedback.js';
import { openExtendEditor, openStudio, showNodes } from './studio.js';
-import { viewChanged, viewSwitch } from './view_navigation.js';
+import { agentTabReady, viewChanged, viewSwitch } from './view_navigation.js';
import { wordmark } from './wordmark.js';
const languageOverride = typeof location !== 'undefined'
@@ -46,7 +46,11 @@ export function openAutopilotView(node, {studio = null, initialPrompt = '', init
header.append(brand, navigation, tools, line);
const inSight = () => dialog.open && dialog.dataset.closing !== 'true';
const body = el('div', 'fv-autopilot-body');
- const card = agentConnectCard(t, api, () => inSight() && !card.element.hidden);
+ const card = agentConnectCard(t, api, () => inSight() && !card.element.hidden, value => {
+ on = value; show();
+ if (value !== 'unknown') agentTabReady(value);
+ if (value === 'on') chat.sync();
+ });
// Leaving for another view waits until this page has closed, so the view underneath is never covered twice.
const closed = () => dialog.open ? new Promise(done => { dialog.addEventListener('close', done, {once: true}); closeDialog(dialog); }) : null;
// The next video at the studio's current settings; the agent may choose others, so this is only what is missing now.
@@ -70,10 +74,11 @@ export function openAutopilotView(node, {studio = null, initialPrompt = '', init
function show() {
const connected = last.agent.connected === true, label = connectionLabel(last.agent, t);
if (connected) wantCard = false;
- const ready = on === true && last.known, talking = ready && (connected || (last.any && !wantCard));
+ const ready = on === 'on' && last.known, talking = ready && (connected || (last.any && !wantCard));
// 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;
+ // A check that failed keeps the card up: its retry is the way back.
+ card.element.hidden = !(ready || on === 'unknown') || talking; chat.element.hidden = !talking;
body.dataset.view = talking ? 'chat' : 'connect';
if (talking) chat.sync();
if (arrived) chat.input.focus();
@@ -98,7 +103,7 @@ export function openAutopilotView(node, {studio = null, initialPrompt = '', init
go.onclick = () => chat.scrollToJob(currentId);
halt.onclick = () => chat.stopAll();
body.append(card.element, chat.element);
- card.enabled.then(value => { on = value; show(); if (value) chat.sync(); });
+ card.state.then(value => { on = value; show(); if (value === 'on') chat.sync(); });
show();
dialog.append(header, body);
dialog.addEventListener('cancel', event => { event.preventDefault(); closeDialog(dialog); });
diff --git a/web/freevideo.js b/web/freevideo.js
index a92283c..081d66a 100644
--- a/web/freevideo.js
+++ b/web/freevideo.js
@@ -15,7 +15,7 @@ import { startDoneNotify, askDesktopPermission, DESKTOP_SETTING } from './done_n
import { installNavigation, refreshNavigation, preferredView, collapseWorkspaces } from './view_navigation.js';
import { isLaunchVisit } from './launch_visit.js';
import { openFreeVideoWorkflow } from './launcher.js';
-import { agentInterfaceEnabled } from './agent_connect.js';
+import { agentInterfaceState } from './agent_connect.js';
import { attachReferencePicker, referenceItems, syncReferencePrompt, referenceInputs, mediaRows } from './prompt_references.js';
import { expandCast } from './cast_mention.js';
import { outputDownloadURL } from './output_download.js';
@@ -702,7 +702,7 @@ app.registerExtension({
beforeConfigureGraph() { configuringGraph = true; configuration++; },
async setup() {
// One failing part must not take the others down; health.js shows what failed.
- for (const [where, start] of [['progress', () => progressConnection.start()], ['navigation', () => installNavigation(showStudio, agentInterfaceEnabled(api), {openWorkflow: openFreeVideoWorkflow})],
+ for (const [where, start] of [['progress', () => progressConnection.start()], ['navigation', () => installNavigation(showStudio, agentInterfaceState(api), {openWorkflow: openFreeVideoWorkflow, recheck: () => agentInterfaceState(api)})],
['updates', startUpdateChecks], ['done-notify', () => startDoneNotify({api, text, desktop: desktopNoticeEnabled, isFreeVideoNode})],
['whitebox', () => startWhiteboxWorker({api})]]) {
try { start(); } catch (error) { health({type: 'error', where, error}); }
diff --git a/web/studio.js b/web/studio.js
index 841e9e6..8b94c62 100644
--- a/web/studio.js
+++ b/web/studio.js
@@ -10,7 +10,7 @@ import { feedbackButton, feedbackIssueURL } from './feedback.js';
import { wordmark } from './wordmark.js';
import { createGenerationProgress, referenceTrimText, thermalText, sharedGpuText, encoderFileText, encoderFilePath } from './generation_progress.js';
import { viewSwitch, viewChanged, agentTabReady, openAutopilot } from './view_navigation.js';
-import { agentInterfaceEnabled } from './agent_connect.js';
+import { agentInterfaceState } from './agent_connect.js';
import { createUpdateNotice, createVersionInfo, productVersion } from './updates.js';
import { createPortNotice } from './port_notice.js';
import { reportIssue, reportTipClosed, showReportTip } from './report_issue.js';
@@ -655,7 +655,7 @@ export function openStudio(node, {extendFrom = null} = {}) {
const versionInfo = createVersionInfo(cn); tools.append(versionInfo.element); cleanup.push(versionInfo.dispose);
tools.append(feedbackButton(t), button(t('Settings', '设置'), openSetup, 'fv-quiet'));
// The Agent's page is the fourth tab, shown where the Agent interface is on; the guide's last step circles it.
- agentTabReady(agentInterfaceEnabled(api));
+ agentTabReady(agentInterfaceState(api), () => agentInterfaceState(api));
const navigation = viewSwitch('studio', () => {}, () => showNodes(node, dialog),
() => openEditorView(node, {studio: dialog}), () => openAutopilot(node, {studio: dialog}));
// The guide starts after the tab settles: it fixes its steps from the anchors present at that moment.
diff --git a/web/view_navigation.js b/web/view_navigation.js
index 26ed284..a58d1c3 100644
--- a/web/view_navigation.js
+++ b/web/view_navigation.js
@@ -33,10 +33,29 @@ export function viewChanged(view, node) {
refreshNavigation();
}
-// Whether this FreeVideo has the Agent interface on. The surfaces that open first (the toolbar, the studio) ask
-// and tell it here; a view switch shows its fourth tab only once the answer is yes.
-export function agentTabReady(answer) {
- agentTab = Promise.resolve(answer).then(on => on === true, () => false);
+// Whether this FreeVideo has the Agent interface on: 'on', 'off' or 'unknown' (true and false read as on and off).
+// The surfaces that open first (the toolbar, the studio) ask and tell it here. The fourth tab hides only when the
+// interface is off; a check that failed leaves it in place and asks again, waiting longer each time.
+let agentState = null, agentRun = null;
+const agentTabs = new Set();
+const asState = on => on === true || on === 'on' ? 'on' : on === false || on === 'off' ? 'off' : 'unknown';
+// On the Autopilot page itself the tab always shows.
+function showAgentTab(button, state = agentState) {
+ if (!button.dataset.here) button.hidden = state === 'off';
+ if (state === 'on') button.dataset.fvGuide = 'agent'; else delete button.dataset.fvGuide;
+}
+function settleAgentTab(state, recheck, run, tries) {
+ if (run !== agentRun) return;
+ agentState = state;
+ for (const ref of agentTabs) { const button = ref.deref(); if (button) showAgentTab(button); else agentTabs.delete(ref); }
+ if (state !== 'unknown' || !recheck || tries >= 6) return;
+ setTimeout(() => {
+ if (run === agentRun) Promise.resolve().then(recheck).then(asState, () => 'unknown').then(next => settleAgentTab(next, recheck, run, tries + 1));
+ }, 2000 * 2 ** tries);
+}
+export function agentTabReady(answer, recheck = null) {
+ const run = agentRun = {};
+ agentTab = Promise.resolve(answer).then(asState, () => 'unknown').then(state => { settleAgentTab(state, recheck, run, 0); return state; });
return agentTab;
}
@@ -60,8 +79,9 @@ export function viewSwitch(view, onStudio, onNodes, onEditor, onAutopilot) {
button.setAttribute('aria-pressed', String(view === id)); button.onclick = action;
if (id === 'autopilot') {
button.hidden = view !== id;
+ if (view === id) button.dataset.here = 'true';
// Settled once the tab is shown or known to stay away; the first-run guide waits for it.
- group.ready = (agentTab || Promise.resolve(false)).then(on => { if (on) { button.hidden = false; button.dataset.fvGuide = 'agent'; } });
+ group.ready = (agentTab || Promise.resolve('off')).then(state => { agentTabs.add(new WeakRef(button)); showAgentTab(button, agentState ?? state); });
}
group.append(button);
}
@@ -99,9 +119,9 @@ export function openCreativeWorkspace() {
return true;
}
-export function installNavigation(openStudio, agent = false, {openWorkflow = null} = {}) {
+export function installNavigation(openStudio, agent = false, {openWorkflow = null, recheck = null} = {}) {
open = openStudio;
- if (!toolbar) agentTabReady(agent);
+ if (!toolbar) agentTabReady(agent, recheck);
if (toolbar) { refreshNavigation(); return; }
toolbar = document.createElement('aside'); toolbar.className = 'fv-view-navigation';
toolbar.setAttribute('aria-label', t('FreeVideo workspace', 'FreeVideo 工作区'));