Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
import assert from "node:assert/strict";
import test from "node:test";
import { applyLossyRequestPolicy } from "../../../open-sse/services/compression/lossyRequestPolicy.ts";
import type { DerivedPlan } from "../../../open-sse/services/compression/deriveDefaultPlan.ts";
const lossyProfile: DerivedPlan = {
mode: "stacked",
source: "active-profile",
stackedPipeline: [
{ engine: "rtk", intensity: "standard" },
{ engine: "caveman", intensity: "full" },
],
};
test("default path replaces a lossy profile with dedup and whitespace folding", () => {
const plan = applyLossyRequestPolicy(lossyProfile, null);
assert.equal(plan.mode, "stacked");
assert.deepEqual(plan.stackedPipeline, [{ engine: "session-dedup" }, { engine: "lite" }]);
});
test("allow-lossy keeps the operator profile for this request", () => {
const plan = applyLossyRequestPolicy(lossyProfile, "allow-lossy");
assert.deepEqual(plan.stackedPipeline, lossyProfile.stackedPipeline);
});
test("engine header is the opt-in for that engine", () => {
const plan = applyLossyRequestPolicy(
{
mode: "rtk",
source: "request-header",
stackedPipeline: [],
},
"engine:rtk"
);
assert.equal(plan.mode, "rtk");
});
test("a safe stacked plan is left as-is", () => {
const safe: DerivedPlan = {
mode: "stacked",
source: "default",
stackedPipeline: [{ engine: "lite" }],
};
assert.equal(applyLossyRequestPolicy(safe, null), safe);
});