@@ -65,6 +65,8 @@ export class CWCTelemetryHelper {
6565 private triggerEventsStorage : TriggerEventsStorage
6666 private responseStreamStartTime : Map < string , number > = new Map ( )
6767 private responseStreamTotalTime : Map < string , number > = new Map ( )
68+ private conversationStreamStartTime : Map < string , number > = new Map ( )
69+ private conversationStreamTotalTime : Map < string , number > = new Map ( )
6870 private responseStreamTimeForChunks : Map < string , number [ ] > = new Map ( )
6971 private responseWithProjectContext : Map < string , boolean > = new Map ( )
7072
@@ -447,7 +449,9 @@ export class CWCTelemetryHelper {
447449 this . getTimeBetweenChunks ( message . tabID , this . responseStreamTimeForChunks )
448450 ) ,
449451 cwsprChatFullResponseLatency : this . responseStreamTotalTime . get ( message . tabID ) ?? 0 ,
450- cwsprTimeToFirstDisplay : this . getFirstDisplayTime ( tabID , startTime ) ,
452+ cwsprChatTimeToFirstDisplay : this . getFirstDisplayTime ( tabID , startTime ) ,
453+ cwsprChatTimeFirstUsableChunk : this . getFirstUsableChunkTime ( message . tabID ) ?? 0 ,
454+ cwsprChatFullServerResponseLatency : this . conversationStreamTotalTime . get ( message . tabID ) ?? 0 ,
451455 cwsprChatTimeBetweenDisplays : JSON . stringify ( this . getTimeBetweenChunks ( tabID , this . displayTimeForChunks ) ) ,
452456 cwsprChatFullDisplayLatency : fullDisplayLatency ,
453457 cwsprChatRequestLength : triggerPayload . message ?. length ?? 0 ,
@@ -549,6 +553,10 @@ export class CWCTelemetryHelper {
549553 this . responseWithProjectContext . set ( messageId , true )
550554 }
551555
556+ public setConversationStreamStartTime ( tabID : string ) {
557+ this . conversationStreamStartTime . set ( tabID , performance . now ( ) )
558+ }
559+
552560 private getResponseStreamTimeToFirstChunk ( tabID : string ) : number {
553561 const chunkTimes = this . responseStreamTimeForChunks . get ( tabID ) ?? [ 0 , 0 ]
554562 if ( chunkTimes . length === 1 ) {
@@ -568,6 +576,13 @@ export class CWCTelemetryHelper {
568576 return Math . round ( chunkTimes [ 0 ] - startTime )
569577 }
570578
579+ private getFirstUsableChunkTime ( tabID : string ) {
580+ const startTime = this . conversationStreamStartTime . get ( tabID ) ?? 0
581+ const chunkTimes = this . responseStreamTimeForChunks . get ( tabID ) ?? [ 0 , 0 ]
582+ // first chunk is the start time, we use the second because thats the first actual usable chunk time
583+ return Math . round ( chunkTimes [ 1 ] - startTime )
584+ }
585+
571586 private getTimeBetweenChunks ( tabID : string , chunks : Map < string , number [ ] > ) : number [ ] {
572587 try {
573588 const chunkDeltaTimes : number [ ] = [ ]
@@ -584,8 +599,13 @@ export class CWCTelemetryHelper {
584599 }
585600
586601 public setResponseStreamTotalTime ( tabID : string ) {
587- const totalTime = performance . now ( ) - ( this . responseStreamStartTime . get ( tabID ) ?? 0 )
588- this . responseStreamTotalTime . set ( tabID , Math . round ( totalTime ) )
602+ // time from when the requests started streaming until the end of the stream
603+ const totalStreamingTime = performance . now ( ) - ( this . responseStreamStartTime . get ( tabID ) ?? 0 )
604+ this . responseStreamTotalTime . set ( tabID , Math . round ( totalStreamingTime ) )
605+
606+ // time from the initial server request, including creating the conversation id, until the end of the stream
607+ const totalConversationTime = performance . now ( ) - ( this . conversationStreamStartTime . get ( tabID ) ?? 0 )
608+ this . conversationStreamTotalTime . set ( tabID , Math . round ( totalConversationTime ) )
589609 }
590610
591611 public getConversationId ( tabID : string ) : string | undefined {
0 commit comments