Skip to main content

systemprompt_cloud/
constants.rs

1//! Compile-time constants for the cloud layer: container paths, callback ports
2//! and timeouts, API endpoints, deploy regions, and on-disk file/profile names.
3//!
4//! Grouped into submodules by concern (`oauth`, `credentials`, `docker`,
5//! `api`, `paths`, `profile`, `env_vars`); path-name and storage constants
6//! are re-exported from `systemprompt_models`.
7//!
8//! Copyright (c) systemprompt.io — Business Source License 1.1.
9//! See <https://systemprompt.io> for licensing details.
10
11pub use systemprompt_models::paths::constants::{build, dir_names, file_names, storage};
12
13pub mod container {
14    use systemprompt_models::paths::constants::cloud_container;
15
16    pub const APP: &str = cloud_container::APP_ROOT;
17    pub const APP_ROOT: &str = cloud_container::APP_ROOT;
18    pub const BIN: &str = cloud_container::BIN;
19    pub const LOGS: &str = cloud_container::LOGS;
20    pub const SERVICES: &str = cloud_container::SERVICES;
21    pub const STORAGE: &str = cloud_container::STORAGE;
22    pub const WEB: &str = cloud_container::WEB;
23    pub const WEB_DIST: &str = cloud_container::WEB_DIST;
24    pub const WEB_CONFIG: &str = cloud_container::WEB_CONFIG;
25    pub const PROFILES: &str = cloud_container::PROFILES;
26    pub const TEMPLATES: &str = cloud_container::TEMPLATES;
27    pub const ASSETS: &str = cloud_container::ASSETS;
28}
29
30pub const CALLBACK_TIMEOUT_SECS: u64 = 300;
31
32pub mod oauth {
33    pub const CALLBACK_PORT: u16 = 8765;
34    pub const CALLBACK_TIMEOUT_SECS: u64 = super::CALLBACK_TIMEOUT_SECS;
35}
36
37pub mod credentials {
38    use super::{dir_names, file_names};
39
40    pub const DEFAULT_DIR_NAME: &str = dir_names::SYSTEMPROMPT;
41    pub const DEFAULT_FILE_NAME: &str = file_names::CREDENTIALS;
42
43    /// Cached validation TTL for `/api/v1/auth/me`.
44    ///
45    /// Skip the round-trip when on-disk credentials were validated within this
46    /// window — short enough that a revoked token is rejected on the next demo
47    /// turn, long enough to absorb back-to-back CLI invocations.
48    pub const VALIDATION_TTL_SECS: i64 = 900;
49}
50
51pub mod tenants {
52    use super::{dir_names, file_names};
53
54    pub const DEFAULT_DIR_NAME: &str = dir_names::SYSTEMPROMPT;
55    pub const DEFAULT_FILE_NAME: &str = file_names::TENANTS;
56}
57
58pub mod cli_session {
59    use super::{dir_names, file_names};
60
61    pub const DEFAULT_DIR_NAME: &str = dir_names::SYSTEMPROMPT;
62    pub const DEFAULT_FILE_NAME: &str = file_names::SESSION;
63}
64
65pub mod docker {
66    pub const CONTAINER_NAME_PREFIX: &str = "systemprompt-postgres";
67    pub const COMPOSE_PATH: &str = "infrastructure/docker";
68
69    pub fn container_name(env_name: &str) -> String {
70        format!("{}-{}", CONTAINER_NAME_PREFIX, env_name)
71    }
72}
73
74pub mod api {
75    pub const PRODUCTION_URL: &str = "https://api.systemprompt.io";
76    pub const SANDBOX_URL: &str = "https://api-sandbox.systemprompt.io";
77}
78
79pub mod paths {
80    use super::{dir_names, file_names};
81
82    pub const ROOT_DIR: &str = dir_names::SYSTEMPROMPT;
83    pub const PROFILES_DIR: &str = dir_names::PROFILES;
84    pub const DOCKER_DIR: &str = dir_names::DOCKER;
85    pub const STORAGE_DIR: &str = dir_names::STORAGE;
86    pub const DOCKERFILE: &str = file_names::DOCKERFILE;
87    pub const PROFILE_CONFIG: &str = file_names::PROFILE_CONFIG;
88    pub const PROFILE_SECRETS: &str = file_names::PROFILE_SECRETS;
89    pub const CREDENTIALS_FILE: &str = file_names::CREDENTIALS;
90    pub const TENANTS_FILE: &str = file_names::TENANTS;
91    pub const SESSION_FILE: &str = file_names::SESSION;
92    pub const PROFILE_DOCKER_DIR: &str = dir_names::DOCKER;
93    pub const ENTRYPOINT: &str = file_names::ENTRYPOINT;
94    pub const DOCKERIGNORE: &str = file_names::DOCKERIGNORE;
95    pub const COMPOSE_FILE: &str = file_names::COMPOSE;
96}
97
98pub mod profile {
99    use super::container;
100
101    pub const DEFAULT_DB_TYPE: &str = "postgres";
102    pub const DEFAULT_PORT: u16 = 8080;
103    pub const LOCAL_HOST: &str = "127.0.0.1";
104    pub const CLOUD_HOST: &str = "0.0.0.0";
105    pub const DEFAULT_CLOUD_URL: &str = "https://cloud.systemprompt.io";
106    pub const LOCAL_ISSUER: &str = "systemprompt-local";
107    pub const CLOUD_ISSUER: &str = "systemprompt";
108    pub const ACCESS_TOKEN_EXPIRATION: i64 = 2_592_000;
109    pub const REFRESH_TOKEN_EXPIRATION: i64 = 15_552_000;
110    pub const CLOUD_APP_PATH: &str = container::APP_ROOT;
111    pub const CREDENTIALS_PATH: &str = "../../credentials.json";
112    pub const TENANTS_PATH: &str = "../../tenants.json";
113}
114
115pub mod proxies {
116    pub const PRIVATE_RANGES: &[&str] = &[
117        "127.0.0.0/8",
118        "::1/128",
119        "10.0.0.0/8",
120        "172.16.0.0/12",
121        "192.168.0.0/16",
122    ];
123
124    pub const FLY_PRIVATE_RANGES: &[&str] = &["fc00::/7"];
125
126    pub const FLY_PUBLIC_RANGES: &[&str] = &["66.241.64.0/18"];
127
128    pub const CLOUDFLARE_RANGES: &[&str] = &[
129        "173.245.48.0/20",
130        "103.21.244.0/22",
131        "103.22.200.0/22",
132        "103.31.4.0/22",
133        "141.101.64.0/18",
134        "108.162.192.0/18",
135        "190.93.240.0/20",
136        "188.114.96.0/20",
137        "197.234.240.0/22",
138        "198.41.128.0/17",
139        "162.158.0.0/15",
140        "104.16.0.0/13",
141        "104.24.0.0/14",
142        "172.64.0.0/13",
143        "131.0.72.0/22",
144        "2400:cb00::/32",
145        "2606:4700::/32",
146        "2803:f800::/32",
147        "2405:b500::/32",
148        "2405:8100::/32",
149        "2a06:98c0::/29",
150        "2c0f:f248::/32",
151    ];
152}
153
154pub mod env_vars {
155    pub use systemprompt_models::paths::constants::env_vars::CUSTOM_SECRETS;
156
157    pub const SYSTEM_MANAGED: &[&str] = &["FLY_APP_NAME", "FLY_MACHINE_ID"];
158
159    pub const CLI_SYNCED: &[&str] = &[
160        "SYSTEMPROMPT_API_TOKEN",
161        "SYSTEMPROMPT_USER_EMAIL",
162        "SYSTEMPROMPT_CLI_REMOTE",
163        "SYSTEMPROMPT_PROFILE",
164    ];
165
166    pub fn is_system_managed(key: &str) -> bool {
167        SYSTEM_MANAGED.iter().any(|&k| k.eq_ignore_ascii_case(key))
168    }
169}