"""全局配置"""

from pathlib import Path
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    """tool_agent 全局配置，支持环境变量覆盖"""

    # 项目路径
    base_dir: Path = Path(__file__).resolve().parent.parent.parent
    tools_dir: Path = base_dir / "tools"
    data_dir: Path = base_dir / "data"

    # 对外端口
    fastapi_port: int = 8001
    mcp_port: int = 8001

    # Docker 工具端口起始
    docker_port_start: int = 9001

    # Docker 容器默认配置
    docker_base_image: str = "agent-sandbox:latest"
    docker_mem_limit: str = "1g"
    docker_nano_cpus: int = 1_000_000_000  # 1 CPU
    docker_ttl_seconds: int = 1800  # 容器自动清理 TTL

    # 冷热调度
    cold_tool_idle_timeout_s: int = 300
    hot_tool_max_containers: int = 5
    eviction_policy: str = "lru"

    # 财务
    monthly_limit_usd: float = 100.0
    single_tx_limit_usd: float = 20.0
    require_approval_above_usd: float = 10.0

    # 健康检查
    health_check_interval_s: int = 60

    # KnowHub API
    knowhub_api: str = "http://43.106.118.91:9999"

    model_config = {"env_prefix": "TOOL_AGENT_"}


settings = Settings()
