@wallavi/widget 1.4.3 → 1.4.5

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.js CHANGED
@@ -34,6 +34,7 @@ var ReactMarkdownLib__default = /*#__PURE__*/_interopDefault(ReactMarkdownLib);
34
34
  var remarkGfm__default = /*#__PURE__*/_interopDefault(remarkGfm);
35
35
 
36
36
  // src/bubble-widget.tsx
37
+ var cn = (...inputs) => tailwindMerge.twMerge(clsx.clsx(inputs));
37
38
 
38
39
  // src/types.ts
39
40
  function getContrastColor(hex) {
@@ -83,6 +84,10 @@ function useChat({
83
84
  playgroundOverrides
84
85
  }) {
85
86
  const persistKey = persist ? `wallavi_${agentId}` : null;
87
+ const onNavigateRef = react.useRef(onNavigate);
88
+ react.useEffect(() => {
89
+ onNavigateRef.current = onNavigate;
90
+ });
86
91
  const [messages, setMessages] = react.useState(() => {
87
92
  if (!persistKey || typeof window === "undefined") return [];
88
93
  try {
@@ -185,7 +190,7 @@ function useChat({
185
190
  if (!res.body) throw new Error("No stream body");
186
191
  const applyEvent = (proto) => {
187
192
  if (proto.type === "navigate") {
188
- if (proto.path.startsWith("/")) onNavigate?.(proto.path);
193
+ if (proto.path.startsWith("/")) onNavigateRef.current?.(proto.path);
189
194
  return;
190
195
  }
191
196
  setMessages((prev) => {
@@ -401,7 +406,6 @@ function ChatHeader({
401
406
  var Avatar2 = ({ style, ...p }) => /* @__PURE__ */ jsxRuntime.jsx(AvatarPrimitive__namespace.Root, { style: { position: "relative", display: "flex", flexShrink: 0, overflow: "hidden", borderRadius: "9999px", ...style }, ...p });
402
407
  var AvatarImage2 = ({ style, ...p }) => /* @__PURE__ */ jsxRuntime.jsx(AvatarPrimitive__namespace.Image, { style: { position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", ...style }, ...p });
403
408
  var AvatarFallback2 = ({ style, ...p }) => /* @__PURE__ */ jsxRuntime.jsx(AvatarPrimitive__namespace.Fallback, { style: { display: "flex", width: "100%", height: "100%", alignItems: "center", justifyContent: "center", borderRadius: "9999px", ...style }, ...p });
404
- var cn = (...inputs) => tailwindMerge.twMerge(clsx.clsx(inputs));
405
409
  var ReactMarkdown = ReactMarkdownLib__default.default;
406
410
  function ThinkingDots() {
407
411
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
@@ -655,7 +659,6 @@ function ChatInput({
655
659
  ] })
656
660
  ] });
657
661
  }
658
- var cn3 = (...inputs) => tailwindMerge.twMerge(clsx.clsx(inputs));
659
662
  function ChatWidget({
660
663
  agentId,
661
664
  workspaceId,
@@ -696,7 +699,7 @@ function ChatWidget({
696
699
  return /* @__PURE__ */ jsxRuntime.jsxs(
697
700
  "div",
698
701
  {
699
- className: cn3(
702
+ className: cn(
700
703
  "flex flex-col overflow-hidden rounded-2xl border shadow-xl bg-background h-full",
701
704
  className
702
705
  ),
@@ -825,7 +828,6 @@ function useAutoConfig(agentId, enabled) {
825
828
  }, [agentId, enabled]);
826
829
  return result;
827
830
  }
828
- var cn4 = (...inputs) => tailwindMerge.twMerge(clsx.clsx(inputs));
829
831
  var KEY_EXPANDED = "wallavi_bubble_expanded";
830
832
  var KEY_DISMISSED = "wallavi_bubble_dismissed";
831
833
  function BubbleWidget({
@@ -873,35 +875,13 @@ function BubbleWidget({
873
875
  if (localStorage.getItem(KEY_EXPANDED) === "true") setExpanded(true);
874
876
  }, []);
875
877
  const remote = useAutoConfig(chatProps.agentId, autoConfig);
876
- const [resolvedBubbleIcon, setResolvedBubbleIcon] = react.useState(bubbleIconUrlProp);
877
- const [resolvedAutoOpen, setResolvedAutoOpen] = react.useState(autoOpenProp);
878
- const [resolvedKeyboardShortcut, setResolvedKeyboardShortcut] = react.useState(keyboardShortcutProp);
879
- const [resolvedPosition, setResolvedPosition] = react.useState(positionProp ?? "bottom-right");
880
- const [resolvedBubbleSize, setResolvedBubbleSize] = react.useState(bubbleSizeProp ?? 52);
881
- const [resolvedWidth, setResolvedWidth] = react.useState(widthProp ?? 360);
882
- const [resolvedHeight, setResolvedHeight] = react.useState(heightProp ?? 580);
883
- react.useEffect(() => {
884
- if (remote.loading) return;
885
- if (!bubbleIconUrlProp) setResolvedBubbleIcon(remote.bubbleIconUrl);
886
- if (!autoOpenProp) setResolvedAutoOpen(remote.autoOpen);
887
- if (!keyboardShortcutProp) setResolvedKeyboardShortcut(remote.keyboardShortcut);
888
- if (!positionProp) setResolvedPosition(remote.position);
889
- if (bubbleSizeProp == null) setResolvedBubbleSize(remote.bubbleSize);
890
- if (widthProp == null) setResolvedWidth(remote.panelWidth);
891
- if (heightProp == null) setResolvedHeight(remote.panelHeight);
892
- }, [remote.loading]);
893
- react.useEffect(() => {
894
- if (autoOpenProp) setResolvedAutoOpen(true);
895
- }, [autoOpenProp]);
896
- react.useEffect(() => {
897
- if (keyboardShortcutProp) setResolvedKeyboardShortcut(true);
898
- }, [keyboardShortcutProp]);
899
- react.useEffect(() => {
900
- if (bubbleIconUrlProp) setResolvedBubbleIcon(bubbleIconUrlProp);
901
- }, [bubbleIconUrlProp]);
902
- react.useEffect(() => {
903
- if (positionProp) setResolvedPosition(positionProp);
904
- }, [positionProp]);
878
+ const resolvedPosition = positionProp ?? remote.position;
879
+ const resolvedBubbleIcon = bubbleIconUrlProp ?? remote.bubbleIconUrl;
880
+ const resolvedAutoOpen = autoOpenProp || remote.autoOpen;
881
+ const resolvedKeyboardShortcut = keyboardShortcutProp || remote.keyboardShortcut;
882
+ const resolvedBubbleSize = bubbleSizeProp ?? remote.bubbleSize;
883
+ const resolvedWidth = widthProp ?? remote.panelWidth;
884
+ const resolvedHeight = heightProp ?? remote.panelHeight;
905
885
  const definedChatProps = Object.fromEntries(
906
886
  Object.entries(chatProps).filter(([, v]) => v !== void 0)
907
887
  );
@@ -911,12 +891,16 @@ function BubbleWidget({
911
891
  agentId: chatProps.agentId,
912
892
  agentName: chatProps.agentName
913
893
  };
894
+ const setOpenRef = react.useRef(setOpen);
895
+ react.useEffect(() => {
896
+ setOpenRef.current = setOpen;
897
+ });
914
898
  react.useEffect(() => {
915
899
  if (!resolvedAutoOpen || autoOpenedRef.current) return;
916
900
  const dismissedUntil = Number(localStorage.getItem(KEY_DISMISSED) ?? 0);
917
901
  if (dismissedUntil < Date.now()) {
918
902
  autoOpenedRef.current = true;
919
- setOpen(true);
903
+ setOpenRef.current(true);
920
904
  }
921
905
  }, [resolvedAutoOpen]);
922
906
  react.useEffect(() => {
@@ -924,7 +908,7 @@ function BubbleWidget({
924
908
  const onKey = (e) => {
925
909
  if ((e.metaKey || e.ctrlKey) && e.key === shortcutKey) {
926
910
  e.preventDefault();
927
- setOpen((v) => !v);
911
+ setOpenRef.current((v) => !v);
928
912
  }
929
913
  };
930
914
  window.addEventListener("keydown", onKey);
@@ -984,7 +968,7 @@ function BubbleWidget({
984
968
  onClose: handleClose,
985
969
  onExpand: toggleExpanded,
986
970
  expanded,
987
- className: cn4("shadow-2xl h-full", panelClassName)
971
+ className: cn("shadow-2xl h-full", panelClassName)
988
972
  }
989
973
  )
990
974
  }
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { useState, useRef, useEffect, useCallback } from 'react';
1
+ import { useRef, useEffect, useState, useCallback } from 'react';
2
2
  import { X, RotateCcw, Loader2, ArrowUp, Zap, ChevronDown, CheckCircle2, AlertCircle } from 'lucide-react';
3
3
  import { clsx } from 'clsx';
4
4
  import { twMerge } from 'tailwind-merge';
@@ -8,6 +8,7 @@ import ReactMarkdownLib from 'react-markdown';
8
8
  import remarkGfm from 'remark-gfm';
9
9
 
10
10
  // src/bubble-widget.tsx
11
+ var cn = (...inputs) => twMerge(clsx(inputs));
11
12
 
12
13
  // src/types.ts
13
14
  function getContrastColor(hex) {
@@ -57,6 +58,10 @@ function useChat({
57
58
  playgroundOverrides
58
59
  }) {
59
60
  const persistKey = persist ? `wallavi_${agentId}` : null;
61
+ const onNavigateRef = useRef(onNavigate);
62
+ useEffect(() => {
63
+ onNavigateRef.current = onNavigate;
64
+ });
60
65
  const [messages, setMessages] = useState(() => {
61
66
  if (!persistKey || typeof window === "undefined") return [];
62
67
  try {
@@ -159,7 +164,7 @@ function useChat({
159
164
  if (!res.body) throw new Error("No stream body");
160
165
  const applyEvent = (proto) => {
161
166
  if (proto.type === "navigate") {
162
- if (proto.path.startsWith("/")) onNavigate?.(proto.path);
167
+ if (proto.path.startsWith("/")) onNavigateRef.current?.(proto.path);
163
168
  return;
164
169
  }
165
170
  setMessages((prev) => {
@@ -375,7 +380,6 @@ function ChatHeader({
375
380
  var Avatar2 = ({ style, ...p }) => /* @__PURE__ */ jsx(AvatarPrimitive.Root, { style: { position: "relative", display: "flex", flexShrink: 0, overflow: "hidden", borderRadius: "9999px", ...style }, ...p });
376
381
  var AvatarImage2 = ({ style, ...p }) => /* @__PURE__ */ jsx(AvatarPrimitive.Image, { style: { position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", ...style }, ...p });
377
382
  var AvatarFallback2 = ({ style, ...p }) => /* @__PURE__ */ jsx(AvatarPrimitive.Fallback, { style: { display: "flex", width: "100%", height: "100%", alignItems: "center", justifyContent: "center", borderRadius: "9999px", ...style }, ...p });
378
- var cn = (...inputs) => twMerge(clsx(inputs));
379
383
  var ReactMarkdown = ReactMarkdownLib;
380
384
  function ThinkingDots() {
381
385
  return /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -629,7 +633,6 @@ function ChatInput({
629
633
  ] })
630
634
  ] });
631
635
  }
632
- var cn3 = (...inputs) => twMerge(clsx(inputs));
633
636
  function ChatWidget({
634
637
  agentId,
635
638
  workspaceId,
@@ -670,7 +673,7 @@ function ChatWidget({
670
673
  return /* @__PURE__ */ jsxs(
671
674
  "div",
672
675
  {
673
- className: cn3(
676
+ className: cn(
674
677
  "flex flex-col overflow-hidden rounded-2xl border shadow-xl bg-background h-full",
675
678
  className
676
679
  ),
@@ -799,7 +802,6 @@ function useAutoConfig(agentId, enabled) {
799
802
  }, [agentId, enabled]);
800
803
  return result;
801
804
  }
802
- var cn4 = (...inputs) => twMerge(clsx(inputs));
803
805
  var KEY_EXPANDED = "wallavi_bubble_expanded";
804
806
  var KEY_DISMISSED = "wallavi_bubble_dismissed";
805
807
  function BubbleWidget({
@@ -847,35 +849,13 @@ function BubbleWidget({
847
849
  if (localStorage.getItem(KEY_EXPANDED) === "true") setExpanded(true);
848
850
  }, []);
849
851
  const remote = useAutoConfig(chatProps.agentId, autoConfig);
850
- const [resolvedBubbleIcon, setResolvedBubbleIcon] = useState(bubbleIconUrlProp);
851
- const [resolvedAutoOpen, setResolvedAutoOpen] = useState(autoOpenProp);
852
- const [resolvedKeyboardShortcut, setResolvedKeyboardShortcut] = useState(keyboardShortcutProp);
853
- const [resolvedPosition, setResolvedPosition] = useState(positionProp ?? "bottom-right");
854
- const [resolvedBubbleSize, setResolvedBubbleSize] = useState(bubbleSizeProp ?? 52);
855
- const [resolvedWidth, setResolvedWidth] = useState(widthProp ?? 360);
856
- const [resolvedHeight, setResolvedHeight] = useState(heightProp ?? 580);
857
- useEffect(() => {
858
- if (remote.loading) return;
859
- if (!bubbleIconUrlProp) setResolvedBubbleIcon(remote.bubbleIconUrl);
860
- if (!autoOpenProp) setResolvedAutoOpen(remote.autoOpen);
861
- if (!keyboardShortcutProp) setResolvedKeyboardShortcut(remote.keyboardShortcut);
862
- if (!positionProp) setResolvedPosition(remote.position);
863
- if (bubbleSizeProp == null) setResolvedBubbleSize(remote.bubbleSize);
864
- if (widthProp == null) setResolvedWidth(remote.panelWidth);
865
- if (heightProp == null) setResolvedHeight(remote.panelHeight);
866
- }, [remote.loading]);
867
- useEffect(() => {
868
- if (autoOpenProp) setResolvedAutoOpen(true);
869
- }, [autoOpenProp]);
870
- useEffect(() => {
871
- if (keyboardShortcutProp) setResolvedKeyboardShortcut(true);
872
- }, [keyboardShortcutProp]);
873
- useEffect(() => {
874
- if (bubbleIconUrlProp) setResolvedBubbleIcon(bubbleIconUrlProp);
875
- }, [bubbleIconUrlProp]);
876
- useEffect(() => {
877
- if (positionProp) setResolvedPosition(positionProp);
878
- }, [positionProp]);
852
+ const resolvedPosition = positionProp ?? remote.position;
853
+ const resolvedBubbleIcon = bubbleIconUrlProp ?? remote.bubbleIconUrl;
854
+ const resolvedAutoOpen = autoOpenProp || remote.autoOpen;
855
+ const resolvedKeyboardShortcut = keyboardShortcutProp || remote.keyboardShortcut;
856
+ const resolvedBubbleSize = bubbleSizeProp ?? remote.bubbleSize;
857
+ const resolvedWidth = widthProp ?? remote.panelWidth;
858
+ const resolvedHeight = heightProp ?? remote.panelHeight;
879
859
  const definedChatProps = Object.fromEntries(
880
860
  Object.entries(chatProps).filter(([, v]) => v !== void 0)
881
861
  );
@@ -885,12 +865,16 @@ function BubbleWidget({
885
865
  agentId: chatProps.agentId,
886
866
  agentName: chatProps.agentName
887
867
  };
868
+ const setOpenRef = useRef(setOpen);
869
+ useEffect(() => {
870
+ setOpenRef.current = setOpen;
871
+ });
888
872
  useEffect(() => {
889
873
  if (!resolvedAutoOpen || autoOpenedRef.current) return;
890
874
  const dismissedUntil = Number(localStorage.getItem(KEY_DISMISSED) ?? 0);
891
875
  if (dismissedUntil < Date.now()) {
892
876
  autoOpenedRef.current = true;
893
- setOpen(true);
877
+ setOpenRef.current(true);
894
878
  }
895
879
  }, [resolvedAutoOpen]);
896
880
  useEffect(() => {
@@ -898,7 +882,7 @@ function BubbleWidget({
898
882
  const onKey = (e) => {
899
883
  if ((e.metaKey || e.ctrlKey) && e.key === shortcutKey) {
900
884
  e.preventDefault();
901
- setOpen((v) => !v);
885
+ setOpenRef.current((v) => !v);
902
886
  }
903
887
  };
904
888
  window.addEventListener("keydown", onKey);
@@ -958,7 +942,7 @@ function BubbleWidget({
958
942
  onClose: handleClose,
959
943
  onExpand: toggleExpanded,
960
944
  expanded,
961
- className: cn4("shadow-2xl h-full", panelClassName)
945
+ className: cn("shadow-2xl h-full", panelClassName)
962
946
  }
963
947
  )
964
948
  }
package/package.json CHANGED
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "private": false,
35
35
  "types": "./dist/index.d.ts",
36
- "version": "1.4.3",
36
+ "version": "1.4.5",
37
37
  "scripts": {
38
38
  "build": "tsup",
39
39
  "typecheck": "tsc --noEmit"