Skip to main content

systemprompt_models/services/
runtime.rs

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