@@ -255,6 +255,29 @@ type ApiFileDownload = {
255
255
error_message : string | null
256
256
}
257
257
258
+ // eslint-disable-next-line no-restricted-syntax
259
+ const enum ChatGPTCookie {
260
+ AgeVerification = 'oai-av-seen' ,
261
+ AllowNonessential = 'oai-allow-ne' ,
262
+ DeviceId = 'oai-did' ,
263
+ DomainMigrationSourceCompleted = 'oai-dm-src-c-240329' ,
264
+ DomainMigrationTargetCompleted = 'oai-dm-tgt-c-240329' ,
265
+ HasClickedOnTryItFirstLink = 'oai-tif-20240402' ,
266
+ HasLoggedInBefore = 'oai-hlib' ,
267
+ HideLoggedOutBanner = 'hide-logged-out-banner' ,
268
+ IntercomDeviceIdDev = 'intercom-device-id-izw1u7l7' ,
269
+ IntercomDeviceIdProd = 'intercom-device-id-dgkjq2bp' ,
270
+ IpOverride = 'oai-ip-country' ,
271
+ IsEmployee = '_oaiauth' ,
272
+ IsPaidUser = '_puid' ,
273
+ LastLocation = 'oai-ll' ,
274
+ SegmentUserId = 'ajs_user_id' ,
275
+ SegmentUserTraits = 'ajs_user_traits' ,
276
+ ShowPaymentModal = 'ui-show-payment-modal' ,
277
+ TempEnableUnauthedCompliance = 'temp-oai-compliance' ,
278
+ Workspace = '_account' ,
279
+ }
280
+
258
281
const sessionApi = urlcat ( baseUrl , '/api/auth/session' )
259
282
const conversationApi = ( id : string ) => urlcat ( apiUrl , '/conversation/:id' , { id } )
260
283
const conversationsApi = ( offset : number , limit : number ) => urlcat ( apiUrl , '/conversations' , { offset, limit } )
@@ -448,14 +471,19 @@ async function _fetchAccountsCheck(): Promise<ApiAccountsCheck> {
448
471
449
472
const fetchAccountsCheck = memorize ( _fetchAccountsCheck )
450
473
474
+ const getCookie = ( key : string ) => document . cookie . match ( `(^|;)\\s*${ key } \\s*=\\s*([^;]+)` ) ?. pop ( ) || ''
475
+
451
476
export async function getTeamAccountId ( ) : Promise < string | null > {
452
477
const accountsCheck = await fetchAccountsCheck ( )
453
- const accountKey = accountsCheck . account_ordering ?. [ 0 ] || 'default'
454
- const account = accountsCheck . accounts [ accountKey ]
455
- if ( ! account ) return null
456
- if ( account . account . plan_type !== 'team' ) return null
478
+ const workspaceId = getCookie ( ChatGPTCookie . Workspace )
479
+ if ( workspaceId ) {
480
+ const account = accountsCheck . accounts [ workspaceId ]
481
+ if ( account ) {
482
+ return account . account . account_id
483
+ }
484
+ }
457
485
458
- return account . account . account_id
486
+ return null
459
487
}
460
488
461
489
export interface ConversationResult {
0 commit comments