MCPcopy Create free account
hub / github.com/OpenPipe/OpenPipe / processStream

Function processStream

client-libs/typescript/src/openai/http.test.ts:63–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

61 let chunkCount = 0;
62
63 async function processStream() {
64 let done, value;
65 while (true) {
66 ({ done, value } = await reader.read());
67 if (done) break;
68 chunkCount++;
69
70 let chunkText = decoder.decode(value, { stream: true }).trim();
71 // Process each potentially concatenated chunk by splitting on the "data: " prefix
72 const splitChunks = chunkText.split(/\ndata: /);
73 splitChunks.forEach((splitChunk, index) => {
74 // For the first chunk only, remove "data: " if it's at the very start of the text
75 if (index === 0 && splitChunk.startsWith("data: ")) {
76 splitChunk = splitChunk.substring(5);
77 }
78
79 const chunkJson = JSON.parse(splitChunk);
80
81 validateOpenAIChunkSignature(chunkJson);
82 });
83 }
84 }
85
86 await processStream();
87 expect(chunkCount).toBeGreaterThan(1);

Callers 1

http.test.tsFile · 0.85

Calls 1

Tested by

no test coverage detected