@@ -487,6 +487,18 @@ ChatTimelineState Apply(
487487 if ( ! before . Contains ( entry . Id ) && ! metadata . ContainsKey ( entry . Id ) )
488488 metadata [ entry . Id ] = entryMetadata ;
489489 }
490+ if ( entryMetadata . AssistantContent is not null &&
491+ next . ActiveAssistantId is { } assistantId &&
492+ metadata . TryGetValue ( assistantId , out var existingMetadata ) )
493+ {
494+ metadata [ assistantId ] = existingMetadata with
495+ {
496+ AssistantContent =
497+ ChatAssistantContentProjector . MergeLiveUpdate (
498+ existingMetadata . AssistantContent ,
499+ entryMetadata . AssistantContent ) ,
500+ } ;
501+ }
490502 }
491503 return next ;
492504 }
@@ -504,6 +516,10 @@ ChatTimelineState Apply(
504516 }
505517
506518 var role = message . Role ? . ToLowerInvariant ( ) ?? string . Empty ;
519+ var rawText = replayPart . Text ;
520+ var userProjection = role == "user"
521+ ? GatewayMediaMessageProjection . Project ( rawText )
522+ : null ;
507523 var entryMetadata = new ChatEntryMetadata (
508524 message . Ts > 0
509525 ? DateTimeOffset . FromUnixTimeMilliseconds ( message . Ts ) . ToLocalTime ( )
@@ -517,17 +533,37 @@ ChatTimelineState Apply(
517533 OpenClawSeq : message . OpenClawSeq ,
518534 OpenClawKind : message . OpenClawKind ,
519535 CompactionTokensBefore : message . CompactionTokensBefore ,
520- CompactionTokensAfter : message . CompactionTokensAfter ) ;
536+ CompactionTokensAfter : message . CompactionTokensAfter ,
537+ AssistantContent : role == "assistant"
538+ ? ChatAssistantContentProjector . Project (
539+ replayPart . AssistantContentParts )
540+ : null ) ;
521541 var text = ChatContentFormatting . TruncateForChatEntry (
522542 ChatMetadataStore . EscapeUntrustedAttachmentMarkerLines (
523- replayPart . Text ) ) ;
524- if ( role == "user" )
525- text = ChatMetadataStore . RehydrateAttachmentMarkers (
526- attachmentMatcher ,
527- text ,
543+ userProjection ? . HasMediaEnvelope == true
544+ ? userProjection . ReconciliationText
545+ : rawText ) ) ;
546+ if ( userProjection is not null )
547+ {
548+ var cachedAttachment = attachmentMatcher . TryMatch (
549+ userProjection . ReconciliationText ,
550+ userProjection . AttachmentCorrelationSignature ,
528551 message . Ts ) ;
552+ var attachmentPresentations = cachedAttachment is not null
553+ ? ChatMetadataStore . CreatePersistedLocalPresentations (
554+ cachedAttachment . Attachments )
555+ : userProjection . Attachments ;
556+ entryMetadata = entryMetadata with
557+ {
558+ Attachments = attachmentPresentations ,
559+ } ;
560+ }
529561 var hasStructuredToolContent =
530562 replayPart . ToolContent . Count > 0 ;
563+ var hasUserAttachments =
564+ entryMetadata . Attachments is { Count : > 0 } ;
565+ var hasAssistantMedia =
566+ entryMetadata . AssistantContent is { Media . Count : > 0 } ;
531567
532568 if ( role == "user" &&
533569 _persistence . IsMessageAborted (
@@ -564,12 +600,16 @@ ChatTimelineState Apply(
564600 }
565601
566602 if ( string . IsNullOrEmpty ( text ) &&
567- ! hasStructuredToolContent )
603+ ! hasStructuredToolContent &&
604+ ! hasUserAttachments &&
605+ ! hasAssistantMedia )
568606 {
569607 continue ;
570608 }
571609
572- if ( ! string . IsNullOrEmpty ( text ) )
610+ if ( ! string . IsNullOrEmpty ( text ) ||
611+ ( role == "user" && hasUserAttachments ) ||
612+ ( role == "assistant" && hasAssistantMedia ) )
573613 {
574614 switch ( role )
575615 {
0 commit comments