fix(cliproxy): use paidTier for account tier detection instead of allowedTiers

- paidTier.id contains actual subscription: g1-ultra-tier or g1-pro-tier

- allowedTiers[isDefault] returns standard-tier for all accounts (not useful)

- mapTierString now correctly parses g1-ultra-tier and g1-pro-tier formats
This commit is contained in:
kaitranntt
2026-01-28 15:17:23 -05:00
parent 87cced8195
commit de23029b57
+9 -13
View File
@@ -303,18 +303,21 @@ function readAuthData(provider: CLIProxyProvider, accountId: string): AuthData |
/** /**
* Map tier ID string to AccountTier type * Map tier ID string to AccountTier type
* API returns: "g1-ultra-tier", "g1-pro-tier", "standard-tier", etc.
* Priority: ultra > pro > free * Priority: ultra > pro > free
*/ */
function mapTierString(tierStr: string | undefined): AccountTier { function mapTierString(tierStr: string | undefined): AccountTier {
if (!tierStr) return 'unknown'; if (!tierStr) return 'unknown';
const normalized = tierStr.toLowerCase(); const normalized = tierStr.toLowerCase();
// Match "g1-ultra-tier" or "ultra" anywhere in string
if (normalized.includes('ultra')) return 'ultra'; if (normalized.includes('ultra')) return 'ultra';
// Match "g1-pro-tier" or "pro" anywhere in string
if (normalized.includes('pro')) return 'pro'; if (normalized.includes('pro')) return 'pro';
// Match free/legacy tiers
if (normalized.includes('free') || normalized.includes('legacy')) { if (normalized.includes('free') || normalized.includes('legacy')) {
return 'free'; return 'free';
} }
// "standard-tier" and other unknown values should NOT map to 'free' // "standard-tier" and other unknown values = unknown
// Let inferTierFromModels handle the detection
return 'unknown'; return 'unknown';
} }
@@ -382,17 +385,10 @@ async function getProjectId(accessToken: string): Promise<{
}; };
} }
// Extract tier using CLIProxyAPIPlus approach: // Extract tier - paidTier reflects actual subscription status, takes priority
// 1. Find tier with isDefault=true in allowedTiers array // API returns: paidTier.id = "g1-ultra-tier" or "g1-pro-tier"
// 2. Fallback to paidTier > currentTier // allowedTiers/currentTier often return "standard-tier" which is not useful
let tierStr: string | undefined; const tierStr = data.paidTier?.id || data.currentTier?.id;
if (data.allowedTiers && Array.isArray(data.allowedTiers)) {
const defaultTier = data.allowedTiers.find((t) => t.isDefault);
tierStr = defaultTier?.id;
}
if (!tierStr) {
tierStr = data.paidTier?.id || data.currentTier?.id;
}
const tier = mapTierString(tierStr); const tier = mapTierString(tierStr);
return { projectId: projectId.trim(), tier }; return { projectId: projectId.trim(), tier };