/**
 * Idempotency cache — dedupe duplicate calls by a caller-supplied key.
 *
 * Sprint-468. Wrap an async operation so repeated calls with the same
 * key return the cached result without re-invoking the operation.
 * Essential for retry-safe writes (BrainPort.archiveKnowledge on
 * retryable failures).
 *
 * Defaults to an in-memory LRU with 1024 entries / 5 min TTL. Production
 * hosts with multi-process topology should inject a shared
 * implementation (e.g. Redis-backed) via the `cache` option.
 *
 * Usage:
 *   const safe = idempotent(brain.archiveKnowledge.bind(brain), {
 *     keyFor: (entry) => sha256(entry.content + entry.author),
 *     ttlMs: 60_000,
 *   });
 */
export interface IdempotencyCache<T> {
    get(key: string): T | undefined;
    set(key: string, value: T): void;
    delete(key: string): void;
}
/**
 * Simple bounded TTL cache. In-memory only; single-process.
 * Eviction: oldest entry first when `maxEntries` is exceeded, and
 * entries past `ttlMs` are skipped on read.
 */
export declare class BoundedTtlCache<T> implements IdempotencyCache<T> {
    private readonly maxEntries;
    private readonly ttlMs;
    private readonly now;
    private readonly store;
    constructor(maxEntries: number, ttlMs: number, now?: () => number);
    get(key: string): T | undefined;
    set(key: string, value: T): void;
    delete(key: string): void;
    get size(): number;
}
export interface IdempotentOptions<TArgs extends unknown[], TResult> {
    /** Derive a stable cache key from the call arguments. */
    keyFor: (...args: TArgs) => string;
    /** Optional cache implementation (defaults to BoundedTtlCache). */
    cache?: IdempotencyCache<TResult>;
    /** Default cache: entries count cap. Default 1024. */
    maxEntries?: number;
    /** Default cache: entry TTL in ms. Default 5 minutes. */
    ttlMs?: number;
}
/**
 * Wrap an async function so identical keyed calls share the same
 * result. Failures are NOT cached — a failed call is retryable.
 */
export declare function idempotent<TArgs extends unknown[], TResult>(fn: (...args: TArgs) => Promise<TResult>, options: IdempotentOptions<TArgs, TResult>): (...args: TArgs) => Promise<TResult>;
/**
 * Convenience: hash the JSON-serialisable arguments as the cache key.
 * Useful when the args already fully determine the operation (e.g.
 * BrainPort.archiveKnowledge takes a single entry object).
 */
export declare function hashKey(...parts: unknown[]): string;
//# sourceMappingURL=idempotent.d.ts.map