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 { computeTarget } from "../../../../../../open-sse/services/compression/adaptiveCompression/computeTarget.ts";
import type { ContextBudgetConfig } from "../../../../../../open-sse/services/compression/adaptiveCompression/types.ts";
/**
* Read-only label for the compression panel (design D-C1 transparency). Shows the active
* policy and the computed token target for a representative model context window. PURE —
* imports only the pure computeTarget leaf, no DB, no clock. The panel renders this string
* as an informational/diagnostic line, mirroring the derived-pipeline preview.
*/
export function formatAdaptiveTarget(
config: ContextBudgetConfig,
representativeModelContextLimit: number
): string {
if (config.mode === "off") return "Adaptive context budget: off (legacy auto-trigger)";
const target = computeTarget(config.policy, representativeModelContextLimit, null, config);
return `Adaptive (${config.mode}, policy: ${config.policy}) — target ≈ ${target.toLocaleString()} tokens (for a ${representativeModelContextLimit.toLocaleString()}-token window)`;
}
export type AdaptiveTargetSummary =
| { enabled: false }
| {
enabled: true;
mode: ContextBudgetConfig["mode"];
policy: ContextBudgetConfig["policy"];
target: number;
contextLimit: number;
};
export function getAdaptiveTargetSummary(
config: ContextBudgetConfig,
representativeModelContextLimit: number
): AdaptiveTargetSummary {
if (config.mode === "off") return { enabled: false };
return {
enabled: true,
mode: config.mode,
policy: config.policy,
target: computeTarget(config.policy, representativeModelContextLimit, null, config),
contextLimit: representativeModelContextLimit,
};
}