openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
56 lines (55 loc) • 2.08 kB
JavaScript
import { t as applyAuthProfileConfig } from "./provider-auth-helpers-ByDXB7Po.mjs";
import { _ as resolveMigrationConfigRuntime } from "./migration-C73lp9ea.mjs";
import "./provider-auth-D_oAZ3fr.mjs";
//#region extensions/migrate-hermes/auth-config.ts
var HermesAuthConfigConflict = class extends Error {};
function existingProfileIsCompatible(e, t) {
if (e.provider !== t.provider || e.mode !== t.mode) return false;
if (e.email && t.email && e.email !== t.email) return false;
return true;
}
function hasAuthProfileConfigConflict(e, t, n) {
if (n) return false;
const r = e.auth?.profiles?.[t.profileId];
return Boolean(r && !existingProfileIsCompatible(r, t));
}
function replaceConfigDraft(e, t) {
for (const t of Object.keys(e)) delete e[t];
Object.assign(e, t);
}
function hasCurrentAuthProfileConfigConflict(e, t) {
let n = e.config;
try {
n = resolveMigrationConfigRuntime(e)?.current?.() ?? n;
} catch {}
return hasAuthProfileConfigConflict(n, t, Boolean(e.overwrite));
}
async function applyAuthProfileConfigWithConflictCheck(e) {
const t = resolveMigrationConfigRuntime(e.ctx);
if (!t?.current || !t.mutateConfigFile) return "unavailable";
try {
await t.mutateConfigFile({
base: "runtime",
afterWrite: { mode: "auto" },
mutate(t) {
let n = t;
if (e.applyConfigPatch) n = e.applyConfigPatch(n);
if (hasAuthProfileConfigConflict(n, e.profile, Boolean(e.ctx.overwrite))) throw new HermesAuthConfigConflict();
n = applyAuthProfileConfig(n, {
profileId: e.profile.profileId,
provider: e.profile.provider,
mode: e.profile.mode,
...e.profile.email ? { email: e.profile.email } : {},
...e.profile.displayName ? { displayName: e.profile.displayName } : {},
preferProfileFirst: false
});
replaceConfigDraft(t, n);
}
});
return "configured";
} catch (e) {
return e instanceof HermesAuthConfigConflict ? "conflict" : "unavailable";
}
}
//#endregion
export { hasAuthProfileConfigConflict as n, hasCurrentAuthProfileConfigConflict as r, applyAuthProfileConfigWithConflictCheck as t };