From 549bf4df0481005293dea0157e5a5fc60b0e0fc5 Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Fri, 15 May 2026 18:34:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=AF=9D=E9=A2=98?= =?UTF-8?q?=E7=AE=A1=E7=90=86=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=9C=A8=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=96=B0=E8=AF=9D=E9=A2=98=E5=8E=86=E5=8F=B2=E5=89=8D?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E8=AE=BE=E7=BD=AE=E5=BD=93=E5=89=8D=E8=AF=9D?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gateway/session.rs | 4 +++- src/gateway/ws.rs | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/gateway/session.rs b/src/gateway/session.rs index c7cf4c9..e454608 100644 --- a/src/gateway/session.rs +++ b/src/gateway/session.rs @@ -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, diff --git a/src/gateway/ws.rs b/src/gateway/ws.rs index 81c4a8c..3cb70be 100644 --- a/src/gateway/ws.rs +++ b/src/gateway/ws.rs @@ -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;