${esc(a.name)} ${esc(a.id)}
- ${(a.actions || []).slice(0, 3).map(x => `
- ${esc(x)} `).join('')}
(function () {
const esc = (s) => String(s ?? '').replace(/&/g,'&').replace(//g,'>');
let state = { threadId: null, selectedAgent: 'A6' };
/** Usa o helper global do Desk (app.js) — garante JWT igual aos outros módulos. */
async function agentsApi(path, opts = {}) {
const deskApi = typeof globalThis.api === 'function' ? globalThis.api : null;
if (deskApi) return deskApi(`/v1/agents${path}`, opts);
const h = authHeaders({ ...(opts.headers || {}) });
if (!(opts.body instanceof FormData) && !h['Content-Type']) h['Content-Type'] = 'application/json';
const r = await fetchWithTimeout(`/api/v1/agents${path}`, { ...opts, headers: h }, 60000);
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 agentCard(a) {
const active = state.selectedAgent === a.id ? ' agentic-agent-active' : '';
return ` ${esc((m.body || '').slice(0, 280))}${esc(a.name)} ${esc(a.id)}
${(a.actions || []).slice(0, 3).map(x => `
Carregando thread…
'; const data = await agentsApi(`/threads/${threadId}/messages`); box.innerHTML = data.messages.map(threadBubble).join('') || 'Sem mensagens.
'; box.scrollTop = box.scrollHeight; } async function renderAgenticOps() { const el = document.getElementById('agentic-ops-content'); if (!el) return; el.innerHTML = 'Carregando Agentic Ops…
'; if (!getToken()) { el.innerHTML = 'Sessão não encontrada neste endereço. Fazer login (use sempre o mesmo URL — ex. desk.ligbox.com.br).
'; return; } if (typeof ensureValidSession === 'function') { const ok = await ensureValidSession(); if (!ok) { el.innerHTML = 'Sessão expirada. Fazer login
'; return; } } try { const [health, roster, inbox, threads, findings] = await Promise.all([ agentsApi('/health'), agentsApi('/roster'), agentsApi('/inbox?limit=20'), agentsApi('/threads?limit=15'), agentsApi('/findings?limit=15'), ]); const tier = health.tier === 't1' ? 'T1 LLM' : 'T0'; const ollama = health.ollama ? `Ollama · ${esc(health.model)}` : 'Ollama offline'; const agents = roster.agents || []; const inboxItems = inbox.messages || []; const threadOpts = (threads.threads || []).map(t => `` ).join(''); const fRows = (findings.findings || []).map(f => `Inbox vazia.
'}A pensar…
'; try { const res = await agentsApi('/chat', { method: 'POST', body: JSON.stringify({ question: q, include_findings: true, target_agent: state.selectedAgent }), }); out.innerHTML = `${esc(state.selectedAgent)}
${esc(res.answer)}
`; if (res.thread_id) { state.threadId = res.thread_id; await loadThread(el, res.thread_id); } } catch (err) { out.innerHTML = `${esc(err.message)}
`; } }); if (state.threadId) await loadThread(el, state.threadId); } catch (err) { el.innerHTML = `Erro: ${esc(err.message)}
`; } } window.renderAgenticOps = renderAgenticOps; })();