Skip to main content

gestalt/
runtime_provider.rs

1// Code generated by sdkgen. DO NOT EDIT.
2
3//! Generated native types and clients for runtime_provider.proto.
4
5use crate::agent::{AgentWorkspace, PreparedAgentWorkspace};
6use crate::codec::host_service::{HostServiceChannel, connect_host_service, plain_channel};
7use crate::codec::runtime_provider::{
8    from_wire_append_runtime_logs_response, from_wire_hosted_app,
9    from_wire_list_runtime_sessions_response, from_wire_prepare_runtime_workspace_response,
10    from_wire_runtime_session, from_wire_runtime_support, to_wire_append_runtime_logs_request,
11    to_wire_get_runtime_session_request, to_wire_list_runtime_sessions_request,
12    to_wire_prepare_runtime_workspace_request, to_wire_remove_runtime_workspace_request,
13    to_wire_start_hosted_app_request, to_wire_start_runtime_session_request,
14    to_wire_stop_runtime_session_request,
15};
16use crate::generated::v1;
17use crate::rpc_support::GestaltError;
18
19/// Open enum for `gestalt.provider.v1.RuntimeEgressMode`; unknown numeric values are preserved.
20pub type RuntimeEgressMode = i32;
21
22/// Named values of `RuntimeEgressMode`.
23pub mod runtime_egress_mode {
24    /// RUNTIME_EGRESS_MODE_UNSPECIFIED.
25    pub const RUNTIME_EGRESS_MODE_UNSPECIFIED: i32 = 0;
26    /// RUNTIME_EGRESS_MODE_NONE.
27    pub const RUNTIME_EGRESS_MODE_NONE: i32 = 1;
28    /// RUNTIME_EGRESS_MODE_CIDR.
29    pub const RUNTIME_EGRESS_MODE_CIDR: i32 = 2;
30    /// RUNTIME_EGRESS_MODE_HOSTNAME.
31    pub const RUNTIME_EGRESS_MODE_HOSTNAME: i32 = 3;
32}
33
34/// Open enum for `gestalt.provider.v1.RuntimeLogStream`; unknown numeric values are preserved.
35pub type RuntimeLogStream = i32;
36
37/// Named values of `RuntimeLogStream`.
38pub mod runtime_log_stream {
39    /// RUNTIME_LOG_STREAM_UNSPECIFIED.
40    pub const RUNTIME_LOG_STREAM_UNSPECIFIED: i32 = 0;
41    /// RUNTIME_LOG_STREAM_STDOUT.
42    pub const RUNTIME_LOG_STREAM_STDOUT: i32 = 1;
43    /// RUNTIME_LOG_STREAM_STDERR.
44    pub const RUNTIME_LOG_STREAM_STDERR: i32 = 2;
45    /// RUNTIME_LOG_STREAM_RUNTIME.
46    pub const RUNTIME_LOG_STREAM_RUNTIME: i32 = 3;
47}
48
49/// Native message type for `gestalt.provider.v1.AppendRuntimeLogsRequest`.
50#[derive(Clone, Debug, Default, PartialEq)]
51pub struct AppendRuntimeLogsRequest {
52    /// The `session_id` field.
53    pub session_id: String,
54    /// The `logs` field.
55    pub logs: Vec<RuntimeLogEntry>,
56}
57
58/// Native message type for `gestalt.provider.v1.AppendRuntimeLogsResponse`.
59#[derive(Clone, Debug, Default, PartialEq)]
60pub struct AppendRuntimeLogsResponse {
61    /// The `last_seq` field.
62    pub last_seq: i64,
63}
64
65/// Native message type for `gestalt.provider.v1.GetRuntimeSessionRequest`.
66#[derive(Clone, Debug, Default, PartialEq)]
67pub struct GetRuntimeSessionRequest {
68    /// The `session_id` field.
69    pub session_id: String,
70}
71
72/// Native message type for `gestalt.provider.v1.HostedApp`.
73#[derive(Clone, Debug, Default, PartialEq)]
74pub struct HostedApp {
75    /// The `id` field.
76    pub id: String,
77    /// The `session_id` field.
78    pub session_id: String,
79    /// The `app_name` field.
80    pub app_name: String,
81    /// The `dial_target` field.
82    pub dial_target: String,
83}
84
85/// Native message type for `gestalt.provider.v1.ListRuntimeSessionsRequest`.
86#[derive(Clone, Debug, Default, PartialEq)]
87pub struct ListRuntimeSessionsRequest {
88    /// The `page_size` field.
89    pub page_size: i32,
90    /// The `page_token` field.
91    pub page_token: String,
92}
93
94/// Native message type for `gestalt.provider.v1.ListRuntimeSessionsResponse`.
95#[derive(Clone, Debug, Default, PartialEq)]
96pub struct ListRuntimeSessionsResponse {
97    /// The `sessions` field.
98    pub sessions: Vec<RuntimeSession>,
99    /// The `next_page_token` field.
100    pub next_page_token: String,
101}
102
103/// Native message type for `gestalt.provider.v1.PrepareRuntimeWorkspaceRequest`.
104#[derive(Clone, Debug, Default, PartialEq)]
105pub struct PrepareRuntimeWorkspaceRequest {
106    /// The `session_id` field.
107    pub session_id: String,
108    /// Opaque, path-safe workspace key minted by the host. Despite the name it
109    /// is not required to match any agent session id; it only identifies the
110    /// prepared workspace directory for later removal.
111    ///
112    /// The `agent_session_id` field.
113    pub agent_session_id: String,
114    /// The `workspace` field; None when unset.
115    pub workspace: Option<AgentWorkspace>,
116}
117
118/// Native message type for `gestalt.provider.v1.PrepareRuntimeWorkspaceResponse`.
119#[derive(Clone, Debug, Default, PartialEq)]
120pub struct PrepareRuntimeWorkspaceResponse {
121    /// The `workspace` field; None when unset.
122    pub workspace: Option<PreparedAgentWorkspace>,
123}
124
125/// Native message type for `gestalt.provider.v1.RemoveRuntimeWorkspaceRequest`.
126#[derive(Clone, Debug, Default, PartialEq)]
127pub struct RemoveRuntimeWorkspaceRequest {
128    /// The `session_id` field.
129    pub session_id: String,
130    /// The workspace key the workspace was prepared under; see
131    /// PrepareRuntimeWorkspaceRequest.agent_session_id.
132    ///
133    /// The `agent_session_id` field.
134    pub agent_session_id: String,
135}
136
137/// Native message type for `gestalt.provider.v1.RuntimeImagePullAuth`.
138#[derive(Clone, Debug, Default, PartialEq)]
139pub struct RuntimeImagePullAuth {
140    /// The `docker_config_json` field.
141    pub docker_config_json: String,
142}
143
144/// Native message type for `gestalt.provider.v1.RuntimeLogEntry`.
145#[derive(Clone, Debug, Default, PartialEq)]
146pub struct RuntimeLogEntry {
147    /// The `stream` field.
148    pub stream: RuntimeLogStream,
149    /// The `message` field.
150    pub message: String,
151    /// The `observed_at` field; None when unset.
152    pub observed_at: Option<std::time::SystemTime>,
153    /// The `source_seq` field.
154    pub source_seq: i64,
155}
156
157/// Native message type for `gestalt.provider.v1.RuntimeSession`.
158#[derive(Clone, Debug, Default, PartialEq)]
159pub struct RuntimeSession {
160    /// The `id` field.
161    pub id: String,
162    /// The `state` field.
163    pub state: String,
164    /// The `metadata` field.
165    pub metadata: std::collections::BTreeMap<String, String>,
166    /// The `lifecycle` field; None when unset.
167    pub lifecycle: Option<RuntimeSessionLifecycle>,
168    /// The `state_reason` field.
169    pub state_reason: String,
170    /// The `state_message` field.
171    pub state_message: String,
172}
173
174/// Native message type for `gestalt.provider.v1.RuntimeSessionLifecycle`.
175#[derive(Clone, Debug, Default, PartialEq)]
176pub struct RuntimeSessionLifecycle {
177    /// The `started_at` field; None when unset.
178    pub started_at: Option<std::time::SystemTime>,
179    /// The `recommended_drain_at` field; None when unset.
180    pub recommended_drain_at: Option<std::time::SystemTime>,
181    /// The `expires_at` field; None when unset.
182    pub expires_at: Option<std::time::SystemTime>,
183}
184
185/// Native message type for `gestalt.provider.v1.RuntimeSupport`.
186#[derive(Clone, Debug, Default, PartialEq)]
187pub struct RuntimeSupport {
188    /// The `can_host_apps` field.
189    pub can_host_apps: bool,
190    /// The `egress_mode` field.
191    pub egress_mode: RuntimeEgressMode,
192    /// The `supports_prepare_workspace` field.
193    pub supports_prepare_workspace: bool,
194}
195
196/// StartHostedAppRequest describes the app process to launch inside a
197/// runtime session. The runtime backend owns allocation and injection of the
198/// app's listener endpoint and returns a host-reachable dial target in the
199/// HostedApp response.
200///
201/// Native message type for `gestalt.provider.v1.StartHostedAppRequest`.
202#[derive(Clone, Debug, Default, PartialEq)]
203pub struct StartHostedAppRequest {
204    /// The `session_id` field.
205    pub session_id: String,
206    /// The `app_name` field.
207    pub app_name: String,
208    /// The `command` field.
209    pub command: String,
210    /// The `args` field.
211    pub args: Vec<String>,
212    /// The `env` field.
213    pub env: std::collections::BTreeMap<String, String>,
214    /// The `allowed_hosts` field.
215    pub allowed_hosts: Vec<String>,
216    /// The `default_action` field.
217    pub default_action: String,
218    /// The `host_binary` field.
219    pub host_binary: String,
220    /// The `workdir` field.
221    pub workdir: String,
222}
223
224/// Native message type for `gestalt.provider.v1.StartRuntimeSessionRequest`.
225#[derive(Clone, Debug, Default, PartialEq)]
226pub struct StartRuntimeSessionRequest {
227    /// The `app_name` field.
228    pub app_name: String,
229    /// The `template` field.
230    pub template: String,
231    /// The `image` field.
232    pub image: String,
233    /// The `metadata` field.
234    pub metadata: std::collections::BTreeMap<String, String>,
235    /// The `image_pull_auth` field; None when unset.
236    pub image_pull_auth: Option<RuntimeImagePullAuth>,
237}
238
239/// Native message type for `gestalt.provider.v1.StopRuntimeSessionRequest`.
240#[derive(Clone, Debug, Default, PartialEq)]
241pub struct StopRuntimeSessionRequest {
242    /// The `session_id` field.
243    pub session_id: String,
244}
245
246/// Client for the `gestalt.provider.v1.Runtime` service.
247pub struct Runtime {
248    inner: v1::runtime_client::RuntimeClient<tonic::transport::Channel>,
249    timeout: Option<std::time::Duration>,
250}
251
252impl Runtime {
253    /// Creates a client over an established channel.
254    pub fn new(channel: tonic::transport::Channel) -> Self {
255        Self {
256            inner: v1::runtime_client::RuntimeClient::new(channel),
257            timeout: None,
258        }
259    }
260
261    /// Sets a deadline applied to every unary call; calls that run past it
262    /// fail with DEADLINE_EXCEEDED. Streaming calls are unaffected.
263    pub fn with_timeout(mut self, timeout: std::time::Duration) -> Self {
264        self.timeout = Some(timeout);
265        self
266    }
267
268    /// Calls `gestalt.provider.v1.Runtime.GetSupport`.
269    pub async fn get_support(&mut self) -> Result<RuntimeSupport, GestaltError> {
270        let mut tonic_request = tonic::Request::new(());
271        if let Some(timeout) = self.timeout {
272            tonic_request.set_timeout(timeout);
273        }
274        let response = self.inner.get_support(tonic_request).await?;
275        Ok(from_wire_runtime_support(response.into_inner()))
276    }
277
278    /// Calls `gestalt.provider.v1.Runtime.StartSession`.
279    pub async fn start_session(
280        &mut self,
281        app_name: String,
282        template: String,
283        image: String,
284        image_pull_auth: Option<RuntimeImagePullAuth>,
285    ) -> Result<RuntimeSession, GestaltError> {
286        let request = StartRuntimeSessionRequest {
287            app_name,
288            template,
289            image,
290            image_pull_auth,
291            ..Default::default()
292        };
293        let mut tonic_request = tonic::Request::new(to_wire_start_runtime_session_request(request));
294        if let Some(timeout) = self.timeout {
295            tonic_request.set_timeout(timeout);
296        }
297        let response = self.inner.start_session(tonic_request).await?;
298        Ok(from_wire_runtime_session(response.into_inner()))
299    }
300
301    /// Calls `gestalt.provider.v1.Runtime.StartSession` with the full request and response messages.
302    pub async fn start_session_raw(
303        &mut self,
304        request: StartRuntimeSessionRequest,
305    ) -> Result<RuntimeSession, GestaltError> {
306        let mut tonic_request = tonic::Request::new(to_wire_start_runtime_session_request(request));
307        if let Some(timeout) = self.timeout {
308            tonic_request.set_timeout(timeout);
309        }
310        let response = self.inner.start_session(tonic_request).await?;
311        Ok(from_wire_runtime_session(response.into_inner()))
312    }
313
314    /// Calls `gestalt.provider.v1.Runtime.GetSession`.
315    pub async fn get_session(
316        &mut self,
317        session_id: String,
318    ) -> Result<RuntimeSession, GestaltError> {
319        let request = GetRuntimeSessionRequest { session_id };
320        let mut tonic_request = tonic::Request::new(to_wire_get_runtime_session_request(request));
321        if let Some(timeout) = self.timeout {
322            tonic_request.set_timeout(timeout);
323        }
324        let response = self.inner.get_session(tonic_request).await?;
325        Ok(from_wire_runtime_session(response.into_inner()))
326    }
327
328    /// Calls `gestalt.provider.v1.Runtime.GetSession` with the full request and response messages.
329    pub async fn get_session_raw(
330        &mut self,
331        request: GetRuntimeSessionRequest,
332    ) -> Result<RuntimeSession, GestaltError> {
333        let mut tonic_request = tonic::Request::new(to_wire_get_runtime_session_request(request));
334        if let Some(timeout) = self.timeout {
335            tonic_request.set_timeout(timeout);
336        }
337        let response = self.inner.get_session(tonic_request).await?;
338        Ok(from_wire_runtime_session(response.into_inner()))
339    }
340
341    /// Calls `gestalt.provider.v1.Runtime.ListSessions`.
342    pub async fn list_sessions(
343        &mut self,
344        request: ListRuntimeSessionsRequest,
345    ) -> Result<ListRuntimeSessionsResponse, GestaltError> {
346        let mut tonic_request = tonic::Request::new(to_wire_list_runtime_sessions_request(request));
347        if let Some(timeout) = self.timeout {
348            tonic_request.set_timeout(timeout);
349        }
350        let response = self.inner.list_sessions(tonic_request).await?;
351        Ok(from_wire_list_runtime_sessions_response(
352            response.into_inner(),
353        ))
354    }
355
356    /// Calls `gestalt.provider.v1.Runtime.StopSession`.
357    pub async fn stop_session(&mut self, session_id: String) -> Result<(), GestaltError> {
358        let request = StopRuntimeSessionRequest { session_id };
359        let mut tonic_request = tonic::Request::new(to_wire_stop_runtime_session_request(request));
360        if let Some(timeout) = self.timeout {
361            tonic_request.set_timeout(timeout);
362        }
363        self.inner.stop_session(tonic_request).await?;
364        Ok(())
365    }
366
367    /// Calls `gestalt.provider.v1.Runtime.StopSession` with the full request and response messages.
368    pub async fn stop_session_raw(
369        &mut self,
370        request: StopRuntimeSessionRequest,
371    ) -> Result<(), GestaltError> {
372        let mut tonic_request = tonic::Request::new(to_wire_stop_runtime_session_request(request));
373        if let Some(timeout) = self.timeout {
374            tonic_request.set_timeout(timeout);
375        }
376        self.inner.stop_session(tonic_request).await?;
377        Ok(())
378    }
379
380    /// Calls `gestalt.provider.v1.Runtime.PrepareWorkspace`.
381    pub async fn prepare_workspace(
382        &mut self,
383        session_id: String,
384        agent_session_id: String,
385        workspace: Option<AgentWorkspace>,
386    ) -> Result<Option<PreparedAgentWorkspace>, GestaltError> {
387        let request = PrepareRuntimeWorkspaceRequest {
388            session_id,
389            agent_session_id,
390            workspace,
391        };
392        let mut tonic_request =
393            tonic::Request::new(to_wire_prepare_runtime_workspace_request(request));
394        if let Some(timeout) = self.timeout {
395            tonic_request.set_timeout(timeout);
396        }
397        let response = from_wire_prepare_runtime_workspace_response(
398            self.inner
399                .prepare_workspace(tonic_request)
400                .await?
401                .into_inner(),
402        );
403        Ok(response.workspace)
404    }
405
406    /// Calls `gestalt.provider.v1.Runtime.PrepareWorkspace` with the full request and response messages.
407    pub async fn prepare_workspace_raw(
408        &mut self,
409        request: PrepareRuntimeWorkspaceRequest,
410    ) -> Result<PrepareRuntimeWorkspaceResponse, GestaltError> {
411        let mut tonic_request =
412            tonic::Request::new(to_wire_prepare_runtime_workspace_request(request));
413        if let Some(timeout) = self.timeout {
414            tonic_request.set_timeout(timeout);
415        }
416        let response = self.inner.prepare_workspace(tonic_request).await?;
417        Ok(from_wire_prepare_runtime_workspace_response(
418            response.into_inner(),
419        ))
420    }
421
422    /// Calls `gestalt.provider.v1.Runtime.RemoveWorkspace`.
423    pub async fn remove_workspace(
424        &mut self,
425        session_id: String,
426        agent_session_id: String,
427    ) -> Result<(), GestaltError> {
428        let request = RemoveRuntimeWorkspaceRequest {
429            session_id,
430            agent_session_id,
431        };
432        let mut tonic_request =
433            tonic::Request::new(to_wire_remove_runtime_workspace_request(request));
434        if let Some(timeout) = self.timeout {
435            tonic_request.set_timeout(timeout);
436        }
437        self.inner.remove_workspace(tonic_request).await?;
438        Ok(())
439    }
440
441    /// Calls `gestalt.provider.v1.Runtime.RemoveWorkspace` with the full request and response messages.
442    pub async fn remove_workspace_raw(
443        &mut self,
444        request: RemoveRuntimeWorkspaceRequest,
445    ) -> Result<(), GestaltError> {
446        let mut tonic_request =
447            tonic::Request::new(to_wire_remove_runtime_workspace_request(request));
448        if let Some(timeout) = self.timeout {
449            tonic_request.set_timeout(timeout);
450        }
451        self.inner.remove_workspace(tonic_request).await?;
452        Ok(())
453    }
454
455    /// Calls `gestalt.provider.v1.Runtime.StartApp`.
456    #[allow(clippy::too_many_arguments)]
457    pub async fn start_app(
458        &mut self,
459        session_id: String,
460        app_name: String,
461        command: String,
462        args: Vec<String>,
463        allowed_hosts: Vec<String>,
464        default_action: String,
465        host_binary: String,
466        workdir: String,
467    ) -> Result<HostedApp, GestaltError> {
468        let request = StartHostedAppRequest {
469            session_id,
470            app_name,
471            command,
472            args,
473            allowed_hosts,
474            default_action,
475            host_binary,
476            workdir,
477            ..Default::default()
478        };
479        let mut tonic_request = tonic::Request::new(to_wire_start_hosted_app_request(request));
480        if let Some(timeout) = self.timeout {
481            tonic_request.set_timeout(timeout);
482        }
483        let response = self.inner.start_app(tonic_request).await?;
484        Ok(from_wire_hosted_app(response.into_inner()))
485    }
486
487    /// Calls `gestalt.provider.v1.Runtime.StartApp` with the full request and response messages.
488    pub async fn start_app_raw(
489        &mut self,
490        request: StartHostedAppRequest,
491    ) -> Result<HostedApp, GestaltError> {
492        let mut tonic_request = tonic::Request::new(to_wire_start_hosted_app_request(request));
493        if let Some(timeout) = self.timeout {
494            tonic_request.set_timeout(timeout);
495        }
496        let response = self.inner.start_app(tonic_request).await?;
497        Ok(from_wire_hosted_app(response.into_inner()))
498    }
499}
500
501/// Client for the `gestalt.provider.v1.RuntimeLogHost` service.
502pub struct RuntimeLogHost {
503    inner: v1::runtime_log_host_client::RuntimeLogHostClient<HostServiceChannel>,
504    timeout: Option<std::time::Duration>,
505}
506
507impl RuntimeLogHost {
508    /// Creates a client over an established channel.
509    pub fn new(channel: tonic::transport::Channel) -> Self {
510        Self {
511            inner: v1::runtime_log_host_client::RuntimeLogHostClient::new(plain_channel(channel)),
512            timeout: None,
513        }
514    }
515
516    /// Sets a deadline applied to every unary call; calls that run past it
517    /// fail with DEADLINE_EXCEEDED. Streaming calls are unaffected.
518    pub fn with_timeout(mut self, timeout: std::time::Duration) -> Self {
519        self.timeout = Some(timeout);
520        self
521    }
522
523    /// Connects to the `runtime log host` host service described by the environment.
524    pub async fn connect() -> Result<Self, GestaltError> {
525        Self::connect_named("").await
526    }
527
528    /// Connects to the named `runtime log host` host-service binding.
529    pub async fn connect_named(name: &str) -> Result<Self, GestaltError> {
530        Ok(Self {
531            inner: v1::runtime_log_host_client::RuntimeLogHostClient::new(
532                connect_host_service("runtime log host", name).await?,
533            ),
534            timeout: None,
535        })
536    }
537
538    /// Calls `gestalt.provider.v1.RuntimeLogHost.AppendLogs`.
539    pub async fn append_logs(
540        &mut self,
541        session_id: String,
542        logs: Vec<RuntimeLogEntry>,
543    ) -> Result<i64, GestaltError> {
544        let request = AppendRuntimeLogsRequest { session_id, logs };
545        let mut tonic_request = tonic::Request::new(to_wire_append_runtime_logs_request(request));
546        if let Some(timeout) = self.timeout {
547            tonic_request.set_timeout(timeout);
548        }
549        let response = from_wire_append_runtime_logs_response(
550            self.inner.append_logs(tonic_request).await?.into_inner(),
551        );
552        Ok(response.last_seq)
553    }
554
555    /// Calls `gestalt.provider.v1.RuntimeLogHost.AppendLogs` with the full request and response messages.
556    pub async fn append_logs_raw(
557        &mut self,
558        request: AppendRuntimeLogsRequest,
559    ) -> Result<AppendRuntimeLogsResponse, GestaltError> {
560        let mut tonic_request = tonic::Request::new(to_wire_append_runtime_logs_request(request));
561        if let Some(timeout) = self.timeout {
562            tonic_request.set_timeout(timeout);
563        }
564        let response = self.inner.append_logs(tonic_request).await?;
565        Ok(from_wire_append_runtime_logs_response(
566            response.into_inner(),
567        ))
568    }
569}