from __future__ import annotations

import os
from dataclasses import dataclass


@dataclass
class SpiderConfig:
    """封装智能体运行时配置。"""

    model_name: str = "qwen3.5-plus"
    base_url: str = "https://dashscope.aliyuncs.com/compatible-mode/v1"
    api_key_env: str = "DASHSCOPE_API_KEY"
    api_key: str | None = None

    def resolve_api_key(self) -> str | None:
        """获取可用 API Key，优先使用显式传入值。"""
        return self.api_key or os.getenv(self.api_key_env)
