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