新增 iMessage 通道适配器完整实现,包含: 1. 核心适配器与工具工厂导出 2. 运行时存储、反射防护、会话路由等基础组件 3. 消息信封、线程管理、回复上下文格式化 4. Tapback 表情反应处理、自定义异常体系 5. 审批按钮、联系人解析、速率限制功能 6. 文本净化、目标解析、缓存管理模块 7. 配置 schema、多账户支持、安装向导等配置模块 8. 审计日志、媒体AI处理等扩展功能
34 lines
930 B
Python
34 lines
930 B
Python
from __future__ import annotations
|
|
|
|
import re
|
|
|
|
_TOOL_CALL_RE = re.compile(r"\[TOOL_CALL:", re.IGNORECASE)
|
|
_ASSISTANT_MARKER_RE = re.compile(r"\[ASSISTANT_SYSTEM\]", re.IGNORECASE)
|
|
|
|
|
|
class ReflectionGuard:
|
|
"""反射防护:检测入站消息中是否包含 Assistant 内部标记。
|
|
|
|
当出站消息包含 [TOOL_CALL:...] 等内部标记,且被 Bridge 反射回
|
|
入站事件时,应丢弃此类消息,避免 Assistant 将其解析为指令。
|
|
"""
|
|
|
|
def __init__(self):
|
|
self._blocked_count = 0
|
|
|
|
def is_reflection(self, text: str) -> bool:
|
|
if not text:
|
|
return False
|
|
if _TOOL_CALL_RE.search(text):
|
|
return True
|
|
if _ASSISTANT_MARKER_RE.search(text):
|
|
return True
|
|
return False
|
|
|
|
def mark_blocked(self) -> None:
|
|
self._blocked_count += 1
|
|
|
|
@property
|
|
def blocked_count(self) -> int:
|
|
return self._blocked_count
|