- 新增 LoadTopic 命令处理器,替代 LoadSession - 新增 SwitchTopic 命令处理器,替代 SwitchSession - 删除 LoadSession 和 SwitchSession 处理器 - 更新 Command 枚举:LoadSession -> LoadTopic, SwitchSession -> SwitchTopic - 同步更新前端协议类型定义 - 调整适配器和网关代码以适应新命令 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
145 lines
4.1 KiB
Rust
145 lines
4.1 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::SaveTopic {
|
|
filepath: None,
|
|
include_subagents: false,
|
|
}));
|
|
}
|
|
|
|
if let Some(args) = trimmed.strip_prefix("/save ") {
|
|
let args = args.trim();
|
|
let parts: Vec<&str> = args.split_whitespace().collect();
|
|
|
|
// 解析参数
|
|
let mut include_subagents = false;
|
|
let mut filepath = None;
|
|
|
|
for part in parts {
|
|
if part == "+sub" {
|
|
include_subagents = true;
|
|
} else if !part.is_empty() {
|
|
// 非特殊参数视为文件路径
|
|
filepath = Some(part.to_string());
|
|
}
|
|
}
|
|
|
|
return Ok(Some(Command::SaveTopic {
|
|
filepath,
|
|
include_subagents,
|
|
}));
|
|
}
|
|
|
|
// 解析 /save-session 命令 - 保存整个会话
|
|
if trimmed == "/save-session" {
|
|
return Ok(Some(Command::SaveSession {
|
|
filepath: None,
|
|
include_all: false,
|
|
include_subagents: false,
|
|
}));
|
|
}
|
|
|
|
if let Some(args) = trimmed.strip_prefix("/save-session ") {
|
|
let args = args.trim();
|
|
let parts: Vec<&str> = args.split_whitespace().collect();
|
|
|
|
// 解析参数
|
|
let mut include_all = false;
|
|
let mut include_subagents = false;
|
|
let mut filepath = None;
|
|
|
|
for part in parts {
|
|
if part == "all" {
|
|
include_all = true;
|
|
} else if part == "+sub" {
|
|
include_subagents = true;
|
|
} else if !part.is_empty() {
|
|
// 非特殊参数视为文件路径
|
|
filepath = Some(part.to_string());
|
|
}
|
|
}
|
|
|
|
return Ok(Some(Command::SaveSession {
|
|
filepath,
|
|
include_all,
|
|
include_subagents,
|
|
}));
|
|
}
|
|
|
|
// 解析 /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 命令 - 切换话题(支持 topic_id 或序号)
|
|
if let Some(topic_id) = trimmed.strip_prefix("/use ") {
|
|
let topic_id = topic_id.trim();
|
|
return Ok(Some(Command::SwitchTopic {
|
|
topic_id: topic_id.to_string(),
|
|
}));
|
|
}
|
|
|
|
// 解析 /current 命令 - 获取当前会话信息
|
|
if trimmed == "/current" {
|
|
return Ok(Some(Command::GetCurrentSession));
|
|
}
|
|
|
|
// 解析 /help 命令 - 显示所有支持的命令
|
|
if trimmed == "/help" {
|
|
return Ok(Some(Command::Help));
|
|
}
|
|
|
|
// 不是命令,返回 None
|
|
Ok(None)
|
|
}
|
|
}
|