"""KiloStar 集中式环境变量管理。 所有散落在各模块的 os.getenv/os.environ 收敛到此处, 通过 pydantic-settings 统一校验、类型转换、默认值管理。 """ from __future__ import annotations from functools import lru_cache from pydantic import Field from pydantic_settings import BaseSettings class DatabaseSettings(BaseSettings): postgres_user: str = "postgres" postgres_password: str = "" postgres_host: str = "db" postgres_port: int = 5432 postgres_db: str = "postgres" class SecuritySettings(BaseSettings): secret_key: str = "" kilostar_secret_key: str = "" kilostar_env: str = "production" class LogSettings(BaseSettings): kilostar_log_level: str = "DEBUG" kilostar_log_format: str = "" kilostar_log_json: str = "" class OnebotSettings(BaseSettings): onebot_access_token: str = "" onebot_http_url: str = "http://127.0.0.1:5700" class AppSettings(BaseSettings): kilostar_mode: str = "distributed" kilostar_lang: str = "zh" kilostar_cors_origins: str = "" db: DatabaseSettings = Field(default_factory=DatabaseSettings) security: SecuritySettings = Field(default_factory=SecuritySettings) log: LogSettings = Field(default_factory=LogSettings) onebot: OnebotSettings = Field(default_factory=OnebotSettings) model_config = {"env_nested_delimiter": "__"} @lru_cache(maxsize=1) def get_settings() -> AppSettings: return AppSettings()