Compare commits

..

No commits in common. "18ad891a51891ac2abb10a0e0d4628c67bc6ac4a" and "edc975e6d013fc3fe777299f62f8c38e7a16ebca" have entirely different histories.

2 changed files with 4 additions and 46 deletions

View File

@ -27,8 +27,6 @@ use crate::command::handlers::switch_topic::SwitchTopicCommandHandler;
use crate::gateway::agent_prompt_provider::AgentPromptProvider; use crate::gateway::agent_prompt_provider::AgentPromptProvider;
use crate::protocol::{WsInbound, WsOutbound, MediaSummary, parse_inbound, serialize_outbound}; use crate::protocol::{WsInbound, WsOutbound, MediaSummary, parse_inbound, serialize_outbound};
use crate::skills::SkillPromptProvider; use crate::skills::SkillPromptProvider;
use crate::tools::task::repository::TaskRepository;
use crate::tools::task::types::TaskSessionState;
use axum::extract::State; use axum::extract::State;
use axum::extract::ws::{Message as WsMessage, WebSocket, WebSocketUpgrade}; use axum::extract::ws::{Message as WsMessage, WebSocket, WebSocketUpgrade};
use axum::response::Response; use axum::response::Response;
@ -484,7 +482,7 @@ async fn handle_inbound(
*current_topic_id = Some(topic_id.clone()); *current_topic_id = Some(topic_id.clone());
// 加载并发送该话题的历史消息 // 加载并发送该话题的历史消息
if let Err(e) = send_topic_history(&store, current_session_id, topic_id, sender, &state.task_repository).await { if let Err(e) = send_topic_history(&store, current_session_id, topic_id, sender).await {
tracing::warn!(error = %e, topic_id = %topic_id, "Failed to send topic history"); tracing::warn!(error = %e, topic_id = %topic_id, "Failed to send topic history");
} }
} }
@ -588,7 +586,7 @@ async fn handle_inbound(
if let Some(first_topic) = topics.first() { if let Some(first_topic) = topics.first() {
let topic_id = first_topic.topic_id.clone(); let topic_id = first_topic.topic_id.clone();
*current_topic_id = Some(topic_id.clone()); *current_topic_id = Some(topic_id.clone());
if let Err(e) = send_topic_history(&store, current_session_id, &topic_id, sender, &state.task_repository).await { if let Err(e) = send_topic_history(&store, current_session_id, &topic_id, sender).await {
tracing::warn!(error = %e, topic_id = %topic_id, "Failed to send initial topic history"); tracing::warn!(error = %e, topic_id = %topic_id, "Failed to send initial topic history");
} }
} }
@ -643,7 +641,6 @@ async fn send_topic_history(
session_id: &str, session_id: &str,
topic_id: &str, topic_id: &str,
sender: &mpsc::Sender<WsOutbound>, sender: &mpsc::Sender<WsOutbound>,
task_repository: &Arc<dyn TaskRepository>,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
// 加载话题消息,按 session_id 过滤,避免混入子智能体消息 // 加载话题消息,按 session_id 过滤,避免混入子智能体消息
let messages = store.load_messages_for_topic(topic_id, Some(session_id))?; let messages = store.load_messages_for_topic(topic_id, Some(session_id))?;
@ -657,35 +654,6 @@ async fn send_topic_history(
} }
} }
// 查询该话题下所有运行中的子智能体任务,补发 TaskStarted 事件
// 解决页面刷新后 navigateToTaskId 丢失的问题
let running_tasks = match task_repository.list_tasks_for_topic(topic_id).await {
Ok(tasks) => tasks,
Err(e) => {
tracing::warn!(error = %e, topic_id = %topic_id, "Failed to list tasks for topic");
return Ok(());
}
};
for task in running_tasks {
if task.state == TaskSessionState::Running {
tracing::info!(
task_id = %task.id,
description = %task.description,
"Re-sending TaskStarted for running task after topic history load"
);
let _ = sender
.send(WsOutbound::TaskStarted {
task_id: task.id.clone(),
description: task.description.clone(),
subagent_type: task.subagent_type.clone(),
topic_id: Some(topic_id.to_string()),
parent_task_id: None,
})
.await;
}
}
Ok(()) Ok(())
} }

View File

@ -445,30 +445,20 @@ export function useChat(): UseChatReturn {
case 'task_started': { case 'task_started': {
const msg = message as TaskStarted const msg = message as TaskStarted
console.log('[useChat] task_started received:', { task_id: msg.task_id, topic_id: msg.topic_id, parent_task_id: msg.parent_task_id, selectedTopic: selectedTopicRef.current })
// 只 backfill 当前话题的 task tool_call避免跨话题串扰 // 只 backfill 当前话题的 task tool_call避免跨话题串扰
if (msg.topic_id && msg.topic_id !== selectedTopicRef.current) { if (msg.topic_id && msg.topic_id !== selectedTopicRef.current) break
console.log('[useChat] task_started filtered by topic_id')
break
}
// 孙智能体的 TaskStarted 不应 backfill 到主视图 // 孙智能体的 TaskStarted 不应 backfill 到主视图
if (msg.parent_task_id) { if (msg.parent_task_id) break
console.log('[useChat] task_started filtered by parent_task_id')
break
}
// 设置 navigateToTaskId让用户可以点击查看实时进度 // 设置 navigateToTaskId让用户可以点击查看实时进度
setMessages((prev) => { setMessages((prev) => {
console.log('[useChat] task_started searching messages for task tool_call, total messages:', prev.length)
for (let i = prev.length - 1; i >= 0; i--) { for (let i = prev.length - 1; i >= 0; i--) {
if (prev[i].type === 'tool_call' && prev[i].toolName === 'task' && !prev[i].navigateToTaskId) { if (prev[i].type === 'tool_call' && prev[i].toolName === 'task' && !prev[i].navigateToTaskId) {
console.log('[useChat] task_started SET navigateToTaskId at index', i, 'task_id:', msg.task_id)
const updated = [...prev] const updated = [...prev]
updated[i] = { ...updated[i], navigateToTaskId: msg.task_id } updated[i] = { ...updated[i], navigateToTaskId: msg.task_id }
return updated return updated
} }
} }
console.log('[useChat] task_started NO matching task tool_call found in messages')
return prev return prev
}) })
break break