后端: 1. 品牌文案与聊天定位统一切到 SmartMate,并放宽非排程问答能力 - 系统人设、路由、排程、查询、交付提示统一从 SmartFlow 改为 SmartMate - 明确普通问答/生活建议/开放讨论可正常回答,deep_answer 不再输出“让我想想”等占位话术 - thinkingMode=auto 时,deep_answer 默认开启 thinking,execute 继续跟随路由决策,其余路由默认关闭 2. Memory 读取链路升级为“结构化强约束 + 语义候选”hybrid 模式,并补齐注入渲染 / Execute 消费 - 新增 read.mode、四类记忆预算、inject.renderMode 等配置及默认值 - 落地 HybridRetrieve,统一 MySQL/RAG 读侧作用域、三级去重(ID/hash/text)、统一重排与按类型预算裁剪 - 新增 FindPinnedByUser、content_hash DTO/兜底补算、legacy/RAG 共用读侧查询口径与 fallback 逻辑 - 记忆注入支持 flat/typed_v2 两种渲染,execute msg3 正式消费 memory_context,主链路注入 MemoryReader 时同步透传 memory 配置 3. Memory 第二步/第三步 handoff 与治理文档补齐 - HANDOFF_Memory向Mem0靠拢三步冲刺计划.md 从 newAgent 迁到 memory 目录,并补充“我的记忆”增删改查与最小留痕口径 - 新增 backend/memory/记忆模块第二步计划.md、backend/memory/第三步治理与观测落地计划.md,分别拆解 hybrid 读取注入闭环与治理/观测/清理路线 - 同步更新 backend/memory/Log.txt 调试日志 前端: 1. 助手输入区新增“智能编排”任务类选择器,并把 task_class_ids 作为请求 extra 透传 - 新建 frontend/src/components/assistant/TaskClassPlanningPicker.vue,支持拉取任务类列表、临时勾选、已选标签回显与清空 - 更新 frontend/src/components/dashboard/AssistantPanel.vue、frontend/src/types/dashboard.ts:Chat extra 正式建模 task_class_ids / retry 字段;当本轮带编排任务类时强制新起会话,避免把现有会话历史误混入新编排 2. 会话上下文窗口统计接入前端展示 - 更新 frontend/src/api/agent.ts、新建 frontend/src/components/assistant/ContextWindowMeter.vue、更新 frontend/src/components/dashboard/AssistantPanel.vue、frontend/src/types/dashboard.ts:接入 /agent/context-stats,兼容 object/string/null 三种返回;在输入工具栏展示 msg0~msg3 占比与预算使用率 3. 助手面板交互细节优化 - 更新 frontend/src/components/dashboard/AssistantPanel.vue:thinking 开关改为 auto/true/false 三态选择;切会话与重试后同步刷新 context stats;历史列表首屏不足时自动继续分页直到形成滚动区 仓库:无
150 lines
4.0 KiB
Go
150 lines
4.0 KiB
Go
package service
|
||
|
||
import (
|
||
"strings"
|
||
|
||
memorymodel "github.com/LoveLosita/smartflow/backend/memory/model"
|
||
memoryutils "github.com/LoveLosita/smartflow/backend/memory/utils"
|
||
"github.com/LoveLosita/smartflow/backend/model"
|
||
)
|
||
|
||
func toItemDTO(item model.MemoryItem) memorymodel.ItemDTO {
|
||
return memorymodel.ItemDTO{
|
||
ID: item.ID,
|
||
UserID: item.UserID,
|
||
ConversationID: strValue(item.ConversationID),
|
||
AssistantID: strValue(item.AssistantID),
|
||
RunID: strValue(item.RunID),
|
||
MemoryType: item.MemoryType,
|
||
Title: item.Title,
|
||
Content: item.Content,
|
||
ContentHash: fallbackContentHash(item.MemoryType, item.Content, strValue(item.ContentHash)),
|
||
Confidence: item.Confidence,
|
||
Importance: item.Importance,
|
||
SensitivityLevel: item.SensitivityLevel,
|
||
IsExplicit: item.IsExplicit,
|
||
Status: item.Status,
|
||
TTLAt: item.TTLAt,
|
||
CreatedAt: item.CreatedAt,
|
||
UpdatedAt: item.UpdatedAt,
|
||
}
|
||
}
|
||
|
||
func toItemDTOs(items []model.MemoryItem) []memorymodel.ItemDTO {
|
||
if len(items) == 0 {
|
||
return nil
|
||
}
|
||
result := make([]memorymodel.ItemDTO, 0, len(items))
|
||
for _, item := range items {
|
||
result = append(result, toItemDTO(item))
|
||
}
|
||
return result
|
||
}
|
||
|
||
func toUserSettingDTO(setting model.MemoryUserSetting) memorymodel.UserSettingDTO {
|
||
return memorymodel.UserSettingDTO{
|
||
UserID: setting.UserID,
|
||
MemoryEnabled: setting.MemoryEnabled,
|
||
ImplicitMemoryEnabled: setting.ImplicitMemoryEnabled,
|
||
SensitiveMemoryEnabled: setting.SensitiveMemoryEnabled,
|
||
UpdatedAt: setting.UpdatedAt,
|
||
}
|
||
}
|
||
|
||
func normalizeMemoryTypes(raw []string) []string {
|
||
if len(raw) == 0 {
|
||
return nil
|
||
}
|
||
result := make([]string, 0, len(raw))
|
||
seen := make(map[string]struct{}, len(raw))
|
||
for _, item := range raw {
|
||
normalized := memorymodel.NormalizeMemoryType(item)
|
||
if normalized == "" {
|
||
continue
|
||
}
|
||
if _, exists := seen[normalized]; exists {
|
||
continue
|
||
}
|
||
seen[normalized] = struct{}{}
|
||
result = append(result, normalized)
|
||
}
|
||
return result
|
||
}
|
||
|
||
func normalizeManageStatuses(raw []string) []string {
|
||
if len(raw) == 0 {
|
||
return []string{
|
||
model.MemoryItemStatusActive,
|
||
model.MemoryItemStatusArchived,
|
||
}
|
||
}
|
||
|
||
result := make([]string, 0, len(raw))
|
||
seen := make(map[string]struct{}, len(raw))
|
||
for _, item := range raw {
|
||
status := strings.ToLower(strings.TrimSpace(item))
|
||
if status != model.MemoryItemStatusActive &&
|
||
status != model.MemoryItemStatusArchived &&
|
||
status != model.MemoryItemStatusDeleted {
|
||
continue
|
||
}
|
||
if _, exists := seen[status]; exists {
|
||
continue
|
||
}
|
||
seen[status] = struct{}{}
|
||
result = append(result, status)
|
||
}
|
||
if len(result) == 0 {
|
||
return []string{
|
||
model.MemoryItemStatusActive,
|
||
model.MemoryItemStatusArchived,
|
||
}
|
||
}
|
||
return result
|
||
}
|
||
|
||
func normalizeLimit(limit, defaultValue, maxValue int) int {
|
||
if limit <= 0 {
|
||
limit = defaultValue
|
||
}
|
||
if maxValue > 0 && limit > maxValue {
|
||
return maxValue
|
||
}
|
||
return limit
|
||
}
|
||
|
||
func strValue(v *string) string {
|
||
if v == nil {
|
||
return ""
|
||
}
|
||
return strings.TrimSpace(*v)
|
||
}
|
||
|
||
// fallbackContentHash 返回条目可用于服务级去重的内容哈希。
|
||
//
|
||
// 说明:
|
||
// 1. 优先复用库内已落表的 content_hash,避免同一条数据多套算法口径不一致;
|
||
// 2. 若历史数据或 RAG metadata 没带 hash,则按“类型 + 规范化内容”补算;
|
||
// 3. 若类型非法或正文为空,则返回空字符串,让上游继续走文本兜底去重。
|
||
func fallbackContentHash(memoryType, content, currentHash string) string {
|
||
currentHash = strings.TrimSpace(currentHash)
|
||
if currentHash != "" {
|
||
return currentHash
|
||
}
|
||
|
||
normalizedType := memorymodel.NormalizeMemoryType(memoryType)
|
||
normalizedContent := normalizeContentForHash(content)
|
||
if normalizedType == "" || normalizedContent == "" {
|
||
return ""
|
||
}
|
||
return memoryutils.HashContent(normalizedType, normalizedContent)
|
||
}
|
||
|
||
func normalizeContentForHash(content string) string {
|
||
content = strings.TrimSpace(content)
|
||
if content == "" {
|
||
return ""
|
||
}
|
||
return strings.ToLower(strings.Join(strings.Fields(content), " "))
|
||
}
|