后端:
1.阶段 6 CP4/CP5 目录收口与共享边界纯化
- 将 backend 根目录收口为 services、client、gateway、cmd、shared 五个一级目录
- 收拢 bootstrap、inits、infra/kafka、infra/outbox、conv、respond、pkg、middleware,移除根目录旧实现与空目录
- 将 utils 下沉到 services/userauth/internal/auth,将 logic 下沉到 services/schedule/core/planning
- 将迁移期 runtime 桥接实现统一收拢到 services/runtime/{conv,dao,eventsvc,model},删除 shared/legacy 与未再被 import 的旧 service 实现
- 将 gateway/shared/respond 收口为 HTTP/Gin 错误写回适配,shared/respond 仅保留共享错误语义与状态映射
- 将 HTTP IdempotencyMiddleware 与 RateLimitMiddleware 收口到 gateway/middleware
- 将 GormCachePlugin 下沉到 shared/infra/gormcache,将共享 RateLimiter 下沉到 shared/infra/ratelimit,将 agent token budget 下沉到 services/agent/shared
- 删除 InitEino 兼容壳,收缩 cmd/internal/coreinit 仅保留旧组合壳残留域初始化语义
- 更新微服务迁移计划与桌面 checklist,补齐 CP4/CP5 当前切流点、目录终态与验证结果
- 完成 go test ./...、git diff --check 与最终真实 smoke;health、register/login、task/create+get、schedule/today、task-class/list、memory/items、agent chat/meta/timeline/context-stats 全部 200,SSE 合并结果为 CP5_OK 且 [DONE] 只有 1 个
82 lines
2.5 KiB
Go
82 lines
2.5 KiB
Go
package utils
|
|
|
|
import (
|
|
memorymodel "github.com/LoveLosita/smartflow/backend/services/memory/model"
|
|
"github.com/LoveLosita/smartflow/backend/services/runtime/model"
|
|
)
|
|
|
|
// EffectiveUserSetting 返回用户记忆设置的生效值。
|
|
//
|
|
// 规则说明:
|
|
// 1. 用户未显式配置时,走系统默认值;
|
|
// 2. 默认允许普通记忆和隐式记忆,但默认关闭敏感记忆;
|
|
// 3. 返回值始终是完整对象,方便调用方直接使用,不再分支判空。
|
|
func EffectiveUserSetting(setting *model.MemoryUserSetting, userID int) model.MemoryUserSetting {
|
|
if setting == nil {
|
|
return model.MemoryUserSetting{
|
|
UserID: userID,
|
|
MemoryEnabled: true,
|
|
ImplicitMemoryEnabled: true,
|
|
SensitiveMemoryEnabled: false,
|
|
}
|
|
}
|
|
return *setting
|
|
}
|
|
|
|
// FilterFactsBySetting 按用户记忆开关过滤候选事实。
|
|
func FilterFactsBySetting(facts []memorymodel.NormalizedFact, setting model.MemoryUserSetting) []memorymodel.NormalizedFact {
|
|
if !setting.MemoryEnabled || len(facts) == 0 {
|
|
return nil
|
|
}
|
|
|
|
result := make([]memorymodel.NormalizedFact, 0, len(facts))
|
|
for _, fact := range facts {
|
|
if !setting.ImplicitMemoryEnabled && !fact.IsExplicit {
|
|
continue
|
|
}
|
|
if !setting.SensitiveMemoryEnabled && fact.SensitivityLevel > 0 {
|
|
continue
|
|
}
|
|
result = append(result, fact)
|
|
}
|
|
return result
|
|
}
|
|
|
|
// FilterItemsBySetting 按用户记忆开关过滤已入库记忆。
|
|
func FilterItemsBySetting(items []model.MemoryItem, setting model.MemoryUserSetting) []model.MemoryItem {
|
|
if !setting.MemoryEnabled || len(items) == 0 {
|
|
return nil
|
|
}
|
|
|
|
result := make([]model.MemoryItem, 0, len(items))
|
|
for _, item := range items {
|
|
if !setting.ImplicitMemoryEnabled && !item.IsExplicit {
|
|
continue
|
|
}
|
|
if !setting.SensitiveMemoryEnabled && item.SensitivityLevel > 0 {
|
|
continue
|
|
}
|
|
result = append(result, item)
|
|
}
|
|
return result
|
|
}
|
|
|
|
// FilterFactsByConfidence 按置信度阈值过滤候选事实。
|
|
//
|
|
// 说明:
|
|
// 1. minConfidence <= 0 时不做过滤,保持向后兼容;
|
|
// 2. 过滤在 FilterFactsBySetting 之后执行,是写入链路的第二道程序化门槛;
|
|
// 3. 阈值由 memory.write.minConfidence 配置控制,默认 0.5。
|
|
func FilterFactsByConfidence(facts []memorymodel.NormalizedFact, minConfidence float64) []memorymodel.NormalizedFact {
|
|
if minConfidence <= 0 || len(facts) == 0 {
|
|
return facts
|
|
}
|
|
result := make([]memorymodel.NormalizedFact, 0, len(facts))
|
|
for _, fact := range facts {
|
|
if fact.Confidence >= minConfidence {
|
|
result = append(result, fact)
|
|
}
|
|
}
|
|
return result
|
|
}
|