Initial commit: Matrix Bridge Daemon
Persistent Python daemon connecting Matrix DM room to AiAgent API. - Config-driven (JSON config file) - Extensible command system (/new_session, /help) - Typing indicators while agent processes - Session auto-naming for identification - Persistent state across restarts - Token refresh, retry logic, error handling - Python stdlib only — no external dependencies
This commit is contained in:
59
config.py
Normal file
59
config.py
Normal file
@@ -0,0 +1,59 @@
|
||||
"""Configuration loader for the Matrix Bridge.
|
||||
|
||||
Loads settings from config.json and provides typed access via dataclasses.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Optional
|
||||
|
||||
|
||||
DEFAULT_CONFIG_PATH = os.path.join(os.path.dirname(__file__), "config.json")
|
||||
|
||||
|
||||
@dataclass
|
||||
class MatrixConfig:
|
||||
server: str
|
||||
user_id: str
|
||||
room_id: str
|
||||
credentials_file: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class AgentConfig:
|
||||
base_url: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class BridgeConfig:
|
||||
poll_interval_seconds: int = 1
|
||||
state_file: str = "/home/admin/agent-dir/bridge-state.json"
|
||||
matrix_poll_timeout: int = 0
|
||||
agent_timeout_seconds: int = 30
|
||||
agent_retries: int = 3
|
||||
max_message_length: int = 40000
|
||||
processed_ids_limit: int = 200
|
||||
agent_response_timeout: int = 300
|
||||
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
matrix: MatrixConfig
|
||||
agent: AgentConfig
|
||||
bridge: BridgeConfig = field(default_factory=BridgeConfig)
|
||||
|
||||
@classmethod
|
||||
def load(cls, path: str = DEFAULT_CONFIG_PATH) -> "Config":
|
||||
"""Load configuration from a JSON file."""
|
||||
with open(path, "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
matrix = MatrixConfig(**data.get("matrix", {}))
|
||||
agent = AgentConfig(**data.get("agent", {}))
|
||||
bridge_data = data.get("bridge", {})
|
||||
bridge = BridgeConfig(**bridge_data)
|
||||
|
||||
return cls(matrix=matrix, agent=agent, bridge=bridge)
|
||||
Reference in New Issue
Block a user