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
@@ -0,0 +1,44 @@
package handler
import (
"encoding/json"
"net/http"
"git.yeij.top/AskaEth/Cyrene/platform-bridge/internal/config"
)
// BlocklistHandler exposes CRUD for blocklist settings.
type BlocklistHandler struct {
store *config.BlocklistStore
}
func NewBlocklistHandler(store *config.BlocklistStore) *BlocklistHandler {
return &BlocklistHandler{store: store}
}
func (h *BlocklistHandler) RegisterRoutes(mux *http.ServeMux) {
mux.HandleFunc("/api/v1/settings/blocklist", h.handleBlocklist)
}
func (h *BlocklistHandler) handleBlocklist(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
writeJSON(w, http.StatusOK, h.store.Get())
case "POST", "PUT":
var bs config.BlocklistSettings
if err := json.NewDecoder(r.Body).Decode(&bs); err != nil {
writeJSON(w, http.StatusBadRequest, errResp("invalid JSON: "+err.Error()))
return
}
if err := h.store.Set(bs); err != nil {
writeJSON(w, http.StatusBadRequest, errResp(err.Error()))
return
}
writeJSON(w, http.StatusOK, map[string]interface{}{
"status": "saved",
"settings": h.store.Get(),
})
default:
writeJSON(w, http.StatusMethodNotAllowed, errResp("method not allowed"))
}
}
@@ -8,21 +8,27 @@ import (
"git.yeij.top/AskaEth/Cyrene/platform-bridge/internal/config"
)
var knownPlatforms = map[string]bool{
var validPlatformTypes = map[string]bool{
"qq": true, "telegram": true, "webhook": true,
"wechat": true, "feishu": true, "discord": true,
}
// ConfigHandler exposes CRUD endpoints for platform configs.
type ConfigHandler struct {
store *config.Store
router *bridge.PlatformRouter
store *config.Store
router *bridge.PlatformRouter
onChanged func(name, platform string, enabled bool, fields map[string]string)
}
func NewConfigHandler(store *config.Store, router *bridge.PlatformRouter) *ConfigHandler {
return &ConfigHandler{store: store, router: router}
}
// SetOnConfigChanged sets a callback invoked after config is saved or deleted.
func (h *ConfigHandler) SetOnConfigChanged(fn func(name, platform string, enabled bool, fields map[string]string)) {
h.onChanged = fn
}
func (h *ConfigHandler) RegisterRoutes(mux *http.ServeMux) {
mux.HandleFunc("/api/v1/configs", h.listConfigs)
mux.HandleFunc("/api/v1/configs/", h.handleConfig)
@@ -33,6 +39,7 @@ func (h *ConfigHandler) listConfigs(w http.ResponseWriter, r *http.Request) {
type configSummary struct {
Name string `json:"name"`
Platform string `json:"platform"`
Enabled bool `json:"enabled"`
Label string `json:"label,omitempty"`
Fields map[string]string `json:"fields"`
@@ -46,8 +53,13 @@ func (h *ConfigHandler) listConfigs(w http.ResponseWriter, r *http.Request) {
if a, err := h.router.GetAdapter(c.Name); err == nil {
connected = a.IsConnected()
}
platform := c.Platform
if platform == "" {
platform = c.Name
}
result = append(result, configSummary{
Name: c.Name,
Platform: platform,
Enabled: c.Enabled,
Label: c.Label,
Fields: c.Fields,
@@ -71,6 +83,7 @@ func (h *ConfigHandler) listConfigs(w http.ResponseWriter, r *http.Request) {
}
result = append(result, configSummary{
Name: name,
Platform: name,
Enabled: false,
Fields: map[string]string{},
Connected: connected,
@@ -92,10 +105,6 @@ func (h *ConfigHandler) handleConfig(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusBadRequest, errResp("missing config name"))
return
}
if !knownPlatforms[name] {
writeJSON(w, http.StatusBadRequest, errResp("unknown platform: "+name))
return
}
switch r.Method {
case "GET":
@@ -120,26 +129,37 @@ func (h *ConfigHandler) getConfig(w http.ResponseWriter, r *http.Request, name s
connected = a.IsConnected()
}
writeJSON(w, http.StatusOK, map[string]interface{}{
"name": cfg.Name,
"enabled": cfg.Enabled,
"label": cfg.Label,
"fields": cfg.Fields,
"updated_at": cfg.UpdatedAt.Format("2006-01-02T15:04:05Z07:00"),
"connected": connected,
"name": cfg.Name,
"platform": cfg.Platform,
"enabled": cfg.Enabled,
"label": cfg.Label,
"fields": cfg.Fields,
"updated_at": cfg.UpdatedAt.Format("2006-01-02T15:04:05Z07:00"),
"connected": connected,
})
}
func (h *ConfigHandler) saveConfig(w http.ResponseWriter, r *http.Request, name string) {
var body struct {
Enabled *bool `json:"enabled"`
Label string `json:"label"`
Fields map[string]string `json:"fields"`
Platform *string `json:"platform"`
Enabled *bool `json:"enabled"`
Label string `json:"label"`
Fields map[string]string `json:"fields"`
}
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
writeJSON(w, http.StatusBadRequest, errResp("invalid JSON: "+err.Error()))
return
}
platform := name
if body.Platform != nil && *body.Platform != "" {
platform = *body.Platform
}
if !validPlatformTypes[platform] {
writeJSON(w, http.StatusBadRequest, errResp("unknown or missing platform type: "+platform))
return
}
enabled := true
if body.Enabled != nil {
enabled = *body.Enabled
@@ -151,29 +171,48 @@ func (h *ConfigHandler) saveConfig(w http.ResponseWriter, r *http.Request, name
}
cfg := config.PlatformConfig{
Name: name,
Enabled: enabled,
Label: body.Label,
Fields: fields,
Name: name,
Platform: platform,
Enabled: enabled,
Label: body.Label,
Fields: fields,
}
if err := h.store.Set(cfg); err != nil {
writeJSON(w, http.StatusInternalServerError, errResp(err.Error()))
return
}
// Trigger hot-reload.
if h.onChanged != nil {
h.onChanged(name, platform, enabled, fields)
}
writeJSON(w, http.StatusOK, map[string]interface{}{
"name": name,
"enabled": enabled,
"label": body.Label,
"fields": fields,
"status": "saved",
"name": name,
"platform": platform,
"enabled": enabled,
"label": body.Label,
"fields": fields,
"status": "saved",
})
}
func (h *ConfigHandler) deleteConfig(w http.ResponseWriter, r *http.Request, name string) {
// Get platform type before deleting (needed for onChanged callback).
platform := name
if cfg, err := h.store.Get(name); err == nil && cfg.Platform != "" {
platform = cfg.Platform
}
if err := h.store.Delete(name); err != nil {
writeJSON(w, http.StatusNotFound, errResp(err.Error()))
return
}
// Trigger hot-reload: disable and clear fields.
if h.onChanged != nil {
h.onChanged(name, platform, false, nil)
}
writeJSON(w, http.StatusOK, map[string]string{"status": "deleted", "name": name})
}
@@ -4,16 +4,18 @@ import (
"net/http"
"strconv"
"git.yeij.top/AskaEth/Cyrene/platform-bridge/internal/config"
"git.yeij.top/AskaEth/Cyrene/platform-bridge/internal/logging"
)
// LogHandler exposes message log retrieval endpoints.
type LogHandler struct {
logger *logging.Logger
store *config.Store
}
func NewLogHandler(logger *logging.Logger) *LogHandler {
return &LogHandler{logger: logger}
func NewLogHandler(logger *logging.Logger, store *config.Store) *LogHandler {
return &LogHandler{logger: logger, store: store}
}
func (h *LogHandler) RegisterRoutes(mux *http.ServeMux) {
@@ -27,6 +29,14 @@ func (h *LogHandler) handleLogs(w http.ResponseWriter, r *http.Request) {
return
}
// Resolve platform type from config name (e.g. "qq-home" → "qq").
platform := name
if h.store != nil {
if cfg, err := h.store.Get(name); err == nil && cfg.Platform != "" {
platform = cfg.Platform
}
}
limit := 100
if l := r.URL.Query().Get("limit"); l != "" {
if n, err := strconv.Atoi(l); err == nil && n > 0 && n <= 1000 {
@@ -34,7 +44,7 @@ func (h *LogHandler) handleLogs(w http.ResponseWriter, r *http.Request) {
}
}
entries, err := h.logger.ReadLogs(name, limit)
entries, err := h.logger.ReadLogs(platform, limit)
if err != nil {
writeJSON(w, http.StatusInternalServerError, errResp(err.Error()))
return
@@ -43,7 +53,7 @@ func (h *LogHandler) handleLogs(w http.ResponseWriter, r *http.Request) {
entries = []logging.LogEntry{}
}
writeJSON(w, http.StatusOK, map[string]interface{}{
"platform": name,
"platform": platform,
"total": len(entries),
"logs": entries,
})
@@ -0,0 +1,86 @@
package handler
import (
"encoding/json"
"net/http"
"sync"
"github.com/gorilla/websocket"
"git.yeij.top/AskaEth/Cyrene/platform-bridge/internal/logging"
)
var wsUpgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { return true },
}
// LogWSHub broadcasts log entries to connected WebSocket clients.
type LogWSHub struct {
mu sync.Mutex
clients map[*websocket.Conn]chan logging.LogEntry
}
// NewLogWSHub creates a LogWSHub and subscribes to the logger.
func NewLogWSHub(logger *logging.Logger) *LogWSHub {
h := &LogWSHub{
clients: make(map[*websocket.Conn]chan logging.LogEntry),
}
logger.OnLog(func(entry logging.LogEntry) {
h.broadcast(entry)
})
return h
}
func (h *LogWSHub) broadcast(entry logging.LogEntry) {
h.mu.Lock()
defer h.mu.Unlock()
for _, ch := range h.clients {
select {
case ch <- entry:
default:
}
}
}
// ServeWS handles WebSocket upgrade and streams log entries to the client.
func (h *LogWSHub) ServeWS(w http.ResponseWriter, r *http.Request) {
conn, err := wsUpgrader.Upgrade(w, r, nil)
if err != nil {
return
}
ch := make(chan logging.LogEntry, 64)
h.mu.Lock()
h.clients[conn] = ch
h.mu.Unlock()
// Write goroutine: drains ch until it is closed.
done := make(chan struct{})
go func() {
defer close(done)
for entry := range ch {
data, _ := json.Marshal(entry)
if err := conn.WriteMessage(websocket.TextMessage, data); err != nil {
return
}
}
}()
// Read goroutine: detect client disconnect.
// (websocket requires a reader to detect close frames.)
go func() {
for {
if _, _, err := conn.ReadMessage(); err != nil {
break
}
}
// Client disconnected — stop broadcasting, close channel.
h.mu.Lock()
delete(h.clients, conn)
h.mu.Unlock()
close(ch)
}()
<-done
conn.Close()
}