import type { GenerationAttemptHandle, GenerationAttemptInput } from "../types.js"; import { OperationUsageRecorder, type OperationUsageSnapshot } from "./operation-usage.js"; export type OperationKind = "turn" | "compaction" | "provider_validation" | "background"; export type OperationTerminalOutcome = "completed" | "failed" | "cancelled" | "budget-exceeded" | "semantic-output-stopped"; export interface OperationPolicy { readonly kind: OperationKind; readonly admissionBudget: number; readonly continuationBudget: number; } export declare function turnOperationPolicy(admissionBudget?: number, continuationBudget?: number): OperationPolicy; export declare function singleAdmissionOperationPolicy(kind: OperationKind, admissionBudget?: number): OperationPolicy; interface OperationLedgerIdentity { readonly operationId: string; readonly kind: OperationKind; readonly admissionBudget: number; readonly continuationBudget: number; } export declare class OperationAdmissionBudgetExceededError extends Error { readonly name = "OperationAdmissionBudgetExceededError"; readonly operation: OperationLedgerIdentity; constructor(operation: OperationLedgerIdentity); } export declare class OperationSemanticOutputError extends Error { readonly name = "OperationSemanticOutputError"; readonly operation: OperationLedgerIdentity; constructor(operation: OperationLedgerIdentity); } export declare function isOperationPolicyError(error: unknown): error is OperationAdmissionBudgetExceededError | OperationSemanticOutputError; export declare class OperationLedger { readonly operationId: string; readonly policy: OperationPolicy; private readonly recorder; private admissions; private continuations; private refusals; private semanticOutput; private terminal; constructor(policy?: OperationPolicy, recorder?: OperationUsageRecorder); get kind(): OperationKind; get admissionsUsed(): number; get continuationsUsed(): number; get semanticOutputPublished(): boolean; /** True once this ledger refused a dispatch the caller tried to make. */ get admissionRefused(): boolean; get terminalOutcome(): OperationTerminalOutcome | undefined; begin(input: GenerationAttemptInput): GenerationAttemptHandle; noteSemanticOutput(): void; beginContinuation(): void; /** * Callers surface the failure that caused the operation to stop, which is the * provider error rather than the guard that refused the retry. The ledger * still records the budget as the terminal reason so telemetry is not lost. */ settle(outcome: OperationTerminalOutcome): void; snapshot(): OperationUsageSnapshot; private identity; } export declare function operationTerminalOutcome(error: unknown, signal?: AbortSignal): OperationTerminalOutcome; export declare function operationUsageFromError(error: unknown): OperationUsageSnapshot | undefined; export {};