protocols.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. """飞书渠道在通用 ``ExecutorBackend`` / ``UserIdentityResolver`` 上的类型收窄。"""
  2. from __future__ import annotations
  3. from typing import Any, Protocol, runtime_checkable
  4. from gateway.core.channels.feishu.types import FeishuReplyContext, IncomingFeishuEvent
  5. from gateway.core.channels.protocols import ExecutorBackend, UserIdentityResolver
  6. __all__ = ["FeishuExecutorBackend", "FeishuUserIdentityResolver"]
  7. @runtime_checkable
  8. class FeishuExecutorBackend(ExecutorBackend, Protocol):
  9. """飞书执行器——窄化 ``ExecutorBackend`` 的参数类型为飞书专属结构。"""
  10. async def handle_inbound_message(
  11. self,
  12. existing_agent_trace_id: str,
  13. text: str,
  14. reply_context: FeishuReplyContext,
  15. connector: Any,
  16. *,
  17. event: IncomingFeishuEvent,
  18. ) -> tuple[str, str]:
  19. """返回 ``(task_id, agent_trace_id)``;失败时 ``agent_trace_id`` 为空。"""
  20. ...
  21. @runtime_checkable
  22. class FeishuUserIdentityResolver(UserIdentityResolver, Protocol):
  23. """飞书用户身份解析器——窄化 ``UserIdentityResolver`` 的事件类型为 ``IncomingFeishuEvent``。"""
  24. def resolve_user_id(self, event: IncomingFeishuEvent) -> str:
  25. ...