use async_trait::async_trait;
use crate::context::ExecutionContext;
use crate::error::Result;
#[async_trait]
pub trait SkillResource: Send + Sync + std::fmt::Debug {
async fn read(&self, ctx: &ExecutionContext) -> Result<SkillResourceContent>;
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum SkillResourceContent {
Text(String),
Binary {
mime_type: String,
bytes: Vec<u8>,
},
}
impl SkillResourceContent {
#[must_use]
pub fn as_text(&self) -> Option<&str> {
match self {
Self::Text(t) => Some(t),
Self::Binary { .. } => None,
}
}
#[must_use]
pub const fn is_binary(&self) -> bool {
matches!(self, Self::Binary { .. })
}
#[must_use]
pub fn size_bytes(&self) -> usize {
match self {
Self::Text(t) => t.len(),
Self::Binary { bytes, .. } => bytes.len(),
}
}
}