feat(FN-1650): merge fusion/fn-1650

This commit is contained in:
gsxdsm
2026-04-13 15:35:08 -07:00
parent 668a6e3894
commit ebbc463dc8
7 changed files with 557 additions and 15 deletions

View File

@@ -4922,7 +4922,10 @@ export function streamChatResponse(
const lines = buffer.split("\n");
buffer = lines.pop() || "";
if (flushPendingEvent && buffer.length > 0) {
// Only push complete SSE lines (ending with \n) to lines for processing.
// Incomplete lines (no trailing \n) are intentionally left in the buffer
// to be continued by the next chunk or properly handled at stream end.
if (flushPendingEvent && buffer.length > 0 && buffer.endsWith("\n")) {
lines.push(buffer);
buffer = "";
}
@@ -4943,7 +4946,9 @@ export function streamChatResponse(
}
}
if (flushPendingEvent) {
// Flush any pending event/data at stream end.
// Only dispatch if we have both a valid event type and accumulated data.
if (flushPendingEvent && currentEvent && currentDataLines.length > 0) {
const trailingData = currentDataLines.join("\n");
dispatchEvent(currentEvent, trailingData);
currentEvent = "";