mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 12:05:54 +00:00
feat: 插件安装支持
This commit is contained in:
@@ -49,3 +49,21 @@ class PluginsRouterGroup(group.RouterGroup):
|
||||
data = await quart.request.json
|
||||
await self.ap.plugin_mgr.reorder_plugins(data.get('plugins'))
|
||||
return self.success()
|
||||
|
||||
@self.route('/install/github', methods=['POST'])
|
||||
async def _() -> str:
|
||||
data = await quart.request.json
|
||||
|
||||
ctx = taskmgr.TaskContext.new()
|
||||
short_source_str = data['source'][-8:]
|
||||
wrapper = self.ap.task_mgr.create_user_task(
|
||||
self.ap.plugin_mgr.install_plugin(data['source'], task_context=ctx),
|
||||
kind="plugin-operation",
|
||||
name=f'plugin-install-github',
|
||||
label=f'安装插件 ...{short_source_str}',
|
||||
context=ctx
|
||||
)
|
||||
|
||||
return self.success(data={
|
||||
'task_id': wrapper.id
|
||||
})
|
||||
|
||||
@@ -21,6 +21,7 @@ class PluginInstaller(metaclass=abc.ABCMeta):
|
||||
async def install_plugin(
|
||||
self,
|
||||
plugin_source: str,
|
||||
task_context: taskmgr.TaskContext = taskmgr.TaskContext.placeholder(),
|
||||
):
|
||||
"""安装插件
|
||||
"""
|
||||
|
||||
@@ -65,10 +65,11 @@ class PluginManager:
|
||||
async def install_plugin(
|
||||
self,
|
||||
plugin_source: str,
|
||||
task_context: taskmgr.TaskContext = taskmgr.TaskContext.placeholder(),
|
||||
):
|
||||
"""安装插件
|
||||
"""
|
||||
await self.installer.install_plugin(plugin_source)
|
||||
await self.installer.install_plugin(plugin_source, task_context)
|
||||
|
||||
await self.ap.ctr_mgr.plugin.post_install_record(
|
||||
{
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
<template v-slot:default="{ isActive }">
|
||||
<v-card prepend-icon="mdi-priority-high" text="优先级影响插件的加载、事件触发顺序" title="设置插件优先级">
|
||||
<v-list id="plugin-orchestration-list">
|
||||
<draggable v-model="plugins" item-key="name" group="plugins" @start="drag = true"
|
||||
id="plugin-orchestration-draggable"
|
||||
<draggable v-model="plugins" item-key="name" group="plugins"
|
||||
@start="drag = true" id="plugin-orchestration-draggable"
|
||||
@end="drag = false">
|
||||
<template #item="{ element }">
|
||||
<div class="plugin-orchestration-item">
|
||||
@@ -36,8 +36,10 @@
|
||||
</v-list>
|
||||
|
||||
<template v-slot:actions>
|
||||
<v-btn class="ml-auto" text="关闭" prepend-icon="mdi-close" @click="cancelOrderChanges"></v-btn>
|
||||
<v-btn color="primary" prepend-icon="mdi-content-save-outline" @click="saveOrder">应用</v-btn>
|
||||
<v-btn class="ml-auto" text="关闭" prepend-icon="mdi-close"
|
||||
@click="cancelOrderChanges"></v-btn>
|
||||
<v-btn color="primary" prepend-icon="mdi-content-save-outline"
|
||||
@click="saveOrder">应用</v-btn>
|
||||
</template>
|
||||
</v-card>
|
||||
</template>
|
||||
@@ -45,8 +47,34 @@
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
|
||||
<v-btn color="primary" prepend-icon="mdi-plus">
|
||||
安装
|
||||
|
||||
<v-dialog activator="parent" max-width="500" persistent v-model="isInstallDialogActive">
|
||||
<template v-slot:default="{ isActive }">
|
||||
|
||||
<v-card title="从 GitHub 安装插件" prepend-icon="mdi-github">
|
||||
|
||||
<div id="plugin-install-dialog-content">
|
||||
<div>
|
||||
目前仅支持从 GitHub 安装,插件列表:<a
|
||||
href="https://github.com/stars/RockChinQ/lists/qchatgpt-%E6%8F%92%E4%BB%B6"
|
||||
target="_blank">LangBot 插件</a>
|
||||
</div>
|
||||
<v-text-field v-model="installDialogSource" label="插件源码地址" />
|
||||
</div>
|
||||
|
||||
<template v-slot:actions>
|
||||
<v-btn class="ml-auto" text="取消" prepend-icon="mdi-close"
|
||||
@click="isInstallDialogActive = false"></v-btn>
|
||||
<v-btn color="primary" prepend-icon="mdi-content-save-outline"
|
||||
@click="installPlugin">安装</v-btn>
|
||||
</template>
|
||||
|
||||
</v-card>
|
||||
</template>
|
||||
</v-dialog>
|
||||
</v-btn>
|
||||
</div>
|
||||
</v-card>
|
||||
@@ -113,6 +141,28 @@ const updatePlugin = (plugin) => {
|
||||
})
|
||||
}
|
||||
|
||||
const installPlugin = () => {
|
||||
|
||||
if (installDialogSource.value == '' || installDialogSource.value.trim() == '') {
|
||||
snackbar.error("请输入插件仓库地址")
|
||||
return
|
||||
}
|
||||
|
||||
proxy.$axios.post(`/plugins/install/github`, {
|
||||
source: installDialogSource.value
|
||||
}).then(res => {
|
||||
if (res.data.code != 0) {
|
||||
snackbar.error(res.data.msg)
|
||||
return
|
||||
}
|
||||
installDialogSource.value = ''
|
||||
snackbar.success(`已添加插件安装任务 请到任务列表查看进度`)
|
||||
isInstallDialogActive.value = false
|
||||
}).catch(error => {
|
||||
snackbar.error(error)
|
||||
})
|
||||
}
|
||||
|
||||
const isOrchestrationDialogActive = ref(false)
|
||||
|
||||
const cancelOrderChanges = () => {
|
||||
@@ -136,6 +186,10 @@ const saveOrder = () => {
|
||||
snackbar.error(error)
|
||||
})
|
||||
}
|
||||
|
||||
const isInstallDialogActive = ref(false)
|
||||
const installDialogSource = ref('')
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -224,4 +278,12 @@ const saveOrder = () => {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#plugin-install-dialog-content {
|
||||
width: calc(100% - 3rem);
|
||||
margin-inline: 1.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user