From 481bfa0dfcbbf9ccc0c1e0d6d355c04fc27c12e1 Mon Sep 17 00:00:00 2001 From: qer Date: Sat, 13 Jun 2026 12:28:08 +0800 Subject: [PATCH] feat(web): capture front-end errors in the troubleshooting log export The KAP debug panel already exported REST + WS traffic as JSONL, but a broken page is usually explained by a JS error the network log doesn't show. Fold window error/unhandledrejection and console.error/warn into the trace buffer (opt-in, install-once, behavior-preserving) as a 'client' source, surface them in the panel with an 'app errors' filter + APP badge, so 'export jsonl' yields a complete troubleshooting log. --- apps/kimi-web/src/debug/DebugPanel.vue | 14 +++-- apps/kimi-web/src/debug/trace.ts | 73 +++++++++++++++++++++++++- apps/kimi-web/src/main.ts | 6 +++ apps/kimi-web/test/debug-trace.test.ts | 19 +++++++ 4 files changed, 108 insertions(+), 4 deletions(-) diff --git a/apps/kimi-web/src/debug/DebugPanel.vue b/apps/kimi-web/src/debug/DebugPanel.vue index c1ae66402..b45f7f095 100644 --- a/apps/kimi-web/src/debug/DebugPanel.vue +++ b/apps/kimi-web/src/debug/DebugPanel.vue @@ -19,7 +19,7 @@ const open = ref(false); // --------------------------------------------------------------------------- // Filters // --------------------------------------------------------------------------- -const sourceFilter = ref<'all' | 'rest' | 'ws'>('all'); +const sourceFilter = ref<'all' | 'rest' | 'ws' | 'client'>('all'); const textFilter = ref(''); const sessionFilter = ref(''); const errorsOnly = ref(false); @@ -142,10 +142,17 @@ function exportJsonl(): void { function badgeClass(e: TraceEntry): string { if (isError(e)) return 'b-err'; + if (e.source === 'client') return 'b-err'; if (e.source === 'rest') return 'b-rest'; if (e.kind === 'ws:lifecycle') return 'b-life'; return e.kind === 'ws:out' ? 'b-out' : 'b-in'; } + +function badgeLabel(e: TraceEntry): string { + if (e.source === 'rest') return 'REST'; + if (e.source === 'client') return 'APP'; + return 'WS'; +}