From 4e7e50754dedc3eac10c83b5e0e521d0753fbce7 Mon Sep 17 00:00:00 2001 From: oyi77 Date: Fri, 3 Apr 2026 10:55:58 +0700 Subject: [PATCH] refactor(auth): improve NVIDIA alias lookup + add LKGP error logging --- open-sse/services/combo.ts | 10 +++++++--- src/sse/services/auth.ts | 29 +++++++++++++++-------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/open-sse/services/combo.ts b/open-sse/services/combo.ts index 13e9ffc0b1..70937296e9 100644 --- a/open-sse/services/combo.ts +++ b/open-sse/services/combo.ts @@ -818,8 +818,8 @@ export async function handleComboChat({ const { getLKGP } = await import("../../src/lib/localDb"); const lkgp = await getLKGP(combo.name, combo.id || combo.name); if (lkgp) lastKnownGoodProvider = lkgp; - } catch { - /* ignore db errors */ + } catch (err) { + log.warn("COMBO", "Failed to retrieve Last Known Good Provider. This is non-fatal.", { err }); } const candidates = await buildAutoCandidates(eligibleModels, combo.name); @@ -998,7 +998,11 @@ export async function handleComboChat({ if (provider) { import("../../src/lib/localDb") .then(({ setLKGP }) => setLKGP(combo.name, combo.id || combo.name, provider)) - .catch(() => {}); + .catch((err) => + log.warn("COMBO", "Failed to record Last Known Good Provider. This is non-fatal.", { + err, + }) + ); } return result; diff --git a/src/sse/services/auth.ts b/src/sse/services/auth.ts index bcd9ae88d7..7d48b85501 100644 --- a/src/sse/services/auth.ts +++ b/src/sse/services/auth.ts @@ -315,10 +315,13 @@ export { fisherYatesShuffle, getNextFromDeckSync as getNextFromDeck }; * Resolve provider aliases (e.g., nvidia -> nvidia_nim) for DB lookup */ function getProviderSearchPool(provider: string): string[] { - const pool = [provider]; - if (provider === "nvidia") pool.push("nvidia_nim"); - if (provider === "nvidia_nim") pool.push("nvidia"); - return [...new Set(pool)]; + if (provider === "nvidia") { + return ["nvidia", "nvidia_nim"]; + } + if (provider === "nvidia_nim") { + return ["nvidia_nim", "nvidia"]; + } + return [provider]; } /** @@ -349,11 +352,10 @@ export async function getProviderCredentials( // Fix #922: Check for aliases (nvidia/nvidia_nim) to ensure credentials are found const providersToSearch = getProviderSearchPool(provider); - let connectionsRaw: any[] = []; - for (const p of providersToSearch) { - const results = await getProviderConnections({ provider: p, isActive: true }); - if (Array.isArray(results)) connectionsRaw.push(...results); - } + const connectionResults = await Promise.all( + providersToSearch.map((p) => getProviderConnections({ provider: p, isActive: true })) + ); + const connectionsRaw = connectionResults.filter(Array.isArray).flat(); let connections = (Array.isArray(connectionsRaw) ? connectionsRaw : []) .map(toProviderConnection) @@ -370,11 +372,10 @@ export async function getProviderCredentials( if (connections.length === 0) { // Check all connections (including inactive) to see if rate limited // Fix #922: Also search aliases here - let allConnectionsRaw: any[] = []; - for (const p of providersToSearch) { - const results = await getProviderConnections({ provider: p }); - if (Array.isArray(results)) allConnectionsRaw.push(...results); - } + const allConnectionsResults = await Promise.all( + providersToSearch.map((p) => getProviderConnections({ provider: p })) + ); + const allConnectionsRaw = allConnectionsResults.filter(Array.isArray).flat(); const allConnections = (Array.isArray(allConnectionsRaw) ? allConnectionsRaw : []) .map(toProviderConnection) .filter((conn) => conn.id.length > 0);