MCPcopy Create free account
hub / github.com/Gan-Xing/CodexBridge / parseSseText

Function parseSseText

test/providers/codex/native_api_server.test.ts:18–33  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

16}
17
18function parseSseText(text: string): Array<{ event: string; data: any }> {
19 const blocks = text.split('\n\n').map((entry) => entry.trim()).filter(Boolean);
20 const parsed: Array<{ event: string; data: any }> = [];
21 for (const block of blocks) {
22 const eventLine = block.split('\n').find((line) => line.startsWith('event: '));
23 const dataLine = block.split('\n').find((line) => line.startsWith('data: '));
24 if (!eventLine || !dataLine || dataLine === 'data: [DONE]') {
25 continue;
26 }
27 parsed.push({
28 event: eventLine.slice(7).trim(),
29 data: JSON.parse(dataLine.slice(6)),
30 });
31 }
32 return parsed;
33}
34
35function parseSseDataText(text: string): any[] {
36 const blocks = text.split('\n\n').map((entry) => entry.trim()).filter(Boolean);

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected