mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 20:32:20 +03:00
* chore(rtk): initialize compression roadmap branch * feat(compression): add RTK engine and compression combos Introduce RTK command-aware tool-output compression alongside stacked RTK -> Caveman pipelines for mixed prompt contexts. Add engine registration, declarative RTK filter packs, language-aware Caveman rule loading, compression combo persistence and assignments, analytics grouped by engine/combo, and new MCP/API endpoints for configuration, previews, filters, and combo management. Expose the new capabilities in the dashboard with dedicated Context & Cache pages for Caveman, RTK, and compression combos, and update docs, i18n strings, migrations, and tests to cover the expanded compression surface. * feat(compression): expand RTK DSL, filter catalog, and recovery APIs Add RTK parity features across the compression pipeline, dashboard, and management APIs. This expands the built-in filter catalog, adds trust-gated custom filter loading, inline filter verification, code stripping, smarter detection, and optional redacted raw-output retention for authenticated recovery. Also extend Caveman with file-based multilingual rule packs, localized output-mode instructions, stricter preview/config schemas, engine registry metadata, analytics fields, and broad unit test coverage for RTK, rule loading, and stacked compression behavior. * fix(auth): protect oauth routes and health reset operations Require authenticated dashboard access for OAuth endpoints that can create or import provider connections when login enforcement is enabled. Move `/api/monitoring/health` to the readonly public route list so safe methods remain public while DELETE now returns 401 for anonymous requests. Also update Next.js native `.node` handling to avoid webpack parse failures from external packages such as ngrok and keytar, and add coverage for the new auth behavior. * build(compression): ship RTK rule and filter assets with app bundles Include compression JSON assets in Next output tracing, prepublish copies, and pack artifact policy checks so standalone and packaged builds can load RTK filters and caveman rule packs at runtime. Also harden compression runtime behavior by resolving alternate asset directories, scoping rule cache entries by source path, carrying RTK raw output pointers through stacked runs, degrading oversized preview diffs, and applying combo language/output mode defaults during chat routing. Add coverage for packaging rules, provider-scoped model parsing, smart truncate edge cases, raw output retention, and combo-driven compression behavior. * docs(workflows): update local repo paths to OmniRoute Replace outdated `/home/diegosouzapw/dev/proxys/9router` references with the current `OmniRoute` directory across deploy, release, and version bump workflow guides so local command examples match the renamed repository layout * feat(compression): complete RTK parity coverage * test(build): align next config assertions --------- Co-authored-by: diegosouzapw <diego.souza.pw@gmail.com>
193 lines
6.1 KiB
TypeScript
193 lines
6.1 KiB
TypeScript
import { describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
selectCompressionStrategy,
|
|
getEffectiveMode,
|
|
applyCompression,
|
|
checkComboOverride,
|
|
shouldAutoTrigger,
|
|
} from "../../../open-sse/services/compression/strategySelector.ts";
|
|
import type { CompressionConfig } from "../../../open-sse/services/compression/types.ts";
|
|
|
|
const baseConfig: CompressionConfig = {
|
|
enabled: true,
|
|
defaultMode: "lite",
|
|
autoTriggerTokens: 0,
|
|
cacheMinutes: 5,
|
|
preserveSystemPrompt: true,
|
|
comboOverrides: {},
|
|
};
|
|
|
|
describe("checkComboOverride", () => {
|
|
it("returns null when comboId is null", () => {
|
|
assert.equal(checkComboOverride(baseConfig, null), null);
|
|
});
|
|
|
|
it("returns null when comboOverrides is empty", () => {
|
|
assert.equal(checkComboOverride(baseConfig, "my-combo"), null);
|
|
});
|
|
|
|
it("returns mode when combo override exists", () => {
|
|
const config = { ...baseConfig, comboOverrides: { "my-combo": "off" as const } };
|
|
assert.equal(checkComboOverride(config, "my-combo"), "off");
|
|
});
|
|
|
|
it("returns null for non-existent combo", () => {
|
|
const config = { ...baseConfig, comboOverrides: { "other-combo": "lite" as const } };
|
|
assert.equal(checkComboOverride(config, "my-combo"), null);
|
|
});
|
|
});
|
|
|
|
describe("shouldAutoTrigger", () => {
|
|
it("returns false when autoTriggerTokens is 0", () => {
|
|
assert.equal(shouldAutoTrigger(baseConfig, 5000), false);
|
|
});
|
|
|
|
it("returns false when tokens below threshold", () => {
|
|
const config = { ...baseConfig, autoTriggerTokens: 1000 };
|
|
assert.equal(shouldAutoTrigger(config, 500), false);
|
|
});
|
|
|
|
it("returns true when tokens at threshold", () => {
|
|
const config = { ...baseConfig, autoTriggerTokens: 1000 };
|
|
assert.equal(shouldAutoTrigger(config, 1000), true);
|
|
});
|
|
|
|
it("returns true when tokens above threshold", () => {
|
|
const config = { ...baseConfig, autoTriggerTokens: 1000 };
|
|
assert.equal(shouldAutoTrigger(config, 1500), true);
|
|
});
|
|
});
|
|
|
|
describe("getEffectiveMode", () => {
|
|
it("returns off when not enabled", () => {
|
|
const config = { ...baseConfig, enabled: false };
|
|
assert.equal(getEffectiveMode(config, null, 100), "off");
|
|
});
|
|
|
|
it("keeps disabled config off despite combo override and auto-trigger", () => {
|
|
const config = {
|
|
...baseConfig,
|
|
enabled: false,
|
|
autoTriggerTokens: 100,
|
|
comboOverrides: { "my-combo": "lite" as const },
|
|
};
|
|
|
|
assert.equal(getEffectiveMode(config, "my-combo", 500), "off");
|
|
});
|
|
|
|
it("returns default mode when no overrides", () => {
|
|
assert.equal(getEffectiveMode(baseConfig, null, 100), "lite");
|
|
});
|
|
|
|
it("returns combo override mode when present", () => {
|
|
const config = {
|
|
...baseConfig,
|
|
defaultMode: "off" as const,
|
|
comboOverrides: { "my-combo": "lite" as const },
|
|
};
|
|
assert.equal(getEffectiveMode(config, "my-combo", 100), "lite");
|
|
});
|
|
|
|
it("returns lite when auto-trigger threshold reached", () => {
|
|
const config = { ...baseConfig, defaultMode: "off" as const, autoTriggerTokens: 1000 };
|
|
assert.equal(getEffectiveMode(config, null, 1500), "lite");
|
|
});
|
|
|
|
it("combo override takes precedence over auto-trigger", () => {
|
|
const config = {
|
|
...baseConfig,
|
|
defaultMode: "off" as const,
|
|
autoTriggerTokens: 100,
|
|
comboOverrides: { "my-combo": "off" as const },
|
|
};
|
|
assert.equal(getEffectiveMode(config, "my-combo", 500), "off");
|
|
});
|
|
});
|
|
|
|
describe("selectCompressionStrategy", () => {
|
|
it("returns effective mode", () => {
|
|
assert.equal(selectCompressionStrategy(baseConfig, null, 100), "lite");
|
|
});
|
|
|
|
it("downgrades aggressive cache-control requests for caching-aware providers", () => {
|
|
const config = { ...baseConfig, defaultMode: "aggressive" as const };
|
|
const body = {
|
|
messages: [
|
|
{
|
|
role: "user",
|
|
content: [{ type: "text", text: "cached", cache_control: { type: "ephemeral" } }],
|
|
},
|
|
],
|
|
};
|
|
|
|
assert.equal(
|
|
selectCompressionStrategy(config, null, 100, body, {
|
|
provider: "anthropic",
|
|
targetFormat: "claude",
|
|
model: "claude-3-5-sonnet",
|
|
}),
|
|
"standard"
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("applyCompression", () => {
|
|
it("returns unchanged body for off mode", () => {
|
|
const body = { messages: [{ role: "user", content: "test" }] };
|
|
const result = applyCompression(body, "off");
|
|
assert.equal(result.compressed, false);
|
|
assert.equal(result.stats, null);
|
|
assert.deepEqual(result.body, body);
|
|
});
|
|
|
|
it("applies lite compression for lite mode", () => {
|
|
const body = { messages: [{ role: "user", content: "test\n\n\n\nmessage" }] };
|
|
const result = applyCompression(body, "lite");
|
|
assert.equal(result.compressed, true);
|
|
assert.ok(result.stats);
|
|
assert.equal(result.stats.mode, "lite");
|
|
});
|
|
|
|
it("returns unchanged body for standard mode (Phase 2)", () => {
|
|
const body = { messages: [{ role: "user", content: "test" }] };
|
|
const result = applyCompression(body, "standard");
|
|
assert.equal(result.compressed, false);
|
|
});
|
|
|
|
it("applies rtk compression to tool output", () => {
|
|
const body = {
|
|
messages: [
|
|
{
|
|
role: "tool",
|
|
content: Array.from({ length: 20 }, () => "same noisy line").join("\n"),
|
|
},
|
|
],
|
|
};
|
|
const result = applyCompression(body, "rtk");
|
|
assert.equal(result.stats?.mode, "rtk");
|
|
assert.equal(result.stats?.engine, "rtk");
|
|
assert.equal(result.compressed, true);
|
|
});
|
|
|
|
it("applies stacked compression with RTK followed by Caveman", () => {
|
|
const body = {
|
|
messages: [
|
|
{
|
|
role: "tool",
|
|
content: Array.from({ length: 20 }, () => "same noisy line").join("\n"),
|
|
},
|
|
{
|
|
role: "user",
|
|
content: "Could you please explain in detail what I need to do?",
|
|
},
|
|
],
|
|
};
|
|
const result = applyCompression(body, "stacked");
|
|
assert.equal(result.stats?.mode, "stacked");
|
|
assert.equal(result.stats?.engine, "stacked");
|
|
assert.ok(result.stats?.engineBreakdown?.some((entry) => entry.engine === "rtk"));
|
|
assert.ok(result.stats?.engineBreakdown?.some((entry) => entry.engine === "caveman"));
|
|
});
|
|
});
|