wealth-alpha-chat-widget 1.0.5 → 1.0.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/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,44 @@ 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 22V11" }),
936
+ /* @__PURE__ */ jsx("path", { d: "M2 13a2 2 0 0 1 2-2h3v11H4a2 2 0 0 1-2-2v-7Z" }),
937
+ /* @__PURE__ */ jsx("path", { d: "M7 11l4-9a3 3 0 0 1 3 3v4h5a2 2 0 0 1 2 2.3l-1.2 7A2 2 0 0 1 17.8 20H7" })
938
+ ] })
939
+ }
940
+ ),
941
+ /* @__PURE__ */ jsx(
942
+ "button",
943
+ {
944
+ type: "button",
945
+ className: `${chat_default.feedbackBtn} ${rating === "down" ? chat_default.feedbackBtnDown : ""}`,
946
+ "aria-label": "Not helpful",
947
+ "aria-pressed": rating === "down",
948
+ onClick: () => rate("down"),
949
+ children: /* @__PURE__ */ jsxs("svg", { className: chat_default.feedbackIcon, viewBox: "0 0 24 24", "aria-hidden": "true", style: { transform: "rotate(180deg)" }, children: [
950
+ /* @__PURE__ */ jsx("path", { d: "M7 22V11" }),
951
+ /* @__PURE__ */ jsx("path", { d: "M2 13a2 2 0 0 1 2-2h3v11H4a2 2 0 0 1-2-2v-7Z" }),
952
+ /* @__PURE__ */ jsx("path", { d: "M7 11l4-9a3 3 0 0 1 3 3v4h5a2 2 0 0 1 2 2.3l-1.2 7A2 2 0 0 1 17.8 20H7" })
953
+ ] })
954
+ }
955
+ )
956
+ ] }) : null,
957
+ isCard ? /* @__PURE__ */ jsxs("div", { className: chat_default.disclaimer, children: [
958
+ /* @__PURE__ */ jsx("b", { children: "Disclaimer:" }),
959
+ " ",
960
+ CARD_DISCLAIMER
961
+ ] }) : null,
901
962
  showMenuGrid ? /* @__PURE__ */ jsx("div", { className: chat_default.menuGrid, children: chips.map((chip) => {
902
963
  const iconKey = MENU_ICON_KEY[chip.id];
903
964
  const iconClass = iconKey && chat_default[iconKey] || "";
@@ -950,7 +1011,8 @@ function ChatBody({
950
1011
  loginUrl,
951
1012
  error,
952
1013
  onChipClick,
953
- onLoginClick
1014
+ onLoginClick,
1015
+ onFeedback
954
1016
  }) {
955
1017
  const endRef = useRef(null);
956
1018
  useEffect(() => {
@@ -970,7 +1032,7 @@ function ChatBody({
970
1032
  ) });
971
1033
  }
972
1034
  return /* @__PURE__ */ jsxs("div", { className: chat_default.body, children: [
973
- messages.map((m) => /* @__PURE__ */ jsx(MessageBubble, { message: m, onChipClick }, m.id)),
1035
+ messages.map((m) => /* @__PURE__ */ jsx(MessageBubble, { message: m, onChipClick, onFeedback }, m.id)),
974
1036
  isTyping ? /* @__PURE__ */ jsx(TypingIndicator, {}) : null,
975
1037
  error ? /* @__PURE__ */ jsx("div", { className: chat_default.errorBanner, children: error }) : null,
976
1038
  /* @__PURE__ */ jsx("div", { ref: endRef })
@@ -1132,7 +1194,8 @@ function WealthChat(props) {
1132
1194
  onLogin,
1133
1195
  onLogout,
1134
1196
  onSessionExpire,
1135
- onError
1197
+ onError,
1198
+ onFeedback
1136
1199
  } = props;
1137
1200
  const [mounted, setMounted] = useState(false);
1138
1201
  const [open, setOpen] = useState(defaultOpen);
@@ -1335,7 +1398,8 @@ function WealthChat(props) {
1335
1398
  loginUrl,
1336
1399
  error: chatState.error,
1337
1400
  onChipClick: handleChipClick,
1338
- onLoginClick: handleLoginClick
1401
+ onLoginClick: handleLoginClick,
1402
+ onFeedback
1339
1403
  }
1340
1404
  ),
1341
1405
  /* @__PURE__ */ jsx(