新增 iMessage 通道适配器完整实现,包含: 1. 核心适配器与工具工厂导出 2. 运行时存储、反射防护、会话路由等基础组件 3. 消息信封、线程管理、回复上下文格式化 4. Tapback 表情反应处理、自定义异常体系 5. 审批按钮、联系人解析、速率限制功能 6. 文本净化、目标解析、缓存管理模块 7. 配置 schema、多账户支持、安装向导等配置模块 8. 审计日志、媒体AI处理等扩展功能
57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
|
|
|
@dataclass
|
|
class ConversationRoute:
|
|
agent_id: str
|
|
channel_chat_id: str
|
|
source: str
|
|
|
|
|
|
def resolve_agent_route(
|
|
channel_chat_id: str,
|
|
configured_bindings: dict[str, str] | None = None,
|
|
runtime_bindings: dict[str, str] | None = None,
|
|
default_agent: str = "main",
|
|
) -> ConversationRoute:
|
|
if runtime_bindings and channel_chat_id in runtime_bindings:
|
|
return ConversationRoute(
|
|
agent_id=runtime_bindings[channel_chat_id],
|
|
channel_chat_id=channel_chat_id,
|
|
source="runtime_binding",
|
|
)
|
|
|
|
if configured_bindings and channel_chat_id in configured_bindings:
|
|
return ConversationRoute(
|
|
agent_id=configured_bindings[channel_chat_id],
|
|
channel_chat_id=channel_chat_id,
|
|
source="configured_binding",
|
|
)
|
|
|
|
return ConversationRoute(
|
|
agent_id=default_agent,
|
|
channel_chat_id=channel_chat_id,
|
|
source="default",
|
|
)
|
|
|
|
|
|
def resolve_configured_binding(
|
|
channel_chat_id: str,
|
|
bindings: dict[str, str] | None = None,
|
|
) -> str | None:
|
|
if bindings and channel_chat_id in bindings:
|
|
return bindings[channel_chat_id]
|
|
return None
|
|
|
|
|
|
def resolve_runtime_binding(
|
|
channel_chat_id: str,
|
|
bindings: dict[str, str] | None = None,
|
|
) -> str | None:
|
|
if bindings and channel_chat_id in bindings:
|
|
return bindings[channel_chat_id]
|
|
return None
|