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
@@ -1,5 +1,11 @@
1
- import React, { useEffect, useMemo, useRef, useState } from "react";
2
- import { ArrowUp } from "lucide-react";
1
+ import React, { useEffect, useId, useImperativeHandle, useMemo, useRef, useState } from "react";
2
+ import { ArrowUp, Square } from "lucide-react";
3
+ import {
4
+ InputGroup,
5
+ InputGroupAddon,
6
+ InputGroupButton,
7
+ InputGroupTextarea,
8
+ } from "../../components/ui/input-group";
3
9
  import { useRestoreInputFocus } from "./ChatHeader";
4
10
  import { ChatSuggestions, filterSuggestions } from "./ChatSuggestions";
5
11
  import { useChatbot } from "../hooks/useChatbot";
@@ -7,19 +13,28 @@ import type { Suggestion } from "../api/chatbot-types";
7
13
 
8
14
  interface ChatInputProps {
9
15
  onSend: (message: string) => void;
16
+ onStop?: () => void;
10
17
  disabled?: boolean;
11
18
  placeholder?: string;
19
+ ref?: React.Ref<ChatInputHandle>;
20
+ }
21
+
22
+ export interface ChatInputHandle {
23
+ edit: (text: string) => void;
12
24
  }
13
25
 
14
26
  export const ChatInput: React.FC<ChatInputProps> = ({
15
27
  onSend,
28
+ onStop,
16
29
  disabled = false,
17
30
  placeholder = "Ask something…",
31
+ ref,
18
32
  }) => {
19
33
  const { suggestions, showSuggestions, suggestionBadgesEnabled, models, selectedModelId, selectModel } = useChatbot();
20
34
  const [text, setText] = useState("");
21
35
  const textareaRef = useRef<HTMLTextAreaElement>(null);
22
- const modelPickerId = React.useId();
36
+ const inputId = useId();
37
+ const modelPickerId = useId();
23
38
  const resize = (element?: HTMLTextAreaElement | null) => {
24
39
  if (!element) return;
25
40
  element.style.height = "auto";
@@ -28,6 +43,14 @@ export const ChatInput: React.FC<ChatInputProps> = ({
28
43
 
29
44
  useRestoreInputFocus(disabled, textareaRef);
30
45
 
46
+ useImperativeHandle(ref, () => ({
47
+ edit(nextText) {
48
+ if (disabled) return;
49
+ setText(nextText);
50
+ textareaRef.current?.focus();
51
+ },
52
+ }), [disabled]);
53
+
31
54
  useEffect(() => {
32
55
  resize(textareaRef.current);
33
56
  }, [text]);
@@ -50,9 +73,6 @@ export const ChatInput: React.FC<ChatInputProps> = ({
50
73
  if (!value || disabled) return;
51
74
  onSend(value);
52
75
  setText("");
53
- if (textareaRef.current) {
54
- textareaRef.current.style.height = "auto";
55
- }
56
76
  };
57
77
 
58
78
  return (
@@ -63,52 +83,54 @@ export const ChatInput: React.FC<ChatInputProps> = ({
63
83
  onSelect={applySuggestion}
64
84
  disabled={disabled}
65
85
  />
66
- <label htmlFor="vps-chat-input" className="sr-only">
67
- Chat message
68
- </label>
69
- <div className="chat-input-row">
70
- <textarea
71
- id="vps-chat-input"
72
- ref={textareaRef}
73
- rows={1}
74
- value={text}
75
- disabled={disabled}
76
- placeholder={placeholder}
77
- onChange={(event) => {
78
- setText(event.target.value);
79
- resize(event.target);
80
- }}
81
- onKeyDown={(event) => {
82
- if (event.key === "Enter" && !event.shiftKey) {
83
- event.preventDefault();
84
- send();
85
- }
86
- }}
87
- className="chat-textarea"
88
- />
89
- <button
90
- type="button"
91
- onClick={send}
92
- disabled={disabled || !text.trim()}
93
- aria-label="Send message"
94
- className="chat-send-btn"
95
- >
96
- <ArrowUp size={16} />
97
- </button>
98
- </div>
99
- {models.length > 1 && (
100
- <div className="chat-model-picker">
101
- <label htmlFor={modelPickerId}>AI model</label>
102
- <select id={modelPickerId} aria-label="AI model" value={selectedModelId} disabled={disabled}
103
- onChange={(event) => selectModel(event.target.value)}>
104
- <option value="auto">Automatic</option>
105
- {models.map((model) => (
106
- <option key={model.id} value={model.id} disabled={!model.configured}>{model.label}</option>
107
- ))}
108
- </select>
109
- </div>
110
- )}
86
+ <form onSubmit={(event) => {
87
+ event.preventDefault();
88
+ send();
89
+ }}>
90
+ <label htmlFor={inputId} className="sr-only">Chat message</label>
91
+ <InputGroup>
92
+ <InputGroupTextarea
93
+ id={inputId}
94
+ ref={textareaRef}
95
+ rows={1}
96
+ value={text}
97
+ disabled={disabled}
98
+ placeholder={placeholder}
99
+ onChange={(event) => setText(event.target.value)}
100
+ onKeyDown={(event) => {
101
+ if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) {
102
+ event.preventDefault();
103
+ event.currentTarget.form?.requestSubmit();
104
+ }
105
+ }}
106
+ />
107
+ <InputGroupAddon>
108
+ {models.length > 1 && (
109
+ <div className="chat-model-picker">
110
+ <label htmlFor={modelPickerId} className="sr-only">AI model</label>
111
+ <select id={modelPickerId} value={selectedModelId} disabled={disabled}
112
+ onChange={(event) => selectModel(event.target.value)}>
113
+ <option value="auto">Automatic</option>
114
+ {models.map((model) => (
115
+ <option key={model.id} value={model.id} disabled={!model.configured}>{model.label}</option>
116
+ ))}
117
+ </select>
118
+ </div>
119
+ )}
120
+ {onStop ? (
121
+ <InputGroupButton onClick={onStop} aria-label="Stop response" title="Stop response">
122
+ <Square size={13} fill="currentColor" aria-hidden="true" />
123
+ </InputGroupButton>
124
+ ) : (
125
+ <InputGroupButton type="submit" disabled={disabled || !text.trim()} aria-label="Send message" title="Send message">
126
+ <ArrowUp size={16} aria-hidden="true" />
127
+ </InputGroupButton>
128
+ )}
129
+ </InputGroupAddon>
130
+ </InputGroup>
131
+ </form>
111
132
  <p className="chat-input-footer">
133
+ <span className="chat-input-note">AI can make mistakes.</span>
112
134
  Powered by <span className="chat-input-footer-brand">VPS Veritas AI</span>
113
135
  </p>
114
136
  </div>
@@ -1,11 +1,11 @@
1
1
  import React from "react";
2
+ import { Check, Copy } from "lucide-react";
3
+ import { useCopyText } from "../hooks/useCopyText";
4
+ import { safeHref } from "../../lib/safeHref";
5
+ import type { Source } from "../api/chatbot-types";
6
+ import { ChatInlineCitation } from "./ChatInlineCitation";
2
7
 
3
- export function safeHref(value: string): string | undefined {
4
- const url = value.trim();
5
- if (/[\u0000-\u001f\u007f]/.test(url)) return undefined;
6
- if (/^(https?:\/\/|mailto:|\/(?!\/)|#)/i.test(url)) return url;
7
- return undefined;
8
- }
8
+ export { safeHref } from "../../lib/safeHref";
9
9
 
10
10
  /**
11
11
  * Robust inline Markdown renderer supporting:
@@ -15,18 +15,25 @@ export function safeHref(value: string): string | undefined {
15
15
  * - Italic *text* and _text_
16
16
  * - Inline code `text`
17
17
  */
18
- function renderInline(text: string): React.ReactNode[] {
18
+ function renderInline(text: string, sources?: Source[]): React.ReactNode[] {
19
19
  if (!text) return [];
20
20
 
21
21
  // Match: [text](url) | **bold** | *italic* | `code` | https?://...
22
22
  const tokenRegex =
23
- /(\[[^\]]+\]\([^)]+\)|\*\*[^*]+\*\*|\*[^*]+\*|`[^`]+`|https?:\/\/[^\s]+)/g;
23
+ /(\[[^\]]+\]\([^)]+\)|\*\*[^*]+\*\*|\*[^*]+\*|`[^`]+`|https?:\/\/[^\s]+|\[S\d+(?:\s*,\s*S\d+)*\])/g;
24
24
 
25
25
  const parts = text.split(tokenRegex);
26
26
 
27
27
  return parts.map((part, index) => {
28
28
  if (!part) return null;
29
29
 
30
+ if (sources?.length && /^\[S\d+(?:\s*,\s*S\d+)*\]$/.test(part)) {
31
+ const cited = [...new Set(part.match(/\d+/g))].map((number) => sources[Number(number) - 1]);
32
+ if (cited.every((source) => source !== undefined)) {
33
+ return <ChatInlineCitation key={index} label={part} sources={cited} />;
34
+ }
35
+ }
36
+
30
37
  // Markdown link: [text](url)
31
38
  const linkMatch = part.match(/^\[([^\]]+)\]\(([^)]+)\)$/);
32
39
  if (linkMatch) {
@@ -228,27 +235,70 @@ function parseBlocks(markdown: string): Block[] {
228
235
  return blocks;
229
236
  }
230
237
 
231
- export const ChatMarkdown = React.memo(function ChatMarkdown({ text }: { text: string }) {
238
+ function MarkdownCode({ code, lang, streaming }: { code: string; lang: string; streaming: boolean }) {
239
+ const { status, copy } = useCopyText();
240
+
241
+ return (
242
+ <div className="md-code-block">
243
+ <div className="md-code-header">
244
+ <span>{lang || "Code"}</span>
245
+ {!streaming && (
246
+ <>
247
+ <span className="md-code-status" role="status">
248
+ {status === "copied" && "Copied"}
249
+ {status === "failed" && "Couldn’t copy"}
250
+ </span>
251
+ <button
252
+ type="button"
253
+ className="chat-message-action"
254
+ aria-label="Copy code"
255
+ title="Copy code"
256
+ disabled={status === "copying"}
257
+ onClick={() => void copy(code)}
258
+ >
259
+ {status === "copied" ? <Check size={15} aria-hidden="true" /> : <Copy size={15} aria-hidden="true" />}
260
+ </button>
261
+ </>
262
+ )}
263
+ </div>
264
+ <pre className="md-pre"><code>
265
+ {code.split("\n").map((line, index) => (
266
+ <span className="md-code-line" key={index}>
267
+ <span className="md-code-number" aria-hidden="true">{index + 1}</span>
268
+ <span>{line || " "}</span>
269
+ </span>
270
+ ))}
271
+ </code></pre>
272
+ </div>
273
+ );
274
+ }
275
+
276
+ export const ChatMarkdown = React.memo(function ChatMarkdown({
277
+ text,
278
+ streaming = false,
279
+ sources,
280
+ }: { text: string; streaming?: boolean; sources?: Source[] }) {
232
281
  if (!text) return null;
233
282
 
234
283
  const blocks = parseBlocks(text);
284
+ const inline = (value: string) => renderInline(value, sources);
235
285
 
236
286
  return (
237
287
  <div className="md-content">
238
288
  {blocks.map((block, idx) => {
239
289
  switch (block.type) {
240
290
  case "h": {
241
- if (block.level === 1) return <h2 key={idx} className="md-h1">{renderInline(block.content)}</h2>;
242
- if (block.level === 2) return <h3 key={idx} className="md-h2">{renderInline(block.content)}</h3>;
243
- if (block.level === 3) return <h4 key={idx} className="md-h3">{renderInline(block.content)}</h4>;
244
- return <h5 key={idx} className="md-h4">{renderInline(block.content)}</h5>;
291
+ if (block.level === 1) return <h2 key={idx} className="md-h1">{inline(block.content)}</h2>;
292
+ if (block.level === 2) return <h3 key={idx} className="md-h2">{inline(block.content)}</h3>;
293
+ if (block.level === 3) return <h4 key={idx} className="md-h3">{inline(block.content)}</h4>;
294
+ return <h5 key={idx} className="md-h4">{inline(block.content)}</h5>;
245
295
  }
246
296
  case "ul":
247
297
  return (
248
298
  <ul key={idx} className="md-ul">
249
299
  {block.items.map((item, itemIdx) => (
250
300
  <li key={itemIdx} className="md-li">
251
- {renderInline(item)}
301
+ {inline(item)}
252
302
  </li>
253
303
  ))}
254
304
  </ul>
@@ -258,22 +308,18 @@ export const ChatMarkdown = React.memo(function ChatMarkdown({ text }: { text: s
258
308
  <ol key={idx} className="md-ol">
259
309
  {block.items.map((item, itemIdx) => (
260
310
  <li key={itemIdx} className="md-li">
261
- {renderInline(item)}
311
+ {inline(item)}
262
312
  </li>
263
313
  ))}
264
314
  </ol>
265
315
  );
266
316
  case "code":
267
- return (
268
- <pre key={idx} className="md-pre">
269
- <code>{block.code}</code>
270
- </pre>
271
- );
317
+ return <MarkdownCode key={idx} code={block.code} lang={block.lang} streaming={streaming} />;
272
318
  case "quote":
273
319
  return (
274
320
  <blockquote key={idx} className="md-quote">
275
321
  {block.lines.map((line, qIdx) => (
276
- <p key={qIdx}>{renderInline(line)}</p>
322
+ <p key={qIdx}>{inline(line)}</p>
277
323
  ))}
278
324
  </blockquote>
279
325
  );
@@ -286,7 +332,7 @@ export const ChatMarkdown = React.memo(function ChatMarkdown({ text }: { text: s
286
332
  <thead>
287
333
  <tr>
288
334
  {block.headers.map((h, hIdx) => (
289
- <th key={hIdx}>{renderInline(h)}</th>
335
+ <th key={hIdx}>{inline(h)}</th>
290
336
  ))}
291
337
  </tr>
292
338
  </thead>
@@ -294,7 +340,7 @@ export const ChatMarkdown = React.memo(function ChatMarkdown({ text }: { text: s
294
340
  {block.rows.map((row, rIdx) => (
295
341
  <tr key={rIdx}>
296
342
  {row.map((cell, cIdx) => (
297
- <td key={cIdx}>{renderInline(cell)}</td>
343
+ <td key={cIdx}>{inline(cell)}</td>
298
344
  ))}
299
345
  </tr>
300
346
  ))}
@@ -308,7 +354,7 @@ export const ChatMarkdown = React.memo(function ChatMarkdown({ text }: { text: s
308
354
  <p key={idx} className="md-p">
309
355
  {block.lines.map((line, lineIdx) => (
310
356
  <React.Fragment key={lineIdx}>
311
- {renderInline(line)}
357
+ {inline(line)}
312
358
  {lineIdx < block.lines.length - 1 && <br />}
313
359
  </React.Fragment>
314
360
  ))}
@@ -1,118 +1,107 @@
1
1
  import React from "react";
2
- import { Check, BotMessageSquare } from "lucide-react";
3
- import type { ChatMessage, ToolCall } from "../api/chatbot-types";
2
+ import { BotMessageSquare, Check, Pencil } from "lucide-react";
3
+ import { Bubble, BubbleContent } from "../../components/ui/bubble";
4
+ import {
5
+ Message,
6
+ MessageAvatar,
7
+ MessageContent,
8
+ MessageFooter,
9
+ MessageHeader,
10
+ } from "../../components/ui/message";
11
+ import type { ChatMessage } from "../api/chatbot-types";
12
+ import { ChatMessageActions } from "./ChatMessageActions";
4
13
  import { ChatMarkdown } from "./ChatMarkdown";
5
- import { ChatTypingIndicator } from "./ChatTypingIndicator";
6
14
  import { AgentReasoning } from "./AgentReasoning";
7
15
  import { GroundedSources } from "./GroundedSources";
8
16
 
9
17
  import { useOptionalChatContext } from "./ChatContext";
10
18
 
11
- function toolLabel(name: string): string {
12
- if (name === "create_ticket") return "Support ticket processed";
13
- if (name === "get_customer") return "Account verified";
14
- if (name === "get_ticket") return "Ticket status loaded";
15
- return "Information retrieved";
16
- }
17
-
18
- function Tools({ toolCalls }: { toolCalls: ToolCall[] }) {
19
- if (!toolCalls.length) return null;
20
- return (
21
- <div className="tool-badges">
22
- {toolCalls.map((call, index) => (
23
- <span
24
- key={`${call.toolName}-${index}`}
25
- className="tool-badge"
26
- >
27
- {toolLabel(call.toolName)}
28
- </span>
29
- ))}
30
- </div>
31
- );
32
- }
33
-
34
19
  interface ChatMessageProps {
35
20
  message: ChatMessage;
21
+ onEdit?: (text: string) => void;
36
22
  }
37
23
 
38
- export const ChatMessageBubble: React.FC<ChatMessageProps> = ({ message }) => {
24
+ export const ChatMessageBubble: React.FC<ChatMessageProps> = ({ message, onEdit }) => {
39
25
  const chatCtx = useOptionalChatContext();
40
26
  const hideInspectSources = chatCtx?.hideInspectSources ?? false;
41
- const showGroundedSources = chatCtx?.showGroundedSources ?? true;
27
+ const showGroundedSources = chatCtx?.showGroundedSources ?? false;
42
28
 
43
29
  const isUser = message.role === "user";
44
30
  const isError = message.status === "error";
45
31
  const isPending = message.status === "pending";
46
- const isWelcome =
47
- message.id === "welcome-default" ||
48
- message.id.startsWith("welcome") ||
49
- message.id === "welcome";
50
-
51
- // Show response timing only for actual assistant replies and live requests.
52
- const isRealAssistantQuery = Boolean(
53
- isPending ||
54
- message.durationMs !== undefined ||
55
- (message.sources && message.sources.length > 0) ||
56
- (message.toolCalls && message.toolCalls.length > 0) ||
57
- message.usage
32
+ const isStopped = message.status === "stopped";
33
+ const isWelcome = message.id.startsWith("welcome");
34
+ const isAssistantReply = message.role === "assistant" && !isWelcome && !isError;
35
+ const showActivity = isAssistantReply && (
36
+ isPending || isStopped || message.durationMs !== undefined ||
37
+ Boolean(message.progressSteps?.length || message.sources?.length || message.toolCalls?.length || message.usage)
58
38
  );
59
- const showReasoning = !isUser && !isError && !isWelcome && isRealAssistantQuery;
39
+ const showActions = isAssistantReply && !isPending && !isStopped && message.content.trim().length > 0;
60
40
 
61
41
  return (
62
- <div className={`msg-row${isUser ? " msg-row--user" : ""}`}>
63
- {!isUser && (
64
- <div
65
- className="avatar-circle avatar-circle--mt"
66
- aria-hidden="true"
67
- >
42
+ <Message align={isUser ? "end" : "start"}>
43
+ {message.role === "assistant" && (
44
+ <MessageAvatar className="avatar-circle" aria-hidden="true">
68
45
  <BotMessageSquare size={15} />
69
- </div>
46
+ </MessageAvatar>
70
47
  )}
71
- <div className={`msg-col${isUser ? " msg-col--user" : ""}`}>
72
- <div
73
- className={
74
- isUser
75
- ? "msg-bubble msg-bubble--user"
76
- : isError
77
- ? "msg-bubble msg-bubble--error"
78
- : "msg-bubble msg-bubble--bot"
79
- }
80
- >
81
- {/* Show progress and elapsed time without exposing internal model reasoning. */}
82
- {showReasoning && (
48
+ <MessageContent>
49
+ {showActivity && (
50
+ <MessageHeader>
83
51
  <AgentReasoning
84
- status={isPending ? "pending" : "complete"}
52
+ status={isPending ? "pending" : isStopped ? "stopped" : "complete"}
85
53
  progressText={message.progressText}
54
+ progressSteps={message.progressSteps}
86
55
  durationMs={message.durationMs}
56
+ toolCalls={message.toolCalls}
87
57
  />
88
- )}
89
-
90
- {isPending ? (
91
- message.content ? (
92
- <div className="msg-content-wrapper msg-content-wrapper--streaming">
93
- {/* Avoid reparsing the full Markdown document on every token frame. */}
94
- <div className="msg-streaming-text">{message.content}</div>
95
- </div>
96
- ) : (
97
- <ChatTypingIndicator />
98
- )
99
- ) : isUser ? (
100
- <p className="msg-user-pre">{message.content}</p>
101
- ) : (
102
- <div className="msg-content-wrapper">
58
+ </MessageHeader>
59
+ )}
60
+ {isUser ? (
61
+ <Bubble align="end">
62
+ <BubbleContent className="msg-user-pre">{message.content}</BubbleContent>
63
+ </Bubble>
64
+ ) : isWelcome || isError ? (
65
+ <Bubble variant={isError ? "destructive" : "muted"}>
66
+ <BubbleContent>
103
67
  <ChatMarkdown text={message.content} />
104
- </div>
105
- )}
106
-
107
- {message.toolCalls ? <Tools toolCalls={message.toolCalls} /> : null}
108
- {!isUser && !isPending && !isError && showGroundedSources && message.sources?.length ? (
109
- <GroundedSources sources={message.sources} hideInspectSources={hideInspectSources} />
110
- ) : null}
111
- </div>
112
- {isUser && message.status !== "error" && (
113
- <Check size={13} className="msg-tick" aria-hidden="true" />
68
+ </BubbleContent>
69
+ </Bubble>
70
+ ) : message.content && (
71
+ <div className="chat-message-body">
72
+ <ChatMarkdown
73
+ text={message.content}
74
+ streaming={isPending}
75
+ sources={isAssistantReply && !isPending && !isStopped && !hideInspectSources ? message.sources : undefined}
76
+ />
77
+ {isAssistantReply && !isPending && !isStopped && showGroundedSources && message.sources?.length ? (
78
+ <GroundedSources sources={message.sources} hideInspectSources={hideInspectSources} />
79
+ ) : null}
80
+ </div>
81
+ )}
82
+ {showActions && chatCtx && (
83
+ <MessageFooter>
84
+ <ChatMessageActions message={message} onFeedback={chatCtx.toggleMessageFeedback} />
85
+ </MessageFooter>
86
+ )}
87
+ {isUser && !isError && (
88
+ <MessageFooter>
89
+ {onEdit && (
90
+ <button
91
+ type="button"
92
+ className="chat-message-action"
93
+ aria-label="Edit message"
94
+ title="Edit message"
95
+ disabled={chatCtx?.status === "awaiting" || chatCtx?.status === "connecting" || Boolean(chatCtx?.pendingTicket)}
96
+ onClick={() => onEdit(message.content)}
97
+ >
98
+ <Pencil size={14} aria-hidden="true" />
99
+ </button>
100
+ )}
101
+ <Check size={13} className="msg-tick" aria-hidden="true" />
102
+ </MessageFooter>
114
103
  )}
115
- </div>
116
- </div>
104
+ </MessageContent>
105
+ </Message>
117
106
  );
118
107
  };
@@ -0,0 +1,51 @@
1
+ import { Check, Copy, ThumbsDown, ThumbsUp } from "lucide-react";
2
+ import type { ChatMessage, MessageFeedback } from "../api/chatbot-types";
3
+ import { useCopyText } from "../hooks/useCopyText";
4
+
5
+ interface ChatMessageActionsProps {
6
+ message: ChatMessage;
7
+ onFeedback: (messageId: string, feedback: MessageFeedback) => void;
8
+ }
9
+
10
+ export function ChatMessageActions({ message, onFeedback }: ChatMessageActionsProps) {
11
+ const { status: copyStatus, copy } = useCopyText();
12
+
13
+ return (
14
+ <div className="chat-message-actions" role="group" aria-label="Response actions">
15
+ <button
16
+ type="button"
17
+ className="chat-message-action"
18
+ aria-label="Copy response"
19
+ title="Copy response"
20
+ disabled={copyStatus === "copying"}
21
+ onClick={() => void copy(message.content)}
22
+ >
23
+ {copyStatus === "copied" ? <Check size={16} aria-hidden="true" /> : <Copy size={16} aria-hidden="true" />}
24
+ </button>
25
+ <button
26
+ type="button"
27
+ className="chat-message-action"
28
+ aria-label="Like response"
29
+ title="Like response"
30
+ aria-pressed={message.feedback === "like"}
31
+ onClick={() => onFeedback(message.id, "like")}
32
+ >
33
+ <ThumbsUp size={16} aria-hidden="true" />
34
+ </button>
35
+ <button
36
+ type="button"
37
+ className="chat-message-action"
38
+ aria-label="Dislike response"
39
+ title="Dislike response"
40
+ aria-pressed={message.feedback === "dislike"}
41
+ onClick={() => onFeedback(message.id, "dislike")}
42
+ >
43
+ <ThumbsDown size={16} aria-hidden="true" />
44
+ </button>
45
+ <span className="chat-message-copy-status" role="status">
46
+ {copyStatus === "copied" && "Copied"}
47
+ {copyStatus === "failed" && "Couldn’t copy"}
48
+ </span>
49
+ </div>
50
+ );
51
+ }
@@ -10,10 +10,17 @@ import {
10
10
  import { useChatbot } from "../hooks/useChatbot";
11
11
  import { ChatEmptyState } from "./ChatEmptyState";
12
12
  import { ChatMessageBubble } from "./ChatMessage";
13
+ import { ChatSuggestions } from "./ChatSuggestions";
14
+ import type { Suggestion } from "../api/chatbot-types";
13
15
 
14
- export const ChatMessageList: React.FC = () => {
15
- const { messages, status, showSuggestions } = useChatbot();
16
+ export const ChatMessageList: React.FC<{ onEdit?: (text: string) => void }> = ({ onEdit }) => {
17
+ const { messages, status, suggestions, showSuggestions, sendMessage } = useChatbot();
16
18
  const isBusy = status === "awaiting" || status === "connecting";
19
+ const visibleMessages = messages.filter((message) => message.status !== "error");
20
+
21
+ // const handleSuggestionSelect = (suggestion: Suggestion) => {
22
+ // void sendMessage(suggestion.query);
23
+ // };
17
24
 
18
25
  return (
19
26
  <MessageScrollerProvider
@@ -24,18 +31,19 @@ export const ChatMessageList: React.FC = () => {
24
31
  <MessageScroller>
25
32
  <MessageScrollerViewport aria-label="Chat messages">
26
33
  <MessageScrollerContent aria-busy={isBusy}>
27
- {messages.length === 0 && (
34
+ {visibleMessages.length === 0 && (
28
35
  <MessageScrollerItem messageId="welcome">
29
36
  <ChatEmptyState />
30
37
  </MessageScrollerItem>
31
38
  )}
32
- {messages.map((message) => (
39
+ {visibleMessages.map((message) => (
33
40
  <MessageScrollerItem
34
- key={message.id}
35
- messageId={message.id}
41
+ key={message.streamId ?? message.id}
42
+ messageId={message.streamId ?? message.id}
43
+ data-role={message.role}
36
44
  scrollAnchor={message.role === "user"}
37
45
  >
38
- <ChatMessageBubble message={message} />
46
+ <ChatMessageBubble message={message} onEdit={onEdit} />
39
47
  </MessageScrollerItem>
40
48
  ))}
41
49
  </MessageScrollerContent>