@eka-care/medassist-widget-embed 0.2.9 → 0.2.11

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.
@@ -895,6 +895,10 @@ body {
895
895
  display: grid;
896
896
  }
897
897
 
898
+ .\!hidden {
899
+ display: none !important;
900
+ }
901
+
898
902
  .hidden {
899
903
  display: none;
900
904
  }
@@ -2165,6 +2169,10 @@ body {
2165
2169
  --tw-ring-color: rgb(232 228 255 / var(--tw-ring-opacity));
2166
2170
  }
2167
2171
 
2172
+ .ring-primary {
2173
+ --tw-ring-color: hsl(var(--primary));
2174
+ }
2175
+
2168
2176
  .ring-primary\/10 {
2169
2177
  --tw-ring-color: hsl(var(--primary) / var(--opacity-10));
2170
2178
  }
@@ -2173,6 +2181,10 @@ body {
2173
2181
  --tw-ring-color: hsl(var(--primary) / 0.2);
2174
2182
  }
2175
2183
 
2184
+ .ring-offset-2 {
2185
+ --tw-ring-offset-width: 2px;
2186
+ }
2187
+
2176
2188
  .blur {
2177
2189
  --tw-blur: blur(8px);
2178
2190
  filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
@@ -31288,9 +31288,15 @@ var MedAssistWidget = (function(exports) {
31288
31288
  messageId,
31289
31289
  files,
31290
31290
  audio,
31291
- toolCalled
31291
+ toolCalled,
31292
+ hidden
31292
31293
  }) => {
31293
31294
  if (!isConnected()) {
31295
+ setShowRetryButton(true);
31296
+ setError({
31297
+ title: "Trying to connect.",
31298
+ description: "Please try again"
31299
+ });
31294
31300
  return;
31295
31301
  }
31296
31302
  if (files && files.length < 0 && message?.trim() === "" && !audio?.audio) {
@@ -31337,36 +31343,41 @@ var MedAssistWidget = (function(exports) {
31337
31343
  } : {}
31338
31344
  });
31339
31345
  if (message || files && files.length > 0) {
31340
- setMessages((prev) => {
31341
- const previousMessage = [...prev];
31342
- const prevLastIndex = previousMessage.length - 1;
31343
- if (isResponseFromTool && prevLastIndex >= 0 && previousMessage[prevLastIndex].toolEscalationData) {
31344
- previousMessage[prevLastIndex] = {
31345
- ...previousMessage[prevLastIndex],
31346
- toolEscalationData: {
31347
- ...previousMessage[prevLastIndex].toolEscalationData,
31348
- tool_id: null,
31349
- isResponded: true
31350
- }
31351
- };
31352
- updateMessageInSession(
31353
- sessionId,
31354
- previousMessage[lastIndex].id || Date.now().toString(),
31355
- previousMessage[lastIndex]
31356
- );
31357
- }
31358
- return [
31359
- ...previousMessage,
31360
- {
31361
- id: messageId || Date.now().toString(),
31362
- content: message || "",
31363
- files: files || [],
31364
- role: MessageSender.USER,
31365
- timestamp: formatMessageTimestamp(Date.now()),
31366
- isStored: true
31346
+ const shouldUpdateToolResponse = isResponseFromTool && lastMessage?.toolEscalationData && (toolCalled === true || !hidden);
31347
+ if (!hidden || shouldUpdateToolResponse) {
31348
+ setMessages((prev) => {
31349
+ const previousMessage = [...prev];
31350
+ const prevLastIndex = previousMessage.length - 1;
31351
+ if (isResponseFromTool && prevLastIndex >= 0 && previousMessage[prevLastIndex].toolEscalationData) {
31352
+ previousMessage[prevLastIndex] = {
31353
+ ...previousMessage[prevLastIndex],
31354
+ toolEscalationData: {
31355
+ ...previousMessage[prevLastIndex].toolEscalationData,
31356
+ tool_id: null,
31357
+ isResponded: true,
31358
+ ...toolCalled && message != null && message.trim() !== "" && { selectedCtaAction: message.trim() }
31359
+ }
31360
+ };
31361
+ updateMessageInSession(
31362
+ sessionId,
31363
+ previousMessage[prevLastIndex].id || Date.now().toString(),
31364
+ previousMessage[prevLastIndex]
31365
+ );
31367
31366
  }
31368
- ];
31369
- });
31367
+ if (hidden) return previousMessage;
31368
+ return [
31369
+ ...previousMessage,
31370
+ {
31371
+ id: messageId || Date.now().toString(),
31372
+ content: message || "",
31373
+ files: files || [],
31374
+ role: MessageSender.USER,
31375
+ timestamp: formatMessageTimestamp(Date.now()),
31376
+ isStored: true
31377
+ }
31378
+ ];
31379
+ });
31380
+ }
31370
31381
  setIsWaitingForResponse(true);
31371
31382
  }
31372
31383
  };
@@ -43117,7 +43128,8 @@ var MedAssistWidget = (function(exports) {
43117
43128
  function GenericCard({
43118
43129
  card,
43119
43130
  onSendMessage,
43120
- disabled = false
43131
+ disabled = false,
43132
+ selectedCtaAction
43121
43133
  }) {
43122
43134
  const {
43123
43135
  title,
@@ -43140,6 +43152,9 @@ var MedAssistWidget = (function(exports) {
43140
43152
  };
43141
43153
  const bannerTheme = banner?.theme ?? "success";
43142
43154
  const bannerClass = BANNER_THEME_CLASSES[bannerTheme];
43155
+ const displayCtas = selectedCtaAction != null && selectedCtaAction.trim() !== "" ? ctas?.filter(
43156
+ (cta) => cta.action?.trim() === selectedCtaAction.trim()
43157
+ ) ?? [] : ctas ?? [];
43143
43158
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Card, { className: "overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-sm", children: [
43144
43159
  /* @__PURE__ */ jsxRuntimeExports.jsxs(CardHeader, { className: "flex flex-row items-start justify-between gap-3 pb-2", children: [
43145
43160
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0 flex-1", children: [
@@ -43179,21 +43194,25 @@ var MedAssistWidget = (function(exports) {
43179
43194
  i
43180
43195
  )) }) : null
43181
43196
  ] }),
43182
- ctas?.length ? /* @__PURE__ */ jsxRuntimeExports.jsx(CardFooter, { className: "flex justify-center flex-wrap gap-2 pt-0", children: ctas.map((cta, i) => {
43197
+ displayCtas.length ? /* @__PURE__ */ jsxRuntimeExports.jsx(CardFooter, { className: "flex justify-center flex-wrap gap-2 pt-0", children: displayCtas.map((cta, i) => {
43183
43198
  const variant = cta.theme ? CTA_VARIANT[cta.theme] : "default";
43184
43199
  const isOutline = i > 0 || cta.link && !cta.action;
43200
+ const isSelected = disabled && selectedCtaAction != null && cta.action?.trim() === selectedCtaAction.trim();
43185
43201
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(
43186
43202
  Button,
43187
43203
  {
43188
43204
  type: "button",
43189
- variant: isOutline ? "outline" : variant,
43205
+ variant: isOutline && !isSelected ? "outline" : variant,
43190
43206
  size: "sm",
43191
- className: "gap-1.5",
43207
+ className: cn(
43208
+ "gap-1.5",
43209
+ isSelected && "ring-2 ring-primary ring-offset-2"
43210
+ ),
43192
43211
  disabled,
43193
43212
  onClick: () => handleCtaClick(cta),
43194
43213
  children: [
43195
43214
  cta.icon ? /* @__PURE__ */ jsxRuntimeExports.jsx(CardIcon, { name: cta.icon, size: 14, className: "shrink-0" }) : null,
43196
- cta.title
43215
+ isSelected ? "Selected" : cta.title
43197
43216
  ]
43198
43217
  },
43199
43218
  i
@@ -43205,17 +43224,27 @@ var MedAssistWidget = (function(exports) {
43205
43224
  cards,
43206
43225
  onSendMessage,
43207
43226
  disabled = false,
43227
+ selectedCtaAction,
43208
43228
  className
43209
43229
  }) {
43210
43230
  if (!cards?.length) {
43211
43231
  return /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground py-2", children: "No options available." });
43212
43232
  }
43213
- return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: className ?? "flex flex-col gap-3 mt-3", children: cards.map((card, index2) => /* @__PURE__ */ jsxRuntimeExports.jsx(
43233
+ const displayCards = selectedCtaAction != null && selectedCtaAction.trim() !== "" ? cards.filter(
43234
+ (card) => card.ctas?.some(
43235
+ (cta) => cta.action?.trim() === selectedCtaAction.trim()
43236
+ )
43237
+ ) : cards;
43238
+ if (!displayCards.length) {
43239
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground py-2", children: "No options available." });
43240
+ }
43241
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: className ?? "flex flex-col gap-3 mt-3", children: displayCards.map((card, index2) => /* @__PURE__ */ jsxRuntimeExports.jsx(
43214
43242
  GenericCard,
43215
43243
  {
43216
43244
  card,
43217
43245
  onSendMessage,
43218
- disabled
43246
+ disabled,
43247
+ selectedCtaAction
43219
43248
  },
43220
43249
  index2
43221
43250
  )) });
@@ -43440,9 +43469,11 @@ var MedAssistWidget = (function(exports) {
43440
43469
  await onSendMessage({
43441
43470
  message,
43442
43471
  messageId,
43443
- toolCalled: true
43472
+ toolCalled: true,
43473
+ hidden: true
43444
43474
  });
43445
43475
  },
43476
+ selectedCtaAction: toolEscalationData?.selectedCtaAction,
43446
43477
  disabled: toolEscalationData?.isResponded
43447
43478
  }
43448
43479
  )