@eka-care/medassist-core 1.0.70 → 1.0.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/index.d.mts +1442 -0
  2. package/dist/index.mjs +2 -0
  3. package/dist/messages/types.d.ts +1 -0
  4. package/package.json +1 -1
  5. package/dist/Synapse.d.ts.map +0 -1
  6. package/dist/connection/ConnectionFactory.d.ts.map +0 -1
  7. package/dist/connection/SSE.d.ts.map +0 -1
  8. package/dist/connection/Websocket.d.ts.map +0 -1
  9. package/dist/constants/index.d.ts.map +0 -1
  10. package/dist/constants/types.d.ts.map +0 -1
  11. package/dist/conversation.d.ts.map +0 -1
  12. package/dist/esm/Synapse.js +0 -612
  13. package/dist/esm/connection/ConnectionFactory.js +0 -27
  14. package/dist/esm/connection/SSE.js +0 -212
  15. package/dist/esm/connection/Websocket.js +0 -178
  16. package/dist/esm/constants/index.js +0 -25
  17. package/dist/esm/constants/types.js +0 -1
  18. package/dist/esm/conversation.js +0 -7
  19. package/dist/esm/events/Events.js +0 -41
  20. package/dist/esm/events/Incoming.js +0 -1
  21. package/dist/esm/events/Outgoing.js +0 -1
  22. package/dist/esm/events/index.js +0 -2
  23. package/dist/esm/events/types.js +0 -5
  24. package/dist/esm/index.js +0 -34
  25. package/dist/esm/internal/Api/BaseResource.js +0 -50
  26. package/dist/esm/internal/Api/HttpClient.js +0 -131
  27. package/dist/esm/internal/Api/types.js +0 -1
  28. package/dist/esm/internal/Error/Error.js +0 -229
  29. package/dist/esm/internal/Error/types.js +0 -9
  30. package/dist/esm/internal/connection/BaseConnection.js +0 -134
  31. package/dist/esm/internal/connection/types.js +0 -17
  32. package/dist/esm/internal/events/EventEmitter.js +0 -26
  33. package/dist/esm/internal/store/index.js +0 -5
  34. package/dist/esm/media/audio/Audio.copy.js +0 -363
  35. package/dist/esm/media/audio/Audio.js +0 -310
  36. package/dist/esm/media/audio/types.js +0 -13
  37. package/dist/esm/media/file/File.js +0 -159
  38. package/dist/esm/messages/MessageManager.js +0 -476
  39. package/dist/esm/messages/types.js +0 -35
  40. package/dist/esm/resources/config/Config.js +0 -11
  41. package/dist/esm/resources/feedback/Feedback.js +0 -9
  42. package/dist/esm/resources/feedback/types.js +0 -7
  43. package/dist/esm/resources/index.js +0 -152
  44. package/dist/esm/resources/session/Session.js +0 -44
  45. package/dist/esm/resources/session/types.js +0 -5
  46. package/dist/esm/resources/toolCall/ToolCall.js +0 -12
  47. package/dist/esm/resources/toolCall/types.js +0 -34
  48. package/dist/esm/resources/types.js +0 -4
  49. package/dist/esm/resources/voice/VoiceResource.js +0 -14
  50. package/dist/esm/resources/voice/types.js +0 -1
  51. package/dist/esm/types/index.js +0 -8
  52. package/dist/esm/utils/Error.js +0 -110
  53. package/dist/esm/voice/VoiceAgent.js +0 -305
  54. package/dist/esm/voice/VoiceAudioAnalyser.js +0 -32
  55. package/dist/esm/voice/index.js +0 -1
  56. package/dist/esm/voice/types.js +0 -15
  57. package/dist/events/Events.d.ts.map +0 -1
  58. package/dist/events/Incoming.d.ts.map +0 -1
  59. package/dist/events/Outgoing.d.ts.map +0 -1
  60. package/dist/events/index.d.ts.map +0 -1
  61. package/dist/events/types.d.ts.map +0 -1
  62. package/dist/index.d.ts.map +0 -1
  63. package/dist/internal/Api/BaseResource.d.ts.map +0 -1
  64. package/dist/internal/Api/HttpClient.d.ts.map +0 -1
  65. package/dist/internal/Api/types.d.ts.map +0 -1
  66. package/dist/internal/Error/Error.d.ts.map +0 -1
  67. package/dist/internal/Error/types.d.ts.map +0 -1
  68. package/dist/internal/connection/BaseConnection.d.ts.map +0 -1
  69. package/dist/internal/connection/types.d.ts.map +0 -1
  70. package/dist/internal/events/EventEmitter.d.ts.map +0 -1
  71. package/dist/internal/store/index.d.ts.map +0 -1
  72. package/dist/media/audio/Audio.copy.d.ts.map +0 -1
  73. package/dist/media/audio/Audio.d.ts.map +0 -1
  74. package/dist/media/audio/types.d.ts.map +0 -1
  75. package/dist/media/file/File.d.ts.map +0 -1
  76. package/dist/messages/MessageManager.d.ts.map +0 -1
  77. package/dist/messages/types.d.ts.map +0 -1
  78. package/dist/resources/config/Config.d.ts.map +0 -1
  79. package/dist/resources/feedback/Feedback.d.ts.map +0 -1
  80. package/dist/resources/feedback/types.d.ts.map +0 -1
  81. package/dist/resources/index.d.ts.map +0 -1
  82. package/dist/resources/session/Session.d.ts.map +0 -1
  83. package/dist/resources/session/types.d.ts.map +0 -1
  84. package/dist/resources/toolCall/ToolCall.d.ts.map +0 -1
  85. package/dist/resources/toolCall/types.d.ts.map +0 -1
  86. package/dist/resources/types.d.ts.map +0 -1
  87. package/dist/resources/voice/VoiceResource.d.ts.map +0 -1
  88. package/dist/resources/voice/types.d.ts.map +0 -1
  89. package/dist/types/index.d.ts.map +0 -1
  90. package/dist/utils/Error.d.ts.map +0 -1
  91. package/dist/voice/VoiceAgent.d.ts.map +0 -1
  92. package/dist/voice/VoiceAudioAnalyser.d.ts.map +0 -1
  93. package/dist/voice/index.d.ts.map +0 -1
  94. package/dist/voice/types.d.ts.map +0 -1
@@ -0,0 +1,1442 @@
1
+ /**
2
+ * Types for agent configuration initialization
3
+ */
4
+ interface AgentConfig {
5
+ agentId: string;
6
+ name: string;
7
+ prompt: string;
8
+ firstMessage: string;
9
+ language: string;
10
+ theme?: {
11
+ primaryColor?: string;
12
+ backgroundColor?: string;
13
+ fontFamily?: string;
14
+ };
15
+ metadata?: Record<string, unknown>;
16
+ }
17
+ interface ResourceConfig {
18
+ agentId: string;
19
+ serverUrl: string;
20
+ authorization?: string;
21
+ authToken?: string;
22
+ }
23
+ type ResourceResponse = {
24
+ error?: {
25
+ code: string;
26
+ msg: string;
27
+ };
28
+ };
29
+
30
+ type TDoctorToolResponse = ResourceResponse & TDoctorDetails;
31
+ type TAvailabilitySlotsToolResponse = ResourceResponse & {
32
+ slots: string[];
33
+ };
34
+ type TAvailabilityDatesToolResponse = ResourceResponse & {
35
+ available_dates: string[];
36
+ };
37
+ declare enum SYNAPSE_TOOL_NAME {
38
+ MOBILE_VERIFICATION = "mobile_verification",
39
+ AVAILABILITY_DATES = "availability_dates",
40
+ AVAILABILITY_SLOTS = "availability_slots",
41
+ DOCTOR_AVAILABILITY = "doctor_availability",
42
+ DOCTOR_DETAILS = "doctor_details",
43
+ GET_LOCATION = "get_location"
44
+ }
45
+ declare enum SYNAPSE_COMPONENTS {
46
+ MOBILE = "mobile_number",
47
+ OTP = "otp",
48
+ EMAIL = "email_address",
49
+ PILL = "pills",
50
+ MULTI = "multi",
51
+ DOCTOR_CARD = "doctor_card",
52
+ CARD = "card",
53
+ MEDIA_CARD = "media_card"
54
+ }
55
+ type SYNAPSE_TOOL_TYPES = {
56
+ ELICITATION: "elicitation";
57
+ };
58
+ type TDoctorDetailsMap = {
59
+ [doctor_id: string]: TDoctorDetails;
60
+ };
61
+ type ToolCallbacks = {
62
+ [key in SYNAPSE_TOOL_CALLBACK_NAME]: {
63
+ tool_name: SYNAPSE_TOOL_NAME;
64
+ input_schema: Record<string, unknown>;
65
+ };
66
+ };
67
+ declare enum SYNAPSE_TOOL_CALLBACK_NAME {
68
+ DOCTOR_AVAILABILITY = "get_doctor_availability",
69
+ AVAILABILITY_DATES = "get_available_dates",
70
+ AVAILABILITY_SLOTS = "get_available_slots",
71
+ MOBILE_VERIFICATION = "verify_mobile_number",
72
+ DOCTOR_DETAILS = "get_doctor_details"
73
+ }
74
+ type TGetLocationToolResponse = ResourceResponse & {
75
+ latitude: number;
76
+ longitude: number;
77
+ accuracy?: number;
78
+ };
79
+ type TDoctorCardInput = {
80
+ doctors: TDoctorAvailability[];
81
+ doctor_details?: TDoctorDetailsMap;
82
+ };
83
+ type TOption = {
84
+ id: string;
85
+ label: string;
86
+ value: string;
87
+ };
88
+ type SynapseInputCompMap = {
89
+ [SYNAPSE_COMPONENTS.CARD]: {
90
+ cards: TCardInput[];
91
+ };
92
+ [SYNAPSE_COMPONENTS.DOCTOR_CARD]: TDoctorCardInput;
93
+ [SYNAPSE_COMPONENTS.MEDIA_CARD]: {
94
+ media_card: TMediaCard;
95
+ };
96
+ [SYNAPSE_COMPONENTS.MULTI]: {
97
+ options: TOption[];
98
+ };
99
+ [SYNAPSE_COMPONENTS.PILL]: {
100
+ options: TOption[];
101
+ };
102
+ [SYNAPSE_COMPONENTS.OTP]: {
103
+ otp?: string;
104
+ };
105
+ [SYNAPSE_COMPONENTS.MOBILE]: {
106
+ mobile_number?: string;
107
+ };
108
+ [SYNAPSE_COMPONENTS.EMAIL]: {
109
+ email_address?: string;
110
+ };
111
+ };
112
+ type SynapseSelectedCompMap = {
113
+ [SYNAPSE_COMPONENTS.CARD]: TCardInput;
114
+ [SYNAPSE_COMPONENTS.DOCTOR_CARD]: TDoctorAvailability;
115
+ [SYNAPSE_COMPONENTS.MEDIA_CARD]: TMediaCard;
116
+ [SYNAPSE_COMPONENTS.MULTI]: TOption;
117
+ [SYNAPSE_COMPONENTS.PILL]: TOption;
118
+ [SYNAPSE_COMPONENTS.EMAIL]: {
119
+ email_address?: string;
120
+ };
121
+ [SYNAPSE_COMPONENTS.OTP]: {
122
+ otp?: string;
123
+ };
124
+ [SYNAPSE_COMPONENTS.MOBILE]: {
125
+ mobile_number?: string;
126
+ };
127
+ };
128
+ type ToolInputTypes = SynapseSelectedCompMap[keyof SynapseSelectedCompMap];
129
+ type BaseToolDetails = {
130
+ status?: SYNAPSE_EICITATION_STATUS;
131
+ _meta?: {
132
+ schema?: {
133
+ type: "object";
134
+ properties?: {
135
+ [key: string]: {
136
+ type?: string | number | object;
137
+ description?: string;
138
+ pattern?: string;
139
+ minLength?: number;
140
+ maxLength?: number;
141
+ example?: string;
142
+ };
143
+ };
144
+ required?: string[];
145
+ };
146
+ tool_result?: Record<string, unknown>;
147
+ disp_message?: string;
148
+ hidden_message?: string;
149
+ toast_message?: string;
150
+ mcp_meta_fields?: string[];
151
+ disp_toast_msg?: string;
152
+ orientation?: "vertical" | "horizontal";
153
+ user_hint?: string;
154
+ };
155
+ };
156
+ type ComponentToolDetails<C extends SYNAPSE_COMPONENTS> = BaseToolDetails & {
157
+ component: C;
158
+ input: SynapseInputCompMap[C] & {
159
+ text?: string;
160
+ };
161
+ };
162
+ type ToolDetails = {
163
+ [C in SYNAPSE_COMPONENTS]: ComponentToolDetails<C>;
164
+ }[SYNAPSE_COMPONENTS];
165
+ declare enum SYNAPSE_EICITATION_STATUS {
166
+ PROGRESS = "progress",
167
+ SUCCESS = "success",
168
+ FAILURE = "failure"
169
+ }
170
+ type ToolCallResponse = StreamMatrixToSynapseMessage & ResourceResponse;
171
+
172
+ /**
173
+ * Event types for message layer
174
+ * These are specific to the messaging layer and don't affect the base connection layer
175
+ */
176
+
177
+ interface BaseMessage {
178
+ ev: SOCKET_EVENTS;
179
+ _id: string;
180
+ ts: number;
181
+ }
182
+ interface PingMessage extends BaseMessage {
183
+ ev: (typeof SOCKET_EVENTS)["PING"];
184
+ }
185
+ interface PongMessage extends BaseMessage {
186
+ ev: (typeof SOCKET_EVENTS)["PONG"];
187
+ }
188
+ interface ErrorMessage extends BaseMessage {
189
+ ev: (typeof SOCKET_EVENTS)["ERROR"];
190
+ data: {
191
+ code: string;
192
+ msg: string;
193
+ socket_code?: number;
194
+ };
195
+ }
196
+ interface SyncMessage extends BaseMessage {
197
+ ev: (typeof SOCKET_EVENTS)["SYNC"];
198
+ }
199
+ interface AuthSynapseToMatrixMessage extends BaseMessage {
200
+ ev: (typeof SOCKET_EVENTS)["AUTH"];
201
+ data: {
202
+ token: string;
203
+ };
204
+ }
205
+ interface ChatSynapseToMatrixMessage extends BaseMessage {
206
+ ev: (typeof SOCKET_EVENTS)["CHAT"];
207
+ ct: (typeof SOCKET_CONTENT_TYPES)["TEXT"] | (typeof SOCKET_CONTENT_TYPES)["FILE"] | (typeof SOCKET_CONTENT_TYPES)["TOOL_CALL"] | (typeof SOCKET_CONTENT_TYPES)["AUDIO"];
208
+ data?: {
209
+ urls?: string[];
210
+ text?: string;
211
+ tool_id?: string;
212
+ hidden?: boolean;
213
+ extensions?: string[];
214
+ tool_result?: Record<string, unknown>;
215
+ audio?: string;
216
+ format?: string;
217
+ };
218
+ }
219
+ interface StreamSynapseToMatrixMessage extends BaseMessage {
220
+ ev: (typeof SOCKET_EVENTS)["STREAM"];
221
+ ct: (typeof SOCKET_CONTENT_TYPES)["AUDIO"];
222
+ data: {
223
+ audio: string;
224
+ format: string;
225
+ };
226
+ }
227
+ interface EndOfStreamSynapseToMatrixMessage extends BaseMessage {
228
+ ev: (typeof SOCKET_EVENTS)["END_OF_STREAM"];
229
+ }
230
+ interface ConnectionEstablishedMatrixToSynapseMessage extends BaseMessage {
231
+ ev: (typeof SOCKET_EVENTS)["CONNECTION_ESTABLISHED"];
232
+ sid: string;
233
+ msg: string;
234
+ }
235
+ type ToolCallData = {
236
+ tool_id: string | null;
237
+ tool_type?: SYNAPSE_TOOL_TYPES;
238
+ tool_name: string;
239
+ details?: ToolDetails;
240
+ meta?: Record<string, unknown>;
241
+ };
242
+ interface presignedUrls {
243
+ id: string;
244
+ url: string;
245
+ }
246
+ interface ChatMatrixToSynapseMessage extends BaseMessage {
247
+ ev: (typeof SOCKET_EVENTS)["CHAT"];
248
+ ct: Exclude<SOCKET_CONTENT_TYPES, (typeof SOCKET_CONTENT_TYPES)["AUDIO"]>;
249
+ data: {
250
+ urls?: presignedUrls[];
251
+ exp?: number;
252
+ text?: string;
253
+ tips?: string[];
254
+ } & Partial<ToolCallData>;
255
+ }
256
+ interface StreamMatrixToSynapseMessage extends BaseMessage {
257
+ ev: (typeof SOCKET_EVENTS)["STREAM"];
258
+ ct: (typeof SOCKET_CONTENT_TYPES)["TEXT"] | (typeof SOCKET_CONTENT_TYPES)["TIPS"] | (typeof SOCKET_CONTENT_TYPES)["TOOL_CALL"] | (typeof SOCKET_CONTENT_TYPES)["TOOL_START"] | (typeof SOCKET_CONTENT_TYPES)["TOOL_END"];
259
+ data: {
260
+ text?: string;
261
+ progress_msg?: string;
262
+ tips?: string[];
263
+ } & Partial<ToolCallData>;
264
+ }
265
+ interface EndOfStreamMatrixToSynapseMessage extends BaseMessage {
266
+ ev: (typeof SOCKET_EVENTS)["END_OF_STREAM"];
267
+ ct: (typeof SOCKET_CONTENT_TYPES)["TEXT"];
268
+ }
269
+
270
+ type OutgoingSocketMessage = PingMessage | PongMessage | ErrorMessage | SyncMessage | AuthSynapseToMatrixMessage | ChatSynapseToMatrixMessage | StreamSynapseToMatrixMessage | EndOfStreamSynapseToMatrixMessage;
271
+ type IncomingSocketMessage = PingMessage | PongMessage | ErrorMessage | SyncMessage | ConnectionEstablishedMatrixToSynapseMessage | ChatMatrixToSynapseMessage | StreamMatrixToSynapseMessage | EndOfStreamMatrixToSynapseMessage;
272
+ declare const SOCKET_CONTENT_TYPES: {
273
+ readonly TEXT: "text";
274
+ readonly AUDIO: "audio";
275
+ readonly FILE: "file";
276
+ readonly TOOL_CALL: "tool";
277
+ readonly TIPS: "tips";
278
+ readonly AUDIO_TRANSCRIPT: "audio_transcript";
279
+ readonly TOOL_START: "tool_start";
280
+ readonly TOOL_END: "tool_end";
281
+ };
282
+ type SOCKET_CONTENT_TYPES = (typeof SOCKET_CONTENT_TYPES)[keyof typeof SOCKET_CONTENT_TYPES];
283
+ declare const SOCKET_EVENTS: {
284
+ readonly PING: "ping";
285
+ readonly PONG: "pong";
286
+ readonly CHAT: "chat";
287
+ readonly STREAM: "stream";
288
+ readonly AUTH: "auth";
289
+ readonly END_OF_STREAM: "eos";
290
+ readonly SYNC: "sync";
291
+ readonly ERROR: "err";
292
+ readonly CONNECTION_ESTABLISHED: "conn";
293
+ };
294
+ type SOCKET_EVENTS = (typeof SOCKET_EVENTS)[keyof typeof SOCKET_EVENTS];
295
+ type IncomingSocketErrorMessage = ErrorMessage;
296
+ type IncomingSocketChatMessage = ChatMatrixToSynapseMessage;
297
+ type IncomingSocketStreamMessage = StreamMatrixToSynapseMessage;
298
+ type IncomingSocketEndOfStreamMessage = EndOfStreamMatrixToSynapseMessage;
299
+
300
+ declare const SynapseErrorCode: {
301
+ readonly API: "API_ERROR";
302
+ readonly CONNECTION: "CONNECTION_ERROR";
303
+ readonly RECORDING: "RECORDING_ERROR";
304
+ readonly FILE: "FILE_ERROR";
305
+ readonly SESSION: "SESSION_ERROR";
306
+ readonly MESSAGE: "MESSAGE_ERROR";
307
+ readonly STORE: "STORE_ERROR";
308
+ readonly CONFIGURATION: "CONFIGURATION_ERROR";
309
+ readonly VALIDATION: "VALIDATION_ERROR";
310
+ readonly AUTH: "AUTH_ERROR";
311
+ readonly UNKNOWN: "UNKNOWN_ERROR";
312
+ };
313
+ type SynapseErrorCode = (typeof SynapseErrorCode)[keyof typeof SynapseErrorCode];
314
+ interface SynapseErrorOptions {
315
+ cause?: unknown;
316
+ displayMessage?: string;
317
+ context?: Record<string, unknown>;
318
+ hint?: string;
319
+ }
320
+ declare class SynapseError extends Error {
321
+ readonly code: SynapseErrorCode;
322
+ readonly timestamp: Date;
323
+ readonly cause?: unknown;
324
+ readonly context?: Record<string, unknown>;
325
+ readonly hint?: string;
326
+ readonly displayMessage?: string;
327
+ constructor(message: string, code?: SynapseErrorCode, options?: SynapseErrorOptions);
328
+ }
329
+ declare class APIError<TStatus extends number | undefined = number | undefined, THeader extends Headers | undefined = Headers | undefined, TError extends Record<string, unknown> | undefined = Record<string, unknown> | undefined> extends SynapseError {
330
+ /** HTTP status code */
331
+ readonly status?: TStatus;
332
+ /** JSON body of the error response or custom error object */
333
+ readonly error?: TError;
334
+ /** HTTP response headers */
335
+ readonly headers?: THeader;
336
+ constructor(message: string, status?: TStatus, error?: TError, headers?: THeader);
337
+ private static makeMessage;
338
+ static generate(status: number | undefined, errorResponse: Record<string, unknown> | undefined, message?: string, headers?: Headers): APIError<number, Headers, Record<string, unknown>>;
339
+ }
340
+ declare class APIUserAbortError extends APIError<undefined, undefined, undefined> {
341
+ constructor({ message }?: {
342
+ message?: string;
343
+ });
344
+ }
345
+ declare class APIConnectionTimeoutError extends APIError<undefined, undefined, undefined> {
346
+ constructor({ message }?: {
347
+ message?: string;
348
+ });
349
+ }
350
+ declare class BadRequestError extends APIError<400, Headers, Record<string, unknown>> {
351
+ constructor(message: string, status: 400, error?: Record<string, unknown>, headers?: Headers);
352
+ }
353
+ declare class UnauthorizedError extends APIError<401, Headers, Record<string, unknown>> {
354
+ constructor(message: string, status: 401, error?: Record<string, unknown>, headers?: Headers);
355
+ }
356
+ declare class PermissionDeniedError extends APIError<403, Headers, Record<string, unknown>> {
357
+ constructor(message: string, status: 403, error?: Record<string, unknown>, headers?: Headers);
358
+ }
359
+ declare class NotFoundError extends APIError<404, Headers, Record<string, unknown>> {
360
+ constructor(message: string, status: 404, error?: Record<string, unknown>, headers?: Headers);
361
+ }
362
+ declare class MethodNotAllowedError extends APIError<405, Headers, Record<string, unknown>> {
363
+ constructor(message: string, status: 405, error?: Record<string, unknown>, headers?: Headers);
364
+ }
365
+ declare class RateLimitError extends APIError<429, Headers, Record<string, unknown>> {
366
+ constructor(message: string, status: 429, error?: Record<string, unknown>, headers?: Headers);
367
+ }
368
+ declare class InternalServerError extends APIError<number, Headers, Record<string, unknown>> {
369
+ constructor(message: string, status: number, error?: Record<string, unknown>, headers?: Headers);
370
+ }
371
+ declare class RecordingError extends SynapseError {
372
+ constructor(message: string, options?: SynapseErrorOptions);
373
+ }
374
+
375
+ interface AudioMetaData {
376
+ audio: string;
377
+ format: string;
378
+ duration: number;
379
+ timestamp: number;
380
+ }
381
+ interface AudioConfig {
382
+ mimeType: string;
383
+ audioBitsPerSecond: number;
384
+ maxRecordingDuration: number;
385
+ autoPauseEnabled: boolean;
386
+ }
387
+ type AudioDataCallback = (data: AudioMetaData) => void;
388
+ type AudioErrorCallback = (error: RecordingError) => void;
389
+
390
+ /**
391
+ * Types for message management
392
+ */
393
+
394
+ declare const SYNAPSE_MESSAGE_TYPES: {
395
+ readonly TEXT: "text";
396
+ readonly AUDIO: "audio";
397
+ readonly FILE: "file";
398
+ readonly TOOL_CALL: "tool";
399
+ readonly TIPS: "tips";
400
+ readonly AUDIO_TRANSCRIPT: "audio_transcript";
401
+ readonly TOOL_START: "tool_start";
402
+ readonly TOOL_END: "tool_end";
403
+ };
404
+ type ContentType = SOCKET_CONTENT_TYPES;
405
+ type IncomingMessage = IncomingSocketMessage;
406
+ type OutgoingMessage = OutgoingSocketMessage;
407
+ interface SocketChatRequestData {
408
+ message?: string;
409
+ messageId?: string;
410
+ files?: File[];
411
+ audio?: AudioMetaData;
412
+ urls?: string[];
413
+ tool_id?: string;
414
+ tool_declined?: boolean;
415
+ hidden?: boolean;
416
+ tool_result?: Record<string, unknown>;
417
+ initial_prompts?: TInitalPrompt[];
418
+ }
419
+ type TInitalPrompt = {
420
+ role: string;
421
+ text: string;
422
+ };
423
+ declare const SYNAPSE_REALTIME_EVENTS: {
424
+ readonly CONNECTED: "connected";
425
+ readonly DISCONNECTED: "disconnected";
426
+ readonly PROGRESS_MESSAGE: "progress_message";
427
+ readonly MESSAGE_CHUNK: "message_chunk";
428
+ readonly TIPS_MESSAGE: "tips_message";
429
+ readonly END_OF_STREAM: "end_of_stream";
430
+ readonly ERROR: "error";
431
+ readonly TOOL_CALL: "tool_call";
432
+ readonly AUDIO_TRANSCRIPT: "audio_transcript";
433
+ readonly TOOL_START: "tool_start";
434
+ readonly TOOL_END: "tool_end";
435
+ };
436
+ type SYNAPSE_REALTIME_EVENTS = (typeof SYNAPSE_REALTIME_EVENTS)[keyof typeof SYNAPSE_REALTIME_EVENTS];
437
+ declare const SYNAPSE_REALTIME_ERROR_CODES: {
438
+ readonly SESSION_INACTIVE: "session_not_found";
439
+ readonly SESSION_EXPIRED: "session_expired";
440
+ readonly INVALID_EVENT: "invalid_event";
441
+ readonly INVALID_CONTENT_TYPE: "invalid_content";
442
+ readonly PARSING_ERROR: "parsing";
443
+ readonly FILE_UPLOAD_INPROGRESS: "file_upload_inprogress";
444
+ readonly TIMEOUT: "timeout";
445
+ readonly SERVER_ERROR: "server_error";
446
+ readonly SESSION_TOKEN_MISMATCH: "session_token_mismatch";
447
+ readonly PROMPT_FETCH_ERROR: "prompt_fetch_error";
448
+ readonly INVALID_FILE_REQUEST: "invalid_file_request";
449
+ };
450
+ type SYNAPSE_REALTIME_ERROR_CODES = (typeof SYNAPSE_REALTIME_ERROR_CODES)[keyof typeof SYNAPSE_REALTIME_ERROR_CODES];
451
+ declare const SYNAPSE_REALTIME_RESERVED_EVENTS: {
452
+ readonly SESSION_EXPIRED: "session_expired";
453
+ };
454
+ type SYNAPSE_REALTIME_RESERVED_EVENTS = (typeof SYNAPSE_REALTIME_RESERVED_EVENTS)[keyof typeof SYNAPSE_REALTIME_RESERVED_EVENTS];
455
+ type SOCKET_STREAM_DATA = AudioMetaData;
456
+ type SynapseRealTimeEventData = {
457
+ data: {
458
+ text?: string;
459
+ tips?: string[];
460
+ name?: string;
461
+ } & Partial<ToolCallData>;
462
+ messageId?: string;
463
+ timestamp?: number;
464
+ };
465
+ type TDoctorAvailability = {
466
+ hospital_id?: string;
467
+ doctor_id?: string;
468
+ preferred_date?: string;
469
+ preferred_slot_time?: string;
470
+ availability?: TAvailability[];
471
+ date_preference?: string;
472
+ slot_preference?: string;
473
+ cta?: TCardCta;
474
+ };
475
+ type TAvailability = {
476
+ date?: string;
477
+ day?: string;
478
+ slots?: string[];
479
+ selected_slot?: string;
480
+ };
481
+ type THospital = {
482
+ hospital_id: string;
483
+ name?: string;
484
+ city?: string;
485
+ state?: string;
486
+ region_id?: string;
487
+ };
488
+ type TDoctorDetails = {
489
+ name: string;
490
+ specialty: string;
491
+ hospitals: THospital[];
492
+ timings?: string;
493
+ experience?: string;
494
+ profile_link?: string;
495
+ profile_pic?: string;
496
+ languages?: string;
497
+ info?: string;
498
+ };
499
+ type TCardInput = {
500
+ card_id: string;
501
+ title?: string;
502
+ tags?: string;
503
+ icon?: string;
504
+ description?: string;
505
+ banner?: {
506
+ text: string;
507
+ theme: string;
508
+ };
509
+ banner_text?: string;
510
+ img?: string;
511
+ items?: TCardItem[];
512
+ primary_cta?: TCardCta;
513
+ secondary_cta?: TCardCta;
514
+ };
515
+ type TCardItem = {
516
+ icon?: string;
517
+ text: string;
518
+ };
519
+ type TCardCta = {
520
+ cta_id: string;
521
+ title: string;
522
+ link?: string;
523
+ action?: string;
524
+ icon?: string;
525
+ text?: string;
526
+ tool_result?: Record<string, unknown>;
527
+ };
528
+ type TCardTheme = "success" | "warning" | "danger" | "primary";
529
+ type TMediaCard = {
530
+ title?: string;
531
+ description?: string;
532
+ tags?: string;
533
+ tags_text?: string;
534
+ banner_text?: string;
535
+ action?: "download" | "screenshot";
536
+ link?: string;
537
+ };
538
+ type SynapseContentTypes = SOCKET_CONTENT_TYPES;
539
+
540
+ type TInitialMessage = {
541
+ text?: string;
542
+ suggestions?: {
543
+ label?: string;
544
+ value?: string;
545
+ response?: string;
546
+ }[];
547
+ };
548
+ interface SessionResponse extends ResourceResponse {
549
+ session_id: string;
550
+ session_token?: string;
551
+ session_validity_s?: string;
552
+ user_id?: string;
553
+ msg?: string;
554
+ initial_message?: TInitialMessage;
555
+ }
556
+ interface AgentConfigResponse extends ResourceResponse {
557
+ connectivity?: "sse" | "socket";
558
+ theme?: {
559
+ background?: string;
560
+ background_img?: string;
561
+ accent?: string;
562
+ mode?: "light" | "dark";
563
+ title_img?: string;
564
+ title?: string;
565
+ tagline?: string;
566
+ };
567
+ initial_message?: TInitialMessage;
568
+ hide_watermark?: boolean;
569
+ }
570
+ interface SessionCreateRequest {
571
+ user_id?: string;
572
+ user_context?: TProfile;
573
+ session_context?: {
574
+ intent?: string;
575
+ user_location?: {
576
+ lat: number;
577
+ long: number;
578
+ };
579
+ [key: string]: unknown;
580
+ };
581
+ referer?: string;
582
+ }
583
+ type TProfile = {
584
+ mobile?: string;
585
+ name?: string;
586
+ age?: number;
587
+ gender?: "F" | "M" | "O";
588
+ marital_status?: string;
589
+ [key: string]: unknown;
590
+ };
591
+ type TContext = {
592
+ profile?: TProfile;
593
+ intent?: string;
594
+ user_location?: {
595
+ lat: number;
596
+ long: number;
597
+ };
598
+ referer?: string;
599
+ [key: string]: unknown;
600
+ };
601
+ declare const USER_FEEDBACK: {
602
+ readonly LIKE: "LIKE";
603
+ readonly DISLIKE: "DISLIKE";
604
+ readonly NONE: "NONE";
605
+ };
606
+ type USER_FEEDBACK = (typeof USER_FEEDBACK)[keyof typeof USER_FEEDBACK];
607
+
608
+ type Environment$1 = "development" | "production" | "staging";
609
+
610
+ /**
611
+ * Connection types and interfaces for the Synapse SDK
612
+ */
613
+
614
+ declare const ConnectionStatus: {
615
+ readonly CONNECTING: "connecting";
616
+ readonly CONNECTED: "connected";
617
+ readonly NOT_CONNECTED: "not_connected";
618
+ };
619
+ type ConnectionStatus = (typeof ConnectionStatus)[keyof typeof ConnectionStatus];
620
+ declare const DisconnectionReason: {
621
+ readonly CLIENT_CLOSED: "client_closed";
622
+ readonly SERVER_CLOSED: "server_closed";
623
+ readonly CONNECTION_ERROR: "connection_error";
624
+ readonly AUTHENTICATION_ERROR: "authentication_error";
625
+ readonly MAX_RECONNECT_ATTEMPTS: "max_reconnect_attempts";
626
+ readonly TIMEOUT: "timeout";
627
+ readonly NETWORK_ERROR: "network_error";
628
+ };
629
+ type DisconnectionReason = (typeof DisconnectionReason)[keyof typeof DisconnectionReason];
630
+ interface DisconnectionDetails {
631
+ reason: DisconnectionReason;
632
+ message?: string;
633
+ code?: number;
634
+ timestamp: Date;
635
+ }
636
+ interface SessionConfig {
637
+ agentId: string;
638
+ authorization?: string;
639
+ overrides?: {
640
+ prompt?: string;
641
+ firstMessage?: string;
642
+ language?: string;
643
+ voiceId?: string;
644
+ };
645
+ userId?: string;
646
+ }
647
+ type OnDisconnectCallback = (details: DisconnectionDetails) => void;
648
+ type OnMessageCallback = (event: IncomingMessage) => void;
649
+ type OnStatusChangeCallback = (status: ConnectionStatus) => void;
650
+ type OnOpenCallback = () => void;
651
+ type OnErrorCallback = (error: Error) => void;
652
+
653
+ /**
654
+ * Abstract base class for all connection types
655
+ */
656
+
657
+ declare abstract class BaseConnection {
658
+ /**
659
+ * Unique identifier for the current conversation
660
+ */
661
+ abstract readonly conversationId: string;
662
+ /**
663
+ * Current connection status
664
+ */
665
+ protected status: ConnectionStatus;
666
+ /**
667
+ * Queue to store messages received before callback is registered
668
+ */
669
+ protected queue: IncomingMessage[];
670
+ /**
671
+ * Event emitter to handle events
672
+ */
673
+ private eventEmitter;
674
+ /**
675
+ * Disconnection details (null if still connected)
676
+ */
677
+ protected disconnectionDetails: DisconnectionDetails | null;
678
+ protected onErrorCallback: OnErrorCallback | null;
679
+ protected onDisconnectCallback: OnDisconnectCallback | null;
680
+ protected onMessageCallback: OnMessageCallback | null;
681
+ protected onOpenCallback: OnOpenCallback | null;
682
+ protected onStatusChangeCallback: OnStatusChangeCallback | null;
683
+ /**
684
+ * Close the connection
685
+ */
686
+ abstract close(): void;
687
+ /**
688
+ * Send a message through the connection
689
+ */
690
+ abstract sendMessage(message: OutgoingMessage): void;
691
+ /**
692
+ * Get current connection status
693
+ */
694
+ getStatus(): ConnectionStatus;
695
+ /**
696
+ * Register callback for connection open events
697
+ */
698
+ onOpen(callback: OnOpenCallback): void;
699
+ /**
700
+ * Register callback for incoming messages
701
+ */
702
+ onMessage(callback: OnMessageCallback): void;
703
+ /**
704
+ * Register callback for disconnection events
705
+ */
706
+ onDisconnect(callback: OnDisconnectCallback): void;
707
+ /**
708
+ * Register callback for error events
709
+ */
710
+ onError(callback: OnErrorCallback): void;
711
+ /**
712
+ * Register a listener for a specific event
713
+ */
714
+ on(event: string, listener: (...args: unknown[]) => void): void;
715
+ /**
716
+ * Remove a listener for a specific event
717
+ */
718
+ off(event: string, listener: (...args: unknown[]) => void): void;
719
+ /**
720
+ * Emit an event
721
+ */
722
+ emit(event: string, ...args: unknown[]): void;
723
+ /**
724
+ * Register callback for status changes
725
+ */
726
+ onStatusChange(callback: OnStatusChangeCallback): void;
727
+ /**
728
+ * Protected method to handle disconnection
729
+ * Ensures disconnect callback is only invoked once
730
+ */
731
+ protected disconnect(details: DisconnectionDetails): void;
732
+ /**
733
+ * Protected method to handle incoming messages
734
+ * Queues messages if no callback is registered yet
735
+ * message type can be extended to include more types of messages
736
+ */
737
+ protected handleMessage(message: IncomingMessage): void;
738
+ /**
739
+ * Protected method to update connection status
740
+ */
741
+ protected updateStatus(status: ConnectionStatus): void;
742
+ /**
743
+ * Check if the connection is connected
744
+ */
745
+ abstract isConnected(): boolean;
746
+ /**
747
+ * handle connection established event
748
+ */
749
+ abstract handleConnected(): void;
750
+ }
751
+
752
+ /**
753
+ * WebSocket implementation of BaseConnection
754
+ */
755
+
756
+ interface WebSocketConnectionConfig extends SessionConfig {
757
+ serverUrl: string;
758
+ auth: {
759
+ sessionToken: string;
760
+ sessionId: string;
761
+ };
762
+ reconnect?: boolean;
763
+ reconnectAttempts?: number;
764
+ reconnectDelay?: number;
765
+ }
766
+ declare class WebSocketConnection extends BaseConnection {
767
+ readonly conversationId: string;
768
+ private socket;
769
+ private config;
770
+ private authenticated;
771
+ constructor(config: WebSocketConnectionConfig);
772
+ /**
773
+ * Establish WebSocket connection
774
+ */
775
+ private connect;
776
+ /**
777
+ * Build WebSocket connection URL with session config
778
+ */
779
+ private buildConnectionUrl;
780
+ /**
781
+ * Handle WebSocket open event
782
+ */
783
+ private handleOpen;
784
+ /**
785
+ * Handle incoming WebSocket messages
786
+ */
787
+ private handleSocketMessage;
788
+ /**
789
+ * Handle WebSocket errors
790
+ */
791
+ private handleError;
792
+ /**
793
+ * Handle WebSocket close event
794
+ */
795
+ private handleClose;
796
+ /**
797
+ * Send a message through the WebSocket
798
+ */
799
+ sendMessage(message: OutgoingSocketMessage): void;
800
+ /**
801
+ * Close the WebSocket connection
802
+ */
803
+ close(): void;
804
+ /**
805
+ * Check if the WebSocket is connected
806
+ */
807
+ isConnected(): boolean;
808
+ handleConnected(): void;
809
+ }
810
+
811
+ /**
812
+ * Server-Sent Events implementation of BaseConnection.
813
+ *
814
+ * Unlike the classic GET + EventSource pattern, this server streams events
815
+ * back as the response body of a POST to /chat. The request body is the
816
+ * same OutgoingSocketMessage envelope used over the WebSocket, so
817
+ * MessageManager parsing is shared.
818
+ *
819
+ * Wire shape:
820
+ * POST {serverUrl}/med-assist/session/{sessionId}/chat
821
+ * Headers: Content-Type: application/json
822
+ * Accept: text/event-stream
823
+ * sess-token: <session token>
824
+ * x-agent-id: <agent id>
825
+ * Body: JSON-encoded OutgoingSocketMessage
826
+ * Response: text/event-stream with `data: <json>\n\n` frames whose payloads
827
+ * match the IncomingSocketMessage shape.
828
+ */
829
+
830
+ interface SSEConnectionConfig extends SessionConfig {
831
+ serverUrl: string;
832
+ auth: {
833
+ sessionToken: string;
834
+ sessionId: string;
835
+ };
836
+ }
837
+ declare class SSEConnection extends BaseConnection {
838
+ readonly conversationId: string;
839
+ private config;
840
+ private connected;
841
+ private activeStreamController;
842
+ constructor(config: SSEConnectionConfig);
843
+ /**
844
+ * "Open" the SSE channel. There is no persistent socket — the connection
845
+ * is considered ready as soon as the session/agent identifiers are set.
846
+ * Each outgoing message opens its own short-lived streaming response.
847
+ *
848
+ * The open callback is deferred to a macrotask so it fires AFTER
849
+ * `Synapse.startSession()` resolves and the consumer (e.g. widget's
850
+ * `setUpEventListeners`) has had a chance to register the CONNECTED
851
+ * listener. With WebSocket the real socket open is naturally async; we
852
+ * have to simulate that here, otherwise the CONNECTED event is emitted
853
+ * before anyone is listening for it.
854
+ */
855
+ private connect;
856
+ /**
857
+ * Fire the open callback if the connection is already up by the time
858
+ * the listener registers. Mirrors the queued-disconnect pattern in
859
+ * BaseConnection so late-registering consumers don't miss the open
860
+ * event. Deferred via setTimeout for the same reason as connect().
861
+ */
862
+ onOpen(callback: OnOpenCallback): void;
863
+ private buildChatUrl;
864
+ /**
865
+ * Send an outgoing message. POSTs the same envelope used over the
866
+ * WebSocket and streams the response back as SSE-encoded events.
867
+ */
868
+ sendMessage(message: OutgoingSocketMessage): void;
869
+ private streamChat;
870
+ /**
871
+ * Walk the buffer and dispatch every complete top-level JSON object it
872
+ * contains, returning any trailing partial-object bytes that still need
873
+ * more data. The server streams back-to-back objects (`{…}{…}{…}`) with
874
+ * no separator, so we track brace depth (respecting strings/escapes)
875
+ * to find each object boundary. Any whitespace or stray SSE prefixes
876
+ * between objects is skipped automatically since we anchor on `{`.
877
+ */
878
+ private extractJsonObjects;
879
+ /**
880
+ * Return the index of the matching closing brace for the `{` at `start`,
881
+ * or -1 if the buffer ends before the object closes. String contents
882
+ * and escape sequences are skipped so braces inside strings don't
883
+ * affect the depth count.
884
+ */
885
+ private findObjectEnd;
886
+ close(): void;
887
+ isConnected(): boolean;
888
+ handleConnected(): void;
889
+ }
890
+
891
+ /**
892
+ * Factory class to create the appropriate connection type
893
+ */
894
+
895
+ declare const ConnectionType: {
896
+ readonly SOCKET: "socket";
897
+ readonly SSE: "sse";
898
+ };
899
+ type ConnectionType = (typeof ConnectionType)[keyof typeof ConnectionType];
900
+ type ConnectionConfig = WebSocketConnectionConfig | SSEConnectionConfig;
901
+ declare class ConnectionFactory {
902
+ /**
903
+ * Create a connection based on the specified type
904
+ */
905
+ static createConnection(type: ConnectionType, config: ConnectionConfig): Promise<BaseConnection>;
906
+ }
907
+
908
+ declare const ErrorType: {
909
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
910
+ readonly TIMEOUT_ERROR: "TIMEOUT_ERROR";
911
+ readonly API_ERROR: "API_ERROR";
912
+ readonly RATE_LIMIT_ERROR: "RATE_LIMIT_ERROR";
913
+ readonly SERVER_ERROR: "SERVER_ERROR";
914
+ readonly PARSE_ERROR: "PARSE_ERROR";
915
+ readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
916
+ };
917
+ type ErrorType = (typeof ErrorType)[keyof typeof ErrorType];
918
+
919
+ /**
920
+ * Shared types across the SDK
921
+ */
922
+
923
+ interface SendMessageOptions {
924
+ message?: string;
925
+ messageId?: string;
926
+ files?: File[];
927
+ audio?: AudioMetaData;
928
+ toolCalled?: boolean;
929
+ tool_declined?: boolean;
930
+ tool_id?: string;
931
+ initial_prompts?: TInitalPrompt[];
932
+ tool_result?: Record<string, unknown>;
933
+ hidden?: boolean;
934
+ }
935
+ interface SynapseSDKOverrides {
936
+ prompt?: string;
937
+ firstMessage?: string;
938
+ language?: string;
939
+ primaryColor?: string;
940
+ }
941
+ /**
942
+ * Unified error shape exposed to SDK consumers.
943
+ * All internal errors (APIError, SessionError, ConnectionError, etc.)
944
+ * are normalized to this before reaching the client.
945
+ */
946
+ interface TSynapseError {
947
+ /** Human-readable message suitable for display */
948
+ message: string;
949
+ /** Parsed API error body, when the error originated from an HTTP response */
950
+ error?: {
951
+ code?: string;
952
+ msg?: string;
953
+ } & Record<string, unknown>;
954
+ /** Internal error classification (e.g. "SESSION_ERROR", "CONNECTION_ERROR") */
955
+ code?: string;
956
+ /** HTTP status code, when applicable */
957
+ status?: number;
958
+ /** Extra context set by the SDK (stage, sessionId, etc.) */
959
+ context?: Record<string, unknown>;
960
+ }
961
+ interface SynapseSDKCallbacks {
962
+ onSessionRefreshed?: (sessionResponse: SessionResponse) => void;
963
+ onError?: (error: TSynapseError) => void;
964
+ }
965
+ interface SynapseSDKConfig {
966
+ agentId: string;
967
+ environment?: Environment$1;
968
+ userId?: string;
969
+ connectionType?: ConnectionType;
970
+ overrides?: SynapseSDKOverrides;
971
+ callbacks?: SynapseSDKCallbacks;
972
+ context?: TContext;
973
+ auth?: string;
974
+ authToken?: string;
975
+ serverUrl?: string;
976
+ }
977
+ interface ExistingSessionOptions {
978
+ session_id: string;
979
+ session_token: string;
980
+ }
981
+
982
+ type Environment = "development" | "production" | "staging";
983
+
984
+ declare const VOICE_AGENT_STATE: {
985
+ readonly IDLE: "idle";
986
+ readonly CONNECTING: "connecting";
987
+ readonly CONNECTED: "connected";
988
+ readonly LISTENING: "listening";
989
+ readonly THINKING: "thinking";
990
+ readonly SPEAKING: "speaking";
991
+ readonly MUTED: "muted";
992
+ readonly DISCONNECTING: "disconnecting";
993
+ readonly ERROR: "error";
994
+ };
995
+ type VOICE_AGENT_STATE = (typeof VOICE_AGENT_STATE)[keyof typeof VOICE_AGENT_STATE];
996
+ declare const VOICE_AGENT_EVENTS: {
997
+ readonly STATE_CHANGED: "voice:state_changed";
998
+ readonly ERROR: "voice:error";
999
+ };
1000
+ type VOICE_AGENT_EVENTS = (typeof VOICE_AGENT_EVENTS)[keyof typeof VOICE_AGENT_EVENTS];
1001
+ interface VoiceAgentConfig {
1002
+ baseUrl?: string;
1003
+ offerUrl?: string;
1004
+ handleRefresh?: () => Promise<void>;
1005
+ iceServers?: RTCIceServer[];
1006
+ iceGatheringTimeoutMs?: number;
1007
+ speakingThreshold?: number;
1008
+ environment?: Environment;
1009
+ }
1010
+ interface VoiceSessionCredentials {
1011
+ sessionId: string;
1012
+ sessionToken: string;
1013
+ }
1014
+ interface VoiceError {
1015
+ message: string;
1016
+ cause?: unknown;
1017
+ }
1018
+
1019
+ interface IceServersResponse {
1020
+ ice_servers: RTCIceServer[];
1021
+ }
1022
+ interface VoiceOfferRequest {
1023
+ sdp: string;
1024
+ type: string;
1025
+ pc_id: string | null;
1026
+ request_data: {
1027
+ session_id: string;
1028
+ token: string;
1029
+ };
1030
+ }
1031
+ interface VoiceOfferResponse extends ResourceResponse {
1032
+ sdp: string;
1033
+ type: string;
1034
+ pc_id: string;
1035
+ }
1036
+
1037
+ /**
1038
+ * Init class to fetch agent configuration from the platform
1039
+ */
1040
+
1041
+ declare class ResourceManager {
1042
+ private resourceConfig;
1043
+ private httpClient;
1044
+ private session;
1045
+ private config;
1046
+ private voiceResource;
1047
+ constructor(config: ResourceConfig);
1048
+ /**
1049
+ * Fetch agent configuration and create session
1050
+ */
1051
+ createSession(userId?: string, context?: TContext): Promise<SessionResponse>;
1052
+ getAgentConfig(): Promise<AgentConfigResponse>;
1053
+ /**
1054
+ * Validate a session if it's still active or not
1055
+ * GET /med-assist/session/:sessionId
1056
+ */
1057
+ validateSession(sessionId: string): Promise<{
1058
+ expired: boolean;
1059
+ active: boolean;
1060
+ }>;
1061
+ /**
1062
+ * Refresh a session
1063
+ * POST /med-assist/session/:sessionId/refresh
1064
+ */
1065
+ refreshSession(sessionId: string, sessionToken: string): Promise<SessionResponse>;
1066
+ /**
1067
+ * Feedback on a message
1068
+ * PATCH /med-assist/session/:sessionId/:messageId
1069
+ */
1070
+ sendFeedback(sessionId: string, messageId: string, feedback: USER_FEEDBACK, feedbackReason?: string): Promise<void>;
1071
+ /**
1072
+ * Call a tool
1073
+ * POST /med-assist/api-call-tool
1074
+ */
1075
+ callTool(sessionId: string, toolId: string, message_id: string, session_token: string, toolParams?: Record<string, unknown>): Promise<ToolCallResponse>;
1076
+ getVoiceIceServers(sessionId: string, sessionToken: string): Promise<IceServersResponse>;
1077
+ sendVoiceOffer(body: VoiceOfferRequest): Promise<VoiceOfferResponse>;
1078
+ }
1079
+
1080
+ declare class VoiceAgent {
1081
+ private config;
1082
+ private resourceManager;
1083
+ private getCredentials;
1084
+ private emitter;
1085
+ private remoteAnalyser;
1086
+ private localAnalyser;
1087
+ private pc;
1088
+ private pcId;
1089
+ private dataChannel;
1090
+ private localStream;
1091
+ private remoteAudio;
1092
+ private _state;
1093
+ private _isMuted;
1094
+ private manuallyDisconnected;
1095
+ private _hasConnectionFailureNotified;
1096
+ private _userSpeaking;
1097
+ private _silenceTimer;
1098
+ private _cachedIceServers;
1099
+ private _iceServersCachedAt;
1100
+ constructor(config: VoiceAgentConfig, resourceManager: ResourceManager, getCredentials: () => Promise<VoiceSessionCredentials>);
1101
+ get state(): VOICE_AGENT_STATE;
1102
+ get isMuted(): boolean;
1103
+ on(event: string, listener: (...args: unknown[]) => void): void;
1104
+ off(event: string, listener: (...args: unknown[]) => void): void;
1105
+ connect(): Promise<void>;
1106
+ disconnect(): void;
1107
+ toggleMute(): void;
1108
+ reset(): void;
1109
+ destroy(): void;
1110
+ private fetchIceServers;
1111
+ private setState;
1112
+ private clearSilenceTimer;
1113
+ private handleConnectionFailure;
1114
+ private releaseResources;
1115
+ private startLocalAudioAnalysis;
1116
+ private handleRemoteTrack;
1117
+ }
1118
+
1119
+ /**
1120
+ * High-level SynapseSDK API
1121
+ * Provides a simple interface for managing chat sessions
1122
+ */
1123
+
1124
+ declare class SynapseSDK {
1125
+ private connection;
1126
+ private messageManager;
1127
+ private resourceManager;
1128
+ private sessionConfig;
1129
+ private config;
1130
+ private connectionType;
1131
+ private isRefreshingSession;
1132
+ private connectionAttempts;
1133
+ private sdkEventEmitter;
1134
+ private _voice;
1135
+ constructor(config: SynapseSDKConfig);
1136
+ /**
1137
+ * Start the session
1138
+ * if existing session is provided, it will be validated and refreshed
1139
+ * if no existing session is provided, a new session will be created
1140
+ * then the connection will be initialized and event handlers will be setup
1141
+ * return the session response
1142
+ */
1143
+ startSession(existingSession?: ExistingSessionOptions): Promise<SessionResponse>;
1144
+ /**
1145
+ * Send a message conetnt will be text always
1146
+ */
1147
+ sendMessage({ message, files, audio, tool_declined, tool_id, initial_prompts, tool_result }: SendMessageOptions): Promise<void>;
1148
+ /**
1149
+ * Send feedback on a message
1150
+ */
1151
+ sendFeedback(messageId: string, feedback: USER_FEEDBACK, reason?: string): Promise<void>;
1152
+ /**
1153
+ * Register a listener for a specific event
1154
+ */
1155
+ on(event: SYNAPSE_REALTIME_EVENTS, listener: (...args: unknown[]) => void): void;
1156
+ /**
1157
+ * Remove a listener for a specific event
1158
+ */
1159
+ off(event: SYNAPSE_REALTIME_EVENTS, listener: (...args: unknown[]) => void): void;
1160
+ /**
1161
+ * Get the session ID
1162
+ */
1163
+ getSessionConfig(): SessionResponse;
1164
+ /**
1165
+ * Call tool
1166
+ */
1167
+ callTool(tool_id: string, message_id: string, params?: Record<string, unknown>): Promise<void>;
1168
+ /**
1169
+ * Send audio
1170
+ * */
1171
+ startRecording({ onChunks, onError, }: {
1172
+ onChunks: (chunks: AudioMetaData) => void;
1173
+ onError?: (error: Error) => void;
1174
+ }): Promise<void>;
1175
+ /**
1176
+ * Stop recording audio
1177
+ */
1178
+ endRecording(): void;
1179
+ getAgentConfig(): Promise<AgentConfigResponse>;
1180
+ isConnected(): boolean;
1181
+ get voice(): VoiceAgent;
1182
+ /**
1183
+ * End the session
1184
+ */
1185
+ endSession(): void;
1186
+ private buildVoiceConfig;
1187
+ private toClientError;
1188
+ private emitError;
1189
+ private toSessionError;
1190
+ /**
1191
+ * Initialize the connection
1192
+ * eg: socket connection or polling connection
1193
+ */
1194
+ private initializeConnection;
1195
+ /**
1196
+ * Resolve the session
1197
+ * function to decide whether to create a new session or refresh the existing session
1198
+ */
1199
+ private manageSession;
1200
+ /**
1201
+ * Refresh the session
1202
+ */
1203
+ private refreshSession;
1204
+ /**
1205
+ * Create a new session
1206
+ */
1207
+ private createNewSession;
1208
+ /**
1209
+ * Set up event handlers for connection and messages
1210
+ */
1211
+ private setupEventHandlers;
1212
+ /**
1213
+ * Handle socket error
1214
+ */
1215
+ private onSocketConnectionError;
1216
+ /**
1217
+ * Handle socket connection open
1218
+ */
1219
+ private onSocketConnectionOpen;
1220
+ /**
1221
+ * Handle incoming socket messages
1222
+ */
1223
+ private onIncomingSocketMessage;
1224
+ /**
1225
+ * Handle session expired
1226
+ */
1227
+ private handleSessionExpiry;
1228
+ private toConnectionError;
1229
+ private closeConnection;
1230
+ private cleanup;
1231
+ }
1232
+
1233
+ interface RequestOptions {
1234
+ body?: unknown;
1235
+ headers?: Record<string, string>;
1236
+ params?: Record<string, string>;
1237
+ retries?: number;
1238
+ }
1239
+
1240
+ interface HttpClientConfig {
1241
+ baseUrl: string;
1242
+ apiKey?: string;
1243
+ authorization?: string;
1244
+ timeout?: number;
1245
+ maxRetries?: number;
1246
+ headers?: Record<string, string>;
1247
+ }
1248
+ declare class HttpClient {
1249
+ private baseUrl;
1250
+ private headers;
1251
+ private timeout;
1252
+ private maxRetries;
1253
+ constructor(config: HttpClientConfig);
1254
+ private request;
1255
+ get<T>(path: string, params?: Record<string, string>, options?: RequestOptions): Promise<T>;
1256
+ post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
1257
+ put<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
1258
+ delete<T>(path: string, options?: RequestOptions): Promise<T>;
1259
+ patch<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
1260
+ private buildUrl;
1261
+ private handleError;
1262
+ }
1263
+
1264
+ /**
1265
+ * Base class for all resources
1266
+ */
1267
+
1268
+ declare abstract class BaseResource {
1269
+ protected client: HttpClient;
1270
+ constructor(httpClient: HttpClient);
1271
+ /**
1272
+ * Helper method for making GET requests
1273
+ */
1274
+ protected get<T>(path: string, params?: Record<string, string>, options?: RequestOptions): Promise<T>;
1275
+ /**
1276
+ * Helper method for making POST requests
1277
+ */
1278
+ protected post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
1279
+ /**
1280
+ * Helper method for making PUT requests
1281
+ */
1282
+ protected put<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
1283
+ /**
1284
+ * Helper method for making DELETE requests
1285
+ */
1286
+ protected delete<T>(path: string, options?: RequestOptions): Promise<T>;
1287
+ /**
1288
+ * Helper method for making PATCH requests
1289
+ */
1290
+ protected patch<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
1291
+ /**
1292
+ * Build a path with parameters
1293
+ * Example: buildPath('/sessions/:id', { id: '123' }) => '/sessions/123'
1294
+ */
1295
+ protected buildPath(template: string, params: Record<string, string>): string;
1296
+ }
1297
+
1298
+ /**
1299
+ * SessionsResource class for managing sessions-related api calls
1300
+ */
1301
+ declare class Session extends BaseResource {
1302
+ /**
1303
+ * create a new session
1304
+ * POST /med-assist/session
1305
+ */
1306
+ private basePath;
1307
+ create(sessionRequest: SessionCreateRequest, authToken?: string): Promise<SessionResponse>;
1308
+ retrieve(sessionId: string): Promise<SessionResponse>;
1309
+ /**
1310
+ * refresh a session
1311
+ * POST /med-assist/session/refresh
1312
+ */
1313
+ refresh(sessionId: string, sessionToken: string): Promise<SessionResponse>;
1314
+ feedback(sessionId: string, messageId: string, feedback: USER_FEEDBACK, feedback_reason?: string): Promise<void>;
1315
+ callTool(sessionId: string, toolId: string, messageId: string, sessionToken: string, toolParams?: Record<string, unknown>): Promise<ToolCallResponse>;
1316
+ }
1317
+
1318
+ declare class ToolCall extends BaseResource {
1319
+ private basePath;
1320
+ callTool(sessionId: string, toolName: string, toolParams?: Record<string, unknown>): Promise<ToolCallResponse>;
1321
+ }
1322
+
1323
+ declare class MessageManager {
1324
+ private connection;
1325
+ private callbacks;
1326
+ private fileManager;
1327
+ private audioManager;
1328
+ private outgoingBuffer;
1329
+ constructor(callbacks?: SynapseSDKCallbacks);
1330
+ setConnection(connection: BaseConnection): void;
1331
+ /**
1332
+ * Handle file upload process
1333
+ */
1334
+ private handleFileUploadProcess;
1335
+ /**
1336
+ * send chat message through socket
1337
+ */
1338
+ sendSocketMessage({ message, files, audio, urls, tool_declined, tool_id, tool_result, initial_prompts }: SocketChatRequestData): void;
1339
+ /**
1340
+ * Handle incoming chat message
1341
+ */
1342
+ handleIncomingSocketChatMessage(message: IncomingSocketChatMessage): void;
1343
+ /**
1344
+ * Handle incoming stream message
1345
+ */
1346
+ handleIncomingSocketStreamMessage(message: IncomingSocketStreamMessage): void;
1347
+ handleDisconnect(details: DisconnectionDetails): void;
1348
+ /**
1349
+ * Handle incoming end of stream message
1350
+ */
1351
+ handleIncomingSocketEndOfStreamMessage(_message: IncomingSocketEndOfStreamMessage): void;
1352
+ /**
1353
+ * Handle incoming error message
1354
+ */
1355
+ handleIncomingSocketErrorMessage(message: IncomingSocketErrorMessage): void;
1356
+ /**
1357
+ * send authentication message
1358
+ */
1359
+ sendSocketAuthMessage(sessionToken: string): void;
1360
+ /**
1361
+ * send ping message
1362
+ */
1363
+ sendSocketPingMessage(): void;
1364
+ /**
1365
+ * send audio message
1366
+ */
1367
+ startRecording({ onChunks, onError, }: {
1368
+ onChunks: (chunks: AudioMetaData) => void;
1369
+ onError?: (error: Error) => void;
1370
+ }): Promise<void>;
1371
+ /**
1372
+ * stop recording audio
1373
+ */
1374
+ endRecordingWithSocket(): void;
1375
+ /**
1376
+ * send pong message
1377
+ */
1378
+ sendSocketPongMessage(): void;
1379
+ handleConnectionEstablished(): void;
1380
+ private flushOutgoingBuffer;
1381
+ /**
1382
+ * Cleanup message service
1383
+ */
1384
+ cleanupMessageServerState(): void;
1385
+ private emitError;
1386
+ private toFileError;
1387
+ private toRecordingError;
1388
+ private assertConnection;
1389
+ }
1390
+
1391
+ declare class ErrorUtils {
1392
+ /**
1393
+ * Check if an error is a specific API error type
1394
+ */
1395
+ static isAPIError(error: unknown): error is APIError<number, Headers, Record<string, unknown>>;
1396
+ /**
1397
+ * Check if an error is a network-related error
1398
+ */
1399
+ static isNetworkError(error: unknown): boolean;
1400
+ /**
1401
+ * Check if an error is a timeout error
1402
+ */
1403
+ static isTimeoutError(error: unknown): boolean;
1404
+ /**
1405
+ * Check if an error is an authentication error
1406
+ */
1407
+ static isAuthError(error: unknown): boolean;
1408
+ /**
1409
+ * Check if an error is a client error (4xx)
1410
+ */
1411
+ static isClientError(error: unknown): boolean;
1412
+ /**
1413
+ * Check if an error is a server error (5xx)
1414
+ */
1415
+ static isServerError(error: unknown): boolean;
1416
+ /**
1417
+ * Get user-friendly error message
1418
+ */
1419
+ static getUserFriendlyMessage(error: unknown): string;
1420
+ /**
1421
+ * Extract error details for logging
1422
+ */
1423
+ static getErrorDetails(error: unknown): {
1424
+ type: string;
1425
+ message: string;
1426
+ code?: SynapseErrorCode | string;
1427
+ status?: number;
1428
+ timestamp?: Date;
1429
+ stack?: string;
1430
+ context?: Record<string, unknown>;
1431
+ hint?: string;
1432
+ };
1433
+ }
1434
+
1435
+ declare enum SYNAPSE_CONVERSATION {
1436
+ TEXT = "text",
1437
+ FILE = "file",
1438
+ AUDIO = "audio",
1439
+ VOICE = "voice"
1440
+ }
1441
+
1442
+ export { APIConnectionTimeoutError, APIError, APIUserAbortError, type AgentConfig, type AgentConfigResponse, type AudioConfig, type AudioDataCallback, type AudioErrorCallback, type AudioMetaData, type AuthSynapseToMatrixMessage, BadRequestError, BaseConnection, type BaseMessage, type ChatMatrixToSynapseMessage, type ChatSynapseToMatrixMessage, type ConnectionConfig, type ConnectionEstablishedMatrixToSynapseMessage, ConnectionFactory, ConnectionStatus, ConnectionType, type ContentType, type DisconnectionDetails, DisconnectionReason, type EndOfStreamMatrixToSynapseMessage, type EndOfStreamSynapseToMatrixMessage, type Environment, type ErrorMessage, ErrorType, ErrorUtils, type ExistingSessionOptions, HttpClient, type HttpClientConfig, type IncomingMessage, InternalServerError, MessageManager, MethodNotAllowedError, NotFoundError, type OnDisconnectCallback, type OnErrorCallback, type OnMessageCallback, type OnOpenCallback, type OnStatusChangeCallback, type OutgoingMessage, PermissionDeniedError, type PingMessage, type PongMessage, RateLimitError, type ResourceConfig, ResourceManager, type ResourceResponse, type SOCKET_STREAM_DATA, SSEConnection, type SSEConnectionConfig, SYNAPSE_COMPONENTS, SYNAPSE_CONVERSATION, SYNAPSE_EICITATION_STATUS, SYNAPSE_MESSAGE_TYPES, SYNAPSE_REALTIME_ERROR_CODES, SYNAPSE_REALTIME_EVENTS, SYNAPSE_REALTIME_RESERVED_EVENTS, SYNAPSE_TOOL_CALLBACK_NAME, SYNAPSE_TOOL_NAME, type SYNAPSE_TOOL_TYPES, type SendMessageOptions, Session, type SessionConfig, type SessionCreateRequest, type SessionResponse, type SocketChatRequestData, type StreamMatrixToSynapseMessage, type StreamSynapseToMatrixMessage, type SynapseContentTypes, SynapseError, SynapseErrorCode, type SynapseInputCompMap, type SynapseRealTimeEventData, SynapseSDK, type SynapseSDKCallbacks, type SynapseSDKConfig, type SynapseSDKOverrides, type SynapseSelectedCompMap, type SyncMessage, type TAvailability, type TAvailabilityDatesToolResponse, type TAvailabilitySlotsToolResponse, type TCardCta, type TCardInput, type TCardItem, type TCardTheme, type TContext, type TDoctorAvailability, type TDoctorCardInput, type TDoctorDetails, type TDoctorDetailsMap, type TDoctorToolResponse, type TGetLocationToolResponse, type THospital, type TInitalPrompt, type TInitialMessage, type TMediaCard, type TOption, type TProfile, type TSynapseError, ToolCall, type ToolCallData, type ToolCallResponse, type ToolCallbacks, type ToolDetails, type ToolInputTypes, USER_FEEDBACK, UnauthorizedError, VOICE_AGENT_EVENTS, VOICE_AGENT_STATE, type VoiceAgentConfig, type VoiceError, type VoiceSessionCredentials, WebSocketConnection, type presignedUrls };