补全新版插件系统的类型注解

This commit is contained in:
DrSmoothl
2026-03-06 12:17:00 +08:00
parent 1cd366bc09
commit c6afa97060
3 changed files with 14 additions and 14 deletions

View File

@@ -7,7 +7,7 @@
4. 事件结果历史记录
"""
from typing import Any, Optional
from typing import Any, Awaitable, Callable
import asyncio
import logging
@@ -16,6 +16,9 @@ from src.plugin_runtime.host.component_registry import ComponentRegistry, Regist
logger = logging.getLogger("plugin_runtime.host.event_dispatcher")
# invoke_fn 类型: async (plugin_id, component_name, args) -> response_payload dict
InvokeFn = Callable[[str, str, dict[str, Any]], Awaitable[dict[str, Any]]]
class EventResult:
"""单个 EventHandler 的执行结果"""
@@ -44,8 +47,8 @@ class EventDispatcher:
再通过提供的 invoke_fn 回调 RPC 到 Runner 执行。
"""
def __init__(self, registry: ComponentRegistry):
self._registry = registry
def __init__(self, registry: ComponentRegistry) -> None:
self._registry: ComponentRegistry = registry
self._result_history: dict[str, list[EventResult]] = {}
self._history_enabled: set[str] = set()
@@ -63,10 +66,10 @@ class EventDispatcher:
async def dispatch_event(
self,
event_type: str,
invoke_fn, # async (plugin_id, component_name, args) -> dict — Supervisor.invoke_plugin wrapper
invoke_fn: InvokeFn,
message: dict[str, Any] | None = None,
extra_args: dict[str, Any] | None = None,
) -> tuple[bool, Optional[dict[str, Any]]]:
) -> tuple[bool, dict[str, Any] | None]:
"""分发事件到所有对应 handler。
Args:
@@ -117,7 +120,7 @@ class EventDispatcher:
async def _invoke_handler(
self,
invoke_fn,
invoke_fn: InvokeFn,
handler: RegisteredComponent,
args: dict[str, Any],
event_type: str,

View File

@@ -63,10 +63,10 @@ class RPCServer:
self._pending_requests: dict[int, asyncio.Future] = {}
# 发送队列(背压控制)
self._send_queue: asyncio.Queue | None = None
self._send_queue: asyncio.Queue[bytes] | None = None
# 运行状态
self._running = False
self._running: bool = False
self._tasks: list[asyncio.Task] = []
@property