fix(providers): clear provider list when OpenClaw JSON is deleted (#526)
This commit is contained in:
committed by
GitHub
Unverified
parent
4e3f3c83f6
commit
7e54aad9e6
@@ -267,19 +267,23 @@ export async function getAllProvidersWithKeyInfo(): Promise<
|
||||
const providers = await getAllProviders();
|
||||
const results: Array<ProviderConfig & { hasKey: boolean; keyMasked: string | null }> = [];
|
||||
const activeOpenClawProviders = await getActiveOpenClawProviders();
|
||||
// When openclaw.json is deleted/missing, the active set is empty.
|
||||
// In that case, all providers (including builtins) should be cleaned up.
|
||||
const configMissing = activeOpenClawProviders.size === 0;
|
||||
|
||||
for (const provider of providers) {
|
||||
// Sync check: If it's a custom/OAuth provider and it no longer exists in OpenClaw config
|
||||
// (e.g. wiped by Gateway due to missing plugin, or manually deleted by user)
|
||||
// we should remove it from ClawX UI to stay consistent.
|
||||
const isBuiltin = BUILTIN_PROVIDER_TYPES.includes(provider.type);
|
||||
const isBuiltin = (BUILTIN_PROVIDER_TYPES as readonly string[]).includes(provider.type);
|
||||
// For custom/ollama providers, the OpenClaw config key is derived as
|
||||
// "<type>-<suffix>" where suffix = first 8 chars of providerId with hyphens stripped.
|
||||
// e.g. provider.id "custom-a1b2c3d4-..." → strip hyphens → "customa1b2c3d4..." → slice(0,8) → "customa1"
|
||||
// → openClawKey = "custom-customa1"
|
||||
// This must match getOpenClawProviderKey() in ipc-handlers.ts exactly.
|
||||
const openClawKey = getOpenClawProviderKeyForType(provider.type, provider.id);
|
||||
if (!isBuiltin && !activeOpenClawProviders.has(provider.type) && !activeOpenClawProviders.has(provider.id) && !activeOpenClawProviders.has(openClawKey)) {
|
||||
const isActive = activeOpenClawProviders.has(provider.type) || activeOpenClawProviders.has(provider.id) || activeOpenClawProviders.has(openClawKey);
|
||||
if (configMissing || (!isBuiltin && !isActive)) {
|
||||
console.log(`[Sync] Provider ${provider.id} (${provider.type}) missing from OpenClaw, dropping from ClawX UI`);
|
||||
await deleteProvider(provider.id);
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user