Version: 0.9.39.dev.260423
后端: 1. 记忆系统移除 todo_hint 类型——随口记已由 Task 系统承接,todo_hint 语义重叠且无完成追踪 - 全链路清理:常量、校验、默认重要度、30 天 TTL、读取预算、LLM 抽取提示词枚举 - 总预算从四类收缩为三类(preference / constraint / fact) 2. 记忆抽取触发点从 chat-persist 移至 graph-completion——避免随口记消息被误提取为 constraint/preference - chat-persist consumer 不再自动入队 memory.extract.requested,仅负责聊天历史落库 - graph 完成后新增条件发布:检测 UsedQuickNote 标记,调用过 quick_note_create 则跳过记忆抽取 - ResetForNextRun 重置 UsedQuickNote,防止跨轮残留导致后续正常消息记忆抽取被误跳过 3. 任务类查询接口返回 items 补充数据库主键 ID(前端拖拽编排依赖此字段) 前端: 4. 排程视图新增手动编排模式——侧边栏任务块拖拽入周课表 + 悬浮删除热区 + 建议块虚线标识 - TaskClassSidebar 拖拽发起 + 预览态嵌入时间格式化(含周次/星期) - WeekPlanningBoard 外部拖入 / 内部移动 / 悬浮删除区交互 - ScheduleView 手动编排状态机(进入/退出/取消/覆盖确认)+ apply 时同步处理新增与删除
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// EventTypeChatHistoryPersistRequested 是“聊天消息持久化请求”的业务事件类型。
|
||||
// EventTypeChatHistoryPersistRequested 是"聊天消息持久化请求"的业务事件类型。
|
||||
//
|
||||
// 命名策略:
|
||||
// 1. 只描述业务语义,不包含 outbox/kafka 等实现词;
|
||||
@@ -22,12 +22,12 @@ const (
|
||||
EventTypeChatHistoryPersistRequested = "chat.history.persist.requested"
|
||||
)
|
||||
|
||||
// RegisterChatHistoryPersistHandler 注册“聊天消息持久化”消费者处理器。
|
||||
// RegisterChatHistoryPersistHandler 注册"聊天消息持久化"消费者处理器。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 只负责聊天事件,不处理其他业务事件;
|
||||
// 2. 只负责注册,不负责总线启停;
|
||||
// 3. 通过 outbox 通用事务入口把“业务写入 + consumed 推进”合并为一个事务;
|
||||
// 3. 通过 outbox 通用事务入口把"业务写入 + consumed 推进"合并为一个事务;
|
||||
// 4. 当前版本仅注册新路由键(chat.history.persist.requested),不再注册旧兼容键。
|
||||
func RegisterChatHistoryPersistHandler(
|
||||
bus *outboxinfra.EventBus,
|
||||
@@ -44,7 +44,6 @@ func RegisterChatHistoryPersistHandler(
|
||||
if repoManager == nil {
|
||||
return errors.New("repo manager is nil")
|
||||
}
|
||||
kafkaCfg := kafkabus.LoadConfig()
|
||||
|
||||
// 2. 定义统一处理器:
|
||||
// 2.1 解析 payload;
|
||||
@@ -58,12 +57,12 @@ func RegisterChatHistoryPersistHandler(
|
||||
return nil
|
||||
}
|
||||
|
||||
// 2.2 使用 outbox 通用消费事务,保证“业务写入 + consumed 状态推进”原子一致。
|
||||
// 2.2 使用 outbox 通用消费事务,保证"业务写入 + consumed 状态推进"原子一致。
|
||||
return outboxRepo.ConsumeAndMarkConsumed(ctx, envelope.OutboxID, func(tx *gorm.DB) error {
|
||||
// 2.2.1 基于同一个 tx 构造 RepoManager,复用你现有跨包事务模型。
|
||||
txM := repoManager.WithTx(tx)
|
||||
// 2.2.2 在同事务内写入聊天历史与会话计数。
|
||||
if err := txM.Agent.SaveChatHistoryInTx(
|
||||
return txM.Agent.SaveChatHistoryInTx(
|
||||
ctx,
|
||||
payload.UserID,
|
||||
payload.ConversationID,
|
||||
@@ -72,19 +71,6 @@ func RegisterChatHistoryPersistHandler(
|
||||
payload.ReasoningContent,
|
||||
payload.ReasoningDurationSeconds,
|
||||
payload.TokensConsumed,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 2.2.3 Day1 追加“记忆抽取请求”事件入队:
|
||||
// 1) 仅对 user 消息投递,避免把助手回复重复喂给抽取链路;
|
||||
// 2) 与聊天落库放在同一事务,保证“消息存在 -> 事件一定可追踪”;
|
||||
// 3) 若入队失败,整体回滚并触发 outbox 重试,不留半成功状态。
|
||||
return EnqueueMemoryExtractRequestedInTx(
|
||||
ctx,
|
||||
outboxRepo.WithTx(tx),
|
||||
kafkaCfg,
|
||||
payload,
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -97,7 +83,7 @@ func RegisterChatHistoryPersistHandler(
|
||||
return nil
|
||||
}
|
||||
|
||||
// PublishChatHistoryPersistRequested 发布“聊天消息持久化请求”事件。
|
||||
// PublishChatHistoryPersistRequested 发布"聊天消息持久化请求"事件。
|
||||
//
|
||||
// 设计目的:
|
||||
// 1. 让业务层只传 DTO,不重复拼事件元数据;
|
||||
|
||||
@@ -125,6 +125,51 @@ func EnqueueMemoryExtractRequestedInTx(
|
||||
return err
|
||||
}
|
||||
|
||||
// PublishMemoryExtractFromGraph 在 graph 完成后直接发布记忆抽取事件。
|
||||
//
|
||||
// 设计目的:
|
||||
// 1. 绕过 chat-persist 链路,由 agent service 在 graph 完成后按需调用;
|
||||
// 2. 内部完成 source text 截断、幂等 key 生成、memory 开关检查;
|
||||
// 3. 发布失败只记日志,不阻断主链路。
|
||||
func PublishMemoryExtractFromGraph(
|
||||
ctx context.Context,
|
||||
publisher outboxinfra.EventPublisher,
|
||||
userID int,
|
||||
conversationID string,
|
||||
sourceText string,
|
||||
) error {
|
||||
if !isMemoryWriteEnabled() {
|
||||
return nil
|
||||
}
|
||||
if publisher == nil {
|
||||
return errors.New("event publisher is nil")
|
||||
}
|
||||
|
||||
sourceText = strings.TrimSpace(sourceText)
|
||||
if sourceText == "" || userID <= 0 || strings.TrimSpace(conversationID) == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
truncated := truncateByRune(sourceText, maxMemorySourceTextLength)
|
||||
now := time.Now()
|
||||
payload := model.MemoryExtractRequestedPayload{
|
||||
UserID: userID,
|
||||
ConversationID: strings.TrimSpace(conversationID),
|
||||
SourceRole: "user",
|
||||
SourceText: truncated,
|
||||
OccurredAt: now,
|
||||
IdempotencyKey: buildMemoryExtractIdempotencyKey(userID, conversationID, truncated),
|
||||
}
|
||||
|
||||
return publisher.Publish(ctx, outboxinfra.PublishRequest{
|
||||
EventType: EventTypeMemoryExtractRequested,
|
||||
EventVersion: outboxinfra.DefaultEventVersion,
|
||||
MessageKey: payload.ConversationID,
|
||||
AggregateID: payload.ConversationID,
|
||||
Payload: payload,
|
||||
})
|
||||
}
|
||||
|
||||
func buildMemoryExtractPayloadFromChat(chatPayload model.ChatHistoryPersistPayload) (model.MemoryExtractRequestedPayload, bool) {
|
||||
role := strings.ToLower(strings.TrimSpace(chatPayload.Role))
|
||||
if role != "user" {
|
||||
|
||||
Reference in New Issue
Block a user