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.3 KB
Raw Blame
/**
 * chatCore connection-level upstream overrides (chatCore god-file decomposition, slice 2).
 *
 * Extracted byte-identically from handleChatCore: read the connection's custom User-Agent (trimmed,
 * "" when unset) and its custom upstream headers (#8369) from provider_specific_data. Both feed
 * buildUpstreamHeadersForExecute.
 */

type ProviderSpecificDataLike = { customUserAgent?: unknown; customHeaders?: unknown };

export function resolveConnectionUpstreamOverrides(
  providerSpecificData: ProviderSpecificDataLike | null | undefined
): {
  connectionCustomUserAgent: string;
  connectionCustomHeaders: Record<string, string> | undefined;
} {
  const connectionCustomUserAgent =
    providerSpecificData &&
    typeof providerSpecificData === "object" &&
    typeof providerSpecificData.customUserAgent === "string"
      ? providerSpecificData.customUserAgent.trim()
      : "";

  // #8369: connection-level custom upstream headers from provider_specific_data.
  const connectionCustomHeaders =
    providerSpecificData &&
    typeof providerSpecificData === "object" &&
    typeof providerSpecificData.customHeaders === "object" &&
    !Array.isArray(providerSpecificData.customHeaders)
      ? (providerSpecificData.customHeaders as Record<string, string>)
      : undefined;
  return { connectionCustomUserAgent, connectionCustomHeaders };
}