ForcePilot/backend/package/yuxi/channels/adapters/slack/group_policy.py
Kris a2aa782b86 feat(slack adapter): 实现完整的Slack频道适配器基础功能
新增Slack适配器全套核心模块,包括消息处理流水线、会话管理、配置适配、权限控制等完整功能:
1. 新增语音、视觉相关的TTS和图像分析导出接口
2. 实现消息预处理、路由、线程上下文处理的完整流水线
3. 新增账号管理、缓存机制、房间上下文提取功能
4. 支持Webhook和Socket Mode两种事件接收方式
5. 实现权限白名单、审批配对、自动状态管理功能
6. 新增配置迁移、作用域校验、重连策略等辅助模块
2026-05-12 00:48:57 +08:00

62 lines
1.9 KiB
Python

from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any
@dataclass
class PerChannelPolicy:
require_mention: bool = False
tools_send_enabled: bool = True
@classmethod
def from_config_entry(cls, entry: dict[str, Any] | None) -> PerChannelPolicy:
if not entry:
return cls()
return cls(
require_mention=bool(entry.get("requireMention", False)),
tools_send_enabled=bool(entry.get("tools", {}).get("send", {}).get("enabled", True)),
)
@dataclass
class GroupPolicyRegistry:
channels: dict[str, PerChannelPolicy] = field(default_factory=dict)
def get_policy(self, channel_id: str) -> PerChannelPolicy:
return self.channels.get(channel_id, PerChannelPolicy())
def set_policy(self, channel_id: str, policy: PerChannelPolicy) -> None:
self.channels[channel_id] = policy
@classmethod
def from_config(cls, config: dict[str, Any] | None) -> GroupPolicyRegistry:
if not config:
return cls()
channels_config = config.get("channels", {}) or {}
channels: dict[str, PerChannelPolicy] = {}
for ch_id, ch_config in channels_config.items():
if isinstance(ch_config, dict):
channels[ch_id] = PerChannelPolicy.from_config_entry(ch_config)
return cls(channels=channels)
def resolve_group_require_mention(
channel_id: str,
registry: GroupPolicyRegistry,
global_require_mention: bool = False,
) -> bool:
policy = registry.get_policy(channel_id)
return policy.require_mention or global_require_mention
def resolve_group_tool_policy(
channel_id: str,
registry: GroupPolicyRegistry,
tool_name: str = "send",
) -> bool:
policy = registry.get_policy(channel_id)
if tool_name == "send":
return policy.tools_send_enabled
return True