新增Slack适配器全套核心模块,包括消息处理流水线、会话管理、配置适配、权限控制等完整功能: 1. 新增语音、视觉相关的TTS和图像分析导出接口 2. 实现消息预处理、路由、线程上下文处理的完整流水线 3. 新增账号管理、缓存机制、房间上下文提取功能 4. 支持Webhook和Socket Mode两种事件接收方式 5. 实现权限白名单、审批配对、自动状态管理功能 6. 新增配置迁移、作用域校验、重连策略等辅助模块
54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from typing import Any
|
|
|
|
_INBOUND_FORMATTING_HINTS = {
|
|
"text_markup": "slack_mrkdwn",
|
|
"rules": [
|
|
"Bold uses *single asterisks* (not **double**)",
|
|
"Italic uses _underscores_ (not *single asterisks*)",
|
|
"Links use <https://url.com|label> format",
|
|
"Do not use markdown headings (# ## ###) or pipe tables",
|
|
"Inline code uses `backticks`, code blocks use ```triple backticks```",
|
|
],
|
|
}
|
|
|
|
_INTERACTIVE_REPLIES_HINT = (
|
|
"You can include interactive buttons in messages using:\n"
|
|
"[[slack_buttons: Label:value]] — creates up to 5 Block Kit buttons\n"
|
|
"To customize button style, use [[slack_buttons: Label:value:primary]] or [[slack_buttons: Label:value:danger]]\n"
|
|
"For select menus, use [[slack_select: Placeholder | Label:value]]\n"
|
|
)
|
|
|
|
_INTERACTIVE_REPLIES_DISABLED_HINT = (
|
|
"Interactive replies are currently disabled for this channel.\n"
|
|
"To enable, set `channels.slack.capabilities.interactiveReplies: true` in config."
|
|
)
|
|
|
|
|
|
@dataclass
|
|
class SlackPromptHints:
|
|
text_markup: str = "slack_mrkdwn"
|
|
formatting_rules: list[str] = field(default_factory=lambda: _INBOUND_FORMATTING_HINTS["rules"])
|
|
interactive_replies_enabled: bool = False
|
|
|
|
def inbound_formatting_hints(self) -> dict[str, Any]:
|
|
return {
|
|
"text_markup": self.text_markup,
|
|
"rules": self.formatting_rules,
|
|
}
|
|
|
|
def message_tool_hints(self) -> str:
|
|
if self.interactive_replies_enabled:
|
|
return _INTERACTIVE_REPLIES_HINT
|
|
return _INTERACTIVE_REPLIES_DISABLED_HINT
|
|
|
|
@classmethod
|
|
def from_config(cls, config: dict[str, Any] | None) -> SlackPromptHints:
|
|
if not config:
|
|
return cls()
|
|
capabilities = config.get("capabilities", {}) or {}
|
|
interactive = bool(capabilities.get("interactiveReplies", True))
|
|
return cls(interactive_replies_enabled=interactive)
|