UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 6.52 kB
import{o as writeRuntimeJson,s as writeRuntimeStdout}from"./runtime-DIcLIHcp.mjs";import{n as sanitizeTerminalText}from"./safe-text-B_QTgn0s.mjs";import"./model-ref-shared-T-aCqInj.mjs";import{r as normalizeProviderId}from"./provider-id-A-8WTtLA.mjs";import{r as modelKey}from"./provider-registry-index-fv5AHL27.mjs";import{t as captureRuntimeConfigAsyncReader}from"./io.runtime-BvSeVFIY.mjs";import"./config-DkZ8y8Gv.mjs";import{r as theme,t as colorize}from"./theme-DS2CtI9X.mjs";import{t as ExpectedCliError}from"./expected-cli-error-oDVmXYil.mjs";import{n as requestExitAfterOneShotOutput}from"./one-shot-exit-LLy48Ehj.mjs";import{a as stopProxy,i as startProxy}from"./proxy-lifecycle-BOwipP0f.mjs";import{t as runWithLocalStateOwner}from"./local-state-owner-fjzTarAw.mjs";import{_ as truncate,g as padTerminalCell,h as isRich,l as resolveModelsTargetAgent,n as ensureFlagCompatibility,p as formatTokenK}from"./shared-Sc7lnGKV.mjs";import{i as runModelCatalogReadCommand,r as readSelectedGatewayModelCatalog,t as getModelCatalogWarnings}from"./catalog-warnings-4WHV2K_B.mjs";import{t as loadModelsConfig}from"./load-config-BZk4Hyvt.mjs"; //!src/commands/models/list.list-command.ts const MODEL_CATALOG_REFRESH_TIMEOUT_MS=21e4;const MODEL_PAD=42;const INPUT_PAD=10;const CTX_PAD=11;const STATE_PAD=5;async function runModelsListCommand(e,t,n){ensureFlagCompatibility(e);n?.throwIfAborted();const r=e.provider?.trim();if(r&&/\s/u.test(r)){const e=`Invalid provider filter "${sanitizeTerminalText(r)}". Use a provider id such as "moonshot", not a display label.`;throw new ExpectedCliError({message:e,humanOutput:e,machineOutput:e})}const i=r?normalizeProviderId(r):void 0;const a=await captureRuntimeConfigAsyncReader({skipPluginValidation:true})();const o={...e.agent?.trim()?{agentId:e.agent.trim()}:{},view:e.all||i?`all`:`default`,...i?{provider:i}:{},includeDetails:true,...e.refresh?{refresh:true}:{}};let s=await readSelectedGatewayModelCatalog(a,o,e.refresh?MODEL_CATALOG_REFRESH_TIMEOUT_MS:void 0,n);if(!s){t.error(e.refresh?`Gateway is not running. Refreshing the local model catalog.`:`Gateway is not running. Showing the local cached model catalog. Use --refresh to discover provider models.`);const[{resolvePublishedModelCatalogOwner:r},{withPreparedModelCatalogOwner:i},{getPreparedModelRuntimeAuthMaterializations:a},{buildModelsListResult:c},{UnknownModelCatalogProviderError:l}]=await Promise.all([import(`./prepared-model-catalog-owner-BmkNuw7F.mjs`),import(`./prepared-model-catalog-BMl2SNE7.mjs`),import(`./prepared-model-runtime-auth-R4HShvkd.mjs`),import(`./models-list-result-ByJHk-b6.mjs`),import(`./models-list-capabilities-gVGPwZZ-.mjs`)]);const readLocal=async s=>{n?.throwIfAborted();const l=await loadModelsConfig({commandName:`models list`,runtime:t});const{agentId:u,agentDir:d}=resolveModelsTargetAgent(l,e.agent,{kind:`read`});if(s){const[{prepareOpenClawAgentDatabaseExecution:e},{resolveAuthProfileDatabasePath:t},{prepareLocalCapabilityAccountSecrets:n}]=await Promise.all([import(`./openclaw-agent-execution-BaQEgQEk.mjs`),import(`./sqlite-BKF2ec71.mjs`),import(`./local-account-secrets-DK63WCOh.mjs`)]);await e({agentId:u,path:t(d),env:s.env},s.assertCurrent,s.signal);await n({cfg:l,agentId:u});s.assertCurrent()}const f=e.refresh?await startProxy(l.proxy):null;try{return await i({agentId:u,agentDir:d,config:l,readOnly:e.refresh!==true,...e.refresh?{refreshFullCatalog:true,persistOfflineRefresh:true}:{}},async e=>{const t=r(e);return await c({source:{kind:`published`,owner:{...t,authMaterializations:a(e)}},agentId:u,params:o})})}finally{await stopProxy(f)}};try{s=e.refresh?await runWithLocalStateOwner({method:`models.list`,params:o,target:`local model catalog`,onForeignOwner:`refuse`,runLocal:async e=>{const t=await readLocal(e);e.assertCurrent();return t}}):await readLocal()}catch(e){if(e instanceof l){const t=e.message;throw new ExpectedCliError({message:t,humanOutput:t,machineOutput:t,cause:e})}throw e}}n?.throwIfAborted();for(const e of getModelCatalogWarnings(s))t.error(`${e.message} ${e.fixHint}`);if(s.refreshFailed)t.error(`Model discovery could not refresh all providers. Showing the available published model list.`);const c=s.models.filter(t=>!e.local||t.local===true).map(e=>({key:modelKey(e.provider,e.id),name:e.name,input:e.input?.join(`+`)||`-`,contextWindow:e.contextWindow??null,contextTokens:e.contextTokens,local:e.local??null,available:e.available??null,tags:[.../* @__PURE__ */ new Set([...e.tags??[],...e.alias?[`alias:${e.alias}`]:[]])]}));if(c.length===0&&!e.json&&!e.plain)t.log(`No models found.`);else if(e.json){const e=s.providerOutcomes?.map(({provider:e,profileId:t,status:n,unlistedConfiguredModelIds:r})=>({provider:e,profileId:t||void 0,status:n,unlistedConfiguredModelIds:n===`ready`&&r?.length?r:void 0}));writeRuntimeJson(t,{count:c.length,models:c,...e?.length?{providerOutcomes:e}:{}})}else if(e.plain)for(const e of c)writeRuntimeStdout(t,sanitizeTerminalText(e.key));else{const n=isRich(e);const r=n?e=>{const t=sanitizeTerminalText(e);switch(t){case`default`:return theme.success(t);case`image`:return theme.accentBright(t);case`configured`:return theme.accent(t);case`missing`:return theme.error(t)}if(t.startsWith(`fallback#`)||t.startsWith(`img-fallback#`))return theme.warn(t);if(t.startsWith(`alias:`))return theme.accentDim(t);return theme.muted(t)}:sanitizeTerminalText;const formatState=(e,t=theme.muted)=>colorize(n,e===null?theme.muted:e?theme.success:t,padTerminalCell(e===null?`-`:e?`yes`:`no`,STATE_PAD));const i=[padTerminalCell(`Model`,MODEL_PAD),padTerminalCell(`Input`,INPUT_PAD),padTerminalCell(`Ctx`,CTX_PAD),padTerminalCell(`Local`,STATE_PAD),padTerminalCell(`Auth`,STATE_PAD),`Tags`].join(` `);t.log(n?theme.heading(i):i);for(const e of c){const i=padTerminalCell(truncate(e.key,MODEL_PAD),MODEL_PAD);const a=colorize(n,e.input.includes(`image`)?theme.accentBright:theme.info,padTerminalCell(sanitizeTerminalText(e.input)||`-`,INPUT_PAD));const o=typeof e.contextTokens===`number`&&Number.isFinite(e.contextTokens)&&e.contextTokens>0&&e.contextTokens!==e.contextWindow?`${formatTokenK(e.contextTokens)}/${formatTokenK(e.contextWindow)}`:formatTokenK(e.contextWindow);const s=[n?theme.accent(i):i,a,padTerminalCell(o,CTX_PAD),formatState(e.local),formatState(e.available,theme.error),e.tags.map(r).join(`,`)].join(` `);t.log(s)}}requestExitAfterOneShotOutput(t)}async function modelsListCommand(e,t){await runModelCatalogReadCommand(n=>runModelsListCommand(e,t,n),!e.refresh)}export{modelsListCommand};