feat(session): 添加 /? 帮助命令,错误命令显示友好提示
- 新增 /? 和 /help 命令显示所有可用斜杠命令 - 未知命令不再报错,而是提示"未知命令:/xxx。输入 /? 获取帮助。" - execute_slash_command 错误现在返回友好提示而非传播为服务器错误
This commit is contained in:
parent
e1681e0424
commit
5c558027fa
@ -28,6 +28,10 @@ mod tests {
|
|||||||
assert_eq!(parse_slash_command("/reset"), Some(("reset", "")));
|
assert_eq!(parse_slash_command("/reset"), Some(("reset", "")));
|
||||||
assert_eq!(parse_slash_command("/reset arg"), Some(("reset", "arg")));
|
assert_eq!(parse_slash_command("/reset arg"), Some(("reset", "arg")));
|
||||||
assert_eq!(parse_slash_command("/new hello world"), Some(("new", "hello world")));
|
assert_eq!(parse_slash_command("/new hello world"), Some(("new", "hello world")));
|
||||||
|
assert_eq!(parse_slash_command("/??"), Some(("??", "")));
|
||||||
|
assert_eq!(parse_slash_command("/? arg"), Some(("?", "arg")));
|
||||||
|
assert_eq!(parse_slash_command("/?"), Some(("?", "")));
|
||||||
|
assert_eq!(parse_slash_command("/help"), Some(("help", "")));
|
||||||
assert_eq!(parse_slash_command("hello"), None);
|
assert_eq!(parse_slash_command("hello"), None);
|
||||||
assert_eq!(parse_slash_command("/"), Some(("", "")));
|
assert_eq!(parse_slash_command("/"), Some(("", "")));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -637,6 +637,11 @@ pub static SLASH_COMMANDS: &[SlashCommand] = &[
|
|||||||
description: "保存当前对话为 markdown 文档",
|
description: "保存当前对话为 markdown 文档",
|
||||||
aliases: &["/dump"],
|
aliases: &["/dump"],
|
||||||
},
|
},
|
||||||
|
SlashCommand {
|
||||||
|
name: "?",
|
||||||
|
description: "显示帮助",
|
||||||
|
aliases: &["/?", "/help"],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
impl SessionManager {
|
impl SessionManager {
|
||||||
@ -820,7 +825,13 @@ impl SessionManager {
|
|||||||
Ok((None, "No active session.".to_string()))
|
Ok((None, "No active session.".to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(AgentError::Other(format!("Command not implemented: {}", cmd.name))),
|
"?" | "help" => {
|
||||||
|
let lines: Vec<String> = SLASH_COMMANDS.iter().map(|c| {
|
||||||
|
format!(" {} - {}", c.aliases.join(", "), c.description)
|
||||||
|
}).collect();
|
||||||
|
Ok((None, format!("可用命令:\n{}", lines.join("\n"))))
|
||||||
|
}
|
||||||
|
_ => Err(AgentError::Other(format!("未知命令:/{}。输入 /? 获取帮助。", cmd.name))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1092,15 +1103,22 @@ impl SessionManager {
|
|||||||
|
|
||||||
// Check for slash command
|
// Check for slash command
|
||||||
if let Some((cmd_name, cmd_args)) = parse_slash_command(content) {
|
if let Some((cmd_name, cmd_args)) = parse_slash_command(content) {
|
||||||
let (new_session_id, response) = self.execute_slash_command(
|
let result = self.execute_slash_command(
|
||||||
cmd_name,
|
cmd_name,
|
||||||
if cmd_args.is_empty() { None } else { Some(cmd_args) },
|
if cmd_args.is_empty() { None } else { Some(cmd_args) },
|
||||||
channel,
|
channel,
|
||||||
chat_id,
|
chat_id,
|
||||||
Some(&unified_id),
|
Some(&unified_id),
|
||||||
).await?;
|
).await;
|
||||||
|
|
||||||
return Ok(HandleResult::CommandOutput(response));
|
match result {
|
||||||
|
Ok((_new_session_id, response)) => {
|
||||||
|
return Ok(HandleResult::CommandOutput(response));
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
return Ok(HandleResult::CommandOutput(e.to_string()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normal message handling through LLM
|
// Normal message handling through LLM
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user