refactor(plugin_system): 将插件管理API拆分为更专注的模块
`plugin_manage_api` 模块的职责过于宽泛,混合了插件生命周期、组件状态管理和信息查询等多种功能。为了提高代码的可维护性和清晰度,遵循单一职责原则,现将其进行拆分。 - 新增 `component_state_api.py` 模块,专门负责处理组件的启用/禁用状态管理,包括全局和局部作用域。 - 新增 `plugin_info_api.py` 模块,用于提供插件和组件的信息查询、报告生成和状态统计功能。 - `plugin_manage_api.py` 现在专注于插件的生命周期管理,如加载、重载、启用/禁用和卸载。 - 更新了内部调用方(例如 system_management 插件)以使用新的、职责更明确的API。 BREAKING CHANGE: 原 `plugin_manage_api` 中的大量函数已被移动。组件状态管理相关函数移至 `component_state_api`,信息查询和报告相关函数移至 `plugin_info_api`。
This commit is contained in:
@@ -12,6 +12,8 @@ from src.chat.utils.prompt_component_manager import prompt_component_manager
|
||||
from src.chat.utils.prompt_params import PromptParameters
|
||||
from src.plugin_system.apis import (
|
||||
chat_api,
|
||||
component_state_api,
|
||||
plugin_info_api,
|
||||
plugin_manage_api,
|
||||
)
|
||||
from src.plugin_system.apis.logging_api import get_logger
|
||||
@@ -434,7 +436,7 @@ class SystemCommand(PlusCommand):
|
||||
@require_permission("plugin.manage", deny_message="❌ 你没有权限查看插件报告")
|
||||
async def _show_system_report(self):
|
||||
"""显示系统插件报告"""
|
||||
report = plugin_manage_api.get_system_report()
|
||||
report = plugin_info_api.get_system_report()
|
||||
|
||||
response_parts = [
|
||||
"📊 **系统插件报告**",
|
||||
@@ -509,7 +511,7 @@ class SystemCommand(PlusCommand):
|
||||
stream_id = self.message.chat_info.stream_id # 默认作用于当前会话
|
||||
|
||||
# 1. 搜索组件
|
||||
found_components = plugin_manage_api.search_components_by_name(comp_name, exact_match=True)
|
||||
found_components = plugin_info_api.search_components_by_name(comp_name, exact_match=True)
|
||||
|
||||
if not found_components:
|
||||
await self.send_text(f"❌ 未找到名为 '{comp_name}' 的组件。")
|
||||
@@ -563,7 +565,7 @@ class SystemCommand(PlusCommand):
|
||||
stream_id = target_stream.stream_id
|
||||
|
||||
# 4. 执行操作
|
||||
success = plugin_manage_api.set_component_enabled_local(
|
||||
success = component_state_api.set_component_enabled_local(
|
||||
stream_id=stream_id,
|
||||
name=comp_name,
|
||||
component_type=component_type,
|
||||
|
||||
Reference in New Issue
Block a user