ForcePilot/backend/package/yuxi/channels/capabilities.py
Kris 7a972055b7 feat: 新增渠道服务基础框架与核心工具类
新增大量渠道适配器相关的协议、策略、工具类与基础设施代码,包括:
1.  多协议定义:认证、消息、配置、网关等核心接口
2.  策略模块:上下文、群聊、去重、防抖等业务策略
3.  工具集:重试、去重、文本分块、消息格式化等SDK工具
4.  基础设施:外部进程管理、事件广播、熔断机制等
5.  账户与管道系统:账户管理、消息处理管道实现
6.  运行时服务:状态收集、维护任务、日志等后台服务
2026-05-12 00:53:57 +08:00

115 lines
2.9 KiB
Python

from __future__ import annotations
from pydantic import BaseModel, Field
class TTSVoiceCapabilities(BaseModel):
synthesis_target: str = "voice-note"
transcodes_audio: bool = False
enabled: bool = False
class TTSCapabilities(BaseModel):
voice: TTSVoiceCapabilities = Field(default_factory=TTSVoiceCapabilities)
class ChannelCapabilities(BaseModel):
"""渠道能力声明 — 标准能力标志
BaseChannelAdapter 子类通过声明此模型来告知 Gateway 和前端
该渠道支持哪些功能。Gateway 启动时收集所有渠道的此声明,
通过 get_channel_status() 向客户端广播可用能力集合。
"""
chat_types: list[str] = Field(default_factory=lambda: ["direct"])
delivery_mode: str = "direct"
polls: bool = False
reactions: bool = False
edit: bool = False
unsend: bool = False
reply: bool = False
effects: bool = False
group_management: bool = False
threads: bool = False
media: bool = False
max_media_size_mb: int = 100
tts: TTSCapabilities = Field(default_factory=TTSCapabilities)
native_commands: bool = False
block_streaming: bool = False
lane_streaming: bool = False
reasoning_streaming: bool = False
pin: bool = False
unpin: bool = False
list_pins: bool = False
send_ephemeral: bool = False
text_chunk_limit: int = 4096
supports_markdown: bool = False
supports_streaming: bool = False
streaming_modes: list[str] = Field(default_factory=lambda: ["off"])
delivery_mode: str = ""
def supported_actions(self) -> list[str]:
actions: list[str] = []
if self.media:
actions.append("send_media")
if self.edit:
actions.append("edit")
if self.unsend:
actions.append("delete")
if self.reactions:
actions.append("react")
if self.pin:
actions.append("pin")
if self.unpin:
actions.append("unpin")
if self.list_pins:
actions.append("list_pins")
if self.polls:
actions.append("create_poll")
if self.threads:
actions.append("create_thread")
if self.send_ephemeral:
actions.append("send_ephemeral")
if self.group_management:
actions.extend(["kick", "ban", "mute"])
return actions
CAPS_SIMPLE_TEXT = ChannelCapabilities()
CAPS_FULL_FEATURED = ChannelCapabilities(
chat_types=["direct", "group", "thread"],
polls=True,
reactions=True,
edit=True,
unsend=True,
reply=True,
threads=True,
media=True,
supports_markdown=True,
supports_streaming=True,
streaming_modes=["chunked", "live"],
)
CAPS_GROUP_CHAT_ONLY = ChannelCapabilities(
chat_types=["direct", "group"],
reply=True,
media=True,
group_management=True,
supports_markdown=True,
supports_streaming=True,
streaming_modes=["block"],
)