Singleton SSE event bus that deduplicates gateway events and broadcasts processed events to N clients. Solves the N-listener duplication problem by funneling all gateway events through one listener then broadcasting.
// Source: https://github.com/outsourc-e/clawsuite | License: MIT | Copyright 2026 Eric (outsourc-e)
// Provided via justclaw.it.com; keep this notice with the code.
/**
* Singleton event bus for chat SSE events.
*
* Architecture: ONE gateway listener → processes/deduplicates → broadcasts to N SSE clients.
* Previously each SSE connection registered its own onGatewayEvent listener,
* causing 1 gateway event × N listeners = N duplicate emissions.
*
* Now: 1 gateway event → 1 listener → 1 processed event → broadcast to N clients.
*/
import {
onGatewayEvent,
gatewayConnectCheck,
hasActiveSendRun,
} from './gateway'
import type { GatewayFrame } from './gateway'
export interface ChatSSEEvent {
event: string
data: Record<string, unknown>
}
type ChatSSESubscriber = (event: Cha
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key