/**
 * EventBus - Normalized event stream for the runtime.
 *
 * The EventBus provides:
 * - Publish/subscribe for normalized events
 * - Event history for recent event lookups
 * - Filtering by name, pattern, or source
 */
import type { EventHistory } from './history';
import type { EmitResult, EventCallback, EventFilter, EventUnsubscribe, NormalizedEvent } from './types';
export interface EventBusOptions {
    /** Maximum number of events to keep in history */
    maxHistorySize?: number;
    /** Enable debug mode — emit() returns EmitResult and logs to console */
    debug?: boolean;
    /** EventHistory instance for recording emitted events (debug/test) */
    history?: EventHistory;
    /** PostHog capture function for forwarding custom events */
    posthogCapture?: (name: string, props?: Record<string, unknown>) => void;
    /** When true, skip PostHog forwarding (for tests) */
    testMode?: boolean;
}
/**
 * EventBus class for managing normalized events.
 */
export declare class EventBus {
    private subscriptions;
    private history;
    private maxHistorySize;
    private debug;
    private emitHistory;
    private posthogCapture;
    private testMode;
    constructor(options?: EventBusOptions);
    /**
     * Subscribe to events matching an optional filter.
     * Returns an unsubscribe function.
     */
    subscribe(filterOrCallback: EventFilter | EventCallback, maybeCallback?: EventCallback): EventUnsubscribe;
    /**
     * Publish an event to all matching subscribers.
     */
    publish(name: string, props?: Record<string, unknown>, source?: NormalizedEvent['source']): void;
    /**
     * Publish a pre-constructed NormalizedEvent.
     */
    publishEvent(event: NormalizedEvent): void;
    /**
     * Emit a validated custom event from the host application.
     *
     * Custom events must use the `app:` prefix (e.g. `app:cart:abandoned`).
     * In debug mode, returns an EmitResult with delivery details.
     * In production mode, returns undefined.
     */
    emit(name: string, props?: Record<string, unknown>): EmitResult | undefined;
    /**
     * Set the PostHog capture function after construction.
     * Used by bootstrap to wire PostHog after the EventBus is created.
     */
    setPosthogCapture(fn: (name: string, props?: Record<string, unknown>) => void): void;
    /**
     * Get recent events matching an optional filter.
     */
    getRecent(filter?: EventFilter, limit?: number): NormalizedEvent[];
    /**
     * Check if an event with a specific name occurred within a time window.
     */
    hasRecentEvent(eventName: string, withinMs: number, source?: NormalizedEvent['source']): boolean;
    /**
     * Count events matching a filter within a time window.
     */
    countRecentEvents(filter: EventFilter, withinMs?: number): number;
    /**
     * Clear all event history.
     */
    clearHistory(): void;
    /**
     * Get the number of current subscribers.
     */
    getSubscriberCount(): number;
}
/**
 * Create an EventBus instance.
 */
export declare function createEventBus(options?: EventBusOptions): EventBus;
