openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
754 lines (753 loc) • 30 kB
JavaScript
import { d as withPluginRuntimeRegistryScope } from "./gateway-request-scope-BvvDhs5D.mjs";
import "./model-ref-shared-DqE2RqZv.mjs";
import { r as normalizeProviderId } from "./provider-id-b5XGSf9C.mjs";
import { A as tryResolveLegacyCompatibilityAgentId, f as resolveAgentWorkspaceDir, m as resolveAmbientOwnerAgentId } from "./agent-scope-config-DmXgFGKP.mjs";
import { t as resolveDefaultAgentWorkspaceDir } from "./workspace-default-path-CWX4WiCH.mjs";
import { u as getPluginMetadataSnapshotCache, w as withPluginCache } from "./plugin-cache-B_eRuqTM.mjs";
import { c as getRuntimeConfigSourceSnapshot } from "./runtime-snapshot-WbwbY5b7.mjs";
import { s as resolveAgentModelPrimaryValue } from "./model-input-DrM4DWHG.mjs";
import { i as DEFAULT_PROVIDER } from "./defaults-BWyoTPqn.mjs";
import "./agent-scope-BwB8YH6y.mjs";
import "./legacy.default-agent-owner-DpmHgK0A.mjs";
import { r as resolveProviderPolicySurface } from "./provider-public-artifacts-CzxPvvri.mjs";
import { r as matchesProviderPluginRef } from "./provider-registry-shared-C3T4TYXW.mjs";
import { i as listCliRuntimeModelBackendBindings } from "./cli-backends-B8PrIwPC.mjs";
import { t as captureRuntimeConfig } from "./runtime-source-projection-DTwMWCo9.mjs";
import { r as resolveProviderModelCatalogId } from "./provider-model-routes-CbP035Gi.mjs";
import { i as listAvailableManifestContractPlugins } from "./manifest-contract-eligibility-DoGGge-2.mjs";
import { b as readUtilityModelSetting, o as dedupeModelCatalogEntries } from "./model-selection-shared-9Kz63Hhm.mjs";
import { a as createModelCatalogIdentityKeyResolver, l as resolveModelCatalogIdentityKey } from "./model-catalog-entry-pfJ-_t4l.mjs";
import { r as modelKey } from "./provider-registry-index-DhPtwFh_.mjs";
import { n as resolveDefaultModelForAgent } from "./model-selection-config-Bvf5WqHo.mjs";
import { a as resolveModelExtraParamSources } from "./model-extra-params-D2Glrj-b.mjs";
import "./config-CMA-J084.mjs";
import { n as prepareOperatorModelPolicy } from "./operator-model-policy-BoEHyFtN.mjs";
import { n as createModelVisibilityPolicy, t as RUNTIME_MODEL_VISIBILITY_NORMALIZATION } from "./model-visibility-policy-CH4gPfvH.mjs";
import { t as resolveAgentHarnessPolicy } from "./policy-DzaOuofI.mjs";
import { t as createThinkingCatalogResolver } from "./thinking-Da4gHblr.mjs";
import { l as resolveCliRuntimeTwinRoute, s as omitCliRuntimeAliasTwins } from "./model-runtime-aliases-DZy9Ea2c.mjs";
import { t as resolveCompatibleAgentRuntimeForProvider } from "./session-runtime-compat-C_CO9LR_.mjs";
import { a as prepareModelCatalogView, n as createModelCatalogView, o as selectModelCatalogRuntimeEntry } from "./model-catalog-view-CsclLtvK.mjs";
import { n as publishedModelCatalogOwnerMatchesAgent } from "./prepared-model-catalog-owner-Cf9g0CZ4.mjs";
import { r as resolveSessionModelRef } from "./session-model-ref-Cha0Enxi.mjs";
import { t as projectWorkerPlacementAgentRuntime } from "./placement-session-runtime-CH2rEXuH.mjs";
import { i as resolveGatewayModelThinkingProfile } from "./session-utils-model-BFA7PxHy.mjs";
import { r as resolveProviderFastModeRequestCapabilities } from "./provider-attribution-DJbzqKsf.mjs";
import { r as PreparedModelRuntimePublicationSupersededError, t as PreparedModelRuntimeOwnerNotPublishedError } from "./prepared-model-runtime-admission-errors-LxrcCg4d.mjs";
import { t as resolveFastModeState } from "./fast-mode-BcwTQ_IZ.mjs";
import { T as preparedModelRuntimeConfigsMatch } from "./prepared-model-runtime-Bbo9uBdt.mjs";
import { r as createModelPickerRecommendationRank } from "./model-catalog-order-PB9EaGfB.mjs";
import { t as createPreparedModelCatalogProviderNormalizer } from "./model-catalog-provider-normalizer-4WEnAJTU.mjs";
import "./prepared-model-runtime.errors-BRsU9-dm.mjs";
import { r as isPreparedModelCatalogFull } from "./prepared-model-runtime.full-catalog-FIcw7ozu.mjs";
import { n as resolveConfiguredModelEntries } from "./configured-model-entries-Dhco8ams.mjs";
import { n as withCurrentReadAuthority } from "./current-read-authority-BoawkY8k.mjs";
import "./workspace-DLlXz3VE.mjs";
import { a as resolveUtilityModelRefForAgent, t as resolveAutomaticUtilityModelRef } from "./utility-model-DHdotLLx.mjs";
import { n as readPreparedCatalog, t as loadDeferredCatalog } from "./server-model-catalog-auth-DPSO0-N0.mjs";
import { t as resolveCatalogDecisionRuntime } from "./model-catalog-decision-runtime-BNbeEaZO.mjs";
import { n as prepareModelCatalogDecisions, t as createModelCatalogDecisions } from "./model-catalog-decisions-DRtCsJb_.mjs";
import { t as projectModelCatalogAccessPrograms } from "./model-catalog-access-programs-D76ru0cU.mjs";
import { n as resolveLogicalModelCatalogEntryState, t as prepareLogicalVisibleModelCatalog } from "./model-catalog-visibility-BtMLU5pm.mjs";
import { d as projectProviderCatalogOutcomes, f as retainModelChoiceAccountPin, l as buildPublicModelProjection, p as prepareChatAccountSelection, s as resolveSessionCatalogProfiles, u as projectModelServiceTiers } from "./chat-metadata-session-projection-Dqm83JVm.mjs";
import { t as resolveModelProviderCapabilities } from "./model-provider-capabilities-ChRIXSeJ.mjs";
import { supportsNativeOpenAIResponsesEndpoint } from "@openclaw/ai/internal/openai-responses-payload-policy";
//#region src/agents/model-fast-mode.ts
/** Capture light policy with the private catalog owner; published row reads cannot load plugins. */
function createModelSpeedPolicyResolver(e) {
const t = withPluginCache(getPluginMetadataSnapshotCache(e.metadataSnapshot), () => new Map([...new Set(e.catalog.map((e) => normalizeProviderId(e.provider)))].map((t) => {
const n = e.pluginRegistry?.providers.find(({ provider: e }) => matchesProviderPluginRef(e, t))?.provider;
const r = resolveProviderPolicySurface(t, { manifestRegistry: e.metadataSnapshot.manifestRegistry });
return [t, {
resolveFastModeSupport: n?.resolveFastModeSupport ?? r?.resolveFastModeSupport,
resolveServiceTiers: n?.resolveServiceTiers ?? r?.resolveServiceTiers
}];
})));
const prepare = (n, r, i) => {
const a = t.get(normalizeProviderId(n.provider));
if (!a) return {};
const o = r.selectedRoute ?? n;
if (!a.resolveFastModeSupport && !a.resolveServiceTiers) return {
supportsFastMode: void 0,
serviceTiers: void 0,
supportsServiceTierRecovery: (i ?? n.nativeRuntime) === "openclaw" && supportsNativeOpenAIResponsesEndpoint({
provider: n.provider,
api: o.api ?? "",
baseUrl: o.baseUrl
})
};
const { defaultParams: s, modelParams: c, agentModelParams: l, agentParams: u } = resolveModelExtraParamSources({
config: e.cfg,
provider: n.provider,
modelId: n.id,
agentId: e.agentId
});
const d = {
provider: n.provider,
modelId: n.id,
api: o.api,
baseUrl: o.baseUrl,
authMode: r.selectedAuthMode,
runtimeId: i ?? n.nativeRuntime,
modelParams: n.params,
params: Object.assign({}, s, c, l, u),
requestCapabilities: resolveProviderFastModeRequestCapabilities({
provider: n.provider,
api: o.api,
baseUrl: o.baseUrl,
providerMetadataOwners: e.metadataSnapshot.owners
})
};
return {
supportsFastMode: a.resolveFastModeSupport?.(d),
serviceTiers: a.resolveServiceTiers?.(d),
supportsServiceTierRecovery: d.runtimeId === "openclaw" && supportsNativeOpenAIResponsesEndpoint({
provider: n.provider,
api: o.api ?? "",
baseUrl: o.baseUrl
})
};
};
const n = /* @__PURE__ */ new WeakMap();
return (e, t, r = e.nativeRuntime) => {
if (t.routeResolution !== null && !t.selectedRoute) return {};
const { api: i, baseUrl: a } = t.selectedRoute ?? e;
const o = t.selectedAuthMode;
const s = n.get(e) ?? [];
const c = s.find((e) => e.api === i && e.baseUrl === a && e.authMode === o && e.runtimeId === r);
if (c) return c.policy;
const l = prepare(e, t, r);
s.push({
api: i,
baseUrl: a,
authMode: o,
runtimeId: r,
policy: l
});
n.set(e, s);
return l;
};
}
//#endregion
//#region src/gateway/server-methods/models-list-capabilities.ts
var UnknownModelCatalogProviderError = class extends Error {};
function selectorCapabilities(e) {
const t = [
"boolean",
"choice",
"score"
].filter((t) => e.questions?.[t]);
if (!t.length) return;
const n = { questionTypes: t };
const r = e.limits;
if (r?.maxQuestions !== void 0) n.maxQuestions = r.maxQuestions;
if (r?.maxInputTokens !== void 0) n.maxInputTokens = r.maxInputTokens;
if (r?.inputTokenScope !== void 0) n.inputTokenScope = r.inputTokenScope;
if (e.questions?.choice?.maxOptions !== void 0) n.maxChoiceAlternatives = e.questions.choice.maxOptions;
if (e.questions?.score?.maxOptions !== void 0) n.maxScoreLevels = e.questions.score.maxOptions;
if (e.questions?.boolean?.requiresCriteria !== void 0) n.requiresBooleanCriteria = e.questions.boolean.requiresCriteria;
if (e.confidence !== void 0) n.confidence = e.confidence;
return n;
}
function listDecisionModels({ config: e, snapshot: t }) {
const n = [];
if (e.plugins?.enabled !== false) {
const r = /* @__PURE__ */ new Set();
for (const i of listAvailableManifestContractPlugins({
snapshot: t,
config: e,
contract: "decisionProviders"
})) for (const [e, t] of Object.entries(i.modelCatalog?.providers ?? {})) {
if (!i.contracts?.decisionProviders?.includes(e)) continue;
for (const a of t.models ?? []) {
const t = a.inference?.decision;
const o = `${e}/${a.id}`;
if (!t || r.has(o)) continue;
const s = selectorCapabilities(t);
n.push({
provider: e,
id: a.id,
name: a.name ?? a.id,
pluginId: i.id,
...s ? { capabilities: s } : {}
});
r.add(o);
}
}
}
return n;
}
function createModelsListProviderFilter(e) {
const { config: t, metadataSnapshot: n, catalog: r } = e;
const i = createPreparedModelCatalogProviderNormalizer(n, t);
const a = e.provider ? i(e.provider) : void 0;
if (a) {
const o = (n.owners.contracts.get("decisionProviders") ?? []).flatMap((e) => n.byPluginId.get(e)?.contracts?.decisionProviders ?? []);
if (!new Set([
...n.owners.providers.keys(),
...n.owners.modelCatalogProviders.keys(),
...o,
...Object.keys(t.models?.providers ?? {}),
...r.map((e) => e.provider)
].map(i)).has(a)) throw new UnknownModelCatalogProviderError(`Unknown model catalog provider ${JSON.stringify(e.provider)}. Run openclaw models list --all to list models and their provider IDs.`);
}
return {
normalizeProvider: i,
providerFilter: a,
matchesProvider: (e) => !a || i(e.provider) === a
};
}
//#endregion
//#region src/gateway/server-methods/models-list-result.default-models.ts
/**
* Auto utility preview from agents.defaults.model, plus the route the utility
* model in effect (automatic or explicit) runs on.
*/
async function resolveDefaultModelsPreview(e) {
const { cfg: t, metadataSnapshot: n, snapshot: r } = e;
const i = resolveDefaultModelForAgent({
cfg: t,
manifestPlugins: n,
allowPluginNormalization: false
});
const a = resolveAutomaticUtilityModelRef({
cfg: t,
primaryProvider: i.provider,
primaryModelRef: resolveAgentModelPrimaryValue(t.agents?.defaults?.model),
primaryModelId: i.model,
catalog: r,
metadataSnapshot: n
}) ?? null;
const o = tryResolveLegacyCompatibilityAgentId(t);
const s = readUtilityModelSetting(t);
const c = o ? readUtilityModelSetting(t, o) : void 0;
if (!o || o !== e.agentId || !c || c.kind !== s.kind || c.kind === "disabled" || c.kind === "explicit" && s.kind === "explicit" && c.modelRef !== s.modelRef || c.kind === "auto" && (!a || resolveUtilityModelRefForAgent({
cfg: t,
agentId: o,
catalog: r,
metadataSnapshot: n
}) !== a)) return { automaticUtilityModel: a };
const { resolveUtilityCompletionRuntimeForAgent: l } = await import("./utility-completion-BfBMgtUp.mjs");
const u = await l({
...e,
agentId: o
});
return {
automaticUtilityModel: a,
...u ? { utilityRuntime: u } : {}
};
}
//#endregion
//#region src/gateway/server-methods/models-list-runtime-choices.ts
/** Captures alternative runtime metadata while readiness stays with the prepared catalog owner. */
function prepareModelPickerRuntimeChoices(e) {
const { cfg: t, agentId: n, entry: r, variants: i, requestedRuntimes: a, baseEvaluation: o, decisions: s, evaluateNative: c, projectPublic: l } = e;
const u = resolveCatalogDecisionRuntime({
cfg: t,
agentId: n,
entry: r,
evaluation: o,
pluginRegistry: s.pluginRegistry,
resolveOpenAIProviderRoutes: s.resolveOpenAIProviderRoutes
});
const d = a.filter((e) => e !== (u?.id ?? "openclaw")).map((e) => {
const n = resolveCompatibleAgentRuntimeForProvider({
provider: r.provider,
runtime: e,
cfg: t
}) === e;
const { entry: a, variants: o } = selectModelCatalogRuntimeEntry({
entry: r,
routeVariants: i,
runtimeId: e
});
const u = createModelCatalogView({
cfg: t,
catalog: [a],
routeVariants: o
});
const d = s.evaluateEntry(a, i, e);
const f = e === "openclaw" || s.pluginRegistry?.agentHarnesses.some(({ harness: t }) => t.id === e) || listCliRuntimeModelBackendBindings().some((t) => t.runtime === e && normalizeProviderId(t.provider) === normalizeProviderId(r.provider));
return (t) => {
const r = c(a, d, e);
const i = u.readProjection(a, resolveLogicalModelCatalogEntryState({ evaluation: r }).routeProjection).runtimeEntry;
const { id: o, name: p, provider: m, alias: h, tags: g, apiKeySupported: _, runtimeChoices: v, agentRuntime: y, ...b } = l(i, r, e);
const x = {
id: e,
source: "model",
...y
};
if (!n || t?.includes(e) !== true) {
const t = r.selectedRoute?.runtimePolicy?.compatibleIds;
const i = !n || s.pluginRegistry !== void 0 && !f || t !== void 0 && !t.includes(e) ? "unsupported-runtime" : r.unavailableReason;
return {
agentRuntime: x,
available: false,
...i ? { unavailableReason: i } : {},
...r.unavailableUntil === void 0 ? {} : { unavailableUntil: r.unavailableUntil }
};
}
return {
...b,
agentRuntime: x,
available: r.availability === true
};
};
});
return () => {
const e = s.runtimeChoices(r, i);
return d.map((t) => t(e));
};
}
//#endregion
//#region src/gateway/server-methods/models-list-result.ts
async function buildModelsListResult(e) {
const t = await prepareModelsListResult(e);
if (!t.isCurrent()) throw new PreparedModelRuntimePublicationSupersededError("Model catalog changed while preparing this result. Retry the request.");
e.readScope?.draftAccountSelection?.assertCurrent();
return t.read();
}
/** Prepares catalog work once; the returned reader revalidates native readiness without I/O. */
async function prepareModelsListResult({ preparationAuthority: e, ...t }) {
const { source: n } = t;
const r = t.readScope;
const i = t.publicationScope ?? r;
const a = r?.draftAccountSelection;
const o = e ?? (a ? {
withCurrent: i?.withCurrent,
assertCurrent: () => {
a.assertCurrent();
i?.assertCurrent?.();
}
} : i);
const s = a ? {
authProfileOverride: a.authProfileId,
authProfileOverrideSource: "user"
} : r?.sessionEntry;
const c = !r?.sessionKey && !r?.sessionEntry;
a?.assertCurrent();
const l = n.kind === "published" ? n.owner : void 0;
const u = n.kind === "published" ? n.owner.config : n.context.getRuntimeConfig();
const d = resolveAmbientOwnerAgentId(u, t.agentId);
const f = resolveSessionCatalogProfiles(s, u, d);
const p = t.params.view ?? "default";
const m = t.params.refresh === true;
const h = t.preloadedCatalog?.agentId === d && preparedModelRuntimeConfigsMatch(t.preloadedCatalog.config, u) ? t.preloadedCatalog : void 0;
const g = h !== void 0 && t.catalogProjector !== void 0;
if (n.kind === "gateway" && m && !t.preloadedOnly) {
await loadDeferredCatalog(n.context, d, {
readOnly: false,
refreshFullCatalog: true,
...t.params.provider ? { providerDiscoveryProviderIds: [t.params.provider] } : {}
});
await withCurrentReadAuthority(o, () => {});
}
const _ = n.kind === "gateway" && !g ? await readPreparedCatalog(n.context, d) : void 0;
await withCurrentReadAuthority(o, () => {});
if (!l && !g && !_) throw new PreparedModelRuntimeOwnerNotPublishedError("Model catalog is not ready. Retry after Gateway startup or refresh finishes.");
if (_ && t.agentId !== void 0 && !publishedModelCatalogOwnerMatchesAgent(_, d)) return {
read: () => ({ models: [] }),
isCurrent: () => true
};
const v = l?.modelCatalog ?? (g ? h.snapshot : _);
if (!v) throw new Error("Model catalog omitted its published snapshot");
const y = l ?? _;
const b = captureRuntimeConfig(y?.config ?? u);
const x = y?.agentId ?? d;
const S = y?.workspaceDir ?? resolveAgentWorkspaceDir(b, x) ?? resolveDefaultAgentWorkspaceDir();
const C = y ?? t.catalogProjector;
const w = C?.metadataSnapshot;
const T = C?.authStore;
const E = C?.pluginRegistry;
return withPluginRuntimeRegistryScope(E, async () => {
const e = C?.isCurrent;
const isCurrent = () => e?.() === true && i?.isCurrent?.() !== false;
if (!w || !T) throw new Error("Gateway model catalog owner omitted prepared metadata or auth state");
const n = listDecisionModels({
config: b,
snapshot: w
});
const u = resolveSessionModelRef(b, r?.sessionEntry, x, { allowPluginNormalization: false });
const d = t.includeManualSelection && p === "configured" && r?.sessionEntry ? u : void 0;
const h = prepareModelCatalogView({
cfg: b,
agentId: x,
agentDir: y?.agentDir,
workspaceDir: S,
snapshot: v,
view: p,
retainedModel: d,
metadataSnapshot: w,
pluginRegistry: E,
isCurrent,
observationConfig: C?.observationConfig
});
const { defaultModel: D } = h;
const O = C?.authModes;
const k = C?.authMaterializations;
a?.assertCurrent();
const decisionOwner = () => ({
cfg: b,
agentId: x,
metadataSnapshot: w,
preparedAuthStore: T,
accountCatalog: C?.accountCatalog,
preparedRuntimeAuthModes: O,
preparedRuntimeAuthMaterializations: k,
pluginRegistry: E,
isCurrent,
observationConfig: C?.observationConfig
});
const A = {
...decisionOwner(),
agentDir: y?.agentDir,
workspaceDir: S,
snapshot: {
...v,
entries: h.catalog,
get pendingProviders() {
return v.pendingProviders;
},
get refreshFailed() {
return v.refreshFailed;
}
},
preparedSyntheticAuthComplete: l ? isPreparedModelCatalogFull(l.modelCatalog) : _?.catalogComplete === true,
requesterProfileId: p === "provider-config" || !c ? void 0 : a?.owner ?? t.requesterProfileId,
...p === "provider-config" ? {} : f,
routeResolverFactory: t.routeResolverFactory
};
const j = g ? t.catalogProjector : void 0;
const M = j ? await withCurrentReadAuthority(o, () => j) : await prepareModelCatalogDecisions(A, o);
if (p !== "provider-config") await M.prepareSelectedAccountCatalog(() => {
a?.assertCurrent();
i?.assertCurrent?.();
if (!isCurrent()) throw new PreparedModelRuntimePublicationSupersededError("Selected account catalog changed");
}, {
refresh: m && !t.preloadedOnly && !t.params.preparedOnly,
withCurrent: o?.withCurrent,
beforeRequest: i?.beforeRequest
});
await withCurrentReadAuthority(o, () => {});
const N = dedupeModelCatalogEntries([...h.catalog, ...M.snapshot.entries]).filter((e) => e.inference?.chat !== false);
const { evaluateNative: P } = M;
const { normalizeProvider: F, providerFilter: I, matchesProvider: L } = createModelsListProviderFilter({
config: b,
metadataSnapshot: w,
catalog: N,
provider: t.params.provider
});
const R = n.filter(L);
const { routeVariants: z, providerOutcomes: B } = M.snapshot;
const V = projectProviderCatalogOutcomes(B);
const H = createModelVisibilityPolicy({
cfg: b,
catalog: N,
defaultProvider: DEFAULT_PROVIDER,
defaultModel: D,
agentId: x,
...RUNTIME_MODEL_VISIBILITY_NORMALIZATION,
manifestPlugins: w
});
a?.assertCurrent();
const U = t.params.includeDefaultModels ?? (p === "configured" && !t.params.sessionKey && !t.params.authProfileId) ? await resolveDefaultModelsPreview({
cfg: b,
agentId: x,
agentDir: y?.agentDir,
workspaceDir: S,
metadataSnapshot: w,
preparedAuthStore: T,
preparedRuntimeAuthModes: C?.authModes,
preparedRuntimeAuthMaterializations: C?.authMaterializations,
pluginRegistry: E,
snapshot: v,
isCurrent
}) : void 0;
a?.assertCurrent();
const W = {
...U ? { defaultModels: U } : {},
...V?.length ? { providerOutcomes: V } : {}
};
const G = p === "provider-config" || !r && !t.requesterProfileId ? void 0 : await withCurrentReadAuthority(o, () => prepareChatAccountSelection({
authStore: M.authStore,
sessionEntry: s,
requesterProfileId: a?.owner ?? r?.requesterProfileId ?? t.requesterProfileId
}));
await withCurrentReadAuthority(o, () => {});
const readOutcomeProjection = () => {
const e = G?.();
const t = M.snapshot.pendingProviders?.filter((e) => (!I || F(e) === I) && (p === "all" || p === "provider-config" || H.allowAny || [...H.allowedKeys].some((t) => t.startsWith(`${e}/`))));
return {
...t?.length ? { pendingProviders: t } : {},
...W,
...v.refreshFailed ? { refreshFailed: true } : {},
...e ? { accountSelection: e } : {},
...R.length ? { decisionModels: R } : {}
};
};
const K = t.params.includeProviderCapabilities ? resolveModelProviderCapabilities({
config: b,
metadataSnapshot: w,
workspaceDir: S
}) : void 0;
const q = new Map(K?.capabilities.map(({ provider: e, apiKeySupported: t }) => [e, t]));
const J = t.includeManualSelection ? H.allows : void 0;
const Y = resolveConfiguredModelEntries({
cfg: b,
agentId: x,
defaultModel: D,
canonicalizeRef: (e) => ({
...e,
model: resolveProviderModelCatalogId({
provider: e.provider,
modelId: e.model
}) ?? e.model
}),
...RUNTIME_MODEL_VISIBILITY_NORMALIZATION,
manifestPlugins: w
}).byKey;
const createPublicProjector = (e, n) => {
const r = e.snapshot;
const i = C?.accountCatalog;
const a = t.params.includeDetails;
const o = p === "provider-config" || a;
const s = p === "provider-config" ? isCurrent : () => isCurrent() && e.isCurrent();
const c = createModelSpeedPolicyResolver({
cfg: b,
agentId: x,
catalog: n,
metadataSnapshot: w,
pluginRegistry: E
});
const l = createThinkingCatalogResolver(N);
const u = /* @__PURE__ */ new WeakMap();
return (t, n, d) => {
const f = d ?? "";
let m = u.get(t)?.get(f);
if (!m) {
const r = Y.get(modelKey(t.provider, t.id));
const i = r?.aliases.at(-1);
const o = r?.aliasDisabled ? Object.assign({}, t, { alias: void 0 }) : i && i !== t.alias ? Object.assign({}, t, { alias: i }) : t;
const s = K?.resolveProvider(t.provider);
const c = d ? {
id: d,
source: "model"
} : resolveCatalogDecisionRuntime({
cfg: b,
agentId: x,
entry: t,
evaluation: n,
pluginRegistry: E,
resolveOpenAIProviderRoutes: e.resolveOpenAIProviderRoutes
}) ?? {
id: "openclaw",
source: "implicit"
};
const h = E ? withPluginRuntimeRegistryScope(E, () => projectWorkerPlacementAgentRuntime(c)) : projectWorkerPlacementAgentRuntime(c);
const g = typeof o.reasoning !== "boolean" ? void 0 : resolveGatewayModelThinkingProfile({
cfg: b,
agentId: x,
provider: t.provider,
model: t.id,
agentRuntime: c.id,
modelCatalog: d ? [t] : N,
catalogResolver: d ? createThinkingCatalogResolver([t]) : l,
configuredReasoning: o.configuredReasoning ?? o.reasoning,
thinkingPolicyProvider: o.thinkingPolicyProvider
});
const _ = resolveFastModeState({
cfg: b,
agentId: x,
provider: t.provider,
model: t.id
});
m = {
...buildPublicModelProjection(o, { includeDetails: a }),
...J ? { manualSelectionAllowed: J({
provider: t.provider,
model: t.id
}) } : {},
...r?.tags.size ? { tags: [...r.tags] } : {},
agentRuntime: h,
...g,
..._.source === "default" ? {} : { effectiveFastMode: _.mode },
...s && q.has(s) ? { apiKeySupported: q.get(s) === true } : {},
...p === "provider-config" && t.input?.length ? { input: t.input } : {}
};
const v = u.get(t) ?? /* @__PURE__ */ new Map();
v.set(f, m);
u.set(t, v);
}
const h = o || n.runtimeAuth?.source === "native" ? n.availability : n.availability ?? false;
const g = m.agentRuntime.id;
const _ = c(t, n, g);
const v = _.supportsFastMode;
const y = projectModelServiceTiers({
config: b,
agentId: x,
pluginRegistry: E,
snapshot: r,
entry: t,
evaluation: n,
runtimeId: m.agentRuntime?.id ?? "openclaw",
modelServiceTiers: _.serviceTiers,
isCurrent: s
});
const S = n.selectedCredential;
const C = n.selectedRoute;
const w = s() && n.availability === true && _.supportsServiceTierRecovery && S && S.source !== "harness" && C ? i?.readServiceTierObservations({
identityKey: S.identityKey,
modelId: t.id,
runtimeId: m.agentRuntime?.id ?? "openclaw",
api: C.api,
baseUrl: C.baseUrl
}) : void 0;
const T = {
...m,
...v === void 0 ? {} : { supportsFastMode: v },
..._.supportsServiceTierRecovery === true ? { supportsServiceTierRecovery: true } : {},
...y === void 0 ? {} : { serviceTiers: y },
...p === "provider-config" ? {} : projectModelCatalogAccessPrograms({
config: b,
agentId: x,
snapshot: r,
entry: t,
evaluation: n,
runtimeId: m.agentRuntime?.id ?? "openclaw",
isCurrent: s
}),
...w?.length ? {
serviceTierObservation: w.at(-1),
serviceTierObservations: w.toSorted((e, t) => e.requestedTier.localeCompare(t.requestedTier))
} : {},
...h === void 0 ? {} : { available: h },
...h === false && n.unavailableReason ? {
unavailableReason: n.unavailableReason,
...n.unavailableUntil !== void 0 ? { unavailableUntil: n.unavailableUntil } : {}
} : {}
};
return retainModelChoiceAccountPin(T, e.hasPinnedAccount(t));
};
};
if (p === "provider-config") {
const e = getRuntimeConfigSourceSnapshot() ?? b;
const n = {
entries: h.providerInventory(e, N),
routeVariants: z,
...B?.length ? { providerOutcomes: B } : {}
};
const r = createModelCatalogDecisions({
...decisionOwner(),
snapshot: n,
...t.routeResolverFactory ? { routeResolverFactory: t.routeResolverFactory } : {}
});
const i = await r.projectCatalog(o);
const a = await withCurrentReadAuthority(o, () => i.map((e) => ({
entry: e,
host: r.evaluateEntry(e)
})));
const s = createPublicProjector(r, i);
return {
isCurrent: () => isCurrent() && r.isCurrent(),
read: () => ({
models: a.filter(({ entry: e }) => L(e)).map(({ entry: e, host: t }) => s(e, P(e, t))),
...readOutcomeProjection()
})
};
}
const X = /* @__PURE__ */ new Map();
const Z = /* @__PURE__ */ new Map();
const Q = /* @__PURE__ */ new Map();
const ee = p === "all" ? [] : [H, ...Object.values(b.gateway?.roles?.definitions ?? {}).flatMap(({ modelPolicy: e }) => prepareOperatorModelPolicy({
cfg: b,
policy: e,
manifestPlugins: w
}) ?? [])];
const $ = createPublicProjector(M, N);
const te = await withCurrentReadAuthority(o, () => prepareLogicalVisibleModelCatalog({
cfg: b,
isCurrent: () => isCurrent() && M.isCurrent(),
metadataSnapshot: w,
catalog: N,
defaultProvider: DEFAULT_PROVIDER,
defaultModel: D,
agentId: x,
workspaceDir: S,
view: p,
policy: H,
retainedModel: d,
selectedModel: u,
routeVariants: z,
prepareEntry: (e, t) => {
const n = resolveModelCatalogIdentityKey(e);
const r = p === "all" ? void 0 : resolveCliRuntimeTwinRoute(e, {
config: b,
agentId: x,
cliRuntimeBindings: M.cliRuntimeBindings
});
if (r) Q.set(n, r);
const i = Y.get(modelKey(e.provider, e.id))?.pickerRuntimes;
const a = i?.length ? resolveAgentHarnessPolicy({
config: b,
agentId: x,
provider: e.provider,
modelId: e.id,
modelApi: e.api,
modelBaseUrl: e.baseUrl,
resolveOpenAIProviderRoutes: M.resolveOpenAIProviderRoutes
}).runtime : void 0;
const o = M.evaluateEntry(e, t, a);
const s = a ? {
...o,
requestedRuntimeId: void 0
} : o;
if (i?.length) Z.set(n, prepareModelPickerRuntimeChoices({
cfg: b,
agentId: x,
entry: e,
variants: t,
requestedRuntimes: i,
baseEvaluation: P(e, s),
decisions: M,
evaluateNative: P,
projectPublic: $
}));
return () => {
const t = P(e, s);
X.set(n, t);
const r = t.routeResolution === null && normalizeProviderId(e.provider) !== "openai" && t.availability === void 0 && t.evidence === "synthetic";
return resolveLogicalModelCatalogEntryState({
evaluation: t,
authBacked: t.availability === true || r
});
};
}
}));
return {
isCurrent: () => isCurrent() && M.isCurrent(),
read: () => {
const e = te();
const t = createModelCatalogIdentityKeyResolver();
const n = createModelPickerRecommendationRank(b);
return {
models: omitCliRuntimeAliasTwins(e.filter(L).map((e) => {
const r = t(e);
const i = X.get(r);
if (!i) throw new Error("Model catalog publication omitted prepared auth evaluation");
const a = Z.get(r)?.();
const o = $(e, i);
if (a?.length) o.runtimeChoices = a;
if (n(e) !== void 0) o.recommended = true;
return {
row: o,
twin: Q.get(r)
};
}), ee),
...readOutcomeProjection()
};
}
};
});
}
//#endregion
export { prepareModelsListResult as n, UnknownModelCatalogProviderError as r, buildModelsListResult as t };