@eka-care/medassist-widget-embed 0.2.6 → 0.2.7

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.js CHANGED
@@ -42,6 +42,7 @@
42
42
  }
43
43
  /** Fetch agent-config from API with timeout; aborts if pending > 10s */
44
44
  async function fetchAgentConfig(baseUrl, agentId) {
45
+ var _a;
45
46
  const url = `${baseUrl.replace(/\/$/, "")}/med-assist/agent-config/${agentId}`;
46
47
  const controller = new AbortController();
47
48
  const timeoutId = setTimeout(() => controller.abort(), API_FETCH_TIMEOUT_MS);
@@ -55,7 +56,7 @@
55
56
  if (!res.ok)
56
57
  return undefined;
57
58
  const json = await res.json();
58
- if ((json === null || json === void 0 ? void 0 : json.success) && (json === null || json === void 0 ? void 0 : json.data))
59
+ if ((json === null || json === void 0 ? void 0 : json.success) && ((_a = json === null || json === void 0 ? void 0 : json.data) === null || _a === void 0 ? void 0 : _a.theme))
59
60
  return json.data;
60
61
  return undefined;
61
62
  }
@@ -101,10 +102,49 @@
101
102
  const WIDGET_CSS_URL = `${widgetAssetBaseUrl}medassist-widget.css`;
102
103
  let widgetScriptPromise = null;
103
104
  let widgetCssTextPromise = null;
105
+ // --- Start loading as early as possible (don't wait for DOMContentLoaded) ---
106
+ const urlParams = new URLSearchParams(typeof window !== "undefined" ? window.location.search : "");
107
+ const earlyAgentId = urlParams.get("agentId");
108
+ const earlyBaseUrl = urlParams.get("baseUrl") || "https://matrix.eka.care/reloaded";
109
+ if (typeof document !== "undefined" && document.head) {
110
+ try {
111
+ const assetOrigin = new URL(widgetAssetBaseUrl).origin;
112
+ const apiOrigin = new URL(earlyBaseUrl).origin;
113
+ const preconnectAsset = document.createElement("link");
114
+ preconnectAsset.rel = "preconnect";
115
+ preconnectAsset.href = assetOrigin;
116
+ preconnectAsset.crossOrigin = "anonymous";
117
+ document.head.appendChild(preconnectAsset);
118
+ if (assetOrigin !== apiOrigin) {
119
+ const preconnectApi = document.createElement("link");
120
+ preconnectApi.rel = "preconnect";
121
+ preconnectApi.href = apiOrigin;
122
+ preconnectApi.crossOrigin = "anonymous";
123
+ document.head.appendChild(preconnectApi);
124
+ }
125
+ const preloadScript = document.createElement("link");
126
+ preloadScript.rel = "preload";
127
+ preloadScript.as = "script";
128
+ preloadScript.href = WIDGET_JS_URL;
129
+ document.head.appendChild(preloadScript);
130
+ const preloadCss = document.createElement("link");
131
+ preloadCss.rel = "preload";
132
+ preloadCss.as = "style";
133
+ preloadCss.href = WIDGET_CSS_URL;
134
+ document.head.appendChild(preloadCss);
135
+ }
136
+ catch {
137
+ // ignore URL/preload errors
138
+ }
139
+ loadWidgetCss();
140
+ loadWidgetScript();
141
+ }
142
+ const agentConfigPromise = earlyAgentId && earlyBaseUrl
143
+ ? fetchAgentConfig(earlyBaseUrl, earlyAgentId)
144
+ : Promise.resolve(undefined);
104
145
  // Auto-initialize from URL parameters (no shadow DOM needed in iframe)
105
146
  const initializeFromUrlParams = async () => {
106
147
  var _a, _b, _c, _d, _e;
107
- const urlParams = new URLSearchParams(window.location.search);
108
148
  const agentId = urlParams.get("agentId");
109
149
  if (!agentId) {
110
150
  console.error("Agent ID is required in URL parameters");
@@ -127,31 +167,24 @@
127
167
  : undefined;
128
168
  const container = document.getElementById("root") || document.body;
129
169
  try {
130
- await Promise.all([loadWidgetCss(), loadWidgetScript()]);
170
+ const [, , agentConfig] = await Promise.all([
171
+ loadWidgetCss(),
172
+ loadWidgetScript(),
173
+ agentConfigPromise,
174
+ ]);
131
175
  if (!(window === null || window === void 0 ? void 0 : window.renderMedAssist) ||
132
176
  typeof (window === null || window === void 0 ? void 0 : window.renderMedAssist) !== "function") {
133
177
  throw new Error("renderMedAssist is not available on window");
134
178
  }
135
- // Fetch agent-config when baseUrl is available; 10s timeout aborts pending request
136
179
  let apiTheme;
137
- let allowed;
138
- console.log("base url", baseUrl);
139
- if (baseUrl) {
140
- try {
141
- const agentConfig = await fetchAgentConfig(baseUrl, agentId);
142
- title = (_b = agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.name) !== null && _b !== void 0 ? _b : title;
143
- iconUrl = (_d = (_c = agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.theme) === null || _c === void 0 ? void 0 : _c.icon_img) !== null && _d !== void 0 ? _d : iconUrl;
144
- apiTheme = mapAgentConfigThemeToWidgetTheme((_e = agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.theme) !== null && _e !== void 0 ? _e : undefined);
145
- allowed = agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.allowed;
146
- }
147
- catch {
148
- // ignore; use URL params only
149
- }
180
+ if (agentConfig) {
181
+ title = (_b = agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.name) !== null && _b !== void 0 ? _b : title;
182
+ iconUrl = (_d = (_c = agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.theme) === null || _c === void 0 ? void 0 : _c.icon_img) !== null && _d !== void 0 ? _d : iconUrl;
183
+ apiTheme = mapAgentConfigThemeToWidgetTheme((_e = agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.theme) !== null && _e !== void 0 ? _e : undefined);
150
184
  }
151
185
  const config = {
152
186
  title,
153
187
  iconUrl,
154
- allowed,
155
188
  environment,
156
189
  onClose: () => {
157
190
  if (window.parent !== window) {
@@ -2727,6 +2727,12 @@ body {
2727
2727
  opacity: 0.6;
2728
2728
  }
2729
2729
 
2730
+ .disabled\:hover\:scale-100:hover:disabled {
2731
+ --tw-scale-x: 1;
2732
+ --tw-scale-y: 1;
2733
+ transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
2734
+ }
2735
+
2730
2736
  .group:hover .group-hover\:bg-purple-200\/70 {
2731
2737
  background-color: rgb(233 213 255 / 0.7);
2732
2738
  }
@@ -32017,8 +32017,10 @@ var MedAssistWidget = (function(exports) {
32017
32017
  }) {
32018
32018
  const fileInputRef = reactExports.useRef(null);
32019
32019
  const textareaRef = reactExports.useRef(null);
32020
- const showSendButton = value.trim().length > 0 || hasAttachment;
32020
+ const hasContent = value.trim().length > 0 || hasAttachment;
32021
32021
  const showMic = allowed === void 0 || allowed.includes("audio");
32022
+ const showSendButton = hasContent || !showMic;
32023
+ const canSend = hasContent;
32022
32024
  const showFileAttachment = allowed === void 0 || allowed.includes("file");
32023
32025
  const isMicDisabled = (isDisabled || recordingStatus !== AudioRecordingStatus.IDLE) && !isRecording;
32024
32026
  const micButtonClasses = cn(
@@ -32038,7 +32040,7 @@ var MedAssistWidget = (function(exports) {
32038
32040
  fileInputRef.current?.click();
32039
32041
  };
32040
32042
  const handleKeyPress = (e) => {
32041
- if (e.key === "Enter" && !e.shiftKey && showSendButton && !isDisabled) {
32043
+ if (e.key === "Enter" && !e.shiftKey && canSend && !isDisabled) {
32042
32044
  e.preventDefault();
32043
32045
  onSend();
32044
32046
  }
@@ -32178,15 +32180,16 @@ var MedAssistWidget = (function(exports) {
32178
32180
  children: /* @__PURE__ */ jsxRuntimeExports.jsx(Mic, { className: "w-5 h-5" })
32179
32181
  }
32180
32182
  ),
32181
- showSendButton && !isDisabled && /* @__PURE__ */ jsxRuntimeExports.jsx(
32183
+ showSendButton && /* @__PURE__ */ jsxRuntimeExports.jsx(
32182
32184
  Button,
32183
32185
  {
32184
32186
  type: "button",
32185
32187
  size: "icon",
32186
32188
  onClick: onSend,
32187
- className: "absolute right-0.5 top-1/2 -translate-y-1/2 h-10 w-10 bg-primary hover:bg-primary/90 rounded-full text-primary-foreground transition-all duration-200 shadow-lg hover:shadow-xl hover:scale-105 active:scale-95 shrink-0",
32188
- title: "Send message",
32189
- "aria-label": "Send message",
32189
+ disabled: isDisabled || !canSend,
32190
+ className: `absolute right-0.5 top-1/2 -translate-y-1/2 h-10 w-10 ${!showMic ? "" : "bg-primary"} hover:bg-primary/90 rounded-full text-primary-foreground transition-all duration-200 shadow-lg hover:shadow-xl hover:scale-105 active:scale-95 shrink-0 disabled:opacity-50 disabled:pointer-events-none disabled:hover:scale-100`,
32191
+ title: canSend ? "Send message" : "Type a message to send",
32192
+ "aria-label": canSend ? "Send message" : "Type a message to send",
32190
32193
  children: /* @__PURE__ */ jsxRuntimeExports.jsx(SendIcon, { className: "w-4 h-4 text-primary-foreground" })
32191
32194
  }
32192
32195
  )