openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.05 kB
JavaScript
import{c as normalizeOptionalLowercaseString,l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{t as isUserModelAuthProfileId}from"./user-model-account-id-CU4k7NMV.mjs";import{i as resolveProviderIdForAuth}from"./provider-auth-aliases-BRA1A5Vm.mjs";import{i as resolveCollapsedSessionAuthPinSource}from"./auth-profile-override-provenance-D5ZYWRNQ.mjs";import{t as resolveModelProviderAuthConfig}from"./model-auth-provider-route-BT25VrFM.mjs";import{r as applyModelOverrideToSessionEntry}from"./model-overrides-BuQ2Xi0I.mjs";import{i as findPersistedAuthProfileCredential,o as getRuntimeAuthProfileStoreSnapshot}from"./store-CX8ovUiF.mjs";
//!src/sessions/auth-profile-preservation.ts
function resolvePinnedAuthProfileProvider(e){return getRuntimeAuthProfileStoreSnapshot(e.agentDir)?.profiles[e.profileId]?.provider??findPersistedAuthProfileCredential({agentDir:e.agentDir,profileId:e.profileId})?.provider??e.cfg.auth?.profiles?.[e.profileId]?.provider}function shouldPreserveSessionAuthProfileOverride(e){const t=normalizeOptionalString(e.entry.authProfileOverride);const n=normalizeOptionalLowercaseString(e.provider);if(!t||!n)return false;const resolvesToTargetProvider=(t,r=false)=>{const i=normalizeOptionalLowercaseString(t);const a={config:e.cfg,...e.metadataSnapshot?{metadataSnapshot:e.metadataSnapshot}:{}};return Boolean(i&&resolveProviderIdForAuth(i,{...a,storedCredential:r})===resolveProviderIdForAuth(n,a))};const r=e.recordedProvider?e.recordedProvider.provider??e.cfg.auth?.profiles?.[t]?.provider:resolvePinnedAuthProfileProvider({cfg:e.cfg,agentDir:e.agentDir,profileId:t});if(r)return resolvesToTargetProvider(r,true);const i=t.indexOf(`:`);if(i<0||isUserModelAuthProfileId(t))return resolvesToTargetProvider(e.currentProvider);return resolvesToTargetProvider(t.slice(0,i),true)}function shouldPreserveUnavailableSessionAuthProfileOverride(e){const t=normalizeOptionalString(e.entry.authProfileOverride);return Boolean(t&&!e.store.profiles[t]&&resolveCollapsedSessionAuthPinSource(e.entry)===`user`&&shouldPreserveSessionAuthProfileOverride(e))}function applyModelOverrideWithAuthProfileCompatibility(e){return applyModelOverrideToSessionEntry({entry:e.entry,selection:e.selection,profileOverride:e.profileOverride,profileOverrideSource:e.profileOverrideSource||void 0,selectionSource:e.selectionSource||void 0,explicitDefaultSelection:e.explicitDefaultSelection,markLiveSwitchPending:e.markLiveSwitchPending,preserveAuthProfileOverride:!e.profileOverride&&shouldPreserveSessionAuthProfileOverride({cfg:resolveModelProviderAuthConfig({config:e.cfg,provider:e.selection.provider,modelId:e.selection.model,metadataSnapshot:e.metadataSnapshot}),agentDir:e.agentDir,entry:e.entry,currentProvider:e.currentProvider,provider:e.selection.provider,recordedProvider:e.recordedProvider,...e.metadataSnapshot?{metadataSnapshot:e.metadataSnapshot}:{}})})}export{shouldPreserveSessionAuthProfileOverride as n,shouldPreserveUnavailableSessionAuthProfileOverride as r,applyModelOverrideWithAuthProfileCompatibility as t};