@eka-care/medassist-core 1.0.31 → 1.0.32
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.
- package/README.md +92 -7
- package/dist/Synapse.d.ts +1 -0
- package/dist/Synapse.d.ts.map +1 -1
- package/dist/Synapse.js +29 -31
- package/dist/connection/Websocket.d.ts.map +1 -1
- package/dist/connection/Websocket.js +25 -17
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/index.js +13 -15
- package/dist/resources/session/Session.js +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @eka-care/medassist-core
|
|
2
2
|
|
|
3
|
-
TypeScript SDK for real-time medical chatbot experiences
|
|
3
|
+
TypeScript SDK for real-time medical chatbot experiences: session management, WebSocket connectivity, messaging, and media handling.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,10 +8,10 @@ TypeScript SDK for real-time medical chatbot experiences with session management
|
|
|
8
8
|
npm install @eka-care/medassist-core
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
## Quick
|
|
11
|
+
## Quick start
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
import { SynapseSDK } from "@eka-care/medassist-core";
|
|
14
|
+
import { SynapseSDK, SYNAPSE_REALTIME_EVENTS } from "@eka-care/medassist-core";
|
|
15
15
|
|
|
16
16
|
const sdk = new SynapseSDK({
|
|
17
17
|
agentId: "agent-123",
|
|
@@ -19,14 +19,99 @@ const sdk = new SynapseSDK({
|
|
|
19
19
|
userId: "user-456",
|
|
20
20
|
callbacks: {
|
|
21
21
|
onSessionRefreshed: (session) => console.log("session refreshed", session),
|
|
22
|
-
onConnectionStatusChange: (status) => console.log("status", status),
|
|
23
|
-
onRecordingStatusChange: (status) => console.log("recording", status),
|
|
24
22
|
onError: (error) => console.error("synapse error", error),
|
|
25
23
|
},
|
|
26
24
|
});
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
// Optional: pass existing session to resume
|
|
27
|
+
const existing = {
|
|
28
|
+
session_id: localStorage.getItem("synapse-session-id") ?? undefined,
|
|
29
|
+
session_token: localStorage.getItem("synapse-session-token") ?? undefined,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const session = await sdk.startSession(
|
|
33
|
+
existing?.session_id && existing?.session_token ? existing : undefined
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (session.session_token) {
|
|
37
|
+
localStorage.setItem("synapse-session-id", session.session_id);
|
|
38
|
+
localStorage.setItem("synapse-session-token", session.session_token);
|
|
39
|
+
}
|
|
40
|
+
|
|
29
41
|
sdk.sendMessage({ message: "Hello, doctor!" });
|
|
42
|
+
|
|
43
|
+
sdk.on(SYNAPSE_REALTIME_EVENTS.MESSAGE_CHUNK, (data) => console.log("chunk", data));
|
|
44
|
+
sdk.on(SYNAPSE_REALTIME_EVENTS.END_OF_STREAM, () => console.log("stream done"));
|
|
45
|
+
sdk.off(SYNAPSE_REALTIME_EVENTS.MESSAGE_CHUNK, handler);
|
|
46
|
+
|
|
47
|
+
sdk.endSession();
|
|
30
48
|
```
|
|
31
49
|
|
|
32
|
-
|
|
50
|
+
## Configuration
|
|
51
|
+
|
|
52
|
+
- **`agentId`** (required) – Platform agent identifier.
|
|
53
|
+
- **`environment`** – `"development"` or `"production"`; defaults to `"production"`.
|
|
54
|
+
- **`userId`** – Optional user identifier for analytics.
|
|
55
|
+
- **`overrides`** – Optional prompt, first message, or language overrides.
|
|
56
|
+
- **`callbacks`**
|
|
57
|
+
- **`onSessionRefreshed(session)`** – Persist new credentials when the backend refreshes them.
|
|
58
|
+
- **`onError(error)`** – Centralized error handling for UI or logging.
|
|
59
|
+
|
|
60
|
+
## Session lifecycle
|
|
61
|
+
|
|
62
|
+
1. **`startSession(existingSession?)`** – Creates or resumes a session; validates and refreshes when needed.
|
|
63
|
+
2. A WebSocket connection is established and authenticated with the session token.
|
|
64
|
+
3. Incoming server events are emitted via `SYNAPSE_REALTIME_EVENTS`.
|
|
65
|
+
4. **`endSession()`** – Closes the connection and clears in-memory state.
|
|
66
|
+
|
|
67
|
+
## Messaging API
|
|
68
|
+
|
|
69
|
+
- **`sendMessage(options)`** – Send text, files, or audio. Options: `message?`, `files?`, `audio?`, `tool_declined?`, `tool_id?`, `initial_prompts?`, `messageId?`, `hidden?`.
|
|
70
|
+
- **`sendFeedback(messageId, feedback, reason?)`** – Send feedback for a message.
|
|
71
|
+
- **`callTool(name, params?)`** – Invoke a tool by name with optional params.
|
|
72
|
+
- **`getSessionConfig()`** – Returns current session (e.g. `session_id`, `session_token`). Throws if session is not set.
|
|
73
|
+
- **`on(event, listener)`** / **`off(event, listener)`** – Subscribe to or remove realtime events.
|
|
74
|
+
- **`endSession()`** – Close the connection and cleanup.
|
|
75
|
+
|
|
76
|
+
## Audio
|
|
77
|
+
|
|
78
|
+
- **`startRecording({ onChunks, onError })`** – Start recording; `onChunks` receives audio metadata.
|
|
79
|
+
- **`endRecording()`** – Stop recording and send data over the socket.
|
|
80
|
+
|
|
81
|
+
## Realtime events
|
|
82
|
+
|
|
83
|
+
Use `SYNAPSE_REALTIME_EVENTS` for event names:
|
|
84
|
+
|
|
85
|
+
- `CONNECTED`
|
|
86
|
+
- `MESSAGE_CHUNK`
|
|
87
|
+
- `PROGRESS_MESSAGE`
|
|
88
|
+
- `TOOL_ESCALATION`
|
|
89
|
+
- `TIPS_MESSAGE`
|
|
90
|
+
- `INLINE_TEXT`
|
|
91
|
+
- `END_OF_STREAM`
|
|
92
|
+
- `ERROR`
|
|
93
|
+
|
|
94
|
+
Reserved events (e.g. `SYNAPSE_REALTIME_RESERVED_EVENTS.SESSION_EXPIRED`) are used for internal refresh handling.
|
|
95
|
+
|
|
96
|
+
## Project structure
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
packages/core/
|
|
100
|
+
├── src/
|
|
101
|
+
│ ├── Synapse.ts # High-level SDK
|
|
102
|
+
│ ├── index.ts # Public exports
|
|
103
|
+
│ ├── connection/ # WebSocket transport
|
|
104
|
+
│ ├── events/ # Realtime event types
|
|
105
|
+
│ ├── internal/ # HTTP client, errors, base connection
|
|
106
|
+
│ ├── media/ # File and audio helpers
|
|
107
|
+
│ ├── messages/ # MessageManager and types
|
|
108
|
+
│ ├── resources/ # Session and agent config
|
|
109
|
+
│ └── types/ # Shared types
|
|
110
|
+
└── README.md
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
For architecture details and advanced usage (e.g. `ConnectionFactory`, `MessageManager`), see the [main repository README](../../README.md).
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
MIT
|
package/dist/Synapse.d.ts
CHANGED
package/dist/Synapse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Synapse.d.ts","sourceRoot":"","sources":["../src/Synapse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,OAAO,EACL,uBAAuB,EAExB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"Synapse.d.ts","sourceRoot":"","sources":["../src/Synapse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,OAAO,EACL,uBAAuB,EAExB,MAAM,kBAAkB,CAAC;AAqB1B,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,kBAAkB,EAAiB,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAI/I,qBAAa,UAAU;IACrB,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,cAAc,CAAkB;IACxC,OAAO,CAAC,eAAe,CAAkB;IAEzC,OAAO,CAAC,aAAa,CAA8B;IAC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;IACI,YAAY,IAAI,IAAI;IA+Bd,cAAc,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAIpD,WAAW,IAAI,OAAO;IAG7B;;OAEG;IACI,UAAU,IAAI,IAAI;IAQzB,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,cAAc;IAYtB;;;OAGG;YACW,oBAAoB;IAwClC;;;OAGG;YACW,aAAa;IAwC3B;;OAEG;YACW,cAAc;IAuB5B;;OAEG;YACW,gBAAgB;IAO9B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAwC1B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAW/B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAe9B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAgD/B;;OAEG;YACW,mBAAmB;IA6CjC,OAAO,CAAC,iBAAiB;CAW1B"}
|
package/dist/Synapse.js
CHANGED
|
@@ -23,6 +23,7 @@ class SynapseSDK {
|
|
|
23
23
|
sessionConfig = null;
|
|
24
24
|
config;
|
|
25
25
|
connectionType;
|
|
26
|
+
isRefreshingSession = false;
|
|
26
27
|
constructor(config) {
|
|
27
28
|
this.config = {
|
|
28
29
|
...config,
|
|
@@ -53,6 +54,11 @@ class SynapseSDK {
|
|
|
53
54
|
catch (error) {
|
|
54
55
|
const userFriendlyMessage = Error_1.ErrorUtils.getUserFriendlyMessage(error);
|
|
55
56
|
const errorDetails = Error_1.ErrorUtils.getErrorDetails(error);
|
|
57
|
+
if (error instanceof Error_2.APIError) {
|
|
58
|
+
if (error.status === 404) {
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
56
62
|
const sessionError = this.toSessionError(error, userFriendlyMessage || "Failed to start session", {
|
|
57
63
|
stage: "startSession",
|
|
58
64
|
details: errorDetails,
|
|
@@ -265,9 +271,7 @@ class SynapseSDK {
|
|
|
265
271
|
this.connection.close();
|
|
266
272
|
this.connection = null;
|
|
267
273
|
}
|
|
268
|
-
|
|
269
|
-
this.messageManager.cleanupMessageServerState();
|
|
270
|
-
}
|
|
274
|
+
this.messageManager?.cleanupMessageServerState?.();
|
|
271
275
|
}
|
|
272
276
|
emitError(error) {
|
|
273
277
|
this.config.callbacks?.onError?.(error);
|
|
@@ -331,30 +335,17 @@ class SynapseSDK {
|
|
|
331
335
|
if (result.expired) {
|
|
332
336
|
return this.refreshSession(existingSession.session_id, existingSession.session_token);
|
|
333
337
|
}
|
|
334
|
-
|
|
338
|
+
throw new Error_2.APIError("Failed to create session", 500, undefined, undefined);
|
|
335
339
|
}
|
|
336
340
|
catch (error) {
|
|
337
|
-
|
|
338
|
-
// ConnectionStatus.NOT_CONNECTED
|
|
339
|
-
// );
|
|
341
|
+
console.log("error", error, error instanceof Error_2.APIError);
|
|
340
342
|
if (error instanceof Error_2.APIError) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
return this.createNewSession();
|
|
343
|
+
if (error.status === 404) {
|
|
344
|
+
throw error;
|
|
344
345
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
// context: {
|
|
349
|
-
// stage: "manageSession",
|
|
350
|
-
// },
|
|
351
|
-
// hint: "Please try again later",
|
|
352
|
-
// cause: error,
|
|
353
|
-
// displayMessage: "Failed to authenticate user",
|
|
354
|
-
// });
|
|
355
|
-
// this.emitError(authError);
|
|
356
|
-
// throw authError;
|
|
357
|
-
// }
|
|
346
|
+
}
|
|
347
|
+
else if (error instanceof Error_2.NotFoundError && error.status === 404) {
|
|
348
|
+
throw error;
|
|
358
349
|
}
|
|
359
350
|
throw this.toSessionError(error, "Failed to resolve session", {
|
|
360
351
|
stage: "resolveSession",
|
|
@@ -372,10 +363,9 @@ class SynapseSDK {
|
|
|
372
363
|
if (error instanceof Error_2.APIError) {
|
|
373
364
|
// Emit API error via onError callback before handling
|
|
374
365
|
this.emitError(error);
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
366
|
+
// if (status === 404 || status === 500) {
|
|
367
|
+
// return this.createNewSession();
|
|
368
|
+
// }
|
|
379
369
|
}
|
|
380
370
|
throw this.toSessionError(error, "Failed to refresh session", {
|
|
381
371
|
stage: "refreshSession",
|
|
@@ -493,6 +483,10 @@ class SynapseSDK {
|
|
|
493
483
|
* Handle session expired
|
|
494
484
|
*/
|
|
495
485
|
async handleSessionExpiry() {
|
|
486
|
+
if (this.isRefreshingSession) {
|
|
487
|
+
console.warn("Session is already being refreshed");
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
496
490
|
try {
|
|
497
491
|
this.endSession();
|
|
498
492
|
if (!this.sessionConfig?.session_id ||
|
|
@@ -503,16 +497,17 @@ class SynapseSDK {
|
|
|
503
497
|
this.emitError(error);
|
|
504
498
|
throw error;
|
|
505
499
|
}
|
|
500
|
+
this.isRefreshingSession = true;
|
|
506
501
|
const refreshed = await this.refreshSession(this.sessionConfig.session_id, this.sessionConfig.session_token);
|
|
507
502
|
if (!refreshed.session_id || !refreshed.session_token) {
|
|
508
503
|
throw new Error_2.SessionError("Session refresh failed", {
|
|
509
504
|
context: { stage: "handleSessionExpiry" },
|
|
510
505
|
});
|
|
511
506
|
}
|
|
512
|
-
this.sessionConfig.session_id = refreshed.session_id;
|
|
513
|
-
this.sessionConfig.session_token = refreshed.session_token;
|
|
514
|
-
await this.initializeConnection(refreshed);
|
|
515
|
-
this.setupEventHandlers();
|
|
507
|
+
// this.sessionConfig.session_id = refreshed.session_id;
|
|
508
|
+
// this.sessionConfig.session_token = refreshed.session_token;
|
|
509
|
+
// await this.initializeConnection(refreshed);
|
|
510
|
+
// this.setupEventHandlers();
|
|
516
511
|
this.config.callbacks?.onSessionRefreshed?.(refreshed);
|
|
517
512
|
}
|
|
518
513
|
catch (error) {
|
|
@@ -524,6 +519,9 @@ class SynapseSDK {
|
|
|
524
519
|
});
|
|
525
520
|
this.emitError(sessionError);
|
|
526
521
|
}
|
|
522
|
+
finally {
|
|
523
|
+
this.isRefreshingSession = false;
|
|
524
|
+
}
|
|
527
525
|
}
|
|
528
526
|
toConnectionError(error, fallbackMessage, context, hint) {
|
|
529
527
|
return (0, Error_2.normalizeError)(error, Error_2.ConnectionError, fallbackMessage, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Websocket.d.ts","sourceRoot":"","sources":["../../src/connection/Websocket.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAO9D,MAAM,WAAW,yBAA0B,SAAQ,aAAa;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE;QACJ,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,mBAAoB,SAAQ,cAAc;IACrD,SAAgB,cAAc,EAAE,MAAM,CAAC;IACvC,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,cAAc,CAAa;IACnC,OAAO,CAAC,aAAa,CAAkB;gBAE3B,MAAM,EAAE,yBAAyB;IAY7C;;OAEG;IACH,OAAO,CAAC,OAAO;
|
|
1
|
+
{"version":3,"file":"Websocket.d.ts","sourceRoot":"","sources":["../../src/connection/Websocket.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAO9D,MAAM,WAAW,yBAA0B,SAAQ,aAAa;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE;QACJ,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,mBAAoB,SAAQ,cAAc;IACrD,SAAgB,cAAc,EAAE,MAAM,CAAC;IACvC,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,cAAc,CAAa;IACnC,OAAO,CAAC,aAAa,CAAkB;gBAE3B,MAAM,EAAE,yBAAyB;IAY7C;;OAEG;IACH,OAAO,CAAC,OAAO;IA+Bf;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAQ1B;;OAEG;IACH,OAAO,CAAC,UAAU;IAKlB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAgB3B;;OAEG;IACH,OAAO,CAAC,WAAW;IAcnB;;OAEG;IACH,OAAO,CAAC,WAAW;IAyDnB;;OAEG;IACI,WAAW,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI;IAyBxD;;OAEG;IACI,KAAK,IAAI,IAAI;IASpB;;OAEG;IACI,WAAW,IAAI,OAAO;IAItB,eAAe,IAAI,IAAI;CAK/B"}
|
|
@@ -43,9 +43,11 @@ class WebSocketConnection extends BaseConnection_1.BaseConnection {
|
|
|
43
43
|
this.socket.onclose = this.handleClose.bind(this);
|
|
44
44
|
}
|
|
45
45
|
catch (error) {
|
|
46
|
+
console.log("error from connect", error);
|
|
46
47
|
const connectionError = (0, Error_1.normalizeError)(error, Error_1.ConnectionError, "Failed to establish WebSocket connection", { context: { stage: "connect" } });
|
|
47
48
|
this.onErrorCallback?.(connectionError);
|
|
48
49
|
this.disconnect({
|
|
50
|
+
code: 1001,
|
|
49
51
|
reason: types_1.DisconnectionReason.CONNECTION_ERROR,
|
|
50
52
|
message: connectionError.message,
|
|
51
53
|
timestamp: new Date(),
|
|
@@ -67,15 +69,6 @@ class WebSocketConnection extends BaseConnection_1.BaseConnection {
|
|
|
67
69
|
if (this.authenticated || this.socket?.readyState !== WebSocket.OPEN)
|
|
68
70
|
return;
|
|
69
71
|
this.onOpenCallback?.();
|
|
70
|
-
//register message handlers
|
|
71
|
-
// this.sendAuthMessage();
|
|
72
|
-
// Send initial configuration if overrides are provided
|
|
73
|
-
// if (this.config.overrides) {
|
|
74
|
-
// this.sendMessage({
|
|
75
|
-
// type: "config",
|
|
76
|
-
// content: this.config.overrides,
|
|
77
|
-
// });
|
|
78
|
-
// }
|
|
79
72
|
}
|
|
80
73
|
/**
|
|
81
74
|
* Handle incoming WebSocket messages
|
|
@@ -94,6 +87,12 @@ class WebSocketConnection extends BaseConnection_1.BaseConnection {
|
|
|
94
87
|
* Handle WebSocket errors
|
|
95
88
|
*/
|
|
96
89
|
handleError(event) {
|
|
90
|
+
console.log("handleError", event);
|
|
91
|
+
if (this.reconnectCount < (this.config.reconnectAttempts || 3)) {
|
|
92
|
+
this.reconnectCount++;
|
|
93
|
+
this.connect();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
97
96
|
const connectionError = new Error_1.ConnectionError("WebSocket error", {
|
|
98
97
|
context: { stage: "handleError" },
|
|
99
98
|
cause: event,
|
|
@@ -109,17 +108,29 @@ class WebSocketConnection extends BaseConnection_1.BaseConnection {
|
|
|
109
108
|
const reason = event.reason;
|
|
110
109
|
let disconnectReason;
|
|
111
110
|
let message;
|
|
111
|
+
this.authenticated = false;
|
|
112
|
+
console.log("handleClose", event);
|
|
113
|
+
if (this.isConnected()) {
|
|
114
|
+
console.log("WebSocket is already connected, skipping reconnection");
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
112
117
|
if (code === 1000) {
|
|
113
118
|
disconnectReason = types_1.DisconnectionReason.CLIENT_CLOSED;
|
|
114
119
|
message = "Connection closed normally";
|
|
115
120
|
}
|
|
116
121
|
else if (code === 1001 || code === 1006) {
|
|
117
122
|
disconnectReason = types_1.DisconnectionReason.NETWORK_ERROR;
|
|
118
|
-
message = "Network connection lost";
|
|
123
|
+
message = event.reason || "Network connection lost";
|
|
119
124
|
}
|
|
120
125
|
else if (code === 4001 || code === 1008) {
|
|
121
|
-
|
|
122
|
-
|
|
126
|
+
if (event.reason === "timeout" || event.reason === "Authentication timeout") {
|
|
127
|
+
disconnectReason = types_1.DisconnectionReason.TIMEOUT;
|
|
128
|
+
message = "Connection timed out";
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
disconnectReason = types_1.DisconnectionReason.AUTHENTICATION_ERROR;
|
|
132
|
+
message = event.reason || "Authentication failed";
|
|
133
|
+
}
|
|
123
134
|
}
|
|
124
135
|
else if (wasClean) {
|
|
125
136
|
disconnectReason = types_1.DisconnectionReason.SERVER_CLOSED;
|
|
@@ -134,15 +145,12 @@ class WebSocketConnection extends BaseConnection_1.BaseConnection {
|
|
|
134
145
|
disconnectReason !== types_1.DisconnectionReason.AUTHENTICATION_ERROR &&
|
|
135
146
|
disconnectReason !== types_1.DisconnectionReason.CLIENT_CLOSED &&
|
|
136
147
|
this.reconnectCount < (this.config.reconnectAttempts || 3)) {
|
|
148
|
+
console.log("Reconnecting..", this.reconnectCount, disconnectReason, message);
|
|
149
|
+
console.log("disconnectevent", event);
|
|
137
150
|
this.reconnectCount++;
|
|
138
|
-
// setTimeout(() => {
|
|
139
|
-
// console.log("Reconnecting... after delay");
|
|
140
|
-
// this.connect();
|
|
141
|
-
// }, this.config.reconnectDelay || 1000);
|
|
142
151
|
this.connect();
|
|
143
152
|
}
|
|
144
153
|
else {
|
|
145
|
-
this.authenticated = false;
|
|
146
154
|
this.disconnect({
|
|
147
155
|
reason: disconnectReason,
|
|
148
156
|
message,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AAAA;;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E,MAAM,GAChB,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC;IA+CjD;;;OAGG;IACU,cAAc,CACzB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,eAAe,CAAC;IAI3B;;;OAGG;IACU,YAAY,CACvB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,aAAa,EACvB,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC;IAShB;;;OAGG;IACU,QAAQ,CAAC,CAAC,SAAS,gBAAgB,GAAG,gBAAgB,EACjE,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACnC,OAAO,CAAC,CAAC,CAAC;CAMd"}
|
package/dist/resources/index.js
CHANGED
|
@@ -22,6 +22,7 @@ class ResourceManager {
|
|
|
22
22
|
baseUrl: this.resourceConfig.serverUrl,
|
|
23
23
|
headers: {
|
|
24
24
|
"X-agent-id": this.resourceConfig.agentId, // This will be included in ALL requests
|
|
25
|
+
"ngrok-skip-browser-warning": "69420",
|
|
25
26
|
...(this.resourceConfig.authorization && { Authorization: this.resourceConfig.authorization }),
|
|
26
27
|
},
|
|
27
28
|
// authorization: config.authorization,
|
|
@@ -95,16 +96,16 @@ class ResourceManager {
|
|
|
95
96
|
catch (error) {
|
|
96
97
|
if (error instanceof Error_1.APIError) {
|
|
97
98
|
switch (error.status) {
|
|
98
|
-
case 404:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
case 500:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
99
|
+
// case 404:
|
|
100
|
+
// return {
|
|
101
|
+
// expired: false,
|
|
102
|
+
// active: false,
|
|
103
|
+
// };
|
|
104
|
+
// case 500:
|
|
105
|
+
// return {
|
|
106
|
+
// expired: false,
|
|
107
|
+
// active: false,
|
|
108
|
+
// };
|
|
108
109
|
case 401:
|
|
109
110
|
// if (!!error.error?.msg) {
|
|
110
111
|
// return {
|
|
@@ -118,13 +119,10 @@ class ResourceManager {
|
|
|
118
119
|
active: false,
|
|
119
120
|
};
|
|
120
121
|
default:
|
|
121
|
-
|
|
122
|
-
expired: false,
|
|
123
|
-
active: false,
|
|
124
|
-
};
|
|
122
|
+
throw error;
|
|
125
123
|
}
|
|
126
124
|
}
|
|
127
|
-
throw
|
|
125
|
+
throw error;
|
|
128
126
|
}
|
|
129
127
|
}
|
|
130
128
|
/**
|
|
@@ -30,7 +30,7 @@ class Session extends BaseResource_1.BaseResource {
|
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
async feedback(sessionId, messageId, feedback, feedback_reason) {
|
|
33
|
-
return this.put(`${this.basePath}/${sessionId}/
|
|
33
|
+
return this.put(`${this.basePath}/${sessionId}/message/${messageId}/feedback`, {
|
|
34
34
|
feedback,
|
|
35
35
|
feedback_reason,
|
|
36
36
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEtE,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAA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CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AACD,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eka-care/medassist-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.32",
|
|
4
4
|
"description": "TypeScript SDK for real-time medical chatbot experiences with session management, WebSocket connectivity, and media handling",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|