@mordn/chat-widget 0.5.1 → 0.6.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/index.d.mts +63 -1
- package/dist/index.d.ts +63 -1
- package/dist/index.js +480 -272
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +464 -256
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -51,7 +51,7 @@ __export(src_exports, {
|
|
|
51
51
|
module.exports = __toCommonJS(src_exports);
|
|
52
52
|
|
|
53
53
|
// src/ChatWidget.tsx
|
|
54
|
-
var
|
|
54
|
+
var import_react13 = require("react");
|
|
55
55
|
|
|
56
56
|
// src/ui/button.tsx
|
|
57
57
|
var import_react_slot = require("@radix-ui/react-slot");
|
|
@@ -238,7 +238,7 @@ function Textarea({ className, ...props }) {
|
|
|
238
238
|
// src/components/prompt-input.tsx
|
|
239
239
|
var import_lucide_react4 = require("lucide-react");
|
|
240
240
|
var import_nanoid = require("nanoid");
|
|
241
|
-
var import_react2 = require("react");
|
|
241
|
+
var import_react2 = __toESM(require("react"));
|
|
242
242
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
243
243
|
var AttachmentsContext = (0, import_react2.createContext)(null);
|
|
244
244
|
var usePromptInputAttachments = () => {
|
|
@@ -539,14 +539,17 @@ var PromptInputBody = ({
|
|
|
539
539
|
className,
|
|
540
540
|
...props
|
|
541
541
|
}) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: cn(className, "flex flex-col"), ...props });
|
|
542
|
-
var PromptInputTextarea = ({
|
|
542
|
+
var PromptInputTextarea = import_react2.default.forwardRef(({
|
|
543
543
|
onChange,
|
|
544
|
+
onKeyDown: externalOnKeyDown,
|
|
544
545
|
className,
|
|
545
546
|
placeholder = "What would you like to know?",
|
|
546
547
|
...props
|
|
547
|
-
}) => {
|
|
548
|
+
}, ref) => {
|
|
548
549
|
const attachments = usePromptInputAttachments();
|
|
549
550
|
const handleKeyDown = (e) => {
|
|
551
|
+
externalOnKeyDown?.(e);
|
|
552
|
+
if (e.defaultPrevented) return;
|
|
550
553
|
if (e.key === "Enter") {
|
|
551
554
|
if (e.nativeEvent.isComposing) {
|
|
552
555
|
return;
|
|
@@ -583,6 +586,7 @@ var PromptInputTextarea = ({
|
|
|
583
586
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
584
587
|
Textarea,
|
|
585
588
|
{
|
|
589
|
+
ref,
|
|
586
590
|
className: cn(
|
|
587
591
|
"w-full resize-none rounded-none border-none p-3 shadow-none outline-none ring-0",
|
|
588
592
|
"field-sizing-content",
|
|
@@ -600,7 +604,8 @@ var PromptInputTextarea = ({
|
|
|
600
604
|
...props
|
|
601
605
|
}
|
|
602
606
|
);
|
|
603
|
-
};
|
|
607
|
+
});
|
|
608
|
+
PromptInputTextarea.displayName = "PromptInputTextarea";
|
|
604
609
|
var PromptInputToolbar = ({
|
|
605
610
|
className,
|
|
606
611
|
...props
|
|
@@ -731,23 +736,214 @@ function MessageAttachments({ attachments, className }) {
|
|
|
731
736
|
)) });
|
|
732
737
|
}
|
|
733
738
|
|
|
739
|
+
// src/components/input-plugin-popover.tsx
|
|
740
|
+
var import_react3 = require("react");
|
|
741
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
742
|
+
var FETCH_DEBOUNCE_MS = 120;
|
|
743
|
+
function useInputPlugins({ textareaRef, value, setValue, plugins }) {
|
|
744
|
+
const [active, setActive] = (0, import_react3.useState)(null);
|
|
745
|
+
const [items, setItems] = (0, import_react3.useState)([]);
|
|
746
|
+
const [highlight, setHighlight] = (0, import_react3.useState)(0);
|
|
747
|
+
const [loading, setLoading] = (0, import_react3.useState)(false);
|
|
748
|
+
const debounceRef = (0, import_react3.useRef)(null);
|
|
749
|
+
const requestIdRef = (0, import_react3.useRef)(0);
|
|
750
|
+
const pluginsByTrigger = (0, import_react3.useMemo)(() => {
|
|
751
|
+
const map = /* @__PURE__ */ new Map();
|
|
752
|
+
for (const p of plugins ?? []) {
|
|
753
|
+
if (p.trigger.length === 1) map.set(p.trigger, p);
|
|
754
|
+
}
|
|
755
|
+
return map;
|
|
756
|
+
}, [plugins]);
|
|
757
|
+
const query = (0, import_react3.useMemo)(() => {
|
|
758
|
+
if (!active) return "";
|
|
759
|
+
const ta = textareaRef.current;
|
|
760
|
+
if (!ta) return "";
|
|
761
|
+
const cursor = ta.selectionEnd ?? value.length;
|
|
762
|
+
if (cursor <= active.triggerIndex) return "";
|
|
763
|
+
return value.slice(active.triggerIndex + 1, cursor);
|
|
764
|
+
}, [active, value, textareaRef]);
|
|
765
|
+
(0, import_react3.useEffect)(() => {
|
|
766
|
+
if (!active) return;
|
|
767
|
+
const ta = textareaRef.current;
|
|
768
|
+
if (!ta) return;
|
|
769
|
+
if (value[active.triggerIndex] !== active.plugin.trigger) {
|
|
770
|
+
setActive(null);
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
if (/\s/.test(query)) {
|
|
774
|
+
setActive(null);
|
|
775
|
+
}
|
|
776
|
+
}, [active, value, query, textareaRef]);
|
|
777
|
+
(0, import_react3.useEffect)(() => {
|
|
778
|
+
if (!active) {
|
|
779
|
+
setItems([]);
|
|
780
|
+
setLoading(false);
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
784
|
+
setLoading(true);
|
|
785
|
+
const reqId = ++requestIdRef.current;
|
|
786
|
+
debounceRef.current = setTimeout(async () => {
|
|
787
|
+
try {
|
|
788
|
+
const result = await active.plugin.fetch(query);
|
|
789
|
+
if (reqId !== requestIdRef.current) return;
|
|
790
|
+
setItems(result);
|
|
791
|
+
setHighlight(0);
|
|
792
|
+
} catch (err) {
|
|
793
|
+
console.error("[input-plugin] fetch failed:", err);
|
|
794
|
+
if (reqId !== requestIdRef.current) return;
|
|
795
|
+
setItems([]);
|
|
796
|
+
} finally {
|
|
797
|
+
if (reqId === requestIdRef.current) setLoading(false);
|
|
798
|
+
}
|
|
799
|
+
}, FETCH_DEBOUNCE_MS);
|
|
800
|
+
return () => {
|
|
801
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
802
|
+
};
|
|
803
|
+
}, [active, query]);
|
|
804
|
+
const close = (0, import_react3.useCallback)(() => {
|
|
805
|
+
setActive(null);
|
|
806
|
+
setItems([]);
|
|
807
|
+
setHighlight(0);
|
|
808
|
+
}, []);
|
|
809
|
+
const selectItem = (0, import_react3.useCallback)(
|
|
810
|
+
(item) => {
|
|
811
|
+
if (!active) return;
|
|
812
|
+
const ta = textareaRef.current;
|
|
813
|
+
const cursor = ta?.selectionEnd ?? value.length;
|
|
814
|
+
const replacement = active.plugin.onSelect(item);
|
|
815
|
+
const before = value.slice(0, active.triggerIndex);
|
|
816
|
+
const after = value.slice(cursor);
|
|
817
|
+
const next = `${before}${replacement}${after}`;
|
|
818
|
+
setValue(next);
|
|
819
|
+
const newCursor = before.length + replacement.length;
|
|
820
|
+
setTimeout(() => {
|
|
821
|
+
const t = textareaRef.current;
|
|
822
|
+
if (!t) return;
|
|
823
|
+
t.focus();
|
|
824
|
+
try {
|
|
825
|
+
t.setSelectionRange(newCursor, newCursor);
|
|
826
|
+
} catch {
|
|
827
|
+
}
|
|
828
|
+
}, 0);
|
|
829
|
+
close();
|
|
830
|
+
},
|
|
831
|
+
[active, value, setValue, close, textareaRef]
|
|
832
|
+
);
|
|
833
|
+
const onKeyDown = (0, import_react3.useCallback)(
|
|
834
|
+
(e) => {
|
|
835
|
+
if (active) {
|
|
836
|
+
if (e.key === "ArrowDown") {
|
|
837
|
+
e.preventDefault();
|
|
838
|
+
setHighlight((h) => items.length === 0 ? 0 : (h + 1) % items.length);
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
if (e.key === "ArrowUp") {
|
|
842
|
+
e.preventDefault();
|
|
843
|
+
setHighlight((h) => items.length === 0 ? 0 : (h - 1 + items.length) % items.length);
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
if (e.key === "Enter") {
|
|
847
|
+
if (items.length > 0) {
|
|
848
|
+
e.preventDefault();
|
|
849
|
+
selectItem(items[highlight]);
|
|
850
|
+
}
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
if (e.key === "Escape") {
|
|
854
|
+
e.preventDefault();
|
|
855
|
+
close();
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
if (e.key.length === 1 && pluginsByTrigger.has(e.key) && !e.metaKey && !e.ctrlKey && !e.altKey) {
|
|
860
|
+
const ta = e.currentTarget;
|
|
861
|
+
const cursor = ta.selectionStart ?? value.length;
|
|
862
|
+
const prevChar = cursor > 0 ? value[cursor - 1] : "";
|
|
863
|
+
if (cursor === 0 || /\s/.test(prevChar)) {
|
|
864
|
+
const plugin = pluginsByTrigger.get(e.key);
|
|
865
|
+
setActive({ plugin, triggerIndex: cursor });
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
},
|
|
869
|
+
[active, items, highlight, selectItem, close, pluginsByTrigger, value]
|
|
870
|
+
);
|
|
871
|
+
(0, import_react3.useEffect)(() => {
|
|
872
|
+
if (!active) return;
|
|
873
|
+
if (value[active.triggerIndex] !== active.plugin.trigger) {
|
|
874
|
+
close();
|
|
875
|
+
}
|
|
876
|
+
}, [value, active, close]);
|
|
877
|
+
const popover = active && (loading || items.length > 0 || active.plugin.emptyText) ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
878
|
+
PluginPopover,
|
|
879
|
+
{
|
|
880
|
+
plugin: active.plugin,
|
|
881
|
+
items,
|
|
882
|
+
loading,
|
|
883
|
+
highlight,
|
|
884
|
+
onHover: setHighlight,
|
|
885
|
+
onSelect: selectItem
|
|
886
|
+
}
|
|
887
|
+
) : null;
|
|
888
|
+
return { onKeyDown, popover, isOpen: !!active };
|
|
889
|
+
}
|
|
890
|
+
function PluginPopover({ plugin, items, loading, highlight, onHover, onSelect }) {
|
|
891
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
892
|
+
"div",
|
|
893
|
+
{
|
|
894
|
+
role: "listbox",
|
|
895
|
+
className: cn(
|
|
896
|
+
"absolute bottom-full left-0 right-0 mb-2 z-30",
|
|
897
|
+
"rounded-md border border-border bg-popover text-popover-foreground shadow-md",
|
|
898
|
+
"max-h-64 overflow-y-auto"
|
|
899
|
+
),
|
|
900
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
901
|
+
children: [
|
|
902
|
+
plugin.heading && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "px-3 py-1.5 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground border-b border-border", children: plugin.heading }),
|
|
903
|
+
loading && items.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "px-3 py-2 text-xs text-muted-foreground", children: "Loading\u2026" }),
|
|
904
|
+
!loading && items.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "px-3 py-2 text-xs text-muted-foreground", children: plugin.emptyText ?? "No results" }),
|
|
905
|
+
items.map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
906
|
+
"button",
|
|
907
|
+
{
|
|
908
|
+
type: "button",
|
|
909
|
+
role: "option",
|
|
910
|
+
"aria-selected": idx === highlight,
|
|
911
|
+
onMouseEnter: () => onHover(idx),
|
|
912
|
+
onClick: () => onSelect(item),
|
|
913
|
+
className: cn(
|
|
914
|
+
"w-full text-left px-3 py-2 text-sm transition-colors",
|
|
915
|
+
"flex flex-col gap-0.5",
|
|
916
|
+
idx === highlight ? "bg-accent text-accent-foreground" : "hover:bg-muted"
|
|
917
|
+
),
|
|
918
|
+
children: [
|
|
919
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "font-medium leading-tight", children: item.label }),
|
|
920
|
+
item.sublabel && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "text-[11px] text-muted-foreground leading-tight", children: item.sublabel })
|
|
921
|
+
]
|
|
922
|
+
},
|
|
923
|
+
item.id
|
|
924
|
+
))
|
|
925
|
+
]
|
|
926
|
+
}
|
|
927
|
+
);
|
|
928
|
+
}
|
|
929
|
+
|
|
734
930
|
// src/components/interface.tsx
|
|
735
|
-
var import_react9 = require("react");
|
|
736
|
-
var import_lucide_react10 = require("lucide-react");
|
|
737
931
|
var import_react10 = require("react");
|
|
738
|
-
var
|
|
932
|
+
var import_lucide_react10 = require("lucide-react");
|
|
933
|
+
var import_react11 = require("react");
|
|
934
|
+
var import_react12 = require("@ai-sdk/react");
|
|
739
935
|
var import_ai = require("ai");
|
|
740
936
|
|
|
741
937
|
// src/components/response.tsx
|
|
742
|
-
var
|
|
938
|
+
var import_react5 = require("react");
|
|
743
939
|
var import_streamdown = require("streamdown");
|
|
744
940
|
|
|
745
941
|
// src/hooks/use-code-scroll.ts
|
|
746
|
-
var
|
|
942
|
+
var import_react4 = require("react");
|
|
747
943
|
function useCodeBlockAutoScroll(isStreaming) {
|
|
748
|
-
const observerRef = (0,
|
|
749
|
-
const containerRef = (0,
|
|
750
|
-
(0,
|
|
944
|
+
const observerRef = (0, import_react4.useRef)(null);
|
|
945
|
+
const containerRef = (0, import_react4.useRef)(null);
|
|
946
|
+
(0, import_react4.useEffect)(() => {
|
|
751
947
|
if (!isStreaming || !containerRef.current) {
|
|
752
948
|
if (observerRef.current) {
|
|
753
949
|
observerRef.current.disconnect();
|
|
@@ -777,11 +973,11 @@ function useCodeBlockAutoScroll(isStreaming) {
|
|
|
777
973
|
}
|
|
778
974
|
|
|
779
975
|
// src/components/response.tsx
|
|
780
|
-
var
|
|
781
|
-
var Response = (0,
|
|
976
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
977
|
+
var Response = (0, import_react5.memo)(
|
|
782
978
|
({ className, isStreaming = false, ...props }) => {
|
|
783
979
|
const containerRef = useCodeBlockAutoScroll(isStreaming);
|
|
784
|
-
return /* @__PURE__ */ (0,
|
|
980
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { ref: containerRef, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
785
981
|
import_streamdown.Streamdown,
|
|
786
982
|
{
|
|
787
983
|
className: cn(
|
|
@@ -798,16 +994,16 @@ Response.displayName = "Response";
|
|
|
798
994
|
|
|
799
995
|
// src/ui/collapsible.tsx
|
|
800
996
|
var CollapsiblePrimitive = __toESM(require("@radix-ui/react-collapsible"));
|
|
801
|
-
var
|
|
997
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
802
998
|
function Collapsible({
|
|
803
999
|
...props
|
|
804
1000
|
}) {
|
|
805
|
-
return /* @__PURE__ */ (0,
|
|
1001
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(CollapsiblePrimitive.Root, { "data-slot": "collapsible", ...props });
|
|
806
1002
|
}
|
|
807
1003
|
function CollapsibleTrigger2({
|
|
808
1004
|
...props
|
|
809
1005
|
}) {
|
|
810
|
-
return /* @__PURE__ */ (0,
|
|
1006
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
811
1007
|
CollapsiblePrimitive.CollapsibleTrigger,
|
|
812
1008
|
{
|
|
813
1009
|
"data-slot": "collapsible-trigger",
|
|
@@ -818,7 +1014,7 @@ function CollapsibleTrigger2({
|
|
|
818
1014
|
function CollapsibleContent2({
|
|
819
1015
|
...props
|
|
820
1016
|
}) {
|
|
821
|
-
return /* @__PURE__ */ (0,
|
|
1017
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
822
1018
|
CollapsiblePrimitive.CollapsibleContent,
|
|
823
1019
|
{
|
|
824
1020
|
"data-slot": "collapsible-content",
|
|
@@ -829,8 +1025,8 @@ function CollapsibleContent2({
|
|
|
829
1025
|
|
|
830
1026
|
// src/components/sources.tsx
|
|
831
1027
|
var import_lucide_react6 = require("lucide-react");
|
|
832
|
-
var
|
|
833
|
-
var Sources = ({ className, ...props }) => /* @__PURE__ */ (0,
|
|
1028
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1029
|
+
var Sources = ({ className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
834
1030
|
Collapsible,
|
|
835
1031
|
{
|
|
836
1032
|
className: cn("not-prose mb-4 text-primary text-xs", className),
|
|
@@ -842,25 +1038,25 @@ var SourcesTrigger = ({
|
|
|
842
1038
|
count,
|
|
843
1039
|
children,
|
|
844
1040
|
...props
|
|
845
|
-
}) => /* @__PURE__ */ (0,
|
|
1041
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
846
1042
|
CollapsibleTrigger2,
|
|
847
1043
|
{
|
|
848
1044
|
className: cn("flex items-center gap-2", className),
|
|
849
1045
|
...props,
|
|
850
|
-
children: children ?? /* @__PURE__ */ (0,
|
|
851
|
-
/* @__PURE__ */ (0,
|
|
1046
|
+
children: children ?? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
1047
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("p", { className: "font-medium", children: [
|
|
852
1048
|
"Used ",
|
|
853
1049
|
count,
|
|
854
1050
|
" sources"
|
|
855
1051
|
] }),
|
|
856
|
-
/* @__PURE__ */ (0,
|
|
1052
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_lucide_react6.ChevronDownIcon, { className: "h-4 w-4" })
|
|
857
1053
|
] })
|
|
858
1054
|
}
|
|
859
1055
|
);
|
|
860
1056
|
var SourcesContent = ({
|
|
861
1057
|
className,
|
|
862
1058
|
...props
|
|
863
|
-
}) => /* @__PURE__ */ (0,
|
|
1059
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
864
1060
|
CollapsibleContent2,
|
|
865
1061
|
{
|
|
866
1062
|
className: cn(
|
|
@@ -871,7 +1067,7 @@ var SourcesContent = ({
|
|
|
871
1067
|
...props
|
|
872
1068
|
}
|
|
873
1069
|
);
|
|
874
|
-
var Source = ({ href, title, children, ...props }) => /* @__PURE__ */ (0,
|
|
1070
|
+
var Source = ({ href, title, children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
875
1071
|
"a",
|
|
876
1072
|
{
|
|
877
1073
|
className: "flex items-center gap-2",
|
|
@@ -879,9 +1075,9 @@ var Source = ({ href, title, children, ...props }) => /* @__PURE__ */ (0, import
|
|
|
879
1075
|
rel: "noreferrer",
|
|
880
1076
|
target: "_blank",
|
|
881
1077
|
...props,
|
|
882
|
-
children: children ?? /* @__PURE__ */ (0,
|
|
883
|
-
/* @__PURE__ */ (0,
|
|
884
|
-
/* @__PURE__ */ (0,
|
|
1078
|
+
children: children ?? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
1079
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_lucide_react6.BookIcon, { className: "h-4 w-4" }),
|
|
1080
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "block font-medium", children: title })
|
|
885
1081
|
] })
|
|
886
1082
|
}
|
|
887
1083
|
);
|
|
@@ -889,11 +1085,11 @@ var Source = ({ href, title, children, ...props }) => /* @__PURE__ */ (0, import
|
|
|
889
1085
|
// src/components/reasoning.tsx
|
|
890
1086
|
var import_react_use_controllable_state = require("@radix-ui/react-use-controllable-state");
|
|
891
1087
|
var import_lucide_react7 = require("lucide-react");
|
|
892
|
-
var
|
|
893
|
-
var
|
|
894
|
-
var ReasoningContext = (0,
|
|
1088
|
+
var import_react6 = require("react");
|
|
1089
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1090
|
+
var ReasoningContext = (0, import_react6.createContext)(null);
|
|
895
1091
|
var useReasoning = () => {
|
|
896
|
-
const context = (0,
|
|
1092
|
+
const context = (0, import_react6.useContext)(ReasoningContext);
|
|
897
1093
|
if (!context) {
|
|
898
1094
|
throw new Error("Reasoning components must be used within Reasoning");
|
|
899
1095
|
}
|
|
@@ -901,7 +1097,7 @@ var useReasoning = () => {
|
|
|
901
1097
|
};
|
|
902
1098
|
var AUTO_CLOSE_DELAY = 1e3;
|
|
903
1099
|
var MS_IN_S = 1e3;
|
|
904
|
-
var Reasoning = (0,
|
|
1100
|
+
var Reasoning = (0, import_react6.memo)(
|
|
905
1101
|
({
|
|
906
1102
|
className,
|
|
907
1103
|
isStreaming = false,
|
|
@@ -921,9 +1117,9 @@ var Reasoning = (0, import_react5.memo)(
|
|
|
921
1117
|
prop: durationProp,
|
|
922
1118
|
defaultProp: void 0
|
|
923
1119
|
});
|
|
924
|
-
const [hasAutoClosed, setHasAutoClosed] = (0,
|
|
925
|
-
const [startTime, setStartTime] = (0,
|
|
926
|
-
(0,
|
|
1120
|
+
const [hasAutoClosed, setHasAutoClosed] = (0, import_react6.useState)(false);
|
|
1121
|
+
const [startTime, setStartTime] = (0, import_react6.useState)(null);
|
|
1122
|
+
(0, import_react6.useEffect)(() => {
|
|
927
1123
|
if (isStreaming) {
|
|
928
1124
|
if (startTime === null) {
|
|
929
1125
|
setStartTime(Date.now());
|
|
@@ -933,7 +1129,7 @@ var Reasoning = (0, import_react5.memo)(
|
|
|
933
1129
|
setStartTime(null);
|
|
934
1130
|
}
|
|
935
1131
|
}, [isStreaming, startTime, setDuration]);
|
|
936
|
-
(0,
|
|
1132
|
+
(0, import_react6.useEffect)(() => {
|
|
937
1133
|
if (defaultOpen && !isStreaming && isOpen && !hasAutoClosed && durationProp !== void 0) {
|
|
938
1134
|
const timer = setTimeout(() => {
|
|
939
1135
|
setIsOpen(false);
|
|
@@ -945,11 +1141,11 @@ var Reasoning = (0, import_react5.memo)(
|
|
|
945
1141
|
const handleOpenChange = (newOpen) => {
|
|
946
1142
|
setIsOpen(newOpen);
|
|
947
1143
|
};
|
|
948
|
-
return /* @__PURE__ */ (0,
|
|
1144
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
949
1145
|
ReasoningContext.Provider,
|
|
950
1146
|
{
|
|
951
1147
|
value: { isStreaming, isOpen, setIsOpen, duration },
|
|
952
|
-
children: /* @__PURE__ */ (0,
|
|
1148
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
953
1149
|
Collapsible,
|
|
954
1150
|
{
|
|
955
1151
|
className: cn("not-prose", className),
|
|
@@ -965,24 +1161,24 @@ var Reasoning = (0, import_react5.memo)(
|
|
|
965
1161
|
);
|
|
966
1162
|
var getThinkingMessage = (isStreaming, duration) => {
|
|
967
1163
|
if (isStreaming) {
|
|
968
|
-
return /* @__PURE__ */ (0,
|
|
1164
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_jsx_runtime14.Fragment, { children: "Thinking..." });
|
|
969
1165
|
}
|
|
970
1166
|
if (duration === void 0) {
|
|
971
|
-
return /* @__PURE__ */ (0,
|
|
1167
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_jsx_runtime14.Fragment, { children: "Thought process" });
|
|
972
1168
|
}
|
|
973
1169
|
if (duration === 0) {
|
|
974
|
-
return /* @__PURE__ */ (0,
|
|
1170
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_jsx_runtime14.Fragment, { children: "Thought process" });
|
|
975
1171
|
}
|
|
976
|
-
return /* @__PURE__ */ (0,
|
|
1172
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
977
1173
|
"Thought for ",
|
|
978
1174
|
duration,
|
|
979
1175
|
" seconds"
|
|
980
1176
|
] });
|
|
981
1177
|
};
|
|
982
|
-
var ReasoningTrigger = (0,
|
|
1178
|
+
var ReasoningTrigger = (0, import_react6.memo)(
|
|
983
1179
|
({ className, children, ...props }) => {
|
|
984
1180
|
const { isStreaming, isOpen, duration } = useReasoning();
|
|
985
|
-
return /* @__PURE__ */ (0,
|
|
1181
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
986
1182
|
CollapsibleTrigger2,
|
|
987
1183
|
{
|
|
988
1184
|
className: cn(
|
|
@@ -990,10 +1186,10 @@ var ReasoningTrigger = (0, import_react5.memo)(
|
|
|
990
1186
|
className
|
|
991
1187
|
),
|
|
992
1188
|
...props,
|
|
993
|
-
children: children ?? /* @__PURE__ */ (0,
|
|
994
|
-
/* @__PURE__ */ (0,
|
|
1189
|
+
children: children ?? /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
1190
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react7.BrainIcon, { className: "size-4 flex-shrink-0" }),
|
|
995
1191
|
getThinkingMessage(isStreaming, duration),
|
|
996
|
-
/* @__PURE__ */ (0,
|
|
1192
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
997
1193
|
import_lucide_react7.ChevronDownIcon,
|
|
998
1194
|
{
|
|
999
1195
|
className: cn(
|
|
@@ -1007,8 +1203,8 @@ var ReasoningTrigger = (0, import_react5.memo)(
|
|
|
1007
1203
|
);
|
|
1008
1204
|
}
|
|
1009
1205
|
);
|
|
1010
|
-
var ReasoningContent = (0,
|
|
1011
|
-
({ className, children, ...props }) => /* @__PURE__ */ (0,
|
|
1206
|
+
var ReasoningContent = (0, import_react6.memo)(
|
|
1207
|
+
({ className, children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1012
1208
|
CollapsibleContent2,
|
|
1013
1209
|
{
|
|
1014
1210
|
className: cn(
|
|
@@ -1017,7 +1213,7 @@ var ReasoningContent = (0, import_react5.memo)(
|
|
|
1017
1213
|
className
|
|
1018
1214
|
),
|
|
1019
1215
|
...props,
|
|
1020
|
-
children: /* @__PURE__ */ (0,
|
|
1216
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Response, { className: "grid gap-2", children })
|
|
1021
1217
|
}
|
|
1022
1218
|
)
|
|
1023
1219
|
);
|
|
@@ -1026,8 +1222,8 @@ ReasoningTrigger.displayName = "ReasoningTrigger";
|
|
|
1026
1222
|
ReasoningContent.displayName = "ReasoningContent";
|
|
1027
1223
|
|
|
1028
1224
|
// src/components/loader.tsx
|
|
1029
|
-
var
|
|
1030
|
-
var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ (0,
|
|
1225
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1226
|
+
var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
|
|
1031
1227
|
"svg",
|
|
1032
1228
|
{
|
|
1033
1229
|
height: size,
|
|
@@ -1036,10 +1232,10 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx
|
|
|
1036
1232
|
viewBox: "0 0 16 16",
|
|
1037
1233
|
width: size,
|
|
1038
1234
|
children: [
|
|
1039
|
-
/* @__PURE__ */ (0,
|
|
1040
|
-
/* @__PURE__ */ (0,
|
|
1041
|
-
/* @__PURE__ */ (0,
|
|
1042
|
-
/* @__PURE__ */ (0,
|
|
1235
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("title", { children: "Loader" }),
|
|
1236
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("g", { clipPath: "url(#clip0_2393_1490)", children: [
|
|
1237
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("path", { d: "M8 0V4", stroke: "currentColor", strokeWidth: "1.5" }),
|
|
1238
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1043
1239
|
"path",
|
|
1044
1240
|
{
|
|
1045
1241
|
d: "M8 16V12",
|
|
@@ -1048,7 +1244,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx
|
|
|
1048
1244
|
strokeWidth: "1.5"
|
|
1049
1245
|
}
|
|
1050
1246
|
),
|
|
1051
|
-
/* @__PURE__ */ (0,
|
|
1247
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1052
1248
|
"path",
|
|
1053
1249
|
{
|
|
1054
1250
|
d: "M3.29773 1.52783L5.64887 4.7639",
|
|
@@ -1057,7 +1253,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx
|
|
|
1057
1253
|
strokeWidth: "1.5"
|
|
1058
1254
|
}
|
|
1059
1255
|
),
|
|
1060
|
-
/* @__PURE__ */ (0,
|
|
1256
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1061
1257
|
"path",
|
|
1062
1258
|
{
|
|
1063
1259
|
d: "M12.7023 1.52783L10.3511 4.7639",
|
|
@@ -1066,7 +1262,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx
|
|
|
1066
1262
|
strokeWidth: "1.5"
|
|
1067
1263
|
}
|
|
1068
1264
|
),
|
|
1069
|
-
/* @__PURE__ */ (0,
|
|
1265
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1070
1266
|
"path",
|
|
1071
1267
|
{
|
|
1072
1268
|
d: "M12.7023 14.472L10.3511 11.236",
|
|
@@ -1075,7 +1271,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx
|
|
|
1075
1271
|
strokeWidth: "1.5"
|
|
1076
1272
|
}
|
|
1077
1273
|
),
|
|
1078
|
-
/* @__PURE__ */ (0,
|
|
1274
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1079
1275
|
"path",
|
|
1080
1276
|
{
|
|
1081
1277
|
d: "M3.29773 14.472L5.64887 11.236",
|
|
@@ -1084,7 +1280,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx
|
|
|
1084
1280
|
strokeWidth: "1.5"
|
|
1085
1281
|
}
|
|
1086
1282
|
),
|
|
1087
|
-
/* @__PURE__ */ (0,
|
|
1283
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1088
1284
|
"path",
|
|
1089
1285
|
{
|
|
1090
1286
|
d: "M15.6085 5.52783L11.8043 6.7639",
|
|
@@ -1093,7 +1289,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx
|
|
|
1093
1289
|
strokeWidth: "1.5"
|
|
1094
1290
|
}
|
|
1095
1291
|
),
|
|
1096
|
-
/* @__PURE__ */ (0,
|
|
1292
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1097
1293
|
"path",
|
|
1098
1294
|
{
|
|
1099
1295
|
d: "M0.391602 10.472L4.19583 9.23598",
|
|
@@ -1102,7 +1298,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx
|
|
|
1102
1298
|
strokeWidth: "1.5"
|
|
1103
1299
|
}
|
|
1104
1300
|
),
|
|
1105
|
-
/* @__PURE__ */ (0,
|
|
1301
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1106
1302
|
"path",
|
|
1107
1303
|
{
|
|
1108
1304
|
d: "M15.6085 10.4722L11.8043 9.2361",
|
|
@@ -1111,7 +1307,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx
|
|
|
1111
1307
|
strokeWidth: "1.5"
|
|
1112
1308
|
}
|
|
1113
1309
|
),
|
|
1114
|
-
/* @__PURE__ */ (0,
|
|
1310
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1115
1311
|
"path",
|
|
1116
1312
|
{
|
|
1117
1313
|
d: "M0.391602 5.52783L4.19583 6.7639",
|
|
@@ -1121,11 +1317,11 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx
|
|
|
1121
1317
|
}
|
|
1122
1318
|
)
|
|
1123
1319
|
] }),
|
|
1124
|
-
/* @__PURE__ */ (0,
|
|
1320
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("clipPath", { id: "clip0_2393_1490", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("rect", { fill: "white", height: "16", width: "16" }) }) })
|
|
1125
1321
|
]
|
|
1126
1322
|
}
|
|
1127
1323
|
);
|
|
1128
|
-
var Loader = ({ className, size = 16, ...props }) => /* @__PURE__ */ (0,
|
|
1324
|
+
var Loader = ({ className, size = 16, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1129
1325
|
"div",
|
|
1130
1326
|
{
|
|
1131
1327
|
className: cn(
|
|
@@ -1133,14 +1329,14 @@ var Loader = ({ className, size = 16, ...props }) => /* @__PURE__ */ (0, import_
|
|
|
1133
1329
|
className
|
|
1134
1330
|
),
|
|
1135
1331
|
...props,
|
|
1136
|
-
children: /* @__PURE__ */ (0,
|
|
1332
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(LoaderIcon, { size })
|
|
1137
1333
|
}
|
|
1138
1334
|
);
|
|
1139
1335
|
|
|
1140
1336
|
// src/ui/badge.tsx
|
|
1141
1337
|
var import_react_slot2 = require("@radix-ui/react-slot");
|
|
1142
1338
|
var import_class_variance_authority3 = require("class-variance-authority");
|
|
1143
|
-
var
|
|
1339
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
1144
1340
|
var badgeVariants = (0, import_class_variance_authority3.cva)(
|
|
1145
1341
|
"inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
|
1146
1342
|
{
|
|
@@ -1164,7 +1360,7 @@ function Badge({
|
|
|
1164
1360
|
...props
|
|
1165
1361
|
}) {
|
|
1166
1362
|
const Comp = asChild ? import_react_slot2.Slot : "span";
|
|
1167
|
-
return /* @__PURE__ */ (0,
|
|
1363
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1168
1364
|
Comp,
|
|
1169
1365
|
{
|
|
1170
1366
|
"data-slot": "badge",
|
|
@@ -1176,15 +1372,15 @@ function Badge({
|
|
|
1176
1372
|
|
|
1177
1373
|
// src/components/tool.tsx
|
|
1178
1374
|
var import_lucide_react9 = require("lucide-react");
|
|
1179
|
-
var
|
|
1375
|
+
var import_react8 = require("react");
|
|
1180
1376
|
|
|
1181
1377
|
// src/components/code-block.tsx
|
|
1182
1378
|
var import_lucide_react8 = require("lucide-react");
|
|
1183
|
-
var
|
|
1379
|
+
var import_react7 = require("react");
|
|
1184
1380
|
var import_react_syntax_highlighter = require("react-syntax-highlighter");
|
|
1185
1381
|
var import_prism = require("react-syntax-highlighter/dist/esm/styles/prism");
|
|
1186
|
-
var
|
|
1187
|
-
var CodeBlockContext = (0,
|
|
1382
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
1383
|
+
var CodeBlockContext = (0, import_react7.createContext)({
|
|
1188
1384
|
code: ""
|
|
1189
1385
|
});
|
|
1190
1386
|
var CodeBlock = ({
|
|
@@ -1194,7 +1390,7 @@ var CodeBlock = ({
|
|
|
1194
1390
|
className,
|
|
1195
1391
|
children,
|
|
1196
1392
|
...props
|
|
1197
|
-
}) => /* @__PURE__ */ (0,
|
|
1393
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(CodeBlockContext.Provider, { value: { code }, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1198
1394
|
"div",
|
|
1199
1395
|
{
|
|
1200
1396
|
className: cn(
|
|
@@ -1202,8 +1398,8 @@ var CodeBlock = ({
|
|
|
1202
1398
|
className
|
|
1203
1399
|
),
|
|
1204
1400
|
...props,
|
|
1205
|
-
children: /* @__PURE__ */ (0,
|
|
1206
|
-
/* @__PURE__ */ (0,
|
|
1401
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "relative max-h-96 overflow-y-auto", children: [
|
|
1402
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1207
1403
|
import_react_syntax_highlighter.Prism,
|
|
1208
1404
|
{
|
|
1209
1405
|
className: "overflow-hidden dark:hidden",
|
|
@@ -1229,7 +1425,7 @@ var CodeBlock = ({
|
|
|
1229
1425
|
children: code
|
|
1230
1426
|
}
|
|
1231
1427
|
),
|
|
1232
|
-
/* @__PURE__ */ (0,
|
|
1428
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1233
1429
|
import_react_syntax_highlighter.Prism,
|
|
1234
1430
|
{
|
|
1235
1431
|
className: "hidden overflow-hidden dark:block",
|
|
@@ -1255,14 +1451,14 @@ var CodeBlock = ({
|
|
|
1255
1451
|
children: code
|
|
1256
1452
|
}
|
|
1257
1453
|
),
|
|
1258
|
-
children && /* @__PURE__ */ (0,
|
|
1454
|
+
children && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "absolute top-2 right-2 flex items-center gap-2", children })
|
|
1259
1455
|
] })
|
|
1260
1456
|
}
|
|
1261
1457
|
) });
|
|
1262
1458
|
|
|
1263
1459
|
// src/components/tool.tsx
|
|
1264
|
-
var
|
|
1265
|
-
var Tool = ({ className, ...props }) => /* @__PURE__ */ (0,
|
|
1460
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
1461
|
+
var Tool = ({ className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1266
1462
|
Collapsible,
|
|
1267
1463
|
{
|
|
1268
1464
|
className: cn("not-prose w-full rounded-md border border-[var(--chat-divider)]", className),
|
|
@@ -1277,12 +1473,12 @@ var getStatusBadge = (status) => {
|
|
|
1277
1473
|
"output-error": "Error"
|
|
1278
1474
|
};
|
|
1279
1475
|
const icons = {
|
|
1280
|
-
"input-streaming": /* @__PURE__ */ (0,
|
|
1281
|
-
"input-available": /* @__PURE__ */ (0,
|
|
1282
|
-
"output-available": /* @__PURE__ */ (0,
|
|
1283
|
-
"output-error": /* @__PURE__ */ (0,
|
|
1476
|
+
"input-streaming": /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_lucide_react9.CircleIcon, { className: "size-4" }),
|
|
1477
|
+
"input-available": /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_lucide_react9.ClockIcon, { className: "size-4 animate-pulse" }),
|
|
1478
|
+
"output-available": /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_lucide_react9.CheckCircleIcon, { className: "size-4 text-green-600" }),
|
|
1479
|
+
"output-error": /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_lucide_react9.XCircleIcon, { className: "size-4 text-red-600" })
|
|
1284
1480
|
};
|
|
1285
|
-
return /* @__PURE__ */ (0,
|
|
1481
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(Badge, { className: "gap-1.5 rounded-full text-xs", variant: "secondary", children: [
|
|
1286
1482
|
icons[status],
|
|
1287
1483
|
labels[status]
|
|
1288
1484
|
] });
|
|
@@ -1294,7 +1490,7 @@ var ToolHeader = ({
|
|
|
1294
1490
|
toolName,
|
|
1295
1491
|
state,
|
|
1296
1492
|
...props
|
|
1297
|
-
}) => /* @__PURE__ */ (0,
|
|
1493
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
|
|
1298
1494
|
CollapsibleTrigger2,
|
|
1299
1495
|
{
|
|
1300
1496
|
className: cn(
|
|
@@ -1303,16 +1499,16 @@ var ToolHeader = ({
|
|
|
1303
1499
|
),
|
|
1304
1500
|
...props,
|
|
1305
1501
|
children: [
|
|
1306
|
-
/* @__PURE__ */ (0,
|
|
1307
|
-
/* @__PURE__ */ (0,
|
|
1308
|
-
/* @__PURE__ */ (0,
|
|
1502
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
1503
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_lucide_react9.WrenchIcon, { className: "size-4 text-muted-foreground" }),
|
|
1504
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "font-medium text-sm", children: title ?? toolName ?? type.split("-").slice(1).join("-") }),
|
|
1309
1505
|
getStatusBadge(state)
|
|
1310
1506
|
] }),
|
|
1311
|
-
/* @__PURE__ */ (0,
|
|
1507
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_lucide_react9.ChevronDownIcon, { className: "size-4 text-muted-foreground transition-transform group-data-[state=open]:rotate-180" })
|
|
1312
1508
|
]
|
|
1313
1509
|
}
|
|
1314
1510
|
);
|
|
1315
|
-
var ToolContent = ({ className, ...props }) => /* @__PURE__ */ (0,
|
|
1511
|
+
var ToolContent = ({ className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1316
1512
|
CollapsibleContent2,
|
|
1317
1513
|
{
|
|
1318
1514
|
className: cn(
|
|
@@ -1322,9 +1518,9 @@ var ToolContent = ({ className, ...props }) => /* @__PURE__ */ (0, import_jsx_ru
|
|
|
1322
1518
|
...props
|
|
1323
1519
|
}
|
|
1324
1520
|
);
|
|
1325
|
-
var ToolInput = ({ className, input, ...props }) => /* @__PURE__ */ (0,
|
|
1326
|
-
/* @__PURE__ */ (0,
|
|
1327
|
-
/* @__PURE__ */ (0,
|
|
1521
|
+
var ToolInput = ({ className, input, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: cn("space-y-2 overflow-hidden p-2", className), ...props, children: [
|
|
1522
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("h4", { className: "font-medium text-muted-foreground text-xs uppercase tracking-wide", children: "Parameters" }),
|
|
1523
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "rounded-md bg-muted/50", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(CodeBlock, { code: JSON.stringify(input, null, 2), language: "json" }) })
|
|
1328
1524
|
] });
|
|
1329
1525
|
var ToolOutput = ({
|
|
1330
1526
|
className,
|
|
@@ -1335,15 +1531,15 @@ var ToolOutput = ({
|
|
|
1335
1531
|
if (!(output || errorText)) {
|
|
1336
1532
|
return null;
|
|
1337
1533
|
}
|
|
1338
|
-
let Output = /* @__PURE__ */ (0,
|
|
1339
|
-
if (typeof output === "object" && !(0,
|
|
1340
|
-
Output = /* @__PURE__ */ (0,
|
|
1534
|
+
let Output = /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { children: output });
|
|
1535
|
+
if (typeof output === "object" && !(0, import_react8.isValidElement)(output)) {
|
|
1536
|
+
Output = /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(CodeBlock, { code: JSON.stringify(output, null, 2), language: "json" });
|
|
1341
1537
|
} else if (typeof output === "string") {
|
|
1342
|
-
Output = /* @__PURE__ */ (0,
|
|
1538
|
+
Output = /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(CodeBlock, { code: output, language: "json" });
|
|
1343
1539
|
}
|
|
1344
|
-
return /* @__PURE__ */ (0,
|
|
1345
|
-
/* @__PURE__ */ (0,
|
|
1346
|
-
/* @__PURE__ */ (0,
|
|
1540
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: cn("space-y-2 p-2", className), ...props, children: [
|
|
1541
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("h4", { className: "font-medium text-muted-foreground text-xs uppercase tracking-wide", children: errorText ? "Error" : "Result" }),
|
|
1542
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
|
|
1347
1543
|
"div",
|
|
1348
1544
|
{
|
|
1349
1545
|
className: cn(
|
|
@@ -1351,7 +1547,7 @@ var ToolOutput = ({
|
|
|
1351
1547
|
errorText ? "bg-destructive/10 text-destructive" : "bg-muted/50 text-foreground"
|
|
1352
1548
|
),
|
|
1353
1549
|
children: [
|
|
1354
|
-
errorText && /* @__PURE__ */ (0,
|
|
1550
|
+
errorText && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { children: errorText }),
|
|
1355
1551
|
Output
|
|
1356
1552
|
]
|
|
1357
1553
|
}
|
|
@@ -1360,7 +1556,7 @@ var ToolOutput = ({
|
|
|
1360
1556
|
};
|
|
1361
1557
|
|
|
1362
1558
|
// src/components/suggestion2.tsx
|
|
1363
|
-
var
|
|
1559
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
1364
1560
|
function StarterMessages({
|
|
1365
1561
|
className,
|
|
1366
1562
|
prompts,
|
|
@@ -1368,7 +1564,7 @@ function StarterMessages({
|
|
|
1368
1564
|
...props
|
|
1369
1565
|
}) {
|
|
1370
1566
|
if (prompts.length === 0) return null;
|
|
1371
|
-
return /* @__PURE__ */ (0,
|
|
1567
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
1372
1568
|
"div",
|
|
1373
1569
|
{
|
|
1374
1570
|
className: cn(
|
|
@@ -1376,8 +1572,8 @@ function StarterMessages({
|
|
|
1376
1572
|
className
|
|
1377
1573
|
),
|
|
1378
1574
|
...props,
|
|
1379
|
-
children: prompts.map((prompt, index) => /* @__PURE__ */ (0,
|
|
1380
|
-
/* @__PURE__ */ (0,
|
|
1575
|
+
children: prompts.map((prompt, index) => /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { children: [
|
|
1576
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
1381
1577
|
StarterMessageItem,
|
|
1382
1578
|
{
|
|
1383
1579
|
prompt,
|
|
@@ -1387,7 +1583,7 @@ function StarterMessages({
|
|
|
1387
1583
|
index < prompts.length - 1 && // 1px-tall element used as a divider — same --chat-divider token
|
|
1388
1584
|
// every other separator in the widget uses, so consumers only
|
|
1389
1585
|
// need to override one variable to recolour all of them.
|
|
1390
|
-
/* @__PURE__ */ (0,
|
|
1586
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "h-px mx-3", style: { backgroundColor: "var(--chat-divider)" } })
|
|
1391
1587
|
] }, index))
|
|
1392
1588
|
}
|
|
1393
1589
|
);
|
|
@@ -1398,7 +1594,7 @@ function StarterMessageItem({
|
|
|
1398
1594
|
onClick,
|
|
1399
1595
|
...props
|
|
1400
1596
|
}) {
|
|
1401
|
-
return /* @__PURE__ */ (0,
|
|
1597
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
|
|
1402
1598
|
"button",
|
|
1403
1599
|
{
|
|
1404
1600
|
type: "button",
|
|
@@ -1413,17 +1609,17 @@ function StarterMessageItem({
|
|
|
1413
1609
|
),
|
|
1414
1610
|
...props,
|
|
1415
1611
|
children: [
|
|
1416
|
-
/* @__PURE__ */ (0,
|
|
1417
|
-
prompt.subtitle && /* @__PURE__ */ (0,
|
|
1612
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "text-[13px] text-[hsl(var(--chat-text)/0.7)]", children: prompt.title }),
|
|
1613
|
+
prompt.subtitle && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "block text-[11px] text-[hsl(var(--chat-text)/0.4)] mt-0.5", children: prompt.subtitle })
|
|
1418
1614
|
]
|
|
1419
1615
|
}
|
|
1420
1616
|
);
|
|
1421
1617
|
}
|
|
1422
1618
|
|
|
1423
1619
|
// src/contexts/chat-storage-context.tsx
|
|
1424
|
-
var
|
|
1425
|
-
var
|
|
1426
|
-
var ChatStorageContext = (0,
|
|
1620
|
+
var import_react9 = require("react");
|
|
1621
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
1622
|
+
var ChatStorageContext = (0, import_react9.createContext)({
|
|
1427
1623
|
storageKeyPrefix: ""
|
|
1428
1624
|
});
|
|
1429
1625
|
function ChatStorageProvider({
|
|
@@ -1431,39 +1627,46 @@ function ChatStorageProvider({
|
|
|
1431
1627
|
userId
|
|
1432
1628
|
}) {
|
|
1433
1629
|
const storageKeyPrefix = userId || "";
|
|
1434
|
-
return /* @__PURE__ */ (0,
|
|
1630
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ChatStorageContext.Provider, { value: { storageKeyPrefix }, children });
|
|
1435
1631
|
}
|
|
1436
1632
|
function useChatStorageKey() {
|
|
1437
|
-
return (0,
|
|
1633
|
+
return (0, import_react9.useContext)(ChatStorageContext);
|
|
1438
1634
|
}
|
|
1439
1635
|
|
|
1440
1636
|
// src/components/interface.tsx
|
|
1441
|
-
var
|
|
1637
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
1442
1638
|
function ChatInterface({ id, initialMessages, config, onClose, headerActions } = {}) {
|
|
1443
1639
|
const { storageKeyPrefix } = useChatStorageKey();
|
|
1444
1640
|
const storageKey = (key) => storageKeyPrefix ? `chat-${storageKeyPrefix}-${key}` : `chat-${key}`;
|
|
1445
1641
|
const themeMode = config?.theme?.mode || "light";
|
|
1446
|
-
const [input, setInput] = (0,
|
|
1447
|
-
const
|
|
1448
|
-
const
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1642
|
+
const [input, setInput] = (0, import_react10.useState)("");
|
|
1643
|
+
const inputRef = (0, import_react10.useRef)(null);
|
|
1644
|
+
const inputPlugins = useInputPlugins({
|
|
1645
|
+
textareaRef: inputRef,
|
|
1646
|
+
value: input,
|
|
1647
|
+
setValue: setInput,
|
|
1648
|
+
plugins: config?.inputPlugins
|
|
1649
|
+
});
|
|
1650
|
+
const [showHistory, setShowHistory] = (0, import_react10.useState)(false);
|
|
1651
|
+
const [conversations, setConversations] = (0, import_react10.useState)([]);
|
|
1652
|
+
const [loadingHistory, setLoadingHistory] = (0, import_react10.useState)(false);
|
|
1653
|
+
const [historyLoaded, setHistoryLoaded] = (0, import_react10.useState)(false);
|
|
1654
|
+
const [searchQuery, setSearchQuery] = (0, import_react10.useState)("");
|
|
1655
|
+
const [uploadError, setUploadError] = (0, import_react10.useState)(null);
|
|
1656
|
+
(0, import_react10.useEffect)(() => {
|
|
1454
1657
|
if (uploadError) {
|
|
1455
1658
|
const timeoutId = setTimeout(() => setUploadError(null), 5e3);
|
|
1456
1659
|
return () => clearTimeout(timeoutId);
|
|
1457
1660
|
}
|
|
1458
1661
|
}, [uploadError]);
|
|
1459
|
-
const [tabs, setTabs] = (0,
|
|
1460
|
-
const [activeTabId, setActiveTabId] = (0,
|
|
1461
|
-
const [initialTabCreated, setInitialTabCreated] = (0,
|
|
1462
|
-
const [isInitializing, setIsInitializing] = (0,
|
|
1463
|
-
const [isLoadingMessages, setIsLoadingMessages] = (0,
|
|
1464
|
-
const lastSyncedTabId = (0,
|
|
1465
|
-
const hasInitialized = (0,
|
|
1466
|
-
const { messages, sendMessage, status, setMessages } = (0,
|
|
1662
|
+
const [tabs, setTabs] = (0, import_react10.useState)([]);
|
|
1663
|
+
const [activeTabId, setActiveTabId] = (0, import_react10.useState)("");
|
|
1664
|
+
const [initialTabCreated, setInitialTabCreated] = (0, import_react10.useState)(false);
|
|
1665
|
+
const [isInitializing, setIsInitializing] = (0, import_react10.useState)(true);
|
|
1666
|
+
const [isLoadingMessages, setIsLoadingMessages] = (0, import_react10.useState)(false);
|
|
1667
|
+
const lastSyncedTabId = (0, import_react10.useRef)("");
|
|
1668
|
+
const hasInitialized = (0, import_react10.useRef)(false);
|
|
1669
|
+
const { messages, sendMessage, status, setMessages } = (0, import_react12.useChat)({
|
|
1467
1670
|
id: activeTabId || "temp-id",
|
|
1468
1671
|
transport: new import_ai.DefaultChatTransport({
|
|
1469
1672
|
api: "/api/chat",
|
|
@@ -1552,12 +1755,12 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1552
1755
|
};
|
|
1553
1756
|
const AttachButton = () => {
|
|
1554
1757
|
const attachments = usePromptInputAttachments();
|
|
1555
|
-
return /* @__PURE__ */ (0,
|
|
1758
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
1556
1759
|
PromptInputButton,
|
|
1557
1760
|
{
|
|
1558
1761
|
variant: "ghost",
|
|
1559
1762
|
onClick: () => attachments.openFileDialog(),
|
|
1560
|
-
children: /* @__PURE__ */ (0,
|
|
1763
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react10.PlusIcon, { className: "size-4" })
|
|
1561
1764
|
}
|
|
1562
1765
|
);
|
|
1563
1766
|
};
|
|
@@ -1596,7 +1799,7 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1596
1799
|
}
|
|
1597
1800
|
return newTabId;
|
|
1598
1801
|
};
|
|
1599
|
-
const createNewTab = (0,
|
|
1802
|
+
const createNewTab = (0, import_react10.useCallback)(() => {
|
|
1600
1803
|
if (!initialTabCreated) {
|
|
1601
1804
|
console.warn("Cannot create new tab while initializing");
|
|
1602
1805
|
return;
|
|
@@ -1623,10 +1826,10 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1623
1826
|
setMessages([]);
|
|
1624
1827
|
setInput("");
|
|
1625
1828
|
}, [initialTabCreated]);
|
|
1626
|
-
const startNewConversation = (0,
|
|
1829
|
+
const startNewConversation = (0, import_react10.useCallback)(() => {
|
|
1627
1830
|
createNewTab();
|
|
1628
1831
|
}, [createNewTab]);
|
|
1629
|
-
(0,
|
|
1832
|
+
(0, import_react10.useEffect)(() => {
|
|
1630
1833
|
return () => {
|
|
1631
1834
|
};
|
|
1632
1835
|
}, []);
|
|
@@ -1691,17 +1894,17 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1691
1894
|
setLoadingHistory(false);
|
|
1692
1895
|
}
|
|
1693
1896
|
};
|
|
1694
|
-
(0,
|
|
1897
|
+
(0, import_react10.useEffect)(() => {
|
|
1695
1898
|
if (showHistory && !historyLoaded && config?.userId) {
|
|
1696
1899
|
fetchConversations();
|
|
1697
1900
|
}
|
|
1698
1901
|
}, [showHistory, historyLoaded, config?.userId]);
|
|
1699
|
-
(0,
|
|
1902
|
+
(0, import_react10.useEffect)(() => {
|
|
1700
1903
|
if (!historyLoaded && config?.userId) {
|
|
1701
1904
|
fetchConversations();
|
|
1702
1905
|
}
|
|
1703
1906
|
}, [historyLoaded, config?.userId]);
|
|
1704
|
-
(0,
|
|
1907
|
+
(0, import_react10.useEffect)(() => {
|
|
1705
1908
|
if (tabs.length > 0) {
|
|
1706
1909
|
const timeoutId = setTimeout(() => {
|
|
1707
1910
|
localStorage.setItem(storageKey("tabs"), JSON.stringify(tabs));
|
|
@@ -1710,7 +1913,7 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1710
1913
|
return () => clearTimeout(timeoutId);
|
|
1711
1914
|
}
|
|
1712
1915
|
}, [tabs, activeTabId, storageKey]);
|
|
1713
|
-
(0,
|
|
1916
|
+
(0, import_react10.useEffect)(() => {
|
|
1714
1917
|
if (hasInitialized.current) return;
|
|
1715
1918
|
const loadInitialTabs = () => {
|
|
1716
1919
|
const savedTabs = localStorage.getItem(storageKey("tabs"));
|
|
@@ -1737,8 +1940,8 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1737
1940
|
}
|
|
1738
1941
|
hasInitialized.current = true;
|
|
1739
1942
|
}, []);
|
|
1740
|
-
const hasLoadedInitialMessages = (0,
|
|
1741
|
-
(0,
|
|
1943
|
+
const hasLoadedInitialMessages = (0, import_react10.useRef)(false);
|
|
1944
|
+
(0, import_react10.useEffect)(() => {
|
|
1742
1945
|
if (hasLoadedInitialMessages.current) return;
|
|
1743
1946
|
if (!config?.userId) return;
|
|
1744
1947
|
if (!activeTabId) return;
|
|
@@ -1751,14 +1954,14 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1751
1954
|
}
|
|
1752
1955
|
})();
|
|
1753
1956
|
}, [config?.userId, activeTabId]);
|
|
1754
|
-
(0,
|
|
1957
|
+
(0, import_react10.useEffect)(() => {
|
|
1755
1958
|
if (isInitializing) return;
|
|
1756
1959
|
if (activeTabId && tabs.length > 0 && activeTabId !== lastSyncedTabId.current) {
|
|
1757
1960
|
lastSyncedTabId.current = activeTabId;
|
|
1758
1961
|
setInput("");
|
|
1759
1962
|
}
|
|
1760
1963
|
}, [activeTabId, isInitializing, tabs.length]);
|
|
1761
|
-
const groupedConversations = (0,
|
|
1964
|
+
const groupedConversations = (0, import_react10.useMemo)(() => {
|
|
1762
1965
|
const filtered = conversations.filter(
|
|
1763
1966
|
(conv) => searchQuery === "" || conv.title.toLowerCase().includes(searchQuery.toLowerCase())
|
|
1764
1967
|
);
|
|
@@ -1819,10 +2022,10 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1819
2022
|
const renderMessages = () => messages.map((message, index) => {
|
|
1820
2023
|
const sourceParts = message.parts?.filter((part) => part.type === "source-url") || [];
|
|
1821
2024
|
const fileParts = message.parts?.filter((part) => part.type === "file") || [];
|
|
1822
|
-
return /* @__PURE__ */ (0,
|
|
1823
|
-
message.role === "assistant" && sourceParts.length > 0 && /* @__PURE__ */ (0,
|
|
1824
|
-
/* @__PURE__ */ (0,
|
|
1825
|
-
sourceParts.map((part, i) => /* @__PURE__ */ (0,
|
|
2025
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: index > 0 ? "mt-6" : "", children: [
|
|
2026
|
+
message.role === "assistant" && sourceParts.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(Sources, { children: [
|
|
2027
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SourcesTrigger, { count: sourceParts.length }),
|
|
2028
|
+
sourceParts.map((part, i) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SourcesContent, { children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
1826
2029
|
Source,
|
|
1827
2030
|
{
|
|
1828
2031
|
href: part.url,
|
|
@@ -1831,10 +2034,10 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1831
2034
|
`${message.id}-${i}`
|
|
1832
2035
|
) }, `${message.id}-${i}`))
|
|
1833
2036
|
] }),
|
|
1834
|
-
fileParts.length > 0 && /* @__PURE__ */ (0,
|
|
2037
|
+
fileParts.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: cn(
|
|
1835
2038
|
"flex mb-1",
|
|
1836
2039
|
message.role === "user" ? "justify-end" : "justify-start"
|
|
1837
|
-
), children: /* @__PURE__ */ (0,
|
|
2040
|
+
), children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
1838
2041
|
MessageAttachments,
|
|
1839
2042
|
{
|
|
1840
2043
|
attachments: fileParts.map((part) => ({
|
|
@@ -1845,14 +2048,14 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1845
2048
|
}))
|
|
1846
2049
|
}
|
|
1847
2050
|
) }),
|
|
1848
|
-
message.parts ? /* @__PURE__ */ (0,
|
|
2051
|
+
message.parts ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "space-y-2", children: message.parts.map((part, i) => {
|
|
1849
2052
|
switch (part.type) {
|
|
1850
2053
|
case "text":
|
|
1851
2054
|
const isTextStreaming = status === "streaming" && i === message.parts.length - 1 && message.id === messages.at(-1)?.id;
|
|
1852
|
-
return /* @__PURE__ */ (0,
|
|
2055
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react11.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Message, { from: message.role, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(MessageContent, { children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Response, { isStreaming: isTextStreaming, children: part.text }) }) }) }, `${message.id}-${i}`);
|
|
1853
2056
|
case "reasoning":
|
|
1854
2057
|
const isCurrentlyStreaming = status === "streaming" && i === message.parts.length - 1 && message.id === messages.at(-1)?.id;
|
|
1855
|
-
return /* @__PURE__ */ (0,
|
|
2058
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
|
|
1856
2059
|
Reasoning,
|
|
1857
2060
|
{
|
|
1858
2061
|
className: "w-full",
|
|
@@ -1860,8 +2063,8 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1860
2063
|
defaultOpen: false,
|
|
1861
2064
|
open: isCurrentlyStreaming ? true : void 0,
|
|
1862
2065
|
children: [
|
|
1863
|
-
/* @__PURE__ */ (0,
|
|
1864
|
-
/* @__PURE__ */ (0,
|
|
2066
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ReasoningTrigger, {}),
|
|
2067
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ReasoningContent, { children: part.text })
|
|
1865
2068
|
]
|
|
1866
2069
|
},
|
|
1867
2070
|
`${message.id}-${i}`
|
|
@@ -1869,8 +2072,8 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1869
2072
|
default:
|
|
1870
2073
|
if (part.type.startsWith("tool-") || part.type === "dynamic-tool") {
|
|
1871
2074
|
const toolPart = part;
|
|
1872
|
-
return /* @__PURE__ */ (0,
|
|
1873
|
-
/* @__PURE__ */ (0,
|
|
2075
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(Tool, { children: [
|
|
2076
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
1874
2077
|
ToolHeader,
|
|
1875
2078
|
{
|
|
1876
2079
|
type: part.type,
|
|
@@ -1878,9 +2081,9 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1878
2081
|
state: toolPart.state
|
|
1879
2082
|
}
|
|
1880
2083
|
),
|
|
1881
|
-
/* @__PURE__ */ (0,
|
|
1882
|
-
/* @__PURE__ */ (0,
|
|
1883
|
-
/* @__PURE__ */ (0,
|
|
2084
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(ToolContent, { children: [
|
|
2085
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ToolInput, { input: toolPart.input }),
|
|
2086
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ToolOutput, { output: toolPart.output, errorText: toolPart.errorText })
|
|
1884
2087
|
] })
|
|
1885
2088
|
] }, `${message.id}-${i}`);
|
|
1886
2089
|
}
|
|
@@ -1888,7 +2091,7 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1888
2091
|
}
|
|
1889
2092
|
}) }) : (
|
|
1890
2093
|
/* Handle standard AI SDK messages with content or text property */
|
|
1891
|
-
/* @__PURE__ */ (0,
|
|
2094
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react11.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Message, { from: message.role, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(MessageContent, { children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Response, { children: message.content || message.text }) }) }) }, `${message.id}-content`)
|
|
1892
2095
|
)
|
|
1893
2096
|
] }, message.id);
|
|
1894
2097
|
});
|
|
@@ -1920,8 +2123,8 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1920
2123
|
console.error("Error loading conversation:", error);
|
|
1921
2124
|
}
|
|
1922
2125
|
};
|
|
1923
|
-
const dropdownRef = (0,
|
|
1924
|
-
(0,
|
|
2126
|
+
const dropdownRef = (0, import_react10.useRef)(null);
|
|
2127
|
+
(0, import_react10.useEffect)(() => {
|
|
1925
2128
|
const handleClickOutside = (event) => {
|
|
1926
2129
|
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
1927
2130
|
setShowHistory(false);
|
|
@@ -1934,7 +2137,7 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1934
2137
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
1935
2138
|
};
|
|
1936
2139
|
}, [showHistory]);
|
|
1937
|
-
return /* @__PURE__ */ (0,
|
|
2140
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: cn("w-full h-full flex flex-col bg-white dark:bg-gray-900 overflow-hidden ring-1 ring-black/[0.02] dark:ring-white/[0.03]", themeMode === "dark" && "dark"), children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
|
|
1938
2141
|
"div",
|
|
1939
2142
|
{
|
|
1940
2143
|
className: cn(
|
|
@@ -1942,11 +2145,11 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1942
2145
|
themeMode === "dark" && "dark"
|
|
1943
2146
|
),
|
|
1944
2147
|
children: [
|
|
1945
|
-
/* @__PURE__ */ (0,
|
|
2148
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex items-center gap-2 px-3 py-2 border-b backdrop-blur-sm relative z-20", style: {
|
|
1946
2149
|
borderColor: "var(--chat-divider)",
|
|
1947
2150
|
backgroundColor: "var(--chat-header-bg)"
|
|
1948
2151
|
}, children: [
|
|
1949
|
-
/* @__PURE__ */ (0,
|
|
2152
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "flex items-center gap-1 flex-1 min-w-0 overflow-x-auto scrollbar-hide py-0.5 scroll-smooth", children: tabs.map((tab, index) => /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
|
|
1950
2153
|
"div",
|
|
1951
2154
|
{
|
|
1952
2155
|
className: "relative flex items-center gap-1.5 px-3 py-1.5 rounded-lg cursor-pointer transition-all duration-150 group flex-shrink-0 min-w-0",
|
|
@@ -1969,8 +2172,8 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1969
2172
|
switchToTab(tab.id);
|
|
1970
2173
|
},
|
|
1971
2174
|
children: [
|
|
1972
|
-
/* @__PURE__ */ (0,
|
|
1973
|
-
tabs.length > 1 && /* @__PURE__ */ (0,
|
|
2175
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "truncate max-w-28 text-[13px] font-medium transition-colors", children: tab.title }),
|
|
2176
|
+
tabs.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
1974
2177
|
"button",
|
|
1975
2178
|
{
|
|
1976
2179
|
onClick: (e) => {
|
|
@@ -1989,15 +2192,15 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1989
2192
|
e.currentTarget.style.opacity = tab.isActive ? "0.6" : "0";
|
|
1990
2193
|
e.currentTarget.style.backgroundColor = "transparent";
|
|
1991
2194
|
},
|
|
1992
|
-
children: /* @__PURE__ */ (0,
|
|
2195
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react10.XIcon, { className: "h-3 w-3", strokeWidth: 2.5 })
|
|
1993
2196
|
}
|
|
1994
2197
|
)
|
|
1995
2198
|
]
|
|
1996
2199
|
},
|
|
1997
2200
|
tab.id
|
|
1998
2201
|
)) }),
|
|
1999
|
-
/* @__PURE__ */ (0,
|
|
2000
|
-
/* @__PURE__ */ (0,
|
|
2202
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex items-center gap-0.5 flex-shrink-0", children: [
|
|
2203
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2001
2204
|
"button",
|
|
2002
2205
|
{
|
|
2003
2206
|
onClick: createNewTab,
|
|
@@ -2014,11 +2217,11 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
2014
2217
|
e.currentTarget.style.backgroundColor = "transparent";
|
|
2015
2218
|
},
|
|
2016
2219
|
title: "New Chat",
|
|
2017
|
-
children: /* @__PURE__ */ (0,
|
|
2220
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react10.PlusIcon, { className: "h-4 w-4", strokeWidth: 2 })
|
|
2018
2221
|
}
|
|
2019
2222
|
),
|
|
2020
|
-
/* @__PURE__ */ (0,
|
|
2021
|
-
/* @__PURE__ */ (0,
|
|
2223
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "relative", ref: dropdownRef, children: [
|
|
2224
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2022
2225
|
"button",
|
|
2023
2226
|
{
|
|
2024
2227
|
onClick: () => setShowHistory(!showHistory),
|
|
@@ -2040,17 +2243,17 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
2040
2243
|
}
|
|
2041
2244
|
},
|
|
2042
2245
|
title: "Chat History",
|
|
2043
|
-
children: /* @__PURE__ */ (0,
|
|
2246
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react10.HistoryIcon, { className: "h-4 w-4", strokeWidth: 2 })
|
|
2044
2247
|
}
|
|
2045
2248
|
),
|
|
2046
|
-
showHistory && /* @__PURE__ */ (0,
|
|
2249
|
+
showHistory && /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "absolute right-0 top-full mt-1.5 w-72 rounded-xl shadow-[0_4px_24px_rgba(0,0,0,0.08)] dark:shadow-[0_4px_24px_rgba(0,0,0,0.3)] z-50 animate-in fade-in slide-in-from-top-1 duration-150 overflow-hidden", style: {
|
|
2047
2250
|
backgroundColor: "hsl(var(--chat-background))",
|
|
2048
2251
|
border: `1px solid ${"var(--chat-divider)"}`
|
|
2049
2252
|
}, children: [
|
|
2050
|
-
/* @__PURE__ */ (0,
|
|
2253
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "p-2.5 border-b", style: {
|
|
2051
2254
|
borderColor: "var(--chat-divider)",
|
|
2052
2255
|
backgroundColor: "var(--chat-overlay)"
|
|
2053
|
-
}, children: /* @__PURE__ */ (0,
|
|
2256
|
+
}, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "relative", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2054
2257
|
"input",
|
|
2055
2258
|
{
|
|
2056
2259
|
type: "text",
|
|
@@ -2065,25 +2268,25 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
2065
2268
|
}
|
|
2066
2269
|
}
|
|
2067
2270
|
) }) }),
|
|
2068
|
-
/* @__PURE__ */ (0,
|
|
2069
|
-
/* @__PURE__ */ (0,
|
|
2271
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "max-h-[300px] overflow-y-auto ai-assistant-scrollbar", children: loadingHistory ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "flex items-center justify-center py-12", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "text-[13px]", style: { color: "hsl(var(--chat-text-muted))" }, children: "Loading..." }) }) : conversations.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex flex-col items-center justify-center py-12 px-4 text-center", children: [
|
|
2272
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "w-12 h-12 rounded-full flex items-center justify-center mb-3", style: {
|
|
2070
2273
|
backgroundColor: "hsl(var(--chat-surface))"
|
|
2071
|
-
}, children: /* @__PURE__ */ (0,
|
|
2072
|
-
/* @__PURE__ */ (0,
|
|
2073
|
-
/* @__PURE__ */ (0,
|
|
2074
|
-
] }) : groupedConversations.length === 0 ? /* @__PURE__ */ (0,
|
|
2075
|
-
/* @__PURE__ */ (0,
|
|
2274
|
+
}, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react10.MessageSquareIcon, { className: "h-5 w-5", style: { color: "hsl(var(--chat-text-subtle))" }, strokeWidth: 2 }) }),
|
|
2275
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "text-[13px] font-medium mb-0.5", style: { color: "hsl(var(--chat-text))" }, children: "No Conversations" }),
|
|
2276
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "text-[12px]", style: { color: "hsl(var(--chat-text-muted))" }, children: "Start a new chat to begin" })
|
|
2277
|
+
] }) : groupedConversations.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex flex-col items-center justify-center py-12 px-4 text-center", children: [
|
|
2278
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "w-12 h-12 rounded-full flex items-center justify-center mb-3", style: {
|
|
2076
2279
|
backgroundColor: "hsl(var(--chat-surface))"
|
|
2077
|
-
}, children: /* @__PURE__ */ (0,
|
|
2078
|
-
/* @__PURE__ */ (0,
|
|
2079
|
-
/* @__PURE__ */ (0,
|
|
2080
|
-
] }) : /* @__PURE__ */ (0,
|
|
2081
|
-
/* @__PURE__ */ (0,
|
|
2280
|
+
}, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react10.SearchIcon, { className: "h-5 w-5", style: { color: "hsl(var(--chat-text-subtle))" }, strokeWidth: 2 }) }),
|
|
2281
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "text-[13px] font-medium mb-0.5", style: { color: "hsl(var(--chat-text))" }, children: "No Results" }),
|
|
2282
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "text-[12px]", style: { color: "hsl(var(--chat-text-muted))" }, children: "Try a different search" })
|
|
2283
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "py-0.5", children: groupedConversations.map(([groupName, groupConversations]) => /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "mb-0.5", children: [
|
|
2284
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "px-2.5 py-1 sticky top-0 backdrop-blur-sm z-10", style: {
|
|
2082
2285
|
backgroundColor: "var(--chat-header-bg-strong)"
|
|
2083
|
-
}, children: /* @__PURE__ */ (0,
|
|
2084
|
-
/* @__PURE__ */ (0,
|
|
2286
|
+
}, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("h3", { className: "text-[10px] font-semibold uppercase tracking-wide", style: { color: "hsl(var(--chat-text-muted))" }, children: groupName }) }),
|
|
2287
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "px-1 space-y-0.5", children: groupConversations.map((conversation) => {
|
|
2085
2288
|
const isActiveConversation = activeTabId === conversation.id;
|
|
2086
|
-
return /* @__PURE__ */ (0,
|
|
2289
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2087
2290
|
"button",
|
|
2088
2291
|
{
|
|
2089
2292
|
className: "w-full px-2 py-1 rounded-md transition-all duration-150 text-left group relative",
|
|
@@ -2101,12 +2304,12 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
2101
2304
|
}
|
|
2102
2305
|
},
|
|
2103
2306
|
onClick: () => handleSelectConversation(conversation.id, conversation.title),
|
|
2104
|
-
children: /* @__PURE__ */ (0,
|
|
2105
|
-
/* @__PURE__ */ (0,
|
|
2307
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex items-center gap-1.5", children: [
|
|
2308
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "flex-1 min-w-0", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "text-[12px] line-clamp-1 transition-colors leading-tight", style: {
|
|
2106
2309
|
fontWeight: isActiveConversation ? 500 : 400,
|
|
2107
2310
|
color: isActiveConversation ? "hsl(var(--chat-text))" : "hsl(var(--chat-text-strong))"
|
|
2108
2311
|
}, children: conversation.title }) }),
|
|
2109
|
-
/* @__PURE__ */ (0,
|
|
2312
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2110
2313
|
import_lucide_react10.ChevronRightIcon,
|
|
2111
2314
|
{
|
|
2112
2315
|
className: "h-3 w-3 transition-all duration-150 flex-shrink-0",
|
|
@@ -2126,7 +2329,7 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
2126
2329
|
] })
|
|
2127
2330
|
] }),
|
|
2128
2331
|
headerActions,
|
|
2129
|
-
onClose && /* @__PURE__ */ (0,
|
|
2332
|
+
onClose && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2130
2333
|
"button",
|
|
2131
2334
|
{
|
|
2132
2335
|
onClick: onClose,
|
|
@@ -2143,21 +2346,21 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
2143
2346
|
e.currentTarget.style.backgroundColor = "transparent";
|
|
2144
2347
|
},
|
|
2145
2348
|
title: "Close Chat",
|
|
2146
|
-
children: /* @__PURE__ */ (0,
|
|
2349
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react10.XIcon, { className: "h-4 w-4", strokeWidth: 2 })
|
|
2147
2350
|
}
|
|
2148
2351
|
)
|
|
2149
2352
|
] })
|
|
2150
2353
|
] }),
|
|
2151
|
-
/* @__PURE__ */ (0,
|
|
2152
|
-
/* @__PURE__ */ (0,
|
|
2354
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(Conversation, { className: "flex-1 max-w-full ai-assistant-scrollbar", children: [
|
|
2355
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(ConversationContent, { className: "max-w-[96%] mx-auto py-6", children: [
|
|
2153
2356
|
renderMessages(),
|
|
2154
|
-
status === "submitted" && /* @__PURE__ */ (0,
|
|
2357
|
+
status === "submitted" && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "mt-6", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Message, { from: "assistant", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(MessageContent, { children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Loader, { size: 16 }) }) }) })
|
|
2155
2358
|
] }),
|
|
2156
|
-
/* @__PURE__ */ (0,
|
|
2359
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ConversationScrollButton, {})
|
|
2157
2360
|
] }),
|
|
2158
|
-
/* @__PURE__ */ (0,
|
|
2159
|
-
uploadError && /* @__PURE__ */ (0,
|
|
2160
|
-
isInitializing || isLoadingMessages ? /* @__PURE__ */ (0,
|
|
2361
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "px-5 pb-5", children: [
|
|
2362
|
+
uploadError && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "mb-3 px-4 py-3 bg-red-50 dark:bg-red-900/20 border border-red-200/60 dark:border-red-800/60 rounded-2xl text-sm text-red-700 dark:text-red-400 shadow-sm", children: uploadError }),
|
|
2363
|
+
isInitializing || isLoadingMessages ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "flex items-center justify-center py-8", role: "status", "aria-label": "Loading conversation", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "h-4 w-4 rounded-full border-2 border-current border-t-transparent animate-spin", style: { color: "hsl(var(--chat-text-muted))" } }) }) : messages.length === 0 && status !== "submitted" && config?.starterPrompts && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2161
2364
|
StarterMessages,
|
|
2162
2365
|
{
|
|
2163
2366
|
prompts: config.starterPrompts,
|
|
@@ -2166,20 +2369,25 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
2166
2369
|
}
|
|
2167
2370
|
}
|
|
2168
2371
|
),
|
|
2169
|
-
/* @__PURE__ */ (0,
|
|
2170
|
-
/* @__PURE__ */ (0,
|
|
2171
|
-
/* @__PURE__ */ (0,
|
|
2172
|
-
/* @__PURE__ */ (0,
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2372
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(PromptInput, { onSubmit: handleSubmit, globalDrop: true, multiple: true, accept: "image/*", children: [
|
|
2373
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(PromptInputBody, { children: [
|
|
2374
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(PromptInputAttachments, { children: (attachment) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(PromptInputAttachment, { data: attachment }) }),
|
|
2375
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "relative", children: [
|
|
2376
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2377
|
+
PromptInputTextarea,
|
|
2378
|
+
{
|
|
2379
|
+
ref: inputRef,
|
|
2380
|
+
onChange: (e) => setInput(e.target.value),
|
|
2381
|
+
onKeyDown: inputPlugins.onKeyDown,
|
|
2382
|
+
value: input
|
|
2383
|
+
}
|
|
2384
|
+
),
|
|
2385
|
+
inputPlugins.popover
|
|
2386
|
+
] })
|
|
2179
2387
|
] }),
|
|
2180
|
-
/* @__PURE__ */ (0,
|
|
2181
|
-
/* @__PURE__ */ (0,
|
|
2182
|
-
/* @__PURE__ */ (0,
|
|
2388
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(PromptInputToolbar, { children: [
|
|
2389
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(PromptInputTools, { children: config?.features?.fileUpload === true && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(AttachButton, {}) }),
|
|
2390
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(PromptInputSubmit, { disabled: !input, status })
|
|
2183
2391
|
] })
|
|
2184
2392
|
] })
|
|
2185
2393
|
] })
|
|
@@ -2227,7 +2435,7 @@ function toHslTripletIfHex(value) {
|
|
|
2227
2435
|
}
|
|
2228
2436
|
|
|
2229
2437
|
// src/ChatWidget.tsx
|
|
2230
|
-
var
|
|
2438
|
+
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
2231
2439
|
function ChatWidget({
|
|
2232
2440
|
userId,
|
|
2233
2441
|
conversationId,
|
|
@@ -2250,7 +2458,7 @@ function ChatWidget({
|
|
|
2250
2458
|
const showToggleButton = !isControlled && display?.showToggleButton !== false;
|
|
2251
2459
|
const resizable = layout === "popup" && display?.resizable !== false;
|
|
2252
2460
|
const size = display?.size || "default";
|
|
2253
|
-
const [internalIsOpen, setInternalIsOpen] = (0,
|
|
2461
|
+
const [internalIsOpen, setInternalIsOpen] = (0, import_react13.useState)(
|
|
2254
2462
|
layout !== "popup" ? true : display?.defaultOpen || false
|
|
2255
2463
|
);
|
|
2256
2464
|
const isOpen = isControlled ? open : internalIsOpen;
|
|
@@ -2261,9 +2469,9 @@ function ChatWidget({
|
|
|
2261
2469
|
setInternalIsOpen(next);
|
|
2262
2470
|
}
|
|
2263
2471
|
};
|
|
2264
|
-
const [isResizing, setIsResizing] = (0,
|
|
2265
|
-
const containerRef = (0,
|
|
2266
|
-
const customStyles = (0,
|
|
2472
|
+
const [isResizing, setIsResizing] = (0, import_react13.useState)(false);
|
|
2473
|
+
const containerRef = (0, import_react13.useRef)(null);
|
|
2474
|
+
const customStyles = (0, import_react13.useMemo)(() => {
|
|
2267
2475
|
const styles = {};
|
|
2268
2476
|
if (display?.width) {
|
|
2269
2477
|
styles["--chat-widget-width"] = display.width;
|
|
@@ -2282,14 +2490,14 @@ function ChatWidget({
|
|
|
2282
2490
|
}
|
|
2283
2491
|
return styles;
|
|
2284
2492
|
}, [display?.width, theme?.primaryColor, theme?.backgroundColor, theme?.textColor, theme?.tokens]);
|
|
2285
|
-
const handleMouseDown = (0,
|
|
2493
|
+
const handleMouseDown = (0, import_react13.useCallback)((e) => {
|
|
2286
2494
|
if (!resizable) return;
|
|
2287
2495
|
e.preventDefault();
|
|
2288
2496
|
setIsResizing(true);
|
|
2289
2497
|
document.body.style.cursor = "ew-resize";
|
|
2290
2498
|
document.body.style.userSelect = "none";
|
|
2291
2499
|
}, [resizable]);
|
|
2292
|
-
(0,
|
|
2500
|
+
(0, import_react13.useEffect)(() => {
|
|
2293
2501
|
if (!isResizing) return;
|
|
2294
2502
|
const handleMouseMove = (e) => {
|
|
2295
2503
|
if (!containerRef.current) return;
|
|
@@ -2311,7 +2519,7 @@ function ChatWidget({
|
|
|
2311
2519
|
document.removeEventListener("mouseup", handleMouseUp);
|
|
2312
2520
|
};
|
|
2313
2521
|
}, [isResizing]);
|
|
2314
|
-
const config = (0,
|
|
2522
|
+
const config = (0, import_react13.useMemo)(() => ({
|
|
2315
2523
|
userId,
|
|
2316
2524
|
model,
|
|
2317
2525
|
systemPrompt,
|
|
@@ -2323,13 +2531,13 @@ function ChatWidget({
|
|
|
2323
2531
|
const togglePosition = display?.toggleButtonPosition || { bottom: "24px", right: "24px" };
|
|
2324
2532
|
const themeClass = theme?.mode === "dark" ? "dark" : "";
|
|
2325
2533
|
if (layout === "inline") {
|
|
2326
|
-
return /* @__PURE__ */ (0,
|
|
2534
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ChatStorageProvider, { userId, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2327
2535
|
"div",
|
|
2328
2536
|
{
|
|
2329
2537
|
ref: containerRef,
|
|
2330
2538
|
className: `chat-widget-container chat-widget-inline chat-widget-content ${themeClass} ${className || ""}`,
|
|
2331
2539
|
style: customStyles,
|
|
2332
|
-
children: /* @__PURE__ */ (0,
|
|
2540
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2333
2541
|
ChatInterface,
|
|
2334
2542
|
{
|
|
2335
2543
|
id: conversationId,
|
|
@@ -2343,13 +2551,13 @@ function ChatWidget({
|
|
|
2343
2551
|
) });
|
|
2344
2552
|
}
|
|
2345
2553
|
if (layout === "page") {
|
|
2346
|
-
return /* @__PURE__ */ (0,
|
|
2554
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ChatStorageProvider, { userId, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2347
2555
|
"div",
|
|
2348
2556
|
{
|
|
2349
2557
|
ref: containerRef,
|
|
2350
2558
|
className: `chat-widget-container chat-widget-page chat-widget-content ${themeClass} ${className || ""}`,
|
|
2351
2559
|
style: customStyles,
|
|
2352
|
-
children: /* @__PURE__ */ (0,
|
|
2560
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2353
2561
|
ChatInterface,
|
|
2354
2562
|
{
|
|
2355
2563
|
id: conversationId,
|
|
@@ -2362,18 +2570,18 @@ function ChatWidget({
|
|
|
2362
2570
|
}
|
|
2363
2571
|
) });
|
|
2364
2572
|
}
|
|
2365
|
-
return /* @__PURE__ */ (0,
|
|
2366
|
-
showToggleButton && !isOpen && /* @__PURE__ */ (0,
|
|
2573
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(ChatStorageProvider, { userId, children: [
|
|
2574
|
+
showToggleButton && !isOpen && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2367
2575
|
"button",
|
|
2368
2576
|
{
|
|
2369
2577
|
onClick: () => setIsOpen(true),
|
|
2370
2578
|
className: "fixed z-50 rounded-full bg-primary text-primary-foreground shadow-lg hover:opacity-90 transition-all p-4",
|
|
2371
2579
|
style: togglePosition,
|
|
2372
2580
|
"aria-label": "Open chat",
|
|
2373
|
-
children: /* @__PURE__ */ (0,
|
|
2581
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_lucide_react11.MessageCircle, { className: "h-6 w-6" })
|
|
2374
2582
|
}
|
|
2375
2583
|
),
|
|
2376
|
-
isOpen && /* @__PURE__ */ (0,
|
|
2584
|
+
isOpen && /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
|
|
2377
2585
|
"div",
|
|
2378
2586
|
{
|
|
2379
2587
|
ref: containerRef,
|
|
@@ -2382,7 +2590,7 @@ function ChatWidget({
|
|
|
2382
2590
|
"data-resizing": isResizing,
|
|
2383
2591
|
style: customStyles,
|
|
2384
2592
|
children: [
|
|
2385
|
-
resizable && /* @__PURE__ */ (0,
|
|
2593
|
+
resizable && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2386
2594
|
"div",
|
|
2387
2595
|
{
|
|
2388
2596
|
onMouseDown: handleMouseDown,
|
|
@@ -2390,7 +2598,7 @@ function ChatWidget({
|
|
|
2390
2598
|
"aria-label": "Resize chat widget"
|
|
2391
2599
|
}
|
|
2392
2600
|
),
|
|
2393
|
-
/* @__PURE__ */ (0,
|
|
2601
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "w-full h-full overflow-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2394
2602
|
ChatInterface,
|
|
2395
2603
|
{
|
|
2396
2604
|
id: conversationId,
|
|
@@ -2411,7 +2619,7 @@ function ChatWidget({
|
|
|
2411
2619
|
var ChatWidget_default = ChatWidget;
|
|
2412
2620
|
|
|
2413
2621
|
// src/hooks/use-chat-theme.ts
|
|
2414
|
-
var
|
|
2622
|
+
var import_react14 = require("react");
|
|
2415
2623
|
|
|
2416
2624
|
// src/utils/models.ts
|
|
2417
2625
|
var MODELS = [
|
|
@@ -2531,13 +2739,13 @@ var defaultThemeMode = "light";
|
|
|
2531
2739
|
function useChatTheme() {
|
|
2532
2740
|
const { storageKeyPrefix } = useChatStorageKey();
|
|
2533
2741
|
const keyPrefix = storageKeyPrefix ? `chat-${storageKeyPrefix}-` : "chat-";
|
|
2534
|
-
const [theme, setTheme] = (0,
|
|
2535
|
-
const [conversationStarters, setConversationStarters] = (0,
|
|
2536
|
-
const [model, setModel] = (0,
|
|
2537
|
-
const [systemPrompt, setSystemPrompt] = (0,
|
|
2538
|
-
const [temperature, setTemperature] = (0,
|
|
2539
|
-
const [themeMode, setThemeMode] = (0,
|
|
2540
|
-
(0,
|
|
2742
|
+
const [theme, setTheme] = (0, import_react14.useState)(defaultTheme);
|
|
2743
|
+
const [conversationStarters, setConversationStarters] = (0, import_react14.useState)(defaultConversationStarters);
|
|
2744
|
+
const [model, setModel] = (0, import_react14.useState)(defaultModel);
|
|
2745
|
+
const [systemPrompt, setSystemPrompt] = (0, import_react14.useState)(defaultSystemPrompt);
|
|
2746
|
+
const [temperature, setTemperature] = (0, import_react14.useState)(defaultTemperature);
|
|
2747
|
+
const [themeMode, setThemeMode] = (0, import_react14.useState)(defaultThemeMode);
|
|
2748
|
+
(0, import_react14.useEffect)(() => {
|
|
2541
2749
|
const savedTheme = localStorage.getItem(`${keyPrefix}theme`);
|
|
2542
2750
|
if (savedTheme) {
|
|
2543
2751
|
try {
|
|
@@ -2625,7 +2833,7 @@ function useChatTheme() {
|
|
|
2625
2833
|
window.removeEventListener("chat-theme-mode-change", handleThemeModeChange);
|
|
2626
2834
|
};
|
|
2627
2835
|
}, [keyPrefix]);
|
|
2628
|
-
(0,
|
|
2836
|
+
(0, import_react14.useEffect)(() => {
|
|
2629
2837
|
localStorage.setItem(`${keyPrefix}theme`, JSON.stringify(theme));
|
|
2630
2838
|
const root = document.documentElement;
|
|
2631
2839
|
if (themeMode === "light") {
|
|
@@ -2641,23 +2849,23 @@ function useChatTheme() {
|
|
|
2641
2849
|
root.style.setProperty("--chat-font-size", `${theme.fontSize}px`);
|
|
2642
2850
|
window.dispatchEvent(new CustomEvent("chat-theme-change", { detail: theme }));
|
|
2643
2851
|
}, [theme, themeMode, keyPrefix]);
|
|
2644
|
-
(0,
|
|
2852
|
+
(0, import_react14.useEffect)(() => {
|
|
2645
2853
|
localStorage.setItem(`${keyPrefix}conversation-starters`, JSON.stringify(conversationStarters));
|
|
2646
2854
|
window.dispatchEvent(new CustomEvent("chat-starters-change", { detail: conversationStarters }));
|
|
2647
2855
|
}, [conversationStarters, keyPrefix]);
|
|
2648
|
-
(0,
|
|
2856
|
+
(0, import_react14.useEffect)(() => {
|
|
2649
2857
|
localStorage.setItem(`${keyPrefix}model`, model);
|
|
2650
2858
|
window.dispatchEvent(new CustomEvent("chat-model-change", { detail: model }));
|
|
2651
2859
|
}, [model, keyPrefix]);
|
|
2652
|
-
(0,
|
|
2860
|
+
(0, import_react14.useEffect)(() => {
|
|
2653
2861
|
localStorage.setItem(`${keyPrefix}system-prompt`, systemPrompt);
|
|
2654
2862
|
window.dispatchEvent(new CustomEvent("chat-system-prompt-change", { detail: systemPrompt }));
|
|
2655
2863
|
}, [systemPrompt, keyPrefix]);
|
|
2656
|
-
(0,
|
|
2864
|
+
(0, import_react14.useEffect)(() => {
|
|
2657
2865
|
localStorage.setItem(`${keyPrefix}temperature`, temperature.toString());
|
|
2658
2866
|
window.dispatchEvent(new CustomEvent("chat-temperature-change", { detail: temperature }));
|
|
2659
2867
|
}, [temperature, keyPrefix]);
|
|
2660
|
-
(0,
|
|
2868
|
+
(0, import_react14.useEffect)(() => {
|
|
2661
2869
|
localStorage.setItem(`${keyPrefix}theme-mode`, themeMode);
|
|
2662
2870
|
window.dispatchEvent(new CustomEvent("chat-theme-mode-change", { detail: themeMode }));
|
|
2663
2871
|
}, [themeMode, keyPrefix]);
|
|
@@ -2726,11 +2934,11 @@ function useChatTheme() {
|
|
|
2726
2934
|
}
|
|
2727
2935
|
|
|
2728
2936
|
// src/ui/input.tsx
|
|
2729
|
-
var
|
|
2730
|
-
var
|
|
2731
|
-
var Input =
|
|
2937
|
+
var React2 = __toESM(require("react"));
|
|
2938
|
+
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
2939
|
+
var Input = React2.forwardRef(
|
|
2732
2940
|
({ className, type, ...props }, ref) => {
|
|
2733
|
-
return /* @__PURE__ */ (0,
|
|
2941
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
2734
2942
|
"input",
|
|
2735
2943
|
{
|
|
2736
2944
|
type,
|
|
@@ -2749,22 +2957,22 @@ Input.displayName = "Input";
|
|
|
2749
2957
|
// src/ui/dialog.tsx
|
|
2750
2958
|
var DialogPrimitive = __toESM(require("@radix-ui/react-dialog"));
|
|
2751
2959
|
var import_lucide_react12 = require("lucide-react");
|
|
2752
|
-
var
|
|
2960
|
+
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
2753
2961
|
function Dialog({
|
|
2754
2962
|
...props
|
|
2755
2963
|
}) {
|
|
2756
|
-
return /* @__PURE__ */ (0,
|
|
2964
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(DialogPrimitive.Root, { "data-slot": "dialog", ...props });
|
|
2757
2965
|
}
|
|
2758
2966
|
function DialogPortal({
|
|
2759
2967
|
...props
|
|
2760
2968
|
}) {
|
|
2761
|
-
return /* @__PURE__ */ (0,
|
|
2969
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(DialogPrimitive.Portal, { "data-slot": "dialog-portal", ...props });
|
|
2762
2970
|
}
|
|
2763
2971
|
function DialogOverlay({
|
|
2764
2972
|
className,
|
|
2765
2973
|
...props
|
|
2766
2974
|
}) {
|
|
2767
|
-
return /* @__PURE__ */ (0,
|
|
2975
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
2768
2976
|
DialogPrimitive.Overlay,
|
|
2769
2977
|
{
|
|
2770
2978
|
"data-slot": "dialog-overlay",
|
|
@@ -2782,9 +2990,9 @@ function DialogContent({
|
|
|
2782
2990
|
showCloseButton = true,
|
|
2783
2991
|
...props
|
|
2784
2992
|
}) {
|
|
2785
|
-
return /* @__PURE__ */ (0,
|
|
2786
|
-
/* @__PURE__ */ (0,
|
|
2787
|
-
/* @__PURE__ */ (0,
|
|
2993
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(DialogPortal, { "data-slot": "dialog-portal", children: [
|
|
2994
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(DialogOverlay, {}),
|
|
2995
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
|
|
2788
2996
|
DialogPrimitive.Content,
|
|
2789
2997
|
{
|
|
2790
2998
|
"data-slot": "dialog-content",
|
|
@@ -2795,14 +3003,14 @@ function DialogContent({
|
|
|
2795
3003
|
...props,
|
|
2796
3004
|
children: [
|
|
2797
3005
|
children,
|
|
2798
|
-
showCloseButton && /* @__PURE__ */ (0,
|
|
3006
|
+
showCloseButton && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
|
|
2799
3007
|
DialogPrimitive.Close,
|
|
2800
3008
|
{
|
|
2801
3009
|
"data-slot": "dialog-close",
|
|
2802
3010
|
className: "ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
2803
3011
|
children: [
|
|
2804
|
-
/* @__PURE__ */ (0,
|
|
2805
|
-
/* @__PURE__ */ (0,
|
|
3012
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react12.XIcon, {}),
|
|
3013
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { className: "sr-only", children: "Close" })
|
|
2806
3014
|
]
|
|
2807
3015
|
}
|
|
2808
3016
|
)
|
|
@@ -2812,7 +3020,7 @@ function DialogContent({
|
|
|
2812
3020
|
] });
|
|
2813
3021
|
}
|
|
2814
3022
|
function DialogHeader({ className, ...props }) {
|
|
2815
|
-
return /* @__PURE__ */ (0,
|
|
3023
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
2816
3024
|
"div",
|
|
2817
3025
|
{
|
|
2818
3026
|
"data-slot": "dialog-header",
|
|
@@ -2825,7 +3033,7 @@ function DialogTitle({
|
|
|
2825
3033
|
className,
|
|
2826
3034
|
...props
|
|
2827
3035
|
}) {
|
|
2828
|
-
return /* @__PURE__ */ (0,
|
|
3036
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
2829
3037
|
DialogPrimitive.Title,
|
|
2830
3038
|
{
|
|
2831
3039
|
"data-slot": "dialog-title",
|
|
@@ -2838,7 +3046,7 @@ function DialogDescription({
|
|
|
2838
3046
|
className,
|
|
2839
3047
|
...props
|
|
2840
3048
|
}) {
|
|
2841
|
-
return /* @__PURE__ */ (0,
|
|
3049
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
2842
3050
|
DialogPrimitive.Description,
|
|
2843
3051
|
{
|
|
2844
3052
|
"data-slot": "dialog-description",
|