/* Brain of Reese — Sources page (knowledge base index view). * Scaffolding-stage: fetches /api/docs (implemented in the import phase); * until then it renders the empty state. */ const tbody = document.querySelector("#docs-tbody"); const emptyEl = document.querySelector("#sources-empty"); const tableWrap = document.querySelector(".table-wrap"); const statDocs = document.querySelector("#stat-docs"); const statChunks = document.querySelector("#stat-chunks"); const statLast = document.querySelector("#stat-last"); function fmtDate(iso) { try { return new Date(iso).toLocaleString(); } catch { return iso; } } async function loadDocs() { let r; try { r = await fetch("/api/docs"); } catch { showEmpty(); return; } if (!r.ok) { showEmpty(); return; } const { documents } = await r.json(); if (!documents.length) { showEmpty(); return; } tbody.innerHTML = ""; let totalChunks = 0; let last = ""; for (const d of documents) { totalChunks += d.chunks; if (d.indexed_at > last) last = d.indexed_at; const tr = document.createElement("tr"); tr.innerHTML = `