Skip to content

Commit 401acbd

Browse files
feat: tool
1 parent 2faaddd commit 401acbd

48 files changed

Lines changed: 1013 additions & 478 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ui/src/api/API_README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ API 枚举与类型统一在 `src/api` 范围内管理,相关规则由本文
134134
- Admin Router 与请求客户端直接读取 `window.MaxKB` 运行时路径配置;`Window`
135135
`MaxKBRuntimeConfig` 的全局类型统一声明在根目录 `env.d.ts`
136136
- Admin 普通 JSON 请求使用 Axios;`request.ts` 导出 Axios 实例以及 `promise``get`
137-
`post``put``del` 请求封装。
137+
`post``put``del`Blob 文件 `downloadRequest` 请求封装。
138138
- 正常 JSON 接口返回 `Promise<T>`,请求层负责解包后端 `{ code, message, data }` 响应。
139139
- GET 文件导出使用 `getExportFile`;需要通过 POST 同时传递查询参数和可选请求体的 Excel 导出
140-
使用 `postExportExcel`。请求层统一获取 Blob、解析 `Content-Disposition` 文件名并触发浏览器
141-
下载;业务 API 只需传入默认文件名、接口地址及业务参数
140+
使用 `postExportExcel`;Skill 压缩包等指定请求方法的文件下载使用 `downloadRequest`。请求层统一
141+
获取 Blob、解析 `Content-Disposition` 文件名并触发浏览器下载;业务 API 只需传入接口地址及业务参数
142142
- 业务代码通过 `api.method().then(...)` 处理接口成功后的状态变化;通用接口错误由请求层统一
143143
提示,不在调用处重复使用 `try/catch``.catch()` 提示相同错误。只有业务降级、状态恢复等
144144
非提示类失败处理可以按需保留失败分支。

ui/src/api/admin/core/request.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,31 @@ export function get<T = unknown>(
207207
return promise<T>(request.get<ApiResponse<T>>(url, { params, timeout }), loading)
208208
}
209209

210+
/** 发送指定方法的 Blob 请求并触发浏览器下载。 */
211+
export async function downloadRequest(
212+
url: string,
213+
method: string,
214+
data?: unknown,
215+
params?: Dict<unknown>,
216+
loading?: LoadingTarget,
217+
): Promise<boolean> {
218+
startLoading(loading)
219+
try {
220+
const response = await request.request<Blob>({
221+
url,
222+
method,
223+
data,
224+
params,
225+
responseType: 'blob',
226+
skipGlobalErrorMessage: true,
227+
} as ExportRequestConfig)
228+
229+
return downloadExportResponse(response, 'download')
230+
} finally {
231+
finishLoading(loading)
232+
}
233+
}
234+
210235
/** 发送 GET 请求并将 Blob 响应下载为文件。 */
211236
export async function getExportFile(
212237
fileName: string,

ui/src/api/admin/workspace/tool/tool.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { del, getExportFile, get, post, put } from '../../core/request'
1+
import { del, downloadRequest, getExportFile, get, post, put } from '../../core/request'
22
import type { ParamsPage, ResponsePage } from '../../core/types'
33
import type { Dict, ToolDebugPayload, ToolItem, ToolPayload, ToolPylintIssue } from '@/api/types'
44
import { getWorkspaceId } from '@/utils/resource-context'
@@ -28,6 +28,21 @@ const putTool = (toolId: string, payload: ToolPayload) => {
2828
return put<ToolPayload, ToolItem>(`${getPrefix()}/${toolId}`, payload)
2929
}
3030

31+
/** 检查工作空间工具的 Python 代码。 */
32+
const postToolPylint = (code: string) => {
33+
return post<{ code: string }, ToolPylintIssue[]>(`${getPrefix()}/pylint`, { code })
34+
}
35+
36+
// const generateCode = (data: any) => {
37+
// const p = (window.MaxKB?.prefix ? window.MaxKB?.prefix : '/admin') + '/api'
38+
// return postStream(`${p}${getPrefix()}/generate_code`, data)
39+
// }
40+
41+
/** 调试普通工具代码并返回运行结果。 */
42+
const postToolDebug = (payload: ToolDebugPayload) => {
43+
return post<ToolDebugPayload, unknown>(`${getPrefix()}/debug`, payload)
44+
}
45+
3146
/** 获取工具详情。 */
3247
const getToolDetail = (toolId: string) => {
3348
return get<ToolItem>(`${getPrefix()}/${toolId}`)
@@ -42,37 +57,22 @@ const postToolImport = (file: File, folderId: string) => {
4257
}
4358

4459
/** 上传 Skill 压缩包并返回临时文件 ID。 */
45-
const postSkillFile = (file: File) => {
60+
const putUploadSkillFile = (file: File) => {
4661
const payload = new FormData()
4762
payload.append('file', file)
48-
return post<FormData, string>(`${getPrefix()}/upload_skill_file`, payload)
63+
return put<FormData, string>(`${getPrefix()}/upload_skill_file`, payload)
4964
}
5065

5166
/** 下载 Skill 工具的压缩包。 */
52-
const downloadSkillFile = (toolId: string, fileName: string) => {
53-
return getExportFile(fileName, `${getPrefix()}/${toolId}/download_skill_file`)
67+
const downloadSkillFile = (toolId: string) => {
68+
return downloadRequest(`${getPrefix()}/${toolId}/download_skill_file`, 'GET')
5469
}
5570

5671
/** 导出工作空间工具文件。 */
5772
const exportTool = (toolId: string, toolName: string) => {
5873
return getExportFile(`${toolName}.tool`, `${getPrefix()}/${toolId}/export`)
5974
}
6075

61-
/** 检查工作空间工具的 Python 代码。 */
62-
const postToolPylint = (code: string) => {
63-
return post<{ code: string }, ToolPylintIssue[]>(`${getPrefix()}/pylint`, { code })
64-
}
65-
66-
// const generateCode = (data: any) => {
67-
// const p = (window.MaxKB?.prefix ? window.MaxKB?.prefix : '/admin') + '/api'
68-
// return postStream(`${p}${getPrefix()}/generate_code`, data)
69-
// }
70-
71-
/** 调试普通工具代码并返回运行结果。 */
72-
const postToolDebug = (payload: ToolDebugPayload) => {
73-
return post<ToolDebugPayload, unknown>(`${getPrefix()}/debug`, payload)
74-
}
75-
7676
/** 测试工具配置是否可连接。 */
7777
const postToolTestConnection = (payload: ToolPayload) => {
7878
return post<ToolPayload, boolean>(`${getPrefix()}/test_connection`, payload)
@@ -103,7 +103,7 @@ export default {
103103
postTool,
104104
postToolDebug,
105105
postToolImport,
106-
postSkillFile,
106+
putUploadSkillFile,
107107
postToolPylint,
108108
postToolTestConnection,
109109
putBatchDeleteTools,
Lines changed: 7 additions & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 6 additions & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)