@terryavg/neptune-ai-chatbot 1.0.1 → 1.0.2

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 (59) hide show
  1. package/README.md +137 -2
  2. package/dist/chat-input-42V4ESQB.mjs +478 -0
  3. package/dist/chat-input-4T42R7FR.mjs +481 -0
  4. package/dist/chat-input-BJVIIYOP.mjs +484 -0
  5. package/dist/chat-input-HT47ZLQN.mjs +456 -0
  6. package/dist/chat-input-JFGPZBBQ.mjs +495 -0
  7. package/dist/chat-input-JQ7PSHNW.mjs +515 -0
  8. package/dist/chat-input-USWVSAYY.mjs +461 -0
  9. package/dist/chat-input-VTCTV5ED.mjs +495 -0
  10. package/dist/chat-input-WJMGLQJI.mjs +495 -0
  11. package/dist/chat-message-2VQW74CO.mjs +2230 -0
  12. package/dist/chat-message-35ZWSSQV.mjs +1926 -0
  13. package/dist/chat-message-3CUUWTZG.mjs +2429 -0
  14. package/dist/chat-message-3NHSJNKL.mjs +2241 -0
  15. package/dist/chat-message-3Z7B2WYC.mjs +2228 -0
  16. package/dist/chat-message-564AHZHH.mjs +2186 -0
  17. package/dist/chat-message-5QLTW4K7.mjs +2122 -0
  18. package/dist/chat-message-7EH2TDZG.mjs +1910 -0
  19. package/dist/chat-message-7QHJRHQG.mjs +1909 -0
  20. package/dist/chat-message-AAXNH5TF.mjs +2088 -0
  21. package/dist/chat-message-D36YF274.mjs +1910 -0
  22. package/dist/chat-message-DVCXEL4Z.mjs +2111 -0
  23. package/dist/chat-message-E6KB3AST.mjs +1906 -0
  24. package/dist/chat-message-G2NWPAXK.mjs +1904 -0
  25. package/dist/chat-message-H62Z3DW5.mjs +2368 -0
  26. package/dist/chat-message-HIEZ7B5R.mjs +2190 -0
  27. package/dist/chat-message-I6AKFPK6.mjs +2156 -0
  28. package/dist/chat-message-IKYSAVAB.mjs +1918 -0
  29. package/dist/chat-message-IZL6JHV2.mjs +2429 -0
  30. package/dist/chat-message-J7PVUQO6.mjs +1878 -0
  31. package/dist/chat-message-K6QILTW5.mjs +1897 -0
  32. package/dist/chat-message-MDORLI2R.mjs +2228 -0
  33. package/dist/chat-message-MFUY6KOE.mjs +1910 -0
  34. package/dist/chat-message-MYKOR5OF.mjs +1890 -0
  35. package/dist/chat-message-NKMTAMGG.mjs +1906 -0
  36. package/dist/chat-message-NNGD3FUH.mjs +2168 -0
  37. package/dist/chat-message-QAPRO542.mjs +1915 -0
  38. package/dist/chat-message-R4IJ3MXU.mjs +2146 -0
  39. package/dist/chat-message-U7UCBLHI.mjs +2145 -0
  40. package/dist/chat-message-UKXGFKUR.mjs +1903 -0
  41. package/dist/chat-message-UNIBCF3T.mjs +1900 -0
  42. package/dist/chat-message-UXLPL76T.mjs +1890 -0
  43. package/dist/chat-message-VB54UOHB.mjs +2306 -0
  44. package/dist/chat-message-WUNUZLKI.mjs +2228 -0
  45. package/dist/chat-message-WYN5UZRD.mjs +1927 -0
  46. package/dist/chat-message-Y5OJSR2O.mjs +2228 -0
  47. package/dist/chat-message-YPDHL6WW.mjs +2114 -0
  48. package/dist/chunk-26656QB3.mjs +406 -0
  49. package/dist/chunk-2RXQ2EZ2.mjs +295 -0
  50. package/dist/chunk-DVWFDUN4.mjs +407 -0
  51. package/dist/chunk-JLRHY3SB.mjs +405 -0
  52. package/dist/chunk-XFSEOBLD.mjs +432 -0
  53. package/dist/index.css +174 -43
  54. package/dist/index.d.mts +218 -1
  55. package/dist/index.d.ts +218 -1
  56. package/dist/index.js +2088 -1400
  57. package/dist/index.mjs +606 -413
  58. package/dist/styles.css +1 -1
  59. package/package.json +2 -1
@@ -0,0 +1,1900 @@
1
+ import {
2
+ ToolExecutionIndicator,
3
+ ToolExecutionWidget
4
+ } from "./chunk-2RXQ2EZ2.mjs";
5
+ import {
6
+ __objRest,
7
+ __spreadProps,
8
+ __spreadValues
9
+ } from "./chunk-FWCSY2DS.mjs";
10
+
11
+ // app/components/chat-message.tsx
12
+ import {
13
+ useEffect,
14
+ useState,
15
+ memo,
16
+ useMemo,
17
+ useRef,
18
+ lazy,
19
+ Suspense
20
+ } from "react";
21
+ import ReactMarkdown from "react-markdown";
22
+ import remarkGfm from "remark-gfm";
23
+ import rehypeRaw from "rehype-raw";
24
+ import {
25
+ Copy,
26
+ Check,
27
+ FileText,
28
+ Image as ImageIcon,
29
+ X,
30
+ Download,
31
+ ChevronDown,
32
+ ChevronRight
33
+ } from "lucide-react";
34
+ import { marked } from "marked";
35
+ import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
36
+ import {
37
+ vscDarkPlus,
38
+ oneLight
39
+ } from "react-syntax-highlighter/dist/esm/styles/prism";
40
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
41
+ var CodeBlock = memo(
42
+ ({
43
+ language,
44
+ code,
45
+ theme
46
+ }) => {
47
+ const [copied, setCopied] = useState(false);
48
+ const handleCopy = (e) => {
49
+ e.stopPropagation();
50
+ navigator.clipboard.writeText(code).then(() => {
51
+ setCopied(true);
52
+ setTimeout(() => setCopied(false), 2e3);
53
+ }).catch((err) => console.error("Failed to copy code: ", err));
54
+ };
55
+ const getLanguageLabel = (lang) => {
56
+ const langMap = {
57
+ js: "JavaScript",
58
+ javascript: "JavaScript",
59
+ jsx: "JavaScript React",
60
+ ts: "TypeScript",
61
+ typescript: "TypeScript",
62
+ tsx: "TypeScript React",
63
+ py: "Python",
64
+ python: "Python",
65
+ java: "Java",
66
+ cpp: "C++",
67
+ c: "C",
68
+ cs: "C#",
69
+ csharp: "C#",
70
+ go: "Go",
71
+ rs: "Rust",
72
+ rust: "Rust",
73
+ php: "PHP",
74
+ rb: "Ruby",
75
+ ruby: "Ruby",
76
+ sh: "Shell",
77
+ shell: "Shell",
78
+ bash: "Bash",
79
+ zsh: "Zsh",
80
+ sql: "SQL",
81
+ html: "HTML",
82
+ css: "CSS",
83
+ scss: "SCSS",
84
+ json: "JSON",
85
+ xml: "XML",
86
+ yaml: "YAML",
87
+ yml: "YAML",
88
+ md: "Markdown",
89
+ markdown: "Markdown",
90
+ text: "Text",
91
+ plaintext: "Plain Text"
92
+ };
93
+ return langMap[lang.toLowerCase()] || lang.toUpperCase();
94
+ };
95
+ const isDark = theme === "dark";
96
+ const syntaxTheme = isDark ? vscDarkPlus : oneLight;
97
+ const bgColor = isDark ? "#1e1e1e" : "#efefef";
98
+ const headerBg = isDark ? "#1e1e1e" : "#f5f5f5";
99
+ const borderColor = isDark ? "border-gray-700" : "border-gray-300";
100
+ const textColor = isDark ? "text-gray-300" : "text-gray-700";
101
+ const buttonHover = isDark ? "hover:bg-gray-700" : "hover:bg-gray-200";
102
+ const iconColor = isDark ? "text-gray-400" : "text-gray-600";
103
+ return /* @__PURE__ */ jsxs("div", { className: `mt-1 mb-3 rounded-lg border-2 ${borderColor}`, children: [
104
+ /* @__PURE__ */ jsxs(
105
+ "div",
106
+ {
107
+ className: `sticky top-0 z-20 flex items-center justify-between px-4 py-2 border-b ${borderColor} rounded-tl-lg rounded-tr-lg`,
108
+ style: { top: "-22px", backgroundColor: headerBg },
109
+ children: [
110
+ /* @__PURE__ */ jsx("span", { className: `text-xs font-medium ${textColor}`, children: getLanguageLabel(language) }),
111
+ /* @__PURE__ */ jsx(
112
+ "button",
113
+ {
114
+ onClick: handleCopy,
115
+ className: `p-1.5 rounded transition-colors ${buttonHover}`,
116
+ title: "Copy code",
117
+ children: copied ? /* @__PURE__ */ jsx(Check, { size: 14, className: "text-green-500" }) : /* @__PURE__ */ jsx(Copy, { size: 14, className: iconColor })
118
+ }
119
+ )
120
+ ]
121
+ }
122
+ ),
123
+ /* @__PURE__ */ jsx("div", { className: "max-h-80 overflow-auto", children: /* @__PURE__ */ jsx(
124
+ SyntaxHighlighter,
125
+ {
126
+ language: language.toLowerCase(),
127
+ style: syntaxTheme,
128
+ customStyle: {
129
+ margin: 0,
130
+ background: bgColor,
131
+ fontSize: "0.875rem",
132
+ padding: "1rem"
133
+ },
134
+ codeTagProps: {
135
+ style: {
136
+ backgroundColor: bgColor
137
+ }
138
+ },
139
+ children: code
140
+ }
141
+ ) })
142
+ ] });
143
+ }
144
+ );
145
+ CodeBlock.displayName = "CodeBlock";
146
+ var DynamicChartComponent = lazy(() => import("./chart-component-RCLR3IKU.mjs"));
147
+ var MemoizedChart = memo(
148
+ ({
149
+ type,
150
+ data,
151
+ theme
152
+ }) => {
153
+ return /* @__PURE__ */ jsx(
154
+ Suspense,
155
+ {
156
+ fallback: /* @__PURE__ */ jsx("div", { className: "animate-pulse h-64 bg-gray-100 dark:bg-gray-800 rounded-lg" }),
157
+ children: /* @__PURE__ */ jsx(DynamicChartComponent, { type, data, theme })
158
+ }
159
+ );
160
+ },
161
+ (prevProps, nextProps) => {
162
+ return prevProps.type === nextProps.type && prevProps.theme === nextProps.theme && JSON.stringify(prevProps.data) === JSON.stringify(nextProps.data);
163
+ }
164
+ );
165
+ MemoizedChart.displayName = "MemoizedChart";
166
+ var JsonBlock = memo(
167
+ ({
168
+ title,
169
+ jsonContent,
170
+ keyProp
171
+ }) => {
172
+ const [isExpanded, setIsExpanded] = useState(false);
173
+ const [copyJsonSuccess, setCopyJsonSuccess] = useState(false);
174
+ const formattedJson = useMemo(() => {
175
+ try {
176
+ const parsed = JSON.parse(jsonContent.trim());
177
+ return JSON.stringify(parsed, null, 2);
178
+ } catch (error) {
179
+ console.error("Failed to parse JSON:", error);
180
+ return jsonContent;
181
+ }
182
+ }, [jsonContent]);
183
+ const highlightedJson = useMemo(() => {
184
+ return formattedJson.replace(
185
+ /"([^"]+)":/g,
186
+ '<span class="json-key">"$1"</span>:'
187
+ ).replace(
188
+ /:\s*"([^"]*)"/g,
189
+ ': <span class="json-string">"$1"</span>'
190
+ ).replace(
191
+ /:\s*(-?\d+\.?\d*)/g,
192
+ ': <span class="json-number">$1</span>'
193
+ ).replace(
194
+ /:\s*(true|false)/g,
195
+ ': <span class="json-boolean">$1</span>'
196
+ ).replace(
197
+ /:\s*(null)/g,
198
+ ': <span class="json-null">$1</span>'
199
+ );
200
+ }, [formattedJson]);
201
+ const handleCopyJson = (e) => {
202
+ e.stopPropagation();
203
+ navigator.clipboard.writeText(formattedJson).then(() => {
204
+ setCopyJsonSuccess(true);
205
+ setTimeout(() => setCopyJsonSuccess(false), 2e3);
206
+ }).catch((err) => console.error("Failed to copy JSON: ", err));
207
+ };
208
+ return /* @__PURE__ */ jsxs("div", { className: "my-4 border border-gray-200 dark:border-gray-600 rounded-lg overflow-hidden bg-gray-50 dark:bg-gray-900", children: [
209
+ /* @__PURE__ */ jsxs(
210
+ "div",
211
+ {
212
+ onClick: () => setIsExpanded(!isExpanded),
213
+ className: "flex items-center justify-between p-4 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors bg-gray-50 bg-gray-900",
214
+ children: [
215
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
216
+ isExpanded ? /* @__PURE__ */ jsx(
217
+ ChevronDown,
218
+ {
219
+ size: 20,
220
+ className: "text-gray-600 dark:text-gray-300"
221
+ }
222
+ ) : /* @__PURE__ */ jsx(
223
+ ChevronRight,
224
+ {
225
+ size: 20,
226
+ className: "text-gray-600 dark:text-gray-300"
227
+ }
228
+ ),
229
+ /* @__PURE__ */ jsx("span", { className: "font-semibold text-gray-800 dark:text-white", children: title }),
230
+ /* @__PURE__ */ jsx("span", { className: "text-xs px-2 py-0.5 bg-blue-100 dark:bg-blue-600 text-blue-700 dark:text-white rounded-full", children: "JSON" })
231
+ ] }),
232
+ /* @__PURE__ */ jsx(
233
+ "button",
234
+ {
235
+ onClick: handleCopyJson,
236
+ className: "p-1.5 hover:bg-gray-200 dark:hover:bg-gray-600 rounded transition-colors",
237
+ title: "Copy JSON",
238
+ children: copyJsonSuccess ? /* @__PURE__ */ jsx(Check, { size: 16, className: "text-green-500" }) : /* @__PURE__ */ jsx(
239
+ Copy,
240
+ {
241
+ size: 16,
242
+ className: "text-gray-600 dark:text-gray-300"
243
+ }
244
+ )
245
+ }
246
+ )
247
+ ]
248
+ }
249
+ ),
250
+ isExpanded && /* @__PURE__ */ jsx("div", { className: "border-t border-gray-200 dark:border-gray-700", children: /* @__PURE__ */ jsx("pre", { className: "p-4 overflow-x-auto bg-white dark:bg-black text-sm font-mono", children: /* @__PURE__ */ jsx(
251
+ "code",
252
+ {
253
+ className: "language-json text-gray-800 dark:text-gray-100",
254
+ dangerouslySetInnerHTML: {
255
+ __html: highlightedJson
256
+ }
257
+ }
258
+ ) }) }),
259
+ /* @__PURE__ */ jsx("style", { children: `
260
+ :global(.json-key) {
261
+ color: #d19a66;
262
+ }
263
+ :global(.json-string) {
264
+ color: #98c379;
265
+ }
266
+ :global(.json-number) {
267
+ color: #d19a66;
268
+ }
269
+ :global(.json-boolean) {
270
+ color: #56b6c2;
271
+ }
272
+ :global(.json-null) {
273
+ color: #c678dd;
274
+ }
275
+ :global(.dark .json-key) {
276
+ color: #e5c07b;
277
+ }
278
+ :global(.dark .json-string) {
279
+ color: #98c379;
280
+ }
281
+ :global(.dark .json-number) {
282
+ color: #d19a66;
283
+ }
284
+ :global(.dark .json-boolean) {
285
+ color: #61afef;
286
+ }
287
+ :global(.dark .json-null) {
288
+ color: #c678dd;
289
+ }
290
+ ` })
291
+ ] });
292
+ }
293
+ );
294
+ JsonBlock.displayName = "JsonBlock";
295
+ function ChatMessage({
296
+ message,
297
+ isStreaming = false,
298
+ theme,
299
+ onAppOpen,
300
+ onAnalyticOpen,
301
+ onWidgetSubmit,
302
+ onWidgetCancel,
303
+ messageBubbleColor = "#E5E3F8",
304
+ streamingText = "NAIA is working on it...",
305
+ streamingTextColor = "#2563EB"
306
+ }) {
307
+ const { role, content } = message;
308
+ const [copied, setCopied] = useState(false);
309
+ const [imageDialogOpen, setImageDialogOpen] = useState(false);
310
+ const [selectedImage, setSelectedImage] = useState(null);
311
+ const [displayedLength, setDisplayedLength] = useState(0);
312
+ useEffect(() => {
313
+ if (isStreaming && typeof content === "string") {
314
+ const timer = setTimeout(() => {
315
+ setDisplayedLength(content.length);
316
+ }, 100);
317
+ return () => clearTimeout(timer);
318
+ } else if (!isStreaming) {
319
+ setDisplayedLength(0);
320
+ }
321
+ }, [content, isStreaming]);
322
+ const messageContainerRef = useRef(null);
323
+ const handleImageClick = (imageSrc, imageAlt = "Image") => {
324
+ setSelectedImage({ src: imageSrc, alt: imageAlt });
325
+ setImageDialogOpen(true);
326
+ };
327
+ const closeImageDialog = () => {
328
+ setImageDialogOpen(false);
329
+ setSelectedImage(null);
330
+ };
331
+ useEffect(() => {
332
+ const handleEscape = (e) => {
333
+ if (e.key === "Escape" && imageDialogOpen) {
334
+ closeImageDialog();
335
+ }
336
+ };
337
+ if (imageDialogOpen) {
338
+ document.addEventListener("keydown", handleEscape);
339
+ document.body.style.overflow = "hidden";
340
+ }
341
+ return () => {
342
+ document.removeEventListener("keydown", handleEscape);
343
+ document.body.style.overflow = "unset";
344
+ };
345
+ }, [imageDialogOpen]);
346
+ const detectChartBlocks = (markdown) => {
347
+ const chartPattern = /```chart:([a-z]+)\n([\s\S]*?)\n```/g;
348
+ const charts = [];
349
+ let match;
350
+ while ((match = chartPattern.exec(markdown)) !== null) {
351
+ charts.push({
352
+ type: match[1],
353
+ data: match[2],
354
+ index: match.index,
355
+ fullMatch: match[0]
356
+ });
357
+ }
358
+ return charts;
359
+ };
360
+ const captureChartsAsImages = async () => {
361
+ if (!messageContainerRef.current) {
362
+ return [];
363
+ }
364
+ const canvases = messageContainerRef.current.querySelectorAll("canvas");
365
+ const images = [];
366
+ canvases.forEach((canvas) => {
367
+ try {
368
+ const dataUrl = canvas.toDataURL("image/png");
369
+ images.push(dataUrl);
370
+ } catch (e) {
371
+ console.error("Failed to capture chart canvas:", e);
372
+ images.push("");
373
+ }
374
+ });
375
+ return images;
376
+ };
377
+ const convertMarkdownToStyledHTML = (markdown, chartImages) => {
378
+ let processedMarkdown = markdown;
379
+ if (chartImages && chartImages.length > 0) {
380
+ const chartBlocks = detectChartBlocks(markdown);
381
+ chartBlocks.reverse().forEach((chart, index) => {
382
+ const imageIndex = chartBlocks.length - 1 - index;
383
+ const imageData = chartImages[imageIndex];
384
+ if (imageData) {
385
+ const imgTag = `
386
+
387
+ ![Chart: ${chart.type}](${imageData})
388
+
389
+ `;
390
+ processedMarkdown = processedMarkdown.substring(0, chart.index) + imgTag + processedMarkdown.substring(
391
+ chart.index + chart.fullMatch.length
392
+ );
393
+ }
394
+ });
395
+ }
396
+ marked.setOptions({
397
+ gfm: true,
398
+ // GitHub Flavored Markdown
399
+ breaks: true
400
+ // Convert \n to <br>
401
+ });
402
+ let html = marked.parse(processedMarkdown);
403
+ const styledHTML = `
404
+ <div style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; font-size: 14px; line-height: 1.6; color: #333;">
405
+ ${html}
406
+ </div>
407
+ `;
408
+ return styledHTML.replace(
409
+ /<h1>/g,
410
+ '<h1 style="font-size: 2em; font-weight: bold; margin: 0.67em 0; color: #1a1a1a;">'
411
+ ).replace(
412
+ /<h2>/g,
413
+ '<h2 style="font-size: 1.5em; font-weight: bold; margin: 0.75em 0; color: #1a1a1a;">'
414
+ ).replace(
415
+ /<h3>/g,
416
+ '<h3 style="font-size: 1.17em; font-weight: bold; margin: 0.83em 0; color: #1a1a1a;">'
417
+ ).replace(
418
+ /<h4>/g,
419
+ '<h4 style="font-size: 1em; font-weight: bold; margin: 1em 0; color: #1a1a1a;">'
420
+ ).replace(
421
+ /<h5>/g,
422
+ '<h5 style="font-size: 0.83em; font-weight: bold; margin: 1.17em 0; color: #1a1a1a;">'
423
+ ).replace(
424
+ /<h6>/g,
425
+ '<h6 style="font-size: 0.67em; font-weight: bold; margin: 1.33em 0; color: #1a1a1a;">'
426
+ ).replace(/<p>/g, '<p style="margin: 0.5em 0;">').replace(/<strong>/g, '<strong style="font-weight: bold;">').replace(/<em>/g, '<em style="font-style: italic;">').replace(
427
+ /<pre>/g,
428
+ `<pre style="background-color: #f5f5f5; border: 1px solid #ddd; border-radius: 4px; padding: 12px; overflow-x: auto; margin: 1em 0; font-family: 'Courier New', Courier, monospace; font-size: 13px;">`
429
+ ).replace(
430
+ /<code>/g,
431
+ `<code style="font-family: 'Courier New', Courier, monospace; font-size: 13px; background-color: #f5f5f5; padding: 2px 4px; border-radius: 3px;">`
432
+ ).replace(
433
+ /<ul>/g,
434
+ '<ul style="margin: 0.5em 0; padding-left: 2em; list-style-type: disc;">'
435
+ ).replace(
436
+ /<ol>/g,
437
+ '<ol style="margin: 0.5em 0; padding-left: 2em; list-style-type: decimal;">'
438
+ ).replace(/<li>/g, '<li style="margin: 0.25em 0;">').replace(
439
+ /<table>/g,
440
+ '<table style="border-collapse: collapse; width: 100%; margin: 1em 0; border: 1px solid #ddd;">'
441
+ ).replace(
442
+ /<th>/g,
443
+ '<th style="border: 1px solid #ddd; padding: 8px 12px; background-color: #f5f5f5; font-weight: bold; text-align: left;">'
444
+ ).replace(
445
+ /<td>/g,
446
+ '<td style="border: 1px solid #ddd; padding: 8px 12px;">'
447
+ ).replace(/<tr>/g, '<tr style="border-bottom: 1px solid #ddd;">').replace(
448
+ /<a href=/g,
449
+ '<a style="color: #0066cc; text-decoration: underline;" href='
450
+ ).replace(
451
+ /<blockquote>/g,
452
+ '<blockquote style="border-left: 4px solid #ddd; margin: 1em 0; padding: 0.5em 1em; color: #666; background-color: #f9f9f9;">'
453
+ ).replace(
454
+ /<hr>/g,
455
+ '<hr style="border: none; border-top: 1px solid #ddd; margin: 1em 0;">'
456
+ ).replace(
457
+ /<img /g,
458
+ '<img style="max-width: 100%; height: auto; display: block; margin: 1em 0; border: 1px solid #ddd; border-radius: 4px;" '
459
+ );
460
+ };
461
+ const copyToClipboard = async () => {
462
+ const textToCopy = typeof content === "string" ? content : Array.isArray(content) ? content.filter((part) => part.type === "text").map((part) => part.text).join("\n") : "";
463
+ try {
464
+ if (navigator.clipboard && window.ClipboardItem) {
465
+ const chartImages = await captureChartsAsImages();
466
+ const htmlContent = convertMarkdownToStyledHTML(
467
+ textToCopy,
468
+ chartImages
469
+ );
470
+ const blob = new Blob([htmlContent], { type: "text/html" });
471
+ const textBlob = new Blob([textToCopy], { type: "text/plain" });
472
+ const clipboardItem = new ClipboardItem({
473
+ "text/html": blob,
474
+ "text/plain": textBlob
475
+ });
476
+ await navigator.clipboard.write([clipboardItem]);
477
+ setCopied(true);
478
+ setTimeout(() => setCopied(false), 2e3);
479
+ } else {
480
+ await navigator.clipboard.writeText(textToCopy);
481
+ setCopied(true);
482
+ setTimeout(() => setCopied(false), 2e3);
483
+ }
484
+ } catch (err) {
485
+ console.error("Failed to copy: ", err);
486
+ try {
487
+ await navigator.clipboard.writeText(textToCopy);
488
+ setCopied(true);
489
+ setTimeout(() => setCopied(false), 2e3);
490
+ } catch (fallbackErr) {
491
+ console.error("Fallback copy also failed: ", fallbackErr);
492
+ }
493
+ }
494
+ };
495
+ const StreamingIndicator = () => {
496
+ if (!isStreaming || role !== "assistant") {
497
+ return null;
498
+ }
499
+ return /* @__PURE__ */ jsxs("div", { className: "mt-3 inline-flex items-center", children: [
500
+ /* @__PURE__ */ jsx("div", { className: "flex items-center space-x-1", children: /* @__PURE__ */ jsx(
501
+ "span",
502
+ {
503
+ className: "text-sm font-medium streaming-text",
504
+ style: { color: streamingTextColor },
505
+ children: streamingText
506
+ }
507
+ ) }),
508
+ /* @__PURE__ */ jsx("style", { children: `
509
+ @keyframes bounce {
510
+ 0%, 100% {
511
+ transform: translateY(0px);
512
+ }
513
+ 50% {
514
+ transform: translateY(-3px);
515
+ }
516
+ }
517
+
518
+ .streaming-text {
519
+ animation: bounce 1.5s ease-in-out infinite;
520
+ }
521
+ ` })
522
+ ] });
523
+ };
524
+ const renderChart = (chartType, chartData, key) => {
525
+ try {
526
+ const cleanJsonString = chartData.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "").replace(/,(\s*[}\]])/g, "$1");
527
+ const parsedData = JSON.parse(cleanJsonString);
528
+ const formattedData = parsedData.data ? parsedData : { data: parsedData };
529
+ return /* @__PURE__ */ jsx(
530
+ MemoizedChart,
531
+ {
532
+ type: chartType,
533
+ data: formattedData,
534
+ theme
535
+ },
536
+ key || `chart-${chartType}-${cleanJsonString.length}`
537
+ );
538
+ } catch (error) {
539
+ console.error("Failed to parse chart data:", error);
540
+ return /* @__PURE__ */ jsxs("div", { className: "p-6 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-300 rounded-lg border border-red-100 dark:border-red-800 w-full max-w-full my-4", children: [
541
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 mb-2", children: [
542
+ /* @__PURE__ */ jsx(
543
+ "svg",
544
+ {
545
+ xmlns: "http://www.w3.org/2000/svg",
546
+ className: "h-5 w-5",
547
+ viewBox: "0 0 20 20",
548
+ fill: "currentColor",
549
+ children: /* @__PURE__ */ jsx(
550
+ "path",
551
+ {
552
+ fillRule: "evenodd",
553
+ d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",
554
+ clipRule: "evenodd"
555
+ }
556
+ )
557
+ }
558
+ ),
559
+ /* @__PURE__ */ jsx("h3", { className: "font-medium", children: "Unable to generate chart" })
560
+ ] }),
561
+ /* @__PURE__ */ jsx("p", { className: "ml-8 text-sm", children: "The data format is not compatible with the requested chart type. Please try a different visualization or check the data structure." })
562
+ ] });
563
+ }
564
+ };
565
+ const renderImage = (imageData, key) => {
566
+ const trimmedData = imageData.trim();
567
+ return /* @__PURE__ */ jsx(
568
+ "div",
569
+ {
570
+ className: "my-6 p-2",
571
+ children: /* @__PURE__ */ jsxs("div", { className: "max-w-full", children: [
572
+ /* @__PURE__ */ jsx(
573
+ "img",
574
+ {
575
+ src: trimmedData,
576
+ alt: "Generated image",
577
+ className: "max-w-full max-h-96 rounded-md object-contain mb-2 cursor-pointer hover:opacity-90 transition-opacity",
578
+ onClick: () => handleImageClick(trimmedData, "Generated image"),
579
+ onError: (e) => {
580
+ console.error("Failed to load image:", trimmedData);
581
+ e.target.style.display = "none";
582
+ }
583
+ }
584
+ ),
585
+ /* @__PURE__ */ jsx("div", { className: "flex justify-end text-sm mr-2", children: /* @__PURE__ */ jsx(
586
+ "a",
587
+ {
588
+ href: trimmedData,
589
+ download: "generated-image.jpeg",
590
+ className: "text-blue-500 hover:text-blue-600",
591
+ children: "Download"
592
+ }
593
+ ) })
594
+ ] })
595
+ },
596
+ key || `image-${trimmedData.substring(0, 50)}`
597
+ );
598
+ };
599
+ const renderApp = (appName, appUrl, key) => {
600
+ const handleAppClick = () => {
601
+ if (onAppOpen) {
602
+ onAppOpen(appName, appUrl);
603
+ }
604
+ };
605
+ return /* @__PURE__ */ jsx(
606
+ "div",
607
+ {
608
+ onClick: handleAppClick,
609
+ className: "my-6 p-4 border border-gray-200 dark:border-gray-700 rounded-lg bg-gradient-to-r from-blue-50 to-indigo-50 dark:from-blue-900/20 dark:to-indigo-900/20 cursor-pointer",
610
+ children: /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-3", children: [
611
+ /* @__PURE__ */ jsx("div", { className: "w-10 h-10 rounded-lg bg-blue-500 flex items-center justify-center", children: /* @__PURE__ */ jsx(
612
+ "svg",
613
+ {
614
+ className: "w-6 h-6 text-white",
615
+ fill: "none",
616
+ stroke: "currentColor",
617
+ viewBox: "0 0 24 24",
618
+ xmlns: "http://www.w3.org/2000/svg",
619
+ children: /* @__PURE__ */ jsx(
620
+ "path",
621
+ {
622
+ strokeLinecap: "round",
623
+ strokeLinejoin: "round",
624
+ strokeWidth: 2,
625
+ d: "M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"
626
+ }
627
+ )
628
+ }
629
+ ) }),
630
+ /* @__PURE__ */ jsxs("div", { children: [
631
+ /* @__PURE__ */ jsx("h3", { className: "font-semibold text-gray-800 dark:text-gray-200", children: appName }),
632
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-gray-600 dark:text-gray-400", children: "Click to open application" })
633
+ ] })
634
+ ] }) })
635
+ },
636
+ key || `app-${appName}`
637
+ );
638
+ };
639
+ const renderJson = (title, jsonData, key) => {
640
+ return /* @__PURE__ */ jsx(
641
+ JsonBlock,
642
+ {
643
+ title,
644
+ jsonContent: jsonData.trim(),
645
+ keyProp: key || `json-${title.replace(/\s/g, "")}`
646
+ },
647
+ key || `json-${title.replace(/\s/g, "")}`
648
+ );
649
+ };
650
+ const renderAnalytic = (analyticData, key) => {
651
+ var _a;
652
+ const lines = analyticData.trim().split("\n");
653
+ const headers = ((_a = lines[0]) == null ? void 0 : _a.split(";")) || [];
654
+ const dataRows = lines.slice(1);
655
+ const recordCount = dataRows.length;
656
+ const columnCount = headers.length;
657
+ const datasetName = headers.length > 0 ? `Dataset (${headers.join(", ")})` : "Analytics Dataset";
658
+ const handleAnalyticClick = () => {
659
+ if (onAnalyticOpen) {
660
+ onAnalyticOpen(datasetName, analyticData);
661
+ }
662
+ };
663
+ return /* @__PURE__ */ jsx(
664
+ "div",
665
+ {
666
+ onClick: handleAnalyticClick,
667
+ className: "my-6 p-4 border border-gray-200 dark:border-gray-700 rounded-lg bg-gradient-to-r from-emerald-50 to-teal-50 dark:from-emerald-900/20 dark:to-teal-900/20 cursor-pointer hover:shadow-md transition-shadow",
668
+ children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
669
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-3", children: [
670
+ /* @__PURE__ */ jsx("div", { className: "w-10 h-10 rounded-lg bg-emerald-500 flex items-center justify-center", children: /* @__PURE__ */ jsx(
671
+ "svg",
672
+ {
673
+ className: "w-6 h-6 text-white",
674
+ fill: "none",
675
+ stroke: "currentColor",
676
+ viewBox: "0 0 24 24",
677
+ xmlns: "http://www.w3.org/2000/svg",
678
+ children: /* @__PURE__ */ jsx(
679
+ "path",
680
+ {
681
+ strokeLinecap: "round",
682
+ strokeLinejoin: "round",
683
+ strokeWidth: 2,
684
+ d: "M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"
685
+ }
686
+ )
687
+ }
688
+ ) }),
689
+ /* @__PURE__ */ jsxs("div", { children: [
690
+ /* @__PURE__ */ jsx("h3", { className: "font-semibold text-gray-800 dark:text-gray-200", children: "Analytics Dataset" }),
691
+ /* @__PURE__ */ jsxs("p", { className: "text-sm text-gray-600 dark:text-gray-400", children: [
692
+ recordCount,
693
+ " records, ",
694
+ columnCount,
695
+ " columns - Click to analyze"
696
+ ] }),
697
+ headers.length > 0 && /* @__PURE__ */ jsxs("p", { className: "text-xs text-gray-500 dark:text-gray-500 mt-1", children: [
698
+ "Fields: ",
699
+ headers.slice(0, 3).join(", "),
700
+ headers.length > 3 ? ` (+${headers.length - 3} more)` : ""
701
+ ] })
702
+ ] })
703
+ ] }),
704
+ /* @__PURE__ */ jsx("div", { className: "px-3 py-1 bg-emerald-100 dark:bg-emerald-800/30 text-emerald-700 dark:text-emerald-300 text-xs font-medium rounded-full", children: "Pivot Table" })
705
+ ] })
706
+ },
707
+ key || `analytic-${analyticData.substring(0, 50)}`
708
+ );
709
+ };
710
+ const ImageLoadingIndicator = memo(
711
+ ({ isStreaming: isStreaming2 }) => {
712
+ useEffect(() => {
713
+ if (isStreaming2) {
714
+ const timeout = setTimeout(() => {
715
+ console.warn(
716
+ "Image generation timeout - this may indicate a streaming issue"
717
+ );
718
+ }, 3e4);
719
+ return () => clearTimeout(timeout);
720
+ }
721
+ }, [isStreaming2]);
722
+ return /* @__PURE__ */ jsxs(
723
+ "div",
724
+ {
725
+ className: "my-6 p-6 border border-gray-200 dark:border-gray-700 rounded-lg bg-gray-50 dark:bg-gray-800 w-full block",
726
+ style: {
727
+ display: "block",
728
+ contain: "layout",
729
+ marginTop: "1.5rem",
730
+ marginBottom: "1.5rem",
731
+ overscrollBehavior: "contain",
732
+ scrollSnapStop: "always"
733
+ },
734
+ children: [
735
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 mb-4", children: [
736
+ /* @__PURE__ */ jsx("div", { className: "h-8 w-8 rounded-full bg-indigo-100 dark:bg-indigo-900 flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "animate-spin h-5 w-5 border-2 border-indigo-500 dark:border-indigo-400 border-t-transparent rounded-full" }) }),
737
+ /* @__PURE__ */ jsx("div", { className: "font-medium text-gray-700 dark:text-gray-300", children: "Generating image..." })
738
+ ] }),
739
+ /* @__PURE__ */ jsx("div", { className: "h-64 md:h-80 relative rounded-md overflow-hidden bg-gray-100 dark:bg-gray-700 w-full flex items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "w-full h-full bg-gradient-to-r from-gray-200 via-gray-300 to-gray-200 dark:from-gray-600 dark:via-gray-500 dark:to-gray-600 animate-pulse relative overflow-hidden", children: [
740
+ /* @__PURE__ */ jsx("div", { className: "absolute inset-0 bg-gradient-to-r from-transparent via-white/20 to-transparent animate-[shimmer_2s_infinite] -translate-x-full" }),
741
+ /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ jsx(
742
+ ImageIcon,
743
+ {
744
+ size: 48,
745
+ className: "text-gray-400 dark:text-gray-500"
746
+ }
747
+ ) }),
748
+ /* @__PURE__ */ jsx("div", { className: "absolute top-2 left-2 w-4 h-4 border-l-2 border-t-2 border-gray-400 dark:border-gray-500" }),
749
+ /* @__PURE__ */ jsx("div", { className: "absolute top-2 right-2 w-4 h-4 border-r-2 border-t-2 border-gray-400 dark:border-gray-500" }),
750
+ /* @__PURE__ */ jsx("div", { className: "absolute bottom-2 left-2 w-4 h-4 border-l-2 border-b-2 border-gray-400 dark:border-gray-500" }),
751
+ /* @__PURE__ */ jsx("div", { className: "absolute bottom-2 right-2 w-4 h-4 border-r-2 border-b-2 border-gray-400 dark:border-gray-500" })
752
+ ] }) }),
753
+ /* @__PURE__ */ jsxs("div", { className: "mt-4 flex justify-between text-xs text-gray-500 dark:text-gray-400", children: [
754
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
755
+ /* @__PURE__ */ jsx("div", { className: "w-3 h-3 rounded-full bg-gray-400 dark:bg-gray-500 animate-pulse" }),
756
+ /* @__PURE__ */ jsx("span", { children: "Processing image data..." })
757
+ ] }),
758
+ /* @__PURE__ */ jsx("div", { children: "Please wait..." })
759
+ ] }),
760
+ /* @__PURE__ */ jsx("style", { children: `
761
+ @keyframes shimmer {
762
+ 0% {
763
+ transform: translateX(-100%);
764
+ }
765
+ 100% {
766
+ transform: translateX(100%);
767
+ }
768
+ }
769
+ ` })
770
+ ]
771
+ }
772
+ );
773
+ }
774
+ );
775
+ ImageLoadingIndicator.displayName = "ImageLoadingIndicator";
776
+ const renderImageLoading = () => {
777
+ return /* @__PURE__ */ jsx(ImageLoadingIndicator, { isStreaming });
778
+ };
779
+ const renderChartLoading = (type = "unknown") => {
780
+ const normalizedType = type.toLowerCase();
781
+ return /* @__PURE__ */ jsxs(
782
+ "div",
783
+ {
784
+ className: "my-6 p-6 border border-gray-200 dark:border-gray-700 rounded-lg bg-gray-50 dark:bg-gray-800 w-full block",
785
+ style: {
786
+ display: "block",
787
+ contain: "layout",
788
+ marginTop: "1.5rem",
789
+ marginBottom: "1.5rem",
790
+ overscrollBehavior: "contain",
791
+ scrollSnapStop: "always"
792
+ },
793
+ children: [
794
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 mb-4", children: [
795
+ /* @__PURE__ */ jsx("div", { className: "h-8 w-8 rounded-full bg-indigo-100 dark:bg-indigo-900 flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "animate-spin h-5 w-5 border-2 border-indigo-500 dark:border-indigo-400 border-t-transparent rounded-full" }) }),
796
+ /* @__PURE__ */ jsxs("div", { className: "font-medium text-gray-700 dark:text-gray-300", children: [
797
+ "Generating ",
798
+ normalizedType,
799
+ " chart..."
800
+ ] })
801
+ ] }),
802
+ /* @__PURE__ */ jsxs("div", { className: "h-64 md:h-80 relative rounded-md overflow-hidden bg-gray-100 dark:bg-gray-700 w-full", children: [
803
+ /* @__PURE__ */ jsx("div", { className: "absolute bottom-0 left-0 w-full h-0.5 bg-gray-300 dark:bg-gray-600" }),
804
+ /* @__PURE__ */ jsx("div", { className: "absolute bottom-0 left-0 w-0.5 h-full bg-gray-300 dark:bg-gray-600" }),
805
+ [1, 2, 3, 4].map((i) => /* @__PURE__ */ jsx(
806
+ "div",
807
+ {
808
+ className: "absolute w-full h-px bg-gray-200 dark:bg-gray-600",
809
+ style: { bottom: `${i * 20}%` }
810
+ },
811
+ `h-${i}`
812
+ )),
813
+ [1, 2, 3, 4, 5, 6, 7, 8].map((i) => /* @__PURE__ */ jsx(
814
+ "div",
815
+ {
816
+ className: "absolute h-full w-px bg-gray-200 dark:bg-gray-600",
817
+ style: { left: `${i * 12.5}%` }
818
+ },
819
+ `v-${i}`
820
+ )),
821
+ normalizedType === "bar" && /* @__PURE__ */ jsx("div", { className: "absolute bottom-0 left-0 w-full h-full flex items-end justify-around p-4", children: [45, 80, 30, 65, 50, 75, 40].map((h, i) => /* @__PURE__ */ jsx(
822
+ "div",
823
+ {
824
+ className: "w-8 bg-gray-300 dark:bg-gray-600 animate-pulse rounded-t-sm opacity-60",
825
+ style: { height: `${h}%` }
826
+ },
827
+ `bar-${i}`
828
+ )) }),
829
+ normalizedType === "line" && /* @__PURE__ */ jsx("div", { className: "absolute bottom-0 left-0 w-full h-full flex items-end justify-around p-4", children: [45, 80, 30, 65, 50, 75, 40].map((h, i) => /* @__PURE__ */ jsx(
830
+ "div",
831
+ {
832
+ className: "w-3 h-3 rounded-full bg-gray-400 dark:bg-gray-500 animate-pulse",
833
+ style: {
834
+ position: "absolute",
835
+ bottom: `${h}%`,
836
+ left: `${10 + i * 12}%`
837
+ }
838
+ },
839
+ `point-${i}`
840
+ )) }),
841
+ (normalizedType === "pie" || normalizedType === "doughnut") && /* @__PURE__ */ jsxs("div", { className: "absolute inset-0 flex items-center justify-center", children: [
842
+ /* @__PURE__ */ jsx(
843
+ "div",
844
+ {
845
+ className: `w-32 h-32 rounded-full border-8 border-gray-300 dark:border-gray-600 animate-pulse ${normalizedType === "doughnut" ? "border-[16px]" : "border-8"}`
846
+ }
847
+ ),
848
+ /* @__PURE__ */ jsx("div", { className: "absolute w-32 h-32", children: [1, 2, 3, 4].map((i) => /* @__PURE__ */ jsx(
849
+ "div",
850
+ {
851
+ className: "absolute w-16 h-0.5 bg-gray-400 dark:bg-gray-500 origin-left",
852
+ style: {
853
+ left: "50%",
854
+ top: "50%",
855
+ transform: `rotate(${i * 45}deg)`
856
+ }
857
+ },
858
+ `slice-${i}`
859
+ )) })
860
+ ] }),
861
+ normalizedType === "scatter" && /* @__PURE__ */ jsx("div", { className: "absolute inset-0", children: Array.from({ length: 15 }).map((_, i) => {
862
+ const x = 10 + Math.random() * 80;
863
+ const y = 10 + Math.random() * 80;
864
+ return /* @__PURE__ */ jsx(
865
+ "div",
866
+ {
867
+ className: "absolute w-3 h-3 rounded-full bg-gray-400 dark:bg-gray-500 animate-pulse",
868
+ style: {
869
+ left: `${x}%`,
870
+ bottom: `${y}%`,
871
+ animationDelay: `${i * 100}ms`
872
+ }
873
+ },
874
+ `scatter-${i}`
875
+ );
876
+ }) }),
877
+ normalizedType === "radar" && /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "w-48 h-48 relative", children: [
878
+ [1, 2, 3].map((level) => /* @__PURE__ */ jsx(
879
+ "div",
880
+ {
881
+ className: "absolute rounded-full border border-gray-300 dark:border-gray-600",
882
+ style: {
883
+ width: `${level * 33}%`,
884
+ height: `${level * 33}%`,
885
+ left: `${50 - level * 33 / 2}%`,
886
+ top: `${50 - level * 33 / 2}%`
887
+ }
888
+ },
889
+ `radar-web-${level}`
890
+ )),
891
+ [0, 60, 120, 180, 240, 300].map((angle) => /* @__PURE__ */ jsx(
892
+ "div",
893
+ {
894
+ className: "absolute w-24 h-0.5 bg-gray-300 dark:bg-gray-600 origin-left",
895
+ style: {
896
+ left: "50%",
897
+ top: "50%",
898
+ transform: `rotate(${angle}deg)`
899
+ }
900
+ },
901
+ `radar-axis-${angle}`
902
+ )),
903
+ /* @__PURE__ */ jsxs("div", { className: "absolute w-full h-full animate-pulse", children: [
904
+ /* @__PURE__ */ jsx(
905
+ "div",
906
+ {
907
+ className: "w-3 h-3 absolute rounded-full bg-gray-400 dark:bg-gray-500",
908
+ style: {
909
+ left: "50%",
910
+ top: "10%",
911
+ transform: "translate(-50%, -50%)"
912
+ }
913
+ }
914
+ ),
915
+ /* @__PURE__ */ jsx(
916
+ "div",
917
+ {
918
+ className: "w-3 h-3 absolute rounded-full bg-gray-400 dark:bg-gray-500",
919
+ style: {
920
+ left: "85%",
921
+ top: "35%",
922
+ transform: "translate(-50%, -50%)"
923
+ }
924
+ }
925
+ ),
926
+ /* @__PURE__ */ jsx(
927
+ "div",
928
+ {
929
+ className: "w-3 h-3 absolute rounded-full bg-gray-400 dark:bg-gray-500",
930
+ style: {
931
+ left: "75%",
932
+ top: "75%",
933
+ transform: "translate(-50%, -50%)"
934
+ }
935
+ }
936
+ ),
937
+ /* @__PURE__ */ jsx(
938
+ "div",
939
+ {
940
+ className: "w-3 h-3 absolute rounded-full bg-gray-400 dark:bg-gray-500",
941
+ style: {
942
+ left: "25%",
943
+ top: "75%",
944
+ transform: "translate(-50%, -50%)"
945
+ }
946
+ }
947
+ ),
948
+ /* @__PURE__ */ jsx(
949
+ "div",
950
+ {
951
+ className: "w-3 h-3 absolute rounded-full bg-gray-400 dark:bg-gray-500",
952
+ style: {
953
+ left: "15%",
954
+ top: "35%",
955
+ transform: "translate(-50%, -50%)"
956
+ }
957
+ }
958
+ )
959
+ ] })
960
+ ] }) }),
961
+ normalizedType !== "bar" && normalizedType !== "line" && normalizedType !== "pie" && normalizedType !== "doughnut" && normalizedType !== "scatter" && normalizedType !== "radar" && /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "text-gray-400 dark:text-gray-500 text-lg", children: [
962
+ "Preparing ",
963
+ normalizedType,
964
+ " chart..."
965
+ ] }) })
966
+ ] }),
967
+ /* @__PURE__ */ jsxs("div", { className: "mt-4 flex justify-between text-xs text-gray-500 dark:text-gray-400", children: [
968
+ /* @__PURE__ */ jsx("div", { className: "w-2/3 flex gap-2", children: ["Dataset 1", "Dataset 2"].map((label, i) => /* @__PURE__ */ jsxs(
969
+ "div",
970
+ {
971
+ className: "flex items-center",
972
+ children: [
973
+ /* @__PURE__ */ jsx(
974
+ "div",
975
+ {
976
+ className: `w-3 h-3 rounded-full mr-1 ${i === 0 ? "bg-gray-400 dark:bg-gray-500" : "bg-gray-300 dark:bg-gray-600"}`
977
+ }
978
+ ),
979
+ /* @__PURE__ */ jsx("span", { children: label })
980
+ ]
981
+ },
982
+ `legend-${i}`
983
+ )) }),
984
+ /* @__PURE__ */ jsx("div", { children: "Processing data..." })
985
+ ] })
986
+ ]
987
+ }
988
+ );
989
+ };
990
+ const renderAppLoading = (appName = "Unknown App") => {
991
+ return /* @__PURE__ */ jsxs("div", { className: "my-6 p-6 border border-gray-200 dark:border-gray-700 rounded-lg bg-gradient-to-r from-blue-50 to-indigo-50 dark:from-blue-900/20 dark:to-indigo-900/20 w-full block", children: [
992
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 mb-4", children: [
993
+ /* @__PURE__ */ jsx("div", { className: "h-8 w-8 rounded-full bg-blue-100 dark:bg-blue-900 flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "animate-spin h-5 w-5 border-2 border-blue-500 dark:border-blue-400 border-t-transparent rounded-full" }) }),
994
+ /* @__PURE__ */ jsxs("div", { className: "font-medium text-gray-700 dark:text-gray-300", children: [
995
+ "Preparing ",
996
+ appName,
997
+ "..."
998
+ ] })
999
+ ] }),
1000
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
1001
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-3", children: [
1002
+ /* @__PURE__ */ jsx("div", { className: "w-10 h-10 rounded-lg bg-blue-500 animate-pulse flex items-center justify-center", children: /* @__PURE__ */ jsx(
1003
+ "svg",
1004
+ {
1005
+ className: "w-6 h-6 text-white",
1006
+ fill: "none",
1007
+ stroke: "currentColor",
1008
+ viewBox: "0 0 24 24",
1009
+ xmlns: "http://www.w3.org/2000/svg",
1010
+ children: /* @__PURE__ */ jsx(
1011
+ "path",
1012
+ {
1013
+ strokeLinecap: "round",
1014
+ strokeLinejoin: "round",
1015
+ strokeWidth: 2,
1016
+ d: "M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"
1017
+ }
1018
+ )
1019
+ }
1020
+ ) }),
1021
+ /* @__PURE__ */ jsxs("div", { children: [
1022
+ /* @__PURE__ */ jsx("h3", { className: "font-semibold text-gray-800 dark:text-gray-200", children: appName }),
1023
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-gray-600 dark:text-gray-400", children: "Getting ready to launch..." })
1024
+ ] })
1025
+ ] }),
1026
+ /* @__PURE__ */ jsx("div", { className: "px-4 py-2 bg-gray-300 dark:bg-gray-600 text-gray-500 dark:text-gray-400 rounded-lg", children: "Loading..." })
1027
+ ] })
1028
+ ] });
1029
+ };
1030
+ const renderAnalyticLoading = () => {
1031
+ return /* @__PURE__ */ jsxs("div", { className: "my-6 p-6 border border-gray-200 dark:border-gray-700 rounded-lg bg-gradient-to-r from-emerald-50 to-teal-50 dark:from-emerald-900/20 dark:to-teal-900/20 w-full block", children: [
1032
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 mb-4", children: [
1033
+ /* @__PURE__ */ jsx("div", { className: "h-8 w-8 rounded-full bg-emerald-100 dark:bg-emerald-900 flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "animate-spin h-5 w-5 border-2 border-emerald-500 dark:border-emerald-400 border-t-transparent rounded-full" }) }),
1034
+ /* @__PURE__ */ jsx("div", { className: "font-medium text-gray-700 dark:text-gray-300", children: "Processing analytics data..." })
1035
+ ] }),
1036
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
1037
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-3", children: [
1038
+ /* @__PURE__ */ jsx("div", { className: "w-10 h-10 rounded-lg bg-emerald-500 animate-pulse flex items-center justify-center", children: /* @__PURE__ */ jsx(
1039
+ "svg",
1040
+ {
1041
+ className: "w-6 h-6 text-white",
1042
+ fill: "none",
1043
+ stroke: "currentColor",
1044
+ viewBox: "0 0 24 24",
1045
+ xmlns: "http://www.w3.org/2000/svg",
1046
+ children: /* @__PURE__ */ jsx(
1047
+ "path",
1048
+ {
1049
+ strokeLinecap: "round",
1050
+ strokeLinejoin: "round",
1051
+ strokeWidth: 2,
1052
+ d: "M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"
1053
+ }
1054
+ )
1055
+ }
1056
+ ) }),
1057
+ /* @__PURE__ */ jsxs("div", { children: [
1058
+ /* @__PURE__ */ jsx("h3", { className: "font-semibold text-gray-800 dark:text-gray-200", children: "Analytics Dataset" }),
1059
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-gray-600 dark:text-gray-400", children: "Preparing pivot table interface..." })
1060
+ ] })
1061
+ ] }),
1062
+ /* @__PURE__ */ jsx("div", { className: "px-3 py-1 bg-emerald-100 dark:bg-emerald-800/30 text-emerald-700 dark:text-emerald-300 text-xs font-medium rounded-full animate-pulse", children: "Loading..." })
1063
+ ] })
1064
+ ] });
1065
+ };
1066
+ const renderWidgetLoading = (widgetType = "card") => {
1067
+ const isForm = widgetType === "form";
1068
+ return /* @__PURE__ */ jsxs("div", { className: "my-6 p-6 border border-gray-200 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-800 w-full block", children: [
1069
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 mb-4", children: [
1070
+ /* @__PURE__ */ jsx("div", { className: "h-8 w-8 rounded-full bg-indigo-100 dark:bg-indigo-900 flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "animate-spin h-5 w-5 border-2 border-indigo-500 dark:border-indigo-400 border-t-transparent rounded-full" }) }),
1071
+ /* @__PURE__ */ jsxs("div", { className: "font-medium text-gray-700 dark:text-gray-300", children: [
1072
+ "Preparing ",
1073
+ isForm ? "form" : "card",
1074
+ " widget..."
1075
+ ] })
1076
+ ] }),
1077
+ isForm ? (
1078
+ // Form loading skeleton
1079
+ /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
1080
+ /* @__PURE__ */ jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded animate-pulse" }),
1081
+ /* @__PURE__ */ jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded animate-pulse" }),
1082
+ /* @__PURE__ */ jsx("div", { className: "h-24 bg-gray-200 dark:bg-gray-700 rounded animate-pulse" }),
1083
+ /* @__PURE__ */ jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded w-32 animate-pulse" })
1084
+ ] })
1085
+ ) : (
1086
+ // Card loading skeleton
1087
+ /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
1088
+ /* @__PURE__ */ jsx("div", { className: "h-6 bg-gray-200 dark:bg-gray-700 rounded w-3/4 animate-pulse" }),
1089
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3", children: [
1090
+ /* @__PURE__ */ jsx("div", { className: "h-16 bg-gray-200 dark:bg-gray-700 rounded animate-pulse" }),
1091
+ /* @__PURE__ */ jsx("div", { className: "h-16 bg-gray-200 dark:bg-gray-700 rounded animate-pulse" }),
1092
+ /* @__PURE__ */ jsx("div", { className: "h-16 bg-gray-200 dark:bg-gray-700 rounded animate-pulse" }),
1093
+ /* @__PURE__ */ jsx("div", { className: "h-16 bg-gray-200 dark:bg-gray-700 rounded animate-pulse" })
1094
+ ] })
1095
+ ] })
1096
+ )
1097
+ ] });
1098
+ };
1099
+ const CustomMarkdown = ({ content: content2 }) => /* @__PURE__ */ jsx(
1100
+ ReactMarkdown,
1101
+ {
1102
+ remarkPlugins: [remarkGfm],
1103
+ rehypePlugins: [rehypeRaw],
1104
+ components: {
1105
+ blockquote: ({ children }) => /* @__PURE__ */ jsx("blockquote", { className: "border-l-4 border-gray-300 dark:border-gray-700 pl-4 py-2 my-4 bg-gray-100 dark:bg-gray-800 rounded-md", children }),
1106
+ p: ({ children }) => /* @__PURE__ */ jsx("p", { className: "mb-2 last:mb-0", children }),
1107
+ h1: ({ children }) => /* @__PURE__ */ jsx("h1", { className: "text-2xl font-bold mb-2 last:mb-0", children }),
1108
+ h2: ({ children }) => /* @__PURE__ */ jsx("h2", { className: "text-xl font-bold mb-2 last:mb-0", children }),
1109
+ h3: ({ children }) => /* @__PURE__ */ jsx("h3", { className: "text-lg font-bold mb-2 last:mb-0", children }),
1110
+ h4: ({ children }) => /* @__PURE__ */ jsx("h4", { className: "text-base font-bold mb-2 last:mb-0", children }),
1111
+ h5: ({ children }) => /* @__PURE__ */ jsx("h5", { className: "text-sm font-bold mb-2 last:mb-0", children }),
1112
+ h6: ({ children }) => /* @__PURE__ */ jsx("h6", { className: "text-xs font-bold mb-2 last:mb-0", children }),
1113
+ ul: ({ children }) => /* @__PURE__ */ jsx("ul", { className: "list-disc list-outside ml-6 mb-2 last:mb-0 space-y-1", children }),
1114
+ ol: ({ children }) => /* @__PURE__ */ jsx("ol", { className: "list-decimal list-outside ml-6 mb-2 last:mb-0 space-y-1", children }),
1115
+ li: ({ children }) => /* @__PURE__ */ jsx("li", { className: "mb-1", children }),
1116
+ hr: ({ children }) => /* @__PURE__ */ jsx("hr", { className: "my-4 border-t border-gray-200 dark:border-gray-700 mb-3" }),
1117
+ a: ({ href, children }) => /* @__PURE__ */ jsx(
1118
+ "a",
1119
+ {
1120
+ href,
1121
+ target: "_blank",
1122
+ rel: "noopener noreferrer",
1123
+ className: "text-blue-500 hover:text-blue-600 underline",
1124
+ children
1125
+ }
1126
+ ),
1127
+ pre: (_a) => {
1128
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
1129
+ const childArray = Array.isArray(children) ? children : [children];
1130
+ const codeElement = childArray.find(
1131
+ (child) => {
1132
+ var _a2, _b2;
1133
+ return (_b2 = (_a2 = child == null ? void 0 : child.props) == null ? void 0 : _a2.className) == null ? void 0 : _b2.startsWith("language-");
1134
+ }
1135
+ );
1136
+ if (codeElement) {
1137
+ const language = codeElement.props.className.replace(
1138
+ "language-",
1139
+ ""
1140
+ ) || "text";
1141
+ const code = String(
1142
+ codeElement.props.children || ""
1143
+ ).replace(/\n$/, "");
1144
+ return /* @__PURE__ */ jsx(
1145
+ CodeBlock,
1146
+ {
1147
+ language,
1148
+ code,
1149
+ theme
1150
+ }
1151
+ );
1152
+ }
1153
+ return /* @__PURE__ */ jsx("pre", { className: "my-3 p-4 rounded-lg bg-gray-50 dark:bg-gray-900 border border-gray-200 dark:border-gray-700 overflow-x-auto", children: /* @__PURE__ */ jsx("code", { className: "text-sm font-mono text-gray-800 dark:text-gray-200", children }) });
1154
+ },
1155
+ code: (_c) => {
1156
+ var _d = _c, { className, children } = _d, props = __objRest(_d, ["className", "children"]);
1157
+ const isInlineCode = !className;
1158
+ return isInlineCode ? /* @__PURE__ */ jsx("code", { className: "bg-gray-100 dark:bg-gray-800 text-gray-800 dark:text-gray-200 px-1.5 py-0.5 rounded text-sm font-mono", children }) : /* @__PURE__ */ jsx("code", __spreadProps(__spreadValues({ className }, props), { children }));
1159
+ },
1160
+ table: ({ children }) => /* @__PURE__ */ jsx("div", { className: "overflow-x-auto my-4", children: /* @__PURE__ */ jsx("table", { className: "border-collapse w-full", children }) }),
1161
+ th: ({ children }) => /* @__PURE__ */ jsx("th", { className: "border border-gray-300 dark:border-gray-700 bg-gray-100 dark:bg-gray-800 px-4 py-2 text-left", children }),
1162
+ td: (_e) => {
1163
+ var _f = _e, { children } = _f, props = __objRest(_f, ["children"]);
1164
+ return /* @__PURE__ */ jsx(
1165
+ "td",
1166
+ __spreadProps(__spreadValues({
1167
+ className: "border border-gray-300 dark:border-gray-700 px-4 py-2"
1168
+ }, props), {
1169
+ children
1170
+ })
1171
+ );
1172
+ }
1173
+ },
1174
+ children: content2
1175
+ }
1176
+ );
1177
+ const processTextContent = useMemo(() => {
1178
+ return (text) => {
1179
+ if (!isStreaming) {
1180
+ const parts = text.split(
1181
+ /(```(?:chart:[a-z]+|image|app:[^\n]+|analytic|(?:widget:)?(?:card|form|decision)|json:[^\n]+)\n[\s\S]*?\n```)/g
1182
+ );
1183
+ if (parts.length > 1) {
1184
+ return /* @__PURE__ */ jsx(Fragment, { children: parts.map((part, i) => {
1185
+ const chartMatch = part.match(
1186
+ /```chart:([a-z]+)\n([\s\S]*?)\n```/
1187
+ );
1188
+ const imageMatch = part.match(
1189
+ /```image\n([\s\S]*?)\n```/
1190
+ );
1191
+ const appMatch = part.match(
1192
+ /```app:([^\n]+)\n([\s\S]*?)\n```/
1193
+ );
1194
+ const analyticMatch = part.match(
1195
+ /```analytic\n([\s\S]*?)\n```/
1196
+ );
1197
+ const widgetMatch = part.match(
1198
+ /```(?:widget:(card|form|decision)|decision)\n([\s\S]*?)\n```/
1199
+ );
1200
+ const jsonMatch = part.match(
1201
+ /```json:([^\n]+)\n([\s\S]*?)\n```/
1202
+ );
1203
+ if (chartMatch) {
1204
+ const [_, chartType, chartData] = chartMatch;
1205
+ const chartKey = `completed-chart-${i}-${chartData.substring(0, 50).replace(/\s/g, "")}`;
1206
+ return /* @__PURE__ */ jsx(
1207
+ "div",
1208
+ {
1209
+ className: "my-6 block w-full",
1210
+ style: {
1211
+ display: "block",
1212
+ contain: "layout",
1213
+ marginTop: "1.5rem",
1214
+ marginBottom: "1.5rem",
1215
+ overscrollBehavior: "contain",
1216
+ scrollSnapStop: "always"
1217
+ },
1218
+ children: renderChart(
1219
+ chartType,
1220
+ chartData,
1221
+ chartKey
1222
+ )
1223
+ },
1224
+ chartKey
1225
+ );
1226
+ } else if (imageMatch) {
1227
+ const [_, imageData] = imageMatch;
1228
+ const imageKey = `completed-image-${i}-${imageData.substring(0, 50).replace(/\s/g, "")}`;
1229
+ return /* @__PURE__ */ jsx(
1230
+ "div",
1231
+ {
1232
+ className: "my-6 block w-full",
1233
+ style: {
1234
+ display: "block",
1235
+ contain: "layout",
1236
+ marginTop: "1.5rem",
1237
+ marginBottom: "1.5rem",
1238
+ overscrollBehavior: "contain",
1239
+ scrollSnapStop: "always"
1240
+ },
1241
+ children: renderImage(imageData, imageKey)
1242
+ },
1243
+ imageKey
1244
+ );
1245
+ } else if (appMatch) {
1246
+ const [_, appName, appUrl] = appMatch;
1247
+ const appKey = `completed-app-${i}-${appName.replace(
1248
+ /\s/g,
1249
+ ""
1250
+ )}`;
1251
+ return /* @__PURE__ */ jsx(
1252
+ "div",
1253
+ {
1254
+ className: "my-6 block w-full",
1255
+ style: {
1256
+ display: "block",
1257
+ contain: "layout",
1258
+ marginTop: "1.5rem",
1259
+ marginBottom: "1.5rem",
1260
+ overscrollBehavior: "contain",
1261
+ scrollSnapStop: "always"
1262
+ },
1263
+ children: renderApp(
1264
+ appName,
1265
+ appUrl.trim(),
1266
+ appKey
1267
+ )
1268
+ },
1269
+ appKey
1270
+ );
1271
+ } else if (analyticMatch) {
1272
+ const [_, analyticData] = analyticMatch;
1273
+ const analyticKey = `completed-analytic-${i}-${analyticData.substring(0, 50).replace(/\s/g, "")}`;
1274
+ return /* @__PURE__ */ jsx(
1275
+ "div",
1276
+ {
1277
+ className: "my-6 block w-full",
1278
+ style: {
1279
+ display: "block",
1280
+ contain: "layout",
1281
+ marginTop: "1.5rem",
1282
+ marginBottom: "1.5rem",
1283
+ overscrollBehavior: "contain",
1284
+ scrollSnapStop: "always"
1285
+ },
1286
+ children: renderAnalytic(
1287
+ analyticData.trim(),
1288
+ analyticKey
1289
+ )
1290
+ },
1291
+ analyticKey
1292
+ );
1293
+ } else if (jsonMatch) {
1294
+ const [_, jsonTitle, jsonData] = jsonMatch;
1295
+ const jsonKey = `completed-json-${i}-${jsonTitle.replace(
1296
+ /\s/g,
1297
+ ""
1298
+ )}`;
1299
+ return renderJson(
1300
+ jsonTitle,
1301
+ jsonData,
1302
+ jsonKey
1303
+ );
1304
+ }
1305
+ return part ? /* @__PURE__ */ jsx(
1306
+ CustomMarkdown,
1307
+ {
1308
+ content: part
1309
+ },
1310
+ `text-${i}`
1311
+ ) : null;
1312
+ }) });
1313
+ }
1314
+ return /* @__PURE__ */ jsx(CustomMarkdown, { content: text });
1315
+ }
1316
+ const chartTagMatches = [...text.matchAll(/```chart:([a-z]+)\n/g)];
1317
+ const imageTagMatches = [...text.matchAll(/```image\n/g)];
1318
+ const appTagMatches = [...text.matchAll(/```app:([^\n]+)\n/g)];
1319
+ const analyticTagMatches = [...text.matchAll(/```analytic\n/g)];
1320
+ const widgetTagMatches = [
1321
+ ...text.matchAll(
1322
+ /```(?:widget:(?:card|form|decision)|decision)\n/g
1323
+ )
1324
+ ];
1325
+ const jsonTagMatches = [...text.matchAll(/```json:([^\n]+)\n/g)];
1326
+ if (!chartTagMatches.length && !imageTagMatches.length && !appTagMatches.length && !analyticTagMatches.length && !widgetTagMatches.length && !jsonTagMatches.length) {
1327
+ return /* @__PURE__ */ jsx(CustomMarkdown, { content: text });
1328
+ }
1329
+ const allTags = [
1330
+ ...chartTagMatches.map((match) => ({
1331
+ type: "chart",
1332
+ index: match.index,
1333
+ chartType: match[1],
1334
+ match: match[0]
1335
+ })),
1336
+ ...imageTagMatches.map((match) => ({
1337
+ type: "image",
1338
+ index: match.index,
1339
+ match: match[0]
1340
+ })),
1341
+ ...appTagMatches.map((match) => ({
1342
+ type: "app",
1343
+ index: match.index,
1344
+ appName: match[1],
1345
+ match: match[0]
1346
+ })),
1347
+ ...analyticTagMatches.map((match) => ({
1348
+ type: "analytic",
1349
+ index: match.index,
1350
+ match: match[0]
1351
+ })),
1352
+ ...widgetTagMatches.map((match) => {
1353
+ const widgetType = match[1] || "decision";
1354
+ return {
1355
+ type: "widget",
1356
+ index: match.index,
1357
+ widgetType,
1358
+ match: match[0]
1359
+ };
1360
+ }),
1361
+ ...jsonTagMatches.map((match) => ({
1362
+ type: "json",
1363
+ index: match.index,
1364
+ jsonTitle: match[1],
1365
+ match: match[0]
1366
+ }))
1367
+ ].sort((a, b) => a.index - b.index);
1368
+ if (!allTags.length) {
1369
+ return /* @__PURE__ */ jsx(CustomMarkdown, { content: text });
1370
+ }
1371
+ const lastTag = allTags[allTags.length - 1];
1372
+ const lastOpeningTagIndex = lastTag.index;
1373
+ const textBeforeLastBlock = text.substring(0, lastOpeningTagIndex);
1374
+ const lastBlockContent = text.substring(lastOpeningTagIndex);
1375
+ const hasClosingTag = /\n```|```\n|```$/.test(lastBlockContent);
1376
+ let processedBeforeBlock = null;
1377
+ if (textBeforeLastBlock) {
1378
+ const beforeParts = textBeforeLastBlock.split(
1379
+ /(```(?:chart:[a-z]+|image|app:[^\n]+|analytic|(?:widget:)?(?:card|form|decision)|json:[^\n]+)\n[\s\S]*?\n```)/g
1380
+ );
1381
+ if (beforeParts.length > 1) {
1382
+ processedBeforeBlock = /* @__PURE__ */ jsx(Fragment, { children: beforeParts.map((part, i) => {
1383
+ const chartMatch = part.match(
1384
+ /```chart:([a-z]+)\n([\s\S]*?)\n```/
1385
+ );
1386
+ const imageMatch = part.match(
1387
+ /```image\n([\s\S]*?)\n```/
1388
+ );
1389
+ const appMatch = part.match(
1390
+ /```app:([^\n]+)\n([\s\S]*?)\n```/
1391
+ );
1392
+ const analyticMatch = part.match(
1393
+ /```analytic\n([\s\S]*?)\n```/
1394
+ );
1395
+ const widgetMatch = part.match(
1396
+ /```(?:widget:(card|form|decision)|decision)\n([\s\S]*?)\n```/
1397
+ );
1398
+ const jsonMatch = part.match(
1399
+ /```json:([^\n]+)\n([\s\S]*?)\n```/
1400
+ );
1401
+ if (chartMatch) {
1402
+ const [_, chartType, chartData] = chartMatch;
1403
+ const chartKey = `streaming-complete-chart-${i}-${chartData.substring(0, 50).replace(/\s/g, "")}`;
1404
+ return /* @__PURE__ */ jsx(
1405
+ "div",
1406
+ {
1407
+ className: "my-6 block w-full",
1408
+ style: {
1409
+ display: "block",
1410
+ contain: "layout",
1411
+ marginTop: "1.5rem",
1412
+ marginBottom: "1.5rem",
1413
+ overscrollBehavior: "contain",
1414
+ scrollSnapStop: "always"
1415
+ },
1416
+ children: renderChart(
1417
+ chartType,
1418
+ chartData,
1419
+ chartKey
1420
+ )
1421
+ },
1422
+ chartKey
1423
+ );
1424
+ } else if (imageMatch) {
1425
+ const [_, imageData] = imageMatch;
1426
+ const imageKey = `streaming-complete-image-${i}-${imageData.substring(0, 50).replace(/\s/g, "")}`;
1427
+ return /* @__PURE__ */ jsx(
1428
+ "div",
1429
+ {
1430
+ className: "my-6 block w-full",
1431
+ style: {
1432
+ display: "block",
1433
+ contain: "layout",
1434
+ marginTop: "1.5rem",
1435
+ marginBottom: "1.5rem",
1436
+ overscrollBehavior: "contain",
1437
+ scrollSnapStop: "always"
1438
+ },
1439
+ children: renderImage(imageData, imageKey)
1440
+ },
1441
+ imageKey
1442
+ );
1443
+ } else if (appMatch) {
1444
+ const [_, appName, appUrl] = appMatch;
1445
+ const appKey = `streaming-complete-app-${i}-${appName.replace(
1446
+ /\s/g,
1447
+ ""
1448
+ )}`;
1449
+ return /* @__PURE__ */ jsx(
1450
+ "div",
1451
+ {
1452
+ className: "my-6 block w-full",
1453
+ style: {
1454
+ display: "block",
1455
+ contain: "layout",
1456
+ marginTop: "1.5rem",
1457
+ marginBottom: "1.5rem",
1458
+ overscrollBehavior: "contain",
1459
+ scrollSnapStop: "always"
1460
+ },
1461
+ children: renderApp(
1462
+ appName,
1463
+ appUrl.trim(),
1464
+ appKey
1465
+ )
1466
+ },
1467
+ appKey
1468
+ );
1469
+ } else if (analyticMatch) {
1470
+ const [_, analyticData] = analyticMatch;
1471
+ const analyticKey = `streaming-complete-analytic-${i}-${analyticData.substring(0, 50).replace(/\s/g, "")}`;
1472
+ return /* @__PURE__ */ jsx(
1473
+ "div",
1474
+ {
1475
+ className: "my-6 block w-full",
1476
+ style: {
1477
+ display: "block",
1478
+ contain: "layout",
1479
+ marginTop: "1.5rem",
1480
+ marginBottom: "1.5rem",
1481
+ overscrollBehavior: "contain",
1482
+ scrollSnapStop: "always"
1483
+ },
1484
+ children: renderAnalytic(
1485
+ analyticData.trim(),
1486
+ analyticKey
1487
+ )
1488
+ },
1489
+ analyticKey
1490
+ );
1491
+ } else if (jsonMatch) {
1492
+ const [_, jsonTitle, jsonData] = jsonMatch;
1493
+ const jsonKey = `streaming-complete-json-${i}-${jsonTitle.replace(
1494
+ /\s/g,
1495
+ ""
1496
+ )}`;
1497
+ return renderJson(
1498
+ jsonTitle,
1499
+ jsonData,
1500
+ jsonKey
1501
+ );
1502
+ }
1503
+ return part ? /* @__PURE__ */ jsx(
1504
+ CustomMarkdown,
1505
+ {
1506
+ content: part
1507
+ },
1508
+ `text-${i}`
1509
+ ) : null;
1510
+ }) });
1511
+ } else {
1512
+ processedBeforeBlock = /* @__PURE__ */ jsx(CustomMarkdown, { content: textBeforeLastBlock });
1513
+ }
1514
+ }
1515
+ let lastBlockElement = null;
1516
+ if (hasClosingTag) {
1517
+ if (lastTag.type === "chart") {
1518
+ const chartMatch = lastBlockContent.match(
1519
+ /```chart:([a-z]+)\n([\s\S]*?)\n```/
1520
+ );
1521
+ if (chartMatch) {
1522
+ const [_, chartType, chartData] = chartMatch;
1523
+ const chartKey = `streaming-last-complete-chart-${chartData.substring(0, 50).replace(/\s/g, "")}`;
1524
+ lastBlockElement = /* @__PURE__ */ jsx(
1525
+ "div",
1526
+ {
1527
+ className: "my-6 block w-full",
1528
+ style: {
1529
+ display: "block",
1530
+ contain: "layout",
1531
+ marginTop: "1.5rem",
1532
+ marginBottom: "1.5rem",
1533
+ overscrollBehavior: "contain",
1534
+ scrollSnapStop: "always"
1535
+ },
1536
+ children: renderChart(chartType, chartData, chartKey)
1537
+ },
1538
+ chartKey
1539
+ );
1540
+ }
1541
+ } else if (lastTag.type === "image") {
1542
+ const imageMatch = lastBlockContent.match(
1543
+ /```image\n([\s\S]*?)\n```/
1544
+ );
1545
+ if (imageMatch) {
1546
+ const [_, imageData] = imageMatch;
1547
+ const imageKey = `streaming-last-complete-image-${imageData.substring(0, 50).replace(/\s/g, "")}`;
1548
+ lastBlockElement = /* @__PURE__ */ jsx(
1549
+ "div",
1550
+ {
1551
+ className: "my-6 block w-full",
1552
+ style: {
1553
+ display: "block",
1554
+ contain: "layout",
1555
+ marginTop: "1.5rem",
1556
+ marginBottom: "1.5rem",
1557
+ overscrollBehavior: "contain",
1558
+ scrollSnapStop: "always"
1559
+ },
1560
+ children: renderImage(imageData, imageKey)
1561
+ },
1562
+ imageKey
1563
+ );
1564
+ }
1565
+ } else if (lastTag.type === "app") {
1566
+ const appMatch = lastBlockContent.match(
1567
+ /```app:([^\n]+)\n([\s\S]*?)\n```/
1568
+ );
1569
+ if (appMatch) {
1570
+ const [_, appName, appUrl] = appMatch;
1571
+ const appKey = `streaming-last-complete-app-${appName.replace(
1572
+ /\s/g,
1573
+ ""
1574
+ )}`;
1575
+ lastBlockElement = /* @__PURE__ */ jsx(
1576
+ "div",
1577
+ {
1578
+ className: "my-6 block w-full",
1579
+ style: {
1580
+ display: "block",
1581
+ contain: "layout",
1582
+ marginTop: "1.5rem",
1583
+ marginBottom: "1.5rem",
1584
+ overscrollBehavior: "contain",
1585
+ scrollSnapStop: "always"
1586
+ },
1587
+ children: renderApp(appName, appUrl.trim(), appKey)
1588
+ },
1589
+ appKey
1590
+ );
1591
+ }
1592
+ } else if (lastTag.type === "analytic") {
1593
+ const analyticMatch = lastBlockContent.match(
1594
+ /```analytic\n([\s\S]*?)\n```/
1595
+ );
1596
+ if (analyticMatch) {
1597
+ const [_, analyticData] = analyticMatch;
1598
+ const analyticKey = `streaming-last-complete-analytic-${analyticData.substring(0, 50).replace(/\s/g, "")}`;
1599
+ lastBlockElement = /* @__PURE__ */ jsx(
1600
+ "div",
1601
+ {
1602
+ className: "my-6 block w-full",
1603
+ style: {
1604
+ display: "block",
1605
+ contain: "layout",
1606
+ marginTop: "1.5rem",
1607
+ marginBottom: "1.5rem",
1608
+ overscrollBehavior: "contain",
1609
+ scrollSnapStop: "always"
1610
+ },
1611
+ children: renderAnalytic(
1612
+ analyticData.trim(),
1613
+ analyticKey
1614
+ )
1615
+ },
1616
+ analyticKey
1617
+ );
1618
+ }
1619
+ } else if (lastTag.type === "json") {
1620
+ const jsonMatch = lastBlockContent.match(
1621
+ /```json:([^\n]+)\n([\s\S]*?)\n```/
1622
+ );
1623
+ if (jsonMatch) {
1624
+ const [_, jsonTitle, jsonData] = jsonMatch;
1625
+ const jsonKey = `streaming-last-complete-json-${jsonTitle.replace(
1626
+ /\s/g,
1627
+ ""
1628
+ )}`;
1629
+ lastBlockElement = renderJson(
1630
+ jsonTitle,
1631
+ jsonData,
1632
+ jsonKey
1633
+ );
1634
+ }
1635
+ }
1636
+ } else {
1637
+ if (lastTag.type === "chart") {
1638
+ const chartType = lastTag.chartType;
1639
+ lastBlockElement = renderChartLoading(chartType);
1640
+ } else if (lastTag.type === "image") {
1641
+ lastBlockElement = renderImageLoading();
1642
+ } else if (lastTag.type === "app") {
1643
+ const appName = lastTag.appName;
1644
+ lastBlockElement = renderAppLoading(appName);
1645
+ } else if (lastTag.type === "analytic") {
1646
+ lastBlockElement = renderAnalyticLoading();
1647
+ } else if (lastTag.type === "widget") {
1648
+ const widgetType = lastTag.widgetType;
1649
+ lastBlockElement = renderWidgetLoading(widgetType);
1650
+ } else if (lastTag.type === "json") {
1651
+ const jsonTitle = lastTag.jsonTitle;
1652
+ lastBlockElement = /* @__PURE__ */ jsx("div", { className: "my-4 border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden bg-gray-50 dark:bg-gray-800", children: /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between p-4", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
1653
+ /* @__PURE__ */ jsx("div", { className: "animate-spin h-4 w-4 border-2 border-blue-500 dark:border-blue-400 border-t-transparent rounded-full" }),
1654
+ /* @__PURE__ */ jsx("span", { className: "font-semibold text-gray-800 dark:text-gray-200", children: jsonTitle }),
1655
+ /* @__PURE__ */ jsx("span", { className: "text-xs px-2 py-0.5 bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 rounded-full", children: "JSON" })
1656
+ ] }) }) });
1657
+ }
1658
+ }
1659
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1660
+ processedBeforeBlock,
1661
+ lastBlockElement
1662
+ ] });
1663
+ };
1664
+ }, [isStreaming, theme]);
1665
+ const renderContent = () => {
1666
+ var _a, _b;
1667
+ const contentToRender = content;
1668
+ if (typeof contentToRender === "string") {
1669
+ if (isStreaming && role === "assistant" && displayedLength < contentToRender.length) {
1670
+ const staticContent = contentToRender.slice(0, displayedLength);
1671
+ const newContent = contentToRender.slice(displayedLength);
1672
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1673
+ message.isToolExecuting && message.executingToolName && /* @__PURE__ */ jsx(
1674
+ ToolExecutionIndicator,
1675
+ {
1676
+ toolName: message.executingToolName
1677
+ }
1678
+ ),
1679
+ staticContent && processTextContent(staticContent),
1680
+ newContent && /* @__PURE__ */ jsx("span", { className: "streaming-content", children: processTextContent(newContent) }),
1681
+ /* @__PURE__ */ jsx(StreamingIndicator, {})
1682
+ ] });
1683
+ }
1684
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1685
+ message.isToolExecuting && message.executingToolName && /* @__PURE__ */ jsx(
1686
+ ToolExecutionIndicator,
1687
+ {
1688
+ toolName: message.executingToolName
1689
+ }
1690
+ ),
1691
+ ((_a = message.metadata) == null ? void 0 : _a.steps) && /* @__PURE__ */ jsx(
1692
+ ToolExecutionWidget,
1693
+ {
1694
+ steps: message.metadata.steps,
1695
+ theme
1696
+ }
1697
+ ),
1698
+ processTextContent(contentToRender),
1699
+ /* @__PURE__ */ jsx(StreamingIndicator, {})
1700
+ ] });
1701
+ } else if (Array.isArray(contentToRender)) {
1702
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
1703
+ message.isToolExecuting && message.executingToolName && /* @__PURE__ */ jsx(
1704
+ ToolExecutionIndicator,
1705
+ {
1706
+ toolName: message.executingToolName
1707
+ }
1708
+ ),
1709
+ ((_b = message.metadata) == null ? void 0 : _b.steps) && /* @__PURE__ */ jsx(
1710
+ ToolExecutionWidget,
1711
+ {
1712
+ steps: message.metadata.steps,
1713
+ theme
1714
+ }
1715
+ ),
1716
+ contentToRender.map((part, i) => {
1717
+ if (part.type === "text") {
1718
+ const textContent = part.text;
1719
+ return /* @__PURE__ */ jsx("div", { children: processTextContent(textContent) }, `text-${i}`);
1720
+ } else if (part.type === "file") {
1721
+ const filePart = part;
1722
+ return /* @__PURE__ */ jsxs(
1723
+ "div",
1724
+ {
1725
+ className: "border border-gray-200 dark:border-gray-700 rounded-md p-4",
1726
+ children: [
1727
+ /* @__PURE__ */ jsxs("p", { className: "text-sm text-gray-500 mb-2 flex items-center", children: [
1728
+ /* @__PURE__ */ jsx(FileText, { size: 16, className: "mr-1" }),
1729
+ "PDF Document:"
1730
+ ] }),
1731
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
1732
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium mb-2", children: filePart.filename || "Document" }),
1733
+ /* @__PURE__ */ jsx(
1734
+ "a",
1735
+ {
1736
+ href: filePart.data,
1737
+ download: filePart.filename,
1738
+ className: "mb-2 inline-flex items-center text-blue-500 hover:text-blue-600",
1739
+ children: "Download"
1740
+ }
1741
+ )
1742
+ ] })
1743
+ ]
1744
+ },
1745
+ `file-${i}-${filePart.filename || i}`
1746
+ );
1747
+ } else if (part.type === "image") {
1748
+ const imagePart = part;
1749
+ return /* @__PURE__ */ jsx("div", { className: "p-2", children: /* @__PURE__ */ jsxs("div", { className: "max-w-full", children: [
1750
+ /* @__PURE__ */ jsx(
1751
+ "img",
1752
+ {
1753
+ src: imagePart.image,
1754
+ alt: "Attached image",
1755
+ className: "max-w-full max-h-96 rounded-md object-contain mb-2 cursor-pointer hover:opacity-90 transition-opacity",
1756
+ onClick: () => handleImageClick(
1757
+ imagePart.image,
1758
+ "Attached image"
1759
+ )
1760
+ }
1761
+ ),
1762
+ /* @__PURE__ */ jsx("div", { className: "flex justify-end text-sm mr-2", children: /* @__PURE__ */ jsx(
1763
+ "a",
1764
+ {
1765
+ href: imagePart.image,
1766
+ download: "image.png",
1767
+ className: "text-blue-500 hover:text-blue-600",
1768
+ children: "Download"
1769
+ }
1770
+ ) })
1771
+ ] }) }, `image-${i}-${i}`);
1772
+ }
1773
+ return null;
1774
+ }),
1775
+ /* @__PURE__ */ jsx(StreamingIndicator, {})
1776
+ ] });
1777
+ }
1778
+ return /* @__PURE__ */ jsx("div", { children: "..." });
1779
+ };
1780
+ const formatTime = (date) => {
1781
+ try {
1782
+ if (!date) {
1783
+ return "";
1784
+ }
1785
+ return new Intl.DateTimeFormat(void 0, {
1786
+ day: "numeric",
1787
+ month: "short",
1788
+ year: "numeric",
1789
+ hour: "numeric",
1790
+ minute: "numeric",
1791
+ hour12: false
1792
+ }).format(new Date(date));
1793
+ } catch (error) {
1794
+ console.error("Error formatting date:", date, error);
1795
+ return "--:--";
1796
+ }
1797
+ };
1798
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1799
+ /* @__PURE__ */ jsx("div", { ref: messageContainerRef, className: "mb-3", children: /* @__PURE__ */ jsx(
1800
+ "div",
1801
+ {
1802
+ className: `flex ${role === "user" ? "justify-end" : "justify-start"}`,
1803
+ children: /* @__PURE__ */ jsxs(
1804
+ "div",
1805
+ {
1806
+ className: `max-w-[100%] sm:max-w-[90%] ${role === "user" ? "" : ""}`,
1807
+ children: [
1808
+ /* @__PURE__ */ jsx(
1809
+ "div",
1810
+ {
1811
+ className: `rounded-2xl ${role === "assistant" ? "bg-transparent pl-0" : ""} p-3 transition-all duration-200`,
1812
+ style: role === "user" ? { backgroundColor: messageBubbleColor } : void 0,
1813
+ children: /* @__PURE__ */ jsx(
1814
+ "div",
1815
+ {
1816
+ className: `prose dark:prose-invert prose-p:leading-relaxed prose-pre:p-0 max-w-none`,
1817
+ children: renderContent()
1818
+ }
1819
+ )
1820
+ }
1821
+ ),
1822
+ /* @__PURE__ */ jsxs(
1823
+ "div",
1824
+ {
1825
+ className: `mt-1 text-xs text-gray-500 dark:text-gray-400 ${role === "user" ? "text-right pr-1" : "text-left"}`,
1826
+ children: [
1827
+ formatTime(message.createdAt),
1828
+ role === "assistant" && /* @__PURE__ */ jsx(
1829
+ "button",
1830
+ {
1831
+ onClick: copyToClipboard,
1832
+ className: "ml-2 inline-flex items-center text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition-colors",
1833
+ "aria-label": "Copy message",
1834
+ children: copied ? /* @__PURE__ */ jsx(
1835
+ Check,
1836
+ {
1837
+ size: 14,
1838
+ className: "text-green-500"
1839
+ }
1840
+ ) : /* @__PURE__ */ jsx(Copy, { size: 14 })
1841
+ }
1842
+ )
1843
+ ]
1844
+ }
1845
+ )
1846
+ ]
1847
+ }
1848
+ )
1849
+ }
1850
+ ) }),
1851
+ imageDialogOpen && selectedImage && /* @__PURE__ */ jsx(
1852
+ "div",
1853
+ {
1854
+ className: "fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",
1855
+ onClick: closeImageDialog,
1856
+ children: /* @__PURE__ */ jsxs(
1857
+ "div",
1858
+ {
1859
+ className: "relative max-w-[95vw] max-h-[95vh] bg-white dark:bg-gray-900 rounded-lg overflow-hidden shadow-2xl",
1860
+ onClick: (e) => e.stopPropagation(),
1861
+ children: [
1862
+ /* @__PURE__ */ jsx("div", { className: "absolute top-0 right-0 z-10 p-4", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
1863
+ /* @__PURE__ */ jsx(
1864
+ "a",
1865
+ {
1866
+ href: selectedImage.src,
1867
+ download: "image.png",
1868
+ className: "p-2 bg-black bg-opacity-50 hover:bg-opacity-70 text-white rounded-full transition-all cursor-pointer",
1869
+ title: "Download image",
1870
+ children: /* @__PURE__ */ jsx(Download, { size: 20 })
1871
+ }
1872
+ ),
1873
+ /* @__PURE__ */ jsx(
1874
+ "button",
1875
+ {
1876
+ onClick: closeImageDialog,
1877
+ className: "p-2 bg-black bg-opacity-50 hover:bg-opacity-70 text-white rounded-full transition-all cursor-pointer",
1878
+ title: "Close",
1879
+ children: /* @__PURE__ */ jsx(X, { size: 20 })
1880
+ }
1881
+ )
1882
+ ] }) }),
1883
+ /* @__PURE__ */ jsx(
1884
+ "img",
1885
+ {
1886
+ src: selectedImage.src,
1887
+ alt: selectedImage.alt,
1888
+ className: "max-w-full max-h-[95vh] object-contain"
1889
+ }
1890
+ )
1891
+ ]
1892
+ }
1893
+ )
1894
+ }
1895
+ )
1896
+ ] });
1897
+ }
1898
+ export {
1899
+ ChatMessage as default
1900
+ };