mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 12:08:37 +00:00
fix(config): avoid Anthropic startup crash
This commit is contained in:
@@ -121,6 +121,12 @@ describe("model-selection", () => {
|
|||||||
defaultProvider: "anthropic",
|
defaultProvider: "anthropic",
|
||||||
expected: { provider: "anthropic", model: "claude-sonnet-4-6" },
|
expected: { provider: "anthropic", model: "claude-sonnet-4-6" },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "keeps dated anthropic model ids unchanged",
|
||||||
|
variants: ["anthropic/claude-sonnet-4-20250514", "claude-sonnet-4-20250514"],
|
||||||
|
defaultProvider: "anthropic",
|
||||||
|
expected: { provider: "anthropic", model: "claude-sonnet-4-20250514" },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "normalizes deprecated google flash preview ids",
|
name: "normalizes deprecated google flash preview ids",
|
||||||
variants: ["google/gemini-3.1-flash-preview", "gemini-3.1-flash-preview"],
|
variants: ["google/gemini-3.1-flash-preview", "gemini-3.1-flash-preview"],
|
||||||
|
|||||||
@@ -31,13 +31,6 @@ export type ModelAliasIndex = {
|
|||||||
byKey: Map<string, string[]>;
|
byKey: Map<string, string[]>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ANTHROPIC_MODEL_ALIASES: Record<string, string> = {
|
|
||||||
"opus-4.6": "claude-opus-4-6",
|
|
||||||
"opus-4.5": "claude-opus-4-5",
|
|
||||||
"sonnet-4.6": "claude-sonnet-4-6",
|
|
||||||
"sonnet-4.5": "claude-sonnet-4-5",
|
|
||||||
};
|
|
||||||
|
|
||||||
function normalizeAliasKey(value: string): string {
|
function normalizeAliasKey(value: string): string {
|
||||||
return value.trim().toLowerCase();
|
return value.trim().toLowerCase();
|
||||||
}
|
}
|
||||||
@@ -151,7 +144,20 @@ function normalizeAnthropicModelId(model: string): string {
|
|||||||
return trimmed;
|
return trimmed;
|
||||||
}
|
}
|
||||||
const lower = trimmed.toLowerCase();
|
const lower = trimmed.toLowerCase();
|
||||||
return ANTHROPIC_MODEL_ALIASES[lower] ?? trimmed;
|
// Keep alias resolution local so bundled startup paths cannot trip a TDZ on
|
||||||
|
// a module-level alias table while config parsing is still initializing.
|
||||||
|
switch (lower) {
|
||||||
|
case "opus-4.6":
|
||||||
|
return "claude-opus-4-6";
|
||||||
|
case "opus-4.5":
|
||||||
|
return "claude-opus-4-5";
|
||||||
|
case "sonnet-4.6":
|
||||||
|
return "claude-sonnet-4-6";
|
||||||
|
case "sonnet-4.5":
|
||||||
|
return "claude-sonnet-4-5";
|
||||||
|
default:
|
||||||
|
return trimmed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeProviderModelId(provider: string, model: string): string {
|
function normalizeProviderModelId(provider: string, model: string): string {
|
||||||
|
|||||||
@@ -73,6 +73,30 @@ describe("config pruning defaults", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("adds cacheRetention defaults for dated Anthropic primary model refs", async () => {
|
||||||
|
await withTempHome(async (home) => {
|
||||||
|
await writeConfigForTest(home, {
|
||||||
|
auth: {
|
||||||
|
profiles: {
|
||||||
|
"anthropic:api": { provider: "anthropic", mode: "api_key" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
agents: {
|
||||||
|
defaults: {
|
||||||
|
model: { primary: "anthropic/claude-sonnet-4-20250514" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const cfg = loadConfig();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
cfg.agents?.defaults?.models?.["anthropic/claude-sonnet-4-20250514"]?.params
|
||||||
|
?.cacheRetention,
|
||||||
|
).toBe("short");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("adds default cacheRetention for Anthropic Claude models on Bedrock", async () => {
|
it("adds default cacheRetention for Anthropic Claude models on Bedrock", async () => {
|
||||||
await withTempHome(async (home) => {
|
await withTempHome(async (home) => {
|
||||||
await writeConfigForTest(home, {
|
await writeConfigForTest(home, {
|
||||||
|
|||||||
Reference in New Issue
Block a user