From 472a86698f60e165ac610dc6a340875e94b6f9e0 Mon Sep 17 00:00:00 2001 From: Sawyer Cutler Date: Mon, 21 Sep 2026 22:16:52 -0700 Subject: [PATCH] feat(mailbox): default mountMailbox's SSE bus to in-process (CL-8775) --- src/mount.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/mount.ts b/src/mount.ts index 4e6a09f..9bfaaff 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -8,6 +8,7 @@ import type { Thread } from "@intx/types/runtime"; import type { MailboxDb } from "./db.js"; import type { NativeMailboxStore } from "./native-store.js"; import { + createInMemoryMailboxEventBus, publishMailboxEvent, type MailboxEvent, type MailboxEventBus, @@ -30,7 +31,12 @@ export type OutgoingMailboxMessage = { export type MountMailboxOpts = { db: MailboxDb; - bus: MailboxEventBus; + /** + * SSE live-update bus only. Mail is Postgres. Defaults to an in-process + * bus (one hub process). Pass a shared bus if several hub processes must + * fan the same inbox events. + */ + bus?: MailboxEventBus; resolvePrincipal: ( ctx: unknown, ) => Promise | ResolvedPrincipal | null; @@ -202,7 +208,8 @@ export function mountMailbox( app: Hono, opts: MountMailboxOpts, ): Hono { - const { db, bus, resolvePrincipal, senderAddressFor, deliver } = opts; + const { db, resolvePrincipal, senderAddressFor, deliver } = opts; + const bus = opts.bus ?? createInMemoryMailboxEventBus(); const heartbeatIntervalMs = opts.heartbeatIntervalMs ?? DEFAULT_HEARTBEAT_INTERVAL_MS; if (!Number.isFinite(heartbeatIntervalMs) || heartbeatIntervalMs <= 0) {