ui: simplify worker console

This commit is contained in:
2026-06-28 22:41:32 +09:00
parent 05d39e05c7
commit 0602efd3b7
5 changed files with 129 additions and 163 deletions
@@ -45,7 +45,7 @@ Deno.test("segmentsToText preserves protocol segment semantics", () => {
);
});
Deno.test("projectConsole keeps transcript and protocol-derived event rows distinct", () => {
Deno.test("projectConsole projects initial console output and live protocol rows", () => {
const projection = projectConsole(
[
{
@@ -101,15 +101,15 @@ Deno.test("projectConsole keeps transcript and protocol-derived event rows disti
assert(
projection.lines.some((line) =>
line.source === "transcript" && line.kind === "user"
line.source === "initial" && line.kind === "user"
),
"transcript user row expected",
"initial user row expected",
);
assert(
projection.lines.some((line) =>
line.source === "event" && line.kind === "assistant"
line.source === "live" && line.kind === "assistant"
),
"assistant event row expected",
"assistant live row expected",
);
assert(
projection.lines.some((line) => line.kind === "thinking"),
@@ -133,7 +133,7 @@ Deno.test("projectConsole keeps transcript and protocol-derived event rows disti
);
});
Deno.test("projectConsole displays snapshot and in-flight state", () => {
Deno.test("projectConsole uses snapshot for state without rendering it as console output", () => {
const projection = projectConsole([], [
{
cursor: "20",
@@ -171,8 +171,8 @@ Deno.test("projectConsole displays snapshot and in-flight state", () => {
assert(projection.status === "running", "snapshot should update status");
assert(
projection.lines.some((line) => line.kind === "snapshot"),
"snapshot row expected",
!projection.lines.some((line) => line.title.includes("snapshot")),
"snapshot should not render as a console row",
);
assert(
projection.lines.filter((line) => line.kind === "in_flight").length === 2,
@@ -13,7 +13,6 @@ export type ConsoleLineKind =
| "status"
| "error"
| "usage"
| "snapshot"
| "in_flight"
| "system";
@@ -24,7 +23,7 @@ export type ConsoleLine = {
body: string;
detail?: string;
cursor?: string | null;
source: "transcript" | "event";
source: "initial" | "live";
streaming?: boolean;
error?: boolean;
};
@@ -53,23 +52,22 @@ export function workerConsolePath(runtimeId: string, workerId: string): string {
return workerConsoleHref({ runtime_id: runtimeId, worker_id: workerId });
}
export function transcriptLines(items: WorkerTranscriptItem[]): ConsoleLine[] {
export function initialConsoleLines(items: WorkerTranscriptItem[]): ConsoleLine[] {
return items.map((item) => ({
id: `transcript-${item.event_id}-${item.sequence}`,
kind: transcriptRoleKind(item.role),
title: `${item.role} · transcript #${item.sequence}`,
id: `initial-${item.event_id}-${item.sequence}`,
kind: initialRoleKind(item.role),
title: item.role,
body: item.content,
detail: `event ${item.event_id}`,
source: "transcript",
source: "initial",
}));
}
export function projectConsole(
transcript: WorkerTranscriptItem[],
initialItems: WorkerTranscriptItem[],
events: Array<{ cursor: string; event: ProtocolEvent }> = [],
): ConsoleProjection {
return events.reduce(applyProtocolEvent, {
lines: transcriptLines(transcript),
lines: initialConsoleLines(initialItems),
status: null,
usage: null,
lastCursor: null,
@@ -208,15 +206,6 @@ export function applyProtocolEvent(
break;
case "snapshot":
next.status = event.data.status;
next.lines.push(
line(
envelope.cursor,
"snapshot",
`snapshot · ${event.data.status}`,
`${event.data.entries.length} entries · ${event.data.greeting.provider} / ${event.data.greeting.model}`,
`${event.data.greeting.worker_name} · context ${event.data.greeting.context_tokens}/${event.data.greeting.context_window}`,
),
);
for (const block of event.data.in_flight?.blocks ?? []) {
next.lines.push(inFlightLine(envelope.cursor, block));
}
@@ -443,7 +432,7 @@ export function segmentsToText(segments: Segment[]): string {
.join("\n");
}
function transcriptRoleKind(role: string): ConsoleLineKind {
function initialRoleKind(role: string): ConsoleLineKind {
if (role === "user" || role === "assistant" || role === "system") {
return role;
}
@@ -466,7 +455,7 @@ function line(
body,
detail,
cursor,
source: "event",
source: "live",
streaming,
error,
};