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

325 lines
7.4 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
*/
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
*/
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
*/
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
*/
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
*/
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
*/
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
* @param application_id
* data {
* "is_active": true
* }
*/
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-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-06-10 12:07:14 +00:00
const importApplication: (data: any, loading?: Ref<boolean>) => Promise<Result<any>> = (
2025-06-03 09:29:33 +00:00
data,
loading,
) => {
2025-06-16 04:08:09 +00:00
return post(`${prefix.value}/import`, data, undefined, loading)
2025-06-03 09:29:33 +00:00
}
/**
2025-06-10 12:07:14 +00:00
*
* @param application_id, data
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)
}
/**
*
* @param
* chat_id: string
* 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 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, loading?: Ref<boolean>) => Promise<Result<any>> = (
application_id,
loading,
) => {
return get(`${prefix.value}/${application_id}/mcp_tools`, undefined, loading)
}
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,
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-06-03 09:29:33 +00:00
}