diff --git a/pkg/api/http/controller/groups/plugins.py b/pkg/api/http/controller/groups/plugins.py index 28a3c44c..4966553b 100644 --- a/pkg/api/http/controller/groups/plugins.py +++ b/pkg/api/http/controller/groups/plugins.py @@ -128,10 +128,8 @@ class PluginsRouterGroup(group.RouterGroup): file_bytes = file.read() - file_base64 = base64.b64encode(file_bytes).decode('utf-8') - data = { - 'plugin_file': file_base64, + 'plugin_file': file_bytes, } ctx = taskmgr.TaskContext.new() diff --git a/pkg/plugin/connector.py b/pkg/plugin/connector.py index 08a0785a..4d441583 100644 --- a/pkg/plugin/connector.py +++ b/pkg/plugin/connector.py @@ -109,6 +109,14 @@ class PluginRuntimeConnector: install_info: dict[str, Any], task_context: taskmgr.TaskContext | None = None, ): + if install_source == PluginInstallSource.LOCAL: + # transfer file before install + file_bytes = install_info['plugin_file'] + file_key = await self.handler.send_file(file_bytes, 'lbpkg') + install_info['plugin_file_key'] = file_key + del install_info['plugin_file'] + self.ap.logger.info(f'Transfered file {file_key} to plugin runtime') + async for ret in self.handler.install_plugin(install_source.value, install_info): current_action = ret.get('current_action', None) if current_action is not None: diff --git a/pkg/plugin/handler.py b/pkg/plugin/handler.py index ce3bd6d4..5effee4c 100644 --- a/pkg/plugin/handler.py +++ b/pkg/plugin/handler.py @@ -560,7 +560,18 @@ class RuntimeConnectionHandler(handler.Handler): 'plugin_name': plugin_name, }, ) - return result + + plugin_icon_file_key = result['plugin_icon_file_key'] + mime_type = result['mime_type'] + + plugin_icon_bytes = await self.read_local_file(plugin_icon_file_key) + + await self.delete_local_file(plugin_icon_file_key) + + return { + 'plugin_icon_base64': base64.b64encode(plugin_icon_bytes).decode('utf-8'), + 'mime_type': mime_type, + } async def call_tool(self, tool_name: str, parameters: dict[str, Any]) -> dict[str, Any]: """Call tool"""