Skip to main content

uarp_sdk/generated/api/
teams.rs

1// Code generated by @uarp/codegen from spec/openapi.json. DO NOT EDIT.
2//!
3//! Team management and team chat
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 `getTeamChatHistory`.
20#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
21pub struct GetTeamChatHistoryParams {
22    #[serde(default, skip_serializing_if = "Option::is_none")]
23    pub thread_id: Option<String>,
24    #[serde(default, skip_serializing_if = "Option::is_none")]
25    pub include_internal: Option<bool>,
26}
27
28/// Query and header parameters for `listTeamRuns`.
29#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
30pub struct ListTeamRunsParams {
31    #[serde(default, skip_serializing_if = "Option::is_none")]
32    pub limit: Option<i64>,
33    /// From a previous response's `cursor`.
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub cursor: Option<String>,
36}
37
38/// Query and header parameters for `streamTeamChatEvents`.
39#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
40pub struct StreamTeamChatEventsParams {
41    #[serde(default, skip_serializing_if = "Option::is_none")]
42    pub thread_id: Option<String>,
43}
44
45/// Team management and team chat
46#[derive(Debug, Clone)]
47pub struct TeamsApi {
48    pub(crate) client: Client,
49}
50
51impl Client {
52    /// Team management and team chat
53    pub fn teams(&self) -> TeamsApi {
54        TeamsApi { client: self.clone() }
55    }
56}
57
58impl TeamsApi {
59    /// Add graph edge
60    ///
61    /// `POST /api/v1/teams/{teamId}/graph/edges`
62    ///
63    /// Required scopes: `agents:write`.
64    pub async fn add_team_graph_edge(&self, team_id: &str, body: &models::AddTeamGraphEdgeRequest) -> Result<serde_json::Map<String, serde_json::Value>> {
65        self.client
66            .request_json(Request {
67                method: Method::POST,
68                path: format!("/api/v1/teams/{}/graph/edges", encode_path(team_id)),
69                query: NO_QUERY,
70                body: Some(body),
71                headers: Vec::new(),
72                idempotent: true,
73            })
74            .await
75    }
76
77    /// Add graph node
78    ///
79    /// `POST /api/v1/teams/{teamId}/graph/nodes`
80    ///
81    /// Required scopes: `agents:write`.
82    pub async fn add_team_graph_node(&self, team_id: &str, body: &models::AddTeamGraphNodeRequest) -> Result<serde_json::Map<String, serde_json::Value>> {
83        self.client
84            .request_json(Request {
85                method: Method::POST,
86                path: format!("/api/v1/teams/{}/graph/nodes", encode_path(team_id)),
87                query: NO_QUERY,
88                body: Some(body),
89                headers: Vec::new(),
90                idempotent: true,
91            })
92            .await
93    }
94
95    /// Cancel a team run
96    ///
97    /// Stops the orchestration loop first, then every non-terminal child run, and releases the chat
98    /// state so the canvas does not stay locked on a run that was just killed.
99    ///
100    /// Order matters and is not an implementation detail: killing children while the loop is still
101    /// running makes it spawn more — two fresh child runs were measured within two minutes of a
102    /// “successful” cancel.
103    ///
104    /// `cancelledCount` is camelCase on the wire, unlike every neighbouring field. That is what the
105    /// server sends.
106    ///
107    /// **Deprecated — use `/api/v1/squads/{squadId}/runs/{teamRunId}/cancel`.** The same handler
108    /// under the older noun.
109    ///
110    /// `POST /api/v1/teams/{teamId}/runs/{teamRunId}/cancel`
111    ///
112    /// Required scopes: `agents:write`.
113    #[deprecated]
114    pub async fn cancel_team_run(&self, team_id: &str, team_run_id: &str) -> Result<models::CancelTeamRunResponse> {
115        self.client
116            .request_json(Request {
117                method: Method::POST,
118                path: format!("/api/v1/teams/{}/runs/{}/cancel", encode_path(team_id), encode_path(team_run_id)),
119                query: NO_QUERY,
120                body: NO_BODY,
121                headers: Vec::new(),
122                idempotent: true,
123            })
124            .await
125    }
126
127    /// Create a team
128    ///
129    /// `POST /api/v1/teams`
130    ///
131    /// Required scopes: `agents:write`.
132    pub async fn create(&self, body: &models::TeamCreate) -> Result<models::Team> {
133        self.client
134            .request_json(Request {
135                method: Method::POST,
136                path: "/api/v1/teams".to_string(),
137                query: NO_QUERY,
138                body: Some(body),
139                headers: Vec::new(),
140                idempotent: true,
141            })
142            .await
143    }
144
145    /// Delete team
146    ///
147    /// `DELETE /api/v1/teams/{teamId}`
148    ///
149    /// Required scopes: `agents:write`.
150    pub async fn delete(&self, team_id: &str) -> Result<models::DeleteTeamResponse> {
151        self.client
152            .request_json(Request {
153                method: Method::DELETE,
154                path: format!("/api/v1/teams/{}", encode_path(team_id)),
155                query: NO_QUERY,
156                body: NO_BODY,
157                headers: Vec::new(),
158                idempotent: true,
159            })
160            .await
161    }
162
163    /// Remove edge
164    ///
165    /// `DELETE /api/v1/teams/{teamId}/graph/edges/{edgeId}`
166    ///
167    /// Required scopes: `agents:write`.
168    pub async fn delete_team_graph_edge(&self, team_id: &str, edge_id: &str) -> Result<models::DeleteTeamGraphEdgeResponse> {
169        self.client
170            .request_json(Request {
171                method: Method::DELETE,
172                path: format!("/api/v1/teams/{}/graph/edges/{}", encode_path(team_id), encode_path(edge_id)),
173                query: NO_QUERY,
174                body: NO_BODY,
175                headers: Vec::new(),
176                idempotent: true,
177            })
178            .await
179    }
180
181    /// Remove node
182    ///
183    /// `DELETE /api/v1/teams/{teamId}/graph/nodes/{agentId}`
184    ///
185    /// Required scopes: `agents:write`.
186    pub async fn delete_team_graph_node(&self, team_id: &str, agent_id: &str) -> Result<models::DeleteTeamGraphNodeResponse> {
187        self.client
188            .request_json(Request {
189                method: Method::DELETE,
190                path: format!("/api/v1/teams/{}/graph/nodes/{}", encode_path(team_id), encode_path(agent_id)),
191                query: NO_QUERY,
192                body: NO_BODY,
193                headers: Vec::new(),
194                idempotent: true,
195            })
196            .await
197    }
198
199    /// Get team
200    ///
201    /// `GET /api/v1/teams/{teamId}`
202    ///
203    /// Required scopes: `agents:read`.
204    pub async fn get(&self, team_id: &str) -> Result<models::Team> {
205        self.client
206            .request_json(Request {
207                method: Method::GET,
208                path: format!("/api/v1/teams/{}", encode_path(team_id)),
209                query: NO_QUERY,
210                body: NO_BODY,
211                headers: Vec::new(),
212                idempotent: false,
213            })
214            .await
215    }
216
217    /// Get team chat history
218    ///
219    /// `GET /api/v1/teams/{teamId}/chat`
220    ///
221    /// Required scopes: `agents:read`.
222    pub async fn get_team_chat_history(&self, team_id: &str, params: &GetTeamChatHistoryParams) -> Result<models::GetTeamChatHistoryResponse> {
223        self.client
224            .request_json(Request {
225                method: Method::GET,
226                path: format!("/api/v1/teams/{}/chat", encode_path(team_id)),
227                query: Some(params),
228                body: NO_BODY,
229                headers: Vec::new(),
230                idempotent: false,
231            })
232            .await
233    }
234
235    /// Get full team graph
236    ///
237    /// `GET /api/v1/teams/{teamId}/graph`
238    ///
239    /// Required scopes: `agents:read`.
240    pub async fn get_team_graph(&self, team_id: &str) -> Result<models::GetTeamGraphResponse> {
241        self.client
242            .request_json(Request {
243                method: Method::GET,
244                path: format!("/api/v1/teams/{}/graph", encode_path(team_id)),
245                query: NO_QUERY,
246                body: NO_BODY,
247                headers: Vec::new(),
248                idempotent: false,
249            })
250            .await
251    }
252
253    /// Get graph node
254    ///
255    /// `GET /api/v1/teams/{teamId}/graph/nodes/{agentId}`
256    ///
257    /// Required scopes: `agents:read`.
258    pub async fn get_team_graph_node(&self, team_id: &str, agent_id: &str) -> Result<models::TeamGraphNode> {
259        self.client
260            .request_json(Request {
261                method: Method::GET,
262                path: format!("/api/v1/teams/{}/graph/nodes/{}", encode_path(team_id), encode_path(agent_id)),
263                query: NO_QUERY,
264                body: NO_BODY,
265                headers: Vec::new(),
266                idempotent: false,
267            })
268            .await
269    }
270
271    /// Get specific team run
272    ///
273    /// `GET /api/v1/teams/{teamId}/runs/{teamRunId}`
274    ///
275    /// Required scopes: `agents:read`.
276    pub async fn get_team_run(&self, team_id: &str, team_run_id: &str) -> Result<models::TeamRunDetail> {
277        self.client
278            .request_json(Request {
279                method: Method::GET,
280                path: format!("/api/v1/teams/{}/runs/{}", encode_path(team_id), encode_path(team_run_id)),
281                query: NO_QUERY,
282                body: NO_BODY,
283                headers: Vec::new(),
284                idempotent: false,
285            })
286            .await
287    }
288
289    /// Get team run messages
290    ///
291    /// `GET /api/v1/teams/{teamId}/runs/{teamRunId}/messages`
292    ///
293    /// Required scopes: `agents:read`.
294    pub async fn get_team_run_messages(&self, team_id: &str, team_run_id: &str) -> Result<models::GetTeamRunMessagesResponse> {
295        self.client
296            .request_json(Request {
297                method: Method::GET,
298                path: format!("/api/v1/teams/{}/runs/{}/messages", encode_path(team_id), encode_path(team_run_id)),
299                query: NO_QUERY,
300                body: NO_BODY,
301                headers: Vec::new(),
302                idempotent: false,
303            })
304            .await
305    }
306
307    /// List teams
308    ///
309    /// `GET /api/v1/teams`
310    ///
311    /// Required scopes: `agents:read`.
312    pub async fn list(&self) -> Result<models::ListTeamsResponse> {
313        self.client
314            .request_json(Request {
315                method: Method::GET,
316                path: "/api/v1/teams".to_string(),
317                query: NO_QUERY,
318                body: NO_BODY,
319                headers: Vec::new(),
320                idempotent: false,
321            })
322            .await
323    }
324
325    /// List graph edges
326    ///
327    /// `GET /api/v1/teams/{teamId}/graph/edges`
328    ///
329    /// Required scopes: `agents:read`.
330    pub async fn list_team_graph_edges(&self, team_id: &str) -> Result<models::ListTeamGraphEdgesResponse> {
331        self.client
332            .request_json(Request {
333                method: Method::GET,
334                path: format!("/api/v1/teams/{}/graph/edges", encode_path(team_id)),
335                query: NO_QUERY,
336                body: NO_BODY,
337                headers: Vec::new(),
338                idempotent: false,
339            })
340            .await
341    }
342
343    /// List graph nodes
344    ///
345    /// `GET /api/v1/teams/{teamId}/graph/nodes`
346    ///
347    /// Required scopes: `agents:read`.
348    pub async fn list_team_graph_nodes(&self, team_id: &str) -> Result<models::ListTeamGraphNodesResponse> {
349        self.client
350            .request_json(Request {
351                method: Method::GET,
352                path: format!("/api/v1/teams/{}/graph/nodes", encode_path(team_id)),
353                query: NO_QUERY,
354                body: NO_BODY,
355                headers: Vec::new(),
356                idempotent: false,
357            })
358            .await
359    }
360
361    /// List runs for a team
362    ///
363    /// Ordered OLDEST FIRST, deliberately and unlike `/api/v1/runs`: a team run is a transcript and
364    /// reads forward. Stated here because the two endpoints differ and nothing in the schema said
365    /// so, which left clients to infer an order from the data they happened to receive.
366    ///
367    /// `limit` and `cursor` were undeclared, so a client generated from this document saw the first
368    /// fifty runs and had no way to page past them.
369    ///
370    /// `GET /api/v1/teams/{teamId}/runs`
371    ///
372    /// Required scopes: `agents:read`.
373    pub async fn list_team_runs(&self, team_id: &str, params: &ListTeamRunsParams) -> Result<models::ListTeamRunsResponse> {
374        self.client
375            .request_json(Request {
376                method: Method::GET,
377                path: format!("/api/v1/teams/{}/runs", encode_path(team_id)),
378                query: Some(params),
379                body: NO_BODY,
380                headers: Vec::new(),
381                idempotent: false,
382            })
383            .await
384    }
385
386    /// Stream every item returned by `listTeamRuns`, following the `cursor` cursor until the server
387    /// reports no further pages.
388    pub fn list_team_runs_all<'a>(&'a self, team_id: &'a str, params: &'a ListTeamRunsParams) -> impl Stream<Item = Result<models::TeamRunSummary>> + 'a {
389        async_stream::try_stream! {
390            let mut guard = CursorGuard::new();
391            let mut cursor = params.cursor.clone();
392            loop {
393                let mut page_params = params.clone();
394                page_params.cursor = cursor.clone();
395                let page = self.list_team_runs(team_id, &page_params).await?;
396                let items = page.runs.unwrap_or_default();
397                let was_empty = items.is_empty();
398                for item in items {
399                    yield item;
400                }
401                match guard.advance(page.cursor, page.has_more, was_empty) {
402                    Some(next) => cursor = Some(next),
403                    None => break,
404                }
405            }
406        }
407    }
408
409    /// Start a team run
410    ///
411    /// `POST /api/v1/teams/{teamId}/runs`
412    ///
413    /// Required scopes: `agents:write`.
414    pub async fn start_team_run(&self, team_id: &str, body: &models::StartTeamRunRequest) -> Result<models::StartTeamRunResponse> {
415        self.client
416            .request_json(Request {
417                method: Method::POST,
418                path: format!("/api/v1/teams/{}/runs", encode_path(team_id)),
419                query: NO_QUERY,
420                body: Some(body),
421                headers: Vec::new(),
422                idempotent: true,
423            })
424            .await
425    }
426
427    /// SSE stream for team chat
428    ///
429    /// `GET /api/v1/teams/{teamId}/chat/events`
430    ///
431    /// Required scopes: `agents:read`.
432    ///
433    /// Returns a server-sent event stream.
434    pub fn stream_team_chat_events(&self, team_id: &str, params: &StreamTeamChatEventsParams) -> EventStream {
435        self.client.request_stream(
436            &format!("/api/v1/teams/{}/chat/events", encode_path(team_id)),
437            Some(params),
438            Vec::new(),
439        )
440    }
441
442    /// Stream team run events (SSE)
443    ///
444    /// The path variable was named `runId` here while every sibling under this prefix — and the
445    /// handler, which reads `params.teamRunId` for this route too — calls it `teamRunId`. Same
446    /// value, two names, so a generated client offered both.
447    ///
448    /// `GET /api/v1/teams/{teamId}/runs/{teamRunId}/events`
449    ///
450    /// Required scopes: `agents:read`.
451    ///
452    /// Returns a server-sent event stream.
453    pub fn stream_team_run_events(&self, team_id: &str, team_run_id: &str) -> EventStream {
454        self.client.request_stream(
455            &format!("/api/v1/teams/{}/runs/{}/events", encode_path(team_id), encode_path(team_run_id)),
456            NO_QUERY,
457            Vec::new(),
458        )
459    }
460
461    /// Update team
462    ///
463    /// `PUT /api/v1/teams/{teamId}`
464    ///
465    /// Required scopes: `agents:write`.
466    pub async fn update(&self, team_id: &str, body: &models::TeamUpdate) -> Result<models::Team> {
467        self.client
468            .request_json(Request {
469                method: Method::PUT,
470                path: format!("/api/v1/teams/{}", encode_path(team_id)),
471                query: NO_QUERY,
472                body: Some(body),
473                headers: Vec::new(),
474                idempotent: true,
475            })
476            .await
477    }
478
479    /// Update graph node
480    ///
481    /// `PATCH /api/v1/teams/{teamId}/graph/nodes/{agentId}`
482    ///
483    /// Required scopes: `agents:write`.
484    pub async fn update_team_graph_node(&self, team_id: &str, agent_id: &str, body: &models::UpdateTeamGraphNodeRequest) -> Result<serde_json::Map<String, serde_json::Value>> {
485        self.client
486            .request_json(Request {
487                method: Method::PATCH,
488                path: format!("/api/v1/teams/{}/graph/nodes/{}", encode_path(team_id), encode_path(agent_id)),
489                query: NO_QUERY,
490                body: Some(body),
491                headers: Vec::new(),
492                idempotent: true,
493            })
494            .await
495    }
496}