From e0abd196362dd6700ea7cc154eb32ab1994af346 Mon Sep 17 00:00:00 2001 From: Junyan Qin Date: Sun, 13 Jul 2025 22:14:22 +0800 Subject: [PATCH] feat: get plugin info --- pkg/api/http/controller/groups/plugins.py | 8 ++++---- pkg/plugin/connector.py | 3 +++ pkg/plugin/handler.py | 12 ++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/pkg/api/http/controller/groups/plugins.py b/pkg/api/http/controller/groups/plugins.py index 86ad25e8..8f59986d 100644 --- a/pkg/api/http/controller/groups/plugins.py +++ b/pkg/api/http/controller/groups/plugins.py @@ -50,10 +50,10 @@ class PluginsRouterGroup(group.RouterGroup): ) async def _(author: str, plugin_name: str) -> str: if quart.request.method == 'GET': - plugin = self.ap.plugin_mgr.get_plugin(author, plugin_name) + plugin = await self.ap.plugin_connector.get_plugin_info(author, plugin_name) if plugin is None: return self.http_status(404, -1, 'plugin not found') - return self.success(data={'plugin': plugin.model_dump()}) + return self.success(data={'plugin': plugin}) elif quart.request.method == 'DELETE': ctx = taskmgr.TaskContext.new() wrapper = self.ap.task_mgr.create_user_task( @@ -72,11 +72,11 @@ class PluginsRouterGroup(group.RouterGroup): auth_type=group.AuthType.USER_TOKEN, ) async def _(author: str, plugin_name: str) -> quart.Response: - plugin = self.ap.plugin_mgr.get_plugin(author, plugin_name) + plugin = await self.ap.plugin_connector.get_plugin_info(author, plugin_name) if plugin is None: return self.http_status(404, -1, 'plugin not found') if quart.request.method == 'GET': - return self.success(data={'config': plugin.plugin_config}) + return self.success(data={'config': plugin['plugin_config']}) elif quart.request.method == 'PUT': data = await quart.request.json diff --git a/pkg/plugin/connector.py b/pkg/plugin/connector.py index b46302d5..370b7618 100644 --- a/pkg/plugin/connector.py +++ b/pkg/plugin/connector.py @@ -98,6 +98,9 @@ class PluginRuntimeConnector: async def list_plugins(self) -> list[dict[str, Any]]: return await self.handler.list_plugins() + async def get_plugin_info(self, author: str, plugin_name: str) -> dict[str, Any]: + return await self.handler.get_plugin_info(author, plugin_name) + async def emit_event( self, event: events.BaseEventModel, diff --git a/pkg/plugin/handler.py b/pkg/plugin/handler.py index d0905f1f..22cfe5c9 100644 --- a/pkg/plugin/handler.py +++ b/pkg/plugin/handler.py @@ -372,6 +372,18 @@ class RuntimeConnectionHandler(handler.Handler): return result['plugins'] + async def get_plugin_info(self, author: str, plugin_name: str) -> dict[str, Any]: + """Get plugin""" + result = await self.call_action( + LangBotToRuntimeAction.GET_PLUGIN_INFO, + { + 'author': author, + 'plugin_name': plugin_name, + }, + timeout=10, + ) + return result['plugin'] + async def emit_event( self, event_context: dict[str, Any],