reachat 3.0.0 → 3.2.0

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.
@@ -13,9 +13,9 @@ import Mention from "@tiptap/extension-mention";
13
13
  import { Slot } from "@radix-ui/react-slot";
14
14
  import { motion, AnimatePresence } from "motion/react";
15
15
  import ReactMarkdown from "react-markdown";
16
- import { Prism } from "react-syntax-highlighter";
17
16
  import rehypeKatex from "rehype-katex";
18
17
  import rehypeRaw from "rehype-raw";
18
+ import { Prism } from "react-syntax-highlighter";
19
19
  import { SparklineChart, RadialAreaChart, RadialAreaSeries, RadialBarChart, RadialBarSeries, PieChart, PieArcSeries, AreaChart, AreaSeries, LinearYAxis, LinearXAxis, LineChart, LineSeries, BarChart, BarSeries } from "reaviz";
20
20
  import { findAndReplace } from "mdast-util-find-and-replace";
21
21
  import debounce from "lodash/debounce.js";
@@ -35,6 +35,7 @@ const ChatContext = createContext({
35
35
  const SvgPaperclip = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1, strokeLinecap: "round", strokeLinejoin: "round", className: "lucide lucide-paperclip", ...props }, /* @__PURE__ */ React.createElement("path", { d: "m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48" }));
36
36
  const FileInput = ({
37
37
  allowedFiles,
38
+ multiple,
38
39
  onFileUpload,
39
40
  isLoading,
40
41
  disabled,
@@ -50,6 +51,7 @@ const FileInput = ({
50
51
  ref: fileInputRef,
51
52
  className: "hidden",
52
53
  accept: allowedFiles.join(","),
54
+ multiple,
53
55
  onChange: (e) => {
54
56
  onFileUpload(e);
55
57
  if (fileInputRef.current) {
@@ -65,10 +67,7 @@ const FileInput = ({
65
67
  variant: "text",
66
68
  disabled: isLoading || disabled,
67
69
  className: cn(theme.input.upload),
68
- onClick: () => {
69
- var _a;
70
- return (_a = fileInputRef.current) == null ? void 0 : _a.click();
71
- },
70
+ onClick: () => fileInputRef.current?.click(),
72
71
  children: attachIcon
73
72
  }
74
73
  )
@@ -183,17 +182,25 @@ const chatTheme = {
183
182
  }
184
183
  },
185
184
  markdown: {
185
+ hr: "my-4 border-t border-stroke-neutral-4",
186
186
  copy: "sticky py-1 [&>svg]:w-4 [&>svg]:h-4 opacity-50",
187
187
  p: "mb-2",
188
- a: "text-blue-400 underline",
188
+ a: "text-buttons-colors-link-primary-text-resting underline",
189
189
  table: "table-auto w-full m-2",
190
- th: "px-4 py-2 text-left font-bold border-b border-gray-500",
190
+ th: "px-4 py-2 text-left font-bold border-b border-stroke-neutral-4",
191
191
  td: "px-4 py-2",
192
192
  code: "m-2 rounded-b relative",
193
- toolbar: "text-xs dark:bg-gray-700/50 flex items-center justify-between px-2 py-1 rounded-t sticky top-0 backdrop-blur-md bg-gray-200 ",
193
+ inlineCode: "bg-gradient-neutral-200 p-1 rounded",
194
+ toolbar: "text-xs flex items-center justify-between px-2 py-1 rounded-t sticky top-0 backdrop-blur-md bg-gradient-neutral-500/50",
194
195
  li: "mb-2 ml-6",
195
196
  ul: "mb-4 list-disc",
196
- ol: "mb-4 list-decimal"
197
+ ol: "mb-4 list-decimal",
198
+ h1: "text-4xl font-bold mb-4 mt-6",
199
+ h2: "text-3xl font-bold mb-3 mt-5",
200
+ h3: "text-2xl font-bold mb-3 mt-4",
201
+ h4: "text-xl font-bold mb-2 mt-3",
202
+ h5: "text-lg font-bold mb-2 mt-2",
203
+ h6: "text-base font-bold mb-2 mt-2"
197
204
  },
198
205
  footer: {
199
206
  base: "mt-3 flex gap-1.5",
@@ -323,18 +330,16 @@ const chatTheme = {
323
330
  const POPUP_STYLE = { zIndex: 9999 };
324
331
  const MentionList = forwardRef(
325
332
  ({ items, command, triggerChar, config, query }, ref) => {
326
- var _a;
327
333
  const [selectedIndex, setSelectedIndex] = useState(0);
328
334
  const itemRefs = useRef([]);
329
335
  const { theme } = useContext(ChatContext);
330
- const popupTheme = ((_a = theme == null ? void 0 : theme.input) == null ? void 0 : _a.popup) || chatTheme.input.popup;
336
+ const popupTheme = theme?.input?.popup || chatTheme.input.popup;
331
337
  useEffect(() => {
332
338
  setSelectedIndex(0);
333
339
  }, [items]);
334
340
  useEffect(() => {
335
- var _a2;
336
341
  if (itemRefs.current[selectedIndex]) {
337
- (_a2 = itemRefs.current[selectedIndex]) == null ? void 0 : _a2.scrollIntoView({
342
+ itemRefs.current[selectedIndex]?.scrollIntoView({
338
343
  block: "nearest",
339
344
  behavior: "smooth"
340
345
  });
@@ -465,10 +470,7 @@ function createSuggestionConfig(config, triggerChar, suggestionActiveRef) {
465
470
  if (!query) return config.items.slice(0, config.maxResults || 10);
466
471
  const lowerQuery = query.toLowerCase();
467
472
  return config.items.filter(
468
- (item) => {
469
- var _a;
470
- return item.label.toLowerCase().includes(lowerQuery) || ((_a = item.description) == null ? void 0 : _a.toLowerCase().includes(lowerQuery));
471
- }
473
+ (item) => item.label.toLowerCase().includes(lowerQuery) || item.description?.toLowerCase().includes(lowerQuery)
472
474
  ).slice(0, config.maxResults || 10);
473
475
  },
474
476
  // Render callbacks for managing the popup lifecycle
@@ -495,7 +497,7 @@ function createSuggestionConfig(config, triggerChar, suggestionActiveRef) {
495
497
  },
496
498
  // Called when query or items change
497
499
  onUpdate: (props) => {
498
- component == null ? void 0 : component.updateProps({
500
+ component?.updateProps({
499
501
  ...props,
500
502
  triggerChar,
501
503
  config
@@ -503,25 +505,23 @@ function createSuggestionConfig(config, triggerChar, suggestionActiveRef) {
503
505
  if (!props.clientRect) {
504
506
  return;
505
507
  }
506
- if (component == null ? void 0 : component.element) {
508
+ if (component?.element) {
507
509
  updatePopupPosition(props.editor, component.element);
508
510
  }
509
511
  },
510
512
  // Handle keyboard navigation (Escape closes popup)
511
513
  onKeyDown: (props) => {
512
- var _a;
513
514
  if (props.event.key === "Escape") {
514
- component == null ? void 0 : component.destroy();
515
+ component?.destroy();
515
516
  return true;
516
517
  }
517
- return ((_a = component == null ? void 0 : component.ref) == null ? void 0 : _a.onKeyDown(props)) ?? false;
518
+ return component?.ref?.onKeyDown(props) ?? false;
518
519
  },
519
520
  // Cleanup when suggestion is dismissed
520
521
  onExit: () => {
521
- var _a;
522
522
  suggestionActiveRef.current = false;
523
- (_a = component == null ? void 0 : component.element) == null ? void 0 : _a.remove();
524
- component == null ? void 0 : component.destroy();
523
+ component?.element?.remove();
524
+ component?.destroy();
525
525
  }
526
526
  };
527
527
  }
@@ -541,12 +541,10 @@ const RichTextInput = forwardRef(
541
541
  onSubmit,
542
542
  onChange
543
543
  }, ref) => {
544
- var _a, _b, _c, _d;
545
544
  const { theme } = useContext(ChatContext);
546
545
  const containerRef = useRef(null);
547
546
  const suggestionActiveRef = useRef(false);
548
547
  const extensions = useMemo(() => {
549
- var _a2, _b2, _c2, _d2, _e, _f, _g, _h;
550
548
  const exts = [
551
549
  Document,
552
550
  Paragraph.configure({
@@ -565,7 +563,7 @@ const RichTextInput = forwardRef(
565
563
  exts.push(
566
564
  Mention.configure({
567
565
  HTMLAttributes: {
568
- class: cn((_b2 = (_a2 = theme == null ? void 0 : theme.input) == null ? void 0 : _a2.tag) == null ? void 0 : _b2.base, (_d2 = (_c2 = theme == null ? void 0 : theme.input) == null ? void 0 : _c2.tag) == null ? void 0 : _d2.mention)
566
+ class: cn(theme?.input?.tag?.base, theme?.input?.tag?.mention)
569
567
  },
570
568
  suggestion: createSuggestionConfig(
571
569
  mentions,
@@ -581,7 +579,7 @@ const RichTextInput = forwardRef(
581
579
  exts.push(
582
580
  Mention.configure({
583
581
  HTMLAttributes: {
584
- class: cn((_f = (_e = theme == null ? void 0 : theme.input) == null ? void 0 : _e.tag) == null ? void 0 : _f.base, (_h = (_g = theme == null ? void 0 : theme.input) == null ? void 0 : _g.tag) == null ? void 0 : _h.command)
582
+ class: cn(theme?.input?.tag?.base, theme?.input?.tag?.command)
585
583
  },
586
584
  suggestion: createSuggestionConfig(
587
585
  commands,
@@ -602,13 +600,13 @@ const RichTextInput = forwardRef(
602
600
  immediatelyRender: false,
603
601
  onUpdate: ({ editor: editor2 }) => {
604
602
  const text = editor2.getText();
605
- onChange == null ? void 0 : onChange(text);
603
+ onChange?.(text);
606
604
  },
607
605
  editorProps: {
608
606
  attributes: {
609
607
  class: cn(
610
- (_b = (_a = theme == null ? void 0 : theme.input) == null ? void 0 : _a.editor) == null ? void 0 : _b.base,
611
- (_d = (_c = theme == null ? void 0 : theme.input) == null ? void 0 : _c.editor) == null ? void 0 : _d.placeholder
608
+ theme?.input?.editor?.base,
609
+ theme?.input?.editor?.placeholder
612
610
  ),
613
611
  style: `min-height: ${minHeight}px; max-height: ${maxHeight}px;`,
614
612
  role: "textbox",
@@ -626,7 +624,7 @@ const RichTextInput = forwardRef(
626
624
  if (text.trim() && onSubmit) {
627
625
  event.preventDefault();
628
626
  onSubmit(text);
629
- editor == null ? void 0 : editor.commands.clearContent();
627
+ editor?.commands.clearContent();
630
628
  return true;
631
629
  }
632
630
  }
@@ -643,16 +641,16 @@ const RichTextInput = forwardRef(
643
641
  }, [editor, autoFocus]);
644
642
  useImperativeHandle(ref, () => ({
645
643
  focus: () => {
646
- editor == null ? void 0 : editor.commands.focus();
644
+ editor?.commands.focus();
647
645
  },
648
646
  getValue: () => {
649
- return (editor == null ? void 0 : editor.getText()) || "";
647
+ return editor?.getText() || "";
650
648
  },
651
649
  setValue: (newValue) => {
652
- editor == null ? void 0 : editor.commands.setContent(newValue ? `<p>${newValue}</p>` : "");
650
+ editor?.commands.setContent(newValue ? `<p>${newValue}</p>` : "");
653
651
  },
654
652
  insertText: (text) => {
655
- editor == null ? void 0 : editor.commands.insertContent(text);
653
+ editor?.commands.insertContent(text);
656
654
  }
657
655
  }));
658
656
  return /* @__PURE__ */ jsx("div", { ref: containerRef, className: cn("relative w-full", className), children: /* @__PURE__ */ jsx(EditorContent, { editor }) });
@@ -663,6 +661,7 @@ const ChatInput = forwardRef(
663
661
  ({
664
662
  allowedFiles,
665
663
  placeholder = "Type a message...",
664
+ allowMultipleFiles = false,
666
665
  defaultValue,
667
666
  sendIcon = /* @__PURE__ */ jsx(SvgSend, {}),
668
667
  stopIcon = /* @__PURE__ */ jsx(SvgStop, {}),
@@ -686,43 +685,37 @@ const ChatInput = forwardRef(
686
685
  const inputRef = useRef(null);
687
686
  const containerRef = useRef(null);
688
687
  useEffect(() => {
689
- var _a;
690
688
  if (autoFocus) {
691
- (_a = inputRef.current) == null ? void 0 : _a.focus();
689
+ inputRef.current?.focus();
692
690
  }
693
691
  }, [activeSessionId, autoFocus]);
694
692
  useImperativeHandle(ref, () => ({
695
693
  focus: () => {
696
- var _a;
697
- (_a = inputRef.current) == null ? void 0 : _a.focus();
694
+ inputRef.current?.focus();
698
695
  },
699
696
  getValue: () => {
700
- var _a;
701
- return ((_a = inputRef.current) == null ? void 0 : _a.getValue()) || "";
697
+ return inputRef.current?.getValue() || "";
702
698
  },
703
699
  setValue: (value) => {
704
- var _a;
705
700
  setMessage(value);
706
- (_a = inputRef.current) == null ? void 0 : _a.setValue(value);
701
+ inputRef.current?.setValue(value);
707
702
  },
708
703
  insertText: (text) => {
709
- var _a;
710
- (_a = inputRef.current) == null ? void 0 : _a.insertText(text);
704
+ inputRef.current?.insertText(text);
711
705
  }
712
706
  }));
713
707
  const handleSendMessage = useCallback(() => {
714
- var _a, _b;
715
- const currentMessage = (_a = inputRef.current) == null ? void 0 : _a.getValue();
708
+ const currentMessage = inputRef.current?.getValue();
716
709
  if (currentMessage.trim()) {
717
- sendMessage == null ? void 0 : sendMessage(currentMessage);
710
+ sendMessage?.(currentMessage);
718
711
  setMessage("");
719
- (_b = inputRef.current) == null ? void 0 : _b.setValue("");
712
+ inputRef.current?.setValue("");
720
713
  }
721
714
  }, [sendMessage]);
722
715
  const handleSubmit = useCallback(
723
716
  (value) => {
724
717
  if (value.trim()) {
725
- sendMessage == null ? void 0 : sendMessage(value);
718
+ sendMessage?.(value);
726
719
  setMessage("");
727
720
  }
728
721
  },
@@ -731,16 +724,12 @@ const ChatInput = forwardRef(
731
724
  const handleChange = useCallback((value) => {
732
725
  setMessage(value);
733
726
  }, []);
734
- const handleFileUpload = useCallback(
735
- (event) => {
736
- var _a;
737
- const file = (_a = event.target.files) == null ? void 0 : _a[0];
738
- if (file && fileUpload) {
739
- fileUpload(file);
740
- }
741
- },
742
- [fileUpload]
743
- );
727
+ const handleFileUpload = (event) => {
728
+ const files = event.target.files;
729
+ if (files?.length && fileUpload) {
730
+ fileUpload(allowMultipleFiles ? Array.from(files) : files[0]);
731
+ }
732
+ };
744
733
  const mentionsConfig = useMemo(
745
734
  () => mentions ? { ...mentions, trigger: mentions.trigger || "@" } : void 0,
746
735
  [mentions]
@@ -768,10 +757,11 @@ const ChatInput = forwardRef(
768
757
  }
769
758
  ),
770
759
  /* @__PURE__ */ jsxs("div", { className: cn(theme.input.actions.base), children: [
771
- (allowedFiles == null ? void 0 : allowedFiles.length) > 0 && /* @__PURE__ */ jsx(
760
+ allowedFiles?.length > 0 && /* @__PURE__ */ jsx(
772
761
  FileInput,
773
762
  {
774
763
  allowedFiles,
764
+ multiple: allowMultipleFiles,
775
765
  onFileUpload: handleFileUpload,
776
766
  isLoading,
777
767
  disabled,
@@ -1872,14 +1862,17 @@ const light = {
1872
1862
  const CodeHighlighter = ({
1873
1863
  className,
1874
1864
  children,
1865
+ inlineClassName,
1875
1866
  copyClassName,
1876
1867
  copyIcon = /* @__PURE__ */ jsx(SvgCopy, {}),
1877
1868
  language,
1878
1869
  toolbarClassName,
1879
- theme = dark
1870
+ theme = dark,
1871
+ ...props
1880
1872
  }) => {
1881
- const match = language == null ? void 0 : language.match(/language-(\w+)/);
1873
+ const match = language?.match(/language-(\w+)/);
1882
1874
  const lang = match ? match[1] : "text";
1875
+ const isInline = !match;
1883
1876
  const handleCopy = (text) => {
1884
1877
  navigator.clipboard.writeText(text).then(() => {
1885
1878
  console.log("Text copied to clipboard");
@@ -1887,6 +1880,9 @@ const CodeHighlighter = ({
1887
1880
  console.error("Could not copy text: ", err);
1888
1881
  });
1889
1882
  };
1883
+ if (isInline) {
1884
+ return /* @__PURE__ */ jsx("code", { className: cn(inlineClassName), ...props, children });
1885
+ }
1890
1886
  return /* @__PURE__ */ jsxs("div", { className: cn("relative", className), children: [
1891
1887
  /* @__PURE__ */ jsxs("div", { className: cn(toolbarClassName), children: [
1892
1888
  /* @__PURE__ */ jsx("div", { children: lang }),
@@ -1902,14 +1898,7 @@ const CodeHighlighter = ({
1902
1898
  }
1903
1899
  )
1904
1900
  ] }),
1905
- /* @__PURE__ */ jsx(
1906
- Prism,
1907
- {
1908
- language: lang,
1909
- style: theme,
1910
- children
1911
- }
1912
- )
1901
+ /* @__PURE__ */ jsx(Prism, { language: lang, style: theme, children })
1913
1902
  ] });
1914
1903
  };
1915
1904
  const TableComponent = ({ children, ...props }) => /* @__PURE__ */ jsx("table", { ...props, children });
@@ -1919,16 +1908,19 @@ const Markdown = ({
1919
1908
  children,
1920
1909
  remarkPlugins,
1921
1910
  rehypePlugins = [rehypeRaw, rehypeKatex],
1911
+ theme: themeProp,
1922
1912
  customComponents
1923
1913
  }) => {
1924
- const { theme, markdownComponents } = useContext(ChatContext);
1914
+ const { theme: contextTheme, markdownComponents } = useContext(ChatContext);
1915
+ const theme = themeProp || contextTheme;
1925
1916
  const components = useMemo(() => {
1926
1917
  const defaultComponents = {
1927
1918
  code: ({ className, children: children2, ...props }) => /* @__PURE__ */ jsx(
1928
1919
  CodeHighlighter,
1929
1920
  {
1930
1921
  ...props,
1931
- language: className,
1922
+ language: cn(className),
1923
+ inlineClassName: cn(theme.messages.message.markdown.inlineCode),
1932
1924
  className: cn(theme.messages.message.markdown.code, className),
1933
1925
  copyClassName: cn(theme.messages.message.markdown.copy),
1934
1926
  toolbarClassName: cn(theme.messages.message.markdown.toolbar),
@@ -1957,20 +1949,27 @@ const Markdown = ({
1957
1949
  }
1958
1950
  ),
1959
1951
  a: (props) => /* @__PURE__ */ jsx("a", { ...props, className: cn(theme.messages.message.markdown.a) }),
1952
+ hr: (props) => /* @__PURE__ */ jsx("hr", { ...props, className: cn(theme.messages.message.markdown.hr) }),
1960
1953
  p: (props) => /* @__PURE__ */ jsx("p", { ...props, className: cn(theme.messages.message.markdown.p) }),
1961
1954
  li: (props) => /* @__PURE__ */ jsx("li", { ...props, className: cn(theme.messages.message.markdown.li) }),
1962
1955
  ul: (props) => /* @__PURE__ */ jsx("ul", { ...props, className: cn(theme.messages.message.markdown.ul) }),
1963
1956
  ol: (props) => /* @__PURE__ */ jsx("ol", { ...props, className: cn(theme.messages.message.markdown.ol) }),
1957
+ h1: (props) => /* @__PURE__ */ jsx("h1", { ...props, className: cn(theme.messages.message.markdown.h1) }),
1958
+ h2: (props) => /* @__PURE__ */ jsx("h2", { ...props, className: cn(theme.messages.message.markdown.h2) }),
1959
+ h3: (props) => /* @__PURE__ */ jsx("h3", { ...props, className: cn(theme.messages.message.markdown.h3) }),
1960
+ h4: (props) => /* @__PURE__ */ jsx("h4", { ...props, className: cn(theme.messages.message.markdown.h4) }),
1961
+ h5: (props) => /* @__PURE__ */ jsx("h5", { ...props, className: cn(theme.messages.message.markdown.h5) }),
1962
+ h6: (props) => /* @__PURE__ */ jsx("h6", { ...props, className: cn(theme.messages.message.markdown.h6) }),
1964
1963
  // 'redact' is a custom element created by remarkRedact, not a standard
1965
1964
  // HTML tag, so it falls outside react-markdown's Components type.
1966
- redact: (props) => /* @__PURE__ */ jsx(
1965
+ redact: ((props) => /* @__PURE__ */ jsx(
1967
1966
  Redact,
1968
1967
  {
1969
1968
  value: props["data-redact-value"] || props.children,
1970
1969
  allowToggle: true,
1971
1970
  tooltipText: `${props["data-redact-name"] || "Sensitive"} information - Click to toggle`
1972
1971
  }
1973
- )
1972
+ ))
1974
1973
  };
1975
1974
  return {
1976
1975
  ...defaultComponents,
@@ -2179,8 +2178,8 @@ const commonRedactMatchers = [
2179
2178
  bitcoinMatcher
2180
2179
  ];
2181
2180
  const SvgFile = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 16, height: 16, viewBox: "0 0 16 16", fill: "currentColor", ...props }, /* @__PURE__ */ React.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M2.7036 1.37034C3.04741 1.02653 3.51373 0.833374 3.99996 0.833374H9.33329H9.33331C9.47275 0.833374 9.59885 0.890449 9.68954 0.98251L13.6843 4.97722C13.7763 5.0679 13.8333 5.19398 13.8333 5.33337L13.8333 5.3379V13.3334C13.8333 13.8196 13.6401 14.2859 13.2963 14.6297C12.9525 14.9736 12.4862 15.1667 12 15.1667H3.99996C3.51373 15.1667 3.04741 14.9736 2.7036 14.6297C2.35978 14.2859 2.16663 13.8196 2.16663 13.3334V2.66671C2.16663 2.18048 2.35978 1.71416 2.7036 1.37034ZM3.99996 1.83337H8.83331V5.33337C8.83331 5.60952 9.05717 5.83337 9.33331 5.83337H12.8333V13.3334C12.8333 13.5544 12.7455 13.7663 12.5892 13.9226C12.4329 14.0789 12.221 14.1667 12 14.1667H3.99996C3.77895 14.1667 3.56698 14.0789 3.4107 13.9226C3.25442 13.7663 3.16663 13.5544 3.16663 13.3334V2.66671C3.16663 2.44569 3.25442 2.23373 3.4107 2.07745C3.56698 1.92117 3.77895 1.83337 3.99996 1.83337ZM9.83331 2.5405L12.1262 4.83337H9.83331V2.5405ZM5.33331 8.16663C5.05717 8.16663 4.83331 8.39048 4.83331 8.66663C4.83331 8.94277 5.05717 9.16663 5.33331 9.16663H10.6666C10.9428 9.16663 11.1666 8.94277 11.1666 8.66663C11.1666 8.39048 10.9428 8.16663 10.6666 8.16663H5.33331ZM4.83331 11.3334C4.83331 11.0572 5.05717 10.8334 5.33331 10.8334H10.6666C10.9428 10.8334 11.1666 11.0572 11.1666 11.3334C11.1666 11.6095 10.9428 11.8334 10.6666 11.8334H5.33331C5.05717 11.8334 4.83331 11.6095 4.83331 11.3334ZM5.33331 5.5C5.05717 5.5 4.83331 5.72386 4.83331 6C4.83331 6.27614 5.05717 6.5 5.33331 6.5H6.66665C6.94279 6.5 7.16665 6.27614 7.16665 6C7.16665 5.72386 6.94279 5.5 6.66665 5.5H5.33331Z" }));
2182
- const DefaultFileRenderer = lazy(() => import("./DefaultFileRenderer-CJ3jwiQa.js"));
2183
- const CSVFileRenderer = lazy(() => import("./CSVFileRenderer-C2tuexJf.js"));
2181
+ const DefaultFileRenderer = lazy(() => import("./DefaultFileRenderer-BrFdb4JQ.js"));
2182
+ const CSVFileRenderer = lazy(() => import("./CSVFileRenderer-Darm68BZ.js"));
2184
2183
  const ImageFileRenderer = lazy(() => import("./ImageFileRenderer-C8tVW3I8.js"));
2185
2184
  const PDFFileRenderer = lazy(() => import("./PDFFileRenderer-DQdFS2l6.js"));
2186
2185
  const FILE_TYPE_RENDERER_MAP = {
@@ -2197,7 +2196,7 @@ const MessageFile = ({
2197
2196
  }) => {
2198
2197
  const { theme } = useContext(ChatContext);
2199
2198
  const FileRenderer = useMemo(() => {
2200
- const Renderer = Object.keys(FILE_TYPE_RENDERER_MAP).find((key) => type == null ? void 0 : type.startsWith(key)) ?? "default";
2199
+ const Renderer = Object.keys(FILE_TYPE_RENDERER_MAP).find((key) => type?.startsWith(key)) ?? "default";
2201
2200
  return FILE_TYPE_RENDERER_MAP[Renderer] || DefaultFileRenderer;
2202
2201
  }, [type]);
2203
2202
  return /* @__PURE__ */ jsx(
@@ -2221,8 +2220,7 @@ const MessageFiles = memo(({ files, children }) => {
2221
2220
  }
2222
2221
  return files.reduce(
2223
2222
  (acc, file) => {
2224
- var _a;
2225
- if ((_a = file.type) == null ? void 0 : _a.startsWith("image/")) {
2223
+ if (file.type?.startsWith("image/")) {
2226
2224
  acc.imageFiles.push(file);
2227
2225
  } else {
2228
2226
  acc.otherFiles.push(file);
@@ -2301,7 +2299,7 @@ const MessageQuestion = memo(
2301
2299
  ...props,
2302
2300
  children: children || /* @__PURE__ */ jsxs(Fragment, { children: [
2303
2301
  /* @__PURE__ */ jsx(MessageFiles, { files }),
2304
- /* @__PURE__ */ jsx(Markdown, { remarkPlugins, children: question }),
2302
+ /* @__PURE__ */ jsx(Markdown, { remarkPlugins, theme, children: question }),
2305
2303
  isLong && !expanded && /* @__PURE__ */ jsx(
2306
2304
  Button,
2307
2305
  {
@@ -2328,7 +2326,7 @@ const MessageResponse = memo(
2328
2326
  "data-compact": isCompact,
2329
2327
  className: cn(theme.messages.message.response),
2330
2328
  children: children || /* @__PURE__ */ jsxs(Fragment, { children: [
2331
- /* @__PURE__ */ jsx(Markdown, { remarkPlugins, children: response }),
2329
+ /* @__PURE__ */ jsx(Markdown, { remarkPlugins, theme, children: response }),
2332
2330
  isLoading && /* @__PURE__ */ jsx(
2333
2331
  motion.div,
2334
2332
  {
@@ -2346,7 +2344,6 @@ const MessageResponse = memo(
2346
2344
  );
2347
2345
  }
2348
2346
  );
2349
- MessageResponse.displayName = "MessageResponse";
2350
2347
  const MessageSource = ({ title, url, image, limit = 50 }) => {
2351
2348
  const { theme, isCompact } = useContext(ChatContext);
2352
2349
  return /* @__PURE__ */ jsxs(
@@ -2478,9 +2475,9 @@ const messageVariants = {
2478
2475
  }
2479
2476
  };
2480
2477
  const SessionMessage = memo(
2481
- ({ conversation, isLast, children }) => {
2478
+ ({ conversation, isLast, children, className }) => {
2482
2479
  const { theme, isLoading } = useContext(ChatContext);
2483
- return /* @__PURE__ */ jsx(motion.div, { variants: messageVariants, children: /* @__PURE__ */ jsx(Card, { className: cn(theme.messages.message.base), children: children || /* @__PURE__ */ jsxs(Fragment, { children: [
2480
+ return /* @__PURE__ */ jsx(motion.div, { variants: messageVariants, children: /* @__PURE__ */ jsx(Card, { className: cn(theme.messages.message.base, className), children: children || /* @__PURE__ */ jsxs(Fragment, { children: [
2484
2481
  /* @__PURE__ */ jsx(
2485
2482
  MessageQuestion,
2486
2483
  {
@@ -2521,10 +2518,15 @@ const SessionMessages = ({
2521
2518
  children,
2522
2519
  newSessionContent,
2523
2520
  limit = 10,
2521
+ className,
2524
2522
  showMoreText = "Show more",
2525
- showScrollBottomButton = false
2523
+ autoScroll = true,
2524
+ showLoadMoreButton = false,
2525
+ showScrollBottomButton,
2526
+ loadMoreButtonDisabled,
2527
+ onScroll,
2528
+ onLoadMore
2526
2529
  }) => {
2527
- var _a, _b, _c, _d, _e, _f;
2528
2530
  const { activeSession, theme } = useContext(ChatContext);
2529
2531
  const contentRef = useRef(null);
2530
2532
  const messagesRef = useRef(null);
@@ -2546,12 +2548,12 @@ const SessionMessages = ({
2546
2548
  return () => currentRef.removeEventListener("scroll", handleScroll);
2547
2549
  }, [showScrollBottomButton]);
2548
2550
  useEffect(() => {
2549
- if (contentRef.current) {
2551
+ if (contentRef.current && autoScroll) {
2550
2552
  requestAnimationFrame(
2551
2553
  () => contentRef.current.scrollTop = contentRef.current.scrollHeight
2552
2554
  );
2553
2555
  }
2554
- }, [activeSession, isAnimating]);
2556
+ }, [activeSession, autoScroll, isAnimating]);
2555
2557
  const handleShowMore = () => {
2556
2558
  showNext(limit);
2557
2559
  requestAnimationFrame(() => contentRef.current.scrollTop = 0);
@@ -2565,7 +2567,7 @@ const SessionMessages = ({
2565
2567
  }
2566
2568
  };
2567
2569
  const reversedConvos = useMemo(
2568
- () => [...(activeSession == null ? void 0 : activeSession.conversations) ?? []].reverse(),
2570
+ () => [...activeSession?.conversations ?? []].reverse(),
2569
2571
  [activeSession]
2570
2572
  );
2571
2573
  const { data, hasMore, showNext } = useInfinityList({
@@ -2573,25 +2575,27 @@ const SessionMessages = ({
2573
2575
  size: limit
2574
2576
  });
2575
2577
  const reReversedConvo = useMemo(() => [...data].reverse(), [data]);
2576
- const convosToRender = limit ? reReversedConvo : activeSession == null ? void 0 : activeSession.conversations;
2578
+ const convosToRender = limit ? reReversedConvo : activeSession?.conversations;
2577
2579
  if (!activeSession) {
2578
2580
  return /* @__PURE__ */ jsx(SessionEmpty, { children: newSessionContent });
2579
2581
  }
2580
- return /* @__PURE__ */ jsxs("div", { className: "relative flex-1 overflow-y-hidden", children: [
2582
+ return /* @__PURE__ */ jsxs("div", { className: cn("relative flex-1 overflow-y-hidden", className), children: [
2581
2583
  /* @__PURE__ */ jsxs(
2582
2584
  "div",
2583
2585
  {
2584
- className: cn(theme.messages.content, "h-full"),
2586
+ className: cn(theme.messages.content, className, "h-full"),
2585
2587
  ref: contentRef,
2586
- id: activeSession == null ? void 0 : activeSession.id,
2588
+ id: activeSession?.id,
2589
+ onScrollCapture: onScroll,
2587
2590
  children: [
2588
- hasMore && /* @__PURE__ */ jsx(
2591
+ (showLoadMoreButton || hasMore) && /* @__PURE__ */ jsx(
2589
2592
  Button,
2590
2593
  {
2594
+ disabled: loadMoreButtonDisabled,
2591
2595
  variant: "outline",
2592
2596
  className: cn(theme.messages.showMore),
2593
2597
  fullWidth: true,
2594
- onClick: handleShowMore,
2598
+ onClick: onLoadMore ?? handleShowMore,
2595
2599
  children: showMoreText
2596
2600
  }
2597
2601
  ),
@@ -2604,7 +2608,7 @@ const SessionMessages = ({
2604
2608
  animate: "visible",
2605
2609
  onAnimationComplete: () => requestAnimationFrame(() => {
2606
2610
  setIsAnimating(false);
2607
- if (contentRef.current) {
2611
+ if (contentRef.current && autoScroll) {
2608
2612
  contentRef.current.scrollTop = contentRef.current.scrollHeight;
2609
2613
  }
2610
2614
  }),
@@ -2617,7 +2621,7 @@ const SessionMessages = ({
2617
2621
  conversation.id
2618
2622
  ))
2619
2623
  },
2620
- activeSession == null ? void 0 : activeSession.id
2624
+ activeSession?.id
2621
2625
  ) })
2622
2626
  ]
2623
2627
  }
@@ -2629,13 +2633,13 @@ const SessionMessages = ({
2629
2633
  animate: { y: 0, opacity: 1 },
2630
2634
  exit: { y: 100, opacity: 0 },
2631
2635
  transition: { duration: 0.3, ease: "easeOut" },
2632
- className: (_c = (_b = (_a = theme.messages) == null ? void 0 : _a.message) == null ? void 0 : _b.scrollToBottom) == null ? void 0 : _c.container,
2636
+ className: theme.messages?.message?.scrollToBottom?.container,
2633
2637
  children: /* @__PURE__ */ jsx(
2634
2638
  IconButton,
2635
2639
  {
2636
2640
  onClick: handleScrollToBottom,
2637
- className: (_f = (_e = (_d = theme.messages) == null ? void 0 : _d.message) == null ? void 0 : _e.scrollToBottom) == null ? void 0 : _f.button,
2638
- size: "sm",
2641
+ className: theme.messages?.message?.scrollToBottom?.button,
2642
+ size: "small",
2639
2643
  children: /* @__PURE__ */ jsx(SvgArrowDown, {})
2640
2644
  }
2641
2645
  )
@@ -2705,20 +2709,20 @@ const Chat = ({
2705
2709
  const handleSelectSession = useCallback(
2706
2710
  (sessionId) => {
2707
2711
  setInternalActiveSessionID(sessionId);
2708
- onSelectSession == null ? void 0 : onSelectSession(sessionId);
2712
+ onSelectSession?.(sessionId);
2709
2713
  },
2710
2714
  [onSelectSession]
2711
2715
  );
2712
2716
  const handleDeleteSession = useCallback(
2713
2717
  (sessionId) => {
2714
2718
  setInternalActiveSessionID(void 0);
2715
- onDeleteSession == null ? void 0 : onDeleteSession(sessionId);
2719
+ onDeleteSession?.(sessionId);
2716
2720
  },
2717
2721
  [onDeleteSession]
2718
2722
  );
2719
2723
  const handleCreateNewSession = useCallback(() => {
2720
2724
  setInternalActiveSessionID(void 0);
2721
- onNewSession == null ? void 0 : onNewSession();
2725
+ onNewSession?.();
2722
2726
  }, [onNewSession]);
2723
2727
  useHotkeys([
2724
2728
  {
@@ -2811,7 +2815,7 @@ const SessionListItem = memo(
2811
2815
  const { activeSessionId, selectSession, deleteSession, theme } = useContext(ChatContext);
2812
2816
  const Comp = children ? Slot : ListItem;
2813
2817
  const handleSelect = useCallback(() => {
2814
- selectSession == null ? void 0 : selectSession(session.id);
2818
+ selectSession?.(session.id);
2815
2819
  }, [selectSession, session.id]);
2816
2820
  const handleDelete = useCallback(
2817
2821
  (e) => {
@@ -2873,7 +2877,7 @@ const SessionsList = ({
2873
2877
  }),
2874
2878
  children: [
2875
2879
  /* @__PURE__ */ jsx(List, { children }),
2876
- templates && !activeSessionId && /* @__PURE__ */ jsx("div", { className: "mt-4", children: templates.map((template) => /* @__PURE__ */ jsx("div", { onClick: () => createSession == null ? void 0 : createSession(), children: /* @__PURE__ */ jsx(
2880
+ templates && !activeSessionId && /* @__PURE__ */ jsx("div", { className: "mt-4", children: templates.map((template) => /* @__PURE__ */ jsx("div", { onClick: () => createSession?.(), children: /* @__PURE__ */ jsx(
2877
2881
  SessionListItem,
2878
2882
  {
2879
2883
  session: {
@@ -2902,7 +2906,7 @@ const NewSessionButton = ({
2902
2906
  fullWidth: true,
2903
2907
  disableMargins: true,
2904
2908
  color: "primary",
2905
- startAdornment: /* @__PURE__ */ jsx(SvgPlus, {}),
2909
+ start: /* @__PURE__ */ jsx(SvgPlus, {}),
2906
2910
  className: cn(theme.sessions.create),
2907
2911
  disabled,
2908
2912
  onClick: createSession,
@@ -3038,7 +3042,7 @@ const ChatSuggestion = ({
3038
3042
  const { theme, disabled, isLoading } = useContext(ChatContext);
3039
3043
  const handleClick = () => {
3040
3044
  if (disabled || isLoading) return;
3041
- onClick == null ? void 0 : onClick(content);
3045
+ onClick?.(content);
3042
3046
  };
3043
3047
  return /* @__PURE__ */ jsx(
3044
3048
  Button,
@@ -3291,8 +3295,7 @@ function parseSSELine(line) {
3291
3295
  return null;
3292
3296
  }
3293
3297
  async function* parseSSE(response, signal) {
3294
- var _a;
3295
- const reader = (_a = response.body) == null ? void 0 : _a.getReader();
3298
+ const reader = response.body?.getReader();
3296
3299
  if (!reader) {
3297
3300
  throw new Error("Response body is not readable");
3298
3301
  }
@@ -3344,8 +3347,7 @@ function useAgUi({
3344
3347
  onEventRef.current = onEvent;
3345
3348
  useEffect(() => {
3346
3349
  return () => {
3347
- var _a;
3348
- (_a = abortRef.current) == null ? void 0 : _a.abort();
3350
+ abortRef.current?.abort();
3349
3351
  };
3350
3352
  }, []);
3351
3353
  const selectSession = useCallback((sessionId) => {
@@ -3373,15 +3375,13 @@ function useAgUi({
3373
3375
  setActiveSessionId(id);
3374
3376
  }, []);
3375
3377
  const stopMessage = useCallback(() => {
3376
- var _a;
3377
- (_a = abortRef.current) == null ? void 0 : _a.abort();
3378
+ abortRef.current?.abort();
3378
3379
  abortRef.current = null;
3379
3380
  setIsLoading(false);
3380
3381
  }, []);
3381
3382
  const sendMessage = useCallback(
3382
3383
  async (message) => {
3383
- var _a, _b, _c, _d, _e, _f;
3384
- (_a = abortRef.current) == null ? void 0 : _a.abort();
3384
+ abortRef.current?.abort();
3385
3385
  const abortController = new AbortController();
3386
3386
  abortRef.current = abortController;
3387
3387
  let sessionId = activeSessionId;
@@ -3408,7 +3408,7 @@ function useAgUi({
3408
3408
  );
3409
3409
  setIsLoading(true);
3410
3410
  const currentSession = [
3411
- ...((_b = sessions.find((s) => s.id === sessionId)) == null ? void 0 : _b.conversations) ?? []
3411
+ ...sessions.find((s) => s.id === sessionId)?.conversations ?? []
3412
3412
  ];
3413
3413
  const historyMessages = sessionsToAgUiMessages({
3414
3414
  conversations: currentSession
@@ -3456,11 +3456,11 @@ function useAgUi({
3456
3456
  abortController.signal
3457
3457
  )) {
3458
3458
  if (eventOrError instanceof Error) {
3459
- (_c = onErrorRef.current) == null ? void 0 : _c.call(onErrorRef, eventOrError);
3459
+ onErrorRef.current?.(eventOrError);
3460
3460
  continue;
3461
3461
  }
3462
3462
  const event = eventOrError;
3463
- (_d = onEventRef.current) == null ? void 0 : _d.call(onEventRef, event);
3463
+ onEventRef.current?.(event);
3464
3464
  switch (event.type) {
3465
3465
  case AgUiEventType.TEXT_MESSAGE_CONTENT: {
3466
3466
  responseText += event.delta;
@@ -3505,7 +3505,7 @@ function useAgUi({
3505
3505
  }
3506
3506
  case AgUiEventType.RUN_ERROR: {
3507
3507
  const err = new Error(event.message);
3508
- (_e = onErrorRef.current) == null ? void 0 : _e.call(onErrorRef, err);
3508
+ onErrorRef.current?.(err);
3509
3509
  break;
3510
3510
  }
3511
3511
  case AgUiEventType.RUN_FINISHED: {
@@ -3518,7 +3518,7 @@ function useAgUi({
3518
3518
  return;
3519
3519
  }
3520
3520
  const error = err instanceof Error ? err : new Error(String(err));
3521
- (_f = onErrorRef.current) == null ? void 0 : _f.call(onErrorRef, error);
3521
+ onErrorRef.current?.(error);
3522
3522
  } finally {
3523
3523
  if (abortRef.current === abortController) {
3524
3524
  abortRef.current = null;
@@ -3652,7 +3652,6 @@ const ComponentRenderer = ({
3652
3652
  definitions,
3653
3653
  options
3654
3654
  }) => {
3655
- var _a, _b;
3656
3655
  const { theme, sendMessage } = useContext(ChatContext);
3657
3656
  const result = useMemo(
3658
3657
  () => validateSpec(raw, definitions),
@@ -3660,7 +3659,7 @@ const ComponentRenderer = ({
3660
3659
  );
3661
3660
  if (!result.ok) {
3662
3661
  const error = result.error;
3663
- const custom = (_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(options, error);
3662
+ const custom = options?.onError?.(error);
3664
3663
  if (custom !== void 0) {
3665
3664
  return /* @__PURE__ */ jsx(Fragment, { children: custom });
3666
3665
  }
@@ -3674,7 +3673,7 @@ const ComponentRenderer = ({
3674
3673
  );
3675
3674
  }
3676
3675
  const specs = result.specs;
3677
- return /* @__PURE__ */ jsx("div", { className: (_b = theme.component) == null ? void 0 : _b.base, children: specs.map((spec, index) => /* @__PURE__ */ jsx(
3676
+ return /* @__PURE__ */ jsx("div", { className: theme.component?.base, children: specs.map((spec, index) => /* @__PURE__ */ jsx(
3678
3677
  SpecRenderer,
3679
3678
  {
3680
3679
  spec,
@@ -3691,7 +3690,6 @@ const SpecRenderer = ({
3691
3690
  options,
3692
3691
  sendMessage
3693
3692
  }) => {
3694
- var _a, _b;
3695
3693
  const definition = definitions[spec.type];
3696
3694
  if (!definition) {
3697
3695
  const error = {
@@ -3700,14 +3698,14 @@ const SpecRenderer = ({
3700
3698
  raw: JSON.stringify(spec),
3701
3699
  componentType: spec.type
3702
3700
  };
3703
- const custom = (_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(options, error);
3701
+ const custom = options?.onError?.(error);
3704
3702
  if (custom !== void 0) {
3705
3703
  return /* @__PURE__ */ jsx(Fragment, { children: custom });
3706
3704
  }
3707
3705
  return /* @__PURE__ */ jsx(ComponentError, { title: errorTitle(error.type), message: error.message });
3708
3706
  }
3709
3707
  const RenderedComponent = definition.component;
3710
- const children = (_b = spec.children) == null ? void 0 : _b.map((child, index) => /* @__PURE__ */ jsx(
3708
+ const children = spec.children?.map((child, index) => /* @__PURE__ */ jsx(
3711
3709
  SpecRenderer,
3712
3710
  {
3713
3711
  spec: child,
@@ -3728,7 +3726,6 @@ class SpecErrorBoundary extends Component {
3728
3726
  return { error };
3729
3727
  }
3730
3728
  render() {
3731
- var _a;
3732
3729
  if (this.state.error) {
3733
3730
  const { spec, options } = this.props;
3734
3731
  const catalogError = {
@@ -3737,7 +3734,7 @@ class SpecErrorBoundary extends Component {
3737
3734
  raw: JSON.stringify(spec),
3738
3735
  componentType: spec.type
3739
3736
  };
3740
- const custom = (_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(options, catalogError);
3737
+ const custom = options?.onError?.(catalogError);
3741
3738
  if (custom !== void 0) {
3742
3739
  return /* @__PURE__ */ jsx(Fragment, { children: custom });
3743
3740
  }
@@ -3798,14 +3795,13 @@ function getChildText(children) {
3798
3795
  return "";
3799
3796
  }
3800
3797
  function createComponentPre(definitions, options) {
3801
- const language = (options == null ? void 0 : options.language) ?? "component";
3798
+ const language = options?.language ?? "component";
3802
3799
  const className = `language-${language}`;
3803
3800
  const ComponentPre = ({ children, ...props }) => {
3804
- var _a, _b;
3805
3801
  if (children && typeof children === "object" && "props" in children) {
3806
3802
  const codeElement = children;
3807
- if (((_a = codeElement.props) == null ? void 0 : _a.className) === className) {
3808
- const codeContent = getChildText((_b = codeElement.props) == null ? void 0 : _b.children);
3803
+ if (codeElement.props?.className === className) {
3804
+ const codeContent = getChildText(codeElement.props?.children);
3809
3805
  if (codeContent) {
3810
3806
  return /* @__PURE__ */ jsx(
3811
3807
  ComponentRenderer,
@@ -3917,7 +3913,7 @@ Available components:
3917
3913
  ${componentDocs}`;
3918
3914
  }
3919
3915
  function componentCatalog(definitions, options) {
3920
- const language = (options == null ? void 0 : options.language) ?? "component";
3916
+ const language = options?.language ?? "component";
3921
3917
  const plugin = remarkComponent.bind(void 0, {
3922
3918
  language
3923
3919
  });
@@ -3956,7 +3952,7 @@ function createChartComponentDef() {
3956
3952
  };
3957
3953
  }
3958
3954
  export {
3959
- remarkRedact as $,
3955
+ remarkCve as $,
3960
3956
  AgUiEventType as A,
3961
3957
  SessionMessages as B,
3962
3958
  ChartRenderer as C,
@@ -3981,13 +3977,14 @@ export {
3981
3977
  creditCardMatcher as V,
3982
3978
  dark as W,
3983
3979
  generatePrompt as X,
3984
- light as Y,
3985
- remarkComponent as Z,
3986
- remarkCve as _,
3980
+ groupSessionsByDate as Y,
3981
+ light as Z,
3982
+ remarkComponent as _,
3987
3983
  SvgCopy as a,
3988
- ssnMatcher as a0,
3989
- useAgUi as a1,
3990
- validateSpec as a2,
3984
+ remarkRedact as a0,
3985
+ ssnMatcher as a1,
3986
+ useAgUi as a2,
3987
+ validateSpec as a3,
3991
3988
  AppBar as b,
3992
3989
  Chat as c,
3993
3990
  ChatBubble as d,
@@ -4014,4 +4011,4 @@ export {
4014
4011
  SessionMessage as y,
4015
4012
  SessionMessagePanel as z
4016
4013
  };
4017
- //# sourceMappingURL=index-8tlsyFe-.js.map
4014
+ //# sourceMappingURL=index-iuJAmrEE.js.map