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