systemprompt_models/services/
settings.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub struct Settings {
5    #[serde(default = "default_agent_port_range")]
6    pub agent_port_range: (u16, u16),
7    #[serde(default = "default_mcp_port_range")]
8    pub mcp_port_range: (u16, u16),
9    #[serde(default = "default_true")]
10    pub auto_start_enabled: bool,
11    #[serde(default = "default_true")]
12    pub validation_strict: bool,
13    #[serde(default = "default_schema_validation_mode")]
14    pub schema_validation_mode: String,
15    #[serde(default, skip_serializing_if = "Option::is_none")]
16    pub services_path: Option<String>,
17    #[serde(default, skip_serializing_if = "Option::is_none")]
18    pub skills_path: Option<String>,
19    #[serde(default, skip_serializing_if = "Option::is_none")]
20    pub config_path: Option<String>,
21}
22
23impl Default for Settings {
24    fn default() -> Self {
25        Self {
26            agent_port_range: default_agent_port_range(),
27            mcp_port_range: default_mcp_port_range(),
28            auto_start_enabled: true,
29            validation_strict: true,
30            schema_validation_mode: default_schema_validation_mode(),
31            services_path: None,
32            skills_path: None,
33            config_path: None,
34        }
35    }
36}
37
38impl Settings {
39    pub fn apply_env_overrides(&mut self) {
40        if let Ok(val) = std::env::var("SYSTEMPROMPT_SERVICES_PATH") {
41            self.services_path = Some(val);
42        }
43        if let Ok(val) = std::env::var("SYSTEMPROMPT_SKILLS_PATH") {
44            self.skills_path = Some(val);
45        }
46        if let Ok(val) = std::env::var("SYSTEMPROMPT_CONFIG_PATH") {
47            self.config_path = Some(val);
48        }
49    }
50}
51
52const fn default_agent_port_range() -> (u16, u16) {
53    (9000, 9999)
54}
55
56const fn default_mcp_port_range() -> (u16, u16) {
57    (5000, 5999)
58}
59
60const fn default_true() -> bool {
61    true
62}
63
64fn default_schema_validation_mode() -> String {
65    "auto_migrate".to_string()
66}