@@ -37,6 +37,7 @@ import {
3737 listApps ,
3838 listModelOptions ,
3939 listSessions ,
40+ RUN_SSE_INCOMPLETE_RESPONSE_ERROR ,
4041 runSSE ,
4142 refreshAgentFeedbackCases ,
4243 submitIssueFeedback ,
@@ -4935,15 +4936,16 @@ export default function App() {
49354936 setSeenAgentsBySession ( ( m ) => ( { ...m , [ sid ] : new Set ( ) } ) ) ;
49364937 setExecPathBySession ( ( m ) => ( { ...m , [ sid ] : [ ] } ) ) ;
49374938
4939+ let streamFailed = false ;
4940+ let streamError : unknown = null ;
49384941 try {
49394942 let acc = emptyAcc ( ) ;
49404943 let currentStreamAuthor = "" ;
49414944 let tokens = 0 ;
49424945 let ts = Date . now ( ) / 1000 ;
49434946 let eventId = "" ;
49444947 let invocationId = "" ;
4945- let streamFailed = false ;
4946- let streamError : unknown = null ;
4948+ let hasCompletedReply = false ;
49474949 for await ( const event of runSSE ( {
49484950 appName,
49494951 userId,
@@ -4980,6 +4982,12 @@ export default function App() {
49804982 const nextInvocationId = event . invocationId ?? event . invocation_id ;
49814983 if ( nextInvocationId ) invocationId = nextInvocationId ;
49824984 const blocks = acc . blocks ;
4985+ if (
4986+ event . partial !== true &&
4987+ turnHasVisibleContent ( { role : "assistant" , blocks } )
4988+ ) {
4989+ hasCompletedReply = true ;
4990+ }
49834991 const meta = {
49844992 author : currentStreamAuthor || undefined ,
49854993 tokens : tokens || undefined ,
@@ -5001,6 +5009,13 @@ export default function App() {
50015009 return next ;
50025010 } ) ;
50035011 }
5012+ if ( ! ctrl . signal . aborted && ! streamFailed && ! hasCompletedReply ) {
5013+ streamFailed = true ;
5014+ streamError = RUN_SSE_INCOMPLETE_RESPONSE_ERROR ;
5015+ if ( viewSidRef . current === sid ) {
5016+ setError ( RUN_SSE_INCOMPLETE_RESPONSE_ERROR ) ;
5017+ }
5018+ }
50045019 void refreshSessions ( appName ) ;
50055020 if ( trackRuntimeMessage && ctrl . signal . aborted ) {
50065021 messageOperation ?. fail ( {
@@ -5023,6 +5038,8 @@ export default function App() {
50235038 automaticEvaluationStatusRefreshRef . current ( ) ;
50245039 }
50255040 } catch ( e ) {
5041+ streamFailed = true ;
5042+ streamError = e ;
50265043 if ( trackRuntimeMessage ) {
50275044 messageOperation ?. fail ( {
50285045 sessionId : String ( sid ) ,
@@ -5037,9 +5054,17 @@ export default function App() {
50375054 ! ctrl . signal . aborted &&
50385055 viewSidRef . current === sid
50395056 ) {
5040- setError ( String ( e ) ) ;
5057+ setError ( e instanceof Error ? e . message : String ( e ) ) ;
50415058 }
50425059 } finally {
5060+ if (
5061+ ! ctrl . signal . aborted &&
5062+ streamFailed &&
5063+ viewSidRef . current === sid &&
5064+ text . trim ( )
5065+ ) {
5066+ setInput ( ( current ) => current . trim ( ) ? current : text ) ;
5067+ }
50435068 if ( streamAbortsRef . current . get ( sid ) === ctrl ) streamAbortsRef . current . delete ( sid ) ;
50445069 setStreaming ( sid , false ) ;
50455070 finishStreamPresentation ( sid ) ;
@@ -5100,6 +5125,7 @@ export default function App() {
51005125 streamAbortsRef . current . set ( sid , ctrl ) ;
51015126 setStreaming ( sid , true ) ;
51025127 startStreamPresentation ( sid ) ;
5128+ let streamFailed = false ;
51035129 try {
51045130 let acc = emptyAcc ( ) ;
51055131 let currentStreamAuthor = lastTurn ?. meta ?. author ?? "" ;
@@ -5108,7 +5134,7 @@ export default function App() {
51085134 let ts = Date . now ( ) / 1000 ;
51095135 let eventId = lastTurn ?. meta ?. eventId ?? "" ;
51105136 let invocationId = lastTurn ?. meta ?. invocationId ?? "" ;
5111- let streamFailed = false ;
5137+ let hasCompletedReply = false ;
51125138 for await ( const event of runSSE ( {
51135139 appName,
51145140 userId,
@@ -5145,6 +5171,12 @@ export default function App() {
51455171 const nextInvocationId = event . invocationId ?? event . invocation_id ;
51465172 if ( nextInvocationId ) invocationId = nextInvocationId ;
51475173 const blocks = [ ...currentBase , ...acc . blocks ] ;
5174+ if (
5175+ event . partial !== true &&
5176+ turnHasVisibleContent ( { role : "assistant" , blocks : acc . blocks } )
5177+ ) {
5178+ hasCompletedReply = true ;
5179+ }
51485180 setTurnsFor ( sid , ( t ) => {
51495181 const next = t . slice ( ) ;
51505182 const last = next [ next . length - 1 ] ;
@@ -5170,17 +5202,24 @@ export default function App() {
51705202 return next ;
51715203 } ) ;
51725204 }
5205+ if ( ! ctrl . signal . aborted && ! streamFailed && ! hasCompletedReply ) {
5206+ streamFailed = true ;
5207+ if ( viewSidRef . current === sid ) {
5208+ setError ( RUN_SSE_INCOMPLETE_RESPONSE_ERROR ) ;
5209+ }
5210+ }
51735211 void refreshSessions ( appName ) ;
51745212 if ( ! ctrl . signal . aborted && ! streamFailed && eventId ) {
51755213 automaticEvaluationStatusRefreshRef . current ( ) ;
51765214 }
51775215 } catch ( e ) {
5216+ streamFailed = true ;
51785217 if (
51795218 ( e as Error ) ?. name !== "AbortError" &&
51805219 ! ctrl . signal . aborted &&
51815220 viewSidRef . current === sid
51825221 ) {
5183- setError ( String ( e ) ) ;
5222+ setError ( e instanceof Error ? e . message : String ( e ) ) ;
51845223 }
51855224 } finally {
51865225 if ( streamAbortsRef . current . get ( sid ) === ctrl ) streamAbortsRef . current . delete ( sid ) ;
0 commit comments