From d5fbd6fa069df06a405d6f1814bad50194527a50 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Tue, 30 Jun 2026 17:40:04 +0800 Subject: [PATCH] feat(webui): multi-tab debug console + embedded API browser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase 6 of the debug-console expansion — the four pieces become one console: 测试台 / 消息构建 / 实时活动 / API 浏览器, behind an Apple-HIG sliding-indicator tab bar. - ApiBrowser: a searchable, category-grouped reference for every declarative action (~520), straight from /api/debug/actions — params / returns / invariants / role + readOnly + stream badges. Each row's 试一下 prefills the tester and switches to it (ActionTester gains a presetAction prop keyed by nonce). - Tester / compose / activity stay MOUNTED and toggle via CSS, so the live feed's SSE never drops — it keeps capturing events fired while you invoke from the tester tab (the invoke-then-observe loop) — and in-progress params/messages survive a peek at another tab. The API browser, heavy and stateless, mounts on demand. Adversarially reviewed: no crash / leak / mis-trigger; the review caught that conditional-mounting silently dropped cross-tab live events and discarded in-progress work — fixed by keeping the stateful panels mounted. --- .../src/components/debug/action-tester.tsx | 6 +- .../src/components/debug/api-browser.tsx | 137 ++++++++++++++++++ .../src/components/debug/live-activity.tsx | 2 +- .../webui/src/components/pages/debug-page.tsx | 48 +++++- 4 files changed, 183 insertions(+), 10 deletions(-) create mode 100644 packages/webui/src/components/debug/api-browser.tsx diff --git a/packages/webui/src/components/debug/action-tester.tsx b/packages/webui/src/components/debug/action-tester.tsx index 2a23c0eb..fd7916db 100644 --- a/packages/webui/src/components/debug/action-tester.tsx +++ b/packages/webui/src/components/debug/action-tester.tsx @@ -53,7 +53,7 @@ function Field({ label, children }: { label: ReactNode; children: ReactNode }) { ); } -export function ActionTester({ accounts, docs }: { accounts: QQInfo[]; docs: DebugActionDoc[] }) { +export function ActionTester({ accounts, docs, presetAction }: { accounts: QQInfo[]; docs: DebugActionDoc[]; presetAction?: { name: string; nonce: number } }) { const api = useApi(); const tasks = useDebugTasks(); @@ -72,6 +72,10 @@ export function ActionTester({ accounts, docs }: { accounts: QQInfo[]; docs: Deb useEffect(() => { setHistory(loadHistory()); }, []); useEffect(() => { if (accounts[0] && !uin) setUin(accounts[0].uin); }, [accounts, uin]); + // Prefill from the API browser's 试一下 (nonce lets the same action re-trigger). + useEffect(() => { + if (presetAction) { setActionName(presetAction.name); setParamMode('form'); setResult(null); setFrames([]); setShowHistory(false); } + }, [presetAction]); const doc = useMemo(() => docs.find((d) => d.name === actionName), [docs, actionName]); const effectiveMode = paramMode === 'json' || !doc ? 'json' : 'form'; diff --git a/packages/webui/src/components/debug/api-browser.tsx b/packages/webui/src/components/debug/api-browser.tsx new file mode 100644 index 00000000..f1b8a643 --- /dev/null +++ b/packages/webui/src/components/debug/api-browser.tsx @@ -0,0 +1,137 @@ +// ApiBrowser — an embedded, searchable reference for every declarative action +// (~520), grouped by category, surfaced straight from /api/debug/actions (the +// same docs the tester uses). Each row expands to params / returns / invariants +// and a 试一下 button that prefills the tester. No hand-maintained docs — this +// is the live catalog. +import { useMemo, useState } from 'react'; +import { motion } from 'motion/react'; +import { BookOpen, ChevronRight, PlayCircle, Search, ShieldCheck, Zap } from 'lucide-react'; +import { cn } from '@/lib/utils'; +import type { DebugActionDoc } from '@/types'; + +const cardCls = 'rounded-2xl border border-border/60 bg-card/80 shadow-[0_1px_2px_rgb(0_0_0/0.04),0_8px_24px_-12px_rgb(0_0_0/0.10)] backdrop-blur-sm'; + +function ActionRow({ doc, onTry }: { doc: DebugActionDoc; onTry: (name: string) => void }) { + const [open, setOpen] = useState(false); + return ( +
+ + {open && ( +
+ {doc.aliases.length > 0 && ( +

别名:{doc.aliases.map((a) => {a})}

+ )} + {doc.params.length > 0 ? ( +
+ + + + + + {doc.params.map((p) => ( + + + + + + + ))} + +
参数类型必填说明
{p.name}{p.values ? p.values.map(String).join(' | ') : p.type}{p.role ? ·{p.role} : null}{p.required ? '✓' : '–'}{p.desc ?? ''}{p.default !== undefined ? ` (默认 ${JSON.stringify(p.default)})` : ''}
+
+ ) :

无参数

} + {doc.invariants && doc.invariants.length > 0 && ( +

约束:{doc.invariants.join(';')}

+ )} + {doc.returns &&

返回:{doc.returns}

} +
+ +
+
+ )} +
+ ); +} + +export function ApiBrowser({ docs, onTry }: { docs: DebugActionDoc[]; onTry: (name: string) => void }) { + const [query, setQuery] = useState(''); + const [cat, setCat] = useState(''); + + const categories = useMemo(() => { + const set = new Set(); + for (const d of docs) if (d.category) set.add(d.category); + return Array.from(set).sort(); + }, [docs]); + + const filtered = useMemo(() => { + const q = query.trim().toLowerCase(); + return docs.filter((d) => { + if (cat && d.category !== cat) return false; + if (!q) return true; + return d.name.toLowerCase().includes(q) + || (d.summary?.toLowerCase().includes(q) ?? false) + || d.aliases.some((a) => a.toLowerCase().includes(q)); + }); + }, [docs, query, cat]); + + const grouped = useMemo(() => { + const m = new Map(); + for (const d of filtered) { + const k = d.category ?? '其他'; + const arr = m.get(k) ?? []; + arr.push(d); + m.set(k, arr); + } + return Array.from(m.entries()).sort((a, b) => a[0].localeCompare(b[0])); + }, [filtered]); + + return ( + +
+ +

API 浏览器

+ {filtered.length}/{docs.length} +
+ +
+ + setQuery(e.target.value)} placeholder="搜索 action 名 / 摘要 / 别名…" + className="min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground" /> +
+ +
+ + {categories.map((c) => ( + + ))} +
+ +
+ {grouped.length === 0 ? ( +

无匹配 action

+ ) : grouped.map(([category, items]) => ( +
+

{category} {items.length}

+ {items.map((d) => )} +
+ ))} +
+
+ ); +} diff --git a/packages/webui/src/components/debug/live-activity.tsx b/packages/webui/src/components/debug/live-activity.tsx index d407e675..eac53d87 100644 --- a/packages/webui/src/components/debug/live-activity.tsx +++ b/packages/webui/src/components/debug/live-activity.tsx @@ -25,7 +25,7 @@ function IconBtn({ onClick, title, children }: { onClick: () => void; title: str ); } -export function StatusPill({ status }: { status: 'open' | 'reconnecting' | 'closed' }) { +function StatusPill({ status }: { status: 'open' | 'reconnecting' | 'closed' }) { const map = { open: { dot: 'bg-emerald-500', label: '已连接', glow: 'shadow-[0_0_0_3px_rgb(16_185_129/0.15)]' }, reconnecting: { dot: 'bg-amber-500', label: '重连中', glow: 'shadow-[0_0_0_3px_rgb(245_158_11/0.15)]' }, diff --git a/packages/webui/src/components/pages/debug-page.tsx b/packages/webui/src/components/pages/debug-page.tsx index 88e115f4..a4c032a3 100644 --- a/packages/webui/src/components/pages/debug-page.tsx +++ b/packages/webui/src/components/pages/debug-page.tsx @@ -1,18 +1,27 @@ -// Debug — a standalone top-level page. The action tester and live activity are -// extracted into their own components (ActionTester / LiveActivity); the -// multi-tab console shell lands in a later phase. Apple-HIG flavour throughout. +// Debug — a multi-tab developer console over /api/debug/*. Tabs: the action +// tester, the visual message composer, the live activity feed, and an embedded +// API browser. The browser's 试一下 prefills the tester and switches to it. +// Apple-HIG flavour throughout (sliding-indicator tabs, translucent chrome). import { useEffect, useState } from 'react'; import { motion } from 'motion/react'; -import { Bug } from 'lucide-react'; +import { BookOpen, Bug, FlaskConical, MessageSquarePlus, RadioTower } from 'lucide-react'; +import { cn } from '@/lib/utils'; +import { Tabs } from '@/components/ui/tabs'; import { ActionTester } from '@/components/debug/action-tester'; +import { MessageComposer } from '@/components/debug/message-composer'; import { LiveActivity } from '@/components/debug/live-activity'; +import { ApiBrowser } from '@/components/debug/api-browser'; import { useApi } from '@/lib/api'; import type { DebugActionDoc, QQInfo } from '@/types'; +type Tab = 'tester' | 'compose' | 'activity' | 'api'; + export function DebugPage() { const api = useApi(); const [accounts, setAccounts] = useState([]); const [docs, setDocs] = useState([]); + const [tab, setTab] = useState('tester'); + const [preset, setPreset] = useState<{ name: string; nonce: number } | undefined>(); useEffect(() => { void (async () => { @@ -24,11 +33,16 @@ export function DebugPage() { })(); }, [api]); + const tryAction = (name: string) => { + setPreset((p) => ({ name, nonce: (p?.nonce ?? 0) + 1 })); + setTab('tester'); + }; + return (
@@ -36,13 +50,31 @@ export function DebugPage() {

调试

-

接口测试台与实时活动观测

+

接口测试 · 消息构建 · 实时观测 · API 参考

+ }, + { value: 'compose', label: '消息构建', icon: }, + { value: 'activity', label: '实时活动', icon: }, + { value: 'api', label: 'API 浏览器', icon: , badge: docs.length || undefined }, + ]} + />
- - + {/* Tester / compose / activity stay MOUNTED and toggle via CSS so the + live feed's SSE never drops (it must capture events fired from other + tabs) and in-progress params/messages survive a peek at another tab. + ApiBrowser has no state worth preserving and is heavy (~520 rows), so + it mounts on demand. */} +
+
+
+ {tab === 'api' && }
); }