feat: 管理面板补齐(RAG导入/记忆添加/会话接history/诚实表述) + design/16 §4.6 IM多会话隔离+第三方身份+黑白名单
agent-98 面板批次:
- 会话管理面板改接 history.ListSessions(主web+次级) + 新建次级会话按钮
- 记忆面板手动添加入口 POST /admin/memories(owner)
- 知识库真正实现 IndexDocument(分块+落projectindex) + POST /admin/rag 导入端点
- 三面板空态诚实表述(去除'后端M10+提供')
- RAG嵌入降级到keyword/line(无直属embedder,不伪造语义,符合红线)
agent-99 design/16 §4.6:
- model.Message.SenderName + 迁移0006 sender_name 列
- 第三方身份边界: session.ResolveActor判定(非LLM猜) + [第三方·昵称]前缀(不改源content)
- 群聊/陌生人落独立sess-xxx(persistIsolated),不写主会话,不广播
- 黑/白名单(allowGroups/denyGroups/allowUsers/denyUsers)最前拦截,不进LLM
- 多账号 CHANNELS_JSON 配置 + 每平台多实例
- 管理只读 GET /admin/channels/{platform}/messages(该平台非主人消息流)
实机验证(JWT): 会话管理返回主会话web / 记忆添加成功 / RAG导入documents非空+Cyrene命中; 后端build/vet/test全绿 + 前端build绿
This commit is contained in:
1 parent
37e98ec584
commit
9c2a37c4ac
32 files changed
+1768
-136
No files matched your search
@@ -0,0 +1,34 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ParseChannelAccounts decodes the CHANNELS_JSON value into a per-platform list
|
||||
// of ChannelAccount. The wire shape is map[platform]→[]ChannelAccount, for
|
||||
// example:
|
||||
//
|
||||
// {"telegram":[{"id":"conf0","config":{"bot_token":"..."},"denyUsers":["12345"]}]}
|
||||
//
|
||||
// An empty/blank input yields an empty (non-nil) map so a caller can iterate it
|
||||
// unconditionally. A malformed JSON or a non-array account value returns an
|
||||
// error so a bad config fails loudly at boot rather than silently dropping
|
||||
// channels.
|
||||
func ParseChannelAccounts(raw string) (map[string][]ChannelAccount, error) {
|
||||
if strings.TrimSpace(raw) == "" {
|
||||
return map[string][]ChannelAccount{}, nil
|
||||
}
|
||||
var m map[string][]ChannelAccount
|
||||
dec := json.NewDecoder(strings.NewReader(raw))
|
||||
if err := dec.Decode(&m); err != nil {
|
||||
return nil, fmt.Errorf("config: decode CHANNELS_JSON: %w", err)
|
||||
}
|
||||
// Tolerate a top-level array of accounts that all share a blank platform name
|
||||
// by normalizing a nil map to an empty one.
|
||||
if m == nil {
|
||||
return map[string][]ChannelAccount{}, nil
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseChannelAccounts_Empty(t *testing.T) {
|
||||
t.Parallel()
|
||||
got, err := ParseChannelAccounts("")
|
||||
if err != nil {
|
||||
t.Fatalf("ParseChannelAccounts(empty): %v", err)
|
||||
}
|
||||
if len(got) != 0 {
|
||||
t.Fatalf("empty input = %d platforms, want 0", len(got))
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseChannelAccounts_MultiAccountWithAllowDeny(t *testing.T) {
|
||||
t.Parallel()
|
||||
raw := `{
|
||||
"telegram": [
|
||||
{"id":"conf0","config":{"bot_token":"t0"},"denyUsers":["12345"],"denyGroups":["-100"]},
|
||||
{"id":"conf1","config":{"bot_token":"t1"},"allowUsers":["u1","u2"],"allowGroups":["g1"]}
|
||||
],
|
||||
"qq-obv11": [
|
||||
{"id":"bot0","config":{"remote_url":"http://x","mode":"client"}}
|
||||
]
|
||||
}`
|
||||
got, err := ParseChannelAccounts(raw)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseChannelAccounts: %v", err)
|
||||
}
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("platforms = %d, want 2", len(got))
|
||||
}
|
||||
tg := got["telegram"]
|
||||
if len(tg) != 2 {
|
||||
t.Fatalf("telegram accounts = %d, want 2", len(tg))
|
||||
}
|
||||
if tg[0].ID != "conf0" || tg[0].Config["bot_token"] != "t0" {
|
||||
t.Fatalf("account[0] = %+v", tg[0])
|
||||
}
|
||||
if !reflect.DeepEqual(tg[0].DenyUsers, []string{"12345"}) || !reflect.DeepEqual(tg[0].DenyGroups, []string{"-100"}) {
|
||||
t.Fatalf("account[0] deny lists = %+v", tg[0])
|
||||
}
|
||||
if !reflect.DeepEqual(tg[1].AllowUsers, []string{"u1", "u2"}) || !reflect.DeepEqual(tg[1].AllowGroups, []string{"g1"}) {
|
||||
t.Fatalf("account[1] allow lists = %+v", tg[1])
|
||||
}
|
||||
qq := got["qq-obv11"]
|
||||
if len(qq) != 1 || qq[0].ID != "bot0" || qq[0].Config["mode"] != "client" {
|
||||
t.Fatalf("qq accounts = %+v", qq)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseChannelAccounts_Malformed(t *testing.T) {
|
||||
t.Parallel()
|
||||
if _, err := ParseChannelAccounts(`{`); err == nil {
|
||||
t.Fatal("expected error for malformed JSON")
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ type Config struct {
|
||||
ExecSandbox ExecSandbox
|
||||
MCP MCPConfig
|
||||
Capacity CapacityConfig
|
||||
Channels ChannelsConfig
|
||||
}
|
||||
|
||||
// ServerConfig holds the single gateway listener settings.
|
||||
@@ -154,6 +155,46 @@ type MCPServer struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
// ChannelsConfig holds optional multi-account IM channel settings (design/16
|
||||
// §4.6 §5). The single-account credentials are read from CHANNEL_<NAME>_* env
|
||||
// vars in cmd/cyrene/channels.go; this block carries the optional multi-account
|
||||
// registry plus the per-account allow/deny black-or-white lists via a JSON
|
||||
// string (the reflection-based loader only supports scalars and []string, so a
|
||||
// structured value is passed as JSON — matching the MCP and Capacity configs).
|
||||
type ChannelsConfig struct {
|
||||
// AccountsJSON is the JSON shape map[platform]→[]ChannelAccount, e.g.
|
||||
// {"telegram":[{"id":"conf0","config":{"bot_token":"..."},
|
||||
// "denyUsers":["12345"]}]}. Empty means the single-account env path applies.
|
||||
AccountsJSON string `env:"CHANNELS_JSON"`
|
||||
}
|
||||
|
||||
// ChannelAccount is one IM access config (one account) for a platform. It pairs
|
||||
// an id (used to name the adapter instance and to build the platform:confId
|
||||
// account key) with the platform-specific credential map and the allow/deny
|
||||
// black-or-white lists applied at the channelbridge ingress (design/16 §4.6), so
|
||||
// a blacklisted or non-whitelisted group/user never reaches the LLM.
|
||||
type ChannelAccount struct {
|
||||
// ID is the local config id, unique within its platform. It names the adapter
|
||||
// instance and the platform:confId account key (design/16 §4.5 deviceID).
|
||||
ID string `json:"id"`
|
||||
// Config is the platform-specific credential/feature map decoded into the
|
||||
// adapter's typed Config (bot_token, base_url, remote_url, ...). Missing keys
|
||||
// fall back to the adapter's own zero values.
|
||||
Config map[string]any `json:"config,omitempty"`
|
||||
// AllowGroups, when non-empty, is a white list of group ids: a group message
|
||||
// is dropped unless its GroupID is in this list.
|
||||
AllowGroups []string `json:"allowGroups,omitempty"`
|
||||
// DenyGroups is a black list of group ids: a group message whose GroupID is in
|
||||
// this list is dropped at ingress.
|
||||
DenyGroups []string `json:"denyGroups,omitempty"`
|
||||
// AllowUsers, when non-empty, is a white list of user uids: a direct (private)
|
||||
// message from a user not in this list is dropped.
|
||||
AllowUsers []string `json:"allowUsers,omitempty"`
|
||||
// DenyUsers is a black list of user uids: a direct message from a user in this
|
||||
// list is dropped at ingress.
|
||||
DenyUsers []string `json:"denyUsers,omitempty"`
|
||||
}
|
||||
|
||||
// Load reads configuration, merging an optional .env file (development only)
|
||||
// with process environment variables. Process environment variables always take
|
||||
// precedence over .env values, which take precedence over code defaults.
|
||||
|
||||
Reference in new issue
Block a user