这是一个批量整理提交,包含以下主要改动: 1. 删除多处冗余的空行和未使用的导入 2. 修复文件末尾缺少换行符的问题 3. 调整部分模块的导入顺序与代码排版 4. 修复部分配置默认值与策略逻辑 5. 新增多个功能模块与辅助工具 6. 完善异常处理与日志记录 7. 修复速率限制、消息缓存、权限校验等逻辑bug 8. 废弃部分旧有API与配置项并添加警告提示
56 lines
1.4 KiB
Python
56 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
|