feat(client): enhance knowledge file upload with process configuration support
- Updated the `CreateKnowledgeFromFile` function to accept an optional `processConfig` parameter for per-upload parse configuration overrides. - Introduced the `KnowledgeProcessOverrides` type to define various parsing settings, including parser engine rules and chunking configurations. - Modified the API client and related components to handle the new process configuration, improving flexibility in knowledge file uploads. - Updated documentation and API specifications to reflect the new `process_config` parameter in the upload process. - Added a new `UploadConfirmHost` component to facilitate user confirmation for uploads, integrating with the updated upload logic. - Enhanced user experience by providing detailed configuration options during the upload process.
This commit is contained in:
@@ -4,6 +4,7 @@ import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { MessagePlugin, NotifyPlugin } from 'tdesign-vue-next'
|
||||
import ManualKnowledgeEditor from '@/components/manual-knowledge-editor.vue'
|
||||
import UploadConfirmHost from '@/components/UploadConfirmHost.vue'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { useSettingsStore } from '@/stores/settings'
|
||||
import { getCurrentUser, userInfoFromApi } from '@/api/auth'
|
||||
@@ -257,6 +258,7 @@ onUnmounted(() => {
|
||||
<div id="app">
|
||||
<RouterView />
|
||||
<ManualKnowledgeEditor />
|
||||
<UploadConfirmHost />
|
||||
</div>
|
||||
</t-config-provider>
|
||||
</template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { get, post, put, del, postUpload, getDown } from "../../utils/request";
|
||||
import type { KnowledgeProcessOverrides } from '@/types/knowledgeProcess';
|
||||
|
||||
// 知识库管理 API(列表、创建、获取、更新、删除、复制)
|
||||
export function listKnowledgeBases(params?: {
|
||||
@@ -160,23 +161,51 @@ export function togglePinKnowledgeBase(id: string) {
|
||||
|
||||
// 知识文件 API(基于具体知识库)
|
||||
// data.tag_id: 可选,指定知识所属的分类ID
|
||||
export function uploadKnowledgeFile(kbId: string, data: { file: File; tag_id?: string; [key: string]: any } = { file: new File([], '') }, onProgress?: (progressEvent: any) => void) {
|
||||
export function uploadKnowledgeFile(
|
||||
kbId: string,
|
||||
data: {
|
||||
file: File
|
||||
tag_id?: string
|
||||
fileName?: string
|
||||
process_config?: KnowledgeProcessOverrides | string
|
||||
[key: string]: any
|
||||
} = { file: new File([], '') },
|
||||
onProgress?: (progressEvent: any) => void,
|
||||
) {
|
||||
const formData = new FormData();
|
||||
Object.keys(data).forEach(key => {
|
||||
if (data[key] !== undefined) formData.append(key, data[key]);
|
||||
const value = data[key];
|
||||
if (value === undefined) return;
|
||||
if (key === 'process_config' && value && typeof value !== 'string') {
|
||||
formData.append(key, JSON.stringify(value));
|
||||
} else {
|
||||
formData.append(key, value);
|
||||
}
|
||||
});
|
||||
return postUpload(`/api/v1/knowledge-bases/${kbId}/knowledge/file`, formData, onProgress);
|
||||
}
|
||||
|
||||
// 从URL创建知识
|
||||
// data.tag_id: 可选,指定知识所属的分类ID
|
||||
export function createKnowledgeFromURL(kbId: string, data: { url: string; enable_multimodel?: boolean; tag_id?: string }) {
|
||||
export function createKnowledgeFromURL(
|
||||
kbId: string,
|
||||
data: { url: string; enable_multimodel?: boolean; tag_id?: string; process_config?: KnowledgeProcessOverrides },
|
||||
) {
|
||||
return post(`/api/v1/knowledge-bases/${kbId}/knowledge/url`, data);
|
||||
}
|
||||
|
||||
// 手工创建知识
|
||||
// data.tag_id: 可选,指定知识所属的分类ID
|
||||
export function createManualKnowledge(kbId: string, data: { title: string; content: string; status: string; tag_id?: string }) {
|
||||
export function createManualKnowledge(
|
||||
kbId: string,
|
||||
data: {
|
||||
title: string
|
||||
content: string
|
||||
status: string
|
||||
tag_id?: string
|
||||
process_config?: KnowledgeProcessOverrides
|
||||
},
|
||||
) {
|
||||
return post(`/api/v1/knowledge-bases/${kbId}/knowledge/manual`, data);
|
||||
}
|
||||
|
||||
@@ -215,7 +244,10 @@ export function getKnowledgeDetails(id: string, options?: { agent_id?: string })
|
||||
return get(qs ? `/api/v1/knowledge/${id}?${qs}` : `/api/v1/knowledge/${id}`);
|
||||
}
|
||||
|
||||
export function updateManualKnowledge(id: string, data: { title: string; content: string; status: string }) {
|
||||
export function updateManualKnowledge(
|
||||
id: string,
|
||||
data: { title: string; content: string; status: string; process_config?: KnowledgeProcessOverrides },
|
||||
) {
|
||||
return put(`/api/v1/knowledge/manual/${id}`, data);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
:placeholder="placeholderText"
|
||||
:disabled="disabled"
|
||||
:loading="loading"
|
||||
:status="status"
|
||||
filterable
|
||||
style="width: 100%;"
|
||||
>
|
||||
@@ -51,13 +52,15 @@ interface Props {
|
||||
selectedModelId?: string
|
||||
disabled?: boolean
|
||||
placeholder?: string
|
||||
status?: 'default' | 'success' | 'warning' | 'error'
|
||||
// 可选:外部传入的所有模型列表,如果提供则不调用API
|
||||
allModels?: ModelConfig[]
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
disabled: false,
|
||||
placeholder: ''
|
||||
placeholder: '',
|
||||
status: 'default',
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<script setup lang="ts">
|
||||
import UploadConfirmDialog from '@/views/knowledge/components/UploadConfirmDialog.vue'
|
||||
import { useUploadConfirmStore } from '@/stores/uploadConfirm'
|
||||
|
||||
const uploadConfirmStore = useUploadConfirmStore()
|
||||
|
||||
const handleConfirm = (payload: Parameters<typeof uploadConfirmStore.resolveConfirm>[0]) => {
|
||||
uploadConfirmStore.resolveConfirm(payload)
|
||||
}
|
||||
|
||||
const handleCancel = () => {
|
||||
uploadConfirmStore.rejectConfirm()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UploadConfirmDialog
|
||||
v-model:visible="uploadConfirmStore.visible"
|
||||
:mode="uploadConfirmStore.mode"
|
||||
:kb-info="uploadConfirmStore.kbInfo"
|
||||
:files="uploadConfirmStore.files"
|
||||
:urls="uploadConfirmStore.urls"
|
||||
:manual-preview="uploadConfirmStore.manual"
|
||||
:accept-file-types="uploadConfirmStore.acceptFileTypes"
|
||||
:supported-file-types="uploadConfirmStore.supportedFileTypes"
|
||||
@confirm="handleConfirm"
|
||||
@cancel="handleCancel"
|
||||
/>
|
||||
</template>
|
||||
@@ -3,7 +3,15 @@ import { ref, reactive, computed, watch, nextTick, onBeforeUnmount } from 'vue'
|
||||
import { marked } from 'marked'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
import { listKnowledgeBases, getKnowledgeDetails, createManualKnowledge, updateManualKnowledge } from '@/api/knowledge-base'
|
||||
import {
|
||||
listKnowledgeBases,
|
||||
getKnowledgeDetails,
|
||||
getKnowledgeBaseById,
|
||||
createManualKnowledge,
|
||||
updateManualKnowledge,
|
||||
} from '@/api/knowledge-base'
|
||||
import { useUploadConfirmStore } from '@/stores/uploadConfirm'
|
||||
import type { KnowledgeProcessOverrides } from '@/types/knowledgeProcess'
|
||||
import { sanitizeHTML, safeMarkdownToHTML } from '@/utils/security'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
@@ -24,6 +32,7 @@ interface KnowledgeDetailResponse {
|
||||
type ManualStatus = 'draft' | 'publish'
|
||||
|
||||
const uiStore = useUIStore()
|
||||
const uploadConfirmStore = useUploadConfirmStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
const visible = computed({
|
||||
@@ -576,11 +585,53 @@ const handleSave = async (targetStatus: ManualStatus) => {
|
||||
saving.value = true
|
||||
savingAction.value = targetStatus
|
||||
try {
|
||||
const payload: { title: string; content: string; status: string; tag_id?: string } = {
|
||||
const tagIdToUpload = uiStore.selectedTagId !== '__untagged__' ? uiStore.selectedTagId : undefined
|
||||
const payload: {
|
||||
title: string
|
||||
content: string
|
||||
status: string
|
||||
tag_id?: string
|
||||
process_config?: KnowledgeProcessOverrides
|
||||
} = {
|
||||
title: form.title.trim(),
|
||||
content: form.content,
|
||||
status: targetStatus,
|
||||
}
|
||||
if (tagIdToUpload) {
|
||||
payload.tag_id = tagIdToUpload
|
||||
}
|
||||
|
||||
if (targetStatus === 'publish') {
|
||||
let kbInfo: any
|
||||
try {
|
||||
const kbRes: any = await getKnowledgeBaseById(form.kbId)
|
||||
kbInfo = kbRes?.data
|
||||
} catch {
|
||||
MessagePlugin.error(t('manualEditor.error.fetchDetailFailed'))
|
||||
return
|
||||
}
|
||||
if (!kbInfo) {
|
||||
MessagePlugin.error(t('manualEditor.error.fetchDetailFailed'))
|
||||
return
|
||||
}
|
||||
try {
|
||||
const confirmResult = await uploadConfirmStore.open({
|
||||
mode: 'manual',
|
||||
kbInfo,
|
||||
manual: {
|
||||
kbId: form.kbId,
|
||||
knowledgeId: knowledgeId.value || undefined,
|
||||
title: payload.title,
|
||||
content: payload.content,
|
||||
tagId: tagIdToUpload,
|
||||
},
|
||||
})
|
||||
payload.process_config = confirmResult.processConfig
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
let response: any
|
||||
let knowledgeID = knowledgeId.value
|
||||
let kbId = form.kbId
|
||||
@@ -588,11 +639,6 @@ const handleSave = async (targetStatus: ManualStatus) => {
|
||||
if (mode.value === 'edit' && knowledgeId.value) {
|
||||
response = await updateManualKnowledge(knowledgeId.value, payload)
|
||||
} else {
|
||||
// 创建新知识时,从 store 获取当前选中的分类ID
|
||||
const tagIdToUpload = uiStore.selectedTagId !== '__untagged__' ? uiStore.selectedTagId : undefined
|
||||
if (tagIdToUpload) {
|
||||
payload.tag_id = tagIdToUpload
|
||||
}
|
||||
response = await createManualKnowledge(form.kbId, payload)
|
||||
knowledgeID = response?.data?.id || knowledgeID
|
||||
kbId = form.kbId
|
||||
|
||||
@@ -636,6 +636,74 @@ export default {
|
||||
chunkLoadFailed: 'Failed to load chunks',
|
||||
},
|
||||
|
||||
uploadConfirm: {
|
||||
title: 'Confirm Upload',
|
||||
fileList: 'Files to upload',
|
||||
parseConfig: 'Parse settings',
|
||||
configNav: 'Parse settings navigation',
|
||||
tabOverview: 'Overview',
|
||||
overviewTitle: 'Parse settings for this batch',
|
||||
overviewDesc: 'Click any row to edit',
|
||||
backToOverview: 'Back to overview',
|
||||
summaryChunkOverlapShort: 'Overlap {overlap}',
|
||||
summaryParentChildShort: 'Parent-child',
|
||||
summaryParserMode: 'Mode',
|
||||
summaryParserBuiltin: 'Built-in engine (default)',
|
||||
summaryChunkSize: 'Chunk size',
|
||||
summaryChunkOverlap: 'Overlap',
|
||||
summaryStrategy: 'Strategy',
|
||||
summaryStrategyDefault: 'Default',
|
||||
summaryParentChild: 'Parent-child',
|
||||
summaryParentChildOn: 'On (parent {parent} / child {child})',
|
||||
summaryParentChildOff: 'Off',
|
||||
summaryStatus: 'Status',
|
||||
summaryModel: 'Model',
|
||||
summaryQuestionCount: 'Questions per chunk',
|
||||
summaryQuestionCountValue: '{count}',
|
||||
summaryGraphTags: 'Relation types',
|
||||
summaryGraphTagsValue: '{count}',
|
||||
navChunkingSummary: 'Chunk {size}',
|
||||
statusOn: 'On',
|
||||
statusOff: 'Off',
|
||||
notSet: 'Not set',
|
||||
confirm: 'Upload and parse',
|
||||
cancel: 'Cancel',
|
||||
uploading: 'Uploading {current}/{total}',
|
||||
tabParser: 'Parser',
|
||||
tabChunking: 'Chunking',
|
||||
tabMultimodal: 'Multimodal',
|
||||
tabAsr: 'Audio',
|
||||
tabQuestion: 'Question generation',
|
||||
tabGraph: 'Knowledge graph',
|
||||
noFiles: 'Keep at least one file to upload',
|
||||
noItems: 'Add at least one file or URL',
|
||||
urlItemLabel: 'URL',
|
||||
urlAdded: 'URL added',
|
||||
urlDuplicate: 'This URL is already in the list',
|
||||
addUrl: 'Add',
|
||||
vlmModelRequired: 'This batch includes images. Enable multimodal and select a VLM model.',
|
||||
multimodalRequiredForImages: 'Off (batch includes images)',
|
||||
asrModelRequired: 'This batch includes audio. Enable ASR and select a speech recognition model.',
|
||||
asrRequiredForAudio: 'Off (batch includes audio)',
|
||||
vlmModelSelectRequired: 'Multimodal is enabled. Please select a VLM model.',
|
||||
asrModelSelectRequired: 'Speech recognition is enabled. Please select an ASR model.',
|
||||
continueAdd: 'Add more',
|
||||
addMoreFiles: 'Add more files',
|
||||
addMoreFolder: 'Add more from folder',
|
||||
filesAdded: 'Added {count} file(s)',
|
||||
filesAllDuplicate: 'Selected files are already in the list',
|
||||
titleUrl: 'Confirm URL import',
|
||||
titleManual: 'Confirm online publish',
|
||||
overviewDescUrl: 'The URL will be fetched and parsed after you confirm the settings',
|
||||
overviewDescManual: 'The document will be published and indexed after you confirm the settings',
|
||||
confirmUrl: 'Import and parse',
|
||||
confirmManual: 'Publish and parse',
|
||||
urlSource: 'Import source',
|
||||
manualSource: 'Document to publish',
|
||||
editUrl: 'Edit URL',
|
||||
manualCharCount: '{count} characters',
|
||||
},
|
||||
|
||||
knowledgeStages: {
|
||||
title: 'Processing pipeline',
|
||||
root: 'Knowledge processing',
|
||||
|
||||
@@ -642,6 +642,73 @@ export default {
|
||||
deleteSuccess: "지식이 성공적으로 삭제되었습니다!",
|
||||
chunkLoadFailed: "청크 로드 실패",
|
||||
},
|
||||
uploadConfirm: {
|
||||
title: "문서 업로드 확인",
|
||||
fileList: "업로드할 파일",
|
||||
parseConfig: "파싱 설정",
|
||||
configNav: "파싱 설정 탐색",
|
||||
tabOverview: "구성 개요",
|
||||
overviewTitle: "이번 배치 파싱 설정",
|
||||
overviewDesc: "항목을 클릭하여 설정을 수정하세요",
|
||||
backToOverview: "구성 개요로 돌아가기",
|
||||
summaryChunkOverlapShort: "겹침 {overlap}",
|
||||
summaryParentChildShort: "부모-자식 청킹",
|
||||
summaryParserMode: "모드",
|
||||
summaryParserBuiltin: "내장 엔진(기본)",
|
||||
summaryChunkSize: "청크 크기",
|
||||
summaryChunkOverlap: "겹침",
|
||||
summaryStrategy: "전략",
|
||||
summaryStrategyDefault: "기본",
|
||||
summaryParentChild: "부모-자식 청킹",
|
||||
summaryParentChildOn: "켜짐(부모 {parent} / 자식 {child})",
|
||||
summaryParentChildOff: "꺼짐",
|
||||
summaryStatus: "상태",
|
||||
summaryModel: "모델",
|
||||
summaryQuestionCount: "청크당 질문 수",
|
||||
summaryQuestionCountValue: "{count}개",
|
||||
summaryGraphTags: "관계 유형",
|
||||
summaryGraphTagsValue: "{count}개",
|
||||
navChunkingSummary: "청크 {size}",
|
||||
statusOn: "켜짐",
|
||||
statusOff: "꺼짐",
|
||||
notSet: "미설정",
|
||||
confirm: "업로드 및 파싱 확인",
|
||||
cancel: "취소",
|
||||
uploading: "업로드 중 {current}/{total}",
|
||||
tabParser: "파서",
|
||||
tabChunking: "청킹",
|
||||
tabMultimodal: "멀티모달",
|
||||
tabAsr: "오디오",
|
||||
tabQuestion: "질문 생성",
|
||||
tabGraph: "지식 그래프",
|
||||
noFiles: "업로드할 파일을 하나 이상 남겨 두세요",
|
||||
noItems: "파일 또는 URL을 하나 이상 추가하세요",
|
||||
urlItemLabel: "URL",
|
||||
urlAdded: "URL이 추가되었습니다",
|
||||
urlDuplicate: "이 URL은 이미 목록에 있습니다",
|
||||
addUrl: "추가",
|
||||
vlmModelRequired: "이 배치에 이미지가 포함되어 있습니다. 멀티모달을 활성화하고 VLM 모델을 선택하세요",
|
||||
multimodalRequiredForImages: "꺼짐(이 배치에 이미지 포함)",
|
||||
asrModelRequired: "이 배치에 오디오가 포함되어 있습니다. ASR을 활성화하고 음성 인식 모델을 선택하세요",
|
||||
asrRequiredForAudio: "꺼짐(이 배치에 오디오 포함)",
|
||||
vlmModelSelectRequired: "멀티모달이 활성화되었습니다. VLM 모델을 선택하세요",
|
||||
asrModelSelectRequired: "음성 인식이 활성화되었습니다. ASR 모델을 선택하세요",
|
||||
continueAdd: "계속 추가",
|
||||
addMoreFiles: "파일 더 추가",
|
||||
addMoreFolder: "폴더에서 더 추가",
|
||||
filesAdded: "{count}개 파일이 추가되었습니다",
|
||||
filesAllDuplicate: "선택한 파일이 이미 목록에 있습니다",
|
||||
titleUrl: "URL 가져오기 확인",
|
||||
titleManual: "온라인 편집 게시 확인",
|
||||
overviewDescUrl: "설정 확인 후 URL을 가져와 파싱합니다",
|
||||
overviewDescManual: "설정 확인 후 문서를 게시하고 인덱싱합니다",
|
||||
confirmUrl: "가져오기 및 파싱",
|
||||
confirmManual: "게시 및 파싱",
|
||||
urlSource: "가져오기 소스",
|
||||
manualSource: "게시할 문서",
|
||||
editUrl: "URL 수정",
|
||||
manualCharCount: "{count}자",
|
||||
},
|
||||
knowledgeStages: {
|
||||
title: "처리 파이프라인",
|
||||
root: "지식 처리",
|
||||
|
||||
@@ -606,6 +606,73 @@ export default {
|
||||
cancelParseSubmitted: 'Разбор остановлен',
|
||||
cancelParseFailed: 'Не удалось остановить, попробуйте позже'
|
||||
},
|
||||
uploadConfirm: {
|
||||
title: 'Подтверждение загрузки',
|
||||
fileList: 'Файлы для загрузки',
|
||||
parseConfig: 'Настройки разбора',
|
||||
configNav: 'Навигация по настройкам разбора',
|
||||
tabOverview: 'Обзор',
|
||||
overviewTitle: 'Настройки разбора для этой партии',
|
||||
overviewDesc: 'Нажмите на строку, чтобы изменить',
|
||||
backToOverview: 'Вернуться к обзору',
|
||||
summaryChunkOverlapShort: 'Перекрытие {overlap}',
|
||||
summaryParentChildShort: 'Родительско-дочернее',
|
||||
summaryParserMode: 'Режим',
|
||||
summaryParserBuiltin: 'Встроенный движок (по умолчанию)',
|
||||
summaryChunkSize: 'Размер чанка',
|
||||
summaryChunkOverlap: 'Перекрытие',
|
||||
summaryStrategy: 'Стратегия',
|
||||
summaryStrategyDefault: 'По умолчанию',
|
||||
summaryParentChild: 'Родительско-дочернее',
|
||||
summaryParentChildOn: 'Вкл. (родитель {parent} / дочерний {child})',
|
||||
summaryParentChildOff: 'Выкл.',
|
||||
summaryStatus: 'Статус',
|
||||
summaryModel: 'Модель',
|
||||
summaryQuestionCount: 'Вопросов на чанк',
|
||||
summaryQuestionCountValue: '{count}',
|
||||
summaryGraphTags: 'Типы связей',
|
||||
summaryGraphTagsValue: '{count}',
|
||||
navChunkingSummary: 'Чанк {size}',
|
||||
statusOn: 'Вкл.',
|
||||
statusOff: 'Выкл.',
|
||||
notSet: 'Не задано',
|
||||
confirm: 'Загрузить и обработать',
|
||||
cancel: 'Отмена',
|
||||
uploading: 'Загрузка {current}/{total}',
|
||||
tabParser: 'Парсер',
|
||||
tabChunking: 'Разбиение',
|
||||
tabMultimodal: 'Мультимодальность',
|
||||
tabAsr: 'Аудио',
|
||||
tabQuestion: 'Генерация вопросов',
|
||||
tabGraph: 'Граф знаний',
|
||||
noFiles: 'Оставьте хотя бы один файл для загрузки',
|
||||
noItems: 'Добавьте хотя бы один файл или URL',
|
||||
urlItemLabel: 'URL',
|
||||
urlAdded: 'URL добавлен',
|
||||
urlDuplicate: 'Этот URL уже в списке',
|
||||
addUrl: 'Добавить',
|
||||
vlmModelRequired: 'В партии есть изображения. Включите мультимодальность и выберите модель VLM.',
|
||||
multimodalRequiredForImages: 'Выкл. (в партии есть изображения)',
|
||||
asrModelRequired: 'В партии есть аудио. Включите ASR и выберите модель распознавания речи.',
|
||||
asrRequiredForAudio: 'Выкл. (в партии есть аудио)',
|
||||
vlmModelSelectRequired: 'Мультимодальность включена. Выберите модель VLM.',
|
||||
asrModelSelectRequired: 'Распознавание речи включено. Выберите модель ASR.',
|
||||
continueAdd: 'Добавить ещё',
|
||||
addMoreFiles: 'Добавить файлы',
|
||||
addMoreFolder: 'Добавить из папки',
|
||||
filesAdded: 'Добавлено файлов: {count}',
|
||||
filesAllDuplicate: 'Выбранные файлы уже в списке',
|
||||
titleUrl: 'Подтверждение импорта URL',
|
||||
titleManual: 'Подтверждение публикации',
|
||||
overviewDescUrl: 'После подтверждения настроек URL будет загружен и обработан',
|
||||
overviewDescManual: 'После подтверждения настроек документ будет опубликован и проиндексирован',
|
||||
confirmUrl: 'Импортировать и обработать',
|
||||
confirmManual: 'Опубликовать и обработать',
|
||||
urlSource: 'Источник импорта',
|
||||
manualSource: 'Документ для публикации',
|
||||
editUrl: 'Изменить URL',
|
||||
manualCharCount: '{count} символов',
|
||||
},
|
||||
knowledgeStages: {
|
||||
title: 'Конвейер обработки',
|
||||
root: 'Обработка знаний',
|
||||
|
||||
@@ -639,6 +639,73 @@ export default {
|
||||
deleteSuccess: "知识删除成功!",
|
||||
chunkLoadFailed: "分块加载失败",
|
||||
},
|
||||
uploadConfirm: {
|
||||
title: "上传文档确认",
|
||||
fileList: "待上传文件",
|
||||
parseConfig: "解析配置",
|
||||
configNav: "解析配置导航",
|
||||
tabOverview: "配置总览",
|
||||
overviewTitle: "本批次解析配置",
|
||||
overviewDesc: "点击任一项可修改配置",
|
||||
backToOverview: "返回配置总览",
|
||||
summaryChunkOverlapShort: "重叠 {overlap}",
|
||||
summaryParentChildShort: "父子分块",
|
||||
summaryParserMode: "模式",
|
||||
summaryParserBuiltin: "内置引擎(默认)",
|
||||
summaryChunkSize: "分块大小",
|
||||
summaryChunkOverlap: "重叠",
|
||||
summaryStrategy: "策略",
|
||||
summaryStrategyDefault: "默认",
|
||||
summaryParentChild: "父子分块",
|
||||
summaryParentChildOn: "已开启(父 {parent} / 子 {child})",
|
||||
summaryParentChildOff: "未开启",
|
||||
summaryStatus: "状态",
|
||||
summaryModel: "模型",
|
||||
summaryQuestionCount: "每块问题数",
|
||||
summaryQuestionCountValue: "{count} 个",
|
||||
summaryGraphTags: "关系类型",
|
||||
summaryGraphTagsValue: "{count} 个",
|
||||
navChunkingSummary: "分块 {size}",
|
||||
statusOn: "已开启",
|
||||
statusOff: "未开启",
|
||||
notSet: "未设置",
|
||||
confirm: "确认上传并解析",
|
||||
cancel: "取消",
|
||||
uploading: "正在上传 {current}/{total}",
|
||||
tabParser: "解析引擎",
|
||||
tabChunking: "分块",
|
||||
tabMultimodal: "多模态",
|
||||
tabAsr: "音频",
|
||||
tabQuestion: "问题生成",
|
||||
tabGraph: "图谱",
|
||||
noFiles: "请至少保留一个待上传文件",
|
||||
noItems: "请至少添加一个文件或 URL",
|
||||
urlItemLabel: "URL",
|
||||
urlAdded: "已添加 URL",
|
||||
urlDuplicate: "该 URL 已在列表中",
|
||||
addUrl: "添加",
|
||||
vlmModelRequired: "本批次包含图片,请启用多模态并选择 VLM 模型",
|
||||
multimodalRequiredForImages: "未开启(本批次含图片)",
|
||||
asrModelRequired: "本批次包含音频,请启用 ASR 并选择语音识别模型",
|
||||
asrRequiredForAudio: "未开启(本批次含音频)",
|
||||
vlmModelSelectRequired: "已启用多模态,请选择 VLM 模型",
|
||||
asrModelSelectRequired: "已启用语音识别,请选择 ASR 模型",
|
||||
continueAdd: "继续添加",
|
||||
addMoreFiles: "继续添加文件",
|
||||
addMoreFolder: "继续添加文件夹",
|
||||
filesAdded: "已添加 {count} 个文件",
|
||||
filesAllDuplicate: "所选文件已在列表中",
|
||||
titleUrl: "URL 导入确认",
|
||||
titleManual: "在线编辑发布确认",
|
||||
overviewDescUrl: "确认解析配置后将抓取并解析该 URL",
|
||||
overviewDescManual: "确认解析配置后将发布并索引该文档",
|
||||
confirmUrl: "确认导入并解析",
|
||||
confirmManual: "确认发布并解析",
|
||||
urlSource: "导入来源",
|
||||
manualSource: "待发布文档",
|
||||
editUrl: "修改 URL",
|
||||
manualCharCount: "{count} 个字符",
|
||||
},
|
||||
knowledgeStages: {
|
||||
title: "处理流水线",
|
||||
root: "知识处理",
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import type { KnowledgeProcessOverrides } from '@/types/knowledgeProcess'
|
||||
|
||||
export type UploadConfirmMode = 'file' | 'url' | 'manual'
|
||||
|
||||
export interface UploadConfirmManualSource {
|
||||
kbId: string
|
||||
knowledgeId?: string
|
||||
title: string
|
||||
content: string
|
||||
tagId?: string
|
||||
}
|
||||
|
||||
export interface UploadConfirmResult {
|
||||
processConfig: KnowledgeProcessOverrides
|
||||
mode: UploadConfirmMode
|
||||
files?: File[]
|
||||
urls?: string[]
|
||||
manual?: UploadConfirmManualSource
|
||||
}
|
||||
|
||||
export interface OpenUploadConfirmOptions {
|
||||
mode: UploadConfirmMode
|
||||
kbInfo: any
|
||||
files?: File[]
|
||||
urls?: string[]
|
||||
manual?: UploadConfirmManualSource
|
||||
acceptFileTypes?: string
|
||||
supportedFileTypes?: string[]
|
||||
}
|
||||
|
||||
export const useUploadConfirmStore = defineStore('uploadConfirm', {
|
||||
state: () => ({
|
||||
visible: false,
|
||||
mode: 'file' as UploadConfirmMode,
|
||||
kbInfo: null as any,
|
||||
files: [] as File[],
|
||||
urls: [] as string[],
|
||||
manual: null as UploadConfirmManualSource | null,
|
||||
acceptFileTypes: '',
|
||||
supportedFileTypes: [] as string[],
|
||||
pendingResolve: null as ((value: UploadConfirmResult) => void) | null,
|
||||
pendingReject: null as (() => void) | null,
|
||||
}),
|
||||
|
||||
actions: {
|
||||
open(options: OpenUploadConfirmOptions): Promise<UploadConfirmResult> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.visible = true
|
||||
this.mode = options.mode
|
||||
this.kbInfo = options.kbInfo
|
||||
this.files = options.files ? [...options.files] : []
|
||||
this.urls = options.urls ? [...options.urls] : []
|
||||
this.manual = options.manual || null
|
||||
this.acceptFileTypes = options.acceptFileTypes || ''
|
||||
this.supportedFileTypes = options.supportedFileTypes ? [...options.supportedFileTypes] : []
|
||||
this.pendingResolve = resolve
|
||||
this.pendingReject = reject
|
||||
})
|
||||
},
|
||||
|
||||
resolveConfirm(payload: UploadConfirmResult) {
|
||||
this.pendingResolve?.(payload)
|
||||
this.reset()
|
||||
},
|
||||
|
||||
rejectConfirm() {
|
||||
this.pendingReject?.()
|
||||
this.reset()
|
||||
},
|
||||
|
||||
reset() {
|
||||
this.visible = false
|
||||
this.mode = 'file'
|
||||
this.kbInfo = null
|
||||
this.files = []
|
||||
this.urls = []
|
||||
this.manual = null
|
||||
this.acceptFileTypes = ''
|
||||
this.supportedFileTypes = []
|
||||
this.pendingResolve = null
|
||||
this.pendingReject = null
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,66 @@
|
||||
/** Matches backend types.KnowledgeProcessOverrides (snake_case JSON). */
|
||||
|
||||
export interface ParserEngineRule {
|
||||
file_types: string[]
|
||||
engine: string
|
||||
}
|
||||
|
||||
export interface ChunkingConfigOverride {
|
||||
chunk_size?: number
|
||||
chunk_overlap?: number
|
||||
separators?: string[]
|
||||
enable_multimodal?: boolean
|
||||
parser_engine_rules?: ParserEngineRule[]
|
||||
enable_parent_child?: boolean
|
||||
parent_chunk_size?: number
|
||||
child_chunk_size?: number
|
||||
strategy?: string
|
||||
token_limit?: number
|
||||
languages?: string[]
|
||||
}
|
||||
|
||||
export interface VLMConfigOverride {
|
||||
enabled?: boolean
|
||||
model_id?: string
|
||||
}
|
||||
|
||||
export interface ASRConfigOverride {
|
||||
enabled?: boolean
|
||||
model_id?: string
|
||||
language?: string
|
||||
}
|
||||
|
||||
export interface QuestionGenerationConfigOverride {
|
||||
enabled?: boolean
|
||||
question_count?: number
|
||||
}
|
||||
|
||||
export interface GraphNodeOverride {
|
||||
name: string
|
||||
attributes?: string[]
|
||||
}
|
||||
|
||||
export interface GraphRelationOverride {
|
||||
node1: string
|
||||
node2: string
|
||||
type: string
|
||||
}
|
||||
|
||||
export interface ExtractConfigOverride {
|
||||
enabled?: boolean
|
||||
text?: string
|
||||
tags?: string[]
|
||||
nodes?: GraphNodeOverride[]
|
||||
relations?: GraphRelationOverride[]
|
||||
}
|
||||
|
||||
export interface KnowledgeProcessOverrides {
|
||||
parser_engine_rules?: ParserEngineRule[]
|
||||
chunking_config?: ChunkingConfigOverride
|
||||
enable_multimodel?: boolean
|
||||
vlm_config?: VLMConfigOverride
|
||||
asr_config?: ASRConfigOverride
|
||||
question_generation_config?: QuestionGenerationConfigOverride
|
||||
graph_enabled?: boolean
|
||||
extract_config?: ExtractConfigOverride
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, onUnmounted, watch, reactive, computed, nextTick, h, type ComponentPublicInstance } from "vue";
|
||||
import { MessagePlugin, Icon as TIcon } from "tdesign-vue-next";
|
||||
import { ref, onMounted, onUnmounted, watch, reactive, computed, nextTick, type ComponentPublicInstance } from "vue";
|
||||
import { MessagePlugin } from "tdesign-vue-next";
|
||||
import DocContent from "@/components/doc-content.vue";
|
||||
import KnowledgeProcessingTimeline from "@/components/knowledge-processing-timeline.vue";
|
||||
import useKnowledgeBase from '@/hooks/useKnowledgeBase';
|
||||
@@ -42,6 +42,9 @@ import { knowledgeSpansPayloadHasTrace } from '@/utils/knowledgeTrace';
|
||||
import FAQEntryManager from './components/FAQEntryManager.vue';
|
||||
import DocumentListView from './components/DocumentListView.vue';
|
||||
import DocumentBatchBar from './components/DocumentBatchBar.vue';
|
||||
import KbUploadSourceDropdown from './components/KbUploadSourceDropdown.vue';
|
||||
import type { KnowledgeProcessOverrides } from '@/types/knowledgeProcess';
|
||||
import { useUploadConfirmStore, type UploadConfirmResult } from '@/stores/uploadConfirm';
|
||||
import WikiBrowser from './wiki/WikiBrowser.vue';
|
||||
import { getWikiStats } from '@/api/wiki';
|
||||
import {
|
||||
@@ -51,15 +54,14 @@ import {
|
||||
} from './wikiStatusRefresh';
|
||||
import { listMoveTargets, moveKnowledge, getKnowledgeMoveProgress } from '@/api/knowledge-base';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { formatStringDate, kbFileTypeVerification } from '@/utils';
|
||||
import { formatStringDate } from '@/utils';
|
||||
import { formatFileSize } from '@/utils/files';
|
||||
import type { ParserEngineInfo } from '@/api/system';
|
||||
const route = useRoute();
|
||||
const { t } = useI18n();
|
||||
const kbId = computed(() => (route.params as any).kbId as string || '');
|
||||
const kbInfo = ref<any>(null);
|
||||
const uploadInputRef = ref<HTMLInputElement | null>(null);
|
||||
const folderUploadInputRef = ref<HTMLInputElement | null>(null);
|
||||
const uploadSourceRef = ref<InstanceType<typeof KbUploadSourceDropdown> | null>(null);
|
||||
const uploading = ref(false);
|
||||
const kbLoading = ref(false);
|
||||
const docListLoading = ref(true);
|
||||
@@ -984,7 +986,9 @@ const handleOpenURLImportDialog = (event: CustomEvent) => {
|
||||
const eventKbId = event.detail.kbId;
|
||||
console.log('接收到URL导入对话框打开事件,知识库ID:', eventKbId, '当前知识库ID:', kbId.value);
|
||||
if (eventKbId && eventKbId === kbId.value && !isFAQ.value) {
|
||||
urlDialogVisible.value = true;
|
||||
if (ensureDocumentKbReady()) {
|
||||
uploadSourceRef.value?.openUrlDialog();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1352,32 +1356,6 @@ const documentTitle = computed(() => {
|
||||
return t('knowledgeEditor.document.title');
|
||||
});
|
||||
|
||||
// 文档操作下拉菜单选项
|
||||
const documentActionOptions = computed(() => [
|
||||
{ content: t('upload.uploadDocument'), value: 'upload', prefixIcon: () => h(TIcon, { name: 'upload', size: '16px' }) },
|
||||
{ content: t('upload.uploadFolder'), value: 'uploadFolder', prefixIcon: () => h(TIcon, { name: 'folder-add', size: '16px' }) },
|
||||
{ content: t('knowledgeBase.importURL'), value: 'importURL', prefixIcon: () => h(TIcon, { name: 'link', size: '16px' }) },
|
||||
{ content: t('upload.onlineEdit'), value: 'manualCreate', prefixIcon: () => h(TIcon, { name: 'edit', size: '16px' }) },
|
||||
]);
|
||||
|
||||
// 处理文档操作下拉菜单选择
|
||||
const handleDocumentActionSelect = (data: { value: string }) => {
|
||||
switch (data.value) {
|
||||
case 'upload':
|
||||
handleDocumentUploadClick();
|
||||
break;
|
||||
case 'uploadFolder':
|
||||
handleFolderUploadClick();
|
||||
break;
|
||||
case 'importURL':
|
||||
handleURLImportClick();
|
||||
break;
|
||||
case 'manualCreate':
|
||||
handleManualCreate();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const ensureDocumentKbReady = () => {
|
||||
if (isFAQ.value) {
|
||||
MessagePlugin.warning(t('knowledgeBase.operationNotSupportedForType'));
|
||||
@@ -1406,338 +1384,147 @@ const ensureDocumentKbReady = () => {
|
||||
};
|
||||
|
||||
|
||||
const handleDocumentUploadClick = () => {
|
||||
if (!ensureDocumentKbReady()) return;
|
||||
uploadInputRef.value?.click();
|
||||
const IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
|
||||
const AUDIO_EXTENSIONS = ['mp3', 'wav', 'm4a', 'flac', 'ogg'];
|
||||
|
||||
const uploadConfirmStore = useUploadConfirmStore();
|
||||
|
||||
const getFolderUploadFileName = (file: File) => {
|
||||
const relativePath = (file as any).webkitRelativePath;
|
||||
if (!relativePath) return undefined;
|
||||
const pathParts = relativePath.split('/');
|
||||
if (pathParts.length <= 2) return undefined;
|
||||
const subPath = pathParts.slice(1, -1).join('/');
|
||||
return `${subPath}/${file.name}`;
|
||||
};
|
||||
|
||||
const handleFolderUploadClick = () => {
|
||||
if (!ensureDocumentKbReady()) return;
|
||||
folderUploadInputRef.value?.click();
|
||||
};
|
||||
|
||||
const resetUploadInput = () => {
|
||||
if (uploadInputRef.value) {
|
||||
uploadInputRef.value.value = '';
|
||||
}
|
||||
};
|
||||
|
||||
const handleDocumentUpload = async (event: Event) => {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const files = input?.files;
|
||||
if (!files || files.length === 0) return;
|
||||
|
||||
const targetKbId = kbId.value;
|
||||
if (!targetKbId) {
|
||||
MessagePlugin.error(t('error.missingKbId'));
|
||||
resetUploadInput();
|
||||
return;
|
||||
}
|
||||
|
||||
const vlmEnabled = kbInfo.value?.vlm_config?.enabled || false;
|
||||
const asrEnabled = kbInfo.value?.asr_config?.enabled || false;
|
||||
const dynamicTypes = supportedFileTypes.value.size > 0 ? supportedFileTypes.value : undefined
|
||||
const validFiles: File[] = [];
|
||||
let skippedCount = 0;
|
||||
let imageFilteredCount = 0;
|
||||
let videoFilteredCount = 0;
|
||||
let audioFilteredCount = 0;
|
||||
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = files[i];
|
||||
const fileExt = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase();
|
||||
const imageTypes = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
|
||||
const videoTypes = ['mp4', 'mov', 'avi', 'mkv', 'webm', 'wmv', 'flv'];
|
||||
const audioTypes = ['mp3', 'wav', 'm4a', 'flac', 'ogg'];
|
||||
|
||||
if (videoTypes.includes(fileExt)) {
|
||||
videoFilteredCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!vlmEnabled) {
|
||||
if (imageTypes.includes(fileExt)) {
|
||||
imageFilteredCount++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!asrEnabled && audioTypes.includes(fileExt)) {
|
||||
audioFilteredCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!kbFileTypeVerification(file, files.length > 1, dynamicTypes)) {
|
||||
validFiles.push(file);
|
||||
const showUploadResultMessages = (
|
||||
successCount: number,
|
||||
failCount: number,
|
||||
totalCount: number,
|
||||
mode: 'document' | 'folder',
|
||||
) => {
|
||||
if (mode === 'folder') {
|
||||
if (failCount === 0) {
|
||||
MessagePlugin.success(t('knowledgeBase.uploadAllSuccess', { count: successCount }));
|
||||
} else if (successCount > 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.uploadPartialSuccess', { success: successCount, fail: failCount }));
|
||||
} else {
|
||||
skippedCount++;
|
||||
MessagePlugin.error(t('knowledgeBase.uploadAllFailed'));
|
||||
}
|
||||
}
|
||||
|
||||
if (imageFilteredCount > 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.imagesFilteredNoVLM', { count: imageFilteredCount }));
|
||||
}
|
||||
if (videoFilteredCount > 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.videosFilteredNoVLM', { count: videoFilteredCount }));
|
||||
}
|
||||
if (audioFilteredCount > 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.audiosFilteredNoASR', { count: audioFilteredCount }));
|
||||
}
|
||||
|
||||
if (validFiles.length === 0) {
|
||||
if (skippedCount > 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.allFilesSkippedNoEngine'));
|
||||
}
|
||||
resetUploadInput();
|
||||
return;
|
||||
}
|
||||
if (skippedCount > 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.filesSkippedNoEngine', { count: skippedCount }));
|
||||
}
|
||||
|
||||
let successCount = 0;
|
||||
let failCount = 0;
|
||||
const totalCount = validFiles.length;
|
||||
|
||||
// 获取当前选中的分类ID(如果不是"未分类"则传递)
|
||||
const tagIdToUpload = selectedTagId.value !== '__untagged__' ? selectedTagId.value : undefined;
|
||||
|
||||
for (const file of validFiles) {
|
||||
try {
|
||||
const responseData: any = await uploadKnowledgeFile(targetKbId, { file, tag_id: tagIdToUpload });
|
||||
const isSuccess = responseData?.success || responseData?.code === 200 || responseData?.status === 'success' || (!responseData?.error && responseData);
|
||||
if (isSuccess) {
|
||||
successCount++;
|
||||
} else {
|
||||
failCount++;
|
||||
let errorMessage = t('knowledgeBase.uploadFailed');
|
||||
if (responseData?.error?.message) {
|
||||
errorMessage = responseData.error.message;
|
||||
} else if (responseData?.message) {
|
||||
errorMessage = responseData.message;
|
||||
}
|
||||
if (responseData?.code === 'duplicate_file' || responseData?.error?.code === 'duplicate_file') {
|
||||
errorMessage = t('knowledgeBase.fileExists');
|
||||
}
|
||||
if (totalCount === 1) {
|
||||
MessagePlugin.error(errorMessage);
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
failCount++;
|
||||
let errorMessage = error?.error?.message || error?.message || t('knowledgeBase.uploadFailed');
|
||||
if (error?.code === 'duplicate_file') {
|
||||
errorMessage = t('knowledgeBase.fileExists');
|
||||
}
|
||||
if (totalCount === 1) {
|
||||
MessagePlugin.error(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 显示上传结果
|
||||
if (successCount > 0) {
|
||||
window.dispatchEvent(new CustomEvent('knowledgeFileUploaded', {
|
||||
detail: { kbId: targetKbId }
|
||||
}));
|
||||
}
|
||||
|
||||
if (totalCount === 1) {
|
||||
if (successCount === 1) {
|
||||
MessagePlugin.success(t('knowledgeBase.uploadSuccess'));
|
||||
}
|
||||
} else {
|
||||
if (failCount === 0) {
|
||||
MessagePlugin.success(t('knowledgeBase.allUploadSuccess', { count: successCount }));
|
||||
} else if (successCount > 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.partialUploadSuccess', { success: successCount, fail: failCount }));
|
||||
} else {
|
||||
MessagePlugin.error(t('knowledgeBase.allUploadFailed', { count: failCount }));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
resetUploadInput();
|
||||
if (failCount === 0) {
|
||||
MessagePlugin.success(t('knowledgeBase.allUploadSuccess', { count: successCount }));
|
||||
} else if (successCount > 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.partialUploadSuccess', { success: successCount, fail: failCount }));
|
||||
} else {
|
||||
MessagePlugin.error(t('knowledgeBase.allUploadFailed', { count: failCount }));
|
||||
}
|
||||
};
|
||||
|
||||
// 处理文件夹上传
|
||||
const handleFolderUpload = async (event: Event) => {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const files = input?.files;
|
||||
if (!files || files.length === 0) return;
|
||||
|
||||
const executeUploadBatch = async (
|
||||
files: File[],
|
||||
options: { processConfig?: KnowledgeProcessOverrides } = {},
|
||||
) => {
|
||||
const targetKbId = kbId.value;
|
||||
if (!targetKbId) {
|
||||
MessagePlugin.error(t('error.missingKbId'));
|
||||
if (input) input.value = '';
|
||||
return;
|
||||
if (!targetKbId || files.length === 0) {
|
||||
return { successCount: 0, failCount: files.length };
|
||||
}
|
||||
|
||||
const vlmEnabled = kbInfo.value?.vlm_config?.enabled || false;
|
||||
const asrEnabled = kbInfo.value?.asr_config?.enabled || false;
|
||||
const dynamicTypes = supportedFileTypes.value.size > 0 ? supportedFileTypes.value : undefined
|
||||
|
||||
const validFiles: File[] = [];
|
||||
let hiddenFileCount = 0;
|
||||
let imageFilteredCount = 0;
|
||||
let videoFilteredCount = 0;
|
||||
let audioFilteredCount = 0;
|
||||
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = files[i];
|
||||
const relativePath = (file as any).webkitRelativePath || file.name;
|
||||
|
||||
const pathParts = relativePath.split('/');
|
||||
const hasHiddenComponent = pathParts.some((part: string) => part.startsWith('.'));
|
||||
if (hasHiddenComponent) {
|
||||
hiddenFileCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
const fileExt = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase();
|
||||
const imageTypes = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
|
||||
const videoTypes = ['mp4', 'mov', 'avi', 'mkv', 'webm', 'wmv', 'flv'];
|
||||
const audioTypes = ['mp3', 'wav', 'm4a', 'flac', 'ogg'];
|
||||
|
||||
if (videoTypes.includes(fileExt)) {
|
||||
videoFilteredCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!vlmEnabled) {
|
||||
if (imageTypes.includes(fileExt)) {
|
||||
imageFilteredCount++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!asrEnabled && audioTypes.includes(fileExt)) {
|
||||
audioFilteredCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!kbFileTypeVerification(file, true, dynamicTypes)) {
|
||||
validFiles.push(file);
|
||||
}
|
||||
}
|
||||
|
||||
if (imageFilteredCount > 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.imagesFilteredNoVLM', { count: imageFilteredCount }));
|
||||
}
|
||||
if (videoFilteredCount > 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.videosFilteredNoVLM', { count: videoFilteredCount }));
|
||||
}
|
||||
if (audioFilteredCount > 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.audiosFilteredNoASR', { count: audioFilteredCount }));
|
||||
}
|
||||
|
||||
if (validFiles.length === 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.noValidFilesInFolder', { total: files.length }));
|
||||
if (input) input.value = '';
|
||||
return;
|
||||
}
|
||||
MessagePlugin.info(t('knowledgeBase.uploadingFolder', { total: validFiles.length }));
|
||||
|
||||
// 批量上传
|
||||
const tagIdToUpload = selectedTagId.value !== '__untagged__' ? selectedTagId.value : undefined;
|
||||
let successCount = 0;
|
||||
let failCount = 0;
|
||||
const tagIdToUpload = selectedTagId.value !== '__untagged__' ? selectedTagId.value : undefined;
|
||||
|
||||
for (const file of validFiles) {
|
||||
const relativePath = (file as any).webkitRelativePath;
|
||||
let fileName = file.name;
|
||||
if (relativePath) {
|
||||
const pathParts = relativePath.split('/');
|
||||
if (pathParts.length > 2) {
|
||||
const subPath = pathParts.slice(1, -1).join('/');
|
||||
fileName = `${subPath}/${file.name}`;
|
||||
}
|
||||
}
|
||||
const totalCount = files.length;
|
||||
const hasFolderPaths = files.some((file) => {
|
||||
const relativePath = (file as File & { webkitRelativePath?: string }).webkitRelativePath;
|
||||
return !!relativePath && relativePath.split('/').length > 2;
|
||||
});
|
||||
|
||||
for (const file of files) {
|
||||
try {
|
||||
await uploadKnowledgeFile(targetKbId, { file, fileName, tag_id: tagIdToUpload });
|
||||
successCount++;
|
||||
const uploadData: {
|
||||
file: File
|
||||
tag_id?: string
|
||||
fileName?: string
|
||||
process_config?: KnowledgeProcessOverrides
|
||||
} = { file, tag_id: tagIdToUpload };
|
||||
|
||||
const fileName = getFolderUploadFileName(file);
|
||||
if (fileName) uploadData.fileName = fileName;
|
||||
if (options.processConfig) {
|
||||
uploadData.process_config = options.processConfig;
|
||||
}
|
||||
|
||||
const responseData: any = await uploadKnowledgeFile(targetKbId, uploadData);
|
||||
const isSuccess = responseData?.success || responseData?.code === 200 || responseData?.status === 'success' || (!responseData?.error && responseData);
|
||||
if (isSuccess) {
|
||||
successCount++;
|
||||
} else {
|
||||
failCount++;
|
||||
if (totalCount === 1) {
|
||||
let errorMessage = t('knowledgeBase.uploadFailed');
|
||||
if (responseData?.error?.message) {
|
||||
errorMessage = responseData.error.message;
|
||||
} else if (responseData?.message) {
|
||||
errorMessage = responseData.message;
|
||||
}
|
||||
if (responseData?.code === 'duplicate_file' || responseData?.error?.code === 'duplicate_file') {
|
||||
errorMessage = t('knowledgeBase.fileExists');
|
||||
}
|
||||
MessagePlugin.error(errorMessage);
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
failCount++;
|
||||
if (totalCount === 1) {
|
||||
let errorMessage = error?.error?.message || error?.message || t('knowledgeBase.uploadFailed');
|
||||
if (error?.code === 'duplicate_file') {
|
||||
errorMessage = t('knowledgeBase.fileExists');
|
||||
}
|
||||
MessagePlugin.error(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (successCount > 0) {
|
||||
window.dispatchEvent(new CustomEvent('knowledgeFileUploaded', {
|
||||
detail: { kbId: targetKbId }
|
||||
detail: { kbId: targetKbId },
|
||||
}));
|
||||
}
|
||||
|
||||
if (failCount === 0) {
|
||||
MessagePlugin.success(t('knowledgeBase.uploadAllSuccess', { count: successCount }));
|
||||
} else if (successCount > 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.uploadPartialSuccess', { success: successCount, fail: failCount }));
|
||||
} else {
|
||||
MessagePlugin.error(t('knowledgeBase.uploadAllFailed'));
|
||||
}
|
||||
|
||||
if (input) input.value = '';
|
||||
showUploadResultMessages(successCount, failCount, totalCount, hasFolderPaths ? 'folder' : 'document');
|
||||
return { successCount, failCount };
|
||||
};
|
||||
|
||||
const handleManualCreate = () => {
|
||||
if (!ensureDocumentKbReady()) return;
|
||||
uiStore.openManualEditor({
|
||||
mode: 'create',
|
||||
kbId: kbId.value,
|
||||
status: 'draft',
|
||||
onSuccess: manualEditorSuccess,
|
||||
});
|
||||
};
|
||||
|
||||
// URL 导入相关
|
||||
const urlDialogVisible = ref(false);
|
||||
const urlInputValue = ref('');
|
||||
const urlImporting = ref(false);
|
||||
|
||||
const handleURLImportClick = () => {
|
||||
if (!ensureDocumentKbReady()) return;
|
||||
urlInputValue.value = '';
|
||||
urlDialogVisible.value = true;
|
||||
};
|
||||
|
||||
const handleURLImportCancel = () => {
|
||||
urlDialogVisible.value = false;
|
||||
urlInputValue.value = '';
|
||||
};
|
||||
|
||||
const handleURLImportConfirm = async () => {
|
||||
const url = urlInputValue.value.trim();
|
||||
if (!url) {
|
||||
MessagePlugin.warning(t('knowledgeBase.urlRequired'));
|
||||
return;
|
||||
}
|
||||
|
||||
// 简单的URL格式验证
|
||||
try {
|
||||
new URL(url);
|
||||
} catch (error) {
|
||||
MessagePlugin.warning(t('knowledgeBase.invalidURL'));
|
||||
return;
|
||||
}
|
||||
|
||||
const executeUrlImport = async (url: string, processConfig?: KnowledgeProcessOverrides) => {
|
||||
const targetKbId = kbId.value;
|
||||
if (!targetKbId) {
|
||||
MessagePlugin.error(t('error.missingKbId'));
|
||||
return;
|
||||
}
|
||||
|
||||
urlImporting.value = true;
|
||||
const tagIdToUpload = selectedTagId.value !== '__untagged__' ? selectedTagId.value : undefined;
|
||||
try {
|
||||
// 获取当前选中的分类ID
|
||||
const tagIdToUpload = selectedTagId.value !== '__untagged__' ? selectedTagId.value : undefined;
|
||||
const responseData: any = await createKnowledgeFromURL(targetKbId, { url, tag_id: tagIdToUpload });
|
||||
const responseData: any = await createKnowledgeFromURL(targetKbId, {
|
||||
url,
|
||||
tag_id: tagIdToUpload,
|
||||
process_config: processConfig,
|
||||
});
|
||||
window.dispatchEvent(new CustomEvent('knowledgeFileUploaded', {
|
||||
detail: { kbId: targetKbId }
|
||||
detail: { kbId: targetKbId },
|
||||
}));
|
||||
const isSuccess = responseData?.success || responseData?.code === 200 || responseData?.status === 'success' || (!responseData?.error && responseData);
|
||||
if (isSuccess) {
|
||||
MessagePlugin.success(t('knowledgeBase.urlImportSuccess'));
|
||||
urlDialogVisible.value = false;
|
||||
urlInputValue.value = '';
|
||||
} else {
|
||||
let errorMessage = t('knowledgeBase.urlImportFailed');
|
||||
if (responseData?.error?.message) {
|
||||
@@ -1756,11 +1543,73 @@ const handleURLImportConfirm = async () => {
|
||||
errorMessage = t('knowledgeBase.urlExists');
|
||||
}
|
||||
MessagePlugin.error(errorMessage);
|
||||
} finally {
|
||||
urlImporting.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleUploadConfirmResult = async (result: UploadConfirmResult) => {
|
||||
if (result.mode === 'manual') {
|
||||
return;
|
||||
}
|
||||
|
||||
const files = result.files || [];
|
||||
const urls = result.urls || [];
|
||||
const processConfig = result.processConfig;
|
||||
|
||||
if (files.length > 0) {
|
||||
const hasFolderPaths = files.some((file) => {
|
||||
const relativePath = (file as File & { webkitRelativePath?: string }).webkitRelativePath;
|
||||
return !!relativePath && relativePath.split('/').length > 2;
|
||||
});
|
||||
if (hasFolderPaths) {
|
||||
MessagePlugin.info(t('knowledgeBase.uploadingFolder', { total: files.length }));
|
||||
}
|
||||
await executeUploadBatch(files, { processConfig });
|
||||
}
|
||||
|
||||
for (const url of urls) {
|
||||
await executeUrlImport(url, processConfig);
|
||||
}
|
||||
};
|
||||
|
||||
const openUploadConfirmDialog = async (files: File[], urls: string[] = []) => {
|
||||
if (!kbInfo.value) return;
|
||||
if (files.length === 0 && urls.length === 0) return;
|
||||
try {
|
||||
const result = await uploadConfirmStore.open({
|
||||
mode: 'file',
|
||||
kbInfo: kbInfo.value,
|
||||
files,
|
||||
urls,
|
||||
acceptFileTypes: acceptFileTypes.value,
|
||||
supportedFileTypes: [...supportedFileTypes.value],
|
||||
});
|
||||
await handleUploadConfirmResult(result);
|
||||
} catch {
|
||||
// cancelled
|
||||
}
|
||||
};
|
||||
|
||||
const handleUploadSourceFiles = (files: File[]) => {
|
||||
if (!ensureDocumentKbReady()) return;
|
||||
if (files.length === 0) return;
|
||||
openUploadConfirmDialog(files);
|
||||
};
|
||||
|
||||
const handleUploadSourceUrl = (url: string) => {
|
||||
if (!ensureDocumentKbReady()) return;
|
||||
openUploadConfirmDialog([], [url]);
|
||||
};
|
||||
|
||||
const handleManualCreate = () => {
|
||||
if (!ensureDocumentKbReady()) return;
|
||||
uiStore.openManualEditor({
|
||||
mode: 'create',
|
||||
kbId: kbId.value,
|
||||
status: 'draft',
|
||||
onSuccess: manualEditorSuccess,
|
||||
});
|
||||
};
|
||||
|
||||
const handleOpenKBSettings = () => {
|
||||
if (!kbId.value) {
|
||||
MessagePlugin.warning(t('knowledgeEditor.messages.missingId'));
|
||||
@@ -2158,11 +2007,6 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</div>
|
||||
|
||||
<template v-if="activeKbTab === 'documents' || !isWiki">
|
||||
<input ref="uploadInputRef" type="file" class="document-upload-input"
|
||||
:accept="acceptFileTypes || '.pdf,.docx,.doc,.txt,.md,.json,.jpg,.jpeg,.png,.csv,.xlsx,.xls,.pptx,.ppt,.mp3,.wav,.m4a,.flac,.ogg'"
|
||||
multiple @change="handleDocumentUpload" />
|
||||
<input ref="folderUploadInputRef" type="file" class="document-upload-input" webkitdirectory
|
||||
@change="handleFolderUpload" />
|
||||
<div class="knowledge-main">
|
||||
<aside class="tag-sidebar">
|
||||
<div class="sidebar-header">
|
||||
@@ -2319,15 +2163,20 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</t-tooltip>
|
||||
</div>
|
||||
<div v-if="canEdit" class="doc-filter-actions">
|
||||
<t-tooltip :content="$t('knowledgeBase.addDocument')" placement="top">
|
||||
<t-dropdown :options="documentActionOptions" trigger="click" placement="bottom-right"
|
||||
@click="handleDocumentActionSelect">
|
||||
<t-button variant="text" theme="default" class="content-bar-icon-btn" size="small"
|
||||
data-guide="kb-detail-add-doc">
|
||||
<template #icon><t-icon name="file-add" size="16px" /></template>
|
||||
</t-button>
|
||||
</t-dropdown>
|
||||
</t-tooltip>
|
||||
<KbUploadSourceDropdown
|
||||
ref="uploadSourceRef"
|
||||
:accept-file-types="acceptFileTypes"
|
||||
:supported-file-types="[...supportedFileTypes]"
|
||||
include-manual
|
||||
trigger-icon="file-add"
|
||||
trigger-class="content-bar-icon-btn"
|
||||
data-guide="kb-detail-add-doc"
|
||||
:tooltip="t('knowledgeBase.addDocument')"
|
||||
placement="bottom-right"
|
||||
@files="handleUploadSourceFiles"
|
||||
@url="handleUploadSourceUrl"
|
||||
@manual="handleManualCreate"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="doc-scroll-container" :class="{ 'is-empty': !cardList.length && !docListLoading }" ref="knowledgeScroll"
|
||||
@@ -2687,21 +2536,6 @@ async function createNewSession(value: string): Promise<void> {
|
||||
@delete="confirmBatchDelete" />
|
||||
</div>
|
||||
</div>
|
||||
<!-- URL 导入对话框 -->
|
||||
<t-dialog v-model:visible="urlDialogVisible" :header="$t('knowledgeBase.importURLTitle')" :confirm-btn="{
|
||||
content: $t('common.confirm'),
|
||||
theme: 'primary',
|
||||
loading: urlImporting,
|
||||
}" :cancel-btn="{ content: $t('common.cancel') }" @confirm="handleURLImportConfirm"
|
||||
@cancel="handleURLImportCancel" width="500px">
|
||||
<div class="url-import-form">
|
||||
<div class="url-input-label">{{ $t('knowledgeBase.urlLabel') }}</div>
|
||||
<t-input v-model="urlInputValue" :placeholder="$t('knowledgeBase.urlPlaceholder')" clearable autofocus
|
||||
@enter="handleURLImportConfirm" />
|
||||
<div class="url-input-tip">{{ $t('knowledgeBase.urlTip') }}</div>
|
||||
</div>
|
||||
</t-dialog>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
<template>
|
||||
<div class="kb-upload-source-dropdown">
|
||||
<input
|
||||
ref="fileInputRef"
|
||||
type="file"
|
||||
class="hidden-file-input"
|
||||
multiple
|
||||
:accept="acceptFileTypes || undefined"
|
||||
@change="(e) => handleFilesChange(e, false)"
|
||||
/>
|
||||
<input
|
||||
ref="folderInputRef"
|
||||
type="file"
|
||||
class="hidden-file-input"
|
||||
webkitdirectory
|
||||
multiple
|
||||
@change="(e) => handleFilesChange(e, true)"
|
||||
/>
|
||||
|
||||
<t-tooltip :content="tooltipText" placement="top">
|
||||
<t-dropdown
|
||||
:options="dropdownOptions"
|
||||
trigger="click"
|
||||
:placement="placement"
|
||||
@click="handleActionSelect"
|
||||
>
|
||||
<t-button
|
||||
variant="text"
|
||||
theme="default"
|
||||
:class="['kb-upload-source-trigger', triggerClass]"
|
||||
:data-guide="dataGuide || undefined"
|
||||
size="small"
|
||||
>
|
||||
<template #icon><t-icon :name="triggerIcon" size="16px" /></template>
|
||||
</t-button>
|
||||
</t-dropdown>
|
||||
</t-tooltip>
|
||||
|
||||
<t-dialog
|
||||
v-model:visible="urlDialogVisible"
|
||||
:header="t('knowledgeBase.importURLTitle')"
|
||||
:confirm-btn="{ content: t('common.confirm'), theme: 'primary' }"
|
||||
:cancel-btn="{ content: t('common.cancel') }"
|
||||
width="500px"
|
||||
@confirm="handleUrlDialogConfirm"
|
||||
@cancel="handleUrlDialogCancel"
|
||||
>
|
||||
<div class="url-import-form">
|
||||
<div class="url-input-label">{{ t('knowledgeBase.urlLabel') }}</div>
|
||||
<t-input
|
||||
v-model="urlInputValue"
|
||||
:placeholder="t('knowledgeBase.urlPlaceholder')"
|
||||
clearable
|
||||
autofocus
|
||||
@enter="handleUrlDialogConfirm"
|
||||
/>
|
||||
<div class="url-input-tip">{{ t('knowledgeBase.urlTip') }}</div>
|
||||
</div>
|
||||
</t-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, h, withDefaults } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { MessagePlugin, Icon as TIcon } from 'tdesign-vue-next'
|
||||
import { filterUploadFiles } from '../utils/uploadSources'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
acceptFileTypes?: string
|
||||
supportedFileTypes?: string[]
|
||||
includeManual?: boolean
|
||||
triggerIcon?: string
|
||||
triggerClass?: string
|
||||
dataGuide?: string
|
||||
tooltip?: string
|
||||
placement?: 'top' | 'bottom' | 'bottom-right' | 'bottom-left'
|
||||
}>(), {
|
||||
acceptFileTypes: '',
|
||||
supportedFileTypes: () => [],
|
||||
includeManual: false,
|
||||
triggerIcon: 'file-add',
|
||||
triggerClass: '',
|
||||
dataGuide: '',
|
||||
tooltip: '',
|
||||
placement: 'bottom-right',
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
files: [files: File[]]
|
||||
url: [url: string]
|
||||
manual: []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const fileInputRef = ref<HTMLInputElement | null>(null)
|
||||
const folderInputRef = ref<HTMLInputElement | null>(null)
|
||||
const urlDialogVisible = ref(false)
|
||||
const urlInputValue = ref('')
|
||||
|
||||
const tooltipText = computed(() => props.tooltip || t('knowledgeBase.addDocument'))
|
||||
|
||||
const dropdownOptions = computed(() => {
|
||||
const options = [
|
||||
{
|
||||
content: t('upload.uploadDocument'),
|
||||
value: 'upload',
|
||||
prefixIcon: () => h(TIcon, { name: 'upload', size: '16px' }),
|
||||
},
|
||||
{
|
||||
content: t('upload.uploadFolder'),
|
||||
value: 'uploadFolder',
|
||||
prefixIcon: () => h(TIcon, { name: 'folder-add', size: '16px' }),
|
||||
},
|
||||
{
|
||||
content: t('knowledgeBase.importURL'),
|
||||
value: 'importURL',
|
||||
prefixIcon: () => h(TIcon, { name: 'link', size: '16px' }),
|
||||
},
|
||||
]
|
||||
if (props.includeManual) {
|
||||
options.push({
|
||||
content: t('upload.onlineEdit'),
|
||||
value: 'manualCreate',
|
||||
prefixIcon: () => h(TIcon, { name: 'edit', size: '16px' }),
|
||||
})
|
||||
}
|
||||
return options
|
||||
})
|
||||
|
||||
const handleActionSelect = (data: { value: string }) => {
|
||||
switch (data.value) {
|
||||
case 'upload':
|
||||
fileInputRef.value?.click()
|
||||
break
|
||||
case 'uploadFolder':
|
||||
folderInputRef.value?.click()
|
||||
break
|
||||
case 'importURL':
|
||||
urlInputValue.value = ''
|
||||
urlDialogVisible.value = true
|
||||
break
|
||||
case 'manualCreate':
|
||||
emit('manual')
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const notifyFilterResult = (result: ReturnType<typeof filterUploadFiles>, emptyAllSkippedKey: string) => {
|
||||
const { validFiles, skippedCount, videoFilteredCount } = result
|
||||
if (validFiles.length === 0) {
|
||||
if (skippedCount > 0) {
|
||||
MessagePlugin.warning(t(emptyAllSkippedKey))
|
||||
}
|
||||
return false
|
||||
}
|
||||
if (videoFilteredCount > 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.videosFilteredNoVLM', { count: videoFilteredCount }))
|
||||
}
|
||||
if (skippedCount > 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.filesSkippedNoEngine', { count: skippedCount }))
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
const handleFilesChange = (event: Event, fromFolder: boolean) => {
|
||||
const input = event.target as HTMLInputElement
|
||||
const files = input.files
|
||||
if (!files || files.length === 0) return
|
||||
|
||||
const result = filterUploadFiles(files, {
|
||||
supportedFileTypes: props.supportedFileTypes,
|
||||
fromFolder,
|
||||
multiFile: files.length > 1,
|
||||
})
|
||||
|
||||
if (!notifyFilterResult(result, 'knowledgeBase.allFilesSkippedNoEngine')) {
|
||||
input.value = ''
|
||||
return
|
||||
}
|
||||
|
||||
emit('files', result.validFiles)
|
||||
input.value = ''
|
||||
}
|
||||
|
||||
const handleUrlDialogConfirm = () => {
|
||||
const url = urlInputValue.value.trim()
|
||||
if (!url) {
|
||||
MessagePlugin.warning(t('knowledgeBase.urlRequired'))
|
||||
return
|
||||
}
|
||||
try {
|
||||
new URL(url)
|
||||
} catch {
|
||||
MessagePlugin.warning(t('knowledgeBase.invalidURL'))
|
||||
return
|
||||
}
|
||||
urlDialogVisible.value = false
|
||||
urlInputValue.value = ''
|
||||
emit('url', url)
|
||||
}
|
||||
|
||||
const handleUrlDialogCancel = () => {
|
||||
urlDialogVisible.value = false
|
||||
urlInputValue.value = ''
|
||||
}
|
||||
|
||||
const openUrlDialog = () => {
|
||||
urlInputValue.value = ''
|
||||
urlDialogVisible.value = true
|
||||
}
|
||||
|
||||
defineExpose({ openUrlDialog })
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.hidden-file-input {
|
||||
position: absolute;
|
||||
width: 0;
|
||||
height: 0;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.kb-upload-source-trigger {
|
||||
color: var(--td-text-color-secondary);
|
||||
|
||||
&:hover {
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
}
|
||||
|
||||
.url-import-form {
|
||||
.url-input-label {
|
||||
margin-bottom: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.url-input-tip {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,9 @@
|
||||
<template>
|
||||
<div class="graph-settings">
|
||||
<div class="section-header">
|
||||
<div class="graph-settings" :class="{ 'graph-settings--embedded': embedded }">
|
||||
<div v-if="!embedded" class="section-header">
|
||||
<h2>{{ t('graphSettings.title') }}</h2>
|
||||
<p class="section-description">{{ t('graphSettings.description') }}</p>
|
||||
|
||||
<!-- Warning message when graph database is not enabled -->
|
||||
|
||||
<t-alert
|
||||
v-if="!isGraphDatabaseEnabled"
|
||||
theme="warning"
|
||||
@@ -18,6 +17,15 @@
|
||||
</template>
|
||||
</t-alert>
|
||||
</div>
|
||||
<t-alert
|
||||
v-else-if="!isGraphDatabaseEnabled"
|
||||
theme="warning"
|
||||
class="embedded-graph-alert"
|
||||
>
|
||||
<template #message>
|
||||
<div>{{ t('graphSettings.disabledWarning') }}</div>
|
||||
</template>
|
||||
</t-alert>
|
||||
|
||||
<div v-if="isGraphDatabaseEnabled" class="settings-group">
|
||||
<!-- 启用实体关系提取 -->
|
||||
@@ -296,7 +304,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, onMounted, computed } from 'vue'
|
||||
import { ref, watch, onMounted, computed, withDefaults } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { extractTextRelations, fabriText, fabriTag, type Node, type Relation } from '@/api/initialization'
|
||||
@@ -323,9 +331,12 @@ interface Props {
|
||||
graphExtract: GraphExtractConfig
|
||||
modelId: string
|
||||
allModels?: any[]
|
||||
embedded?: boolean
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
embedded: false,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:graphExtract': [value: GraphExtractConfig]
|
||||
@@ -766,4 +777,27 @@ onMounted(async () => {
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.graph-settings--embedded {
|
||||
.embedded-graph-alert {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.setting-row:not(.vertical) {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 8px;
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
.setting-row:not(.vertical) .setting-info {
|
||||
flex: none;
|
||||
max-width: none;
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
.setting-row:not(.vertical) .setting-control {
|
||||
align-self: flex-start;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="kb-advanced-settings">
|
||||
<div class="section-header">
|
||||
<div class="kb-advanced-settings" :class="{ 'kb-advanced-settings--embedded': embedded }">
|
||||
<div v-if="!embedded" class="section-header">
|
||||
<h2>{{ $t('knowledgeEditor.advanced.title') }}</h2>
|
||||
<p class="section-description">{{ $t('knowledgeEditor.advanced.description') }}</p>
|
||||
</div>
|
||||
@@ -49,7 +49,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { ref, watch, withDefaults } from 'vue'
|
||||
|
||||
interface QuestionGenerationConfig {
|
||||
enabled: boolean
|
||||
@@ -60,9 +60,12 @@ interface Props {
|
||||
questionGeneration?: QuestionGenerationConfig
|
||||
ragEnabled?: boolean
|
||||
allModels?: any[]
|
||||
embedded?: boolean
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
embedded: false,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:questionGeneration': [value: QuestionGenerationConfig]
|
||||
@@ -182,4 +185,51 @@ const handleQuestionGenerationChange = () => {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.kb-advanced-settings--embedded {
|
||||
.setting-row {
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
.setting-row:has(.t-switch) {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
max-width: none;
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex: none;
|
||||
align-self: center;
|
||||
}
|
||||
}
|
||||
|
||||
.subsection .setting-row {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 8px;
|
||||
|
||||
.setting-info {
|
||||
flex: none;
|
||||
max-width: none;
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
align-self: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
.subsection {
|
||||
margin-top: 0;
|
||||
padding: 0;
|
||||
border: none;
|
||||
background: none;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="kb-chunking-settings">
|
||||
<div class="section-header">
|
||||
<div class="kb-chunking-settings" :class="{ 'kb-chunking-settings--embedded': embedded }">
|
||||
<div v-if="!embedded" class="section-header">
|
||||
<div class="section-header-text">
|
||||
<h2>{{ $t('knowledgeEditor.chunking.title') }}</h2>
|
||||
<p class="section-description">{{ $t('knowledgeEditor.chunking.description') }}</p>
|
||||
@@ -21,12 +21,12 @@
|
||||
:placeholder="$t('knowledgeEditor.chunking.strategyPlaceholder')"
|
||||
:clearable="true"
|
||||
@change="handleStrategyChange"
|
||||
style="width: 280px;"
|
||||
:style="selectStyle"
|
||||
/>
|
||||
<!-- Test trigger sits right next to the strategy picker so users
|
||||
discover it exactly when they're deciding which strategy to
|
||||
use on their content. -->
|
||||
<KBChunkingDebug :config="debugConfig" />
|
||||
<KBChunkingDebug v-if="!embedded" :config="debugConfig" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -51,9 +51,9 @@
|
||||
:min="100"
|
||||
:max="4000"
|
||||
:step="50"
|
||||
:marks="{ 100: '100', 1000: '1000', 2000: '2000', 4000: '4000' }"
|
||||
:marks="embedded ? undefined : chunkSizeMarks"
|
||||
@change="handleChunkSizeChange"
|
||||
style="width: 200px;"
|
||||
:style="sliderStyle"
|
||||
/>
|
||||
<span class="value-display">{{ localChunkSize }} {{ $t('knowledgeEditor.chunking.characters') }}</span>
|
||||
</div>
|
||||
@@ -74,9 +74,9 @@
|
||||
:min="0"
|
||||
:max="500"
|
||||
:step="20"
|
||||
:marks="{ 0: '0', 250: '250', 500: '500' }"
|
||||
:marks="embedded ? undefined : chunkOverlapMarks"
|
||||
@change="handleChunkOverlapChange"
|
||||
style="width: 200px;"
|
||||
:style="sliderStyle"
|
||||
/>
|
||||
<span class="value-display">{{ localChunkOverlap }} {{ $t('knowledgeEditor.chunking.characters') }}</span>
|
||||
</div>
|
||||
@@ -84,7 +84,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Separators -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-row setting-row--separators">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.chunking.separatorsLabel') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.chunking.separatorsDescription') }}</p>
|
||||
@@ -98,13 +98,13 @@
|
||||
filterable
|
||||
:placeholder="$t('knowledgeEditor.chunking.separatorsPlaceholder')"
|
||||
@change="handleSeparatorsChange"
|
||||
style="width: 280px;"
|
||||
:style="selectStyle"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Parent-Child Chunking -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-row setting-row--toggle">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.chunking.parentChildLabel') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.chunking.parentChildDescription') }}</p>
|
||||
@@ -130,9 +130,9 @@
|
||||
:min="512"
|
||||
:max="8192"
|
||||
:step="64"
|
||||
:marks="{ 512: '512', 2048: '2048', 4096: '4096', 8192: '8192' }"
|
||||
:marks="embedded ? undefined : parentChunkSizeMarks"
|
||||
@change="handleParentChunkSizeChange"
|
||||
style="width: 200px;"
|
||||
:style="sliderStyle"
|
||||
/>
|
||||
<span class="value-display">{{ localParentChunkSize }} {{ $t('knowledgeEditor.chunking.characters') }}</span>
|
||||
</div>
|
||||
@@ -152,9 +152,9 @@
|
||||
:min="64"
|
||||
:max="2048"
|
||||
:step="32"
|
||||
:marks="{ 64: '64', 384: '384', 1024: '1024', 2048: '2048' }"
|
||||
:marks="embedded ? undefined : childChunkSizeMarks"
|
||||
@change="handleChildChunkSizeChange"
|
||||
style="width: 200px;"
|
||||
:style="sliderStyle"
|
||||
/>
|
||||
<span class="value-display">{{ localChildChunkSize }} {{ $t('knowledgeEditor.chunking.characters') }}</span>
|
||||
</div>
|
||||
@@ -201,7 +201,7 @@
|
||||
:disabled="advancedDisabled"
|
||||
:placeholder="$t('knowledgeEditor.chunking.languagesPlaceholder')"
|
||||
@change="handleLanguagesChange"
|
||||
style="width: 280px;"
|
||||
:style="selectStyle"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -212,7 +212,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, computed } from 'vue'
|
||||
import { ref, watch, computed, withDefaults } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ChevronRightIcon } from 'tdesign-icons-vue-next'
|
||||
import KBChunkingDebug from './KBChunkingDebug.vue'
|
||||
@@ -253,9 +253,20 @@ interface ChunkingConfig {
|
||||
|
||||
interface Props {
|
||||
config: ChunkingConfig
|
||||
embedded?: boolean
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
embedded: false,
|
||||
})
|
||||
|
||||
const selectStyle = computed(() => (props.embedded ? { width: '100%' } : { width: '280px' }))
|
||||
const sliderStyle = computed(() => (props.embedded ? { width: '100%' } : { width: '200px' }))
|
||||
|
||||
const chunkSizeMarks = { 100: '100', 1000: '1000', 2000: '2000', 4000: '4000' }
|
||||
const chunkOverlapMarks = { 0: '0', 250: '250', 500: '500' }
|
||||
const parentChunkSizeMarks = { 512: '512', 2048: '2048', 4096: '4096', 8192: '8192' }
|
||||
const childChunkSizeMarks = { 64: '64', 384: '384', 1024: '1024', 2048: '2048' }
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:config': [value: ChunkingConfig]
|
||||
@@ -563,4 +574,102 @@ const emitUpdate = () => {
|
||||
// panel edge and looks detached from the rest of the form.
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.kb-chunking-settings--embedded {
|
||||
.setting-row {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 10px;
|
||||
padding: 14px 0;
|
||||
}
|
||||
|
||||
.setting-row--toggle {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex: none;
|
||||
width: auto;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-row--separators {
|
||||
padding-bottom: 18px;
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: none;
|
||||
max-width: none;
|
||||
padding-right: 0;
|
||||
|
||||
label {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex: none;
|
||||
max-width: none;
|
||||
justify-content: flex-start;
|
||||
align-items: stretch;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.strategy-control {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.strategy-info-panel {
|
||||
margin: -4px 0 10px;
|
||||
padding: 8px 12px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.slider-container {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.value-display {
|
||||
order: -1;
|
||||
text-align: left;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
:deep(.t-slider) {
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
:deep(.t-select__wrap) {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
:deep(.t-tag) {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.advanced-toggle {
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
.advanced-section .setting-row {
|
||||
padding: 14px 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="kb-parser-settings">
|
||||
<div class="section-header">
|
||||
<div class="kb-parser-settings" :class="{ 'kb-parser-settings--embedded': embedded }">
|
||||
<div v-if="!embedded" class="section-header">
|
||||
<h2>{{ $t('kbSettings.parser.title') }}</h2>
|
||||
<p class="section-description">{{ $t('kbSettings.parser.description') }}</p>
|
||||
</div>
|
||||
@@ -33,7 +33,7 @@
|
||||
<t-select
|
||||
:value="getEngineForGroup(group.extensions) || undefined"
|
||||
@change="(val: string) => handleEngineChange(group.extensions, val)"
|
||||
style="width: 280px;"
|
||||
:style="embedded ? { width: '100%' } : { width: '280px' }"
|
||||
:status="hasAvailableEngine(group.extensions) ? 'default' : 'warning'"
|
||||
:placeholder="$t('kbSettings.parser.noEngine')"
|
||||
>
|
||||
@@ -123,10 +123,16 @@ interface EngineOption {
|
||||
|
||||
interface Props {
|
||||
parserEngineRules?: ParserEngineRule[]
|
||||
/** Compact layout for upload-confirm dialog */
|
||||
embedded?: boolean
|
||||
/** When set, only show file-type groups matching these extensions */
|
||||
relevantExtensions?: string[]
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
parserEngineRules: () => []
|
||||
parserEngineRules: () => [],
|
||||
embedded: false,
|
||||
relevantExtensions: () => [],
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -182,7 +188,11 @@ const fileTypeGroups = computed(() => {
|
||||
})
|
||||
}
|
||||
|
||||
return groups
|
||||
const rel = props.relevantExtensions
|
||||
if (!rel?.length) return groups
|
||||
const relSet = new Set(rel)
|
||||
const filtered = groups.filter(g => g.extensions.some(e => relSet.has(e)))
|
||||
return filtered.length > 0 ? filtered : groups
|
||||
})
|
||||
|
||||
function getEngineOptions(extensions: string[]): EngineOption[] {
|
||||
@@ -468,6 +478,46 @@ watch(() => props.parserEngineRules, (v) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.kb-parser-settings--embedded {
|
||||
.setting-row {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 10px;
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: none;
|
||||
max-width: none;
|
||||
padding-right: 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 6px 10px;
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex: none;
|
||||
max-width: none;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.group-label {
|
||||
font-size: 14px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.ext-tags {
|
||||
margin-top: 0;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.ext-tag {
|
||||
font-size: 11px;
|
||||
padding: 2px 6px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="less">
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { kbFileTypeVerification } from '@/utils'
|
||||
|
||||
export const UPLOAD_VIDEO_EXTENSIONS = ['mp4', 'mov', 'avi', 'mkv', 'webm', 'wmv', 'flv']
|
||||
|
||||
export function getUploadFileExt(file: File): string {
|
||||
const dot = file.name.lastIndexOf('.')
|
||||
if (dot < 0) return ''
|
||||
return file.name.substring(dot + 1).toLowerCase()
|
||||
}
|
||||
|
||||
export function getUploadFileKey(file: File): string {
|
||||
const path = (file as File & { webkitRelativePath?: string }).webkitRelativePath || ''
|
||||
return `${path || file.name}\0${file.size}`
|
||||
}
|
||||
|
||||
export interface FilterUploadFilesOptions {
|
||||
supportedFileTypes?: Set<string> | string[]
|
||||
fromFolder?: boolean
|
||||
multiFile?: boolean
|
||||
}
|
||||
|
||||
export interface FilterUploadFilesResult {
|
||||
validFiles: File[]
|
||||
skippedCount: number
|
||||
videoFilteredCount: number
|
||||
hiddenFileCount: number
|
||||
}
|
||||
|
||||
export function filterUploadFiles(
|
||||
files: FileList | File[],
|
||||
options: FilterUploadFilesOptions = {},
|
||||
): FilterUploadFilesResult {
|
||||
const list = Array.from(files)
|
||||
const dynamicTypes = options.supportedFileTypes
|
||||
? options.supportedFileTypes instanceof Set
|
||||
? options.supportedFileTypes
|
||||
: new Set(options.supportedFileTypes)
|
||||
: undefined
|
||||
|
||||
const validFiles: File[] = []
|
||||
let skippedCount = 0
|
||||
let videoFilteredCount = 0
|
||||
let hiddenFileCount = 0
|
||||
const multiFile = options.multiFile ?? list.length > 1
|
||||
|
||||
for (const file of list) {
|
||||
if (options.fromFolder) {
|
||||
const relativePath = (file as File & { webkitRelativePath?: string }).webkitRelativePath || file.name
|
||||
if (relativePath.split('/').some(part => part.startsWith('.'))) {
|
||||
hiddenFileCount++
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
const fileExt = getUploadFileExt(file)
|
||||
if (UPLOAD_VIDEO_EXTENSIONS.includes(fileExt)) {
|
||||
videoFilteredCount++
|
||||
continue
|
||||
}
|
||||
|
||||
if (kbFileTypeVerification(file, multiFile, dynamicTypes)) {
|
||||
skippedCount++
|
||||
continue
|
||||
}
|
||||
|
||||
validFiles.push(file)
|
||||
}
|
||||
|
||||
return { validFiles, skippedCount, videoFilteredCount, hiddenFileCount }
|
||||
}
|
||||
Reference in New Issue
Block a user