UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

103 lines (102 loc) • 4.19 kB
import { i as normalizeProviderIdForAuth } from "./provider-id-b5XGSf9C.mjs"; import { t as canonicalizeProviderModelId } from "./provider-model-route-hB9HZIqE.mjs"; import { n as resolveDefaultModelForAgent } from "./model-selection-config-Bvf5WqHo.mjs"; import "./model-selection-C2A4Wyix.mjs"; import { i as ensureAuthProfileStoreAsync } from "./store-runtime-dW0pXLJI.mjs"; import { t as buildProviderAuthRecoveryHint } from "./provider-auth-recovery-hint-SMK7UCzs.mjs"; import "./auth-profiles-VRLhewIH.mjs"; import { t as createModelAuthAvailabilityResolver } from "./model-auth-availability-DC3d9ngc.mjs"; //#region src/commands/auth-choice.model-check.ts /** * Resolve the default model ref and its auth readiness. A catalog observation * makes transport-specific auth exact; absent observations remain * indeterminate when provider facts cannot choose one route. Shared by the * onboarding model check and the finalize hatch gating. */ async function resolveDefaultModelAuthStatus(e, t) { const n = resolveDefaultModelForAgent({ cfg: e, agentId: t?.agentId }); const r = await ensureAuthProfileStoreAsync(t?.agentDir, { allowKeychainPrompt: false, config: e, ...n.provider === "openai" ? { externalCliProviderIds: ["openai"] } : {}, readOnly: true }); const i = t?.pendingAuthProfiles ?? []; const a = i.length ? { ...r, profiles: { ...r.profiles } } : r; for (const { profileId: e, credential: t } of i) a.profiles[e] = t; const o = createModelAuthAvailabilityResolver({ cfg: e, agentId: t?.agentId, authStore: a, ...t?.agentDir ? { agentDir: t.agentDir } : {}, ...t?.env ? { env: t.env } : {} }).evaluateModelAuth(n.provider, { modelId: n.model, ...t?.observedRoutes?.length ? { observedRoutes: t.observedRoutes } : {} }); if (o.routeResolution?.kind === "incompatible") return { provider: n.provider, model: n.model, status: "incompatible", message: o.routeResolution.message }; const s = o.availability; const c = o.selectedRoute?.authRequirement; if (s === true) return { provider: n.provider, model: n.model, status: "ready" }; if (s === void 0 && (normalizeProviderIdForAuth(n.provider) === "openai" || o.routeResolution !== null || o.evidence !== void 0)) return { provider: n.provider, model: n.model, status: "indeterminate" }; return { provider: n.provider, model: n.model, status: "missing", ...c ? { authRequirement: c } : {} }; } function catalogRouteObservation(e) { const t = e.baseUrl; if (e.api === void 0 && t === void 0) return; return { ...e.api !== void 0 ? { api: e.api } : {}, ...t !== void 0 ? { baseUrl: t } : {} }; } /** Resolve logical model identity and every physical route represented by a catalog. */ function resolveDefaultModelCatalogFacts(e, t, n) { const r = resolveDefaultModelForAgent({ cfg: e, agentId: n?.agentId }); const i = normalizeProviderIdForAuth(r.provider); const a = canonicalizeProviderModelId(i, r.model); const matches = (e) => normalizeProviderIdForAuth(e.provider) === i && canonicalizeProviderModelId(i, e.id) === a; const o = (n?.routeVariants ?? t).filter(matches).map(catalogRouteObservation).filter((e) => e !== void 0); return o.length > 0 ? { observedRoutes: o } : {}; } /** Warn when the selected default model does not have confirmed usable credentials. */ async function warnIfModelConfigLooksOff(e, t, n) { let r; const i = await resolveDefaultModelAuthStatus(e, n); if (i.status === "missing") r = `No auth configured for provider "${i.provider}". The agent may fail until credentials are added. ${buildProviderAuthRecoveryHint({ provider: i.provider, config: e, includeEnvVar: i.authRequirement !== "subscription" })}`; else if (i.status === "incompatible") r = `Model route is incompatible for "${i.provider}/${i.model}": ${i.message}`; else if (i.status === "indeterminate") r = `Auth readiness could not be confirmed for "${i.provider}/${i.model}". Verify the selected model route and credential source before continuing.`; if (r) await t.note(r, "Model check"); } //#endregion export { resolveDefaultModelCatalogFacts as n, warnIfModelConfigLooksOff as r, resolveDefaultModelAuthStatus as t };