@@ -2,7 +2,38 @@ import { useEffect, useRef, useState } from 'react';
22import { useTraceContext } from '../../context/TraceContext' ;
33import { SessionCard } from './SessionCard' ;
44import { config } from '../../config' ;
5- import type { LiveSession , StreamingInvocation } from '../../lib/types' ;
5+ import type { ConversationElement , LiveSession , StreamingInvocation } from '../../lib/types' ;
6+
7+ function invocationsToElements ( invocations : StreamingInvocation [ ] ) : ConversationElement [ ] {
8+ return invocations . flatMap ( ( inv , idx ) => {
9+ const elements : ConversationElement [ ] = [ ] ;
10+ if ( inv . userText ) {
11+ elements . push ( {
12+ type : 'user_input' ,
13+ timestamp : idx * 3 ,
14+ invocationId : inv . invocationId ,
15+ data : { text : inv . userText } ,
16+ } ) ;
17+ }
18+ for ( const tc of inv . toolCalls || [ ] ) {
19+ elements . push ( {
20+ type : 'tool_call' ,
21+ timestamp : idx * 3 + 1 ,
22+ invocationId : inv . invocationId ,
23+ data : { toolCall : tc } ,
24+ } ) ;
25+ }
26+ if ( inv . agentText ) {
27+ elements . push ( {
28+ type : 'agent_response' ,
29+ timestamp : idx * 3 + 2 ,
30+ invocationId : inv . invocationId ,
31+ data : { text : inv . agentText } ,
32+ } ) ;
33+ }
34+ return elements ;
35+ } ) ;
36+ }
637
738export function LiveStreamingView ( ) {
839 const { state, actions } = useTraceContext ( ) ;
@@ -67,7 +98,9 @@ export function LiveStreamingView() {
6798 status : s . isComplete ? 'complete' : 'active' ,
6899 metadata : ( s . metadata ?? { } ) as Record < string , string > ,
69100 invocations : s . invocations ,
70- liveElements : [ ] ,
101+ liveElements : s . invocations ?. length
102+ ? invocationsToElements ( s . invocations )
103+ : [ ] ,
71104 liveStats : { totalInputTokens : 0 , totalOutputTokens : 0 } ,
72105 startedAt : s . startedAt ,
73106 } ) ;
@@ -272,7 +305,9 @@ export function LiveStreamingView() {
272305 status : 'complete' ,
273306 metadata : { } ,
274307 invocations : data . invocations ,
275- liveElements : [ ] ,
308+ liveElements : data . invocations ?. length
309+ ? invocationsToElements ( data . invocations )
310+ : [ ] ,
276311 liveStats : {
277312 totalInputTokens : 0 ,
278313 totalOutputTokens : 0 ,
@@ -284,6 +319,9 @@ export function LiveStreamingView() {
284319 ...session ,
285320 status : 'complete' ,
286321 invocations : data . invocations ,
322+ liveElements : data . invocations ?. length
323+ ? invocationsToElements ( data . invocations )
324+ : session . liveElements ,
287325 } ) ;
288326 }
289327
0 commit comments