1#![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#[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#[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 #[serde(default, skip_serializing_if = "Option::is_none")]
35 pub cursor: Option<String>,
36}
37
38#[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#[derive(Debug, Clone)]
47pub struct TeamsApi {
48 pub(crate) client: Client,
49}
50
51impl Client {
52 pub fn teams(&self) -> TeamsApi {
54 TeamsApi { client: self.clone() }
55 }
56}
57
58impl TeamsApi {
59 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 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 #[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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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}