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

1.1 KB
Raw Blame
/**
 * #13945: getProviderCredentials() can return a truthy "diagnostic sentinel"
 * object instead of null or real credentials whenever every connection for a
 * provider is terminally unusable — allExpired, allRateLimited,
 * blockedByKeyPolicy, or leaseConnectionMismatch. The chat path
 * (src/sse/handlers/chatHelpers.ts::handleNoCredentials) checks each of
 * those fields explicitly, but callers outside the chat path have
 * historically tested the return value by plain truthiness
 * (`if (creds) return creds;`), which treats the sentinel as usable
 * credentials.
 *
 * This guard centralizes that check so every non-chat caller can treat a
 * sentinel exactly like `null` instead of duplicating (and potentially
 * missing a field of) the truthiness test.
 */
export function isCredentialDiagnosticSentinel(value: unknown): boolean {
  if (!value || typeof value !== "object") return false;
  const record = value as Record<string, unknown>;
  return Boolean(
    record.allRateLimited ||
    record.allExpired ||
    record.blockedByKeyPolicy ||
    record.leaseConnectionMismatch
  );
}