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.812.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 [`get_ai_artifact_share_status`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetAiArtifactShareStatusError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_shared_ai_artifact`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetSharedAiArtifactError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`list_ai_usage`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum ListAiUsageError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`record_ai_usage`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum RecordAiUsageError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`share_ai_artifact`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ShareAiArtifactError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`unshare_ai_artifact`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum UnshareAiArtifactError {
57    UnknownValue(serde_json::Value),
58}
59
60
61pub async fn get_ai_artifact_share_status(configuration: &configuration::Configuration, workspace: &str, artifact_id: &str) -> Result<models::GetAiArtifactShareStatus200Response, Error<GetAiArtifactShareStatusError>> {
62    let local_var_configuration = configuration;
63
64    let local_var_client = &local_var_configuration.client;
65
66    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_artifacts/status", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
67    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
68
69    local_var_req_builder = local_var_req_builder.query(&[("artifact_id", &artifact_id.to_string())]);
70    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
71        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
72    }
73    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
74        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
75    };
76
77    let local_var_req = local_var_req_builder.build()?;
78    let local_var_resp = local_var_client.execute(local_var_req).await?;
79
80    let local_var_status = local_var_resp.status();
81    let local_var_content = local_var_resp.text().await?;
82
83    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
84        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
85    } else {
86        let local_var_entity: Option<GetAiArtifactShareStatusError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
87        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
88        Err(Error::ResponseError(local_var_error))
89    }
90}
91
92pub async fn get_shared_ai_artifact(configuration: &configuration::Configuration, workspace: &str, id: &str) -> Result<models::GetSharedAiArtifact200Response, Error<GetSharedAiArtifactError>> {
93    let local_var_configuration = configuration;
94
95    let local_var_client = &local_var_configuration.client;
96
97    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));
98    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
99
100    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
101        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
102    }
103    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
104        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
105    };
106
107    let local_var_req = local_var_req_builder.build()?;
108    let local_var_resp = local_var_client.execute(local_var_req).await?;
109
110    let local_var_status = local_var_resp.status();
111    let local_var_content = local_var_resp.text().await?;
112
113    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
114        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
115    } else {
116        let local_var_entity: Option<GetSharedAiArtifactError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
117        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
118        Err(Error::ResponseError(local_var_error))
119    }
120}
121
122pub 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>> {
123    let local_var_configuration = configuration;
124
125    let local_var_client = &local_var_configuration.client;
126
127    let local_var_uri_str = format!("{}/w/{workspace}/ai/usage", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
128    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
129
130    if let Some(ref local_var_str) = days {
131        local_var_req_builder = local_var_req_builder.query(&[("days", &local_var_str.to_string())]);
132    }
133    if let Some(ref local_var_str) = group_by {
134        local_var_req_builder = local_var_req_builder.query(&[("group_by", &local_var_str.to_string())]);
135    }
136    if let Some(ref local_var_str) = scope {
137        local_var_req_builder = local_var_req_builder.query(&[("scope", &local_var_str.to_string())]);
138    }
139    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
140        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
141    }
142    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
143        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
144    };
145
146    let local_var_req = local_var_req_builder.build()?;
147    let local_var_resp = local_var_client.execute(local_var_req).await?;
148
149    let local_var_status = local_var_resp.status();
150    let local_var_content = local_var_resp.text().await?;
151
152    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
153        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
154    } else {
155        let local_var_entity: Option<ListAiUsageError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
156        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
157        Err(Error::ResponseError(local_var_error))
158    }
159}
160
161pub async fn record_ai_usage(configuration: &configuration::Configuration, workspace: &str, record_ai_usage_request: models::RecordAiUsageRequest) -> Result<(), Error<RecordAiUsageError>> {
162    let local_var_configuration = configuration;
163
164    let local_var_client = &local_var_configuration.client;
165
166    let local_var_uri_str = format!("{}/w/{workspace}/ai/usage", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
167    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
168
169    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
170        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
171    }
172    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
173        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
174    };
175    local_var_req_builder = local_var_req_builder.json(&record_ai_usage_request);
176
177    let local_var_req = local_var_req_builder.build()?;
178    let local_var_resp = local_var_client.execute(local_var_req).await?;
179
180    let local_var_status = local_var_resp.status();
181    let local_var_content = local_var_resp.text().await?;
182
183    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
184        Ok(())
185    } else {
186        let local_var_entity: Option<RecordAiUsageError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
187        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
188        Err(Error::ResponseError(local_var_error))
189    }
190}
191
192/// 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. 
193pub async fn share_ai_artifact(configuration: &configuration::Configuration, workspace: &str, share_ai_artifact_request: models::ShareAiArtifactRequest) -> Result<models::SharedAiArtifactInfo, Error<ShareAiArtifactError>> {
194    let local_var_configuration = configuration;
195
196    let local_var_client = &local_var_configuration.client;
197
198    let local_var_uri_str = format!("{}/w/{workspace}/ai/shared_artifacts/share", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
199    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
200
201    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
202        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
203    }
204    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
205        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
206    };
207    local_var_req_builder = local_var_req_builder.json(&share_ai_artifact_request);
208
209    let local_var_req = local_var_req_builder.build()?;
210    let local_var_resp = local_var_client.execute(local_var_req).await?;
211
212    let local_var_status = local_var_resp.status();
213    let local_var_content = local_var_resp.text().await?;
214
215    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
216        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
217    } else {
218        let local_var_entity: Option<ShareAiArtifactError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
219        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
220        Err(Error::ResponseError(local_var_error))
221    }
222}
223
224pub async fn unshare_ai_artifact(configuration: &configuration::Configuration, workspace: &str, id: &str) -> Result<String, Error<UnshareAiArtifactError>> {
225    let local_var_configuration = configuration;
226
227    let local_var_client = &local_var_configuration.client;
228
229    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));
230    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
231
232    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
233        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
234    }
235    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
236        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
237    };
238
239    let local_var_req = local_var_req_builder.build()?;
240    let local_var_resp = local_var_client.execute(local_var_req).await?;
241
242    let local_var_status = local_var_resp.status();
243    let local_var_content = local_var_resp.text().await?;
244
245    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
246        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
247    } else {
248        let local_var_entity: Option<UnshareAiArtifactError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
249        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
250        Err(Error::ResponseError(local_var_error))
251    }
252}
253