openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
92 lines (91 loc) • 4.21 kB
JavaScript
import { y as uniqueStrings } from "./string-normalization-DsCfAx8q.js";
import { r as normalizeProviderId } from "./provider-id-DMd-TDFp.js";
import { i as isUserModelAuthProfileId } from "./profile-usage-stats-dkZh2v8y.js";
import { n as readCodexCliCredentialsCached } from "./cli-credentials-CHuqM5pH.js";
import { m as loadAuthProfileStoreWithoutExternalProfiles, r as ensureAuthProfileStore } from "./store-F1B2duCT.js";
import { a as resolveAuthProfileOrder, n as isStoredCredentialCompatibleWithAuthProvider } from "./order-CC2RBzI5.js";
import { t as resolveEnvApiKey } from "./model-auth-env-Dq9W4xg9.js";
import { n as externalCliDiscoveryForProviderAuth } from "./external-cli-discovery-CbeZXk1q.js";
import { S as resolveUsableCustomProviderApiKey, b as resolveProviderEntryApiKeyProfileReference } from "./model-auth-provider-config-C_kr_q2g.js";
import { t as resolveAuthProfileDisplayLabel } from "./auth-profiles-BdUEhE7u.js";
import "./model-auth-C48_DZ-I.js";
//#region src/agents/model-auth-label.ts
/**
* Formats user-facing auth labels for resolved provider/model credentials.
*/
/** Resolve the display label that describes how a provider is authenticated. */
function resolveModelAuthLabel(params) {
const resolvedProvider = params.provider?.trim();
if (!resolvedProvider) return;
const providerKey = normalizeProviderId(resolvedProvider);
const profileOverride = params.sessionEntry?.authProfileOverride?.trim();
const store = params.includeExternalProfiles === false ? loadAuthProfileStoreWithoutExternalProfiles(params.agentDir, { profileId: profileOverride }) : ensureAuthProfileStore(params.agentDir, {
profileId: profileOverride,
externalCli: externalCliDiscoveryForProviderAuth({
cfg: params.cfg,
provider: providerKey,
preferredProfile: profileOverride
})
});
const acceptedProviderKeys = uniqueStrings([...(params.acceptedProviderIds ?? []).map(normalizeProviderId), providerKey].filter(Boolean));
const candidates = [profileOverride, ...uniqueStrings(acceptedProviderKeys.flatMap((acceptedProvider) => resolveAuthProfileOrder({
cfg: params.cfg,
store,
provider: acceptedProvider,
preferredProfile: profileOverride
})))].filter(Boolean);
for (const profileId of candidates) {
const profile = store.profiles[profileId];
if (!profile || !acceptedProviderKeys.some((acceptedProvider) => isStoredCredentialCompatibleWithAuthProvider({
cfg: params.cfg,
provider: acceptedProvider,
credential: profile
}))) continue;
const label = isUserModelAuthProfileId(profileId) ? "personal account" : resolveAuthProfileDisplayLabel({
cfg: params.cfg,
store,
profileId
});
return `${profile.type === "api_key" ? "api-key" : profile.type}${label ? ` (${label})` : ""}`;
}
const providerEntryProfileRef = resolveProviderEntryApiKeyProfileReference({
cfg: params.cfg,
provider: providerKey,
store
});
if (providerEntryProfileRef.kind === "profile") {
const label = resolveAuthProfileDisplayLabel({
cfg: params.cfg,
store,
profileId: providerEntryProfileRef.profileId
});
if (providerEntryProfileRef.mode === "token") return `token${label ? ` (${label})` : ""}`;
return `api-key${label ? ` (${label})` : ""}`;
}
if (providerEntryProfileRef.kind === "profile-incompatible") return "unknown";
if (params.codexCliCredentialsHome && (providerKey === "openai" || providerKey === "codex") && readCodexCliCredentialsCached({
codexHome: params.codexCliCredentialsHome,
ttlMs: 5e3,
allowKeychainPrompt: false
})) return "oauth (codex-cli)";
const envKey = resolveEnvApiKey(providerKey, process.env, {
config: params.cfg,
workspaceDir: params.workspaceDir
});
if (envKey?.apiKey) {
if (envKey.source.includes("OAUTH_TOKEN")) return `oauth (${envKey.source})`;
return `api-key (${envKey.source})`;
}
if (providerKey === "codex" && readCodexCliCredentialsCached({
ttlMs: 5e3,
allowKeychainPrompt: false
})) return "oauth (codex-cli)";
if (providerKey === "claude-cli") return "native (claude-cli)";
if (resolveUsableCustomProviderApiKey({
cfg: params.cfg,
provider: providerKey
})) return `api-key (models.json)`;
return "unknown";
}
//#endregion
export { resolveModelAuthLabel as t };