feat: 同平台多账号支持 — adapter_name 贯穿全链路
- UnifiedMessage 新增 AdapterName 字段 - router 从适配器 ConfigName() 捕获 adapter 实例名 - forwardToAICore source 新增 adapter_name - ai-core SetBotUID key 优先用 adapter_name,回退 platform - 更新优化大纲加入 P4.1 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -871,7 +871,8 @@ func handleChat(
|
||||
SenderName string `json:"sender_name"`
|
||||
OriginalUID string `json:"original_uid"`
|
||||
BotUID string `json:"bot_uid"`
|
||||
GroupName string `json:"group_name,omitempty"`
|
||||
GroupName string
|
||||
AdapterName string `json:"group_name,omitempty"`
|
||||
} `json:"source,omitempty"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
@@ -888,9 +889,18 @@ func handleChat(
|
||||
if thinker != nil {
|
||||
thinker.RecordUserMessage(req.SessionID)
|
||||
if req.Source.Platform != "" && req.Source.BotUID != "" {
|
||||
thinker.SetBotUID(req.Source.Platform, req.Source.BotUID)
|
||||
adapterKey := req.Source.Platform
|
||||
if req.Source.AdapterName != "" {
|
||||
adapterKey = req.Source.AdapterName
|
||||
}
|
||||
thinker.SetBotUID(adapterKey, req.Source.BotUID)
|
||||
}
|
||||
if req.Source.Platform != "" && req.Source.ChannelID != "" {
|
||||
adapterKey := req.Source.Platform
|
||||
if req.Source.AdapterName != "" {
|
||||
adapterKey = req.Source.AdapterName
|
||||
}
|
||||
thinker.SetBotUID(adapterKey, req.Source.BotUID)
|
||||
thinker.AddOrUpdatePlatformChannel(req.Source.Platform, req.Source.ChannelType, req.Source.ChannelID, req.Source.GroupName)
|
||||
}
|
||||
}
|
||||
@@ -924,7 +934,11 @@ func handleChat(
|
||||
if thinker != nil {
|
||||
thinker.RecordUserMessage(req.SessionID)
|
||||
if req.Source.Platform != "" && req.Source.BotUID != "" {
|
||||
thinker.SetBotUID(req.Source.Platform, req.Source.BotUID)
|
||||
adapterKey := req.Source.Platform
|
||||
if req.Source.AdapterName != "" {
|
||||
adapterKey = req.Source.AdapterName
|
||||
}
|
||||
thinker.SetBotUID(adapterKey, req.Source.BotUID)
|
||||
}
|
||||
if req.Source.Platform != "" && req.Source.ChannelID != "" {
|
||||
thinker.AddOrUpdatePlatformChannel(req.Source.Platform, req.Source.ChannelType, req.Source.ChannelID, req.Source.GroupName)
|
||||
|
||||
@@ -665,6 +665,7 @@ func forwardToAICore(cfg *config.Config, msg *bridge.UnifiedMessage, mode, userI
|
||||
"original_uid": msg.OriginalSenderUID,
|
||||
"bot_uid": msg.BotUID,
|
||||
"group_name": msg.GroupName,
|
||||
"adapter_name": msg.AdapterName,
|
||||
},
|
||||
}
|
||||
if len(images) > 0 {
|
||||
|
||||
@@ -150,6 +150,11 @@ func (r *PlatformRouter) RouteMessage(adapterKey string, rawMsg interface{}) (*U
|
||||
unified.BotUID = selfAware.SelfID()
|
||||
}
|
||||
|
||||
// Capture adapter config name for multi-account routing.
|
||||
if named, ok := a.(interface{ ConfigName() string }); ok {
|
||||
unified.AdapterName = named.ConfigName()
|
||||
}
|
||||
|
||||
// Resolve identity (nil for unknown users; caller decides routing).
|
||||
// Use platform type (e.g. "qq") for identity resolution, not adapter key.
|
||||
identity := r.mapper.ResolveOrNil(a.PlatformName(), unified.SenderID)
|
||||
|
||||
@@ -29,6 +29,7 @@ type UnifiedMessage struct {
|
||||
GroupName string `json:"group_name,omitempty"` // resolved group name for group chats
|
||||
OriginalRawMessage interface{} `json:"-"` // preserved for SendMessage wiring
|
||||
BotUID string `json:"-"` // bot's own platform UID, set by router
|
||||
AdapterName string `json:"-"` // adapter config name (e.g. "qq-main"), set by router
|
||||
}
|
||||
|
||||
// Attachment represents a file/image/voice/video attachment.
|
||||
|
||||
Reference in New Issue
Block a user