@terryavg/neptune-ai-chatbot 1.0.1 → 1.0.3

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