(line: string)
| 109 | } |
| 110 | |
| 111 | function parseSseLine(line: string): { done: boolean; data: any } { |
| 112 | if (line.startsWith("data:[DONE]") || line.startsWith("data: [DONE]")) { |
| 113 | return { done: true, data: undefined }; |
| 114 | } |
| 115 | if (line.startsWith("data:")) { |
| 116 | return { done: false, data: parseDataLine(line) }; |
| 117 | } |
| 118 | if (line.startsWith(": ping")) { |
| 119 | return { done: true, data: undefined }; |
| 120 | } |
| 121 | return { done: false, data: undefined }; |
| 122 | } |
| 123 | |
| 124 | export async function* streamSse(response: Response): AsyncGenerator<any> { |
| 125 | let buffer = ""; |
no test coverage detected