39 lines
964 B
TypeScript
39 lines
964 B
TypeScript
import { EventEmitter } from "node:events";
|
|
|
|
export type BossEventName =
|
|
| "conversation.updated"
|
|
| "project.messages.updated"
|
|
| "project.context_risk.updated"
|
|
| "app.logs.updated"
|
|
| "master_agent.task.updated"
|
|
| "devices.updated"
|
|
| "devices.skills.updated"
|
|
| "ota.updated";
|
|
|
|
export interface BossEventPayload {
|
|
at: string;
|
|
projectId?: string;
|
|
deviceId?: string;
|
|
taskId?: string;
|
|
status?: string;
|
|
note?: string;
|
|
}
|
|
|
|
type BossEventListener = (event: BossEventName, payload: BossEventPayload) => void;
|
|
|
|
const eventBus = new EventEmitter();
|
|
|
|
export function publishBossEvent(event: BossEventName, payload: Omit<BossEventPayload, "at"> = {}) {
|
|
eventBus.emit("boss-event", event, {
|
|
at: new Date().toISOString(),
|
|
...payload,
|
|
} satisfies BossEventPayload);
|
|
}
|
|
|
|
export function subscribeBossEvents(listener: BossEventListener) {
|
|
eventBus.on("boss-event", listener);
|
|
return () => {
|
|
eventBus.off("boss-event", listener);
|
|
};
|
|
}
|