2026-02-01 22:25:28 +05:30
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2026-02-06 19:11:11 +05:30
|
|
|
from pathlib import Path
|
|
|
|
|
from typing import Self
|
|
|
|
|
|
|
|
|
|
from pydantic import model_validator
|
2026-02-01 22:25:28 +05:30
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
2026-02-06 19:11:11 +05:30
|
|
|
BACKEND_ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
DEFAULT_ENV_FILE = BACKEND_ROOT / ".env"
|
|
|
|
|
|
2026-02-01 22:25:28 +05:30
|
|
|
|
|
|
|
|
class Settings(BaseSettings):
|
2026-02-04 02:28:51 +05:30
|
|
|
model_config = SettingsConfigDict(
|
2026-02-06 19:11:11 +05:30
|
|
|
# Load `backend/.env` regardless of current working directory.
|
|
|
|
|
# (Important when running uvicorn from repo root or via a process manager.)
|
|
|
|
|
env_file=[DEFAULT_ENV_FILE, ".env"],
|
2026-02-04 02:28:51 +05:30
|
|
|
env_file_encoding="utf-8",
|
|
|
|
|
extra="ignore",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
environment: str = "dev"
|
|
|
|
|
database_url: str = "postgresql+psycopg://postgres:postgres@localhost:5432/openclaw_agency"
|
|
|
|
|
redis_url: str = "redis://localhost:6379/0"
|
|
|
|
|
|
|
|
|
|
# Clerk auth (auth only; roles stored in DB)
|
|
|
|
|
clerk_jwks_url: str = ""
|
|
|
|
|
clerk_verify_iat: bool = True
|
|
|
|
|
clerk_leeway: float = 10.0
|
|
|
|
|
|
2026-02-01 22:25:28 +05:30
|
|
|
cors_origins: str = ""
|
2026-02-04 03:46:46 +05:30
|
|
|
base_url: str = ""
|
2026-02-01 22:25:28 +05:30
|
|
|
|
2026-02-08 21:49:26 +05:30
|
|
|
# Optional: local directory where the backend is allowed to write "preserved" agent
|
|
|
|
|
# workspace files (e.g. USER.md/SELF.md/MEMORY.md). If empty, local writes are disabled
|
|
|
|
|
# and provisioning relies on the gateway API.
|
|
|
|
|
#
|
|
|
|
|
# Security note: do NOT point this at arbitrary system paths in production.
|
|
|
|
|
local_agent_workspace_root: str = ""
|
|
|
|
|
|
2026-02-04 02:28:51 +05:30
|
|
|
# Database lifecycle
|
|
|
|
|
db_auto_migrate: bool = False
|
|
|
|
|
|
2026-02-04 20:21:33 +05:30
|
|
|
# Logging
|
|
|
|
|
log_level: str = "INFO"
|
|
|
|
|
log_format: str = "text"
|
|
|
|
|
log_use_utc: bool = False
|
|
|
|
|
|
2026-02-06 19:11:11 +05:30
|
|
|
@model_validator(mode="after")
|
|
|
|
|
def _defaults(self) -> Self:
|
|
|
|
|
# In dev, default to applying Alembic migrations at startup to avoid schema drift
|
|
|
|
|
# (e.g. missing newly-added columns).
|
|
|
|
|
if "db_auto_migrate" not in self.model_fields_set and self.environment == "dev":
|
|
|
|
|
self.db_auto_migrate = True
|
|
|
|
|
return self
|
|
|
|
|
|
2026-02-01 22:25:28 +05:30
|
|
|
|
2026-02-04 02:28:51 +05:30
|
|
|
settings = Settings()
|