@@ -356,6 +356,56 @@ internal class StreamFrameExtTest {
356356 )
357357 }
358358
359+ @Test
360+ fun testToMessageResponsesSkipsEmptyTextCompleteFrames () {
361+ val frames = listOf (
362+ StreamFrame .TextComplete (" Hello" , index = 0 ),
363+ StreamFrame .ToolCallComplete (" call_1" , " tool" , " {}" , index = 1 ),
364+ StreamFrame .TextDelta (" " , index = 2 ),
365+ StreamFrame .TextComplete (" " , index = 2 ),
366+ StreamFrame .ToolCallComplete (" call_2" , " otherTool" , """ {"query":"test"}""" , index = 3 ),
367+ StreamFrame .End (" tool_calls" , ResponseMetaInfo .Empty )
368+ )
369+
370+ val messages = frames.toMessageResponses()
371+
372+ assertEquals(
373+ listOf (
374+ Message .Assistant (
375+ parts = listOf (ContentPart .Text (" Hello" )),
376+ finishReason = " tool_calls" ,
377+ metaInfo = ResponseMetaInfo .Empty
378+ ),
379+ Message .Tool .Call (
380+ id = " call_1" ,
381+ tool = " tool" ,
382+ content = " {}" ,
383+ metaInfo = ResponseMetaInfo .Empty
384+ ),
385+ Message .Tool .Call (
386+ id = " call_2" ,
387+ tool = " otherTool" ,
388+ content = """ {"query":"test"}""" ,
389+ metaInfo = ResponseMetaInfo .Empty
390+ )
391+ ),
392+ messages
393+ )
394+ }
395+
396+ @Test
397+ fun testToMessageResponsesSkipsEmptyOnlyTextCompleteFrames () {
398+ val frames = listOf (
399+ StreamFrame .TextDelta (" " ),
400+ StreamFrame .TextComplete (" " ),
401+ StreamFrame .End (" stop" , ResponseMetaInfo .Empty )
402+ )
403+
404+ val messages = frames.toMessageResponses()
405+
406+ assertEquals(emptyList(), messages)
407+ }
408+
359409 @Test
360410 fun testToMessageResponsesWithEmptyFrames () {
361411 val frames = emptyList<StreamFrame >()
0 commit comments