@monotykamary/pi-retry 0.6.5 → 0.6.6
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/README.md +1 -0
- package/package.json +1 -1
- package/retry.ts +12 -0
package/README.md
CHANGED
|
@@ -138,6 +138,7 @@ const BACKOFF_MULTIPLIER = 2; // Double each time
|
|
|
138
138
|
5. **Retry or continue (both invisible)** — Wait (exponential backoff for errors), then trigger a new turn via `pi.sendMessage()` with `customType`, `display: false`, and `triggerTurn: true`
|
|
139
139
|
6. **Context cleanup** — The `context` event strips all custom-type triggers before the LLM sees them (insurance against custom `convertToLlm` overrides)
|
|
140
140
|
7. **Indefinite continuation** — Max_tokens auto-continues are uncapped; each continuation produces valid output and the model naturally terminates when done
|
|
141
|
+
8. **Lifecycle exposure** — Emits `pi-retry:started`, `pi-retry:completed`, and `pi-retry:cancelled` on Pi's shared extension event bus with a matching `retryId`, allowing status integrations to suppress intermediate completion signals
|
|
141
142
|
|
|
142
143
|
The pi's built-in `transform-messages` already strips aborted/errored assistant messages from the LLM context, so the model never sees the failed attempts.
|
|
143
144
|
|
package/package.json
CHANGED
package/retry.ts
CHANGED
|
@@ -21,6 +21,10 @@ import {
|
|
|
21
21
|
CONTINUATION_CUSTOM_TYPE,
|
|
22
22
|
} from "./src/index.js";
|
|
23
23
|
|
|
24
|
+
const RETRY_STARTED_EVENT = "pi-retry:started";
|
|
25
|
+
const RETRY_COMPLETED_EVENT = "pi-retry:completed";
|
|
26
|
+
const RETRY_CANCELLED_EVENT = "pi-retry:cancelled";
|
|
27
|
+
|
|
24
28
|
/**
|
|
25
29
|
* Unified retry extension — retries EVERY error by default.
|
|
26
30
|
*
|
|
@@ -111,6 +115,7 @@ let _continueInProgress = false;
|
|
|
111
115
|
let _continueGeneration: number | null = null;
|
|
112
116
|
let _continueInputGeneration: number | null = null;
|
|
113
117
|
let _inputGeneration = 0;
|
|
118
|
+
let _retryLifecycleId = 0;
|
|
114
119
|
|
|
115
120
|
// Session generation counter: incremented on every session_start.
|
|
116
121
|
// The retry loop captures the current generation when it starts and exits
|
|
@@ -520,6 +525,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
520
525
|
// Guard: mutex — if a previous continue is still in-flight, skip
|
|
521
526
|
if (_continueInProgress) return;
|
|
522
527
|
_continueInProgress = true;
|
|
528
|
+
const retryLifecycleId = ++_retryLifecycleId;
|
|
529
|
+
let didRetryComplete = false;
|
|
530
|
+
pi.events.emit(RETRY_STARTED_EVENT, { retryId: retryLifecycleId });
|
|
523
531
|
|
|
524
532
|
// Capture the current session generation. If /new fires while we're
|
|
525
533
|
// looping, _sessionGeneration will increment and the loop will exit.
|
|
@@ -606,6 +614,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
606
614
|
// The hidden AgentSession turn completed. Check the result.
|
|
607
615
|
if (!lastMessageIsRetryableError()) {
|
|
608
616
|
// Success or non-error terminal state — exit the loop.
|
|
617
|
+
didRetryComplete = true;
|
|
609
618
|
return;
|
|
610
619
|
}
|
|
611
620
|
|
|
@@ -614,6 +623,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
614
623
|
} finally {
|
|
615
624
|
// Release the mutex only if this loop still owns it.
|
|
616
625
|
if (_continueGeneration === myGeneration) {
|
|
626
|
+
pi.events.emit(didRetryComplete ? RETRY_COMPLETED_EVENT : RETRY_CANCELLED_EVENT, {
|
|
627
|
+
retryId: retryLifecycleId,
|
|
628
|
+
});
|
|
617
629
|
_continueInProgress = false;
|
|
618
630
|
_continueGeneration = null;
|
|
619
631
|
_continueInputGeneration = null;
|