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.
- package/dist-lib/types/App.d.ts +1 -0
- package/dist-lib/types/chatbot/api/chatbot-api.d.ts +10 -2
- package/dist-lib/types/chatbot/api/chatbot-types.d.ts +21 -0
- package/dist-lib/types/chatbot/core/AgentReasoning.d.ts +9 -0
- package/dist-lib/types/chatbot/core/ChatContext.d.ts +2 -0
- package/dist-lib/types/chatbot/core/ChatMarkdown.d.ts +2 -2
- package/dist-lib/types/chatbot/core/ChatProvider.d.ts +13 -1
- package/dist-lib/types/chatbot/core/ChatTypingIndicator.d.ts +1 -0
- package/dist-lib/types/chatbot/core/GroundedSources.d.ts +14 -0
- package/dist-lib/types/chatbot/embedded/EmbeddedChatbot.d.ts +13 -1
- package/dist-lib/types/chatbot/index.d.ts +1 -1
- package/dist-lib/types/chatbot/widget/ChatbotWidget.d.ts +13 -1
- package/dist-lib/vps-chatbot.cjs +32 -28
- package/dist-lib/vps-chatbot.js +1262 -1085
- package/package.json +2 -2
- package/src/chatbot/api/chatbot-api.ts +105 -3
- package/src/chatbot/api/chatbot-types.ts +23 -0
- package/src/chatbot/core/AgentReasoning.tsx +60 -0
- package/src/chatbot/core/ChatContext.tsx +2 -0
- package/src/chatbot/core/ChatEmptyState.tsx +4 -4
- package/src/chatbot/core/ChatError.tsx +2 -2
- package/src/chatbot/core/ChatHeader.tsx +13 -13
- package/src/chatbot/core/ChatInput.tsx +6 -6
- package/src/chatbot/core/ChatMarkdown.tsx +280 -55
- package/src/chatbot/core/ChatMessage.tsx +53 -62
- package/src/chatbot/core/ChatMessageList.tsx +1 -1
- package/src/chatbot/core/ChatPanel.tsx +2 -6
- package/src/chatbot/core/ChatProvider.tsx +109 -22
- package/src/chatbot/core/ChatSuggestions.tsx +5 -10
- package/src/chatbot/core/ChatTicketConfirmation.tsx +9 -9
- package/src/chatbot/core/ChatTypingIndicator.tsx +16 -5
- package/src/chatbot/core/GroundedSources.tsx +181 -0
- package/src/chatbot/embedded/EmbeddedChatbot.tsx +33 -4
- package/src/chatbot/embedded/EmbeddedChatbotPanel.tsx +2 -11
- package/src/chatbot/embedded/EmbeddedChatbotTrigger.tsx +2 -2
- package/src/chatbot/index.ts +1 -0
- package/src/chatbot/widget/ChatbotWidget.tsx +33 -4
- package/src/chatbot/widget/ChatbotWidgetPanel.tsx +1 -6
- package/src/chatbot/widget/ChatbotWidgetTrigger.tsx +1 -8
- package/src/components/EnvBadge.tsx +2 -2
- package/src/components/ui/message-scroller.tsx +5 -23
- package/src/index.css +1998 -51
|
@@ -1,87 +1,312 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Robust inline Markdown renderer supporting:
|
|
5
|
+
* - Markdown links [text](url)
|
|
6
|
+
* - Raw URLs https://...
|
|
7
|
+
* - Bold **text**
|
|
8
|
+
* - Italic *text* and _text_
|
|
9
|
+
* - Inline code `text`
|
|
10
|
+
*/
|
|
3
11
|
function renderInline(text: string): React.ReactNode[] {
|
|
4
|
-
|
|
12
|
+
if (!text) return [];
|
|
13
|
+
|
|
14
|
+
// Match: [text](url) | **bold** | *italic* | `code` | https?://...
|
|
15
|
+
const tokenRegex =
|
|
16
|
+
/(\[[^\]]+\]\([^)]+\)|\*\*[^*]+\*\*|\*[^*]+\*|`[^`]+`|https?:\/\/[^\s]+)/g;
|
|
17
|
+
|
|
18
|
+
const parts = text.split(tokenRegex);
|
|
19
|
+
|
|
5
20
|
return parts.map((part, index) => {
|
|
6
|
-
if (part
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
21
|
+
if (!part) return null;
|
|
22
|
+
|
|
23
|
+
// Markdown link: [text](url)
|
|
24
|
+
const linkMatch = part.match(/^\[([^\]]+)\]\(([^)]+)\)$/);
|
|
25
|
+
if (linkMatch) {
|
|
26
|
+
const linkText = linkMatch[1];
|
|
27
|
+
const linkUrl = linkMatch[2];
|
|
28
|
+
const isExternal = /^https?:\/\//i.test(linkUrl);
|
|
10
29
|
return (
|
|
11
|
-
<
|
|
30
|
+
<a
|
|
12
31
|
key={index}
|
|
13
|
-
|
|
32
|
+
href={linkUrl}
|
|
33
|
+
target={isExternal ? "_blank" : undefined}
|
|
34
|
+
rel={isExternal ? "noopener noreferrer" : undefined}
|
|
35
|
+
className="md-link"
|
|
14
36
|
>
|
|
37
|
+
{linkText}
|
|
38
|
+
</a>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Bold: **text**
|
|
43
|
+
if (part.startsWith("**") && part.endsWith("**") && part.length >= 4) {
|
|
44
|
+
return <strong key={index}>{part.slice(2, -2)}</strong>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Italic: *text*
|
|
48
|
+
if (part.startsWith("*") && part.endsWith("*") && part.length >= 2) {
|
|
49
|
+
return <em key={index}>{part.slice(1, -1)}</em>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Inline code: `code`
|
|
53
|
+
if (part.startsWith("`") && part.endsWith("`") && part.length >= 2) {
|
|
54
|
+
return (
|
|
55
|
+
<code key={index} className="md-code">
|
|
15
56
|
{part.slice(1, -1)}
|
|
16
57
|
</code>
|
|
17
58
|
);
|
|
18
59
|
}
|
|
19
|
-
|
|
60
|
+
|
|
61
|
+
// Raw URL: https://...
|
|
62
|
+
if (/^https?:\/\//i.test(part)) {
|
|
20
63
|
return (
|
|
21
64
|
<a
|
|
22
65
|
key={index}
|
|
23
66
|
href={part}
|
|
24
67
|
target="_blank"
|
|
25
68
|
rel="noopener noreferrer"
|
|
26
|
-
className="
|
|
69
|
+
className="md-link"
|
|
27
70
|
>
|
|
28
71
|
{part}
|
|
29
72
|
</a>
|
|
30
73
|
);
|
|
31
74
|
}
|
|
75
|
+
|
|
32
76
|
return <React.Fragment key={index}>{part}</React.Fragment>;
|
|
33
77
|
});
|
|
34
78
|
}
|
|
35
79
|
|
|
36
|
-
|
|
37
|
-
|
|
80
|
+
type Block =
|
|
81
|
+
| { type: "h"; level: number; content: string }
|
|
82
|
+
| { type: "p"; lines: string[] }
|
|
83
|
+
| { type: "ul"; items: string[] }
|
|
84
|
+
| { type: "ol"; items: string[] }
|
|
85
|
+
| { type: "code"; lang: string; code: string }
|
|
86
|
+
| { type: "quote"; lines: string[] }
|
|
87
|
+
| { type: "hr" }
|
|
88
|
+
| { type: "table"; headers: string[]; rows: string[][] };
|
|
38
89
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.filter((line) => line.trim().startsWith("- ") || line.trim().startsWith("* "));
|
|
47
|
-
return (
|
|
48
|
-
<ul key={blockIndex} className="my-1.5 ml-4 list-disc space-y-0.5">
|
|
49
|
-
{items.map((item, itemIndex) => (
|
|
50
|
-
<li key={itemIndex}>{renderInline(item.replace(/^[-*]\s+/, ""))}</li>
|
|
51
|
-
))}
|
|
52
|
-
</ul>
|
|
53
|
-
);
|
|
54
|
-
}
|
|
90
|
+
/**
|
|
91
|
+
* Line-by-line block parser for Markdown documents.
|
|
92
|
+
* Correctly distinguishes lists, headers, code fences, blockquotes, and paragraphs.
|
|
93
|
+
*/
|
|
94
|
+
function parseBlocks(markdown: string): Block[] {
|
|
95
|
+
const lines = markdown.replace(/\r\n/g, "\n").split("\n");
|
|
96
|
+
const blocks: Block[] = [];
|
|
55
97
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
{items.map((item, itemIndex) => (
|
|
61
|
-
<li key={itemIndex}>{renderInline(item.replace(/^\d+\.\s+/, ""))}</li>
|
|
62
|
-
))}
|
|
63
|
-
</ol>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
98
|
+
let i = 0;
|
|
99
|
+
while (i < lines.length) {
|
|
100
|
+
const rawLine = lines[i];
|
|
101
|
+
const trimmed = rawLine.trim();
|
|
66
102
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
className="my-2 overflow-x-auto rounded-lg bg-[var(--code-bg)] p-3 font-mono text-[12px] text-primary-foreground"
|
|
73
|
-
>
|
|
74
|
-
<code>{content}</code>
|
|
75
|
-
</pre>
|
|
76
|
-
);
|
|
77
|
-
}
|
|
103
|
+
// 1. Skip completely empty lines
|
|
104
|
+
if (!trimmed) {
|
|
105
|
+
i++;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
78
108
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
109
|
+
// 2. Code blocks (```lang ... ```)
|
|
110
|
+
if (trimmed.startsWith("```")) {
|
|
111
|
+
const lang = trimmed.slice(3).trim();
|
|
112
|
+
const codeLines: string[] = [];
|
|
113
|
+
i++;
|
|
114
|
+
while (i < lines.length && !lines[i].trim().startsWith("```")) {
|
|
115
|
+
codeLines.push(lines[i]);
|
|
116
|
+
i++;
|
|
117
|
+
}
|
|
118
|
+
if (i < lines.length && lines[i].trim().startsWith("```")) {
|
|
119
|
+
i++; // skip closing fence
|
|
120
|
+
}
|
|
121
|
+
blocks.push({ type: "code", lang, code: codeLines.join("\n") });
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 3. Horizontal rule (--- or ***)
|
|
126
|
+
if (/^(---|___|\*\*\*)$/.test(trimmed)) {
|
|
127
|
+
blocks.push({ type: "hr" });
|
|
128
|
+
i++;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 4. Headings (# to ####)
|
|
133
|
+
const headingMatch = trimmed.match(/^(#{1,4})\s+(.*)$/);
|
|
134
|
+
if (headingMatch) {
|
|
135
|
+
blocks.push({
|
|
136
|
+
type: "h",
|
|
137
|
+
level: headingMatch[1].length,
|
|
138
|
+
content: headingMatch[2],
|
|
139
|
+
});
|
|
140
|
+
i++;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// 5. Blockquote (> ...)
|
|
145
|
+
if (trimmed.startsWith(">")) {
|
|
146
|
+
const quoteLines: string[] = [];
|
|
147
|
+
while (i < lines.length && lines[i].trim().startsWith(">")) {
|
|
148
|
+
quoteLines.push(lines[i].trim().replace(/^>\s?/, ""));
|
|
149
|
+
i++;
|
|
150
|
+
}
|
|
151
|
+
blocks.push({ type: "quote", lines: quoteLines });
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 6. Unordered list (- or *)
|
|
156
|
+
if (/^[-*]\s+/.test(trimmed)) {
|
|
157
|
+
const items: string[] = [];
|
|
158
|
+
while (i < lines.length && /^[-*]\s+/.test(lines[i].trim())) {
|
|
159
|
+
items.push(lines[i].trim().replace(/^[-*]\s+/, ""));
|
|
160
|
+
i++;
|
|
161
|
+
}
|
|
162
|
+
blocks.push({ type: "ul", items });
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 7. Ordered list (1. 2. ...)
|
|
167
|
+
if (/^\d+\.\s+/.test(trimmed)) {
|
|
168
|
+
const items: string[] = [];
|
|
169
|
+
while (i < lines.length && /^\d+\.\s+/.test(lines[i].trim())) {
|
|
170
|
+
items.push(lines[i].trim().replace(/^\d+\.\s+/, ""));
|
|
171
|
+
i++;
|
|
172
|
+
}
|
|
173
|
+
blocks.push({ type: "ol", items });
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// 8. Markdown table (| col | col |)
|
|
178
|
+
if (trimmed.startsWith("|") && trimmed.endsWith("|")) {
|
|
179
|
+
const tableLines: string[] = [];
|
|
180
|
+
while (i < lines.length && lines[i].trim().startsWith("|") && lines[i].trim().endsWith("|")) {
|
|
181
|
+
tableLines.push(lines[i].trim());
|
|
182
|
+
i++;
|
|
183
|
+
}
|
|
184
|
+
if (tableLines.length >= 2) {
|
|
185
|
+
const parseRow = (line: string) =>
|
|
186
|
+
line
|
|
187
|
+
.slice(1, -1)
|
|
188
|
+
.split("|")
|
|
189
|
+
.map((c) => c.trim());
|
|
190
|
+
const headers = parseRow(tableLines[0]);
|
|
191
|
+
// line 1 is usually separator (|---|---|)
|
|
192
|
+
const rowStartIndex = tableLines[1].includes("-") ? 2 : 1;
|
|
193
|
+
const rows = tableLines.slice(rowStartIndex).map(parseRow);
|
|
194
|
+
blocks.push({ type: "table", headers, rows });
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// 9. Standard paragraph (accumulate contiguous lines until next empty line or block token)
|
|
200
|
+
const pLines: string[] = [];
|
|
201
|
+
while (
|
|
202
|
+
i < lines.length &&
|
|
203
|
+
lines[i].trim() &&
|
|
204
|
+
!lines[i].trim().startsWith("```") &&
|
|
205
|
+
!/^(#{1,4})\s+/.test(lines[i].trim()) &&
|
|
206
|
+
!/^[-*]\s+/.test(lines[i].trim()) &&
|
|
207
|
+
!/^\d+\.\s+/.test(lines[i].trim()) &&
|
|
208
|
+
!lines[i].trim().startsWith(">") &&
|
|
209
|
+
!/^(---|___|\*\*\*)$/.test(lines[i].trim())
|
|
210
|
+
) {
|
|
211
|
+
pLines.push(lines[i].trim());
|
|
212
|
+
i++;
|
|
213
|
+
}
|
|
214
|
+
if (pLines.length > 0) {
|
|
215
|
+
blocks.push({ type: "p", lines: pLines });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return blocks;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export const ChatMarkdown: React.FC<{ text: string }> = ({ text }) => {
|
|
223
|
+
if (!text) return null;
|
|
224
|
+
|
|
225
|
+
const blocks = parseBlocks(text);
|
|
226
|
+
|
|
227
|
+
return (
|
|
228
|
+
<div className="md-content">
|
|
229
|
+
{blocks.map((block, idx) => {
|
|
230
|
+
switch (block.type) {
|
|
231
|
+
case "h": {
|
|
232
|
+
if (block.level === 1) return <h2 key={idx} className="md-h1">{renderInline(block.content)}</h2>;
|
|
233
|
+
if (block.level === 2) return <h3 key={idx} className="md-h2">{renderInline(block.content)}</h3>;
|
|
234
|
+
if (block.level === 3) return <h4 key={idx} className="md-h3">{renderInline(block.content)}</h4>;
|
|
235
|
+
return <h5 key={idx} className="md-h4">{renderInline(block.content)}</h5>;
|
|
236
|
+
}
|
|
237
|
+
case "ul":
|
|
238
|
+
return (
|
|
239
|
+
<ul key={idx} className="md-ul">
|
|
240
|
+
{block.items.map((item, itemIdx) => (
|
|
241
|
+
<li key={itemIdx} className="md-li">
|
|
242
|
+
{renderInline(item)}
|
|
243
|
+
</li>
|
|
244
|
+
))}
|
|
245
|
+
</ul>
|
|
246
|
+
);
|
|
247
|
+
case "ol":
|
|
248
|
+
return (
|
|
249
|
+
<ol key={idx} className="md-ol">
|
|
250
|
+
{block.items.map((item, itemIdx) => (
|
|
251
|
+
<li key={itemIdx} className="md-li">
|
|
252
|
+
{renderInline(item)}
|
|
253
|
+
</li>
|
|
254
|
+
))}
|
|
255
|
+
</ol>
|
|
256
|
+
);
|
|
257
|
+
case "code":
|
|
258
|
+
return (
|
|
259
|
+
<pre key={idx} className="md-pre">
|
|
260
|
+
<code>{block.code}</code>
|
|
261
|
+
</pre>
|
|
262
|
+
);
|
|
263
|
+
case "quote":
|
|
264
|
+
return (
|
|
265
|
+
<blockquote key={idx} className="md-quote">
|
|
266
|
+
{block.lines.map((line, qIdx) => (
|
|
267
|
+
<p key={qIdx}>{renderInline(line)}</p>
|
|
268
|
+
))}
|
|
269
|
+
</blockquote>
|
|
270
|
+
);
|
|
271
|
+
case "hr":
|
|
272
|
+
return <hr key={idx} className="md-hr" />;
|
|
273
|
+
case "table":
|
|
274
|
+
return (
|
|
275
|
+
<div key={idx} className="md-table-wrap">
|
|
276
|
+
<table className="md-table">
|
|
277
|
+
<thead>
|
|
278
|
+
<tr>
|
|
279
|
+
{block.headers.map((h, hIdx) => (
|
|
280
|
+
<th key={hIdx}>{renderInline(h)}</th>
|
|
281
|
+
))}
|
|
282
|
+
</tr>
|
|
283
|
+
</thead>
|
|
284
|
+
<tbody>
|
|
285
|
+
{block.rows.map((row, rIdx) => (
|
|
286
|
+
<tr key={rIdx}>
|
|
287
|
+
{row.map((cell, cIdx) => (
|
|
288
|
+
<td key={cIdx}>{renderInline(cell)}</td>
|
|
289
|
+
))}
|
|
290
|
+
</tr>
|
|
291
|
+
))}
|
|
292
|
+
</tbody>
|
|
293
|
+
</table>
|
|
294
|
+
</div>
|
|
295
|
+
);
|
|
296
|
+
case "p":
|
|
297
|
+
default:
|
|
298
|
+
return (
|
|
299
|
+
<p key={idx} className="md-p">
|
|
300
|
+
{block.lines.map((line, lineIdx) => (
|
|
301
|
+
<React.Fragment key={lineIdx}>
|
|
302
|
+
{renderInline(line)}
|
|
303
|
+
{lineIdx < block.lines.length - 1 && <br />}
|
|
304
|
+
</React.Fragment>
|
|
305
|
+
))}
|
|
306
|
+
</p>
|
|
307
|
+
);
|
|
308
|
+
}
|
|
84
309
|
})}
|
|
85
|
-
|
|
310
|
+
</div>
|
|
86
311
|
);
|
|
87
|
-
}
|
|
312
|
+
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import {
|
|
3
|
-
import type { ChatMessage,
|
|
4
|
-
import { cn } from "../../lib/cn";
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Check, BotMessageSquare } from "lucide-react";
|
|
3
|
+
import type { ChatMessage, ToolCall } from "../api/chatbot-types";
|
|
5
4
|
import { ChatMarkdown } from "./ChatMarkdown";
|
|
6
5
|
import { ChatTypingIndicator } from "./ChatTypingIndicator";
|
|
6
|
+
import { AgentReasoning } from "./AgentReasoning";
|
|
7
|
+
|
|
8
|
+
import { useOptionalChatContext } from "./ChatContext";
|
|
7
9
|
|
|
8
10
|
function toolLabel(name: string): string {
|
|
9
11
|
if (name === "create_ticket") return "Support ticket processed";
|
|
@@ -12,50 +14,14 @@ function toolLabel(name: string): string {
|
|
|
12
14
|
return "Information retrieved";
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
function Sources({ sources }: { sources: Source[] }) {
|
|
16
|
-
const [open, setOpen] = useState(false);
|
|
17
|
-
if (!sources.length) return null;
|
|
18
|
-
return (
|
|
19
|
-
<div className="mt-2 border-t border-border pt-1.5">
|
|
20
|
-
<button
|
|
21
|
-
type="button"
|
|
22
|
-
className="inline-flex items-center gap-1.5 text-[11.5px] font-semibold text-muted-foreground hover:text-foreground"
|
|
23
|
-
onClick={() => setOpen((value) => !value)}
|
|
24
|
-
aria-expanded={open}
|
|
25
|
-
>
|
|
26
|
-
<FileText size={12} aria-hidden="true" />
|
|
27
|
-
{sources.length} grounded source{sources.length > 1 ? "s" : ""}
|
|
28
|
-
{open ? <ChevronUp size={12} /> : <ChevronDown size={12} />}
|
|
29
|
-
</button>
|
|
30
|
-
{open && (
|
|
31
|
-
<ul className="mt-1.5 space-y-1">
|
|
32
|
-
{sources.map((source) => (
|
|
33
|
-
<li
|
|
34
|
-
key={source.chunkId}
|
|
35
|
-
className="flex items-center justify-between rounded-md border border-border bg-muted px-2 py-1 text-[11px] text-muted-foreground"
|
|
36
|
-
>
|
|
37
|
-
<span className="truncate" title={source.source}>
|
|
38
|
-
{source.source.split(/[/\\]/).pop() || source.source}
|
|
39
|
-
</span>
|
|
40
|
-
<span className="ml-2 font-semibold text-success">
|
|
41
|
-
{Math.round(source.score * 100)}%
|
|
42
|
-
</span>
|
|
43
|
-
</li>
|
|
44
|
-
))}
|
|
45
|
-
</ul>
|
|
46
|
-
)}
|
|
47
|
-
</div>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
17
|
function Tools({ toolCalls }: { toolCalls: ToolCall[] }) {
|
|
52
18
|
if (!toolCalls.length) return null;
|
|
53
19
|
return (
|
|
54
|
-
<div className="
|
|
20
|
+
<div className="tool-badges">
|
|
55
21
|
{toolCalls.map((call, index) => (
|
|
56
22
|
<span
|
|
57
23
|
key={`${call.toolName}-${index}`}
|
|
58
|
-
className="
|
|
24
|
+
className="tool-badge"
|
|
59
25
|
>
|
|
60
26
|
{toolLabel(call.toolName)}
|
|
61
27
|
</span>
|
|
@@ -69,45 +35,70 @@ interface ChatMessageProps {
|
|
|
69
35
|
}
|
|
70
36
|
|
|
71
37
|
export const ChatMessageBubble: React.FC<ChatMessageProps> = ({ message }) => {
|
|
38
|
+
const chatCtx = useOptionalChatContext();
|
|
39
|
+
const hideInspectSources = chatCtx?.hideInspectSources ?? false;
|
|
40
|
+
const showGroundedSources = chatCtx?.showGroundedSources ?? true;
|
|
41
|
+
|
|
72
42
|
const isUser = message.role === "user";
|
|
73
43
|
const isError = message.status === "error";
|
|
44
|
+
const isPending = message.status === "pending";
|
|
45
|
+
const isWelcome =
|
|
46
|
+
message.id === "welcome-default" ||
|
|
47
|
+
message.id.startsWith("welcome") ||
|
|
48
|
+
message.id === "welcome";
|
|
49
|
+
|
|
50
|
+
// Only actual AI responses with retrieval, tools, or live pending state show the reasoning accordion
|
|
51
|
+
const isRealAssistantQuery = Boolean(
|
|
52
|
+
isPending ||
|
|
53
|
+
(message.sources && message.sources.length > 0) ||
|
|
54
|
+
(message.toolCalls && message.toolCalls.length > 0) ||
|
|
55
|
+
message.usage
|
|
56
|
+
);
|
|
57
|
+
const showReasoning = !isUser && !isError && !isWelcome && isRealAssistantQuery;
|
|
74
58
|
|
|
75
59
|
return (
|
|
76
|
-
<div
|
|
77
|
-
className={cn("flex items-start gap-2.5", isUser && "flex-row-reverse")}
|
|
78
|
-
>
|
|
60
|
+
<div className={`msg-row${isUser ? " msg-row--user" : ""}`}>
|
|
79
61
|
{!isUser && (
|
|
80
62
|
<div
|
|
81
|
-
className="
|
|
63
|
+
className="avatar-circle avatar-circle--mt"
|
|
82
64
|
aria-hidden="true"
|
|
83
65
|
>
|
|
84
66
|
<BotMessageSquare size={15} />
|
|
85
67
|
</div>
|
|
86
68
|
)}
|
|
87
|
-
<div className={
|
|
69
|
+
<div className={`msg-col${isUser ? " msg-col--user" : ""}`}>
|
|
88
70
|
<div
|
|
89
|
-
className={
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
"rounded-tl-sm border border-[var(--error-border)] bg-[var(--error-bg)] text-[var(--error-text)]"
|
|
97
|
-
)}
|
|
71
|
+
className={
|
|
72
|
+
isUser
|
|
73
|
+
? "msg-bubble msg-bubble--user"
|
|
74
|
+
: isError
|
|
75
|
+
? "msg-bubble msg-bubble--error"
|
|
76
|
+
: "msg-bubble msg-bubble--bot"
|
|
77
|
+
}
|
|
98
78
|
>
|
|
99
|
-
{
|
|
100
|
-
|
|
79
|
+
{/* Agent Reasoning Accordion (ChatGPT / Open WebUI style) only on real queries */}
|
|
80
|
+
{showReasoning && (
|
|
81
|
+
<AgentReasoning
|
|
82
|
+
status={isPending ? "pending" : "complete"}
|
|
83
|
+
progressText={message.progressText}
|
|
84
|
+
sourcesCount={message.sources?.length || 5}
|
|
85
|
+
/>
|
|
86
|
+
)}
|
|
87
|
+
|
|
88
|
+
{isPending ? (
|
|
89
|
+
<ChatTypingIndicator text={message.progressText} />
|
|
101
90
|
) : isUser ? (
|
|
102
|
-
<p className="
|
|
91
|
+
<p className="msg-user-pre">{message.content}</p>
|
|
103
92
|
) : (
|
|
104
|
-
<
|
|
93
|
+
<div className="msg-content-wrapper">
|
|
94
|
+
<ChatMarkdown text={message.content} />
|
|
95
|
+
</div>
|
|
105
96
|
)}
|
|
97
|
+
|
|
106
98
|
{message.toolCalls ? <Tools toolCalls={message.toolCalls} /> : null}
|
|
107
|
-
{message.sources ? <Sources sources={message.sources} /> : null}
|
|
108
99
|
</div>
|
|
109
100
|
{isUser && message.status !== "error" && (
|
|
110
|
-
<Check size={13} className="
|
|
101
|
+
<Check size={13} className="msg-tick" aria-hidden="true" />
|
|
111
102
|
)}
|
|
112
103
|
</div>
|
|
113
104
|
</div>
|
|
@@ -24,7 +24,7 @@ export const ChatMessageList: React.FC = () => {
|
|
|
24
24
|
<MessageScroller>
|
|
25
25
|
<MessageScrollerViewport aria-label="Chat messages">
|
|
26
26
|
<MessageScrollerContent aria-busy={isBusy}>
|
|
27
|
-
{
|
|
27
|
+
{messages.length === 0 && (
|
|
28
28
|
<MessageScrollerItem messageId="welcome">
|
|
29
29
|
<ChatEmptyState />
|
|
30
30
|
</MessageScrollerItem>
|
|
@@ -5,7 +5,6 @@ import { ChatHeader } from "./ChatHeader";
|
|
|
5
5
|
import { ChatInput } from "./ChatInput";
|
|
6
6
|
import { ChatMessageList } from "./ChatMessageList";
|
|
7
7
|
import { ChatTicketConfirmation } from "./ChatTicketConfirmation";
|
|
8
|
-
import { cn } from "../../lib/cn";
|
|
9
8
|
import { type EnvStage } from "../../components/EnvBadge";
|
|
10
9
|
|
|
11
10
|
interface ChatPanelProps {
|
|
@@ -35,10 +34,7 @@ export const ChatPanel: React.FC<ChatPanelProps> = ({
|
|
|
35
34
|
|
|
36
35
|
return (
|
|
37
36
|
<section
|
|
38
|
-
className={
|
|
39
|
-
"flex h-full min-h-0 flex-col overflow-hidden bg-card",
|
|
40
|
-
className
|
|
41
|
-
)}
|
|
37
|
+
className={`chat-panel${className ? ` ${className}` : ""}`}
|
|
42
38
|
aria-label="VPS AI Assistant"
|
|
43
39
|
>
|
|
44
40
|
<ChatHeader
|
|
@@ -50,7 +46,7 @@ export const ChatPanel: React.FC<ChatPanelProps> = ({
|
|
|
50
46
|
envStage={envStage}
|
|
51
47
|
envPulse={envPulse}
|
|
52
48
|
/>
|
|
53
|
-
<div className="
|
|
49
|
+
<div className="chat-panel-body">
|
|
54
50
|
<ChatMessageList />
|
|
55
51
|
</div>
|
|
56
52
|
{error && status === "error" && (
|