后端: 1. 旧 Agent 管线(agent/)全面下线,共享逻辑迁移至 newAgent/ - 删除 backend/agent/ 整个目录(44 个 Go 文件),5 条旧专用流程已由 newAgent 统一 graph 取代 - 共享逻辑迁入 newAgent/:clone(shared/clone.go)、时间解析(shared/deadline.go)、优先级常量(shared/task_priority.go)、TaskQuery 类型(model/taskquery_types.go)、SystemPrompt(prompt/system.go)、Usage 合并(stream/usage.go) 2. service 层清除 agent/ 全部依赖 - 删除 4 个旧流程入口文件(agent_route / agent_quick_note / agent_schedule_plan / agent_schedule_refine) - agent_task_query.go 删除 runTaskQueryFlow,参数类型切到 newagentmodel - agent.go / agent_newagent.go / agent_schedule_preview.go / agent_schedule_state.go / cmd/start.go / quicknote.go:agent* 引用全部替换为 newagent* 3. 流式降级回退路径内联到 service 层(agent_stream_fallback.go),消除最后一条 agent/chat 依赖 前端: 1. ScheduleFineTuneModal 幂等键追加 classId 后缀,修复多任务类并行保存 key 重复
158 lines
3.8 KiB
Go
158 lines
3.8 KiB
Go
package agentsvc
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"sort"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/LoveLosita/smartflow/backend/model"
|
|
newagentmodel "github.com/LoveLosita/smartflow/backend/newAgent/model"
|
|
"github.com/LoveLosita/smartflow/backend/respond"
|
|
)
|
|
|
|
func (s *AgentService) QueryTasksForTool(ctx context.Context, req newagentmodel.TaskQueryRequest) ([]newagentmodel.TaskQueryTaskRecord, error) {
|
|
_ = ctx
|
|
if req.UserID <= 0 {
|
|
return nil, errors.New("invalid user_id in task query")
|
|
}
|
|
if s.taskRepo == nil {
|
|
return nil, errors.New("task repository is nil")
|
|
}
|
|
|
|
tasks, err := s.taskRepo.GetTasksByUserID(req.UserID)
|
|
if err != nil {
|
|
if errors.Is(err, respond.UserTasksEmpty) {
|
|
return make([]newagentmodel.TaskQueryTaskRecord, 0), nil
|
|
}
|
|
return nil, err
|
|
}
|
|
|
|
now := time.Now()
|
|
filtered := make([]model.Task, 0, len(tasks))
|
|
for _, originalTask := range tasks {
|
|
currentTask := originalTask
|
|
applyReadTimeUrgencyPromotion(¤tTask, now)
|
|
if !taskMatchesQueryFilter(currentTask, req) {
|
|
continue
|
|
}
|
|
filtered = append(filtered, currentTask)
|
|
}
|
|
|
|
sortTasksForQuery(filtered, req)
|
|
if req.Limit > 0 && len(filtered) > req.Limit {
|
|
filtered = filtered[:req.Limit]
|
|
}
|
|
|
|
records := make([]newagentmodel.TaskQueryTaskRecord, 0, len(filtered))
|
|
for _, task := range filtered {
|
|
records = append(records, newagentmodel.TaskQueryTaskRecord{
|
|
ID: task.ID,
|
|
Title: task.Title,
|
|
PriorityGroup: task.Priority,
|
|
IsCompleted: task.IsCompleted,
|
|
DeadlineAt: task.DeadlineAt,
|
|
UrgencyThresholdAt: task.UrgencyThresholdAt,
|
|
})
|
|
}
|
|
return records, nil
|
|
}
|
|
|
|
func applyReadTimeUrgencyPromotion(task *model.Task, now time.Time) {
|
|
if task == nil || task.IsCompleted || task.UrgencyThresholdAt == nil {
|
|
return
|
|
}
|
|
if task.UrgencyThresholdAt.After(now) {
|
|
return
|
|
}
|
|
switch task.Priority {
|
|
case 2:
|
|
task.Priority = 1
|
|
case 4:
|
|
task.Priority = 3
|
|
}
|
|
}
|
|
|
|
func taskMatchesQueryFilter(task model.Task, req newagentmodel.TaskQueryRequest) bool {
|
|
if !req.IncludeCompleted && task.IsCompleted {
|
|
return false
|
|
}
|
|
if req.Quadrant != nil && task.Priority != *req.Quadrant {
|
|
return false
|
|
}
|
|
keyword := strings.TrimSpace(req.Keyword)
|
|
if keyword != "" && !strings.Contains(strings.ToLower(task.Title), strings.ToLower(keyword)) {
|
|
return false
|
|
}
|
|
if req.DeadlineAfter != nil {
|
|
if task.DeadlineAt == nil || task.DeadlineAt.Before(*req.DeadlineAfter) {
|
|
return false
|
|
}
|
|
}
|
|
if req.DeadlineBefore != nil {
|
|
if task.DeadlineAt == nil || task.DeadlineAt.After(*req.DeadlineBefore) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func sortTasksForQuery(tasks []model.Task, req newagentmodel.TaskQueryRequest) {
|
|
if len(tasks) <= 1 {
|
|
return
|
|
}
|
|
order := strings.ToLower(strings.TrimSpace(req.Order))
|
|
if order != "desc" {
|
|
order = "asc"
|
|
}
|
|
sortBy := strings.ToLower(strings.TrimSpace(req.SortBy))
|
|
if sortBy == "" {
|
|
sortBy = "deadline"
|
|
}
|
|
|
|
sort.SliceStable(tasks, func(i, j int) bool {
|
|
left := tasks[i]
|
|
right := tasks[j]
|
|
switch sortBy {
|
|
case "priority":
|
|
if left.Priority != right.Priority {
|
|
if order == "desc" {
|
|
return left.Priority > right.Priority
|
|
}
|
|
return left.Priority < right.Priority
|
|
}
|
|
return left.ID > right.ID
|
|
case "id":
|
|
if order == "desc" {
|
|
return left.ID > right.ID
|
|
}
|
|
return left.ID < right.ID
|
|
default:
|
|
if less, decided := compareDeadline(left.DeadlineAt, right.DeadlineAt, order); decided {
|
|
return less
|
|
}
|
|
return left.ID > right.ID
|
|
}
|
|
})
|
|
}
|
|
|
|
func compareDeadline(left, right *time.Time, order string) (less bool, decided bool) {
|
|
if left == nil && right == nil {
|
|
return false, false
|
|
}
|
|
if left == nil && right != nil {
|
|
return false, true
|
|
}
|
|
if left != nil && right == nil {
|
|
return true, true
|
|
}
|
|
if left.Equal(*right) {
|
|
return false, false
|
|
}
|
|
if order == "desc" {
|
|
return left.After(*right), true
|
|
}
|
|
return left.Before(*right), true
|
|
}
|