feat(webui): event inspector -- see captured payloads in the dashboard
Adds GET /api/captures (token-gated, matching the memory/skills enabled-false-not-an-error convention when Server.Captures is nil) and a new dashboard page at /captures listing recent inbound captures, newest first, with per-row expand to explore the redacted payload and headers pretty-printed. Live updates reuse the existing operator-activity event pipeline (Server.emit -> Events.Publish -> the /events SSE stream every other page already subscribes to) rather than polling or inventing new push plumbing: handleCapture now emits a Kind "capture" event with the same field shape the list endpoint returns, so a captured event appears in the inspector without a manual refresh. Frontend follows the tasks/task-row.js precedent: row rendering is split into ui/src/captures/capture-row.js so it can be unit tested without the page's fetch/SSE wiring. "Unbound" is shown for every row today since no binding data model exists yet (t2db.4) -- the column is wired now so that bead only needs to change what it renders, not add it.
This commit is contained in:
1 parent
101c133239
commit
37714928fc
13 files changed
+551
-12
No files matched your search
@@ -107,6 +107,7 @@ export const api = {
|
||||
return res.json();
|
||||
},
|
||||
logs: (params) => req("/api/logs" + qs(params)),
|
||||
captures: (limit) => req("/api/captures" + qs({ limit })),
|
||||
memory: () => req("/api/memory"),
|
||||
chatSessions: () => req("/api/chat/sessions"),
|
||||
chatMessages: (id) => req(`/api/chat/sessions/${encodeURIComponent(id)}/messages`),
|
||||
|
||||
@@ -16,6 +16,7 @@ const paths = {
|
||||
workflows: '<path d="M4 7h6a3 3 0 0 1 3 3v4a3 3 0 0 0 3 3h4"/><path d="M17 4l3 3-3 3"/><path d="M7 21l-3-3 3-3"/>',
|
||||
memory: '<circle cx="12" cy="12" r="3.2"/><path d="M12 3v3.4M12 17.6V21M3 12h3.4M17.6 12H21M5.6 5.6l2.4 2.4M16 16l2.4 2.4M18.4 5.6L16 8M8 16l-2.4 2.4"/>',
|
||||
channels: '<rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3.5 7l8.5 6 8.5-6"/>',
|
||||
captures: '<path d="M12 3v11M12 14l-4-4M12 14l4-4"/><path d="M4 14v4a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-4"/>',
|
||||
settings: '<circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 0 0 .3 1.9l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-2.9 1.2V21a2 2 0 1 1-4 0v-.1A1.7 1.7 0 0 0 7 19.4a1.7 1.7 0 0 0-1.9.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1A1.7 1.7 0 0 0 3 15H3a2 2 0 1 1 0-4h.1A1.7 1.7 0 0 0 4.6 7a1.7 1.7 0 0 0-.3-1.9l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1A1.7 1.7 0 0 0 9 3.6V3a2 2 0 1 1 4 0v.1A1.7 1.7 0 0 0 15 4.6h.1a1.7 1.7 0 0 0 1.9-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.9V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z"/>',
|
||||
search: '<circle cx="11" cy="11" r="7"/><path d="M20 20l-3.6-3.6"/>',
|
||||
moon: '<path d="M20 14.5A8.5 8.5 0 0 1 9.5 4a8.5 8.5 0 1 0 10.5 10.5z"/>',
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import { ago, el, pill } from "../base/dom.js";
|
||||
|
||||
/**
|
||||
* One captured event's summary row, plus its expandable detail row when
|
||||
* expanded is true. Split out from captures.js so it can be unit tested
|
||||
* without the page's fetch/SSE wiring, mirroring tasks/task-row.js.
|
||||
*/
|
||||
export function captureRow(c, { expanded, onToggle }) {
|
||||
const row = el(
|
||||
"tr.capture-row",
|
||||
{
|
||||
tabindex: "0",
|
||||
"aria-expanded": String(expanded),
|
||||
onclick: onToggle,
|
||||
onkeydown: (e) => {
|
||||
if (e.key !== "Enter" && e.key !== " ") return;
|
||||
e.preventDefault();
|
||||
onToggle(e);
|
||||
},
|
||||
},
|
||||
el("td.mono", c.source || "(unknown)"),
|
||||
el("td", { title: c.received_at || "" }, ago(c.received_at)),
|
||||
// Every captured event is unbound today: no playbook binding data model
|
||||
// exists yet (t2db.4). Once a binding can match an event, this pill
|
||||
// distinguishes bound from unbound instead of always reading "Unbound"
|
||||
// -- see docs/prds/event-capture-storage.md's "what this does not decide".
|
||||
el("td", pill("Unbound", "idle")),
|
||||
el("td.mono", c.content_type || "—"),
|
||||
el("td", el("button.btn.btn-small", { type: "button" }, expanded ? "Hide" : "View")),
|
||||
);
|
||||
return expanded ? [row, captureDetailRow(c)] : [row];
|
||||
}
|
||||
|
||||
export function captureDetailRow(c) {
|
||||
return el(
|
||||
"tr.capture-detail-row",
|
||||
el(
|
||||
"td",
|
||||
{ colspan: 5 },
|
||||
el(
|
||||
"div.capture-detail",
|
||||
el("div.capture-detail-section", el("div.capture-detail-title", "Payload"), payloadView(c.body)),
|
||||
el("div.capture-detail-section", el("div.capture-detail-title", "Headers"), payloadView(c.headers)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function payloadView(raw) {
|
||||
if (!raw) return el("div.capture-empty", "(empty)");
|
||||
return el("pre.capture-payload", prettyPrint(raw));
|
||||
}
|
||||
|
||||
// prettyPrint indents valid JSON for readability; a non-JSON payload (the
|
||||
// capture endpoint stores whatever arrives, JSON or not, per
|
||||
// docs/prds/webhook-intake-security.md) is shown as-is rather than failing
|
||||
// to render.
|
||||
export function prettyPrint(raw) {
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(raw), null, 2);
|
||||
} catch {
|
||||
return raw;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/* Event inspector: captured payloads, explorable per row. */
|
||||
|
||||
.capture-row {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.capture-row:hover {
|
||||
background: var(--bg-raised);
|
||||
}
|
||||
|
||||
.capture-row:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
.capture-detail-row td {
|
||||
padding: var(--sp-3) var(--sp-3) var(--sp-4);
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.capture-detail {
|
||||
display: grid;
|
||||
gap: var(--sp-4);
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
|
||||
.capture-detail-section {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.capture-detail-title {
|
||||
font-size: var(--text-xs);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
color: var(--fg-subtle);
|
||||
margin-bottom: var(--sp-2);
|
||||
}
|
||||
|
||||
.capture-payload {
|
||||
background: var(--bg-raised);
|
||||
border: 1px solid var(--border-strong);
|
||||
border-radius: var(--radius-sm);
|
||||
padding: var(--sp-3);
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--text-xs);
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
max-height: 24rem;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.capture-empty {
|
||||
color: var(--fg-muted);
|
||||
font-size: var(--text-sm);
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.capture-detail {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
import "./captures.css";
|
||||
import { api, subscribeEvents } from "../base/api.js";
|
||||
import { el, empty, mount, pill } from "../base/dom.js";
|
||||
import { captureRow } from "./capture-row.js";
|
||||
|
||||
/**
|
||||
* Event inspector (t2db.2): the operator-facing half of capture. Recent
|
||||
* inbound events, newest first, with the full redacted payload explorable
|
||||
* per row -- see docs/prds/event-capture-storage.md for what the backend
|
||||
* guarantees (retention, redaction, disk bounds).
|
||||
*
|
||||
* Live updates ride the same /events SSE stream every other page uses
|
||||
* (Server.emit publishes a "capture" kind event on every successful
|
||||
* capture) rather than polling, so a captured event appears here without a
|
||||
* manual refresh.
|
||||
*/
|
||||
export function capturesPage() {
|
||||
const root = el("div");
|
||||
const list = el("div.card");
|
||||
const streamState = pill("connecting", "idle");
|
||||
|
||||
let captures = [];
|
||||
let expandedId = null;
|
||||
let loadError = null;
|
||||
let enabled = true;
|
||||
|
||||
render();
|
||||
load();
|
||||
|
||||
const unsubscribe = subscribeEvents(
|
||||
(event) => {
|
||||
if (event.kind !== "capture" || event.data?.id == null) return;
|
||||
captures = [event.data, ...captures.filter((c) => c.id !== event.data.id)].slice(0, 200);
|
||||
renderRows();
|
||||
},
|
||||
(state) => {
|
||||
streamState.className = `pill pill-${state === "live" ? "ok" : "warn"}`;
|
||||
streamState.textContent = state;
|
||||
},
|
||||
);
|
||||
root.addEventListener("archie:teardown", unsubscribe);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
const res = await api.captures(100);
|
||||
enabled = res.enabled !== false;
|
||||
captures = res.captures || [];
|
||||
loadError = null;
|
||||
} catch (err) {
|
||||
loadError = String(err.message || err);
|
||||
}
|
||||
renderRows();
|
||||
}
|
||||
|
||||
function render() {
|
||||
mount(
|
||||
root,
|
||||
el(
|
||||
"div.page-head",
|
||||
el(
|
||||
"div",
|
||||
el("h1.page-title", "Event inspector"),
|
||||
el("p.page-sub", "Real inbound payloads archie has captured, most recent first."),
|
||||
),
|
||||
el("div.page-actions", streamState, el("button.btn", { onclick: load }, "Refresh")),
|
||||
),
|
||||
list,
|
||||
);
|
||||
renderRows();
|
||||
}
|
||||
|
||||
function renderRows() {
|
||||
if (loadError) {
|
||||
mount(list, empty("Cannot reach archied", loadError));
|
||||
return;
|
||||
}
|
||||
if (!enabled) {
|
||||
mount(list, empty("Capture is not configured", "This deployment has no capture storage wired up."));
|
||||
return;
|
||||
}
|
||||
if (!captures.length) {
|
||||
mount(
|
||||
list,
|
||||
empty("No captures yet", "Point a webhook at /webhooks/capture/<source> and it will show up here."),
|
||||
);
|
||||
return;
|
||||
}
|
||||
mount(
|
||||
list,
|
||||
el(
|
||||
"div.table-scroll",
|
||||
el(
|
||||
"table.table",
|
||||
el(
|
||||
"thead",
|
||||
el(
|
||||
"tr",
|
||||
...["Source", "Received", "Binding", "Content type", ""].map((h) => el("th", h)),
|
||||
),
|
||||
),
|
||||
el("tbody", ...captures.flatMap((c) => captureRow(c, {
|
||||
expanded: expandedId === c.id,
|
||||
onToggle: () => {
|
||||
expandedId = expandedId === c.id ? null : c.id;
|
||||
renderRows();
|
||||
},
|
||||
}))),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { workflowsPage } from "./workflows/workflows.js";
|
||||
import { channelsPage } from "./channels/channels.js";
|
||||
import { settingsPage } from "./settings/settings.js";
|
||||
import { logsPage } from "./logs/logs.js";
|
||||
import { capturesPage } from "./captures/captures.js";
|
||||
import { memoryPage } from "./memory/memory.js";
|
||||
import { chatPage } from "./chat/chat.js";
|
||||
|
||||
@@ -24,6 +25,7 @@ const routes = [
|
||||
{ path: "/chat", label: "Chat", icon: "chat", view: chatPage },
|
||||
{ path: "/tasks", label: "Tasks", icon: "tasks", view: tasksPage },
|
||||
{ path: "/logs", label: "Logs", icon: "logs", view: logsPage },
|
||||
{ path: "/captures", label: "Event inspector", icon: "captures", view: capturesPage },
|
||||
{ path: "/skills", label: "Skills", icon: "skills", view: skillsPage },
|
||||
{ path: "/workflows", label: "Workflows", icon: "workflows", view: workflowsPage },
|
||||
{ path: "/memory", label: "Memory", icon: "memory", view: memoryPage },
|
||||
|
||||
Reference in new issue
Block a user