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