notifier.py 630 B

12345678910111213141516171819202122
  1. import logging
  2. log = logging.getLogger(__name__)
  3. class AgentNotifier:
  4. """Agent 通知接口基类。
  5. 当 pending.json 有新消息时,Client 会调用 notify()。
  6. 每个 Agent 可以继承此类实现自己的通知方式。
  7. """
  8. async def notify(self, count: int, from_contacts: list[str]):
  9. raise NotImplementedError
  10. class ConsoleNotifier(AgentNotifier):
  11. """默认实现:打印到控制台。"""
  12. async def notify(self, count: int, from_contacts: list[str]):
  13. sources = ", ".join(from_contacts)
  14. log.info(f"[IM 通知] 你有 {count} 条新消息,来自: {sources}")