openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
74 lines (73 loc) • 3.69 kB
JavaScript
import { c as normalizeOptionalLowercaseString, l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { d as isUserModelAuthProfileId } from "./user-model-account-authority-CRj924IP.mjs";
import { i as resolveProviderIdForAuth } from "./provider-auth-aliases-CgGlzANu.mjs";
import { r as resolveCollapsedSessionAuthPinSource } from "./auth-profile-override-provenance-B7WULxR7.mjs";
import { r as applyModelOverrideToSessionEntry } from "./model-overrides-BXZ5Hz6C.mjs";
import { i as findPersistedAuthProfileCredential, o as getRuntimeAuthProfileStoreSnapshot } from "./store-Bh2lUvOT.mjs";
import { t as resolveModelProviderAuthConfig } from "./model-auth-provider-route-nEDhMXpO.mjs";
//#region 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;
}
/** Checks whether a pinned session auth profile can authenticate the selected 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);
}
/** Missing credentials preserve explicit same-provider intent until authentication reports recovery. */
function shouldPreserveUnavailableSessionAuthProfileOverride(e) {
const t = normalizeOptionalString(e.entry.authProfileOverride);
return Boolean(t && !e.store.profiles[t] && resolveCollapsedSessionAuthPinSource(e.entry) === "user" && shouldPreserveSessionAuthProfileOverride(e));
}
/** Applies a user model selection without dropping a compatible pinned auth profile. */
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 } : {}
})
});
}
//#endregion
export { shouldPreserveSessionAuthProfileOverride as n, shouldPreserveUnavailableSessionAuthProfileOverride as r, applyModelOverrideWithAuthProfileCompatibility as t };