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