新增大量渠道适配器相关的协议、策略、工具类与基础设施代码,包括: 1. 多协议定义:认证、消息、配置、网关等核心接口 2. 策略模块:上下文、群聊、去重、防抖等业务策略 3. 工具集:重试、去重、文本分块、消息格式化等SDK工具 4. 基础设施:外部进程管理、事件广播、熔断机制等 5. 账户与管道系统:账户管理、消息处理管道实现 6. 运行时服务:状态收集、维护任务、日志等后台服务
42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
from dataclasses import dataclass
|
|
from enum import StrEnum
|
|
|
|
from yuxi.channels.models import ChannelMessage
|
|
|
|
|
|
class ContextCommand(StrEnum):
|
|
RESET = "reset"
|
|
HISTORY = "history"
|
|
CONTEXT = "context"
|
|
SUMMARY = "summary"
|
|
|
|
|
|
@dataclass
|
|
class ContextCommandResult:
|
|
handled: bool
|
|
command: ContextCommand | None = None
|
|
args: str = ""
|
|
is_unknown_command: bool = False
|
|
|
|
|
|
class ContextPolicy:
|
|
COMMAND_PREFIX = "/"
|
|
|
|
def parse(self, message: ChannelMessage) -> ContextCommandResult:
|
|
content = message.content.strip()
|
|
if not content.startswith(self.COMMAND_PREFIX):
|
|
return ContextCommandResult(handled=False)
|
|
|
|
parts = content[1:].split(maxsplit=1)
|
|
cmd = parts[0].lower()
|
|
args = parts[1] if len(parts) > 1 else ""
|
|
|
|
try:
|
|
return ContextCommandResult(
|
|
handled=True,
|
|
command=ContextCommand(cmd),
|
|
args=args,
|
|
)
|
|
except ValueError:
|
|
return ContextCommandResult(handled=False, is_unknown_command=True)
|