Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions sdks/typescript/packages/client/src/transform/sse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,20 @@ export const parseSSEStream = (source$: Observable<HttpEvent>): Observable<any>
/**
* Helper function to process an SSE event.
* Extracts and joins data lines, then parses the result as JSON.
* Follows the SSE spec by only processing 'data:' prefixed lines.
*
* Follows the SSE spec by processing lines starting with 'data:',
* ignoring a single space if it is present after the colon.
*
* @param eventText The raw event text to process
*/
function processSSEEvent(eventText: string) {
const lines = eventText.split("\n");
const dataLines: string[] = [];

for (const line of lines) {
if (line.startsWith("data: ")) {
// Extract data content (remove 'data: ' prefix)
dataLines.push(line.slice(6));
if (line.startsWith("data:")) {
// Remove 'data:' prefix, and optionally a single space afterwards
dataLines.push(line.slice(5).replace(/^ /, ""));
}
}

Expand Down