feat: 实现 sessions 持久化,支持会话恢复

This commit is contained in:
hhs
2026-06-14 18:54:18 +08:00
parent d724a8e9f9
commit 966b30218a
6 changed files with 376 additions and 35 deletions

View File

@@ -0,0 +1,47 @@
package store
import (
"context"
"errors"
"time"
)
var (
// ErrSessionNotFound 会话不存在。
ErrSessionNotFound = errors.New("session not found")
)
// SessionRepository 会话持久化接口。
type SessionRepository interface {
// Save 创建或更新会话UPSERT
Save(ctx context.Context, s SessionRecord) error
// FindByID 根据 ID 查询会话。
FindByID(ctx context.Context, id string) (*SessionRecord, error)
// FindByUser 查询用户的会话列表(分页,按 updated_at 降序)。
// 返回 (列表, 总数, error)。
FindByUser(ctx context.Context, userID string, page, size int) ([]SessionRecord, int, error)
// UpdateTitle 更新会话标题。
UpdateTitle(ctx context.Context, id string, title string) error
// UpdateConfig 更新会话配置。
UpdateConfig(ctx context.Context, id string, configJSON []byte) error
// Touch 刷新 updated_at。
Touch(ctx context.Context, id string) error
// Delete 删除会话。
Delete(ctx context.Context, id string) error
}
// SessionRecord 持久化会话模型store 层)。
type SessionRecord struct {
ID string
UserID string
Title string
Config []byte // JSON 编码的 SessionConfig
CreatedAt time.Time
UpdatedAt time.Time
}