1use serde::{Deserialize, Serialize};
4use std::time::{Duration, SystemTime};
5use uuid::Uuid;
6
7pub mod agent;
8pub mod communication;
9pub mod error;
10pub mod resource;
11pub mod security;
12
13pub use agent::*;
14pub use communication::*;
15pub use error::*;
16pub use resource::*;
17pub use security::*;
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
21pub struct AgentId(pub Uuid);
22
23impl AgentId {
24 pub fn new() -> Self {
25 Self(Uuid::new_v4())
26 }
27}
28
29impl Default for AgentId {
30 fn default() -> Self {
31 Self::new()
32 }
33}
34
35impl std::fmt::Display for AgentId {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 write!(f, "{}", self.0)
38 }
39}
40
41impl std::str::FromStr for AgentId {
42 type Err = uuid::Error;
43
44 fn from_str(s: &str) -> Result<Self, Self::Err> {
45 Ok(Self(Uuid::parse_str(s)?))
46 }
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
51pub struct MessageId(pub Uuid);
52
53impl std::fmt::Display for MessageId {
54 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55 write!(f, "{}", self.0)
56 }
57}
58
59impl MessageId {
60 pub fn new() -> Self {
61 Self(Uuid::new_v4())
62 }
63}
64
65impl Default for MessageId {
66 fn default() -> Self {
67 Self::new()
68 }
69}
70
71#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
73pub struct RequestId(pub Uuid);
74
75impl RequestId {
76 pub fn new() -> Self {
77 Self(Uuid::new_v4())
78 }
79}
80
81impl Default for RequestId {
82 fn default() -> Self {
83 Self::new()
84 }
85}
86
87impl std::fmt::Display for RequestId {
88 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
89 write!(f, "{}", self.0)
90 }
91}
92
93#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
95pub struct PolicyId(pub Uuid);
96
97impl std::fmt::Display for PolicyId {
98 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
99 write!(f, "{}", self.0)
100 }
101}
102
103impl PolicyId {
104 pub fn new() -> Self {
105 Self(Uuid::new_v4())
106 }
107}
108
109impl Default for PolicyId {
110 fn default() -> Self {
111 Self::new()
112 }
113}
114
115#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
117pub struct AuditId(pub Uuid);
118
119impl AuditId {
120 pub fn new() -> Self {
121 Self(Uuid::new_v4())
122 }
123}
124
125impl Default for AuditId {
126 fn default() -> Self {
127 Self::new()
128 }
129}
130
131#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Default)]
133pub enum Priority {
134 Low = 0,
135 #[default]
136 Normal = 1,
137 High = 2,
138 Critical = 3,
139}
140
141#[derive(Debug, Clone, Serialize, Deserialize)]
143pub struct SystemStatus {
144 pub total_agents: usize,
145 pub running_agents: usize,
146 pub suspended_agents: usize,
147 pub resource_utilization: ResourceUsage,
148 pub uptime: Duration,
149 pub last_updated: SystemTime,
150}
151
152#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
154pub enum Capability {
155 FileSystem,
156 Network,
157 Database,
158 Computation,
159 Communication,
160 Custom(String),
161}
162
163#[derive(Debug, Clone, Serialize, Deserialize)]
165pub struct Dependency {
166 pub name: String,
167 pub version: String,
168 pub required: bool,
169}
170
171#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
173pub enum SchedulingAlgorithm {
174 FirstComeFirstServe,
175 #[default]
176 PriorityBased,
177 RoundRobin,
178 ShortestJobFirst,
179 WeightedFairQueuing,
180}
181
182#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
184pub enum LoadBalancingStrategy {
185 RoundRobin,
186 LeastConnections,
187 #[default]
188 ResourceBased,
189 WeightedRoundRobin,
190}
191
192#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
194pub enum HealthStatus {
195 Healthy,
196 Degraded,
197 Unhealthy,
198}
199
200#[derive(Debug, Clone, Serialize, Deserialize)]
202pub struct ComponentHealth {
203 pub status: HealthStatus,
204 pub message: Option<String>,
205 pub last_check: SystemTime,
206 pub uptime: Duration,
207 pub metrics: std::collections::HashMap<String, String>,
208}
209
210impl ComponentHealth {
211 pub fn healthy(message: Option<String>) -> Self {
212 Self {
213 status: HealthStatus::Healthy,
214 message,
215 last_check: SystemTime::now(),
216 uptime: Duration::default(),
217 metrics: std::collections::HashMap::new(),
218 }
219 }
220
221 pub fn degraded(message: String) -> Self {
222 Self {
223 status: HealthStatus::Degraded,
224 message: Some(message),
225 last_check: SystemTime::now(),
226 uptime: Duration::default(),
227 metrics: std::collections::HashMap::new(),
228 }
229 }
230
231 pub fn unhealthy(message: String) -> Self {
232 Self {
233 status: HealthStatus::Unhealthy,
234 message: Some(message),
235 last_check: SystemTime::now(),
236 uptime: Duration::default(),
237 metrics: std::collections::HashMap::new(),
238 }
239 }
240
241 pub fn with_uptime(mut self, uptime: Duration) -> Self {
242 self.uptime = uptime;
243 self
244 }
245
246 pub fn with_metric(mut self, key: String, value: String) -> Self {
247 self.metrics.insert(key, value);
248 self
249 }
250}