gestalt-sdk 0.0.1-alpha.19

Rust SDK scaffolding and generated protocol bindings for Gestalt executable providers
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
// Code generated by sdkgen. DO NOT EDIT.

//! Generated native types and clients for runtime_provider.proto.

use crate::agent::{AgentWorkspace, PreparedAgentWorkspace};
use crate::codec::host_service::{HostServiceChannel, connect_host_service, plain_channel};
use crate::codec::runtime_provider::{
    from_wire_append_runtime_logs_response, from_wire_hosted_app,
    from_wire_list_runtime_sessions_response, from_wire_prepare_runtime_workspace_response,
    from_wire_runtime_session, from_wire_runtime_support, to_wire_append_runtime_logs_request,
    to_wire_get_runtime_session_request, to_wire_list_runtime_sessions_request,
    to_wire_prepare_runtime_workspace_request, to_wire_remove_runtime_workspace_request,
    to_wire_start_hosted_app_request, to_wire_start_runtime_session_request,
    to_wire_stop_runtime_session_request,
};
use crate::generated::v1;
use crate::rpc_support::GestaltError;

/// Open enum for `gestalt.provider.v1.RuntimeEgressMode`; unknown numeric values are preserved.
pub type RuntimeEgressMode = i32;

/// Named values of `RuntimeEgressMode`.
pub mod runtime_egress_mode {
    /// RUNTIME_EGRESS_MODE_UNSPECIFIED.
    pub const RUNTIME_EGRESS_MODE_UNSPECIFIED: i32 = 0;
    /// RUNTIME_EGRESS_MODE_NONE.
    pub const RUNTIME_EGRESS_MODE_NONE: i32 = 1;
    /// RUNTIME_EGRESS_MODE_CIDR.
    pub const RUNTIME_EGRESS_MODE_CIDR: i32 = 2;
    /// RUNTIME_EGRESS_MODE_HOSTNAME.
    pub const RUNTIME_EGRESS_MODE_HOSTNAME: i32 = 3;
}

/// Open enum for `gestalt.provider.v1.RuntimeLogStream`; unknown numeric values are preserved.
pub type RuntimeLogStream = i32;

/// Named values of `RuntimeLogStream`.
pub mod runtime_log_stream {
    /// RUNTIME_LOG_STREAM_UNSPECIFIED.
    pub const RUNTIME_LOG_STREAM_UNSPECIFIED: i32 = 0;
    /// RUNTIME_LOG_STREAM_STDOUT.
    pub const RUNTIME_LOG_STREAM_STDOUT: i32 = 1;
    /// RUNTIME_LOG_STREAM_STDERR.
    pub const RUNTIME_LOG_STREAM_STDERR: i32 = 2;
    /// RUNTIME_LOG_STREAM_RUNTIME.
    pub const RUNTIME_LOG_STREAM_RUNTIME: i32 = 3;
}

/// Native message type for `gestalt.provider.v1.AppendRuntimeLogsRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct AppendRuntimeLogsRequest {
    /// The `session_id` field.
    pub session_id: String,
    /// The `logs` field.
    pub logs: Vec<RuntimeLogEntry>,
}

/// Native message type for `gestalt.provider.v1.AppendRuntimeLogsResponse`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct AppendRuntimeLogsResponse {
    /// The `last_seq` field.
    pub last_seq: i64,
}

/// Native message type for `gestalt.provider.v1.GetRuntimeSessionRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct GetRuntimeSessionRequest {
    /// The `session_id` field.
    pub session_id: String,
}

/// Native message type for `gestalt.provider.v1.HostedApp`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct HostedApp {
    /// The `id` field.
    pub id: String,
    /// The `session_id` field.
    pub session_id: String,
    /// The `app_name` field.
    pub app_name: String,
    /// The `dial_target` field.
    pub dial_target: String,
}

/// Native message type for `gestalt.provider.v1.ListRuntimeSessionsRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ListRuntimeSessionsRequest {
    /// The `page_size` field.
    pub page_size: i32,
    /// The `page_token` field.
    pub page_token: String,
}

/// Native message type for `gestalt.provider.v1.ListRuntimeSessionsResponse`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ListRuntimeSessionsResponse {
    /// The `sessions` field.
    pub sessions: Vec<RuntimeSession>,
    /// The `next_page_token` field.
    pub next_page_token: String,
}

/// Native message type for `gestalt.provider.v1.PrepareRuntimeWorkspaceRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct PrepareRuntimeWorkspaceRequest {
    /// The `session_id` field.
    pub session_id: String,
    /// Opaque, path-safe workspace key minted by the host. Despite the name it
    /// is not required to match any agent session id; it only identifies the
    /// prepared workspace directory for later removal.
    ///
    /// The `agent_session_id` field.
    pub agent_session_id: String,
    /// The `workspace` field; None when unset.
    pub workspace: Option<AgentWorkspace>,
}

/// Native message type for `gestalt.provider.v1.PrepareRuntimeWorkspaceResponse`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct PrepareRuntimeWorkspaceResponse {
    /// The `workspace` field; None when unset.
    pub workspace: Option<PreparedAgentWorkspace>,
}

/// Native message type for `gestalt.provider.v1.RemoveRuntimeWorkspaceRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct RemoveRuntimeWorkspaceRequest {
    /// The `session_id` field.
    pub session_id: String,
    /// The workspace key the workspace was prepared under; see
    /// PrepareRuntimeWorkspaceRequest.agent_session_id.
    ///
    /// The `agent_session_id` field.
    pub agent_session_id: String,
}

/// Native message type for `gestalt.provider.v1.RuntimeImagePullAuth`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct RuntimeImagePullAuth {
    /// The `docker_config_json` field.
    pub docker_config_json: String,
}

/// Native message type for `gestalt.provider.v1.RuntimeLogEntry`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct RuntimeLogEntry {
    /// The `stream` field.
    pub stream: RuntimeLogStream,
    /// The `message` field.
    pub message: String,
    /// The `observed_at` field; None when unset.
    pub observed_at: Option<std::time::SystemTime>,
    /// The `source_seq` field.
    pub source_seq: i64,
}

/// Native message type for `gestalt.provider.v1.RuntimeSession`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct RuntimeSession {
    /// The `id` field.
    pub id: String,
    /// The `state` field.
    pub state: String,
    /// The `metadata` field.
    pub metadata: std::collections::BTreeMap<String, String>,
    /// The `lifecycle` field; None when unset.
    pub lifecycle: Option<RuntimeSessionLifecycle>,
    /// The `state_reason` field.
    pub state_reason: String,
    /// The `state_message` field.
    pub state_message: String,
}

/// Native message type for `gestalt.provider.v1.RuntimeSessionLifecycle`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct RuntimeSessionLifecycle {
    /// The `started_at` field; None when unset.
    pub started_at: Option<std::time::SystemTime>,
    /// The `recommended_drain_at` field; None when unset.
    pub recommended_drain_at: Option<std::time::SystemTime>,
    /// The `expires_at` field; None when unset.
    pub expires_at: Option<std::time::SystemTime>,
}

/// Native message type for `gestalt.provider.v1.RuntimeSupport`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct RuntimeSupport {
    /// The `can_host_apps` field.
    pub can_host_apps: bool,
    /// The `egress_mode` field.
    pub egress_mode: RuntimeEgressMode,
    /// The `supports_prepare_workspace` field.
    pub supports_prepare_workspace: bool,
}

/// StartHostedAppRequest describes the app process to launch inside a
/// runtime session. The runtime backend owns allocation and injection of the
/// app's listener endpoint and returns a host-reachable dial target in the
/// HostedApp response.
///
/// Native message type for `gestalt.provider.v1.StartHostedAppRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct StartHostedAppRequest {
    /// The `session_id` field.
    pub session_id: String,
    /// The `app_name` field.
    pub app_name: String,
    /// The `command` field.
    pub command: String,
    /// The `args` field.
    pub args: Vec<String>,
    /// The `env` field.
    pub env: std::collections::BTreeMap<String, String>,
    /// The `allowed_hosts` field.
    pub allowed_hosts: Vec<String>,
    /// The `default_action` field.
    pub default_action: String,
    /// The `host_binary` field.
    pub host_binary: String,
    /// The `workdir` field.
    pub workdir: String,
}

/// Native message type for `gestalt.provider.v1.StartRuntimeSessionRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct StartRuntimeSessionRequest {
    /// The `app_name` field.
    pub app_name: String,
    /// The `template` field.
    pub template: String,
    /// The `image` field.
    pub image: String,
    /// The `metadata` field.
    pub metadata: std::collections::BTreeMap<String, String>,
    /// The `image_pull_auth` field; None when unset.
    pub image_pull_auth: Option<RuntimeImagePullAuth>,
}

/// Native message type for `gestalt.provider.v1.StopRuntimeSessionRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct StopRuntimeSessionRequest {
    /// The `session_id` field.
    pub session_id: String,
}

/// Client for the `gestalt.provider.v1.Runtime` service.
pub struct Runtime {
    inner: v1::runtime_client::RuntimeClient<tonic::transport::Channel>,
    timeout: Option<std::time::Duration>,
}

impl Runtime {
    /// Creates a client over an established channel.
    pub fn new(channel: tonic::transport::Channel) -> Self {
        Self {
            inner: v1::runtime_client::RuntimeClient::new(channel),
            timeout: None,
        }
    }

    /// Sets a deadline applied to every unary call; calls that run past it
    /// fail with DEADLINE_EXCEEDED. Streaming calls are unaffected.
    pub fn with_timeout(mut self, timeout: std::time::Duration) -> Self {
        self.timeout = Some(timeout);
        self
    }

    /// Calls `gestalt.provider.v1.Runtime.GetSupport`.
    pub async fn get_support(&mut self) -> Result<RuntimeSupport, GestaltError> {
        let mut tonic_request = tonic::Request::new(());
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.get_support(tonic_request).await?;
        Ok(from_wire_runtime_support(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.Runtime.StartSession`.
    pub async fn start_session(
        &mut self,
        app_name: String,
        template: String,
        image: String,
        image_pull_auth: Option<RuntimeImagePullAuth>,
    ) -> Result<RuntimeSession, GestaltError> {
        let request = StartRuntimeSessionRequest {
            app_name,
            template,
            image,
            image_pull_auth,
            ..Default::default()
        };
        let mut tonic_request = tonic::Request::new(to_wire_start_runtime_session_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.start_session(tonic_request).await?;
        Ok(from_wire_runtime_session(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.Runtime.StartSession` with the full request and response messages.
    pub async fn start_session_raw(
        &mut self,
        request: StartRuntimeSessionRequest,
    ) -> Result<RuntimeSession, GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_start_runtime_session_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.start_session(tonic_request).await?;
        Ok(from_wire_runtime_session(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.Runtime.GetSession`.
    pub async fn get_session(
        &mut self,
        session_id: String,
    ) -> Result<RuntimeSession, GestaltError> {
        let request = GetRuntimeSessionRequest { session_id };
        let mut tonic_request = tonic::Request::new(to_wire_get_runtime_session_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.get_session(tonic_request).await?;
        Ok(from_wire_runtime_session(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.Runtime.GetSession` with the full request and response messages.
    pub async fn get_session_raw(
        &mut self,
        request: GetRuntimeSessionRequest,
    ) -> Result<RuntimeSession, GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_get_runtime_session_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.get_session(tonic_request).await?;
        Ok(from_wire_runtime_session(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.Runtime.ListSessions`.
    pub async fn list_sessions(
        &mut self,
        request: ListRuntimeSessionsRequest,
    ) -> Result<ListRuntimeSessionsResponse, GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_list_runtime_sessions_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.list_sessions(tonic_request).await?;
        Ok(from_wire_list_runtime_sessions_response(
            response.into_inner(),
        ))
    }

    /// Calls `gestalt.provider.v1.Runtime.StopSession`.
    pub async fn stop_session(&mut self, session_id: String) -> Result<(), GestaltError> {
        let request = StopRuntimeSessionRequest { session_id };
        let mut tonic_request = tonic::Request::new(to_wire_stop_runtime_session_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        self.inner.stop_session(tonic_request).await?;
        Ok(())
    }

    /// Calls `gestalt.provider.v1.Runtime.StopSession` with the full request and response messages.
    pub async fn stop_session_raw(
        &mut self,
        request: StopRuntimeSessionRequest,
    ) -> Result<(), GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_stop_runtime_session_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        self.inner.stop_session(tonic_request).await?;
        Ok(())
    }

    /// Calls `gestalt.provider.v1.Runtime.PrepareWorkspace`.
    pub async fn prepare_workspace(
        &mut self,
        session_id: String,
        agent_session_id: String,
        workspace: Option<AgentWorkspace>,
    ) -> Result<Option<PreparedAgentWorkspace>, GestaltError> {
        let request = PrepareRuntimeWorkspaceRequest {
            session_id,
            agent_session_id,
            workspace,
        };
        let mut tonic_request =
            tonic::Request::new(to_wire_prepare_runtime_workspace_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = from_wire_prepare_runtime_workspace_response(
            self.inner
                .prepare_workspace(tonic_request)
                .await?
                .into_inner(),
        );
        Ok(response.workspace)
    }

    /// Calls `gestalt.provider.v1.Runtime.PrepareWorkspace` with the full request and response messages.
    pub async fn prepare_workspace_raw(
        &mut self,
        request: PrepareRuntimeWorkspaceRequest,
    ) -> Result<PrepareRuntimeWorkspaceResponse, GestaltError> {
        let mut tonic_request =
            tonic::Request::new(to_wire_prepare_runtime_workspace_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.prepare_workspace(tonic_request).await?;
        Ok(from_wire_prepare_runtime_workspace_response(
            response.into_inner(),
        ))
    }

    /// Calls `gestalt.provider.v1.Runtime.RemoveWorkspace`.
    pub async fn remove_workspace(
        &mut self,
        session_id: String,
        agent_session_id: String,
    ) -> Result<(), GestaltError> {
        let request = RemoveRuntimeWorkspaceRequest {
            session_id,
            agent_session_id,
        };
        let mut tonic_request =
            tonic::Request::new(to_wire_remove_runtime_workspace_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        self.inner.remove_workspace(tonic_request).await?;
        Ok(())
    }

    /// Calls `gestalt.provider.v1.Runtime.RemoveWorkspace` with the full request and response messages.
    pub async fn remove_workspace_raw(
        &mut self,
        request: RemoveRuntimeWorkspaceRequest,
    ) -> Result<(), GestaltError> {
        let mut tonic_request =
            tonic::Request::new(to_wire_remove_runtime_workspace_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        self.inner.remove_workspace(tonic_request).await?;
        Ok(())
    }

    /// Calls `gestalt.provider.v1.Runtime.StartApp`.
    #[allow(clippy::too_many_arguments)]
    pub async fn start_app(
        &mut self,
        session_id: String,
        app_name: String,
        command: String,
        args: Vec<String>,
        allowed_hosts: Vec<String>,
        default_action: String,
        host_binary: String,
        workdir: String,
    ) -> Result<HostedApp, GestaltError> {
        let request = StartHostedAppRequest {
            session_id,
            app_name,
            command,
            args,
            allowed_hosts,
            default_action,
            host_binary,
            workdir,
            ..Default::default()
        };
        let mut tonic_request = tonic::Request::new(to_wire_start_hosted_app_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.start_app(tonic_request).await?;
        Ok(from_wire_hosted_app(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.Runtime.StartApp` with the full request and response messages.
    pub async fn start_app_raw(
        &mut self,
        request: StartHostedAppRequest,
    ) -> Result<HostedApp, GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_start_hosted_app_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.start_app(tonic_request).await?;
        Ok(from_wire_hosted_app(response.into_inner()))
    }
}

/// Client for the `gestalt.provider.v1.RuntimeLogHost` service.
pub struct RuntimeLogHost {
    inner: v1::runtime_log_host_client::RuntimeLogHostClient<HostServiceChannel>,
    timeout: Option<std::time::Duration>,
}

impl RuntimeLogHost {
    /// Creates a client over an established channel.
    pub fn new(channel: tonic::transport::Channel) -> Self {
        Self {
            inner: v1::runtime_log_host_client::RuntimeLogHostClient::new(plain_channel(channel)),
            timeout: None,
        }
    }

    /// Sets a deadline applied to every unary call; calls that run past it
    /// fail with DEADLINE_EXCEEDED. Streaming calls are unaffected.
    pub fn with_timeout(mut self, timeout: std::time::Duration) -> Self {
        self.timeout = Some(timeout);
        self
    }

    /// Connects to the `runtime log host` host service described by the environment.
    pub async fn connect() -> Result<Self, GestaltError> {
        Self::connect_named("").await
    }

    /// Connects to the named `runtime log host` host-service binding.
    pub async fn connect_named(name: &str) -> Result<Self, GestaltError> {
        Ok(Self {
            inner: v1::runtime_log_host_client::RuntimeLogHostClient::new(
                connect_host_service("runtime log host", name).await?,
            ),
            timeout: None,
        })
    }

    /// Calls `gestalt.provider.v1.RuntimeLogHost.AppendLogs`.
    pub async fn append_logs(
        &mut self,
        session_id: String,
        logs: Vec<RuntimeLogEntry>,
    ) -> Result<i64, GestaltError> {
        let request = AppendRuntimeLogsRequest { session_id, logs };
        let mut tonic_request = tonic::Request::new(to_wire_append_runtime_logs_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = from_wire_append_runtime_logs_response(
            self.inner.append_logs(tonic_request).await?.into_inner(),
        );
        Ok(response.last_seq)
    }

    /// Calls `gestalt.provider.v1.RuntimeLogHost.AppendLogs` with the full request and response messages.
    pub async fn append_logs_raw(
        &mut self,
        request: AppendRuntimeLogsRequest,
    ) -> Result<AppendRuntimeLogsResponse, GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_append_runtime_logs_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.append_logs(tonic_request).await?;
        Ok(from_wire_append_runtime_logs_response(
            response.into_inner(),
        ))
    }
}