feat: 优化话题管理,确保在加载新话题历史前正确设置当前话题
This commit is contained in:
parent
a2d4ed9193
commit
549bf4df04
@ -184,6 +184,9 @@ impl Session {
|
||||
// 清除当前历史
|
||||
self.history.remove_history(chat_id);
|
||||
|
||||
// 先设置当前话题(set_history 需要这个)
|
||||
self.history.set_chat_topic(chat_id, topic_id.to_string());
|
||||
|
||||
// 加载新话题的历史
|
||||
let messages = self
|
||||
.store
|
||||
@ -191,7 +194,6 @@ impl Session {
|
||||
.map_err(|e| AgentError::Other(format!("load topic messages error: {}", e)))?;
|
||||
|
||||
self.history.set_history(chat_id, messages);
|
||||
self.history.set_chat_topic(chat_id, topic_id.to_string());
|
||||
|
||||
tracing::info!(
|
||||
topic_id = %topic_id,
|
||||
|
||||
@ -243,10 +243,13 @@ async fn handle_inbound(
|
||||
current_topic_id = ?current_topic_id,
|
||||
"Building CommandContext for WebSocket command"
|
||||
);
|
||||
let cmd_ctx = CommandContext::new("websocket", "cli")
|
||||
let mut cmd_ctx = CommandContext::new("websocket", "cli")
|
||||
.with_session_id(current_session_id.as_str())
|
||||
.with_chat_id(current_session_id.as_str())
|
||||
.with_topic_id(current_topic_id.as_deref().unwrap_or(""));
|
||||
.with_chat_id(current_session_id.as_str());
|
||||
// 只在有 topic_id 时才设置
|
||||
if let Some(ref topic_id) = *current_topic_id {
|
||||
cmd_ctx = cmd_ctx.with_topic_id(topic_id.as_str());
|
||||
}
|
||||
|
||||
// 执行命令
|
||||
let response = router.dispatch_with_response(cmd, cmd_ctx).await;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user