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
@@ -86,8 +86,15 @@ type Message struct {
|
||||
// that sent the message (design/16 §4.5) — e.g. "web:chrome:a1b2c3" for a
|
||||
// browser, "weixin-ilink:conf0:wx_uid_123" for IM. It complements Platform: two
|
||||
// clients on the same platform share Platform but differ in DeviceID.
|
||||
DeviceID string
|
||||
CreatedAt int64
|
||||
DeviceID string
|
||||
// SenderName is the human-readable display name of the message's sender
|
||||
// (design/16 §4.6). It is set for third-party messages (group chats and
|
||||
// stranger private chats) so the agent and the IM adapter log page can label
|
||||
// who is speaking; it is intentionally blank for the owner's private chat on
|
||||
// the main session (the owner is never labeled). It is display metadata only —
|
||||
// identity is never decided from this field.
|
||||
SenderName string
|
||||
CreatedAt int64
|
||||
}
|
||||
|
||||
// SessionMeta is the wire-facing metadata of one persistent session.
|
||||
@@ -117,6 +124,12 @@ type HistoryStore interface {
|
||||
// Recent returns the most recent n messages for sessionID in oldest-first order,
|
||||
// for WS replay / context tail usage.
|
||||
Recent(ctx context.Context, sessionID string, n int) ([]Message, error)
|
||||
// ListPlatformLog returns up to limit messages for an IM platform across every
|
||||
// non-main (isolated) session, newest first, for the adapter log page (design/16
|
||||
// §4.6 §4). It excludes the fixed main web session, so the platform's non-owner
|
||||
// message stream (groups + stranger private chats) is surfaced without the
|
||||
// owner-private mirror. before is a millisecond cursor; 0 means newest page.
|
||||
ListPlatformLog(ctx context.Context, platform string, before int64, limit int) ([]Message, error)
|
||||
// DeleteSession removes a sub session and all its messages. The main session is
|
||||
// immutable and returns ErrImmutableMain.
|
||||
DeleteSession(ctx context.Context, sessionID string) error
|
||||
@@ -199,10 +212,10 @@ func (s *Store) insert(ctx context.Context, msg Message) (Message, error) {
|
||||
msg.Platform = PlatformWeb
|
||||
}
|
||||
_, err := s.db.ExecContext(ctx, `INSERT INTO chat_messages
|
||||
(id, session_id, role, content, mode, mood, image, thinking, platform, device_id, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
(id, session_id, role, content, mode, mood, image, thinking, platform, device_id, sender_name, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
msg.ID, msg.SessionID, msg.Role, msg.Content, msg.Mode, msg.Mood,
|
||||
msg.Image, msg.Thinking, msg.Platform, msg.DeviceID, msg.CreatedAt)
|
||||
msg.Image, msg.Thinking, msg.Platform, msg.DeviceID, msg.SenderName, msg.CreatedAt)
|
||||
if err != nil {
|
||||
return Message{}, fmt.Errorf("history: append %s to %s: %w", msg.Role, msg.SessionID, err)
|
||||
}
|
||||
@@ -218,7 +231,7 @@ func (s *Store) insert(ctx context.Context, msg Message) (Message, error) {
|
||||
// limit is clamped to [1, maxPageLimit].
|
||||
func (s *Store) List(ctx context.Context, sessionID string, before int64, limit int, platform string) ([]Message, error) {
|
||||
limit = clampLimit(limit)
|
||||
query := `SELECT id, session_id, role, content, mode, mood, image, thinking, platform, device_id, created_at
|
||||
query := `SELECT id, session_id, role, content, mode, mood, image, thinking, platform, device_id, sender_name, created_at
|
||||
FROM chat_messages WHERE session_id = ?`
|
||||
args := []any{sessionID}
|
||||
if before > 0 {
|
||||
@@ -252,13 +265,50 @@ func (s *Store) List(ctx context.Context, sessionID string, before int64, limit
|
||||
return msgs, nil
|
||||
}
|
||||
|
||||
// ListPlatformLog returns up to limit messages for platform across every non-main
|
||||
// (isolated) session, newest first. Main-session messages are excluded so only the
|
||||
// platform's own message stream (groups + stranger private chats) is surfaced to the
|
||||
// adapter log page (design/16 §4.6 §4). before is a millisecond cursor; when nonzero
|
||||
// only strictly older messages are returned. The returned slice is non-nil.
|
||||
func (s *Store) ListPlatformLog(ctx context.Context, platform string, before int64, limit int) ([]Message, error) {
|
||||
limit = clampLimit(limit)
|
||||
query := `SELECT id, session_id, role, content, mode, mood, image, thinking, platform, device_id, sender_name, created_at
|
||||
FROM chat_messages WHERE platform = ? AND session_id != ?`
|
||||
args := []any{platform, MainSessionID}
|
||||
if before > 0 {
|
||||
query += ` AND created_at < ?`
|
||||
args = append(args, before)
|
||||
}
|
||||
query += ` ORDER BY created_at DESC LIMIT ?`
|
||||
args = append(args, limit)
|
||||
|
||||
rows, err := s.db.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("history: platform log %s: %w", platform, err)
|
||||
}
|
||||
defer func() { _ = rows.Close() }()
|
||||
|
||||
msgs := make([]Message, 0)
|
||||
for rows.Next() {
|
||||
m, err := scanMessage(rows)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("history: scan platform log %s: %w", platform, err)
|
||||
}
|
||||
msgs = append(msgs, m)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("history: iterate platform log %s: %w", platform, err)
|
||||
}
|
||||
return msgs, nil
|
||||
}
|
||||
|
||||
// Recent returns the most recent n messages for sessionID in oldest-first order (the
|
||||
// tail-most window), for WS replay / context tail. The returned slice is non-nil.
|
||||
func (s *Store) Recent(ctx context.Context, sessionID string, n int) ([]Message, error) {
|
||||
if n < 1 {
|
||||
n = defaultPageLimit
|
||||
}
|
||||
rows, err := s.db.QueryContext(ctx, `SELECT id, session_id, role, content, mode, mood, image, thinking, platform, device_id, created_at
|
||||
rows, err := s.db.QueryContext(ctx, `SELECT id, session_id, role, content, mode, mood, image, thinking, platform, device_id, sender_name, created_at
|
||||
FROM chat_messages WHERE session_id = ? ORDER BY created_at DESC LIMIT ?`, sessionID, n)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("history: recent %s: %w", sessionID, err)
|
||||
@@ -372,11 +422,11 @@ func (s *Store) ensureMainSession(ctx context.Context) error {
|
||||
// scanMessage reads one chat_messages row. message columns are scanned positionally.
|
||||
func scanMessage(sc rowScanner) (Message, error) {
|
||||
var m Message
|
||||
var mode, mood, image, thinking, platform, deviceID string
|
||||
if err := sc.Scan(&m.ID, &m.SessionID, &m.Role, &m.Content, &mode, &mood, &image, &thinking, &platform, &deviceID, &m.CreatedAt); err != nil {
|
||||
var mode, mood, platform, deviceID, senderName string
|
||||
if err := sc.Scan(&m.ID, &m.SessionID, &m.Role, &m.Content, &mode, &mood, &m.Image, &m.Thinking, &platform, &deviceID, &senderName, &m.CreatedAt); err != nil {
|
||||
return Message{}, err
|
||||
}
|
||||
m.Mode, m.Mood, m.Image, m.Thinking, m.Platform, m.DeviceID = mode, mood, image, thinking, platform, deviceID
|
||||
m.Mode, m.Mood, m.Platform, m.DeviceID, m.SenderName = mode, mood, platform, deviceID, senderName
|
||||
return m, nil
|
||||
}
|
||||
|
||||
@@ -433,6 +483,7 @@ CREATE TABLE IF NOT EXISTS chat_messages (
|
||||
thinking TEXT,
|
||||
platform TEXT NOT NULL DEFAULT 'web',
|
||||
device_id TEXT NOT NULL DEFAULT '',
|
||||
sender_name TEXT NOT NULL DEFAULT '',
|
||||
created_at INTEGER NOT NULL
|
||||
)`
|
||||
|
||||
|
||||
@@ -367,3 +367,59 @@ func TestDeleteSession(t *testing.T) {
|
||||
t.Fatalf("delete main err = %v, want ErrImmutableMain", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSenderNameRoundTripOnListRecentAndPlatformLog(t *testing.T) {
|
||||
t.Parallel()
|
||||
st := newStore(t)
|
||||
ctx := context.Background()
|
||||
|
||||
// An isolated group session carries the sender display name (design/16 §4.6).
|
||||
groupID := "sess-g"
|
||||
if err := st.Append(ctx, Message{SessionID: groupID, Role: RoleUser, Content: "hello all", Platform: "telegram", SenderName: "张三", DeviceID: "telegram:-20:9", CreatedAt: 1000}); err != nil {
|
||||
t.Fatalf("append group msg: %v", err)
|
||||
}
|
||||
// An owner-private message on the main session carries no sender name.
|
||||
if err := st.Append(ctx, Message{SessionID: MainSessionID, Role: RoleUser, Content: "hi", Platform: "telegram", CreatedAt: 900}); err != nil {
|
||||
t.Fatalf("append main msg: %v", err)
|
||||
}
|
||||
// An unrelated platform on the main session should not leak into the log.
|
||||
if err := st.Append(ctx, Message{SessionID: MainSessionID, Role: RoleUser, Content: "web msg", Platform: "web", CreatedAt: 800}); err != nil {
|
||||
t.Fatalf("append web msg: %v", err)
|
||||
}
|
||||
|
||||
// List reads the sender_name back.
|
||||
ls, err := st.List(ctx, groupID, 0, 50, "")
|
||||
if err != nil {
|
||||
t.Fatalf("list: %v", err)
|
||||
}
|
||||
if len(ls) != 1 || ls[0].SenderName != "张三" || ls[0].Content != "hello all" {
|
||||
t.Fatalf("list = %+v, want SenderName 张三", ls)
|
||||
}
|
||||
|
||||
// Recent reads it too.
|
||||
rs, err := st.Recent(ctx, groupID, 5)
|
||||
if err != nil {
|
||||
t.Fatalf("recent: %v", err)
|
||||
}
|
||||
if len(rs) != 1 || rs[0].SenderName != "张三" {
|
||||
t.Fatalf("recent = %+v, want SenderName 张三", rs)
|
||||
}
|
||||
|
||||
// Platform log surfaces only the isolated (non-main) messages of the platform,
|
||||
// newest first, excluding the owner-private mirror on the main session.
|
||||
log, err := st.ListPlatformLog(ctx, "telegram", 0, 50)
|
||||
if err != nil {
|
||||
t.Fatalf("platform log: %v", err)
|
||||
}
|
||||
if len(log) != 1 {
|
||||
t.Fatalf("platform log = %+v, want only the isolated group message", log)
|
||||
}
|
||||
if log[0].SessionID != groupID || log[0].SenderName != "张三" {
|
||||
t.Fatalf("platform log[0] = %+v, want group session with SenderName 张三", log[0])
|
||||
}
|
||||
|
||||
// A platform with only main-session messages yields an empty log.
|
||||
if log, err := st.ListPlatformLog(ctx, "web", 0, 50); err != nil || len(log) != 0 {
|
||||
t.Fatalf("web platform log = %+v, err=%v; want empty", log, err)
|
||||
}
|
||||
}
|
||||
@@ -10,28 +10,36 @@
|
||||
// so a configured vector index (pgvector / SQLite vector) is genuinely used and
|
||||
// never a shell.
|
||||
//
|
||||
// The store is read-only for this milestone: upload/chunk/embed and delete land
|
||||
// in M10. The write methods return ErrWriteUnsupported so the admin handler can
|
||||
// answer honestly instead of fabricating a success.
|
||||
// The store persists knowledge documents by indexing them into the project index
|
||||
// (项目索引 → 项目描述 → 章节内容): IndexDocument chunks a document's content and
|
||||
// stores it as a project plus its chapters, making it text/keyword-searchable
|
||||
// immediately. Semantic/vector embedding of an imported document is a graceful
|
||||
// no-op here (this data source holds no vector index); the existing semantic path
|
||||
// still ranks project-linked memories via the retriever. Deletion remains
|
||||
// unimplemented (M10) and returns ErrWriteUnsupported so the admin handler
|
||||
// answers honestly instead of fabricating a success.
|
||||
package knowledge
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/logger"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/memory"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/memory/projectindex"
|
||||
)
|
||||
|
||||
// ErrWriteUnsupported is returned by the write operations. Upload/chunk/embed and
|
||||
// delete are milestone M10; the admin handler maps it to a clear 501 so the
|
||||
// frontend can explain rather than show a placeholder alert.
|
||||
var ErrWriteUnsupported = errors.New("knowledge: write operations (upload/chunk/embed/delete) land in M10")
|
||||
// ErrWriteUnsupported is returned by DeleteDocument. Deletion is milestone M10;
|
||||
// the admin handler maps it to a clear 501 so the frontend can explain rather
|
||||
// than show a placeholder alert.
|
||||
var ErrWriteUnsupported = errors.New("knowledge: delete is not implemented in this milestone")
|
||||
|
||||
// defaultTopK bounds the semantic retrieval path.
|
||||
const defaultTopK = 8
|
||||
@@ -54,8 +62,12 @@ type Doc struct {
|
||||
Chunks int
|
||||
// Embedded reports whether a persistent vector index is wired for this
|
||||
// deployment. This is the deployment-level semantic capability; per-document
|
||||
// embedding state is not tracked yet (M10).
|
||||
// embedding state is not tracked yet.
|
||||
Embedded bool
|
||||
// Content is the document body supplied to IndexDocument. It is empty for
|
||||
// documents returned by ListDocuments (they carry metadata only) and is
|
||||
// chunked into chapters by IndexDocument.
|
||||
Content string
|
||||
}
|
||||
|
||||
// Hit is one retrieval result surfaced to the admin panel.
|
||||
@@ -253,10 +265,61 @@ func describeProject(p *projectindex.Project) string {
|
||||
return p.Title
|
||||
}
|
||||
|
||||
// IndexDocument is not implemented in this milestone. It returns
|
||||
// ErrWriteUnsupported so the handler answers honestly (upload/chunk/embed = M10).
|
||||
func (s *Store) IndexDocument(_ context.Context, _ Doc) error {
|
||||
return ErrWriteUnsupported
|
||||
// IndexDocument persists a document into the project index: it creates a project
|
||||
// entry (title + description), chunks the content into chapters and adds each
|
||||
// chapter, so the document becomes immediately text/keyword-searchable via
|
||||
// projectindex.Search. A blank name or content returns an error. When the
|
||||
// project-index store is not wired there is nowhere to persist, so it returns an
|
||||
// error rather than a fabricated success.
|
||||
//
|
||||
// Semantic embedding is a graceful no-op: this data source does not own a vector
|
||||
// index, so a document imported here is keyword-searchable, and the existing
|
||||
// semantic path (project-linked memories ranked by the retriever) is untouched.
|
||||
// Per the red line that a configured vector enhancement must be genuinely used
|
||||
// and never a shell, we do not pretend to embed; the "Embedded" flag still
|
||||
// reflects the deployment-level vector capability reported by ListDocuments.
|
||||
func (s *Store) IndexDocument(ctx context.Context, doc Doc) error {
|
||||
name := strings.TrimSpace(doc.Name)
|
||||
if name == "" {
|
||||
return errors.New("knowledge: index document: name is required")
|
||||
}
|
||||
content := strings.TrimSpace(doc.Content)
|
||||
if content == "" {
|
||||
return errors.New("knowledge: index document: content is required")
|
||||
}
|
||||
if s.projects == nil {
|
||||
return errors.New("knowledge: index document: project index store is not configured")
|
||||
}
|
||||
|
||||
projectID := strings.TrimSpace(doc.ID)
|
||||
if projectID == "" {
|
||||
id, err := newProjectID()
|
||||
if err != nil {
|
||||
return fmt.Errorf("knowledge: index document: %w", err)
|
||||
}
|
||||
projectID = id
|
||||
}
|
||||
|
||||
if err := s.projects.PutProject(ctx, projectindex.Project{
|
||||
ID: projectID,
|
||||
Title: name,
|
||||
Desc: strings.TrimSpace(doc.Desc),
|
||||
}); err != nil {
|
||||
return fmt.Errorf("knowledge: index project: %w", err)
|
||||
}
|
||||
|
||||
chunks := chunkDocument(content)
|
||||
for i, ch := range chunks {
|
||||
if err := s.projects.AddChapter(ctx, projectID, projectindex.Chapter{
|
||||
ProjectID: projectID,
|
||||
Title: fmt.Sprintf("第 %d 节", i+1),
|
||||
Content: ch,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("knowledge: index chapter %d: %w", i+1, err)
|
||||
}
|
||||
}
|
||||
s.log.Info("indexed document", "project", projectID, "name", name, "chapters", len(chunks))
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteDocument is not implemented in this milestone. It returns
|
||||
@@ -264,3 +327,53 @@ func (s *Store) IndexDocument(_ context.Context, _ Doc) error {
|
||||
func (s *Store) DeleteDocument(_ context.Context, _ string) error {
|
||||
return ErrWriteUnsupported
|
||||
}
|
||||
|
||||
// maxChapterRunes bounds a single chapter's content length. Paragraphs longer
|
||||
// than this are split into fixed-run pieces so no chapter is overwhelmingly large.
|
||||
const maxChapterRunes = 500
|
||||
|
||||
// chunkDocument splits content into chapter-sized strings. Paragraphs are
|
||||
// split on blank lines (a run of two or more newlines); a paragraph longer than
|
||||
// maxChapterRunes is cut into fixed-run pieces at a rune boundary. Empty
|
||||
// paragraphs are dropped and a non-nil (possibly empty) slice is returned.
|
||||
func chunkDocument(content string) []string {
|
||||
paragraphs := strings.Split(content, "\n\n")
|
||||
chunks := make([]string, 0, len(paragraphs))
|
||||
for _, p := range paragraphs {
|
||||
p = strings.TrimSpace(p)
|
||||
if p == "" {
|
||||
continue
|
||||
}
|
||||
if utf8.RuneCountInString(p) <= maxChapterRunes {
|
||||
chunks = append(chunks, p)
|
||||
continue
|
||||
}
|
||||
chunks = append(chunks, splitRunes(p, maxChapterRunes)...)
|
||||
}
|
||||
return chunks
|
||||
}
|
||||
|
||||
// splitRunes breaks s into pieces of at most n runes each.
|
||||
func splitRunes(s string, n int) []string {
|
||||
rs := []rune(s)
|
||||
out := make([]string, 0, (len(rs)+n-1)/n)
|
||||
for len(rs) > 0 {
|
||||
if len(rs) <= n {
|
||||
out = append(out, string(rs))
|
||||
break
|
||||
}
|
||||
out = append(out, string(rs[:n]))
|
||||
rs = rs[n:]
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// newProjectID returns a 128-bit cryptographically random id, hex-encoded. It
|
||||
// avoids a UUID dependency so the package stays self-contained.
|
||||
func newProjectID() (string, error) {
|
||||
b := make([]byte, 16)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
return "", fmt.Errorf("knowledge: generate id: %w", err)
|
||||
}
|
||||
return hex.EncodeToString(b), nil
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package knowledge
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"log/slog"
|
||||
"testing"
|
||||
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/db"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/memory/projectindex"
|
||||
)
|
||||
|
||||
func testLogger() *slog.Logger {
|
||||
return slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
}
|
||||
|
||||
// newTestStore builds a Store backed by an isolated in-memory SQLite project index.
|
||||
func newTestStore(t *testing.T) *Store {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
d, err := db.Open(ctx, ":memory:", testLogger())
|
||||
if err != nil {
|
||||
t.Fatalf("open in-memory db: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { _ = d.Close() })
|
||||
ps, err := projectindex.New(ctx, d, testLogger())
|
||||
if err != nil {
|
||||
t.Fatalf("projectindex.New: %v", err)
|
||||
}
|
||||
return New(Deps{Projects: ps, Log: testLogger()})
|
||||
}
|
||||
|
||||
func TestIndexDocumentPersistsProjectAndChapters(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
s := newTestStore(t)
|
||||
|
||||
doc := Doc{Name: "Cyrene 设计", Desc: "v2 设计文档", Content: "这是项目描述段落。\n\n第二段:内部实现要点。\n第三行补充说明。"}
|
||||
if err := s.IndexDocument(ctx, doc); err != nil {
|
||||
t.Fatalf("IndexDocument: %v", err)
|
||||
}
|
||||
|
||||
docs, err := s.ListDocuments(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("ListDocuments: %v", err)
|
||||
}
|
||||
if len(docs) != 1 {
|
||||
t.Fatalf("documents = %d, want 1", len(docs))
|
||||
}
|
||||
if docs[0].Name != "Cyrene 设计" || docs[0].Desc != "v2 设计文档" {
|
||||
t.Fatalf("doc = %+v, want name/desc set", docs[0])
|
||||
}
|
||||
if docs[0].Chunks != 2 {
|
||||
t.Fatalf("chunks = %d, want 2 (two paragraphs)", docs[0].Chunks)
|
||||
}
|
||||
|
||||
// The imported content is keyword-searchable via the project index.
|
||||
hits, err := s.Search(ctx, "内部实现")
|
||||
if err != nil {
|
||||
t.Fatalf("Search: %v", err)
|
||||
}
|
||||
if len(hits) == 0 {
|
||||
t.Fatalf("search returned no hits for imported content")
|
||||
}
|
||||
found := false
|
||||
for _, h := range hits {
|
||||
if h.DocName == "Cyrene 设计" && h.Chapter == "第 2 节" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("hits = %+v, want chapter 第 2 节 under Cyrene 设计", hits)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexDocumentRejectsBlankNameOrContent(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
s := newTestStore(t)
|
||||
|
||||
if err := s.IndexDocument(ctx, Doc{Content: "有内容没名字"}); err == nil {
|
||||
t.Fatal("IndexDocument with blank name should error")
|
||||
}
|
||||
if err := s.IndexDocument(ctx, Doc{Name: "有名字没内容"}); err == nil {
|
||||
t.Fatal("IndexDocument with blank content should error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexDocumentRequiresProjectStore(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
s := New(Deps{Log: testLogger()}) // projects == nil
|
||||
|
||||
err := s.IndexDocument(ctx, Doc{Name: "x", Content: "y"})
|
||||
if err == nil {
|
||||
t.Fatal("IndexDocument without a project index should error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteDocumentStillUnsupported(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := New(Deps{Log: testLogger()})
|
||||
if err := s.DeleteDocument(context.Background(), "any"); !errors.Is(err, ErrWriteUnsupported) {
|
||||
t.Fatalf("DeleteDocument err = %v, want ErrWriteUnsupported", err)
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,13 @@ type Message struct {
|
||||
// Content carries one or more parts. A text-only message uses a single
|
||||
// ContentTypeText part.
|
||||
Content []Content
|
||||
// SenderName is the human-readable display name of the message's sender
|
||||
// (design/16 §4.6). It is transport metadata used by the context-assembly
|
||||
// layer to label third-party messages for the model (e.g. "[第三方 · 昵称]"),
|
||||
// never a substitute for the strongly typed sender identity carried on the
|
||||
// channel layer. Empty means the sender is unlabeled (the owner, or an
|
||||
// unknown/unresolved sender), and callers may leave it unset.
|
||||
SenderName string
|
||||
// ToolCallID and ToolCallName are reserved as interface-level placeholders
|
||||
// for the M2 tool loop; they are ignored by current adapters.
|
||||
ToolCallID string
|
||||
|
||||
Reference in new issue
Block a user