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.mjs CHANGED
@@ -695,6 +695,13 @@ var chat_default = {
695
695
  bubbleBot: "chat_bubbleBot",
696
696
  bubbleUser: "chat_bubbleUser",
697
697
  bubbleCard: "chat_bubbleCard",
698
+ disclaimer: "chat_disclaimer",
699
+ feedbackRow: "chat_feedbackRow",
700
+ feedbackLabel: "chat_feedbackLabel",
701
+ feedbackBtn: "chat_feedbackBtn",
702
+ feedbackBtnUp: "chat_feedbackBtnUp",
703
+ feedbackBtnDown: "chat_feedbackBtnDown",
704
+ feedbackIcon: "chat_feedbackIcon",
698
705
  bubbleMeta: "chat_bubbleMeta",
699
706
  chipRow: "chat_chipRow",
700
707
  chip: "chat_chip",
@@ -807,7 +814,7 @@ var ALLOWED_TAGS = [
807
814
  "span",
808
815
  "div"
809
816
  ];
810
- var ALLOWED_ATTR = ["href", "target", "rel", "class", "style", "data-wa-gauge-pct"];
817
+ var ALLOWED_ATTR = ["href", "target", "rel", "class", "style", "data-wa-gauge-pct", "data-chip"];
811
818
  var SANITIZE_CFG = {
812
819
  ALLOWED_TAGS,
813
820
  ALLOWED_ATTR,
@@ -877,11 +884,27 @@ var MENU_ICON_SVG = {
877
884
  function isRootMenuChips(chips) {
878
885
  return chips.length > 0 && chips.every((c) => ROOT_MENU_CHIP_IDS.has(c.id));
879
886
  }
880
- function MessageBubble({ message, onChipClick }) {
887
+ var CARD_DISCLAIMER = "AI-assisted, educational only. Not financial advice. Consult a SEBI-registered advisor.";
888
+ function MessageBubble({ message, onChipClick, onFeedback }) {
881
889
  const isBot = message.role === "bot";
890
+ const [rating, setRating] = useState(null);
891
+ const rate = (value) => {
892
+ setRating(value);
893
+ onFeedback?.(message.id, value);
894
+ };
882
895
  const isCard = isBot && message.content.includes("<div");
883
896
  const bubbleClass = isBot ? `${chat_default.bubble} ${isCard ? chat_default.bubbleCard : chat_default.bubbleBot}` : `${chat_default.bubble} ${chat_default.bubbleUser}`;
884
897
  const handleMarkdownClick = (e) => {
898
+ const row = e.target.closest(".srow[data-chip]");
899
+ if (row) {
900
+ e.preventDefault();
901
+ const chipId = row.getAttribute("data-chip");
902
+ if (chipId) {
903
+ const label = row.querySelector(".nm")?.textContent?.trim() ?? "";
904
+ onChipClick({ id: chipId, label });
905
+ }
906
+ return;
907
+ }
885
908
  const anchor = e.target.closest("a");
886
909
  if (!anchor?.href) return;
887
910
  e.preventDefault();
@@ -898,6 +921,42 @@ function MessageBubble({ message, onChipClick }) {
898
921
  onClick: handleMarkdownClick
899
922
  }
900
923
  ) : message.content }),
924
+ isCard ? /* @__PURE__ */ jsxs("div", { className: chat_default.feedbackRow, children: [
925
+ /* @__PURE__ */ jsx("span", { className: chat_default.feedbackLabel, children: "Was this helpful?" }),
926
+ /* @__PURE__ */ jsx(
927
+ "button",
928
+ {
929
+ type: "button",
930
+ className: `${chat_default.feedbackBtn} ${rating === "up" ? chat_default.feedbackBtnUp : ""}`,
931
+ "aria-label": "Helpful",
932
+ "aria-pressed": rating === "up",
933
+ onClick: () => rate("up"),
934
+ children: /* @__PURE__ */ jsxs("svg", { className: chat_default.feedbackIcon, viewBox: "0 0 24 24", "aria-hidden": "true", children: [
935
+ /* @__PURE__ */ jsx("path", { d: "M7 10v12" }),
936
+ /* @__PURE__ */ 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" })
937
+ ] })
938
+ }
939
+ ),
940
+ /* @__PURE__ */ jsx(
941
+ "button",
942
+ {
943
+ type: "button",
944
+ className: `${chat_default.feedbackBtn} ${rating === "down" ? chat_default.feedbackBtnDown : ""}`,
945
+ "aria-label": "Not helpful",
946
+ "aria-pressed": rating === "down",
947
+ onClick: () => rate("down"),
948
+ children: /* @__PURE__ */ jsxs("svg", { className: chat_default.feedbackIcon, viewBox: "0 0 24 24", "aria-hidden": "true", children: [
949
+ /* @__PURE__ */ jsx("path", { d: "M17 14V2" }),
950
+ /* @__PURE__ */ 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" })
951
+ ] })
952
+ }
953
+ )
954
+ ] }) : null,
955
+ isCard ? /* @__PURE__ */ jsxs("div", { className: chat_default.disclaimer, children: [
956
+ /* @__PURE__ */ jsx("b", { children: "Disclaimer:" }),
957
+ " ",
958
+ CARD_DISCLAIMER
959
+ ] }) : null,
901
960
  showMenuGrid ? /* @__PURE__ */ jsx("div", { className: chat_default.menuGrid, children: chips.map((chip) => {
902
961
  const iconKey = MENU_ICON_KEY[chip.id];
903
962
  const iconClass = iconKey && chat_default[iconKey] || "";
@@ -950,7 +1009,8 @@ function ChatBody({
950
1009
  loginUrl,
951
1010
  error,
952
1011
  onChipClick,
953
- onLoginClick
1012
+ onLoginClick,
1013
+ onFeedback
954
1014
  }) {
955
1015
  const endRef = useRef(null);
956
1016
  useEffect(() => {
@@ -970,7 +1030,7 @@ function ChatBody({
970
1030
  ) });
971
1031
  }
972
1032
  return /* @__PURE__ */ jsxs("div", { className: chat_default.body, children: [
973
- messages.map((m) => /* @__PURE__ */ jsx(MessageBubble, { message: m, onChipClick }, m.id)),
1033
+ messages.map((m) => /* @__PURE__ */ jsx(MessageBubble, { message: m, onChipClick, onFeedback }, m.id)),
974
1034
  isTyping ? /* @__PURE__ */ jsx(TypingIndicator, {}) : null,
975
1035
  error ? /* @__PURE__ */ jsx("div", { className: chat_default.errorBanner, children: error }) : null,
976
1036
  /* @__PURE__ */ jsx("div", { ref: endRef })
@@ -1132,7 +1192,8 @@ function WealthChat(props) {
1132
1192
  onLogin,
1133
1193
  onLogout,
1134
1194
  onSessionExpire,
1135
- onError
1195
+ onError,
1196
+ onFeedback
1136
1197
  } = props;
1137
1198
  const [mounted, setMounted] = useState(false);
1138
1199
  const [open, setOpen] = useState(defaultOpen);
@@ -1335,7 +1396,8 @@ function WealthChat(props) {
1335
1396
  loginUrl,
1336
1397
  error: chatState.error,
1337
1398
  onChipClick: handleChipClick,
1338
- onLoginClick: handleLoginClick
1399
+ onLoginClick: handleLoginClick,
1400
+ onFeedback
1339
1401
  }
1340
1402
  ),
1341
1403
  /* @__PURE__ */ jsx(