@@ -8,7 +8,8 @@ public static class TestHelper
88{
99 public static async Task < AssistantMessageEvent ? > GetFinalAssistantMessageAsync (
1010 CopilotSession session ,
11- TimeSpan ? timeout = null )
11+ TimeSpan ? timeout = null ,
12+ bool alreadyIdle = false )
1213 {
1314 var tcs = new TaskCompletionSource < AssistantMessageEvent > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
1415 using var cts = new CancellationTokenSource ( timeout ?? TimeSpan . FromSeconds ( 60 ) ) ;
@@ -42,7 +43,7 @@ async void CheckExistingMessages()
4243 {
4344 try
4445 {
45- var existing = await GetExistingFinalResponseAsync ( session ) ;
46+ var existing = await GetExistingFinalResponseAsync ( session , alreadyIdle ) ;
4647 if ( existing != null ) tcs . TrySetResult ( existing ) ;
4748 }
4849 catch ( Exception ex )
@@ -52,7 +53,7 @@ async void CheckExistingMessages()
5253 }
5354 }
5455
55- private static async Task < AssistantMessageEvent ? > GetExistingFinalResponseAsync ( CopilotSession session )
56+ private static async Task < AssistantMessageEvent ? > GetExistingFinalResponseAsync ( CopilotSession session , bool alreadyIdle )
5657 {
5758 var messages = ( await session . GetMessagesAsync ( ) ) . ToList ( ) ;
5859
@@ -62,7 +63,7 @@ async void CheckExistingMessages()
6263 var error = currentTurn . OfType < SessionErrorEvent > ( ) . FirstOrDefault ( ) ;
6364 if ( error != null ) throw new Exception ( error . Data . Message ?? "session error" ) ;
6465
65- var idleIdx = currentTurn . FindIndex ( m => m is SessionIdleEvent ) ;
66+ var idleIdx = alreadyIdle ? currentTurn . Count : currentTurn . FindIndex ( m => m is SessionIdleEvent ) ;
6667 if ( idleIdx == - 1 ) return null ;
6768
6869 for ( var i = idleIdx - 1 ; i >= 0 ; i -- )
0 commit comments