pi-context 2.1.0 → 2.1.1
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/package.json +1 -1
- package/src/index.ts +32 -1
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -452,6 +452,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
452
452
|
const compactParams = CompactParams;
|
|
453
453
|
const commandCtx = CommandCtx;
|
|
454
454
|
CompactParams = null;
|
|
455
|
+
const compactTurnLeaf = sm.getLeafId();
|
|
455
456
|
|
|
456
457
|
// `agent_end` is emitted before the core Agent is actually idle. If we
|
|
457
458
|
// call pi.sendMessage({ triggerTurn: true }) inside this handler, pi still
|
|
@@ -461,6 +462,24 @@ export default function (pi: ExtensionAPI) {
|
|
|
461
462
|
setTimeout(async () => {
|
|
462
463
|
try {
|
|
463
464
|
await commandCtx.waitForIdle();
|
|
465
|
+
|
|
466
|
+
const currentLeaf = sm.getLeafId();
|
|
467
|
+
if (currentLeaf !== compactTurnLeaf) {
|
|
468
|
+
commandCtx.ui.notify("context_compact cancelled: conversation advanced before compaction completed.", "warning");
|
|
469
|
+
pi.sendMessage({
|
|
470
|
+
customType: PiContextCustomMessageType,
|
|
471
|
+
content: [
|
|
472
|
+
"context_compact cancelled: conversation advanced before the summary branch was created.",
|
|
473
|
+
"No compaction was applied; continue from the current path. If still useful, inspect timeline and retry with an updated summary.",
|
|
474
|
+
].join("\n"),
|
|
475
|
+
display: false,
|
|
476
|
+
}, {
|
|
477
|
+
triggerTurn: true,
|
|
478
|
+
deliverAs: "followUp",
|
|
479
|
+
});
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
|
|
464
483
|
const nid = sm.branchWithSummary(compactParams.tid, compactParams.enrichedMessage);
|
|
465
484
|
compactParams.nid = nid;
|
|
466
485
|
// branchWithSummary advances the leaf to the summary entry. Reset
|
|
@@ -488,7 +507,19 @@ export default function (pi: ExtensionAPI) {
|
|
|
488
507
|
deliverAs: "followUp",
|
|
489
508
|
});
|
|
490
509
|
} catch (err) {
|
|
491
|
-
|
|
510
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
511
|
+
commandCtx.ui.notify(`context_compact failed: ${message}`, "error");
|
|
512
|
+
pi.sendMessage({
|
|
513
|
+
customType: PiContextCustomMessageType,
|
|
514
|
+
content: [
|
|
515
|
+
`context_compact failed: ${message}`,
|
|
516
|
+
"No compaction was applied; continue from the current path. Retry only with a fresh timeline/summary.",
|
|
517
|
+
].join("\n"),
|
|
518
|
+
display: false,
|
|
519
|
+
}, {
|
|
520
|
+
triggerTurn: true,
|
|
521
|
+
deliverAs: "followUp",
|
|
522
|
+
});
|
|
492
523
|
}
|
|
493
524
|
}, 0);
|
|
494
525
|
});
|