use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1AgentsCreateError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1AgentsCreateOrUpdateAliasError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1AgentsDeleteError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1AgentsDeleteAliasError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1AgentsGetError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1AgentsGetVersionError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1AgentsListError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1AgentsListVersionAliasesError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1AgentsListVersionsError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1AgentsUpdateError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1AgentsUpdateVersionError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
pub async fn agents_api_v1_agents_create(configuration: &configuration::Configuration, agent_creation_request: models::AgentCreationRequest) -> Result<models::Agent, Error<AgentsApiV1AgentsCreateError>> {
let p_body_agent_creation_request = agent_creation_request;
let uri_str = format!("{}/v1/agents", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_agent_creation_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Agent`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1AgentsCreateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub 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>> {
let p_path_agent_id = agent_id;
let p_query_alias = alias;
let p_query_version = version;
let uri_str = format!("{}/v1/agents/{agent_id}/aliases", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
req_builder = req_builder.query(&[("alias", &p_query_alias.to_string())]);
req_builder = req_builder.query(&[("version", &p_query_version.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AgentAliasResponse`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1AgentsCreateOrUpdateAliasError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_agents_delete(configuration: &configuration::Configuration, agent_id: &str) -> Result<(), Error<AgentsApiV1AgentsDeleteError>> {
let p_path_agent_id = agent_id;
let uri_str = format!("{}/v1/agents/{agent_id}", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1AgentsDeleteError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_agents_delete_alias(configuration: &configuration::Configuration, agent_id: &str, alias: &str) -> Result<(), Error<AgentsApiV1AgentsDeleteAliasError>> {
let p_path_agent_id = agent_id;
let p_query_alias = alias;
let uri_str = format!("{}/v1/agents/{agent_id}/aliases", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
req_builder = req_builder.query(&[("alias", &p_query_alias.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1AgentsDeleteAliasError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_agents_get(configuration: &configuration::Configuration, agent_id: &str, agent_version: Option<&str>) -> Result<models::Agent, Error<AgentsApiV1AgentsGetError>> {
let p_path_agent_id = agent_id;
let p_query_agent_version = agent_version;
let uri_str = format!("{}/v1/agents/{agent_id}", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_agent_version {
req_builder = req_builder.query(&[("agent_version", &serde_json::to_string(param_value)?)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Agent`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1AgentsGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_agents_get_version(configuration: &configuration::Configuration, agent_id: &str, version: &str) -> Result<models::Agent, Error<AgentsApiV1AgentsGetVersionError>> {
let p_path_agent_id = agent_id;
let p_path_version = version;
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));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Agent`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1AgentsGetVersionError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub 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>> {
let p_query_page = page;
let p_query_page_size = page_size;
let p_query_deployment_chat = deployment_chat;
let p_query_sources = sources;
let p_query_name = name;
let p_query_search = search;
let p_query_id = id;
let p_query_metadata = metadata;
let uri_str = format!("{}/v1/agents", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_page {
req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_page_size {
req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_deployment_chat {
req_builder = req_builder.query(&[("deployment_chat", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_sources {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("sources".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("sources", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_query_name {
req_builder = req_builder.query(&[("name", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_search {
req_builder = req_builder.query(&[("search", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_id {
req_builder = req_builder.query(&[("id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_metadata {
req_builder = req_builder.query(&[("metadata", &serde_json::to_string(param_value)?)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Agent>`"))),
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>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1AgentsListError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_agents_list_version_aliases(configuration: &configuration::Configuration, agent_id: &str) -> Result<Vec<models::AgentAliasResponse>, Error<AgentsApiV1AgentsListVersionAliasesError>> {
let p_path_agent_id = agent_id;
let uri_str = format!("{}/v1/agents/{agent_id}/aliases", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::AgentAliasResponse>`"))),
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>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1AgentsListVersionAliasesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub 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>> {
let p_path_agent_id = agent_id;
let p_query_page = page;
let p_query_page_size = page_size;
let uri_str = format!("{}/v1/agents/{agent_id}/versions", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_page {
req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_page_size {
req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Agent>`"))),
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>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1AgentsListVersionsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_agents_update(configuration: &configuration::Configuration, agent_id: &str, agent_update_request: models::AgentUpdateRequest) -> Result<models::Agent, Error<AgentsApiV1AgentsUpdateError>> {
let p_path_agent_id = agent_id;
let p_body_agent_update_request = agent_update_request;
let uri_str = format!("{}/v1/agents/{agent_id}", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_agent_update_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Agent`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1AgentsUpdateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_agents_update_version(configuration: &configuration::Configuration, agent_id: &str, version: i32) -> Result<models::Agent, Error<AgentsApiV1AgentsUpdateVersionError>> {
let p_path_agent_id = agent_id;
let p_query_version = version;
let uri_str = format!("{}/v1/agents/{agent_id}/version", configuration.base_path, agent_id=crate::apis::urlencode(p_path_agent_id));
let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
req_builder = req_builder.query(&[("version", &p_query_version.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Agent`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1AgentsUpdateVersionError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}