Skip to main content

windmill_api/apis/
ai_api.rs

1/*
2 * Windmill API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.853.1
7 * Contact: contact@windmill.dev
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`complete_ai`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CompleteAiError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_ai_artifact_share_status`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetAiArtifactShareStatusError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_ai_session_share_status`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetAiSessionShareStatusError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_shared_ai_artifact`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetSharedAiArtifactError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_shared_ai_session`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetSharedAiSessionError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`list_ai_session_backups`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum ListAiSessionBackupsError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`list_ai_usage`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum ListAiUsageError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`pull_ai_session_backups`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum PullAiSessionBackupsError {
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`push_ai_session_backups`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum PushAiSessionBackupsError {
78    UnknownValue(serde_json::Value),
79}
80
81/// struct for typed errors of method [`record_ai_usage`]
82#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum RecordAiUsageError {
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`set_ai_session_share_public`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum SetAiSessionSharePublicError {
92    UnknownValue(serde_json::Value),
93}
94
95/// struct for typed errors of method [`share_ai_artifact`]
96#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(untagged)]
98pub enum ShareAiArtifactError {
99    UnknownValue(serde_json::Value),
100}
101
102/// struct for typed errors of method [`share_ai_session`]
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(untagged)]
105pub enum ShareAiSessionError {
106    UnknownValue(serde_json::Value),
107}
108
109/// struct for typed errors of method [`unshare_ai_artifact`]
110#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum UnshareAiArtifactError {
113    UnknownValue(serde_json::Value),
114}
115
116/// struct for typed errors of method [`unshare_ai_session`]
117#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(untagged)]
119pub enum UnshareAiSessionError {
120    UnknownValue(serde_json::Value),
121}
122
123
124/// Sends a system and a user message to the configured provider and returns the text of the answer, with no tools and no streaming. For callers that do not speak a provider's own API through the proxy, such as the CLI and jobs. 
125pub async fn complete_ai(configuration: &configuration::Configuration, workspace: &str, complete_ai_request: models::CompleteAiRequest) -> Result<models::CompleteAi200Response, Error<CompleteAiError>> {
126    let local_var_configuration = configuration;
127
128    let local_var_client = &local_var_configuration.client;
129
130    let local_var_uri_str = format!("{}/w/{workspace}/ai/complete", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
131    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
132
133    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
134        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
135    }
136    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
137        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
138    };
139    local_var_req_builder = local_var_req_builder.json(&complete_ai_request);
140
141    let local_var_req = local_var_req_builder.build()?;
142    let local_var_resp = local_var_client.execute(local_var_req).await?;
143
144    let local_var_status = local_var_resp.status();
145    let local_var_content = local_var_resp.text().await?;
146
147    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
148        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
149    } else {
150        let local_var_entity: Option<CompleteAiError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
151        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
152        Err(Error::ResponseError(local_var_error))
153    }
154}
155
156pub async fn get_ai_artifact_share_status(configuration: &configuration::Configuration, workspace: &str, artifact_id: &str) -> Result<models::GetAiArtifactShareStatus200Response, Error<GetAiArtifactShareStatusError>> {
157    let local_var_configuration = configuration;
158
159    let local_var_client = &local_var_configuration.client;
160
161    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_artifacts/status", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
162    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
163
164    local_var_req_builder = local_var_req_builder.query(&[("artifact_id", &artifact_id.to_string())]);
165    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
166        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
167    }
168    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
169        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
170    };
171
172    let local_var_req = local_var_req_builder.build()?;
173    let local_var_resp = local_var_client.execute(local_var_req).await?;
174
175    let local_var_status = local_var_resp.status();
176    let local_var_content = local_var_resp.text().await?;
177
178    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
179        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
180    } else {
181        let local_var_entity: Option<GetAiArtifactShareStatusError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
182        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
183        Err(Error::ResponseError(local_var_error))
184    }
185}
186
187pub async fn get_ai_session_share_status(configuration: &configuration::Configuration, workspace: &str, session_id: &str) -> Result<models::GetAiSessionShareStatus200Response, Error<GetAiSessionShareStatusError>> {
188    let local_var_configuration = configuration;
189
190    let local_var_client = &local_var_configuration.client;
191
192    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_sessions/status", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
193    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
194
195    local_var_req_builder = local_var_req_builder.query(&[("session_id", &session_id.to_string())]);
196    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
197        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
198    }
199    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
200        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
201    };
202
203    let local_var_req = local_var_req_builder.build()?;
204    let local_var_resp = local_var_client.execute(local_var_req).await?;
205
206    let local_var_status = local_var_resp.status();
207    let local_var_content = local_var_resp.text().await?;
208
209    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
210        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
211    } else {
212        let local_var_entity: Option<GetAiSessionShareStatusError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
213        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
214        Err(Error::ResponseError(local_var_error))
215    }
216}
217
218pub async fn get_shared_ai_artifact(configuration: &configuration::Configuration, workspace: &str, id: &str) -> Result<models::GetSharedAiArtifact200Response, Error<GetSharedAiArtifactError>> {
219    let local_var_configuration = configuration;
220
221    let local_var_client = &local_var_configuration.client;
222
223    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_artifacts/get/{id}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), id=crate::apis::urlencode(id));
224    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
225
226    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
227        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
228    }
229    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
230        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
231    };
232
233    let local_var_req = local_var_req_builder.build()?;
234    let local_var_resp = local_var_client.execute(local_var_req).await?;
235
236    let local_var_status = local_var_resp.status();
237    let local_var_content = local_var_resp.text().await?;
238
239    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
240        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
241    } else {
242        let local_var_entity: Option<GetSharedAiArtifactError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
243        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
244        Err(Error::ResponseError(local_var_error))
245    }
246}
247
248/// A public share is served without authentication; any other one only to a member of the workspace. 
249pub async fn get_shared_ai_session(configuration: &configuration::Configuration, workspace: &str, id: &str) -> Result<models::GetSharedAiSession200Response, Error<GetSharedAiSessionError>> {
250    let local_var_configuration = configuration;
251
252    let local_var_client = &local_var_configuration.client;
253
254    let local_var_uri_str = format!("{}/w/{workspace}/ai_u/shared_sessions/get/{id}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), id=crate::apis::urlencode(id));
255    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
256
257    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
258        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
259    }
260    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
261        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
262    };
263
264    let local_var_req = local_var_req_builder.build()?;
265    let local_var_resp = local_var_client.execute(local_var_req).await?;
266
267    let local_var_status = local_var_resp.status();
268    let local_var_content = local_var_resp.text().await?;
269
270    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
271        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
272    } else {
273        let local_var_entity: Option<GetSharedAiSessionError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
274        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
275        Err(Error::ResponseError(local_var_error))
276    }
277}
278
279pub async fn list_ai_session_backups(configuration: &configuration::Configuration, workspace: &str) -> Result<models::ListAiSessionBackups200Response, Error<ListAiSessionBackupsError>> {
280    let local_var_configuration = configuration;
281
282    let local_var_client = &local_var_configuration.client;
283
284    let local_var_uri_str = format!("{}/w/{workspace}/ai/sessions/list", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
285    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
286
287    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
288        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
289    }
290    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
291        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
292    };
293
294    let local_var_req = local_var_req_builder.build()?;
295    let local_var_resp = local_var_client.execute(local_var_req).await?;
296
297    let local_var_status = local_var_resp.status();
298    let local_var_content = local_var_resp.text().await?;
299
300    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
301        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
302    } else {
303        let local_var_entity: Option<ListAiSessionBackupsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
304        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
305        Err(Error::ResponseError(local_var_error))
306    }
307}
308
309pub async fn list_ai_usage(configuration: &configuration::Configuration, workspace: &str, days: Option<i32>, group_by: Option<&str>, scope: Option<&str>) -> Result<models::ListAiUsage200Response, Error<ListAiUsageError>> {
310    let local_var_configuration = configuration;
311
312    let local_var_client = &local_var_configuration.client;
313
314    let local_var_uri_str = format!("{}/w/{workspace}/ai/usage", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
315    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
316
317    if let Some(ref local_var_str) = days {
318        local_var_req_builder = local_var_req_builder.query(&[("days", &local_var_str.to_string())]);
319    }
320    if let Some(ref local_var_str) = group_by {
321        local_var_req_builder = local_var_req_builder.query(&[("group_by", &local_var_str.to_string())]);
322    }
323    if let Some(ref local_var_str) = scope {
324        local_var_req_builder = local_var_req_builder.query(&[("scope", &local_var_str.to_string())]);
325    }
326    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
327        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
328    }
329    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
330        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
331    };
332
333    let local_var_req = local_var_req_builder.build()?;
334    let local_var_resp = local_var_client.execute(local_var_req).await?;
335
336    let local_var_status = local_var_resp.status();
337    let local_var_content = local_var_resp.text().await?;
338
339    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
340        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
341    } else {
342        let local_var_entity: Option<ListAiUsageError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
343        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
344        Err(Error::ResponseError(local_var_error))
345    }
346}
347
348pub async fn pull_ai_session_backups(configuration: &configuration::Configuration, workspace: &str, pull_ai_session_backups_request: models::PullAiSessionBackupsRequest) -> Result<models::PullAiSessionBackups200Response, Error<PullAiSessionBackupsError>> {
349    let local_var_configuration = configuration;
350
351    let local_var_client = &local_var_configuration.client;
352
353    let local_var_uri_str = format!("{}/w/{workspace}/ai/sessions/pull", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
354    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
355
356    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
357        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
358    }
359    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
360        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
361    };
362    local_var_req_builder = local_var_req_builder.json(&pull_ai_session_backups_request);
363
364    let local_var_req = local_var_req_builder.build()?;
365    let local_var_resp = local_var_client.execute(local_var_req).await?;
366
367    let local_var_status = local_var_resp.status();
368    let local_var_content = local_var_resp.text().await?;
369
370    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
371        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
372    } else {
373        let local_var_entity: Option<PullAiSessionBackupsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
374        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
375        Err(Error::ResponseError(local_var_error))
376    }
377}
378
379pub async fn push_ai_session_backups(configuration: &configuration::Configuration, workspace: &str, push_ai_session_backups_request: models::PushAiSessionBackupsRequest) -> Result<models::PushAiSessionBackups200Response, Error<PushAiSessionBackupsError>> {
380    let local_var_configuration = configuration;
381
382    let local_var_client = &local_var_configuration.client;
383
384    let local_var_uri_str = format!("{}/w/{workspace}/ai/sessions/push", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
385    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
386
387    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
388        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
389    }
390    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
391        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
392    };
393    local_var_req_builder = local_var_req_builder.json(&push_ai_session_backups_request);
394
395    let local_var_req = local_var_req_builder.build()?;
396    let local_var_resp = local_var_client.execute(local_var_req).await?;
397
398    let local_var_status = local_var_resp.status();
399    let local_var_content = local_var_resp.text().await?;
400
401    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
402        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
403    } else {
404        let local_var_entity: Option<PushAiSessionBackupsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
405        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
406        Err(Error::ResponseError(local_var_error))
407    }
408}
409
410pub async fn record_ai_usage(configuration: &configuration::Configuration, workspace: &str, record_ai_usage_request: models::RecordAiUsageRequest) -> Result<(), Error<RecordAiUsageError>> {
411    let local_var_configuration = configuration;
412
413    let local_var_client = &local_var_configuration.client;
414
415    let local_var_uri_str = format!("{}/w/{workspace}/ai/usage", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
416    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
417
418    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
419        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
420    }
421    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
422        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
423    };
424    local_var_req_builder = local_var_req_builder.json(&record_ai_usage_request);
425
426    let local_var_req = local_var_req_builder.build()?;
427    let local_var_resp = local_var_client.execute(local_var_req).await?;
428
429    let local_var_status = local_var_resp.status();
430    let local_var_content = local_var_resp.text().await?;
431
432    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
433        Ok(())
434    } else {
435        let local_var_entity: Option<RecordAiUsageError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
436        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
437        Err(Error::ResponseError(local_var_error))
438    }
439}
440
441pub async fn set_ai_session_share_public(configuration: &configuration::Configuration, workspace: &str, id: &str, set_ai_session_share_public_request: models::SetAiSessionSharePublicRequest) -> Result<models::SharedAiSessionInfo, Error<SetAiSessionSharePublicError>> {
442    let local_var_configuration = configuration;
443
444    let local_var_client = &local_var_configuration.client;
445
446    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_sessions/set_public/{id}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), id=crate::apis::urlencode(id));
447    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
448
449    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
450        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
451    }
452    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
453        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
454    };
455    local_var_req_builder = local_var_req_builder.json(&set_ai_session_share_public_request);
456
457    let local_var_req = local_var_req_builder.build()?;
458    let local_var_resp = local_var_client.execute(local_var_req).await?;
459
460    let local_var_status = local_var_resp.status();
461    let local_var_content = local_var_resp.text().await?;
462
463    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
464        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
465    } else {
466        let local_var_entity: Option<SetAiSessionSharePublicError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
467        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
468        Err(Error::ResponseError(local_var_error))
469    }
470}
471
472/// Stores a read-only copy that any member of the workspace can open by id. Sharing the same artifact again updates that copy, keeps its id, and restarts its retention window. 
473pub async fn share_ai_artifact(configuration: &configuration::Configuration, workspace: &str, share_ai_artifact_request: models::ShareAiArtifactRequest) -> Result<models::SharedAiArtifactInfo, Error<ShareAiArtifactError>> {
474    let local_var_configuration = configuration;
475
476    let local_var_client = &local_var_configuration.client;
477
478    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_artifacts/share", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
479    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
480
481    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
482        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
483    }
484    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
485        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
486    };
487    local_var_req_builder = local_var_req_builder.json(&share_ai_artifact_request);
488
489    let local_var_req = local_var_req_builder.build()?;
490    let local_var_resp = local_var_client.execute(local_var_req).await?;
491
492    let local_var_status = local_var_resp.status();
493    let local_var_content = local_var_resp.text().await?;
494
495    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
496        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
497    } else {
498        let local_var_entity: Option<ShareAiArtifactError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
499        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
500        Err(Error::ResponseError(local_var_error))
501    }
502}
503
504/// Stores a read-only snapshot of the session that members of the workspace can open by id, or anyone with the link once it is public. Sharing the same session again updates that snapshot and keeps its id. 
505pub async fn share_ai_session(configuration: &configuration::Configuration, workspace: &str, share_ai_session_request: models::ShareAiSessionRequest) -> Result<models::SharedAiSessionInfo, Error<ShareAiSessionError>> {
506    let local_var_configuration = configuration;
507
508    let local_var_client = &local_var_configuration.client;
509
510    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_sessions/share", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
511    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
512
513    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
514        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
515    }
516    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
517        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
518    };
519    local_var_req_builder = local_var_req_builder.json(&share_ai_session_request);
520
521    let local_var_req = local_var_req_builder.build()?;
522    let local_var_resp = local_var_client.execute(local_var_req).await?;
523
524    let local_var_status = local_var_resp.status();
525    let local_var_content = local_var_resp.text().await?;
526
527    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
528        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
529    } else {
530        let local_var_entity: Option<ShareAiSessionError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
531        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
532        Err(Error::ResponseError(local_var_error))
533    }
534}
535
536pub async fn unshare_ai_artifact(configuration: &configuration::Configuration, workspace: &str, id: &str) -> Result<String, Error<UnshareAiArtifactError>> {
537    let local_var_configuration = configuration;
538
539    let local_var_client = &local_var_configuration.client;
540
541    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_artifacts/delete/{id}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), id=crate::apis::urlencode(id));
542    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
543
544    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
545        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
546    }
547    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
548        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
549    };
550
551    let local_var_req = local_var_req_builder.build()?;
552    let local_var_resp = local_var_client.execute(local_var_req).await?;
553
554    let local_var_status = local_var_resp.status();
555    let local_var_content = local_var_resp.text().await?;
556
557    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
558        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
559    } else {
560        let local_var_entity: Option<UnshareAiArtifactError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
561        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
562        Err(Error::ResponseError(local_var_error))
563    }
564}
565
566pub async fn unshare_ai_session(configuration: &configuration::Configuration, workspace: &str, id: &str) -> Result<String, Error<UnshareAiSessionError>> {
567    let local_var_configuration = configuration;
568
569    let local_var_client = &local_var_configuration.client;
570
571    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_sessions/delete/{id}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), id=crate::apis::urlencode(id));
572    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
573
574    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
575        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
576    }
577    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
578        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
579    };
580
581    let local_var_req = local_var_req_builder.build()?;
582    let local_var_resp = local_var_client.execute(local_var_req).await?;
583
584    let local_var_status = local_var_resp.status();
585    let local_var_content = local_var_resp.text().await?;
586
587    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
588        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
589    } else {
590        let local_var_entity: Option<UnshareAiSessionError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
591        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
592        Err(Error::ResponseError(local_var_error))
593    }
594}
595