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