Update config/settings.py
Browse files- config/settings.py +268 -333
config/settings.py
CHANGED
|
@@ -1,376 +1,311 @@
|
|
| 1 |
"""
|
| 2 |
-
Configuration
|
| 3 |
-
|
| 4 |
"""
|
| 5 |
-
from typing import Optional, Dict, Any, List
|
| 6 |
-
from enum import Enum
|
| 7 |
import os
|
| 8 |
-
import logging
|
| 9 |
import sys
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
# Try to import from pydantic-settings, fallback to pydantic
|
| 14 |
try:
|
| 15 |
-
from
|
| 16 |
-
from
|
| 17 |
PYDANTIC_V2 = True
|
| 18 |
-
logger.info("Using pydantic-settings for BaseSettings")
|
| 19 |
except ImportError:
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
except ImportError as e:
|
| 25 |
-
logger.error(f"Failed to import pydantic: {e}")
|
| 26 |
-
# Create minimal fallback
|
| 27 |
-
class BaseSettings:
|
| 28 |
-
def __init__(self, **kwargs):
|
| 29 |
-
for k, v in kwargs.items():
|
| 30 |
-
setattr(self, k, v)
|
| 31 |
-
|
| 32 |
-
class Field:
|
| 33 |
-
@staticmethod
|
| 34 |
-
def default(value):
|
| 35 |
-
return value
|
| 36 |
-
|
| 37 |
-
def validator(*args, **kwargs):
|
| 38 |
-
def decorator(func):
|
| 39 |
-
return func
|
| 40 |
-
return decorator
|
| 41 |
-
|
| 42 |
-
PYDANTIC_V2 = False
|
| 43 |
|
|
|
|
|
|
|
| 44 |
|
|
|
|
| 45 |
class ARFMode(str, Enum):
|
| 46 |
-
"""ARF
|
| 47 |
DEMO = "demo"
|
| 48 |
OSS = "oss"
|
| 49 |
ENTERPRISE = "enterprise"
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
class SafetyMode(str, Enum):
|
| 53 |
-
"""Safety
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
| 58 |
|
| 59 |
class InstallationStatus(str, Enum):
|
| 60 |
-
"""
|
| 61 |
NOT_INSTALLED = "not_installed"
|
| 62 |
OSS_ONLY = "oss_only"
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
use_true_arf: bool = Field(
|
| 79 |
-
default=True,
|
| 80 |
-
description="Use true ARF integration when available"
|
| 81 |
-
)
|
| 82 |
-
|
| 83 |
-
# ===== Installation Status (Auto-detected) =====
|
| 84 |
-
arf_oss_installed: bool = Field(
|
| 85 |
-
default=False,
|
| 86 |
-
description="ARF OSS package installed"
|
| 87 |
-
)
|
| 88 |
-
|
| 89 |
-
arf_enterprise_installed: bool = Field(
|
| 90 |
-
default=False,
|
| 91 |
-
description="ARF Enterprise package installed"
|
| 92 |
-
)
|
| 93 |
-
|
| 94 |
-
arf_oss_version: Optional[str] = Field(
|
| 95 |
-
default=None,
|
| 96 |
-
description="ARF OSS version if installed"
|
| 97 |
-
)
|
| 98 |
-
|
| 99 |
-
arf_enterprise_version: Optional[str] = Field(
|
| 100 |
-
default=None,
|
| 101 |
-
description="ARF Enterprise version if installed"
|
| 102 |
-
)
|
| 103 |
-
|
| 104 |
-
# ===== ARF Configuration =====
|
| 105 |
-
arf_api_key: Optional[str] = Field(
|
| 106 |
-
default=None,
|
| 107 |
-
description="ARF API key for real integration"
|
| 108 |
-
)
|
| 109 |
-
|
| 110 |
-
arf_base_url: str = Field(
|
| 111 |
-
default="https://api.arf.dev",
|
| 112 |
-
description="ARF API base URL"
|
| 113 |
-
)
|
| 114 |
-
|
| 115 |
-
# ===== Business Configuration =====
|
| 116 |
-
engineer_hourly_rate: float = Field(
|
| 117 |
-
default=150.0,
|
| 118 |
-
description="Engineer hourly rate in USD"
|
| 119 |
-
)
|
| 120 |
-
|
| 121 |
-
engineer_annual_cost: float = Field(
|
| 122 |
-
default=125000.0,
|
| 123 |
-
description="Engineer annual cost in USD"
|
| 124 |
-
)
|
| 125 |
-
|
| 126 |
-
default_savings_rate: float = Field(
|
| 127 |
-
default=0.82,
|
| 128 |
-
description="Default savings rate with ARF"
|
| 129 |
-
)
|
| 130 |
-
|
| 131 |
-
# ===== UI Configuration =====
|
| 132 |
-
auto_refresh_seconds: int = Field(
|
| 133 |
-
default=30,
|
| 134 |
-
description="Auto-refresh interval in seconds"
|
| 135 |
-
)
|
| 136 |
-
|
| 137 |
-
max_history_items: int = Field(
|
| 138 |
-
default=100,
|
| 139 |
-
description="Maximum history items to display"
|
| 140 |
-
)
|
| 141 |
-
|
| 142 |
-
# ===== Demo Configuration =====
|
| 143 |
-
default_scenario: str = Field(
|
| 144 |
-
default="Cache Miss Storm",
|
| 145 |
-
description="Default incident scenario"
|
| 146 |
-
)
|
| 147 |
-
|
| 148 |
-
scenario_config_path: str = Field(
|
| 149 |
-
default="config/scenarios",
|
| 150 |
-
description="Path to scenario configuration files"
|
| 151 |
-
)
|
| 152 |
-
|
| 153 |
-
# ===== Safety Configuration =====
|
| 154 |
-
default_safety_mode: SafetyMode = Field(
|
| 155 |
-
default=SafetyMode.ADVISORY,
|
| 156 |
-
description="Default safety mode"
|
| 157 |
-
)
|
| 158 |
-
|
| 159 |
-
require_approval: bool = Field(
|
| 160 |
-
default=True,
|
| 161 |
-
description="Require human approval for execution"
|
| 162 |
-
)
|
| 163 |
-
|
| 164 |
-
# ===== Validation =====
|
| 165 |
-
@validator("arf_mode", "default_safety_mode", pre=True)
|
| 166 |
-
def validate_enums(cls, v):
|
| 167 |
-
"""Convert strings to enum values if needed"""
|
| 168 |
-
if isinstance(v, str):
|
| 169 |
-
# Try to match enum values
|
| 170 |
-
if hasattr(cls, '__fields__'):
|
| 171 |
-
field_name = None
|
| 172 |
-
for field in cls.__fields__.values():
|
| 173 |
-
if field.name == 'arf_mode' and isinstance(v, str):
|
| 174 |
-
try:
|
| 175 |
-
return ARFMode(v.lower())
|
| 176 |
-
except ValueError:
|
| 177 |
-
return ARFMode.DEMO
|
| 178 |
-
elif field.name == 'default_safety_mode' and isinstance(v, str):
|
| 179 |
-
try:
|
| 180 |
-
return SafetyMode(v.lower())
|
| 181 |
-
except ValueError:
|
| 182 |
-
return SafetyMode.ADVISORY
|
| 183 |
-
return v
|
| 184 |
-
|
| 185 |
-
@validator("arf_api_key")
|
| 186 |
-
def validate_api_key(cls, v: Optional[str], values: Dict[str, Any]) -> Optional[str]:
|
| 187 |
-
if values.get("arf_mode") == ARFMode.ENTERPRISE and not v:
|
| 188 |
-
raise ValueError("ARF API key required for Enterprise mode")
|
| 189 |
-
return v
|
| 190 |
-
|
| 191 |
-
@validator("use_true_arf")
|
| 192 |
-
def validate_true_arf(cls, v: bool, values: Dict[str, Any]) -> bool:
|
| 193 |
-
if v and not values.get("arf_oss_installed"):
|
| 194 |
-
logger.warning("True ARF requested but OSS package not installed. Using mock mode.")
|
| 195 |
-
return False
|
| 196 |
-
return v
|
| 197 |
-
|
| 198 |
-
# ===== Installation Detection =====
|
| 199 |
-
@classmethod
|
| 200 |
-
def detect_installation(cls):
|
| 201 |
-
"""Detect ARF package installation"""
|
| 202 |
-
results = {
|
| 203 |
-
"oss_installed": False,
|
| 204 |
-
"enterprise_installed": False,
|
| 205 |
-
"oss_version": None,
|
| 206 |
-
"enterprise_version": None
|
| 207 |
-
}
|
| 208 |
|
| 209 |
-
#
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
logger.info(f"✅ ARF OSS v{results['oss_version']} detected")
|
| 215 |
-
except ImportError:
|
| 216 |
-
logger.info("⚠️ ARF OSS not installed - will use mock mode")
|
| 217 |
|
| 218 |
-
#
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
results["enterprise_installed"] = True
|
| 222 |
-
results["enterprise_version"] = getattr(arf_enterprise, '__version__', '1.0.2')
|
| 223 |
-
logger.info(f"✅ ARF Enterprise v{results['enterprise_version']} detected")
|
| 224 |
-
except ImportError:
|
| 225 |
-
logger.info("⚠️ ARF Enterprise not installed - will use simulation")
|
| 226 |
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
return InstallationStatus.ENTERPRISE
|
| 235 |
-
elif self.arf_oss_installed:
|
| 236 |
-
return InstallationStatus.OSS_ONLY
|
| 237 |
-
else:
|
| 238 |
-
return InstallationStatus.NOT_INSTALLED
|
| 239 |
-
|
| 240 |
-
def get_installation_badges(self) -> Dict[str, Any]:
|
| 241 |
-
"""Get badge information for UI display"""
|
| 242 |
-
if self.arf_oss_installed:
|
| 243 |
-
oss_badge = {
|
| 244 |
-
"text": f"✅ ARF OSS v{self.arf_oss_version}",
|
| 245 |
-
"color": "#10b981",
|
| 246 |
-
"icon": "✅"
|
| 247 |
-
}
|
| 248 |
-
else:
|
| 249 |
-
oss_badge = {
|
| 250 |
-
"text": "⚠️ Mock ARF",
|
| 251 |
-
"color": "#f59e0b",
|
| 252 |
-
"icon": "⚠️"
|
| 253 |
-
}
|
| 254 |
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
}
|
| 261 |
-
else:
|
| 262 |
-
enterprise_badge = {
|
| 263 |
-
"text": "🔒 Enterprise Required",
|
| 264 |
-
"color": "#64748b",
|
| 265 |
-
"icon": "🔒"
|
| 266 |
-
}
|
| 267 |
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
def get_installation_recommendations(self) -> List[str]:
|
| 274 |
-
"""Get installation recommendations"""
|
| 275 |
-
recommendations = []
|
| 276 |
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
)
|
| 286 |
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
|
| 302 |
-
#
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
)
|
| 309 |
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
|
|
|
|
|
|
| 313 |
|
| 314 |
-
|
| 315 |
-
|
|
|
|
|
|
|
| 316 |
|
| 317 |
-
#
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
for rec in recommendations:
|
| 326 |
-
print(f" • {rec}")
|
| 327 |
|
| 328 |
-
|
|
|
|
|
|
|
|
|
|
| 329 |
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
|
| 334 |
-
#
|
| 335 |
try:
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
arf_oss_installed=installation_info["oss_installed"],
|
| 342 |
-
arf_enterprise_installed=installation_info["enterprise_installed"],
|
| 343 |
-
arf_oss_version=installation_info["oss_version"],
|
| 344 |
-
arf_enterprise_version=installation_info["enterprise_version"],
|
| 345 |
-
)
|
| 346 |
-
|
| 347 |
-
# Log installation status
|
| 348 |
-
status = settings.get_installation_status()
|
| 349 |
-
logger.info(f"ARF Installation Status: {status.value}")
|
| 350 |
-
|
| 351 |
-
if status == InstallationStatus.NOT_INSTALLED:
|
| 352 |
-
logger.warning("No ARF packages installed. Demo will use mock mode.")
|
| 353 |
-
logger.warning("For real ARF experience, install: pip install agentic-reliability-framework==3.3.7")
|
| 354 |
-
|
| 355 |
except Exception as e:
|
| 356 |
-
logger.
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
|
| 374 |
def get_settings() -> Settings:
|
| 375 |
-
"""Get settings
|
| 376 |
-
return settings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
"""
|
| 2 |
+
ARF Settings Configuration with Pydantic 2.x Compatibility
|
| 3 |
+
Fixed for both OSS and Enterprise deployments
|
| 4 |
"""
|
|
|
|
|
|
|
| 5 |
import os
|
|
|
|
| 6 |
import sys
|
| 7 |
+
from enum import Enum
|
| 8 |
+
from typing import Optional, Dict, Any, List, Union
|
| 9 |
+
from datetime import datetime
|
| 10 |
|
| 11 |
+
# Try to import pydantic with version detection
|
|
|
|
|
|
|
| 12 |
try:
|
| 13 |
+
from pydantic import Field, validator, model_validator
|
| 14 |
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
| 15 |
PYDANTIC_V2 = True
|
|
|
|
| 16 |
except ImportError:
|
| 17 |
+
# Fallback for pydantic v1
|
| 18 |
+
from pydantic import Field, validator
|
| 19 |
+
from pydantic_settings import BaseSettings
|
| 20 |
+
PYDANTIC_V2 = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
import logging
|
| 23 |
+
logger = logging.getLogger(__name__)
|
| 24 |
|
| 25 |
+
# Enums for ARF modes
|
| 26 |
class ARFMode(str, Enum):
|
| 27 |
+
"""ARF Operational Modes"""
|
| 28 |
DEMO = "demo"
|
| 29 |
OSS = "oss"
|
| 30 |
ENTERPRISE = "enterprise"
|
| 31 |
+
HYBRID = "hybrid"
|
| 32 |
+
SIMULATION = "simulation"
|
| 33 |
|
| 34 |
class SafetyMode(str, Enum):
|
| 35 |
+
"""Safety and Compliance Modes"""
|
| 36 |
+
STANDARD = "standard"
|
| 37 |
+
STRICT = "strict"
|
| 38 |
+
PERMISSIVE = "permissive"
|
| 39 |
+
ENTERPRISE = "enterprise"
|
| 40 |
+
COMPLIANCE = "compliance"
|
| 41 |
|
| 42 |
class InstallationStatus(str, Enum):
|
| 43 |
+
"""Package Installation Status"""
|
| 44 |
NOT_INSTALLED = "not_installed"
|
| 45 |
OSS_ONLY = "oss_only"
|
| 46 |
+
ENTERPRISE_ONLY = "enterprise_only"
|
| 47 |
+
FULL_INSTALL = "full_install"
|
| 48 |
+
DEMO_MODE = "demo_mode"
|
| 49 |
|
| 50 |
+
# Pydantic 2.x compatible Settings class
|
| 51 |
+
if PYDANTIC_V2:
|
| 52 |
+
class Settings(BaseSettings):
|
| 53 |
+
"""ARF Settings with Pydantic 2.x compatibility"""
|
| 54 |
+
model_config = SettingsConfigDict(
|
| 55 |
+
env_file=".env",
|
| 56 |
+
env_file_encoding="utf-8",
|
| 57 |
+
env_prefix="ARF_",
|
| 58 |
+
case_sensitive=False,
|
| 59 |
+
extra="ignore"
|
| 60 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
# Core Settings
|
| 63 |
+
arf_mode: ARFMode = Field(default=ARFMode.DEMO, description="ARF operational mode")
|
| 64 |
+
safety_mode: SafetyMode = Field(default=SafetyMode.STANDARD, description="Safety compliance mode")
|
| 65 |
+
debug: bool = Field(default=False, description="Enable debug logging")
|
| 66 |
+
log_level: str = Field(default="INFO", description="Logging level")
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
# Version Info
|
| 69 |
+
arf_version: str = Field(default="3.3.7", description="ARF version")
|
| 70 |
+
demo_version: str = Field(default="3.8.0", description="Demo app version")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
+
# Installation Status
|
| 73 |
+
oss_installed: bool = Field(default=False, description="ARF OSS package installed")
|
| 74 |
+
enterprise_installed: bool = Field(default=False, description="Enterprise package installed")
|
| 75 |
+
installation_status: InstallationStatus = Field(
|
| 76 |
+
default=InstallationStatus.DEMO_MODE,
|
| 77 |
+
description="Overall installation status"
|
| 78 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
+
# Feature Flags
|
| 81 |
+
enable_telemetry: bool = Field(default=True, description="Enable telemetry collection")
|
| 82 |
+
enable_anomaly_detection: bool = Field(default=True, description="Enable anomaly detection")
|
| 83 |
+
enable_business_metrics: bool = Field(default=True, description="Enable business metrics")
|
| 84 |
+
enable_audit_trail: bool = Field(default=True, description="Enable audit trail")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
+
# Paths
|
| 87 |
+
data_dir: str = Field(default="./data", description="Data directory")
|
| 88 |
+
log_dir: str = Field(default="./logs", description="Log directory")
|
| 89 |
+
cache_dir: str = Field(default="./cache", description="Cache directory")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
+
# API Settings
|
| 92 |
+
api_timeout: int = Field(default=30, description="API timeout in seconds")
|
| 93 |
+
max_retries: int = Field(default=3, description="Maximum API retries")
|
| 94 |
+
rate_limit: int = Field(default=100, description="API rate limit per minute")
|
| 95 |
|
| 96 |
+
# UI Settings
|
| 97 |
+
ui_theme: str = Field(default="dark", description="UI theme")
|
| 98 |
+
refresh_interval: int = Field(default=5, description="UI refresh interval in seconds")
|
|
|
|
| 99 |
|
| 100 |
+
# Business Settings
|
| 101 |
+
default_currency: str = Field(default="USD", description="Default currency")
|
| 102 |
+
cost_per_incident: float = Field(default=10000.0, description="Default cost per incident")
|
| 103 |
+
engineer_hourly_rate: float = Field(default=150.0, description="Engineer hourly rate")
|
| 104 |
+
|
| 105 |
+
@model_validator(mode='before')
|
| 106 |
+
@classmethod
|
| 107 |
+
def validate_enums(cls, data: Any) -> Any:
|
| 108 |
+
"""Validate and convert enum fields from strings"""
|
| 109 |
+
if isinstance(data, dict):
|
| 110 |
+
# Convert string values to enums if needed
|
| 111 |
+
if 'arf_mode' in data and isinstance(data['arf_mode'], str):
|
| 112 |
+
try:
|
| 113 |
+
data['arf_mode'] = ARFMode(data['arf_mode'].lower())
|
| 114 |
+
except ValueError:
|
| 115 |
+
data['arf_mode'] = ARFMode.DEMO
|
| 116 |
+
|
| 117 |
+
if 'safety_mode' in data and isinstance(data['safety_mode'], str):
|
| 118 |
+
try:
|
| 119 |
+
data['safety_mode'] = SafetyMode(data['safety_mode'].lower())
|
| 120 |
+
except ValueError:
|
| 121 |
+
data['safety_mode'] = SafetyMode.STANDARD
|
| 122 |
+
|
| 123 |
+
if 'installation_status' in data and isinstance(data['installation_status'], str):
|
| 124 |
+
try:
|
| 125 |
+
data['installation_status'] = InstallationStatus(data['installation_status'].lower())
|
| 126 |
+
except ValueError:
|
| 127 |
+
data['installation_status'] = InstallationStatus.DEMO_MODE
|
| 128 |
+
return data
|
| 129 |
+
|
| 130 |
+
@model_validator(mode='after')
|
| 131 |
+
def check_installation_status(self):
|
| 132 |
+
"""Update installation status based on detected packages"""
|
| 133 |
+
# Check if OSS is installed
|
| 134 |
+
try:
|
| 135 |
+
import agentic_reliability_framework
|
| 136 |
+
self.oss_installed = True
|
| 137 |
+
except ImportError:
|
| 138 |
+
self.oss_installed = False
|
| 139 |
+
|
| 140 |
+
# Check if Enterprise is installed
|
| 141 |
+
try:
|
| 142 |
+
import agentic_reliability_enterprise
|
| 143 |
+
self.enterprise_installed = True
|
| 144 |
+
except ImportError:
|
| 145 |
+
self.enterprise_installed = False
|
| 146 |
+
|
| 147 |
+
# Update installation status
|
| 148 |
+
if self.oss_installed and self.enterprise_installed:
|
| 149 |
+
self.installation_status = InstallationStatus.FULL_INSTALL
|
| 150 |
+
elif self.oss_installed:
|
| 151 |
+
self.installation_status = InstallationStatus.OSS_ONLY
|
| 152 |
+
elif self.enterprise_installed:
|
| 153 |
+
self.installation_status = InstallationStatus.ENTERPRISE_ONLY
|
| 154 |
+
else:
|
| 155 |
+
self.installation_status = InstallationStatus.DEMO_MODE
|
| 156 |
+
|
| 157 |
+
return self
|
| 158 |
|
| 159 |
+
else:
|
| 160 |
+
# Pydantic v1 compatible Settings class
|
| 161 |
+
class Settings(BaseSettings):
|
| 162 |
+
"""ARF Settings with Pydantic v1 compatibility"""
|
| 163 |
+
class Config:
|
| 164 |
+
env_file = ".env"
|
| 165 |
+
env_file_encoding = "utf-8"
|
| 166 |
+
env_prefix = "ARF_"
|
| 167 |
+
case_sensitive = False
|
| 168 |
|
| 169 |
+
# Core Settings
|
| 170 |
+
arf_mode: ARFMode = Field(default=ARFMode.DEMO, description="ARF operational mode")
|
| 171 |
+
safety_mode: SafetyMode = Field(default=SafetyMode.STANDARD, description="Safety compliance mode")
|
| 172 |
+
debug: bool = Field(default=False, description="Enable debug logging")
|
| 173 |
+
log_level: str = Field(default="INFO", description="Logging level")
|
| 174 |
+
|
| 175 |
+
# Version Info
|
| 176 |
+
arf_version: str = Field(default="3.3.7", description="ARF version")
|
| 177 |
+
demo_version: str = Field(default="3.8.0", description="Demo app version")
|
| 178 |
+
|
| 179 |
+
# Installation Status
|
| 180 |
+
oss_installed: bool = Field(default=False, description="ARF OSS package installed")
|
| 181 |
+
enterprise_installed: bool = Field(default=False, description="Enterprise package installed")
|
| 182 |
+
installation_status: InstallationStatus = Field(
|
| 183 |
+
default=InstallationStatus.DEMO_MODE,
|
| 184 |
+
description="Overall installation status"
|
| 185 |
)
|
| 186 |
|
| 187 |
+
# Feature Flags
|
| 188 |
+
enable_telemetry: bool = Field(default=True, description="Enable telemetry collection")
|
| 189 |
+
enable_anomaly_detection: bool = Field(default=True, description="Enable anomaly detection")
|
| 190 |
+
enable_business_metrics: bool = Field(default=True, description="Enable business metrics")
|
| 191 |
+
enable_audit_trail: bool = Field(default=True, description="Enable audit trail")
|
| 192 |
|
| 193 |
+
# Paths
|
| 194 |
+
data_dir: str = Field(default="./data", description="Data directory")
|
| 195 |
+
log_dir: str = Field(default="./logs", description="Log directory")
|
| 196 |
+
cache_dir: str = Field(default="./cache", description="Cache directory")
|
| 197 |
|
| 198 |
+
# API Settings
|
| 199 |
+
api_timeout: int = Field(default=30, description="API timeout in seconds")
|
| 200 |
+
max_retries: int = Field(default=3, description="Maximum API retries")
|
| 201 |
+
rate_limit: int = Field(default=100, description="API rate limit per minute")
|
| 202 |
|
| 203 |
+
# UI Settings
|
| 204 |
+
ui_theme: str = Field(default="dark", description="UI theme")
|
| 205 |
+
refresh_interval: int = Field(default=5, description="UI refresh interval in seconds")
|
|
|
|
|
|
|
| 206 |
|
| 207 |
+
# Business Settings
|
| 208 |
+
default_currency: str = Field(default="USD", description="Default currency")
|
| 209 |
+
cost_per_incident: float = Field(default=10000.0, description="Default cost per incident")
|
| 210 |
+
engineer_hourly_rate: float = Field(default=150.0, description="Engineer hourly rate")
|
| 211 |
|
| 212 |
+
@validator('arf_mode', 'safety_mode', 'installation_status', pre=True)
|
| 213 |
+
def validate_enum_strings(cls, v, field):
|
| 214 |
+
"""Convert string values to enums"""
|
| 215 |
+
if isinstance(v, str):
|
| 216 |
+
try:
|
| 217 |
+
if field.name == 'arf_mode':
|
| 218 |
+
return ARFMode(v.lower())
|
| 219 |
+
elif field.name == 'safety_mode':
|
| 220 |
+
return SafetyMode(v.lower())
|
| 221 |
+
elif field.name == 'installation_status':
|
| 222 |
+
return InstallationStatus(v.lower())
|
| 223 |
+
except ValueError:
|
| 224 |
+
# Return default value
|
| 225 |
+
if field.name == 'arf_mode':
|
| 226 |
+
return ARFMode.DEMO
|
| 227 |
+
elif field.name == 'safety_mode':
|
| 228 |
+
return SafetyMode.STANDARD
|
| 229 |
+
elif field.name == 'installation_status':
|
| 230 |
+
return InstallationStatus.DEMO_MODE
|
| 231 |
+
return v
|
| 232 |
+
|
| 233 |
+
@validator('installation_status', always=True)
|
| 234 |
+
def update_installation_status(cls, v, values):
|
| 235 |
+
"""Update installation status based on detected packages"""
|
| 236 |
+
# Check if OSS is installed
|
| 237 |
+
try:
|
| 238 |
+
import agentic_reliability_framework
|
| 239 |
+
values['oss_installed'] = True
|
| 240 |
+
except ImportError:
|
| 241 |
+
values['oss_installed'] = False
|
| 242 |
+
|
| 243 |
+
# Check if Enterprise is installed
|
| 244 |
+
try:
|
| 245 |
+
import agentic_reliability_enterprise
|
| 246 |
+
values['enterprise_installed'] = True
|
| 247 |
+
except ImportError:
|
| 248 |
+
values['enterprise_installed'] = False
|
| 249 |
+
|
| 250 |
+
# Determine installation status
|
| 251 |
+
if values.get('oss_installed') and values.get('enterprise_installed'):
|
| 252 |
+
return InstallationStatus.FULL_INSTALL
|
| 253 |
+
elif values.get('oss_installed'):
|
| 254 |
+
return InstallationStatus.OSS_ONLY
|
| 255 |
+
elif values.get('enterprise_installed'):
|
| 256 |
+
return InstallationStatus.ENTERPRISE_ONLY
|
| 257 |
+
else:
|
| 258 |
+
return InstallationStatus.DEMO_MODE
|
| 259 |
|
| 260 |
+
# Singleton settings instance
|
| 261 |
try:
|
| 262 |
+
settings = Settings()
|
| 263 |
+
logger.info("✅ Settings initialized successfully")
|
| 264 |
+
logger.info(f"📊 ARF Mode: {settings.arf_mode}")
|
| 265 |
+
logger.info(f"🛡️ Safety Mode: {settings.safety_mode}")
|
| 266 |
+
logger.info(f"📦 Installation Status: {settings.installation_status}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
except Exception as e:
|
| 268 |
+
logger.error(f"❌ Failed to initialize settings: {e}")
|
| 269 |
+
# Create fallback settings
|
| 270 |
+
class FallbackSettings:
|
| 271 |
+
arf_mode = ARFMode.DEMO
|
| 272 |
+
safety_mode = SafetyMode.STANDARD
|
| 273 |
+
debug = False
|
| 274 |
+
log_level = "INFO"
|
| 275 |
+
arf_version = "3.3.7"
|
| 276 |
+
demo_version = "3.8.0"
|
| 277 |
+
oss_installed = False
|
| 278 |
+
enterprise_installed = False
|
| 279 |
+
installation_status = InstallationStatus.DEMO_MODE
|
| 280 |
+
enable_telemetry = True
|
| 281 |
+
enable_anomaly_detection = True
|
| 282 |
+
enable_business_metrics = True
|
| 283 |
+
enable_audit_trail = True
|
| 284 |
+
data_dir = "./data"
|
| 285 |
+
log_dir = "./logs"
|
| 286 |
+
cache_dir = "./cache"
|
| 287 |
+
api_timeout = 30
|
| 288 |
+
max_retries = 3
|
| 289 |
+
rate_limit = 100
|
| 290 |
+
ui_theme = "dark"
|
| 291 |
+
refresh_interval = 5
|
| 292 |
+
default_currency = "USD"
|
| 293 |
+
cost_per_incident = 10000.0
|
| 294 |
+
engineer_hourly_rate = 150.0
|
| 295 |
+
|
| 296 |
+
settings = FallbackSettings()
|
| 297 |
+
logger.warning("⚠️ Using fallback settings due to initialization error")
|
| 298 |
|
| 299 |
def get_settings() -> Settings:
|
| 300 |
+
"""Get the settings singleton instance"""
|
| 301 |
+
return settings
|
| 302 |
+
|
| 303 |
+
# Export everything
|
| 304 |
+
__all__ = [
|
| 305 |
+
"Settings",
|
| 306 |
+
"get_settings",
|
| 307 |
+
"ARFMode",
|
| 308 |
+
"SafetyMode",
|
| 309 |
+
"InstallationStatus",
|
| 310 |
+
"settings"
|
| 311 |
+
]
|