import { type Agent } from "@caupulican/pi-agent-core/agent"; import type { AgentEvent, AgentMessage } from "@caupulican/pi-agent-core/types"; import type { AssistantMessage } from "@caupulican/pi-ai"; import type { FailureCorpusRecorder } from "./failure-corpus.ts"; import type { ModelRegistry } from "./model-registry.ts"; import type { ModelRouterFailoverStatus } from "./model-router/status.ts"; import type { SettingsManager } from "./settings-manager.ts"; type ForegroundRecoveryEvent = { type: "warning"; message: string; } | { type: "auto_retry_start"; attempt: number; maxAttempts: number; delayMs: number; errorMessage: string; } | { type: "auto_retry_end"; success: boolean; attempt: number; finalError?: string; }; declare const foregroundSubmissionLeaseMarker: unique symbol; /** Identity-bound authority to prepare and execute one logical foreground submission. */ export interface ForegroundSubmissionLease { readonly [foregroundSubmissionLeaseMarker]: true; } export interface ForegroundRecoveryControllerDeps { agent: Agent; settingsManager: SettingsManager; modelRegistry: ModelRegistry; failureCorpus: FailureCorpusRecorder; getContextWindow(): number; emit(event: ForegroundRecoveryEvent): void; checkCompaction(message: AssistantMessage): Promise; onSuccessfulAssistant(): void; prepareRun(): Promise; afterRun(): Promise; isCompacting?: () => boolean; } /** Owns the complete logical foreground run plus retry/failover/compaction recovery ordering. */ export declare class ForegroundRecoveryController { private readonly retry; private readonly billingFailover; private lastAssistantMessage; private pendingCompactionRetryKey; private activeRuns; private submissionLease; private shutdownReason; private readonly idleWaiters; private readonly deps; constructor(deps: ForegroundRecoveryControllerDeps); private getRetryPolicy; get attempt(): number; get isRetrying(): boolean; get isRunActive(): boolean; get isBusy(): boolean; /** Atomically reserve the full foreground lifecycle, including asynchronous prompt preparation. */ tryAcquireSubmission(): ForegroundSubmissionLease | undefined; /** Wait until foreground ownership can be acquired without a check-then-act gap. */ acquireSubmission(): Promise; ownsSubmission(lease: ForegroundSubmissionLease | undefined): boolean; releaseSubmission(lease: ForegroundSubmissionLease): void; runAgentPrompt(messages: AgentMessage | AgentMessage[], submissionLease?: ForegroundSubmissionLease): Promise; /** Continue from the already canonical agent history without replaying the original user message. */ runAgentContinuation(submissionLease?: ForegroundSubmissionLease): Promise; private runAgentExecution; wakeIdleWaiters(): void; waitForIdle(): Promise; shutdown(): void; private resolveIdleWaiters; abortRetry(): void; isModelExhausted(ref: string): boolean; getFailoverStatus(): ModelRouterFailoverStatus; observeAssistant(message: AssistantMessage): void; willRetryAfterAgentEnd(event: Extract): boolean; handlePostAgentRun(): Promise; private finishRetry; private classifyAssistantError; } export {}; //# sourceMappingURL=foreground-recovery-controller.d.ts.map