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
"use strict";
// =========================================================================
// Decide where the standalone proxy (server.cjs) forwards an intercepted,
// decrypted request — and which router endpoint speaks its wire format.
//
// The Antigravity IDE sends a cloudcode envelope:
// { model, project, request: { contents, systemInstruction, tools, ... } }
// and expects a cloudcode SSE reply ({ response: { candidates, ... } }).
// That envelope is forwarded to the antigravity-compatible endpoint
// (/v1/antigravity), where the pipeline translates request antigravity→openai
// and response openai→antigravity, so the IDE gets its own format back
// regardless of which provider actually served it.
//
// Plain OpenAI bodies ({ messages: [...] }) keep going to /v1/chat/completions.
//
// Pure + deterministic so it is unit-testable without the proxy.
// =========================================================================
const CHAT_PATH = "/v1/chat/completions";
const ANTIGRAVITY_PATH = "/v1/antigravity";
/**
* True when the parsed body is an Antigravity/cloudcode envelope (the IDE wraps
* the Gemini-style payload under `request`, with a `contents` array).
*/
function isCloudcodeEnvelope(body) {
return !!(
body &&
typeof body === "object" &&
!Array.isArray(body) &&
body.request &&
typeof body.request === "object" &&
Array.isArray(body.request.contents)
);
}
/**
* Resolve the forward URL + the format the IDE expects back. `baseUrl` is the
* router base (e.g. http://localhost:20128); trailing slashes are trimmed.
*/
function resolveForwardTarget(baseUrl, body) {
const base = String(baseUrl || "").replace(/\/+$/, "");
if (isCloudcodeEnvelope(body)) {
return { url: `${base}${ANTIGRAVITY_PATH}`, format: "antigravity" };
}
return { url: `${base}${CHAT_PATH}`, format: "openai" };
}
module.exports = {
resolveForwardTarget,
isCloudcodeEnvelope,
CHAT_PATH,
ANTIGRAVITY_PATH,
};