Skip to main content

hanzo_client/apis/
bot_api.rs

1/*
2 * Hanzo Cloud API
3 *
4 * The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_bot_runs`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetBotRunsError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`post_bot_runs`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum PostBotRunsError {
29    Status501(),
30    UnknownValue(serde_json::Value),
31}
32
33/// struct for typed errors of method [`post_bot_runs_by_runid_stop`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum PostBotRunsByRunidStopError {
37    UnknownValue(serde_json::Value),
38}
39
40
41/// List returns the caller org's live bot runs, read from the bot runtime and projected into the console contract with each run's live session URL derived here.  The org is ALWAYS the validated principal's org, NEVER a request field, and it is what scopes the runtime's answer — so one tenant can never enumerate another's runs. A runtime that cannot answer is an error, not an empty list: [] would tell the caller \"your org has no runs\", which is a different claim from \"we could not ask\", and the difference is the whole reason this endpoint exists.
42pub async fn get_bot_runs(configuration: &configuration::Configuration, ) -> Result<models::BotRuns, Error<GetBotRunsError>> {
43
44    let uri_str = format!("{}/v1/bot/runs", configuration.base_path);
45    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
46
47    if let Some(ref user_agent) = configuration.user_agent {
48        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
49    }
50    if let Some(ref token) = configuration.bearer_access_token {
51        req_builder = req_builder.bearer_auth(token.to_owned());
52    };
53
54    let req = req_builder.build()?;
55    let resp = configuration.client.execute(req).await?;
56
57    let status = resp.status();
58    let content_type = resp
59        .headers()
60        .get("content-type")
61        .and_then(|v| v.to_str().ok())
62        .unwrap_or("application/octet-stream");
63    let content_type = super::ContentType::from(content_type);
64
65    if !status.is_client_error() && !status.is_server_error() {
66        let content = resp.text().await?;
67        match content_type {
68            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
69            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BotRuns`"))),
70            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BotRuns`")))),
71        }
72    } else {
73        let content = resp.text().await?;
74        let entity: Option<GetBotRunsError> = serde_json::from_str(&content).ok();
75        Err(Error::ResponseError(ResponseContent { status, content, entity }))
76    }
77}
78
79/// Answers 501 to every call: launching a bot run is not implemented.  The bot runtime exposes no launch operation, so nothing here can start a sandbox. This address is published rather than dropped because it is the collection every run is created in: GET lists them, POST would launch one.  The refusal is total and takes no input. No run id is minted, no session URL is handed back, and no per-run fee is charged. That is the point: the earlier version minted an id the runtime had never heard of, pointed it at a VNC node that did not exist, and took real money for it. 501 is the truth, and the truth is cheaper than a plausible lie.  Listing and stopping runs are live and org-scoped. Only the launch is missing, and it returns in the same change that can prove a bot boots — a runtime-side launch operation first (TS, cross-repo), with the entitlement gate and the meter beside it.
80pub async fn post_bot_runs(configuration: &configuration::Configuration, ) -> Result<(), Error<PostBotRunsError>> {
81
82    let uri_str = format!("{}/v1/bot/runs", configuration.base_path);
83    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
84
85    if let Some(ref user_agent) = configuration.user_agent {
86        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
87    }
88    if let Some(ref token) = configuration.bearer_access_token {
89        req_builder = req_builder.bearer_auth(token.to_owned());
90    };
91
92    let req = req_builder.build()?;
93    let resp = configuration.client.execute(req).await?;
94
95    let status = resp.status();
96
97    if !status.is_client_error() && !status.is_server_error() {
98        Ok(())
99    } else {
100        let content = resp.text().await?;
101        let entity: Option<PostBotRunsError> = serde_json::from_str(&content).ok();
102        Err(Error::ResponseError(ResponseContent { status, content, entity }))
103    }
104}
105
106/// Stop terminates one of the caller org's own bot runs and reports its terminal state.  The own-key guard is the org: it is the caller's validated org, never theirs to choose, and the runtime resolves the run id UNDER it. A run belonging to another tenant is not among this org's runs, so it answers absent — the same 404 a nonexistent id gets, which is what keeps this from being an oracle.  Absence is honoured ONLY when the runtime answers it. A runtime that does not serve stop reports nothing about the run, and reporting \"stopped\" on that basis would be a stop that cannot fail — so it is a 502.
107pub async fn post_bot_runs_by_runid_stop(configuration: &configuration::Configuration, run_id: &str) -> Result<models::BotStopped, Error<PostBotRunsByRunidStopError>> {
108    // add a prefix to parameters to efficiently prevent name collisions
109    let p_run_id = run_id;
110
111    let uri_str = format!("{}/v1/bot/runs/{runId}/stop", configuration.base_path, runId=crate::apis::urlencode(p_run_id));
112    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
113
114    if let Some(ref user_agent) = configuration.user_agent {
115        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
116    }
117    if let Some(ref token) = configuration.bearer_access_token {
118        req_builder = req_builder.bearer_auth(token.to_owned());
119    };
120
121    let req = req_builder.build()?;
122    let resp = configuration.client.execute(req).await?;
123
124    let status = resp.status();
125    let content_type = resp
126        .headers()
127        .get("content-type")
128        .and_then(|v| v.to_str().ok())
129        .unwrap_or("application/octet-stream");
130    let content_type = super::ContentType::from(content_type);
131
132    if !status.is_client_error() && !status.is_server_error() {
133        let content = resp.text().await?;
134        match content_type {
135            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
136            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BotStopped`"))),
137            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BotStopped`")))),
138        }
139    } else {
140        let content = resp.text().await?;
141        let entity: Option<PostBotRunsByRunidStopError> = serde_json::from_str(&content).ok();
142        Err(Error::ResponseError(ResponseContent { status, content, entity }))
143    }
144}
145