@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
63 lines • 2.13 kB
JavaScript
import { isQuotaExhaustionMessage } from "@earendil-works/pi-ai";
import { isBillingErrorMessage } from "./billing.js";
/**
* Non-retryable failures that still say the entry is unusable for everyone:
* billing and account quota/budget exhaustion. Auth and request-shape rejections
* are not outages and never open a circuit.
*/
export function isHealthExhaustionFailure(errorMessage) {
return isBillingErrorMessage(errorMessage) || isQuotaExhaustionMessage(errorMessage);
}
/**
* One session's side of the shared breaker: at most one probe token, taken by
* atomic admission before the session switches to (or starts on) an entry, and
* given back on every terminal path - accepted, failed, aborted, or abandoned.
*/
export class CircuitProbes {
constructor(circuits) {
this.circuits = circuits;
}
isOpen(selector) {
return this.circuits?.isOpen(selector) ?? false;
}
governs(selector) {
return this.circuits?.governs(selector) ?? false;
}
isExhausted(selector) {
return this.circuits?.isExhausted(selector) ?? false;
}
admit(selector) {
const admission = this.circuits?.admit(selector) ?? { kind: "closed" };
if (admission.kind === "probe" && this.token?.selector !== selector) {
this.release();
this.token = admission.token;
}
return admission.kind;
}
holds(selector) {
return this.token?.selector === selector;
}
get probing() {
return this.token?.selector;
}
noteFailure(selector, failure) {
this.circuits?.noteFailure(selector, failure);
if (this.token?.selector === selector)
this.token = undefined;
}
accept(selector) {
this.circuits?.close(selector);
if (this.token?.selector === selector)
this.token = undefined;
}
release() {
if (this.token)
this.circuits?.release(this.token);
this.token = undefined;
}
releaseAll() {
this.token = undefined;
this.circuits?.releaseAll();
}
}
//# sourceMappingURL=circuit-probes.js.map