use std::fmt;
use std::sync::Arc;
use futures::future::BoxFuture;
use crate::tool::ToolRuntime;
pub const SKILL_PROVIDER: &str = "skills";
pub const LOAD_SKILL_TOOL: &str = "load_skill";
pub const READ_SKILL_FILE_TOOL: &str = "read_skill_file";
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SkillToolGrant {
pub skill: String,
pub provider: String,
pub tool: String,
pub ask: bool,
}
#[derive(Clone, Debug)]
pub struct AttachedSkills {
pub catalog: String,
pub runtime: Arc<dyn ToolRuntime>,
pub grants: Vec<SkillToolGrant>,
}
impl AttachedSkills {
pub fn is_empty(&self) -> bool {
self.catalog.is_empty()
}
}
#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
#[error("{message}")]
pub struct SkillError {
pub kind: &'static str,
pub message: String,
}
impl SkillError {
pub fn new(kind: &'static str, message: impl Into<String>) -> Self {
Self { kind, message: message.into() }
}
}
pub trait SkillSource: Send + Sync + fmt::Debug {
fn attach<'a>(&'a self, names: &'a [String]) -> BoxFuture<'a, Result<AttachedSkills, SkillError>>;
}
#[derive(Clone, Debug)]
pub struct Skills(pub Arc<dyn SkillSource>);
impl Skills {
pub fn new(source: Arc<dyn SkillSource>) -> Self {
Self(source)
}
}