Update project and configurations
This commit is contained in:
27
intelligent_cabin/app/plugins/base.py
Normal file
27
intelligent_cabin/app/plugins/base.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
PluginHandler = Callable[[dict[str, Any]], dict[str, Any]]
|
||||
|
||||
|
||||
class PluginRegistry:
|
||||
def __init__(self) -> None:
|
||||
self._handlers: dict[str, PluginHandler] = {}
|
||||
|
||||
def register(self, plugin_id: str, handler: PluginHandler) -> None:
|
||||
self._handlers[plugin_id] = handler
|
||||
|
||||
def execute(self, plugin_id: str, slots: dict[str, Any]) -> dict[str, Any]:
|
||||
handler = self._handlers.get(plugin_id)
|
||||
if handler is None:
|
||||
return {
|
||||
"success": False,
|
||||
"message": f"插件 {plugin_id} 未注册。",
|
||||
"data": {"plugin_id": plugin_id, "slots": slots},
|
||||
}
|
||||
return handler(slots)
|
||||
|
||||
def registered_plugins(self) -> list[str]:
|
||||
return sorted(self._handlers.keys())
|
||||
Reference in New Issue
Block a user