Skip to main content

agentkernel_sdk/
types.rs

1use serde::{Deserialize, Serialize};
2
3/// Security profile for sandbox execution.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5#[serde(rename_all = "lowercase")]
6pub enum SecurityProfile {
7    Permissive,
8    Moderate,
9    Restrictive,
10}
11
12/// Options for running a command.
13#[derive(Debug, Default, Serialize)]
14pub struct RunOptions {
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub image: Option<String>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub profile: Option<SecurityProfile>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub fast: Option<bool>,
21}
22
23/// Output from a command execution.
24#[derive(Debug, Deserialize)]
25pub struct RunOutput {
26    pub output: String,
27}
28
29/// Information about a sandbox.
30#[derive(Debug, Deserialize)]
31pub struct SandboxInfo {
32    pub name: String,
33    pub status: String,
34    pub backend: String,
35    pub image: Option<String>,
36    pub vcpus: Option<u32>,
37    pub memory_mb: Option<u64>,
38    pub created_at: Option<String>,
39}
40
41/// SSE stream event.
42#[derive(Debug)]
43pub struct StreamEvent {
44    pub event_type: String,
45    pub data: serde_json::Value,
46}
47
48/// API response wrapper (internal).
49#[derive(Debug, Deserialize)]
50pub(crate) struct ApiResponse<T> {
51    pub success: bool,
52    pub data: Option<T>,
53    pub error: Option<String>,
54}
55
56/// Run request body (internal).
57#[derive(Serialize)]
58pub(crate) struct RunRequest {
59    pub command: Vec<String>,
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub image: Option<String>,
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub profile: Option<SecurityProfile>,
64    pub fast: bool,
65}
66
67/// Options for creating a sandbox with a git source.
68#[derive(Debug, Default, Serialize)]
69pub struct CreateSandboxOptions {
70    /// Docker image to use.
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub image: Option<String>,
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub vcpus: Option<u32>,
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub memory_mb: Option<u64>,
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub profile: Option<SecurityProfile>,
79    /// Git repository URL to clone into the sandbox.
80    #[serde(skip_serializing_if = "Option::is_none")]
81    pub source_url: Option<String>,
82    /// Git ref to checkout after cloning.
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub source_ref: Option<String>,
85    /// Volume mounts (slug:/path or slug:/path:ro). Create volumes via CLI first.
86    #[serde(skip_serializing_if = "Vec::is_empty")]
87    #[serde(default)]
88    pub volumes: Vec<String>,
89}
90
91/// Create sandbox request body (internal).
92#[derive(Serialize)]
93pub(crate) struct CreateRequest {
94    pub name: String,
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub image: Option<String>,
97    #[serde(skip_serializing_if = "Option::is_none")]
98    pub vcpus: Option<u32>,
99    #[serde(skip_serializing_if = "Option::is_none")]
100    pub memory_mb: Option<u64>,
101    #[serde(skip_serializing_if = "Option::is_none")]
102    pub profile: Option<SecurityProfile>,
103    #[serde(skip_serializing_if = "Option::is_none")]
104    pub source_url: Option<String>,
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub source_ref: Option<String>,
107}
108
109/// Options for executing a command in a sandbox.
110#[derive(Debug, Default, Serialize)]
111pub struct ExecOptions {
112    /// Environment variables (`KEY=VALUE`).
113    #[serde(skip_serializing_if = "Vec::is_empty")]
114    pub env: Vec<String>,
115    /// Working directory inside the container.
116    #[serde(skip_serializing_if = "Option::is_none")]
117    pub workdir: Option<String>,
118    /// Run as root (maps to `--sudo` on CLI).
119    #[serde(skip_serializing_if = "Option::is_none")]
120    pub sudo: Option<bool>,
121}
122
123/// Exec request body (internal).
124#[derive(Serialize)]
125pub(crate) struct ExecRequest {
126    pub command: Vec<String>,
127    #[serde(skip_serializing_if = "Vec::is_empty")]
128    pub env: Vec<String>,
129    #[serde(skip_serializing_if = "Option::is_none")]
130    pub workdir: Option<String>,
131    #[serde(skip_serializing_if = "Option::is_none")]
132    pub sudo: Option<bool>,
133}
134
135/// File write request body (internal).
136#[derive(Serialize)]
137pub(crate) struct FileWriteRequest {
138    pub content: String,
139    #[serde(skip_serializing_if = "Option::is_none")]
140    pub encoding: Option<String>,
141}
142
143/// Response from reading a file.
144#[derive(Debug, Deserialize)]
145pub struct FileReadResponse {
146    pub content: String,
147    pub encoding: String,
148    pub size: usize,
149}
150
151/// Batch run request body (internal).
152#[derive(Serialize)]
153pub(crate) struct BatchRunRequest {
154    pub commands: Vec<BatchCommand>,
155}
156
157/// A command for batch execution.
158#[derive(Debug, Serialize)]
159pub struct BatchCommand {
160    pub command: Vec<String>,
161}
162
163/// Result of a single batch command.
164#[derive(Debug, Deserialize)]
165pub struct BatchResult {
166    pub output: Option<String>,
167    pub error: Option<String>,
168}
169
170/// Response from batch execution.
171#[derive(Debug, Deserialize)]
172pub struct BatchRunResponse {
173    pub results: Vec<BatchResult>,
174}
175
176/// Batch file write request body (internal).
177#[derive(Serialize)]
178pub(crate) struct BatchFileWriteRequest {
179    pub files: std::collections::HashMap<String, String>,
180}
181
182/// Result of a batch file write.
183#[derive(Debug, Deserialize)]
184pub struct BatchFileWriteResponse {
185    pub written: usize,
186}
187
188/// Status of a detached command.
189#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
190#[serde(rename_all = "lowercase")]
191pub enum DetachedStatus {
192    Running,
193    Completed,
194    Failed,
195}
196
197/// A detached (background) command running in a sandbox.
198#[derive(Debug, Deserialize)]
199pub struct DetachedCommand {
200    pub id: String,
201    pub sandbox: String,
202    pub command: Vec<String>,
203    pub pid: u32,
204    pub status: DetachedStatus,
205    pub exit_code: Option<i32>,
206    pub started_at: String,
207}
208
209/// Response from detached command logs.
210#[derive(Debug, Deserialize)]
211pub struct DetachedLogsResponse {
212    pub stdout: Option<String>,
213    pub stderr: Option<String>,
214}