refactor: skill.rs → types.rs 重命名
类型定义重命名,消除过时的 'skill' 概念
This commit is contained in:
+5
-5
@@ -15,7 +15,7 @@ use db::Database;
|
|||||||
use llm::{Conversation, ConversationConfig, DEFAULT_SYSTEM_PROMPT, ToolExecutor, Usage};
|
use llm::{Conversation, ConversationConfig, DEFAULT_SYSTEM_PROMPT, ToolExecutor, Usage};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tools::approval::{ApprovalDecision, ApprovalManager};
|
use tools::approval::{ApprovalDecision, ApprovalManager};
|
||||||
use tools::skill::ExecutionContext;
|
use tools::types::ExecutionContext;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
use wechat::client::WeChatClient;
|
use wechat::client::WeChatClient;
|
||||||
|
|
||||||
@@ -293,7 +293,7 @@ async fn cmd_listen(
|
|||||||
let session = conv.session();
|
let session = conv.session();
|
||||||
let approval = approval_manager.clone();
|
let approval = approval_manager.clone();
|
||||||
let memory_store = memory_store.clone();
|
let memory_store = memory_store.clone();
|
||||||
let send_wechat: tools::skill::WechatSender = {
|
let send_wechat: tools::types::WechatSender = {
|
||||||
let client = client.clone();
|
let client = client.clone();
|
||||||
Arc::new(move |user_id: &str, text: &str| {
|
Arc::new(move |user_id: &str, text: &str| {
|
||||||
let client = client.clone();
|
let client = client.clone();
|
||||||
@@ -816,7 +816,7 @@ async fn cmd_send(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
use tools::skill::SkillResult;
|
use tools::types::SkillResult;
|
||||||
|
|
||||||
async fn builtin_approve(ctx: &ExecutionContext, name: &str) -> Result<bool, String> {
|
async fn builtin_approve(ctx: &ExecutionContext, name: &str) -> Result<bool, String> {
|
||||||
let manager = match ctx.approval_manager.as_ref() {
|
let manager = match ctx.approval_manager.as_ref() {
|
||||||
@@ -841,10 +841,10 @@ async fn builtin_approve(ctx: &ExecutionContext, name: &str) -> Result<bool, Str
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_capability_list(specs: &[tools::skill::SkillSpec]) -> String {
|
fn build_capability_list(specs: &[tools::types::SkillSpec]) -> String {
|
||||||
let mut lines = vec!["📋 可用工具:".to_string()];
|
let mut lines = vec!["📋 可用工具:".to_string()];
|
||||||
for spec in specs {
|
for spec in specs {
|
||||||
let risk = if spec.risk_level == tools::skill::RiskLevel::High {
|
let risk = if spec.risk_level == tools::types::RiskLevel::High {
|
||||||
" ⚠️需确认"
|
" ⚠️需确认"
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::tools::skill::{RiskLevel, SkillResult};
|
use crate::tools::types::{RiskLevel, SkillResult};
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
|
|
||||||
/// 内置工具执行器:统一处理参数校验、执行、错误返回
|
/// 内置工具执行器:统一处理参数校验、执行、错误返回
|
||||||
@@ -18,16 +18,16 @@ impl BuiltinRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 返回所有内置工具的 spec 列表
|
/// 返回所有内置工具的 spec 列表
|
||||||
pub fn specs() -> Vec<super::skill::SkillSpec> {
|
pub fn specs() -> Vec<super::types::SkillSpec> {
|
||||||
vec![
|
vec![
|
||||||
super::skill::SkillSpec {
|
super::types::SkillSpec {
|
||||||
name: "get_current_datetime".into(),
|
name: "get_current_datetime".into(),
|
||||||
description: "获取当前日期时间(北京时间 UTC+8)".into(),
|
description: "获取当前日期时间(北京时间 UTC+8)".into(),
|
||||||
risk_level: RiskLevel::Low,
|
risk_level: RiskLevel::Low,
|
||||||
parameters: serde_json::json!({"type":"object","properties":{"format":{"type":"string"}}}),
|
parameters: serde_json::json!({"type":"object","properties":{"format":{"type":"string"}}}),
|
||||||
timeout_secs: 5,
|
timeout_secs: 5,
|
||||||
},
|
},
|
||||||
super::skill::SkillSpec {
|
super::types::SkillSpec {
|
||||||
name: "manage_memos".into(),
|
name: "manage_memos".into(),
|
||||||
description: "管理备忘录:添加/列出/删除。高风险操作(add/delete)需确认".into(),
|
description: "管理备忘录:添加/列出/删除。高风险操作(add/delete)需确认".into(),
|
||||||
risk_level: RiskLevel::Low,
|
risk_level: RiskLevel::Low,
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
pub mod approval;
|
pub mod approval;
|
||||||
pub mod builtin;
|
pub mod builtin;
|
||||||
pub mod skill;
|
pub mod types;
|
||||||
pub mod weather;
|
pub mod weather;
|
||||||
|
|||||||
@@ -32,8 +32,12 @@ pub struct SkillSpec {
|
|||||||
pub timeout_secs: u64,
|
pub timeout_secs: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_risk_level() -> RiskLevel { RiskLevel::Low }
|
fn default_risk_level() -> RiskLevel {
|
||||||
fn default_timeout() -> u64 { 30 }
|
RiskLevel::Low
|
||||||
|
}
|
||||||
|
fn default_timeout() -> u64 {
|
||||||
|
30
|
||||||
|
}
|
||||||
|
|
||||||
// ─── 工具执行结果 ───
|
// ─── 工具执行结果 ───
|
||||||
|
|
||||||
@@ -47,29 +51,51 @@ pub struct SkillResult {
|
|||||||
|
|
||||||
impl SkillResult {
|
impl SkillResult {
|
||||||
pub fn ok(output: impl Into<String>) -> Self {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 struct ExecutionContext {
|
||||||
pub user_id: String,
|
pub user_id: String,
|
||||||
@@ -79,7 +105,11 @@ pub struct ExecutionContext {
|
|||||||
|
|
||||||
impl ExecutionContext {
|
impl ExecutionContext {
|
||||||
pub fn new(user_id: impl Into<String>) -> Self {
|
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 {
|
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::sync::Mutex;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use crate::tools::skill::{RiskLevel, SkillResult, SkillSpec};
|
use crate::tools::types::{RiskLevel, SkillResult, SkillSpec};
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════
|
// ═══════════════════════════════════════════════
|
||||||
// JWT 认证
|
// JWT 认证
|
||||||
|
|||||||
Reference in New Issue
Block a user