openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 4.14 kB
JavaScript
import{V as timestampMsToIsoString}from"./number-coercion-B3CfI447.mjs";import{o as writeRuntimeJson}from"./runtime-DIcLIHcp.mjs";import{r as terminalText}from"./safe-text-B_QTgn0s.mjs";import{f as shortenHomePath}from"./utils-Dlk0IYAa.mjs";import{_ as isActiveUnusableWindow,w as readAuthProfileUsageStats}from"./user-model-account-authority-B8H7rvCb.mjs";import{i as resolveProviderIdForAuth}from"./provider-auth-aliases-BRA1A5Vm.mjs";import{a as buildAuthProfileUnusableHint}from"./oauth-refresh-failure-BdZMhNvV.mjs";import{n as externalCliDiscoveryForProviderAuth}from"./external-cli-discovery-CHmIqgrd.mjs";import{i as ensureAuthProfileStoreAsync}from"./store-runtime-GNz-2GjY.mjs";import{t as resolveAuthStatePathForDisplay}from"./paths-BDkFWGjX.mjs";import{n as resolveAuthProfileDisplayLabel}from"./display-_lnk7MT7.mjs";import"./auth-profiles-nMUErGRQ.mjs";import{l as resolveModelsTargetAgent}from"./shared-Sc7lnGKV.mjs";import{t as loadModelsConfig}from"./load-config-BZk4Hyvt.mjs";
//!src/commands/models/auth-list.ts
async function modelsAuthListCommand(e,t){const n=await loadModelsConfig({commandName:`models auth list`,runtime:t});const{agentId:r,agentDir:i}=resolveModelsTargetAgent(n,e.agent,{kind:`read`});const a=e.provider?.trim()?resolveProviderIdForAuth(e.provider):void 0;const o=await ensureAuthProfileStoreAsync(i,a?{externalCli:externalCliDiscoveryForProviderAuth({cfg:n,provider:a})}:void 0);const s=[];for(const[e,t]of Object.entries(o.profiles)){const r=readAuthProfileUsageStats(o,e);const i=t.type===`api_key`?void 0:timestampMsToIsoString(t.expires);const a=Date.now();const c=isActiveUnusableWindow(r?.blockedUntil,a)?timestampMsToIsoString(r?.blockedUntil):void 0;const l=r?.blockedScope===`model`?r.blockedModel:void 0;const u=isActiveUnusableWindow(r?.cooldownUntil,a)?timestampMsToIsoString(r?.cooldownUntil):void 0;const d=isActiveUnusableWindow(r?.disabledUntil,a)?timestampMsToIsoString(r?.disabledUntil):void 0;const f=Boolean(d);const p=f?r?.disabledReason:u?r?.cooldownReason:void 0;const m=d||u?buildAuthProfileUnusableHint({kind:f?`disabled`:`cooldown`,reason:p,provider:t.provider,profileId:e}):void 0;s.push({id:e,provider:resolveProviderIdForAuth(t.provider),type:t.type,label:resolveAuthProfileDisplayLabel({cfg:n,store:o,profileId:e}),...t.email?{email:t.email}:{},...t.displayName?{displayName:t.displayName}:{},...i?{expiresAt:i}:{},...c?{blockedUntil:c,...r?.blockedReason?{blockedReason:r.blockedReason}:{},...r?.blockedSource?{blockedSource:r.blockedSource}:{},blockedScope:l?`model`:`profile`,...l?{blockedModel:l}:{}}:{},...u?{cooldownUntil:u}:{},...d?{disabledUntil:d}:{},...u&&r?.cooldownReason?{cooldownReason:r.cooldownReason}:{},...u&&r?.cooldownClassification?{cooldownClassification:r.cooldownClassification}:{},...d&&r?.disabledReason?{disabledReason:r.disabledReason}:{},...m?{recoveryHint:m}:{}})}const c=s.filter(e=>!a||e.provider===a).toSorted((e,t)=>e.provider.localeCompare(t.provider)||e.id.localeCompare(t.id));if(e.json){writeRuntimeJson(t,{agentId:r,agentDir:shortenHomePath(i),authStatePath:shortenHomePath(resolveAuthStatePathForDisplay(i)),provider:a||null,profiles:c});return}t.log(terminalText`Agent: ${r}`);t.log(terminalText`Auth state store: ${shortenHomePath(resolveAuthStatePathForDisplay(i))}`);if(a)t.log(terminalText`Provider: ${a}`);if(c.length===0){t.log(`Profiles: (none)`);return}t.log(`Profiles:`);for(const e of c){const n=[`${e.provider}/${e.type}`];if(e.expiresAt)n.push(`expires ${e.expiresAt}`);if(e.blockedUntil){const t=e.blockedReason?`:${e.blockedReason}`:``;const r=e.blockedSource?` via ${e.blockedSource}`:``;const i=e.blockedScope===`model`?` for model${e.blockedModel?` ${e.blockedModel}`:``}`:` for profile`;n.push(`blocked${t}${r}${i} until ${e.blockedUntil}`)}if(e.cooldownUntil){const t=e.cooldownClassification??e.cooldownReason;n.push(`cooldown${t?`:${t}`:``} until ${e.cooldownUntil}`)}if(e.disabledUntil)n.push(`disabled${e.disabledReason?`:${e.disabledReason}`:``} until ${e.disabledUntil}`);t.log(terminalText`- ${e.label} [${n.join(`; `)}]${e.recoveryHint?` — ${e.recoveryHint}`:``}`)}}export{modelsAuthListCommand};