后端: 1.粗排结果/预览语义修复(task_item suggested 保真 + existing/嵌入识别补全) - 更新conv/schedule_state.go:LoadScheduleState 补齐 event.rel_id / schedules.embedded_task_id / task_item.embedded_time 三种“已落位”信号;嵌入任务强制 existing + 继承 host slots;补充 task_item duration/name/slot helper;Diff 相关英文注释改中文 - 更新conv/schedule_preview.go:预览层新增 shouldMarkSuggestedInPreview,pending 任务与 source=task_item 的建议态任务统一输出 suggested 2.newAgent 状态快照增强(ScheduleState/OriginalScheduleState 跨轮恢复) - 更新model/state_store.go:AgentStateSnapshot 新增 ScheduleState / OriginalScheduleState - 更新model/graph_run_state.go:AgentGraphRunInput/AgentGraphState 接入两份 schedule 状态;恢复旧快照时自动补 original clone - 更新service/agentsvc/agent_newagent.go:loadOrCreateRuntimeState 返回并恢复 schedule/original;runNewAgentGraph 透传到 graph - 更新node/agent_nodes.go:saveAgentState 一并保存 schedule/original 到 Redis 快照 3.Execute 链路纠偏(只写内存不落库 + 完整打点 + 恢复消息去重) - 更新node/execute.go:AlwaysExecute/confirm resume 路径取消 PersistScheduleChanges,仅保留内存写;新增 execute LLM 完整上下文日志;新增工具调用前后 state 摘要日志;thinking 模式改为 enabled - 更新node/chat.go:pending resume 不再重复写入同一轮 user message - 更新service/agentsvc/agent_newagent.go:新增 deliver preview write/state 摘要日志,便于排查 suggested 丢失问题 4.AlwaysExecute 贯通 Plan→Graph→Execute - 更新node/plan.go:PlanNodeInput 新增 AlwaysExecute;plan_done 后支持自动确认直接进入执行 - 更新graph/common_graph.go:branchAfterPlan 支持 PhaseExecuting/PhaseDone 分支 5.排课上下文补强(显式注入 task_class_ids,减少 Execute 误 ask_user) - 更新prompt/execute.go:Plan/ReAct 两种 execute prompt 都显式写入任务类 ID,声明“上下文已完整,无需追问” - 更新node/rough_build.go:粗排完成 pinned block 显式标注任务类 ID,避免 Execute 找不到 ID 来源 6.流式输出与预览调试工具修复 - 更新stream/emitter.go:保留换行,修复 pseudo stream 分片后文本黏连/双换行问题 - 更新infra/schedule_preview_viewer.html:升级预览工具,支持 candidate_plans / hybrid_entries 前端:无 仓库: 1.更新了infra内的html,适应了获取日程接口
128 lines
3.3 KiB
Go
128 lines
3.3 KiB
Go
package conv
|
||
|
||
import (
|
||
"fmt"
|
||
"time"
|
||
|
||
"github.com/LoveLosita/smartflow/backend/model"
|
||
newagenttools "github.com/LoveLosita/smartflow/backend/newAgent/tools"
|
||
)
|
||
|
||
// ScheduleStateToPreview 将 newAgent 的 ScheduleState 转换为前端预览缓存格式。
|
||
//
|
||
// 职责边界:
|
||
// 1. 只做数据格式转换,不做业务逻辑;
|
||
// 2. 将每个 ScheduleTask 的每个 TaskSlot 转为一条 HybridScheduleEntry;
|
||
// 3. Day → (Week, DayOfWeek) 通过 ScheduleState.DayToWeekDay 转换;
|
||
// 4. 转换失败的 slot(day_index 无效)静默跳过。
|
||
func ScheduleStateToPreview(
|
||
state *newagenttools.ScheduleState,
|
||
userID int,
|
||
conversationID string,
|
||
taskClassIDs []int,
|
||
summary string,
|
||
) *model.SchedulePlanPreviewCache {
|
||
if state == nil {
|
||
return nil
|
||
}
|
||
|
||
entries := make([]model.HybridScheduleEntry, 0, len(state.Tasks))
|
||
for i := range state.Tasks {
|
||
t := &state.Tasks[i]
|
||
// 待安排且无位置的任务不生成 entry。
|
||
if t.Status == "pending" && len(t.Slots) == 0 {
|
||
continue
|
||
}
|
||
|
||
for _, slot := range t.Slots {
|
||
week, dayOfWeek, ok := state.DayToWeekDay(slot.Day)
|
||
if !ok {
|
||
continue
|
||
}
|
||
|
||
entry := model.HybridScheduleEntry{
|
||
Week: week,
|
||
DayOfWeek: dayOfWeek,
|
||
SectionFrom: slot.SlotStart,
|
||
SectionTo: slot.SlotEnd,
|
||
Name: t.Name,
|
||
}
|
||
|
||
// Type 映射。
|
||
if t.Source == "event" {
|
||
if t.EventType != "" {
|
||
entry.Type = t.EventType
|
||
} else {
|
||
entry.Type = "course"
|
||
}
|
||
} else {
|
||
entry.Type = "task"
|
||
}
|
||
|
||
// Status 映射:existing 不变,pending(有位置)= suggested。
|
||
if shouldMarkSuggestedInPreview(*t) {
|
||
entry.Status = "suggested"
|
||
} else {
|
||
entry.Status = "existing"
|
||
}
|
||
|
||
// ID 映射。
|
||
if t.Source == "event" {
|
||
entry.EventID = t.SourceID
|
||
} else {
|
||
entry.TaskItemID = t.SourceID
|
||
}
|
||
|
||
// 嵌入与阻塞语义。
|
||
entry.CanBeEmbedded = t.CanEmbed
|
||
if t.Source == "event" && t.CanEmbed && t.EmbeddedBy == nil {
|
||
// 可嵌入且当前无嵌入任务 → 不阻塞 suggested 占位。
|
||
entry.BlockForSuggested = false
|
||
} else {
|
||
entry.BlockForSuggested = true
|
||
}
|
||
|
||
entries = append(entries, entry)
|
||
}
|
||
}
|
||
|
||
// 生成摘要(若调用方未提供)。
|
||
if summary == "" {
|
||
existingCount := 0
|
||
suggestedCount := 0
|
||
for _, e := range entries {
|
||
if e.Status == "existing" {
|
||
existingCount++
|
||
} else {
|
||
suggestedCount++
|
||
}
|
||
}
|
||
summary = fmt.Sprintf("共 %d 个日程条目,其中已确定 %d 个,新安排 %d 个。", len(entries), existingCount, suggestedCount)
|
||
}
|
||
|
||
return &model.SchedulePlanPreviewCache{
|
||
UserID: userID,
|
||
ConversationID: conversationID,
|
||
Summary: summary,
|
||
HybridEntries: entries,
|
||
TaskClassIDs: taskClassIDs,
|
||
GeneratedAt: time.Now(),
|
||
}
|
||
}
|
||
|
||
// shouldMarkSuggestedInPreview 判断某条 ScheduleTask 在预览层是否应标记为 suggested。
|
||
//
|
||
// 规则说明:
|
||
// 1. pending 任务在预览语义中属于“建议态”;
|
||
// 2. source=task_item 且 Duration>0 的任务来自待排任务池,
|
||
// 即使工具层在 place 后把它改成 existing,预览层也要继续按 suggested 输出。
|
||
func shouldMarkSuggestedInPreview(t newagenttools.ScheduleTask) bool {
|
||
if t.Status == "pending" {
|
||
return true
|
||
}
|
||
if t.Source == "task_item" && t.Duration > 0 {
|
||
return true
|
||
}
|
||
return false
|
||
}
|