skill_web/api/
config.rs

1//! Configuration API client
2
3use super::client::ApiClient;
4use super::error::ApiResult;
5use super::types::*;
6
7/// Configuration API operations
8#[derive(Clone)]
9pub struct ConfigApi {
10    client: ApiClient,
11}
12
13impl ConfigApi {
14    /// Create a new config API client
15    pub fn new(client: ApiClient) -> Self {
16        Self { client }
17    }
18
19    /// Get application configuration
20    pub async fn get(&self) -> ApiResult<AppConfig> {
21        self.client.get("/config").await
22    }
23
24    /// Update application configuration
25    pub async fn update(&self, request: &UpdateAppConfigRequest) -> ApiResult<AppConfig> {
26        self.client.put("/config", request).await
27    }
28
29    /// Set default execution timeout
30    pub async fn set_timeout(&self, timeout_secs: u64) -> ApiResult<AppConfig> {
31        self.update(&UpdateAppConfigRequest {
32            default_timeout_secs: Some(timeout_secs),
33            ..Default::default()
34        })
35        .await
36    }
37
38    /// Set max concurrent executions
39    pub async fn set_max_concurrent(&self, max: usize) -> ApiResult<AppConfig> {
40        self.update(&UpdateAppConfigRequest {
41            max_concurrent_executions: Some(max),
42            ..Default::default()
43        })
44        .await
45    }
46
47    /// Enable or disable execution history
48    pub async fn set_history_enabled(&self, enabled: bool) -> ApiResult<AppConfig> {
49        self.update(&UpdateAppConfigRequest {
50            enable_history: Some(enabled),
51            ..Default::default()
52        })
53        .await
54    }
55
56    /// Set max history entries
57    pub async fn set_max_history(&self, max: usize) -> ApiResult<AppConfig> {
58        self.update(&UpdateAppConfigRequest {
59            max_history_entries: Some(max),
60            ..Default::default()
61        })
62        .await
63    }
64
65    /// Health check
66    pub async fn health(&self) -> ApiResult<HealthResponse> {
67        self.client.get("/health").await
68    }
69
70    /// Get version information
71    pub async fn version(&self) -> ApiResult<VersionResponse> {
72        self.client.get("/version").await
73    }
74
75    /// Check if the server is healthy
76    pub async fn is_healthy(&self) -> bool {
77        match self.health().await {
78            Ok(response) => response.healthy,
79            Err(_) => false,
80        }
81    }
82
83    // =========================================================================
84    // Manifest Import/Export
85    // =========================================================================
86
87    /// Validate a manifest without importing
88    pub async fn validate_manifest(&self, content: &str) -> ApiResult<ValidateManifestResponse> {
89        self.client
90            .post("/manifest/validate", &ValidateManifestRequest {
91                content: content.to_string(),
92            })
93            .await
94    }
95
96    /// Import a manifest configuration
97    pub async fn import_manifest(
98        &self,
99        content: &str,
100        merge: bool,
101        install: bool,
102    ) -> ApiResult<ImportManifestResponse> {
103        self.client
104            .post("/manifest/import", &ImportManifestRequest {
105                content: content.to_string(),
106                merge,
107                install,
108            })
109            .await
110    }
111
112    // =========================================================================
113    // Search Configuration
114    // =========================================================================
115
116    /// Get search configuration
117    pub async fn get_search_config(&self) -> ApiResult<SearchConfigResponse> {
118        self.client.get("/search/config").await
119    }
120
121    /// Update search configuration
122    pub async fn update_search_config(
123        &self,
124        request: &UpdateSearchConfigRequest,
125    ) -> ApiResult<SearchConfigResponse> {
126        self.client.put("/search/config", request).await
127    }
128
129    /// Set embedding provider
130    pub async fn set_embedding_provider(
131        &self,
132        provider: &str,
133        model: Option<&str>,
134    ) -> ApiResult<SearchConfigResponse> {
135        self.update_search_config(&UpdateSearchConfigRequest {
136            embedding_provider: Some(provider.to_string()),
137            embedding_model: model.map(String::from),
138            ..Default::default()
139        })
140        .await
141    }
142
143    /// Enable or disable hybrid search
144    pub async fn set_hybrid_search(&self, enabled: bool) -> ApiResult<SearchConfigResponse> {
145        self.update_search_config(&UpdateSearchConfigRequest {
146            enable_hybrid: Some(enabled),
147            ..Default::default()
148        })
149        .await
150    }
151
152    /// Enable or disable reranking
153    pub async fn set_reranking(&self, enabled: bool) -> ApiResult<SearchConfigResponse> {
154        self.update_search_config(&UpdateSearchConfigRequest {
155            enable_reranking: Some(enabled),
156            ..Default::default()
157        })
158        .await
159    }
160}