Files
OmniRoute/open-sse/services/compression/engineBreakdown.ts
Diego Rodrigues de Sa e Souza 3c9883bb73 Release v3.8.29 (#4126)
OmniRoute v3.8.29 — 115 commits since v3.8.28. Full CHANGELOG + 41 i18n mirrors. All content quality gates green (build, unit 8/8, vitest 188/188, PR test policy, quality gates extended, docs sync, quality ratchet). Remaining red CI checks are pre-existing release flakes (coverage-shard/integration/node-compat teardown), a new transitive undici advisory in electron devDeps, and a workflow-level CodeQL fail (0 open alerts). VPS-validated by the operator.
2026-06-19 06:49: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 } : {}),
},
];
}