UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

118 lines (117 loc) • 3.68 kB
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs"; import "./string-coerce-runtime-BwAZZDf5.mjs"; import { d as CLAUDE_MODEL_ID_ALIASES, t as CLAUDE_CLI_BACKEND_ID } from "./cli-constants-CDevEMvo.mjs"; //#region extensions/anthropic/claude-model-refs.ts function splitTrailingModelAuthProfile(e) { const t = e.trim(); const n = t.lastIndexOf("/"); let r = t.indexOf("@", n + 1); if (r <= 0) return { model: t }; if (/^\d{8}(?:@|$)/.test(t.slice(r + 1))) { const e = t.indexOf("@", r + 9); if (e < 0) return { model: t }; r = e; } const i = t.slice(0, r).trim(); const a = t.slice(r + 1).trim(); return i && a ? { model: i, profile: a } : { model: t }; } function attachModelAuthProfile(e, t) { return t ? `${e}@${t}` : e; } function normalizeAnthropicProviderId(e) { const t = normalizeLowercaseStringOrEmpty(e); if (t === "bedrock" || t === "aws-bedrock") return "amazon-bedrock"; return t; } function parseAnthropicModelRef(e) { const t = e.trim(); if (!t) return null; const n = t.indexOf("/"); if (n <= 0) return { provider: "anthropic", model: t, explicitProvider: false }; const r = t.slice(0, n).trim(); const i = t.slice(n + 1).trim(); if (!r || !i) return null; return { provider: normalizeAnthropicProviderId(r), model: i, explicitProvider: true }; } function canonicalizeKnownClaudeCliModelId(e) { const { model: t, profile: n } = splitTrailingModelAuthProfile(e); const r = normalizeLowercaseStringOrEmpty(t); if (!r) return null; const i = upgradeOldClaudeModelId(r); if (i) return attachModelAuthProfile(i, n); if (r.startsWith("claude-")) return attachModelAuthProfile(t, n); const a = CLAUDE_MODEL_ID_ALIASES.get(r); return a ? attachModelAuthProfile(a, n) : null; } function upgradeOldClaudeModelId(e) { const t = /^claude-(opus|sonnet)-4(?:$|[-.][015](?=$|[-.:@])|-20\d{6})/.exec(e); if (t) return t[1] === "opus" ? "claude-opus-5-5" : "claude-sonnet-4-6"; if (e.startsWith("claude-3") && e.includes("opus")) return "claude-opus-5-5"; if (e.startsWith("claude-3") && (e.includes("sonnet") || e.includes("haiku"))) return "claude-sonnet-4-6"; if ([ "opus-4.5", "opus-4.1", "opus-4", "opus-3" ].includes(e)) return "claude-opus-5-5"; if ([ "sonnet-4.5", "sonnet-4.1", "sonnet-4.0", "sonnet-4", "sonnet-3.7", "sonnet-3.5", "sonnet-3", "haiku-3.5", "haiku-3" ].includes(e)) return "claude-sonnet-4-6"; return null; } function resolveClaudeCliAnthropicModelRefs(e) { const t = parseAnthropicModelRef(e); if (!t) return null; if (t.provider !== "anthropic" && t.provider !== "claude-cli") return null; const n = `anthropic/${t.model}`; const r = /* @__PURE__ */ new Set([n]); const i = canonicalizeKnownClaudeCliModelId(t.model); if (!t.explicitProvider && !i) return null; const a = i || t.provider === "claude-cli" ? `anthropic/${i ?? t.model}` : void 0; if (a) r.add(a); return { selectedRef: n, runtimeRefs: [...r], ...a ? { rewriteRef: a } : {} }; } function resolveKnownAnthropicModelRef(e) { if (!e) return null; const t = e.trim(); if (!t) return null; return resolveClaudeCliAnthropicModelRefs(t)?.rewriteRef ?? t; } function modelEntryWithClaudeCliRuntime(e) { const t = e ?? {}; const n = normalizeLowercaseStringOrEmpty(t.agentRuntime?.id); if (n && n !== "auto") return t; return { ...t, agentRuntime: { ...t.agentRuntime, id: CLAUDE_CLI_BACKEND_ID } }; } //#endregion export { resolveKnownAnthropicModelRef as a, resolveClaudeCliAnthropicModelRefs as i, normalizeAnthropicProviderId as n, splitTrailingModelAuthProfile as o, parseAnthropicModelRef as r, modelEntryWithClaudeCliRuntime as t };