Skip to content

Types & interfaces

Every interface and type below is exported from the package root (import { RtpConfig } from "t140llm") unless noted otherwise. Steganography types live in a separate module — see Steganography.

Streams

TextDataStream

typescript
type TextDataStream = EventEmitter | AsyncIterable<unknown>;

The input every processor accepts. An EventEmitter emits data, end, error, and optionally metadata events; an AsyncIterable yields chunks (the shape most LLM SDK streams return). Both are consumed directly — no wrapping.

RtpConfig

The configuration object shared by every RTP/SRTP transport. All fields are optional.

FieldTypeMeaning
payloadTypenumberRTP payload type (default 96)
ssrcnumberSynchronization source (default: secure random)
initialSequenceNumbernumberStarting sequence number (default 0)
initialTimestampnumberStarting timestamp (default 0)
timestampIncrementnumberTimestamp increment per packet (default 160)
fecEnabledbooleanEnable Forward Error Correction (RFC 5109)
fecPayloadTypenumberPayload type for FEC packets (default 97)
fecGroupSizenumberMedia packets protected per FEC packet (default 3)
processBackspacesbooleanEnable T.140 backspace processing
charRateLimitnumberCharacter rate limit (chars/sec)
redEnabledbooleanEnable T.140 redundancy (RED)
redPayloadTypenumberPayload type for RED encoding
redundancyLevelnumberNumber of redundant T.140 blocks to include
customTransportTransportStreamUse instead of the default UDP socket
handleMetadatabooleanDetect and process LLM metadata
metadataCallback(m: LLMMetadata) => voidCalled for each metadata item
sendMetadataAsPacketsbooleanSend metadata as separate RTP packets
metadataPayloadTypenumberPayload type for metadata packets
multiplexEnabledbooleanEnable multiplexing multiple streams
streamIdentifierstringUnique ID for this stream in a multiplex
csrcListnumber[]Contributing source identifiers
useCsrcForStreamIdbooleanUse the CSRC field for stream identification
markerBitbooleanSet the RTP marker bit (RFC 4103 §5.1 M-bit, first packet after idle)
bomPrewarmbooleanSend BOM (U+FEFF) on transport creation to open NAT pinholes (RFC 4103)

SrtpConfig

Extends RtpConfig (minus charRateLimit) with the SRTP key material.

FieldTypeMeaning
masterKeyBufferRequired. SRTP master key
masterSaltBufferRequired. SRTP master salt
profileSrtpProtectionProfileCrypto profile (default profile 1)
isSRTCPbooleanTreat as SRTCP (default false)

SrtpProtectionProfile

Valid values per the IANA SRTP registry:

ValueProfile
0x0001SRTP_AES128_CM_HMAC_SHA1_80
0x0002SRTP_AES128_CM_HMAC_SHA1_32
0x0005SRTP_AEAD_AES_128_GCM
0x0006SRTP_AEAD_AES_256_GCM
0x0007DOUBLE_AEAD_AES_128_GCM_AEAD_AES_128_GCM
0x0008DOUBLE_AEAD_AES_256_GCM_AEAD_AES_256_GCM

TransportStream

Implement this to plug in a custom transport (WebRTC data channel, steganographic carrier, etc.). Pass it as RtpConfig.customTransport.

typescript
interface TransportStream {
  send(data: Buffer, callback?: (error?: Error) => void): void;
  close?(): void;
}

Processor options

Passed as the third argument to processAIStream and to attachStream on pre-created transports.

typescript
interface ProcessorOptions {
  processBackspaces?: boolean;
  handleMetadata?: boolean;
  metadataCallback?: (metadata: LLMMetadata) => void;
  sendMetadataOverTransport?: boolean;
  onError?: (error: Error) => void;
  preCreateConnection?: boolean;
}

AttachStreamOptions extends this with sendMetadataOverWebsocket?: boolean and tlsOptions?: TLSOptions.

Metadata

typescript
interface LLMMetadata {
  type: 'tool_call' | 'tool_result' | 'custom' | 'reasoning' | string;
  content: unknown;
  id?: string;
}

Emitted for tool calls, tool results, reasoning, and custom provider metadata. Enable with handleMetadata: true and receive via metadataCallback. See reasoning streams.

Errors

T140RtpTransport emits typed errors on its error event.

typescript
interface T140RtpError {
  type: T140RtpErrorType;
  message: string;
  cause?: Error;
}

T140RtpErrorType is an enum:

ValueWhen
NETWORK_ERRORUDP socket / network failures
ENCRYPTION_ERRORSRTP encryption failures
FEC_ERRORFEC packet creation failures
INVALID_CONFIGInvalid or missing configuration
RATE_LIMIT_ERRORRate-limit handling failures
RESOURCE_ERRORSocket allocation/deallocation failures
typescript
import { T140RtpErrorType } from "t140llm";

transport.on("error", (err) => {
  if (err.type === T140RtpErrorType.NETWORK_ERROR) { /* ... */ }
});

WebSocket options

typescript
interface TLSOptions {
  rejectUnauthorized?: boolean;
  ca?: string;
  cert?: string;
  key?: string;
}

interface WebSocketOptions {
  tlsOptions?: TLSOptions;
}

Released under the MIT License.