@copilotkitnext/react 0.0.13 → 0.0.15
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 +47 -20
- package/dist/index.d.ts +47 -20
- package/dist/index.js +906 -308
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +935 -330
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +5 -10
- package/vitest.config.mjs +5 -0
package/dist/index.js
CHANGED
|
@@ -47,11 +47,13 @@ __export(index_exports, {
|
|
|
47
47
|
CopilotChatUserMessage: () => CopilotChatUserMessage_default,
|
|
48
48
|
CopilotChatView: () => CopilotChatView_default,
|
|
49
49
|
CopilotKitCoreReact: () => CopilotKitCoreReact,
|
|
50
|
+
CopilotKitInspector: () => CopilotKitInspector,
|
|
50
51
|
CopilotKitProvider: () => CopilotKitProvider,
|
|
51
52
|
CopilotModalHeader: () => CopilotModalHeader,
|
|
53
|
+
CopilotPopup: () => CopilotPopup,
|
|
54
|
+
CopilotPopupView: () => CopilotPopupView,
|
|
52
55
|
CopilotSidebar: () => CopilotSidebar,
|
|
53
56
|
CopilotSidebarView: () => CopilotSidebarView,
|
|
54
|
-
WebInspector: () => WebInspector,
|
|
55
57
|
WildcardToolCallRender: () => WildcardToolCallRender,
|
|
56
58
|
defineToolCallRenderer: () => defineToolCallRenderer,
|
|
57
59
|
useAgent: () => useAgent,
|
|
@@ -560,6 +562,8 @@ function renderSlot(slot, DefaultComponent, props) {
|
|
|
560
562
|
|
|
561
563
|
// src/components/chat/CopilotChatInput.tsx
|
|
562
564
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
565
|
+
var SLASH_MENU_MAX_VISIBLE_ITEMS = 5;
|
|
566
|
+
var SLASH_MENU_ITEM_HEIGHT_PX = 40;
|
|
563
567
|
function CopilotChatInput({
|
|
564
568
|
mode = "input",
|
|
565
569
|
onSubmitMessage,
|
|
@@ -571,15 +575,12 @@ function CopilotChatInput({
|
|
|
571
575
|
value,
|
|
572
576
|
toolsMenu,
|
|
573
577
|
autoFocus = true,
|
|
574
|
-
additionalToolbarItems,
|
|
575
578
|
textArea,
|
|
576
579
|
sendButton,
|
|
577
580
|
startTranscribeButton,
|
|
578
581
|
cancelTranscribeButton,
|
|
579
582
|
finishTranscribeButton,
|
|
580
|
-
|
|
581
|
-
toolsButton,
|
|
582
|
-
toolbar,
|
|
583
|
+
addMenuButton,
|
|
583
584
|
audioRecorder,
|
|
584
585
|
children,
|
|
585
586
|
className,
|
|
@@ -593,10 +594,82 @@ function CopilotChatInput({
|
|
|
593
594
|
}
|
|
594
595
|
}, [isControlled, value]);
|
|
595
596
|
const resolvedValue = isControlled ? value ?? "" : internalValue;
|
|
597
|
+
const [layout, setLayout] = (0, import_react4.useState)("compact");
|
|
598
|
+
const ignoreResizeRef = (0, import_react4.useRef)(false);
|
|
599
|
+
const resizeEvaluationRafRef = (0, import_react4.useRef)(null);
|
|
600
|
+
const isExpanded = mode === "input" && layout === "expanded";
|
|
601
|
+
const [commandQuery, setCommandQuery] = (0, import_react4.useState)(null);
|
|
602
|
+
const [slashHighlightIndex, setSlashHighlightIndex] = (0, import_react4.useState)(0);
|
|
596
603
|
const inputRef = (0, import_react4.useRef)(null);
|
|
604
|
+
const gridRef = (0, import_react4.useRef)(null);
|
|
605
|
+
const addButtonContainerRef = (0, import_react4.useRef)(null);
|
|
606
|
+
const actionsContainerRef = (0, import_react4.useRef)(null);
|
|
597
607
|
const audioRecorderRef = (0, import_react4.useRef)(null);
|
|
608
|
+
const slashMenuRef = (0, import_react4.useRef)(null);
|
|
598
609
|
const config = useCopilotChatConfiguration();
|
|
610
|
+
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
599
611
|
const previousModalStateRef = (0, import_react4.useRef)(void 0);
|
|
612
|
+
const measurementCanvasRef = (0, import_react4.useRef)(null);
|
|
613
|
+
const measurementsRef = (0, import_react4.useRef)({
|
|
614
|
+
singleLineHeight: 0,
|
|
615
|
+
maxHeight: 0,
|
|
616
|
+
paddingLeft: 0,
|
|
617
|
+
paddingRight: 0
|
|
618
|
+
});
|
|
619
|
+
const commandItems = (0, import_react4.useMemo)(() => {
|
|
620
|
+
const entries = [];
|
|
621
|
+
const seen = /* @__PURE__ */ new Set();
|
|
622
|
+
const pushItem = (item) => {
|
|
623
|
+
if (item === "-") {
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
if (item.items && item.items.length > 0) {
|
|
627
|
+
for (const nested of item.items) {
|
|
628
|
+
pushItem(nested);
|
|
629
|
+
}
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
if (!seen.has(item.label)) {
|
|
633
|
+
seen.add(item.label);
|
|
634
|
+
entries.push(item);
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
if (onAddFile) {
|
|
638
|
+
pushItem({
|
|
639
|
+
label: labels.chatInputToolbarAddButtonLabel,
|
|
640
|
+
action: onAddFile
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
if (toolsMenu && toolsMenu.length > 0) {
|
|
644
|
+
for (const item of toolsMenu) {
|
|
645
|
+
pushItem(item);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return entries;
|
|
649
|
+
}, [labels.chatInputToolbarAddButtonLabel, onAddFile, toolsMenu]);
|
|
650
|
+
const filteredCommands = (0, import_react4.useMemo)(() => {
|
|
651
|
+
if (commandQuery === null) {
|
|
652
|
+
return [];
|
|
653
|
+
}
|
|
654
|
+
if (commandItems.length === 0) {
|
|
655
|
+
return [];
|
|
656
|
+
}
|
|
657
|
+
const query = commandQuery.trim().toLowerCase();
|
|
658
|
+
if (query.length === 0) {
|
|
659
|
+
return commandItems;
|
|
660
|
+
}
|
|
661
|
+
const startsWith = [];
|
|
662
|
+
const contains = [];
|
|
663
|
+
for (const item of commandItems) {
|
|
664
|
+
const label = item.label.toLowerCase();
|
|
665
|
+
if (label.startsWith(query)) {
|
|
666
|
+
startsWith.push(item);
|
|
667
|
+
} else if (label.includes(query)) {
|
|
668
|
+
contains.push(item);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return [...startsWith, ...contains];
|
|
672
|
+
}, [commandItems, commandQuery]);
|
|
600
673
|
(0, import_react4.useEffect)(() => {
|
|
601
674
|
if (!autoFocus) {
|
|
602
675
|
previousModalStateRef.current = config?.isModalOpen;
|
|
@@ -607,6 +680,29 @@ function CopilotChatInput({
|
|
|
607
680
|
}
|
|
608
681
|
previousModalStateRef.current = config?.isModalOpen;
|
|
609
682
|
}, [config?.isModalOpen, autoFocus]);
|
|
683
|
+
(0, import_react4.useEffect)(() => {
|
|
684
|
+
if (commandItems.length === 0 && commandQuery !== null) {
|
|
685
|
+
setCommandQuery(null);
|
|
686
|
+
}
|
|
687
|
+
}, [commandItems.length, commandQuery]);
|
|
688
|
+
const previousCommandQueryRef = (0, import_react4.useRef)(null);
|
|
689
|
+
(0, import_react4.useEffect)(() => {
|
|
690
|
+
if (commandQuery !== null && commandQuery !== previousCommandQueryRef.current && filteredCommands.length > 0) {
|
|
691
|
+
setSlashHighlightIndex(0);
|
|
692
|
+
}
|
|
693
|
+
previousCommandQueryRef.current = commandQuery;
|
|
694
|
+
}, [commandQuery, filteredCommands.length]);
|
|
695
|
+
(0, import_react4.useEffect)(() => {
|
|
696
|
+
if (commandQuery === null) {
|
|
697
|
+
setSlashHighlightIndex(0);
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
if (filteredCommands.length === 0) {
|
|
701
|
+
setSlashHighlightIndex(-1);
|
|
702
|
+
} else if (slashHighlightIndex < 0 || slashHighlightIndex >= filteredCommands.length) {
|
|
703
|
+
setSlashHighlightIndex(0);
|
|
704
|
+
}
|
|
705
|
+
}, [commandQuery, filteredCommands, slashHighlightIndex]);
|
|
610
706
|
(0, import_react4.useEffect)(() => {
|
|
611
707
|
const recorder = audioRecorderRef.current;
|
|
612
708
|
if (!recorder) {
|
|
@@ -620,14 +716,103 @@ function CopilotChatInput({
|
|
|
620
716
|
}
|
|
621
717
|
}
|
|
622
718
|
}, [mode]);
|
|
719
|
+
(0, import_react4.useEffect)(() => {
|
|
720
|
+
if (mode !== "input") {
|
|
721
|
+
setLayout("compact");
|
|
722
|
+
setCommandQuery(null);
|
|
723
|
+
}
|
|
724
|
+
}, [mode]);
|
|
725
|
+
const updateSlashState = (0, import_react4.useCallback)(
|
|
726
|
+
(value2) => {
|
|
727
|
+
if (commandItems.length === 0) {
|
|
728
|
+
setCommandQuery((prev) => prev === null ? prev : null);
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
if (value2.startsWith("/")) {
|
|
732
|
+
const firstLine = value2.split(/\r?\n/, 1)[0] ?? "";
|
|
733
|
+
const query = firstLine.slice(1);
|
|
734
|
+
setCommandQuery((prev) => prev === query ? prev : query);
|
|
735
|
+
} else {
|
|
736
|
+
setCommandQuery((prev) => prev === null ? prev : null);
|
|
737
|
+
}
|
|
738
|
+
},
|
|
739
|
+
[commandItems.length]
|
|
740
|
+
);
|
|
741
|
+
(0, import_react4.useEffect)(() => {
|
|
742
|
+
updateSlashState(resolvedValue);
|
|
743
|
+
}, [resolvedValue, updateSlashState]);
|
|
623
744
|
const handleChange = (e) => {
|
|
624
745
|
const nextValue = e.target.value;
|
|
625
746
|
if (!isControlled) {
|
|
626
747
|
setInternalValue(nextValue);
|
|
627
748
|
}
|
|
628
749
|
onChange?.(nextValue);
|
|
750
|
+
updateSlashState(nextValue);
|
|
629
751
|
};
|
|
752
|
+
const clearInputValue = (0, import_react4.useCallback)(() => {
|
|
753
|
+
if (!isControlled) {
|
|
754
|
+
setInternalValue("");
|
|
755
|
+
}
|
|
756
|
+
if (onChange) {
|
|
757
|
+
onChange("");
|
|
758
|
+
}
|
|
759
|
+
}, [isControlled, onChange]);
|
|
760
|
+
const runCommand = (0, import_react4.useCallback)(
|
|
761
|
+
(item) => {
|
|
762
|
+
clearInputValue();
|
|
763
|
+
item.action?.();
|
|
764
|
+
setCommandQuery(null);
|
|
765
|
+
setSlashHighlightIndex(0);
|
|
766
|
+
requestAnimationFrame(() => {
|
|
767
|
+
inputRef.current?.focus();
|
|
768
|
+
});
|
|
769
|
+
},
|
|
770
|
+
[clearInputValue]
|
|
771
|
+
);
|
|
630
772
|
const handleKeyDown = (e) => {
|
|
773
|
+
if (commandQuery !== null && mode === "input") {
|
|
774
|
+
if (e.key === "ArrowDown") {
|
|
775
|
+
if (filteredCommands.length > 0) {
|
|
776
|
+
e.preventDefault();
|
|
777
|
+
setSlashHighlightIndex((prev) => {
|
|
778
|
+
if (filteredCommands.length === 0) {
|
|
779
|
+
return prev;
|
|
780
|
+
}
|
|
781
|
+
const next = prev === -1 ? 0 : (prev + 1) % filteredCommands.length;
|
|
782
|
+
return next;
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
if (e.key === "ArrowUp") {
|
|
788
|
+
if (filteredCommands.length > 0) {
|
|
789
|
+
e.preventDefault();
|
|
790
|
+
setSlashHighlightIndex((prev) => {
|
|
791
|
+
if (filteredCommands.length === 0) {
|
|
792
|
+
return prev;
|
|
793
|
+
}
|
|
794
|
+
if (prev === -1) {
|
|
795
|
+
return filteredCommands.length - 1;
|
|
796
|
+
}
|
|
797
|
+
return prev <= 0 ? filteredCommands.length - 1 : prev - 1;
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
if (e.key === "Enter") {
|
|
803
|
+
const selected = slashHighlightIndex >= 0 ? filteredCommands[slashHighlightIndex] : void 0;
|
|
804
|
+
if (selected) {
|
|
805
|
+
e.preventDefault();
|
|
806
|
+
runCommand(selected);
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
if (e.key === "Escape") {
|
|
811
|
+
e.preventDefault();
|
|
812
|
+
setCommandQuery(null);
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
631
816
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
632
817
|
e.preventDefault();
|
|
633
818
|
send();
|
|
@@ -655,7 +840,11 @@ function CopilotChatInput({
|
|
|
655
840
|
value: resolvedValue,
|
|
656
841
|
onChange: handleChange,
|
|
657
842
|
onKeyDown: handleKeyDown,
|
|
658
|
-
autoFocus
|
|
843
|
+
autoFocus,
|
|
844
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
845
|
+
"w-full py-3",
|
|
846
|
+
isExpanded ? "px-5" : "pr-5"
|
|
847
|
+
)
|
|
659
848
|
});
|
|
660
849
|
const BoundAudioRecorder = renderSlot(audioRecorder, CopilotChatAudioRecorder, {
|
|
661
850
|
ref: audioRecorderRef
|
|
@@ -673,45 +862,20 @@ function CopilotChatInput({
|
|
|
673
862
|
const BoundFinishTranscribeButton = renderSlot(finishTranscribeButton, CopilotChatInput.FinishTranscribeButton, {
|
|
674
863
|
onClick: onFinishTranscribe
|
|
675
864
|
});
|
|
676
|
-
const
|
|
677
|
-
onClick: onAddFile,
|
|
678
|
-
disabled: mode === "transcribe"
|
|
679
|
-
});
|
|
680
|
-
const BoundToolsButton = renderSlot(toolsButton, CopilotChatInput.ToolsButton, {
|
|
865
|
+
const BoundAddMenuButton = renderSlot(addMenuButton, CopilotChatInput.AddMenuButton, {
|
|
681
866
|
disabled: mode === "transcribe",
|
|
867
|
+
onAddFile,
|
|
682
868
|
toolsMenu
|
|
683
869
|
});
|
|
684
|
-
const BoundToolbar = renderSlot(
|
|
685
|
-
typeof toolbar === "string" || toolbar === void 0 ? (0, import_tailwind_merge3.twMerge)(toolbar, "w-full h-[60px] bg-transparent flex items-center justify-between") : toolbar,
|
|
686
|
-
CopilotChatInput.Toolbar,
|
|
687
|
-
{
|
|
688
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
689
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center", children: [
|
|
690
|
-
onAddFile && BoundAddFileButton,
|
|
691
|
-
BoundToolsButton,
|
|
692
|
-
additionalToolbarItems
|
|
693
|
-
] }),
|
|
694
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "flex items-center", children: mode === "transcribe" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
695
|
-
onCancelTranscribe && BoundCancelTranscribeButton,
|
|
696
|
-
onFinishTranscribe && BoundFinishTranscribeButton
|
|
697
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
698
|
-
onStartTranscribe && BoundStartTranscribeButton,
|
|
699
|
-
BoundSendButton
|
|
700
|
-
] }) })
|
|
701
|
-
] })
|
|
702
|
-
}
|
|
703
|
-
);
|
|
704
870
|
if (children) {
|
|
705
|
-
|
|
871
|
+
const childProps = {
|
|
706
872
|
textArea: BoundTextArea,
|
|
707
873
|
audioRecorder: BoundAudioRecorder,
|
|
708
874
|
sendButton: BoundSendButton,
|
|
709
875
|
startTranscribeButton: BoundStartTranscribeButton,
|
|
710
876
|
cancelTranscribeButton: BoundCancelTranscribeButton,
|
|
711
877
|
finishTranscribeButton: BoundFinishTranscribeButton,
|
|
712
|
-
|
|
713
|
-
toolsButton: BoundToolsButton,
|
|
714
|
-
toolbar: BoundToolbar,
|
|
878
|
+
addMenuButton: BoundAddMenuButton,
|
|
715
879
|
onSubmitMessage,
|
|
716
880
|
onStartTranscribe,
|
|
717
881
|
onCancelTranscribe,
|
|
@@ -719,9 +883,9 @@ function CopilotChatInput({
|
|
|
719
883
|
onAddFile,
|
|
720
884
|
mode,
|
|
721
885
|
toolsMenu,
|
|
722
|
-
autoFocus
|
|
723
|
-
|
|
724
|
-
|
|
886
|
+
autoFocus
|
|
887
|
+
};
|
|
888
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_jsx_runtime6.Fragment, { children: children(childProps) });
|
|
725
889
|
}
|
|
726
890
|
const handleContainerClick = (e) => {
|
|
727
891
|
const target = e.target;
|
|
@@ -729,7 +893,227 @@ function CopilotChatInput({
|
|
|
729
893
|
inputRef.current.focus();
|
|
730
894
|
}
|
|
731
895
|
};
|
|
732
|
-
|
|
896
|
+
const ensureMeasurements = (0, import_react4.useCallback)(() => {
|
|
897
|
+
const textarea = inputRef.current;
|
|
898
|
+
if (!textarea) {
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
const previousValue = textarea.value;
|
|
902
|
+
const previousHeight = textarea.style.height;
|
|
903
|
+
textarea.style.height = "auto";
|
|
904
|
+
const computedStyle = window.getComputedStyle(textarea);
|
|
905
|
+
const paddingLeft = parseFloat(computedStyle.paddingLeft) || 0;
|
|
906
|
+
const paddingRight = parseFloat(computedStyle.paddingRight) || 0;
|
|
907
|
+
const paddingTop = parseFloat(computedStyle.paddingTop) || 0;
|
|
908
|
+
const paddingBottom = parseFloat(computedStyle.paddingBottom) || 0;
|
|
909
|
+
textarea.value = "";
|
|
910
|
+
const singleLineHeight = textarea.scrollHeight;
|
|
911
|
+
textarea.value = previousValue;
|
|
912
|
+
const contentHeight = singleLineHeight - paddingTop - paddingBottom;
|
|
913
|
+
const maxHeight = contentHeight * 5 + paddingTop + paddingBottom;
|
|
914
|
+
measurementsRef.current = {
|
|
915
|
+
singleLineHeight,
|
|
916
|
+
maxHeight,
|
|
917
|
+
paddingLeft,
|
|
918
|
+
paddingRight
|
|
919
|
+
};
|
|
920
|
+
textarea.style.height = previousHeight;
|
|
921
|
+
textarea.style.maxHeight = `${maxHeight}px`;
|
|
922
|
+
}, []);
|
|
923
|
+
const adjustTextareaHeight = (0, import_react4.useCallback)(() => {
|
|
924
|
+
const textarea = inputRef.current;
|
|
925
|
+
if (!textarea) {
|
|
926
|
+
return 0;
|
|
927
|
+
}
|
|
928
|
+
if (measurementsRef.current.singleLineHeight === 0) {
|
|
929
|
+
ensureMeasurements();
|
|
930
|
+
}
|
|
931
|
+
const { maxHeight } = measurementsRef.current;
|
|
932
|
+
if (maxHeight) {
|
|
933
|
+
textarea.style.maxHeight = `${maxHeight}px`;
|
|
934
|
+
}
|
|
935
|
+
textarea.style.height = "auto";
|
|
936
|
+
const scrollHeight = textarea.scrollHeight;
|
|
937
|
+
if (maxHeight) {
|
|
938
|
+
textarea.style.height = `${Math.min(scrollHeight, maxHeight)}px`;
|
|
939
|
+
} else {
|
|
940
|
+
textarea.style.height = `${scrollHeight}px`;
|
|
941
|
+
}
|
|
942
|
+
return scrollHeight;
|
|
943
|
+
}, [ensureMeasurements]);
|
|
944
|
+
const updateLayout = (0, import_react4.useCallback)((nextLayout) => {
|
|
945
|
+
setLayout((prev) => {
|
|
946
|
+
if (prev === nextLayout) {
|
|
947
|
+
return prev;
|
|
948
|
+
}
|
|
949
|
+
ignoreResizeRef.current = true;
|
|
950
|
+
return nextLayout;
|
|
951
|
+
});
|
|
952
|
+
}, []);
|
|
953
|
+
const evaluateLayout = (0, import_react4.useCallback)(() => {
|
|
954
|
+
if (mode !== "input") {
|
|
955
|
+
updateLayout("compact");
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
|
|
959
|
+
const isMobileViewport = window.matchMedia("(max-width: 767px)").matches;
|
|
960
|
+
if (isMobileViewport) {
|
|
961
|
+
ensureMeasurements();
|
|
962
|
+
adjustTextareaHeight();
|
|
963
|
+
updateLayout("expanded");
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
const textarea = inputRef.current;
|
|
968
|
+
const grid = gridRef.current;
|
|
969
|
+
const addContainer = addButtonContainerRef.current;
|
|
970
|
+
const actionsContainer = actionsContainerRef.current;
|
|
971
|
+
if (!textarea || !grid || !addContainer || !actionsContainer) {
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
if (measurementsRef.current.singleLineHeight === 0) {
|
|
975
|
+
ensureMeasurements();
|
|
976
|
+
}
|
|
977
|
+
const scrollHeight = adjustTextareaHeight();
|
|
978
|
+
const baseline = measurementsRef.current.singleLineHeight;
|
|
979
|
+
const hasExplicitBreak = resolvedValue.includes("\n");
|
|
980
|
+
const renderedMultiline = baseline > 0 ? scrollHeight > baseline + 1 : false;
|
|
981
|
+
let shouldExpand = hasExplicitBreak || renderedMultiline;
|
|
982
|
+
if (!shouldExpand) {
|
|
983
|
+
const gridStyles = window.getComputedStyle(grid);
|
|
984
|
+
const paddingLeft = parseFloat(gridStyles.paddingLeft) || 0;
|
|
985
|
+
const paddingRight = parseFloat(gridStyles.paddingRight) || 0;
|
|
986
|
+
const columnGap = parseFloat(gridStyles.columnGap) || 0;
|
|
987
|
+
const gridAvailableWidth = grid.clientWidth - paddingLeft - paddingRight;
|
|
988
|
+
if (gridAvailableWidth > 0) {
|
|
989
|
+
const addWidth = addContainer.getBoundingClientRect().width;
|
|
990
|
+
const actionsWidth = actionsContainer.getBoundingClientRect().width;
|
|
991
|
+
const compactWidth = Math.max(gridAvailableWidth - addWidth - actionsWidth - columnGap * 2, 0);
|
|
992
|
+
const canvas = measurementCanvasRef.current ?? document.createElement("canvas");
|
|
993
|
+
if (!measurementCanvasRef.current) {
|
|
994
|
+
measurementCanvasRef.current = canvas;
|
|
995
|
+
}
|
|
996
|
+
const context = canvas.getContext("2d");
|
|
997
|
+
if (context) {
|
|
998
|
+
const textareaStyles = window.getComputedStyle(textarea);
|
|
999
|
+
const font = textareaStyles.font || `${textareaStyles.fontStyle} ${textareaStyles.fontVariant} ${textareaStyles.fontWeight} ${textareaStyles.fontSize}/${textareaStyles.lineHeight} ${textareaStyles.fontFamily}`;
|
|
1000
|
+
context.font = font;
|
|
1001
|
+
const compactInnerWidth = Math.max(
|
|
1002
|
+
compactWidth - (measurementsRef.current.paddingLeft || 0) - (measurementsRef.current.paddingRight || 0),
|
|
1003
|
+
0
|
|
1004
|
+
);
|
|
1005
|
+
if (compactInnerWidth > 0) {
|
|
1006
|
+
const lines = resolvedValue.length > 0 ? resolvedValue.split("\n") : [""];
|
|
1007
|
+
let longestWidth = 0;
|
|
1008
|
+
for (const line of lines) {
|
|
1009
|
+
const metrics = context.measureText(line || " ");
|
|
1010
|
+
if (metrics.width > longestWidth) {
|
|
1011
|
+
longestWidth = metrics.width;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
if (longestWidth > compactInnerWidth) {
|
|
1015
|
+
shouldExpand = true;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
const nextLayout = shouldExpand ? "expanded" : "compact";
|
|
1022
|
+
updateLayout(nextLayout);
|
|
1023
|
+
}, [adjustTextareaHeight, ensureMeasurements, mode, resolvedValue, updateLayout]);
|
|
1024
|
+
(0, import_react4.useLayoutEffect)(() => {
|
|
1025
|
+
evaluateLayout();
|
|
1026
|
+
}, [evaluateLayout]);
|
|
1027
|
+
(0, import_react4.useEffect)(() => {
|
|
1028
|
+
if (typeof ResizeObserver === "undefined") {
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
const textarea = inputRef.current;
|
|
1032
|
+
const grid = gridRef.current;
|
|
1033
|
+
const addContainer = addButtonContainerRef.current;
|
|
1034
|
+
const actionsContainer = actionsContainerRef.current;
|
|
1035
|
+
if (!textarea || !grid || !addContainer || !actionsContainer) {
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
const scheduleEvaluation = () => {
|
|
1039
|
+
if (ignoreResizeRef.current) {
|
|
1040
|
+
ignoreResizeRef.current = false;
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
if (typeof window === "undefined") {
|
|
1044
|
+
evaluateLayout();
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
if (resizeEvaluationRafRef.current !== null) {
|
|
1048
|
+
cancelAnimationFrame(resizeEvaluationRafRef.current);
|
|
1049
|
+
}
|
|
1050
|
+
resizeEvaluationRafRef.current = window.requestAnimationFrame(() => {
|
|
1051
|
+
resizeEvaluationRafRef.current = null;
|
|
1052
|
+
evaluateLayout();
|
|
1053
|
+
});
|
|
1054
|
+
};
|
|
1055
|
+
const observer = new ResizeObserver(() => {
|
|
1056
|
+
scheduleEvaluation();
|
|
1057
|
+
});
|
|
1058
|
+
observer.observe(grid);
|
|
1059
|
+
observer.observe(addContainer);
|
|
1060
|
+
observer.observe(actionsContainer);
|
|
1061
|
+
observer.observe(textarea);
|
|
1062
|
+
return () => {
|
|
1063
|
+
observer.disconnect();
|
|
1064
|
+
if (typeof window !== "undefined" && resizeEvaluationRafRef.current !== null) {
|
|
1065
|
+
cancelAnimationFrame(resizeEvaluationRafRef.current);
|
|
1066
|
+
resizeEvaluationRafRef.current = null;
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
}, [evaluateLayout]);
|
|
1070
|
+
const slashMenuVisible = commandQuery !== null && commandItems.length > 0;
|
|
1071
|
+
(0, import_react4.useEffect)(() => {
|
|
1072
|
+
if (!slashMenuVisible || slashHighlightIndex < 0) {
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
const active = slashMenuRef.current?.querySelector(
|
|
1076
|
+
`[data-slash-index="${slashHighlightIndex}"]`
|
|
1077
|
+
);
|
|
1078
|
+
active?.scrollIntoView({ block: "nearest" });
|
|
1079
|
+
}, [slashMenuVisible, slashHighlightIndex]);
|
|
1080
|
+
const slashMenu = slashMenuVisible ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1081
|
+
"div",
|
|
1082
|
+
{
|
|
1083
|
+
"data-testid": "copilot-slash-menu",
|
|
1084
|
+
role: "listbox",
|
|
1085
|
+
"aria-label": "Slash commands",
|
|
1086
|
+
ref: slashMenuRef,
|
|
1087
|
+
className: "absolute bottom-full left-0 right-0 z-30 mb-2 max-h-64 overflow-y-auto rounded-lg border border-border bg-white shadow-lg dark:border-[#3a3a3a] dark:bg-[#1f1f1f]",
|
|
1088
|
+
style: { maxHeight: `${SLASH_MENU_MAX_VISIBLE_ITEMS * SLASH_MENU_ITEM_HEIGHT_PX}px` },
|
|
1089
|
+
children: filteredCommands.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "px-3 py-2 text-sm text-muted-foreground", children: "No commands found" }) : filteredCommands.map((item, index) => {
|
|
1090
|
+
const isActive = index === slashHighlightIndex;
|
|
1091
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1092
|
+
"button",
|
|
1093
|
+
{
|
|
1094
|
+
type: "button",
|
|
1095
|
+
role: "option",
|
|
1096
|
+
"aria-selected": isActive,
|
|
1097
|
+
"data-active": isActive ? "true" : void 0,
|
|
1098
|
+
"data-slash-index": index,
|
|
1099
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
1100
|
+
"w-full px-3 py-2 text-left text-sm transition-colors",
|
|
1101
|
+
"hover:bg-muted dark:hover:bg-[#2f2f2f]",
|
|
1102
|
+
isActive ? "bg-muted dark:bg-[#2f2f2f]" : "bg-transparent"
|
|
1103
|
+
),
|
|
1104
|
+
onMouseEnter: () => setSlashHighlightIndex(index),
|
|
1105
|
+
onMouseDown: (event) => {
|
|
1106
|
+
event.preventDefault();
|
|
1107
|
+
runCommand(item);
|
|
1108
|
+
},
|
|
1109
|
+
children: item.label
|
|
1110
|
+
},
|
|
1111
|
+
`${item.label}-${index}`
|
|
1112
|
+
);
|
|
1113
|
+
})
|
|
1114
|
+
}
|
|
1115
|
+
) : null;
|
|
1116
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
733
1117
|
"div",
|
|
734
1118
|
{
|
|
735
1119
|
className: (0, import_tailwind_merge3.twMerge)(
|
|
@@ -747,10 +1131,62 @@ function CopilotChatInput({
|
|
|
747
1131
|
),
|
|
748
1132
|
onClick: handleContainerClick,
|
|
749
1133
|
...props,
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
1134
|
+
"data-layout": isExpanded ? "expanded" : "compact",
|
|
1135
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
1136
|
+
"div",
|
|
1137
|
+
{
|
|
1138
|
+
ref: gridRef,
|
|
1139
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
1140
|
+
"grid w-full gap-x-3 gap-y-3 px-3 py-2",
|
|
1141
|
+
isExpanded ? "grid-cols-[auto_minmax(0,1fr)_auto] grid-rows-[auto_auto]" : "grid-cols-[auto_minmax(0,1fr)_auto] items-center"
|
|
1142
|
+
),
|
|
1143
|
+
"data-layout": isExpanded ? "expanded" : "compact",
|
|
1144
|
+
children: [
|
|
1145
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1146
|
+
"div",
|
|
1147
|
+
{
|
|
1148
|
+
ref: addButtonContainerRef,
|
|
1149
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
1150
|
+
"flex items-center",
|
|
1151
|
+
isExpanded ? "row-start-2" : "row-start-1",
|
|
1152
|
+
"col-start-1"
|
|
1153
|
+
),
|
|
1154
|
+
children: BoundAddMenuButton
|
|
1155
|
+
}
|
|
1156
|
+
),
|
|
1157
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1158
|
+
"div",
|
|
1159
|
+
{
|
|
1160
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
1161
|
+
"relative flex min-w-0 flex-col",
|
|
1162
|
+
isExpanded ? "col-span-3 row-start-1" : "col-start-2 row-start-1"
|
|
1163
|
+
),
|
|
1164
|
+
children: mode === "transcribe" ? BoundAudioRecorder : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1165
|
+
BoundTextArea,
|
|
1166
|
+
slashMenu
|
|
1167
|
+
] })
|
|
1168
|
+
}
|
|
1169
|
+
),
|
|
1170
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1171
|
+
"div",
|
|
1172
|
+
{
|
|
1173
|
+
ref: actionsContainerRef,
|
|
1174
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
1175
|
+
"flex items-center justify-end gap-2",
|
|
1176
|
+
isExpanded ? "col-start-3 row-start-2" : "col-start-3 row-start-1"
|
|
1177
|
+
),
|
|
1178
|
+
children: mode === "transcribe" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1179
|
+
onCancelTranscribe && BoundCancelTranscribeButton,
|
|
1180
|
+
onFinishTranscribe && BoundFinishTranscribeButton
|
|
1181
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1182
|
+
onStartTranscribe && BoundStartTranscribeButton,
|
|
1183
|
+
BoundSendButton
|
|
1184
|
+
] })
|
|
1185
|
+
}
|
|
1186
|
+
)
|
|
1187
|
+
]
|
|
1188
|
+
}
|
|
1189
|
+
)
|
|
754
1190
|
}
|
|
755
1191
|
);
|
|
756
1192
|
}
|
|
@@ -811,124 +1247,110 @@ function CopilotChatInput({
|
|
|
811
1247
|
...props
|
|
812
1248
|
}
|
|
813
1249
|
);
|
|
814
|
-
CopilotChatInput2.
|
|
815
|
-
CopilotChatInput2.ToolbarButton,
|
|
816
|
-
{
|
|
817
|
-
icon: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.Plus, { className: "size-[20px]" }),
|
|
818
|
-
labelKey: "chatInputToolbarAddButtonLabel",
|
|
819
|
-
defaultClassName: "ml-2",
|
|
820
|
-
...props
|
|
821
|
-
}
|
|
822
|
-
);
|
|
823
|
-
CopilotChatInput2.ToolsButton = ({ className, toolsMenu, ...props }) => {
|
|
1250
|
+
CopilotChatInput2.AddMenuButton = ({ className, toolsMenu, onAddFile, disabled, ...props }) => {
|
|
824
1251
|
const config = useCopilotChatConfiguration();
|
|
825
1252
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
826
|
-
const
|
|
827
|
-
|
|
1253
|
+
const menuItems = (0, import_react4.useMemo)(() => {
|
|
1254
|
+
const items = [];
|
|
1255
|
+
if (onAddFile) {
|
|
1256
|
+
items.push({
|
|
1257
|
+
label: labels.chatInputToolbarAddButtonLabel,
|
|
1258
|
+
action: onAddFile
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
if (toolsMenu && toolsMenu.length > 0) {
|
|
1262
|
+
if (items.length > 0) {
|
|
1263
|
+
items.push("-");
|
|
1264
|
+
}
|
|
1265
|
+
for (const item of toolsMenu) {
|
|
1266
|
+
if (item === "-") {
|
|
1267
|
+
if (items.length === 0 || items[items.length - 1] === "-") {
|
|
1268
|
+
continue;
|
|
1269
|
+
}
|
|
1270
|
+
items.push(item);
|
|
1271
|
+
} else {
|
|
1272
|
+
items.push(item);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
while (items.length > 0 && items[items.length - 1] === "-") {
|
|
1276
|
+
items.pop();
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
return items;
|
|
1280
|
+
}, [onAddFile, toolsMenu, labels.chatInputToolbarAddButtonLabel]);
|
|
1281
|
+
const renderMenuItems = (0, import_react4.useCallback)(
|
|
1282
|
+
(items) => items.map((item, index) => {
|
|
828
1283
|
if (item === "-") {
|
|
829
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DropdownMenuSeparator, {}, index);
|
|
830
|
-
}
|
|
1284
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DropdownMenuSeparator, {}, `separator-${index}`);
|
|
1285
|
+
}
|
|
1286
|
+
if (item.items && item.items.length > 0) {
|
|
831
1287
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(DropdownMenuSub, { children: [
|
|
832
1288
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DropdownMenuSubTrigger, { children: item.label }),
|
|
833
1289
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DropdownMenuSubContent, { children: renderMenuItems(item.items) })
|
|
834
|
-
] }, index);
|
|
835
|
-
} else {
|
|
836
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DropdownMenuItem, { onClick: item.action, children: item.label }, index);
|
|
1290
|
+
] }, `group-${index}`);
|
|
837
1291
|
}
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
1292
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DropdownMenuItem, { onClick: item.action, children: item.label }, `item-${index}`);
|
|
1293
|
+
}),
|
|
1294
|
+
[]
|
|
1295
|
+
);
|
|
1296
|
+
const hasMenuItems = menuItems.length > 0;
|
|
1297
|
+
const isDisabled = disabled || !hasMenuItems;
|
|
843
1298
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(DropdownMenu, { children: [
|
|
844
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
855
|
-
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
|
|
1299
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Tooltip, { children: [
|
|
1300
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1301
|
+
Button,
|
|
1302
|
+
{
|
|
1303
|
+
type: "button",
|
|
1304
|
+
variant: "chatInputToolbarSecondary",
|
|
1305
|
+
size: "chatInputToolbarIcon",
|
|
1306
|
+
className: (0, import_tailwind_merge3.twMerge)("ml-1", className),
|
|
1307
|
+
disabled: isDisabled,
|
|
1308
|
+
...props,
|
|
1309
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.Plus, { className: "size-[20px]" })
|
|
1310
|
+
}
|
|
1311
|
+
) }) }),
|
|
1312
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TooltipContent, { side: "bottom", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "flex items-center gap-1 text-xs font-medium", children: [
|
|
1313
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "Add files and more" }),
|
|
1314
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("code", { className: "rounded bg-[#4a4a4a] px-1 py-[1px] font-mono text-[11px] text-white dark:bg-[#e0e0e0] dark:text-black", children: "/" })
|
|
1315
|
+
] }) })
|
|
1316
|
+
] }),
|
|
1317
|
+
hasMenuItems && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DropdownMenuContent, { side: "top", align: "start", children: renderMenuItems(menuItems) })
|
|
859
1318
|
] });
|
|
860
1319
|
};
|
|
861
|
-
CopilotChatInput2.
|
|
862
|
-
CopilotChatInput2.TextArea = (0, import_react4.forwardRef)(function TextArea2({ maxRows = 5, style, className, ...props }, ref) {
|
|
1320
|
+
CopilotChatInput2.TextArea = (0, import_react4.forwardRef)(function TextArea2({ style, className, autoFocus, ...props }, ref) {
|
|
863
1321
|
const internalTextareaRef = (0, import_react4.useRef)(null);
|
|
864
|
-
const [maxHeight, setMaxHeight] = (0, import_react4.useState)(0);
|
|
865
1322
|
const config = useCopilotChatConfiguration();
|
|
866
1323
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
867
1324
|
(0, import_react4.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
868
|
-
const adjustHeight = () => {
|
|
869
|
-
const textarea = internalTextareaRef.current;
|
|
870
|
-
if (textarea && maxHeight > 0) {
|
|
871
|
-
textarea.style.height = "auto";
|
|
872
|
-
textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;
|
|
873
|
-
}
|
|
874
|
-
};
|
|
875
1325
|
(0, import_react4.useEffect)(() => {
|
|
876
|
-
const
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
textarea.
|
|
881
|
-
|
|
882
|
-
const computedStyle = window.getComputedStyle(textarea);
|
|
883
|
-
const paddingTop = parseFloat(computedStyle.paddingTop);
|
|
884
|
-
const paddingBottom = parseFloat(computedStyle.paddingBottom);
|
|
885
|
-
const contentHeight = textarea.scrollHeight - paddingTop - paddingBottom;
|
|
886
|
-
setMaxHeight(contentHeight * maxRows + paddingTop + paddingBottom);
|
|
887
|
-
textarea.value = currentValue;
|
|
888
|
-
if (currentValue) {
|
|
889
|
-
textarea.style.height = "auto";
|
|
890
|
-
textarea.style.height = `${Math.min(textarea.scrollHeight, contentHeight * maxRows + paddingTop + paddingBottom)}px`;
|
|
891
|
-
}
|
|
892
|
-
if (props.autoFocus) {
|
|
893
|
-
textarea.focus();
|
|
894
|
-
}
|
|
895
|
-
}
|
|
1326
|
+
const textarea = internalTextareaRef.current;
|
|
1327
|
+
if (!textarea) return;
|
|
1328
|
+
const handleFocus = () => {
|
|
1329
|
+
setTimeout(() => {
|
|
1330
|
+
textarea.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
|
1331
|
+
}, 300);
|
|
896
1332
|
};
|
|
897
|
-
|
|
898
|
-
|
|
1333
|
+
textarea.addEventListener("focus", handleFocus);
|
|
1334
|
+
return () => textarea.removeEventListener("focus", handleFocus);
|
|
1335
|
+
}, []);
|
|
899
1336
|
(0, import_react4.useEffect)(() => {
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
const handleInput = (e) => {
|
|
903
|
-
adjustHeight();
|
|
904
|
-
if (props.onChange) {
|
|
905
|
-
props.onChange(e);
|
|
1337
|
+
if (autoFocus) {
|
|
1338
|
+
internalTextareaRef.current?.focus();
|
|
906
1339
|
}
|
|
907
|
-
};
|
|
1340
|
+
}, [autoFocus]);
|
|
908
1341
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
909
1342
|
"textarea",
|
|
910
1343
|
{
|
|
911
1344
|
ref: internalTextareaRef,
|
|
912
1345
|
...props,
|
|
913
|
-
onChange: handleInput,
|
|
914
1346
|
style: {
|
|
915
1347
|
overflow: "auto",
|
|
916
1348
|
resize: "none",
|
|
917
|
-
maxHeight: `${maxHeight}px`,
|
|
918
1349
|
...style
|
|
919
1350
|
},
|
|
920
1351
|
placeholder: labels.chatInputPlaceholder,
|
|
921
1352
|
className: (0, import_tailwind_merge3.twMerge)(
|
|
922
|
-
|
|
923
|
-
"w-full p-5 pb-0",
|
|
924
|
-
// Behavior
|
|
925
|
-
"outline-none resize-none",
|
|
926
|
-
// Background
|
|
927
|
-
"bg-transparent",
|
|
928
|
-
// Typography
|
|
929
|
-
"antialiased font-regular leading-relaxed text-[16px]",
|
|
930
|
-
// Placeholder styles
|
|
931
|
-
"placeholder:text-[#00000077] dark:placeholder:text-[#fffc]",
|
|
1353
|
+
"bg-transparent outline-none antialiased font-regular leading-relaxed text-[16px] placeholder:text-[#00000077] dark:placeholder:text-[#fffc]",
|
|
932
1354
|
className
|
|
933
1355
|
),
|
|
934
1356
|
rows: 1
|
|
@@ -943,22 +1365,15 @@ CopilotChatInput.ToolbarButton.displayName = "CopilotChatInput.ToolbarButton";
|
|
|
943
1365
|
CopilotChatInput.StartTranscribeButton.displayName = "CopilotChatInput.StartTranscribeButton";
|
|
944
1366
|
CopilotChatInput.CancelTranscribeButton.displayName = "CopilotChatInput.CancelTranscribeButton";
|
|
945
1367
|
CopilotChatInput.FinishTranscribeButton.displayName = "CopilotChatInput.FinishTranscribeButton";
|
|
946
|
-
CopilotChatInput.
|
|
947
|
-
CopilotChatInput.ToolsButton.displayName = "CopilotChatInput.ToolsButton";
|
|
948
|
-
CopilotChatInput.Toolbar.displayName = "CopilotChatInput.Toolbar";
|
|
1368
|
+
CopilotChatInput.AddMenuButton.displayName = "CopilotChatInput.AddMenuButton";
|
|
949
1369
|
var CopilotChatInput_default = CopilotChatInput;
|
|
950
1370
|
|
|
951
1371
|
// src/components/chat/CopilotChatAssistantMessage.tsx
|
|
952
|
-
var import_react_markdown = require("react-markdown");
|
|
953
|
-
var import_remark_gfm = __toESM(require("remark-gfm"));
|
|
954
|
-
var import_remark_math = __toESM(require("remark-math"));
|
|
955
|
-
var import_rehype_pretty_code = __toESM(require("rehype-pretty-code"));
|
|
956
|
-
var import_rehype_katex = __toESM(require("rehype-katex"));
|
|
957
1372
|
var import_react16 = require("react");
|
|
958
1373
|
var import_lucide_react3 = require("lucide-react");
|
|
959
1374
|
var import_tailwind_merge4 = require("tailwind-merge");
|
|
960
1375
|
var import_katex_min = require("katex/dist/katex.min.css");
|
|
961
|
-
var
|
|
1376
|
+
var import_streamdown = require("streamdown");
|
|
962
1377
|
|
|
963
1378
|
// src/hooks/use-render-tool-call.tsx
|
|
964
1379
|
var import_react7 = require("react");
|
|
@@ -1008,18 +1423,18 @@ var CopilotKitCoreReact = class extends import_core.CopilotKitCore {
|
|
|
1008
1423
|
}
|
|
1009
1424
|
};
|
|
1010
1425
|
|
|
1011
|
-
// src/components/
|
|
1426
|
+
// src/components/CopilotKitInspector.tsx
|
|
1012
1427
|
var React4 = __toESM(require("react"));
|
|
1013
1428
|
var import_react5 = require("@lit-labs/react");
|
|
1014
1429
|
var import_web_inspector = require("@copilotkitnext/web-inspector");
|
|
1015
1430
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1016
1431
|
(0, import_web_inspector.defineWebInspector)();
|
|
1017
|
-
var
|
|
1432
|
+
var CopilotKitInspectorBase = (0, import_react5.createComponent)({
|
|
1018
1433
|
tagName: import_web_inspector.WEB_INSPECTOR_TAG,
|
|
1019
1434
|
elementClass: import_web_inspector.WebInspectorElement,
|
|
1020
1435
|
react: React4
|
|
1021
1436
|
});
|
|
1022
|
-
var
|
|
1437
|
+
var CopilotKitInspector = React4.forwardRef(
|
|
1023
1438
|
({ core, ...rest }, ref) => {
|
|
1024
1439
|
const innerRef = React4.useRef(null);
|
|
1025
1440
|
React4.useImperativeHandle(ref, () => innerRef.current, []);
|
|
@@ -1028,10 +1443,16 @@ var WebInspector = React4.forwardRef(
|
|
|
1028
1443
|
innerRef.current.core = core ?? null;
|
|
1029
1444
|
}
|
|
1030
1445
|
}, [core]);
|
|
1031
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1446
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1447
|
+
CopilotKitInspectorBase,
|
|
1448
|
+
{
|
|
1449
|
+
...rest,
|
|
1450
|
+
ref: innerRef
|
|
1451
|
+
}
|
|
1452
|
+
);
|
|
1032
1453
|
}
|
|
1033
1454
|
);
|
|
1034
|
-
|
|
1455
|
+
CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
1035
1456
|
|
|
1036
1457
|
// src/providers/CopilotKitProvider.tsx
|
|
1037
1458
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
@@ -1193,7 +1614,7 @@ var CopilotKitProvider = ({
|
|
|
1193
1614
|
},
|
|
1194
1615
|
children: [
|
|
1195
1616
|
children,
|
|
1196
|
-
shouldRenderInspector ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1617
|
+
shouldRenderInspector ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CopilotKitInspector, { core: copilotkit }) : null
|
|
1197
1618
|
]
|
|
1198
1619
|
}
|
|
1199
1620
|
);
|
|
@@ -1898,105 +2319,7 @@ function CopilotChatAssistantMessage({
|
|
|
1898
2319
|
);
|
|
1899
2320
|
}
|
|
1900
2321
|
((CopilotChatAssistantMessage2) => {
|
|
1901
|
-
|
|
1902
|
-
children,
|
|
1903
|
-
...props
|
|
1904
|
-
}) => {
|
|
1905
|
-
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1906
|
-
"code",
|
|
1907
|
-
{
|
|
1908
|
-
className: "px-[4.8px] py-[2.5px] bg-[rgb(236,236,236)] dark:bg-gray-800 rounded text-sm font-mono font-medium! text-foreground!",
|
|
1909
|
-
...props,
|
|
1910
|
-
children
|
|
1911
|
-
}
|
|
1912
|
-
);
|
|
1913
|
-
};
|
|
1914
|
-
const CodeBlock = ({ children, className, onClick, ...props }) => {
|
|
1915
|
-
const config = useCopilotChatConfiguration();
|
|
1916
|
-
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1917
|
-
const [copied, setCopied] = (0, import_react16.useState)(false);
|
|
1918
|
-
const getCodeContent = (node) => {
|
|
1919
|
-
if (typeof node === "string") return node;
|
|
1920
|
-
if (Array.isArray(node)) return node.map(getCodeContent).join("");
|
|
1921
|
-
if (node?.props?.children) return getCodeContent(node.props.children);
|
|
1922
|
-
return "";
|
|
1923
|
-
};
|
|
1924
|
-
const codeContent = getCodeContent(children);
|
|
1925
|
-
const language = props["data-language"];
|
|
1926
|
-
const copyToClipboard = async () => {
|
|
1927
|
-
if (!codeContent.trim()) return;
|
|
1928
|
-
try {
|
|
1929
|
-
setCopied(true);
|
|
1930
|
-
setTimeout(() => setCopied(false), 2e3);
|
|
1931
|
-
if (onClick) {
|
|
1932
|
-
onClick();
|
|
1933
|
-
}
|
|
1934
|
-
} catch (err) {
|
|
1935
|
-
console.error("Failed to copy code:", err);
|
|
1936
|
-
}
|
|
1937
|
-
};
|
|
1938
|
-
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "relative", children: [
|
|
1939
|
-
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "flex items-center justify-between px-4 pr-3 py-3 text-xs", children: [
|
|
1940
|
-
language && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "font-regular text-muted-foreground dark:text-white", children: language }),
|
|
1941
|
-
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
1942
|
-
"button",
|
|
1943
|
-
{
|
|
1944
|
-
className: cn(
|
|
1945
|
-
"px-2 gap-0.5 text-xs flex items-center cursor-pointer text-muted-foreground dark:text-white"
|
|
1946
|
-
),
|
|
1947
|
-
onClick: copyToClipboard,
|
|
1948
|
-
title: copied ? labels.assistantMessageToolbarCopyCodeCopiedLabel : `${labels.assistantMessageToolbarCopyCodeLabel} code`,
|
|
1949
|
-
children: [
|
|
1950
|
-
copied ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.Check, { className: "h-[10px]! w-[10px]!" }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.Copy, { className: "h-[10px]! w-[10px]!" }),
|
|
1951
|
-
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "text-[11px]", children: copied ? labels.assistantMessageToolbarCopyCodeCopiedLabel : labels.assistantMessageToolbarCopyCodeLabel })
|
|
1952
|
-
]
|
|
1953
|
-
}
|
|
1954
|
-
)
|
|
1955
|
-
] }),
|
|
1956
|
-
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1957
|
-
"pre",
|
|
1958
|
-
{
|
|
1959
|
-
className: cn(
|
|
1960
|
-
className,
|
|
1961
|
-
"rounded-2xl bg-transparent border-t-0 my-1!"
|
|
1962
|
-
),
|
|
1963
|
-
...props,
|
|
1964
|
-
children
|
|
1965
|
-
}
|
|
1966
|
-
)
|
|
1967
|
-
] });
|
|
1968
|
-
};
|
|
1969
|
-
CopilotChatAssistantMessage2.MarkdownRenderer = ({ content, className }) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1970
|
-
import_react_markdown.MarkdownHooks,
|
|
1971
|
-
{
|
|
1972
|
-
remarkPlugins: [import_remark_gfm.default, import_remark_math.default],
|
|
1973
|
-
rehypePlugins: [
|
|
1974
|
-
[
|
|
1975
|
-
import_rehype_pretty_code.default,
|
|
1976
|
-
{
|
|
1977
|
-
keepBackground: false,
|
|
1978
|
-
theme: {
|
|
1979
|
-
dark: "one-dark-pro",
|
|
1980
|
-
light: "one-light"
|
|
1981
|
-
},
|
|
1982
|
-
bypassInlineCode: true
|
|
1983
|
-
}
|
|
1984
|
-
],
|
|
1985
|
-
import_rehype_katex.default
|
|
1986
|
-
],
|
|
1987
|
-
components: {
|
|
1988
|
-
pre: CodeBlock,
|
|
1989
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1990
|
-
code: ({ className: className2, children, ...props }) => {
|
|
1991
|
-
if (typeof children === "string") {
|
|
1992
|
-
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(InlineCode, { ...props, children });
|
|
1993
|
-
}
|
|
1994
|
-
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("code", { className: className2, ...props, children });
|
|
1995
|
-
}
|
|
1996
|
-
},
|
|
1997
|
-
children: (0, import_core3.completePartialMarkdown)(content || "")
|
|
1998
|
-
}
|
|
1999
|
-
) });
|
|
2322
|
+
CopilotChatAssistantMessage2.MarkdownRenderer = ({ content, className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_streamdown.Streamdown, { className, ...props, children: content ?? "" });
|
|
2000
2323
|
CopilotChatAssistantMessage2.Toolbar = ({
|
|
2001
2324
|
className,
|
|
2002
2325
|
...props
|
|
@@ -2348,7 +2671,7 @@ var CopilotChatUserMessage_default = CopilotChatUserMessage;
|
|
|
2348
2671
|
var import_react18 = __toESM(require("react"));
|
|
2349
2672
|
var import_lucide_react5 = require("lucide-react");
|
|
2350
2673
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
2351
|
-
var baseClasses = "group inline-flex h-8 items-center gap-1.5 rounded-full border border-border/60 bg-background px-3 text-xs leading-none text-foreground transition-colors cursor-pointer hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:text-muted-foreground disabled:hover:bg-background disabled:hover:text-muted-foreground pointer-events-auto";
|
|
2674
|
+
var baseClasses = "group inline-flex h-7 sm:h-8 items-center gap-1 sm:gap-1.5 rounded-full border border-border/60 bg-background px-2.5 sm:px-3 text-[11px] sm:text-xs leading-none text-foreground transition-colors cursor-pointer hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:text-muted-foreground disabled:hover:bg-background disabled:hover:text-muted-foreground pointer-events-auto";
|
|
2352
2675
|
var labelClasses = "whitespace-nowrap font-medium leading-none";
|
|
2353
2676
|
var CopilotChatSuggestionPill = import_react18.default.forwardRef(function CopilotChatSuggestionPill2({ className, children, icon, isLoading, type, ...props }, ref) {
|
|
2354
2677
|
const showIcon = !isLoading && icon;
|
|
@@ -2363,7 +2686,7 @@ var CopilotChatSuggestionPill = import_react18.default.forwardRef(function Copil
|
|
|
2363
2686
|
disabled: isLoading || props.disabled,
|
|
2364
2687
|
...props,
|
|
2365
2688
|
children: [
|
|
2366
|
-
isLoading ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "flex h-4 w-4 items-center justify-center text-muted-foreground", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react5.Loader2, { className: "h-4 w-4 animate-spin", "aria-hidden": "true" }) }) : showIcon && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "flex h-4 w-4 items-center justify-center text-muted-foreground", children: icon }),
|
|
2689
|
+
isLoading ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "flex h-3.5 sm:h-4 w-3.5 sm:w-4 items-center justify-center text-muted-foreground", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react5.Loader2, { className: "h-3.5 sm:h-4 w-3.5 sm:w-4 animate-spin", "aria-hidden": "true" }) }) : showIcon && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "flex h-3.5 sm:h-4 w-3.5 sm:w-4 items-center justify-center text-muted-foreground", children: icon }),
|
|
2367
2690
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: labelClasses, children })
|
|
2368
2691
|
]
|
|
2369
2692
|
}
|
|
@@ -2381,7 +2704,7 @@ var DefaultContainer = import_react19.default.forwardRef(function DefaultContain
|
|
|
2381
2704
|
{
|
|
2382
2705
|
ref,
|
|
2383
2706
|
className: cn(
|
|
2384
|
-
"flex flex-wrap items-center gap-2
|
|
2707
|
+
"flex flex-wrap items-center gap-1.5 sm:gap-2 pl-0 pr-4 sm:px-0 pointer-events-none",
|
|
2385
2708
|
className
|
|
2386
2709
|
),
|
|
2387
2710
|
...props
|
|
@@ -2524,10 +2847,52 @@ CopilotChatMessageView.Cursor = function Cursor({ className, ...props }) {
|
|
|
2524
2847
|
var CopilotChatMessageView_default = CopilotChatMessageView;
|
|
2525
2848
|
|
|
2526
2849
|
// src/components/chat/CopilotChatView.tsx
|
|
2527
|
-
var
|
|
2850
|
+
var import_react21 = __toESM(require("react"));
|
|
2528
2851
|
var import_tailwind_merge7 = require("tailwind-merge");
|
|
2529
2852
|
var import_use_stick_to_bottom = require("use-stick-to-bottom");
|
|
2530
2853
|
var import_lucide_react6 = require("lucide-react");
|
|
2854
|
+
|
|
2855
|
+
// src/hooks/use-keyboard-height.tsx
|
|
2856
|
+
var import_react20 = require("react");
|
|
2857
|
+
function useKeyboardHeight() {
|
|
2858
|
+
const [keyboardState, setKeyboardState] = (0, import_react20.useState)({
|
|
2859
|
+
isKeyboardOpen: false,
|
|
2860
|
+
keyboardHeight: 0,
|
|
2861
|
+
availableHeight: typeof window !== "undefined" ? window.innerHeight : 0,
|
|
2862
|
+
viewportHeight: typeof window !== "undefined" ? window.innerHeight : 0
|
|
2863
|
+
});
|
|
2864
|
+
(0, import_react20.useEffect)(() => {
|
|
2865
|
+
if (typeof window === "undefined") {
|
|
2866
|
+
return;
|
|
2867
|
+
}
|
|
2868
|
+
const visualViewport = window.visualViewport;
|
|
2869
|
+
if (!visualViewport) {
|
|
2870
|
+
return;
|
|
2871
|
+
}
|
|
2872
|
+
const updateKeyboardState = () => {
|
|
2873
|
+
const layoutHeight = window.innerHeight;
|
|
2874
|
+
const visualHeight = visualViewport.height;
|
|
2875
|
+
const keyboardHeight = Math.max(0, layoutHeight - visualHeight);
|
|
2876
|
+
const isKeyboardOpen = keyboardHeight > 150;
|
|
2877
|
+
setKeyboardState({
|
|
2878
|
+
isKeyboardOpen,
|
|
2879
|
+
keyboardHeight,
|
|
2880
|
+
availableHeight: visualHeight,
|
|
2881
|
+
viewportHeight: layoutHeight
|
|
2882
|
+
});
|
|
2883
|
+
};
|
|
2884
|
+
updateKeyboardState();
|
|
2885
|
+
visualViewport.addEventListener("resize", updateKeyboardState);
|
|
2886
|
+
visualViewport.addEventListener("scroll", updateKeyboardState);
|
|
2887
|
+
return () => {
|
|
2888
|
+
visualViewport.removeEventListener("resize", updateKeyboardState);
|
|
2889
|
+
visualViewport.removeEventListener("scroll", updateKeyboardState);
|
|
2890
|
+
};
|
|
2891
|
+
}, []);
|
|
2892
|
+
return keyboardState;
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
// src/components/chat/CopilotChatView.tsx
|
|
2531
2896
|
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
2532
2897
|
function CopilotChatView({
|
|
2533
2898
|
messageView,
|
|
@@ -2549,11 +2914,12 @@ function CopilotChatView({
|
|
|
2549
2914
|
className,
|
|
2550
2915
|
...props
|
|
2551
2916
|
}) {
|
|
2552
|
-
const inputContainerRef = (0,
|
|
2553
|
-
const [inputContainerHeight, setInputContainerHeight] = (0,
|
|
2554
|
-
const [isResizing, setIsResizing] = (0,
|
|
2555
|
-
const resizeTimeoutRef = (0,
|
|
2556
|
-
|
|
2917
|
+
const inputContainerRef = (0, import_react21.useRef)(null);
|
|
2918
|
+
const [inputContainerHeight, setInputContainerHeight] = (0, import_react21.useState)(0);
|
|
2919
|
+
const [isResizing, setIsResizing] = (0, import_react21.useState)(false);
|
|
2920
|
+
const resizeTimeoutRef = (0, import_react21.useRef)(null);
|
|
2921
|
+
const { isKeyboardOpen, keyboardHeight, availableHeight } = useKeyboardHeight();
|
|
2922
|
+
(0, import_react21.useEffect)(() => {
|
|
2557
2923
|
const element = inputContainerRef.current;
|
|
2558
2924
|
if (!element) return;
|
|
2559
2925
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
@@ -2607,15 +2973,16 @@ function CopilotChatView({
|
|
|
2607
2973
|
isResizing,
|
|
2608
2974
|
children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { style: { paddingBottom: `${inputContainerHeight + (hasSuggestions ? 4 : 32)}px` }, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "max-w-3xl mx-auto", children: [
|
|
2609
2975
|
BoundMessageView,
|
|
2610
|
-
hasSuggestions ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "
|
|
2976
|
+
hasSuggestions ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "pl-0 pr-4 sm:px-0 mt-4", children: BoundSuggestionView }) : null
|
|
2611
2977
|
] }) })
|
|
2612
2978
|
});
|
|
2613
2979
|
const BoundScrollToBottomButton = renderSlot(scrollToBottomButton, CopilotChatView.ScrollToBottomButton, {});
|
|
2614
2980
|
const BoundDisclaimer = renderSlot(disclaimer, CopilotChatView.Disclaimer, {});
|
|
2615
2981
|
const BoundInputContainer = renderSlot(inputContainer, CopilotChatView.InputContainer, {
|
|
2616
2982
|
ref: inputContainerRef,
|
|
2983
|
+
keyboardHeight: isKeyboardOpen ? keyboardHeight : 0,
|
|
2617
2984
|
children: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
|
|
2618
|
-
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "max-w-3xl mx-auto py-0 px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 pointer-events-auto", children: BoundInput }),
|
|
2985
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "max-w-3xl mx-auto py-0 px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6 pointer-events-auto", children: BoundInput }),
|
|
2619
2986
|
BoundDisclaimer
|
|
2620
2987
|
] })
|
|
2621
2988
|
});
|
|
@@ -2641,7 +3008,7 @@ function CopilotChatView({
|
|
|
2641
3008
|
const ScrollContent = ({ children, scrollToBottomButton, inputContainerHeight, isResizing }) => {
|
|
2642
3009
|
const { isAtBottom, scrollToBottom } = (0, import_use_stick_to_bottom.useStickToBottomContext)();
|
|
2643
3010
|
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
|
|
2644
|
-
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_use_stick_to_bottom.StickToBottom.Content, { className: "overflow-y-scroll overflow-x-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8", children }) }),
|
|
3011
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_use_stick_to_bottom.StickToBottom.Content, { className: "overflow-y-scroll overflow-x-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6", children }) }),
|
|
2645
3012
|
!isAtBottom && !isResizing && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
2646
3013
|
"div",
|
|
2647
3014
|
{
|
|
@@ -2665,13 +3032,13 @@ function CopilotChatView({
|
|
|
2665
3032
|
className,
|
|
2666
3033
|
...props
|
|
2667
3034
|
}) => {
|
|
2668
|
-
const [hasMounted, setHasMounted] = (0,
|
|
3035
|
+
const [hasMounted, setHasMounted] = (0, import_react21.useState)(false);
|
|
2669
3036
|
const { scrollRef, contentRef, scrollToBottom } = (0, import_use_stick_to_bottom.useStickToBottom)();
|
|
2670
|
-
const [showScrollButton, setShowScrollButton] = (0,
|
|
2671
|
-
(0,
|
|
3037
|
+
const [showScrollButton, setShowScrollButton] = (0, import_react21.useState)(false);
|
|
3038
|
+
(0, import_react21.useEffect)(() => {
|
|
2672
3039
|
setHasMounted(true);
|
|
2673
3040
|
}, []);
|
|
2674
|
-
(0,
|
|
3041
|
+
(0, import_react21.useEffect)(() => {
|
|
2675
3042
|
if (autoScroll) return;
|
|
2676
3043
|
const scrollElement = scrollRef.current;
|
|
2677
3044
|
if (!scrollElement) return;
|
|
@@ -2689,7 +3056,7 @@ function CopilotChatView({
|
|
|
2689
3056
|
};
|
|
2690
3057
|
}, [scrollRef, autoScroll]);
|
|
2691
3058
|
if (!hasMounted) {
|
|
2692
|
-
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "h-full max-h-full flex flex-col min-h-0 overflow-y-scroll overflow-x-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8", children }) });
|
|
3059
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "h-full max-h-full flex flex-col min-h-0 overflow-y-scroll overflow-x-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6", children }) });
|
|
2693
3060
|
}
|
|
2694
3061
|
if (!autoScroll) {
|
|
2695
3062
|
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
@@ -2702,7 +3069,7 @@ function CopilotChatView({
|
|
|
2702
3069
|
),
|
|
2703
3070
|
...props,
|
|
2704
3071
|
children: [
|
|
2705
|
-
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { ref: contentRef, className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8", children }),
|
|
3072
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { ref: contentRef, className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6", children }),
|
|
2706
3073
|
showScrollButton && !isResizing && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
2707
3074
|
"div",
|
|
2708
3075
|
{
|
|
@@ -2771,7 +3138,20 @@ function CopilotChatView({
|
|
|
2771
3138
|
...props
|
|
2772
3139
|
}
|
|
2773
3140
|
);
|
|
2774
|
-
CopilotChatView2.InputContainer =
|
|
3141
|
+
CopilotChatView2.InputContainer = import_react21.default.forwardRef(({ children, className, keyboardHeight = 0, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3142
|
+
"div",
|
|
3143
|
+
{
|
|
3144
|
+
ref,
|
|
3145
|
+
className: cn("absolute bottom-0 left-0 right-0 z-20 pointer-events-none", className),
|
|
3146
|
+
style: {
|
|
3147
|
+
// Adjust position when keyboard is open to keep input visible
|
|
3148
|
+
transform: keyboardHeight > 0 ? `translateY(-${keyboardHeight}px)` : void 0,
|
|
3149
|
+
transition: "transform 0.2s ease-out"
|
|
3150
|
+
},
|
|
3151
|
+
...props,
|
|
3152
|
+
children
|
|
3153
|
+
}
|
|
3154
|
+
));
|
|
2775
3155
|
CopilotChatView2.InputContainer.displayName = "CopilotChatView.InputContainer";
|
|
2776
3156
|
CopilotChatView2.Disclaimer = ({ className, ...props }) => {
|
|
2777
3157
|
const config = useCopilotChatConfiguration();
|
|
@@ -2790,14 +3170,14 @@ var CopilotChatView_default = CopilotChatView;
|
|
|
2790
3170
|
|
|
2791
3171
|
// src/components/chat/CopilotChat.tsx
|
|
2792
3172
|
var import_shared7 = require("@copilotkitnext/shared");
|
|
2793
|
-
var
|
|
3173
|
+
var import_react22 = require("react");
|
|
2794
3174
|
var import_ts_deepmerge = require("ts-deepmerge");
|
|
2795
3175
|
var import_client = require("@ag-ui/client");
|
|
2796
3176
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2797
3177
|
function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, ...props }) {
|
|
2798
3178
|
const existingConfig = useCopilotChatConfiguration();
|
|
2799
3179
|
const resolvedAgentId = agentId ?? existingConfig?.agentId ?? import_shared7.DEFAULT_AGENT_ID;
|
|
2800
|
-
const resolvedThreadId = (0,
|
|
3180
|
+
const resolvedThreadId = (0, import_react22.useMemo)(
|
|
2801
3181
|
() => threadId ?? existingConfig?.threadId ?? (0, import_shared7.randomUUID)(),
|
|
2802
3182
|
[threadId, existingConfig?.threadId]
|
|
2803
3183
|
);
|
|
@@ -2810,7 +3190,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
2810
3190
|
suggestionView: providedSuggestionView,
|
|
2811
3191
|
...restProps
|
|
2812
3192
|
} = props;
|
|
2813
|
-
(0,
|
|
3193
|
+
(0, import_react22.useEffect)(() => {
|
|
2814
3194
|
const connect = async (agent2) => {
|
|
2815
3195
|
try {
|
|
2816
3196
|
await copilotkit.connectAgent({ agent: agent2 });
|
|
@@ -2828,7 +3208,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
2828
3208
|
return () => {
|
|
2829
3209
|
};
|
|
2830
3210
|
}, [resolvedThreadId, agent, copilotkit, resolvedAgentId]);
|
|
2831
|
-
const onSubmitInput = (0,
|
|
3211
|
+
const onSubmitInput = (0, import_react22.useCallback)(
|
|
2832
3212
|
async (value) => {
|
|
2833
3213
|
agent?.addMessage({
|
|
2834
3214
|
id: (0, import_shared7.randomUUID)(),
|
|
@@ -2845,7 +3225,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
2845
3225
|
},
|
|
2846
3226
|
[agent, copilotkit]
|
|
2847
3227
|
);
|
|
2848
|
-
const handleSelectSuggestion = (0,
|
|
3228
|
+
const handleSelectSuggestion = (0, import_react22.useCallback)(
|
|
2849
3229
|
async (suggestion) => {
|
|
2850
3230
|
if (!agent) {
|
|
2851
3231
|
return;
|
|
@@ -2899,7 +3279,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
2899
3279
|
})(CopilotChat || (CopilotChat = {}));
|
|
2900
3280
|
|
|
2901
3281
|
// src/components/chat/CopilotChatToggleButton.tsx
|
|
2902
|
-
var
|
|
3282
|
+
var import_react23 = __toESM(require("react"));
|
|
2903
3283
|
var import_lucide_react7 = require("lucide-react");
|
|
2904
3284
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
2905
3285
|
var DefaultOpenIcon = ({
|
|
@@ -2926,11 +3306,11 @@ var BUTTON_BASE_CLASSES = cn(
|
|
|
2926
3306
|
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
2927
3307
|
"disabled:pointer-events-none disabled:opacity-60"
|
|
2928
3308
|
);
|
|
2929
|
-
var CopilotChatToggleButton =
|
|
3309
|
+
var CopilotChatToggleButton = import_react23.default.forwardRef(function CopilotChatToggleButton2({ openIcon, closeIcon, className, ...buttonProps }, ref) {
|
|
2930
3310
|
const { onClick, type, disabled, ...restProps } = buttonProps;
|
|
2931
3311
|
const configuration = useCopilotChatConfiguration();
|
|
2932
3312
|
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
2933
|
-
const [fallbackOpen, setFallbackOpen] = (0,
|
|
3313
|
+
const [fallbackOpen, setFallbackOpen] = (0, import_react23.useState)(false);
|
|
2934
3314
|
const isOpen = configuration?.isModalOpen ?? fallbackOpen;
|
|
2935
3315
|
const setModalOpen = configuration?.setModalOpen ?? setFallbackOpen;
|
|
2936
3316
|
const handleClick = (event) => {
|
|
@@ -3016,10 +3396,10 @@ CopilotChatToggleButton.displayName = "CopilotChatToggleButton";
|
|
|
3016
3396
|
var CopilotChatToggleButton_default = CopilotChatToggleButton;
|
|
3017
3397
|
|
|
3018
3398
|
// src/components/chat/CopilotSidebarView.tsx
|
|
3019
|
-
var
|
|
3399
|
+
var import_react25 = require("react");
|
|
3020
3400
|
|
|
3021
3401
|
// src/components/chat/CopilotModalHeader.tsx
|
|
3022
|
-
var
|
|
3402
|
+
var import_react24 = require("react");
|
|
3023
3403
|
var import_lucide_react8 = require("lucide-react");
|
|
3024
3404
|
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
3025
3405
|
function CopilotModalHeader({
|
|
@@ -3033,7 +3413,7 @@ function CopilotModalHeader({
|
|
|
3033
3413
|
const configuration = useCopilotChatConfiguration();
|
|
3034
3414
|
const fallbackTitle = configuration?.labels.modalHeaderTitle ?? CopilotChatDefaultLabels.modalHeaderTitle;
|
|
3035
3415
|
const resolvedTitle = title ?? fallbackTitle;
|
|
3036
|
-
const handleClose = (0,
|
|
3416
|
+
const handleClose = (0, import_react24.useCallback)(() => {
|
|
3037
3417
|
configuration?.setModalOpen(false);
|
|
3038
3418
|
}, [configuration]);
|
|
3039
3419
|
const BoundTitle = renderSlot(titleContent, CopilotModalHeader.Title, {
|
|
@@ -3109,8 +3489,8 @@ var SIDEBAR_TRANSITION_MS = 260;
|
|
|
3109
3489
|
function CopilotSidebarView({ header, width, ...props }) {
|
|
3110
3490
|
const configuration = useCopilotChatConfiguration();
|
|
3111
3491
|
const isSidebarOpen = configuration?.isModalOpen ?? false;
|
|
3112
|
-
const sidebarRef = (0,
|
|
3113
|
-
const [sidebarWidth, setSidebarWidth] = (0,
|
|
3492
|
+
const sidebarRef = (0, import_react25.useRef)(null);
|
|
3493
|
+
const [sidebarWidth, setSidebarWidth] = (0, import_react25.useState)(width ?? DEFAULT_SIDEBAR_WIDTH);
|
|
3114
3494
|
const widthToCss = (w) => {
|
|
3115
3495
|
return typeof w === "number" ? `${w}px` : w;
|
|
3116
3496
|
};
|
|
@@ -3120,7 +3500,7 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
3120
3500
|
}
|
|
3121
3501
|
return w;
|
|
3122
3502
|
};
|
|
3123
|
-
(0,
|
|
3503
|
+
(0, import_react25.useEffect)(() => {
|
|
3124
3504
|
if (width !== void 0) {
|
|
3125
3505
|
return;
|
|
3126
3506
|
}
|
|
@@ -3152,10 +3532,13 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
3152
3532
|
"style",
|
|
3153
3533
|
{
|
|
3154
3534
|
dangerouslySetInnerHTML: {
|
|
3155
|
-
__html: `
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3535
|
+
__html: `
|
|
3536
|
+
@media (min-width: 768px) {
|
|
3537
|
+
body {
|
|
3538
|
+
margin-inline-end: ${widthToMargin(sidebarWidth)};
|
|
3539
|
+
transition: margin-inline-end ${SIDEBAR_TRANSITION_MS}ms ease;
|
|
3540
|
+
}
|
|
3541
|
+
}`
|
|
3159
3542
|
}
|
|
3160
3543
|
}
|
|
3161
3544
|
),
|
|
@@ -3166,12 +3549,22 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
3166
3549
|
ref: sidebarRef,
|
|
3167
3550
|
"data-copilot-sidebar": true,
|
|
3168
3551
|
className: cn(
|
|
3169
|
-
"fixed right-0 top-0 z-[1200] flex
|
|
3552
|
+
"fixed right-0 top-0 z-[1200] flex",
|
|
3553
|
+
// Height with dvh fallback and safe area support
|
|
3554
|
+
"h-[100vh] h-[100dvh] max-h-screen",
|
|
3555
|
+
// Responsive width: full on mobile, custom on desktop
|
|
3556
|
+
"w-full",
|
|
3170
3557
|
"border-l border-border bg-background text-foreground shadow-xl",
|
|
3171
3558
|
"transition-transform duration-300 ease-out",
|
|
3172
3559
|
isSidebarOpen ? "translate-x-0" : "translate-x-full pointer-events-none"
|
|
3173
3560
|
),
|
|
3174
|
-
style: {
|
|
3561
|
+
style: {
|
|
3562
|
+
// Use CSS custom property for responsive width
|
|
3563
|
+
["--sidebar-width"]: widthToCss(sidebarWidth),
|
|
3564
|
+
// Safe area insets for iOS
|
|
3565
|
+
paddingTop: "env(safe-area-inset-top)",
|
|
3566
|
+
paddingBottom: "env(safe-area-inset-bottom)"
|
|
3567
|
+
},
|
|
3175
3568
|
"aria-hidden": !isSidebarOpen,
|
|
3176
3569
|
"aria-label": "Copilot chat sidebar",
|
|
3177
3570
|
role: "complementary",
|
|
@@ -3185,14 +3578,173 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
3185
3578
|
}
|
|
3186
3579
|
CopilotSidebarView.displayName = "CopilotSidebarView";
|
|
3187
3580
|
|
|
3188
|
-
// src/components/chat/
|
|
3189
|
-
var
|
|
3581
|
+
// src/components/chat/CopilotPopupView.tsx
|
|
3582
|
+
var import_react26 = require("react");
|
|
3190
3583
|
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
3584
|
+
var DEFAULT_POPUP_WIDTH = 420;
|
|
3585
|
+
var DEFAULT_POPUP_HEIGHT = 560;
|
|
3586
|
+
var dimensionToCss = (value, fallback) => {
|
|
3587
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
3588
|
+
return `${value}px`;
|
|
3589
|
+
}
|
|
3590
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
3591
|
+
return value;
|
|
3592
|
+
}
|
|
3593
|
+
return `${fallback}px`;
|
|
3594
|
+
};
|
|
3595
|
+
function CopilotPopupView({
|
|
3596
|
+
header,
|
|
3597
|
+
width,
|
|
3598
|
+
height,
|
|
3599
|
+
clickOutsideToClose,
|
|
3600
|
+
className,
|
|
3601
|
+
...restProps
|
|
3602
|
+
}) {
|
|
3603
|
+
const configuration = useCopilotChatConfiguration();
|
|
3604
|
+
const isPopupOpen = configuration?.isModalOpen ?? false;
|
|
3605
|
+
const setModalOpen = configuration?.setModalOpen;
|
|
3606
|
+
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
3607
|
+
const containerRef = (0, import_react26.useRef)(null);
|
|
3608
|
+
const [isRendered, setIsRendered] = (0, import_react26.useState)(isPopupOpen);
|
|
3609
|
+
const [isAnimatingOut, setIsAnimatingOut] = (0, import_react26.useState)(false);
|
|
3610
|
+
(0, import_react26.useEffect)(() => {
|
|
3611
|
+
if (isPopupOpen) {
|
|
3612
|
+
setIsRendered(true);
|
|
3613
|
+
setIsAnimatingOut(false);
|
|
3614
|
+
return;
|
|
3615
|
+
}
|
|
3616
|
+
if (!isRendered) {
|
|
3617
|
+
return;
|
|
3618
|
+
}
|
|
3619
|
+
setIsAnimatingOut(true);
|
|
3620
|
+
const timeout = setTimeout(() => {
|
|
3621
|
+
setIsRendered(false);
|
|
3622
|
+
setIsAnimatingOut(false);
|
|
3623
|
+
}, 200);
|
|
3624
|
+
return () => clearTimeout(timeout);
|
|
3625
|
+
}, [isPopupOpen, isRendered]);
|
|
3626
|
+
(0, import_react26.useEffect)(() => {
|
|
3627
|
+
if (!isPopupOpen) {
|
|
3628
|
+
return;
|
|
3629
|
+
}
|
|
3630
|
+
if (typeof window === "undefined") {
|
|
3631
|
+
return;
|
|
3632
|
+
}
|
|
3633
|
+
const handleKeyDown = (event) => {
|
|
3634
|
+
if (event.key === "Escape") {
|
|
3635
|
+
event.preventDefault();
|
|
3636
|
+
setModalOpen?.(false);
|
|
3637
|
+
}
|
|
3638
|
+
};
|
|
3639
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
3640
|
+
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
3641
|
+
}, [isPopupOpen, setModalOpen]);
|
|
3642
|
+
(0, import_react26.useEffect)(() => {
|
|
3643
|
+
if (!isPopupOpen) {
|
|
3644
|
+
return;
|
|
3645
|
+
}
|
|
3646
|
+
const focusTimer = setTimeout(() => {
|
|
3647
|
+
containerRef.current?.focus({ preventScroll: true });
|
|
3648
|
+
}, 200);
|
|
3649
|
+
return () => clearTimeout(focusTimer);
|
|
3650
|
+
}, [isPopupOpen]);
|
|
3651
|
+
(0, import_react26.useEffect)(() => {
|
|
3652
|
+
if (!isPopupOpen || !clickOutsideToClose) {
|
|
3653
|
+
return;
|
|
3654
|
+
}
|
|
3655
|
+
if (typeof document === "undefined") {
|
|
3656
|
+
return;
|
|
3657
|
+
}
|
|
3658
|
+
const handlePointerDown = (event) => {
|
|
3659
|
+
const target = event.target;
|
|
3660
|
+
if (!target) {
|
|
3661
|
+
return;
|
|
3662
|
+
}
|
|
3663
|
+
const container = containerRef.current;
|
|
3664
|
+
if (container?.contains(target)) {
|
|
3665
|
+
return;
|
|
3666
|
+
}
|
|
3667
|
+
const toggleButton = document.querySelector("[data-slot='chat-toggle-button']");
|
|
3668
|
+
if (toggleButton && toggleButton.contains(target)) {
|
|
3669
|
+
return;
|
|
3670
|
+
}
|
|
3671
|
+
setModalOpen?.(false);
|
|
3672
|
+
};
|
|
3673
|
+
document.addEventListener("pointerdown", handlePointerDown);
|
|
3674
|
+
return () => document.removeEventListener("pointerdown", handlePointerDown);
|
|
3675
|
+
}, [isPopupOpen, clickOutsideToClose, setModalOpen]);
|
|
3676
|
+
const headerElement = (0, import_react26.useMemo)(() => renderSlot(header, CopilotModalHeader, {}), [header]);
|
|
3677
|
+
const resolvedWidth = dimensionToCss(width, DEFAULT_POPUP_WIDTH);
|
|
3678
|
+
const resolvedHeight = dimensionToCss(height, DEFAULT_POPUP_HEIGHT);
|
|
3679
|
+
const popupStyle = (0, import_react26.useMemo)(
|
|
3680
|
+
() => ({
|
|
3681
|
+
"--copilot-popup-width": resolvedWidth,
|
|
3682
|
+
"--copilot-popup-height": resolvedHeight,
|
|
3683
|
+
"--copilot-popup-max-width": "calc(100vw - 3rem)",
|
|
3684
|
+
"--copilot-popup-max-height": "calc(100dvh - 7.5rem)",
|
|
3685
|
+
paddingTop: "env(safe-area-inset-top)",
|
|
3686
|
+
paddingBottom: "env(safe-area-inset-bottom)",
|
|
3687
|
+
paddingLeft: "env(safe-area-inset-left)",
|
|
3688
|
+
paddingRight: "env(safe-area-inset-right)"
|
|
3689
|
+
}),
|
|
3690
|
+
[resolvedHeight, resolvedWidth]
|
|
3691
|
+
);
|
|
3692
|
+
const popupAnimationClass = isPopupOpen && !isAnimatingOut ? "pointer-events-auto translate-y-0 opacity-100 md:scale-100" : "pointer-events-none translate-y-4 opacity-0 md:translate-y-5 md:scale-[0.95]";
|
|
3693
|
+
const popupContent = isRendered ? /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
3694
|
+
"div",
|
|
3695
|
+
{
|
|
3696
|
+
className: cn(
|
|
3697
|
+
"fixed inset-0 z-[1200] flex max-w-full flex-col items-stretch",
|
|
3698
|
+
"md:inset-auto md:bottom-24 md:right-6 md:items-end md:gap-4"
|
|
3699
|
+
),
|
|
3700
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
|
|
3701
|
+
"div",
|
|
3702
|
+
{
|
|
3703
|
+
ref: containerRef,
|
|
3704
|
+
tabIndex: -1,
|
|
3705
|
+
role: "dialog",
|
|
3706
|
+
"aria-label": labels.modalHeaderTitle,
|
|
3707
|
+
"data-copilot-popup": true,
|
|
3708
|
+
className: cn(
|
|
3709
|
+
"relative flex h-full w-full flex-col overflow-hidden bg-background text-foreground",
|
|
3710
|
+
"origin-bottom focus:outline-none transform-gpu transition-transform transition-opacity duration-200 ease-out",
|
|
3711
|
+
"md:transition-transform md:transition-opacity",
|
|
3712
|
+
"rounded-none border border-border/0 shadow-none ring-0",
|
|
3713
|
+
"md:h-[var(--copilot-popup-height)] md:w-[var(--copilot-popup-width)]",
|
|
3714
|
+
"md:max-h-[var(--copilot-popup-max-height)] md:max-w-[var(--copilot-popup-max-width)]",
|
|
3715
|
+
"md:origin-bottom-right md:rounded-2xl md:border-border md:shadow-xl md:ring-1 md:ring-border/40",
|
|
3716
|
+
popupAnimationClass
|
|
3717
|
+
),
|
|
3718
|
+
style: popupStyle,
|
|
3719
|
+
children: [
|
|
3720
|
+
headerElement,
|
|
3721
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "flex-1 overflow-hidden", "data-popup-chat": true, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
3722
|
+
CopilotChatView_default,
|
|
3723
|
+
{
|
|
3724
|
+
...restProps,
|
|
3725
|
+
className: cn("h-full min-h-0", className)
|
|
3726
|
+
}
|
|
3727
|
+
) })
|
|
3728
|
+
]
|
|
3729
|
+
}
|
|
3730
|
+
)
|
|
3731
|
+
}
|
|
3732
|
+
) : null;
|
|
3733
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
|
|
3734
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(CopilotChatToggleButton_default, {}),
|
|
3735
|
+
popupContent
|
|
3736
|
+
] });
|
|
3737
|
+
}
|
|
3738
|
+
CopilotPopupView.displayName = "CopilotPopupView";
|
|
3739
|
+
|
|
3740
|
+
// src/components/chat/CopilotSidebar.tsx
|
|
3741
|
+
var import_react27 = require("react");
|
|
3742
|
+
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
3191
3743
|
function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
|
|
3192
|
-
const SidebarViewOverride = (0,
|
|
3744
|
+
const SidebarViewOverride = (0, import_react27.useMemo)(() => {
|
|
3193
3745
|
const Component = (viewProps) => {
|
|
3194
3746
|
const { header: viewHeader, width: viewWidth, ...restProps } = viewProps;
|
|
3195
|
-
return /* @__PURE__ */ (0,
|
|
3747
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
3196
3748
|
CopilotSidebarView,
|
|
3197
3749
|
{
|
|
3198
3750
|
...restProps,
|
|
@@ -3203,7 +3755,7 @@ function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
|
|
|
3203
3755
|
};
|
|
3204
3756
|
return Object.assign(Component, CopilotChatView_default);
|
|
3205
3757
|
}, [header, width]);
|
|
3206
|
-
return /* @__PURE__ */ (0,
|
|
3758
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
3207
3759
|
CopilotChat,
|
|
3208
3760
|
{
|
|
3209
3761
|
...chatProps,
|
|
@@ -3214,6 +3766,50 @@ function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
|
|
|
3214
3766
|
}
|
|
3215
3767
|
CopilotSidebar.displayName = "CopilotSidebar";
|
|
3216
3768
|
|
|
3769
|
+
// src/components/chat/CopilotPopup.tsx
|
|
3770
|
+
var import_react28 = require("react");
|
|
3771
|
+
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
3772
|
+
function CopilotPopup({
|
|
3773
|
+
header,
|
|
3774
|
+
defaultOpen,
|
|
3775
|
+
width,
|
|
3776
|
+
height,
|
|
3777
|
+
clickOutsideToClose,
|
|
3778
|
+
...chatProps
|
|
3779
|
+
}) {
|
|
3780
|
+
const PopupViewOverride = (0, import_react28.useMemo)(() => {
|
|
3781
|
+
const Component = (viewProps) => {
|
|
3782
|
+
const {
|
|
3783
|
+
header: viewHeader,
|
|
3784
|
+
width: viewWidth,
|
|
3785
|
+
height: viewHeight,
|
|
3786
|
+
clickOutsideToClose: viewClickOutsideToClose,
|
|
3787
|
+
...restProps
|
|
3788
|
+
} = viewProps;
|
|
3789
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3790
|
+
CopilotPopupView,
|
|
3791
|
+
{
|
|
3792
|
+
...restProps,
|
|
3793
|
+
header: header ?? viewHeader,
|
|
3794
|
+
width: width ?? viewWidth,
|
|
3795
|
+
height: height ?? viewHeight,
|
|
3796
|
+
clickOutsideToClose: clickOutsideToClose ?? viewClickOutsideToClose
|
|
3797
|
+
}
|
|
3798
|
+
);
|
|
3799
|
+
};
|
|
3800
|
+
return Object.assign(Component, CopilotChatView_default);
|
|
3801
|
+
}, [clickOutsideToClose, header, height, width]);
|
|
3802
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3803
|
+
CopilotChat,
|
|
3804
|
+
{
|
|
3805
|
+
...chatProps,
|
|
3806
|
+
chatView: PopupViewOverride,
|
|
3807
|
+
isModalDefaultOpen: defaultOpen
|
|
3808
|
+
}
|
|
3809
|
+
);
|
|
3810
|
+
}
|
|
3811
|
+
CopilotPopup.displayName = "CopilotPopup";
|
|
3812
|
+
|
|
3217
3813
|
// src/types/defineToolCallRenderer.ts
|
|
3218
3814
|
var import_zod2 = require("zod");
|
|
3219
3815
|
function defineToolCallRenderer(def) {
|
|
@@ -3227,25 +3823,25 @@ function defineToolCallRenderer(def) {
|
|
|
3227
3823
|
}
|
|
3228
3824
|
|
|
3229
3825
|
// src/components/WildcardToolCallRender.tsx
|
|
3230
|
-
var
|
|
3231
|
-
var
|
|
3826
|
+
var import_react29 = require("react");
|
|
3827
|
+
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
3232
3828
|
var WildcardToolCallRender = defineToolCallRenderer({
|
|
3233
3829
|
name: "*",
|
|
3234
3830
|
render: ({ args, result, name, status }) => {
|
|
3235
|
-
const [isExpanded, setIsExpanded] = (0,
|
|
3831
|
+
const [isExpanded, setIsExpanded] = (0, import_react29.useState)(false);
|
|
3236
3832
|
const statusString = String(status);
|
|
3237
3833
|
const isActive = statusString === "inProgress" || statusString === "executing";
|
|
3238
3834
|
const isComplete = statusString === "complete";
|
|
3239
3835
|
const statusStyles = isActive ? "bg-amber-100 text-amber-800 dark:bg-amber-500/15 dark:text-amber-400" : isComplete ? "bg-emerald-100 text-emerald-800 dark:bg-emerald-500/15 dark:text-emerald-400" : "bg-zinc-100 text-zinc-800 dark:bg-zinc-700/40 dark:text-zinc-300";
|
|
3240
|
-
return /* @__PURE__ */ (0,
|
|
3241
|
-
/* @__PURE__ */ (0,
|
|
3836
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "mt-2 pb-2", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "rounded-xl border border-zinc-200/60 dark:border-zinc-800/60 bg-white/70 dark:bg-zinc-900/50 shadow-sm backdrop-blur p-4", children: [
|
|
3837
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
3242
3838
|
"div",
|
|
3243
3839
|
{
|
|
3244
3840
|
className: "flex items-center justify-between gap-3 cursor-pointer",
|
|
3245
3841
|
onClick: () => setIsExpanded(!isExpanded),
|
|
3246
3842
|
children: [
|
|
3247
|
-
/* @__PURE__ */ (0,
|
|
3248
|
-
/* @__PURE__ */ (0,
|
|
3843
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "flex items-center gap-2 min-w-0", children: [
|
|
3844
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
3249
3845
|
"svg",
|
|
3250
3846
|
{
|
|
3251
3847
|
className: `h-4 w-4 text-zinc-500 dark:text-zinc-400 transition-transform ${isExpanded ? "rotate-90" : ""}`,
|
|
@@ -3253,7 +3849,7 @@ var WildcardToolCallRender = defineToolCallRenderer({
|
|
|
3253
3849
|
viewBox: "0 0 24 24",
|
|
3254
3850
|
strokeWidth: 2,
|
|
3255
3851
|
stroke: "currentColor",
|
|
3256
|
-
children: /* @__PURE__ */ (0,
|
|
3852
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
3257
3853
|
"path",
|
|
3258
3854
|
{
|
|
3259
3855
|
strokeLinecap: "round",
|
|
@@ -3263,10 +3859,10 @@ var WildcardToolCallRender = defineToolCallRenderer({
|
|
|
3263
3859
|
)
|
|
3264
3860
|
}
|
|
3265
3861
|
),
|
|
3266
|
-
/* @__PURE__ */ (0,
|
|
3267
|
-
/* @__PURE__ */ (0,
|
|
3862
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "inline-block h-2 w-2 rounded-full bg-blue-500" }),
|
|
3863
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "truncate text-sm font-medium text-zinc-900 dark:text-zinc-100", children: name })
|
|
3268
3864
|
] }),
|
|
3269
|
-
/* @__PURE__ */ (0,
|
|
3865
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
3270
3866
|
"span",
|
|
3271
3867
|
{
|
|
3272
3868
|
className: `inline-flex items-center rounded-full px-2 py-1 text-xs font-medium ${statusStyles}`,
|
|
@@ -3276,14 +3872,14 @@ var WildcardToolCallRender = defineToolCallRenderer({
|
|
|
3276
3872
|
]
|
|
3277
3873
|
}
|
|
3278
3874
|
),
|
|
3279
|
-
isExpanded && /* @__PURE__ */ (0,
|
|
3280
|
-
/* @__PURE__ */ (0,
|
|
3281
|
-
/* @__PURE__ */ (0,
|
|
3282
|
-
/* @__PURE__ */ (0,
|
|
3875
|
+
isExpanded && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "mt-3 grid gap-4", children: [
|
|
3876
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { children: [
|
|
3877
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "text-xs uppercase tracking-wide text-zinc-500 dark:text-zinc-400", children: "Arguments" }),
|
|
3878
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("pre", { className: "mt-2 max-h-64 overflow-auto rounded-md bg-zinc-50 dark:bg-zinc-800/60 p-3 text-xs leading-relaxed text-zinc-800 dark:text-zinc-200 whitespace-pre-wrap break-words", children: JSON.stringify(args ?? {}, null, 2) })
|
|
3283
3879
|
] }),
|
|
3284
|
-
result !== void 0 && /* @__PURE__ */ (0,
|
|
3285
|
-
/* @__PURE__ */ (0,
|
|
3286
|
-
/* @__PURE__ */ (0,
|
|
3880
|
+
result !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { children: [
|
|
3881
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "text-xs uppercase tracking-wide text-zinc-500 dark:text-zinc-400", children: "Result" }),
|
|
3882
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("pre", { className: "mt-2 max-h-64 overflow-auto rounded-md bg-zinc-50 dark:bg-zinc-800/60 p-3 text-xs leading-relaxed text-zinc-800 dark:text-zinc-200 whitespace-pre-wrap break-words", children: typeof result === "string" ? result : JSON.stringify(result, null, 2) })
|
|
3287
3883
|
] })
|
|
3288
3884
|
] })
|
|
3289
3885
|
] }) });
|
|
@@ -3307,11 +3903,13 @@ var WildcardToolCallRender = defineToolCallRenderer({
|
|
|
3307
3903
|
CopilotChatUserMessage,
|
|
3308
3904
|
CopilotChatView,
|
|
3309
3905
|
CopilotKitCoreReact,
|
|
3906
|
+
CopilotKitInspector,
|
|
3310
3907
|
CopilotKitProvider,
|
|
3311
3908
|
CopilotModalHeader,
|
|
3909
|
+
CopilotPopup,
|
|
3910
|
+
CopilotPopupView,
|
|
3312
3911
|
CopilotSidebar,
|
|
3313
3912
|
CopilotSidebarView,
|
|
3314
|
-
WebInspector,
|
|
3315
3913
|
WildcardToolCallRender,
|
|
3316
3914
|
defineToolCallRenderer,
|
|
3317
3915
|
useAgent,
|