import type { InstanceAiEvent } from '@n8n/api-types';
import type { InstanceAiLivenessPolicy, InstanceAiLivenessTimeoutReason } from '@n8n/instance-ai';
export declare const INSTANCE_AI_RUN_TIMEOUT_REASON = "timeout";
export type InstanceAiLivenessTimedOutActiveRun = {
    runId: string;
    abortController: AbortController;
};
export type InstanceAiLivenessTimedOutSuspendedRun = {
    runId: string;
    threadId: string;
    abortController: AbortController;
};
export type InstanceAiLivenessTimedOutTask = {
    threadId: string;
    taskId: string;
    role: string;
    timeoutReason?: InstanceAiLivenessTimeoutReason;
};
export type InstanceAiLivenessPendingConfirmation = {
    threadId: string;
};
export type InstanceAiLivenessSweepResult = {
    activeThreadIds: string[];
    suspendedThreadIds: string[];
    confirmationRequestIds: string[];
};
export type InstanceAiLivenessRunState<TSuspendedRun extends InstanceAiLivenessTimedOutSuspendedRun> = {
    sweepTimedOut: (policy: InstanceAiLivenessPolicy, now?: number) => InstanceAiLivenessSweepResult;
    cancelActiveRun: (threadId: string) => InstanceAiLivenessTimedOutActiveRun | undefined;
    cancelSuspendedRun: (threadId: string) => TSuspendedRun | undefined;
    getActiveRunId: (threadId: string) => string | undefined;
    getPendingConfirmation: (requestId: string) => InstanceAiLivenessPendingConfirmation | undefined;
    rejectPendingConfirmation: (requestId: string) => boolean;
};
export type InstanceAiLivenessBackgroundTasks = {
    timeoutTimedOutTasks: (policy: InstanceAiLivenessPolicy, now?: number) => Promise<InstanceAiLivenessTimedOutTask[]>;
};
export type InstanceAiLivenessEventBus = {
    getEventsForRun: (threadId: string, runId: string) => Pick<InstanceAiEvent, 'responseId'>[];
    publish: (threadId: string, event: InstanceAiEvent) => void;
};
export type InstanceAiLivenessLogger = {
    debug: (message: string, metadata?: Record<string, unknown>) => void;
    warn: (message: string, metadata?: Record<string, unknown>) => void;
};
export type InstanceAiLivenessServiceOptions<TSuspendedRun extends InstanceAiLivenessTimedOutSuspendedRun> = {
    policy: InstanceAiLivenessPolicy;
    backgroundTaskIdleTimeoutMs: number;
    runState: InstanceAiLivenessRunState<TSuspendedRun>;
    backgroundTasks: InstanceAiLivenessBackgroundTasks;
    eventBus: InstanceAiLivenessEventBus;
    finalizeCancelledSuspendedRun: (suspended: TSuspendedRun, reason: string) => void;
    logger: InstanceAiLivenessLogger;
};
export declare class InstanceAiLivenessService<TSuspendedRun extends InstanceAiLivenessTimedOutSuspendedRun> {
    private readonly options;
    private timeoutInterval?;
    private readonly timedOutRunIds;
    private readonly timedOutActiveRunThreads;
    constructor(options: InstanceAiLivenessServiceOptions<TSuspendedRun>);
    get backgroundTaskIdleTimeoutMs(): number;
    start(): void;
    shutdown(): void;
    clearThreadState(threadId: string): void;
    markRunTimedOut(runId: string): void;
    consumeRunTimedOut(runId: string): boolean;
    hasTimedOutActiveRunThread(threadId: string): boolean;
    sweepTimedOutWork(now?: number): Promise<void>;
    cancelTimedOutActiveRun(threadId: string): void;
    cancelTimedOutSuspendedRun(threadId: string): void;
    publishRunTimeoutNotice(threadId: string, runId: string): void;
}
