skill_web/api/
skills.rs

1//! Skills API client
2
3use super::client::ApiClient;
4use super::error::ApiResult;
5use super::types::*;
6
7/// Skills API operations
8#[derive(Clone)]
9pub struct SkillsApi {
10    client: ApiClient,
11}
12
13impl SkillsApi {
14    /// Create a new skills API client
15    pub fn new(client: ApiClient) -> Self {
16        Self { client }
17    }
18
19    /// List all installed skills with pagination
20    pub async fn list(&self, pagination: Option<PaginationParams>) -> ApiResult<PaginatedResponse<SkillSummary>> {
21        let params = pagination.unwrap_or_default();
22        self.client.get_with_query("/skills", &params).await
23    }
24
25    /// List all skills (no pagination)
26    pub async fn list_all(&self) -> ApiResult<Vec<SkillSummary>> {
27        let response: PaginatedResponse<SkillSummary> = self.client
28            .get_with_query("/skills", &PaginationParams { page: 1, per_page: 1000 })
29            .await?;
30        Ok(response.items)
31    }
32
33    /// Get details for a specific skill
34    pub async fn get(&self, name: &str) -> ApiResult<SkillDetail> {
35        self.client.get(&format!("/skills/{}", name)).await
36    }
37
38    /// Install a skill from a source
39    pub async fn install(&self, request: &InstallSkillRequest) -> ApiResult<InstallSkillResponse> {
40        self.client.post("/skills", request).await
41    }
42
43    /// Install a skill from a git URL
44    pub async fn install_from_git(
45        &self,
46        url: &str,
47        git_ref: Option<&str>,
48        force: bool,
49    ) -> ApiResult<InstallSkillResponse> {
50        self.install(&InstallSkillRequest {
51            source: url.to_string(),
52            name: None,
53            git_ref: git_ref.map(String::from),
54            force,
55        })
56        .await
57    }
58
59    /// Install a skill with a custom name
60    pub async fn install_with_name(
61        &self,
62        source: &str,
63        name: &str,
64    ) -> ApiResult<InstallSkillResponse> {
65        self.install(&InstallSkillRequest {
66            source: source.to_string(),
67            name: Some(name.to_string()),
68            git_ref: None,
69            force: false,
70        })
71        .await
72    }
73
74    /// Uninstall a skill
75    pub async fn uninstall(&self, name: &str) -> ApiResult<()> {
76        self.client.delete(&format!("/skills/{}", name)).await
77    }
78
79    /// Get the tools for a skill
80    pub async fn get_tools(&self, skill_name: &str) -> ApiResult<Vec<ToolInfo>> {
81        let detail = self.get(skill_name).await?;
82        Ok(detail.tools)
83    }
84
85    /// Get instances for a skill
86    pub async fn get_instances(&self, skill_name: &str) -> ApiResult<Vec<InstanceInfo>> {
87        let detail = self.get(skill_name).await?;
88        Ok(detail.instances)
89    }
90}