Files
OmniRoute/open-sse/services/compression/deriveDefaultPlan.ts
Jan Leon fb6ea295bf feat(compression): add Responses tool-output engine (#8010)
* Add Responses tool-output compression engine

* fix: enable Codex Responses stacked steps

* fix(compression): share Codex tokenizer and rebase UI

* fix(compression): sync MCP engine selection

* fix(compression): i18n parity for codex-responses mode + rebaseline

The codex-responses compression engine already imports the shared
countTextTokens/resolveTokenizerEncoding from tiktokenCounter.ts (no
duplicate encoder) and CompressionSettingsTab.tsx already threads the
new mode through the existing useTranslations()/labelKey pattern - both
pre-existing on this branch tip after rebasing onto release/v3.8.49.

What was missing after the rebase: the new compressionModeCodexResponses
/ compressionModeCodexResponsesDesc keys existed only in en.json. Filled
en-fallback into all 42 locales via scripts/i18n/fill-missing-from-en.mjs
and added real pt-BR/vi translations. Also rebaselined the three files
whose own growth (new codex-responses mode wiring) crossed the frozen
file-size caps: open-sse/mcp-server/schemas/tools.ts, open-sse/services/
compression/strategySelector.ts, and src/lib/db/compression.ts.

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

---------

Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouza.pw@gmail.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
2026-07-22 07:03:02 -03:00

57 lines
2.0 KiB
TypeScript

import { ENGINE_CATALOG, engineMeta } from "./engineCatalog.ts";
import type { EngineToggle } from "./types.ts";
/** Maps single-mode engine ids to the effective CompressionMode name. */
const SINGLE_MODE_OF: Record<string, string> = {
lite: "lite",
caveman: "standard",
aggressive: "aggressive",
ultra: "ultra",
rtk: "rtk",
"codex-responses": "codex-responses",
omniglyph: "omniglyph",
};
export type CompressionSource =
"request-header" | "routing-override" | "active-profile" | "auto-trigger" | "default" | "off";
export interface DerivedPlan {
mode: string;
stackedPipeline: Array<{ engine: string; intensity?: string }>;
/** Which precedence layer decided this plan (Phase 3 observability). Optional so
* Phase 1/2 callers and snapshots are unaffected. */
source?: CompressionSource;
}
/**
* Derives the effective compression plan from the per-engine toggle map.
*
* Rules (evaluated in order):
* 1. masterEnabled=false OR no engines on → { mode:"off", stackedPipeline:[] }
* 2. Exactly one engine on AND it is single-mode → that engine's standalone mode
* 3. Otherwise → { mode:"stacked", stackedPipeline: enabled engines sorted by stackPriority }
*/
export function deriveDefaultPlan(
engines: Record<string, EngineToggle>,
masterEnabled: boolean
): DerivedPlan {
if (!masterEnabled) return { mode: "off", stackedPipeline: [] };
const onIds = Object.keys(ENGINE_CATALOG).filter((id) => engines[id]?.enabled === true);
if (onIds.length === 0) return { mode: "off", stackedPipeline: [] };
if (onIds.length === 1 && engineMeta(onIds[0]).isSingleMode) {
return { mode: SINGLE_MODE_OF[onIds[0]], stackedPipeline: [] };
}
const ordered = onIds.sort((a, b) => engineMeta(a).stackPriority - engineMeta(b).stackPriority);
const stackedPipeline = ordered.map((id) => {
const level = engines[id]?.level;
return level ? { engine: id, intensity: level } : { engine: id };
});
return { mode: "stacked", stackedPipeline };
}