新增 Mattermost 渠道完整实现,包含适配器核心、消息处理、交互回调、命令支持、安全校验、多账号管理等功能,支持机器人消息发送、交互按钮、命令注册、投票功能以及配置动态修改等特性。
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
def resolve_agent_route(
|
|
config: dict[str, Any],
|
|
channel_id: str,
|
|
team_id: str | None = None,
|
|
user_id: str | None = None,
|
|
) -> dict[str, Any]:
|
|
"""Per-channel / Per-team Agent 路由解析。
|
|
|
|
根据消息来源的频道或团队,路由到不同的 AI Agent。
|
|
当配置中未指定路由时,使用默认 Agent。
|
|
"""
|
|
routes = config.get("agent_routes", {})
|
|
|
|
if team_id:
|
|
team_key = f"team:{team_id}"
|
|
if team_key in routes:
|
|
return routes[team_key]
|
|
|
|
if channel_id:
|
|
channel_key = f"channel:{channel_id}"
|
|
if channel_key in routes:
|
|
return routes[channel_key]
|
|
|
|
if user_id:
|
|
user_key = f"user:{user_id}"
|
|
if user_key in routes:
|
|
return routes[user_key]
|
|
|
|
default_agent = config.get("default_agent_id", "")
|
|
return {"agent_id": default_agent, "route": "default"}
|
|
|
|
|
|
def build_agent_route_map(config: dict[str, Any]) -> dict[str, Any]:
|
|
"""构建 Agent 路由映射表。"""
|
|
routes = config.get("agent_routes", {})
|
|
return {
|
|
"routes": routes,
|
|
"default_agent_id": config.get("default_agent_id", ""),
|
|
"route_count": len(routes),
|
|
}
|