@wallavi/widget 1.4.4 → 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 +20 -40
- package/dist/index.mjs +21 -41
- package/package.json +1 -1
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("/"))
|
|
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:
|
|
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
|
|
877
|
-
const
|
|
878
|
-
const
|
|
879
|
-
const
|
|
880
|
-
const
|
|
881
|
-
const
|
|
882
|
-
const
|
|
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,18 +891,18 @@ 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
|
-
|
|
903
|
+
setOpenRef.current(true);
|
|
920
904
|
}
|
|
921
905
|
}, [resolvedAutoOpen]);
|
|
922
|
-
const setOpenRef = react.useRef(setOpen);
|
|
923
|
-
react.useEffect(() => {
|
|
924
|
-
setOpenRef.current = setOpen;
|
|
925
|
-
});
|
|
926
906
|
react.useEffect(() => {
|
|
927
907
|
if (!resolvedKeyboardShortcut) return;
|
|
928
908
|
const onKey = (e) => {
|
|
@@ -988,7 +968,7 @@ function BubbleWidget({
|
|
|
988
968
|
onClose: handleClose,
|
|
989
969
|
onExpand: toggleExpanded,
|
|
990
970
|
expanded,
|
|
991
|
-
className:
|
|
971
|
+
className: cn("shadow-2xl h-full", panelClassName)
|
|
992
972
|
}
|
|
993
973
|
)
|
|
994
974
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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("/"))
|
|
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:
|
|
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
|
|
851
|
-
const
|
|
852
|
-
const
|
|
853
|
-
const
|
|
854
|
-
const
|
|
855
|
-
const
|
|
856
|
-
const
|
|
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,18 +865,18 @@ 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
|
-
|
|
877
|
+
setOpenRef.current(true);
|
|
894
878
|
}
|
|
895
879
|
}, [resolvedAutoOpen]);
|
|
896
|
-
const setOpenRef = useRef(setOpen);
|
|
897
|
-
useEffect(() => {
|
|
898
|
-
setOpenRef.current = setOpen;
|
|
899
|
-
});
|
|
900
880
|
useEffect(() => {
|
|
901
881
|
if (!resolvedKeyboardShortcut) return;
|
|
902
882
|
const onKey = (e) => {
|
|
@@ -962,7 +942,7 @@ function BubbleWidget({
|
|
|
962
942
|
onClose: handleClose,
|
|
963
943
|
onExpand: toggleExpanded,
|
|
964
944
|
expanded,
|
|
965
|
-
className:
|
|
945
|
+
className: cn("shadow-2xl h-full", panelClassName)
|
|
966
946
|
}
|
|
967
947
|
)
|
|
968
948
|
}
|