langgraph-api 0.1.1

Rust Client API of LangGraph
Documentation
/*
 * LangSmith Deployment
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 0.1.0
 *
 * Generated by: https://openapi-generator.tech
 */

use super::{ContentType, Error, UploadFile, configuration};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};

/// struct for typed errors of method [`count_crons_runs_crons_count_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CountCronsRunsCronsCountPostError {
    Status404(String),
    Status422(String),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`create_cron_runs_crons_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateCronRunsCronsPostError {
    Status404(String),
    Status422(String),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`create_thread_cron_threads_thread_id_runs_crons_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateThreadCronThreadsThreadIdRunsCronsPostError {
    Status404(String),
    Status422(String),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`delete_cron_runs_crons_cron_id_delete`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteCronRunsCronsCronIdDeleteError {
    Status404(String),
    Status422(String),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`search_crons_runs_crons_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SearchCronsRunsCronsPostError {
    Status422(String),
    UnknownValue(serde_json::Value),
}

/// Get the count of crons matching the specified criteria.
pub fn count_crons_runs_crons_count_post_request_builder(
    configuration: &configuration::Configuration,
    cron_count_request: models::CronCountRequest,
) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body_cron_count_request = cron_count_request;

    let uri_str = format!("{}/runs/crons/count", 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());
    }
    req_builder = req_builder.json(&p_body_cron_count_request);

    Ok(req_builder)
}

pub async fn count_crons_runs_crons_count_post(
    configuration: &configuration::Configuration,
    cron_count_request: models::CronCountRequest,
) -> Result<i32, Error<CountCronsRunsCronsCountPostError>> {
    let req_builder =
        count_crons_runs_crons_count_post_request_builder(configuration, cron_count_request)
            .map_err(super::map_request_builder_error)?;
    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 => Err(Error::from(serde_json::Error::custom(
                "Received `text/plain` content type response that cannot be converted to `i32`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `i32`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<CountCronsRunsCronsCountPostError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Create a cron to schedule runs on new threads.
pub fn create_cron_runs_crons_post_request_builder(
    configuration: &configuration::Configuration,
    cron_create: models::CronCreate,
) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body_cron_create = cron_create;

    let uri_str = format!("{}/runs/crons", 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());
    }
    req_builder = req_builder.json(&p_body_cron_create);

    Ok(req_builder)
}

pub async fn create_cron_runs_crons_post(
    configuration: &configuration::Configuration,
    cron_create: models::CronCreate,
) -> Result<models::Cron, Error<CreateCronRunsCronsPostError>> {
    let req_builder = create_cron_runs_crons_post_request_builder(configuration, cron_create)
        .map_err(super::map_request_builder_error)?;
    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 => Err(Error::from(serde_json::Error::custom(
                "Received `text/plain` content type response that cannot be converted to `models::Cron`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::Cron`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<CreateCronRunsCronsPostError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Create a cron to schedule runs on a thread.
pub fn create_thread_cron_threads_thread_id_runs_crons_post_request_builder(
    configuration: &configuration::Configuration,
    thread_id: &str,
    thread_cron_create: models::ThreadCronCreate,
) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_thread_id = thread_id;
    let p_body_thread_cron_create = thread_cron_create;

    let uri_str = format!(
        "{}/threads/{thread_id}/runs/crons",
        configuration.base_path,
        thread_id = crate::apis::urlencode(p_path_thread_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());
    }
    req_builder = req_builder.json(&p_body_thread_cron_create);

    Ok(req_builder)
}

pub async fn create_thread_cron_threads_thread_id_runs_crons_post(
    configuration: &configuration::Configuration,
    thread_id: &str,
    thread_cron_create: models::ThreadCronCreate,
) -> Result<models::Cron, Error<CreateThreadCronThreadsThreadIdRunsCronsPostError>> {
    let req_builder = create_thread_cron_threads_thread_id_runs_crons_post_request_builder(
        configuration,
        thread_id,
        thread_cron_create,
    )
    .map_err(super::map_request_builder_error)?;
    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 => Err(Error::from(serde_json::Error::custom(
                "Received `text/plain` content type response that cannot be converted to `models::Cron`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::Cron`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<CreateThreadCronThreadsThreadIdRunsCronsPostError> =
            serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Delete a cron by ID.
pub fn delete_cron_runs_crons_cron_id_delete_request_builder(
    configuration: &configuration::Configuration,
    cron_id: &str,
) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_cron_id = cron_id;

    let uri_str = format!(
        "{}/runs/crons/{cron_id}",
        configuration.base_path,
        cron_id = crate::apis::urlencode(p_path_cron_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());
    }

    Ok(req_builder)
}

pub async fn delete_cron_runs_crons_cron_id_delete(
    configuration: &configuration::Configuration,
    cron_id: &str,
) -> Result<serde_json::Value, Error<DeleteCronRunsCronsCronIdDeleteError>> {
    let req_builder = delete_cron_runs_crons_cron_id_delete_request_builder(configuration, cron_id)
        .map_err(super::map_request_builder_error)?;
    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 => Err(Error::from(serde_json::Error::custom(
                "Received `text/plain` content type response that cannot be converted to `serde_json::Value`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<DeleteCronRunsCronsCronIdDeleteError> =
            serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Search all active crons
pub fn search_crons_runs_crons_post_request_builder(
    configuration: &configuration::Configuration,
    cron_search: models::CronSearch,
) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body_cron_search = cron_search;

    let uri_str = format!("{}/runs/crons/search", 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());
    }
    req_builder = req_builder.json(&p_body_cron_search);

    Ok(req_builder)
}

pub async fn search_crons_runs_crons_post(
    configuration: &configuration::Configuration,
    cron_search: models::CronSearch,
) -> Result<Vec<models::Cron>, Error<SearchCronsRunsCronsPostError>> {
    let req_builder = search_crons_runs_crons_post_request_builder(configuration, cron_search)
        .map_err(super::map_request_builder_error)?;
    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 => Err(Error::from(serde_json::Error::custom(
                "Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Cron&gt;`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::Cron&gt;`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<SearchCronsRunsCronsPostError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}