From 7fac68b51c9ed4bc26a91040e765b3f4109e3727 Mon Sep 17 00:00:00 2001 From: xiaoxixi Date: Tue, 28 Apr 2026 22:30:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(session):=20Phase=204=20-=20=E6=96=9C?= =?UTF-8?q?=E6=9D=A0=E5=91=BD=E4=BB=A4=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增命令: - /sessions — 列出 channel:chat_id 下最近 10 条对话 - /switch — 切换到指定对话 - /rename <新标题> — 重命名当前对话 更新命令: - /delete — 软删除后创建新对话 - /info — 显示 session_id + message_count 所有命令描述改为中文。 --- src/session/session.rs | 55 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/src/session/session.rs b/src/session/session.rs index 4da70a7..3a74d17 100644 --- a/src/session/session.rs +++ b/src/session/session.rs @@ -605,27 +605,42 @@ impl SlashCommand { pub static SLASH_COMMANDS: &[SlashCommand] = &[ SlashCommand { name: "new", - description: "Create a new conversation", + description: "创建新对话", aliases: &["/new"], }, + SlashCommand { + name: "sessions", + description: "列出最近对话", + aliases: &["/sessions"], + }, + SlashCommand { + name: "switch", + description: "切换到指定对话", + aliases: &["/switch"], + }, + SlashCommand { + name: "rename", + description: "重命名当前对话", + aliases: &["/rename"], + }, SlashCommand { name: "delete", - description: "Delete current conversation and start a new one", + description: "删除当前对话", aliases: &["/delete"], }, SlashCommand { name: "compact", - description: "Manually trigger context compression", + description: "手动触发上下文压缩", aliases: &["/compact"], }, SlashCommand { name: "info", - description: "Print current session information", + description: "显示当前对话信息", aliases: &["/info"], }, SlashCommand { name: "dump", - description: "Save current session as markdown document", + description: "保存当前对话为 markdown 文档", aliases: &["/dump"], }, ]; @@ -779,6 +794,36 @@ impl SessionManager { Ok((None, "No active session.".to_string())) } } + "sessions" => { + let (dialogs, _current) = self.list_dialogs(channel, chat_id, false).await?; + if dialogs.is_empty() { + Ok((None, "暂无对话记录。".to_string())) + } else { + let lines: Vec = dialogs.iter().map(|d| { + let current = if current_session_id.map(|s| s.dialog_id == d.session_id.dialog_id).unwrap_or(false) { + " [当前]" + } else { + "" + }; + format!("- {} ({}){} — {}", d.session_id.dialog_id, d.title, current, chrono::DateTime::from_timestamp_millis(d.last_active_at).map(|dt| dt.format("%m-%d %H:%M").to_string()).unwrap_or_default()) + }).collect(); + Ok((None, format!("最近对话:\n{}", lines.join("\n")))) + } + } + "switch" => { + let dialog_id = args.ok_or_else(|| AgentError::Other("Usage: /switch ".to_string()))?; + let new_id = self.switch_dialog(channel, chat_id, dialog_id).await?; + Ok((None, format!("已切换到对话:{}", new_id.dialog_id))) + } + "rename" => { + let title = args.ok_or_else(|| AgentError::Other("Usage: /rename <新标题>".to_string()))?; + if let Some(sid) = current_session_id { + self.rename_dialog(sid, title).await?; + Ok((None, format!("对话已重命名为:{}", title))) + } else { + Ok((None, "No active session.".to_string())) + } + } _ => Err(AgentError::Other(format!("Command not implemented: {}", cmd.name))), } }