Merge branch 'main' into storage-allow-list
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -42,7 +42,7 @@
|
||||
</div>
|
||||
<div v-if="event.content && isEventExpanded(event.event_id)" class="action-details">
|
||||
<div class="thinking-detail-content markdown-content">
|
||||
<div v-for="(token, idx) in getTokens(event.content)" :key="idx" v-html="getTokenHTML(token)"></div>
|
||||
<div v-html="renderMarkdownContent(event.content)"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -64,7 +64,7 @@
|
||||
</div>
|
||||
<div v-if="event.tool_data?.thought && isEventExpanded(event.tool_call_id)" class="action-details">
|
||||
<div class="thinking-detail-content markdown-content">
|
||||
<div v-for="(token, idx) in getTokens(event.tool_data.thought)" :key="idx" v-html="getTokenHTML(token)"></div>
|
||||
<div v-html="renderMarkdownContent(event.tool_data.thought)"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -173,7 +173,7 @@
|
||||
</div>
|
||||
<div v-if="event.content && isEventExpanded(event.event_id)" class="action-details">
|
||||
<div class="thinking-detail-content markdown-content">
|
||||
<div v-for="(token, idx) in getTokens(event.content)" :key="idx" v-html="getTokenHTML(token)"></div>
|
||||
<div v-html="renderMarkdownContent(event.content)"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -195,7 +195,7 @@
|
||||
</div>
|
||||
<div v-if="event.tool_data?.thought && isEventExpanded(event.tool_call_id)" class="action-details">
|
||||
<div class="thinking-detail-content markdown-content">
|
||||
<div v-for="(token, idx) in getTokens(event.tool_data.thought)" :key="idx" v-html="getTokenHTML(token)"></div>
|
||||
<div v-html="renderMarkdownContent(event.tool_data.thought)"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -207,9 +207,9 @@
|
||||
v-if="event.content && event.content.trim()"
|
||||
class="answer-content markdown-content"
|
||||
>
|
||||
<div v-for="(token, idx) in getTokens(event.content)" :key="idx" v-html="getTokenHTML(token)"></div>
|
||||
<div v-html="renderMarkdownContent(event.content)"></div>
|
||||
</div>
|
||||
<div v-if="event.done" class="answer-toolbar">
|
||||
<div v-if="event.done && event.content && event.content.trim()" class="answer-toolbar">
|
||||
<t-button size="small" variant="outline" shape="round" @click.stop="handleCopyAnswer(event)" :title="$t('agent.copy')">
|
||||
<t-icon name="copy" />
|
||||
</t-button>
|
||||
@@ -335,18 +335,53 @@
|
||||
|
||||
<!-- Image Preview -->
|
||||
<picturePreview :reviewImg="imagePreviewVisible" :reviewUrl="imagePreviewUrl" @closePreImg="closeImagePreview" />
|
||||
|
||||
<!-- Wiki Page Detail Drawer -->
|
||||
<t-drawer
|
||||
v-model:visible="wikiDrawerVisible"
|
||||
:header="wikiDrawerPage?.title || ''"
|
||||
size="480px"
|
||||
:footer="false"
|
||||
placement="right"
|
||||
attach="body"
|
||||
:show-overlay="true"
|
||||
:close-btn="true"
|
||||
:close-on-overlay-click="true"
|
||||
class="wiki-graph-drawer"
|
||||
>
|
||||
<template v-if="wikiDrawerPage">
|
||||
<div class="wiki-reader-meta" style="margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center;">
|
||||
<div style="display: flex; align-items: center; gap: 12px;">
|
||||
<t-tag size="small" :theme="getTypeTheme(wikiDrawerPage.page_type)" variant="light-outline">
|
||||
{{ getTypeLabel(wikiDrawerPage.page_type) }}
|
||||
</t-tag>
|
||||
<span class="wiki-reader-meta-text">{{ $t('knowledgeEditor.wikiBrowser.version', { ver: wikiDrawerPage.version || 1 }) }}</span>
|
||||
</div>
|
||||
<t-link theme="primary" hover="color" @click="navigateToWikiGraph">
|
||||
<template #prefixIcon><t-icon name="chart-bubble" /></template>
|
||||
{{ $t('knowledgeEditor.wikiBrowser.viewInGraph') }}
|
||||
</t-link>
|
||||
</div>
|
||||
<div ref="wikiDrawerBodyRef" class="wiki-reader-body" v-html="wikiDrawerContent" @click="handleWikiDrawerClick"></div>
|
||||
</template>
|
||||
</t-drawer>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, onMounted, onBeforeUnmount, nextTick } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useRouter, useRoute } from 'vue-router';
|
||||
import { marked } from 'marked';
|
||||
import markedKatex from 'marked-katex-extension';
|
||||
import 'katex/dist/katex.min.css';
|
||||
import DOMPurify from 'dompurify';
|
||||
import ToolResultRenderer from './ToolResultRenderer.vue';
|
||||
import picturePreview from '@/components/picture-preview.vue';
|
||||
import { getChunkByIdOnly } from '@/api/knowledge-base';
|
||||
import { getWikiPage, type WikiPage } from '@/api/wiki';
|
||||
import { MessagePlugin } from 'tdesign-vue-next';
|
||||
import { useUIStore } from '@/stores/ui';
|
||||
import { useSettingsStore } from '@/stores/settings';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import i18n from '@/i18n';
|
||||
import { hydrateProtectedFileImages } from '@/utils/security';
|
||||
@@ -363,7 +398,10 @@ import {
|
||||
} from '@/utils/mermaidShared';
|
||||
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const uiStore = useUIStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
const authStore = useAuthStore();
|
||||
const { t } = useI18n();
|
||||
|
||||
ensureMermaidInitialized();
|
||||
@@ -378,11 +416,13 @@ const DOMPurifyConfig = {
|
||||
'svg', 'g', 'path', 'rect', 'circle', 'ellipse', 'line', 'polygon',
|
||||
'polyline', 'text', 'tspan', 'defs', 'marker', 'filter', 'use',
|
||||
'clippath', 'lineargradient', 'radialgradient', 'stop', 'pattern',
|
||||
'image', 'foreignobject', 'desc', 'title', 'switch', 'symbol', 'mask'
|
||||
'image', 'foreignobject', 'desc', 'title', 'switch', 'symbol', 'mask',
|
||||
// KaTeX MathML 支持的标签
|
||||
'math', 'annotation', 'semantics', 'mo', 'mi', 'mn', 'msup', 'mrow', 'mfrac', 'msqrt', 'mroot', 'mstyle'
|
||||
],
|
||||
ALLOWED_ATTR: [
|
||||
'href', 'title', 'target', 'rel', 'data-tooltip', 'data-url', 'data-kb-id',
|
||||
'data-chunk-id', 'data-doc', 'class', 'role', 'tabindex', 'src', 'alt', 'data-protected-src',
|
||||
'data-chunk-id', 'data-doc', 'data-slug', 'class', 'role', 'tabindex', 'src', 'alt', 'data-protected-src',
|
||||
'width', 'height', 'style', 'id',
|
||||
// Mermaid SVG 支持的属性
|
||||
'd', 'fill', 'stroke', 'stroke-width', 'stroke-linecap', 'stroke-linejoin',
|
||||
@@ -397,8 +437,11 @@ const DOMPurifyConfig = {
|
||||
'patternunits', 'patterntransform', 'clippathunits', 'maskunits',
|
||||
'filterunits', 'primitiveunits', 'xmlns', 'xmlns:xlink', 'xlink:href',
|
||||
'version', 'baseprofile', 'enable-background', 'overflow', 'visibility',
|
||||
'display', 'pointer-events', 'cursor', 'data-emit', 'direction'
|
||||
'display', 'pointer-events', 'cursor', 'data-emit', 'direction',
|
||||
// KaTeX MathML 支持的属性
|
||||
'mathvariant', 'encoding', 'aria-hidden'
|
||||
],
|
||||
USE_PROFILES: { html: true, svg: true, mathMl: true },
|
||||
// Allow provider:// URLs so they can be hydrated later.
|
||||
ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|(?:local|minio|cos|tos):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
|
||||
};
|
||||
@@ -478,7 +521,10 @@ const sanitizeForDisplay = (text: string): string => {
|
||||
});
|
||||
result = result.replace(ID_LABEL_RE, '');
|
||||
result = result.replace(UUID_RE, '');
|
||||
result = result.replace(/`\s*`/g, '');
|
||||
// Remove empty inline code like `` or ` ` while preserving triple-backtick
|
||||
// fenced code blocks (```). Without the lookaround the greedy pair match
|
||||
// would eat two of the three fence backticks and break code block rendering.
|
||||
result = result.replace(/(?<!`)`[ \t]*`(?!`)/g, '');
|
||||
result = result.replace(/\(\s*\)/g, '');
|
||||
return result;
|
||||
};
|
||||
@@ -500,6 +546,110 @@ const closeImagePreview = () => {
|
||||
imagePreviewVisible.value = false;
|
||||
};
|
||||
|
||||
// Wiki Drawer 状态
|
||||
const wikiDrawerVisible = ref(false);
|
||||
const wikiDrawerPage = ref<WikiPage | null>(null);
|
||||
const wikiDrawerBodyRef = ref<HTMLElement | null>(null);
|
||||
const currentWikiKbId = ref<string>('');
|
||||
|
||||
function getTypeTheme(type: string): string {
|
||||
const map: Record<string, string> = {
|
||||
summary: 'primary', entity: 'success', concept: 'warning',
|
||||
synthesis: 'primary', comparison: 'danger', index: 'default', log: 'default',
|
||||
};
|
||||
return map[type] || 'default';
|
||||
}
|
||||
|
||||
function getTypeLabel(type: string): string {
|
||||
const map: Record<string, string> = {
|
||||
summary: t('knowledgeEditor.wikiBrowser.filterSummary'),
|
||||
entity: t('knowledgeEditor.wikiBrowser.filterEntity'),
|
||||
concept: t('knowledgeEditor.wikiBrowser.filterConcept'),
|
||||
synthesis: t('knowledgeEditor.wikiBrowser.filterSynthesis'),
|
||||
comparison: t('knowledgeEditor.wikiBrowser.filterComparison'),
|
||||
index: 'Index',
|
||||
log: 'Log',
|
||||
};
|
||||
return map[type] || type;
|
||||
}
|
||||
|
||||
const wikiDrawerContent = computed(() => {
|
||||
if (!wikiDrawerPage.value) return '';
|
||||
const content = wikiDrawerPage.value.content || '';
|
||||
|
||||
// Pre-process wiki links [[slug|name]] to custom HTML tags for the drawer
|
||||
let preprocessed = content.replace(/\[\[([^\]]+)\]\]/g, (_, inner: string) => {
|
||||
const pipeIdx = inner.indexOf('|');
|
||||
const slug = pipeIdx > 0 ? inner.substring(0, pipeIdx).trim() : inner.trim();
|
||||
let display = slug;
|
||||
if (pipeIdx > 0) {
|
||||
display = inner.substring(pipeIdx + 1).trim();
|
||||
} else {
|
||||
const parts = slug.split('/');
|
||||
display = parts.length > 1 ? parts.slice(1).join('/') : slug;
|
||||
}
|
||||
return `<a href="#" class="wiki-content-link citation-wiki" data-slug="${escapeHtml(slug)}">${escapeHtml(display)}</a>`;
|
||||
});
|
||||
|
||||
return marked.parse(preprocessed, { breaks: true, async: false }) as string;
|
||||
});
|
||||
|
||||
watch(wikiDrawerContent, async () => {
|
||||
await nextTick();
|
||||
if (wikiDrawerBodyRef.value) {
|
||||
await hydrateProtectedFileImages(wikiDrawerBodyRef.value);
|
||||
}
|
||||
});
|
||||
|
||||
const openWikiDrawer = async (kbId: string, slug: string) => {
|
||||
if (!kbId || !slug) return;
|
||||
try {
|
||||
currentWikiKbId.value = kbId;
|
||||
const res = await getWikiPage(kbId, slug);
|
||||
wikiDrawerPage.value = (res as any).data || res as any;
|
||||
wikiDrawerVisible.value = true;
|
||||
} catch (e) {
|
||||
console.error(`Failed to load page ${slug}:`, e);
|
||||
MessagePlugin.warning(t('agentStream.citation.loadFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
const navigateToWikiGraph = () => {
|
||||
if (currentWikiKbId.value && wikiDrawerPage.value?.slug) {
|
||||
wikiDrawerVisible.value = false;
|
||||
try {
|
||||
router.push(`/platform/knowledge-bases/${currentWikiKbId.value}?tab=graph&slug=${encodeURIComponent(wikiDrawerPage.value.slug)}`);
|
||||
} catch (error) {
|
||||
console.error('Failed to navigate to wiki graph:', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleWikiDrawerClick = (e: MouseEvent) => {
|
||||
const target = e.target as HTMLElement;
|
||||
if (target.closest('.citation-wiki')) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const slug = target.closest('.citation-wiki')?.getAttribute('data-slug');
|
||||
if (slug) openWikiDrawer(currentWikiKbId.value, slug);
|
||||
} else if (target.tagName.toLowerCase() === 'img') {
|
||||
e.preventDefault();
|
||||
const src = target.getAttribute('src');
|
||||
if (src) openImagePreview(src);
|
||||
} else {
|
||||
// allow link navigation inside drawer
|
||||
const aEl = target.closest?.('a') as HTMLAnchorElement | null;
|
||||
// @ts-ignore
|
||||
if (aEl && aEl.href && window.runtime && window.runtime.BrowserOpenURL) {
|
||||
if (aEl.href.startsWith('http://') || aEl.href.startsWith('https://')) {
|
||||
e.preventDefault();
|
||||
// @ts-ignore
|
||||
window.runtime.BrowserOpenURL(aEl.href);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 浮层状态(Web/KB 共用)
|
||||
const KB_SNIPPET_LIMIT = 600;
|
||||
|
||||
@@ -586,6 +736,16 @@ const props = defineProps<{
|
||||
|
||||
// Configure marked for security
|
||||
marked.use({});
|
||||
marked.use(markedKatex({ throwOnError: false }));
|
||||
|
||||
const preprocessMathDelimiters = (rawText: string): string => {
|
||||
if (!rawText || typeof rawText !== 'string') {
|
||||
return '';
|
||||
}
|
||||
return rawText
|
||||
.replace(/\\\[([\s\S]*?)\\\]/g, '$$$$$1$$$$')
|
||||
.replace(/\\\(([\s\S]*?)\\\)/g, '$$$1$$');
|
||||
};
|
||||
|
||||
// Event stream
|
||||
const eventStream = computed(() => props.session?.agentEventStream || []);
|
||||
@@ -734,6 +894,19 @@ const finalContent = computed(() => {
|
||||
return { type: 'answer' };
|
||||
}
|
||||
|
||||
// Do NOT fall back to re-rendering the last thinking event when the
|
||||
// intermediate-steps tree already shows it — that would duplicate the
|
||||
// thinking card below the tree. The fallback is only meaningful for
|
||||
// legacy conversations where the tree is absent. Also skip for
|
||||
// user-stopped conversations which have no final answer to fall back to.
|
||||
if (shouldShowCollapsedSteps.value) {
|
||||
return null;
|
||||
}
|
||||
const wasStopped = stream.some((e: any) => e.type === 'stop');
|
||||
if (wasStopped) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Fallback: if no answer content (legacy path or LLM didn't call final_answer),
|
||||
// use last thinking as final content
|
||||
const thinkingEvents = stream.filter((e: any) => e.type === 'thinking' && e.content && e.content.trim());
|
||||
@@ -911,6 +1084,14 @@ const displayEvents = computed(() => {
|
||||
return answerEvents;
|
||||
}
|
||||
|
||||
// If the intermediate-steps tree is active, all thinking/tool_call events
|
||||
// are already rendered there. Showing anything else here would duplicate
|
||||
// them. This covers both the user-stopped case and any completion path
|
||||
// that didn't produce an answer event.
|
||||
if (shouldShowCollapsedSteps.value) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Fallback: if no answer events, show last thinking (legacy compatibility)
|
||||
const final = finalContent.value;
|
||||
if (!final) {
|
||||
@@ -1024,13 +1205,14 @@ type KbTooltipState = {
|
||||
|
||||
const kbChunkDetails = ref<Record<string, KbTooltipState>>({});
|
||||
|
||||
const escapeHtml = (value: string): string =>
|
||||
value
|
||||
function escapeHtml(value: string): string {
|
||||
return value
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
const buildKbTooltipContent = (content: string): string => {
|
||||
const escapedContent = escapeHtml(content).replace(/\n/g, '<br>');
|
||||
@@ -1185,6 +1367,49 @@ const onHoverOut = (e: Event) => {
|
||||
scheduleFloatClose();
|
||||
};
|
||||
|
||||
const getKbIdForWiki = (slug: string): string => {
|
||||
if (route.params.kbId) return route.params.kbId as string;
|
||||
|
||||
// The backend ships `found_kbs` as a map<slug, string[]> — a single slug can
|
||||
// legitimately resolve to more than one KB when multiple wiki KBs are in
|
||||
// scope. For navigation we just pick the first one; cross-KB disambiguation
|
||||
// (if ever needed) can layer on top. We also defensively handle the legacy
|
||||
// string shape in case older tool outputs are still cached in a session.
|
||||
const pickKbId = (v: unknown): string => {
|
||||
if (!v) return '';
|
||||
if (typeof v === 'string') return v;
|
||||
if (Array.isArray(v)) {
|
||||
for (const item of v) {
|
||||
if (typeof item === 'string' && item) return item;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
// Try to extract from agent event stream (retrieval pipeline). Walk
|
||||
// backwards so we prefer the most recent tool call's mapping.
|
||||
if (props.session?.agentEventStream) {
|
||||
for (let i = props.session.agentEventStream.length - 1; i >= 0; i--) {
|
||||
const event = props.session.agentEventStream[i];
|
||||
const foundKbs = event?.tool_data?.found_kbs;
|
||||
if (event.type === 'tool_call' && foundKbs) {
|
||||
const hit = pickKbId(foundKbs[slug]);
|
||||
if (hit) return hit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallbacks
|
||||
const selectedKbs = settingsStore.getSelectedKnowledgeBases();
|
||||
if (selectedKbs && selectedKbs.length > 0) return selectedKbs[0];
|
||||
|
||||
if (authStore.knowledgeBases && authStore.knowledgeBases.length > 0) {
|
||||
return authStore.knowledgeBases[0].id;
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
const onRootClick = (e: Event) => {
|
||||
const target = e.target as HTMLElement;
|
||||
if (!target) return;
|
||||
@@ -1228,6 +1453,24 @@ const onRootClick = (e: Event) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle wiki link clicks -> navigate to KB wiki browser page
|
||||
const wikiEl = target.closest?.('.citation-wiki') as HTMLElement | null;
|
||||
if (wikiEl && wikiEl.getAttribute('data-slug')) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const slug = wikiEl.getAttribute('data-slug');
|
||||
|
||||
// Determine the relevant KB ID
|
||||
const kbId = getKbIdForWiki(slug);
|
||||
|
||||
if (kbId && slug) {
|
||||
openWikiDrawer(kbId, slug);
|
||||
} else {
|
||||
MessagePlugin.warning(t('agentStream.citation.noKbForWiki'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle generic a clicks (especially in Wails desktop)
|
||||
const aEl = target.closest?.('a') as HTMLAnchorElement | null;
|
||||
// @ts-ignore
|
||||
@@ -1271,6 +1514,24 @@ const onRootKeydown = (e: KeyboardEvent) => {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle wiki citation keyboard -> navigate to KB wiki browser
|
||||
const wikiEl = target.closest?.('.citation-wiki') as HTMLElement | null;
|
||||
if (wikiEl) {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
const slug = wikiEl.getAttribute('data-slug');
|
||||
|
||||
const kbId = getKbIdForWiki(slug || '');
|
||||
|
||||
if (kbId && slug) {
|
||||
openWikiDrawer(kbId, slug);
|
||||
} else {
|
||||
MessagePlugin.warning(t('agentStream.citation.noKbForWiki'));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
@@ -1389,13 +1650,42 @@ const preprocessMarkdown = (contentStr: string): string => {
|
||||
const displayDoc = escapeHtml(truncateMiddle(doc));
|
||||
return `<span class="citation citation-kb" data-kb-id="${safeKbId}" data-chunk-id="${safeChunkId}" data-doc="${safeDoc}" role="button" tabindex="0"><span class="citation-icon kb"></span><span class="citation-text">${displayDoc}</span><span class="citation-tip"><span class="t-popup__content"><span class="tip-loading">${t('agentStream.citation.loading')}</span></span></span></span>`;
|
||||
}
|
||||
)
|
||||
.replace(
|
||||
/\[\[([^\]]+)\]\]/g,
|
||||
(match, inner: string) => {
|
||||
const pipeIdx = inner.indexOf('|');
|
||||
const slug = pipeIdx > 0 ? inner.substring(0, pipeIdx).trim() : inner.trim();
|
||||
let display = slug;
|
||||
if (pipeIdx > 0) {
|
||||
display = inner.substring(pipeIdx + 1).trim();
|
||||
} else {
|
||||
// Fallback: strip type prefix like "summary/" or "concept/"
|
||||
const parts = slug.split('/');
|
||||
display = parts.length > 1 ? parts.slice(1).join('/') : slug;
|
||||
}
|
||||
|
||||
// Bail out on empty slug; otherwise accept any non-empty slug.
|
||||
// Structural pages like "index" and "log" have no slash but are
|
||||
// still valid targets — the drawer renderer already treats them
|
||||
// as such, so the chat bubble must match.
|
||||
if (!slug) return match;
|
||||
|
||||
const safeSlug = escapeHtml(slug);
|
||||
const safeDisplay = escapeHtml(display);
|
||||
return `<a href="#" class="wiki-content-link citation-wiki" data-slug="${safeSlug}">${safeDisplay}</a>`;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// Get tokens from markdown content (with sanitization for user-friendly display)
|
||||
const getTokens = (content: any) => {
|
||||
// 自定义渲染器 - 支持 Mermaid
|
||||
const agentRenderer = new marked.Renderer();
|
||||
agentRenderer.code = createMermaidCodeRenderer('mermaid-agent');
|
||||
|
||||
// 单次渲染 Markdown 内容(替代 token-by-token,修复 KaTeX 公式在 streaming 时闪烁消失的问题)
|
||||
const renderMarkdownContent = (content: any): string => {
|
||||
const contentStr = typeof content === 'string' ? content : String(content || '');
|
||||
if (!contentStr.trim()) return [];
|
||||
if (!contentStr.trim()) return '';
|
||||
|
||||
// Extract <kb.../> and <web.../> tags before sanitization to prevent
|
||||
// sanitizeForDisplay from stripping chunk_id labels and UUIDs inside them.
|
||||
@@ -1415,32 +1705,29 @@ const getTokens = (content: any) => {
|
||||
return `\x00IMG${idx}\x00`;
|
||||
});
|
||||
|
||||
let sanitized = sanitizeForDisplay(preservedWithImages);
|
||||
// Preserve wiki links [[slug|name]]
|
||||
const wikiPlaceholders: string[] = [];
|
||||
const preservedWithWiki = preservedWithImages.replace(/\[\[([^\]]+)\]\]/g, (match) => {
|
||||
const idx = wikiPlaceholders.length;
|
||||
wikiPlaceholders.push(match);
|
||||
return `\x00WIKI${idx}\x00`;
|
||||
});
|
||||
|
||||
let sanitized = sanitizeForDisplay(preservedWithWiki);
|
||||
|
||||
// Restore preserved wiki links
|
||||
sanitized = sanitized.replace(/\x00WIKI(\d+)\x00/g, (_, idx) => wikiPlaceholders[Number(idx)]);
|
||||
|
||||
// Restore preserved images
|
||||
sanitized = sanitized.replace(/\x00IMG(\d+)\x00/g, (_, idx) => imagePlaceholders[Number(idx)]);
|
||||
|
||||
|
||||
// Restore preserved tags
|
||||
sanitized = sanitized.replace(/\x00TAG(\d+)\x00/g, (_, idx) => tagPlaceholders[Number(idx)]);
|
||||
|
||||
const processed = preprocessMarkdown(sanitized);
|
||||
return marked.lexer(processed);
|
||||
};
|
||||
|
||||
// 自定义渲染器 - 支持 Mermaid
|
||||
const agentRenderer = new marked.Renderer();
|
||||
agentRenderer.code = createMermaidCodeRenderer('mermaid-agent');
|
||||
|
||||
// Render HTML from a single token
|
||||
const getTokenHTML = (token: any): string => {
|
||||
try {
|
||||
const html = marked.parser([token], { renderer: agentRenderer });
|
||||
const protectedHTML = protectProviderImageSrcInHTML(html);
|
||||
return DOMPurify.sanitize(protectedHTML, DOMPurifyConfig);
|
||||
} catch (e) {
|
||||
console.error('Token rendering error:', e);
|
||||
return '';
|
||||
}
|
||||
const processed = preprocessMarkdown(preprocessMathDelimiters(sanitized));
|
||||
const html = marked.parse(processed, { renderer: agentRenderer }) as string;
|
||||
const protectedHTML = protectProviderImageSrcInHTML(html);
|
||||
return DOMPurify.sanitize(protectedHTML, DOMPurifyConfig);
|
||||
};
|
||||
|
||||
// Legacy Markdown rendering function (kept for summaries)
|
||||
@@ -1449,7 +1736,7 @@ const renderMarkdown = (content: any): string => {
|
||||
if (!contentStr.trim()) return '';
|
||||
|
||||
try {
|
||||
const processed = preprocessMarkdown(contentStr);
|
||||
const processed = preprocessMarkdown(preprocessMathDelimiters(contentStr));
|
||||
const html = marked.parse(processed, { renderer: agentRenderer }) as string;
|
||||
if (!html) return '';
|
||||
|
||||
@@ -2867,6 +3154,29 @@ const handleAddToKnowledge = (answerEvent: any) => {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Inline wiki link style for chat bubbles — brand-blue dashed underline,
|
||||
matching the style used inside the wiki drawer. Rendered inline with
|
||||
the surrounding text, NOT as a pill, so it reads like a regular link. */
|
||||
:deep(a.wiki-content-link) {
|
||||
color: var(--td-brand-color);
|
||||
text-decoration: none;
|
||||
border-bottom: 1px dashed var(--td-brand-color);
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
transition: border-bottom-style 0.15s ease;
|
||||
}
|
||||
|
||||
:deep(a.wiki-content-link:hover) {
|
||||
border-bottom-style: solid;
|
||||
text-decoration: none !important;
|
||||
}
|
||||
|
||||
:deep(a.wiki-content-link:focus-visible) {
|
||||
outline: 2px solid var(--td-brand-color);
|
||||
outline-offset: 2px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.tool-arguments-wrapper {
|
||||
margin-top: 8px;
|
||||
padding: 0 10px;
|
||||
@@ -3012,6 +3322,114 @@ const handleAddToKnowledge = (answerEvent: any) => {
|
||||
</style>
|
||||
|
||||
<style lang="less">
|
||||
/* Global styles for teleported components */
|
||||
|
||||
.wiki-graph-drawer {
|
||||
box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
|
||||
|
||||
.wiki-reader-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.wiki-reader-meta-text {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.wiki-reader-body {
|
||||
line-height: 1.6;
|
||||
font-size: 14px;
|
||||
color: var(--td-text-color-primary);
|
||||
|
||||
h1 { font-size: 24px; margin: 28px 0 16px; font-weight: 600; line-height: 1.4; }
|
||||
h2 { font-size: 18px; margin: 24px 0 12px; font-weight: 600; line-height: 1.4; }
|
||||
h3 { font-size: 16px; margin: 20px 0 10px; font-weight: 600; line-height: 1.5; }
|
||||
h4, h5, h6 { font-size: 14px; margin: 16px 0 8px; font-weight: 600; line-height: 1.5; }
|
||||
|
||||
p { margin: 0 0 14px; }
|
||||
|
||||
ul, ol {
|
||||
margin: 0 0 14px;
|
||||
padding-left: 24px;
|
||||
}
|
||||
li {
|
||||
margin-bottom: 6px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
li > p {
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin: 0 0 14px;
|
||||
padding: 10px 16px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-left: 4px solid var(--td-component-border);
|
||||
border-radius: 0 4px 4px 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: monospace;
|
||||
font-size: 13px;
|
||||
padding: 2px 4px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-radius: 4px;
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
|
||||
pre {
|
||||
margin: 0 0 14px;
|
||||
padding: 12px 16px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-radius: 6px;
|
||||
overflow-x: auto;
|
||||
|
||||
code {
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
}
|
||||
}
|
||||
|
||||
p:has(img) {
|
||||
text-align: center;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: 13px;
|
||||
margin-top: 16px;
|
||||
margin-bottom: 24px;
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
max-height: 400px;
|
||||
object-fit: contain;
|
||||
border-radius: 6px;
|
||||
display: block;
|
||||
margin: 0 auto 8px;
|
||||
cursor: zoom-in;
|
||||
transition: opacity 0.2s;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
a.wiki-content-link {
|
||||
color: var(--td-brand-color);
|
||||
text-decoration: none;
|
||||
border-bottom: 1px dashed var(--td-brand-color);
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
&:hover {
|
||||
border-bottom-style: solid;
|
||||
text-decoration: none !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Dark mode: invert agent icon (uses currentColor which doesn't work in <img>)
|
||||
html[theme-mode="dark"] .tree-root-title img {
|
||||
filter: invert(1);
|
||||
|
||||
@@ -73,6 +73,12 @@
|
||||
:data="toolData as GrepResultsData"
|
||||
/>
|
||||
|
||||
<!-- Wiki Edit Results Display -->
|
||||
<WikiEditResult
|
||||
v-else-if="displayType === 'wiki_write_page' || displayType === 'wiki_replace_text' || displayType === 'wiki_rename_page' || displayType === 'wiki_delete_page'"
|
||||
:data="toolData as WikiEditData"
|
||||
/>
|
||||
|
||||
<!-- Fallback: Display raw output -->
|
||||
<div v-else class="fallback-output">
|
||||
<div class="fallback-header">
|
||||
@@ -100,7 +106,8 @@ import type {
|
||||
DatabaseQueryData,
|
||||
WebSearchResultsData,
|
||||
WebFetchResultsData,
|
||||
GrepResultsData
|
||||
GrepResultsData,
|
||||
WikiEditData
|
||||
} from '@/types/tool-results';
|
||||
|
||||
import SearchResults from './tool-results/SearchResults.vue';
|
||||
@@ -115,6 +122,7 @@ import DatabaseQuery from './tool-results/DatabaseQuery.vue';
|
||||
import WebSearchResults from './tool-results/WebSearchResults.vue';
|
||||
import WebFetchResults from './tool-results/WebFetchResults.vue';
|
||||
import GrepResults from './tool-results/GrepResults.vue';
|
||||
import WikiEditResult from './tool-results/WikiEditResult.vue';
|
||||
|
||||
interface Props {
|
||||
displayType?: DisplayType;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="bot_msg">
|
||||
<div class="bot_msg" :class="{ 'is-embedded': embeddedMode }">
|
||||
<div style="display: flex;flex-direction: column; gap:8px">
|
||||
<!-- 显示@的知识库和文件(非 Agent 模式下显示) -->
|
||||
<div v-if="!session.isAgentMode && mentionedItems && mentionedItems.length > 0" class="mentioned_items">
|
||||
@@ -27,8 +27,7 @@
|
||||
<!-- 直接渲染完整内容,避免切分导致的问题,样式与 thinking 一致 -->
|
||||
<!-- 只有当有实际内容时才显示包围框 -->
|
||||
<div class="content-wrapper" v-if="hasActualContent">
|
||||
<div class="ai-markdown-template markdown-content">
|
||||
<div v-for="(token, index) in markdownTokens" :key="index" v-html="renderToken(token)"></div>
|
||||
<div class="ai-markdown-template markdown-content" v-html="renderedHTML">
|
||||
</div>
|
||||
</div>
|
||||
<!-- Streaming indicator (non-Agent mode) -->
|
||||
@@ -62,6 +61,8 @@
|
||||
<script setup>
|
||||
import { onMounted, onBeforeUnmount, watch, computed, ref, reactive, defineProps, nextTick, onUpdated } from 'vue';
|
||||
import { marked } from 'marked';
|
||||
import markedKatex from 'marked-katex-extension';
|
||||
import 'katex/dist/katex.min.css';
|
||||
import docInfo from './docInfo.vue';
|
||||
import deepThink from './deepThink.vue';
|
||||
import AgentStreamDisplay from './AgentStreamDisplay.vue';
|
||||
@@ -86,6 +87,17 @@ marked.use({
|
||||
breaks: true, // 全局启用单个换行支持
|
||||
});
|
||||
|
||||
marked.use(markedKatex({ throwOnError: false }));
|
||||
|
||||
const preprocessMathDelimiters = (rawText) => {
|
||||
if (!rawText || typeof rawText !== 'string') {
|
||||
return '';
|
||||
}
|
||||
return rawText
|
||||
.replace(/\\\[([\s\S]*?)\\\]/g, '$$$$$1$$$$')
|
||||
.replace(/\\\(([\s\S]*?)\\\)/g, '$$$1$$');
|
||||
};
|
||||
|
||||
ensureMermaidInitialized();
|
||||
|
||||
const emit = defineEmits(['scroll-bottom'])
|
||||
@@ -114,6 +126,10 @@ const props = defineProps({
|
||||
isFirstEnter: {
|
||||
type: Boolean,
|
||||
required: false
|
||||
},
|
||||
embeddedMode: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
});
|
||||
|
||||
@@ -147,19 +163,15 @@ const mentionedItems = computed(() => {
|
||||
return props.session?.mentioned_items || [];
|
||||
});
|
||||
|
||||
const markdownTokens = computed(() => {
|
||||
// 单次渲染整个 Markdown 内容(替代 token-by-token,修复 KaTeX 公式在 streaming 时闪烁消失的问题)
|
||||
const renderedHTML = computed(() => {
|
||||
const text = props.content || props.session?.content || '';
|
||||
if (!text || typeof text !== 'string') {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!text || typeof text !== 'string') return '';
|
||||
const processed = replaceIncompleteImageWithPlaceholder(text);
|
||||
|
||||
// 首先对 Markdown 内容进行安全处理
|
||||
const safeMarkdown = safeMarkdownToHTML(processed);
|
||||
|
||||
// 使用 marked.lexer 分词
|
||||
return marked.lexer(safeMarkdown);
|
||||
const safeText = preprocessMathDelimiters(processed);
|
||||
const safeMarkdown = safeMarkdownToHTML(safeText);
|
||||
const html = marked.parse(safeMarkdown, { renderer: customRenderer, breaks: true });
|
||||
return sanitizeHTML(html);
|
||||
});
|
||||
|
||||
// 计算属性:判断是否有实际内容(非空且不只是空白)
|
||||
@@ -168,31 +180,6 @@ const hasActualContent = computed(() => {
|
||||
return text && text.trim().length > 0;
|
||||
});
|
||||
|
||||
// 渲染单个 token 为 HTML
|
||||
const renderToken = (token) => {
|
||||
try {
|
||||
// 创建临时的 marked 配置
|
||||
const markedOptions = {
|
||||
renderer: customRenderer,
|
||||
breaks: true
|
||||
};
|
||||
|
||||
// 解析单个 token
|
||||
// marked.parser 接受 token 数组
|
||||
let html = marked.parser([token], markedOptions);
|
||||
|
||||
// 使用 DOMPurify 进行最终的安全清理
|
||||
return sanitizeHTML(html);
|
||||
} catch (e) {
|
||||
console.error('Token rendering error:', e);
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
const myMarkdown = (res) => {
|
||||
return marked.parse(res, { renderer })
|
||||
}
|
||||
|
||||
// 获取实际内容
|
||||
const getActualContent = () => {
|
||||
return (props.content || props.session?.content || '').trim();
|
||||
@@ -288,6 +275,16 @@ onBeforeUnmount(() => {
|
||||
@import '../../../components/css/markdown.less';
|
||||
@import '../../../components/css/chat-message-shared.less';
|
||||
|
||||
.bot_msg {
|
||||
&.is-embedded {
|
||||
width: 100%;
|
||||
|
||||
:deep(.agent-stream-display) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 内容包装器 - 与 Agent 模式的 answer 样式一致
|
||||
.content-wrapper {
|
||||
background: var(--td-bg-color-container);
|
||||
|
||||
@@ -197,6 +197,7 @@ const getWebSearchDisplayText = (item) => {
|
||||
background-color: var(--td-bg-color-container);
|
||||
border: .5px solid var(--td-component-stroke);
|
||||
box-shadow: 0 2px 4px rgba(7, 192, 95, 0.08);
|
||||
box-sizing: border-box;
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
<template>
|
||||
<div class="wiki-edit-result">
|
||||
<div class="result-card wiki-card">
|
||||
<div class="result-header wiki-header">
|
||||
<div class="result-title">
|
||||
<span class="wiki-icon" :class="actionClass">{{ actionIcon }}</span>
|
||||
<span class="wiki-title-text">{{ headerTitle }}</span>
|
||||
</div>
|
||||
<div class="result-meta">
|
||||
<span class="action-badge" :class="actionClass">{{ actionLabel }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="result-content expanded">
|
||||
<div class="info-section">
|
||||
<!-- wiki_write_page -->
|
||||
<template v-if="data.display_type === 'wiki_write_page'">
|
||||
<div class="info-field">
|
||||
<span class="field-label">{{ $t('chat.wikiFieldSlug') }}</span>
|
||||
<span class="field-value"><code>{{ data.slug }}</code></span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">{{ $t('chat.wikiFieldTitle') }}</span>
|
||||
<span class="field-value">{{ data.title }}</span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">{{ $t('chat.wikiFieldPageType') }}</span>
|
||||
<span class="field-value"><code>{{ data.page_type }}</code></span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">{{ $t('chat.wikiFieldSummary') }}</span>
|
||||
<span class="field-value">{{ data.summary }}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- wiki_replace_text -->
|
||||
<template v-else-if="data.display_type === 'wiki_replace_text'">
|
||||
<div class="info-field">
|
||||
<span class="field-label">{{ $t('chat.wikiFieldSlug') }}</span>
|
||||
<span class="field-value"><code>{{ data.slug }}</code></span>
|
||||
</div>
|
||||
<div class="info-field" v-if="data.title">
|
||||
<span class="field-label">{{ $t('chat.wikiFieldTitle') }}</span>
|
||||
<span class="field-value">{{ data.title }}</span>
|
||||
</div>
|
||||
<div class="diff-block">
|
||||
<div class="diff-line diff-old">
|
||||
<span class="diff-marker">-</span>
|
||||
<span class="diff-text">{{ data.old_text }}</span>
|
||||
</div>
|
||||
<div class="diff-line diff-new">
|
||||
<span class="diff-marker">+</span>
|
||||
<span class="diff-text">{{ data.new_text }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- wiki_rename_page -->
|
||||
<template v-else-if="data.display_type === 'wiki_rename_page'">
|
||||
<div class="info-field" v-if="data.title">
|
||||
<span class="field-label">{{ $t('chat.wikiFieldTitle') }}</span>
|
||||
<span class="field-value">{{ data.title }}</span>
|
||||
</div>
|
||||
<div class="rename-visual">
|
||||
<code class="slug-old">{{ data.old_slug }}</code>
|
||||
<span class="rename-arrow">→</span>
|
||||
<code class="slug-new">{{ data.new_slug }}</code>
|
||||
</div>
|
||||
<div class="info-field" v-if="data.updated_count > 0">
|
||||
<span class="field-label">{{ $t('chat.wikiFieldAffectedPages') }}</span>
|
||||
<span class="field-value">{{ $t('chat.wikiAffectedCount', { count: data.updated_count }) }}</span>
|
||||
</div>
|
||||
<div class="affected-list" v-if="data.affected_pages?.length">
|
||||
<code v-for="slug in data.affected_pages" :key="slug" class="affected-slug">{{ slug }}</code>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- wiki_delete_page -->
|
||||
<template v-else-if="data.display_type === 'wiki_delete_page'">
|
||||
<div class="info-field">
|
||||
<span class="field-label">{{ $t('chat.wikiFieldSlug') }}</span>
|
||||
<span class="field-value"><code>{{ data.slug }}</code></span>
|
||||
</div>
|
||||
<div class="info-field" v-if="data.title">
|
||||
<span class="field-label">{{ $t('chat.wikiFieldTitle') }}</span>
|
||||
<span class="field-value">{{ data.title }}</span>
|
||||
</div>
|
||||
<div class="info-field" v-if="data.updated_count > 0">
|
||||
<span class="field-label">{{ $t('chat.wikiFieldAffectedPages') }}</span>
|
||||
<span class="field-value">{{ $t('chat.wikiAffectedCount', { count: data.updated_count }) }}</span>
|
||||
</div>
|
||||
<div class="affected-list" v-if="data.affected_pages?.length">
|
||||
<code v-for="slug in data.affected_pages" :key="slug" class="affected-slug">{{ slug }}</code>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { WikiEditData } from '@/types/tool-results';
|
||||
|
||||
const props = defineProps<{
|
||||
data: WikiEditData;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const actionIcon = computed(() => {
|
||||
switch (props.data.display_type) {
|
||||
case 'wiki_write_page': return (props.data as any).action === 'created' ? '✦' : '✎';
|
||||
case 'wiki_replace_text': return '⇄';
|
||||
case 'wiki_rename_page': return '↻';
|
||||
case 'wiki_delete_page': return '✕';
|
||||
default: return '•';
|
||||
}
|
||||
});
|
||||
|
||||
const actionClass = computed(() => {
|
||||
switch (props.data.display_type) {
|
||||
case 'wiki_write_page':
|
||||
return (props.data as any).action === 'created' ? 'created' : 'updated';
|
||||
case 'wiki_replace_text': return 'updated';
|
||||
case 'wiki_rename_page': return 'renamed';
|
||||
case 'wiki_delete_page': return 'deleted';
|
||||
default: return '';
|
||||
}
|
||||
});
|
||||
|
||||
const actionLabel = computed(() => {
|
||||
switch (props.data.display_type) {
|
||||
case 'wiki_write_page':
|
||||
return (props.data as any).action === 'created'
|
||||
? t('chat.wikiActionCreated')
|
||||
: t('chat.wikiActionUpdated');
|
||||
case 'wiki_replace_text': return t('chat.wikiActionUpdated');
|
||||
case 'wiki_rename_page': return t('chat.wikiActionRenamed');
|
||||
case 'wiki_delete_page': return t('chat.wikiActionDeleted');
|
||||
default: return '';
|
||||
}
|
||||
});
|
||||
|
||||
const headerTitle = computed(() => {
|
||||
switch (props.data.display_type) {
|
||||
case 'wiki_write_page': return t('chat.wikiWritePageTitle');
|
||||
case 'wiki_replace_text': return t('chat.wikiReplaceTextTitle');
|
||||
case 'wiki_rename_page': return t('chat.wikiRenamePageTitle');
|
||||
case 'wiki_delete_page': return t('chat.wikiDeletePageTitle');
|
||||
default: return 'Wiki';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import './tool-results.less';
|
||||
|
||||
.wiki-edit-result {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.wiki-card {
|
||||
margin: 0 8px 8px 8px;
|
||||
}
|
||||
|
||||
.wiki-header {
|
||||
.wiki-icon {
|
||||
font-size: 14px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 4px;
|
||||
flex-shrink: 0;
|
||||
|
||||
&.created {
|
||||
color: var(--td-success-color);
|
||||
background: rgba(0, 168, 112, 0.1);
|
||||
}
|
||||
&.updated {
|
||||
color: var(--td-brand-color);
|
||||
background: rgba(7, 192, 95, 0.1);
|
||||
}
|
||||
&.renamed {
|
||||
color: var(--td-warning-color);
|
||||
background: rgba(255, 152, 0, 0.1);
|
||||
}
|
||||
&.deleted {
|
||||
color: var(--td-error-color);
|
||||
background: rgba(227, 77, 89, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
.wiki-title-text {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.action-badge {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
padding: 2px 8px;
|
||||
border-radius: 10px;
|
||||
line-height: 1.5;
|
||||
|
||||
&.created {
|
||||
color: var(--td-success-color);
|
||||
background: rgba(0, 168, 112, 0.1);
|
||||
border: 1px solid rgba(0, 168, 112, 0.2);
|
||||
}
|
||||
&.updated {
|
||||
color: var(--td-brand-color);
|
||||
background: rgba(7, 192, 95, 0.1);
|
||||
border: 1px solid rgba(7, 192, 95, 0.2);
|
||||
}
|
||||
&.renamed {
|
||||
color: var(--td-warning-color);
|
||||
background: rgba(255, 152, 0, 0.1);
|
||||
border: 1px solid rgba(255, 152, 0, 0.2);
|
||||
}
|
||||
&.deleted {
|
||||
color: var(--td-error-color);
|
||||
background: rgba(227, 77, 89, 0.1);
|
||||
border: 1px solid rgba(227, 77, 89, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
.diff-block {
|
||||
margin-top: 8px;
|
||||
border: 1px solid @card-border;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.diff-line {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
padding: 6px 10px;
|
||||
line-height: 1.5;
|
||||
|
||||
&.diff-old {
|
||||
background: rgba(227, 77, 89, 0.06);
|
||||
color: var(--td-error-color);
|
||||
border-bottom: 1px solid @card-border;
|
||||
}
|
||||
&.diff-new {
|
||||
background: rgba(0, 168, 112, 0.06);
|
||||
color: var(--td-success-color);
|
||||
}
|
||||
}
|
||||
|
||||
.diff-marker {
|
||||
font-weight: 700;
|
||||
flex-shrink: 0;
|
||||
width: 14px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.diff-text {
|
||||
word-break: break-word;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.rename-visual {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 8px 0;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.slug-old {
|
||||
text-decoration: line-through;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.slug-new {
|
||||
color: var(--td-success-color);
|
||||
font-weight: 600;
|
||||
}
|
||||
.rename-arrow {
|
||||
font-size: 16px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
}
|
||||
|
||||
.affected-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
margin-top: 6px;
|
||||
padding-left: 90px;
|
||||
|
||||
.affected-slug {
|
||||
font-size: 11px;
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border: 1px solid @card-border;
|
||||
}
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
|
||||
font-size: 11px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
padding: 2px 5px;
|
||||
border-radius: 3px;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
</style>
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="user_msg_container" ref="containerRef">
|
||||
<div class="user_msg_container" ref="containerRef" :class="{ 'is-embedded': embeddedMode }">
|
||||
<!-- 显示@的知识库和文件 -->
|
||||
<div v-if="mentioned_items && mentioned_items.length > 0" class="mentioned_items">
|
||||
<span
|
||||
@@ -84,6 +84,10 @@ const props = defineProps({
|
||||
type: String,
|
||||
required: false,
|
||||
default: ''
|
||||
},
|
||||
embeddedMode: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
});
|
||||
|
||||
@@ -111,7 +115,7 @@ const getAttachmentIcon = (fileNameOrType) => {
|
||||
if (['doc', 'docx'].includes(ext)) return 'file-word';
|
||||
if (['xls', 'xlsx'].includes(ext)) return 'file-excel';
|
||||
if (['ppt', 'pptx'].includes(ext)) return 'file-powerpoint';
|
||||
if (['txt', 'md'].includes(ext)) return 'file-text';
|
||||
if (['txt', 'md'].includes(ext)) return 'file';
|
||||
if (['mp3', 'wav', 'm4a', 'flac', 'ogg', 'aac'].includes(ext)) return 'sound';
|
||||
return 'file';
|
||||
};
|
||||
@@ -216,6 +220,14 @@ const closePreImg = () => {
|
||||
}
|
||||
}
|
||||
|
||||
.user_msg_container {
|
||||
&.is-embedded {
|
||||
.user_msg {
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.user_msg {
|
||||
width: max-content;
|
||||
max-width: 776px;
|
||||
@@ -233,7 +245,6 @@ const closePreImg = () => {
|
||||
font-size: 15px;
|
||||
text-align: justify;
|
||||
word-break: break-all;
|
||||
max-width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="chat">
|
||||
<div class="chat" :class="{ 'is-embedded': embeddedMode, 'is-sidebar-collapsed': uiStore.sidebarCollapsed }">
|
||||
<div ref="scrollContainer" class="chat_scroll_box" @scroll="handleScroll">
|
||||
<div class="msg_list">
|
||||
<div class="msg_list" :class="{ 'is-embedded': embeddedMode }">
|
||||
<!-- 消息列表骨架屏 -->
|
||||
<div v-if="historyLoading && messagesList.length === 0" class="msg-skeleton-list">
|
||||
<div class="msg-skeleton msg-skeleton-user">
|
||||
@@ -47,11 +47,11 @@
|
||||
</div>
|
||||
<div v-for="(session, id) in messagesList" :key='id'>
|
||||
<div v-if="session.role == 'user'">
|
||||
<usermsg :content="session.content" :mentioned_items="session.mentioned_items" :images="session.images" :attachments="session.attachments"></usermsg>
|
||||
<usermsg :content="session.content" :mentioned_items="session.mentioned_items" :images="session.images" :attachments="session.attachments" :embeddedMode="embeddedMode"></usermsg>
|
||||
</div>
|
||||
<div v-if="session.role == 'assistant'">
|
||||
<botmsg :content="session.content" :session="session" :user-query="getUserQuery(id)" @scroll-bottom="scrollToBottom"
|
||||
:isFirstEnter="isFirstEnter"></botmsg>
|
||||
:isFirstEnter="isFirstEnter" :embeddedMode="embeddedMode"></botmsg>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="loading"
|
||||
@@ -69,7 +69,7 @@
|
||||
<t-icon name="chevron-down" size="20px" />
|
||||
</div>
|
||||
</transition>
|
||||
<div style="min-height: 115px; margin: 16px auto 4px;width: 100%;max-width: 800px;">
|
||||
<div class="input-container" :class="{ 'is-embedded': embeddedMode }">
|
||||
<InputField
|
||||
ref="inputFieldRef"
|
||||
@send-msg="(query, modelId, mentionedItems, imageFiles, attachmentFiles) => sendMsg(query, modelId, mentionedItems, imageFiles, attachmentFiles)"
|
||||
@@ -77,6 +77,7 @@
|
||||
:isReplying="isReplying"
|
||||
:sessionId="session_id"
|
||||
:assistantMessageId="currentAssistantMessageId"
|
||||
:embeddedMode="embeddedMode"
|
||||
></InputField>
|
||||
</div>
|
||||
</div>
|
||||
@@ -91,7 +92,7 @@
|
||||
</template>
|
||||
<script setup>
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { ref, onMounted, onUnmounted, nextTick, watch, reactive, onBeforeUnmount } from 'vue';
|
||||
import { ref, onMounted, onUnmounted, nextTick, watch, reactive, onBeforeUnmount, defineProps } from 'vue';
|
||||
import { useRoute, useRouter, onBeforeRouteLeave, onBeforeRouteUpdate } from 'vue-router';
|
||||
import InputField from '../../components/Input-field.vue';
|
||||
import botmsg from './components/botmsg.vue';
|
||||
@@ -106,6 +107,14 @@ import { useI18n } from 'vue-i18n';
|
||||
import { useUIStore } from '@/stores/ui';
|
||||
import KnowledgeBaseEditorModal from '@/views/knowledge/KnowledgeBaseEditorModal.vue';
|
||||
import { useKnowledgeBaseCreationNavigation } from '@/hooks/useKnowledgeBaseCreationNavigation';
|
||||
|
||||
const props = defineProps({
|
||||
session_id: { type: String, default: '' },
|
||||
agentId: { type: String, default: '' },
|
||||
kbIds: { type: Array, default: () => [] },
|
||||
embeddedMode: { type: Boolean, default: false }
|
||||
});
|
||||
|
||||
const usemenuStore = useMenuStore();
|
||||
const useSettingsStoreInstance = useSettingsStore();
|
||||
const uiStore = useUIStore();
|
||||
@@ -115,7 +124,7 @@ const { menuArr, isFirstSession, firstQuery, firstMentionedItems, firstModelId,
|
||||
const { output, onChunk, isStreaming, isLoading, error, startStream, stopStream } = useStream();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const session_id = ref(route.params.chatid);
|
||||
const session_id = ref(props.session_id || route.params.chatid);
|
||||
const sessionData = ref(null);
|
||||
const inputFieldRef = ref();
|
||||
const created_at = ref('');
|
||||
@@ -155,10 +164,10 @@ const fetchSuggestedQuestions = async () => {
|
||||
suggestedQuestionsLoading.value = true;
|
||||
// 加载期间保留旧数据,不清空,避免布局抖动
|
||||
try {
|
||||
const agentId = useSettingsStoreInstance.selectedAgentId;
|
||||
const agentId = props.embeddedMode ? props.agentId : useSettingsStoreInstance.selectedAgentId;
|
||||
if (!agentId) return;
|
||||
const selectedKBs = useSettingsStoreInstance.getSelectedKnowledgeBases();
|
||||
const selectedFiles = useSettingsStoreInstance.getSelectedFiles();
|
||||
const selectedKBs = props.embeddedMode ? props.kbIds : useSettingsStoreInstance.getSelectedKnowledgeBases();
|
||||
const selectedFiles = props.embeddedMode ? [] : useSettingsStoreInstance.getSelectedFiles();
|
||||
const res = await getSuggestedQuestions(agentId, {
|
||||
knowledge_base_ids: selectedKBs.length > 0 ? selectedKBs : undefined,
|
||||
knowledge_ids: selectedFiles.length > 0 ? selectedFiles : undefined,
|
||||
@@ -371,15 +380,14 @@ const reconstructEventStreamFromSteps = (agentSteps, messageContent, isCompleted
|
||||
if (isFallback) answerEvent.is_fallback = true;
|
||||
events.push(answerEvent);
|
||||
} else if (isCompleted) {
|
||||
// 如果消息已完成但 content 为空(Agent 模式常见情况),添加一个空的 answer 事件标记完成
|
||||
// 这样可以确保 isConversationDone 返回 true,不显示 loading-indicator
|
||||
const answerEvent = {
|
||||
type: 'answer',
|
||||
content: '',
|
||||
done: true
|
||||
};
|
||||
if (isFallback) answerEvent.is_fallback = true;
|
||||
events.push(answerEvent);
|
||||
// 消息已完成但 content 为空:说明是"停止时尚未产出最终答案"的场景。
|
||||
// Push 一个 stop 事件,让 AgentStreamDisplay 的 isConversationDone 返回 true,
|
||||
// 但不产生 answer 内容,也就不会渲染最终答案的 toolbar。与实时 stop 分支保持一致。
|
||||
events.push({
|
||||
type: 'stop',
|
||||
timestamp: Date.now(),
|
||||
reason: 'user_requested'
|
||||
});
|
||||
}
|
||||
|
||||
return events;
|
||||
@@ -426,11 +434,9 @@ const handleMsgList = async (data, isScrollType = false, newScrollHeight) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 只给非Agent模式的空内容已完成消息设置默认错误消息
|
||||
// Agent模式的消息内容在agent_steps中,content为空是正常的
|
||||
if (item.is_completed && !item.content && !item.isAgentMode) {
|
||||
item.content = t('chat.cannotAnswer');
|
||||
}
|
||||
// 非 Agent 模式下若 content 为空(例如用户停止时尚未产出任何文字),
|
||||
// 保持为空;botmsg.vue 会因 hasActualContent=false 不渲染内容区和 toolbar。
|
||||
// 此前这里会兜底为 "chat.cannotAnswer",会让停止场景显示误导性文案并出现复制按钮。
|
||||
messagesList.unshift(item);
|
||||
if (isFirstEnter.value) {
|
||||
scrollToBottom(true);
|
||||
@@ -530,18 +536,18 @@ const sendMsg = async (value, modelId = '', mentionedItems = [], imageFiles = []
|
||||
scrollToBottom(true);
|
||||
|
||||
// Get agent mode status from settings store
|
||||
const agentEnabled = useSettingsStoreInstance.isAgentEnabled;
|
||||
const agentEnabled = props.embeddedMode ? (props.agentId && props.agentId !== 'builtin-quick-answer') : useSettingsStoreInstance.isAgentEnabled;
|
||||
|
||||
// Get web search status from settings store
|
||||
const webSearchEnabled = useSettingsStoreInstance.isWebSearchEnabled;
|
||||
const webSearchEnabled = props.embeddedMode ? false : useSettingsStoreInstance.isWebSearchEnabled;
|
||||
|
||||
// Get memory status from settings store
|
||||
const enableMemory = useSettingsStoreInstance.isMemoryEnabled;
|
||||
const enableMemory = props.embeddedMode ? false : useSettingsStoreInstance.isMemoryEnabled;
|
||||
|
||||
// Get knowledge_base_ids from settings store (selected by user via KnowledgeBaseSelector)
|
||||
// Merge @mentioned KB/file IDs so retrieval uses the same targets user @mentioned (including shared KBs)
|
||||
const sidebarKbIds = useSettingsStoreInstance.settings.selectedKnowledgeBases || [];
|
||||
const sidebarFileIds = useSettingsStoreInstance.settings.selectedFiles || [];
|
||||
const sidebarKbIds = props.embeddedMode ? props.kbIds : (useSettingsStoreInstance.settings.selectedKnowledgeBases || []);
|
||||
const sidebarFileIds = props.embeddedMode ? [] : (useSettingsStoreInstance.settings.selectedFiles || []);
|
||||
const kbIdSet = new Set(sidebarKbIds);
|
||||
const fileIdSet = new Set(sidebarFileIds);
|
||||
for (const item of mentionedItems || []) {
|
||||
@@ -556,13 +562,13 @@ const sendMsg = async (value, modelId = '', mentionedItems = [], imageFiles = []
|
||||
const knowledgeIds = [...fileIdSet];
|
||||
|
||||
// Get selected agent ID (backend resolves shared agent and its tenant from share relation)
|
||||
const selectedAgentId = useSettingsStoreInstance.selectedAgentId || '';
|
||||
const selectedAgentId = props.embeddedMode ? props.agentId : (useSettingsStoreInstance.selectedAgentId || '');
|
||||
|
||||
// Use agent-chat endpoint when agent is enabled, otherwise use knowledge-chat
|
||||
const endpoint = agentEnabled ? '/api/v1/agent-chat' : '/api/v1/knowledge-chat';
|
||||
|
||||
// Get selected MCP services from settings store (if available)
|
||||
const mcpServiceIds = useSettingsStoreInstance.settings.selectedMCPServices || [];
|
||||
const mcpServiceIds = props.embeddedMode ? [] : (useSettingsStoreInstance.settings.selectedMCPServices || []);
|
||||
|
||||
await startStream({
|
||||
session_id: session_id.value,
|
||||
@@ -716,7 +722,25 @@ onChunk((data) => {
|
||||
|
||||
// 原有的知识库 QA 处理逻辑(非 Agent 模式)
|
||||
// answer 内容中可能包含 <think>...</think> 标签
|
||||
|
||||
|
||||
// 非 Agent 模式下的 stop 事件:只更新状态,不把后端附带的 "Generation stopped by user"
|
||||
// 文案拼进 content,保留用户点停止时已经流式输出的内容不变。
|
||||
if (data.response_type === 'stop') {
|
||||
console.log('[Stop Event] Non-agent generation stopped');
|
||||
const stoppedMessage = messagesList.findLast((item) => {
|
||||
if (item.request_id === data.id) return true;
|
||||
return item.id === data.id;
|
||||
});
|
||||
if (stoppedMessage) {
|
||||
stoppedMessage.is_completed = true;
|
||||
}
|
||||
loading.value = false;
|
||||
isReplying.value = false;
|
||||
fullContent.value = '';
|
||||
currentAssistantMessageId.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查消息是否已经完成,如果已完成则忽略后续的完成事件(防止空内容覆盖)
|
||||
const existingMessage = messagesList.findLast((item) => {
|
||||
if (item.request_id === data.id) {
|
||||
@@ -1140,10 +1164,16 @@ onMounted(async () => {
|
||||
messagesList.splice(0);
|
||||
|
||||
// 若从智能体列表点击共享智能体进入,URL 带 agent_id 与 source_tenant_id,同步到 store
|
||||
const agentIdFromQuery = route.query.agent_id && String(route.query.agent_id);
|
||||
const agentIdFromQuery = props.embeddedAgentId || (route.query.agent_id && String(route.query.agent_id));
|
||||
const sourceTenantIdFromQuery = route.query.source_tenant_id && String(route.query.source_tenant_id);
|
||||
if (agentIdFromQuery && sourceTenantIdFromQuery) {
|
||||
useSettingsStoreInstance.selectAgent(agentIdFromQuery, sourceTenantIdFromQuery);
|
||||
} else if (agentIdFromQuery) {
|
||||
useSettingsStoreInstance.selectAgent(agentIdFromQuery, null);
|
||||
}
|
||||
|
||||
if (props.embeddedKbIds && props.embeddedKbIds.length > 0) {
|
||||
useSettingsStoreInstance.selectKnowledgeBases(props.embeddedKbIds);
|
||||
}
|
||||
|
||||
// 初始化状态:加载历史消息时不应显示loading
|
||||
@@ -1204,6 +1234,11 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
padding: 20px;
|
||||
box-sizing: border-box;
|
||||
flex: 1;
|
||||
// The parent .platform-route-outlet is a flex column with min-height:0
|
||||
// and overflow:hidden — we also need min-height:0 here so that our
|
||||
// own flex:1 child (.chat_scroll_box) can shrink below its content
|
||||
// height and scroll instead of pushing .input-container out of view.
|
||||
min-height: 0;
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -1211,6 +1246,25 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
max-width: calc(100vw - 260px);
|
||||
min-width: 400px;
|
||||
|
||||
&.is-sidebar-collapsed {
|
||||
max-width: calc(100vw - 60px);
|
||||
}
|
||||
|
||||
&.is-embedded {
|
||||
max-width: 100%;
|
||||
min-width: 100%;
|
||||
padding: 0;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
&.is-embedded :deep(.answers-input) {
|
||||
transform: translateX(0);
|
||||
width: 100%;
|
||||
left: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
:deep(.answers-input) {
|
||||
position: static;
|
||||
transform: translateX(0);
|
||||
@@ -1223,6 +1277,12 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
|
||||
.chat_scroll_box {
|
||||
flex: 1;
|
||||
// Without min-height: 0, a flex-column child defaults to min-height: auto
|
||||
// and expands to fit all inner content. When there are many messages,
|
||||
// that pushes .input-container out of the viewport. Clamping min-height
|
||||
// to 0 lets overflow-y: auto take effect so the messages scroll inside
|
||||
// this box instead of stretching it.
|
||||
min-height: 0;
|
||||
width: 100%;
|
||||
overflow-y: auto;
|
||||
|
||||
@@ -1321,6 +1381,24 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
padding-left: 4px;
|
||||
}
|
||||
|
||||
.input-container {
|
||||
min-height: 115px;
|
||||
// Keep the input visible when messages overflow: without flex-shrink: 0
|
||||
// a tall .chat_scroll_box can squeeze this container down to 0 height.
|
||||
flex-shrink: 0;
|
||||
margin: 16px auto 4px;
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
box-sizing: border-box;
|
||||
|
||||
&.is-embedded {
|
||||
max-width: 100%;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
.msg_list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -243,10 +243,11 @@ const handleKBEditorSuccess = (kbId: string) => {
|
||||
}
|
||||
|
||||
.dialogue-answers {
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
|
||||
:deep(.answers-input) {
|
||||
position: static;
|
||||
|
||||
@@ -0,0 +1,479 @@
|
||||
<template>
|
||||
<div class="markdown-test-page">
|
||||
<h1 class="page-title">Markdown Rendering Test</h1>
|
||||
<p class="page-desc">
|
||||
Dev-only page for visual regression testing of markdown / LaTeX / Mermaid rendering.
|
||||
Add new test cases or paste arbitrary markdown in the editor below.
|
||||
</p>
|
||||
|
||||
<!-- LaTeX Formulas -->
|
||||
<section class="test-section">
|
||||
<h2>LaTeX Formulas</h2>
|
||||
<div v-for="(tc, i) in latexCases" :key="'latex-'+i" class="test-case">
|
||||
<div class="test-raw"><code>{{ tc.raw }}</code></div>
|
||||
<div class="test-rendered markdown-content" v-html="render(tc.raw)"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Code Blocks -->
|
||||
<section class="test-section">
|
||||
<h2>Code Blocks</h2>
|
||||
<div class="test-case">
|
||||
<div class="test-rendered markdown-content" v-html="render(codeBlockSample)"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Tables -->
|
||||
<section class="test-section">
|
||||
<h2>Tables</h2>
|
||||
<div class="test-case">
|
||||
<div class="test-rendered markdown-content" v-html="render(tableSample)"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Lists & Blockquotes -->
|
||||
<section class="test-section">
|
||||
<h2>Lists & Blockquotes</h2>
|
||||
<div class="test-case">
|
||||
<div class="test-rendered markdown-content" v-html="render(listsSample)"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Mixed Content (LaTeX + code + text) -->
|
||||
<section class="test-section">
|
||||
<h2>Mixed Content</h2>
|
||||
<div class="test-case">
|
||||
<div class="test-rendered markdown-content" v-html="render(mixedSample)"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Mermaid -->
|
||||
<section class="test-section">
|
||||
<h2>Mermaid Diagram</h2>
|
||||
<div class="test-case">
|
||||
<div ref="mermaidContainer" class="test-rendered markdown-content" v-html="render(mermaidSample)"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Streaming Simulation -->
|
||||
<section class="test-section">
|
||||
<h2>Streaming Simulation</h2>
|
||||
<p class="test-hint">Simulates character-by-character streaming, like during a chat response.</p>
|
||||
<div class="stream-controls">
|
||||
<button @click="startStream" :disabled="isStreaming" class="btn">Start</button>
|
||||
<button @click="resetStream" class="btn">Reset</button>
|
||||
<label class="speed-label">
|
||||
Speed:
|
||||
<input type="range" min="10" max="200" v-model.number="streamSpeed" />
|
||||
{{ streamSpeed }}ms
|
||||
</label>
|
||||
</div>
|
||||
<div class="test-case">
|
||||
<div class="test-rendered markdown-content" v-html="render(streamBuffer)"></div>
|
||||
<div v-if="isStreaming" class="loading-typing">
|
||||
<span></span><span></span><span></span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Custom Editor -->
|
||||
<section class="test-section">
|
||||
<h2>Custom Input</h2>
|
||||
<p class="test-hint">Paste any markdown here to test rendering.</p>
|
||||
<textarea
|
||||
v-model="customInput"
|
||||
class="custom-textarea"
|
||||
rows="8"
|
||||
placeholder="Type or paste markdown here..."
|
||||
></textarea>
|
||||
<div v-if="customInput.trim()" class="test-case">
|
||||
<div class="test-rendered markdown-content" v-html="render(customInput)"></div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, nextTick, watch } from 'vue';
|
||||
import { marked } from 'marked';
|
||||
import markedKatex from 'marked-katex-extension';
|
||||
import DOMPurify from 'dompurify';
|
||||
import 'katex/dist/katex.min.css';
|
||||
import {
|
||||
ensureMermaidInitialized,
|
||||
renderMermaidInContainer,
|
||||
createMermaidCodeRenderer,
|
||||
} from '@/utils/mermaidShared';
|
||||
|
||||
// Configure marked
|
||||
marked.use({ breaks: true, gfm: true });
|
||||
marked.use(markedKatex({ throwOnError: false }));
|
||||
|
||||
const mermaidRenderer = new marked.Renderer();
|
||||
mermaidRenderer.code = createMermaidCodeRenderer('mermaid-test');
|
||||
|
||||
ensureMermaidInitialized();
|
||||
|
||||
const mermaidContainer = ref<HTMLElement | null>(null);
|
||||
|
||||
const preprocessMathDelimiters = (rawText: string): string => {
|
||||
if (!rawText) return '';
|
||||
return rawText
|
||||
.replace(/\\\[([\s\S]*?)\\\]/g, '$$$$$1$$$$')
|
||||
.replace(/\\\(([\s\S]*?)\\\)/g, '$$$1$$');
|
||||
};
|
||||
|
||||
const render = (raw: string): string => {
|
||||
if (!raw) return '';
|
||||
const processed = preprocessMathDelimiters(raw);
|
||||
const html = marked.parse(processed, { renderer: mermaidRenderer }) as string;
|
||||
return DOMPurify.sanitize(html, { USE_PROFILES: { html: true, svg: true, mathMl: true } });
|
||||
};
|
||||
|
||||
// --- Test Data ---
|
||||
|
||||
const latexCases = [
|
||||
{ raw: 'Inline math: $E = mc^2$ in the middle of text.' },
|
||||
{ raw: 'Block math:\n$$\\int_0^\\infty e^{-x}\\,dx = 1$$' },
|
||||
{ raw: 'Chemical formula: $\\mathrm{Mg}^{2+} + 2\\mathrm{OH}^{-} = \\mathrm{Mg(OH)}_{2}\\downarrow$' },
|
||||
{ raw: 'Chemical block:\n$$\\mathrm{Cu}^{2+} + 2\\mathrm{OH}^{-} \\rightarrow \\mathrm{Cu(OH)_2}\\downarrow$$' },
|
||||
{ raw: 'Summation: $\\sum_{i=1}^{n} i = \\frac{n(n+1)}{2}$' },
|
||||
{ raw: 'Matrix:\n$$\\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix}$$' },
|
||||
{ raw: 'Escaped delimiters: \\(\\alpha + \\beta = \\gamma\\) and \\[\\int_a^b f(x)\\,dx\\]' },
|
||||
];
|
||||
|
||||
const codeBlockSample = `Here is some Python:
|
||||
|
||||
\`\`\`python
|
||||
def fibonacci(n: int) -> int:
|
||||
"""Calculate the nth Fibonacci number."""
|
||||
if n <= 1:
|
||||
return n
|
||||
return fibonacci(n - 1) + fibonacci(n - 2)
|
||||
|
||||
print(fibonacci(10)) # 55
|
||||
\`\`\`
|
||||
|
||||
And inline code: \`const x = 42;\`
|
||||
`;
|
||||
|
||||
const tableSample = `| Element | Symbol | Atomic Number |
|
||||
|---------|--------|:-------------:|
|
||||
| Hydrogen | H | 1 |
|
||||
| Helium | He | 2 |
|
||||
| Lithium | Li | 3 |
|
||||
| Carbon | C | 6 |
|
||||
`;
|
||||
|
||||
const listsSample = `### Ordered List
|
||||
1. First item
|
||||
2. Second item
|
||||
1. Nested item A
|
||||
2. Nested item B
|
||||
3. Third item
|
||||
|
||||
### Unordered List
|
||||
- Alpha
|
||||
- Beta
|
||||
- Sub-item
|
||||
- Another sub-item
|
||||
- Gamma
|
||||
|
||||
### Blockquote
|
||||
> This is a blockquote with **bold** and *italic* text.
|
||||
>
|
||||
> It can span multiple paragraphs.
|
||||
`;
|
||||
|
||||
const mixedSample = `## Quadratic Formula
|
||||
|
||||
The solutions to $ax^2 + bx + c = 0$ are given by:
|
||||
|
||||
$$x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$$
|
||||
|
||||
### Example in Python
|
||||
|
||||
\`\`\`python
|
||||
import math
|
||||
|
||||
def solve_quadratic(a, b, c):
|
||||
discriminant = b**2 - 4*a*c
|
||||
if discriminant < 0:
|
||||
return None
|
||||
x1 = (-b + math.sqrt(discriminant)) / (2*a)
|
||||
x2 = (-b - math.sqrt(discriminant)) / (2*a)
|
||||
return x1, x2
|
||||
\`\`\`
|
||||
|
||||
| a | b | c | Solutions |
|
||||
|---|---|---|-----------|
|
||||
| 1 | -3 | 2 | $x = 1, 2$ |
|
||||
| 1 | 0 | -4 | $x = \\pm 2$ |
|
||||
| 1 | 2 | 5 | No real solutions |
|
||||
|
||||
> **Note:** The discriminant $\\Delta = b^2 - 4ac$ determines the nature of the roots.
|
||||
`;
|
||||
|
||||
const mermaidSample = `\`\`\`mermaid
|
||||
graph TD
|
||||
A[Start] --> B{Decision}
|
||||
B -->|Yes| C[Process A]
|
||||
B -->|No| D[Process B]
|
||||
C --> E[End]
|
||||
D --> E
|
||||
\`\`\`
|
||||
`;
|
||||
|
||||
// --- Streaming Simulation ---
|
||||
const fullStreamText = `The energy-mass equivalence is $E = mc^2$.
|
||||
|
||||
In chemistry, the neutralization reaction:
|
||||
|
||||
$$\\mathrm{Mg}^{2+} + 2\\mathrm{OH}^{-} = \\mathrm{Mg(OH)}_2\\downarrow$$
|
||||
|
||||
Here is a code example:
|
||||
|
||||
\`\`\`python
|
||||
def greet(name):
|
||||
print(f"Hello, {name}!")
|
||||
\`\`\`
|
||||
|
||||
And the derivative rule: $\\frac{d}{dx}\\sin x = \\cos x$.
|
||||
|
||||
Done.`;
|
||||
|
||||
const streamBuffer = ref('');
|
||||
const isStreaming = ref(false);
|
||||
const streamSpeed = ref(30);
|
||||
let streamTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
const startStream = () => {
|
||||
resetStream();
|
||||
isStreaming.value = true;
|
||||
let idx = 0;
|
||||
const tick = () => {
|
||||
if (idx >= fullStreamText.length) {
|
||||
if (streamTimer) clearInterval(streamTimer);
|
||||
isStreaming.value = false;
|
||||
return;
|
||||
}
|
||||
streamBuffer.value += fullStreamText[idx++];
|
||||
};
|
||||
streamTimer = setInterval(tick, streamSpeed.value);
|
||||
};
|
||||
|
||||
const resetStream = () => {
|
||||
if (streamTimer) clearInterval(streamTimer);
|
||||
streamBuffer.value = '';
|
||||
isStreaming.value = false;
|
||||
};
|
||||
|
||||
// Custom input
|
||||
const customInput = ref('');
|
||||
|
||||
// Render mermaid after mount and content changes
|
||||
const doMermaid = async () => {
|
||||
await nextTick();
|
||||
if (mermaidContainer.value) {
|
||||
await renderMermaidInContainer(mermaidContainer.value);
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(doMermaid);
|
||||
watch(mermaidSample, doMermaid);
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import '../../components/css/markdown.less';
|
||||
|
||||
.markdown-test-page {
|
||||
max-width: 860px;
|
||||
margin: 0 auto;
|
||||
padding: 32px 24px;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.page-desc {
|
||||
color: var(--td-text-color-secondary, #666);
|
||||
font-size: 14px;
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.test-section {
|
||||
margin-bottom: 36px;
|
||||
border-bottom: 1px solid var(--td-component-stroke, #e5e5e5);
|
||||
padding-bottom: 24px;
|
||||
|
||||
h2 {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.test-hint {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary, #999);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.test-case {
|
||||
margin: 12px 0;
|
||||
}
|
||||
|
||||
.test-raw {
|
||||
background: var(--td-bg-color-secondarycontainer, #f5f5f5);
|
||||
padding: 6px 10px;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 6px;
|
||||
font-size: 13px;
|
||||
overflow-x: auto;
|
||||
|
||||
code {
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
|
||||
.test-rendered {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid var(--td-component-stroke, #e5e5e5);
|
||||
border-radius: 6px;
|
||||
background: var(--td-bg-color-container, #fff);
|
||||
}
|
||||
|
||||
.stream-controls {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 4px 16px;
|
||||
border: 1px solid var(--td-component-stroke, #ccc);
|
||||
border-radius: 4px;
|
||||
background: var(--td-bg-color-container, #fff);
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
|
||||
&:hover {
|
||||
background: var(--td-bg-color-container-hover, #f0f0f0);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
.speed-label {
|
||||
font-size: 13px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
|
||||
input[type="range"] {
|
||||
width: 120px;
|
||||
}
|
||||
}
|
||||
|
||||
.custom-textarea {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
|
||||
font-size: 13px;
|
||||
border: 1px solid var(--td-component-stroke, #ccc);
|
||||
border-radius: 6px;
|
||||
resize: vertical;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.loading-typing {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 8px 0;
|
||||
|
||||
span {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--td-brand-color, #0052d9);
|
||||
animation: typingBounce 1.4s ease-in-out infinite;
|
||||
|
||||
&:nth-child(1) { animation-delay: 0s; }
|
||||
&:nth-child(2) { animation-delay: 0.2s; }
|
||||
&:nth-child(3) { animation-delay: 0.4s; }
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes typingBounce {
|
||||
0%, 60%, 100% { transform: translateY(0); }
|
||||
30% { transform: translateY(-8px); }
|
||||
}
|
||||
|
||||
// Markdown content styles (same as chat)
|
||||
.markdown-content {
|
||||
font-size: 15px;
|
||||
color: var(--td-text-color-primary);
|
||||
line-height: 1.6;
|
||||
|
||||
:deep(p) { margin: 6px 0; }
|
||||
:deep(code) {
|
||||
background: var(--td-bg-color-secondarycontainer, #f5f5f5);
|
||||
padding: 2px 5px;
|
||||
border-radius: 3px;
|
||||
font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
|
||||
font-size: 13px;
|
||||
}
|
||||
:deep(pre) {
|
||||
background: var(--td-bg-color-secondarycontainer, #f5f5f5);
|
||||
padding: 12px;
|
||||
border-radius: 4px;
|
||||
overflow-x: auto;
|
||||
margin: 8px 0;
|
||||
code { background: none; padding: 0; }
|
||||
}
|
||||
:deep(table) {
|
||||
border-collapse: collapse;
|
||||
margin: 8px 0;
|
||||
width: 100%;
|
||||
th, td {
|
||||
border: 1px solid var(--td-component-stroke, #e5e5e5);
|
||||
padding: 6px 10px;
|
||||
text-align: left;
|
||||
}
|
||||
th {
|
||||
background: var(--td-bg-color-secondarycontainer, #f5f5f5);
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
:deep(blockquote) {
|
||||
border-left: 3px solid var(--td-brand-color, #0052d9);
|
||||
padding-left: 12px;
|
||||
margin: 8px 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
:deep(img) {
|
||||
max-width: 80%;
|
||||
border-radius: 8px;
|
||||
margin: 8px 0;
|
||||
}
|
||||
:deep(.mermaid) {
|
||||
margin: 16px 0;
|
||||
padding: 16px;
|
||||
background: var(--td-bg-color-secondarycontainer, #f5f5f5);
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
svg { max-width: 100%; height: auto; }
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -28,11 +28,17 @@ import {
|
||||
createKnowledgeFromURL,
|
||||
listKnowledgeBases,
|
||||
reparseKnowledge,
|
||||
batchDeleteKnowledge,
|
||||
} from "@/api/knowledge-base/index";
|
||||
import FAQEntryManager from './components/FAQEntryManager.vue';
|
||||
import DocumentListView from './components/DocumentListView.vue';
|
||||
import DocumentBatchBar from './components/DocumentBatchBar.vue';
|
||||
import WikiBrowser from './wiki/WikiBrowser.vue';
|
||||
import { getWikiStats } from '@/api/wiki';
|
||||
import { listMoveTargets, moveKnowledge, getKnowledgeMoveProgress } from '@/api/knowledge-base';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { formatStringDate, kbFileTypeVerification } from '@/utils';
|
||||
import { formatFileSize } from '@/utils/files';
|
||||
import { getParserEngines, type ParserEngineInfo } from '@/api/system';
|
||||
const route = useRoute();
|
||||
const { t } = useI18n();
|
||||
@@ -44,6 +50,86 @@ const uploading = ref(false);
|
||||
const kbLoading = ref(false);
|
||||
const docListLoading = ref(true);
|
||||
const isFAQ = computed(() => (kbInfo.value?.type || '') === 'faq');
|
||||
const isWiki = computed(() => !!kbInfo.value?.indexing_strategy?.wiki_enabled);
|
||||
const validTabs = ['documents', 'wiki', 'graph'] as const
|
||||
type KbTab = typeof validTabs[number]
|
||||
const initTab = validTabs.includes(route.query.tab as any) ? (route.query.tab as KbTab) : 'documents'
|
||||
const activeKbTab = ref<KbTab>(initTab);
|
||||
|
||||
// Wiki 状态用于面包屑上的索引中指示。父组件自行拉取,避免依赖 WikiBrowser 挂载状态
|
||||
// (用户切到"文档" tab 时 WikiBrowser 会卸载,这里仍需持续反映后台索引进度)。
|
||||
const wikiStatus = ref<{ pendingTasks: number; isActive: boolean; pendingIssues: number }>({
|
||||
pendingTasks: 0,
|
||||
isActive: false,
|
||||
pendingIssues: 0,
|
||||
})
|
||||
const wikiIsIndexing = computed(() => wikiStatus.value.isActive || wikiStatus.value.pendingTasks > 0)
|
||||
const wikiIndexingTip = computed(() => {
|
||||
if (!wikiIsIndexing.value) return ''
|
||||
return t('knowledgeEditor.wikiBrowser.queueStatus', { count: wikiStatus.value.pendingTasks || 0 })
|
||||
})
|
||||
const onWikiStatusChange = (payload: { pendingTasks: number; isActive: boolean; pendingIssues: number }) => {
|
||||
wikiStatus.value = payload
|
||||
}
|
||||
|
||||
let wikiStatusTimer: ReturnType<typeof setInterval> | null = null
|
||||
let wikiStatusProbeTimers: Array<ReturnType<typeof setTimeout>> = []
|
||||
const stopWikiStatusPolling = () => {
|
||||
if (wikiStatusTimer) {
|
||||
clearInterval(wikiStatusTimer)
|
||||
wikiStatusTimer = null
|
||||
}
|
||||
}
|
||||
const clearWikiStatusProbes = () => {
|
||||
wikiStatusProbeTimers.forEach(t => clearTimeout(t))
|
||||
wikiStatusProbeTimers = []
|
||||
}
|
||||
const fetchWikiStatusOnce = async () => {
|
||||
if (!kbId.value || !isWiki.value) return
|
||||
try {
|
||||
const res: any = await getWikiStats(kbId.value)
|
||||
const data = res?.data || res
|
||||
if (!data) return
|
||||
wikiStatus.value = {
|
||||
pendingTasks: data.pending_tasks || 0,
|
||||
isActive: !!data.is_active,
|
||||
pendingIssues: data.pending_issues || 0,
|
||||
}
|
||||
// 活跃时轮询,空闲时停掉定时器,避免无谓请求
|
||||
if (wikiIsIndexing.value) {
|
||||
if (!wikiStatusTimer) {
|
||||
wikiStatusTimer = setInterval(fetchWikiStatusOnce, 5000)
|
||||
}
|
||||
} else {
|
||||
stopWikiStatusPolling()
|
||||
}
|
||||
} catch (_) { /* ignore */ }
|
||||
}
|
||||
// 用户刚触发了一个上传 / reparse / URL 导入之类的动作后,后台通常要过
|
||||
// 一小段时间才会把 wiki 任务真正塞进队列;如果这时空闲轮询刚好停了,
|
||||
// 面包屑的"索引中"会延迟很久才亮起。所以这里安排几次退避重试,
|
||||
// 主动把面包屑的 loading 尽快点亮,一旦探测到任务就会走正常的 5s 轮询。
|
||||
const scheduleWikiStatusProbes = () => {
|
||||
if (!kbId.value || !isWiki.value) return
|
||||
clearWikiStatusProbes()
|
||||
const delays = [500, 2000, 5000, 10000]
|
||||
delays.forEach(delay => {
|
||||
const timer = setTimeout(() => { fetchWikiStatusOnce() }, delay)
|
||||
wikiStatusProbeTimers.push(timer)
|
||||
})
|
||||
}
|
||||
watch([kbId, isWiki], ([newKbId, newIsWiki]) => {
|
||||
stopWikiStatusPolling()
|
||||
clearWikiStatusProbes()
|
||||
wikiStatus.value = { pendingTasks: 0, isActive: false, pendingIssues: 0 }
|
||||
if (newKbId && newIsWiki) {
|
||||
fetchWikiStatusOnce()
|
||||
}
|
||||
}, { immediate: true })
|
||||
onUnmounted(() => {
|
||||
stopWikiStatusPolling()
|
||||
clearWikiStatusProbes()
|
||||
})
|
||||
const missingStorageEngine = computed(() => {
|
||||
if (!kbInfo.value || isFAQ.value) return false
|
||||
const spc = kbInfo.value.storage_provider_config
|
||||
@@ -166,7 +252,7 @@ const onVisibleChange = (visible: boolean) => {
|
||||
}
|
||||
};
|
||||
let isCardDetails = ref(false);
|
||||
let timeout: ReturnType<typeof setInterval> | null = null;
|
||||
let timeout: ReturnType<typeof setTimeout> | null = null;
|
||||
let delDialog = ref(false)
|
||||
let rebuildDialog = ref(false)
|
||||
let rebuildKnowledgeItem = ref<KnowledgeCard>({ id: '', parse_status: '' })
|
||||
@@ -187,6 +273,26 @@ const moveMode = ref<'reuse_vectors' | 'reparse'>('reuse_vectors');
|
||||
const moveSubmitting = ref(false);
|
||||
let movePollTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
// View mode (grid / list) — persisted per browser
|
||||
type DocViewMode = 'grid' | 'list';
|
||||
const VIEW_MODE_KEY = 'weknora.kb.docs.viewMode';
|
||||
const initViewMode = (): DocViewMode => {
|
||||
try {
|
||||
return localStorage.getItem(VIEW_MODE_KEY) === 'list' ? 'list' : 'grid';
|
||||
} catch { return 'grid'; }
|
||||
};
|
||||
const viewMode = ref<DocViewMode>(initViewMode());
|
||||
watch(viewMode, (v) => {
|
||||
try { localStorage.setItem(VIEW_MODE_KEY, v); } catch { /* ignore */ }
|
||||
});
|
||||
|
||||
// Multi-select state — shared between grid and list views.
|
||||
// Vue 3.5 tracks Set#add/delete natively, so direct mutation is reactive.
|
||||
const selectedIds = ref<Set<string>>(new Set());
|
||||
let lastSelectedIndex = -1;
|
||||
const batchDeleteDialog = ref(false);
|
||||
const batchDeleting = ref(false);
|
||||
|
||||
const selectedTagId = ref<string>('');
|
||||
const tagList = ref<any[]>([]);
|
||||
const tagLoading = ref(false);
|
||||
@@ -276,16 +382,6 @@ const formatDocTime = (time?: string) => {
|
||||
return formatted.slice(2, 16) // "YY-MM-DD HH:mm"
|
||||
}
|
||||
|
||||
// 格式化文件大小,用于气泡等展示
|
||||
const formatFileSize = (bytes?: number | string) => {
|
||||
if (bytes == null || bytes === '') return ''
|
||||
const n = typeof bytes === 'string' ? parseInt(bytes, 10) : bytes
|
||||
if (Number.isNaN(n) || n <= 0) return ''
|
||||
if (n < 1024) return `${n} B`
|
||||
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`
|
||||
return `${(n / (1024 * 1024)).toFixed(1)} MB`
|
||||
}
|
||||
|
||||
const channelLabelMap: Record<string, string> = {
|
||||
web: 'knowledgeBase.channelWeb',
|
||||
api: 'knowledgeBase.channelApi',
|
||||
@@ -317,9 +413,9 @@ const getKnowledgeType = (item: any) => {
|
||||
return '--';
|
||||
}
|
||||
|
||||
const loadKnowledgeFiles = (kbIdValue: string) => {
|
||||
if (!kbIdValue) return;
|
||||
getKnowled(
|
||||
const loadKnowledgeFiles = (kbIdValue: string): Promise<void> => {
|
||||
if (!kbIdValue) return Promise.resolve();
|
||||
return getKnowled(
|
||||
{
|
||||
page: 1,
|
||||
page_size: pageSize,
|
||||
@@ -604,6 +700,17 @@ const loadKnowledgeList = async () => {
|
||||
};
|
||||
|
||||
// 监听路由参数变化,重新获取知识库内容
|
||||
// Sync activeKbTab to URL query so it survives page refresh
|
||||
watch(activeKbTab, (tab) => {
|
||||
const query = { ...route.query }
|
||||
if (tab === 'documents') {
|
||||
delete query.tab
|
||||
} else {
|
||||
query.tab = tab
|
||||
}
|
||||
router.replace({ query })
|
||||
})
|
||||
|
||||
watch(() => kbId.value, (newKbId, oldKbId) => {
|
||||
if (newKbId && newKbId !== oldKbId) {
|
||||
tagSearchQuery.value = '';
|
||||
@@ -666,6 +773,8 @@ const handleFileUploaded = (event: CustomEvent) => {
|
||||
page = 1; // Reset page counter when reloading files after upload
|
||||
loadKnowledgeFiles(uploadedKbId);
|
||||
loadTags(uploadedKbId);
|
||||
// 启动几次探测,尽快让面包屑的"索引中"亮起。
|
||||
scheduleWikiStatusProbes();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -715,6 +824,10 @@ onUnmounted(() => {
|
||||
window.removeEventListener('knowledgeFileUploaded', handleFileUploaded as EventListener);
|
||||
window.removeEventListener('openURLImportDialog', handleOpenURLImportDialog as EventListener);
|
||||
stopMovePoll();
|
||||
if (timeout !== null) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
});
|
||||
watch(() => cardList.value, (newValue) => {
|
||||
if (isFAQ.value) return;
|
||||
@@ -734,7 +847,7 @@ watch(() => cardList.value, (newValue) => {
|
||||
return isParsing || isSummaryPending;
|
||||
})
|
||||
if (timeout !== null) {
|
||||
clearInterval(timeout);
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
if (analyzeList.length) {
|
||||
@@ -761,25 +874,59 @@ type KnowledgeCard = {
|
||||
tag_id?: string;
|
||||
};
|
||||
const updateStatus = (analyzeList: KnowledgeCard[]) => {
|
||||
if (timeout !== null) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
if (!analyzeList.length) return;
|
||||
|
||||
let query = ``;
|
||||
for (let i = 0; i < analyzeList.length; i++) {
|
||||
query += `ids=${analyzeList[i].id}&`;
|
||||
}
|
||||
timeout = setInterval(() => {
|
||||
timeout = setTimeout(() => {
|
||||
batchQueryKnowledge(query).then((result: any) => {
|
||||
let hasChanges = false;
|
||||
if (result.success && result.data) {
|
||||
(result.data as KnowledgeCard[]).forEach((item: KnowledgeCard) => {
|
||||
const index = cardList.value.findIndex(card => card.id == item.id);
|
||||
if (index == -1) return;
|
||||
|
||||
// Always update the card data
|
||||
cardList.value[index].parse_status = item.parse_status;
|
||||
cardList.value[index].summary_status = item.summary_status;
|
||||
cardList.value[index].description = item.description;
|
||||
if (cardList.value[index].parse_status !== item.parse_status ||
|
||||
cardList.value[index].summary_status !== item.summary_status ||
|
||||
cardList.value[index].description !== item.description) {
|
||||
|
||||
// Always update the card data
|
||||
cardList.value[index].parse_status = item.parse_status;
|
||||
cardList.value[index].summary_status = item.summary_status;
|
||||
cardList.value[index].description = item.description;
|
||||
hasChanges = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
// If there are no changes, the watch won't trigger, so we must manually poll again
|
||||
// Even if there are changes, we can manually poll again just to be safe.
|
||||
// The watch will clear this timeout if it triggers.
|
||||
const stillPending = cardList.value.filter(item => {
|
||||
const isParsing = item.parse_status == 'pending' || item.parse_status == 'processing';
|
||||
const isSummaryPending = item.parse_status == 'completed' &&
|
||||
(item.summary_status == 'pending' || item.summary_status == 'processing');
|
||||
return isParsing || isSummaryPending;
|
||||
});
|
||||
if (stillPending.length > 0) {
|
||||
updateStatus(stillPending);
|
||||
}
|
||||
}).catch((_err) => {
|
||||
// 错误处理
|
||||
const stillPending = cardList.value.filter(item => {
|
||||
const isParsing = item.parse_status == 'pending' || item.parse_status == 'processing';
|
||||
const isSummaryPending = item.parse_status == 'completed' &&
|
||||
(item.summary_status == 'pending' || item.summary_status == 'processing');
|
||||
return isParsing || isSummaryPending;
|
||||
});
|
||||
if (stillPending.length > 0) {
|
||||
updateStatus(stillPending);
|
||||
}
|
||||
});
|
||||
}, 1500);
|
||||
};
|
||||
@@ -795,6 +942,12 @@ const openCardDetails = (item: KnowledgeCard) => {
|
||||
getCardDetails(item);
|
||||
};
|
||||
|
||||
// Open source document preview from WikiBrowser
|
||||
const openSourceDoc = (knowledgeId: string) => {
|
||||
isCardDetails.value = true;
|
||||
getCardDetails({ id: knowledgeId });
|
||||
};
|
||||
|
||||
// 悬停知识卡片时跟随鼠标显示详情气泡
|
||||
const hoveredCardItem = ref<KnowledgeCard | null>(null);
|
||||
const cardPopoverPos = ref({ x: 0, y: 0 });
|
||||
@@ -984,7 +1137,14 @@ const ensureDocumentKbReady = () => {
|
||||
MessagePlugin.warning(t('knowledgeEditor.messages.missingId'));
|
||||
return false;
|
||||
}
|
||||
if (!kbInfo.value || !kbInfo.value.embedding_model_id || !kbInfo.value.summary_model_id) {
|
||||
if (!kbInfo.value || !kbInfo.value.summary_model_id) {
|
||||
MessagePlugin.warning(t('knowledgeBase.notInitialized'));
|
||||
return false;
|
||||
}
|
||||
// Embedding model only required when RAG indexing is enabled
|
||||
const strategy = (kbInfo.value as any).indexing_strategy
|
||||
const needsEmbedding = !strategy || strategy.vector_enabled || strategy.keyword_enabled
|
||||
if (needsEmbedding && !kbInfo.value.embedding_model_id) {
|
||||
MessagePlugin.warning(t('knowledgeBase.notInitialized'));
|
||||
return false;
|
||||
}
|
||||
@@ -1419,6 +1579,8 @@ const rebuildConfirm = async () => {
|
||||
MessagePlugin.success(t('knowledgeBase.rebuildSubmitted'));
|
||||
page = 1; // Reset page counter when reloading files after reparse
|
||||
loadKnowledgeFiles(kbId.value);
|
||||
// reparse 同样会触发 wiki 重入队,探测一下让面包屑尽快亮起。
|
||||
scheduleWikiStatusProbes();
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || t('knowledgeBase.rebuildFailed'));
|
||||
}
|
||||
@@ -1452,6 +1614,113 @@ const delCardConfirm = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const toggleSelectRow = (id: string, checked: boolean, shiftKey?: boolean) => {
|
||||
const items = cardList.value || [];
|
||||
const idx = items.findIndex((i: KnowledgeCard) => i.id === id);
|
||||
if (shiftKey && lastSelectedIndex >= 0 && idx >= 0) {
|
||||
const [s, e] = idx < lastSelectedIndex
|
||||
? [idx, lastSelectedIndex]
|
||||
: [lastSelectedIndex, idx];
|
||||
for (let i = s; i <= e; i++) {
|
||||
if (checked) selectedIds.value.add(items[i].id);
|
||||
else selectedIds.value.delete(items[i].id);
|
||||
}
|
||||
} else {
|
||||
if (checked) selectedIds.value.add(id);
|
||||
else selectedIds.value.delete(id);
|
||||
}
|
||||
lastSelectedIndex = idx;
|
||||
};
|
||||
|
||||
const onCardGridCheckboxChange = (id: string, checked: boolean, ctx?: { e?: Event }) => {
|
||||
const me = ctx?.e as MouseEvent | undefined;
|
||||
toggleSelectRow(id, checked, !!me?.shiftKey);
|
||||
};
|
||||
|
||||
const toggleSelectAll = (checked: boolean) => {
|
||||
if (checked) {
|
||||
for (const item of cardList.value || []) selectedIds.value.add(item.id);
|
||||
} else {
|
||||
for (const item of cardList.value || []) selectedIds.value.delete(item.id);
|
||||
}
|
||||
};
|
||||
|
||||
const clearSelection = () => {
|
||||
selectedIds.value.clear();
|
||||
lastSelectedIndex = -1;
|
||||
};
|
||||
|
||||
const openBatchDeleteDialog = () => {
|
||||
if (selectedIds.value.size === 0) return;
|
||||
batchDeleteDialog.value = true;
|
||||
};
|
||||
|
||||
const confirmBatchDelete = async () => {
|
||||
if (batchDeleting.value || selectedIds.value.size === 0) return;
|
||||
const ids = Array.from(selectedIds.value);
|
||||
const deletedIdSet = new Set(ids);
|
||||
batchDeleting.value = true;
|
||||
try {
|
||||
const res: any = await batchDeleteKnowledge(kbId.value, ids);
|
||||
if (res?.success) {
|
||||
MessagePlugin.success(t('knowledgeBase.batchDeleteSuccess', { count: ids.length }));
|
||||
clearSelection();
|
||||
batchDeleteDialog.value = false;
|
||||
page = 1;
|
||||
// 后端将批量删除放入异步队列,立刻拉列表仍可能包含待删项;短轮询直到列表与后端一致或超时
|
||||
const maxPolls = 30;
|
||||
const delayMs = 400;
|
||||
for (let i = 0; i < maxPolls; i++) {
|
||||
await loadKnowledgeFiles(kbId.value);
|
||||
const stillPresent = (cardList.value || []).some((c: KnowledgeCard) => deletedIdSet.has(c.id));
|
||||
if (!stillPresent) break;
|
||||
await new Promise<void>((r) => setTimeout(r, delayMs));
|
||||
}
|
||||
loadTags(kbId.value);
|
||||
} else {
|
||||
MessagePlugin.error(res?.message || t('knowledgeBase.batchDeleteFailed'));
|
||||
}
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('knowledgeBase.batchDeleteFailed'));
|
||||
} finally {
|
||||
batchDeleting.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// Bridge list-view actions back to existing per-card handlers.
|
||||
const handleListAction = (
|
||||
action: 'edit' | 'reparse' | 'move' | 'delete',
|
||||
item: KnowledgeCard,
|
||||
) => {
|
||||
const idx = (cardList.value || []).findIndex((i: KnowledgeCard) => i.id === item.id);
|
||||
if (action === 'edit') return handleManualEdit(idx, item);
|
||||
if (action === 'reparse') return handleKnowledgeReparse(idx, item);
|
||||
if (action === 'move') return handleMoveKnowledge(item);
|
||||
if (action === 'delete') return delCard(idx, item);
|
||||
};
|
||||
|
||||
// Clear selection on filter/tag/kb change to avoid acting on hidden items.
|
||||
watch([selectedTagId, docSearchKeyword, selectedFileType, kbId], () => {
|
||||
clearSelection();
|
||||
});
|
||||
|
||||
// After cardList reloads: stable keys rely on correct indices for shift-range; clamp anchor index.
|
||||
watch(cardList, () => {
|
||||
const items = cardList.value || [];
|
||||
const n = items.length;
|
||||
if (lastSelectedIndex >= n) {
|
||||
lastSelectedIndex = n > 0 ? n - 1 : -1;
|
||||
}
|
||||
if (moreIndex.value >= n) {
|
||||
moreIndex.value = -1;
|
||||
}
|
||||
if (selectedIds.value.size === 0) return;
|
||||
const visible = new Set(items.map((i: KnowledgeCard) => i.id));
|
||||
for (const id of selectedIds.value) {
|
||||
if (!visible.has(id)) selectedIds.value.delete(id);
|
||||
}
|
||||
}, { deep: false });
|
||||
|
||||
// 处理知识库编辑成功后的回调
|
||||
const handleKBEditorSuccess = (kbIdValue: string) => {
|
||||
if (kbIdValue === kbId.value) {
|
||||
@@ -1539,7 +1808,33 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</template>
|
||||
</button>
|
||||
<t-icon name="chevron-right" class="breadcrumb-separator" />
|
||||
<span class="breadcrumb-current">{{ $t('knowledgeEditor.document.title') }}</span>
|
||||
<template v-if="isWiki">
|
||||
<span
|
||||
:class="['breadcrumb-tab', { active: activeKbTab === 'documents' }]"
|
||||
@click="activeKbTab = 'documents'"
|
||||
>{{ $t('knowledgeEditor.wikiBrowser.tabDocuments') }}</span>
|
||||
<span class="breadcrumb-tab-sep">/</span>
|
||||
<span
|
||||
:class="['breadcrumb-tab', { active: activeKbTab === 'wiki', indexing: wikiIsIndexing }]"
|
||||
@click="activeKbTab = 'wiki'"
|
||||
>
|
||||
Wiki
|
||||
<t-tooltip v-if="wikiIsIndexing" :content="wikiIndexingTip" placement="bottom">
|
||||
<t-loading size="small" class="breadcrumb-tab-indicator" />
|
||||
</t-tooltip>
|
||||
</span>
|
||||
<span class="breadcrumb-tab-sep">/</span>
|
||||
<span
|
||||
:class="['breadcrumb-tab', { active: activeKbTab === 'graph', indexing: wikiIsIndexing }]"
|
||||
@click="activeKbTab = 'graph'"
|
||||
>
|
||||
{{ $t('knowledgeEditor.wikiBrowser.tabGraph') }}
|
||||
<t-tooltip v-if="wikiIsIndexing" :content="wikiIndexingTip" placement="bottom">
|
||||
<t-loading size="small" class="breadcrumb-tab-indicator" />
|
||||
</t-tooltip>
|
||||
</span>
|
||||
</template>
|
||||
<span v-else class="breadcrumb-current">{{ $t('knowledgeEditor.document.title') }}</span>
|
||||
</h2>
|
||||
<!-- 身份与最后更新:紧凑单行,置于标题行右侧,悬停显示权限说明 -->
|
||||
<div v-if="kbInfo && !authStore.isLiteMode" class="kb-access-meta">
|
||||
@@ -1590,7 +1885,13 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Wiki Browser / Graph (shown when wiki or graph tab is active) -->
|
||||
<div v-if="isWiki && (activeKbTab === 'wiki' || activeKbTab === 'graph')" class="wiki-main-area">
|
||||
<WikiBrowser v-if="kbId" :knowledge-base-id="kbId" :view="activeKbTab === 'graph' ? 'graph' : 'browser'" @open-source-doc="openSourceDoc" @status-change="onWikiStatusChange" />
|
||||
</div>
|
||||
|
||||
<template v-if="activeKbTab === 'documents' || !isWiki">
|
||||
<input
|
||||
ref="uploadInputRef"
|
||||
type="file"
|
||||
@@ -1799,6 +2100,30 @@ async function createNewSession(value: string): Promise<void> {
|
||||
class="doc-type-select"
|
||||
clearable
|
||||
/>
|
||||
<div class="doc-view-toggle" role="group" :aria-label="$t('knowledgeBase.viewModeToggle')">
|
||||
<t-tooltip :content="$t('knowledgeBase.viewModeGrid')" placement="top">
|
||||
<button
|
||||
type="button"
|
||||
class="doc-view-toggle-btn"
|
||||
:class="{ active: viewMode === 'grid' }"
|
||||
@click="viewMode = 'grid'"
|
||||
:aria-pressed="viewMode === 'grid'"
|
||||
>
|
||||
<t-icon name="view-module" size="16px" />
|
||||
</button>
|
||||
</t-tooltip>
|
||||
<t-tooltip :content="$t('knowledgeBase.viewModeList')" placement="top">
|
||||
<button
|
||||
type="button"
|
||||
class="doc-view-toggle-btn"
|
||||
:class="{ active: viewMode === 'list' }"
|
||||
@click="viewMode = 'list'"
|
||||
:aria-pressed="viewMode === 'list'"
|
||||
>
|
||||
<t-icon name="view-list" size="16px" />
|
||||
</button>
|
||||
</t-tooltip>
|
||||
</div>
|
||||
<div v-if="canEdit" class="doc-filter-actions">
|
||||
<t-tooltip :content="$t('knowledgeBase.addDocument')" placement="top">
|
||||
<t-dropdown
|
||||
@@ -1834,13 +2159,14 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<template v-else-if="cardList.length">
|
||||
<template v-else-if="cardList.length && viewMode === 'grid'">
|
||||
<div class="doc-card-list doc-card-list-animated">
|
||||
<!-- 现有文档卡片 -->
|
||||
<div
|
||||
class="knowledge-card"
|
||||
:class="{ 'is-selected': selectedIds.has(item.id), 'has-selection': selectedIds.size > 0 }"
|
||||
v-for="(item, index) in cardList"
|
||||
:key="index"
|
||||
:key="item.id"
|
||||
@click="openCardDetails(item)"
|
||||
@mouseenter="onCardMouseEnter($event, item)"
|
||||
@mousemove="onCardMouseMove($event)"
|
||||
@@ -1848,6 +2174,20 @@ async function createNewSession(value: string): Promise<void> {
|
||||
>
|
||||
<div class="card-content">
|
||||
<div class="card-content-nav">
|
||||
<div
|
||||
v-if="canEdit"
|
||||
class="card-nav-check"
|
||||
:class="{ active: selectedIds.has(item.id) }"
|
||||
@click.stop
|
||||
>
|
||||
<t-checkbox
|
||||
class="card-select-checkbox"
|
||||
size="small"
|
||||
:checked="selectedIds.has(item.id)"
|
||||
:title="item.file_name"
|
||||
@change="(checked, ctx) => onCardGridCheckboxChange(item.id, checked, ctx)"
|
||||
/>
|
||||
</div>
|
||||
<span class="card-content-title" :title="item.file_name">{{ item.file_name }}</span>
|
||||
<t-popup
|
||||
v-if="canEdit"
|
||||
@@ -2054,12 +2394,32 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
<template v-else-if="cardList.length && viewMode === 'list'">
|
||||
<DocumentListView
|
||||
:items="cardList"
|
||||
:selected-ids="selectedIds"
|
||||
:tag-list="tagList"
|
||||
:can-edit="canEdit"
|
||||
@open="(item: any) => openCardDetails(item)"
|
||||
@toggle-row="toggleSelectRow"
|
||||
@toggle-all="toggleSelectAll"
|
||||
@action="(action: any, item: any) => handleListAction(action, item)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="!docListLoading">
|
||||
<div class="doc-empty-state">
|
||||
<EmptyKnowledge />
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="doc-batch-bar-anchor" v-show="selectedIds.size > 0">
|
||||
<DocumentBatchBar
|
||||
:count="selectedIds.size"
|
||||
:loading="batchDeleting"
|
||||
@clear="clearSelection"
|
||||
@delete="openBatchDeleteDialog"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<t-dialog
|
||||
v-model:visible="delDialog"
|
||||
@@ -2085,6 +2445,41 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</div>
|
||||
</t-dialog>
|
||||
|
||||
<!-- 批量删除确认弹窗 -->
|
||||
<t-dialog
|
||||
v-model:visible="batchDeleteDialog"
|
||||
dialogClassName="del-knowledge"
|
||||
:closeBtn="false"
|
||||
:cancelBtn="null"
|
||||
:confirmBtn="null"
|
||||
>
|
||||
<div class="circle-wrap">
|
||||
<div class="header">
|
||||
<img class="circle-img" src="@/assets/img/circle.png" alt="" />
|
||||
<span class="circle-title">{{ t('knowledgeBase.batchDeleteConfirmation') }}</span>
|
||||
</div>
|
||||
<span class="del-circle-txt">
|
||||
{{ t('knowledgeBase.confirmBatchDeleteDocument', { count: selectedIds.size }) }}
|
||||
</span>
|
||||
<div class="circle-btn">
|
||||
<span
|
||||
class="circle-btn-txt"
|
||||
:class="{ disabled: batchDeleting }"
|
||||
@click="batchDeleting ? null : (batchDeleteDialog = false)"
|
||||
>
|
||||
{{ t('common.cancel') }}
|
||||
</span>
|
||||
<span
|
||||
class="circle-btn-txt confirm"
|
||||
:class="{ disabled: batchDeleting }"
|
||||
@click="confirmBatchDelete"
|
||||
>
|
||||
{{ batchDeleting ? '...' : t('knowledgeBase.confirmDelete') }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</t-dialog>
|
||||
|
||||
<!-- 重建知识确认弹窗 -->
|
||||
<t-dialog
|
||||
v-model:visible="rebuildDialog"
|
||||
@@ -2136,10 +2531,13 @@ async function createNewSession(value: string): Promise<void> {
|
||||
<div class="url-input-tip">{{ $t('knowledgeBase.urlTip') }}</div>
|
||||
</div>
|
||||
</t-dialog>
|
||||
|
||||
<DocContent :visible="isCardDetails" :details="details" @closeDoc="closeDoc" @getDoc="getDoc"></DocContent>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- DocContent drawer (shared by documents tab and wiki source refs) -->
|
||||
<DocContent :visible="isCardDetails" :details="details" @closeDoc="closeDoc" @getDoc="getDoc"></DocContent>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
@@ -2171,10 +2569,54 @@ async function createNewSession(value: string): Promise<void> {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 24px 32px 32px;
|
||||
padding: 24px 32px 0px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
// Breadcrumb tab switch (文档/Wiki in breadcrumb)
|
||||
.breadcrumb-tab {
|
||||
cursor: pointer;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-weight: 400;
|
||||
transition: color 0.15s;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
|
||||
&:hover {
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
&.active {
|
||||
color: var(--td-brand-color);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
&.indexing {
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
}
|
||||
|
||||
.breadcrumb-tab-indicator {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
color: var(--td-brand-color);
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.breadcrumb-tab-sep {
|
||||
margin: 0 6px;
|
||||
color: var(--td-text-color-disabled);
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.wiki-main-area {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
// 与列表页一致:浅灰底圆角区,左侧筛选为白底卡片
|
||||
.knowledge-main {
|
||||
display: flex;
|
||||
@@ -2601,6 +3043,38 @@ async function createNewSession(value: string): Promise<void> {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.doc-view-toggle {
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 2px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-radius: 6px;
|
||||
gap: 0;
|
||||
|
||||
.doc-view-toggle-btn {
|
||||
width: 28px;
|
||||
height: 24px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
border-radius: 4px;
|
||||
color: var(--td-text-color-secondary, #888);
|
||||
cursor: pointer;
|
||||
transition: background-color 0.12s ease, color 0.12s ease;
|
||||
|
||||
&:hover { color: var(--td-text-color-primary, #232323); }
|
||||
|
||||
&.active {
|
||||
background: var(--td-bg-color-container, #fff);
|
||||
color: var(--td-brand-color, #0052d9);
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.doc-filter-actions {
|
||||
flex-shrink: 0;
|
||||
:deep(.content-bar-icon-btn) {
|
||||
@@ -2663,6 +3137,12 @@ async function createNewSession(value: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/* 批量条在滚动区外,始终贴主内容列底部,不随列表高度在列内上下漂移 */
|
||||
.doc-batch-bar-anchor {
|
||||
flex-shrink: 0;
|
||||
padding-top: 4px;
|
||||
}
|
||||
|
||||
// Header 样式(无底部分割线,留更多空间给下方内容区)
|
||||
.document-header {
|
||||
display: flex;
|
||||
@@ -2939,6 +3419,7 @@ async function createNewSession(value: string): Promise<void> {
|
||||
|
||||
.faq-manager-wrapper {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
padding: 24px 32px;
|
||||
overflow-y: auto;
|
||||
margin: 0 16px 0 4px;
|
||||
@@ -2993,7 +3474,7 @@ async function createNewSession(value: string): Promise<void> {
|
||||
box-sizing: border-box;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
|
||||
gap: 14px;
|
||||
gap: 16px;
|
||||
align-content: flex-start;
|
||||
width: 100%;
|
||||
|
||||
@@ -3004,14 +3485,24 @@ async function createNewSession(value: string): Promise<void> {
|
||||
|
||||
.knowledge-card-skeleton {
|
||||
cursor: default;
|
||||
.card-content { padding: 15px 17px 13px; }
|
||||
.card-content-nav { margin-bottom: 14px; }
|
||||
|
||||
.card-content {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 12px 16px 8px;
|
||||
}
|
||||
|
||||
.card-content-nav {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.card-bottom {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
flex-shrink: 0;
|
||||
margin-top: auto;
|
||||
width: 100%;
|
||||
padding: 0 17px;
|
||||
padding: 0 16px;
|
||||
box-sizing: border-box;
|
||||
height: 34px;
|
||||
display: flex;
|
||||
@@ -3099,6 +3590,11 @@ async function createNewSession(value: string): Promise<void> {
|
||||
font-weight: 400;
|
||||
line-height: 22px;
|
||||
cursor: pointer;
|
||||
|
||||
&.disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
.confirm {
|
||||
@@ -3293,6 +3789,7 @@ async function createNewSession(value: string): Promise<void> {
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 0;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.card-draft-tip {
|
||||
@@ -3302,22 +3799,77 @@ async function createNewSession(value: string): Promise<void> {
|
||||
|
||||
.knowledge-card {
|
||||
min-width: 248px;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border: 1px solid color-mix(in srgb, var(--td-component-stroke) 82%, var(--td-bg-color-secondarycontainer));
|
||||
height: 148px;
|
||||
border-radius: 9px;
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.035);
|
||||
background: var(--td-bg-color-container);
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.2s ease, box-shadow 0.2s ease;
|
||||
transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
|
||||
|
||||
/* 初始态略可见,悬停/多选/已选时再强调,避免「凭空多一列」的突兀感 */
|
||||
.card-nav-check {
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 22px;
|
||||
height: 29px;
|
||||
opacity: 0.4;
|
||||
transition: opacity 0.2s ease;
|
||||
cursor: pointer;
|
||||
|
||||
&.active,
|
||||
&:focus-within {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.card-select-checkbox {
|
||||
margin: 0;
|
||||
line-height: 0;
|
||||
|
||||
:deep(.t-checkbox) {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
:deep(.t-checkbox__label) {
|
||||
display: none !important;
|
||||
width: 0 !important;
|
||||
min-width: 0 !important;
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
:deep(.t-checkbox__input) {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
:deep(.t-checkbox__input-wrapper) {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&:hover .card-nav-check,
|
||||
&.has-selection .card-nav-check {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.card-content {
|
||||
padding: 15px 17px 13px;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 12px 16px 8px;
|
||||
}
|
||||
|
||||
.card-analyze {
|
||||
flex-shrink: 0;
|
||||
height: 52px;
|
||||
display: flex;
|
||||
}
|
||||
@@ -3341,11 +3893,11 @@ async function createNewSession(value: string): Promise<void> {
|
||||
}
|
||||
|
||||
.card-content-nav {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 11px;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.card-content-title {
|
||||
@@ -3389,6 +3941,8 @@ async function createNewSession(value: string): Promise<void> {
|
||||
}
|
||||
|
||||
.card-content-txt {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
@@ -3402,9 +3956,9 @@ async function createNewSession(value: string): Promise<void> {
|
||||
}
|
||||
|
||||
.card-bottom {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
padding: 0 17px;
|
||||
flex-shrink: 0;
|
||||
margin-top: auto;
|
||||
padding: 0 16px;
|
||||
box-sizing: border-box;
|
||||
height: 34px;
|
||||
width: 100%;
|
||||
@@ -3423,19 +3977,19 @@ async function createNewSession(value: string): Promise<void> {
|
||||
}
|
||||
|
||||
.card-type {
|
||||
color: var(--td-text-color-secondary);
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-family: "PingFang SC";
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
padding: 3px 8px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-radius: 4px;
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
}
|
||||
|
||||
.knowledge-card:hover {
|
||||
border-color: var(--td-brand-color);
|
||||
box-shadow: 0 2px 8px rgba(7, 192, 95, 0.12);
|
||||
border-color: color-mix(in srgb, var(--td-component-stroke) 55%, var(--td-brand-color));
|
||||
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.07);
|
||||
}
|
||||
|
||||
/* 悬停知识卡片时跟随鼠标的详情气泡 */
|
||||
|
||||
@@ -52,6 +52,69 @@
|
||||
</t-radio-group>
|
||||
<p class="form-tip">{{ $t('knowledgeEditor.basic.typeDescription') }}</p>
|
||||
</div>
|
||||
|
||||
<!-- 索引策略 (紧跟类型选择) -->
|
||||
<div v-if="!isFAQ" class="form-item">
|
||||
<label class="form-label required">{{ $t('knowledgeEditor.indexing.title') }}</label>
|
||||
<p class="form-tip">{{ $t('knowledgeEditor.indexing.description') }}</p>
|
||||
<div class="indexing-checks" :class="{ 'is-locked': isIndexingLocked }">
|
||||
<div
|
||||
class="indexing-check-item"
|
||||
:class="{ 'is-checked': formData.indexingStrategy.vectorEnabled, 'is-disabled': isIndexingLocked }"
|
||||
@click="toggleVectorIndexing"
|
||||
>
|
||||
<t-checkbox
|
||||
:checked="formData.indexingStrategy.vectorEnabled"
|
||||
:disabled="isIndexingLocked"
|
||||
class="indexing-check-box"
|
||||
>{{ $t('knowledgeEditor.indexing.searchTitle') }}</t-checkbox>
|
||||
<p class="indexing-check-desc">{{ $t('knowledgeEditor.indexing.searchDesc') }}</p>
|
||||
</div>
|
||||
<div
|
||||
class="indexing-check-item"
|
||||
:class="{ 'is-checked': formData.indexingStrategy.wikiEnabled, 'is-disabled': isIndexingLocked }"
|
||||
@click="toggleWikiIndexing"
|
||||
>
|
||||
<t-checkbox
|
||||
:checked="formData.indexingStrategy.wikiEnabled"
|
||||
:disabled="isIndexingLocked"
|
||||
class="indexing-check-box"
|
||||
>
|
||||
<span class="indexing-check-title">
|
||||
{{ $t('knowledgeEditor.indexing.wikiTitle') }}
|
||||
<span class="indexing-new-badge">NEW</span>
|
||||
</span>
|
||||
</t-checkbox>
|
||||
<p class="indexing-check-desc">{{ $t('knowledgeEditor.indexing.wikiDesc') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="isIndexingLocked" class="form-tip locked-tip">
|
||||
{{ $t('knowledgeEditor.indexing.lockedTip') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Wiki 提取粒度 (仅当 Wiki 启用时显示) -->
|
||||
<div v-if="!isFAQ && formData.indexingStrategy.wikiEnabled" class="form-item">
|
||||
<label class="form-label">{{ $t('knowledgeEditor.wiki.extractionGranularityLabel') }}</label>
|
||||
<p class="form-tip">{{ $t('knowledgeEditor.wiki.extractionGranularityTip') }}</p>
|
||||
<t-radio-group
|
||||
:value="resolvedGranularity"
|
||||
class="granularity-radio-group"
|
||||
@change="handleGranularityChange"
|
||||
>
|
||||
<t-radio-button value="focused">
|
||||
{{ $t('knowledgeEditor.wiki.granularityFocused') }}
|
||||
</t-radio-button>
|
||||
<t-radio-button value="standard">
|
||||
{{ $t('knowledgeEditor.wiki.granularityStandard') }}
|
||||
</t-radio-button>
|
||||
<t-radio-button value="exhaustive">
|
||||
{{ $t('knowledgeEditor.wiki.granularityExhaustive') }}
|
||||
</t-radio-button>
|
||||
</t-radio-group>
|
||||
<p class="form-tip granularity-hint">{{ granularityHint }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label required">{{ $t('knowledgeEditor.basic.nameLabel') }}</label>
|
||||
<t-input
|
||||
@@ -62,13 +125,15 @@
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ $t('knowledgeEditor.basic.descriptionLabel') }}</label>
|
||||
<t-textarea
|
||||
v-model="formData.description"
|
||||
<t-textarea
|
||||
v-model="formData.description"
|
||||
:placeholder="$t('knowledgeEditor.basic.descriptionPlaceholder')"
|
||||
:maxlength="200"
|
||||
:autosize="{ minRows: 3, maxRows: 6 }"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Wiki 合成模型移至模型配置页 -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -80,6 +145,8 @@
|
||||
v-if="formData"
|
||||
:config="formData.modelConfig"
|
||||
:has-files="hasFiles"
|
||||
:wiki-enabled="formData.indexingStrategy?.wikiEnabled"
|
||||
:rag-enabled="formData.indexingStrategy?.vectorEnabled || formData.indexingStrategy?.keywordEnabled"
|
||||
:all-models="allModels"
|
||||
@update:config="handleModelConfigUpdate"
|
||||
/>
|
||||
@@ -146,17 +213,6 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 图谱设置 -->
|
||||
<div v-if="!isFAQ" v-show="currentSection === 'graph'" class="section">
|
||||
<GraphSettings
|
||||
v-if="formData"
|
||||
:graph-extract="formData.nodeExtractConfig"
|
||||
:model-id="formData.modelConfig.llmModelId"
|
||||
:all-models="allModels"
|
||||
@update:graphExtract="handleNodeExtractUpdate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 多模态配置 -->
|
||||
<div v-if="!isFAQ" v-show="currentSection === 'multimodal'" class="section">
|
||||
<div v-if="formData" class="kb-multimodal-settings">
|
||||
@@ -202,7 +258,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 音视频语音识别(ASR)设置 -->
|
||||
<!-- 音频处理(ASR)设置 -->
|
||||
<div v-if="!isFAQ" v-show="currentSection === 'asr'" class="section">
|
||||
<div v-if="formData" class="kb-multimodal-settings">
|
||||
<div class="section-header">
|
||||
@@ -246,12 +302,24 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 知识图谱 -->
|
||||
<div v-if="!isFAQ" v-show="currentSection === 'graph'" class="section">
|
||||
<GraphSettings
|
||||
v-if="formData"
|
||||
:graph-extract="formData.nodeExtractConfig"
|
||||
:model-id="formData.modelConfig.llmModelId"
|
||||
:all-models="allModels"
|
||||
@update:graphExtract="handleNodeExtractUpdate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 高级设置 -->
|
||||
<div v-if="!isFAQ" v-show="currentSection === 'advanced'" class="section">
|
||||
<KBAdvancedSettings
|
||||
ref="advancedSettingsRef"
|
||||
v-if="formData"
|
||||
:question-generation="formData.questionGenerationConfig"
|
||||
:rag-enabled="formData.indexingStrategy?.vectorEnabled || formData.indexingStrategy?.keywordEnabled"
|
||||
:all-models="allModels"
|
||||
@update:question-generation="handleQuestionGenerationUpdate"
|
||||
/>
|
||||
@@ -288,7 +356,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { MessagePlugin, DialogPlugin } from 'tdesign-vue-next'
|
||||
import { createKnowledgeBase, getKnowledgeBaseById, listKnowledgeFiles, updateKnowledgeBase } from '@/api/knowledge-base'
|
||||
import { createKnowledgeBase, getKnowledgeBaseById, listKnowledgeFiles, updateKnowledgeBase, rebuildKBIndex } from '@/api/knowledge-base'
|
||||
import { updateKBConfig, type KBModelConfigRequest } from '@/api/initialization'
|
||||
import { listModels } from '@/api/model'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
@@ -328,7 +396,25 @@ const loading = ref(false)
|
||||
const allModels = ref<any[]>([])
|
||||
const hasFiles = ref(false)
|
||||
const initialStorageProvider = ref<string>('')
|
||||
const initialIndexingStrategy = ref<any>(null)
|
||||
const dsCount = ref(0)
|
||||
// 用户是否在分块设置中手动改过任何值。一旦为 true,就不再根据索引策略自动调整默认分块参数。
|
||||
const chunkingDirty = ref(false)
|
||||
|
||||
// 仅 Wiki 索引模式下的分块预设:更大 chunk、无 overlap、关闭父子分块。
|
||||
// 该预设只在「创建模式」下、且用户尚未手动调整分块参数时生效,避免覆盖既有 KB 的配置。
|
||||
const WIKI_ONLY_CHUNKING_PRESET = {
|
||||
chunkSize: 2048,
|
||||
chunkOverlap: 0,
|
||||
enableParentChild: false,
|
||||
} as const
|
||||
|
||||
// 非 Wiki-only 场景下回落到的默认值(与 initFormData 保持一致)。
|
||||
const DEFAULT_CHUNKING_PRESET = {
|
||||
chunkSize: 512,
|
||||
chunkOverlap: 100,
|
||||
enableParentChild: true,
|
||||
} as const
|
||||
|
||||
const navItems = computed(() => {
|
||||
const items: { key: string; icon: string; label: string; badge?: number }[] = [
|
||||
@@ -394,7 +480,8 @@ const initFormData = (type: 'document' | 'faq' = 'document') => {
|
||||
},
|
||||
modelConfig: {
|
||||
llmModelId: '',
|
||||
embeddingModelId: ''
|
||||
embeddingModelId: '',
|
||||
wikiSynthesisModelId: '',
|
||||
},
|
||||
chunkingConfig: {
|
||||
chunkSize: 512,
|
||||
@@ -433,6 +520,17 @@ const initFormData = (type: 'document' | 'faq' = 'document') => {
|
||||
enabled: true,
|
||||
questionCount: 3
|
||||
},
|
||||
wikiConfig: {
|
||||
synthesisModelId: '',
|
||||
maxPagesPerIngest: 0,
|
||||
extractionGranularity: 'standard' as 'focused' | 'standard' | 'exhaustive',
|
||||
},
|
||||
indexingStrategy: {
|
||||
vectorEnabled: true,
|
||||
keywordEnabled: true,
|
||||
wikiEnabled: false,
|
||||
graphEnabled: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -479,7 +577,8 @@ const loadKBData = async () => {
|
||||
},
|
||||
modelConfig: {
|
||||
llmModelId: kb.summary_model_id || '',
|
||||
embeddingModelId: kb.embedding_model_id || ''
|
||||
embeddingModelId: kb.embedding_model_id || '',
|
||||
wikiSynthesisModelId: kb.wiki_config?.synthesis_model_id || ''
|
||||
},
|
||||
chunkingConfig: {
|
||||
chunkSize: kb.chunking_config?.chunk_size || 512,
|
||||
@@ -514,8 +613,25 @@ const loadKBData = async () => {
|
||||
enabled: kb.question_generation_config?.enabled || false,
|
||||
questionCount: kb.question_generation_config?.question_count || 3
|
||||
},
|
||||
wikiConfig: {
|
||||
synthesisModelId: kb.wiki_config?.synthesis_model_id || '',
|
||||
maxPagesPerIngest: kb.wiki_config?.max_pages_per_ingest || 0,
|
||||
extractionGranularity: (
|
||||
kb.wiki_config?.extraction_granularity === 'focused' ||
|
||||
kb.wiki_config?.extraction_granularity === 'exhaustive'
|
||||
? kb.wiki_config.extraction_granularity
|
||||
: 'standard'
|
||||
) as 'focused' | 'standard' | 'exhaustive',
|
||||
},
|
||||
indexingStrategy: {
|
||||
vectorEnabled: kb.indexing_strategy?.vector_enabled ?? true,
|
||||
keywordEnabled: kb.indexing_strategy?.keyword_enabled ?? true,
|
||||
wikiEnabled: kb.indexing_strategy?.wiki_enabled ?? false,
|
||||
graphEnabled: kb.indexing_strategy?.graph_enabled ?? false,
|
||||
},
|
||||
}
|
||||
initialStorageProvider.value = formData.value.storageProvider
|
||||
initialIndexingStrategy.value = { ...formData.value.indexingStrategy }
|
||||
} catch (error) {
|
||||
console.error('Failed to load knowledge base data:', error)
|
||||
MessagePlugin.error(t('knowledgeEditor.messages.loadDataFailed'))
|
||||
@@ -532,12 +648,83 @@ const handleModelConfigUpdate = (config: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 粒度选择器:从 formData.wikiConfig 读出并规范化,未知值回退到 'standard',
|
||||
// 与后端 WikiExtractionGranularity.Normalize() 的契约保持一致。
|
||||
const resolvedGranularity = computed<'focused' | 'standard' | 'exhaustive'>(() => {
|
||||
const g = formData.value?.wikiConfig?.extractionGranularity
|
||||
if (g === 'focused' || g === 'standard' || g === 'exhaustive') {
|
||||
return g
|
||||
}
|
||||
return 'standard'
|
||||
})
|
||||
|
||||
const granularityHint = computed<string>(() => {
|
||||
switch (resolvedGranularity.value) {
|
||||
case 'focused':
|
||||
return t('knowledgeEditor.wiki.granularityFocusedHint')
|
||||
case 'exhaustive':
|
||||
return t('knowledgeEditor.wiki.granularityExhaustiveHint')
|
||||
default:
|
||||
return t('knowledgeEditor.wiki.granularityStandardHint')
|
||||
}
|
||||
})
|
||||
|
||||
const handleGranularityChange = (value: string | number | boolean) => {
|
||||
if (!formData.value) return
|
||||
const next: 'focused' | 'standard' | 'exhaustive' =
|
||||
value === 'focused' || value === 'exhaustive'
|
||||
? (value as 'focused' | 'exhaustive')
|
||||
: 'standard'
|
||||
formData.value.wikiConfig = {
|
||||
...formData.value.wikiConfig,
|
||||
extractionGranularity: next,
|
||||
}
|
||||
}
|
||||
|
||||
const isIndexingLocked = computed(() => props.mode === 'edit' && hasFiles.value)
|
||||
|
||||
const toggleVectorIndexing = () => {
|
||||
if (!formData.value) return
|
||||
if (isIndexingLocked.value) return
|
||||
const next = !formData.value.indexingStrategy.vectorEnabled
|
||||
formData.value.indexingStrategy.vectorEnabled = next
|
||||
formData.value.indexingStrategy.keywordEnabled = next
|
||||
}
|
||||
|
||||
const toggleWikiIndexing = () => {
|
||||
if (!formData.value) return
|
||||
if (isIndexingLocked.value) return
|
||||
formData.value.indexingStrategy.wikiEnabled = !formData.value.indexingStrategy.wikiEnabled
|
||||
}
|
||||
|
||||
const handleChunkingConfigUpdate = (config: any) => {
|
||||
if (formData.value) {
|
||||
formData.value.chunkingConfig = { ...config }
|
||||
// 用户已经手动触达分块设置,后续索引策略切换不再覆盖这些值
|
||||
chunkingDirty.value = true
|
||||
}
|
||||
}
|
||||
|
||||
// 判断当前是否为「仅 Wiki 索引」:只开了 Wiki,关了向量/关键词检索
|
||||
const isWikiOnlyStrategy = computed(() => {
|
||||
const s = formData.value?.indexingStrategy
|
||||
if (!s) return false
|
||||
return !!s.wikiEnabled && !s.vectorEnabled && !s.keywordEnabled
|
||||
})
|
||||
|
||||
// 仅在创建模式、用户未改过分块设置时,随索引策略自动应用/撤销 Wiki-only 预设。
|
||||
// 编辑模式严格保持后端已有配置不变,避免误改。
|
||||
watch(isWikiOnlyStrategy, (wikiOnly) => {
|
||||
if (props.mode !== 'create') return
|
||||
if (!formData.value) return
|
||||
if (chunkingDirty.value) return
|
||||
const preset = wikiOnly ? WIKI_ONLY_CHUNKING_PRESET : DEFAULT_CHUNKING_PRESET
|
||||
formData.value.chunkingConfig = {
|
||||
...formData.value.chunkingConfig,
|
||||
...preset,
|
||||
}
|
||||
})
|
||||
|
||||
const handleParserEngineRulesUpdate = (rules: any[]) => {
|
||||
if (formData.value) {
|
||||
formData.value.chunkingConfig.parserEngineRules = rules?.length ? rules : undefined
|
||||
@@ -564,6 +751,10 @@ const handleAddASRModel = () => {
|
||||
uiStore.openSettings('models', 'asr')
|
||||
}
|
||||
|
||||
const handleAddWikiModel = () => {
|
||||
uiStore.openSettings('models', 'knowledgeqa')
|
||||
}
|
||||
|
||||
const handleStorageProviderUpdate = (value: string) => {
|
||||
if (formData.value) {
|
||||
formData.value.storageProvider = value || 'local'
|
||||
@@ -593,9 +784,20 @@ const validateForm = (): boolean => {
|
||||
return false
|
||||
}
|
||||
|
||||
// 验证模型配置 - 必须配置 embedding 和 summary 模型
|
||||
if (!formData.value.modelConfig.embeddingModelId) {
|
||||
MessagePlugin.warning(t('knowledgeEditor.messages.embeddingRequired'))
|
||||
// 验证索引策略 — 文档类型至少需要开启一种
|
||||
if (formData.value.type !== 'faq') {
|
||||
const s = formData.value.indexingStrategy
|
||||
if (s && !s.vectorEnabled && !s.keywordEnabled && !s.wikiEnabled && !s.graphEnabled) {
|
||||
MessagePlugin.warning(t('knowledgeEditor.indexing.atLeastOne'))
|
||||
currentSection.value = 'basic'
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 验证模型配置 - embedding 模型仅在检索索引启用时必须
|
||||
const needsEmbedding = formData.value.indexingStrategy?.vectorEnabled || formData.value.indexingStrategy?.keywordEnabled
|
||||
if (needsEmbedding && !formData.value.modelConfig.embeddingModelId) {
|
||||
MessagePlugin.warning(t('knowledgeEditor.indexing.embeddingRequired'))
|
||||
currentSection.value = 'models'
|
||||
return false
|
||||
}
|
||||
@@ -672,16 +874,8 @@ const buildSubmitData = () => {
|
||||
provider: formData.value.storageProvider || 'local'
|
||||
}
|
||||
|
||||
// 添加知识图谱配置
|
||||
if (formData.value.nodeExtractConfig.enabled) {
|
||||
data.extract_config = {
|
||||
enabled: true,
|
||||
text: formData.value.nodeExtractConfig.text,
|
||||
tags: formData.value.nodeExtractConfig.tags,
|
||||
nodes: formData.value.nodeExtractConfig.nodes,
|
||||
relations: formData.value.nodeExtractConfig.relations
|
||||
}
|
||||
}
|
||||
// 添加知识图谱配置 — now synced via indexingStrategy.graphEnabled
|
||||
// extract_config is sent below along with indexing_strategy
|
||||
|
||||
// 添加问题生成配置
|
||||
if (formData.value.questionGenerationConfig?.enabled) {
|
||||
@@ -698,6 +892,37 @@ const buildSubmitData = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// Wiki enablement is carried solely by indexing_strategy.wiki_enabled.
|
||||
// wiki_config only holds wiki-specific tunables.
|
||||
if (formData.value.type !== 'faq') {
|
||||
data.wiki_config = {
|
||||
synthesis_model_id: formData.value.modelConfig?.wikiSynthesisModelId || '',
|
||||
max_pages_per_ingest: formData.value.wikiConfig?.maxPagesPerIngest || 0,
|
||||
extraction_granularity: formData.value.wikiConfig?.extractionGranularity || 'standard',
|
||||
}
|
||||
}
|
||||
|
||||
// Send indexing strategy
|
||||
if (formData.value.type !== 'faq') {
|
||||
data.indexing_strategy = {
|
||||
vector_enabled: formData.value.indexingStrategy?.vectorEnabled ?? true,
|
||||
keyword_enabled: formData.value.indexingStrategy?.keywordEnabled ?? true,
|
||||
wiki_enabled: formData.value.indexingStrategy?.wikiEnabled ?? false,
|
||||
graph_enabled: formData.value.indexingStrategy?.graphEnabled ?? false,
|
||||
}
|
||||
}
|
||||
|
||||
// Sync extract_config.enabled from indexingStrategy.graphEnabled
|
||||
if (formData.value.indexingStrategy?.graphEnabled && formData.value.nodeExtractConfig?.enabled) {
|
||||
data.extract_config = {
|
||||
enabled: true,
|
||||
text: formData.value.nodeExtractConfig.text,
|
||||
tags: formData.value.nodeExtractConfig.tags,
|
||||
nodes: formData.value.nodeExtractConfig.nodes,
|
||||
relations: formData.value.nodeExtractConfig.relations
|
||||
}
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -756,7 +981,7 @@ const doSubmit = async () => {
|
||||
throw new Error(t('knowledgeEditor.messages.missingId'))
|
||||
}
|
||||
|
||||
// 1. 更新基本信息(名称、描述)和 FAQ 配置
|
||||
// 1. 更新基本信息(名称、描述)和 FAQ/Wiki 配置
|
||||
const updateConfig: any = {}
|
||||
if (formData.value.type === 'faq' && formData.value.faqConfig) {
|
||||
updateConfig.faq_config = {
|
||||
@@ -764,6 +989,21 @@ const doSubmit = async () => {
|
||||
question_index_mode: formData.value.faqConfig.questionIndexMode || 'separate'
|
||||
}
|
||||
}
|
||||
if (formData.value.wikiConfig && formData.value.type !== 'faq') {
|
||||
updateConfig.wiki_config = {
|
||||
synthesis_model_id: formData.value.modelConfig?.wikiSynthesisModelId || '',
|
||||
max_pages_per_ingest: formData.value.wikiConfig.maxPagesPerIngest || 0,
|
||||
extraction_granularity: formData.value.wikiConfig.extractionGranularity || 'standard',
|
||||
}
|
||||
}
|
||||
if (formData.value.type !== 'faq') {
|
||||
updateConfig.indexing_strategy = {
|
||||
vector_enabled: formData.value.indexingStrategy?.vectorEnabled ?? true,
|
||||
keyword_enabled: formData.value.indexingStrategy?.keywordEnabled ?? true,
|
||||
wiki_enabled: formData.value.indexingStrategy?.wikiEnabled ?? false,
|
||||
graph_enabled: formData.value.indexingStrategy?.graphEnabled ?? false,
|
||||
}
|
||||
}
|
||||
await updateKnowledgeBase(props.kbId, {
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
@@ -804,6 +1044,41 @@ const doSubmit = async () => {
|
||||
|
||||
await updateKBConfig(props.kbId, config)
|
||||
MessagePlugin.success(t('knowledgeEditor.messages.updateSuccess'))
|
||||
|
||||
// Check if indexing strategy changed and offer rebuild
|
||||
if (hasFiles.value && initialIndexingStrategy.value && formData.value) {
|
||||
const curr = formData.value.indexingStrategy
|
||||
const prev = initialIndexingStrategy.value
|
||||
const strategyChanged = (
|
||||
curr.vectorEnabled !== prev.vectorEnabled ||
|
||||
curr.keywordEnabled !== prev.keywordEnabled ||
|
||||
curr.wikiEnabled !== prev.wikiEnabled ||
|
||||
curr.graphEnabled !== prev.graphEnabled
|
||||
)
|
||||
if (strategyChanged) {
|
||||
const dialog = DialogPlugin.confirm({
|
||||
header: t('knowledgeEditor.indexing.rebuildConfirmTitle'),
|
||||
body: t('knowledgeEditor.indexing.rebuildConfirmBody', { count: '...' }),
|
||||
confirmBtn: t('common.confirm'),
|
||||
cancelBtn: t('common.cancel'),
|
||||
onConfirm: async () => {
|
||||
dialog.destroy()
|
||||
try {
|
||||
const result: any = await rebuildKBIndex(props.kbId!)
|
||||
const count = result?.data?.document_count ?? 0
|
||||
MessagePlugin.success(t('knowledgeEditor.indexing.rebuildSuccess', { count }))
|
||||
} catch (e) {
|
||||
console.error('Rebuild index failed:', e)
|
||||
}
|
||||
},
|
||||
onCancel: () => {
|
||||
dialog.destroy()
|
||||
MessagePlugin.info(t('knowledgeEditor.indexing.rebuildSkip'))
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
emit('success', props.kbId)
|
||||
}
|
||||
|
||||
@@ -822,8 +1097,10 @@ const resetState = () => {
|
||||
formData.value = null
|
||||
hasFiles.value = false
|
||||
initialStorageProvider.value = ''
|
||||
initialIndexingStrategy.value = null
|
||||
saving.value = false
|
||||
loading.value = false
|
||||
chunkingDirty.value = false
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
@@ -1069,7 +1346,7 @@ watch(
|
||||
}
|
||||
|
||||
.form-item {
|
||||
margin-bottom: 20px;
|
||||
margin-bottom: 16px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
@@ -1097,6 +1374,103 @@ watch(
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.granularity-radio-group {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.granularity-hint {
|
||||
margin-top: 8px;
|
||||
line-height: 1.6;
|
||||
color: var(--td-text-color-secondary);
|
||||
white-space: normal;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.indexing-checks {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.indexing-check-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: 8px;
|
||||
background: var(--td-bg-color-container);
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
transition: border-color 0.2s ease, background 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--td-brand-color);
|
||||
}
|
||||
|
||||
&.is-checked {
|
||||
border-color: var(--td-brand-color);
|
||||
background: var(--td-brand-color-light);
|
||||
}
|
||||
|
||||
&.is-disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.7;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--td-component-stroke);
|
||||
}
|
||||
|
||||
&.is-checked:hover {
|
||||
border-color: var(--td-brand-color);
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.t-checkbox__label) {
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.locked-tip {
|
||||
color: var(--td-warning-color);
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
// 禁用内部 checkbox 自身的点击事件,统一由卡片处理
|
||||
.indexing-check-box {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.indexing-check-title {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.indexing-new-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0 6px;
|
||||
height: 16px;
|
||||
border-radius: 3px;
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
letter-spacing: 0.4px;
|
||||
color: var(--td-brand-color);
|
||||
background: var(--td-brand-color-light);
|
||||
}
|
||||
|
||||
.indexing-check-desc {
|
||||
margin: 0;
|
||||
padding-left: 24px;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.faq-guide {
|
||||
margin-top: 20px;
|
||||
padding: 12px 16px;
|
||||
|
||||
@@ -1004,8 +1004,13 @@ const confirmDelete = () => {
|
||||
}
|
||||
|
||||
const isInitialized = (kb: KB) => {
|
||||
return !!(kb.embedding_model_id && kb.embedding_model_id !== '' &&
|
||||
kb.summary_model_id && kb.summary_model_id !== '')
|
||||
// LLM (summary) model is always required
|
||||
if (!kb.summary_model_id || kb.summary_model_id === '') return false
|
||||
// Embedding model only required when RAG indexing is enabled (vector or keyword)
|
||||
const strategy = (kb as any).indexing_strategy
|
||||
const needsEmbedding = !strategy || strategy.vector_enabled || strategy.keyword_enabled
|
||||
if (needsEmbedding && (!kb.embedding_model_id || kb.embedding_model_id === '')) return false
|
||||
return true
|
||||
}
|
||||
|
||||
// 计算是否有未初始化的知识库
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
defineProps<{
|
||||
count: number;
|
||||
loading?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'clear'): void;
|
||||
(e: 'delete'): void;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<transition name="batch-bar-fade">
|
||||
<div v-if="count > 0" class="doc-batch-bar" role="region" :aria-label="t('knowledgeBase.selectedCount', { count })">
|
||||
<div class="batch-bar-inner">
|
||||
<div class="batch-bar-left">
|
||||
<span class="batch-bar-count">{{ t('knowledgeBase.selectedCount', { count }) }}</span>
|
||||
<t-button variant="text" theme="default" size="small" class="batch-bar-clear" @click="emit('clear')">
|
||||
{{ t('knowledgeBase.clearSelection') }}
|
||||
</t-button>
|
||||
</div>
|
||||
<div class="batch-bar-actions">
|
||||
<t-button
|
||||
theme="danger"
|
||||
variant="outline"
|
||||
size="small"
|
||||
:loading="loading"
|
||||
@click="emit('delete')"
|
||||
>
|
||||
<template #icon><t-icon name="delete" size="14px" /></template>
|
||||
{{ t('knowledgeBase.batchDelete') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</transition>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
.doc-batch-bar {
|
||||
position: relative;
|
||||
z-index: 5;
|
||||
width: 100%;
|
||||
max-width: 560px;
|
||||
margin: 0 auto;
|
||||
padding: 0 4px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.batch-bar-inner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 8px 12px;
|
||||
background: var(--td-bg-color-container);
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.batch-bar-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.batch-bar-count {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-secondary);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.batch-bar-clear {
|
||||
flex-shrink: 0;
|
||||
padding: 0 6px !important;
|
||||
height: 28px !important;
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-secondary) !important;
|
||||
|
||||
&:hover {
|
||||
color: var(--td-brand-color) !important;
|
||||
}
|
||||
}
|
||||
|
||||
.batch-bar-actions {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.batch-bar-fade-enter-active,
|
||||
.batch-bar-fade-leave-active {
|
||||
transition: transform 0.2s ease, opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.batch-bar-fade-enter-from,
|
||||
.batch-bar-fade-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateY(6px);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,562 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { formatFileSize, getFileIcon } from '@/utils/files';
|
||||
|
||||
interface Tag {
|
||||
id: string;
|
||||
name: string;
|
||||
color?: string;
|
||||
}
|
||||
|
||||
interface KnowledgeItem {
|
||||
id: string;
|
||||
file_name: string;
|
||||
file_type?: string;
|
||||
file_size?: number | string;
|
||||
type?: string;
|
||||
tag_id?: string | number;
|
||||
parse_status?: string;
|
||||
summary_status?: string;
|
||||
updated_at?: string;
|
||||
source?: string;
|
||||
isMore?: boolean;
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
items: KnowledgeItem[];
|
||||
selectedIds: Set<string>;
|
||||
canEdit: boolean;
|
||||
tagList: Tag[];
|
||||
loading?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'open', item: KnowledgeItem): void;
|
||||
(e: 'toggle-row', id: string, checked: boolean, shiftKey: boolean): void;
|
||||
(e: 'toggle-all', checked: boolean): void;
|
||||
(e: 'action', action: 'edit' | 'reparse' | 'move' | 'delete', item: KnowledgeItem): void;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const tagMap = computed(() => {
|
||||
const map: Record<string, Tag> = {};
|
||||
for (const tag of props.tagList) map[String(tag.id)] = tag;
|
||||
return map;
|
||||
});
|
||||
const getTagName = (tagId?: string | number) => {
|
||||
if (!tagId && tagId !== 0) return '';
|
||||
return tagMap.value[String(tagId)]?.name || '';
|
||||
};
|
||||
|
||||
const formatTime = (time?: string) => {
|
||||
if (!time) return '--';
|
||||
const d = new Date(time);
|
||||
if (Number.isNaN(d.getTime())) return '--';
|
||||
const yy = String(d.getFullYear()).slice(2);
|
||||
const MM = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const dd = String(d.getDate()).padStart(2, '0');
|
||||
const hh = String(d.getHours()).padStart(2, '0');
|
||||
const mm = String(d.getMinutes()).padStart(2, '0');
|
||||
return `${yy}-${MM}-${dd} ${hh}:${mm}`;
|
||||
};
|
||||
|
||||
const getTypeLabel = (item: KnowledgeItem) => {
|
||||
if (item.type === 'url') return 'URL';
|
||||
if (item.type === 'manual') return t('knowledgeBase.typeManual');
|
||||
if (item.file_type) return item.file_type.toUpperCase();
|
||||
return '--';
|
||||
};
|
||||
|
||||
interface StatusInfo {
|
||||
label: string;
|
||||
theme: 'success' | 'warning' | 'danger' | 'primary' | 'default';
|
||||
icon?: string;
|
||||
spin?: boolean;
|
||||
}
|
||||
const computeStatus = (item: KnowledgeItem): StatusInfo => {
|
||||
if (item.parse_status === 'pending' || item.parse_status === 'processing') {
|
||||
return { label: t('knowledgeBase.statusProcessing'), theme: 'primary', icon: 'loading', spin: true };
|
||||
}
|
||||
if (item.parse_status === 'failed') {
|
||||
return { label: t('knowledgeBase.statusFailed'), theme: 'danger', icon: 'close-circle' };
|
||||
}
|
||||
if (item.parse_status === 'draft') {
|
||||
return { label: t('knowledgeBase.statusDraft'), theme: 'warning' };
|
||||
}
|
||||
if (
|
||||
item.parse_status === 'completed' &&
|
||||
(item.summary_status === 'pending' || item.summary_status === 'processing')
|
||||
) {
|
||||
return { label: t('knowledgeBase.generatingSummary'), theme: 'primary', icon: 'loading', spin: true };
|
||||
}
|
||||
if (item.parse_status === 'completed') {
|
||||
return { label: t('knowledgeBase.statusCompleted'), theme: 'success' };
|
||||
}
|
||||
return { label: '--', theme: 'default' };
|
||||
};
|
||||
|
||||
const statusByRow = computed(() => {
|
||||
const map = new Map<string, StatusInfo>();
|
||||
for (const item of props.items) map.set(item.id, computeStatus(item));
|
||||
return map;
|
||||
});
|
||||
|
||||
const allSelected = computed(() => {
|
||||
return props.items.length > 0 && props.items.every(i => props.selectedIds.has(i.id));
|
||||
});
|
||||
const someSelected = computed(() => {
|
||||
return props.items.some(i => props.selectedIds.has(i.id)) && !allSelected.value;
|
||||
});
|
||||
|
||||
const onHeaderCheckboxChange = (checked: boolean) => {
|
||||
emit('toggle-all', checked);
|
||||
};
|
||||
|
||||
const onRowCheckboxChange = (item: KnowledgeItem, checked: boolean, ctx?: { e?: Event }) => {
|
||||
const me = ctx?.e as MouseEvent | undefined;
|
||||
emit('toggle-row', item.id, checked, !!me?.shiftKey);
|
||||
};
|
||||
|
||||
const moreOpen = ref<string | null>(null);
|
||||
const onMoreVisible = (id: string, visible: boolean) => {
|
||||
moreOpen.value = visible ? id : null;
|
||||
};
|
||||
|
||||
const handleAction = (action: 'edit' | 'reparse' | 'move' | 'delete', item: KnowledgeItem) => {
|
||||
moreOpen.value = null;
|
||||
item.isMore = false;
|
||||
emit('action', action, item);
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="doc-list-view" :class="{ 'is-loading': loading }">
|
||||
<div class="doc-list-header" role="row">
|
||||
<div class="cell cell-check" role="columnheader" @click.stop>
|
||||
<t-checkbox
|
||||
class="doc-list-check"
|
||||
size="small"
|
||||
:checked="allSelected"
|
||||
:indeterminate="someSelected"
|
||||
:disabled="!items.length"
|
||||
:title="t('knowledgeBase.selectAll')"
|
||||
@change="onHeaderCheckboxChange"
|
||||
/>
|
||||
</div>
|
||||
<div class="cell cell-name" role="columnheader">{{ t('knowledgeBase.columnName') }}</div>
|
||||
<div class="cell cell-tag" role="columnheader">{{ t('knowledgeBase.columnTag') }}</div>
|
||||
<div class="cell cell-size" role="columnheader">{{ t('knowledgeBase.columnSize') }}</div>
|
||||
<div class="cell cell-type" role="columnheader">{{ t('knowledgeBase.columnType') }}</div>
|
||||
<div class="cell cell-status" role="columnheader">{{ t('knowledgeBase.columnStatus') }}</div>
|
||||
<div class="cell cell-time" role="columnheader">{{ t('knowledgeBase.columnUpdatedAt') }}</div>
|
||||
<div class="cell cell-actions" role="columnheader" v-if="canEdit"></div>
|
||||
</div>
|
||||
|
||||
<div class="doc-list-body">
|
||||
<div
|
||||
v-for="item in items"
|
||||
:key="item.id"
|
||||
class="doc-list-row"
|
||||
:class="{ selected: selectedIds.has(item.id), 'menu-open': moreOpen === item.id }"
|
||||
role="row"
|
||||
@click="emit('open', item)"
|
||||
>
|
||||
<div class="cell cell-check" @click.stop>
|
||||
<t-checkbox
|
||||
class="doc-list-check"
|
||||
size="small"
|
||||
:checked="selectedIds.has(item.id)"
|
||||
:title="item.file_name"
|
||||
@change="(c, ctx) => onRowCheckboxChange(item, c, ctx)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="cell cell-name">
|
||||
<span class="row-file-icon-wrap">
|
||||
<t-icon :name="getFileIcon(item)" />
|
||||
</span>
|
||||
<span class="row-file-name" :title="item.file_name">{{ item.file_name }}</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="cell cell-tag">
|
||||
<t-tag v-if="getTagName(item.tag_id)" size="small" variant="light-outline" class="row-tag">
|
||||
{{ getTagName(item.tag_id) }}
|
||||
</t-tag>
|
||||
<span v-else class="row-muted">--</span>
|
||||
</div>
|
||||
|
||||
<div class="cell cell-size">
|
||||
<span class="row-mono">{{ formatFileSize(item.file_size) || '--' }}</span>
|
||||
</div>
|
||||
|
||||
<div class="cell cell-type">
|
||||
<span class="row-mono">{{ getTypeLabel(item) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="cell cell-status">
|
||||
<template v-if="statusByRow.get(item.id) as StatusInfo | undefined">
|
||||
<t-tag
|
||||
v-if="statusByRow.get(item.id)!.label !== '--'"
|
||||
size="small"
|
||||
:theme="statusByRow.get(item.id)!.theme"
|
||||
variant="light-outline"
|
||||
class="row-status-tag"
|
||||
>
|
||||
<template v-if="statusByRow.get(item.id)!.icon" #icon>
|
||||
<t-icon
|
||||
:name="statusByRow.get(item.id)!.icon!"
|
||||
:class="{ 'icon-spin': statusByRow.get(item.id)!.spin }"
|
||||
/>
|
||||
</template>
|
||||
{{ statusByRow.get(item.id)!.label }}
|
||||
</t-tag>
|
||||
<span v-else class="row-muted">--</span>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div class="cell cell-time">
|
||||
<span class="row-mono">{{ formatTime(item.updated_at) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="cell cell-actions" v-if="canEdit" @click.stop>
|
||||
<t-popup
|
||||
placement="bottom-right"
|
||||
trigger="click"
|
||||
destroy-on-close
|
||||
:on-visible-change="(v: boolean) => onMoreVisible(item.id, v)"
|
||||
>
|
||||
<button class="row-more-btn" :class="{ active: moreOpen === item.id }" type="button" :aria-label="t('knowledgeBase.columnActions')">
|
||||
<t-icon name="more" size="16px" />
|
||||
</button>
|
||||
<template #content>
|
||||
<div class="row-menu">
|
||||
<div
|
||||
v-if="item.type === 'manual'"
|
||||
class="row-menu-item"
|
||||
@click.stop="handleAction('edit', item)"
|
||||
>
|
||||
<t-icon class="icon" name="edit" />
|
||||
<span>{{ t('knowledgeBase.editDocument') }}</span>
|
||||
</div>
|
||||
<div class="row-menu-item" @click.stop="handleAction('reparse', item)">
|
||||
<t-icon class="icon" name="refresh" />
|
||||
<span>{{ t('knowledgeBase.rebuildDocument') }}</span>
|
||||
</div>
|
||||
<div class="row-menu-item" @click.stop="handleAction('move', item)">
|
||||
<t-icon class="icon" name="swap" />
|
||||
<span>{{ t('knowledgeBase.moveDocument') }}</span>
|
||||
</div>
|
||||
<div class="row-menu-item danger" @click.stop="handleAction('delete', item)">
|
||||
<t-icon class="icon" name="delete" />
|
||||
<span>{{ t('knowledgeBase.deleteDocument') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
@keyframes doc-list-fade-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(6px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.doc-list-view {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
background: var(--td-bg-color-container);
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: 9px;
|
||||
/* 不能用 overflow:hidden,否则表头 position:sticky 相对外层滚动区失效 */
|
||||
overflow: visible;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
|
||||
animation: doc-list-fade-in 0.32s ease-out;
|
||||
}
|
||||
|
||||
.doc-list-header,
|
||||
.doc-list-row {
|
||||
display: grid;
|
||||
grid-template-columns:
|
||||
44px // checkbox
|
||||
minmax(220px, 2.4fr) // name
|
||||
minmax(100px, 0.9fr) // tag
|
||||
96px // size
|
||||
72px // type
|
||||
minmax(96px, 0.7fr) // status
|
||||
140px // updated_at
|
||||
48px; // actions
|
||||
align-items: center;
|
||||
column-gap: 0;
|
||||
padding: 0 16px;
|
||||
}
|
||||
|
||||
.doc-list-header {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 3;
|
||||
height: 40px;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
font-family: 'PingFang SC', -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
color: var(--td-text-color-secondary);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
border-radius: 8px 8px 0 0;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
.doc-list-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-radius: 0 0 8px 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.doc-list-row {
|
||||
position: relative;
|
||||
min-height: 52px;
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-primary);
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
&:hover:not(.selected),
|
||||
&.menu-open:not(.selected) {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
}
|
||||
|
||||
&:hover .row-more-btn,
|
||||
&.menu-open .row-more-btn,
|
||||
&.selected .row-more-btn {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-width: 0;
|
||||
padding: 0 8px;
|
||||
&:first-child { padding-left: 0; }
|
||||
&:last-child { padding-right: 0; }
|
||||
}
|
||||
|
||||
.cell-check {
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.cell-name {
|
||||
gap: 10px;
|
||||
font-family: 'PingFang SC', -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
}
|
||||
|
||||
.cell-size,
|
||||
.cell-time {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.cell-actions {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
/* TDesign 勾选框:去掉空白 label、与表格行对齐 */
|
||||
.doc-list-check {
|
||||
margin: 0;
|
||||
|
||||
:deep(.t-checkbox) {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
:deep(.t-checkbox__label) {
|
||||
display: none !important;
|
||||
width: 0 !important;
|
||||
min-width: 0 !important;
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
:deep(.t-checkbox__input) {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
:deep(.t-checkbox__input-wrapper) {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.row-file-icon-wrap {
|
||||
flex-shrink: 0;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 6px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 16px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
.row-file-name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.01em;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.row-tag {
|
||||
max-width: 100%;
|
||||
:deep(.t-tag__text) {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 120px;
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
|
||||
.row-muted {
|
||||
color: var(--td-text-color-disabled, #bbb);
|
||||
}
|
||||
|
||||
.row-mono {
|
||||
font-variant-numeric: tabular-nums;
|
||||
font-size: 12px;
|
||||
font-family: 'PingFang SC', -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
.row-status-tag :deep(.t-icon) {
|
||||
margin-right: 2px;
|
||||
}
|
||||
.icon-spin {
|
||||
animation: doc-list-spin 0.9s linear infinite;
|
||||
}
|
||||
@keyframes doc-list-spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.row-more-btn {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
border-radius: 5px;
|
||||
color: var(--td-text-color-secondary);
|
||||
cursor: pointer;
|
||||
opacity: 0;
|
||||
transition: opacity 0.15s ease, background-color 0.15s ease, color 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
background: var(--td-component-stroke);
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
&.active {
|
||||
opacity: 1;
|
||||
background: var(--td-component-stroke);
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.row-menu {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 140px;
|
||||
gap: 2px;
|
||||
padding: 4px 6px;
|
||||
}
|
||||
|
||||
.row-menu-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 8px 12px;
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
color: var(--td-text-color-primary);
|
||||
cursor: pointer;
|
||||
border-radius: 6px;
|
||||
transition: background-color 0.15s cubic-bezier(0.2, 0, 0, 1), transform 0.12s ease;
|
||||
|
||||
&:hover {
|
||||
background: var(--td-bg-color-container-hover);
|
||||
}
|
||||
|
||||
&:active {
|
||||
background: var(--td-bg-color-container-active);
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
.icon {
|
||||
font-size: 16px;
|
||||
color: var(--td-text-color-secondary);
|
||||
transition: color 0.15s ease;
|
||||
}
|
||||
|
||||
&:hover .icon {
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
&.danger {
|
||||
color: var(--td-error-color-6);
|
||||
margin-top: 4px;
|
||||
position: relative;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: -3px;
|
||||
left: 8px;
|
||||
right: 8px;
|
||||
height: 1px;
|
||||
background: var(--td-component-stroke);
|
||||
}
|
||||
|
||||
.icon {
|
||||
color: var(--td-error-color-6);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: var(--td-error-color-1);
|
||||
color: var(--td-error-color-6);
|
||||
|
||||
.icon {
|
||||
color: var(--td-error-color-6);
|
||||
}
|
||||
}
|
||||
|
||||
&:active {
|
||||
background: var(--td-error-color-2);
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -149,7 +149,7 @@ interface ConnectorDef {
|
||||
permissionDocUrl: string
|
||||
permissionPageUrl: string
|
||||
requiredPermissions: string[]
|
||||
fields: { key: string; labelKey: string; placeholder: string; secret?: boolean }[]
|
||||
fields: { key: string; labelKey: string; placeholder: string; secret?: boolean; optional?: boolean; hintKey?: string }[]
|
||||
}
|
||||
|
||||
const connectorDefs = computed<ConnectorDef[]>(() => [
|
||||
@@ -183,13 +183,17 @@ const connectorDefs = computed<ConnectorDef[]>(() => [
|
||||
},
|
||||
{
|
||||
type: 'yuque',
|
||||
available: false,
|
||||
docUrl: 'https://www.yuque.com/settings/tokens',
|
||||
permissionDocUrl: '',
|
||||
permissionPageUrl: '',
|
||||
requiredPermissions: [],
|
||||
available: true,
|
||||
docUrl: 'https://www.yuque.com/yuque/developer/api',
|
||||
permissionDocUrl: 'https://www.yuque.com/yuque/developer/api',
|
||||
permissionPageUrl: 'https://www.yuque.com/settings/tokens',
|
||||
requiredPermissions: [
|
||||
'repo:read',
|
||||
'doc:read',
|
||||
],
|
||||
fields: [
|
||||
{ key: 'api_token', labelKey: 'datasource.field.apiToken', placeholder: '', secret: true },
|
||||
{ key: 'base_url', labelKey: 'datasource.field.baseUrl', placeholder: 'https://www.yuque.com', optional: true, hintKey: 'datasource.field.baseUrlHint' },
|
||||
],
|
||||
},
|
||||
])
|
||||
@@ -244,6 +248,7 @@ function selectType(def: ConnectorDef) {
|
||||
async function testConnection() {
|
||||
const fields = currentDef.value?.fields || []
|
||||
for (const f of fields) {
|
||||
if (f.optional) continue
|
||||
if (!form.value.config.credentials[f.key]) {
|
||||
MessagePlugin.warning(`${t(f.labelKey)} ${t('datasource.isRequired')}`)
|
||||
return
|
||||
@@ -373,6 +378,7 @@ function toggleResource(id: string) {
|
||||
function validateStep1Fields(): boolean {
|
||||
const fields = currentDef.value?.fields || []
|
||||
for (const f of fields) {
|
||||
if (f.optional) continue
|
||||
if (!form.value.config.credentials[f.key]) {
|
||||
MessagePlugin.warning(`${t(f.labelKey)} ${t('datasource.isRequired')}`)
|
||||
return false
|
||||
@@ -458,6 +464,7 @@ async function handleClose() {
|
||||
const resourceTypeLabelMap: Record<string, string> = {
|
||||
wiki_space: 'datasource.resourceType.wikiSpace',
|
||||
doc_category: 'datasource.resourceType.docCategory',
|
||||
book: 'datasource.resourceType.book',
|
||||
}
|
||||
|
||||
function resourceTypeLabel(type: string): string {
|
||||
@@ -549,7 +556,7 @@ const stepTitles = computed(() => [
|
||||
</div>
|
||||
</div>
|
||||
<a :href="currentDef.permissionPageUrl" target="_blank" rel="noopener" class="ds-prereq-link">
|
||||
{{ t('datasource.prereqOpenConsole') }}
|
||||
{{ t(`datasource.prereqOpenConsole_${form.type}`, t('datasource.prereqOpenConsole')) }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -565,12 +572,16 @@ const stepTitles = computed(() => [
|
||||
</div>
|
||||
|
||||
<div v-for="field in currentDef?.fields || []" :key="field.key" class="form-item">
|
||||
<label class="form-label">{{ t(field.labelKey) }}</label>
|
||||
<label class="form-label">
|
||||
{{ t(field.labelKey) }}
|
||||
<span v-if="!field.optional" class="required-mark">*</span>
|
||||
</label>
|
||||
<t-input
|
||||
v-model="form.config.credentials[field.key]"
|
||||
:placeholder="field.placeholder"
|
||||
:type="field.secret ? 'password' : 'text'"
|
||||
/>
|
||||
<div v-if="field.hintKey" class="form-hint">{{ t(field.hintKey) }}</div>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
@@ -871,7 +882,9 @@ const stepTitles = computed(() => [
|
||||
|
||||
.form-item { margin-bottom: 16px; }
|
||||
.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--td-text-color-primary); }
|
||||
.required-mark { color: var(--td-error-color); margin-left: 2px; }
|
||||
.form-tip { font-size: 12px; color: var(--td-text-color-placeholder); margin: 4px 0 12px; }
|
||||
.form-hint { font-size: 12px; color: var(--td-text-color-placeholder); margin-top: 6px; line-height: 1.5; }
|
||||
.form-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
|
||||
.test-ok { color: var(--td-success-color); font-size: 13px; display: flex; align-items: center; gap: 4px; }
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
</div>
|
||||
|
||||
<div class="settings-group">
|
||||
<!-- Question Generation feature -->
|
||||
<!-- Question Generation feature (only useful for RAG indexing) -->
|
||||
<template v-if="ragEnabled !== false">
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.questionGeneration.label') }}</label>
|
||||
@@ -41,6 +42,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -56,6 +58,7 @@ interface QuestionGenerationConfig {
|
||||
|
||||
interface Props {
|
||||
questionGeneration?: QuestionGenerationConfig
|
||||
ragEnabled?: boolean
|
||||
allModels?: any[]
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
<template>
|
||||
<div class="kb-multimodal-settings">
|
||||
<div class="section-header">
|
||||
<h2>{{ $t('knowledgeEditor.indexing.title') }}</h2>
|
||||
<p class="section-description">{{ $t('knowledgeEditor.indexing.description') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-group">
|
||||
<!-- Hybrid Search (vector + keyword combined) -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.indexing.searchTitle') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.indexing.searchDesc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch
|
||||
:model-value="searchEnabled"
|
||||
@change="handleSearchToggle"
|
||||
size="medium"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Wiki -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.indexing.wikiTitle') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.indexing.wikiDesc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch
|
||||
:model-value="modelValue.wikiEnabled"
|
||||
@change="(val: boolean) => update('wikiEnabled', val)"
|
||||
size="medium"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Wiki sub-settings (inline when enabled) -->
|
||||
<template v-if="modelValue.wikiEnabled">
|
||||
<slot name="wiki-settings" />
|
||||
</template>
|
||||
|
||||
<!-- Knowledge Graph -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.indexing.graphTitle') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.indexing.graphDesc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch
|
||||
:model-value="modelValue.graphEnabled"
|
||||
@change="(val: boolean) => update('graphEnabled', val)"
|
||||
size="medium"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Graph sub-settings (inline when enabled) -->
|
||||
<template v-if="modelValue.graphEnabled">
|
||||
<slot name="graph-settings" />
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
export interface IndexingStrategy {
|
||||
vectorEnabled: boolean
|
||||
keywordEnabled: boolean
|
||||
wikiEnabled: boolean
|
||||
graphEnabled: boolean
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: IndexingStrategy
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:modelValue', value: IndexingStrategy): void
|
||||
}>()
|
||||
|
||||
// Search = vector + keyword combined (the system always uses hybrid search internally)
|
||||
const searchEnabled = computed(() => props.modelValue.vectorEnabled || props.modelValue.keywordEnabled)
|
||||
|
||||
const handleSearchToggle = (val: boolean) => {
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
vectorEnabled: val,
|
||||
keywordEnabled: val,
|
||||
})
|
||||
}
|
||||
|
||||
const update = (field: keyof IndexingStrategy, value: boolean) => {
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
[field]: value,
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
/* NOT scoped — these classes must match the parent modal's scoped styles.
|
||||
Since slot content is rendered in the parent scope, only the wrapper
|
||||
elements defined HERE need their own styles. We replicate the same
|
||||
design tokens used by .kb-multimodal-settings in the parent. */
|
||||
</style>
|
||||
@@ -25,15 +25,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Embedding 嵌入模型 -->
|
||||
<div class="setting-row">
|
||||
<!-- Embedding 嵌入模型 (仅 RAG 检索启用时必填) -->
|
||||
<div v-if="ragEnabled !== false" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.models.embeddingLabel') }} <span class="required">*</span></label>
|
||||
<label>{{ $t('knowledgeEditor.models.embeddingLabel') }} <span v-if="ragEnabled" class="required">*</span></label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.models.embeddingDesc') }}</p>
|
||||
<t-alert
|
||||
v-if="hasFiles"
|
||||
theme="warning"
|
||||
:message="$t('knowledgeEditor.models.embeddingLocked')"
|
||||
<t-alert
|
||||
v-if="hasFiles"
|
||||
theme="warning"
|
||||
:message="$t('knowledgeEditor.models.embeddingLocked')"
|
||||
style="margin-top: 8px;"
|
||||
/>
|
||||
</div>
|
||||
@@ -51,6 +51,24 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Wiki 合成模型 (仅当 Wiki 启用时显示) -->
|
||||
<div v-if="wikiEnabled" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.wiki.synthesisModelLabel') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.wiki.synthesisModelTip') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<ModelSelector
|
||||
model-type="KnowledgeQA"
|
||||
:selected-model-id="config.wikiSynthesisModelId"
|
||||
:all-models="allModels"
|
||||
@update:selected-model-id="handleWikiModelChange"
|
||||
@add-model="handleAddModel('knowledgeqa')"
|
||||
:placeholder="$t('knowledgeEditor.wiki.synthesisModelPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -65,11 +83,14 @@ interface ModelConfig {
|
||||
llmModelId?: string
|
||||
embeddingModelId?: string
|
||||
vllmModelId?: string
|
||||
wikiSynthesisModelId?: string
|
||||
}
|
||||
|
||||
interface Props {
|
||||
config: ModelConfig
|
||||
hasFiles: boolean
|
||||
wikiEnabled?: boolean
|
||||
ragEnabled?: boolean
|
||||
allModels?: any[]
|
||||
}
|
||||
|
||||
@@ -82,11 +103,9 @@ const emit = defineEmits<{
|
||||
const uiStore = useUIStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
// 引用各个模型选择器
|
||||
const llmSelectorRef = ref<InstanceType<typeof ModelSelector>>()
|
||||
const embeddingSelectorRef = ref<InstanceType<typeof ModelSelector>>()
|
||||
|
||||
// 处理LLM模型变化
|
||||
const handleLLMChange = (modelId: string) => {
|
||||
emit('update:config', {
|
||||
...props.config,
|
||||
@@ -94,7 +113,6 @@ const handleLLMChange = (modelId: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
// 处理Embedding模型变化
|
||||
const handleEmbeddingChange = (modelId: string) => {
|
||||
emit('update:config', {
|
||||
...props.config,
|
||||
@@ -102,13 +120,16 @@ const handleEmbeddingChange = (modelId: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
// 处理添加模型按钮点击
|
||||
const handleAddModel = (subSection: string) => {
|
||||
// 打开全局设置对话框,并导航到对应的模型子页面
|
||||
uiStore.openSettings('models', subSection)
|
||||
const handleWikiModelChange = (modelId: string) => {
|
||||
emit('update:config', {
|
||||
...props.config,
|
||||
wikiSynthesisModelId: modelId
|
||||
})
|
||||
}
|
||||
|
||||
// 由于使用了 allModels prop,不再需要单独刷新各个选择器
|
||||
const handleAddModel = (subSection: string) => {
|
||||
uiStore.openSettings('models', subSection)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,9 @@
|
||||
<template>
|
||||
<div class="main" ref="dropzone">
|
||||
<Menu></Menu>
|
||||
<RouterView v-if="isRouterAlive" />
|
||||
<div v-if="isRouterAlive" class="platform-route-outlet">
|
||||
<RouterView />
|
||||
</div>
|
||||
<div class="upload-mask" v-show="ismask">
|
||||
<input type="file" style="display: none" ref="uploadInput" accept=".pdf,.docx,.doc,.pptx,.ppt,.txt,.md,.jpg,.jpeg,.png,.csv,.xls,.xlsx" />
|
||||
<UploadMask></UploadMask>
|
||||
@@ -36,7 +38,15 @@ const reloadApp = () => {
|
||||
}
|
||||
provide('app:reload', reloadApp)
|
||||
|
||||
// 仅在 Wails 桌面端运行时拦截 Cmd/Ctrl+R:
|
||||
// 桌面端没有浏览器地址栏,整页重载会白屏,所以用前端软刷新替代。
|
||||
// 浏览器(含 Web 版 / 非 Lite 部署)里不拦截,交给浏览器做真正的整页刷新,
|
||||
// 否则会出现左侧菜单、全局设置、Pinia store 等不随"刷新"一起重置的问题。
|
||||
// @ts-ignore
|
||||
const isWailsDesktop = typeof window !== 'undefined' && !!(window as any).runtime?.EventsOn
|
||||
|
||||
const handleGlobalKeyDown = (e: KeyboardEvent) => {
|
||||
if (!isWailsDesktop) return
|
||||
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'r') {
|
||||
e.preventDefault()
|
||||
reloadApp()
|
||||
@@ -64,7 +74,13 @@ const checkKnowledgeBaseInitialization = async (): Promise<boolean> => {
|
||||
const kbResponse = await getKnowledgeBaseById(currentKbId);
|
||||
const kb = kbResponse.data;
|
||||
|
||||
if (!kb.embedding_model_id || !kb.summary_model_id) {
|
||||
if (!kb.summary_model_id) {
|
||||
MessagePlugin.warning(t('knowledgeBase.notInitialized'));
|
||||
return false;
|
||||
}
|
||||
const strategy = kb.indexing_strategy;
|
||||
const needsEmbedding = !strategy || strategy.vector_enabled || strategy.keyword_enabled;
|
||||
if (needsEmbedding && !kb.embedding_model_id) {
|
||||
MessagePlugin.warning(t('knowledgeBase.notInitialized'));
|
||||
return false;
|
||||
}
|
||||
@@ -134,9 +150,8 @@ onMounted(() => {
|
||||
document.addEventListener('dragover', handleGlobalDragOver, true);
|
||||
document.addEventListener('dragleave', handleGlobalDragLeave, true);
|
||||
document.addEventListener('drop', handleGlobalDrop, true);
|
||||
window.addEventListener('keydown', handleGlobalKeyDown);
|
||||
// @ts-ignore
|
||||
if (window.runtime?.EventsOn) {
|
||||
if (isWailsDesktop) {
|
||||
window.addEventListener('keydown', handleGlobalKeyDown);
|
||||
// @ts-ignore
|
||||
window.runtime.EventsOn('app:reload', () => {
|
||||
reloadApp()
|
||||
@@ -150,11 +165,13 @@ onUnmounted(() => {
|
||||
document.removeEventListener('dragover', handleGlobalDragOver, true);
|
||||
document.removeEventListener('dragleave', handleGlobalDragLeave, true);
|
||||
document.removeEventListener('drop', handleGlobalDrop, true);
|
||||
window.removeEventListener('keydown', handleGlobalKeyDown);
|
||||
// @ts-ignore
|
||||
if (window.runtime?.EventsOff) {
|
||||
if (isWailsDesktop) {
|
||||
window.removeEventListener('keydown', handleGlobalKeyDown);
|
||||
// @ts-ignore
|
||||
window.runtime.EventsOff('app:reload')
|
||||
if (window.runtime?.EventsOff) {
|
||||
// @ts-ignore
|
||||
window.runtime.EventsOff('app:reload')
|
||||
}
|
||||
}
|
||||
dragCounter = 0;
|
||||
});
|
||||
@@ -162,13 +179,25 @@ onUnmounted(() => {
|
||||
<style lang="less">
|
||||
.main {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-width: 600px;
|
||||
min-height: 0;
|
||||
/* 统一整页背景,让左侧菜单与右侧内容区视觉连贯 */
|
||||
background: var(--td-bg-color-container);
|
||||
}
|
||||
|
||||
/* 右侧路由区:占满剩余宽度与整列高度,并把 min-height:0 传给子页面以便内部 flex 滚动 */
|
||||
.platform-route-outlet {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.upload-mask {
|
||||
background-color: rgba(255, 255, 255, 0.8);
|
||||
position: fixed;
|
||||
|
||||
@@ -350,7 +350,11 @@ function convertToLegacyFormat(model: ModelConfig) {
|
||||
provider: model.parameters.provider || '', // 添加 provider 字段
|
||||
dimension: model.parameters.embedding_parameters?.dimension,
|
||||
isBuiltin: model.is_builtin || false,
|
||||
supportsVision: model.parameters.supports_vision || false
|
||||
supportsVision: model.parameters.supports_vision || false,
|
||||
// 将后端 map 形式转换为前端可编辑的数组形式
|
||||
customHeaders: model.parameters.custom_headers
|
||||
? Object.entries(model.parameters.custom_headers).map(([key, value]) => ({ key, value: String(value) }))
|
||||
: []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -426,6 +430,18 @@ const handleModelSave = async (modelData: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 将前端 Key-Value 数组形式的自定义 Header 转换成后端期望的 map
|
||||
const customHeadersMap: Record<string, string> = {}
|
||||
if (Array.isArray(modelData.customHeaders)) {
|
||||
for (const item of modelData.customHeaders) {
|
||||
const key = (item?.key ?? '').trim()
|
||||
const value = (item?.value ?? '').trim()
|
||||
if (key && value) {
|
||||
customHeadersMap[key] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 将前端格式转换为后端格式
|
||||
const apiModelData: ModelConfig = {
|
||||
name: modelData.modelName.trim(), // 使用 modelName 作为 name,并去除首尾空格
|
||||
@@ -436,6 +452,7 @@ const handleModelSave = async (modelData: any) => {
|
||||
base_url: modelData.baseUrl?.trim() || '',
|
||||
api_key: modelData.apiKey?.trim() || '',
|
||||
provider: modelData.provider || '', // 添加 provider 字段
|
||||
...(Object.keys(customHeadersMap).length > 0 ? { custom_headers: customHeadersMap } : {}),
|
||||
...(currentModelType.value === 'embedding' && modelData.dimension ? {
|
||||
embedding_parameters: {
|
||||
dimension: modelData.dimension,
|
||||
@@ -503,6 +520,12 @@ const getModelOptions = (type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr',
|
||||
value: `edit-${type}-${model.id}`
|
||||
})
|
||||
|
||||
// 复制选项
|
||||
options.push({
|
||||
content: t('common.copy'),
|
||||
value: `copy-${type}-${model.id}`
|
||||
})
|
||||
|
||||
// 删除选项
|
||||
options.push({
|
||||
content: t('common.delete'),
|
||||
@@ -519,6 +542,8 @@ const handleMenuAction = (data: { value: string }, type: 'chat' | 'embedding' |
|
||||
|
||||
if (value.indexOf('edit-') === 0) {
|
||||
editModel(type, model)
|
||||
} else if (value.indexOf('copy-') === 0) {
|
||||
copyModel(type, model.id)
|
||||
} else if (value.indexOf('delete-') === 0) {
|
||||
// 使用确认对话框进行确认
|
||||
if (confirm(t('modelSettings.confirmDelete'))) {
|
||||
@@ -527,6 +552,48 @@ const handleMenuAction = (data: { value: string }, type: 'chat' | 'embedding' |
|
||||
}
|
||||
}
|
||||
|
||||
// 生成不重复的复制名称:原名 + 复制后缀(若已存在则追加序号)
|
||||
const generateCopyName = (originalName: string): string => {
|
||||
const suffix = t('modelSettings.copySuffix')
|
||||
const existingNames = new Set(allModels.value.map(m => m.name))
|
||||
let candidate = `${originalName}${suffix}`
|
||||
let counter = 2
|
||||
while (existingNames.has(candidate)) {
|
||||
candidate = `${originalName}${suffix} ${counter}`
|
||||
counter += 1
|
||||
}
|
||||
return candidate
|
||||
}
|
||||
|
||||
// 复制模型
|
||||
const copyModel = async (_type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr', modelId: string) => {
|
||||
const source = allModels.value.find(m => m.id === modelId)
|
||||
if (!source) {
|
||||
return
|
||||
}
|
||||
if (source.is_builtin) {
|
||||
MessagePlugin.warning(t('modelSettings.toasts.builtinCannotCopy'))
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const newModel: ModelConfig = {
|
||||
name: generateCopyName(source.name),
|
||||
type: source.type,
|
||||
source: source.source,
|
||||
description: source.description || '',
|
||||
parameters: JSON.parse(JSON.stringify(source.parameters || {}))
|
||||
}
|
||||
|
||||
await createModel(newModel)
|
||||
MessagePlugin.success(t('modelSettings.toasts.copied'))
|
||||
await loadModels()
|
||||
} catch (error: any) {
|
||||
console.error('复制模型失败:', error)
|
||||
MessagePlugin.error(error.message || t('modelSettings.toasts.copyFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
// 获取后端模型类型
|
||||
function getModelType(type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr'): 'KnowledgeQA' | 'Embedding' | 'Rerank' | 'VLLM' | 'ASR' {
|
||||
const typeMap = {
|
||||
|
||||
@@ -25,195 +25,201 @@
|
||||
<p class="empty-text">{{ $t('settings.parser.noEngineDetected') }}</p>
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div v-else class="engine-cards">
|
||||
<!-- 当后端未返回 builtin 引擎项时,仍展示 DocReader 状态卡片 -->
|
||||
<div v-if="!hasBuiltinEngine" class="engine-item first" data-model-type="builtin">
|
||||
<div class="engine-item-header">
|
||||
<div class="engine-title-row">
|
||||
<h3>builtin</h3>
|
||||
<t-tag
|
||||
:theme="connected ? 'success' : 'danger'"
|
||||
variant="light"
|
||||
size="small"
|
||||
>{{ connected ? $t('settings.parser.connected') : $t('settings.parser.disconnected') }}</t-tag>
|
||||
</div>
|
||||
<p>{{ $t('settings.parser.builtinDesc') }}</p>
|
||||
</div>
|
||||
<div class="docreader-inline">
|
||||
<div class="status-line">
|
||||
<t-tag
|
||||
:theme="connected ? 'success' : 'danger'"
|
||||
variant="light"
|
||||
size="small"
|
||||
>{{ connected ? $t('settings.parser.connected') : $t('settings.parser.disconnected') }}</t-tag>
|
||||
<t-tag theme="default" variant="light" size="small">{{ docreaderTransport === 'http' ? 'HTTP' : 'gRPC' }}</t-tag>
|
||||
<span v-if="docreaderAddrEnv" class="env-hint">{{ $t('settings.parser.currentAddr') }}: {{ docreaderAddrEnv }}</span>
|
||||
</div>
|
||||
<p class="docreader-desc">
|
||||
{{ $t('settings.parser.envVarHint') }}
|
||||
</p>
|
||||
<div
|
||||
v-if="!hasBuiltinEngine"
|
||||
:class="['engine-card', { active: drawerVisible && currentEngine?.Name === 'builtin' }]"
|
||||
@click="openDrawer({ Name: 'builtin' } as any)"
|
||||
>
|
||||
<div class="engine-card-header">
|
||||
<h3>builtin</h3>
|
||||
<t-tag
|
||||
:theme="connected ? 'success' : 'danger'"
|
||||
variant="light"
|
||||
size="small"
|
||||
>{{ connected ? $t('settings.parser.connected') : $t('settings.parser.disconnected') }}</t-tag>
|
||||
</div>
|
||||
<p class="engine-card-desc">{{ $t('settings.parser.builtinDesc') }}</p>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-for="(engine, idx) in sortedEngines"
|
||||
v-for="engine in sortedEngines"
|
||||
:key="engine.Name"
|
||||
:class="['engine-item', { first: idx === 0 && hasBuiltinEngine }]"
|
||||
:data-model-type="engine.Name"
|
||||
:class="['engine-card', { active: drawerVisible && currentEngine?.Name === engine.Name }]"
|
||||
@click="openDrawer(engine)"
|
||||
>
|
||||
<div class="engine-item-header">
|
||||
<div class="engine-title-row">
|
||||
<h3>{{ getEngineDisplayName(engine.Name) }}</h3>
|
||||
<t-tag v-if="engine.Available" theme="success" variant="light" size="small">{{ $t('settings.parser.available') }}</t-tag>
|
||||
<t-tooltip v-else-if="engine.UnavailableReason" :content="engine.UnavailableReason" placement="top">
|
||||
<t-tag theme="danger" variant="light" size="small" class="tag-with-tooltip">{{ $t('settings.parser.unavailable') }}</t-tag>
|
||||
</t-tooltip>
|
||||
<t-tag v-else theme="danger" variant="light" size="small">{{ $t('settings.parser.unavailable') }}</t-tag>
|
||||
<a
|
||||
v-if="engineDocLink(engine.Name)"
|
||||
:href="engineDocLink(engine.Name)"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="engine-doc-link"
|
||||
>{{ engineDocLabel(engine.Name) }} ↗</a>
|
||||
</div>
|
||||
<p>{{ getEngineDisplayDesc(engine.Name, engine.Description) }}</p>
|
||||
</div>
|
||||
|
||||
<!-- builtin: DocReader 连接信息 -->
|
||||
<div v-if="engine.Name === 'builtin'" class="docreader-inline">
|
||||
<div class="status-line">
|
||||
<t-tag v-if="connected" theme="success" variant="light" size="small">{{ $t('settings.parser.connected') }}</t-tag>
|
||||
<t-tag v-else theme="danger" variant="light" size="small">{{ $t('settings.parser.disconnected') }}</t-tag>
|
||||
<t-tag theme="default" variant="light" size="small">{{ docreaderTransport === 'http' ? 'HTTP' : 'gRPC' }}</t-tag>
|
||||
<span v-if="docreaderAddrEnv" class="env-hint">{{ $t('settings.parser.currentAddr') }}: {{ docreaderAddrEnv }}</span>
|
||||
</div>
|
||||
<p class="docreader-desc">
|
||||
{{ $t('settings.parser.envVarHint') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- weknoracloud: 凭证状态 -->
|
||||
<template v-if="engine.Name === 'weknoracloud'">
|
||||
<div v-if="wkcState === 'configured'" class="wkc-status wkc-status--ok">
|
||||
<t-icon name="check-circle" style="font-size: 15px; color: var(--td-success-color); flex-shrink: 0;" />
|
||||
<span>{{ $t('settings.weknoraCloud.credentialConfigured') }}</span>
|
||||
</div>
|
||||
<div v-else-if="wkcState === 'loading'" class="wkc-status">
|
||||
<t-loading size="small" />
|
||||
<span>{{ $t('settings.weknoraCloud.checkingStatus') }}</span>
|
||||
</div>
|
||||
<div v-else class="wkc-status wkc-status--warn">
|
||||
<t-icon name="error-circle" style="font-size: 15px; color: #f97316; flex-shrink: 0;" />
|
||||
<div style="flex: 1;">
|
||||
<span v-if="wkcState === 'expired'">{{ $t('settings.weknoraCloud.credentialExpired') }}</span>
|
||||
<span v-else>{{ $t('settings.weknoraCloud.unconfigured') }}</span>
|
||||
<div style="margin-top: 6px;">
|
||||
<t-button
|
||||
variant="text"
|
||||
size="small"
|
||||
theme="primary"
|
||||
@click="goToWkcSettings"
|
||||
style="padding: 0; height: auto;"
|
||||
>{{ $t('settings.weknoraCloud.goToSettings') }}</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div v-if="engine.FileTypes && engine.FileTypes.length" class="file-types">
|
||||
<t-tag
|
||||
v-for="ft in engine.FileTypes"
|
||||
:key="ft"
|
||||
size="small"
|
||||
variant="light"
|
||||
theme="default"
|
||||
>{{ ft }}</t-tag>
|
||||
</div>
|
||||
|
||||
<!-- mineru 自建配置 -->
|
||||
<div v-if="engine.Name === 'mineru'" class="engine-form">
|
||||
<div class="form-field">
|
||||
<label>{{ t('settings.parser.selfHostedEndpoint') }}</label>
|
||||
<t-input
|
||||
v-model="config.mineru_endpoint"
|
||||
:placeholder="$t('settings.parser.mineruEndpointPlaceholder')"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label>Backend</label>
|
||||
<t-select v-model="config.mineru_model" :placeholder="$t('settings.parser.defaultPipeline')" clearable>
|
||||
<t-option value="pipeline" label="pipeline" />
|
||||
<t-option value="vlm-auto-engine" label="vlm-auto-engine" />
|
||||
<t-option value="vlm-http-client" label="vlm-http-client" />
|
||||
<t-option value="hybrid-auto-engine" label="hybrid-auto-engine" />
|
||||
<t-option value="hybrid-http-client" label="hybrid-http-client" />
|
||||
</t-select>
|
||||
</div>
|
||||
<div class="form-toggles">
|
||||
<t-checkbox v-model="config.mineru_enable_formula">{{ $t('settings.parser.formulaRecognition') }}</t-checkbox>
|
||||
<t-checkbox v-model="config.mineru_enable_table">{{ $t('settings.parser.tableRecognition') }}</t-checkbox>
|
||||
<t-checkbox v-model="config.mineru_enable_ocr">OCR</t-checkbox>
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label>{{ t('settings.parser.language') }}</label>
|
||||
<t-input
|
||||
v-model="config.mineru_language"
|
||||
:placeholder="$t('settings.parser.languagePlaceholder')"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- mineru_cloud 云 API 配置 -->
|
||||
<div v-if="engine.Name === 'mineru_cloud'" class="engine-form">
|
||||
<div class="form-field">
|
||||
<label>API Key</label>
|
||||
<t-input
|
||||
v-model="config.mineru_api_key"
|
||||
type="password"
|
||||
:placeholder="$t('settings.parser.mineruCloudApiKeyPlaceholder')"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label>Model Version</label>
|
||||
<t-select v-model="config.mineru_cloud_model" :placeholder="$t('settings.parser.defaultPipeline')" clearable>
|
||||
<t-option value="pipeline" label="pipeline" />
|
||||
<t-option value="vlm" :label="$t('settings.parser.vlmLabel')" />
|
||||
<t-option value="MinerU-HTML" :label="$t('settings.parser.mineruHtmlLabel')" />
|
||||
</t-select>
|
||||
</div>
|
||||
<div class="form-toggles">
|
||||
<t-checkbox v-model="config.mineru_cloud_enable_formula">{{ $t('settings.parser.formulaRecognition') }}</t-checkbox>
|
||||
<t-checkbox v-model="config.mineru_cloud_enable_table">{{ $t('settings.parser.tableRecognition') }}</t-checkbox>
|
||||
<t-checkbox v-model="config.mineru_cloud_enable_ocr">OCR</t-checkbox>
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label>{{ t('settings.parser.language') }}</label>
|
||||
<t-input
|
||||
v-model="config.mineru_cloud_language"
|
||||
:placeholder="$t('settings.parser.languagePlaceholder')"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
<div class="engine-card-header">
|
||||
<h3>{{ getEngineDisplayName(engine.Name) }}</h3>
|
||||
<t-tag v-if="engine.Available" theme="success" variant="light" size="small">{{ $t('settings.parser.available') }}</t-tag>
|
||||
<t-tooltip v-else-if="engine.UnavailableReason" :content="engine.UnavailableReason" placement="top">
|
||||
<t-tag theme="danger" variant="light" size="small" class="tag-with-tooltip">{{ $t('settings.parser.unavailable') }}</t-tag>
|
||||
</t-tooltip>
|
||||
<t-tag v-else theme="danger" variant="light" size="small">{{ $t('settings.parser.unavailable') }}</t-tag>
|
||||
</div>
|
||||
<p class="engine-card-desc">{{ getEngineDisplayDesc(engine.Name, engine.Description) }}</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 检测与保存 -->
|
||||
<div class="save-bar">
|
||||
<t-button theme="default" variant="outline" :loading="checking" @click="onCheck">
|
||||
{{ $t('settings.parser.checkWithParams') }}
|
||||
</t-button>
|
||||
<t-button theme="primary" :loading="saving" @click="onSave">{{ $t('settings.parser.saveConfig') }}</t-button>
|
||||
<span v-if="checkMessage" class="save-msg hint">{{ checkMessage }}</span>
|
||||
<span v-else-if="saveMessage" :class="['save-msg', saveSuccess ? 'success' : 'error']">
|
||||
{{ saveMessage }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 配置抽屉 -->
|
||||
<t-drawer
|
||||
v-model:visible="drawerVisible"
|
||||
:header="drawerTitle"
|
||||
size="500px"
|
||||
>
|
||||
<div v-if="currentEngine" class="drawer-content">
|
||||
<div class="engine-info-block">
|
||||
<p class="engine-desc">{{ getEngineDisplayDesc(currentEngine.Name, currentEngine.Description) }}
|
||||
<a
|
||||
v-if="engineDocLink(currentEngine.Name)"
|
||||
:href="engineDocLink(currentEngine.Name)"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="engine-doc-link"
|
||||
>{{ engineDocLabel(currentEngine.Name) }} ↗</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- builtin: DocReader 连接信息 -->
|
||||
<div v-if="currentEngine.Name === 'builtin'" class="docreader-inline">
|
||||
<div class="status-line">
|
||||
<t-tag v-if="connected" theme="success" variant="light" size="small">{{ $t('settings.parser.connected') }}</t-tag>
|
||||
<t-tag v-else theme="danger" variant="light" size="small">{{ $t('settings.parser.disconnected') }}</t-tag>
|
||||
<t-tag theme="default" variant="light" size="small">{{ docreaderTransport === 'http' ? 'HTTP' : 'gRPC' }}</t-tag>
|
||||
<span v-if="docreaderAddrEnv" class="env-hint">{{ $t('settings.parser.currentAddr') }}: {{ docreaderAddrEnv }}</span>
|
||||
</div>
|
||||
<p class="docreader-desc">
|
||||
{{ $t('settings.parser.envVarHint') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- weknoracloud: 凭证状态 -->
|
||||
<template v-if="currentEngine.Name === 'weknoracloud'">
|
||||
<div v-if="wkcState === 'configured'" class="wkc-status wkc-status--ok">
|
||||
<t-icon name="check-circle" style="font-size: 15px; color: var(--td-success-color); flex-shrink: 0;" />
|
||||
<span>{{ $t('settings.weknoraCloud.credentialConfigured') }}</span>
|
||||
</div>
|
||||
<div v-else-if="wkcState === 'loading'" class="wkc-status">
|
||||
<t-loading size="small" />
|
||||
<span>{{ $t('settings.weknoraCloud.checkingStatus') }}</span>
|
||||
</div>
|
||||
<div v-else class="wkc-status wkc-status--warn">
|
||||
<t-icon name="error-circle" style="font-size: 15px; color: #f97316; flex-shrink: 0;" />
|
||||
<div style="flex: 1;">
|
||||
<span v-if="wkcState === 'expired'">{{ $t('settings.weknoraCloud.credentialExpired') }}</span>
|
||||
<span v-else>{{ $t('settings.weknoraCloud.unconfigured') }}</span>
|
||||
<div style="margin-top: 6px;">
|
||||
<t-button
|
||||
variant="text"
|
||||
size="small"
|
||||
theme="primary"
|
||||
@click="goToWkcSettings"
|
||||
style="padding: 0; height: auto;"
|
||||
>{{ $t('settings.weknoraCloud.goToSettings') }}</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div v-if="currentEngine.FileTypes && currentEngine.FileTypes.length" class="file-types">
|
||||
<t-tag
|
||||
v-for="ft in currentEngine.FileTypes"
|
||||
:key="ft"
|
||||
size="small"
|
||||
variant="light"
|
||||
theme="default"
|
||||
>{{ ft }}</t-tag>
|
||||
</div>
|
||||
|
||||
<!-- mineru 自建配置 -->
|
||||
<div v-if="currentEngine.Name === 'mineru'" class="engine-form">
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ t('settings.parser.selfHostedEndpoint') }}</label>
|
||||
<t-input
|
||||
v-model="config.mineru_endpoint"
|
||||
:placeholder="$t('settings.parser.mineruEndpointPlaceholder')"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<label class="form-label">Backend</label>
|
||||
<t-select v-model="config.mineru_model" :placeholder="$t('settings.parser.defaultPipeline')" clearable>
|
||||
<t-option value="pipeline" label="pipeline" />
|
||||
<t-option value="vlm-auto-engine" label="vlm-auto-engine" />
|
||||
<t-option value="vlm-http-client" label="vlm-http-client" />
|
||||
<t-option value="hybrid-auto-engine" label="hybrid-auto-engine" />
|
||||
<t-option value="hybrid-http-client" label="hybrid-http-client" />
|
||||
</t-select>
|
||||
</div>
|
||||
<div class="form-toggles">
|
||||
<t-checkbox v-model="config.mineru_enable_formula">{{ $t('settings.parser.formulaRecognition') }}</t-checkbox>
|
||||
<t-checkbox v-model="config.mineru_enable_table">{{ $t('settings.parser.tableRecognition') }}</t-checkbox>
|
||||
<t-checkbox v-model="config.mineru_enable_ocr">OCR</t-checkbox>
|
||||
</div>
|
||||
<div class="form-item" style="margin-top: 16px;">
|
||||
<label class="form-label">{{ t('settings.parser.language') }}</label>
|
||||
<t-input
|
||||
v-model="config.mineru_language"
|
||||
:placeholder="$t('settings.parser.languagePlaceholder')"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- mineru_cloud 云 API 配置 -->
|
||||
<div v-if="currentEngine.Name === 'mineru_cloud'" class="engine-form">
|
||||
<div class="form-item">
|
||||
<label class="form-label">API Key</label>
|
||||
<t-input
|
||||
v-model="config.mineru_api_key"
|
||||
type="password"
|
||||
:placeholder="$t('settings.parser.mineruCloudApiKeyPlaceholder')"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<label class="form-label">Model Version</label>
|
||||
<t-select v-model="config.mineru_cloud_model" :placeholder="$t('settings.parser.defaultPipeline')" clearable>
|
||||
<t-option value="pipeline" label="pipeline" />
|
||||
<t-option value="vlm" :label="$t('settings.parser.vlmLabel')" />
|
||||
<t-option value="MinerU-HTML" :label="$t('settings.parser.mineruHtmlLabel')" />
|
||||
</t-select>
|
||||
</div>
|
||||
<div class="form-toggles">
|
||||
<t-checkbox v-model="config.mineru_cloud_enable_formula">{{ $t('settings.parser.formulaRecognition') }}</t-checkbox>
|
||||
<t-checkbox v-model="config.mineru_cloud_enable_table">{{ $t('settings.parser.tableRecognition') }}</t-checkbox>
|
||||
<t-checkbox v-model="config.mineru_cloud_enable_ocr">OCR</t-checkbox>
|
||||
</div>
|
||||
<div class="form-item" style="margin-top: 16px;">
|
||||
<label class="form-label">{{ t('settings.parser.language') }}</label>
|
||||
<t-input
|
||||
v-model="config.mineru_cloud_language"
|
||||
:placeholder="$t('settings.parser.languagePlaceholder')"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-item" v-if="currentEngine && (hasConfigFields(currentEngine.Name) || currentEngine.Name === 'builtin')">
|
||||
<label class="form-label">{{ $t('settings.parser.testConnection', '测试连接') }}</label>
|
||||
<div class="api-test-section">
|
||||
<t-button variant="outline" :loading="checking" @click="onCheck">
|
||||
{{ $t('settings.parser.testConnection', '测试连接') }}
|
||||
</t-button>
|
||||
<span v-if="checkMessage || saveMessage" :class="['test-message', saveSuccess && !checkMessage ? 'success' : (checkMessage ? 'hint' : 'error')]">
|
||||
{{ checkMessage || saveMessage }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="drawer-footer-actions">
|
||||
<t-button theme="default" variant="outline" @click="drawerVisible = false">{{ $t('common.cancel') }}</t-button>
|
||||
<t-button theme="primary" :loading="saving" @click="onSave">{{ $t('common.save') }}</t-button>
|
||||
</div>
|
||||
</template>
|
||||
</t-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -278,6 +284,12 @@ const checkMessage = ref('')
|
||||
|
||||
const hasBuiltinEngine = computed(() => engines.value.some(e => e.Name === 'builtin'))
|
||||
|
||||
const drawerVisible = ref(false)
|
||||
const currentEngine = ref<ParserEngineInfo | null>(null)
|
||||
const drawerTitle = computed(() => {
|
||||
return currentEngine.value ? getEngineDisplayName(currentEngine.value.Name) : ''
|
||||
})
|
||||
|
||||
/** 固定展示顺序,未列出的引擎排在末尾按名称排序 */
|
||||
const ENGINE_ORDER: Record<string, number> = {
|
||||
builtin: 0,
|
||||
@@ -321,6 +333,13 @@ function getEngineDisplayDesc(engineName: string, fallback: string): string {
|
||||
return translated !== key ? translated : fallback
|
||||
}
|
||||
|
||||
function openDrawer(engine: ParserEngineInfo) {
|
||||
currentEngine.value = engine
|
||||
drawerVisible.value = true
|
||||
saveMessage.value = ''
|
||||
checkMessage.value = ''
|
||||
}
|
||||
|
||||
async function loadEngines() {
|
||||
try {
|
||||
const res = await getParserEngines()
|
||||
@@ -394,13 +413,47 @@ async function onCheck() {
|
||||
}
|
||||
checking.value = true
|
||||
checkMessage.value = ''
|
||||
saveMessage.value = ''
|
||||
try {
|
||||
const res = await checkParserEngines(buildConfigPayload())
|
||||
engines.value = res?.data ?? []
|
||||
checkMessage.value = t('settings.parser.checkDoneStatusUpdated')
|
||||
if (res?.connected !== undefined) {
|
||||
connected.value = res.connected
|
||||
}
|
||||
|
||||
if (currentEngine.value) {
|
||||
if (currentEngine.value.Name === 'builtin') {
|
||||
if (connected.value) {
|
||||
checkMessage.value = t('settings.parser.checkSuccess', '测试连接成功')
|
||||
saveSuccess.value = true
|
||||
} else {
|
||||
checkMessage.value = t('settings.parser.checkFailed', '测试连接失败')
|
||||
saveSuccess.value = false
|
||||
}
|
||||
} else {
|
||||
const updatedEngine = engines.value.find(e => e.Name === currentEngine.value!.Name)
|
||||
if (updatedEngine) {
|
||||
if (updatedEngine.Available) {
|
||||
checkMessage.value = t('settings.parser.checkSuccess', '测试连接成功')
|
||||
saveSuccess.value = true
|
||||
} else {
|
||||
checkMessage.value = updatedEngine.UnavailableReason || t('settings.parser.checkFailed', '测试连接失败')
|
||||
saveSuccess.value = false
|
||||
}
|
||||
} else {
|
||||
checkMessage.value = t('settings.parser.checkFailed', '引擎状态未知')
|
||||
saveSuccess.value = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
checkMessage.value = t('settings.parser.checkDoneStatusUpdated', '检测已完成,状态已更新')
|
||||
saveSuccess.value = true
|
||||
}
|
||||
|
||||
setTimeout(() => { checkMessage.value = '' }, 3000)
|
||||
} catch (e: any) {
|
||||
checkMessage.value = e?.message || t('settings.parser.checkFailed')
|
||||
checkMessage.value = e?.message || t('settings.parser.checkFailed', '测试连接失败')
|
||||
saveSuccess.value = false
|
||||
} finally {
|
||||
checking.value = false
|
||||
}
|
||||
@@ -413,6 +466,7 @@ async function onSave() {
|
||||
await updateParserEngineConfig(buildConfigPayload())
|
||||
saveSuccess.value = true
|
||||
saveMessage.value = t('settings.parser.saveSuccess')
|
||||
drawerVisible.value = false
|
||||
loadEngines()
|
||||
} catch (e: any) {
|
||||
saveSuccess.value = false
|
||||
@@ -500,34 +554,41 @@ onMounted(loadAll)
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 引擎条目 ----
|
||||
.engine-item {
|
||||
padding-top: 24px;
|
||||
// ---- 引擎卡片布局 ----
|
||||
.engine-cards {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
|
||||
gap: 16px;
|
||||
margin-top: 24px;
|
||||
border-top: 1px solid var(--td-component-stroke);
|
||||
}
|
||||
|
||||
&.first {
|
||||
margin-top: 0;
|
||||
padding-top: 0;
|
||||
border-top: none;
|
||||
.engine-card {
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
background: var(--td-bg-color-container);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--td-brand-color);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
&.active {
|
||||
border-color: var(--td-brand-color);
|
||||
background: rgba(var(--td-brand-color-5-rgba), 0.05);
|
||||
}
|
||||
}
|
||||
|
||||
.engine-item-header {
|
||||
margin-bottom: 16px;
|
||||
|
||||
p {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
margin: 6px 0 0 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.engine-title-row {
|
||||
.engine-card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
|
||||
h3 {
|
||||
font-size: 15px;
|
||||
@@ -535,30 +596,86 @@ onMounted(loadAll)
|
||||
color: var(--td-text-color-primary);
|
||||
margin: 0;
|
||||
font-family: 'SF Mono', 'Monaco', 'Menlo', monospace;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.engine-card-desc {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
// ---- 抽屉内容 ----
|
||||
.drawer-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.engine-info-block {
|
||||
.engine-desc {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin: 0 0 8px 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
// 输入框样式
|
||||
:deep(.t-input),
|
||||
:deep(.t-select) {
|
||||
width: 100%;
|
||||
font-size: 13px;
|
||||
|
||||
.t-input__inner,
|
||||
.t-input__wrap,
|
||||
input {
|
||||
font-size: 13px;
|
||||
border-radius: 6px;
|
||||
border-color: var(--td-component-stroke);
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
&:hover .t-input__inner,
|
||||
&:hover .t-input__wrap,
|
||||
&:hover input {
|
||||
border-color: var(--td-component-stroke);
|
||||
}
|
||||
|
||||
&.t-is-focused .t-input__inner,
|
||||
&.t-is-focused .t-input__wrap,
|
||||
&.t-is-focused input {
|
||||
border-color: var(--td-brand-color);
|
||||
box-shadow: 0 0 0 2px rgba(7, 192, 95, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
.engine-doc-link {
|
||||
margin-left: auto;
|
||||
font-size: 12px;
|
||||
font-size: 13px;
|
||||
color: var(--td-brand-color);
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.8;
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- DocReader 连接信息 ----
|
||||
.docreader-inline {
|
||||
padding: 10px 14px;
|
||||
padding: 12px 16px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-radius: 8px;
|
||||
margin-bottom: 12px;
|
||||
|
||||
.status-line {
|
||||
margin-bottom: 6px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,13 +684,6 @@ onMounted(loadAll)
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
line-height: 1.6;
|
||||
|
||||
code {
|
||||
padding: 1px 5px;
|
||||
font-size: 11px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-radius: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
.status-line {
|
||||
@@ -593,28 +703,35 @@ onMounted(loadAll)
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
// ---- 配置表单 ----
|
||||
.engine-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
margin-top: 16px;
|
||||
padding-top: 16px;
|
||||
border-top: 1px dashed var(--td-component-stroke);
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
.form-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
.form-item {
|
||||
margin-bottom: 20px;
|
||||
|
||||
label {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-secondary);
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.form-label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
|
||||
&.required::after {
|
||||
content: '*';
|
||||
color: var(--td-error-color);
|
||||
margin-left: 4px;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -622,35 +739,7 @@ onMounted(loadAll)
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
// ---- 保存栏(sticky) ----
|
||||
.save-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
position: sticky;
|
||||
bottom: 0;
|
||||
margin-top: 32px;
|
||||
padding: 16px 0 4px;
|
||||
background: linear-gradient(to bottom, transparent 0%, var(--td-bg-color-container) 12%);
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.save-msg {
|
||||
font-size: 13px;
|
||||
|
||||
&.success {
|
||||
color: var(--td-success-color);
|
||||
}
|
||||
|
||||
&.error {
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
|
||||
&.hint {
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.tag-with-tooltip {
|
||||
@@ -662,11 +751,10 @@ onMounted(loadAll)
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
padding: 10px 14px;
|
||||
padding: 12px 16px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin-bottom: 12px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
|
||||
&--ok {
|
||||
@@ -681,4 +769,76 @@ onMounted(loadAll)
|
||||
border-left: 3px solid #f97316;
|
||||
}
|
||||
}
|
||||
|
||||
.api-test-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
|
||||
.test-message {
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
flex: 1;
|
||||
|
||||
&.success {
|
||||
color: var(--td-brand-color-active);
|
||||
}
|
||||
|
||||
&.error {
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
|
||||
&.hint {
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.t-button) {
|
||||
min-width: 88px;
|
||||
height: 32px;
|
||||
font-size: 13px;
|
||||
border-radius: 6px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.status-icon {
|
||||
font-size: 16px;
|
||||
flex-shrink: 0;
|
||||
|
||||
&.available {
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
|
||||
&.unavailable {
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.drawer-footer-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
width: 100%;
|
||||
|
||||
:deep(.t-button) {
|
||||
min-width: 80px;
|
||||
height: 36px;
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
border-radius: 6px;
|
||||
transition: all 0.15s ease;
|
||||
|
||||
&.t-button--variant-outline {
|
||||
color: var(--td-text-color-secondary);
|
||||
border-color: var(--td-component-stroke);
|
||||
|
||||
&:hover {
|
||||
border-color: var(--td-brand-color);
|
||||
color: var(--td-brand-color);
|
||||
background: rgba(7, 192, 95, 0.04);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -117,6 +117,11 @@
|
||||
<ChatHistorySettings />
|
||||
</div>
|
||||
|
||||
<!-- 向量数据库引擎 -->
|
||||
<div v-if="currentSection === 'vectorstore'" class="section">
|
||||
<VectorStoreSettings />
|
||||
</div>
|
||||
|
||||
<!-- 解析引擎 -->
|
||||
<div v-if="currentSection === 'parser'" class="section">
|
||||
<ParserEngineSettings />
|
||||
@@ -169,6 +174,7 @@ import OllamaSettings from './OllamaSettings.vue'
|
||||
import McpSettings from './McpSettings.vue'
|
||||
import WebSearchSettings from './WebSearchSettings.vue'
|
||||
import ChatHistorySettings from './ChatHistorySettings.vue'
|
||||
import VectorStoreSettings from './VectorStoreSettings.vue'
|
||||
import ParserEngineSettings from './ParserEngineSettings.vue'
|
||||
import StorageEngineSettings from './StorageEngineSettings.vue'
|
||||
import WeKnoraCloudSettings from './WeKnoraCloudSettings.vue'
|
||||
@@ -186,45 +192,12 @@ const navItems = computed(() => [
|
||||
{ key: 'general', icon: 'setting', label: t('general.title') },
|
||||
{ key: 'ollama', icon: 'server', label: 'Ollama' },
|
||||
{ key: 'weknoracloud', icon: '', label: 'WeKnora Cloud' },
|
||||
{
|
||||
key: 'models',
|
||||
icon: 'control-platform',
|
||||
label: t('settings.modelManagement'),
|
||||
children: [
|
||||
{ key: 'chat', label: t('model.llmModel') },
|
||||
{ key: 'embedding', label: t('model.embeddingModel') },
|
||||
{ key: 'rerank', label: t('model.rerankModel') },
|
||||
{ key: 'vllm', label: t('model.vlmModel') }
|
||||
]
|
||||
},
|
||||
{ key: 'models', icon: 'control-platform', label: t('settings.modelManagement') },
|
||||
{ key: 'websearch', icon: 'search', label: t('settings.webSearchConfig') },
|
||||
{ key: 'chathistory', icon: 'chat', label: t('chatHistorySettings.title') },
|
||||
{
|
||||
key: 'parser',
|
||||
icon: 'file-search',
|
||||
label: t('settings.parserEngine'),
|
||||
children: [
|
||||
{ key: 'builtin', label: 'Builtin (DocReader)' },
|
||||
{ key: 'weknoracloud', label: 'WeKnora Cloud' },
|
||||
{ key: 'simple', label: 'Simple' },
|
||||
{ key: 'markitdown', label: 'Markitdown' },
|
||||
{ key: 'mineru', label: 'MinerU' },
|
||||
{ key: 'mineru_cloud', label: 'MinerU Cloud' },
|
||||
]
|
||||
},
|
||||
{
|
||||
key: 'storage',
|
||||
icon: 'cloud',
|
||||
label: t('settings.storageEngine'),
|
||||
children: [
|
||||
{ key: 'local', label: 'Local' },
|
||||
{ key: 'minio', label: 'MinIO' },
|
||||
{ key: 'cos', label: t('settings.storage.cos') },
|
||||
{ key: 'tos', label: t('settings.storage.tos') },
|
||||
{ key: 's3', label: 'AWS S3' },
|
||||
{ key: 'oss', label: t('settings.storage.oss') },
|
||||
]
|
||||
},
|
||||
{ key: 'vectorstore', icon: 'data-base', label: t('settings.vectorStoreEngine') },
|
||||
{ key: 'parser', icon: 'file-search', label: t('settings.parserEngine') },
|
||||
{ key: 'storage', icon: 'cloud', label: t('settings.storageEngine') },
|
||||
{ key: 'mcp', icon: 'tools', label: t('settings.mcpService') },
|
||||
{ key: 'system', icon: 'info-circle', label: t('settings.systemSettings') },
|
||||
{ key: 'tenant', icon: 'user-circle', label: t('settings.tenantInfo') },
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,812 @@
|
||||
<template>
|
||||
<div class="vectorstore-settings">
|
||||
<div class="section-header">
|
||||
<h2>{{ t('vectorStoreSettings.title') }}</h2>
|
||||
<p class="section-description">{{ t('vectorStoreSettings.description') }}</p>
|
||||
</div>
|
||||
|
||||
<!-- Loading -->
|
||||
<div v-if="loading" class="loading-container">
|
||||
<t-loading size="small" />
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div class="settings-group">
|
||||
<div class="section-subheader">
|
||||
<h3>{{ t('vectorStoreSettings.storesTitle') }}</h3>
|
||||
<t-button theme="primary" size="small" @click="openAddDialog">
|
||||
<template #icon><add-icon /></template>
|
||||
{{ t('vectorStoreSettings.addStore') }}
|
||||
</t-button>
|
||||
</div>
|
||||
|
||||
<!-- Store List -->
|
||||
<div v-if="stores.length > 0" class="store-list">
|
||||
<!-- Env Stores -->
|
||||
<div v-for="store in envStores" :key="store.id" class="store-item store-item--env">
|
||||
<div class="item-row">
|
||||
<div class="item-info">
|
||||
<div class="item-header">
|
||||
<t-icon name="lock-on" size="14px" />
|
||||
<span class="item-name">{{ store.name }}</span>
|
||||
<t-tag theme="warning" size="small" variant="light">{{ t('vectorStoreSettings.envTag') }}</t-tag>
|
||||
<t-tag size="small" variant="outline">{{ store.engine_type }}</t-tag>
|
||||
</div>
|
||||
</div>
|
||||
<div class="item-actions">
|
||||
<t-button
|
||||
theme="default" variant="outline" size="small"
|
||||
:loading="testingId === store.id"
|
||||
@click="testExisting(store)"
|
||||
>
|
||||
{{ t('vectorStoreSettings.testConnection') }}
|
||||
</t-button>
|
||||
<t-button theme="default" variant="text" size="small" shape="square" style="visibility: hidden;">
|
||||
<template #icon><t-icon name="more" /></template>
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="getTestResult(store)" :class="['test-result-bar', getTestResult(store)!.success ? 'success' : 'error']">
|
||||
<span class="test-result-message">{{ getTestResult(store)!.message }}</span>
|
||||
<t-icon name="close" size="14px" class="test-result-close" @click="clearTestResult(store)" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- User Stores -->
|
||||
<div v-for="store in userStores" :key="store.id" class="store-item">
|
||||
<div class="item-row">
|
||||
<div class="item-info">
|
||||
<div class="item-header">
|
||||
<span class="item-name">{{ store.name }}</span>
|
||||
<t-tag size="small" variant="outline">{{ store.engine_type }}</t-tag>
|
||||
</div>
|
||||
<div class="item-desc">{{ getStoreEndpoint(store) }}</div>
|
||||
</div>
|
||||
<div class="item-actions">
|
||||
<t-button
|
||||
theme="default" variant="outline" size="small"
|
||||
:loading="testingId === store.id"
|
||||
@click="testExisting(store)"
|
||||
>
|
||||
{{ t('vectorStoreSettings.testConnection') }}
|
||||
</t-button>
|
||||
<t-dropdown :options="storeActions" trigger="click" @click="(action: any) => handleAction(action, store)">
|
||||
<t-button theme="default" variant="text" size="small" shape="square">
|
||||
<template #icon><t-icon name="more" /></template>
|
||||
</t-button>
|
||||
</t-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="getTestResult(store)" :class="['test-result-bar', getTestResult(store)!.success ? 'success' : 'error']">
|
||||
<span class="test-result-message">{{ getTestResult(store)!.message }}</span>
|
||||
<t-icon name="close" size="14px" class="test-result-close" @click="clearTestResult(store)" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Empty State -->
|
||||
<div v-else class="empty-stores">
|
||||
<p>{{ t('vectorStoreSettings.emptyDesc') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Add/Edit Dialog -->
|
||||
<t-dialog
|
||||
v-model:visible="showDialog"
|
||||
:header="editingStore ? t('vectorStoreSettings.editStore') : t('vectorStoreSettings.addStore')"
|
||||
width="580px"
|
||||
placement="center"
|
||||
:footer="false"
|
||||
destroy-on-close
|
||||
>
|
||||
<div class="dialog-form-container">
|
||||
<!-- Edit Mode: immutable info banner + readonly fields -->
|
||||
<template v-if="editingStore">
|
||||
<div class="immutable-notice">
|
||||
<t-icon name="info-circle" size="14px" />
|
||||
<span>{{ t('vectorStoreSettings.immutableNotice') }}</span>
|
||||
</div>
|
||||
<div class="readonly-fields">
|
||||
<div class="readonly-row">
|
||||
<span class="readonly-label">{{ t('vectorStoreSettings.engineTypeLabel') }}</span>
|
||||
<span class="readonly-value">{{ selectedType?.display_name || editingStore.engine_type }}</span>
|
||||
</div>
|
||||
<template v-if="selectedType">
|
||||
<template v-for="field in selectedType.connection_fields" :key="field.name">
|
||||
<div v-if="field.sensitive || form.connection_config[field.name]" class="readonly-row">
|
||||
<span class="readonly-label">{{ fieldLabel(field.name) }}</span>
|
||||
<span class="readonly-value">{{ field.sensitive ? '********' : form.connection_config[field.name] }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
<template v-if="selectedType?.index_fields?.length">
|
||||
<template v-for="field in selectedType.index_fields" :key="field.name">
|
||||
<div v-if="form.index_config[field.name]" class="readonly-row">
|
||||
<span class="readonly-label">{{ fieldLabel(field.name) }}</span>
|
||||
<span class="readonly-value">{{ form.index_config[field.name] }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
</div>
|
||||
<div class="form-divider"></div>
|
||||
</template>
|
||||
|
||||
<t-form :data="form" :rules="formRules" label-align="top" @submit="saveStore" class="store-form">
|
||||
<div class="form-scroll-area">
|
||||
<!-- Create Mode: engine type + connection fields -->
|
||||
<template v-if="!editingStore">
|
||||
<t-form-item :label="t('vectorStoreSettings.engineTypeLabel')" name="engine_type">
|
||||
<t-select v-model="form.engine_type" @change="onEngineTypeChange">
|
||||
<t-option
|
||||
v-for="st in storeTypes"
|
||||
:key="st.type"
|
||||
:value="st.type"
|
||||
:label="st.display_name"
|
||||
/>
|
||||
</t-select>
|
||||
</t-form-item>
|
||||
</template>
|
||||
|
||||
<!-- Name (always editable) -->
|
||||
<t-form-item :label="t('vectorStoreSettings.nameLabel')" name="name">
|
||||
<t-input v-model="form.name" :placeholder="t('vectorStoreSettings.namePlaceholder')" />
|
||||
</t-form-item>
|
||||
|
||||
<!-- Create Mode: connection fields -->
|
||||
<template v-if="!editingStore && selectedType">
|
||||
<div class="form-divider"></div>
|
||||
<div class="form-section-label">{{ t('vectorStoreSettings.connectionInfo') }}</div>
|
||||
|
||||
<template v-for="field in selectedType.connection_fields" :key="field.name">
|
||||
<t-form-item
|
||||
:label="fieldLabel(field.name)"
|
||||
:name="`connection_config.${field.name}`"
|
||||
>
|
||||
<t-switch
|
||||
v-if="field.type === 'boolean'"
|
||||
v-model="form.connection_config[field.name]"
|
||||
/>
|
||||
<t-input
|
||||
v-else-if="field.type === 'string' && field.sensitive"
|
||||
v-model="form.connection_config[field.name]"
|
||||
type="password"
|
||||
placeholder="********"
|
||||
/>
|
||||
<t-input-number
|
||||
v-else-if="field.type === 'number'"
|
||||
v-model="form.connection_config[field.name]"
|
||||
:placeholder="field.default != null ? String(field.default) : ' '"
|
||||
theme="normal"
|
||||
style="width: 100%;"
|
||||
/>
|
||||
<t-input
|
||||
v-else
|
||||
v-model="form.connection_config[field.name]"
|
||||
:placeholder="field.default?.toString() || ''"
|
||||
/>
|
||||
</t-form-item>
|
||||
</template>
|
||||
|
||||
<!-- Advanced: index fields -->
|
||||
<template v-if="selectedType.index_fields?.length">
|
||||
<div class="form-divider"></div>
|
||||
<div class="advanced-toggle" @click="showAdvanced = !showAdvanced">
|
||||
<t-icon :name="showAdvanced ? 'chevron-down' : 'chevron-right'" size="14px" />
|
||||
<span>{{ t('vectorStoreSettings.advancedIndexConfig') }}</span>
|
||||
</div>
|
||||
|
||||
<template v-if="showAdvanced">
|
||||
<template v-for="field in selectedType.index_fields" :key="field.name">
|
||||
<t-form-item :label="fieldLabel(field.name)" :name="`index_config.${field.name}`">
|
||||
<t-input-number
|
||||
v-if="field.type === 'number'"
|
||||
v-model="form.index_config[field.name]"
|
||||
:placeholder="field.default?.toString()"
|
||||
:min="1"
|
||||
:max="isReplicaField(field.name) ? 10 : 64"
|
||||
theme="normal"
|
||||
style="width: 100%;"
|
||||
/>
|
||||
<t-input
|
||||
v-else
|
||||
v-model="form.index_config[field.name]"
|
||||
:placeholder="field.default?.toString() || ''"
|
||||
:maxlength="128"
|
||||
/>
|
||||
</t-form-item>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
</div><!-- /.form-scroll-area -->
|
||||
|
||||
<!-- Dialog Footer (outside scroll area) -->
|
||||
<div class="dialog-footer">
|
||||
<div class="footer-left">
|
||||
<t-button
|
||||
v-if="!editingStore"
|
||||
theme="default"
|
||||
variant="outline"
|
||||
:loading="testing"
|
||||
@click="testFromDialog"
|
||||
>
|
||||
{{ testing ? t('vectorStoreSettings.testing') : t('vectorStoreSettings.testConnection') }}
|
||||
</t-button>
|
||||
</div>
|
||||
<div class="footer-right">
|
||||
<t-button theme="default" variant="base" @click="showDialog = false">{{ t('common.cancel') }}</t-button>
|
||||
<t-button theme="primary" type="submit" :loading="saving">{{ t('common.save') }}</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</t-form>
|
||||
</div>
|
||||
</t-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { MessagePlugin, DialogPlugin } from 'tdesign-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { AddIcon } from 'tdesign-icons-vue-next'
|
||||
import {
|
||||
listVectorStores,
|
||||
listVectorStoreTypes,
|
||||
createVectorStore,
|
||||
updateVectorStore,
|
||||
deleteVectorStore as deleteVectorStoreAPI,
|
||||
testVectorStoreRaw,
|
||||
testVectorStoreById,
|
||||
type VectorStoreEntity,
|
||||
type VectorStoreTypeInfo,
|
||||
} from '@/api/vector-store'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
// ===== State =====
|
||||
const stores = ref<VectorStoreEntity[]>([])
|
||||
const storeTypes = ref<VectorStoreTypeInfo[]>([])
|
||||
const loading = ref(false)
|
||||
const showDialog = ref(false)
|
||||
const editingStore = ref<VectorStoreEntity | null>(null)
|
||||
const testing = ref(false)
|
||||
const testingId = ref<string | null>(null)
|
||||
const saving = ref(false)
|
||||
const showAdvanced = ref(false)
|
||||
const testResults = ref<Record<string, { success: boolean; message: string } | null>>({})
|
||||
|
||||
const form = ref<{
|
||||
name: string
|
||||
engine_type: string
|
||||
connection_config: Record<string, any>
|
||||
index_config: Record<string, any>
|
||||
}>({
|
||||
name: '',
|
||||
engine_type: '',
|
||||
connection_config: {},
|
||||
index_config: {},
|
||||
})
|
||||
|
||||
// ===== Computed =====
|
||||
const envStores = computed(() => stores.value.filter(s => s.source === 'env'))
|
||||
const userStores = computed(() => stores.value.filter(s => s.source === 'user'))
|
||||
const selectedType = computed(() => storeTypes.value.find(st => st.type === form.value.engine_type))
|
||||
|
||||
const storeActions = computed(() => [
|
||||
{ content: t('common.edit'), value: 'edit' },
|
||||
{ content: t('common.delete'), value: 'delete', theme: 'error' as const },
|
||||
])
|
||||
|
||||
const formRules = computed(() => {
|
||||
const rules: Record<string, any[]> = {
|
||||
name: [{ required: true, message: t('vectorStoreSettings.validation.nameRequired') }],
|
||||
}
|
||||
if (!editingStore.value) {
|
||||
rules.engine_type = [{ required: true, message: t('vectorStoreSettings.validation.engineTypeRequired') }]
|
||||
if (selectedType.value) {
|
||||
for (const field of selectedType.value.connection_fields) {
|
||||
if (field.required) {
|
||||
rules[`connection_config.${field.name}`] = [
|
||||
{ required: true, message: t('vectorStoreSettings.validation.fieldRequired', { field: fieldLabel(field.name) }) },
|
||||
]
|
||||
}
|
||||
}
|
||||
// Index name/collection string fields: pattern validation (optional — empty is allowed)
|
||||
for (const field of (selectedType.value.index_fields || [])) {
|
||||
if (field.type === 'string') {
|
||||
rules[`index_config.${field.name}`] = [
|
||||
{
|
||||
validator: (val: string) => !val || indexNamePattern.test(val),
|
||||
message: t('vectorStoreSettings.validation.indexNamePattern'),
|
||||
trigger: 'blur',
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rules
|
||||
})
|
||||
|
||||
// Index/collection name pattern: must start with letter, alphanumeric + _ + - only, max 128
|
||||
const indexNamePattern = /^[a-zA-Z][a-zA-Z0-9_-]{0,127}$/
|
||||
|
||||
// ===== Methods =====
|
||||
const fieldLabel = (name: string): string => {
|
||||
const key = `vectorStoreSettings.fields.${name}`
|
||||
const translated = t(key)
|
||||
// If i18n key not found, vue-i18n returns the key itself — fall back to field name
|
||||
return translated === key ? name : translated
|
||||
}
|
||||
|
||||
// Distinguish replica fields (max 10) from shard fields (max 64) for input bounds
|
||||
const replicaFieldNames = ['number_of_replicas', 'replication_factor', 'replica_number']
|
||||
const isReplicaField = (name: string): boolean => replicaFieldNames.includes(name)
|
||||
|
||||
const getTestResult = (store: VectorStoreEntity) => {
|
||||
return store.id ? testResults.value[store.id] ?? null : null
|
||||
}
|
||||
|
||||
const getStoreEndpoint = (store: VectorStoreEntity): string => {
|
||||
const cc = store.connection_config || {}
|
||||
return cc.addr || cc.host || ''
|
||||
}
|
||||
|
||||
const onEngineTypeChange = () => {
|
||||
form.value.connection_config = {}
|
||||
form.value.index_config = {}
|
||||
showAdvanced.value = false
|
||||
}
|
||||
|
||||
const loadStores = async () => {
|
||||
try {
|
||||
const response = await listVectorStores()
|
||||
if (response.data && Array.isArray(response.data)) {
|
||||
stores.value = response.data
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load vector stores:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const loadStoreTypes = async () => {
|
||||
try {
|
||||
storeTypes.value = await listVectorStoreTypes()
|
||||
} catch (error) {
|
||||
console.error('Failed to load vector store types:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const openAddDialog = () => {
|
||||
editingStore.value = null
|
||||
showAdvanced.value = false
|
||||
form.value = {
|
||||
name: '',
|
||||
engine_type: storeTypes.value[0]?.type || '',
|
||||
connection_config: {},
|
||||
index_config: {},
|
||||
}
|
||||
showDialog.value = true
|
||||
}
|
||||
|
||||
const editStore = (store: VectorStoreEntity) => {
|
||||
editingStore.value = store
|
||||
showAdvanced.value = false
|
||||
form.value = {
|
||||
name: store.name,
|
||||
engine_type: store.engine_type,
|
||||
connection_config: { ...store.connection_config },
|
||||
index_config: { ...store.index_config },
|
||||
}
|
||||
showDialog.value = true
|
||||
}
|
||||
|
||||
const saveStore = async ({ validateResult, firstError }: any) => {
|
||||
if (validateResult !== true && validateResult !== undefined) {
|
||||
MessagePlugin.warning(firstError || t('vectorStoreSettings.toasts.errorGeneric'))
|
||||
return
|
||||
}
|
||||
|
||||
saving.value = true
|
||||
try {
|
||||
if (editingStore.value) {
|
||||
await updateVectorStore(editingStore.value.id!, { name: form.value.name.trim() })
|
||||
MessagePlugin.success(t('vectorStoreSettings.toasts.storeUpdated'))
|
||||
} else {
|
||||
const data: Partial<VectorStoreEntity> = {
|
||||
name: form.value.name.trim(),
|
||||
engine_type: form.value.engine_type,
|
||||
connection_config: { ...form.value.connection_config },
|
||||
index_config: showAdvanced.value ? { ...form.value.index_config } : {},
|
||||
}
|
||||
await createVectorStore(data)
|
||||
MessagePlugin.success(t('vectorStoreSettings.toasts.storeCreated'))
|
||||
}
|
||||
showDialog.value = false
|
||||
await loadStores()
|
||||
} catch (error: any) {
|
||||
const msg = error?.message || t('vectorStoreSettings.toasts.errorGeneric')
|
||||
if (msg.toLowerCase().includes('already exists') || msg.toLowerCase().includes('duplicate')) {
|
||||
MessagePlugin.error(t('vectorStoreSettings.toasts.duplicateName'))
|
||||
} else {
|
||||
MessagePlugin.error(msg)
|
||||
}
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleAction = (action: { value: string }, store: VectorStoreEntity) => {
|
||||
if (action.value === 'edit') {
|
||||
editStore(store)
|
||||
} else if (action.value === 'delete') {
|
||||
confirmDelete(store)
|
||||
}
|
||||
}
|
||||
|
||||
const confirmDelete = (store: VectorStoreEntity) => {
|
||||
const dialog = DialogPlugin.confirm({
|
||||
header: t('vectorStoreSettings.deleteConfirm'),
|
||||
confirmBtn: t('common.delete'),
|
||||
cancelBtn: t('common.cancel'),
|
||||
theme: 'warning',
|
||||
onConfirm: async () => {
|
||||
try {
|
||||
await deleteVectorStoreAPI(store.id!)
|
||||
MessagePlugin.success(t('vectorStoreSettings.toasts.storeDeleted'))
|
||||
await loadStores()
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || t('vectorStoreSettings.toasts.errorGeneric'))
|
||||
}
|
||||
dialog.destroy()
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const clearTestResult = (store: VectorStoreEntity) => {
|
||||
if (store.id) {
|
||||
const { [store.id]: _, ...rest } = testResults.value
|
||||
testResults.value = rest
|
||||
}
|
||||
}
|
||||
|
||||
const testExisting = async (store: VectorStoreEntity) => {
|
||||
testingId.value = store.id!
|
||||
testResults.value = { ...testResults.value, [store.id!]: null }
|
||||
try {
|
||||
const res = await testVectorStoreById(store.id!)
|
||||
testResults.value = {
|
||||
...testResults.value,
|
||||
[store.id!]: {
|
||||
success: res.success,
|
||||
message: res.success
|
||||
? t('vectorStoreSettings.toasts.testSuccess')
|
||||
: (res.error || t('vectorStoreSettings.toasts.testFailed')),
|
||||
},
|
||||
}
|
||||
} catch (error: any) {
|
||||
testResults.value = {
|
||||
...testResults.value,
|
||||
[store.id!]: {
|
||||
success: false,
|
||||
message: error?.message || t('vectorStoreSettings.toasts.testFailed'),
|
||||
},
|
||||
}
|
||||
} finally {
|
||||
testingId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
const testFromDialog = async () => {
|
||||
testing.value = true
|
||||
try {
|
||||
const data = {
|
||||
engine_type: form.value.engine_type,
|
||||
connection_config: { ...form.value.connection_config },
|
||||
}
|
||||
const res = await testVectorStoreRaw(data)
|
||||
if (res.success) {
|
||||
MessagePlugin.success(t('vectorStoreSettings.toasts.testSuccess'))
|
||||
} else {
|
||||
MessagePlugin.error(res.error || t('vectorStoreSettings.toasts.testFailed'))
|
||||
}
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || t('vectorStoreSettings.toasts.testFailed'))
|
||||
} finally {
|
||||
testing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ===== Init =====
|
||||
onMounted(async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
await Promise.all([loadStoreTypes(), loadStores()])
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.vectorstore-settings {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 32px;
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
font-size: 14px;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.loading-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 48px 0;
|
||||
}
|
||||
|
||||
.settings-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.section-subheader {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 16px;
|
||||
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.store-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.store-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 14px 16px;
|
||||
background: var(--td-bg-color-container);
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: 8px;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--td-brand-color);
|
||||
}
|
||||
|
||||
&--env {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
|
||||
&:hover {
|
||||
border-color: var(--td-component-stroke);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.item-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.item-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.item-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.item-desc {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.item-actions {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
margin-left: 12px;
|
||||
}
|
||||
|
||||
.item-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.test-result-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
padding: 8px 12px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
line-height: 1.4;
|
||||
word-break: break-word;
|
||||
|
||||
&.success {
|
||||
background: rgba(7, 192, 95, 0.1);
|
||||
color: var(--td-success-color);
|
||||
}
|
||||
|
||||
&.error {
|
||||
background: var(--td-error-color-1, rgba(227, 77, 89, 0.1));
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
}
|
||||
|
||||
.test-result-message {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.test-result-close {
|
||||
flex-shrink: 0;
|
||||
margin-left: 8px;
|
||||
cursor: pointer;
|
||||
opacity: 0.6;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-stores {
|
||||
padding: 48px 32px;
|
||||
text-align: center;
|
||||
color: var(--td-text-color-placeholder);
|
||||
border: 1px dashed var(--td-component-stroke);
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
// Dialog
|
||||
.dialog-form-container {
|
||||
margin-top: 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-height: 70vh;
|
||||
}
|
||||
|
||||
.store-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.form-scroll-area {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding-right: 12px;
|
||||
}
|
||||
|
||||
.immutable-notice {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
padding: 10px 14px;
|
||||
margin-bottom: 16px;
|
||||
background: rgba(7, 192, 95, 0.1);
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
color: var(--td-brand-color);
|
||||
white-space: pre-line;
|
||||
}
|
||||
|
||||
.readonly-fields {
|
||||
padding: 10px 14px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-radius: 6px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.readonly-row {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 8px;
|
||||
padding: 3px 0;
|
||||
font-size: 12px;
|
||||
line-height: 1.4;
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.readonly-label {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: 11px;
|
||||
white-space: nowrap;
|
||||
min-width: 60px;
|
||||
}
|
||||
|
||||
.readonly-value {
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: 12px;
|
||||
font-family: 'SF Mono', Monaco, Menlo, monospace;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.form-divider {
|
||||
height: 1px;
|
||||
background: var(--td-component-border);
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.form-section-label {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.advanced-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary);
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
margin-bottom: 12px;
|
||||
|
||||
&:hover {
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 32px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid var(--td-component-border);
|
||||
|
||||
.footer-right {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -99,6 +99,16 @@
|
||||
</t-form-item>
|
||||
</template>
|
||||
|
||||
<t-form-item v-if="selectedProviderType?.supports_proxy" :label="t('webSearchSettings.proxyUrlLabel')" name="parameters.proxy_url">
|
||||
<t-input
|
||||
v-model="providerForm.parameters.proxy_url"
|
||||
:placeholder="t('webSearchSettings.proxyUrlPlaceholder')"
|
||||
/>
|
||||
<template #help>
|
||||
<span class="switch-help">{{ t('webSearchSettings.proxyUrlHelp') }}</span>
|
||||
</template>
|
||||
</t-form-item>
|
||||
|
||||
<div class="form-divider"></div>
|
||||
|
||||
<t-form-item :label="t('webSearchSettings.setAsDefault')" name="is_default">
|
||||
@@ -164,7 +174,7 @@ const providerForm = ref<{
|
||||
name: string
|
||||
provider: string
|
||||
description: string
|
||||
parameters: { api_key?: string; engine_id?: string }
|
||||
parameters: { api_key?: string; engine_id?: string; proxy_url?: string }
|
||||
is_default: boolean
|
||||
}>({
|
||||
name: '',
|
||||
@@ -228,6 +238,7 @@ const editProvider = (entity: WebSearchProviderEntity) => {
|
||||
parameters: {
|
||||
api_key: '',
|
||||
engine_id: entity.parameters?.engine_id || '',
|
||||
proxy_url: entity.parameters?.proxy_url || '',
|
||||
},
|
||||
is_default: entity.is_default || false,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user