新增Slack适配器全套核心模块,包括消息处理流水线、会话管理、配置适配、权限控制等完整功能: 1. 新增语音、视觉相关的TTS和图像分析导出接口 2. 实现消息预处理、路由、线程上下文处理的完整流水线 3. 新增账号管理、缓存机制、房间上下文提取功能 4. 支持Webhook和Socket Mode两种事件接收方式 5. 实现权限白名单、审批配对、自动状态管理功能 6. 新增配置迁移、作用域校验、重连策略等辅助模块
68 lines
2.5 KiB
Python
68 lines
2.5 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from typing import Any
|
|
|
|
|
|
@dataclass
|
|
class ConfigAdapterResult:
|
|
config: dict[str, Any]
|
|
warnings: list[str] = field(default_factory=list)
|
|
migrated_fields: list[str] = field(default_factory=list)
|
|
|
|
|
|
def adapt_config(config: dict[str, Any] | None) -> ConfigAdapterResult:
|
|
if not config:
|
|
return ConfigAdapterResult(config={})
|
|
|
|
result = ConfigAdapterResult(config=dict(config))
|
|
|
|
_adapt_streaming(result)
|
|
_adapt_security(result)
|
|
_adapt_capabilities(result)
|
|
_adapt_dm_scope(result)
|
|
|
|
return result
|
|
|
|
|
|
def _adapt_streaming(result: ConfigAdapterResult) -> None:
|
|
streaming = result.config.get("streaming", {})
|
|
if isinstance(streaming, str):
|
|
result.config["streaming"] = {"mode": streaming}
|
|
result.warnings.append("streaming config was a string, converted to {mode: ...}")
|
|
result.migrated_fields.append("streaming")
|
|
|
|
legacy_stream = result.config.pop("streamMode_ENABLED", None)
|
|
if legacy_stream is not None:
|
|
result.config.setdefault("streaming", {})
|
|
if isinstance(result.config["streaming"], str):
|
|
result.config["streaming"] = {"mode": result.config["streaming"]}
|
|
result.config["streaming"]["mode"] = "auto"
|
|
result.warnings.append("Legacy streamMode_ENABLED migrated to streaming.mode=auto")
|
|
result.migrated_fields.append("streamMode_ENABLED")
|
|
|
|
|
|
def _adapt_security(result: ConfigAdapterResult) -> None:
|
|
security = result.config.get("security", {})
|
|
if isinstance(security, str):
|
|
result.config["security"] = {"mode": security}
|
|
result.warnings.append("security config was a string, converted to object")
|
|
result.migrated_fields.append("security")
|
|
|
|
|
|
def _adapt_capabilities(result: ConfigAdapterResult) -> None:
|
|
legacy_exec_approvals = result.config.pop("execApprovalsEnabled", None)
|
|
if legacy_exec_approvals is not None:
|
|
caps = result.config.setdefault("capabilities", {})
|
|
caps["execApprovals"] = bool(legacy_exec_approvals)
|
|
result.warnings.append("Legacy execApprovalsEnabled migrated to capabilities.execApprovals")
|
|
result.migrated_fields.append("execApprovalsEnabled")
|
|
|
|
|
|
def _adapt_dm_scope(result: ConfigAdapterResult) -> None:
|
|
legacy_dm = result.config.pop("dm_chat", None)
|
|
if legacy_dm is not None:
|
|
result.config["dm_scope"] = legacy_dm
|
|
result.warnings.append("Legacy dm_chat migrated to dm_scope")
|
|
result.migrated_fields.append("dm_chat")
|