MCPcopy
hub / github.com/di-sukharev/opencommit / pump

Function pump

out/cli.cjs:79144–79179  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

79142 });
79143}
79144function getResponseStream(inputStream) {
79145 const reader = inputStream.getReader();
79146 const stream4 = new ReadableStream({
79147 start(controller) {
79148 let currentText = "";
79149 return pump();
79150 function pump() {
79151 return reader.read().then(({ value, done }) => {
79152 if (done) {
79153 if (currentText.trim()) {
79154 controller.error(new GoogleGenerativeAIError("Failed to parse stream"));
79155 return;
79156 }
79157 controller.close();
79158 return;
79159 }
79160 currentText += value;
79161 let match = currentText.match(responseLineRE);
79162 let parsedResponse;
79163 while (match) {
79164 try {
79165 parsedResponse = JSON.parse(match[1]);
79166 } catch (e3) {
79167 controller.error(new GoogleGenerativeAIError(`Error parsing JSON response: "${match[1]}"`));
79168 return;
79169 }
79170 controller.enqueue(parsedResponse);
79171 currentText = currentText.substring(match[0].length);
79172 match = currentText.match(responseLineRE);
79173 }
79174 return pump();
79175 }).catch((e3) => {
79176 let err = e3;
79177 err.stack = e3.stack;
79178 if (err.name === "AbortError") {
79179 err = new GoogleGenerativeAIAbortError("Request aborted when reading from the stream");
79180 } else {
79181 err = new GoogleGenerativeAIError("Error reading from the stream");
79182 }

Callers 1

startFunction · 0.85

Calls 9

thenMethod · 0.80
trimMethod · 0.80
catchMethod · 0.45
readMethod · 0.45
errorMethod · 0.45
closeMethod · 0.45
matchMethod · 0.45
parseMethod · 0.45
enqueueMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…