Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

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

wizardchenbd029b6d19a6
diff --git a/frontend/src/components/doc-content.vue b/frontend/src/components/doc-content.vue
index c7e533abf..9870b3099 100644
--- a/frontend/src/components/doc-content.vue
+++ b/frontend/src/components/doc-content.vue
@@ -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>
diff --git a/frontend/src/components/knowledge-processing-timeline.vue b/frontend/src/components/knowledge-processing-timeline.vue
index 9e6651920..7c9677b84 100644
--- a/frontend/src/components/knowledge-processing-timeline.vue
+++ b/frontend/src/components/knowledge-processing-timeline.vue
@@ -6,6 +6,7 @@ import { getKnowledgeSpans, reparseKnowledge } from '@/api/knowledge-base/index'
interface SpanNode {
span_id?: string
+ parent_span_id?: string
name: string
kind: string
status: string
@@ -31,6 +32,7 @@ interface SpansResponse {
knowledge_id: string
attempt: number
latest_attempt: number
+ current_attempt?: number
parse_status: string
current_stage?: string
trace: SpanNode
@@ -44,21 +46,27 @@ const props = defineProps<{
compact?: boolean
}>()
+const emit = defineEmits<{
+ (e: 'update:hasSpans', has: boolean): void
+ (e: 'update:summary', summary: { totalMs: number; status: string; stageIndex: number; stageTotal: number; stageLabel: string }): void
+}>()
+
const { t } = useI18n()
const STAGES = ['docreader', 'chunking', 'embedding', 'multimodal', 'postprocess'] as const
+const POLL_INTERVAL_MS = 2000
const data = ref<SpansResponse | null>(null)
const loading = ref(false)
+const refreshing = ref(false)
const selectedAttempt = ref<number | undefined>(undefined)
const expandedRows = ref<Set<string>>(new Set(['__root__']))
const selectedSpanId = ref<string | null>(null)
const expandedJsonKeys = ref<Set<string>>(new Set())
const nowTick = ref(Date.now())
+const detailTab = ref<'overview' | 'input' | 'output' | 'metadata' | 'raw'>('overview')
+const lastFetchedAt = ref<number>(0)
-// Per-attempt status cache for the tab strip. Lazy-fetched: when the strip
-// first becomes visible, we hit /spans?attempt=n once per missing tab so we
-// can colour the chip without polling all of them indefinitely.
const attemptStatuses = reactive<Map<number, string>>(new Map())
let pollTimer: ReturnType<typeof setTimeout> | null = null
@@ -92,13 +100,33 @@ const currentStageIndex = computed(() => {
function formatDuration(ms?: number): string {
if (ms === undefined || ms === null || isNaN(ms) || ms < 0) return '—'
if (ms < 1000) return `${Math.round(ms)}ms`
- return `${(ms / 1000).toFixed(1)}s`
+ 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 formatRelativeTime(ts: number): string {
+ if (!ts) return '—'
+ const sec = Math.max(0, Math.floor((nowTick.value - ts) / 1000))
+ if (sec < 1) return t('knowledgeStages.justNow')
+ if (sec < 60) return t('knowledgeStages.secondsAgo', { n: sec })
+ const min = Math.floor(sec / 60)
+ return t('knowledgeStages.minutesAgo', { n: min })
}
function isPolling(status?: string): boolean {
return status === 'pending' || status === 'processing'
}
+const isLive = computed(() => isPolling(data.value?.parse_status))
+
+const nextRefreshIn = computed(() => {
+ if (!isLive.value || !lastFetchedAt.value) return 0
+ const elapsed = nowTick.value - lastFetchedAt.value
+ return Math.max(0, Math.ceil((POLL_INTERVAL_MS - elapsed) / 1000))
+})
+
function clearTimer() {
if (pollTimer) {
clearTimeout(pollTimer)
@@ -106,39 +134,42 @@ function clearTimer() {
}
}
-async function fetchSpans() {
+async function fetchSpans(opts: { manual?: boolean } = {}) {
if (!props.knowledgeId) return
- loading.value = true
+ if (opts.manual) refreshing.value = true
+ if (!data.value) loading.value = true
try {
const res: any = await getKnowledgeSpans(props.knowledgeId, selectedAttempt.value)
if (res?.success && res.data) {
data.value = res.data as SpansResponse
+ lastFetchedAt.value = Date.now()
if (selectedAttempt.value === undefined) {
selectedAttempt.value = data.value.attempt
}
- // Always refresh the active tab's status from the freshest payload.
const traceStatus = data.value.trace?.status || data.value.parse_status || 'running'
attemptStatuses.set(data.value.attempt, traceStatus)
ensureAttemptStatuses()
+ const hasSpans = !!(data.value.trace && (data.value.trace.span_id || (data.value.current_attempt ?? 0) > 0))
+ emit('update:hasSpans', hasSpans)
+ } else {
+ emit('update:hasSpans', false)
}
} catch (e) {
- // Swallow — surface via empty state
+ emit('update:hasSpans', false)
} finally {
loading.value = false
+ refreshing.value = false
}
if (unmounted) return
if (props.autoPoll !== false && data.value && isPolling(data.value.parse_status)) {
clearTimer()
- pollTimer = setTimeout(fetchSpans, 2000)
+ pollTimer = setTimeout(() => fetchSpans(), POLL_INTERVAL_MS)
} else {
clearTimer()
}
}
-// Lazy per-attempt status discovery. We only fire one request per missing
-// number; the active attempt is always populated via fetchSpans, so usually
-// only the older attempts hit this path.
function ensureAttemptStatuses() {
const latest = data.value?.latest_attempt || 0
if (latest <= 1) return
@@ -170,15 +201,20 @@ function localizedErrorSuggestion(code?: string): string {
return fallback === 'knowledgeStages.errorCode.UNKNOWN_SUGGESTION' ? '' : fallback
}
-async function copySpan(node: SpanNode) {
+async function copyValue(value: any) {
try {
- await navigator.clipboard.writeText(JSON.stringify(node, null, 2))
+ const text = typeof value === 'string' ? value : JSON.stringify(value, null, 2)
+ await navigator.clipboard.writeText(text)
MessagePlugin.success(t('knowledgeStages.copied'))
} catch {
MessagePlugin.error(t('knowledgeStages.copyDetails'))
}
}
+async function copySpan(node: SpanNode) {
+ await copyValue(node)
+}
+
async function onRetry() {
if (!props.knowledgeId) return
try {
@@ -192,6 +228,11 @@ async function onRetry() {
}
}
+async function onManualRefresh() {
+ if (refreshing.value || loading.value) return
+ await fetchSpans({ manual: true })
+}
+
function onAttemptChange(n: number) {
if (Number.isNaN(n)) return
selectedAttempt.value = n
@@ -219,6 +260,7 @@ function onKeydown(ev: KeyboardEvent) {
onMounted(() => {
fetchSpans()
+ // Tick at 1Hz; running bars and "next refresh" countdown depend on it.
nowTimer = setInterval(() => {
nowTick.value = Date.now()
}, 1000)
@@ -309,8 +351,7 @@ const tEnd = computed<number | null>(() => {
const max = Math.max(...all)
candidate = candidate === null ? max : Math.max(candidate, max)
}
- const status = data.value?.parse_status
- if (isPolling(status)) {
+ if (isPolling(data.value?.parse_status)) {
const now = nowTick.value
candidate = candidate === null ? now : Math.max(candidate, now)
}
@@ -319,8 +360,6 @@ const tEnd = computed<number | null>(() => {
const totalMs = computed<number>(() => {
if (t0.value === null || tEnd.value === null) return 0
- // Prefer the trace's own reported duration when terminal — it's authoritative
- // now that the root span closes properly on done/failed.
const traceDur = data.value?.trace?.duration_ms
if (typeof traceDur === 'number' && traceDur > 0 && !isPolling(data.value?.parse_status)) {
return traceDur
@@ -328,7 +367,7 @@ const totalMs = computed<number>(() => {
return Math.max(0, tEnd.value - t0.value)
})
-const showRuler = computed(() => totalMs.value >= 100)
+const showRuler = computed(() => totalMs.value >= 50)
const rulerTicks = computed(() => {
if (!showRuler.value) return [] as { left: string; label: string }[]
@@ -343,6 +382,15 @@ const rulerTicks = computed(() => {
]
})
+// "Now" position on the waterfall scale, used to draw the live cursor
+// while polling so the user can see time advancing even when the running
+// stage's bar grows slowly toward the right edge.
+const nowMarkerPct = computed<number | null>(() => {
+ if (!isLive.value || !t0.value || !totalMs.value) return null
+ const pct = ((nowTick.value - t0.value) / totalMs.value) * 100
+ return Math.max(0, Math.min(100, pct))
+})
+
interface FlatRow {
key: string
depth: number
@@ -350,6 +398,7 @@ interface FlatRow {
hasChildren: boolean
isRoot: boolean
isStage: boolean
+ parentKey?: string
}
const flatRows = computed<FlatRow[]>(() => {
@@ -377,10 +426,11 @@ const flatRows = computed<FlatRow[]>(() => {
hasChildren: stageChildren.length > 0,
isRoot: false,
isStage: true,
+ parentKey: rootKey,
})
if (!expandedRows.value.has(stageKey)) continue
- const walk = (n: SpanNode, depth: number, idxPath: string) => {
+ const walk = (n: SpanNode, depth: number, idxPath: string, parentKey: string) => {
const key = rowKey(n, `${idxPath}:${n.name}`)
const kids = n.children || []
rows.push({
@@ -390,10 +440,11 @@ const flatRows = computed<FlatRow[]>(() => {
hasChildren: kids.length > 0,
isRoot: false,
isStage: false,
+ parentKey,
})
- kids.forEach((c, i) => walk(c, depth + 1, `${idxPath}/${i}`))
+ kids.forEach((c, i) => walk(c, depth + 1, `${idxPath}/${i}`, key))
}
- stageChildren.forEach((c, i) => walk(c, 2, `${stageKey}/${i}`))
+ stageChildren.forEach((c, i) => walk(c, 2, `${stageKey}/${i}`, stageKey))
}
return rows
@@ -405,7 +456,7 @@ const selectedRow = computed<FlatRow | null>(() => {
return flatRows.value.find((r) => r.key === id) || null
})
-const drawerOpen = computed(() => selectedSpanId.value !== null && selectedRow.value !== null)
+const detailOpen = computed(() => selectedSpanId.value !== null && selectedRow.value !== null)
function barStyle(node: SpanNode): Record<string, string> {
const total = totalMs.value
@@ -414,13 +465,33 @@ function barStyle(node: SpanNode): Record<string, string> {
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)
+ const widthPct = Math.max(0.4, ((end - start) / total) * 100)
return {
left: `${Math.max(0, Math.min(100, leftPct))}%`,
width: `${Math.min(100 - Math.max(0, leftPct), widthPct)}%`,
}
}
+function barOffsetPct(node: SpanNode): number | null {
+ const total = totalMs.value
+ if (!total || t0.value === null) return null
+ const start = nodeStart(node)
+ if (start === null) return null
+ return Math.max(0, Math.min(100, ((start - t0.value) / total) * 100))
+}
+
+function barOffsetMs(node: SpanNode): number {
+ const start = nodeStart(node)
+ if (start === null || t0.value === null) return 0
+ return Math.max(0, start - t0.value)
+}
+
+function liveElapsedMs(node: SpanNode): number {
+ const s = nodeStart(node)
+ if (s === null) return 0
+ return Math.max(0, nowTick.value - s)
+}
+
function isPlaceholder(node: SpanNode): boolean {
return !node.span_id && !node.started_at
}
@@ -439,10 +510,11 @@ function selectRow(row: FlatRow) {
selectedSpanId.value = null
} else {
selectedSpanId.value = row.key
+ detailTab.value = 'overview'
}
}
-function closeDrawer() {
+function closeDetail() {
selectedSpanId.value = null
}
@@ -450,6 +522,13 @@ function isObjectWithKeys(v: any): boolean {
return v && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length > 0
}
+function hasContent(v: any): boolean {
+ if (v === null || v === undefined || v === '') return false
+ if (Array.isArray(v)) return v.length > 0
+ if (typeof v === 'object') return Object.keys(v).length > 0
+ return true
+}
+
function prettyJSON(v: any): string {
try {
return JSON.stringify(v, null, 2)
@@ -470,12 +549,48 @@ function rowLabel(row: FlatRow): string {
return row.node.name
}
-function isMonoRowName(row: FlatRow): boolean {
- // Monospace only for free-form sub-spans (not root, not the canonical stages).
- return !row.isRoot && !row.isStage
+function rowKindLabel(row: FlatRow): string {
+ if (row.isRoot) return 'root'
+ if (row.isStage) return 'stage'
+ return row.node.kind || 'span'
+}
+
+function jsonExpandKey(section: string, key: string): string {
+ return `${selectedSpanId.value || ''}::${section}::${key}`
+}
+
+function toggleJsonKey(section: string, key: string) {
+ const k = jsonExpandKey(section, key)
+ const next = new Set(expandedJsonKeys.value)
+ if (next.has(k)) next.delete(k)
+ else next.add(k)
+ expandedJsonKeys.value = next
+}
+
+function isJsonExpanded(section: string, key: string): boolean {
+ return expandedJsonKeys.value.has(jsonExpandKey(section, key))
}
-// ---------- Detail key/value rendering ----------
+function formatTime(s?: string | null): string {
+ if (!s) return '—'
+ const ts = Date.parse(s)
+ if (Number.isNaN(ts)) return s
+ const d = new Date(ts)
+ const ms = String(d.getMilliseconds()).padStart(3, '0')
+ const hh = String(d.getHours()).padStart(2, '0')
+ const mm = String(d.getMinutes()).padStart(2, '0')
+ const ss = String(d.getSeconds()).padStart(2, '0')
+ // Date prefix: omit year when same as current year to keep the row
+ // compact, but always show month+day so traces from yesterday/last
+ // week aren't ambiguous. The full ISO date is preserved in the
+ // tooltip via the original string.
+ const now = new Date()
+ const yyyy = d.getFullYear()
+ const mo = String(d.getMonth() + 1).padStart(2, '0')
+ const dd = String(d.getDate()).padStart(2, '0')
+ const datePart = yyyy === now.getFullYear() ? `${mo}-${dd}` : `${yyyy}-${mo}-${dd}`
+ return `${datePart} ${hh}:${mm}:${ss}.${ms}`
+}
function humanizeKey(k: string): string {
return k
@@ -508,7 +623,7 @@ function toKvEntry(key: string, value: any): KvEntry {
return { key, label, kind: 'scalar', display: '—', raw: value }
}
if (typeof value === 'boolean') {
- return { key, label, kind: 'bool', display: value ? '✓' : '✗', raw: value }
+ return { key, label, kind: 'bool', display: value ? 'true' : 'false', raw: value }
}
if (typeof value === 'number') {
return { key, label, kind: 'scalar', display: value.toLocaleString(), raw: value }
@@ -517,42 +632,15 @@ function toKvEntry(key: string, value: any): KvEntry {
return { key, label, kind: 'scalar', display: value, raw: value }
}
if (Array.isArray(value)) {
- return { key, label, kind: 'array', display: `[Array length=${value.length}]`, raw: value }
+ return { key, label, kind: 'array', display: `Array · ${value.length}`, raw: value }
}
if (typeof value === 'object') {
const n = Object.keys(value as object).length
- return { key, label, kind: 'object', display: `{Object · ${n} keys}`, raw: value }
+ return { key, label, kind: 'object', display: `Object · ${n} keys`, raw: value }
}
return { key, label, kind: 'scalar', display: String(value), raw: value }
}
-function jsonExpandKey(section: string, key: string): string {
- return `${selectedSpanId.value || ''}::${section}::${key}`
-}
-
-function toggleJsonKey(section: string, key: string) {
- const k = jsonExpandKey(section, key)
- const next = new Set(expandedJsonKeys.value)
- if (next.has(k)) next.delete(k)
- else next.add(k)
- expandedJsonKeys.value = next
-}
-
-function isJsonExpanded(section: string, key: string): boolean {
- return expandedJsonKeys.value.has(jsonExpandKey(section, key))
-}
-
-function formatTime(s?: string | null): string {
- if (!s) return '—'
- const ts = Date.parse(s)
- if (Number.isNaN(ts)) return s
- const d = new Date(ts)
- const ms = String(d.getMilliseconds()).padStart(3, '0')
- return `${d.toLocaleTimeString()}.${ms}`
-}
-
-// ---------- Attempt strip helpers ----------
-
interface AttemptTab {
n: number
status: string
@@ -577,15 +665,15 @@ const attemptTabs = computed<AttemptTab[]>(() => {
function attemptGlyph(status: string): { ch: string; cls: string } {
switch (status) {
case 'done':
- return { ch: '✓', cls: 'kp-tab-glyph-done' }
+ return { ch: '✓', cls: 'kp-glyph-done' }
case 'failed':
- return { ch: '✗', cls: 'kp-tab-glyph-failed' }
+ return { ch: '✗', cls: 'kp-glyph-failed' }
case 'running':
case 'pending':
case 'processing':
- return { ch: '●', cls: 'kp-tab-glyph-running' }
+ return { ch: '●', cls: 'kp-glyph-running' }
default:
- return { ch: '–', cls: 'kp-tab-glyph-unknown' }
+ return { ch: '–', cls: 'kp-glyph-unknown' }
}
}
@@ -598,10 +686,93 @@ const headerStatusText = computed(() => {
const s = data.value?.trace?.status || data.value?.parse_status || ''
return s ? localizedStatus(s) : ''
})
+
+// Emit summary upstream so the doc-content drawer can show a one-line
+// status pill without mounting a second copy of the tree.
+watch(
+ [
+ () => totalMs.value,
+ () => data.value?.parse_status,
+ () => currentStageIndex.value,
+ () => currentStageLabel.value,
+ ],
+ () => {
+ emit('update:summary', {
+ totalMs: totalMs.value,
+ status: data.value?.trace?.status || data.value?.parse_status || '',
+ stageIndex: currentStageIndex.value,
+ stageTotal: stages.value.length,
+ stageLabel: currentStageLabel.value,
+ })
+ },
+ { immediate: true },
+)
+
+function tabHasContent(tab: 'input' | 'output' | 'metadata'): boolean {
+ const node = selectedRow.value?.node
+ if (!node) return false
+ return hasContent((node as any)[tab])
+}
+
+// Identity / lineage info for the Overview tab. Surfaces fields that
+// were previously buried in the raw payload so the panel doesn't feel
+// thin even when the span has no input/output/metadata.
+interface IdentityField {
+ key: string
+ label: string
+ value: string
+ mono: boolean
+ copyable: boolean
+}
+
+function identityFields(row: FlatRow): IdentityField[] {
+ const out: IdentityField[] = []
+ const node = row.node as any
+ out.push({ key: 'name', label: t('knowledgeStages.detail.name'), value: rowLabel(row), mono: false, copyable: false })
+ out.push({ key: 'kind', label: t('knowledgeStages.detail.kind'), value: rowKindLabel(row), mono: true, copyable: false })
+ out.push({ key: 'status', label: t('knowledgeStages.detail.status'), value: localizedStatus(row.node.status), mono: false, copyable: false })
+ if (row.isStage) {
+ const idx = stages.value.findIndex((s) => s.name === row.node.name)
+ if (idx >= 0) {
+ out.push({ key: 'stageIndex', label: t('knowledgeStages.detail.stageOrder'), value: `${idx + 1} / ${stages.value.length}`, mono: true, copyable: false })
+ }
+ }
+ if (row.hasChildren) {
+ out.push({ key: 'children', label: t('knowledgeStages.detail.childCount'), value: String((row.node.children || []).length), mono: true, copyable: false })
+ }
+ if (node.span_id) out.push({ key: 'span_id', label: 'span_id', value: node.span_id, mono: true, copyable: true })
+ if (node.parent_span_id) out.push({ key: 'parent_span_id', label: 'parent_span_id', value: node.parent_span_id, mono: true, copyable: true })
+ if (data.value?.knowledge_id) out.push({ key: 'knowledge_id', label: 'knowledge_id', value: data.value.knowledge_id, mono: true, copyable: true })
+ if (data.value?.current_attempt) out.push({ key: 'attempt', label: t('knowledgeStages.head.attempt'), value: `#${data.value.current_attempt}`, mono: true, copyable: false })
+ return out
+}
+
+// Quick stage-by-stage breakdown shown inside root's overview.
+interface StageRowSummary {
+ name: string
+ label: string
+ status: string
+ duration_ms?: number
+ pct: number
+}
+
+const stageBreakdown = computed<StageRowSummary[]>(() => {
+ const total = totalMs.value || 1
+ return stages.value.map((s) => ({
+ name: s.name,
+ label: t(`knowledgeStages.stage.${s.name}`),
+ status: s.status,
+ duration_ms: s.duration_ms,
+ pct: typeof s.duration_ms === 'number' && s.duration_ms > 0 ? Math.min(100, (s.duration_ms / total) * 100) : 0,
+ }))
+})
</script>
<template>
<div class="kp-timeline" :class="{ 'kp-compact': compact }">
+ <!-- =========================================================
+ COMPACT MODE — used by the card hover popover. Untouched.
+ ========================================================= -->
<template v-if="compact">
<div class="kp-compact-row">
<span
@@ -624,14 +795,34 @@ const headerStatusText = computed(() => {
</div>
</template>
+ <!-- =========================================================
+ FULL MODE — Langfuse-style waterfall, lives inside the
+ secondary drawer. Bottom-docked detail panel.
+ ========================================================= -->
<template v-else>
<div class="kp-shell">
- <div class="kp-main">
- <div class="kp-header">
- <div class="kp-header-left">
- <span class="kp-title">{{ t('knowledgeStages.title') }}</span>
+ <!-- ============== HEADER ============== -->
+ <div class="kp-head">
+ <div class="kp-head-row">
+ <div class="kp-head-id">
+ <span class="kp-head-status-dot" :class="['kp-dot-' + (data?.trace?.status || data?.parse_status || 'unknown')]" />
+ <span class="kp-head-name">{{ t('knowledgeStages.root') }}</span>
+ <span v-if="isLive" class="kp-live-badge" :title="t('knowledgeStages.liveTooltip', { n: nextRefreshIn })">
+ <span class="kp-live-dot" />
+ <span class="kp-live-text">{{ t('knowledgeStages.live') }}</span>
+ </span>
</div>
- <div class="kp-header-actions">
+ <div class="kp-head-actions">
+ <button
+ type="button"
+ class="kp-icon-btn"
+ :class="{ 'kp-icon-btn-spin': refreshing }"
+ :disabled="loading || refreshing"
+ :title="t('knowledgeStages.refresh')"
+ @click="onManualRefresh"
+ >
+ <t-icon name="refresh" size="14px" />
+ </button>
<t-button
v-if="data?.parse_status === 'failed'"
size="small"
@@ -645,47 +836,78 @@ const headerStatusText = computed(() => {
</div>
</div>
- <div v-if="data" class="kp-status-line">
- <span v-if="totalMs > 0" class="kp-total">{{ t('knowledgeStages.total', { d: formatDuration(totalMs) }) }}</span>
- <span v-if="totalMs > 0 && headerStatusText" class="kp-status-sep">·</span>
- <span v-if="headerStatusText" class="kp-status-cluster">
- <span class="kp-status-glyph" :class="headerStatusGlyph.cls">{{ headerStatusGlyph.ch }}</span>
- <span>{{ headerStatusText }}</span>
- </span>
+ <div v-if="data" class="kp-head-stats">
+ <div class="kp-stat">
+ <span class="kp-stat-label">{{ t('knowledgeStages.head.duration') }}</span>
+ <span class="kp-stat-val kp-mono">{{ totalMs > 0 ? formatDuration(totalMs) : '—' }}</span>
+ </div>
+ <div class="kp-stat">
+ <span class="kp-stat-label">{{ t('knowledgeStages.head.stages') }}</span>
+ <span class="kp-stat-val kp-mono">
+ <span class="kp-stat-num">{{ stages.filter((s) => s.status === 'done').length }}</span>
+ <span class="kp-stat-slash">/</span>
+ <span>{{ stages.length }}</span>
+ </span>
+ </div>
+ <div class="kp-stat">
+ <span class="kp-stat-label">{{ t('knowledgeStages.head.status') }}</span>
+ <span class="kp-stat-val">
+ <span class="kp-meta-glyph" :class="headerStatusGlyph.cls">{{ headerStatusGlyph.ch }}</span>
+ {{ headerStatusText || '—' }}
+ </span>
+ </div>
+ <div v-if="data?.current_attempt" class="kp-stat">
+ <span class="kp-stat-label">{{ t('knowledgeStages.head.attempt') }}</span>
+ <span class="kp-stat-val kp-mono">#{{ data.current_attempt }}</span>
+ </div>
+ <!-- "Updated Xs ago" stat is only meaningful while polling.
+ After the trace is terminal it would tick up forever
+ ("5s ago" → "1m ago" → "5m ago") implying staleness when
+ the data is in fact final. Hide it once parsing ends. -->
+ <div v-if="lastFetchedAt && isLive" class="kp-stat kp-stat-end">
+ <span class="kp-stat-label">{{ t('knowledgeStages.head.updated') }}</span>
+ <span class="kp-stat-val">{{ formatRelativeTime(lastFetchedAt) }}</span>
+ </div>
+ </div>
+
+ <div v-if="attemptTabs.length > 0" class="kp-attempts">
+ <button
+ v-for="tab in attemptTabs"
+ :key="tab.n"
+ type="button"
+ class="kp-attempt"
+ :class="{ 'kp-attempt-active': tab.active }"
+ @click="onAttemptChange(tab.n)"
+ >
+ <span class="kp-attempt-num kp-mono">#{{ tab.n }}</span>
+ <span class="kp-attempt-glyph" :class="attemptGlyph(tab.status).cls">{{ attemptGlyph(tab.status).ch }}</span>
+ </button>
</div>
+ </div>
- <div v-if="loading && !data" class="kp-loading">
+ <!-- ============== BODY (Waterfall) ============== -->
+ <div class="kp-body" :class="{ 'kp-body-with-detail': detailOpen }">
+ <div v-if="loading && !data" class="kp-state">
<t-loading size="small" />
</div>
- <div v-else-if="!data && !loading" class="kp-empty">{{ t('knowledgeStages.noActivity') }}</div>
+ <div v-else-if="!data && !loading" class="kp-state kp-state-empty">
+ <span>{{ t('knowledgeStages.noActivity') }}</span>
+ </div>
<template v-else-if="data">
- <div v-if="attemptTabs.length > 0" class="kp-tab-strip">
- <button
- v-for="tab in attemptTabs"
- :key="tab.n"
- type="button"
- class="kp-tab"
- :class="{ 'kp-tab-active': tab.active }"
- @click="onAttemptChange(tab.n)"
- >
- <span class="kp-tab-num">#{{ tab.n }}</span>
- <span class="kp-tab-glyph" :class="attemptGlyph(tab.status).cls">{{ attemptGlyph(tab.status).ch }}</span>
- </button>
- </div>
-
- <div v-if="showRuler" class="kp-ruler-row">
+ <div v-if="showRuler" class="kp-ruler">
<div class="kp-ruler-spacer-name" />
<div class="kp-ruler-spacer-meta" />
<div class="kp-ruler-track">
<span
v-for="(tick, i) in rulerTicks"
:key="i"
- class="kp-ruler-tick"
+ class="kp-tick"
+ :class="{ 'kp-tick-first': i === 0, 'kp-tick-last': i === rulerTicks.length - 1 }"
:style="{ left: tick.left }"
>
- <span class="kp-ruler-tick-line" />
- <span class="kp-ruler-tick-label">{{ tick.label }}</span>
+ <span class="kp-tick-line" />
+ <span class="kp-tick-label kp-mono">{{ tick.label }}</span>
</span>
</div>
</div>
@@ -695,11 +917,15 @@ const headerStatusText = computed(() => {
v-for="row in flatRows"
:key="row.key"
class="kp-row"
- :class="{ 'kp-row-active': selectedSpanId === row.key }"
+ :class="{
+ 'kp-row-active': selectedSpanId === row.key,
+ 'kp-row-root': row.isRoot,
+ 'kp-row-stage': row.isStage,
+ }"
@click="selectRow(row)"
>
<div class="kp-cell-name">
- <div class="kp-name-inner" :style="{ paddingLeft: row.depth * 14 + 'px' }">
+ <div class="kp-name-inner" :style="{ paddingLeft: row.depth * 16 + 'px' }">
<button
v-if="row.hasChildren && !row.isRoot"
type="button"
@@ -715,127 +941,303 @@ const headerStatusText = computed(() => {
/>
<span
class="kp-name-text"
- :class="{ 'kp-name-root': row.isRoot, 'kp-name-mono': isMonoRowName(row) }"
+ :class="{ 'kp-name-root': row.isRoot, 'kp-name-mono': !row.isRoot && !row.isStage }"
>{{ rowLabel(row) }}</span>
+ <span class="kp-name-kind">{{ rowKindLabel(row) }}</span>
</div>
</div>
- <div class="kp-cell-dur">{{ formatDuration(row.node.duration_ms) }}</div>
+
+ <div class="kp-cell-dur kp-mono">
+ <template v-if="row.node.status === 'running'">
+ <span class="kp-running-time">{{ formatDuration(liveElapsedMs(row.node)) }}</span>
+ </template>
+ <template v-else>
+ {{ formatDuration(row.node.duration_ms) }}
+ </template>
+ </div>
+
<div class="kp-cell-bar">
- <div v-if="isPlaceholder(row.node)" class="kp-bar kp-bar-placeholder" />
- <div
- v-else
- class="kp-bar"
- :class="['kp-bar-' + row.node.status, { 'kp-bar-running': row.node.status === 'running' }]"
- :style="barStyle(row.node)"
+ <span
+ v-if="nowMarkerPct !== null && row.isRoot"
+ class="kp-now-marker"
+ :style="{ left: nowMarkerPct + '%' }"
/>
+ <div v-if="isPlaceholder(row.node)" class="kp-bar kp-bar-placeholder" />
+ <template v-else>
+ <div
+ class="kp-bar"
+ :class="['kp-bar-' + row.node.status, { 'kp-bar-running-anim': row.node.status === 'running' }]"
+ :style="barStyle(row.node)"
+ >
+ <span class="kp-bar-tip">
+ <span class="kp-bar-tip-name">{{ rowLabel(row) }}</span>
+ <span class="kp-bar-tip-sep">·</span>
+ <span class="kp-mono">{{ formatDuration(row.node.status === 'running' ? liveElapsedMs(row.node) : row.node.duration_ms) }}</span>
+ <span class="kp-bar-tip-sep">·</span>
+ <span>{{ localizedStatus(row.node.status) }}</span>
+ </span>
+ </div>
+ <span
+ v-if="barOffsetPct(row.node) !== null && barOffsetMs(row.node) > 0"
+ class="kp-bar-offset kp-mono"
+ :style="{ left: barOffsetPct(row.node) + '%' }"
+ >
+ +{{ formatDuration(barOffsetMs(row.node)) }}
+ </span>
+ </template>
</div>
</div>
</div>
</template>
<div v-if="data?.last_error && data?.parse_status === 'failed'" class="kp-last-error">
- <div class="kp-last-error-row">
- <t-icon name="error-circle-filled" size="16px" class="kp-last-error-icon" />
- <div class="kp-last-error-body">
- <div class="kp-last-error-title">{{ localizedErrorTitle(data.last_error.error_code) }}</div>
- <div class="kp-last-error-suggestion">{{ localizedErrorSuggestion(data.last_error.error_code) }}</div>
- <div v-if="data.last_error.error_message" class="kp-last-error-raw">{{ data.last_error.error_message }}</div>
+ <div class="kp-last-error-bar" />
+ <div class="kp-last-error-body">
+ <div class="kp-last-error-row">
+ <span class="kp-last-error-glyph">!</span>
+ <span class="kp-last-error-title">{{ localizedErrorTitle(data.last_error.error_code) }}</span>
+ <span v-if="data.last_error.error_code" class="kp-last-error-code kp-mono">{{ data.last_error.error_code }}</span>
</div>
- <t-button size="small" theme="primary" @click="onRetry">
- <t-icon name="refresh" size="14px" />
- <span style="margin-left: 4px">{{ t('knowledgeStages.retry') }}</span>
- </t-button>
+ <div class="kp-last-error-suggestion">{{ localizedErrorSuggestion(data.last_error.error_code) }}</div>
+ <div v-if="data.last_error.error_message" class="kp-last-error-raw kp-mono">{{ data.last_error.error_message }}</div>
</div>
</div>
</div>
- <!-- Drawer (slides in within the shell) -->
- <div class="kp-drawer" :class="{ 'kp-drawer-open': drawerOpen }">
+ <!-- ============== DETAIL PANEL ============== -->
+ <div class="kp-detail" :class="{ 'kp-detail-open': detailOpen }">
<template v-if="selectedRow">
- <div class="kp-drawer-header">
- <div class="kp-drawer-title">
+ <div class="kp-detail-head">
+ <div class="kp-detail-title">
<span
- class="kp-status-dot kp-drawer-dot"
+ class="kp-status-dot kp-detail-dot"
:class="['kp-dot-' + selectedRow.node.status]"
/>
- <span class="kp-drawer-name">{{ rowLabel(selectedRow) }}</span>
- </div>
- <div class="kp-drawer-meta">
+ <span class="kp-detail-name">{{ rowLabel(selectedRow) }}</span>
+ <span class="kp-detail-kind">{{ rowKindLabel(selectedRow) }}</span>
<span class="kp-status-chip" :class="'kp-chip-' + selectedRow.node.status">
{{ localizedStatus(selectedRow.node.status) }}
</span>
- <button type="button" class="kp-drawer-close" @click="closeDrawer" aria-label="close">×</button>
+ </div>
+ <div class="kp-detail-actions">
+ <button type="button" class="kp-icon-btn" :title="t('knowledgeStages.copyDetails')" @click.stop="copySpan(selectedRow.node)">
+ <t-icon name="copy" size="14px" />
+ </button>
+ <button type="button" class="kp-icon-btn" :title="t('knowledgeStages.close')" @click="closeDetail">
+ <t-icon name="close" size="14px" />
+ </button>
</div>
</div>
- <div class="kp-drawer-body">
- <div class="kp-section">
- <div class="kp-kv-grid">
- <div class="kp-kv-row">
- <span class="kp-kv-key">{{ t('knowledgeStages.detail.started') }}</span>
- <span class="kp-kv-val kp-mono">{{ formatTime(selectedRow.node.started_at) }}</span>
- </div>
- <div class="kp-kv-row">
- <span class="kp-kv-key">{{ t('knowledgeStages.detail.finished') }}</span>
- <span class="kp-kv-val kp-mono">{{ formatTime(selectedRow.node.finished_at) }}</span>
- </div>
- <div class="kp-kv-row">
- <span class="kp-kv-key">{{ t('knowledgeStages.detail.duration') }}</span>
- <span class="kp-kv-val kp-mono">{{ formatDuration(selectedRow.node.duration_ms) }}</span>
- </div>
- </div>
- </div>
+ <div class="kp-tabs">
+ <button
+ type="button"
+ class="kp-tab"
+ :class="{ 'kp-tab-active': detailTab === 'overview' }"
+ @click="detailTab = 'overview'"
+ >{{ t('knowledgeStages.tab.overview') }}</button>
+ <button
+ type="button"
+ class="kp-tab"
+ :class="{ 'kp-tab-active': detailTab === 'input', 'kp-tab-empty': !tabHasContent('input') }"
+ @click="detailTab = 'input'"
+ >{{ t('knowledgeStages.detail.input') }}</button>
+ <button
+ type="button"
+ class="kp-tab"
+ :class="{ 'kp-tab-active': detailTab === 'output', 'kp-tab-empty': !tabHasContent('output') }"
+ @click="detailTab = 'output'"
+ >{{ t('knowledgeStages.detail.output') }}</button>
+ <button
+ type="button"
+ class="kp-tab"
+ :class="{ 'kp-tab-active': detailTab === 'metadata', 'kp-tab-empty': !tabHasContent('metadata') }"
+ @click="detailTab = 'metadata'"
+ >{{ t('knowledgeStages.detail.metadata') }}</button>
+ <button
+ type="button"
+ class="kp-tab"
+ :class="{ 'kp-tab-active': detailTab === 'raw' }"
+ @click="detailTab = 'raw'"
+ >{{ t('knowledgeStages.tab.raw') }}</button>
+ </div>
- <div
- v-if="(selectedRow.node.status === 'failed' || selectedRow.node.status === 'cancelled') && (selectedRow.node.error_code || selectedRow.node.error_message)"
- class="kp-error-block"
- >
- <div class="kp-error-title">
- <t-icon name="error-circle" size="14px" />
- <span>{{ localizedErrorTitle(selectedRow.node.error_code) || t('knowledgeStages.detail.error') }}</span>
- <span v-if="selectedRow.node.error_code" class="kp-error-code">{{ selectedRow.node.error_code }}</span>
+ <div class="kp-detail-body">
+ <!-- Overview tab -->
+ <template v-if="detailTab === 'overview'">
+ <!-- Timing -->
+ <div class="kp-section">
+ <div class="kp-section-title">{{ t('knowledgeStages.detail.timing') }}</div>
+ <div class="kp-kv">
+ <div class="kp-kv-row">
+ <span class="kp-kv-key">{{ t('knowledgeStages.detail.started') }}</span>
+ <span class="kp-kv-val kp-mono">{{ formatTime(selectedRow.node.started_at) }}</span>
+ </div>
+ <div class="kp-kv-row">
+ <span class="kp-kv-key">{{ t('knowledgeStages.detail.finished') }}</span>
+ <span class="kp-kv-val kp-mono">
+ <template v-if="selectedRow.node.status === 'running'">
+ <span class="kp-kv-running">{{ t('knowledgeStages.detail.inProgress') }}</span>
+ </template>
+ <template v-else>
+ {{ formatTime(selectedRow.node.finished_at) }}
+ </template>
+ </span>
+ </div>
+ <div class="kp-kv-row">
+ <span class="kp-kv-key">{{ t('knowledgeStages.detail.duration') }}</span>
+ <span class="kp-kv-val kp-mono">
+ <template v-if="selectedRow.node.status === 'running'">
+ {{ formatDuration(liveElapsedMs(selectedRow.node)) }}
+ <span class="kp-kv-tag-live">{{ t('knowledgeStages.detail.elapsed') }}</span>
+ </template>
+ <template v-else>
+ {{ formatDuration(selectedRow.node.duration_ms) }}
+ </template>
+ </span>
+ </div>
+ <div v-if="!selectedRow.isRoot && barOffsetMs(selectedRow.node) > 0" class="kp-kv-row">
+ <span class="kp-kv-key">{{ t('knowledgeStages.detail.offset') }}</span>
+ <span class="kp-kv-val kp-mono">+{{ formatDuration(barOffsetMs(selectedRow.node)) }}</span>
+ </div>
+ </div>
</div>
- <div v-if="selectedRow.node.error_message" class="kp-error-msg">{{ selectedRow.node.error_message }}</div>
- </div>
- <template v-for="section in (['input','output','metadata'] as const)" :key="section">
- <div v-if="isObjectWithKeys((selectedRow.node as any)[section])" class="kp-section">
- <div class="kp-section-title">{{ t('knowledgeStages.detail.' + section) }}</div>
- <div class="kp-kv-grid">
+ <!-- Identity / lineage -->
+ <div class="kp-section">
+ <div class="kp-section-title">{{ t('knowledgeStages.detail.identity') }}</div>
+ <div class="kp-kv">
<div
- v-for="entry in buildKvEntries((selectedRow.node as any)[section])"
+ v-for="entry in identityFields(selectedRow)"
:key="entry.key"
class="kp-kv-row"
>
<span class="kp-kv-key">{{ entry.label }}</span>
- <span v-if="entry.kind === 'bool'" class="kp-kv-val kp-bool" :class="{ 'kp-bool-true': entry.raw, 'kp-bool-false': !entry.raw }">{{ entry.display }}</span>
- <span v-else-if="entry.kind === 'scalar'" class="kp-kv-val">{{ entry.display }}</span>
- <div v-else class="kp-kv-val kp-kv-collapsible">
+ <span class="kp-kv-val" :class="{ 'kp-mono': entry.mono, 'kp-kv-truncate': entry.copyable }">
+ <span class="kp-kv-text">{{ entry.value }}</span>
<button
+ v-if="entry.copyable"
type="button"
- class="kp-kv-toggle"
- @click.stop="toggleJsonKey(section, entry.key)"
+ class="kp-kv-copy"
+ :title="t('knowledgeStages.copy')"
+ @click.stop="copyValue(entry.value)"
>
- <span class="kp-kv-summary">{{ entry.display }}</span>
- <span class="kp-kv-toggle-label">{{
- isJsonExpanded(section, entry.key)
- ? t('knowledgeStages.detail.hideJson')
- : t('knowledgeStages.detail.showJson')
- }}</span>
+ <t-icon name="copy" size="11px" />
</button>
- <pre v-if="isJsonExpanded(section, entry.key)" class="kp-json">{{ prettyJSON(entry.raw) }}</pre>
+ </span>
+ </div>
+ </div>
+ </div>
+
+ <!-- Stage breakdown (root only) -->
+ <div v-if="selectedRow.isRoot" class="kp-section">
+ <div class="kp-section-title">{{ t('knowledgeStages.detail.stageBreakdown') }}</div>
+ <div class="kp-breakdown">
+ <div
+ v-for="s in stageBreakdown"
+ :key="s.name"
+ class="kp-breakdown-row"
+ :class="['kp-breakdown-' + s.status]"
+ >
+ <span class="kp-breakdown-label">
+ <span class="kp-status-dot" :class="['kp-dot-' + s.status]" />
+ {{ s.label }}
+ </span>
+ <div class="kp-breakdown-track">
+ <div class="kp-breakdown-bar" :class="['kp-bar-' + s.status]" :style="{ width: s.pct + '%' }" />
</div>
+ <span class="kp-breakdown-dur kp-mono">{{ formatDuration(s.duration_ms) }}</span>
</div>
</div>
</div>
+
+ <!-- Error -->
+ <div
+ v-if="(selectedRow.node.status === 'failed' || selectedRow.node.status === 'cancelled') && (selectedRow.node.error_code || selectedRow.node.error_message)"
+ class="kp-error-block"
+ >
+ <div class="kp-error-head">
+ <span class="kp-error-glyph">!</span>
+ <span class="kp-error-title">{{ localizedErrorTitle(selectedRow.node.error_code) || t('knowledgeStages.detail.error') }}</span>
+ <span v-if="selectedRow.node.error_code" class="kp-error-code kp-mono">{{ selectedRow.node.error_code }}</span>
+ </div>
+ <pre v-if="selectedRow.node.error_message" class="kp-error-msg kp-mono">{{ selectedRow.node.error_message }}</pre>
+ </div>
+
+ <div v-if="!selectedRow.node.span_id && !selectedRow.node.started_at" class="kp-detail-hint">
+ {{ t('knowledgeStages.detail.placeholderHint') }}
+ </div>
</template>
- </div>
- <div class="kp-drawer-footer">
- <t-button size="small" variant="outline" @click.stop="copySpan(selectedRow.node)">
- <t-icon name="copy" size="14px" />
- <span style="margin-left: 4px">{{ t('knowledgeStages.copyDetails') }}</span>
- </t-button>
+ <!-- Input / Output / Metadata tabs -->
+ <template v-else-if="detailTab === 'input' || detailTab === 'output' || detailTab === 'metadata'">
+ <div v-if="!tabHasContent(detailTab)" class="kp-detail-empty">
+ <span>{{ t('knowledgeStages.detail.empty') }}</span>
+ </div>
+ <template v-else>
+ <div class="kp-section">
+ <div class="kp-section-bar">
+ <span class="kp-section-title">{{ t('knowledgeStages.detail.' + detailTab) }}</span>
+ <button
+ type="button"
+ class="kp-section-action"
+ @click="copyValue((selectedRow.node as any)[detailTab])"
+ >
+ <t-icon name="copy" size="11px" />
+ <span>{{ t('knowledgeStages.copy') }}</span>
+ </button>
+ </div>
+
+ <div v-if="isObjectWithKeys((selectedRow.node as any)[detailTab])" class="kp-kv">
+ <div
+ v-for="entry in buildKvEntries((selectedRow.node as any)[detailTab])"
+ :key="entry.key"
+ class="kp-kv-row kp-kv-row-multiline"
+ >
+ <span class="kp-kv-key kp-mono">{{ entry.key }}</span>
+ <div class="kp-kv-val kp-kv-multiline">
+ <span v-if="entry.kind === 'bool'" class="kp-mono" :class="{ 'kp-bool-true': entry.raw, 'kp-bool-false': !entry.raw }">{{ entry.display }}</span>
+ <span v-else-if="entry.kind === 'scalar'" class="kp-kv-scalar">{{ entry.display }}</span>
+ <div v-else class="kp-kv-collapsible">
+ <button
+ type="button"
+ class="kp-kv-toggle"
+ @click.stop="toggleJsonKey(detailTab, entry.key)"
+ >
+ <span class="kp-kv-summary kp-mono">{{ entry.display }}</span>
+ <span class="kp-kv-toggle-label">{{
+ isJsonExpanded(detailTab, entry.key)
+ ? t('knowledgeStages.detail.hideJson')
+ : t('knowledgeStages.detail.showJson')
+ }}</span>
+ </button>
+ <pre v-if="isJsonExpanded(detailTab, entry.key)" class="kp-json kp-mono">{{ prettyJSON(entry.raw) }}</pre>
+ </div>
+ </div>
+ </div>
+ </div>
+ <pre v-else class="kp-json kp-mono">{{ prettyJSON((selectedRow.node as any)[detailTab]) }}</pre>
+ </div>
+ </template>
+ </template>
+
+ <!-- Raw JSON tab -->
+ <template v-else-if="detailTab === 'raw'">
+ <div class="kp-section">
+ <div class="kp-section-bar">
+ <span class="kp-section-title">{{ t('knowledgeStages.tab.raw') }}</span>
+ <button
+ type="button"
+ class="kp-section-action"
+ @click="copyValue(selectedRow.node)"
+ >
+ <t-icon name="copy" size="11px" />
+ <span>{{ t('knowledgeStages.copy') }}</span>
+ </button>
+ </div>
+ <pre class="kp-json kp-mono kp-json-large">{{ prettyJSON(selectedRow.node) }}</pre>
+ </div>
+ </template>
</div>
</template>
</div>
@@ -844,182 +1246,377 @@ const headerStatusText = computed(() => {
</div>
</template>
-<style scoped>
+<style scoped lang="less">
.kp-timeline {
+ font-family: var(--app-font-family);
font-size: 13px;
color: var(--td-text-color-primary);
width: 100%;
+ height: 100%;
+ /* Defensive: never let waterfall rows / detail panel push past the
+ drawer's visible bounds even if the host width is unexpectedly
+ narrow. The horizontal scroll inside .kp-body handles legit cases
+ where labels are long. */
+ overflow: hidden;
}
-/* Shell wraps both timeline and drawer so the drawer is bounded by the
- component, not the viewport. */
.kp-shell {
position: relative;
+ display: flex;
+ flex-direction: column;
+ height: 100%;
+ width: 100%;
+ min-height: 0;
+ min-width: 0;
+ background: var(--td-bg-color-container);
overflow: hidden;
- border-radius: 8px;
}
-.kp-main {
- width: 100%;
+
+/* ============== HEADER ============== */
+.kp-head {
+ flex: 0 0 auto;
+ padding: 16px 20px 12px;
+ border-bottom: 1px solid var(--td-component-stroke);
+ background: var(--td-bg-color-container);
}
-/* ============ HEADER ============ */
-.kp-header {
+.kp-head-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
- padding-bottom: 6px;
-}
-.kp-title {
- font-weight: 600;
- font-size: 14px;
- color: var(--td-text-color-primary);
}
-.kp-header-actions {
+
+.kp-head-id {
display: flex;
align-items: center;
- gap: 8px;
+ gap: 10px;
+ min-width: 0;
}
-.kp-status-line {
- font-size: 12px;
- color: var(--td-text-color-secondary);
- margin-bottom: 12px;
- display: flex;
- gap: 6px;
- align-items: center;
- padding-bottom: 8px;
- border-bottom: 1px solid var(--td-component-border, #e7e7e7);
+
+.kp-head-status-dot {
+ width: 9px;
+ height: 9px;
+ border-radius: 50%;
+ flex-shrink: 0;
+ background: var(--td-text-color-placeholder);
}
-.kp-total { color: var(--td-text-color-primary); }
-.kp-status-sep { color: var(--td-text-color-placeholder); }
-.kp-status-cluster {
- display: inline-flex;
- gap: 4px;
- align-items: center;
+
+.kp-head-name {
+ font-size: 14px;
+ font-weight: 600;
+ color: var(--td-text-color-primary);
+ letter-spacing: -0.01em;
}
-.kp-status-glyph {
+
+/* LIVE badge — sits next to the title while polling, telegraphs the
+ pipeline is actively refreshing. Pulsing dot + uppercase mono label. */
+.kp-live-badge {
display: inline-flex;
align-items: center;
- justify-content: center;
- width: 12px;
- height: 12px;
- font-size: 11px;
+ gap: 5px;
+ padding: 2px 8px;
+ border-radius: var(--td-radius-medium);
+ background: var(--td-brand-color-light);
+ color: var(--td-brand-color);
+ font-size: 10px;
+ font-weight: 600;
+ text-transform: uppercase;
+ letter-spacing: 0.06em;
line-height: 1;
}
-/* ============ ATTEMPT TAB STRIP ============ */
-.kp-tab-strip {
+.kp-live-dot {
+ width: 6px;
+ height: 6px;
+ border-radius: 50%;
+ background: var(--td-brand-color);
+ animation: kpLivePulse 1.4s ease-in-out infinite;
+}
+
+.kp-live-text {
+ font-family: var(--app-font-family-mono);
+}
+
+@keyframes kpLivePulse {
+ 0%, 100% { opacity: 1; transform: scale(1); }
+ 50% { opacity: 0.45; transform: scale(0.8); }
+}
+
+.kp-head-actions {
display: flex;
- gap: 8px;
- overflow-x: auto;
- padding-bottom: 10px;
- margin-bottom: 6px;
- border-bottom: 1px solid var(--td-component-border, #e7e7e7);
+ align-items: center;
+ gap: 6px;
}
-.kp-tab {
+
+.kp-icon-btn {
display: inline-flex;
align-items: center;
- gap: 6px;
- padding: 4px 10px;
- border: 1px solid var(--td-component-border, #dcdcdc);
- border-radius: 999px;
- background: var(--td-bg-color-container, #fff);
- color: var(--td-text-color-secondary);
- font-size: 12px;
- line-height: 1;
+ justify-content: center;
+ width: 26px;
+ height: 26px;
+ border: none;
+ background: transparent;
+ color: var(--td-text-color-placeholder);
cursor: pointer;
- white-space: nowrap;
- transition: background-color 0.15s, border-color 0.15s, color 0.15s;
+ border-radius: var(--td-radius-default);
+ transition: background 150ms ease, color 150ms ease;
}
-.kp-tab:hover {
- background: var(--td-bg-color-container-hover, rgba(0, 0, 0, 0.03));
+
+.kp-icon-btn:hover:not(:disabled) {
+ background: var(--td-bg-color-secondarycontainer);
+ color: var(--td-text-color-primary);
}
-.kp-tab-active {
- background: var(--td-brand-color-light, rgba(0, 102, 255, 0.08));
- border-color: var(--td-brand-color);
- color: var(--td-brand-color);
+
+.kp-icon-btn:disabled {
+ cursor: not-allowed;
+ opacity: 0.4;
}
-.kp-tab-num { font-weight: 600; }
-.kp-tab-glyph {
- font-size: 10px;
+
+.kp-icon-btn-spin :deep(.t-icon) {
+ animation: kpSpin 0.9s linear infinite;
+}
+
+@keyframes kpSpin {
+ to { transform: rotate(360deg); }
+}
+
+/* Stats row — surfaces duration / stage count / status / attempt /
+ updated-time. Spaced like a TDesign description list. */
+.kp-head-stats {
+ display: flex;
+ align-items: center;
+ flex-wrap: wrap;
+ gap: 18px;
+ margin-top: 12px;
+ font-size: 12px;
+}
+
+.kp-stat {
+ display: inline-flex;
+ align-items: baseline;
+ gap: 6px;
+ white-space: nowrap;
+}
+
+.kp-stat-end {
+ margin-left: auto;
+}
+
+.kp-stat-label {
+ color: var(--td-text-color-placeholder);
+ font-size: 11px;
+ font-weight: 500;
+ text-transform: uppercase;
+ letter-spacing: 0.5px;
+}
+
+.kp-stat-val {
+ color: var(--td-text-color-primary);
+ font-size: 12px;
+ font-weight: 500;
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+}
+
+.kp-stat-num { color: var(--td-text-color-primary); }
+.kp-stat-slash { color: var(--td-text-color-placeholder); margin: 0 1px; }
+
+.kp-meta-glyph {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 12px;
+ height: 12px;
+ font-size: 11px;
line-height: 1;
}
-.kp-tab-glyph-done { color: var(--td-success-color); }
-.kp-tab-glyph-failed { color: var(--td-error-color); }
-.kp-tab-glyph-running {
+
+.kp-glyph-done { color: var(--td-success-color); }
+.kp-glyph-failed { color: var(--td-error-color); }
+.kp-glyph-running {
color: var(--td-brand-color);
- animation: kpPulse 1.4s ease-in-out infinite;
+ animation: kpLivePulse 1.4s ease-in-out infinite;
}
-.kp-tab-glyph-unknown { color: var(--td-text-color-placeholder); }
+.kp-glyph-unknown { color: var(--td-text-color-placeholder); }
-/* ============ RULER ============ */
-.kp-ruler-row {
- display: grid;
- grid-template-columns: minmax(220px, 38%) 64px 1fr;
+/* Attempts strip */
+.kp-attempts {
+ display: flex;
+ gap: 6px;
+ margin-top: 12px;
+ overflow-x: auto;
+ padding-bottom: 2px;
+}
+
+.kp-attempt {
+ display: inline-flex;
align-items: center;
- margin-bottom: 4px;
- padding: 0 8px;
+ gap: 5px;
+ padding: 4px 10px;
+ border: 1px solid var(--td-component-border);
+ border-radius: var(--td-radius-default);
+ background: var(--td-bg-color-container);
+ color: var(--td-text-color-secondary);
+ font-size: 12px;
+ line-height: 1.4;
+ cursor: pointer;
+ white-space: nowrap;
+ transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
+}
+
+.kp-attempt:hover {
+ background: var(--td-bg-color-secondarycontainer);
+ border-color: var(--td-text-color-placeholder);
+ color: var(--td-text-color-primary);
+}
+
+.kp-attempt-active {
+ background: var(--td-brand-color);
+ color: var(--td-text-color-anti);
+ border-color: var(--td-brand-color);
+}
+
+.kp-attempt-active .kp-attempt-glyph { color: var(--td-text-color-anti) !important; }
+
+.kp-attempt-num {
+ font-weight: 600;
+ font-size: 11px;
+}
+
+.kp-attempt-glyph {
+ font-size: 9px;
+ line-height: 1;
+}
+
+/* ============== BODY (Waterfall) ============== */
+.kp-body {
+ flex: 1 1 auto;
+ min-height: 0;
+ overflow-y: auto;
+ padding: 12px 0 16px;
+ background: var(--td-bg-color-container);
+}
+
+.kp-state {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: 8px;
+ padding: 56px 0;
+ font-size: 13px;
+ color: var(--td-text-color-placeholder);
+}
+
+/* Ruler */
+.kp-ruler {
+ display: grid;
+ grid-template-columns: minmax(220px, 42%) 64px 1fr;
+ height: 24px;
+ align-items: end;
+ padding: 0 20px 6px;
+ margin-bottom: 6px;
+ position: sticky;
+ top: 0;
+ background: var(--td-bg-color-container);
+ z-index: 2;
+ border-bottom: 1px dashed var(--td-component-stroke);
}
+
.kp-ruler-spacer-name,
-.kp-ruler-spacer-meta { height: 16px; }
+.kp-ruler-spacer-meta { height: 100%; }
+
.kp-ruler-track {
position: relative;
- height: 16px;
+ height: 100%;
+ margin-right: 16px;
}
-.kp-ruler-tick {
+
+.kp-tick {
position: absolute;
- top: 0;
- transform: translateX(-50%);
+ bottom: 0;
display: flex;
flex-direction: column;
align-items: center;
- font-size: 11px;
+ transform: translateX(-50%);
+ font-size: 10px;
color: var(--td-text-color-placeholder);
}
-.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 {
+
+.kp-tick-first { transform: translateX(0); align-items: flex-start; }
+.kp-tick-last { transform: translateX(-100%); align-items: flex-end; }
+
+.kp-tick-line {
width: 1px;
- height: 4px;
- background: var(--td-component-border, #e7e7e7);
+ height: 5px;
+ background: var(--td-component-border);
}
-.kp-ruler-tick-label {
- margin-top: 1px;
- font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
+
+.kp-tick-label {
+ margin-top: 2px;
+ font-size: 10px;
+ letter-spacing: 0.02em;
}
-/* ============ ROWS GRID ============ */
+/* Rows */
.kp-rows {
display: flex;
flex-direction: column;
- background: var(--td-bg-color-container, #fff);
}
+
.kp-row {
display: grid;
- grid-template-columns: minmax(220px, 38%) 64px 1fr;
+ grid-template-columns: minmax(220px, 42%) 64px 1fr;
align-items: center;
height: 32px;
cursor: pointer;
position: relative;
- transition: background-color 0.12s, box-shadow 0.12s;
- padding: 0 8px;
+ padding: 0 20px;
+ transition: background 150ms ease;
+}
+
+.kp-row::before {
+ content: "";
+ position: absolute;
+ left: 0;
+ top: 4px;
+ bottom: 4px;
+ width: 2px;
+ background: transparent;
+ border-radius: 0 2px 2px 0;
+ transition: background 150ms ease;
+}
+
+.kp-row:hover {
+ background: var(--td-bg-color-secondarycontainer);
}
-.kp-row:hover { background: var(--td-bg-color-container-hover, rgba(0, 0, 0, 0.03)); }
+
.kp-row-active {
- background: var(--td-bg-color-container-hover, rgba(0, 0, 0, 0.04));
- box-shadow: inset 3px 0 0 var(--td-brand-color);
+ background: var(--td-bg-color-secondarycontainer);
+}
+
+.kp-row-active::before {
+ background: var(--td-brand-color);
+}
+
+.kp-row-root {
+ font-weight: 600;
}
+/* Name cell */
.kp-cell-name { min-width: 0; }
+
.kp-name-inner {
display: flex;
align-items: center;
- gap: 6px;
+ gap: 7px;
min-width: 0;
}
+
.kp-tree-toggle {
- width: 12px;
- height: 12px;
+ width: 14px;
+ height: 14px;
display: inline-flex;
align-items: center;
justify-content: center;
@@ -1028,21 +1625,28 @@ const headerStatusText = computed(() => {
padding: 0;
cursor: pointer;
color: var(--td-text-color-placeholder);
- font-size: 12px;
+ font-size: 10px;
line-height: 1;
- transition: transform 0.15s;
+ transition: transform 150ms ease, color 120ms ease;
flex-shrink: 0;
+ border-radius: var(--td-radius-small);
+}
+
+.kp-tree-toggle:hover {
+ color: var(--td-text-color-primary);
+ background: var(--td-bg-color-container-hover);
}
.kp-tree-toggle-open { transform: rotate(90deg); }
-.kp-tree-toggle-spacer { width: 12px; height: 12px; display: inline-block; flex-shrink: 0; }
+.kp-tree-toggle-spacer { width: 14px; height: 14px; display: inline-block; flex-shrink: 0; }
+
.kp-status-dot {
- width: 8px;
- height: 8px;
+ width: 7px;
+ height: 7px;
border-radius: 50%;
flex-shrink: 0;
- background: var(--td-text-color-placeholder, #c0c0c0);
- margin-right: 2px;
+ background: var(--td-text-color-placeholder);
}
+
.kp-name-text {
font-size: 12px;
color: var(--td-text-color-primary);
@@ -1050,212 +1654,608 @@ const headerStatusText = computed(() => {
text-overflow: ellipsis;
white-space: nowrap;
}
-.kp-name-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
-.kp-name-root { font-weight: 600; }
-.kp-cell-dur {
- font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
+.kp-name-mono {
+ font-family: var(--app-font-family-mono);
font-size: 11px;
+}
+
+.kp-name-root {
+ font-weight: 600;
+ font-size: 13px;
+}
+
+.kp-name-kind {
+ font-family: var(--app-font-family-mono);
+ font-size: 10px;
+ text-transform: uppercase;
+ letter-spacing: 0.5px;
color: var(--td-text-color-placeholder);
+ margin-left: auto;
+ padding-left: 8px;
+ flex-shrink: 0;
+}
+
+/* Duration cell */
+.kp-cell-dur {
+ font-size: 11px;
+ color: var(--td-text-color-secondary);
text-align: right;
- padding-right: 8px;
+ padding-right: 12px;
+ letter-spacing: 0.02em;
+}
+
+.kp-running-time {
+ color: var(--td-brand-color);
+ font-weight: 500;
}
+/* Bar cell */
.kp-cell-bar {
position: relative;
height: 32px;
+ margin-right: 16px;
+}
+
+/* Vertical "now" cursor — animates left during polling so the user can
+ visually confirm time is advancing even when the running bar grows
+ slowly toward the right edge of the trace. */
+.kp-now-marker {
+ position: absolute;
+ top: 4px;
+ bottom: 4px;
+ width: 1px;
+ background: var(--td-brand-color);
+ opacity: 0.6;
+ z-index: 1;
+ pointer-events: none;
+ transition: left 1s linear;
+}
+
+.kp-now-marker::before {
+ content: "";
+ position: absolute;
+ top: -2px;
+ left: -3px;
+ width: 7px;
+ height: 7px;
+ border-radius: 50%;
+ background: var(--td-brand-color);
+ animation: kpLivePulse 1.4s ease-in-out infinite;
}
+
.kp-bar {
position: absolute;
- top: 13px;
- height: 6px;
- border-radius: 3px;
- background: var(--td-text-color-placeholder, #c0c0c0);
+ top: 12px;
+ height: 8px;
+ border-radius: var(--td-radius-small);
+ background: var(--td-text-color-placeholder);
min-width: 2px;
+ /* Smooth left/width changes so polling-driven re-renders feel like
+ the bar is growing, not jumping. The 1s easing matches the nowTick
+ 1Hz cadence. */
+ transition: left 800ms cubic-bezier(0.2, 0.8, 0.2, 1),
+ width 800ms cubic-bezier(0.2, 0.8, 0.2, 1),
+ filter 150ms ease;
+ z-index: 2;
+}
+
+.kp-row:hover .kp-bar { filter: brightness(1.05); }
+
+.kp-bar-tip {
+ position: absolute;
+ bottom: calc(100% + 8px);
+ left: 50%;
+ transform: translateX(-50%);
+ background: var(--td-text-color-primary);
+ color: var(--td-text-color-anti);
+ font-size: 11px;
+ padding: 4px 8px;
+ border-radius: var(--td-radius-default);
+ white-space: nowrap;
+ opacity: 0;
+ pointer-events: none;
+ transition: opacity 150ms ease;
+ z-index: 10;
+ display: flex;
+ align-items: center;
+ gap: 4px;
}
+
+.kp-bar-tip-name { font-weight: 500; }
+.kp-bar-tip-sep { color: var(--td-font-white-3); }
+
+.kp-bar:hover .kp-bar-tip { opacity: 1; }
+
.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-error-color-light, rgba(207, 55, 62, 0.5));
+ border: 1px dashed var(--td-error-color);
+ height: 6px;
+ top: 13px;
}
.kp-bar-skipped {
background: var(--td-text-color-placeholder);
- opacity: 0.5;
+ opacity: 0.4;
}
.kp-bar-pending { display: none; }
.kp-bar-running {
background: var(--td-brand-color);
- background-image: linear-gradient(
- 45deg,
- rgba(255, 255, 255, 0.3) 25%,
- transparent 25%,
- transparent 50%,
- rgba(255, 255, 255, 0.3) 50%,
- rgba(255, 255, 255, 0.3) 75%,
- transparent 75%,
- transparent
+}
+
+/* Indeterminate sweep on the running bar — gives obvious motion while
+ waiting for the next poll. */
+.kp-bar-running-anim {
+ position: relative;
+ overflow: hidden;
+}
+.kp-bar-running-anim::after {
+ content: "";
+ position: absolute;
+ inset: 0;
+ background: linear-gradient(
+ 90deg,
+ transparent 0%,
+ rgba(255, 255, 255, 0.5) 50%,
+ transparent 100%
);
- background-size: 12px 12px;
- animation: kpStripes 0.8s linear infinite;
+ animation: kpSweep 1.6s linear infinite;
}
+
.kp-bar-placeholder {
- right: 0;
+ right: 4px;
top: 13px;
- height: 4px;
- width: 12px;
+ height: 6px;
+ width: 14px;
background: transparent;
- border: 1px dashed var(--td-component-border, #e7e7e7);
- border-radius: 2px;
+ border: 1px dashed var(--td-component-border);
+ border-radius: var(--td-radius-small);
+ position: absolute;
+}
+
+.kp-bar-offset {
+ position: absolute;
+ bottom: -1px;
+ font-size: 9px;
+ color: var(--td-text-color-placeholder);
+ pointer-events: none;
+ white-space: nowrap;
+ transform: translateX(-50%);
+ opacity: 0;
+ transition: opacity 150ms ease;
}
-@keyframes kpStripes {
- from { background-position: 0 0; }
- to { background-position: 12px 0; }
+.kp-row:hover .kp-bar-offset,
+.kp-row-active .kp-bar-offset { opacity: 1; }
+
+@keyframes kpSweep {
+ 0% { transform: translateX(-100%); }
+ 100% { transform: translateX(100%); }
}
-/* ============ STATUS DOTS (shared) ============ */
+/* Status dots (shared with compact mode) */
.kp-dot-done { background: var(--td-success-color); }
.kp-dot-running {
background: var(--td-brand-color);
- animation: kpPulse 1.4s ease-in-out infinite;
+ animation: kpLivePulse 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);
+ border: 1px dashed var(--td-text-color-placeholder);
}
-.kp-dot-skipped { background: var(--td-text-color-placeholder, #c0c0c0); opacity: 0.5; }
+.kp-dot-skipped { background: var(--td-text-color-placeholder); opacity: 0.4; }
.kp-dot-pending {
background: transparent;
- border: 1px solid var(--td-component-border, #dcdcdc);
+ border: 1px solid var(--td-component-border);
}
.kp-dot-placeholder {
background: transparent;
- border: 1px dashed var(--td-component-border, #dcdcdc);
+ border: 1px dashed var(--td-component-border);
}
+.kp-dot-completed { background: var(--td-success-color); }
+.kp-dot-processing { background: var(--td-brand-color); animation: kpLivePulse 1.4s ease-in-out infinite; }
+.kp-dot-unknown { background: var(--td-text-color-placeholder); }
-@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 4px transparent; }
+/* Last error block */
+.kp-last-error {
+ margin: 14px 20px 4px;
+ display: flex;
+ background: var(--td-error-color-light);
+ border-radius: var(--td-radius-medium);
+ overflow: hidden;
+ border: 1px solid var(--td-error-color-3);
}
-/* ============ DRAWER ============ */
-.kp-drawer {
- position: absolute;
- top: 0;
- right: 0;
- bottom: 0;
- width: 42%;
- min-width: 320px;
- max-width: 480px;
- background: var(--td-bg-color-page, #fff);
- border-left: 1px solid var(--td-component-border, #e7e7e7);
- box-shadow: -4px 0 16px rgba(0, 0, 0, 0.06);
- transform: translateX(100%);
- transition: transform 200ms ease;
- display: flex;
- flex-direction: column;
- z-index: 2;
+.kp-last-error-bar {
+ width: 3px;
+ background: var(--td-error-color);
+ flex-shrink: 0;
}
-.kp-drawer-open { transform: translateX(0); }
-.kp-drawer-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- gap: 8px;
+.kp-last-error-body {
+ flex: 1;
padding: 10px 14px;
- border-bottom: 1px solid var(--td-component-border, #e7e7e7);
-}
-.kp-drawer-title {
- display: flex;
- align-items: center;
- gap: 8px;
min-width: 0;
}
-.kp-drawer-dot { width: 10px; height: 10px; }
-.kp-drawer-name {
- font-weight: 600;
- font-size: 13px;
- color: var(--td-text-color-primary);
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
-}
-.kp-drawer-meta {
+
+.kp-last-error-row {
display: flex;
align-items: center;
gap: 8px;
+ margin-bottom: 4px;
}
-.kp-drawer-close {
- border: none;
- background: transparent;
- cursor: pointer;
- font-size: 18px;
- line-height: 1;
- color: var(--td-text-color-placeholder);
- padding: 0 4px;
-}
-.kp-drawer-close:hover { color: var(--td-text-color-primary); }
-.kp-drawer-body {
- flex: 1;
- overflow-y: auto;
- padding: 12px 16px;
- display: flex;
- flex-direction: column;
- gap: 14px;
-}
-.kp-drawer-footer {
- padding: 10px 14px;
- border-top: 1px solid var(--td-component-border, #e7e7e7);
- display: flex;
- justify-content: flex-end;
- background: var(--td-bg-color-container, #fff);
+.kp-last-error-glyph {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 16px;
+ height: 16px;
+ background: var(--td-error-color);
+ color: var(--td-text-color-anti);
+ border-radius: 50%;
+ font-size: 11px;
+ font-weight: 700;
+ flex-shrink: 0;
}
-.kp-section { display: flex; flex-direction: column; gap: 6px; }
-.kp-section-title {
+.kp-last-error-title {
+ font-weight: 600;
+ font-size: 12px;
+ color: var(--td-error-color);
+}
+
+.kp-last-error-code {
+ font-size: 10px;
+ background: var(--td-error-color);
+ color: var(--td-text-color-anti);
+ padding: 1px 6px;
+ border-radius: var(--td-radius-small);
+ margin-left: auto;
+}
+
+.kp-last-error-suggestion {
+ font-size: 12px;
+ color: var(--td-text-color-secondary);
+ margin-bottom: 4px;
+}
+
+.kp-last-error-raw {
font-size: 11px;
+ color: var(--td-text-color-placeholder);
+ white-space: pre-wrap;
+ word-break: break-word;
+}
+
+/* ============== DETAIL PANEL ============== */
+.kp-detail {
+ flex: 0 0 auto;
+ display: flex;
+ flex-direction: column;
+ border-top: 1px solid var(--td-component-stroke);
+ background: var(--td-bg-color-container);
+ height: 0;
+ overflow: hidden;
+ transition: height 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
+}
+
+.kp-detail-open {
+ height: 50%;
+ min-height: 320px;
+}
+
+.kp-detail-head {
+ flex: 0 0 auto;
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 8px;
+ padding: 12px 20px 10px;
+ border-bottom: 1px solid var(--td-component-stroke);
+}
+
+.kp-detail-title {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ min-width: 0;
+}
+
+.kp-detail-dot {
+ width: 8px;
+ height: 8px;
+ flex-shrink: 0;
+}
+
+.kp-detail-name {
+ font-weight: 600;
+ font-size: 13px;
+ color: var(--td-text-color-primary);
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ min-width: 0;
+}
+
+.kp-detail-kind {
+ font-family: var(--app-font-family-mono);
+ font-size: 10px;
text-transform: uppercase;
- letter-spacing: 0.06em;
+ letter-spacing: 0.5px;
color: var(--td-text-color-placeholder);
+ flex-shrink: 0;
+}
+
+/* Status chip — soft tinted background using the brand/error/success
+ palette. Matches TDesign tag aesthetics. */
+.kp-status-chip {
+ display: inline-flex;
+ align-items: center;
+ padding: 1px 8px;
+ border-radius: var(--td-radius-default);
+ font-size: 11px;
+ font-weight: 500;
+ background: var(--td-bg-color-component);
+ color: var(--td-text-color-primary);
+ flex-shrink: 0;
+}
+
+.kp-chip-done { background: var(--td-success-color-light); color: var(--td-success-color); }
+.kp-chip-running { background: var(--td-brand-color-light); color: var(--td-brand-color); }
+.kp-chip-failed { background: var(--td-error-color-light); color: var(--td-error-color); }
+.kp-chip-cancelled { background: var(--td-bg-color-component); color: var(--td-text-color-secondary); }
+.kp-chip-skipped { background: var(--td-bg-color-component); color: var(--td-text-color-placeholder); }
+.kp-chip-pending { background: var(--td-bg-color-component); color: var(--td-text-color-secondary); }
+
+.kp-detail-actions {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+}
+
+/* Tabs */
+.kp-tabs {
+ flex: 0 0 auto;
+ display: flex;
+ gap: 0;
+ padding: 0 20px;
+ border-bottom: 1px solid var(--td-component-stroke);
+ background: var(--td-bg-color-container);
+}
+
+.kp-tab {
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+ padding: 9px 14px 10px;
+ border: none;
+ background: transparent;
+ color: var(--td-text-color-secondary);
+ font-size: 13px;
+ cursor: pointer;
+ position: relative;
+ transition: color 150ms ease;
+}
+
+.kp-tab:hover { color: var(--td-text-color-primary); }
+
+.kp-tab-active {
+ color: var(--td-text-color-primary);
font-weight: 600;
}
-.kp-kv-grid {
+
+.kp-tab-active::after {
+ content: "";
+ position: absolute;
+ left: 14px;
+ right: 14px;
+ bottom: -1px;
+ height: 2px;
+ background: var(--td-brand-color);
+ border-radius: 2px 2px 0 0;
+}
+
+.kp-tab-empty { color: var(--td-text-color-placeholder); }
+
+.kp-detail-body {
+ flex: 1 1 auto;
+ overflow-y: auto;
+ padding: 16px 20px 18px;
display: flex;
flex-direction: column;
+ gap: 16px;
+}
+
+.kp-detail-empty {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ padding: 48px 0;
+ font-size: 13px;
+ color: var(--td-text-color-placeholder);
+}
+
+.kp-detail-hint {
+ font-size: 12px;
+ color: var(--td-text-color-secondary);
+ padding: 10px 12px;
+ background: var(--td-bg-color-secondarycontainer);
+ border-radius: var(--td-radius-medium);
+ border-left: 2px solid var(--td-component-border);
+}
+
+/* Sections */
+.kp-section {
+ display: flex;
+ flex-direction: column;
+ gap: 8px;
+}
+
+.kp-section-title {
+ font-size: 11px;
+ font-weight: 500;
+ text-transform: uppercase;
+ letter-spacing: 0.5px;
+ color: var(--td-text-color-secondary);
+}
+
+.kp-section-bar {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 8px;
+}
+
+.kp-section-action {
+ display: inline-flex;
+ align-items: center;
gap: 4px;
- background: var(--td-bg-color-secondarycontainer, #fafafa);
- border-radius: 6px;
- padding: 8px 10px;
+ border: 1px solid var(--td-component-border);
+ background: var(--td-bg-color-container);
+ color: var(--td-text-color-secondary);
+ font-size: 11px;
+ padding: 3px 8px;
+ border-radius: var(--td-radius-default);
+ cursor: pointer;
+ transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}
+
+.kp-section-action:hover {
+ background: var(--td-brand-color);
+ color: var(--td-text-color-anti);
+ border-color: var(--td-brand-color);
+}
+
+.kp-section-action:hover :deep(.t-icon) { color: var(--td-text-color-anti); }
+
+/* KV grid — TDesign description list aesthetic. White card on the gray
+ page bg, soft 1px row separators, key/label color hierarchy. */
+.kp-kv {
+ display: flex;
+ flex-direction: column;
+ border: 1px solid var(--td-component-stroke);
+ border-radius: var(--td-radius-medium);
+ background: var(--td-bg-color-container);
+ overflow: hidden;
+}
+
.kp-kv-row {
display: grid;
- grid-template-columns: 110px 1fr;
+ grid-template-columns: 130px 1fr;
gap: 12px;
- align-items: baseline;
+ align-items: center;
font-size: 12px;
min-width: 0;
+ padding: 8px 12px;
+ background: var(--td-bg-color-container);
+}
+
+.kp-kv-row + .kp-kv-row {
+ border-top: 1px solid var(--td-bg-color-secondarycontainer);
}
+
+.kp-kv-row-multiline {
+ align-items: flex-start;
+}
+
.kp-kv-key {
- color: var(--td-text-color-placeholder);
+ color: var(--td-text-color-secondary);
font-size: 11px;
+ font-weight: 500;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
+
.kp-kv-val {
color: var(--td-text-color-primary);
overflow-wrap: anywhere;
word-break: break-word;
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ min-width: 0;
+}
+
+.kp-kv-truncate {
+ overflow: hidden;
+}
+
+.kp-kv-truncate .kp-kv-text {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ min-width: 0;
+ flex: 1;
+}
+
+.kp-kv-multiline {
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+ align-items: stretch;
+}
+
+.kp-kv-scalar { font-size: 12px; }
+
+.kp-kv-running {
+ color: var(--td-brand-color);
+ font-style: italic;
+ font-family: var(--app-font-family);
+ font-size: 11px;
+}
+
+.kp-kv-tag-live {
+ display: inline-block;
+ margin-left: 6px;
+ padding: 0 6px;
+ font-size: 9px;
+ font-weight: 600;
+ text-transform: uppercase;
+ letter-spacing: 0.5px;
+ background: var(--td-brand-color-light);
+ color: var(--td-brand-color);
+ border-radius: var(--td-radius-small);
+ font-family: var(--app-font-family);
+}
+
+.kp-kv-copy {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 18px;
+ height: 18px;
+ border: none;
+ background: transparent;
+ color: var(--td-text-color-placeholder);
+ cursor: pointer;
+ border-radius: var(--td-radius-small);
+ flex-shrink: 0;
+}
+
+.kp-kv-copy:hover {
+ background: var(--td-bg-color-container-hover);
+ color: var(--td-brand-color);
+}
+
+.kp-mono {
+ font-family: var(--app-font-family-mono);
+ font-size: 11px;
+ letter-spacing: 0;
+}
+
+.kp-bool-true { color: var(--td-success-color); font-weight: 500; }
+.kp-bool-false { color: var(--td-error-color); font-weight: 500; }
+
+.kp-kv-collapsible {
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+ min-width: 0;
}
-.kp-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
-.kp-bool-true { color: var(--td-success-color); }
-.kp-bool-false { color: var(--td-error-color); }
-.kp-kv-collapsible { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kp-kv-toggle {
border: none;
background: transparent;
@@ -1269,150 +2269,165 @@ const headerStatusText = computed(() => {
font-size: 12px;
flex-wrap: wrap;
}
-.kp-kv-summary {
- font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
- font-size: 11px;
- color: var(--td-text-color-secondary);
-}
+
+.kp-kv-summary { color: var(--td-text-color-secondary); }
+
.kp-kv-toggle-label {
font-size: 11px;
color: var(--td-brand-color);
+ font-weight: 500;
}
+
.kp-kv-toggle:hover .kp-kv-toggle-label { text-decoration: underline; }
-.kp-status-chip {
- display: inline-block;
- padding: 1px 8px;
- border-radius: 10px;
- font-size: 11px;
- background: var(--td-bg-color-component, #eee);
+/* Stage breakdown table inside root overview */
+.kp-breakdown {
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+ border: 1px solid var(--td-component-stroke);
+ border-radius: var(--td-radius-medium);
+ background: var(--td-bg-color-container);
+ padding: 10px 12px;
+}
+
+.kp-breakdown-row {
+ display: grid;
+ grid-template-columns: 110px 1fr 64px;
+ gap: 10px;
+ align-items: center;
+ font-size: 12px;
+}
+
+.kp-breakdown-label {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
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-breakdown-track {
+ position: relative;
+ height: 6px;
+ background: var(--td-bg-color-secondarycontainer);
+ border-radius: var(--td-radius-small);
+ overflow: hidden;
+}
+
+.kp-breakdown-bar {
+ position: absolute;
+ left: 0;
+ top: 0;
+ bottom: 0;
+ border-radius: var(--td-radius-small);
+ transition: width 800ms cubic-bezier(0.2, 0.8, 0.2, 1);
+}
+
+.kp-breakdown-row.kp-breakdown-pending .kp-breakdown-bar { display: none; }
+
+.kp-breakdown-dur {
+ text-align: right;
+ color: var(--td-text-color-secondary);
+}
+
+/* Error block in overview */
.kp-error-block {
+ border: 1px solid var(--td-error-color-3);
+ border-radius: var(--td-radius-medium);
+ background: var(--td-error-color-light);
padding: 10px 12px;
- border: 1px solid var(--td-error-color);
- border-radius: 6px;
- background: rgba(217, 48, 37, 0.05);
display: flex;
flex-direction: column;
- gap: 6px;
+ gap: 8px;
}
-.kp-error-title {
+
+.kp-error-head {
display: flex;
align-items: center;
- gap: 6px;
- color: var(--td-error-color);
+ gap: 8px;
+}
+
+.kp-error-glyph {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 16px;
+ height: 16px;
+ background: var(--td-error-color);
+ color: var(--td-text-color-anti);
+ border-radius: 50%;
+ font-size: 11px;
+ font-weight: 700;
+ flex-shrink: 0;
+}
+
+.kp-error-title {
font-weight: 600;
font-size: 12px;
+ color: var(--td-error-color);
}
+
.kp-error-code {
- font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
- font-size: 11px;
- background: rgba(217, 48, 37, 0.12);
- border-radius: 999px;
- padding: 1px 8px;
margin-left: auto;
+ font-size: 10px;
+ background: var(--td-error-color);
+ color: var(--td-text-color-anti);
+ padding: 1px 6px;
+ border-radius: var(--td-radius-small);
}
+
.kp-error-msg {
- font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
+ margin: 0;
font-size: 11px;
color: var(--td-text-color-secondary);
white-space: pre-wrap;
word-break: break-word;
+ max-height: 160px;
+ overflow: auto;
+ padding: 8px 10px;
+ background: var(--td-bg-color-container);
+ border-radius: var(--td-radius-default);
+ border: 1px solid var(--td-component-stroke);
}
+/* JSON viewer */
.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;
+ margin: 0;
+ padding: 10px 12px;
+ background: var(--td-bg-color-secondarycontainer);
+ border: 1px solid var(--td-component-stroke);
+ border-radius: var(--td-radius-medium);
+ max-height: 360px;
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);
+ line-height: 1.6;
}
-/* ============ EMPTY / LOADING ============ */
-.kp-empty {
- font-size: 12px;
- color: var(--td-text-color-placeholder);
- padding: 20px 0;
- text-align: center;
-}
-.kp-loading {
- display: flex;
- justify-content: center;
- padding: 24px 0;
-}
-
-/* ============ LAST-ERROR (failed only) ============ */
-.kp-last-error {
- margin-top: 12px;
- padding: 10px 12px;
- background: var(--td-bg-color-component);
- border-left: 3px solid var(--td-error-color);
- border-radius: 4px;
-}
-.kp-last-error-row {
- display: flex;
- align-items: flex-start;
- gap: 8px;
-}
-.kp-last-error-icon {
- color: var(--td-error-color);
- flex-shrink: 0;
- margin-top: 2px;
-}
-.kp-last-error-body {
- flex: 1 1 auto;
- min-width: 0;
-}
-.kp-last-error-title {
- font-weight: 600;
- color: var(--td-text-color-primary);
-}
-.kp-last-error-suggestion {
- font-size: 12px;
- color: var(--td-text-color-secondary);
- margin-top: 2px;
-}
-.kp-last-error-raw {
- font-size: 11px;
- color: var(--td-text-color-placeholder);
- margin-top: 4px;
- font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
- white-space: pre-wrap;
- word-break: break-word;
-}
+.kp-json-large { max-height: 480px; }
-/* ============ COMPACT MODE (untouched) ============ */
+/* ============== COMPACT MODE (untouched) ============== */
.kp-compact {
max-width: 320px;
+ height: auto;
}
+
.kp-compact-row {
display: flex;
align-items: center;
gap: 6px;
}
+
.kp-dot {
width: 8px;
height: 8px;
border-radius: 50%;
- background: var(--td-text-color-placeholder, #c0c0c0);
+ background: var(--td-text-color-placeholder);
display: inline-block;
}
+
.kp-compact-caption {
margin-top: 4px;
font-size: 12px;
@@ -1421,6 +2436,7 @@ const headerStatusText = computed(() => {
overflow: hidden;
text-overflow: ellipsis;
}
+
.kp-stage-emph {
color: var(--td-brand-color);
font-weight: 600;
diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts
index 9029c6753..713a22b03 100755
--- a/frontend/src/i18n/locales/en-US.ts
+++ b/frontend/src/i18n/locales/en-US.ts
@@ -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',
diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts
index d3ea599a8..572b51245 100755
--- a/frontend/src/i18n/locales/ko-KR.ts
+++ b/frontend/src/i18n/locales/ko-KR.ts
@@ -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: "문서 파싱",
diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts
index 169ad0d4e..77a5ee517 100755
--- a/frontend/src/i18n/locales/zh-CN.ts
+++ b/frontend/src/i18n/locales/zh-CN.ts
@@ -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: "文档解析",
diff --git a/internal/application/service/extract.go b/internal/application/service/extract.go
index 0e678bb02..dd64b0a60 100644
--- a/internal/application/service/extract.go
+++ b/internal/application/service/extract.go
@@ -87,15 +87,21 @@ func NewChunkExtractTask(
tenantID uint64,
chunkID string,
modelID string,
+ knowledgeID string,
+ attempt int,
+ chunkIndex int,
) error {
if strings.ToLower(os.Getenv("NEO4J_ENABLE")) != "true" {
logger.Warn(ctx, "NEO4J is not enabled, skip chunk extract task")
return nil
}
taskPayload := types.ExtractChunkPayload{
- TenantID: tenantID,
- ChunkID: chunkID,
- ModelID: modelID,
+ TenantID: tenantID,
+ ChunkID: chunkID,
+ ModelID: modelID,
+ KnowledgeID: knowledgeID,
+ Attempt: attempt,
+ ChunkIndex: chunkIndex,
}
langfuse.InjectTracing(ctx, &taskPayload)
payload, err := json.Marshal(taskPayload)
@@ -150,6 +156,10 @@ type ChunkExtractService struct {
knowledgeBaseRepo interfaces.KnowledgeBaseRepository
chunkRepo interfaces.ChunkRepository
graphEngine interfaces.RetrieveGraphRepository
+ // spanTracker records this graph-extract task's subspan under the
+ // parent attempt's postprocess stage so the trace viewer shows real
+ // per-chunk graph extraction time rather than the upstream's enqueue.
+ spanTracker SpanTracker
}
// NewChunkExtractService creates a new chunk extract service
@@ -159,20 +169,25 @@ func NewChunkExtractService(
knowledgeBaseRepo interfaces.KnowledgeBaseRepository,
chunkRepo interfaces.ChunkRepository,
graphEngine interfaces.RetrieveGraphRepository,
+ spanTracker SpanTracker,
) interfaces.TaskHandler {
- // generator := chatpipeline.NewQAPromptGenerator(chatpipeline.NewFormater(), config.ExtractManager.ExtractGraph)
- // ctx := context.Background()
- // logger.Debugf(ctx, "chunk extract system prompt: %s", generator.System(ctx))
- // logger.Debugf(ctx, "chunk extract user prompt: %s", generator.User(ctx, "demo"))
return &ChunkExtractService{
template: config.ExtractManager.ExtractGraph,
modelService: modelService,
knowledgeBaseRepo: knowledgeBaseRepo,
chunkRepo: chunkRepo,
graphEngine: graphEngine,
+ spanTracker: spanTracker,
}
}
+func (s *ChunkExtractService) tracker() SpanTracker {
+ if s.spanTracker == nil {
+ return noopSpanTracker{}
+ }
+ return s.spanTracker
+}
+
// Handle handles the chunk extraction task
func (s *ChunkExtractService) Handle(ctx context.Context, t *asynq.Task) error {
var p types.ExtractChunkPayload
@@ -184,24 +199,59 @@ func (s *ChunkExtractService) Handle(ctx context.Context, t *asynq.Task) error {
ctx = logger.WithField(ctx, "extract", p.ChunkID)
ctx = context.WithValue(ctx, types.TenantIDContextKey, p.TenantID)
+ // Open a postprocess subspan keyed by chunk ordinal so the trace
+ // shows real per-chunk graph extraction time. Skipped silently when
+ // upstream didn't pass the parent attempt (legacy in-flight tasks)
+ // or when the postprocess stage span isn't found.
+ var gSpan *Span
+ if p.KnowledgeID != "" && p.Attempt > 0 {
+ parent := s.tracker().LookupStage(ctx, p.KnowledgeID, p.Attempt, types.StagePostProcess)
+ if parent != nil {
+ gSpan = s.tracker().BeginSubSpan(ctx, parent,
+ fmt.Sprintf("postprocess.graph.chunk[%d]", p.ChunkIndex),
+ types.SpanKindSubSpan,
+ types.JSONMap{
+ "chunk_id": p.ChunkID,
+ "chunk_index": p.ChunkIndex,
+ "model_id": p.ModelID,
+ })
+ }
+ }
+ var handleErr error
+ graphOut := types.JSONMap{}
+ defer func() {
+ if gSpan == nil {
+ return
+ }
+ if handleErr != nil {
+ s.tracker().FailSpan(ctx, gSpan, "GRAPH_EXTRACT_FAILED", handleErr.Error(), handleErr)
+ } else {
+ s.tracker().EndSpan(ctx, gSpan, graphOut)
+ }
+ }()
+
chunk, err := s.chunkRepo.GetChunkByID(ctx, p.TenantID, p.ChunkID)
if err != nil {
logger.Errorf(ctx, "failed to get chunk: %v", err)
+ handleErr = err
return err
}
kb, err := s.knowledgeBaseRepo.GetKnowledgeBaseByID(ctx, chunk.KnowledgeBaseID)
if err != nil {
logger.Errorf(ctx, "failed to get knowledge base: %v", err)
+ handleErr = err
return err
}
if kb.ExtractConfig == nil {
logger.Warnf(ctx, "failed to get extract config")
+ graphOut["skipped"] = "no_extract_config"
return err
}
chatModel, err := s.modelService.GetChatModel(ctx, p.ModelID)
if err != nil {
logger.Errorf(ctx, "failed to get chat model: %v", err)
+ handleErr = err
return err
}
@@ -219,12 +269,14 @@ func (s *ChunkExtractService) Handle(ctx context.Context, t *asynq.Task) error {
extractor := chatpipeline.NewExtractor(chatModel, template)
graph, err := extractor.Extract(ctx, chunk.Content)
if err != nil {
+ handleErr = err
return err
}
chunk, err = s.chunkRepo.GetChunkByID(ctx, p.TenantID, p.ChunkID)
if err != nil {
logger.Warnf(ctx, "graph ignore chunk %s: %v", p.ChunkID, err)
+ graphOut["skipped"] = "chunk_disappeared"
return nil
}
@@ -236,8 +288,11 @@ func (s *ChunkExtractService) Handle(ctx context.Context, t *asynq.Task) error {
[]*types.GraphData{graph},
); err != nil {
logger.Errorf(ctx, "failed to add graph: %v", err)
+ handleErr = err
return err
}
+ graphOut["nodes_added"] = len(graph.Node)
+ graphOut["relations_added"] = len(graph.Relation)
return nil
}
diff --git a/internal/application/service/knowledge.go b/internal/application/service/knowledge.go
index 38db807ce..6eb0b51d0 100644
--- a/internal/application/service/knowledge.go
+++ b/internal/application/service/knowledge.go
@@ -219,6 +219,48 @@ func (s *knowledgeService) skipStage(ctx context.Context, kid, name, reason stri
s.tracker().SkipSpan(ctx, span, reason)
}
+// beginPostprocessSubspan opens a subspan beneath the postprocess stage
+// span for (kid, attempt). Async post-pipeline tasks (summary, question,
+// graph, wiki) call this on entry so their actual processing time shows
+// up in the trace tree under postprocess instead of the stage looking
+// like an instant ~10ms enqueue.
+//
+// Returns nil when:
+// - attempt <= 0 (legacy in-flight task without span tracking)
+// - the postprocess stage span is missing (parse predates tracker, or
+// the upstream BeginStage call failed)
+//
+// Callers must tolerate nil — pair every begin with a deferred
+// endPostprocessSubspan / failPostprocessSubspan that no-ops on nil.
+func (s *knowledgeService) beginPostprocessSubspan(
+ ctx context.Context, knowledgeID string, attempt int, name string, input types.JSONMap,
+) *Span {
+ if attempt <= 0 || knowledgeID == "" || name == "" {
+ return nil
+ }
+ parent := s.tracker().LookupStage(ctx, knowledgeID, attempt, types.StagePostProcess)
+ if parent == nil {
+ return nil
+ }
+ return s.tracker().BeginSubSpan(ctx, parent, name, types.SpanKindSubSpan, input)
+}
+
+func (s *knowledgeService) endPostprocessSubspan(ctx context.Context, span *Span, output types.JSONMap) {
+ if span == nil {
+ return
+ }
+ s.tracker().EndSpan(ctx, span, output)
+}
+
+func (s *knowledgeService) failPostprocessSubspan(
+ ctx context.Context, span *Span, code, msg string, err error,
+) {
+ if span == nil {
+ return
+ }
+ s.tracker().FailSpan(ctx, span, code, msg, err)
+}
+
// getParserEngineOverridesFromContext returns parser engine overrides from tenant in context (e.g. MinerU endpoint, API key).
// Used when building document ReadRequest so UI-configured values take precedence over env.
func (s *knowledgeService) getParserEngineOverridesFromContext(ctx context.Context) map[string]string {
diff --git a/internal/application/service/knowledge_post_process.go b/internal/application/service/knowledge_post_process.go
index 887349d60..0d808f9e1 100644
--- a/internal/application/service/knowledge_post_process.go
+++ b/internal/application/service/knowledge_post_process.go
@@ -143,12 +143,12 @@ func (s *KnowledgePostProcessService) Handle(ctx context.Context, task *asynq.Ta
enqueuedSummary := false
enqueuedQuestion := false
if len(textChunks) > 0 {
- s.enqueueSummaryGenerationTask(ctx, payload)
+ s.enqueueSummaryGenerationTask(ctx, payload, attempt)
enqueuedSummary = true
// Question generation only makes sense for RAG indexing (improves chunk recall).
// Skip when only Wiki/Graph is enabled without vector/keyword search.
if kb.NeedsEmbeddingModel() {
- enqueuedQuestion = s.enqueueQuestionGenerationIfEnabled(ctx, payload, kb)
+ enqueuedQuestion = s.enqueueQuestionGenerationIfEnabled(ctx, payload, kb, attempt)
}
}
@@ -156,8 +156,9 @@ func (s *KnowledgePostProcessService) Handle(ctx context.Context, task *asynq.Ta
enqueuedGraph := false
if kb.IsGraphEnabled() {
logger.Infof(ctx, "[KnowledgePostProcess] Spawning Graph RAG extract tasks for %d text-like chunks", len(textChunks))
- for _, chunk := range textChunks {
- err := NewChunkExtractTask(ctx, s.taskEnqueuer, payload.TenantID, chunk.ID, kb.SummaryModelID)
+ for i, chunk := range textChunks {
+ err := NewChunkExtractTask(ctx, s.taskEnqueuer, payload.TenantID, chunk.ID, kb.SummaryModelID,
+ payload.KnowledgeID, attempt, i)
if err != nil {
logger.Errorf(ctx, "[KnowledgePostProcess] Failed to create chunk extract task for %s: %v", chunk.ID, err)
}
@@ -190,7 +191,7 @@ func (s *KnowledgePostProcessService) Handle(ctx context.Context, task *asynq.Ta
return nil
}
-func (s *KnowledgePostProcessService) enqueueSummaryGenerationTask(ctx context.Context, payload types.KnowledgePostProcessPayload) {
+func (s *KnowledgePostProcessService) enqueueSummaryGenerationTask(ctx context.Context, payload types.KnowledgePostProcessPayload, attempt int) {
if s.taskEnqueuer == nil {
return
}
@@ -200,6 +201,7 @@ func (s *KnowledgePostProcessService) enqueueSummaryGenerationTask(ctx context.C
KnowledgeBaseID: payload.KnowledgeBaseID,
KnowledgeID: payload.KnowledgeID,
Language: payload.Language,
+ Attempt: attempt,
}
langfuse.InjectTracing(ctx, &taskPayload)
payloadBytes, err := json.Marshal(taskPayload)
@@ -216,7 +218,7 @@ func (s *KnowledgePostProcessService) enqueueSummaryGenerationTask(ctx context.C
}
}
-func (s *KnowledgePostProcessService) enqueueQuestionGenerationIfEnabled(ctx context.Context, payload types.KnowledgePostProcessPayload, kb *types.KnowledgeBase) bool {
+func (s *KnowledgePostProcessService) enqueueQuestionGenerationIfEnabled(ctx context.Context, payload types.KnowledgePostProcessPayload, kb *types.KnowledgeBase, attempt int) bool {
if s.taskEnqueuer == nil {
return false
}
@@ -239,6 +241,7 @@ func (s *KnowledgePostProcessService) enqueueQuestionGenerationIfEnabled(ctx con
KnowledgeID: payload.KnowledgeID,
QuestionCount: questionCount,
Language: payload.Language,
+ Attempt: attempt,
}
langfuse.InjectTracing(ctx, &taskPayload)
payloadBytes, err := json.Marshal(taskPayload)
diff --git a/internal/application/service/knowledge_process.go b/internal/application/service/knowledge_process.go
index dffed0e16..683aa7618 100644
--- a/internal/application/service/knowledge_process.go
+++ b/internal/application/service/knowledge_process.go
@@ -887,15 +887,37 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
ctx = context.WithValue(ctx, types.LanguageContextKey, payload.Language)
}
+ // Open a subspan under the parent attempt's postprocess stage so the
+ // trace surface shows the real summary-generation duration (LLM call
+ // + chunk write + index) instead of just the upstream's enqueue time.
+ // Closes via the deferred handler below — every return path lands in
+ // the defer, including the early returns ahead.
+ span := s.beginPostprocessSubspan(ctx, payload.KnowledgeID, payload.Attempt, "postprocess.summary",
+ types.JSONMap{"language": payload.Language})
+ var summaryErr error
+ summaryOut := types.JSONMap{}
+ defer func() {
+ if span == nil {
+ return
+ }
+ if summaryErr != nil {
+ s.failPostprocessSubspan(ctx, span, "SUMMARY_FAILED", summaryErr.Error(), summaryErr)
+ } else {
+ s.endPostprocessSubspan(ctx, span, summaryOut)
+ }
+ }()
+
// Get knowledge base
kb, err := s.kbService.GetKnowledgeBaseByID(ctx, payload.KnowledgeBaseID)
if err != nil {
logger.Errorf(ctx, "Failed to get knowledge base: %v", err)
+ summaryErr = err
return nil
}
if kb.SummaryModelID == "" {
logger.Warn(ctx, "Knowledge base summary model ID is empty, skipping summary generation")
+ summaryOut["skipped"] = "no_summary_model"
return nil
}
@@ -903,6 +925,7 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
knowledge, err := s.repo.GetKnowledgeByID(ctx, payload.TenantID, payload.KnowledgeID)
if err != nil {
logger.Errorf(ctx, "Failed to get knowledge: %v", err)
+ summaryErr = err
return nil
}
@@ -927,6 +950,7 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
if err != nil {
logger.Errorf(ctx, "Failed to get chunks: %v", err)
markSummaryFailed()
+ summaryErr = err
return nil
}
@@ -937,6 +961,7 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
textChunks = append(textChunks, chunk)
}
}
+ summaryOut["text_chunks"] = len(textChunks)
if len(textChunks) == 0 {
logger.Infof(ctx, "No text chunks found for knowledge: %s", payload.KnowledgeID)
@@ -944,6 +969,7 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
knowledge.SummaryStatus = types.SummaryStatusCompleted
knowledge.UpdatedAt = time.Now()
s.repo.UpdateKnowledge(ctx, knowledge)
+ summaryOut["skipped"] = "no_text_chunks"
return nil
}
@@ -957,6 +983,7 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
if err != nil {
logger.Errorf(ctx, "Failed to get chat model: %v", err)
markSummaryFailed()
+ summaryErr = err
return fmt.Errorf("failed to get chat model: %w", err)
}
@@ -974,8 +1001,11 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
knowledge.UpdatedAt = time.Now()
if updateErr := s.repo.UpdateKnowledge(ctx, knowledge); updateErr != nil {
logger.Errorf(ctx, "Failed to mark summary as failed: %v", updateErr)
+ summaryErr = updateErr
return fmt.Errorf("failed to update knowledge: %w", updateErr)
}
+ summaryOut["fallback"] = "insufficient_content"
+ summaryErr = err
return nil
}
// For other errors (LLM API issues etc.), fall back to the first chunk.
@@ -987,6 +1017,7 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
summary = string(runes[:500])
}
}
+ summaryOut["fallback"] = "first_chunk"
}
}
@@ -994,8 +1025,10 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
knowledge.Description = summary
knowledge.SummaryStatus = types.SummaryStatusCompleted
knowledge.UpdatedAt = time.Now()
+ summaryOut["summary_chars"] = len([]rune(summary))
if err := s.repo.UpdateKnowledge(ctx, knowledge); err != nil {
logger.Errorf(ctx, "Failed to update knowledge description: %v", err)
+ summaryErr = err
return fmt.Errorf("failed to update knowledge: %w", err)
}
@@ -1034,6 +1067,7 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
// Save summary chunk
if err := s.chunkService.CreateChunks(ctx, []*types.Chunk{summaryChunk}); err != nil {
logger.Errorf(ctx, "Failed to create summary chunk: %v", err)
+ summaryErr = err
return fmt.Errorf("failed to create summary chunk: %w", err)
}
@@ -1041,6 +1075,7 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
tenantInfo, err := s.tenantRepo.GetTenantByID(ctx, payload.TenantID)
if err != nil {
logger.Errorf(ctx, "Failed to get tenant info: %v", err)
+ summaryErr = err
return fmt.Errorf("failed to get tenant info: %w", err)
}
ctx = context.WithValue(ctx, types.TenantInfoContextKey, tenantInfo)
@@ -1049,12 +1084,14 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
ctx, s.retrieveEngine, s.ownership, tenantInfo.ID, kb.VectorStoreID)
if err != nil {
logger.Errorf(ctx, "Failed to init retrieve engine: %v", err)
+ summaryErr = err
return fmt.Errorf("failed to init retrieve engine: %w", err)
}
embeddingModel, err := s.modelService.GetEmbeddingModel(ctx, kb.EmbeddingModelID)
if err != nil {
logger.Errorf(ctx, "Failed to get embedding model: %v", err)
+ summaryErr = err
return fmt.Errorf("failed to get embedding model: %w", err)
}
@@ -1070,13 +1107,16 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
if err := retrieveEngine.BatchIndex(ctx, embeddingModel, indexInfo); err != nil {
logger.Errorf(ctx, "Failed to index summary chunk: %v", err)
+ summaryErr = err
return fmt.Errorf("failed to index summary chunk: %w", err)
}
logger.Infof(ctx, "Successfully created and indexed summary chunk for knowledge: %s", payload.KnowledgeID)
+ summaryOut["summary_chunk_indexed"] = true
}
logger.Infof(ctx, "Successfully generated summary for knowledge: %s", payload.KnowledgeID)
+ summaryOut["status"] = "completed"
return nil
}
@@ -1101,6 +1141,12 @@ func (s *knowledgeService) ProcessQuestionGeneration(ctx context.Context, t *asy
indexEntriesPrepared := 0
indexBatchAttempted := false
indexBatchSucceeded := false
+ // Postprocess subspan for the trace viewer. Opened lazily after we
+ // unmarshal the payload (so we have payload.Attempt) and closed in
+ // the defer below alongside the stats log so the span output mirrors
+ // what we already log to stdout.
+ var qSpan *Span
+ var qErr error
defer func() {
logger.Infof(
ctx,
@@ -1125,6 +1171,39 @@ func (s *knowledgeService) ProcessQuestionGeneration(ctx context.Context, t *asy
indexBatchAttempted,
indexBatchSucceeded,
)
+ if qSpan != nil {
+ out := types.JSONMap{
+ "status": exitStatus,
+ "total_chunks": totalChunks,
+ "text_chunks": totalTextChunks,
+ "empty_content_chunks": emptyContentChunks,
+ "llm_attempts": llmCallAttempts,
+ "llm_success": llmCallSuccess,
+ "llm_empty": llmCallEmpty,
+ "llm_failed": llmCallFailed,
+ "questions_generated": generatedQuestionsTotal,
+ "chunk_update_failed": chunkUpdateFailed,
+ "metadata_set_failed": chunkMetadataSetFailed,
+ "index_entries_prepared": indexEntriesPrepared,
+ "index_batch_attempted": indexBatchAttempted,
+ "index_batch_succeeded": indexBatchSucceeded,
+ "retry": retryCount,
+ "max_retry": maxRetry,
+ }
+ // Treat any non-success exitStatus as a failed run; the
+ // existing stats-string already enumerates them. qErr stays
+ // optional for callers that want to surface a Go error.
+ if exitStatus != "success" || qErr != nil {
+ msg := exitStatus
+ var detailErr error = qErr
+ if qErr != nil {
+ msg = qErr.Error()
+ }
+ s.failPostprocessSubspan(ctx, qSpan, "QUESTION_FAILED", msg, detailErr)
+ } else {
+ s.endPostprocessSubspan(ctx, qSpan, out)
+ }
+ }
}()
if err := json.Unmarshal(t.Payload(), &payload); err != nil {
@@ -1135,6 +1214,14 @@ func (s *knowledgeService) ProcessQuestionGeneration(ctx context.Context, t *asy
logger.Infof(ctx, "Processing question generation for knowledge: %s", payload.KnowledgeID)
+ // Open the postprocess.question subspan now that we have payload.Attempt.
+ // Closes via the defer above.
+ qSpan = s.beginPostprocessSubspan(ctx, payload.KnowledgeID, payload.Attempt, "postprocess.question",
+ types.JSONMap{
+ "question_count": payload.QuestionCount,
+ "language": payload.Language,
+ })
+
// Set tenant context
ctx = context.WithValue(ctx, types.TenantIDContextKey, payload.TenantID)
if payload.Language != "" {
@@ -1144,7 +1231,8 @@ func (s *knowledgeService) ProcessQuestionGeneration(ctx context.Context, t *asy
if strings.TrimSpace(s.config.Conversation.GenerateQuestionsPrompt) == "" {
exitStatus = "prompt_not_configured"
logger.Errorf(ctx, "GenerateQuestionsPrompt is empty: configure conversation.generate_questions_prompt_id")
- return fmt.Errorf("generate questions prompt not configured")
+ qErr = fmt.Errorf("generate questions prompt not configured")
+ return qErr
}
// Get knowledge base
@@ -1152,6 +1240,7 @@ func (s *knowledgeService) ProcessQuestionGeneration(ctx context.Context, t *asy
if err != nil {
exitStatus = "kb_not_found"
logger.Errorf(ctx, "Failed to get knowledge base: %v", err)
+ qErr = err
return nil
}
@@ -1160,6 +1249,7 @@ func (s *knowledgeService) ProcessQuestionGeneration(ctx context.Context, t *asy
if err != nil {
exitStatus = "knowledge_not_found"
logger.Errorf(ctx, "Failed to get knowledge: %v", err)
+ qErr = err
return nil
}
diff --git a/internal/application/service/knowledge_span_tracker_test.go b/internal/application/service/knowledge_span_tracker_test.go
index f1ef3cd43..1073e4ff9 100644
--- a/internal/application/service/knowledge_span_tracker_test.go
+++ b/internal/application/service/knowledge_span_tracker_test.go
@@ -2,6 +2,7 @@ package service
import (
"context"
+ "encoding/json"
"errors"
"testing"
@@ -271,3 +272,140 @@ func TestSpanTracker_FailSpan_CascadesDependentSubspans(t *testing.T) {
assert.Equal(t, types.SpanStatusCancelled, statusBy["embedding.batch[0]"],
"subspan under the cascaded stage must also be cancelled")
}
+
+// TestPostprocessSubspan_AttachesUnderPostProcessStage covers the contract
+// that the async post-pipeline tasks (summary, question, graph) rely on:
+// after the parsing pipeline closes the postprocess stage span, an
+// out-of-band worker can still LookupStage + BeginSubSpan to record its
+// real processing time as a child of postprocess. Without this guarantee
+// the trace viewer's postprocess row stays at the ~10ms enqueue duration
+// even when summary generation takes 20 s.
+func TestPostprocessSubspan_AttachesUnderPostProcessStage(t *testing.T) {
+ tracker, db := setupSpanTrackerTest(t)
+ ctx := context.Background()
+ repo := repository.NewKnowledgeSpanRepository(db)
+
+ // Set up the parent attempt with a closed postprocess stage — the
+ // async worker must still find it via LookupStage.
+ _, attempt, err := tracker.OpenAttempt(ctx, "kid", "lf-trace")
+ require.NoError(t, err)
+
+ post := tracker.BeginStage(ctx, "kid", attempt, types.StagePostProcess, types.JSONMap{
+ "chunks_total": 20,
+ })
+ require.NotNil(t, post)
+ tracker.EndSpan(ctx, post, types.JSONMap{"enqueued_summary": true})
+
+ // Simulate ProcessSummaryGeneration entering: lookup parent +
+ // BeginSubSpan (the same call shape as beginPostprocessSubspan).
+ parent := tracker.LookupStage(ctx, "kid", attempt, types.StagePostProcess)
+ require.NotNil(t, parent, "lookup must succeed even after EndSpan closed the parent")
+ assert.Equal(t, types.StagePostProcess, parent.Name)
+ assert.Equal(t, types.SpanKindStage, parent.Kind)
+
+ sumSpan := tracker.BeginSubSpan(ctx, parent, "postprocess.summary", types.SpanKindSubSpan,
+ types.JSONMap{"language": "zh-CN"})
+ require.NotNil(t, sumSpan)
+ assert.Equal(t, parent.SpanID, sumSpan.ParentSpanID,
+ "subspan must hang off the postprocess stage's span_id")
+ assert.Equal(t, types.SpanKindSubSpan, sumSpan.Kind)
+
+ tracker.EndSpan(ctx, sumSpan, types.JSONMap{
+ "text_chunks": 20,
+ "summary_chars": 142,
+ })
+
+ // Verify the row landed under the right parent with the right name.
+ rows, err := repo.ListByAttempt(ctx, "kid", attempt)
+ require.NoError(t, err)
+ var found *types.KnowledgeProcessingSpan
+ for i := range rows {
+ if rows[i].Name == "postprocess.summary" {
+ cp := rows[i]
+ found = &cp
+ break
+ }
+ }
+ require.NotNil(t, found, "summary subspan row must persist")
+ assert.Equal(t, parent.SpanID, found.ParentSpanID,
+ "persisted parent_span_id matches LookupStage result")
+ assert.Equal(t, types.SpanStatusDone, found.Status)
+ assert.NotNil(t, found.Output, "EndSpan must record the output map")
+}
+
+// TestPostprocessSubspan_MissingParentFallsThrough covers the legacy
+// path: an in-flight async task may carry attempt=0 (queued before the
+// span-tracking field was added) or hit a knowledge whose postprocess
+// stage row is missing (parse predates tracker). LookupStage returning
+// nil must NOT crash the handler — the caller is expected to skip span
+// recording and continue normal processing.
+func TestPostprocessSubspan_MissingParentFallsThrough(t *testing.T) {
+ tracker, _ := setupSpanTrackerTest(t)
+ ctx := context.Background()
+
+ // No OpenAttempt → no rows for kid. LookupStage must return nil.
+ parent := tracker.LookupStage(ctx, "kid-without-attempt", 7, types.StagePostProcess)
+ assert.Nil(t, parent, "missing parent attempt yields nil, not an error")
+
+ // Open an attempt but never begin postprocess. Lookup must still nil.
+ _, attempt, err := tracker.OpenAttempt(ctx, "kid-no-postprocess", "")
+ require.NoError(t, err)
+ parent = tracker.LookupStage(ctx, "kid-no-postprocess", attempt, types.StagePostProcess)
+ assert.Nil(t, parent, "missing postprocess stage row yields nil")
+}
+
+// TestChunkExtractPayload_AttemptRoundTrip verifies the new fields
+// added to ExtractChunkPayload survive JSON marshal/unmarshal so a
+// cross-process asynq worker can recover the parent attempt + chunk
+// ordinal on the receiving side. Skipping this would let a typo in
+// the JSON tag silently zero the attempt and disable span recording.
+func TestChunkExtractPayload_AttemptRoundTrip(t *testing.T) {
+ in := types.ExtractChunkPayload{
+ TenantID: 42,
+ ChunkID: "chunk-x",
+ ModelID: "m1",
+ KnowledgeID: "kid-7",
+ Attempt: 3,
+ ChunkIndex: 9,
+ }
+ bytes, err := json.Marshal(in)
+ require.NoError(t, err)
+
+ var out types.ExtractChunkPayload
+ require.NoError(t, json.Unmarshal(bytes, &out))
+
+ assert.Equal(t, in.KnowledgeID, out.KnowledgeID)
+ assert.Equal(t, in.Attempt, out.Attempt)
+ assert.Equal(t, in.ChunkIndex, out.ChunkIndex)
+}
+
+// TestSummaryQuestionPayload_AttemptRoundTrip mirrors the above for the
+// summary + question payloads to keep the contract documented.
+func TestSummaryQuestionPayload_AttemptRoundTrip(t *testing.T) {
+ sumIn := types.SummaryGenerationPayload{
+ TenantID: 42,
+ KnowledgeBaseID: "kb-1",
+ KnowledgeID: "kid-7",
+ Language: "zh-CN",
+ Attempt: 5,
+ }
+ sumBytes, err := json.Marshal(sumIn)
+ require.NoError(t, err)
+ var sumOut types.SummaryGenerationPayload
+ require.NoError(t, json.Unmarshal(sumBytes, &sumOut))
+ assert.Equal(t, 5, sumOut.Attempt)
+
+ qIn := types.QuestionGenerationPayload{
+ TenantID: 42,
+ KnowledgeBaseID: "kb-1",
+ KnowledgeID: "kid-7",
+ QuestionCount: 3,
+ Language: "zh-CN",
+ Attempt: 5,
+ }
+ qBytes, err := json.Marshal(qIn)
+ require.NoError(t, err)
+ var qOut types.QuestionGenerationPayload
+ require.NoError(t, json.Unmarshal(qBytes, &qOut))
+ assert.Equal(t, 5, qOut.Attempt)
+}
diff --git a/internal/types/task.go b/internal/types/task.go
index c277e04ff..afceea085 100644
--- a/internal/types/task.go
+++ b/internal/types/task.go
@@ -25,6 +25,16 @@ type ExtractChunkPayload struct {
TenantID uint64 `json:"tenant_id"`
ChunkID string `json:"chunk_id"`
ModelID string `json:"model_id"`
+ // KnowledgeID + Attempt link the per-chunk extract back to the parent
+ // parse attempt's postprocess stage so the worker can record a
+ // postprocess.graph.chunk[i] subspan. 0 / "" means "skip span
+ // recording" for legacy in-flight tasks.
+ KnowledgeID string `json:"knowledge_id,omitempty"`
+ Attempt int `json:"attempt,omitempty"`
+ // ChunkIndex is the 0-based ordinal of this chunk inside the parent
+ // knowledge's text-chunk set, used as the subspan name suffix
+ // ("postprocess.graph.chunk[3]") so the timeline preserves order.
+ ChunkIndex int `json:"chunk_index,omitempty"`
}
// DocumentProcessPayload represents the document process task payload
@@ -77,6 +87,12 @@ type QuestionGenerationPayload struct {
QuestionCount int `json:"question_count"`
// Language is the request locale (e.g. zh-CN, en-US) when the task was enqueued, used for {{language}} / {{lang}} in templates.
Language string `json:"language,omitempty"`
+ // Attempt links this task to the parent parse attempt so the worker
+ // can record a postprocess.question subspan under the right attempt's
+ // postprocess stage. 0 means "skip span recording" (legacy in-flight
+ // tasks queued before this field shipped, or callers without a
+ // tracker).
+ Attempt int `json:"attempt,omitempty"`
}
// SummaryGenerationPayload represents the summary generation task payload
@@ -86,6 +102,10 @@ type SummaryGenerationPayload struct {
KnowledgeBaseID string `json:"knowledge_base_id"`
KnowledgeID string `json:"knowledge_id"`
Language string `json:"language,omitempty"`
+ // Attempt links this task to the parent parse attempt so the worker
+ // can record a postprocess.summary subspan under the right attempt's
+ // postprocess stage. See QuestionGenerationPayload.Attempt notes.
+ Attempt int `json:"attempt,omitempty"`
}
// KBClonePayload represents the knowledge base clone task payload