"""API 和外部服务配置。"""

import os


def _env(name: str, default: str = "", required: bool = False) -> str:
    value = os.environ.get(name, default)
    if required and not value:
        raise RuntimeError(f"缺少必要环境变量: {name}")
    return value


API_BASE_URL = _env("AGENT_API_BASE_URL", "https://api.example.com")
API_KEY = _env("AGENT_API_KEY", required=True)
MODEL_ID = _env("AGENT_MODEL_ID", "deepseek-chat")

# 推理模型配置（智能思考模式使用）
THINKING_API_BASE_URL = _env("AGENT_THINKING_API_BASE_URL", API_BASE_URL)
THINKING_API_KEY = _env("AGENT_THINKING_API_KEY", API_KEY)
THINKING_MODEL_ID = _env("AGENT_THINKING_MODEL_ID", MODEL_ID)

# Tavily 搜索（可选）
TAVILY_API_KEY = _env("AGENT_TAVILY_API_KEY", "")

# 默认响应 token 限制
DEFAULT_RESPONSE_MAX_TOKENS = int(os.environ.get("AGENT_DEFAULT_RESPONSE_MAX_TOKENS", "32768"))

__all__ = [
    "API_BASE_URL",
    "API_KEY",
    "MODEL_ID",
    "TAVILY_API_KEY",
    "DEFAULT_RESPONSE_MAX_TOKENS",
    "THINKING_API_BASE_URL",
    "THINKING_API_KEY",
    "THINKING_MODEL_ID",
]
