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 AgentsApiV1ConversationsAppendError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1ConversationsAppendStreamError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1ConversationsDeleteError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1ConversationsGetError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1ConversationsHistoryError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1ConversationsListError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1ConversationsMessagesError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1ConversationsRestartError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1ConversationsRestartStreamError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1ConversationsStartError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AgentsApiV1ConversationsStartStreamError {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
pub async fn agents_api_v1_conversations_append(configuration: &configuration::Configuration, conversation_id: &str, conversation_append_request: models::ConversationAppendRequest) -> Result<models::ConversationResponse, Error<AgentsApiV1ConversationsAppendError>> {
let p_path_conversation_id = conversation_id;
let p_body_conversation_append_request = conversation_append_request;
let uri_str = format!("{}/v1/conversations/{conversation_id}", configuration.base_path, conversation_id=crate::apis::urlencode(p_path_conversation_id));
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_conversation_append_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::ConversationResponse`"))),
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::ConversationResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1ConversationsAppendError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_conversations_append_stream(configuration: &configuration::Configuration, conversation_id: &str, conversation_append_stream_request: models::ConversationAppendStreamRequest) -> Result<models::ConversationEvents, Error<AgentsApiV1ConversationsAppendStreamError>> {
let p_path_conversation_id = conversation_id;
let p_body_conversation_append_stream_request = conversation_append_stream_request;
let uri_str = format!("{}/v1/conversations/{conversation_id}#stream", configuration.base_path, conversation_id=crate::apis::urlencode(p_path_conversation_id));
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_conversation_append_stream_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::ConversationEvents`"))),
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::ConversationEvents`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1ConversationsAppendStreamError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_conversations_delete(configuration: &configuration::Configuration, conversation_id: &str) -> Result<(), Error<AgentsApiV1ConversationsDeleteError>> {
let p_path_conversation_id = conversation_id;
let uri_str = format!("{}/v1/conversations/{conversation_id}", configuration.base_path, conversation_id=crate::apis::urlencode(p_path_conversation_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<AgentsApiV1ConversationsDeleteError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_conversations_get(configuration: &configuration::Configuration, conversation_id: &str) -> Result<models::ResponseV1ConversationsGet, Error<AgentsApiV1ConversationsGetError>> {
let p_path_conversation_id = conversation_id;
let uri_str = format!("{}/v1/conversations/{conversation_id}", configuration.base_path, conversation_id=crate::apis::urlencode(p_path_conversation_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 `models::ResponseV1ConversationsGet`"))),
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::ResponseV1ConversationsGet`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1ConversationsGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_conversations_history(configuration: &configuration::Configuration, conversation_id: &str) -> Result<models::ConversationHistory, Error<AgentsApiV1ConversationsHistoryError>> {
let p_path_conversation_id = conversation_id;
let uri_str = format!("{}/v1/conversations/{conversation_id}/history", configuration.base_path, conversation_id=crate::apis::urlencode(p_path_conversation_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 `models::ConversationHistory`"))),
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::ConversationHistory`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1ConversationsHistoryError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_conversations_list(configuration: &configuration::Configuration, page: Option<i32>, page_size: Option<i32>, metadata: Option<std::collections::HashMap<String, serde_json::Value>>) -> Result<Vec<models::ResponseV1ConversationsListInner>, Error<AgentsApiV1ConversationsListError>> {
let p_query_page = page;
let p_query_page_size = page_size;
let p_query_metadata = metadata;
let uri_str = format!("{}/v1/conversations", 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_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::ResponseV1ConversationsListInner>`"))),
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::ResponseV1ConversationsListInner>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1ConversationsListError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_conversations_messages(configuration: &configuration::Configuration, conversation_id: &str) -> Result<models::ConversationMessages, Error<AgentsApiV1ConversationsMessagesError>> {
let p_path_conversation_id = conversation_id;
let uri_str = format!("{}/v1/conversations/{conversation_id}/messages", configuration.base_path, conversation_id=crate::apis::urlencode(p_path_conversation_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 `models::ConversationMessages`"))),
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::ConversationMessages`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1ConversationsMessagesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_conversations_restart(configuration: &configuration::Configuration, conversation_id: &str, conversation_restart_request: models::ConversationRestartRequest) -> Result<models::ConversationResponse, Error<AgentsApiV1ConversationsRestartError>> {
let p_path_conversation_id = conversation_id;
let p_body_conversation_restart_request = conversation_restart_request;
let uri_str = format!("{}/v1/conversations/{conversation_id}/restart", configuration.base_path, conversation_id=crate::apis::urlencode(p_path_conversation_id));
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_conversation_restart_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::ConversationResponse`"))),
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::ConversationResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1ConversationsRestartError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_conversations_restart_stream(configuration: &configuration::Configuration, conversation_id: &str, conversation_restart_stream_request: models::ConversationRestartStreamRequest) -> Result<models::ConversationEvents, Error<AgentsApiV1ConversationsRestartStreamError>> {
let p_path_conversation_id = conversation_id;
let p_body_conversation_restart_stream_request = conversation_restart_stream_request;
let uri_str = format!("{}/v1/conversations/{conversation_id}/restart#stream", configuration.base_path, conversation_id=crate::apis::urlencode(p_path_conversation_id));
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_conversation_restart_stream_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::ConversationEvents`"))),
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::ConversationEvents`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1ConversationsRestartStreamError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_conversations_start(configuration: &configuration::Configuration, conversation_request: models::ConversationRequest) -> Result<models::ConversationResponse, Error<AgentsApiV1ConversationsStartError>> {
let p_body_conversation_request = conversation_request;
let uri_str = format!("{}/v1/conversations", 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_conversation_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::ConversationResponse`"))),
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::ConversationResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1ConversationsStartError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn agents_api_v1_conversations_start_stream(configuration: &configuration::Configuration, conversation_stream_request: models::ConversationStreamRequest) -> Result<models::ConversationEvents, Error<AgentsApiV1ConversationsStartStreamError>> {
let p_body_conversation_stream_request = conversation_stream_request;
let uri_str = format!("{}/v1/conversations#stream", 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_conversation_stream_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::ConversationEvents`"))),
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::ConversationEvents`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AgentsApiV1ConversationsStartStreamError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}