mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
perf: use file transfer in getting icon and installing local plugins (#1674)
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -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"""
|
||||||
|
|||||||
Reference in New Issue
Block a user