- Added topic management capabilities, allowing users to create, switch, and query topics within sessions. - Updated command structure to include new commands: SwitchSession and GetCurrentSession. - Introduced TopicRecord for managing topic data in the storage layer. - Modified session handlers to accommodate topic operations, including listing and loading topics. - Enhanced database schema to support topics, including new tables and relationships. - Updated input adapters to recognize new commands and handle topic-related actions. - Improved logging for session and topic operations to aid in debugging and monitoring.
104 lines
2.7 KiB
Rust
104 lines
2.7 KiB
Rust
use std::collections::HashMap;
|
||
use uuid::Uuid;
|
||
|
||
/// 命令执行上下文 - 携带执行所需信息
|
||
#[derive(Debug, Clone)]
|
||
pub struct CommandContext {
|
||
/// 唯一请求ID
|
||
pub request_id: Uuid,
|
||
/// 当前会话ID
|
||
pub session_id: Option<String>,
|
||
/// 当前话题ID
|
||
pub topic_id: Option<String>,
|
||
/// 当前聊天ID
|
||
pub chat_id: Option<String>,
|
||
/// 发送者ID
|
||
pub sender_id: String,
|
||
/// 通道名称(如 "cli", "feishu", "wechat")
|
||
pub channel_name: String,
|
||
/// 额外元数据
|
||
pub metadata: HashMap<String, String>,
|
||
}
|
||
|
||
impl CommandContext {
|
||
/// 创建新的命令上下文
|
||
pub fn new(sender_id: impl Into<String>, channel_name: impl Into<String>) -> 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<String>) -> Self {
|
||
self.session_id = Some(session_id.into());
|
||
self
|
||
}
|
||
|
||
/// 设置话题ID
|
||
pub fn with_topic_id(mut self, topic_id: impl Into<String>) -> Self {
|
||
self.topic_id = Some(topic_id.into());
|
||
self
|
||
}
|
||
|
||
/// 设置聊天ID
|
||
pub fn with_chat_id(mut self, chat_id: impl Into<String>) -> Self {
|
||
self.chat_id = Some(chat_id.into());
|
||
self
|
||
}
|
||
|
||
/// 添加元数据
|
||
pub fn with_metadata(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
|
||
self.metadata.insert(key.into(), value.into());
|
||
self
|
||
}
|
||
}
|
||
|
||
/// 适配器上下文 - 用于输入解析
|
||
#[derive(Debug, Clone)]
|
||
pub struct AdapterContext {
|
||
/// 当前会话ID
|
||
pub session_id: Option<String>,
|
||
/// 当前话题ID
|
||
pub topic_id: Option<String>,
|
||
/// 当前聊天ID
|
||
pub chat_id: Option<String>,
|
||
/// 发送者ID
|
||
pub sender_id: String,
|
||
}
|
||
|
||
impl AdapterContext {
|
||
/// 创建新的适配器上下文
|
||
pub fn new(sender_id: impl Into<String>) -> 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<String>) -> Self {
|
||
self.session_id = Some(session_id.into());
|
||
self
|
||
}
|
||
|
||
/// 设置话题ID
|
||
pub fn with_topic_id(mut self, topic_id: impl Into<String>) -> Self {
|
||
self.topic_id = Some(topic_id.into());
|
||
self
|
||
}
|
||
|
||
/// 设置聊天ID
|
||
pub fn with_chat_id(mut self, chat_id: impl Into<String>) -> Self {
|
||
self.chat_id = Some(chat_id.into());
|
||
self
|
||
}
|
||
}
|