@copilotkit/react-core 1.9.2-next.8 → 1.9.2
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 +193 -0
- package/dist/{chunk-ERXWDCY6.mjs → chunk-36MGCCPZ.mjs} +2 -2
- package/dist/{chunk-CCESTGAM.mjs → chunk-3OQM3NEK.mjs} +2 -2
- package/dist/{chunk-7G6RR4HE.mjs → chunk-3Q4F7RF2.mjs} +2 -2
- package/dist/chunk-57K2ZJ5F.mjs +348 -0
- package/dist/chunk-57K2ZJ5F.mjs.map +1 -0
- package/dist/{chunk-UBNRUXEK.mjs → chunk-5BSUSFHM.mjs} +2 -2
- package/dist/{chunk-RN3ZRHI7.mjs → chunk-AD7DWJNW.mjs} +66 -25
- package/dist/chunk-AD7DWJNW.mjs.map +1 -0
- package/dist/{chunk-JPMIAGI6.mjs → chunk-BVK7PLK6.mjs} +2 -2
- package/dist/{chunk-VJCHRQ7Q.mjs → chunk-DGON3GZX.mjs} +39 -6
- package/dist/chunk-DGON3GZX.mjs.map +1 -0
- package/dist/{chunk-XFOTNHYA.mjs → chunk-DKZTPL66.mjs} +2 -2
- package/dist/{chunk-XFOTNHYA.mjs.map → chunk-DKZTPL66.mjs.map} +1 -1
- package/dist/{chunk-S4BOATBG.mjs → chunk-FN3UA2ZE.mjs} +3 -3
- package/dist/{chunk-ISYBUDL4.mjs → chunk-JWAXDYOW.mjs} +11 -12
- package/dist/chunk-JWAXDYOW.mjs.map +1 -0
- package/dist/{chunk-T4ZKC4X4.mjs → chunk-KIXKBJUV.mjs} +3 -3
- package/dist/{chunk-I4JPQECN.mjs → chunk-LFAZTKBK.mjs} +5 -5
- package/dist/{chunk-JHIZ5HAI.mjs → chunk-NJA5ZLAZ.mjs} +29 -10
- package/dist/chunk-NJA5ZLAZ.mjs.map +1 -0
- package/dist/{chunk-ZHEEHGLS.mjs → chunk-QGT4JO7R.mjs} +35 -6
- package/dist/chunk-QGT4JO7R.mjs.map +1 -0
- package/dist/{chunk-JXF732XG.mjs → chunk-S5QUEHJC.mjs} +195 -77
- package/dist/chunk-S5QUEHJC.mjs.map +1 -0
- package/dist/{chunk-QQZLIEXK.mjs → chunk-SJJNFYGQ.mjs} +3 -3
- package/dist/{chunk-CMQV4XNY.mjs → chunk-VDADWRS3.mjs} +2 -2
- package/dist/chunk-YAF2LATQ.mjs +310 -0
- package/dist/chunk-YAF2LATQ.mjs.map +1 -0
- package/dist/{chunk-VF6UPRKM.mjs → chunk-ZGMZ5WJI.mjs} +4 -4
- package/dist/components/copilot-provider/copilot-messages.js +37 -4
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
- package/dist/components/copilot-provider/copilotkit-props.d.ts +14 -9
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
- package/dist/components/copilot-provider/copilotkit.js +354 -258
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +10 -10
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +354 -258
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +10 -10
- package/dist/components/error-boundary/error-boundary.js +135 -146
- package/dist/components/error-boundary/error-boundary.js.map +1 -1
- package/dist/components/error-boundary/error-boundary.mjs +4 -4
- package/dist/components/error-boundary/error-utils.js.map +1 -1
- package/dist/components/error-boundary/error-utils.mjs +2 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +354 -258
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +10 -10
- package/dist/components/toast/toast-provider.js +118 -85
- package/dist/components/toast/toast-provider.js.map +1 -1
- package/dist/components/toast/toast-provider.mjs +1 -1
- package/dist/components/usage-banner.js +135 -146
- package/dist/components/usage-banner.js.map +1 -1
- package/dist/components/usage-banner.mjs +1 -1
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js +1 -1
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{copilot-context-3da805ab.d.ts → copilot-context-3ab4fdf5.d.ts} +3 -3
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +249 -88
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +32 -32
- package/dist/hooks/use-chat.d.ts +1 -1
- package/dist/hooks/use-chat.js +287 -174
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +5 -5
- package/dist/hooks/use-coagent-state-render.js +1 -1
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +3 -3
- package/dist/hooks/use-coagent.d.ts +1 -1
- package/dist/hooks/use-coagent.js +224 -82
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +14 -14
- package/dist/hooks/use-copilot-action.js +26 -7
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +4 -4
- package/dist/hooks/use-copilot-additional-instructions.js +1 -1
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js +26 -7
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +5 -5
- package/dist/hooks/use-copilot-chat.d.ts +1 -1
- package/dist/hooks/use-copilot-chat.js +195 -82
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +13 -13
- package/dist/hooks/use-copilot-readable.js +1 -1
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-copilot-runtime-client.d.ts +2 -2
- package/dist/hooks/use-copilot-runtime-client.js +8 -8
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt-render.js +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
- package/dist/hooks/use-langgraph-interrupt.js +195 -82
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +14 -14
- package/dist/hooks/use-make-copilot-document-readable.js +1 -1
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +593 -336
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -33
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +11 -11
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +11 -11
- package/dist/setupTests.d.ts +2 -0
- package/dist/setupTests.js +26 -0
- package/dist/setupTests.js.map +1 -0
- package/dist/setupTests.mjs +24 -0
- package/dist/setupTests.mjs.map +1 -0
- package/dist/types/interrupt-action.d.ts +1 -1
- package/dist/utils/extract.d.ts +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +10 -10
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +10 -10
- package/jest.config.js +4 -0
- package/package.json +6 -3
- package/src/components/copilot-provider/__tests__/{copilotkit-trace.test.tsx → copilotkit-error.test.tsx} +17 -17
- package/src/components/copilot-provider/copilot-messages.tsx +43 -4
- package/src/components/copilot-provider/copilotkit-props.tsx +13 -8
- package/src/components/copilot-provider/copilotkit.tsx +61 -19
- package/src/components/toast/toast-provider.tsx +49 -24
- package/src/components/usage-banner.tsx +144 -147
- package/src/context/copilot-context.tsx +4 -4
- package/src/hooks/__tests__/use-coagent-config.test.ts +284 -0
- package/src/hooks/use-chat.ts +249 -61
- package/src/hooks/use-coagent.ts +41 -0
- package/src/hooks/use-copilot-action.ts +51 -9
- package/src/hooks/use-copilot-runtime-client.ts +12 -50
- package/src/setupTests.ts +26 -0
- package/tsconfig.json +5 -2
- package/dist/chunk-HD2GE3DK.mjs +0 -359
- package/dist/chunk-HD2GE3DK.mjs.map +0 -1
- package/dist/chunk-ISYBUDL4.mjs.map +0 -1
- package/dist/chunk-JHIZ5HAI.mjs.map +0 -1
- package/dist/chunk-JXF732XG.mjs.map +0 -1
- package/dist/chunk-RN3ZRHI7.mjs.map +0 -1
- package/dist/chunk-VJCHRQ7Q.mjs.map +0 -1
- package/dist/chunk-VRXANACV.mjs +0 -277
- package/dist/chunk-VRXANACV.mjs.map +0 -1
- package/dist/chunk-ZHEEHGLS.mjs.map +0 -1
- /package/dist/{chunk-ERXWDCY6.mjs.map → chunk-36MGCCPZ.mjs.map} +0 -0
- /package/dist/{chunk-CCESTGAM.mjs.map → chunk-3OQM3NEK.mjs.map} +0 -0
- /package/dist/{chunk-7G6RR4HE.mjs.map → chunk-3Q4F7RF2.mjs.map} +0 -0
- /package/dist/{chunk-UBNRUXEK.mjs.map → chunk-5BSUSFHM.mjs.map} +0 -0
- /package/dist/{chunk-JPMIAGI6.mjs.map → chunk-BVK7PLK6.mjs.map} +0 -0
- /package/dist/{chunk-S4BOATBG.mjs.map → chunk-FN3UA2ZE.mjs.map} +0 -0
- /package/dist/{chunk-T4ZKC4X4.mjs.map → chunk-KIXKBJUV.mjs.map} +0 -0
- /package/dist/{chunk-I4JPQECN.mjs.map → chunk-LFAZTKBK.mjs.map} +0 -0
- /package/dist/{chunk-QQZLIEXK.mjs.map → chunk-SJJNFYGQ.mjs.map} +0 -0
- /package/dist/{chunk-CMQV4XNY.mjs.map → chunk-VDADWRS3.mjs.map} +0 -0
- /package/dist/{chunk-VF6UPRKM.mjs.map → chunk-ZGMZ5WJI.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -184,7 +184,7 @@ var emptyCopilotContext = {
|
|
|
184
184
|
langGraphInterruptAction: null,
|
|
185
185
|
setLangGraphInterruptAction: () => null,
|
|
186
186
|
removeLangGraphInterruptAction: () => null,
|
|
187
|
-
|
|
187
|
+
onError: void 0
|
|
188
188
|
};
|
|
189
189
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
190
190
|
function useCopilotContext() {
|
|
@@ -548,12 +548,14 @@ function ToastProvider({
|
|
|
548
548
|
border: `1px solid ${colors.border}`,
|
|
549
549
|
borderLeft: `4px solid ${colors.border}`,
|
|
550
550
|
borderRadius: "8px",
|
|
551
|
-
padding: "
|
|
551
|
+
padding: "12px 16px",
|
|
552
552
|
fontSize: "13px",
|
|
553
553
|
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
|
|
554
554
|
backdropFilter: "blur(8px)",
|
|
555
|
-
maxWidth: "
|
|
556
|
-
|
|
555
|
+
maxWidth: "min(90vw, 700px)",
|
|
556
|
+
width: "100%",
|
|
557
|
+
boxSizing: "border-box",
|
|
558
|
+
overflow: "hidden"
|
|
557
559
|
},
|
|
558
560
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
559
561
|
"div",
|
|
@@ -565,94 +567,125 @@ function ToastProvider({
|
|
|
565
567
|
gap: "10px"
|
|
566
568
|
},
|
|
567
569
|
children: [
|
|
568
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
{
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
fontWeight: "400",
|
|
589
|
-
fontSize: "13px",
|
|
590
|
-
flex: 1,
|
|
591
|
-
wordWrap: "break-word",
|
|
592
|
-
overflowWrap: "break-word",
|
|
593
|
-
hyphens: "auto"
|
|
594
|
-
},
|
|
595
|
-
children: (() => {
|
|
596
|
-
const message = bannerError.message;
|
|
597
|
-
const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
598
|
-
const plainUrlRegex = /(https?:\/\/[^\s)]+)/g;
|
|
599
|
-
let cleanMessage = message.replace(markdownLinkRegex, "").replace(plainUrlRegex, "").replace(/See more:\s*/g, "").replace(/\s+/g, " ").trim();
|
|
600
|
-
if (cleanMessage.length > 120) {
|
|
601
|
-
cleanMessage = cleanMessage.substring(0, 117) + "...";
|
|
570
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
571
|
+
"div",
|
|
572
|
+
{
|
|
573
|
+
style: {
|
|
574
|
+
display: "flex",
|
|
575
|
+
alignItems: "center",
|
|
576
|
+
gap: "8px",
|
|
577
|
+
flex: 1,
|
|
578
|
+
minWidth: 0
|
|
579
|
+
},
|
|
580
|
+
children: [
|
|
581
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
582
|
+
"div",
|
|
583
|
+
{
|
|
584
|
+
style: {
|
|
585
|
+
width: "12px",
|
|
586
|
+
height: "12px",
|
|
587
|
+
borderRadius: "50%",
|
|
588
|
+
backgroundColor: colors.border,
|
|
589
|
+
flexShrink: 0
|
|
602
590
|
}
|
|
603
|
-
return cleanMessage;
|
|
604
|
-
})()
|
|
605
|
-
}
|
|
606
|
-
),
|
|
607
|
-
(() => {
|
|
608
|
-
const message = bannerError.message;
|
|
609
|
-
const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
610
|
-
const plainUrlRegex = /(https?:\/\/[^\s)]+)/g;
|
|
611
|
-
let url = null;
|
|
612
|
-
let buttonText = "See More";
|
|
613
|
-
const markdownMatch = markdownLinkRegex.exec(message);
|
|
614
|
-
if (markdownMatch) {
|
|
615
|
-
url = markdownMatch[2];
|
|
616
|
-
buttonText = "See More";
|
|
617
|
-
} else {
|
|
618
|
-
const urlMatch = plainUrlRegex.exec(message);
|
|
619
|
-
if (urlMatch) {
|
|
620
|
-
url = urlMatch[0];
|
|
621
|
-
buttonText = "See More";
|
|
622
591
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
627
|
-
"button",
|
|
592
|
+
),
|
|
593
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
594
|
+
"div",
|
|
628
595
|
{
|
|
629
|
-
onClick: () => window.open(url, "_blank", "noopener,noreferrer"),
|
|
630
596
|
style: {
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
fontSize: "11px",
|
|
637
|
-
fontWeight: "500",
|
|
638
|
-
cursor: "pointer",
|
|
639
|
-
transition: "all 0.2s ease",
|
|
640
|
-
flexShrink: 0
|
|
597
|
+
display: "flex",
|
|
598
|
+
alignItems: "center",
|
|
599
|
+
gap: "10px",
|
|
600
|
+
flex: 1,
|
|
601
|
+
minWidth: 0
|
|
641
602
|
},
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
603
|
+
children: [
|
|
604
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
605
|
+
"div",
|
|
606
|
+
{
|
|
607
|
+
style: {
|
|
608
|
+
color: colors.text,
|
|
609
|
+
lineHeight: "1.4",
|
|
610
|
+
fontWeight: "400",
|
|
611
|
+
fontSize: "13px",
|
|
612
|
+
flex: 1,
|
|
613
|
+
wordBreak: "break-all",
|
|
614
|
+
overflowWrap: "break-word",
|
|
615
|
+
maxWidth: "550px",
|
|
616
|
+
overflow: "hidden",
|
|
617
|
+
display: "-webkit-box",
|
|
618
|
+
WebkitLineClamp: 10,
|
|
619
|
+
WebkitBoxOrient: "vertical"
|
|
620
|
+
},
|
|
621
|
+
children: (() => {
|
|
622
|
+
let message = bannerError.message;
|
|
623
|
+
const jsonMatch = message.match(/'message':\s*'([^']+)'/);
|
|
624
|
+
if (jsonMatch) {
|
|
625
|
+
return jsonMatch[1];
|
|
626
|
+
}
|
|
627
|
+
message = message.split(" - ")[0];
|
|
628
|
+
message = message.split(": Error code")[0];
|
|
629
|
+
message = message.replace(/:\s*\d{3}$/, "");
|
|
630
|
+
message = message.replace(/See more:.*$/g, "");
|
|
631
|
+
message = message.trim();
|
|
632
|
+
return message || "Configuration error occurred.";
|
|
633
|
+
})()
|
|
634
|
+
}
|
|
635
|
+
),
|
|
636
|
+
(() => {
|
|
637
|
+
const message = bannerError.message;
|
|
638
|
+
const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
639
|
+
const plainUrlRegex = /(https?:\/\/[^\s)]+)/g;
|
|
640
|
+
let url = null;
|
|
641
|
+
let buttonText = "See More";
|
|
642
|
+
const markdownMatch = markdownLinkRegex.exec(message);
|
|
643
|
+
if (markdownMatch) {
|
|
644
|
+
url = markdownMatch[2];
|
|
645
|
+
buttonText = "See More";
|
|
646
|
+
} else {
|
|
647
|
+
const urlMatch = plainUrlRegex.exec(message);
|
|
648
|
+
if (urlMatch) {
|
|
649
|
+
url = urlMatch[0].replace(/[.,;:'"]*$/, "");
|
|
650
|
+
buttonText = "See More";
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
if (!url)
|
|
654
|
+
return null;
|
|
655
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
656
|
+
"button",
|
|
657
|
+
{
|
|
658
|
+
onClick: () => window.open(url, "_blank", "noopener,noreferrer"),
|
|
659
|
+
style: {
|
|
660
|
+
background: colors.border,
|
|
661
|
+
color: "white",
|
|
662
|
+
border: "none",
|
|
663
|
+
borderRadius: "5px",
|
|
664
|
+
padding: "4px 10px",
|
|
665
|
+
fontSize: "11px",
|
|
666
|
+
fontWeight: "500",
|
|
667
|
+
cursor: "pointer",
|
|
668
|
+
transition: "all 0.2s ease",
|
|
669
|
+
flexShrink: 0
|
|
670
|
+
},
|
|
671
|
+
onMouseEnter: (e) => {
|
|
672
|
+
e.currentTarget.style.opacity = "0.9";
|
|
673
|
+
e.currentTarget.style.transform = "translateY(-1px)";
|
|
674
|
+
},
|
|
675
|
+
onMouseLeave: (e) => {
|
|
676
|
+
e.currentTarget.style.opacity = "1";
|
|
677
|
+
e.currentTarget.style.transform = "translateY(0)";
|
|
678
|
+
},
|
|
679
|
+
children: buttonText
|
|
680
|
+
}
|
|
681
|
+
);
|
|
682
|
+
})()
|
|
683
|
+
]
|
|
651
684
|
}
|
|
652
|
-
)
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
685
|
+
)
|
|
686
|
+
]
|
|
687
|
+
}
|
|
688
|
+
),
|
|
656
689
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
657
690
|
"button",
|
|
658
691
|
{
|
|
@@ -705,8 +738,38 @@ function CopilotMessages({ children }) {
|
|
|
705
738
|
const lastLoadedThreadId = (0, import_react6.useRef)();
|
|
706
739
|
const lastLoadedAgentName = (0, import_react6.useRef)();
|
|
707
740
|
const lastLoadedMessages = (0, import_react6.useRef)();
|
|
708
|
-
const { threadId, agentSession, runtimeClient, showDevConsole } = useCopilotContext();
|
|
741
|
+
const { threadId, agentSession, runtimeClient, showDevConsole, onError, copilotApiConfig } = useCopilotContext();
|
|
709
742
|
const { setBannerError } = useToast();
|
|
743
|
+
const traceUIError = (0, import_react6.useCallback)(
|
|
744
|
+
(error, originalError) => __async(this, null, function* () {
|
|
745
|
+
if (!onError || !copilotApiConfig.publicApiKey)
|
|
746
|
+
return;
|
|
747
|
+
try {
|
|
748
|
+
const traceEvent = {
|
|
749
|
+
type: "error",
|
|
750
|
+
timestamp: Date.now(),
|
|
751
|
+
context: {
|
|
752
|
+
source: "ui",
|
|
753
|
+
request: {
|
|
754
|
+
operation: "loadAgentState",
|
|
755
|
+
url: copilotApiConfig.chatApiEndpoint,
|
|
756
|
+
startTime: Date.now()
|
|
757
|
+
},
|
|
758
|
+
technical: {
|
|
759
|
+
environment: "browser",
|
|
760
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
761
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
762
|
+
}
|
|
763
|
+
},
|
|
764
|
+
error
|
|
765
|
+
};
|
|
766
|
+
yield onError(traceEvent);
|
|
767
|
+
} catch (traceError) {
|
|
768
|
+
console.error("Error in CopilotMessages onError handler:", traceError);
|
|
769
|
+
}
|
|
770
|
+
}),
|
|
771
|
+
[onError, copilotApiConfig.publicApiKey, copilotApiConfig.chatApiEndpoint]
|
|
772
|
+
);
|
|
710
773
|
const createStructuredError2 = (gqlError) => {
|
|
711
774
|
const extensions = gqlError.extensions;
|
|
712
775
|
const originalError = extensions == null ? void 0 : extensions.originalError;
|
|
@@ -751,12 +814,14 @@ function CopilotMessages({ children }) {
|
|
|
751
814
|
const ckError = createStructuredError2(gqlError);
|
|
752
815
|
if (ckError) {
|
|
753
816
|
setBannerError(ckError);
|
|
817
|
+
traceUIError(ckError, gqlError);
|
|
754
818
|
} else {
|
|
755
819
|
const fallbackError = new import_shared4.CopilotKitError({
|
|
756
820
|
message: gqlError.message,
|
|
757
821
|
code: import_shared4.CopilotKitErrorCode.UNKNOWN
|
|
758
822
|
});
|
|
759
823
|
setBannerError(fallbackError);
|
|
824
|
+
traceUIError(fallbackError, gqlError);
|
|
760
825
|
}
|
|
761
826
|
};
|
|
762
827
|
graphQLErrors.forEach(routeError);
|
|
@@ -770,10 +835,11 @@ function CopilotMessages({ children }) {
|
|
|
770
835
|
code: import_shared4.CopilotKitErrorCode.UNKNOWN
|
|
771
836
|
});
|
|
772
837
|
setBannerError(fallbackError);
|
|
838
|
+
traceUIError(fallbackError, error);
|
|
773
839
|
}
|
|
774
840
|
}
|
|
775
841
|
},
|
|
776
|
-
[setBannerError, showDevConsole]
|
|
842
|
+
[setBannerError, showDevConsole, traceUIError]
|
|
777
843
|
);
|
|
778
844
|
(0, import_react6.useEffect)(() => {
|
|
779
845
|
if (!threadId || threadId === lastLoadedThreadId.current)
|
|
@@ -807,7 +873,7 @@ function CopilotMessages({ children }) {
|
|
|
807
873
|
}
|
|
808
874
|
});
|
|
809
875
|
void fetchMessages();
|
|
810
|
-
}, [threadId, agentSession == null ? void 0 : agentSession.agentName
|
|
876
|
+
}, [threadId, agentSession == null ? void 0 : agentSession.agentName]);
|
|
811
877
|
const memoizedChildren = (0, import_react6.useMemo)(() => children, [children]);
|
|
812
878
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
813
879
|
CopilotMessagesContext.Provider,
|
|
@@ -827,13 +893,13 @@ var import_react7 = require("react");
|
|
|
827
893
|
var import_shared5 = require("@copilotkit/shared");
|
|
828
894
|
var useCopilotRuntimeClient = (options) => {
|
|
829
895
|
const { setBannerError } = useToast();
|
|
830
|
-
const _a = options, { showDevConsole,
|
|
896
|
+
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
831
897
|
const lastStructuredErrorRef = (0, import_react7.useRef)(null);
|
|
832
898
|
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
833
|
-
if (!
|
|
899
|
+
if (!onError || !runtimeOptions.publicApiKey)
|
|
834
900
|
return;
|
|
835
901
|
try {
|
|
836
|
-
const
|
|
902
|
+
const errorEvent = {
|
|
837
903
|
type: "error",
|
|
838
904
|
timestamp: Date.now(),
|
|
839
905
|
context: {
|
|
@@ -844,16 +910,16 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
844
910
|
startTime: Date.now()
|
|
845
911
|
},
|
|
846
912
|
technical: {
|
|
847
|
-
environment:
|
|
913
|
+
environment: "browser",
|
|
848
914
|
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
849
915
|
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
850
916
|
}
|
|
851
917
|
},
|
|
852
918
|
error
|
|
853
919
|
};
|
|
854
|
-
yield
|
|
855
|
-
} catch (
|
|
856
|
-
console.error("Error in
|
|
920
|
+
yield onError(errorEvent);
|
|
921
|
+
} catch (error2) {
|
|
922
|
+
console.error("Error in onError handler:", error2);
|
|
857
923
|
}
|
|
858
924
|
});
|
|
859
925
|
const runtimeClient = (0, import_react7.useMemo)(() => {
|
|
@@ -917,7 +983,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
917
983
|
setBannerError(warningError);
|
|
918
984
|
}
|
|
919
985
|
}));
|
|
920
|
-
}, [runtimeOptions, setBannerError, showDevConsole,
|
|
986
|
+
}, [runtimeOptions, setBannerError, showDevConsole, onError]);
|
|
921
987
|
return runtimeClient;
|
|
922
988
|
};
|
|
923
989
|
function createStructuredError(gqlError) {
|
|
@@ -1144,8 +1210,8 @@ var defaultIcons = {
|
|
|
1144
1210
|
"svg",
|
|
1145
1211
|
{
|
|
1146
1212
|
viewBox: "0 0 24 24",
|
|
1147
|
-
width: "
|
|
1148
|
-
height: "
|
|
1213
|
+
width: "16",
|
|
1214
|
+
height: "16",
|
|
1149
1215
|
stroke: "currentColor",
|
|
1150
1216
|
strokeWidth: "2.5",
|
|
1151
1217
|
fill: "none",
|
|
@@ -1162,8 +1228,8 @@ var defaultIcons = {
|
|
|
1162
1228
|
"svg",
|
|
1163
1229
|
{
|
|
1164
1230
|
viewBox: "0 0 24 24",
|
|
1165
|
-
width: "
|
|
1166
|
-
height: "
|
|
1231
|
+
width: "16",
|
|
1232
|
+
height: "16",
|
|
1167
1233
|
stroke: "currentColor",
|
|
1168
1234
|
strokeWidth: "2.5",
|
|
1169
1235
|
fill: "none",
|
|
@@ -1180,8 +1246,8 @@ var defaultIcons = {
|
|
|
1180
1246
|
"svg",
|
|
1181
1247
|
{
|
|
1182
1248
|
viewBox: "0 0 24 24",
|
|
1183
|
-
width: "
|
|
1184
|
-
height: "
|
|
1249
|
+
width: "16",
|
|
1250
|
+
height: "16",
|
|
1185
1251
|
stroke: "currentColor",
|
|
1186
1252
|
strokeWidth: "2.5",
|
|
1187
1253
|
fill: "none",
|
|
@@ -1206,19 +1272,33 @@ function UsageBanner({
|
|
|
1206
1272
|
return null;
|
|
1207
1273
|
}
|
|
1208
1274
|
const parseMessage = (rawMessage) => {
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
if (matches.length > 0) {
|
|
1212
|
-
let cleanMessage2 = rawMessage.replace(/\.\s*See more:\s*\[([^\]]+)\]\(([^)]+)\)/g, ".").replace(/See more:\s*\[([^\]]+)\]\(([^)]+)\)/g, "").trim();
|
|
1213
|
-
return cleanMessage2;
|
|
1275
|
+
if (rawMessage.toLowerCase().includes("authentication") || rawMessage.toLowerCase().includes("api key")) {
|
|
1276
|
+
return "Authentication failed. Please check your API key.";
|
|
1214
1277
|
}
|
|
1215
|
-
|
|
1278
|
+
if (rawMessage.toLowerCase().includes("rate limit")) {
|
|
1279
|
+
return "Rate limit exceeded. Please try again later.";
|
|
1280
|
+
}
|
|
1281
|
+
if (rawMessage.toLowerCase().includes("checkpointer")) {
|
|
1282
|
+
return "Agent configuration error. Please check your setup.";
|
|
1283
|
+
}
|
|
1284
|
+
let cleanMessage2 = rawMessage;
|
|
1285
|
+
cleanMessage2 = cleanMessage2.split(" - ")[0];
|
|
1286
|
+
cleanMessage2 = cleanMessage2.split(": Error code")[0];
|
|
1287
|
+
cleanMessage2 = cleanMessage2.split(": 401")[0];
|
|
1288
|
+
cleanMessage2 = cleanMessage2.split(": 403")[0];
|
|
1289
|
+
cleanMessage2 = cleanMessage2.split(": 404")[0];
|
|
1290
|
+
cleanMessage2 = cleanMessage2.split(": 500")[0];
|
|
1291
|
+
cleanMessage2 = cleanMessage2.replace(/See more:.*$/g, "").trim();
|
|
1292
|
+
if (cleanMessage2.includes("{") || cleanMessage2.includes("'") || cleanMessage2.length > 60) {
|
|
1293
|
+
return "Configuration error. Please check your setup.";
|
|
1294
|
+
}
|
|
1295
|
+
return cleanMessage2 || "An error occurred. Please check your configuration.";
|
|
1216
1296
|
};
|
|
1217
1297
|
const cleanMessage = parseMessage(message);
|
|
1218
1298
|
const Icon = icon || defaultIcons[severity];
|
|
1219
1299
|
const themeConfigs = {
|
|
1220
1300
|
[import_shared8.Severity.INFO]: {
|
|
1221
|
-
bg: "
|
|
1301
|
+
bg: "rgba(239, 246, 255, 0.95)",
|
|
1222
1302
|
border: "#93c5fd",
|
|
1223
1303
|
text: "#1e40af",
|
|
1224
1304
|
icon: "#3b82f6",
|
|
@@ -1226,7 +1306,7 @@ function UsageBanner({
|
|
|
1226
1306
|
primaryBtnHover: "#2563eb"
|
|
1227
1307
|
},
|
|
1228
1308
|
[import_shared8.Severity.WARNING]: {
|
|
1229
|
-
bg: "
|
|
1309
|
+
bg: "rgba(255, 251, 235, 0.95)",
|
|
1230
1310
|
border: "#fbbf24",
|
|
1231
1311
|
text: "#92400e",
|
|
1232
1312
|
icon: "#f59e0b",
|
|
@@ -1234,7 +1314,7 @@ function UsageBanner({
|
|
|
1234
1314
|
primaryBtnHover: "#d97706"
|
|
1235
1315
|
},
|
|
1236
1316
|
[import_shared8.Severity.CRITICAL]: {
|
|
1237
|
-
bg: "
|
|
1317
|
+
bg: "rgba(254, 242, 242, 0.95)",
|
|
1238
1318
|
border: "#f87171",
|
|
1239
1319
|
text: "#991b1b",
|
|
1240
1320
|
icon: "#ef4444",
|
|
@@ -1248,24 +1328,26 @@ function UsageBanner({
|
|
|
1248
1328
|
{
|
|
1249
1329
|
style: {
|
|
1250
1330
|
position: "fixed",
|
|
1251
|
-
bottom: "
|
|
1331
|
+
bottom: "24px",
|
|
1252
1332
|
left: "50%",
|
|
1253
1333
|
transform: "translateX(-50%)",
|
|
1254
|
-
|
|
1255
|
-
|
|
1334
|
+
width: "400px",
|
|
1335
|
+
maxWidth: "90vw",
|
|
1256
1336
|
zIndex: 1e4,
|
|
1257
|
-
animation: "bannerSlideIn 0.
|
|
1337
|
+
animation: "bannerSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1)"
|
|
1258
1338
|
},
|
|
1259
1339
|
children: [
|
|
1260
1340
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("style", { children: `
|
|
1261
1341
|
@keyframes bannerSlideIn {
|
|
1262
1342
|
from {
|
|
1263
1343
|
opacity: 0;
|
|
1264
|
-
transform: translateX(-50%) translateY(
|
|
1344
|
+
transform: translateX(-50%) translateY(20px);
|
|
1345
|
+
scale: 0.95;
|
|
1265
1346
|
}
|
|
1266
1347
|
to {
|
|
1267
1348
|
opacity: 1;
|
|
1268
1349
|
transform: translateX(-50%) translateY(0);
|
|
1350
|
+
scale: 1;
|
|
1269
1351
|
}
|
|
1270
1352
|
}
|
|
1271
1353
|
` }),
|
|
@@ -1273,17 +1355,16 @@ function UsageBanner({
|
|
|
1273
1355
|
"div",
|
|
1274
1356
|
{
|
|
1275
1357
|
style: {
|
|
1276
|
-
|
|
1277
|
-
alignItems: "flex-start",
|
|
1278
|
-
gap: "14px",
|
|
1279
|
-
borderRadius: "16px",
|
|
1358
|
+
borderRadius: "12px",
|
|
1280
1359
|
border: `1px solid ${themeConfig.border}`,
|
|
1281
1360
|
background: themeConfig.bg,
|
|
1282
|
-
padding: "
|
|
1283
|
-
boxShadow: "0
|
|
1361
|
+
padding: "14px",
|
|
1362
|
+
boxShadow: "0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08)",
|
|
1284
1363
|
position: "relative",
|
|
1285
|
-
backdropFilter: "blur(
|
|
1286
|
-
WebkitBackdropFilter: "blur(
|
|
1364
|
+
backdropFilter: "blur(12px)",
|
|
1365
|
+
WebkitBackdropFilter: "blur(12px)",
|
|
1366
|
+
boxSizing: "border-box",
|
|
1367
|
+
overflow: "hidden"
|
|
1287
1368
|
},
|
|
1288
1369
|
children: [
|
|
1289
1370
|
onClose && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
@@ -1292,35 +1373,23 @@ function UsageBanner({
|
|
|
1292
1373
|
onClick: onClose,
|
|
1293
1374
|
style: {
|
|
1294
1375
|
position: "absolute",
|
|
1295
|
-
top: "
|
|
1296
|
-
right: "
|
|
1297
|
-
background: "rgba(255, 255, 255, 0.
|
|
1376
|
+
top: "8px",
|
|
1377
|
+
right: "8px",
|
|
1378
|
+
background: "rgba(255, 255, 255, 0.9)",
|
|
1298
1379
|
border: "none",
|
|
1299
1380
|
color: themeConfig.text,
|
|
1300
1381
|
cursor: "pointer",
|
|
1301
|
-
fontSize: "
|
|
1382
|
+
fontSize: "16px",
|
|
1302
1383
|
lineHeight: "1",
|
|
1303
|
-
padding: "
|
|
1304
|
-
borderRadius: "
|
|
1305
|
-
|
|
1306
|
-
|
|
1384
|
+
padding: "4px",
|
|
1385
|
+
borderRadius: "4px",
|
|
1386
|
+
width: "20px",
|
|
1387
|
+
height: "20px",
|
|
1307
1388
|
display: "flex",
|
|
1308
1389
|
alignItems: "center",
|
|
1309
|
-
justifyContent: "center"
|
|
1310
|
-
width: "28px",
|
|
1311
|
-
height: "28px"
|
|
1390
|
+
justifyContent: "center"
|
|
1312
1391
|
},
|
|
1313
1392
|
title: "Close",
|
|
1314
|
-
onMouseOver: (e) => {
|
|
1315
|
-
e.currentTarget.style.opacity = "1";
|
|
1316
|
-
e.currentTarget.style.background = "rgba(255, 255, 255, 1)";
|
|
1317
|
-
e.currentTarget.style.transform = "scale(1.05)";
|
|
1318
|
-
},
|
|
1319
|
-
onMouseOut: (e) => {
|
|
1320
|
-
e.currentTarget.style.opacity = "0.7";
|
|
1321
|
-
e.currentTarget.style.background = "rgba(255, 255, 255, 0.8)";
|
|
1322
|
-
e.currentTarget.style.transform = "scale(1)";
|
|
1323
|
-
},
|
|
1324
1393
|
children: "\xD7"
|
|
1325
1394
|
}
|
|
1326
1395
|
),
|
|
@@ -1328,106 +1397,92 @@ function UsageBanner({
|
|
|
1328
1397
|
"div",
|
|
1329
1398
|
{
|
|
1330
1399
|
style: {
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1400
|
+
fontSize: "14px",
|
|
1401
|
+
fontWeight: 500,
|
|
1402
|
+
color: themeConfig.text,
|
|
1403
|
+
lineHeight: "1.4",
|
|
1404
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
|
|
1405
|
+
paddingRight: onClose ? "30px" : "0",
|
|
1406
|
+
marginBottom: actions ? "12px" : "0",
|
|
1407
|
+
wordBreak: "break-word",
|
|
1408
|
+
overflow: "hidden",
|
|
1409
|
+
textOverflow: "ellipsis",
|
|
1410
|
+
display: "-webkit-box",
|
|
1411
|
+
WebkitLineClamp: 2,
|
|
1412
|
+
WebkitBoxOrient: "vertical"
|
|
1340
1413
|
},
|
|
1341
|
-
children:
|
|
1414
|
+
children: cleanMessage
|
|
1342
1415
|
}
|
|
1343
1416
|
),
|
|
1344
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
{
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
},
|
|
1414
|
-
onMouseOver: (e) => {
|
|
1415
|
-
e.currentTarget.style.backgroundColor = themeConfig.primaryBtnHover;
|
|
1416
|
-
e.currentTarget.style.transform = "translateY(-1px)";
|
|
1417
|
-
e.currentTarget.style.boxShadow = "0 6px 16px rgba(0, 0, 0, 0.2)";
|
|
1418
|
-
},
|
|
1419
|
-
onMouseOut: (e) => {
|
|
1420
|
-
e.currentTarget.style.backgroundColor = themeConfig.primaryBtn;
|
|
1421
|
-
e.currentTarget.style.transform = "translateY(0)";
|
|
1422
|
-
e.currentTarget.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.15)";
|
|
1423
|
-
},
|
|
1424
|
-
children: actions.primary.label
|
|
1425
|
-
}
|
|
1426
|
-
)
|
|
1427
|
-
]
|
|
1428
|
-
}
|
|
1429
|
-
)
|
|
1430
|
-
] })
|
|
1417
|
+
actions && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1418
|
+
"div",
|
|
1419
|
+
{
|
|
1420
|
+
style: {
|
|
1421
|
+
display: "flex",
|
|
1422
|
+
gap: "8px",
|
|
1423
|
+
flexWrap: "wrap"
|
|
1424
|
+
},
|
|
1425
|
+
children: [
|
|
1426
|
+
actions.secondary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1427
|
+
"button",
|
|
1428
|
+
{
|
|
1429
|
+
onClick: actions.secondary.onClick,
|
|
1430
|
+
style: {
|
|
1431
|
+
borderRadius: "8px",
|
|
1432
|
+
padding: "6px 12px",
|
|
1433
|
+
fontSize: "13px",
|
|
1434
|
+
fontWeight: 500,
|
|
1435
|
+
color: themeConfig.text,
|
|
1436
|
+
backgroundColor: "rgba(255, 255, 255, 0.9)",
|
|
1437
|
+
border: `1px solid ${themeConfig.border}`,
|
|
1438
|
+
cursor: "pointer",
|
|
1439
|
+
transition: "all 0.2s ease",
|
|
1440
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
|
|
1441
|
+
},
|
|
1442
|
+
onMouseOver: (e) => {
|
|
1443
|
+
e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 1)";
|
|
1444
|
+
e.currentTarget.style.transform = "translateY(-1px)";
|
|
1445
|
+
},
|
|
1446
|
+
onMouseOut: (e) => {
|
|
1447
|
+
e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 0.9)";
|
|
1448
|
+
e.currentTarget.style.transform = "translateY(0)";
|
|
1449
|
+
},
|
|
1450
|
+
children: actions.secondary.label
|
|
1451
|
+
}
|
|
1452
|
+
),
|
|
1453
|
+
actions.primary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1454
|
+
"button",
|
|
1455
|
+
{
|
|
1456
|
+
onClick: actions.primary.onClick,
|
|
1457
|
+
style: {
|
|
1458
|
+
borderRadius: "8px",
|
|
1459
|
+
padding: "6px 12px",
|
|
1460
|
+
fontSize: "13px",
|
|
1461
|
+
fontWeight: 600,
|
|
1462
|
+
color: "#fff",
|
|
1463
|
+
backgroundColor: themeConfig.primaryBtn,
|
|
1464
|
+
border: "none",
|
|
1465
|
+
cursor: "pointer",
|
|
1466
|
+
transition: "all 0.2s ease",
|
|
1467
|
+
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)",
|
|
1468
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
|
|
1469
|
+
},
|
|
1470
|
+
onMouseOver: (e) => {
|
|
1471
|
+
e.currentTarget.style.backgroundColor = themeConfig.primaryBtnHover;
|
|
1472
|
+
e.currentTarget.style.transform = "translateY(-1px)";
|
|
1473
|
+
e.currentTarget.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.2)";
|
|
1474
|
+
},
|
|
1475
|
+
onMouseOut: (e) => {
|
|
1476
|
+
e.currentTarget.style.backgroundColor = themeConfig.primaryBtn;
|
|
1477
|
+
e.currentTarget.style.transform = "translateY(0)";
|
|
1478
|
+
e.currentTarget.style.boxShadow = "0 2px 8px rgba(0, 0, 0, 0.15)";
|
|
1479
|
+
},
|
|
1480
|
+
children: actions.primary.label
|
|
1481
|
+
}
|
|
1482
|
+
)
|
|
1483
|
+
]
|
|
1484
|
+
}
|
|
1485
|
+
)
|
|
1431
1486
|
]
|
|
1432
1487
|
}
|
|
1433
1488
|
)
|
|
@@ -1844,18 +1899,24 @@ ${nonDocumentStrings}`;
|
|
|
1844
1899
|
headers,
|
|
1845
1900
|
credentials: copilotApiConfig.credentials,
|
|
1846
1901
|
showDevConsole: (_b = props.showDevConsole) != null ? _b : false,
|
|
1847
|
-
|
|
1902
|
+
onError: props.onError
|
|
1848
1903
|
});
|
|
1849
1904
|
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react10.useState)({});
|
|
1850
|
-
const addChatSuggestionConfiguration = (
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
setChatSuggestionConfiguration
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1905
|
+
const addChatSuggestionConfiguration = (0, import_react10.useCallback)(
|
|
1906
|
+
(id, suggestion) => {
|
|
1907
|
+
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
1908
|
+
},
|
|
1909
|
+
[setChatSuggestionConfiguration]
|
|
1910
|
+
);
|
|
1911
|
+
const removeChatSuggestionConfiguration = (0, import_react10.useCallback)(
|
|
1912
|
+
(id) => {
|
|
1913
|
+
setChatSuggestionConfiguration((prev) => {
|
|
1914
|
+
const _a2 = prev, { [id]: _ } = _a2, rest = __objRest(_a2, [__restKey(id)]);
|
|
1915
|
+
return rest;
|
|
1916
|
+
});
|
|
1917
|
+
},
|
|
1918
|
+
[setChatSuggestionConfiguration]
|
|
1919
|
+
);
|
|
1859
1920
|
const [availableAgents, setAvailableAgents] = (0, import_react10.useState)([]);
|
|
1860
1921
|
const [coagentStates, setCoagentStates] = (0, import_react10.useState)({});
|
|
1861
1922
|
const coagentStatesRef = (0, import_react10.useRef)({});
|
|
@@ -1935,6 +1996,41 @@ ${nonDocumentStrings}`;
|
|
|
1935
1996
|
setLangGraphInterruptAction(null);
|
|
1936
1997
|
}, []);
|
|
1937
1998
|
const memoizedChildren = (0, import_react10.useMemo)(() => children, [children]);
|
|
1999
|
+
const agentLock = (0, import_react10.useMemo)(() => {
|
|
2000
|
+
var _a2;
|
|
2001
|
+
return (_a2 = props.agent) != null ? _a2 : null;
|
|
2002
|
+
}, [props.agent]);
|
|
2003
|
+
const forwardedParameters = (0, import_react10.useMemo)(
|
|
2004
|
+
() => {
|
|
2005
|
+
var _a2;
|
|
2006
|
+
return (_a2 = props.forwardedParameters) != null ? _a2 : {};
|
|
2007
|
+
},
|
|
2008
|
+
[props.forwardedParameters]
|
|
2009
|
+
);
|
|
2010
|
+
const updateExtensions = (0, import_react10.useCallback)(
|
|
2011
|
+
(newExtensions) => {
|
|
2012
|
+
setExtensions((prev) => {
|
|
2013
|
+
const resolved = typeof newExtensions === "function" ? newExtensions(prev) : newExtensions;
|
|
2014
|
+
const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
|
|
2015
|
+
const isEqual = isSameLength && // @ts-ignore
|
|
2016
|
+
Object.entries(resolved).every(([key, value]) => prev[key] === value);
|
|
2017
|
+
return isEqual ? prev : resolved;
|
|
2018
|
+
});
|
|
2019
|
+
},
|
|
2020
|
+
[setExtensions]
|
|
2021
|
+
);
|
|
2022
|
+
const updateAuthStates = (0, import_react10.useCallback)(
|
|
2023
|
+
(newAuthStates) => {
|
|
2024
|
+
setAuthStates((prev) => {
|
|
2025
|
+
const resolved = typeof newAuthStates === "function" ? newAuthStates(prev) : newAuthStates;
|
|
2026
|
+
const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
|
|
2027
|
+
const isEqual = isSameLength && // @ts-ignore
|
|
2028
|
+
Object.entries(resolved).every(([key, value]) => prev[key] === value);
|
|
2029
|
+
return isEqual ? prev : resolved;
|
|
2030
|
+
});
|
|
2031
|
+
},
|
|
2032
|
+
[setAuthStates]
|
|
2033
|
+
);
|
|
1938
2034
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1939
2035
|
CopilotContext.Provider,
|
|
1940
2036
|
{
|
|
@@ -1972,8 +2068,8 @@ ${nonDocumentStrings}`;
|
|
|
1972
2068
|
agentSession,
|
|
1973
2069
|
setAgentSession,
|
|
1974
2070
|
runtimeClient,
|
|
1975
|
-
forwardedParameters
|
|
1976
|
-
agentLock
|
|
2071
|
+
forwardedParameters,
|
|
2072
|
+
agentLock,
|
|
1977
2073
|
threadId: internalThreadId,
|
|
1978
2074
|
setThreadId,
|
|
1979
2075
|
runId,
|
|
@@ -1982,13 +2078,13 @@ ${nonDocumentStrings}`;
|
|
|
1982
2078
|
availableAgents,
|
|
1983
2079
|
authConfig_c: props.authConfig_c,
|
|
1984
2080
|
authStates_c: authStates,
|
|
1985
|
-
setAuthStates_c:
|
|
2081
|
+
setAuthStates_c: updateAuthStates,
|
|
1986
2082
|
extensions,
|
|
1987
|
-
setExtensions,
|
|
2083
|
+
setExtensions: updateExtensions,
|
|
1988
2084
|
langGraphInterruptAction,
|
|
1989
2085
|
setLangGraphInterruptAction,
|
|
1990
2086
|
removeLangGraphInterruptAction,
|
|
1991
|
-
|
|
2087
|
+
onError: props.onError
|
|
1992
2088
|
},
|
|
1993
2089
|
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotMessages, { children: memoizedChildren })
|
|
1994
2090
|
}
|
|
@@ -2041,6 +2137,7 @@ var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
|
2041
2137
|
|
|
2042
2138
|
// src/hooks/use-chat.ts
|
|
2043
2139
|
var import_react11 = require("react");
|
|
2140
|
+
var import_react_dom2 = require("react-dom");
|
|
2044
2141
|
var import_shared12 = require("@copilotkit/shared");
|
|
2045
2142
|
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
2046
2143
|
|
|
@@ -2099,6 +2196,35 @@ function useChat(options) {
|
|
|
2099
2196
|
} = options;
|
|
2100
2197
|
const runChatCompletionRef = (0, import_react11.useRef)();
|
|
2101
2198
|
const addErrorToast = useErrorToast();
|
|
2199
|
+
const { setBannerError } = useToast();
|
|
2200
|
+
const { onError } = useCopilotContext();
|
|
2201
|
+
const traceUIError = (error, originalError) => __async(this, null, function* () {
|
|
2202
|
+
if (!onError || !(copilotConfig == null ? void 0 : copilotConfig.publicApiKey))
|
|
2203
|
+
return;
|
|
2204
|
+
try {
|
|
2205
|
+
const traceEvent = {
|
|
2206
|
+
type: "error",
|
|
2207
|
+
timestamp: Date.now(),
|
|
2208
|
+
context: {
|
|
2209
|
+
source: "ui",
|
|
2210
|
+
request: {
|
|
2211
|
+
operation: "useChatCompletion",
|
|
2212
|
+
url: copilotConfig.chatApiEndpoint,
|
|
2213
|
+
startTime: Date.now()
|
|
2214
|
+
},
|
|
2215
|
+
technical: {
|
|
2216
|
+
environment: "browser",
|
|
2217
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
2218
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
2219
|
+
}
|
|
2220
|
+
},
|
|
2221
|
+
error
|
|
2222
|
+
};
|
|
2223
|
+
yield onError(traceEvent);
|
|
2224
|
+
} catch (traceError) {
|
|
2225
|
+
console.error("Error in use-chat onError handler:", traceError);
|
|
2226
|
+
}
|
|
2227
|
+
});
|
|
2102
2228
|
const agentSessionRef = (0, import_react11.useRef)(agentSession);
|
|
2103
2229
|
agentSessionRef.current = agentSession;
|
|
2104
2230
|
const runIdRef = (0, import_react11.useRef)(runId);
|
|
@@ -2118,7 +2244,7 @@ function useChat(options) {
|
|
|
2118
2244
|
const pendingAppendsRef = (0, import_react11.useRef)([]);
|
|
2119
2245
|
const runChatCompletion = useAsyncCallback(
|
|
2120
2246
|
(previousMessages) => __async(this, null, function* () {
|
|
2121
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
2247
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
2122
2248
|
setIsLoading(true);
|
|
2123
2249
|
const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
|
|
2124
2250
|
if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql6.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
|
|
@@ -2250,20 +2376,53 @@ function useChat(options) {
|
|
|
2250
2376
|
messages2 = (0, import_runtime_client_gql6.convertGqlOutputToMessages)(
|
|
2251
2377
|
(0, import_runtime_client_gql6.filterAdjacentAgentStateMessages)(rawMessagesResponse)
|
|
2252
2378
|
);
|
|
2253
|
-
if (messages2.length === 0) {
|
|
2254
|
-
continue;
|
|
2255
|
-
}
|
|
2256
2379
|
newMessages = [];
|
|
2257
2380
|
if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
2381
|
+
const guardrailsReason = ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || "";
|
|
2258
2382
|
newMessages = [
|
|
2259
2383
|
new import_runtime_client_gql6.TextMessage({
|
|
2260
2384
|
role: import_runtime_client_gql6.MessageRole.Assistant,
|
|
2261
|
-
content:
|
|
2385
|
+
content: guardrailsReason
|
|
2262
2386
|
})
|
|
2263
2387
|
];
|
|
2388
|
+
const guardrailsError = new import_shared12.CopilotKitError({
|
|
2389
|
+
message: `Guardrails validation failed: ${guardrailsReason}`,
|
|
2390
|
+
code: import_shared12.CopilotKitErrorCode.MISUSE
|
|
2391
|
+
});
|
|
2392
|
+
yield traceUIError(guardrailsError, {
|
|
2393
|
+
statusReason: value.generateCopilotResponse.status.reason,
|
|
2394
|
+
statusDetails: value.generateCopilotResponse.status.details
|
|
2395
|
+
});
|
|
2264
2396
|
setMessages([...previousMessages, ...newMessages]);
|
|
2265
2397
|
break;
|
|
2266
|
-
}
|
|
2398
|
+
}
|
|
2399
|
+
if (((_m = value.generateCopilotResponse.status) == null ? void 0 : _m.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "UNKNOWN_ERROR") {
|
|
2400
|
+
const errorMessage = ((_n = value.generateCopilotResponse.status.details) == null ? void 0 : _n.description) || "An unknown error occurred";
|
|
2401
|
+
const statusDetails = value.generateCopilotResponse.status.details;
|
|
2402
|
+
const originalError = (statusDetails == null ? void 0 : statusDetails.originalError) || (statusDetails == null ? void 0 : statusDetails.error);
|
|
2403
|
+
const originalCode = (originalError == null ? void 0 : originalError.code) || ((_o = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _o.code);
|
|
2404
|
+
const originalSeverity = (originalError == null ? void 0 : originalError.severity) || ((_p = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _p.severity);
|
|
2405
|
+
const originalVisibility = (originalError == null ? void 0 : originalError.visibility) || ((_q = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _q.visibility);
|
|
2406
|
+
let errorCode = import_shared12.CopilotKitErrorCode.NETWORK_ERROR;
|
|
2407
|
+
if (originalCode && Object.values(import_shared12.CopilotKitErrorCode).includes(originalCode)) {
|
|
2408
|
+
errorCode = originalCode;
|
|
2409
|
+
}
|
|
2410
|
+
const structuredError = new import_shared12.CopilotKitError({
|
|
2411
|
+
message: errorMessage,
|
|
2412
|
+
code: errorCode,
|
|
2413
|
+
severity: originalSeverity,
|
|
2414
|
+
visibility: originalVisibility
|
|
2415
|
+
});
|
|
2416
|
+
setBannerError(structuredError);
|
|
2417
|
+
yield traceUIError(structuredError, {
|
|
2418
|
+
statusReason: value.generateCopilotResponse.status.reason,
|
|
2419
|
+
statusDetails: value.generateCopilotResponse.status.details,
|
|
2420
|
+
originalErrorCode: originalCode,
|
|
2421
|
+
preservedStructure: !!originalCode
|
|
2422
|
+
});
|
|
2423
|
+
setIsLoading(false);
|
|
2424
|
+
break;
|
|
2425
|
+
} else if (messages2.length > 0) {
|
|
2267
2426
|
newMessages = [...messages2];
|
|
2268
2427
|
for (const message of messages2) {
|
|
2269
2428
|
if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
|
|
@@ -2285,17 +2444,22 @@ function useChat(options) {
|
|
|
2285
2444
|
lastAgentStateMessage.state.messages
|
|
2286
2445
|
);
|
|
2287
2446
|
}
|
|
2288
|
-
setCoagentStatesWithRef((prevAgentStates) =>
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2447
|
+
setCoagentStatesWithRef((prevAgentStates) => {
|
|
2448
|
+
var _a2;
|
|
2449
|
+
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
2450
|
+
[lastAgentStateMessage.agentName]: {
|
|
2451
|
+
name: lastAgentStateMessage.agentName,
|
|
2452
|
+
state: lastAgentStateMessage.state,
|
|
2453
|
+
running: lastAgentStateMessage.running,
|
|
2454
|
+
active: lastAgentStateMessage.active,
|
|
2455
|
+
threadId: lastAgentStateMessage.threadId,
|
|
2456
|
+
nodeName: lastAgentStateMessage.nodeName,
|
|
2457
|
+
runId: lastAgentStateMessage.runId,
|
|
2458
|
+
// Preserve existing config from previous state
|
|
2459
|
+
config: (_a2 = prevAgentStates[lastAgentStateMessage.agentName]) == null ? void 0 : _a2.config
|
|
2460
|
+
}
|
|
2461
|
+
});
|
|
2462
|
+
});
|
|
2299
2463
|
if (lastAgentStateMessage.running) {
|
|
2300
2464
|
setAgentSession({
|
|
2301
2465
|
threadId: lastAgentStateMessage.threadId,
|
|
@@ -2325,6 +2489,39 @@ function useChat(options) {
|
|
|
2325
2489
|
newMessages
|
|
2326
2490
|
);
|
|
2327
2491
|
let didExecuteAction = false;
|
|
2492
|
+
const executeActionFromMessage = (currentAction, actionMessage) => __async(this, null, function* () {
|
|
2493
|
+
var _a2;
|
|
2494
|
+
const isInterruptAction = interruptMessages.find((m) => m.id === actionMessage.id);
|
|
2495
|
+
followUp = (_a2 = currentAction == null ? void 0 : currentAction.followUp) != null ? _a2 : !isInterruptAction;
|
|
2496
|
+
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
2497
|
+
currentAction._setActivatingMessageId(actionMessage.id);
|
|
2498
|
+
}
|
|
2499
|
+
const resultMessage = yield executeAction({
|
|
2500
|
+
onFunctionCall,
|
|
2501
|
+
message: actionMessage,
|
|
2502
|
+
chatAbortControllerRef,
|
|
2503
|
+
onError: (error) => {
|
|
2504
|
+
addErrorToast([error]);
|
|
2505
|
+
console.error(`Failed to execute action ${actionMessage.name}: ${error}`);
|
|
2506
|
+
},
|
|
2507
|
+
setMessages,
|
|
2508
|
+
getFinalMessages: () => finalMessages,
|
|
2509
|
+
isRenderAndWait: (currentAction == null ? void 0 : currentAction._isRenderAndWait) || false
|
|
2510
|
+
});
|
|
2511
|
+
didExecuteAction = true;
|
|
2512
|
+
const messageIndex = finalMessages.findIndex((msg) => msg.id === actionMessage.id);
|
|
2513
|
+
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
2514
|
+
if (currentAction == null ? void 0 : currentAction._isRenderAndWait) {
|
|
2515
|
+
const messagesForImmediateUpdate = [...finalMessages];
|
|
2516
|
+
(0, import_react_dom2.flushSync)(() => {
|
|
2517
|
+
setMessages(messagesForImmediateUpdate);
|
|
2518
|
+
});
|
|
2519
|
+
}
|
|
2520
|
+
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
2521
|
+
currentAction._setActivatingMessageId(null);
|
|
2522
|
+
}
|
|
2523
|
+
return resultMessage;
|
|
2524
|
+
});
|
|
2328
2525
|
if (onFunctionCall) {
|
|
2329
2526
|
const lastMessages = [];
|
|
2330
2527
|
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
@@ -2341,37 +2538,28 @@ function useChat(options) {
|
|
|
2341
2538
|
(action2) => action2.name === message.name
|
|
2342
2539
|
);
|
|
2343
2540
|
const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
|
|
2344
|
-
const executeActionFromMessage = (action2, message2) => __async(this, null, function* () {
|
|
2345
|
-
var _a2;
|
|
2346
|
-
const isInterruptAction = interruptMessages.find((m) => m.id === message2.id);
|
|
2347
|
-
followUp = (_a2 = action2 == null ? void 0 : action2.followUp) != null ? _a2 : !isInterruptAction;
|
|
2348
|
-
const resultMessage = yield executeAction({
|
|
2349
|
-
onFunctionCall,
|
|
2350
|
-
previousMessages,
|
|
2351
|
-
message: message2,
|
|
2352
|
-
chatAbortControllerRef,
|
|
2353
|
-
onError: (error) => {
|
|
2354
|
-
addErrorToast([error]);
|
|
2355
|
-
console.error(`Failed to execute action ${message2.name}: ${error}`);
|
|
2356
|
-
}
|
|
2357
|
-
});
|
|
2358
|
-
didExecuteAction = true;
|
|
2359
|
-
const messageIndex = finalMessages.findIndex((msg) => msg.id === message2.id);
|
|
2360
|
-
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
2361
|
-
return resultMessage;
|
|
2362
|
-
});
|
|
2363
2541
|
if (action && message.isActionExecutionMessage()) {
|
|
2364
|
-
const
|
|
2365
|
-
const
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2542
|
+
const isRenderAndWaitAction = (action == null ? void 0 : action._isRenderAndWait) || false;
|
|
2543
|
+
const alreadyProcessed = isRenderAndWaitAction && finalMessages.some(
|
|
2544
|
+
(fm) => fm.isResultMessage() && fm.actionExecutionId === message.id
|
|
2545
|
+
);
|
|
2546
|
+
if (alreadyProcessed) {
|
|
2547
|
+
} else {
|
|
2548
|
+
const resultMessage = yield executeActionFromMessage(
|
|
2549
|
+
action,
|
|
2550
|
+
message
|
|
2551
|
+
);
|
|
2552
|
+
const pairedFeAction = getPairedFeAction(actions, resultMessage);
|
|
2553
|
+
if (pairedFeAction) {
|
|
2554
|
+
const newExecutionMessage = new import_runtime_client_gql6.ActionExecutionMessage({
|
|
2555
|
+
name: pairedFeAction.name,
|
|
2556
|
+
arguments: (0, import_shared12.parseJson)(resultMessage.result, resultMessage.result),
|
|
2557
|
+
status: message.status,
|
|
2558
|
+
createdAt: message.createdAt,
|
|
2559
|
+
parentMessageId: message.parentMessageId
|
|
2560
|
+
});
|
|
2561
|
+
yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
|
|
2562
|
+
}
|
|
2375
2563
|
}
|
|
2376
2564
|
} else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
|
|
2377
2565
|
const newExecutionMessage = new import_runtime_client_gql6.ActionExecutionMessage({
|
|
@@ -2389,16 +2577,12 @@ function useChat(options) {
|
|
|
2389
2577
|
}
|
|
2390
2578
|
setMessages(finalMessages);
|
|
2391
2579
|
}
|
|
2392
|
-
if (
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
(didExecuteAction || // the last message is a server side result
|
|
2396
|
-
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
2397
|
-
!((_m = chatAbortControllerRef.current) == null ? void 0 : _m.signal.aborted)
|
|
2398
|
-
) {
|
|
2580
|
+
if (followUp !== false && (didExecuteAction || // the last message is a server side result
|
|
2581
|
+
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
2582
|
+
!((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)) {
|
|
2399
2583
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
2400
2584
|
return yield runChatCompletionRef.current(finalMessages);
|
|
2401
|
-
} else if ((
|
|
2585
|
+
} else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
|
|
2402
2586
|
const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
|
|
2403
2587
|
if (message.isActionExecutionMessage()) {
|
|
2404
2588
|
return finalMessages.find(
|
|
@@ -2409,7 +2593,7 @@ function useChat(options) {
|
|
|
2409
2593
|
});
|
|
2410
2594
|
const repairedMessageIds = repairedMessages.map((message) => message.id);
|
|
2411
2595
|
setMessages(repairedMessages);
|
|
2412
|
-
if ((
|
|
2596
|
+
if ((_t = agentSessionRef.current) == null ? void 0 : _t.nodeName) {
|
|
2413
2597
|
setAgentSession({
|
|
2414
2598
|
threadId: agentSessionRef.current.threadId,
|
|
2415
2599
|
agentName: agentSessionRef.current.agentName,
|
|
@@ -2503,21 +2687,35 @@ function useChat(options) {
|
|
|
2503
2687
|
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
2504
2688
|
);
|
|
2505
2689
|
const reload = useAsyncCallback(
|
|
2506
|
-
(
|
|
2690
|
+
(reloadMessageId) => __async(this, null, function* () {
|
|
2507
2691
|
if (isLoading || messages.length === 0) {
|
|
2508
2692
|
return;
|
|
2509
2693
|
}
|
|
2510
|
-
const
|
|
2511
|
-
if (
|
|
2512
|
-
console.warn(`Message with id ${
|
|
2694
|
+
const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);
|
|
2695
|
+
if (reloadMessageIndex === -1) {
|
|
2696
|
+
console.warn(`Message with id ${reloadMessageId} not found`);
|
|
2697
|
+
return;
|
|
2698
|
+
}
|
|
2699
|
+
const reloadMessageRole = messages[reloadMessageIndex].role;
|
|
2700
|
+
if (reloadMessageRole !== import_runtime_client_gql6.MessageRole.Assistant) {
|
|
2701
|
+
console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);
|
|
2513
2702
|
return;
|
|
2514
2703
|
}
|
|
2515
|
-
let
|
|
2516
|
-
if (
|
|
2517
|
-
|
|
2704
|
+
let historyCutoff = [];
|
|
2705
|
+
if (messages.length > 2) {
|
|
2706
|
+
const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find(
|
|
2707
|
+
(msg) => (
|
|
2708
|
+
// @ts-expect-error -- message has role
|
|
2709
|
+
msg.role === import_runtime_client_gql6.MessageRole.User
|
|
2710
|
+
)
|
|
2711
|
+
);
|
|
2712
|
+
const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
|
|
2713
|
+
(msg) => msg.id === lastUserMessageBeforeRegenerate.id
|
|
2714
|
+
);
|
|
2715
|
+
historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
|
|
2518
2716
|
}
|
|
2519
|
-
setMessages(
|
|
2520
|
-
return runChatCompletionAndHandleFunctionCall(
|
|
2717
|
+
setMessages(historyCutoff);
|
|
2718
|
+
return runChatCompletionAndHandleFunctionCall(historyCutoff);
|
|
2521
2719
|
}),
|
|
2522
2720
|
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
2523
2721
|
);
|
|
@@ -2552,20 +2750,31 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
|
|
|
2552
2750
|
function executeAction(_0) {
|
|
2553
2751
|
return __async(this, arguments, function* ({
|
|
2554
2752
|
onFunctionCall,
|
|
2555
|
-
previousMessages,
|
|
2556
2753
|
message,
|
|
2557
2754
|
chatAbortControllerRef,
|
|
2558
|
-
onError
|
|
2755
|
+
onError,
|
|
2756
|
+
setMessages,
|
|
2757
|
+
getFinalMessages,
|
|
2758
|
+
isRenderAndWait
|
|
2559
2759
|
}) {
|
|
2560
2760
|
let result;
|
|
2561
2761
|
let error = null;
|
|
2762
|
+
const currentMessagesForHandler = getFinalMessages();
|
|
2763
|
+
const handlerReturnedPromise = onFunctionCall({
|
|
2764
|
+
messages: currentMessagesForHandler,
|
|
2765
|
+
name: message.name,
|
|
2766
|
+
args: message.arguments
|
|
2767
|
+
});
|
|
2768
|
+
if (isRenderAndWait) {
|
|
2769
|
+
const currentMessagesForRender = getFinalMessages();
|
|
2770
|
+
(0, import_react_dom2.flushSync)(() => {
|
|
2771
|
+
setMessages([...currentMessagesForRender]);
|
|
2772
|
+
});
|
|
2773
|
+
}
|
|
2562
2774
|
try {
|
|
2563
2775
|
result = yield Promise.race([
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
name: message.name,
|
|
2567
|
-
args: message.arguments
|
|
2568
|
-
}),
|
|
2776
|
+
handlerReturnedPromise,
|
|
2777
|
+
// Await the promise returned by the handler
|
|
2569
2778
|
new Promise(
|
|
2570
2779
|
(resolve) => {
|
|
2571
2780
|
var _a;
|
|
@@ -2832,6 +3041,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
2832
3041
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
2833
3042
|
const idRef = (0, import_react13.useRef)((0, import_shared13.randomId)());
|
|
2834
3043
|
const renderAndWaitRef = (0, import_react13.useRef)(null);
|
|
3044
|
+
const activatingMessageIdRef = (0, import_react13.useRef)(null);
|
|
2835
3045
|
const { addToast } = useToast();
|
|
2836
3046
|
action = __spreadValues({}, action);
|
|
2837
3047
|
if (
|
|
@@ -2839,30 +3049,48 @@ function useCopilotAction(action, dependencies) {
|
|
|
2839
3049
|
isFrontendAction(action) && // check if renderAndWaitForResponse is set
|
|
2840
3050
|
(action.renderAndWait || action.renderAndWaitForResponse)
|
|
2841
3051
|
) {
|
|
3052
|
+
action._isRenderAndWait = true;
|
|
2842
3053
|
const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
|
|
2843
3054
|
action.renderAndWait = void 0;
|
|
2844
3055
|
action.renderAndWaitForResponse = void 0;
|
|
3056
|
+
action._setActivatingMessageId = (id) => {
|
|
3057
|
+
activatingMessageIdRef.current = id;
|
|
3058
|
+
};
|
|
2845
3059
|
action.handler = useAsyncCallback(() => __async(this, null, function* () {
|
|
3060
|
+
const currentActivatingId = activatingMessageIdRef.current;
|
|
2846
3061
|
let resolve;
|
|
2847
3062
|
let reject;
|
|
2848
3063
|
const promise = new Promise((resolvePromise, rejectPromise) => {
|
|
2849
3064
|
resolve = resolvePromise;
|
|
2850
3065
|
reject = rejectPromise;
|
|
2851
3066
|
});
|
|
2852
|
-
renderAndWaitRef.current = {
|
|
2853
|
-
|
|
3067
|
+
renderAndWaitRef.current = {
|
|
3068
|
+
promise,
|
|
3069
|
+
resolve,
|
|
3070
|
+
reject,
|
|
3071
|
+
messageId: currentActivatingId
|
|
3072
|
+
};
|
|
3073
|
+
const result = yield promise;
|
|
3074
|
+
return result;
|
|
2854
3075
|
}), []);
|
|
2855
3076
|
action.render = (props) => {
|
|
3077
|
+
const currentRenderMessageId = props.messageId;
|
|
2856
3078
|
let status = props.status;
|
|
2857
|
-
if (props.status === "executing"
|
|
2858
|
-
|
|
3079
|
+
if (props.status === "executing") {
|
|
3080
|
+
if (!renderAndWaitRef.current || !renderAndWaitRef.current.promise) {
|
|
3081
|
+
status = "inProgress";
|
|
3082
|
+
} else if (renderAndWaitRef.current.messageId !== currentRenderMessageId && activatingMessageIdRef.current !== currentRenderMessageId) {
|
|
3083
|
+
status = "inProgress";
|
|
3084
|
+
}
|
|
2859
3085
|
}
|
|
2860
3086
|
const waitProps = {
|
|
2861
3087
|
status,
|
|
2862
3088
|
args: props.args,
|
|
2863
3089
|
result: props.result,
|
|
2864
|
-
handler
|
|
2865
|
-
|
|
3090
|
+
// handler and respond should only be provided if this is the truly active instance
|
|
3091
|
+
// and its promise infrastructure is ready.
|
|
3092
|
+
handler: status === "executing" && renderAndWaitRef.current && renderAndWaitRef.current.messageId === currentRenderMessageId ? renderAndWaitRef.current.resolve : void 0,
|
|
3093
|
+
respond: status === "executing" && renderAndWaitRef.current && renderAndWaitRef.current.messageId === currentRenderMessageId ? renderAndWaitRef.current.resolve : void 0
|
|
2866
3094
|
};
|
|
2867
3095
|
const isNoArgsRenderWait = (_fn) => {
|
|
2868
3096
|
var _a;
|
|
@@ -3105,6 +3333,9 @@ function useCoAgent(options) {
|
|
|
3105
3333
|
threadId,
|
|
3106
3334
|
agentName: name
|
|
3107
3335
|
});
|
|
3336
|
+
if (result.error) {
|
|
3337
|
+
return;
|
|
3338
|
+
}
|
|
3108
3339
|
const newState = (_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.state;
|
|
3109
3340
|
if (newState === lastLoadedState.current)
|
|
3110
3341
|
return;
|
|
@@ -3128,6 +3359,32 @@ function useCoAgent(options) {
|
|
|
3128
3359
|
// reset initialstate on reset
|
|
3129
3360
|
coagentStates[name] === void 0
|
|
3130
3361
|
]);
|
|
3362
|
+
(0, import_react17.useEffect)(() => {
|
|
3363
|
+
const newConfig = options.config ? options.config : options.configurable ? { configurable: options.configurable } : void 0;
|
|
3364
|
+
if (newConfig === void 0)
|
|
3365
|
+
return;
|
|
3366
|
+
setCoagentStatesWithRef((prev) => {
|
|
3367
|
+
var _a;
|
|
3368
|
+
const existing = (_a = prev[name]) != null ? _a : {
|
|
3369
|
+
name,
|
|
3370
|
+
state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
|
|
3371
|
+
config: {},
|
|
3372
|
+
running: false,
|
|
3373
|
+
active: false,
|
|
3374
|
+
threadId: void 0,
|
|
3375
|
+
nodeName: void 0,
|
|
3376
|
+
runId: void 0
|
|
3377
|
+
};
|
|
3378
|
+
if (JSON.stringify(existing.config) === JSON.stringify(newConfig)) {
|
|
3379
|
+
return prev;
|
|
3380
|
+
}
|
|
3381
|
+
return __spreadProps(__spreadValues({}, prev), {
|
|
3382
|
+
[name]: __spreadProps(__spreadValues({}, existing), {
|
|
3383
|
+
config: newConfig
|
|
3384
|
+
})
|
|
3385
|
+
});
|
|
3386
|
+
});
|
|
3387
|
+
}, [JSON.stringify(options.config), JSON.stringify(options.configurable)]);
|
|
3131
3388
|
const runAgentCallback = useAsyncCallback(
|
|
3132
3389
|
(hint) => __async(this, null, function* () {
|
|
3133
3390
|
yield runAgent(name, context, appendMessage, runChatCompletion, hint);
|