51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from dataclasses import dataclass
|
|
|
|
|
|
def _env_bool(name: str, default: bool) -> bool:
|
|
value = os.environ.get(name)
|
|
if value is None:
|
|
return default
|
|
return value.strip().lower() in {"1", "true", "yes", "on"}
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class PluginConfig:
|
|
gateway_url: str = "http://127.0.0.1:1934"
|
|
api_key: str = ""
|
|
default_user_id: str = ""
|
|
default_agent_id: str = ""
|
|
default_workspace_id: str = ""
|
|
auto_search: bool = True
|
|
auto_append_episode: bool = True
|
|
auto_commit_session: bool = False
|
|
review_mode: bool = True
|
|
timeout: int = 30
|
|
|
|
@classmethod
|
|
def from_env(cls) -> "PluginConfig":
|
|
try:
|
|
timeout_val = int(os.environ.get("MEMORY_GATEWAY_TIMEOUT", "30"))
|
|
except ValueError:
|
|
timeout_val = 30
|
|
|
|
return cls(
|
|
gateway_url=os.environ.get("MEMORY_GATEWAY_URL", cls.gateway_url).rstrip("/"),
|
|
api_key=os.environ.get("MEMORY_GATEWAY_API_KEY", ""),
|
|
default_user_id=os.environ.get("MEMORY_GATEWAY_DEFAULT_USER_ID", ""),
|
|
default_agent_id=os.environ.get("MEMORY_GATEWAY_DEFAULT_AGENT_ID", ""),
|
|
default_workspace_id=os.environ.get("MEMORY_GATEWAY_DEFAULT_WORKSPACE_ID", ""),
|
|
auto_search=_env_bool("MEMORY_GATEWAY_AUTO_SEARCH", True),
|
|
auto_append_episode=_env_bool("MEMORY_GATEWAY_AUTO_APPEND_EPISODE", True),
|
|
auto_commit_session=_env_bool("MEMORY_GATEWAY_AUTO_COMMIT_SESSION", False),
|
|
review_mode=_env_bool("MEMORY_GATEWAY_REVIEW_MODE", True),
|
|
timeout=timeout_val,
|
|
)
|
|
|
|
|
|
def load_config() -> PluginConfig:
|
|
return PluginConfig.from_env()
|
|
|