vpschatbotwidget 1.0.2 → 1.1.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/dist-lib/types/App.d.ts +1 -0
- package/dist-lib/types/chatbot/api/chatbot-api.d.ts +10 -2
- package/dist-lib/types/chatbot/api/chatbot-types.d.ts +21 -0
- package/dist-lib/types/chatbot/core/AgentReasoning.d.ts +9 -0
- package/dist-lib/types/chatbot/core/ChatContext.d.ts +2 -0
- package/dist-lib/types/chatbot/core/ChatMarkdown.d.ts +2 -2
- package/dist-lib/types/chatbot/core/ChatProvider.d.ts +13 -1
- package/dist-lib/types/chatbot/core/ChatTypingIndicator.d.ts +1 -0
- package/dist-lib/types/chatbot/core/GroundedSources.d.ts +14 -0
- package/dist-lib/types/chatbot/embedded/EmbeddedChatbot.d.ts +13 -1
- package/dist-lib/types/chatbot/index.d.ts +1 -1
- package/dist-lib/types/chatbot/widget/ChatbotWidget.d.ts +13 -1
- package/dist-lib/vps-chatbot.cjs +32 -28
- package/dist-lib/vps-chatbot.js +1262 -1085
- package/package.json +2 -2
- package/src/chatbot/api/chatbot-api.ts +105 -3
- package/src/chatbot/api/chatbot-types.ts +23 -0
- package/src/chatbot/core/AgentReasoning.tsx +60 -0
- package/src/chatbot/core/ChatContext.tsx +2 -0
- package/src/chatbot/core/ChatEmptyState.tsx +4 -4
- package/src/chatbot/core/ChatError.tsx +2 -2
- package/src/chatbot/core/ChatHeader.tsx +13 -13
- package/src/chatbot/core/ChatInput.tsx +6 -6
- package/src/chatbot/core/ChatMarkdown.tsx +280 -55
- package/src/chatbot/core/ChatMessage.tsx +53 -62
- package/src/chatbot/core/ChatMessageList.tsx +1 -1
- package/src/chatbot/core/ChatPanel.tsx +2 -6
- package/src/chatbot/core/ChatProvider.tsx +109 -22
- package/src/chatbot/core/ChatSuggestions.tsx +5 -10
- package/src/chatbot/core/ChatTicketConfirmation.tsx +9 -9
- package/src/chatbot/core/ChatTypingIndicator.tsx +16 -5
- package/src/chatbot/core/GroundedSources.tsx +181 -0
- package/src/chatbot/embedded/EmbeddedChatbot.tsx +33 -4
- package/src/chatbot/embedded/EmbeddedChatbotPanel.tsx +2 -11
- package/src/chatbot/embedded/EmbeddedChatbotTrigger.tsx +2 -2
- package/src/chatbot/index.ts +1 -0
- package/src/chatbot/widget/ChatbotWidget.tsx +33 -4
- package/src/chatbot/widget/ChatbotWidgetPanel.tsx +1 -6
- package/src/chatbot/widget/ChatbotWidgetTrigger.tsx +1 -8
- package/src/components/EnvBadge.tsx +2 -2
- package/src/components/ui/message-scroller.tsx +5 -23
- package/src/index.css +1998 -51
|
@@ -152,8 +152,8 @@ export const EmbeddedChatbotTrigger: React.FC<EmbeddedChatbotTriggerProps> = ({
|
|
|
152
152
|
aria-expanded={false}
|
|
153
153
|
aria-controls="vps-embedded-chat-panel"
|
|
154
154
|
aria-label="Assistant"
|
|
155
|
-
className={`
|
|
156
|
-
dragging ? "
|
|
155
|
+
className={`embedded-trigger-btn ${
|
|
156
|
+
dragging ? "embedded-trigger-btn--grabbing" : "embedded-trigger-btn--grab"
|
|
157
157
|
}`}
|
|
158
158
|
style={{
|
|
159
159
|
top: top ?? "50%",
|
package/src/chatbot/index.ts
CHANGED
|
@@ -15,7 +15,15 @@ export interface ChatbotWidgetProps {
|
|
|
15
15
|
/** Environment badge stage. Omit for production. */
|
|
16
16
|
envStage?: EnvStage;
|
|
17
17
|
envPulse?: boolean;
|
|
18
|
-
/**
|
|
18
|
+
/** Direct role name (e.g. "VPS Admin", "Client User", "Captain") */
|
|
19
|
+
role?: string;
|
|
20
|
+
/** Direct role ID for server-side RAG access control */
|
|
21
|
+
roleId?: number;
|
|
22
|
+
/** Direct client experience ("web" | "mobile" | "admin") */
|
|
23
|
+
client?: "mobile" | "web" | "admin";
|
|
24
|
+
/** Optional custom initial welcome message */
|
|
25
|
+
welcomeMessage?: string;
|
|
26
|
+
/** Backend or proxy API base URL */
|
|
19
27
|
apiBaseUrl?: string;
|
|
20
28
|
/** Alias for apiBaseUrl */
|
|
21
29
|
apiUrl?: string;
|
|
@@ -29,11 +37,15 @@ export interface ChatbotWidgetProps {
|
|
|
29
37
|
disableSuggestions?: boolean;
|
|
30
38
|
/** Initial welcome message to trigger on mount */
|
|
31
39
|
initialMessage?: string;
|
|
40
|
+
/** If true, hides the "Inspect Sources" toggle button and drawer in grounded sources */
|
|
41
|
+
hideInspectSources?: boolean;
|
|
42
|
+
/** Whether to show grounded sources (default: true) */
|
|
43
|
+
showGroundedSources?: boolean;
|
|
32
44
|
}
|
|
33
45
|
|
|
34
46
|
const ChatbotWidgetView: React.FC<Omit<
|
|
35
47
|
ChatbotWidgetProps,
|
|
36
|
-
"apiBaseUrl" | "apiUrl" | "proxyUrl" | "userContext" | "suggestions" | "disableSuggestions" | "initialMessage"
|
|
48
|
+
"apiBaseUrl" | "apiUrl" | "proxyUrl" | "userContext" | "suggestions" | "disableSuggestions" | "initialMessage" | "hideInspectSources" | "showGroundedSources"
|
|
37
49
|
>> = ({
|
|
38
50
|
defaultOpen = false,
|
|
39
51
|
open,
|
|
@@ -69,22 +81,33 @@ export const ChatbotWidget: React.FC<ChatbotWidgetProps> = ({
|
|
|
69
81
|
apiUrl,
|
|
70
82
|
proxyUrl,
|
|
71
83
|
userContext,
|
|
84
|
+
role,
|
|
85
|
+
roleId,
|
|
86
|
+
client,
|
|
87
|
+
welcomeMessage,
|
|
72
88
|
suggestions,
|
|
73
89
|
disableSuggestions,
|
|
74
90
|
initialMessage,
|
|
91
|
+
hideInspectSources,
|
|
92
|
+
showGroundedSources,
|
|
75
93
|
...viewProps
|
|
76
94
|
}) => {
|
|
77
95
|
const existingContext = useOptionalChatContext();
|
|
78
96
|
const explicitUrl = apiBaseUrl ?? apiUrl ?? proxyUrl;
|
|
79
97
|
|
|
80
|
-
// If already inside ChatProvider and no conflicting apiBaseUrl or userContext override is passed, reuse context
|
|
81
98
|
const canReuseContext =
|
|
82
99
|
Boolean(existingContext) &&
|
|
83
100
|
(!explicitUrl || resolveApiBaseUrl(explicitUrl) === resolveApiBaseUrl(existingContext?.apiBaseUrl)) &&
|
|
84
101
|
!userContext &&
|
|
102
|
+
role === undefined &&
|
|
103
|
+
roleId === undefined &&
|
|
104
|
+
client === undefined &&
|
|
105
|
+
welcomeMessage === undefined &&
|
|
85
106
|
!suggestions &&
|
|
86
107
|
disableSuggestions === undefined &&
|
|
87
|
-
!initialMessage
|
|
108
|
+
!initialMessage &&
|
|
109
|
+
hideInspectSources === undefined &&
|
|
110
|
+
showGroundedSources === undefined;
|
|
88
111
|
|
|
89
112
|
if (canReuseContext) {
|
|
90
113
|
return <ChatbotWidgetView {...viewProps} />;
|
|
@@ -94,9 +117,15 @@ export const ChatbotWidget: React.FC<ChatbotWidgetProps> = ({
|
|
|
94
117
|
<ChatProvider
|
|
95
118
|
apiBaseUrl={explicitUrl}
|
|
96
119
|
userContext={userContext}
|
|
120
|
+
role={role}
|
|
121
|
+
roleId={roleId}
|
|
122
|
+
client={client}
|
|
123
|
+
welcomeMessage={welcomeMessage}
|
|
97
124
|
suggestions={suggestions}
|
|
98
125
|
disableSuggestions={disableSuggestions}
|
|
99
126
|
initialMessage={initialMessage}
|
|
127
|
+
hideInspectSources={hideInspectSources}
|
|
128
|
+
showGroundedSources={showGroundedSources}
|
|
100
129
|
>
|
|
101
130
|
<ChatbotWidgetView {...viewProps} />
|
|
102
131
|
</ChatProvider>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ChatPanel } from "../core/ChatPanel";
|
|
3
|
-
import { cn } from "../../lib/cn";
|
|
4
3
|
import { type EnvStage } from "../../components/EnvBadge";
|
|
5
4
|
|
|
6
5
|
interface ChatbotWidgetPanelProps {
|
|
@@ -21,11 +20,7 @@ export const ChatbotWidgetPanel: React.FC<ChatbotWidgetPanelProps> = ({
|
|
|
21
20
|
return (
|
|
22
21
|
<div
|
|
23
22
|
id="vps-chatbot-widget-panel"
|
|
24
|
-
className=
|
|
25
|
-
"fixed bottom-[98px] right-7 z-[999] flex h-[min(660px,calc(100vh-120px))] w-[min(420px,calc(100vw-32px))] flex-col overflow-hidden rounded-[20px] border border-border bg-card",
|
|
26
|
-
"shadow-[0_20px_40px_-15px_rgba(0,0,0,0.12)]",
|
|
27
|
-
"origin-bottom-right animate-[chat-pop_180ms_ease-out] motion-reduce:animate-none"
|
|
28
|
-
)}
|
|
23
|
+
className="widget-panel"
|
|
29
24
|
>
|
|
30
25
|
<ChatPanel
|
|
31
26
|
onClose={onClose}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { MessageSquare, X } from "lucide-react";
|
|
3
|
-
import { cn } from "../../lib/cn";
|
|
4
3
|
|
|
5
4
|
interface ChatbotWidgetTriggerProps {
|
|
6
5
|
open: boolean;
|
|
@@ -18,13 +17,7 @@ export const ChatbotWidgetTrigger: React.FC<ChatbotWidgetTriggerProps> = ({
|
|
|
18
17
|
aria-expanded={open}
|
|
19
18
|
aria-controls="vps-chatbot-widget-panel"
|
|
20
19
|
aria-label={open ? "Close assistant" : "Open assistant"}
|
|
21
|
-
className=
|
|
22
|
-
"fixed bottom-7 right-7 z-[1000] flex h-[58px] w-[58px] items-center justify-center rounded-xl text-primary-foreground",
|
|
23
|
-
"bg-primary hover:bg-[var(--primary-hover)]",
|
|
24
|
-
"shadow-md",
|
|
25
|
-
"transition duration-200 motion-reduce:transition-none motion-reduce:hover:scale-100",
|
|
26
|
-
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-primary"
|
|
27
|
-
)}
|
|
20
|
+
className="widget-trigger-btn"
|
|
28
21
|
>
|
|
29
22
|
{open ? <X size={22} /> : <MessageSquare size={24} />}
|
|
30
23
|
</button>
|
|
@@ -87,7 +87,7 @@ export const EnvBadge: React.FC<EnvBadgeProps> = ({
|
|
|
87
87
|
|
|
88
88
|
return (
|
|
89
89
|
<span
|
|
90
|
-
className={`env-badge ${variant} ${className}
|
|
90
|
+
className={`env-badge-inline ${variant} ${className}`.trim()}
|
|
91
91
|
title={tooltip}
|
|
92
92
|
aria-label={`${label} build`}
|
|
93
93
|
role="status"
|
|
@@ -97,7 +97,7 @@ export const EnvBadge: React.FC<EnvBadgeProps> = ({
|
|
|
97
97
|
<Icon size={10} className="env-badge-icon" aria-hidden="true" />
|
|
98
98
|
|
|
99
99
|
{/* Label */}
|
|
100
|
-
<span className="
|
|
100
|
+
<span className="env-badge-inline-label">{label}</span>
|
|
101
101
|
</span>
|
|
102
102
|
);
|
|
103
103
|
};
|
|
@@ -21,10 +21,7 @@ function MessageScroller({
|
|
|
21
21
|
return (
|
|
22
22
|
<MessageScrollerPrimitive.Root
|
|
23
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
|
-
)}
|
|
24
|
+
className={cn("msg-scroller-root", className)}
|
|
28
25
|
{...props}
|
|
29
26
|
/>
|
|
30
27
|
);
|
|
@@ -37,11 +34,7 @@ function MessageScrollerViewport({
|
|
|
37
34
|
return (
|
|
38
35
|
<MessageScrollerPrimitive.Viewport
|
|
39
36
|
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
|
-
)}
|
|
37
|
+
className={cn("msg-scroller-viewport", className)}
|
|
45
38
|
{...props}
|
|
46
39
|
/>
|
|
47
40
|
);
|
|
@@ -54,7 +47,7 @@ function MessageScrollerContent({
|
|
|
54
47
|
return (
|
|
55
48
|
<MessageScrollerPrimitive.Content
|
|
56
49
|
data-slot="message-scroller-content"
|
|
57
|
-
className={cn("
|
|
50
|
+
className={cn("msg-scroller-content", className)}
|
|
58
51
|
{...props}
|
|
59
52
|
/>
|
|
60
53
|
);
|
|
@@ -69,10 +62,7 @@ function MessageScrollerItem({
|
|
|
69
62
|
<MessageScrollerPrimitive.Item
|
|
70
63
|
data-slot="message-scroller-item"
|
|
71
64
|
scrollAnchor={scrollAnchor}
|
|
72
|
-
className={cn(
|
|
73
|
-
"min-w-0 shrink-0 [contain-intrinsic-size:auto_10rem] [content-visibility:auto]",
|
|
74
|
-
className
|
|
75
|
-
)}
|
|
65
|
+
className={cn("msg-scroller-item", className)}
|
|
76
66
|
{...props}
|
|
77
67
|
/>
|
|
78
68
|
);
|
|
@@ -88,15 +78,7 @@ function MessageScrollerButton({
|
|
|
88
78
|
<MessageScrollerPrimitive.Button
|
|
89
79
|
data-slot="message-scroller-button"
|
|
90
80
|
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
|
-
)}
|
|
81
|
+
className={cn("msg-scroller-btn", className)}
|
|
100
82
|
{...props}
|
|
101
83
|
>
|
|
102
84
|
{children ?? (
|