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