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