Current connection lifecycle state.
connecting -- WebSocket is open but the provider's start event has not arrived yet.open -- Stream is active; audio can be sent and received.closing -- close was called; waiting for WS to finish closing.closed -- Stream is fully terminated; no further I/O.Create a new telephony stream transport.
Wires up WebSocket event handlers immediately. The transport starts in
'connecting' state and transitions to 'open' when the provider sends
its start event through the media stream.
WebSocket-like object (must emit 'message', 'close', 'error'
and expose send(data) and close(code?, reason?) methods).
Provider-specific message parser/formatter.
Optional config: TelephonyStreamTransportConfigOptional configuration overrides.
Send synthesised audio to the caller.
Assumes chunk.format === 'pcm' and that chunk.audio contains raw
signed 16-bit little-endian PCM samples at chunk.sampleRate. The audio
is resampled to 8 kHz, mu-law encoded, and forwarded via the parser.
No-op if the transport is not in the 'open' state (e.g., before the
provider's start event or after the stream has closed).
Encoded audio chunk from the TTS pipeline.
Initiate graceful closure of the transport.
Sets state to 'closing' and delegates to the underlying WebSocket's
close() method. The actual transition to 'closed' happens when the
WebSocket's 'close' event fires.
Optional code: numberOptional WebSocket close code (default 1000).
Optional reason: stringOptional human-readable close reason.
Readonly idStable UUID for this transport connection.
Adapts a telephony provider WebSocket media stream to the
IStreamTransportinterface consumed by the AgentOS voice pipeline.Inbound path (phone -> pipeline)
Bufferor JSONstring.'audio'events: mu-law 8 kHz -> Int16 PCM -> resample -> Float32 ->'audio'emit.'dtmf'/'mark'events are re-emitted as-is for higher-layer handling.'start'transitions the transport to'open'and sends the optional connection acknowledgment from the parser.'stop'or WebSocket close transitions to'closed'and emits'close'.Outbound path (pipeline -> phone)
sendAudio()receives anEncodedAudioChunk(PCM Int16 format assumed).chunk.sampleRate-> 8 kHz via linear interpolation.Events emitted
'audio'(AudioFrame) -- inbound decoded audio for STT / VAD.'dtmf'({ digit: string; durationMs?: number }) -- caller key-press.'mark'({ name: string }) -- named stream marker.'close'() -- transport has been fully closed.'error'(Error) -- unrecoverable WebSocket or parsing error.Example