pulse-coder-engine 0.0.1-alpha.13 → 0.0.1-alpha.14
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/built-in/index.cjs +41 -3
- package/dist/built-in/index.cjs.map +1 -1
- package/dist/built-in/index.js +41 -3
- package/dist/built-in/index.js.map +1 -1
- package/dist/index.cjs +41 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +41 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/built-in/index.js
CHANGED
|
@@ -1458,6 +1458,9 @@ async function loop(context, options) {
|
|
|
1458
1458
|
const loopHooks = options?.hooks ?? {};
|
|
1459
1459
|
while (true) {
|
|
1460
1460
|
try {
|
|
1461
|
+
if (options?.abortSignal?.aborted) {
|
|
1462
|
+
return "Request aborted.";
|
|
1463
|
+
}
|
|
1461
1464
|
if (compactionAttempts < MAX_COMPACTION_ATTEMPTS) {
|
|
1462
1465
|
const { didCompact, newMessages } = await maybeCompactContext(context, {
|
|
1463
1466
|
provider: options?.provider,
|
|
@@ -1471,6 +1474,9 @@ async function loop(context, options) {
|
|
|
1471
1474
|
continue;
|
|
1472
1475
|
}
|
|
1473
1476
|
}
|
|
1477
|
+
if (options?.abortSignal?.aborted) {
|
|
1478
|
+
return "Request aborted.";
|
|
1479
|
+
}
|
|
1474
1480
|
let tools = options?.tools || {};
|
|
1475
1481
|
let systemPrompt = options?.systemPrompt;
|
|
1476
1482
|
if (loopHooks.beforeLLMCall?.length) {
|
|
@@ -1495,6 +1501,9 @@ async function loop(context, options) {
|
|
|
1495
1501
|
onClarificationRequest: options?.onClarificationRequest,
|
|
1496
1502
|
abortSignal: options?.abortSignal
|
|
1497
1503
|
};
|
|
1504
|
+
if (options?.abortSignal?.aborted) {
|
|
1505
|
+
return "Request aborted.";
|
|
1506
|
+
}
|
|
1498
1507
|
const result = streamTextAI(context.messages, tools, {
|
|
1499
1508
|
abortSignal: options?.abortSignal,
|
|
1500
1509
|
toolExecutionContext,
|
|
@@ -1533,6 +1542,9 @@ async function loop(context, options) {
|
|
|
1533
1542
|
await hook({ context, finishReason, text });
|
|
1534
1543
|
}
|
|
1535
1544
|
}
|
|
1545
|
+
if (options?.abortSignal?.aborted) {
|
|
1546
|
+
return "Request aborted.";
|
|
1547
|
+
}
|
|
1536
1548
|
if (finishReason === "stop") {
|
|
1537
1549
|
if (!text) {
|
|
1538
1550
|
continue;
|
|
@@ -1582,7 +1594,7 @@ async function loop(context, options) {
|
|
|
1582
1594
|
}
|
|
1583
1595
|
if (isRetryableError(error)) {
|
|
1584
1596
|
const delay = Math.min(2e3 * Math.pow(2, errorCount - 1), 3e4);
|
|
1585
|
-
await sleep(delay);
|
|
1597
|
+
await sleep(delay, options?.abortSignal);
|
|
1586
1598
|
continue;
|
|
1587
1599
|
}
|
|
1588
1600
|
return `Error: ${error?.message ?? String(error)}`;
|
|
@@ -1593,8 +1605,34 @@ function isRetryableError(error) {
|
|
|
1593
1605
|
const status = error?.status ?? error?.statusCode;
|
|
1594
1606
|
return status === 429 || status === 500 || status === 502 || status === 503;
|
|
1595
1607
|
}
|
|
1596
|
-
function sleep(ms) {
|
|
1597
|
-
return new Promise((resolve) =>
|
|
1608
|
+
function sleep(ms, abortSignal) {
|
|
1609
|
+
return new Promise((resolve, reject) => {
|
|
1610
|
+
if (abortSignal?.aborted) {
|
|
1611
|
+
const abortError = new Error("Aborted");
|
|
1612
|
+
abortError.name = "AbortError";
|
|
1613
|
+
reject(abortError);
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
let timeoutId;
|
|
1617
|
+
const onAbort = () => {
|
|
1618
|
+
clearTimeout(timeoutId);
|
|
1619
|
+
if (abortSignal) {
|
|
1620
|
+
abortSignal.removeEventListener("abort", onAbort);
|
|
1621
|
+
}
|
|
1622
|
+
const abortError = new Error("Aborted");
|
|
1623
|
+
abortError.name = "AbortError";
|
|
1624
|
+
reject(abortError);
|
|
1625
|
+
};
|
|
1626
|
+
timeoutId = setTimeout(() => {
|
|
1627
|
+
if (abortSignal) {
|
|
1628
|
+
abortSignal.removeEventListener("abort", onAbort);
|
|
1629
|
+
}
|
|
1630
|
+
resolve();
|
|
1631
|
+
}, ms);
|
|
1632
|
+
if (abortSignal) {
|
|
1633
|
+
abortSignal.addEventListener("abort", onAbort, { once: true });
|
|
1634
|
+
}
|
|
1635
|
+
});
|
|
1598
1636
|
}
|
|
1599
1637
|
|
|
1600
1638
|
// src/tools/read.ts
|