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.884.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 [`ai_web_fetch`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AiWebFetchError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`ai_web_search`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum AiWebSearchError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`call_ai_session_tool`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum CallAiSessionToolError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`complete_ai`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum CompleteAiError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`forget_opened_ai_session`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ForgetOpenedAiSessionError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`get_ai_artifact_share_status`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetAiArtifactShareStatusError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`get_ai_session_share_status`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetAiSessionShareStatusError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`get_shared_ai_artifact`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum GetSharedAiArtifactError {
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`get_shared_ai_session`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum GetSharedAiSessionError {
78    UnknownValue(serde_json::Value),
79}
80
81/// struct for typed errors of method [`list_ai_session_backups`]
82#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum ListAiSessionBackupsError {
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`list_ai_usage`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum ListAiUsageError {
92    UnknownValue(serde_json::Value),
93}
94
95/// struct for typed errors of method [`list_shared_ai_artifacts`]
96#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(untagged)]
98pub enum ListSharedAiArtifactsError {
99    UnknownValue(serde_json::Value),
100}
101
102/// struct for typed errors of method [`list_shared_ai_sessions`]
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(untagged)]
105pub enum ListSharedAiSessionsError {
106    UnknownValue(serde_json::Value),
107}
108
109/// struct for typed errors of method [`open_secret_request`]
110#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum OpenSecretRequestError {
113    UnknownValue(serde_json::Value),
114}
115
116/// struct for typed errors of method [`pull_ai_session_backups`]
117#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(untagged)]
119pub enum PullAiSessionBackupsError {
120    UnknownValue(serde_json::Value),
121}
122
123/// struct for typed errors of method [`push_ai_session_backups`]
124#[derive(Debug, Clone, Serialize, Deserialize)]
125#[serde(untagged)]
126pub enum PushAiSessionBackupsError {
127    UnknownValue(serde_json::Value),
128}
129
130/// struct for typed errors of method [`record_ai_usage`]
131#[derive(Debug, Clone, Serialize, Deserialize)]
132#[serde(untagged)]
133pub enum RecordAiUsageError {
134    UnknownValue(serde_json::Value),
135}
136
137/// struct for typed errors of method [`set_ai_session_share_public`]
138#[derive(Debug, Clone, Serialize, Deserialize)]
139#[serde(untagged)]
140pub enum SetAiSessionSharePublicError {
141    UnknownValue(serde_json::Value),
142}
143
144/// struct for typed errors of method [`share_ai_artifact`]
145#[derive(Debug, Clone, Serialize, Deserialize)]
146#[serde(untagged)]
147pub enum ShareAiArtifactError {
148    UnknownValue(serde_json::Value),
149}
150
151/// struct for typed errors of method [`share_ai_session`]
152#[derive(Debug, Clone, Serialize, Deserialize)]
153#[serde(untagged)]
154pub enum ShareAiSessionError {
155    UnknownValue(serde_json::Value),
156}
157
158/// struct for typed errors of method [`unshare_ai_artifact`]
159#[derive(Debug, Clone, Serialize, Deserialize)]
160#[serde(untagged)]
161pub enum UnshareAiArtifactError {
162    UnknownValue(serde_json::Value),
163}
164
165/// struct for typed errors of method [`unshare_ai_session`]
166#[derive(Debug, Clone, Serialize, Deserialize)]
167#[serde(untagged)]
168pub enum UnshareAiSessionError {
169    UnknownValue(serde_json::Value),
170}
171
172
173/// Has the search API set in the workspace's AI settings fetch a page and returns its text as markdown. The page is fetched from the search API's servers, not Windmill's. 
174pub async fn ai_web_fetch(configuration: &configuration::Configuration, workspace: &str, ai_web_fetch_request: models::AiWebFetchRequest) -> Result<models::AiWebFetch200Response, Error<AiWebFetchError>> {
175    let local_var_configuration = configuration;
176
177    let local_var_client = &local_var_configuration.client;
178
179    let local_var_uri_str = format!("{}/w/{workspace}/ai/web_fetch", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
180    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
181
182    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
183        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
184    }
185    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
186        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
187    };
188    local_var_req_builder = local_var_req_builder.json(&ai_web_fetch_request);
189
190    let local_var_req = local_var_req_builder.build()?;
191    let local_var_resp = local_var_client.execute(local_var_req).await?;
192
193    let local_var_status = local_var_resp.status();
194    let local_var_content = local_var_resp.text().await?;
195
196    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
197        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
198    } else {
199        let local_var_entity: Option<AiWebFetchError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
200        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
201        Err(Error::ResponseError(local_var_error))
202    }
203}
204
205/// Runs a query against the search API (Exa, Tavily, Linkup or DeepSeek) set in the workspace's AI settings, with the key of its resource. The AI chat uses it when the model's provider has no built-in web search. 
206pub async fn ai_web_search(configuration: &configuration::Configuration, workspace: &str, ai_web_search_request: models::AiWebSearchRequest) -> Result<models::AiWebSearch200Response, Error<AiWebSearchError>> {
207    let local_var_configuration = configuration;
208
209    let local_var_client = &local_var_configuration.client;
210
211    let local_var_uri_str = format!("{}/w/{workspace}/ai/web_search", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
212    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
213
214    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
215        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
216    }
217    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
218        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
219    };
220    local_var_req_builder = local_var_req_builder.json(&ai_web_search_request);
221
222    let local_var_req = local_var_req_builder.build()?;
223    let local_var_resp = local_var_client.execute(local_var_req).await?;
224
225    let local_var_status = local_var_resp.status();
226    let local_var_content = local_var_resp.text().await?;
227
228    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
229        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
230    } else {
231        let local_var_entity: Option<AiWebSearchError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
232        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
233        Err(Error::ResponseError(local_var_error))
234    }
235}
236
237/// The in-app chat's entry to the session toolset the MCP server also serves. Refused for job tokens and scoped tokens.
238pub 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>> {
239    let local_var_configuration = configuration;
240
241    let local_var_client = &local_var_configuration.client;
242
243    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));
244    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
245
246    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
247        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
248    }
249    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
250        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
251    };
252    local_var_req_builder = local_var_req_builder.json(&call_ai_session_tool_request);
253
254    let local_var_req = local_var_req_builder.build()?;
255    let local_var_resp = local_var_client.execute(local_var_req).await?;
256
257    let local_var_status = local_var_resp.status();
258    let local_var_content = local_var_resp.text().await?;
259
260    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
261        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
262    } else {
263        let local_var_entity: Option<CallAiSessionToolError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
264        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
265        Err(Error::ResponseError(local_var_error))
266    }
267}
268
269/// 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. 
270pub async fn complete_ai(configuration: &configuration::Configuration, workspace: &str, complete_ai_request: models::CompleteAiRequest) -> Result<models::CompleteAi200Response, Error<CompleteAiError>> {
271    let local_var_configuration = configuration;
272
273    let local_var_client = &local_var_configuration.client;
274
275    let local_var_uri_str = format!("{}/w/{workspace}/ai/complete", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
276    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
277
278    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
279        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
280    }
281    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
282        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
283    };
284    local_var_req_builder = local_var_req_builder.json(&complete_ai_request);
285
286    let local_var_req = local_var_req_builder.build()?;
287    let local_var_resp = local_var_client.execute(local_var_req).await?;
288
289    let local_var_status = local_var_resp.status();
290    let local_var_content = local_var_resp.text().await?;
291
292    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
293        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
294    } else {
295        let local_var_entity: Option<CompleteAiError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
296        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
297        Err(Error::ResponseError(local_var_error))
298    }
299}
300
301/// The share stays readable by link; opening it again lists it again. 
302pub async fn forget_opened_ai_session(configuration: &configuration::Configuration, workspace: &str, id: &str) -> Result<String, Error<ForgetOpenedAiSessionError>> {
303    let local_var_configuration = configuration;
304
305    let local_var_client = &local_var_configuration.client;
306
307    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_sessions/opened/{id}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), id=crate::apis::urlencode(id));
308    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
309
310    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
311        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
312    }
313    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
314        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
315    };
316
317    let local_var_req = local_var_req_builder.build()?;
318    let local_var_resp = local_var_client.execute(local_var_req).await?;
319
320    let local_var_status = local_var_resp.status();
321    let local_var_content = local_var_resp.text().await?;
322
323    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
324        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
325    } else {
326        let local_var_entity: Option<ForgetOpenedAiSessionError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
327        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
328        Err(Error::ResponseError(local_var_error))
329    }
330}
331
332pub async fn get_ai_artifact_share_status(configuration: &configuration::Configuration, workspace: &str, artifact_id: &str) -> Result<models::GetAiArtifactShareStatus200Response, Error<GetAiArtifactShareStatusError>> {
333    let local_var_configuration = configuration;
334
335    let local_var_client = &local_var_configuration.client;
336
337    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_artifacts/status", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
338    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
339
340    local_var_req_builder = local_var_req_builder.query(&[("artifact_id", &artifact_id.to_string())]);
341    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
342        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
343    }
344    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
345        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
346    };
347
348    let local_var_req = local_var_req_builder.build()?;
349    let local_var_resp = local_var_client.execute(local_var_req).await?;
350
351    let local_var_status = local_var_resp.status();
352    let local_var_content = local_var_resp.text().await?;
353
354    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
355        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
356    } else {
357        let local_var_entity: Option<GetAiArtifactShareStatusError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
358        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
359        Err(Error::ResponseError(local_var_error))
360    }
361}
362
363pub async fn get_ai_session_share_status(configuration: &configuration::Configuration, workspace: &str, session_id: &str) -> Result<models::GetAiSessionShareStatus200Response, Error<GetAiSessionShareStatusError>> {
364    let local_var_configuration = configuration;
365
366    let local_var_client = &local_var_configuration.client;
367
368    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_sessions/status", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
369    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
370
371    local_var_req_builder = local_var_req_builder.query(&[("session_id", &session_id.to_string())]);
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<GetAiSessionShareStatusError> = 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
394pub async fn get_shared_ai_artifact(configuration: &configuration::Configuration, workspace: &str, id: &str) -> Result<models::GetSharedAiArtifact200Response, Error<GetSharedAiArtifactError>> {
395    let local_var_configuration = configuration;
396
397    let local_var_client = &local_var_configuration.client;
398
399    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));
400    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
401
402    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
403        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
404    }
405    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
406        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
407    };
408
409    let local_var_req = local_var_req_builder.build()?;
410    let local_var_resp = local_var_client.execute(local_var_req).await?;
411
412    let local_var_status = local_var_resp.status();
413    let local_var_content = local_var_resp.text().await?;
414
415    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
416        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
417    } else {
418        let local_var_entity: Option<GetSharedAiArtifactError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
419        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
420        Err(Error::ResponseError(local_var_error))
421    }
422}
423
424/// A public share is served without authentication; any other one only to a member of the workspace. 
425pub async fn get_shared_ai_session(configuration: &configuration::Configuration, workspace: &str, id: &str) -> Result<models::GetSharedAiSession200Response, Error<GetSharedAiSessionError>> {
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_u/shared_sessions/get/{id}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), id=crate::apis::urlencode(id));
431    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, 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
440    let local_var_req = local_var_req_builder.build()?;
441    let local_var_resp = local_var_client.execute(local_var_req).await?;
442
443    let local_var_status = local_var_resp.status();
444    let local_var_content = local_var_resp.text().await?;
445
446    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
447        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
448    } else {
449        let local_var_entity: Option<GetSharedAiSessionError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
450        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
451        Err(Error::ResponseError(local_var_error))
452    }
453}
454
455pub async fn list_ai_session_backups(configuration: &configuration::Configuration, workspace: &str) -> Result<models::ListAiSessionBackups200Response, Error<ListAiSessionBackupsError>> {
456    let local_var_configuration = configuration;
457
458    let local_var_client = &local_var_configuration.client;
459
460    let local_var_uri_str = format!("{}/w/{workspace}/ai/sessions/list", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
461    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
462
463    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
464        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
465    }
466    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
467        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
468    };
469
470    let local_var_req = local_var_req_builder.build()?;
471    let local_var_resp = local_var_client.execute(local_var_req).await?;
472
473    let local_var_status = local_var_resp.status();
474    let local_var_content = local_var_resp.text().await?;
475
476    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
477        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
478    } else {
479        let local_var_entity: Option<ListAiSessionBackupsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
480        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
481        Err(Error::ResponseError(local_var_error))
482    }
483}
484
485pub 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>> {
486    let local_var_configuration = configuration;
487
488    let local_var_client = &local_var_configuration.client;
489
490    let local_var_uri_str = format!("{}/w/{workspace}/ai/usage", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
491    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
492
493    if let Some(ref local_var_str) = days {
494        local_var_req_builder = local_var_req_builder.query(&[("days", &local_var_str.to_string())]);
495    }
496    if let Some(ref local_var_str) = group_by {
497        local_var_req_builder = local_var_req_builder.query(&[("group_by", &local_var_str.to_string())]);
498    }
499    if let Some(ref local_var_str) = scope {
500        local_var_req_builder = local_var_req_builder.query(&[("scope", &local_var_str.to_string())]);
501    }
502    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
503        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
504    }
505    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
506        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
507    };
508
509    let local_var_req = local_var_req_builder.build()?;
510    let local_var_resp = local_var_client.execute(local_var_req).await?;
511
512    let local_var_status = local_var_resp.status();
513    let local_var_content = local_var_resp.text().await?;
514
515    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
516        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
517    } else {
518        let local_var_entity: Option<ListAiUsageError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
519        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
520        Err(Error::ResponseError(local_var_error))
521    }
522}
523
524/// Every share still inside its retention window, newest first, without its content. Capped at 500. 
525pub async fn list_shared_ai_artifacts(configuration: &configuration::Configuration, workspace: &str) -> Result<Vec<models::SharedAiArtifactInfo>, Error<ListSharedAiArtifactsError>> {
526    let local_var_configuration = configuration;
527
528    let local_var_client = &local_var_configuration.client;
529
530    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_artifacts/list", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
531    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
532
533    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
534        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
535    }
536    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
537        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
538    };
539
540    let local_var_req = local_var_req_builder.build()?;
541    let local_var_resp = local_var_client.execute(local_var_req).await?;
542
543    let local_var_status = local_var_resp.status();
544    let local_var_content = local_var_resp.text().await?;
545
546    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
547        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
548    } else {
549        let local_var_entity: Option<ListSharedAiArtifactsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
550        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
551        Err(Error::ResponseError(local_var_error))
552    }
553}
554
555/// The caller's own shares and the ones they opened by link, most recently shared or opened first, without their snapshot. Capped at 500. `session_id` is set on the caller's own shares only, `opened_at` on the others. 
556pub async fn list_shared_ai_sessions(configuration: &configuration::Configuration, workspace: &str) -> Result<Vec<models::ListSharedAiSessions200ResponseInner>, Error<ListSharedAiSessionsError>> {
557    let local_var_configuration = configuration;
558
559    let local_var_client = &local_var_configuration.client;
560
561    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_sessions/list", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
562    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
563
564    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
565        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
566    }
567    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
568        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
569    };
570
571    let local_var_req = local_var_req_builder.build()?;
572    let local_var_resp = local_var_client.execute(local_var_req).await?;
573
574    let local_var_status = local_var_resp.status();
575    let local_var_content = local_var_resp.text().await?;
576
577    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
578        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
579    } else {
580        let local_var_entity: Option<ListSharedAiSessionsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
581        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
582        Err(Error::ResponseError(local_var_error))
583    }
584}
585
586/// The page an MCP client's request_secret link opens reads the card to draw from the link's signed token. Refused when the token is invalid, expired, or made for another user or workspace.
587pub async fn open_secret_request(configuration: &configuration::Configuration, workspace: &str, get_github_app_token200_response: models::GetGithubAppToken200Response) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<OpenSecretRequestError>> {
588    let local_var_configuration = configuration;
589
590    let local_var_client = &local_var_configuration.client;
591
592    let local_var_uri_str = format!("{}/w/{workspace}/ai_session_tools/secret_request/open", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
593    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
594
595    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
596        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
597    }
598    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
599        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
600    };
601    local_var_req_builder = local_var_req_builder.json(&get_github_app_token200_response);
602
603    let local_var_req = local_var_req_builder.build()?;
604    let local_var_resp = local_var_client.execute(local_var_req).await?;
605
606    let local_var_status = local_var_resp.status();
607    let local_var_content = local_var_resp.text().await?;
608
609    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
610        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
611    } else {
612        let local_var_entity: Option<OpenSecretRequestError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
613        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
614        Err(Error::ResponseError(local_var_error))
615    }
616}
617
618pub async fn pull_ai_session_backups(configuration: &configuration::Configuration, workspace: &str, pull_ai_session_backups_request: models::PullAiSessionBackupsRequest) -> Result<models::PullAiSessionBackups200Response, Error<PullAiSessionBackupsError>> {
619    let local_var_configuration = configuration;
620
621    let local_var_client = &local_var_configuration.client;
622
623    let local_var_uri_str = format!("{}/w/{workspace}/ai/sessions/pull", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
624    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
625
626    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
627        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
628    }
629    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
630        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
631    };
632    local_var_req_builder = local_var_req_builder.json(&pull_ai_session_backups_request);
633
634    let local_var_req = local_var_req_builder.build()?;
635    let local_var_resp = local_var_client.execute(local_var_req).await?;
636
637    let local_var_status = local_var_resp.status();
638    let local_var_content = local_var_resp.text().await?;
639
640    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
641        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
642    } else {
643        let local_var_entity: Option<PullAiSessionBackupsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
644        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
645        Err(Error::ResponseError(local_var_error))
646    }
647}
648
649pub async fn push_ai_session_backups(configuration: &configuration::Configuration, workspace: &str, push_ai_session_backups_request: models::PushAiSessionBackupsRequest) -> Result<models::PushAiSessionBackups200Response, Error<PushAiSessionBackupsError>> {
650    let local_var_configuration = configuration;
651
652    let local_var_client = &local_var_configuration.client;
653
654    let local_var_uri_str = format!("{}/w/{workspace}/ai/sessions/push", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
655    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
656
657    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
658        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
659    }
660    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
661        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
662    };
663    local_var_req_builder = local_var_req_builder.json(&push_ai_session_backups_request);
664
665    let local_var_req = local_var_req_builder.build()?;
666    let local_var_resp = local_var_client.execute(local_var_req).await?;
667
668    let local_var_status = local_var_resp.status();
669    let local_var_content = local_var_resp.text().await?;
670
671    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
672        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
673    } else {
674        let local_var_entity: Option<PushAiSessionBackupsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
675        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
676        Err(Error::ResponseError(local_var_error))
677    }
678}
679
680pub async fn record_ai_usage(configuration: &configuration::Configuration, workspace: &str, record_ai_usage_request: models::RecordAiUsageRequest) -> Result<(), Error<RecordAiUsageError>> {
681    let local_var_configuration = configuration;
682
683    let local_var_client = &local_var_configuration.client;
684
685    let local_var_uri_str = format!("{}/w/{workspace}/ai/usage", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
686    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
687
688    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
689        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
690    }
691    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
692        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
693    };
694    local_var_req_builder = local_var_req_builder.json(&record_ai_usage_request);
695
696    let local_var_req = local_var_req_builder.build()?;
697    let local_var_resp = local_var_client.execute(local_var_req).await?;
698
699    let local_var_status = local_var_resp.status();
700    let local_var_content = local_var_resp.text().await?;
701
702    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
703        Ok(())
704    } else {
705        let local_var_entity: Option<RecordAiUsageError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
706        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
707        Err(Error::ResponseError(local_var_error))
708    }
709}
710
711pub 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>> {
712    let local_var_configuration = configuration;
713
714    let local_var_client = &local_var_configuration.client;
715
716    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));
717    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
718
719    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
720        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
721    }
722    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
723        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
724    };
725    local_var_req_builder = local_var_req_builder.json(&set_ai_session_share_public_request);
726
727    let local_var_req = local_var_req_builder.build()?;
728    let local_var_resp = local_var_client.execute(local_var_req).await?;
729
730    let local_var_status = local_var_resp.status();
731    let local_var_content = local_var_resp.text().await?;
732
733    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
734        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
735    } else {
736        let local_var_entity: Option<SetAiSessionSharePublicError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
737        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
738        Err(Error::ResponseError(local_var_error))
739    }
740}
741
742/// 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. 
743pub async fn share_ai_artifact(configuration: &configuration::Configuration, workspace: &str, share_ai_artifact_request: models::ShareAiArtifactRequest) -> Result<models::SharedAiArtifactInfo, Error<ShareAiArtifactError>> {
744    let local_var_configuration = configuration;
745
746    let local_var_client = &local_var_configuration.client;
747
748    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_artifacts/share", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
749    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
750
751    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
752        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
753    }
754    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
755        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
756    };
757    local_var_req_builder = local_var_req_builder.json(&share_ai_artifact_request);
758
759    let local_var_req = local_var_req_builder.build()?;
760    let local_var_resp = local_var_client.execute(local_var_req).await?;
761
762    let local_var_status = local_var_resp.status();
763    let local_var_content = local_var_resp.text().await?;
764
765    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
766        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
767    } else {
768        let local_var_entity: Option<ShareAiArtifactError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
769        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
770        Err(Error::ResponseError(local_var_error))
771    }
772}
773
774/// 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. 
775pub async fn share_ai_session(configuration: &configuration::Configuration, workspace: &str, share_ai_session_request: models::ShareAiSessionRequest) -> Result<models::SharedAiSessionInfo, Error<ShareAiSessionError>> {
776    let local_var_configuration = configuration;
777
778    let local_var_client = &local_var_configuration.client;
779
780    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_sessions/share", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
781    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
782
783    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
784        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
785    }
786    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
787        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
788    };
789    local_var_req_builder = local_var_req_builder.json(&share_ai_session_request);
790
791    let local_var_req = local_var_req_builder.build()?;
792    let local_var_resp = local_var_client.execute(local_var_req).await?;
793
794    let local_var_status = local_var_resp.status();
795    let local_var_content = local_var_resp.text().await?;
796
797    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
798        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
799    } else {
800        let local_var_entity: Option<ShareAiSessionError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
801        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
802        Err(Error::ResponseError(local_var_error))
803    }
804}
805
806pub async fn unshare_ai_artifact(configuration: &configuration::Configuration, workspace: &str, id: &str) -> Result<String, Error<UnshareAiArtifactError>> {
807    let local_var_configuration = configuration;
808
809    let local_var_client = &local_var_configuration.client;
810
811    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));
812    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
813
814    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
815        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
816    }
817    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
818        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
819    };
820
821    let local_var_req = local_var_req_builder.build()?;
822    let local_var_resp = local_var_client.execute(local_var_req).await?;
823
824    let local_var_status = local_var_resp.status();
825    let local_var_content = local_var_resp.text().await?;
826
827    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
828        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
829    } else {
830        let local_var_entity: Option<UnshareAiArtifactError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
831        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
832        Err(Error::ResponseError(local_var_error))
833    }
834}
835
836pub async fn unshare_ai_session(configuration: &configuration::Configuration, workspace: &str, id: &str) -> Result<String, Error<UnshareAiSessionError>> {
837    let local_var_configuration = configuration;
838
839    let local_var_client = &local_var_configuration.client;
840
841    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));
842    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
843
844    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
845        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
846    }
847    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
848        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
849    };
850
851    let local_var_req = local_var_req_builder.build()?;
852    let local_var_resp = local_var_client.execute(local_var_req).await?;
853
854    let local_var_status = local_var_resp.status();
855    let local_var_content = local_var_resp.text().await?;
856
857    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
858        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
859    } else {
860        let local_var_entity: Option<UnshareAiSessionError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
861        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
862        Err(Error::ResponseError(local_var_error))
863    }
864}
865