From b837a5830a6124ae08a56efb119ccad07d10e1d4 Mon Sep 17 00:00:00 2001 From: iseki Date: Sun, 19 Jan 2025 06:45:42 +0800 Subject: [PATCH] fix(stream-text): ensure SSE handling conforms to the spec --- packages/stream-text/src/index.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/stream-text/src/index.ts b/packages/stream-text/src/index.ts index f9e1475..af21c92 100644 --- a/packages/stream-text/src/index.ts +++ b/packages/stream-text/src/index.ts @@ -44,7 +44,7 @@ export interface StreamTextResult { usage?: Usage } -const chunkHeaderPrefix = 'data:' +const chunkHeaderPrefix = /^data(?:: ?)?/ /** * @experimental WIP, does not support function calling (tools). @@ -79,14 +79,10 @@ export const streamText = async (options: StreamTextOptions): Promise 0 && content[0] === ' ' ? content.slice(1) : content) - } - else { - break // event ended, dispatch + dataLines.push(line.replace(chunkHeaderPrefix, '')) } }