Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .sdk-source.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schemaVersion": 1,
"sourceCommit": "dcb64b2f48febb318d116d7abe5e12d51cb2913c",
"sourceCommit": "60be0cdcc0ccb8cbc28c3840c0a3980370b41f5b",
"contract": "contracts/2026.07/public-sdk-contract.json",
"packages": [
"typescript"
Expand Down
4 changes: 2 additions & 2 deletions typescript/src/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async function* parseSSE(response: Response): AsyncGenerator<SSEEvent> {
`SSE frame exceeds the ${MAX_SSE_FRAME_BYTES.toLocaleString("en-US")}-byte limit.`
);
}
const lines = buffer.split("\n");
const lines = buffer.split(/\r?\n/);
// Keep the last potentially incomplete line in the buffer
buffer = lines.pop() ?? "";

Expand All @@ -80,7 +80,7 @@ async function* parseSSE(response: Response): AsyncGenerator<SSEEvent> {
`SSE frame exceeds the ${MAX_SSE_FRAME_BYTES.toLocaleString("en-US")}-byte limit.`
);
}
if (line === "") {
if (line === "" || line === "\r") {
// Blank line = end of event
if (currentData.length > 0) {
yield {
Expand Down
15 changes: 15 additions & 0 deletions typescript/tests/streaming.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,21 @@ describe("ChatStream", () => {
]);
});

test("handles CRLF split between network chunks", async () => {
const response = chunkedSSEResponse([
"event: chunk\r",
"\ndata: \"Hello\"\r",
"\n\r",
"\nevent: done\r\ndata: \r\n\r\n",
]);
const events = [];
for await (const event of new ChatStream(response)) events.push(event);
expect(events).toEqual([
{ type: "chunk", content: "Hello" },
{ type: "done" },
]);
});

test("ignores comment lines", async () => {
const response = sseResponse(
`: this is a comment\nevent: chunk\ndata: "Hi"\n\nevent: done\ndata: \n\n`
Expand Down