@copilotkit/react-ui 1.3.2 → 1.3.3-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/{chunk-PGJGIYRW.mjs → chunk-3YESXHJH.mjs} +3 -3
- package/dist/{chunk-I454U2HM.mjs → chunk-BTOVRBBW.mjs} +52 -25
- package/dist/chunk-BTOVRBBW.mjs.map +1 -0
- package/dist/chunk-GDNJRSD4.mjs +126 -0
- package/dist/chunk-GDNJRSD4.mjs.map +1 -0
- package/dist/{chunk-N6GQ4WV4.mjs → chunk-GHMYWL42.mjs} +2 -2
- package/dist/{chunk-N6GQ4WV4.mjs.map → chunk-GHMYWL42.mjs.map} +1 -1
- package/dist/chunk-GOTHQ665.mjs +19 -0
- package/dist/chunk-GOTHQ665.mjs.map +1 -0
- package/dist/chunk-MA5B5ELM.mjs +26 -0
- package/dist/chunk-MA5B5ELM.mjs.map +1 -0
- package/dist/chunk-U42OB2S3.mjs +61 -0
- package/dist/chunk-U42OB2S3.mjs.map +1 -0
- package/dist/{chunk-KJQVEUVB.mjs → chunk-UUHCZZZV.mjs} +2 -2
- package/dist/chunk-UUHCZZZV.mjs.map +1 -0
- package/dist/chunk-YH2STM73.mjs +76 -0
- package/dist/chunk-YH2STM73.mjs.map +1 -0
- package/dist/components/chat/Chat.d.ts +18 -2
- package/dist/components/chat/Chat.js +664 -556
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +6 -2
- package/dist/components/chat/Messages.d.ts +1 -1
- package/dist/components/chat/Messages.js +61 -662
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +1 -4
- package/dist/components/chat/Modal.js +669 -561
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +7 -3
- package/dist/components/chat/Popup.js +669 -561
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +8 -4
- package/dist/components/chat/Sidebar.js +669 -561
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +8 -4
- package/dist/components/chat/index.d.ts +1 -1
- package/dist/components/chat/index.js +669 -561
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +9 -5
- package/dist/components/chat/messages/RenderActionExecutionMessage.d.ts +7 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.js +122 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.mjs +10 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.mjs.map +1 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.d.ts +7 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.js +107 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.mjs +10 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.mjs.map +1 -0
- package/dist/components/chat/messages/RenderResultMessage.d.ts +7 -0
- package/dist/components/chat/messages/RenderResultMessage.js +65 -0
- package/dist/components/chat/messages/RenderResultMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderResultMessage.mjs +10 -0
- package/dist/components/chat/messages/RenderResultMessage.mjs.map +1 -0
- package/dist/components/chat/messages/RenderTextMessage.d.ts +7 -0
- package/dist/components/chat/messages/RenderTextMessage.js +614 -0
- package/dist/components/chat/messages/RenderTextMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderTextMessage.mjs +13 -0
- package/dist/components/chat/messages/RenderTextMessage.mjs.map +1 -0
- package/dist/components/chat/props.d.ts +12 -1
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +669 -561
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +9 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +677 -569
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -5
- package/package.json +7 -7
- package/src/components/chat/Chat.tsx +39 -4
- package/src/components/chat/Messages.tsx +45 -175
- package/src/components/chat/Popup.tsx +2 -2
- package/src/components/chat/Sidebar.tsx +2 -2
- package/src/components/chat/messages/RenderActionExecutionMessage.tsx +90 -0
- package/src/components/chat/messages/RenderAgentStateMessage.tsx +81 -0
- package/src/components/chat/messages/RenderResultMessage.tsx +15 -0
- package/src/components/chat/messages/RenderTextMessage.tsx +28 -0
- package/src/components/chat/props.ts +12 -0
- package/dist/chunk-4K36ATCD.mjs +0 -184
- package/dist/chunk-4K36ATCD.mjs.map +0 -1
- package/dist/chunk-I454U2HM.mjs.map +0 -1
- package/dist/chunk-KJQVEUVB.mjs.map +0 -1
- /package/dist/{chunk-PGJGIYRW.mjs.map → chunk-3YESXHJH.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -520,20 +520,365 @@ var Header = ({}) => {
|
|
|
520
520
|
};
|
|
521
521
|
|
|
522
522
|
// src/components/chat/Messages.tsx
|
|
523
|
-
var
|
|
523
|
+
var import_react3 = __toESM(require("react"));
|
|
524
|
+
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
525
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
526
|
+
var Messages = ({
|
|
527
|
+
messages,
|
|
528
|
+
inProgress,
|
|
529
|
+
children,
|
|
530
|
+
RenderTextMessage: RenderTextMessage2,
|
|
531
|
+
RenderActionExecutionMessage: RenderActionExecutionMessage2,
|
|
532
|
+
RenderAgentStateMessage: RenderAgentStateMessage2,
|
|
533
|
+
RenderResultMessage: RenderResultMessage2
|
|
534
|
+
}) => {
|
|
535
|
+
const context = useChatContext();
|
|
536
|
+
const initialMessages = (0, import_react3.useMemo)(
|
|
537
|
+
() => makeInitialMessages(context.labels.initial),
|
|
538
|
+
[context.labels.initial]
|
|
539
|
+
);
|
|
540
|
+
messages = [...initialMessages, ...messages];
|
|
541
|
+
const actionResults = {};
|
|
542
|
+
for (let i = 0; i < messages.length; i++) {
|
|
543
|
+
if (messages[i] instanceof import_runtime_client_gql.ActionExecutionMessage) {
|
|
544
|
+
const id = messages[i].id;
|
|
545
|
+
const resultMessage = messages.find(
|
|
546
|
+
(message) => message instanceof import_runtime_client_gql.ResultMessage && message.actionExecutionId === id
|
|
547
|
+
);
|
|
548
|
+
if (resultMessage) {
|
|
549
|
+
actionResults[id] = import_runtime_client_gql.ResultMessage.decodeResult(resultMessage.result || "");
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
const messagesEndRef = import_react3.default.useRef(null);
|
|
554
|
+
const scrollToBottom = () => {
|
|
555
|
+
if (messagesEndRef.current) {
|
|
556
|
+
messagesEndRef.current.scrollIntoView({
|
|
557
|
+
behavior: "auto"
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
(0, import_react3.useEffect)(() => {
|
|
562
|
+
scrollToBottom();
|
|
563
|
+
}, [messages]);
|
|
564
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "copilotKitMessages", children: [
|
|
565
|
+
messages.map((message, index) => {
|
|
566
|
+
const isCurrentMessage = index === messages.length - 1;
|
|
567
|
+
if (message instanceof import_runtime_client_gql.TextMessage) {
|
|
568
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
569
|
+
RenderTextMessage2,
|
|
570
|
+
{
|
|
571
|
+
message,
|
|
572
|
+
inProgress,
|
|
573
|
+
index,
|
|
574
|
+
isCurrentMessage
|
|
575
|
+
},
|
|
576
|
+
index
|
|
577
|
+
);
|
|
578
|
+
} else if (message instanceof import_runtime_client_gql.ActionExecutionMessage) {
|
|
579
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
580
|
+
RenderActionExecutionMessage2,
|
|
581
|
+
{
|
|
582
|
+
message,
|
|
583
|
+
inProgress,
|
|
584
|
+
index,
|
|
585
|
+
isCurrentMessage,
|
|
586
|
+
actionResult: actionResults[message.id]
|
|
587
|
+
},
|
|
588
|
+
index
|
|
589
|
+
);
|
|
590
|
+
} else if (message instanceof import_runtime_client_gql.AgentStateMessage) {
|
|
591
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
592
|
+
RenderAgentStateMessage2,
|
|
593
|
+
{
|
|
594
|
+
message,
|
|
595
|
+
inProgress,
|
|
596
|
+
index,
|
|
597
|
+
isCurrentMessage
|
|
598
|
+
},
|
|
599
|
+
index
|
|
600
|
+
);
|
|
601
|
+
} else if (message instanceof import_runtime_client_gql.ResultMessage) {
|
|
602
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
603
|
+
RenderResultMessage2,
|
|
604
|
+
{
|
|
605
|
+
message,
|
|
606
|
+
inProgress,
|
|
607
|
+
index,
|
|
608
|
+
isCurrentMessage
|
|
609
|
+
},
|
|
610
|
+
index
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
}),
|
|
614
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("footer", { ref: messagesEndRef, children })
|
|
615
|
+
] });
|
|
616
|
+
};
|
|
617
|
+
function makeInitialMessages(initial) {
|
|
618
|
+
let initialArray = [];
|
|
619
|
+
if (initial) {
|
|
620
|
+
if (Array.isArray(initial)) {
|
|
621
|
+
initialArray.push(...initial);
|
|
622
|
+
} else {
|
|
623
|
+
initialArray.push(initial);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
return initialArray.map(
|
|
627
|
+
(message) => new import_runtime_client_gql.TextMessage({
|
|
628
|
+
role: import_runtime_client_gql.Role.Assistant,
|
|
629
|
+
content: message
|
|
630
|
+
})
|
|
631
|
+
);
|
|
632
|
+
}
|
|
524
633
|
|
|
525
|
-
// src/components/chat/
|
|
634
|
+
// src/components/chat/Input.tsx
|
|
635
|
+
var import_react6 = require("react");
|
|
636
|
+
|
|
637
|
+
// src/components/chat/Textarea.tsx
|
|
526
638
|
var import_react4 = require("react");
|
|
639
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
640
|
+
var AutoResizingTextarea = (0, import_react4.forwardRef)(
|
|
641
|
+
({ maxRows = 1, placeholder, value, onChange, onKeyDown, autoFocus }, ref) => {
|
|
642
|
+
const internalTextareaRef = (0, import_react4.useRef)(null);
|
|
643
|
+
const [maxHeight, setMaxHeight] = (0, import_react4.useState)(0);
|
|
644
|
+
(0, import_react4.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
645
|
+
(0, import_react4.useEffect)(() => {
|
|
646
|
+
const calculateMaxHeight = () => {
|
|
647
|
+
const textarea = internalTextareaRef.current;
|
|
648
|
+
if (textarea) {
|
|
649
|
+
textarea.style.height = "auto";
|
|
650
|
+
const singleRowHeight = textarea.scrollHeight;
|
|
651
|
+
setMaxHeight(singleRowHeight * maxRows);
|
|
652
|
+
if (autoFocus) {
|
|
653
|
+
textarea.focus();
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
calculateMaxHeight();
|
|
658
|
+
}, [maxRows]);
|
|
659
|
+
(0, import_react4.useEffect)(() => {
|
|
660
|
+
const textarea = internalTextareaRef.current;
|
|
661
|
+
if (textarea) {
|
|
662
|
+
textarea.style.height = "auto";
|
|
663
|
+
textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;
|
|
664
|
+
}
|
|
665
|
+
}, [value, maxHeight]);
|
|
666
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
667
|
+
"textarea",
|
|
668
|
+
{
|
|
669
|
+
ref: internalTextareaRef,
|
|
670
|
+
value,
|
|
671
|
+
onChange,
|
|
672
|
+
onKeyDown,
|
|
673
|
+
placeholder,
|
|
674
|
+
style: {
|
|
675
|
+
overflow: "auto",
|
|
676
|
+
resize: "none",
|
|
677
|
+
maxHeight: `${maxHeight}px`
|
|
678
|
+
},
|
|
679
|
+
rows: 1
|
|
680
|
+
}
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
);
|
|
684
|
+
var Textarea_default = AutoResizingTextarea;
|
|
685
|
+
|
|
686
|
+
// src/hooks/use-push-to-talk.tsx
|
|
687
|
+
var import_react_core = require("@copilotkit/react-core");
|
|
688
|
+
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
689
|
+
var import_react5 = require("react");
|
|
690
|
+
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
691
|
+
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
692
|
+
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
693
|
+
audioContextRef.current = new window.AudioContext();
|
|
694
|
+
yield audioContextRef.current.resume();
|
|
695
|
+
}
|
|
696
|
+
mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
|
|
697
|
+
mediaRecorderRef.current.start(1e3);
|
|
698
|
+
mediaRecorderRef.current.ondataavailable = (event) => {
|
|
699
|
+
recordedChunks.push(event.data);
|
|
700
|
+
};
|
|
701
|
+
mediaRecorderRef.current.onstop = onStop;
|
|
702
|
+
});
|
|
703
|
+
var stopRecording = (mediaRecorderRef) => {
|
|
704
|
+
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
|
|
705
|
+
mediaRecorderRef.current.stop();
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
var transcribeAudio = (recordedChunks, transcribeAudioUrl) => __async(void 0, null, function* () {
|
|
709
|
+
const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
|
|
710
|
+
const formData = new FormData();
|
|
711
|
+
formData.append("file", completeBlob, "recording.mp4");
|
|
712
|
+
const response = yield fetch(transcribeAudioUrl, {
|
|
713
|
+
method: "POST",
|
|
714
|
+
body: formData
|
|
715
|
+
});
|
|
716
|
+
if (!response.ok) {
|
|
717
|
+
throw new Error(`Error: ${response.statusText}`);
|
|
718
|
+
}
|
|
719
|
+
const transcription = yield response.json();
|
|
720
|
+
return transcription.text;
|
|
721
|
+
});
|
|
722
|
+
var playAudioResponse = (text, textToSpeechUrl, audioContext) => {
|
|
723
|
+
const encodedText = encodeURIComponent(text);
|
|
724
|
+
const url = `${textToSpeechUrl}?text=${encodedText}`;
|
|
725
|
+
fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
|
|
726
|
+
const source = audioContext.createBufferSource();
|
|
727
|
+
source.buffer = audioBuffer;
|
|
728
|
+
source.connect(audioContext.destination);
|
|
729
|
+
source.start(0);
|
|
730
|
+
}).catch((error) => {
|
|
731
|
+
console.error("Error with decoding audio data", error);
|
|
732
|
+
});
|
|
733
|
+
};
|
|
734
|
+
var usePushToTalk = ({
|
|
735
|
+
sendFunction,
|
|
736
|
+
inProgress
|
|
737
|
+
}) => {
|
|
738
|
+
const [pushToTalkState, setPushToTalkState] = (0, import_react5.useState)("idle");
|
|
739
|
+
const mediaStreamRef = (0, import_react5.useRef)(null);
|
|
740
|
+
const audioContextRef = (0, import_react5.useRef)(null);
|
|
741
|
+
const mediaRecorderRef = (0, import_react5.useRef)(null);
|
|
742
|
+
const recordedChunks = (0, import_react5.useRef)([]);
|
|
743
|
+
const context = (0, import_react_core.useCopilotContext)();
|
|
744
|
+
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react5.useState)(null);
|
|
745
|
+
(0, import_react5.useEffect)(() => {
|
|
746
|
+
if (pushToTalkState === "recording") {
|
|
747
|
+
startRecording(
|
|
748
|
+
mediaStreamRef,
|
|
749
|
+
mediaRecorderRef,
|
|
750
|
+
audioContextRef,
|
|
751
|
+
recordedChunks.current,
|
|
752
|
+
() => {
|
|
753
|
+
setPushToTalkState("transcribing");
|
|
754
|
+
}
|
|
755
|
+
);
|
|
756
|
+
} else {
|
|
757
|
+
stopRecording(mediaRecorderRef);
|
|
758
|
+
if (pushToTalkState === "transcribing") {
|
|
759
|
+
transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl).then(
|
|
760
|
+
(transcription) => __async(void 0, null, function* () {
|
|
761
|
+
recordedChunks.current = [];
|
|
762
|
+
setPushToTalkState("idle");
|
|
763
|
+
const message = yield sendFunction(transcription);
|
|
764
|
+
setStartReadingFromMessageId(message.id);
|
|
765
|
+
})
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
return () => {
|
|
770
|
+
stopRecording(mediaRecorderRef);
|
|
771
|
+
};
|
|
772
|
+
}, [pushToTalkState]);
|
|
773
|
+
(0, import_react5.useEffect)(() => {
|
|
774
|
+
if (inProgress === false && startReadingFromMessageId) {
|
|
775
|
+
const lastMessageIndex = context.messages.findIndex(
|
|
776
|
+
(message) => message.id === startReadingFromMessageId
|
|
777
|
+
);
|
|
778
|
+
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
|
|
779
|
+
(message) => message instanceof import_runtime_client_gql2.TextMessage && message.role === "assistant"
|
|
780
|
+
);
|
|
781
|
+
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
782
|
+
playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
|
|
783
|
+
setStartReadingFromMessageId(null);
|
|
784
|
+
}
|
|
785
|
+
}, [startReadingFromMessageId, inProgress]);
|
|
786
|
+
return { pushToTalkState, setPushToTalkState };
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
// src/components/chat/Input.tsx
|
|
790
|
+
var import_react_core2 = require("@copilotkit/react-core");
|
|
791
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
792
|
+
var Input = ({ inProgress, onSend, isVisible = false }) => {
|
|
793
|
+
const context = useChatContext();
|
|
794
|
+
const copilotContext = (0, import_react_core2.useCopilotContext)();
|
|
795
|
+
const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
|
|
796
|
+
const textareaRef = (0, import_react6.useRef)(null);
|
|
797
|
+
const handleDivClick = (event) => {
|
|
798
|
+
var _a;
|
|
799
|
+
if (event.target !== event.currentTarget)
|
|
800
|
+
return;
|
|
801
|
+
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
802
|
+
};
|
|
803
|
+
const [text, setText] = (0, import_react6.useState)("");
|
|
804
|
+
const send = () => {
|
|
805
|
+
var _a;
|
|
806
|
+
if (inProgress)
|
|
807
|
+
return;
|
|
808
|
+
onSend(text);
|
|
809
|
+
setText("");
|
|
810
|
+
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
811
|
+
};
|
|
812
|
+
(0, import_react6.useEffect)(() => {
|
|
813
|
+
var _a;
|
|
814
|
+
if (isVisible) {
|
|
815
|
+
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
816
|
+
}
|
|
817
|
+
}, [isVisible]);
|
|
818
|
+
const { pushToTalkState, setPushToTalkState } = usePushToTalk({
|
|
819
|
+
sendFunction: onSend,
|
|
820
|
+
inProgress
|
|
821
|
+
});
|
|
822
|
+
const sendIcon = inProgress || pushToTalkState === "transcribing" ? context.icons.activityIcon : context.icons.sendIcon;
|
|
823
|
+
const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
|
|
824
|
+
const sendDisabled = inProgress || text.length === 0 || pushToTalkState !== "idle";
|
|
825
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "copilotKitInput", onClick: handleDivClick, children: [
|
|
826
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
827
|
+
Textarea_default,
|
|
828
|
+
{
|
|
829
|
+
ref: textareaRef,
|
|
830
|
+
placeholder: context.labels.placeholder,
|
|
831
|
+
autoFocus: true,
|
|
832
|
+
maxRows: 5,
|
|
833
|
+
value: text,
|
|
834
|
+
onChange: (event) => setText(event.target.value),
|
|
835
|
+
onKeyDown: (event) => {
|
|
836
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
837
|
+
event.preventDefault();
|
|
838
|
+
send();
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
),
|
|
843
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "copilotKitInputControls", children: [
|
|
844
|
+
showPushToTalk && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
845
|
+
"button",
|
|
846
|
+
{
|
|
847
|
+
onClick: () => setPushToTalkState(pushToTalkState === "idle" ? "recording" : "transcribing"),
|
|
848
|
+
className: pushToTalkState === "recording" ? "copilotKitPushToTalkRecording" : "",
|
|
849
|
+
children: context.icons.pushToTalkIcon
|
|
850
|
+
}
|
|
851
|
+
),
|
|
852
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { disabled: sendDisabled, onClick: send, children: sendIcon })
|
|
853
|
+
] })
|
|
854
|
+
] });
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
// src/components/chat/Response.tsx
|
|
858
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
859
|
+
var ResponseButton = ({ onClick, inProgress }) => {
|
|
860
|
+
const context = useChatContext();
|
|
861
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("button", { onClick, className: "copilotKitResponseButton", children: [
|
|
862
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: inProgress ? context.icons.stopIcon : context.icons.regenerateIcon }),
|
|
863
|
+
inProgress ? context.labels.stopGenerating : context.labels.regenerateResponse
|
|
864
|
+
] });
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
// src/components/chat/messages/RenderTextMessage.tsx
|
|
868
|
+
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
869
|
+
|
|
870
|
+
// src/components/chat/Markdown.tsx
|
|
871
|
+
var import_react8 = require("react");
|
|
527
872
|
var import_react_markdown = __toESM(require("react-markdown"));
|
|
528
873
|
|
|
529
874
|
// src/components/chat/CodeBlock.tsx
|
|
530
|
-
var
|
|
875
|
+
var import_react7 = require("react");
|
|
531
876
|
var import_react_syntax_highlighter = require("react-syntax-highlighter");
|
|
532
877
|
|
|
533
878
|
// src/hooks/use-copy-to-clipboard.tsx
|
|
534
|
-
var
|
|
879
|
+
var React6 = __toESM(require("react"));
|
|
535
880
|
function useCopyToClipboard({ timeout = 2e3 }) {
|
|
536
|
-
const [isCopied, setIsCopied] =
|
|
881
|
+
const [isCopied, setIsCopied] = React6.useState(false);
|
|
537
882
|
const copyToClipboard = (value) => {
|
|
538
883
|
var _a;
|
|
539
884
|
if (typeof window === "undefined" || !((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
|
|
@@ -553,7 +898,7 @@ function useCopyToClipboard({ timeout = 2e3 }) {
|
|
|
553
898
|
}
|
|
554
899
|
|
|
555
900
|
// src/components/chat/CodeBlock.tsx
|
|
556
|
-
var
|
|
901
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
557
902
|
var programmingLanguages = {
|
|
558
903
|
javascript: ".js",
|
|
559
904
|
python: ".py",
|
|
@@ -588,7 +933,7 @@ var generateRandomString = (length, lowercase = false) => {
|
|
|
588
933
|
}
|
|
589
934
|
return lowercase ? result.toLowerCase() : result;
|
|
590
935
|
};
|
|
591
|
-
var CodeBlock = (0,
|
|
936
|
+
var CodeBlock = (0, import_react7.memo)(({ language, value }) => {
|
|
592
937
|
const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2e3 });
|
|
593
938
|
const downloadAsFile = () => {
|
|
594
939
|
if (typeof window === "undefined") {
|
|
@@ -616,21 +961,21 @@ var CodeBlock = (0, import_react3.memo)(({ language, value }) => {
|
|
|
616
961
|
return;
|
|
617
962
|
copyToClipboard(value);
|
|
618
963
|
};
|
|
619
|
-
return /* @__PURE__ */ (0,
|
|
620
|
-
/* @__PURE__ */ (0,
|
|
621
|
-
/* @__PURE__ */ (0,
|
|
622
|
-
/* @__PURE__ */ (0,
|
|
623
|
-
/* @__PURE__ */ (0,
|
|
624
|
-
/* @__PURE__ */ (0,
|
|
625
|
-
/* @__PURE__ */ (0,
|
|
964
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitCodeBlock", children: [
|
|
965
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitCodeBlockToolbar", children: [
|
|
966
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "copilotKitCodeBlockToolbarLanguage", children: language }),
|
|
967
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitCodeBlockToolbarButtons", children: [
|
|
968
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { className: "copilotKitCodeBlockToolbarButton", onClick: downloadAsFile, children: [
|
|
969
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(DownloadIcon, {}),
|
|
970
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "sr-only", children: "Download" })
|
|
626
971
|
] }),
|
|
627
|
-
/* @__PURE__ */ (0,
|
|
628
|
-
isCopied ? /* @__PURE__ */ (0,
|
|
629
|
-
/* @__PURE__ */ (0,
|
|
972
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { className: "copilotKitCodeBlockToolbarButton", onClick: onCopy, children: [
|
|
973
|
+
isCopied ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CheckIcon, {}) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CopyIcon, {}),
|
|
974
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "sr-only", children: "Copy code" })
|
|
630
975
|
] })
|
|
631
976
|
] })
|
|
632
977
|
] }),
|
|
633
|
-
/* @__PURE__ */ (0,
|
|
978
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
634
979
|
import_react_syntax_highlighter.Prism,
|
|
635
980
|
{
|
|
636
981
|
language,
|
|
@@ -921,480 +1266,228 @@ var highlightStyle = {
|
|
|
921
1266
|
},
|
|
922
1267
|
'pre[class*="language-"] > code[class*="language-"]': {
|
|
923
1268
|
position: "relative",
|
|
924
|
-
zIndex: "1"
|
|
925
|
-
},
|
|
926
|
-
".line-highlight.line-highlight": {
|
|
927
|
-
background: "#f7ebc6",
|
|
928
|
-
boxShadow: "inset 5px 0 0 #f7d87c",
|
|
929
|
-
zIndex: "0"
|
|
930
|
-
}
|
|
931
|
-
};
|
|
932
|
-
|
|
933
|
-
// src/components/chat/Markdown.tsx
|
|
934
|
-
var import_remark_gfm = __toESM(require("remark-gfm"));
|
|
935
|
-
var import_remark_math = __toESM(require("remark-math"));
|
|
936
|
-
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
937
|
-
var MemoizedReactMarkdown = (0, import_react4.memo)(
|
|
938
|
-
import_react_markdown.default,
|
|
939
|
-
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.className === nextProps.className
|
|
940
|
-
);
|
|
941
|
-
var Markdown = ({ content }) => {
|
|
942
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MemoizedReactMarkdown, { components, remarkPlugins: [import_remark_gfm.default, import_remark_math.default], children: content }) });
|
|
943
|
-
};
|
|
944
|
-
var components = {
|
|
945
|
-
p({ children }) {
|
|
946
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children });
|
|
947
|
-
},
|
|
948
|
-
a(_a) {
|
|
949
|
-
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
950
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
951
|
-
"a",
|
|
952
|
-
__spreadProps(__spreadValues({
|
|
953
|
-
style: { color: "blue", textDecoration: "underline" }
|
|
954
|
-
}, props), {
|
|
955
|
-
target: "_blank",
|
|
956
|
-
rel: "noopener noreferrer",
|
|
957
|
-
children
|
|
958
|
-
})
|
|
959
|
-
);
|
|
960
|
-
},
|
|
961
|
-
code(_c) {
|
|
962
|
-
var _d = _c, { children, className, inline } = _d, props = __objRest(_d, ["children", "className", "inline"]);
|
|
963
|
-
if (children.length) {
|
|
964
|
-
if (children[0] == "\u258D") {
|
|
965
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
966
|
-
"span",
|
|
967
|
-
{
|
|
968
|
-
style: {
|
|
969
|
-
animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
|
|
970
|
-
marginTop: "0.25rem"
|
|
971
|
-
},
|
|
972
|
-
children: "\u258D"
|
|
973
|
-
}
|
|
974
|
-
);
|
|
975
|
-
}
|
|
976
|
-
children[0] = children[0].replace("`\u258D`", "\u258D");
|
|
977
|
-
}
|
|
978
|
-
const match = /language-(\w+)/.exec(className || "");
|
|
979
|
-
if (inline) {
|
|
980
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("code", __spreadProps(__spreadValues({ className }, props), { children }));
|
|
981
|
-
}
|
|
982
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
983
|
-
CodeBlock,
|
|
984
|
-
__spreadValues({
|
|
985
|
-
language: match && match[1] || "",
|
|
986
|
-
value: String(children).replace(/\n$/, "")
|
|
987
|
-
}, props),
|
|
988
|
-
Math.random()
|
|
989
|
-
);
|
|
990
|
-
}
|
|
991
|
-
};
|
|
992
|
-
|
|
993
|
-
// src/components/chat/Messages.tsx
|
|
994
|
-
var import_react_core = require("@copilotkit/react-core");
|
|
995
|
-
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
996
|
-
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
997
|
-
var Messages = ({ messages, inProgress, children }) => {
|
|
998
|
-
const { chatComponentsCache } = (0, import_react_core.useCopilotContext)();
|
|
999
|
-
const context = useChatContext();
|
|
1000
|
-
const initialMessages = (0, import_react5.useMemo)(
|
|
1001
|
-
() => makeInitialMessages(context.labels.initial),
|
|
1002
|
-
[context.labels.initial]
|
|
1003
|
-
);
|
|
1004
|
-
messages = [...initialMessages, ...messages];
|
|
1005
|
-
const functionResults = {};
|
|
1006
|
-
for (let i = 0; i < messages.length; i++) {
|
|
1007
|
-
if (messages[i] instanceof import_runtime_client_gql.ActionExecutionMessage) {
|
|
1008
|
-
const id = messages[i].id;
|
|
1009
|
-
const resultMessage = messages.find(
|
|
1010
|
-
(message) => message instanceof import_runtime_client_gql.ResultMessage && message.actionExecutionId === id
|
|
1011
|
-
);
|
|
1012
|
-
if (resultMessage) {
|
|
1013
|
-
functionResults[id] = import_runtime_client_gql.ResultMessage.decodeResult(resultMessage.result || "");
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
const messagesEndRef = import_react5.default.useRef(null);
|
|
1018
|
-
const scrollToBottom = () => {
|
|
1019
|
-
if (messagesEndRef.current) {
|
|
1020
|
-
messagesEndRef.current.scrollIntoView({
|
|
1021
|
-
behavior: "auto"
|
|
1022
|
-
});
|
|
1023
|
-
}
|
|
1024
|
-
};
|
|
1025
|
-
(0, import_react5.useEffect)(() => {
|
|
1026
|
-
scrollToBottom();
|
|
1027
|
-
}, [messages]);
|
|
1028
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "copilotKitMessages", children: [
|
|
1029
|
-
messages.map((message, index) => {
|
|
1030
|
-
const isCurrentMessage = index === messages.length - 1;
|
|
1031
|
-
if (message instanceof import_runtime_client_gql.TextMessage && message.role === "user") {
|
|
1032
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: message.content }, index);
|
|
1033
|
-
} else if (message instanceof import_runtime_client_gql.TextMessage && message.role == "assistant") {
|
|
1034
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: isCurrentMessage && inProgress && !message.content ? context.icons.spinnerIcon : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Markdown, { content: message.content }) }, index);
|
|
1035
|
-
} else if (message instanceof import_runtime_client_gql.ActionExecutionMessage) {
|
|
1036
|
-
if (chatComponentsCache.current !== null && chatComponentsCache.current.actions[message.name]) {
|
|
1037
|
-
const render = chatComponentsCache.current.actions[message.name];
|
|
1038
|
-
if (typeof render === "string") {
|
|
1039
|
-
if (isCurrentMessage && inProgress) {
|
|
1040
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1041
|
-
context.icons.spinnerIcon,
|
|
1042
|
-
" ",
|
|
1043
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "inProgressLabel", children: render })
|
|
1044
|
-
] }, index);
|
|
1045
|
-
} else {
|
|
1046
|
-
return null;
|
|
1047
|
-
}
|
|
1048
|
-
} else {
|
|
1049
|
-
const args = message.arguments;
|
|
1050
|
-
let status = "inProgress";
|
|
1051
|
-
if (functionResults[message.id] !== void 0) {
|
|
1052
|
-
status = "complete";
|
|
1053
|
-
} else if (message.status.code !== import_runtime_client_gql.MessageStatusCode.Pending) {
|
|
1054
|
-
status = "executing";
|
|
1055
|
-
}
|
|
1056
|
-
try {
|
|
1057
|
-
const toRender = render({
|
|
1058
|
-
status,
|
|
1059
|
-
args,
|
|
1060
|
-
result: functionResults[message.id]
|
|
1061
|
-
});
|
|
1062
|
-
if (!toRender && status === "complete") {
|
|
1063
|
-
return null;
|
|
1064
|
-
}
|
|
1065
|
-
if (typeof toRender === "string") {
|
|
1066
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1067
|
-
isCurrentMessage && inProgress && context.icons.spinnerIcon,
|
|
1068
|
-
" ",
|
|
1069
|
-
toRender
|
|
1070
|
-
] }, index);
|
|
1071
|
-
} else {
|
|
1072
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
|
|
1073
|
-
}
|
|
1074
|
-
} catch (e) {
|
|
1075
|
-
console.error(`Error executing render function for action ${message.name}: ${e}`);
|
|
1076
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1077
|
-
isCurrentMessage && inProgress && context.icons.spinnerIcon,
|
|
1078
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("b", { children: [
|
|
1079
|
-
"\u274C Error executing render: ",
|
|
1080
|
-
message.name
|
|
1081
|
-
] }),
|
|
1082
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("br", {}),
|
|
1083
|
-
e instanceof Error ? e.message : String(e)
|
|
1084
|
-
] }, index);
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
} else if (!inProgress || !isCurrentMessage) {
|
|
1088
|
-
return null;
|
|
1089
|
-
} else {
|
|
1090
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
|
|
1091
|
-
}
|
|
1092
|
-
} else if (message instanceof import_runtime_client_gql.AgentStateMessage) {
|
|
1093
|
-
let render;
|
|
1094
|
-
if (chatComponentsCache.current !== null) {
|
|
1095
|
-
render = chatComponentsCache.current.coagentActions[`${message.agentName}-${message.nodeName}`] || chatComponentsCache.current.coagentActions[`${message.agentName}-global`];
|
|
1096
|
-
}
|
|
1097
|
-
if (render) {
|
|
1098
|
-
if (typeof render === "string") {
|
|
1099
|
-
if (isCurrentMessage && inProgress) {
|
|
1100
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1101
|
-
context.icons.spinnerIcon,
|
|
1102
|
-
" ",
|
|
1103
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "inProgressLabel", children: render })
|
|
1104
|
-
] }, index);
|
|
1105
|
-
} else {
|
|
1106
|
-
return null;
|
|
1107
|
-
}
|
|
1108
|
-
} else {
|
|
1109
|
-
const state = message.state;
|
|
1110
|
-
let status = message.active ? "inProgress" : "complete";
|
|
1111
|
-
const toRender = render({
|
|
1112
|
-
status,
|
|
1113
|
-
state,
|
|
1114
|
-
nodeName: message.nodeName
|
|
1115
|
-
});
|
|
1116
|
-
if (!toRender && status === "complete") {
|
|
1117
|
-
return null;
|
|
1118
|
-
}
|
|
1119
|
-
if (typeof toRender === "string") {
|
|
1120
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1121
|
-
isCurrentMessage && inProgress && context.icons.spinnerIcon,
|
|
1122
|
-
" ",
|
|
1123
|
-
toRender
|
|
1124
|
-
] }, index);
|
|
1125
|
-
} else {
|
|
1126
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
} else if (!inProgress || !isCurrentMessage) {
|
|
1130
|
-
return null;
|
|
1131
|
-
} else {
|
|
1132
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
|
|
1133
|
-
}
|
|
1134
|
-
} else if (message instanceof import_runtime_client_gql.ResultMessage && inProgress && isCurrentMessage) {
|
|
1135
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
|
|
1136
|
-
}
|
|
1137
|
-
}),
|
|
1138
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("footer", { ref: messagesEndRef, children })
|
|
1139
|
-
] });
|
|
1140
|
-
};
|
|
1141
|
-
function makeInitialMessages(initial) {
|
|
1142
|
-
let initialArray = [];
|
|
1143
|
-
if (initial) {
|
|
1144
|
-
if (Array.isArray(initial)) {
|
|
1145
|
-
initialArray.push(...initial);
|
|
1146
|
-
} else {
|
|
1147
|
-
initialArray.push(initial);
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
return initialArray.map(
|
|
1151
|
-
(message) => new import_runtime_client_gql.TextMessage({
|
|
1152
|
-
role: import_runtime_client_gql.Role.Assistant,
|
|
1153
|
-
content: message
|
|
1154
|
-
})
|
|
1155
|
-
);
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
// src/components/chat/Input.tsx
|
|
1159
|
-
var import_react8 = require("react");
|
|
1160
|
-
|
|
1161
|
-
// src/components/chat/Textarea.tsx
|
|
1162
|
-
var import_react6 = require("react");
|
|
1163
|
-
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1164
|
-
var AutoResizingTextarea = (0, import_react6.forwardRef)(
|
|
1165
|
-
({ maxRows = 1, placeholder, value, onChange, onKeyDown, autoFocus }, ref) => {
|
|
1166
|
-
const internalTextareaRef = (0, import_react6.useRef)(null);
|
|
1167
|
-
const [maxHeight, setMaxHeight] = (0, import_react6.useState)(0);
|
|
1168
|
-
(0, import_react6.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
1169
|
-
(0, import_react6.useEffect)(() => {
|
|
1170
|
-
const calculateMaxHeight = () => {
|
|
1171
|
-
const textarea = internalTextareaRef.current;
|
|
1172
|
-
if (textarea) {
|
|
1173
|
-
textarea.style.height = "auto";
|
|
1174
|
-
const singleRowHeight = textarea.scrollHeight;
|
|
1175
|
-
setMaxHeight(singleRowHeight * maxRows);
|
|
1176
|
-
if (autoFocus) {
|
|
1177
|
-
textarea.focus();
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
};
|
|
1181
|
-
calculateMaxHeight();
|
|
1182
|
-
}, [maxRows]);
|
|
1183
|
-
(0, import_react6.useEffect)(() => {
|
|
1184
|
-
const textarea = internalTextareaRef.current;
|
|
1185
|
-
if (textarea) {
|
|
1186
|
-
textarea.style.height = "auto";
|
|
1187
|
-
textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;
|
|
1188
|
-
}
|
|
1189
|
-
}, [value, maxHeight]);
|
|
1190
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1191
|
-
"textarea",
|
|
1192
|
-
{
|
|
1193
|
-
ref: internalTextareaRef,
|
|
1194
|
-
value,
|
|
1195
|
-
onChange,
|
|
1196
|
-
onKeyDown,
|
|
1197
|
-
placeholder,
|
|
1198
|
-
style: {
|
|
1199
|
-
overflow: "auto",
|
|
1200
|
-
resize: "none",
|
|
1201
|
-
maxHeight: `${maxHeight}px`
|
|
1202
|
-
},
|
|
1203
|
-
rows: 1
|
|
1204
|
-
}
|
|
1205
|
-
);
|
|
1206
|
-
}
|
|
1207
|
-
);
|
|
1208
|
-
var Textarea_default = AutoResizingTextarea;
|
|
1209
|
-
|
|
1210
|
-
// src/hooks/use-push-to-talk.tsx
|
|
1211
|
-
var import_react_core2 = require("@copilotkit/react-core");
|
|
1212
|
-
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
1213
|
-
var import_react7 = require("react");
|
|
1214
|
-
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
1215
|
-
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
1216
|
-
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
1217
|
-
audioContextRef.current = new window.AudioContext();
|
|
1218
|
-
yield audioContextRef.current.resume();
|
|
1219
|
-
}
|
|
1220
|
-
mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
|
|
1221
|
-
mediaRecorderRef.current.start(1e3);
|
|
1222
|
-
mediaRecorderRef.current.ondataavailable = (event) => {
|
|
1223
|
-
recordedChunks.push(event.data);
|
|
1224
|
-
};
|
|
1225
|
-
mediaRecorderRef.current.onstop = onStop;
|
|
1226
|
-
});
|
|
1227
|
-
var stopRecording = (mediaRecorderRef) => {
|
|
1228
|
-
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
|
|
1229
|
-
mediaRecorderRef.current.stop();
|
|
1230
|
-
}
|
|
1231
|
-
};
|
|
1232
|
-
var transcribeAudio = (recordedChunks, transcribeAudioUrl) => __async(void 0, null, function* () {
|
|
1233
|
-
const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
|
|
1234
|
-
const formData = new FormData();
|
|
1235
|
-
formData.append("file", completeBlob, "recording.mp4");
|
|
1236
|
-
const response = yield fetch(transcribeAudioUrl, {
|
|
1237
|
-
method: "POST",
|
|
1238
|
-
body: formData
|
|
1239
|
-
});
|
|
1240
|
-
if (!response.ok) {
|
|
1241
|
-
throw new Error(`Error: ${response.statusText}`);
|
|
1269
|
+
zIndex: "1"
|
|
1270
|
+
},
|
|
1271
|
+
".line-highlight.line-highlight": {
|
|
1272
|
+
background: "#f7ebc6",
|
|
1273
|
+
boxShadow: "inset 5px 0 0 #f7d87c",
|
|
1274
|
+
zIndex: "0"
|
|
1242
1275
|
}
|
|
1243
|
-
const transcription = yield response.json();
|
|
1244
|
-
return transcription.text;
|
|
1245
|
-
});
|
|
1246
|
-
var playAudioResponse = (text, textToSpeechUrl, audioContext) => {
|
|
1247
|
-
const encodedText = encodeURIComponent(text);
|
|
1248
|
-
const url = `${textToSpeechUrl}?text=${encodedText}`;
|
|
1249
|
-
fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
|
|
1250
|
-
const source = audioContext.createBufferSource();
|
|
1251
|
-
source.buffer = audioBuffer;
|
|
1252
|
-
source.connect(audioContext.destination);
|
|
1253
|
-
source.start(0);
|
|
1254
|
-
}).catch((error) => {
|
|
1255
|
-
console.error("Error with decoding audio data", error);
|
|
1256
|
-
});
|
|
1257
1276
|
};
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1277
|
+
|
|
1278
|
+
// src/components/chat/Markdown.tsx
|
|
1279
|
+
var import_remark_gfm = __toESM(require("remark-gfm"));
|
|
1280
|
+
var import_remark_math = __toESM(require("remark-math"));
|
|
1281
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1282
|
+
var MemoizedReactMarkdown = (0, import_react8.memo)(
|
|
1283
|
+
import_react_markdown.default,
|
|
1284
|
+
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.className === nextProps.className
|
|
1285
|
+
);
|
|
1286
|
+
var Markdown = ({ content }) => {
|
|
1287
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(MemoizedReactMarkdown, { components, remarkPlugins: [import_remark_gfm.default, import_remark_math.default], children: content }) });
|
|
1288
|
+
};
|
|
1289
|
+
var components = {
|
|
1290
|
+
p({ children }) {
|
|
1291
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { children });
|
|
1292
|
+
},
|
|
1293
|
+
a(_a) {
|
|
1294
|
+
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
1295
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1296
|
+
"a",
|
|
1297
|
+
__spreadProps(__spreadValues({
|
|
1298
|
+
style: { color: "blue", textDecoration: "underline" }
|
|
1299
|
+
}, props), {
|
|
1300
|
+
target: "_blank",
|
|
1301
|
+
rel: "noopener noreferrer",
|
|
1302
|
+
children
|
|
1303
|
+
})
|
|
1304
|
+
);
|
|
1305
|
+
},
|
|
1306
|
+
code(_c) {
|
|
1307
|
+
var _d = _c, { children, className, inline } = _d, props = __objRest(_d, ["children", "className", "inline"]);
|
|
1308
|
+
if (children.length) {
|
|
1309
|
+
if (children[0] == "\u258D") {
|
|
1310
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1311
|
+
"span",
|
|
1312
|
+
{
|
|
1313
|
+
style: {
|
|
1314
|
+
animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
|
|
1315
|
+
marginTop: "0.25rem"
|
|
1316
|
+
},
|
|
1317
|
+
children: "\u258D"
|
|
1318
|
+
}
|
|
1290
1319
|
);
|
|
1291
1320
|
}
|
|
1321
|
+
children[0] = children[0].replace("`\u258D`", "\u258D");
|
|
1292
1322
|
}
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
}, [pushToTalkState]);
|
|
1297
|
-
(0, import_react7.useEffect)(() => {
|
|
1298
|
-
if (inProgress === false && startReadingFromMessageId) {
|
|
1299
|
-
const lastMessageIndex = context.messages.findIndex(
|
|
1300
|
-
(message) => message.id === startReadingFromMessageId
|
|
1301
|
-
);
|
|
1302
|
-
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
|
|
1303
|
-
(message) => message instanceof import_runtime_client_gql2.TextMessage && message.role === "assistant"
|
|
1304
|
-
);
|
|
1305
|
-
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
1306
|
-
playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
|
|
1307
|
-
setStartReadingFromMessageId(null);
|
|
1323
|
+
const match = /language-(\w+)/.exec(className || "");
|
|
1324
|
+
if (inline) {
|
|
1325
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("code", __spreadProps(__spreadValues({ className }, props), { children }));
|
|
1308
1326
|
}
|
|
1309
|
-
|
|
1310
|
-
|
|
1327
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1328
|
+
CodeBlock,
|
|
1329
|
+
__spreadValues({
|
|
1330
|
+
language: match && match[1] || "",
|
|
1331
|
+
value: String(children).replace(/\n$/, "")
|
|
1332
|
+
}, props),
|
|
1333
|
+
Math.random()
|
|
1334
|
+
);
|
|
1335
|
+
}
|
|
1311
1336
|
};
|
|
1312
1337
|
|
|
1313
|
-
// src/components/chat/
|
|
1314
|
-
var
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
const
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
if (event.target !== event.currentTarget)
|
|
1324
|
-
return;
|
|
1325
|
-
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1326
|
-
};
|
|
1327
|
-
const [text, setText] = (0, import_react8.useState)("");
|
|
1328
|
-
const send = () => {
|
|
1329
|
-
var _a;
|
|
1330
|
-
if (inProgress)
|
|
1331
|
-
return;
|
|
1332
|
-
onSend(text);
|
|
1333
|
-
setText("");
|
|
1334
|
-
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1335
|
-
};
|
|
1336
|
-
(0, import_react8.useEffect)(() => {
|
|
1337
|
-
var _a;
|
|
1338
|
-
if (isVisible) {
|
|
1339
|
-
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1338
|
+
// src/components/chat/messages/RenderTextMessage.tsx
|
|
1339
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1340
|
+
function RenderTextMessage(props) {
|
|
1341
|
+
const { message, inProgress, index, isCurrentMessage } = props;
|
|
1342
|
+
const { icons } = useChatContext();
|
|
1343
|
+
if (message instanceof import_runtime_client_gql3.TextMessage) {
|
|
1344
|
+
if (message.role === "user") {
|
|
1345
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: message.content }, index);
|
|
1346
|
+
} else if (message.role == "assistant") {
|
|
1347
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: isCurrentMessage && inProgress && !message.content ? icons.spinnerIcon : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Markdown, { content: message.content }) }, index);
|
|
1340
1348
|
}
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
// src/components/chat/messages/RenderActionExecutionMessage.tsx
|
|
1353
|
+
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1354
|
+
var import_react_core3 = require("@copilotkit/react-core");
|
|
1355
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1356
|
+
function RenderActionExecutionMessage(props) {
|
|
1357
|
+
const { message, inProgress, index, isCurrentMessage, actionResult } = props;
|
|
1358
|
+
const { chatComponentsCache } = (0, import_react_core3.useCopilotContext)();
|
|
1359
|
+
const { icons } = useChatContext();
|
|
1360
|
+
if (message instanceof import_runtime_client_gql4.ActionExecutionMessage) {
|
|
1361
|
+
if (chatComponentsCache.current !== null && chatComponentsCache.current.actions[message.name]) {
|
|
1362
|
+
const render = chatComponentsCache.current.actions[message.name];
|
|
1363
|
+
if (typeof render === "string") {
|
|
1364
|
+
if (isCurrentMessage && inProgress) {
|
|
1365
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1366
|
+
icons.spinnerIcon,
|
|
1367
|
+
" ",
|
|
1368
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "inProgressLabel", children: render })
|
|
1369
|
+
] }, index);
|
|
1370
|
+
} else {
|
|
1371
|
+
return null;
|
|
1372
|
+
}
|
|
1373
|
+
} else {
|
|
1374
|
+
const args = message.arguments;
|
|
1375
|
+
let status = "inProgress";
|
|
1376
|
+
if (actionResult !== void 0) {
|
|
1377
|
+
status = "complete";
|
|
1378
|
+
} else if (message.status.code !== import_runtime_client_gql4.MessageStatusCode.Pending) {
|
|
1379
|
+
status = "executing";
|
|
1380
|
+
}
|
|
1381
|
+
try {
|
|
1382
|
+
const toRender = render({
|
|
1383
|
+
status,
|
|
1384
|
+
args,
|
|
1385
|
+
result: actionResult
|
|
1386
|
+
});
|
|
1387
|
+
if (!toRender && status === "complete") {
|
|
1388
|
+
return null;
|
|
1363
1389
|
}
|
|
1390
|
+
if (typeof toRender === "string") {
|
|
1391
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1392
|
+
isCurrentMessage && inProgress && icons.spinnerIcon,
|
|
1393
|
+
" ",
|
|
1394
|
+
toRender
|
|
1395
|
+
] }, index);
|
|
1396
|
+
} else {
|
|
1397
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
|
|
1398
|
+
}
|
|
1399
|
+
} catch (e) {
|
|
1400
|
+
console.error(`Error executing render function for action ${message.name}: ${e}`);
|
|
1401
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1402
|
+
isCurrentMessage && inProgress && icons.spinnerIcon,
|
|
1403
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("b", { children: [
|
|
1404
|
+
"\u274C Error executing render: ",
|
|
1405
|
+
message.name
|
|
1406
|
+
] }),
|
|
1407
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("br", {}),
|
|
1408
|
+
e instanceof Error ? e.message : String(e)
|
|
1409
|
+
] }, index);
|
|
1364
1410
|
}
|
|
1365
1411
|
}
|
|
1366
|
-
)
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
children: context.icons.pushToTalkIcon
|
|
1374
|
-
}
|
|
1375
|
-
),
|
|
1376
|
-
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { disabled: sendDisabled, onClick: send, children: sendIcon })
|
|
1377
|
-
] })
|
|
1378
|
-
] });
|
|
1379
|
-
};
|
|
1412
|
+
} else if (!inProgress || !isCurrentMessage) {
|
|
1413
|
+
return null;
|
|
1414
|
+
} else {
|
|
1415
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: icons.spinnerIcon }, index);
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1380
1419
|
|
|
1381
|
-
// src/components/chat/
|
|
1382
|
-
var
|
|
1383
|
-
var
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
}
|
|
1420
|
+
// src/components/chat/messages/RenderResultMessage.tsx
|
|
1421
|
+
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1422
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1423
|
+
function RenderResultMessage(props) {
|
|
1424
|
+
const { message, inProgress, index, isCurrentMessage } = props;
|
|
1425
|
+
const { icons } = useChatContext();
|
|
1426
|
+
if (message instanceof import_runtime_client_gql5.ResultMessage && inProgress && isCurrentMessage) {
|
|
1427
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: icons.spinnerIcon }, index);
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1390
1430
|
|
|
1391
|
-
// src/components/chat/
|
|
1431
|
+
// src/components/chat/messages/RenderAgentStateMessage.tsx
|
|
1432
|
+
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1392
1433
|
var import_react_core4 = require("@copilotkit/react-core");
|
|
1434
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1435
|
+
function RenderAgentStateMessage(props) {
|
|
1436
|
+
const { message, inProgress, index, isCurrentMessage } = props;
|
|
1437
|
+
const { chatComponentsCache } = (0, import_react_core4.useCopilotContext)();
|
|
1438
|
+
const { icons } = useChatContext();
|
|
1439
|
+
if (message instanceof import_runtime_client_gql6.AgentStateMessage) {
|
|
1440
|
+
let render;
|
|
1441
|
+
if (chatComponentsCache.current !== null) {
|
|
1442
|
+
render = chatComponentsCache.current.coagentActions[`${message.agentName}-${message.nodeName}`] || chatComponentsCache.current.coagentActions[`${message.agentName}-global`];
|
|
1443
|
+
}
|
|
1444
|
+
if (render) {
|
|
1445
|
+
if (typeof render === "string") {
|
|
1446
|
+
if (isCurrentMessage && inProgress) {
|
|
1447
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1448
|
+
icons.spinnerIcon,
|
|
1449
|
+
" ",
|
|
1450
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "inProgressLabel", children: render })
|
|
1451
|
+
] }, index);
|
|
1452
|
+
} else {
|
|
1453
|
+
return null;
|
|
1454
|
+
}
|
|
1455
|
+
} else {
|
|
1456
|
+
const state = message.state;
|
|
1457
|
+
let status = message.active ? "inProgress" : "complete";
|
|
1458
|
+
const toRender = render({
|
|
1459
|
+
status,
|
|
1460
|
+
state,
|
|
1461
|
+
nodeName: message.nodeName
|
|
1462
|
+
});
|
|
1463
|
+
if (!toRender && status === "complete") {
|
|
1464
|
+
return null;
|
|
1465
|
+
}
|
|
1466
|
+
if (typeof toRender === "string") {
|
|
1467
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1468
|
+
isCurrentMessage && inProgress && icons.spinnerIcon,
|
|
1469
|
+
" ",
|
|
1470
|
+
toRender
|
|
1471
|
+
] }, index);
|
|
1472
|
+
} else {
|
|
1473
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
} else if (!inProgress || !isCurrentMessage) {
|
|
1477
|
+
return null;
|
|
1478
|
+
} else {
|
|
1479
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: icons.spinnerIcon }, index);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
// src/components/chat/Suggestion.tsx
|
|
1485
|
+
var import_react_core5 = require("@copilotkit/react-core");
|
|
1393
1486
|
var import_shared = require("@copilotkit/shared");
|
|
1394
|
-
var
|
|
1395
|
-
var
|
|
1487
|
+
var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
1488
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
1396
1489
|
function Suggestion({ title, message, onClick, partial, className }) {
|
|
1397
|
-
return /* @__PURE__ */ (0,
|
|
1490
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
|
|
1398
1491
|
"button",
|
|
1399
1492
|
{
|
|
1400
1493
|
disabled: partial,
|
|
@@ -1405,7 +1498,7 @@ function Suggestion({ title, message, onClick, partial, className }) {
|
|
|
1405
1498
|
className: className || "suggestion",
|
|
1406
1499
|
children: [
|
|
1407
1500
|
partial && SmallSpinnerIcon,
|
|
1408
|
-
/* @__PURE__ */ (0,
|
|
1501
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { children: title })
|
|
1409
1502
|
]
|
|
1410
1503
|
}
|
|
1411
1504
|
);
|
|
@@ -1423,11 +1516,11 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1423
1516
|
for (const config of Object.values(chatSuggestionConfiguration)) {
|
|
1424
1517
|
try {
|
|
1425
1518
|
const numOfSuggestionsInstructions = config.minSuggestions === 0 ? `Produce up to ${config.maxSuggestions} suggestions. If there are no highly relevant suggestions you can think of, provide an empty array.` : `Produce between ${config.minSuggestions} and ${config.maxSuggestions} suggestions.`;
|
|
1426
|
-
const result = yield (0,
|
|
1519
|
+
const result = yield (0, import_react_core5.extract)({
|
|
1427
1520
|
context,
|
|
1428
1521
|
instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. " + config.instructions + "\n\n" + numOfSuggestionsInstructions,
|
|
1429
1522
|
data: "Available tools: " + tools + "\n\n",
|
|
1430
|
-
requestType:
|
|
1523
|
+
requestType: import_runtime_client_gql7.CopilotRequestType.Task,
|
|
1431
1524
|
parameters: [
|
|
1432
1525
|
{
|
|
1433
1526
|
name: "suggestions",
|
|
@@ -1482,14 +1575,14 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1482
1575
|
|
|
1483
1576
|
// src/components/chat/Chat.tsx
|
|
1484
1577
|
var import_react11 = __toESM(require("react"));
|
|
1485
|
-
var
|
|
1486
|
-
var
|
|
1578
|
+
var import_react_core8 = require("@copilotkit/react-core");
|
|
1579
|
+
var import_runtime_client_gql10 = require("@copilotkit/runtime-client-gql");
|
|
1487
1580
|
var import_shared3 = require("@copilotkit/shared");
|
|
1488
1581
|
|
|
1489
1582
|
// src/components/dev-console/utils.ts
|
|
1490
|
-
var
|
|
1491
|
-
var
|
|
1492
|
-
var
|
|
1583
|
+
var import_react_core6 = require("@copilotkit/react-core");
|
|
1584
|
+
var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
|
|
1585
|
+
var import_runtime_client_gql9 = require("@copilotkit/runtime-client-gql");
|
|
1493
1586
|
function shouldShowDevConsole(showDevConsole) {
|
|
1494
1587
|
if (typeof showDevConsole === "boolean") {
|
|
1495
1588
|
return showDevConsole;
|
|
@@ -1551,7 +1644,7 @@ function getPublishedCopilotKitVersion(current, forceCheck = false) {
|
|
|
1551
1644
|
}
|
|
1552
1645
|
function logReadables(context) {
|
|
1553
1646
|
console.log("%cCurrent Readables:", "font-size: 16px; font-weight: bold;");
|
|
1554
|
-
const readables = context.getContextString([],
|
|
1647
|
+
const readables = context.getContextString([], import_react_core6.defaultCopilotContextCategories).trim();
|
|
1555
1648
|
if (readables.length === 0) {
|
|
1556
1649
|
console.log("No readables found");
|
|
1557
1650
|
return;
|
|
@@ -1579,7 +1672,7 @@ function logMessages(context) {
|
|
|
1579
1672
|
return;
|
|
1580
1673
|
}
|
|
1581
1674
|
const tableData = context.messages.map((message) => {
|
|
1582
|
-
if (message instanceof
|
|
1675
|
+
if (message instanceof import_runtime_client_gql8.TextMessage) {
|
|
1583
1676
|
return {
|
|
1584
1677
|
id: message.id,
|
|
1585
1678
|
type: "TextMessage",
|
|
@@ -1588,7 +1681,7 @@ function logMessages(context) {
|
|
|
1588
1681
|
scope: void 0,
|
|
1589
1682
|
content: message.content
|
|
1590
1683
|
};
|
|
1591
|
-
} else if (message instanceof
|
|
1684
|
+
} else if (message instanceof import_runtime_client_gql8.ActionExecutionMessage) {
|
|
1592
1685
|
return {
|
|
1593
1686
|
id: message.id,
|
|
1594
1687
|
type: "ActionExecutionMessage",
|
|
@@ -1597,7 +1690,7 @@ function logMessages(context) {
|
|
|
1597
1690
|
scope: message.scope,
|
|
1598
1691
|
content: message.arguments
|
|
1599
1692
|
};
|
|
1600
|
-
} else if (message instanceof
|
|
1693
|
+
} else if (message instanceof import_runtime_client_gql8.ResultMessage) {
|
|
1601
1694
|
return {
|
|
1602
1695
|
id: message.id,
|
|
1603
1696
|
type: "ResultMessage",
|
|
@@ -1606,7 +1699,7 @@ function logMessages(context) {
|
|
|
1606
1699
|
scope: message.actionExecutionId,
|
|
1607
1700
|
content: message.result
|
|
1608
1701
|
};
|
|
1609
|
-
} else if (message instanceof
|
|
1702
|
+
} else if (message instanceof import_runtime_client_gql9.AgentStateMessage) {
|
|
1610
1703
|
return {
|
|
1611
1704
|
id: message.id,
|
|
1612
1705
|
type: `AgentStateMessage (running: ${message.running})`,
|
|
@@ -1621,12 +1714,12 @@ function logMessages(context) {
|
|
|
1621
1714
|
}
|
|
1622
1715
|
|
|
1623
1716
|
// src/components/dev-console/console.tsx
|
|
1624
|
-
var
|
|
1717
|
+
var import_react_core7 = require("@copilotkit/react-core");
|
|
1625
1718
|
var import_react9 = require("react");
|
|
1626
1719
|
|
|
1627
1720
|
// src/components/dev-console/icons.tsx
|
|
1628
|
-
var
|
|
1629
|
-
var ExclamationMarkTriangleIcon = /* @__PURE__ */ (0,
|
|
1721
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
1722
|
+
var ExclamationMarkTriangleIcon = /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1630
1723
|
"svg",
|
|
1631
1724
|
{
|
|
1632
1725
|
width: "13.3967723px",
|
|
@@ -1634,7 +1727,7 @@ var ExclamationMarkTriangleIcon = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
|
1634
1727
|
viewBox: "0 0 13.3967723 12",
|
|
1635
1728
|
version: "1.1",
|
|
1636
1729
|
xmlns: "http://www.w3.org/2000/svg",
|
|
1637
|
-
children: /* @__PURE__ */ (0,
|
|
1730
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("g", { id: "exclamation-triangle", fill: "#CD2121", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1638
1731
|
"path",
|
|
1639
1732
|
{
|
|
1640
1733
|
d: "M5.39935802,0.75 C5.97670802,-0.25 7.42007802,-0.25 7.99742802,0.75 L13.193588,9.75 C13.770888,10.75 13.049288,12 11.894588,12 L1.50223802,12 C0.34753802,12 -0.37414898,10.75 0.20319802,9.75 L5.39935802,0.75 Z M6.69838802,2.5 C7.11260802,2.5 7.44838802,2.83579 7.44838802,3.25 L7.44838802,6.25 C7.44838802,6.66421 7.11260802,7 6.69838802,7 C6.28417802,7 5.94838802,6.66421 5.94838802,6.25 L5.94838802,3.25 C5.94838802,2.83579 6.28417802,2.5 6.69838802,2.5 Z M6.69838802,10.5 C7.25067802,10.5 7.69838802,10.0523 7.69838802,9.5 C7.69838802,8.9477 7.25067802,8.5 6.69838802,8.5 C6.14610802,8.5 5.69838802,8.9477 5.69838802,9.5 C5.69838802,10.0523 6.14610802,10.5 6.69838802,10.5 Z",
|
|
@@ -1643,7 +1736,7 @@ var ExclamationMarkTriangleIcon = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
|
1643
1736
|
) }) })
|
|
1644
1737
|
}
|
|
1645
1738
|
);
|
|
1646
|
-
var ExclamationMarkIcon = /* @__PURE__ */ (0,
|
|
1739
|
+
var ExclamationMarkIcon = /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1647
1740
|
"svg",
|
|
1648
1741
|
{
|
|
1649
1742
|
width: "14px",
|
|
@@ -1651,7 +1744,7 @@ var ExclamationMarkIcon = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
|
1651
1744
|
viewBox: "0 0 14 14",
|
|
1652
1745
|
version: "1.1",
|
|
1653
1746
|
xmlns: "http://www.w3.org/2000/svg",
|
|
1654
|
-
children: /* @__PURE__ */ (0,
|
|
1747
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("g", { id: "exclamation-circle", fill: "#EC662C", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1655
1748
|
"path",
|
|
1656
1749
|
{
|
|
1657
1750
|
d: "M7,14 C10.866,14 14,10.866 14,7 C14,3.13401 10.866,0 7,0 C3.13401,0 0,3.13401 0,7 C0,10.866 3.13401,14 7,14 Z M7,3 C7.41421,3 7.75,3.33579 7.75,3.75 L7.75,6.75 C7.75,7.16421 7.41421,7.5 7,7.5 C6.58579,7.5 6.25,7.16421 6.25,6.75 L6.25,3.75 C6.25,3.33579 6.58579,3 7,3 Z M7,11 C7.55228,11 8,10.5523 8,10 C8,9.4477 7.55228,9 7,9 C6.44772,9 6,9.4477 6,10 C6,10.5523 6.44772,11 7,11 Z",
|
|
@@ -1660,14 +1753,14 @@ var ExclamationMarkIcon = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
|
1660
1753
|
) }) })
|
|
1661
1754
|
}
|
|
1662
1755
|
);
|
|
1663
|
-
var ChevronDownIcon = /* @__PURE__ */ (0,
|
|
1756
|
+
var ChevronDownIcon = /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("svg", { width: "7px", height: "4px", viewBox: "0 0 7 4", version: "1.1", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("g", { id: "Group", fill: "#000000", fillRule: "nonzero", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1664
1757
|
"path",
|
|
1665
1758
|
{
|
|
1666
1759
|
d: "M3.71690723,3.90271086 C3.59268176,4.03242971 3.39143629,4.03242971 3.26721082,3.90271086 L0.0853966595,0.57605615 C-0.0314221035,0.444981627 -0.0279751448,0.240725043 0.0931934622,0.114040675 C0.214362069,-0.0126436935 0.409725445,-0.0162475626 0.535093061,0.105888951 L3.49205902,3.19746006 L6.44902499,0.105888951 C6.52834574,0.0168884389 6.64780588,-0.0197473458 6.7605411,0.0103538404 C6.87327633,0.0404550266 6.96130636,0.132492308 6.99009696,0.250359396 C7.01888756,0.368226483 6.98384687,0.493124608 6.89872139,0.57605615 L3.71690723,3.90271086 Z",
|
|
1667
1760
|
id: "Path"
|
|
1668
1761
|
}
|
|
1669
1762
|
) }) }) });
|
|
1670
|
-
var CheckIcon2 = /* @__PURE__ */ (0,
|
|
1763
|
+
var CheckIcon2 = /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1671
1764
|
"svg",
|
|
1672
1765
|
{
|
|
1673
1766
|
width: "14px",
|
|
@@ -1675,7 +1768,7 @@ var CheckIcon2 = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
|
1675
1768
|
viewBox: "0 0 14 14",
|
|
1676
1769
|
version: "1.1",
|
|
1677
1770
|
xmlns: "http://www.w3.org/2000/svg",
|
|
1678
|
-
children: /* @__PURE__ */ (0,
|
|
1771
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("g", { id: "Group-2", transform: "translate(-118, 0)", fill: "#1BC030", fillRule: "nonzero", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("g", { id: "Group", transform: "translate(118, 0)", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1679
1772
|
"path",
|
|
1680
1773
|
{
|
|
1681
1774
|
d: "M0,7 C0,3.13384615 3.13384615,0 7,0 C10.8661538,0 14,3.13384615 14,7 C14,10.8661538 10.8661538,14 7,14 C3.13384615,14 0,10.8661538 0,7 Z M9.59179487,5.69764103 C9.70905818,5.54139023 9.73249341,5.33388318 9.65303227,5.15541491 C9.57357113,4.97694665 9.40367989,4.85551619 9.20909814,4.83811118 C9.01451638,4.82070616 8.82577109,4.91005717 8.71589744,5.07158974 L6.39261538,8.32389744 L5.22666667,7.15794872 C5.01450582,6.96025518 4.68389046,6.9660885 4.47883563,7.17114332 C4.27378081,7.37619815 4.26794748,7.70681351 4.46564103,7.91897436 L6.08102564,9.53435897 C6.19289944,9.64614839 6.3482622,9.70310251 6.50588106,9.69010587 C6.66349993,9.67710922 6.80743532,9.59547613 6.89948718,9.46687179 L9.59179487,5.69764103 L9.59179487,5.69764103 Z",
|
|
@@ -1684,7 +1777,7 @@ var CheckIcon2 = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
|
1684
1777
|
) }) }) })
|
|
1685
1778
|
}
|
|
1686
1779
|
);
|
|
1687
|
-
var CopilotKitIcon = /* @__PURE__ */ (0,
|
|
1780
|
+
var CopilotKitIcon = /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
1688
1781
|
"svg",
|
|
1689
1782
|
{
|
|
1690
1783
|
width: "33px",
|
|
@@ -1693,8 +1786,8 @@ var CopilotKitIcon = /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
|
1693
1786
|
version: "1.1",
|
|
1694
1787
|
xmlns: "http://www.w3.org/2000/svg",
|
|
1695
1788
|
children: [
|
|
1696
|
-
/* @__PURE__ */ (0,
|
|
1697
|
-
/* @__PURE__ */ (0,
|
|
1789
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("title", { children: "bd5c9079-929b-4d55-bdc9-16d1c8181b71" }),
|
|
1790
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1698
1791
|
"image",
|
|
1699
1792
|
{
|
|
1700
1793
|
x: "0",
|
|
@@ -1711,10 +1804,10 @@ var CopilotKitIcon = /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
|
1711
1804
|
// src/components/dev-console/console.tsx
|
|
1712
1805
|
var import_react10 = require("@headlessui/react");
|
|
1713
1806
|
var import_shared2 = require("@copilotkit/shared");
|
|
1714
|
-
var
|
|
1807
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
1715
1808
|
function CopilotDevConsole() {
|
|
1716
1809
|
const currentVersion = import_shared2.COPILOTKIT_VERSION;
|
|
1717
|
-
const context = (0,
|
|
1810
|
+
const context = (0, import_react_core7.useCopilotContext)();
|
|
1718
1811
|
const [showDevConsole, setShowDevConsole] = (0, import_react9.useState)(false);
|
|
1719
1812
|
(0, import_react9.useEffect)(() => {
|
|
1720
1813
|
setShowDevConsole(shouldShowDevConsole(context.showDevConsole));
|
|
@@ -1785,14 +1878,14 @@ function CopilotDevConsole() {
|
|
|
1785
1878
|
if (!showDevConsole) {
|
|
1786
1879
|
return null;
|
|
1787
1880
|
}
|
|
1788
|
-
return /* @__PURE__ */ (0,
|
|
1881
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
|
|
1789
1882
|
"div",
|
|
1790
1883
|
{
|
|
1791
1884
|
ref: consoleRef,
|
|
1792
1885
|
className: "copilotKitDevConsole " + (versionStatus === "update-available" ? "copilotKitDevConsoleUpgrade" : "") + (versionStatus === "outdated" ? "copilotKitDevConsoleWarnOutdated" : ""),
|
|
1793
1886
|
children: [
|
|
1794
|
-
/* @__PURE__ */ (0,
|
|
1795
|
-
/* @__PURE__ */ (0,
|
|
1887
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "copilotKitDevConsoleLogo", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("a", { href: "https://copilotkit.ai", target: "_blank", children: CopilotKitIcon }) }),
|
|
1888
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1796
1889
|
VersionInfo,
|
|
1797
1890
|
{
|
|
1798
1891
|
showDevConsole: context.showDevConsole,
|
|
@@ -1801,7 +1894,7 @@ function CopilotDevConsole() {
|
|
|
1801
1894
|
latestVersion
|
|
1802
1895
|
}
|
|
1803
1896
|
),
|
|
1804
|
-
/* @__PURE__ */ (0,
|
|
1897
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1805
1898
|
DebugMenuButton,
|
|
1806
1899
|
{
|
|
1807
1900
|
setShowDevConsole,
|
|
@@ -1856,12 +1949,12 @@ function VersionInfo({
|
|
|
1856
1949
|
setTimeout(() => setCopyStatus(""), 1e3);
|
|
1857
1950
|
});
|
|
1858
1951
|
};
|
|
1859
|
-
return /* @__PURE__ */ (0,
|
|
1860
|
-
/* @__PURE__ */ (0,
|
|
1952
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "copilotKitVersionInfo", children: [
|
|
1953
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("header", { children: [
|
|
1861
1954
|
"COPILOTKIT DEV CONSOLE",
|
|
1862
|
-
showDevConsole === "auto" && /* @__PURE__ */ (0,
|
|
1955
|
+
showDevConsole === "auto" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("aside", { children: asideLabel })
|
|
1863
1956
|
] }),
|
|
1864
|
-
/* @__PURE__ */ (0,
|
|
1957
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("section", { children: [
|
|
1865
1958
|
"Version: ",
|
|
1866
1959
|
versionLabel,
|
|
1867
1960
|
" (",
|
|
@@ -1869,7 +1962,7 @@ function VersionInfo({
|
|
|
1869
1962
|
") ",
|
|
1870
1963
|
versionIcon
|
|
1871
1964
|
] }),
|
|
1872
|
-
(versionStatus === "update-available" || versionStatus === "outdated") && /* @__PURE__ */ (0,
|
|
1965
|
+
(versionStatus === "update-available" || versionStatus === "outdated") && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("footer", { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { onClick: handleCopyClick, children: copyStatus || installCommand }) })
|
|
1873
1966
|
] });
|
|
1874
1967
|
}
|
|
1875
1968
|
function DebugMenuButton({
|
|
@@ -1877,13 +1970,13 @@ function DebugMenuButton({
|
|
|
1877
1970
|
checkForUpdates,
|
|
1878
1971
|
mode
|
|
1879
1972
|
}) {
|
|
1880
|
-
const context = (0,
|
|
1881
|
-
return /* @__PURE__ */ (0,
|
|
1882
|
-
/* @__PURE__ */ (0,
|
|
1973
|
+
const context = (0, import_react_core7.useCopilotContext)();
|
|
1974
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "bg-black fixed top-24 w-52 text-right", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_react10.Menu, { children: [
|
|
1975
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react10.MenuButton, { className: `copilotKitDebugMenuButton ${mode === "compact" ? "compact" : ""}`, children: mode == "compact" ? "Debug" : /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
|
|
1883
1976
|
"Debug ",
|
|
1884
1977
|
ChevronDownIcon
|
|
1885
1978
|
] }) }),
|
|
1886
|
-
/* @__PURE__ */ (0,
|
|
1979
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
|
|
1887
1980
|
import_react10.MenuItems,
|
|
1888
1981
|
{
|
|
1889
1982
|
transition: true,
|
|
@@ -1891,12 +1984,12 @@ function DebugMenuButton({
|
|
|
1891
1984
|
className: "copilotKitDebugMenu",
|
|
1892
1985
|
style: { zIndex: 40 },
|
|
1893
1986
|
children: [
|
|
1894
|
-
/* @__PURE__ */ (0,
|
|
1895
|
-
/* @__PURE__ */ (0,
|
|
1896
|
-
/* @__PURE__ */ (0,
|
|
1897
|
-
/* @__PURE__ */ (0,
|
|
1898
|
-
/* @__PURE__ */ (0,
|
|
1899
|
-
/* @__PURE__ */ (0,
|
|
1987
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react10.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => logReadables(context), children: "Log Readables" }) }),
|
|
1988
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react10.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => logActions(context), children: "Log Actions" }) }),
|
|
1989
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react10.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => logMessages(context), children: "Log Messages" }) }),
|
|
1990
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react10.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => checkForUpdates(true), children: "Check for Updates" }) }),
|
|
1991
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("hr", {}),
|
|
1992
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react10.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => setShowDevConsole(false), children: "Hide Dev Console" }) })
|
|
1900
1993
|
]
|
|
1901
1994
|
}
|
|
1902
1995
|
)
|
|
@@ -1904,7 +1997,7 @@ function DebugMenuButton({
|
|
|
1904
1997
|
}
|
|
1905
1998
|
|
|
1906
1999
|
// src/components/chat/Chat.tsx
|
|
1907
|
-
var
|
|
2000
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
1908
2001
|
function CopilotChat({
|
|
1909
2002
|
instructions,
|
|
1910
2003
|
onSubmitMessage,
|
|
@@ -1912,13 +2005,17 @@ function CopilotChat({
|
|
|
1912
2005
|
showResponseButton = true,
|
|
1913
2006
|
onInProgress,
|
|
1914
2007
|
Messages: Messages2 = Messages,
|
|
2008
|
+
RenderTextMessage: RenderTextMessage2 = RenderTextMessage,
|
|
2009
|
+
RenderActionExecutionMessage: RenderActionExecutionMessage2 = RenderActionExecutionMessage,
|
|
2010
|
+
RenderAgentStateMessage: RenderAgentStateMessage2 = RenderAgentStateMessage,
|
|
2011
|
+
RenderResultMessage: RenderResultMessage2 = RenderResultMessage,
|
|
1915
2012
|
Input: Input2 = Input,
|
|
1916
2013
|
ResponseButton: ResponseButton2 = ResponseButton,
|
|
1917
2014
|
className,
|
|
1918
2015
|
icons,
|
|
1919
2016
|
labels
|
|
1920
2017
|
}) {
|
|
1921
|
-
const context = (0,
|
|
2018
|
+
const context = (0, import_react_core8.useCopilotContext)();
|
|
1922
2019
|
(0, import_react11.useEffect)(() => {
|
|
1923
2020
|
context.setChatInstructions(instructions || "");
|
|
1924
2021
|
}, [instructions]);
|
|
@@ -1932,32 +2029,43 @@ function CopilotChat({
|
|
|
1932
2029
|
} = useCopilotChatLogic(makeSystemMessage, onInProgress, onSubmitMessage);
|
|
1933
2030
|
const chatContext = import_react11.default.useContext(ChatContext);
|
|
1934
2031
|
const isVisible = chatContext ? chatContext.open : true;
|
|
1935
|
-
return /* @__PURE__ */ (0,
|
|
1936
|
-
/* @__PURE__ */ (0,
|
|
1937
|
-
/* @__PURE__ */ (0,
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
2032
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
|
|
2033
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(CopilotDevConsole, {}),
|
|
2034
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
|
|
2035
|
+
Messages2,
|
|
2036
|
+
{
|
|
2037
|
+
RenderTextMessage: RenderTextMessage2,
|
|
2038
|
+
RenderActionExecutionMessage: RenderActionExecutionMessage2,
|
|
2039
|
+
RenderAgentStateMessage: RenderAgentStateMessage2,
|
|
2040
|
+
RenderResultMessage: RenderResultMessage2,
|
|
2041
|
+
messages: visibleMessages,
|
|
2042
|
+
inProgress: isLoading,
|
|
2043
|
+
children: [
|
|
2044
|
+
currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { children: [
|
|
2045
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("h6", { children: "Suggested:" }),
|
|
2046
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "suggestions", children: currentSuggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
2047
|
+
Suggestion,
|
|
2048
|
+
{
|
|
2049
|
+
title: suggestion.title,
|
|
2050
|
+
message: suggestion.message,
|
|
2051
|
+
partial: suggestion.partial,
|
|
2052
|
+
className: suggestion.className,
|
|
2053
|
+
onClick: (message) => sendMessage(message)
|
|
2054
|
+
},
|
|
2055
|
+
index
|
|
2056
|
+
)) })
|
|
2057
|
+
] }),
|
|
2058
|
+
showResponseButton && visibleMessages.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
2059
|
+
ResponseButton2,
|
|
2060
|
+
{
|
|
2061
|
+
onClick: isLoading ? stopGeneration : reloadMessages,
|
|
2062
|
+
inProgress: isLoading
|
|
2063
|
+
}
|
|
2064
|
+
)
|
|
2065
|
+
]
|
|
2066
|
+
}
|
|
2067
|
+
),
|
|
2068
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Input2, { inProgress: isLoading, onSend: sendMessage, isVisible })
|
|
1961
2069
|
] });
|
|
1962
2070
|
}
|
|
1963
2071
|
function WrappedCopilotChat({
|
|
@@ -1968,14 +2076,14 @@ function WrappedCopilotChat({
|
|
|
1968
2076
|
}) {
|
|
1969
2077
|
const chatContext = import_react11.default.useContext(ChatContext);
|
|
1970
2078
|
if (!chatContext) {
|
|
1971
|
-
return /* @__PURE__ */ (0,
|
|
1972
|
-
}, children: /* @__PURE__ */ (0,
|
|
2079
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ChatContextProvider, { icons, labels, open: true, setOpen: () => {
|
|
2080
|
+
}, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: `copilotKitChat ${className}`, children }) });
|
|
1973
2081
|
}
|
|
1974
|
-
return /* @__PURE__ */ (0,
|
|
2082
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_jsx_runtime19.Fragment, { children });
|
|
1975
2083
|
}
|
|
1976
2084
|
var SUGGESTIONS_DEBOUNCE_TIMEOUT = 1e3;
|
|
1977
2085
|
var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) => {
|
|
1978
|
-
const { visibleMessages, appendMessage, reloadMessages, stopGeneration, isLoading } = (0,
|
|
2086
|
+
const { visibleMessages, appendMessage, reloadMessages, stopGeneration, isLoading } = (0, import_react_core8.useCopilotChat)({
|
|
1979
2087
|
id: (0, import_shared3.randomId)(),
|
|
1980
2088
|
makeSystemMessage
|
|
1981
2089
|
});
|
|
@@ -1987,7 +2095,7 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
|
|
|
1987
2095
|
(_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
|
|
1988
2096
|
suggestionsAbortControllerRef.current = null;
|
|
1989
2097
|
};
|
|
1990
|
-
const context = (0,
|
|
2098
|
+
const context = (0, import_react_core8.useCopilotContext)();
|
|
1991
2099
|
(0, import_react11.useEffect)(() => {
|
|
1992
2100
|
onInProgress == null ? void 0 : onInProgress(isLoading);
|
|
1993
2101
|
abortSuggestions();
|
|
@@ -2012,9 +2120,9 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
|
|
|
2012
2120
|
const sendMessage = (messageContent) => __async(void 0, null, function* () {
|
|
2013
2121
|
abortSuggestions();
|
|
2014
2122
|
setCurrentSuggestions([]);
|
|
2015
|
-
const message = new
|
|
2123
|
+
const message = new import_runtime_client_gql10.TextMessage({
|
|
2016
2124
|
content: messageContent,
|
|
2017
|
-
role:
|
|
2125
|
+
role: import_runtime_client_gql10.Role.User
|
|
2018
2126
|
});
|
|
2019
2127
|
appendMessage(message);
|
|
2020
2128
|
if (onSubmitMessage) {
|
|
@@ -2037,7 +2145,7 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
|
|
|
2037
2145
|
};
|
|
2038
2146
|
|
|
2039
2147
|
// src/components/chat/Modal.tsx
|
|
2040
|
-
var
|
|
2148
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
2041
2149
|
var CopilotModal = ({
|
|
2042
2150
|
instructions,
|
|
2043
2151
|
defaultOpen = false,
|
|
@@ -2065,19 +2173,19 @@ var CopilotModal = ({
|
|
|
2065
2173
|
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
2066
2174
|
setOpenState(open);
|
|
2067
2175
|
};
|
|
2068
|
-
return /* @__PURE__ */ (0,
|
|
2176
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(ChatContextProvider, { icons, labels, open: openState, setOpen, children: [
|
|
2069
2177
|
children,
|
|
2070
|
-
/* @__PURE__ */ (0,
|
|
2071
|
-
/* @__PURE__ */ (0,
|
|
2072
|
-
/* @__PURE__ */ (0,
|
|
2178
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className, children: [
|
|
2179
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Button2, {}),
|
|
2180
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
|
|
2073
2181
|
Window2,
|
|
2074
2182
|
{
|
|
2075
2183
|
clickOutsideToClose,
|
|
2076
2184
|
shortcut,
|
|
2077
2185
|
hitEscapeToClose,
|
|
2078
2186
|
children: [
|
|
2079
|
-
/* @__PURE__ */ (0,
|
|
2080
|
-
/* @__PURE__ */ (0,
|
|
2187
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Header2, {}),
|
|
2188
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
2081
2189
|
CopilotChat,
|
|
2082
2190
|
{
|
|
2083
2191
|
instructions,
|
|
@@ -2098,17 +2206,17 @@ var CopilotModal = ({
|
|
|
2098
2206
|
};
|
|
2099
2207
|
|
|
2100
2208
|
// src/components/chat/Popup.tsx
|
|
2101
|
-
var
|
|
2209
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
2102
2210
|
function CopilotPopup(props) {
|
|
2103
2211
|
props = __spreadProps(__spreadValues({}, props), {
|
|
2104
2212
|
className: props.className ? props.className + " copilotKitPopup" : "copilotKitPopup"
|
|
2105
2213
|
});
|
|
2106
|
-
return /* @__PURE__ */ (0,
|
|
2214
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(CopilotModal, __spreadProps(__spreadValues({}, props), { children: props.children }));
|
|
2107
2215
|
}
|
|
2108
2216
|
|
|
2109
2217
|
// src/components/chat/Sidebar.tsx
|
|
2110
2218
|
var import_react13 = require("react");
|
|
2111
|
-
var
|
|
2219
|
+
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
2112
2220
|
function CopilotSidebar(props) {
|
|
2113
2221
|
props = __spreadProps(__spreadValues({}, props), {
|
|
2114
2222
|
className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar"
|
|
@@ -2121,12 +2229,12 @@ function CopilotSidebar(props) {
|
|
|
2121
2229
|
(_a = props.onSetOpen) == null ? void 0 : _a.call(props, open);
|
|
2122
2230
|
setExpandedClassName(open ? "sidebarExpanded" : "");
|
|
2123
2231
|
};
|
|
2124
|
-
return /* @__PURE__ */ (0,
|
|
2232
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: `copilotKitSidebarContentWrapper ${expandedClassName}`, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(CopilotModal, __spreadProps(__spreadValues(__spreadValues({}, props), { onSetOpen }), { children: props.children })) });
|
|
2125
2233
|
}
|
|
2126
2234
|
|
|
2127
2235
|
// src/hooks/use-copilot-chat-suggestions.tsx
|
|
2128
2236
|
var import_react14 = require("react");
|
|
2129
|
-
var
|
|
2237
|
+
var import_react_core9 = require("@copilotkit/react-core");
|
|
2130
2238
|
var import_shared4 = require("@copilotkit/shared");
|
|
2131
2239
|
function useCopilotChatSuggestions({
|
|
2132
2240
|
instructions,
|
|
@@ -2134,7 +2242,7 @@ function useCopilotChatSuggestions({
|
|
|
2134
2242
|
minSuggestions = 1,
|
|
2135
2243
|
maxSuggestions = 3
|
|
2136
2244
|
}, dependencies = []) {
|
|
2137
|
-
const context = (0,
|
|
2245
|
+
const context = (0, import_react_core9.useCopilotContext)();
|
|
2138
2246
|
(0, import_react14.useEffect)(() => {
|
|
2139
2247
|
const id = (0, import_shared4.randomId)();
|
|
2140
2248
|
context.addChatSuggestionConfiguration(id, {
|