feat: route internal events through a shared plugin event bus

Formalises three ad-hoc publish paths that already existed:
automation-events.ts, metrics/automation-bridge.ts and the
hostSessionStatus singleton, now the host.session.status topic.

Both invariants the old code relied on are preserved. Publishing stays
fire-and-forget, so a failing subscriber cannot disturb a metrics poll or
a host delete. The automations engine subscribes to the bus at scheduler
start instead of being imported ad hoc, which keeps the edge
one-directional: automations may import repositories, hosts modules must
not import automations.
This commit is contained in:
LukeGus committed 2026-09-21 07:19:01 -05:00
1 parent 0a771c9600
commit 1393fa7581
9 files changed
+433 -52

No files matched your search

+13
View File
@@ -1,5 +1,12 @@
import { pluginEvents, TOPICS } from "../plugins/events.js";
type HostSessionStatusListener = (hostId: number, online: boolean) => void;
export interface HostSessionStatusPayload {
hostId: number;
online: boolean;
}
export class HostSessionStatus {
private counts = new Map<number, number>();
private listeners = new Set<HostSessionStatusListener>();
@@ -32,6 +39,12 @@ export class HostSessionStatus {
private emit(hostId: number, online: boolean): void {
for (const listener of this.listeners) listener(hostId, online);
// Also published as a topic so plugins (and anything else on the bus) can
// observe session status without holding a reference to this singleton.
pluginEvents.emit(TOPICS.hostSessionStatus, {
hostId,
online,
} satisfies HostSessionStatusPayload);
}
}