feat(knowledge): instrument postprocess subspans + polish timeline UI

Backend: summary, question, and graph-extract async tasks now record
real processing time as subspans hanging off the (closed) postprocess
stage, so the trace viewer no longer caps the postprocess row at the
~10 ms enqueue duration. Carries Attempt through SummaryGeneration /
QuestionGeneration / ExtractChunk payloads so cross-process workers
can resolve the right parent attempt.

Frontend: drawer now uses attach="body" so the secondary 820px detail
drawer escapes the 654px container of the main drawer; timeline
timestamps include date prefix (MM-DD, or YYYY-MM-DD across years);
"updated X ago" caption only shows during live polling.

Tests: 4 new cases covering postprocess subspan attaching under a
closed parent, missing-parent fallthrough, and Attempt JSON round-trip
on the three task payloads.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
wizardchen
2026-05-27 21:33:16 +08:00
committed by lyingbug
parent 5ffc755e76
commit bd029b6d19
11 changed files with 2415 additions and 537 deletions
+429 -17
View File
@@ -64,6 +64,35 @@ mermaid.initialize({
const props = defineProps(["visible", "details", "knowledgeType", "sourceInfo", "canEditKB", "parse_status"]);
const emit = defineEmits(["closeDoc", "getDoc", "questionDeleted"]);
const hasTimelineSpans = ref(false);
const timelineDrawerVisible = ref(false);
const timelineSummary = ref<{ totalMs: number; status: string; stageIndex: number; stageTotal: number; stageLabel: string }>({
totalMs: 0, status: '', stageIndex: 0, stageTotal: 0, stageLabel: '',
});
watch(() => props.details?.id, () => {
hasTimelineSpans.value = false;
timelineDrawerVisible.value = false;
timelineSummary.value = { totalMs: 0, status: '', stageIndex: 0, stageTotal: 0, stageLabel: '' };
});
function formatTimelineDuration(ms: number): string {
if (!ms || ms < 0) return '—';
if (ms < 1000) return `${Math.round(ms)}ms`;
if (ms < 60000) return `${(ms / 1000).toFixed(2)}s`;
const mins = Math.floor(ms / 60000);
const rem = ((ms % 60000) / 1000).toFixed(1);
return `${mins}m${rem}s`;
}
function openTimeline() {
timelineDrawerVisible.value = true;
}
function closeTimeline() {
timelineDrawerVisible.value = false;
}
marked.use({
breaks: true, // 启用单行换行转 <br>
gfm: true, // 启用 GitHub Flavored Markdown
@@ -778,7 +807,7 @@ const handleDetailsScroll = () => {
</script>
<template>
<div class="doc_content" ref="mdContentWrap">
<t-drawer :visible="visible" :zIndex="2000" :closeBtn="true" :footer="false" @close="handleClose">
<t-drawer :visible="visible" :zIndex="2000" size="654px" attach="body" :closeBtn="true" :footer="false" @close="handleClose">
<template #header>
<div class="drawer-header">
<span class="header-title">{{ getDisplayTitle() }}</span>
@@ -788,17 +817,94 @@ const handleDetailsScroll = () => {
</div>
</template>
<!-- 解析阶段时间线(仅在解析中/失败时显示) -->
<div
v-if="details.id"
class="parse_timeline_box"
<!-- 解析阶段时间线 trigger(点击打开二级抽屉) -->
<button
v-if="details.id && hasTimelineSpans"
type="button"
class="kp-trigger"
:class="['kp-trigger-' + (timelineSummary.status || 'unknown')]"
@click="openTimeline"
>
<span class="kp-trigger-status">
<span class="kp-trigger-dot" :class="['kp-trigger-dot-' + (timelineSummary.status || 'unknown')]" />
<span class="kp-trigger-label">{{ $t('knowledgeStages.title') }}</span>
</span>
<span class="kp-trigger-divider" />
<span class="kp-trigger-meta">
<template v-if="timelineSummary.totalMs > 0">
<span class="kp-trigger-meta-key">{{ $t('knowledgeStages.head.duration') }}</span>
<span class="kp-trigger-meta-val kp-trigger-mono">{{ formatTimelineDuration(timelineSummary.totalMs) }}</span>
</template>
<template v-else-if="timelineSummary.stageTotal > 0">
<span class="kp-trigger-meta-key">{{ $t('knowledgeStages.head.stage') }}</span>
<span class="kp-trigger-meta-val kp-trigger-mono">
{{ timelineSummary.stageIndex }}/{{ timelineSummary.stageTotal }}
</span>
<span class="kp-trigger-meta-key kp-trigger-meta-stage">· {{ timelineSummary.stageLabel }}</span>
</template>
</span>
<span class="kp-trigger-tail">
<span
v-if="timelineSummary.status === 'running' || timelineSummary.status === 'processing' || timelineSummary.status === 'pending'"
class="kp-trigger-live"
>
<span class="kp-trigger-live-dot" />
<span class="kp-trigger-live-text">LIVE</span>
</span>
<span class="kp-trigger-cta">{{ $t('knowledgeStages.viewTrace') }}</span>
<t-icon name="chevron-right" size="14px" class="kp-trigger-arrow" />
</span>
</button>
<!-- Hidden mount: keeps the timeline fetching data so trigger summary
stays live even before the user opens the secondary drawer. The
drawer itself shows a separate, fully-interactive instance. -->
<div class="kp-trigger-shadow" aria-hidden="true">
<KnowledgeProcessingTimeline
v-if="details.id"
:knowledge-id="details.id"
:parse-status="details.parse_status"
:compact="true"
@update:has-spans="hasTimelineSpans = $event"
@update:summary="timelineSummary = $event"
/>
</div>
<!-- 二级抽屉:完整 Langfuse-style waterfall -->
<t-drawer
:visible="timelineDrawerVisible"
:zIndex="2100"
size="820px"
attach="body"
:closeBtn="false"
:footer="false"
:header="false"
:showOverlay="true"
:closeOnOverlayClick="true"
placement="right"
class="kp-secondary-drawer"
@close="closeTimeline"
>
<div class="kp-drawer-shell">
<div class="kp-drawer-titlebar">
<div class="kp-drawer-titlebar-left">
<span class="kp-drawer-titlebar-kind">trace</span>
<span class="kp-drawer-titlebar-title">{{ $t('knowledgeStages.title') }}</span>
</div>
<button type="button" class="kp-drawer-titlebar-close" @click="closeTimeline" :aria-label="$t('knowledgeStages.close')">
<t-icon name="close" size="16px" />
</button>
</div>
<div class="kp-drawer-body">
<KnowledgeProcessingTimeline
v-if="details.id && timelineDrawerVisible"
:knowledge-id="details.id"
:parse-status="details.parse_status"
/>
</div>
</div>
</t-drawer>
<!-- 文件类型专属区域 -->
<div v-if="details.type === 'file'" class="doc_box">
<a :href="url" style="display: none" ref="down" :download="details.title"></a>
@@ -1015,18 +1121,12 @@ const handleDetailsScroll = () => {
<style scoped lang="less">
@import "./css/markdown.less";
:deep(.t-drawer .t-drawer__content-wrapper) {
width: min(654px, 85vw) !important; // 减少到85%视口宽度,给左侧留更多空间
max-width: 654px !important;
}
// 在小屏幕上进一步调整
@media (max-width: 768px) {
:deep(.t-drawer .t-drawer__content-wrapper) {
width: 90vw !important; // 小屏幕上使用90%宽度
max-width: none !important;
}
}
/* Drawer widths are now driven by the `:size` prop on each <t-drawer>
(see mainDrawerSize / timelineDrawerSize in <script>). CSS rules with
!important were removed because they fought each other across the
scoped/non-scoped boundary and had no clean specificity ordering in
dev mode (Vite injects scoped <style> tags later than non-scoped,
inverting prod). Inline width via the prop is unambiguous. */
// 代码块样式
:deep(.code-block-wrapper) {
@@ -1108,6 +1208,301 @@ const handleDetailsScroll = () => {
border-radius: 6px;
}
/* ============== Timeline trigger pill ==============
Designed to read like an information row in the doc drawer, not a
loud CTA. Soft 6px corners, neutral border, left strip carries the
status color so the pipeline state is glanceable without dominating
the layout. Mirrors the KBInfoPopover/manual-knowledge-editor card
feel that the rest of the app uses. */
.kp-trigger {
margin: 8px 0 16px;
width: 100%;
display: flex;
align-items: center;
gap: 12px;
padding: 10px 14px;
border: 1px solid var(--td-component-stroke);
border-radius: var(--td-radius-medium);
background: var(--td-bg-color-container);
color: var(--td-text-color-primary);
cursor: pointer;
font-family: var(--app-font-family);
text-align: left;
position: relative;
overflow: hidden;
transition: border-color 150ms ease, background 150ms ease, transform 100ms ease;
}
.kp-trigger::before {
content: "";
position: absolute;
left: 0;
top: 8px;
bottom: 8px;
width: 3px;
border-radius: 0 2px 2px 0;
background: var(--td-component-border);
transition: background 150ms ease;
}
.kp-trigger:hover {
background: var(--td-bg-color-secondarycontainer);
border-color: var(--td-component-border);
}
.kp-trigger:active { transform: translateY(1px); }
.kp-trigger-done::before,
.kp-trigger-completed::before { background: var(--td-success-color); }
.kp-trigger-failed::before { background: var(--td-error-color); }
.kp-trigger-running::before,
.kp-trigger-processing::before,
.kp-trigger-pending::before { background: var(--td-brand-color); }
.kp-trigger-unknown::before { background: var(--td-component-border); }
.kp-trigger-status {
display: inline-flex;
align-items: center;
gap: 8px;
flex-shrink: 0;
}
.kp-trigger-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--td-text-color-placeholder);
flex-shrink: 0;
}
.kp-trigger-dot-done,
.kp-trigger-dot-completed { background: var(--td-success-color); }
.kp-trigger-dot-failed { background: var(--td-error-color); }
.kp-trigger-dot-running,
.kp-trigger-dot-processing,
.kp-trigger-dot-pending {
background: var(--td-brand-color);
animation: kpTriggerPulse 1.6s ease-in-out infinite;
}
.kp-trigger-dot-unknown { background: var(--td-text-color-placeholder); }
@keyframes kpTriggerPulse {
0%, 100% { box-shadow: 0 0 0 0 var(--td-brand-color-light); }
50% { box-shadow: 0 0 0 4px transparent; }
}
.kp-trigger-label {
font-size: 13px;
font-weight: 600;
color: var(--td-text-color-primary);
}
.kp-trigger-divider {
width: 1px;
height: 14px;
background: var(--td-component-stroke);
flex-shrink: 0;
}
.kp-trigger-meta {
display: inline-flex;
align-items: baseline;
gap: 6px;
flex: 1;
min-width: 0;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.kp-trigger-meta-key {
color: var(--td-text-color-placeholder);
font-size: 11px;
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.kp-trigger-meta-stage {
text-transform: none;
letter-spacing: 0;
font-weight: 400;
color: var(--td-text-color-secondary);
margin-left: 2px;
}
.kp-trigger-meta-val {
color: var(--td-text-color-primary);
font-size: 12px;
font-weight: 500;
}
.kp-trigger-mono {
font-family: var(--app-font-family-mono);
font-size: 12px;
letter-spacing: 0;
}
.kp-trigger-tail {
display: inline-flex;
align-items: center;
gap: 8px;
flex-shrink: 0;
}
/* LIVE badge — pulses while the parser is mid-run, so the user knows
opening the trace will show fresh data. */
.kp-trigger-live {
display: inline-flex;
align-items: center;
gap: 4px;
padding: 2px 7px;
background: var(--td-brand-color-light);
color: var(--td-brand-color);
border-radius: var(--td-radius-default);
font-size: 10px;
font-weight: 600;
letter-spacing: 0.06em;
line-height: 1;
}
.kp-trigger-live-dot {
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--td-brand-color);
animation: kpTriggerLivePulse 1.4s ease-in-out infinite;
}
.kp-trigger-live-text {
font-family: var(--app-font-family-mono);
}
@keyframes kpTriggerLivePulse {
0%, 100% { opacity: 1; transform: scale(1); }
50% { opacity: 0.4; transform: scale(0.8); }
}
.kp-trigger-cta {
font-size: 12px;
color: var(--td-text-color-secondary);
}
.kp-trigger:hover .kp-trigger-cta {
color: var(--td-brand-color);
}
.kp-trigger-arrow {
color: var(--td-text-color-placeholder);
transition: transform 150ms ease, color 150ms ease;
}
.kp-trigger:hover .kp-trigger-arrow {
color: var(--td-brand-color);
transform: translateX(2px);
}
/* Hidden mount keeps fetcher live without showing UI */
.kp-trigger-shadow {
display: none;
}
/* ============== Secondary drawer shell ============== */
.kp-drawer-shell {
display: flex;
flex-direction: column;
height: 100%;
width: 100%;
background: var(--td-bg-color-container);
/* Belt-and-suspenders: even if some inner element forgets a min-width:0
declaration in a flex chain, clip rather than overflow the drawer. */
overflow: hidden;
min-width: 0;
}
.kp-drawer-titlebar {
flex: 0 0 auto;
display: flex;
align-items: center;
justify-content: space-between;
padding: 14px 20px 12px;
border-bottom: 1px solid var(--td-component-stroke);
background: var(--td-bg-color-container);
}
.kp-drawer-titlebar-left {
display: flex;
align-items: center;
gap: 10px;
min-width: 0;
}
.kp-drawer-titlebar-kind {
font-family: var(--app-font-family-mono);
font-size: 10px;
text-transform: uppercase;
letter-spacing: 0.5px;
color: var(--td-text-color-placeholder);
background: var(--td-bg-color-secondarycontainer);
border-radius: var(--td-radius-default);
padding: 2px 6px;
line-height: 1.2;
}
.kp-drawer-titlebar-title {
font-size: 15px;
font-weight: 600;
color: var(--td-text-color-primary);
letter-spacing: -0.005em;
}
.kp-drawer-titlebar-close {
display: inline-flex;
align-items: center;
justify-content: center;
width: 28px;
height: 28px;
border: none;
background: transparent;
cursor: pointer;
color: var(--td-text-color-placeholder);
border-radius: var(--td-radius-default);
transition: background 150ms ease, color 150ms ease;
}
.kp-drawer-titlebar-close:hover {
background: var(--td-bg-color-secondarycontainer);
color: var(--td-text-color-primary);
}
.kp-drawer-body {
flex: 1 1 auto;
min-height: 0;
min-width: 0;
overflow: hidden;
/* Plain block layout — flex was unnecessary and risked the timeline
becoming a flex item with auto-sized basis, leaking past the drawer
bounds when its internal min-widths exceeded the parent. */
display: block;
position: relative;
}
.kp-drawer-body > :deep(.kp-timeline) {
width: 100%;
height: 100%;
}
/* Width is set via the :size prop on the <t-drawer>, not CSS — see the
<script> for mainDrawerSize / timelineDrawerSize. Only padding +
background are still tweaked here so the timeline fills the secondary
drawer cleanly, edge-to-edge. */
:deep(.kp-secondary-drawer .t-drawer__body) {
padding: 0 !important;
}
:deep(.kp-secondary-drawer .t-drawer__content) {
background: var(--td-bg-color-container);
}
// 文档摘要区域
.summary_box {
display: flex;
@@ -1514,3 +1909,20 @@ const handleDetailsScroll = () => {
margin-top: 12px;
}
</style>
<!-- Non-scoped padding/background overrides for the secondary drawer.
Width is now controlled via the :size prop on <t-drawer> (see
timelineDrawerSize in <script>) — that puts width on element.style
rather than fighting !important CSS rules. We only keep these
non-scoped rules because TDesign's default body padding and
content background need to be flushed for the timeline to fill
edge-to-edge. -->
<style lang="less">
.t-drawer.kp-secondary-drawer .t-drawer__body {
padding: 0 !important;
}
.t-drawer.kp-secondary-drawer .t-drawer__content {
background: var(--td-bg-color-container);
}
</style>
File diff suppressed because it is too large Load Diff
+36 -2
View File
@@ -394,21 +394,55 @@ export default {
attempt: 'Attempt {n}',
attemptLatest: 'Attempt {n} (latest)',
retry: 'Retry parsing',
refresh: 'Refresh now',
copy: 'Copy',
copyDetails: 'Copy details',
copied: 'Copied to clipboard',
close: 'Close',
live: 'LIVE',
liveTooltip: 'Parsing in progress, refreshes every 2s (next in {n}s)',
viewTrace: 'View trace',
justNow: 'just now',
secondsAgo: '{n}s ago',
minutesAgo: '{n}m ago',
noActivity: 'No parsing activity yet',
totalDuration: 'Total: {d}',
total: 'Total {d}',
head: {
duration: 'Duration',
stages: 'Stages',
stage: 'Stage',
status: 'Status',
attempt: 'Attempt',
updated: 'Updated',
},
tab: {
overview: 'Overview',
raw: 'Raw JSON',
},
detail: {
started: 'Started',
finished: 'Finished',
duration: 'Duration',
offset: 'Offset',
timing: 'Timing',
identity: 'Identity',
stageBreakdown: 'Stage breakdown',
stageOrder: 'Stage order',
childCount: 'Child spans',
kind: 'Kind',
status: 'Status',
name: 'Name',
input: 'Input',
output: 'Output',
metadata: 'Metadata',
error: 'Error',
showJson: 'Show JSON',
hideJson: 'Hide JSON',
empty: 'No data',
inProgress: 'In progress',
elapsed: 'Elapsed',
placeholderHint: 'This stage has no detailed span record; only the inferred state is shown.',
showJson: 'Expand JSON',
hideJson: 'Collapse JSON',
},
stage: {
docreader: 'Document parsing',
+36 -2
View File
@@ -400,21 +400,55 @@ export default {
attempt: "{n}번째 시도",
attemptLatest: "{n}번째 시도 (최신)",
retry: "다시 파싱",
refresh: "지금 새로고침",
copy: "복사",
copyDetails: "세부정보 복사",
copied: "클립보드에 복사됨",
close: "닫기",
live: "LIVE",
liveTooltip: "파싱 중, 2초마다 자동 새로고침 ({n}s 후)",
viewTrace: "Trace 보기",
justNow: "방금",
secondsAgo: "{n}초 전",
minutesAgo: "{n}분 전",
noActivity: "파싱 활동 없음",
totalDuration: "총 소요시간: {d}",
total: "총 {d}",
head: {
duration: "소요시간",
stages: "단계",
stage: "단계",
status: "상태",
attempt: "시도",
updated: "갱신",
},
tab: {
overview: "개요",
raw: "원본 JSON",
},
detail: {
started: "시작",
finished: "종료",
duration: "소요시간",
offset: "시작 오프셋",
timing: "타이밍",
identity: "식별 정보",
stageBreakdown: "단계 분석",
stageOrder: "단계 순서",
childCount: "하위 span 수",
kind: "유형",
status: "상태",
name: "이름",
input: "입력",
output: "출력",
metadata: "메타데이터",
error: "오류",
showJson: "JSON 표시",
hideJson: "JSON 숨기기",
empty: "데이터 없음",
inProgress: "진행 중",
elapsed: "경과",
placeholderHint: "이 단계에는 상세한 span 기록이 없으며, 추정된 상태만 표시됩니다.",
showJson: "JSON 펼치기",
hideJson: "JSON 접기",
},
stage: {
docreader: "문서 파싱",
+36 -2
View File
@@ -397,21 +397,55 @@ export default {
attempt: "第 {n} 次尝试",
attemptLatest: "第 {n} 次尝试(最新)",
retry: "重新解析",
refresh: "立即刷新",
copy: "复制",
copyDetails: "复制详情",
copied: "已复制到剪贴板",
close: "关闭",
live: "LIVE",
liveTooltip: "解析中,每 2 秒自动刷新({n}s 后)",
viewTrace: "查看 Trace",
justNow: "刚刚",
secondsAgo: "{n} 秒前",
minutesAgo: "{n} 分钟前",
noActivity: "暂无解析记录",
totalDuration: "总耗时:{d}",
total: "总耗时 {d}",
head: {
duration: "总耗时",
stages: "阶段",
stage: "阶段",
status: "状态",
attempt: "尝试",
updated: "更新于",
},
tab: {
overview: "概览",
raw: "原始 JSON",
},
detail: {
started: "开始",
finished: "结束",
duration: "耗时",
offset: "起点偏移",
timing: "时序",
identity: "身份信息",
stageBreakdown: "阶段分解",
stageOrder: "阶段顺序",
childCount: "子 span 数",
kind: "类型",
status: "状态",
name: "名称",
input: "输入",
output: "输出",
metadata: "元数据",
error: "错误",
showJson: "显示 JSON",
hideJson: "隐藏 JSON",
empty: "暂无数据",
inProgress: "进行中",
elapsed: "已用",
placeholderHint: "此阶段未记录详细 span,仅展示推断状态。",
showJson: "展开 JSON",
hideJson: "收起 JSON",
},
stage: {
docreader: "文档解析",