@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
127 lines • 7 kB
TypeScript
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
import { type Api, type Model } from "@earendil-works/pi-ai";
import { CircuitProbes } from "./circuit-probes.ts";
import type { ActiveFallbackState, CircuitFailure, FallbackReason, FallbackRungRefusal, RetryFallbackControllerDeps } from "./controller-types.ts";
import type { AccountLimits } from "../subscription-limits/limit-store.ts";
export type { ActiveFallbackState, FallbackRungRefusal, RetryFallbackControllerDeps } from "./controller-types.ts";
export declare class RetryFallbackController {
private readonly deps;
private readonly triedSelectors;
private state;
private lastExhaustedChainKey;
private heldForNetworkBlip;
private blipModel;
private readonly ownFailures;
private readonly refusedProviders;
private readonly refusals;
private readonly unusable;
readonly probes: CircuitProbes;
private canonicalCache;
constructor(deps: RetryFallbackControllerDeps);
get activeState(): Readonly<ActiveFallbackState> | undefined;
get exhaustedChainKey(): string | undefined;
/** The weekly-limit family hold on `model`, while it lasts (senpi#5596). */
heldFamily(model: Model<Api>): {
readonly family: string;
readonly errorMessage: string;
} | undefined;
/** The families a no-family limit was confirmed on before it held the whole provider (senpi#5596). */
widenedFamiliesOf(provider: string): readonly string[] | undefined;
get turnRefusals(): readonly FallbackRungRefusal[];
isProviderSpent(provider: string): boolean;
accountError(provider: string): string | undefined;
accountResetAt(provider: string): number | undefined;
releaseGuessedAccountHold(provider: string): boolean;
releaseAccountHold(provider: string): boolean;
releaseAccountHoldShownServable(provider: string, usage: readonly AccountLimits[]): boolean;
resetTurn(): void;
clear(): void;
private canonicalChains;
/**
* `refusedProvider`: a provider the failure being decided rules out (a request-level refusal or
* a spent account) before the walk records it.
*/
canTryFallback(refusedProvider?: string): boolean;
/**
* Whether a chain exists for the current model at all, regardless of whether
* a candidate is usable right now. `canTryFallback()` answers the latter and
* goes false on cooldown or exhaustion, so it cannot tell a UI "you never
* configured a chain" apart from "the chain is spent".
*/
hasConfiguredChain(): boolean;
/**
* Revert to the chain's original model at a turn boundary. Fires for unpinned
* state under the cooldown-expiry policy once the original selector is no longer
* suppressed and is still usable; pinned state and the "never" policy hold the
* fallback model. One exception outranks both the cooldown and the policy: a
* fallback that is itself known unusable (billing or an account limit) while the
* original is not is never where the session rests (senpi#2376). An original that is
* itself still held (an account usage limit with the reset it named, which can outlast
* the circuit's 30-minute ceiling) is not restored before that hold ends (senpi#3347).
* At a turn boundary, a changed credential on the original's provider first releases
* its billing pin and parks (senpi#4099).
*/
maybeRestorePrimary(revertPolicy: "cooldown-expiry" | "never", boundary?: "turn" | "continuation"): Promise<boolean>;
private originalRecovered;
/**
* A user-driven setThinkingLevel makes the current level a deliberate choice,
* so the revert restore-rule must no longer treat it as fallback-applied.
*/
noteManualThinkingLevel(): void;
/**
* A senpi-owned compaction successfully rewrote the conversation context, the
* one safe moment to re-attempt a refusal-pinned fallback's original model:
* the refusal assumption ("the same context refuses again") no longer holds.
* Refusal contributions clear; billing contributions never release - retrying
* the same account never recovers it. Returns true only when the overall pin
* transitioned true -> false, i.e. the caller may now restore the primary via
* the existing maybeRestorePrimary gate.
*/
notifyCompactionApplied(): boolean;
/** A user-driven model change abandons the fallback window entirely. */
clearForManualModelChange(model: Model<Api>): void;
/**
* A login or an explicit block reset on `provider` makes the account and
* model holds it earned stale, so the restore guard stops waiting out a reset that may no longer apply.
*/
noteProviderAccountsChanged(provider: string): void;
/** A response this session got from `selector` succeeded: the entry serves it again (senpi#3467). */
noteServed(selector: string): void;
private emitScopeProbe;
/**
* Records a failure that makes the entry unusable for every session - billing
* or quota exhaustion, or a transient failure that spent its budget or failed a
* half-open probe - independent of whether a fallback candidate remains.
*/
noteHealthFailure(model: Model<Api>, thinkingLevel: ThinkingLevel | undefined, failure: CircuitFailure): void;
/**
* Turn-boundary skip: when the current entry's circuit is open because this session
* saw it fail (and has not been served by it since), or because its account is spent
* for everyone, move to the next closed entry without spending a request on it. A
* sibling's bare failure or Retry-After never moves this session (senpi#3467). With no
* closed entry left the current one stays and probes, so the chain never refuses a
* turn; a half-open current entry is claimed for this session.
*/
rerouteAroundOpenCircuit(): Promise<boolean>;
tryFallback(reason: FallbackReason, failure: {
errorMessage?: string;
retryAfterMs?: number;
refusedProvider?: string;
}, failureObserved?: boolean): Promise<boolean>;
private walkFallback;
private applyCandidate;
/**
* The chain governing `current`, when fallback is enabled. An active episode's chain wins over the
* rung's own chain, so the walk continues down the chain it started on: Opus 5.5 -> Fable 5.2 -> Kimi
* never detours through Fable's own chain, and a Fable session that reached Opus 5.5 never takes
* Opus 5.5's chain off Anthropic (senpi#6699). Outside an episode the model's own chain governs.
*/
private managedChainKey;
private nextCandidate;
private switchOrRelease;
private selectThinking;
private skip;
}
/** Only explicit account remedies invalidate holds; health and listing notices do not. */
export declare function followProviderAccountChanges(controller: Pick<RetryFallbackController, "noteProviderAccountsChanged">): () => void;
//# sourceMappingURL=controller.d.ts.map