@copilotkit/react-core 1.9.2-next.8 → 1.9.2-next.9

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.
Files changed (99) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/{chunk-CCESTGAM.mjs → chunk-3OQM3NEK.mjs} +2 -2
  3. package/dist/{chunk-T4ZKC4X4.mjs → chunk-3YHYWAHK.mjs} +2 -2
  4. package/dist/{chunk-ISYBUDL4.mjs → chunk-55QZ2SVJ.mjs} +4 -5
  5. package/dist/chunk-55QZ2SVJ.mjs.map +1 -0
  6. package/dist/chunk-57K2ZJ5F.mjs +348 -0
  7. package/dist/chunk-57K2ZJ5F.mjs.map +1 -0
  8. package/dist/{chunk-ZHEEHGLS.mjs → chunk-ADIITPD2.mjs} +8 -5
  9. package/dist/{chunk-ZHEEHGLS.mjs.map → chunk-ADIITPD2.mjs.map} +1 -1
  10. package/dist/{chunk-S4BOATBG.mjs → chunk-EF5BNM34.mjs} +2 -2
  11. package/dist/{chunk-I4JPQECN.mjs → chunk-EXU7GWLC.mjs} +4 -4
  12. package/dist/{chunk-7G6RR4HE.mjs → chunk-FXK6RQIN.mjs} +2 -2
  13. package/dist/{chunk-JXF732XG.mjs → chunk-G7LYGERN.mjs} +80 -13
  14. package/dist/chunk-G7LYGERN.mjs.map +1 -0
  15. package/dist/{chunk-VJCHRQ7Q.mjs → chunk-JDEWNLNP.mjs} +37 -4
  16. package/dist/chunk-JDEWNLNP.mjs.map +1 -0
  17. package/dist/{chunk-JHIZ5HAI.mjs → chunk-NQVCZQ5T.mjs} +3 -3
  18. package/dist/{chunk-VF6UPRKM.mjs → chunk-OF4SZTLL.mjs} +3 -3
  19. package/dist/{chunk-QQZLIEXK.mjs → chunk-SJJNFYGQ.mjs} +3 -3
  20. package/dist/{chunk-RN3ZRHI7.mjs → chunk-WOGURSAL.mjs} +5 -5
  21. package/dist/chunk-YAF2LATQ.mjs +310 -0
  22. package/dist/chunk-YAF2LATQ.mjs.map +1 -0
  23. package/dist/components/copilot-provider/copilot-messages.js +35 -2
  24. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  25. package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
  26. package/dist/components/copilot-provider/copilotkit.js +289 -234
  27. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  28. package/dist/components/copilot-provider/copilotkit.mjs +7 -7
  29. package/dist/components/copilot-provider/index.js +289 -234
  30. package/dist/components/copilot-provider/index.js.map +1 -1
  31. package/dist/components/copilot-provider/index.mjs +7 -7
  32. package/dist/components/error-boundary/error-boundary.js +135 -146
  33. package/dist/components/error-boundary/error-boundary.js.map +1 -1
  34. package/dist/components/error-boundary/error-boundary.mjs +4 -4
  35. package/dist/components/error-boundary/error-utils.js.map +1 -1
  36. package/dist/components/error-boundary/error-utils.mjs +2 -2
  37. package/dist/components/index.js +289 -234
  38. package/dist/components/index.js.map +1 -1
  39. package/dist/components/index.mjs +7 -7
  40. package/dist/components/toast/toast-provider.js +118 -85
  41. package/dist/components/toast/toast-provider.js.map +1 -1
  42. package/dist/components/toast/toast-provider.mjs +1 -1
  43. package/dist/components/usage-banner.js +135 -146
  44. package/dist/components/usage-banner.js.map +1 -1
  45. package/dist/components/usage-banner.mjs +1 -1
  46. package/dist/hooks/index.js +75 -10
  47. package/dist/hooks/index.js.map +1 -1
  48. package/dist/hooks/index.mjs +14 -14
  49. package/dist/hooks/use-chat.js +72 -10
  50. package/dist/hooks/use-chat.js.map +1 -1
  51. package/dist/hooks/use-chat.mjs +4 -4
  52. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  53. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  54. package/dist/hooks/use-coagent.js +75 -10
  55. package/dist/hooks/use-coagent.js.map +1 -1
  56. package/dist/hooks/use-coagent.mjs +10 -10
  57. package/dist/hooks/use-copilot-action.js.map +1 -1
  58. package/dist/hooks/use-copilot-action.mjs +3 -3
  59. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  60. package/dist/hooks/use-copilot-authenticated-action.mjs +4 -4
  61. package/dist/hooks/use-copilot-chat.js +72 -10
  62. package/dist/hooks/use-copilot-chat.js.map +1 -1
  63. package/dist/hooks/use-copilot-chat.mjs +9 -9
  64. package/dist/hooks/use-copilot-runtime-client.js +1 -1
  65. package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
  66. package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
  67. package/dist/hooks/use-langgraph-interrupt.js +72 -10
  68. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  69. package/dist/hooks/use-langgraph-interrupt.mjs +10 -10
  70. package/dist/index.js +363 -243
  71. package/dist/index.js.map +1 -1
  72. package/dist/index.mjs +15 -15
  73. package/dist/lib/copilot-task.mjs +8 -8
  74. package/dist/lib/index.mjs +8 -8
  75. package/dist/utils/extract.mjs +7 -7
  76. package/dist/utils/index.mjs +7 -7
  77. package/package.json +3 -3
  78. package/src/components/copilot-provider/copilot-messages.tsx +42 -3
  79. package/src/components/toast/toast-provider.tsx +49 -24
  80. package/src/components/usage-banner.tsx +144 -147
  81. package/src/hooks/use-chat.ts +106 -6
  82. package/src/hooks/use-coagent.ts +5 -0
  83. package/src/hooks/use-copilot-runtime-client.ts +2 -39
  84. package/dist/chunk-HD2GE3DK.mjs +0 -359
  85. package/dist/chunk-HD2GE3DK.mjs.map +0 -1
  86. package/dist/chunk-ISYBUDL4.mjs.map +0 -1
  87. package/dist/chunk-JXF732XG.mjs.map +0 -1
  88. package/dist/chunk-VJCHRQ7Q.mjs.map +0 -1
  89. package/dist/chunk-VRXANACV.mjs +0 -277
  90. package/dist/chunk-VRXANACV.mjs.map +0 -1
  91. /package/dist/{chunk-CCESTGAM.mjs.map → chunk-3OQM3NEK.mjs.map} +0 -0
  92. /package/dist/{chunk-T4ZKC4X4.mjs.map → chunk-3YHYWAHK.mjs.map} +0 -0
  93. /package/dist/{chunk-S4BOATBG.mjs.map → chunk-EF5BNM34.mjs.map} +0 -0
  94. /package/dist/{chunk-I4JPQECN.mjs.map → chunk-EXU7GWLC.mjs.map} +0 -0
  95. /package/dist/{chunk-7G6RR4HE.mjs.map → chunk-FXK6RQIN.mjs.map} +0 -0
  96. /package/dist/{chunk-JHIZ5HAI.mjs.map → chunk-NQVCZQ5T.mjs.map} +0 -0
  97. /package/dist/{chunk-VF6UPRKM.mjs.map → chunk-OF4SZTLL.mjs.map} +0 -0
  98. /package/dist/{chunk-QQZLIEXK.mjs.map → chunk-SJJNFYGQ.mjs.map} +0 -0
  99. /package/dist/{chunk-RN3ZRHI7.mjs.map → chunk-WOGURSAL.mjs.map} +0 -0
package/dist/index.js CHANGED
@@ -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: "10px 14px",
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: "500px",
556
- minWidth: "350px"
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)("div", { style: { display: "flex", alignItems: "center", gap: "8px", flex: 1 }, children: [
569
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
570
- "div",
571
- {
572
- style: {
573
- width: "12px",
574
- height: "12px",
575
- borderRadius: "50%",
576
- backgroundColor: colors.border,
577
- flexShrink: 0
578
- }
579
- }
580
- ),
581
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "10px", flex: 1 }, children: [
582
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
583
- "div",
584
- {
585
- style: {
586
- color: colors.text,
587
- lineHeight: "1.4",
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
- if (!url)
625
- return null;
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
- background: colors.border,
632
- color: "white",
633
- border: "none",
634
- borderRadius: "5px",
635
- padding: "4px 10px",
636
- fontSize: "11px",
637
- fontWeight: "500",
638
- cursor: "pointer",
639
- transition: "all 0.2s ease",
640
- flexShrink: 0
641
- },
642
- onMouseEnter: (e) => {
643
- e.currentTarget.style.opacity = "0.9";
644
- e.currentTarget.style.transform = "translateY(-1px)";
645
- },
646
- onMouseLeave: (e) => {
647
- e.currentTarget.style.opacity = "1";
648
- e.currentTarget.style.transform = "translateY(0)";
597
+ display: "flex",
598
+ alignItems: "center",
599
+ gap: "10px",
600
+ flex: 1,
601
+ minWidth: 0
649
602
  },
650
- children: buttonText
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, onTrace, copilotApiConfig } = useCopilotContext();
709
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
+ );
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)
@@ -844,7 +910,7 @@ var useCopilotRuntimeClient = (options) => {
844
910
  startTime: Date.now()
845
911
  },
846
912
  technical: {
847
- environment: process.env.NODE_ENV,
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
  }
@@ -1144,8 +1210,8 @@ var defaultIcons = {
1144
1210
  "svg",
1145
1211
  {
1146
1212
  viewBox: "0 0 24 24",
1147
- width: "18",
1148
- height: "18",
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: "18",
1166
- height: "18",
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: "18",
1184
- height: "18",
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
- const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
1210
- const matches = Array.from(rawMessage.matchAll(linkRegex));
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.";
1277
+ }
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.";
1214
1283
  }
1215
- return rawMessage;
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: "linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%)",
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: "linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%)",
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: "linear-gradient(135deg, #fef2f2 0%, #fecaca 100%)",
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: "20px",
1331
+ bottom: "24px",
1252
1332
  left: "50%",
1253
1333
  transform: "translateX(-50%)",
1254
- maxWidth: "min(95vw, 680px)",
1255
- width: "100%",
1334
+ width: "400px",
1335
+ maxWidth: "90vw",
1256
1336
  zIndex: 1e4,
1257
- animation: "bannerSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1)"
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(10px);
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
- display: "flex",
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: "18px 20px",
1283
- boxShadow: "0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1)",
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(10px)",
1286
- WebkitBackdropFilter: "blur(10px)"
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: "12px",
1296
- right: "12px",
1297
- background: "rgba(255, 255, 255, 0.8)",
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: "18px",
1382
+ fontSize: "16px",
1302
1383
  lineHeight: "1",
1303
- padding: "6px",
1304
- borderRadius: "8px",
1305
- opacity: 0.7,
1306
- transition: "all 0.2s ease",
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
- color: themeConfig.icon,
1332
- flexShrink: 0,
1333
- marginTop: "1px",
1334
- padding: "6px",
1335
- borderRadius: "10px",
1336
- background: "rgba(255, 255, 255, 0.7)",
1337
- display: "flex",
1338
- alignItems: "center",
1339
- justifyContent: "center"
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: Icon
1414
+ children: cleanMessage
1342
1415
  }
1343
1416
  ),
1344
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { flex: 1, paddingRight: onClose ? "40px" : "0" }, children: [
1345
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1346
- "div",
1347
- {
1348
- style: {
1349
- fontSize: "15px",
1350
- fontWeight: 600,
1351
- color: themeConfig.text,
1352
- lineHeight: "1.5",
1353
- marginBottom: actions ? "12px" : "0",
1354
- fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1355
- },
1356
- children: cleanMessage
1357
- }
1358
- ),
1359
- actions && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1360
- "div",
1361
- {
1362
- style: {
1363
- display: "flex",
1364
- gap: "10px",
1365
- flexWrap: "wrap"
1366
- },
1367
- children: [
1368
- actions.secondary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1369
- "button",
1370
- {
1371
- onClick: actions.secondary.onClick,
1372
- style: {
1373
- borderRadius: "10px",
1374
- padding: "8px 16px",
1375
- fontSize: "14px",
1376
- fontWeight: 500,
1377
- color: themeConfig.text,
1378
- backgroundColor: "rgba(255, 255, 255, 0.8)",
1379
- border: `1.5px solid ${themeConfig.border}`,
1380
- cursor: "pointer",
1381
- transition: "all 0.2s ease",
1382
- fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1383
- },
1384
- onMouseOver: (e) => {
1385
- e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 1)";
1386
- e.currentTarget.style.transform = "translateY(-1px)";
1387
- e.currentTarget.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.15)";
1388
- },
1389
- onMouseOut: (e) => {
1390
- e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 0.8)";
1391
- e.currentTarget.style.transform = "translateY(0)";
1392
- e.currentTarget.style.boxShadow = "none";
1393
- },
1394
- children: actions.secondary.label
1395
- }
1396
- ),
1397
- actions.primary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1398
- "button",
1399
- {
1400
- onClick: actions.primary.onClick,
1401
- style: {
1402
- borderRadius: "10px",
1403
- padding: "8px 16px",
1404
- fontSize: "14px",
1405
- fontWeight: 600,
1406
- color: "#fff",
1407
- backgroundColor: themeConfig.primaryBtn,
1408
- border: "none",
1409
- cursor: "pointer",
1410
- transition: "all 0.2s ease",
1411
- boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
1412
- fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
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
  )
@@ -2099,6 +2154,35 @@ function useChat(options) {
2099
2154
  } = options;
2100
2155
  const runChatCompletionRef = (0, import_react11.useRef)();
2101
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
+ });
2102
2186
  const agentSessionRef = (0, import_react11.useRef)(agentSession);
2103
2187
  agentSessionRef.current = agentSession;
2104
2188
  const runIdRef = (0, import_react11.useRef)(runId);
@@ -2118,7 +2202,7 @@ function useChat(options) {
2118
2202
  const pendingAppendsRef = (0, import_react11.useRef)([]);
2119
2203
  const runChatCompletion = useAsyncCallback(
2120
2204
  (previousMessages) => __async(this, null, function* () {
2121
- 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;
2122
2206
  setIsLoading(true);
2123
2207
  const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
2124
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) {
@@ -2250,20 +2334,53 @@ function useChat(options) {
2250
2334
  messages2 = (0, import_runtime_client_gql6.convertGqlOutputToMessages)(
2251
2335
  (0, import_runtime_client_gql6.filterAdjacentAgentStateMessages)(rawMessagesResponse)
2252
2336
  );
2253
- if (messages2.length === 0) {
2254
- continue;
2255
- }
2256
2337
  newMessages = [];
2257
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) || "";
2258
2340
  newMessages = [
2259
2341
  new import_runtime_client_gql6.TextMessage({
2260
2342
  role: import_runtime_client_gql6.MessageRole.Assistant,
2261
- content: ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || ""
2343
+ content: guardrailsReason
2262
2344
  })
2263
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
+ });
2264
2354
  setMessages([...previousMessages, ...newMessages]);
2265
2355
  break;
2266
- } else {
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) {
2267
2384
  newMessages = [...messages2];
2268
2385
  for (const message of messages2) {
2269
2386
  if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
@@ -2394,11 +2511,11 @@ function useChat(options) {
2394
2511
  followUp !== false && // and we executed an action
2395
2512
  (didExecuteAction || // the last message is a server side result
2396
2513
  !isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
2397
- !((_m = chatAbortControllerRef.current) == null ? void 0 : _m.signal.aborted)
2514
+ !((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)
2398
2515
  ) {
2399
2516
  yield new Promise((resolve) => setTimeout(resolve, 10));
2400
2517
  return yield runChatCompletionRef.current(finalMessages);
2401
- } else if ((_n = chatAbortControllerRef.current) == null ? void 0 : _n.signal.aborted) {
2518
+ } else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
2402
2519
  const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
2403
2520
  if (message.isActionExecutionMessage()) {
2404
2521
  return finalMessages.find(
@@ -2409,7 +2526,7 @@ function useChat(options) {
2409
2526
  });
2410
2527
  const repairedMessageIds = repairedMessages.map((message) => message.id);
2411
2528
  setMessages(repairedMessages);
2412
- if ((_o = agentSessionRef.current) == null ? void 0 : _o.nodeName) {
2529
+ if ((_t = agentSessionRef.current) == null ? void 0 : _t.nodeName) {
2413
2530
  setAgentSession({
2414
2531
  threadId: agentSessionRef.current.threadId,
2415
2532
  agentName: agentSessionRef.current.agentName,
@@ -3105,6 +3222,9 @@ function useCoAgent(options) {
3105
3222
  threadId,
3106
3223
  agentName: name
3107
3224
  });
3225
+ if (result.error) {
3226
+ return;
3227
+ }
3108
3228
  const newState = (_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.state;
3109
3229
  if (newState === lastLoadedState.current)
3110
3230
  return;