diff --git a/src/tools/task/runtime.rs b/src/tools/task/runtime.rs index e29d9fa..94fc4aa 100644 --- a/src/tools/task/runtime.rs +++ b/src/tools/task/runtime.rs @@ -211,9 +211,15 @@ impl SubAgentEmitter { let scope_key = &self.sub_session_id; + let now = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap_or_default() + .as_secs() as i64; + let records: Vec = todos_array .iter() - .filter_map(|item| { + .enumerate() + .filter_map(|(idx, item)| { Some(crate::storage::TodoRecord { id: item.get("id")?.as_str()?.to_string(), scope_key: scope_key.clone(), @@ -221,9 +227,9 @@ impl SubAgentEmitter { topic_id: None, content: item.get("content")?.as_str()?.to_string(), status: item.get("status")?.as_str()?.to_string(), - priority: item.get("priority")?.as_str()?.to_string(), - created_at: item.get("created_at")?.as_i64()?, - updated_at: item.get("updated_at")?.as_i64()?, + priority: "medium".to_string(), + created_at: now + idx as i64, + updated_at: now, }) }) .collect(); diff --git a/web/src/App.tsx b/web/src/App.tsx index 3eb0cea..ba420f9 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -49,6 +49,7 @@ function App() { skills, requestSkillList, todos, + setTodos, requestTodoList, requestSubAgentTodoList, // 定时任务 @@ -355,12 +356,13 @@ function App() { const key = `${selectedTopic ?? ''}|${subAgentView?.taskId ?? ''}` if (key === prevTodoTriggerRef.current) return prevTodoTriggerRef.current = key + setTodos([]) // 先清空,防止切换时短暂显示旧 scope 的 todos const todoCmd = subAgentView?.taskId ? requestSubAgentTodoList(subAgentView.taskId) : requestTodoList() handleCommand(todoCmd) sendMessage({ type: 'command', payload: JSON.stringify(todoCmd) }) - }, [status, selectedTopic, subAgentView, handleCommand, sendMessage, requestTodoList, requestSubAgentTodoList]) + }, [status, selectedTopic, subAgentView, handleCommand, sendMessage, requestTodoList, requestSubAgentTodoList, setTodos]) const handleRefreshMemories = useCallback(() => { const cmd = requestMemoryList() @@ -379,6 +381,13 @@ function App() { sendMessage({ type: 'command', payload: JSON.stringify(cmd) }) }, [handleCommand, sendMessage]) + // 根据当前视图(主会话/子代理)返回正确的 todo 请求命令 + const refreshTodoList = useCallback((): Command => { + return subAgentView?.taskId + ? requestSubAgentTodoList(subAgentView.taskId) + : requestTodoList() + }, [subAgentView, requestTodoList, requestSubAgentTodoList]) + const handleRefreshSchedulerJobs = useCallback(() => { const cmd = requestSchedulerJobList() handleCommand(cmd) @@ -719,7 +728,7 @@ function App() { {/* 悬浮 Todo 面板 */} diff --git a/web/src/hooks/useChat.ts b/web/src/hooks/useChat.ts index 7bc19a7..28063b8 100644 --- a/web/src/hooks/useChat.ts +++ b/web/src/hooks/useChat.ts @@ -1,4 +1,4 @@ -import { useState, useCallback, useEffect, useRef, useMemo } from 'react' +import { useState, useCallback, useEffect, useRef, useMemo, type Dispatch, type SetStateAction } from 'react' import type { Command, ChatMessage, @@ -98,6 +98,7 @@ interface UseChatReturn { // Todo 状态 todos: TodoItemSummary[] + setTodos: Dispatch> requestTodoList: () => Command requestSubAgentTodoList: (subTaskId: string) => Command @@ -957,6 +958,7 @@ export function useChat(): UseChatReturn { skills, requestSkillList, todos, + setTodos, requestTodoList, requestSubAgentTodoList, schedulerJobs,