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 AgentsApiV1AgentsCreateError {
22 Status422(models::HttpValidationError),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum AgentsApiV1AgentsCreateOrUpdateAliasError {
30 Status422(models::HttpValidationError),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum AgentsApiV1AgentsDeleteError {
38 Status422(models::HttpValidationError),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum AgentsApiV1AgentsDeleteAliasError {
46 Status422(models::HttpValidationError),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum AgentsApiV1AgentsGetError {
54 Status422(models::HttpValidationError),
55 UnknownValue(serde_json::Value),
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum AgentsApiV1AgentsGetVersionError {
62 Status422(models::HttpValidationError),
63 UnknownValue(serde_json::Value),
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum AgentsApiV1AgentsListError {
70 Status422(models::HttpValidationError),
71 UnknownValue(serde_json::Value),
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum AgentsApiV1AgentsListVersionAliasesError {
78 Status422(models::HttpValidationError),
79 UnknownValue(serde_json::Value),
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum AgentsApiV1AgentsListVersionsError {
86 Status422(models::HttpValidationError),
87 UnknownValue(serde_json::Value),
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(untagged)]
93pub enum AgentsApiV1AgentsUpdateError {
94 Status422(models::HttpValidationError),
95 UnknownValue(serde_json::Value),
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(untagged)]
101pub enum AgentsApiV1AgentsUpdateVersionError {
102 Status422(models::HttpValidationError),
103 UnknownValue(serde_json::Value),
104}
105
106
107pub async fn agents_api_v1_agents_create(configuration: &configuration::Configuration, agent_creation_request: models::AgentCreationRequest) -> Result<models::Agent, Error<AgentsApiV1AgentsCreateError>> {
109 let p_body_agent_creation_request = agent_creation_request;
111
112 let uri_str = format!("{}/v1/agents", configuration.base_path);
113 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
114
115 if let Some(ref user_agent) = configuration.user_agent {
116 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
117 }
118 if let Some(ref token) = configuration.bearer_access_token {
119 req_builder = req_builder.bearer_auth(token.to_owned());
120 };
121 req_builder = req_builder.json(&p_body_agent_creation_request);
122
123 let req = req_builder.build()?;
124 let resp = configuration.client.execute(req).await?;
125
126 let status = resp.status();
127 let content_type = resp
128 .headers()
129 .get("content-type")
130 .and_then(|v| v.to_str().ok())
131 .unwrap_or("application/octet-stream");
132 let content_type = super::ContentType::from(content_type);
133
134 if !status.is_client_error() && !status.is_server_error() {
135 let content = resp.text().await?;
136 match content_type {
137 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
138 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Agent`"))),
139 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::Agent`")))),
140 }
141 } else {
142 let content = resp.text().await?;
143 let entity: Option<AgentsApiV1AgentsCreateError> = serde_json::from_str(&content).ok();
144 Err(Error::ResponseError(ResponseContent { status, content, entity }))
145 }
146}
147
148pub async fn agents_api_v1_agents_create_or_update_alias(configuration: &configuration::Configuration, agent_id: &str, alias: &str, version: i32) -> Result<models::AgentAliasResponse, Error<AgentsApiV1AgentsCreateOrUpdateAliasError>> {
150 let p_path_agent_id = agent_id;
152 let p_query_alias = alias;
153 let p_query_version = version;
154
155 let uri_str = format!("{}/v1/agents/{agent_id}/aliases", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
156 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
157
158 req_builder = req_builder.query(&[("alias", &p_query_alias.to_string())]);
159 req_builder = req_builder.query(&[("version", &p_query_version.to_string())]);
160 if let Some(ref user_agent) = configuration.user_agent {
161 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
162 }
163 if let Some(ref token) = configuration.bearer_access_token {
164 req_builder = req_builder.bearer_auth(token.to_owned());
165 };
166
167 let req = req_builder.build()?;
168 let resp = configuration.client.execute(req).await?;
169
170 let status = resp.status();
171 let content_type = resp
172 .headers()
173 .get("content-type")
174 .and_then(|v| v.to_str().ok())
175 .unwrap_or("application/octet-stream");
176 let content_type = super::ContentType::from(content_type);
177
178 if !status.is_client_error() && !status.is_server_error() {
179 let content = resp.text().await?;
180 match content_type {
181 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
182 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AgentAliasResponse`"))),
183 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::AgentAliasResponse`")))),
184 }
185 } else {
186 let content = resp.text().await?;
187 let entity: Option<AgentsApiV1AgentsCreateOrUpdateAliasError> = serde_json::from_str(&content).ok();
188 Err(Error::ResponseError(ResponseContent { status, content, entity }))
189 }
190}
191
192pub async fn agents_api_v1_agents_delete(configuration: &configuration::Configuration, agent_id: &str) -> Result<(), Error<AgentsApiV1AgentsDeleteError>> {
193 let p_path_agent_id = agent_id;
195
196 let uri_str = format!("{}/v1/agents/{agent_id}", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
197 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
198
199 if let Some(ref user_agent) = configuration.user_agent {
200 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
201 }
202 if let Some(ref token) = configuration.bearer_access_token {
203 req_builder = req_builder.bearer_auth(token.to_owned());
204 };
205
206 let req = req_builder.build()?;
207 let resp = configuration.client.execute(req).await?;
208
209 let status = resp.status();
210
211 if !status.is_client_error() && !status.is_server_error() {
212 Ok(())
213 } else {
214 let content = resp.text().await?;
215 let entity: Option<AgentsApiV1AgentsDeleteError> = serde_json::from_str(&content).ok();
216 Err(Error::ResponseError(ResponseContent { status, content, entity }))
217 }
218}
219
220pub async fn agents_api_v1_agents_delete_alias(configuration: &configuration::Configuration, agent_id: &str, alias: &str) -> Result<(), Error<AgentsApiV1AgentsDeleteAliasError>> {
222 let p_path_agent_id = agent_id;
224 let p_query_alias = alias;
225
226 let uri_str = format!("{}/v1/agents/{agent_id}/aliases", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
227 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
228
229 req_builder = req_builder.query(&[("alias", &p_query_alias.to_string())]);
230 if let Some(ref user_agent) = configuration.user_agent {
231 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
232 }
233 if let Some(ref token) = configuration.bearer_access_token {
234 req_builder = req_builder.bearer_auth(token.to_owned());
235 };
236
237 let req = req_builder.build()?;
238 let resp = configuration.client.execute(req).await?;
239
240 let status = resp.status();
241
242 if !status.is_client_error() && !status.is_server_error() {
243 Ok(())
244 } else {
245 let content = resp.text().await?;
246 let entity: Option<AgentsApiV1AgentsDeleteAliasError> = serde_json::from_str(&content).ok();
247 Err(Error::ResponseError(ResponseContent { status, content, entity }))
248 }
249}
250
251pub async fn agents_api_v1_agents_get(configuration: &configuration::Configuration, agent_id: &str, agent_version: Option<&str>) -> Result<models::Agent, Error<AgentsApiV1AgentsGetError>> {
253 let p_path_agent_id = agent_id;
255 let p_query_agent_version = agent_version;
256
257 let uri_str = format!("{}/v1/agents/{agent_id}", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
258 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
259
260 if let Some(ref param_value) = p_query_agent_version {
261 req_builder = req_builder.query(&[("agent_version", &serde_json::to_string(param_value)?)]);
262 }
263 if let Some(ref user_agent) = configuration.user_agent {
264 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
265 }
266 if let Some(ref token) = configuration.bearer_access_token {
267 req_builder = req_builder.bearer_auth(token.to_owned());
268 };
269
270 let req = req_builder.build()?;
271 let resp = configuration.client.execute(req).await?;
272
273 let status = resp.status();
274 let content_type = resp
275 .headers()
276 .get("content-type")
277 .and_then(|v| v.to_str().ok())
278 .unwrap_or("application/octet-stream");
279 let content_type = super::ContentType::from(content_type);
280
281 if !status.is_client_error() && !status.is_server_error() {
282 let content = resp.text().await?;
283 match content_type {
284 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
285 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Agent`"))),
286 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::Agent`")))),
287 }
288 } else {
289 let content = resp.text().await?;
290 let entity: Option<AgentsApiV1AgentsGetError> = serde_json::from_str(&content).ok();
291 Err(Error::ResponseError(ResponseContent { status, content, entity }))
292 }
293}
294
295pub async fn agents_api_v1_agents_get_version(configuration: &configuration::Configuration, agent_id: &str, version: &str) -> Result<models::Agent, Error<AgentsApiV1AgentsGetVersionError>> {
297 let p_path_agent_id = agent_id;
299 let p_path_version = version;
300
301 let uri_str = format!("{}/v1/agents/{agent_id}/versions/{version}", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id), version=crate::apis::urlencode(p_path_version));
302 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
303
304 if let Some(ref user_agent) = configuration.user_agent {
305 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
306 }
307 if let Some(ref token) = configuration.bearer_access_token {
308 req_builder = req_builder.bearer_auth(token.to_owned());
309 };
310
311 let req = req_builder.build()?;
312 let resp = configuration.client.execute(req).await?;
313
314 let status = resp.status();
315 let content_type = resp
316 .headers()
317 .get("content-type")
318 .and_then(|v| v.to_str().ok())
319 .unwrap_or("application/octet-stream");
320 let content_type = super::ContentType::from(content_type);
321
322 if !status.is_client_error() && !status.is_server_error() {
323 let content = resp.text().await?;
324 match content_type {
325 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
326 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Agent`"))),
327 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::Agent`")))),
328 }
329 } else {
330 let content = resp.text().await?;
331 let entity: Option<AgentsApiV1AgentsGetVersionError> = serde_json::from_str(&content).ok();
332 Err(Error::ResponseError(ResponseContent { status, content, entity }))
333 }
334}
335
336pub async fn agents_api_v1_agents_list(configuration: &configuration::Configuration, page: Option<i32>, page_size: Option<i32>, deployment_chat: Option<bool>, sources: Option<Vec<models::RequestSource>>, name: Option<&str>, search: Option<&str>, id: Option<&str>, metadata: Option<std::collections::HashMap<String, serde_json::Value>>) -> Result<Vec<models::Agent>, Error<AgentsApiV1AgentsListError>> {
338 let p_query_page = page;
340 let p_query_page_size = page_size;
341 let p_query_deployment_chat = deployment_chat;
342 let p_query_sources = sources;
343 let p_query_name = name;
344 let p_query_search = search;
345 let p_query_id = id;
346 let p_query_metadata = metadata;
347
348 let uri_str = format!("{}/v1/agents", configuration.base_path);
349 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
350
351 if let Some(ref param_value) = p_query_page {
352 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
353 }
354 if let Some(ref param_value) = p_query_page_size {
355 req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
356 }
357 if let Some(ref param_value) = p_query_deployment_chat {
358 req_builder = req_builder.query(&[("deployment_chat", ¶m_value.to_string())]);
359 }
360 if let Some(ref param_value) = p_query_sources {
361 req_builder = match "multi" {
362 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("sources".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
363 _ => req_builder.query(&[("sources", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
364 };
365 }
366 if let Some(ref param_value) = p_query_name {
367 req_builder = req_builder.query(&[("name", ¶m_value.to_string())]);
368 }
369 if let Some(ref param_value) = p_query_search {
370 req_builder = req_builder.query(&[("search", ¶m_value.to_string())]);
371 }
372 if let Some(ref param_value) = p_query_id {
373 req_builder = req_builder.query(&[("id", ¶m_value.to_string())]);
374 }
375 if let Some(ref param_value) = p_query_metadata {
376 req_builder = req_builder.query(&[("metadata", &serde_json::to_string(param_value)?)]);
377 }
378 if let Some(ref user_agent) = configuration.user_agent {
379 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
380 }
381 if let Some(ref token) = configuration.bearer_access_token {
382 req_builder = req_builder.bearer_auth(token.to_owned());
383 };
384
385 let req = req_builder.build()?;
386 let resp = configuration.client.execute(req).await?;
387
388 let status = resp.status();
389 let content_type = resp
390 .headers()
391 .get("content-type")
392 .and_then(|v| v.to_str().ok())
393 .unwrap_or("application/octet-stream");
394 let content_type = super::ContentType::from(content_type);
395
396 if !status.is_client_error() && !status.is_server_error() {
397 let content = resp.text().await?;
398 match content_type {
399 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
400 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Agent>`"))),
401 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Agent>`")))),
402 }
403 } else {
404 let content = resp.text().await?;
405 let entity: Option<AgentsApiV1AgentsListError> = serde_json::from_str(&content).ok();
406 Err(Error::ResponseError(ResponseContent { status, content, entity }))
407 }
408}
409
410pub async fn agents_api_v1_agents_list_version_aliases(configuration: &configuration::Configuration, agent_id: &str) -> Result<Vec<models::AgentAliasResponse>, Error<AgentsApiV1AgentsListVersionAliasesError>> {
412 let p_path_agent_id = agent_id;
414
415 let uri_str = format!("{}/v1/agents/{agent_id}/aliases", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
416 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
417
418 if let Some(ref user_agent) = configuration.user_agent {
419 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
420 }
421 if let Some(ref token) = configuration.bearer_access_token {
422 req_builder = req_builder.bearer_auth(token.to_owned());
423 };
424
425 let req = req_builder.build()?;
426 let resp = configuration.client.execute(req).await?;
427
428 let status = resp.status();
429 let content_type = resp
430 .headers()
431 .get("content-type")
432 .and_then(|v| v.to_str().ok())
433 .unwrap_or("application/octet-stream");
434 let content_type = super::ContentType::from(content_type);
435
436 if !status.is_client_error() && !status.is_server_error() {
437 let content = resp.text().await?;
438 match content_type {
439 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
440 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::AgentAliasResponse>`"))),
441 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::AgentAliasResponse>`")))),
442 }
443 } else {
444 let content = resp.text().await?;
445 let entity: Option<AgentsApiV1AgentsListVersionAliasesError> = serde_json::from_str(&content).ok();
446 Err(Error::ResponseError(ResponseContent { status, content, entity }))
447 }
448}
449
450pub async fn agents_api_v1_agents_list_versions(configuration: &configuration::Configuration, agent_id: &str, page: Option<i32>, page_size: Option<i32>) -> Result<Vec<models::Agent>, Error<AgentsApiV1AgentsListVersionsError>> {
452 let p_path_agent_id = agent_id;
454 let p_query_page = page;
455 let p_query_page_size = page_size;
456
457 let uri_str = format!("{}/v1/agents/{agent_id}/versions", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
458 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
459
460 if let Some(ref param_value) = p_query_page {
461 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
462 }
463 if let Some(ref param_value) = p_query_page_size {
464 req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
465 }
466 if let Some(ref user_agent) = configuration.user_agent {
467 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
468 }
469 if let Some(ref token) = configuration.bearer_access_token {
470 req_builder = req_builder.bearer_auth(token.to_owned());
471 };
472
473 let req = req_builder.build()?;
474 let resp = configuration.client.execute(req).await?;
475
476 let status = resp.status();
477 let content_type = resp
478 .headers()
479 .get("content-type")
480 .and_then(|v| v.to_str().ok())
481 .unwrap_or("application/octet-stream");
482 let content_type = super::ContentType::from(content_type);
483
484 if !status.is_client_error() && !status.is_server_error() {
485 let content = resp.text().await?;
486 match content_type {
487 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
488 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Agent>`"))),
489 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Agent>`")))),
490 }
491 } else {
492 let content = resp.text().await?;
493 let entity: Option<AgentsApiV1AgentsListVersionsError> = serde_json::from_str(&content).ok();
494 Err(Error::ResponseError(ResponseContent { status, content, entity }))
495 }
496}
497
498pub async fn agents_api_v1_agents_update(configuration: &configuration::Configuration, agent_id: &str, agent_update_request: models::AgentUpdateRequest) -> Result<models::Agent, Error<AgentsApiV1AgentsUpdateError>> {
500 let p_path_agent_id = agent_id;
502 let p_body_agent_update_request = agent_update_request;
503
504 let uri_str = format!("{}/v1/agents/{agent_id}", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
505 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
506
507 if let Some(ref user_agent) = configuration.user_agent {
508 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
509 }
510 if let Some(ref token) = configuration.bearer_access_token {
511 req_builder = req_builder.bearer_auth(token.to_owned());
512 };
513 req_builder = req_builder.json(&p_body_agent_update_request);
514
515 let req = req_builder.build()?;
516 let resp = configuration.client.execute(req).await?;
517
518 let status = resp.status();
519 let content_type = resp
520 .headers()
521 .get("content-type")
522 .and_then(|v| v.to_str().ok())
523 .unwrap_or("application/octet-stream");
524 let content_type = super::ContentType::from(content_type);
525
526 if !status.is_client_error() && !status.is_server_error() {
527 let content = resp.text().await?;
528 match content_type {
529 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
530 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Agent`"))),
531 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::Agent`")))),
532 }
533 } else {
534 let content = resp.text().await?;
535 let entity: Option<AgentsApiV1AgentsUpdateError> = serde_json::from_str(&content).ok();
536 Err(Error::ResponseError(ResponseContent { status, content, entity }))
537 }
538}
539
540pub async fn agents_api_v1_agents_update_version(configuration: &configuration::Configuration, agent_id: &str, version: i32) -> Result<models::Agent, Error<AgentsApiV1AgentsUpdateVersionError>> {
542 let p_path_agent_id = agent_id;
544 let p_query_version = version;
545
546 let uri_str = format!("{}/v1/agents/{agent_id}/version", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
547 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
548
549 req_builder = req_builder.query(&[("version", &p_query_version.to_string())]);
550 if let Some(ref user_agent) = configuration.user_agent {
551 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
552 }
553 if let Some(ref token) = configuration.bearer_access_token {
554 req_builder = req_builder.bearer_auth(token.to_owned());
555 };
556
557 let req = req_builder.build()?;
558 let resp = configuration.client.execute(req).await?;
559
560 let status = resp.status();
561 let content_type = resp
562 .headers()
563 .get("content-type")
564 .and_then(|v| v.to_str().ok())
565 .unwrap_or("application/octet-stream");
566 let content_type = super::ContentType::from(content_type);
567
568 if !status.is_client_error() && !status.is_server_error() {
569 let content = resp.text().await?;
570 match content_type {
571 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
572 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Agent`"))),
573 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::Agent`")))),
574 }
575 } else {
576 let content = resp.text().await?;
577 let entity: Option<AgentsApiV1AgentsUpdateVersionError> = serde_json::from_str(&content).ok();
578 Err(Error::ResponseError(ResponseContent { status, content, entity }))
579 }
580}
581