protocols.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from __future__ import annotations
  2. from typing import Any, Protocol, runtime_checkable
  3. from gateway.core.channels.types import FeishuReplyContext, IncomingFeishuEvent
  4. @runtime_checkable
  5. class TraceBackend(Protocol):
  6. """与 Lifecycle.TraceManager 对接前的抽象:按渠道用户解析 trace_id。"""
  7. async def get_or_create_trace(
  8. self,
  9. *,
  10. channel: str,
  11. user_id: str,
  12. workspace_id: str,
  13. agent_type: str,
  14. metadata: dict[str, Any],
  15. ) -> str:
  16. ...
  17. @runtime_checkable
  18. class ExecutorBackend(Protocol):
  19. """与 Executor 对接前的抽象:处理入站用户文本并负责回呼飞书。"""
  20. async def handle_inbound_message(
  21. self,
  22. trace_id: str,
  23. text: str,
  24. reply_context: FeishuReplyContext,
  25. connector: Any,
  26. *,
  27. event: IncomingFeishuEvent,
  28. ) -> str:
  29. """返回 task_id 或占位 id。"""
  30. ...
  31. @runtime_checkable
  32. class UserIdentityResolver(Protocol):
  33. """将飞书事件映射为网关内统一 user_id(后续可换 DB 映射表)。"""
  34. def resolve_user_id(self, event: IncomingFeishuEvent) -> str:
  35. ...