Version: 0.8.3.dev.260328
后端: 1.彻底删除原agent文件夹,并将现agent2文件夹全量重命名为agent(包括全部涉及到的文件以及文档、注释),迁移工作完美结束 2.修复了重试消息的相关逻辑问题 前端: 1.改善了一些交互体验,修复了一些bug,现在只剩少的功能了,现存的bug基本都修复完毕 全仓库: 1.更新了决策记录和README文档
This commit is contained in:
@@ -235,6 +235,55 @@ func (a *AgentDAO) EnsureRetryGroupSeed(ctx context.Context, userID int, chatID,
|
||||
}).Error
|
||||
}
|
||||
|
||||
// ValidateRetrySourceMessages 校验重试父消息是否真实存在且角色匹配。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 负责校验 retry 请求引用的父 user/assistant 消息是否属于当前用户、当前会话。
|
||||
// 2. 负责校验两条父消息的角色语义,避免把占位 id、串号 id 或交换角色的 id 写进数据库。
|
||||
// 3. 不负责补种 retry_group_id;分组补种仍由 EnsureRetryGroupSeed 负责。
|
||||
func (a *AgentDAO) ValidateRetrySourceMessages(ctx context.Context, userID int, chatID string, sourceUserMessageID, sourceAssistantMessageID int) error {
|
||||
// 1. retry 是“基于既有一问一答重新生成”,因此两条父消息 id 必须同时有效。
|
||||
// 2. 只要任意一个缺失,就直接返回错误,禁止继续写出 index=1 的脏重试数据。
|
||||
if sourceUserMessageID <= 0 || sourceAssistantMessageID <= 0 {
|
||||
return errors.New("retry source message ids are invalid")
|
||||
}
|
||||
|
||||
type retrySourceRow struct {
|
||||
ID int
|
||||
Role *string
|
||||
}
|
||||
|
||||
ids := []int{sourceUserMessageID, sourceAssistantMessageID}
|
||||
rows := make([]retrySourceRow, 0, len(ids))
|
||||
if err := a.db.WithContext(ctx).
|
||||
Model(&model.ChatHistory{}).
|
||||
Select("id", "role").
|
||||
Where("user_id = ? AND chat_id = ? AND id IN ?", userID, chatID, ids).
|
||||
Find(&rows).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if len(rows) != len(ids) {
|
||||
return errors.New("retry source messages not found in current conversation")
|
||||
}
|
||||
|
||||
roleByID := make(map[int]string, len(rows))
|
||||
for _, row := range rows {
|
||||
if row.Role == nil {
|
||||
roleByID[row.ID] = ""
|
||||
continue
|
||||
}
|
||||
roleByID[row.ID] = strings.ToLower(strings.TrimSpace(*row.Role))
|
||||
}
|
||||
|
||||
if roleByID[sourceUserMessageID] != "user" {
|
||||
return errors.New("retry source user message is invalid")
|
||||
}
|
||||
if roleByID[sourceAssistantMessageID] != "assistant" {
|
||||
return errors.New("retry source assistant message is invalid")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *AgentDAO) GetRetryGroupNextIndex(ctx context.Context, userID int, chatID, retryGroupID string) (int, error) {
|
||||
normalizedGroupID := strings.TrimSpace(retryGroupID)
|
||||
if normalizedGroupID == "" {
|
||||
|
||||
Reference in New Issue
Block a user