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

+10
View File
@@ -2,6 +2,7 @@ import { useAppStore } from "../store/useAppStore";
import { useModeStore } from "../store/useModeStore";
import { getAuthToken, isTokenExpired, onAuthExpired, setAuthToken } from "./api";
import {
parseAdminChannelMessage,
parseAgent,
parseAwakenTool,
parseGraph,
@@ -85,6 +86,15 @@ function dispatch(ev: { type: string; data: unknown }): void {
}
break;
}
case "channel_persisted": {
// design/16 §4.6 §4 — an isolated (group/stranger) channel message was
// persisted and broadcast for the IM adapter log page. The web chat has no
// handler for this type, so it never reaches the active conversation; the
// admin adapter log consumes it via `channelEvents` to append in realtime.
const msg = parseAdminChannelMessage(r?.message);
if (msg) s.pushChannelEvent(msg);
break;
}
case "thinking.start": {
pendingThinking = "";
break;
+26 -1
View File
@@ -1,4 +1,4 @@
import { MODES, type AgentInfo, type ChatMessage, type FlowGraph, type Mode, type ToolUsed } from "./types";
import { MODES, type AdminChannelMessage, type AgentInfo, type ChatMessage, type FlowGraph, type Mode, type ToolUsed } from "./types";
import { now, uid } from "./util";
/**
@@ -158,3 +158,28 @@ export function parsePersistedMessage(v: unknown): ChatMessage | null {
createdAt: typeof r.createdAt === "number" ? r.createdAt : now(),
};
}
/** Build an AdminChannelMessage from a `channel_persisted` payload (design/16
* §4.6 §4): the backend broadcast a fully-persisted isolated (group/stranger)
* channel message carrying the backend id + adapter id, for the IM adapter log
* page to append in realtime. Requires id + sessionId; role/content fall back to
* defaults so a malformed frame is dropped rather than rendered. */
export function parseAdminChannelMessage(v: unknown): AdminChannelMessage | null {
const r = toRecord(v);
if (!r) return null;
const id = typeof r.id === "string" && r.id ? r.id : "";
const sessionId = typeof r.sessionId === "string" && r.sessionId ? r.sessionId : "";
if (!id || !sessionId) return null;
return {
id,
sessionId,
role: typeof r.role === "string" ? r.role : "user",
content: typeof r.content === "string" ? r.content : "",
mode: typeof r.mode === "string" ? r.mode : undefined,
platform: typeof r.platform === "string" && r.platform ? r.platform : undefined,
deviceId: typeof r.deviceId === "string" && r.deviceId ? r.deviceId : undefined,
adapterId: typeof r.adapterId === "string" && r.adapterId ? r.adapterId : undefined,
senderName: typeof r.senderName === "string" && r.senderName ? r.senderName : undefined,
createdAt: typeof r.createdAt === "number" ? r.createdAt : now(),
};
}