Skip to Content

SDK reference

Every export of @kejue/voice-web — startCall, KejueWebCall, KejueTextCall, options, events, and types.

@kejue/voice-web is the browser SDK for web calls. The guides are voice and text chat.

npm install @kejue/voice-web livekit-client

The SDK rides on the open-source LiveKit WebRTC stack. livekit-client (^2.18) is a peer dependency, so your app owns the version. ESM and CJS builds ship with TypeScript declarations.

New integrations should use @kejue/voice-web and the Kejue names below. Existing @kejue/sonus-web clients remain supported. SonusWebCall and SonusTextCall are compatibility aliases of KejueWebCall and KejueTextCall, with matching option/event type aliases. The SDK negotiates current event topics and falls back for older servers without delivering duplicate events.

Exports

ExportKindWhat it is
startCall(opts)functionStarts a call on whichever surface the credentials describe
KejueWebCallclassA live browser voice call
KejueTextCallclassA live typed conversation
KejueWebCallOptions, KejueTextCallOptions, StartCallOptionstypesOption shapes for the three entry points
WebCallCredentials, ModalitytypesThe credential contract
AgentState, TextAgentState, AnyAgentStatetypesState vocabularies
TranscriptLine, ToolActivity, HandoffEvent, DTMFEvent, TextDeltatypesEvent payloads
KejueWebCallEvents, KejueTextCallEventstypesEvent name → payload maps
Unsubscribetype() => void, returned by on()
RoomFactory, RoomLiketypesTest seams for injecting a fake room

startCall(opts)

Resolves the credentials, then routes: modality: "text" starts a KejueTextCall, anything else a KejueWebCall. With no explicit modality option, the credentials decide — so a backend that switches a call to text needs no front-end redeploy.

Prefer the concrete class when your app only ever does one thing: the return type stays narrow, so you keep mute() or send() without a type guard. Starting the wrong class for a set of credentials throws immediately.

WebCallCredentials

What your backend returns from POST /web-calls.

FieldTypeNotes
tokenstringRequired. The join token
ws_urlstringRequired. Signalling endpoint
call_idstring?Correlate against GET /calls/{id}
room_namestring?Diagnostic
expires_at_msnumber?Unix ms after which the token can no longer join
modalityModality?'audio' or 'text'

Anywhere the SDK takes credentials it accepts the object or an async function returning it. Prefer the function — it runs at connect time, so the token can't go stale sitting in a variable.

KejueWebCall

Voice call options

OptionTypeDefault
credentialsWebCallCredentials | () => Promise<WebCallCredentials>—
iceTransportPolicy'relay' | 'all''all'
startMutedbooleanfalse
includeToolPayloadsbooleanfalse
attachAudiobooleantrue

Voice call events

EventPayloadFires when
stateChangeAgentStateState transition
transcriptTranscriptLineOnce per new line
transcriptUpdateTranscriptLine[]Full transcript after each change
toolToolActivityA tool started or finished
noise{ ts: number }Unintelligible caller audio; turn dropped
handoffHandoffEventControl passed to another agent
dtmfDTMFEventKeys pressed — digit count only
errorErrorNon-fatal problem; fatal ones reject start()
disconnectedvoidThe call ended

Voice call methods

MemberSignatureNotes
KejueWebCall.start(opts) => Promise<KejueWebCall>Static. Rejects on connection failure or text credentials
setMuted(muted: boolean) => Promise<void>
mute / unmute() => Promise<void>
hangup() => Promise<void>Idempotent
on(event, cb) => UnsubscribeA throwing listener is isolated; its error re-emits on error
stateAgentStatedisconnected | connecting | initializing | listening | thinking | speaking
mutedboolean
callId / roomNamestring | undefined
transcriptTranscriptLine[]A copy, oldest first

KejueTextCall

Chat options

OptionTypeDefault
credentialsWebCallCredentials | () => Promise<WebCallCredentials>—
includeToolPayloadsbooleanfalse

No audio options — a text call never touches the microphone or speakers.

Chat events

EventPayloadFires when
stateChangeTextAgentStateState transition
transcriptTranscriptLineOnce per new line
transcriptUpdateTranscriptLine[]Full conversation. Authoritative
deltaTextDeltaA chunk of the reply being written
replyEnd{ generation: number, interrupted: boolean, ts: number }The reply finished
messageAck{ id: string, ts: number }The agent accepted a sent message
toolToolActivityA tool started or finished
handoffHandoffEventControl passed to another agent
errorErrorNon-fatal
disconnectedvoidThe conversation ended

Chat methods

MemberSignatureNotes
KejueTextCall.start(opts) => Promise<KejueTextCall>Static. Rejects on connection failure or audio credentials
send(text: string) => Promise<string>Returns the message id. Refuses empty messages and messages over 4,000 characters
hangup() => Promise<void>Idempotent
on(event, cb) => Unsubscribe
stateTextAgentStatedisconnected | connecting | initializing | idle | thinking | replying
callId / roomNamestring | undefined
transcriptTranscriptLine[]A copy, oldest first

Payload types

TypeShape
Modality'audio' | 'text'
TranscriptLine{ role: string, text: string, ts: number } — role is 'agent' or 'user'
ToolActivity{ name, status: 'running' | 'ok' | 'error', args?, output?, ts }
HandoffEvent{ fromAgent?, targetAgent?, reason?, ts }
DTMFEvent{ digitCount, reason, ts } — digits are never transmitted
TextDelta{ generation, text, ts } — discard chunks older than the newest generation

See also

Web calls · Voice calls · Text chat

On this page