feat: Enhance plugin runtime configuration and hook management
- Added `inactive_plugins` field to `RunnerReadyPayload` and `ReloadPluginResultPayload` to track plugins that are not activated due to being disabled or unmet dependencies. - Introduced `InspectPluginConfigPayload` and `InspectPluginConfigResultPayload` for inspecting plugin configuration metadata. - Implemented `PluginActivationStatus` enum to better represent plugin activation states. - Updated `_activate_plugin` method to return activation status and handle inactive plugins accordingly. - Added hooks for send service to allow modification of messages before and after sending. - Created new runtime routes for listing hook specifications in the WebUI. - Refactored plugin configuration handling to utilize runtime inspection for better accuracy and flexibility. - Enhanced error handling and logging for plugin configuration operations.
This commit is contained in:
46
src/plugin_runtime/hook_catalog.py
Normal file
46
src/plugin_runtime/hook_catalog.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""内置命名 Hook 目录注册器。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from typing import List
|
||||
|
||||
from src.plugin_runtime.host.hook_spec_registry import HookSpec, HookSpecRegistry
|
||||
|
||||
|
||||
HookSpecRegistrar = Callable[[HookSpecRegistry], List[HookSpec]]
|
||||
"""单个业务模块向注册中心写入 Hook 规格的注册器签名。"""
|
||||
|
||||
|
||||
def _get_builtin_hook_spec_registrars() -> List[HookSpecRegistrar]:
|
||||
"""返回当前内置 Hook 规格注册器列表。
|
||||
|
||||
Returns:
|
||||
List[HookSpecRegistrar]: 已启用的内置 Hook 注册器列表。
|
||||
"""
|
||||
|
||||
from src.chat.message_receive.bot import register_chat_hook_specs
|
||||
from src.maisaka.chat_loop_service import register_maisaka_hook_specs
|
||||
from src.services.send_service import register_send_service_hook_specs
|
||||
|
||||
return [
|
||||
register_chat_hook_specs,
|
||||
register_send_service_hook_specs,
|
||||
register_maisaka_hook_specs,
|
||||
]
|
||||
|
||||
|
||||
def register_builtin_hook_specs(registry: HookSpecRegistry) -> List[HookSpec]:
|
||||
"""向注册中心写入全部内置 Hook 规格。
|
||||
|
||||
Args:
|
||||
registry: 目标 Hook 规格注册中心。
|
||||
|
||||
Returns:
|
||||
List[HookSpec]: 本次完成注册后的全部内置 Hook 规格。
|
||||
"""
|
||||
|
||||
registered_specs: List[HookSpec] = []
|
||||
for registrar in _get_builtin_hook_spec_registrars():
|
||||
registered_specs.extend(registrar(registry))
|
||||
return registered_specs
|
||||
Reference in New Issue
Block a user