fix: stabilize streamed message rendering

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
David Kaya
2026-03-23 23:49:12 +01:00
co-authored by Copilot
parent 8caa2d2eb4
commit 082af36255
9 changed files with 81 additions and 15 deletions
@@ -167,6 +167,7 @@ public sealed class TurnDeltaEventDto : SidecarEventDto
public string MessageId { get; init; } = string.Empty;
public string AuthorName { get; init; } = string.Empty;
public string ContentDelta { get; init; } = string.Empty;
public string? Content { get; init; }
}
public sealed class TurnCompleteEventDto : SidecarEventDto
@@ -119,6 +119,7 @@ public sealed class CopilotWorkflowRunner : ITurnWorkflowRunner
string messageId = update.Update.MessageId ?? $"{command.RequestId}-delta-{fallbackMessageIndex++}";
StreamingSegment segment = GetOrCreateSegment(segments, messageId, authorName);
segment.SetContent(StreamingTextMerger.Merge(segment.Content.ToString(), update.Update.Text));
segment.SetAuthorName(authorName);
await onDelta(new TurnDeltaEventDto
{
@@ -128,6 +129,7 @@ public sealed class CopilotWorkflowRunner : ITurnWorkflowRunner
MessageId = messageId,
AuthorName = authorName,
ContentDelta = update.Update.Text,
Content = segment.Content.ToString(),
}).ConfigureAwait(false);
}
else if (evt is ExecutorCompletedEvent completed
@@ -477,7 +479,7 @@ public sealed class CopilotWorkflowRunner : ITurnWorkflowRunner
public string MessageId { get; }
public string AuthorName { get; }
public string AuthorName { get; private set; }
public StringBuilder Content { get; } = new();
@@ -486,6 +488,11 @@ public sealed class CopilotWorkflowRunner : ITurnWorkflowRunner
Content.Clear();
Content.Append(value);
}
public void SetAuthorName(string value)
{
AuthorName = value;
}
}
private sealed class AgentBundle : IAsyncDisposable
@@ -128,6 +128,7 @@ public sealed class SidecarProtocolHostTests
MessageId = "assistant-1",
AuthorName = "Primary",
ContentDelta = "Hello",
Content = "Hello",
});
await onActivity(new AgentActivityEventDto
@@ -201,6 +202,7 @@ public sealed class SidecarProtocolHostTests
{
Assert.Equal("turn-delta", deltaEvent.GetProperty("type").GetString());
Assert.Equal("Hello", deltaEvent.GetProperty("contentDelta").GetString());
Assert.Equal("Hello", deltaEvent.GetProperty("content").GetString());
},
toolEvent =>
{