From f153781208691da20206effda590d2a2e39c0dc3 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Thu, 18 Jun 2026 15:44:05 +0800 Subject: [PATCH] feat(webui): promote debug to a standalone page, Apple-style redesign MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the debug console out of the Settings 调试 subtab into a dedicated top-level /debug page (sidebar nav + route + AppPath), and redesign it in an Apple-HIG flavour: translucent sticky header with title block + connection pill, soft layered cards (rounded-2xl, hairline borders, blurred backdrop), an iOS-style segmented control with a sliding active pill (params form/JSON, stream all/event/action filter), refined timeline rows + empty state, calm type hierarchy with tabular-nums. Logic (tester + live SSE) carried over verbatim. Remove the old settings/debug-panel + the Settings 'debug' subtab. --- .../webui/src/components/layout/sidebar.tsx | 3 +- .../webui/src/components/pages/debug-page.tsx | 358 ++++++++++++++++++ .../src/components/pages/settings-page.tsx | 3 - .../src/components/settings/debug-panel.tsx | 254 ------------- packages/webui/src/router/index.tsx | 15 +- 5 files changed, 372 insertions(+), 261 deletions(-) create mode 100644 packages/webui/src/components/pages/debug-page.tsx delete mode 100644 packages/webui/src/components/settings/debug-panel.tsx diff --git a/packages/webui/src/components/layout/sidebar.tsx b/packages/webui/src/components/layout/sidebar.tsx index bffdd7e3..1feb4258 100644 --- a/packages/webui/src/components/layout/sidebar.tsx +++ b/packages/webui/src/components/layout/sidebar.tsx @@ -1,4 +1,4 @@ -import { Check, Eye, EyeOff, GripVertical, LayoutDashboard, Lock, PlugZap, Settings, Sparkles, SlidersHorizontal, Terminal } from 'lucide-react'; +import { Bug, Check, Eye, EyeOff, GripVertical, LayoutDashboard, Lock, PlugZap, Settings, Sparkles, SlidersHorizontal, Terminal } from 'lucide-react'; import { motion, Reorder } from 'motion/react'; import { Link, useRouterState } from '@tanstack/react-router'; import { ScrollArea } from '@/components/ui/scroll-area'; @@ -21,6 +21,7 @@ export const NAV_ITEMS: NavItem[] = [ { to: '/processes', label: '进程注入', icon: PlugZap, description: '加载 / 卸载 / 登录' }, { to: '/config', label: '节点配置', icon: Settings, description: 'OneBot 协议端点' }, { to: '/logs', label: '日志', icon: Terminal, description: '实时事件流' }, + { to: '/debug', label: '调试', icon: Bug, description: '测试台与实时活动' }, { to: '/settings', label: '系统设置', icon: SlidersHorizontal, description: '主题与账号' }, ]; diff --git a/packages/webui/src/components/pages/debug-page.tsx b/packages/webui/src/components/pages/debug-page.tsx new file mode 100644 index 00000000..7dc63217 --- /dev/null +++ b/packages/webui/src/components/pages/debug-page.tsx @@ -0,0 +1,358 @@ +// Debug — a standalone top-level page (Wave A3, redesigned). Apple-HIG flavour: +// clarity (calm type hierarchy, generous whitespace), deference (translucent +// chrome, content-first), depth (soft layered cards, a sliding segmented +// control). Two tools over /api/debug/*: +// • Action 测试台 — pick account + action (schema form / raw JSON), invoke. +// • 实时活动 — merged live SSE of events + action calls. +import { useEffect, useId, useMemo, useRef, useState, type ReactNode } from 'react'; +import { motion } from 'motion/react'; +import { Activity, Bug, ChevronRight, FlaskConical, Loader2, Pause, Play, RadioTower, Trash2 } from 'lucide-react'; +import { Input } from '@/components/ui/input'; +import { Select } from '@/components/ui/select'; +import { Textarea } from '@/components/ui/textarea'; +import { useApi } from '@/lib/api'; +import { cn } from '@/lib/utils'; +import type { DebugActionDoc, DebugInvokeResult, DebugStreamMessage, QQInfo } from '@/types'; + +const STREAM_CAP = 300; + +interface StreamRow { id: number; at: number; msg: Extract } + +function coerceParam(type: string, raw: string): unknown { + if (raw === '') return undefined; + if (type.includes('int') || type === 'number' || type === 'uint') { + const n = Number(raw); + return Number.isFinite(n) ? n : raw; + } + if (type === 'bool' || type === 'boolean') return raw === 'true' || raw === '1'; + return raw; +} + +// ── iOS-style segmented control with a sliding active pill ── +function Segmented({ value, onChange, options }: { + value: T; onChange: (v: T) => void; options: { value: T; label: ReactNode }[]; +}) { + const id = useId(); + return ( +
+ {options.map((o) => { + const active = o.value === value; + return ( + + ); + })} +
+ ); +} + +function Field({ label, children }: { label: ReactNode; children: ReactNode }) { + return ( + + ); +} + +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'; + +export function DebugPage() { + const api = useApi(); + + // ── action tester ── + const [accounts, setAccounts] = useState([]); + const [docs, setDocs] = useState([]); + const [uin, setUin] = useState(''); + const [actionName, setActionName] = useState(''); + const [fields, setFields] = useState>({}); + const [paramMode, setParamMode] = useState<'form' | 'json'>('form'); + const [rawJson, setRawJson] = useState('{}'); + const [invoking, setInvoking] = useState(false); + const [result, setResult] = useState(null); + + const doc = useMemo(() => docs.find((d) => d.name === actionName), [docs, actionName]); + const effectiveMode = paramMode === 'json' || !doc ? 'json' : 'form'; + + useEffect(() => { + void (async () => { + try { + const [qq, acts] = await Promise.all([api.qqList(), api.debug.actions()]); + setAccounts(qq); + setDocs(acts.actions); + if (qq[0]) setUin(qq[0].uin); + } catch { /* surfaced lazily on invoke */ } + })(); + }, []); // eslint-disable-line react-hooks/exhaustive-deps + + const invoke = async () => { + if (!uin) { setResult({ error: '请选择账号' }); return; } + if (!actionName.trim()) { setResult({ error: '请填写 action' }); return; } + let params: Record = {}; + if (effectiveMode === 'json') { + try { params = JSON.parse(rawJson || '{}'); } catch { setResult({ error: 'params JSON 无效' }); return; } + if (typeof params !== 'object' || params === null || Array.isArray(params)) { setResult({ error: 'params 必须是对象' }); return; } + } else if (doc) { + for (const p of doc.params) { + const v = coerceParam(p.type, fields[p.name] ?? ''); + if (v !== undefined) params[p.name] = v; + } + } + setInvoking(true); + setResult(null); + try { setResult(await api.debug.invoke(uin, actionName.trim(), params)); } + catch (e) { setResult({ error: e instanceof Error ? e.message : '调用失败' }); } + finally { setInvoking(false); } + }; + + const resultFailed = !!result && ('error' in result || result.status === 'failed'); + + // ── live stream ── + const [rows, setRows] = useState([]); + const [paused, setPaused] = useState(false); + const [status, setStatus] = useState<'open' | 'reconnecting' | 'closed'>('closed'); + const [kindFilter, setKindFilter] = useState<'all' | 'event' | 'action'>('all'); + const pausedRef = useRef(paused); + pausedRef.current = paused; + const idRef = useRef(0); + + useEffect(() => { + const off = api.debug.stream( + (m) => { + if (m.kind === 'ready' || pausedRef.current) return; + setRows((prev) => { + const next = [{ id: idRef.current++, at: Date.now(), msg: m }, ...prev]; + return next.length > STREAM_CAP ? next.slice(0, STREAM_CAP) : next; + }); + }, + (s) => setStatus(s), + ); + return off; + }, []); // eslint-disable-line react-hooks/exhaustive-deps + + const visible = rows.filter((r) => kindFilter === 'all' || r.msg.kind === kindFilter); + + return ( +
+ {/* header */} + +
+
+ +
+
+

调试

+

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

+
+
+ +
+ +
+ {/* tester */} + +
+ +

Action 测试台

+
+
+ 调用会真实生效(真发消息 / 真踢人等),请谨慎。 +
+ +
+ + + + + { setActionName(e.target.value); setResult(null); }} /> + + {docs.map((d) => )} + + +
+ + {doc && ( +

+ {doc.summary}{doc.returns ? <> · 返回 {doc.returns} : null} +

+ )} + +
+ 参数 + setParamMode(m)} + options={[{ value: 'form', label: '表单' }, { value: 'json', label: 'JSON' }]} + /> +
+ + {effectiveMode === 'json' ? ( +