@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
39 lines (38 loc) • 2.29 kB
TypeScript
/**
* Turns a live voice call's event stream into stored conversation turns.
*
* A realtime voice model reports a call as separate, loosely ordered events:
* final user transcripts, assistant text deltas, tool calls, and the added
* assistant message that closes a reply. This recorder groups them into
* exchanges and hands each finished exchange to a `write` function (normally
* `NeuroLink.recordConversationTurn`).
*
* It knows nothing about LiveKit, so it can be driven by a synthetic event
* stream in tests. The rules it applies:
*
* - An exchange is the user's final transcript(s) plus the assistant message
* that answers them. The assistant message's id is the exchange's `turnId`,
* which makes a retried write idempotent.
* - Settle rule. A user's final transcript can arrive after the assistant has
* started, or even finished, replying. A closed reply with no user text is
* held for `settleMs`; a transcript arriving in that window completes it.
* A reply still without user text after the window (the opening greeting,
* typically) is dropped, because a stored turn needs both sides.
* - A new user transcript arriving while the previous reply is still being
* spoken, and after that exchange already had user text, closes the
* previous exchange as interrupted (barge-in) and starts a new one.
* - `flush` is for shutdown. It closes the open exchange with what was said
* so far, marks it interrupted and call-ended, and appends a short note so
* a later reader knows the reply is incomplete. A user turn with no reply
* gets the note alone. The flush waits for pending writes only up to a
* budget, because the worker process is reaped about a second after the
* shutdown callbacks start.
* - Writes run strictly one at a time, in order. A failed write is retried;
* after the last retry it is reported through `onPermanentFailure` and the
* recorder carries on — a storage problem never stops a call.
*
* See docs/features/livekit-voice-agent.md.
*/
import type { VoiceTurnRecorder, VoiceTurnRecorderOptions } from "../../types/index.js";
/** Create a recorder for one call. */
export declare function createVoiceTurnRecorder(options: VoiceTurnRecorderOptions): VoiceTurnRecorder;