use std::collections::BTreeMap;
use std::sync::Arc;
use async_trait::async_trait;
use crate::context::ExecutionContext;
use crate::error::Result;
use crate::skills::resource::SkillResource;
#[async_trait]
pub trait Skill: Send + Sync + std::fmt::Debug {
fn name(&self) -> &str;
fn description(&self) -> &str;
fn version(&self) -> Option<&str> {
None
}
async fn load(&self, ctx: &ExecutionContext) -> Result<LoadedSkill>;
}
#[derive(Debug)]
pub struct LoadedSkill {
pub instructions: String,
pub resources: BTreeMap<String, Arc<dyn SkillResource>>,
}
impl LoadedSkill {
#[must_use]
pub fn new(instructions: impl Into<String>) -> Self {
Self {
instructions: instructions.into(),
resources: BTreeMap::new(),
}
}
#[must_use]
pub fn with_resource(
mut self,
key: impl Into<String>,
resource: Arc<dyn SkillResource>,
) -> Self {
self.resources.insert(key.into(), resource);
self
}
#[must_use]
pub fn resource_keys(&self) -> Vec<&str> {
self.resources.keys().map(String::as_str).collect()
}
}