Skip to main content

ubiquity_core/
config.rs

1//! Configuration types for Ubiquity
2
3use serde::{Deserialize, Serialize};
4use std::time::Duration;
5
6/// LLM provider configuration
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct LLMConfig {
9    pub provider: LLMProvider,
10    pub api_key: String,
11    pub model: String,
12    pub temperature: f32,
13    pub max_tokens: usize,
14    pub timeout: Duration,
15    pub retry_attempts: u32,
16    pub retry_delay: Duration,
17}
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
20#[serde(rename_all = "lowercase")]
21pub enum LLMProvider {
22    Claude,
23    OpenAI,
24    Local,
25    Mock, // For testing
26}
27
28/// Security configuration
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct SecurityConfig {
31    pub auth_enabled: bool,
32    pub auth_type: AuthType,
33    pub tls_enabled: bool,
34    pub tls_cert_path: Option<String>,
35    pub tls_key_path: Option<String>,
36    pub allowed_origins: Vec<String>,
37}
38
39#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
40#[serde(rename_all = "snake_case")]
41pub enum AuthType {
42    None,
43    Token,
44    Certificate,
45    ApiKey,
46}
47
48/// Transport configuration with timeout and retry
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct TransportConfigExt {
51    pub connect_timeout: Duration,
52    pub read_timeout: Duration,
53    pub write_timeout: Duration,
54    pub keep_alive_interval: Duration,
55    pub max_message_size: usize,
56    pub retry_attempts: u32,
57    pub retry_delay: Duration,
58    pub exponential_backoff: bool,
59    pub max_connections: usize,
60}
61
62impl Default for TransportConfigExt {
63    fn default() -> Self {
64        Self {
65            connect_timeout: Duration::from_secs(30),
66            read_timeout: Duration::from_secs(60),
67            write_timeout: Duration::from_secs(30),
68            keep_alive_interval: Duration::from_secs(30),
69            max_message_size: 10 * 1024 * 1024, // 10MB
70            retry_attempts: 3,
71            retry_delay: Duration::from_secs(1),
72            exponential_backoff: true,
73            max_connections: 100,
74        }
75    }
76}
77
78/// Monitoring configuration
79#[derive(Debug, Clone, Serialize, Deserialize)]
80pub struct MonitoringConfig {
81    pub metrics_enabled: bool,
82    pub traces_enabled: bool,
83    pub logs_level: LogLevel,
84    pub metrics_port: u16,
85    pub health_check_interval: Duration,
86}
87
88#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
89#[serde(rename_all = "lowercase")]
90pub enum LogLevel {
91    Trace,
92    Debug,
93    Info,
94    Warn,
95    Error,
96}
97
98/// Complete Ubiquity configuration
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct UbiquityConfig {
101    pub agent: AgentConfigExt,
102    pub llm: Option<LLMConfig>,
103    pub security: SecurityConfig,
104    pub transport: TransportConfigExt,
105    pub monitoring: MonitoringConfig,
106}
107
108/// Extended agent configuration
109#[derive(Debug, Clone, Serialize, Deserialize)]
110pub struct AgentConfigExt {
111    pub default_consciousness_level: f64,
112    pub consciousness_check_interval: Duration,
113    pub task_timeout: Duration,
114    pub max_concurrent_tasks: usize,
115    pub enable_state_persistence: bool,
116    pub state_save_interval: Duration,
117}
118
119impl Default for AgentConfigExt {
120    fn default() -> Self {
121        Self {
122            default_consciousness_level: 0.85,
123            consciousness_check_interval: Duration::from_secs(10),
124            task_timeout: Duration::from_secs(300),
125            max_concurrent_tasks: 10,
126            enable_state_persistence: true,
127            state_save_interval: Duration::from_secs(60),
128        }
129    }
130}
131
132/// Authentication token
133#[derive(Debug, Clone, Serialize, Deserialize)]
134pub struct AuthToken {
135    pub token: String,
136    pub agent_id: String,
137    pub capabilities: crate::AgentCapability,
138    pub expires_at: Option<chrono::DateTime<chrono::Utc>>,
139}
140
141/// Health status
142#[derive(Debug, Clone, Serialize, Deserialize)]
143pub struct HealthStatus {
144    pub healthy: bool,
145    pub consciousness_level: f64,
146    pub active_tasks: usize,
147    pub memory_usage_mb: f64,
148    pub uptime_seconds: u64,
149    pub last_error: Option<String>,
150}