UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

53 lines • 2.6 kB
/** * True when a provider is available only through a shared cloud credential chain (ambient AWS * env, Google ADC). Such a provider stays selectable but never outranks one the user configured * (senpi#2327). Compatibility sources without auth status report every provider as configured. */ export function isAmbientOnlyProvider(source, providerId) { return source.getProviderAuthStatus?.(providerId).ambient === true; } export function createAmbientProviderCheck(source) { const cache = new Map(); return (providerId) => { let ambient = cache.get(providerId); if (ambient === undefined) { ambient = isAmbientOnlyProvider(source, providerId); cache.set(providerId, ambient); } return ambient; }; } /** * Metered API lane -> the subscription-plan lanes that sell the same vendor's models. When both are * available, the automatic default takes the plan, whatever order `providerDefaults` declares. */ const SUBSCRIPTION_LANES = { openai: ["chatgpt-subscription"], anthropic: ["anthropic-subscription"], moonshotai: ["kimi-coding"], "moonshotai-cn": ["kimi-coding"], xiaomi: ["xiaomi-token-plan-cn", "xiaomi-token-plan-ams", "xiaomi-token-plan-sgp"], }; /** * The automatic default among available models. Models from providers the user configured are * considered first; ambient-only providers only when nothing else is available. Within that group * the first `providerDefaults` entry (declared order) that is available wins, except that an * available subscription lane of that entry's provider wins over it; else the group's first * available model. */ export function selectProviderDefault(availableModels, providerDefaults, source) { const isAmbient = createAmbientProviderCheck(source); const configured = availableModels.filter((model) => !isAmbient(model.provider)); const group = configured.length > 0 ? configured : availableModels; const defaultOf = (provider) => group.find((model) => model.provider === provider && model.id === providerDefaults[provider]); for (const provider of Object.keys(providerDefaults)) { const match = defaultOf(provider); if (!match) continue; const subscription = SUBSCRIPTION_LANES[provider]?.map(defaultOf).find((model) => model !== undefined); return { model: subscription ?? match, provenance: "provider-default" }; } const first = group[0]; return first ? { model: first, provenance: "first-available" } : undefined; } //# sourceMappingURL=provider-default-selection.js.map