1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//! # SZ-Rust Capability Registry
//!
//! 统一能力注册表,将 Skills(AI 内置能力)与 Plugins(业务插件)抽象为统一的 [`Capability`] 接口。
//!
//! ## 核心组件
//!
//! - [`Capability`] trait — 统一能力抽象(name/description/schema/tags/source/call)
//! - [`CapabilityRegistry`] — 中心注册表(注册/发现/调用)
//! - [`Cap`] facade — 静态 API(OnceLock 全局实例)
//! - [`CapabilitySource`] — 能力来源枚举(Skill/Plugin/Service)
//! - [`CapError`] — 错误类型(6 变体,non_exhaustive)
//! - [`McpCapabilityAdapter`] — MCP 工具适配为 Capability
//!
//! ## 快速开始
//!
//! ### 使用 facade(推荐)
//!
//! ```no_run
//! use std::sync::Arc;
//! use async_trait::async_trait;
//! use serde_json::{json, Value};
//! use sz_rust_capability::{Cap, Capability, CapabilitySource, CapError, CapResult};
//!
//! struct MyCapability;
//!
//! #[async_trait]
//! impl Capability for MyCapability {
//! fn name(&self) -> &'static str { "my.cap" }
//! fn description(&self) -> &'static str { "自定义能力" }
//! fn schema(&self) -> Value { json!({}) }
//! fn tags(&self) -> &[&'static str] { &["custom"] }
//! fn source(&self) -> CapabilitySource { CapabilitySource::Plugin }
//! async fn call(&self, args: Value) -> CapResult<Value> { Ok(args) }
//! }
//!
//! // 初始化 facade
//! Cap::init().ok();
//!
//! // 注册能力
//! Cap::register(Arc::new(MyCapability)).unwrap();
//!
//! // 发现能力
//! let caps = Cap::find_by_tags(&["custom"], None).unwrap();
//! assert_eq!(caps.len(), 1);
//! ```
//!
//! ### 使用 Registry 实例(多实例场景)
//!
//! ```
//! use std::sync::Arc;
//! use async_trait::async_trait;
//! use serde_json::{json, Value};
//! use sz_rust_capability::{Capability, CapabilityRegistry, CapabilitySource, CapResult};
//!
//! struct EchoCap;
//! #[async_trait]
//! impl Capability for EchoCap {
//! fn name(&self) -> &'static str { "echo" }
//! fn description(&self) -> &'static str { "回显" }
//! fn schema(&self) -> Value { json!({}) }
//! fn tags(&self) -> &[&'static str] { &["test"] }
//! fn source(&self) -> CapabilitySource { CapabilitySource::Skill }
//! async fn call(&self, args: Value) -> CapResult<Value> { Ok(args) }
//! }
//!
//! let registry = CapabilityRegistry::new();
//! registry.register(Arc::new(EchoCap));
//! assert_eq!(registry.len(), 1);
//! ```
//!
//! ### 注册 MCP 工具
//!
//! ```no_run
//! use sz_rust_capability::{CapabilityRegistry, register_mcp_tools};
//!
//! let registry = CapabilityRegistry::new();
//! let names = register_mcp_tools(®istry).unwrap();
//! assert_eq!(names.len(), 7); // 7 个 MCP 工具
//! ```
//!
//! ## 性能指标
//!
//! | 操作 | 延迟 | spec 要求 |
//! |------|------|-----------|
//! | 注册 | 187 ns | <1 ms |
//! | 查找 | 38 ns | <100 μs |
//! | 标签搜索(1000 能力) | 20 μs | <5 ms |
pub use ;
pub use ;
pub use ;
pub use Cap;
pub use CapMetrics;
pub use ;
pub use CapabilityRegistry;
pub use CapabilitySource;