UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 5.28 kB
import{o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import"./src-0ci69Prg.mjs";import{r as normalizeProviderId,t as findNormalizedProviderKey}from"./provider-id-A-8WTtLA.mjs";import{i as getCurrentPluginMetadataSnapshot}from"./current-plugin-metadata-snapshot-CYi8VAby.mjs";import{a as normalizeOptionalAgentRuntimeId}from"./agent-runtime-id-dWmvEQWJ.mjs";import{n as isManifestPluginAvailableForControlPlane,s as loadManifestMetadataSnapshot}from"./manifest-contract-eligibility-BFn2JM5T.mjs";import{r as modelKey}from"./provider-registry-index-fv5AHL27.mjs";import{t as RUNTIME_MODEL_VISIBILITY_NORMALIZATION}from"./model-visibility-policy-Bd5YBCCk.mjs";import{t as resolveAgentHarnessPolicy}from"./policy-B5H6zqjn.mjs";import"./model-selection-CNHinoVN.mjs";import{c as resolveCliRuntimeExecutionProvider}from"./model-runtime-aliases-BFQ__k4Y.mjs";import{o as resolveEffectiveAgentRuntime}from"./thinking-runtime-V6V09nGt.mjs";import{n as resolveModelRuntimeDirective}from"./directive-handling.model-runtime-Dj3PYFBx.mjs";import{t as workerInferenceMetadata}from"./inference-placement-BT7fCd4s.mjs"; //!src/auto-reply/reply/model-runtime-normalization.ts function normalizeRuntimeChoiceId(e){const t=normalizeLowercaseStringOrEmpty(e);return!t||t===`auto`||t==="default"?`openclaw`:t}function resolveRuntimeNormalization(e){return{...RUNTIME_MODEL_VISIBILITY_NORMALIZATION,manifestPlugins:getCurrentPluginMetadataSnapshot({config:e,allowWorkspaceScopedSnapshot:true})}}function findSelectedCatalogEntry(e){const t=normalizeProviderId(e.provider);const n=modelKey(t,e.model);return e.catalog?.find(n=>normalizeProviderId(n.provider)===t&&n.id.trim()===e.model.trim())??e.catalog?.find(e=>modelKey(e.provider,e.id)===n)}function isKnownModelSelectionProvider(e){const t=normalizeProviderId(e.provider);if(findNormalizedProviderKey(e.cfg.models?.providers,t)||e.catalog.some(e=>normalizeProviderId(e.provider)===t))return true;const n=loadManifestMetadataSnapshot({config:e.cfg});return n.plugins.some(r=>r.providers.some(e=>normalizeProviderId(e)===t)&&isManifestPluginAvailableForControlPlane({snapshot:n,plugin:r,config:e.cfg}))}async function prepareModelSelectionRuntime(e){const t=resolveModelRuntimeDirective(e);if(t.kind===`invalid`)return{status:`rejected`,reason:`invalid-runtime`,message:t.errorText};let n=t;const r=e.profileOverride?{...e.sessionEntry,providerOverride:e.provider,modelProvider:e.provider,authProfileOverride:e.profileOverride,authProfileOverrideSource:`user`}:e.sessionEntry;const i=n.kind===`clear`?{...r,agentRuntimeOverride:void 0}:r;const a=findSelectedCatalogEntry(e);if(!isKnownModelSelectionProvider(e))return{status:`rejected`,reason:`unknown-provider`,message:`Unknown provider "${e.provider}". Use /models to list providers.`};let o;let s;let c;let l=n.kind===`set`;const u={agentId:e.agentId,provider:e.provider,modelId:e.model,modelApi:a?.api,modelBaseUrl:a?.baseUrl};if(!e.rawRuntime){const t=resolveAgentHarnessPolicy({...u,config:e.cfg});const n=resolveEffectiveAgentRuntime({...u,cfg:e.cfg,sessionEntry:i});if(!i?.agentRuntimeOverride)c=resolveCliRuntimeExecutionProvider({cfg:e.cfg,agentId:e.agentId,provider:e.provider,modelId:e.model,authProfileId:i?.authProfileOverride});l=Boolean(a?.nativeRuntime||n!==`openclaw`||c||t.forcedByEnvironment&&t.runtime!==`openclaw`)}if(n.kind===`set`&&n.runtime===`openclaw`&&!i?.authProfileOverride){const t=e.cfg.cloudWorkers?.requiredProfile;const n=t?e.cfg.cloudWorkers?.profiles?.[t]:void 0;if(n&&workerInferenceMetadata({providerId:n.provider,profileSnapshot:n}).inference)l=false}if(l){const{preparePublishedModelRuntimeChoice:t}=await import(`./model-runtime-choice-CI3W-p4X.mjs`);const r=await t({...e,sessionEntry:i,runtimeId:n.kind===`set`?n.runtime:void 0,preferredRuntimeId:(n.kind===`unchanged`?normalizeOptionalAgentRuntimeId(i?.agentRuntimeOverride):void 0)??c});if(r.kind===`unavailable`)return{status:`rejected`,reason:`invalid-runtime`,message:r.message};o=r.validate;s=r.harness;n={kind:`set`,runtime:r.runtimeId}}const d=n.kind===`set`?n.runtime:resolveEffectiveAgentRuntime({cfg:e.cfg,...u,sessionEntry:i});let f;const p=e.thinkingPolicyRequired!==false||d!==`openclaw`||!a||a.nativeRuntime!==void 0&&a.nativeRuntime!==`openclaw`;if(e.hydrateThinkingCatalog!==false&&e.cfg.plugins?.enabled!==false&&p){const{loadProviderScopedThinkingCatalog:t}=await import(`./agents/model-catalog.runtime.js`);const n=await t({config:e.cfg,agentId:e.agentId,provider:e.provider,model:e.model,agentRuntime:d,workspaceDir:e.workspaceDir});f=findSelectedCatalogEntry({...e,catalog:n})}return{status:`ready`,runtime:n,validateRuntimeSelection:o,harness:s,catalog:f?[f,...e.catalog.filter(e=>e!==a)]:[...e.catalog]}}function modelCatalogEntryKey(e){return JSON.stringify([e.provider.trim(),e.id.trim()])}function mergePreparedConfiguredCatalog(e){if(!e.prepared?.length)return e.configured;const t=new Map(e.configured.map(e=>[modelCatalogEntryKey(e),e]));for(const n of e.prepared){const e=modelCatalogEntryKey(n);t.set(e,{...t.get(e),...n})}return[...t.values()]}export{prepareModelSelectionRuntime as a,normalizeRuntimeChoiceId as i,isKnownModelSelectionProvider as n,resolveRuntimeNormalization as o,mergePreparedConfiguredCatalog as r,findSelectedCatalogEntry as t};