mirror of
https://github.com/davidkaya/aryx.git
synced 2026-11-15 22:52:04 +01:00
fix: stabilize streamed message rendering
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
1 parent
8caa2d2eb4
commit
082af36255
9 files changed
+81
-15
No files matched your search
@@ -418,7 +418,13 @@ export function ChatPane({
|
||||
: `rounded-xl border px-4 py-3 text-[14px] leading-relaxed text-zinc-200 ${assistantContainerClass}`
|
||||
}
|
||||
>
|
||||
<MarkdownContent content={message.content} />
|
||||
{!isUser && message.pending ? (
|
||||
<div className="whitespace-pre-wrap break-words text-[14px] leading-relaxed text-zinc-200">
|
||||
{message.content}
|
||||
</div>
|
||||
) : (
|
||||
<MarkdownContent content={message.content} />
|
||||
)}
|
||||
{message.pending && message.content && (
|
||||
<span className="mt-1 inline-block h-4 w-[2px] animate-pulse rounded-sm bg-zinc-400" />
|
||||
)}
|
||||
|
||||
@@ -77,17 +77,18 @@ function applyErrorEvent(session: SessionRecord, event: SessionEventRecord): Ses
|
||||
}
|
||||
|
||||
function applyMessageDeltaEvent(session: SessionRecord, event: SessionEventRecord): SessionRecord {
|
||||
if (!event.messageId || event.contentDelta === undefined) {
|
||||
if (!event.messageId || (event.content === undefined && event.contentDelta === undefined)) {
|
||||
return session;
|
||||
}
|
||||
|
||||
const resolvedContent = event.content ?? event.contentDelta ?? '';
|
||||
const messageIndex = session.messages.findIndex((message) => message.id === event.messageId);
|
||||
if (messageIndex >= 0) {
|
||||
const existing = session.messages[messageIndex];
|
||||
const nextMessage: ChatMessageRecord = {
|
||||
...existing,
|
||||
authorName: event.authorName ?? existing.authorName,
|
||||
content: mergeStreamingText(existing.content, event.contentDelta),
|
||||
content: event.content ?? mergeStreamingText(existing.content, resolvedContent),
|
||||
pending: true,
|
||||
};
|
||||
|
||||
@@ -112,14 +113,14 @@ function applyMessageDeltaEvent(session: SessionRecord, event: SessionEventRecor
|
||||
...session,
|
||||
messages: [
|
||||
...session.messages,
|
||||
{
|
||||
id: event.messageId,
|
||||
role: 'assistant',
|
||||
authorName: event.authorName ?? 'assistant',
|
||||
content: event.contentDelta,
|
||||
createdAt: event.occurredAt,
|
||||
pending: true,
|
||||
},
|
||||
{
|
||||
id: event.messageId,
|
||||
role: 'assistant',
|
||||
authorName: event.authorName ?? 'assistant',
|
||||
content: resolvedContent,
|
||||
createdAt: event.occurredAt,
|
||||
pending: true,
|
||||
},
|
||||
],
|
||||
updatedAt: event.occurredAt,
|
||||
};
|
||||
@@ -139,10 +140,15 @@ function applyMessageCompleteEvent(session: SessionRecord, event: SessionEventRe
|
||||
const nextMessage: ChatMessageRecord = {
|
||||
...existing,
|
||||
authorName: event.authorName ?? existing.authorName,
|
||||
content: event.content ?? existing.content,
|
||||
pending: false,
|
||||
};
|
||||
|
||||
if (nextMessage.authorName === existing.authorName && !existing.pending) {
|
||||
if (
|
||||
nextMessage.authorName === existing.authorName
|
||||
&& nextMessage.content === existing.content
|
||||
&& !existing.pending
|
||||
) {
|
||||
return session;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user