Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion ui/src/api/API_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ API 枚举与类型统一在 `src/api` 范围内管理,相关规则由本文
- GET 文件导出使用 `getExportFile`;需要通过 POST 同时传递查询参数和可选请求体的 Excel 导出
使用 `postExportExcel`;Skill 压缩包等指定请求方法的文件下载使用 `downloadRequest`。请求层统一
获取 Blob、解析 `Content-Disposition` 文件名并触发浏览器下载;业务 API 只需传入接口地址及业务参数。
`downloadRequest` 的第五个参数可指定回退文件名,缺省为 `download`;服务端文件名始终优先。
- 业务代码通过 `api.method().then(...)` 处理接口成功后的状态变化;通用接口错误由请求层统一
提示,不在调用处重复使用 `try/catch` 或 `.catch()` 提示相同错误。只有业务降级、状态恢复等
非提示类失败处理可以按需保留失败分支。
Expand Down Expand Up @@ -520,6 +521,11 @@ System 接口由资源管理服务提供;本地开源后端没有对应扩展
任务取消、生成问题、迁移、同步、导出、原文件下载/替换及标签关联。
批量任务沿用 v2 的 `id_list` / `state_list`;生成问题使用 `document_id_list`,
添加标签使用 `document_ids` / `tag_ids`,迁移和批量导出直接提交文档 ID 数组。
文档导出分别提供四个接口,不以单元素批量请求代替单项接口:
`exportDocument`、`exportDocumentZip` 使用 GET 请求 `/<documentId>/export`、`/<documentId>/export_zip`;
`exportMulDocument`、`exportMulDocumentZip` 使用 POST 请求 `batch_export`、`batch_export_zip`,请求体直接为 ID 数组。
单项参数为知识库 ID、文档 ID、文档名称;批量参数为知识库 ID、文档 ID 数组、知识库名称。
服务端未提供文件名时,分别以文档名称或知识库名称加 `.xlsx` / `.zip` 回退,沿用 v2 下载命名。
向量化、生成问题默认排除成功分段,也可选择全部分段。任务类型使用 `DOCUMENT_TASK_TYPE`。
单项向量化使用 `putDocumentRefresh(knowledgeId, documentId, stateList)` 请求 `/<documentId>/refresh`;
单项取消使用 `putCancelTask(knowledgeId, documentId, taskType)` 请求 `/<documentId>/cancel_task`,提交 `{ type }`。
Expand All @@ -529,7 +535,12 @@ System 接口由资源管理服务提供;本地开源后端没有对应扩展
提交 `{ id_list, state_list }`。两者均包含全部七种分段状态;单项取消分词复用 `putCancelTask`,任务类型为 `TOKENIZE`。
文档设置的共享载荷为 `DocumentSettingPayload`,生成问题使用 `DocumentGeneratePayload`;
单项设置通过 `meta` 保留来源数据,批量设置将 `allow_download` 放在顶层。
飞书同步沿用 v2 扩展接口 `/knowledge/lark/<knowledgeId>/_batch`,需部署环境支持。
文档同步区分单项和批量,不以单元素批量请求代替单项接口:
`putDocumentSync` 请求 `/<knowledgeId>/document/<documentId>/sync`,
`putMulSyncDocument` 请求 `/<knowledgeId>/document/batch_sync`;
`putLarkDocumentSync` 请求 `/lark/<knowledgeId>/document/<documentId>/sync`,
`putMulLarkSyncDocument` 请求 `/lark/<knowledgeId>/_batch`。上述路径均相对工作空间的 `knowledge` 前缀,
全部使用 PUT;单项不传请求体,批量提交 `{ id_list }`。飞书接口需部署环境支持。
共享文档 API 继续仅提供查询,不增加写入方法。

`workspace/knowledge/document.ts` 维护文档分页查询,路径为
Expand Down
4 changes: 2 additions & 2 deletions ui/src/api/admin/core/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export async function postExportExcel<TData = unknown>(fileName: string, url: st
}

/** 发送指定方法的 Blob 请求并触发浏览器下载。 */
export async function downloadRequest(url: string, method: string, data?: unknown, params?: Dict<unknown>): Promise<boolean> {
export async function downloadRequest(url: string, method: string, data?: unknown, params?: Dict<unknown>, fileName = 'download'): Promise<boolean> {
const response = await request.request<Blob>({
url,
method,
Expand All @@ -188,7 +188,7 @@ export async function downloadRequest(url: string, method: string, data?: unknow
skipGlobalErrorMessage: true,
} as ExportRequestConfig)

return downloadExportResponse(response, 'download')
return downloadExportResponse(response, fileName)
}

/** 发送 POST 请求并返回可逐块读取的原始响应。 */
Expand Down
72 changes: 41 additions & 31 deletions ui/src/api/admin/workspace/knowledge/document.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { del, downloadRequest, get, getExportFile, post, put } from '../../core/request'
import { del, downloadRequest, get, getExportFile, post, postExportExcel, put } from '../../core/request'
import type { ParamsPage, ResponsePage } from '../../core/types'
import type {
Dict,
Expand All @@ -8,7 +8,6 @@ import type {
DocumentSettingPayload,
DocumentTaskState,
DocumentTaskType,
KnowledgeTagGroup,
} from '@/api/types'
import { getWorkspaceId } from '@/utils/resource-context'

Expand Down Expand Up @@ -49,6 +48,10 @@ const putDocumentTokenize = (knowledgeId: string, documentId: string, stateList:
const putBatchTokenizeDocuments = (knowledgeId: string, documentIds: string[], stateList: DocumentTaskState[]) =>
put(`${getPrefix(knowledgeId)}/batch_tokenize`, { id_list: documentIds, state_list: stateList })

/** 单个/批量生成关联问题。 */
const putGenerateDocumentQuestions = (knowledgeId: string, data: DocumentGeneratePayload) =>
put(`${getPrefix(knowledgeId)}/batch_generate_related`, data)

/** 单个取消文档任务。 */
const putCancelTask = (knowledgeId: string, documentId: string, taskType: DocumentTaskType) =>
put(`${getPrefix(knowledgeId)}/${documentId}/cancel_task`, { type: taskType })
Expand All @@ -57,6 +60,21 @@ const putCancelTask = (knowledgeId: string, documentId: string, taskType: Docume
const putBatchCancelDocumentTask = (knowledgeId: string, documentIds: string[], taskType: DocumentTaskType) =>
put(`${getPrefix(knowledgeId)}/batch_cancel_task`, { id_list: documentIds, type: taskType })

/** 同步单个 Web 文档。 */
const putDocumentSync = (knowledgeId: string, documentId: string) => put(`${getPrefix(knowledgeId)}/${documentId}/sync`)

/** 批量同步 Web 文档。 */
const putMulSyncDocument = (knowledgeId: string, documentIds: string[]) =>
put<{ id_list: string[] }, boolean>(`${getPrefix(knowledgeId)}/batch_sync`, { id_list: documentIds })

/** 同步单个飞书文档。 */
const putLarkDocumentSync = (knowledgeId: string, documentId: string) =>
put(`/workspace/${getWorkspaceId()}/knowledge/lark/${knowledgeId}/document/${documentId}/sync`)

/** 批量同步飞书文档。 */
const putMulLarkSyncDocument = (knowledgeId: string, documentIds: string[]) =>
put<{ id_list: string[] }, boolean>(`/workspace/${getWorkspaceId()}/knowledge/lark/${knowledgeId}/_batch`, { id_list: documentIds })

/** 保存单个文档的召回及来源设置。 */
const putDocumentSetting = (knowledgeId: string, documentId: string, data: DocumentSettingPayload) =>
put(`${getPrefix(knowledgeId)}/${documentId}`, data)
Expand All @@ -65,24 +83,25 @@ const putDocumentSetting = (knowledgeId: string, documentId: string, data: Docum
const putBatchDocumentSetting = (knowledgeId: string, documentIds: string[], data: DocumentSettingPayload) =>
put(`${getPrefix(knowledgeId)}/batch_hit_handling`, { ...data, id_list: documentIds })

/** 根据文档内容生成关联问题。 */
const putGenerateDocumentQuestions = (knowledgeId: string, data: DocumentGeneratePayload) =>
put(`${getPrefix(knowledgeId)}/batch_generate_related`, data)

/** 将选中文档迁移至目标知识库。 */
const putMigrateDocuments = (knowledgeId: string, targetKnowledgeId: string, documentIds: string[]) =>
put(`${getPrefix(knowledgeId)}/migrate/${targetKnowledgeId}`, documentIds)

/** 同步 Web 文档。 */
const putSyncDocuments = (knowledgeId: string, documentIds: string[]) => put(`${getPrefix(knowledgeId)}/batch_sync`, { id_list: documentIds })
/** 将单个文档导出为 Excel。 */
const exportDocument = (knowledgeId: string, documentId: string, documentName: string) =>
getExportFile(`${documentName.trim()}.xlsx`, `${getPrefix(knowledgeId)}/${documentId}/export`)

/** 将选中文档批量导出为 Excel。 */
const exportMulDocument = (knowledgeId: string, documentIds: string[], knowledgeName: string) =>
postExportExcel(`${knowledgeName.trim()}.xlsx`, `${getPrefix(knowledgeId)}/batch_export`, undefined, documentIds)

/** 同步飞书文档。 */
const putSyncLarkDocuments = (knowledgeId: string, documentIds: string[]) =>
put(`/workspace/${getWorkspaceId()}/knowledge/lark/${knowledgeId}/_batch`, { id_list: documentIds })
/** 将单个文档及图片导出为 ZIP。 */
const exportDocumentZip = (knowledgeId: string, documentId: string, documentName: string) =>
getExportFile(`${documentName.trim()}.zip`, `${getPrefix(knowledgeId)}/${documentId}/export_zip`)

/** 导出所选文档为 Excel 或 ZIP。 */
const exportDocuments = (knowledgeId: string, documentIds: string[], format: 'excel' | 'zip') =>
downloadRequest(`${getPrefix(knowledgeId)}/${format === 'excel' ? 'batch_export' : 'batch_export_zip'}`, 'POST', documentIds)
/** 将选中文档及图片批量导出为 ZIP。 */
const exportMulDocumentZip = (knowledgeId: string, documentIds: string[], knowledgeName: string) =>
downloadRequest(`${getPrefix(knowledgeId)}/batch_export_zip`, 'POST', documentIds, undefined, `${knowledgeName.trim()}.zip`)

/** 下载文档原文件。 */
const downloadDocumentSource = (knowledgeId: string, document: DocumentItem) =>
Expand All @@ -95,17 +114,6 @@ const postReplaceDocumentSource = (knowledgeId: string, documentId: string, file
return post(`${getPrefix(knowledgeId)}/${documentId}/replace_source_file`, data)
}

/** 查询文档当前标签。 */
const getDocumentTags = (knowledgeId: string, documentId: string) => get<KnowledgeTagGroup[]>(`${getPrefix(knowledgeId)}/${documentId}/tags`)

/** 批量添加文档标签。 */
const postAddDocumentTags = (knowledgeId: string, documentIds: string[], tagIds: string[]) =>
post(`${getPrefix(knowledgeId)}/batch_add_tag`, { document_ids: documentIds, tag_ids: tagIds })

/** 移除文档标签关联。 */
const putDeleteDocumentTags = (knowledgeId: string, documentId: string, tagIds: string[]) =>
put(`${getPrefix(knowledgeId)}/${documentId}/tags/batch_delete`, tagIds)

export default {
getDocumentPage,
putQuickCreateDocuments,
Expand All @@ -122,12 +130,14 @@ export default {
putBatchDocumentSetting,
putGenerateDocumentQuestions,
putMigrateDocuments,
putSyncDocuments,
putSyncLarkDocuments,
exportDocuments,
putDocumentSync,
putMulSyncDocument,
putLarkDocumentSync,
putMulLarkSyncDocument,
exportDocument,
exportMulDocument,
exportDocumentZip,
exportMulDocumentZip,
downloadDocumentSource,
postReplaceDocumentSource,
getDocumentTags,
postAddDocumentTags,
putDeleteDocumentTags,
}
10 changes: 10 additions & 0 deletions ui/src/api/admin/workspace/knowledge/tags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** 查询文档当前标签。 */
const getDocumentTags = (knowledgeId: string, documentId: string) => get<KnowledgeTagGroup[]>(`${getPrefix(knowledgeId)}/${documentId}/tags`)

/** 批量添加文档标签。 */
const postAddDocumentTags = (knowledgeId: string, documentIds: string[], tagIds: string[]) =>
post(`${getPrefix(knowledgeId)}/batch_add_tag`, { document_ids: documentIds, tag_ids: tagIds })

/** 移除文档标签关联。 */
const putDeleteDocumentTags = (knowledgeId: string, documentId: string, tagIds: string[]) =>
put(`${getPrefix(knowledgeId)}/${documentId}/tags/batch_delete`, tagIds)
2 changes: 1 addition & 1 deletion ui/src/assets/iconfont.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ defineExpose({ open, close })

<template>
<MkDialog v-model="visible" title="生成问题" @closed="emit('closed')">
<el-form ref="formRef" :model="form" label-position="top" :disabled="loading || modelLoading" @submit.prevent>
<el-form ref="formRef" :model="form" label-position="top" v-loading="loading || modelLoading" @submit.prevent>
<el-alert :closable="false" :title="promptTip" type="primary" class="mb-4! items-start! whitespace-pre-line" show-icon>
<template #icon><MkIcon name="icon_info_filled" class="mt-2" /></template>
</el-alert>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/constants/CONSTANT_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const knowledgeTypeLabel = KNOWLEDGE_TYPE_LABELS[knowledgeType]
`state.ts` 的 `EXECUTION_STATUS_OPTIONS` 维护触发器、工具和知识库工作流执行记录共用的
中文文案与图标类型,仅包含 `PENDING`、`STARTED`、`SUCCESS`、`FAILURE`、`REVOKE`、
`REVOKED`、`TRIGGER_ERROR` 七种接口状态,列表筛选及执行详情复用该配置。新增状态只需在业务配置中补齐展示,
不修改 `MkStatusLabel`。文档任务使用 `views/knowledge-detail/document/status.ts` 的独立配置,
不修改 `MkStatusLabel`。文档任务使用 `views/knowledge-detail/library/document/status.ts` 的独立配置,
筛选查询仍映射 `DOCUMENT_TASK_STATE` 与 `DOCUMENT_TASK_TYPE`,不提交展示状态键。

`document.ts` 的 `DOCUMENT_HIT_HANDLING_LABELS` 维护文档命中处理方式的展示文案,
Expand Down
2 changes: 2 additions & 0 deletions ui/src/router/ROUTE_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ System 共享资源页面:
详情容器复用 `ResourceDetailLayout`,菜单依次为“资料库(文档、图片、标签管理)”、
“工作流”、“检索优化(召回测试、问题、自定义分词)”、“授权与集成(对话用户、外部检索服务)”、
“设置”。资料库分组使用空 path,保留原 `/document` 地址;图片和标签分别使用 `/image`、`/tag`。
对应 View 统一位于 `views/knowledge-detail/library/` 下的 `document/`、`image/`、`tag/`;
普通和共享文档路由均引用 `library/document/index.vue`,文件分组不增加 URL 层级。
检索优化使用 `/retrieval/recall`、`/retrieval/question`、`/retrieval/dictionary`;
授权与集成使用 `/integration/chat-user`、`/integration/external-retrieval`。
分组不挂载页面组件,直接访问分组时重定向到首个子页。新增七个页面暂为占位 View。`setting`
Expand Down
2 changes: 1 addition & 1 deletion ui/src/router/admin/workspace/modules/knowledge-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const sharedKnowledgeRoutes: RouteRecordRaw[] = [
{
path: 'document',
name: 'workspace-shared-knowledge-document-list',
component: () => import('@/views/knowledge-detail/document/index.vue'),
component: () => import('@/views/knowledge-detail/library/document/index.vue'),
meta: { title: '文档', order: 10 },
},
],
Expand Down
6 changes: 3 additions & 3 deletions ui/src/router/admin/workspace/modules/knowledge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ export const knowledgeRoutes: RouteRecordRaw[] = [
{
path: 'document',
name: 'workspace-knowledge-document-list',
component: () => import('@/views/knowledge-detail/document/index.vue'),
component: () => import('@/views/knowledge-detail/library/document/index.vue'),
meta: { title: '文档', order: 10 },
},
{
path: 'image',
name: 'workspace-knowledge-image-list',
component: () => import('@/views/knowledge-detail/image/index.vue'),
component: () => import('@/views/knowledge-detail/library/image/index.vue'),
meta: { title: '图片', order: 20 },
},
{
path: 'tag',
name: 'workspace-knowledge-tag',
component: () => import('@/views/knowledge-detail/tag/index.vue'),
component: () => import('@/views/knowledge-detail/library/tag/index.vue'),
meta: { title: '标签管理', order: 30 },
},
],
Expand Down
3 changes: 3 additions & 0 deletions ui/src/styles/element-plus.scss
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@
--el-messagebox-border-radius: 12px;
--el-messagebox-font-size: 16px;
--el-messagebox-content-color: var(--el-text-color-primary);
&__container {
align-items: start;
}
&__headerbtn {
right: 20px;
top: 20px;
Expand Down
Loading
Loading