perf: use file transfer in getting icon and installing local plugins (#1674)

This commit is contained in:
Junyan Qin
2025-09-19 19:38:27 +08:00
parent 5a6206f148
commit 0ffb4d5792
3 changed files with 21 additions and 4 deletions

View File

@@ -128,10 +128,8 @@ class PluginsRouterGroup(group.RouterGroup):
file_bytes = file.read() file_bytes = file.read()
file_base64 = base64.b64encode(file_bytes).decode('utf-8')
data = { data = {
'plugin_file': file_base64, 'plugin_file': file_bytes,
} }
ctx = taskmgr.TaskContext.new() ctx = taskmgr.TaskContext.new()

View File

@@ -109,6 +109,14 @@ class PluginRuntimeConnector:
install_info: dict[str, Any], install_info: dict[str, Any],
task_context: taskmgr.TaskContext | None = None, 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): async for ret in self.handler.install_plugin(install_source.value, install_info):
current_action = ret.get('current_action', None) current_action = ret.get('current_action', None)
if current_action is not None: if current_action is not None:

View File

@@ -560,7 +560,18 @@ class RuntimeConnectionHandler(handler.Handler):
'plugin_name': plugin_name, '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]: async def call_tool(self, tool_name: str, parameters: dict[str, Any]) -> dict[str, Any]:
"""Call tool""" """Call tool"""