import { useEffect, useState } from 'react'; import { useParams } from 'react-router-dom'; import { getAgentSummary, HttpError } from '../api'; import type { AgentSummary } from '../types'; import { Link } from 'react-router-dom'; import { fmtRelative, fmtTime } from '../util'; export function AgentActivityPage() { const { id } = useParams<{ id: string }>(); const [data, setData] = useState(null); const [err, setErr] = useState(null); const [needsKey, setNeedsKey] = useState(false); const [pendingKey, setPendingKey] = useState(''); useEffect(() => { if (!id) return; const ac = new AbortController(); getAgentSummary(id, ac.signal) .then((d) => { setData(d); setErr(null); setNeedsKey(false); }) .catch((e) => { if ((e as Error).name === 'AbortError') return; if (e instanceof HttpError && (e.status === 401 || e.status === 403)) { setNeedsKey(true); setErr(null); } else { setErr((e as Error).message); } }); return () => ac.abort(); }, [id]); function saveKey() { if (!pendingKey.trim()) return; localStorage.setItem('dialectic-admin-key', pendingKey.trim()); setPendingKey(''); window.location.reload(); } if (!id) return
missing agent id
; return (
agent

{id}

{needsKey && (
this page calls an admin endpoint — paste your x-dialectic-admin-key (stored in localStorage; never sent except to /api/admin/*).
setPendingKey(e.target.value)} placeholder="admin key…" />
key never leaves this browser
)} {err &&
{err}
} {data && ( <>
{data.key_provisioned ? 'yes' : 'no'}
key provisioned
{data.signups_count}
signups
{data.arguments_count}
arguments
{data.verdicts_count}
verdicts

recent topics

{data.recent_topics.length === 0 ? (
no recent topics for this agent
) : ( {data.recent_topics.map((t) => ( ))}
topic role status last action
{t.title} {t.role} {t.status} {fmtRelative(t.last_action_at)}
)} )}
); }