wealth-alpha-chat-widget 1.0.4 → 1.0.6

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/index.cjs CHANGED
@@ -701,6 +701,13 @@ var chat_default = {
701
701
  bubbleBot: "chat_bubbleBot",
702
702
  bubbleUser: "chat_bubbleUser",
703
703
  bubbleCard: "chat_bubbleCard",
704
+ disclaimer: "chat_disclaimer",
705
+ feedbackRow: "chat_feedbackRow",
706
+ feedbackLabel: "chat_feedbackLabel",
707
+ feedbackBtn: "chat_feedbackBtn",
708
+ feedbackBtnUp: "chat_feedbackBtnUp",
709
+ feedbackBtnDown: "chat_feedbackBtnDown",
710
+ feedbackIcon: "chat_feedbackIcon",
704
711
  bubbleMeta: "chat_bubbleMeta",
705
712
  chipRow: "chat_chipRow",
706
713
  chip: "chat_chip",
@@ -813,7 +820,7 @@ var ALLOWED_TAGS = [
813
820
  "span",
814
821
  "div"
815
822
  ];
816
- var ALLOWED_ATTR = ["href", "target", "rel", "class", "style", "data-wa-gauge-pct"];
823
+ var ALLOWED_ATTR = ["href", "target", "rel", "class", "style", "data-wa-gauge-pct", "data-chip"];
817
824
  var SANITIZE_CFG = {
818
825
  ALLOWED_TAGS,
819
826
  ALLOWED_ATTR,
@@ -883,11 +890,27 @@ var MENU_ICON_SVG = {
883
890
  function isRootMenuChips(chips) {
884
891
  return chips.length > 0 && chips.every((c) => ROOT_MENU_CHIP_IDS.has(c.id));
885
892
  }
886
- function MessageBubble({ message, onChipClick }) {
893
+ var CARD_DISCLAIMER = "AI-assisted, educational only. Not financial advice. Consult a SEBI-registered advisor.";
894
+ function MessageBubble({ message, onChipClick, onFeedback }) {
887
895
  const isBot = message.role === "bot";
896
+ const [rating, setRating] = react.useState(null);
897
+ const rate = (value) => {
898
+ setRating(value);
899
+ onFeedback?.(message.id, value);
900
+ };
888
901
  const isCard = isBot && message.content.includes("<div");
889
902
  const bubbleClass = isBot ? `${chat_default.bubble} ${isCard ? chat_default.bubbleCard : chat_default.bubbleBot}` : `${chat_default.bubble} ${chat_default.bubbleUser}`;
890
903
  const handleMarkdownClick = (e) => {
904
+ const row = e.target.closest(".srow[data-chip]");
905
+ if (row) {
906
+ e.preventDefault();
907
+ const chipId = row.getAttribute("data-chip");
908
+ if (chipId) {
909
+ const label = row.querySelector(".nm")?.textContent?.trim() ?? "";
910
+ onChipClick({ id: chipId, label });
911
+ }
912
+ return;
913
+ }
891
914
  const anchor = e.target.closest("a");
892
915
  if (!anchor?.href) return;
893
916
  e.preventDefault();
@@ -904,6 +927,42 @@ function MessageBubble({ message, onChipClick }) {
904
927
  onClick: handleMarkdownClick
905
928
  }
906
929
  ) : message.content }),
930
+ isCard ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: chat_default.feedbackRow, children: [
931
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: chat_default.feedbackLabel, children: "Was this helpful?" }),
932
+ /* @__PURE__ */ jsxRuntime.jsx(
933
+ "button",
934
+ {
935
+ type: "button",
936
+ className: `${chat_default.feedbackBtn} ${rating === "up" ? chat_default.feedbackBtnUp : ""}`,
937
+ "aria-label": "Helpful",
938
+ "aria-pressed": rating === "up",
939
+ onClick: () => rate("up"),
940
+ children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { className: chat_default.feedbackIcon, viewBox: "0 0 24 24", "aria-hidden": "true", children: [
941
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M7 10v12" }),
942
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z" })
943
+ ] })
944
+ }
945
+ ),
946
+ /* @__PURE__ */ jsxRuntime.jsx(
947
+ "button",
948
+ {
949
+ type: "button",
950
+ className: `${chat_default.feedbackBtn} ${rating === "down" ? chat_default.feedbackBtnDown : ""}`,
951
+ "aria-label": "Not helpful",
952
+ "aria-pressed": rating === "down",
953
+ onClick: () => rate("down"),
954
+ children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { className: chat_default.feedbackIcon, viewBox: "0 0 24 24", "aria-hidden": "true", children: [
955
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M17 14V2" }),
956
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z" })
957
+ ] })
958
+ }
959
+ )
960
+ ] }) : null,
961
+ isCard ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: chat_default.disclaimer, children: [
962
+ /* @__PURE__ */ jsxRuntime.jsx("b", { children: "Disclaimer:" }),
963
+ " ",
964
+ CARD_DISCLAIMER
965
+ ] }) : null,
907
966
  showMenuGrid ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: chat_default.menuGrid, children: chips.map((chip) => {
908
967
  const iconKey = MENU_ICON_KEY[chip.id];
909
968
  const iconClass = iconKey && chat_default[iconKey] || "";
@@ -956,7 +1015,8 @@ function ChatBody({
956
1015
  loginUrl,
957
1016
  error,
958
1017
  onChipClick,
959
- onLoginClick
1018
+ onLoginClick,
1019
+ onFeedback
960
1020
  }) {
961
1021
  const endRef = react.useRef(null);
962
1022
  react.useEffect(() => {
@@ -976,7 +1036,7 @@ function ChatBody({
976
1036
  ) });
977
1037
  }
978
1038
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: chat_default.body, children: [
979
- messages.map((m) => /* @__PURE__ */ jsxRuntime.jsx(MessageBubble, { message: m, onChipClick }, m.id)),
1039
+ messages.map((m) => /* @__PURE__ */ jsxRuntime.jsx(MessageBubble, { message: m, onChipClick, onFeedback }, m.id)),
980
1040
  isTyping ? /* @__PURE__ */ jsxRuntime.jsx(TypingIndicator, {}) : null,
981
1041
  error ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: chat_default.errorBanner, children: error }) : null,
982
1042
  /* @__PURE__ */ jsxRuntime.jsx("div", { ref: endRef })
@@ -1138,7 +1198,8 @@ function WealthChat(props) {
1138
1198
  onLogin,
1139
1199
  onLogout,
1140
1200
  onSessionExpire,
1141
- onError
1201
+ onError,
1202
+ onFeedback
1142
1203
  } = props;
1143
1204
  const [mounted, setMounted] = react.useState(false);
1144
1205
  const [open, setOpen] = react.useState(defaultOpen);
@@ -1341,7 +1402,8 @@ function WealthChat(props) {
1341
1402
  loginUrl,
1342
1403
  error: chatState.error,
1343
1404
  onChipClick: handleChipClick,
1344
- onLoginClick: handleLoginClick
1405
+ onLoginClick: handleLoginClick,
1406
+ onFeedback
1345
1407
  }
1346
1408
  ),
1347
1409
  /* @__PURE__ */ jsxRuntime.jsx(