From d5cf4c9b8be5bee904b86316f51a54e17c4de8e0 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Fri, 6 Mar 2026 12:35:31 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=B7=BB=E5=8A=A0=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E6=B3=A8=E8=A7=A3=E4=BB=A5=E5=A2=9E=E5=BC=BA=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=8F=AF=E8=AF=BB=E6=80=A7=E5=92=8C=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=AE=89=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugin_runtime/runner/runner_main.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/plugin_runtime/runner/runner_main.py b/src/plugin_runtime/runner/runner_main.py index e6017121..4972129f 100644 --- a/src/plugin_runtime/runner/runner_main.py +++ b/src/plugin_runtime/runner/runner_main.py @@ -11,6 +11,7 @@ import asyncio import contextlib +import inspect import logging import os import signal @@ -43,15 +44,15 @@ class PluginRunner: host_address: str, session_token: str, plugin_dirs: list[str], - ): - self._host_address = host_address - self._session_token = session_token - self._plugin_dirs = plugin_dirs + ) -> None: + self._host_address: str = host_address + self._session_token: str = session_token + self._plugin_dirs: list[str] = plugin_dirs - self._rpc_client = RPCClient(host_address, session_token) - self._loader = PluginLoader() - self._start_time = time.monotonic() - self._shutting_down = False + self._rpc_client: RPCClient = RPCClient(host_address, session_token) + self._loader: PluginLoader = PluginLoader() + self._start_time: float = time.monotonic() + self._shutting_down: bool = False async def run(self) -> None: """Runner 主入口""" @@ -113,7 +114,7 @@ class PluginRunner: async def _register_plugin(self, meta: PluginMeta) -> None: """向 Host 注册单个插件""" # 收集插件组件声明 - components = [] + components: list[ComponentDeclaration] = [] instance = meta.instance # 从插件实例获取组件声明(SDK 插件须实现 get_components 方法) @@ -176,7 +177,7 @@ class PluginRunner: ) try: - result = await handler_method(**invoke.args) if asyncio.iscoroutinefunction(handler_method) else handler_method(**invoke.args) + result = await handler_method(**invoke.args) if inspect.iscoroutinefunction(handler_method) else handler_method(**invoke.args) resp_payload = InvokeResultPayload(success=True, result=result) return envelope.make_response(payload=resp_payload.model_dump()) except Exception as e: @@ -214,7 +215,7 @@ class PluginRunner: ) try: - raw = await handler_method(**invoke.args) if asyncio.iscoroutinefunction(handler_method) else handler_method(**invoke.args) + raw = await handler_method(**invoke.args) if inspect.iscoroutinefunction(handler_method) else handler_method(**invoke.args) # 规范化返回值 if isinstance(raw, str):