fix: normalize anthropic model ids
This commit is contained in:
@@ -277,6 +277,11 @@ async function runClaudeCliOnce(params: {
|
||||
const result = await runCommandWithTimeout(["claude", ...args], {
|
||||
timeoutMs: params.timeoutMs,
|
||||
cwd: params.workspaceDir,
|
||||
env: (() => {
|
||||
const next = { ...process.env };
|
||||
delete next.ANTHROPIC_API_KEY;
|
||||
return next;
|
||||
})(),
|
||||
});
|
||||
if (process.env.CLAWDBOT_CLAUDE_CLI_LOG_OUTPUT === "1") {
|
||||
const stdoutDump = result.stdout.trim();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import { buildAllowedModelSet, modelKey } from "./model-selection.js";
|
||||
import { buildAllowedModelSet, modelKey, parseModelRef } from "./model-selection.js";
|
||||
|
||||
const catalog = [
|
||||
{
|
||||
@@ -54,3 +54,13 @@ describe("buildAllowedModelSet", () => {
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseModelRef", () => {
|
||||
it("normalizes anthropic/opus-4.5 to claude-opus-4-5", () => {
|
||||
const ref = parseModelRef("anthropic/opus-4.5", "anthropic");
|
||||
expect(ref).toEqual({
|
||||
provider: "anthropic",
|
||||
model: "claude-opus-4-5",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -27,6 +27,15 @@ export function normalizeProviderId(provider: string): string {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function normalizeAnthropicModelId(model: string): string {
|
||||
const trimmed = model.trim();
|
||||
if (!trimmed) return trimmed;
|
||||
const lower = trimmed.toLowerCase();
|
||||
if (lower === "opus-4.5") return "claude-opus-4-5";
|
||||
if (lower === "sonnet-4.5") return "claude-sonnet-4-5";
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
export function parseModelRef(
|
||||
raw: string,
|
||||
defaultProvider: string,
|
||||
@@ -35,13 +44,18 @@ export function parseModelRef(
|
||||
if (!trimmed) return null;
|
||||
const slash = trimmed.indexOf("/");
|
||||
if (slash === -1) {
|
||||
return { provider: normalizeProviderId(defaultProvider), model: trimmed };
|
||||
const provider = normalizeProviderId(defaultProvider);
|
||||
const model =
|
||||
provider === "anthropic" ? normalizeAnthropicModelId(trimmed) : trimmed;
|
||||
return { provider, model };
|
||||
}
|
||||
const providerRaw = trimmed.slice(0, slash).trim();
|
||||
const provider = normalizeProviderId(providerRaw);
|
||||
const model = trimmed.slice(slash + 1).trim();
|
||||
if (!provider || !model) return null;
|
||||
return { provider, model };
|
||||
const normalizedModel =
|
||||
provider === "anthropic" ? normalizeAnthropicModelId(model) : model;
|
||||
return { provider, model: normalizedModel };
|
||||
}
|
||||
|
||||
export function buildModelAliasIndex(params: {
|
||||
|
||||
Reference in New Issue
Block a user