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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user