@copilotkit/react-core 1.9.2-next.1 → 1.9.2-next.11

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 (168) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/dist/{chunk-CCESTGAM.mjs → chunk-3OQM3NEK.mjs} +2 -2
  3. package/dist/{chunk-2FW7HH6W.mjs → chunk-3YHYWAHK.mjs} +3 -3
  4. package/dist/{chunk-RUY6MLHA.mjs → chunk-55QZ2SVJ.mjs} +36 -6
  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-UIT6QMUJ.mjs → chunk-7BYXCFPB.mjs} +5 -5
  9. package/dist/{chunk-HJP2RX5R.mjs → chunk-AFDL5JI3.mjs} +82 -15
  10. package/dist/chunk-AFDL5JI3.mjs.map +1 -0
  11. package/dist/{chunk-SGLWMQ2J.mjs → chunk-BEDNUHSA.mjs} +15 -12
  12. package/dist/chunk-BEDNUHSA.mjs.map +1 -0
  13. package/dist/{chunk-Q5D5XQFA.mjs → chunk-CMQV4XNY.mjs} +2 -2
  14. package/dist/{chunk-LDACFA2B.mjs → chunk-EF5BNM34.mjs} +3 -3
  15. package/dist/{chunk-UHQMV2CE.mjs → chunk-ERXWDCY6.mjs} +2 -2
  16. package/dist/{chunk-NNSXCFQO.mjs → chunk-JDEWNLNP.mjs} +41 -7
  17. package/dist/chunk-JDEWNLNP.mjs.map +1 -0
  18. package/dist/{chunk-C6F6EQNA.mjs → chunk-JPMIAGI6.mjs} +2 -2
  19. package/dist/{chunk-T42PN5VN.mjs → chunk-NQVCZQ5T.mjs} +4 -4
  20. package/dist/{chunk-YZDRMIOM.mjs → chunk-OIPDW3UR.mjs} +4 -4
  21. package/dist/{chunk-XY5BN4HZ.mjs → chunk-RYREGU4E.mjs} +11 -8
  22. package/dist/{chunk-XY5BN4HZ.mjs.map → chunk-RYREGU4E.mjs.map} +1 -1
  23. package/dist/{chunk-QQZLIEXK.mjs → chunk-SJJNFYGQ.mjs} +3 -3
  24. package/dist/{chunk-YDENFEKA.mjs → chunk-U4LIYN3I.mjs} +2 -2
  25. package/dist/{chunk-LZDDYZEY.mjs → chunk-UBNRUXEK.mjs} +2 -2
  26. package/dist/{chunk-6KGEF242.mjs → chunk-XFOTNHYA.mjs} +3 -2
  27. package/dist/chunk-XFOTNHYA.mjs.map +1 -0
  28. package/dist/chunk-YAF2LATQ.mjs +310 -0
  29. package/dist/chunk-YAF2LATQ.mjs.map +1 -0
  30. package/dist/components/copilot-provider/copilot-messages.js +39 -4
  31. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  32. package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
  33. package/dist/components/copilot-provider/copilotkit-props.d.ts +21 -2
  34. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  35. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  36. package/dist/components/copilot-provider/copilotkit.js +330 -240
  37. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  38. package/dist/components/copilot-provider/copilotkit.mjs +10 -10
  39. package/dist/components/copilot-provider/index.d.ts +1 -1
  40. package/dist/components/copilot-provider/index.js +330 -240
  41. package/dist/components/copilot-provider/index.js.map +1 -1
  42. package/dist/components/copilot-provider/index.mjs +10 -10
  43. package/dist/components/error-boundary/error-boundary.js +135 -146
  44. package/dist/components/error-boundary/error-boundary.js.map +1 -1
  45. package/dist/components/error-boundary/error-boundary.mjs +4 -4
  46. package/dist/components/error-boundary/error-utils.js.map +1 -1
  47. package/dist/components/error-boundary/error-utils.mjs +2 -2
  48. package/dist/components/index.d.ts +1 -1
  49. package/dist/components/index.js +330 -240
  50. package/dist/components/index.js.map +1 -1
  51. package/dist/components/index.mjs +10 -10
  52. package/dist/components/toast/toast-provider.js +118 -85
  53. package/dist/components/toast/toast-provider.js.map +1 -1
  54. package/dist/components/toast/toast-provider.mjs +1 -1
  55. package/dist/components/usage-banner.js +135 -146
  56. package/dist/components/usage-banner.js.map +1 -1
  57. package/dist/components/usage-banner.mjs +1 -1
  58. package/dist/context/copilot-context.d.ts +1 -1
  59. package/dist/context/copilot-context.js +2 -1
  60. package/dist/context/copilot-context.js.map +1 -1
  61. package/dist/context/copilot-context.mjs +1 -1
  62. package/dist/context/index.d.ts +1 -1
  63. package/dist/context/index.js +2 -1
  64. package/dist/context/index.js.map +1 -1
  65. package/dist/context/index.mjs +1 -1
  66. package/dist/{copilot-context-f9b2b4c3.d.ts → copilot-context-3da805ab.d.ts} +5 -1
  67. package/dist/hooks/index.d.ts +1 -1
  68. package/dist/hooks/index.js +108 -12
  69. package/dist/hooks/index.js.map +1 -1
  70. package/dist/hooks/index.mjs +32 -32
  71. package/dist/hooks/use-chat.d.ts +1 -1
  72. package/dist/hooks/use-chat.js +105 -12
  73. package/dist/hooks/use-chat.js.map +1 -1
  74. package/dist/hooks/use-chat.mjs +6 -6
  75. package/dist/hooks/use-coagent-state-render.js +2 -1
  76. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  77. package/dist/hooks/use-coagent-state-render.mjs +3 -3
  78. package/dist/hooks/use-coagent.d.ts +1 -1
  79. package/dist/hooks/use-coagent.js +108 -12
  80. package/dist/hooks/use-coagent.js.map +1 -1
  81. package/dist/hooks/use-coagent.mjs +14 -14
  82. package/dist/hooks/use-copilot-action.js +2 -1
  83. package/dist/hooks/use-copilot-action.js.map +1 -1
  84. package/dist/hooks/use-copilot-action.mjs +4 -4
  85. package/dist/hooks/use-copilot-additional-instructions.js +2 -1
  86. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
  87. package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
  88. package/dist/hooks/use-copilot-authenticated-action.js +2 -1
  89. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  90. package/dist/hooks/use-copilot-authenticated-action.mjs +5 -5
  91. package/dist/hooks/use-copilot-chat.d.ts +1 -1
  92. package/dist/hooks/use-copilot-chat.js +105 -12
  93. package/dist/hooks/use-copilot-chat.js.map +1 -1
  94. package/dist/hooks/use-copilot-chat.mjs +13 -13
  95. package/dist/hooks/use-copilot-readable.js +2 -1
  96. package/dist/hooks/use-copilot-readable.js.map +1 -1
  97. package/dist/hooks/use-copilot-readable.mjs +2 -2
  98. package/dist/hooks/use-copilot-runtime-client.d.ts +2 -0
  99. package/dist/hooks/use-copilot-runtime-client.js +52 -2
  100. package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
  101. package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
  102. package/dist/hooks/use-langgraph-interrupt-render.js +2 -1
  103. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  104. package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
  105. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  106. package/dist/hooks/use-langgraph-interrupt.js +105 -12
  107. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  108. package/dist/hooks/use-langgraph-interrupt.mjs +14 -14
  109. package/dist/hooks/use-make-copilot-document-readable.js +2 -1
  110. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  111. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  112. package/dist/index.d.ts +1 -1
  113. package/dist/index.js +404 -249
  114. package/dist/index.js.map +1 -1
  115. package/dist/index.mjs +33 -33
  116. package/dist/lib/copilot-task.d.ts +1 -1
  117. package/dist/lib/copilot-task.js.map +1 -1
  118. package/dist/lib/copilot-task.mjs +11 -11
  119. package/dist/lib/index.d.ts +1 -1
  120. package/dist/lib/index.js.map +1 -1
  121. package/dist/lib/index.mjs +11 -11
  122. package/dist/types/interrupt-action.d.ts +1 -1
  123. package/dist/utils/extract.d.ts +1 -1
  124. package/dist/utils/extract.js.map +1 -1
  125. package/dist/utils/extract.mjs +10 -10
  126. package/dist/utils/index.d.ts +1 -1
  127. package/dist/utils/index.js.map +1 -1
  128. package/dist/utils/index.mjs +10 -10
  129. package/jest.config.js +7 -3
  130. package/package.json +4 -3
  131. package/src/components/copilot-provider/__tests__/copilotkit-trace.test.tsx +75 -0
  132. package/src/components/copilot-provider/copilot-messages.tsx +46 -5
  133. package/src/components/copilot-provider/copilotkit-props.tsx +21 -0
  134. package/src/components/copilot-provider/copilotkit.tsx +5 -1
  135. package/src/components/toast/toast-provider.tsx +49 -24
  136. package/src/components/usage-banner.tsx +144 -147
  137. package/src/context/copilot-context.tsx +7 -1
  138. package/src/hooks/use-chat.ts +106 -6
  139. package/src/hooks/use-coagent.ts +5 -0
  140. package/src/hooks/use-copilot-runtime-client.ts +41 -39
  141. package/tsconfig.json +1 -8
  142. package/tsup.config.ts +6 -6
  143. package/dist/chunk-6KGEF242.mjs.map +0 -1
  144. package/dist/chunk-HD2GE3DK.mjs +0 -359
  145. package/dist/chunk-HD2GE3DK.mjs.map +0 -1
  146. package/dist/chunk-HJP2RX5R.mjs.map +0 -1
  147. package/dist/chunk-NNSXCFQO.mjs.map +0 -1
  148. package/dist/chunk-RUY6MLHA.mjs.map +0 -1
  149. package/dist/chunk-SGLWMQ2J.mjs.map +0 -1
  150. package/dist/chunk-VRXANACV.mjs +0 -277
  151. package/dist/chunk-VRXANACV.mjs.map +0 -1
  152. package/dist/utils/utils.test.d.ts +0 -2
  153. package/dist/utils/utils.test.js +0 -9
  154. package/dist/utils/utils.test.js.map +0 -1
  155. package/dist/utils/utils.test.mjs +0 -7
  156. package/dist/utils/utils.test.mjs.map +0 -1
  157. /package/dist/{chunk-CCESTGAM.mjs.map → chunk-3OQM3NEK.mjs.map} +0 -0
  158. /package/dist/{chunk-2FW7HH6W.mjs.map → chunk-3YHYWAHK.mjs.map} +0 -0
  159. /package/dist/{chunk-UIT6QMUJ.mjs.map → chunk-7BYXCFPB.mjs.map} +0 -0
  160. /package/dist/{chunk-Q5D5XQFA.mjs.map → chunk-CMQV4XNY.mjs.map} +0 -0
  161. /package/dist/{chunk-LDACFA2B.mjs.map → chunk-EF5BNM34.mjs.map} +0 -0
  162. /package/dist/{chunk-UHQMV2CE.mjs.map → chunk-ERXWDCY6.mjs.map} +0 -0
  163. /package/dist/{chunk-C6F6EQNA.mjs.map → chunk-JPMIAGI6.mjs.map} +0 -0
  164. /package/dist/{chunk-T42PN5VN.mjs.map → chunk-NQVCZQ5T.mjs.map} +0 -0
  165. /package/dist/{chunk-YZDRMIOM.mjs.map → chunk-OIPDW3UR.mjs.map} +0 -0
  166. /package/dist/{chunk-QQZLIEXK.mjs.map → chunk-SJJNFYGQ.mjs.map} +0 -0
  167. /package/dist/{chunk-YDENFEKA.mjs.map → chunk-U4LIYN3I.mjs.map} +0 -0
  168. /package/dist/{chunk-LZDDYZEY.mjs.map → chunk-UBNRUXEK.mjs.map} +0 -0
@@ -161,7 +161,8 @@ var emptyCopilotContext = {
161
161
  },
162
162
  langGraphInterruptAction: null,
163
163
  setLangGraphInterruptAction: () => null,
164
- removeLangGraphInterruptAction: () => null
164
+ removeLangGraphInterruptAction: () => null,
165
+ onTrace: void 0
165
166
  };
166
167
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
167
168
  function useCopilotContext() {
@@ -516,12 +517,14 @@ function ToastProvider({
516
517
  border: `1px solid ${colors.border}`,
517
518
  borderLeft: `4px solid ${colors.border}`,
518
519
  borderRadius: "8px",
519
- padding: "10px 14px",
520
+ padding: "12px 16px",
520
521
  fontSize: "13px",
521
522
  boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
522
523
  backdropFilter: "blur(8px)",
523
- maxWidth: "500px",
524
- minWidth: "350px"
524
+ maxWidth: "min(90vw, 700px)",
525
+ width: "100%",
526
+ boxSizing: "border-box",
527
+ overflow: "hidden"
525
528
  },
526
529
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
527
530
  "div",
@@ -533,94 +536,125 @@ function ToastProvider({
533
536
  gap: "10px"
534
537
  },
535
538
  children: [
536
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "8px", flex: 1 }, children: [
537
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
538
- "div",
539
- {
540
- style: {
541
- width: "12px",
542
- height: "12px",
543
- borderRadius: "50%",
544
- backgroundColor: colors.border,
545
- flexShrink: 0
546
- }
547
- }
548
- ),
549
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "10px", flex: 1 }, children: [
550
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
551
- "div",
552
- {
553
- style: {
554
- color: colors.text,
555
- lineHeight: "1.4",
556
- fontWeight: "400",
557
- fontSize: "13px",
558
- flex: 1,
559
- wordWrap: "break-word",
560
- overflowWrap: "break-word",
561
- hyphens: "auto"
562
- },
563
- children: (() => {
564
- const message = bannerError.message;
565
- const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
566
- const plainUrlRegex = /(https?:\/\/[^\s)]+)/g;
567
- let cleanMessage = message.replace(markdownLinkRegex, "").replace(plainUrlRegex, "").replace(/See more:\s*/g, "").replace(/\s+/g, " ").trim();
568
- if (cleanMessage.length > 120) {
569
- cleanMessage = cleanMessage.substring(0, 117) + "...";
539
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
540
+ "div",
541
+ {
542
+ style: {
543
+ display: "flex",
544
+ alignItems: "center",
545
+ gap: "8px",
546
+ flex: 1,
547
+ minWidth: 0
548
+ },
549
+ children: [
550
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
551
+ "div",
552
+ {
553
+ style: {
554
+ width: "12px",
555
+ height: "12px",
556
+ borderRadius: "50%",
557
+ backgroundColor: colors.border,
558
+ flexShrink: 0
570
559
  }
571
- return cleanMessage;
572
- })()
573
- }
574
- ),
575
- (() => {
576
- const message = bannerError.message;
577
- const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
578
- const plainUrlRegex = /(https?:\/\/[^\s)]+)/g;
579
- let url = null;
580
- let buttonText = "See More";
581
- const markdownMatch = markdownLinkRegex.exec(message);
582
- if (markdownMatch) {
583
- url = markdownMatch[2];
584
- buttonText = "See More";
585
- } else {
586
- const urlMatch = plainUrlRegex.exec(message);
587
- if (urlMatch) {
588
- url = urlMatch[0];
589
- buttonText = "See More";
590
560
  }
591
- }
592
- if (!url)
593
- return null;
594
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
595
- "button",
561
+ ),
562
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
563
+ "div",
596
564
  {
597
- onClick: () => window.open(url, "_blank", "noopener,noreferrer"),
598
565
  style: {
599
- background: colors.border,
600
- color: "white",
601
- border: "none",
602
- borderRadius: "5px",
603
- padding: "4px 10px",
604
- fontSize: "11px",
605
- fontWeight: "500",
606
- cursor: "pointer",
607
- transition: "all 0.2s ease",
608
- flexShrink: 0
609
- },
610
- onMouseEnter: (e) => {
611
- e.currentTarget.style.opacity = "0.9";
612
- e.currentTarget.style.transform = "translateY(-1px)";
566
+ display: "flex",
567
+ alignItems: "center",
568
+ gap: "10px",
569
+ flex: 1,
570
+ minWidth: 0
613
571
  },
614
- onMouseLeave: (e) => {
615
- e.currentTarget.style.opacity = "1";
616
- e.currentTarget.style.transform = "translateY(0)";
617
- },
618
- children: buttonText
572
+ children: [
573
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
574
+ "div",
575
+ {
576
+ style: {
577
+ color: colors.text,
578
+ lineHeight: "1.4",
579
+ fontWeight: "400",
580
+ fontSize: "13px",
581
+ flex: 1,
582
+ wordBreak: "break-all",
583
+ overflowWrap: "break-word",
584
+ maxWidth: "550px",
585
+ overflow: "hidden",
586
+ display: "-webkit-box",
587
+ WebkitLineClamp: 10,
588
+ WebkitBoxOrient: "vertical"
589
+ },
590
+ children: (() => {
591
+ let message = bannerError.message;
592
+ const jsonMatch = message.match(/'message':\s*'([^']+)'/);
593
+ if (jsonMatch) {
594
+ return jsonMatch[1];
595
+ }
596
+ message = message.split(" - ")[0];
597
+ message = message.split(": Error code")[0];
598
+ message = message.replace(/:\s*\d{3}$/, "");
599
+ message = message.replace(/See more:.*$/g, "");
600
+ message = message.trim();
601
+ return message || "Configuration error occurred.";
602
+ })()
603
+ }
604
+ ),
605
+ (() => {
606
+ const message = bannerError.message;
607
+ const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
608
+ const plainUrlRegex = /(https?:\/\/[^\s)]+)/g;
609
+ let url = null;
610
+ let buttonText = "See More";
611
+ const markdownMatch = markdownLinkRegex.exec(message);
612
+ if (markdownMatch) {
613
+ url = markdownMatch[2];
614
+ buttonText = "See More";
615
+ } else {
616
+ const urlMatch = plainUrlRegex.exec(message);
617
+ if (urlMatch) {
618
+ url = urlMatch[0].replace(/[.,;:'"]*$/, "");
619
+ buttonText = "See More";
620
+ }
621
+ }
622
+ if (!url)
623
+ return null;
624
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
625
+ "button",
626
+ {
627
+ onClick: () => window.open(url, "_blank", "noopener,noreferrer"),
628
+ style: {
629
+ background: colors.border,
630
+ color: "white",
631
+ border: "none",
632
+ borderRadius: "5px",
633
+ padding: "4px 10px",
634
+ fontSize: "11px",
635
+ fontWeight: "500",
636
+ cursor: "pointer",
637
+ transition: "all 0.2s ease",
638
+ flexShrink: 0
639
+ },
640
+ onMouseEnter: (e) => {
641
+ e.currentTarget.style.opacity = "0.9";
642
+ e.currentTarget.style.transform = "translateY(-1px)";
643
+ },
644
+ onMouseLeave: (e) => {
645
+ e.currentTarget.style.opacity = "1";
646
+ e.currentTarget.style.transform = "translateY(0)";
647
+ },
648
+ children: buttonText
649
+ }
650
+ );
651
+ })()
652
+ ]
619
653
  }
620
- );
621
- })()
622
- ] })
623
- ] }),
654
+ )
655
+ ]
656
+ }
657
+ ),
624
658
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
625
659
  "button",
626
660
  {
@@ -673,8 +707,38 @@ function CopilotMessages({ children }) {
673
707
  const lastLoadedThreadId = (0, import_react6.useRef)();
674
708
  const lastLoadedAgentName = (0, import_react6.useRef)();
675
709
  const lastLoadedMessages = (0, import_react6.useRef)();
676
- const { threadId, agentSession, runtimeClient, showDevConsole } = useCopilotContext();
710
+ const { threadId, agentSession, runtimeClient, showDevConsole, onTrace, copilotApiConfig } = useCopilotContext();
677
711
  const { setBannerError } = useToast();
712
+ const traceUIError = (0, import_react6.useCallback)(
713
+ (error, originalError) => __async(this, null, function* () {
714
+ if (!onTrace || !copilotApiConfig.publicApiKey)
715
+ return;
716
+ try {
717
+ const traceEvent = {
718
+ type: "error",
719
+ timestamp: Date.now(),
720
+ context: {
721
+ source: "ui",
722
+ request: {
723
+ operation: "loadAgentState",
724
+ url: copilotApiConfig.chatApiEndpoint,
725
+ startTime: Date.now()
726
+ },
727
+ technical: {
728
+ environment: "browser",
729
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
730
+ stackTrace: originalError instanceof Error ? originalError.stack : void 0
731
+ }
732
+ },
733
+ error
734
+ };
735
+ yield onTrace(traceEvent);
736
+ } catch (traceError) {
737
+ console.error("Error in CopilotMessages onTrace handler:", traceError);
738
+ }
739
+ }),
740
+ [onTrace, copilotApiConfig.publicApiKey, copilotApiConfig.chatApiEndpoint]
741
+ );
678
742
  const createStructuredError2 = (gqlError) => {
679
743
  const extensions = gqlError.extensions;
680
744
  const originalError = extensions == null ? void 0 : extensions.originalError;
@@ -719,12 +783,14 @@ function CopilotMessages({ children }) {
719
783
  const ckError = createStructuredError2(gqlError);
720
784
  if (ckError) {
721
785
  setBannerError(ckError);
786
+ traceUIError(ckError, gqlError);
722
787
  } else {
723
788
  const fallbackError = new import_shared4.CopilotKitError({
724
789
  message: gqlError.message,
725
790
  code: import_shared4.CopilotKitErrorCode.UNKNOWN
726
791
  });
727
792
  setBannerError(fallbackError);
793
+ traceUIError(fallbackError, gqlError);
728
794
  }
729
795
  };
730
796
  graphQLErrors.forEach(routeError);
@@ -738,10 +804,11 @@ function CopilotMessages({ children }) {
738
804
  code: import_shared4.CopilotKitErrorCode.UNKNOWN
739
805
  });
740
806
  setBannerError(fallbackError);
807
+ traceUIError(fallbackError, error);
741
808
  }
742
809
  }
743
810
  },
744
- [setBannerError, showDevConsole]
811
+ [setBannerError, showDevConsole, traceUIError]
745
812
  );
746
813
  (0, import_react6.useEffect)(() => {
747
814
  if (!threadId || threadId === lastLoadedThreadId.current)
@@ -776,6 +843,7 @@ function CopilotMessages({ children }) {
776
843
  });
777
844
  void fetchMessages();
778
845
  }, [threadId, agentSession == null ? void 0 : agentSession.agentName, runtimeClient]);
846
+ const memoizedChildren = (0, import_react6.useMemo)(() => children, [children]);
779
847
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
780
848
  CopilotMessagesContext.Provider,
781
849
  {
@@ -783,7 +851,7 @@ function CopilotMessages({ children }) {
783
851
  messages,
784
852
  setMessages
785
853
  },
786
- children
854
+ children: memoizedChildren
787
855
  }
788
856
  );
789
857
  }
@@ -794,8 +862,35 @@ var import_react7 = require("react");
794
862
  var import_shared5 = require("@copilotkit/shared");
795
863
  var useCopilotRuntimeClient = (options) => {
796
864
  const { setBannerError } = useToast();
797
- const _a = options, { showDevConsole } = _a, runtimeOptions = __objRest(_a, ["showDevConsole"]);
865
+ const _a = options, { showDevConsole, onTrace } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onTrace"]);
798
866
  const lastStructuredErrorRef = (0, import_react7.useRef)(null);
867
+ const traceUIError = (error, originalError) => __async(void 0, null, function* () {
868
+ if (!onTrace || !runtimeOptions.publicApiKey)
869
+ return;
870
+ try {
871
+ const traceEvent = {
872
+ type: "error",
873
+ timestamp: Date.now(),
874
+ context: {
875
+ source: "ui",
876
+ request: {
877
+ operation: "runtimeClient",
878
+ url: runtimeOptions.url,
879
+ startTime: Date.now()
880
+ },
881
+ technical: {
882
+ environment: "browser",
883
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
884
+ stackTrace: originalError instanceof Error ? originalError.stack : void 0
885
+ }
886
+ },
887
+ error
888
+ };
889
+ yield onTrace(traceEvent);
890
+ } catch (traceError) {
891
+ console.error("Error in onTrace handler:", traceError);
892
+ }
893
+ });
799
894
  const runtimeClient = (0, import_react7.useMemo)(() => {
800
895
  return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
801
896
  handleGQLErrors: (error) => {
@@ -823,12 +918,14 @@ var useCopilotRuntimeClient = (options) => {
823
918
  const ckError = createStructuredError(gqlError);
824
919
  if (ckError) {
825
920
  setBannerError(ckError);
921
+ traceUIError(ckError, gqlError);
826
922
  } else {
827
923
  const fallbackError = new import_shared5.CopilotKitError({
828
924
  message: gqlError.message,
829
925
  code: import_shared5.CopilotKitErrorCode.UNKNOWN
830
926
  });
831
927
  setBannerError(fallbackError);
928
+ traceUIError(fallbackError, gqlError);
832
929
  }
833
930
  };
834
931
  graphQLErrors.forEach(routeError);
@@ -842,6 +939,7 @@ var useCopilotRuntimeClient = (options) => {
842
939
  code: import_shared5.CopilotKitErrorCode.UNKNOWN
843
940
  });
844
941
  setBannerError(fallbackError);
942
+ traceUIError(fallbackError, error);
845
943
  }
846
944
  }
847
945
  },
@@ -854,7 +952,7 @@ var useCopilotRuntimeClient = (options) => {
854
952
  setBannerError(warningError);
855
953
  }
856
954
  }));
857
- }, [runtimeOptions, setBannerError, showDevConsole]);
955
+ }, [runtimeOptions, setBannerError, showDevConsole, onTrace]);
858
956
  return runtimeClient;
859
957
  };
860
958
  function createStructuredError(gqlError) {
@@ -947,8 +1045,8 @@ var defaultIcons = {
947
1045
  "svg",
948
1046
  {
949
1047
  viewBox: "0 0 24 24",
950
- width: "18",
951
- height: "18",
1048
+ width: "16",
1049
+ height: "16",
952
1050
  stroke: "currentColor",
953
1051
  strokeWidth: "2.5",
954
1052
  fill: "none",
@@ -965,8 +1063,8 @@ var defaultIcons = {
965
1063
  "svg",
966
1064
  {
967
1065
  viewBox: "0 0 24 24",
968
- width: "18",
969
- height: "18",
1066
+ width: "16",
1067
+ height: "16",
970
1068
  stroke: "currentColor",
971
1069
  strokeWidth: "2.5",
972
1070
  fill: "none",
@@ -983,8 +1081,8 @@ var defaultIcons = {
983
1081
  "svg",
984
1082
  {
985
1083
  viewBox: "0 0 24 24",
986
- width: "18",
987
- height: "18",
1084
+ width: "16",
1085
+ height: "16",
988
1086
  stroke: "currentColor",
989
1087
  strokeWidth: "2.5",
990
1088
  fill: "none",
@@ -1009,19 +1107,33 @@ function UsageBanner({
1009
1107
  return null;
1010
1108
  }
1011
1109
  const parseMessage = (rawMessage) => {
1012
- const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
1013
- const matches = Array.from(rawMessage.matchAll(linkRegex));
1014
- if (matches.length > 0) {
1015
- let cleanMessage2 = rawMessage.replace(/\.\s*See more:\s*\[([^\]]+)\]\(([^)]+)\)/g, ".").replace(/See more:\s*\[([^\]]+)\]\(([^)]+)\)/g, "").trim();
1016
- return cleanMessage2;
1110
+ if (rawMessage.toLowerCase().includes("authentication") || rawMessage.toLowerCase().includes("api key")) {
1111
+ return "Authentication failed. Please check your API key.";
1112
+ }
1113
+ if (rawMessage.toLowerCase().includes("rate limit")) {
1114
+ return "Rate limit exceeded. Please try again later.";
1115
+ }
1116
+ if (rawMessage.toLowerCase().includes("checkpointer")) {
1117
+ return "Agent configuration error. Please check your setup.";
1118
+ }
1119
+ let cleanMessage2 = rawMessage;
1120
+ cleanMessage2 = cleanMessage2.split(" - ")[0];
1121
+ cleanMessage2 = cleanMessage2.split(": Error code")[0];
1122
+ cleanMessage2 = cleanMessage2.split(": 401")[0];
1123
+ cleanMessage2 = cleanMessage2.split(": 403")[0];
1124
+ cleanMessage2 = cleanMessage2.split(": 404")[0];
1125
+ cleanMessage2 = cleanMessage2.split(": 500")[0];
1126
+ cleanMessage2 = cleanMessage2.replace(/See more:.*$/g, "").trim();
1127
+ if (cleanMessage2.includes("{") || cleanMessage2.includes("'") || cleanMessage2.length > 60) {
1128
+ return "Configuration error. Please check your setup.";
1017
1129
  }
1018
- return rawMessage;
1130
+ return cleanMessage2 || "An error occurred. Please check your configuration.";
1019
1131
  };
1020
1132
  const cleanMessage = parseMessage(message);
1021
1133
  const Icon = icon || defaultIcons[severity];
1022
1134
  const themeConfigs = {
1023
1135
  [import_shared7.Severity.INFO]: {
1024
- bg: "linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%)",
1136
+ bg: "rgba(239, 246, 255, 0.95)",
1025
1137
  border: "#93c5fd",
1026
1138
  text: "#1e40af",
1027
1139
  icon: "#3b82f6",
@@ -1029,7 +1141,7 @@ function UsageBanner({
1029
1141
  primaryBtnHover: "#2563eb"
1030
1142
  },
1031
1143
  [import_shared7.Severity.WARNING]: {
1032
- bg: "linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%)",
1144
+ bg: "rgba(255, 251, 235, 0.95)",
1033
1145
  border: "#fbbf24",
1034
1146
  text: "#92400e",
1035
1147
  icon: "#f59e0b",
@@ -1037,7 +1149,7 @@ function UsageBanner({
1037
1149
  primaryBtnHover: "#d97706"
1038
1150
  },
1039
1151
  [import_shared7.Severity.CRITICAL]: {
1040
- bg: "linear-gradient(135deg, #fef2f2 0%, #fecaca 100%)",
1152
+ bg: "rgba(254, 242, 242, 0.95)",
1041
1153
  border: "#f87171",
1042
1154
  text: "#991b1b",
1043
1155
  icon: "#ef4444",
@@ -1051,24 +1163,26 @@ function UsageBanner({
1051
1163
  {
1052
1164
  style: {
1053
1165
  position: "fixed",
1054
- bottom: "20px",
1166
+ bottom: "24px",
1055
1167
  left: "50%",
1056
1168
  transform: "translateX(-50%)",
1057
- maxWidth: "min(95vw, 680px)",
1058
- width: "100%",
1169
+ width: "400px",
1170
+ maxWidth: "90vw",
1059
1171
  zIndex: 1e4,
1060
- animation: "bannerSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1)"
1172
+ animation: "bannerSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1)"
1061
1173
  },
1062
1174
  children: [
1063
1175
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("style", { children: `
1064
1176
  @keyframes bannerSlideIn {
1065
1177
  from {
1066
1178
  opacity: 0;
1067
- transform: translateX(-50%) translateY(10px);
1179
+ transform: translateX(-50%) translateY(20px);
1180
+ scale: 0.95;
1068
1181
  }
1069
1182
  to {
1070
1183
  opacity: 1;
1071
1184
  transform: translateX(-50%) translateY(0);
1185
+ scale: 1;
1072
1186
  }
1073
1187
  }
1074
1188
  ` }),
@@ -1076,17 +1190,16 @@ function UsageBanner({
1076
1190
  "div",
1077
1191
  {
1078
1192
  style: {
1079
- display: "flex",
1080
- alignItems: "flex-start",
1081
- gap: "14px",
1082
- borderRadius: "16px",
1193
+ borderRadius: "12px",
1083
1194
  border: `1px solid ${themeConfig.border}`,
1084
1195
  background: themeConfig.bg,
1085
- padding: "18px 20px",
1086
- boxShadow: "0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1)",
1196
+ padding: "14px",
1197
+ boxShadow: "0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08)",
1087
1198
  position: "relative",
1088
- backdropFilter: "blur(10px)",
1089
- WebkitBackdropFilter: "blur(10px)"
1199
+ backdropFilter: "blur(12px)",
1200
+ WebkitBackdropFilter: "blur(12px)",
1201
+ boxSizing: "border-box",
1202
+ overflow: "hidden"
1090
1203
  },
1091
1204
  children: [
1092
1205
  onClose && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
@@ -1095,35 +1208,23 @@ function UsageBanner({
1095
1208
  onClick: onClose,
1096
1209
  style: {
1097
1210
  position: "absolute",
1098
- top: "12px",
1099
- right: "12px",
1100
- background: "rgba(255, 255, 255, 0.8)",
1211
+ top: "8px",
1212
+ right: "8px",
1213
+ background: "rgba(255, 255, 255, 0.9)",
1101
1214
  border: "none",
1102
1215
  color: themeConfig.text,
1103
1216
  cursor: "pointer",
1104
- fontSize: "18px",
1217
+ fontSize: "16px",
1105
1218
  lineHeight: "1",
1106
- padding: "6px",
1107
- borderRadius: "8px",
1108
- opacity: 0.7,
1109
- transition: "all 0.2s ease",
1219
+ padding: "4px",
1220
+ borderRadius: "4px",
1221
+ width: "20px",
1222
+ height: "20px",
1110
1223
  display: "flex",
1111
1224
  alignItems: "center",
1112
- justifyContent: "center",
1113
- width: "28px",
1114
- height: "28px"
1225
+ justifyContent: "center"
1115
1226
  },
1116
1227
  title: "Close",
1117
- onMouseOver: (e) => {
1118
- e.currentTarget.style.opacity = "1";
1119
- e.currentTarget.style.background = "rgba(255, 255, 255, 1)";
1120
- e.currentTarget.style.transform = "scale(1.05)";
1121
- },
1122
- onMouseOut: (e) => {
1123
- e.currentTarget.style.opacity = "0.7";
1124
- e.currentTarget.style.background = "rgba(255, 255, 255, 0.8)";
1125
- e.currentTarget.style.transform = "scale(1)";
1126
- },
1127
1228
  children: "\xD7"
1128
1229
  }
1129
1230
  ),
@@ -1131,106 +1232,92 @@ function UsageBanner({
1131
1232
  "div",
1132
1233
  {
1133
1234
  style: {
1134
- color: themeConfig.icon,
1135
- flexShrink: 0,
1136
- marginTop: "1px",
1137
- padding: "6px",
1138
- borderRadius: "10px",
1139
- background: "rgba(255, 255, 255, 0.7)",
1140
- display: "flex",
1141
- alignItems: "center",
1142
- justifyContent: "center"
1235
+ fontSize: "14px",
1236
+ fontWeight: 500,
1237
+ color: themeConfig.text,
1238
+ lineHeight: "1.4",
1239
+ fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
1240
+ paddingRight: onClose ? "30px" : "0",
1241
+ marginBottom: actions ? "12px" : "0",
1242
+ wordBreak: "break-word",
1243
+ overflow: "hidden",
1244
+ textOverflow: "ellipsis",
1245
+ display: "-webkit-box",
1246
+ WebkitLineClamp: 2,
1247
+ WebkitBoxOrient: "vertical"
1143
1248
  },
1144
- children: Icon
1249
+ children: cleanMessage
1145
1250
  }
1146
1251
  ),
1147
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { flex: 1, paddingRight: onClose ? "40px" : "0" }, children: [
1148
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1149
- "div",
1150
- {
1151
- style: {
1152
- fontSize: "15px",
1153
- fontWeight: 600,
1154
- color: themeConfig.text,
1155
- lineHeight: "1.5",
1156
- marginBottom: actions ? "12px" : "0",
1157
- fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1158
- },
1159
- children: cleanMessage
1160
- }
1161
- ),
1162
- actions && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1163
- "div",
1164
- {
1165
- style: {
1166
- display: "flex",
1167
- gap: "10px",
1168
- flexWrap: "wrap"
1169
- },
1170
- children: [
1171
- actions.secondary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1172
- "button",
1173
- {
1174
- onClick: actions.secondary.onClick,
1175
- style: {
1176
- borderRadius: "10px",
1177
- padding: "8px 16px",
1178
- fontSize: "14px",
1179
- fontWeight: 500,
1180
- color: themeConfig.text,
1181
- backgroundColor: "rgba(255, 255, 255, 0.8)",
1182
- border: `1.5px solid ${themeConfig.border}`,
1183
- cursor: "pointer",
1184
- transition: "all 0.2s ease",
1185
- fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1186
- },
1187
- onMouseOver: (e) => {
1188
- e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 1)";
1189
- e.currentTarget.style.transform = "translateY(-1px)";
1190
- e.currentTarget.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.15)";
1191
- },
1192
- onMouseOut: (e) => {
1193
- e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 0.8)";
1194
- e.currentTarget.style.transform = "translateY(0)";
1195
- e.currentTarget.style.boxShadow = "none";
1196
- },
1197
- children: actions.secondary.label
1198
- }
1199
- ),
1200
- actions.primary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1201
- "button",
1202
- {
1203
- onClick: actions.primary.onClick,
1204
- style: {
1205
- borderRadius: "10px",
1206
- padding: "8px 16px",
1207
- fontSize: "14px",
1208
- fontWeight: 600,
1209
- color: "#fff",
1210
- backgroundColor: themeConfig.primaryBtn,
1211
- border: "none",
1212
- cursor: "pointer",
1213
- transition: "all 0.2s ease",
1214
- boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
1215
- fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1216
- },
1217
- onMouseOver: (e) => {
1218
- e.currentTarget.style.backgroundColor = themeConfig.primaryBtnHover;
1219
- e.currentTarget.style.transform = "translateY(-1px)";
1220
- e.currentTarget.style.boxShadow = "0 6px 16px rgba(0, 0, 0, 0.2)";
1221
- },
1222
- onMouseOut: (e) => {
1223
- e.currentTarget.style.backgroundColor = themeConfig.primaryBtn;
1224
- e.currentTarget.style.transform = "translateY(0)";
1225
- e.currentTarget.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.15)";
1226
- },
1227
- children: actions.primary.label
1228
- }
1229
- )
1230
- ]
1231
- }
1232
- )
1233
- ] })
1252
+ actions && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1253
+ "div",
1254
+ {
1255
+ style: {
1256
+ display: "flex",
1257
+ gap: "8px",
1258
+ flexWrap: "wrap"
1259
+ },
1260
+ children: [
1261
+ actions.secondary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1262
+ "button",
1263
+ {
1264
+ onClick: actions.secondary.onClick,
1265
+ style: {
1266
+ borderRadius: "8px",
1267
+ padding: "6px 12px",
1268
+ fontSize: "13px",
1269
+ fontWeight: 500,
1270
+ color: themeConfig.text,
1271
+ backgroundColor: "rgba(255, 255, 255, 0.9)",
1272
+ border: `1px solid ${themeConfig.border}`,
1273
+ cursor: "pointer",
1274
+ transition: "all 0.2s ease",
1275
+ fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1276
+ },
1277
+ onMouseOver: (e) => {
1278
+ e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 1)";
1279
+ e.currentTarget.style.transform = "translateY(-1px)";
1280
+ },
1281
+ onMouseOut: (e) => {
1282
+ e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 0.9)";
1283
+ e.currentTarget.style.transform = "translateY(0)";
1284
+ },
1285
+ children: actions.secondary.label
1286
+ }
1287
+ ),
1288
+ actions.primary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1289
+ "button",
1290
+ {
1291
+ onClick: actions.primary.onClick,
1292
+ style: {
1293
+ borderRadius: "8px",
1294
+ padding: "6px 12px",
1295
+ fontSize: "13px",
1296
+ fontWeight: 600,
1297
+ color: "#fff",
1298
+ backgroundColor: themeConfig.primaryBtn,
1299
+ border: "none",
1300
+ cursor: "pointer",
1301
+ transition: "all 0.2s ease",
1302
+ boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)",
1303
+ fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1304
+ },
1305
+ onMouseOver: (e) => {
1306
+ e.currentTarget.style.backgroundColor = themeConfig.primaryBtnHover;
1307
+ e.currentTarget.style.transform = "translateY(-1px)";
1308
+ e.currentTarget.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.2)";
1309
+ },
1310
+ onMouseOut: (e) => {
1311
+ e.currentTarget.style.backgroundColor = themeConfig.primaryBtn;
1312
+ e.currentTarget.style.transform = "translateY(0)";
1313
+ e.currentTarget.style.boxShadow = "0 2px 8px rgba(0, 0, 0, 0.15)";
1314
+ },
1315
+ children: actions.primary.label
1316
+ }
1317
+ )
1318
+ ]
1319
+ }
1320
+ )
1234
1321
  ]
1235
1322
  }
1236
1323
  )
@@ -1634,7 +1721,8 @@ ${nonDocumentStrings}`;
1634
1721
  publicApiKey: copilotApiConfig.publicApiKey,
1635
1722
  headers,
1636
1723
  credentials: copilotApiConfig.credentials,
1637
- showDevConsole: (_b = props.showDevConsole) != null ? _b : false
1724
+ showDevConsole: (_b = props.showDevConsole) != null ? _b : false,
1725
+ onTrace: props.onTrace
1638
1726
  });
1639
1727
  const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react10.useState)({});
1640
1728
  const addChatSuggestionConfiguration = (id, suggestion) => {
@@ -1724,6 +1812,7 @@ ${nonDocumentStrings}`;
1724
1812
  const removeLangGraphInterruptAction = (0, import_react10.useCallback)(() => {
1725
1813
  setLangGraphInterruptAction(null);
1726
1814
  }, []);
1815
+ const memoizedChildren = (0, import_react10.useMemo)(() => children, [children]);
1727
1816
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1728
1817
  CopilotContext.Provider,
1729
1818
  {
@@ -1776,9 +1865,10 @@ ${nonDocumentStrings}`;
1776
1865
  setExtensions,
1777
1866
  langGraphInterruptAction,
1778
1867
  setLangGraphInterruptAction,
1779
- removeLangGraphInterruptAction
1868
+ removeLangGraphInterruptAction,
1869
+ onTrace: props.onTrace
1780
1870
  },
1781
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotMessages, { children })
1871
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotMessages, { children: memoizedChildren })
1782
1872
  }
1783
1873
  );
1784
1874
  }