pub struct CapabilityRegistry { /* private fields */ }Expand description
Every capability, once, validated, in id order, with the lookups projections need.
Implementations§
Source§impl CapabilityRegistry
impl CapabilityRegistry
Sourcepub fn builder() -> Builder
pub fn builder() -> Builder
Start composing a registry.
use majordomus_cli::capability::{builtin, CapabilityRegistry, RegistryError};
let registry = CapabilityRegistry::builder().with_builtin(builtin::all()).build().unwrap();
assert!(registry.get("repository.info").is_some());
assert_eq!(registry.by_mcp_tool("majordomus_get").unwrap().id.as_str(), "objects.get");
// the same executables twice: every id is claimed twice, and the registry says so
let twice = CapabilityRegistry::builder().with_builtin(builtin::all()).with_builtin(builtin::all()).build();
let errors = twice.unwrap_err();
assert!(errors.iter().all(|e| matches!(e, RegistryError::DuplicateId { .. })));Sourcepub fn iter(&self) -> impl Iterator<Item = &Capability>
pub fn iter(&self) -> impl Iterator<Item = &Capability>
Every capability, by id.
Sourcepub fn modules(&self) -> impl Iterator<Item = &ModuleInfo>
pub fn modules(&self) -> impl Iterator<Item = &ModuleInfo>
Every module, by id: the composed ones, the derived ones, and one per declarative kind.
Sourcepub fn module(&self, id: &str) -> Option<&ModuleInfo>
pub fn module(&self, id: &str) -> Option<&ModuleInfo>
One module by id.
Sourcepub fn cases(&self, id: &str) -> Option<CaseProvider>
pub fn cases(&self, id: &str) -> Option<CaseProvider>
The benchmark case provider of an executable; None for a resource or an unknown id.
Sourcepub fn get(&self, id: &str) -> Option<&Capability>
pub fn get(&self, id: &str) -> Option<&Capability>
A capability by canonical id.
Sourcepub fn by_mcp_tool(&self, name: &str) -> Option<&Capability>
pub fn by_mcp_tool(&self, name: &str) -> Option<&Capability>
The capability an MCP tool name projects.
Sourcepub fn by_mcp_uri(&self, uri: &str) -> Option<(&Capability, &McpResource)>
pub fn by_mcp_uri(&self, uri: &str) -> Option<(&Capability, &McpResource)>
The capability an MCP resource URI projects, with the resource exposure it matched:
a declarative object, or a query read as a document (majordomus://repository).
use majordomus_cli::capability::{builtin, CapabilityKind, CapabilityRegistry};
let r = CapabilityRegistry::builder().with_builtin(builtin::all()).build().unwrap();
let (c, res) = r.by_mcp_uri(builtin::REPOSITORY_URI).unwrap();
assert_eq!((c.id.as_str(), c.kind, res.name.as_str()), ("repository.info", CapabilityKind::Query, "repository"));
assert!(r.by_mcp_uri("majordomus://rule/none@1").is_none());Sourcepub fn by_http(&self, method: HttpMethod, path: &str) -> Option<&Capability>
pub fn by_http(&self, method: HttpMethod, path: &str) -> Option<&Capability>
The capability an HTTP method and path project.
Sourcepub fn by_cli(&self, path: &[String]) -> Option<&Capability>
pub fn by_cli(&self, path: &[String]) -> Option<&Capability>
The capability a CLI path projects.
Sourcepub fn by_skill(&self, alias: &str) -> Option<&Capability>
pub fn by_skill(&self, alias: &str) -> Option<&Capability>
The capability a skill alias names, when one declares it.
use majordomus_cli::capability::{builtin, CapabilityRegistry};
let r = CapabilityRegistry::builder().with_builtin(builtin::all()).build().unwrap();
// `/intent <sentence>` is intents.propose, because its declaration says so
assert_eq!(r.by_skill("intent").map(|c| c.id.as_str()), Some("intents.propose"));
assert!(r.by_skill("no-such-alias").is_none());Sourcepub fn skills(&self) -> impl Iterator<Item = &Capability>
pub fn skills(&self) -> impl Iterator<Item = &Capability>
Every capability that declares a skill, by alias.
use majordomus_cli::capability::{builtin, CapabilityRegistry};
let r = CapabilityRegistry::builder().with_builtin(builtin::all()).build().unwrap();
let aliases: Vec<&str> =
r.skills().filter_map(|c| c.skill.as_ref()).map(|s| s.alias.as_str()).collect();
// few by design: a skill is for what a person types by name, not for every tool
assert!(aliases.contains(&"intent"));
let mut ordered = aliases.clone();
ordered.sort_unstable();
assert_eq!(aliases, ordered, "by alias");Sourcepub fn fingerprint(&self) -> &str
pub fn fingerprint(&self) -> &str
The fingerprint of this registry and the repository state it was built from.
Sourcepub fn dispatch(
&self,
ctx: &Context,
id: &str,
input: Value,
) -> Result<Value, CapabilityError>
pub fn dispatch( &self, ctx: &Context, id: &str, input: Value, ) -> Result<Value, CapabilityError>
Run the handler of an executable by id, with no counters and no cache: the raw
dispatch the executor wraps. Everything else calls Context::execute. A
resource, or an unknown id, is NotFound.