feat(backthink): 主动推送 sink 打通——hub.SendProactive + bridge.SendProactive + wire 接线
backthink 决策+路由(P2)就绪但无投递 sink(ActiveClient/IMAdapter 无实现)。补齐: - gateway/proactive.go: hub.SendProactive 向 owner/admin 连接广播 proactive_message WS事件, 内容脱敏(去RawData/media/token),返回接收数,count=0→IM兜底;Server.SendProactive 委托 - channelbridge/proactive.go: Bridge.SendProactive 解析 owner 账户(msg.Platform→匹配白名单账号, 否则首个已配置主人频道),ChannelType=Direct+ChannelID/SenderID=owner id,走 adapter.SendProactive - backthink/sinks.go: SetActiveSink/SetIMSink 晚注入(New后重建pusher,currentPusher 并发安全) - wire.go: 在 gw/bridge 建好后 bt.SetActiveSink(gw)/SetIMSink(bridge) - 投递链: think→parseProactive→ShouldPush→currentPusher.Push→gate→active(active_client)/IM(im_bridge) →record(route+送达数) - 测试: sinks/gateway proactive/channelbridge proactive; 后端 build/vet/test 全绿 - 注: -race 本机 TSan 不可用(环境); 多平台IM按msg.Platform匹配 owner 账号(单sink诚实); weixin 24h窗口按 ErrProactiveWindow 记录为 im_bridge 错误不静默
This commit is contained in:
1 parent
2283383b9e
commit
6a2b8b9f12
9 files changed
+615
-6
No files matched your search
@@ -157,6 +157,7 @@ type Backthink struct {
|
||||
log *slog.Logger
|
||||
store *Store
|
||||
pusher Pusher
|
||||
gate PushGate
|
||||
now func() time.Time
|
||||
sessionID string
|
||||
|
||||
@@ -187,12 +188,13 @@ func New(cfg Config, deps Deps) (*Backthink, error) {
|
||||
return nil, fmt.Errorf("backthink: new: %w", err)
|
||||
}
|
||||
|
||||
// Resolve the gate up front so the sink setters can rebuild the pusher with it.
|
||||
gate := deps.Gate
|
||||
if gate == nil {
|
||||
gate = newRateGate(cfg.MaxPushWindow, cfg.PushWindow, log)
|
||||
}
|
||||
pusher := deps.Pusher
|
||||
if pusher == nil {
|
||||
gate := deps.Gate
|
||||
if gate == nil {
|
||||
gate = newRateGate(cfg.MaxPushWindow, cfg.PushWindow, log)
|
||||
}
|
||||
pusher = newPusher(deps.Active, deps.IM, gate, log)
|
||||
}
|
||||
|
||||
@@ -211,6 +213,7 @@ func New(cfg Config, deps Deps) (*Backthink, error) {
|
||||
log: log,
|
||||
store: store,
|
||||
pusher: pusher,
|
||||
gate: gate,
|
||||
now: now,
|
||||
sessionID: sessionID,
|
||||
}, nil
|
||||
@@ -407,7 +410,7 @@ func (b *Backthink) think(parent context.Context, tr Trigger) {
|
||||
|
||||
pushRes := PushResult{Route: RouteNone, Detail: b.interruptReason(push, at, state)}
|
||||
if shouldPush {
|
||||
pushRes = b.pusher.Push(cctx, PushRequest{
|
||||
pushRes = b.currentPusher().Push(cctx, PushRequest{
|
||||
Message: b.buildProactiveMessage(message, channelHint),
|
||||
ChannelHint: channelHint,
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user