/** * Progressive Source Collector * * Collects browse results as they stream in and resolves early once * a quality threshold is met. This enables fast initial responses * while still getting comprehensive data from all sources. * * Key behaviors: * - Starts processing immediately as sources complete * - Returns early when quality threshold is met (2+ high-authority OR 3+ any) * - Tracks pending sources for refinement metadata * - Supports timeout-based fallback for slow sources */ /** * Quality threshold configuration */ export interface QualityThreshold { /** Minimum number of high-authority sources (gov/official, score >= 0.8) */ minHighAuthority?: number; /** Minimum number of any successful sources */ minTotalSources?: number; /** Minimum combined authority score (sum of all source scores) */ minCombinedAuthority?: number; /** Maximum time to wait for threshold (ms) */ maxWaitMs?: number; /** Minimum time to wait even if threshold is met (ms) - gives fast sources a chance */ minWaitMs?: number; } /** * Collection result */ export interface CollectionResult { /** Sources that completed before early return */ completedSources: T[]; /** Number of sources still pending at time of return */ pendingCount: number; /** Whether we returned early (before all sources completed) */ isEarlyReturn: boolean; /** Time taken until early return / completion */ collectionTimeMs: number; /** Quality score achieved (combined authority of completed sources) */ qualityScore: number; /** Reason for returning (threshold_met, timeout, all_complete) */ returnReason: 'threshold_met' | 'timeout' | 'all_complete'; } /** * Progressive source collector * * Usage: * ```typescript * const collector = new ProgressiveCollector(threshold); * const result = await collector.collect(browsePromises, getAuthorityScore); * ``` */ export declare class ProgressiveCollector { private threshold; private completedSources; private startTime; private resolveEarly; private hasResolved; constructor(threshold?: QualityThreshold); /** * Collect sources progressively, returning early when quality threshold is met * * @param promises Array of promises for each source * @param getAuthorityScore Function to extract authority score from result * @param isSuccess Function to check if result is successful */ collect(promises: Promise[], getAuthorityScore: (result: T) => number, isSuccess: (result: T) => boolean): Promise>; /** * Handle a source completing */ private handleSourceComplete; /** * Check if quality threshold is met */ private checkThreshold; /** * Calculate combined quality score */ private calculateQualityScore; /** * Return with current results */ private returnWithResult; } /** * Convenience function for progressive collection */ export declare function collectProgressively(promises: Promise[], getAuthorityScore: (result: T) => number, isSuccess: (result: T) => boolean, threshold?: QualityThreshold): Promise>; //# sourceMappingURL=progressive-collector.d.ts.map