@@ -58,6 +58,7 @@ import {
5858 parseAccountPriority ,
5959} from "./pool-rotation" ;
6060import { checkAccountIdCollision , getMainChatgptAccountId , readCodexTokens , readCodexTokensResult } from "./auth-collision" ;
61+ import { codexPlanValue , isThirtyDayOnlyCodexPlan } from "./plan" ;
6162export { checkAccountIdCollision , getMainChatgptAccountId } from "./auth-collision" ;
6263export { clearAccountNeedsReauth , isAccountNeedsReauth , markAccountNeedsReauth } from "./account-runtime-state" ;
6364import { clearAccountNeedsReauth , isAccountNeedsReauth , markAccountNeedsReauth } from "./account-runtime-state" ;
@@ -208,16 +209,11 @@ function codexAccountPersistenceConflict(
208209 : undefined ;
209210}
210211
211- function isThirtyDayOnlyPlan ( plan : string | null | undefined ) : boolean {
212- const normalized = plan ?. trim ( ) . toLowerCase ( ) ;
213- return normalized === "go" || normalized === "free" ;
214- }
215-
216212function quotaForPlan < T extends Omit < StoredAccountQuota , "updatedAt" > | StoredAccountQuota | null > (
217213 quota : T ,
218- plan : string | null | undefined ,
214+ plan : unknown ,
219215) : T {
220- if ( ! quota || ! isThirtyDayOnlyPlan ( plan ) ) return quota ;
216+ if ( ! quota || ! isThirtyDayOnlyCodexPlan ( plan ) ) return quota ;
221217 return {
222218 ...( quota . monthlyPercent !== undefined ? { monthlyPercent : quota . monthlyPercent } : { } ) ,
223219 ...( quota . monthlyResetAt !== undefined ? { monthlyResetAt : quota . monthlyResetAt } : { } ) ,
@@ -233,14 +229,15 @@ function poolAccountDto(
233229 paused : boolean ,
234230 priority : number ,
235231) : CodexAuthAccountDto {
236- const quota = quotaForPlan ( quotaResult . quota , account . plan ) ;
232+ const plan = codexPlanValue ( account . plan ) ;
233+ const quota = quotaForPlan ( quotaResult . quota , plan ) ;
237234 const needsReauth = ! hasCredential || quotaResult . needsReauth || isAccountNeedsReauth ( account . id ) ;
238235 const health = projectCodexAccountHealth ( { accountId : account . id , needsReauth } ) ;
239236 return {
240237 id : account . id ,
241238 email : maskEmail ( account . email ) ?? account . email ,
242239 ...( account . alias !== undefined ? { alias : account . alias } : { } ) ,
243- ...( account . plan !== undefined ? { plan : account . plan } : { } ) ,
240+ ...( plan !== undefined ? { plan } : { } ) ,
244241 ...( account . logLabel !== undefined ? { logLabel : account . logLabel } : { } ) ,
245242 isMain : false ,
246243 paused,
@@ -398,7 +395,7 @@ const POOL_CACHE_TTL = 5 * 60_000;
398395const POOL_QUOTA_REFRESH_CONCURRENCY = 4 ;
399396
400397function nonEmptyPlan ( value : unknown ) : string | null {
401- return typeof value === "string" && value . trim ( ) !== "" ? value : null ;
398+ return codexPlanValue ( value ) ?? null ;
402399}
403400
404401function isRuntimeConfig ( config : OcxConfig ) : boolean {
@@ -1334,7 +1331,7 @@ export async function handleCodexAuthAPI(
13341331 if ( url . pathname === "/api/codex-auth/accounts" && req . method === "POST" ) {
13351332 if ( ! isUnverifiedCodexImportEnabled ( ) ) return manualImportDisabledResponse ( ) ;
13361333
1337- let body : { id : string ; email : string ; plan ?: string ; accessToken : string ; refreshToken : string ; chatgptAccountId : string } ;
1334+ let body : { id : string ; email : string ; plan ?: unknown ; accessToken : string ; refreshToken : string ; chatgptAccountId : string } ;
13381335 try { body = ( await req . json ( ) ) as typeof body ; } catch { return jsonResponse ( { error : "Invalid JSON" } , 400 ) ; }
13391336 if ( ! body . id || ! body . email || ! body . accessToken || ! body . refreshToken || ! body . chatgptAccountId ) {
13401337 return jsonResponse ( { error : "Missing required fields" } , 400 ) ;
@@ -1349,8 +1346,9 @@ export async function handleCodexAuthAPI(
13491346 const preflightConflict = codexAccountPersistenceConflict ( runtimeConfig , body . id , "create" ) ;
13501347 if ( preflightConflict ) return jsonResponse ( { error : preflightConflict } , 400 ) ;
13511348 // 1.1: Duplicate check is scoped by personal vs workspace plan bucket.
1349+ const plan = codexPlanValue ( body . plan ) ;
13521350 const derivedAccountId = extractAccountId ( undefined , body . accessToken ) ?? body . chatgptAccountId ;
1353- const collision = checkAccountIdCollision ( derivedAccountId , body . email , body . plan ) ;
1351+ const collision = checkAccountIdCollision ( derivedAccountId , body . email , plan ) ;
13541352 if ( collision . collision ) {
13551353 return jsonResponse ( { error : collision . reason } , 400 ) ;
13561354 }
@@ -1363,7 +1361,12 @@ export async function handleCodexAuthAPI(
13631361 const commitConflict = codexAccountPersistenceConflict ( latestConfig , body . id , "create" ) ;
13641362 if ( commitConflict ) return jsonResponse ( { error : commitConflict } , 400 ) ;
13651363 const addedAccount = withCodexAccountLogLabel (
1366- { id : body . id , email : body . email , plan : body . plan , isMain : false } ,
1364+ {
1365+ id : body . id ,
1366+ email : body . email ,
1367+ ...( plan !== undefined ? { plan } : { } ) ,
1368+ isMain : false ,
1369+ } ,
13671370 latestConfig . codexAccounts ?? [ ] ,
13681371 ) ;
13691372 const persistence = persistNewCodexAccount (
0 commit comments