MCPcopy Create free account
hub / github.com/OperationT00/T-Code / parseSse

Function parseSse

clients/t-code-cli/src/runtime-client.ts:114–132  ·  view source on GitHub ↗
(body: string)

Source from the content-addressed store, hash-verified

112}
113
114export function parseSse(body: string): RuntimeEvent[] {
115 return body
116 .split(/\r?\n\r?\n/)
117 .map(block => block.trim())
118 .filter(Boolean)
119 .map(block => {
120 let id = 0;
121 let type = "message";
122 const data: string[] = [];
123 for (const line of block.split(/\r?\n/)) {
124 if (line.startsWith("id:")) id = Number(line.slice(3).trim());
125 if (line.startsWith("event:")) type = line.slice(6).trim();
126 if (line.startsWith("data:")) data.push(line.slice(5).trimStart());
127 }
128 const payload = JSON.parse(data.join("\n")) as Record<string, unknown>;
129 const schemaVersion = typeof payload.schema_version === "number" ? payload.schema_version : 1;
130 return { id, type, schemaVersion, data: payload };
131 });
132}
133
134function isRecord(value: unknown): value is Record<string, unknown> {
135 return typeof value === "object" && value !== null;

Callers 2

eventsMethod · 0.85

Calls 2

pushMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected