import { EventEmitter } from 'events'

export type VoiceEventPayload = {
  event: 'wake' | 'command' | 'response' | 'idle' | 'error'
  agent?: 'cosmo' | 'lusya'
  text?: string
  timestamp: string
}

// Singleton across hot-reloads in dev, preserved via global.
const globalForBus = globalThis as unknown as { __voiceBus?: EventEmitter }
export const voiceBus: EventEmitter = globalForBus.__voiceBus ?? new EventEmitter()
voiceBus.setMaxListeners(32)
if (!globalForBus.__voiceBus) globalForBus.__voiceBus = voiceBus
