Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
234 lines
7.0 KiB
TypeScript
234 lines
7.0 KiB
TypeScript
/**
|
|
* Claude CLI model-ref normalization. It maps family aliases and retired model
|
|
* ids to current Anthropic runtime refs while preserving auth-profile suffixes.
|
|
*/
|
|
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
import { CLAUDE_CLI_BACKEND_ID, CLAUDE_CLI_MODEL_ALIASES } from "./cli-constants.js";
|
|
|
|
const DEFAULT_CLAUDE_MODEL_BY_FAMILY: Record<string, string> = {
|
|
opus: "claude-opus-4-8",
|
|
sonnet: "claude-sonnet-4-6",
|
|
haiku: "claude-haiku-4-5",
|
|
};
|
|
|
|
/** Normalized Claude CLI selection plus runtime refs used by setup migrations. */
|
|
export type ClaudeCliAnthropicModelRefs = {
|
|
selectedRef: string;
|
|
runtimeRefs: string[];
|
|
rewriteRef?: string;
|
|
};
|
|
|
|
function splitTrailingModelAuthProfile(raw: string): { model: string; profile?: string } {
|
|
const trimmed = raw.trim();
|
|
if (!trimmed) {
|
|
return { model: "" };
|
|
}
|
|
const lastSlash = trimmed.lastIndexOf("/");
|
|
let delimiter = trimmed.indexOf("@", lastSlash + 1);
|
|
if (delimiter <= 0) {
|
|
return { model: trimmed };
|
|
}
|
|
if (/^\d{8}(?:@|$)/.test(trimmed.slice(delimiter + 1))) {
|
|
const nextDelimiter = trimmed.indexOf("@", delimiter + 9);
|
|
if (nextDelimiter < 0) {
|
|
return { model: trimmed };
|
|
}
|
|
delimiter = nextDelimiter;
|
|
}
|
|
const model = trimmed.slice(0, delimiter).trim();
|
|
const profile = trimmed.slice(delimiter + 1).trim();
|
|
return model && profile ? { model, profile } : { model: trimmed };
|
|
}
|
|
|
|
function attachModelAuthProfile(model: string, profile?: string): string {
|
|
return profile ? `${model}@${profile}` : model;
|
|
}
|
|
|
|
function hasRetiredVersionPrefix(normalized: string, prefix: string): boolean {
|
|
if (normalized === prefix) {
|
|
return true;
|
|
}
|
|
if (!normalized.startsWith(prefix)) {
|
|
return false;
|
|
}
|
|
const next = normalized[prefix.length];
|
|
return next === "-" || next === "." || next === ":" || next === "@";
|
|
}
|
|
|
|
function hasAnyRetiredVersionPrefix(normalized: string, prefixes: readonly string[]): boolean {
|
|
return prefixes.some((prefix) => hasRetiredVersionPrefix(normalized, prefix));
|
|
}
|
|
|
|
function parseProviderModelRef(
|
|
raw: string,
|
|
defaultProvider: string,
|
|
): { provider: string; model: string; explicitProvider: boolean } | null {
|
|
const trimmed = raw.trim();
|
|
if (!trimmed) {
|
|
return null;
|
|
}
|
|
const slashIndex = trimmed.indexOf("/");
|
|
if (slashIndex <= 0) {
|
|
return { provider: defaultProvider, model: trimmed, explicitProvider: false };
|
|
}
|
|
const provider = trimmed.slice(0, slashIndex).trim();
|
|
const model = trimmed.slice(slashIndex + 1).trim();
|
|
if (!provider || !model) {
|
|
return null;
|
|
}
|
|
return {
|
|
provider: normalizeLowercaseStringOrEmpty(provider),
|
|
model,
|
|
explicitProvider: true,
|
|
};
|
|
}
|
|
|
|
function canonicalizeKnownClaudeCliModelId(modelId: string): string | null {
|
|
const split = splitTrailingModelAuthProfile(modelId);
|
|
const trimmed = split.model.trim();
|
|
const normalized = normalizeLowercaseStringOrEmpty(trimmed);
|
|
if (!normalized) {
|
|
return null;
|
|
}
|
|
const upgraded = upgradeOldClaudeModelId(normalized);
|
|
if (upgraded) {
|
|
return attachModelAuthProfile(upgraded, split.profile);
|
|
}
|
|
if (normalized.startsWith("claude-")) {
|
|
return attachModelAuthProfile(trimmed, split.profile);
|
|
}
|
|
const defaultModel = DEFAULT_CLAUDE_MODEL_BY_FAMILY[normalized];
|
|
if (defaultModel) {
|
|
return attachModelAuthProfile(defaultModel, split.profile);
|
|
}
|
|
const aliasedModel = CLAUDE_CLI_MODEL_ALIASES[normalized];
|
|
return aliasedModel?.startsWith("claude-")
|
|
? attachModelAuthProfile(aliasedModel, split.profile)
|
|
: null;
|
|
}
|
|
|
|
function upgradeOldClaudeModelId(normalized: string): string | null {
|
|
if (normalized.startsWith("claude-opus-4-8") || normalized.startsWith("claude-opus-4.8")) {
|
|
return null;
|
|
}
|
|
if (normalized.startsWith("claude-opus-4-7") || normalized.startsWith("claude-opus-4.7")) {
|
|
return null;
|
|
}
|
|
if (normalized.startsWith("claude-opus-4-6") || normalized.startsWith("claude-opus-4.6")) {
|
|
return null;
|
|
}
|
|
if (normalized.startsWith("claude-sonnet-4-6") || normalized.startsWith("claude-sonnet-4.6")) {
|
|
return null;
|
|
}
|
|
// claude-haiku-4-5 is a current production model and must not be migrated.
|
|
if (normalized.startsWith("claude-haiku-4-5") || normalized.startsWith("claude-haiku-4.5")) {
|
|
return null;
|
|
}
|
|
if (
|
|
normalized === "claude-opus-4" ||
|
|
hasAnyRetiredVersionPrefix(normalized, [
|
|
"claude-opus-4-7",
|
|
"claude-opus-4.7",
|
|
"claude-opus-4-5",
|
|
"claude-opus-4.5",
|
|
"claude-opus-4-1",
|
|
"claude-opus-4.1",
|
|
"claude-opus-4-0",
|
|
"claude-opus-4.0",
|
|
]) ||
|
|
/^claude-opus-4-20\d{6}/.test(normalized)
|
|
) {
|
|
return "claude-opus-4-8";
|
|
}
|
|
if (
|
|
normalized === "claude-sonnet-4" ||
|
|
hasAnyRetiredVersionPrefix(normalized, [
|
|
"claude-sonnet-4-5",
|
|
"claude-sonnet-4.5",
|
|
"claude-sonnet-4-1",
|
|
"claude-sonnet-4.1",
|
|
"claude-sonnet-4-0",
|
|
"claude-sonnet-4.0",
|
|
]) ||
|
|
/^claude-sonnet-4-20\d{6}/.test(normalized)
|
|
) {
|
|
return "claude-sonnet-4-6";
|
|
}
|
|
if (normalized.startsWith("claude-3") && normalized.includes("opus")) {
|
|
return "claude-opus-4-8";
|
|
}
|
|
if (
|
|
normalized.startsWith("claude-3") &&
|
|
(normalized.includes("sonnet") || normalized.includes("haiku"))
|
|
) {
|
|
return "claude-sonnet-4-6";
|
|
}
|
|
if (
|
|
normalized === "opus-4.5" ||
|
|
normalized === "opus-4.1" ||
|
|
normalized === "opus-4" ||
|
|
normalized === "opus-3"
|
|
) {
|
|
return "claude-opus-4-8";
|
|
}
|
|
if (
|
|
normalized === "sonnet-4.5" ||
|
|
normalized === "sonnet-4.1" ||
|
|
normalized === "sonnet-4.0" ||
|
|
normalized === "sonnet-4" ||
|
|
normalized === "sonnet-3.7" ||
|
|
normalized === "sonnet-3.5" ||
|
|
normalized === "sonnet-3" ||
|
|
normalized === "haiku-3.5" ||
|
|
normalized === "haiku-3"
|
|
) {
|
|
return "claude-sonnet-4-6";
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/** Resolve a Claude CLI model ref into selected and Anthropic-compatible runtime refs. */
|
|
export function resolveClaudeCliAnthropicModelRefs(
|
|
raw: string,
|
|
): ClaudeCliAnthropicModelRefs | null {
|
|
const parsed = parseProviderModelRef(raw, "anthropic");
|
|
if (!parsed) {
|
|
return null;
|
|
}
|
|
if (parsed.provider !== "anthropic" && parsed.provider !== CLAUDE_CLI_BACKEND_ID) {
|
|
return null;
|
|
}
|
|
|
|
const selectedRef = `anthropic/${parsed.model}`;
|
|
const runtimeRefs = new Set<string>([selectedRef]);
|
|
const canonicalModelId = canonicalizeKnownClaudeCliModelId(parsed.model);
|
|
if (!parsed.explicitProvider && !canonicalModelId) {
|
|
return null;
|
|
}
|
|
const rewriteRef =
|
|
canonicalModelId || parsed.provider === CLAUDE_CLI_BACKEND_ID
|
|
? `anthropic/${canonicalModelId ?? parsed.model}`
|
|
: undefined;
|
|
if (rewriteRef) {
|
|
runtimeRefs.add(rewriteRef);
|
|
}
|
|
|
|
return {
|
|
selectedRef,
|
|
runtimeRefs: [...runtimeRefs],
|
|
...(rewriteRef ? { rewriteRef } : {}),
|
|
};
|
|
}
|
|
|
|
/** Resolve a known Anthropic/Claude CLI model ref to its current Anthropic model ref. */
|
|
export function resolveKnownAnthropicModelRef(raw?: string): string | null {
|
|
if (!raw) {
|
|
return null;
|
|
}
|
|
const trimmed = raw.trim();
|
|
if (!trimmed) {
|
|
return null;
|
|
}
|
|
return resolveClaudeCliAnthropicModelRefs(trimmed)?.rewriteRef ?? trimmed;
|
|
}
|