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