/**
 * Centralized event emitter — single emitEvent() entry point.
 *
 * All gateway event producers call emitEvent(). Internally:
 * 1. Writes to local SQLite (synchronous via node:sqlite DatabaseSync)
 * 2. Broadcasts "events.new" to connected WebSocket clients
 * 3. Rate-limits high-frequency categories (tool, message)
 *
 * initEventSystem() is the full lifecycle wrapper called by server.impl.ts:
 * - Creates EventStore
 * - Replays crash journal into event store
 * - Starts retention cleanup (immediate + daily)
 * - Monitors DB size
 * - Optionally starts TursoSyncEngine
 * - Returns async shutdown that flushes sync before closing
 *
 * Singleton pattern matching existing reliability.ts style.
 *
 * @module
 */
import { type EventStore } from "./store.js";
import { type HeartbeatPayload } from "./turso-sync.js";
import type { EventInput, EventStoreConfig } from "./types.js";
export type { HeartbeatPayload } from "./turso-sync.js";
export type EventEmitterHandle = {
    store: EventStore;
    shutdown: () => void;
};
/**
 * Initialize the event emitter singleton. Call once at gateway startup.
 *
 * @param config.storeConfig - EventStoreConfig for local SQLite
 * @param config.broadcast - Optional broadcast function for WebSocket events
 */
export declare function initEventEmitter(config: {
    storeConfig: EventStoreConfig;
    broadcast?: (event: string, payload: unknown, opts?: {
        dropIfSlow?: boolean;
    }) => void;
}): EventEmitterHandle;
/**
 * Emit an event. Safe to call from any context — never throws.
 *
 * Writes to local SQLite, broadcasts to WebSocket clients, and
 * rate-limits high-frequency categories (tool, message).
 */
export declare function emitEvent(input: EventInput): void;
/**
 * Get the event store instance, or null if not initialized.
 */
export declare function getEventStore(): EventStore | null;
/**
 * Shut down the event emitter. Closes store and clears state.
 */
export declare function shutdown(): void;
export type EventSystemHandle = {
    /** Async shutdown: flushes Turso sync, stops cleanup, closes store. */
    shutdown: () => Promise<void>;
    /** Push a heartbeat payload to Turso (no-op if Turso not configured). */
    pushHeartbeat: (heartbeat: HeartbeatPayload) => void;
};
export type EventSystemConfig = {
    storeConfig: EventStoreConfig;
    broadcast?: (event: string, payload: unknown, opts?: {
        dropIfSlow?: boolean;
    }) => void;
    /** Gateway state directory for crash journal replay. */
    stateDir?: string;
    /** Turso URL for write-behind sync. If absent, sync is skipped. */
    tursoUrl?: string;
    /** Turso auth token. */
    tursoAuthToken?: string;
    /** Hub-assigned server ID (required for Turso sync). */
    serverId?: string;
    /** Sync interval to Turso in ms. Default: 30000. */
    syncIntervalMs?: number;
    /** Events per sync batch. Default: 500. */
    syncBatchSize?: number;
};
/**
 * Initialize the full event system. Call once at gateway startup.
 *
 * - Creates local EventStore
 * - Replays crash journal entries as "crash" events
 * - Runs retention cleanup immediately and schedules daily
 * - Checks DB size and emits warning if above threshold
 * - Optionally starts TursoSyncEngine for write-behind
 *
 * Returns an async shutdown handle.
 */
export declare function initEventSystem(config: EventSystemConfig): Promise<EventSystemHandle>;
