fix(ui): refresh document summary state
parent
0766c5671f
commit
76b3256497
|
|
@ -11,7 +11,7 @@ import { onMounted, ref, nextTick, onUnmounted, watch, computed } from "vue";
|
|||
import {
|
||||
downKnowledgeDetails, deleteGeneratedQuestion, getChunkByIdOnly, previewKnowledgeFile,
|
||||
updateDocumentChunk, listChunkRevisions, revertDocumentChunk, updateKnowledgeMetadata,
|
||||
regenerateKnowledgeSummary, upsertGeneratedQuestion, regenerateGeneratedQuestions,
|
||||
regenerateKnowledgeSummary, upsertGeneratedQuestion, regenerateGeneratedQuestions, getKnowledgeDetails,
|
||||
} from "@/api/knowledge-base/index";
|
||||
import { MessagePlugin } from "tdesign-vue-next";
|
||||
import { sanitizeHTML, safeMarkdownToHTML, createSafeImage, isValidImageURL, hydrateProtectedFileImages, isValidURL } from '@/utils/security';
|
||||
|
|
@ -126,8 +126,7 @@ const saveMetadata = async () => {
|
|||
props.details.custom_metadata = value;
|
||||
metadataEditing.value = false;
|
||||
if (result?.data) {
|
||||
props.details.summary_status = result.data.summary_status || props.details.summary_status;
|
||||
props.details.description = result.data.description ?? props.details.description;
|
||||
applySummaryState(result.data.summary_status, result.data.description);
|
||||
}
|
||||
MessagePlugin.success(t('common.saveSuccess'));
|
||||
} catch (error: any) {
|
||||
|
|
@ -142,8 +141,7 @@ const refreshSummary = async () => {
|
|||
try {
|
||||
const result: any = await regenerateKnowledgeSummary(props.details.id);
|
||||
if (result?.data) {
|
||||
props.details.description = result.data.description || '';
|
||||
props.details.summary_status = result.data.summary_status || 'completed';
|
||||
applySummaryState(result.data.summary_status || 'completed', result.data.description || '');
|
||||
}
|
||||
MessagePlugin.success(t('knowledgeBase.summaryRefreshed'));
|
||||
} catch (error: any) {
|
||||
|
|
@ -208,7 +206,73 @@ mermaid.initialize({
|
|||
}
|
||||
});
|
||||
const props = defineProps(["visible", "details", "knowledgeType", "sourceInfo", "canEditKB", "canDownloadKB", "parse_status", "kbId"]);
|
||||
const emit = defineEmits(["closeDoc", "getDoc", "questionDeleted"]);
|
||||
const emit = defineEmits(["closeDoc", "getDoc", "questionDeleted", "summaryStateChange"]);
|
||||
|
||||
const applySummaryState = (summaryStatus?: string, description?: string) => {
|
||||
if (typeof summaryStatus === 'string' && summaryStatus) {
|
||||
props.details.summary_status = summaryStatus;
|
||||
}
|
||||
if (typeof description === 'string') {
|
||||
props.details.description = description;
|
||||
}
|
||||
if (props.details?.id) {
|
||||
emit('summaryStateChange', {
|
||||
id: props.details.id,
|
||||
summary_status: props.details.summary_status,
|
||||
description: props.details.description,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const isSummaryStatusInFlight = (status?: string) => status === 'pending' || status === 'processing';
|
||||
const summaryStatusRefreshing = computed(() => isSummaryStatusInFlight(props.details?.summary_status));
|
||||
let summaryStatusPollTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
let summaryStatusPollGeneration = 0;
|
||||
|
||||
const stopSummaryStatusPolling = () => {
|
||||
summaryStatusPollGeneration++;
|
||||
if (summaryStatusPollTimer !== null) {
|
||||
clearTimeout(summaryStatusPollTimer);
|
||||
summaryStatusPollTimer = null;
|
||||
}
|
||||
};
|
||||
|
||||
const scheduleSummaryStatusPoll = () => {
|
||||
if (summaryStatusPollTimer !== null || !props.visible || !props.details?.id ||
|
||||
!isSummaryStatusInFlight(props.details?.summary_status)) return;
|
||||
|
||||
const knowledgeID = props.details.id;
|
||||
const generation = summaryStatusPollGeneration;
|
||||
summaryStatusPollTimer = setTimeout(async () => {
|
||||
summaryStatusPollTimer = null;
|
||||
if (generation !== summaryStatusPollGeneration || !props.visible || props.details?.id !== knowledgeID) return;
|
||||
try {
|
||||
const result: any = await getKnowledgeDetails(knowledgeID);
|
||||
if (generation !== summaryStatusPollGeneration || props.details?.id !== knowledgeID) return;
|
||||
if (result?.success && result.data) {
|
||||
applySummaryState(result.data.summary_status, result.data.description);
|
||||
}
|
||||
} catch {
|
||||
// Keep the current status visible and retry while the drawer remains open.
|
||||
}
|
||||
if (generation === summaryStatusPollGeneration && props.visible && props.details?.id === knowledgeID &&
|
||||
isSummaryStatusInFlight(props.details?.summary_status)) {
|
||||
scheduleSummaryStatusPoll();
|
||||
}
|
||||
}, 1500);
|
||||
};
|
||||
|
||||
watch(
|
||||
() => [props.visible, props.details?.id, props.details?.summary_status],
|
||||
([visible, knowledgeID, summaryStatus]) => {
|
||||
if (visible && knowledgeID && isSummaryStatusInFlight(summaryStatus as string)) {
|
||||
scheduleSummaryStatusPoll();
|
||||
} else {
|
||||
stopSummaryStatusPolling();
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
watch(() => props.details?.id, syncMetadataDraft, { immediate: true });
|
||||
|
||||
const hasTimelineSpans = ref(false);
|
||||
|
|
@ -578,6 +642,7 @@ watch(() => props.details?.chunkLoading, (val) => {
|
|||
}
|
||||
});
|
||||
onUnmounted(() => {
|
||||
stopSummaryStatusPolling();
|
||||
window.removeEventListener('resize', onTraceDrawerWindowResize);
|
||||
cleanupTraceDrawerResize();
|
||||
cleanupMainDrawerResize();
|
||||
|
|
@ -1043,8 +1108,7 @@ const saveChunkEdit = async (item: any) => {
|
|||
});
|
||||
Object.assign(item, result.data);
|
||||
editingChunkId.value = '';
|
||||
props.details.summary_status = result.summary_status || props.details.summary_status;
|
||||
props.details.description = result.description ?? props.details.description;
|
||||
applySummaryState(result.summary_status, result.description);
|
||||
void refreshChunkHistoryAfterMutation(item);
|
||||
MessagePlugin.success(t('common.saveSuccess'));
|
||||
} catch (error: any) {
|
||||
|
|
@ -1062,8 +1126,7 @@ const toggleChunkEnabled = async (item: any, isEnabled: boolean) => {
|
|||
expected_revision: item.content_revision || 0,
|
||||
});
|
||||
Object.assign(item, result.data);
|
||||
props.details.summary_status = result.summary_status || props.details.summary_status;
|
||||
props.details.description = result.description ?? props.details.description;
|
||||
applySummaryState(result.summary_status, result.description);
|
||||
void refreshChunkHistoryAfterMutation(item);
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || t('common.error'));
|
||||
|
|
@ -1187,8 +1250,7 @@ const revertChunk = async (item: any, revision: number) => {
|
|||
try {
|
||||
const result: any = await revertDocumentChunk(props.details.id, item.id, revision, item.content_revision || 0);
|
||||
Object.assign(item, result.data);
|
||||
props.details.summary_status = result.summary_status || props.details.summary_status;
|
||||
props.details.description = result.description ?? props.details.description;
|
||||
applySummaryState(result.summary_status, result.description);
|
||||
await refreshChunkHistoryAfterMutation(item);
|
||||
MessagePlugin.success(t('knowledgeBase.chunkReverted'));
|
||||
} catch (error: any) {
|
||||
|
|
@ -1660,7 +1722,13 @@ const handleDetailsScroll = () => {
|
|||
|
||||
<section v-if="showSummarySection" class="setting-drawer__section summary-section">
|
||||
<div class="section-title-actions">
|
||||
<h4 class="setting-drawer__section-title">{{ $t('knowledgeBase.documentSummary') }}</h4>
|
||||
<div class="summary-section-heading">
|
||||
<h4 class="setting-drawer__section-title">{{ $t('knowledgeBase.documentSummary') }}</h4>
|
||||
<span v-if="details.description && summaryStatusRefreshing" class="summary-refreshing-indicator">
|
||||
<t-loading size="small" />
|
||||
<span>{{ $t('knowledgeBase.generatingSummary') }}</span>
|
||||
</span>
|
||||
</div>
|
||||
<t-tooltip v-if="canEditContent" :content="$t('knowledgeBase.regenerateSummary')" placement="top">
|
||||
<t-button class="icon-action-btn" size="small" variant="text" shape="square"
|
||||
:loading="summaryRefreshing" @click="refreshSummary">
|
||||
|
|
@ -2220,6 +2288,24 @@ const handleDetailsScroll = () => {
|
|||
min-width: 0;
|
||||
}
|
||||
|
||||
.summary-section-heading,
|
||||
.summary-refreshing-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.summary-section-heading {
|
||||
min-width: 0;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.summary-refreshing-indicator {
|
||||
gap: 5px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: 11px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.metadata-grid {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
|
|
|||
|
|
@ -530,7 +530,7 @@ export default {
|
|||
confirmDeleteQuestion: 'Are you sure you want to delete this question? The corresponding vector index will also be removed.',
|
||||
legacyQuestionCannotDelete: 'Legacy format questions cannot be deleted. Please regenerate questions.',
|
||||
customMetadata: 'Custom metadata',
|
||||
metadataCapabilityHint: 'Used to support indexing and retrieval, document summaries, knowledge-base answers, and agent search',
|
||||
metadataCapabilityHint: 'Used for document summaries and as document-level context after retrieval; it is not indexed and does not affect retrieval ranking',
|
||||
noCustomMetadata: 'No custom metadata',
|
||||
metadataObjectRequired: 'Metadata must be a JSON object',
|
||||
addMetadataField: 'Add metadata field',
|
||||
|
|
|
|||
|
|
@ -540,7 +540,7 @@ export default {
|
|||
"이 질문을 삭제하시겠습니까? 삭제 시 해당 벡터 인덱스도 함께 제거됩니다.",
|
||||
legacyQuestionCannotDelete: "이전 형식의 질문은 삭제할 수 없습니다. 질문을 다시 생성하세요",
|
||||
customMetadata: "사용자 정의 메타데이터",
|
||||
metadataCapabilityHint: "인덱싱 및 검색, 문서 요약, 지식베이스 답변, 에이전트 검색을 지원하는 데 사용됩니다",
|
||||
metadataCapabilityHint: "문서 요약과 검색 후 문서 수준 답변 컨텍스트에 사용됩니다. 인덱스에 포함되지 않으며 검색 순위에 영향을 주지 않습니다",
|
||||
noCustomMetadata: "사용자 정의 메타데이터 없음",
|
||||
metadataObjectRequired: "메타데이터는 JSON 객체여야 합니다",
|
||||
addMetadataField: "메타데이터 필드 추가",
|
||||
|
|
|
|||
|
|
@ -465,7 +465,7 @@ export default {
|
|||
confirmDeleteQuestion: 'Вы уверены, что хотите удалить этот вопрос? Соответствующий векторный индекс также будет удален.',
|
||||
legacyQuestionCannotDelete: 'Вопросы в устаревшем формате нельзя удалить. Пожалуйста, сгенерируйте вопросы заново.',
|
||||
customMetadata: 'Пользовательские метаданные',
|
||||
metadataCapabilityHint: 'Используются для индексации и поиска, сводок, ответов по базе знаний и поиска агента',
|
||||
metadataCapabilityHint: 'Используются для сводок и как контекст документа после поиска; не индексируются и не влияют на ранжирование',
|
||||
noCustomMetadata: 'Нет пользовательских метаданных',
|
||||
metadataObjectRequired: 'Метаданные должны быть JSON-объектом',
|
||||
addMetadataField: 'Добавить поле метаданных',
|
||||
|
|
|
|||
|
|
@ -529,7 +529,7 @@ export default {
|
|||
confirmDeleteQuestion: "确定要删除这个问题吗?删除后将同时移除对应的向量索引。",
|
||||
legacyQuestionCannotDelete: "旧格式问题无法删除,请重新生成问题",
|
||||
customMetadata: "自定义元数据",
|
||||
metadataCapabilityHint: "用于辅助索引召回、文档总结、知识库问答和智能体检索",
|
||||
metadataCapabilityHint: "用于文档总结,并在文档被召回后作为文档级上下文辅助回答;不会参与索引或影响召回排序",
|
||||
noCustomMetadata: "暂无自定义元数据",
|
||||
metadataObjectRequired: "元数据必须是 JSON 对象",
|
||||
addMetadataField: "添加元数据字段",
|
||||
|
|
|
|||
|
|
@ -1752,6 +1752,18 @@ const getDoc = (page: number) => {
|
|||
getfDetails(details.id, page)
|
||||
};
|
||||
|
||||
const syncDocumentSummaryState = (state: { id?: string; summary_status?: string; description?: string }) => {
|
||||
if (!state?.id) return;
|
||||
const card = cardList.value.find((item: KnowledgeCard) => item.id === state.id);
|
||||
if (!card) return;
|
||||
if (typeof state.summary_status === 'string' && state.summary_status) {
|
||||
card.summary_status = state.summary_status;
|
||||
}
|
||||
if (typeof state.description === 'string') {
|
||||
card.description = state.description;
|
||||
}
|
||||
};
|
||||
|
||||
const toggleSelectRow = (id: string, checked: boolean, shiftKey?: boolean) => {
|
||||
const items = cardList.value || [];
|
||||
const idx = items.findIndex((i: KnowledgeCard) => i.id === id);
|
||||
|
|
@ -2336,7 +2348,7 @@ async function createNewSession(value: string): Promise<void> {
|
|||
<!-- DocContent drawer (shared by documents tab and wiki source refs) -->
|
||||
<DocContent ref="docContentRef" :visible="isCardDetails" :details="details" :canEditKB="canEdit"
|
||||
:canDownloadKB="canDownloadKnowledge" :kbId="kbId"
|
||||
@closeDoc="closeDoc" @getDoc="getDoc">
|
||||
@closeDoc="closeDoc" @getDoc="getDoc" @summaryStateChange="syncDocumentSummaryState">
|
||||
</DocContent>
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
|||
Loading…
Reference in New Issue