/**
 * SceneAnalysisJobRunner — concurrent per-scene analysis runner.
 *
 * Drives the Stage 2 portion of the Scene Story pipeline: takes the
 * AnalysisInterval[] selected by buildAnalysisIntervals() and runs each one
 * through a SkillExecutor with bounded concurrency and single-retry semantics.
 *
 * Concurrency: legacy mode stays globally concurrent. Smart Analysis Mode can
 * pass runExecution to add an opt-in per-trace SQL gate without changing the
 * legacy product decision of "3-way parallel analysis".
 *
 * Cancel semantics: cancel() drains the queued jobs to 'cancelled' state
 * immediately, but running jobs keep executing (SkillExecutor has no abort
 * hook). When they finish after cancel, their result is marked 'dropped'
 * rather than 'completed' — callers can still inspect it via getJobs() for
 * telemetry, but it is not emitted as a real completion.
 */
import { AnalysisInterval, SceneAnalysisJob, SceneJobResult } from './types';
export interface SceneSkillExecutor {
    execute(skillId: string, traceId: string, params: Record<string, any>, inherited?: Record<string, any>): Promise<SceneSkillExecutionResult>;
}
export interface SceneSkillExecutionResult {
    success: boolean;
    displayResults?: any[];
    executionTimeMs?: number;
    error?: string;
}
export type JobRunnerEvent = {
    type: 'job_queued';
    job: SceneAnalysisJob;
} | {
    type: 'job_started';
    job: SceneAnalysisJob;
} | {
    type: 'job_retrying';
    job: SceneAnalysisJob;
    error: string;
} | {
    type: 'job_completed';
    job: SceneAnalysisJob;
    result: SceneJobResult;
} | {
    type: 'job_failed';
    job: SceneAnalysisJob;
    error: string;
} | {
    type: 'job_cancelled';
    job: SceneAnalysisJob;
} | {
    type: 'job_dropped';
    job: SceneAnalysisJob;
    reason: 'late_after_cancel';
} | {
    type: 'all_done';
    jobs: SceneAnalysisJob[];
};
export interface SceneAnalysisJobRunnerOptions {
    /** Max jobs running concurrently. Product decision: 3. */
    concurrency: number;
    /** Retries after initial failure. Product decision: 1. */
    maxRetries: number;
    /** Trace id shared by every job produced by this runner. */
    traceId: string;
    /** Analysis id used to scope job ids. */
    analysisId: string;
    /** Skill executor used to run the per-interval skill. */
    skillExecutor: SceneSkillExecutor;
    /** Optional smart-only execution gate around per-job SQL-heavy skill calls. */
    runExecution?: (fn: () => Promise<SceneSkillExecutionResult>) => Promise<SceneSkillExecutionResult>;
    /** Optional projection input for replay/debug artifacts. */
    toDataEnvelopes?: (result: SceneSkillExecutionResult, traceId: string, job: SceneAnalysisJob) => unknown[];
    /** Receives every state transition for SSE fanout and telemetry. */
    onEvent: (event: JobRunnerEvent) => void;
}
export declare class SceneAnalysisJobRunner {
    private readonly opts;
    private readonly jobs;
    private readonly queue;
    private readonly running;
    private cancelled;
    private allDoneResolvers;
    private allDoneEmitted;
    constructor(opts: SceneAnalysisJobRunnerOptions);
    /** Wraps onEvent so a misbehaving listener cannot break the runner state. */
    private emit;
    /**
     * Add a batch of analysis intervals as jobs and start executing.
     * Safe to call multiple times; each call appends to the queue.
     */
    enqueue(intervals: AnalysisInterval[]): void;
    /**
     * Request cancellation. Queued jobs transition to 'cancelled' immediately;
     * running jobs are left to finish but their results will be dropped.
     */
    cancel(): void;
    /**
     * Resolves when every job has reached a terminal state (completed / failed /
     * cancelled / dropped). Safe to await after cancel(); will resolve once any
     * in-flight jobs finish.
     */
    waitForAllDone(): Promise<void>;
    getJobs(): SceneAnalysisJob[];
    isCancelled(): boolean;
    private pump;
    private runJob;
    private buildDataEnvelopes;
    private transitionJob;
    private maybeSignalAllDone;
}
//# sourceMappingURL=sceneAnalysisJobRunner.d.ts.map