from __future__ import annotations import os from dataclasses import dataclass from pathlib import Path @dataclass class Settings: host: str port: int api_keys: list[str] lingma_bin: str lingma_work_dir: str lingma_socket_port: int lingma_startup_timeout: int lingma_rpc_timeout: int default_model: str default_ask_mode: str dedicated_domain_url: str auto_login_enabled: bool auto_login_headless: bool auto_login_timeout: int auto_login_max_retry: int lingma_username: str lingma_password: str def load_settings() -> Settings: keys_raw = os.getenv("API_KEYS", "") api_keys = [k.strip() for k in keys_raw.split(",") if k.strip()] work_dir = os.getenv( "LINGMA_WORK_DIR", str(Path.home() / ".lingma" / "vscode" / "sharedClientCache"), ) return Settings( host=os.getenv("HOST", "0.0.0.0"), port=int(os.getenv("PORT", "8317")), api_keys=api_keys, lingma_bin=os.getenv("LINGMA_BIN", "/app/bin/Lingma"), lingma_work_dir=work_dir, lingma_socket_port=int(os.getenv("LINGMA_SOCKET_PORT", "36510")), lingma_startup_timeout=int(os.getenv("LINGMA_STARTUP_TIMEOUT", "40")), lingma_rpc_timeout=int(os.getenv("LINGMA_RPC_TIMEOUT", "30")), default_model=os.getenv("DEFAULT_MODEL", "org_auto"), default_ask_mode=os.getenv("DEFAULT_ASK_MODE", "chat"), dedicated_domain_url=os.getenv("DEDICATED_DOMAIN_URL", "").strip(), auto_login_enabled=os.getenv("AUTO_LOGIN_ENABLED", "true").lower() in {"1", "true", "yes", "on"}, auto_login_headless=os.getenv("AUTO_LOGIN_HEADLESS", "true").lower() in {"1", "true", "yes", "on"}, auto_login_timeout=int(os.getenv("AUTO_LOGIN_TIMEOUT", "180")), auto_login_max_retry=int(os.getenv("AUTO_LOGIN_MAX_RETRY", "2")), lingma_username=os.getenv("LINGMA_USERNAME", "").strip(), lingma_password=os.getenv("LINGMA_PASSWORD", "").strip(), )