feat(webui): role-driven action tester with streaming + history

Phase 4 of the debug-console expansion — the tester no longer makes you
hand-write JSON. Each param renders the right smart control from its
semantic role: group/friend/member pickers (member linked to the sibling
group_id), FileSource for media, FaceGrid, datetime for timestamps,
switch for bool, select for enum — with the raw-JSON escape hatch kept.

- Read-only actions badge green, side-effecting amber; a name-pattern set
  of destructive actions (kick/ban/recall/delete/…) confirms first.
- Stream API actions invoke over /api/debug/invoke-stream and render
  frames live, tracked in the app-level task registry with progress; a
  clean success requires the terminal response frame, and a failed frame
  shows its reason (not just the {type:'error'} marker).
- Every call lands in capped localStorage history with one-click replay;
  responses render in a collapsible JsonTree.
- Extracted LiveActivity (filter / search / export) and the Segmented
  control into their own components; debug-page is now a thin host.

Adversarially reviewed: stream terminal-frame judging, member/group
linkage, and contract shapes verified; fixed the failed-stream-frame
reason being hidden, a latent required-enum controlled-select trap, stale
member value on group change, and several low UX edges.
This commit is contained in:
DrSmoothl committed 2026-06-30 17:17:15 +08:00
1 parent c5611ed622
commit 11866caa2f
6 files changed
+765 -324

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
// debug-history — a capped, localStorage-backed ring buffer of recent action
// invocations for the tester (replay / inspect). Client-only and ephemeral by
// design: it's a debugging convenience, not a persisted record, so there is no
// backend store. Newest first.
export interface InvokeRecord {
id: string;
at: number;
uin: string;
action: string;
params: Record<string, unknown>;
ok: boolean;
/** wall-clock ms, when known. */
ms?: number;
/** true if invoked via the streaming transport. */
stream?: boolean;
}
const LS_KEY = 'snowluma.debug.history.v1';
const CAP = 200;
let seq = 0;
export function loadHistory(): InvokeRecord[] {
try {
const raw = localStorage.getItem(LS_KEY);
if (!raw) return [];
const arr = JSON.parse(raw) as InvokeRecord[];
return Array.isArray(arr) ? arr : [];
} catch { return []; }
}
export function pushHistory(rec: Omit<InvokeRecord, 'id'>): InvokeRecord[] {
const full: InvokeRecord = { ...rec, id: `h-${rec.at.toString(36)}-${(seq++).toString(36)}` };
const next = [full, ...loadHistory()].slice(0, CAP);
try { localStorage.setItem(LS_KEY, JSON.stringify(next)); } catch { /* quota — drop silently */ }
return next;
}
export function clearHistory(): void {
try { localStorage.removeItem(LS_KEY); } catch { /* ignore */ }
}