refactor(chat): 简化Action和PlusCommand的调用预处理
移除 `ChatBot` 和 `ActionModifier` 中用于过滤禁用组件的模板代码。 这两个模块现在直接从 `ComponentRegistry` 获取为当前聊天会话(`stream_id`)定制的可用组件列表。所有关于组件是否启用的判断逻辑都已下沉到 `plugin_system` 核心中,使得上层调用代码更清晰,且不再需要依赖 `global_announcement_manager` 来进行手动过滤。
This commit is contained in:
@@ -857,6 +857,23 @@ class ComponentRegistry:
|
||||
info = self.get_component_info(command_name, ComponentType.PLUS_COMMAND)
|
||||
return info if isinstance(info, PlusCommandInfo) else None
|
||||
|
||||
def get_available_plus_commands_info(self, stream_id: str | None = None) -> dict[str, PlusCommandInfo]:
|
||||
"""获取在指定上下文中所有可用的PlusCommand信息
|
||||
|
||||
Args:
|
||||
stream_id: 可选的流ID,用于检查局部组件状态
|
||||
|
||||
Returns:
|
||||
一个字典,键是命令名,值是 PlusCommandInfo 对象
|
||||
"""
|
||||
all_plus_commands = self.get_components_by_type(ComponentType.PLUS_COMMAND)
|
||||
available_commands = {
|
||||
name: info
|
||||
for name, info in all_plus_commands.items()
|
||||
if self.is_component_available(name, ComponentType.PLUS_COMMAND, stream_id)
|
||||
}
|
||||
return cast(dict[str, PlusCommandInfo], available_commands)
|
||||
|
||||
# === EventHandler 特定查询方法 ===
|
||||
|
||||
def get_event_handler_registry(self) -> dict[str, type[BaseEventHandler]]:
|
||||
|
||||
@@ -217,12 +217,11 @@ class ToolExecutor:
|
||||
return tool_results, [], ""
|
||||
|
||||
def _get_tool_definitions(self) -> list[dict[str, Any]]:
|
||||
all_tools = get_llm_available_tool_definitions()
|
||||
user_disabled_tools = global_announcement_manager.get_disabled_chat_tools(self.chat_id)
|
||||
all_tools = get_llm_available_tool_definitions(self.chat_id)
|
||||
|
||||
# 获取基础工具定义(包括二步工具的第一步)
|
||||
tool_definitions = [
|
||||
definition for definition in all_tools if definition.get("function", {}).get("name") not in user_disabled_tools
|
||||
definition for definition in all_tools if definition.get("function", {}).get("name")
|
||||
]
|
||||
|
||||
# 检查是否有待处理的二步工具第二步调用
|
||||
|
||||
Reference in New Issue
Block a user