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>
132 lines
4.1 KiB
TypeScript
132 lines
4.1 KiB
TypeScript
import { describe, it, afterEach } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
|
|
import {
|
|
applyCompression,
|
|
maybePersistRtkRawOutput,
|
|
processRtkText,
|
|
readRtkRawOutput,
|
|
redactRtkRawOutput,
|
|
} from "../../../open-sse/services/compression/index.ts";
|
|
|
|
const originalDataDir = process.env.DATA_DIR;
|
|
|
|
afterEach(() => {
|
|
if (originalDataDir === undefined) delete process.env.DATA_DIR;
|
|
else process.env.DATA_DIR = originalDataDir;
|
|
});
|
|
|
|
describe("RTK raw output retention", () => {
|
|
it("redacts secrets before raw output persistence and exposes a pointer", () => {
|
|
const tempData = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-rtk-raw-"));
|
|
process.env.DATA_DIR = tempData;
|
|
const raw = [
|
|
"Error: failed with token=sk-1234567890abcdefghijklmnop",
|
|
...Array.from({ length: 40 }, () => "same noisy line"),
|
|
].join("\n");
|
|
|
|
const result = processRtkText(raw, {
|
|
command: "custom",
|
|
config: {
|
|
rawOutputRetention: "always",
|
|
maxLinesPerResult: 2,
|
|
maxCharsPerResult: 120,
|
|
},
|
|
});
|
|
|
|
assert.equal(result.compressed, true);
|
|
assert.equal(result.rawOutputPointers?.length, 1);
|
|
const pointer = result.rawOutputPointers?.[0];
|
|
assert.ok(pointer);
|
|
const recovered = readRtkRawOutput(pointer.id);
|
|
assert.ok(recovered);
|
|
assert.ok(recovered.includes("[REDACTED"));
|
|
assert.ok(!recovered.includes("sk-1234567890abcdefghijklmnop"));
|
|
});
|
|
|
|
it("keeps raw output disabled by default", () => {
|
|
const redacted = redactRtkRawOutput("Authorization: Bearer secret-token-value");
|
|
assert.equal(redacted.redacted, true);
|
|
assert.ok(!redacted.text.includes("secret-token-value"));
|
|
|
|
const result = processRtkText("line\nline\nline\nline", {
|
|
config: { maxLinesPerResult: 1 },
|
|
});
|
|
|
|
assert.equal(result.rawOutputPointers, undefined);
|
|
});
|
|
|
|
it("retains only configured failure output and enforces byte caps", () => {
|
|
const tempData = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-rtk-raw-cap-"));
|
|
process.env.DATA_DIR = tempData;
|
|
|
|
assert.equal(
|
|
maybePersistRtkRawOutput("ordinary successful output", { retention: "failures" }),
|
|
null
|
|
);
|
|
|
|
const pointer = maybePersistRtkRawOutput("error: " + "x".repeat(5000), {
|
|
retention: "failures",
|
|
maxBytes: 64,
|
|
});
|
|
assert.ok(pointer);
|
|
const recovered = readRtkRawOutput(pointer.id);
|
|
assert.ok(recovered?.includes("truncated at 1024 bytes"));
|
|
assert.equal(readRtkRawOutput("0123456789abcdef01234567"), null);
|
|
});
|
|
|
|
it("propagates raw output pointers from stacked RTK runs", () => {
|
|
const tempData = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-rtk-stacked-raw-"));
|
|
process.env.DATA_DIR = tempData;
|
|
|
|
const result = applyCompression(
|
|
{
|
|
messages: [
|
|
{
|
|
role: "tool",
|
|
content: [
|
|
"Error: failed with Authorization: Bearer secret-token-value",
|
|
...Array.from({ length: 40 }, () => "same noisy line"),
|
|
].join("\n"),
|
|
},
|
|
],
|
|
},
|
|
"stacked",
|
|
{
|
|
config: {
|
|
enabled: true,
|
|
defaultMode: "stacked",
|
|
autoTriggerTokens: 0,
|
|
cacheMinutes: 5,
|
|
preserveSystemPrompt: true,
|
|
comboOverrides: {},
|
|
rtkConfig: {
|
|
enabled: true,
|
|
intensity: "standard",
|
|
applyToToolResults: true,
|
|
applyToCodeBlocks: false,
|
|
applyToAssistantMessages: false,
|
|
enabledFilters: [],
|
|
disabledFilters: [],
|
|
maxLinesPerResult: 2,
|
|
maxCharsPerResult: 120,
|
|
deduplicateThreshold: 3,
|
|
customFiltersEnabled: true,
|
|
trustProjectFilters: false,
|
|
rawOutputRetention: "always",
|
|
rawOutputMaxBytes: 1_048_576,
|
|
},
|
|
stackedPipeline: [{ engine: "rtk", intensity: "standard" }],
|
|
},
|
|
}
|
|
);
|
|
|
|
const pointer = result.stats?.rtkRawOutputPointers?.[0];
|
|
assert.ok(pointer);
|
|
assert.ok(readRtkRawOutput(pointer.id)?.includes("[REDACTED"));
|
|
});
|
|
});
|