feat: IM平台列 + deviceID标识 + 会话持久化完善
- agent-96: chat_messages 加 platform 列(迁移0004) + IM主人私聊落主会话web(带platform) + 前端按平台过滤契约 + message_persisted 带 platform(复用 BroadcastPersisted) - agent-97: chat_messages 加 device_id 列(迁移0005) + history.Message.DeviceID + Web发消息带deviceId(localStorage getClientId) + IM persistToMain 带 deviceID + 前端气泡展示 SourceLabel + 修主会话基础2个bug(fn scanMessage语法/DDL缺列) - design/16 §4.4(平台) + §4.5(deviceID) 已入档 - 实机: POST /chat 带 deviceId 读回 user/assistant 均带 deviceId+platform; 后端 build/vet/test 绿 + 前端 build 绿 - 红线: 身份靠 actor 元数据; 禁止 shell 读 .env(JWT冒烟由主会话跑)
This commit is contained in:
1 parent
1bf60c1ae4
commit
37e98ec584
26 files changed
+828
-116
No files matched your search
@@ -113,7 +113,7 @@ type HistoryStore interface {
|
||||
// (with the assigned id/timestamp) so the orchestrator can broadcast it for
|
||||
// cross-end realtime sync (design/16 §4.2).
|
||||
AppendFull(ctx context.Context, msg history.Message) (history.Message, error)
|
||||
List(ctx context.Context, sessionID string, before int64, limit int) ([]history.Message, error)
|
||||
List(ctx context.Context, sessionID string, before int64, limit int, platform string) ([]history.Message, error)
|
||||
Recent(ctx context.Context, sessionID string, n int) ([]history.Message, error)
|
||||
DeleteSession(ctx context.Context, sessionID string) error
|
||||
NewSubSession(ctx context.Context, ownerID string) (string, error)
|
||||
@@ -459,20 +459,25 @@ func newOrchestrator(s *Server) *Orchestrator {
|
||||
Emit: func(sessionID, typ string, data map[string]any) {
|
||||
s.hub.broadcast(wsEvent{Type: typ, SessionID: sessionID, Data: data})
|
||||
},
|
||||
OnPersisted: func(msg history.Message) {
|
||||
// Broadcast the complete message so every browser of the same account
|
||||
// appends it without a manual refresh (design/16 §4.2). The frontend
|
||||
// dedups by the backend-generated id, and thinking is stripped to stay
|
||||
// consistent with the WS history replay (design/16 §6).
|
||||
wire := toHistoryMessage(msg)
|
||||
wire.Thinking = ""
|
||||
s.hub.broadcast(wsEvent{Type: "message_persisted", SessionID: msg.SessionID, Data: map[string]any{"message": wire}})
|
||||
},
|
||||
Log: s.log,
|
||||
History: s.history,
|
||||
OnPersisted: s.BroadcastPersisted,
|
||||
Log: s.log,
|
||||
History: s.history,
|
||||
})
|
||||
}
|
||||
|
||||
// BroadcastPersisted broadcasts a just-persisted chat message as a
|
||||
// `message_persisted` WS event so every browser of the same account appends it
|
||||
// without a manual refresh (design/16 §4.2). It is shared by the orchestrator
|
||||
// (Web turns) and the channel bridge (IM owner-private messages routed into the
|
||||
// main web session), so both paths emit the identical frame. Thinking is stripped
|
||||
// to stay consistent with the WS history replay (design/16 §6). It is a no-op-safe
|
||||
// call when the hub has broadcast wired.
|
||||
func (s *Server) BroadcastPersisted(msg history.Message) {
|
||||
wire := toHistoryMessage(msg)
|
||||
wire.Thinking = ""
|
||||
s.hub.broadcast(wsEvent{Type: "message_persisted", SessionID: msg.SessionID, Data: map[string]any{"message": wire}})
|
||||
}
|
||||
|
||||
// sourcedLog returns a logger tagged with source "gateway", substituting a
|
||||
// discard logger for nil so Server can always log safely.
|
||||
func sourcedLog(l *slog.Logger) *slog.Logger {
|
||||
|
||||
Reference in new issue
Block a user