vpschatbotwidget 1.2.1 → 1.2.3

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 (68) hide show
  1. package/README.md +56 -16
  2. package/dist-lib/types/chatbot/api/chatbot-types.d.ts +8 -1
  3. package/dist-lib/types/chatbot/core/AgentReasoning.d.ts +4 -1
  4. package/dist-lib/types/chatbot/core/ChatContext.d.ts +5 -1
  5. package/dist-lib/types/chatbot/core/ChatHeader.d.ts +2 -0
  6. package/dist-lib/types/chatbot/core/ChatInlineCitation.d.ts +5 -0
  7. package/dist-lib/types/chatbot/core/ChatInput.d.ts +5 -0
  8. package/dist-lib/types/chatbot/core/ChatMarkdown.d.ts +4 -1
  9. package/dist-lib/types/chatbot/core/ChatMessage.d.ts +1 -0
  10. package/dist-lib/types/chatbot/core/ChatMessageActions.d.ts +7 -0
  11. package/dist-lib/types/chatbot/core/ChatMessageList.d.ts +3 -1
  12. package/dist-lib/types/chatbot/core/ChatProvider.d.ts +2 -2
  13. package/dist-lib/types/chatbot/core/GroundedSources.d.ts +5 -0
  14. package/dist-lib/types/chatbot/embedded/EmbeddedChatbot.d.ts +2 -2
  15. package/dist-lib/types/chatbot/hooks/useCopyText.d.ts +4 -0
  16. package/dist-lib/types/chatbot/hooks/useResponseSound.d.ts +6 -0
  17. package/dist-lib/types/chatbot/index.d.ts +1 -1
  18. package/dist-lib/types/chatbot/widget/ChatbotWidget.d.ts +2 -2
  19. package/dist-lib/types/components/ai-elements/inline-citation.d.ts +52 -0
  20. package/dist-lib/types/components/ai-elements/reasoning.d.ts +21 -0
  21. package/dist-lib/types/components/ai-elements/suggestion.d.ts +9 -0
  22. package/dist-lib/types/components/ui/bubble.d.ts +6 -0
  23. package/dist-lib/types/components/ui/button.d.ts +8 -0
  24. package/dist-lib/types/components/ui/hover-card.d.ts +5 -0
  25. package/dist-lib/types/components/ui/input-group.d.ts +5 -0
  26. package/dist-lib/types/components/ui/marker.d.ts +6 -0
  27. package/dist-lib/types/components/ui/message.d.ts +8 -0
  28. package/dist-lib/types/components/ui/trace.d.ts +19 -0
  29. package/dist-lib/types/lib/safeHref.d.ts +1 -0
  30. package/dist-lib/vps-chatbot.cjs +110 -29
  31. package/dist-lib/vps-chatbot.js +9540 -1654
  32. package/package.json +6 -2
  33. package/src/chatbot/api/chatbot-api.ts +1 -0
  34. package/src/chatbot/api/chatbot-types.ts +9 -1
  35. package/src/chatbot/chatbot.test.tsx +125 -7
  36. package/src/chatbot/core/AgentReasoning.tsx +68 -36
  37. package/src/chatbot/core/ChatContext.tsx +5 -0
  38. package/src/chatbot/core/ChatEmptyState.tsx +14 -13
  39. package/src/chatbot/core/ChatError.tsx +20 -12
  40. package/src/chatbot/core/ChatHeader.tsx +17 -1
  41. package/src/chatbot/core/ChatInlineCitation.tsx +63 -0
  42. package/src/chatbot/core/ChatInput.tsx +73 -51
  43. package/src/chatbot/core/ChatMarkdown.tsx +70 -24
  44. package/src/chatbot/core/ChatMessage.tsx +77 -88
  45. package/src/chatbot/core/ChatMessageActions.tsx +51 -0
  46. package/src/chatbot/core/ChatMessageList.tsx +15 -7
  47. package/src/chatbot/core/ChatPanel.tsx +19 -7
  48. package/src/chatbot/core/ChatProvider.tsx +58 -10
  49. package/src/chatbot/core/ChatSuggestions.tsx +14 -34
  50. package/src/chatbot/core/GroundedSources.tsx +113 -90
  51. package/src/chatbot/core/grounding.test.tsx +111 -4
  52. package/src/chatbot/embedded/EmbeddedChatbot.tsx +2 -2
  53. package/src/chatbot/hooks/useCopyText.ts +23 -0
  54. package/src/chatbot/hooks/useResponseSound.ts +74 -0
  55. package/src/chatbot/index.ts +1 -0
  56. package/src/chatbot/widget/ChatbotWidget.tsx +2 -2
  57. package/src/components/ai-elements/inline-citation.tsx +299 -0
  58. package/src/components/ai-elements/reasoning.tsx +126 -0
  59. package/src/components/ai-elements/suggestion.tsx +42 -0
  60. package/src/components/ui/bubble.tsx +18 -0
  61. package/src/components/ui/button.tsx +43 -0
  62. package/src/components/ui/hover-card.tsx +43 -0
  63. package/src/components/ui/input-group.tsx +18 -0
  64. package/src/components/ui/marker.tsx +18 -0
  65. package/src/components/ui/message.tsx +26 -0
  66. package/src/components/ui/trace.tsx +68 -0
  67. package/src/index.css +579 -272
  68. package/src/lib/safeHref.ts +6 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vpschatbotwidget",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
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",
@@ -50,11 +50,15 @@
50
50
  "typecheck": "tsc --noEmit"
51
51
  },
52
52
  "dependencies": {
53
+ "@base-ui/react": "^1.9.0",
53
54
  "@shadcn/react": "^0.3.1",
55
+ "class-variance-authority": "^0.7.1",
54
56
  "clsx": "^2.1.1",
57
+ "embla-carousel-react": "^8.6.0",
55
58
  "lucide-react": "^0.468.0",
56
59
  "react": "^19.3.0",
57
- "react-dom": "^19.3.0"
60
+ "react-dom": "^19.3.0",
61
+ "streamdown": "^2.8.1"
58
62
  },
59
63
  "devDependencies": {
60
64
  "@tailwindcss/vite": "^4.3.3",
@@ -95,6 +95,7 @@ export function normalizeSource(dto: SourceDto): Source {
95
95
  source: dto.source,
96
96
  score: dto.score,
97
97
  title: dto.title,
98
+ ...(dto.url ? { url: dto.url } : {}),
98
99
  snippet: dto.snippet,
99
100
  };
100
101
  }
@@ -1,12 +1,15 @@
1
1
  export type ChatRole = "user" | "assistant" | "system";
2
2
 
3
- export type MessageStatus = "pending" | "complete" | "error";
3
+ export type MessageStatus = "pending" | "complete" | "error" | "stopped";
4
+
5
+ export type MessageFeedback = "like" | "dislike";
4
6
 
5
7
  export interface Source {
6
8
  chunkId: string;
7
9
  source: string;
8
10
  score: number;
9
11
  title?: string;
12
+ url?: string;
10
13
  snippet?: string;
11
14
  }
12
15
 
@@ -25,15 +28,19 @@ export interface TokenUsage {
25
28
 
26
29
  export interface ChatMessage {
27
30
  id: string;
31
+ /** Stable view identity while a streamed reply receives its server request ID. */
32
+ streamId?: string;
28
33
  role: ChatRole;
29
34
  content: string;
30
35
  createdAt: string;
31
36
  status?: MessageStatus;
32
37
  progressText?: string;
38
+ progressSteps?: string[];
33
39
  durationMs?: number;
34
40
  sources?: Source[];
35
41
  toolCalls?: ToolCall[];
36
42
  usage?: TokenUsage;
43
+ feedback?: MessageFeedback;
37
44
  }
38
45
 
39
46
  export interface ChatUserContext {
@@ -108,6 +115,7 @@ export interface SourceDto {
108
115
  source: string;
109
116
  score: number;
110
117
  title?: string;
118
+ url?: string;
111
119
  snippet?: string;
112
120
  }
113
121
 
@@ -1,6 +1,6 @@
1
- import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
1
+ import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
2
2
  import userEvent from "@testing-library/user-event";
3
- import { beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4
4
  import { ChatProvider } from "../chatbot/core/ChatProvider";
5
5
  import { ChatbotWidget } from "../chatbot/widget/ChatbotWidget";
6
6
  import { EmbeddedChatbot } from "../chatbot/embedded/EmbeddedChatbot";
@@ -31,6 +31,7 @@ const usage = {
31
31
  describe("chatbot UI", () => {
32
32
  beforeEach(() => {
33
33
  window.localStorage.removeItem("vps-embedded-assistant-top");
34
+ window.localStorage.removeItem("vps-chatbot-response-sound");
34
35
  vi.stubGlobal(
35
36
  "fetch",
36
37
  vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
@@ -48,7 +49,7 @@ describe("chatbot UI", () => {
48
49
  request_id: "req-1",
49
50
  session_id: "session-1",
50
51
  answer: "Transformer oil reports are available in the Reports page.",
51
- sources: [],
52
+ sources: [{ chunk_id: "source-1", source: "knowledge/Reports-Fuel.md", score: 0.98 }],
52
53
  tool_calls: [],
53
54
  usage,
54
55
  });
@@ -57,6 +58,7 @@ describe("chatbot UI", () => {
57
58
  })
58
59
  );
59
60
  });
61
+ afterEach(() => vi.unstubAllGlobals());
60
62
 
61
63
  it("opens and closes the widget", async () => {
62
64
  const user = userEvent.setup();
@@ -69,6 +71,7 @@ describe("chatbot UI", () => {
69
71
  expect(screen.queryByLabelText("VPS AI Assistant")).not.toBeInTheDocument();
70
72
  await user.click(screen.getByRole("button", { name: "Open assistant" }));
71
73
  expect(screen.getByLabelText("VPS AI Assistant")).toBeInTheDocument();
74
+ expect(screen.getByText("AI can make mistakes.")).toBeVisible();
72
75
  await user.click(screen.getByRole("button", { name: "Close assistant" }));
73
76
  expect(screen.queryByLabelText("VPS AI Assistant")).not.toBeInTheDocument();
74
77
  });
@@ -86,6 +89,7 @@ describe("chatbot UI", () => {
86
89
  "aria-hidden",
87
90
  "false"
88
91
  );
92
+ expect(screen.getByText("AI can make mistakes.")).toBeVisible();
89
93
  await user.click(screen.getByRole("button", { name: "Close chat" }));
90
94
  expect(document.getElementById("vps-embedded-chat-panel")).toHaveAttribute(
91
95
  "aria-hidden",
@@ -153,6 +157,107 @@ describe("chatbot UI", () => {
153
157
  );
154
158
  });
155
159
 
160
+ it("copies only the completed assistant reply and reports clipboard failures", async () => {
161
+ const user = userEvent.setup();
162
+ render(<ChatbotWidget defaultOpen />);
163
+
164
+ expect(screen.queryByRole("group", { name: "Response actions" })).not.toBeInTheDocument();
165
+ await user.type(screen.getByLabelText("Chat message"), "Where can I find reports?{Enter}");
166
+
167
+ const actions = await screen.findByRole("group", { name: "Response actions" });
168
+ const copy = within(actions).getByRole("button", { name: "Copy response" });
169
+ await user.click(copy);
170
+ expect(await navigator.clipboard.readText()).toBe(
171
+ "Transformer oil reports are available in the Reports page."
172
+ );
173
+ expect(within(actions).getByRole("status")).toHaveTextContent("Copied");
174
+
175
+ vi.spyOn(navigator.clipboard, "writeText").mockRejectedValueOnce(new Error("Access denied"));
176
+ await user.click(copy);
177
+ expect(within(actions).getByRole("status")).toHaveTextContent("Couldn’t copy");
178
+
179
+ await user.click(screen.getByRole("button", { name: "Edit message" }));
180
+ expect(screen.getByLabelText("Chat message")).toHaveValue("Where can I find reports?");
181
+ expect(screen.getByLabelText("Chat message")).toHaveFocus();
182
+ });
183
+
184
+ it("shows live progress and Markdown, then keeps the displayed reply when stopped", async () => {
185
+ const user = userEvent.setup();
186
+ const original = vi.mocked(fetch).getMockImplementation()!;
187
+ const encoder = new TextEncoder();
188
+ let streamController: ReadableStreamDefaultController<Uint8Array> | undefined;
189
+ let signal: AbortSignal | null | undefined;
190
+ vi.mocked(fetch).mockImplementation(async (input, init) => {
191
+ if (!String(input).endsWith("/messages/stream")) return original(input, init);
192
+ signal = init?.signal;
193
+ return new Response(new ReadableStream<Uint8Array>({
194
+ start(controller) {
195
+ streamController = controller;
196
+ signal?.addEventListener("abort", () => controller.error(new DOMException("Aborted", "AbortError")));
197
+ },
198
+ }), { headers: { "Content-Type": "text/event-stream" } });
199
+ });
200
+
201
+ render(<ChatbotWidget defaultOpen />);
202
+ const input = screen.getByLabelText("Chat message");
203
+ await user.type(input, "Where are reports?{Enter}");
204
+ await waitFor(() => expect(streamController).toBeDefined());
205
+ const thread = within(screen.getByLabelText("Chat messages"));
206
+ const activity = thread.getByRole("button", { name: "Thinking" });
207
+ expect(activity).toHaveAttribute("aria-expanded", "true");
208
+
209
+ await act(async () => {
210
+ streamController!.enqueue(encoder.encode(
211
+ 'data: {"type":"progress","stage":"Searching relevant knowledge…"}\n\n' +
212
+ 'data: {"type":"token","text":"Open **Reports**."}\n\n'
213
+ ));
214
+ });
215
+ expect(await thread.findByText("Reports", { selector: "strong" })).toBeVisible();
216
+ expect(thread.getByText("Searching relevant knowledge…")).toBeVisible();
217
+ expect(thread.queryByRole("group", { name: "Response actions" })).not.toBeInTheDocument();
218
+
219
+ await user.click(screen.getByRole("button", { name: "Stop response" }));
220
+ expect(signal?.aborted).toBe(true);
221
+ expect(thread.getByRole("button", { name: "Response stopped" })).toHaveAttribute("aria-expanded", "false");
222
+ expect(thread.getByText("Reports", { selector: "strong" })).toBeVisible();
223
+ expect(input).toBeEnabled();
224
+ });
225
+
226
+ it("plays one completion sound per shared reply and lets the user mute it", async () => {
227
+ const user = userEvent.setup();
228
+ const start = vi.fn();
229
+ class TestAudioContext {
230
+ state = "running";
231
+ currentTime = 0;
232
+ destination = {};
233
+ createOscillator() {
234
+ return { frequency: { value: 0 }, connect: vi.fn(), start, stop: vi.fn(), disconnect: vi.fn() };
235
+ }
236
+ createGain() {
237
+ return {
238
+ gain: { setValueAtTime: vi.fn(), exponentialRampToValueAtTime: vi.fn() },
239
+ connect: vi.fn(),
240
+ disconnect: vi.fn(),
241
+ };
242
+ }
243
+ async close() {}
244
+ }
245
+ vi.stubGlobal("AudioContext", TestAudioContext);
246
+ render(<ChatProvider><ChatbotWidget defaultOpen /><EmbeddedChatbot defaultOpen showTrigger={false} /></ChatProvider>);
247
+
248
+ const [input] = screen.getAllByLabelText("Chat message");
249
+ const [mute, otherMute] = screen.getAllByRole("button", { name: "Response sound" });
250
+ expect(mute).toHaveAttribute("aria-pressed", "true");
251
+ await user.type(input!, "Where are reports?{Enter}");
252
+ await waitFor(() => expect(start).toHaveBeenCalledTimes(2));
253
+
254
+ await user.click(mute!);
255
+ expect(otherMute).toHaveAttribute("aria-pressed", "false");
256
+ await user.type(input!, "Where are samples?{Enter}");
257
+ await waitFor(() => expect(screen.getAllByText("Transformer oil reports are available in the Reports page.")).toHaveLength(4));
258
+ expect(start).toHaveBeenCalledTimes(2);
259
+ });
260
+
156
261
  it("selects a configured AI model for the next turn", async () => {
157
262
  const user = userEvent.setup();
158
263
  const original = vi.mocked(fetch).getMockImplementation()!;
@@ -244,10 +349,9 @@ describe("chatbot UI", () => {
244
349
  await user.keyboard("{Enter}");
245
350
 
246
351
  await waitFor(() => {
247
- expect(
248
- screen.getAllByText(/unable to process the chat request right now/i).length
249
- ).toBeGreaterThan(0);
352
+ expect(screen.getAllByText(/unable to process the chat request right now/i)).toHaveLength(1);
250
353
  });
354
+ expect(screen.queryByRole("group", { name: "Response actions" })).not.toBeInTheDocument();
251
355
 
252
356
  fetchMock.mockImplementation(async (input, init) => {
253
357
  const url = String(input);
@@ -280,7 +384,7 @@ describe("chatbot UI", () => {
280
384
  <ChatProvider>
281
385
  <ChatbotWidget defaultOpen />
282
386
  <div data-testid="second-surface">
283
- <ChatPanel />
387
+ <EmbeddedChatbot defaultOpen showTrigger={false} />
284
388
  </div>
285
389
  </ChatProvider>
286
390
  );
@@ -295,6 +399,20 @@ describe("chatbot UI", () => {
295
399
  ).toBeGreaterThan(1);
296
400
  });
297
401
  expect(within(screen.getByTestId("second-surface")).getByText("shared question")).toBeTruthy();
402
+ expect(screen.getAllByRole("button", { name: /thought for/i })).toHaveLength(2);
403
+ expect(screen.queryByText(/retrieved VPS sources?/i)).not.toBeInTheDocument();
404
+ expect(screen.queryByRole("button", { name: /inspect sources/i })).not.toBeInTheDocument();
405
+ expect(screen.queryByText("Score 0.98")).not.toBeInTheDocument();
406
+
407
+ const [widgetLike, embeddedLike] = screen.getAllByRole("button", { name: "Like response" });
408
+ const [widgetDislike, embeddedDislike] = screen.getAllByRole("button", { name: "Dislike response" });
409
+ await user.click(widgetLike!);
410
+ expect(embeddedLike).toHaveAttribute("aria-pressed", "true");
411
+ await user.click(embeddedDislike!);
412
+ expect(widgetLike).toHaveAttribute("aria-pressed", "false");
413
+ expect(widgetDislike).toHaveAttribute("aria-pressed", "true");
414
+ await user.click(widgetDislike!);
415
+ expect(embeddedDislike).toHaveAttribute("aria-pressed", "false");
298
416
  });
299
417
 
300
418
  it("resolves apiBaseUrl correctly with various proxy and endpoint patterns", () => {
@@ -1,18 +1,40 @@
1
1
  import React, { useEffect, useState } from "react";
2
- import { CheckCircle2, LoaderCircle } from "lucide-react";
2
+ import { CheckCircle2, LoaderCircle, Square, Wrench } from "lucide-react";
3
+ import { Marker, MarkerContent, MarkerIcon } from "../../components/ui/marker";
4
+ import { Reasoning, ReasoningContent, ReasoningTrigger } from "../../components/ai-elements/reasoning";
5
+ import {
6
+ Trace,
7
+ TraceDescription,
8
+ TraceIcon,
9
+ TraceLine,
10
+ TraceTitle,
11
+ } from "../../components/ui/trace";
12
+ import type { ToolCall } from "../api/chatbot-types";
3
13
 
4
14
  interface AgentReasoningProps {
5
- status?: "pending" | "complete" | "error";
15
+ status?: "pending" | "complete" | "stopped";
6
16
  progressText?: string;
17
+ progressSteps?: string[];
7
18
  durationMs?: number;
19
+ toolCalls?: ToolCall[];
20
+ }
21
+
22
+ function toolLabel(name: string): string {
23
+ if (name === "create_ticket") return "Support ticket processed";
24
+ if (name === "get_customer") return "Account verified";
25
+ if (name === "get_ticket") return "Ticket status loaded";
26
+ return "Information retrieved";
8
27
  }
9
28
 
10
29
  export const AgentReasoning: React.FC<AgentReasoningProps> = ({
11
30
  status = "complete",
12
31
  progressText,
32
+ progressSteps = [],
13
33
  durationMs,
34
+ toolCalls = [],
14
35
  }) => {
15
36
  const isPending = status === "pending";
37
+ const isStopped = status === "stopped";
16
38
  const [seconds, setSeconds] = useState(0);
17
39
 
18
40
  useEffect(() => {
@@ -24,42 +46,52 @@ export const AgentReasoning: React.FC<AgentReasoningProps> = ({
24
46
  return () => clearInterval(interval);
25
47
  }, [isPending]);
26
48
 
27
- const durationDisplay = isPending
28
- ? `${seconds.toFixed(1)}s`
29
- : durationMs === undefined
30
- ? undefined
31
- : `${(durationMs / 1000).toFixed(1)}s`;
49
+ const hasActivity = progressSteps.length > 0 || toolCalls.length > 0;
50
+ const duration = durationMs === undefined ? undefined : Number((durationMs / 1000).toFixed(1));
32
51
 
33
- return (
34
- <div className={`agent-reasoning-container${isPending ? " agent-reasoning--active" : ""}`}>
35
- <div
36
- className="agent-reasoning-header"
37
- role="status"
38
- aria-live="off"
39
- >
40
- <div className="agent-reasoning-header-left">
52
+ if (!hasActivity) {
53
+ return (
54
+ <Trace className="chat-response-trace">
55
+ <TraceLine status={isPending ? "running" : undefined}>
56
+ <TraceIcon>
57
+ {isPending ? <LoaderCircle size={14} className="trace-spinner" /> : <CheckCircle2 size={14} />}
58
+ </TraceIcon>
59
+ <TraceTitle>{isPending ? progressText || "Thinking" : isStopped ? "Response stopped" : "Thought"}</TraceTitle>
41
60
  {isPending ? (
42
- <LoaderCircle
43
- size={13}
44
- className="agent-reasoning-spinner"
45
- aria-hidden="true"
46
- />
47
- ) : (
48
- <CheckCircle2
49
- size={13}
50
- className="agent-reasoning-done-icon"
51
- aria-hidden="true"
52
- />
61
+ <TraceDescription aria-hidden="true">{seconds.toFixed(1)}s</TraceDescription>
62
+ ) : !isStopped && duration !== undefined && (
63
+ <TraceDescription>{duration}s</TraceDescription>
53
64
  )}
54
- <span className="agent-reasoning-title">
55
- {isPending
56
- ? `${progressText || "Working…"} · ${durationDisplay}`
57
- : durationDisplay
58
- ? `Response generated in ${durationDisplay}`
59
- : "Response generated"}
60
- </span>
61
- </div>
62
- </div>
63
- </div>
65
+ </TraceLine>
66
+ </Trace>
67
+ );
68
+ }
69
+
70
+ return (
71
+ <Reasoning className="chat-response-trace" isStreaming={isPending} duration={duration}>
72
+ <ReasoningTrigger
73
+ getThinkingMessage={isStopped ? () => "Response stopped" : undefined}
74
+ icon={isStopped ? <Square size={12} /> : undefined}
75
+ description={isPending ? `${seconds.toFixed(1)}s` : undefined}
76
+ />
77
+ <ReasoningContent>
78
+ <Trace>
79
+ {progressSteps.map((step, index) => (
80
+ <Marker key={`${step}-${index}`}>
81
+ <MarkerIcon>
82
+ <span className="chat-progress-dot" />
83
+ </MarkerIcon>
84
+ <MarkerContent>{step}</MarkerContent>
85
+ </Marker>
86
+ ))}
87
+ {toolCalls.map((call, index) => (
88
+ <TraceLine key={`${call.toolName}-${index}`}>
89
+ <TraceIcon><Wrench size={13} /></TraceIcon>
90
+ <TraceTitle>{toolLabel(call.toolName)}</TraceTitle>
91
+ </TraceLine>
92
+ ))}
93
+ </Trace>
94
+ </ReasoningContent>
95
+ </Reasoning>
64
96
  );
65
97
  };
@@ -2,6 +2,7 @@ import { createContext, useContext } from "react";
2
2
  import type {
3
3
  ChatMessage,
4
4
  ChatUserContext,
5
+ MessageFeedback,
5
6
  Suggestion,
6
7
  Ticket,
7
8
  ModelOption,
@@ -29,7 +30,11 @@ export interface ChatContextValue {
29
30
  apiBaseUrl?: string;
30
31
  hideInspectSources?: boolean;
31
32
  showGroundedSources?: boolean;
33
+ soundEnabled: boolean;
34
+ toggleSound: () => void;
32
35
  sendMessage: (text: string) => Promise<void>;
36
+ stopResponse: () => void;
37
+ toggleMessageFeedback: (messageId: string, feedback: MessageFeedback) => void;
33
38
  retryLast: () => Promise<void>;
34
39
  confirmTicket: (customerIdOrEmail?: string) => Promise<void>;
35
40
  cancelTicket: () => void;
@@ -1,21 +1,22 @@
1
1
  import React from "react";
2
2
  import { BotMessageSquare } from "lucide-react";
3
+ import { Bubble, BubbleContent } from "../../components/ui/bubble";
4
+ import { Message, MessageAvatar, MessageContent } from "../../components/ui/message";
3
5
 
4
6
  export const ChatEmptyState: React.FC = () => {
5
7
  return (
6
- <div className="chat-empty-row">
7
- <div
8
- className="avatar-circle avatar-circle--mt"
9
- aria-hidden="true"
10
- >
8
+ <Message>
9
+ <MessageAvatar className="avatar-circle" aria-hidden="true">
11
10
  <BotMessageSquare size={15} />
12
- </div>
13
- <div className="chat-empty-bubble">
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>
11
+ </MessageAvatar>
12
+ <MessageContent>
13
+ <Bubble>
14
+ <BubbleContent>
15
+ Hello — I am the VPS Veritas assistant. Ask about reports, sample status,
16
+ registration, or support, or choose a suggested question.
17
+ </BubbleContent>
18
+ </Bubble>
19
+ </MessageContent>
20
+ </Message>
20
21
  );
21
22
  };
@@ -1,4 +1,7 @@
1
1
  import React from "react";
2
+ import { CircleAlert } from "lucide-react";
3
+ import { Message, MessageContent, MessageFooter } from "../../components/ui/message";
4
+ import { Trace, TraceIcon, TraceLine, TraceTitle } from "../../components/ui/trace";
2
5
 
3
6
  interface ChatErrorProps {
4
7
  message: string;
@@ -7,20 +10,25 @@ interface ChatErrorProps {
7
10
 
8
11
  export const ChatError: React.FC<ChatErrorProps> = ({ message, onRetry }) => {
9
12
  return (
10
- <div
13
+ <Message
11
14
  className="chat-error-banner"
12
15
  role="alert"
13
16
  >
14
- <p>{message}</p>
15
- {onRetry && (
16
- <button
17
- type="button"
18
- onClick={onRetry}
19
- className="chat-error-retry-btn"
20
- >
21
- Try again
22
- </button>
23
- )}
24
- </div>
17
+ <MessageContent>
18
+ <Trace className="chat-message-body">
19
+ <TraceLine status="error">
20
+ <TraceIcon><CircleAlert size={14} /></TraceIcon>
21
+ <TraceTitle className="chat-error-title">{message}</TraceTitle>
22
+ </TraceLine>
23
+ </Trace>
24
+ {onRetry && (
25
+ <MessageFooter>
26
+ <button type="button" onClick={onRetry} className="chat-error-retry-btn">
27
+ Try again
28
+ </button>
29
+ </MessageFooter>
30
+ )}
31
+ </MessageContent>
32
+ </Message>
25
33
  );
26
34
  };
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useRef } from "react";
2
- import { ArrowLeft, Minus, RefreshCw } from "lucide-react";
2
+ import { ArrowLeft, Minus, RefreshCw, Volume2, VolumeX } from "lucide-react";
3
3
  import { EnvBadge, type EnvStage } from "../../components/EnvBadge";
4
4
 
5
5
  interface ChatHeaderProps {
@@ -8,6 +8,8 @@ interface ChatHeaderProps {
8
8
  onClose?: () => void;
9
9
  onReset?: () => void;
10
10
  onBack?: () => void;
11
+ soundEnabled?: boolean;
12
+ onToggleSound?: () => void;
11
13
  showMinimize?: boolean;
12
14
  /** Environment badge stage shown in the header. Omit for production. */
13
15
  envStage?: EnvStage;
@@ -36,6 +38,8 @@ export const ChatHeader: React.FC<ChatHeaderProps> = ({
36
38
  onClose,
37
39
  onReset,
38
40
  onBack,
41
+ soundEnabled,
42
+ onToggleSound,
39
43
  showMinimize = false,
40
44
  envStage,
41
45
  envPulse = true,
@@ -71,6 +75,18 @@ export const ChatHeader: React.FC<ChatHeaderProps> = ({
71
75
  </div>
72
76
  </div>
73
77
  <div className="chat-header-actions">
78
+ {onToggleSound && (
79
+ <button
80
+ type="button"
81
+ className="icon-btn-action chat-sound-btn"
82
+ aria-label="Response sound"
83
+ aria-pressed={Boolean(soundEnabled)}
84
+ title={soundEnabled ? "Mute response sound" : "Enable response sound"}
85
+ onClick={onToggleSound}
86
+ >
87
+ {soundEnabled ? <Volume2 size={16} aria-hidden="true" /> : <VolumeX size={16} aria-hidden="true" />}
88
+ </button>
89
+ )}
74
90
  {onReset && (
75
91
  <button
76
92
  type="button"
@@ -0,0 +1,63 @@
1
+ import {
2
+ InlineCitation,
3
+ InlineCitationCard,
4
+ InlineCitationCardBody,
5
+ InlineCitationCardTrigger,
6
+ InlineCitationCarousel,
7
+ InlineCitationCarouselContent,
8
+ InlineCitationCarouselHeader,
9
+ InlineCitationCarouselIndex,
10
+ InlineCitationCarouselItem,
11
+ InlineCitationCarouselNext,
12
+ InlineCitationCarouselPrev,
13
+ InlineCitationQuote,
14
+ InlineCitationSource,
15
+ } from "../../components/ai-elements/inline-citation";
16
+ import { safeHref } from "../../lib/safeHref";
17
+ import type { Source } from "../api/chatbot-types";
18
+ import { formatDocTitle, getRouteHint } from "./GroundedSources";
19
+
20
+ export function ChatInlineCitation({ label, sources }: { label: string; sources: Source[] }) {
21
+ const entries = sources.map((source) => {
22
+ const title = formatDocTitle(source);
23
+ const url = safeHref(source.url || source.source) ?? getRouteHint(source.source)?.path;
24
+ return {
25
+ key: source.chunkId,
26
+ label: url || title,
27
+ content: (
28
+ <>
29
+ <InlineCitationSource title={title} url={url} />
30
+ {source.snippet && <InlineCitationQuote>{source.snippet}</InlineCitationQuote>}
31
+ </>
32
+ ),
33
+ };
34
+ });
35
+
36
+ return (
37
+ <InlineCitation>
38
+ <InlineCitationCard>
39
+ <InlineCitationCardTrigger sources={entries.map((entry) => entry.label)} aria-label={"View sources " + label}>
40
+ {label}
41
+ </InlineCitationCardTrigger>
42
+ <InlineCitationCardBody>
43
+ {entries.length === 1 ? entries[0].content : (
44
+ <InlineCitationCarousel aria-label="Sources">
45
+ <InlineCitationCarouselHeader>
46
+ <InlineCitationCarouselIndex />
47
+ <InlineCitationCarouselPrev />
48
+ <InlineCitationCarouselNext />
49
+ </InlineCitationCarouselHeader>
50
+ <InlineCitationCarouselContent>
51
+ {entries.map((entry, index) => (
52
+ <InlineCitationCarouselItem key={entry.key + "-" + index} aria-label={"Source " + (index + 1)}>
53
+ {entry.content}
54
+ </InlineCitationCarouselItem>
55
+ ))}
56
+ </InlineCitationCarouselContent>
57
+ </InlineCitationCarousel>
58
+ )}
59
+ </InlineCitationCardBody>
60
+ </InlineCitationCard>
61
+ </InlineCitation>
62
+ );
63
+ }