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:
@@ -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