MCPcopy Create free account
hub / github.com/Alphanimble/htmlstream / parseStreamPartLine

Function parseStreamPartLine

src/stream-parts.ts:8–28  ·  view source on GitHub ↗
(line: string)

Source from the content-addressed store, hash-verified

6}
7
8export function parseStreamPartLine(line: string): StreamPart | null {
9 const trimmed = line.trim();
10 if (!trimmed) {
11 return null;
12 }
13
14 try {
15 const part = JSON.parse(trimmed) as StreamPart;
16 if (
17 (part.kind === "reasoning" || part.kind === "content") &&
18 typeof part.delta === "string" &&
19 part.delta.length > 0
20 ) {
21 return part;
22 }
23 } catch {
24 // fall through to multi-object parse
25 }
26
27 return parseStreamPartsText(trimmed).parts[0] ?? null;
28}
29
30/** Parse one or more glued NDJSON stream objects from text. */
31export function parseStreamPartsText(text: string): {

Callers 2

reasoning.test.tsxFile · 0.90
readStreamPartsFunction · 0.85

Calls 1

parseStreamPartsTextFunction · 0.85

Tested by

no test coverage detected