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
61 lines • 2.08 kB
TypeScript
/**
* Human-in-the-Loop Pattern - AI → Human escalation
*/
import { AsyncFunction, Logger } from "../types/common";
import { TimeoutFallback, EscalationRule, HumanReview, HumanInTheLoopOptions, HumanInTheLoopResult, CommonEscalationRules } from "../types/human-in-the-loop";
export { CommonEscalationRules };
/**
* Internal options (without execute and input)
*/
interface HumanInTheLoopInternalOptions<TInput = any, TOutput = any> {
escalationRules?: EscalationRule<TInput, TOutput>[];
reviewTimeout?: number;
requestHumanReview: (review: HumanReview<TInput, TOutput>) => Promise<TOutput>;
onEscalate?: (review: HumanReview<TInput, TOutput>) => void;
onReviewComplete?: (review: HumanReview<TInput, TOutput>) => void;
logger?: Logger;
timeoutFallback?: TimeoutFallback;
}
/**
* Human-in-the-Loop - Enables AI → Human escalation (internal class)
*/
export declare class HumanInTheLoop<TInput = any, TOutput = any> {
private readonly aiFn;
private readonly options;
private reviews;
private reviewCounter;
constructor(aiFn: AsyncFunction<TOutput, [TInput]>, options: HumanInTheLoopInternalOptions<TInput, TOutput>);
/**
* Execute AI function with possible escalation
*/
execute(input: TInput): Promise<TOutput>;
/**
* Check escalation rules
*/
private checkEscalationRules;
/**
* Create a review
*/
private createReview;
/**
* Request human review with timeout
*/
private requestReview;
/**
* Get all reviews
*/
getReviews(): HumanReview<TInput, TOutput>[];
/**
* Get review by ID
*/
getReview(id: string): HumanReview<TInput, TOutput> | undefined;
/**
* Get pending reviews
*/
getPendingReviews(): HumanReview<TInput, TOutput>[];
}
/**
* Human-in-the-Loop Pattern with single parameter API
*/
export declare function humanInTheLoop<TInput = any, TOutput = any>(options: HumanInTheLoopOptions<TInput, TOutput>): Promise<HumanInTheLoopResult<TOutput>>;
//# sourceMappingURL=human-in-the-loop.d.ts.map