UNPKG

ai-patterns

Version:

Production-ready TypeScript patterns to build solid and robust AI applications. Retry logic, circuit breakers, rate limiting, human-in-the-loop escalation, prompt versioning, response validation, context window management, and more—all with complete type

94 lines 1.82 kB
/** * Types for Timeout Pattern */ import { AsyncFunction, Logger } from "./common"; import { PatternError } from "./errors"; /** * Options for timeout pattern */ export interface TimeoutOptions<TResult = any> { /** * Function to execute with timeout */ execute: AsyncFunction<TResult>; /** * Timeout duration in milliseconds */ timeoutMs: number; /** * Custom error message */ message?: string; /** * Logger for timeout events */ logger?: Logger; /** * Callback invoked on timeout */ onTimeout?: () => void; /** * External AbortSignal for cancellation */ signal?: AbortSignal; } /** * Result of a successful timeout operation */ export interface TimeoutResult<T> { /** * The successful result value */ value: T; /** * Duration of operation in milliseconds */ duration: number; /** * Whether the operation timed out */ timedOut: false; } /** * Error thrown when timeout occurs */ export interface TimeoutError extends PatternError { /** * Duration before timeout */ duration: number; /** * Indicates this is a timeout error */ timedOut: true; } /** * Common timeout durations (in milliseconds) */ export declare const TimeoutDurations: { /** * Very short timeout - 1 second */ VERY_SHORT: number; /** * Short timeout - 5 seconds */ SHORT: number; /** * Medium timeout - 15 seconds */ MEDIUM: number; /** * Long timeout - 30 seconds */ LONG: number; /** * Very long timeout - 1 minute */ VERY_LONG: number; /** * Extended timeout - 5 minutes */ EXTENDED: number; }; //# sourceMappingURL=timeout.d.ts.map