systemprompt_models/services/
runtime.rs1use serde::{Deserialize, Serialize};
7use std::fmt;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
10pub enum RuntimeStatus {
11 Running,
12 Starting,
13 Stopped,
14 Crashed,
15 Orphaned,
16}
17
18impl RuntimeStatus {
19 pub const fn is_healthy(&self) -> bool {
20 matches!(self, Self::Running | Self::Starting)
21 }
22
23 pub const fn needs_cleanup(&self) -> bool {
24 matches!(self, Self::Crashed | Self::Orphaned)
25 }
26}
27
28impl fmt::Display for RuntimeStatus {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 match self {
31 Self::Running => write!(f, "running"),
32 Self::Starting => write!(f, "starting"),
33 Self::Stopped => write!(f, "stopped"),
34 Self::Crashed => write!(f, "crashed"),
35 Self::Orphaned => write!(f, "orphaned"),
36 }
37 }
38}
39
40impl std::str::FromStr for RuntimeStatus {
41 type Err = String;
42
43 fn from_str(s: &str) -> Result<Self, Self::Err> {
44 match s.to_lowercase().as_str() {
45 "running" => Ok(Self::Running),
46 "starting" => Ok(Self::Starting),
47 "stopped" => Ok(Self::Stopped),
48 "crashed" | "error" => Ok(Self::Crashed),
49 "orphaned" => Ok(Self::Orphaned),
50 _ => Err(format!("Invalid runtime status: {s}")),
51 }
52 }
53}
54
55#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
56pub enum ServiceType {
57 Api,
58 Agent,
59 Mcp,
60}
61
62impl fmt::Display for ServiceType {
63 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64 match self {
65 Self::Api => write!(f, "api"),
66 Self::Agent => write!(f, "agent"),
67 Self::Mcp => write!(f, "mcp"),
68 }
69 }
70}
71
72impl ServiceType {
73 pub fn from_module_name(name: &str) -> Self {
74 match name.to_lowercase().as_str() {
75 "agent" => Self::Agent,
76 "api" => Self::Api,
77 _ => Self::Mcp,
78 }
79 }
80}