From 4386e9122d92c7c32d8f11c4216631a473b5c5dd Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Thu, 1 Jan 2026 13:20:59 -0500 Subject: [PATCH] fix(cliproxy): add kiro/ghcp provider mappings to discoverExistingAccounts - Replace hardcoded typeToProvider with dynamic lookup from PROVIDER_TYPE_VALUES - Add email extraction from filename as fallback for empty data.email - Fixes issue where Kiro/GHCP accounts were skipped during discovery Closes #242 --- src/cliproxy/account-manager.ts | 34 ++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/cliproxy/account-manager.ts b/src/cliproxy/account-manager.ts index 71cc2d3e..8ba64cd1 100644 --- a/src/cliproxy/account-manager.ts +++ b/src/cliproxy/account-manager.ts @@ -12,6 +12,7 @@ import * as fs from 'fs'; import * as path from 'path'; import { CLIProxyProvider } from './types'; import { getCliproxyDir, getAuthDir } from './config-generator'; +import { PROVIDER_TYPE_VALUES } from './auth/auth-types'; /** Account information */ export interface AccountInfo { @@ -431,26 +432,33 @@ export function discoverExistingAccounts(): void { // Skip if no type field if (!data.type) continue; - // Map token type values to internal provider names - // CLIProxyAPI uses different type values in tokens (e.g., "antigravity" vs "agy") - const typeToProvider: Record = { - gemini: 'gemini', - antigravity: 'agy', - codex: 'codex', - qwen: 'qwen', - iflow: 'iflow', - }; - + // Build reverse mapping from PROVIDER_TYPE_VALUES (type value -> provider) + // e.g., "antigravity" -> "agy", "kiro" -> "kiro", "codewhisperer" -> "kiro" const typeValue = data.type.toLowerCase(); - const provider = typeToProvider[typeValue]; + let provider: CLIProxyProvider | undefined; + for (const [prov, typeValues] of Object.entries(PROVIDER_TYPE_VALUES)) { + if (typeValues.includes(typeValue)) { + provider = prov as CLIProxyProvider; + break; + } + } // Skip if unknown provider type if (!provider) { continue; } - // Extract email if available - const email = data.email || undefined; + // Extract email if available, fallback to filename + let email = data.email || undefined; + + // Fallback: extract email from filename (e.g., "kiro-google-user@example.com.json") + if (!email && file.includes('@')) { + const match = file.match(/([^-]+@[^.]+\.[^.]+)(?=\.json$)/); + if (match) { + email = match[1]; + } + } + const accountId = email || 'default'; // Initialize provider section if needed