@eka-care/medassist-widget-embed 0.2.1 → 0.2.3
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/dist/iframe.html +4 -0
- package/dist/iframe.js +49 -34
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -2
- package/dist/src/medassist-widget.js +155 -29
- package/dist/src/medassist-widget.js.map +1 -1
- package/iframe.html +4 -0
- package/iframe.ts +48 -41
- package/index.ts +42 -2
- package/package.json +1 -1
- package/src/medassist-widget.js +155 -29
- package/src/medassist-widget.js.map +1 -1
package/dist/iframe.html
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>MedAssist Widget</title>
|
|
7
|
+
|
|
8
|
+
<!-- Resouce hints for faster loading -->
|
|
9
|
+
<link rel="preconnect" href="https://unpkg.com" crossorigin/>
|
|
10
|
+
<link rel="dns-prefetch" href="https://unpkg.com"/>
|
|
7
11
|
<style>
|
|
8
12
|
* {
|
|
9
13
|
margin: 0;
|
package/dist/iframe.js
CHANGED
|
@@ -70,47 +70,57 @@
|
|
|
70
70
|
const baseUrl = urlParams.get("baseUrl") || undefined;
|
|
71
71
|
const environment = (_a = getEnvironment(urlParams.get("environment"))) !== null && _a !== void 0 ? _a : "production";
|
|
72
72
|
const container = document.getElementById("root") || document.body;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
window.parent
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
73
|
+
try {
|
|
74
|
+
await Promise.all([
|
|
75
|
+
loadWidgetCss(),
|
|
76
|
+
loadWidgetScript(),
|
|
77
|
+
]);
|
|
78
|
+
if (!(window === null || window === void 0 ? void 0 : window.renderMedAssist) || typeof (window === null || window === void 0 ? void 0 : window.renderMedAssist) !== "function") {
|
|
79
|
+
throw new Error("renderMedAssist is not available on window");
|
|
80
|
+
}
|
|
81
|
+
const config = {
|
|
82
|
+
title,
|
|
83
|
+
iconUrl,
|
|
84
|
+
environment,
|
|
85
|
+
onClose: () => {
|
|
86
|
+
// Send message to parent window to close iframe
|
|
87
|
+
if (window.parent !== window) {
|
|
88
|
+
window.parent.postMessage({ type: "WIDGET_CLOSE" }, "*");
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
context: context ? JSON.parse(context) : undefined,
|
|
92
|
+
baseUrl,
|
|
93
|
+
displayMode: "full", //for iframe default display mode is full
|
|
94
|
+
};
|
|
95
|
+
window.renderMedAssist(container, agentId, config);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error("Failed to initialize MedAssist widget", error);
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
95
101
|
};
|
|
96
102
|
async function loadWidgetCss() {
|
|
97
103
|
// Check if already loaded
|
|
98
|
-
|
|
104
|
+
const existingLink = document.querySelector(`link[data-medassist-style='true']`);
|
|
105
|
+
if (existingLink) {
|
|
99
106
|
return;
|
|
100
107
|
}
|
|
101
108
|
if (!widgetCssTextPromise) {
|
|
102
|
-
widgetCssTextPromise =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
109
|
+
widgetCssTextPromise = new Promise((resolve, reject) => {
|
|
110
|
+
const link = document.createElement("link");
|
|
111
|
+
link.rel = "stylesheet";
|
|
112
|
+
link.href = WIDGET_CSS_URL;
|
|
113
|
+
link.setAttribute("data-medassist-style", "true");
|
|
114
|
+
link.onload = () => {
|
|
115
|
+
resolve("");
|
|
116
|
+
};
|
|
117
|
+
link.onerror = () => {
|
|
118
|
+
reject(new Error(`Failed to load ${WIDGET_CSS_URL}`));
|
|
119
|
+
};
|
|
120
|
+
document.head.appendChild(link);
|
|
107
121
|
});
|
|
108
122
|
}
|
|
109
|
-
|
|
110
|
-
const styleTag = document.createElement("style");
|
|
111
|
-
styleTag.setAttribute("data-medassist-style", "true");
|
|
112
|
-
styleTag.textContent = cssText;
|
|
113
|
-
document.head.appendChild(styleTag);
|
|
123
|
+
await widgetCssTextPromise;
|
|
114
124
|
}
|
|
115
125
|
function loadWidgetScript() {
|
|
116
126
|
if (!widgetScriptPromise) {
|
|
@@ -151,7 +161,12 @@
|
|
|
151
161
|
document.addEventListener("DOMContentLoaded", initializeFromUrlParams);
|
|
152
162
|
}
|
|
153
163
|
else {
|
|
154
|
-
|
|
164
|
+
try {
|
|
165
|
+
initializeFromUrlParams();
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
console.error("Failed to initialize MedAssist widget", error);
|
|
169
|
+
}
|
|
155
170
|
}
|
|
156
171
|
}
|
|
157
172
|
})();
|
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,8 @@ declare class MedAssistWidgetLoader extends HTMLElement {
|
|
|
35
35
|
static get observedAttributes(): string[];
|
|
36
36
|
connectedCallback(): void;
|
|
37
37
|
attributeChangedCallback(name: string): void;
|
|
38
|
+
private preloadResources;
|
|
39
|
+
private setupAuthExpirationListener;
|
|
38
40
|
openFromBridge(): void;
|
|
39
41
|
renderButton(): void;
|
|
40
42
|
initializeFullMode(): void;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,gBAAgB,QAAO,iBAAiB,GAAG,IAahD,CAAC;AAEF,KAAK,iBAAiB,GAAG,YAAY,GAAG,aAAa,GAAG,SAAS,CAAC;AAElE,QAAA,MAAM,cAAc,GAClB,OAAO,MAAM,GAAG,IAAI,KACnB,iBAAi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E,OAAO,CAAC,MAAM,CAAC,GAAG,IAAW,CAAC;AAExD,cAAM,qBAAsB,SAAQ,WAAW;IAC7C,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,WAAW,CAAoB;;IAcvC,MAAM,KAAK,kBAAkB,IAAI,MAAM,EAAE,CAExC;IAED,iBAAiB,IAAI,IAAI;IAQzB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAoB5C,OAAO,CAAC,gBAAgB;IAqBxB,OAAO,CAAC,2BAA2B;IAe5B,cAAc,IAAI,IAAI;IAe7B,YAAY,IAAI,IAAI;IAiEpB,kBAAkB,IAAI,IAAI;IA6BpB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IA0F9B,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IA4BpC,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;CA0ClC"}
|
package/dist/index.js
CHANGED
|
@@ -105,6 +105,9 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
105
105
|
this.defaultIconUrl = "https://cdn.eka.care/bot-icon.svg";
|
|
106
106
|
this.widgetLoaded = false;
|
|
107
107
|
this.displayMode = this.getAttribute("display-mode") === "full" ? "full" : "widget";
|
|
108
|
+
this.preloadResources();
|
|
109
|
+
// Listen for AUTH_EXPIRED events from the widget and forward to parent
|
|
110
|
+
this.setupAuthExpirationListener();
|
|
108
111
|
}
|
|
109
112
|
static get observedAttributes() {
|
|
110
113
|
return ["icon-url", "display-mode"];
|
|
@@ -136,6 +139,40 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
136
139
|
}
|
|
137
140
|
}
|
|
138
141
|
}
|
|
142
|
+
// Preload resources in the background
|
|
143
|
+
preloadResources() {
|
|
144
|
+
// Preload CSS (browser will cache it)
|
|
145
|
+
if (!document.querySelector(`link[href="${WIDGET_CSS_URL}"]`)) {
|
|
146
|
+
const cssLink = document.createElement("link");
|
|
147
|
+
cssLink.rel = "preload";
|
|
148
|
+
cssLink.href = WIDGET_CSS_URL;
|
|
149
|
+
cssLink.as = "style";
|
|
150
|
+
document.head.appendChild(cssLink);
|
|
151
|
+
}
|
|
152
|
+
// Preload JS (browser will cache it)
|
|
153
|
+
if (!document.querySelector(`link[href="${WIDGET_JS_URL}"]`)) {
|
|
154
|
+
const jsLink = document.createElement("link");
|
|
155
|
+
jsLink.rel = "preload";
|
|
156
|
+
jsLink.href = WIDGET_JS_URL;
|
|
157
|
+
jsLink.as = "script";
|
|
158
|
+
jsLink.crossOrigin = "anonymous";
|
|
159
|
+
document.head.appendChild(jsLink);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
setupAuthExpirationListener() {
|
|
163
|
+
if (typeof window === "undefined")
|
|
164
|
+
return;
|
|
165
|
+
const messageHandler = (event) => {
|
|
166
|
+
var _a;
|
|
167
|
+
if (((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === "AUTH_EXPIRED") {
|
|
168
|
+
if (window.parent !== window) {
|
|
169
|
+
window.parent.postMessage({ type: "AUTH_EXPIRED", message: "Authentication expired" }, "*");
|
|
170
|
+
}
|
|
171
|
+
// window.webkit.messageHandlers.authTokenExpired.postMessage({});
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
window.addEventListener("message", messageHandler);
|
|
175
|
+
}
|
|
139
176
|
openFromBridge() {
|
|
140
177
|
this.displayMode = this.getAttribute("display-mode") === "full" ? "full" : "widget";
|
|
141
178
|
if (this.displayMode === "full") {
|
|
@@ -144,8 +181,7 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
144
181
|
else {
|
|
145
182
|
this.renderButton();
|
|
146
183
|
}
|
|
147
|
-
this.loadWidgetCss()
|
|
148
|
-
.then(() => this.loadWidgetScript())
|
|
184
|
+
Promise.all([this.loadWidgetCss(), this.loadWidgetScript()])
|
|
149
185
|
.then(() => this.loadAndRender())
|
|
150
186
|
.catch((error) => {
|
|
151
187
|
console.error("Failed to open MedAssist widget from bridge", error);
|
|
@@ -26737,7 +26737,7 @@ var MedAssistWidget = (function(exports) {
|
|
|
26737
26737
|
hasRequired_Error$1 = 1;
|
|
26738
26738
|
(function(exports$1) {
|
|
26739
26739
|
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
26740
|
-
exports$1.ValidationError = exports$1.ConfigurationError = exports$1.StoreError = exports$1.MessageError = exports$1.SessionError = exports$1.FileError = exports$1.RecordingError = exports$1.ConnectionError = exports$1.InternalServerError = exports$1.RateLimitError = exports$1.MethodNotAllowedError = exports$1.NotFoundError = exports$1.PermissionDeniedError = exports$1.UnauthorizedError = exports$1.BadRequestError = exports$1.APIConnectionTimeoutError = exports$1.APIUserAbortError = exports$1.APIError = exports$1.SynapseError = exports$1.SynapseErrorCode = void 0;
|
|
26740
|
+
exports$1.ValidationError = exports$1.ConfigurationError = exports$1.StoreError = exports$1.MessageError = exports$1.SessionError = exports$1.FileError = exports$1.AuthenticationError = exports$1.RecordingError = exports$1.ConnectionError = exports$1.InternalServerError = exports$1.RateLimitError = exports$1.MethodNotAllowedError = exports$1.NotFoundError = exports$1.PermissionDeniedError = exports$1.UnauthorizedError = exports$1.BadRequestError = exports$1.APIConnectionTimeoutError = exports$1.APIUserAbortError = exports$1.APIError = exports$1.SynapseError = exports$1.SynapseErrorCode = void 0;
|
|
26741
26741
|
exports$1.normalizeError = normalizeError;
|
|
26742
26742
|
exports$1.SynapseErrorCode = {
|
|
26743
26743
|
API: "API_ERROR",
|
|
@@ -26915,6 +26915,13 @@ var MedAssistWidget = (function(exports) {
|
|
|
26915
26915
|
}
|
|
26916
26916
|
}
|
|
26917
26917
|
exports$1.RecordingError = RecordingError;
|
|
26918
|
+
class AuthenticationError extends SynapseError {
|
|
26919
|
+
constructor(message, options = {}) {
|
|
26920
|
+
super(message, exports$1.SynapseErrorCode.AUTH, options);
|
|
26921
|
+
this.name = "AuthenticationError";
|
|
26922
|
+
}
|
|
26923
|
+
}
|
|
26924
|
+
exports$1.AuthenticationError = AuthenticationError;
|
|
26918
26925
|
class FileError extends SynapseError {
|
|
26919
26926
|
constructor(message, options = {}) {
|
|
26920
26927
|
super(message, exports$1.SynapseErrorCode.FILE, options);
|
|
@@ -27464,11 +27471,11 @@ var MedAssistWidget = (function(exports) {
|
|
|
27464
27471
|
};
|
|
27465
27472
|
var SYNAPSE_TOOL_CALLBACK_NAME;
|
|
27466
27473
|
(function(SYNAPSE_TOOL_CALLBACK_NAME2) {
|
|
27467
|
-
SYNAPSE_TOOL_CALLBACK_NAME2["DOCTOR_AVAILABILITY"] = "
|
|
27468
|
-
SYNAPSE_TOOL_CALLBACK_NAME2["AVAILABILITY_DATES"] = "
|
|
27469
|
-
SYNAPSE_TOOL_CALLBACK_NAME2["AVAILABILITY_SLOTS"] = "
|
|
27470
|
-
SYNAPSE_TOOL_CALLBACK_NAME2["MOBILE_VERIFICATION"] = "
|
|
27471
|
-
SYNAPSE_TOOL_CALLBACK_NAME2["DOCTOR_DETAILS"] = "
|
|
27474
|
+
SYNAPSE_TOOL_CALLBACK_NAME2["DOCTOR_AVAILABILITY"] = "get_doctor_availability";
|
|
27475
|
+
SYNAPSE_TOOL_CALLBACK_NAME2["AVAILABILITY_DATES"] = "get_available_dates";
|
|
27476
|
+
SYNAPSE_TOOL_CALLBACK_NAME2["AVAILABILITY_SLOTS"] = "get_available_slots";
|
|
27477
|
+
SYNAPSE_TOOL_CALLBACK_NAME2["MOBILE_VERIFICATION"] = "verify_mobile_number";
|
|
27478
|
+
SYNAPSE_TOOL_CALLBACK_NAME2["DOCTOR_DETAILS"] = "get_doctor_details";
|
|
27472
27479
|
})(SYNAPSE_TOOL_CALLBACK_NAME || (types$7.SYNAPSE_TOOL_CALLBACK_NAME = SYNAPSE_TOOL_CALLBACK_NAME = {}));
|
|
27473
27480
|
return types$7;
|
|
27474
27481
|
}
|
|
@@ -27908,7 +27915,9 @@ var MedAssistWidget = (function(exports) {
|
|
|
27908
27915
|
FILE_UPLOAD_INPROGRESS: "file_upload_inprogress",
|
|
27909
27916
|
TIMEOUT: "timeout",
|
|
27910
27917
|
SERVER_ERROR: "server_error",
|
|
27911
|
-
SESSION_TOKEN_MISMATCH: "session_token_mismatch"
|
|
27918
|
+
SESSION_TOKEN_MISMATCH: "session_token_mismatch",
|
|
27919
|
+
PROMPT_FETCH_ERROR: "prompt_fetch_error",
|
|
27920
|
+
INVALID_FILE_REQUEST: "invalid_file_request"
|
|
27912
27921
|
};
|
|
27913
27922
|
types$6.SYNAPSE_REALTIME_RESERVED_EVENTS = {
|
|
27914
27923
|
SESSION_EXPIRED: "session_expired"
|
|
@@ -28473,19 +28482,25 @@ var MedAssistWidget = (function(exports) {
|
|
|
28473
28482
|
*/
|
|
28474
28483
|
handleIncomingSocketErrorMessage(message) {
|
|
28475
28484
|
const connection = this.assertConnection("handleIncomingSocketErrorMessage");
|
|
28476
|
-
switch (message
|
|
28485
|
+
switch (message?.data?.code) {
|
|
28477
28486
|
case types_1.SYNAPSE_REALTIME_ERROR_CODES.SESSION_EXPIRED:
|
|
28478
28487
|
connection.emit(types_1.SYNAPSE_REALTIME_RESERVED_EVENTS.SESSION_EXPIRED);
|
|
28479
28488
|
break;
|
|
28489
|
+
case types_1.SYNAPSE_REALTIME_ERROR_CODES.INVALID_EVENT:
|
|
28490
|
+
console.log("invalid event error", message);
|
|
28491
|
+
break;
|
|
28480
28492
|
default:
|
|
28481
|
-
const error = new Error_1.MessageError(message
|
|
28493
|
+
const error = new Error_1.MessageError(message?.data?.msg || "Socket error received", {
|
|
28482
28494
|
context: {
|
|
28483
28495
|
stage: "handleIncomingSocketErrorMessage",
|
|
28484
|
-
errorCode: message
|
|
28485
|
-
}
|
|
28496
|
+
errorCode: message?.data?.code
|
|
28497
|
+
},
|
|
28498
|
+
hint: message?.data?.msg,
|
|
28499
|
+
cause: message,
|
|
28500
|
+
displayMessage: message?.data?.msg
|
|
28486
28501
|
});
|
|
28487
|
-
|
|
28488
|
-
|
|
28502
|
+
console.log("error from socket", error);
|
|
28503
|
+
connection.emit(types_1.SYNAPSE_REALTIME_EVENTS.ERROR, message);
|
|
28489
28504
|
}
|
|
28490
28505
|
}
|
|
28491
28506
|
/**
|
|
@@ -30337,8 +30352,26 @@ var MedAssistWidget = (function(exports) {
|
|
|
30337
30352
|
if (error instanceof distExports.SynapseError) {
|
|
30338
30353
|
switch (error.code) {
|
|
30339
30354
|
case distExports.SynapseErrorCode.SESSION:
|
|
30340
|
-
|
|
30341
|
-
|
|
30355
|
+
const errorContext = error.context;
|
|
30356
|
+
const isRefreshFailure = errorContext?.stage === "handleSessionExpiry" || errorContext?.stage === "refreshSession";
|
|
30357
|
+
if (isRefreshFailure) {
|
|
30358
|
+
if (!isOnline) {
|
|
30359
|
+
setError({
|
|
30360
|
+
title: "Session expired",
|
|
30361
|
+
description: "Please check your connection and try again"
|
|
30362
|
+
});
|
|
30363
|
+
setShowRetryButton(true);
|
|
30364
|
+
} else {
|
|
30365
|
+
setError({
|
|
30366
|
+
title: "Session not found",
|
|
30367
|
+
description: "Please start a new session"
|
|
30368
|
+
});
|
|
30369
|
+
setStartNewConnection(true);
|
|
30370
|
+
}
|
|
30371
|
+
} else {
|
|
30372
|
+
setConnectionStatus(distExports.ConnectionStatus.NOT_CONNECTED);
|
|
30373
|
+
setShowRetryButton(true);
|
|
30374
|
+
}
|
|
30342
30375
|
break;
|
|
30343
30376
|
case distExports.SynapseErrorCode.RECORDING:
|
|
30344
30377
|
setError({
|
|
@@ -30348,14 +30381,22 @@ var MedAssistWidget = (function(exports) {
|
|
|
30348
30381
|
break;
|
|
30349
30382
|
case distExports.SynapseErrorCode.CONNECTION:
|
|
30350
30383
|
setError({
|
|
30351
|
-
title: "Connecting..."
|
|
30352
|
-
description: "Please wait while we connect to the server"
|
|
30384
|
+
title: "Connecting..."
|
|
30353
30385
|
});
|
|
30386
|
+
setShowRetryButton(true);
|
|
30354
30387
|
break;
|
|
30388
|
+
// case SynapseErrorCode.AUTH:
|
|
30389
|
+
// setError({
|
|
30390
|
+
// title: "Authentication failed",
|
|
30391
|
+
// description:
|
|
30392
|
+
// error?.displayMessage || "Please try again later",
|
|
30393
|
+
// });
|
|
30394
|
+
// window.parent.postMessage({ type: "AUTH_EXPIRED"})
|
|
30395
|
+
// break;
|
|
30355
30396
|
default:
|
|
30356
30397
|
console.error("useChat: Error from SDK from onError callback", error.code, error);
|
|
30357
30398
|
setError({
|
|
30358
|
-
title:
|
|
30399
|
+
title: "Something went wrong",
|
|
30359
30400
|
description: "Please try again later"
|
|
30360
30401
|
});
|
|
30361
30402
|
setShowRetryButton(true);
|
|
@@ -30558,6 +30599,9 @@ var MedAssistWidget = (function(exports) {
|
|
|
30558
30599
|
);
|
|
30559
30600
|
return;
|
|
30560
30601
|
}
|
|
30602
|
+
if (isWaitingForResponse) {
|
|
30603
|
+
setIsWaitingForResponse(false);
|
|
30604
|
+
}
|
|
30561
30605
|
const messageId = toolCallData.messageId;
|
|
30562
30606
|
const timestamp = toolCallData.timestamp ?? Date.now();
|
|
30563
30607
|
setMessages((prevMessages) => {
|
|
@@ -30607,13 +30651,95 @@ var MedAssistWidget = (function(exports) {
|
|
|
30607
30651
|
});
|
|
30608
30652
|
synapseRef.current?.on(distExports.SYNAPSE_REALTIME_EVENTS.ERROR, (error) => {
|
|
30609
30653
|
console.log("error from sdk on ERROR event", error);
|
|
30610
|
-
const
|
|
30611
|
-
|
|
30612
|
-
|
|
30613
|
-
|
|
30614
|
-
|
|
30615
|
-
|
|
30616
|
-
|
|
30654
|
+
const errorCode = error?.data?.code;
|
|
30655
|
+
switch (errorCode) {
|
|
30656
|
+
case distExports.SYNAPSE_REALTIME_ERROR_CODES.SESSION_INACTIVE:
|
|
30657
|
+
setError({
|
|
30658
|
+
title: "Session not found",
|
|
30659
|
+
description: "Please start a new session"
|
|
30660
|
+
});
|
|
30661
|
+
setStartNewConnection(true);
|
|
30662
|
+
setRecordingStatus(AudioRecordingStatus.IDLE);
|
|
30663
|
+
return;
|
|
30664
|
+
case distExports.SYNAPSE_REALTIME_ERROR_CODES.SESSION_EXPIRED:
|
|
30665
|
+
if (!isOnline) {
|
|
30666
|
+
setError({
|
|
30667
|
+
title: "Session expired",
|
|
30668
|
+
description: "Please check your connection and try again"
|
|
30669
|
+
});
|
|
30670
|
+
setShowRetryButton(true);
|
|
30671
|
+
} else {
|
|
30672
|
+
setError({
|
|
30673
|
+
title: "Session not found",
|
|
30674
|
+
description: "Please start a new session"
|
|
30675
|
+
});
|
|
30676
|
+
setStartNewConnection(true);
|
|
30677
|
+
}
|
|
30678
|
+
setRecordingStatus(AudioRecordingStatus.IDLE);
|
|
30679
|
+
return;
|
|
30680
|
+
case distExports.SYNAPSE_REALTIME_ERROR_CODES.SESSION_TOKEN_MISMATCH:
|
|
30681
|
+
setError({
|
|
30682
|
+
title: "Session not found",
|
|
30683
|
+
description: "Please start a new session"
|
|
30684
|
+
});
|
|
30685
|
+
setStartNewConnection(true);
|
|
30686
|
+
setRecordingStatus(AudioRecordingStatus.IDLE);
|
|
30687
|
+
return;
|
|
30688
|
+
case distExports.SYNAPSE_REALTIME_ERROR_CODES.INVALID_EVENT:
|
|
30689
|
+
console.log("invalid event error", error);
|
|
30690
|
+
return;
|
|
30691
|
+
case distExports.SYNAPSE_REALTIME_ERROR_CODES.INVALID_CONTENT_TYPE:
|
|
30692
|
+
console.log("invalid content type error", error);
|
|
30693
|
+
return;
|
|
30694
|
+
case distExports.SYNAPSE_REALTIME_ERROR_CODES.PARSING_ERROR:
|
|
30695
|
+
setError({
|
|
30696
|
+
title: "Error parsing request",
|
|
30697
|
+
description: "please try again"
|
|
30698
|
+
});
|
|
30699
|
+
setShowRetryButton(true);
|
|
30700
|
+
setRecordingStatus(AudioRecordingStatus.IDLE);
|
|
30701
|
+
return;
|
|
30702
|
+
case distExports.SYNAPSE_REALTIME_ERROR_CODES.TIMEOUT:
|
|
30703
|
+
setError({
|
|
30704
|
+
title: "Request timed out",
|
|
30705
|
+
description: "please try again"
|
|
30706
|
+
});
|
|
30707
|
+
setShowRetryButton(true);
|
|
30708
|
+
setRecordingStatus(AudioRecordingStatus.IDLE);
|
|
30709
|
+
return;
|
|
30710
|
+
case distExports.SYNAPSE_REALTIME_ERROR_CODES.PROMPT_FETCH_ERROR:
|
|
30711
|
+
setError({
|
|
30712
|
+
title: "Something went wrong",
|
|
30713
|
+
description: "please try again"
|
|
30714
|
+
});
|
|
30715
|
+
setShowRetryButton(true);
|
|
30716
|
+
setRecordingStatus(AudioRecordingStatus.IDLE);
|
|
30717
|
+
return;
|
|
30718
|
+
case distExports.SYNAPSE_REALTIME_ERROR_CODES.INVALID_FILE_REQUEST:
|
|
30719
|
+
setError({
|
|
30720
|
+
title: "Something went wrong",
|
|
30721
|
+
description: "please try again"
|
|
30722
|
+
});
|
|
30723
|
+
setShowRetryButton(true);
|
|
30724
|
+
setRecordingStatus(AudioRecordingStatus.IDLE);
|
|
30725
|
+
return;
|
|
30726
|
+
case distExports.SYNAPSE_REALTIME_ERROR_CODES.SERVER_ERROR:
|
|
30727
|
+
setError({
|
|
30728
|
+
title: "Something went wrong",
|
|
30729
|
+
description: "please try again"
|
|
30730
|
+
});
|
|
30731
|
+
setShowRetryButton(true);
|
|
30732
|
+
setRecordingStatus(AudioRecordingStatus.IDLE);
|
|
30733
|
+
return;
|
|
30734
|
+
default:
|
|
30735
|
+
setError({
|
|
30736
|
+
title: "Something went wrong",
|
|
30737
|
+
description: "please try again"
|
|
30738
|
+
});
|
|
30739
|
+
setShowRetryButton(true);
|
|
30740
|
+
setRecordingStatus(AudioRecordingStatus.IDLE);
|
|
30741
|
+
return;
|
|
30742
|
+
}
|
|
30617
30743
|
});
|
|
30618
30744
|
synapseRef.current?.on(distExports.SYNAPSE_REALTIME_EVENTS.AUDIO_TRANSCRIPT, async (data) => {
|
|
30619
30745
|
const inlineTextData = data;
|
|
@@ -41927,10 +42053,10 @@ var MedAssistWidget = (function(exports) {
|
|
|
41927
42053
|
}
|
|
41928
42054
|
}, [selectedHospital, doctor.doctor_id]);
|
|
41929
42055
|
reactExports.useEffect(() => {
|
|
41930
|
-
if (callbacks?.[distExports.SYNAPSE_TOOL_CALLBACK_NAME.AVAILABILITY_DATES] && !
|
|
42056
|
+
if (callbacks?.[distExports.SYNAPSE_TOOL_CALLBACK_NAME.AVAILABILITY_DATES] && selectedHospital && !availability[selectedHospital]?.length) {
|
|
41931
42057
|
getAvailabilityDates(callbacks[distExports.SYNAPSE_TOOL_CALLBACK_NAME.AVAILABILITY_DATES].tool_name);
|
|
41932
42058
|
}
|
|
41933
|
-
}, [callbacks,
|
|
42059
|
+
}, [callbacks, selectedHospital]);
|
|
41934
42060
|
const availabilityForSelectedHospital = reactExports.useMemo(() => {
|
|
41935
42061
|
return availability[selectedHospital] || [];
|
|
41936
42062
|
}, [availability, selectedHospital]);
|
|
@@ -42107,7 +42233,7 @@ var MedAssistWidget = (function(exports) {
|
|
|
42107
42233
|
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-slate-600", children: doctorDetails.hospitals?.[0].name || "" })
|
|
42108
42234
|
] })
|
|
42109
42235
|
] }),
|
|
42110
|
-
availabilityForSelectedHospital.length || loadingAvailabilityDates ? /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
42236
|
+
availabilityForSelectedHospital.length > 0 || loadingAvailabilityDates ? /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
42111
42237
|
Button,
|
|
42112
42238
|
{
|
|
42113
42239
|
type: "button",
|
|
@@ -42132,7 +42258,7 @@ var MedAssistWidget = (function(exports) {
|
|
|
42132
42258
|
] })
|
|
42133
42259
|
}
|
|
42134
42260
|
) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-3 w-full flex items-center justify-center py-3 px-4 bg-lavender-50 border border-lavender-200 rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-slate-600 font-medium", children: "No details available" }) }),
|
|
42135
|
-
open && availabilityForSelectedHospital.length && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
42261
|
+
open && availabilityForSelectedHospital.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
42136
42262
|
"div",
|
|
42137
42263
|
{
|
|
42138
42264
|
id: "ap-slots",
|