fix: 5 项问题修复
1. (High) call_capability 路由内置工具 — 优先 BuiltinRegistry 2. (High) 内置 High 工具走审批 — builtin_approve 独立检查 3. (Medium) query_capabilities 去重 — 内置覆盖外部同名 4. (Medium) manage_memos 错误处理 — .ok() → 检查 Result 5. (Low) 重复 file_state — 删除第二个声明
This commit is contained in:
@@ -5,7 +5,6 @@ use chrono::Local;
|
||||
pub struct BuiltinRegistry;
|
||||
|
||||
impl BuiltinRegistry {
|
||||
/// 执行内置工具,返回 Some(SkillResult) 或 None(不是内置工具)
|
||||
pub async fn execute(name: &str, args_json: &str) -> Option<SkillResult> {
|
||||
match name {
|
||||
"get_current_datetime" => Some(execute_datetime()),
|
||||
@@ -33,6 +32,10 @@ impl BuiltinRegistry {
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
pub fn is_high_risk(name: &str) -> bool {
|
||||
Self::specs().iter().any(|s| s.name == name && s.risk_level == RiskLevel::High)
|
||||
}
|
||||
}
|
||||
|
||||
fn execute_datetime() -> SkillResult {
|
||||
@@ -44,7 +47,7 @@ async fn handle_memos(args_json: &str) -> SkillResult {
|
||||
let params: serde_json::Value = serde_json::from_str(args_json).unwrap_or_default();
|
||||
let action = params.get("action").and_then(|v| v.as_str()).unwrap_or("list");
|
||||
let path = ".data/memos.json";
|
||||
std::fs::create_dir_all(".data").ok();
|
||||
if let Err(e) = std::fs::create_dir_all(".data") { return SkillResult::error(format!("创建目录失败: {}", e)); }
|
||||
|
||||
let mut data: Vec<serde_json::Value> = if std::path::Path::new(path).exists() {
|
||||
serde_json::from_str(&std::fs::read_to_string(path).unwrap_or_default()).unwrap_or_default()
|
||||
|
||||
Reference in New Issue
Block a user