1use super::client::ApiClient;
4use super::error::ApiResult;
5use super::types::*;
6
7#[derive(Clone)]
9pub struct ConfigApi {
10 client: ApiClient,
11}
12
13impl ConfigApi {
14 pub fn new(client: ApiClient) -> Self {
16 Self { client }
17 }
18
19 pub async fn get(&self) -> ApiResult<AppConfig> {
21 self.client.get("/config").await
22 }
23
24 pub async fn update(&self, request: &UpdateAppConfigRequest) -> ApiResult<AppConfig> {
26 self.client.put("/config", request).await
27 }
28
29 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 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 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 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 pub async fn health(&self) -> ApiResult<HealthResponse> {
67 self.client.get("/health").await
68 }
69
70 pub async fn version(&self) -> ApiResult<VersionResponse> {
72 self.client.get("/version").await
73 }
74
75 pub async fn is_healthy(&self) -> bool {
77 match self.health().await {
78 Ok(response) => response.healthy,
79 Err(_) => false,
80 }
81 }
82
83 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 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 pub async fn get_search_config(&self) -> ApiResult<SearchConfigResponse> {
118 self.client.get("/search/config").await
119 }
120
121 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 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 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 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}