fix(claude): improve backward compatibility for openrouter_compat_mode

Extend backward compatibility support for legacy openrouter_compat_mode field:
- Support number type (1 = enabled, 0 = disabled)
- Support string type ("true"/"1" = enabled)
- Add corresponding test cases for number and string types
This commit is contained in:
Jason
2026-01-29 10:52:13 +08:00
parent 81b975c47c
commit 0c25687e09
2 changed files with 31 additions and 3 deletions

View File

@@ -517,6 +517,24 @@ mod tests {
}));
assert!(adapter.needs_transform(&legacy_compat_enabled));
// Backward compatibility: openrouter_compat_mode=1 should enable transform
let legacy_compat_enabled_num = create_provider(json!({
"env": {
"ANTHROPIC_BASE_URL": "https://api.example.com"
},
"openrouter_compat_mode": 1
}));
assert!(adapter.needs_transform(&legacy_compat_enabled_num));
// Backward compatibility: openrouter_compat_mode="true" should enable transform
let legacy_compat_enabled_str = create_provider(json!({
"env": {
"ANTHROPIC_BASE_URL": "https://api.example.com"
},
"openrouter_compat_mode": "true"
}));
assert!(adapter.needs_transform(&legacy_compat_enabled_str));
// Backward compatibility: openrouter_compat_mode=false should not enable transform
let legacy_compat_disabled = create_provider(json!({
"env": {

View File

@@ -292,9 +292,19 @@ export function ProviderForm({
try {
const config = JSON.parse(settingsConfigValue || "{}");
const format = config?.api_format;
if (format === "openai_chat") return "openai_chat";
// Backward compatibility: if old openrouter_compat_mode is true, treat as openai_chat
if (config?.openrouter_compat_mode === true) return "openai_chat";
if (typeof format === "string") {
return format === "openai_chat" ? "openai_chat" : "anthropic";
}
// Backward compatibility: old openrouter_compat_mode (bool/number/string)
const raw = config?.openrouter_compat_mode;
if (typeof raw === "boolean") return raw ? "openai_chat" : "anthropic";
if (typeof raw === "number") return raw !== 0 ? "openai_chat" : "anthropic";
if (typeof raw === "string") {
const normalized = raw.trim().toLowerCase();
if (normalized === "true" || normalized === "1") return "openai_chat";
return "anthropic";
}
} catch {
// ignore
}