/**
 * IngestorManager — owns and manages the lifecycle of all ingestor instances.
 *
 * Keyed by `callerAlias:connectionAlias:instanceId`, so each caller gets its
 * own ingestor instance (with its own secrets, buffer, and connection state).
 * Multiple sessions from the same caller share the same ingestor/buffer.
 *
 * Supports multi-instance listeners: when a caller defines `listenerInstances`
 * for a connection, one ingestor is spawned per instanceId (e.g., watching
 * multiple Trello boards or multiple Reddit subreddits simultaneously).
 *
 * The manager is created once when the remote server starts, and provides
 * event retrieval and status methods used by the `poll_events` and
 * `ingestor_status` tool handlers.
 */
import { type IngestorOverrides, type RemoteServerConfig, type ListenerConfigField } from '../../shared/config.js';
import type { IngestedEvent, IngestorConfig, IngestorStatus } from './types.js';
import { WebhookIngestor } from './webhook/base-webhook-ingestor.js';
import './discord/discord-gateway.js';
import './slack/socket-mode.js';
import './webhook/github-webhook-ingestor.js';
import './webhook/stripe-webhook-ingestor.js';
import './webhook/trello-webhook-ingestor.js';
import './poll/poll-ingestor.js';
/** Sentinel instance ID used for single-instance (default) connections. */
declare const DEFAULT_INSTANCE_ID = "_default";
/** Build a composite ingestor map key. */
declare function makeKey(caller: string, connection: string, instance?: string): string;
/** Parse a composite ingestor map key. */
declare function parseKey(key: string): {
    caller: string;
    connection: string;
    instance: string;
};
interface LifecycleResult {
    success: boolean;
    connection: string;
    instanceId?: string;
    state?: string;
    error?: string;
}
export declare class IngestorManager {
    private readonly config;
    /** Active ingestor instances, keyed by `callerAlias:connectionAlias:instanceId`. */
    private ingestors;
    /** Trigger rule engines per caller. Created during startAll() for callers with triggerRules. */
    private triggerEngines;
    /** Global event listeners (e.g. SSE streams). Called for every event from every ingestor. */
    private eventListeners;
    /**
     * Optional config loader for hot-reload support. When provided, `startOne()`
     * uses it to get fresh config from disk instead of the constructor snapshot.
     */
    private configLoader;
    constructor(config: RemoteServerConfig, configLoader?: () => RemoteServerConfig);
    /** Return fresh config if a loader is available, otherwise the constructor snapshot. */
    private getConfig;
    /**
     * Start ingestors for all callers whose connections have an `ingestor` config.
     * Called once when the remote server starts listening.
     *
     * For connections with `listenerInstances`, spawns one ingestor per instanceId.
     * For connections without, spawns a single default instance (backward compatible).
     */
    startAll(): Promise<void>;
    /**
     * Internal: create, register, and start a single ingestor instance.
     */
    private startIngestor;
    /**
     * Initialize trigger rule engines for callers with triggerRules config.
     * Subscribes to 'event' emissions from matching ingestors and dispatches
     * to Claude Code remote triggers.
     */
    private initTriggerEngines;
    /**
     * Stop all running ingestors. Called during graceful shutdown.
     */
    stopAll(): Promise<void>;
    /**
     * Get events for a specific caller and connection, optionally filtered by instance.
     * When instanceId is omitted, aggregates events from all instances of that connection.
     */
    getEvents(callerAlias: string, connectionAlias: string, afterId?: number, instanceId?: string): IngestedEvent[];
    /**
     * Get events across all ingestors for a caller, sorted chronologically.
     * @param callerAlias  The caller whose events to retrieve.
     * @param afterId  Return events with id > afterId. Pass -1 for all.
     */
    getAllEvents(callerAlias: string, afterId?: number): IngestedEvent[];
    /**
     * Get status of all ingestors for a caller.
     */
    getStatuses(callerAlias: string): IngestorStatus[];
    /**
     * Subscribe to all events from all ingestors (current and future).
     * Used by the SSE /events/stream endpoint to fan out events to CLI watchers.
     */
    onEvent(listener: (event: IngestedEvent) => void): void;
    /** Unsubscribe a global event listener. */
    offEvent(listener: (event: IngestedEvent) => void): void;
    /** Forward an ingestor event to all global listeners. */
    private notifyEventListeners;
    /**
     * Find all webhook ingestor instances that match a given webhook path.
     * Returns all matching instances across all callers (for fan-out dispatch).
     *
     * @param path - The webhook path segment (e.g., 'github' from /webhooks/github).
     */
    getWebhookIngestors(path: string): WebhookIngestor[];
    /**
     * Start a single ingestor for a specific caller+connection pair.
     * When instanceId is provided, starts that specific instance.
     * When omitted, starts the default instance (or all instances if listenerInstances is defined).
     */
    startOne(callerAlias: string, connectionAlias: string, instanceId?: string): Promise<LifecycleResult | LifecycleResult[]>;
    /** Internal: start a single specific instance. */
    private startOneInstance;
    /**
     * Stop a single ingestor for a specific caller+connection pair.
     * When instanceId is provided, stops that specific instance.
     * When omitted, stops all instances of that connection.
     */
    stopOne(callerAlias: string, connectionAlias: string, instanceId?: string, options?: {
        permanent?: boolean;
    }): Promise<LifecycleResult | LifecycleResult[]>;
    /** Internal: stop a single specific instance. */
    private stopOneInstance;
    /**
     * Restart a single ingestor (stop + start). Useful after configuration changes.
     */
    restartOne(callerAlias: string, connectionAlias: string, instanceId?: string): Promise<LifecycleResult | LifecycleResult[]>;
    /**
     * Check if an ingestor exists (running or otherwise) for a caller+connection pair.
     * When instanceId is provided, checks that specific instance.
     * When omitted, checks if any instance exists for that connection.
     */
    has(callerAlias: string, connectionAlias: string, instanceId?: string): boolean;
    /**
     * Merge caller-level ingestor overrides into a copy of the template config.
     * Override fields replace template values; omitted fields inherit the template defaults.
     */
    static mergeIngestorConfig(templateConfig: IngestorConfig, overrides?: IngestorOverrides): IngestorConfig;
    /**
     * Apply instance-specific params from IngestorOverrides to the effective config and secrets.
     *
     * For each param, checks the connection's listenerConfig fields:
     *   - If the field has `overrideKey`, injects `params[key]` as `secrets[overrideKey]`
     *     (used by poll ingestors for URL template resolution, e.g., REDDIT_SUBREDDIT).
     *   - If the field has `instanceKey` and the config is a webhook, attaches
     *     the value to the webhook config for payload discrimination (e.g., _boardId for Trello).
     *   - Otherwise, attaches the value as a generic `_instanceParams` bag on the config.
     */
    static applyInstanceParams(config: IngestorConfig, secrets: Record<string, string>, params: Record<string, unknown>, fields: ListenerConfigField[]): void;
}
export { makeKey, parseKey, DEFAULT_INSTANCE_ID };
//# sourceMappingURL=manager.d.ts.map