Files
MoviePilot/app/application/commands.py
jxxghp 7e851dbfa7 refactor(chain): 处理链功能域 mixin 化,清理未使用导入并根治兼容层循环导入
- ChainBase 拆分为 RecognitionMixin/MessageProcessingMixin/NotificationMixin
- TransferChain 拆分为 7 个功能 mixin(_mixins.py),SubscribeChain 音乐订阅域拆出 _music.py
- 斜杠命令交互四件套收敛为 InteractionChainMixin 委托,会话管理器移至 application 层,chain 层不再 re-export
- 模块基础类收敛到 app/modules/_base(notification/mediaserver 语义重命名)
- 清理 app/chain/__init__.py 24 个未使用导入,修正 49 处测试 patch 目标到实际命名空间
- 兼容层 legacy 符号不再并入 __all__,根治 schemas 初始化反向拉起 application.transfer 的循环导入
- 修复 bangumi 集数为字符串时 set_bangumi_info 抛 TypeError
- 新增重复代码等架构门禁测试;capability 清单校验排除下划线内部目录
2026-08-16 16:30:16 +08:00

46 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""命令工具服务门面。
Agent 工具与 API 端点对命令注册表的操作统一经本模块调用,
Command 实现由 startup 组合根在导入期注册,避免 application 层
静态依赖顶层 command 模块。
依赖方向:
agent.tools / api.endpoints -> application.commands <- startup(注册 Command 类)
"""
from typing import Any, Dict, Optional
# Command 类:由 startup/command_initializer 在导入期注册。
_command_class: Any = None
def register_command_class(command_class: Any) -> None:
"""注册 Command 类(组合根在导入期调用)。"""
global _command_class
_command_class = command_class
def get_command_object() -> Any:
"""返回命令注册表实例。"""
if _command_class is None:
raise RuntimeError(
"命令服务未初始化:请先通过 register_command_class 注册 Command 类"
)
return _command_class()
def get_commands() -> Dict[str, Any]:
"""返回全部已注册命令。"""
return get_command_object().get_commands()
def get_command(name: str) -> Optional[Any]:
"""按命令名查询注册表。"""
return get_command_object().get(name)
def init_commands(plugin_id: Optional[str] = None) -> None:
"""初始化命令(可指定单个插件)。"""
get_command_object().init_commands(plugin_id)