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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vpschatbotwidget",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "private": false,
5
5
  "description": "This is an Package for the chatbot widget ui for our customer portel . ",
6
6
  "homepage": "https://github.com/dhineshkumar-natobotics/VPS-Chatbot-Widget#readme",
@@ -65,7 +65,7 @@
65
65
  "@types/react": "^19.3.0",
66
66
  "@types/react-dom": "^19.3.0",
67
67
  "@vitejs/plugin-react": "^4.3.4",
68
- "jsdom": "^29.1.1",
68
+ "jsdom": "^26.0.0",
69
69
  "tailwindcss": "^4.3.3",
70
70
  "typescript": "^5.6.3",
71
71
  "vite": "^6.0.1",
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  ApiErrorDto,
3
+ ChatAccessContext,
3
4
  ChatApiError,
4
5
  ChatMessage,
5
6
  ChatMessageDto,
@@ -92,6 +93,8 @@ export function normalizeSource(dto: SourceDto): Source {
92
93
  chunkId: dto.chunk_id,
93
94
  source: dto.source,
94
95
  score: dto.score,
96
+ title: dto.title,
97
+ snippet: dto.snippet,
95
98
  };
96
99
  }
97
100
 
@@ -144,7 +147,20 @@ async function readJson(response: Response): Promise<unknown> {
144
147
  export interface ChatApiClient {
145
148
  apiBaseUrl: string;
146
149
  createSession(): Promise<SessionCreated>;
147
- sendMessage(sessionId: string, message: string): Promise<{
150
+ sendMessage(sessionId: string, message: string, access?: ChatAccessContext): Promise<{
151
+ requestId: string;
152
+ sessionId: string;
153
+ answer: string;
154
+ sources: Source[];
155
+ toolCalls: ToolCall[];
156
+ usage: TokenUsage;
157
+ }>;
158
+ sendMessageStream?(
159
+ sessionId: string,
160
+ message: string,
161
+ access?: ChatAccessContext,
162
+ onProgress?: (stage: string) => void
163
+ ): Promise<{
148
164
  requestId: string;
149
165
  sessionId: string;
150
166
  answer: string;
@@ -201,12 +217,16 @@ export function createChatApi(initialBaseUrl?: string): ChatApiClient {
201
217
  return { sessionId: dto.session_id, createdAt: dto.created_at };
202
218
  },
203
219
 
204
- async sendMessage(sessionId: string, message: string) {
220
+ async sendMessage(sessionId: string, message: string, access?: ChatAccessContext) {
205
221
  const dto = await request<ChatResponseDto>(
206
222
  `/api/v1/sessions/${sessionId}/messages`,
207
223
  {
208
224
  method: "POST",
209
- body: JSON.stringify({ message }),
225
+ body: JSON.stringify({
226
+ message,
227
+ ...(access?.roleId !== undefined ? { role_id: access.roleId } : {}),
228
+ ...(access?.client ? { client: access.client } : {}),
229
+ }),
210
230
  }
211
231
  );
212
232
  return {
@@ -219,6 +239,88 @@ export function createChatApi(initialBaseUrl?: string): ChatApiClient {
219
239
  };
220
240
  },
221
241
 
242
+ async sendMessageStream(
243
+ sessionId: string,
244
+ message: string,
245
+ access?: ChatAccessContext,
246
+ onProgress?: (stage: string) => void
247
+ ) {
248
+ const url = buildApiUrl(baseUrl, `/api/v1/sessions/${sessionId}/messages/stream`);
249
+ try {
250
+ const response = await fetch(url, {
251
+ method: "POST",
252
+ headers: {
253
+ "Content-Type": "application/json",
254
+ },
255
+ body: JSON.stringify({
256
+ message,
257
+ ...(access?.roleId !== undefined ? { role_id: access.roleId } : {}),
258
+ ...(access?.client ? { client: access.client } : {}),
259
+ }),
260
+ });
261
+
262
+ if (!response.ok || !response.body) {
263
+ return await this.sendMessage(sessionId, message, access);
264
+ }
265
+
266
+ const reader = response.body.getReader();
267
+ const decoder = new TextDecoder();
268
+ let buffer = "";
269
+ let finalResult: {
270
+ requestId: string;
271
+ sessionId: string;
272
+ answer: string;
273
+ sources: Source[];
274
+ toolCalls: ToolCall[];
275
+ usage: TokenUsage;
276
+ } | null = null;
277
+
278
+ while (true) {
279
+ const { done, value } = await reader.read();
280
+ if (done) break;
281
+ buffer += decoder.decode(value, { stream: true });
282
+ const lines = buffer.split("\n\n");
283
+ buffer = lines.pop() || "";
284
+
285
+ for (const line of lines) {
286
+ const trimmed = line.trim();
287
+ if (trimmed.startsWith("data:")) {
288
+ try {
289
+ const data = JSON.parse(trimmed.slice(5).trim());
290
+ if (data.type === "progress" && data.stage) {
291
+ onProgress?.(data.stage);
292
+ } else if (data.type === "complete") {
293
+ finalResult = {
294
+ requestId: data.request_id,
295
+ sessionId: data.session_id,
296
+ answer: data.answer,
297
+ sources: (data.sources || []).map(normalizeSource),
298
+ toolCalls: (data.tool_calls || []).map(normalizeToolCall),
299
+ usage: normalizeUsage(data.usage),
300
+ };
301
+ } else if (data.type === "error") {
302
+ throw new Error(data.message || "An error occurred");
303
+ }
304
+ } catch (e) {
305
+ if (e instanceof Error && e.message !== "An error occurred") {
306
+ // Ignore JSON parse error on incomplete chunk
307
+ } else {
308
+ throw e;
309
+ }
310
+ }
311
+ }
312
+ }
313
+ }
314
+
315
+ if (finalResult) {
316
+ return finalResult;
317
+ }
318
+ return await this.sendMessage(sessionId, message, access);
319
+ } catch {
320
+ return await this.sendMessage(sessionId, message, access);
321
+ }
322
+ },
323
+
222
324
  async getHistory(sessionId: string): Promise<ChatMessage[]> {
223
325
  try {
224
326
  const dto = await request<SessionMessagesResponseDto>(
@@ -6,6 +6,8 @@ export interface Source {
6
6
  chunkId: string;
7
7
  source: string;
8
8
  score: number;
9
+ title?: string;
10
+ snippet?: string;
9
11
  }
10
12
 
11
13
  export interface ToolCall {
@@ -27,6 +29,7 @@ export interface ChatMessage {
27
29
  content: string;
28
30
  createdAt: string;
29
31
  status?: MessageStatus;
32
+ progressText?: string;
30
33
  sources?: Source[];
31
34
  toolCalls?: ToolCall[];
32
35
  usage?: TokenUsage;
@@ -36,10 +39,20 @@ export interface ChatUserContext {
36
39
  customerId?: string;
37
40
  email?: string;
38
41
  name?: string;
42
+ /** Display name of the role, if the host application has one. */
39
43
  role?: string;
44
+ /** Authenticated Customer Portal role ID used for server-side RAG routing. */
45
+ roleId?: number;
46
+ /** Client experience that owns this authenticated session. */
47
+ client?: "mobile" | "web" | "admin";
40
48
  page?: string;
41
49
  }
42
50
 
51
+ export interface ChatAccessContext {
52
+ roleId?: number;
53
+ client?: "mobile" | "web" | "admin";
54
+ }
55
+
43
56
  export interface Ticket {
44
57
  ticketId: string;
45
58
  customerId: string;
@@ -79,6 +92,8 @@ export interface SourceDto {
79
92
  chunk_id: string;
80
93
  source: string;
81
94
  score: number;
95
+ title?: string;
96
+ snippet?: string;
82
97
  }
83
98
 
84
99
  export interface ToolCallDto {
@@ -121,6 +136,14 @@ export interface ChatResponseDto {
121
136
  sources: SourceDto[];
122
137
  tool_calls?: ToolCallDto[];
123
138
  usage: TokenUsageDto;
139
+ role?: RoleDto | null;
140
+ }
141
+
142
+ export interface RoleDto {
143
+ id: number;
144
+ usertype: string;
145
+ channel: "mobile" | "web" | "admin";
146
+ knowledge_scopes: string[];
124
147
  }
125
148
 
126
149
  export interface TicketDto {
@@ -0,0 +1,60 @@
1
+ import React, { useState, useEffect } from "react";
2
+ import { Brain, ChevronDown, ChevronRight, CheckCircle2 } from "lucide-react";
3
+
4
+ interface AgentReasoningProps {
5
+ status?: "pending" | "complete" | "error";
6
+ progressText?: string;
7
+ sourcesCount?: number;
8
+ durationMs?: number;
9
+ }
10
+
11
+ export const AgentReasoning: React.FC<AgentReasoningProps> = ({
12
+ status = "complete",
13
+ progressText,
14
+ sourcesCount = 5,
15
+ durationMs = 1800,
16
+ }) => {
17
+ const isPending = status === "pending";
18
+ const [isOpen, setIsOpen] = useState(isPending);
19
+ const [seconds, setSeconds] = useState(0);
20
+
21
+ useEffect(() => {
22
+ if (!isPending) return;
23
+ setIsOpen(true);
24
+ const start = Date.now();
25
+ const interval = setInterval(() => {
26
+ setSeconds(Number(((Date.now() - start) / 1000).toFixed(1)));
27
+ }, 100);
28
+ return () => clearInterval(interval);
29
+ }, [isPending]);
30
+
31
+ // When transition from pending to complete, collapse like ChatGPT / Open WebUI
32
+ useEffect(() => {
33
+ if (!isPending) {
34
+ setIsOpen(false);
35
+ }
36
+ }, [isPending]);
37
+
38
+ const durationDisplay = isPending
39
+ ? `${seconds}s`
40
+ : `${(durationMs / 1000).toFixed(1)}s`;
41
+
42
+ return (
43
+ <div className={`agent-reasoning-container${isPending ? " agent-reasoning--active" : ""}`}>
44
+ <div
45
+ className="agent-reasoning-header"
46
+ aria-expanded={isOpen}
47
+ >
48
+ <div className="agent-reasoning-header-left">
49
+ <Brain
50
+ size={13}
51
+ className={`agent-reasoning-brain-icon${isPending ? " agent-reasoning-brain--pulse" : ""}`}
52
+ />
53
+ <span className="agent-reasoning-title">
54
+ {isPending ? `Thinking (${durationDisplay})...` : `Thought for ${durationDisplay} `}
55
+ </span>
56
+ </div>
57
+ </div>
58
+ </div>
59
+ );
60
+ };
@@ -26,6 +26,8 @@ export interface ChatContextValue {
26
26
  suggestionBadgesEnabled: boolean;
27
27
  userContext: ChatUserContext;
28
28
  apiBaseUrl?: string;
29
+ hideInspectSources?: boolean;
30
+ showGroundedSources?: boolean;
29
31
  sendMessage: (text: string) => Promise<void>;
30
32
  retryLast: () => Promise<void>;
31
33
  confirmTicket: (customerIdOrEmail?: string) => Promise<void>;
@@ -1,16 +1,16 @@
1
1
  import React from "react";
2
- import { Bot, BotMessageSquare } from "lucide-react";
2
+ import { BotMessageSquare } from "lucide-react";
3
3
 
4
4
  export const ChatEmptyState: React.FC = () => {
5
5
  return (
6
- <div className="flex items-start gap-2.5">
6
+ <div className="chat-empty-row">
7
7
  <div
8
- className="mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground"
8
+ className="avatar-circle avatar-circle--mt"
9
9
  aria-hidden="true"
10
10
  >
11
11
  <BotMessageSquare size={15} />
12
12
  </div>
13
- <div className="max-w-[82%] rounded-2xl rounded-tl-sm border border-border bg-[var(--bubble-assistant-bg)] px-3.5 py-2.5 text-[13.5px] leading-[1.55] text-foreground">
13
+ <div className="chat-empty-bubble">
14
14
  <p>
15
15
  Hello — I am the VPS Veritas assistant. Ask about reports, sample status,
16
16
  registration, or support, or choose a question below the text box.
@@ -8,7 +8,7 @@ interface ChatErrorProps {
8
8
  export const ChatError: React.FC<ChatErrorProps> = ({ message, onRetry }) => {
9
9
  return (
10
10
  <div
11
- className="mx-4 mb-2 rounded-lg border border-[var(--error-border)] bg-[var(--error-bg)] px-3 py-2 text-[12.5px] text-[var(--error-text)]"
11
+ className="chat-error-banner"
12
12
  role="alert"
13
13
  >
14
14
  <p>{message}</p>
@@ -16,7 +16,7 @@ export const ChatError: React.FC<ChatErrorProps> = ({ message, onRetry }) => {
16
16
  <button
17
17
  type="button"
18
18
  onClick={onRetry}
19
- className="mt-1.5 text-[12px] font-semibold underline underline-offset-2"
19
+ className="chat-error-retry-btn"
20
20
  >
21
21
  Try again
22
22
  </button>
@@ -1,6 +1,5 @@
1
1
  import React, { useEffect, useRef } from "react";
2
- import { ArrowLeft, Bot, Minus, RefreshCw } from "lucide-react";
3
- import ChatbotIcon from "../../../Chatbot.svg";
2
+ import { ArrowLeft, Minus, RefreshCw } from "lucide-react";
4
3
  import { EnvBadge, type EnvStage } from "../../components/EnvBadge";
5
4
 
6
5
  interface ChatHeaderProps {
@@ -15,6 +14,7 @@ interface ChatHeaderProps {
15
14
  /** Whether the status dot pulses. Default: true */
16
15
  envPulse?: boolean;
17
16
  }
17
+
18
18
  const SVGComponent = (props: React.SVGProps<SVGSVGElement> & { width?: string; height?: string , Color?: string}) => (
19
19
  <svg
20
20
  width={props.width || "24px"}
@@ -41,41 +41,41 @@ export const ChatHeader: React.FC<ChatHeaderProps> = ({
41
41
  envPulse = true,
42
42
  }) => {
43
43
  return (
44
- <header className="flex items-center justify-between border-b border-border bg-card px-5 py-4">
45
- <div className="flex items-center gap-3">
44
+ <header className="chat-header">
45
+ <div className="chat-header-left">
46
46
  {onBack && (
47
47
  <button
48
48
  type="button"
49
49
  onClick={onBack}
50
- className="flex h-8 w-8 items-center justify-center rounded-full border border-border bg-muted text-muted-foreground hover:bg-[var(--grey-100)]"
50
+ className="icon-btn-back"
51
51
  aria-label="Back"
52
52
  >
53
53
  <ArrowLeft size={16} />
54
54
  </button>
55
55
  )}
56
56
  <div
57
- className="flex h-8 w-8 items-center justify-center rounded-full bg-primary text-primary-foreground"
57
+ className="avatar-circle"
58
58
  aria-hidden="true"
59
59
  >
60
- <SVGComponent width="16px" height="16px" Color="white" />
60
+ <SVGComponent width="16px" height="16px" color="white" />
61
61
  </div>
62
62
  <div>
63
- <div className="flex items-center gap-1.5">
64
- <h2 className="text-[16px] font-bold tracking-tight text-foreground">
63
+ <div className="chat-header-title-row">
64
+ <h2 className="chat-header-title">
65
65
  {title}
66
66
  </h2>
67
67
  {/* ── Env badge inline with title ── */}
68
68
  <EnvBadge stage={envStage} pulse={envPulse} />
69
69
  </div>
70
- <p className="text-[12px] text-muted-foreground font-medium text-[var(--text-subtle)]">{subtitle || "Customer portal support"}</p>
70
+ <p className="chat-header-subtitle">{subtitle || "Customer portal support"}</p>
71
71
  </div>
72
72
  </div>
73
- <div className="flex items-center gap-1">
73
+ <div className="chat-header-actions">
74
74
  {onReset && (
75
75
  <button
76
76
  type="button"
77
77
  onClick={onReset}
78
- className="flex h-7 w-7 items-center justify-center rounded-md text-[var(--text-subtle)] hover:bg-muted hover:text-foreground"
78
+ className="icon-btn-action"
79
79
  aria-label="Start a new conversation"
80
80
  title="New conversation"
81
81
  >
@@ -86,7 +86,7 @@ export const ChatHeader: React.FC<ChatHeaderProps> = ({
86
86
  <button
87
87
  type="button"
88
88
  onClick={onClose}
89
- className="flex h-7 w-7 items-center justify-center rounded-md text-[var(--text-subtle)] hover:bg-muted hover:text-foreground"
89
+ className="icon-btn-action"
90
90
  aria-label={showMinimize ? "Minimize chat" : "Close chat"}
91
91
  >
92
92
  <Minus size={16} />
@@ -55,7 +55,7 @@ export const ChatInput: React.FC<ChatInputProps> = ({
55
55
  };
56
56
 
57
57
  return (
58
- <div className="bg-card px-4 pb-3 pt-2">
58
+ <div className="chat-input-wrapper">
59
59
  <ChatSuggestions
60
60
  variant="badge"
61
61
  suggestions={visibleSuggestions}
@@ -65,7 +65,7 @@ export const ChatInput: React.FC<ChatInputProps> = ({
65
65
  <label htmlFor="vps-chat-input" className="sr-only">
66
66
  Chat message
67
67
  </label>
68
- <div className="flex items-end gap-2 rounded-xl bg-[var(--input-bg)] px-2.5 py-1.5">
68
+ <div className="chat-input-row">
69
69
  <textarea
70
70
  id="vps-chat-input"
71
71
  ref={textareaRef}
@@ -83,20 +83,20 @@ export const ChatInput: React.FC<ChatInputProps> = ({
83
83
  send();
84
84
  }
85
85
  }}
86
- className="max-h-24 flex-1 resize-none bg-transparent py-1.5 text-[13.5px] text-foreground outline-none placeholder:text-[var(--text-subtle)] disabled:opacity-60"
86
+ className="chat-textarea"
87
87
  />
88
88
  <button
89
89
  type="button"
90
90
  onClick={send}
91
91
  disabled={disabled || !text.trim()}
92
92
  aria-label="Send message"
93
- className="mb-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-action text-action-foreground hover:bg-[var(--action-hover)] disabled:cursor-not-allowed disabled:opacity-40"
93
+ className="chat-send-btn"
94
94
  >
95
95
  <ArrowUp size={16} />
96
96
  </button>
97
97
  </div>
98
- <p className="mt-2 text-center text-[11px] font-medium text-[var(--text-subtle)]">
99
- Powered by <span className="text-primary font-bold hover:underline cursor-pointer">VPS Veritas AI</span>
98
+ <p className="chat-input-footer">
99
+ Powered by <span className="chat-input-footer-brand">VPS Veritas AI</span>
100
100
  </p>
101
101
  </div>
102
102
  );