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