Skip to main content

uarp_sdk/generated/api/
bridge.rs

1// Code generated by @uarp/codegen from spec/openapi.json. DO NOT EDIT.
2//!
3//! Local agent bridge for Snaga desktop connections
4
5#![allow(unused_imports, clippy::too_many_arguments)]
6
7use reqwest::Method;
8use serde::{Deserialize, Serialize};
9
10use crate::client::{Client, Request, NO_BODY, NO_QUERY};
11use crate::error::Result;
12use crate::generated::models;
13use crate::multipart::{field_text, FilePart};
14use crate::util::encode_path;
15
16/// Query and header parameters for `bridgePoll`.
17#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
18pub struct BridgePollParams {
19    #[serde(default, skip_serializing_if = "Option::is_none")]
20    pub agent_id: Option<String>,
21    #[serde(default, skip_serializing_if = "Option::is_none")]
22    pub machine_id: Option<String>,
23    /// Server-side long-poll timeout override (ms).
24    #[serde(default, skip_serializing_if = "Option::is_none")]
25    pub timeout: Option<i64>,
26}
27
28/// Query and header parameters for `getBridgeTaskApproval`.
29#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
30pub struct GetBridgeTaskApprovalParams {
31    #[serde(default, skip_serializing_if = "Option::is_none")]
32    pub approval_id: Option<String>,
33}
34
35/// Local agent bridge for Snaga desktop connections
36#[derive(Debug, Clone)]
37pub struct BridgeApi {
38    pub(crate) client: Client,
39}
40
41impl Client {
42    /// Local agent bridge for Snaga desktop connections
43    pub fn bridge(&self) -> BridgeApi {
44        BridgeApi { client: self.clone() }
45    }
46}
47
48impl BridgeApi {
49    /// Delegate task to bridge agent
50    ///
51    /// `POST /api/v1/bridge/delegate`
52    pub async fn bridge_delegate(&self, body: &models::BridgeDelegateRequest) -> Result<models::BridgeDelegateResponse> {
53        self.client
54            .request_json(Request {
55                method: Method::POST,
56                path: "/api/v1/bridge/delegate".to_string(),
57                query: NO_QUERY,
58                body: Some(body),
59                headers: Vec::new(),
60                idempotent: true,
61            })
62            .await
63    }
64
65    /// Deregister bridge agent
66    ///
67    /// `POST /api/v1/bridge/deregister`
68    pub async fn bridge_deregister(&self, body: &models::BridgeDeregisterRequest) -> Result<models::BridgeDeregisterResponse> {
69        self.client
70            .request_json(Request {
71                method: Method::POST,
72                path: "/api/v1/bridge/deregister".to_string(),
73                query: NO_QUERY,
74                body: Some(body),
75                headers: Vec::new(),
76                idempotent: true,
77            })
78            .await
79    }
80
81    /// Bridge heartbeat
82    ///
83    /// Idempotent liveness ping for the bridge connection. **404 on missing connection is
84    /// intentional** — drives the client to re-register rather than reusing a stale identity.
85    ///
86    /// `POST /api/v1/bridge/heartbeat`
87    pub async fn bridge_heartbeat(&self, body: &models::BridgeHeartbeatRequest) -> Result<models::BridgeHeartbeatResponse> {
88        self.client
89            .request_json(Request {
90                method: Method::POST,
91                path: "/api/v1/bridge/heartbeat".to_string(),
92                query: NO_QUERY,
93                body: Some(body),
94                headers: Vec::new(),
95                idempotent: true,
96            })
97            .await
98    }
99
100    /// Long-poll for pending bridge tasks
101    ///
102    /// Long-poll up to platform-configured `POLL_TIMEOUT_MS`. Returns 200 with tasks if any are
103    /// pending, or 204 No Content on timeout (client should re-poll immediately).
104    ///
105    /// `GET /api/v1/bridge/poll`
106    pub async fn bridge_poll(&self, params: &BridgePollParams) -> Result<models::BridgePollResponse> {
107        self.client
108            .request_json(Request {
109                method: Method::GET,
110                path: "/api/v1/bridge/poll".to_string(),
111                query: Some(params),
112                body: NO_BODY,
113                headers: Vec::new(),
114                idempotent: false,
115            })
116            .await
117    }
118
119    /// Register bridge agent (Snaga CLI handshake)
120    ///
121    /// Registers a long-lived bridge agent for the calling tenant. Returns 201 on first
122    /// registration, 200 on reconnect of an existing machine_id. Tenant-scoped only — no scope
123    /// enforcement.
124    ///
125    /// `POST /api/v1/bridge/register`
126    pub async fn bridge_register(&self, body: &models::BridgeRegisterRequest) -> Result<models::BridgeRegisterResponse> {
127        self.client
128            .request_json(Request {
129                method: Method::POST,
130                path: "/api/v1/bridge/register".to_string(),
131                query: NO_QUERY,
132                body: Some(body),
133                headers: Vec::new(),
134                idempotent: true,
135            })
136            .await
137    }
138
139    /// Get bridge connection status
140    ///
141    /// `GET /api/v1/bridge/status`
142    pub async fn bridge_status(&self) -> Result<models::BridgeStatusResponse> {
143        self.client
144            .request_json(Request {
145                method: Method::GET,
146                path: "/api/v1/bridge/status".to_string(),
147                query: NO_QUERY,
148                body: NO_BODY,
149                headers: Vec::new(),
150                idempotent: false,
151            })
152            .await
153    }
154
155    /// Bridge WebSocket upgrade endpoint for the Snaga CLI
156    ///
157    /// WebSocket upgrade. Long-lived bidirectional channel between a `snaga serve` CLI and the
158    /// platform. Server delivers tasks, client streams capabilities and tool results. Auth via
159    /// `Sec-WebSocket-Protocol: uarp.\<base64(api_key)\>` subprotocol.
160    ///
161    /// `GET /api/v1/bridge/ws`
162    pub async fn bridge_web_socket(&self) -> Result<serde_json::Value> {
163        self.client
164            .request_json(Request {
165                method: Method::GET,
166                path: "/api/v1/bridge/ws".to_string(),
167                query: NO_QUERY,
168                body: NO_BODY,
169                headers: Vec::new(),
170                idempotent: false,
171            })
172            .await
173    }
174
175    /// Get approval status
176    ///
177    /// `GET /api/v1/bridge/tasks/{taskId}/approval`
178    pub async fn get_bridge_task_approval(&self, task_id: &str, params: &GetBridgeTaskApprovalParams) -> Result<models::GetBridgeTaskApprovalResponse> {
179        self.client
180            .request_json(Request {
181                method: Method::GET,
182                path: format!("/api/v1/bridge/tasks/{}/approval", encode_path(task_id)),
183                query: Some(params),
184                body: NO_BODY,
185                headers: Vec::new(),
186                idempotent: false,
187            })
188            .await
189    }
190
191    /// List bridge agents
192    ///
193    /// `GET /api/v1/bridge/agents`
194    pub async fn list_bridge_agents(&self) -> Result<Vec<models::BridgeAgentSummary>> {
195        self.client
196            .request_json(Request {
197                method: Method::GET,
198                path: "/api/v1/bridge/agents".to_string(),
199                query: NO_QUERY,
200                body: NO_BODY,
201                headers: Vec::new(),
202                idempotent: false,
203            })
204            .await
205    }
206
207    /// Push task events
208    ///
209    /// `POST /api/v1/bridge/tasks/{taskId}/events`
210    pub async fn push_bridge_task_events(&self, task_id: &str, body: &serde_json::Value) -> Result<models::PushBridgeTaskEventsResponse> {
211        self.client
212            .request_json(Request {
213                method: Method::POST,
214                path: format!("/api/v1/bridge/tasks/{}/events", encode_path(task_id)),
215                query: NO_QUERY,
216                body: Some(body),
217                headers: Vec::new(),
218                idempotent: true,
219            })
220            .await
221    }
222
223    /// Update agent capabilities
224    ///
225    /// `POST /api/v1/bridge/agents/{agentId}/capability`
226    pub async fn update_bridge_agent_capability(&self, agent_id: &str, body: &models::UpdateBridgeAgentCapabilityRequest) -> Result<models::UpdateBridgeAgentCapabilityResponse> {
227        self.client
228            .request_json(Request {
229                method: Method::POST,
230                path: format!("/api/v1/bridge/agents/{}/capability", encode_path(agent_id)),
231                query: NO_QUERY,
232                body: Some(body),
233                headers: Vec::new(),
234                idempotent: true,
235            })
236            .await
237    }
238}