Skip to main content

AirLibrary/CLI/
ResponseTypes.rs

1//! Response DTO structs returned by daemon IPC calls and serialised to
2//! stdout by `OutputFormatter`. Keeping these separate from the parser and
3//! handler code makes the wire contract easy to review and unit-test.
4
5use std::collections::HashMap;
6
7use chrono::{DateTime, Utc};
8use serde::{Deserialize, Serialize};
9
10/// Overall daemon + services status.
11#[derive(Debug, Serialize, Deserialize)]
12pub struct StatusResponse {
13	pub daemon_running:bool,
14
15	pub uptime_secs:u64,
16
17	pub version:String,
18
19	pub services:HashMap<String, ServiceStatus>,
20
21	pub timestamp:String,
22}
23
24/// Per-service status inside a `StatusResponse`.
25#[derive(Debug, Serialize, Deserialize)]
26pub struct ServiceStatus {
27	pub name:String,
28
29	pub running:bool,
30
31	pub health:ServiceHealth,
32
33	pub uptime_secs:u64,
34
35	pub error:Option<String>,
36}
37
38/// Coarse service health classification.
39#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
40#[serde(rename_all = "UPPERCASE")]
41pub enum ServiceHealth {
42	Healthy,
43
44	Degraded,
45
46	Unhealthy,
47
48	Unknown,
49}
50
51/// Aggregated performance metrics snapshot.
52#[derive(Debug, Serialize, Deserialize)]
53pub struct MetricsResponse {
54	pub timestamp:String,
55
56	pub memory_used_mb:f64,
57
58	pub memory_available_mb:f64,
59
60	pub cpu_usage_percent:f64,
61
62	pub disk_used_mb:u64,
63
64	pub disk_available_mb:u64,
65
66	pub active_connections:u32,
67
68	pub processed_requests:u64,
69
70	pub failed_requests:u64,
71
72	pub service_metrics:HashMap<String, ServiceMetrics>,
73}
74
75/// Per-service request latency counters.
76#[derive(Debug, Serialize, Deserialize)]
77pub struct ServiceMetrics {
78	pub name:String,
79
80	pub requests_total:u64,
81
82	pub requests_success:u64,
83
84	pub requests_failed:u64,
85
86	pub average_latency_ms:f64,
87
88	pub p99_latency_ms:f64,
89}
90
91/// Result of a health-check sweep across all services.
92#[derive(Debug, Serialize, Deserialize)]
93pub struct HealthCheckResponse {
94	pub overall_healthy:bool,
95
96	pub overall_health_percentage:f64,
97
98	pub services:HashMap<String, ServiceHealthDetail>,
99
100	pub timestamp:String,
101}
102
103/// Fine-grained health detail for one service.
104#[derive(Debug, Serialize, Deserialize)]
105pub struct ServiceHealthDetail {
106	pub name:String,
107
108	pub healthy:bool,
109
110	pub response_time_ms:u64,
111
112	pub last_check:String,
113
114	pub details:String,
115}
116
117/// Configuration key/value read result.
118#[derive(Debug, Serialize, Deserialize)]
119pub struct ConfigResponse {
120	pub key:Option<String>,
121
122	pub value:serde_json::Value,
123
124	pub path:String,
125
126	pub modified:String,
127}
128
129/// Single structured log line.
130#[derive(Debug, Serialize, Deserialize)]
131pub struct LogEntry {
132	pub timestamp:DateTime<Utc>,
133
134	pub level:String,
135
136	pub service:Option<String>,
137
138	pub message:String,
139
140	pub context:Option<serde_json::Value>,
141}
142
143/// Active IPC connection metadata.
144#[derive(Debug, Serialize, Deserialize)]
145pub struct ConnectionInfo {
146	pub id:String,
147
148	pub remote_address:String,
149
150	pub connected_at:DateTime<Utc>,
151
152	pub service:Option<String>,
153
154	pub active:bool,
155}
156
157/// Full daemon state snapshot (debug dump).
158#[derive(Debug, Serialize, Deserialize)]
159pub struct DaemonState {
160	pub timestamp:DateTime<Utc>,
161
162	pub version:String,
163
164	pub uptime_secs:u64,
165
166	pub services:HashMap<String, serde_json::Value>,
167
168	pub connections:Vec<ConnectionInfo>,
169
170	pub plugin_state:serde_json::Value,
171}