vpschatbotwidget 1.0.0
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/Chatbot.svg +1 -0
- package/README.md +86 -0
- package/dist/assets/index-C0fUDi2s.css +1 -0
- package/dist/assets/index-foGq5_Av.js +159 -0
- package/dist/index.html +17 -0
- package/index.html +16 -0
- package/package.json +47 -0
- package/src/App.tsx +85 -0
- package/src/chatbot/api/chatbot-api.ts +258 -0
- package/src/chatbot/api/chatbot-types.ts +145 -0
- package/src/chatbot/chatbot.test.tsx +274 -0
- package/src/chatbot/config/colors.ts +166 -0
- package/src/chatbot/config/suggestions.ts +21 -0
- package/src/chatbot/core/ChatContext.tsx +43 -0
- package/src/chatbot/core/ChatEmptyState.tsx +21 -0
- package/src/chatbot/core/ChatError.tsx +26 -0
- package/src/chatbot/core/ChatHeader.tsx +108 -0
- package/src/chatbot/core/ChatInput.tsx +103 -0
- package/src/chatbot/core/ChatMarkdown.tsx +87 -0
- package/src/chatbot/core/ChatMessage.tsx +115 -0
- package/src/chatbot/core/ChatMessageList.tsx +47 -0
- package/src/chatbot/core/ChatPanel.tsx +66 -0
- package/src/chatbot/core/ChatProvider.tsx +185 -0
- package/src/chatbot/core/ChatSuggestions.tsx +71 -0
- package/src/chatbot/core/ChatTicketConfirmation.tsx +59 -0
- package/src/chatbot/core/ChatTypingIndicator.tsx +16 -0
- package/src/chatbot/core/ticket-intent.ts +12 -0
- package/src/chatbot/embedded/EmbeddedChatbot.tsx +47 -0
- package/src/chatbot/embedded/EmbeddedChatbotPanel.tsx +56 -0
- package/src/chatbot/embedded/EmbeddedChatbotTrigger.tsx +167 -0
- package/src/chatbot/hooks/useChatbot.ts +5 -0
- package/src/chatbot/index.ts +7 -0
- package/src/chatbot/widget/ChatbotWidget.tsx +43 -0
- package/src/chatbot/widget/ChatbotWidgetPanel.tsx +39 -0
- package/src/chatbot/widget/ChatbotWidgetTrigger.tsx +32 -0
- package/src/components/AgentSummaryCard.tsx +37 -0
- package/src/components/ChatHeader.tsx +142 -0
- package/src/components/ChatInput.tsx +123 -0
- package/src/components/ChatWidget.tsx +295 -0
- package/src/components/ConnectingStatus.tsx +16 -0
- package/src/components/EnvBadge.tsx +103 -0
- package/src/components/FeedbackRatingCard.tsx +123 -0
- package/src/components/MessageItem.tsx +157 -0
- package/src/components/MessageList.tsx +143 -0
- package/src/components/OrderTrackingCard.tsx +104 -0
- package/src/components/QuickPrompts.tsx +46 -0
- package/src/components/ResponseIconMapper.tsx +155 -0
- package/src/components/SourceCitations.tsx +46 -0
- package/src/components/ToolCallBadge.tsx +29 -0
- package/src/components/TypingProgressBar.tsx +113 -0
- package/src/components/ui/message-scroller.tsx +128 -0
- package/src/index.css +550 -0
- package/src/lib/cn.ts +5 -0
- package/src/lib/gibberishDetector.ts +159 -0
- package/src/lib/textHighlighter.tsx +206 -0
- package/src/main.tsx +10 -0
- package/src/services/api.ts +74 -0
- package/src/test/message-scroller-stub.tsx +60 -0
- package/src/test/setup.ts +8 -0
- package/src/types/chat.ts +66 -0
- package/src/vite-env.d.ts +14 -0
- package/tsconfig.json +21 -0
- package/vite.config.ts +28 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypingProgressBar.tsx
|
|
3
|
+
*
|
|
4
|
+
* A slim, bottom-anchored animated progress strip that is shown while the
|
|
5
|
+
* AI is generating a response. It cycles through contextual phase labels
|
|
6
|
+
* with a fade-in → hold → fade-out rhythm so the user always knows the
|
|
7
|
+
* system is actively working.
|
|
8
|
+
*
|
|
9
|
+
* Features
|
|
10
|
+
* ─────────
|
|
11
|
+
* • Smooth shimmer fill bar (CSS animation)
|
|
12
|
+
* • Rotating phase labels that fade in/out every 2.2 s
|
|
13
|
+
* • Dynamic icon from lucide-react that matches the current phase
|
|
14
|
+
* • Mounts with a slide-up animation, unmounts with slide-down
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import React, { useState, useEffect, useRef } from "react";
|
|
18
|
+
import {
|
|
19
|
+
Search,
|
|
20
|
+
Database,
|
|
21
|
+
Brain,
|
|
22
|
+
FileText,
|
|
23
|
+
CheckCircle2,
|
|
24
|
+
Loader2,
|
|
25
|
+
Zap,
|
|
26
|
+
} from "lucide-react";
|
|
27
|
+
|
|
28
|
+
// ── Phase definitions ──────────────────────────────────────────────────────────
|
|
29
|
+
interface Phase {
|
|
30
|
+
label: string;
|
|
31
|
+
Icon: React.ElementType;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const PHASES: Phase[] = [
|
|
35
|
+
{ label: "Searching knowledge base…", Icon: Search },
|
|
36
|
+
{ label: "Querying database…", Icon: Database },
|
|
37
|
+
{ label: "Analysing your request…", Icon: Brain },
|
|
38
|
+
{ label: "Composing response…", Icon: FileText },
|
|
39
|
+
{ label: "Verifying information…", Icon: CheckCircle2 },
|
|
40
|
+
{ label: "Almost there…", Icon: Zap },
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const PHASE_DURATION_MS = 2200;
|
|
44
|
+
|
|
45
|
+
interface TypingProgressBarProps {
|
|
46
|
+
isVisible: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const TypingProgressBar: React.FC<TypingProgressBarProps> = ({
|
|
50
|
+
isVisible,
|
|
51
|
+
}) => {
|
|
52
|
+
const [phaseIdx, setPhaseIdx] = useState(0);
|
|
53
|
+
const [textVisible, setTextVisible] = useState(true); // drives fade in/out
|
|
54
|
+
const [mounted, setMounted] = useState(false); // drives slide-up/down
|
|
55
|
+
const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
|
56
|
+
const fadeRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
57
|
+
|
|
58
|
+
// Slide-up on show, slide-down on hide
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (isVisible) {
|
|
61
|
+
setMounted(true);
|
|
62
|
+
setPhaseIdx(0);
|
|
63
|
+
setTextVisible(true);
|
|
64
|
+
} else {
|
|
65
|
+
// let the slide-down animation play before unmounting
|
|
66
|
+
const t = setTimeout(() => setMounted(false), 400);
|
|
67
|
+
return () => clearTimeout(t);
|
|
68
|
+
}
|
|
69
|
+
}, [isVisible]);
|
|
70
|
+
|
|
71
|
+
// Cycle phases with fade-in/out
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (!isVisible) {
|
|
74
|
+
if (intervalRef.current) clearInterval(intervalRef.current);
|
|
75
|
+
if (fadeRef.current) clearTimeout(fadeRef.current);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
intervalRef.current = setInterval(() => {
|
|
80
|
+
// fade out → wait → swap text → fade in
|
|
81
|
+
setTextVisible(false);
|
|
82
|
+
fadeRef.current = setTimeout(() => {
|
|
83
|
+
setPhaseIdx((prev) => (prev + 1) % PHASES.length);
|
|
84
|
+
setTextVisible(true);
|
|
85
|
+
}, 350); // half of fade transition
|
|
86
|
+
}, PHASE_DURATION_MS);
|
|
87
|
+
|
|
88
|
+
return () => {
|
|
89
|
+
if (intervalRef.current) clearInterval(intervalRef.current);
|
|
90
|
+
if (fadeRef.current) clearTimeout(fadeRef.current);
|
|
91
|
+
};
|
|
92
|
+
}, [isVisible]);
|
|
93
|
+
|
|
94
|
+
if (!mounted) return null;
|
|
95
|
+
|
|
96
|
+
const { label, Icon } = PHASES[phaseIdx];
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<div className={`typing-progress-bar-root ${isVisible ? "tpb-enter" : "tpb-exit"}`}>
|
|
100
|
+
{/* Shimmer fill track */}
|
|
101
|
+
<div className="tpb-shimmer-track">
|
|
102
|
+
<div className="tpb-shimmer-fill" />
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
{/* Phase label row */}
|
|
106
|
+
<div className={`tpb-label-row ${textVisible ? "tpb-label-in" : "tpb-label-out"}`}>
|
|
107
|
+
<Loader2 size={12} className="tpb-spinner-icon" />
|
|
108
|
+
<Icon size={13} className="tpb-phase-icon" />
|
|
109
|
+
<span className="tpb-phase-text">{label}</span>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
);
|
|
113
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ArrowDown } from "lucide-react";
|
|
3
|
+
import {
|
|
4
|
+
MessageScroller as MessageScrollerPrimitive,
|
|
5
|
+
useMessageScroller,
|
|
6
|
+
useMessageScrollerScrollable,
|
|
7
|
+
useMessageScrollerVisibility,
|
|
8
|
+
} from "@shadcn/react/message-scroller";
|
|
9
|
+
import { cn } from "../../lib/cn";
|
|
10
|
+
|
|
11
|
+
function MessageScrollerProvider(
|
|
12
|
+
props: React.ComponentProps<typeof MessageScrollerPrimitive.Provider>
|
|
13
|
+
) {
|
|
14
|
+
return <MessageScrollerPrimitive.Provider {...props} />;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function MessageScroller({
|
|
18
|
+
className,
|
|
19
|
+
...props
|
|
20
|
+
}: React.ComponentProps<typeof MessageScrollerPrimitive.Root>) {
|
|
21
|
+
return (
|
|
22
|
+
<MessageScrollerPrimitive.Root
|
|
23
|
+
data-slot="message-scroller"
|
|
24
|
+
className={cn(
|
|
25
|
+
"group/message-scroller relative flex size-full min-h-0 flex-col overflow-hidden",
|
|
26
|
+
className
|
|
27
|
+
)}
|
|
28
|
+
{...props}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function MessageScrollerViewport({
|
|
34
|
+
className,
|
|
35
|
+
...props
|
|
36
|
+
}: React.ComponentProps<typeof MessageScrollerPrimitive.Viewport>) {
|
|
37
|
+
return (
|
|
38
|
+
<MessageScrollerPrimitive.Viewport
|
|
39
|
+
data-slot="message-scroller-viewport"
|
|
40
|
+
className={cn(
|
|
41
|
+
"size-full min-h-0 min-w-0 overflow-y-auto overscroll-contain",
|
|
42
|
+
"data-[pending-scroll]:invisible",
|
|
43
|
+
className
|
|
44
|
+
)}
|
|
45
|
+
{...props}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function MessageScrollerContent({
|
|
51
|
+
className,
|
|
52
|
+
...props
|
|
53
|
+
}: React.ComponentProps<typeof MessageScrollerPrimitive.Content>) {
|
|
54
|
+
return (
|
|
55
|
+
<MessageScrollerPrimitive.Content
|
|
56
|
+
data-slot="message-scroller-content"
|
|
57
|
+
className={cn("flex h-max min-h-full flex-col gap-4 px-4 py-4", className)}
|
|
58
|
+
{...props}
|
|
59
|
+
/>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function MessageScrollerItem({
|
|
64
|
+
className,
|
|
65
|
+
scrollAnchor = false,
|
|
66
|
+
...props
|
|
67
|
+
}: React.ComponentProps<typeof MessageScrollerPrimitive.Item>) {
|
|
68
|
+
return (
|
|
69
|
+
<MessageScrollerPrimitive.Item
|
|
70
|
+
data-slot="message-scroller-item"
|
|
71
|
+
scrollAnchor={scrollAnchor}
|
|
72
|
+
className={cn(
|
|
73
|
+
"min-w-0 shrink-0 [contain-intrinsic-size:auto_10rem] [content-visibility:auto]",
|
|
74
|
+
className
|
|
75
|
+
)}
|
|
76
|
+
{...props}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function MessageScrollerButton({
|
|
82
|
+
direction = "end",
|
|
83
|
+
className,
|
|
84
|
+
children,
|
|
85
|
+
...props
|
|
86
|
+
}: React.ComponentProps<typeof MessageScrollerPrimitive.Button>) {
|
|
87
|
+
return (
|
|
88
|
+
<MessageScrollerPrimitive.Button
|
|
89
|
+
data-slot="message-scroller-button"
|
|
90
|
+
direction={direction}
|
|
91
|
+
className={cn(
|
|
92
|
+
"absolute left-1/2 z-10 flex h-9 w-9 -translate-x-1/2 items-center justify-center rounded-full border border-border bg-card text-foreground shadow-md transition-[opacity,transform] duration-200",
|
|
93
|
+
"hover:bg-[var(--input-bg)]",
|
|
94
|
+
"data-[active=false]:pointer-events-none data-[active=false]:scale-95 data-[active=false]:opacity-0",
|
|
95
|
+
"data-[active=true]:scale-100 data-[active=true]:opacity-100",
|
|
96
|
+
"data-[direction=end]:bottom-3 data-[direction=start]:top-3",
|
|
97
|
+
"motion-reduce:transition-none",
|
|
98
|
+
className
|
|
99
|
+
)}
|
|
100
|
+
{...props}
|
|
101
|
+
>
|
|
102
|
+
{children ?? (
|
|
103
|
+
<>
|
|
104
|
+
<ArrowDown
|
|
105
|
+
size={16}
|
|
106
|
+
aria-hidden="true"
|
|
107
|
+
className={direction === "start" ? "rotate-180" : undefined}
|
|
108
|
+
/>
|
|
109
|
+
<span className="sr-only">
|
|
110
|
+
{direction === "end" ? "Jump to latest" : "Jump to start"}
|
|
111
|
+
</span>
|
|
112
|
+
</>
|
|
113
|
+
)}
|
|
114
|
+
</MessageScrollerPrimitive.Button>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export {
|
|
119
|
+
MessageScrollerProvider,
|
|
120
|
+
MessageScroller,
|
|
121
|
+
MessageScrollerViewport,
|
|
122
|
+
MessageScrollerContent,
|
|
123
|
+
MessageScrollerItem,
|
|
124
|
+
MessageScrollerButton,
|
|
125
|
+
useMessageScroller,
|
|
126
|
+
useMessageScrollerScrollable,
|
|
127
|
+
useMessageScrollerVisibility,
|
|
128
|
+
};
|