openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.07 kB
JavaScript
import{o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{i as buildModelAliasIndex,y as resolveModelRefFromString}from"./model-selection-shared-CIOFxJ36.mjs";import"./string-coerce-runtime-BYDH9Quw.mjs";import"./agent-runtime-SZFAv6hc.mjs";import{n as CLAUDE_CLI_CANONICAL_DEFAULT_MODEL_REF,t as CLAUDE_CLI_BACKEND_ID}from"./cli-constants-Cc2K557b.mjs";import{i as resolveClaudeCliAnthropicModelRefs,o as splitTrailingModelAuthProfile,t as modelEntryWithClaudeCliRuntime}from"./claude-model-refs-CGLVRRxI.mjs";
//!extensions/anthropic/cli-migration.ts
function rewriteModelSelection(e){const t=e.agents?.defaults?.model;const n={cfg:e,defaultProvider:`anthropic`,allowManifestNormalization:false,allowPluginNormalization:false};const r=buildModelAliasIndex(n);const i=[];function rewrite(e){const t=resolveModelRefFromString({...n,aliasIndex:r,raw:e});if(t?.alias){const n=t.ref.provider+`/`+t.ref.model;const r=resolveClaudeCliAnthropicModelRefs(n);i.push(...r?.runtimeRefs??[]);const a=r?.rewriteRef??r?.selectedRef;if(!a)return{value:e,primary:e};const{profile:o}=splitTrailingModelAuthProfile(e);const s=o?a+`@`+o:a;return{value:s,primary:s,changed:s!==e}}const a=resolveClaudeCliAnthropicModelRefs(e);i.push(...a?.runtimeRefs??[]);const o=a?.rewriteRef;return{value:o??e,primary:o??a?.selectedRef,changed:Boolean(o)}}if(typeof t===`string`){const e=rewrite(t);return{...e,runtimeRefs:i,changed:Boolean(e.changed)}}if(!t)return{value:t,runtimeRefs:i,changed:false};const a=t.primary!==void 0?rewrite(t.primary):void 0;const o=t.fallbacks?.map(e=>rewrite(e).value);const s=Boolean(a?.changed)||Boolean(o?.some((e,n)=>e!==t.fallbacks?.[n]));return{value:s?{...t,...a?{primary:a.value}:{},...o?{fallbacks:o}:{}}:t,primary:a?.primary,runtimeRefs:i,changed:s}}function buildAnthropicCliMigrationResult(e){const t=e.agents?.defaults;const n=rewriteModelSelection(e);let r=t?.models;const i=[];const a=[];if(r){const e={...r};for(const[t,n]of Object.entries(r)){const r=resolveClaudeCliAnthropicModelRefs(t);a.push(...r?.runtimeRefs??[]);const o=r?.rewriteRef;if(!o||o===t)continue;if(!Object.hasOwn(e,o))Object.defineProperty(e,o,{value:n,writable:true,enumerable:true,configurable:true});if(normalizeLowercaseStringOrEmpty(t).startsWith(`${`claude-cli`}/`))delete e[t];i.push(o)}if(i.length>0||a.length>0)r=e}const o=n.primary??CLAUDE_CLI_CANONICAL_DEFAULT_MODEL_REF;const s={...r};const c=/* @__PURE__ */ new Set([...n.runtimeRefs,o,...a,...i,`anthropic/*`]);for(const e of c){const t=Object.hasOwn(s,e)?s[e]:void 0;Object.defineProperty(s,e,{value:modelEntryWithClaudeCliRuntime(t),writable:true,enumerable:true,configurable:true})}return{profiles:[],configPatch:{agents:{defaults:{...n.changed?{model:n.value}:{},models:s}}},replaceDefaultModels:true,defaultModel:o,notes:[`Claude CLI auth detected; kept Anthropic model refs and selected the local Claude CLI runtime.`,`Existing Anthropic auth profiles are kept for rollback.`,...i.length>0?[`Migrated allowlist entries: ${i.join(`, `)}.`]:[]]}}export{buildAnthropicCliMigrationResult as t};