import type { RuntimeEventEnvelope } from './envelope.js'; import type { AnyRuntimeEvent, RuntimeEventDomain, DomainEventMap } from '../../../events/domain-map.js'; export type { RuntimeEventEnvelope, EnvelopeContext } from './envelope.js'; export { createEventEnvelope } from './envelope.js'; export type { SessionEvent, SessionEventType } from '../../../events/session.js'; export type { TurnEvent, TurnEventType, TurnInputOrigin } from '../../../events/turn.js'; export type { ProviderEvent, ProviderEventType } from '../../../events/providers.js'; export type { ToolEvent, ToolEventType } from '../../../events/tools.js'; export type { TaskEvent, TaskEventType } from '../../../events/tasks.js'; export type { AgentEvent, AgentEventType } from '../../../events/agents.js'; export type { WorkflowEvent, WorkflowEventType } from '../../../events/workflows.js'; export type { OrchestrationEvent, OrchestrationEventType, OrchestrationTaskContract } from '../../../events/orchestration.js'; export type { CommunicationEvent, CommunicationEventType, CommunicationKind, CommunicationScope } from '../../../events/communication.js'; export type { PlannerEvent, PlannerEventType, WorkPlanEventBase, WorkPlanSnapshotEventRecord, WorkPlanTaskEventRecord, WorkPlanTaskStatus, } from '../../../events/planner.js'; export type { PermissionEvent, PermissionEventType } from '../../../events/permissions.js'; export type { PluginEvent, PluginEventType } from '../../../events/plugins.js'; export type { McpEvent, McpEventType } from '../../../events/mcp.js'; export type { TransportEvent, TransportEventType } from '../../../events/transport.js'; export type { CompactionEvent, CompactionEventType } from '../../../events/compaction.js'; export type { GoodVibesUIEvent, GoodVibesUIEventType } from '../../../events/ui.js'; export type { OpsEvent, OpsEventType } from '../../../events/ops.js'; export type { OpsInterventionReason } from '../../../events/ops.js'; export { RUNTIME_EVENT_DOMAINS, isRuntimeEventDomain } from '../../../events/domain-map.js'; export { registeredEventTypes, validateKnownEvent } from '../../../events/contracts.js'; export type { AnyRuntimeEvent, RuntimeEventPayload, RuntimeEventDomain, DomainEventMap, RuntimeEventRecord } from '../../../events/domain-map.js'; export type { AutomationEvent, AutomationEventType, AutomationScheduleKind, AutomationExecutionMode, AutomationRunOutcome } from '../../../events/automation.js'; export { AUTOMATION_SCHEDULE_KINDS, AUTOMATION_RUN_OUTCOMES } from '../../../events/automation.js'; export type { RouteEvent, RouteEventType, RouteSurfaceKind, RouteTargetKind } from '../../../events/routes.js'; export { ROUTE_SURFACE_KINDS, ROUTE_TARGET_KINDS } from '../../../events/routes.js'; export type { ControlPlaneEvent, ControlPlaneEventType, ControlPlaneClientKind, ControlPlaneTransportKind, ControlPlanePrincipalKind } from '../../../events/control-plane.js'; export { CONTROL_PLANE_CLIENT_KINDS, CONTROL_PLANE_TRANSPORT_KINDS, CONTROL_PLANE_PRINCIPAL_KINDS } from '../../../events/control-plane.js'; export type { DeliveryEvent, DeliveryEventType, DeliveryKind } from '../../../events/deliveries.js'; export { DELIVERY_KINDS } from '../../../events/deliveries.js'; export type { WatcherEvent, WatcherEventType, WatcherSourceKind } from '../../../events/watchers.js'; export { WATCHER_SOURCE_KINDS } from '../../../events/watchers.js'; export type { SurfaceEvent, SurfaceEventType, SurfaceKind } from '../../../events/surfaces.js'; export { SURFACE_KINDS } from '../../../events/surfaces.js'; export type { KnowledgeEvent, KnowledgeEventType } from '../../../events/knowledge.js'; export type { FleetEvent, FleetEventType, FleetNodeKind, FleetNodeState, FleetAttentionReason } from '../../../events/fleet.js'; export type { ConfigEvent, ConfigEventType, ConfigEventScope, ConfigEventValue } from '../../../events/config.js'; /** Listener callback receiving a fully-formed envelope. */ export type EnvelopeListener = (envelope: RuntimeEventEnvelope) => void; /** * Maximum listeners per channel before a potential memory leak warning is emitted. * * 100 is a generous threshold for a single event type or domain; normal usage * rarely exceeds single-digit listeners. Exceeding this strongly suggests a * subscriber is being registered without a corresponding unsubscribe. */ export declare const MAX_LISTENERS = 100; /** * Options accepted by the RuntimeEventBus constructor. */ export interface RuntimeEventBusOptions { /** * Override the maximum number of listeners per channel. * Defaults to MAX_LISTENERS (100). * Values above zero are accepted; the cap is applied per event-type channel * and per domain channel independently. */ maxListeners?: number | undefined; } /** * Point the default listener cap at the operator's configured value. * * Called once at startup by the host that owns the config (the standalone * daemon's `main()` and `resolveDaemonFacadeRuntime`), in the same place and for * the same reason `configureActivityLogger` is: the value exists only after a * ConfigManager does, and every bus built afterwards should honour it without * each construction site having to know the key. * * A value that is not a positive number leaves the current default in place. A * hand-edited settings file is the only way to get one, and a `NaN` cap would * silently switch the leak check off entirely, the opposite of what raising * the number is for. * * Buses built BEFORE this call keep the cap they were constructed with, and an * explicit `maxListeners` option always wins over the default. */ export declare function configureRuntimeEventBusDefaults(options: RuntimeEventBusOptions): void; /** * Read `runtime.eventBus.maxListeners` into bus options. * * Takes a plain key reader rather than a ConfigManager so this module keeps its * place below the config layer in the import graph. An absent or non-numeric * value yields empty options, which leaves the default cap alone. */ export declare function runtimeEventBusOptionsFrom(getConfig: (key: 'runtime.eventBus.maxListeners') => unknown): RuntimeEventBusOptions; /** * RuntimeEventBus, typed event bus for domain-structured runtime events. * * Supports two subscription modes: * - `on(eventType, callback)`, subscribe to a specific event type * - `onDomain(domain, callback)`, subscribe to all events in a domain * * All events are wrapped in a RuntimeEventEnvelope providing traceId, * sessionId, timestamps, and source context. * * This is the authoritative event transport for runtime domain signaling. * * DISPATCH ORDERING GUARANTEE (contract, pinned by * test/runtime-event-bus-dispatch-contract.test.ts): {@link RuntimeEventBus.emit} NEVER invokes * a subscriber synchronously. Each matching handler is deferred to its own * `queueMicrotask`, so emit() always returns to its caller, and the caller's * remaining synchronous statements run, BEFORE any listener fires. A component * may therefore emit an event from the MIDDLE of a state mutation without risk * that a subscriber observes the half-applied state: by the time a listener * runs, the mutating call has already completed and the state has settled. This * asynchronous-dispatch ordering is load-bearing for event-ordering safety * across the runtime (e.g. the orchestration zombie-reap path relies on * listeners never seeing a mutation mid-flight), do NOT replace queueMicrotask * with synchronous invocation. */ export declare class RuntimeEventBus { /** Per-event-type listener sets. Keyed by the exact event type string. */ private readonly _listeners; /** Per-domain listener sets. Keyed by RuntimeEventDomain. */ private readonly _domainListeners; /** Effective listener cap for this instance. */ private readonly _maxListeners; /** Track per-listener error counts for misbehaving-listener dedup. */ private readonly _listenerErrorCounts; /** Number of errors a listener must throw before OPS_LISTENER_MISBEHAVING is emitted. */ private static readonly _MISBEHAVE_DEDUP_THRESHOLD; constructor(opts?: RuntimeEventBusOptions); /** * Subscribe to a specific event type. * * @param eventType - The exact event type string to listen for. * @param callback - Called with the full envelope on each emission. * @returns An unsubscribe function. */ on(eventType: T['type'], callback: EnvelopeListener): () => void; /** * Subscribe to all events in a named domain. * * @param domain - Domain name (e.g. 'turn', 'tools', 'session'). * @param callback - Called with the full envelope for each domain event. * @returns An unsubscribe function. */ onDomain(domain: D, callback: EnvelopeListener): () => void; /** * Emit a runtime event envelope to all matching per-type and per-domain subscribers. * * Callers MUST use the typed emitter wrapper functions from * `platform/runtime/emitters/` rather than calling this method directly. * Direct usage bypasses domain-event type enforcement: TypeScript cannot * statically link the `domain` argument to the `envelope` payload type due * to union complexity limitations (TS2590), meaning mismatched pairs compile * without error. * * @see emitTurnSubmitted, emitToolReceived, etc. in `src/runtime/emitters/` * * Domain-keyed overload: when the domain is statically known, the envelope * type is narrowed to the corresponding DomainEventMap entry, no cast needed. * * @param domain - Domain this event belongs to. * @param envelope - The fully-formed envelope to dispatch. */ emit(domain: D, envelope: RuntimeEventEnvelope): void; /** * Record a listener error: increment metrics, update error count, emit * OPS_LISTENER_MISBEHAVING once the dedup threshold is reached, and log. * * @param listener - The misbehaving listener function. * @param eventType - The event type that triggered the listener. * @param err - The thrown value caught from the listener. * @param domain - Optional domain name, present when the listener was a domain subscriber. */ private _recordListenerError; /** * Directly dispatch an OPS_LISTENER_MISBEHAVING envelope to any registered * OPS_LISTENER_MISBEHAVING and 'ops' domain listeners. * * Bypasses emit() to avoid potential recursion: a listener watching for * misbehaving events itself misbehaving would otherwise cause infinite loops. */ private _emitListenerMisbehaving; private _off; private _offDomain; } //# sourceMappingURL=index.d.ts.map