'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 => `| Name | Category | Description |
|---|
${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 => `| When | Tool | Duration | Outcome |
|---|
${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();