openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
46 lines (45 loc) • 2.79 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CIXf7egm.js";
import { n as normalizeAgentId } from "./agent-id-CeT3w4ap.js";
import { D as tryResolveLegacyCompatibilityAgentId, u as resolveAgentDir } from "./agent-scope-config-DcbEhP0R.js";
import { w as resolveStateDir } from "./paths-D2sRr1a_.js";
import "./session-key-BnWWjqNc.js";
import "./legacy.default-agent-owner-BGwEdQRe.js";
import { o as resolveSharedAuthStoreOwnership } from "./path-resolve-oRkRBkQd.js";
import path from "node:path";
//#region src/agents/legacy-inherited-auth-dir.ts
function resolveLegacyInheritedAuthAgentId(config) {
return normalizeOptionalString(config.agents?.defaults?.authInheritance?.agentId) ?? tryResolveLegacyCompatibilityAgentId(config) ?? "main";
}
function resolveLegacyInheritedAuthAgentDir(config, env = process.env) {
return resolveAgentDir(config, resolveLegacyInheritedAuthAgentId(config), env);
}
function resolveLegacyInheritedAuthDir(config, env = process.env) {
return resolveSharedAuthStoreOwnership(env).location === "legacy-main" ? resolveLegacyInheritedAuthAgentDir(config, env) : void 0;
}
function pinLegacyInheritedAuthOwnerForRosterTransition(sourceConfig, targetConfig) {
const sourceOwner = resolveLegacyInheritedAuthAgentId(sourceConfig);
if (sourceOwner === resolveLegacyInheritedAuthAgentId(targetConfig)) return targetConfig;
return {
...targetConfig,
agents: {
...targetConfig.agents,
defaults: {
...targetConfig.agents?.defaults,
authInheritance: {
...targetConfig.agents?.defaults?.authInheritance,
agentId: sourceOwner
}
}
}
};
}
function assertSafeLegacyInheritedAuthDirTransition(sourceConfig, targetConfig, env = process.env) {
const sourceOwner = resolveLegacyInheritedAuthAgentId(sourceConfig);
const sourceDir = resolveAgentDir(sourceConfig, sourceOwner, env);
const conventionalDir = path.join(resolveStateDir(env), "agents", normalizeAgentId(sourceOwner), "agent");
const targetDir = resolveAgentDir(targetConfig, sourceOwner, env);
if (path.resolve(sourceDir) === path.resolve(conventionalDir) || targetDir === sourceDir) return;
throw Object.assign(/* @__PURE__ */ new Error(`Config write refused: inherited auth for agent "${sourceOwner}" is stored in custom agentDir ${JSON.stringify(sourceDir)}, but this roster change removes or changes that directory. Relocate the credentials to ${JSON.stringify(conventionalDir)} or set agents.defaults.authInheritance explicitly for the destination owner, then retry.`), { code: "CONFIG_WRITE_REJECTED" });
}
//#endregion
export { resolveLegacyInheritedAuthDir as a, resolveLegacyInheritedAuthAgentId as i, pinLegacyInheritedAuthOwnerForRosterTransition as n, resolveLegacyInheritedAuthAgentDir as r, assertSafeLegacyInheritedAuthDirTransition as t };