ForcePilot/backend/package/yuxi/channels/capabilities.py
Kris 1f78c44b03 refactor: 整理并清理项目中的冗余代码与格式问题
这是一个批量整理提交,包含以下主要改动:
1.  删除多处冗余的空行和未使用的导入
2.  修复文件末尾缺少换行符的问题
3.  调整部分模块的导入顺序与代码排版
4.  修复部分配置默认值与策略逻辑
5.  新增多个功能模块与辅助工具
6.  完善异常处理与日志记录
7.  修复速率限制、消息缓存、权限校验等逻辑bug
8.  废弃部分旧有API与配置项并添加警告提示
2026-05-12 14:51:53 +08:00

117 lines
3.0 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
vision: bool = False
approval: bool = False
typing: bool = False
text_chunk_limit: int = 4096
supports_markdown: bool = False
supports_streaming: bool = False
streaming_modes: list[str] = Field(default_factory=lambda: ["off"])
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"],
)