UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 4.67 kB
import{o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{o as asDateTimestampMs}from"./number-coercion-B3CfI447.mjs";import{n as sliceUtf16Safe}from"./utf16-slice-DA3Mllbx.mjs";import{g as parseSecretRef}from"./types.secrets-UWdyCdE6.mjs";import{f as shortenHomePath}from"./utils-Dlk0IYAa.mjs";import{r as normalizeProviderId}from"./provider-id-A-8WTtLA.mjs";import{k as resolveProfileUnusableUntilForDisplay}from"./user-model-account-authority-B8H7rvCb.mjs";import{t as findNormalizedProviderValue}from"./model-selection-normalize-DU37Sfvg.mjs";import{l as cloneAuthProfileStore}from"./oauth-shared-DTzAchzX.mjs";import{b as resolveUsableCustomProviderApiKey}from"./model-auth-provider-config-KlOdxZHz.mjs";import{a as resolveAuthProfileOrder,t as isConfiguredAwsSdkAuthProfileForProvider}from"./order-B8e_5ABM.mjs";import{t as resolveEnvApiKey}from"./model-auth-env-B6Hhnpzd.mjs";import{t as formatAuthProfileOAuthLabel}from"./display-_lnk7MT7.mjs";import{r as formatRemainingShort}from"./auth-health-DIboE8Qn.mjs"; //!src/security/secret-mask.ts function maskApiKey(e){const t=stripControlCharacters(e).trim();if(!t)return`missing`;if(t.length<=6)return`${sliceUtf16Safe(t,0,1)}...${sliceUtf16Safe(t,-1)}`;if(t.length<=16)return`${sliceUtf16Safe(t,0,2)}...${sliceUtf16Safe(t,-2)}`;return`${sliceUtf16Safe(t,0,8)}...${sliceUtf16Safe(t,-8)}`}function stripControlCharacters(e){let t=``;for(const n of e){const e=n.charCodeAt(0);if(!(e>=0&&e<=31||e>=127&&e<=159))t+=n}return t} //!src/agents/model-catalog-auth-labels.ts function resolveStoredCredentialLabel(e){const t=maskApiKey(typeof e.value===`string`?e.value:``);if(t!==`missing`)return t;if(parseSecretRef(e.refValue))return`ref`;return`missing`}function formatModelCatalogAuthLabel(e,t){if(typeof e===`string`)return e;const{cfg:n,metadataSnapshot:r}=t;const i=cloneAuthProfileStore(t.store);const a=Date.now();const o=resolveAuthProfileOrder({cfg:n,store:i,provider:e.provider,authAliasLookupParams:{metadataSnapshot:r}}).filter(t=>{if(!e.apiKeyOnly)return true;const r=i.profiles[t]?.type??n.auth?.profiles?.[t]?.mode;return r!==`oauth`&&r!==`token`});if(!o.length)return e.fallback;const s=findNormalizedProviderValue(i.lastGood,e.provider);return`${o.map((t,n)=>{const r=[];if(n===0)r.push(`next`);if(s===t)r.push(`lastGood`);const o=resolveProfileUnusableUntilForDisplay(i,t);if(o&&o>a)r.push(`cooldown ${formatRemainingShort(o-a,{underMinuteLabel:`soon`})}`);const c=i.profiles[t];const l=c&&c.type!==`api_key`?asDateTimestampMs(c.expires):void 0;if(l!==void 0&&l>0)r.push(l<=a?`expired`:` exp ${formatRemainingShort(l-a,{underMinuteLabel:`soon`})}`);return`${e.profiles[t]}${r.length?` (${r.join(`, `)})`:``}`}).join(`, `)} (${e.source})`}function captureProfileLabel(e,t,n){const r=n.profiles[e];const i=t.auth?.profiles?.[e];if(!r||i?.provider&&i.provider!==r.provider||i?.mode&&i.mode!==r.type&&!(i.mode===`oauth`&&r.type===`token`))return`${e}=missing`;if(r.type===`api_key`)return`${e}=${resolveStoredCredentialLabel({value:r.key,refValue:r.keyRef})}`;if(r.type===`token`)return`${e}=token:${resolveStoredCredentialLabel({value:r.token,refValue:r.tokenRef})}`;return formatAuthProfileOAuthLabel({cfg:t,store:n,profileId:e})}function captureFallbackLabel(e,t,n,r,i){const a=resolveEnvApiKey(e,r,{config:t,workspaceDir:i});if(a){const e=a.source.includes(`ANTHROPIC_OAUTH_TOKEN`)||normalizeLowercaseStringOrEmpty(a.source).includes(`oauth`)?`OAuth (env)`:maskApiKey(a.apiKey);return a.source&&a.source!==e&&a.source!==`missing`?`${e} (${a.source})`:e}const o=resolveUsableCustomProviderApiKey({cfg:t,provider:e})?.apiKey;if(o)return`${maskApiKey(o)} (models.json: ${shortenHomePath(`${n}/models.json`)})`;return`missing`}function prepareModelCatalogAuthLabels(e){const t=/* @__PURE__ */ new Map;const n=/* @__PURE__ */ new Set([...Object.keys(e.store.profiles),...Object.keys(e.config.auth?.profiles??{}),...Object.values(e.store.order??{}).flat(),...Object.values(e.config.auth?.order??{}).flat()]);const r=new Set([...e.providers].map(normalizeProviderId));if(r.size===0)return t;const i=[...n].map(t=>[t,captureProfileLabel(t,e.config,e.store)]);for(const n of r){const r={provider:n,profiles:Object.fromEntries(i.map(([t,r])=>[t,!e.store.profiles[t]&&isConfiguredAwsSdkAuthProfileForProvider({cfg:e.config,provider:n,profileId:t})?`${t}=aws-sdk`:r])),source:`auth profile store: ${shortenHomePath(e.authStorePath)}`,fallback:captureFallbackLabel(n,e.config,e.agentDir,e.env,e.workspaceDir),apiKeyOnly:false};t.set(n,{all:r,apiKey:n===`openai`?{...r,apiKeyOnly:true}:r})}return t}export{prepareModelCatalogAuthLabels as n,maskApiKey as r,formatModelCatalogAuthLabel as t};