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