Fix Vision Protocol: rename shadowed ts var, load agents dynamically

const ts = ts() in loadVision caused TDZ ReferenceError crashing gallery.
visionRunScreenshot now fetches online agents from agents_list API when
no screenshots exist yet (previously showed No agents online falsely).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 18:21:44 +00:00
parent d3d2b36257
commit 8298353106
+7 -4
View File
@@ -2922,7 +2922,7 @@ async function loadVision() {
} }
gallery.innerHTML = shots.map(s => { gallery.innerHTML = shots.map(s => {
const ts = ts(s.created_at); const shotTs = ts(s.created_at);
const has = s.file_size > 0; const has = s.file_size > 0;
const meth = (s.method || 'unknown').toUpperCase(); const meth = (s.method || 'unknown').toUpperCase();
const dim = s.width && s.height ? `${s.width}×${s.height}` : ''; const dim = s.width && s.height ? `${s.width}×${s.height}` : '';
@@ -2939,7 +2939,7 @@ async function loadVision() {
◈ ${dim ? dim + ' · ' : ''}${Math.round((s.file_size||0)/1024)}KB IMAGE ◈ ${dim ? dim + ' · ' : ''}${Math.round((s.file_size||0)/1024)}KB IMAGE
</div>` : '<div style="font-size:0.6rem;color:var(--dim);margin-bottom:6px;font-family:var(--mono)">TEXT SNAPSHOT ONLY</div>'} </div>` : '<div style="font-size:0.6rem;color:var(--dim);margin-bottom:6px;font-family:var(--mono)">TEXT SNAPSHOT ONLY</div>'}
${analysis ? `<div style="font-size:0.62rem;line-height:1.5;color:var(--text-dim)">${esc(analysis)}${s.vision_analysis?.length>180?'…':''}</div>` : ''} ${analysis ? `<div style="font-size:0.62rem;line-height:1.5;color:var(--text-dim)">${esc(analysis)}${s.vision_analysis?.length>180?'…':''}</div>` : ''}
<div style="font-family:var(--mono);font-size:0.55rem;color:var(--border2);margin-top:6px">${ts}</div> <div style="font-family:var(--mono);font-size:0.55rem;color:var(--border2);margin-top:6px">${shotTs}</div>
</div> </div>
</div>`; </div>`;
}).join(''); }).join('');
@@ -2965,8 +2965,11 @@ async function visionViewScreenshot(id) {
} }
async function visionRunScreenshot() { async function visionRunScreenshot() {
// Pick agent from dropdown or prompt let agents = _visionAgents.length ? _visionAgents : null;
const agents = _visionAgents; if (!agents) {
const all = await api('agents_list');
agents = (Array.isArray(all) ? all : []).filter(a => a.status === 'online').map(a => a.hostname).filter(Boolean);
}
if (!agents.length) { if (!agents.length) {
toast('No agents online — check AGENTS tab', 'err'); return; toast('No agents online — check AGENTS tab', 'err'); return;
} }