feat(channels): 适配器日志接 WS 实时推送(落库即秒推, channel_persisted)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

后端: persistIsolated 由 _ = full(不广播)改为 notifyPersisted(full); BroadcastPersisted 按
sessionId 分流——main/web:<uuid> → message_persisted(Web聊天同步), 隔离 sess-xxx → channel_persisted
(适配器日志专用, 永不写主会话 web, 红线). payload data:{message:historyMessage}(strip thinking).
前端: ws.ts 新增 channel_persisted case→parseAdminChannelMessage→pushChannelEvent; wsParse.ts 纯函数;
useAppStore 新增 channelEvents(最新在前,按id去重,cap200,不持久化); channelLogList 订阅过滤
(单adapter按adapterId/总览取adapterId非空)merge进列表(仅追加、id去重、不整页重载),保留拉历史+10s兜底.
Docs/api-client.md §3.4 补 channel_persisted 契约.
验收: 后端 build/vet/test 全绿+windows/darwin交叉编译绿; 前端 npm run build 99模块绿.
注: 偏离=web:<uuid> 归 message_persisted(保Web副会话同步), 隔离永不带web前缀红线仍守.
This commit is contained in:
Aska committed 2026-09-07 18:51:00 +08:00
1 parent 9e7b4ebaac
commit 3386679d45
10 files changed
+180 -23

No files matched your search

@@ -1,6 +1,7 @@
import { adminChannelMessages, adminChannelLogOverview } from "../../../lib/api";
import type { AdminChannelMessage } from "../../../lib/types";
import { useAsyncData } from "../../../lib/useAsyncData";
import { useAppStore } from "../../../store/useAppStore";
import { Button, Tag } from "../../../components/primitives";
import { Notice } from "../../components";
import { useAutoReload } from "../../hooks";
@@ -48,7 +49,20 @@ export function ChannelLogList({
[adapter, limit],
);
useAutoReload(reload, 10000);
const msgs = data ? [...data].reverse() : data;
// Realtime tail pushed by `channel_persisted` WS frames (design/16 §4.6 §4). The
// store keeps them newest-first, capped at 200 and deduped by id; we filter to the
// surface this list renders (single adapter, or the overview which shows adapter
// messages only), flip to oldest→newest, then append only ids the history page has
// not already covered. This makes a new persisted message appear without a reload;
// the 10s useAutoReload stays as a fallback for events the socket missed.
const channelEvents = useAppStore((s) => s.channelEvents);
const base = data ? [...data].reverse() : [];
const live = channelEvents
.filter((m) => (adapter ? m.adapterId === adapter : m.adapterId))
.reverse();
const seen = new Set(base.map((m) => m.id));
const msgs = [...base, ...live.filter((m) => !seen.has(m.id))];
return (
<div className={className}>