copilot-api-plus 1.0.35 → 1.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +14 -7
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -2315,6 +2315,18 @@ function transformStreamResponse(response, model) {
|
|
|
2315
2315
|
} });
|
|
2316
2316
|
}
|
|
2317
2317
|
/**
|
|
2318
|
+
* Process candidate parts and handle finish
|
|
2319
|
+
*/
|
|
2320
|
+
function processCandidate(candidate, state$1, emit) {
|
|
2321
|
+
const parts = candidate?.content?.parts ?? [];
|
|
2322
|
+
for (const part of parts) processPart(part, state$1, emit);
|
|
2323
|
+
if (candidate?.finishReason === "STOP") {
|
|
2324
|
+
handleFinish(state$1, emit);
|
|
2325
|
+
return true;
|
|
2326
|
+
}
|
|
2327
|
+
return false;
|
|
2328
|
+
}
|
|
2329
|
+
/**
|
|
2318
2330
|
* Process the stream and emit events
|
|
2319
2331
|
*/
|
|
2320
2332
|
async function processStream(reader, decoder, state$1, controller) {
|
|
@@ -2323,8 +2335,7 @@ async function processStream(reader, decoder, state$1, controller) {
|
|
|
2323
2335
|
while (!finished) {
|
|
2324
2336
|
const { done, value } = await reader.read();
|
|
2325
2337
|
if (done) break;
|
|
2326
|
-
const
|
|
2327
|
-
const lines = processChunk(chunk, state$1);
|
|
2338
|
+
const lines = processChunk(decoder.decode(value, { stream: true }), state$1);
|
|
2328
2339
|
for (const line of lines) {
|
|
2329
2340
|
if (finished) break;
|
|
2330
2341
|
const data = parseSSELine(line);
|
|
@@ -2334,11 +2345,7 @@ async function processStream(reader, decoder, state$1, controller) {
|
|
|
2334
2345
|
state$1.inputTokens = usage.promptTokenCount ?? state$1.inputTokens;
|
|
2335
2346
|
state$1.outputTokens = usage.candidatesTokenCount ?? state$1.outputTokens;
|
|
2336
2347
|
}
|
|
2337
|
-
|
|
2338
|
-
const parts = candidate?.content?.parts ?? [];
|
|
2339
|
-
for (const part of parts) processPart(part, state$1, emit);
|
|
2340
|
-
if (candidate?.finishReason === "STOP") {
|
|
2341
|
-
handleFinish(state$1, emit);
|
|
2348
|
+
if (candidates[0] && processCandidate(candidates[0], state$1, emit)) {
|
|
2342
2349
|
finished = true;
|
|
2343
2350
|
break;
|
|
2344
2351
|
}
|