后端: 1.阶段 6 agent / memory 服务化收口 - 新增 cmd/agent 独立进程入口,承载 agent zrpc server、agent outbox relay / consumer 和运行时依赖初始化 - 补齐 services/agent/rpc 的 Chat stream 与 conversation meta/list/timeline、schedule-preview、context-stats、schedule-state unary RPC - 新增 gateway/client/agent 与 shared/contracts/agent,将 /api/v1/agent chat 和非 chat 门面切到 agent zrpc - 收缩 gateway 本地 AgentService 装配,双 RPC 开关开启时不再初始化本地 agent 编排、LLM、RAG 和 memory reader fallback - 将 backend/memory 物理迁入 services/memory,私有实现收入 internal,保留 module/model/observe 作为 memory 服务门面 - 调整 memory outbox、memory reader 和 agent 记忆渲染链路的 import 与服务边界,cmd/memory 独占 memory worker / consumer - 关闭 gateway 侧 agent outbox worker 所有权,agent relay / consumer 由 cmd/agent 独占,gateway 仅保留 HTTP/SSE 门面与迁移期开关回退 - 更新阶段 6 文档,记录 agent / memory 当前切流点、smoke 结果,以及 backend/client 与 gateway/shared 的目录收口口径
65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package repo
|
||
|
||
import (
|
||
"context"
|
||
"errors"
|
||
|
||
"github.com/LoveLosita/smartflow/backend/model"
|
||
"gorm.io/gorm"
|
||
"gorm.io/gorm/clause"
|
||
)
|
||
|
||
// SettingsRepo 封装 memory_user_settings 的读写。
|
||
type SettingsRepo struct {
|
||
db *gorm.DB
|
||
}
|
||
|
||
func NewSettingsRepo(db *gorm.DB) *SettingsRepo {
|
||
return &SettingsRepo{db: db}
|
||
}
|
||
|
||
func (r *SettingsRepo) WithTx(tx *gorm.DB) *SettingsRepo {
|
||
return &SettingsRepo{db: tx}
|
||
}
|
||
|
||
// GetByUserID 读取用户记忆设置。
|
||
//
|
||
// 返回语义:
|
||
// 1. 命中时返回真实记录;
|
||
// 2. 未命中时返回 nil,nil,由上层决定是否走默认开关;
|
||
// 3. 不在仓储层偷偷补默认值,避免写路径和读路径语义不一致。
|
||
func (r *SettingsRepo) GetByUserID(ctx context.Context, userID int) (*model.MemoryUserSetting, error) {
|
||
if r == nil || r.db == nil {
|
||
return nil, errors.New("memory settings repo is nil")
|
||
}
|
||
if userID <= 0 {
|
||
return nil, errors.New("memory settings user_id is invalid")
|
||
}
|
||
|
||
var setting model.MemoryUserSetting
|
||
query := r.db.WithContext(ctx).Where("user_id = ?", userID).Limit(1).Find(&setting)
|
||
if query.Error != nil {
|
||
return nil, query.Error
|
||
}
|
||
if query.RowsAffected == 0 {
|
||
return nil, nil
|
||
}
|
||
return &setting, nil
|
||
}
|
||
|
||
// Upsert 写入用户记忆设置。
|
||
func (r *SettingsRepo) Upsert(ctx context.Context, setting model.MemoryUserSetting) error {
|
||
if r == nil || r.db == nil {
|
||
return errors.New("memory settings repo is nil")
|
||
}
|
||
return r.db.WithContext(ctx).Clauses(clause.OnConflict{
|
||
Columns: []clause.Column{{Name: "user_id"}},
|
||
DoUpdates: clause.AssignmentColumns([]string{
|
||
"memory_enabled",
|
||
"implicit_memory_enabled",
|
||
"sensitive_memory_enabled",
|
||
"updated_at",
|
||
}),
|
||
}).Create(&setting).Error
|
||
}
|