diff options
Diffstat (limited to 'packages/cli/src/render.ts')
| -rw-r--r-- | packages/cli/src/render.ts | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/packages/cli/src/render.ts b/packages/cli/src/render.ts index 9f25dd3..f512b7a 100644 --- a/packages/cli/src/render.ts +++ b/packages/cli/src/render.ts @@ -8,40 +8,40 @@ import type { AgentEvent, ConversationMeta } from "@dispatch/transport-contract"; interface RenderOpts { - readonly showReasoning: boolean; + readonly showReasoning: boolean; } interface RenderOutput { - readonly stdout?: string; - readonly stderr?: string; + readonly stdout?: string; + readonly stderr?: string; } export function renderEvent(e: AgentEvent, opts: RenderOpts): RenderOutput | undefined { - switch (e.type) { - case "text-delta": - return { stdout: e.delta }; - case "reasoning-delta": - return opts.showReasoning ? { stdout: e.delta } : undefined; - case "tool-call": - return { stdout: `\n[tool] ${e.toolName} ${JSON.stringify(e.input)}\n` }; - case "tool-output": - return { stdout: e.data }; - case "tool-result": - return { - stdout: `[tool:${e.toolName}]${e.isError ? " ERROR" : ""} ${e.content}\n`, - }; - case "usage": - return { - stdout: `\n[usage] in=${e.usage.inputTokens} out=${e.usage.outputTokens}\n`, - }; - case "error": - return { stderr: `[error] ${e.message}\n` }; - case "status": - case "turn-start": - case "turn-sealed": - case "done": - return undefined; - } + switch (e.type) { + case "text-delta": + return { stdout: e.delta }; + case "reasoning-delta": + return opts.showReasoning ? { stdout: e.delta } : undefined; + case "tool-call": + return { stdout: `\n[tool] ${e.toolName} ${JSON.stringify(e.input)}\n` }; + case "tool-output": + return { stdout: e.data }; + case "tool-result": + return { + stdout: `[tool:${e.toolName}]${e.isError ? " ERROR" : ""} ${e.content}\n`, + }; + case "usage": + return { + stdout: `\n[usage] in=${e.usage.inputTokens} out=${e.usage.outputTokens}\n`, + }; + case "error": + return { stderr: `[error] ${e.message}\n` }; + case "status": + case "turn-start": + case "turn-sealed": + case "done": + return undefined; + } } /** @@ -50,13 +50,13 @@ export function renderEvent(e: AgentEvent, opts: RenderOpts): RenderOutput | und * no I/O. Returns the empty string when the stream had no text deltas. */ export function extractLastText(events: readonly AgentEvent[]): string { - let text = ""; - for (const e of events) { - if (e.type === "text-delta") { - text += e.delta; - } - } - return text; + let text = ""; + for (const e of events) { + if (e.type === "text-delta") { + text += e.delta; + } + } + return text; } /** @@ -65,15 +65,15 @@ export function extractLastText(events: readonly AgentEvent[]): string { * (clock is an outermost edge) so the function is pure and testable. */ export function formatRelativeTime(epochMs: number, now: number): string { - const delta = now - epochMs; - if (delta < 60_000) return "just now"; - const minutes = Math.floor(delta / 60_000); - if (minutes < 60) return `${minutes}m ago`; - const hours = Math.floor(minutes / 60); - if (hours < 24) return `${hours}h ago`; - const days = Math.floor(hours / 24); - if (days < 7) return `${days}d ago`; - return new Date(epochMs).toISOString().slice(0, 10); + const delta = now - epochMs; + if (delta < 60_000) return "just now"; + const minutes = Math.floor(delta / 60_000); + if (minutes < 60) return `${minutes}m ago`; + const hours = Math.floor(minutes / 60); + if (hours < 24) return `${hours}h ago`; + const days = Math.floor(hours / 24); + if (days < 7) return `${days}d ago`; + return new Date(epochMs).toISOString().slice(0, 10); } /** @@ -82,11 +82,11 @@ export function formatRelativeTime(epochMs: number, now: number): string { * string. `now` is injected for `formatRelativeTime` (pure + testable). */ export function formatConversationList( - conversations: readonly ConversationMeta[], - now: number, + conversations: readonly ConversationMeta[], + now: number, ): string { - if (conversations.length === 0) return ""; - return conversations - .map((c) => `${c.id.slice(0, 8)} | ${c.title} | ${formatRelativeTime(c.lastActivityAt, now)}`) - .join("\n"); + if (conversations.length === 0) return ""; + return conversations + .map((c) => `${c.id.slice(0, 8)} | ${c.title} | ${formatRelativeTime(c.lastActivityAt, now)}`) + .join("\n"); } |
