@@ -278,12 +278,12 @@ export function createLaneTextDeliverer(params: CreateLaneTextDelivererParams) {
278278 : [ text ] ;
279279
280280 const clampActiveChunkIndex = ( ) =>
281- Math . min ( lane . activeChunkIndex ?? 0 , Math . max ( 0 , chunks . length - 1 ) ) ;
281+ Math . min ( lane . activeChunkIndex , Math . max ( 0 , chunks . length - 1 ) ) ;
282282 const activeChunkIndex = clampActiveChunkIndex ( ) ;
283- const firstChunk = chunks [ activeChunkIndex ] ;
283+ const activeChunk = chunks [ activeChunkIndex ] ;
284284 const remainingChunks = chunks . slice ( activeChunkIndex + 1 ) ;
285285
286- if ( ! firstChunk || firstChunk . length > params . draftMaxChars ) {
286+ if ( ! activeChunk || activeChunk . length > params . draftMaxChars ) {
287287 return undefined ;
288288 }
289289
@@ -297,12 +297,11 @@ export function createLaneTextDeliverer(params: CreateLaneTextDelivererParams) {
297297 deliveredText : deliveredStreamTextBeforeUpdate ,
298298 finalText,
299299 } ) &&
300- deliveredStreamTextBeforeUpdate . length > firstChunk . trimEnd ( ) . length ;
300+ deliveredStreamTextBeforeUpdate . length > activeChunk . trimEnd ( ) . length ;
301301
302302 const finalizeDeliveredPrefix = async (
303303 deliveredStreamText : string ,
304304 messageId : number ,
305- suffixSourceText = activeFullText ,
306305 ) : Promise < LaneDeliveryResult > => {
307306 lane . finalized = true ;
308307 params . markDelivered ( ) ;
@@ -321,7 +320,7 @@ export function createLaneTextDeliverer(params: CreateLaneTextDelivererParams) {
321320 }
322321 }
323322 }
324- const suffix = suffixSourceText . slice ( deliveredStreamText . length ) ;
323+ const suffix = activeFullText . slice ( deliveredStreamText . length ) ;
325324 if ( suffix . trim ( ) . length > 0 ) {
326325 for ( const chunk of compactChunks ( params . splitFinalTextForStream ?.( suffix ) ?? [ ] ) ) {
327326 if ( chunk . trim ( ) . length === 0 ) {
@@ -408,18 +407,18 @@ export function createLaneTextDeliverer(params: CreateLaneTextDelivererParams) {
408407 }
409408
410409 if ( ! deliveredPrefixBeforeUpdate ) {
411- lane . lastPartialText = firstChunk ;
410+ lane . lastPartialText = activeChunk ;
412411 lane . hasStreamedMessage = true ;
413412 lane . finalized = false ;
414- stream . update ( firstChunk ) ;
413+ stream . update ( activeChunk ) ;
415414 }
416415 if ( isFinal ) {
417416 await params . stopDraftLane ( lane ) ;
418417 } else {
419418 await params . flushDraftLane ( lane ) ;
420419 }
421420 const activeChunkIndexAfterStop = isFinal ? clampActiveChunkIndex ( ) : activeChunkIndex ;
422- const activeChunkAfterStop = chunks [ activeChunkIndexAfterStop ] ?? firstChunk ;
421+ const activeChunkAfterStop = chunks [ activeChunkIndexAfterStop ] ?? activeChunk ;
423422 const remainingChunksAfterStop = chunks . slice ( activeChunkIndexAfterStop + 1 ) ;
424423
425424 const messageId = stream . messageId ( ) ;
@@ -434,14 +433,14 @@ export function createLaneTextDeliverer(params: CreateLaneTextDelivererParams) {
434433
435434 const deliveredStreamTextAfterStop = stream . lastDeliveredText ?.( ) ;
436435 const activeChunkTextAfterStop = activeChunkAfterStop . trimEnd ( ) ;
437- const retainedFirstChunkAfterStop =
436+ const retainedActiveChunkAfterStop =
438437 activeChunkIndexAfterStop !== activeChunkIndex &&
439- deliveredStreamTextAfterStop === firstChunk . trimEnd ( ) ;
438+ deliveredStreamTextAfterStop === activeChunk . trimEnd ( ) ;
440439 if (
441440 isFinal &&
442441 deliveredStreamTextAfterStop !== undefined &&
443442 deliveredStreamTextAfterStop !== activeChunkTextAfterStop &&
444- ! retainedFirstChunkAfterStop
443+ ! retainedActiveChunkAfterStop
445444 ) {
446445 if (
447446 isDeliveredPrefix ( { deliveredText : deliveredStreamTextAfterStop , finalText } ) &&
0 commit comments