refactor(chat): 简化Action和PlusCommand的调用预处理

移除 `ChatBot` 和 `ActionModifier` 中用于过滤禁用组件的模板代码。

这两个模块现在直接从 `ComponentRegistry` 获取为当前聊天会话(`stream_id`)定制的可用组件列表。所有关于组件是否启用的判断逻辑都已下沉到 `plugin_system` 核心中,使得上层调用代码更清晰,且不再需要依赖 `global_announcement_manager` 来进行手动过滤。
This commit is contained in:
minecraft1024a
2025-11-22 09:51:31 +08:00
parent 3e927f45bb
commit affd70b165
6 changed files with 53 additions and 44 deletions

View File

@@ -11,7 +11,7 @@ from src.common.logger import get_logger
from src.config.config import global_config, model_config
from src.llm_models.utils_model import LLMRequest
from src.plugin_system.base.component_types import ActionInfo
from src.plugin_system.core.global_announcement_manager import global_announcement_manager
if TYPE_CHECKING:
from src.common.data_models.message_manager_data_model import StreamContext
@@ -68,6 +68,16 @@ class ActionModifier:
"""
# 初始化log_prefix
await self._initialize_log_prefix()
# 根据 stream_id 加载当前可用的动作
await self.action_manager.load_actions(self.chat_id)
from src.plugin_system.base.component_types import ComponentType
from src.plugin_system.core.component_registry import component_registry
# 计算并记录禁用的动作数量
all_registered_actions = component_registry.get_components_by_type(ComponentType.ACTION)
loaded_actions_count = len(self.action_manager.get_using_actions())
disabled_actions_count = len(all_registered_actions) - loaded_actions_count
if disabled_actions_count > 0:
logger.info(f"{self.log_prefix} 用户禁用了 {disabled_actions_count} 个动作。")
logger.debug(f"{self.log_prefix}开始完整动作修改流程")
@@ -75,7 +85,6 @@ class ActionModifier:
removals_s2: list[tuple[str, str]] = []
removals_s3: list[tuple[str, str]] = []
self.action_manager.restore_actions()
all_actions = self.action_manager.get_using_actions()
# === 第0阶段根据聊天类型过滤动作 ===
@@ -126,15 +135,6 @@ class ActionModifier:
if message_content:
chat_content = chat_content + "\n" + f"现在,最新的消息是:{message_content}"
# === 第一阶段:去除用户自行禁用的 ===
disabled_actions = global_announcement_manager.get_disabled_chat_actions(self.chat_id)
if disabled_actions:
for disabled_action_name in disabled_actions:
if disabled_action_name in all_actions:
removals_s1.append((disabled_action_name, "用户自行禁用"))
self.action_manager.remove_action_from_using(disabled_action_name)
logger.debug(f"{self.log_prefix}阶段一移除动作: {disabled_action_name},原因: 用户自行禁用")
# === 第二阶段:检查动作的关联类型 ===
if not self.chat_stream:
logger.error(f"{self.log_prefix} chat_stream 未初始化,无法执行第二阶段")