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

+15
View File
@@ -1,6 +1,7 @@
import { create } from "zustand";
import { persist } from "zustand/middleware";
import type {
AdminChannelMessage,
AgentInfo,
AwakenState,
BackthinkItem,
@@ -45,6 +46,13 @@ export interface AppStore {
sessionBusy: boolean;
pendingCount: number;
/** 适配器消息日志实时事件(`channel_persisted` WS 帧,design/16 §4.6 §4)——
* 隔离会话(群聊/陌生人)落库后秒推,供 IM 适配器日志页增量插入。最新在前,
* 最多保留最近 ~200 条,按 id 去重。web 聊天无此字段的消费者。 */
channelEvents: AdminChannelMessage[];
/** Push one `channel_persisted` message (newest first, dedup by id, capped ~200). */
pushChannelEvent: (msg: AdminChannelMessage) => void;
/** 当前 persona(web 主会话=默认 persona)。加载前/失败时为 null,头像回退中性默认占位。 */
currentPersona: PersonaRecord | null;
@@ -116,6 +124,7 @@ export const useAppStore = create<AppStore>()(
pendingCount: 0,
currentPersona: null,
taskLogs: {},
channelEvents: [],
setWsStatus: (status) => set({ wsStatus: status }),
setCurrentPersona: (p) => set({ currentPersona: p }),
@@ -316,6 +325,12 @@ export const useAppStore = create<AppStore>()(
return { taskLogs };
}),
pushChannelEvent: (msg) =>
set((s) => {
if (s.channelEvents.some((m) => m.id === msg.id)) return s;
return { channelEvents: [msg, ...s.channelEvents].slice(0, 200) };
}),
resetChat: () =>
set((s) => ({
messages: [],