feat(notify): IM 路由的主动消息也在非前台补浏览器通知(契约 v0.74)
主人裁定 C 的必然推论:她该不该提醒我,与后端走了哪条路由无关。P0 如实报回的缺口 = 通知只挂在 proactive_message 帧上,而 auto 提示在有已连接 IM 渠道时优先走 IM ⇒ 最常发生的路径恰恰不弹。 判据(先查现状、不猜):行字段**区分不出**主动推送与普通回复(已用真库证据排除 platform/adapterId/turnId 反推)⇒ 新增**结构化的正向声明**:帧顶 data.proactive === true,只由主动推送那条通道打(gateway.BroadcastProactivePersisted);普通路径永远传 false。 - 后端:channelbridge 抽出唯一写入口径 persistMain + 新增 proactive_notify 接缝;gateway 抽出 broadcastPersisted(msg, proactive) 两入口共用 - 前端:handlers/proactive-notice.ts 两条帧路共用同一套提醒运行时(有界去重 + 降级说明 + DOM/Notification 取值);message.ts 读到判据才走提醒 - 对照断言(必须有):普通 IM 回复/主人提问/显式 proactive:false ⇒ **0 通知、3 气泡**(不误伤) - 变异实测:去掉非主动保护 / 跨两路去重失效 / 前台也弹 / IM 不发判据帧 / 普通广播带判据 ⇒ 5 条全部打红 - 契约 v0.74(纯增量:message_persisted 新增可选 proactive:true) - 边界(如实):判据**不落库**(翻历史不弹提醒,也不得从行字段反推);落库失败时不发判据帧(无权威 id 的帧前端整帧丢弃)
This commit is contained in:
1 parent
a6cb44b8a8
commit
f4adf0b526
13 files changed
+652
-122
No files matched your search
@@ -20,14 +20,30 @@ import (
|
||||
// 会话。Thinking 会被抹除,以与 WS 历史回放保持一致(design/16 §6)。
|
||||
// 当 hub 接好广播时它是安全空操作。两种帧类型都携带消息内容,
|
||||
// 因此 design/11 §7.1 帧门只把它们投递给 owner/admin 连接。
|
||||
//
|
||||
// 它**绝不**带 `proactive` 键:普通消息的帧顶永远没有那个结构化判据,客户端因此
|
||||
// 不可能把普通消息误判成主动消息去弹通知(切片 P0b 的「不误伤」那一条)。主动推送
|
||||
// 那条路走 BroadcastProactivePersisted(proactive.go)。
|
||||
func (s *Server) BroadcastPersisted(msg history.Message) {
|
||||
s.broadcastPersisted(msg, false)
|
||||
}
|
||||
|
||||
// broadcastPersisted 是上面两个入口共用的帧构造与扇出:proactive 决定帧顶是否带上
|
||||
// 「这是她主动说的话」的结构化判据 `proactive:true`(切片 P0b,见 proactive.go 的
|
||||
// BroadcastProactivePersisted)。两条入口走**同一个**函数,因此帧类型推导、thinking
|
||||
// 抹除与角色门(design/11 §7.1)逐字一致 —— 差别只有那一个键。
|
||||
func (s *Server) broadcastPersisted(msg history.Message, proactive bool) {
|
||||
wire := toHistoryMessage(msg)
|
||||
wire.Thinking = ""
|
||||
typ := "channel_persisted"
|
||||
if msg.SessionID == history.MainSessionID || strings.HasPrefix(msg.SessionID, history.MainSessionID+":") {
|
||||
typ = "message_persisted"
|
||||
}
|
||||
s.hub.broadcast(wsEvent{Type: typ, SessionID: msg.SessionID, Data: map[string]any{"message": wire}})
|
||||
data := map[string]any{"message": wire}
|
||||
if proactive {
|
||||
data["proactive"] = true
|
||||
}
|
||||
s.hub.broadcast(wsEvent{Type: typ, SessionID: msg.SessionID, Data: data})
|
||||
}
|
||||
|
||||
// wsCapacityAwaken 是能力状态迁移的 WS 事件类型(design/14 §5)。
|
||||
|
||||
Reference in new issue
Block a user