(body: string)
| 34 | } |
| 35 | |
| 36 | function parseSse(body: string): Array<StreamEvent> { |
| 37 | const events: Array<StreamEvent> = [] |
| 38 | for (const line of body.split('\n')) { |
| 39 | const trimmed = line.trim() |
| 40 | if (!trimmed.startsWith('data:')) continue |
| 41 | const json = trimmed.slice('data:'.length).trim() |
| 42 | if (!json) continue |
| 43 | try { |
| 44 | const parsed: unknown = JSON.parse(json) |
| 45 | if (isStreamEvent(parsed)) events.push(parsed) |
| 46 | } catch { |
| 47 | // Ignore non-JSON keepalive lines. |
| 48 | } |
| 49 | } |
| 50 | return events |
| 51 | } |
| 52 | |
| 53 | function isStreamEvent(value: unknown): value is StreamEvent { |
| 54 | return ( |
no test coverage detected