@@ -32,6 +32,7 @@ import {
32
32
SYSTEM_PROMPT ,
33
33
SYSTEM_PROMPT_TEMPLATE ,
34
34
} from './constants' ;
35
+ import { InternalServerError } from 'openai' ;
35
36
36
37
export class GUIAgent < T extends Operator > extends BaseGUIAgent <
37
38
GUIAgentConfig < T >
@@ -489,66 +490,71 @@ export class GUIAgent<T extends Operator> extends BaseGUIAgent<
489
490
error : unknown ,
490
491
type : ErrorStatusEnum | null = null ,
491
492
) : GUIAgentError {
492
- if (
493
- error instanceof Error &&
494
- 'status' in error &&
495
- 'error' in error &&
496
- error . status === 500 &&
497
- typeof error . error === 'string' &&
498
- error . error . includes ( 'unhandled errors in a TaskGroup' )
499
- ) {
500
- return new GUIAgentError (
493
+ this . logger . error ( '[GUIAgent] guiAgentErrorParser:' , error ) ;
494
+
495
+ let parseError = null ;
496
+
497
+ if ( error instanceof InternalServerError ) {
498
+ this . logger . error (
499
+ '[GUIAgent] guiAgentErrorParser instanceof InternalServerError.' ,
500
+ ) ;
501
+ parseError = new GUIAgentError (
501
502
ErrorStatusEnum . MODEL_SERVICE_ERROR ,
502
503
error . message ,
503
504
error . stack ,
504
- JSON . stringify ( error ) ,
505
505
) ;
506
506
}
507
507
508
- if ( type === ErrorStatusEnum . REACH_MAXLOOP_ERROR ) {
509
- return new GUIAgentError (
508
+ if ( ! parseError && type === ErrorStatusEnum . REACH_MAXLOOP_ERROR ) {
509
+ parseError = new GUIAgentError (
510
510
ErrorStatusEnum . REACH_MAXLOOP_ERROR ,
511
511
'Has reached max loop count' ,
512
512
) ;
513
513
}
514
514
515
- if ( type === ErrorStatusEnum . SCREENSHOT_RETRY_ERROR ) {
516
- return new GUIAgentError (
515
+ if ( ! parseError && type === ErrorStatusEnum . SCREENSHOT_RETRY_ERROR ) {
516
+ parseError = new GUIAgentError (
517
517
ErrorStatusEnum . SCREENSHOT_RETRY_ERROR ,
518
518
'Too many screenshot failures' ,
519
519
) ;
520
520
}
521
521
522
- if ( type === ErrorStatusEnum . INVOKE_RETRY_ERROR ) {
523
- return new GUIAgentError (
522
+ if ( ! parseError && type === ErrorStatusEnum . INVOKE_RETRY_ERROR ) {
523
+ parseError = new GUIAgentError (
524
524
ErrorStatusEnum . INVOKE_RETRY_ERROR ,
525
525
'Too many model invoke failures' ,
526
526
'null' ,
527
- JSON . stringify ( error ) ,
528
527
) ;
529
528
}
530
529
531
- if ( type === ErrorStatusEnum . EXECUTE_RETRY_ERROR ) {
532
- return new GUIAgentError (
530
+ if ( ! parseError && type === ErrorStatusEnum . EXECUTE_RETRY_ERROR ) {
531
+ parseError = new GUIAgentError (
533
532
ErrorStatusEnum . EXECUTE_RETRY_ERROR ,
534
533
'Too many action execute failures' ,
535
534
'null' ,
536
- JSON . stringify ( error ) ,
537
535
) ;
538
536
}
539
537
540
- if ( type === ErrorStatusEnum . ENVIRONMENT_ERROR ) {
541
- return new GUIAgentError (
538
+ if ( ! parseError && type === ErrorStatusEnum . ENVIRONMENT_ERROR ) {
539
+ parseError = new GUIAgentError (
542
540
ErrorStatusEnum . ENVIRONMENT_ERROR ,
543
541
'The environment error occurred when parsing the action' ,
544
542
) ;
545
543
}
546
544
547
- return new GUIAgentError (
548
- ErrorStatusEnum . UNKNOWN_ERROR ,
549
- error instanceof Error ? error . message : 'Unknown error occurred' ,
550
- error instanceof Error ? error . stack || 'null' : 'null' ,
551
- JSON . stringify ( error ) ,
552
- ) ;
545
+ if ( ! parseError ) {
546
+ parseError = new GUIAgentError (
547
+ ErrorStatusEnum . UNKNOWN_ERROR ,
548
+ error instanceof Error ? error . message : 'Unknown error occurred' ,
549
+ error instanceof Error ? error . stack || 'null' : 'null' ,
550
+ ) ;
551
+ }
552
+
553
+ if ( ! parseError . stack ) {
554
+ // Avoid guiAgentErrorParser it self in stack trace
555
+ Error . captureStackTrace ( parseError , this . guiAgentErrorParser ) ;
556
+ }
557
+
558
+ return parseError ;
553
559
}
554
560
}
0 commit comments