systemprompt_models/modules/
service_category.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
6pub enum ServiceCategory {
7 Core,
8 Agent,
9 Mcp,
10 Meta,
11}
12
13impl ServiceCategory {
14 pub const fn base_path(&self) -> &'static str {
15 match self {
16 Self::Core => "/api/v1/core",
17 Self::Agent => "/api/v1/agents",
18 Self::Mcp => "/api/v1/mcp",
19 Self::Meta => "/",
20 }
21 }
22
23 pub const fn display_name(&self) -> &'static str {
24 match self {
25 Self::Core => "Core",
26 Self::Agent => "Agent",
27 Self::Mcp => "MCP",
28 Self::Meta => "Meta",
29 }
30 }
31
32 pub fn mount_path(&self, module_name: &str) -> String {
33 if module_name.is_empty() {
34 self.base_path().to_string()
35 } else {
36 match self {
37 Self::Meta => {
38 format!("/{module_name}")
39 },
40 Self::Core | Self::Agent | Self::Mcp => {
41 format!("{}/{}", self.base_path(), module_name)
42 },
43 }
44 }
45 }
46
47 pub fn matches_path(&self, path: &str) -> bool {
48 let base = self.base_path();
49 if base == "/" {
50 path == "/" || path.starts_with("/.well-known") || path.starts_with("/api/v1/meta")
51 } else {
52 path.starts_with(base)
53 }
54 }
55
56 pub const fn all() -> &'static [Self] {
57 &[Self::Core, Self::Agent, Self::Mcp, Self::Meta]
58 }
59
60 pub fn from_path(path: &str) -> Option<Self> {
61 for category in &[Self::Core, Self::Agent, Self::Mcp] {
62 if category.matches_path(path) {
63 return Some(*category);
64 }
65 }
66 if Self::Meta.matches_path(path) {
67 Some(Self::Meta)
68 } else {
69 None
70 }
71 }
72}