@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
|
@@ -377,20 +377,365 @@ var ChatContextProvider = ({
|
|
|
377
377
|
};
|
|
378
378
|
|
|
379
379
|
// src/components/chat/Messages.tsx
|
|
380
|
-
var
|
|
380
|
+
var import_react2 = __toESM(require("react"));
|
|
381
|
+
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
382
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
383
|
+
var Messages = ({
|
|
384
|
+
messages,
|
|
385
|
+
inProgress,
|
|
386
|
+
children,
|
|
387
|
+
RenderTextMessage: RenderTextMessage2,
|
|
388
|
+
RenderActionExecutionMessage: RenderActionExecutionMessage2,
|
|
389
|
+
RenderAgentStateMessage: RenderAgentStateMessage2,
|
|
390
|
+
RenderResultMessage: RenderResultMessage2
|
|
391
|
+
}) => {
|
|
392
|
+
const context = useChatContext();
|
|
393
|
+
const initialMessages = (0, import_react2.useMemo)(
|
|
394
|
+
() => makeInitialMessages(context.labels.initial),
|
|
395
|
+
[context.labels.initial]
|
|
396
|
+
);
|
|
397
|
+
messages = [...initialMessages, ...messages];
|
|
398
|
+
const actionResults = {};
|
|
399
|
+
for (let i = 0; i < messages.length; i++) {
|
|
400
|
+
if (messages[i] instanceof import_runtime_client_gql.ActionExecutionMessage) {
|
|
401
|
+
const id = messages[i].id;
|
|
402
|
+
const resultMessage = messages.find(
|
|
403
|
+
(message) => message instanceof import_runtime_client_gql.ResultMessage && message.actionExecutionId === id
|
|
404
|
+
);
|
|
405
|
+
if (resultMessage) {
|
|
406
|
+
actionResults[id] = import_runtime_client_gql.ResultMessage.decodeResult(resultMessage.result || "");
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
const messagesEndRef = import_react2.default.useRef(null);
|
|
411
|
+
const scrollToBottom = () => {
|
|
412
|
+
if (messagesEndRef.current) {
|
|
413
|
+
messagesEndRef.current.scrollIntoView({
|
|
414
|
+
behavior: "auto"
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
(0, import_react2.useEffect)(() => {
|
|
419
|
+
scrollToBottom();
|
|
420
|
+
}, [messages]);
|
|
421
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "copilotKitMessages", children: [
|
|
422
|
+
messages.map((message, index) => {
|
|
423
|
+
const isCurrentMessage = index === messages.length - 1;
|
|
424
|
+
if (message instanceof import_runtime_client_gql.TextMessage) {
|
|
425
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
426
|
+
RenderTextMessage2,
|
|
427
|
+
{
|
|
428
|
+
message,
|
|
429
|
+
inProgress,
|
|
430
|
+
index,
|
|
431
|
+
isCurrentMessage
|
|
432
|
+
},
|
|
433
|
+
index
|
|
434
|
+
);
|
|
435
|
+
} else if (message instanceof import_runtime_client_gql.ActionExecutionMessage) {
|
|
436
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
437
|
+
RenderActionExecutionMessage2,
|
|
438
|
+
{
|
|
439
|
+
message,
|
|
440
|
+
inProgress,
|
|
441
|
+
index,
|
|
442
|
+
isCurrentMessage,
|
|
443
|
+
actionResult: actionResults[message.id]
|
|
444
|
+
},
|
|
445
|
+
index
|
|
446
|
+
);
|
|
447
|
+
} else if (message instanceof import_runtime_client_gql.AgentStateMessage) {
|
|
448
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
449
|
+
RenderAgentStateMessage2,
|
|
450
|
+
{
|
|
451
|
+
message,
|
|
452
|
+
inProgress,
|
|
453
|
+
index,
|
|
454
|
+
isCurrentMessage
|
|
455
|
+
},
|
|
456
|
+
index
|
|
457
|
+
);
|
|
458
|
+
} else if (message instanceof import_runtime_client_gql.ResultMessage) {
|
|
459
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
460
|
+
RenderResultMessage2,
|
|
461
|
+
{
|
|
462
|
+
message,
|
|
463
|
+
inProgress,
|
|
464
|
+
index,
|
|
465
|
+
isCurrentMessage
|
|
466
|
+
},
|
|
467
|
+
index
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
}),
|
|
471
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("footer", { ref: messagesEndRef, children })
|
|
472
|
+
] });
|
|
473
|
+
};
|
|
474
|
+
function makeInitialMessages(initial) {
|
|
475
|
+
let initialArray = [];
|
|
476
|
+
if (initial) {
|
|
477
|
+
if (Array.isArray(initial)) {
|
|
478
|
+
initialArray.push(...initial);
|
|
479
|
+
} else {
|
|
480
|
+
initialArray.push(initial);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
return initialArray.map(
|
|
484
|
+
(message) => new import_runtime_client_gql.TextMessage({
|
|
485
|
+
role: import_runtime_client_gql.Role.Assistant,
|
|
486
|
+
content: message
|
|
487
|
+
})
|
|
488
|
+
);
|
|
489
|
+
}
|
|
381
490
|
|
|
382
|
-
// src/components/chat/
|
|
491
|
+
// src/components/chat/Input.tsx
|
|
492
|
+
var import_react5 = require("react");
|
|
493
|
+
|
|
494
|
+
// src/components/chat/Textarea.tsx
|
|
383
495
|
var import_react3 = require("react");
|
|
496
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
497
|
+
var AutoResizingTextarea = (0, import_react3.forwardRef)(
|
|
498
|
+
({ maxRows = 1, placeholder, value, onChange, onKeyDown, autoFocus }, ref) => {
|
|
499
|
+
const internalTextareaRef = (0, import_react3.useRef)(null);
|
|
500
|
+
const [maxHeight, setMaxHeight] = (0, import_react3.useState)(0);
|
|
501
|
+
(0, import_react3.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
502
|
+
(0, import_react3.useEffect)(() => {
|
|
503
|
+
const calculateMaxHeight = () => {
|
|
504
|
+
const textarea = internalTextareaRef.current;
|
|
505
|
+
if (textarea) {
|
|
506
|
+
textarea.style.height = "auto";
|
|
507
|
+
const singleRowHeight = textarea.scrollHeight;
|
|
508
|
+
setMaxHeight(singleRowHeight * maxRows);
|
|
509
|
+
if (autoFocus) {
|
|
510
|
+
textarea.focus();
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
calculateMaxHeight();
|
|
515
|
+
}, [maxRows]);
|
|
516
|
+
(0, import_react3.useEffect)(() => {
|
|
517
|
+
const textarea = internalTextareaRef.current;
|
|
518
|
+
if (textarea) {
|
|
519
|
+
textarea.style.height = "auto";
|
|
520
|
+
textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;
|
|
521
|
+
}
|
|
522
|
+
}, [value, maxHeight]);
|
|
523
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
524
|
+
"textarea",
|
|
525
|
+
{
|
|
526
|
+
ref: internalTextareaRef,
|
|
527
|
+
value,
|
|
528
|
+
onChange,
|
|
529
|
+
onKeyDown,
|
|
530
|
+
placeholder,
|
|
531
|
+
style: {
|
|
532
|
+
overflow: "auto",
|
|
533
|
+
resize: "none",
|
|
534
|
+
maxHeight: `${maxHeight}px`
|
|
535
|
+
},
|
|
536
|
+
rows: 1
|
|
537
|
+
}
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
);
|
|
541
|
+
var Textarea_default = AutoResizingTextarea;
|
|
542
|
+
|
|
543
|
+
// src/hooks/use-push-to-talk.tsx
|
|
544
|
+
var import_react_core = require("@copilotkit/react-core");
|
|
545
|
+
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
546
|
+
var import_react4 = require("react");
|
|
547
|
+
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
548
|
+
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
549
|
+
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
550
|
+
audioContextRef.current = new window.AudioContext();
|
|
551
|
+
yield audioContextRef.current.resume();
|
|
552
|
+
}
|
|
553
|
+
mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
|
|
554
|
+
mediaRecorderRef.current.start(1e3);
|
|
555
|
+
mediaRecorderRef.current.ondataavailable = (event) => {
|
|
556
|
+
recordedChunks.push(event.data);
|
|
557
|
+
};
|
|
558
|
+
mediaRecorderRef.current.onstop = onStop;
|
|
559
|
+
});
|
|
560
|
+
var stopRecording = (mediaRecorderRef) => {
|
|
561
|
+
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
|
|
562
|
+
mediaRecorderRef.current.stop();
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
var transcribeAudio = (recordedChunks, transcribeAudioUrl) => __async(void 0, null, function* () {
|
|
566
|
+
const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
|
|
567
|
+
const formData = new FormData();
|
|
568
|
+
formData.append("file", completeBlob, "recording.mp4");
|
|
569
|
+
const response = yield fetch(transcribeAudioUrl, {
|
|
570
|
+
method: "POST",
|
|
571
|
+
body: formData
|
|
572
|
+
});
|
|
573
|
+
if (!response.ok) {
|
|
574
|
+
throw new Error(`Error: ${response.statusText}`);
|
|
575
|
+
}
|
|
576
|
+
const transcription = yield response.json();
|
|
577
|
+
return transcription.text;
|
|
578
|
+
});
|
|
579
|
+
var playAudioResponse = (text, textToSpeechUrl, audioContext) => {
|
|
580
|
+
const encodedText = encodeURIComponent(text);
|
|
581
|
+
const url = `${textToSpeechUrl}?text=${encodedText}`;
|
|
582
|
+
fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
|
|
583
|
+
const source = audioContext.createBufferSource();
|
|
584
|
+
source.buffer = audioBuffer;
|
|
585
|
+
source.connect(audioContext.destination);
|
|
586
|
+
source.start(0);
|
|
587
|
+
}).catch((error) => {
|
|
588
|
+
console.error("Error with decoding audio data", error);
|
|
589
|
+
});
|
|
590
|
+
};
|
|
591
|
+
var usePushToTalk = ({
|
|
592
|
+
sendFunction,
|
|
593
|
+
inProgress
|
|
594
|
+
}) => {
|
|
595
|
+
const [pushToTalkState, setPushToTalkState] = (0, import_react4.useState)("idle");
|
|
596
|
+
const mediaStreamRef = (0, import_react4.useRef)(null);
|
|
597
|
+
const audioContextRef = (0, import_react4.useRef)(null);
|
|
598
|
+
const mediaRecorderRef = (0, import_react4.useRef)(null);
|
|
599
|
+
const recordedChunks = (0, import_react4.useRef)([]);
|
|
600
|
+
const context = (0, import_react_core.useCopilotContext)();
|
|
601
|
+
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react4.useState)(null);
|
|
602
|
+
(0, import_react4.useEffect)(() => {
|
|
603
|
+
if (pushToTalkState === "recording") {
|
|
604
|
+
startRecording(
|
|
605
|
+
mediaStreamRef,
|
|
606
|
+
mediaRecorderRef,
|
|
607
|
+
audioContextRef,
|
|
608
|
+
recordedChunks.current,
|
|
609
|
+
() => {
|
|
610
|
+
setPushToTalkState("transcribing");
|
|
611
|
+
}
|
|
612
|
+
);
|
|
613
|
+
} else {
|
|
614
|
+
stopRecording(mediaRecorderRef);
|
|
615
|
+
if (pushToTalkState === "transcribing") {
|
|
616
|
+
transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl).then(
|
|
617
|
+
(transcription) => __async(void 0, null, function* () {
|
|
618
|
+
recordedChunks.current = [];
|
|
619
|
+
setPushToTalkState("idle");
|
|
620
|
+
const message = yield sendFunction(transcription);
|
|
621
|
+
setStartReadingFromMessageId(message.id);
|
|
622
|
+
})
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
return () => {
|
|
627
|
+
stopRecording(mediaRecorderRef);
|
|
628
|
+
};
|
|
629
|
+
}, [pushToTalkState]);
|
|
630
|
+
(0, import_react4.useEffect)(() => {
|
|
631
|
+
if (inProgress === false && startReadingFromMessageId) {
|
|
632
|
+
const lastMessageIndex = context.messages.findIndex(
|
|
633
|
+
(message) => message.id === startReadingFromMessageId
|
|
634
|
+
);
|
|
635
|
+
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
|
|
636
|
+
(message) => message instanceof import_runtime_client_gql2.TextMessage && message.role === "assistant"
|
|
637
|
+
);
|
|
638
|
+
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
639
|
+
playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
|
|
640
|
+
setStartReadingFromMessageId(null);
|
|
641
|
+
}
|
|
642
|
+
}, [startReadingFromMessageId, inProgress]);
|
|
643
|
+
return { pushToTalkState, setPushToTalkState };
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
// src/components/chat/Input.tsx
|
|
647
|
+
var import_react_core2 = require("@copilotkit/react-core");
|
|
648
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
649
|
+
var Input = ({ inProgress, onSend, isVisible = false }) => {
|
|
650
|
+
const context = useChatContext();
|
|
651
|
+
const copilotContext = (0, import_react_core2.useCopilotContext)();
|
|
652
|
+
const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
|
|
653
|
+
const textareaRef = (0, import_react5.useRef)(null);
|
|
654
|
+
const handleDivClick = (event) => {
|
|
655
|
+
var _a;
|
|
656
|
+
if (event.target !== event.currentTarget)
|
|
657
|
+
return;
|
|
658
|
+
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
659
|
+
};
|
|
660
|
+
const [text, setText] = (0, import_react5.useState)("");
|
|
661
|
+
const send = () => {
|
|
662
|
+
var _a;
|
|
663
|
+
if (inProgress)
|
|
664
|
+
return;
|
|
665
|
+
onSend(text);
|
|
666
|
+
setText("");
|
|
667
|
+
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
668
|
+
};
|
|
669
|
+
(0, import_react5.useEffect)(() => {
|
|
670
|
+
var _a;
|
|
671
|
+
if (isVisible) {
|
|
672
|
+
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
673
|
+
}
|
|
674
|
+
}, [isVisible]);
|
|
675
|
+
const { pushToTalkState, setPushToTalkState } = usePushToTalk({
|
|
676
|
+
sendFunction: onSend,
|
|
677
|
+
inProgress
|
|
678
|
+
});
|
|
679
|
+
const sendIcon = inProgress || pushToTalkState === "transcribing" ? context.icons.activityIcon : context.icons.sendIcon;
|
|
680
|
+
const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
|
|
681
|
+
const sendDisabled = inProgress || text.length === 0 || pushToTalkState !== "idle";
|
|
682
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "copilotKitInput", onClick: handleDivClick, children: [
|
|
683
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
684
|
+
Textarea_default,
|
|
685
|
+
{
|
|
686
|
+
ref: textareaRef,
|
|
687
|
+
placeholder: context.labels.placeholder,
|
|
688
|
+
autoFocus: true,
|
|
689
|
+
maxRows: 5,
|
|
690
|
+
value: text,
|
|
691
|
+
onChange: (event) => setText(event.target.value),
|
|
692
|
+
onKeyDown: (event) => {
|
|
693
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
694
|
+
event.preventDefault();
|
|
695
|
+
send();
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
),
|
|
700
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "copilotKitInputControls", children: [
|
|
701
|
+
showPushToTalk && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
702
|
+
"button",
|
|
703
|
+
{
|
|
704
|
+
onClick: () => setPushToTalkState(pushToTalkState === "idle" ? "recording" : "transcribing"),
|
|
705
|
+
className: pushToTalkState === "recording" ? "copilotKitPushToTalkRecording" : "",
|
|
706
|
+
children: context.icons.pushToTalkIcon
|
|
707
|
+
}
|
|
708
|
+
),
|
|
709
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { disabled: sendDisabled, onClick: send, children: sendIcon })
|
|
710
|
+
] })
|
|
711
|
+
] });
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
// src/components/chat/Response.tsx
|
|
715
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
716
|
+
var ResponseButton = ({ onClick, inProgress }) => {
|
|
717
|
+
const context = useChatContext();
|
|
718
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("button", { onClick, className: "copilotKitResponseButton", children: [
|
|
719
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: inProgress ? context.icons.stopIcon : context.icons.regenerateIcon }),
|
|
720
|
+
inProgress ? context.labels.stopGenerating : context.labels.regenerateResponse
|
|
721
|
+
] });
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
// src/components/chat/messages/RenderTextMessage.tsx
|
|
725
|
+
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
726
|
+
|
|
727
|
+
// src/components/chat/Markdown.tsx
|
|
728
|
+
var import_react7 = require("react");
|
|
384
729
|
var import_react_markdown = __toESM(require("react-markdown"));
|
|
385
730
|
|
|
386
731
|
// src/components/chat/CodeBlock.tsx
|
|
387
|
-
var
|
|
732
|
+
var import_react6 = require("react");
|
|
388
733
|
var import_react_syntax_highlighter = require("react-syntax-highlighter");
|
|
389
734
|
|
|
390
735
|
// src/hooks/use-copy-to-clipboard.tsx
|
|
391
|
-
var
|
|
736
|
+
var React5 = __toESM(require("react"));
|
|
392
737
|
function useCopyToClipboard({ timeout = 2e3 }) {
|
|
393
|
-
const [isCopied, setIsCopied] =
|
|
738
|
+
const [isCopied, setIsCopied] = React5.useState(false);
|
|
394
739
|
const copyToClipboard = (value) => {
|
|
395
740
|
var _a;
|
|
396
741
|
if (typeof window === "undefined" || !((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
|
|
@@ -410,7 +755,7 @@ function useCopyToClipboard({ timeout = 2e3 }) {
|
|
|
410
755
|
}
|
|
411
756
|
|
|
412
757
|
// src/components/chat/CodeBlock.tsx
|
|
413
|
-
var
|
|
758
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
414
759
|
var programmingLanguages = {
|
|
415
760
|
javascript: ".js",
|
|
416
761
|
python: ".py",
|
|
@@ -445,7 +790,7 @@ var generateRandomString = (length, lowercase = false) => {
|
|
|
445
790
|
}
|
|
446
791
|
return lowercase ? result.toLowerCase() : result;
|
|
447
792
|
};
|
|
448
|
-
var CodeBlock = (0,
|
|
793
|
+
var CodeBlock = (0, import_react6.memo)(({ language, value }) => {
|
|
449
794
|
const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2e3 });
|
|
450
795
|
const downloadAsFile = () => {
|
|
451
796
|
if (typeof window === "undefined") {
|
|
@@ -473,21 +818,21 @@ var CodeBlock = (0, import_react2.memo)(({ language, value }) => {
|
|
|
473
818
|
return;
|
|
474
819
|
copyToClipboard(value);
|
|
475
820
|
};
|
|
476
|
-
return /* @__PURE__ */ (0,
|
|
477
|
-
/* @__PURE__ */ (0,
|
|
478
|
-
/* @__PURE__ */ (0,
|
|
479
|
-
/* @__PURE__ */ (0,
|
|
480
|
-
/* @__PURE__ */ (0,
|
|
481
|
-
/* @__PURE__ */ (0,
|
|
482
|
-
/* @__PURE__ */ (0,
|
|
821
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "copilotKitCodeBlock", children: [
|
|
822
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "copilotKitCodeBlockToolbar", children: [
|
|
823
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "copilotKitCodeBlockToolbarLanguage", children: language }),
|
|
824
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "copilotKitCodeBlockToolbarButtons", children: [
|
|
825
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("button", { className: "copilotKitCodeBlockToolbarButton", onClick: downloadAsFile, children: [
|
|
826
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(DownloadIcon, {}),
|
|
827
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "sr-only", children: "Download" })
|
|
483
828
|
] }),
|
|
484
|
-
/* @__PURE__ */ (0,
|
|
485
|
-
isCopied ? /* @__PURE__ */ (0,
|
|
486
|
-
/* @__PURE__ */ (0,
|
|
829
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("button", { className: "copilotKitCodeBlockToolbarButton", onClick: onCopy, children: [
|
|
830
|
+
isCopied ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CheckIcon, {}) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopyIcon, {}),
|
|
831
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "sr-only", children: "Copy code" })
|
|
487
832
|
] })
|
|
488
833
|
] })
|
|
489
834
|
] }),
|
|
490
|
-
/* @__PURE__ */ (0,
|
|
835
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
491
836
|
import_react_syntax_highlighter.Prism,
|
|
492
837
|
{
|
|
493
838
|
language,
|
|
@@ -777,481 +1122,229 @@ var highlightStyle = {
|
|
|
777
1122
|
color: "#808080"
|
|
778
1123
|
},
|
|
779
1124
|
'pre[class*="language-"] > code[class*="language-"]': {
|
|
780
|
-
position: "relative",
|
|
781
|
-
zIndex: "1"
|
|
782
|
-
},
|
|
783
|
-
".line-highlight.line-highlight": {
|
|
784
|
-
background: "#f7ebc6",
|
|
785
|
-
boxShadow: "inset 5px 0 0 #f7d87c",
|
|
786
|
-
zIndex: "0"
|
|
787
|
-
}
|
|
788
|
-
};
|
|
789
|
-
|
|
790
|
-
// src/components/chat/Markdown.tsx
|
|
791
|
-
var import_remark_gfm = __toESM(require("remark-gfm"));
|
|
792
|
-
var import_remark_math = __toESM(require("remark-math"));
|
|
793
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
794
|
-
var MemoizedReactMarkdown = (0, import_react3.memo)(
|
|
795
|
-
import_react_markdown.default,
|
|
796
|
-
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.className === nextProps.className
|
|
797
|
-
);
|
|
798
|
-
var Markdown = ({ content }) => {
|
|
799
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MemoizedReactMarkdown, { components, remarkPlugins: [import_remark_gfm.default, import_remark_math.default], children: content }) });
|
|
800
|
-
};
|
|
801
|
-
var components = {
|
|
802
|
-
p({ children }) {
|
|
803
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children });
|
|
804
|
-
},
|
|
805
|
-
a(_a) {
|
|
806
|
-
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
807
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
808
|
-
"a",
|
|
809
|
-
__spreadProps(__spreadValues({
|
|
810
|
-
style: { color: "blue", textDecoration: "underline" }
|
|
811
|
-
}, props), {
|
|
812
|
-
target: "_blank",
|
|
813
|
-
rel: "noopener noreferrer",
|
|
814
|
-
children
|
|
815
|
-
})
|
|
816
|
-
);
|
|
817
|
-
},
|
|
818
|
-
code(_c) {
|
|
819
|
-
var _d = _c, { children, className, inline } = _d, props = __objRest(_d, ["children", "className", "inline"]);
|
|
820
|
-
if (children.length) {
|
|
821
|
-
if (children[0] == "\u258D") {
|
|
822
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
823
|
-
"span",
|
|
824
|
-
{
|
|
825
|
-
style: {
|
|
826
|
-
animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
|
|
827
|
-
marginTop: "0.25rem"
|
|
828
|
-
},
|
|
829
|
-
children: "\u258D"
|
|
830
|
-
}
|
|
831
|
-
);
|
|
832
|
-
}
|
|
833
|
-
children[0] = children[0].replace("`\u258D`", "\u258D");
|
|
834
|
-
}
|
|
835
|
-
const match = /language-(\w+)/.exec(className || "");
|
|
836
|
-
if (inline) {
|
|
837
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("code", __spreadProps(__spreadValues({ className }, props), { children }));
|
|
838
|
-
}
|
|
839
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
840
|
-
CodeBlock,
|
|
841
|
-
__spreadValues({
|
|
842
|
-
language: match && match[1] || "",
|
|
843
|
-
value: String(children).replace(/\n$/, "")
|
|
844
|
-
}, props),
|
|
845
|
-
Math.random()
|
|
846
|
-
);
|
|
847
|
-
}
|
|
848
|
-
};
|
|
849
|
-
|
|
850
|
-
// src/components/chat/Messages.tsx
|
|
851
|
-
var import_react_core = require("@copilotkit/react-core");
|
|
852
|
-
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
853
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
854
|
-
var Messages = ({ messages, inProgress, children }) => {
|
|
855
|
-
const { chatComponentsCache } = (0, import_react_core.useCopilotContext)();
|
|
856
|
-
const context = useChatContext();
|
|
857
|
-
const initialMessages = (0, import_react4.useMemo)(
|
|
858
|
-
() => makeInitialMessages(context.labels.initial),
|
|
859
|
-
[context.labels.initial]
|
|
860
|
-
);
|
|
861
|
-
messages = [...initialMessages, ...messages];
|
|
862
|
-
const functionResults = {};
|
|
863
|
-
for (let i = 0; i < messages.length; i++) {
|
|
864
|
-
if (messages[i] instanceof import_runtime_client_gql.ActionExecutionMessage) {
|
|
865
|
-
const id = messages[i].id;
|
|
866
|
-
const resultMessage = messages.find(
|
|
867
|
-
(message) => message instanceof import_runtime_client_gql.ResultMessage && message.actionExecutionId === id
|
|
868
|
-
);
|
|
869
|
-
if (resultMessage) {
|
|
870
|
-
functionResults[id] = import_runtime_client_gql.ResultMessage.decodeResult(resultMessage.result || "");
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
const messagesEndRef = import_react4.default.useRef(null);
|
|
875
|
-
const scrollToBottom = () => {
|
|
876
|
-
if (messagesEndRef.current) {
|
|
877
|
-
messagesEndRef.current.scrollIntoView({
|
|
878
|
-
behavior: "auto"
|
|
879
|
-
});
|
|
880
|
-
}
|
|
881
|
-
};
|
|
882
|
-
(0, import_react4.useEffect)(() => {
|
|
883
|
-
scrollToBottom();
|
|
884
|
-
}, [messages]);
|
|
885
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "copilotKitMessages", children: [
|
|
886
|
-
messages.map((message, index) => {
|
|
887
|
-
const isCurrentMessage = index === messages.length - 1;
|
|
888
|
-
if (message instanceof import_runtime_client_gql.TextMessage && message.role === "user") {
|
|
889
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: message.content }, index);
|
|
890
|
-
} else if (message instanceof import_runtime_client_gql.TextMessage && message.role == "assistant") {
|
|
891
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: isCurrentMessage && inProgress && !message.content ? context.icons.spinnerIcon : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Markdown, { content: message.content }) }, index);
|
|
892
|
-
} else if (message instanceof import_runtime_client_gql.ActionExecutionMessage) {
|
|
893
|
-
if (chatComponentsCache.current !== null && chatComponentsCache.current.actions[message.name]) {
|
|
894
|
-
const render = chatComponentsCache.current.actions[message.name];
|
|
895
|
-
if (typeof render === "string") {
|
|
896
|
-
if (isCurrentMessage && inProgress) {
|
|
897
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
898
|
-
context.icons.spinnerIcon,
|
|
899
|
-
" ",
|
|
900
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "inProgressLabel", children: render })
|
|
901
|
-
] }, index);
|
|
902
|
-
} else {
|
|
903
|
-
return null;
|
|
904
|
-
}
|
|
905
|
-
} else {
|
|
906
|
-
const args = message.arguments;
|
|
907
|
-
let status = "inProgress";
|
|
908
|
-
if (functionResults[message.id] !== void 0) {
|
|
909
|
-
status = "complete";
|
|
910
|
-
} else if (message.status.code !== import_runtime_client_gql.MessageStatusCode.Pending) {
|
|
911
|
-
status = "executing";
|
|
912
|
-
}
|
|
913
|
-
try {
|
|
914
|
-
const toRender = render({
|
|
915
|
-
status,
|
|
916
|
-
args,
|
|
917
|
-
result: functionResults[message.id]
|
|
918
|
-
});
|
|
919
|
-
if (!toRender && status === "complete") {
|
|
920
|
-
return null;
|
|
921
|
-
}
|
|
922
|
-
if (typeof toRender === "string") {
|
|
923
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
924
|
-
isCurrentMessage && inProgress && context.icons.spinnerIcon,
|
|
925
|
-
" ",
|
|
926
|
-
toRender
|
|
927
|
-
] }, index);
|
|
928
|
-
} else {
|
|
929
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
|
|
930
|
-
}
|
|
931
|
-
} catch (e) {
|
|
932
|
-
console.error(`Error executing render function for action ${message.name}: ${e}`);
|
|
933
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
934
|
-
isCurrentMessage && inProgress && context.icons.spinnerIcon,
|
|
935
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("b", { children: [
|
|
936
|
-
"\u274C Error executing render: ",
|
|
937
|
-
message.name
|
|
938
|
-
] }),
|
|
939
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("br", {}),
|
|
940
|
-
e instanceof Error ? e.message : String(e)
|
|
941
|
-
] }, index);
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
} else if (!inProgress || !isCurrentMessage) {
|
|
945
|
-
return null;
|
|
946
|
-
} else {
|
|
947
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
|
|
948
|
-
}
|
|
949
|
-
} else if (message instanceof import_runtime_client_gql.AgentStateMessage) {
|
|
950
|
-
let render;
|
|
951
|
-
if (chatComponentsCache.current !== null) {
|
|
952
|
-
render = chatComponentsCache.current.coagentActions[`${message.agentName}-${message.nodeName}`] || chatComponentsCache.current.coagentActions[`${message.agentName}-global`];
|
|
953
|
-
}
|
|
954
|
-
if (render) {
|
|
955
|
-
if (typeof render === "string") {
|
|
956
|
-
if (isCurrentMessage && inProgress) {
|
|
957
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
958
|
-
context.icons.spinnerIcon,
|
|
959
|
-
" ",
|
|
960
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "inProgressLabel", children: render })
|
|
961
|
-
] }, index);
|
|
962
|
-
} else {
|
|
963
|
-
return null;
|
|
964
|
-
}
|
|
965
|
-
} else {
|
|
966
|
-
const state = message.state;
|
|
967
|
-
let status = message.active ? "inProgress" : "complete";
|
|
968
|
-
const toRender = render({
|
|
969
|
-
status,
|
|
970
|
-
state,
|
|
971
|
-
nodeName: message.nodeName
|
|
972
|
-
});
|
|
973
|
-
if (!toRender && status === "complete") {
|
|
974
|
-
return null;
|
|
975
|
-
}
|
|
976
|
-
if (typeof toRender === "string") {
|
|
977
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
978
|
-
isCurrentMessage && inProgress && context.icons.spinnerIcon,
|
|
979
|
-
" ",
|
|
980
|
-
toRender
|
|
981
|
-
] }, index);
|
|
982
|
-
} else {
|
|
983
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
} else if (!inProgress || !isCurrentMessage) {
|
|
987
|
-
return null;
|
|
988
|
-
} else {
|
|
989
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
|
|
990
|
-
}
|
|
991
|
-
} else if (message instanceof import_runtime_client_gql.ResultMessage && inProgress && isCurrentMessage) {
|
|
992
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
|
|
993
|
-
}
|
|
994
|
-
}),
|
|
995
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("footer", { ref: messagesEndRef, children })
|
|
996
|
-
] });
|
|
997
|
-
};
|
|
998
|
-
function makeInitialMessages(initial) {
|
|
999
|
-
let initialArray = [];
|
|
1000
|
-
if (initial) {
|
|
1001
|
-
if (Array.isArray(initial)) {
|
|
1002
|
-
initialArray.push(...initial);
|
|
1003
|
-
} else {
|
|
1004
|
-
initialArray.push(initial);
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
return initialArray.map(
|
|
1008
|
-
(message) => new import_runtime_client_gql.TextMessage({
|
|
1009
|
-
role: import_runtime_client_gql.Role.Assistant,
|
|
1010
|
-
content: message
|
|
1011
|
-
})
|
|
1012
|
-
);
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
// src/components/chat/Input.tsx
|
|
1016
|
-
var import_react7 = require("react");
|
|
1017
|
-
|
|
1018
|
-
// src/components/chat/Textarea.tsx
|
|
1019
|
-
var import_react5 = require("react");
|
|
1020
|
-
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1021
|
-
var AutoResizingTextarea = (0, import_react5.forwardRef)(
|
|
1022
|
-
({ maxRows = 1, placeholder, value, onChange, onKeyDown, autoFocus }, ref) => {
|
|
1023
|
-
const internalTextareaRef = (0, import_react5.useRef)(null);
|
|
1024
|
-
const [maxHeight, setMaxHeight] = (0, import_react5.useState)(0);
|
|
1025
|
-
(0, import_react5.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
1026
|
-
(0, import_react5.useEffect)(() => {
|
|
1027
|
-
const calculateMaxHeight = () => {
|
|
1028
|
-
const textarea = internalTextareaRef.current;
|
|
1029
|
-
if (textarea) {
|
|
1030
|
-
textarea.style.height = "auto";
|
|
1031
|
-
const singleRowHeight = textarea.scrollHeight;
|
|
1032
|
-
setMaxHeight(singleRowHeight * maxRows);
|
|
1033
|
-
if (autoFocus) {
|
|
1034
|
-
textarea.focus();
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
};
|
|
1038
|
-
calculateMaxHeight();
|
|
1039
|
-
}, [maxRows]);
|
|
1040
|
-
(0, import_react5.useEffect)(() => {
|
|
1041
|
-
const textarea = internalTextareaRef.current;
|
|
1042
|
-
if (textarea) {
|
|
1043
|
-
textarea.style.height = "auto";
|
|
1044
|
-
textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;
|
|
1045
|
-
}
|
|
1046
|
-
}, [value, maxHeight]);
|
|
1047
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1048
|
-
"textarea",
|
|
1049
|
-
{
|
|
1050
|
-
ref: internalTextareaRef,
|
|
1051
|
-
value,
|
|
1052
|
-
onChange,
|
|
1053
|
-
onKeyDown,
|
|
1054
|
-
placeholder,
|
|
1055
|
-
style: {
|
|
1056
|
-
overflow: "auto",
|
|
1057
|
-
resize: "none",
|
|
1058
|
-
maxHeight: `${maxHeight}px`
|
|
1059
|
-
},
|
|
1060
|
-
rows: 1
|
|
1061
|
-
}
|
|
1062
|
-
);
|
|
1063
|
-
}
|
|
1064
|
-
);
|
|
1065
|
-
var Textarea_default = AutoResizingTextarea;
|
|
1066
|
-
|
|
1067
|
-
// src/hooks/use-push-to-talk.tsx
|
|
1068
|
-
var import_react_core2 = require("@copilotkit/react-core");
|
|
1069
|
-
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
1070
|
-
var import_react6 = require("react");
|
|
1071
|
-
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
1072
|
-
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
1073
|
-
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
1074
|
-
audioContextRef.current = new window.AudioContext();
|
|
1075
|
-
yield audioContextRef.current.resume();
|
|
1076
|
-
}
|
|
1077
|
-
mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
|
|
1078
|
-
mediaRecorderRef.current.start(1e3);
|
|
1079
|
-
mediaRecorderRef.current.ondataavailable = (event) => {
|
|
1080
|
-
recordedChunks.push(event.data);
|
|
1081
|
-
};
|
|
1082
|
-
mediaRecorderRef.current.onstop = onStop;
|
|
1083
|
-
});
|
|
1084
|
-
var stopRecording = (mediaRecorderRef) => {
|
|
1085
|
-
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
|
|
1086
|
-
mediaRecorderRef.current.stop();
|
|
1125
|
+
position: "relative",
|
|
1126
|
+
zIndex: "1"
|
|
1127
|
+
},
|
|
1128
|
+
".line-highlight.line-highlight": {
|
|
1129
|
+
background: "#f7ebc6",
|
|
1130
|
+
boxShadow: "inset 5px 0 0 #f7d87c",
|
|
1131
|
+
zIndex: "0"
|
|
1087
1132
|
}
|
|
1088
1133
|
};
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
}
|
|
1100
|
-
const transcription = yield response.json();
|
|
1101
|
-
return transcription.text;
|
|
1102
|
-
});
|
|
1103
|
-
var playAudioResponse = (text, textToSpeechUrl, audioContext) => {
|
|
1104
|
-
const encodedText = encodeURIComponent(text);
|
|
1105
|
-
const url = `${textToSpeechUrl}?text=${encodedText}`;
|
|
1106
|
-
fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
|
|
1107
|
-
const source = audioContext.createBufferSource();
|
|
1108
|
-
source.buffer = audioBuffer;
|
|
1109
|
-
source.connect(audioContext.destination);
|
|
1110
|
-
source.start(0);
|
|
1111
|
-
}).catch((error) => {
|
|
1112
|
-
console.error("Error with decoding audio data", error);
|
|
1113
|
-
});
|
|
1134
|
+
|
|
1135
|
+
// src/components/chat/Markdown.tsx
|
|
1136
|
+
var import_remark_gfm = __toESM(require("remark-gfm"));
|
|
1137
|
+
var import_remark_math = __toESM(require("remark-math"));
|
|
1138
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1139
|
+
var MemoizedReactMarkdown = (0, import_react7.memo)(
|
|
1140
|
+
import_react_markdown.default,
|
|
1141
|
+
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.className === nextProps.className
|
|
1142
|
+
);
|
|
1143
|
+
var Markdown = ({ content }) => {
|
|
1144
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MemoizedReactMarkdown, { components, remarkPlugins: [import_remark_gfm.default, import_remark_math.default], children: content }) });
|
|
1114
1145
|
};
|
|
1115
|
-
var
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
setStartReadingFromMessageId(message.id);
|
|
1146
|
-
})
|
|
1146
|
+
var components = {
|
|
1147
|
+
p({ children }) {
|
|
1148
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { children });
|
|
1149
|
+
},
|
|
1150
|
+
a(_a) {
|
|
1151
|
+
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
1152
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1153
|
+
"a",
|
|
1154
|
+
__spreadProps(__spreadValues({
|
|
1155
|
+
style: { color: "blue", textDecoration: "underline" }
|
|
1156
|
+
}, props), {
|
|
1157
|
+
target: "_blank",
|
|
1158
|
+
rel: "noopener noreferrer",
|
|
1159
|
+
children
|
|
1160
|
+
})
|
|
1161
|
+
);
|
|
1162
|
+
},
|
|
1163
|
+
code(_c) {
|
|
1164
|
+
var _d = _c, { children, className, inline } = _d, props = __objRest(_d, ["children", "className", "inline"]);
|
|
1165
|
+
if (children.length) {
|
|
1166
|
+
if (children[0] == "\u258D") {
|
|
1167
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1168
|
+
"span",
|
|
1169
|
+
{
|
|
1170
|
+
style: {
|
|
1171
|
+
animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
|
|
1172
|
+
marginTop: "0.25rem"
|
|
1173
|
+
},
|
|
1174
|
+
children: "\u258D"
|
|
1175
|
+
}
|
|
1147
1176
|
);
|
|
1148
1177
|
}
|
|
1178
|
+
children[0] = children[0].replace("`\u258D`", "\u258D");
|
|
1149
1179
|
}
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
}, [pushToTalkState]);
|
|
1154
|
-
(0, import_react6.useEffect)(() => {
|
|
1155
|
-
if (inProgress === false && startReadingFromMessageId) {
|
|
1156
|
-
const lastMessageIndex = context.messages.findIndex(
|
|
1157
|
-
(message) => message.id === startReadingFromMessageId
|
|
1158
|
-
);
|
|
1159
|
-
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
|
|
1160
|
-
(message) => message instanceof import_runtime_client_gql2.TextMessage && message.role === "assistant"
|
|
1161
|
-
);
|
|
1162
|
-
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
1163
|
-
playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
|
|
1164
|
-
setStartReadingFromMessageId(null);
|
|
1180
|
+
const match = /language-(\w+)/.exec(className || "");
|
|
1181
|
+
if (inline) {
|
|
1182
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("code", __spreadProps(__spreadValues({ className }, props), { children }));
|
|
1165
1183
|
}
|
|
1166
|
-
|
|
1167
|
-
|
|
1184
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1185
|
+
CodeBlock,
|
|
1186
|
+
__spreadValues({
|
|
1187
|
+
language: match && match[1] || "",
|
|
1188
|
+
value: String(children).replace(/\n$/, "")
|
|
1189
|
+
}, props),
|
|
1190
|
+
Math.random()
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1168
1193
|
};
|
|
1169
1194
|
|
|
1170
|
-
// src/components/chat/
|
|
1171
|
-
var
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
const
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
if (event.target !== event.currentTarget)
|
|
1181
|
-
return;
|
|
1182
|
-
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1183
|
-
};
|
|
1184
|
-
const [text, setText] = (0, import_react7.useState)("");
|
|
1185
|
-
const send = () => {
|
|
1186
|
-
var _a;
|
|
1187
|
-
if (inProgress)
|
|
1188
|
-
return;
|
|
1189
|
-
onSend(text);
|
|
1190
|
-
setText("");
|
|
1191
|
-
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1192
|
-
};
|
|
1193
|
-
(0, import_react7.useEffect)(() => {
|
|
1194
|
-
var _a;
|
|
1195
|
-
if (isVisible) {
|
|
1196
|
-
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1195
|
+
// src/components/chat/messages/RenderTextMessage.tsx
|
|
1196
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1197
|
+
function RenderTextMessage(props) {
|
|
1198
|
+
const { message, inProgress, index, isCurrentMessage } = props;
|
|
1199
|
+
const { icons } = useChatContext();
|
|
1200
|
+
if (message instanceof import_runtime_client_gql3.TextMessage) {
|
|
1201
|
+
if (message.role === "user") {
|
|
1202
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: message.content }, index);
|
|
1203
|
+
} else if (message.role == "assistant") {
|
|
1204
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: isCurrentMessage && inProgress && !message.content ? icons.spinnerIcon : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Markdown, { content: message.content }) }, index);
|
|
1197
1205
|
}
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
// src/components/chat/messages/RenderActionExecutionMessage.tsx
|
|
1210
|
+
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1211
|
+
var import_react_core3 = require("@copilotkit/react-core");
|
|
1212
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1213
|
+
function RenderActionExecutionMessage(props) {
|
|
1214
|
+
const { message, inProgress, index, isCurrentMessage, actionResult } = props;
|
|
1215
|
+
const { chatComponentsCache } = (0, import_react_core3.useCopilotContext)();
|
|
1216
|
+
const { icons } = useChatContext();
|
|
1217
|
+
if (message instanceof import_runtime_client_gql4.ActionExecutionMessage) {
|
|
1218
|
+
if (chatComponentsCache.current !== null && chatComponentsCache.current.actions[message.name]) {
|
|
1219
|
+
const render = chatComponentsCache.current.actions[message.name];
|
|
1220
|
+
if (typeof render === "string") {
|
|
1221
|
+
if (isCurrentMessage && inProgress) {
|
|
1222
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1223
|
+
icons.spinnerIcon,
|
|
1224
|
+
" ",
|
|
1225
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "inProgressLabel", children: render })
|
|
1226
|
+
] }, index);
|
|
1227
|
+
} else {
|
|
1228
|
+
return null;
|
|
1229
|
+
}
|
|
1230
|
+
} else {
|
|
1231
|
+
const args = message.arguments;
|
|
1232
|
+
let status = "inProgress";
|
|
1233
|
+
if (actionResult !== void 0) {
|
|
1234
|
+
status = "complete";
|
|
1235
|
+
} else if (message.status.code !== import_runtime_client_gql4.MessageStatusCode.Pending) {
|
|
1236
|
+
status = "executing";
|
|
1237
|
+
}
|
|
1238
|
+
try {
|
|
1239
|
+
const toRender = render({
|
|
1240
|
+
status,
|
|
1241
|
+
args,
|
|
1242
|
+
result: actionResult
|
|
1243
|
+
});
|
|
1244
|
+
if (!toRender && status === "complete") {
|
|
1245
|
+
return null;
|
|
1246
|
+
}
|
|
1247
|
+
if (typeof toRender === "string") {
|
|
1248
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1249
|
+
isCurrentMessage && inProgress && icons.spinnerIcon,
|
|
1250
|
+
" ",
|
|
1251
|
+
toRender
|
|
1252
|
+
] }, index);
|
|
1253
|
+
} else {
|
|
1254
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
|
|
1220
1255
|
}
|
|
1256
|
+
} catch (e) {
|
|
1257
|
+
console.error(`Error executing render function for action ${message.name}: ${e}`);
|
|
1258
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1259
|
+
isCurrentMessage && inProgress && icons.spinnerIcon,
|
|
1260
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("b", { children: [
|
|
1261
|
+
"\u274C Error executing render: ",
|
|
1262
|
+
message.name
|
|
1263
|
+
] }),
|
|
1264
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("br", {}),
|
|
1265
|
+
e instanceof Error ? e.message : String(e)
|
|
1266
|
+
] }, index);
|
|
1221
1267
|
}
|
|
1222
1268
|
}
|
|
1223
|
-
)
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
children: context.icons.pushToTalkIcon
|
|
1231
|
-
}
|
|
1232
|
-
),
|
|
1233
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { disabled: sendDisabled, onClick: send, children: sendIcon })
|
|
1234
|
-
] })
|
|
1235
|
-
] });
|
|
1236
|
-
};
|
|
1269
|
+
} else if (!inProgress || !isCurrentMessage) {
|
|
1270
|
+
return null;
|
|
1271
|
+
} else {
|
|
1272
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: icons.spinnerIcon }, index);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1237
1276
|
|
|
1238
|
-
// src/components/chat/
|
|
1239
|
-
var
|
|
1240
|
-
var
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
}
|
|
1277
|
+
// src/components/chat/messages/RenderResultMessage.tsx
|
|
1278
|
+
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1279
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1280
|
+
function RenderResultMessage(props) {
|
|
1281
|
+
const { message, inProgress, index, isCurrentMessage } = props;
|
|
1282
|
+
const { icons } = useChatContext();
|
|
1283
|
+
if (message instanceof import_runtime_client_gql5.ResultMessage && inProgress && isCurrentMessage) {
|
|
1284
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: icons.spinnerIcon }, index);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1247
1287
|
|
|
1248
|
-
// src/components/chat/
|
|
1288
|
+
// src/components/chat/messages/RenderAgentStateMessage.tsx
|
|
1289
|
+
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1249
1290
|
var import_react_core4 = require("@copilotkit/react-core");
|
|
1291
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1292
|
+
function RenderAgentStateMessage(props) {
|
|
1293
|
+
const { message, inProgress, index, isCurrentMessage } = props;
|
|
1294
|
+
const { chatComponentsCache } = (0, import_react_core4.useCopilotContext)();
|
|
1295
|
+
const { icons } = useChatContext();
|
|
1296
|
+
if (message instanceof import_runtime_client_gql6.AgentStateMessage) {
|
|
1297
|
+
let render;
|
|
1298
|
+
if (chatComponentsCache.current !== null) {
|
|
1299
|
+
render = chatComponentsCache.current.coagentActions[`${message.agentName}-${message.nodeName}`] || chatComponentsCache.current.coagentActions[`${message.agentName}-global`];
|
|
1300
|
+
}
|
|
1301
|
+
if (render) {
|
|
1302
|
+
if (typeof render === "string") {
|
|
1303
|
+
if (isCurrentMessage && inProgress) {
|
|
1304
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1305
|
+
icons.spinnerIcon,
|
|
1306
|
+
" ",
|
|
1307
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "inProgressLabel", children: render })
|
|
1308
|
+
] }, index);
|
|
1309
|
+
} else {
|
|
1310
|
+
return null;
|
|
1311
|
+
}
|
|
1312
|
+
} else {
|
|
1313
|
+
const state = message.state;
|
|
1314
|
+
let status = message.active ? "inProgress" : "complete";
|
|
1315
|
+
const toRender = render({
|
|
1316
|
+
status,
|
|
1317
|
+
state,
|
|
1318
|
+
nodeName: message.nodeName
|
|
1319
|
+
});
|
|
1320
|
+
if (!toRender && status === "complete") {
|
|
1321
|
+
return null;
|
|
1322
|
+
}
|
|
1323
|
+
if (typeof toRender === "string") {
|
|
1324
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1325
|
+
isCurrentMessage && inProgress && icons.spinnerIcon,
|
|
1326
|
+
" ",
|
|
1327
|
+
toRender
|
|
1328
|
+
] }, index);
|
|
1329
|
+
} else {
|
|
1330
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
} else if (!inProgress || !isCurrentMessage) {
|
|
1334
|
+
return null;
|
|
1335
|
+
} else {
|
|
1336
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: icons.spinnerIcon }, index);
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
// src/components/chat/Suggestion.tsx
|
|
1342
|
+
var import_react_core5 = require("@copilotkit/react-core");
|
|
1250
1343
|
var import_shared = require("@copilotkit/shared");
|
|
1251
|
-
var
|
|
1252
|
-
var
|
|
1344
|
+
var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
1345
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1253
1346
|
function Suggestion({ title, message, onClick, partial, className }) {
|
|
1254
|
-
return /* @__PURE__ */ (0,
|
|
1347
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
1255
1348
|
"button",
|
|
1256
1349
|
{
|
|
1257
1350
|
disabled: partial,
|
|
@@ -1262,7 +1355,7 @@ function Suggestion({ title, message, onClick, partial, className }) {
|
|
|
1262
1355
|
className: className || "suggestion",
|
|
1263
1356
|
children: [
|
|
1264
1357
|
partial && SmallSpinnerIcon,
|
|
1265
|
-
/* @__PURE__ */ (0,
|
|
1358
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: title })
|
|
1266
1359
|
]
|
|
1267
1360
|
}
|
|
1268
1361
|
);
|
|
@@ -1280,11 +1373,11 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1280
1373
|
for (const config of Object.values(chatSuggestionConfiguration)) {
|
|
1281
1374
|
try {
|
|
1282
1375
|
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.`;
|
|
1283
|
-
const result = yield (0,
|
|
1376
|
+
const result = yield (0, import_react_core5.extract)({
|
|
1284
1377
|
context,
|
|
1285
1378
|
instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. " + config.instructions + "\n\n" + numOfSuggestionsInstructions,
|
|
1286
1379
|
data: "Available tools: " + tools + "\n\n",
|
|
1287
|
-
requestType:
|
|
1380
|
+
requestType: import_runtime_client_gql7.CopilotRequestType.Task,
|
|
1288
1381
|
parameters: [
|
|
1289
1382
|
{
|
|
1290
1383
|
name: "suggestions",
|
|
@@ -1339,14 +1432,14 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1339
1432
|
|
|
1340
1433
|
// src/components/chat/Chat.tsx
|
|
1341
1434
|
var import_react10 = __toESM(require("react"));
|
|
1342
|
-
var
|
|
1343
|
-
var
|
|
1435
|
+
var import_react_core8 = require("@copilotkit/react-core");
|
|
1436
|
+
var import_runtime_client_gql10 = require("@copilotkit/runtime-client-gql");
|
|
1344
1437
|
var import_shared3 = require("@copilotkit/shared");
|
|
1345
1438
|
|
|
1346
1439
|
// src/components/dev-console/utils.ts
|
|
1347
|
-
var
|
|
1348
|
-
var
|
|
1349
|
-
var
|
|
1440
|
+
var import_react_core6 = require("@copilotkit/react-core");
|
|
1441
|
+
var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
|
|
1442
|
+
var import_runtime_client_gql9 = require("@copilotkit/runtime-client-gql");
|
|
1350
1443
|
function shouldShowDevConsole(showDevConsole) {
|
|
1351
1444
|
if (typeof showDevConsole === "boolean") {
|
|
1352
1445
|
return showDevConsole;
|
|
@@ -1408,7 +1501,7 @@ function getPublishedCopilotKitVersion(current, forceCheck = false) {
|
|
|
1408
1501
|
}
|
|
1409
1502
|
function logReadables(context) {
|
|
1410
1503
|
console.log("%cCurrent Readables:", "font-size: 16px; font-weight: bold;");
|
|
1411
|
-
const readables = context.getContextString([],
|
|
1504
|
+
const readables = context.getContextString([], import_react_core6.defaultCopilotContextCategories).trim();
|
|
1412
1505
|
if (readables.length === 0) {
|
|
1413
1506
|
console.log("No readables found");
|
|
1414
1507
|
return;
|
|
@@ -1436,7 +1529,7 @@ function logMessages(context) {
|
|
|
1436
1529
|
return;
|
|
1437
1530
|
}
|
|
1438
1531
|
const tableData = context.messages.map((message) => {
|
|
1439
|
-
if (message instanceof
|
|
1532
|
+
if (message instanceof import_runtime_client_gql8.TextMessage) {
|
|
1440
1533
|
return {
|
|
1441
1534
|
id: message.id,
|
|
1442
1535
|
type: "TextMessage",
|
|
@@ -1445,7 +1538,7 @@ function logMessages(context) {
|
|
|
1445
1538
|
scope: void 0,
|
|
1446
1539
|
content: message.content
|
|
1447
1540
|
};
|
|
1448
|
-
} else if (message instanceof
|
|
1541
|
+
} else if (message instanceof import_runtime_client_gql8.ActionExecutionMessage) {
|
|
1449
1542
|
return {
|
|
1450
1543
|
id: message.id,
|
|
1451
1544
|
type: "ActionExecutionMessage",
|
|
@@ -1454,7 +1547,7 @@ function logMessages(context) {
|
|
|
1454
1547
|
scope: message.scope,
|
|
1455
1548
|
content: message.arguments
|
|
1456
1549
|
};
|
|
1457
|
-
} else if (message instanceof
|
|
1550
|
+
} else if (message instanceof import_runtime_client_gql8.ResultMessage) {
|
|
1458
1551
|
return {
|
|
1459
1552
|
id: message.id,
|
|
1460
1553
|
type: "ResultMessage",
|
|
@@ -1463,7 +1556,7 @@ function logMessages(context) {
|
|
|
1463
1556
|
scope: message.actionExecutionId,
|
|
1464
1557
|
content: message.result
|
|
1465
1558
|
};
|
|
1466
|
-
} else if (message instanceof
|
|
1559
|
+
} else if (message instanceof import_runtime_client_gql9.AgentStateMessage) {
|
|
1467
1560
|
return {
|
|
1468
1561
|
id: message.id,
|
|
1469
1562
|
type: `AgentStateMessage (running: ${message.running})`,
|
|
@@ -1478,12 +1571,12 @@ function logMessages(context) {
|
|
|
1478
1571
|
}
|
|
1479
1572
|
|
|
1480
1573
|
// src/components/dev-console/console.tsx
|
|
1481
|
-
var
|
|
1574
|
+
var import_react_core7 = require("@copilotkit/react-core");
|
|
1482
1575
|
var import_react8 = require("react");
|
|
1483
1576
|
|
|
1484
1577
|
// src/components/dev-console/icons.tsx
|
|
1485
|
-
var
|
|
1486
|
-
var ExclamationMarkTriangleIcon = /* @__PURE__ */ (0,
|
|
1578
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1579
|
+
var ExclamationMarkTriangleIcon = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1487
1580
|
"svg",
|
|
1488
1581
|
{
|
|
1489
1582
|
width: "13.3967723px",
|
|
@@ -1491,7 +1584,7 @@ var ExclamationMarkTriangleIcon = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
|
1491
1584
|
viewBox: "0 0 13.3967723 12",
|
|
1492
1585
|
version: "1.1",
|
|
1493
1586
|
xmlns: "http://www.w3.org/2000/svg",
|
|
1494
|
-
children: /* @__PURE__ */ (0,
|
|
1587
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("g", { id: "exclamation-triangle", fill: "#CD2121", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1495
1588
|
"path",
|
|
1496
1589
|
{
|
|
1497
1590
|
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",
|
|
@@ -1500,7 +1593,7 @@ var ExclamationMarkTriangleIcon = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
|
1500
1593
|
) }) })
|
|
1501
1594
|
}
|
|
1502
1595
|
);
|
|
1503
|
-
var ExclamationMarkIcon = /* @__PURE__ */ (0,
|
|
1596
|
+
var ExclamationMarkIcon = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1504
1597
|
"svg",
|
|
1505
1598
|
{
|
|
1506
1599
|
width: "14px",
|
|
@@ -1508,7 +1601,7 @@ var ExclamationMarkIcon = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
|
1508
1601
|
viewBox: "0 0 14 14",
|
|
1509
1602
|
version: "1.1",
|
|
1510
1603
|
xmlns: "http://www.w3.org/2000/svg",
|
|
1511
|
-
children: /* @__PURE__ */ (0,
|
|
1604
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("g", { id: "exclamation-circle", fill: "#EC662C", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1512
1605
|
"path",
|
|
1513
1606
|
{
|
|
1514
1607
|
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",
|
|
@@ -1517,14 +1610,14 @@ var ExclamationMarkIcon = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
|
1517
1610
|
) }) })
|
|
1518
1611
|
}
|
|
1519
1612
|
);
|
|
1520
|
-
var ChevronDownIcon = /* @__PURE__ */ (0,
|
|
1613
|
+
var ChevronDownIcon = /* @__PURE__ */ (0, import_jsx_runtime14.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_runtime14.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("g", { id: "Group", fill: "#000000", fillRule: "nonzero", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1521
1614
|
"path",
|
|
1522
1615
|
{
|
|
1523
1616
|
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",
|
|
1524
1617
|
id: "Path"
|
|
1525
1618
|
}
|
|
1526
1619
|
) }) }) });
|
|
1527
|
-
var CheckIcon2 = /* @__PURE__ */ (0,
|
|
1620
|
+
var CheckIcon2 = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1528
1621
|
"svg",
|
|
1529
1622
|
{
|
|
1530
1623
|
width: "14px",
|
|
@@ -1532,7 +1625,7 @@ var CheckIcon2 = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
|
1532
1625
|
viewBox: "0 0 14 14",
|
|
1533
1626
|
version: "1.1",
|
|
1534
1627
|
xmlns: "http://www.w3.org/2000/svg",
|
|
1535
|
-
children: /* @__PURE__ */ (0,
|
|
1628
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("g", { id: "Group-2", transform: "translate(-118, 0)", fill: "#1BC030", fillRule: "nonzero", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("g", { id: "Group", transform: "translate(118, 0)", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1536
1629
|
"path",
|
|
1537
1630
|
{
|
|
1538
1631
|
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",
|
|
@@ -1541,7 +1634,7 @@ var CheckIcon2 = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
|
1541
1634
|
) }) }) })
|
|
1542
1635
|
}
|
|
1543
1636
|
);
|
|
1544
|
-
var CopilotKitIcon = /* @__PURE__ */ (0,
|
|
1637
|
+
var CopilotKitIcon = /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
1545
1638
|
"svg",
|
|
1546
1639
|
{
|
|
1547
1640
|
width: "33px",
|
|
@@ -1550,8 +1643,8 @@ var CopilotKitIcon = /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
|
1550
1643
|
version: "1.1",
|
|
1551
1644
|
xmlns: "http://www.w3.org/2000/svg",
|
|
1552
1645
|
children: [
|
|
1553
|
-
/* @__PURE__ */ (0,
|
|
1554
|
-
/* @__PURE__ */ (0,
|
|
1646
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("title", { children: "bd5c9079-929b-4d55-bdc9-16d1c8181b71" }),
|
|
1647
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1555
1648
|
"image",
|
|
1556
1649
|
{
|
|
1557
1650
|
x: "0",
|
|
@@ -1568,10 +1661,10 @@ var CopilotKitIcon = /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
|
1568
1661
|
// src/components/dev-console/console.tsx
|
|
1569
1662
|
var import_react9 = require("@headlessui/react");
|
|
1570
1663
|
var import_shared2 = require("@copilotkit/shared");
|
|
1571
|
-
var
|
|
1664
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1572
1665
|
function CopilotDevConsole() {
|
|
1573
1666
|
const currentVersion = import_shared2.COPILOTKIT_VERSION;
|
|
1574
|
-
const context = (0,
|
|
1667
|
+
const context = (0, import_react_core7.useCopilotContext)();
|
|
1575
1668
|
const [showDevConsole, setShowDevConsole] = (0, import_react8.useState)(false);
|
|
1576
1669
|
(0, import_react8.useEffect)(() => {
|
|
1577
1670
|
setShowDevConsole(shouldShowDevConsole(context.showDevConsole));
|
|
@@ -1642,14 +1735,14 @@ function CopilotDevConsole() {
|
|
|
1642
1735
|
if (!showDevConsole) {
|
|
1643
1736
|
return null;
|
|
1644
1737
|
}
|
|
1645
|
-
return /* @__PURE__ */ (0,
|
|
1738
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
|
|
1646
1739
|
"div",
|
|
1647
1740
|
{
|
|
1648
1741
|
ref: consoleRef,
|
|
1649
1742
|
className: "copilotKitDevConsole " + (versionStatus === "update-available" ? "copilotKitDevConsoleUpgrade" : "") + (versionStatus === "outdated" ? "copilotKitDevConsoleWarnOutdated" : ""),
|
|
1650
1743
|
children: [
|
|
1651
|
-
/* @__PURE__ */ (0,
|
|
1652
|
-
/* @__PURE__ */ (0,
|
|
1744
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "copilotKitDevConsoleLogo", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("a", { href: "https://copilotkit.ai", target: "_blank", children: CopilotKitIcon }) }),
|
|
1745
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1653
1746
|
VersionInfo,
|
|
1654
1747
|
{
|
|
1655
1748
|
showDevConsole: context.showDevConsole,
|
|
@@ -1658,7 +1751,7 @@ function CopilotDevConsole() {
|
|
|
1658
1751
|
latestVersion
|
|
1659
1752
|
}
|
|
1660
1753
|
),
|
|
1661
|
-
/* @__PURE__ */ (0,
|
|
1754
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1662
1755
|
DebugMenuButton,
|
|
1663
1756
|
{
|
|
1664
1757
|
setShowDevConsole,
|
|
@@ -1713,12 +1806,12 @@ function VersionInfo({
|
|
|
1713
1806
|
setTimeout(() => setCopyStatus(""), 1e3);
|
|
1714
1807
|
});
|
|
1715
1808
|
};
|
|
1716
|
-
return /* @__PURE__ */ (0,
|
|
1717
|
-
/* @__PURE__ */ (0,
|
|
1809
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "copilotKitVersionInfo", children: [
|
|
1810
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("header", { children: [
|
|
1718
1811
|
"COPILOTKIT DEV CONSOLE",
|
|
1719
|
-
showDevConsole === "auto" && /* @__PURE__ */ (0,
|
|
1812
|
+
showDevConsole === "auto" && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("aside", { children: asideLabel })
|
|
1720
1813
|
] }),
|
|
1721
|
-
/* @__PURE__ */ (0,
|
|
1814
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("section", { children: [
|
|
1722
1815
|
"Version: ",
|
|
1723
1816
|
versionLabel,
|
|
1724
1817
|
" (",
|
|
@@ -1726,7 +1819,7 @@ function VersionInfo({
|
|
|
1726
1819
|
") ",
|
|
1727
1820
|
versionIcon
|
|
1728
1821
|
] }),
|
|
1729
|
-
(versionStatus === "update-available" || versionStatus === "outdated") && /* @__PURE__ */ (0,
|
|
1822
|
+
(versionStatus === "update-available" || versionStatus === "outdated") && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("footer", { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { onClick: handleCopyClick, children: copyStatus || installCommand }) })
|
|
1730
1823
|
] });
|
|
1731
1824
|
}
|
|
1732
1825
|
function DebugMenuButton({
|
|
@@ -1734,13 +1827,13 @@ function DebugMenuButton({
|
|
|
1734
1827
|
checkForUpdates,
|
|
1735
1828
|
mode
|
|
1736
1829
|
}) {
|
|
1737
|
-
const context = (0,
|
|
1738
|
-
return /* @__PURE__ */ (0,
|
|
1739
|
-
/* @__PURE__ */ (0,
|
|
1830
|
+
const context = (0, import_react_core7.useCopilotContext)();
|
|
1831
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "bg-black fixed top-24 w-52 text-right", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_react9.Menu, { children: [
|
|
1832
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react9.MenuButton, { className: `copilotKitDebugMenuButton ${mode === "compact" ? "compact" : ""}`, children: mode == "compact" ? "Debug" : /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
|
|
1740
1833
|
"Debug ",
|
|
1741
1834
|
ChevronDownIcon
|
|
1742
1835
|
] }) }),
|
|
1743
|
-
/* @__PURE__ */ (0,
|
|
1836
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
|
|
1744
1837
|
import_react9.MenuItems,
|
|
1745
1838
|
{
|
|
1746
1839
|
transition: true,
|
|
@@ -1748,12 +1841,12 @@ function DebugMenuButton({
|
|
|
1748
1841
|
className: "copilotKitDebugMenu",
|
|
1749
1842
|
style: { zIndex: 40 },
|
|
1750
1843
|
children: [
|
|
1751
|
-
/* @__PURE__ */ (0,
|
|
1752
|
-
/* @__PURE__ */ (0,
|
|
1753
|
-
/* @__PURE__ */ (0,
|
|
1754
|
-
/* @__PURE__ */ (0,
|
|
1755
|
-
/* @__PURE__ */ (0,
|
|
1756
|
-
/* @__PURE__ */ (0,
|
|
1844
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react9.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => logReadables(context), children: "Log Readables" }) }),
|
|
1845
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react9.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => logActions(context), children: "Log Actions" }) }),
|
|
1846
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react9.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => logMessages(context), children: "Log Messages" }) }),
|
|
1847
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react9.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => checkForUpdates(true), children: "Check for Updates" }) }),
|
|
1848
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("hr", {}),
|
|
1849
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react9.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => setShowDevConsole(false), children: "Hide Dev Console" }) })
|
|
1757
1850
|
]
|
|
1758
1851
|
}
|
|
1759
1852
|
)
|
|
@@ -1761,7 +1854,7 @@ function DebugMenuButton({
|
|
|
1761
1854
|
}
|
|
1762
1855
|
|
|
1763
1856
|
// src/components/chat/Chat.tsx
|
|
1764
|
-
var
|
|
1857
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
1765
1858
|
function CopilotChat({
|
|
1766
1859
|
instructions,
|
|
1767
1860
|
onSubmitMessage,
|
|
@@ -1769,13 +1862,17 @@ function CopilotChat({
|
|
|
1769
1862
|
showResponseButton = true,
|
|
1770
1863
|
onInProgress,
|
|
1771
1864
|
Messages: Messages2 = Messages,
|
|
1865
|
+
RenderTextMessage: RenderTextMessage2 = RenderTextMessage,
|
|
1866
|
+
RenderActionExecutionMessage: RenderActionExecutionMessage2 = RenderActionExecutionMessage,
|
|
1867
|
+
RenderAgentStateMessage: RenderAgentStateMessage2 = RenderAgentStateMessage,
|
|
1868
|
+
RenderResultMessage: RenderResultMessage2 = RenderResultMessage,
|
|
1772
1869
|
Input: Input2 = Input,
|
|
1773
1870
|
ResponseButton: ResponseButton2 = ResponseButton,
|
|
1774
1871
|
className,
|
|
1775
1872
|
icons,
|
|
1776
1873
|
labels
|
|
1777
1874
|
}) {
|
|
1778
|
-
const context = (0,
|
|
1875
|
+
const context = (0, import_react_core8.useCopilotContext)();
|
|
1779
1876
|
(0, import_react10.useEffect)(() => {
|
|
1780
1877
|
context.setChatInstructions(instructions || "");
|
|
1781
1878
|
}, [instructions]);
|
|
@@ -1789,32 +1886,43 @@ function CopilotChat({
|
|
|
1789
1886
|
} = useCopilotChatLogic(makeSystemMessage, onInProgress, onSubmitMessage);
|
|
1790
1887
|
const chatContext = import_react10.default.useContext(ChatContext);
|
|
1791
1888
|
const isVisible = chatContext ? chatContext.open : true;
|
|
1792
|
-
return /* @__PURE__ */ (0,
|
|
1793
|
-
/* @__PURE__ */ (0,
|
|
1794
|
-
/* @__PURE__ */ (0,
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1889
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
|
|
1890
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(CopilotDevConsole, {}),
|
|
1891
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
|
|
1892
|
+
Messages2,
|
|
1893
|
+
{
|
|
1894
|
+
RenderTextMessage: RenderTextMessage2,
|
|
1895
|
+
RenderActionExecutionMessage: RenderActionExecutionMessage2,
|
|
1896
|
+
RenderAgentStateMessage: RenderAgentStateMessage2,
|
|
1897
|
+
RenderResultMessage: RenderResultMessage2,
|
|
1898
|
+
messages: visibleMessages,
|
|
1899
|
+
inProgress: isLoading,
|
|
1900
|
+
children: [
|
|
1901
|
+
currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { children: [
|
|
1902
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("h6", { children: "Suggested:" }),
|
|
1903
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "suggestions", children: currentSuggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1904
|
+
Suggestion,
|
|
1905
|
+
{
|
|
1906
|
+
title: suggestion.title,
|
|
1907
|
+
message: suggestion.message,
|
|
1908
|
+
partial: suggestion.partial,
|
|
1909
|
+
className: suggestion.className,
|
|
1910
|
+
onClick: (message) => sendMessage(message)
|
|
1911
|
+
},
|
|
1912
|
+
index
|
|
1913
|
+
)) })
|
|
1914
|
+
] }),
|
|
1915
|
+
showResponseButton && visibleMessages.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1916
|
+
ResponseButton2,
|
|
1917
|
+
{
|
|
1918
|
+
onClick: isLoading ? stopGeneration : reloadMessages,
|
|
1919
|
+
inProgress: isLoading
|
|
1920
|
+
}
|
|
1921
|
+
)
|
|
1922
|
+
]
|
|
1923
|
+
}
|
|
1924
|
+
),
|
|
1925
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Input2, { inProgress: isLoading, onSend: sendMessage, isVisible })
|
|
1818
1926
|
] });
|
|
1819
1927
|
}
|
|
1820
1928
|
function WrappedCopilotChat({
|
|
@@ -1825,14 +1933,14 @@ function WrappedCopilotChat({
|
|
|
1825
1933
|
}) {
|
|
1826
1934
|
const chatContext = import_react10.default.useContext(ChatContext);
|
|
1827
1935
|
if (!chatContext) {
|
|
1828
|
-
return /* @__PURE__ */ (0,
|
|
1829
|
-
}, children: /* @__PURE__ */ (0,
|
|
1936
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ChatContextProvider, { icons, labels, open: true, setOpen: () => {
|
|
1937
|
+
}, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: `copilotKitChat ${className}`, children }) });
|
|
1830
1938
|
}
|
|
1831
|
-
return /* @__PURE__ */ (0,
|
|
1939
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_jsx_runtime16.Fragment, { children });
|
|
1832
1940
|
}
|
|
1833
1941
|
var SUGGESTIONS_DEBOUNCE_TIMEOUT = 1e3;
|
|
1834
1942
|
var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) => {
|
|
1835
|
-
const { visibleMessages, appendMessage, reloadMessages, stopGeneration, isLoading } = (0,
|
|
1943
|
+
const { visibleMessages, appendMessage, reloadMessages, stopGeneration, isLoading } = (0, import_react_core8.useCopilotChat)({
|
|
1836
1944
|
id: (0, import_shared3.randomId)(),
|
|
1837
1945
|
makeSystemMessage
|
|
1838
1946
|
});
|
|
@@ -1844,7 +1952,7 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
|
|
|
1844
1952
|
(_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
|
|
1845
1953
|
suggestionsAbortControllerRef.current = null;
|
|
1846
1954
|
};
|
|
1847
|
-
const context = (0,
|
|
1955
|
+
const context = (0, import_react_core8.useCopilotContext)();
|
|
1848
1956
|
(0, import_react10.useEffect)(() => {
|
|
1849
1957
|
onInProgress == null ? void 0 : onInProgress(isLoading);
|
|
1850
1958
|
abortSuggestions();
|
|
@@ -1869,9 +1977,9 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
|
|
|
1869
1977
|
const sendMessage = (messageContent) => __async(void 0, null, function* () {
|
|
1870
1978
|
abortSuggestions();
|
|
1871
1979
|
setCurrentSuggestions([]);
|
|
1872
|
-
const message = new
|
|
1980
|
+
const message = new import_runtime_client_gql10.TextMessage({
|
|
1873
1981
|
content: messageContent,
|
|
1874
|
-
role:
|
|
1982
|
+
role: import_runtime_client_gql10.Role.User
|
|
1875
1983
|
});
|
|
1876
1984
|
appendMessage(message);
|
|
1877
1985
|
if (onSubmitMessage) {
|