@@ -45,7 +45,6 @@ pub(crate) fn read_current_auth_status() -> Result<CurrentAuthStatus, String> {
4545 return Ok ( CurrentAuthStatus {
4646 available : false ,
4747 account_id : None ,
48- workspace_name : None ,
4948 email : None ,
5049 plan_type : None ,
5150 auth_mode : None ,
@@ -80,9 +79,6 @@ pub(crate) fn read_current_auth_status() -> Result<CurrentAuthStatus, String> {
8079 let extracted = extract_auth ( & value) . ok ( ) ;
8180 let principal_id = extracted. as_ref ( ) . map ( |auth| auth. principal_id . clone ( ) ) ;
8281 let account_id = extracted. as_ref ( ) . map ( |auth| auth. account_id . clone ( ) ) ;
83- let workspace_name = extracted
84- . as_ref ( )
85- . and_then ( |auth| auth. workspace_name . clone ( ) ) ;
8682 let email = extracted. as_ref ( ) . and_then ( |auth| auth. email . clone ( ) ) ;
8783 let plan_type = extracted. as_ref ( ) . and_then ( |auth| auth. plan_type . clone ( ) ) ;
8884
@@ -98,7 +94,6 @@ pub(crate) fn read_current_auth_status() -> Result<CurrentAuthStatus, String> {
9894 Ok ( CurrentAuthStatus {
9995 available : true ,
10096 account_id,
101- workspace_name,
10297 email,
10398 plan_type,
10499 auth_mode,
@@ -226,7 +221,6 @@ pub(crate) fn extract_auth(auth_json: &Value) -> Result<ExtractedAuth, String> {
226221 . get ( "account_id" )
227222 . and_then ( Value :: as_str)
228223 . map ( ToString :: to_string) ;
229- let mut organizations: Vec < Value > = Vec :: new ( ) ;
230224 let mut email = None ;
231225 let mut plan_type = None ;
232226 let mut principal_id = None ;
@@ -240,11 +234,6 @@ pub(crate) fn extract_auth(auth_json: &Value) -> Result<ExtractedAuth, String> {
240234 let auth_claim = claims
241235 . get ( "https://api.openai.com/auth" )
242236 . and_then ( Value :: as_object) ;
243- organizations = auth_claim
244- . and_then ( |value| value. get ( "organizations" ) )
245- . and_then ( Value :: as_array)
246- . cloned ( )
247- . unwrap_or_default ( ) ;
248237 if account_id. is_none ( ) {
249238 account_id = auth_claim
250239 . and_then ( |value| value. get ( "chatgpt_account_id" ) )
@@ -279,76 +268,16 @@ pub(crate) fn extract_auth(auth_json: &Value) -> Result<ExtractedAuth, String> {
279268 let account_id =
280269 account_id. ok_or_else ( || "无法从 auth.json 识别 chatgpt_account_id" . to_string ( ) ) ?;
281270 let principal_id = principal_id. unwrap_or_else ( || account_id. clone ( ) ) ;
282- let workspace_name = resolve_workspace_name_from_organizations ( & organizations, & account_id) ;
283271
284272 Ok ( ExtractedAuth {
285273 principal_id,
286274 account_id,
287- workspace_name,
288275 access_token,
289276 email,
290277 plan_type,
291278 } )
292279}
293280
294- fn resolve_workspace_name_from_organizations (
295- organizations : & [ Value ] ,
296- account_id : & str ,
297- ) -> Option < String > {
298- #[ derive( Clone ) ]
299- struct OrganizationCandidate {
300- id : Option < String > ,
301- title : String ,
302- is_default : bool ,
303- }
304-
305- let candidates: Vec < OrganizationCandidate > = organizations
306- . iter ( )
307- . filter_map ( |item| {
308- let object = item. as_object ( ) ?;
309- let title = object
310- . get ( "title" )
311- . and_then ( Value :: as_str)
312- . map ( str:: trim)
313- . filter ( |value| !value. is_empty ( ) ) ?
314- . to_string ( ) ;
315-
316- Some ( OrganizationCandidate {
317- id : object
318- . get ( "id" )
319- . and_then ( Value :: as_str)
320- . map ( ToString :: to_string) ,
321- title,
322- is_default : object
323- . get ( "is_default" )
324- . and_then ( Value :: as_bool)
325- . unwrap_or ( false ) ,
326- } )
327- } )
328- . collect ( ) ;
329-
330- if let Some ( exact) = candidates
331- . iter ( )
332- . find ( |candidate| candidate. id . as_deref ( ) == Some ( account_id) )
333- {
334- return Some ( exact. title . clone ( ) ) ;
335- }
336-
337- if candidates. len ( ) == 1 {
338- return Some ( candidates[ 0 ] . title . clone ( ) ) ;
339- }
340-
341- let default_candidates: Vec < & OrganizationCandidate > = candidates
342- . iter ( )
343- . filter ( |candidate| candidate. is_default )
344- . collect ( ) ;
345- if default_candidates. len ( ) == 1 {
346- return Some ( default_candidates[ 0 ] . title . clone ( ) ) ;
347- }
348-
349- None
350- }
351-
352281pub ( crate ) fn current_auth_account_key ( ) -> Option < String > {
353282 read_current_codex_auth ( )
354283 . ok ( )
@@ -589,61 +518,3 @@ fn extract_client_id_from_claims(claims: &Value) -> Option<String> {
589518 _ => None ,
590519 }
591520}
592-
593- #[ cfg( test) ]
594- mod tests {
595- use super :: resolve_workspace_name_from_organizations;
596- use serde_json:: json;
597- use serde_json:: Value ;
598-
599- fn organizations ( items : Value ) -> Vec < Value > {
600- items. as_array ( ) . cloned ( ) . unwrap_or_default ( )
601- }
602-
603- #[ test]
604- fn workspace_name_prefers_exact_id_match ( ) {
605- let organizations = organizations ( json ! ( [
606- { "id" : "org-1" , "title" : "Default Workspace" , "is_default" : true } ,
607- { "id" : "acct-2" , "title" : "Target Workspace" , "is_default" : false }
608- ] ) ) ;
609-
610- let resolved = resolve_workspace_name_from_organizations ( & organizations, "acct-2" ) ;
611-
612- assert_eq ! ( resolved. as_deref( ) , Some ( "Target Workspace" ) ) ;
613- }
614-
615- #[ test]
616- fn workspace_name_uses_single_organization_title ( ) {
617- let organizations = organizations (
618- json ! ( [ { "id" : "org-1" , "title" : "Only Workspace" , "is_default" : false } ] ) ,
619- ) ;
620-
621- let resolved = resolve_workspace_name_from_organizations ( & organizations, "acct-unknown" ) ;
622-
623- assert_eq ! ( resolved. as_deref( ) , Some ( "Only Workspace" ) ) ;
624- }
625-
626- #[ test]
627- fn workspace_name_uses_unique_default_as_fallback ( ) {
628- let organizations = organizations ( json ! ( [
629- { "id" : "org-1" , "title" : "Default Workspace" , "is_default" : true } ,
630- { "id" : "org-2" , "title" : "Secondary Workspace" , "is_default" : false }
631- ] ) ) ;
632-
633- let resolved = resolve_workspace_name_from_organizations ( & organizations, "acct-unknown" ) ;
634-
635- assert_eq ! ( resolved. as_deref( ) , Some ( "Default Workspace" ) ) ;
636- }
637-
638- #[ test]
639- fn workspace_name_returns_none_when_ambiguous ( ) {
640- let organizations = organizations ( json ! ( [
641- { "id" : "org-1" , "title" : "Workspace A" , "is_default" : false } ,
642- { "id" : "org-2" , "title" : "Workspace B" , "is_default" : false }
643- ] ) ) ;
644-
645- let resolved = resolve_workspace_name_from_organizations ( & organizations, "acct-unknown" ) ;
646-
647- assert_eq ! ( resolved, None ) ;
648- }
649- }
0 commit comments