feat(parser): add OpenDataLoader, PaddleOCR-VL engines, and parser improvements
Introduce opendataloader and PaddleOCR-VL parser engines with tenant-level settings UI, replace liteparse, and harden Excel/PPT/Markdown parsing. Optional odl-hybrid sidecar stays local-build only and is excluded from default dev-start and full profiles.
This commit is contained in:
@@ -86,6 +86,15 @@ export interface ParserEngineConfig {
|
||||
mineru_cloud_enable_table?: boolean | null
|
||||
mineru_cloud_enable_ocr?: boolean | null
|
||||
mineru_cloud_language?: string
|
||||
// PaddleOCR-VL 自建参数
|
||||
paddleocr_vl_endpoint?: string
|
||||
paddleocr_vl_use_seal_recognition?: boolean | null
|
||||
paddleocr_vl_use_chart_recognition?: boolean | null
|
||||
// PaddleOCR-VL 云 API 参数
|
||||
paddleocr_vl_cloud_token?: string
|
||||
paddleocr_vl_cloud_model?: string
|
||||
paddleocr_vl_cloud_use_seal_recognition?: boolean | null
|
||||
paddleocr_vl_cloud_use_chart_recognition?: boolean | null
|
||||
}
|
||||
|
||||
export interface ParserEnginesResponse {
|
||||
|
||||
@@ -11,6 +11,7 @@ import { onMounted, ref, nextTick, onUnmounted, watch, computed } from "vue";
|
||||
import { downKnowledgeDetails, deleteGeneratedQuestion, getChunkByIdOnly, previewKnowledgeFile } from "@/api/knowledge-base/index";
|
||||
import { MessagePlugin, DialogPlugin } from "tdesign-vue-next";
|
||||
import { sanitizeHTML, safeMarkdownToHTML, createSafeImage, isValidImageURL, hydrateProtectedFileImages, isValidURL } from '@/utils/security';
|
||||
import { normalizeSpuriousTablePrefixes } from '@/utils/markdownTableNormalize';
|
||||
import { openMermaidFullscreen } from '@/utils/mermaidViewer';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
@@ -283,8 +284,15 @@ let page = 1;
|
||||
let loadingChunks = false;
|
||||
let pendingRequestedPage: number | null = null;
|
||||
let pendingChunksBeforeLoad = 0;
|
||||
let doc = null;
|
||||
const CHUNK_PAGE_SIZE = 25;
|
||||
/** Scroll container for the main doc drawer (not the first .t-drawer__body on the page). */
|
||||
let docScrollEl: HTMLElement | null = null;
|
||||
let mdContentWrap = ref()
|
||||
// Drawer uses attach="body", so markdown nodes live outside mdContentWrap in the DOM.
|
||||
const docMarkdownRoot = ref<HTMLElement | null>(null)
|
||||
|
||||
const getMarkdownRenderRoot = (): ParentNode | null =>
|
||||
docMarkdownRoot.value ?? (mdContentWrap.value as ParentNode | null) ?? null
|
||||
let url = ref('')
|
||||
// 视图模式:chunks / merged / preview
|
||||
// file 类型默认「预览」,URL / 手动创建 默认「全文」
|
||||
@@ -365,18 +373,40 @@ const mergeChunks = (chunks: any[]): string => {
|
||||
return merged;
|
||||
};
|
||||
|
||||
const findDocDrawerScrollEl = (): HTMLElement | null =>
|
||||
document.querySelector('.doc-main-drawer .t-drawer__body') as HTMLElement | null;
|
||||
|
||||
const unbindDrawerScroll = () => {
|
||||
if (docScrollEl) {
|
||||
docScrollEl.removeEventListener('scroll', handleDetailsScroll);
|
||||
docScrollEl = null;
|
||||
}
|
||||
};
|
||||
|
||||
const bindDrawerScroll = () => {
|
||||
unbindDrawerScroll();
|
||||
docScrollEl = findDocDrawerScrollEl();
|
||||
if (docScrollEl) {
|
||||
docScrollEl.addEventListener('scroll', handleDetailsScroll, { passive: true });
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
loadTraceDrawerWidth();
|
||||
loadMainDrawerWidth();
|
||||
window.addEventListener('resize', onTraceDrawerWindowResize, { passive: true });
|
||||
nextTick(() => {
|
||||
const drawers = document.getElementsByClassName('t-drawer__body');
|
||||
if (drawers && drawers.length > 0) {
|
||||
doc = drawers[0];
|
||||
doc.addEventListener('scroll', handleDetailsScroll);
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
watch(() => props.visible, (visible) => {
|
||||
if (visible) {
|
||||
nextTick(() => {
|
||||
bindDrawerScroll();
|
||||
maybeLoadMoreChunks();
|
||||
});
|
||||
} else {
|
||||
unbindDrawerScroll();
|
||||
}
|
||||
});
|
||||
watch(() => props.details?.id, () => {
|
||||
page = 1;
|
||||
loadingChunks = false;
|
||||
@@ -396,15 +426,16 @@ watch(() => props.details?.chunkLoading, (val) => {
|
||||
pendingRequestedPage = null;
|
||||
pendingChunksBeforeLoad = 0;
|
||||
loadingChunks = false;
|
||||
if (props.visible) {
|
||||
nextTick(() => maybeLoadMoreChunks());
|
||||
}
|
||||
}
|
||||
});
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', onTraceDrawerWindowResize);
|
||||
cleanupTraceDrawerResize();
|
||||
cleanupMainDrawerResize();
|
||||
if (doc) {
|
||||
doc.removeEventListener('scroll', handleDetailsScroll);
|
||||
}
|
||||
unbindDrawerScroll();
|
||||
if (audioBlobUrl.value) {
|
||||
URL.revokeObjectURL(audioBlobUrl.value);
|
||||
}
|
||||
@@ -561,7 +592,10 @@ const loadAudioPreview = async () => {
|
||||
};
|
||||
const runMarkdownPostRenderPipeline = async () => {
|
||||
await nextTick();
|
||||
const renderRoot = mdContentWrap.value as ParentNode;
|
||||
const renderRoot = getMarkdownRenderRoot();
|
||||
if (!renderRoot) {
|
||||
return;
|
||||
}
|
||||
await hydrateProtectedFileImages(renderRoot);
|
||||
const images = renderRoot?.querySelectorAll?.('img.markdown-image') as NodeListOf<HTMLImageElement> | undefined;
|
||||
if (images) {
|
||||
@@ -576,26 +610,29 @@ const runMarkdownPostRenderPipeline = async () => {
|
||||
await renderMermaidDiagrams();
|
||||
};
|
||||
|
||||
watch(() => props.details.md, (newVal) => {
|
||||
watch(() => props.details.md, () => {
|
||||
runMarkdownPostRenderPipeline();
|
||||
}, { immediate: true, deep: true })
|
||||
}, { immediate: true, deep: true, flush: 'post' })
|
||||
|
||||
watch(() => viewMode.value, (mode) => {
|
||||
if ((mode === 'chunks' || mode === 'merged') && props.visible) {
|
||||
runMarkdownPostRenderPipeline();
|
||||
if (mode === 'chunks') {
|
||||
nextTick(() => maybeLoadMoreChunks());
|
||||
}
|
||||
}
|
||||
});
|
||||
}, { flush: 'post' });
|
||||
|
||||
watch(() => props.visible, (visible) => {
|
||||
if (visible && (viewMode.value === 'chunks' || viewMode.value === 'merged')) {
|
||||
runMarkdownPostRenderPipeline();
|
||||
}
|
||||
});
|
||||
}, { flush: 'post' });
|
||||
|
||||
// 渲染 Mermaid 图表的函数
|
||||
const renderMermaidDiagrams = async () => {
|
||||
try {
|
||||
const mermaidElements = mdContentWrap.value?.querySelectorAll('.mermaid');
|
||||
const mermaidElements = getMarkdownRenderRoot()?.querySelectorAll('.mermaid');
|
||||
console.log('[Mermaid] Found mermaid elements:', mermaidElements?.length);
|
||||
if (mermaidElements && mermaidElements.length > 0) {
|
||||
await mermaid.run({
|
||||
@@ -624,12 +661,13 @@ const handleMermaidClick = (e: Event) => {
|
||||
|
||||
// 为 Mermaid 容器绑定点击全屏事件(绑定在 div 上,不是 SVG 上)
|
||||
const bindMermaidClickEvents = () => {
|
||||
if (!mdContentWrap.value) {
|
||||
console.log('[Mermaid] mdContentWrap is null');
|
||||
const renderRoot = getMarkdownRenderRoot();
|
||||
if (!renderRoot) {
|
||||
console.log('[Mermaid] markdown render root is null');
|
||||
return;
|
||||
}
|
||||
// 绑定在 .mermaid div 上,而不是 SVG 上
|
||||
const mermaidDivs = mdContentWrap.value.querySelectorAll('.mermaid');
|
||||
const mermaidDivs = renderRoot.querySelectorAll('.mermaid');
|
||||
console.log('[Mermaid] Found mermaid divs:', mermaidDivs.length);
|
||||
mermaidDivs.forEach((div, index) => {
|
||||
const divEl = div as HTMLElement;
|
||||
@@ -663,6 +701,9 @@ const processMarkdown = (markdownText) => {
|
||||
// 处理被 <p> 包裹的表格行,转换为正常的表格行,并在前后补空行
|
||||
processedText = processedText.replace(/<p>\s*(\|[\s\S]*?\|)\s*<\/p>/gi, '\n$1\n');
|
||||
|
||||
// MarkItDown 常在表格前插入空行 + 分隔行,渲染会出现多余空行
|
||||
processedText = normalizeSpuriousTablePrefixes(processedText);
|
||||
|
||||
// 保留表格单元格中的 <br>,不转成换行,避免打散表格;其他区域原样交给 marked 处理
|
||||
|
||||
// 先预处理数学定界符,再做安全预处理
|
||||
@@ -683,7 +724,8 @@ const processMarkdown = (markdownText) => {
|
||||
};
|
||||
const handleClose = () => {
|
||||
emit("closeDoc", false);
|
||||
if (doc) doc.scrollTop = 0;
|
||||
const scrollEl = docScrollEl || findDocDrawerScrollEl();
|
||||
if (scrollEl) scrollEl.scrollTop = 0;
|
||||
viewMode.value = 'merged';
|
||||
};
|
||||
|
||||
@@ -973,19 +1015,41 @@ const downloadFile = () => {
|
||||
MessagePlugin.error(t('file.downloadFailed'));
|
||||
});
|
||||
};
|
||||
const requestNextChunkPage = () => {
|
||||
if (loadingChunks || props.details?.chunkLoading) return;
|
||||
const total = props.details?.total ?? 0;
|
||||
const loaded = props.details?.md?.length ?? 0;
|
||||
if (loaded >= total || total === 0) return;
|
||||
const pageNum = Math.ceil(total / CHUNK_PAGE_SIZE);
|
||||
if (page + 1 > pageNum) return;
|
||||
page++;
|
||||
loadingChunks = true;
|
||||
pendingRequestedPage = page;
|
||||
pendingChunksBeforeLoad = loaded;
|
||||
emit('getDoc', page);
|
||||
};
|
||||
|
||||
/** When the list is shorter than the drawer, scroll never fires — prefetch until scrollable or done. */
|
||||
const maybeLoadMoreChunks = () => {
|
||||
if (!props.visible || loadingChunks || props.details?.chunkLoading) return;
|
||||
const el = docScrollEl || findDocDrawerScrollEl();
|
||||
if (!el) return;
|
||||
const loaded = props.details?.md?.length ?? 0;
|
||||
const total = props.details?.total ?? 0;
|
||||
if (loaded >= total) return;
|
||||
const { scrollHeight, clientHeight } = el;
|
||||
if (scrollHeight <= clientHeight + 8) {
|
||||
requestNextChunkPage();
|
||||
}
|
||||
};
|
||||
|
||||
const handleDetailsScroll = () => {
|
||||
if (doc && !loadingChunks) {
|
||||
let pageNum = Math.ceil(props.details.total / 25);
|
||||
const { scrollTop, scrollHeight, clientHeight } = doc;
|
||||
if (scrollTop + clientHeight >= scrollHeight - 8) {
|
||||
if (props.details.md.length < props.details.total && page + 1 <= pageNum) {
|
||||
page++;
|
||||
loadingChunks = true;
|
||||
pendingRequestedPage = page;
|
||||
pendingChunksBeforeLoad = props.details.md.length;
|
||||
emit("getDoc", page);
|
||||
}
|
||||
}
|
||||
if (loadingChunks || props.details?.chunkLoading) return;
|
||||
const el = docScrollEl || findDocDrawerScrollEl();
|
||||
if (!el) return;
|
||||
const { scrollTop, scrollHeight, clientHeight } = el;
|
||||
if (scrollTop + clientHeight >= scrollHeight - 8) {
|
||||
requestNextChunkPage();
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@@ -1052,6 +1116,7 @@ const handleDetailsScroll = () => {
|
||||
</div>
|
||||
</t-drawer>
|
||||
|
||||
<div ref="docMarkdownRoot" class="doc-markdown-root">
|
||||
<!-- URL类型专属区域(保留:source 是真实链接,不与标题重复) -->
|
||||
<div v-if="details.type === 'url'" class="url_box">
|
||||
<span class="label">{{ $t('knowledgeBase.urlSource') }}</span>
|
||||
@@ -1203,6 +1268,7 @@ const handleDetailsScroll = () => {
|
||||
<DocumentPreview :knowledgeId="details.id" :fileType="details.file_type" :fileName="details.title"
|
||||
:active="viewMode === 'preview'" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</t-drawer>
|
||||
</div>
|
||||
|
||||
@@ -951,6 +951,8 @@ export default {
|
||||
selfHostedEndpoint: 'Self-hosted Endpoint',
|
||||
formulaRecognition: 'Formula Recognition',
|
||||
tableRecognition: 'Table Recognition',
|
||||
sealRecognition: 'Seal Recognition',
|
||||
chartRecognition: 'Chart Recognition',
|
||||
language: 'Language',
|
||||
testConnection: 'Test Connection',
|
||||
saveConfig: 'Save Configuration',
|
||||
@@ -971,6 +973,9 @@ export default {
|
||||
serverUrl: 'Server URL',
|
||||
vlmServerUrlPlaceholder: 'e.g. http://your-vllm-server:8000',
|
||||
vlmServerUrlHint: 'Required when Backend is vlm-http-client or hybrid-http-client',
|
||||
paddleocrVlEndpointPlaceholder: 'e.g. http://your-paddleocr-vl:8080',
|
||||
paddleocrVlEndpointHint: 'Base URL of the full PaddleOCR-VL pipeline service; no /layout-parsing suffix needed',
|
||||
paddleocrVlCloudTokenPlaceholder: 'PaddleOCR-VL AI Studio Token',
|
||||
},
|
||||
storage: {
|
||||
title: 'Storage Engine',
|
||||
@@ -2814,6 +2819,9 @@ export default {
|
||||
max_owned_per_user: 'Max tenants owned per user',
|
||||
default_storage_quota_gb: 'Default storage quota for new tenants (GB)',
|
||||
},
|
||||
asynq: {
|
||||
concurrency: 'Async task worker concurrency',
|
||||
},
|
||||
},
|
||||
enumLabels: {
|
||||
auth: {
|
||||
@@ -4240,6 +4248,14 @@ export default {
|
||||
name: 'MinerU Cloud',
|
||||
desc: 'MinerU Cloud API',
|
||||
},
|
||||
paddleocr_vl: {
|
||||
name: 'PaddleOCR-VL',
|
||||
desc: 'PaddleOCR-VL self-hosted service',
|
||||
},
|
||||
paddleocr_vl_cloud: {
|
||||
name: 'PaddleOCR-VL Cloud',
|
||||
desc: 'PaddleOCR-VL Cloud API',
|
||||
},
|
||||
weknoracloud: {
|
||||
name: 'WeKnora Cloud',
|
||||
desc: 'Document parsing via WeKnora Cloud',
|
||||
|
||||
@@ -811,6 +811,8 @@ export default {
|
||||
selfHostedEndpoint: '자체 호스팅 엔드포인트',
|
||||
formulaRecognition: '수식 인식',
|
||||
tableRecognition: '표 인식',
|
||||
sealRecognition: '인장 인식',
|
||||
chartRecognition: '차트 인식',
|
||||
language: '언어',
|
||||
testConnection: '연결 테스트',
|
||||
saveConfig: '설정 저장',
|
||||
@@ -831,6 +833,9 @@ export default {
|
||||
serverUrl: '서버 URL',
|
||||
vlmServerUrlPlaceholder: '예: http://your-vllm-server:8000',
|
||||
vlmServerUrlHint: 'Backend가 vlm-http-client 또는 hybrid-http-client인 경우 필요',
|
||||
paddleocrVlEndpointPlaceholder: '예: http://your-paddleocr-vl:8080',
|
||||
paddleocrVlEndpointHint: 'PaddleOCR-VL 전체 서비스(pipeline) 주소를 입력하세요. /layout-parsing 접미사는 불필요합니다',
|
||||
paddleocrVlCloudTokenPlaceholder: 'PaddleOCR-VL AI Studio Token',
|
||||
},
|
||||
storage: {
|
||||
title: '스토리지 엔진',
|
||||
@@ -2053,6 +2058,9 @@ export default {
|
||||
max_owned_per_user: "사용자당 최대 테넌트 수",
|
||||
default_storage_quota_gb: "신규 테넌트 기본 저장 용량 (GB)",
|
||||
},
|
||||
asynq: {
|
||||
concurrency: "비동기 작업 워커 동시 처리 수",
|
||||
},
|
||||
},
|
||||
enumLabels: {
|
||||
auth: {
|
||||
@@ -4302,6 +4310,14 @@ export default {
|
||||
name: 'MinerU Cloud',
|
||||
desc: 'MinerU Cloud API',
|
||||
},
|
||||
paddleocr_vl: {
|
||||
name: 'PaddleOCR-VL',
|
||||
desc: 'PaddleOCR-VL 자체 호스팅 서비스',
|
||||
},
|
||||
paddleocr_vl_cloud: {
|
||||
name: 'PaddleOCR-VL Cloud',
|
||||
desc: 'PaddleOCR-VL Cloud API',
|
||||
},
|
||||
weknoracloud: {
|
||||
name: 'WeKnora Cloud',
|
||||
desc: 'WeKnora Cloud를 통한 문서 파싱',
|
||||
|
||||
@@ -866,6 +866,8 @@ export default {
|
||||
selfHostedEndpoint: 'Собственная конечная точка',
|
||||
formulaRecognition: 'Распознавание формул',
|
||||
tableRecognition: 'Распознавание таблиц',
|
||||
sealRecognition: 'Распознавание печатей',
|
||||
chartRecognition: 'Распознавание диаграмм',
|
||||
language: 'Язык',
|
||||
testConnection: 'Проверить с текущими параметрами',
|
||||
saveConfig: 'Сохранить конфигурацию',
|
||||
@@ -882,7 +884,10 @@ export default {
|
||||
languagePlaceholder: 'напр. ch, en, ja (по умолчанию ch)',
|
||||
mineruCloudApiKeyPlaceholder: 'MinerU Cloud API Key',
|
||||
vlmLabel: 'vlm (визуальная языковая модель)',
|
||||
mineruHtmlLabel: 'MinerU-HTML (HTML парсинг)'
|
||||
mineruHtmlLabel: 'MinerU-HTML (HTML парсинг)',
|
||||
paddleocrVlEndpointPlaceholder: 'напр. http://your-paddleocr-vl:8080',
|
||||
paddleocrVlEndpointHint: 'Адрес полного сервиса PaddleOCR-VL (pipeline); суффикс /layout-parsing не требуется',
|
||||
paddleocrVlCloudTokenPlaceholder: 'Токен PaddleOCR-VL AI Studio'
|
||||
},
|
||||
storage: {
|
||||
title: 'Хранилище',
|
||||
@@ -1772,6 +1777,9 @@ export default {
|
||||
max_owned_per_user: 'Максимум тенантов на пользователя',
|
||||
default_storage_quota_gb: 'Квота хранилища для новых тенантов по умолчанию (ГБ)',
|
||||
},
|
||||
asynq: {
|
||||
concurrency: 'Параллелизм воркеров асинхронных задач',
|
||||
},
|
||||
},
|
||||
enumLabels: {
|
||||
auth: {
|
||||
@@ -3802,6 +3810,14 @@ export default {
|
||||
name: 'MinerU Cloud',
|
||||
desc: 'MinerU Cloud API',
|
||||
},
|
||||
paddleocr_vl: {
|
||||
name: 'PaddleOCR-VL',
|
||||
desc: 'Самостоятельно развёрнутый сервис PaddleOCR-VL',
|
||||
},
|
||||
paddleocr_vl_cloud: {
|
||||
name: 'PaddleOCR-VL Cloud',
|
||||
desc: 'PaddleOCR-VL Cloud API',
|
||||
},
|
||||
weknoracloud: {
|
||||
name: 'WeKnora Cloud',
|
||||
desc: 'Парсинг документов через WeKnora Cloud',
|
||||
|
||||
@@ -807,6 +807,8 @@ export default {
|
||||
selfHostedEndpoint: "自建端点",
|
||||
formulaRecognition: "公式识别",
|
||||
tableRecognition: "表格识别",
|
||||
sealRecognition: "印章识别",
|
||||
chartRecognition: "图表识别",
|
||||
language: "语言",
|
||||
testConnection: "测试连接",
|
||||
saveConfig: "保存配置",
|
||||
@@ -827,6 +829,9 @@ export default {
|
||||
serverUrl: "服务器地址",
|
||||
vlmServerUrlPlaceholder: "如 http://your-vllm-server:8000",
|
||||
vlmServerUrlHint: "当 Backend 选择 vlm-http-client 或 hybrid-http-client 时需要填写",
|
||||
paddleocrVlEndpointPlaceholder: "如 http://your-paddleocr-vl:8080",
|
||||
paddleocrVlEndpointHint: "填写 PaddleOCR-VL 完整服务(pipeline)地址,无需 /layout-parsing 后缀",
|
||||
paddleocrVlCloudTokenPlaceholder: "PaddleOCR-VL 飞桨星河社区 Token",
|
||||
},
|
||||
storage: {
|
||||
title: "存储引擎",
|
||||
@@ -2032,6 +2037,9 @@ export default {
|
||||
max_owned_per_user: "每用户最大租户数",
|
||||
default_storage_quota_gb: "新租户默认存储配额 (GB)",
|
||||
},
|
||||
asynq: {
|
||||
concurrency: "异步任务并发数",
|
||||
},
|
||||
},
|
||||
enumLabels: {
|
||||
auth: {
|
||||
@@ -4234,6 +4242,14 @@ export default {
|
||||
name: "MinerU Cloud",
|
||||
desc: "MinerU Cloud API",
|
||||
},
|
||||
paddleocr_vl: {
|
||||
name: "PaddleOCR-VL",
|
||||
desc: "PaddleOCR-VL 自部署服务",
|
||||
},
|
||||
paddleocr_vl_cloud: {
|
||||
name: "PaddleOCR-VL Cloud",
|
||||
desc: "PaddleOCR-VL 云 API",
|
||||
},
|
||||
weknoracloud: {
|
||||
name: "WeKnora Cloud",
|
||||
desc: "使用 WeKnora Cloud 进行文档解析",
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/** Matches a GFM alignment cell (---, :---, ---:, :---:). */
|
||||
const SEPARATOR_CELL = /^:?-{3,}:?$/;
|
||||
|
||||
function splitRowCells(line: string): string[] {
|
||||
const inner = line.trim();
|
||||
if (!inner.startsWith('|')) {
|
||||
return [];
|
||||
}
|
||||
let parts = inner.split('|');
|
||||
if (parts.length && parts[0].trim() === '') {
|
||||
parts = parts.slice(1);
|
||||
}
|
||||
if (parts.length && parts[parts.length - 1].trim() === '') {
|
||||
parts = parts.slice(0, -1);
|
||||
}
|
||||
return parts.map((part) => part.trim());
|
||||
}
|
||||
|
||||
function isTableRow(line: string): boolean {
|
||||
const stripped = line.trim();
|
||||
return stripped.startsWith('|') && stripped.includes('|', 1);
|
||||
}
|
||||
|
||||
function isSeparatorRow(line: string): boolean {
|
||||
const cells = splitRowCells(line);
|
||||
return cells.length > 0 && cells.every((cell) => SEPARATOR_CELL.test(cell));
|
||||
}
|
||||
|
||||
function isEmptyRow(line: string): boolean {
|
||||
const cells = splitRowCells(line);
|
||||
return cells.length > 0 && cells.every((cell) => cell === '');
|
||||
}
|
||||
|
||||
function separatorRowFor(headerLine: string): string {
|
||||
const cells = splitRowCells(headerLine);
|
||||
return `| ${cells.map(() => '---').join(' | ')} |`;
|
||||
}
|
||||
|
||||
function normalizeTableBlock(block: string[]): string[] {
|
||||
let rows = [...block];
|
||||
while (rows.length && isEmptyRow(rows[0])) {
|
||||
rows.shift();
|
||||
}
|
||||
if (rows.length && isSeparatorRow(rows[0])) {
|
||||
rows.shift();
|
||||
}
|
||||
if (rows.length >= 2 && !isSeparatorRow(rows[1])) {
|
||||
rows = [rows[0], separatorRowFor(rows[0]), ...rows.slice(1)];
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/** Fix MarkItDown-style tables: empty row + separator before real rows. */
|
||||
export function normalizeSpuriousTablePrefixes(content: string): string {
|
||||
const lines = content.split('\n');
|
||||
const out: string[] = [];
|
||||
let i = 0;
|
||||
while (i < lines.length) {
|
||||
if (!isTableRow(lines[i])) {
|
||||
out.push(lines[i]);
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
const block: string[] = [];
|
||||
while (i < lines.length && isTableRow(lines[i])) {
|
||||
block.push(lines[i]);
|
||||
i += 1;
|
||||
}
|
||||
out.push(...normalizeTableBlock(block));
|
||||
}
|
||||
return out.join('\n');
|
||||
}
|
||||
@@ -311,6 +311,60 @@
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Section 3 — paddleocr_vl 自建配置 -->
|
||||
<section v-if="currentEngine.Name === 'paddleocr_vl'" class="setting-drawer__section">
|
||||
<h4 class="setting-drawer__section-title">{{ $t('settings.parser.configSection', '配置') }}</h4>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label required">{{ t('settings.parser.selfHostedEndpoint') }}</label>
|
||||
<t-input
|
||||
v-model="config.paddleocr_vl_endpoint"
|
||||
:placeholder="$t('settings.parser.paddleocrVlEndpointPlaceholder')"
|
||||
clearable
|
||||
/>
|
||||
<p class="form-desc">{{ $t('settings.parser.paddleocrVlEndpointHint') }}</p>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ $t('settings.parser.featuresLabel', '识别选项') }}</label>
|
||||
<div class="form-toggles">
|
||||
<t-checkbox v-model="config.paddleocr_vl_use_seal_recognition">{{ $t('settings.parser.sealRecognition') }}</t-checkbox>
|
||||
<t-checkbox v-model="config.paddleocr_vl_use_chart_recognition">{{ $t('settings.parser.chartRecognition') }}</t-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Section 3 — paddleocr_vl_cloud 云 API 配置 -->
|
||||
<section v-if="currentEngine.Name === 'paddleocr_vl_cloud'" class="setting-drawer__section">
|
||||
<h4 class="setting-drawer__section-title">{{ $t('settings.parser.configSection', '配置') }}</h4>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label required">Token</label>
|
||||
<t-input
|
||||
v-model="config.paddleocr_vl_cloud_token"
|
||||
type="password"
|
||||
:placeholder="$t('settings.parser.paddleocrVlCloudTokenPlaceholder')"
|
||||
clearable
|
||||
>
|
||||
<template #prefix-icon><t-icon name="lock-on" /></template>
|
||||
</t-input>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<label class="form-label">Model</label>
|
||||
<t-input
|
||||
v-model="config.paddleocr_vl_cloud_model"
|
||||
placeholder="PaddleOCR-VL-1.6"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ $t('settings.parser.featuresLabel', '识别选项') }}</label>
|
||||
<div class="form-toggles">
|
||||
<t-checkbox v-model="config.paddleocr_vl_cloud_use_seal_recognition">{{ $t('settings.parser.sealRecognition') }}</t-checkbox>
|
||||
<t-checkbox v-model="config.paddleocr_vl_cloud_use_chart_recognition">{{ $t('settings.parser.chartRecognition') }}</t-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</SettingDrawer>
|
||||
</div>
|
||||
@@ -336,7 +390,7 @@ const { t } = useI18n()
|
||||
const uiStore = useUIStore()
|
||||
const authStore = useAuthStore()
|
||||
|
||||
const CONFIGURABLE_ENGINES = new Set(['mineru', 'mineru_cloud'])
|
||||
const CONFIGURABLE_ENGINES = new Set(['mineru', 'mineru_cloud', 'paddleocr_vl', 'paddleocr_vl_cloud'])
|
||||
|
||||
/** 各解析引擎的项目/官方文档地址 */
|
||||
const ENGINE_DOC_LINKS: Record<string, string> = {
|
||||
@@ -344,6 +398,8 @@ const ENGINE_DOC_LINKS: Record<string, string> = {
|
||||
markitdown: 'https://github.com/microsoft/markitdown',
|
||||
mineru: 'https://github.com/opendatalab/MinerU',
|
||||
mineru_cloud: 'https://mineru.net/apiManage/docs',
|
||||
paddleocr_vl: 'https://github.com/PaddlePaddle/PaddleOCR',
|
||||
paddleocr_vl_cloud: 'https://aistudio.baidu.com/paddleocr',
|
||||
}
|
||||
|
||||
/** 解析引擎配置默认值(与 DocReader/Python 侧一致) */
|
||||
@@ -363,6 +419,13 @@ const DEFAULT_PARSER_CONFIG: ParserEngineConfig = {
|
||||
mineru_cloud_enable_table: true,
|
||||
mineru_cloud_enable_ocr: true,
|
||||
mineru_cloud_language: 'ch',
|
||||
paddleocr_vl_endpoint: '',
|
||||
paddleocr_vl_use_seal_recognition: true,
|
||||
paddleocr_vl_use_chart_recognition: false,
|
||||
paddleocr_vl_cloud_token: '',
|
||||
paddleocr_vl_cloud_model: 'PaddleOCR-VL-1.6',
|
||||
paddleocr_vl_cloud_use_seal_recognition: true,
|
||||
paddleocr_vl_cloud_use_chart_recognition: false,
|
||||
}
|
||||
|
||||
const engines = ref<ParserEngineInfo[]>([])
|
||||
@@ -407,6 +470,8 @@ const ENGINE_ORDER: Record<string, number> = {
|
||||
markitdown: 3,
|
||||
mineru: 4,
|
||||
mineru_cloud: 5,
|
||||
paddleocr_vl: 6,
|
||||
paddleocr_vl_cloud: 7,
|
||||
}
|
||||
|
||||
const sortedEngines = computed(() => {
|
||||
@@ -491,6 +556,13 @@ async function loadConfig() {
|
||||
mineru_cloud_enable_table: data?.mineru_cloud_enable_table ?? DEFAULT_PARSER_CONFIG.mineru_cloud_enable_table ?? true,
|
||||
mineru_cloud_enable_ocr: data?.mineru_cloud_enable_ocr ?? DEFAULT_PARSER_CONFIG.mineru_cloud_enable_ocr ?? true,
|
||||
mineru_cloud_language: data?.mineru_cloud_language ?? DEFAULT_PARSER_CONFIG.mineru_cloud_language ?? 'ch',
|
||||
paddleocr_vl_endpoint: data?.paddleocr_vl_endpoint ?? DEFAULT_PARSER_CONFIG.paddleocr_vl_endpoint ?? '',
|
||||
paddleocr_vl_use_seal_recognition: data?.paddleocr_vl_use_seal_recognition ?? DEFAULT_PARSER_CONFIG.paddleocr_vl_use_seal_recognition ?? true,
|
||||
paddleocr_vl_use_chart_recognition: data?.paddleocr_vl_use_chart_recognition ?? DEFAULT_PARSER_CONFIG.paddleocr_vl_use_chart_recognition ?? false,
|
||||
paddleocr_vl_cloud_token: data?.paddleocr_vl_cloud_token ?? DEFAULT_PARSER_CONFIG.paddleocr_vl_cloud_token ?? '',
|
||||
paddleocr_vl_cloud_model: data?.paddleocr_vl_cloud_model ?? DEFAULT_PARSER_CONFIG.paddleocr_vl_cloud_model ?? 'PaddleOCR-VL-1.6',
|
||||
paddleocr_vl_cloud_use_seal_recognition: data?.paddleocr_vl_cloud_use_seal_recognition ?? DEFAULT_PARSER_CONFIG.paddleocr_vl_cloud_use_seal_recognition ?? true,
|
||||
paddleocr_vl_cloud_use_chart_recognition: data?.paddleocr_vl_cloud_use_chart_recognition ?? DEFAULT_PARSER_CONFIG.paddleocr_vl_cloud_use_chart_recognition ?? false,
|
||||
}
|
||||
} catch {
|
||||
config.value = { ...DEFAULT_PARSER_CONFIG }
|
||||
@@ -521,6 +593,13 @@ function buildConfigPayload(): ParserEngineConfig {
|
||||
mineru_cloud_enable_table: config.value.mineru_cloud_enable_table,
|
||||
mineru_cloud_enable_ocr: config.value.mineru_cloud_enable_ocr,
|
||||
mineru_cloud_language: config.value.mineru_cloud_language?.trim() ?? '',
|
||||
paddleocr_vl_endpoint: config.value.paddleocr_vl_endpoint?.trim() ?? '',
|
||||
paddleocr_vl_use_seal_recognition: config.value.paddleocr_vl_use_seal_recognition,
|
||||
paddleocr_vl_use_chart_recognition: config.value.paddleocr_vl_use_chart_recognition,
|
||||
paddleocr_vl_cloud_token: config.value.paddleocr_vl_cloud_token?.trim() ?? '',
|
||||
paddleocr_vl_cloud_model: config.value.paddleocr_vl_cloud_model?.trim() ?? '',
|
||||
paddleocr_vl_cloud_use_seal_recognition: config.value.paddleocr_vl_cloud_use_seal_recognition,
|
||||
paddleocr_vl_cloud_use_chart_recognition: config.value.paddleocr_vl_cloud_use_chart_recognition,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -739,7 +818,9 @@ onMounted(loadAll)
|
||||
color: #0089FF;
|
||||
}
|
||||
.engine-card--mineru .engine-card__badge,
|
||||
.engine-card--mineru_cloud .engine-card__badge {
|
||||
.engine-card--mineru_cloud .engine-card__badge,
|
||||
.engine-card--paddleocr_vl .engine-card__badge,
|
||||
.engine-card--paddleocr_vl_cloud .engine-card__badge {
|
||||
background: rgba(98, 53, 187, 0.12);
|
||||
color: #6235BB;
|
||||
}
|
||||
@@ -1086,7 +1167,9 @@ onMounted(loadAll)
|
||||
color: #0089FF;
|
||||
}
|
||||
.parser-engine-drawer--mineru .setting-drawer__header-icon,
|
||||
.parser-engine-drawer--mineru_cloud .setting-drawer__header-icon {
|
||||
.parser-engine-drawer--mineru_cloud .setting-drawer__header-icon,
|
||||
.parser-engine-drawer--paddleocr_vl .setting-drawer__header-icon,
|
||||
.parser-engine-drawer--paddleocr_vl_cloud .setting-drawer__header-icon {
|
||||
background: rgba(98, 53, 187, 0.12);
|
||||
color: #6235BB;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user