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-clientThe 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
| Export | Kind | What it is |
|---|---|---|
startCall(opts) | function | Starts a call on whichever surface the credentials describe |
KejueWebCall | class | A live browser voice call |
KejueTextCall | class | A live typed conversation |
KejueWebCallOptions, KejueTextCallOptions, StartCallOptions | types | Option shapes for the three entry points |
WebCallCredentials, Modality | types | The credential contract |
AgentState, TextAgentState, AnyAgentState | types | State vocabularies |
TranscriptLine, ToolActivity, HandoffEvent, DTMFEvent, TextDelta | types | Event payloads |
KejueWebCallEvents, KejueTextCallEvents | types | Event name → payload maps |
Unsubscribe | type | () => void, returned by on() |
RoomFactory, RoomLike | types | Test 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.
| Field | Type | Notes |
|---|---|---|
token | string | Required. The join token |
ws_url | string | Required. Signalling endpoint |
call_id | string? | Correlate against GET /calls/{id} |
room_name | string? | Diagnostic |
expires_at_ms | number? | Unix ms after which the token can no longer join |
modality | Modality? | '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
| Option | Type | Default |
|---|---|---|
credentials | WebCallCredentials | () => Promise<WebCallCredentials> | — |
iceTransportPolicy | 'relay' | 'all' | 'all' |
startMuted | boolean | false |
includeToolPayloads | boolean | false |
attachAudio | boolean | true |
Voice call events
| Event | Payload | Fires when |
|---|---|---|
stateChange | AgentState | State transition |
transcript | TranscriptLine | Once per new line |
transcriptUpdate | TranscriptLine[] | Full transcript after each change |
tool | ToolActivity | A tool started or finished |
noise | { ts: number } | Unintelligible caller audio; turn dropped |
handoff | HandoffEvent | Control passed to another agent |
dtmf | DTMFEvent | Keys pressed — digit count only |
error | Error | Non-fatal problem; fatal ones reject start() |
disconnected | void | The call ended |
Voice call methods
| Member | Signature | Notes |
|---|---|---|
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) => Unsubscribe | A throwing listener is isolated; its error re-emits on error |
state | AgentState | disconnected | connecting | initializing | listening | thinking | speaking |
muted | boolean | |
callId / roomName | string | undefined | |
transcript | TranscriptLine[] | A copy, oldest first |
KejueTextCall
Chat options
| Option | Type | Default |
|---|---|---|
credentials | WebCallCredentials | () => Promise<WebCallCredentials> | — |
includeToolPayloads | boolean | false |
No audio options — a text call never touches the microphone or speakers.
Chat events
| Event | Payload | Fires when |
|---|---|---|
stateChange | TextAgentState | State transition |
transcript | TranscriptLine | Once per new line |
transcriptUpdate | TranscriptLine[] | Full conversation. Authoritative |
delta | TextDelta | A 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 |
tool | ToolActivity | A tool started or finished |
handoff | HandoffEvent | Control passed to another agent |
error | Error | Non-fatal |
disconnected | void | The conversation ended |
Chat methods
| Member | Signature | Notes |
|---|---|---|
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 | |
state | TextAgentState | disconnected | connecting | initializing | idle | thinking | replying |
callId / roomName | string | undefined | |
transcript | TranscriptLine[] | A copy, oldest first |
Payload types
| Type | Shape |
|---|---|
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 |