From 80f8a219c89a963c485da0f40dc428bf688fedb7 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Sun, 7 Jun 2026 18:52:13 +0900 Subject: Revert "feat(chat): live turn metrics — telemetry reducer + rendering" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 48c6d85c3cc5a57a729f14068e2346b17ed62088. --- src/features/chat/index.ts | 2 - src/features/chat/store.svelte.ts | 12 --- src/features/chat/store.test.ts | 46 ---------- src/features/chat/ui.test.ts | 150 +++----------------------------- src/features/chat/ui/ChatView.svelte | 93 ++++++-------------- src/features/chat/ui/TurnSummary.svelte | 75 ---------------- 6 files changed, 37 insertions(+), 341 deletions(-) delete mode 100644 src/features/chat/ui/TurnSummary.svelte (limited to 'src/features/chat') diff --git a/src/features/chat/index.ts b/src/features/chat/index.ts index b096cca..4f2091a 100644 --- a/src/features/chat/index.ts +++ b/src/features/chat/index.ts @@ -1,10 +1,8 @@ export type { RenderedChunk, RenderGroup, ToolBatchEntry } from "../../core/chunks"; export { groupRenderedChunks } from "../../core/chunks"; -export type { StepMetrics, TelemetryState, TurnMetrics } from "../../core/telemetry"; export type { ChatTransport, HistorySync } from "./ports"; export type { ChatStore, ChatStoreDependencies } from "./store.svelte"; export { createChatStore } from "./store.svelte"; export { default as ChatView } from "./ui/ChatView.svelte"; export { default as Composer } from "./ui/Composer.svelte"; export { default as ModelSelector } from "./ui/ModelSelector.svelte"; -export { default as TurnSummary } from "./ui/TurnSummary.svelte"; diff --git a/src/features/chat/store.svelte.ts b/src/features/chat/store.svelte.ts index 58c165f..1d8ab17 100644 --- a/src/features/chat/store.svelte.ts +++ b/src/features/chat/store.svelte.ts @@ -13,8 +13,6 @@ import { selectChunks, selectMessages, } from "../../core/chunks"; -import type { TelemetryState } from "../../core/telemetry"; -import { foldMetricEvent, initialState as telemetryInitialState } from "../../core/telemetry"; import type { ConversationCache } from "../conversation-cache"; import type { ChatTransport, HistorySync } from "./ports"; @@ -32,8 +30,6 @@ export interface ChatStore { readonly pendingSync: boolean; readonly error: string | null; readonly model: string | undefined; - readonly telemetry: TelemetryState; - readonly currentTurnId: string | null; handleDelta(msg: ChatDeltaMessage | ChatErrorMessage): void; send(text: string): void; setModel(model: string): void; @@ -46,7 +42,6 @@ export function createChatStore(deps: ChatStoreDependencies): ChatStore { let _pendingSync = $state(false); let _error = $state(null); let _model = $state(deps.model); - let telemetry = $state(telemetryInitialState()); let disposed = false; async function syncTail(): Promise { @@ -81,12 +76,6 @@ export function createChatStore(deps: ChatStoreDependencies): ChatStore { get model(): string | undefined { return _model; }, - get telemetry(): TelemetryState { - return telemetry; - }, - get currentTurnId(): string | null { - return transcript.currentTurnId; - }, handleDelta(msg: ChatDeltaMessage | ChatErrorMessage): void { if (msg.type === "chat.error") { @@ -100,7 +89,6 @@ export function createChatStore(deps: ChatStoreDependencies): ChatStore { return; } transcript = foldEvent(transcript, msg.event); - telemetry = foldMetricEvent(telemetry, msg.event); if (transcript.sealedTurnId !== null) { void syncTail(); } diff --git a/src/features/chat/store.test.ts b/src/features/chat/store.test.ts index 347cdd7..71781ac 100644 --- a/src/features/chat/store.test.ts +++ b/src/features/chat/store.test.ts @@ -393,52 +393,6 @@ describe("createChatStore", () => { store.dispose(); }); - it("folding step-complete and usage events populates telemetry", () => { - const transport = createFakeTransport(); - const historySync = createFakeHistorySync(); - const cache = createFakeCache(); - const store = createChatStore({ - conversationId: CONV_ID, - transport: transport.impl, - historySync: historySync.impl, - cache: cache.impl, - }); - - store.handleDelta(deltaEvent({ type: "turn-start", conversationId: CONV_ID, turnId: "t1" })); - store.handleDelta( - deltaEvent({ - type: "step-complete", - conversationId: CONV_ID, - turnId: "t1", - stepId: "t1#0" as StepId, - ttftMs: 300, - decodeMs: 700, - genTotalMs: 1000, - }), - ); - store.handleDelta( - deltaEvent({ - type: "usage", - conversationId: CONV_ID, - turnId: "t1", - stepId: "t1#0" as StepId, - usage: { inputTokens: 50, outputTokens: 20 }, - }), - ); - - const turn = store.telemetry.turns.get("t1"); - expect(turn).toBeDefined(); - expect(turn?.steps).toHaveLength(1); - const step = turn?.steps.find((s) => s.stepId === ("t1#0" as StepId)); - expect(step).toBeDefined(); - expect(step?.ttftMs).toBe(300); - expect(step?.decodeMs).toBe(700); - expect(step?.usage?.inputTokens).toBe(50); - expect(step?.usage?.outputTokens).toBe(20); - - store.dispose(); - }); - it("handleDelta ignores a chat.delta for a different conversationId", () => { const transport = createFakeTransport(); const historySync = createFakeHistorySync(); diff --git a/src/features/chat/ui.test.ts b/src/features/chat/ui.test.ts index 02d3c5a..b31cbf1 100644 --- a/src/features/chat/ui.test.ts +++ b/src/features/chat/ui.test.ts @@ -3,15 +3,9 @@ import { render, screen } from "@testing-library/svelte"; import userEvent from "@testing-library/user-event"; import { describe, expect, it, vi } from "vitest"; import type { RenderedChunk } from "../../core/chunks"; -import type { TelemetryState } from "../../core/telemetry"; -import { initialState } from "../../core/telemetry"; import ChatView from "./ui/ChatView.svelte"; import Composer from "./ui/Composer.svelte"; import ModelSelector from "./ui/ModelSelector.svelte"; -import TurnSummary from "./ui/TurnSummary.svelte"; - -const emptyTelemetry = initialState(); -const noTurnId = null; describe("ChatView", () => { it("renders a message's text chunk", () => { @@ -24,7 +18,7 @@ describe("ChatView", () => { }, ]; - render(ChatView, { props: { chunks, telemetry: emptyTelemetry, currentTurnId: noTurnId } }); + render(ChatView, { props: { chunks } }); expect(screen.getByText("Hello world")).toBeInTheDocument(); }); @@ -40,7 +34,7 @@ describe("ChatView", () => { }, ]; - render(ChatView, { props: { chunks, telemetry: emptyTelemetry, currentTurnId: noTurnId } }); + render(ChatView, { props: { chunks } }); expect(screen.getByText("Hi there")).toBeInTheDocument(); expect(screen.getByText("Hello!")).toBeInTheDocument(); @@ -61,7 +55,7 @@ describe("ChatView", () => { }, ]; - render(ChatView, { props: { chunks, telemetry: emptyTelemetry, currentTurnId: noTurnId } }); + render(ChatView, { props: { chunks } }); expect(screen.getByText("read_file")).toBeInTheDocument(); const pre = screen.getByText((content, element) => { @@ -86,7 +80,7 @@ describe("ChatView", () => { }, ]; - render(ChatView, { props: { chunks, telemetry: emptyTelemetry, currentTurnId: noTurnId } }); + render(ChatView, { props: { chunks } }); expect(screen.getByText("read_file")).toBeInTheDocument(); expect(screen.getByText("file contents here")).toBeInTheDocument(); @@ -102,7 +96,7 @@ describe("ChatView", () => { }, ]; - render(ChatView, { props: { chunks, telemetry: emptyTelemetry, currentTurnId: noTurnId } }); + render(ChatView, { props: { chunks } }); const alert = screen.getByRole("alert"); expect(alert).toHaveTextContent("Something failed"); @@ -118,7 +112,7 @@ describe("ChatView", () => { }, ]; - render(ChatView, { props: { chunks, telemetry: emptyTelemetry, currentTurnId: noTurnId } }); + render(ChatView, { props: { chunks } }); expect(screen.getByText("Rate limited")).toBeInTheDocument(); expect(screen.getByText("[RATE_LIMIT]")).toBeInTheDocument(); @@ -134,7 +128,7 @@ describe("ChatView", () => { }, ]; - render(ChatView, { props: { chunks, telemetry: emptyTelemetry, currentTurnId: noTurnId } }); + render(ChatView, { props: { chunks } }); expect(screen.getByText("System context loaded")).toBeInTheDocument(); }); @@ -149,7 +143,7 @@ describe("ChatView", () => { }, ]; - render(ChatView, { props: { chunks, telemetry: emptyTelemetry, currentTurnId: noTurnId } }); + render(ChatView, { props: { chunks } }); // In-flight chunks render at full opacity (no faded "disabled" look). const wrapper = screen.getByText("Streaming...").closest("div"); @@ -157,7 +151,7 @@ describe("ChatView", () => { }); it("renders empty transcript", () => { - render(ChatView, { props: { chunks: [], telemetry: emptyTelemetry, currentTurnId: noTurnId } }); + render(ChatView, { props: { chunks: [] } }); const log = screen.getByRole("log"); expect(log).toBeInTheDocument(); @@ -205,9 +199,7 @@ describe("ChatView", () => { }, ]; - const { container } = render(ChatView, { - props: { chunks, telemetry: emptyTelemetry, currentTurnId: noTurnId }, - }); + const { container } = render(ChatView, { props: { chunks } }); // One DaisyUI list with two rows (one per call), not separate cards. const lists = container.querySelectorAll("ul.list"); @@ -232,9 +224,7 @@ describe("ChatView", () => { }, ]; - const { container } = render(ChatView, { - props: { chunks, telemetry: emptyTelemetry, currentTurnId: noTurnId }, - }); + const { container } = render(ChatView, { props: { chunks } }); const collapse = container.querySelector(".collapse"); expect(collapse).not.toBeNull(); @@ -257,9 +247,7 @@ describe("ChatView", () => { }, ]; - const { container, rerender } = render(ChatView, { - props: { chunks: streaming, telemetry: emptyTelemetry, currentTurnId: noTurnId }, - }); + const { container, rerender } = render(ChatView, { props: { chunks: streaming } }); // Streaming: "Thinking" + loading dots. expect(screen.getByText("Thinking")).toBeInTheDocument(); @@ -281,8 +269,6 @@ describe("ChatView", () => { provisional: false, }, ], - telemetry: emptyTelemetry, - currentTurnId: noTurnId, }); // Completed: "Thoughts", no dots — and the open state survived the transition. @@ -292,118 +278,6 @@ describe("ChatView", () => { expect(screen.getByRole("checkbox", { name: "Toggle thoughts" })).toBeChecked(); expect(container).toHaveTextContent("hmm, all done"); }); - - it("assistant text shows step metrics footer when step-complete data is available", () => { - const chunks: RenderedChunk[] = [ - { - seq: 1, - role: "assistant", - chunk: { type: "text", text: "Here is my answer" }, - provisional: false, - }, - ]; - - const telemetry: TelemetryState = { - turns: new Map([ - [ - "turn-1", - { - wallMs: 2500, - steps: [ - { - stepId: "turn-1#0" as StepId, - genTotalMs: 1200, - decodeMs: 1000, - usage: { inputTokens: 100, outputTokens: 86 }, - }, - ], - }, - ], - ]), - }; - - render(ChatView, { props: { chunks, telemetry, currentTurnId: "turn-1" } }); - - expect(screen.getByText("Here is my answer")).toBeInTheDocument(); - expect(screen.getByText("1.2s")).toBeInTheDocument(); - expect(screen.getByText("86 t/s")).toBeInTheDocument(); - expect(screen.getByText("86 tok")).toBeInTheDocument(); - }); - - it("does not show metrics footer when no step data exists", () => { - const chunks: RenderedChunk[] = [ - { - seq: 1, - role: "assistant", - chunk: { type: "text", text: "Still streaming" }, - provisional: true, - }, - ]; - - render(ChatView, { props: { chunks, telemetry: emptyTelemetry, currentTurnId: "turn-1" } }); - - expect(screen.getByText("Still streaming")).toBeInTheDocument(); - expect(screen.queryByText("t/s")).toBeNull(); - expect(screen.queryByText("tok")).toBeNull(); - }); -}); - -describe("TurnSummary", () => { - it("renders turn stats when telemetry has data", () => { - const telemetry: TelemetryState = { - turns: new Map([ - [ - "turn-1", - { - wallMs: 4200, - steps: [ - { - stepId: "turn-1#0" as StepId, - genTotalMs: 2000, - decodeMs: 1500, - usage: { inputTokens: 500, outputTokens: 300 }, - }, - { - stepId: "turn-1#1" as StepId, - genTotalMs: 1800, - decodeMs: 1200, - usage: { inputTokens: 600, outputTokens: 200 }, - }, - ], - }, - ], - ]), - }; - - render(TurnSummary, { props: { telemetry, turnId: "turn-1" } }); - - expect(screen.getByText("Turn")).toBeInTheDocument(); - expect(screen.getByText("4.2s")).toBeInTheDocument(); - expect(screen.getByText("Tokens")).toBeInTheDocument(); - expect(screen.getByText("1,600")).toBeInTheDocument(); - expect(screen.getByText("Output")).toBeInTheDocument(); - expect(screen.getByText("500")).toBeInTheDocument(); - expect(screen.getByText("Input")).toBeInTheDocument(); - expect(screen.getByText("1,100")).toBeInTheDocument(); - expect(screen.getByText("Steps")).toBeInTheDocument(); - expect(screen.getByText("2")).toBeInTheDocument(); - expect(screen.getByText("TPS")).toBeInTheDocument(); - expect(screen.getByText("185 t/s")).toBeInTheDocument(); - }); - - it("renders nothing when turnId is null", () => { - const { container } = render(TurnSummary, { - props: { telemetry: emptyTelemetry, turnId: null }, - }); - expect(container.querySelector(".stats")).toBeNull(); - }); - - it("renders nothing when turn metrics not found", () => { - const { container } = render(TurnSummary, { - props: { telemetry: emptyTelemetry, turnId: "nonexistent" }, - }); - expect(container.querySelector(".stats")).toBeNull(); - }); }); describe("Composer", () => { diff --git a/src/features/chat/ui/ChatView.svelte b/src/features/chat/ui/ChatView.svelte index 6acda53..3a078fb 100644 --- a/src/features/chat/ui/ChatView.svelte +++ b/src/features/chat/ui/ChatView.svelte @@ -1,27 +1,16 @@ -{#snippet chunkRow(rendered: RenderedChunk, sIdx: number)} +{#snippet chunkRow(rendered: RenderedChunk)} {#if rendered.role === "user"} +
{#if rendered.chunk.type === "text"} @@ -52,6 +38,9 @@
{:else if rendered.chunk.type === "thinking"} +
@@ -69,18 +58,14 @@
{:else if rendered.chunk.type === "tool-call" || rendered.chunk.type === "tool-result"} - {@const step = currentTurnId ? stepMetrics(telemetry, currentTurnId, sIdx) : undefined} - {@const toolDur = step?.toolDurationMs} +
{#if rendered.chunk.type === "tool-call"}
-
- {rendered.chunk.toolName} - {#if toolDur !== undefined && toolDur > 0} - {formatMs(toolDur)} - {/if} -
+ {rendered.chunk.toolName}
{JSON.stringify(rendered.chunk.input, null, 2)}
{:else} @@ -88,43 +73,19 @@ class="w-fit max-w-full rounded-box bg-base-200 p-3 text-sm" class:text-error={rendered.chunk.isError} > -
- {rendered.chunk.toolName} - {#if toolDur !== undefined && toolDur > 0} - {formatMs(toolDur)} - {/if} -
+ {rendered.chunk.toolName}
{rendered.chunk.content}
{/if}
{:else} - {@const step = currentTurnId ? stepMetrics(telemetry, currentTurnId, sIdx) : undefined} - {@const tps = step ? stepTps(step) : undefined} +
{#if rendered.chunk.type === "text"} -
    -
  • -

    {rendered.chunk.text}

    -
  • - {#if step && (step.genTotalMs !== undefined || tps !== undefined || step.usage?.outputTokens !== undefined)} -
  • - {#if step.genTotalMs !== undefined} - {formatMs(step.genTotalMs)} - {/if} - · - {#if tps !== undefined} - {Math.round(tps)} t/s - {/if} - · - {#if step.usage?.outputTokens !== undefined} - {step.usage.outputTokens} tok - {/if} -
  • - {/if} -
+

{rendered.chunk.text}

{:else if rendered.chunk.type === "error"}