|
| 1 | +import {Result} from '@/request/Result' |
| 2 | +import {get, post, postStream, del, put, request, download, exportFile} from '@/request/index' |
| 3 | +import type {pageRequest} from '@/api/type/common' |
| 4 | +import type {ApplicationFormType} from '@/api/type/application' |
| 5 | +import {type Ref} from 'vue' |
| 6 | +import useStore from '@/stores' |
| 7 | + |
| 8 | +const prefix = '/system/resource/application' |
| 9 | + |
| 10 | +/** |
| 11 | + * 获取全部应用 |
| 12 | + * @param 参数 |
| 13 | + */ |
| 14 | +const getAllApplication: (param?: any, loading?: Ref<boolean>) => Promise<Result<any[]>> = ( |
| 15 | + param, |
| 16 | + loading, |
| 17 | +) => { |
| 18 | + return get(`${prefix}`, param, loading) |
| 19 | +} |
| 20 | + |
| 21 | +/** |
| 22 | + * 获取分页应用 |
| 23 | + * param { |
| 24 | + "name": "string", |
| 25 | + } |
| 26 | + */ |
| 27 | +const getApplication: ( |
| 28 | + page: pageRequest, |
| 29 | + param: any, |
| 30 | + loading?: Ref<boolean>, |
| 31 | +) => Promise<Result<any>> = (page, param, loading) => { |
| 32 | + return get(`${prefix}/${page.current_page}/${page.page_size}`, param, loading) |
| 33 | +} |
| 34 | + |
| 35 | +/** |
| 36 | + * 创建应用 |
| 37 | + * @param 参数 |
| 38 | + */ |
| 39 | +const postApplication: ( |
| 40 | + data: ApplicationFormType, |
| 41 | + loading?: Ref<boolean>, |
| 42 | +) => Promise<Result<any>> = (data, loading) => { |
| 43 | + return post(`${prefix}`, data, undefined, loading) |
| 44 | +} |
| 45 | + |
| 46 | +/** |
| 47 | + * 修改应用 |
| 48 | + * @param 参数 |
| 49 | + */ |
| 50 | +const putApplication: ( |
| 51 | + application_id: string, |
| 52 | + data: ApplicationFormType, |
| 53 | + loading?: Ref<boolean>, |
| 54 | +) => Promise<Result<any>> = (application_id, data, loading) => { |
| 55 | + return put(`${prefix}/${application_id}`, data, undefined, loading) |
| 56 | +} |
| 57 | + |
| 58 | +/** |
| 59 | + * 删除应用 |
| 60 | + * @param 参数 application_id |
| 61 | + */ |
| 62 | +const delApplication: ( |
| 63 | + application_id: string, |
| 64 | + loading?: Ref<boolean>, |
| 65 | +) => Promise<Result<boolean>> = (application_id, loading) => { |
| 66 | + return del(`${prefix}/${application_id}`, undefined, {}, loading) |
| 67 | +} |
| 68 | + |
| 69 | +/** |
| 70 | + * 应用详情 |
| 71 | + * @param 参数 application_id |
| 72 | + */ |
| 73 | +const getApplicationDetail: ( |
| 74 | + application_id: string, |
| 75 | + loading?: Ref<boolean>, |
| 76 | +) => Promise<Result<any>> = (application_id, loading) => { |
| 77 | + return get(`${prefix}/${application_id}`, undefined, loading) |
| 78 | +} |
| 79 | + |
| 80 | +/** |
| 81 | + * 获取AccessToken |
| 82 | + * @param 参数 application_id |
| 83 | + */ |
| 84 | +const getAccessToken: (application_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = ( |
| 85 | + application_id, |
| 86 | + loading, |
| 87 | +) => { |
| 88 | + return get(`${prefix}/${application_id}/access_token`, undefined, loading) |
| 89 | +} |
| 90 | +/** |
| 91 | + * 获取应用设置 |
| 92 | + * @param application_id 应用id |
| 93 | + * @param loading 加载器 |
| 94 | + * @returns |
| 95 | + */ |
| 96 | +const getApplicationSetting: ( |
| 97 | + application_id: string, |
| 98 | + loading?: Ref<boolean>, |
| 99 | +) => Promise<Result<any>> = (application_id, loading) => { |
| 100 | + return get(`${prefix}/${application_id}/setting`, undefined, loading) |
| 101 | +} |
| 102 | + |
| 103 | +/** |
| 104 | + * 修改AccessToken |
| 105 | + * @param 参数 application_id |
| 106 | + * data { |
| 107 | + * "is_active": true |
| 108 | + * } |
| 109 | + */ |
| 110 | +const putAccessToken: ( |
| 111 | + application_id: string, |
| 112 | + data: any, |
| 113 | + loading?: Ref<boolean>, |
| 114 | +) => Promise<Result<any>> = (application_id, data, loading) => { |
| 115 | + return put(`${prefix}/${application_id}/access_token`, data, undefined, loading) |
| 116 | +} |
| 117 | + |
| 118 | +/** |
| 119 | + * 导出应用 |
| 120 | + */ |
| 121 | + |
| 122 | +const exportApplication = ( |
| 123 | + application_id: string, |
| 124 | + application_name: string, |
| 125 | + loading?: Ref<boolean>, |
| 126 | +) => { |
| 127 | + return exportFile( |
| 128 | + application_name + '.mk', |
| 129 | + `${prefix}/${application_id}/export`, |
| 130 | + undefined, |
| 131 | + loading, |
| 132 | + ) |
| 133 | +} |
| 134 | + |
| 135 | +/** |
| 136 | + * 导入应用 |
| 137 | + */ |
| 138 | +const importApplication: (data: any, loading?: Ref<boolean>) => Promise<Result<any>> = ( |
| 139 | + data, |
| 140 | + loading, |
| 141 | +) => { |
| 142 | + return post(`${prefix}/import`, data, undefined, loading) |
| 143 | +} |
| 144 | + |
| 145 | +/** |
| 146 | + * 统计 |
| 147 | + * @param 参数 application_id, data |
| 148 | + */ |
| 149 | +const getStatistics: ( |
| 150 | + application_id: string, |
| 151 | + data: any, |
| 152 | + loading?: Ref<boolean>, |
| 153 | +) => Promise<Result<any>> = (application_id, data, loading) => { |
| 154 | + return get(`${prefix}/${application_id}/application_stats`, data, loading) |
| 155 | +} |
| 156 | +/** |
| 157 | + * 打开调试对话id |
| 158 | + * @param application_id 应用id |
| 159 | + * @param loading 加载器 |
| 160 | + * @returns |
| 161 | + */ |
| 162 | +const open: (application_id: string, loading?: Ref<boolean>) => Promise<Result<string>> = ( |
| 163 | + application_id, |
| 164 | + loading, |
| 165 | +) => { |
| 166 | + return get(`${prefix}/${application_id}/open`, {}, loading) |
| 167 | +} |
| 168 | +/** |
| 169 | + * 对话 |
| 170 | + * @param 参数 |
| 171 | + * chat_id: string |
| 172 | + * data |
| 173 | + */ |
| 174 | +const chat: (chat_id: string, data: any) => Promise<any> = (chat_id, data) => { |
| 175 | + const prefix = (window.MaxKB?.prefix ? window.MaxKB?.prefix : '/admin') + '/api' |
| 176 | + return postStream(`${prefix}/chat_message/${chat_id}`, data) |
| 177 | +} |
| 178 | +/** |
| 179 | + * 获取对话用户认证类型 |
| 180 | + * @param loading 加载器 |
| 181 | + * @returns |
| 182 | + */ |
| 183 | +const getChatUserAuthType: (loading?: Ref<boolean>) => Promise<any> = (loading) => { |
| 184 | + return get(`/chat_user/auth/types`, {}, loading) |
| 185 | +} |
| 186 | + |
| 187 | +/** |
| 188 | + * 获取平台状态 |
| 189 | + */ |
| 190 | +const getPlatformStatus: (application_id: string) => Promise<Result<any>> = (application_id) => { |
| 191 | + return get(`${prefix}/${application_id}/platform/status`) |
| 192 | +} |
| 193 | +/** |
| 194 | + * 更新平台状态 |
| 195 | + */ |
| 196 | +const updatePlatformStatus: (application_id: string, data: any) => Promise<Result<any>> = ( |
| 197 | + application_id, |
| 198 | + data, |
| 199 | +) => { |
| 200 | + return post(`${prefix}/${application_id}/platform/status`, data) |
| 201 | +} |
| 202 | +/** |
| 203 | + * 获取平台配置 |
| 204 | + */ |
| 205 | +const getPlatformConfig: (application_id: string, type: string) => Promise<Result<any>> = ( |
| 206 | + application_id, |
| 207 | + type, |
| 208 | +) => { |
| 209 | + return get(`${prefix}/${application_id}/platform/${type}`) |
| 210 | +} |
| 211 | +/** |
| 212 | + * 更新平台配置 |
| 213 | + */ |
| 214 | +const updatePlatformConfig: ( |
| 215 | + application_id: string, |
| 216 | + type: string, |
| 217 | + data: any, |
| 218 | + loading?: Ref<boolean>, |
| 219 | +) => Promise<Result<any>> = (application_id, type, data, loading) => { |
| 220 | + return post(`${prefix}/${application_id}/platform/${type}`, data, undefined, loading) |
| 221 | +} |
| 222 | +/** |
| 223 | + * 应用发布 |
| 224 | + * @param application_id |
| 225 | + * @param loading |
| 226 | + * @returns |
| 227 | + */ |
| 228 | +const publish: ( |
| 229 | + application_id: string, |
| 230 | + data: any, |
| 231 | + loading?: Ref<boolean>, |
| 232 | +) => Promise<Result<any>> = (application_id, data, loading) => { |
| 233 | + return put(`${prefix}/${application_id}/publish`, data, {}, loading) |
| 234 | +} |
| 235 | + |
| 236 | +/** |
| 237 | + * |
| 238 | + * @param application_id |
| 239 | + * @param data |
| 240 | + * @param loading |
| 241 | + * @returns |
| 242 | + */ |
| 243 | +const playDemoText: (application_id: string, data: any, loading?: Ref<boolean>) => Promise<any> = ( |
| 244 | + application_id, |
| 245 | + data, |
| 246 | + loading, |
| 247 | +) => { |
| 248 | + return download( |
| 249 | + `${prefix}/${application_id}/play_demo_text`, |
| 250 | + 'post', |
| 251 | + data, |
| 252 | + undefined, |
| 253 | + loading, |
| 254 | + ) |
| 255 | +} |
| 256 | + |
| 257 | +/** |
| 258 | + * 文本转语音 |
| 259 | + */ |
| 260 | +const postTextToSpeech: ( |
| 261 | + application_id: String, |
| 262 | + data: any, |
| 263 | + loading?: Ref<boolean>, |
| 264 | +) => Promise<Result<any>> = (application_id, data, loading) => { |
| 265 | + return download( |
| 266 | + `${prefix}/${application_id}/text_to_speech`, |
| 267 | + 'post', |
| 268 | + data, |
| 269 | + undefined, |
| 270 | + loading, |
| 271 | + ) |
| 272 | +} |
| 273 | +/** |
| 274 | + * 语音转文本 |
| 275 | + */ |
| 276 | +const speechToText: ( |
| 277 | + application_id: String, |
| 278 | + data: any, |
| 279 | + loading?: Ref<boolean>, |
| 280 | +) => Promise<Result<any>> = (application_id, data, loading) => { |
| 281 | + return post(`${prefix}/${application_id}/speech_to_text`, data, undefined, loading) |
| 282 | +} |
| 283 | + |
| 284 | +/** |
| 285 | + * mcp 节点 |
| 286 | + */ |
| 287 | +const getMcpTools: (application_id: String, loading?: Ref<boolean>) => Promise<Result<any>> = ( |
| 288 | + application_id, |
| 289 | + loading, |
| 290 | +) => { |
| 291 | + return get(`${prefix}/${application_id}/mcp_tools`, undefined, loading) |
| 292 | +} |
| 293 | + |
| 294 | +export default { |
| 295 | + getAllApplication, |
| 296 | + getApplication, |
| 297 | + postApplication, |
| 298 | + putApplication, |
| 299 | + delApplication, |
| 300 | + getApplicationDetail, |
| 301 | + getAccessToken, |
| 302 | + putAccessToken, |
| 303 | + exportApplication, |
| 304 | + importApplication, |
| 305 | + getStatistics, |
| 306 | + open, |
| 307 | + chat, |
| 308 | + getChatUserAuthType, |
| 309 | + getApplicationSetting, |
| 310 | + getPlatformStatus, |
| 311 | + updatePlatformStatus, |
| 312 | + getPlatformConfig, |
| 313 | + publish, |
| 314 | + updatePlatformConfig, |
| 315 | + playDemoText, |
| 316 | + postTextToSpeech, |
| 317 | + speechToText, |
| 318 | + getMcpTools, |
| 319 | +} |
0 commit comments