@mordn/chat-widget 0.5.1 → 0.6.1
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 +64 -2
- package/dist/index.d.ts +64 -2
- package/dist/index.js +485 -275
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +469 -259
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
|
|
4
4
|
// src/ChatWidget.tsx
|
|
5
|
-
import { useCallback as
|
|
5
|
+
import { useCallback as useCallback5, useEffect as useEffect6, useMemo as useMemo4, useRef as useRef5, useState as useState6 } from "react";
|
|
6
6
|
|
|
7
7
|
// src/ui/button.tsx
|
|
8
8
|
import { Slot } from "@radix-ui/react-slot";
|
|
@@ -197,7 +197,7 @@ import {
|
|
|
197
197
|
XIcon
|
|
198
198
|
} from "lucide-react";
|
|
199
199
|
import { nanoid } from "nanoid";
|
|
200
|
-
import {
|
|
200
|
+
import React, {
|
|
201
201
|
Children,
|
|
202
202
|
createContext,
|
|
203
203
|
Fragment as Fragment2,
|
|
@@ -509,14 +509,17 @@ var PromptInputBody = ({
|
|
|
509
509
|
className,
|
|
510
510
|
...props
|
|
511
511
|
}) => /* @__PURE__ */ jsx8("div", { className: cn(className, "flex flex-col"), ...props });
|
|
512
|
-
var PromptInputTextarea = ({
|
|
512
|
+
var PromptInputTextarea = React.forwardRef(({
|
|
513
513
|
onChange,
|
|
514
|
+
onKeyDown: externalOnKeyDown,
|
|
514
515
|
className,
|
|
515
516
|
placeholder = "What would you like to know?",
|
|
516
517
|
...props
|
|
517
|
-
}) => {
|
|
518
|
+
}, ref) => {
|
|
518
519
|
const attachments = usePromptInputAttachments();
|
|
519
520
|
const handleKeyDown = (e) => {
|
|
521
|
+
externalOnKeyDown?.(e);
|
|
522
|
+
if (e.defaultPrevented) return;
|
|
520
523
|
if (e.key === "Enter") {
|
|
521
524
|
if (e.nativeEvent.isComposing) {
|
|
522
525
|
return;
|
|
@@ -553,6 +556,7 @@ var PromptInputTextarea = ({
|
|
|
553
556
|
return /* @__PURE__ */ jsx8(
|
|
554
557
|
Textarea,
|
|
555
558
|
{
|
|
559
|
+
ref,
|
|
556
560
|
className: cn(
|
|
557
561
|
"w-full resize-none rounded-none border-none p-3 shadow-none outline-none ring-0",
|
|
558
562
|
"field-sizing-content",
|
|
@@ -570,7 +574,8 @@ var PromptInputTextarea = ({
|
|
|
570
574
|
...props
|
|
571
575
|
}
|
|
572
576
|
);
|
|
573
|
-
};
|
|
577
|
+
});
|
|
578
|
+
PromptInputTextarea.displayName = "PromptInputTextarea";
|
|
574
579
|
var PromptInputToolbar = ({
|
|
575
580
|
className,
|
|
576
581
|
...props
|
|
@@ -701,8 +706,199 @@ function MessageAttachments({ attachments, className }) {
|
|
|
701
706
|
)) });
|
|
702
707
|
}
|
|
703
708
|
|
|
709
|
+
// src/components/input-plugin-popover.tsx
|
|
710
|
+
import { useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
|
|
711
|
+
import { jsx as jsx10, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
712
|
+
var FETCH_DEBOUNCE_MS = 120;
|
|
713
|
+
function useInputPlugins({ textareaRef, value, setValue, plugins }) {
|
|
714
|
+
const [active, setActive] = useState2(null);
|
|
715
|
+
const [items, setItems] = useState2([]);
|
|
716
|
+
const [highlight, setHighlight] = useState2(0);
|
|
717
|
+
const [loading, setLoading] = useState2(false);
|
|
718
|
+
const debounceRef = useRef2(null);
|
|
719
|
+
const requestIdRef = useRef2(0);
|
|
720
|
+
const pluginsByTrigger = useMemo2(() => {
|
|
721
|
+
const map = /* @__PURE__ */ new Map();
|
|
722
|
+
for (const p of plugins ?? []) {
|
|
723
|
+
if (p.trigger.length === 1) map.set(p.trigger, p);
|
|
724
|
+
}
|
|
725
|
+
return map;
|
|
726
|
+
}, [plugins]);
|
|
727
|
+
const query = useMemo2(() => {
|
|
728
|
+
if (!active) return "";
|
|
729
|
+
const ta = textareaRef.current;
|
|
730
|
+
if (!ta) return "";
|
|
731
|
+
const cursor = ta.selectionEnd ?? value.length;
|
|
732
|
+
if (cursor <= active.triggerIndex) return "";
|
|
733
|
+
return value.slice(active.triggerIndex + 1, cursor);
|
|
734
|
+
}, [active, value, textareaRef]);
|
|
735
|
+
useEffect2(() => {
|
|
736
|
+
if (!active) return;
|
|
737
|
+
const ta = textareaRef.current;
|
|
738
|
+
if (!ta) return;
|
|
739
|
+
if (value[active.triggerIndex] !== active.plugin.trigger) {
|
|
740
|
+
setActive(null);
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
if (/\s/.test(query)) {
|
|
744
|
+
setActive(null);
|
|
745
|
+
}
|
|
746
|
+
}, [active, value, query, textareaRef]);
|
|
747
|
+
useEffect2(() => {
|
|
748
|
+
if (!active) {
|
|
749
|
+
setItems([]);
|
|
750
|
+
setLoading(false);
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
754
|
+
setLoading(true);
|
|
755
|
+
const reqId = ++requestIdRef.current;
|
|
756
|
+
debounceRef.current = setTimeout(async () => {
|
|
757
|
+
try {
|
|
758
|
+
const result = await active.plugin.fetch(query);
|
|
759
|
+
if (reqId !== requestIdRef.current) return;
|
|
760
|
+
setItems(result);
|
|
761
|
+
setHighlight(0);
|
|
762
|
+
} catch (err) {
|
|
763
|
+
console.error("[input-plugin] fetch failed:", err);
|
|
764
|
+
if (reqId !== requestIdRef.current) return;
|
|
765
|
+
setItems([]);
|
|
766
|
+
} finally {
|
|
767
|
+
if (reqId === requestIdRef.current) setLoading(false);
|
|
768
|
+
}
|
|
769
|
+
}, FETCH_DEBOUNCE_MS);
|
|
770
|
+
return () => {
|
|
771
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
772
|
+
};
|
|
773
|
+
}, [active, query]);
|
|
774
|
+
const close = useCallback3(() => {
|
|
775
|
+
setActive(null);
|
|
776
|
+
setItems([]);
|
|
777
|
+
setHighlight(0);
|
|
778
|
+
}, []);
|
|
779
|
+
const selectItem = useCallback3(
|
|
780
|
+
(item) => {
|
|
781
|
+
if (!active) return;
|
|
782
|
+
const ta = textareaRef.current;
|
|
783
|
+
const cursor = ta?.selectionEnd ?? value.length;
|
|
784
|
+
const replacement = active.plugin.onSelect(item);
|
|
785
|
+
const before = value.slice(0, active.triggerIndex);
|
|
786
|
+
const after = value.slice(cursor);
|
|
787
|
+
const next = `${before}${replacement}${after}`;
|
|
788
|
+
setValue(next);
|
|
789
|
+
const newCursor = before.length + replacement.length;
|
|
790
|
+
setTimeout(() => {
|
|
791
|
+
const t = textareaRef.current;
|
|
792
|
+
if (!t) return;
|
|
793
|
+
t.focus();
|
|
794
|
+
try {
|
|
795
|
+
t.setSelectionRange(newCursor, newCursor);
|
|
796
|
+
} catch {
|
|
797
|
+
}
|
|
798
|
+
}, 0);
|
|
799
|
+
close();
|
|
800
|
+
},
|
|
801
|
+
[active, value, setValue, close, textareaRef]
|
|
802
|
+
);
|
|
803
|
+
const onKeyDown = useCallback3(
|
|
804
|
+
(e) => {
|
|
805
|
+
if (active) {
|
|
806
|
+
if (e.key === "ArrowDown") {
|
|
807
|
+
e.preventDefault();
|
|
808
|
+
setHighlight((h) => items.length === 0 ? 0 : (h + 1) % items.length);
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
if (e.key === "ArrowUp") {
|
|
812
|
+
e.preventDefault();
|
|
813
|
+
setHighlight((h) => items.length === 0 ? 0 : (h - 1 + items.length) % items.length);
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
if (e.key === "Enter") {
|
|
817
|
+
if (items.length > 0) {
|
|
818
|
+
e.preventDefault();
|
|
819
|
+
selectItem(items[highlight]);
|
|
820
|
+
}
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
if (e.key === "Escape") {
|
|
824
|
+
e.preventDefault();
|
|
825
|
+
close();
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
if (e.key.length === 1 && pluginsByTrigger.has(e.key) && !e.metaKey && !e.ctrlKey && !e.altKey) {
|
|
830
|
+
const ta = e.currentTarget;
|
|
831
|
+
const cursor = ta.selectionStart ?? value.length;
|
|
832
|
+
const prevChar = cursor > 0 ? value[cursor - 1] : "";
|
|
833
|
+
if (cursor === 0 || /\s/.test(prevChar)) {
|
|
834
|
+
const plugin = pluginsByTrigger.get(e.key);
|
|
835
|
+
setActive({ plugin, triggerIndex: cursor });
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
},
|
|
839
|
+
[active, items, highlight, selectItem, close, pluginsByTrigger, value]
|
|
840
|
+
);
|
|
841
|
+
useEffect2(() => {
|
|
842
|
+
if (!active) return;
|
|
843
|
+
if (value[active.triggerIndex] !== active.plugin.trigger) {
|
|
844
|
+
close();
|
|
845
|
+
}
|
|
846
|
+
}, [value, active, close]);
|
|
847
|
+
const popover = active && (loading || items.length > 0 || active.plugin.emptyText) ? /* @__PURE__ */ jsx10(
|
|
848
|
+
PluginPopover,
|
|
849
|
+
{
|
|
850
|
+
plugin: active.plugin,
|
|
851
|
+
items,
|
|
852
|
+
loading,
|
|
853
|
+
highlight,
|
|
854
|
+
onHover: setHighlight,
|
|
855
|
+
onSelect: selectItem
|
|
856
|
+
}
|
|
857
|
+
) : null;
|
|
858
|
+
return { onKeyDown, popover, isOpen: !!active };
|
|
859
|
+
}
|
|
860
|
+
function PluginPopover({ plugin, items, loading, highlight, onHover, onSelect }) {
|
|
861
|
+
return /* @__PURE__ */ jsxs6(
|
|
862
|
+
"div",
|
|
863
|
+
{
|
|
864
|
+
role: "listbox",
|
|
865
|
+
className: cn(
|
|
866
|
+
"absolute bottom-full left-0 right-0 mb-2 z-30",
|
|
867
|
+
"rounded-md border border-border bg-popover text-popover-foreground shadow-md",
|
|
868
|
+
"max-h-64 overflow-y-auto"
|
|
869
|
+
),
|
|
870
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
871
|
+
children: [
|
|
872
|
+
plugin.heading && /* @__PURE__ */ jsx10("div", { className: "px-3 py-1.5 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground border-b border-border", children: plugin.heading }),
|
|
873
|
+
loading && items.length === 0 && /* @__PURE__ */ jsx10("div", { className: "px-3 py-2 text-xs text-muted-foreground", children: "Loading\u2026" }),
|
|
874
|
+
!loading && items.length === 0 && /* @__PURE__ */ jsx10("div", { className: "px-3 py-2 text-xs text-muted-foreground", children: plugin.emptyText ?? "No results" }),
|
|
875
|
+
items.map((item, idx) => /* @__PURE__ */ jsxs6(
|
|
876
|
+
"button",
|
|
877
|
+
{
|
|
878
|
+
type: "button",
|
|
879
|
+
role: "option",
|
|
880
|
+
"aria-selected": idx === highlight,
|
|
881
|
+
onMouseEnter: () => onHover(idx),
|
|
882
|
+
onClick: () => onSelect(item),
|
|
883
|
+
className: cn(
|
|
884
|
+
"w-full text-left px-3 py-2 text-sm transition-colors",
|
|
885
|
+
"flex flex-col gap-0.5",
|
|
886
|
+
idx === highlight ? "bg-accent text-accent-foreground" : "hover:bg-muted"
|
|
887
|
+
),
|
|
888
|
+
children: [
|
|
889
|
+
/* @__PURE__ */ jsx10("span", { className: "font-medium leading-tight", children: item.label }),
|
|
890
|
+
item.sublabel && /* @__PURE__ */ jsx10("span", { className: "text-[11px] text-muted-foreground leading-tight", children: item.sublabel })
|
|
891
|
+
]
|
|
892
|
+
},
|
|
893
|
+
item.id
|
|
894
|
+
))
|
|
895
|
+
]
|
|
896
|
+
}
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
|
|
704
900
|
// src/components/interface.tsx
|
|
705
|
-
import { useState as
|
|
901
|
+
import { useState as useState5, useEffect as useEffect5, useRef as useRef4, useMemo as useMemo3, useCallback as useCallback4 } from "react";
|
|
706
902
|
import { HistoryIcon, MessageSquareIcon, SearchIcon, ChevronRightIcon as ChevronRightIcon2, PlusIcon as PlusIcon2, XIcon as XIcon2 } from "lucide-react";
|
|
707
903
|
import { Fragment as Fragment5 } from "react";
|
|
708
904
|
import { useChat } from "@ai-sdk/react";
|
|
@@ -713,11 +909,11 @@ import { memo } from "react";
|
|
|
713
909
|
import { Streamdown } from "streamdown";
|
|
714
910
|
|
|
715
911
|
// src/hooks/use-code-scroll.ts
|
|
716
|
-
import { useEffect as
|
|
912
|
+
import { useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
717
913
|
function useCodeBlockAutoScroll(isStreaming) {
|
|
718
|
-
const observerRef =
|
|
719
|
-
const containerRef =
|
|
720
|
-
|
|
914
|
+
const observerRef = useRef3(null);
|
|
915
|
+
const containerRef = useRef3(null);
|
|
916
|
+
useEffect3(() => {
|
|
721
917
|
if (!isStreaming || !containerRef.current) {
|
|
722
918
|
if (observerRef.current) {
|
|
723
919
|
observerRef.current.disconnect();
|
|
@@ -747,11 +943,11 @@ function useCodeBlockAutoScroll(isStreaming) {
|
|
|
747
943
|
}
|
|
748
944
|
|
|
749
945
|
// src/components/response.tsx
|
|
750
|
-
import { jsx as
|
|
946
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
751
947
|
var Response = memo(
|
|
752
948
|
({ className, isStreaming = false, ...props }) => {
|
|
753
949
|
const containerRef = useCodeBlockAutoScroll(isStreaming);
|
|
754
|
-
return /* @__PURE__ */
|
|
950
|
+
return /* @__PURE__ */ jsx11("div", { ref: containerRef, children: /* @__PURE__ */ jsx11(
|
|
755
951
|
Streamdown,
|
|
756
952
|
{
|
|
757
953
|
className: cn(
|
|
@@ -768,16 +964,16 @@ Response.displayName = "Response";
|
|
|
768
964
|
|
|
769
965
|
// src/ui/collapsible.tsx
|
|
770
966
|
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
|
|
771
|
-
import { jsx as
|
|
967
|
+
import { jsx as jsx12 } from "react/jsx-runtime";
|
|
772
968
|
function Collapsible({
|
|
773
969
|
...props
|
|
774
970
|
}) {
|
|
775
|
-
return /* @__PURE__ */
|
|
971
|
+
return /* @__PURE__ */ jsx12(CollapsiblePrimitive.Root, { "data-slot": "collapsible", ...props });
|
|
776
972
|
}
|
|
777
973
|
function CollapsibleTrigger2({
|
|
778
974
|
...props
|
|
779
975
|
}) {
|
|
780
|
-
return /* @__PURE__ */
|
|
976
|
+
return /* @__PURE__ */ jsx12(
|
|
781
977
|
CollapsiblePrimitive.CollapsibleTrigger,
|
|
782
978
|
{
|
|
783
979
|
"data-slot": "collapsible-trigger",
|
|
@@ -788,7 +984,7 @@ function CollapsibleTrigger2({
|
|
|
788
984
|
function CollapsibleContent2({
|
|
789
985
|
...props
|
|
790
986
|
}) {
|
|
791
|
-
return /* @__PURE__ */
|
|
987
|
+
return /* @__PURE__ */ jsx12(
|
|
792
988
|
CollapsiblePrimitive.CollapsibleContent,
|
|
793
989
|
{
|
|
794
990
|
"data-slot": "collapsible-content",
|
|
@@ -799,8 +995,8 @@ function CollapsibleContent2({
|
|
|
799
995
|
|
|
800
996
|
// src/components/sources.tsx
|
|
801
997
|
import { BookIcon, ChevronDownIcon as ChevronDownIcon2 } from "lucide-react";
|
|
802
|
-
import { Fragment as Fragment3, jsx as
|
|
803
|
-
var Sources = ({ className, ...props }) => /* @__PURE__ */
|
|
998
|
+
import { Fragment as Fragment3, jsx as jsx13, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
999
|
+
var Sources = ({ className, ...props }) => /* @__PURE__ */ jsx13(
|
|
804
1000
|
Collapsible,
|
|
805
1001
|
{
|
|
806
1002
|
className: cn("not-prose mb-4 text-primary text-xs", className),
|
|
@@ -812,25 +1008,25 @@ var SourcesTrigger = ({
|
|
|
812
1008
|
count,
|
|
813
1009
|
children,
|
|
814
1010
|
...props
|
|
815
|
-
}) => /* @__PURE__ */
|
|
1011
|
+
}) => /* @__PURE__ */ jsx13(
|
|
816
1012
|
CollapsibleTrigger2,
|
|
817
1013
|
{
|
|
818
1014
|
className: cn("flex items-center gap-2", className),
|
|
819
1015
|
...props,
|
|
820
|
-
children: children ?? /* @__PURE__ */
|
|
821
|
-
/* @__PURE__ */
|
|
1016
|
+
children: children ?? /* @__PURE__ */ jsxs7(Fragment3, { children: [
|
|
1017
|
+
/* @__PURE__ */ jsxs7("p", { className: "font-medium", children: [
|
|
822
1018
|
"Used ",
|
|
823
1019
|
count,
|
|
824
1020
|
" sources"
|
|
825
1021
|
] }),
|
|
826
|
-
/* @__PURE__ */
|
|
1022
|
+
/* @__PURE__ */ jsx13(ChevronDownIcon2, { className: "h-4 w-4" })
|
|
827
1023
|
] })
|
|
828
1024
|
}
|
|
829
1025
|
);
|
|
830
1026
|
var SourcesContent = ({
|
|
831
1027
|
className,
|
|
832
1028
|
...props
|
|
833
|
-
}) => /* @__PURE__ */
|
|
1029
|
+
}) => /* @__PURE__ */ jsx13(
|
|
834
1030
|
CollapsibleContent2,
|
|
835
1031
|
{
|
|
836
1032
|
className: cn(
|
|
@@ -841,7 +1037,7 @@ var SourcesContent = ({
|
|
|
841
1037
|
...props
|
|
842
1038
|
}
|
|
843
1039
|
);
|
|
844
|
-
var Source = ({ href, title, children, ...props }) => /* @__PURE__ */
|
|
1040
|
+
var Source = ({ href, title, children, ...props }) => /* @__PURE__ */ jsx13(
|
|
845
1041
|
"a",
|
|
846
1042
|
{
|
|
847
1043
|
className: "flex items-center gap-2",
|
|
@@ -849,9 +1045,9 @@ var Source = ({ href, title, children, ...props }) => /* @__PURE__ */ jsx12(
|
|
|
849
1045
|
rel: "noreferrer",
|
|
850
1046
|
target: "_blank",
|
|
851
1047
|
...props,
|
|
852
|
-
children: children ?? /* @__PURE__ */
|
|
853
|
-
/* @__PURE__ */
|
|
854
|
-
/* @__PURE__ */
|
|
1048
|
+
children: children ?? /* @__PURE__ */ jsxs7(Fragment3, { children: [
|
|
1049
|
+
/* @__PURE__ */ jsx13(BookIcon, { className: "h-4 w-4" }),
|
|
1050
|
+
/* @__PURE__ */ jsx13("span", { className: "block font-medium", children: title })
|
|
855
1051
|
] })
|
|
856
1052
|
}
|
|
857
1053
|
);
|
|
@@ -859,8 +1055,8 @@ var Source = ({ href, title, children, ...props }) => /* @__PURE__ */ jsx12(
|
|
|
859
1055
|
// src/components/reasoning.tsx
|
|
860
1056
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
861
1057
|
import { BrainIcon, ChevronDownIcon as ChevronDownIcon3 } from "lucide-react";
|
|
862
|
-
import { createContext as createContext2, memo as memo2, useContext as useContext2, useEffect as
|
|
863
|
-
import { Fragment as Fragment4, jsx as
|
|
1058
|
+
import { createContext as createContext2, memo as memo2, useContext as useContext2, useEffect as useEffect4, useState as useState3 } from "react";
|
|
1059
|
+
import { Fragment as Fragment4, jsx as jsx14, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
864
1060
|
var ReasoningContext = createContext2(null);
|
|
865
1061
|
var useReasoning = () => {
|
|
866
1062
|
const context = useContext2(ReasoningContext);
|
|
@@ -891,9 +1087,9 @@ var Reasoning = memo2(
|
|
|
891
1087
|
prop: durationProp,
|
|
892
1088
|
defaultProp: void 0
|
|
893
1089
|
});
|
|
894
|
-
const [hasAutoClosed, setHasAutoClosed] =
|
|
895
|
-
const [startTime, setStartTime] =
|
|
896
|
-
|
|
1090
|
+
const [hasAutoClosed, setHasAutoClosed] = useState3(false);
|
|
1091
|
+
const [startTime, setStartTime] = useState3(null);
|
|
1092
|
+
useEffect4(() => {
|
|
897
1093
|
if (isStreaming) {
|
|
898
1094
|
if (startTime === null) {
|
|
899
1095
|
setStartTime(Date.now());
|
|
@@ -903,7 +1099,7 @@ var Reasoning = memo2(
|
|
|
903
1099
|
setStartTime(null);
|
|
904
1100
|
}
|
|
905
1101
|
}, [isStreaming, startTime, setDuration]);
|
|
906
|
-
|
|
1102
|
+
useEffect4(() => {
|
|
907
1103
|
if (defaultOpen && !isStreaming && isOpen && !hasAutoClosed && durationProp !== void 0) {
|
|
908
1104
|
const timer = setTimeout(() => {
|
|
909
1105
|
setIsOpen(false);
|
|
@@ -915,11 +1111,11 @@ var Reasoning = memo2(
|
|
|
915
1111
|
const handleOpenChange = (newOpen) => {
|
|
916
1112
|
setIsOpen(newOpen);
|
|
917
1113
|
};
|
|
918
|
-
return /* @__PURE__ */
|
|
1114
|
+
return /* @__PURE__ */ jsx14(
|
|
919
1115
|
ReasoningContext.Provider,
|
|
920
1116
|
{
|
|
921
1117
|
value: { isStreaming, isOpen, setIsOpen, duration },
|
|
922
|
-
children: /* @__PURE__ */
|
|
1118
|
+
children: /* @__PURE__ */ jsx14(
|
|
923
1119
|
Collapsible,
|
|
924
1120
|
{
|
|
925
1121
|
className: cn("not-prose", className),
|
|
@@ -935,15 +1131,15 @@ var Reasoning = memo2(
|
|
|
935
1131
|
);
|
|
936
1132
|
var getThinkingMessage = (isStreaming, duration) => {
|
|
937
1133
|
if (isStreaming) {
|
|
938
|
-
return /* @__PURE__ */
|
|
1134
|
+
return /* @__PURE__ */ jsx14(Fragment4, { children: "Thinking..." });
|
|
939
1135
|
}
|
|
940
1136
|
if (duration === void 0) {
|
|
941
|
-
return /* @__PURE__ */
|
|
1137
|
+
return /* @__PURE__ */ jsx14(Fragment4, { children: "Thought process" });
|
|
942
1138
|
}
|
|
943
1139
|
if (duration === 0) {
|
|
944
|
-
return /* @__PURE__ */
|
|
1140
|
+
return /* @__PURE__ */ jsx14(Fragment4, { children: "Thought process" });
|
|
945
1141
|
}
|
|
946
|
-
return /* @__PURE__ */
|
|
1142
|
+
return /* @__PURE__ */ jsxs8(Fragment4, { children: [
|
|
947
1143
|
"Thought for ",
|
|
948
1144
|
duration,
|
|
949
1145
|
" seconds"
|
|
@@ -952,7 +1148,7 @@ var getThinkingMessage = (isStreaming, duration) => {
|
|
|
952
1148
|
var ReasoningTrigger = memo2(
|
|
953
1149
|
({ className, children, ...props }) => {
|
|
954
1150
|
const { isStreaming, isOpen, duration } = useReasoning();
|
|
955
|
-
return /* @__PURE__ */
|
|
1151
|
+
return /* @__PURE__ */ jsx14(
|
|
956
1152
|
CollapsibleTrigger2,
|
|
957
1153
|
{
|
|
958
1154
|
className: cn(
|
|
@@ -960,10 +1156,10 @@ var ReasoningTrigger = memo2(
|
|
|
960
1156
|
className
|
|
961
1157
|
),
|
|
962
1158
|
...props,
|
|
963
|
-
children: children ?? /* @__PURE__ */
|
|
964
|
-
/* @__PURE__ */
|
|
1159
|
+
children: children ?? /* @__PURE__ */ jsxs8(Fragment4, { children: [
|
|
1160
|
+
/* @__PURE__ */ jsx14(BrainIcon, { className: "size-4 flex-shrink-0" }),
|
|
965
1161
|
getThinkingMessage(isStreaming, duration),
|
|
966
|
-
/* @__PURE__ */
|
|
1162
|
+
/* @__PURE__ */ jsx14(
|
|
967
1163
|
ChevronDownIcon3,
|
|
968
1164
|
{
|
|
969
1165
|
className: cn(
|
|
@@ -978,7 +1174,7 @@ var ReasoningTrigger = memo2(
|
|
|
978
1174
|
}
|
|
979
1175
|
);
|
|
980
1176
|
var ReasoningContent = memo2(
|
|
981
|
-
({ className, children, ...props }) => /* @__PURE__ */
|
|
1177
|
+
({ className, children, ...props }) => /* @__PURE__ */ jsx14(
|
|
982
1178
|
CollapsibleContent2,
|
|
983
1179
|
{
|
|
984
1180
|
className: cn(
|
|
@@ -987,7 +1183,7 @@ var ReasoningContent = memo2(
|
|
|
987
1183
|
className
|
|
988
1184
|
),
|
|
989
1185
|
...props,
|
|
990
|
-
children: /* @__PURE__ */
|
|
1186
|
+
children: /* @__PURE__ */ jsx14(Response, { className: "grid gap-2", children })
|
|
991
1187
|
}
|
|
992
1188
|
)
|
|
993
1189
|
);
|
|
@@ -996,8 +1192,8 @@ ReasoningTrigger.displayName = "ReasoningTrigger";
|
|
|
996
1192
|
ReasoningContent.displayName = "ReasoningContent";
|
|
997
1193
|
|
|
998
1194
|
// src/components/loader.tsx
|
|
999
|
-
import { jsx as
|
|
1000
|
-
var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */
|
|
1195
|
+
import { jsx as jsx15, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1196
|
+
var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ jsxs9(
|
|
1001
1197
|
"svg",
|
|
1002
1198
|
{
|
|
1003
1199
|
height: size,
|
|
@@ -1006,10 +1202,10 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ jsxs8(
|
|
|
1006
1202
|
viewBox: "0 0 16 16",
|
|
1007
1203
|
width: size,
|
|
1008
1204
|
children: [
|
|
1009
|
-
/* @__PURE__ */
|
|
1010
|
-
/* @__PURE__ */
|
|
1011
|
-
/* @__PURE__ */
|
|
1012
|
-
/* @__PURE__ */
|
|
1205
|
+
/* @__PURE__ */ jsx15("title", { children: "Loader" }),
|
|
1206
|
+
/* @__PURE__ */ jsxs9("g", { clipPath: "url(#clip0_2393_1490)", children: [
|
|
1207
|
+
/* @__PURE__ */ jsx15("path", { d: "M8 0V4", stroke: "currentColor", strokeWidth: "1.5" }),
|
|
1208
|
+
/* @__PURE__ */ jsx15(
|
|
1013
1209
|
"path",
|
|
1014
1210
|
{
|
|
1015
1211
|
d: "M8 16V12",
|
|
@@ -1018,7 +1214,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ jsxs8(
|
|
|
1018
1214
|
strokeWidth: "1.5"
|
|
1019
1215
|
}
|
|
1020
1216
|
),
|
|
1021
|
-
/* @__PURE__ */
|
|
1217
|
+
/* @__PURE__ */ jsx15(
|
|
1022
1218
|
"path",
|
|
1023
1219
|
{
|
|
1024
1220
|
d: "M3.29773 1.52783L5.64887 4.7639",
|
|
@@ -1027,7 +1223,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ jsxs8(
|
|
|
1027
1223
|
strokeWidth: "1.5"
|
|
1028
1224
|
}
|
|
1029
1225
|
),
|
|
1030
|
-
/* @__PURE__ */
|
|
1226
|
+
/* @__PURE__ */ jsx15(
|
|
1031
1227
|
"path",
|
|
1032
1228
|
{
|
|
1033
1229
|
d: "M12.7023 1.52783L10.3511 4.7639",
|
|
@@ -1036,7 +1232,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ jsxs8(
|
|
|
1036
1232
|
strokeWidth: "1.5"
|
|
1037
1233
|
}
|
|
1038
1234
|
),
|
|
1039
|
-
/* @__PURE__ */
|
|
1235
|
+
/* @__PURE__ */ jsx15(
|
|
1040
1236
|
"path",
|
|
1041
1237
|
{
|
|
1042
1238
|
d: "M12.7023 14.472L10.3511 11.236",
|
|
@@ -1045,7 +1241,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ jsxs8(
|
|
|
1045
1241
|
strokeWidth: "1.5"
|
|
1046
1242
|
}
|
|
1047
1243
|
),
|
|
1048
|
-
/* @__PURE__ */
|
|
1244
|
+
/* @__PURE__ */ jsx15(
|
|
1049
1245
|
"path",
|
|
1050
1246
|
{
|
|
1051
1247
|
d: "M3.29773 14.472L5.64887 11.236",
|
|
@@ -1054,7 +1250,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ jsxs8(
|
|
|
1054
1250
|
strokeWidth: "1.5"
|
|
1055
1251
|
}
|
|
1056
1252
|
),
|
|
1057
|
-
/* @__PURE__ */
|
|
1253
|
+
/* @__PURE__ */ jsx15(
|
|
1058
1254
|
"path",
|
|
1059
1255
|
{
|
|
1060
1256
|
d: "M15.6085 5.52783L11.8043 6.7639",
|
|
@@ -1063,7 +1259,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ jsxs8(
|
|
|
1063
1259
|
strokeWidth: "1.5"
|
|
1064
1260
|
}
|
|
1065
1261
|
),
|
|
1066
|
-
/* @__PURE__ */
|
|
1262
|
+
/* @__PURE__ */ jsx15(
|
|
1067
1263
|
"path",
|
|
1068
1264
|
{
|
|
1069
1265
|
d: "M0.391602 10.472L4.19583 9.23598",
|
|
@@ -1072,7 +1268,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ jsxs8(
|
|
|
1072
1268
|
strokeWidth: "1.5"
|
|
1073
1269
|
}
|
|
1074
1270
|
),
|
|
1075
|
-
/* @__PURE__ */
|
|
1271
|
+
/* @__PURE__ */ jsx15(
|
|
1076
1272
|
"path",
|
|
1077
1273
|
{
|
|
1078
1274
|
d: "M15.6085 10.4722L11.8043 9.2361",
|
|
@@ -1081,7 +1277,7 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ jsxs8(
|
|
|
1081
1277
|
strokeWidth: "1.5"
|
|
1082
1278
|
}
|
|
1083
1279
|
),
|
|
1084
|
-
/* @__PURE__ */
|
|
1280
|
+
/* @__PURE__ */ jsx15(
|
|
1085
1281
|
"path",
|
|
1086
1282
|
{
|
|
1087
1283
|
d: "M0.391602 5.52783L4.19583 6.7639",
|
|
@@ -1091,11 +1287,11 @@ var LoaderIcon = ({ size = 16 }) => /* @__PURE__ */ jsxs8(
|
|
|
1091
1287
|
}
|
|
1092
1288
|
)
|
|
1093
1289
|
] }),
|
|
1094
|
-
/* @__PURE__ */
|
|
1290
|
+
/* @__PURE__ */ jsx15("defs", { children: /* @__PURE__ */ jsx15("clipPath", { id: "clip0_2393_1490", children: /* @__PURE__ */ jsx15("rect", { fill: "white", height: "16", width: "16" }) }) })
|
|
1095
1291
|
]
|
|
1096
1292
|
}
|
|
1097
1293
|
);
|
|
1098
|
-
var Loader = ({ className, size = 16, ...props }) => /* @__PURE__ */
|
|
1294
|
+
var Loader = ({ className, size = 16, ...props }) => /* @__PURE__ */ jsx15(
|
|
1099
1295
|
"div",
|
|
1100
1296
|
{
|
|
1101
1297
|
className: cn(
|
|
@@ -1103,14 +1299,14 @@ var Loader = ({ className, size = 16, ...props }) => /* @__PURE__ */ jsx14(
|
|
|
1103
1299
|
className
|
|
1104
1300
|
),
|
|
1105
1301
|
...props,
|
|
1106
|
-
children: /* @__PURE__ */
|
|
1302
|
+
children: /* @__PURE__ */ jsx15(LoaderIcon, { size })
|
|
1107
1303
|
}
|
|
1108
1304
|
);
|
|
1109
1305
|
|
|
1110
1306
|
// src/ui/badge.tsx
|
|
1111
1307
|
import { Slot as Slot2 } from "@radix-ui/react-slot";
|
|
1112
1308
|
import { cva as cva3 } from "class-variance-authority";
|
|
1113
|
-
import { jsx as
|
|
1309
|
+
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
1114
1310
|
var badgeVariants = cva3(
|
|
1115
1311
|
"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",
|
|
1116
1312
|
{
|
|
@@ -1134,7 +1330,7 @@ function Badge({
|
|
|
1134
1330
|
...props
|
|
1135
1331
|
}) {
|
|
1136
1332
|
const Comp = asChild ? Slot2 : "span";
|
|
1137
|
-
return /* @__PURE__ */
|
|
1333
|
+
return /* @__PURE__ */ jsx16(
|
|
1138
1334
|
Comp,
|
|
1139
1335
|
{
|
|
1140
1336
|
"data-slot": "badge",
|
|
@@ -1157,13 +1353,13 @@ import { isValidElement } from "react";
|
|
|
1157
1353
|
|
|
1158
1354
|
// src/components/code-block.tsx
|
|
1159
1355
|
import { CheckIcon as CheckIcon3, CopyIcon } from "lucide-react";
|
|
1160
|
-
import { createContext as createContext3, useContext as useContext3, useState as
|
|
1356
|
+
import { createContext as createContext3, useContext as useContext3, useState as useState4 } from "react";
|
|
1161
1357
|
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
|
|
1162
1358
|
import {
|
|
1163
1359
|
oneDark,
|
|
1164
1360
|
oneLight
|
|
1165
1361
|
} from "react-syntax-highlighter/dist/esm/styles/prism";
|
|
1166
|
-
import { jsx as
|
|
1362
|
+
import { jsx as jsx17, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1167
1363
|
var CodeBlockContext = createContext3({
|
|
1168
1364
|
code: ""
|
|
1169
1365
|
});
|
|
@@ -1174,7 +1370,7 @@ var CodeBlock = ({
|
|
|
1174
1370
|
className,
|
|
1175
1371
|
children,
|
|
1176
1372
|
...props
|
|
1177
|
-
}) => /* @__PURE__ */
|
|
1373
|
+
}) => /* @__PURE__ */ jsx17(CodeBlockContext.Provider, { value: { code }, children: /* @__PURE__ */ jsx17(
|
|
1178
1374
|
"div",
|
|
1179
1375
|
{
|
|
1180
1376
|
className: cn(
|
|
@@ -1182,8 +1378,8 @@ var CodeBlock = ({
|
|
|
1182
1378
|
className
|
|
1183
1379
|
),
|
|
1184
1380
|
...props,
|
|
1185
|
-
children: /* @__PURE__ */
|
|
1186
|
-
/* @__PURE__ */
|
|
1381
|
+
children: /* @__PURE__ */ jsxs10("div", { className: "relative max-h-96 overflow-y-auto", children: [
|
|
1382
|
+
/* @__PURE__ */ jsx17(
|
|
1187
1383
|
SyntaxHighlighter,
|
|
1188
1384
|
{
|
|
1189
1385
|
className: "overflow-hidden dark:hidden",
|
|
@@ -1209,7 +1405,7 @@ var CodeBlock = ({
|
|
|
1209
1405
|
children: code
|
|
1210
1406
|
}
|
|
1211
1407
|
),
|
|
1212
|
-
/* @__PURE__ */
|
|
1408
|
+
/* @__PURE__ */ jsx17(
|
|
1213
1409
|
SyntaxHighlighter,
|
|
1214
1410
|
{
|
|
1215
1411
|
className: "hidden overflow-hidden dark:block",
|
|
@@ -1235,14 +1431,14 @@ var CodeBlock = ({
|
|
|
1235
1431
|
children: code
|
|
1236
1432
|
}
|
|
1237
1433
|
),
|
|
1238
|
-
children && /* @__PURE__ */
|
|
1434
|
+
children && /* @__PURE__ */ jsx17("div", { className: "absolute top-2 right-2 flex items-center gap-2", children })
|
|
1239
1435
|
] })
|
|
1240
1436
|
}
|
|
1241
1437
|
) });
|
|
1242
1438
|
|
|
1243
1439
|
// src/components/tool.tsx
|
|
1244
|
-
import { jsx as
|
|
1245
|
-
var Tool = ({ className, ...props }) => /* @__PURE__ */
|
|
1440
|
+
import { jsx as jsx18, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
1441
|
+
var Tool = ({ className, ...props }) => /* @__PURE__ */ jsx18(
|
|
1246
1442
|
Collapsible,
|
|
1247
1443
|
{
|
|
1248
1444
|
className: cn("not-prose w-full rounded-md border border-[var(--chat-divider)]", className),
|
|
@@ -1257,12 +1453,12 @@ var getStatusBadge = (status) => {
|
|
|
1257
1453
|
"output-error": "Error"
|
|
1258
1454
|
};
|
|
1259
1455
|
const icons = {
|
|
1260
|
-
"input-streaming": /* @__PURE__ */
|
|
1261
|
-
"input-available": /* @__PURE__ */
|
|
1262
|
-
"output-available": /* @__PURE__ */
|
|
1263
|
-
"output-error": /* @__PURE__ */
|
|
1456
|
+
"input-streaming": /* @__PURE__ */ jsx18(CircleIcon2, { className: "size-4" }),
|
|
1457
|
+
"input-available": /* @__PURE__ */ jsx18(ClockIcon, { className: "size-4 animate-pulse" }),
|
|
1458
|
+
"output-available": /* @__PURE__ */ jsx18(CheckCircleIcon, { className: "size-4 text-green-600" }),
|
|
1459
|
+
"output-error": /* @__PURE__ */ jsx18(XCircleIcon, { className: "size-4 text-red-600" })
|
|
1264
1460
|
};
|
|
1265
|
-
return /* @__PURE__ */
|
|
1461
|
+
return /* @__PURE__ */ jsxs11(Badge, { className: "gap-1.5 rounded-full text-xs", variant: "secondary", children: [
|
|
1266
1462
|
icons[status],
|
|
1267
1463
|
labels[status]
|
|
1268
1464
|
] });
|
|
@@ -1274,7 +1470,7 @@ var ToolHeader = ({
|
|
|
1274
1470
|
toolName,
|
|
1275
1471
|
state,
|
|
1276
1472
|
...props
|
|
1277
|
-
}) => /* @__PURE__ */
|
|
1473
|
+
}) => /* @__PURE__ */ jsxs11(
|
|
1278
1474
|
CollapsibleTrigger2,
|
|
1279
1475
|
{
|
|
1280
1476
|
className: cn(
|
|
@@ -1283,16 +1479,16 @@ var ToolHeader = ({
|
|
|
1283
1479
|
),
|
|
1284
1480
|
...props,
|
|
1285
1481
|
children: [
|
|
1286
|
-
/* @__PURE__ */
|
|
1287
|
-
/* @__PURE__ */
|
|
1288
|
-
/* @__PURE__ */
|
|
1482
|
+
/* @__PURE__ */ jsxs11("div", { className: "flex items-center gap-2", children: [
|
|
1483
|
+
/* @__PURE__ */ jsx18(WrenchIcon, { className: "size-4 text-muted-foreground" }),
|
|
1484
|
+
/* @__PURE__ */ jsx18("span", { className: "font-medium text-sm", children: title ?? toolName ?? type.split("-").slice(1).join("-") }),
|
|
1289
1485
|
getStatusBadge(state)
|
|
1290
1486
|
] }),
|
|
1291
|
-
/* @__PURE__ */
|
|
1487
|
+
/* @__PURE__ */ jsx18(ChevronDownIcon4, { className: "size-4 text-muted-foreground transition-transform group-data-[state=open]:rotate-180" })
|
|
1292
1488
|
]
|
|
1293
1489
|
}
|
|
1294
1490
|
);
|
|
1295
|
-
var ToolContent = ({ className, ...props }) => /* @__PURE__ */
|
|
1491
|
+
var ToolContent = ({ className, ...props }) => /* @__PURE__ */ jsx18(
|
|
1296
1492
|
CollapsibleContent2,
|
|
1297
1493
|
{
|
|
1298
1494
|
className: cn(
|
|
@@ -1302,9 +1498,9 @@ var ToolContent = ({ className, ...props }) => /* @__PURE__ */ jsx17(
|
|
|
1302
1498
|
...props
|
|
1303
1499
|
}
|
|
1304
1500
|
);
|
|
1305
|
-
var ToolInput = ({ className, input, ...props }) => /* @__PURE__ */
|
|
1306
|
-
/* @__PURE__ */
|
|
1307
|
-
/* @__PURE__ */
|
|
1501
|
+
var ToolInput = ({ className, input, ...props }) => /* @__PURE__ */ jsxs11("div", { className: cn("space-y-2 overflow-hidden p-2", className), ...props, children: [
|
|
1502
|
+
/* @__PURE__ */ jsx18("h4", { className: "font-medium text-muted-foreground text-xs uppercase tracking-wide", children: "Parameters" }),
|
|
1503
|
+
/* @__PURE__ */ jsx18("div", { className: "rounded-md bg-muted/50", children: /* @__PURE__ */ jsx18(CodeBlock, { code: JSON.stringify(input, null, 2), language: "json" }) })
|
|
1308
1504
|
] });
|
|
1309
1505
|
var ToolOutput = ({
|
|
1310
1506
|
className,
|
|
@@ -1315,15 +1511,15 @@ var ToolOutput = ({
|
|
|
1315
1511
|
if (!(output || errorText)) {
|
|
1316
1512
|
return null;
|
|
1317
1513
|
}
|
|
1318
|
-
let Output = /* @__PURE__ */
|
|
1514
|
+
let Output = /* @__PURE__ */ jsx18("div", { children: output });
|
|
1319
1515
|
if (typeof output === "object" && !isValidElement(output)) {
|
|
1320
|
-
Output = /* @__PURE__ */
|
|
1516
|
+
Output = /* @__PURE__ */ jsx18(CodeBlock, { code: JSON.stringify(output, null, 2), language: "json" });
|
|
1321
1517
|
} else if (typeof output === "string") {
|
|
1322
|
-
Output = /* @__PURE__ */
|
|
1518
|
+
Output = /* @__PURE__ */ jsx18(CodeBlock, { code: output, language: "json" });
|
|
1323
1519
|
}
|
|
1324
|
-
return /* @__PURE__ */
|
|
1325
|
-
/* @__PURE__ */
|
|
1326
|
-
/* @__PURE__ */
|
|
1520
|
+
return /* @__PURE__ */ jsxs11("div", { className: cn("space-y-2 p-2", className), ...props, children: [
|
|
1521
|
+
/* @__PURE__ */ jsx18("h4", { className: "font-medium text-muted-foreground text-xs uppercase tracking-wide", children: errorText ? "Error" : "Result" }),
|
|
1522
|
+
/* @__PURE__ */ jsxs11(
|
|
1327
1523
|
"div",
|
|
1328
1524
|
{
|
|
1329
1525
|
className: cn(
|
|
@@ -1331,7 +1527,7 @@ var ToolOutput = ({
|
|
|
1331
1527
|
errorText ? "bg-destructive/10 text-destructive" : "bg-muted/50 text-foreground"
|
|
1332
1528
|
),
|
|
1333
1529
|
children: [
|
|
1334
|
-
errorText && /* @__PURE__ */
|
|
1530
|
+
errorText && /* @__PURE__ */ jsx18("div", { children: errorText }),
|
|
1335
1531
|
Output
|
|
1336
1532
|
]
|
|
1337
1533
|
}
|
|
@@ -1340,7 +1536,7 @@ var ToolOutput = ({
|
|
|
1340
1536
|
};
|
|
1341
1537
|
|
|
1342
1538
|
// src/components/suggestion2.tsx
|
|
1343
|
-
import { jsx as
|
|
1539
|
+
import { jsx as jsx19, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
1344
1540
|
function StarterMessages({
|
|
1345
1541
|
className,
|
|
1346
1542
|
prompts,
|
|
@@ -1348,7 +1544,7 @@ function StarterMessages({
|
|
|
1348
1544
|
...props
|
|
1349
1545
|
}) {
|
|
1350
1546
|
if (prompts.length === 0) return null;
|
|
1351
|
-
return /* @__PURE__ */
|
|
1547
|
+
return /* @__PURE__ */ jsx19(
|
|
1352
1548
|
"div",
|
|
1353
1549
|
{
|
|
1354
1550
|
className: cn(
|
|
@@ -1356,8 +1552,8 @@ function StarterMessages({
|
|
|
1356
1552
|
className
|
|
1357
1553
|
),
|
|
1358
1554
|
...props,
|
|
1359
|
-
children: prompts.map((prompt, index) => /* @__PURE__ */
|
|
1360
|
-
/* @__PURE__ */
|
|
1555
|
+
children: prompts.map((prompt, index) => /* @__PURE__ */ jsxs12("div", { children: [
|
|
1556
|
+
/* @__PURE__ */ jsx19(
|
|
1361
1557
|
StarterMessageItem,
|
|
1362
1558
|
{
|
|
1363
1559
|
prompt,
|
|
@@ -1367,7 +1563,7 @@ function StarterMessages({
|
|
|
1367
1563
|
index < prompts.length - 1 && // 1px-tall element used as a divider — same --chat-divider token
|
|
1368
1564
|
// every other separator in the widget uses, so consumers only
|
|
1369
1565
|
// need to override one variable to recolour all of them.
|
|
1370
|
-
/* @__PURE__ */
|
|
1566
|
+
/* @__PURE__ */ jsx19("div", { className: "h-px mx-3", style: { backgroundColor: "var(--chat-divider)" } })
|
|
1371
1567
|
] }, index))
|
|
1372
1568
|
}
|
|
1373
1569
|
);
|
|
@@ -1378,7 +1574,7 @@ function StarterMessageItem({
|
|
|
1378
1574
|
onClick,
|
|
1379
1575
|
...props
|
|
1380
1576
|
}) {
|
|
1381
|
-
return /* @__PURE__ */
|
|
1577
|
+
return /* @__PURE__ */ jsxs12(
|
|
1382
1578
|
"button",
|
|
1383
1579
|
{
|
|
1384
1580
|
type: "button",
|
|
@@ -1393,8 +1589,8 @@ function StarterMessageItem({
|
|
|
1393
1589
|
),
|
|
1394
1590
|
...props,
|
|
1395
1591
|
children: [
|
|
1396
|
-
/* @__PURE__ */
|
|
1397
|
-
prompt.subtitle && /* @__PURE__ */
|
|
1592
|
+
/* @__PURE__ */ jsx19("span", { className: "text-[13px] text-[hsl(var(--chat-text)/0.7)]", children: prompt.title }),
|
|
1593
|
+
prompt.subtitle && /* @__PURE__ */ jsx19("span", { className: "block text-[11px] text-[hsl(var(--chat-text)/0.4)] mt-0.5", children: prompt.subtitle })
|
|
1398
1594
|
]
|
|
1399
1595
|
}
|
|
1400
1596
|
);
|
|
@@ -1402,7 +1598,7 @@ function StarterMessageItem({
|
|
|
1402
1598
|
|
|
1403
1599
|
// src/contexts/chat-storage-context.tsx
|
|
1404
1600
|
import { createContext as createContext4, useContext as useContext4 } from "react";
|
|
1405
|
-
import { jsx as
|
|
1601
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
1406
1602
|
var ChatStorageContext = createContext4({
|
|
1407
1603
|
storageKeyPrefix: ""
|
|
1408
1604
|
});
|
|
@@ -1411,38 +1607,45 @@ function ChatStorageProvider({
|
|
|
1411
1607
|
userId
|
|
1412
1608
|
}) {
|
|
1413
1609
|
const storageKeyPrefix = userId || "";
|
|
1414
|
-
return /* @__PURE__ */
|
|
1610
|
+
return /* @__PURE__ */ jsx20(ChatStorageContext.Provider, { value: { storageKeyPrefix }, children });
|
|
1415
1611
|
}
|
|
1416
1612
|
function useChatStorageKey() {
|
|
1417
1613
|
return useContext4(ChatStorageContext);
|
|
1418
1614
|
}
|
|
1419
1615
|
|
|
1420
1616
|
// src/components/interface.tsx
|
|
1421
|
-
import { jsx as
|
|
1617
|
+
import { jsx as jsx21, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
1422
1618
|
function ChatInterface({ id, initialMessages, config, onClose, headerActions } = {}) {
|
|
1423
1619
|
const { storageKeyPrefix } = useChatStorageKey();
|
|
1424
1620
|
const storageKey = (key) => storageKeyPrefix ? `chat-${storageKeyPrefix}-${key}` : `chat-${key}`;
|
|
1425
1621
|
const themeMode = config?.theme?.mode || "light";
|
|
1426
|
-
const [input, setInput] =
|
|
1427
|
-
const
|
|
1428
|
-
const
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1622
|
+
const [input, setInput] = useState5("");
|
|
1623
|
+
const inputRef = useRef4(null);
|
|
1624
|
+
const inputPlugins = useInputPlugins({
|
|
1625
|
+
textareaRef: inputRef,
|
|
1626
|
+
value: input,
|
|
1627
|
+
setValue: setInput,
|
|
1628
|
+
plugins: config?.inputPlugins
|
|
1629
|
+
});
|
|
1630
|
+
const [showHistory, setShowHistory] = useState5(false);
|
|
1631
|
+
const [conversations, setConversations] = useState5([]);
|
|
1632
|
+
const [loadingHistory, setLoadingHistory] = useState5(false);
|
|
1633
|
+
const [historyLoaded, setHistoryLoaded] = useState5(false);
|
|
1634
|
+
const [searchQuery, setSearchQuery] = useState5("");
|
|
1635
|
+
const [uploadError, setUploadError] = useState5(null);
|
|
1636
|
+
useEffect5(() => {
|
|
1434
1637
|
if (uploadError) {
|
|
1435
1638
|
const timeoutId = setTimeout(() => setUploadError(null), 5e3);
|
|
1436
1639
|
return () => clearTimeout(timeoutId);
|
|
1437
1640
|
}
|
|
1438
1641
|
}, [uploadError]);
|
|
1439
|
-
const [tabs, setTabs] =
|
|
1440
|
-
const [activeTabId, setActiveTabId] =
|
|
1441
|
-
const [initialTabCreated, setInitialTabCreated] =
|
|
1442
|
-
const [isInitializing, setIsInitializing] =
|
|
1443
|
-
const [isLoadingMessages, setIsLoadingMessages] =
|
|
1444
|
-
const lastSyncedTabId =
|
|
1445
|
-
const hasInitialized =
|
|
1642
|
+
const [tabs, setTabs] = useState5([]);
|
|
1643
|
+
const [activeTabId, setActiveTabId] = useState5("");
|
|
1644
|
+
const [initialTabCreated, setInitialTabCreated] = useState5(false);
|
|
1645
|
+
const [isInitializing, setIsInitializing] = useState5(true);
|
|
1646
|
+
const [isLoadingMessages, setIsLoadingMessages] = useState5(false);
|
|
1647
|
+
const lastSyncedTabId = useRef4("");
|
|
1648
|
+
const hasInitialized = useRef4(false);
|
|
1446
1649
|
const { messages, sendMessage, status, setMessages } = useChat({
|
|
1447
1650
|
id: activeTabId || "temp-id",
|
|
1448
1651
|
transport: new DefaultChatTransport({
|
|
@@ -1532,12 +1735,12 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1532
1735
|
};
|
|
1533
1736
|
const AttachButton = () => {
|
|
1534
1737
|
const attachments = usePromptInputAttachments();
|
|
1535
|
-
return /* @__PURE__ */
|
|
1738
|
+
return /* @__PURE__ */ jsx21(
|
|
1536
1739
|
PromptInputButton,
|
|
1537
1740
|
{
|
|
1538
1741
|
variant: "ghost",
|
|
1539
1742
|
onClick: () => attachments.openFileDialog(),
|
|
1540
|
-
children: /* @__PURE__ */
|
|
1743
|
+
children: /* @__PURE__ */ jsx21(PlusIcon2, { className: "size-4" })
|
|
1541
1744
|
}
|
|
1542
1745
|
);
|
|
1543
1746
|
};
|
|
@@ -1576,7 +1779,7 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1576
1779
|
}
|
|
1577
1780
|
return newTabId;
|
|
1578
1781
|
};
|
|
1579
|
-
const createNewTab =
|
|
1782
|
+
const createNewTab = useCallback4(() => {
|
|
1580
1783
|
if (!initialTabCreated) {
|
|
1581
1784
|
console.warn("Cannot create new tab while initializing");
|
|
1582
1785
|
return;
|
|
@@ -1603,10 +1806,10 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1603
1806
|
setMessages([]);
|
|
1604
1807
|
setInput("");
|
|
1605
1808
|
}, [initialTabCreated]);
|
|
1606
|
-
const startNewConversation =
|
|
1809
|
+
const startNewConversation = useCallback4(() => {
|
|
1607
1810
|
createNewTab();
|
|
1608
1811
|
}, [createNewTab]);
|
|
1609
|
-
|
|
1812
|
+
useEffect5(() => {
|
|
1610
1813
|
return () => {
|
|
1611
1814
|
};
|
|
1612
1815
|
}, []);
|
|
@@ -1671,17 +1874,17 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1671
1874
|
setLoadingHistory(false);
|
|
1672
1875
|
}
|
|
1673
1876
|
};
|
|
1674
|
-
|
|
1877
|
+
useEffect5(() => {
|
|
1675
1878
|
if (showHistory && !historyLoaded && config?.userId) {
|
|
1676
1879
|
fetchConversations();
|
|
1677
1880
|
}
|
|
1678
1881
|
}, [showHistory, historyLoaded, config?.userId]);
|
|
1679
|
-
|
|
1882
|
+
useEffect5(() => {
|
|
1680
1883
|
if (!historyLoaded && config?.userId) {
|
|
1681
1884
|
fetchConversations();
|
|
1682
1885
|
}
|
|
1683
1886
|
}, [historyLoaded, config?.userId]);
|
|
1684
|
-
|
|
1887
|
+
useEffect5(() => {
|
|
1685
1888
|
if (tabs.length > 0) {
|
|
1686
1889
|
const timeoutId = setTimeout(() => {
|
|
1687
1890
|
localStorage.setItem(storageKey("tabs"), JSON.stringify(tabs));
|
|
@@ -1690,7 +1893,7 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1690
1893
|
return () => clearTimeout(timeoutId);
|
|
1691
1894
|
}
|
|
1692
1895
|
}, [tabs, activeTabId, storageKey]);
|
|
1693
|
-
|
|
1896
|
+
useEffect5(() => {
|
|
1694
1897
|
if (hasInitialized.current) return;
|
|
1695
1898
|
const loadInitialTabs = () => {
|
|
1696
1899
|
const savedTabs = localStorage.getItem(storageKey("tabs"));
|
|
@@ -1717,8 +1920,8 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1717
1920
|
}
|
|
1718
1921
|
hasInitialized.current = true;
|
|
1719
1922
|
}, []);
|
|
1720
|
-
const hasLoadedInitialMessages =
|
|
1721
|
-
|
|
1923
|
+
const hasLoadedInitialMessages = useRef4(false);
|
|
1924
|
+
useEffect5(() => {
|
|
1722
1925
|
if (hasLoadedInitialMessages.current) return;
|
|
1723
1926
|
if (!config?.userId) return;
|
|
1724
1927
|
if (!activeTabId) return;
|
|
@@ -1731,14 +1934,14 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1731
1934
|
}
|
|
1732
1935
|
})();
|
|
1733
1936
|
}, [config?.userId, activeTabId]);
|
|
1734
|
-
|
|
1937
|
+
useEffect5(() => {
|
|
1735
1938
|
if (isInitializing) return;
|
|
1736
1939
|
if (activeTabId && tabs.length > 0 && activeTabId !== lastSyncedTabId.current) {
|
|
1737
1940
|
lastSyncedTabId.current = activeTabId;
|
|
1738
1941
|
setInput("");
|
|
1739
1942
|
}
|
|
1740
1943
|
}, [activeTabId, isInitializing, tabs.length]);
|
|
1741
|
-
const groupedConversations =
|
|
1944
|
+
const groupedConversations = useMemo3(() => {
|
|
1742
1945
|
const filtered = conversations.filter(
|
|
1743
1946
|
(conv) => searchQuery === "" || conv.title.toLowerCase().includes(searchQuery.toLowerCase())
|
|
1744
1947
|
);
|
|
@@ -1799,10 +2002,10 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1799
2002
|
const renderMessages = () => messages.map((message, index) => {
|
|
1800
2003
|
const sourceParts = message.parts?.filter((part) => part.type === "source-url") || [];
|
|
1801
2004
|
const fileParts = message.parts?.filter((part) => part.type === "file") || [];
|
|
1802
|
-
return /* @__PURE__ */
|
|
1803
|
-
message.role === "assistant" && sourceParts.length > 0 && /* @__PURE__ */
|
|
1804
|
-
/* @__PURE__ */
|
|
1805
|
-
sourceParts.map((part, i) => /* @__PURE__ */
|
|
2005
|
+
return /* @__PURE__ */ jsxs13("div", { className: index > 0 ? "mt-6" : "", children: [
|
|
2006
|
+
message.role === "assistant" && sourceParts.length > 0 && /* @__PURE__ */ jsxs13(Sources, { children: [
|
|
2007
|
+
/* @__PURE__ */ jsx21(SourcesTrigger, { count: sourceParts.length }),
|
|
2008
|
+
sourceParts.map((part, i) => /* @__PURE__ */ jsx21(SourcesContent, { children: /* @__PURE__ */ jsx21(
|
|
1806
2009
|
Source,
|
|
1807
2010
|
{
|
|
1808
2011
|
href: part.url,
|
|
@@ -1811,10 +2014,10 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1811
2014
|
`${message.id}-${i}`
|
|
1812
2015
|
) }, `${message.id}-${i}`))
|
|
1813
2016
|
] }),
|
|
1814
|
-
fileParts.length > 0 && /* @__PURE__ */
|
|
2017
|
+
fileParts.length > 0 && /* @__PURE__ */ jsx21("div", { className: cn(
|
|
1815
2018
|
"flex mb-1",
|
|
1816
2019
|
message.role === "user" ? "justify-end" : "justify-start"
|
|
1817
|
-
), children: /* @__PURE__ */
|
|
2020
|
+
), children: /* @__PURE__ */ jsx21(
|
|
1818
2021
|
MessageAttachments,
|
|
1819
2022
|
{
|
|
1820
2023
|
attachments: fileParts.map((part) => ({
|
|
@@ -1825,14 +2028,14 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1825
2028
|
}))
|
|
1826
2029
|
}
|
|
1827
2030
|
) }),
|
|
1828
|
-
message.parts ? /* @__PURE__ */
|
|
2031
|
+
message.parts ? /* @__PURE__ */ jsx21("div", { className: "space-y-2", children: message.parts.map((part, i) => {
|
|
1829
2032
|
switch (part.type) {
|
|
1830
2033
|
case "text":
|
|
1831
2034
|
const isTextStreaming = status === "streaming" && i === message.parts.length - 1 && message.id === messages.at(-1)?.id;
|
|
1832
|
-
return /* @__PURE__ */
|
|
2035
|
+
return /* @__PURE__ */ jsx21(Fragment5, { children: /* @__PURE__ */ jsx21(Message, { from: message.role, children: /* @__PURE__ */ jsx21(MessageContent, { children: /* @__PURE__ */ jsx21(Response, { isStreaming: isTextStreaming, children: part.text }) }) }) }, `${message.id}-${i}`);
|
|
1833
2036
|
case "reasoning":
|
|
1834
2037
|
const isCurrentlyStreaming = status === "streaming" && i === message.parts.length - 1 && message.id === messages.at(-1)?.id;
|
|
1835
|
-
return /* @__PURE__ */
|
|
2038
|
+
return /* @__PURE__ */ jsxs13(
|
|
1836
2039
|
Reasoning,
|
|
1837
2040
|
{
|
|
1838
2041
|
className: "w-full",
|
|
@@ -1840,8 +2043,8 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1840
2043
|
defaultOpen: false,
|
|
1841
2044
|
open: isCurrentlyStreaming ? true : void 0,
|
|
1842
2045
|
children: [
|
|
1843
|
-
/* @__PURE__ */
|
|
1844
|
-
/* @__PURE__ */
|
|
2046
|
+
/* @__PURE__ */ jsx21(ReasoningTrigger, {}),
|
|
2047
|
+
/* @__PURE__ */ jsx21(ReasoningContent, { children: part.text })
|
|
1845
2048
|
]
|
|
1846
2049
|
},
|
|
1847
2050
|
`${message.id}-${i}`
|
|
@@ -1849,8 +2052,8 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1849
2052
|
default:
|
|
1850
2053
|
if (part.type.startsWith("tool-") || part.type === "dynamic-tool") {
|
|
1851
2054
|
const toolPart = part;
|
|
1852
|
-
return /* @__PURE__ */
|
|
1853
|
-
/* @__PURE__ */
|
|
2055
|
+
return /* @__PURE__ */ jsxs13(Tool, { children: [
|
|
2056
|
+
/* @__PURE__ */ jsx21(
|
|
1854
2057
|
ToolHeader,
|
|
1855
2058
|
{
|
|
1856
2059
|
type: part.type,
|
|
@@ -1858,9 +2061,9 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1858
2061
|
state: toolPart.state
|
|
1859
2062
|
}
|
|
1860
2063
|
),
|
|
1861
|
-
/* @__PURE__ */
|
|
1862
|
-
/* @__PURE__ */
|
|
1863
|
-
/* @__PURE__ */
|
|
2064
|
+
/* @__PURE__ */ jsxs13(ToolContent, { children: [
|
|
2065
|
+
/* @__PURE__ */ jsx21(ToolInput, { input: toolPart.input }),
|
|
2066
|
+
/* @__PURE__ */ jsx21(ToolOutput, { output: toolPart.output, errorText: toolPart.errorText })
|
|
1864
2067
|
] })
|
|
1865
2068
|
] }, `${message.id}-${i}`);
|
|
1866
2069
|
}
|
|
@@ -1868,7 +2071,7 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1868
2071
|
}
|
|
1869
2072
|
}) }) : (
|
|
1870
2073
|
/* Handle standard AI SDK messages with content or text property */
|
|
1871
|
-
/* @__PURE__ */
|
|
2074
|
+
/* @__PURE__ */ jsx21(Fragment5, { children: /* @__PURE__ */ jsx21(Message, { from: message.role, children: /* @__PURE__ */ jsx21(MessageContent, { children: /* @__PURE__ */ jsx21(Response, { children: message.content || message.text }) }) }) }, `${message.id}-content`)
|
|
1872
2075
|
)
|
|
1873
2076
|
] }, message.id);
|
|
1874
2077
|
});
|
|
@@ -1900,8 +2103,8 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1900
2103
|
console.error("Error loading conversation:", error);
|
|
1901
2104
|
}
|
|
1902
2105
|
};
|
|
1903
|
-
const dropdownRef =
|
|
1904
|
-
|
|
2106
|
+
const dropdownRef = useRef4(null);
|
|
2107
|
+
useEffect5(() => {
|
|
1905
2108
|
const handleClickOutside = (event) => {
|
|
1906
2109
|
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
1907
2110
|
setShowHistory(false);
|
|
@@ -1914,7 +2117,7 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1914
2117
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
1915
2118
|
};
|
|
1916
2119
|
}, [showHistory]);
|
|
1917
|
-
return /* @__PURE__ */
|
|
2120
|
+
return /* @__PURE__ */ jsx21("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__ */ jsxs13(
|
|
1918
2121
|
"div",
|
|
1919
2122
|
{
|
|
1920
2123
|
className: cn(
|
|
@@ -1922,11 +2125,11 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1922
2125
|
themeMode === "dark" && "dark"
|
|
1923
2126
|
),
|
|
1924
2127
|
children: [
|
|
1925
|
-
/* @__PURE__ */
|
|
2128
|
+
/* @__PURE__ */ jsxs13("div", { className: "flex items-center gap-2 px-3 py-2 border-b backdrop-blur-sm relative z-20", style: {
|
|
1926
2129
|
borderColor: "var(--chat-divider)",
|
|
1927
2130
|
backgroundColor: "var(--chat-header-bg)"
|
|
1928
2131
|
}, children: [
|
|
1929
|
-
/* @__PURE__ */
|
|
2132
|
+
/* @__PURE__ */ jsx21("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__ */ jsxs13(
|
|
1930
2133
|
"div",
|
|
1931
2134
|
{
|
|
1932
2135
|
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",
|
|
@@ -1949,8 +2152,8 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1949
2152
|
switchToTab(tab.id);
|
|
1950
2153
|
},
|
|
1951
2154
|
children: [
|
|
1952
|
-
/* @__PURE__ */
|
|
1953
|
-
tabs.length > 1 && /* @__PURE__ */
|
|
2155
|
+
/* @__PURE__ */ jsx21("span", { className: "truncate max-w-28 text-[13px] font-medium transition-colors", children: tab.title }),
|
|
2156
|
+
tabs.length > 1 && /* @__PURE__ */ jsx21(
|
|
1954
2157
|
"button",
|
|
1955
2158
|
{
|
|
1956
2159
|
onClick: (e) => {
|
|
@@ -1969,15 +2172,15 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1969
2172
|
e.currentTarget.style.opacity = tab.isActive ? "0.6" : "0";
|
|
1970
2173
|
e.currentTarget.style.backgroundColor = "transparent";
|
|
1971
2174
|
},
|
|
1972
|
-
children: /* @__PURE__ */
|
|
2175
|
+
children: /* @__PURE__ */ jsx21(XIcon2, { className: "h-3 w-3", strokeWidth: 2.5 })
|
|
1973
2176
|
}
|
|
1974
2177
|
)
|
|
1975
2178
|
]
|
|
1976
2179
|
},
|
|
1977
2180
|
tab.id
|
|
1978
2181
|
)) }),
|
|
1979
|
-
/* @__PURE__ */
|
|
1980
|
-
/* @__PURE__ */
|
|
2182
|
+
/* @__PURE__ */ jsxs13("div", { className: "flex items-center gap-0.5 flex-shrink-0", children: [
|
|
2183
|
+
/* @__PURE__ */ jsx21(
|
|
1981
2184
|
"button",
|
|
1982
2185
|
{
|
|
1983
2186
|
onClick: createNewTab,
|
|
@@ -1994,11 +2197,11 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1994
2197
|
e.currentTarget.style.backgroundColor = "transparent";
|
|
1995
2198
|
},
|
|
1996
2199
|
title: "New Chat",
|
|
1997
|
-
children: /* @__PURE__ */
|
|
2200
|
+
children: /* @__PURE__ */ jsx21(PlusIcon2, { className: "h-4 w-4", strokeWidth: 2 })
|
|
1998
2201
|
}
|
|
1999
2202
|
),
|
|
2000
|
-
/* @__PURE__ */
|
|
2001
|
-
/* @__PURE__ */
|
|
2203
|
+
/* @__PURE__ */ jsxs13("div", { className: "relative", ref: dropdownRef, children: [
|
|
2204
|
+
/* @__PURE__ */ jsx21(
|
|
2002
2205
|
"button",
|
|
2003
2206
|
{
|
|
2004
2207
|
onClick: () => setShowHistory(!showHistory),
|
|
@@ -2020,17 +2223,17 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
2020
2223
|
}
|
|
2021
2224
|
},
|
|
2022
2225
|
title: "Chat History",
|
|
2023
|
-
children: /* @__PURE__ */
|
|
2226
|
+
children: /* @__PURE__ */ jsx21(HistoryIcon, { className: "h-4 w-4", strokeWidth: 2 })
|
|
2024
2227
|
}
|
|
2025
2228
|
),
|
|
2026
|
-
showHistory && /* @__PURE__ */
|
|
2229
|
+
showHistory && /* @__PURE__ */ jsxs13("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: {
|
|
2027
2230
|
backgroundColor: "hsl(var(--chat-background))",
|
|
2028
2231
|
border: `1px solid ${"var(--chat-divider)"}`
|
|
2029
2232
|
}, children: [
|
|
2030
|
-
/* @__PURE__ */
|
|
2233
|
+
/* @__PURE__ */ jsx21("div", { className: "p-2.5 border-b", style: {
|
|
2031
2234
|
borderColor: "var(--chat-divider)",
|
|
2032
2235
|
backgroundColor: "var(--chat-overlay)"
|
|
2033
|
-
}, children: /* @__PURE__ */
|
|
2236
|
+
}, children: /* @__PURE__ */ jsx21("div", { className: "relative", children: /* @__PURE__ */ jsx21(
|
|
2034
2237
|
"input",
|
|
2035
2238
|
{
|
|
2036
2239
|
type: "text",
|
|
@@ -2045,25 +2248,25 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
2045
2248
|
}
|
|
2046
2249
|
}
|
|
2047
2250
|
) }) }),
|
|
2048
|
-
/* @__PURE__ */
|
|
2049
|
-
/* @__PURE__ */
|
|
2251
|
+
/* @__PURE__ */ jsx21("div", { className: "max-h-[300px] overflow-y-auto ai-assistant-scrollbar", children: loadingHistory ? /* @__PURE__ */ jsx21("div", { className: "flex items-center justify-center py-12", children: /* @__PURE__ */ jsx21("div", { className: "text-[13px]", style: { color: "hsl(var(--chat-text-muted))" }, children: "Loading..." }) }) : conversations.length === 0 ? /* @__PURE__ */ jsxs13("div", { className: "flex flex-col items-center justify-center py-12 px-4 text-center", children: [
|
|
2252
|
+
/* @__PURE__ */ jsx21("div", { className: "w-12 h-12 rounded-full flex items-center justify-center mb-3", style: {
|
|
2050
2253
|
backgroundColor: "hsl(var(--chat-surface))"
|
|
2051
|
-
}, children: /* @__PURE__ */
|
|
2052
|
-
/* @__PURE__ */
|
|
2053
|
-
/* @__PURE__ */
|
|
2054
|
-
] }) : groupedConversations.length === 0 ? /* @__PURE__ */
|
|
2055
|
-
/* @__PURE__ */
|
|
2254
|
+
}, children: /* @__PURE__ */ jsx21(MessageSquareIcon, { className: "h-5 w-5", style: { color: "hsl(var(--chat-text-subtle))" }, strokeWidth: 2 }) }),
|
|
2255
|
+
/* @__PURE__ */ jsx21("p", { className: "text-[13px] font-medium mb-0.5", style: { color: "hsl(var(--chat-text))" }, children: "No Conversations" }),
|
|
2256
|
+
/* @__PURE__ */ jsx21("p", { className: "text-[12px]", style: { color: "hsl(var(--chat-text-muted))" }, children: "Start a new chat to begin" })
|
|
2257
|
+
] }) : groupedConversations.length === 0 ? /* @__PURE__ */ jsxs13("div", { className: "flex flex-col items-center justify-center py-12 px-4 text-center", children: [
|
|
2258
|
+
/* @__PURE__ */ jsx21("div", { className: "w-12 h-12 rounded-full flex items-center justify-center mb-3", style: {
|
|
2056
2259
|
backgroundColor: "hsl(var(--chat-surface))"
|
|
2057
|
-
}, children: /* @__PURE__ */
|
|
2058
|
-
/* @__PURE__ */
|
|
2059
|
-
/* @__PURE__ */
|
|
2060
|
-
] }) : /* @__PURE__ */
|
|
2061
|
-
/* @__PURE__ */
|
|
2260
|
+
}, children: /* @__PURE__ */ jsx21(SearchIcon, { className: "h-5 w-5", style: { color: "hsl(var(--chat-text-subtle))" }, strokeWidth: 2 }) }),
|
|
2261
|
+
/* @__PURE__ */ jsx21("p", { className: "text-[13px] font-medium mb-0.5", style: { color: "hsl(var(--chat-text))" }, children: "No Results" }),
|
|
2262
|
+
/* @__PURE__ */ jsx21("p", { className: "text-[12px]", style: { color: "hsl(var(--chat-text-muted))" }, children: "Try a different search" })
|
|
2263
|
+
] }) : /* @__PURE__ */ jsx21("div", { className: "py-0.5", children: groupedConversations.map(([groupName, groupConversations]) => /* @__PURE__ */ jsxs13("div", { className: "mb-0.5", children: [
|
|
2264
|
+
/* @__PURE__ */ jsx21("div", { className: "px-2.5 py-1 sticky top-0 backdrop-blur-sm z-10", style: {
|
|
2062
2265
|
backgroundColor: "var(--chat-header-bg-strong)"
|
|
2063
|
-
}, children: /* @__PURE__ */
|
|
2064
|
-
/* @__PURE__ */
|
|
2266
|
+
}, children: /* @__PURE__ */ jsx21("h3", { className: "text-[10px] font-semibold uppercase tracking-wide", style: { color: "hsl(var(--chat-text-muted))" }, children: groupName }) }),
|
|
2267
|
+
/* @__PURE__ */ jsx21("div", { className: "px-1 space-y-0.5", children: groupConversations.map((conversation) => {
|
|
2065
2268
|
const isActiveConversation = activeTabId === conversation.id;
|
|
2066
|
-
return /* @__PURE__ */
|
|
2269
|
+
return /* @__PURE__ */ jsx21(
|
|
2067
2270
|
"button",
|
|
2068
2271
|
{
|
|
2069
2272
|
className: "w-full px-2 py-1 rounded-md transition-all duration-150 text-left group relative",
|
|
@@ -2081,12 +2284,12 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
2081
2284
|
}
|
|
2082
2285
|
},
|
|
2083
2286
|
onClick: () => handleSelectConversation(conversation.id, conversation.title),
|
|
2084
|
-
children: /* @__PURE__ */
|
|
2085
|
-
/* @__PURE__ */
|
|
2287
|
+
children: /* @__PURE__ */ jsxs13("div", { className: "flex items-center gap-1.5", children: [
|
|
2288
|
+
/* @__PURE__ */ jsx21("div", { className: "flex-1 min-w-0", children: /* @__PURE__ */ jsx21("p", { className: "text-[12px] line-clamp-1 transition-colors leading-tight", style: {
|
|
2086
2289
|
fontWeight: isActiveConversation ? 500 : 400,
|
|
2087
2290
|
color: isActiveConversation ? "hsl(var(--chat-text))" : "hsl(var(--chat-text-strong))"
|
|
2088
2291
|
}, children: conversation.title }) }),
|
|
2089
|
-
/* @__PURE__ */
|
|
2292
|
+
/* @__PURE__ */ jsx21(
|
|
2090
2293
|
ChevronRightIcon2,
|
|
2091
2294
|
{
|
|
2092
2295
|
className: "h-3 w-3 transition-all duration-150 flex-shrink-0",
|
|
@@ -2106,7 +2309,7 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
2106
2309
|
] })
|
|
2107
2310
|
] }),
|
|
2108
2311
|
headerActions,
|
|
2109
|
-
onClose && /* @__PURE__ */
|
|
2312
|
+
onClose && /* @__PURE__ */ jsx21(
|
|
2110
2313
|
"button",
|
|
2111
2314
|
{
|
|
2112
2315
|
onClick: onClose,
|
|
@@ -2123,21 +2326,21 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
2123
2326
|
e.currentTarget.style.backgroundColor = "transparent";
|
|
2124
2327
|
},
|
|
2125
2328
|
title: "Close Chat",
|
|
2126
|
-
children: /* @__PURE__ */
|
|
2329
|
+
children: /* @__PURE__ */ jsx21(XIcon2, { className: "h-4 w-4", strokeWidth: 2 })
|
|
2127
2330
|
}
|
|
2128
2331
|
)
|
|
2129
2332
|
] })
|
|
2130
2333
|
] }),
|
|
2131
|
-
/* @__PURE__ */
|
|
2132
|
-
/* @__PURE__ */
|
|
2334
|
+
/* @__PURE__ */ jsxs13(Conversation, { className: "flex-1 max-w-full ai-assistant-scrollbar", children: [
|
|
2335
|
+
/* @__PURE__ */ jsxs13(ConversationContent, { className: "max-w-[96%] mx-auto py-6", children: [
|
|
2133
2336
|
renderMessages(),
|
|
2134
|
-
status === "submitted" && /* @__PURE__ */
|
|
2337
|
+
status === "submitted" && /* @__PURE__ */ jsx21("div", { className: "mt-6", children: /* @__PURE__ */ jsx21(Message, { from: "assistant", children: /* @__PURE__ */ jsx21(MessageContent, { children: /* @__PURE__ */ jsx21(Loader, { size: 16 }) }) }) })
|
|
2135
2338
|
] }),
|
|
2136
|
-
/* @__PURE__ */
|
|
2339
|
+
/* @__PURE__ */ jsx21(ConversationScrollButton, {})
|
|
2137
2340
|
] }),
|
|
2138
|
-
/* @__PURE__ */
|
|
2139
|
-
uploadError && /* @__PURE__ */
|
|
2140
|
-
isInitializing || isLoadingMessages ? /* @__PURE__ */
|
|
2341
|
+
/* @__PURE__ */ jsxs13("div", { className: "px-5 pb-5", children: [
|
|
2342
|
+
uploadError && /* @__PURE__ */ jsx21("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 }),
|
|
2343
|
+
isInitializing || isLoadingMessages ? /* @__PURE__ */ jsx21("div", { className: "flex items-center justify-center py-8", role: "status", "aria-label": "Loading conversation", children: /* @__PURE__ */ jsx21("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__ */ jsx21(
|
|
2141
2344
|
StarterMessages,
|
|
2142
2345
|
{
|
|
2143
2346
|
prompts: config.starterPrompts,
|
|
@@ -2146,20 +2349,25 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
2146
2349
|
}
|
|
2147
2350
|
}
|
|
2148
2351
|
),
|
|
2149
|
-
/* @__PURE__ */
|
|
2150
|
-
/* @__PURE__ */
|
|
2151
|
-
/* @__PURE__ */
|
|
2152
|
-
/* @__PURE__ */
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2352
|
+
/* @__PURE__ */ jsxs13(PromptInput, { onSubmit: handleSubmit, globalDrop: true, multiple: true, accept: "image/*", children: [
|
|
2353
|
+
/* @__PURE__ */ jsxs13(PromptInputBody, { children: [
|
|
2354
|
+
/* @__PURE__ */ jsx21(PromptInputAttachments, { children: (attachment) => /* @__PURE__ */ jsx21(PromptInputAttachment, { data: attachment }) }),
|
|
2355
|
+
/* @__PURE__ */ jsxs13("div", { className: "relative", children: [
|
|
2356
|
+
/* @__PURE__ */ jsx21(
|
|
2357
|
+
PromptInputTextarea,
|
|
2358
|
+
{
|
|
2359
|
+
ref: inputRef,
|
|
2360
|
+
onChange: (e) => setInput(e.target.value),
|
|
2361
|
+
onKeyDown: inputPlugins.onKeyDown,
|
|
2362
|
+
value: input
|
|
2363
|
+
}
|
|
2364
|
+
),
|
|
2365
|
+
inputPlugins.popover
|
|
2366
|
+
] })
|
|
2159
2367
|
] }),
|
|
2160
|
-
/* @__PURE__ */
|
|
2161
|
-
/* @__PURE__ */
|
|
2162
|
-
/* @__PURE__ */
|
|
2368
|
+
/* @__PURE__ */ jsxs13(PromptInputToolbar, { children: [
|
|
2369
|
+
/* @__PURE__ */ jsx21(PromptInputTools, { children: config?.features?.fileUpload === true && /* @__PURE__ */ jsx21(AttachButton, {}) }),
|
|
2370
|
+
/* @__PURE__ */ jsx21(PromptInputSubmit, { disabled: !input, status })
|
|
2163
2371
|
] })
|
|
2164
2372
|
] })
|
|
2165
2373
|
] })
|
|
@@ -2207,7 +2415,7 @@ function toHslTripletIfHex(value) {
|
|
|
2207
2415
|
}
|
|
2208
2416
|
|
|
2209
2417
|
// src/ChatWidget.tsx
|
|
2210
|
-
import { jsx as
|
|
2418
|
+
import { jsx as jsx22, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
2211
2419
|
function ChatWidget({
|
|
2212
2420
|
userId,
|
|
2213
2421
|
conversationId,
|
|
@@ -2223,14 +2431,15 @@ function ChatWidget({
|
|
|
2223
2431
|
onClose,
|
|
2224
2432
|
headerActions,
|
|
2225
2433
|
open,
|
|
2226
|
-
onOpenChange
|
|
2434
|
+
onOpenChange,
|
|
2435
|
+
inputPlugins
|
|
2227
2436
|
}) {
|
|
2228
2437
|
const layout = display?.layout || "popup";
|
|
2229
2438
|
const isControlled = open !== void 0;
|
|
2230
2439
|
const showToggleButton = !isControlled && display?.showToggleButton !== false;
|
|
2231
2440
|
const resizable = layout === "popup" && display?.resizable !== false;
|
|
2232
2441
|
const size = display?.size || "default";
|
|
2233
|
-
const [internalIsOpen, setInternalIsOpen] =
|
|
2442
|
+
const [internalIsOpen, setInternalIsOpen] = useState6(
|
|
2234
2443
|
layout !== "popup" ? true : display?.defaultOpen || false
|
|
2235
2444
|
);
|
|
2236
2445
|
const isOpen = isControlled ? open : internalIsOpen;
|
|
@@ -2241,9 +2450,9 @@ function ChatWidget({
|
|
|
2241
2450
|
setInternalIsOpen(next);
|
|
2242
2451
|
}
|
|
2243
2452
|
};
|
|
2244
|
-
const [isResizing, setIsResizing] =
|
|
2245
|
-
const containerRef =
|
|
2246
|
-
const customStyles =
|
|
2453
|
+
const [isResizing, setIsResizing] = useState6(false);
|
|
2454
|
+
const containerRef = useRef5(null);
|
|
2455
|
+
const customStyles = useMemo4(() => {
|
|
2247
2456
|
const styles = {};
|
|
2248
2457
|
if (display?.width) {
|
|
2249
2458
|
styles["--chat-widget-width"] = display.width;
|
|
@@ -2262,14 +2471,14 @@ function ChatWidget({
|
|
|
2262
2471
|
}
|
|
2263
2472
|
return styles;
|
|
2264
2473
|
}, [display?.width, theme?.primaryColor, theme?.backgroundColor, theme?.textColor, theme?.tokens]);
|
|
2265
|
-
const handleMouseDown =
|
|
2474
|
+
const handleMouseDown = useCallback5((e) => {
|
|
2266
2475
|
if (!resizable) return;
|
|
2267
2476
|
e.preventDefault();
|
|
2268
2477
|
setIsResizing(true);
|
|
2269
2478
|
document.body.style.cursor = "ew-resize";
|
|
2270
2479
|
document.body.style.userSelect = "none";
|
|
2271
2480
|
}, [resizable]);
|
|
2272
|
-
|
|
2481
|
+
useEffect6(() => {
|
|
2273
2482
|
if (!isResizing) return;
|
|
2274
2483
|
const handleMouseMove = (e) => {
|
|
2275
2484
|
if (!containerRef.current) return;
|
|
@@ -2291,25 +2500,26 @@ function ChatWidget({
|
|
|
2291
2500
|
document.removeEventListener("mouseup", handleMouseUp);
|
|
2292
2501
|
};
|
|
2293
2502
|
}, [isResizing]);
|
|
2294
|
-
const config =
|
|
2503
|
+
const config = useMemo4(() => ({
|
|
2295
2504
|
userId,
|
|
2296
2505
|
model,
|
|
2297
2506
|
systemPrompt,
|
|
2298
2507
|
temperature,
|
|
2299
2508
|
theme,
|
|
2300
2509
|
features,
|
|
2301
|
-
starterPrompts
|
|
2302
|
-
|
|
2510
|
+
starterPrompts,
|
|
2511
|
+
inputPlugins
|
|
2512
|
+
}), [userId, model, systemPrompt, temperature, theme, features, starterPrompts, inputPlugins]);
|
|
2303
2513
|
const togglePosition = display?.toggleButtonPosition || { bottom: "24px", right: "24px" };
|
|
2304
2514
|
const themeClass = theme?.mode === "dark" ? "dark" : "";
|
|
2305
2515
|
if (layout === "inline") {
|
|
2306
|
-
return /* @__PURE__ */
|
|
2516
|
+
return /* @__PURE__ */ jsx22(ChatStorageProvider, { userId, children: /* @__PURE__ */ jsx22(
|
|
2307
2517
|
"div",
|
|
2308
2518
|
{
|
|
2309
2519
|
ref: containerRef,
|
|
2310
2520
|
className: `chat-widget-container chat-widget-inline chat-widget-content ${themeClass} ${className || ""}`,
|
|
2311
2521
|
style: customStyles,
|
|
2312
|
-
children: /* @__PURE__ */
|
|
2522
|
+
children: /* @__PURE__ */ jsx22(
|
|
2313
2523
|
ChatInterface,
|
|
2314
2524
|
{
|
|
2315
2525
|
id: conversationId,
|
|
@@ -2323,13 +2533,13 @@ function ChatWidget({
|
|
|
2323
2533
|
) });
|
|
2324
2534
|
}
|
|
2325
2535
|
if (layout === "page") {
|
|
2326
|
-
return /* @__PURE__ */
|
|
2536
|
+
return /* @__PURE__ */ jsx22(ChatStorageProvider, { userId, children: /* @__PURE__ */ jsx22(
|
|
2327
2537
|
"div",
|
|
2328
2538
|
{
|
|
2329
2539
|
ref: containerRef,
|
|
2330
2540
|
className: `chat-widget-container chat-widget-page chat-widget-content ${themeClass} ${className || ""}`,
|
|
2331
2541
|
style: customStyles,
|
|
2332
|
-
children: /* @__PURE__ */
|
|
2542
|
+
children: /* @__PURE__ */ jsx22(
|
|
2333
2543
|
ChatInterface,
|
|
2334
2544
|
{
|
|
2335
2545
|
id: conversationId,
|
|
@@ -2342,18 +2552,18 @@ function ChatWidget({
|
|
|
2342
2552
|
}
|
|
2343
2553
|
) });
|
|
2344
2554
|
}
|
|
2345
|
-
return /* @__PURE__ */
|
|
2346
|
-
showToggleButton && !isOpen && /* @__PURE__ */
|
|
2555
|
+
return /* @__PURE__ */ jsxs14(ChatStorageProvider, { userId, children: [
|
|
2556
|
+
showToggleButton && !isOpen && /* @__PURE__ */ jsx22(
|
|
2347
2557
|
"button",
|
|
2348
2558
|
{
|
|
2349
2559
|
onClick: () => setIsOpen(true),
|
|
2350
2560
|
className: "fixed z-50 rounded-full bg-primary text-primary-foreground shadow-lg hover:opacity-90 transition-all p-4",
|
|
2351
2561
|
style: togglePosition,
|
|
2352
2562
|
"aria-label": "Open chat",
|
|
2353
|
-
children: /* @__PURE__ */
|
|
2563
|
+
children: /* @__PURE__ */ jsx22(MessageCircle, { className: "h-6 w-6" })
|
|
2354
2564
|
}
|
|
2355
2565
|
),
|
|
2356
|
-
isOpen && /* @__PURE__ */
|
|
2566
|
+
isOpen && /* @__PURE__ */ jsxs14(
|
|
2357
2567
|
"div",
|
|
2358
2568
|
{
|
|
2359
2569
|
ref: containerRef,
|
|
@@ -2362,7 +2572,7 @@ function ChatWidget({
|
|
|
2362
2572
|
"data-resizing": isResizing,
|
|
2363
2573
|
style: customStyles,
|
|
2364
2574
|
children: [
|
|
2365
|
-
resizable && /* @__PURE__ */
|
|
2575
|
+
resizable && /* @__PURE__ */ jsx22(
|
|
2366
2576
|
"div",
|
|
2367
2577
|
{
|
|
2368
2578
|
onMouseDown: handleMouseDown,
|
|
@@ -2370,7 +2580,7 @@ function ChatWidget({
|
|
|
2370
2580
|
"aria-label": "Resize chat widget"
|
|
2371
2581
|
}
|
|
2372
2582
|
),
|
|
2373
|
-
/* @__PURE__ */
|
|
2583
|
+
/* @__PURE__ */ jsx22("div", { className: "w-full h-full overflow-hidden", children: /* @__PURE__ */ jsx22(
|
|
2374
2584
|
ChatInterface,
|
|
2375
2585
|
{
|
|
2376
2586
|
id: conversationId,
|
|
@@ -2391,7 +2601,7 @@ function ChatWidget({
|
|
|
2391
2601
|
var ChatWidget_default = ChatWidget;
|
|
2392
2602
|
|
|
2393
2603
|
// src/hooks/use-chat-theme.ts
|
|
2394
|
-
import { useState as
|
|
2604
|
+
import { useState as useState7, useEffect as useEffect7 } from "react";
|
|
2395
2605
|
|
|
2396
2606
|
// src/utils/models.ts
|
|
2397
2607
|
var MODELS = [
|
|
@@ -2511,13 +2721,13 @@ var defaultThemeMode = "light";
|
|
|
2511
2721
|
function useChatTheme() {
|
|
2512
2722
|
const { storageKeyPrefix } = useChatStorageKey();
|
|
2513
2723
|
const keyPrefix = storageKeyPrefix ? `chat-${storageKeyPrefix}-` : "chat-";
|
|
2514
|
-
const [theme, setTheme] =
|
|
2515
|
-
const [conversationStarters, setConversationStarters] =
|
|
2516
|
-
const [model, setModel] =
|
|
2517
|
-
const [systemPrompt, setSystemPrompt] =
|
|
2518
|
-
const [temperature, setTemperature] =
|
|
2519
|
-
const [themeMode, setThemeMode] =
|
|
2520
|
-
|
|
2724
|
+
const [theme, setTheme] = useState7(defaultTheme);
|
|
2725
|
+
const [conversationStarters, setConversationStarters] = useState7(defaultConversationStarters);
|
|
2726
|
+
const [model, setModel] = useState7(defaultModel);
|
|
2727
|
+
const [systemPrompt, setSystemPrompt] = useState7(defaultSystemPrompt);
|
|
2728
|
+
const [temperature, setTemperature] = useState7(defaultTemperature);
|
|
2729
|
+
const [themeMode, setThemeMode] = useState7(defaultThemeMode);
|
|
2730
|
+
useEffect7(() => {
|
|
2521
2731
|
const savedTheme = localStorage.getItem(`${keyPrefix}theme`);
|
|
2522
2732
|
if (savedTheme) {
|
|
2523
2733
|
try {
|
|
@@ -2605,7 +2815,7 @@ function useChatTheme() {
|
|
|
2605
2815
|
window.removeEventListener("chat-theme-mode-change", handleThemeModeChange);
|
|
2606
2816
|
};
|
|
2607
2817
|
}, [keyPrefix]);
|
|
2608
|
-
|
|
2818
|
+
useEffect7(() => {
|
|
2609
2819
|
localStorage.setItem(`${keyPrefix}theme`, JSON.stringify(theme));
|
|
2610
2820
|
const root = document.documentElement;
|
|
2611
2821
|
if (themeMode === "light") {
|
|
@@ -2621,23 +2831,23 @@ function useChatTheme() {
|
|
|
2621
2831
|
root.style.setProperty("--chat-font-size", `${theme.fontSize}px`);
|
|
2622
2832
|
window.dispatchEvent(new CustomEvent("chat-theme-change", { detail: theme }));
|
|
2623
2833
|
}, [theme, themeMode, keyPrefix]);
|
|
2624
|
-
|
|
2834
|
+
useEffect7(() => {
|
|
2625
2835
|
localStorage.setItem(`${keyPrefix}conversation-starters`, JSON.stringify(conversationStarters));
|
|
2626
2836
|
window.dispatchEvent(new CustomEvent("chat-starters-change", { detail: conversationStarters }));
|
|
2627
2837
|
}, [conversationStarters, keyPrefix]);
|
|
2628
|
-
|
|
2838
|
+
useEffect7(() => {
|
|
2629
2839
|
localStorage.setItem(`${keyPrefix}model`, model);
|
|
2630
2840
|
window.dispatchEvent(new CustomEvent("chat-model-change", { detail: model }));
|
|
2631
2841
|
}, [model, keyPrefix]);
|
|
2632
|
-
|
|
2842
|
+
useEffect7(() => {
|
|
2633
2843
|
localStorage.setItem(`${keyPrefix}system-prompt`, systemPrompt);
|
|
2634
2844
|
window.dispatchEvent(new CustomEvent("chat-system-prompt-change", { detail: systemPrompt }));
|
|
2635
2845
|
}, [systemPrompt, keyPrefix]);
|
|
2636
|
-
|
|
2846
|
+
useEffect7(() => {
|
|
2637
2847
|
localStorage.setItem(`${keyPrefix}temperature`, temperature.toString());
|
|
2638
2848
|
window.dispatchEvent(new CustomEvent("chat-temperature-change", { detail: temperature }));
|
|
2639
2849
|
}, [temperature, keyPrefix]);
|
|
2640
|
-
|
|
2850
|
+
useEffect7(() => {
|
|
2641
2851
|
localStorage.setItem(`${keyPrefix}theme-mode`, themeMode);
|
|
2642
2852
|
window.dispatchEvent(new CustomEvent("chat-theme-mode-change", { detail: themeMode }));
|
|
2643
2853
|
}, [themeMode, keyPrefix]);
|
|
@@ -2706,11 +2916,11 @@ function useChatTheme() {
|
|
|
2706
2916
|
}
|
|
2707
2917
|
|
|
2708
2918
|
// src/ui/input.tsx
|
|
2709
|
-
import * as
|
|
2710
|
-
import { jsx as
|
|
2711
|
-
var Input =
|
|
2919
|
+
import * as React2 from "react";
|
|
2920
|
+
import { jsx as jsx23 } from "react/jsx-runtime";
|
|
2921
|
+
var Input = React2.forwardRef(
|
|
2712
2922
|
({ className, type, ...props }, ref) => {
|
|
2713
|
-
return /* @__PURE__ */
|
|
2923
|
+
return /* @__PURE__ */ jsx23(
|
|
2714
2924
|
"input",
|
|
2715
2925
|
{
|
|
2716
2926
|
type,
|
|
@@ -2729,22 +2939,22 @@ Input.displayName = "Input";
|
|
|
2729
2939
|
// src/ui/dialog.tsx
|
|
2730
2940
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
2731
2941
|
import { XIcon as XIcon3 } from "lucide-react";
|
|
2732
|
-
import { jsx as
|
|
2942
|
+
import { jsx as jsx24, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
2733
2943
|
function Dialog({
|
|
2734
2944
|
...props
|
|
2735
2945
|
}) {
|
|
2736
|
-
return /* @__PURE__ */
|
|
2946
|
+
return /* @__PURE__ */ jsx24(DialogPrimitive.Root, { "data-slot": "dialog", ...props });
|
|
2737
2947
|
}
|
|
2738
2948
|
function DialogPortal({
|
|
2739
2949
|
...props
|
|
2740
2950
|
}) {
|
|
2741
|
-
return /* @__PURE__ */
|
|
2951
|
+
return /* @__PURE__ */ jsx24(DialogPrimitive.Portal, { "data-slot": "dialog-portal", ...props });
|
|
2742
2952
|
}
|
|
2743
2953
|
function DialogOverlay({
|
|
2744
2954
|
className,
|
|
2745
2955
|
...props
|
|
2746
2956
|
}) {
|
|
2747
|
-
return /* @__PURE__ */
|
|
2957
|
+
return /* @__PURE__ */ jsx24(
|
|
2748
2958
|
DialogPrimitive.Overlay,
|
|
2749
2959
|
{
|
|
2750
2960
|
"data-slot": "dialog-overlay",
|
|
@@ -2762,9 +2972,9 @@ function DialogContent({
|
|
|
2762
2972
|
showCloseButton = true,
|
|
2763
2973
|
...props
|
|
2764
2974
|
}) {
|
|
2765
|
-
return /* @__PURE__ */
|
|
2766
|
-
/* @__PURE__ */
|
|
2767
|
-
/* @__PURE__ */
|
|
2975
|
+
return /* @__PURE__ */ jsxs15(DialogPortal, { "data-slot": "dialog-portal", children: [
|
|
2976
|
+
/* @__PURE__ */ jsx24(DialogOverlay, {}),
|
|
2977
|
+
/* @__PURE__ */ jsxs15(
|
|
2768
2978
|
DialogPrimitive.Content,
|
|
2769
2979
|
{
|
|
2770
2980
|
"data-slot": "dialog-content",
|
|
@@ -2775,14 +2985,14 @@ function DialogContent({
|
|
|
2775
2985
|
...props,
|
|
2776
2986
|
children: [
|
|
2777
2987
|
children,
|
|
2778
|
-
showCloseButton && /* @__PURE__ */
|
|
2988
|
+
showCloseButton && /* @__PURE__ */ jsxs15(
|
|
2779
2989
|
DialogPrimitive.Close,
|
|
2780
2990
|
{
|
|
2781
2991
|
"data-slot": "dialog-close",
|
|
2782
2992
|
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",
|
|
2783
2993
|
children: [
|
|
2784
|
-
/* @__PURE__ */
|
|
2785
|
-
/* @__PURE__ */
|
|
2994
|
+
/* @__PURE__ */ jsx24(XIcon3, {}),
|
|
2995
|
+
/* @__PURE__ */ jsx24("span", { className: "sr-only", children: "Close" })
|
|
2786
2996
|
]
|
|
2787
2997
|
}
|
|
2788
2998
|
)
|
|
@@ -2792,7 +3002,7 @@ function DialogContent({
|
|
|
2792
3002
|
] });
|
|
2793
3003
|
}
|
|
2794
3004
|
function DialogHeader({ className, ...props }) {
|
|
2795
|
-
return /* @__PURE__ */
|
|
3005
|
+
return /* @__PURE__ */ jsx24(
|
|
2796
3006
|
"div",
|
|
2797
3007
|
{
|
|
2798
3008
|
"data-slot": "dialog-header",
|
|
@@ -2805,7 +3015,7 @@ function DialogTitle({
|
|
|
2805
3015
|
className,
|
|
2806
3016
|
...props
|
|
2807
3017
|
}) {
|
|
2808
|
-
return /* @__PURE__ */
|
|
3018
|
+
return /* @__PURE__ */ jsx24(
|
|
2809
3019
|
DialogPrimitive.Title,
|
|
2810
3020
|
{
|
|
2811
3021
|
"data-slot": "dialog-title",
|
|
@@ -2818,7 +3028,7 @@ function DialogDescription({
|
|
|
2818
3028
|
className,
|
|
2819
3029
|
...props
|
|
2820
3030
|
}) {
|
|
2821
|
-
return /* @__PURE__ */
|
|
3031
|
+
return /* @__PURE__ */ jsx24(
|
|
2822
3032
|
DialogPrimitive.Description,
|
|
2823
3033
|
{
|
|
2824
3034
|
"data-slot": "dialog-description",
|