From be759701ccd7a9923d7a26b1ee0bd00769ef3018 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Fri, 4 Jul 2025 11:21:05 +0800 Subject: [PATCH] feat: add application management API and update ApplicationResourceIndex.vue --- .../system-resource-management/application.ts | 319 ++++++++++++++++++ .../locales/lang/en-US/views/application.ts | 1 + .../locales/lang/zh-CN/views/application.ts | 1 + .../locales/lang/zh-Hant/views/application.ts | 1 + ui/src/router/modules/system.ts | 64 ++-- ui/src/utils/permission/data.ts | 7 +- .../ApplicationResourceIndex.vue | 169 ++++++++-- 7 files changed, 504 insertions(+), 58 deletions(-) create mode 100644 ui/src/api/system-resource-management/application.ts diff --git a/ui/src/api/system-resource-management/application.ts b/ui/src/api/system-resource-management/application.ts new file mode 100644 index 000000000..6f62d4d14 --- /dev/null +++ b/ui/src/api/system-resource-management/application.ts @@ -0,0 +1,319 @@ +import {Result} from '@/request/Result' +import {get, post, postStream, del, put, request, download, exportFile} from '@/request/index' +import type {pageRequest} from '@/api/type/common' +import type {ApplicationFormType} from '@/api/type/application' +import {type Ref} from 'vue' +import useStore from '@/stores' + +const prefix = '/system/resource/application' + +/** + * 获取全部应用 + * @param 参数 + */ +const getAllApplication: (param?: any, loading?: Ref) => Promise> = ( + param, + loading, +) => { + return get(`${prefix}`, param, loading) +} + +/** + * 获取分页应用 + * param { + "name": "string", + } + */ +const getApplication: ( + page: pageRequest, + param: any, + loading?: Ref, +) => Promise> = (page, param, loading) => { + return get(`${prefix}/${page.current_page}/${page.page_size}`, param, loading) +} + +/** + * 创建应用 + * @param 参数 + */ +const postApplication: ( + data: ApplicationFormType, + loading?: Ref, +) => Promise> = (data, loading) => { + return post(`${prefix}`, data, undefined, loading) +} + +/** + * 修改应用 + * @param 参数 + */ +const putApplication: ( + application_id: string, + data: ApplicationFormType, + loading?: Ref, +) => Promise> = (application_id, data, loading) => { + return put(`${prefix}/${application_id}`, data, undefined, loading) +} + +/** + * 删除应用 + * @param 参数 application_id + */ +const delApplication: ( + application_id: string, + loading?: Ref, +) => Promise> = (application_id, loading) => { + return del(`${prefix}/${application_id}`, undefined, {}, loading) +} + +/** + * 应用详情 + * @param 参数 application_id + */ +const getApplicationDetail: ( + application_id: string, + loading?: Ref, +) => Promise> = (application_id, loading) => { + return get(`${prefix}/${application_id}`, undefined, loading) +} + +/** + * 获取AccessToken + * @param 参数 application_id + */ +const getAccessToken: (application_id: string, loading?: Ref) => Promise> = ( + application_id, + loading, +) => { + return get(`${prefix}/${application_id}/access_token`, undefined, loading) +} +/** + * 获取应用设置 + * @param application_id 应用id + * @param loading 加载器 + * @returns + */ +const getApplicationSetting: ( + application_id: string, + loading?: Ref, +) => Promise> = (application_id, loading) => { + return get(`${prefix}/${application_id}/setting`, undefined, loading) +} + +/** + * 修改AccessToken + * @param 参数 application_id + * data { + * "is_active": true + * } + */ +const putAccessToken: ( + application_id: string, + data: any, + loading?: Ref, +) => Promise> = (application_id, data, loading) => { + return put(`${prefix}/${application_id}/access_token`, data, undefined, loading) +} + +/** + * 导出应用 + */ + +const exportApplication = ( + application_id: string, + application_name: string, + loading?: Ref, +) => { + return exportFile( + application_name + '.mk', + `${prefix}/${application_id}/export`, + undefined, + loading, + ) +} + +/** + * 导入应用 + */ +const importApplication: (data: any, loading?: Ref) => Promise> = ( + data, + loading, +) => { + return post(`${prefix}/import`, data, undefined, loading) +} + +/** + * 统计 + * @param 参数 application_id, data + */ +const getStatistics: ( + application_id: string, + data: any, + loading?: Ref, +) => Promise> = (application_id, data, loading) => { + return get(`${prefix}/${application_id}/application_stats`, data, loading) +} +/** + * 打开调试对话id + * @param application_id 应用id + * @param loading 加载器 + * @returns + */ +const open: (application_id: string, loading?: Ref) => Promise> = ( + application_id, + loading, +) => { + return get(`${prefix}/${application_id}/open`, {}, loading) +} +/** + * 对话 + * @param 参数 + * chat_id: string + * data + */ +const chat: (chat_id: string, data: any) => Promise = (chat_id, data) => { + const prefix = (window.MaxKB?.prefix ? window.MaxKB?.prefix : '/admin') + '/api' + return postStream(`${prefix}/chat_message/${chat_id}`, data) +} +/** + * 获取对话用户认证类型 + * @param loading 加载器 + * @returns + */ +const getChatUserAuthType: (loading?: Ref) => Promise = (loading) => { + return get(`/chat_user/auth/types`, {}, loading) +} + +/** + * 获取平台状态 + */ +const getPlatformStatus: (application_id: string) => Promise> = (application_id) => { + return get(`${prefix}/${application_id}/platform/status`) +} +/** + * 更新平台状态 + */ +const updatePlatformStatus: (application_id: string, data: any) => Promise> = ( + application_id, + data, +) => { + return post(`${prefix}/${application_id}/platform/status`, data) +} +/** + * 获取平台配置 + */ +const getPlatformConfig: (application_id: string, type: string) => Promise> = ( + application_id, + type, +) => { + return get(`${prefix}/${application_id}/platform/${type}`) +} +/** + * 更新平台配置 + */ +const updatePlatformConfig: ( + application_id: string, + type: string, + data: any, + loading?: Ref, +) => Promise> = (application_id, type, data, loading) => { + return post(`${prefix}/${application_id}/platform/${type}`, data, undefined, loading) +} +/** + * 应用发布 + * @param application_id + * @param loading + * @returns + */ +const publish: ( + application_id: string, + data: any, + loading?: Ref, +) => Promise> = (application_id, data, loading) => { + return put(`${prefix}/${application_id}/publish`, data, {}, loading) +} + +/** + * + * @param application_id + * @param data + * @param loading + * @returns + */ +const playDemoText: (application_id: string, data: any, loading?: Ref) => Promise = ( + application_id, + data, + loading, +) => { + return download( + `${prefix}/${application_id}/play_demo_text`, + 'post', + data, + undefined, + loading, + ) +} + +/** + * 文本转语音 + */ +const postTextToSpeech: ( + application_id: String, + data: any, + loading?: Ref, +) => Promise> = (application_id, data, loading) => { + return download( + `${prefix}/${application_id}/text_to_speech`, + 'post', + data, + undefined, + loading, + ) +} +/** + * 语音转文本 + */ +const speechToText: ( + application_id: String, + data: any, + loading?: Ref, +) => Promise> = (application_id, data, loading) => { + return post(`${prefix}/${application_id}/speech_to_text`, data, undefined, loading) +} + +/** + * mcp 节点 + */ +const getMcpTools: (application_id: String, loading?: Ref) => Promise> = ( + application_id, + loading, +) => { + return get(`${prefix}/${application_id}/mcp_tools`, undefined, loading) +} + +export default { + getAllApplication, + getApplication, + postApplication, + putApplication, + delApplication, + getApplicationDetail, + getAccessToken, + putAccessToken, + exportApplication, + importApplication, + getStatistics, + open, + chat, + getChatUserAuthType, + getApplicationSetting, + getPlatformStatus, + updatePlatformStatus, + getPlatformConfig, + publish, + updatePlatformConfig, + playDemoText, + postTextToSpeech, + speechToText, + getMcpTools, +} diff --git a/ui/src/locales/lang/en-US/views/application.ts b/ui/src/locales/lang/en-US/views/application.ts index 4e07dc0b5..e4faa34cd 100644 --- a/ui/src/locales/lang/en-US/views/application.ts +++ b/ui/src/locales/lang/en-US/views/application.ts @@ -225,4 +225,5 @@ export default { emptyMessage1: 'Retrieval Testing results will show here', emptyMessage2: 'No matching sections found', }, + publishTime: 'Publish Time', } diff --git a/ui/src/locales/lang/zh-CN/views/application.ts b/ui/src/locales/lang/zh-CN/views/application.ts index a9d309a67..b55771bdb 100644 --- a/ui/src/locales/lang/zh-CN/views/application.ts +++ b/ui/src/locales/lang/zh-CN/views/application.ts @@ -211,4 +211,5 @@ export default { emptyMessage1: '命中段落显示在这里', emptyMessage2: '没有命中的分段', }, + publishTime: '发布时间', } diff --git a/ui/src/locales/lang/zh-Hant/views/application.ts b/ui/src/locales/lang/zh-Hant/views/application.ts index 373d0ec99..3ef4ad8f1 100644 --- a/ui/src/locales/lang/zh-Hant/views/application.ts +++ b/ui/src/locales/lang/zh-Hant/views/application.ts @@ -211,4 +211,5 @@ export default { emptyMessage1: '命中的段落顯示在這裡', emptyMessage2: '沒有命中的分段', }, + publishTime: '發佈時間', } diff --git a/ui/src/router/modules/system.ts b/ui/src/router/modules/system.ts index 4c4e44bb4..b6cbe0edf 100644 --- a/ui/src/router/modules/system.ts +++ b/ui/src/router/modules/system.ts @@ -1,10 +1,10 @@ -import { PermissionConst, EditionConst, RoleConst } from '@/utils/permission/data' -import { ComplexPermission } from '@/utils/permission/type' +import {PermissionConst, EditionConst, RoleConst} from '@/utils/permission/data' +import {ComplexPermission} from '@/utils/permission/type' const systemRouter = { path: '/system', name: 'system', - meta: { title: 'views.system.title' }, + meta: {title: 'views.system.title'}, hidden: true, component: () => import('@/layout/layout-template/SystemMainLayout.vue'), children: [ @@ -78,6 +78,12 @@ const systemRouter = { parentPath: '/system', parentName: 'system', permission: [ + new ComplexPermission( + [RoleConst.ADMIN], + [PermissionConst.RESOURCE_APPLICATION_READ], + [EditionConst.IS_EE], + 'OR', + ), new ComplexPermission( [RoleConst.ADMIN], [PermissionConst.RESOURCE_KNOWLEDGE_READ], @@ -99,6 +105,26 @@ const systemRouter = { ], }, children: [ + { + path: '/system/resource-management/application', + name: 'ApplicationResourceIndex', + meta: { + title: 'views.application.title', + activeMenu: '/system', + parentPath: '/system', + parentName: 'system', + sameRoute: 'workspace', + permission: [ + new ComplexPermission( + [RoleConst.ADMIN], + [PermissionConst.RESOURCE_APPLICATION_READ], + [EditionConst.IS_EE], + 'OR', + ), + ], + }, + component: () => import('@/views/system-resource-management/ApplicationResourceIndex.vue'), + }, { path: '/system/resource-management/knowledge', name: 'KnowledgeResourceIndex', @@ -172,18 +198,18 @@ const systemRouter = { parentName: 'system', sameRoute: 'authorization', permission: [new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE], - [PermissionConst.APPLICATION_WORKSPACE_USER_RESOURCE_PERMISSION_READ, - PermissionConst.APPLICATION_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole],[],'OR'), - new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE], - [PermissionConst.KNOWLEDGE_WORKSPACE_USER_RESOURCE_PERMISSION_READ, - PermissionConst.KNOWLEDGE_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole],[],'OR'), - new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE], - [PermissionConst.TOOL_WORKSPACE_USER_RESOURCE_PERMISSION_READ, - PermissionConst.TOOL_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole],[],'OR'), - new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE], - [PermissionConst.MODEL_WORKSPACE_USER_RESOURCE_PERMISSION_READ, - PermissionConst.MODEL_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole],[],'OR'), - ], + [PermissionConst.APPLICATION_WORKSPACE_USER_RESOURCE_PERMISSION_READ, + PermissionConst.APPLICATION_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole], [], 'OR'), + new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE], + [PermissionConst.KNOWLEDGE_WORKSPACE_USER_RESOURCE_PERMISSION_READ, + PermissionConst.KNOWLEDGE_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole], [], 'OR'), + new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE], + [PermissionConst.TOOL_WORKSPACE_USER_RESOURCE_PERMISSION_READ, + PermissionConst.TOOL_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole], [], 'OR'), + new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE], + [PermissionConst.MODEL_WORKSPACE_USER_RESOURCE_PERMISSION_READ, + PermissionConst.MODEL_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole], [], 'OR'), + ], }, children: [ @@ -199,7 +225,7 @@ const systemRouter = { sameRoute: 'authorization', permission: [new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE], [PermissionConst.APPLICATION_WORKSPACE_USER_RESOURCE_PERMISSION_READ, - PermissionConst.APPLICATION_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole],[],'OR'),] + PermissionConst.APPLICATION_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole], [], 'OR'),] }, component: () => import('@/views/system/resource-authorization/index.vue'), }, @@ -215,7 +241,7 @@ const systemRouter = { sameRoute: 'authorization', permission: [new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE], [PermissionConst.KNOWLEDGE_WORKSPACE_USER_RESOURCE_PERMISSION_READ, - PermissionConst.KNOWLEDGE_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole],[],'OR'),] + PermissionConst.KNOWLEDGE_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole], [], 'OR'),] }, component: () => import('@/views/system/resource-authorization/index.vue'), }, @@ -231,7 +257,7 @@ const systemRouter = { sameRoute: 'authorization', permission: [new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE], [PermissionConst.TOOL_WORKSPACE_USER_RESOURCE_PERMISSION_READ, - PermissionConst.TOOL_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole],[],'OR'),] + PermissionConst.TOOL_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole], [], 'OR'),] }, component: () => import('@/views/system/resource-authorization/index.vue'), }, @@ -247,7 +273,7 @@ const systemRouter = { sameRoute: 'authorization', permission: [new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE], [PermissionConst.MODEL_WORKSPACE_USER_RESOURCE_PERMISSION_READ, - PermissionConst.MODEL_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole],[],'OR'),] + PermissionConst.MODEL_WORKSPACE_USER_RESOURCE_PERMISSION_READ.getWorkspacePermissionWorkspaceManageRole], [], 'OR'),] }, component: () => import('@/views/system/resource-authorization/index.vue'), }, diff --git a/ui/src/utils/permission/data.ts b/ui/src/utils/permission/data.ts index 68cf3f5de..efd4de234 100644 --- a/ui/src/utils/permission/data.ts +++ b/ui/src/utils/permission/data.ts @@ -1,4 +1,4 @@ -import { Permission, Role, Edition } from '@/utils/permission/type' +import {Permission, Role, Edition} from '@/utils/permission/type' // class Operate(Enum): // """ // 一个权限组的操作权限 @@ -195,7 +195,7 @@ const PermissionConst = { SHARED_KNOWLEDGE_PROBLEM_CREATE: new Permission('SYSTEM_KNOWLEDGE_PROBLEM:READ+CREATE'), SHARED_KNOWLEDGE_PROBLEM_EDIT: new Permission('SYSTEM_KNOWLEDGE_PROBLEM:READ+EDIT'), SHARED_KNOWLEDGE_PROBLEM_DELETE: new Permission('SYSTEM_KNOWLEDGE_PROBLEM:READ+DELETE'), - + SHARED_KNOWLEDGE_HIT_TEST_READ: new Permission('SYSTEM_KNOWLEDGE_HIT_TEST:READ'), KNOWLEDGE_HIT_TEST_READ: new Permission('KNOWLEDGE_HIT_TEST:READ'), @@ -219,6 +219,7 @@ const PermissionConst = { RESOURCE_TOOL_EXPORT: new Permission('SYSTEM_RESOURCE_TOOL:READ+EXPORT'), RESOURCE_KNOWLEDGE_READ: new Permission('SYSTEM_RESOURCE_KNOWLEDGE:READ'), + RESOURCE_APPLICATION_READ: new Permission('SYSTEM_RESOURCE_APPLICATION:READ'), RESOURCE_MODEL_READ: new Permission('SYSTEM_RESOURCE_MODEL:READ'), @@ -277,4 +278,4 @@ const EditionConst = { IS_EE: new Edition('X-PACK-EE'), IS_CE: new Edition('X-PACK-CE'), } -export { PermissionConst, RoleConst, EditionConst } +export {PermissionConst, RoleConst, EditionConst} diff --git a/ui/src/views/system-resource-management/ApplicationResourceIndex.vue b/ui/src/views/system-resource-management/ApplicationResourceIndex.vue index 24fc4eac1..8fcfb1efe 100644 --- a/ui/src/views/system-resource-management/ApplicationResourceIndex.vue +++ b/ui/src/views/system-resource-management/ApplicationResourceIndex.vue @@ -15,9 +15,9 @@ style="width: 120px" @change="search_type_change" > - + - + - + - + - + {{ scope.row.name }} @@ -71,16 +71,84 @@ - @@ -127,23 +195,30 @@
{{ $t('common.clear') }} + >{{ $t('common.clear') }} {{ $t('common.confirm') }} + >{{ $t('common.confirm') }}
- - + + + - + + + + @@ -154,16 +229,16 @@