From 18194cc06bb9b4fd5f7266aef9b90c9000fa3d91 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Mon, 17 Nov 2025 14:31:34 +0800 Subject: [PATCH] feat: add Data Source tool functionality and localization --- .../migrations/0004_alter_tool_tool_type.py | 18 + apps/tools/models/tool.py | 1 + ui/src/locales/lang/en-US/views/tool.ts | 3 + ui/src/locales/lang/zh-CN/views/tool.ts | 3 + ui/src/locales/lang/zh-Hant/views/tool.ts | 3 + .../ToolResourceIndex.vue | 38 ++ .../views/system-shared/ToolSharedIndex.vue | 1 + .../views/tool/DataSourceToolFormDrawer.vue | 456 ++++++++++++++++++ .../tool/component/ToolListContainer.vue | 41 ++ ui/src/views/tool/index.vue | 1 + 10 files changed, 565 insertions(+) create mode 100644 apps/tools/migrations/0004_alter_tool_tool_type.py create mode 100644 ui/src/views/tool/DataSourceToolFormDrawer.vue diff --git a/apps/tools/migrations/0004_alter_tool_tool_type.py b/apps/tools/migrations/0004_alter_tool_tool_type.py new file mode 100644 index 000000000..e561675b0 --- /dev/null +++ b/apps/tools/migrations/0004_alter_tool_tool_type.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2.8 on 2025-11-17 07:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tools', '0003_alter_tool_template_id'), + ] + + operations = [ + migrations.AlterField( + model_name='tool', + name='tool_type', + field=models.CharField(choices=[('INTERNAL', '内置'), ('CUSTOM', '自定义'), ('MCP', 'MCP工具'), ('DATA_SOURCE', '数据源')], db_index=True, default='CUSTOM', max_length=20, verbose_name='工具类型'), + ), + ] diff --git a/apps/tools/models/tool.py b/apps/tools/models/tool.py index e58eb14ef..712f2029e 100644 --- a/apps/tools/models/tool.py +++ b/apps/tools/models/tool.py @@ -32,6 +32,7 @@ class ToolType(models.TextChoices): INTERNAL = "INTERNAL", '内置' CUSTOM = "CUSTOM", "自定义" MCP = "MCP", "MCP工具" + DATA_SOURCE = "DATA_SOURCE", "数据源" class Tool(AppModelMixin): diff --git a/ui/src/locales/lang/en-US/views/tool.ts b/ui/src/locales/lang/en-US/views/tool.ts index ac948bd94..074d494d5 100644 --- a/ui/src/locales/lang/en-US/views/tool.ts +++ b/ui/src/locales/lang/en-US/views/tool.ts @@ -4,6 +4,9 @@ export default { createTool: 'Create Tool', editTool: 'Edit Tool', createMcpTool: 'Create MCP', + createDataSourceTool: 'Create Data Source', + dataSource: 'Data Source', + editDataSourceTool: 'Edit Data Source', editMcpTool: 'Edit MCP', copyTool: 'Copy Tool', importTool: 'Import Tool', diff --git a/ui/src/locales/lang/zh-CN/views/tool.ts b/ui/src/locales/lang/zh-CN/views/tool.ts index ed8763fe0..d597c93a8 100644 --- a/ui/src/locales/lang/zh-CN/views/tool.ts +++ b/ui/src/locales/lang/zh-CN/views/tool.ts @@ -4,6 +4,9 @@ export default { createTool: '创建工具', editTool: '编辑工具', createMcpTool: '创建MCP', + createDataSourceTool: '创建数据源', + dataSource: '数据源', + editDataSourceTool: '编辑数据源', editMcpTool: '编辑MCP', copyTool: '复制工具', importTool: '导入工具', diff --git a/ui/src/locales/lang/zh-Hant/views/tool.ts b/ui/src/locales/lang/zh-Hant/views/tool.ts index 09eaca8d7..923e04317 100644 --- a/ui/src/locales/lang/zh-Hant/views/tool.ts +++ b/ui/src/locales/lang/zh-Hant/views/tool.ts @@ -4,6 +4,9 @@ export default { createTool: '建立工具', editTool: '編輯工具', createMcpTool: '建立MCP', + createDataSourceTool: '建立資料來源', + dataSource: '資料來源', + editDataSourceTool: '編輯資料來源', editMcpTool: '編輯MCP', copyTool: '複製工具', importTool: '匯入工具', diff --git a/ui/src/views/system-resource-management/ToolResourceIndex.vue b/ui/src/views/system-resource-management/ToolResourceIndex.vue index 2983d41d2..a30944564 100644 --- a/ui/src/views/system-resource-management/ToolResourceIndex.vue +++ b/ui/src/views/system-resource-management/ToolResourceIndex.vue @@ -82,6 +82,7 @@ diff --git a/ui/src/views/tool/DataSourceToolFormDrawer.vue b/ui/src/views/tool/DataSourceToolFormDrawer.vue new file mode 100644 index 000000000..6a8b64671 --- /dev/null +++ b/ui/src/views/tool/DataSourceToolFormDrawer.vue @@ -0,0 +1,456 @@ + + + + diff --git a/ui/src/views/tool/component/ToolListContainer.vue b/ui/src/views/tool/component/ToolListContainer.vue index 09b14b0e9..39ce26e88 100644 --- a/ui/src/views/tool/component/ToolListContainer.vue +++ b/ui/src/views/tool/component/ToolListContainer.vue @@ -48,6 +48,16 @@ + +
+ + + +
+
{{ $t('views.tool.createDataSourceTool') }}
+
+
+
@@ -249,6 +259,7 @@ + @@ -268,6 +279,7 @@ import { useRoute, onBeforeRouteLeave } from 'vue-router' import InitParamDrawer from '@/views/tool/component/InitParamDrawer.vue' import ToolFormDrawer from '@/views/tool/ToolFormDrawer.vue' import McpToolFormDrawer from '@/views/tool/McpToolFormDrawer.vue' +import DataSourceToolFormDrawer from '@/views/tool/DataSourceToolFormDrawer.vue' import CreateFolderDialog from '@/components/folder-tree/CreateFolderDialog.vue' import AuthorizedWorkspace from '@/views/system-shared/AuthorizedWorkspaceDialog.vue' import ToolStoreDialog from '@/views/tool/toolStore/ToolStoreDialog.vue' @@ -350,8 +362,10 @@ const search_type_change = () => { } const ToolFormDrawerRef = ref() const McpToolFormDrawerRef = ref() +const DataSourceToolFormDrawerRef = ref() const ToolDrawertitle = ref('') const McpToolDrawertitle = ref('') +const DataSourceToolDrawertitle = ref('') const MoveToDialogRef = ref() function openMoveToDialog(data: any) { @@ -384,6 +398,12 @@ function openCreateDialog(data?: any) { openCreateMcpDialog(data) return } + // 数据源工具 + if (data?.tool_type === 'DATA_SOURCE') { + bus.emit('select_node', data.folder_id) + openCreateDataSourceDialog(data) + return + } // 有版本号的展示readme,是商店更新过来的 if (data?.version) { let readMe = '' @@ -440,6 +460,27 @@ function openCreateMcpDialog(data?: any) { } } +function openCreateDataSourceDialog(data?: any) { + // 有template_id的不允许编辑,是模板转换来的 + if (data?.template_id) { + return + } + // 共享过来的工具不让编辑 + if (isShared.value) { + return + } + DataSourceToolDrawertitle.value = data ? t('views.tool.editDataSourceTool') : t('views.tool.createDataSourceTool') + if (data) { + loadSharedApi({ type: 'tool', systemType: apiType.value }) + .getToolById(data?.id, loading) + .then((res: any) => { + DataSourceToolFormDrawerRef.value.open(res.data) + }) + } else { + DataSourceToolFormDrawerRef.value.open(data) + } +} + async function changeState(row: any) { if (row.is_active) { MsgConfirm( diff --git a/ui/src/views/tool/index.vue b/ui/src/views/tool/index.vue index 7264b19bf..ce0321b77 100644 --- a/ui/src/views/tool/index.vue +++ b/ui/src/views/tool/index.vue @@ -26,6 +26,7 @@ {{ $t('views.tool.all') }} {{ $t('views.tool.title') }} MCP + {{ $t('views.tool.dataSource') }}