use std::collections::HashMap; use uuid::Uuid; /// 命令执行上下文 - 携带执行所需信息 #[derive(Debug, Clone)] pub struct CommandContext { /// 唯一请求ID pub request_id: Uuid, /// 当前会话ID pub session_id: Option, /// 当前话题ID pub topic_id: Option, /// 当前聊天ID pub chat_id: Option, /// 发送者ID pub sender_id: String, /// 通道名称(如 "cli", "feishu", "wechat") pub channel_name: String, /// 额外元数据 pub metadata: HashMap, } impl CommandContext { /// 创建新的命令上下文 pub fn new(sender_id: impl Into, channel_name: impl Into) -> Self { Self { request_id: Uuid::new_v4(), session_id: None, topic_id: None, chat_id: None, sender_id: sender_id.into(), channel_name: channel_name.into(), metadata: HashMap::new(), } } /// 设置会话ID pub fn with_session_id(mut self, session_id: impl Into) -> Self { self.session_id = Some(session_id.into()); self } /// 设置话题ID pub fn with_topic_id(mut self, topic_id: impl Into) -> Self { self.topic_id = Some(topic_id.into()); self } /// 设置聊天ID pub fn with_chat_id(mut self, chat_id: impl Into) -> Self { self.chat_id = Some(chat_id.into()); self } /// 添加元数据 pub fn with_metadata(mut self, key: impl Into, value: impl Into) -> Self { self.metadata.insert(key.into(), value.into()); self } } /// 适配器上下文 - 用于输入解析 #[derive(Debug, Clone)] pub struct AdapterContext { /// 当前会话ID pub session_id: Option, /// 当前话题ID pub topic_id: Option, /// 当前聊天ID pub chat_id: Option, /// 发送者ID pub sender_id: String, } impl AdapterContext { /// 创建新的适配器上下文 pub fn new(sender_id: impl Into) -> Self { Self { session_id: None, topic_id: None, chat_id: None, sender_id: sender_id.into(), } } /// 设置会话ID pub fn with_session_id(mut self, session_id: impl Into) -> Self { self.session_id = Some(session_id.into()); self } /// 设置话题ID pub fn with_topic_id(mut self, topic_id: impl Into) -> Self { self.topic_id = Some(topic_id.into()); self } /// 设置聊天ID pub fn with_chat_id(mut self, chat_id: impl Into) -> Self { self.chat_id = Some(chat_id.into()); self } }