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
import {
  getDeprecationNotice,
  isDeprecatedProvider,
} from "@omniroute/open-sse/services/tokenRefresh.ts";

export function isOrphanDeprecatedConnection(conn: { provider?: string | null }): boolean {
  return isDeprecatedProvider(String(conn.provider || ""));
}

export type DeprecatedProviderLeftoverGroup = {
  provider: string;
  migrateTo: string;
  reason: string;
  connectionIds: string[];
  names: string[];
};

export function listDeprecatedProviderLeftovers(
  connections: Array<{
    id: string;
    provider?: string | null;
    name?: string | null;
  }>
): DeprecatedProviderLeftoverGroup[] {
  const groups = new Map<string, DeprecatedProviderLeftoverGroup>();

  for (const conn of connections) {
    if (!isOrphanDeprecatedConnection(conn)) continue;
    const provider = String(conn.provider || "");
    const notice = getDeprecationNotice(provider);
    if (!notice) continue;

    let group = groups.get(provider);
    if (!group) {
      group = {
        provider,
        migrateTo: notice.migrateTo,
        reason: notice.reason,
        connectionIds: [],
        names: [],
      };
      groups.set(provider, group);
    }
    group.connectionIds.push(conn.id);
    group.names.push(typeof conn.name === "string" ? conn.name : "");
  }

  return [...groups.values()].filter((group) => group.connectionIds.length > 0);
}