@ai2070/l0
Version:
L0: The Missing Reliability Substrate for AI
50 lines • 2.48 kB
TypeScript
import type { L0Options, L0Result } from "../types/l0";
export interface ParallelOptions {
concurrency?: number;
failFast?: boolean;
sharedRetry?: L0Options["retry"];
sharedMonitoring?: L0Options["monitoring"];
onProgress?: (completed: number, total: number) => void;
onComplete?: (result: L0Result, index: number) => void;
onError?: (error: Error, index: number) => void;
}
export interface RaceResult<TOutput = unknown> extends L0Result<TOutput> {
winnerIndex: number;
}
export interface ParallelResult<TOutput = unknown> {
results: Array<L0Result<TOutput> | null>;
errors: Array<Error | null>;
successCount: number;
failureCount: number;
duration: number;
allSucceeded: boolean;
aggregatedTelemetry?: AggregatedTelemetry;
}
export interface AggregatedTelemetry {
totalTokens: number;
totalDuration: number;
totalRetries: number;
totalNetworkErrors: number;
totalViolations: number;
avgTokensPerSecond: number;
avgTimeToFirstToken: number;
}
export declare function parallel<TOutput = unknown>(operations: L0Options<TOutput>[], options?: ParallelOptions): Promise<ParallelResult<TOutput>>;
export declare function parallelAll<TOutput = unknown>(operations: L0Options<TOutput>[], options?: Omit<ParallelOptions, "concurrency">): Promise<ParallelResult<TOutput>>;
export declare function sequential<TOutput = unknown>(operations: L0Options<TOutput>[], options?: Omit<ParallelOptions, "concurrency">): Promise<ParallelResult<TOutput>>;
export declare function batched<TOutput = unknown>(operations: L0Options<TOutput>[], batchSize: number, options?: Omit<ParallelOptions, "concurrency">): Promise<ParallelResult<TOutput>>;
export declare function race<TOutput = unknown>(operations: L0Options<TOutput>[], options?: Pick<ParallelOptions, "sharedRetry" | "sharedMonitoring">): Promise<RaceResult<TOutput>>;
export declare class OperationPool {
private concurrency;
private options;
private queue;
private activeWorkers;
constructor(concurrency: number, options?: Pick<ParallelOptions, "sharedRetry" | "sharedMonitoring">);
execute(operation: L0Options): Promise<L0Result>;
private processQueue;
drain(): Promise<void>;
getQueueLength(): number;
getActiveWorkers(): number;
}
export declare function createPool(concurrency: number, options?: Pick<ParallelOptions, "sharedRetry" | "sharedMonitoring">): OperationPool;
//# sourceMappingURL=parallel.d.ts.map