Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

5.3 KB
Raw Blame
"""
Base interface for settings management.

This module defines the abstract base class that all settings managers
must implement, ensuring a consistent interface.
"""

from abc import ABC, abstractmethod
from typing import Any, Dict, Optional, Union


class ISettingsManager(ABC):
    """Abstract base class for settings managers."""

    @abstractmethod
    def get_setting(
        self, key: str, default: Any = None, check_env: bool = True
    ) -> Any:
        """
        Get a setting value.

        Args:
            key: Setting key
            default: Default value if setting is not found
            check_env: If true, check environment variables first

        Returns:
            Setting value or default if not found

        Raises:
            SettingsValueError: The selected value cannot be converted to its
                declared type, or that type is unsupported.
        """
        pass

    @abstractmethod
    def set_setting(self, key: str, value: Any, commit: bool = True) -> bool:
        """
        Set a setting value.

        Args:
            key: Setting key
            value: Setting value
            commit: Whether to commit the change

        Returns:
            True if successful, False otherwise
        """
        pass

    @abstractmethod
    def get_all_settings(
        self,
        bypass_cache: bool = False,
        include_environment_overrides: bool = True,
        strict: bool = False,
    ) -> Dict[str, Any]:
        """
        Get all settings.

        Args:
            bypass_cache: If true, bypass any implementation cache.
            include_environment_overrides: If true, overlay current LDR_* values.
            strict: If true, propagate database and enum query failures.

        Returns:
            Dictionary of all settings with metadata

        Raises:
            SettingsValueError: With ``include_environment_overrides``, any
                effective value cannot be converted to its declared type, or
                that type is unsupported.
        """
        pass

    @abstractmethod
    def create_or_update_setting(
        self, setting: Union[Dict[str, Any], Any], commit: bool = True
    ) -> Optional[Any]:
        """
        Create or update a setting.

        Args:
            setting: Setting object or dictionary
            commit: Whether to commit the change

        Returns:
            The created or updated Setting model, or None if failed
        """
        pass

    @abstractmethod
    def delete_setting(
        self, key: str, commit: bool = True, override_locked: bool = False
    ) -> bool:
        """
        Delete a setting.

        Args:
            key: Setting key
            commit: Whether to commit the change
            override_locked: Delete even when settings are locked.

        Returns:
            True if successful, False otherwise
        """
        pass

    @abstractmethod
    def get_bool_setting(
        self, key: str, default: bool = False, check_env: bool = True
    ) -> bool:
        """
        Get a setting value as a boolean.

        Args:
            key: Setting key
            default: Default boolean value if setting is not found
            check_env: If true, check environment variables first

        Returns:
            Boolean value of the setting
        """
        pass

    @abstractmethod
    def get_settings_snapshot(self, strict: bool = False) -> Dict[str, Any]:
        """
        Get a simplified settings snapshot with just key-value pairs.

        Args:
            strict: If true, propagate database and enum query failures.

        Returns:
            Dictionary with setting keys mapped to their values
        """
        pass

    @abstractmethod
    def load_from_defaults_file(
        self,
        commit: bool = True,
        preserve_environment_locked: bool = False,
    ) -> None:
        """
        Import settings from the defaults settings file.

        Deliberately does not accept ``**kwargs``: forwarding them would
        expose ``import_settings``' settings-lock bypass
        (``override_locked``) through this wrapper (#5841). Trusted
        bootstrap callers spend the bypass via direct ``import_settings``
        calls.

        Args:
            commit: Whether to commit changes to database
            preserve_environment_locked: Preserve stored values for
                settings with active environment overrides while imported
                metadata is refreshed
        """
        pass

    @abstractmethod
    def import_settings(
        self,
        settings_data: Dict[str, Any],
        commit: bool = True,
        overwrite: bool = True,
        delete_extra: bool = False,
        preserve_environment_locked: bool = False,
        override_locked: bool = False,
    ) -> None:
        """
        Import settings from a dictionary.

        Args:
            settings_data: The raw settings data to import
            commit: Whether to commit the DB after loading
            overwrite: If true, overwrite existing settings
            delete_extra: If true, delete settings not in settings_data
            preserve_environment_locked: If true, preserve the stored value
                for settings with active environment overrides while imported
                metadata may refresh
            override_locked: Import even when settings are locked.
        """
        pass