1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! /save 命令实现
//!
//! 保存当前会话。
use super::super::backend_context::BackendContext;
use super::super::command_trait::Command;
/// Save 命令
///
/// 用法:
/// - /save - 保存当前会话
/// - /save <name> - 保存并重命名会话
pub struct Save;
impl Command for Save {
fn name(&self) -> &'static str {
"save"
}
fn help(&self) -> Option<&'static str> {
Some("保存当前会话。用法: /save [name]")
}
fn execute<'a>(
&'a self,
ctx: &'a mut BackendContext<'_>,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = bool> + Send + 'a>> {
Box::pin(async move {
let parts: Vec<&str> = ctx.message.split_whitespace().collect();
let name = parts.get(1).copied();
if let Some(mgr) = ctx.session_mgr {
let messages = ctx.agent.get_messages();
mgr.set_messages(messages.to_vec());
if let Some(n) = name {
if let Err(e) = mgr.rename_current(n) {
let _ = ctx
.event_tx
.send(crate::AgentEvent::error(
format!("Failed to rename: {}", e),
None,
None,
))
.await;
}
}
if let Err(e) = mgr.save_current() {
let _ = ctx
.event_tx
.send(crate::AgentEvent::error(
format!("Failed to save: {}", e),
None,
None,
))
.await;
} else {
let _ = ctx
.event_tx
.send(crate::AgentEvent::progress("✓ Session saved", None))
.await;
}
} else {
let _ = ctx
.event_tx
.send(crate::AgentEvent::progress(
"❌ Session manager not available",
None,
))
.await;
}
false // 不转发给 agent
})
}
}