use super::client::ApiClient;
use super::error::ApiResult;
use super::types::*;
#[derive(Clone)]
pub struct ConfigApi {
client: ApiClient,
}
impl ConfigApi {
pub fn new(client: ApiClient) -> Self {
Self { client }
}
pub async fn get(&self) -> ApiResult<AppConfig> {
self.client.get("/config").await
}
pub async fn update(&self, request: &UpdateAppConfigRequest) -> ApiResult<AppConfig> {
self.client.put("/config", request).await
}
pub async fn set_timeout(&self, timeout_secs: u64) -> ApiResult<AppConfig> {
self.update(&UpdateAppConfigRequest {
default_timeout_secs: Some(timeout_secs),
..Default::default()
})
.await
}
pub async fn set_max_concurrent(&self, max: usize) -> ApiResult<AppConfig> {
self.update(&UpdateAppConfigRequest {
max_concurrent_executions: Some(max),
..Default::default()
})
.await
}
pub async fn set_history_enabled(&self, enabled: bool) -> ApiResult<AppConfig> {
self.update(&UpdateAppConfigRequest {
enable_history: Some(enabled),
..Default::default()
})
.await
}
pub async fn set_max_history(&self, max: usize) -> ApiResult<AppConfig> {
self.update(&UpdateAppConfigRequest {
max_history_entries: Some(max),
..Default::default()
})
.await
}
pub async fn health(&self) -> ApiResult<HealthResponse> {
self.client.get("/health").await
}
pub async fn version(&self) -> ApiResult<VersionResponse> {
self.client.get("/version").await
}
pub async fn is_healthy(&self) -> bool {
match self.health().await {
Ok(response) => response.healthy,
Err(_) => false,
}
}
pub async fn validate_manifest(&self, content: &str) -> ApiResult<ValidateManifestResponse> {
self.client
.post("/manifest/validate", &ValidateManifestRequest {
content: content.to_string(),
})
.await
}
pub async fn import_manifest(
&self,
content: &str,
merge: bool,
install: bool,
) -> ApiResult<ImportManifestResponse> {
self.client
.post("/manifest/import", &ImportManifestRequest {
content: content.to_string(),
merge,
install,
})
.await
}
pub async fn get_search_config(&self) -> ApiResult<SearchConfigResponse> {
self.client.get("/search/config").await
}
pub async fn update_search_config(
&self,
request: &UpdateSearchConfigRequest,
) -> ApiResult<SearchConfigResponse> {
self.client.put("/search/config", request).await
}
pub async fn set_embedding_provider(
&self,
provider: &str,
model: Option<&str>,
) -> ApiResult<SearchConfigResponse> {
self.update_search_config(&UpdateSearchConfigRequest {
embedding_provider: Some(provider.to_string()),
embedding_model: model.map(String::from),
..Default::default()
})
.await
}
pub async fn set_hybrid_search(&self, enabled: bool) -> ApiResult<SearchConfigResponse> {
self.update_search_config(&UpdateSearchConfigRequest {
enable_hybrid: Some(enabled),
..Default::default()
})
.await
}
pub async fn set_reranking(&self, enabled: bool) -> ApiResult<SearchConfigResponse> {
self.update_search_config(&UpdateSearchConfigRequest {
enable_reranking: Some(enabled),
..Default::default()
})
.await
}
}