fix: ensure custom provider deletion targets correct runtime key by making key generation idempotent (#691)

This commit is contained in:
paisley
2026-03-27 16:56:28 +08:00
committed by GitHub
Unverified
parent 1292e9f120
commit 50bcfeccfc
2 changed files with 18 additions and 0 deletions

View File

@@ -65,6 +65,15 @@ function shouldUseExplicitDefaultOverride(config: ProviderConfig, runtimeProvide
export function getOpenClawProviderKey(type: string, providerId: string): string {
if (type === 'custom' || type === 'ollama') {
// If the providerId is already a runtime key (e.g. re-seeded from openclaw.json
// as "custom-XXXXXXXX"), return it directly to avoid double-hashing.
const prefix = `${type}-`;
if (providerId.startsWith(prefix)) {
const tail = providerId.slice(prefix.length);
if (tail.length === 8 && !tail.includes('-')) {
return providerId;
}
}
const suffix = providerId.replace(/-/g, '').slice(0, 8);
return `${type}-${suffix}`;
}

View File

@@ -18,6 +18,15 @@ const PROVIDER_KEY_ALIASES: Record<string, string> = {
export function getOpenClawProviderKeyForType(type: string, providerId: string): string {
if (MULTI_INSTANCE_PROVIDER_TYPES.has(type)) {
// If the providerId is already a runtime key (e.g. re-seeded from openclaw.json
// as "custom-XXXXXXXX"), return it directly to avoid double-hashing.
const prefix = `${type}-`;
if (providerId.startsWith(prefix)) {
const tail = providerId.slice(prefix.length);
if (tail.length === 8 && !tail.includes('-')) {
return providerId;
}
}
const suffix = providerId.replace(/-/g, '').slice(0, 8);
return `${type}-${suffix}`;
}