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.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,44 @@ 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 22V11" }),
942
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M2 13a2 2 0 0 1 2-2h3v11H4a2 2 0 0 1-2-2v-7Z" }),
943
+ /* @__PURE__ */ jsxRuntime.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" })
944
+ ] })
945
+ }
946
+ ),
947
+ /* @__PURE__ */ jsxRuntime.jsx(
948
+ "button",
949
+ {
950
+ type: "button",
951
+ className: `${chat_default.feedbackBtn} ${rating === "down" ? chat_default.feedbackBtnDown : ""}`,
952
+ "aria-label": "Not helpful",
953
+ "aria-pressed": rating === "down",
954
+ onClick: () => rate("down"),
955
+ children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { className: chat_default.feedbackIcon, viewBox: "0 0 24 24", "aria-hidden": "true", style: { transform: "rotate(180deg)" }, children: [
956
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M7 22V11" }),
957
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M2 13a2 2 0 0 1 2-2h3v11H4a2 2 0 0 1-2-2v-7Z" }),
958
+ /* @__PURE__ */ jsxRuntime.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" })
959
+ ] })
960
+ }
961
+ )
962
+ ] }) : null,
963
+ isCard ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: chat_default.disclaimer, children: [
964
+ /* @__PURE__ */ jsxRuntime.jsx("b", { children: "Disclaimer:" }),
965
+ " ",
966
+ CARD_DISCLAIMER
967
+ ] }) : null,
907
968
  showMenuGrid ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: chat_default.menuGrid, children: chips.map((chip) => {
908
969
  const iconKey = MENU_ICON_KEY[chip.id];
909
970
  const iconClass = iconKey && chat_default[iconKey] || "";
@@ -956,7 +1017,8 @@ function ChatBody({
956
1017
  loginUrl,
957
1018
  error,
958
1019
  onChipClick,
959
- onLoginClick
1020
+ onLoginClick,
1021
+ onFeedback
960
1022
  }) {
961
1023
  const endRef = react.useRef(null);
962
1024
  react.useEffect(() => {
@@ -976,7 +1038,7 @@ function ChatBody({
976
1038
  ) });
977
1039
  }
978
1040
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: chat_default.body, children: [
979
- messages.map((m) => /* @__PURE__ */ jsxRuntime.jsx(MessageBubble, { message: m, onChipClick }, m.id)),
1041
+ messages.map((m) => /* @__PURE__ */ jsxRuntime.jsx(MessageBubble, { message: m, onChipClick, onFeedback }, m.id)),
980
1042
  isTyping ? /* @__PURE__ */ jsxRuntime.jsx(TypingIndicator, {}) : null,
981
1043
  error ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: chat_default.errorBanner, children: error }) : null,
982
1044
  /* @__PURE__ */ jsxRuntime.jsx("div", { ref: endRef })
@@ -1138,7 +1200,8 @@ function WealthChat(props) {
1138
1200
  onLogin,
1139
1201
  onLogout,
1140
1202
  onSessionExpire,
1141
- onError
1203
+ onError,
1204
+ onFeedback
1142
1205
  } = props;
1143
1206
  const [mounted, setMounted] = react.useState(false);
1144
1207
  const [open, setOpen] = react.useState(defaultOpen);
@@ -1341,7 +1404,8 @@ function WealthChat(props) {
1341
1404
  loginUrl,
1342
1405
  error: chatState.error,
1343
1406
  onChipClick: handleChipClick,
1344
- onLoginClick: handleLoginClick
1407
+ onLoginClick: handleLoginClick,
1408
+ onFeedback
1345
1409
  }
1346
1410
  ),
1347
1411
  /* @__PURE__ */ jsxRuntime.jsx(