@copilotkit/react-core 1.9.2-next.1 → 1.9.2-next.10
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 +71 -0
- package/dist/{chunk-CCESTGAM.mjs → chunk-3OQM3NEK.mjs} +2 -2
- package/dist/{chunk-2FW7HH6W.mjs → chunk-3YHYWAHK.mjs} +3 -3
- package/dist/{chunk-RUY6MLHA.mjs → chunk-55QZ2SVJ.mjs} +36 -6
- package/dist/chunk-55QZ2SVJ.mjs.map +1 -0
- package/dist/chunk-57K2ZJ5F.mjs +348 -0
- package/dist/chunk-57K2ZJ5F.mjs.map +1 -0
- package/dist/{chunk-XY5BN4HZ.mjs → chunk-ADIITPD2.mjs} +9 -6
- package/dist/{chunk-XY5BN4HZ.mjs.map → chunk-ADIITPD2.mjs.map} +1 -1
- package/dist/{chunk-Q5D5XQFA.mjs → chunk-CMQV4XNY.mjs} +2 -2
- package/dist/{chunk-LDACFA2B.mjs → chunk-EF5BNM34.mjs} +3 -3
- package/dist/{chunk-UHQMV2CE.mjs → chunk-ERXWDCY6.mjs} +2 -2
- package/dist/{chunk-UIT6QMUJ.mjs → chunk-EXU7GWLC.mjs} +5 -5
- package/dist/{chunk-YDENFEKA.mjs → chunk-FXK6RQIN.mjs} +2 -2
- package/dist/{chunk-HJP2RX5R.mjs → chunk-G7LYGERN.mjs} +81 -14
- package/dist/chunk-G7LYGERN.mjs.map +1 -0
- package/dist/{chunk-NNSXCFQO.mjs → chunk-JDEWNLNP.mjs} +41 -7
- package/dist/chunk-JDEWNLNP.mjs.map +1 -0
- package/dist/{chunk-C6F6EQNA.mjs → chunk-JPMIAGI6.mjs} +2 -2
- package/dist/{chunk-T42PN5VN.mjs → chunk-NQVCZQ5T.mjs} +4 -4
- package/dist/{chunk-YZDRMIOM.mjs → chunk-OF4SZTLL.mjs} +4 -4
- package/dist/{chunk-QQZLIEXK.mjs → chunk-SJJNFYGQ.mjs} +3 -3
- package/dist/{chunk-LZDDYZEY.mjs → chunk-UBNRUXEK.mjs} +2 -2
- package/dist/{chunk-SGLWMQ2J.mjs → chunk-WOGURSAL.mjs} +12 -9
- package/dist/chunk-WOGURSAL.mjs.map +1 -0
- package/dist/{chunk-6KGEF242.mjs → chunk-XFOTNHYA.mjs} +3 -2
- package/dist/chunk-XFOTNHYA.mjs.map +1 -0
- package/dist/chunk-YAF2LATQ.mjs +310 -0
- package/dist/chunk-YAF2LATQ.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.js +39 -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 +21 -2
- 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 +330 -240
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +8 -8
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +330 -240
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +8 -8
- 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 +330 -240
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +8 -8
- 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 +2 -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 +2 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{copilot-context-f9b2b4c3.d.ts → copilot-context-3da805ab.d.ts} +5 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +108 -12
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +19 -19
- package/dist/hooks/use-chat.d.ts +1 -1
- package/dist/hooks/use-chat.js +105 -12
- 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 +2 -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 +108 -12
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +11 -11
- package/dist/hooks/use-copilot-action.js +2 -1
- 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 +2 -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 +2 -1
- 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 +105 -12
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +10 -10
- package/dist/hooks/use-copilot-readable.js +2 -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 -0
- package/dist/hooks/use-copilot-runtime-client.js +52 -2
- 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 +2 -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 +105 -12
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +11 -11
- package/dist/hooks/use-make-copilot-document-readable.js +2 -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 +404 -249
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -20
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +9 -9
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +9 -9
- 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 +8 -8
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +8 -8
- package/jest.config.js +7 -3
- package/package.json +4 -3
- package/src/components/copilot-provider/__tests__/copilotkit-trace.test.tsx +75 -0
- package/src/components/copilot-provider/copilot-messages.tsx +46 -5
- package/src/components/copilot-provider/copilotkit-props.tsx +21 -0
- package/src/components/copilot-provider/copilotkit.tsx +5 -1
- package/src/components/toast/toast-provider.tsx +49 -24
- package/src/components/usage-banner.tsx +144 -147
- package/src/context/copilot-context.tsx +7 -1
- package/src/hooks/use-chat.ts +106 -6
- package/src/hooks/use-coagent.ts +5 -0
- package/src/hooks/use-copilot-runtime-client.ts +41 -39
- package/tsconfig.json +1 -8
- package/tsup.config.ts +6 -6
- package/dist/chunk-6KGEF242.mjs.map +0 -1
- package/dist/chunk-HD2GE3DK.mjs +0 -359
- package/dist/chunk-HD2GE3DK.mjs.map +0 -1
- package/dist/chunk-HJP2RX5R.mjs.map +0 -1
- package/dist/chunk-NNSXCFQO.mjs.map +0 -1
- package/dist/chunk-RUY6MLHA.mjs.map +0 -1
- package/dist/chunk-SGLWMQ2J.mjs.map +0 -1
- package/dist/chunk-VRXANACV.mjs +0 -277
- package/dist/chunk-VRXANACV.mjs.map +0 -1
- package/dist/utils/utils.test.d.ts +0 -2
- package/dist/utils/utils.test.js +0 -9
- package/dist/utils/utils.test.js.map +0 -1
- package/dist/utils/utils.test.mjs +0 -7
- package/dist/utils/utils.test.mjs.map +0 -1
- /package/dist/{chunk-CCESTGAM.mjs.map → chunk-3OQM3NEK.mjs.map} +0 -0
- /package/dist/{chunk-2FW7HH6W.mjs.map → chunk-3YHYWAHK.mjs.map} +0 -0
- /package/dist/{chunk-Q5D5XQFA.mjs.map → chunk-CMQV4XNY.mjs.map} +0 -0
- /package/dist/{chunk-LDACFA2B.mjs.map → chunk-EF5BNM34.mjs.map} +0 -0
- /package/dist/{chunk-UHQMV2CE.mjs.map → chunk-ERXWDCY6.mjs.map} +0 -0
- /package/dist/{chunk-UIT6QMUJ.mjs.map → chunk-EXU7GWLC.mjs.map} +0 -0
- /package/dist/{chunk-YDENFEKA.mjs.map → chunk-FXK6RQIN.mjs.map} +0 -0
- /package/dist/{chunk-C6F6EQNA.mjs.map → chunk-JPMIAGI6.mjs.map} +0 -0
- /package/dist/{chunk-T42PN5VN.mjs.map → chunk-NQVCZQ5T.mjs.map} +0 -0
- /package/dist/{chunk-YZDRMIOM.mjs.map → chunk-OF4SZTLL.mjs.map} +0 -0
- /package/dist/{chunk-QQZLIEXK.mjs.map → chunk-SJJNFYGQ.mjs.map} +0 -0
- /package/dist/{chunk-LZDDYZEY.mjs.map → chunk-UBNRUXEK.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -183,7 +183,8 @@ var emptyCopilotContext = {
|
|
|
183
183
|
},
|
|
184
184
|
langGraphInterruptAction: null,
|
|
185
185
|
setLangGraphInterruptAction: () => null,
|
|
186
|
-
removeLangGraphInterruptAction: () => null
|
|
186
|
+
removeLangGraphInterruptAction: () => null,
|
|
187
|
+
onTrace: void 0
|
|
187
188
|
};
|
|
188
189
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
189
190
|
function useCopilotContext() {
|
|
@@ -547,12 +548,14 @@ function ToastProvider({
|
|
|
547
548
|
border: `1px solid ${colors.border}`,
|
|
548
549
|
borderLeft: `4px solid ${colors.border}`,
|
|
549
550
|
borderRadius: "8px",
|
|
550
|
-
padding: "
|
|
551
|
+
padding: "12px 16px",
|
|
551
552
|
fontSize: "13px",
|
|
552
553
|
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
|
|
553
554
|
backdropFilter: "blur(8px)",
|
|
554
|
-
maxWidth: "
|
|
555
|
-
|
|
555
|
+
maxWidth: "min(90vw, 700px)",
|
|
556
|
+
width: "100%",
|
|
557
|
+
boxSizing: "border-box",
|
|
558
|
+
overflow: "hidden"
|
|
556
559
|
},
|
|
557
560
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
558
561
|
"div",
|
|
@@ -564,94 +567,125 @@ function ToastProvider({
|
|
|
564
567
|
gap: "10px"
|
|
565
568
|
},
|
|
566
569
|
children: [
|
|
567
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
{
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
fontWeight: "400",
|
|
588
|
-
fontSize: "13px",
|
|
589
|
-
flex: 1,
|
|
590
|
-
wordWrap: "break-word",
|
|
591
|
-
overflowWrap: "break-word",
|
|
592
|
-
hyphens: "auto"
|
|
593
|
-
},
|
|
594
|
-
children: (() => {
|
|
595
|
-
const message = bannerError.message;
|
|
596
|
-
const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
597
|
-
const plainUrlRegex = /(https?:\/\/[^\s)]+)/g;
|
|
598
|
-
let cleanMessage = message.replace(markdownLinkRegex, "").replace(plainUrlRegex, "").replace(/See more:\s*/g, "").replace(/\s+/g, " ").trim();
|
|
599
|
-
if (cleanMessage.length > 120) {
|
|
600
|
-
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
|
|
601
590
|
}
|
|
602
|
-
return cleanMessage;
|
|
603
|
-
})()
|
|
604
|
-
}
|
|
605
|
-
),
|
|
606
|
-
(() => {
|
|
607
|
-
const message = bannerError.message;
|
|
608
|
-
const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
609
|
-
const plainUrlRegex = /(https?:\/\/[^\s)]+)/g;
|
|
610
|
-
let url = null;
|
|
611
|
-
let buttonText = "See More";
|
|
612
|
-
const markdownMatch = markdownLinkRegex.exec(message);
|
|
613
|
-
if (markdownMatch) {
|
|
614
|
-
url = markdownMatch[2];
|
|
615
|
-
buttonText = "See More";
|
|
616
|
-
} else {
|
|
617
|
-
const urlMatch = plainUrlRegex.exec(message);
|
|
618
|
-
if (urlMatch) {
|
|
619
|
-
url = urlMatch[0];
|
|
620
|
-
buttonText = "See More";
|
|
621
591
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
626
|
-
"button",
|
|
592
|
+
),
|
|
593
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
594
|
+
"div",
|
|
627
595
|
{
|
|
628
|
-
onClick: () => window.open(url, "_blank", "noopener,noreferrer"),
|
|
629
596
|
style: {
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
fontSize: "11px",
|
|
636
|
-
fontWeight: "500",
|
|
637
|
-
cursor: "pointer",
|
|
638
|
-
transition: "all 0.2s ease",
|
|
639
|
-
flexShrink: 0
|
|
640
|
-
},
|
|
641
|
-
onMouseEnter: (e) => {
|
|
642
|
-
e.currentTarget.style.opacity = "0.9";
|
|
643
|
-
e.currentTarget.style.transform = "translateY(-1px)";
|
|
597
|
+
display: "flex",
|
|
598
|
+
alignItems: "center",
|
|
599
|
+
gap: "10px",
|
|
600
|
+
flex: 1,
|
|
601
|
+
minWidth: 0
|
|
644
602
|
},
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
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
|
+
]
|
|
650
684
|
}
|
|
651
|
-
)
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
685
|
+
)
|
|
686
|
+
]
|
|
687
|
+
}
|
|
688
|
+
),
|
|
655
689
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
656
690
|
"button",
|
|
657
691
|
{
|
|
@@ -704,8 +738,38 @@ function CopilotMessages({ children }) {
|
|
|
704
738
|
const lastLoadedThreadId = (0, import_react6.useRef)();
|
|
705
739
|
const lastLoadedAgentName = (0, import_react6.useRef)();
|
|
706
740
|
const lastLoadedMessages = (0, import_react6.useRef)();
|
|
707
|
-
const { threadId, agentSession, runtimeClient, showDevConsole } = useCopilotContext();
|
|
741
|
+
const { threadId, agentSession, runtimeClient, showDevConsole, onTrace, copilotApiConfig } = useCopilotContext();
|
|
708
742
|
const { setBannerError } = useToast();
|
|
743
|
+
const traceUIError = (0, import_react6.useCallback)(
|
|
744
|
+
(error, originalError) => __async(this, null, function* () {
|
|
745
|
+
if (!onTrace || !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 onTrace(traceEvent);
|
|
767
|
+
} catch (traceError) {
|
|
768
|
+
console.error("Error in CopilotMessages onTrace handler:", traceError);
|
|
769
|
+
}
|
|
770
|
+
}),
|
|
771
|
+
[onTrace, copilotApiConfig.publicApiKey, copilotApiConfig.chatApiEndpoint]
|
|
772
|
+
);
|
|
709
773
|
const createStructuredError2 = (gqlError) => {
|
|
710
774
|
const extensions = gqlError.extensions;
|
|
711
775
|
const originalError = extensions == null ? void 0 : extensions.originalError;
|
|
@@ -750,12 +814,14 @@ function CopilotMessages({ children }) {
|
|
|
750
814
|
const ckError = createStructuredError2(gqlError);
|
|
751
815
|
if (ckError) {
|
|
752
816
|
setBannerError(ckError);
|
|
817
|
+
traceUIError(ckError, gqlError);
|
|
753
818
|
} else {
|
|
754
819
|
const fallbackError = new import_shared4.CopilotKitError({
|
|
755
820
|
message: gqlError.message,
|
|
756
821
|
code: import_shared4.CopilotKitErrorCode.UNKNOWN
|
|
757
822
|
});
|
|
758
823
|
setBannerError(fallbackError);
|
|
824
|
+
traceUIError(fallbackError, gqlError);
|
|
759
825
|
}
|
|
760
826
|
};
|
|
761
827
|
graphQLErrors.forEach(routeError);
|
|
@@ -769,10 +835,11 @@ function CopilotMessages({ children }) {
|
|
|
769
835
|
code: import_shared4.CopilotKitErrorCode.UNKNOWN
|
|
770
836
|
});
|
|
771
837
|
setBannerError(fallbackError);
|
|
838
|
+
traceUIError(fallbackError, error);
|
|
772
839
|
}
|
|
773
840
|
}
|
|
774
841
|
},
|
|
775
|
-
[setBannerError, showDevConsole]
|
|
842
|
+
[setBannerError, showDevConsole, traceUIError]
|
|
776
843
|
);
|
|
777
844
|
(0, import_react6.useEffect)(() => {
|
|
778
845
|
if (!threadId || threadId === lastLoadedThreadId.current)
|
|
@@ -807,6 +874,7 @@ function CopilotMessages({ children }) {
|
|
|
807
874
|
});
|
|
808
875
|
void fetchMessages();
|
|
809
876
|
}, [threadId, agentSession == null ? void 0 : agentSession.agentName, runtimeClient]);
|
|
877
|
+
const memoizedChildren = (0, import_react6.useMemo)(() => children, [children]);
|
|
810
878
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
811
879
|
CopilotMessagesContext.Provider,
|
|
812
880
|
{
|
|
@@ -814,7 +882,7 @@ function CopilotMessages({ children }) {
|
|
|
814
882
|
messages,
|
|
815
883
|
setMessages
|
|
816
884
|
},
|
|
817
|
-
children
|
|
885
|
+
children: memoizedChildren
|
|
818
886
|
}
|
|
819
887
|
);
|
|
820
888
|
}
|
|
@@ -825,8 +893,35 @@ var import_react7 = require("react");
|
|
|
825
893
|
var import_shared5 = require("@copilotkit/shared");
|
|
826
894
|
var useCopilotRuntimeClient = (options) => {
|
|
827
895
|
const { setBannerError } = useToast();
|
|
828
|
-
const _a = options, { showDevConsole } = _a, runtimeOptions = __objRest(_a, ["showDevConsole"]);
|
|
896
|
+
const _a = options, { showDevConsole, onTrace } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onTrace"]);
|
|
829
897
|
const lastStructuredErrorRef = (0, import_react7.useRef)(null);
|
|
898
|
+
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
899
|
+
if (!onTrace || !runtimeOptions.publicApiKey)
|
|
900
|
+
return;
|
|
901
|
+
try {
|
|
902
|
+
const traceEvent = {
|
|
903
|
+
type: "error",
|
|
904
|
+
timestamp: Date.now(),
|
|
905
|
+
context: {
|
|
906
|
+
source: "ui",
|
|
907
|
+
request: {
|
|
908
|
+
operation: "runtimeClient",
|
|
909
|
+
url: runtimeOptions.url,
|
|
910
|
+
startTime: Date.now()
|
|
911
|
+
},
|
|
912
|
+
technical: {
|
|
913
|
+
environment: "browser",
|
|
914
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
915
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
916
|
+
}
|
|
917
|
+
},
|
|
918
|
+
error
|
|
919
|
+
};
|
|
920
|
+
yield onTrace(traceEvent);
|
|
921
|
+
} catch (traceError) {
|
|
922
|
+
console.error("Error in onTrace handler:", traceError);
|
|
923
|
+
}
|
|
924
|
+
});
|
|
830
925
|
const runtimeClient = (0, import_react7.useMemo)(() => {
|
|
831
926
|
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
832
927
|
handleGQLErrors: (error) => {
|
|
@@ -854,12 +949,14 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
854
949
|
const ckError = createStructuredError(gqlError);
|
|
855
950
|
if (ckError) {
|
|
856
951
|
setBannerError(ckError);
|
|
952
|
+
traceUIError(ckError, gqlError);
|
|
857
953
|
} else {
|
|
858
954
|
const fallbackError = new import_shared5.CopilotKitError({
|
|
859
955
|
message: gqlError.message,
|
|
860
956
|
code: import_shared5.CopilotKitErrorCode.UNKNOWN
|
|
861
957
|
});
|
|
862
958
|
setBannerError(fallbackError);
|
|
959
|
+
traceUIError(fallbackError, gqlError);
|
|
863
960
|
}
|
|
864
961
|
};
|
|
865
962
|
graphQLErrors.forEach(routeError);
|
|
@@ -873,6 +970,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
873
970
|
code: import_shared5.CopilotKitErrorCode.UNKNOWN
|
|
874
971
|
});
|
|
875
972
|
setBannerError(fallbackError);
|
|
973
|
+
traceUIError(fallbackError, error);
|
|
876
974
|
}
|
|
877
975
|
}
|
|
878
976
|
},
|
|
@@ -885,7 +983,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
885
983
|
setBannerError(warningError);
|
|
886
984
|
}
|
|
887
985
|
}));
|
|
888
|
-
}, [runtimeOptions, setBannerError, showDevConsole]);
|
|
986
|
+
}, [runtimeOptions, setBannerError, showDevConsole, onTrace]);
|
|
889
987
|
return runtimeClient;
|
|
890
988
|
};
|
|
891
989
|
function createStructuredError(gqlError) {
|
|
@@ -1112,8 +1210,8 @@ var defaultIcons = {
|
|
|
1112
1210
|
"svg",
|
|
1113
1211
|
{
|
|
1114
1212
|
viewBox: "0 0 24 24",
|
|
1115
|
-
width: "
|
|
1116
|
-
height: "
|
|
1213
|
+
width: "16",
|
|
1214
|
+
height: "16",
|
|
1117
1215
|
stroke: "currentColor",
|
|
1118
1216
|
strokeWidth: "2.5",
|
|
1119
1217
|
fill: "none",
|
|
@@ -1130,8 +1228,8 @@ var defaultIcons = {
|
|
|
1130
1228
|
"svg",
|
|
1131
1229
|
{
|
|
1132
1230
|
viewBox: "0 0 24 24",
|
|
1133
|
-
width: "
|
|
1134
|
-
height: "
|
|
1231
|
+
width: "16",
|
|
1232
|
+
height: "16",
|
|
1135
1233
|
stroke: "currentColor",
|
|
1136
1234
|
strokeWidth: "2.5",
|
|
1137
1235
|
fill: "none",
|
|
@@ -1148,8 +1246,8 @@ var defaultIcons = {
|
|
|
1148
1246
|
"svg",
|
|
1149
1247
|
{
|
|
1150
1248
|
viewBox: "0 0 24 24",
|
|
1151
|
-
width: "
|
|
1152
|
-
height: "
|
|
1249
|
+
width: "16",
|
|
1250
|
+
height: "16",
|
|
1153
1251
|
stroke: "currentColor",
|
|
1154
1252
|
strokeWidth: "2.5",
|
|
1155
1253
|
fill: "none",
|
|
@@ -1174,19 +1272,33 @@ function UsageBanner({
|
|
|
1174
1272
|
return null;
|
|
1175
1273
|
}
|
|
1176
1274
|
const parseMessage = (rawMessage) => {
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
if (matches.length > 0) {
|
|
1180
|
-
let cleanMessage2 = rawMessage.replace(/\.\s*See more:\s*\[([^\]]+)\]\(([^)]+)\)/g, ".").replace(/See more:\s*\[([^\]]+)\]\(([^)]+)\)/g, "").trim();
|
|
1181
|
-
return cleanMessage2;
|
|
1275
|
+
if (rawMessage.toLowerCase().includes("authentication") || rawMessage.toLowerCase().includes("api key")) {
|
|
1276
|
+
return "Authentication failed. Please check your API key.";
|
|
1182
1277
|
}
|
|
1183
|
-
|
|
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.";
|
|
1184
1296
|
};
|
|
1185
1297
|
const cleanMessage = parseMessage(message);
|
|
1186
1298
|
const Icon = icon || defaultIcons[severity];
|
|
1187
1299
|
const themeConfigs = {
|
|
1188
1300
|
[import_shared8.Severity.INFO]: {
|
|
1189
|
-
bg: "
|
|
1301
|
+
bg: "rgba(239, 246, 255, 0.95)",
|
|
1190
1302
|
border: "#93c5fd",
|
|
1191
1303
|
text: "#1e40af",
|
|
1192
1304
|
icon: "#3b82f6",
|
|
@@ -1194,7 +1306,7 @@ function UsageBanner({
|
|
|
1194
1306
|
primaryBtnHover: "#2563eb"
|
|
1195
1307
|
},
|
|
1196
1308
|
[import_shared8.Severity.WARNING]: {
|
|
1197
|
-
bg: "
|
|
1309
|
+
bg: "rgba(255, 251, 235, 0.95)",
|
|
1198
1310
|
border: "#fbbf24",
|
|
1199
1311
|
text: "#92400e",
|
|
1200
1312
|
icon: "#f59e0b",
|
|
@@ -1202,7 +1314,7 @@ function UsageBanner({
|
|
|
1202
1314
|
primaryBtnHover: "#d97706"
|
|
1203
1315
|
},
|
|
1204
1316
|
[import_shared8.Severity.CRITICAL]: {
|
|
1205
|
-
bg: "
|
|
1317
|
+
bg: "rgba(254, 242, 242, 0.95)",
|
|
1206
1318
|
border: "#f87171",
|
|
1207
1319
|
text: "#991b1b",
|
|
1208
1320
|
icon: "#ef4444",
|
|
@@ -1216,24 +1328,26 @@ function UsageBanner({
|
|
|
1216
1328
|
{
|
|
1217
1329
|
style: {
|
|
1218
1330
|
position: "fixed",
|
|
1219
|
-
bottom: "
|
|
1331
|
+
bottom: "24px",
|
|
1220
1332
|
left: "50%",
|
|
1221
1333
|
transform: "translateX(-50%)",
|
|
1222
|
-
|
|
1223
|
-
|
|
1334
|
+
width: "400px",
|
|
1335
|
+
maxWidth: "90vw",
|
|
1224
1336
|
zIndex: 1e4,
|
|
1225
|
-
animation: "bannerSlideIn 0.
|
|
1337
|
+
animation: "bannerSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1)"
|
|
1226
1338
|
},
|
|
1227
1339
|
children: [
|
|
1228
1340
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("style", { children: `
|
|
1229
1341
|
@keyframes bannerSlideIn {
|
|
1230
1342
|
from {
|
|
1231
1343
|
opacity: 0;
|
|
1232
|
-
transform: translateX(-50%) translateY(
|
|
1344
|
+
transform: translateX(-50%) translateY(20px);
|
|
1345
|
+
scale: 0.95;
|
|
1233
1346
|
}
|
|
1234
1347
|
to {
|
|
1235
1348
|
opacity: 1;
|
|
1236
1349
|
transform: translateX(-50%) translateY(0);
|
|
1350
|
+
scale: 1;
|
|
1237
1351
|
}
|
|
1238
1352
|
}
|
|
1239
1353
|
` }),
|
|
@@ -1241,17 +1355,16 @@ function UsageBanner({
|
|
|
1241
1355
|
"div",
|
|
1242
1356
|
{
|
|
1243
1357
|
style: {
|
|
1244
|
-
|
|
1245
|
-
alignItems: "flex-start",
|
|
1246
|
-
gap: "14px",
|
|
1247
|
-
borderRadius: "16px",
|
|
1358
|
+
borderRadius: "12px",
|
|
1248
1359
|
border: `1px solid ${themeConfig.border}`,
|
|
1249
1360
|
background: themeConfig.bg,
|
|
1250
|
-
padding: "
|
|
1251
|
-
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)",
|
|
1252
1363
|
position: "relative",
|
|
1253
|
-
backdropFilter: "blur(
|
|
1254
|
-
WebkitBackdropFilter: "blur(
|
|
1364
|
+
backdropFilter: "blur(12px)",
|
|
1365
|
+
WebkitBackdropFilter: "blur(12px)",
|
|
1366
|
+
boxSizing: "border-box",
|
|
1367
|
+
overflow: "hidden"
|
|
1255
1368
|
},
|
|
1256
1369
|
children: [
|
|
1257
1370
|
onClose && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
@@ -1260,35 +1373,23 @@ function UsageBanner({
|
|
|
1260
1373
|
onClick: onClose,
|
|
1261
1374
|
style: {
|
|
1262
1375
|
position: "absolute",
|
|
1263
|
-
top: "
|
|
1264
|
-
right: "
|
|
1265
|
-
background: "rgba(255, 255, 255, 0.
|
|
1376
|
+
top: "8px",
|
|
1377
|
+
right: "8px",
|
|
1378
|
+
background: "rgba(255, 255, 255, 0.9)",
|
|
1266
1379
|
border: "none",
|
|
1267
1380
|
color: themeConfig.text,
|
|
1268
1381
|
cursor: "pointer",
|
|
1269
|
-
fontSize: "
|
|
1382
|
+
fontSize: "16px",
|
|
1270
1383
|
lineHeight: "1",
|
|
1271
|
-
padding: "
|
|
1272
|
-
borderRadius: "
|
|
1273
|
-
|
|
1274
|
-
|
|
1384
|
+
padding: "4px",
|
|
1385
|
+
borderRadius: "4px",
|
|
1386
|
+
width: "20px",
|
|
1387
|
+
height: "20px",
|
|
1275
1388
|
display: "flex",
|
|
1276
1389
|
alignItems: "center",
|
|
1277
|
-
justifyContent: "center"
|
|
1278
|
-
width: "28px",
|
|
1279
|
-
height: "28px"
|
|
1390
|
+
justifyContent: "center"
|
|
1280
1391
|
},
|
|
1281
1392
|
title: "Close",
|
|
1282
|
-
onMouseOver: (e) => {
|
|
1283
|
-
e.currentTarget.style.opacity = "1";
|
|
1284
|
-
e.currentTarget.style.background = "rgba(255, 255, 255, 1)";
|
|
1285
|
-
e.currentTarget.style.transform = "scale(1.05)";
|
|
1286
|
-
},
|
|
1287
|
-
onMouseOut: (e) => {
|
|
1288
|
-
e.currentTarget.style.opacity = "0.7";
|
|
1289
|
-
e.currentTarget.style.background = "rgba(255, 255, 255, 0.8)";
|
|
1290
|
-
e.currentTarget.style.transform = "scale(1)";
|
|
1291
|
-
},
|
|
1292
1393
|
children: "\xD7"
|
|
1293
1394
|
}
|
|
1294
1395
|
),
|
|
@@ -1296,106 +1397,92 @@ function UsageBanner({
|
|
|
1296
1397
|
"div",
|
|
1297
1398
|
{
|
|
1298
1399
|
style: {
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
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"
|
|
1308
1413
|
},
|
|
1309
|
-
children:
|
|
1414
|
+
children: cleanMessage
|
|
1310
1415
|
}
|
|
1311
1416
|
),
|
|
1312
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
{
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
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
|
-
onMouseOver: (e) => {
|
|
1383
|
-
e.currentTarget.style.backgroundColor = themeConfig.primaryBtnHover;
|
|
1384
|
-
e.currentTarget.style.transform = "translateY(-1px)";
|
|
1385
|
-
e.currentTarget.style.boxShadow = "0 6px 16px rgba(0, 0, 0, 0.2)";
|
|
1386
|
-
},
|
|
1387
|
-
onMouseOut: (e) => {
|
|
1388
|
-
e.currentTarget.style.backgroundColor = themeConfig.primaryBtn;
|
|
1389
|
-
e.currentTarget.style.transform = "translateY(0)";
|
|
1390
|
-
e.currentTarget.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.15)";
|
|
1391
|
-
},
|
|
1392
|
-
children: actions.primary.label
|
|
1393
|
-
}
|
|
1394
|
-
)
|
|
1395
|
-
]
|
|
1396
|
-
}
|
|
1397
|
-
)
|
|
1398
|
-
] })
|
|
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
|
+
)
|
|
1399
1486
|
]
|
|
1400
1487
|
}
|
|
1401
1488
|
)
|
|
@@ -1811,7 +1898,8 @@ ${nonDocumentStrings}`;
|
|
|
1811
1898
|
publicApiKey: copilotApiConfig.publicApiKey,
|
|
1812
1899
|
headers,
|
|
1813
1900
|
credentials: copilotApiConfig.credentials,
|
|
1814
|
-
showDevConsole: (_b = props.showDevConsole) != null ? _b : false
|
|
1901
|
+
showDevConsole: (_b = props.showDevConsole) != null ? _b : false,
|
|
1902
|
+
onTrace: props.onTrace
|
|
1815
1903
|
});
|
|
1816
1904
|
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react10.useState)({});
|
|
1817
1905
|
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
@@ -1901,6 +1989,7 @@ ${nonDocumentStrings}`;
|
|
|
1901
1989
|
const removeLangGraphInterruptAction = (0, import_react10.useCallback)(() => {
|
|
1902
1990
|
setLangGraphInterruptAction(null);
|
|
1903
1991
|
}, []);
|
|
1992
|
+
const memoizedChildren = (0, import_react10.useMemo)(() => children, [children]);
|
|
1904
1993
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1905
1994
|
CopilotContext.Provider,
|
|
1906
1995
|
{
|
|
@@ -1953,9 +2042,10 @@ ${nonDocumentStrings}`;
|
|
|
1953
2042
|
setExtensions,
|
|
1954
2043
|
langGraphInterruptAction,
|
|
1955
2044
|
setLangGraphInterruptAction,
|
|
1956
|
-
removeLangGraphInterruptAction
|
|
2045
|
+
removeLangGraphInterruptAction,
|
|
2046
|
+
onTrace: props.onTrace
|
|
1957
2047
|
},
|
|
1958
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotMessages, { children })
|
|
2048
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotMessages, { children: memoizedChildren })
|
|
1959
2049
|
}
|
|
1960
2050
|
);
|
|
1961
2051
|
}
|
|
@@ -2064,6 +2154,35 @@ function useChat(options) {
|
|
|
2064
2154
|
} = options;
|
|
2065
2155
|
const runChatCompletionRef = (0, import_react11.useRef)();
|
|
2066
2156
|
const addErrorToast = useErrorToast();
|
|
2157
|
+
const { setBannerError } = useToast();
|
|
2158
|
+
const { onTrace } = useCopilotContext();
|
|
2159
|
+
const traceUIError = (error, originalError) => __async(this, null, function* () {
|
|
2160
|
+
if (!onTrace || !(copilotConfig == null ? void 0 : copilotConfig.publicApiKey))
|
|
2161
|
+
return;
|
|
2162
|
+
try {
|
|
2163
|
+
const traceEvent = {
|
|
2164
|
+
type: "error",
|
|
2165
|
+
timestamp: Date.now(),
|
|
2166
|
+
context: {
|
|
2167
|
+
source: "ui",
|
|
2168
|
+
request: {
|
|
2169
|
+
operation: "useChatCompletion",
|
|
2170
|
+
url: copilotConfig.chatApiEndpoint,
|
|
2171
|
+
startTime: Date.now()
|
|
2172
|
+
},
|
|
2173
|
+
technical: {
|
|
2174
|
+
environment: "browser",
|
|
2175
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
2176
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
2177
|
+
}
|
|
2178
|
+
},
|
|
2179
|
+
error
|
|
2180
|
+
};
|
|
2181
|
+
yield onTrace(traceEvent);
|
|
2182
|
+
} catch (traceError) {
|
|
2183
|
+
console.error("Error in use-chat onTrace handler:", traceError);
|
|
2184
|
+
}
|
|
2185
|
+
});
|
|
2067
2186
|
const agentSessionRef = (0, import_react11.useRef)(agentSession);
|
|
2068
2187
|
agentSessionRef.current = agentSession;
|
|
2069
2188
|
const runIdRef = (0, import_react11.useRef)(runId);
|
|
@@ -2083,7 +2202,7 @@ function useChat(options) {
|
|
|
2083
2202
|
const pendingAppendsRef = (0, import_react11.useRef)([]);
|
|
2084
2203
|
const runChatCompletion = useAsyncCallback(
|
|
2085
2204
|
(previousMessages) => __async(this, null, function* () {
|
|
2086
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
2205
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
2087
2206
|
setIsLoading(true);
|
|
2088
2207
|
const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
|
|
2089
2208
|
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) {
|
|
@@ -2215,20 +2334,53 @@ function useChat(options) {
|
|
|
2215
2334
|
messages2 = (0, import_runtime_client_gql6.convertGqlOutputToMessages)(
|
|
2216
2335
|
(0, import_runtime_client_gql6.filterAdjacentAgentStateMessages)(rawMessagesResponse)
|
|
2217
2336
|
);
|
|
2218
|
-
if (messages2.length === 0) {
|
|
2219
|
-
continue;
|
|
2220
|
-
}
|
|
2221
2337
|
newMessages = [];
|
|
2222
2338
|
if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
2339
|
+
const guardrailsReason = ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || "";
|
|
2223
2340
|
newMessages = [
|
|
2224
2341
|
new import_runtime_client_gql6.TextMessage({
|
|
2225
2342
|
role: import_runtime_client_gql6.MessageRole.Assistant,
|
|
2226
|
-
content:
|
|
2343
|
+
content: guardrailsReason
|
|
2227
2344
|
})
|
|
2228
2345
|
];
|
|
2346
|
+
const guardrailsError = new import_shared12.CopilotKitError({
|
|
2347
|
+
message: `Guardrails validation failed: ${guardrailsReason}`,
|
|
2348
|
+
code: import_shared12.CopilotKitErrorCode.MISUSE
|
|
2349
|
+
});
|
|
2350
|
+
yield traceUIError(guardrailsError, {
|
|
2351
|
+
statusReason: value.generateCopilotResponse.status.reason,
|
|
2352
|
+
statusDetails: value.generateCopilotResponse.status.details
|
|
2353
|
+
});
|
|
2229
2354
|
setMessages([...previousMessages, ...newMessages]);
|
|
2230
2355
|
break;
|
|
2231
|
-
}
|
|
2356
|
+
}
|
|
2357
|
+
if (((_m = value.generateCopilotResponse.status) == null ? void 0 : _m.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "UNKNOWN_ERROR") {
|
|
2358
|
+
const errorMessage = ((_n = value.generateCopilotResponse.status.details) == null ? void 0 : _n.description) || "An unknown error occurred";
|
|
2359
|
+
const statusDetails = value.generateCopilotResponse.status.details;
|
|
2360
|
+
const originalError = (statusDetails == null ? void 0 : statusDetails.originalError) || (statusDetails == null ? void 0 : statusDetails.error);
|
|
2361
|
+
const originalCode = (originalError == null ? void 0 : originalError.code) || ((_o = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _o.code);
|
|
2362
|
+
const originalSeverity = (originalError == null ? void 0 : originalError.severity) || ((_p = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _p.severity);
|
|
2363
|
+
const originalVisibility = (originalError == null ? void 0 : originalError.visibility) || ((_q = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _q.visibility);
|
|
2364
|
+
let errorCode = import_shared12.CopilotKitErrorCode.NETWORK_ERROR;
|
|
2365
|
+
if (originalCode && Object.values(import_shared12.CopilotKitErrorCode).includes(originalCode)) {
|
|
2366
|
+
errorCode = originalCode;
|
|
2367
|
+
}
|
|
2368
|
+
const structuredError = new import_shared12.CopilotKitError({
|
|
2369
|
+
message: errorMessage,
|
|
2370
|
+
code: errorCode,
|
|
2371
|
+
severity: originalSeverity,
|
|
2372
|
+
visibility: originalVisibility
|
|
2373
|
+
});
|
|
2374
|
+
setBannerError(structuredError);
|
|
2375
|
+
yield traceUIError(structuredError, {
|
|
2376
|
+
statusReason: value.generateCopilotResponse.status.reason,
|
|
2377
|
+
statusDetails: value.generateCopilotResponse.status.details,
|
|
2378
|
+
originalErrorCode: originalCode,
|
|
2379
|
+
preservedStructure: !!originalCode
|
|
2380
|
+
});
|
|
2381
|
+
setIsLoading(false);
|
|
2382
|
+
break;
|
|
2383
|
+
} else if (messages2.length > 0) {
|
|
2232
2384
|
newMessages = [...messages2];
|
|
2233
2385
|
for (const message of messages2) {
|
|
2234
2386
|
if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
|
|
@@ -2359,11 +2511,11 @@ function useChat(options) {
|
|
|
2359
2511
|
followUp !== false && // and we executed an action
|
|
2360
2512
|
(didExecuteAction || // the last message is a server side result
|
|
2361
2513
|
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
2362
|
-
!((
|
|
2514
|
+
!((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)
|
|
2363
2515
|
) {
|
|
2364
2516
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
2365
2517
|
return yield runChatCompletionRef.current(finalMessages);
|
|
2366
|
-
} else if ((
|
|
2518
|
+
} else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
|
|
2367
2519
|
const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
|
|
2368
2520
|
if (message.isActionExecutionMessage()) {
|
|
2369
2521
|
return finalMessages.find(
|
|
@@ -2374,7 +2526,7 @@ function useChat(options) {
|
|
|
2374
2526
|
});
|
|
2375
2527
|
const repairedMessageIds = repairedMessages.map((message) => message.id);
|
|
2376
2528
|
setMessages(repairedMessages);
|
|
2377
|
-
if ((
|
|
2529
|
+
if ((_t = agentSessionRef.current) == null ? void 0 : _t.nodeName) {
|
|
2378
2530
|
setAgentSession({
|
|
2379
2531
|
threadId: agentSessionRef.current.threadId,
|
|
2380
2532
|
agentName: agentSessionRef.current.agentName,
|
|
@@ -3070,6 +3222,9 @@ function useCoAgent(options) {
|
|
|
3070
3222
|
threadId,
|
|
3071
3223
|
agentName: name
|
|
3072
3224
|
});
|
|
3225
|
+
if (result.error) {
|
|
3226
|
+
return;
|
|
3227
|
+
}
|
|
3073
3228
|
const newState = (_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.state;
|
|
3074
3229
|
if (newState === lastLoadedState.current)
|
|
3075
3230
|
return;
|