Skip to main content

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    #[serde(default = "default_true")]
22    pub marketplace_public: bool,
23    #[serde(default, skip_serializing_if = "Option::is_none")]
24    pub default_marketplace_id: Option<String>,
25}
26
27impl Default for Settings {
28    fn default() -> Self {
29        Self {
30            agent_port_range: default_agent_port_range(),
31            mcp_port_range: default_mcp_port_range(),
32            auto_start_enabled: true,
33            validation_strict: true,
34            schema_validation_mode: default_schema_validation_mode(),
35            services_path: None,
36            skills_path: None,
37            config_path: None,
38            marketplace_public: true,
39            default_marketplace_id: None,
40        }
41    }
42}
43
44impl Settings {
45    pub fn apply_env_overrides(&mut self) {
46        if let Ok(val) = std::env::var("SYSTEMPROMPT_SERVICES_PATH") {
47            self.services_path = Some(val);
48        }
49        if let Ok(val) = std::env::var("SYSTEMPROMPT_SKILLS_PATH") {
50            self.skills_path = Some(val);
51        }
52        if let Ok(val) = std::env::var("SYSTEMPROMPT_CONFIG_PATH") {
53            self.config_path = Some(val);
54        }
55    }
56}
57
58const fn default_agent_port_range() -> (u16, u16) {
59    (9000, 9999)
60}
61
62const fn default_mcp_port_range() -> (u16, u16) {
63    (5000, 5999)
64}
65
66const fn default_true() -> bool {
67    true
68}
69
70fn default_schema_validation_mode() -> String {
71    "auto_migrate".to_string()
72}