新增 iMessage 通道适配器完整实现,包含: 1. 核心适配器与工具工厂导出 2. 运行时存储、反射防护、会话路由等基础组件 3. 消息信封、线程管理、回复上下文格式化 4. Tapback 表情反应处理、自定义异常体系 5. 审批按钮、联系人解析、速率限制功能 6. 文本净化、目标解析、缓存管理模块 7. 配置 schema、多账户支持、安装向导等配置模块 8. 审计日志、媒体AI处理等扩展功能
32 lines
901 B
Python
32 lines
901 B
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from collections.abc import Awaitable, Callable
|
|
|
|
from yuxi.utils.logging_config import logger
|
|
|
|
DEFAULT_TRANSPORT_TIMEOUT_S = 30.0
|
|
DEFAULT_TRANSPORT_POLL_INTERVAL_S = 0.5
|
|
|
|
|
|
async def wait_for_transport_ready(
|
|
probe_fn: Callable[[], Awaitable[bool]],
|
|
timeout_s: float = DEFAULT_TRANSPORT_TIMEOUT_S,
|
|
poll_interval_s: float = DEFAULT_TRANSPORT_POLL_INTERVAL_S,
|
|
) -> bool:
|
|
deadline = asyncio.get_event_loop().time() + timeout_s
|
|
|
|
while asyncio.get_event_loop().time() < deadline:
|
|
try:
|
|
ready = await probe_fn()
|
|
if ready:
|
|
logger.info("[iMessage/Transport] Transport ready")
|
|
return True
|
|
except Exception:
|
|
pass
|
|
|
|
await asyncio.sleep(poll_interval_s)
|
|
|
|
logger.error(f"[iMessage/Transport] Transport not ready after {timeout_s}s")
|
|
return False
|