import type { OperationErrorDescriptor, OperationEvent, OperationHandle, OperationProgress, OperationStatus } from '../types/operations.js'; /** Options for a process-local operation handle. */ export interface LocalOperationHandleOptions { /** Replaces the system clock, for event timestamps. */ now?: () => Date; /** * Builds the error `result()` rejects with on cancellation. * * Injected so a family can keep its own error type — the image family rejects with * `ImageOperationCancelledError` — without this module depending on any family. */ cancellationError?: (id: string, reason?: string) => unknown; /** Called on every emitted event, for persistence, metrics, or webhooks. */ onEvent?: (event: OperationEvent) => void; } /** * A process-local operation handle: status, awaitable result, cancellation, and an event stream. * * This was the image family's private handle and is now shared, so every long-running family * reports the same lifecycle. It stays deliberately process-bound; durability is layered on top by * `OperationRunner` rather than folded in here, so a caller that does not need a store pays nothing * for one. */ export declare class LocalOperationHandle implements OperationHandle { /** The operation's id. */ readonly id: string; private readonly options; private readonly controller; private readonly history; private readonly waiters; private readonly resultPromise; private readonly now; private resolveResult; private rejectResult; private currentStatus; private currentProgress?; private currentAttempt; private sequence; constructor( /** The operation's id. */ id: string, options?: LocalOperationHandleOptions); /** Where the operation stands. */ status(): OperationStatus; /** The latest progress reported. */ progress(): OperationProgress | undefined; /** Attempt currently running, starting at 1. */ attempt(): number; /** The signal handed to the executor, aborted on cancellation. */ get signal(): AbortSignal; /** Resolves with the result, or rejects when the operation fails, is cancelled, or expires. */ result(): Promise; /** Asks the operation to stop. Resolves false when it already finished or is already stopping. */ cancel(reason?: string): boolean; /** Every event, past and future, until the operation finishes. */ events(): AsyncIterable>; /** * Moves the handle to `running` without executing anything. * * Used by `OperationRunner`, which owns the executor call itself so it can wrap it in a lease and * a heartbeat. Without this the handle would sit in `queued` for the whole run, suppressing both * the `running` event and every progress report. */ markRunning(attempt?: number): boolean; /** Publishes progress. Ignored once the operation has settled. */ report(progress: OperationProgress): void; /** Records that the next attempt is scheduled, without running it. */ markRetrying(error: unknown, delayMs: number): void; /** Marks the operation expired and rejects its result. Returns false when it already finished. */ markExpired(error?: unknown): boolean; /** * Runs `executor` and settles the handle with its outcome. * * Deferred to a microtask so a caller always receives the handle before any event fires, which * keeps `events()` from missing the first transition. */ start(executor: (signal: AbortSignal) => Promise): void; /** Runs `executor` inline, for a caller that is already inside an async context. */ run(executor: (signal: AbortSignal) => Promise): Promise; /** Marks the operation succeeded and resolves its result. Ignored once it has finished. */ settleSuccess(value: TResult): void; /** Marks the operation failed and rejects its result. Ignored once it has finished. */ settleFailure(error: unknown, deadLettered?: boolean): void; private buildCancellationError; private iterateEvents; private eventBase; private emit; } /** Reduces any error to the name, code, message, and retryability an operation record stores. */ export declare function describeOperationError(error: unknown): OperationErrorDescriptor;