UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

36 lines (35 loc) • 1.31 kB
export var TurnState; (function (TurnState) { TurnState[TurnState["IDLE"] = 0] = "IDLE"; TurnState[TurnState["USER_SPEAKING"] = 1] = "USER_SPEAKING"; TurnState[TurnState["PROCESSING"] = 2] = "PROCESSING"; TurnState[TurnState["ASSISTANT_SPEAKING"] = 3] = "ASSISTANT_SPEAKING"; })(TurnState || (TurnState = {})); export class TurnManager { state = TurnState.IDLE; constructor(bus) { bus.subscribe("vad_start", () => this.onVadStart()); bus.subscribe("vad_stop", () => this.onVadStop()); } onVadStart() { // Only update state if TTS is NOT playing. During ASSISTANT_SPEAKING, the // barge-in interrupt is triggered by Soniox non-final tokens — which arrive // after a network round-trip. If we let VAD immediately flip state to // USER_SPEAKING, the state check in handleSonioxMessage fails and the // interrupt never fires. if (this.state !== TurnState.ASSISTANT_SPEAKING) { this.state = TurnState.USER_SPEAKING; } } onVadStop() { if (this.state === TurnState.USER_SPEAKING) { this.state = TurnState.PROCESSING; } } assistantSpeaking() { this.state = TurnState.ASSISTANT_SPEAKING; } reset() { this.state = TurnState.IDLE; } }