feat(gateway): 会话title生成+PATCH改名(A4) — 首条用户消息自动命名+可重命名
- history/title.go: RenameSession(改名字段)+ensureTitle(首条用户消息自动命名,折叠空白取前20rune,纯空白回落主会话/次级会话)
- store.go insert() 前调用 ensureTitle(覆盖Web+IM,最小侵入), HistoryStore 新增 RenameSession
- gateway: PATCH /api/v1/sessions/{id} (owner/admin, ≤80rune, 主会话可改名), handleRenameSession
- 新增/扩展测试(title_test, history_handler_test, fake同步)
- Docs/api-client.md v0.21 同步
This commit is contained in:
1 parent
747b9ad414
commit
89c5fe8027
9 files changed
+466
-4
No files matched your search
@@ -151,6 +151,10 @@ type HistoryStore interface {
|
||||
// DeleteSession removes a sub session and all its messages. The main session is
|
||||
// immutable and returns ErrImmutableMain.
|
||||
DeleteSession(ctx context.Context, sessionID string) error
|
||||
// RenameSession sets a session's display title. Both the main session and sub
|
||||
// sessions may be renamed (a title is display-only metadata); an unknown id
|
||||
// returns ErrSessionNotFound.
|
||||
RenameSession(ctx context.Context, sessionID, title string) error
|
||||
// NewSubSession creates a new sub session and returns its id (MainSessionID:uuid).
|
||||
NewSubSession(ctx context.Context, ownerID string) (string, error)
|
||||
// ListSessions returns the main session first then every sub session, oldest first.
|
||||
@@ -229,6 +233,9 @@ func (s *Store) insert(ctx context.Context, msg Message) (Message, error) {
|
||||
if msg.Platform == "" {
|
||||
msg.Platform = PlatformWeb
|
||||
}
|
||||
if msg.Role == RoleUser {
|
||||
s.ensureTitle(ctx, msg.SessionID, msg.Content)
|
||||
}
|
||||
_, err := s.db.ExecContext(ctx, `INSERT INTO chat_messages
|
||||
(id, session_id, role, content, mode, mood, image, thinking, platform, device_id, sender_name, adapter_id, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
|
||||
Reference in new issue
Block a user