2026-03-18 21:01:13 -04:00
|
|
|
import { EventEmitter } from "events";
|
|
|
|
|
|
|
|
|
|
export type JobEvent =
|
|
|
|
|
| { type: "job:state"; jobId: string; state: string }
|
|
|
|
|
| { type: "job:paid"; jobId: string; invoiceType: "eval" | "work" }
|
|
|
|
|
| { type: "job:completed"; jobId: string; result: string }
|
|
|
|
|
| { type: "job:failed"; jobId: string; reason: string };
|
|
|
|
|
|
|
|
|
|
export type SessionEvent =
|
|
|
|
|
| { type: "session:state"; sessionId: string; state: string }
|
|
|
|
|
| { type: "session:paid"; sessionId: string; amountSats: number }
|
|
|
|
|
| { type: "session:balance"; sessionId: string; balanceSats: number };
|
|
|
|
|
|
2026-03-23 01:07:52 +00:00
|
|
|
export type DebateEvent =
|
|
|
|
|
| { type: "debate:argument"; jobId: string; agent: "Beta-A" | "Beta-B"; position: "accept" | "reject"; argument: string }
|
|
|
|
|
| { type: "debate:verdict"; jobId: string; accepted: boolean; reason: string };
|
|
|
|
|
|
|
|
|
|
export type BusEvent = JobEvent | SessionEvent | DebateEvent;
|
2026-03-18 21:01:13 -04:00
|
|
|
|
|
|
|
|
class EventBus extends EventEmitter {
|
|
|
|
|
emit(event: "bus", data: BusEvent): boolean;
|
|
|
|
|
emit(event: string, ...args: unknown[]): boolean {
|
|
|
|
|
return super.emit(event, ...args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
on(event: "bus", listener: (data: BusEvent) => void): this;
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
on(event: string, listener: (...args: any[]) => void): this {
|
|
|
|
|
return super.on(event, listener);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
publish(data: BusEvent): void {
|
|
|
|
|
this.emit("bus", data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const eventBus = new EventBus();
|
|
|
|
|
eventBus.setMaxListeners(256);
|