reachat 3.0.0 → 3.1.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.
- package/dist/{CSVFileRenderer-C2tuexJf.js → CSVFileRenderer-C2E4Xnkz.js} +2 -2
- package/dist/{CSVFileRenderer-C2tuexJf.js.map → CSVFileRenderer-C2E4Xnkz.js.map} +1 -1
- package/dist/{DefaultFileRenderer-CJ3jwiQa.js → DefaultFileRenderer-Day12qYs.js} +2 -2
- package/dist/{DefaultFileRenderer-CJ3jwiQa.js.map → DefaultFileRenderer-Day12qYs.js.map} +1 -1
- package/dist/docs.json +16 -16
- package/dist/{index-8tlsyFe-.js → index-CZSBRZbI.js} +70 -99
- package/dist/index-CZSBRZbI.js.map +1 -0
- package/dist/index.css +75 -1077
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +69 -98
- package/dist/index.umd.cjs.map +1 -1
- package/dist/stories/Changelog.mdx +1 -1
- package/dist/stories/Intro.mdx +1 -1
- package/package.json +24 -25
- package/dist/index-8tlsyFe-.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
console.error("vite-plugin-css-injected-by-js", e);
|
|
11
11
|
}
|
|
12
12
|
})();
|
|
13
|
-
import { A, b, C, c, d, e, f, g, h, i, j, k, F, M, l, m, n, o, p, q, r, s, t, u, N, R, v, w, x, y, z, B, D, E, G, H, T, I, J, K, L, O, P, Q, U, V, W, X, Y, Z, _, $, a0, a1, a2 } from "./index-
|
|
13
|
+
import { A, b, C, c, d, e, f, g, h, i, j, k, F, M, l, m, n, o, p, q, r, s, t, u, N, R, v, w, x, y, z, B, D, E, G, H, T, I, J, K, L, O, P, Q, U, V, W, X, Y, Z, _, $, a0, a1, a2 } from "./index-CZSBRZbI.js";
|
|
14
14
|
import "react/jsx-runtime";
|
|
15
15
|
import "react";
|
|
16
16
|
import "reablocks";
|
package/dist/index.umd.cjs
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
})();
|
|
13
13
|
(function(global, factory) {
|
|
14
14
|
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("reablocks"), require("react"), require("motion/react"), require("@tiptap/react"), require("@floating-ui/dom"), require("@tiptap/extension-document"), require("@tiptap/extension-paragraph"), require("@tiptap/extension-text"), require("@tiptap/extension-hard-break"), require("@tiptap/extension-placeholder"), require("@tiptap/extension-mention"), require("@radix-ui/react-slot"), require("react-markdown"), require("react-syntax-highlighter"), require("rehype-katex"), require("rehype-raw"), require("reaviz"), require("mdast-util-find-and-replace"), require("lodash/debounce.js"), require("reakeys"), require("remark-gfm"), require("remark-youtube"), require("remark-math"), require("date-fns"), require("@floating-ui/react"), require("zod")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "reablocks", "react", "motion/react", "@tiptap/react", "@floating-ui/dom", "@tiptap/extension-document", "@tiptap/extension-paragraph", "@tiptap/extension-text", "@tiptap/extension-hard-break", "@tiptap/extension-placeholder", "@tiptap/extension-mention", "@radix-ui/react-slot", "react-markdown", "react-syntax-highlighter", "rehype-katex", "rehype-raw", "reaviz", "mdast-util-find-and-replace", "lodash/debounce.js", "reakeys", "remark-gfm", "remark-youtube", "remark-math", "date-fns", "@floating-ui/react", "zod"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.reachat = {}, global.jsxRuntime, global.reablocks, global.React, global.react$1, global.react, global.dom, global.Document, global.Paragraph, global.Text, global.HardBreak, global.Placeholder, global.Mention, global.reactSlot, global.ReactMarkdown, global.reactSyntaxHighlighter, global.rehypeKatex, global.rehypeRaw, global.reaviz, global.mdastUtilFindAndReplace, global.debounce, global.reakeys, global.remarkGfm, global.remarkYoutube, global.remarkMath, global.dateFns, global.react$2, global.zod));
|
|
15
|
-
})(this, function(exports2, jsxRuntime, reablocks, React, react$1, react, dom, Document, Paragraph, Text, HardBreak, Placeholder, Mention, reactSlot, ReactMarkdown, reactSyntaxHighlighter, rehypeKatex, rehypeRaw, reaviz, mdastUtilFindAndReplace, debounce, reakeys, remarkGfm, remarkYoutube, remarkMath, dateFns, react$2, zod) {
|
|
15
|
+
})(this, (function(exports2, jsxRuntime, reablocks, React, react$1, react, dom, Document, Paragraph, Text, HardBreak, Placeholder, Mention, reactSlot, ReactMarkdown, reactSyntaxHighlighter, rehypeKatex, rehypeRaw, reaviz, mdastUtilFindAndReplace, debounce, reakeys, remarkGfm, remarkYoutube, remarkMath, dateFns, react$2, zod) {
|
|
16
16
|
"use strict";
|
|
17
17
|
function _interopNamespaceDefault(e) {
|
|
18
18
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
@@ -70,10 +70,7 @@
|
|
|
70
70
|
variant: "text",
|
|
71
71
|
disabled: isLoading || disabled,
|
|
72
72
|
className: reablocks.cn(theme.input.upload),
|
|
73
|
-
onClick: () =>
|
|
74
|
-
var _a;
|
|
75
|
-
return (_a = fileInputRef.current) == null ? void 0 : _a.click();
|
|
76
|
-
},
|
|
73
|
+
onClick: () => fileInputRef.current?.click(),
|
|
77
74
|
children: attachIcon
|
|
78
75
|
}
|
|
79
76
|
)
|
|
@@ -328,18 +325,16 @@
|
|
|
328
325
|
const POPUP_STYLE = { zIndex: 9999 };
|
|
329
326
|
const MentionList = React.forwardRef(
|
|
330
327
|
({ items, command, triggerChar, config, query }, ref) => {
|
|
331
|
-
var _a;
|
|
332
328
|
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
|
333
329
|
const itemRefs = React.useRef([]);
|
|
334
330
|
const { theme } = React.useContext(ChatContext);
|
|
335
|
-
const popupTheme =
|
|
331
|
+
const popupTheme = theme?.input?.popup || chatTheme.input.popup;
|
|
336
332
|
React.useEffect(() => {
|
|
337
333
|
setSelectedIndex(0);
|
|
338
334
|
}, [items]);
|
|
339
335
|
React.useEffect(() => {
|
|
340
|
-
var _a2;
|
|
341
336
|
if (itemRefs.current[selectedIndex]) {
|
|
342
|
-
|
|
337
|
+
itemRefs.current[selectedIndex]?.scrollIntoView({
|
|
343
338
|
block: "nearest",
|
|
344
339
|
behavior: "smooth"
|
|
345
340
|
});
|
|
@@ -470,10 +465,7 @@
|
|
|
470
465
|
if (!query) return config.items.slice(0, config.maxResults || 10);
|
|
471
466
|
const lowerQuery = query.toLowerCase();
|
|
472
467
|
return config.items.filter(
|
|
473
|
-
(item) =>
|
|
474
|
-
var _a;
|
|
475
|
-
return item.label.toLowerCase().includes(lowerQuery) || ((_a = item.description) == null ? void 0 : _a.toLowerCase().includes(lowerQuery));
|
|
476
|
-
}
|
|
468
|
+
(item) => item.label.toLowerCase().includes(lowerQuery) || item.description?.toLowerCase().includes(lowerQuery)
|
|
477
469
|
).slice(0, config.maxResults || 10);
|
|
478
470
|
},
|
|
479
471
|
// Render callbacks for managing the popup lifecycle
|
|
@@ -500,7 +492,7 @@
|
|
|
500
492
|
},
|
|
501
493
|
// Called when query or items change
|
|
502
494
|
onUpdate: (props) => {
|
|
503
|
-
component
|
|
495
|
+
component?.updateProps({
|
|
504
496
|
...props,
|
|
505
497
|
triggerChar,
|
|
506
498
|
config
|
|
@@ -508,25 +500,23 @@
|
|
|
508
500
|
if (!props.clientRect) {
|
|
509
501
|
return;
|
|
510
502
|
}
|
|
511
|
-
if (component
|
|
503
|
+
if (component?.element) {
|
|
512
504
|
updatePopupPosition(props.editor, component.element);
|
|
513
505
|
}
|
|
514
506
|
},
|
|
515
507
|
// Handle keyboard navigation (Escape closes popup)
|
|
516
508
|
onKeyDown: (props) => {
|
|
517
|
-
var _a;
|
|
518
509
|
if (props.event.key === "Escape") {
|
|
519
|
-
component
|
|
510
|
+
component?.destroy();
|
|
520
511
|
return true;
|
|
521
512
|
}
|
|
522
|
-
return
|
|
513
|
+
return component?.ref?.onKeyDown(props) ?? false;
|
|
523
514
|
},
|
|
524
515
|
// Cleanup when suggestion is dismissed
|
|
525
516
|
onExit: () => {
|
|
526
|
-
var _a;
|
|
527
517
|
suggestionActiveRef.current = false;
|
|
528
|
-
|
|
529
|
-
component
|
|
518
|
+
component?.element?.remove();
|
|
519
|
+
component?.destroy();
|
|
530
520
|
}
|
|
531
521
|
};
|
|
532
522
|
}
|
|
@@ -546,12 +536,10 @@
|
|
|
546
536
|
onSubmit,
|
|
547
537
|
onChange
|
|
548
538
|
}, ref) => {
|
|
549
|
-
var _a, _b, _c, _d;
|
|
550
539
|
const { theme } = React.useContext(ChatContext);
|
|
551
540
|
const containerRef = React.useRef(null);
|
|
552
541
|
const suggestionActiveRef = React.useRef(false);
|
|
553
542
|
const extensions = React.useMemo(() => {
|
|
554
|
-
var _a2, _b2, _c2, _d2, _e, _f, _g, _h;
|
|
555
543
|
const exts = [
|
|
556
544
|
Document,
|
|
557
545
|
Paragraph.configure({
|
|
@@ -570,7 +558,7 @@
|
|
|
570
558
|
exts.push(
|
|
571
559
|
Mention.configure({
|
|
572
560
|
HTMLAttributes: {
|
|
573
|
-
class: reablocks.cn(
|
|
561
|
+
class: reablocks.cn(theme?.input?.tag?.base, theme?.input?.tag?.mention)
|
|
574
562
|
},
|
|
575
563
|
suggestion: createSuggestionConfig(
|
|
576
564
|
mentions,
|
|
@@ -586,7 +574,7 @@
|
|
|
586
574
|
exts.push(
|
|
587
575
|
Mention.configure({
|
|
588
576
|
HTMLAttributes: {
|
|
589
|
-
class: reablocks.cn(
|
|
577
|
+
class: reablocks.cn(theme?.input?.tag?.base, theme?.input?.tag?.command)
|
|
590
578
|
},
|
|
591
579
|
suggestion: createSuggestionConfig(
|
|
592
580
|
commands,
|
|
@@ -607,13 +595,13 @@
|
|
|
607
595
|
immediatelyRender: false,
|
|
608
596
|
onUpdate: ({ editor: editor2 }) => {
|
|
609
597
|
const text = editor2.getText();
|
|
610
|
-
onChange
|
|
598
|
+
onChange?.(text);
|
|
611
599
|
},
|
|
612
600
|
editorProps: {
|
|
613
601
|
attributes: {
|
|
614
602
|
class: reablocks.cn(
|
|
615
|
-
|
|
616
|
-
|
|
603
|
+
theme?.input?.editor?.base,
|
|
604
|
+
theme?.input?.editor?.placeholder
|
|
617
605
|
),
|
|
618
606
|
style: `min-height: ${minHeight}px; max-height: ${maxHeight}px;`,
|
|
619
607
|
role: "textbox",
|
|
@@ -631,7 +619,7 @@
|
|
|
631
619
|
if (text.trim() && onSubmit) {
|
|
632
620
|
event.preventDefault();
|
|
633
621
|
onSubmit(text);
|
|
634
|
-
editor
|
|
622
|
+
editor?.commands.clearContent();
|
|
635
623
|
return true;
|
|
636
624
|
}
|
|
637
625
|
}
|
|
@@ -648,16 +636,16 @@
|
|
|
648
636
|
}, [editor, autoFocus]);
|
|
649
637
|
React.useImperativeHandle(ref, () => ({
|
|
650
638
|
focus: () => {
|
|
651
|
-
editor
|
|
639
|
+
editor?.commands.focus();
|
|
652
640
|
},
|
|
653
641
|
getValue: () => {
|
|
654
|
-
return
|
|
642
|
+
return editor?.getText() || "";
|
|
655
643
|
},
|
|
656
644
|
setValue: (newValue) => {
|
|
657
|
-
editor
|
|
645
|
+
editor?.commands.setContent(newValue ? `<p>${newValue}</p>` : "");
|
|
658
646
|
},
|
|
659
647
|
insertText: (text) => {
|
|
660
|
-
editor
|
|
648
|
+
editor?.commands.insertContent(text);
|
|
661
649
|
}
|
|
662
650
|
}));
|
|
663
651
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: reablocks.cn("relative w-full", className), children: /* @__PURE__ */ jsxRuntime.jsx(react.EditorContent, { editor }) });
|
|
@@ -691,43 +679,37 @@
|
|
|
691
679
|
const inputRef = React.useRef(null);
|
|
692
680
|
const containerRef = React.useRef(null);
|
|
693
681
|
React.useEffect(() => {
|
|
694
|
-
var _a;
|
|
695
682
|
if (autoFocus) {
|
|
696
|
-
|
|
683
|
+
inputRef.current?.focus();
|
|
697
684
|
}
|
|
698
685
|
}, [activeSessionId, autoFocus]);
|
|
699
686
|
React.useImperativeHandle(ref, () => ({
|
|
700
687
|
focus: () => {
|
|
701
|
-
|
|
702
|
-
(_a = inputRef.current) == null ? void 0 : _a.focus();
|
|
688
|
+
inputRef.current?.focus();
|
|
703
689
|
},
|
|
704
690
|
getValue: () => {
|
|
705
|
-
|
|
706
|
-
return ((_a = inputRef.current) == null ? void 0 : _a.getValue()) || "";
|
|
691
|
+
return inputRef.current?.getValue() || "";
|
|
707
692
|
},
|
|
708
693
|
setValue: (value) => {
|
|
709
|
-
var _a;
|
|
710
694
|
setMessage(value);
|
|
711
|
-
|
|
695
|
+
inputRef.current?.setValue(value);
|
|
712
696
|
},
|
|
713
697
|
insertText: (text) => {
|
|
714
|
-
|
|
715
|
-
(_a = inputRef.current) == null ? void 0 : _a.insertText(text);
|
|
698
|
+
inputRef.current?.insertText(text);
|
|
716
699
|
}
|
|
717
700
|
}));
|
|
718
701
|
const handleSendMessage = React.useCallback(() => {
|
|
719
|
-
|
|
720
|
-
const currentMessage = (_a = inputRef.current) == null ? void 0 : _a.getValue();
|
|
702
|
+
const currentMessage = inputRef.current?.getValue();
|
|
721
703
|
if (currentMessage.trim()) {
|
|
722
|
-
sendMessage
|
|
704
|
+
sendMessage?.(currentMessage);
|
|
723
705
|
setMessage("");
|
|
724
|
-
|
|
706
|
+
inputRef.current?.setValue("");
|
|
725
707
|
}
|
|
726
708
|
}, [sendMessage]);
|
|
727
709
|
const handleSubmit = React.useCallback(
|
|
728
710
|
(value) => {
|
|
729
711
|
if (value.trim()) {
|
|
730
|
-
sendMessage
|
|
712
|
+
sendMessage?.(value);
|
|
731
713
|
setMessage("");
|
|
732
714
|
}
|
|
733
715
|
},
|
|
@@ -738,8 +720,7 @@
|
|
|
738
720
|
}, []);
|
|
739
721
|
const handleFileUpload = React.useCallback(
|
|
740
722
|
(event) => {
|
|
741
|
-
|
|
742
|
-
const file = (_a = event.target.files) == null ? void 0 : _a[0];
|
|
723
|
+
const file = event.target.files?.[0];
|
|
743
724
|
if (file && fileUpload) {
|
|
744
725
|
fileUpload(file);
|
|
745
726
|
}
|
|
@@ -773,7 +754,7 @@
|
|
|
773
754
|
}
|
|
774
755
|
),
|
|
775
756
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: reablocks.cn(theme.input.actions.base), children: [
|
|
776
|
-
|
|
757
|
+
allowedFiles?.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
777
758
|
FileInput,
|
|
778
759
|
{
|
|
779
760
|
allowedFiles,
|
|
@@ -1883,7 +1864,7 @@
|
|
|
1883
1864
|
toolbarClassName,
|
|
1884
1865
|
theme = dark
|
|
1885
1866
|
}) => {
|
|
1886
|
-
const match = language
|
|
1867
|
+
const match = language?.match(/language-(\w+)/);
|
|
1887
1868
|
const lang = match ? match[1] : "text";
|
|
1888
1869
|
const handleCopy = (text) => {
|
|
1889
1870
|
navigator.clipboard.writeText(text).then(() => {
|
|
@@ -1968,14 +1949,14 @@
|
|
|
1968
1949
|
ol: (props) => /* @__PURE__ */ jsxRuntime.jsx("ol", { ...props, className: reablocks.cn(theme.messages.message.markdown.ol) }),
|
|
1969
1950
|
// 'redact' is a custom element created by remarkRedact, not a standard
|
|
1970
1951
|
// HTML tag, so it falls outside react-markdown's Components type.
|
|
1971
|
-
redact: (props) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1952
|
+
redact: ((props) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1972
1953
|
reablocks.Redact,
|
|
1973
1954
|
{
|
|
1974
1955
|
value: props["data-redact-value"] || props.children,
|
|
1975
1956
|
allowToggle: true,
|
|
1976
1957
|
tooltipText: `${props["data-redact-name"] || "Sensitive"} information - Click to toggle`
|
|
1977
1958
|
}
|
|
1978
|
-
)
|
|
1959
|
+
))
|
|
1979
1960
|
};
|
|
1980
1961
|
return {
|
|
1981
1962
|
...defaultComponents,
|
|
@@ -2202,7 +2183,7 @@
|
|
|
2202
2183
|
}) => {
|
|
2203
2184
|
const { theme } = React.useContext(ChatContext);
|
|
2204
2185
|
const FileRenderer = React.useMemo(() => {
|
|
2205
|
-
const Renderer = Object.keys(FILE_TYPE_RENDERER_MAP).find((key) => type
|
|
2186
|
+
const Renderer = Object.keys(FILE_TYPE_RENDERER_MAP).find((key) => type?.startsWith(key)) ?? "default";
|
|
2206
2187
|
return FILE_TYPE_RENDERER_MAP[Renderer] || DefaultFileRenderer$2;
|
|
2207
2188
|
}, [type]);
|
|
2208
2189
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -2386,8 +2367,7 @@
|
|
|
2386
2367
|
}
|
|
2387
2368
|
return files.reduce(
|
|
2388
2369
|
(acc, file) => {
|
|
2389
|
-
|
|
2390
|
-
if ((_a = file.type) == null ? void 0 : _a.startsWith("image/")) {
|
|
2370
|
+
if (file.type?.startsWith("image/")) {
|
|
2391
2371
|
acc.imageFiles.push(file);
|
|
2392
2372
|
} else {
|
|
2393
2373
|
acc.otherFiles.push(file);
|
|
@@ -2689,7 +2669,6 @@ ${response}` : ""}`);
|
|
|
2689
2669
|
showMoreText = "Show more",
|
|
2690
2670
|
showScrollBottomButton = false
|
|
2691
2671
|
}) => {
|
|
2692
|
-
var _a, _b, _c, _d, _e, _f;
|
|
2693
2672
|
const { activeSession, theme } = React.useContext(ChatContext);
|
|
2694
2673
|
const contentRef = React.useRef(null);
|
|
2695
2674
|
const messagesRef = React.useRef(null);
|
|
@@ -2730,7 +2709,7 @@ ${response}` : ""}`);
|
|
|
2730
2709
|
}
|
|
2731
2710
|
};
|
|
2732
2711
|
const reversedConvos = React.useMemo(
|
|
2733
|
-
() => [...
|
|
2712
|
+
() => [...activeSession?.conversations ?? []].reverse(),
|
|
2734
2713
|
[activeSession]
|
|
2735
2714
|
);
|
|
2736
2715
|
const { data, hasMore, showNext } = reablocks.useInfinityList({
|
|
@@ -2738,7 +2717,7 @@ ${response}` : ""}`);
|
|
|
2738
2717
|
size: limit
|
|
2739
2718
|
});
|
|
2740
2719
|
const reReversedConvo = React.useMemo(() => [...data].reverse(), [data]);
|
|
2741
|
-
const convosToRender = limit ? reReversedConvo : activeSession
|
|
2720
|
+
const convosToRender = limit ? reReversedConvo : activeSession?.conversations;
|
|
2742
2721
|
if (!activeSession) {
|
|
2743
2722
|
return /* @__PURE__ */ jsxRuntime.jsx(SessionEmpty, { children: newSessionContent });
|
|
2744
2723
|
}
|
|
@@ -2748,7 +2727,7 @@ ${response}` : ""}`);
|
|
|
2748
2727
|
{
|
|
2749
2728
|
className: reablocks.cn(theme.messages.content, "h-full"),
|
|
2750
2729
|
ref: contentRef,
|
|
2751
|
-
id: activeSession
|
|
2730
|
+
id: activeSession?.id,
|
|
2752
2731
|
children: [
|
|
2753
2732
|
hasMore && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2754
2733
|
reablocks.Button,
|
|
@@ -2782,7 +2761,7 @@ ${response}` : ""}`);
|
|
|
2782
2761
|
conversation.id
|
|
2783
2762
|
))
|
|
2784
2763
|
},
|
|
2785
|
-
activeSession
|
|
2764
|
+
activeSession?.id
|
|
2786
2765
|
) })
|
|
2787
2766
|
]
|
|
2788
2767
|
}
|
|
@@ -2794,12 +2773,12 @@ ${response}` : ""}`);
|
|
|
2794
2773
|
animate: { y: 0, opacity: 1 },
|
|
2795
2774
|
exit: { y: 100, opacity: 0 },
|
|
2796
2775
|
transition: { duration: 0.3, ease: "easeOut" },
|
|
2797
|
-
className:
|
|
2776
|
+
className: theme.messages?.message?.scrollToBottom?.container,
|
|
2798
2777
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2799
2778
|
reablocks.IconButton,
|
|
2800
2779
|
{
|
|
2801
2780
|
onClick: handleScrollToBottom,
|
|
2802
|
-
className:
|
|
2781
|
+
className: theme.messages?.message?.scrollToBottom?.button,
|
|
2803
2782
|
size: "sm",
|
|
2804
2783
|
children: /* @__PURE__ */ jsxRuntime.jsx(SvgArrowDown, {})
|
|
2805
2784
|
}
|
|
@@ -2870,20 +2849,20 @@ ${response}` : ""}`);
|
|
|
2870
2849
|
const handleSelectSession = React.useCallback(
|
|
2871
2850
|
(sessionId) => {
|
|
2872
2851
|
setInternalActiveSessionID(sessionId);
|
|
2873
|
-
onSelectSession
|
|
2852
|
+
onSelectSession?.(sessionId);
|
|
2874
2853
|
},
|
|
2875
2854
|
[onSelectSession]
|
|
2876
2855
|
);
|
|
2877
2856
|
const handleDeleteSession = React.useCallback(
|
|
2878
2857
|
(sessionId) => {
|
|
2879
2858
|
setInternalActiveSessionID(void 0);
|
|
2880
|
-
onDeleteSession
|
|
2859
|
+
onDeleteSession?.(sessionId);
|
|
2881
2860
|
},
|
|
2882
2861
|
[onDeleteSession]
|
|
2883
2862
|
);
|
|
2884
2863
|
const handleCreateNewSession = React.useCallback(() => {
|
|
2885
2864
|
setInternalActiveSessionID(void 0);
|
|
2886
|
-
onNewSession
|
|
2865
|
+
onNewSession?.();
|
|
2887
2866
|
}, [onNewSession]);
|
|
2888
2867
|
reakeys.useHotkeys([
|
|
2889
2868
|
{
|
|
@@ -2976,7 +2955,7 @@ ${response}` : ""}`);
|
|
|
2976
2955
|
const { activeSessionId, selectSession, deleteSession, theme } = React.useContext(ChatContext);
|
|
2977
2956
|
const Comp = children ? reactSlot.Slot : reablocks.ListItem;
|
|
2978
2957
|
const handleSelect = React.useCallback(() => {
|
|
2979
|
-
selectSession
|
|
2958
|
+
selectSession?.(session.id);
|
|
2980
2959
|
}, [selectSession, session.id]);
|
|
2981
2960
|
const handleDelete = React.useCallback(
|
|
2982
2961
|
(e) => {
|
|
@@ -3038,7 +3017,7 @@ ${response}` : ""}`);
|
|
|
3038
3017
|
}),
|
|
3039
3018
|
children: [
|
|
3040
3019
|
/* @__PURE__ */ jsxRuntime.jsx(reablocks.List, { children }),
|
|
3041
|
-
templates && !activeSessionId && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4", children: templates.map((template) => /* @__PURE__ */ jsxRuntime.jsx("div", { onClick: () => createSession
|
|
3020
|
+
templates && !activeSessionId && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4", children: templates.map((template) => /* @__PURE__ */ jsxRuntime.jsx("div", { onClick: () => createSession?.(), children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3042
3021
|
SessionListItem,
|
|
3043
3022
|
{
|
|
3044
3023
|
session: {
|
|
@@ -3067,7 +3046,7 @@ ${response}` : ""}`);
|
|
|
3067
3046
|
fullWidth: true,
|
|
3068
3047
|
disableMargins: true,
|
|
3069
3048
|
color: "primary",
|
|
3070
|
-
|
|
3049
|
+
start: /* @__PURE__ */ jsxRuntime.jsx(SvgPlus, {}),
|
|
3071
3050
|
className: reablocks.cn(theme.sessions.create),
|
|
3072
3051
|
disabled,
|
|
3073
3052
|
onClick: createSession,
|
|
@@ -3203,7 +3182,7 @@ ${response}` : ""}`);
|
|
|
3203
3182
|
const { theme, disabled, isLoading } = React.useContext(ChatContext);
|
|
3204
3183
|
const handleClick = () => {
|
|
3205
3184
|
if (disabled || isLoading) return;
|
|
3206
|
-
onClick
|
|
3185
|
+
onClick?.(content);
|
|
3207
3186
|
};
|
|
3208
3187
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3209
3188
|
reablocks.Button,
|
|
@@ -3456,8 +3435,7 @@ ${response}` : ""}`);
|
|
|
3456
3435
|
return null;
|
|
3457
3436
|
}
|
|
3458
3437
|
async function* parseSSE(response, signal) {
|
|
3459
|
-
|
|
3460
|
-
const reader = (_a = response.body) == null ? void 0 : _a.getReader();
|
|
3438
|
+
const reader = response.body?.getReader();
|
|
3461
3439
|
if (!reader) {
|
|
3462
3440
|
throw new Error("Response body is not readable");
|
|
3463
3441
|
}
|
|
@@ -3509,8 +3487,7 @@ ${response}` : ""}`);
|
|
|
3509
3487
|
onEventRef.current = onEvent;
|
|
3510
3488
|
React.useEffect(() => {
|
|
3511
3489
|
return () => {
|
|
3512
|
-
|
|
3513
|
-
(_a = abortRef.current) == null ? void 0 : _a.abort();
|
|
3490
|
+
abortRef.current?.abort();
|
|
3514
3491
|
};
|
|
3515
3492
|
}, []);
|
|
3516
3493
|
const selectSession = React.useCallback((sessionId) => {
|
|
@@ -3538,15 +3515,13 @@ ${response}` : ""}`);
|
|
|
3538
3515
|
setActiveSessionId(id);
|
|
3539
3516
|
}, []);
|
|
3540
3517
|
const stopMessage = React.useCallback(() => {
|
|
3541
|
-
|
|
3542
|
-
(_a = abortRef.current) == null ? void 0 : _a.abort();
|
|
3518
|
+
abortRef.current?.abort();
|
|
3543
3519
|
abortRef.current = null;
|
|
3544
3520
|
setIsLoading(false);
|
|
3545
3521
|
}, []);
|
|
3546
3522
|
const sendMessage = React.useCallback(
|
|
3547
3523
|
async (message) => {
|
|
3548
|
-
|
|
3549
|
-
(_a = abortRef.current) == null ? void 0 : _a.abort();
|
|
3524
|
+
abortRef.current?.abort();
|
|
3550
3525
|
const abortController = new AbortController();
|
|
3551
3526
|
abortRef.current = abortController;
|
|
3552
3527
|
let sessionId = activeSessionId;
|
|
@@ -3573,7 +3548,7 @@ ${response}` : ""}`);
|
|
|
3573
3548
|
);
|
|
3574
3549
|
setIsLoading(true);
|
|
3575
3550
|
const currentSession = [
|
|
3576
|
-
...
|
|
3551
|
+
...sessions.find((s) => s.id === sessionId)?.conversations ?? []
|
|
3577
3552
|
];
|
|
3578
3553
|
const historyMessages = sessionsToAgUiMessages({
|
|
3579
3554
|
conversations: currentSession
|
|
@@ -3621,11 +3596,11 @@ ${response}` : ""}`);
|
|
|
3621
3596
|
abortController.signal
|
|
3622
3597
|
)) {
|
|
3623
3598
|
if (eventOrError instanceof Error) {
|
|
3624
|
-
|
|
3599
|
+
onErrorRef.current?.(eventOrError);
|
|
3625
3600
|
continue;
|
|
3626
3601
|
}
|
|
3627
3602
|
const event = eventOrError;
|
|
3628
|
-
|
|
3603
|
+
onEventRef.current?.(event);
|
|
3629
3604
|
switch (event.type) {
|
|
3630
3605
|
case AgUiEventType.TEXT_MESSAGE_CONTENT: {
|
|
3631
3606
|
responseText += event.delta;
|
|
@@ -3670,7 +3645,7 @@ ${response}` : ""}`);
|
|
|
3670
3645
|
}
|
|
3671
3646
|
case AgUiEventType.RUN_ERROR: {
|
|
3672
3647
|
const err = new Error(event.message);
|
|
3673
|
-
|
|
3648
|
+
onErrorRef.current?.(err);
|
|
3674
3649
|
break;
|
|
3675
3650
|
}
|
|
3676
3651
|
case AgUiEventType.RUN_FINISHED: {
|
|
@@ -3683,7 +3658,7 @@ ${response}` : ""}`);
|
|
|
3683
3658
|
return;
|
|
3684
3659
|
}
|
|
3685
3660
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
3686
|
-
|
|
3661
|
+
onErrorRef.current?.(error);
|
|
3687
3662
|
} finally {
|
|
3688
3663
|
if (abortRef.current === abortController) {
|
|
3689
3664
|
abortRef.current = null;
|
|
@@ -3817,7 +3792,6 @@ ${response}` : ""}`);
|
|
|
3817
3792
|
definitions,
|
|
3818
3793
|
options
|
|
3819
3794
|
}) => {
|
|
3820
|
-
var _a, _b;
|
|
3821
3795
|
const { theme, sendMessage } = React.useContext(ChatContext);
|
|
3822
3796
|
const result = React.useMemo(
|
|
3823
3797
|
() => validateSpec(raw, definitions),
|
|
@@ -3825,7 +3799,7 @@ ${response}` : ""}`);
|
|
|
3825
3799
|
);
|
|
3826
3800
|
if (!result.ok) {
|
|
3827
3801
|
const error = result.error;
|
|
3828
|
-
const custom =
|
|
3802
|
+
const custom = options?.onError?.(error);
|
|
3829
3803
|
if (custom !== void 0) {
|
|
3830
3804
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: custom });
|
|
3831
3805
|
}
|
|
@@ -3839,7 +3813,7 @@ ${response}` : ""}`);
|
|
|
3839
3813
|
);
|
|
3840
3814
|
}
|
|
3841
3815
|
const specs = result.specs;
|
|
3842
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", { className:
|
|
3816
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: theme.component?.base, children: specs.map((spec, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
3843
3817
|
SpecRenderer,
|
|
3844
3818
|
{
|
|
3845
3819
|
spec,
|
|
@@ -3856,7 +3830,6 @@ ${response}` : ""}`);
|
|
|
3856
3830
|
options,
|
|
3857
3831
|
sendMessage
|
|
3858
3832
|
}) => {
|
|
3859
|
-
var _a, _b;
|
|
3860
3833
|
const definition = definitions[spec.type];
|
|
3861
3834
|
if (!definition) {
|
|
3862
3835
|
const error = {
|
|
@@ -3865,14 +3838,14 @@ ${response}` : ""}`);
|
|
|
3865
3838
|
raw: JSON.stringify(spec),
|
|
3866
3839
|
componentType: spec.type
|
|
3867
3840
|
};
|
|
3868
|
-
const custom =
|
|
3841
|
+
const custom = options?.onError?.(error);
|
|
3869
3842
|
if (custom !== void 0) {
|
|
3870
3843
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: custom });
|
|
3871
3844
|
}
|
|
3872
3845
|
return /* @__PURE__ */ jsxRuntime.jsx(ComponentError, { title: errorTitle(error.type), message: error.message });
|
|
3873
3846
|
}
|
|
3874
3847
|
const RenderedComponent = definition.component;
|
|
3875
|
-
const children =
|
|
3848
|
+
const children = spec.children?.map((child, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
3876
3849
|
SpecRenderer,
|
|
3877
3850
|
{
|
|
3878
3851
|
spec: child,
|
|
@@ -3893,7 +3866,6 @@ ${response}` : ""}`);
|
|
|
3893
3866
|
return { error };
|
|
3894
3867
|
}
|
|
3895
3868
|
render() {
|
|
3896
|
-
var _a;
|
|
3897
3869
|
if (this.state.error) {
|
|
3898
3870
|
const { spec, options } = this.props;
|
|
3899
3871
|
const catalogError = {
|
|
@@ -3902,7 +3874,7 @@ ${response}` : ""}`);
|
|
|
3902
3874
|
raw: JSON.stringify(spec),
|
|
3903
3875
|
componentType: spec.type
|
|
3904
3876
|
};
|
|
3905
|
-
const custom =
|
|
3877
|
+
const custom = options?.onError?.(catalogError);
|
|
3906
3878
|
if (custom !== void 0) {
|
|
3907
3879
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: custom });
|
|
3908
3880
|
}
|
|
@@ -3963,14 +3935,13 @@ ${response}` : ""}`);
|
|
|
3963
3935
|
return "";
|
|
3964
3936
|
}
|
|
3965
3937
|
function createComponentPre(definitions, options) {
|
|
3966
|
-
const language =
|
|
3938
|
+
const language = options?.language ?? "component";
|
|
3967
3939
|
const className = `language-${language}`;
|
|
3968
3940
|
const ComponentPre = ({ children, ...props }) => {
|
|
3969
|
-
var _a, _b;
|
|
3970
3941
|
if (children && typeof children === "object" && "props" in children) {
|
|
3971
3942
|
const codeElement = children;
|
|
3972
|
-
if (
|
|
3973
|
-
const codeContent = getChildText(
|
|
3943
|
+
if (codeElement.props?.className === className) {
|
|
3944
|
+
const codeContent = getChildText(codeElement.props?.children);
|
|
3974
3945
|
if (codeContent) {
|
|
3975
3946
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3976
3947
|
ComponentRenderer,
|
|
@@ -4082,7 +4053,7 @@ Available components:
|
|
|
4082
4053
|
${componentDocs}`;
|
|
4083
4054
|
}
|
|
4084
4055
|
function componentCatalog(definitions, options) {
|
|
4085
|
-
const language =
|
|
4056
|
+
const language = options?.language ?? "component";
|
|
4086
4057
|
const plugin = remarkComponent.bind(void 0, {
|
|
4087
4058
|
language
|
|
4088
4059
|
});
|
|
@@ -4176,5 +4147,5 @@ ${componentDocs}`;
|
|
|
4176
4147
|
exports2.useAgUi = useAgUi;
|
|
4177
4148
|
exports2.validateSpec = validateSpec;
|
|
4178
4149
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
4179
|
-
});
|
|
4150
|
+
}));
|
|
4180
4151
|
//# sourceMappingURL=index.umd.cjs.map
|