"""Intelligente Kontext-Sammlung fuer den Hausmeister-Bot. Tool-Handler werden automatisch aus tools/*.py geladen. Hier bleiben nur Hilfsfunktionen fuer /commands und Backward-Compat. """ import sys import os sys.path.insert(0, os.path.dirname(__file__)) import tool_loader from tools.memory import set_source_type, last_suggest_result # noqa: F401 def get_tool_handlers(session_id: str = None) -> dict: """Registry: Tool-Name -> Handler. Wird von llm.ask_with_tools() genutzt.""" return tool_loader.get_handlers(session_id=session_id) # --- Backward-Compat fuer /commands die direkt aufrufen --- def gather_status() -> str: """Komplett-Status aller Container fuer /status.""" handlers = tool_loader.get_handlers() return handlers["get_all_containers"]() def gather_errors(hours: float = 2) -> str: handlers = tool_loader.get_handlers() return handlers["get_errors"](hours=hours) def gather_error_count(hours: float = 24) -> str: handlers = tool_loader.get_handlers() return handlers["count_errors"](hours=hours) def gather_container_status(query: str) -> str: handlers = tool_loader.get_handlers() return handlers["get_container_detail"](query=query) def gather_logs(container: str, hours: float = 1) -> str: handlers = tool_loader.get_handlers() return handlers["get_container_logs"](container=container, hours=hours) def gather_health(container: str) -> str: """Health-Check — bleibt hier weil es kein eigenes Tool ist.""" from core import loki_client health = loki_client.get_health(container, hours=24) status_emoji = {"healthy": "✅", "warning": "⚠️", "critical": "🔴"}.get( health.get("status", ""), "❓" ) return ( f"{status_emoji} {health.get('host', container)}\n" f"Status: {health.get('status', '?')}\n" f"Fehler (24h): {health.get('errors_last_{hours}h', '?')}\n" f"Sendet Logs: {'ja' if health.get('sending_logs') else 'nein'}" ) def gather_silence() -> str: handlers = tool_loader.get_handlers() return handlers["get_silent_hosts"]()