diff --git a/frontend/src/components/doc-content.vue b/frontend/src/components/doc-content.vue index ee197397..c7e533ab 100644 --- a/frontend/src/components/doc-content.vue +++ b/frontend/src/components/doc-content.vue @@ -790,7 +790,7 @@ const handleDetailsScroll = () => {
(null) const loading = ref(false) -const expandedStage = ref('') const selectedAttempt = ref(undefined) +const expandedRows = ref>(new Set(['__root__'])) +const detailRow = ref(null) +const nowTick = ref(Date.now()) let pollTimer: ReturnType | null = null +let nowTimer: ReturnType | null = null let unmounted = false const stages = computed(() => { @@ -80,22 +83,11 @@ const currentStageIndex = computed(() => { }) function formatDuration(ms?: number): string { - if (!ms || ms < 0) return '—' - if (ms < 1000) return `${ms}ms` + if (ms === undefined || ms === null || isNaN(ms) || ms < 0) return '—' + if (ms < 1000) return `${Math.round(ms)}ms` return `${(ms / 1000).toFixed(1)}s` } -function statusIcon(status: string): string { - switch (status) { - case 'done': return 'check' - case 'running': return 'loading' - case 'failed': return 'close' - case 'cancelled': return 'minus-circle' - case 'skipped': return 'minus' - default: return 'circle' - } -} - function isPolling(status?: string): boolean { return status === 'pending' || status === 'processing' } @@ -137,7 +129,6 @@ function localizedErrorTitle(code?: string): string { if (!code) return '' const key = `knowledgeStages.errorCode.${code}` const localized = t(key) - // vue-i18n returns the key when missing return localized === key ? code : localized } @@ -150,14 +141,9 @@ function localizedErrorSuggestion(code?: string): string { return fallback === 'knowledgeStages.errorCode.UNKNOWN_SUGGESTION' ? '' : fallback } -function toggleExpand(stage: SpanNode) { - if (stage.status !== 'failed' && stage.status !== 'cancelled') return - expandedStage.value = expandedStage.value === stage.name ? '' : stage.name -} - -async function copySpan(stage: SpanNode) { +async function copySpan(node: SpanNode) { try { - await navigator.clipboard.writeText(JSON.stringify(stage, null, 2)) + await navigator.clipboard.writeText(JSON.stringify(node, null, 2)) MessagePlugin.success(t('knowledgeStages.copied')) } catch { MessagePlugin.error(t('knowledgeStages.copyDetails')) @@ -200,19 +186,254 @@ watch( () => { selectedAttempt.value = undefined data.value = null - expandedStage.value = '' + expandedRows.value = new Set(['__root__']) + detailRow.value = null fetchSpans() }, ) onMounted(() => { fetchSpans() + nowTimer = setInterval(() => { + nowTick.value = Date.now() + }, 1000) }) onBeforeUnmount(() => { unmounted = true clearTimer() + if (nowTimer) { + clearInterval(nowTimer) + nowTimer = null + } }) + +// ---------- Waterfall helpers ---------- + +function rowKey(node: SpanNode, fallback: string): string { + return node.span_id || fallback +} + +function parseTime(s?: string | null): number | null { + if (!s) return null + const t = Date.parse(s) + return Number.isNaN(t) ? null : t +} + +function nodeStart(node: SpanNode): number | null { + return parseTime(node.started_at || undefined) +} + +function nodeEnd(node: SpanNode): number | null { + const e = parseTime(node.finished_at || undefined) + if (e !== null) return e + const s = nodeStart(node) + if (s !== null && typeof node.duration_ms === 'number' && node.duration_ms > 0) { + return s + node.duration_ms + } + return null +} + +function collectStarts(node: SpanNode | undefined, out: number[]) { + if (!node) return + const s = nodeStart(node) + if (s !== null) out.push(s) + for (const c of node.children || []) collectStarts(c, out) +} + +function collectEnds(node: SpanNode | undefined, out: number[]) { + if (!node) return + const e = nodeEnd(node) + if (e !== null) out.push(e) + for (const c of node.children || []) collectEnds(c, out) +} + +const traceRoot = computed(() => { + const trace = data.value?.trace + if (!trace) return null + // Build a synthesized root that contains the canonical 5 stages in order, + // so the waterfall always shows the full pipeline shape. + const synthChildren: SpanNode[] = stages.value.map((stage) => stage) + return { + ...trace, + name: trace.name || 'knowledge_processing', + kind: trace.kind || 'root', + children: synthChildren, + } +}) + +const t0 = computed(() => { + const root = traceRoot.value + if (!root) return null + const direct = nodeStart(root) + if (direct !== null) return direct + const all: number[] = [] + collectStarts(root, all) + if (all.length === 0) return null + return Math.min(...all) +}) + +const tEnd = computed(() => { + const root = traceRoot.value + if (!root) return null + const direct = parseTime(root.finished_at || undefined) + const all: number[] = [] + collectEnds(root, all) + let candidate: number | null = direct + if (all.length > 0) { + const max = Math.max(...all) + candidate = candidate === null ? max : Math.max(candidate, max) + } + // If the trace is still running, extend t_end to "now" so the running bar + // grows visibly. + const status = data.value?.parse_status + if (isPolling(status)) { + const now = nowTick.value + candidate = candidate === null ? now : Math.max(candidate, now) + } + return candidate +}) + +const totalMs = computed(() => { + if (t0.value === null || tEnd.value === null) return 0 + return Math.max(0, tEnd.value - t0.value) +}) + +const showRuler = computed(() => totalMs.value >= 100) + +const rulerTicks = computed(() => { + if (!showRuler.value) return [] as { left: string; label: string }[] + const total = totalMs.value + const fmt = (ms: number) => formatDuration(ms) + return [ + { left: '0%', label: fmt(0) }, + { left: '25%', label: fmt(total * 0.25) }, + { left: '50%', label: fmt(total * 0.5) }, + { left: '75%', label: fmt(total * 0.75) }, + { left: '100%', label: fmt(total) }, + ] +}) + +interface FlatRow { + key: string + depth: number + node: SpanNode + hasChildren: boolean + isRoot: boolean + isStage: boolean +} + +function isStageName(name?: string): boolean { + return !!name && (STAGES as readonly string[]).includes(name) +} + +const flatRows = computed(() => { + const root = traceRoot.value + if (!root) return [] + const rows: FlatRow[] = [] + + const rootKey = rowKey(root, '__root__') + rows.push({ + key: rootKey, + depth: 0, + node: root, + hasChildren: (root.children || []).length > 0, + isRoot: true, + isStage: false, + }) + if (!expandedRows.value.has(rootKey) && !expandedRows.value.has('__root__')) { + return rows + } + + for (const stage of root.children || []) { + const stageKey = rowKey(stage, `stage:${stage.name}`) + const stageChildren = stage.children || [] + rows.push({ + key: stageKey, + depth: 1, + node: stage, + hasChildren: stageChildren.length > 0, + isRoot: false, + isStage: true, + }) + if (!expandedRows.value.has(stageKey)) continue + + // Walk descendants depth-first; stage children are already at depth 2. + const walk = (n: SpanNode, depth: number, idxPath: string) => { + const key = rowKey(n, `${idxPath}:${n.name}`) + const kids = n.children || [] + rows.push({ + key, + depth, + node: n, + hasChildren: kids.length > 0, + isRoot: false, + isStage: false, + }) + if (kids.length === 0) return + // Auto-expand non-stage descendants — only stage rows gate further depth. + kids.forEach((c, i) => walk(c, depth + 1, `${idxPath}/${i}`)) + } + stageChildren.forEach((c, i) => walk(c, 2, `${stageKey}/${i}`)) + } + + return rows +}) + +function barStyle(node: SpanNode): Record { + const total = totalMs.value + if (!total || t0.value === null) return { display: 'none' } + const start = nodeStart(node) + if (start === null) return { display: 'none' } + const end = nodeEnd(node) ?? (isPolling(data.value?.parse_status) ? nowTick.value : start) + const leftPct = ((start - t0.value) / total) * 100 + const widthPct = Math.max(0.5, ((end - start) / total) * 100) + return { + left: `${Math.max(0, Math.min(100, leftPct))}%`, + width: `${Math.min(100 - Math.max(0, leftPct), widthPct)}%`, + } +} + +function isPlaceholder(node: SpanNode): boolean { + return !node.span_id && !node.started_at +} + +function toggleTree(row: FlatRow, ev?: MouseEvent) { + if (ev) ev.stopPropagation() + if (!row.hasChildren) return + const next = new Set(expandedRows.value) + if (next.has(row.key)) next.delete(row.key) + else next.add(row.key) + expandedRows.value = next +} + +function toggleDetail(row: FlatRow) { + detailRow.value = detailRow.value === row.key ? null : row.key +} + +function isObjectWithKeys(v: any): boolean { + return v && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length > 0 +} + +function prettyJSON(v: any): string { + try { + return JSON.stringify(v, null, 2) + } catch { + return String(v) + } +} + +function localizedStatus(status: string): string { + const key = `knowledgeStages.status.${status}` + const localized = t(key) + return localized === key ? status : localized +} + +function rowLabel(row: FlatRow): string { + if (row.isRoot) return row.node.name || 'knowledge_processing' + if (row.isStage) return t(`knowledgeStages.stage.${row.node.name}`) + return row.node.name +}
@@ -307,19 +629,28 @@ onBeforeUnmount(() => { .kp-timeline { font-size: 13px; color: var(--td-text-color-primary); + width: 100%; } -/* ============ FULL MODE ============ */ +/* ============ HEADER ============ */ .kp-header { display: flex; align-items: center; justify-content: space-between; - margin-bottom: 12px; + gap: 12px; + padding-bottom: 8px; + border-bottom: 1px solid var(--td-component-border, #e7e7e7); + margin-bottom: 8px; } .kp-title { font-weight: 600; font-size: 14px; } +.kp-header-actions { + display: flex; + align-items: center; + gap: 8px; +} .kp-attempt-select { font-size: 12px; padding: 2px 8px; @@ -329,116 +660,325 @@ onBeforeUnmount(() => { color: var(--td-text-color-primary); cursor: pointer; } - -.kp-steps { +.kp-status-line { + font-size: 12px; + color: var(--td-text-color-secondary); + margin-bottom: 10px; display: flex; - align-items: flex-start; - gap: 4px; - width: 100%; + gap: 6px; + align-items: center; } -.kp-step { +.kp-status-sep { + color: var(--td-text-color-placeholder); +} + +/* ============ RULER ============ */ +.kp-ruler-row { + display: grid; + grid-template-columns: minmax(180px, 30%) minmax(110px, 14%) 1fr; + align-items: center; + margin-bottom: 4px; +} +.kp-ruler-track { + position: relative; + height: 16px; +} +.kp-ruler-tick { + position: absolute; + top: 0; + transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; - gap: 4px; - flex: 0 0 auto; - min-width: 72px; - padding: 4px 2px; - border-radius: 6px; - transition: background-color 0.15s; -} -.kp-clickable { - cursor: pointer; -} -.kp-clickable:hover { - background: var(--td-bg-color-container-hover, rgba(0, 0, 0, 0.04)); -} -.kp-icon-wrap { - width: 24px; - height: 24px; - border-radius: 50%; - display: inline-flex; - align-items: center; - justify-content: center; - color: #fff; - background: var(--td-text-color-placeholder, #c0c0c0); -} -.kp-step-name { - font-size: 12px; - text-align: center; - color: var(--td-text-color-primary); -} -.kp-step-dur { font-size: 11px; color: var(--td-text-color-placeholder); } -.kp-connector { - flex: 1 1 auto; - height: 2px; - margin-top: 11px; - background: var(--td-component-border, #e0e0e0); - min-width: 12px; +.kp-ruler-tick:first-child { transform: translateX(0); align-items: flex-start; } +.kp-ruler-tick:last-child { transform: translateX(-100%); align-items: flex-end; } +.kp-ruler-tick-line { + width: 1px; + height: 4px; + background: var(--td-component-border, #e7e7e7); } -.kp-connector-done { - background: var(--td-success-color); -} -.kp-connector-failed { - background: var(--td-error-color); +.kp-ruler-tick-label { + margin-top: 1px; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; } -.kp-step-done .kp-icon-wrap { - background: var(--td-success-color); +/* ============ ROWS GRID ============ */ +.kp-rows { + display: flex; + flex-direction: column; + border: 1px solid var(--td-component-border, #e7e7e7); + border-radius: 6px; + overflow: hidden; + background: var(--td-bg-color-container, #fff); } -.kp-step-running .kp-icon-wrap { +.kp-row { + display: grid; + grid-template-columns: minmax(180px, 30%) minmax(110px, 14%) 1fr; + align-items: center; + min-height: 28px; + cursor: pointer; + border-bottom: 1px solid var(--td-component-border, #f0f0f0); + transition: background-color 0.12s; +} +.kp-row:last-child { border-bottom: none; } +.kp-row:hover { background: var(--td-bg-color-container-hover, rgba(0, 0, 0, 0.025)); } +.kp-row-active { background: var(--td-bg-color-container-hover, rgba(0, 0, 0, 0.04)); } + +.kp-cell-name { + padding: 4px 8px 4px 8px; + min-width: 0; +} +.kp-name-inner { + display: flex; + align-items: center; + gap: 6px; + min-width: 0; +} +.kp-tree-toggle { + width: 14px; + height: 14px; + display: inline-flex; + align-items: center; + justify-content: center; + border: none; + background: transparent; + padding: 0; + cursor: pointer; + color: var(--td-text-color-placeholder); + transition: transform 0.15s; +} +.kp-tree-toggle-open { transform: rotate(90deg); } +.kp-tree-toggle-spacer { width: 14px; height: 14px; display: inline-block; } +.kp-status-dot { + width: 8px; + height: 8px; + border-radius: 50%; + flex-shrink: 0; + background: var(--td-text-color-placeholder, #c0c0c0); +} +.kp-name-text { + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 12px; + color: var(--td-text-color-primary); + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.kp-name-root { font-weight: 600; } + +.kp-cell-meta { + display: flex; + align-items: center; + justify-content: flex-end; + gap: 8px; + padding: 4px 12px 4px 4px; + font-size: 12px; + color: var(--td-text-color-secondary); +} +.kp-meta-status { + font-size: 11px; + text-transform: lowercase; + color: var(--td-text-color-placeholder); +} +.kp-meta-dur { + width: 56px; + text-align: right; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 11px; + color: var(--td-text-color-secondary); +} + +.kp-cell-bar { + position: relative; + height: 18px; + margin-right: 12px; +} +.kp-bar { + position: absolute; + top: 5px; + height: 8px; + border-radius: 2px; + background: var(--td-text-color-placeholder, #c0c0c0); + min-width: 2px; +} +.kp-bar-done { background: var(--td-success-color); } +.kp-bar-failed { background: var(--td-error-color); } +.kp-bar-cancelled { + background: transparent; + border: 1px dashed var(--td-text-color-placeholder, #c0c0c0); +} +.kp-bar-skipped { + background: var(--td-text-color-placeholder); + opacity: 0.5; +} +.kp-bar-pending { + background: var(--td-component-border, #e7e7e7); +} +.kp-bar-running { + background: var(--td-brand-color); + background-image: linear-gradient( + 45deg, + rgba(255, 255, 255, 0.25) 25%, + transparent 25%, + transparent 50%, + rgba(255, 255, 255, 0.25) 50%, + rgba(255, 255, 255, 0.25) 75%, + transparent 75%, + transparent + ); + background-size: 12px 12px; + animation: kpStripes 0.8s linear infinite; +} +.kp-bar-placeholder { + right: 0; + top: 6px; + height: 6px; + width: 12px; + background: transparent; + border: 1px dashed var(--td-component-border, #e7e7e7); + border-radius: 2px; +} + +@keyframes kpStripes { + from { background-position: 0 0; } + to { background-position: 12px 0; } +} + +/* ============ STATUS DOTS (shared) ============ */ +.kp-dot-done { background: var(--td-success-color); } +.kp-dot-running { background: var(--td-brand-color); animation: kpPulse 1.4s ease-in-out infinite; } -.kp-step-failed .kp-icon-wrap { - background: var(--td-error-color); -} -.kp-step-cancelled .kp-icon-wrap { +.kp-dot-failed { background: var(--td-error-color); } +.kp-dot-cancelled { background: transparent; - color: var(--td-text-color-placeholder); border: 1px dashed var(--td-text-color-placeholder, #c0c0c0); } -.kp-step-skipped .kp-icon-wrap { - background: var(--td-text-color-placeholder, #c0c0c0); -} -.kp-step-pending .kp-icon-wrap { +.kp-dot-skipped { background: var(--td-text-color-placeholder, #c0c0c0); opacity: 0.5; } +.kp-dot-pending { background: transparent; - color: var(--td-text-color-placeholder); border: 1px solid var(--td-component-border, #dcdcdc); } +.kp-dot-placeholder { + background: transparent; + border: 1px dashed var(--td-component-border, #dcdcdc); +} @keyframes kpPulse { 0%, 100% { box-shadow: 0 0 0 0 var(--td-brand-color-light, rgba(0, 102, 255, 0.4)); } - 50% { box-shadow: 0 0 0 6px transparent; } + 50% { box-shadow: 0 0 0 4px transparent; } } -.kp-error-card { - margin-top: 12px; - padding: 10px 12px; - background: var(--td-bg-color-component); - border: 1px solid var(--td-error-color); - border-radius: 6px; +/* ============ DETAIL ROW ============ */ +.kp-detail { + grid-column: 1 / -1; + padding: 12px 16px; + background: var(--td-bg-color-secondarycontainer, #fafafa); + border-bottom: 1px solid var(--td-component-border, #f0f0f0); + font-size: 12px; } -.kp-error-title { +.kp-detail-error { + border-left: 3px solid var(--td-error-color); +} +.kp-detail-grid { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); + gap: 8px 16px; + margin-bottom: 8px; +} +.kp-detail-field { + display: flex; + flex-direction: column; + gap: 2px; + min-width: 0; +} +.kp-detail-label { + font-size: 10px; + text-transform: uppercase; + letter-spacing: 0.04em; + color: var(--td-text-color-placeholder); +} +.kp-detail-value { + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 11px; + color: var(--td-text-color-secondary); + overflow-wrap: anywhere; +} +.kp-status-chip { + display: inline-block; + padding: 1px 8px; + border-radius: 10px; + font-size: 11px; + background: var(--td-bg-color-component, #eee); + color: var(--td-text-color-primary); + width: fit-content; +} +.kp-chip-done { background: rgba(0, 168, 112, 0.12); color: var(--td-success-color); } +.kp-chip-running { background: rgba(0, 102, 255, 0.12); color: var(--td-brand-color); } +.kp-chip-failed { background: rgba(217, 48, 37, 0.12); color: var(--td-error-color); } +.kp-chip-cancelled { background: var(--td-bg-color-component, #eee); color: var(--td-text-color-secondary); } +.kp-chip-skipped { background: var(--td-bg-color-component, #eee); color: var(--td-text-color-placeholder); } +.kp-chip-pending { background: var(--td-bg-color-component, #eee); color: var(--td-text-color-secondary); } + +.kp-detail-error-block { + margin: 6px 0 10px; + padding: 8px 10px; + border: 1px solid var(--td-error-color); + border-radius: 4px; + background: rgba(217, 48, 37, 0.04); +} +.kp-detail-error-title { display: flex; align-items: center; gap: 6px; - font-weight: 600; color: var(--td-error-color); - margin-bottom: 6px; + font-weight: 600; + margin-bottom: 4px; } -.kp-error-msg { - font-size: 12px; +.kp-detail-error-msg { + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 11px; + color: var(--td-text-color-secondary); white-space: pre-wrap; word-break: break-word; - color: var(--td-text-color-secondary); - margin-bottom: 8px; - font-family: ui-monospace, SFMono-Regular, Menlo, monospace; } +.kp-detail-section { + margin-top: 8px; +} +.kp-json { + margin: 4px 0 0; + padding: 8px 10px; + background: var(--td-bg-color-container, #fff); + border: 1px solid var(--td-component-border, #e7e7e7); + border-radius: 4px; + max-height: 240px; + overflow: auto; + white-space: pre-wrap; + word-break: break-word; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 11px; + color: var(--td-text-color-primary); +} +.kp-detail-actions { + margin-top: 8px; + display: flex; + justify-content: flex-end; +} + +/* ============ EMPTY ============ */ +.kp-empty { + font-size: 12px; + color: var(--td-text-color-placeholder); + padding: 20px 0; + text-align: center; +} + +/* ============ LAST-ERROR (failed only) ============ */ .kp-last-error { margin-top: 12px; padding: 10px 12px; @@ -478,12 +1018,6 @@ onBeforeUnmount(() => { word-break: break-word; } -.kp-empty { - font-size: 12px; - color: var(--td-text-color-placeholder); - padding: 8px 0; -} - /* ============ COMPACT MODE ============ */ .kp-compact { max-width: 320px; @@ -500,21 +1034,6 @@ onBeforeUnmount(() => { background: var(--td-text-color-placeholder, #c0c0c0); display: inline-block; } -.kp-dot-done { background: var(--td-success-color); } -.kp-dot-running { - background: var(--td-brand-color); - animation: kpPulse 1.4s ease-in-out infinite; -} -.kp-dot-failed { background: var(--td-error-color); } -.kp-dot-cancelled { - background: transparent; - border: 1px dashed var(--td-text-color-placeholder, #c0c0c0); -} -.kp-dot-skipped { background: var(--td-text-color-placeholder, #c0c0c0); opacity: 0.6; } -.kp-dot-pending { - background: transparent; - border: 1px solid var(--td-component-border, #dcdcdc); -} .kp-compact-caption { margin-top: 4px; font-size: 12px; diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 39a5619d..177c285c 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -396,6 +396,7 @@ export default { copyDetails: 'Copy details', copied: 'Copied to clipboard', noActivity: 'No parsing activity yet', + totalDuration: 'Total: {d}', stage: { docreader: 'Document parsing', chunking: 'Chunking', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 99a7ec98..6eae382e 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -402,6 +402,7 @@ export default { copyDetails: "세부정보 복사", copied: "클립보드에 복사됨", noActivity: "파싱 활동 없음", + totalDuration: "총 소요시간: {d}", stage: { docreader: "문서 파싱", chunking: "청킹", diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 2c95f5fa..33a6fb25 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -366,6 +366,7 @@ export default { copyDetails: 'Скопировать детали', copied: 'Скопировано в буфер обмена', noActivity: 'Нет активности парсинга', + totalDuration: 'Всего: {d}', stage: { docreader: 'Парсинг документа', chunking: 'Разбиение', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 71c8e552..7c330053 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -399,6 +399,7 @@ export default { copyDetails: "复制详情", copied: "已复制到剪贴板", noActivity: "暂无解析记录", + totalDuration: "总耗时:{d}", stage: { docreader: "文档解析", chunking: "分块",