fix: render compaction on worker status
This commit is contained in:
@@ -7,9 +7,11 @@
|
||||
requests: number;
|
||||
uploadTokens: number;
|
||||
outputTokens: number;
|
||||
compaction?: { phase: string } | null;
|
||||
};
|
||||
|
||||
let { startedAtMs, requests, uploadTokens, outputTokens }: Props = $props();
|
||||
let { startedAtMs, requests, uploadTokens, outputTokens, compaction = null }: Props =
|
||||
$props();
|
||||
let nowMs = $state(Date.now());
|
||||
|
||||
$effect(() => {
|
||||
@@ -27,6 +29,10 @@
|
||||
|
||||
<div class="worker-run-status" role="status" aria-live="off">
|
||||
<Spinner />
|
||||
{#if compaction}
|
||||
<span>Compacting · {compaction.phase}</span>
|
||||
<span aria-hidden="true">|</span>
|
||||
{/if}
|
||||
<span>{elapsed}</span>
|
||||
<span aria-hidden="true">・</span>
|
||||
<span>{requests} {requestLabel}</span>
|
||||
|
||||
@@ -1092,11 +1092,9 @@ Deno.test("snapshot restores running compaction without staged content", () => {
|
||||
|
||||
const projection = projectConsole([{ eventId: "snapshot", event: snapshot }]);
|
||||
|
||||
assertEquals(projection.lines.length, 1);
|
||||
assertEquals(projection.lines[0].id, "compaction-runtime");
|
||||
assertEquals(projection.lines[0].streaming, true);
|
||||
assertEquals(projection.lines[0].body, "compacting · summarizing");
|
||||
assertEquals(projection.lines[0].body.includes("staged"), false);
|
||||
assertEquals(projection.lines.length, 0);
|
||||
assertEquals(projection.compaction?.phase, "summarizing");
|
||||
assertEquals(projection.compaction?.trigger, "manual");
|
||||
});
|
||||
|
||||
Deno.test("compaction service activity stays nested in one lifecycle item", () => {
|
||||
|
||||
@@ -173,6 +173,7 @@ export type ConsoleProjection = {
|
||||
taskNextId: number;
|
||||
status: string | null;
|
||||
workerState: WorkerStateSnapshot | null;
|
||||
compaction: InFlightCompaction | null;
|
||||
usage: string | null;
|
||||
runActivity: RunActivityStats;
|
||||
cwd: string | null;
|
||||
@@ -246,6 +247,7 @@ export function emptyConsoleProjection(): ConsoleProjection {
|
||||
taskNextId: 1,
|
||||
status: null,
|
||||
workerState: null,
|
||||
compaction: null,
|
||||
usage: null,
|
||||
runActivity: emptyRunActivityStats(),
|
||||
cwd: null,
|
||||
@@ -722,23 +724,7 @@ function applyInFlightCompaction(
|
||||
projection: ConsoleProjection,
|
||||
progress: InFlightCompaction | null,
|
||||
): ConsoleProjection {
|
||||
const id = "compaction-runtime";
|
||||
const lines = projection.lines.filter((line) => line.id !== id);
|
||||
if (!progress) return { ...projection, lines };
|
||||
return {
|
||||
...projection,
|
||||
lines: [
|
||||
...lines,
|
||||
{
|
||||
id,
|
||||
kind: "status",
|
||||
title: "Compaction",
|
||||
body: `compacting · ${progress.phase.replaceAll("_", " ")}`,
|
||||
source: "event",
|
||||
streaming: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
return { ...projection, compaction: progress };
|
||||
}
|
||||
|
||||
function applyCompactionLifecycle(
|
||||
@@ -863,6 +849,7 @@ export function applyProtocolEvent(
|
||||
taskNextId: projection.taskNextId,
|
||||
status: projection.status,
|
||||
workerState: projection.workerState,
|
||||
compaction: projection.compaction,
|
||||
usage: projection.usage,
|
||||
runActivity: applyRunActivityEvent(
|
||||
projection.runActivity,
|
||||
@@ -1003,6 +990,7 @@ export function applyProtocolEvent(
|
||||
event.data.in_flight.compaction,
|
||||
);
|
||||
next.lines = withCompaction.lines;
|
||||
next.compaction = withCompaction.compaction;
|
||||
}
|
||||
for (const line of next.lines) {
|
||||
const compaction = line.compaction;
|
||||
@@ -2013,6 +2001,7 @@ function snapshotProjectionFromSession(
|
||||
taskNextId: 1,
|
||||
status: null,
|
||||
workerState: null,
|
||||
compaction: null,
|
||||
usage: null,
|
||||
runActivity: emptyRunActivityStats(),
|
||||
cwd,
|
||||
|
||||
@@ -1907,6 +1907,7 @@
|
||||
requests={consoleProjection.runActivity.requests}
|
||||
uploadTokens={consoleProjection.runActivity.uploadTokens}
|
||||
outputTokens={consoleProjection.runActivity.outputTokens}
|
||||
compaction={consoleProjection.compaction}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user