Reference
?

session.on

Subscribes to a live session event and returns an unsubscribe function.
session.on(event, callback) → () => void

Subscribes to one of the session's four events and returns an unsubscribe function. stateChange drives the agent's visual (connecting, listening, thinking, speaking, ended); transcript streams live captions for both sides; toolCall reports tool activity and carries each finished tool's return value; error surfaces transport failures. A transcript event carries the segment's full text, so render by upserting on segmentId, not appending.

Parameters
event
'stateChange' | 'transcript' | 'toolCall' | 'error'
RequiredWhich event to subscribe to.
callback
(event) => void
RequiredHandler. The argument type depends on the event.
Subscribe and later unsubscribe
const off = session.on('transcript', ({ role, segmentId, text, final }) =>
  upsertCaption(segmentId, role, text, final),
);
// later
off();