systemprompt_models/paths/
system.rs

1use std::path::{Path, PathBuf};
2
3use super::PathError;
4use crate::profile::PathsConfig;
5
6#[derive(Debug, Clone)]
7pub struct SystemPaths {
8    root: PathBuf,
9    services: PathBuf,
10    skills: PathBuf,
11    settings: PathBuf,
12    content_config: PathBuf,
13    geoip_database: Option<PathBuf>,
14    defaults: PathBuf,
15}
16
17impl SystemPaths {
18    const LOGS_DIR: &'static str = "logs";
19
20    pub fn from_profile(paths: &PathsConfig) -> Result<Self, PathError> {
21        let root = Self::canonicalize(&paths.system, "system")?;
22        let defaults = Self::resolve_defaults_dir(&root);
23
24        Ok(Self {
25            root,
26            services: PathBuf::from(&paths.services),
27            skills: PathBuf::from(paths.skills()),
28            settings: PathBuf::from(paths.config()),
29            content_config: PathBuf::from(paths.content_config()),
30            geoip_database: paths.geoip_database.as_ref().map(PathBuf::from),
31            defaults,
32        })
33    }
34
35    fn canonicalize(path: &str, field: &'static str) -> Result<PathBuf, PathError> {
36        std::fs::canonicalize(path).map_err(|source| PathError::CanonicalizeFailed {
37            path: PathBuf::from(path),
38            field,
39            source,
40        })
41    }
42
43    fn resolve_defaults_dir(root: &Path) -> PathBuf {
44        root.join("defaults")
45    }
46
47    pub fn root(&self) -> &Path {
48        &self.root
49    }
50
51    pub fn services(&self) -> &Path {
52        &self.services
53    }
54
55    pub fn skills(&self) -> &Path {
56        &self.skills
57    }
58
59    pub fn settings(&self) -> &Path {
60        &self.settings
61    }
62
63    pub fn content_config(&self) -> &Path {
64        &self.content_config
65    }
66
67    pub fn geoip_database(&self) -> Option<&Path> {
68        self.geoip_database.as_deref()
69    }
70
71    pub fn logs(&self) -> PathBuf {
72        self.root.join(Self::LOGS_DIR)
73    }
74
75    pub fn resolve_skill(&self, name: &str) -> PathBuf {
76        self.skills.join(name)
77    }
78
79    pub fn resolve_service(&self, name: &str) -> PathBuf {
80        self.services.join(name)
81    }
82
83    pub fn defaults(&self) -> &Path {
84        &self.defaults
85    }
86
87    pub fn default_templates(&self) -> PathBuf {
88        self.defaults.join("templates")
89    }
90
91    pub fn default_assets(&self) -> PathBuf {
92        self.defaults.join("assets")
93    }
94
95    pub fn default_web(&self) -> PathBuf {
96        self.defaults.join("web")
97    }
98}