From 8edc7ef9050949536cd8d154cf25934b489aef3d Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Fri, 15 May 2026 18:42:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E8=AF=9D=E9=A2=98=E8=8E=B7=E5=8F=96=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=91=BD=E4=BB=A4=E4=B8=8A=E4=B8=8B=E6=96=87?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gateway/processor.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/gateway/processor.rs b/src/gateway/processor.rs index e9f8b49..d6f9aed 100644 --- a/src/gateway/processor.rs +++ b/src/gateway/processor.rs @@ -10,7 +10,6 @@ use crate::command::handler::CommandRouter; use crate::command::handlers::save_session::SaveSessionCommandHandler; use crate::command::handlers::session::SessionCommandHandler; use crate::command::handlers::session_query::SessionQueryCommandHandler; -use crate::command::Command; use crate::config::LLMProviderConfig; use crate::gateway::agent_prompt_provider::AgentPromptProvider; use crate::skills::SkillPromptProvider; @@ -123,6 +122,14 @@ impl InboundProcessor { // 计算正确的 session_id(根据 channel_name 和 chat_id) let session_id = persistent_session_id(&inbound.channel, &inbound.chat_id); + // 获取当前话题(如果有 Session) + let current_topic = if let Some(session) = self.session_manager.get(&inbound.channel).await { + let guard = session.lock().await; + guard.current_topic(&inbound.chat_id).map(|s| s.to_string()) + } else { + None + }; + // 使用 ChannelInputAdapter 尝试解析命令 let adapter = ChannelInputAdapter::new(); let ctx = crate::command::context::AdapterContext::new(&inbound.channel) @@ -130,12 +137,13 @@ impl InboundProcessor { if let Ok(Some(cmd)) = adapter.try_parse(&inbound.content, ctx) { // 使用命令路由器处理 - let cmd_ctx = crate::command::context::CommandContext::new(&inbound.channel, &inbound.channel) + let mut cmd_ctx = crate::command::context::CommandContext::new(&inbound.channel, &inbound.channel) .with_session_id(&session_id) .with_chat_id(&inbound.chat_id); - - // 记录是否是创建会话命令(用于后续处理) - let _is_create_session = matches!(cmd, Command::CreateSession { .. }); + // 只在有话题时才设置 topic_id + if let Some(ref topic_id) = current_topic { + cmd_ctx = cmd_ctx.with_topic_id(topic_id.as_str()); + } let response = self.command_router.dispatch_with_response(cmd, cmd_ctx).await;