Skip to content

@callagent/web-sdk ​

Classes ​

AudioPlayer ​

Defined in: apps/web-sdk/src/audio/player.ts:31

Constructors ​

Constructor ​
ts
new AudioPlayer(options): AudioPlayer;

Defined in: apps/web-sdk/src/audio/player.ts:42

Parameters ​
ParameterType
optionsAudioPlayerOptions
Returns ​

AudioPlayer

Accessors ​

context ​
Get Signature ​
ts
get context(): AudioContext | null;

Defined in: apps/web-sdk/src/audio/player.ts:55

Returns ​

AudioContext | null

generation ​
Get Signature ​
ts
get generation(): number;

Defined in: apps/web-sdk/src/audio/player.ts:74

Increments once per interruption; exposed so specs can assert the boundary moved.

Returns ​

number

isSpeaking ​
Get Signature ​
ts
get isSpeaking(): boolean;

Defined in: apps/web-sdk/src/audio/player.ts:46

Returns ​

boolean

pendingSourceCount ​
Get Signature ​
ts
get pendingSourceCount(): number;

Defined in: apps/web-sdk/src/audio/player.ts:51

Queued-but-unplayed sources. Exposed so specs can assert an interrupt drained.

Returns ​

number

Methods ​

clear() ​
ts
clear(): void;

Defined in: apps/web-sdk/src/audio/player.ts:120

Stop immediately and discard everything queued. Called on the gateway's clear control frame and on hangup.

Returns ​

void

close() ​
ts
close(): Promise<void>;

Defined in: apps/web-sdk/src/audio/player.ts:146

Returns ​

Promise<void>

enqueue() ​
ts
enqueue(pcm): void;

Defined in: apps/web-sdk/src/audio/player.ts:78

Parameters ​
ParameterType
pcmInt16Array
Returns ​

void

resume() ​
ts
resume(): Promise<void>;

Defined in: apps/web-sdk/src/audio/player.ts:63

Must be called from a user gesture on Safari and Chrome, otherwise the context starts suspended and the first assistant reply is silent.

Returns ​

Promise<void>

setVolume() ​
ts
setVolume(volume): void;

Defined in: apps/web-sdk/src/audio/player.ts:68

Parameters ​
ParameterType
volumenumber
Returns ​

void


Backoff ​

Defined in: apps/web-sdk/src/backoff.ts:14

Exponential backoff with jitter, deterministic under an injected RNG so the reconnection specs can assert exact delays instead of sleeping.

Constructors ​

Constructor ​
ts
new Backoff(options?, random?): Backoff;

Defined in: apps/web-sdk/src/backoff.ts:23

Parameters ​
ParameterTypeDefault value
optionsBackoffOptions{}
random() => numberMath.random
Returns ​

Backoff

Accessors ​

attempt ​
Get Signature ​
ts
get attempt(): number;

Defined in: apps/web-sdk/src/backoff.ts:32

Returns ​

number

exhausted ​
Get Signature ​
ts
get exhausted(): boolean;

Defined in: apps/web-sdk/src/backoff.ts:36

Returns ​

boolean

Methods ​

next() ​
ts
next(): number;

Defined in: apps/web-sdk/src/backoff.ts:45

Consumes one attempt and returns how long to wait before it.

Returns ​

number

reset() ​
ts
reset(): void;

Defined in: apps/web-sdk/src/backoff.ts:40

Returns ​

void


Call ​

Defined in: apps/web-sdk/src/call.ts:55

One live session: voice or chat, WebRTC or WebSocket.

The public surface is deliberately small — mute, unmute, send, stop and the event stream — because everything else about the conversation is decided server-side where it can be logged, billed and replayed.

Extends ​

Constructors ​

Constructor ​
ts
new Call(deps, startOptions): Call;

Defined in: apps/web-sdk/src/call.ts:75

Parameters ​
ParameterType
depsCallDependencies
startOptionsStartCallOptions
Returns ​

Call

Overrides ​

Emitter.constructor

Accessors ​

id ​
Get Signature ​
ts
get id(): string;

Defined in: apps/web-sdk/src/call.ts:81

Returns ​

string

isAssistantSpeaking ​
Get Signature ​
ts
get isAssistantSpeaking(): boolean;

Defined in: apps/web-sdk/src/call.ts:106

True while assistant audio is actually reaching the speakers.

Returns ​

boolean

isMuted ​
Get Signature ​
ts
get isMuted(): boolean;

Defined in: apps/web-sdk/src/call.ts:97

Returns ​

boolean

mode ​
Get Signature ​
ts
get mode(): "voice" | "chat";

Defined in: apps/web-sdk/src/call.ts:101

Returns ​

"voice" | "chat"

sessionId ​
Get Signature ​
ts
get sessionId(): string;

Defined in: apps/web-sdk/src/call.ts:85

Returns ​

string

state ​
Get Signature ​
ts
get state(): 
  | "created"
  | "queued"
  | "ringing"
  | "connecting"
  | "connected"
  | "listening"
  | "user_speaking"
  | "thinking"
  | "tool_executing"
  | "assistant_speaking"
  | "on_hold"
  | "transferring"
  | "human_queue"
  | "human_connected"
  | "ending"
  | "ended"
  | "failed";

Defined in: apps/web-sdk/src/call.ts:89

Returns ​

| "created" | "queued" | "ringing" | "connecting" | "connected" | "listening" | "user_speaking" | "thinking" | "tool_executing" | "assistant_speaking" | "on_hold" | "transferring" | "human_queue" | "human_connected" | "ending" | "ended" | "failed"

transport ​
Get Signature ​
ts
get transport(): TransportKind;

Defined in: apps/web-sdk/src/call.ts:93

Returns ​

TransportKind

Methods ​

emit() ​
ts
emit<K>(event, payload): void;

Defined in: apps/web-sdk/src/emitter.ts:47

A throwing listener must never take the call down with it — customer page code is on the other end of these callbacks.

Type Parameters ​
Type Parameter
K extends keyof CallEvents
Parameters ​
ParameterType
eventK
payloadCallEvents[K]
Returns ​

void

Inherited from ​

Emitter.emit

listenerCount() ​
ts
listenerCount<K>(event): number;

Defined in: apps/web-sdk/src/emitter.ts:39

Type Parameters ​
Type Parameter
K extends keyof CallEvents
Parameters ​
ParameterType
eventK
Returns ​

number

Inherited from ​

Emitter.listenerCount

mute() ​
ts
mute(): void;

Defined in: apps/web-sdk/src/call.ts:212

Returns ​

void

off() ​
ts
off<K>(event, listener): void;

Defined in: apps/web-sdk/src/emitter.ts:31

Type Parameters ​
Type Parameter
K extends keyof CallEvents
Parameters ​
ParameterType
eventK
listenerListener<CallEvents[K]>
Returns ​

void

Inherited from ​

Emitter.off

on() ​
ts
on<K>(event, listener): () => void;

Defined in: apps/web-sdk/src/emitter.ts:13

Type Parameters ​
Type Parameter
K extends keyof CallEvents
Parameters ​
ParameterType
eventK
listenerListener<CallEvents[K]>
Returns ​

() => void

Inherited from ​

Emitter.on

once() ​
ts
once<K>(event, listener): () => void;

Defined in: apps/web-sdk/src/emitter.ts:23

Type Parameters ​
Type Parameter
K extends keyof CallEvents
Parameters ​
ParameterType
eventK
listenerListener<CallEvents[K]>
Returns ​

() => void

Inherited from ​

Emitter.once

removeAllListeners() ​
ts
removeAllListeners(): void;

Defined in: apps/web-sdk/src/emitter.ts:35

Returns ​

void

Inherited from ​

Emitter.removeAllListeners

send() ​
ts
send(content): void;

Defined in: apps/web-sdk/src/call.ts:225

Sends a typed message. Works in both chat and voice mode.

Parameters ​
ParameterType
contentstring
Returns ​

void

sendDtmf() ​
ts
sendDtmf(digits): void;

Defined in: apps/web-sdk/src/call.ts:232

The gateway takes one digit per frame, so a string is sent digit by digit.

Parameters ​
ParameterType
digitsstring
Returns ​

void

setMuted() ​
ts
setMuted(muted): void;

Defined in: apps/web-sdk/src/call.ts:220

Parameters ​
ParameterType
mutedboolean
Returns ​

void

setVolume() ​
ts
setVolume(volume): void;

Defined in: apps/web-sdk/src/call.ts:238

0…1. Applies to both the WebSocket player and the WebRTC element.

Parameters ​
ParameterType
volumenumber
Returns ​

void

stop() ​
ts
stop(reason?): Promise<void>;

Defined in: apps/web-sdk/src/call.ts:206

Parameters ​
ParameterTypeDefault value
reasonstring'client_hangup'
Returns ​

Promise<void>

unmute() ​
ts
unmute(): void;

Defined in: apps/web-sdk/src/call.ts:216

Returns ​

void


CallAgent ​

Defined in: apps/web-sdk/src/client.ts:33

The entry point.

ts
const client = new CallAgent({ publicKey, apiUrl });
client.on('client-tool', async ({ name, arguments: args }) => { … });
const call = await client.start({ assistantId, variables });

One client can start many calls; it owns the token lifecycle and the client-tool registry, both of which outlive an individual call.

Extends ​

Constructors ​

Constructor ​
ts
new CallAgent(options): CallAgent;

Defined in: apps/web-sdk/src/client.ts:41

Parameters ​
ParameterType
optionsCallAgentOptions
Returns ​

CallAgent

Overrides ​

Emitter.constructor

Accessors ​

activeCall ​
Get Signature ​
ts
get activeCall(): Call | null;

Defined in: apps/web-sdk/src/client.ts:78

Returns ​

Call | null

apiUrl ​
Get Signature ​
ts
get apiUrl(): string;

Defined in: apps/web-sdk/src/client.ts:74

Returns ​

string

Methods ​

dispose() ​
ts
dispose(): void;

Defined in: apps/web-sdk/src/client.ts:168

Releases the refresh timer. Call it when the page tears the client down.

Returns ​

void

emit() ​
ts
emit<K>(event, payload): void;

Defined in: apps/web-sdk/src/emitter.ts:47

A throwing listener must never take the call down with it — customer page code is on the other end of these callbacks.

Type Parameters ​
Type Parameter
K extends keyof CallAgentEvents
Parameters ​
ParameterType
eventK
payloadCallAgentEvents[K]
Returns ​

void

Inherited from ​

Emitter.emit

listenerCount() ​
ts
listenerCount<K>(event): number;

Defined in: apps/web-sdk/src/emitter.ts:39

Type Parameters ​
Type Parameter
K extends keyof CallAgentEvents
Parameters ​
ParameterType
eventK
Returns ​

number

Inherited from ​

Emitter.listenerCount

off() ​
ts
off<K>(event, listener): void;

Defined in: apps/web-sdk/src/emitter.ts:31

Type Parameters ​
Type Parameter
K extends keyof CallAgentEvents
Parameters ​
ParameterType
eventK
listenerListener<CallAgentEvents[K]>
Returns ​

void

Inherited from ​

Emitter.off

on() ​
ts
on<K>(event, listener): () => void;

Defined in: apps/web-sdk/src/client.ts:98

Type Parameters ​
Type Parameter
K extends keyof CallAgentEvents
Parameters ​
ParameterType
eventK
listener(payload) => void
Returns ​

() => void

Overrides ​

Emitter.on

once() ​
ts
once<K>(event, listener): () => void;

Defined in: apps/web-sdk/src/emitter.ts:23

Type Parameters ​
Type Parameter
K extends keyof CallAgentEvents
Parameters ​
ParameterType
eventK
listenerListener<CallAgentEvents[K]>
Returns ​

() => void

Inherited from ​

Emitter.once

registerTool() ​
ts
registerTool(name, handler): () => void;

Defined in: apps/web-sdk/src/client.ts:91

Registers a handler for a specific client-side tool (§32). Named registration wins over a generic on('client-tool') handler.

Parameters ​
ParameterType
namestring
handlerClientToolHandler
Returns ​

() => void

removeAllListeners() ​
ts
removeAllListeners(): void;

Defined in: apps/web-sdk/src/emitter.ts:35

Returns ​

void

Inherited from ​

Emitter.removeAllListeners

start() ​
ts
start(options?): Promise<Call>;

Defined in: apps/web-sdk/src/client.ts:117

Parameters ​
ParameterType
optionsStartCallOptions
Returns ​

Promise<Call>

startChat() ​
ts
startChat(options?): Promise<Call>;

Defined in: apps/web-sdk/src/client.ts:158

Chat-only session: same protocol, same events, no microphone or speaker.

Parameters ​
ParameterType
optionsOmit<StartCallOptions, "mode">
Returns ​

Promise<Call>

stop() ​
ts
stop(reason?): Promise<void>;

Defined in: apps/web-sdk/src/client.ts:162

Parameters ​
ParameterTypeDefault value
reasonstring'client_hangup'
Returns ​

Promise<void>


CallAgentError ​

Defined in: apps/web-sdk/src/errors.ts:38

Extends ​

  • Error

Constructors ​

Constructor ​
ts
new CallAgentError(options): CallAgentError;

Defined in: apps/web-sdk/src/errors.ts:44

Parameters ​
ParameterType
optionsCallAgentErrorOptions
Returns ​

CallAgentError

Overrides ​
ts
Error.constructor

Properties ​

PropertyModifierTypeDescriptionInherited fromDefined in
cause?publicunknown-Error.causenode_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26
codereadonlyCallAgentErrorCode--apps/web-sdk/src/errors.ts:39
details?readonlyRecord<string, unknown>--apps/web-sdk/src/errors.ts:42
documentationUrl?readonlystring--apps/web-sdk/src/errors.ts:41
messagepublicstring-Error.messagenode_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1077
namepublicstring-Error.namenode_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1076
retryablereadonlyboolean--apps/web-sdk/src/errors.ts:40
stack?publicstring-Error.stacknode_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1078
stackTraceLimitstaticnumberThe Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames.Error.stackTraceLimitnode_modules/.pnpm/@types+node@22.20.1/node_modules/@types/node/globals.d.ts:68

Methods ​

captureStackTrace() ​
ts
static captureStackTrace(targetObject, constructorOpt?): void;

Defined in: node_modules/.pnpm/@types+node@22.20.1/node_modules/@types/node/globals.d.ts:52

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

js
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

js
function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();
Parameters ​
ParameterType
targetObjectobject
constructorOpt?Function
Returns ​

void

Inherited from ​
ts
Error.captureStackTrace
from() ​
ts
static from(value, fallback?): CallAgentError;

Defined in: apps/web-sdk/src/errors.ts:53

Parameters ​
ParameterTypeDefault value
valueunknownundefined
fallbackCallAgentErrorCode'server_error'
Returns ​

CallAgentError

prepareStackTrace() ​
ts
static prepareStackTrace(err, stackTraces): any;

Defined in: node_modules/.pnpm/@types+node@22.20.1/node_modules/@types/node/globals.d.ts:56

Parameters ​
ParameterType
errError
stackTracesCallSite[]
Returns ​

any

See ​

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from ​
ts
Error.prepareStackTrace

Emitter ​

Defined in: apps/web-sdk/src/emitter.ts:10

Extended by ​

Type Parameters ​

Type Parameter
Events extends Record<string, unknown>

Constructors ​

Constructor ​
ts
new Emitter<Events>(): Emitter<Events>;
Returns ​

Emitter<Events>

Methods ​

emit() ​
ts
emit<K>(event, payload): void;

Defined in: apps/web-sdk/src/emitter.ts:47

A throwing listener must never take the call down with it — customer page code is on the other end of these callbacks.

Type Parameters ​
Type Parameter
K extends string | number | symbol
Parameters ​
ParameterType
eventK
payloadEvents[K]
Returns ​

void

listenerCount() ​
ts
listenerCount<K>(event): number;

Defined in: apps/web-sdk/src/emitter.ts:39

Type Parameters ​
Type Parameter
K extends string | number | symbol
Parameters ​
ParameterType
eventK
Returns ​

number

off() ​
ts
off<K>(event, listener): void;

Defined in: apps/web-sdk/src/emitter.ts:31

Type Parameters ​
Type Parameter
K extends string | number | symbol
Parameters ​
ParameterType
eventK
listenerListener<Events[K]>
Returns ​

void

on() ​
ts
on<K>(event, listener): () => void;

Defined in: apps/web-sdk/src/emitter.ts:13

Type Parameters ​
Type Parameter
K extends string | number | symbol
Parameters ​
ParameterType
eventK
listenerListener<Events[K]>
Returns ​

() => void

once() ​
ts
once<K>(event, listener): () => void;

Defined in: apps/web-sdk/src/emitter.ts:23

Type Parameters ​
Type Parameter
K extends string | number | symbol
Parameters ​
ParameterType
eventK
listenerListener<Events[K]>
Returns ​

() => void

removeAllListeners() ​
ts
removeAllListeners(): void;

Defined in: apps/web-sdk/src/emitter.ts:35

Returns ​

void


FrameAccumulator ​

Defined in: apps/web-sdk/src/audio/pcm.ts:57

Accumulates arbitrary-length chunks and emits exactly frameSamples at a time.

Constructors ​

Constructor ​
ts
new FrameAccumulator(frameSamples): FrameAccumulator;

Defined in: apps/web-sdk/src/audio/pcm.ts:61

Parameters ​
ParameterType
frameSamplesnumber
Returns ​

FrameAccumulator

Methods ​

push() ​
ts
push(chunk): Float32Array<ArrayBufferLike>[];

Defined in: apps/web-sdk/src/audio/pcm.ts:65

Parameters ​
ParameterType
chunkFloat32Array
Returns ​

Float32Array<ArrayBufferLike>[]

reset() ​
ts
reset(): void;

Defined in: apps/web-sdk/src/audio/pcm.ts:89

Returns ​

void


Microphone ​

Defined in: apps/web-sdk/src/audio/microphone.ts:95

Constructors ​

Constructor ​
ts
new Microphone(options): Microphone;

Defined in: apps/web-sdk/src/audio/microphone.ts:106

Parameters ​
ParameterType
optionsMicrophoneOptions
Returns ​

Microphone

Accessors ​

muted ​
Get Signature ​
ts
get muted(): boolean;

Defined in: apps/web-sdk/src/audio/microphone.ts:114

Returns ​

boolean

stream ​
Get Signature ​
ts
get stream(): MediaStream | null;

Defined in: apps/web-sdk/src/audio/microphone.ts:110

Returns ​

MediaStream | null

Methods ​

close() ​
ts
close(): Promise<void>;

Defined in: apps/web-sdk/src/audio/microphone.ts:222

Returns ​

Promise<void>

open() ​
ts
open(): Promise<MediaStream>;

Defined in: apps/web-sdk/src/audio/microphone.ts:130

Acquires the device. Throws a CallAgentError with an actionable message.

Returns ​

Promise<MediaStream>

setMuted() ​
ts
setMuted(muted): void;

Defined in: apps/web-sdk/src/audio/microphone.ts:213

Parameters ​
ParameterType
mutedboolean
Returns ​

void

setTargetSampleRate() ​
ts
setTargetSampleRate(sampleRate): void;

Defined in: apps/web-sdk/src/audio/microphone.ts:122

The gateway announces the negotiated rate after the handshake, which may differ from what we asked for; the resampler has to follow it or we send the wrong pitch.

Parameters ​
ParameterType
sampleRatenumber
Returns ​

void

startCapture() ​
ts
startCapture(onFrame): Promise<void>;

Defined in: apps/web-sdk/src/audio/microphone.ts:173

Starts pumping PCM frames. Only used by the WebSocket fallback — under WebRTC the MediaStream goes straight onto a peer connection and the browser does the encoding, which is both cheaper and better sounding.

Parameters ​
ParameterType
onFrame(pcm) => void
Returns ​

Promise<void>


SessionSocket ​

Defined in: apps/web-sdk/src/transport/socket.ts:50

Constructors ​

Constructor ​
ts
new SessionSocket(options): SessionSocket;

Defined in: apps/web-sdk/src/transport/socket.ts:63

Parameters ​
ParameterType
optionsSessionSocketOptions
Returns ​

SessionSocket

Accessors ​

reconnectAttempts ​
Get Signature ​
ts
get reconnectAttempts(): number;

Defined in: apps/web-sdk/src/transport/socket.ts:74

Returns ​

number

state ​
Get Signature ​
ts
get state(): SocketState;

Defined in: apps/web-sdk/src/transport/socket.ts:70

Returns ​

SocketState

Methods ​

close() ​
ts
close(code?, reason?): void;

Defined in: apps/web-sdk/src/transport/socket.ts:94

Parameters ​
ParameterTypeDefault value
codenumber1000
reasonstring'client_closed'
Returns ​

void

connect() ​
ts
connect(): Promise<void>;

Defined in: apps/web-sdk/src/transport/socket.ts:78

Returns ​

Promise<void>

send() ​
ts
send(frame): void;

Defined in: apps/web-sdk/src/transport/socket.ts:83

Parameters ​
ParameterType
frameClientFrame
Returns ​

void

sendAudio() ​
ts
sendAudio(payload): void;

Defined in: apps/web-sdk/src/transport/socket.ts:87

Parameters ​
ParameterType
payloadArrayBuffer
Returns ​

void


TokenManager ​

Defined in: apps/web-sdk/src/auth.ts:160

Constructors ​

Constructor ​
ts
new TokenManager(options): TokenManager;

Defined in: apps/web-sdk/src/auth.ts:174

Parameters ​
ParameterType
optionsTokenManagerOptions
Returns ​

TokenManager

Accessors ​

expiresAtMs ​
Get Signature ​
ts
get expiresAtMs(): number;

Defined in: apps/web-sdk/src/auth.ts:195

Returns ​

number

token ​
Get Signature ​
ts
get token(): string | null;

Defined in: apps/web-sdk/src/auth.ts:191

Returns ​

string | null

Methods ​

getToken() ​
ts
getToken(): Promise<string>;

Defined in: apps/web-sdk/src/auth.ts:200

Returns a token that is valid now, fetching or refreshing if necessary.

Returns ​

Promise<string>

refresh() ​
ts
refresh(): Promise<string>;

Defined in: apps/web-sdk/src/auth.ts:205

Returns ​

Promise<string>

stop() ​
ts
stop(): void;

Defined in: apps/web-sdk/src/auth.ts:213

Returns ​

void


WebRtcMedia ​

Defined in: apps/web-sdk/src/transport/webrtc.ts:40

Constructors ​

Constructor ​
ts
new WebRtcMedia(options): WebRtcMedia;

Defined in: apps/web-sdk/src/transport/webrtc.ts:47

Parameters ​
ParameterType
optionsWebRtcMediaOptions
Returns ​

WebRtcMedia

Accessors ​

connectionState ​
Get Signature ​
ts
get connectionState(): RTCPeerConnectionState;

Defined in: apps/web-sdk/src/transport/webrtc.ts:51

Returns ​

RTCPeerConnectionState

Methods ​

acceptAnswer() ​
ts
acceptAnswer(sdp): Promise<void>;

Defined in: apps/web-sdk/src/transport/webrtc.ts:107

Parameters ​
ParameterType
sdpstring
Returns ​

Promise<void>

addRemoteCandidate() ​
ts
addRemoteCandidate(candidate): Promise<void>;

Defined in: apps/web-sdk/src/transport/webrtc.ts:117

Parameters ​
ParameterType
candidateRTCIceCandidateInit | null
Returns ​

Promise<void>

close() ​
ts
close(): void;

Defined in: apps/web-sdk/src/transport/webrtc.ts:131

Returns ​

void

start() ​
ts
start(localStream): Promise<void>;

Defined in: apps/web-sdk/src/transport/webrtc.ts:55

Parameters ​
ParameterType
localStreamMediaStream | null
Returns ​

Promise<void>

Interfaces ​

AudioPlayerOptions ​

Defined in: apps/web-sdk/src/audio/player.ts:19

Assistant audio playback with exact interruption (§21).

The design constraint that shapes everything here: when the gateway says the assistant was interrupted, sound must stop within a few tens of milliseconds. So playback never hands a long buffer to the browser — it schedules short segments back to back on an AudioContext timeline and keeps every live source node so clear() can stop(0) all of them and drop what has not been scheduled yet.

A generation counter guards the boundary: clear() bumps it, and the next frame starts a new one. The gateway stops writing the instant it sends clear and the socket is ordered, so nothing from the interrupted utterance can arrive afterwards — but generation is what makes that assumption explicit and testable rather than implied.

Properties ​

PropertyTypeDescriptionDefined in
audioContextFactory?(sampleRate) => AudioContextInjected in tests; in a browser this is window.AudioContext.apps/web-sdk/src/audio/player.ts:22
onDrained?() => void-apps/web-sdk/src/audio/player.ts:26
onStarted?() => void-apps/web-sdk/src/audio/player.ts:25
sampleRatenumber-apps/web-sdk/src/audio/player.ts:20
scheduleAheadSeconds?numberHow far ahead of currentTime to schedule. Lower = tighter barge-in, more risk of gaps.apps/web-sdk/src/audio/player.ts:24

BackoffOptions ​

Defined in: apps/web-sdk/src/backoff.ts:1

Properties ​

PropertyTypeDescriptionDefined in
factor?number-apps/web-sdk/src/backoff.ts:4
initialMs?number-apps/web-sdk/src/backoff.ts:2
jitter?number0…1. Full jitter at 1.0; a fleet of widgets reconnecting in lockstep is a DDoS.apps/web-sdk/src/backoff.ts:6
maxAttempts?number-apps/web-sdk/src/backoff.ts:7
maxMs?number-apps/web-sdk/src/backoff.ts:3

CallAgentEvents ​

Defined in: apps/web-sdk/src/client.ts:12

@callagent/web-sdk — browser voice and chat client (§60).

Zero runtime dependencies by design: this ships inside a <script> tag on other people's pages, so every kilobyte is somebody else's Largest Contentful Paint.

Extends ​

  • Record<string, unknown>

Indexable ​

ts
[key: string]: unknown

Properties ​

PropertyTypeDefined in
call-end{ callId: string; reason: string; }apps/web-sdk/src/client.ts:15
call-end.callIdstringapps/web-sdk/src/client.ts:15
call-end.reasonstringapps/web-sdk/src/client.ts:15
call-startCallapps/web-sdk/src/client.ts:14
client-toolClientToolInvocationapps/web-sdk/src/client.ts:16
errorCallAgentErrorapps/web-sdk/src/client.ts:13

CallAgentOptions ​

Defined in: apps/web-sdk/src/types.ts:83

Properties ​

PropertyTypeDescriptionDefined in
apiUrl?stringControl-plane origin, e.g. https://api.callagent.dev.apps/web-sdk/src/types.ts:89
internals?{ audioContextFactory?: (sampleRate) => AudioContext; clearTimeoutImpl?: (handle) => void; disableRemoteAudioElement?: boolean; fetchImpl?: { (input, init?): Promise<Response>; (input, init?): Promise<Response>; }; mediaDevices?: MediaDevices; now?: () => number; peerConnectionFactory?: PeerConnectionFactory; random?: () => number; setTimeoutImpl?: (handler, ms) => unknown; webSocketFactory?: WebSocketFactory; }Test seams. Not part of the supported surface; they exist so the specs are real.apps/web-sdk/src/types.ts:104
internals.audioContextFactory?(sampleRate) => AudioContext-apps/web-sdk/src/types.ts:108
internals.clearTimeoutImpl?(handle) => void-apps/web-sdk/src/types.ts:113
internals.disableRemoteAudioElement?booleanSkips <audio> element creation, for headless environments.apps/web-sdk/src/types.ts:115
internals.fetchImpl?{ (input, init?): Promise<Response>; (input, init?): Promise<Response>; }-apps/web-sdk/src/types.ts:105
internals.mediaDevices?MediaDevices-apps/web-sdk/src/types.ts:109
internals.now?() => number-apps/web-sdk/src/types.ts:110
internals.peerConnectionFactory?PeerConnectionFactory-apps/web-sdk/src/types.ts:107
internals.random?() => number-apps/web-sdk/src/types.ts:111
internals.setTimeoutImpl?(handler, ms) => unknown-apps/web-sdk/src/types.ts:112
internals.webSocketFactory?WebSocketFactory-apps/web-sdk/src/types.ts:106
publicKey?stringPublic key from Settings → API Keys. A private key is rejected locally.apps/web-sdk/src/types.ts:85
reconnect?{ factor?: number; initialMs?: number; jitter?: number; maxAttempts?: number; maxMs?: number; }-apps/web-sdk/src/types.ts:96
reconnect.factor?number-apps/web-sdk/src/types.ts:99
reconnect.initialMs?number-apps/web-sdk/src/types.ts:97
reconnect.jitter?number-apps/web-sdk/src/types.ts:100
reconnect.maxAttempts?number-apps/web-sdk/src/types.ts:101
reconnect.maxMs?number-apps/web-sdk/src/types.ts:98
token?stringA JWT your own backend minted. Mutually exclusive with publicKey.apps/web-sdk/src/types.ts:87
tokenRefreshSkewMs?numberRefresh the client JWT this many ms before it expires.apps/web-sdk/src/types.ts:95
transports?TransportKind[]Ordered transport preference. Defaults to WebRTC then WebSocket.apps/web-sdk/src/types.ts:93
userId?stringOpaque identifier for the end user; lands in the JWT's user claim.apps/web-sdk/src/types.ts:91

CallEndedEvent ​

Defined in: apps/web-sdk/src/types.ts:47

Properties ​

PropertyTypeDefined in
callIdstringapps/web-sdk/src/types.ts:48
reasonstringapps/web-sdk/src/types.ts:49
state| "created" | "queued" | "ringing" | "connecting" | "connected" | "listening" | "user_speaking" | "thinking" | "tool_executing" | "assistant_speaking" | "on_hold" | "transferring" | "human_queue" | "human_connected" | "ending" | "ended" | "failed"apps/web-sdk/src/types.ts:50

CallEvents ​

Defined in: apps/web-sdk/src/types.ts:68

Extends ​

  • Record<string, unknown>

Indexable ​

ts
[key: string]: unknown

Properties ​

PropertyTypeDefined in
connected{ callId: string; sessionId: string; transport: TransportKind; }apps/web-sdk/src/types.ts:75
connected.callIdstringapps/web-sdk/src/types.ts:75
connected.sessionIdstringapps/web-sdk/src/types.ts:75
connected.transportTransportKindapps/web-sdk/src/types.ts:75
endedCallEndedEventapps/web-sdk/src/types.ts:76
errorCallAgentErrorapps/web-sdk/src/types.ts:74
messageConversationMessageapps/web-sdk/src/types.ts:70
reconnected{ attempt: number; }apps/web-sdk/src/types.ts:78
reconnected.attemptnumberapps/web-sdk/src/types.ts:78
reconnectingReconnectingEventapps/web-sdk/src/types.ts:77
server-errorServerErrorapps/web-sdk/src/types.ts:80
speech-endSpeechEventapps/web-sdk/src/types.ts:72
speech-startSpeechEventapps/web-sdk/src/types.ts:71
stateStateEventapps/web-sdk/src/types.ts:73
tool-callClientToolInvocationapps/web-sdk/src/types.ts:79
transcriptTranscriptEventapps/web-sdk/src/types.ts:69

ClientToolInvocation ​

Defined in: apps/web-sdk/src/types.ts:57

Properties ​

PropertyTypeDefined in
argumentsRecord<string, unknown>apps/web-sdk/src/types.ts:60
callIdstringapps/web-sdk/src/types.ts:61
namestringapps/web-sdk/src/types.ts:59
toolCallIdstringapps/web-sdk/src/types.ts:58

ConversationMessage ​

Defined in: apps/web-sdk/src/types.ts:24

Properties ​

PropertyTypeDescriptionDefined in
atstring-apps/web-sdk/src/types.ts:28
contentstring-apps/web-sdk/src/types.ts:27
id?string-apps/web-sdk/src/types.ts:25
interrupted?booleanTrue when barge-in cut the assistant off mid-sentence (§21).apps/web-sdk/src/types.ts:30
role"system" | "user" | "assistant" | "tool" | "operator"-apps/web-sdk/src/types.ts:26
toolCallId?string-apps/web-sdk/src/types.ts:31
toolCalls?{ arguments: Record<string, unknown>; id: string; name: string; }[]-apps/web-sdk/src/types.ts:32

ReconnectingEvent ​

Defined in: apps/web-sdk/src/types.ts:53

Properties ​

PropertyTypeDefined in
attemptnumberapps/web-sdk/src/types.ts:54

ServerError ​

Defined in: apps/web-sdk/src/protocol.ts:206

Properties ​

PropertyTypeDefined in
codestringapps/web-sdk/src/protocol.ts:207
documentationUrl?stringapps/web-sdk/src/protocol.ts:210
messagestringapps/web-sdk/src/protocol.ts:208
retryable?booleanapps/web-sdk/src/protocol.ts:209

ServerMessage ​

Defined in: apps/web-sdk/src/protocol.ts:196

Properties ​

PropertyTypeDefined in
atstringapps/web-sdk/src/protocol.ts:200
contentstringapps/web-sdk/src/protocol.ts:199
id?stringapps/web-sdk/src/protocol.ts:197
interrupted?booleanapps/web-sdk/src/protocol.ts:201
role"system" | "user" | "assistant" | "tool" | "operator"apps/web-sdk/src/protocol.ts:198
toolCallId?stringapps/web-sdk/src/protocol.ts:202
toolCalls?{ arguments: Record<string, unknown>; id: string; name: string; }[]apps/web-sdk/src/protocol.ts:203

ServerTranscript ​

Defined in: apps/web-sdk/src/protocol.ts:187

Properties ​

PropertyTypeDefined in
atstringapps/web-sdk/src/protocol.ts:191
confidence?numberapps/web-sdk/src/protocol.ts:192
finalbooleanapps/web-sdk/src/protocol.ts:190
language?stringapps/web-sdk/src/protocol.ts:193
roleSpeakerapps/web-sdk/src/protocol.ts:188
textstringapps/web-sdk/src/protocol.ts:189

SpeechEvent ​

Defined in: apps/web-sdk/src/types.ts:35

Properties ​

PropertyTypeDefined in
atstringapps/web-sdk/src/types.ts:37
speakerSpeakerapps/web-sdk/src/types.ts:36

StartCallOptions ​

Defined in: apps/web-sdk/src/types.ts:119

Properties ​

PropertyTypeDescriptionDefined in
assistantId?string-apps/web-sdk/src/types.ts:120
metadata?Record<string, unknown>-apps/web-sdk/src/types.ts:125
microphone?{ autoGainControl?: boolean; deviceId?: string; echoCancellation?: boolean; noiseSuppression?: boolean; }-apps/web-sdk/src/types.ts:128
microphone.autoGainControl?boolean-apps/web-sdk/src/types.ts:132
microphone.deviceId?string-apps/web-sdk/src/types.ts:129
microphone.echoCancellation?boolean-apps/web-sdk/src/types.ts:130
microphone.noiseSuppression?boolean-apps/web-sdk/src/types.ts:131
mode?SessionModechat runs the same session without a microphone or speaker.apps/web-sdk/src/types.ts:123
squadId?string-apps/web-sdk/src/types.ts:121
transports?TransportKind[]Overrides the client-level transport preference for this call only.apps/web-sdk/src/types.ts:127
variables?Record<string, unknown>-apps/web-sdk/src/types.ts:124

StateEvent ​

Defined in: apps/web-sdk/src/types.ts:40

Properties ​

PropertyTypeDefined in
atstringapps/web-sdk/src/types.ts:43
previous| "created" | "queued" | "ringing" | "connecting" | "connected" | "listening" | "user_speaking" | "thinking" | "tool_executing" | "assistant_speaking" | "on_hold" | "transferring" | "human_queue" | "human_connected" | "ending" | "ended" | "failed"apps/web-sdk/src/types.ts:42
reason?stringapps/web-sdk/src/types.ts:44
state| "created" | "queued" | "ringing" | "connecting" | "connected" | "listening" | "user_speaking" | "thinking" | "tool_executing" | "assistant_speaking" | "on_hold" | "transferring" | "human_queue" | "human_connected" | "ending" | "ended" | "failed"apps/web-sdk/src/types.ts:41

TokenManagerOptions ​

Defined in: apps/web-sdk/src/auth.ts:139

Properties ​

PropertyTypeDescriptionDefined in
apiUrlstring-apps/web-sdk/src/auth.ts:140
assistantId?string-apps/web-sdk/src/auth.ts:144
clearTimeoutImpl?(handle) => void-apps/web-sdk/src/auth.ts:149
fetchImpl?{ (input, init?): Promise<Response>; (input, init?): Promise<Response>; }-apps/web-sdk/src/auth.ts:146
now?() => number-apps/web-sdk/src/auth.ts:147
onError?(error) => void-apps/web-sdk/src/auth.ts:153
onToken?(token) => void-apps/web-sdk/src/auth.ts:152
publicKey?string-apps/web-sdk/src/auth.ts:141
refreshSkewMs?numberRefresh this far ahead of exp.apps/web-sdk/src/auth.ts:151
setTimeoutImpl?(handler, ms) => unknown-apps/web-sdk/src/auth.ts:148
token?stringA token the host page minted itself; the SDK then never calls the exchange.apps/web-sdk/src/auth.ts:143
userId?string-apps/web-sdk/src/auth.ts:145

TranscriptEvent ​

Defined in: apps/web-sdk/src/types.ts:13

Properties ​

PropertyTypeDescriptionDefined in
atstring-apps/web-sdk/src/types.ts:19
confidence?number-apps/web-sdk/src/types.ts:20
finalbooleanfalse while the transcriber is still revising the utterance.apps/web-sdk/src/types.ts:18
language?string-apps/web-sdk/src/types.ts:21
speakerSpeakerWho spoke. Partial results are emitted for both sides as they arrive.apps/web-sdk/src/types.ts:15
textstring-apps/web-sdk/src/types.ts:16

WebSocketLike ​

Defined in: apps/web-sdk/src/transport/socket.ts:16

Properties ​

PropertyModifierTypeDefined in
binaryTypepublicstringapps/web-sdk/src/transport/socket.ts:18
onclosepublic((event) => void) | nullapps/web-sdk/src/transport/socket.ts:22
onerrorpublic((event) => void) | nullapps/web-sdk/src/transport/socket.ts:23
onmessagepublic((event) => void) | nullapps/web-sdk/src/transport/socket.ts:24
onopenpublic((event) => void) | nullapps/web-sdk/src/transport/socket.ts:21
readyStatereadonlynumberapps/web-sdk/src/transport/socket.ts:17

Methods ​

close() ​
ts
close(code?, reason?): void;

Defined in: apps/web-sdk/src/transport/socket.ts:20

Parameters ​
ParameterType
code?number
reason?string
Returns ​

void

send() ​
ts
send(data): void;

Defined in: apps/web-sdk/src/transport/socket.ts:19

Parameters ​
ParameterType
datastring | ArrayBufferLike | Blob | ArrayBufferView<ArrayBufferLike>
Returns ​

void

Type Aliases ​

CallAgentErrorCode ​

ts
type CallAgentErrorCode = 
  | "invalid_public_key"
  | "private_key_rejected"
  | "auth_failed"
  | "token_expired"
  | "microphone_denied"
  | "microphone_unavailable"
  | "audio_unsupported"
  | "transport_failed"
  | "transport_closed"
  | "protocol_mismatch"
  | "call_start_failed"
  | "call_ended"
  | "client_tool_failed"
  | "not_connected"
  | "aborted"
  | "server_error";

Defined in: apps/web-sdk/src/errors.ts:9

Error codes the SDK raises. Kept as a closed union so host pages can branch on error.code instead of matching on message text (CONVENTIONS.md §4).

The server's own codes come from CallAgentErrorCode in @callagent/contracts and arrive verbatim on server.error frames; they are surfaced as code without being remapped, so a support ticket quotes the same string both planes log.


CallState ​

ts
type CallState = typeof CALL_STATES[number];

Defined in: apps/web-sdk/src/protocol.ts:60


ClientFrame ​

ts
type ClientFrame = 
  | {
  assistantId?: string;
  callId: string;
  clientTools?: string[];
  event: "start";
  mediaToken?: string;
  metadata?: Record<string, unknown>;
  mode: SessionMode;
  organizationId?: string;
  protocolVersion: number;
  sampleRate: number;
  sdkVersion: string;
  variables?: Record<string, string>;
}
  | {
  event: "auth";
  token: string;
}
  | {
  event: "offer";
  sdp: string;
}
  | {
  candidate: RTCIceCandidateInit | null;
  event: "ice";
}
  | {
  event: "mute";
  muted: boolean;
}
  | {
  content: string;
  event: "text";
}
  | {
  digit: string;
  event: "dtmf";
}
  | {
  event: "mark";
  name: string;
}
  | {
  error?: string;
  event: "tool_result";
  result?: unknown;
  toolCallId: string;
}
  | {
  event: "stop";
  reason?: string;
};

Defined in: apps/web-sdk/src/protocol.ts:156

The gateway dispatches on event, ignores unknown ones, and reads only the keys it knows — so extra fields on start are forward-compatible, not a protocol break.

Union Members ​

Type Literal ​
ts
{
  assistantId?: string;
  callId: string;
  clientTools?: string[];
  event: "start";
  mediaToken?: string;
  metadata?: Record<string, unknown>;
  mode: SessionMode;
  organizationId?: string;
  protocolVersion: number;
  sampleRate: number;
  sdkVersion: string;
  variables?: Record<string, string>;
}
NameTypeDescriptionDefined in
assistantId?string-apps/web-sdk/src/protocol.ts:160
callIdstring-apps/web-sdk/src/protocol.ts:159
clientTools?string[]-apps/web-sdk/src/protocol.ts:170
event"start"-apps/web-sdk/src/protocol.ts:158
mediaToken?string-apps/web-sdk/src/protocol.ts:169
metadata?Record<string, unknown>-apps/web-sdk/src/protocol.ts:171
modeSessionMode-apps/web-sdk/src/protocol.ts:168
organizationId?string-apps/web-sdk/src/protocol.ts:161
protocolVersionnumberFields below are SDK additions; the current gateway ignores them.apps/web-sdk/src/protocol.ts:166
sampleRatenumberRate of the PCM we will send. The gateway echoes a format frame back.apps/web-sdk/src/protocol.ts:163
sdkVersionstring-apps/web-sdk/src/protocol.ts:167
variables?Record<string, string>-apps/web-sdk/src/protocol.ts:164

Type Literal ​
ts
{
  event: "auth";
  token: string;
}

Type Literal ​
ts
{
  event: "offer";
  sdp: string;
}

Type Literal ​
ts
{
  candidate: RTCIceCandidateInit | null;
  event: "ice";
}

Type Literal ​
ts
{
  event: "mute";
  muted: boolean;
}

Type Literal ​
ts
{
  content: string;
  event: "text";
}

Type Literal ​
ts
{
  digit: string;
  event: "dtmf";
}

Type Literal ​
ts
{
  event: "mark";
  name: string;
}

Type Literal ​
ts
{
  error?: string;
  event: "tool_result";
  result?: unknown;
  toolCallId: string;
}

Type Literal ​
ts
{
  event: "stop";
  reason?: string;
}

ClientToolHandler ​

ts
type ClientToolHandler = (invocation) => unknown | Promise<unknown>;

Defined in: apps/web-sdk/src/types.ts:64

Parameters ​

ParameterType
invocationClientToolInvocation

Returns ​

unknown | Promise<unknown>


MessageRole ​

ts
type MessageRole = typeof MESSAGE_ROLES[number];

Defined in: apps/web-sdk/src/protocol.ts:72


ServerEventName ​

ts
type ServerEventName = ServerFrame["event"];

Defined in: apps/web-sdk/src/protocol.ts:251


ServerFrame ​

ts
type ServerFrame = 
  | {
  channels: number;
  encoding: "pcm_s16le";
  event: "format";
  sampleRate: number;
}
  | {
  event: "clear";
}
  | {
  event: "mark";
  name: string;
}
  | {
  event: "stop";
  reason?: string;
}
  | {
  event: "answer";
  sdp: string;
}
  | {
  candidate: RTCIceCandidateInit | null;
  event: "ice";
}
  | {
  callId: string;
  event: "ready";
  protocolVersion?: number;
  sampleRate?: number;
  sessionId?: string;
  state?: CallState;
  transport?: TransportKind;
}
  | {
  at?: string;
  event: "state";
  reason?: string;
  state: CallState;
}
  | {
  event: "transcript";
  transcript: ServerTranscript;
}
  | {
  event: "message";
  message: ServerMessage;
}
  | {
  at?: string;
  event: "speech";
  phase: "start" | "end";
  speaker: Speaker;
}
  | {
  arguments: Record<string, unknown>;
  event: "tool_call";
  name: string;
  timeoutMs?: number;
  toolCallId: string;
}
  | {
  error: ServerError;
  event: "error";
}
  | {
  event: "ended";
  reason: string;
  state?: CallState;
};

Defined in: apps/web-sdk/src/protocol.ts:213

Union Members ​

Type Literal ​
ts
{
  channels: number;
  encoding: "pcm_s16le";
  event: "format";
  sampleRate: number;
}

Implemented by the gateway today: the negotiated PCM format.


Type Literal ​
ts
{
  event: "clear";
}

Barge-in (§21). Drop everything queued and stop the speaker now. Playing to the end of the buffer here is the single most noticeable voice-UX bug there is. The socket is ordered, so any audio frame after this one is the next utterance.


Type Literal ​
ts
{
  event: "mark";
  name: string;
}

Type Literal ​
ts
{
  event: "stop";
  reason?: string;
}

Type Literal ​
ts
{
  event: "answer";
  sdp: string;
}

Signalling, forwarded verbatim by the gateway; no ICE agent runs there yet.


Type Literal ​
ts
{
  candidate: RTCIceCandidateInit | null;
  event: "ice";
}

Type Literal ​
ts
{
  callId: string;
  event: "ready";
  protocolVersion?: number;
  sampleRate?: number;
  sessionId?: string;
  state?: CallState;
  transport?: TransportKind;
}

Session events the gateway still has to emit — see the file header.


Type Literal ​
ts
{
  at?: string;
  event: "state";
  reason?: string;
  state: CallState;
}

Type Literal ​
ts
{
  event: "transcript";
  transcript: ServerTranscript;
}

Type Literal ​
ts
{
  event: "message";
  message: ServerMessage;
}

Type Literal ​
ts
{
  at?: string;
  event: "speech";
  phase: "start" | "end";
  speaker: Speaker;
}

Type Literal ​
ts
{
  arguments: Record<string, unknown>;
  event: "tool_call";
  name: string;
  timeoutMs?: number;
  toolCallId: string;
}

Type Literal ​
ts
{
  error: ServerError;
  event: "error";
}

Type Literal ​
ts
{
  event: "ended";
  reason: string;
  state?: CallState;
}

SessionMode ​

ts
type SessionMode = "voice" | "chat";

Defined in: apps/web-sdk/src/protocol.ts:76


SocketState ​

ts
type SocketState = "idle" | "connecting" | "open" | "reconnecting" | "closed";

Defined in: apps/web-sdk/src/transport/socket.ts:14

The session control channel.

One WebSocket carries JSON control frames in both directions and, when WebRTC is unavailable, binary PCM as well. It owns reconnection: the call object above it sees open / close / frame and does not care how many sockets it took.


Speaker ​

ts
type Speaker = "user" | "assistant";

Defined in: apps/web-sdk/src/protocol.ts:74


TransportKind ​

ts
type TransportKind = "webrtc" | "websocket" | "chat";

Defined in: apps/web-sdk/src/protocol.ts:79

How the client is carrying media. chat means there is no media at all.

Variables ​

CALL_STATES ​

ts
const CALL_STATES: readonly ["created", "queued", "ringing", "connecting", "connected", "listening", "user_speaking", "thinking", "tool_executing", "assistant_speaking", "on_hold", "transferring", "human_queue", "human_connected", "ending", "ended", "failed"];

Defined in: apps/web-sdk/src/protocol.ts:40

Mirrors CallState in @callagent/contracts / App\Enums\CallState. protocol.contract.test.ts proves the two lists are identical.


CLIENT_ROUTES ​

ts
const CLIENT_ROUTES: Readonly<{
  token: "/api/v1/client-tokens";
  webCall: "/api/v1/client/calls";
}>;

Defined in: apps/web-sdk/src/protocol.ts:85


MESSAGE_ROLES ​

ts
const MESSAGE_ROLES: readonly ["system", "user", "assistant", "tool", "operator"];

Defined in: apps/web-sdk/src/protocol.ts:71

Mirrors CallMessageSchema.role in @callagent/contracts.


PROTOCOL_VERSION ​

ts
const PROTOCOL_VERSION: 1 = 1;

Defined in: apps/web-sdk/src/protocol.ts:34

The browser <-> Voice Gateway session protocol.

ALIGNED WITH THE GATEWAY'S WebRtcTransport ​

apps/voice-gateway/src/transport/webrtc.ts (A2) already implements the media half of this: a WebSocket carrying raw PCM16 frames as binary messages and a small { "event": "..." } JSON control channel. This file speaks exactly that wire format rather than inventing a second one, and adds the conversation events the SDK needs (transcripts, messages, state, client tools) as further event values.

What the gateway implements today: start, dtmf, mark, stop, offer/answer/ ice inbound; format, clear, mark, stop outbound; binary PCM both ways.

What the gateway still has to add for a complete session (raised as decision D-A14-001 and BLOCKERS #16): ready, state, transcript, message, speech, tool_call, error, ended outbound; mute, text, tool_result, auth inbound. Unknown inbound events are ignored on both sides, so the SDK works against the current gateway for audio and barge-in and lights up the rest as it lands.

TODO(A1): these shapes belong in packages/contracts/src/web-session.ts as zod schemas, re-exported from here.

WHY THE SDK DOES NOT IMPORT ZOD AT RUNTIME ​

The widget is a <script src=...> drop-in on other people's marketing pages; a validation library is a large fraction of the byte budget. So the SDK ships zero runtime dependencies and validates inbound frames with the narrow guards below. The enums it does share with the control plane (CallState, message roles) are asserted against @callagent/contracts in protocol.contract.test.ts, so a divergence fails the build rather than silently accepting an unknown state.


VERSION ​

ts
const VERSION: "0.1.0" = '0.1.0';

Defined in: apps/web-sdk/src/index.ts:76

Functions ​

assertPublicKey() ​

ts
function assertPublicKey(key): string;

Defined in: apps/web-sdk/src/auth.ts:79

Parameters ​

ParameterType
keystring

Returns ​

string


decodeAudioFrame() ​

ts
function decodeAudioFrame(buffer): Int16Array<ArrayBufferLike> | null;

Defined in: apps/web-sdk/src/protocol.ts:267

Parameters ​

ParameterType
bufferArrayBuffer

Returns ​

Int16Array<ArrayBufferLike> | null


decodeJwt() ​

ts
function decodeJwt(token): DecodedJwt;

Defined in: apps/web-sdk/src/auth.ts:110

Reads exp out of a JWT without verifying it. Verification is the server's job — the client only needs to know when to ask for a new one, and a forged exp can at worst make the SDK refresh too eagerly.

Parameters ​

ParameterType
tokenstring

Returns ​

DecodedJwt


describeMediaError() ​

ts
function describeMediaError(error): {
  code: MicrophoneErrorCode;
  message: string;
};

Defined in: apps/web-sdk/src/audio/microphone.ts:31

Parameters ​

ParameterType
errorunknown

Returns ​

ts
{
  code: MicrophoneErrorCode;
  message: string;
}
NameTypeDefined in
codeMicrophoneErrorCodeapps/web-sdk/src/audio/microphone.ts:32
messagestringapps/web-sdk/src/audio/microphone.ts:33

encodeAudioFrame() ​

ts
function encodeAudioFrame(pcm): ArrayBuffer;

Defined in: apps/web-sdk/src/protocol.ts:263

Binary messages are raw little-endian PCM16 mono in both directions, matching WebRtcTransport. There is no frame header: the gateway stops writing the moment it sends clear, and the socket is ordered, so the client can safely treat every frame that arrives after a clear as belonging to the next utterance.

Parameters ​

ParameterType
pcmInt16Array

Returns ​

ArrayBuffer


floatToPcm16() ​

ts
function floatToPcm16(input): Int16Array;

Defined in: apps/web-sdk/src/audio/pcm.ts:10

PCM helpers.

Everything on the socket is signed 16-bit little-endian mono, because that is what every STT vendor and every telephony codec path in this platform already speaks (packages/audio). The browser gives us float32 at the device rate, so the two conversions below are the only audio maths the SDK does.

Parameters ​

ParameterType
inputFloat32Array

Returns ​

Int16Array


inspectPublicKey() ​

ts
function inspectPublicKey(key): PublicKeyCheck;

Defined in: apps/web-sdk/src/auth.ts:41

Parameters ​

ParameterType
keystring

Returns ​

PublicKeyCheck


isCallState() ​

ts
function isCallState(value): value is "created" | "queued" | "ringing" | "connecting" | "connected" | "listening" | "user_speaking" | "thinking" | "tool_executing" | "assistant_speaking" | "on_hold" | "transferring" | "human_queue" | "human_connected" | "ending" | "ended" | "failed";

Defined in: apps/web-sdk/src/protocol.ts:64

Parameters ​

ParameterType
valueunknown

Returns ​

value is "created" | "queued" | "ringing" | "connecting" | "connected" | "listening" | "user_speaking" | "thinking" | "tool_executing" | "assistant_speaking" | "on_hold" | "transferring" | "human_queue" | "human_connected" | "ending" | "ended" | "failed"


isSecureContextForMedia() ​

ts
function isSecureContextForMedia(): boolean;

Defined in: apps/web-sdk/src/audio/microphone.ts:90

Returns ​

boolean


looksLikePublicKey() ​

ts
function looksLikePublicKey(key): boolean;

Defined in: apps/web-sdk/src/auth.ts:91

Parameters ​

ParameterType
keystring

Returns ​

boolean


parseServerFrame() ​

ts
function parseServerFrame(raw): ServerFrame | null;

Defined in: apps/web-sdk/src/protocol.ts:305

Structural validation of one inbound control frame.

Deliberately permissive about extra fields (the gateway may add some without a client release) and strict about the fields we branch on. An unknown event is not an error — it is a newer gateway — so it returns null and the caller ignores it.

Parameters ​

ParameterType
rawunknown

Returns ​

ServerFrame | null


pcm16ToFloat() ​

ts
function pcm16ToFloat(input): Float32Array<ArrayBuffer>;

Defined in: apps/web-sdk/src/audio/pcm.ts:21

Parameters ​

ParameterType
inputInt16Array

Returns ​

Float32Array<ArrayBuffer>


queryMicrophonePermission() ​

ts
function queryMicrophonePermission(): Promise<PermissionState | "unsupported">;

Defined in: apps/web-sdk/src/audio/microphone.ts:77

navigator.permissions is not implemented for microphone everywhere, so this is best-effort: it lets the widget show "allow the microphone" before the browser prompt where it can, and stays quiet where it cannot.

Returns ​

Promise<PermissionState | "unsupported">


resampleLinear() ​

ts
function resampleLinear(
   input, 
   fromRate, 
   toRate
): Float32Array;

Defined in: apps/web-sdk/src/audio/pcm.ts:37

Linear resampling.

Not as good as a windowed-sinc filter, but it runs on the audio thread budget and the far end is a speech model, not a mastering engineer. packages/audio owns the high-quality path for server-side media; this is the browser's cheap equivalent.

Parameters ​

ParameterType
inputFloat32Array
fromRatenumber
toRatenumber

Returns ​

Float32Array


supportsWebAudio() ​

ts
function supportsWebAudio(scope?): boolean;

Defined in: apps/web-sdk/src/transport/support.ts:28

Parameters ​

ParameterTypeDefault value
scopetypeof globalThisglobalThis

Returns ​

boolean


supportsWebRtc() ​

ts
function supportsWebRtc(scope?): boolean;

Defined in: apps/web-sdk/src/transport/support.ts:11

Transport selection (§60: "use WebRTC where possible").

WebRTC is preferred because the browser then owns jitter buffering, packet loss concealment and Opus encoding — all things a WebSocket PCM stream has to do badly in JavaScript. The WebSocket path exists because corporate networks block UDP and some embedded webviews ship without RTCPeerConnection at all.

Parameters ​

ParameterTypeDefault value
scopetypeof globalThisglobalThis

Returns ​

boolean


supportsWebSocket() ​

ts
function supportsWebSocket(scope?): boolean;

Defined in: apps/web-sdk/src/transport/support.ts:24

Parameters ​

ParameterTypeDefault value
scopetypeof globalThisglobalThis

Returns ​

boolean


transportPreference() ​

ts
function transportPreference(options): TransportKind[];

Defined in: apps/web-sdk/src/transport/support.ts:41

Ordered list offered to the gateway; it picks the first it also supports.

Parameters ​

ParameterType
optionsTransportPreferenceOptions

Returns ​

TransportKind[]

Scrisă după cod. Ce nu este încă implementat este marcat ca atare, niciodată descris ca funcțional.