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.
Files changed (63) hide show
  1. package/Chatbot.svg +1 -0
  2. package/README.md +86 -0
  3. package/dist/assets/index-C0fUDi2s.css +1 -0
  4. package/dist/assets/index-foGq5_Av.js +159 -0
  5. package/dist/index.html +17 -0
  6. package/index.html +16 -0
  7. package/package.json +47 -0
  8. package/src/App.tsx +85 -0
  9. package/src/chatbot/api/chatbot-api.ts +258 -0
  10. package/src/chatbot/api/chatbot-types.ts +145 -0
  11. package/src/chatbot/chatbot.test.tsx +274 -0
  12. package/src/chatbot/config/colors.ts +166 -0
  13. package/src/chatbot/config/suggestions.ts +21 -0
  14. package/src/chatbot/core/ChatContext.tsx +43 -0
  15. package/src/chatbot/core/ChatEmptyState.tsx +21 -0
  16. package/src/chatbot/core/ChatError.tsx +26 -0
  17. package/src/chatbot/core/ChatHeader.tsx +108 -0
  18. package/src/chatbot/core/ChatInput.tsx +103 -0
  19. package/src/chatbot/core/ChatMarkdown.tsx +87 -0
  20. package/src/chatbot/core/ChatMessage.tsx +115 -0
  21. package/src/chatbot/core/ChatMessageList.tsx +47 -0
  22. package/src/chatbot/core/ChatPanel.tsx +66 -0
  23. package/src/chatbot/core/ChatProvider.tsx +185 -0
  24. package/src/chatbot/core/ChatSuggestions.tsx +71 -0
  25. package/src/chatbot/core/ChatTicketConfirmation.tsx +59 -0
  26. package/src/chatbot/core/ChatTypingIndicator.tsx +16 -0
  27. package/src/chatbot/core/ticket-intent.ts +12 -0
  28. package/src/chatbot/embedded/EmbeddedChatbot.tsx +47 -0
  29. package/src/chatbot/embedded/EmbeddedChatbotPanel.tsx +56 -0
  30. package/src/chatbot/embedded/EmbeddedChatbotTrigger.tsx +167 -0
  31. package/src/chatbot/hooks/useChatbot.ts +5 -0
  32. package/src/chatbot/index.ts +7 -0
  33. package/src/chatbot/widget/ChatbotWidget.tsx +43 -0
  34. package/src/chatbot/widget/ChatbotWidgetPanel.tsx +39 -0
  35. package/src/chatbot/widget/ChatbotWidgetTrigger.tsx +32 -0
  36. package/src/components/AgentSummaryCard.tsx +37 -0
  37. package/src/components/ChatHeader.tsx +142 -0
  38. package/src/components/ChatInput.tsx +123 -0
  39. package/src/components/ChatWidget.tsx +295 -0
  40. package/src/components/ConnectingStatus.tsx +16 -0
  41. package/src/components/EnvBadge.tsx +103 -0
  42. package/src/components/FeedbackRatingCard.tsx +123 -0
  43. package/src/components/MessageItem.tsx +157 -0
  44. package/src/components/MessageList.tsx +143 -0
  45. package/src/components/OrderTrackingCard.tsx +104 -0
  46. package/src/components/QuickPrompts.tsx +46 -0
  47. package/src/components/ResponseIconMapper.tsx +155 -0
  48. package/src/components/SourceCitations.tsx +46 -0
  49. package/src/components/ToolCallBadge.tsx +29 -0
  50. package/src/components/TypingProgressBar.tsx +113 -0
  51. package/src/components/ui/message-scroller.tsx +128 -0
  52. package/src/index.css +550 -0
  53. package/src/lib/cn.ts +5 -0
  54. package/src/lib/gibberishDetector.ts +159 -0
  55. package/src/lib/textHighlighter.tsx +206 -0
  56. package/src/main.tsx +10 -0
  57. package/src/services/api.ts +74 -0
  58. package/src/test/message-scroller-stub.tsx +60 -0
  59. package/src/test/setup.ts +8 -0
  60. package/src/types/chat.ts +66 -0
  61. package/src/vite-env.d.ts +14 -0
  62. package/tsconfig.json +21 -0
  63. package/vite.config.ts +28 -0
@@ -0,0 +1,274 @@
1
+ import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
2
+ import userEvent from "@testing-library/user-event";
3
+ import { beforeEach, describe, expect, it, vi } from "vitest";
4
+ import { ChatProvider } from "../chatbot/core/ChatProvider";
5
+ import { ChatbotWidget } from "../chatbot/widget/ChatbotWidget";
6
+ import { EmbeddedChatbot } from "../chatbot/embedded/EmbeddedChatbot";
7
+ import { ChatPanel } from "../chatbot/core/ChatPanel";
8
+
9
+ vi.mock("@shadcn/react/message-scroller", async () => {
10
+ return await import("../test/message-scroller-stub");
11
+ });
12
+
13
+ function jsonResponse(body: unknown, status = 200): Response {
14
+ return {
15
+ ok: status >= 200 && status < 300,
16
+ status,
17
+ text: async () => JSON.stringify(body),
18
+ json: async () => body,
19
+ } as Response;
20
+ }
21
+
22
+ const usage = {
23
+ model: "test-model",
24
+ prompt_tokens: 1,
25
+ completion_tokens: 2,
26
+ total_tokens: 3,
27
+ };
28
+
29
+ describe("chatbot UI", () => {
30
+ beforeEach(() => {
31
+ window.localStorage.removeItem("vps-embedded-assistant-top");
32
+ vi.stubGlobal(
33
+ "fetch",
34
+ vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
35
+ const url = String(input);
36
+ const method = (init?.method || "GET").toUpperCase();
37
+
38
+ if (url.endsWith("/api/v1/sessions") && method === "POST") {
39
+ return jsonResponse({
40
+ session_id: "session-1",
41
+ created_at: "2026-01-01T00:00:00Z",
42
+ });
43
+ }
44
+ if (url.includes("/api/v1/sessions/session-1/messages") && method === "POST") {
45
+ return jsonResponse({
46
+ request_id: "req-1",
47
+ session_id: "session-1",
48
+ answer: "Transformer oil reports are available in the Reports page.",
49
+ sources: [],
50
+ tool_calls: [],
51
+ usage,
52
+ });
53
+ }
54
+ return jsonResponse({ error: { message: "Not found" } }, 404);
55
+ })
56
+ );
57
+ });
58
+
59
+ it("opens and closes the widget", async () => {
60
+ const user = userEvent.setup();
61
+ render(
62
+ <ChatProvider>
63
+ <ChatbotWidget />
64
+ </ChatProvider>
65
+ );
66
+
67
+ expect(screen.queryByLabelText("VPS AI Assistant")).not.toBeInTheDocument();
68
+ await user.click(screen.getByRole("button", { name: "Open assistant" }));
69
+ expect(screen.getByLabelText("VPS AI Assistant")).toBeInTheDocument();
70
+ await user.click(screen.getByRole("button", { name: "Close assistant" }));
71
+ expect(screen.queryByLabelText("VPS AI Assistant")).not.toBeInTheDocument();
72
+ });
73
+
74
+ it("opens and closes the embedded panel", async () => {
75
+ const user = userEvent.setup();
76
+ render(
77
+ <ChatProvider>
78
+ <EmbeddedChatbot />
79
+ </ChatProvider>
80
+ );
81
+
82
+ await user.click(screen.getByRole("button", { name: /assistant/i }));
83
+ expect(document.getElementById("vps-embedded-chat-panel")).toHaveAttribute(
84
+ "aria-hidden",
85
+ "false"
86
+ );
87
+ await user.click(screen.getByRole("button", { name: "Close chat" }));
88
+ expect(document.getElementById("vps-embedded-chat-panel")).toHaveAttribute(
89
+ "aria-hidden",
90
+ "true"
91
+ );
92
+ });
93
+
94
+ it("drags the slide-out assistant tab without opening the panel", () => {
95
+ render(
96
+ <ChatProvider>
97
+ <EmbeddedChatbot />
98
+ </ChatProvider>
99
+ );
100
+
101
+ const button = screen.getByRole("button", { name: "Assistant" });
102
+ Object.defineProperty(button, "offsetHeight", { value: 40, configurable: true });
103
+ button.getBoundingClientRect = () =>
104
+ ({
105
+ x: 0,
106
+ y: 200,
107
+ top: 200,
108
+ left: 0,
109
+ bottom: 240,
110
+ right: 100,
111
+ width: 100,
112
+ height: 40,
113
+ toJSON: () => ({}),
114
+ }) as DOMRect;
115
+
116
+ fireEvent.pointerDown(button, { pointerId: 1, clientY: 220, button: 0 });
117
+ fireEvent.pointerMove(button, { pointerId: 1, clientY: 340 });
118
+ fireEvent.pointerUp(button, { pointerId: 1, clientY: 340 });
119
+
120
+ expect(document.getElementById("vps-embedded-chat-panel")).toHaveAttribute(
121
+ "aria-hidden",
122
+ "true"
123
+ );
124
+ expect(button.style.top).toBe("320px");
125
+ });
126
+
127
+ it("renders suggestions and sends a message", async () => {
128
+ const user = userEvent.setup();
129
+ render(
130
+ <ChatProvider>
131
+ <ChatPanel />
132
+ </ChatProvider>
133
+ );
134
+
135
+ expect(screen.getByText(/VPS Veritas assistant/i)).toBeInTheDocument();
136
+ expect(screen.getByRole("list", { name: "Suggested questions" })).toBeInTheDocument();
137
+ await user.click(screen.getByRole("button", { name: "How do I access my reports?" }));
138
+
139
+ const input = screen.getByLabelText("Chat message") as HTMLTextAreaElement;
140
+ expect(input.value).toBe("How do I access my reports in the VPS Customer Portal?");
141
+ await user.keyboard("{Enter}");
142
+
143
+ await waitFor(() => {
144
+ expect(
145
+ screen.getByText("Transformer oil reports are available in the Reports page.")
146
+ ).toBeInTheDocument();
147
+ });
148
+ expect(fetch).toHaveBeenCalledWith(
149
+ "/api/v1/sessions/session-1/messages",
150
+ expect.objectContaining({ method: "POST" })
151
+ );
152
+ });
153
+
154
+ it("filters suggestion badges as the user types", async () => {
155
+ const user = userEvent.setup();
156
+ render(
157
+ <ChatProvider>
158
+ <ChatPanel />
159
+ </ChatProvider>
160
+ );
161
+
162
+ const input = screen.getByLabelText("Chat message");
163
+ expect(screen.getByRole("button", { name: "Where can I find sample status?" })).toBeInTheDocument();
164
+
165
+ await user.type(input, "report");
166
+ expect(screen.getByRole("button", { name: "How do I access my reports?" })).toBeInTheDocument();
167
+ expect(screen.queryByRole("button", { name: "Where can I find sample status?" })).not.toBeInTheDocument();
168
+ });
169
+
170
+ it("sends from the keyboard with Enter and keeps Shift+Enter as a newline", async () => {
171
+ const user = userEvent.setup();
172
+ render(
173
+ <ChatProvider>
174
+ <ChatPanel />
175
+ </ChatProvider>
176
+ );
177
+
178
+ const input = screen.getByLabelText("Chat message");
179
+ await user.type(input, "Where is sample status?");
180
+ await user.keyboard("{Enter}");
181
+
182
+ await waitFor(() => {
183
+ expect(screen.getByText("Where is sample status?")).toBeInTheDocument();
184
+ });
185
+
186
+ await user.type(input, "line one");
187
+ await user.keyboard("{Shift>}{Enter}{/Shift}");
188
+ expect((input as HTMLTextAreaElement).value).toContain("\n");
189
+ });
190
+
191
+ it("shows a friendly error and retries", async () => {
192
+ const user = userEvent.setup();
193
+ const fetchMock = vi.mocked(fetch);
194
+ fetchMock.mockImplementation(async (input, init) => {
195
+ const url = String(input);
196
+ const method = (init?.method || "GET").toUpperCase();
197
+ if (url.endsWith("/api/v1/sessions") && method === "POST") {
198
+ return jsonResponse({
199
+ session_id: "session-1",
200
+ created_at: "2026-01-01T00:00:00Z",
201
+ });
202
+ }
203
+ if (url.includes("/messages") && method === "POST") {
204
+ return jsonResponse(
205
+ { error: { message: "Unable to process the chat request right now." } },
206
+ 502
207
+ );
208
+ }
209
+ return jsonResponse({}, 500);
210
+ });
211
+
212
+ render(
213
+ <ChatProvider>
214
+ <ChatPanel />
215
+ </ChatProvider>
216
+ );
217
+
218
+ await user.type(screen.getByLabelText("Chat message"), "hello");
219
+ await user.keyboard("{Enter}");
220
+
221
+ await waitFor(() => {
222
+ expect(
223
+ screen.getAllByText(/unable to process the chat request right now/i).length
224
+ ).toBeGreaterThan(0);
225
+ });
226
+
227
+ fetchMock.mockImplementation(async (input, init) => {
228
+ const url = String(input);
229
+ const method = (init?.method || "GET").toUpperCase();
230
+ if (url.endsWith("/api/v1/sessions") && method === "POST") {
231
+ return jsonResponse({
232
+ session_id: "session-1",
233
+ created_at: "2026-01-01T00:00:00Z",
234
+ });
235
+ }
236
+ return jsonResponse({
237
+ request_id: "req-2",
238
+ session_id: "session-1",
239
+ answer: "Recovered reply",
240
+ sources: [],
241
+ tool_calls: [],
242
+ usage,
243
+ });
244
+ });
245
+
246
+ await user.click(screen.getByRole("button", { name: "Try again" }));
247
+ await waitFor(() => {
248
+ expect(screen.getByText("Recovered reply")).toBeInTheDocument();
249
+ });
250
+ });
251
+
252
+ it("keeps widget and embedded views on the same conversation", async () => {
253
+ const user = userEvent.setup();
254
+ render(
255
+ <ChatProvider>
256
+ <ChatbotWidget defaultOpen />
257
+ <div data-testid="second-surface">
258
+ <ChatPanel />
259
+ </div>
260
+ </ChatProvider>
261
+ );
262
+
263
+ const surfaces = screen.getAllByLabelText("Chat message");
264
+ await user.type(surfaces[0]!, "shared question");
265
+ await user.keyboard("{Enter}");
266
+
267
+ await waitFor(() => {
268
+ expect(
269
+ screen.getAllByText("Transformer oil reports are available in the Reports page.").length
270
+ ).toBeGreaterThan(1);
271
+ });
272
+ expect(within(screen.getByTestId("second-surface")).getByText("shared question")).toBeTruthy();
273
+ });
274
+ });
@@ -0,0 +1,166 @@
1
+ export const ColorPalette = {
2
+ Colors: {
3
+ VPS_White: "#fff",
4
+ VPS_Dark_Blue: "#1A1A31",
5
+ VPS_Light_Blue: "#353552",
6
+ VPS_Light_Grey: "#D1D1D6",
7
+ VPS_Orange: "#FF4717",
8
+ Dark_Blue_50: "#F1F5FC",
9
+ Dark_Blue_100: "#E5EBFA",
10
+ Dark_Blue_200: "#D1DAF4",
11
+ Dark_Blue_300: "#B4C2ED",
12
+ Dark_Blue_400: "#96A2E3",
13
+ Dark_Blue_500: "#7C84D8",
14
+ Dark_Blue_600: "#6262C9",
15
+ Dark_Blue_700: "#5351B1",
16
+ Dark_Blue_800: "#44448F",
17
+ Dark_Blue_900: "#3C3D73",
18
+ Dark_Blue_950: "#1A1A31",
19
+ Light_Blue_50: "#F4F6FA",
20
+ Light_Blue_100: "#E6E9F3",
21
+ Light_Blue_200: "#D3D8EA",
22
+ Light_Blue_300: "#B4BEDC",
23
+ Light_Blue_400: "#909DCA",
24
+ Light_Blue_500: "#7580BC",
25
+ Light_Blue_600: "#6369AD",
26
+ Light_Blue_700: "#575A9E",
27
+ Light_Blue_800: "#4B4B82",
28
+ Light_Blue_900: "#404168",
29
+ Light_Blue_950: "#353552",
30
+ Grey_50: "#F6F6F7",
31
+ Grey_100: "#EFEFF0",
32
+ Grey_200: "#E2E1E4",
33
+ Grey_300: "#D1D1D6",
34
+ Grey_400: "#B9B9C0",
35
+ Grey_500: "#A7A6AE",
36
+ Grey_600: "#93919A",
37
+ Grey_700: "#7E7D85",
38
+ Grey_800: "#67666D",
39
+ Grey_900: "#56555A",
40
+ Grey_950: "#323234",
41
+ Orange_50: "#FFF3ED",
42
+ Orange_100: "#FFE4D4",
43
+ Orange_200: "#FFC5A8",
44
+ Orange_300: "#FF9D70",
45
+ Orange_400: "#FF6837",
46
+ Orange_500: "#FF4717",
47
+ Orange_600: "#F02706",
48
+ Orange_700: "#C71807",
49
+ Orange_800: "#9E150E",
50
+ Orange_900: "#7F150F",
51
+ Orange_950: "#450605",
52
+ Success_50: "#F1FCF5",
53
+ Success_100: "#DEFAEA",
54
+ Success_200: "#BEF4D4",
55
+ Success_300: "#8BEAB3",
56
+ Success_400: "#52D689",
57
+ Success_500: "#2ECC71",
58
+ Success_600: "#1D9C53",
59
+ Success_700: "#1B7A43",
60
+ Success_800: "#1A6139",
61
+ Success_900: "#175031",
62
+ Success_950: "#072C18",
63
+ Warning_50: "#FFFEEA",
64
+ Warning_100: "#FFF9C5",
65
+ Warning_200: "#FFF485",
66
+ Warning_300: "#FFE846",
67
+ Warning_400: "#FFD81B",
68
+ Warning_500: "#FFB800",
69
+ Warning_600: "#E28D00",
70
+ Warning_700: "#BB6302",
71
+ Warning_800: "#984C08",
72
+ Warning_900: "#7C3F0B",
73
+ Warning_950: "#482000",
74
+ Error_50: "#FFF1F1",
75
+ Error_100: "#FFDFDF",
76
+ Error_200: "#FFC5C5",
77
+ Error_300: "#FF9D9D",
78
+ Error_400: "#FF6464",
79
+ Error_500: "#FF2E2E",
80
+ Error_600: "#ED1515",
81
+ Error_700: "#C80D0D",
82
+ Error_800: "#A50F0F",
83
+ Error_900: "#881414",
84
+ Error_950: "#4B0404",
85
+ Netural_25: "#FDFDFD",
86
+ Netural_50: "#FAFAFA",
87
+ Netural_100: "#F5F5F5",
88
+ Netural_200: "#E9EAEC",
89
+ Netural_300: "#D6D7DB",
90
+ Netural_400: "#A4A7AE",
91
+ Netural_500: "#727681",
92
+ Netural_600: "#545863",
93
+ Netural_700: "#424651",
94
+ Netural_800: "#252B37",
95
+ Netural_900: "#191D28",
96
+ Netural_950: "#0A0D12",
97
+ Tint_Dark_Blue_100: "#1A1A31",
98
+ Tint_Dark_Blue_90: "#313146",
99
+ Tint_Dark_Blue_80: "#48485A",
100
+ Tint_Dark_Blue_70: "#5F5F6F",
101
+ Tint_Dark_Blue_60: "#767683",
102
+ Tint_Dark_Blue_50: "#8C8C98",
103
+ Tint_Dark_Blue_40: "#A3A3AD",
104
+ Tint_Dark_Blue_30: "#BABAC1",
105
+ Tint_Dark_Blue_20: "#D1D1D6",
106
+ Tint_Dark_Blue_10: "#E8E8EA",
107
+ Tint_Dark_Blue_5: "#F4F4F5",
108
+ Tint_Light_Blue_100: "#353552",
109
+ Tint_Light_Blue_90: "#494963",
110
+ Tint_Light_Blue_80: "#5D5D75",
111
+ Tint_Light_Blue_70: "#727286",
112
+ Tint_Light_Blue_60: "#868697",
113
+ Tint_Light_Blue_50: "#9A9AA8",
114
+ Tint_Light_Blue_40: "#AEAEBA",
115
+ Tint_Light_Blue_30: "#C2C2CB",
116
+ Tint_Light_Blue_20: "#D7D7DC",
117
+ Tint_Light_Blue_10: "#EBEBEE",
118
+ Tint_Light_Blue_5: "#F5F5F6",
119
+ Tint_Grey_100: "#D1D1D6",
120
+ Tint_Grey_90: "#D6D6DA",
121
+ Tint_Grey_80: "#DADADE",
122
+ Tint_Grey_70: "#DFDFE2",
123
+ Tint_Grey_60: "#E3E3E6",
124
+ Tint_Grey_50: "#E8E8EB",
125
+ Tint_Grey_40: "#EDEDEF",
126
+ Tint_Grey_30: "#F1F1F3",
127
+ Tint_Grey_20: "#F6F6F7",
128
+ Tint_Grey_10: "#FAFAFB",
129
+ Tint_Grey_5: "#FDFDFD",
130
+ Tint_Solus_100: "#FF4717",
131
+ Tint_Solus_90: "#FF592E",
132
+ Tint_Solus_80: "#FF6C45",
133
+ Tint_Solus_70: "#FF7E5D",
134
+ Tint_Solus_60: "#FF9174",
135
+ Tint_Solus_50: "#FFA38B",
136
+ Tint_Solus_40: "#FFB5A2",
137
+ Tint_Solus_30: "#FFC8B9",
138
+ Tint_Solus_20: "#FFDAD1",
139
+ Tint_Solus_10: "#FFEDE8",
140
+ Tint_Solus_5: "#FFF6F3",
141
+ Other_Color: "#00ABC9",
142
+ },
143
+ StatusColor: {
144
+ tested: "#3E4784",
145
+ received: "#EE46BC",
146
+ InTransit: "#6938EF",
147
+ registered: "#1570EF",
148
+ reported: "#2ECC71",
149
+ noStatus: "#727681",
150
+ Action: "#FF2E2E",
151
+ Caution: "#FFB800",
152
+ Pass: "#2ECC71",
153
+ No_Rating: "#FF6837",
154
+ Received: "#EE46BC",
155
+ Tested: "#3E4784",
156
+ Reported: "#2ECC71",
157
+ No_Status: "#6938EF",
158
+ Overdue: "#FF2E2E",
159
+ Duesoon: "#FFB800",
160
+ Scheduled: "#1570EF",
161
+ Good: "#2ECC71",
162
+ NotApplicable: "#353552",
163
+ },
164
+ } as const;
165
+
166
+ export type ColorPalette = typeof ColorPalette;
@@ -0,0 +1,21 @@
1
+ import type { Suggestion } from "../api/chatbot-types";
2
+
3
+ /** Domain prompts derived from the VPS Customer Portal FAQ knowledge base. */
4
+ export const DEFAULT_SUGGESTIONS: Suggestion[] = [
5
+ {
6
+ label: "How do I access my reports?",
7
+ query: "How do I access my reports in the VPS Customer Portal?",
8
+ },
9
+ {
10
+ label: "Where can I find sample status?",
11
+ query: "Where can I find my sample status?",
12
+ },
13
+ {
14
+ label: "How do I pre-register a sample?",
15
+ query: "How do I pre-register a sample in the portal?",
16
+ },
17
+ {
18
+ label: "How do I contact VPS Support?",
19
+ query: "How can I contact VPS Customer Support?",
20
+ },
21
+ ];
@@ -0,0 +1,43 @@
1
+ import { createContext, useContext } from "react";
2
+ import type {
3
+ ChatMessage,
4
+ ChatUserContext,
5
+ Suggestion,
6
+ Ticket,
7
+ } from "../api/chatbot-types";
8
+
9
+ export type ChatUiStatus = "idle" | "connecting" | "awaiting" | "error";
10
+
11
+ export interface PendingTicket {
12
+ subject: string;
13
+ description: string;
14
+ }
15
+
16
+ export interface ChatContextValue {
17
+ messages: ChatMessage[];
18
+ status: ChatUiStatus;
19
+ error: string | null;
20
+ sessionId: string | null;
21
+ pendingTicket: PendingTicket | null;
22
+ ticketBusy: boolean;
23
+ lastTicket: Ticket | null;
24
+ suggestions: Suggestion[];
25
+ showSuggestions: boolean;
26
+ suggestionBadgesEnabled: boolean;
27
+ userContext: ChatUserContext;
28
+ sendMessage: (text: string) => Promise<void>;
29
+ retryLast: () => Promise<void>;
30
+ confirmTicket: (customerIdOrEmail?: string) => Promise<void>;
31
+ cancelTicket: () => void;
32
+ resetConversation: () => Promise<void>;
33
+ }
34
+
35
+ export const ChatContext = createContext<ChatContextValue | null>(null);
36
+
37
+ export function useChatContext(): ChatContextValue {
38
+ const value = useContext(ChatContext);
39
+ if (!value) {
40
+ throw new Error("useChatbot must be used inside ChatProvider.");
41
+ }
42
+ return value;
43
+ }
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ import { Bot, BotMessageSquare } from "lucide-react";
3
+
4
+ export const ChatEmptyState: React.FC = () => {
5
+ return (
6
+ <div className="flex items-start gap-2.5">
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"
9
+ aria-hidden="true"
10
+ >
11
+ <BotMessageSquare size={15} />
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">
14
+ <p>
15
+ Hello — I am the VPS Veritas assistant. Ask about reports, sample status,
16
+ registration, or support, or choose a question below the text box.
17
+ </p>
18
+ </div>
19
+ </div>
20
+ );
21
+ };
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+
3
+ interface ChatErrorProps {
4
+ message: string;
5
+ onRetry?: () => void;
6
+ }
7
+
8
+ export const ChatError: React.FC<ChatErrorProps> = ({ message, onRetry }) => {
9
+ return (
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)]"
12
+ role="alert"
13
+ >
14
+ <p>{message}</p>
15
+ {onRetry && (
16
+ <button
17
+ type="button"
18
+ onClick={onRetry}
19
+ className="mt-1.5 text-[12px] font-semibold underline underline-offset-2"
20
+ >
21
+ Try again
22
+ </button>
23
+ )}
24
+ </div>
25
+ );
26
+ };
@@ -0,0 +1,108 @@
1
+ import React, { useEffect, useRef } from "react";
2
+ import { ArrowLeft, Bot, Minus, RefreshCw } from "lucide-react";
3
+ import ChatbotIcon from "../../../Chatbot.svg";
4
+ import { EnvBadge, type EnvStage } from "../../components/EnvBadge";
5
+
6
+ interface ChatHeaderProps {
7
+ title?: string;
8
+ subtitle?: string;
9
+ onClose?: () => void;
10
+ onReset?: () => void;
11
+ onBack?: () => void;
12
+ showMinimize?: boolean;
13
+ /** Environment badge stage shown in the header. Omit for production. */
14
+ envStage?: EnvStage;
15
+ /** Whether the status dot pulses. Default: true */
16
+ envPulse?: boolean;
17
+ }
18
+ const SVGComponent = (props: React.SVGProps<SVGSVGElement> & { width?: string; height?: string , Color?: string}) => (
19
+ <svg
20
+ width={props.width || "24px"}
21
+ height={props.height || "24px"}
22
+ viewBox="0 0 24 24"
23
+ role="img"
24
+ xmlns="http://www.w3.org/2000/svg"
25
+ fill={props.Color || "currentColor"}
26
+ {...props}
27
+ >
28
+ <path d="M11.999 0c-2.25 0-4.5.06-6.6.21a5.57 5.57 0 0 0-5.19 5.1c-.24 3.21-.27 6.39-.06 9.6a5.644 5.644 0 0 0 5.7 5.19h3.15v-3.9h-3.15c-.93.03-1.74-.63-1.83-1.56-.18-3-.15-6 .06-9 .06-.84.72-1.47 1.56-1.53 2.04-.15 4.2-.21 6.36-.21s4.32.09 6.36.18c.81.06 1.5.69 1.56 1.53.24 3 .24 6 .06 9-.12.93-.9 1.62-1.83 1.59h-3.15l-6 3.9V24l6-3.9h3.15c2.97.03 5.46-2.25 5.7-5.19.21-3.18.18-6.39-.03-9.57a5.57 5.57 0 0 0-5.19-5.1c-2.13-.18-4.38-.24-6.63-.24zm-5.04 8.76c-.36 0-.66.3-.66.66v2.34c0 .33.18.63.48.78 1.62.78 3.42 1.2 5.22 1.26 1.8-.06 3.6-.48 5.22-1.26.3-.15.48-.45.48-.78V9.42c0-.09-.03-.15-.09-.21a.648.648 0 0 0-.87-.36c-1.5.66-3.12 1.02-4.77 1.05-1.65-.03-3.27-.42-4.77-1.08a.566.566 0 0 0-.24-.06z" />
29
+ </svg>
30
+ );
31
+ export default SVGComponent;
32
+
33
+ export const ChatHeader: React.FC<ChatHeaderProps> = ({
34
+ title = "VPS AI Assistant",
35
+ subtitle = "Customer portal support",
36
+ onClose,
37
+ onReset,
38
+ onBack,
39
+ showMinimize = false,
40
+ envStage,
41
+ envPulse = true,
42
+ }) => {
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">
46
+ {onBack && (
47
+ <button
48
+ type="button"
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)]"
51
+ aria-label="Back"
52
+ >
53
+ <ArrowLeft size={16} />
54
+ </button>
55
+ )}
56
+ <div
57
+ className="flex h-8 w-8 items-center justify-center rounded-full bg-primary text-primary-foreground"
58
+ aria-hidden="true"
59
+ >
60
+ <SVGComponent width="16px" height="16px" Color="white" />
61
+ </div>
62
+ <div>
63
+ <div className="flex items-center gap-1.5">
64
+ <h2 className="text-[16px] font-bold tracking-tight text-foreground">
65
+ {title}
66
+ </h2>
67
+ {/* ── Env badge inline with title ── */}
68
+ <EnvBadge stage={envStage} pulse={envPulse} />
69
+ </div>
70
+ <p className="text-[12px] text-muted-foreground font-medium text-[var(--text-subtle)]">{subtitle || "Customer portal support"}</p>
71
+ </div>
72
+ </div>
73
+ <div className="flex items-center gap-1">
74
+ {onReset && (
75
+ <button
76
+ type="button"
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"
79
+ aria-label="Start a new conversation"
80
+ title="New conversation"
81
+ >
82
+ <RefreshCw size={15} />
83
+ </button>
84
+ )}
85
+ {onClose && (
86
+ <button
87
+ type="button"
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"
90
+ aria-label={showMinimize ? "Minimize chat" : "Close chat"}
91
+ >
92
+ <Minus size={16} />
93
+ </button>
94
+ )}
95
+ </div>
96
+ </header>
97
+ );
98
+ };
99
+
100
+ export function useRestoreInputFocus(disabled: boolean, inputRef: React.RefObject<HTMLTextAreaElement | null>) {
101
+ const wasDisabled = useRef(disabled);
102
+ useEffect(() => {
103
+ if (wasDisabled.current && !disabled) {
104
+ inputRef.current?.focus();
105
+ }
106
+ wasDisabled.current = disabled;
107
+ }, [disabled, inputRef]);
108
+ }