refactor: skill.rs → types.rs 重命名
类型定义重命名,消除过时的 'skill' 概念
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::tools::skill::{RiskLevel, SkillResult};
|
||||
use crate::tools::types::{RiskLevel, SkillResult};
|
||||
use chrono::Local;
|
||||
|
||||
/// 内置工具执行器:统一处理参数校验、执行、错误返回
|
||||
@@ -18,16 +18,16 @@ impl BuiltinRegistry {
|
||||
}
|
||||
|
||||
/// 返回所有内置工具的 spec 列表
|
||||
pub fn specs() -> Vec<super::skill::SkillSpec> {
|
||||
pub fn specs() -> Vec<super::types::SkillSpec> {
|
||||
vec![
|
||||
super::skill::SkillSpec {
|
||||
super::types::SkillSpec {
|
||||
name: "get_current_datetime".into(),
|
||||
description: "获取当前日期时间(北京时间 UTC+8)".into(),
|
||||
risk_level: RiskLevel::Low,
|
||||
parameters: serde_json::json!({"type":"object","properties":{"format":{"type":"string"}}}),
|
||||
timeout_secs: 5,
|
||||
},
|
||||
super::skill::SkillSpec {
|
||||
super::types::SkillSpec {
|
||||
name: "manage_memos".into(),
|
||||
description: "管理备忘录:添加/列出/删除。高风险操作(add/delete)需确认".into(),
|
||||
risk_level: RiskLevel::Low,
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
pub mod approval;
|
||||
pub mod builtin;
|
||||
pub mod skill;
|
||||
pub mod types;
|
||||
pub mod weather;
|
||||
|
||||
@@ -32,8 +32,12 @@ pub struct SkillSpec {
|
||||
pub timeout_secs: u64,
|
||||
}
|
||||
|
||||
fn default_risk_level() -> RiskLevel { RiskLevel::Low }
|
||||
fn default_timeout() -> u64 { 30 }
|
||||
fn default_risk_level() -> RiskLevel {
|
||||
RiskLevel::Low
|
||||
}
|
||||
fn default_timeout() -> u64 {
|
||||
30
|
||||
}
|
||||
|
||||
// ─── 工具执行结果 ───
|
||||
|
||||
@@ -47,29 +51,51 @@ pub struct SkillResult {
|
||||
|
||||
impl SkillResult {
|
||||
pub fn ok(output: impl Into<String>) -> Self {
|
||||
Self { success: true, output: output.into(), data: None }
|
||||
Self {
|
||||
success: true,
|
||||
output: output.into(),
|
||||
data: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ok_with_data(output: impl Into<String>, data: serde_json::Value) -> Self {
|
||||
Self { success: true, output: output.into(), data: Some(data) }
|
||||
Self {
|
||||
success: true,
|
||||
output: output.into(),
|
||||
data: Some(data),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rejected(skill_name: &str) -> Self {
|
||||
Self { success: false, output: format!("用户拒绝了你的调用:{}", skill_name), data: None }
|
||||
Self {
|
||||
success: false,
|
||||
output: format!("用户拒绝了你的调用:{}", skill_name),
|
||||
data: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expired(skill_name: &str) -> Self {
|
||||
Self { success: false, output: format!("用户没有确认操作:{}", skill_name), data: None }
|
||||
Self {
|
||||
success: false,
|
||||
output: format!("用户没有确认操作:{}", skill_name),
|
||||
data: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn error(msg: impl Into<String>) -> Self {
|
||||
Self { success: false, output: msg.into(), data: None }
|
||||
Self {
|
||||
success: false,
|
||||
output: msg.into(),
|
||||
data: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ─── 执行上下文 ───
|
||||
|
||||
pub type WechatSender = Arc<dyn Fn(&str, &str) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send>> + Send + Sync>;
|
||||
pub type WechatSender = Arc<
|
||||
dyn Fn(&str, &str) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send>> + Send + Sync,
|
||||
>;
|
||||
|
||||
pub struct ExecutionContext {
|
||||
pub user_id: String,
|
||||
@@ -79,7 +105,11 @@ pub struct ExecutionContext {
|
||||
|
||||
impl ExecutionContext {
|
||||
pub fn new(user_id: impl Into<String>) -> Self {
|
||||
Self { user_id: user_id.into(), approval_manager: None, send_wechat: None }
|
||||
Self {
|
||||
user_id: user_id.into(),
|
||||
approval_manager: None,
|
||||
send_wechat: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_approval(mut self, mgr: Arc<crate::tools::approval::ApprovalManager>) -> Self {
|
||||
@@ -19,7 +19,7 @@ use std::collections::HashMap;
|
||||
use std::sync::Mutex;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use crate::tools::skill::{RiskLevel, SkillResult, SkillSpec};
|
||||
use crate::tools::types::{RiskLevel, SkillResult, SkillSpec};
|
||||
|
||||
// ═══════════════════════════════════════════════
|
||||
// JWT 认证
|
||||
|
||||
Reference in New Issue
Block a user