openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 4.06 kB
JavaScript
import{b as uniqueStrings}from"./string-normalization-D_oBUpO3.mjs";import{r as normalizeProviderId}from"./provider-id-A-8WTtLA.mjs";import{t as isUserModelAuthProfileId}from"./user-model-account-id-CU4k7NMV.mjs";import{i as resolveCollapsedSessionAuthPinSource}from"./auth-profile-override-provenance-D5ZYWRNQ.mjs";import{S as shouldPreferExplicitConfigApiKeyAuth,b as resolveUsableCustomProviderApiKey,v as resolveProviderEntryApiKeyProfileReference}from"./model-auth-provider-config-KlOdxZHz.mjs";import{u as readCodexCliCredentialsCached}from"./external-cli-sync-C2s6hWdT.mjs";import{a as resolveAuthProfileOrder,n as isStoredCredentialCompatibleWithAuthProvider}from"./order-B8e_5ABM.mjs";import{n as externalCliDiscoveryForProviderAuth}from"./external-cli-discovery-CHmIqgrd.mjs";import{t as resolveEnvApiKey}from"./model-auth-env-B6Hhnpzd.mjs";import{c as ensureAuthProfileStoreWithoutExternalProfilesAsync,h as loadAuthProfileStoreWithoutExternalProfiles,i as ensureAuthProfileStoreAsync,r as ensureAuthProfileStore}from"./store-runtime-GNz-2GjY.mjs";import{n as resolveAuthProfileDisplayLabel}from"./display-_lnk7MT7.mjs";import"./auth-profiles-nMUErGRQ.mjs";import"./model-auth-C99Q9Dp8.mjs";
//!src/agents/model-auth-label.ts
function resolveModelAuthLabel(e){if(!e.provider?.trim())return;const t=e.sessionEntry?.authProfileOverride?.trim();return resolveModelAuthLabelFromStore(e,e.authStore??(e.includeExternalProfiles===false?loadAuthProfileStoreWithoutExternalProfiles(e.agentDir,{profileId:t}):ensureAuthProfileStore(e.agentDir,{profileId:t,externalCli:externalCliDiscoveryForProviderAuth({cfg:e.cfg,provider:normalizeProviderId(e.provider??``),preferredProfile:t})})))}async function resolveModelAuthLabelAsync(e){if(!e.provider?.trim())return;const t=e.sessionEntry?.authProfileOverride?.trim();return resolveModelAuthLabelFromStore(e,e.authStore??(e.includeExternalProfiles===false?await ensureAuthProfileStoreWithoutExternalProfilesAsync(e.agentDir,{profileId:t}):await ensureAuthProfileStoreAsync(e.agentDir,{profileId:t,externalCli:externalCliDiscoveryForProviderAuth({cfg:e.cfg,provider:normalizeProviderId(e.provider),preferredProfile:t})})))}function resolveModelAuthLabelFromStore(e,t){const n=e.provider?.trim();if(!n)return;const r=normalizeProviderId(n);const i=e.sessionEntry?.authProfileOverride?.trim();const a=uniqueStrings([...(e.acceptedProviderIds??[]).map(normalizeProviderId),r].filter(Boolean));const o=[i,...uniqueStrings(a.flatMap(n=>resolveAuthProfileOrder({cfg:e.cfg,store:t,provider:n,preferredProfile:i})))].filter(Boolean);const s=resolveProviderEntryApiKeyProfileReference({cfg:e.cfg,provider:r,store:t});if(resolveCollapsedSessionAuthPinSource(e.sessionEntry)!==`user`&&s.kind===`literal`&&shouldPreferExplicitConfigApiKeyAuth(e.cfg,r))return`api-key (models.json)`;for(const n of o){const r=t.profiles[n];if(!r||!a.some(t=>isStoredCredentialCompatibleWithAuthProvider({cfg:e.cfg,provider:t,credential:r})))continue;const i=isUserModelAuthProfileId(n)?`personal account`:resolveAuthProfileDisplayLabel({cfg:e.cfg,store:t,profileId:n});return`${r.type===`api_key`?`api-key`:r.type}${i?` (${i})`:``}`}if(s.kind===`profile`){const n=resolveAuthProfileDisplayLabel({cfg:e.cfg,store:t,profileId:s.profileId});return`${s.mode===`token`?`token`:`api-key`}${n?` (${n})`:``}`}if(s.kind===`profile-incompatible`)return`unknown`;if(e.codexCliCredentialsHome&&(r===`openai`||r===`codex`)&&readCodexCliCredentialsCached({codexHome:e.codexCliCredentialsHome,ttlMs:5e3,allowKeychainPrompt:false}))return`oauth (codex-cli)`;const c=resolveEnvApiKey(r,process.env,{config:e.cfg,workspaceDir:e.workspaceDir});if(c?.apiKey)return`${c.source.includes(`OAUTH_TOKEN`)?`oauth`:`api-key`} (${c.source})`;if(r===`codex`&&readCodexCliCredentialsCached({ttlMs:5e3,allowKeychainPrompt:false}))return`oauth (codex-cli)`;if(r===`claude-cli`)return`native (claude-cli)`;if(resolveUsableCustomProviderApiKey({cfg:e.cfg,provider:r}))return`api-key (models.json)`;return`unknown`}export{resolveModelAuthLabelAsync as n,resolveModelAuthLabel as t};