pulse-coder-engine 0.0.1-alpha.13 → 0.0.1-alpha.15
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 +52 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +52 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -451,6 +451,9 @@ async function loop(context, options) {
|
|
|
451
451
|
const loopHooks = options?.hooks ?? {};
|
|
452
452
|
while (true) {
|
|
453
453
|
try {
|
|
454
|
+
if (options?.abortSignal?.aborted) {
|
|
455
|
+
return "Request aborted.";
|
|
456
|
+
}
|
|
454
457
|
if (compactionAttempts < MAX_COMPACTION_ATTEMPTS) {
|
|
455
458
|
const { didCompact, newMessages } = await maybeCompactContext(context, {
|
|
456
459
|
provider: options?.provider,
|
|
@@ -464,6 +467,9 @@ async function loop(context, options) {
|
|
|
464
467
|
continue;
|
|
465
468
|
}
|
|
466
469
|
}
|
|
470
|
+
if (options?.abortSignal?.aborted) {
|
|
471
|
+
return "Request aborted.";
|
|
472
|
+
}
|
|
467
473
|
let tools = options?.tools || {};
|
|
468
474
|
let systemPrompt = options?.systemPrompt;
|
|
469
475
|
if (loopHooks.beforeLLMCall?.length) {
|
|
@@ -488,6 +494,9 @@ async function loop(context, options) {
|
|
|
488
494
|
onClarificationRequest: options?.onClarificationRequest,
|
|
489
495
|
abortSignal: options?.abortSignal
|
|
490
496
|
};
|
|
497
|
+
if (options?.abortSignal?.aborted) {
|
|
498
|
+
return "Request aborted.";
|
|
499
|
+
}
|
|
491
500
|
const result = streamTextAI(context.messages, tools, {
|
|
492
501
|
abortSignal: options?.abortSignal,
|
|
493
502
|
toolExecutionContext,
|
|
@@ -526,6 +535,9 @@ async function loop(context, options) {
|
|
|
526
535
|
await hook({ context, finishReason, text });
|
|
527
536
|
}
|
|
528
537
|
}
|
|
538
|
+
if (options?.abortSignal?.aborted) {
|
|
539
|
+
return "Request aborted.";
|
|
540
|
+
}
|
|
529
541
|
if (finishReason === "stop") {
|
|
530
542
|
if (!text) {
|
|
531
543
|
continue;
|
|
@@ -575,7 +587,7 @@ async function loop(context, options) {
|
|
|
575
587
|
}
|
|
576
588
|
if (isRetryableError(error)) {
|
|
577
589
|
const delay = Math.min(2e3 * Math.pow(2, errorCount - 1), 3e4);
|
|
578
|
-
await sleep(delay);
|
|
590
|
+
await sleep(delay, options?.abortSignal);
|
|
579
591
|
continue;
|
|
580
592
|
}
|
|
581
593
|
return `Error: ${error?.message ?? String(error)}`;
|
|
@@ -586,8 +598,34 @@ function isRetryableError(error) {
|
|
|
586
598
|
const status = error?.status ?? error?.statusCode;
|
|
587
599
|
return status === 429 || status === 500 || status === 502 || status === 503;
|
|
588
600
|
}
|
|
589
|
-
function sleep(ms) {
|
|
590
|
-
return new Promise((resolve) =>
|
|
601
|
+
function sleep(ms, abortSignal) {
|
|
602
|
+
return new Promise((resolve, reject) => {
|
|
603
|
+
if (abortSignal?.aborted) {
|
|
604
|
+
const abortError = new Error("Aborted");
|
|
605
|
+
abortError.name = "AbortError";
|
|
606
|
+
reject(abortError);
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
let timeoutId;
|
|
610
|
+
const onAbort = () => {
|
|
611
|
+
clearTimeout(timeoutId);
|
|
612
|
+
if (abortSignal) {
|
|
613
|
+
abortSignal.removeEventListener("abort", onAbort);
|
|
614
|
+
}
|
|
615
|
+
const abortError = new Error("Aborted");
|
|
616
|
+
abortError.name = "AbortError";
|
|
617
|
+
reject(abortError);
|
|
618
|
+
};
|
|
619
|
+
timeoutId = setTimeout(() => {
|
|
620
|
+
if (abortSignal) {
|
|
621
|
+
abortSignal.removeEventListener("abort", onAbort);
|
|
622
|
+
}
|
|
623
|
+
resolve();
|
|
624
|
+
}, ms);
|
|
625
|
+
if (abortSignal) {
|
|
626
|
+
abortSignal.addEventListener("abort", onAbort, { once: true });
|
|
627
|
+
}
|
|
628
|
+
});
|
|
591
629
|
}
|
|
592
630
|
|
|
593
631
|
// src/tools/read.ts
|
|
@@ -2790,6 +2828,17 @@ var Engine = class {
|
|
|
2790
2828
|
}
|
|
2791
2829
|
return resultText;
|
|
2792
2830
|
}
|
|
2831
|
+
/**
|
|
2832
|
+
* 手动触发上下文压缩
|
|
2833
|
+
* 默认复用 Engine 初始化时配置的 provider/model
|
|
2834
|
+
*/
|
|
2835
|
+
async compactContext(context, options) {
|
|
2836
|
+
return await maybeCompactContext(context, {
|
|
2837
|
+
force: options?.force,
|
|
2838
|
+
provider: options?.provider ?? this.options.llmProvider,
|
|
2839
|
+
model: options?.model ?? this.options.model
|
|
2840
|
+
});
|
|
2841
|
+
}
|
|
2793
2842
|
/**
|
|
2794
2843
|
* 获取插件状态
|
|
2795
2844
|
*/
|