'use strict'; const tokenInput = document.getElementById('token'); const panels = { health: document.getElementById('health'), tools: document.getElementById('tools'), stats: document.getElementById('stats'), recent: document.getElementById('recent'), }; function headers() { const t = tokenInput.value.trim(); return t ? { 'Authorization': `Bearer ${t}` } : {}; } async function fetchJson(path) { const res = await fetch(path, { headers: headers() }); if (!res.ok) throw new Error(`${res.status} ${res.statusText}`); return res.json(); } function render(panel, html) { panels[panel].innerHTML = html; } async function showHealth() { try { const data = await fetchJson('/health'); render('health', `
${JSON.stringify(data, null, 2)}
`); } catch (e) { render('health', `

${e.message}

`); } } async function showTools() { try { const data = await fetchJson('/api/v1/tools'); const rows = data.tools.map(t => `${t.name}${t.category}${t.description}` ).join(''); render('tools', `${rows}
NameCategoryDescription
`); } catch (e) { render('tools', `

${e.message}

`); } } async function showStats() { try { const data = await fetchJson('/api/v1/state/stats'); render('stats', `
${JSON.stringify(data, null, 2)}
`); } catch (e) { render('stats', `

${e.message}

`); } } async function showRecent() { try { const data = await fetchJson('/api/v1/state/recent'); const rows = data.invocations.map(r => `${r.invoked_at}${r.tool}${r.duration_ms}ms${r.outcome.status}` ).join(''); render('recent', `${rows}
WhenToolDurationOutcome
`); } catch (e) { render('recent', `

${e.message}

`); } } const loaders = { health: showHealth, tools: showTools, stats: showStats, recent: showRecent }; document.querySelectorAll('nav button').forEach(btn => { btn.addEventListener('click', () => { const target = btn.dataset.panel; document.querySelectorAll('nav button').forEach(b => b.classList.remove('active')); btn.classList.add('active'); Object.values(panels).forEach(p => p.hidden = true); panels[target].hidden = false; loaders[target](); }); }); document.querySelector('nav button[data-panel="health"]').click();