Skip to main content

matrixcode_core/command/handlers/
load.rs

1//! /load 命令实现
2//!
3//! 加载指定会话。
4
5use super::super::command_trait::Command;
6use super::super::backend_context::BackendContext;
7
8/// Load 命令
9///
10/// 用法:
11/// - /load <session_id> - 加载指定会话
12pub 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>(&'a self, ctx: &'a mut BackendContext<'_>) 
24        -> std::pin::Pin<Box<dyn std::future::Future<Output = bool> + Send + 'a>> 
25    {
26        Box::pin(async move {
27            let session_id = ctx.message.strip_prefix("/load ").unwrap_or("");
28
29            if let Some(mgr) = ctx.session_mgr {
30                if mgr.resume(session_id).is_ok() {
31                    if let Some(msgs) = mgr.messages() {
32                        let messages = msgs.to_vec();
33                        ctx.agent.set_messages(messages.clone());
34                        let _ = ctx.event_tx.send(crate::AgentEvent::progress(
35                            format!("✓ Session '{}' loaded ({} messages)", session_id, messages.len()),
36                            None,
37                        )).await;
38                    }
39                } else {
40                    let _ = ctx.event_tx.send(crate::AgentEvent::progress(
41                        format!("❌ Session '{}' not found", session_id), None
42                    )).await;
43                }
44            } else {
45                let _ = ctx.event_tx.send(crate::AgentEvent::progress(
46                    "❌ Session manager not available", None
47                )).await;
48            }
49
50            false // 不转发给 agent
51        })
52    }
53}