Compare commits

..

No commits in common. "ec5ddf644a7b2ff70c3f633441cfb384cc417616" and "50d0b92336df0e5712d3616ca659e051bf1e715b" have entirely different histories.

4 changed files with 10 additions and 76 deletions

View File

@ -190,6 +190,12 @@ impl AgentExecutionService {
// 只有当是最新回合时才触发历史压缩 // 只有当是最新回合时才触发历史压缩
let should_schedule_compaction = is_current_turn; let should_schedule_compaction = is_current_turn;
// 拦截 todo_write 结果:持久化 + 前端推送(不受 is_current_turn 限制)
session.intercept_todo_write_results(
&request.result.emitted_messages,
request.chat_id,
);
Ok(FinalizedAgentResult { Ok(FinalizedAgentResult {
outbound_messages, outbound_messages,
should_schedule_compaction, should_schedule_compaction,

View File

@ -255,7 +255,6 @@ impl InboundProcessor {
inbound.channel.clone(), inbound.channel.clone(),
inbound.chat_id.clone(), inbound.chat_id.clone(),
emitter_metadata, emitter_metadata,
self.session_manager.store(),
), ),
self.session_manager.store(), self.session_manager.store(),
&session_id, &session_id,

View File

@ -55,7 +55,6 @@ pub struct BusToolCallEmitter {
channel_name: String, channel_name: String,
chat_id: String, chat_id: String,
metadata: HashMap<String, String>, metadata: HashMap<String, String>,
store: Arc<SessionStore>,
} }
impl BusToolCallEmitter { impl BusToolCallEmitter {
@ -64,14 +63,12 @@ impl BusToolCallEmitter {
channel_name: impl Into<String>, channel_name: impl Into<String>,
chat_id: impl Into<String>, chat_id: impl Into<String>,
metadata: HashMap<String, String>, metadata: HashMap<String, String>,
store: Arc<SessionStore>,
) -> Self { ) -> Self {
Self { Self {
bus, bus,
channel_name: channel_name.into(), channel_name: channel_name.into(),
chat_id: chat_id.into(), chat_id: chat_id.into(),
metadata, metadata,
store,
} }
} }
} }
@ -110,63 +107,6 @@ impl EmittedMessageHandler for BusToolCallEmitter {
tracing::error!(error = %error, channel = %self.channel_name, chat_id = %self.chat_id, "Failed to publish live outbound tool call"); tracing::error!(error = %error, channel = %self.channel_name, chat_id = %self.chat_id, "Failed to publish live outbound tool call");
} }
} }
// 拦截 todo_write 结果:即时持久化到 SQLite
if message.tool_name.as_deref() == Some("todo_write") {
self.persist_todo_write_result(&message);
}
}
}
impl BusToolCallEmitter {
/// 从 todo_write 工具结果中提取 todos 并持久化
fn persist_todo_write_result(&self, message: &ChatMessage) {
let parsed: serde_json::Value = match serde_json::from_str(&message.content) {
Ok(v) => v,
Err(_) => return,
};
let Some(todos_array) = parsed.get("current_todos").and_then(|v| v.as_array()) else {
return;
};
let session_id = crate::storage::persistent_session_id(&self.channel_name, &self.chat_id);
// 优先用 topic_id与 list_todos handler 和 tool 内存状态保持一致)
let scope_key = self
.metadata
.get("topic_id")
.filter(|t| !t.is_empty())
.cloned()
.unwrap_or_else(|| session_id.clone());
let topic_id = self.metadata.get("topic_id").filter(|t| !t.is_empty()).cloned();
let records: Vec<crate::storage::TodoRecord> = todos_array
.iter()
.filter_map(|item| {
Some(crate::storage::TodoRecord {
id: item.get("id")?.as_str()?.to_string(),
scope_key: scope_key.clone(),
session_id: session_id.clone(),
topic_id: topic_id.clone(),
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()?,
})
})
.collect();
tracing::info!(
scope_key = %scope_key,
todo_count = records.len(),
"BusToolCallEmitter: persisting todo_write result"
);
if let Err(e) = self.store.replace_todos(&scope_key, &records) {
tracing::warn!(error = %e, %scope_key, "Failed to persist todo list from BusToolCallEmitter");
}
} }
} }
@ -1967,7 +1907,6 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn test_bus_tool_call_emitter_emits_completed_tool_results() { async fn test_bus_tool_call_emitter_emits_completed_tool_results() {
let store = Arc::new(SessionStore::in_memory().unwrap());
let bus = MessageBus::new(4); let bus = MessageBus::new(4);
let emitter = let emitter =
BusToolCallEmitter::new( BusToolCallEmitter::new(
@ -1975,7 +1914,6 @@ mod tests {
"test-channel", "test-channel",
"chat-1", "chat-1",
HashMap::new(), HashMap::new(),
store,
); );
emitter emitter

View File

@ -332,20 +332,11 @@ function App() {
const skillCmd = requestSkillList() const skillCmd = requestSkillList()
handleCommand(skillCmd) handleCommand(skillCmd)
sendMessage({ type: 'command', payload: JSON.stringify(skillCmd) }) sendMessage({ type: 'command', payload: JSON.stringify(skillCmd) })
}
}, [status, handleCommand, sendMessage, requestMemoryList, requestSkillList])
// 连接就绪、切换 topic、或进出子代理视图时刷新 todo 列表
const prevTodoTriggerRef = useRef<string>('')
useEffect(() => {
if (status !== 'connected') return
const key = `${selectedTopic ?? ''}|${subAgentView?.taskId ?? ''}`
if (key === prevTodoTriggerRef.current) return
prevTodoTriggerRef.current = key
const todoCmd = requestTodoList() const todoCmd = requestTodoList()
handleCommand(todoCmd) handleCommand(todoCmd)
sendMessage({ type: 'command', payload: JSON.stringify(todoCmd) }) sendMessage({ type: 'command', payload: JSON.stringify(todoCmd) })
}, [status, selectedTopic, subAgentView, handleCommand, sendMessage, requestTodoList]) }
}, [status, handleCommand, sendMessage, requestMemoryList, requestSkillList, requestTodoList])
const handleRefreshMemories = useCallback(() => { const handleRefreshMemories = useCallback(() => {
const cmd = requestMemoryList() const cmd = requestMemoryList()