use async_trait::async_trait;
use serde::Serialize;
use crate::error::CapResult;
use crate::source::CapabilitySource;
#[async_trait]
pub trait Capability: Send + Sync + 'static {
fn name(&self) -> &'static str;
fn description(&self) -> &'static str;
fn schema(&self) -> serde_json::Value;
fn tags(&self) -> &[&'static str];
fn source(&self) -> CapabilitySource;
async fn call(&self, args: serde_json::Value) -> CapResult<serde_json::Value>;
fn version(&self) -> &'static str {
"1.0.0"
}
fn requires_confirmation(&self) -> bool {
false
}
async fn validate_args(&self, args: &serde_json::Value) -> CapResult<()> {
crate::registry::validate_json_schema(&self.schema(), args)
}
}
#[derive(Debug, Clone, Serialize)]
pub struct CapabilityInfo {
pub name: &'static str,
pub description: &'static str,
pub tags: Vec<&'static str>,
pub source: CapabilitySource,
pub version: &'static str,
pub requires_confirmation: bool,
}
impl CapabilityInfo {
pub fn from_trait(cap: &dyn Capability) -> Self {
Self {
name: cap.name(),
description: cap.description(),
tags: cap.tags().to_vec(),
source: cap.source(),
version: cap.version(),
requires_confirmation: cap.requires_confirmation(),
}
}
}