修复了一些bug,修改了插件加载输出
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from typing import List, Any, Optional, Type
|
from typing import List, Any, Optional, Type
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger
|
||||||
from rich.traceback import install
|
from rich.traceback import install
|
||||||
from src.plugin_system.base.component_types import ToolInfo
|
from src.plugin_system.base.component_types import ComponentType, ToolInfo
|
||||||
install(extra_lines=3)
|
install(extra_lines=3)
|
||||||
|
|
||||||
logger = get_logger("base_tool")
|
logger = get_logger("base_tool")
|
||||||
@@ -44,14 +44,15 @@ class BaseTool:
|
|||||||
raise NotImplementedError(f"工具类 {cls.__name__} 必须定义 name 和 description 属性")
|
raise NotImplementedError(f"工具类 {cls.__name__} 必须定义 name 和 description 属性")
|
||||||
|
|
||||||
return ToolInfo(
|
return ToolInfo(
|
||||||
tool_name=cls.name,
|
name=cls.name,
|
||||||
tool_description=cls.description,
|
tool_description=cls.description,
|
||||||
available_for_llm=cls.available_for_llm,
|
available_for_llm=cls.available_for_llm,
|
||||||
tool_parameters=cls.parameters
|
tool_parameters=cls.parameters,
|
||||||
|
component_type=ComponentType.TOOL,
|
||||||
)
|
)
|
||||||
|
|
||||||
# 工具参数定义,子类必须重写
|
# 工具参数定义,子类必须重写
|
||||||
async def execute(self, **function_args: dict[str, Any]) -> dict[str, Any]:
|
async def execute(self, function_args: dict[str, Any]) -> dict[str, Any]:
|
||||||
"""执行工具函数
|
"""执行工具函数
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
@@ -150,7 +150,6 @@ class CommandInfo(ComponentInfo):
|
|||||||
class ToolInfo(ComponentInfo):
|
class ToolInfo(ComponentInfo):
|
||||||
"""工具组件信息"""
|
"""工具组件信息"""
|
||||||
|
|
||||||
tool_name: str = "" # 工具名称
|
|
||||||
tool_parameters: Dict[str, Any] = field(default_factory=dict) # 工具参数定义
|
tool_parameters: Dict[str, Any] = field(default_factory=dict) # 工具参数定义
|
||||||
available_for_llm: bool = True # 是否可供LLM使用
|
available_for_llm: bool = True # 是否可供LLM使用
|
||||||
tool_description: str = "" # 工具描述
|
tool_description: str = "" # 工具描述
|
||||||
|
|||||||
@@ -199,6 +199,8 @@ class ComponentRegistry:
|
|||||||
if tool_info.available_for_llm and tool_info.enabled:
|
if tool_info.available_for_llm and tool_info.enabled:
|
||||||
self._llm_available_tools[tool_name] = tool_class
|
self._llm_available_tools[tool_name] = tool_class
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def _register_event_handler_component(
|
def _register_event_handler_component(
|
||||||
self, handler_info: EventHandlerInfo, handler_class: Type[BaseEventHandler]
|
self, handler_info: EventHandlerInfo, handler_class: Type[BaseEventHandler]
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
|||||||
@@ -345,6 +345,7 @@ class PluginManager:
|
|||||||
stats = component_registry.get_registry_stats()
|
stats = component_registry.get_registry_stats()
|
||||||
action_count = stats.get("action_components", 0)
|
action_count = stats.get("action_components", 0)
|
||||||
command_count = stats.get("command_components", 0)
|
command_count = stats.get("command_components", 0)
|
||||||
|
tool_count = stats.get("tool_components", 0)
|
||||||
event_handler_count = stats.get("event_handlers", 0)
|
event_handler_count = stats.get("event_handlers", 0)
|
||||||
total_components = stats.get("total_components", 0)
|
total_components = stats.get("total_components", 0)
|
||||||
|
|
||||||
@@ -352,7 +353,7 @@ class PluginManager:
|
|||||||
if total_registered > 0:
|
if total_registered > 0:
|
||||||
logger.info("🎉 插件系统加载完成!")
|
logger.info("🎉 插件系统加载完成!")
|
||||||
logger.info(
|
logger.info(
|
||||||
f"📊 总览: {total_registered}个插件, {total_components}个组件 (Action: {action_count}, Command: {command_count}, EventHandler: {event_handler_count})"
|
f"📊 总览: {total_registered}个插件, {total_components}个组件 (Action: {action_count}, Command: {command_count}, Tool: {tool_count}, EventHandler: {event_handler_count})"
|
||||||
)
|
)
|
||||||
|
|
||||||
# 显示详细的插件列表
|
# 显示详细的插件列表
|
||||||
@@ -387,6 +388,9 @@ class PluginManager:
|
|||||||
command_components = [
|
command_components = [
|
||||||
c for c in plugin_info.components if c.component_type == ComponentType.COMMAND
|
c for c in plugin_info.components if c.component_type == ComponentType.COMMAND
|
||||||
]
|
]
|
||||||
|
tool_components = [
|
||||||
|
c for c in plugin_info.components if c.component_type == ComponentType.TOOL
|
||||||
|
]
|
||||||
event_handler_components = [
|
event_handler_components = [
|
||||||
c for c in plugin_info.components if c.component_type == ComponentType.EVENT_HANDLER
|
c for c in plugin_info.components if c.component_type == ComponentType.EVENT_HANDLER
|
||||||
]
|
]
|
||||||
@@ -398,7 +402,9 @@ class PluginManager:
|
|||||||
if command_components:
|
if command_components:
|
||||||
command_names = [c.name for c in command_components]
|
command_names = [c.name for c in command_components]
|
||||||
logger.info(f" ⚡ Command组件: {', '.join(command_names)}")
|
logger.info(f" ⚡ Command组件: {', '.join(command_names)}")
|
||||||
|
if tool_components:
|
||||||
|
tool_names = [c.name for c in tool_components]
|
||||||
|
logger.info(f" 🛠️ Tool组件: {', '.join(tool_names)}")
|
||||||
if event_handler_components:
|
if event_handler_components:
|
||||||
event_handler_names = [c.name for c in event_handler_components]
|
event_handler_names = [c.name for c in event_handler_components]
|
||||||
logger.info(f" 📢 EventHandler组件: {', '.join(event_handler_names)}")
|
logger.info(f" 📢 EventHandler组件: {', '.join(event_handler_names)}")
|
||||||
|
|||||||
Reference in New Issue
Block a user