import type { SuperagentConnector } from '../../types'; // Popularity rank for sorting: lower = more popular (1 is top). Missing or 0 // sorts last, mirroring the web catalog's "popular" sort (see // apps/builder/src/constants/connectors — read, don't import: native boundary). export function connectorPopularityRank(connector: SuperagentConnector): number { return connector.popularity && connector.popularity > 0 ? connector.popularity : Number.POSITIVE_INFINITY; } // Sort by popularity ascending, then name, so unranked connectors fall to the // bottom in a stable alphabetical order. export function sortConnectorsByPopularity(connectors: SuperagentConnector[]): SuperagentConnector[] { return [...connectors].sort((a, b) => { const rankA = connectorPopularityRank(a); const rankB = connectorPopularityRank(b); if (rankA !== rankB) { return rankA - rankB; } return (a.name ?? '').localeCompare(b.name ?? ''); }); }