oudecheng 2e13f6932c feat: Enhance session management with topic support
- 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.
2026-05-15 15:01:58 +08:00

98 lines
2.9 KiB
Rust

use crate::command::adapter::{AdapterError, InputAdapter};
use crate::command::context::AdapterContext;
use crate::command::Command;
/// Channel 输入适配器
///
/// 将 Channel 消息中的文本命令(如 "/new", "/save")转换为 Command
pub struct ChannelInputAdapter;
impl ChannelInputAdapter {
/// 创建新的 Channel 输入适配器
pub fn new() -> Self {
Self
}
}
impl Default for ChannelInputAdapter {
fn default() -> Self {
Self::new()
}
}
impl InputAdapter for ChannelInputAdapter {
fn try_parse(
&self,
input: &str,
_ctx: AdapterContext,
) -> Result<Option<Command>, AdapterError> {
let trimmed = input.trim();
// 解析 /new 命令
if trimmed == "/new" {
return Ok(Some(Command::CreateSession { title: None }));
}
if let Some(title) = trimmed.strip_prefix("/new ") {
let title = title.trim();
return Ok(Some(Command::CreateSession {
title: Some(title.to_string()),
}));
}
// 解析 /save 命令
if trimmed == "/save" {
return Ok(Some(Command::SaveSession {
filepath: None,
include_all: false,
}));
}
if let Some(args) = trimmed.strip_prefix("/save ") {
let args = args.trim();
// 解析参数:可能是 "all"、路径、或 "all 路径"
let (include_all, filepath) = if args == "all" {
// /save all - 保存全部消息
(true, None)
} else if args.starts_with("all ") {
// /save all <filepath> - 保存全部消息到指定路径
let path = args[4..].trim();
(true, Some(path.to_string()))
} else {
// /save <filepath> - 保存活跃消息到指定路径
(false, Some(args.to_string()))
};
return Ok(Some(Command::SaveSession { filepath, include_all }));
}
// 解析 /list 命令
if trimmed == "/list" {
return Ok(Some(Command::ListSessions {
include_archived: false,
}));
}
if trimmed == "/list all" {
return Ok(Some(Command::ListSessions {
include_archived: true,
}));
}
// 解析 /use 命令 - 切换会话(支持 session_id 或序号)
if let Some(session_id) = trimmed.strip_prefix("/use ") {
let session_id = session_id.trim();
return Ok(Some(Command::SwitchSession {
session_id: session_id.to_string(),
}));
}
// 解析 /current 命令 - 获取当前会话信息
if trimmed == "/current" {
return Ok(Some(Command::GetCurrentSession));
}
// 不是命令,返回 None
Ok(None)
}
}