Files
openclaw/extensions/anthropic/cli-constants.ts
Jason (Json) 866012f5be fix(anthropic): detect Claude CLI routes pinned to non-default models (#113424)
* fix(anthropic): detect Claude CLI routes pinned to non-default models

Route detection probed one hardcoded model id, so moving the packaged CLI
default stopped advertising session creation for configs routing an older
Claude model, and adoption stamped the packaged default onto sessions the
operator never routed. Probe the seeded CLI model ids instead and reuse the
routed model for both paths.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(anthropic): keep the canonical CLI model id module-local

The route probe replaced its only external consumer, so the export is dead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-24 17:04:12 -06:00

69 lines
2.8 KiB
TypeScript

/**
* Shared Claude CLI constants. These identify the synthetic backend, default
* model refs, aliases, and session-id fields used across runtime and setup.
*/
/** Synthetic provider/backend id for Claude Code CLI-backed Anthropic models. */
export const CLAUDE_CLI_BACKEND_ID = "claude-cli";
/** Non-secret marker for Claude Code settings.json apiKeyHelper auth. */
export const CLAUDE_CLI_API_KEY_HELPER_AUTH_MARKER = ["openclaw", "claude-cli-api-key-helper"].join(
":",
);
/** Default Claude CLI model ref for agent defaults and live tests. */
export const CLAUDE_CLI_DEFAULT_MODEL_REF = `${CLAUDE_CLI_BACKEND_ID}/claude-opus-5`;
/** Provider-relative model id for Anthropic runtime-policy resolution. */
const CLAUDE_CLI_CANONICAL_DEFAULT_MODEL_ID = CLAUDE_CLI_DEFAULT_MODEL_REF.slice(
CLAUDE_CLI_BACKEND_ID.length + 1,
);
/** Canonical model ref routed to the Claude CLI backend by Anthropic setup. */
export const CLAUDE_CLI_CANONICAL_DEFAULT_MODEL_REF = `anthropic/${CLAUDE_CLI_CANONICAL_DEFAULT_MODEL_ID}`;
/** Default Claude CLI models allowed when setup seeds the model allowlist. */
export const CLAUDE_CLI_DEFAULT_ALLOWLIST_REFS = [
CLAUDE_CLI_DEFAULT_MODEL_REF,
`${CLAUDE_CLI_BACKEND_ID}/claude-sonnet-5`,
`${CLAUDE_CLI_BACKEND_ID}/claude-fable-5`,
`${CLAUDE_CLI_BACKEND_ID}/claude-opus-4-8`,
`${CLAUDE_CLI_BACKEND_ID}/claude-opus-4-7`,
`${CLAUDE_CLI_BACKEND_ID}/claude-sonnet-4-6`,
`${CLAUDE_CLI_BACKEND_ID}/claude-opus-4-6`,
] as const;
/**
* Claude CLI model ids probed when detecting an existing CLI route, canonical
* default first. Route detection must not depend on which model is currently
* the default: existing configs route older Claude models, so probing only the
* default would stop advertising session creation after a default bump.
*/
export const CLAUDE_CLI_ROUTE_PROBE_MODEL_IDS = CLAUDE_CLI_DEFAULT_ALLOWLIST_REFS.map((ref) =>
ref.slice(CLAUDE_CLI_BACKEND_ID.length + 1),
);
/** User-facing Claude CLI model aliases normalized before execution. */
export const CLAUDE_CLI_MODEL_ALIASES: Record<string, string> = {
opus: "opus",
"opus-5": "claude-opus-5",
"opus-4.8": "claude-opus-4-8",
"opus-4.7": "claude-opus-4-7",
"opus-4.6": "claude-opus-4-6",
"claude-opus-5": "claude-opus-5",
"claude-opus-4-8": "claude-opus-4-8",
"claude-opus-4-7": "claude-opus-4-7",
"claude-opus-4-6": "claude-opus-4-6",
sonnet: "sonnet",
"sonnet-5": "claude-sonnet-5",
"claude-sonnet-5": "claude-sonnet-5",
"sonnet-4.6": "claude-sonnet-4-6",
"claude-sonnet-4-6": "claude-sonnet-4-6",
fable: "fable",
"fable-5": "claude-fable-5",
"claude-fable-5": "claude-fable-5",
haiku: "haiku",
};
/** JSONL fields that may contain Claude CLI session ids. */
export const CLAUDE_CLI_SESSION_ID_FIELDS = [
"session_id",
"sessionId",
"conversation_id",
"conversationId",
] as const;