Skip to main content
The core SDK is event-driven. After starting a session, subscribe to events to receive streamed message chunks, tips, tool calls, and lifecycle signals. Drive your UI off these events.

Subscribing

import { SYNAPSE_REALTIME_EVENTS } from "@eka-care/medassist-core";

function onChunk(evt) {
  appendToCurrentMessage(evt.data.text);
}

// Register
sdk.on(SYNAPSE_REALTIME_EVENTS.MESSAGE_CHUNK, onChunk);

// Remove (pass the same function reference)
sdk.off(SYNAPSE_REALTIME_EVENTS.MESSAGE_CHUNK, onChunk);
off() requires the same function reference you passed to on(). Inline arrow functions can’t be removed — keep a reference if you need to unsubscribe.

Event reference

Use the SYNAPSE_REALTIME_EVENTS enum — never hardcode the string values.
EventFires when
CONNECTEDThe session connects.
DISCONNECTEDThe connection drops. Payload carries a DisconnectionReason.
PROGRESS_MESSAGEThe agent emits an interim “working on it” status.
MESSAGE_CHUNKA streamed slice of the assistant’s reply. Concatenate these.
TIPS_MESSAGESuggested follow-up prompts (data.tips).
END_OF_STREAMThe current assistant message is complete.
ERRORA stream or server error. See error codes.
TOOL_CALLThe agent invokes a tool / asks for input. See Tool calls.
TOOL_STARTA tool begins executing.
TOOL_ENDA tool finishes executing.
AUDIO_TRANSCRIPTA transcript of recorded audio. See Voice & audio.

Event payload

Every listener receives a SynapseRealTimeEventData object:
type SynapseRealTimeEventData = {
  data: {
    text?: string;     // message / chunk text
    tips?: string[];   // suggested follow-ups
    name?: string;     // tool or entity name
  } & Partial<ToolCallData>; // tool fields on TOOL_CALL events
  messageId?: string;
  timestamp?: number;
};

Streaming a message

A single assistant reply arrives as many MESSAGE_CHUNK events followed by one END_OF_STREAM. Accumulate chunks, then finalize:
let buffer = "";

sdk.on(SYNAPSE_REALTIME_EVENTS.MESSAGE_CHUNK, (evt) => {
  buffer += evt.data.text ?? "";
  renderStreaming(buffer);
});

sdk.on(SYNAPSE_REALTIME_EVENTS.END_OF_STREAM, (evt) => {
  commitMessage(buffer, evt.messageId);
  buffer = "";
});

sdk.on(SYNAPSE_REALTIME_EVENTS.PROGRESS_MESSAGE, (evt) => {
  showTypingIndicator(evt.data.text);
});

Next steps

Tool calls & elicitation

Handle TOOL_CALL events — render inputs and send results back.