1use super::client::ApiClient;
4use super::error::ApiResult;
5use super::types::*;
6
7#[derive(Clone)]
9pub struct SkillsApi {
10 client: ApiClient,
11}
12
13impl SkillsApi {
14 pub fn new(client: ApiClient) -> Self {
16 Self { client }
17 }
18
19 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", ¶ms).await
23 }
24
25 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 pub async fn get(&self, name: &str) -> ApiResult<SkillDetail> {
35 self.client.get(&format!("/skills/{}", name)).await
36 }
37
38 pub async fn install(&self, request: &InstallSkillRequest) -> ApiResult<InstallSkillResponse> {
40 self.client.post("/skills", request).await
41 }
42
43 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 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 pub async fn uninstall(&self, name: &str) -> ApiResult<()> {
76 self.client.delete(&format!("/skills/{}", name)).await
77 }
78
79 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 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}