(function () { const esc = (s) => String(s ?? '').replace(/&/g, '&').replace(//g, '>'); const SEV_COLS = [ { key: 'critical', label: 'Crítico', cls: 'ao-kanban-col--critical' }, { key: 'high', label: 'Alto', cls: 'ao-kanban-col--high' }, { key: 'warn', label: 'Aviso', cls: 'ao-kanban-col--warn' }, { key: 'info', label: 'Info / OK', cls: 'ao-kanban-col--info' }, ]; const AGENT_ICONS = { A0: '🎯', A1: '💓', A2: '🛤', A3: '✉', A4: '🛡', A5: '👁', A6: '🤖', A7: '🔧', sentinel: '📡', curator: '📚', }; const AGENT_COLORS = { A0: '#6366f1', A1: '#22c55e', A2: '#3b82f6', A3: '#06b6d4', A4: '#8b5cf6', A5: '#ec4899', A6: '#a855f7', A7: '#ef4444', sentinel: '#f59e0b', curator: '#64748b', }; const SUB_VIEWS = [ { id: 'command', label: 'Squad Command', icon: '🎯' }, { id: 'agents', label: 'Agent Management', icon: '👥' }, { id: 'tasks', label: 'Task Board', icon: '📋' }, { id: 'memory', label: 'Knowledge Graph', icon: '🧠' }, { id: 'recurring', label: 'Recurring Tasks', icon: '🔄' }, { id: 'activity', label: 'Activity Feed', icon: '📡' }, ]; let state = { selectedAgent: 'A6', selectedIncidentId: null, threadId: null, mobileTab: 'board', mainTab: 'missions', subView: 'command', chatModalOpen: false, kbQuery: '', lastActions: [], pollTimer: null, }; let cache = null; let extraCache = { scenarios: null, activity: null, kbSources: null, kbHits: null }; let shellMounted = false; let eventsBound = false; let renderInFlight = false; let pendingRender = null; let lastThreadHtml = ''; let chatInFlight = false; async function agentsApi(path, opts = {}) { const h = authHeaders({ ...(opts.headers || {}) }); if (!(opts.body instanceof FormData) && !h['Content-Type']) h['Content-Type'] = 'application/json'; const isSlow = /\/chat$/.test(path) || path.includes('/chat'); const timeoutMs = isSlow ? 180000 : 60000; const r = await fetchWithTimeout(`/api/v1/agents${path}`, { ...opts, headers: h }, timeoutMs); if (r.status === 401) { logout(); throw new Error('sessão expirada — faça login novamente'); } if (!r.ok) throw new Error(`${r.status} ${(await r.text()).slice(0, 200)}`); return r.json(); } function escHtml(s) { return esc(s); } function renderMarkdown(text) { if (!text) return ''; const lines = String(text).split('\n'); const out = []; let inList = false; let inTable = false; const flushList = () => { if (inList) { out.push(''); inList = false; } }; const flushTable = () => { if (inTable) { out.push(''); inTable = false; } }; for (let i = 0; i < lines.length; i++) { const raw = lines[i]; const line = raw.trimEnd(); if (/^\|.+\|$/.test(line.trim())) { flushList(); const cells = line.trim().slice(1, -1).split('|').map((c) => c.trim()); if (/^[-:\s|]+$/.test(line.replace(/\|/g, ''))) continue; if (!inTable) { out.push(''); cells.forEach((c) => out.push(``)); out.push(''); inTable = true; } else { out.push(''); cells.forEach((c) => out.push(``)); out.push(''); } continue; } flushTable(); if (/^---+$/.test(line.trim())) { flushList(); out.push('
'); } else if (/^### (.+)/.test(line)) { flushList(); out.push(`

${inlineMd(line.replace(/^### /, ''))}

`); } else if (/^## (.+)/.test(line)) { flushList(); out.push(`

${inlineMd(line.replace(/^## /, ''))}

`); } else if (/^[-*] (.+)/.test(line)) { if (!inList) { out.push('
${inlineMd(c)}
${inlineMd(c)}