langgraph_api/generated/apis/
a2_a_api.rs

1/*
2 * LangSmith Deployment
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 0.1.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{ContentType, Error, UploadFile, configuration};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize, de::Error as _};
15
16/// struct for typed errors of method [`post_a2a`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum PostA2aError {
20    Status400(),
21    Status404(),
22    Status500(),
23    UnknownValue(serde_json::Value),
24}
25
26/// 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
27pub fn post_a2a_request_builder(
28    configuration: &configuration::Configuration,
29    assistant_id: &str,
30    accept: &str,
31    post_a2a_request: models::PostA2aRequest,
32) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
33    // add a prefix to parameters to efficiently prevent name collisions
34    let p_path_assistant_id = assistant_id;
35    let p_header_accept = accept;
36    let p_body_post_a2a_request = post_a2a_request;
37
38    let uri_str = format!(
39        "{}/a2a/{assistant_id}",
40        configuration.base_path,
41        assistant_id = crate::apis::urlencode(p_path_assistant_id)
42    );
43    let mut req_builder = configuration
44        .client
45        .request(reqwest::Method::POST, &uri_str);
46
47    if let Some(ref user_agent) = configuration.user_agent {
48        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
49    }
50    req_builder = req_builder.header("Accept", p_header_accept.to_string());
51    req_builder = req_builder.json(&p_body_post_a2a_request);
52
53    Ok(req_builder)
54}
55
56pub async fn post_a2a(
57    configuration: &configuration::Configuration,
58    assistant_id: &str,
59    accept: &str,
60    post_a2a_request: models::PostA2aRequest,
61) -> Result<models::PostA2a200Response, Error<PostA2aError>> {
62    let req_builder =
63        post_a2a_request_builder(configuration, assistant_id, accept, post_a2a_request)
64            .map_err(super::map_request_builder_error)?;
65    let req = req_builder.build()?;
66    let resp = configuration.client.execute(req).await?;
67
68    let status = resp.status();
69    let content_type = resp
70        .headers()
71        .get("content-type")
72        .and_then(|v| v.to_str().ok())
73        .unwrap_or("application/octet-stream");
74    let content_type = super::ContentType::from(content_type);
75
76    if !status.is_client_error() && !status.is_server_error() {
77        let content = resp.text().await?;
78        match content_type {
79            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
80            ContentType::Text => Err(Error::from(serde_json::Error::custom(
81                "Received `text/plain` content type response that cannot be converted to `models::PostA2a200Response`",
82            ))),
83            ContentType::Unsupported(unknown_type) => {
84                Err(Error::from(serde_json::Error::custom(format!(
85                    "Received `{unknown_type}` content type response that cannot be converted to `models::PostA2a200Response`"
86                ))))
87            }
88        }
89    } else {
90        let content = resp.text().await?;
91        let entity: Option<PostA2aError> = serde_json::from_str(&content).ok();
92        Err(Error::ResponseError(ResponseContent {
93            status,
94            content,
95            entity,
96        }))
97    }
98}