mecha10_core/context/
infra_config.rs

1//! Infrastructure configuration types
2//!
3//! Configuration structures for Redis, PostgreSQL, MLflow, MinIO, and other
4//! infrastructure services used by the Mecha10 framework.
5
6use serde::Deserialize;
7
8/// Infrastructure configuration
9#[derive(Debug, Deserialize, Clone)]
10pub struct InfrastructureConfig {
11    /// Local Redis instance for on-robot messaging
12    pub redis: RedisConfig,
13    /// Control plane Redis instance for robot-to-cloud communication
14    /// Optional - only used when connecting to Mecha10 cloud services
15    #[serde(default)]
16    pub control_plane_redis: Option<RedisConfig>,
17    /// Redis bridge configuration
18    /// Controls message forwarding between local and control plane Redis
19    #[serde(default)]
20    pub bridge: Option<BridgeConfig>,
21    #[serde(default)]
22    pub postgres: Option<PostgresConfig>,
23    #[serde(default)]
24    pub mlflow: Option<MlflowConfig>,
25    #[serde(default)]
26    pub minio: Option<MinioConfig>,
27}
28
29#[derive(Debug, Deserialize, Clone)]
30pub struct RedisConfig {
31    pub url: String,
32    #[serde(default = "default_max_connections")]
33    pub max_connections: usize,
34    #[serde(default = "default_connection_timeout")]
35    pub connection_timeout_ms: u64,
36}
37
38impl Default for RedisConfig {
39    fn default() -> Self {
40        Self {
41            url: "redis://localhost:6379".to_string(),
42            max_connections: default_max_connections(),
43            connection_timeout_ms: default_connection_timeout(),
44        }
45    }
46}
47
48#[derive(Debug, Deserialize, Clone)]
49pub struct PostgresConfig {
50    pub host: String,
51    pub port: u16,
52    pub database: String,
53    pub username: String,
54    pub password: String,
55    #[serde(default = "default_max_connections")]
56    pub max_connections: usize,
57}
58
59#[derive(Debug, Deserialize, Clone)]
60pub struct MlflowConfig {
61    pub tracking_uri: String,
62    pub artifact_location: String,
63}
64
65#[derive(Debug, Deserialize, Clone)]
66pub struct MinioConfig {
67    pub endpoint: String,
68    pub access_key: String,
69    pub secret_key: String,
70    #[serde(default)]
71    pub secure: bool,
72}
73
74/// Redis bridge configuration
75#[derive(Debug, Deserialize, Clone)]
76pub struct BridgeConfig {
77    /// Enable or disable the bridge
78    #[serde(default = "default_bridge_enabled")]
79    pub enabled: bool,
80
81    /// Topic patterns that should stay local (not bridged)
82    /// Examples: "/sensor/camera/*", "/sensor/lidar/*"
83    #[serde(default = "default_local_topics")]
84    pub local_topics: Vec<String>,
85
86    /// Topic patterns that should be bridged to control plane
87    /// Examples: "/system/*", "/telemetry/*", "/logs/*"
88    #[serde(default = "default_bridged_topics")]
89    pub bridged_topics: Vec<String>,
90
91    /// Robot identifier for wildcard subscriptions
92    /// Used in control plane for topic prefixing (e.g., "robot-123/camera/rgb")
93    #[serde(default)]
94    pub robot_id: Option<String>,
95}
96
97impl Default for BridgeConfig {
98    fn default() -> Self {
99        Self {
100            enabled: default_bridge_enabled(),
101            local_topics: default_local_topics(),
102            bridged_topics: default_bridged_topics(),
103            robot_id: None,
104        }
105    }
106}
107
108fn default_bridge_enabled() -> bool {
109    true
110}
111
112fn default_local_topics() -> Vec<String> {
113    vec![
114        // High-frequency sensor data stays local
115        "/sensor/camera/*".to_string(),
116        "/sensor/lidar/*".to_string(),
117        "/sensor/imu/*".to_string(),
118    ]
119}
120
121fn default_bridged_topics() -> Vec<String> {
122    vec![
123        // System topics go to control plane
124        "/system/*".to_string(),
125        "/telemetry/*".to_string(),
126        "/logs/*".to_string(),
127        "/fleet/*".to_string(),
128    ]
129}
130
131fn default_max_connections() -> usize {
132    10
133}
134
135fn default_connection_timeout() -> u64 {
136    5000
137}