openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.03 kB
JavaScript
import{o as normalizeLowercaseStringOrEmpty}from"../../string-coerce-CpTFcSwY.mjs";import{l as isRecord}from"../../record-coerce-BTbqdJ3-.mjs";import"../../string-coerce-runtime-BYDH9Quw.mjs";import{c as CLAUDE_CLI_PROFILE_ID,t as CLAUDE_CLI_BACKEND_ID}from"../../cli-constants-Cc2K557b.mjs";import{n as normalizeAnthropicProviderId,r as parseAnthropicModelRef}from"../../claude-model-refs-CGLVRRxI.mjs";
//!extensions/anthropic/doctor-contract-api.ts
const CLAUDE_CLI_WILDCARD_REF=`anthropic/*`;function hasAnthropicCredential(e){if(Object.values(e.auth?.profiles??{}).some(e=>normalizeAnthropicProviderId(e.provider)===`anthropic`))return true;return[`ANTHROPIC_API_KEY`,`ANTHROPIC_OAUTH_TOKEN`].some(t=>{const n=process.env[t]||e.env?.vars?.[t]||e.env?.[t];return typeof n===`string`&&n.trim()!==``})}function normalizeCompatibilityConfig({cfg:e}){const t=e.agents?.defaults?.models??{};if(Object.keys(t).some(e=>{const t=parseAnthropicModelRef(e);return t?.explicitProvider&&t.provider===`anthropic`&&t.model===`*`}))return{config:e,changes:[]};const n=e.agents?.defaults?.model;const r=typeof n===`string`?n:n?.primary;const i=r?parseAnthropicModelRef(r):null;const a=r?t[r]:void 0;const o=isRecord(a?.agentRuntime)?a.agentRuntime.id:void 0;const s=Object.entries(e.models?.providers??{}).filter(([e])=>normalizeAnthropicProviderId(e)===`anthropic`);if(!i?.explicitProvider||i.provider!==`anthropic`||normalizeLowercaseStringOrEmpty(o)!==`claude-cli`||s.some(([,e])=>e.agentRuntime!==void 0||e.apiKey!==void 0&&e.apiKey!==`anthropic:claude-cli`)||hasAnthropicCredential(e))return{config:e,changes:[]};return{config:{...e,agents:{...e.agents,defaults:{...e.agents?.defaults,models:{...t,[CLAUDE_CLI_WILDCARD_REF]:{agentRuntime:{id:CLAUDE_CLI_BACKEND_ID}}}}}},changes:[`agents.defaults.models["${CLAUDE_CLI_WILDCARD_REF}"]: added the ${CLAUDE_CLI_BACKEND_ID} runtime so Claude models not seeded at Claude CLI sign-in run through Claude Code instead of failing without an Anthropic API key.`]}}export{normalizeCompatibilityConfig};