openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
85 lines (84 loc) • 3.74 kB
JavaScript
import { c as resolveCliRuntimeCanonicalProvider, o as resolveCliBackendConfig } from "./cli-backends-B8PrIwPC.mjs";
import { o as resolveAuthProfileOrderWithMetadata } from "./order-jOvee2J6.mjs";
import { t as resolveBundledCliBackendAuthPolicy } from "./cli-backend-auth-policy-Crs4uIXe.mjs";
//#region src/agents/cli-execution-auth.ts
const GOOGLE_GEMINI_CLI_PROVIDER_ID = "google-gemini-cli";
const GOOGLE_PROVIDER_ID = "google";
const CLAUDE_CLI_PROVIDER_ID = "claude-cli";
var CliExecutionAuthProfileError = class extends Error {
constructor(...e) {
super(...e);
this.name = "CliExecutionAuthProfileError";
}
};
function cliBackendAcceptsAuthProfileForwarding(e) {
const t = resolveCliBackendConfig(e.provider, e.config, { agentId: e.agentId });
return t?.id === GOOGLE_GEMINI_CLI_PROVIDER_ID || t?.id === CLAUDE_CLI_PROVIDER_ID;
}
/**
* Preserve the session account unless the user selects another or it was removed.
* A user-locked profile must fail closed rather than run as another user.
*/
function selectCliExecutionAuthProfile(e) {
const { store: t } = e;
const n = e.selected?.authProfileId?.trim();
const r = n && e.selected?.authProfileIdSource !== "auto";
const i = e.sessionBinding?.authProfileId?.trim();
const a = resolveBundledCliBackendAuthPolicy(e.cliExecutionProvider)?.nativeAuthProfileIds;
if (!r && e.sessionBinding && !i) return;
const o = r ? n : i && (t.profiles[i] || a?.includes(i)) ? i : void 0;
const s = o ?? n;
if (s && a?.includes(s)) return;
const c = resolveCliRuntimeCanonicalProvider({
runtime: e.cliExecutionProvider,
config: e.config,
includeSetupRegistry: true,
metadataSnapshot: e.metadataSnapshot
});
const acceptsCredential = (t, n) => t.provider === e.cliExecutionProvider || t.provider === c && (e.cliExecutionProvider === CLAUDE_CLI_PROVIDER_ID ? n || t.type !== "api_key" : e.cliExecutionProvider === GOOGLE_GEMINI_CLI_PROVIDER_ID && t.type === "api_key");
if (o) {
const n = t.profiles[o];
if (!n) throw new CliExecutionAuthProfileError(`No credentials found for profile "${o}".`);
if (acceptsCredential(n, true)) return {
profileId: o,
provider: n.provider
};
throw new CliExecutionAuthProfileError(`CLI backend "${e.cliExecutionProvider}" cannot use auth profile "${o}" owned by "${n.provider}".`);
}
const l = [e.cliExecutionProvider];
if (c && (e.cliExecutionProvider === CLAUDE_CLI_PROVIDER_ID || e.cliExecutionProvider === GOOGLE_GEMINI_CLI_PROVIDER_ID && e.authProfileProvider === GOOGLE_PROVIDER_ID)) l.push(c);
for (const r of l) {
const i = resolveAuthProfileOrderWithMetadata({
cfg: e.config,
store: t,
provider: r,
preferredProfile: n,
readinessMode: e.readinessMode,
authAliasLookupParams: { metadataSnapshot: e.metadataSnapshot }
});
for (const e of i.profileIds) {
const n = t.profiles[e];
if (n && acceptsCredential(n, false) && !a?.includes(e)) return {
profileId: e,
provider: n.provider
};
}
if (i.hasExplicitOrder) return;
}
}
async function resolveCliExecutionAuthProfileId(e) {
const t = e.loadAuthProfileStoreForRuntimeAsync ?? (await import("./store-runtime-pgVSsSj7.mjs")).loadAuthProfileStoreForRuntimeAsync;
const n = e.selected?.authProfileId?.trim();
const r = await t(e.agentDir, {
readOnly: true,
allowKeychainPrompt: false,
externalCliProviderIds: [e.cliExecutionProvider],
profileId: n && e.selected?.authProfileIdSource !== "auto" ? n : e.sessionBinding?.authProfileId?.trim() ?? n
});
return selectCliExecutionAuthProfile({
...e,
store: r
})?.profileId;
}
//#endregion
export { selectCliExecutionAuthProfile as i, cliBackendAcceptsAuthProfileForwarding as n, resolveCliExecutionAuthProfileId as r, CliExecutionAuthProfileError as t };