fix: platform_silent记忆提取 + 群聊上下文整合 + 多QQ实例支持

- platform_silent模式接入Orchestrator记忆提取:被动观察群聊时提取值得记住的信息到对应命名空间
- post_chat后台思考注入平台观察:对话后思考也能看到群聊摘要
- QQ适配器:OneBot v11 self_id动态捕获、CQ图片URL提取、视觉+OCR并行处理
- Router解耦:ConfigName/PlatformName分离,支持多QQ实例独立连接
- 黑白名单功能:后端API + Ethend代理 + UI面板
- \n\n双换行断句:AI回复按双换行分割为多条消息按间隔发送
- @提及修复:bot自感知UID进行@检测
- 群聊上下文共享:channel-based userID避免记忆碎片化
- 消息日志显示处理后内容而非原始SSE数据
- platform-bridge Dockerfile + docker-compose.yml更新

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-31 09:37:18 +08:00
parent 71f0a1abdb
commit 47dce276a4
22 changed files with 2375 additions and 313 deletions
@@ -44,6 +44,23 @@ func (m *IdentityMapper) Resolve(platform, platformUID string) (*permissions.Pla
return id, nil
}
// ResolveOrNil finds the Cyrene user for a platform identity, returning nil for unknown users.
func (m *IdentityMapper) ResolveOrNil(platform, platformUID string) *permissions.PlatformIdentity {
m.mu.RLock()
defer m.mu.RUnlock()
plat, ok := m.byPlatform[platform]
if !ok {
return nil
}
return plat[platformUID]
}
// IsAdmin returns true if the given platform user is a registered admin.
func (m *IdentityMapper) IsAdmin(platform, platformUID string) bool {
id := m.ResolveOrNil(platform, platformUID)
return id != nil && id.PermissionLevel == "admin"
}
// List returns all identities for a platform.
func (m *IdentityMapper) List(platform string) []permissions.PlatformIdentity {
m.mu.RLock()
@@ -1,12 +1,22 @@
package bridge
import (
"context"
"fmt"
"sync"
"git.yeij.top/AskaEth/Cyrene/platform-bridge/internal/permissions"
)
// adapterKey returns the unique key for an adapter in the router map.
// Uses ConfigName() if the adapter implements it, otherwise PlatformName().
func adapterKey(a PlatformAdapter) string {
if named, ok := a.(interface{ ConfigName() string }); ok {
return named.ConfigName()
}
return a.PlatformName()
}
// PlatformRouter manages all platform adapters and routes messages.
type PlatformRouter struct {
mu sync.RWMutex
@@ -37,11 +47,37 @@ func NewPlatformRouter(mapper *IdentityMapper, checker *permissions.Checker) *Pl
}
}
// RegisterAdapter adds a platform adapter.
// RegisterAdapter adds a platform adapter, keyed by its config name.
func (r *PlatformRouter) RegisterAdapter(a PlatformAdapter) {
r.mu.Lock()
defer r.mu.Unlock()
r.adapters[a.PlatformName()] = a
r.adapters[adapterKey(a)] = a
}
// RemoveAdapter disconnects and removes a platform adapter.
func (r *PlatformRouter) RemoveAdapter(platform string) {
r.mu.Lock()
a, ok := r.adapters[platform]
if ok {
delete(r.adapters, platform)
}
r.mu.Unlock()
if ok {
a.Disconnect(context.Background())
}
}
// ReplaceAdapter disconnects the old adapter (if present), registers the new one,
// and connects it. Returns an error if the new adapter fails to connect.
func (r *PlatformRouter) ReplaceAdapter(a PlatformAdapter) error {
key := adapterKey(a)
r.mu.Lock()
if old, ok := r.adapters[key]; ok {
old.Disconnect(context.Background())
}
r.adapters[key] = a
r.mu.Unlock()
return a.Connect(context.Background())
}
// GetAdapter returns the adapter for a platform.
@@ -55,7 +91,7 @@ func (r *PlatformRouter) GetAdapter(platform string) (PlatformAdapter, error) {
return a, nil
}
// ListAdapters returns all registered adapter names.
// ListAdapters returns all registered adapter names (config names).
func (r *PlatformRouter) ListAdapters() []string {
r.mu.RLock()
defer r.mu.RUnlock()
@@ -66,14 +102,28 @@ func (r *PlatformRouter) ListAdapters() []string {
return names
}
// GetAdaptersByPlatform returns all registered adapters for a given platform type.
func (r *PlatformRouter) GetAdaptersByPlatform(platform string) []PlatformAdapter {
r.mu.RLock()
defer r.mu.RUnlock()
var result []PlatformAdapter
for _, a := range r.adapters {
if a.PlatformName() == platform {
result = append(result, a)
}
}
return result
}
// SetMessageHandler sets the callback for processing unified messages.
func (r *PlatformRouter) SetMessageHandler(h MessageHandler) {
r.handler = h
}
// RouteMessage converts a platform message to unified, checks permissions, and dispatches.
func (r *PlatformRouter) RouteMessage(platform string, rawMsg interface{}) (*UnifiedResponse, error) {
a, err := r.GetAdapter(platform)
// adapterKey is the config name (e.g., "qq", "qq-home") used to look up the adapter instance.
func (r *PlatformRouter) RouteMessage(adapterKey string, rawMsg interface{}) (*UnifiedResponse, error) {
a, err := r.GetAdapter(adapterKey)
if err != nil {
return nil, err
}
@@ -83,18 +133,22 @@ func (r *PlatformRouter) RouteMessage(platform string, rawMsg interface{}) (*Uni
return nil, fmt.Errorf("convert to unified: %w", err)
}
// Resolve identity.
identity, err := r.mapper.Resolve(platform, unified.SenderID)
if err != nil {
return nil, fmt.Errorf("identity not found: %w", err)
// Preserve original platform UID before identity mapping.
unified.OriginalSenderUID = unified.SenderID
unified.OriginalRawMessage = rawMsg
// Capture bot's own UID for @mention detection.
if selfAware, ok := a.(interface{ SelfID() string }); ok {
unified.BotUID = selfAware.SelfID()
}
// Merge identity info into the unified message.
unified.SenderID = identity.CyreneUser
unified.SenderName = identity.Nickname
// Apply permission-based filtering.
_ = identity // used by permission checks on tools
// 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)
if identity != nil {
unified.SenderID = identity.CyreneUser
unified.SenderName = identity.Nickname
}
// Update channel context.
r.updateContext(unified)
@@ -108,8 +162,9 @@ func (r *PlatformRouter) RouteMessage(platform string, rawMsg interface{}) (*Uni
return nil, err
}
response.Platform = platform
response.PlatformHints = r.platformHints(platform)
// Use adapter key for response routing so SendResponse finds the correct instance.
response.Platform = adapterKey
response.PlatformHints = r.platformHints(adapterKey)
return response, nil
}
@@ -21,6 +21,12 @@ type UnifiedMessage struct {
RawData interface{} `json:"raw_data,omitempty"`
Timestamp time.Time `json:"timestamp"`
// Routing metadata.
RouteType string `json:"route_type,omitempty"` // "normal", "silent", "admin_mention"
OriginalSenderUID string `json:"original_sender_uid,omitempty"` // preserved before identity mapping
OriginalRawMessage interface{} `json:"-"` // preserved for SendMessage wiring
BotUID string `json:"-"` // bot's own platform UID, set by router
}
// Attachment represents a file/image/voice attachment.