The sessions' handoff (交接文档) tab rendered every message body as escaped plain text: markdown in assistant replies stayed literal, code fences showed raw backticks, and tool input/output was one giant unhighlighted pre with no copy button. - new src/web/mdrender.ts: single escape-first Markdown + hand-rolled syntax-highlight core (json/diff/js/ts/py/sh lexers, GitHub light+dark palettes, unknown languages degrade to escaped text, zero runtime deps). Inlined into the browser IIFE via .toString() exactly like the JSONC helpers; tests/mdrender.test.ts pins behavior plus the self-contained inlining contract (esbuild-minified .toString() must run in a bare scope, mirroring the tsup pipeline). - web/markdown.ts becomes a thin wrapper over the same core, so the server-rendered handoff fallback and blog articles gain highlighting too. - client.ts renderHandoffMd: role cards (user/assistant/tool left border + badge), markdown-rendered bodies incl. thinking chains (collapsed by default), structured tool cards (input/output label, language detection json/diff, per-block copy button, JSON pretty-print, open when <= 20 lines), document meta (title/session id/token stats) rendered as a key/value box instead of being skipped. - styles.ts: card/token CSS vars in light + both dark palettes (#2559 verbatim-equality kept); i18n: det.io_in/det.io_out. - tests/web-handoff-roles.test.ts adapted to the new markup; the #2065 invariant (in-body headings never become role dividers) is preserved. CHANGELOG + docs/architecture/webui(.zh-CN).md + reference/architecture.md file map updated (architecture-docs lane green).
3.2 KiB
Module: web panel & admin surface (src/web + src/server/admin.ts)
Part of the architecture hub · 中文: webui.zh-CN.md · as of 2026-11-08, master
(bitmap fallback: webui.en.png)
Responsibility
Everything a human sees about the proxy: the session browser, logs, config, updates, notices, and the machine-facing admin routes (/__bili/*, /__acp/*) that ACP-native agents also call. The panel is a VIEW over the storage module — it never owns data.
Principles
- The panel never lies. A 0-block session exports nothing as "original conversation" (#155); storage degradation is surfaced, not hidden (
runtime-status); every data row can be traced to the storage rows it came from. - One notice channel. Every banner flows through ONE loop over
mergedNotices()— builtin (S), remote feed (A), local files (B); equal ids shadow B>A>S (#5548). No bespoke feed fetchers, dismissal stores, or inline banners. - Admin surface is gated. Loopback + trusted-origin checks (#1440) — the surface is control-plane, not public API.
How it works
Routes. admin.ts owns /__bili/* and /__acp/*: status (the attribution field makes broken plugin injection visible, #3581), overview, sessions + detail, logs, config, plugin, watcher, upstream. ACP-native agents use the same routes for compress/decompress/acp_status.
Data sources. The live session pool plus storage rows (tier tree, #3917); acp_status ranges/nudge are recomputed LIVE per render, never cached stale (acp-status.ts); the cache ledger economics (cache-ledger.ts, #1536); billing at USD prices with the payback view (#4899); notice dismissal receipts in unified storage (kv_store namespace notices).
Render. Server-rendered HTML shell (page.ts) + one JS bundle (client.ts) + styles; i18n.ts carries the zh-CN/en message tables (dead keys are test-guarded); mdrender.ts is the single escape-first Markdown + syntax-highlight core (hand-rolled lexers for json/diff/js/ts/py/sh, GitHub light+dark palettes, zero runtime deps — inlined into the browser IIFE via .toString() exactly like the JSONC helpers), and markdown.ts wraps it for the server side (blog articles + handoff fallback); report.ts builds dependency-free MD+SVG session reports; diagnostics.ts produces the paste-ready blob for issue reports (#3040).
Notices. mergedNotices() (src/announcements.ts) merges the three sources; the remote feed is this repo's announcements/remote.json, polled on the ~3-minute watcher cadence, fail-open (fetch problems keep the last-known-good snapshot; model traffic is never affected); builtin notices are dead-key-guarded by tests/notice-registry.test.ts.
Key entries
src/server/admin.ts (routes) · src/web/ (shell, bundle, i18n, report, diagnostics) · src/announcements.ts (notice registry) · src/notices.ts (builtins) · src/remote-notices.ts (feed poller) · src/notice-store.ts (receipts)
Related
storage · update (update actions live in the panel, #3719) · CONFIGURATION · announcements/remote.json