feat: 优化会话列表消息格式,添加会话切换提示
This commit is contained in:
parent
e005d06a9b
commit
530bea518d
@ -71,10 +71,24 @@ async fn handle_list_sessions(
|
|||||||
let sessions_json =
|
let sessions_json =
|
||||||
serde_json::to_string(&summaries).map_err(|e| CommandError::new("SERIALIZE_ERROR", e.to_string()))?;
|
serde_json::to_string(&summaries).map_err(|e| CommandError::new("SERIALIZE_ERROR", e.to_string()))?;
|
||||||
|
|
||||||
|
// 构建可读的会话列表消息
|
||||||
let message = if summaries.is_empty() {
|
let message = if summaries.is_empty() {
|
||||||
"No sessions found.".to_string()
|
"No sessions found.".to_string()
|
||||||
} else {
|
} 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 <session_id> to switch to a session".to_string());
|
||||||
|
lines.join("\n")
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(CommandResponse::success(ctx.request_id)
|
Ok(CommandResponse::success(ctx.request_id)
|
||||||
|
|||||||
@ -10,6 +10,7 @@ use crate::command::handler::CommandRouter;
|
|||||||
use crate::command::handlers::save_session::SaveSessionCommandHandler;
|
use crate::command::handlers::save_session::SaveSessionCommandHandler;
|
||||||
use crate::command::handlers::session::SessionCommandHandler;
|
use crate::command::handlers::session::SessionCommandHandler;
|
||||||
use crate::command::handlers::session_query::SessionQueryCommandHandler;
|
use crate::command::handlers::session_query::SessionQueryCommandHandler;
|
||||||
|
use crate::command::Command;
|
||||||
use crate::config::LLMProviderConfig;
|
use crate::config::LLMProviderConfig;
|
||||||
use crate::gateway::agent_prompt_provider::AgentPromptProvider;
|
use crate::gateway::agent_prompt_provider::AgentPromptProvider;
|
||||||
use crate::skills::SkillPromptProvider;
|
use crate::skills::SkillPromptProvider;
|
||||||
@ -124,17 +125,32 @@ impl InboundProcessor {
|
|||||||
let cmd_ctx = crate::command::context::CommandContext::new(&inbound.channel, &inbound.channel)
|
let cmd_ctx = crate::command::context::CommandContext::new(&inbound.channel, &inbound.channel)
|
||||||
.with_session_id(&inbound.chat_id);
|
.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;
|
let response = self.command_router.dispatch_with_response(cmd, cmd_ctx).await;
|
||||||
|
|
||||||
// 发送响应给用户
|
// 发送响应给用户
|
||||||
if response.success {
|
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 {
|
for msg in &response.messages {
|
||||||
if let Err(error) = self
|
if let Err(error) = self
|
||||||
.bus
|
.bus
|
||||||
.publish_outbound(OutboundMessage::assistant(
|
.publish_outbound(OutboundMessage::assistant(
|
||||||
inbound.channel.clone(),
|
inbound.channel.clone(),
|
||||||
inbound.chat_id.clone(),
|
target_chat_id.clone(),
|
||||||
msg.content.clone(),
|
msg.content.clone(),
|
||||||
None,
|
None,
|
||||||
inbound.forwarded_metadata.clone(),
|
inbound.forwarded_metadata.clone(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user