2026-07-06 21:55:17 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
|
|
|
|
|
import tomlkit
|
|
|
|
|
from tomlkit.exceptions import TOMLKitError
|
|
|
|
|
|
2026-07-20 18:21:27 +08:00
|
|
|
from .models import DEFAULT_SYSTEM_PROMPT as DEFAULT_SYSTEM_PROMPT
|
2026-07-21 22:55:51 +08:00
|
|
|
from .models import DEFAULT_TOOL_DIRECTIVES as DEFAULT_TOOL_DIRECTIVES
|
2026-07-14 23:24:17 +08:00
|
|
|
from .models import AgentConfig as AgentConfig
|
2026-07-06 21:55:17 +08:00
|
|
|
from .models import AnthropicProvider as AnthropicProvider
|
2026-07-14 17:19:21 +08:00
|
|
|
from .models import DatabaseConfig as DatabaseConfig
|
2026-07-06 21:55:17 +08:00
|
|
|
from .models import DeepseekProvider as DeepseekProvider
|
2026-07-20 18:08:27 +08:00
|
|
|
from .models import HttpTimeoutConfig as HttpTimeoutConfig
|
2026-07-06 21:55:17 +08:00
|
|
|
from .models import ModelConfig as ModelConfig
|
|
|
|
|
from .models import OpenAICompatibleProvider as OpenAICompatibleProvider
|
|
|
|
|
from .models import OpenAIProvider as OpenAIProvider
|
2026-07-24 16:19:50 +08:00
|
|
|
from .models import PluginsConfig as PluginsConfig
|
2026-07-06 21:55:17 +08:00
|
|
|
from .models import ProviderConfig as ProviderConfig
|
2026-07-21 22:55:51 +08:00
|
|
|
from .models import compose_agent_system_content as compose_agent_system_content
|
2026-07-06 21:55:17 +08:00
|
|
|
from .path import get_default_path as _get_default_path
|
|
|
|
|
from .store import ConfigFormatError as ConfigFormatError
|
|
|
|
|
from .store import ConfigStore as ConfigStore
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
default_config_source: Path = _get_default_path()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load(path: Path | None = None) -> ConfigStore:
|
|
|
|
|
"""Load configuration from a TOML file.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
path: Path to the config file. If ``None``, uses :data:`default_config_source`.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
A :class:`ConfigStore` with parsed providers.
|
|
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
|
ConfigFormatError: If the file contains invalid TOML.
|
|
|
|
|
"""
|
|
|
|
|
if path is None:
|
|
|
|
|
path = default_config_source
|
|
|
|
|
try:
|
|
|
|
|
with path.open() as f:
|
|
|
|
|
doc = tomlkit.parse(f.read())
|
|
|
|
|
except FileNotFoundError:
|
|
|
|
|
doc = tomlkit.document()
|
|
|
|
|
except TOMLKitError as exc:
|
|
|
|
|
raise ConfigFormatError(str(exc)) from exc
|
|
|
|
|
return ConfigStore(path=path, document=doc)
|