feat: implement reparse functionality with process configuration support

- Enhanced the `reparseKnowledge` function to accept optional process configuration overrides, allowing users to adjust parsing settings during reparse operations.
- Updated the frontend components to integrate reparse capabilities, including the `UploadConfirmDialog` and `KnowledgeBase` views, providing a user-friendly interface for confirming reparse actions.
- Added new localization strings for reparse confirmation and process configuration details in multiple languages.
- Modified the backend API to handle reparse requests with optional configuration, ensuring proper validation and persistence of overrides.
- Introduced new types and interfaces to manage reparse-specific data structures in the store, improving type safety and clarity in the codebase.
This commit is contained in:
wizardchen
2026-06-09 20:34:16 +08:00
committed by lyingbug
parent d8a26f7c23
commit 2aadd61fcc
14 changed files with 371 additions and 23 deletions
@@ -2,8 +2,9 @@
import { ref, reactive, onMounted, onBeforeUnmount, watch, computed, nextTick } from 'vue'
import { MessagePlugin } from 'tdesign-vue-next'
import { useI18n } from 'vue-i18n'
import { getKnowledgeSpans, reparseKnowledge, cancelKnowledgeParse } from '@/api/knowledge-base/index'
import { getKnowledgeSpans, reparseKnowledge, cancelKnowledgeParse, getKnowledgeDetails } from '@/api/knowledge-base/index'
import { knowledgeSpansPayloadHasTrace } from '@/utils/knowledgeTrace'
import type { KnowledgeProcessOverrides } from '@/types/knowledgeProcess'
interface SpanNode {
span_id?: string
@@ -92,6 +93,7 @@ const STAGES = ['docreader', 'chunking', 'embedding', 'multimodal', 'postprocess
const POLL_INTERVAL_MS = 2000
const data = ref<SpansResponse | null>(null)
const processOverrides = ref<KnowledgeProcessOverrides | null>(null)
const loading = ref(false)
const refreshing = ref(false)
const selectedAttempt = ref<number | undefined>(undefined)
@@ -519,8 +521,21 @@ function onKeydown(ev: KeyboardEvent) {
}
}
async function fetchProcessOverrides() {
if (props.compact || !props.knowledgeId) return
try {
const res: any = await getKnowledgeDetails(props.knowledgeId)
if (res?.success && res.data) {
processOverrides.value = res.data.metadata?.process_overrides ?? null
}
} catch {
processOverrides.value = null
}
}
onMounted(() => {
fetchSpans()
fetchProcessOverrides()
// One permanent interval for the entire component lifetime. The
// tick decides whether to actually fetch — no clearing, no
// re-arming, no watchers wired into it. If this interval ever
@@ -1290,6 +1305,46 @@ const stageBreakdown = computed<StageRowSummary[]>(() => {
pct: typeof s.duration_ms === 'number' && s.duration_ms > 0 ? Math.min(100, (s.duration_ms / total) * 100) : 0,
}))
})
// Human-readable summary of the per-upload parse overrides stored in
// knowledge.metadata.process_overrides. Empty overrides → KB defaults.
const processConfigLines = computed<string[]>(() => {
const o = processOverrides.value
if (!o) return [t('knowledgeStages.processConfig.kbDefault')]
const k = (s: string) => `knowledgeStages.processConfig.${s}`
const onOff = (v: boolean) => (v ? t(k('on')) : t(k('off')))
const lines: string[] = []
const cc = o.chunking_config
if (cc) {
const parts: string[] = []
if (cc.chunk_size != null) parts.push(t(k('chunkSize'), { n: cc.chunk_size }))
if (cc.enable_parent_child != null) {
parts.push(cc.enable_parent_child ? t(k('parentChildOn')) : t(k('parentChildOff')))
}
if (parts.length) lines.push(`${t(k('chunking'))}: ${parts.join(' · ')}`)
}
const rules = o.parser_engine_rules || cc?.parser_engine_rules
if (rules?.length) {
lines.push(`${t(k('parser'))}: ${rules.map(r => `${r.file_types.join('/')}→${r.engine}`).join(', ')}`)
}
const mm = o.vlm_config?.enabled ?? o.enable_multimodel
if (mm != null) lines.push(`${t(k('multimodal'))}: ${onOff(mm)}`)
if (o.asr_config?.enabled != null) lines.push(`${t(k('asr'))}: ${onOff(o.asr_config.enabled)}`)
const qg = o.question_generation_config
if (qg?.enabled != null) {
lines.push(`${t(k('question'))}: ${qg.enabled ? t(k('questionOn'), { n: qg.question_count ?? 3 }) : t(k('off'))}`)
}
const graph = o.graph_enabled ?? o.extract_config?.enabled
if (graph != null) lines.push(`${t(k('graph'))}: ${onOff(graph)}`)
return lines.length ? lines : [t('knowledgeStages.processConfig.kbDefault')]
})
</script>
<template>
@@ -1333,6 +1388,19 @@ const stageBreakdown = computed<StageRowSummary[]>(() => {
<span class="kp-live-text">{{ t('knowledgeStages.live') }}</span>
</span>
<div class="kp-head-actions">
<t-popup trigger="hover" placement="bottom-right" :overlay-style="{ maxWidth: '340px' }">
<button type="button" class="kp-icon-btn"
:title="t('knowledgeStages.processConfig.title')"
:aria-label="t('knowledgeStages.processConfig.title')">
<t-icon name="info-circle" size="14px" />
</button>
<template #content>
<div class="kp-proccfg-pop">
<div class="kp-proccfg-title">{{ t('knowledgeStages.processConfig.title') }}</div>
<div v-for="(line, i) in processConfigLines" :key="i" class="kp-proccfg-line">{{ line }}</div>
</div>
</template>
</t-popup>
<button type="button" class="kp-icon-btn" :class="{
'kp-icon-btn-spin': refreshing,
'kp-icon-btn-autoflow': isLive && !refreshing,
@@ -3163,4 +3231,26 @@ const stageBreakdown = computed<StageRowSummary[]>(() => {
color: var(--td-brand-color);
font-weight: 600;
}
.kp-proccfg-pop {
display: flex;
flex-direction: column;
gap: 4px;
padding: 2px 0;
max-width: 320px;
}
.kp-proccfg-title {
font-weight: 600;
font-size: 13px;
color: var(--td-text-color-primary);
margin-bottom: 2px;
}
.kp-proccfg-line {
font-size: 12px;
line-height: 1.6;
color: var(--td-text-color-secondary);
word-break: break-word;
}
</style>