MCPcopy
hub / github.com/continuedev/continue / streamJSON

Function streamJSON

packages/fetch/src/stream.ts:152–169  ·  view source on GitHub ↗
(response: Response)

Source from the content-addressed store, hash-verified

150}
151
152export async function* streamJSON(response: Response): AsyncGenerator<any> {
153 let buffer = "";
154 for await (const value of streamResponse(response)) {
155 buffer += value;
156
157 let position;
158 while ((position = buffer.indexOf("\n")) >= 0) {
159 const line = buffer.slice(0, position);
160 try {
161 const data = JSON.parse(line);
162 yield data;
163 } catch (e) {
164 throw new Error(`Malformed JSON sent from server: ${line}`);
165 }
166 buffer = buffer.slice(position + 1);
167 }
168 }
169}

Callers 1

chatCompletionStreamMethod · 0.90

Calls 1

streamResponseFunction · 0.85

Tested by

no test coverage detected