1use reqwest;
12use serde::{Deserialize, Serialize, de::Error as _};
13
14use super::{ContentType, Error, configuration};
15use crate::{apis::ResponseContent, models};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum AddAdditionalTokenPackageError {
21 Status400(models::GetFinances400Response),
22 Status401(models::GetFinances401Response),
23 Status403(models::GetAccountStatus403Response),
24 Status404(models::GetImage404Response),
25 Status429(models::GetFinances429Response),
26 Status500(models::GetFinances500Response),
27 UnknownValue(serde_json::Value)
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum CreateAgentError {
34 Status400(models::GetFinances400Response),
35 Status401(models::GetFinances401Response),
36 Status403(models::GetAccountStatus403Response),
37 Status429(models::GetFinances429Response),
38 Status500(models::GetFinances500Response),
39 UnknownValue(serde_json::Value)
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum DeleteAgentError {
46 Status400(models::GetFinances400Response),
47 Status401(models::GetFinances401Response),
48 Status403(models::GetAccountStatus403Response),
49 Status404(models::GetImage404Response),
50 Status429(models::GetFinances429Response),
51 Status500(models::GetFinances500Response),
52 UnknownValue(serde_json::Value)
53}
54
55#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum GetAgentError {
59 Status400(models::GetFinances400Response),
60 Status401(models::GetFinances401Response),
61 Status403(models::GetAccountStatus403Response),
62 Status404(models::GetImage404Response),
63 Status429(models::GetFinances429Response),
64 Status500(models::GetFinances500Response),
65 UnknownValue(serde_json::Value)
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum GetAgentStatisticsError {
72 Status400(models::GetFinances400Response),
73 Status401(models::GetFinances401Response),
74 Status403(models::GetAccountStatus403Response),
75 Status404(models::GetImage404Response),
76 Status429(models::GetFinances429Response),
77 Status500(models::GetFinances500Response),
78 UnknownValue(serde_json::Value)
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum GetAgentsError {
85 Status400(models::GetFinances400Response),
86 Status401(models::GetFinances401Response),
87 Status403(models::GetAccountStatus403Response),
88 Status404(models::GetImage404Response),
89 Status429(models::GetFinances429Response),
90 Status500(models::GetFinances500Response),
91 UnknownValue(serde_json::Value)
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(untagged)]
97pub enum GetAgentsTokenPackagesError {
98 Status400(models::GetFinances400Response),
99 Status401(models::GetFinances401Response),
100 Status403(models::GetAccountStatus403Response),
101 Status404(models::GetImage404Response),
102 Status429(models::GetFinances429Response),
103 Status500(models::GetFinances500Response),
104 UnknownValue(serde_json::Value)
105}
106
107#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(untagged)]
110pub enum GetKnowledgebasesTokenPackagesError {
111 Status400(models::GetFinances400Response),
112 Status401(models::GetFinances401Response),
113 Status403(models::GetAccountStatus403Response),
114 Status404(models::GetImage404Response),
115 Status429(models::GetFinances429Response),
116 Status500(models::GetFinances500Response),
117 UnknownValue(serde_json::Value)
118}
119
120#[derive(Debug, Clone, Serialize, Deserialize)]
122#[serde(untagged)]
123pub enum GetModelsError {
124 Status400(models::GetFinances400Response),
125 Status401(models::GetFinances401Response),
126 Status403(models::GetAccountStatus403Response),
127 Status404(models::GetImage404Response),
128 Status429(models::GetFinances429Response),
129 Status500(models::GetFinances500Response),
130 UnknownValue(serde_json::Value)
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize)]
135#[serde(untagged)]
136pub enum UpdateAgentError {
137 Status400(models::GetFinances400Response),
138 Status401(models::GetFinances401Response),
139 Status403(models::GetAccountStatus403Response),
140 Status404(models::GetImage404Response),
141 Status429(models::GetFinances429Response),
142 Status500(models::GetFinances500Response),
143 UnknownValue(serde_json::Value)
144}
145
146pub async fn add_additional_token_package(
149 configuration: &configuration::Configuration,
150 id: i32,
151 add_token_package: Option<models::AddTokenPackage>
152) -> Result<(), Error<AddAdditionalTokenPackageError>> {
153 let p_path_id = id;
155 let p_body_add_token_package = add_token_package;
156
157 let uri_str = format!(
158 "{}/api/v1/cloud-ai/agents/{id}/add-additional-token-package",
159 configuration.base_path,
160 id = p_path_id
161 );
162 let mut req_builder = configuration
163 .client
164 .request(reqwest::Method::POST, &uri_str);
165
166 if let Some(ref user_agent) = configuration.user_agent {
167 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
168 }
169 if let Some(ref token) = configuration.bearer_access_token {
170 req_builder = req_builder.bearer_auth(token.to_owned());
171 };
172 req_builder = req_builder.json(&p_body_add_token_package);
173
174 let req = req_builder.build()?;
175 let resp = configuration.client.execute(req).await?;
176
177 let status = resp.status();
178
179 if !status.is_client_error() && !status.is_server_error() {
180 Ok(())
181 } else {
182 let content = resp.text().await?;
183 let entity: Option<AddAdditionalTokenPackageError> = serde_json::from_str(&content).ok();
184 Err(Error::ResponseError(ResponseContent {
185 status,
186 content,
187 entity
188 }))
189 }
190}
191
192pub async fn create_agent(
197 configuration: &configuration::Configuration,
198 create_agent: models::CreateAgent
199) -> Result<models::CreateAgent201Response, Error<CreateAgentError>> {
200 let p_body_create_agent = create_agent;
202
203 let uri_str = format!("{}/api/v1/cloud-ai/agents", configuration.base_path);
204 let mut req_builder = configuration
205 .client
206 .request(reqwest::Method::POST, &uri_str);
207
208 if let Some(ref user_agent) = configuration.user_agent {
209 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
210 }
211 if let Some(ref token) = configuration.bearer_access_token {
212 req_builder = req_builder.bearer_auth(token.to_owned());
213 };
214 req_builder = req_builder.json(&p_body_create_agent);
215
216 let req = req_builder.build()?;
217 let resp = configuration.client.execute(req).await?;
218
219 let status = resp.status();
220 let content_type = resp
221 .headers()
222 .get("content-type")
223 .and_then(|v| v.to_str().ok())
224 .unwrap_or("application/octet-stream");
225 let content_type = super::ContentType::from(content_type);
226
227 if !status.is_client_error() && !status.is_server_error() {
228 let content = resp.text().await?;
229 match content_type {
230 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
231 ContentType::Text => {
232 return Err(Error::from(serde_json::Error::custom(
233 "Received `text/plain` content type response that cannot be converted to `models::CreateAgent201Response`"
234 )));
235 }
236 ContentType::Unsupported(unknown_type) => {
237 return Err(Error::from(serde_json::Error::custom(format!(
238 "Received `{unknown_type}` content type response that cannot be converted to `models::CreateAgent201Response`"
239 ))));
240 }
241 }
242 } else {
243 let content = resp.text().await?;
244 let entity: Option<CreateAgentError> = serde_json::from_str(&content).ok();
245 Err(Error::ResponseError(ResponseContent {
246 status,
247 content,
248 entity
249 }))
250 }
251}
252
253pub async fn delete_agent(
256 configuration: &configuration::Configuration,
257 id: i32
258) -> Result<(), Error<DeleteAgentError>> {
259 let p_path_id = id;
261
262 let uri_str = format!(
263 "{}/api/v1/cloud-ai/agents/{id}",
264 configuration.base_path,
265 id = p_path_id
266 );
267 let mut req_builder = configuration
268 .client
269 .request(reqwest::Method::DELETE, &uri_str);
270
271 if let Some(ref user_agent) = configuration.user_agent {
272 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
273 }
274 if let Some(ref token) = configuration.bearer_access_token {
275 req_builder = req_builder.bearer_auth(token.to_owned());
276 };
277
278 let req = req_builder.build()?;
279 let resp = configuration.client.execute(req).await?;
280
281 let status = resp.status();
282
283 if !status.is_client_error() && !status.is_server_error() {
284 Ok(())
285 } else {
286 let content = resp.text().await?;
287 let entity: Option<DeleteAgentError> = serde_json::from_str(&content).ok();
288 Err(Error::ResponseError(ResponseContent {
289 status,
290 content,
291 entity
292 }))
293 }
294}
295
296pub async fn get_agent(
299 configuration: &configuration::Configuration,
300 id: i32
301) -> Result<models::CreateAgent201Response, Error<GetAgentError>> {
302 let p_path_id = id;
304
305 let uri_str = format!(
306 "{}/api/v1/cloud-ai/agents/{id}",
307 configuration.base_path,
308 id = p_path_id
309 );
310 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
311
312 if let Some(ref user_agent) = configuration.user_agent {
313 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
314 }
315 if let Some(ref token) = configuration.bearer_access_token {
316 req_builder = req_builder.bearer_auth(token.to_owned());
317 };
318
319 let req = req_builder.build()?;
320 let resp = configuration.client.execute(req).await?;
321
322 let status = resp.status();
323 let content_type = resp
324 .headers()
325 .get("content-type")
326 .and_then(|v| v.to_str().ok())
327 .unwrap_or("application/octet-stream");
328 let content_type = super::ContentType::from(content_type);
329
330 if !status.is_client_error() && !status.is_server_error() {
331 let content = resp.text().await?;
332 match content_type {
333 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
334 ContentType::Text => {
335 return Err(Error::from(serde_json::Error::custom(
336 "Received `text/plain` content type response that cannot be converted to `models::CreateAgent201Response`"
337 )));
338 }
339 ContentType::Unsupported(unknown_type) => {
340 return Err(Error::from(serde_json::Error::custom(format!(
341 "Received `{unknown_type}` content type response that cannot be converted to `models::CreateAgent201Response`"
342 ))));
343 }
344 }
345 } else {
346 let content = resp.text().await?;
347 let entity: Option<GetAgentError> = serde_json::from_str(&content).ok();
348 Err(Error::ResponseError(ResponseContent {
349 status,
350 content,
351 entity
352 }))
353 }
354}
355
356pub async fn get_agent_statistics(
360 configuration: &configuration::Configuration,
361 id: i32,
362 start_time: Option<chrono::DateTime<chrono::FixedOffset>>,
363 end_time: Option<chrono::DateTime<chrono::FixedOffset>>,
364 interval: Option<f64>
365) -> Result<models::GetAgentStatistics200Response, Error<GetAgentStatisticsError>> {
366 let p_path_id = id;
368 let p_query_start_time = start_time;
369 let p_query_end_time = end_time;
370 let p_query_interval = interval;
371
372 let uri_str = format!(
373 "{}/api/v1/cloud-ai/agents/{id}/statistic",
374 configuration.base_path,
375 id = p_path_id
376 );
377 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
378
379 if let Some(ref param_value) = p_query_start_time {
380 req_builder = req_builder.query(&[("startTime", ¶m_value.to_string())]);
381 }
382 if let Some(ref param_value) = p_query_end_time {
383 req_builder = req_builder.query(&[("endTime", ¶m_value.to_string())]);
384 }
385 if let Some(ref param_value) = p_query_interval {
386 req_builder = req_builder.query(&[("interval", ¶m_value.to_string())]);
387 }
388 if let Some(ref user_agent) = configuration.user_agent {
389 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
390 }
391 if let Some(ref token) = configuration.bearer_access_token {
392 req_builder = req_builder.bearer_auth(token.to_owned());
393 };
394
395 let req = req_builder.build()?;
396 let resp = configuration.client.execute(req).await?;
397
398 let status = resp.status();
399 let content_type = resp
400 .headers()
401 .get("content-type")
402 .and_then(|v| v.to_str().ok())
403 .unwrap_or("application/octet-stream");
404 let content_type = super::ContentType::from(content_type);
405
406 if !status.is_client_error() && !status.is_server_error() {
407 let content = resp.text().await?;
408 match content_type {
409 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
410 ContentType::Text => {
411 return Err(Error::from(serde_json::Error::custom(
412 "Received `text/plain` content type response that cannot be converted to `models::GetAgentStatistics200Response`"
413 )));
414 }
415 ContentType::Unsupported(unknown_type) => {
416 return Err(Error::from(serde_json::Error::custom(format!(
417 "Received `{unknown_type}` content type response that cannot be converted to `models::GetAgentStatistics200Response`"
418 ))));
419 }
420 }
421 } else {
422 let content = resp.text().await?;
423 let entity: Option<GetAgentStatisticsError> = serde_json::from_str(&content).ok();
424 Err(Error::ResponseError(ResponseContent {
425 status,
426 content,
427 entity
428 }))
429 }
430}
431
432pub async fn get_agents(
436 configuration: &configuration::Configuration
437) -> Result<models::GetAgents200Response, Error<GetAgentsError>> {
438 let uri_str = format!("{}/api/v1/cloud-ai/agents", configuration.base_path);
439 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
440
441 if let Some(ref user_agent) = configuration.user_agent {
442 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
443 }
444 if let Some(ref token) = configuration.bearer_access_token {
445 req_builder = req_builder.bearer_auth(token.to_owned());
446 };
447
448 let req = req_builder.build()?;
449 let resp = configuration.client.execute(req).await?;
450
451 let status = resp.status();
452 let content_type = resp
453 .headers()
454 .get("content-type")
455 .and_then(|v| v.to_str().ok())
456 .unwrap_or("application/octet-stream");
457 let content_type = super::ContentType::from(content_type);
458
459 if !status.is_client_error() && !status.is_server_error() {
460 let content = resp.text().await?;
461 match content_type {
462 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
463 ContentType::Text => {
464 return Err(Error::from(serde_json::Error::custom(
465 "Received `text/plain` content type response that cannot be converted to `models::GetAgents200Response`"
466 )));
467 }
468 ContentType::Unsupported(unknown_type) => {
469 return Err(Error::from(serde_json::Error::custom(format!(
470 "Received `{unknown_type}` content type response that cannot be converted to `models::GetAgents200Response`"
471 ))));
472 }
473 }
474 } else {
475 let content = resp.text().await?;
476 let entity: Option<GetAgentsError> = serde_json::from_str(&content).ok();
477 Err(Error::ResponseError(ResponseContent {
478 status,
479 content,
480 entity
481 }))
482 }
483}
484
485pub async fn get_agents_token_packages(
489 configuration: &configuration::Configuration
490) -> Result<models::GetAgentsTokenPackages200Response, Error<GetAgentsTokenPackagesError>> {
491 let uri_str = format!(
492 "{}/api/v1/cloud-ai/token-packages/agents",
493 configuration.base_path
494 );
495 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
496
497 if let Some(ref user_agent) = configuration.user_agent {
498 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
499 }
500 if let Some(ref token) = configuration.bearer_access_token {
501 req_builder = req_builder.bearer_auth(token.to_owned());
502 };
503
504 let req = req_builder.build()?;
505 let resp = configuration.client.execute(req).await?;
506
507 let status = resp.status();
508 let content_type = resp
509 .headers()
510 .get("content-type")
511 .and_then(|v| v.to_str().ok())
512 .unwrap_or("application/octet-stream");
513 let content_type = super::ContentType::from(content_type);
514
515 if !status.is_client_error() && !status.is_server_error() {
516 let content = resp.text().await?;
517 match content_type {
518 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
519 ContentType::Text => {
520 return Err(Error::from(serde_json::Error::custom(
521 "Received `text/plain` content type response that cannot be converted to `models::GetAgentsTokenPackages200Response`"
522 )));
523 }
524 ContentType::Unsupported(unknown_type) => {
525 return Err(Error::from(serde_json::Error::custom(format!(
526 "Received `{unknown_type}` content type response that cannot be converted to `models::GetAgentsTokenPackages200Response`"
527 ))));
528 }
529 }
530 } else {
531 let content = resp.text().await?;
532 let entity: Option<GetAgentsTokenPackagesError> = serde_json::from_str(&content).ok();
533 Err(Error::ResponseError(ResponseContent {
534 status,
535 content,
536 entity
537 }))
538 }
539}
540
541pub async fn get_knowledgebases_token_packages(
545 configuration: &configuration::Configuration
546) -> Result<models::GetAgentsTokenPackages200Response, Error<GetKnowledgebasesTokenPackagesError>>
547{
548 let uri_str = format!(
549 "{}/api/v1/cloud-ai/token-packages/knowledge-bases",
550 configuration.base_path
551 );
552 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
553
554 if let Some(ref user_agent) = configuration.user_agent {
555 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
556 }
557 if let Some(ref token) = configuration.bearer_access_token {
558 req_builder = req_builder.bearer_auth(token.to_owned());
559 };
560
561 let req = req_builder.build()?;
562 let resp = configuration.client.execute(req).await?;
563
564 let status = resp.status();
565 let content_type = resp
566 .headers()
567 .get("content-type")
568 .and_then(|v| v.to_str().ok())
569 .unwrap_or("application/octet-stream");
570 let content_type = super::ContentType::from(content_type);
571
572 if !status.is_client_error() && !status.is_server_error() {
573 let content = resp.text().await?;
574 match content_type {
575 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
576 ContentType::Text => {
577 return Err(Error::from(serde_json::Error::custom(
578 "Received `text/plain` content type response that cannot be converted to `models::GetAgentsTokenPackages200Response`"
579 )));
580 }
581 ContentType::Unsupported(unknown_type) => {
582 return Err(Error::from(serde_json::Error::custom(format!(
583 "Received `{unknown_type}` content type response that cannot be converted to `models::GetAgentsTokenPackages200Response`"
584 ))));
585 }
586 }
587 } else {
588 let content = resp.text().await?;
589 let entity: Option<GetKnowledgebasesTokenPackagesError> =
590 serde_json::from_str(&content).ok();
591 Err(Error::ResponseError(ResponseContent {
592 status,
593 content,
594 entity
595 }))
596 }
597}
598
599pub async fn get_models(
603 configuration: &configuration::Configuration
604) -> Result<models::GetModels200Response, Error<GetModelsError>> {
605 let uri_str = format!("{}/api/v1/cloud-ai/models", configuration.base_path);
606 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
607
608 if let Some(ref user_agent) = configuration.user_agent {
609 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
610 }
611 if let Some(ref token) = configuration.bearer_access_token {
612 req_builder = req_builder.bearer_auth(token.to_owned());
613 };
614
615 let req = req_builder.build()?;
616 let resp = configuration.client.execute(req).await?;
617
618 let status = resp.status();
619 let content_type = resp
620 .headers()
621 .get("content-type")
622 .and_then(|v| v.to_str().ok())
623 .unwrap_or("application/octet-stream");
624 let content_type = super::ContentType::from(content_type);
625
626 if !status.is_client_error() && !status.is_server_error() {
627 let content = resp.text().await?;
628 match content_type {
629 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
630 ContentType::Text => {
631 return Err(Error::from(serde_json::Error::custom(
632 "Received `text/plain` content type response that cannot be converted to `models::GetModels200Response`"
633 )));
634 }
635 ContentType::Unsupported(unknown_type) => {
636 return Err(Error::from(serde_json::Error::custom(format!(
637 "Received `{unknown_type}` content type response that cannot be converted to `models::GetModels200Response`"
638 ))));
639 }
640 }
641 } else {
642 let content = resp.text().await?;
643 let entity: Option<GetModelsError> = serde_json::from_str(&content).ok();
644 Err(Error::ResponseError(ResponseContent {
645 status,
646 content,
647 entity
648 }))
649 }
650}
651
652pub async fn update_agent(
655 configuration: &configuration::Configuration,
656 id: i32,
657 update_agent: models::UpdateAgent
658) -> Result<models::CreateAgent201Response, Error<UpdateAgentError>> {
659 let p_path_id = id;
661 let p_body_update_agent = update_agent;
662
663 let uri_str = format!(
664 "{}/api/v1/cloud-ai/agents/{id}",
665 configuration.base_path,
666 id = p_path_id
667 );
668 let mut req_builder = configuration
669 .client
670 .request(reqwest::Method::PATCH, &uri_str);
671
672 if let Some(ref user_agent) = configuration.user_agent {
673 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
674 }
675 if let Some(ref token) = configuration.bearer_access_token {
676 req_builder = req_builder.bearer_auth(token.to_owned());
677 };
678 req_builder = req_builder.json(&p_body_update_agent);
679
680 let req = req_builder.build()?;
681 let resp = configuration.client.execute(req).await?;
682
683 let status = resp.status();
684 let content_type = resp
685 .headers()
686 .get("content-type")
687 .and_then(|v| v.to_str().ok())
688 .unwrap_or("application/octet-stream");
689 let content_type = super::ContentType::from(content_type);
690
691 if !status.is_client_error() && !status.is_server_error() {
692 let content = resp.text().await?;
693 match content_type {
694 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
695 ContentType::Text => {
696 return Err(Error::from(serde_json::Error::custom(
697 "Received `text/plain` content type response that cannot be converted to `models::CreateAgent201Response`"
698 )));
699 }
700 ContentType::Unsupported(unknown_type) => {
701 return Err(Error::from(serde_json::Error::custom(format!(
702 "Received `{unknown_type}` content type response that cannot be converted to `models::CreateAgent201Response`"
703 ))));
704 }
705 }
706 } else {
707 let content = resp.text().await?;
708 let entity: Option<UpdateAgentError> = serde_json::from_str(&content).ok();
709 Err(Error::ResponseError(ResponseContent {
710 status,
711 content,
712 entity
713 }))
714 }
715}