From 36367d49f0f51f4ecba9a32adf54308af153bdb2 Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Thu, 15 Jan 2026 11:22:40 -0500 Subject: [PATCH] fix(dashboard): update projectId for existing accounts during discovery Previously, discoverExistingAccounts skipped existing token files entirely, so accounts created before the projectId feature never got their projectId populated from auth files. Now when a token file is already registered, we still check if projectId needs to be updated for agy accounts. --- src/cliproxy/account-manager.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cliproxy/account-manager.ts b/src/cliproxy/account-manager.ts index 8906994b..7803b451 100644 --- a/src/cliproxy/account-manager.ts +++ b/src/cliproxy/account-manager.ts @@ -639,6 +639,15 @@ export function discoverExistingAccounts(): void { // Skip if token file already registered (under any accountId) const existingTokenFiles = Object.values(providerAccounts.accounts).map((a) => a.tokenFile); if (existingTokenFiles.includes(file)) { + // Token file exists - check if we need to update projectId for agy accounts + if (provider === 'agy' && data.project_id) { + const existingEntry = Object.entries(providerAccounts.accounts).find( + ([, meta]) => meta.tokenFile === file + ); + if (existingEntry && !existingEntry[1].projectId) { + existingEntry[1].projectId = data.project_id; + } + } continue; } @@ -710,7 +719,7 @@ export function discoverExistingAccounts(): void { if (!freshRegistry.providers[prov]) { freshRegistry.providers[prov] = discovered; } else { - // Merge accounts, preferring fresh registry's existing entries + // Merge accounts, preferring fresh registry's existing entries but updating projectId const freshProviderAccounts = freshRegistry.providers[prov]; if (!freshProviderAccounts) continue; for (const [id, meta] of Object.entries(discovered.accounts)) { @@ -720,6 +729,9 @@ export function discoverExistingAccounts(): void { if (!freshProviderAccounts.default || freshProviderAccounts.default === 'default') { freshProviderAccounts.default = id; } + } else if (meta.projectId && !freshProviderAccounts.accounts[id].projectId) { + // Update existing account with projectId if discovered from auth file + freshProviderAccounts.accounts[id].projectId = meta.projectId; } } }