feat: PlatformChannel 支持 AdapterID/AdapterName — 多账号全链路区分
- PlatformChannel 新增 AdapterID + AdapterName 字段 - AddOrUpdatePlatformChannel 接受 adapter 信息参数 - channel_sync 传递 adapter_id/adapter_name - 消息处理路径传递 adapter_name Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -48,6 +48,8 @@ func doSync(thinker *background.Thinker, client *http.Client, baseURL, token str
|
||||
ChannelType string `json:"channel_type"`
|
||||
ChannelID string `json:"channel_id"`
|
||||
ChannelName string `json:"channel_name,omitempty"`
|
||||
AdapterID string `json:"adapter_id,omitempty"`
|
||||
AdapterName string `json:"adapter_name,omitempty"`
|
||||
} `json:"channels"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||
@@ -56,7 +58,7 @@ func doSync(thinker *background.Thinker, client *http.Client, baseURL, token str
|
||||
}
|
||||
|
||||
for _, ch := range result.Channels {
|
||||
thinker.AddOrUpdatePlatformChannel(ch.Platform, ch.ChannelType, ch.ChannelID, ch.ChannelName)
|
||||
thinker.AddOrUpdatePlatformChannel(ch.Platform, ch.ChannelType, ch.ChannelID, ch.ChannelName, ch.AdapterID, ch.AdapterName)
|
||||
}
|
||||
|
||||
// Also fetch platforms to get bot UIDs.
|
||||
|
||||
@@ -967,7 +967,7 @@ func handleChat(
|
||||
adapterKey = req.Source.AdapterName
|
||||
}
|
||||
thinker.SetBotUID(adapterKey, req.Source.BotUID)
|
||||
thinker.AddOrUpdatePlatformChannel(req.Source.Platform, req.Source.ChannelType, req.Source.ChannelID, req.Source.GroupName)
|
||||
thinker.AddOrUpdatePlatformChannel(req.Source.Platform, req.Source.ChannelType, req.Source.ChannelID, req.Source.GroupName, "", req.Source.AdapterName)
|
||||
}
|
||||
}
|
||||
// 图片预处理:静默观察时也分析图片内容,供后台思考使用
|
||||
@@ -1007,7 +1007,7 @@ func handleChat(
|
||||
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)
|
||||
thinker.AddOrUpdatePlatformChannel(req.Source.Platform, req.Source.ChannelType, req.Source.ChannelID, req.Source.GroupName, "", req.Source.AdapterName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,8 @@ type PlatformChannel struct {
|
||||
ChannelType string // group, private
|
||||
ChannelID string // group ID or user OBv11 number
|
||||
ChannelName string // group name or user display name (resolved at runtime)
|
||||
AdapterID string // unique config ID of the adapter instance
|
||||
AdapterName string // config name, e.g. "qq-main"
|
||||
}
|
||||
|
||||
// PlatformFormat describes how proactive message targets are formatted for a platform.
|
||||
@@ -312,7 +314,7 @@ func (t *Thinker) SetBotUID(platform, uid string) {
|
||||
}
|
||||
|
||||
// AddOrUpdatePlatformChannel adds or updates a platform channel with resolved display name.
|
||||
func (t *Thinker) AddOrUpdatePlatformChannel(platform, channelType, channelID, channelName string) {
|
||||
func (t *Thinker) AddOrUpdatePlatformChannel(platform, channelType, channelID, channelName, adapterID, adapterName string) {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
|
||||
@@ -321,6 +323,12 @@ func (t *Thinker) AddOrUpdatePlatformChannel(platform, channelType, channelID, c
|
||||
if channelName != "" {
|
||||
t.platformChannels[i].ChannelName = channelName
|
||||
}
|
||||
if adapterID != "" {
|
||||
t.platformChannels[i].AdapterID = adapterID
|
||||
}
|
||||
if adapterName != "" {
|
||||
t.platformChannels[i].AdapterName = adapterName
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -330,6 +338,8 @@ func (t *Thinker) AddOrUpdatePlatformChannel(platform, channelType, channelID, c
|
||||
ChannelType: channelType,
|
||||
ChannelID: channelID,
|
||||
ChannelName: channelName,
|
||||
AdapterID: adapterID,
|
||||
AdapterName: adapterName,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user