/*
* 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 [`post_a2a`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PostA2aError {
Status400(),
Status404(),
Status500(),
UnknownValue(serde_json::Value),
}
/// Communicate with an assistant using the Agent-to-Agent Protocol. Sends a JSON-RPC 2.0 message to the assistant. - **Request**: Provide an object with `jsonrpc`, `id`, `method`, and optional `params`. - **Response**: Returns a JSON-RPC response with task information or error. **Supported Methods:** - `message/send`: Send a message to the assistant - `tasks/get`: Get the status and result of a task **Notes:** - Supports threaded conversations via thread context - Messages can contain text and data parts - Tasks run asynchronously and return completion status
pub fn post_a2a_request_builder(
configuration: &configuration::Configuration,
assistant_id: &str,
accept: &str,
post_a2a_request: models::PostA2aRequest,
) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_assistant_id = assistant_id;
let p_header_accept = accept;
let p_body_post_a2a_request = post_a2a_request;
let uri_str = format!(
"{}/a2a/{assistant_id}",
configuration.base_path,
assistant_id = crate::apis::urlencode(p_path_assistant_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.header("Accept", p_header_accept.to_string());
req_builder = req_builder.json(&p_body_post_a2a_request);
Ok(req_builder)
}
pub async fn post_a2a(
configuration: &configuration::Configuration,
assistant_id: &str,
accept: &str,
post_a2a_request: models::PostA2aRequest,
) -> Result<models::PostA2a200Response, Error<PostA2aError>> {
let req_builder =
post_a2a_request_builder(configuration, assistant_id, accept, post_a2a_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 `models::PostA2a200Response`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::PostA2a200Response`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<PostA2aError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}