UnisKB/ui/src/api/application/application.ts

413 lines
9.3 KiB
TypeScript
Raw Normal View History

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'
2025-06-16 04:08:09 +00:00
import useStore from '@/stores'
2025-06-03 09:29:33 +00:00
const prefix: any = { _value: '/workspace/' }
2025-06-16 04:08:09 +00:00
Object.defineProperty(prefix, 'value', {
get: function () {
const { user } = useStore()
2025-06-16 04:08:09 +00:00
return this._value + user.getWorkspaceId() + '/application'
},
})
2025-06-03 09:29:33 +00:00
/**
*
* @param param
* @param loading
2025-06-03 09:29:33 +00:00
*/
2025-06-10 12:07:14 +00:00
const getAllApplication: (param?: any, loading?: Ref<boolean>) => Promise<Result<any[]>> = (
param,
loading,
) => {
2025-06-16 04:08:09 +00:00
return get(`${prefix.value}`, param, loading)
2025-06-03 09:29:33 +00:00
}
/**
*
* param {
"name": "string",
}
*/
const getApplication: (
page: pageRequest,
param: any,
loading?: Ref<boolean>,
2025-06-06 01:39:01 +00:00
) => Promise<Result<any>> = (page, param, loading) => {
2025-06-16 04:08:09 +00:00
return get(`${prefix.value}/${page.current_page}/${page.page_size}`, param, loading)
2025-06-03 09:29:33 +00:00
}
/**
*
* @param data
* @param loading
2025-06-03 09:29:33 +00:00
*/
const postApplication: (
data: ApplicationFormType,
loading?: Ref<boolean>,
2025-06-06 01:39:01 +00:00
) => Promise<Result<any>> = (data, loading) => {
2025-06-16 04:08:09 +00:00
return post(`${prefix.value}`, data, undefined, loading)
2025-06-03 09:29:33 +00:00
}
/**
*
* @param application_id
* @param data
* @param loading
2025-06-03 09:29:33 +00:00
*/
const putApplication: (
2025-06-06 04:31:30 +00:00
application_id: string,
2025-06-03 09:29:33 +00:00
data: ApplicationFormType,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, data, loading) => {
2025-06-16 04:08:09 +00:00
return put(`${prefix.value}/${application_id}`, data, undefined, loading)
2025-06-03 09:29:33 +00:00
}
/**
*
* @param application_id
* @param loading
2025-06-03 09:29:33 +00:00
*/
const delApplication: (
2025-06-06 04:31:30 +00:00
application_id: string,
2025-06-03 09:29:33 +00:00
loading?: Ref<boolean>,
) => Promise<Result<boolean>> = (application_id, loading) => {
2025-06-16 04:08:09 +00:00
return del(`${prefix.value}/${application_id}`, undefined, {}, loading)
2025-06-03 09:29:33 +00:00
}
/**
*
* @param application_id
* @param loading
2025-06-03 09:29:33 +00:00
*/
const getApplicationDetail: (
application_id: string,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, loading) => {
2025-06-16 04:08:09 +00:00
return get(`${prefix.value}/${application_id}`, undefined, loading)
2025-06-03 09:29:33 +00:00
}
/**
* AccessToken
* @param application_id
* @param loading
2025-06-03 09:29:33 +00:00
*/
const getAccessToken: (application_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
application_id,
loading,
) => {
2025-06-16 04:08:09 +00:00
return get(`${prefix.value}/${application_id}/access_token`, undefined, loading)
2025-06-03 09:29:33 +00:00
}
2025-06-19 09:25:46 +00:00
/**
*
* @param application_id id
* @param loading
* @returns
*/
const getApplicationSetting: (
application_id: string,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, loading) => {
return get(`${prefix.value}/${application_id}/setting`, undefined, loading)
}
2025-06-03 09:29:33 +00:00
/**
* AccessToken
* data {
* "is_active": true
* }
* @param application_id
* @param data
* @param loading
2025-06-03 09:29:33 +00:00
*/
const putAccessToken: (
application_id: string,
data: any,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, data, loading) => {
2025-06-16 04:08:09 +00:00
return put(`${prefix.value}/${application_id}/access_token`, data, undefined, loading)
2025-06-03 09:29:33 +00:00
}
2025-07-10 14:33:39 +00:00
/**
* -AccessToken
* data {
* "show_source": boolean,
* "show_history": boolean,
* "draggable": boolean,
* "show_guide": boolean,
* "avatar": file,
* "float_icon": file,
* }
* @param application_id
* @param data
* @param loading
2025-07-10 14:33:39 +00:00
*/
const putXpackAccessToken: (
application_id: string,
data: any,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, data, loading) => {
return put(`${prefix.value}/${application_id}/setting`, data, undefined, loading)
}
2025-06-03 09:29:33 +00:00
/**
2025-06-10 12:07:14 +00:00
*
2025-06-03 09:29:33 +00:00
*/
2025-06-10 12:07:14 +00:00
const exportApplication = (
2025-06-03 09:29:33 +00:00
application_id: string,
2025-06-10 12:07:14 +00:00
application_name: string,
2025-06-03 09:29:33 +00:00
loading?: Ref<boolean>,
2025-06-10 12:07:14 +00:00
) => {
return exportFile(
application_name + '.mk',
2025-06-16 04:08:09 +00:00
`${prefix.value}/${application_id}/export`,
2025-06-03 09:29:33 +00:00
undefined,
loading,
)
}
/**
2025-06-10 12:07:14 +00:00
*
2025-06-03 09:29:33 +00:00
*/
2025-07-11 13:45:08 +00:00
const importApplication: (
folder_id: string,
data: any,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (folder_id, data, loading) => {
return post(`${prefix.value}/folder/${folder_id}/import`, data, undefined, loading)
2025-06-03 09:29:33 +00:00
}
/**
2025-06-10 12:07:14 +00:00
*
* @param application_id
* @param data
* @param loading
2025-06-03 09:29:33 +00:00
*/
2025-06-10 12:07:14 +00:00
const getStatistics: (
2025-06-06 04:31:30 +00:00
application_id: string,
2025-06-03 09:29:33 +00:00
data: any,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, data, loading) => {
2025-06-16 04:08:09 +00:00
return get(`${prefix.value}/${application_id}/application_stats`, data, loading)
2025-06-03 09:29:33 +00:00
}
/**
* id
* @param application_id id
* @param loading
* @returns
*/
const open: (application_id: string, loading?: Ref<boolean>) => Promise<Result<string>> = (
application_id,
loading,
) => {
2025-06-16 04:08:09 +00:00
return get(`${prefix.value}/${application_id}/open`, {}, loading)
}
2025-09-09 06:09:59 +00:00
/**
2025-09-12 09:06:38 +00:00
*
* @param workspace_id
* @param model_id
* @param application_id
* @param data
* @returns
*/
const generate_prompt: (workspace_id:string ,model_id:string, application_id:string,data: any) => Promise<any> = (
2025-09-09 06:09:59 +00:00
workspace_id,
model_id,
2025-09-12 09:06:38 +00:00
application_id,
2025-09-09 06:09:59 +00:00
data
) => {
const prefix = (window.MaxKB?.prefix ? window.MaxKB?.prefix : '/admin') + '/api'
2025-09-12 09:06:38 +00:00
return postStream(`${prefix}/workspace/${workspace_id}/application/${application_id}/model/${model_id}/prompt_generate`, data)
2025-09-09 06:09:59 +00:00
}
/**
*
* chat_id: string
* data
* @param chat_id
* @param data
*/
const chat: (chat_id: string, data: any) => Promise<any> = (chat_id, data) => {
2025-07-01 07:43:00 +00:00
const prefix = (window.MaxKB?.prefix ? window.MaxKB?.prefix : '/admin') + '/api'
return postStream(`${prefix}/chat_message/${chat_id}`, data)
}
2025-06-19 09:25:46 +00:00
/**
*
* @param loading
* @returns
*/
const getChatUserAuthType: (loading?: Ref<boolean>) => Promise<any> = (loading) => {
return get(`/chat_user/auth/types`, {}, loading)
}
2025-06-20 09:13:01 +00:00
/**
*
*/
const getPlatformStatus: (application_id: string) => Promise<Result<any>> = (application_id) => {
return get(`${prefix.value}/${application_id}/platform/status`)
}
/**
*
*/
const updatePlatformStatus: (application_id: string, data: any) => Promise<Result<any>> = (
application_id,
2025-06-23 02:35:21 +00:00
data,
2025-06-20 09:13:01 +00:00
) => {
return post(`${prefix.value}/${application_id}/platform/status`, data)
}
/**
*
*/
const getPlatformConfig: (application_id: string, type: string) => Promise<Result<any>> = (
application_id,
2025-06-23 02:35:21 +00:00
type,
2025-06-20 09:13:01 +00:00
) => {
return get(`${prefix.value}/${application_id}/platform/${type}`)
}
2025-06-24 10:21:09 +00:00
/**
*
*/
const updatePlatformConfig: (
application_id: string,
type: string,
data: any,
loading?: Ref<boolean>,
2025-06-24 10:21:09 +00:00
) => Promise<Result<any>> = (application_id, type, data, loading) => {
return post(`${prefix.value}/${application_id}/platform/${type}`, data, undefined, loading)
}
2025-06-23 02:35:21 +00:00
/**
*
* @param application_id
* @param data
2025-06-23 02:35:21 +00:00
* @param loading
* @returns
*/
const publish: (
application_id: string,
data: any,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, data, loading) => {
return put(`${prefix.value}/${application_id}/publish`, data, {}, loading)
}
/**
*
* @param application_id
* @param data
* @param loading
* @returns
*/
const playDemoText: (application_id: string, data: any, loading?: Ref<boolean>) => Promise<any> = (
application_id,
data,
loading,
) => {
return download(
`${prefix.value}/${application_id}/play_demo_text`,
'post',
data,
undefined,
loading,
)
}
/**
*
*/
2025-07-01 12:30:43 +00:00
const postTextToSpeech: (
application_id: string,
data: any,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, data, loading) => {
return download(
`${prefix.value}/${application_id}/text_to_speech`,
'post',
data,
undefined,
loading,
)
}
/**
*
*/
const speechToText: (
application_id: string,
data: any,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, data, loading) => {
return post(`${prefix.value}/${application_id}/speech_to_text`, data, undefined, loading)
}
2025-07-01 11:16:58 +00:00
/**
* mcp
*/
const getMcpTools: (
application_id: string,
mcp_servers: any,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, mcp_servers, loading) => {
return post(`${prefix.value}/${application_id}/mcp_tools`, { mcp_servers }, {}, loading)
2025-07-01 11:16:58 +00:00
}
2025-07-04 11:52:45 +00:00
/**
*
* @param file
* @param sourceId
* @param resourceType
* @param loading
2025-07-04 11:52:45 +00:00
*/
2025-07-10 09:09:19 +00:00
const postUploadFile: (
2025-07-04 11:52:45 +00:00
file: any,
sourceId: string,
resourceType:
| 'KNOWLEDGE'
| 'APPLICATION'
| 'TOOL'
| 'DOCUMENT'
| 'CHAT'
| 'TEMPORARY_30_MINUTE'
| 'TEMPORARY_120_MINUTE'
| 'TEMPORARY_1_DAY',
2025-07-10 09:09:19 +00:00
loading?: Ref<boolean>,
) => Promise<Result<any>> = (file, sourceId, resourceType, loading) => {
2025-07-04 11:52:45 +00:00
const fd = new FormData()
fd.append('file', file)
fd.append('source_id', sourceId)
fd.append('source_type', resourceType)
2025-07-10 09:09:19 +00:00
return post(`/oss/file`, fd, undefined, loading)
2025-07-04 11:52:45 +00:00
}
2025-06-03 09:29:33 +00:00
export default {
2025-06-10 12:07:14 +00:00
getAllApplication,
2025-06-03 09:29:33 +00:00
getApplication,
postApplication,
putApplication,
delApplication,
getApplicationDetail,
getAccessToken,
putAccessToken,
2025-07-10 14:33:39 +00:00
putXpackAccessToken,
2025-06-03 09:29:33 +00:00
exportApplication,
importApplication,
2025-06-10 12:07:14 +00:00
getStatistics,
open,
chat,
2025-06-19 09:25:46 +00:00
getChatUserAuthType,
getApplicationSetting,
2025-06-20 09:13:01 +00:00
getPlatformStatus,
updatePlatformStatus,
2025-06-23 02:35:21 +00:00
getPlatformConfig,
publish,
updatePlatformConfig,
playDemoText,
2025-07-01 12:30:43 +00:00
postTextToSpeech,
speechToText,
2025-07-01 11:16:58 +00:00
getMcpTools,
2025-07-10 09:09:19 +00:00
postUploadFile,
2025-09-09 06:09:59 +00:00
generate_prompt
2025-06-03 09:29:33 +00:00
}