matrixcode_core/command/handlers/
load.rs1use super::super::backend_context::BackendContext;
6use super::super::command_trait::Command;
7
8pub struct Load;
13
14impl Command for Load {
15 fn name(&self) -> &'static str {
16 "load"
17 }
18
19 fn help(&self) -> Option<&'static str> {
20 Some("加载指定会话。用法: /load <session_id>")
21 }
22
23 fn execute<'a>(
24 &'a self,
25 ctx: &'a mut BackendContext<'_>,
26 ) -> std::pin::Pin<Box<dyn std::future::Future<Output = bool> + Send + 'a>> {
27 Box::pin(async move {
28 let session_id = ctx.message.strip_prefix("/load ").unwrap_or("");
29
30 if let Some(mgr) = ctx.session_mgr {
31 if mgr.resume(session_id).is_ok() {
32 if let Some(msgs) = mgr.messages() {
33 let messages = msgs.to_vec();
34 ctx.agent.set_messages(messages.clone());
35 let _ = ctx
36 .event_tx
37 .send(crate::AgentEvent::progress(
38 format!(
39 "✓ Session '{}' loaded ({} messages)",
40 session_id,
41 messages.len()
42 ),
43 None,
44 ))
45 .await;
46 }
47 } else {
48 let _ = ctx
49 .event_tx
50 .send(crate::AgentEvent::progress(
51 format!("❌ Session '{}' not found", session_id),
52 None,
53 ))
54 .await;
55 }
56 } else {
57 let _ = ctx
58 .event_tx
59 .send(crate::AgentEvent::progress(
60 "❌ Session manager not available",
61 None,
62 ))
63 .await;
64 }
65
66 false })
68 }
69}