@@ -101,6 +101,24 @@ function formatAgentError(error: unknown) {
101101 return String ( error ) ;
102102}
103103
104+ function formatAgentResponseError ( error : unknown ) : string {
105+ if ( isAggregateErrorLike ( error ) ) {
106+ const nestedErrors = error . errors . map ( formatAgentResponseError ) ;
107+
108+ if ( nestedErrors . length ) {
109+ return nestedErrors . join ( "\n" ) ;
110+ }
111+
112+ return error . message || "Agent response failed" ;
113+ }
114+
115+ if ( error instanceof Error ) {
116+ return error . toString ( ) ;
117+ }
118+
119+ return String ( error ) ;
120+ }
121+
104122function formatAdminUserPrompt ( adminUser : AdminUser , usernameField : string ) {
105123 const dbUser = adminUser . dbUser as Record < string , unknown > ;
106124 const adminUserContext = {
@@ -553,11 +571,12 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
553571 } catch ( error ) {
554572 logger . error ( `Agent response streaming failed:\n${ formatAgentError ( error ) } ` ) ;
555573 sequenceDebugCollector . flush ( ) ;
574+ fullResponse = formatAgentResponseError ( error ) ;
556575 const textId = startBlock ( 'text' ) ;
557576 send ( {
558577 type : 'text-delta' ,
559578 id : textId ,
560- delta : 'Agent response failed. Check server logs for details.' ,
579+ delta : fullResponse ,
561580 } ) ;
562581 }
563582 sequenceDebugCollector . flush ( ) ;
@@ -676,6 +695,7 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
676695 } catch ( error ) {
677696 logger . error ( `Agent speech response failed:\n${ formatAgentError ( error ) } ` ) ;
678697 sequenceDebugCollector . flush ( ) ;
698+ fullResponse = formatAgentResponseError ( error ) ;
679699 const turnUpdates : Record < string , unknown > = {
680700 [ this . options . turnResource . responseField ] : fullResponse ,
681701 } ;
@@ -687,7 +707,7 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
687707 await this . updateTurn ( turnId , turnUpdates ) ;
688708 response . setStatus ( 500 , undefined ) ;
689709 return {
690- error : "Agent speech response failed. Check server logs for details." ,
710+ error : fullResponse ,
691711 } ;
692712 }
693713 }
0 commit comments