47dce276a4
- 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>
91 lines
2.5 KiB
Go
91 lines
2.5 KiB
Go
package bridge
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
|
|
"git.yeij.top/AskaEth/Cyrene/platform-bridge/internal/permissions"
|
|
)
|
|
|
|
// IdentityMapper maps platform identities to Cyrene users.
|
|
type IdentityMapper struct {
|
|
mu sync.RWMutex
|
|
byPlatform map[string]map[string]*permissions.PlatformIdentity // platform -> platformUID -> identity
|
|
}
|
|
|
|
func NewIdentityMapper() *IdentityMapper {
|
|
return &IdentityMapper{
|
|
byPlatform: make(map[string]map[string]*permissions.PlatformIdentity),
|
|
}
|
|
}
|
|
|
|
// Register adds or updates a platform identity mapping.
|
|
func (m *IdentityMapper) Register(id permissions.PlatformIdentity) {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
if m.byPlatform[id.Platform] == nil {
|
|
m.byPlatform[id.Platform] = make(map[string]*permissions.PlatformIdentity)
|
|
}
|
|
m.byPlatform[id.Platform][id.PlatformUID] = &id
|
|
}
|
|
|
|
// Resolve finds the Cyrene user for a platform identity.
|
|
func (m *IdentityMapper) Resolve(platform, platformUID string) (*permissions.PlatformIdentity, error) {
|
|
m.mu.RLock()
|
|
defer m.mu.RUnlock()
|
|
plat, ok := m.byPlatform[platform]
|
|
if !ok {
|
|
return nil, fmt.Errorf("unknown platform: %s", platform)
|
|
}
|
|
id, ok := plat[platformUID]
|
|
if !ok {
|
|
return nil, fmt.Errorf("unknown user on %s: %s", platform, platformUID)
|
|
}
|
|
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()
|
|
defer m.mu.RUnlock()
|
|
plat, ok := m.byPlatform[platform]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
result := make([]permissions.PlatformIdentity, 0, len(plat))
|
|
for _, id := range plat {
|
|
result = append(result, *id)
|
|
}
|
|
return result
|
|
}
|
|
|
|
// ListAll returns all registered identities.
|
|
func (m *IdentityMapper) ListAll() map[string][]permissions.PlatformIdentity {
|
|
m.mu.RLock()
|
|
defer m.mu.RUnlock()
|
|
result := make(map[string][]permissions.PlatformIdentity)
|
|
for plat, users := range m.byPlatform {
|
|
for _, id := range users {
|
|
result[plat] = append(result[plat], *id)
|
|
}
|
|
}
|
|
return result
|
|
}
|