feat: 管理面板补齐(RAG导入/记忆添加/会话接history/诚实表述) + design/16 §4.6 IM多会话隔离+第三方身份+黑白名单
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

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:
Aska committed 2026-09-07 05:13:36 +08:00
1 parent 37e98ec584
commit 9c2a37c4ac
32 files changed
+1768 -136

No files matched your search

+210 -28
View File
@@ -86,6 +86,11 @@ type Options struct {
Owner *user.OwnerProfile
History history.HistoryStore
OnPersisted func(history.Message)
// OnRejected, when non-nil, is called after a message is dropped by the
// allow/deny black-or-white lists (design/16 §4.6 §6), so the composition root
// can route it into an audit trail. It is invoked with the rejected message and
// a short reason token ("group_denied", "user_not_allowed", ...). Nil = log only.
OnRejected func(adapter.UnifiedMessage, string)
}
// Bridge owns the channel adapter lifecycle and the inbound message pipeline. It
@@ -97,6 +102,7 @@ type Bridge struct {
owner *user.OwnerProfile
history history.HistoryStore
onPersisted func(history.Message)
onRejected func(adapter.UnifiedMessage, string)
mu sync.RWMutex
adapters map[string]adapter.PlatformAdapter
@@ -130,6 +136,7 @@ func New(opts Options) (*Bridge, error) {
owner: opts.Owner,
history: opts.History,
onPersisted: opts.OnPersisted,
onRejected: opts.OnRejected,
adapters: make(map[string]adapter.PlatformAdapter),
connected: make(map[string]bool),
cancel: func() {},
@@ -205,7 +212,12 @@ func (b *Bridge) Start() {
b.connected[a.Name()] = true
b.mu.Unlock()
a.SetMessageHandler(b.onMessage)
// Close over the adapter so the inbound callback knows which account
// received the message — required for multi-account reply routing and for
// reading that account's allow/deny lists (design/16 §4.6 §5).
a.SetMessageHandler(func(ctx context.Context, msg adapter.UnifiedMessage) {
b.onMessage(ctx, msg, a)
})
b.wg.Add(1)
go b.readLoop(a)
b.log.Info("channel connected", "channel", a.Name())
@@ -274,7 +286,7 @@ func (b *Bridge) snapshot() []adapter.PlatformAdapter {
// when no bot token is present.
func (b *Bridge) configured(a adapter.PlatformAdapter) bool {
cfg := a.Config()
switch a.Name() {
switch basePlatform(a.Name()) {
case "telegram", "weixin-ilink":
return cfgStr(cfg, "bot_token") != ""
case "qq-obv11":
@@ -290,6 +302,16 @@ func (b *Bridge) configured(a adapter.PlatformAdapter) bool {
}
}
// basePlatform returns the bare platform name of a (possibly multi-account)
// adapter name like "telegram:conf0" → "telegram", so the credential gate and the
// reply-routing fallback treat every account of a platform identically.
func basePlatform(name string) string {
if base, _, ok := strings.Cut(name, ":"); ok {
return base
}
return name
}
// readLoop runs an adapter's blocking read path until the bridge stops. The emit
// sink is wired to onMessage so poll-style adapters (Telegram getUpdates, weixin
// long poll) deliver through the same pipeline as push-style adapters.
@@ -297,13 +319,16 @@ func (b *Bridge) readLoop(a adapter.PlatformAdapter) {
defer b.wg.Done()
ctx := b.ctx
a.ReadMessages(ctx, func(msg adapter.UnifiedMessage) {
b.onMessage(ctx, msg)
b.onMessage(ctx, msg, a)
})
}
// onMessage is the adapter-facing inbound callback. It runs the pipeline in a
// bounded goroutine so the adapter's read loop never blocks on a slow agent turn.
func (b *Bridge) onMessage(ctx context.Context, msg adapter.UnifiedMessage) {
// The adapter is carried explicitly so the pipeline knows which account received
// the message (multi-account reply routing + per-account allow/deny, design/16
// §4.6 §5).
func (b *Bridge) onMessage(ctx context.Context, msg adapter.UnifiedMessage, a adapter.PlatformAdapter) {
b.mu.Lock()
if b.closed {
b.mu.Unlock()
@@ -337,15 +362,24 @@ func (b *Bridge) onMessage(ctx context.Context, msg adapter.UnifiedMessage) {
go func() {
defer b.wg.Done()
defer func() { <-b.sem }()
b.process(ctx, msg)
b.processFrom(ctx, msg, a)
}()
}
// process runs the full inbound pipeline: resolve the session/actor, drive the
// agent loop with the chat text, and send the loop's reply back through the
// channel. Identity is resolved structurally by the session layer; the bridge
// never reads message content to decide who the sender is.
// process runs the inbound pipeline using the adapter whose platform matches the
// message (single-account convenience path; the adapter may be a bare
// platform-named registration).
func (b *Bridge) process(ctx context.Context, msg adapter.UnifiedMessage) {
b.processFrom(ctx, msg, b.adapter(msg.Platform))
}
// processFrom runs the full inbound pipeline against the named account adapter:
// resolve the session/actor, apply the allow/deny black-or-white lists, drive the
// agent loop with the chat text, and send the loop's reply back through the same
// adapter that received the message. Identity is resolved structurally by the
// session layer; the bridge never reads message content to decide who the sender
// is (a project red line).
func (b *Bridge) processFrom(ctx context.Context, msg adapter.UnifiedMessage, a adapter.PlatformAdapter) {
text := strings.TrimSpace(msg.Content)
if text == "" {
b.log.Debug("inbound message has no chat text, skipped",
@@ -353,6 +387,22 @@ func (b *Bridge) process(ctx context.Context, msg adapter.UnifiedMessage) {
return
}
// design/16 §4.6 §6: the black-or-white lists are enforced at the very head of
// the pipeline, before a session is resolved or the loop is driven, so a
// blacklisted/non-whitelisted group or user message never reaches the LLM. The
// owner is always allowed (structural, via the resolved actor).
actor := session.ResolveActor(msg, b.owner)
if actor.IsOwner() {
// fall through: owner messages are never blacklisted
} else if denied, reason := b.blacklisted(msg, a); denied {
b.log.Warn("inbound message blacklisted, dropped",
"platform", msg.Platform, "channel", msg.ChannelID, "reason", reason)
if b.onRejected != nil {
b.onRejected(msg, reason)
}
return
}
sess, err := b.sessions.GetOrCreate(ctx, msg, b.owner)
if err != nil {
b.log.Warn("session resolve failed", "platform", msg.Platform,
@@ -368,7 +418,7 @@ func (b *Bridge) process(ctx context.Context, msg adapter.UnifiedMessage) {
// design/16 §4.4 + design/02 §3: an owner private chat is routed INTO the single
// main web session (shared across platforms) and persisted to chat_messages with
// the channel platform, so the Web client mirrors it; group chats and strangers
// keep their isolated sess-xxx context and are NOT persisted to the main session.
// keep their isolated sess-xxx context and their own platform log.
sessID := sess.SessionID
isOwnerPrivate := !sess.IsGroup && sess.Owner
platform := ""
@@ -377,19 +427,26 @@ func (b *Bridge) process(ctx context.Context, msg adapter.UnifiedMessage) {
platform = msg.Platform
}
// Persist the inbound user message into the main web session before the turn, so
// the Web client sees it even if the channel reply fails (design/16 §4.4).
// The third-party boundary only applies in a restricted (group/stranger)
// context: memory is read-only (MemWritable=false), and the sender name is
// carried so the agent can see who is speaking (design/16 §4.6 §1-2). The
// resolved actor decides who is the owner vs a third party structurally — never
// from prompt text.
runEnv := loop.SessionEnv{ActorEnv: sess.Env(), MemWritable: sess.MemWritable}
senderName := senderDisplayName(msg, actor)
loopMsgs := b.buildLoopMessages(ctx, text, runEnv, actor, senderName)
// Persist the inbound user message before the turn so it is durable even if the
// channel reply fails. Owner-private messages land in the main web session and
// are broadcast to the Web client; restricted messages land in their isolated
// session (the adapter log page) and are NOT broadcast to the main session.
if isOwnerPrivate {
b.persistToMain(ctx, history.RoleUser, text, platform, deviceIDFor(msg))
} else {
b.persistIsolated(ctx, history.RoleUser, text, deviceIDFor(msg), sess, msg.Platform, senderName)
}
// Thread the resolved isolation boundary into the loop's memory gates: the
// owner's private conversation reads+writes memory, group chats and strangers
// are read-only isolation (design/02 §3, design/11 §2).
runEnv := loop.SessionEnv{ActorEnv: sess.Env(), MemWritable: sess.MemWritable}
res, err := b.run.Run(loop.WithSessionEnv(ctx, runEnv), sessID, []model.Message{
model.TextMessage(model.RoleUser, text),
})
res, err := b.run.Run(loop.WithSessionEnv(ctx, runEnv), sessID, loopMsgs)
if err != nil {
b.log.Warn("agent run failed", "platform", msg.Platform,
"session", sessID, "error", err)
@@ -401,13 +458,14 @@ func (b *Bridge) process(ctx context.Context, msg adapter.UnifiedMessage) {
b.log.Debug("no reply produced", "platform", msg.Platform, "session", sessID)
return
}
// Persist the assistant reply into the main web session (design/16 §4.4) and
// broadcast, then deliver it back to the channel — so the Web client mirrors the
// IM reply too.
// Persist the assistant reply (owner-private → main session + broadcast;
// restricted → isolated log) then deliver it back to the channel.
if isOwnerPrivate {
b.persistToMain(ctx, history.RoleAssistant, reply, platform, deviceIDFor(msg))
} else {
b.persistIsolated(ctx, history.RoleAssistant, reply, "", sess, msg.Platform, "")
}
if err := b.sendReply(ctx, msg, reply); err != nil {
if err := b.sendReply(ctx, msg, a, reply); err != nil {
if errors.Is(err, adapter.ErrUnsupported) {
b.log.Debug("channel does not support outbound reply, skipped",
"platform", msg.Platform, "session", sessID)
@@ -417,11 +475,35 @@ func (b *Bridge) process(ctx context.Context, msg adapter.UnifiedMessage) {
}
}
// sendReply delivers the loop's text back to the channel's source conversation.
// It mirrors the inbound message's channel targeting fields so the adapter
// resolves the same peer the message came from.
func (b *Bridge) sendReply(ctx context.Context, in adapter.UnifiedMessage, text string) error {
a := b.adapter(in.Platform)
// buildLoopMessages builds the model-visible message list for one inbound turn. In
// a restricted (group/stranger) context it prepends a single system message that
// states the third-party identity boundary — "every IM non-admin account's message
// is a third party, unrelated to the owner" (design/16 §4.6 §1). The boundary is
// decided structurally from the resolved SessionEnv, never inferred by the LLM.
// The raw message text is left untouched (a copy is built with the prefix), so
// persisted content stays consistent with what the source platform delivered.
func (b *Bridge) buildLoopMessages(_ context.Context, text string, env loop.SessionEnv, actor adapter.Actor, senderName string) []model.Message {
msg := model.TextMessage(model.RoleUser, text)
thirdParty := env.Restricted() && !actor.IsOwner() && senderName != ""
if thirdParty {
msg.SenderName = senderName
msg.Content[0].Text = fmt.Sprintf("[第三方 · %s] %s", senderName, text)
}
if !env.Restricted() {
return []model.Message{msg}
}
boundary := model.TextMessage(model.RoleSystem, thirdPartyBoundaryPrompt)
return []model.Message{boundary, msg}
}
// sendReply delivers the loop's text back to the channel's source conversation
// through the account adapter that received the message (multi-account safe,
// design/16 §4.6 §5). It mirrors the inbound message's channel targeting fields so
// the adapter resolves the same peer the message came from.
func (b *Bridge) sendReply(ctx context.Context, in adapter.UnifiedMessage, a adapter.PlatformAdapter, text string) error {
if a == nil {
a = b.adapter(in.Platform)
}
if a == nil {
return fmt.Errorf("channelbridge: no adapter for platform %q", in.Platform)
}
@@ -475,3 +557,103 @@ func deviceIDFor(msg adapter.UnifiedMessage) string {
}
return msg.Platform + ":" + msg.ChannelID
}
// thirdPartyBoundaryPrompt is the system message prepended to a restricted
// (group-chat / stranger) context so the model knows the identity boundary. It is
// only injected when the session is structurally restricted (design/16 §4.6 §1);
// the LLM never decides who is a third party — that was already resolved from the
// actor metadata before this message exists.
const thirdPartyBoundaryPrompt = "你正在 IM 平台的群聊/第三方会话中。每个 IM 的「非管理员账户」发送的消息 = 第三方人员,和主人没有半毛钱关系,不要把它们当成主人的话、也不要按主人对待。只有未标注昵称的消息才是管理员(主人)发言。"
// senderDisplayName returns the human-readable sender name used to label a
// third-party message. It prefers the resolved actor's display name (which the
// channel layer derived from channel metadata + the raw SenderName), falling back
// to the message's own SenderName, so an empty SenderName always means "the
// owner/unlabeled" rather than a nickname that resolved to nothing.
func senderDisplayName(msg adapter.UnifiedMessage, actor adapter.Actor) string {
if actor.DisplayName != "" {
return actor.DisplayName
}
return msg.SenderName
}
// blacklisted applies the per-account allow/deny black-or-white lists (design/16
// §4.6 §6) to a non-owner inbound message. Group messages are matched by GroupID
// against allowGroups/denyGroups; direct messages are matched by the sender's user
// id against allowUsers/denyUsers. An empty allow list means "allow all" (only the
// deny list applies); a non-empty allow list becomes a white list. The owner is
// never blacklisted (the caller skips this for owner messages).
func (b *Bridge) blacklisted(msg adapter.UnifiedMessage, a adapter.PlatformAdapter) (bool, string) {
if a == nil {
return false, ""
}
allowGroups, denyGroups, allowUsers, denyUsers := channelLists(a.Config())
if msg.IsGroup() {
if sliceContains(denyGroups, msg.GroupID) {
return true, "group_denied"
}
if len(allowGroups) > 0 && !sliceContains(allowGroups, msg.GroupID) {
return true, "group_not_allowed"
}
return false, ""
}
uid := firstNonEmptyStr(msg.SenderID, msg.Sender.UserID)
if sliceContains(denyUsers, uid) {
return true, "user_denied"
}
if len(allowUsers) > 0 && !sliceContains(allowUsers, uid) {
return true, "user_not_allowed"
}
return false, ""
}
// channelLists reads the allow/deny string lists off an adapter's Config snapshot.
// The lists are stored as plain []string values (set by the multi-account wiring);
// an absent key yields an empty list.
func channelLists(cfg map[string]any) (allowGroups, denyGroups, allowUsers, denyUsers []string) {
if cfg == nil {
return nil, nil, nil, nil
}
return cfgStrings(cfg, "allowGroups"), cfgStrings(cfg, "denyGroups"),
cfgStrings(cfg, "allowUsers"), cfgStrings(cfg, "denyUsers")
}
// cfgStrings reads a []string field from an adapter config map, returning nil when
// absent or of a different type.
func cfgStrings(m map[string]any, key string) []string {
if m == nil {
return nil
}
switch v := m[key].(type) {
case []string:
return v
case []any:
out := make([]string, 0, len(v))
for _, e := range v {
if s, ok := e.(string); ok {
out = append(out, s)
}
}
return out
default:
return nil
}
}
// sliceContains reports whether s is present in list.
func sliceContains(list []string, s string) bool {
for _, v := range list {
if v == s {
return true
}
}
return false
}
// firstNonEmptyStr returns a when non-empty, otherwise b.
func firstNonEmptyStr(a, b string) string {
if a != "" {
return a
}
return b
}
@@ -2,6 +2,7 @@ package channelbridge
import (
"context"
"strings"
"sync"
"testing"
@@ -18,6 +19,7 @@ import (
type fakeAdapter struct {
name string
connected bool
cfg map[string]any
sends []adapter.UnifiedMessage
handler adapter.MessageHandler
sendErr error
@@ -25,6 +27,9 @@ type fakeAdapter struct {
func (f *fakeAdapter) Name() string { return f.name }
func (f *fakeAdapter) Config() map[string]any {
if f.cfg != nil {
return f.cfg
}
return map[string]any{"bot_token": "configured"}
}
func (f *fakeAdapter) Connect(context.Context) error { f.connected = true; return nil }
@@ -236,6 +241,9 @@ func (c *captureHistory) List(context.Context, string, int64, int, string) ([]hi
func (c *captureHistory) Recent(context.Context, string, int) ([]history.Message, error) {
return nil, nil
}
func (c *captureHistory) ListPlatformLog(context.Context, string, int64, int) ([]history.Message, error) {
return nil, nil
}
func (c *captureHistory) DeleteSession(context.Context, string) error { return nil }
func (c *captureHistory) NewSubSession(context.Context, string) (string, error) {
return "", nil
@@ -350,16 +358,177 @@ func TestGroupMessageNotPersistedToMainSession(t *testing.T) {
}
b.process(context.Background(), msg)
// Group chat stays isolated: nothing is written to the main web session and the
// loop runs against the isolated session id.
if recs := hist.records(); len(recs) != 0 {
t.Fatalf("group appends = %+v, want none persisted", recs)
// design/16 §4.6: a group/stranger conversation stays isolated — it is NOT
// persisted into the main web session, and the loop runs against the isolated
// session id. Messages land only in the isolated session's own platform log
// (the adapter log page), so nothing reaches the Web main session.
recs := hist.records()
if len(recs) != 2 {
t.Fatalf("group appends = %d, want 2 (isolated user + assistant)", len(recs))
}
for i, rec := range recs {
if rec.SessionID != "sess-g" {
t.Fatalf("record[%d] SessionID = %q, want isolated sess-g (not web)", i, rec.SessionID)
}
if rec.Platform != "telegram" {
t.Fatalf("record[%d] Platform = %q, want telegram", i, rec.Platform)
}
}
if chat.sessionID != "sess-g" {
t.Fatalf("group loop session id = %q, want sess-g", chat.sessionID)
}
}
func TestBlacklistGroupMessageDroppedBeforeLoop(t *testing.T) {
t.Parallel()
chat := &stubChatter{res: &loop.Result{Text: "不该回复"}}
// A stranger's group session that would otherwise be processed.
sess := &stubSessions{sess: session.Session{SessionID: "sess-g", IsGroup: true, Owner: false, MemWritable: false}}
ad := &fakeAdapter{name: "telegram", cfg: map[string]any{
"bot_token": "configured",
"denyGroups": []string{"-100"},
}}
var rejected []string
b, err := New(Options{
Loop: chat, Sessions: sess, Owner: &user.OwnerProfile{}, History: &captureHistory{},
OnRejected: func(_ adapter.UnifiedMessage, reason string) { rejected = append(rejected, reason) },
})
if err != nil {
t.Fatalf("New: %v", err)
}
b.Add(ad)
msg := adapter.UnifiedMessage{
Platform: "telegram", ChannelID: "-100", ChannelType: adapter.ChannelGroup,
GroupID: "-100", SenderID: "9", SenderName: "张三",
Sender: adapter.Actor{Role: adapter.RoleMember}, Content: "spam",
ContentType: adapter.ContentText,
}
b.process(context.Background(), msg)
// The blacklisted group message never reaches the agent loop and never sends a
// reply; the rejection reason is surfaced for the audit trail.
if chat.sessionID != "" || len(chat.messages) != 0 {
t.Fatalf("loop ran for blacklisted message: session=%q messages=%+v", chat.sessionID, chat.messages)
}
if len(ad.sends) != 0 {
t.Fatalf("blacklisted message sent %d replies, want 0", len(ad.sends))
}
if len(rejected) != 1 || rejected[0] != "group_denied" {
t.Fatalf("rejection reasons = %v, want [group_denied]", rejected)
}
}
func TestBlacklistUserMessageDroppedBeforeLoop(t *testing.T) {
t.Parallel()
chat := &stubChatter{res: &loop.Result{Text: "不该回复"}}
sess := &stubSessions{sess: session.Session{SessionID: "sess-s", IsGroup: false, Owner: false, MemWritable: false}}
ad := &fakeAdapter{name: "telegram", cfg: map[string]any{
"bot_token": "configured",
"allowUsers": []string{"111"},
}}
b, err := New(Options{Loop: chat, Sessions: sess, Owner: &user.OwnerProfile{}, History: &captureHistory{}})
if err != nil {
t.Fatalf("New: %v", err)
}
b.Add(ad)
msg := adapter.UnifiedMessage{
Platform: "telegram", ChannelID: "200", ChannelType: adapter.ChannelDirect,
SenderID: "200", Sender: adapter.Actor{Role: adapter.RoleMember}, Content: "hi",
ContentType: adapter.ContentText,
}
b.process(context.Background(), msg)
// A direct message from a user NOT in the allow whitelist is dropped; the owner
// is never affected (this is a stranger).
if chat.sessionID != "" || len(chat.messages) != 0 {
t.Fatalf("loop ran for non-whitelisted user: session=%q messages=%+v", chat.sessionID, chat.messages)
}
if len(ad.sends) != 0 {
t.Fatalf("non-whitelisted user sent %d replies, want 0", len(ad.sends))
}
}
func TestGroupMessageThirdPartySenderNameAndBoundary(t *testing.T) {
t.Parallel()
chat := &stubChatter{res: &loop.Result{Text: "收到"}}
sess := &stubSessions{sess: session.Session{SessionID: "sess-g", IsGroup: true, Owner: false, MemWritable: false}}
hist := &captureHistory{}
b, err := New(Options{Loop: chat, Sessions: sess, Owner: &user.OwnerProfile{}, History: hist})
if err != nil {
t.Fatalf("New: %v", err)
}
msg := adapter.UnifiedMessage{
Platform: "telegram", ChannelID: "-20", ChannelType: adapter.ChannelGroup,
GroupID: "-20", GroupName: "Gang", SenderID: "9", SenderName: "张三",
Sender: adapter.Actor{Role: adapter.RoleMember}, Content: "hello all",
ContentType: adapter.ContentText,
}
b.process(context.Background(), msg)
// The loop sees a leading third-party boundary system message plus the user
// message already prefixed with [第三方 · 张三] (the raw content is preserved in
// history, so no source data is lost).
if len(chat.messages) != 2 {
t.Fatalf("loop messages = %d, want 2 (boundary + user)", len(chat.messages))
}
if chat.messages[0].Role != model.RoleSystem || !strings.Contains(chat.messages[0].Content[0].Text, "非管理员账户") {
t.Fatalf("expected third-party boundary system message, got %+v", chat.messages[0])
}
user := chat.messages[1]
if user.SenderName != "张三" || user.Content[0].Text != "[第三方 · 张三] hello all" {
t.Fatalf("loop user message = %+v, want SenderName 张三 and [第三方 · 张三] prefix", user)
}
// History keeps the RAW content and carries the sender name so the adapter log
// page can label the stream without altering the source message.
recs := hist.records()
if len(recs) != 2 || recs[0].Content != "hello all" || recs[0].SenderName != "张三" {
t.Fatalf("isolated records = %+v, want raw content with SenderName 张三", recs)
}
}
func TestOwnerInGroupIsIsolatedButNotLabeledThirdParty(t *testing.T) {
t.Parallel()
chat := &stubChatter{res: &loop.Result{Text: "收到"}}
// Owner speaking inside a group: the session stays restricted (mem read-only),
// but the owner is never labeled as a third party (design/16 §4.6 §1-2).
sess := &stubSessions{sess: session.Session{SessionID: "sess-g", IsGroup: true, Owner: true, MemWritable: false}}
hist := &captureHistory{}
b, err := New(Options{Loop: chat, Sessions: sess, Owner: &user.OwnerProfile{}, History: hist})
if err != nil {
t.Fatalf("New: %v", err)
}
msg := adapter.UnifiedMessage{
Platform: "telegram", ChannelID: "-20", ChannelType: adapter.ChannelGroup,
GroupID: "-20", SenderID: "owner_uid", SenderName: "主人",
Sender: adapter.Actor{Role: adapter.RoleOwner}, Content: "我在群里",
ContentType: adapter.ContentText,
}
b.process(context.Background(), msg)
// Restricted context → a third-party boundary system message is still injected.
if len(chat.messages) != 2 || chat.messages[0].Role != model.RoleSystem {
t.Fatalf("loop messages = %d, want 2 (boundary + user)", len(chat.messages))
}
// Owner's message is NOT prefixed as third-party and carries no SenderName.
user := chat.messages[1]
if user.SenderName != "" || user.Content[0].Text != "我在群里" {
t.Fatalf("owner group message = %+v, want no SenderName and no [第三方] prefix", user)
}
// Owner group speech still lands in the isolated session (not the main web session).
recs := hist.records()
if len(recs) != 2 || recs[0].SessionID != "sess-g" {
t.Fatalf("owner group records = %+v, want isolated sess-g, not web", recs)
}
}
func TestNoHistoryStoreKeepsBridgeUnchanged(t *testing.T) {
t.Parallel()
// A bridge built without a history store persists nothing but still runs/replies.
@@ -3,6 +3,8 @@ package channelbridge
import (
"context"
"git.yeij.top/AskaEth/Cyrene_v2/internal/channel/adapter"
"git.yeij.top/AskaEth/Cyrene_v2/internal/channel/session"
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/history"
)
@@ -23,6 +25,16 @@ func (b *Bridge) SetOnPersisted(fn func(history.Message)) {
b.onPersisted = fn
}
// SetOnRejected wires (or replaces) the hook called after a message is dropped by
// the allow/deny black-or-white lists (design/16 §4.6 §6). The composition root
// routes it into the gateway audit trail. It is a no-op-safe call and is safe for
// concurrent use with in-flight processing.
func (b *Bridge) SetOnRejected(fn func(adapter.UnifiedMessage, string)) {
b.mu.Lock()
defer b.mu.Unlock()
b.onRejected = fn
}
// notifyPersisted hands a just-persisted message to the transport hook when one is
// wired, so the gateway can broadcast `message_persisted` for cross-end sync.
func (b *Bridge) notifyPersisted(msg history.Message) {
@@ -53,3 +65,27 @@ func (b *Bridge) persistToMain(ctx context.Context, role, content, platform, dev
}
b.notifyPersisted(full)
}
// persistIsolated writes one message into a restricted (group / stranger) session's
// own platform log (design/16 §4.6 §4): the message lands in the isolated sess-xxx
// session (NOT the main web session) and carries the channel platform, the client
// deviceID and the sender's display name, so the IM adapter log page can render the
// non-owner message stream. It is deliberately NOT broadcast to the Web main session
// (only owner-private messages mirror to the Web). It is a no-op when no history
// store is wired, so the bridge runs unchanged without storage.
func (b *Bridge) persistIsolated(ctx context.Context, role, content, deviceID string, sess session.Session, platform, senderName string) {
if b.history == nil {
return
}
full, err := b.history.AppendFull(ctx, history.Message{
SessionID: sess.SessionID, Role: role, Content: content, Platform: platform,
DeviceID: deviceID, SenderName: senderName,
})
if err != nil {
b.log.Warn("persist isolated session", "err", err, "role", role,
"session", sess.SessionID, "platform", platform, "sender_name", senderName)
return
}
// No broadcast: third-party messages must not reach the Web main session (design/16 §4.6 §3).
_ = full
}
+9 -1
View File
@@ -96,8 +96,16 @@ func (s *Server) adminListPersonas(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, s.collectPersonas())
}
// adminListSessions lists channel sessions (admin read).
// adminListSessions lists the persistent chat-history sessions (main + sub) when a
// history store is wired, otherwise falls back to the channel-session view. It is
// the admin counterpart of handleListSessions: the panel shows the real main and
// secondary sessions (design/16 §2) rather than stale channel-session rows, and
// the fallback keeps the pre-design/16 contract for servers built without history.
func (s *Server) adminListSessions(w http.ResponseWriter, r *http.Request) {
if s.history != nil {
s.handleHistorySessions(w, r)
return
}
writeJSON(w, http.StatusOK, s.collectSessions(r.Context()))
}
@@ -0,0 +1,127 @@
package gateway
import (
"encoding/json"
"net/http"
"strings"
apperr "git.yeij.top/AskaEth/Cyrene_v2/internal/errors"
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/knowledge"
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/memory"
)
// Admin memory + knowledge-base write endpoints (owner-only, audited). The memory
// add writes a real item into the memory store (owner-private, safe), and the RAG
// index imports a document into the project index so it becomes searchable. Both
// degrade to a clear 501 when their backing store is not wired.
// memoryAddRequest is the POST /api/v1/admin/memories body.
type memoryAddRequest struct {
PersonaID string `json:"personaId"`
Content string `json:"content"`
Scope string `json:"scope"`
}
// adminAddMemory writes a single memory item for the owner. It is the manual
// "添加记忆" path: the item is scoped to the persona (default), so it behaves like
// the "记住 X" path the loop already writes. Scope may be omitted (default
// persona) or one of user|persona|project; an invalid non-empty scope is rejected.
func (s *Server) adminAddMemory(w http.ResponseWriter, r *http.Request) {
var req memoryAddRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
writeError(w, apperr.Wrap(apperr.ErrBadRequest, "bad_request", "invalid request body"))
return
}
personaID := strings.TrimSpace(req.PersonaID)
if personaID == "" {
personaID = "cyrene"
}
content := strings.TrimSpace(req.Content)
if content == "" {
s.auditClaims(r, "memory.add", "error")
writeError(w, apperr.Wrap(apperr.ErrBadRequest, "bad_request", "content is required"))
return
}
rawScope := strings.TrimSpace(req.Scope)
if rawScope != "" && !isValidMemoryScope(rawScope) {
s.auditClaims(r, "memory.add", "error")
writeError(w, apperr.Wrap(apperr.ErrBadRequest, "bad_request", "scope must be one of user|persona|project"))
return
}
store, ok := s.memories.(*memory.Store)
if !ok {
s.auditClaims(r, "memory.add", "error")
writeError(w, &apperr.AppError{Code: "not_implemented", Message: "记忆存储未配置(未注入 memory.Store)", HTTPCode: http.StatusNotImplemented})
return
}
stored, err := store.Add(r.Context(), memory.MemoryItem{
PersonaID: personaID,
Content: content,
Scope: memory.Scope(rawScope),
})
if err != nil {
s.auditClaims(r, "memory.add", "error")
s.log.Error("memory add", "err", err)
writeError(w, apperr.Wrap(apperr.ErrInternal, "memory_add_failed", "failed to add memory"))
return
}
s.auditClaims(r, "memory.add", "ok")
writeJSON(w, http.StatusCreated, map[string]any{"id": stored.ID, "scope": string(stored.Scope), "text": stored.Content})
}
// isValidMemoryScope reports whether raw is one of the defined memory scopes.
func isValidMemoryScope(raw string) bool {
switch memory.Scope(strings.TrimSpace(raw)) {
case memory.ScopeUser, memory.ScopePersona, memory.ScopeProject:
return true
default:
return false
}
}
// ragIndexRequest is the POST /api/v1/admin/rag body.
type ragIndexRequest struct {
Name string `json:"name"`
Desc string `json:"desc"`
Content string `json:"content"`
}
// adminIndexRag imports one knowledge document: it hands the name/description and
// content to the knowledge store, which chunks it and indexes it into the project
// index so the document becomes keyword/searchable. It is the admin "导入文档" path.
func (s *Server) adminIndexRag(w http.ResponseWriter, r *http.Request) {
var req ragIndexRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
writeError(w, apperr.Wrap(apperr.ErrBadRequest, "bad_request", "invalid request body"))
return
}
name := strings.TrimSpace(req.Name)
if name == "" {
s.auditClaims(r, "rag.index", "error")
writeError(w, apperr.Wrap(apperr.ErrBadRequest, "bad_request", "name is required"))
return
}
content := strings.TrimSpace(req.Content)
if content == "" {
s.auditClaims(r, "rag.index", "error")
writeError(w, apperr.Wrap(apperr.ErrBadRequest, "bad_request", "content is required"))
return
}
if s.rag == nil {
s.auditClaims(r, "rag.index", "error")
writeError(w, &apperr.AppError{Code: "not_implemented", Message: "知识库 RAG 服务未配置(未注入 RagStore)", HTTPCode: http.StatusNotImplemented})
return
}
if err := s.rag.IndexDocument(r.Context(), knowledge.Doc{
Name: name,
Desc: strings.TrimSpace(req.Desc),
Content: content,
}); err != nil {
s.auditClaims(r, "rag.index", "error")
s.log.Error("rag index", "err", err)
writeError(w, apperr.Wrap(apperr.ErrInternal, "rag_index_failed", "failed to index document"))
return
}
s.auditClaims(r, "rag.index", "ok")
writeJSON(w, http.StatusCreated, map[string]any{"name": name})
}
@@ -0,0 +1,233 @@
package gateway
import (
"context"
"encoding/json"
"io"
"log/slog"
"net/http"
"testing"
"git.yeij.top/AskaEth/Cyrene_v2/internal/auth"
"git.yeij.top/AskaEth/Cyrene_v2/internal/db"
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/history"
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/knowledge"
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/memory"
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/memory/projectindex"
)
func gwTestLogger() *slog.Logger {
return slog.New(slog.NewTextHandler(io.Discard, nil))
}
// newMemoryStoreForGateway opens an isolated in-memory SQLite DB and builds a
// real memory.Store over it so the owner write path (which type-asserts to
// *memory.Store) exercises the real Add.
func newMemoryStoreForGateway(t *testing.T) *memory.Store {
t.Helper()
ctx := context.Background()
d, err := db.Open(ctx, ":memory:", gwTestLogger())
if err != nil {
t.Fatalf("open in-memory db: %v", err)
}
t.Cleanup(func() { _ = d.Close() })
s, err := memory.NewStore(ctx, d, gwTestLogger())
if err != nil {
t.Fatalf("memory.NewStore: %v", err)
}
return s
}
func newRagStoreForGateway(t *testing.T) *knowledge.Store {
t.Helper()
ctx := context.Background()
d, err := db.Open(ctx, ":memory:", gwTestLogger())
if err != nil {
t.Fatalf("open in-memory db: %v", err)
}
t.Cleanup(func() { _ = d.Close() })
ps, err := projectindex.New(ctx, d, gwTestLogger())
if err != nil {
t.Fatalf("projectindex.New: %v", err)
}
return knowledge.New(knowledge.Deps{Projects: ps, Log: gwTestLogger()})
}
func newHistoryStoreForGateway(t *testing.T) *history.Store {
t.Helper()
ctx := context.Background()
d, err := db.Open(ctx, ":memory:", gwTestLogger())
if err != nil {
t.Fatalf("open in-memory db: %v", err)
}
t.Cleanup(func() { _ = d.Close() })
s, err := history.NewStore(ctx, d, gwTestLogger())
if err != nil {
t.Fatalf("history.NewStore: %v", err)
}
return s
}
func TestAdminAddMemoryWritesAndLists(t *testing.T) {
t.Parallel()
store := newMemoryStoreForGateway(t)
srv, ts, jwt := buildEnv(t, cfgDefault(), Deps{Memories: store})
_ = srv
tok := signAny(t, jwt, "acct", auth.RoleOwner)
resp, body := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/memories",
map[string]any{"personaId": "cyrene", "content": "她喜欢喝冰美式", "scope": "persona"}, tok)
if resp.StatusCode != http.StatusCreated {
t.Fatalf("add status = %d, want 201 (body=%s)", resp.StatusCode, body)
}
var added struct {
ID string `json:"id"`
Scope string `json:"scope"`
Text string `json:"text"`
}
if err := json.Unmarshal(decodeBody(t, body)["data"], &added); err != nil {
t.Fatalf("decode add: %v (body=%s)", err, body)
}
if added.ID == "" || added.Scope != "persona" || added.Text != "她喜欢喝冰美式" {
t.Fatalf("added = %+v, want persona/她喜欢喝冰美式", added)
}
// The freshly added item is now listed.
listResp, listBody := doReq(t, http.MethodGet, ts.URL+"/api/v1/admin/memories", nil, tok)
if listResp.StatusCode != http.StatusOK {
t.Fatalf("list status = %d, want 200 (body=%s)", listResp.StatusCode, listBody)
}
var items []MemorySummary
if err := json.Unmarshal(decodeBody(t, listBody)["data"], &items); err != nil {
t.Fatalf("decode list: %v", err)
}
if len(items) != 1 || items[0].Text != "她喜欢喝冰美式" || items[0].Scope != "persona" {
t.Fatalf("items = %+v, want one persona 她喜欢喝冰美式", items)
}
}
func TestAdminAddMemoryRejectsBadInput(t *testing.T) {
t.Parallel()
store := newMemoryStoreForGateway(t)
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{Memories: store})
tok := signAny(t, jwt, "acct", auth.RoleOwner)
// Blank content.
resp, _ := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/memories",
map[string]any{"personaId": "cyrene", "content": " "}, tok)
if resp.StatusCode != http.StatusBadRequest {
t.Fatalf("blank content status = %d, want 400", resp.StatusCode)
}
// Invalid scope.
resp2, _ := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/memories",
map[string]any{"personaId": "cyrene", "content": "x", "scope": "bogus"}, tok)
if resp2.StatusCode != http.StatusBadRequest {
t.Fatalf("bogus scope status = %d, want 400", resp2.StatusCode)
}
}
func TestAdminAddMemoryUnwired501(t *testing.T) {
t.Parallel()
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{}) // no memory store
tok := signAny(t, jwt, "acct", auth.RoleOwner)
resp, _ := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/memories",
map[string]any{"content": "x"}, tok)
if resp.StatusCode != http.StatusNotImplemented {
t.Fatalf("unwired status = %d, want 501", resp.StatusCode)
}
}
func TestAdminIndexRagImportsAndLists(t *testing.T) {
t.Parallel()
rag := newRagStoreForGateway(t)
srv, ts, jwt := buildEnv(t, cfgDefault(), Deps{RAG: rag})
_ = srv
tok := signAny(t, jwt, "acct", auth.RoleOwner)
resp, body := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/rag",
map[string]any{"name": "内部知识库.md", "desc": "团队规范", "content": "第一段:命名规范。\n\n第二段:评审流程。"}, tok)
if resp.StatusCode != http.StatusCreated {
t.Fatalf("index status = %d, want 201 (body=%s)", resp.StatusCode, body)
}
// The document now shows up in the list (imported + chunked).
listResp, listBody := doReq(t, http.MethodGet, ts.URL+"/api/v1/admin/rag", nil, tok)
if listResp.StatusCode != http.StatusOK {
t.Fatalf("list status = %d, want 200 (body=%s)", listResp.StatusCode, listBody)
}
var res AdminRagResponse
if err := json.Unmarshal(decodeBody(t, listBody)["data"], &res); err != nil {
t.Fatalf("decode list: %v", err)
}
if len(res.Documents) != 1 || res.Documents[0].Name != "内部知识库.md" || res.Documents[0].Chunks != 2 {
t.Fatalf("documents = %+v, want one 内部知识库.md with 2 chunks", res.Documents)
}
// It is immediately queryable (keyword/line path).
qResp, qBody := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/rag/query",
map[string]any{"query": "评审流程"}, tok)
if qResp.StatusCode != http.StatusOK {
t.Fatalf("query status = %d, want 200 (body=%s)", qResp.StatusCode, qBody)
}
var qres struct {
Hits []AdminRagHit `json:"hits"`
}
if err := json.Unmarshal(decodeBody(t, qBody)["data"], &qres); err != nil {
t.Fatalf("decode query: %v", err)
}
if len(qres.Hits) == 0 || qres.Hits[0].DocName != "内部知识库.md" {
t.Fatalf("hits = %+v, want a hit on 内部知识库.md", qres.Hits)
}
}
func TestAdminIndexRagRejectsBlankNameOrContent(t *testing.T) {
t.Parallel()
rag := newRagStoreForGateway(t)
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{RAG: rag})
tok := signAny(t, jwt, "acct", auth.RoleOwner)
resp, _ := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/rag",
map[string]any{"name": " ", "content": "x"}, tok)
if resp.StatusCode != http.StatusBadRequest {
t.Fatalf("blank name status = %d, want 400", resp.StatusCode)
}
resp2, _ := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/rag",
map[string]any{"name": "x", "content": " "}, tok)
if resp2.StatusCode != http.StatusBadRequest {
t.Fatalf("blank content status = %d, want 400", resp2.StatusCode)
}
}
func TestAdminIndexRagUnwired501(t *testing.T) {
t.Parallel()
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{})
tok := signAny(t, jwt, "acct", auth.RoleOwner)
resp, _ := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/rag",
map[string]any{"name": "x", "content": "y"}, tok)
if resp.StatusCode != http.StatusNotImplemented {
t.Fatalf("unwired status = %d, want 501", resp.StatusCode)
}
}
func TestAdminListSessionsHistoryFirst(t *testing.T) {
t.Parallel()
h := newHistoryStoreForGateway(t)
srv, ts, jwt := buildEnv(t, cfgDefault(), Deps{History: h})
_ = srv
tok := signAny(t, jwt, "acct", auth.RoleOwner)
resp, body := doReq(t, http.MethodGet, ts.URL+"/api/v1/admin/sessions", nil, tok)
if resp.StatusCode != http.StatusOK {
t.Fatalf("status = %d, want 200 (body=%s)", resp.StatusCode, body)
}
var items []historySessionSummary
if err := json.Unmarshal(decodeBody(t, body)["data"], &items); err != nil {
t.Fatalf("decode: %v", err)
}
if len(items) == 0 {
t.Fatal("admin sessions list is empty; main session should always exist")
}
if items[0].Type != "main" || items[0].ID == "" {
t.Fatalf("first session = %+v, want a main session with id", items[0])
}
}
+10
View File
@@ -20,6 +20,16 @@ func (s *Server) auditClaims(r *http.Request, what, result string) {
s.audit(r.Context(), who, what, result)
}
// AuditEvent records an external (non-HTTP) audit event with an explicit caller
// identity, so programmatic sinks outside the request path (for example the
// channel bridge's blacklist rejection hook, design/16 §4.6 §6) can append to the
// same who/what/when/result trail. who is a free-form actor label ("channel" or
// "bridge:telegram"); what is the operation and result its outcome. It is safe for
// concurrent use.
func (s *Server) AuditEvent(who, what, result string) {
s.audit(context.Background(), who, what, result)
}
// audit emits one structured audit record on the gateway logger and persists it to
// the configured AuditStore (falling back to an in-memory store when none is
// injected). A persist failure is logged but never blocks the admin write, so a
+55 -4
View File
@@ -34,7 +34,11 @@ type historyMessage struct {
Thinking string `json:"thinking,omitempty"`
Platform string `json:"platform,omitempty"`
DeviceID string `json:"deviceId,omitempty"`
CreatedAt int64 `json:"createdAt"`
// SenderName is the human-readable sender display name of a third-party
// message (group/stranger, design/16 §4.6). It is blank for the owner's
// private chat on the main session, so empty means "labeled as the owner".
SenderName string `json:"senderName,omitempty"`
CreatedAt int64 `json:"createdAt"`
}
// handleHistorySessions returns the main session first, then every sub session (oldest
@@ -125,6 +129,52 @@ func (s *Server) handleListMessages(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, out)
}
// handleChannelPlatformLog returns up to limit messages for an IM platform across its
// isolated (group/stranger) sessions, newest first, for the admin adapter log page
// (design/16 §4.6 §4). It excludes the fixed main web session, so only the platform's
// non-owner message stream is surfaced; the owner-private mirror stays out of this view.
func (s *Server) handleChannelPlatformLog(w http.ResponseWriter, r *http.Request) {
if s.history == nil {
writeError(w, &apperr.AppError{Code: "not_implemented", Message: "会话历史服务未配置(未注入 HistoryStore)", HTTPCode: http.StatusNotImplemented})
return
}
platform := r.PathValue("platform")
if platform == "" {
writeError(w, apperr.Wrap(apperr.ErrBadRequest, "bad_request", "platform is required"))
return
}
limitStr := r.URL.Query().Get("limit")
limit := historyDefaultLimit
if limitStr != "" {
v, err := strconv.Atoi(limitStr)
if err != nil || v < 1 {
writeError(w, apperr.Wrap(apperr.ErrBadRequest, "bad_request", "invalid limit"))
return
}
limit = v
}
var before int64
if b := r.URL.Query().Get("before"); b != "" {
v, err := strconv.ParseInt(b, 10, 64)
if err != nil {
writeError(w, apperr.Wrap(apperr.ErrBadRequest, "bad_request", "invalid before"))
return
}
before = v
}
msgs, err := s.history.ListPlatformLog(r.Context(), platform, before, limit)
if err != nil {
s.log.Error("history platform log", "err", err, "platform", platform)
writeError(w, apperr.Wrap(apperr.ErrInternal, "platform_log_failed", "failed to list platform log"))
return
}
out := make([]historyMessage, 0, len(msgs))
for _, m := range msgs {
out = append(out, toHistoryMessage(m))
}
writeJSON(w, http.StatusOK, out)
}
// handleDeleteSession deletes a sub session and all its messages. The main session is
// immutable (design/16 §6) and returns 403.
func (s *Server) handleDeleteSession(w http.ResponseWriter, r *http.Request) {
@@ -160,9 +210,10 @@ func toHistoryMessage(m history.Message) historyMessage {
Mood: m.Mood,
Image: m.Image,
Thinking: m.Thinking,
Platform: m.Platform,
DeviceID: m.DeviceID,
CreatedAt: m.CreatedAt,
Platform: m.Platform,
DeviceID: m.DeviceID,
SenderName: m.SenderName,
CreatedAt: m.CreatedAt,
}
}
+4
View File
@@ -115,6 +115,7 @@ type HistoryStore interface {
AppendFull(ctx context.Context, msg history.Message) (history.Message, error)
List(ctx context.Context, sessionID string, before int64, limit int, platform string) ([]history.Message, error)
Recent(ctx context.Context, sessionID string, n int) ([]history.Message, error)
ListPlatformLog(ctx context.Context, platform string, before int64, limit int) ([]history.Message, error)
DeleteSession(ctx context.Context, sessionID string) error
NewSubSession(ctx context.Context, ownerID string) (string, error)
ListSessions(ctx context.Context) ([]history.SessionMeta, error)
@@ -347,6 +348,7 @@ func (s *Server) Handler() http.Handler {
mux.Handle("GET /api/v1/admin/memories", adminAuth(http.HandlerFunc(s.adminListMemories)))
mux.Handle("GET /api/v1/admin/plugins", adminAuth(http.HandlerFunc(s.adminListPlugins)))
mux.Handle("GET /api/v1/admin/channels", adminAuth(http.HandlerFunc(s.adminListChannels)))
mux.Handle("GET /api/v1/admin/channels/{platform}/messages", adminAuth(http.HandlerFunc(s.handleChannelPlatformLog)))
mux.Handle("GET /api/v1/admin/iot", adminAuth(http.HandlerFunc(s.adminListIoT)))
mux.Handle("GET /api/v1/admin/llm", adminAuth(http.HandlerFunc(s.adminGetLlm)))
mux.Handle("GET /api/v1/admin/automations", adminAuth(http.HandlerFunc(s.adminListAutomations)))
@@ -383,7 +385,9 @@ func (s *Server) Handler() http.Handler {
mux.Handle("POST /api/v1/admin/channels/test", ownerAuth(http.HandlerFunc(s.adminChannelTest)))
mux.Handle("POST /api/v1/admin/plugins/install", ownerAuth(http.HandlerFunc(s.adminPluginInstall)))
mux.Handle("POST /api/v1/admin/plugins/uninstall", ownerAuth(http.HandlerFunc(s.adminPluginUninstall)))
mux.Handle("POST /api/v1/admin/memories", ownerAuth(http.HandlerFunc(s.adminAddMemory)))
mux.Handle("POST /api/v1/admin/memories/search", ownerAuth(http.HandlerFunc(s.adminMemorySearch)))
mux.Handle("POST /api/v1/admin/rag", ownerAuth(http.HandlerFunc(s.adminIndexRag)))
mux.Handle("GET /api/v1/admin/sessions/{id}/export", adminAuth(http.HandlerFunc(s.adminExportSession)))
// External webhook callbacks (e.g. the webhook channel) are mounted without
@@ -183,6 +183,10 @@ func (f *fakeHistory) Recent(context.Context, string, int) ([]history.Message, e
return nil, nil
}
func (f *fakeHistory) ListPlatformLog(context.Context, string, int64, int) ([]history.Message, error) {
return nil, nil
}
func (f *fakeHistory) DeleteSession(context.Context, string) error {
return nil
}