codex_mobile_bridge/bridge_protocol/
management.rs1use 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}
13
14impl BridgeManagementOperation {
15 pub fn as_str(self) -> &'static str {
16 match self {
17 Self::Install => "install",
18 Self::Update => "update",
19 Self::Repair => "repair",
20 Self::Rollback => "rollback",
21 }
22 }
23}
24
25#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
26#[serde(rename_all = "snake_case")]
27pub enum BridgeManagementStatus {
28 Queued,
29 Running,
30 Reconnecting,
31 Succeeded,
32 Failed,
33}
34
35impl BridgeManagementStatus {
36 pub fn is_terminal(self) -> bool {
37 matches!(self, Self::Succeeded | Self::Failed)
38 }
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
42#[serde(rename_all = "snake_case")]
43pub enum BridgeManagementPhase {
44 ResolveTarget,
45 InstallRelease,
46 ActivateRelease,
47 RestartService,
48 VerifyHealth,
49 Done,
50}
51
52impl BridgeManagementPhase {
53 pub fn as_str(&self) -> &'static str {
54 match self {
55 Self::ResolveTarget => "resolve_target",
56 Self::InstallRelease => "install_release",
57 Self::ActivateRelease => "activate_release",
58 Self::RestartService => "restart_service",
59 Self::VerifyHealth => "verify_health",
60 Self::Done => "done",
61 }
62 }
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize, Default)]
66#[serde(rename_all = "camelCase")]
67pub struct ManagedBridgeReleaseDescriptor {
68 pub crate_name: String,
69 pub version: String,
70 pub registry: String,
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize, Default)]
74#[serde(rename_all = "camelCase")]
75pub struct ManagedInstallRecord {
76 pub install_state: String,
77 pub current_artifact_id: Option<String>,
78 pub current_version: Option<String>,
79 pub current_build_hash: Option<String>,
80 pub current_sha256: Option<String>,
81 pub current_protocol_version: Option<u32>,
82 pub current_release_path: Option<String>,
83 pub previous_artifact_id: Option<String>,
84 pub previous_version: Option<String>,
85 pub previous_build_hash: Option<String>,
86 pub previous_sha256: Option<String>,
87 pub previous_protocol_version: Option<u32>,
88 pub previous_release_path: Option<String>,
89 pub last_operation: Option<String>,
90 pub last_operation_status: Option<String>,
91 pub last_operation_at_ms: i64,
92 pub installed_at_ms: i64,
93 pub updated_at_ms: i64,
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize, Default)]
97#[serde(rename_all = "camelCase")]
98pub struct ManagedServiceStatus {
99 pub installed: bool,
100 pub active: bool,
101 pub enabled: bool,
102 pub load_state: String,
103 pub active_state: String,
104 pub unit_file_state: String,
105 pub sub_state: String,
106 pub result: String,
107 pub exec_main_status: Option<i32>,
108 pub checked_at_ms: i64,
109}
110
111#[derive(Debug, Clone, Serialize, Deserialize, Default)]
112#[serde(rename_all = "camelCase")]
113pub struct ManagedBridgeHealthSnapshot {
114 pub ok: bool,
115 pub bridge_version: Option<String>,
116 pub build_hash: Option<String>,
117 pub protocol_version: Option<u32>,
118 pub runtime_count: usize,
119 pub primary_runtime_id: Option<String>,
120 pub runtime: Option<RuntimeStatusSnapshot>,
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize, Default)]
124#[serde(rename_all = "camelCase")]
125pub struct ManagedBridgeSnapshot {
126 pub available_release: Option<ManagedBridgeReleaseDescriptor>,
127 pub install_record: Option<ManagedInstallRecord>,
128 pub service_status: ManagedServiceStatus,
129 pub bridge_health: Option<ManagedBridgeHealthSnapshot>,
130 pub current_link_target: Option<String>,
131 pub current_binary_sha256: Option<String>,
132 pub unit_file_exists: bool,
133 pub env_file_exists: bool,
134 pub can_update: bool,
135 pub needs_repair: bool,
136 pub can_rollback: bool,
137 #[serde(default)]
138 pub warnings: Vec<String>,
139}
140
141#[derive(Debug, Clone, Serialize, Deserialize)]
142#[serde(rename_all = "camelCase")]
143pub struct BridgeManagementTask {
144 pub task_id: String,
145 pub operation: BridgeManagementOperation,
146 pub status: BridgeManagementStatus,
147 pub phase: BridgeManagementPhase,
148 pub summary: String,
149 pub detail: Option<String>,
150 pub failure_code: Option<String>,
151 pub target_version: Option<String>,
152 pub current_version: Option<String>,
153 pub started_at_ms: i64,
154 pub updated_at_ms: i64,
155 pub snapshot: Option<ManagedBridgeSnapshot>,
156}
157
158#[derive(Debug, Clone, Serialize, Deserialize)]
159#[serde(rename_all = "camelCase")]
160pub struct BridgeManagementTaskPayload {
161 pub task: BridgeManagementTask,
162}
163
164#[derive(Debug, Clone, Serialize, Deserialize, Default)]
165#[serde(rename_all = "camelCase")]
166pub struct BridgeManagementTaskResultPayload {
167 pub task: Option<BridgeManagementTask>,
168}