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