@@ -280,33 +280,165 @@ export function createCodexConfigMethods(options = {}) {
280280 try {
281281 const silent = ! ! ( options && options . silent ) ;
282282 const forceRefresh = ! ! ( options && options . forceRefresh ) ;
283- const res = await api ( 'doctor' , {
284- lang : this . lang ,
285- remote : true ,
286- range : this . sessionsUsageTimeRange ,
287- targetApp : this . skillsTargetApp ,
288- includeUsage : true ,
289- includeTasks : true ,
290- includeSkills : true ,
291- includeInstall : true ,
292- forceRefresh
293- } ) ;
283+ const useDoctor = ! ! ( options && options . doctor ) ;
284+ if ( useDoctor ) {
285+ const res = await api ( 'doctor' , {
286+ lang : this . lang ,
287+ remote : true ,
288+ range : this . sessionsUsageTimeRange ,
289+ targetApp : this . skillsTargetApp ,
290+ includeUsage : true ,
291+ includeTasks : true ,
292+ includeSkills : true ,
293+ includeInstall : true ,
294+ forceRefresh
295+ } ) ;
296+ if ( hasResponseError ( res ) ) {
297+ this . healthCheckResult = null ;
298+ if ( ! silent ) {
299+ this . showMessage ( getResponseMessage ( res , '检查失败' ) , 'error' ) ;
300+ }
301+ return ;
302+ }
303+ if ( res && typeof res === 'object' ) {
304+ this . healthCheckResult = res ;
305+ const report = res . report && typeof res . report === 'object' ? res . report : null ;
306+ const summary = report && report . summary && typeof report . summary === 'object' ? report . summary : null ;
307+ const total = summary && Number . isFinite ( Number ( summary . total ) )
308+ ? Math . max ( 0 , Math . floor ( Number ( summary . total ) ) )
309+ : ( Array . isArray ( res . issues ) ? res . issues . length : 0 ) ;
310+ const errors = summary && Number . isFinite ( Number ( summary . error ) ) ? Math . max ( 0 , Math . floor ( Number ( summary . error ) ) ) : 0 ;
311+ const warns = summary && Number . isFinite ( Number ( summary . warn ) ) ? Math . max ( 0 , Math . floor ( Number ( summary . warn ) ) ) : 0 ;
312+ this . healthCheckBatchTotal = total ;
313+ this . healthCheckBatchDone = total ;
314+ this . healthCheckBatchFailed = errors + warns ;
315+ if ( ! silent && res . ok ) {
316+ this . showMessage ( '检查通过' , 'success' ) ;
317+ }
318+ return ;
319+ }
320+ this . healthCheckResult = null ;
321+ if ( ! silent ) {
322+ this . showMessage ( '检查失败' , 'error' ) ;
323+ }
324+ return ;
325+ }
326+
327+ if ( this . configMode === 'claude' ) {
328+ const entries = Object . entries ( this . claudeConfigs || { } ) ;
329+ this . healthCheckBatchTotal = entries . length ;
330+
331+ const speedTasks = entries . map ( ( [ name , config ] ) => this . runClaudeSpeedTest ( name , config )
332+ . then ( ( result ) => {
333+ if ( ! result || result . ok !== true ) {
334+ this . healthCheckBatchFailed += 1 ;
335+ }
336+ return { name, result } ;
337+ } )
338+ . catch ( ( err ) => {
339+ this . healthCheckBatchFailed += 1 ;
340+ return {
341+ name,
342+ result : { ok : false , error : err && err . message ? err . message : 'Speed test failed' }
343+ } ;
344+ } )
345+ . finally ( ( ) => {
346+ this . healthCheckBatchDone += 1 ;
347+ } )
348+ ) ;
349+
350+ const pairs = await Promise . all ( speedTasks ) ;
351+ const results = { } ;
352+ const issues = [ ] ;
353+ for ( const pair of pairs ) {
354+ results [ pair . name ] = pair . result || null ;
355+ if ( typeof this . buildSpeedTestIssue === 'function' ) {
356+ const issue = this . buildSpeedTestIssue ( pair . name , pair . result ) ;
357+ if ( issue ) issues . push ( issue ) ;
358+ }
359+ }
360+ const ok = issues . length === 0 && this . healthCheckBatchFailed === 0 ;
361+ this . healthCheckResult = {
362+ ok,
363+ issues,
364+ remote : {
365+ type : 'speed-test' ,
366+ speedTests : results
367+ }
368+ } ;
369+ if ( ok && ! silent ) {
370+ this . showMessage ( '检查通过' , 'success' ) ;
371+ }
372+ return ;
373+ }
374+
375+ const shouldRunSpeedTests = this . configMode === 'codex' ;
376+ const speedTimeoutMs = shouldRunSpeedTests ? 3500 : 0 ;
377+ const providers = shouldRunSpeedTests
378+ ? ( this . providersList || [ ] )
379+ . map ( ( provider ) => typeof provider === 'string'
380+ ? provider . trim ( )
381+ : String ( ( provider && provider . name ) || '' ) . trim ( ) )
382+ . filter ( Boolean )
383+ : [ ] ;
384+ const currentProvider = String ( this . currentProvider || '' ) . trim ( ) ;
385+ const orderedProviders = currentProvider && providers . includes ( currentProvider )
386+ ? [ currentProvider , ...providers . filter ( ( name ) => name !== currentProvider ) ]
387+ : providers ;
388+ this . healthCheckBatchTotal = orderedProviders . length ;
389+
390+ const speedTasks = orderedProviders . map ( ( provider ) => this . runSpeedTest ( provider , { silent : true , timeoutMs : speedTimeoutMs } )
391+ . then ( ( result ) => {
392+ if ( ! result || result . ok !== true ) {
393+ this . healthCheckBatchFailed += 1 ;
394+ }
395+ return { name : provider , result } ;
396+ } )
397+ . catch ( ( err ) => {
398+ this . healthCheckBatchFailed += 1 ;
399+ return {
400+ name : provider ,
401+ result : { ok : false , error : err && err . message ? err . message : 'Speed test failed' }
402+ } ;
403+ } )
404+ . finally ( ( ) => {
405+ this . healthCheckBatchDone += 1 ;
406+ } )
407+ ) ;
408+
409+ const configTask = api ( 'config-health-check' , { remote : this . configMode === 'codex' } ) ;
410+ const [ res , pairs ] = await Promise . all ( [
411+ configTask ,
412+ Promise . all ( speedTasks )
413+ ] ) ;
294414 if ( hasResponseError ( res ) ) {
295415 this . healthCheckResult = null ;
296416 if ( ! silent ) {
297417 this . showMessage ( getResponseMessage ( res , '检查失败' ) , 'error' ) ;
298418 }
299419 } else if ( res && typeof res === 'object' ) {
300- this . healthCheckResult = res ;
301- const report = res . report && typeof res . report === 'object' ? res . report : null ;
302- const summary = report && report . summary && typeof report . summary === 'object' ? report . summary : null ;
303- const total = summary && Number . isFinite ( Number ( summary . total ) ) ? Math . max ( 0 , Math . floor ( Number ( summary . total ) ) ) : ( Array . isArray ( res . issues ) ? res . issues . length : 0 ) ;
304- const errors = summary && Number . isFinite ( Number ( summary . error ) ) ? Math . max ( 0 , Math . floor ( Number ( summary . error ) ) ) : 0 ;
305- const warns = summary && Number . isFinite ( Number ( summary . warn ) ) ? Math . max ( 0 , Math . floor ( Number ( summary . warn ) ) ) : 0 ;
306- this . healthCheckBatchTotal = total ;
307- this . healthCheckBatchDone = total ;
308- this . healthCheckBatchFailed = errors + warns ;
309- if ( ! silent && res . ok ) {
420+ const issues = Array . isArray ( res . issues ) ? [ ...res . issues ] : [ ] ;
421+ let remote = res . remote || null ;
422+ if ( shouldRunSpeedTests ) {
423+ const results = { } ;
424+ for ( const pair of pairs ) {
425+ results [ pair . name ] = pair . result || null ;
426+ const issue = this . buildSpeedTestIssue ( pair . name , pair . result ) ;
427+ if ( issue ) issues . push ( issue ) ;
428+ }
429+ remote = remote && typeof remote === 'object'
430+ ? { ...remote , speedTests : results }
431+ : { type : 'speed-test' , speedTests : results } ;
432+ }
433+
434+ const ok = issues . length === 0 ;
435+ this . healthCheckResult = {
436+ ...res ,
437+ ok,
438+ issues,
439+ remote
440+ } ;
441+ if ( ok && ! silent ) {
310442 this . showMessage ( '检查通过' , 'success' ) ;
311443 }
312444 } else {
0 commit comments