UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

104 lines (103 loc) • 4.71 kB
import { b as uniqueStrings } from "./string-normalization-DLmfYZXI.mjs"; import { r as normalizeProviderId } from "./provider-id-b5XGSf9C.mjs"; import { d as isUserModelAuthProfileId } from "./user-model-account-authority-CRj924IP.mjs"; import { r as resolveCollapsedSessionAuthPinSource } from "./auth-profile-override-provenance-B7WULxR7.mjs"; import { a as resolveAuthProfileOrder, n as isStoredCredentialCompatibleWithAuthProvider } from "./order-jOvee2J6.mjs"; import { a as readCodexCliCredentialsCached } from "./cli-credentials-BaPg7qWx.mjs"; import { n as externalCliDiscoveryForProviderAuth } from "./external-cli-discovery-DZ419koV.mjs"; import { t as resolveEnvApiKey } from "./model-auth-env-kbpGo8fU.mjs"; import { S as shouldPreferExplicitConfigApiKeyAuth, b as resolveUsableCustomProviderApiKey, v as resolveProviderEntryApiKeyProfileReference } from "./model-auth-provider-config-Bnc4upRS.mjs"; import { c as ensureAuthProfileStoreWithoutExternalProfilesAsync, h as loadAuthProfileStoreWithoutExternalProfiles, i as ensureAuthProfileStoreAsync, r as ensureAuthProfileStore } from "./store-runtime-dW0pXLJI.mjs"; import { n as resolveAuthProfileDisplayLabel } from "./display-DA_6g711.mjs"; import "./auth-profiles-VRLhewIH.mjs"; import "./model-auth-CEsyk_Yg.mjs"; //#region src/agents/model-auth-label.ts /** @deprecated Retained for the synchronous Plugin SDK model-header API. Use resolveModelAuthLabelAsync. */ function resolveModelAuthLabel(e) { if (!e.provider?.trim()) return; const t = e.sessionEntry?.authProfileOverride?.trim(); return resolveModelAuthLabelFromStore(e, e.authStore ?? (e.includeExternalProfiles === false ? loadAuthProfileStoreWithoutExternalProfiles(e.agentDir, { profileId: t }) : ensureAuthProfileStore(e.agentDir, { profileId: t, externalCli: externalCliDiscoveryForProviderAuth({ cfg: e.cfg, provider: normalizeProviderId(e.provider ?? ""), preferredProfile: t }) }))); } async function resolveModelAuthLabelAsync(e) { if (!e.provider?.trim()) return; const t = e.sessionEntry?.authProfileOverride?.trim(); return resolveModelAuthLabelFromStore(e, e.authStore ?? (e.includeExternalProfiles === false ? await ensureAuthProfileStoreWithoutExternalProfilesAsync(e.agentDir, { profileId: t }) : await ensureAuthProfileStoreAsync(e.agentDir, { profileId: t, externalCli: externalCliDiscoveryForProviderAuth({ cfg: e.cfg, provider: normalizeProviderId(e.provider), preferredProfile: t }) }))); } function resolveModelAuthLabelFromStore(e, t) { const n = e.provider?.trim(); if (!n) return; const r = normalizeProviderId(n); const i = e.sessionEntry?.authProfileOverride?.trim(); const a = uniqueStrings([...(e.acceptedProviderIds ?? []).map(normalizeProviderId), r].filter(Boolean)); const o = [i, ...uniqueStrings(a.flatMap((n) => resolveAuthProfileOrder({ cfg: e.cfg, store: t, provider: n, preferredProfile: i })))].filter(Boolean); const s = resolveProviderEntryApiKeyProfileReference({ cfg: e.cfg, provider: r, store: t }); if (resolveCollapsedSessionAuthPinSource(e.sessionEntry) !== "user" && s.kind === "literal" && shouldPreferExplicitConfigApiKeyAuth(e.cfg, r)) return "api-key (models.json)"; for (const n of o) { const r = t.profiles[n]; if (!r || !a.some((t) => isStoredCredentialCompatibleWithAuthProvider({ cfg: e.cfg, provider: t, credential: r }))) continue; const i = isUserModelAuthProfileId(n) ? "personal account" : resolveAuthProfileDisplayLabel({ cfg: e.cfg, store: t, profileId: n }); return `${r.type === "api_key" ? "api-key" : r.type}${i ? ` (${i})` : ""}`; } if (s.kind === "profile") { const n = resolveAuthProfileDisplayLabel({ cfg: e.cfg, store: t, profileId: s.profileId }); return `${s.mode === "token" ? "token" : "api-key"}${n ? ` (${n})` : ""}`; } if (s.kind === "profile-incompatible") return "unknown"; if (e.codexCliCredentialsHome && (r === "openai" || r === "codex") && readCodexCliCredentialsCached({ codexHome: e.codexCliCredentialsHome, ttlMs: 5e3, allowKeychainPrompt: false })) return "oauth (codex-cli)"; const c = resolveEnvApiKey(r, process.env, { config: e.cfg, workspaceDir: e.workspaceDir }); if (c?.apiKey) return `${c.source.includes("OAUTH_TOKEN") ? "oauth" : "api-key"} (${c.source})`; if (r === "codex" && readCodexCliCredentialsCached({ ttlMs: 5e3, allowKeychainPrompt: false })) return "oauth (codex-cli)"; if (r === "claude-cli") return "native (claude-cli)"; if (resolveUsableCustomProviderApiKey({ cfg: e.cfg, provider: r })) return `api-key (models.json)`; return "unknown"; } //#endregion export { resolveModelAuthLabelAsync as n, resolveModelAuthLabel as t };