openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
11 lines • 22.9 kB
JavaScript
import{u as getPluginMetadataSnapshotCache,w as withPluginCache}from"./plugin-cache-B6QVpzXr.mjs";import{d as withPluginRuntimeRegistryScope}from"./gateway-request-scope-7deHmsb_.mjs";import"./model-ref-shared-T-aCqInj.mjs";import{r as normalizeProviderId}from"./provider-id-A-8WTtLA.mjs";import{A as tryResolveLegacyCompatibilityAgentId,f as resolveAgentWorkspaceDir,m as resolveAmbientOwnerAgentId}from"./agent-scope-config-CG9CFpGX.mjs";import{t as resolveDefaultAgentWorkspaceDir}from"./workspace-default-path-ULYbn-EL.mjs";import{c as getRuntimeConfigSourceSnapshot}from"./runtime-snapshot-Bg5K4JNu.mjs";import{s as resolveAgentModelPrimaryValue}from"./model-input-CJnF-FEy.mjs";import{i as DEFAULT_PROVIDER}from"./defaults-k51tX6yK.mjs";import"./agent-scope-Dw5XRSEh.mjs";import"./legacy.default-agent-owner-DUgZJ5NH.mjs";import{i as resolveProviderPolicySurface}from"./provider-public-artifacts-DlwyY-Ow.mjs";import{i as matchesProviderPluginRef}from"./provider-registry-shared-WqkaV5jB.mjs";import{i as listCliRuntimeModelBackendBindings}from"./cli-backends-BDgFsc0L.mjs";import{t as captureRuntimeConfig}from"./runtime-source-projection-DvPkX_nq.mjs";import{i as resolveProviderModelCatalogId}from"./provider-model-routes-D-c2AdKe.mjs";import{b as readUtilityModelSetting,o as dedupeModelCatalogEntries}from"./model-selection-shared-CIOFxJ36.mjs";import{a as resolveModelCatalogIdentityKey,t as createModelCatalogIdentityKeyResolver}from"./openai-model-routes-DFmM1mZU.mjs";import{r as modelKey}from"./provider-registry-index-fv5AHL27.mjs";import{n as resolveDefaultModelForAgent}from"./model-selection-config-CnvHkHXn.mjs";import{n as prepareOperatorModelPolicy}from"./operator-model-policy-jasRvLsy.mjs";import{a as resolveModelExtraParamSources}from"./model-extra-params-CALSEb0J.mjs";import{s as hasCurrentPreparedModelCatalogReplacement}from"./prepared-model-runtime.lifecycle--BWG5_Dq.mjs";import"./config-DkZ8y8Gv.mjs";import{n as createModelVisibilityPolicy,t as RUNTIME_MODEL_VISIBILITY_NORMALIZATION}from"./model-visibility-policy-Bd5YBCCk.mjs";import{t as resolveAgentHarnessPolicy}from"./policy-B5H6zqjn.mjs";import{t as createThinkingCatalogResolver}from"./thinking-D7mmXLQ_.mjs";import{r as PreparedModelRuntimePublicationSupersededError,t as PreparedModelRuntimeOwnerNotPublishedError}from"./prepared-model-runtime-admission-errors-DZto8oll.mjs";import{r as resolveProviderFastModeRequestCapabilities}from"./provider-attribution-JD1bPk3I.mjs";import{l as resolveCliRuntimeTwinRoute,s as omitCliRuntimeAliasTwins}from"./model-runtime-aliases-BFQ__k4Y.mjs";import{t as resolveCompatibleAgentRuntimeForProvider}from"./session-runtime-compat-DGwJiPrH.mjs";import{a as prepareModelCatalogView,n as createModelCatalogView,o as selectModelCatalogRuntimeEntry}from"./model-catalog-view-Dlcu0aHX.mjs";import{n as publishedModelCatalogOwnerMatchesAgent}from"./prepared-model-catalog-owner-CH4iXuo9.mjs";import{r as resolveSessionModelRef}from"./session-model-ref-B_XpQbtb.mjs";import{t as projectWorkerPlacementAgentRuntime}from"./placement-session-runtime-BPT1cH3j.mjs";import{i as resolveGatewayModelThinkingProfile}from"./session-utils-model-Cp0PM3hO.mjs";import{t as resolveFastModeState}from"./fast-mode-Bole1OXq.mjs";import{r as createModelPickerRecommendationRank}from"./model-catalog-order-D7AfVn17.mjs";import"./prepared-model-runtime.errors-CJIB8kC0.mjs";import{n as isPreparedModelCatalogFull}from"./prepared-model-runtime.full-catalog-BxShrXPt.mjs";import{T as preparedModelRuntimeConfigsMatch}from"./prepared-model-runtime-Bq1P9DhS.mjs";import{n as resolveConfiguredModelEntries}from"./configured-model-entries-CeK5vxAX.mjs";import{n as withCurrentReadAuthority}from"./current-read-authority-J_xgisvq.mjs";import"./workspace-1G3FI-0P.mjs";import{o as resolveUtilityModelSelectionForAgent,t as resolveAutomaticUtilityModelRef}from"./utility-model-CDT0xFeg.mjs";import{n as readPreparedCatalog,t as loadDeferredCatalog}from"./server-model-catalog-auth-DgYxoyva.mjs";import{n as prepareModelCatalogDecisions,t as createModelCatalogDecisions}from"./model-catalog-decisions-DfA_bB0A.mjs";import{t as resolveCatalogDecisionRuntime}from"./model-catalog-decision-runtime-uVizY4Lw.mjs";import{n as projectModelCatalogAccessPrograms}from"./model-catalog-access-programs-CLJ7pxBX.mjs";import{n as resolveLogicalModelCatalogEntryState,t as prepareLogicalVisibleModelCatalog}from"./model-catalog-visibility-BJvZBN-f.mjs";import{d as projectModelServiceTiers,f as projectProviderCatalogOutcomes,l as buildPublicModelProjection,m as prepareChatAccountSelection,p as retainModelChoiceAccountPin,s as resolveSessionCatalogProfiles,u as projectModelCatalogRefreshStatus}from"./chat-metadata-session-projection-tb9Ydp9S.mjs";import{t as resolveModelProviderCapabilities}from"./model-provider-capabilities-D9B2E7Cu.mjs";import{n as createModelsListProviderFilter,r as listDecisionModels}from"./models-list-capabilities-3XqA-G9v.mjs";import{supportsNativeOpenAIResponsesEndpoint}from"@openclaw/ai/internal/openai-responses-payload-policy";
//!src/agents/model-fast-mode.ts
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}}
//!src/gateway/server-methods/models-list-catalog.ts
async function readModelsListCatalog(e,t,n){const read=()=>readPreparedCatalog(e,t);let r=await withCurrentReadAuthority(n,read);await withCurrentReadAuthority(n,()=>{});if(r&&hasCurrentPreparedModelCatalogReplacement(r)){r=await withCurrentReadAuthority(n,read);await withCurrentReadAuthority(n,()=>{})}return r}
//!src/gateway/server-methods/models-list-result.default-models.ts
async function resolveDefaultModelsPreview(e){const{request:t,view:n}=e;if(!(t.includeDefaultModels??(n===`configured`&&!t.sessionKey&&!t.authProfileId)))return;const r=t.includeDefaultModels===true&&!t.sessionKey&&!t.authProfileId;const{cfg:i,metadataSnapshot:a,snapshot:o}=e;const s=resolveUtilityModelSelectionForAgent({cfg:i,agentId:e.agentId,catalog:o,metadataSnapshot:a});const c=`modelRef`in s?s:{modelRef:null,source:readUtilityModelSetting(i,e.agentId).kind===`disabled`?`disabled`:`none`};const l=resolveDefaultModelForAgent({cfg:i,manifestPlugins:a,allowPluginNormalization:false});const u=resolveAutomaticUtilityModelRef({cfg:i,primaryProvider:l.provider,primaryModelRef:resolveAgentModelPrimaryValue(i.agents?.defaults?.model),primaryModelId:l.model,catalog:o,metadataSnapshot:a})??null;const d=tryResolveLegacyCompatibilityAgentId(i);const f=readUtilityModelSetting(i);const p=d?readUtilityModelSetting(i,d):void 0;if(!d||d!==e.agentId||!p||p.kind!==f.kind||p.kind===`disabled`||p.kind===`explicit`&&f.kind===`explicit`&&p.modelRef!==f.modelRef||p.kind===`auto`&&(!u||c.modelRef!==u))return{defaultModels:{automaticUtilityModel:u},...r?{utilityModel:c}:{}};const{resolveUtilityCompletionRuntimeForAgent:m}=await import(`./utility-completion-CIoP3R-m.mjs`);const h=await m({...e,agentId:d});return{defaultModels:{automaticUtilityModel:u,...h?{utilityRuntime:h}:{}},...r?{utilityModel:c}:{}}}
//!src/gateway/server-methods/models-list-runtime-choices.ts
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))}}
//!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()}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 readModelsListCatalog(n.context,d,o):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,catalog:v.entries});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;a?.assertCurrent();const decisionOwner=()=>({cfg:b,agentId:x,metadataSnapshot:w,preparedAuthStore:T,accountCatalog:C?.accountCatalog,preparedRuntimeAuthModes:C?.authModes,preparedRuntimeAuthMaterializations:C?.authMaterializations,pluginRegistry:E,isCurrent,observationConfig:C?.observationConfig});const O={...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 k=g?t.catalogProjector:void 0;const A=k?await withCurrentReadAuthority(o,()=>k):await prepareModelCatalogDecisions(O,o);if(p!==`provider-config`)await A.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{routeVariants:j,providerOutcomes:M,entries:N}=A.snapshot;const P=dedupeModelCatalogEntries([...h.catalog,...N]);const F=P.filter(e=>e.inference?.chat!==false);const{evaluateNative:I}=A;const{normalizeProvider:L,providerFilter:R,matchesProvider:z}=createModelsListProviderFilter({config:b,metadataSnapshot:w,catalog:F,provider:t.params.provider});const B=n.filter(z);const V=projectProviderCatalogOutcomes(M);const H=createModelVisibilityPolicy({cfg:b,catalog:P,defaultProvider:DEFAULT_PROVIDER,defaultModel:D,agentId:x,...RUNTIME_MODEL_VISIBILITY_NORMALIZATION,manifestPlugins:w});a?.assertCurrent();const U=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,request:t.params,view:p});a?.assertCurrent();const W={...U,...V?.length?{providerOutcomes:V}:{}};const G=p===`provider-config`||!r&&!t.requesterProfileId?void 0:await withCurrentReadAuthority(o,()=>prepareChatAccountSelection({authStore:A.authStore,sessionEntry:s,requesterProfileId:a?.owner??r?.requesterProfileId??t.requesterProfileId}));await withCurrentReadAuthority(o,()=>{});const readOutcomeProjection=()=>{const e=G?.();const isVisibleProvider=e=>(!R||L(e)===R)&&([`all`,`provider-config`].includes(p)||H.allowAny||[...H.allowedKeys].some(t=>t.startsWith(`${e}/`)));return{...W,...projectModelCatalogRefreshStatus({snapshot:v,pendingProviders:A.snapshot.pendingProviders,isVisibleProvider}),...e?{accountSelection:e}:{},...B.length?{decisionModels:B}:{}}};const K=t.params.includeProviderCapabilities===true?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(F);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]:F,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:g,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:g,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:g,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,F),routeVariants:j,...M?.length?{providerOutcomes:M}:{}};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})=>z(e)).map(({entry:e,host:t})=>s(e,I(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(A,F);const te=await withCurrentReadAuthority(o,()=>prepareLogicalVisibleModelCatalog({cfg:b,isCurrent:()=>isCurrent()&&A.isCurrent(),metadataSnapshot:w,catalog:F,defaultProvider:DEFAULT_PROVIDER,defaultModel:D,agentId:x,workspaceDir:S,view:p,policy:H,retainedModel:d,selectedModel:u,routeVariants:j,prepareEntry:(e,t)=>{const n=resolveModelCatalogIdentityKey(e);const r=p===`all`?void 0:resolveCliRuntimeTwinRoute(e,{config:b,agentId:x,cliRuntimeBindings:A.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:A.resolveOpenAIProviderRoutes}).runtime:void 0;const o=A.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:I(e,s),decisions:A,evaluateNative:I,projectPublic:$}));return()=>{const t=I(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()&&A.isCurrent(),read:()=>{const e=te();const t=createModelCatalogIdentityKeyResolver();const n=createModelPickerRecommendationRank(b);return{models:omitCliRuntimeAliasTwins(e.filter(z).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()}}}})}export{prepareModelsListResult as n,buildModelsListResult as t};