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 { resolveProxyForConnection } from "@/lib/db/settings";
import { hasBlockingProxyAssignment } from "@/lib/db/proxies";
/**
* #13470: fail-closed guard for the token-health-check sweep, mirroring the #6246
* contract the interactive chat/executor path enforces via
* `safeResolveProxy`/`hasBlockingProxyAssignment` (src/sse/handlers/chatHelpers.ts).
* Before this guard, the sweep called `resolveProxyForConnection` directly and a
* connection whose assigned proxy pool had gone fully dead resolved silently to
* direct/env-proxy egress — leaking the refresh-token exchange on the real IP.
* Callers must skip (log + return) rather than throw: this sweeps many connections
* per tick and one blocked connection must not abort the rest.
*/
export async function resolveGuardedProxyConfig(
connectionId: string,
provider?: string
): Promise<{ proxyConfig: unknown; blocked: boolean }> {
const resolved = (await resolveProxyForConnection(connectionId)) as { proxy?: unknown } | null;
const proxyConfig = resolved?.proxy ?? null;
if (!proxyConfig && hasBlockingProxyAssignment(connectionId, provider)) {
return { proxyConfig: null, blocked: true };
}
return { proxyConfig, blocked: false };
}