Skip to main content

uarp_sdk/generated/api/
a2a.rs

1// Code generated by @uarp/codegen from spec/openapi.json. DO NOT EDIT.
2//!
3//! Agent-to-Agent protocol: discovery and task execution
4
5#![allow(unused_imports, clippy::too_many_arguments)]
6
7use reqwest::Method;
8use serde::{Deserialize, Serialize};
9use futures_core::Stream;
10
11use crate::client::{Client, Request, NO_BODY, NO_QUERY};
12use crate::error::Result;
13use crate::generated::models;
14use crate::multipart::{field_text, FilePart};
15use crate::pagination::CursorGuard;
16use crate::sse::EventStream;
17use crate::util::encode_path;
18
19/// Query and header parameters for `getAgentCard`.
20#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
21pub struct GetAgentCardParams {
22    pub agent_id: String,
23}
24
25/// Query and header parameters for `listA2ATasks`.
26#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
27pub struct ListA2ATasksParams {
28    #[serde(default, skip_serializing_if = "Option::is_none")]
29    pub limit: Option<i64>,
30    #[serde(default, skip_serializing_if = "Option::is_none")]
31    pub cursor: Option<String>,
32}
33
34/// Agent-to-Agent protocol: discovery and task execution
35#[derive(Debug, Clone)]
36pub struct A2AApi {
37    pub(crate) client: Client,
38}
39
40impl Client {
41    /// Agent-to-Agent protocol: discovery and task execution
42    pub fn a2a(&self) -> A2AApi {
43        A2AApi { client: self.clone() }
44    }
45}
46
47impl A2AApi {
48    /// A2A JSON-RPC 2.0 endpoint
49    ///
50    /// Handles `tasks/send`, `tasks/sendSubscribe`, `tasks/get`, `tasks/cancel`,
51    /// `tasks/pushNotification/set`, `tasks/pushNotification/get` via JSON-RPC 2.0.
52    ///
53    /// **Scope dispatch is dynamic per JSON-RPC method**: read-style methods (`tasks/get`,
54    /// `tasks/pushNotification/get`) require `agents:read`; write-style (`tasks/send`,
55    /// `tasks/sendSubscribe`, `tasks/cancel`, `tasks/pushNotification/set`) require `agents:write`.
56    /// The static `bearerAuth: \[agents:write\]` declared here is the *strictest* scope; an
57    /// `agents:read`-only key works for the read methods but the spec cannot express the per-method
58    /// conditional.
59    ///
60    /// `POST /api/v1/a2a`
61    ///
62    /// Required scopes: `agents:write`.
63    pub async fn a2a_json_rpc(&self, body: &models::A2ajsonRpcRequest) -> Result<serde_json::Value> {
64        self.client
65            .request_json(Request {
66                method: Method::POST,
67                path: "/api/v1/a2a".to_string(),
68                query: NO_QUERY,
69                body: Some(body),
70                headers: Vec::new(),
71                idempotent: true,
72            })
73            .await
74    }
75
76    /// Cancel an A2A task
77    ///
78    /// `POST /api/v1/a2a/tasks/{taskId}/cancel`
79    ///
80    /// Required scopes: `agents:write`.
81    pub async fn cancel_a2a_task(&self, task_id: &str) -> Result<models::CancelA2ATaskResponse> {
82        self.client
83            .request_json(Request {
84                method: Method::POST,
85                path: format!("/api/v1/a2a/tasks/{}/cancel", encode_path(task_id)),
86                query: NO_QUERY,
87                body: NO_BODY,
88                headers: Vec::new(),
89                idempotent: true,
90            })
91            .await
92    }
93
94    /// Create an A2A task
95    ///
96    /// Creates a new agent-to-agent task and schedules the underlying run.
97    ///
98    /// `POST /api/v1/a2a/tasks`
99    ///
100    /// Required scopes: `agents:write`.
101    pub async fn create_a2a_task(&self, body: &models::CreateA2ATaskRequest) -> Result<models::A2ATask> {
102        self.client
103            .request_json(Request {
104                method: Method::POST,
105                path: "/api/v1/a2a/tasks".to_string(),
106                query: NO_QUERY,
107                body: Some(body),
108                headers: Vec::new(),
109                idempotent: true,
110            })
111            .await
112    }
113
114    /// Get A2A task status
115    ///
116    /// `GET /api/v1/a2a/tasks/{taskId}`
117    ///
118    /// Required scopes: `agents:read`.
119    pub async fn get_a2a_task(&self, task_id: &str) -> Result<models::A2ATask> {
120        self.client
121            .request_json(Request {
122                method: Method::GET,
123                path: format!("/api/v1/a2a/tasks/{}", encode_path(task_id)),
124                query: NO_QUERY,
125                body: NO_BODY,
126                headers: Vec::new(),
127                idempotent: false,
128            })
129            .await
130    }
131
132    /// Get A2A agent card for discovery
133    ///
134    /// `GET /.well-known/agent.json`
135    pub async fn get_agent_card(&self, params: &GetAgentCardParams) -> Result<serde_json::Value> {
136        self.client
137            .request_json(Request {
138                method: Method::GET,
139                path: "/.well-known/agent.json".to_string(),
140                query: Some(params),
141                body: NO_BODY,
142                headers: Vec::new(),
143                idempotent: false,
144            })
145            .await
146    }
147
148    /// List A2A tasks
149    ///
150    /// `GET /api/v1/a2a/tasks`
151    ///
152    /// Required scopes: `agents:read`.
153    pub async fn list_a2a_tasks(&self, params: &ListA2ATasksParams) -> Result<models::ListA2ATasksResponse> {
154        self.client
155            .request_json(Request {
156                method: Method::GET,
157                path: "/api/v1/a2a/tasks".to_string(),
158                query: Some(params),
159                body: NO_BODY,
160                headers: Vec::new(),
161                idempotent: false,
162            })
163            .await
164    }
165
166    /// Stream every item returned by `listA2ATasks`, following the `cursor` cursor until the server
167    /// reports no further pages.
168    pub fn list_a2a_tasks_all<'a>(&'a self, params: &'a ListA2ATasksParams) -> impl Stream<Item = Result<models::A2ATask>> + 'a {
169        async_stream::try_stream! {
170            let mut guard = CursorGuard::new();
171            let mut cursor = params.cursor.clone();
172            loop {
173                let mut page_params = params.clone();
174                page_params.cursor = cursor.clone();
175                let page = self.list_a2a_tasks(&page_params).await?;
176                let items = page.tasks;
177                let was_empty = items.is_empty();
178                for item in items {
179                    yield item;
180                }
181                match guard.advance(page.cursor, page.has_more, was_empty) {
182                    Some(next) => cursor = Some(next),
183                    None => break,
184                }
185            }
186        }
187    }
188
189    /// Stream A2A task status updates (SSE)
190    ///
191    /// `GET /api/v1/a2a/tasks/{taskId}/events`
192    ///
193    /// Required scopes: `agents:read`.
194    ///
195    /// Returns a server-sent event stream.
196    pub fn stream_a2a_task_events(&self, task_id: &str) -> EventStream {
197        self.client.request_stream(
198            &format!("/api/v1/a2a/tasks/{}/events", encode_path(task_id)),
199            NO_QUERY,
200            Vec::new(),
201        )
202    }
203}