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))), } }