feat(channel,runtime): 批次2 后端 — 消息级角色归属进上下文 + IM 私聊随主会话角色 + 渠道级绑定
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

按 design/22 §2/§3/§4.4/§7(3/4/5)。
- ①「消息级角色归属」进入模型上下文(批次 1 只做存储+DTO):历史消息的发送角色现在对模型可见,且**不把系统元数据塞进用户正文**(design/11 §10 红线)
- ② IM owner 私聊镜像解析出的角色 = **主会话绑定的角色**(§7-3)
- ③ 渠道级绑定:ChannelAccount 加 personaId(channels.json 读写/校验/脱敏沿用既有约定)+ 角色解析优先级 **会话 > 渠道 > 默认** + **群聊/陌生人强制默认角色**(§7-4);admin 渠道配置端点支持 personaId
- Docs/api-client 版本 +1
- 验收:go build/vet/test 全绿 + linux/darwin 交叉编译
This commit is contained in:
AskaEth committed 2026-10-03 21:01:33 +08:00
1 parent 3732c538cc
commit 5969bba3bd
22 files changed
+1396 -23

No files matched your search

@@ -140,6 +140,14 @@ type Options struct {
// (channels.json → env fallback). When non-nil the bridge supports hot reload;
// nil keeps the bridge boot-only (Reload returns ErrNilFactory).
Factory PlatformFactory
// ChannelPersona, when non-nil, resolves the role bound to one channel account
// (channels.json ChannelAccount.PersonaID, design/22 §2 方案 b): it is called with
// the platform and the local account id, and returns "" when the account binds no
// role. It is consulted once per adapter connect/reload (never per message) and
// only for the owner's private chat, so a group/stranger conversation can never be
// moved into a role's scope (design/22 §7-4). Nil keeps every channel on the global
// default role.
ChannelPersona func(platform, accountID string) string
}
// Bridge owns the channel adapter lifecycle and the inbound message pipeline. It
@@ -181,6 +189,12 @@ type Bridge struct {
started bool
closed bool
factory PlatformFactory
// channelPersona resolves an account's channel-level role from the effective
// config (design/22 §2 方案 b); adapterPersona caches the resolved role per
// connected adapter so the inbound path never re-reads channels.json. Both are
// guarded by mu.
channelPersona func(platform, accountID string) string
adapterPersona map[string]string
// proactiveCursor is the rotation cursor for the proactive-push no-signal
// fallback (channelbridge/proactive.go), so the default channel is not always
// the first whitelisted owner channel. Guarded by mu.
@@ -251,6 +265,8 @@ func New(opts Options) (*Bridge, error) {
readCancels: make(map[string]context.CancelFunc),
gates: make(map[string]*adapter.FlowGate),
factory: opts.Factory,
channelPersona: opts.ChannelPersona,
adapterPersona: make(map[string]string),
cancel: func() {},
sem: make(chan struct{}, maxConcurrent),
}, nil