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.862.0
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 [`call_ai_session_tool`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CallAiSessionToolError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`complete_ai`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum CompleteAiError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_ai_artifact_share_status`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetAiArtifactShareStatusError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_ai_session_share_status`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetAiSessionShareStatusError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_shared_ai_artifact`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetSharedAiArtifactError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`get_shared_ai_session`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetSharedAiSessionError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`list_ai_session_backups`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum ListAiSessionBackupsError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`list_ai_usage`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum ListAiUsageError {
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`list_shared_ai_artifacts`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ListSharedAiArtifactsError {
78    UnknownValue(serde_json::Value),
79}
80
81/// struct for typed errors of method [`pull_ai_session_backups`]
82#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum PullAiSessionBackupsError {
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`push_ai_session_backups`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum PushAiSessionBackupsError {
92    UnknownValue(serde_json::Value),
93}
94
95/// struct for typed errors of method [`record_ai_usage`]
96#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(untagged)]
98pub enum RecordAiUsageError {
99    UnknownValue(serde_json::Value),
100}
101
102/// struct for typed errors of method [`set_ai_session_share_public`]
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(untagged)]
105pub enum SetAiSessionSharePublicError {
106    UnknownValue(serde_json::Value),
107}
108
109/// struct for typed errors of method [`share_ai_artifact`]
110#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum ShareAiArtifactError {
113    UnknownValue(serde_json::Value),
114}
115
116/// struct for typed errors of method [`share_ai_session`]
117#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(untagged)]
119pub enum ShareAiSessionError {
120    UnknownValue(serde_json::Value),
121}
122
123/// struct for typed errors of method [`unshare_ai_artifact`]
124#[derive(Debug, Clone, Serialize, Deserialize)]
125#[serde(untagged)]
126pub enum UnshareAiArtifactError {
127    UnknownValue(serde_json::Value),
128}
129
130/// struct for typed errors of method [`unshare_ai_session`]
131#[derive(Debug, Clone, Serialize, Deserialize)]
132#[serde(untagged)]
133pub enum UnshareAiSessionError {
134    UnknownValue(serde_json::Value),
135}
136
137
138/// The in-app chat's entry to the session toolset the MCP server also serves. Refused for job tokens and scoped tokens.
139pub async fn call_ai_session_tool(configuration: &configuration::Configuration, workspace: &str, name: &str, call_ai_session_tool_request: models::CallAiSessionToolRequest) -> Result<models::CallAiSessionTool200Response, Error<CallAiSessionToolError>> {
140    let local_var_configuration = configuration;
141
142    let local_var_client = &local_var_configuration.client;
143
144    let local_var_uri_str = format!("{}/w/{workspace}/ai_session_tools/{name}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), name=crate::apis::urlencode(name));
145    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
146
147    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
148        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
149    }
150    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
151        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
152    };
153    local_var_req_builder = local_var_req_builder.json(&call_ai_session_tool_request);
154
155    let local_var_req = local_var_req_builder.build()?;
156    let local_var_resp = local_var_client.execute(local_var_req).await?;
157
158    let local_var_status = local_var_resp.status();
159    let local_var_content = local_var_resp.text().await?;
160
161    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
162        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
163    } else {
164        let local_var_entity: Option<CallAiSessionToolError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
165        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
166        Err(Error::ResponseError(local_var_error))
167    }
168}
169
170/// 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. 
171pub async fn complete_ai(configuration: &configuration::Configuration, workspace: &str, complete_ai_request: models::CompleteAiRequest) -> Result<models::CompleteAi200Response, Error<CompleteAiError>> {
172    let local_var_configuration = configuration;
173
174    let local_var_client = &local_var_configuration.client;
175
176    let local_var_uri_str = format!("{}/w/{workspace}/ai/complete", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
177    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
178
179    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
180        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
181    }
182    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
183        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
184    };
185    local_var_req_builder = local_var_req_builder.json(&complete_ai_request);
186
187    let local_var_req = local_var_req_builder.build()?;
188    let local_var_resp = local_var_client.execute(local_var_req).await?;
189
190    let local_var_status = local_var_resp.status();
191    let local_var_content = local_var_resp.text().await?;
192
193    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
194        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
195    } else {
196        let local_var_entity: Option<CompleteAiError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
197        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
198        Err(Error::ResponseError(local_var_error))
199    }
200}
201
202pub async fn get_ai_artifact_share_status(configuration: &configuration::Configuration, workspace: &str, artifact_id: &str) -> Result<models::GetAiArtifactShareStatus200Response, Error<GetAiArtifactShareStatusError>> {
203    let local_var_configuration = configuration;
204
205    let local_var_client = &local_var_configuration.client;
206
207    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_artifacts/status", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
208    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
209
210    local_var_req_builder = local_var_req_builder.query(&[("artifact_id", &artifact_id.to_string())]);
211    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
212        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
213    }
214    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
215        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
216    };
217
218    let local_var_req = local_var_req_builder.build()?;
219    let local_var_resp = local_var_client.execute(local_var_req).await?;
220
221    let local_var_status = local_var_resp.status();
222    let local_var_content = local_var_resp.text().await?;
223
224    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
225        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
226    } else {
227        let local_var_entity: Option<GetAiArtifactShareStatusError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
228        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
229        Err(Error::ResponseError(local_var_error))
230    }
231}
232
233pub async fn get_ai_session_share_status(configuration: &configuration::Configuration, workspace: &str, session_id: &str) -> Result<models::GetAiSessionShareStatus200Response, Error<GetAiSessionShareStatusError>> {
234    let local_var_configuration = configuration;
235
236    let local_var_client = &local_var_configuration.client;
237
238    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_sessions/status", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
239    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
240
241    local_var_req_builder = local_var_req_builder.query(&[("session_id", &session_id.to_string())]);
242    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
243        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
244    }
245    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
246        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
247    };
248
249    let local_var_req = local_var_req_builder.build()?;
250    let local_var_resp = local_var_client.execute(local_var_req).await?;
251
252    let local_var_status = local_var_resp.status();
253    let local_var_content = local_var_resp.text().await?;
254
255    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
256        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
257    } else {
258        let local_var_entity: Option<GetAiSessionShareStatusError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
259        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
260        Err(Error::ResponseError(local_var_error))
261    }
262}
263
264pub async fn get_shared_ai_artifact(configuration: &configuration::Configuration, workspace: &str, id: &str) -> Result<models::GetSharedAiArtifact200Response, Error<GetSharedAiArtifactError>> {
265    let local_var_configuration = configuration;
266
267    let local_var_client = &local_var_configuration.client;
268
269    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));
270    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
271
272    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
273        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
274    }
275    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
276        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
277    };
278
279    let local_var_req = local_var_req_builder.build()?;
280    let local_var_resp = local_var_client.execute(local_var_req).await?;
281
282    let local_var_status = local_var_resp.status();
283    let local_var_content = local_var_resp.text().await?;
284
285    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
286        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
287    } else {
288        let local_var_entity: Option<GetSharedAiArtifactError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
289        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
290        Err(Error::ResponseError(local_var_error))
291    }
292}
293
294/// A public share is served without authentication; any other one only to a member of the workspace. 
295pub async fn get_shared_ai_session(configuration: &configuration::Configuration, workspace: &str, id: &str) -> Result<models::GetSharedAiSession200Response, Error<GetSharedAiSessionError>> {
296    let local_var_configuration = configuration;
297
298    let local_var_client = &local_var_configuration.client;
299
300    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));
301    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
302
303    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
304        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
305    }
306    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
307        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
308    };
309
310    let local_var_req = local_var_req_builder.build()?;
311    let local_var_resp = local_var_client.execute(local_var_req).await?;
312
313    let local_var_status = local_var_resp.status();
314    let local_var_content = local_var_resp.text().await?;
315
316    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
317        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
318    } else {
319        let local_var_entity: Option<GetSharedAiSessionError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
320        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
321        Err(Error::ResponseError(local_var_error))
322    }
323}
324
325pub async fn list_ai_session_backups(configuration: &configuration::Configuration, workspace: &str) -> Result<models::ListAiSessionBackups200Response, Error<ListAiSessionBackupsError>> {
326    let local_var_configuration = configuration;
327
328    let local_var_client = &local_var_configuration.client;
329
330    let local_var_uri_str = format!("{}/w/{workspace}/ai/sessions/list", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
331    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
332
333    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
334        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
335    }
336    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
337        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
338    };
339
340    let local_var_req = local_var_req_builder.build()?;
341    let local_var_resp = local_var_client.execute(local_var_req).await?;
342
343    let local_var_status = local_var_resp.status();
344    let local_var_content = local_var_resp.text().await?;
345
346    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
347        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
348    } else {
349        let local_var_entity: Option<ListAiSessionBackupsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
350        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
351        Err(Error::ResponseError(local_var_error))
352    }
353}
354
355pub 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>> {
356    let local_var_configuration = configuration;
357
358    let local_var_client = &local_var_configuration.client;
359
360    let local_var_uri_str = format!("{}/w/{workspace}/ai/usage", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
361    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
362
363    if let Some(ref local_var_str) = days {
364        local_var_req_builder = local_var_req_builder.query(&[("days", &local_var_str.to_string())]);
365    }
366    if let Some(ref local_var_str) = group_by {
367        local_var_req_builder = local_var_req_builder.query(&[("group_by", &local_var_str.to_string())]);
368    }
369    if let Some(ref local_var_str) = scope {
370        local_var_req_builder = local_var_req_builder.query(&[("scope", &local_var_str.to_string())]);
371    }
372    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
373        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
374    }
375    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
376        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
377    };
378
379    let local_var_req = local_var_req_builder.build()?;
380    let local_var_resp = local_var_client.execute(local_var_req).await?;
381
382    let local_var_status = local_var_resp.status();
383    let local_var_content = local_var_resp.text().await?;
384
385    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
386        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
387    } else {
388        let local_var_entity: Option<ListAiUsageError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
389        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
390        Err(Error::ResponseError(local_var_error))
391    }
392}
393
394/// Every share still inside its retention window, newest first, without its content. Capped at 500. 
395pub async fn list_shared_ai_artifacts(configuration: &configuration::Configuration, workspace: &str) -> Result<Vec<models::SharedAiArtifactInfo>, Error<ListSharedAiArtifactsError>> {
396    let local_var_configuration = configuration;
397
398    let local_var_client = &local_var_configuration.client;
399
400    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_artifacts/list", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
401    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
402
403    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
404        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
405    }
406    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
407        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
408    };
409
410    let local_var_req = local_var_req_builder.build()?;
411    let local_var_resp = local_var_client.execute(local_var_req).await?;
412
413    let local_var_status = local_var_resp.status();
414    let local_var_content = local_var_resp.text().await?;
415
416    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
417        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
418    } else {
419        let local_var_entity: Option<ListSharedAiArtifactsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
420        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
421        Err(Error::ResponseError(local_var_error))
422    }
423}
424
425pub async fn pull_ai_session_backups(configuration: &configuration::Configuration, workspace: &str, pull_ai_session_backups_request: models::PullAiSessionBackupsRequest) -> Result<models::PullAiSessionBackups200Response, Error<PullAiSessionBackupsError>> {
426    let local_var_configuration = configuration;
427
428    let local_var_client = &local_var_configuration.client;
429
430    let local_var_uri_str = format!("{}/w/{workspace}/ai/sessions/pull", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
431    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
432
433    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
434        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
435    }
436    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
437        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
438    };
439    local_var_req_builder = local_var_req_builder.json(&pull_ai_session_backups_request);
440
441    let local_var_req = local_var_req_builder.build()?;
442    let local_var_resp = local_var_client.execute(local_var_req).await?;
443
444    let local_var_status = local_var_resp.status();
445    let local_var_content = local_var_resp.text().await?;
446
447    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
448        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
449    } else {
450        let local_var_entity: Option<PullAiSessionBackupsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
451        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
452        Err(Error::ResponseError(local_var_error))
453    }
454}
455
456pub async fn push_ai_session_backups(configuration: &configuration::Configuration, workspace: &str, push_ai_session_backups_request: models::PushAiSessionBackupsRequest) -> Result<models::PushAiSessionBackups200Response, Error<PushAiSessionBackupsError>> {
457    let local_var_configuration = configuration;
458
459    let local_var_client = &local_var_configuration.client;
460
461    let local_var_uri_str = format!("{}/w/{workspace}/ai/sessions/push", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
462    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
463
464    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
465        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
466    }
467    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
468        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
469    };
470    local_var_req_builder = local_var_req_builder.json(&push_ai_session_backups_request);
471
472    let local_var_req = local_var_req_builder.build()?;
473    let local_var_resp = local_var_client.execute(local_var_req).await?;
474
475    let local_var_status = local_var_resp.status();
476    let local_var_content = local_var_resp.text().await?;
477
478    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
479        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
480    } else {
481        let local_var_entity: Option<PushAiSessionBackupsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
482        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
483        Err(Error::ResponseError(local_var_error))
484    }
485}
486
487pub async fn record_ai_usage(configuration: &configuration::Configuration, workspace: &str, record_ai_usage_request: models::RecordAiUsageRequest) -> Result<(), Error<RecordAiUsageError>> {
488    let local_var_configuration = configuration;
489
490    let local_var_client = &local_var_configuration.client;
491
492    let local_var_uri_str = format!("{}/w/{workspace}/ai/usage", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
493    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
494
495    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
496        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
497    }
498    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
499        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
500    };
501    local_var_req_builder = local_var_req_builder.json(&record_ai_usage_request);
502
503    let local_var_req = local_var_req_builder.build()?;
504    let local_var_resp = local_var_client.execute(local_var_req).await?;
505
506    let local_var_status = local_var_resp.status();
507    let local_var_content = local_var_resp.text().await?;
508
509    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
510        Ok(())
511    } else {
512        let local_var_entity: Option<RecordAiUsageError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
513        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
514        Err(Error::ResponseError(local_var_error))
515    }
516}
517
518pub 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>> {
519    let local_var_configuration = configuration;
520
521    let local_var_client = &local_var_configuration.client;
522
523    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));
524    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
525
526    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
527        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
528    }
529    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
530        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
531    };
532    local_var_req_builder = local_var_req_builder.json(&set_ai_session_share_public_request);
533
534    let local_var_req = local_var_req_builder.build()?;
535    let local_var_resp = local_var_client.execute(local_var_req).await?;
536
537    let local_var_status = local_var_resp.status();
538    let local_var_content = local_var_resp.text().await?;
539
540    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
541        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
542    } else {
543        let local_var_entity: Option<SetAiSessionSharePublicError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
544        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
545        Err(Error::ResponseError(local_var_error))
546    }
547}
548
549/// 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. 
550pub async fn share_ai_artifact(configuration: &configuration::Configuration, workspace: &str, share_ai_artifact_request: models::ShareAiArtifactRequest) -> Result<models::SharedAiArtifactInfo, Error<ShareAiArtifactError>> {
551    let local_var_configuration = configuration;
552
553    let local_var_client = &local_var_configuration.client;
554
555    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_artifacts/share", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
556    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
557
558    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
559        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
560    }
561    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
562        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
563    };
564    local_var_req_builder = local_var_req_builder.json(&share_ai_artifact_request);
565
566    let local_var_req = local_var_req_builder.build()?;
567    let local_var_resp = local_var_client.execute(local_var_req).await?;
568
569    let local_var_status = local_var_resp.status();
570    let local_var_content = local_var_resp.text().await?;
571
572    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
573        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
574    } else {
575        let local_var_entity: Option<ShareAiArtifactError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
576        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
577        Err(Error::ResponseError(local_var_error))
578    }
579}
580
581/// 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. 
582pub async fn share_ai_session(configuration: &configuration::Configuration, workspace: &str, share_ai_session_request: models::ShareAiSessionRequest) -> Result<models::SharedAiSessionInfo, Error<ShareAiSessionError>> {
583    let local_var_configuration = configuration;
584
585    let local_var_client = &local_var_configuration.client;
586
587    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_sessions/share", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
588    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
589
590    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
591        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
592    }
593    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
594        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
595    };
596    local_var_req_builder = local_var_req_builder.json(&share_ai_session_request);
597
598    let local_var_req = local_var_req_builder.build()?;
599    let local_var_resp = local_var_client.execute(local_var_req).await?;
600
601    let local_var_status = local_var_resp.status();
602    let local_var_content = local_var_resp.text().await?;
603
604    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
605        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
606    } else {
607        let local_var_entity: Option<ShareAiSessionError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
608        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
609        Err(Error::ResponseError(local_var_error))
610    }
611}
612
613pub async fn unshare_ai_artifact(configuration: &configuration::Configuration, workspace: &str, id: &str) -> Result<String, Error<UnshareAiArtifactError>> {
614    let local_var_configuration = configuration;
615
616    let local_var_client = &local_var_configuration.client;
617
618    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));
619    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
620
621    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
622        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
623    }
624    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
625        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
626    };
627
628    let local_var_req = local_var_req_builder.build()?;
629    let local_var_resp = local_var_client.execute(local_var_req).await?;
630
631    let local_var_status = local_var_resp.status();
632    let local_var_content = local_var_resp.text().await?;
633
634    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
635        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
636    } else {
637        let local_var_entity: Option<UnshareAiArtifactError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
638        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
639        Err(Error::ResponseError(local_var_error))
640    }
641}
642
643pub async fn unshare_ai_session(configuration: &configuration::Configuration, workspace: &str, id: &str) -> Result<String, Error<UnshareAiSessionError>> {
644    let local_var_configuration = configuration;
645
646    let local_var_client = &local_var_configuration.client;
647
648    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));
649    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
650
651    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
652        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
653    }
654    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
655        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
656    };
657
658    let local_var_req = local_var_req_builder.build()?;
659    let local_var_resp = local_var_client.execute(local_var_req).await?;
660
661    let local_var_status = local_var_resp.status();
662    let local_var_content = local_var_resp.text().await?;
663
664    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
665        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
666    } else {
667        let local_var_entity: Option<UnshareAiSessionError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
668        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
669        Err(Error::ResponseError(local_var_error))
670    }
671}
672