diff --git a/src/command/handlers/session_query.rs b/src/command/handlers/session_query.rs index 3b05410..d63c88d 100644 --- a/src/command/handlers/session_query.rs +++ b/src/command/handlers/session_query.rs @@ -71,10 +71,24 @@ async fn handle_list_sessions( let sessions_json = serde_json::to_string(&summaries).map_err(|e| CommandError::new("SERIALIZE_ERROR", e.to_string()))?; + // 构建可读的会话列表消息 let message = if summaries.is_empty() { "No sessions found.".to_string() } else { - format!("Found {} session(s)", summaries.len()) + let mut lines = vec![format!("Found {} session(s):", summaries.len())]; + for summary in &summaries { + let archived_info = summary + .archived_at + .map(|_| " [archived]") + .unwrap_or(""); + lines.push(format!( + " - {}: {}{}", + summary.session_id, summary.title, archived_info + )); + } + lines.push("".to_string()); + lines.push("Use /use to switch to a session".to_string()); + lines.join("\n") }; Ok(CommandResponse::success(ctx.request_id) diff --git a/src/gateway/processor.rs b/src/gateway/processor.rs index 92ff1b9..b945977 100644 --- a/src/gateway/processor.rs +++ b/src/gateway/processor.rs @@ -10,6 +10,7 @@ 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; @@ -124,17 +125,32 @@ impl InboundProcessor { let cmd_ctx = crate::command::context::CommandContext::new(&inbound.channel, &inbound.channel) .with_session_id(&inbound.chat_id); + // 记录是否是创建会话命令(用于后续自动切换) + let is_create_session = matches!(cmd, Command::CreateSession { .. }); + let response = self.command_router.dispatch_with_response(cmd, cmd_ctx).await; // 发送响应给用户 if response.success { + // 如果是创建会话,更新 chat_id 到新会话 + let target_chat_id = if let Some(session_id) = response.metadata.get("session_id") { + if is_create_session { + // 自动切换到新会话 + session_id.clone() + } else { + inbound.chat_id.clone() + } + } else { + inbound.chat_id.clone() + }; + // 提取响应消息 for msg in &response.messages { if let Err(error) = self .bus .publish_outbound(OutboundMessage::assistant( inbound.channel.clone(), - inbound.chat_id.clone(), + target_chat_id.clone(), msg.content.clone(), None, inbound.forwarded_metadata.clone(),