1use serde::{Deserialize, Serialize};
2
3use super::runtime::RuntimeStatusSnapshot;
4
5#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
6#[serde(rename_all = "snake_case")]
7pub enum BridgeManagementOperation {
8 Install,
9 Update,
10 Repair,
11 Rollback,
12 StartService,
13 StopService,
14 RestartService,
15 Uninstall,
16}
17
18impl BridgeManagementOperation {
19 pub fn as_str(self) -> &'static str {
20 match self {
21 Self::Install => "install",
22 Self::Update => "update",
23 Self::Repair => "repair",
24 Self::Rollback => "rollback",
25 Self::StartService => "start_service",
26 Self::StopService => "stop_service",
27 Self::RestartService => "restart_service",
28 Self::Uninstall => "uninstall",
29 }
30 }
31}
32
33#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
34#[serde(rename_all = "snake_case")]
35pub enum BridgeManagementStatus {
36 Queued,
37 Running,
38 Reconnecting,
39 Succeeded,
40 Failed,
41}
42
43impl BridgeManagementStatus {
44 pub fn is_terminal(self) -> bool {
45 matches!(self, Self::Succeeded | Self::Failed)
46 }
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
50#[serde(rename_all = "snake_case")]
51pub enum BridgeManagementPhase {
52 ResolveTarget,
53 InstallRelease,
54 ActivateRelease,
55 ControlService,
56 CleanupManagedFiles,
57 RestartService,
58 VerifyHealth,
59 Done,
60}
61
62impl BridgeManagementPhase {
63 pub fn as_str(&self) -> &'static str {
64 match self {
65 Self::ResolveTarget => "resolve_target",
66 Self::InstallRelease => "install_release",
67 Self::ActivateRelease => "activate_release",
68 Self::ControlService => "control_service",
69 Self::CleanupManagedFiles => "cleanup_managed_files",
70 Self::RestartService => "restart_service",
71 Self::VerifyHealth => "verify_health",
72 Self::Done => "done",
73 }
74 }
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize, Default)]
78#[serde(rename_all = "camelCase")]
79pub struct ManagedBridgeReleaseDescriptor {
80 pub crate_name: String,
81 pub version: String,
82 pub registry: String,
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize, Default)]
86#[serde(rename_all = "camelCase")]
87pub struct ManagedInstallRecord {
88 pub install_state: String,
89 pub current_artifact_id: Option<String>,
90 pub current_version: Option<String>,
91 pub current_build_hash: Option<String>,
92 pub current_sha256: Option<String>,
93 pub current_protocol_version: Option<u32>,
94 pub current_release_path: Option<String>,
95 pub previous_artifact_id: Option<String>,
96 pub previous_version: Option<String>,
97 pub previous_build_hash: Option<String>,
98 pub previous_sha256: Option<String>,
99 pub previous_protocol_version: Option<u32>,
100 pub previous_release_path: Option<String>,
101 pub last_operation: Option<String>,
102 pub last_operation_status: Option<String>,
103 pub last_operation_at_ms: i64,
104 pub installed_at_ms: i64,
105 pub updated_at_ms: i64,
106}
107
108#[derive(Debug, Clone, Serialize, Deserialize, Default)]
109#[serde(rename_all = "camelCase")]
110pub struct ManagedServiceStatus {
111 pub installed: bool,
112 pub active: bool,
113 pub enabled: bool,
114 pub load_state: String,
115 pub active_state: String,
116 pub unit_file_state: String,
117 pub sub_state: String,
118 pub result: String,
119 pub exec_main_status: Option<i32>,
120 pub checked_at_ms: i64,
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize, Default)]
124#[serde(rename_all = "camelCase")]
125pub struct ManagedBridgeHealthSnapshot {
126 pub ok: bool,
127 pub bridge_version: Option<String>,
128 pub build_hash: Option<String>,
129 pub protocol_version: Option<u32>,
130 pub runtime_count: usize,
131 pub primary_runtime_id: Option<String>,
132 pub runtime: Option<RuntimeStatusSnapshot>,
133}
134
135#[derive(Debug, Clone, Serialize, Deserialize, Default)]
136#[serde(rename_all = "camelCase")]
137pub struct ManagedBridgeSnapshot {
138 pub available_release: Option<ManagedBridgeReleaseDescriptor>,
139 pub install_record: Option<ManagedInstallRecord>,
140 pub service_status: ManagedServiceStatus,
141 pub bridge_health: Option<ManagedBridgeHealthSnapshot>,
142 pub current_link_target: Option<String>,
143 pub current_binary_sha256: Option<String>,
144 pub unit_file_exists: bool,
145 pub env_file_exists: bool,
146 pub can_update: bool,
147 pub needs_repair: bool,
148 pub can_rollback: bool,
149 #[serde(default)]
150 pub warnings: Vec<String>,
151}
152
153#[derive(Debug, Clone, Serialize, Deserialize, Default)]
154#[serde(rename_all = "camelCase")]
155pub struct PlatformDescriptor {
156 pub os: String,
157 pub arch: String,
158 pub supported: bool,
159 pub reason: Option<String>,
160}
161
162#[derive(Debug, Clone, Serialize, Deserialize, Default)]
163#[serde(rename_all = "camelCase")]
164pub struct RemoteToolchainStatus {
165 pub cargo_available: bool,
166 pub rustc_available: bool,
167 pub compiler_available: bool,
168 pub systemd_user_available: bool,
169 pub cargo_path: Option<String>,
170 pub rustc_path: Option<String>,
171 pub compiler_path: Option<String>,
172 pub reason: Option<String>,
173}
174
175#[derive(Debug, Clone, Serialize, Deserialize, Default)]
176#[serde(rename_all = "camelCase")]
177pub struct RemoteRegistryStatus {
178 pub crate_name: String,
179 pub registry: String,
180 pub reachable: bool,
181 pub latest_version: Option<String>,
182 pub error: Option<String>,
183}
184
185#[derive(Debug, Clone, Serialize, Deserialize, Default)]
186#[serde(rename_all = "camelCase")]
187pub struct RemoteInstallRecord {
188 pub install_state: String,
189 pub current_artifact_id: Option<String>,
190 pub current_version: Option<String>,
191 pub current_build_hash: Option<String>,
192 pub current_sha256: Option<String>,
193 pub current_protocol_version: Option<u32>,
194 pub current_release_path: Option<String>,
195 pub previous_artifact_id: Option<String>,
196 pub previous_version: Option<String>,
197 pub previous_build_hash: Option<String>,
198 pub previous_sha256: Option<String>,
199 pub previous_protocol_version: Option<u32>,
200 pub previous_release_path: Option<String>,
201 pub last_operation: Option<String>,
202 pub last_operation_status: Option<String>,
203 pub last_operation_at_ms: i64,
204 pub installed_at_ms: i64,
205 pub updated_at_ms: i64,
206}
207
208#[derive(Debug, Clone, Serialize, Deserialize, Default)]
209#[serde(rename_all = "camelCase")]
210pub struct RemoteServiceStatus {
211 pub installed: bool,
212 pub active: bool,
213 pub enabled: bool,
214 pub lingering_enabled: bool,
215 pub load_state: String,
216 pub active_state: String,
217 pub unit_file_state: String,
218 pub sub_state: String,
219 pub result: String,
220 pub fragment_path: Option<String>,
221 pub exec_main_pid: Option<i64>,
222 pub exec_main_status: Option<i32>,
223 pub last_message: String,
224 pub checked_at_ms: i64,
225}
226
227#[derive(Debug, Clone, Serialize, Deserialize, Default)]
228#[serde(rename_all = "camelCase")]
229pub struct BridgeHealthSnapshot {
230 pub ok: bool,
231 pub bridge_version: Option<String>,
232 pub build_hash: Option<String>,
233 pub protocol_version: Option<u32>,
234 pub runtime_count: usize,
235 pub primary_runtime_id: Option<String>,
236 pub runtime: Option<RuntimeStatusSnapshot>,
237}
238
239#[derive(Debug, Clone, Serialize, Deserialize, Default)]
240#[serde(rename_all = "camelCase")]
241pub struct DiagnosticLogEntry {
242 pub level: String,
243 pub source: String,
244 pub code: String,
245 pub message: String,
246 pub detail: Option<String>,
247 #[serde(default)]
248 pub detail_samples: Vec<String>,
249 pub first_at_ms: i64,
250 pub last_at_ms: i64,
251 pub repeat_count: i32,
252}
253
254#[derive(Debug, Clone, Serialize, Deserialize, Default)]
255#[serde(rename_all = "camelCase")]
256pub struct RemoteLogChunk {
257 pub text: String,
258 pub collected_at_ms: i64,
259 #[serde(default)]
260 pub entries: Vec<DiagnosticLogEntry>,
261 pub truncated: bool,
262}
263
264#[derive(Debug, Clone, Serialize, Deserialize, Default)]
265#[serde(rename_all = "camelCase")]
266pub struct RemoteInspectionReport {
267 pub detected_platform: PlatformDescriptor,
268 pub toolchain_status: RemoteToolchainStatus,
269 pub registry_status: RemoteRegistryStatus,
270 pub available_release: Option<ManagedBridgeReleaseDescriptor>,
271 pub install_record: Option<RemoteInstallRecord>,
272 pub service_status: RemoteServiceStatus,
273 pub bridge_health: Option<BridgeHealthSnapshot>,
274 pub current_link_target: Option<String>,
275 pub current_binary_sha256: Option<String>,
276 pub unit_file_exists: bool,
277 pub env_file_exists: bool,
278 pub can_update: bool,
279 pub needs_repair: bool,
280 pub can_rollback: bool,
281 #[serde(default)]
282 pub warnings: Vec<String>,
283 pub app_server_log: RemoteLogChunk,
284 pub bridge_service_log: RemoteLogChunk,
285 pub systemd_log: RemoteLogChunk,
286 pub recent_log: RemoteLogChunk,
287}
288
289#[derive(Debug, Clone, Serialize, Deserialize)]
290#[serde(rename_all = "camelCase")]
291pub struct BridgeManagementTask {
292 pub task_id: String,
293 pub operation: BridgeManagementOperation,
294 pub status: BridgeManagementStatus,
295 pub phase: BridgeManagementPhase,
296 pub summary: String,
297 pub detail: Option<String>,
298 pub failure_code: Option<String>,
299 pub target_version: Option<String>,
300 pub current_version: Option<String>,
301 pub started_at_ms: i64,
302 pub updated_at_ms: i64,
303 pub snapshot: Option<ManagedBridgeSnapshot>,
304}
305
306#[derive(Debug, Clone, Serialize, Deserialize)]
307#[serde(rename_all = "camelCase")]
308pub struct BridgeManagementTaskPayload {
309 pub task: BridgeManagementTask,
310}
311
312#[derive(Debug, Clone, Serialize, Deserialize, Default)]
313#[serde(rename_all = "camelCase")]
314pub struct BridgeManagementTaskResultPayload {
315 pub task: Option<BridgeManagementTask>,
316}