daytona_client/models/
process.rs

1//! Process and session management models
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use uuid::Uuid;
6
7/// Process session
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct ProcessSession {
11    pub id: Uuid,
12    pub sandbox_id: Uuid,
13    pub shell: String,
14    pub working_directory: String,
15    pub environment: std::collections::HashMap<String, String>,
16    pub created_at: DateTime<Utc>,
17    pub last_activity_at: DateTime<Utc>,
18    pub state: SessionState,
19    pub rows: u16,
20    pub cols: u16,
21}
22
23/// Session state
24#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(rename_all = "lowercase")]
26pub enum SessionState {
27    Active,
28    Idle,
29    Terminated,
30    Error,
31}
32
33/// Session command (matches API)
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct SessionCommand {
36    pub id: String,
37    pub command: String,
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub exit_code: Option<i32>,
40}
41
42/// Session (matches API)
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(rename_all = "camelCase")]
45pub struct Session {
46    pub session_id: String,
47    pub commands: Option<Vec<SessionCommand>>,
48}
49
50/// Session execute request (matches API)
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(rename_all = "camelCase")]
53pub struct SessionExecuteRequest {
54    pub command: String,
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub run_async: Option<bool>,
57}
58
59/// Session execute response (matches API)
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(rename_all = "camelCase")]
62pub struct SessionExecuteResponse {
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub cmd_id: Option<String>,
65    #[serde(skip_serializing_if = "Option::is_none")]
66    pub output: Option<String>,
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub exit_code: Option<i32>,
69}
70
71/// Create session request (matches API)
72#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(rename_all = "camelCase")]
74pub struct CreateSessionRequest {
75    pub session_id: String,
76}
77
78/// Resize session request
79#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(rename_all = "camelCase")]
81pub struct ResizeSessionRequest {
82    pub rows: u16,
83    pub cols: u16,
84}
85
86/// Execute command request with streaming
87#[derive(Debug, Clone, Serialize, Deserialize)]
88#[serde(rename_all = "camelCase")]
89pub struct StreamExecuteRequest {
90    pub command: String,
91    #[serde(skip_serializing_if = "Option::is_none")]
92    pub shell: Option<bool>,
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub working_dir: Option<String>,
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub env: Option<std::collections::HashMap<String, String>>,
97    #[serde(skip_serializing_if = "Option::is_none")]
98    pub stdin: Option<String>,
99}
100
101/// Process output chunk
102#[derive(Debug, Clone, Deserialize)]
103#[serde(rename_all = "camelCase")]
104pub struct ProcessOutputChunk {
105    pub stream_type: StreamType,
106    pub data: String,
107    pub timestamp: DateTime<Utc>,
108}
109
110/// Stream type
111#[derive(Debug, Clone, Deserialize)]
112#[serde(rename_all = "lowercase")]
113pub enum StreamType {
114    Stdout,
115    Stderr,
116    Exit,
117}
118
119/// Process list item
120#[derive(Debug, Clone, Deserialize)]
121#[serde(rename_all = "camelCase")]
122pub struct ProcessInfo {
123    pub pid: u32,
124    pub ppid: u32,
125    pub user: String,
126    pub command: String,
127    pub cpu_percent: f32,
128    pub memory_percent: f32,
129    pub memory_kb: u64,
130    pub started_at: DateTime<Utc>,
131    pub state: ProcessState,
132}
133
134/// Process state
135#[derive(Debug, Clone, Serialize, Deserialize)]
136#[serde(rename_all = "lowercase")]
137pub enum ProcessState {
138    Running,
139    Sleeping,
140    Stopped,
141    Zombie,
142    Dead,
143}
144
145/// Kill process request
146#[derive(Debug, Clone, Serialize, Deserialize)]
147#[serde(rename_all = "camelCase")]
148pub struct KillProcessRequest {
149    pub pid: u32,
150    #[serde(skip_serializing_if = "Option::is_none")]
151    pub signal: Option<i32>,
152}
153
154/// Terminal input
155#[derive(Debug, Clone, Serialize, Deserialize)]
156#[serde(rename_all = "camelCase")]
157pub struct TerminalInput {
158    pub data: String,
159}
160
161/// Terminal output
162#[derive(Debug, Clone, Deserialize)]
163#[serde(rename_all = "camelCase")]
164pub struct TerminalOutput {
165    pub data: Vec<u8>,
166    pub timestamp: DateTime<Utc>,
167}
168
169/// Session information
170#[derive(Debug, Clone, Serialize, Deserialize)]
171#[serde(rename_all = "camelCase")]
172pub struct SessionInfo {
173    pub id: String,
174    pub sandbox_id: Uuid,
175    pub shell: String,
176    pub working_directory: String,
177    pub created_at: DateTime<Utc>,
178    pub state: SessionState,
179}
180
181/// Session command result
182#[derive(Debug, Clone, Serialize, Deserialize)]
183#[serde(rename_all = "camelCase")]
184pub struct SessionCommandResult {
185    pub command_id: String,
186    pub session_id: String,
187    pub command: String,
188    pub exit_code: Option<i32>,
189    pub stdout: String,
190    pub stderr: String,
191    pub started_at: DateTime<Utc>,
192    pub completed_at: Option<DateTime<Utc>>,
193    pub state: CommandState,
194}
195
196/// Command execution state
197#[derive(Debug, Clone, Serialize, Deserialize)]
198#[serde(rename_all = "lowercase")]
199pub enum CommandState {
200    Running,
201    Completed,
202    Failed,
203    Timeout,
204}
205
206/// Process status information
207#[derive(Debug, Clone, Serialize, Deserialize)]
208#[serde(rename_all = "camelCase")]
209pub struct ProcessStatus {
210    pub process_id: String,
211    pub sandbox_id: Uuid,
212    pub command: String,
213    pub pid: Option<u32>,
214    pub state: ProcessState,
215    pub exit_code: Option<i32>,
216    pub started_at: DateTime<Utc>,
217    pub completed_at: Option<DateTime<Utc>>,
218}