from __future__ import annotations from typing import Any, TYPE_CHECKING if TYPE_CHECKING: from .adapter import WeChatAdapter class WeChatHeartbeatAdapter: def __init__(self, config: dict[str, Any]): self._typing_enabled = config.get("typing_indicator", False) self._heartbeat_interval = config.get("heartbeat_interval", 300.0) async def send_typing_indicator(self, send_fn, chat_id: str) -> None: if not self._typing_enabled: return try: await send_fn(chat_id, "...") except Exception: pass async def heartbeat_check(self, adapter: WeChatAdapter) -> dict[str, Any]: import time start = time.monotonic() try: health = await adapter.health_check() latency = (time.monotonic() - start) * 1000 return {"alive": health.status == "healthy", "latencyMs": latency} except Exception as e: return {"alive": False, "lastError": str(e)} @staticmethod def should_preserve_thread_id_for_group_heartbeat(config: dict[str, Any]) -> bool: return config.get("preserve_heartbeat_thread_id_for_group", False)