Skip to main content

box_open_sdk/managers/
ai_studio.rs

1// Code generated by box-gantry. DO NOT EDIT.
2
3use crate::internal::path_escape;
4use crate::runtime::{self, Error};
5
6/// Optional parameters for [`AiStudioManager::list_ai_agents`].
7#[derive(Clone, Debug, Default)]
8pub struct AiStudioListAiAgentsOptions {
9    pub mode: Option<Vec<String>>,
10    pub fields: Option<Vec<String>>,
11    pub agent_state: Option<Vec<String>>,
12    pub include_box_default: Option<bool>,
13    pub marker: Option<String>,
14    pub limit: Option<i64>,
15}
16
17/// Optional parameters for [`AiStudioManager::get_ai_agent`].
18#[derive(Clone, Debug, Default)]
19pub struct AiStudioGetAiAgentOptions {
20    pub fields: Option<Vec<String>>,
21}
22
23/// Async paginator over [`AiStudioManager::list_ai_agents`], yielding one `crate::models::schemas::AiSingleAgentResponseFull`
24/// per item across pages (FR-7.3).
25pub struct AiStudioListAiAgentsPaginator {
26    manager: AiStudioManager,
27    options: AiStudioListAiAgentsOptions,
28    buffer: std::vec::IntoIter<crate::models::schemas::AiSingleAgentResponseFull>,
29    done: bool,
30}
31
32impl AiStudioListAiAgentsPaginator {
33    /// The next item, advancing pages as needed; `None` at the end.
34    /// An error is yielded once, then iteration stops.
35    pub async fn next(
36        &mut self,
37    ) -> Option<Result<crate::models::schemas::AiSingleAgentResponseFull, Error>> {
38        loop {
39            if let Some(item) = self.buffer.next() {
40                return Some(Ok(item));
41            }
42            if self.done {
43                return None;
44            }
45            let page = match self
46                .manager
47                .list_ai_agents_page(Some(self.options.clone()))
48                .await
49            {
50                Ok(page) => page,
51                Err(err) => {
52                    self.done = true;
53                    return Some(Err(err));
54                }
55            };
56            self.buffer = page.entries.into_iter();
57            match page.next_marker.flatten() {
58                Some(cursor) if !cursor.is_empty() => self.options.marker = Some(cursor),
59                _ => self.done = true,
60            }
61        }
62    }
63}
64
65/// Operations for the "ai_studio" API area.
66pub struct AiStudioManager {
67    session: std::sync::Arc<runtime::Client>,
68}
69
70impl AiStudioManager {
71    pub(crate) fn new(session: std::sync::Arc<runtime::Client>) -> Self {
72        Self { session }
73    }
74
75    async fn list_ai_agents_page(
76        &self,
77        opts: Option<AiStudioListAiAgentsOptions>,
78    ) -> Result<crate::models::schemas::AiMultipleAgentResponse, Error> {
79        let mut url = self.session.base_url("api");
80        url.push_str("/ai_agents");
81        let mut req = self.session.new_request("GET", &url);
82        let opts = opts.unwrap_or_default();
83        if let Some(value) = opts.mode {
84            req = runtime::with_query(req, "mode", &value.join(","));
85        }
86        if let Some(value) = opts.fields {
87            req = runtime::with_query(req, "fields", &value.join(","));
88        }
89        if let Some(value) = opts.agent_state {
90            req = runtime::with_query(req, "agent_state", &value.join(","));
91        }
92        if let Some(value) = opts.include_box_default {
93            req = runtime::with_query(req, "include_box_default", &value.to_string());
94        }
95        if let Some(value) = opts.marker {
96            req = runtime::with_query(req, "marker", &value);
97        }
98        if let Some(value) = opts.limit {
99            req = runtime::with_query(req, "limit", &value.to_string());
100        }
101        let resp = self.session.fetch(req).await?;
102        let data = runtime::response_bytes(&resp)?;
103        Ok(serde_json::from_slice(&data)?)
104    }
105
106    /// Iterate every `crate::models::schemas::AiSingleAgentResponseFull` across pages, threading the cursor.
107    pub fn list_ai_agents(
108        &self,
109        opts: Option<AiStudioListAiAgentsOptions>,
110    ) -> AiStudioListAiAgentsPaginator {
111        AiStudioListAiAgentsPaginator {
112            manager: AiStudioManager::new(self.session.clone()),
113            options: opts.unwrap_or_default(),
114            buffer: Vec::new().into_iter(),
115            done: false,
116        }
117    }
118
119    pub async fn create_ai_agents(
120        &self,
121        body: crate::models::schemas::CreateAiAgent,
122    ) -> Result<crate::models::schemas::AiSingleAgentResponseFull, Error> {
123        let mut url = self.session.base_url("api");
124        url.push_str("/ai_agents");
125        let mut req = self.session.new_request("POST", &url);
126        let payload = serde_json::to_vec(&body)?;
127        req = runtime::with_json_body(req, &payload);
128        let resp = self.session.fetch(req).await?;
129        let data = runtime::response_bytes(&resp)?;
130        Ok(serde_json::from_slice(&data)?)
131    }
132
133    pub async fn get_ai_agent(
134        &self,
135        agent_id: String,
136        opts: Option<AiStudioGetAiAgentOptions>,
137    ) -> Result<crate::models::schemas::AiSingleAgentResponseFull, Error> {
138        let mut url = self.session.base_url("api");
139        url.push_str("/ai_agents");
140        url.push('/');
141        let seg = path_escape(&agent_id);
142        url.push_str(&seg);
143        let mut req = self.session.new_request("GET", &url);
144        let opts = opts.unwrap_or_default();
145        if let Some(value) = opts.fields {
146            req = runtime::with_query(req, "fields", &value.join(","));
147        }
148        let resp = self.session.fetch(req).await?;
149        let data = runtime::response_bytes(&resp)?;
150        Ok(serde_json::from_slice(&data)?)
151    }
152
153    pub async fn update_ai_agent(
154        &self,
155        agent_id: String,
156        body: crate::models::schemas::CreateAiAgent,
157    ) -> Result<crate::models::schemas::AiSingleAgentResponseFull, Error> {
158        let mut url = self.session.base_url("api");
159        url.push_str("/ai_agents");
160        url.push('/');
161        let seg = path_escape(&agent_id);
162        url.push_str(&seg);
163        let mut req = self.session.new_request("PUT", &url);
164        let payload = serde_json::to_vec(&body)?;
165        req = runtime::with_json_body(req, &payload);
166        let resp = self.session.fetch(req).await?;
167        let data = runtime::response_bytes(&resp)?;
168        Ok(serde_json::from_slice(&data)?)
169    }
170
171    pub async fn delete_ai_agent(&self, agent_id: String) -> Result<(), Error> {
172        let mut url = self.session.base_url("api");
173        url.push_str("/ai_agents");
174        url.push('/');
175        let seg = path_escape(&agent_id);
176        url.push_str(&seg);
177        let req = self.session.new_request("DELETE", &url);
178        let _ = self.session.fetch(req).await?;
179        Ok(())
180    }
181}