export type CheckpointOptions = { /** * - Tool names that require approval (exact match). */ tools?: string[] | undefined; /** * - Custom predicate — overrides tools list if set. */ shouldAsk?: ((toolName: string, args: any) => boolean) | undefined; /** * - Async `(question, context) => void` to deliver the question. */ send?: ((question: string, context: any) => any) | undefined; /** * - Async `(context) => string` that resolves with the user's reply. */ waitForReply?: ((context: any) => any) | undefined; /** * - Ms to wait before auto-denying. 0 disables. */ timeout?: number | undefined; }; /** * @typedef {object} CheckpointOptions * @property {Array} [tools] - Tool names that require approval (exact match). * @property {(toolName: string, args: any) => boolean} [shouldAsk] - Custom predicate — overrides tools list if set. * @property {(question: string, context: any) => any} [send] - Async `(question, context) => void` to deliver the question. * @property {(context: any) => any} [waitForReply] - Async `(context) => string` that resolves with the user's reply. * @property {number} [timeout=300000] - Ms to wait before auto-denying. 0 disables. */ export class Checkpoint { /** * @param {CheckpointOptions} [options={}] * @when you want an always-prompt human-in-the-loop approval gate on chosen tools — complementary to bareguard's policy-driven pauses * @fails auto-denies on timeout (0 disables) and denies safe when no reply channel is wired; a TimeoutError is surfaced, never swallowed. * @example * const checkpoint = new Checkpoint({ tools: ['deploy'], waitForReply }); * const ok = await checkpoint.confirm('deploy', args); */ constructor(options?: CheckpointOptions); tools: Set; send: ((question: string, context: any) => any) | null; waitForReply: ((context: any) => any) | null; shouldAskFn: ((toolName: string, args: any) => boolean) | null; timeout: number; /** * @param {string} toolName - Name of the tool being invoked. * @param {any} args - Arguments passed to the tool. * @returns {boolean} Whether approval should be requested. */ shouldAsk(toolName: string, args: any): boolean; /** * Send a question and wait for a reply. Rejects with TimeoutError if `timeout` ms elapse * without a reply — the Loop catches this, auto-denies the tool call, and routes the * error through loop:error + onError. No silent hangs. * @param {string} question - The approval question to send. * @param {{tool?: string, [key: string]: any}} [context={}] - Context passed to send and waitForReply. * @returns {Promise} The user's reply, or null. * @throws {Error} `[Checkpoint] send and waitForReply callbacks required` — when callbacks are missing. * @throws {TimeoutError} When no reply arrives within `timeout` ms. */ ask(question: string, context?: { tool?: string; [key: string]: any; }): Promise; }