Skip to content

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

743 B
Raw Blame
/**
 * opencodeResponseBody.ts — body hygiene for the opencode rotation loop.
 *
 * Leaf module: zero imports. An upstream response the loop decides not to
 * return (a refusal it rotates away from, a failure it pauses after) keeps its
 * connection busy until the body is consumed or cancelled. Cancelling releases
 * the socket right away instead of whenever the Response is garbage-collected.
 */

/**
 * Cancel a response body nobody will read. Never throws. A body that is already
 * locked (a reader holds it) is left to that reader.
 */
export function discardResponseBody(response: Response | null | undefined): void {
  const body = response?.body;
  if (!body || body.locked) return;
  void body.cancel().catch(() => undefined);
}