import { h, Fragment } from "preact";
import { useState, useEffect } from "preact/hooks";
import "./captures.css";
import { api, subscribeEvents } from "../base/api.jsx";
import { CaptureRow } from "./capture-row.jsx";
import { Pill } from "../base/pill.jsx";
export function Empty({ title, detail }) {
return (
{title}
{detail &&
{detail}
}
);
}
/**
* 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. That event is deliberately lightweight (id + source only,
* no payload -- see handleCapture's comment on why): it is treated purely
* as an invalidation signal, triggering a refetch of the authoritative list
* rather than being merged into local state directly.
*/
export function capturesPage(query) {
return ;
}
function CapturesApp({ query }) {
const [captures, setCaptures] = useState([]);
const [expandedId, setExpandedId] = useState(null);
const [loadError, setLoadError] = useState(null);
const [enabled, setEnabled] = useState(true);
const [streamState, setStreamState] = useState({ text: "connecting", kind: "idle" });
const load = async () => {
try {
const res = await api.captures(100);
setEnabled(res.enabled !== false);
setCaptures(res.captures || []);
setLoadError(null);
} catch (err) {
setLoadError(String(err.message || err));
}
};
useEffect(() => {
load();
const unsubscribe = subscribeEvents(
(event) => {
if (event.kind !== "capture") return;
load();
},
(state) => {
setStreamState({
text: state,
kind: state === "live" ? "ok" : "warn",
});
}
);
return () => unsubscribe();
}, []);
const renderRows = () => {
if (loadError) {
return ;
}
if (!enabled) {
return ;
}
if (!captures.length) {
return ;
}
return (
{["Source", "Received", "Binding", "Content type", ""].map((h, i) => (
| {h} |
))}
{captures.map((c) => (
setExpandedId(expandedId === c.id ? null : c.id)}
/>
))}
);
};
return (
Event inspector
Real inbound payloads archie has captured, most recent first.
{renderRows()}
);
}