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.
Files changed (42) hide show
  1. package/dist-lib/types/App.d.ts +1 -0
  2. package/dist-lib/types/chatbot/api/chatbot-api.d.ts +10 -2
  3. package/dist-lib/types/chatbot/api/chatbot-types.d.ts +21 -0
  4. package/dist-lib/types/chatbot/core/AgentReasoning.d.ts +9 -0
  5. package/dist-lib/types/chatbot/core/ChatContext.d.ts +2 -0
  6. package/dist-lib/types/chatbot/core/ChatMarkdown.d.ts +2 -2
  7. package/dist-lib/types/chatbot/core/ChatProvider.d.ts +13 -1
  8. package/dist-lib/types/chatbot/core/ChatTypingIndicator.d.ts +1 -0
  9. package/dist-lib/types/chatbot/core/GroundedSources.d.ts +14 -0
  10. package/dist-lib/types/chatbot/embedded/EmbeddedChatbot.d.ts +13 -1
  11. package/dist-lib/types/chatbot/index.d.ts +1 -1
  12. package/dist-lib/types/chatbot/widget/ChatbotWidget.d.ts +13 -1
  13. package/dist-lib/vps-chatbot.cjs +32 -28
  14. package/dist-lib/vps-chatbot.js +1262 -1085
  15. package/package.json +2 -2
  16. package/src/chatbot/api/chatbot-api.ts +105 -3
  17. package/src/chatbot/api/chatbot-types.ts +23 -0
  18. package/src/chatbot/core/AgentReasoning.tsx +60 -0
  19. package/src/chatbot/core/ChatContext.tsx +2 -0
  20. package/src/chatbot/core/ChatEmptyState.tsx +4 -4
  21. package/src/chatbot/core/ChatError.tsx +2 -2
  22. package/src/chatbot/core/ChatHeader.tsx +13 -13
  23. package/src/chatbot/core/ChatInput.tsx +6 -6
  24. package/src/chatbot/core/ChatMarkdown.tsx +280 -55
  25. package/src/chatbot/core/ChatMessage.tsx +53 -62
  26. package/src/chatbot/core/ChatMessageList.tsx +1 -1
  27. package/src/chatbot/core/ChatPanel.tsx +2 -6
  28. package/src/chatbot/core/ChatProvider.tsx +109 -22
  29. package/src/chatbot/core/ChatSuggestions.tsx +5 -10
  30. package/src/chatbot/core/ChatTicketConfirmation.tsx +9 -9
  31. package/src/chatbot/core/ChatTypingIndicator.tsx +16 -5
  32. package/src/chatbot/core/GroundedSources.tsx +181 -0
  33. package/src/chatbot/embedded/EmbeddedChatbot.tsx +33 -4
  34. package/src/chatbot/embedded/EmbeddedChatbotPanel.tsx +2 -11
  35. package/src/chatbot/embedded/EmbeddedChatbotTrigger.tsx +2 -2
  36. package/src/chatbot/index.ts +1 -0
  37. package/src/chatbot/widget/ChatbotWidget.tsx +33 -4
  38. package/src/chatbot/widget/ChatbotWidgetPanel.tsx +1 -6
  39. package/src/chatbot/widget/ChatbotWidgetTrigger.tsx +1 -8
  40. package/src/components/EnvBadge.tsx +2 -2
  41. package/src/components/ui/message-scroller.tsx +5 -23
  42. package/src/index.css +1998 -51
@@ -11,10 +11,18 @@ import { ChatContext, type ChatUiStatus } from "./ChatContext";
11
11
  export interface ChatProviderProps {
12
12
  children: React.ReactNode;
13
13
  userContext?: ChatUserContext;
14
+ /** Direct role name prop (e.g. "VPS Admin", "Client User", "Captain") */
15
+ role?: string;
16
+ /** Direct role ID prop for server-side RAG access control */
17
+ roleId?: number;
18
+ /** Direct client experience prop ("web" | "mobile" | "admin") */
19
+ client?: "mobile" | "web" | "admin";
20
+ /** Optional custom welcome message to display as initial assistant response */
21
+ welcomeMessage?: string;
14
22
  suggestions?: Suggestion[];
15
23
  disableSuggestions?: boolean;
16
24
  initialMessage?: string;
17
- /** Backend or proxy API base URL (e.g. "https://vpsai.onrender.com" or "/api"). Defaults to VITE_API_BASE or "" */
25
+ /** Backend or proxy API base URL. Defaults to VITE_API_BASE or origin */
18
26
  apiBaseUrl?: string;
19
27
  /** Alias for apiBaseUrl */
20
28
  apiUrl?: string;
@@ -22,8 +30,23 @@ export interface ChatProviderProps {
22
30
  proxyUrl?: string;
23
31
  /** Optional custom chat API client */
24
32
  api?: ChatApiClient;
33
+ /** If true, hides the "Inspect Sources" toggle and details drawer */
34
+ hideInspectSources?: boolean;
35
+ /** Whether to render grounded sources (default: true) */
36
+ showGroundedSources?: boolean;
25
37
  }
26
38
 
39
+ const DEFAULT_WELCOME_TEXT = `Hello! I am your **VPS Veritas assistant**.
40
+
41
+ I can help you with:
42
+ - **Fuel Quality Testing (FQT)** & **Oil Condition Monitoring (OCM)**
43
+ - **Fuel Defect Reporting (FDR)** — report and track bunker defect incidents
44
+ - **Bunker Master** — manage bunkering operations, BDN logs, and surveys
45
+ - **FSC & FSQ E-Forms** — paperless fuel system checks and bunker sample pre-registration
46
+ - **Samplogic** sample logistics, report downloads, and support tickets
47
+
48
+ Feel free to ask a question or select one of the suggested topics below!`;
49
+
27
50
  function newId(prefix: string): string {
28
51
  return `${prefix}-${crypto.randomUUID()}`;
29
52
  }
@@ -41,6 +64,10 @@ function friendlyError(err: unknown): string {
41
64
  export const ChatProvider: React.FC<ChatProviderProps> = ({
42
65
  children,
43
66
  userContext = {},
67
+ role,
68
+ roleId,
69
+ client: clientChannel,
70
+ welcomeMessage,
44
71
  suggestions = DEFAULT_SUGGESTIONS,
45
72
  disableSuggestions = false,
46
73
  initialMessage,
@@ -48,6 +75,8 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
48
75
  apiUrl,
49
76
  proxyUrl,
50
77
  api,
78
+ hideInspectSources = false,
79
+ showGroundedSources = true,
51
80
  }) => {
52
81
  const resolvedBaseUrl = apiBaseUrl ?? apiUrl ?? proxyUrl;
53
82
  const client = useMemo(
@@ -55,8 +84,30 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
55
84
  [api, resolvedBaseUrl]
56
85
  );
57
86
 
87
+ const effectiveUserContext = useMemo<ChatUserContext>(() => {
88
+ return {
89
+ ...userContext,
90
+ ...(role !== undefined ? { role } : {}),
91
+ ...(roleId !== undefined ? { roleId } : {}),
92
+ ...(clientChannel !== undefined ? { client: clientChannel } : {}),
93
+ };
94
+ }, [userContext, role, roleId, clientChannel]);
95
+
96
+ const defaultWelcomeMsg = useMemo<ChatMessage | null>(() => {
97
+ if (welcomeMessage === "") return null;
98
+ return {
99
+ id: "welcome-default",
100
+ role: "assistant",
101
+ content: welcomeMessage || DEFAULT_WELCOME_TEXT,
102
+ createdAt: new Date().toISOString(),
103
+ status: "complete",
104
+ };
105
+ }, [welcomeMessage]);
106
+
58
107
  const [sessionId, setSessionId] = useState<string | null>(null);
59
- const [messages, setMessages] = useState<ChatMessage[]>([]);
108
+ const [messages, setMessages] = useState<ChatMessage[]>(() => {
109
+ return defaultWelcomeMsg ? [defaultWelcomeMsg] : [];
110
+ });
60
111
  const [status, setStatus] = useState<ChatUiStatus>("idle");
61
112
  const [error, setError] = useState<string | null>(null);
62
113
  const lastUserTextRef = useRef<string | null>(null);
@@ -70,7 +121,6 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
70
121
  return created.sessionId;
71
122
  }, [sessionId, client]);
72
123
 
73
-
74
124
  const sendToBackend = useCallback(
75
125
  async (text: string) => {
76
126
  lastUserTextRef.current = text;
@@ -88,27 +138,58 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
88
138
  content: "",
89
139
  createdAt: new Date().toISOString(),
90
140
  status: "pending",
141
+ progressText: "Analyzing question & expanding domain terms ",
91
142
  };
92
143
 
93
144
  setMessages((prev) => [...prev, userMessage, pendingAssistant]);
94
145
  setStatus("awaiting");
95
146
  setError(null);
96
147
 
148
+ const updateProgress = (stageText: string) => {
149
+ setMessages((prev) =>
150
+ prev.map((message) =>
151
+ message.id === pendingId
152
+ ? { ...message, progressText: stageText }
153
+ : message
154
+ )
155
+ );
156
+ };
157
+
158
+
159
+
97
160
  try {
98
161
  const currentSession = await ensureSession();
99
- const response = await client.sendMessage(currentSession, text);
162
+ const response = client.sendMessageStream
163
+ ? await client.sendMessageStream(
164
+ currentSession,
165
+ text,
166
+ {
167
+ roleId: effectiveUserContext.roleId,
168
+ client: effectiveUserContext.client,
169
+ },
170
+ (liveStage) => {
171
+
172
+ updateProgress(liveStage);
173
+ }
174
+ )
175
+ : await client.sendMessage(currentSession, text, {
176
+ roleId: effectiveUserContext.roleId,
177
+ client: effectiveUserContext.client,
178
+ });
179
+
100
180
  setMessages((prev) =>
101
181
  prev.map((message) =>
102
182
  message.id === pendingId
103
183
  ? {
104
- ...message,
105
- id: response.requestId || pendingId,
106
- content: response.answer,
107
- status: "complete",
108
- sources: response.sources,
109
- toolCalls: response.toolCalls,
110
- usage: response.usage,
111
- }
184
+ ...message,
185
+ id: response.requestId || pendingId,
186
+ content: response.answer,
187
+ status: "complete",
188
+ progressText: undefined,
189
+ sources: response.sources,
190
+ toolCalls: response.toolCalls,
191
+ usage: response.usage,
192
+ }
112
193
  : message
113
194
  )
114
195
  );
@@ -118,7 +199,7 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
118
199
  setMessages((prev) =>
119
200
  prev.map((item) =>
120
201
  item.id === pendingId
121
- ? { ...item, content: message, status: "error" }
202
+ ? { ...item, content: message, status: "error", progressText: undefined }
122
203
  : item
123
204
  )
124
205
  );
@@ -126,7 +207,7 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
126
207
  setStatus("error");
127
208
  }
128
209
  },
129
- [ensureSession, client]
210
+ [ensureSession, client, effectiveUserContext.client, effectiveUserContext.roleId]
130
211
  );
131
212
 
132
213
  const sendMessage = useCallback(
@@ -145,19 +226,19 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
145
226
  await sendToBackend(last);
146
227
  }, [sendToBackend]);
147
228
 
148
- const confirmTicket = useCallback(async () => {}, []);
149
- const cancelTicket = useCallback(() => {}, []);
229
+ const confirmTicket = useCallback(async () => { }, []);
230
+ const cancelTicket = useCallback(() => { }, []);
150
231
 
151
232
  const resetConversation = useCallback(async () => {
152
233
  if (sessionId) {
153
234
  await client.closeSession(sessionId);
154
235
  }
155
236
  setSessionId(null);
156
- setMessages([]);
237
+ setMessages(defaultWelcomeMsg ? [defaultWelcomeMsg] : []);
157
238
  setStatus("idle");
158
239
  setError(null);
159
240
  lastUserTextRef.current = null;
160
- }, [sessionId, client]);
241
+ }, [sessionId, client, defaultWelcomeMsg]);
161
242
 
162
243
  React.useEffect(() => {
163
244
  if (!initialMessage || initialSentRef.current) return;
@@ -175,10 +256,15 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
175
256
  ticketBusy: false,
176
257
  lastTicket: null,
177
258
  suggestions,
178
- showSuggestions: !disableSuggestions && messages.length === 0,
259
+ showSuggestions:
260
+ !disableSuggestions &&
261
+ (messages.length === 0 ||
262
+ (messages.length === 1 && messages[0].id === "welcome-default")),
179
263
  suggestionBadgesEnabled: !disableSuggestions,
180
- userContext,
264
+ userContext: effectiveUserContext,
181
265
  apiBaseUrl: client.apiBaseUrl,
266
+ hideInspectSources,
267
+ showGroundedSources,
182
268
  sendMessage,
183
269
  retryLast,
184
270
  confirmTicket,
@@ -192,8 +278,10 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
192
278
  sessionId,
193
279
  suggestions,
194
280
  disableSuggestions,
195
- userContext,
281
+ effectiveUserContext,
196
282
  client.apiBaseUrl,
283
+ hideInspectSources,
284
+ showGroundedSources,
197
285
  sendMessage,
198
286
  retryLast,
199
287
  confirmTicket,
@@ -202,6 +290,5 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
202
290
  ]
203
291
  );
204
292
 
205
-
206
293
  return <ChatContext.Provider value={value}>{children}</ChatContext.Provider>;
207
294
  };
@@ -1,6 +1,5 @@
1
1
  import React from "react";
2
2
  import type { Suggestion } from "../api/chatbot-types";
3
- import { cn } from "../../lib/cn";
4
3
 
5
4
  export function filterSuggestions(suggestions: Suggestion[], text: string): Suggestion[] {
6
5
  const query = text.trim().toLowerCase();
@@ -29,21 +28,17 @@ export const ChatSuggestions: React.FC<ChatSuggestionsProps> = ({
29
28
  if (variant === "badge") {
30
29
  return (
31
30
  <ul
32
- className="mb-2 flex flex-wrap gap-1.5"
31
+ className="suggestions-badge-list"
33
32
  aria-label="Suggested questions"
34
33
  >
35
34
  {suggestions.map((item) => (
36
- <li key={item.query} className="max-w-full">
35
+ <li key={item.query} className="suggestion-badge-item">
37
36
  <button
38
37
  type="button"
39
38
  disabled={disabled}
40
39
  onClick={() => onSelect(item)}
41
40
  title={item.query}
42
- className={cn(
43
- "max-w-full truncate rounded-full border border-border bg-card px-2.5 py-1 text-left text-[11.5px] font-semibold text-foreground",
44
- "hover:border-primary hover:bg-[var(--tint-solus-10)] hover:text-primary",
45
- "disabled:cursor-not-allowed disabled:opacity-50"
46
- )}
41
+ className="suggestion-badge-btn"
47
42
  >
48
43
  {item.label}
49
44
  </button>
@@ -54,14 +49,14 @@ export const ChatSuggestions: React.FC<ChatSuggestionsProps> = ({
54
49
  }
55
50
 
56
51
  return (
57
- <div className="mt-3 flex flex-col gap-2">
52
+ <div className="suggestions-list">
58
53
  {suggestions.map((item) => (
59
54
  <button
60
55
  key={item.query}
61
56
  type="button"
62
57
  disabled={disabled}
63
58
  onClick={() => onSelect(item)}
64
- className="rounded-lg border border-border bg-card px-3.5 py-2.5 text-left text-[13px] font-semibold text-foreground shadow-[0_1px_3px_rgba(0,0,0,0.02)] transition hover:-translate-y-px hover:border-vps-light-grey hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50 motion-reduce:transition-none motion-reduce:hover:translate-y-0"
59
+ className="suggestion-list-btn"
65
60
  >
66
61
  {item.label}
67
62
  </button>
@@ -11,37 +11,37 @@ export const ChatTicketConfirmation: React.FC = () => {
11
11
 
12
12
  return (
13
13
  <div
14
- className="mx-4 mb-3 rounded-xl border border-border bg-card p-4 shadow-sm"
14
+ className="ticket-card"
15
15
  role="region"
16
16
  aria-label="Create support ticket"
17
17
  >
18
- <h3 className="text-[13.5px] font-bold text-foreground">
18
+ <h3 className="ticket-card-title">
19
19
  Create support ticket?
20
20
  </h3>
21
- <p className="mt-1.5 text-[12.5px] leading-5 text-muted-foreground">
21
+ <p className="ticket-card-desc">
22
22
  I can open a support request for you. Nothing is created until you confirm.
23
23
  </p>
24
- <p className="mt-2 rounded-md bg-muted px-2.5 py-2 text-[12.5px] text-foreground">
24
+ <p className="ticket-card-body">
25
25
  {pendingTicket.description}
26
26
  </p>
27
27
  {needsIdentity && (
28
- <label className="mt-3 block text-[12px] font-semibold text-foreground">
28
+ <label className="ticket-id-label">
29
29
  Customer ID or email
30
30
  <input
31
31
  value={identity}
32
32
  onChange={(event) => setIdentity(event.target.value)}
33
- className="mt-1 w-full rounded-md border border-border px-2.5 py-2 text-[13px] font-normal outline-none focus-visible:ring-2 focus-visible:ring-primary"
33
+ className="ticket-id-input"
34
34
  placeholder="CUST-1001 or you@company.com"
35
35
  autoComplete="email"
36
36
  />
37
37
  </label>
38
38
  )}
39
- <div className="mt-3 flex justify-end gap-2">
39
+ <div className="ticket-actions">
40
40
  <button
41
41
  type="button"
42
42
  onClick={cancelTicket}
43
43
  disabled={ticketBusy}
44
- className="rounded-lg border border-border bg-card px-3.5 py-1.5 text-[12.5px] font-semibold text-muted-foreground hover:bg-muted"
44
+ className="ticket-cancel-btn"
45
45
  >
46
46
  Cancel
47
47
  </button>
@@ -49,7 +49,7 @@ export const ChatTicketConfirmation: React.FC = () => {
49
49
  type="button"
50
50
  onClick={() => void confirmTicket(identity)}
51
51
  disabled={ticketBusy || (needsIdentity && !identity.trim())}
52
- className="rounded-lg bg-action px-3.5 py-1.5 text-[12.5px] font-semibold text-action-foreground hover:bg-[var(--action-hover)] disabled:opacity-40"
52
+ className="ticket-confirm-btn"
53
53
  >
54
54
  {ticketBusy ? "Creating…" : "Create ticket"}
55
55
  </button>
@@ -1,16 +1,27 @@
1
1
  import React from "react";
2
+ import { Sparkles } from "lucide-react";
2
3
  import { cn } from "../../lib/cn";
3
4
 
4
- export const ChatTypingIndicator: React.FC<{ className?: string }> = ({ className }) => {
5
+ export const ChatTypingIndicator: React.FC<{
6
+ className?: string;
7
+ text?: string;
8
+ }> = ({ className, text }) => {
5
9
  return (
6
10
  <div
7
- className={cn("flex items-center gap-1 py-0.5", className)}
11
+ className={cn("typing-indicator-container", className)}
8
12
  role="status"
9
13
  aria-label="Assistant is preparing a reply"
10
14
  >
11
- <span className="h-1.5 w-1.5 rounded-full bg-[var(--text-subtle)] motion-safe:animate-pulse" />
12
- <span className="h-1.5 w-1.5 rounded-full bg-[var(--text-subtle)] motion-safe:animate-pulse [animation-delay:150ms]" />
13
- <span className="h-1.5 w-1.5 rounded-full bg-[var(--text-subtle)] motion-safe:animate-pulse [animation-delay:300ms]" />
15
+ {/* <div className="typing-indicator">
16
+ <span className="typing-dot" />
17
+ <span className="typing-dot" />
18
+ <span className="typing-dot" />
19
+ </div> */}
20
+ <div className="typing-progress-pill">
21
+ <span className="typing-progress-text">
22
+ {text || "Retrieving knowledge & generating answer ..."}
23
+ </span>
24
+ </div>
14
25
  </div>
15
26
  );
16
27
  };
@@ -0,0 +1,181 @@
1
+ import React, { useState } from "react";
2
+ import { BookOpen, ChevronDown, ChevronUp, ExternalLink, ShieldCheck } from "lucide-react";
3
+ import type { Source } from "../api/chatbot-types";
4
+
5
+ // Map document basenames to corresponding portal routes
6
+ const ROUTE_HINTS: Record<string, { label: string; path: string }> = {
7
+ "fuel-defect-reporting": {
8
+ label: "Fuel Defect Reporting",
9
+ path: "/dashboard/fuel-Defect-Reporting",
10
+ },
11
+ "bunker-master": {
12
+ label: "Bunker Master",
13
+ path: "/dashboard/bunker-master",
14
+ },
15
+ "fsc-fsq-e-forms": {
16
+ label: "Pre-Registration & E-Forms",
17
+ path: "/dashboard/pre-registration",
18
+ },
19
+ "pre-registration-ship": {
20
+ label: "Pre-Registration",
21
+ path: "/dashboard/pre-registration",
22
+ },
23
+ "reports-fuel": {
24
+ label: "Fuel Reports",
25
+ path: "/dashboard/reports",
26
+ },
27
+ "sample-fuel": {
28
+ label: "Sample Status",
29
+ path: "/dashboard/sample-status",
30
+ },
31
+ };
32
+
33
+ function getRouteHint(sourcePath: string): { label: string; path: string } | null {
34
+ const filename = sourcePath.split(/[/\\]/).pop() || "";
35
+ const stem = filename.replace(/\.md$/i, "").toLowerCase();
36
+ for (const [key, value] of Object.entries(ROUTE_HINTS)) {
37
+ if (stem.includes(key)) {
38
+ return value;
39
+ }
40
+ }
41
+ return null;
42
+ }
43
+
44
+ function formatDocTitle(source: Source): string {
45
+ if (source.title) return source.title;
46
+ const filename = source.source.split(/[/\\]/).pop() || source.source;
47
+ return filename
48
+ .replace(/\.md$/i, "")
49
+ .replace(/[-_]/g, " ")
50
+ .replace(/\b\w/g, (c) => c.toUpperCase());
51
+ }
52
+
53
+ export interface GroundedSourcesProps {
54
+ sources: Source[];
55
+ /** If true, hides the "Inspect Sources" toggle button and details list */
56
+ hideInspectSources?: boolean;
57
+ /** Direct alias or inverted flag (default: true) */
58
+ showInspectSources?: boolean;
59
+ /** Whether the details view is open by default (default: false) */
60
+ defaultExpanded?: boolean;
61
+ /** Maximum number of grounded sources to display (default: 5) */
62
+ maxSources?: number;
63
+ }
64
+
65
+ export const GroundedSources: React.FC<GroundedSourcesProps> = ({
66
+ sources,
67
+ hideInspectSources = false,
68
+ showInspectSources = true,
69
+ defaultExpanded = false,
70
+ maxSources = 5,
71
+ }) => {
72
+ const shouldHideInspect = hideInspectSources || showInspectSources === false;
73
+ const [expanded, setExpanded] = useState(defaultExpanded && !shouldHideInspect);
74
+ const [activeSnippetIdx, setActiveSnippetIdx] = useState<number | null>(null);
75
+
76
+ if (!sources || !sources.length) return null;
77
+
78
+ // Display top 5 grounded sources as requested
79
+ const topSources = sources.slice(0, maxSources);
80
+
81
+ return (
82
+ <div className="grounded-sources-card">
83
+ <div className="grounded-sources-header">
84
+ <div className="grounded-sources-badge">
85
+ <ShieldCheck size={13} className="grounded-shield-icon" />
86
+ <span>Grounded in {topSources.length} Verified VPS Sources</span>
87
+ </div>
88
+ {!shouldHideInspect && (
89
+ <button
90
+ type="button"
91
+ className="grounded-toggle-btn"
92
+ onClick={() => setExpanded((prev) => !prev)}
93
+ aria-expanded={expanded}
94
+ >
95
+ <span>{expanded ? "Hide Details" : "Inspect Sources"}</span>
96
+ {expanded ? <ChevronUp size={12} /> : <ChevronDown size={12} />}
97
+ </button>
98
+ )}
99
+ </div>
100
+
101
+ <div className="grounded-pills-row">
102
+ {topSources.map((source, idx) => {
103
+ const title = formatDocTitle(source);
104
+ const scorePct = Math.round(source.score * 100);
105
+ const isSelected = activeSnippetIdx === idx;
106
+
107
+ return (
108
+ <button
109
+ key={`${source.chunkId}-${idx}`}
110
+ type="button"
111
+ className={`grounded-source-pill${isSelected ? " grounded-source-pill--selected" : ""}`}
112
+ onClick={() => {
113
+ if (!shouldHideInspect) {
114
+ setExpanded(true);
115
+ setActiveSnippetIdx(isSelected ? null : idx);
116
+ }
117
+ }}
118
+ title={source.source}
119
+ >
120
+ <BookOpen size={11} className="grounded-book-icon" />
121
+ <span className="grounded-pill-title">{title}</span>
122
+ <span className="grounded-pill-score">{scorePct}% match</span>
123
+ </button>
124
+ );
125
+ })}
126
+ </div>
127
+
128
+ {!shouldHideInspect && expanded && (
129
+ <div className="grounded-sources-details-list">
130
+ {topSources.map((source, idx) => {
131
+ const title = formatDocTitle(source);
132
+ const scorePct = Math.round(source.score * 100);
133
+ const routeHint = getRouteHint(source.source);
134
+ const isHighlighted = activeSnippetIdx === idx;
135
+
136
+ return (
137
+ <div
138
+ key={`detail-${source.chunkId}-${idx}`}
139
+ className={`grounded-detail-item${isHighlighted ? " grounded-detail-item--highlighted" : ""}`}
140
+ >
141
+ <div className="grounded-detail-top">
142
+ <div className="grounded-detail-title-group">
143
+ <span className="grounded-detail-index">[{idx + 1}]</span>
144
+ <span className="grounded-detail-title">{title}</span>
145
+ </div>
146
+ <div className="grounded-detail-meta">
147
+ <span className="grounded-detail-score">{scorePct}% Match</span>
148
+ {routeHint && (
149
+ <a
150
+ href={routeHint.path}
151
+ onClick={(e) => {
152
+ e.preventDefault();
153
+ window.location.href = routeHint.path;
154
+ }}
155
+ className="grounded-route-link"
156
+ title={`Navigate to ${routeHint.label}`}
157
+ >
158
+ <span>{routeHint.label}</span>
159
+ <ExternalLink size={10} />
160
+ </a>
161
+ )}
162
+ </div>
163
+ </div>
164
+
165
+ <div className="grounded-detail-path">
166
+ <code>{source.source}</code>
167
+ </div>
168
+
169
+ {source.snippet && (
170
+ <p className="grounded-detail-snippet">
171
+ "{source.snippet}"
172
+ </p>
173
+ )}
174
+ </div>
175
+ );
176
+ })}
177
+ </div>
178
+ )}
179
+ </div>
180
+ );
181
+ };
@@ -15,7 +15,15 @@ export interface EmbeddedChatbotProps {
15
15
  /** Environment badge stage. Omit for production. */
16
16
  envStage?: EnvStage;
17
17
  envPulse?: boolean;
18
- /** Backend or proxy API base URL (e.g. "https://vpsai.onrender.com" or "/api") */
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 EmbeddedChatbotProps {
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 EmbeddedChatbotView: React.FC<Omit<
35
47
  EmbeddedChatbotProps,
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,
@@ -72,22 +84,33 @@ export const EmbeddedChatbot: React.FC<EmbeddedChatbotProps> = ({
72
84
  apiUrl,
73
85
  proxyUrl,
74
86
  userContext,
87
+ role,
88
+ roleId,
89
+ client,
90
+ welcomeMessage,
75
91
  suggestions,
76
92
  disableSuggestions,
77
93
  initialMessage,
94
+ hideInspectSources,
95
+ showGroundedSources,
78
96
  ...viewProps
79
97
  }) => {
80
98
  const existingContext = useOptionalChatContext();
81
99
  const explicitUrl = apiBaseUrl ?? apiUrl ?? proxyUrl;
82
100
 
83
- // If already inside ChatProvider and no conflicting apiBaseUrl or userContext override is passed, reuse context
84
101
  const canReuseContext =
85
102
  Boolean(existingContext) &&
86
103
  (!explicitUrl || resolveApiBaseUrl(explicitUrl) === resolveApiBaseUrl(existingContext?.apiBaseUrl)) &&
87
104
  !userContext &&
105
+ role === undefined &&
106
+ roleId === undefined &&
107
+ client === undefined &&
108
+ welcomeMessage === undefined &&
88
109
  !suggestions &&
89
110
  disableSuggestions === undefined &&
90
- !initialMessage;
111
+ !initialMessage &&
112
+ hideInspectSources === undefined &&
113
+ showGroundedSources === undefined;
91
114
 
92
115
  if (canReuseContext) {
93
116
  return <EmbeddedChatbotView {...viewProps} />;
@@ -97,9 +120,15 @@ export const EmbeddedChatbot: React.FC<EmbeddedChatbotProps> = ({
97
120
  <ChatProvider
98
121
  apiBaseUrl={explicitUrl}
99
122
  userContext={userContext}
123
+ role={role}
124
+ roleId={roleId}
125
+ client={client}
126
+ welcomeMessage={welcomeMessage}
100
127
  suggestions={suggestions}
101
128
  disableSuggestions={disableSuggestions}
102
129
  initialMessage={initialMessage}
130
+ hideInspectSources={hideInspectSources}
131
+ showGroundedSources={showGroundedSources}
103
132
  >
104
133
  <EmbeddedChatbotView {...viewProps} />
105
134
  </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 EmbeddedChatbotPanelProps {
@@ -23,22 +22,14 @@ export const EmbeddedChatbotPanel: React.FC<EmbeddedChatbotPanelProps> = ({
23
22
  return (
24
23
  <>
25
24
  <div
26
- className={cn(
27
- "fixed inset-0 z-[90] bg-[var(--overlay)] sm:hidden",
28
- open ? "opacity-100" : "pointer-events-none opacity-0",
29
- "transition-opacity duration-200 motion-reduce:transition-none"
30
- )}
25
+ className={`embedded-overlay ${open ? "embedded-overlay--open" : "embedded-overlay--closed"}`}
31
26
  hidden={!open}
32
27
  onClick={onClose}
33
28
  aria-hidden="true"
34
29
  />
35
30
  <aside
36
31
  id="vps-embedded-chat-panel"
37
- className={cn(
38
- "fixed inset-y-0 right-0 z-[100] flex w-full max-w-[440px] flex-col border-l border-border bg-card shadow-xl",
39
- "transition-transform duration-300 ease-out motion-reduce:transition-none",
40
- open ? "translate-x-0" : "translate-x-full"
41
- )}
32
+ className={`embedded-panel ${open ? "embedded-panel--open" : "embedded-panel--closed"}`}
42
33
  aria-hidden={!open}
43
34
  >
44
35
  {open && (