Files
OmniRoute/open-sse/services/compression/engineBreakdown.ts
Diego Rodrigues de Sa e Souza 1cdbf73925 feat(compression): show an engine node for single-engine runs in the studio (#4210)
Integrated into release/v3.8.29 (round 7). Studio shows a real engine node for single-engine compression runs via ensureEngineBreakdown (new pure leaf engineBreakdown.ts). Reconciled the file-size baseline (chatCore.ts 5060->5063) + union-merged with the #4202 zenmux rebaseline key after release drift. Validated locally: file-size gate OK + 3/3 tests + typecheck:core clean.
2026-06-18 20:23:01 -03:00

30 lines
1.3 KiB
TypeScript

import type { CompressionStats } from "./types.ts";
export type EngineBreakdownEntry = NonNullable<CompressionStats["engineBreakdown"]>[number];
/**
* Return a non-empty per-engine breakdown for the live `compression.completed` event.
*
* Only the stacked pipeline fills `stats.engineBreakdown`; single-engine modes
* (rtk/lite/standard/aggressive/ultra) leave it empty, which makes the dashboard studio render
* an empty Input→Output pipeline (no engine node, inert replay) for the most common case. When
* the breakdown is empty we synthesize a single entry from the overall stats so the studio
* always shows at least one real engine node. Mirrors `seedLatestCompressionRunFromDb`.
*/
export function ensureEngineBreakdown(stats: CompressionStats): EngineBreakdownEntry[] {
if (stats.engineBreakdown && stats.engineBreakdown.length > 0) {
return stats.engineBreakdown;
}
return [
{
engine: stats.engine || stats.mode || "compression",
originalTokens: stats.originalTokens,
compressedTokens: stats.compressedTokens,
savingsPercent: stats.savingsPercent,
techniquesUsed: stats.techniquesUsed ?? [],
...(stats.rulesApplied ? { rulesApplied: stats.rulesApplied } : {}),
...(stats.durationMs !== undefined ? { durationMs: stats.durationMs } : {}),
},
];
}