1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteKnowledgeConnectorsByProviderError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetKnowledgeConnectorsError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetKnowledgeConnectorsByProviderCallbackError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetKnowledgeConnectorsByProviderConnectError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetKnowledgeConnectorsCatalogError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetKnowledgeGraphError {
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum PostKnowledgeConnectorsByProviderSyncError {
64 UnknownValue(serde_json::Value),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum PostKnowledgeImportError {
71 UnknownValue(serde_json::Value),
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum PostKnowledgeSearchError {
78 UnknownValue(serde_json::Value),
79}
80
81
82pub async fn delete_knowledge_connectors_by_provider(configuration: &configuration::Configuration, provider: &str) -> Result<models::ConnectionOut, Error<DeleteKnowledgeConnectorsByProviderError>> {
84 let p_provider = provider;
86
87 let uri_str = format!("{}/v1/knowledge/connectors/{provider}", configuration.base_path, provider=crate::apis::urlencode(p_provider));
88 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
89
90 if let Some(ref user_agent) = configuration.user_agent {
91 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
92 }
93 if let Some(ref token) = configuration.bearer_access_token {
94 req_builder = req_builder.bearer_auth(token.to_owned());
95 };
96
97 let req = req_builder.build()?;
98 let resp = configuration.client.execute(req).await?;
99
100 let status = resp.status();
101 let content_type = resp
102 .headers()
103 .get("content-type")
104 .and_then(|v| v.to_str().ok())
105 .unwrap_or("application/octet-stream");
106 let content_type = super::ContentType::from(content_type);
107
108 if !status.is_client_error() && !status.is_server_error() {
109 let content = resp.text().await?;
110 match content_type {
111 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
112 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConnectionOut`"))),
113 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ConnectionOut`")))),
114 }
115 } else {
116 let content = resp.text().await?;
117 let entity: Option<DeleteKnowledgeConnectorsByProviderError> = serde_json::from_str(&content).ok();
118 Err(Error::ResponseError(ResponseContent { status, content, entity }))
119 }
120}
121
122pub async fn get_knowledge_connectors(configuration: &configuration::Configuration, ) -> Result<models::KbConnectorsOut, Error<GetKnowledgeConnectorsError>> {
124
125 let uri_str = format!("{}/v1/knowledge/connectors", configuration.base_path);
126 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
127
128 if let Some(ref user_agent) = configuration.user_agent {
129 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
130 }
131 if let Some(ref token) = configuration.bearer_access_token {
132 req_builder = req_builder.bearer_auth(token.to_owned());
133 };
134
135 let req = req_builder.build()?;
136 let resp = configuration.client.execute(req).await?;
137
138 let status = resp.status();
139 let content_type = resp
140 .headers()
141 .get("content-type")
142 .and_then(|v| v.to_str().ok())
143 .unwrap_or("application/octet-stream");
144 let content_type = super::ContentType::from(content_type);
145
146 if !status.is_client_error() && !status.is_server_error() {
147 let content = resp.text().await?;
148 match content_type {
149 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
150 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::KbConnectorsOut`"))),
151 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::KbConnectorsOut`")))),
152 }
153 } else {
154 let content = resp.text().await?;
155 let entity: Option<GetKnowledgeConnectorsError> = serde_json::from_str(&content).ok();
156 Err(Error::ResponseError(ResponseContent { status, content, entity }))
157 }
158}
159
160pub async fn get_knowledge_connectors_by_provider_callback(configuration: &configuration::Configuration, provider: &str, code: Option<&str>, state: Option<&str>, error: Option<&str>) -> Result<models::ConnectionOut, Error<GetKnowledgeConnectorsByProviderCallbackError>> {
162 let p_provider = provider;
164 let p_code = code;
165 let p_state = state;
166 let p_error = error;
167
168 let uri_str = format!("{}/v1/knowledge/connectors/{provider}/callback", configuration.base_path, provider=crate::apis::urlencode(p_provider));
169 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
170
171 if let Some(ref param_value) = p_code {
172 req_builder = req_builder.query(&[("code", ¶m_value.to_string())]);
173 }
174 if let Some(ref param_value) = p_state {
175 req_builder = req_builder.query(&[("state", ¶m_value.to_string())]);
176 }
177 if let Some(ref param_value) = p_error {
178 req_builder = req_builder.query(&[("error", ¶m_value.to_string())]);
179 }
180 if let Some(ref user_agent) = configuration.user_agent {
181 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
182 }
183 if let Some(ref token) = configuration.bearer_access_token {
184 req_builder = req_builder.bearer_auth(token.to_owned());
185 };
186
187 let req = req_builder.build()?;
188 let resp = configuration.client.execute(req).await?;
189
190 let status = resp.status();
191 let content_type = resp
192 .headers()
193 .get("content-type")
194 .and_then(|v| v.to_str().ok())
195 .unwrap_or("application/octet-stream");
196 let content_type = super::ContentType::from(content_type);
197
198 if !status.is_client_error() && !status.is_server_error() {
199 let content = resp.text().await?;
200 match content_type {
201 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
202 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConnectionOut`"))),
203 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ConnectionOut`")))),
204 }
205 } else {
206 let content = resp.text().await?;
207 let entity: Option<GetKnowledgeConnectorsByProviderCallbackError> = serde_json::from_str(&content).ok();
208 Err(Error::ResponseError(ResponseContent { status, content, entity }))
209 }
210}
211
212pub async fn get_knowledge_connectors_by_provider_connect(configuration: &configuration::Configuration, provider: &str) -> Result<models::KbAuthorizeOut, Error<GetKnowledgeConnectorsByProviderConnectError>> {
214 let p_provider = provider;
216
217 let uri_str = format!("{}/v1/knowledge/connectors/{provider}/connect", configuration.base_path, provider=crate::apis::urlencode(p_provider));
218 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
219
220 if let Some(ref user_agent) = configuration.user_agent {
221 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
222 }
223 if let Some(ref token) = configuration.bearer_access_token {
224 req_builder = req_builder.bearer_auth(token.to_owned());
225 };
226
227 let req = req_builder.build()?;
228 let resp = configuration.client.execute(req).await?;
229
230 let status = resp.status();
231 let content_type = resp
232 .headers()
233 .get("content-type")
234 .and_then(|v| v.to_str().ok())
235 .unwrap_or("application/octet-stream");
236 let content_type = super::ContentType::from(content_type);
237
238 if !status.is_client_error() && !status.is_server_error() {
239 let content = resp.text().await?;
240 match content_type {
241 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
242 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::KbAuthorizeOut`"))),
243 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::KbAuthorizeOut`")))),
244 }
245 } else {
246 let content = resp.text().await?;
247 let entity: Option<GetKnowledgeConnectorsByProviderConnectError> = serde_json::from_str(&content).ok();
248 Err(Error::ResponseError(ResponseContent { status, content, entity }))
249 }
250}
251
252pub async fn get_knowledge_connectors_catalog(configuration: &configuration::Configuration, ) -> Result<models::CatalogOut, Error<GetKnowledgeConnectorsCatalogError>> {
254
255 let uri_str = format!("{}/v1/knowledge/connectors/catalog", configuration.base_path);
256 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
257
258 if let Some(ref user_agent) = configuration.user_agent {
259 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
260 }
261 if let Some(ref token) = configuration.bearer_access_token {
262 req_builder = req_builder.bearer_auth(token.to_owned());
263 };
264
265 let req = req_builder.build()?;
266 let resp = configuration.client.execute(req).await?;
267
268 let status = resp.status();
269 let content_type = resp
270 .headers()
271 .get("content-type")
272 .and_then(|v| v.to_str().ok())
273 .unwrap_or("application/octet-stream");
274 let content_type = super::ContentType::from(content_type);
275
276 if !status.is_client_error() && !status.is_server_error() {
277 let content = resp.text().await?;
278 match content_type {
279 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
280 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CatalogOut`"))),
281 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CatalogOut`")))),
282 }
283 } else {
284 let content = resp.text().await?;
285 let entity: Option<GetKnowledgeConnectorsCatalogError> = serde_json::from_str(&content).ok();
286 Err(Error::ResponseError(ResponseContent { status, content, entity }))
287 }
288}
289
290pub async fn get_knowledge_graph(configuration: &configuration::Configuration, project: Option<&str>) -> Result<models::GraphOut, Error<GetKnowledgeGraphError>> {
292 let p_project = project;
294
295 let uri_str = format!("{}/v1/knowledge/graph", configuration.base_path);
296 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
297
298 if let Some(ref param_value) = p_project {
299 req_builder = req_builder.query(&[("project", ¶m_value.to_string())]);
300 }
301 if let Some(ref user_agent) = configuration.user_agent {
302 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
303 }
304 if let Some(ref token) = configuration.bearer_access_token {
305 req_builder = req_builder.bearer_auth(token.to_owned());
306 };
307
308 let req = req_builder.build()?;
309 let resp = configuration.client.execute(req).await?;
310
311 let status = resp.status();
312 let content_type = resp
313 .headers()
314 .get("content-type")
315 .and_then(|v| v.to_str().ok())
316 .unwrap_or("application/octet-stream");
317 let content_type = super::ContentType::from(content_type);
318
319 if !status.is_client_error() && !status.is_server_error() {
320 let content = resp.text().await?;
321 match content_type {
322 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
323 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GraphOut`"))),
324 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GraphOut`")))),
325 }
326 } else {
327 let content = resp.text().await?;
328 let entity: Option<GetKnowledgeGraphError> = serde_json::from_str(&content).ok();
329 Err(Error::ResponseError(ResponseContent { status, content, entity }))
330 }
331}
332
333pub async fn post_knowledge_connectors_by_provider_sync(configuration: &configuration::Configuration, provider: &str) -> Result<models::KbSyncOut, Error<PostKnowledgeConnectorsByProviderSyncError>> {
335 let p_provider = provider;
337
338 let uri_str = format!("{}/v1/knowledge/connectors/{provider}/sync", configuration.base_path, provider=crate::apis::urlencode(p_provider));
339 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
340
341 if let Some(ref user_agent) = configuration.user_agent {
342 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
343 }
344 if let Some(ref token) = configuration.bearer_access_token {
345 req_builder = req_builder.bearer_auth(token.to_owned());
346 };
347
348 let req = req_builder.build()?;
349 let resp = configuration.client.execute(req).await?;
350
351 let status = resp.status();
352 let content_type = resp
353 .headers()
354 .get("content-type")
355 .and_then(|v| v.to_str().ok())
356 .unwrap_or("application/octet-stream");
357 let content_type = super::ContentType::from(content_type);
358
359 if !status.is_client_error() && !status.is_server_error() {
360 let content = resp.text().await?;
361 match content_type {
362 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
363 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::KbSyncOut`"))),
364 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::KbSyncOut`")))),
365 }
366 } else {
367 let content = resp.text().await?;
368 let entity: Option<PostKnowledgeConnectorsByProviderSyncError> = serde_json::from_str(&content).ok();
369 Err(Error::ResponseError(ResponseContent { status, content, entity }))
370 }
371}
372
373pub async fn post_knowledge_import(configuration: &configuration::Configuration, ) -> Result<(), Error<PostKnowledgeImportError>> {
375
376 let uri_str = format!("{}/v1/knowledge/import", configuration.base_path);
377 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
378
379 if let Some(ref user_agent) = configuration.user_agent {
380 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
381 }
382 if let Some(ref token) = configuration.bearer_access_token {
383 req_builder = req_builder.bearer_auth(token.to_owned());
384 };
385
386 let req = req_builder.build()?;
387 let resp = configuration.client.execute(req).await?;
388
389 let status = resp.status();
390
391 if !status.is_client_error() && !status.is_server_error() {
392 Ok(())
393 } else {
394 let content = resp.text().await?;
395 let entity: Option<PostKnowledgeImportError> = serde_json::from_str(&content).ok();
396 Err(Error::ResponseError(ResponseContent { status, content, entity }))
397 }
398}
399
400pub async fn post_knowledge_search(configuration: &configuration::Configuration, search_in: models::SearchIn) -> Result<models::SearchOut, Error<PostKnowledgeSearchError>> {
402 let p_search_in = search_in;
404
405 let uri_str = format!("{}/v1/knowledge/search", configuration.base_path);
406 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
407
408 if let Some(ref user_agent) = configuration.user_agent {
409 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
410 }
411 if let Some(ref token) = configuration.bearer_access_token {
412 req_builder = req_builder.bearer_auth(token.to_owned());
413 };
414 req_builder = req_builder.json(&p_search_in);
415
416 let req = req_builder.build()?;
417 let resp = configuration.client.execute(req).await?;
418
419 let status = resp.status();
420 let content_type = resp
421 .headers()
422 .get("content-type")
423 .and_then(|v| v.to_str().ok())
424 .unwrap_or("application/octet-stream");
425 let content_type = super::ContentType::from(content_type);
426
427 if !status.is_client_error() && !status.is_server_error() {
428 let content = resp.text().await?;
429 match content_type {
430 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
431 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SearchOut`"))),
432 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SearchOut`")))),
433 }
434 } else {
435 let content = resp.text().await?;
436 let entity: Option<PostKnowledgeSearchError> = serde_json::from_str(&content).ok();
437 Err(Error::ResponseError(ResponseContent { status, content, entity }))
438 }
439}
440