use super::client::ApiClient;
use super::error::ApiResult;
use super::types::*;
#[derive(Clone)]
pub struct SkillsApi {
client: ApiClient,
}
impl SkillsApi {
pub fn new(client: ApiClient) -> Self {
Self { client }
}
pub async fn list(&self, pagination: Option<PaginationParams>) -> ApiResult<PaginatedResponse<SkillSummary>> {
let params = pagination.unwrap_or_default();
self.client.get_with_query("/skills", ¶ms).await
}
pub async fn list_all(&self) -> ApiResult<Vec<SkillSummary>> {
let response: PaginatedResponse<SkillSummary> = self.client
.get_with_query("/skills", &PaginationParams { page: 1, per_page: 1000 })
.await?;
Ok(response.items)
}
pub async fn get(&self, name: &str) -> ApiResult<SkillDetail> {
self.client.get(&format!("/skills/{}", name)).await
}
pub async fn install(&self, request: &InstallSkillRequest) -> ApiResult<InstallSkillResponse> {
self.client.post("/skills", request).await
}
pub async fn install_from_git(
&self,
url: &str,
git_ref: Option<&str>,
force: bool,
) -> ApiResult<InstallSkillResponse> {
self.install(&InstallSkillRequest {
source: url.to_string(),
name: None,
git_ref: git_ref.map(String::from),
force,
})
.await
}
pub async fn install_with_name(
&self,
source: &str,
name: &str,
) -> ApiResult<InstallSkillResponse> {
self.install(&InstallSkillRequest {
source: source.to_string(),
name: Some(name.to_string()),
git_ref: None,
force: false,
})
.await
}
pub async fn uninstall(&self, name: &str) -> ApiResult<()> {
self.client.delete(&format!("/skills/{}", name)).await
}
pub async fn get_tools(&self, skill_name: &str) -> ApiResult<Vec<ToolInfo>> {
let detail = self.get(skill_name).await?;
Ok(detail.tools)
}
pub async fn get_instances(&self, skill_name: &str) -> ApiResult<Vec<InstanceInfo>> {
let detail = self.get(skill_name).await?;
Ok(detail.instances)
}
}