diff --git a/src/plugin_system/base/base_event_plugin.py b/src/plugin_system/base/base_event_plugin.py new file mode 100644 index 000000000..8ca16e7a6 --- /dev/null +++ b/src/plugin_system/base/base_event_plugin.py @@ -0,0 +1,19 @@ +from abc import ABC, abstractmethod +from typing import List, Dict, Type + +class BaseEventsPlugin(ABC): + """ + 事件触发型插件基类 + + 所有事件触发型插件都应该继承这个基类而不是 BasePlugin + """ + + @property + @abstractmethod + def plugin_name(self) -> str: + return "" # 插件内部标识符(如 "hello_world_plugin") + + @property + @abstractmethod + def enable_plugin(self) -> bool: + return False \ No newline at end of file diff --git a/src/plugin_system/base/component_types.py b/src/plugin_system/base/component_types.py index 9beac16ab..14025ed99 100644 --- a/src/plugin_system/base/component_types.py +++ b/src/plugin_system/base/component_types.py @@ -40,6 +40,20 @@ class ChatMode(Enum): return self.value +# 事件类型枚举 +class EventType(Enum): + """ + 事件类型枚举类 + """ + + ON_MESSAGE = "on_message" + ON_PLAN = "on_plan" + POST_LLM = "post_llm" + AFTER_LLM = "after_llm" + POST_SEND = "post_send" + AFTER_SEND = "after_send" + + @dataclass class PythonDependency: """Python包依赖信息""" diff --git a/src/plugin_system/core/events_manager.py b/src/plugin_system/core/events_manager.py new file mode 100644 index 000000000..92ef350e2 --- /dev/null +++ b/src/plugin_system/core/events_manager.py @@ -0,0 +1,9 @@ +from typing import List, Dict, Type + +from src.plugin_system.base.component_types import EventType + + +class EventsManager: + def __init__(self): + # 有权重的 events 订阅者注册表 + self.events_subscribers: Dict[EventType, List[Dict[int, Type]]] = {event: [] for event in EventType} diff --git a/src/plugin_system/core/plugin_manager.py b/src/plugin_system/core/plugin_manager.py index 3dbd91675..9dd2865a4 100644 --- a/src/plugin_system/core/plugin_manager.py +++ b/src/plugin_system/core/plugin_manager.py @@ -1,4 +1,4 @@ -from typing import Dict, List, Optional, Callable, Tuple, Type, Any +from typing import Dict, List, Optional, Tuple, Type, Any import os from importlib.util import spec_from_file_location, module_from_spec from inspect import getmodule @@ -6,7 +6,6 @@ from pathlib import Path import traceback from src.common.logger import get_logger -from src.plugin_system.events.events import EventType from src.plugin_system.core.component_registry import component_registry from src.plugin_system.core.dependency_manager import dependency_manager from src.plugin_system.base.base_plugin import BasePlugin @@ -31,8 +30,6 @@ class PluginManager: self.loaded_plugins: Dict[str, BasePlugin] = {} # 已加载的插件类实例注册表,插件名 -> 插件类实例 self.failed_plugins: Dict[str, str] = {} # 记录加载失败的插件类及其错误信息,插件名 -> 错误信息 - self.events_subscriptions: Dict[EventType, List[Callable]] = {} - # 确保插件目录存在 self._ensure_plugin_directories() logger.info("插件管理器初始化完成") diff --git a/src/plugin_system/events/__init__.py b/src/plugin_system/events/__init__.py deleted file mode 100644 index 6b49951df..000000000 --- a/src/plugin_system/events/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -""" -插件的事件系统模块 -""" - -from .events import EventType - -__all__ = [ - "EventType", -] diff --git a/src/plugin_system/events/events.py b/src/plugin_system/events/events.py deleted file mode 100644 index 64d3a7dad..000000000 --- a/src/plugin_system/events/events.py +++ /dev/null @@ -1,14 +0,0 @@ -from enum import Enum - - -class EventType(Enum): - """ - 事件类型枚举类 - """ - - ON_MESSAGE = "on_message" - ON_PLAN = "on_plan" - POST_LLM = "post_llm" - AFTER_LLM = "after_llm" - POST_SEND = "post_send" - AFTER_SEND = "after_send"