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;