@copilotkit/react-core 1.9.2-next.2 → 1.9.2-next.21

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 (170) hide show
  1. package/CHANGELOG.md +162 -0
  2. package/dist/{chunk-UHQMV2CE.mjs → chunk-36MGCCPZ.mjs} +2 -2
  3. package/dist/{chunk-CCESTGAM.mjs → chunk-3OQM3NEK.mjs} +2 -2
  4. package/dist/{chunk-OUSWPVDT.mjs → chunk-4URMLOBR.mjs} +4 -4
  5. package/dist/chunk-57K2ZJ5F.mjs +348 -0
  6. package/dist/chunk-57K2ZJ5F.mjs.map +1 -0
  7. package/dist/{chunk-LZDDYZEY.mjs → chunk-5BSUSFHM.mjs} +2 -2
  8. package/dist/{chunk-C6F6EQNA.mjs → chunk-BVK7PLK6.mjs} +2 -2
  9. package/dist/{chunk-CMKIDDQL.mjs → chunk-DDIBJUWK.mjs} +11 -8
  10. package/dist/{chunk-CMKIDDQL.mjs.map → chunk-DDIBJUWK.mjs.map} +1 -1
  11. package/dist/{chunk-NNSXCFQO.mjs → chunk-DGON3GZX.mjs} +42 -8
  12. package/dist/chunk-DGON3GZX.mjs.map +1 -0
  13. package/dist/{chunk-6KGEF242.mjs → chunk-DKZTPL66.mjs} +3 -2
  14. package/dist/chunk-DKZTPL66.mjs.map +1 -0
  15. package/dist/{chunk-LDACFA2B.mjs → chunk-FN3UA2ZE.mjs} +3 -3
  16. package/dist/{chunk-RUY6MLHA.mjs → chunk-JWAXDYOW.mjs} +36 -6
  17. package/dist/chunk-JWAXDYOW.mjs.map +1 -0
  18. package/dist/{chunk-2FW7HH6W.mjs → chunk-KIXKBJUV.mjs} +3 -3
  19. package/dist/{chunk-MGIXEJWG.mjs → chunk-MTAJI7HV.mjs} +181 -68
  20. package/dist/chunk-MTAJI7HV.mjs.map +1 -0
  21. package/dist/{chunk-L6QAOAE4.mjs → chunk-N2M65NJ2.mjs} +69 -25
  22. package/dist/chunk-N2M65NJ2.mjs.map +1 -0
  23. package/dist/{chunk-T42PN5VN.mjs → chunk-NJA5ZLAZ.mjs} +29 -10
  24. package/dist/chunk-NJA5ZLAZ.mjs.map +1 -0
  25. package/dist/{chunk-4I7PLQF7.mjs → chunk-QKEH3O4S.mjs} +5 -5
  26. package/dist/{chunk-FRZZPPIV.mjs → chunk-RAQK4M64.mjs} +2 -2
  27. package/dist/{chunk-QQZLIEXK.mjs → chunk-SJJNFYGQ.mjs} +3 -3
  28. package/dist/{chunk-Q5D5XQFA.mjs → chunk-VDADWRS3.mjs} +2 -2
  29. package/dist/chunk-YAF2LATQ.mjs +310 -0
  30. package/dist/chunk-YAF2LATQ.mjs.map +1 -0
  31. package/dist/components/copilot-provider/copilot-messages.js +40 -5
  32. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  33. package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
  34. package/dist/components/copilot-provider/copilotkit-props.d.ts +27 -3
  35. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  36. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  37. package/dist/components/copilot-provider/copilotkit.js +385 -254
  38. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  39. package/dist/components/copilot-provider/copilotkit.mjs +10 -10
  40. package/dist/components/copilot-provider/index.d.ts +1 -1
  41. package/dist/components/copilot-provider/index.js +385 -254
  42. package/dist/components/copilot-provider/index.js.map +1 -1
  43. package/dist/components/copilot-provider/index.mjs +10 -10
  44. package/dist/components/error-boundary/error-boundary.js +135 -146
  45. package/dist/components/error-boundary/error-boundary.js.map +1 -1
  46. package/dist/components/error-boundary/error-boundary.mjs +4 -4
  47. package/dist/components/error-boundary/error-utils.js.map +1 -1
  48. package/dist/components/error-boundary/error-utils.mjs +2 -2
  49. package/dist/components/index.d.ts +1 -1
  50. package/dist/components/index.js +385 -254
  51. package/dist/components/index.js.map +1 -1
  52. package/dist/components/index.mjs +10 -10
  53. package/dist/components/toast/toast-provider.js +118 -85
  54. package/dist/components/toast/toast-provider.js.map +1 -1
  55. package/dist/components/toast/toast-provider.mjs +1 -1
  56. package/dist/components/usage-banner.js +135 -146
  57. package/dist/components/usage-banner.js.map +1 -1
  58. package/dist/components/usage-banner.mjs +1 -1
  59. package/dist/context/copilot-context.d.ts +1 -1
  60. package/dist/context/copilot-context.js +2 -1
  61. package/dist/context/copilot-context.js.map +1 -1
  62. package/dist/context/copilot-context.mjs +1 -1
  63. package/dist/context/index.d.ts +1 -1
  64. package/dist/context/index.js +2 -1
  65. package/dist/context/index.js.map +1 -1
  66. package/dist/context/index.mjs +1 -1
  67. package/dist/{copilot-context-f9b2b4c3.d.ts → copilot-context-3ab4fdf5.d.ts} +6 -2
  68. package/dist/hooks/index.d.ts +1 -1
  69. package/dist/hooks/index.js +232 -71
  70. package/dist/hooks/index.js.map +1 -1
  71. package/dist/hooks/index.mjs +32 -32
  72. package/dist/hooks/use-chat.d.ts +1 -1
  73. package/dist/hooks/use-chat.js +295 -156
  74. package/dist/hooks/use-chat.js.map +1 -1
  75. package/dist/hooks/use-chat.mjs +6 -6
  76. package/dist/hooks/use-coagent-state-render.js +2 -1
  77. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  78. package/dist/hooks/use-coagent-state-render.mjs +3 -3
  79. package/dist/hooks/use-coagent.d.ts +1 -1
  80. package/dist/hooks/use-coagent.js +207 -65
  81. package/dist/hooks/use-coagent.js.map +1 -1
  82. package/dist/hooks/use-coagent.mjs +14 -14
  83. package/dist/hooks/use-copilot-action.js +27 -7
  84. package/dist/hooks/use-copilot-action.js.map +1 -1
  85. package/dist/hooks/use-copilot-action.mjs +4 -4
  86. package/dist/hooks/use-copilot-additional-instructions.js +2 -1
  87. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
  88. package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
  89. package/dist/hooks/use-copilot-authenticated-action.js +27 -7
  90. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  91. package/dist/hooks/use-copilot-authenticated-action.mjs +5 -5
  92. package/dist/hooks/use-copilot-chat.d.ts +1 -1
  93. package/dist/hooks/use-copilot-chat.js +204 -65
  94. package/dist/hooks/use-copilot-chat.js.map +1 -1
  95. package/dist/hooks/use-copilot-chat.mjs +13 -13
  96. package/dist/hooks/use-copilot-readable.js +2 -1
  97. package/dist/hooks/use-copilot-readable.js.map +1 -1
  98. package/dist/hooks/use-copilot-readable.mjs +2 -2
  99. package/dist/hooks/use-copilot-runtime-client.d.ts +2 -0
  100. package/dist/hooks/use-copilot-runtime-client.js +52 -2
  101. package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
  102. package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
  103. package/dist/hooks/use-langgraph-interrupt-render.js +2 -1
  104. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  105. package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
  106. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  107. package/dist/hooks/use-langgraph-interrupt.js +204 -65
  108. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  109. package/dist/hooks/use-langgraph-interrupt.mjs +14 -14
  110. package/dist/hooks/use-make-copilot-document-readable.js +2 -1
  111. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  112. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  113. package/dist/index.d.ts +1 -1
  114. package/dist/index.js +582 -321
  115. package/dist/index.js.map +1 -1
  116. package/dist/index.mjs +33 -33
  117. package/dist/lib/copilot-task.d.ts +1 -1
  118. package/dist/lib/copilot-task.js.map +1 -1
  119. package/dist/lib/copilot-task.mjs +11 -11
  120. package/dist/lib/index.d.ts +1 -1
  121. package/dist/lib/index.js.map +1 -1
  122. package/dist/lib/index.mjs +11 -11
  123. package/dist/types/interrupt-action.d.ts +1 -1
  124. package/dist/utils/extract.d.ts +1 -1
  125. package/dist/utils/extract.js.map +1 -1
  126. package/dist/utils/extract.mjs +10 -10
  127. package/dist/utils/index.d.ts +1 -1
  128. package/dist/utils/index.js.map +1 -1
  129. package/dist/utils/index.mjs +10 -10
  130. package/jest.config.js +7 -3
  131. package/package.json +4 -3
  132. package/src/components/copilot-provider/__tests__/copilotkit-error.test.tsx +75 -0
  133. package/src/components/copilot-provider/copilot-messages.tsx +47 -6
  134. package/src/components/copilot-provider/copilotkit-props.tsx +27 -1
  135. package/src/components/copilot-provider/copilotkit.tsx +64 -18
  136. package/src/components/toast/toast-provider.tsx +49 -24
  137. package/src/components/usage-banner.tsx +144 -147
  138. package/src/context/copilot-context.tsx +8 -2
  139. package/src/hooks/use-chat.ts +247 -61
  140. package/src/hooks/use-coagent.ts +5 -0
  141. package/src/hooks/use-copilot-action.ts +51 -9
  142. package/src/hooks/use-copilot-runtime-client.ts +41 -40
  143. package/tsconfig.json +4 -8
  144. package/tsup.config.ts +6 -6
  145. package/dist/chunk-6KGEF242.mjs.map +0 -1
  146. package/dist/chunk-HD2GE3DK.mjs +0 -359
  147. package/dist/chunk-HD2GE3DK.mjs.map +0 -1
  148. package/dist/chunk-L6QAOAE4.mjs.map +0 -1
  149. package/dist/chunk-MGIXEJWG.mjs.map +0 -1
  150. package/dist/chunk-NNSXCFQO.mjs.map +0 -1
  151. package/dist/chunk-RUY6MLHA.mjs.map +0 -1
  152. package/dist/chunk-T42PN5VN.mjs.map +0 -1
  153. package/dist/chunk-VRXANACV.mjs +0 -277
  154. package/dist/chunk-VRXANACV.mjs.map +0 -1
  155. package/dist/utils/utils.test.d.ts +0 -2
  156. package/dist/utils/utils.test.js +0 -9
  157. package/dist/utils/utils.test.js.map +0 -1
  158. package/dist/utils/utils.test.mjs +0 -7
  159. package/dist/utils/utils.test.mjs.map +0 -1
  160. /package/dist/{chunk-UHQMV2CE.mjs.map → chunk-36MGCCPZ.mjs.map} +0 -0
  161. /package/dist/{chunk-CCESTGAM.mjs.map → chunk-3OQM3NEK.mjs.map} +0 -0
  162. /package/dist/{chunk-OUSWPVDT.mjs.map → chunk-4URMLOBR.mjs.map} +0 -0
  163. /package/dist/{chunk-LZDDYZEY.mjs.map → chunk-5BSUSFHM.mjs.map} +0 -0
  164. /package/dist/{chunk-C6F6EQNA.mjs.map → chunk-BVK7PLK6.mjs.map} +0 -0
  165. /package/dist/{chunk-LDACFA2B.mjs.map → chunk-FN3UA2ZE.mjs.map} +0 -0
  166. /package/dist/{chunk-2FW7HH6W.mjs.map → chunk-KIXKBJUV.mjs.map} +0 -0
  167. /package/dist/{chunk-4I7PLQF7.mjs.map → chunk-QKEH3O4S.mjs.map} +0 -0
  168. /package/dist/{chunk-FRZZPPIV.mjs.map → chunk-RAQK4M64.mjs.map} +0 -0
  169. /package/dist/{chunk-QQZLIEXK.mjs.map → chunk-SJJNFYGQ.mjs.map} +0 -0
  170. /package/dist/{chunk-Q5D5XQFA.mjs.map → chunk-VDADWRS3.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
+ onError: 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: "10px 14px",
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: "500px",
555
- minWidth: "350px"
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)("div", { style: { display: "flex", alignItems: "center", gap: "8px", flex: 1 }, children: [
568
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
569
- "div",
570
- {
571
- style: {
572
- width: "12px",
573
- height: "12px",
574
- borderRadius: "50%",
575
- backgroundColor: colors.border,
576
- flexShrink: 0
577
- }
578
- }
579
- ),
580
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "10px", flex: 1 }, children: [
581
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
582
- "div",
583
- {
584
- style: {
585
- color: colors.text,
586
- lineHeight: "1.4",
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
- if (!url)
624
- return null;
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
- background: colors.border,
631
- color: "white",
632
- border: "none",
633
- borderRadius: "5px",
634
- padding: "4px 10px",
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)";
644
- },
645
- onMouseLeave: (e) => {
646
- e.currentTarget.style.opacity = "1";
647
- e.currentTarget.style.transform = "translateY(0)";
597
+ display: "flex",
598
+ alignItems: "center",
599
+ gap: "10px",
600
+ flex: 1,
601
+ minWidth: 0
648
602
  },
649
- 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
+ ]
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, onError, copilotApiConfig } = useCopilotContext();
708
742
  const { setBannerError } = useToast();
743
+ const traceUIError = (0, import_react6.useCallback)(
744
+ (error, originalError) => __async(this, null, function* () {
745
+ if (!onError || !copilotApiConfig.publicApiKey)
746
+ return;
747
+ try {
748
+ const traceEvent = {
749
+ type: "error",
750
+ timestamp: Date.now(),
751
+ context: {
752
+ source: "ui",
753
+ request: {
754
+ operation: "loadAgentState",
755
+ url: copilotApiConfig.chatApiEndpoint,
756
+ startTime: Date.now()
757
+ },
758
+ technical: {
759
+ environment: "browser",
760
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
761
+ stackTrace: originalError instanceof Error ? originalError.stack : void 0
762
+ }
763
+ },
764
+ error
765
+ };
766
+ yield onError(traceEvent);
767
+ } catch (traceError) {
768
+ console.error("Error in CopilotMessages onError handler:", traceError);
769
+ }
770
+ }),
771
+ [onError, copilotApiConfig.publicApiKey, copilotApiConfig.chatApiEndpoint]
772
+ );
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)
@@ -806,7 +873,8 @@ function CopilotMessages({ children }) {
806
873
  }
807
874
  });
808
875
  void fetchMessages();
809
- }, [threadId, agentSession == null ? void 0 : agentSession.agentName, runtimeClient]);
876
+ }, [threadId, agentSession == null ? void 0 : agentSession.agentName]);
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, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
829
897
  const lastStructuredErrorRef = (0, import_react7.useRef)(null);
898
+ const traceUIError = (error, originalError) => __async(void 0, null, function* () {
899
+ if (!onError || !runtimeOptions.publicApiKey)
900
+ return;
901
+ try {
902
+ const errorEvent = {
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 onError(errorEvent);
921
+ } catch (error2) {
922
+ console.error("Error in onError handler:", error2);
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, onError]);
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: "18",
1116
- height: "18",
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: "18",
1134
- height: "18",
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: "18",
1152
- height: "18",
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
- const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
1178
- const matches = Array.from(rawMessage.matchAll(linkRegex));
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.";
1277
+ }
1278
+ if (rawMessage.toLowerCase().includes("rate limit")) {
1279
+ return "Rate limit exceeded. Please try again later.";
1182
1280
  }
1183
- return rawMessage;
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: "linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%)",
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: "linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%)",
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: "linear-gradient(135deg, #fef2f2 0%, #fecaca 100%)",
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: "20px",
1331
+ bottom: "24px",
1220
1332
  left: "50%",
1221
1333
  transform: "translateX(-50%)",
1222
- maxWidth: "min(95vw, 680px)",
1223
- width: "100%",
1334
+ width: "400px",
1335
+ maxWidth: "90vw",
1224
1336
  zIndex: 1e4,
1225
- 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)"
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(10px);
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
- display: "flex",
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: "18px 20px",
1251
- 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)",
1252
1363
  position: "relative",
1253
- backdropFilter: "blur(10px)",
1254
- WebkitBackdropFilter: "blur(10px)"
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: "12px",
1264
- right: "12px",
1265
- background: "rgba(255, 255, 255, 0.8)",
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: "18px",
1382
+ fontSize: "16px",
1270
1383
  lineHeight: "1",
1271
- padding: "6px",
1272
- borderRadius: "8px",
1273
- opacity: 0.7,
1274
- transition: "all 0.2s ease",
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
- color: themeConfig.icon,
1300
- flexShrink: 0,
1301
- marginTop: "1px",
1302
- padding: "6px",
1303
- borderRadius: "10px",
1304
- background: "rgba(255, 255, 255, 0.7)",
1305
- display: "flex",
1306
- alignItems: "center",
1307
- 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"
1308
1413
  },
1309
- children: Icon
1414
+ children: cleanMessage
1310
1415
  }
1311
1416
  ),
1312
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { flex: 1, paddingRight: onClose ? "40px" : "0" }, children: [
1313
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1314
- "div",
1315
- {
1316
- style: {
1317
- fontSize: "15px",
1318
- fontWeight: 600,
1319
- color: themeConfig.text,
1320
- lineHeight: "1.5",
1321
- marginBottom: actions ? "12px" : "0",
1322
- fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1323
- },
1324
- children: cleanMessage
1325
- }
1326
- ),
1327
- actions && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1328
- "div",
1329
- {
1330
- style: {
1331
- display: "flex",
1332
- gap: "10px",
1333
- flexWrap: "wrap"
1334
- },
1335
- children: [
1336
- actions.secondary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1337
- "button",
1338
- {
1339
- onClick: actions.secondary.onClick,
1340
- style: {
1341
- borderRadius: "10px",
1342
- padding: "8px 16px",
1343
- fontSize: "14px",
1344
- fontWeight: 500,
1345
- color: themeConfig.text,
1346
- backgroundColor: "rgba(255, 255, 255, 0.8)",
1347
- border: `1.5px solid ${themeConfig.border}`,
1348
- cursor: "pointer",
1349
- transition: "all 0.2s ease",
1350
- fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1351
- },
1352
- onMouseOver: (e) => {
1353
- e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 1)";
1354
- e.currentTarget.style.transform = "translateY(-1px)";
1355
- e.currentTarget.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.15)";
1356
- },
1357
- onMouseOut: (e) => {
1358
- e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 0.8)";
1359
- e.currentTarget.style.transform = "translateY(0)";
1360
- e.currentTarget.style.boxShadow = "none";
1361
- },
1362
- children: actions.secondary.label
1363
- }
1364
- ),
1365
- actions.primary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1366
- "button",
1367
- {
1368
- onClick: actions.primary.onClick,
1369
- style: {
1370
- borderRadius: "10px",
1371
- padding: "8px 16px",
1372
- fontSize: "14px",
1373
- fontWeight: 600,
1374
- color: "#fff",
1375
- backgroundColor: themeConfig.primaryBtn,
1376
- border: "none",
1377
- cursor: "pointer",
1378
- transition: "all 0.2s ease",
1379
- boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
1380
- fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
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,18 +1898,25 @@ ${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
+ onError: props.onError
1815
1903
  });
1816
1904
  const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react10.useState)({});
1817
- const addChatSuggestionConfiguration = (id, suggestion) => {
1818
- setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
1819
- };
1820
- const removeChatSuggestionConfiguration = (id) => {
1821
- setChatSuggestionConfiguration((prev) => {
1822
- const _a2 = prev, { [id]: _ } = _a2, rest = __objRest(_a2, [__restKey(id)]);
1823
- return rest;
1824
- });
1825
- };
1905
+ const addChatSuggestionConfiguration = (0, import_react10.useCallback)(
1906
+ (id, suggestion) => {
1907
+ setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
1908
+ },
1909
+ [setChatSuggestionConfiguration]
1910
+ );
1911
+ const removeChatSuggestionConfiguration = (0, import_react10.useCallback)(
1912
+ (id) => {
1913
+ setChatSuggestionConfiguration((prev) => {
1914
+ const _a2 = prev, { [id]: _ } = _a2, rest = __objRest(_a2, [__restKey(id)]);
1915
+ return rest;
1916
+ });
1917
+ },
1918
+ [setChatSuggestionConfiguration]
1919
+ );
1826
1920
  const [availableAgents, setAvailableAgents] = (0, import_react10.useState)([]);
1827
1921
  const [coagentStates, setCoagentStates] = (0, import_react10.useState)({});
1828
1922
  const coagentStatesRef = (0, import_react10.useRef)({});
@@ -1901,6 +1995,42 @@ ${nonDocumentStrings}`;
1901
1995
  const removeLangGraphInterruptAction = (0, import_react10.useCallback)(() => {
1902
1996
  setLangGraphInterruptAction(null);
1903
1997
  }, []);
1998
+ const memoizedChildren = (0, import_react10.useMemo)(() => children, [children]);
1999
+ const agentLock = (0, import_react10.useMemo)(() => {
2000
+ var _a2;
2001
+ return (_a2 = props.agent) != null ? _a2 : null;
2002
+ }, [props.agent]);
2003
+ const forwardedParameters = (0, import_react10.useMemo)(
2004
+ () => {
2005
+ var _a2;
2006
+ return (_a2 = props.forwardedParameters) != null ? _a2 : {};
2007
+ },
2008
+ [props.forwardedParameters]
2009
+ );
2010
+ const updateExtensions = (0, import_react10.useCallback)(
2011
+ (newExtensions) => {
2012
+ setExtensions((prev) => {
2013
+ const resolved = typeof newExtensions === "function" ? newExtensions(prev) : newExtensions;
2014
+ const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
2015
+ const isEqual = isSameLength && // @ts-ignore
2016
+ Object.entries(resolved).every(([key, value]) => prev[key] === value);
2017
+ return isEqual ? prev : resolved;
2018
+ });
2019
+ },
2020
+ [setExtensions]
2021
+ );
2022
+ const updateAuthStates = (0, import_react10.useCallback)(
2023
+ (newAuthStates) => {
2024
+ setAuthStates((prev) => {
2025
+ const resolved = typeof newAuthStates === "function" ? newAuthStates(prev) : newAuthStates;
2026
+ const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
2027
+ const isEqual = isSameLength && // @ts-ignore
2028
+ Object.entries(resolved).every(([key, value]) => prev[key] === value);
2029
+ return isEqual ? prev : resolved;
2030
+ });
2031
+ },
2032
+ [setAuthStates]
2033
+ );
1904
2034
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1905
2035
  CopilotContext.Provider,
1906
2036
  {
@@ -1938,8 +2068,8 @@ ${nonDocumentStrings}`;
1938
2068
  agentSession,
1939
2069
  setAgentSession,
1940
2070
  runtimeClient,
1941
- forwardedParameters: props.forwardedParameters || {},
1942
- agentLock: props.agent || null,
2071
+ forwardedParameters,
2072
+ agentLock,
1943
2073
  threadId: internalThreadId,
1944
2074
  setThreadId,
1945
2075
  runId,
@@ -1948,14 +2078,15 @@ ${nonDocumentStrings}`;
1948
2078
  availableAgents,
1949
2079
  authConfig_c: props.authConfig_c,
1950
2080
  authStates_c: authStates,
1951
- setAuthStates_c: setAuthStates,
2081
+ setAuthStates_c: updateAuthStates,
1952
2082
  extensions,
1953
- setExtensions,
2083
+ setExtensions: updateExtensions,
1954
2084
  langGraphInterruptAction,
1955
2085
  setLangGraphInterruptAction,
1956
- removeLangGraphInterruptAction
2086
+ removeLangGraphInterruptAction,
2087
+ onError: props.onError
1957
2088
  },
1958
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotMessages, { children })
2089
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotMessages, { children: memoizedChildren })
1959
2090
  }
1960
2091
  );
1961
2092
  }
@@ -2006,6 +2137,7 @@ var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
2006
2137
 
2007
2138
  // src/hooks/use-chat.ts
2008
2139
  var import_react11 = require("react");
2140
+ var import_react_dom2 = require("react-dom");
2009
2141
  var import_shared12 = require("@copilotkit/shared");
2010
2142
  var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
2011
2143
 
@@ -2064,6 +2196,35 @@ function useChat(options) {
2064
2196
  } = options;
2065
2197
  const runChatCompletionRef = (0, import_react11.useRef)();
2066
2198
  const addErrorToast = useErrorToast();
2199
+ const { setBannerError } = useToast();
2200
+ const { onError } = useCopilotContext();
2201
+ const traceUIError = (error, originalError) => __async(this, null, function* () {
2202
+ if (!onError || !(copilotConfig == null ? void 0 : copilotConfig.publicApiKey))
2203
+ return;
2204
+ try {
2205
+ const traceEvent = {
2206
+ type: "error",
2207
+ timestamp: Date.now(),
2208
+ context: {
2209
+ source: "ui",
2210
+ request: {
2211
+ operation: "useChatCompletion",
2212
+ url: copilotConfig.chatApiEndpoint,
2213
+ startTime: Date.now()
2214
+ },
2215
+ technical: {
2216
+ environment: "browser",
2217
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
2218
+ stackTrace: originalError instanceof Error ? originalError.stack : void 0
2219
+ }
2220
+ },
2221
+ error
2222
+ };
2223
+ yield onError(traceEvent);
2224
+ } catch (traceError) {
2225
+ console.error("Error in use-chat onError handler:", traceError);
2226
+ }
2227
+ });
2067
2228
  const agentSessionRef = (0, import_react11.useRef)(agentSession);
2068
2229
  agentSessionRef.current = agentSession;
2069
2230
  const runIdRef = (0, import_react11.useRef)(runId);
@@ -2083,7 +2244,7 @@ function useChat(options) {
2083
2244
  const pendingAppendsRef = (0, import_react11.useRef)([]);
2084
2245
  const runChatCompletion = useAsyncCallback(
2085
2246
  (previousMessages) => __async(this, null, function* () {
2086
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2247
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
2087
2248
  setIsLoading(true);
2088
2249
  const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
2089
2250
  if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql6.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
@@ -2215,20 +2376,53 @@ function useChat(options) {
2215
2376
  messages2 = (0, import_runtime_client_gql6.convertGqlOutputToMessages)(
2216
2377
  (0, import_runtime_client_gql6.filterAdjacentAgentStateMessages)(rawMessagesResponse)
2217
2378
  );
2218
- if (messages2.length === 0) {
2219
- continue;
2220
- }
2221
2379
  newMessages = [];
2222
2380
  if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
2381
+ const guardrailsReason = ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || "";
2223
2382
  newMessages = [
2224
2383
  new import_runtime_client_gql6.TextMessage({
2225
2384
  role: import_runtime_client_gql6.MessageRole.Assistant,
2226
- content: ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || ""
2385
+ content: guardrailsReason
2227
2386
  })
2228
2387
  ];
2388
+ const guardrailsError = new import_shared12.CopilotKitError({
2389
+ message: `Guardrails validation failed: ${guardrailsReason}`,
2390
+ code: import_shared12.CopilotKitErrorCode.MISUSE
2391
+ });
2392
+ yield traceUIError(guardrailsError, {
2393
+ statusReason: value.generateCopilotResponse.status.reason,
2394
+ statusDetails: value.generateCopilotResponse.status.details
2395
+ });
2229
2396
  setMessages([...previousMessages, ...newMessages]);
2230
2397
  break;
2231
- } else {
2398
+ }
2399
+ if (((_m = value.generateCopilotResponse.status) == null ? void 0 : _m.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "UNKNOWN_ERROR") {
2400
+ const errorMessage = ((_n = value.generateCopilotResponse.status.details) == null ? void 0 : _n.description) || "An unknown error occurred";
2401
+ const statusDetails = value.generateCopilotResponse.status.details;
2402
+ const originalError = (statusDetails == null ? void 0 : statusDetails.originalError) || (statusDetails == null ? void 0 : statusDetails.error);
2403
+ const originalCode = (originalError == null ? void 0 : originalError.code) || ((_o = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _o.code);
2404
+ const originalSeverity = (originalError == null ? void 0 : originalError.severity) || ((_p = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _p.severity);
2405
+ const originalVisibility = (originalError == null ? void 0 : originalError.visibility) || ((_q = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _q.visibility);
2406
+ let errorCode = import_shared12.CopilotKitErrorCode.NETWORK_ERROR;
2407
+ if (originalCode && Object.values(import_shared12.CopilotKitErrorCode).includes(originalCode)) {
2408
+ errorCode = originalCode;
2409
+ }
2410
+ const structuredError = new import_shared12.CopilotKitError({
2411
+ message: errorMessage,
2412
+ code: errorCode,
2413
+ severity: originalSeverity,
2414
+ visibility: originalVisibility
2415
+ });
2416
+ setBannerError(structuredError);
2417
+ yield traceUIError(structuredError, {
2418
+ statusReason: value.generateCopilotResponse.status.reason,
2419
+ statusDetails: value.generateCopilotResponse.status.details,
2420
+ originalErrorCode: originalCode,
2421
+ preservedStructure: !!originalCode
2422
+ });
2423
+ setIsLoading(false);
2424
+ break;
2425
+ } else if (messages2.length > 0) {
2232
2426
  newMessages = [...messages2];
2233
2427
  for (const message of messages2) {
2234
2428
  if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
@@ -2290,6 +2484,39 @@ function useChat(options) {
2290
2484
  newMessages
2291
2485
  );
2292
2486
  let didExecuteAction = false;
2487
+ const executeActionFromMessage = (currentAction, actionMessage) => __async(this, null, function* () {
2488
+ var _a2;
2489
+ const isInterruptAction = interruptMessages.find((m) => m.id === actionMessage.id);
2490
+ followUp = (_a2 = currentAction == null ? void 0 : currentAction.followUp) != null ? _a2 : !isInterruptAction;
2491
+ if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
2492
+ currentAction._setActivatingMessageId(actionMessage.id);
2493
+ }
2494
+ const resultMessage = yield executeAction({
2495
+ onFunctionCall,
2496
+ message: actionMessage,
2497
+ chatAbortControllerRef,
2498
+ onError: (error) => {
2499
+ addErrorToast([error]);
2500
+ console.error(`Failed to execute action ${actionMessage.name}: ${error}`);
2501
+ },
2502
+ setMessages,
2503
+ getFinalMessages: () => finalMessages,
2504
+ isRenderAndWait: (currentAction == null ? void 0 : currentAction._isRenderAndWait) || false
2505
+ });
2506
+ didExecuteAction = true;
2507
+ const messageIndex = finalMessages.findIndex((msg) => msg.id === actionMessage.id);
2508
+ finalMessages.splice(messageIndex + 1, 0, resultMessage);
2509
+ if (currentAction == null ? void 0 : currentAction._isRenderAndWait) {
2510
+ const messagesForImmediateUpdate = [...finalMessages];
2511
+ (0, import_react_dom2.flushSync)(() => {
2512
+ setMessages(messagesForImmediateUpdate);
2513
+ });
2514
+ }
2515
+ if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
2516
+ currentAction._setActivatingMessageId(null);
2517
+ }
2518
+ return resultMessage;
2519
+ });
2293
2520
  if (onFunctionCall) {
2294
2521
  const lastMessages = [];
2295
2522
  for (let i = finalMessages.length - 1; i >= 0; i--) {
@@ -2306,37 +2533,28 @@ function useChat(options) {
2306
2533
  (action2) => action2.name === message.name
2307
2534
  );
2308
2535
  const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
2309
- const executeActionFromMessage = (action2, message2) => __async(this, null, function* () {
2310
- var _a2;
2311
- const isInterruptAction = interruptMessages.find((m) => m.id === message2.id);
2312
- followUp = (_a2 = action2 == null ? void 0 : action2.followUp) != null ? _a2 : !isInterruptAction;
2313
- const resultMessage = yield executeAction({
2314
- onFunctionCall,
2315
- previousMessages,
2316
- message: message2,
2317
- chatAbortControllerRef,
2318
- onError: (error) => {
2319
- addErrorToast([error]);
2320
- console.error(`Failed to execute action ${message2.name}: ${error}`);
2321
- }
2322
- });
2323
- didExecuteAction = true;
2324
- const messageIndex = finalMessages.findIndex((msg) => msg.id === message2.id);
2325
- finalMessages.splice(messageIndex + 1, 0, resultMessage);
2326
- return resultMessage;
2327
- });
2328
2536
  if (action && message.isActionExecutionMessage()) {
2329
- const resultMessage = yield executeActionFromMessage(action, message);
2330
- const pairedFeAction = getPairedFeAction(actions, resultMessage);
2331
- if (pairedFeAction) {
2332
- const newExecutionMessage = new import_runtime_client_gql6.ActionExecutionMessage({
2333
- name: pairedFeAction.name,
2334
- arguments: (0, import_shared12.parseJson)(resultMessage.result, resultMessage.result),
2335
- status: message.status,
2336
- createdAt: message.createdAt,
2337
- parentMessageId: message.parentMessageId
2338
- });
2339
- yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
2537
+ const isRenderAndWaitAction = (action == null ? void 0 : action._isRenderAndWait) || false;
2538
+ const alreadyProcessed = isRenderAndWaitAction && finalMessages.some(
2539
+ (fm) => fm.isResultMessage() && fm.actionExecutionId === message.id
2540
+ );
2541
+ if (alreadyProcessed) {
2542
+ } else {
2543
+ const resultMessage = yield executeActionFromMessage(
2544
+ action,
2545
+ message
2546
+ );
2547
+ const pairedFeAction = getPairedFeAction(actions, resultMessage);
2548
+ if (pairedFeAction) {
2549
+ const newExecutionMessage = new import_runtime_client_gql6.ActionExecutionMessage({
2550
+ name: pairedFeAction.name,
2551
+ arguments: (0, import_shared12.parseJson)(resultMessage.result, resultMessage.result),
2552
+ status: message.status,
2553
+ createdAt: message.createdAt,
2554
+ parentMessageId: message.parentMessageId
2555
+ });
2556
+ yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
2557
+ }
2340
2558
  }
2341
2559
  } else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
2342
2560
  const newExecutionMessage = new import_runtime_client_gql6.ActionExecutionMessage({
@@ -2354,16 +2572,12 @@ function useChat(options) {
2354
2572
  }
2355
2573
  setMessages(finalMessages);
2356
2574
  }
2357
- if (
2358
- // if followUp is not explicitly false
2359
- followUp !== false && // and we executed an action
2360
- (didExecuteAction || // the last message is a server side result
2361
- !isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
2362
- !((_m = chatAbortControllerRef.current) == null ? void 0 : _m.signal.aborted)
2363
- ) {
2575
+ if (followUp !== false && (didExecuteAction || // the last message is a server side result
2576
+ !isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
2577
+ !((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)) {
2364
2578
  yield new Promise((resolve) => setTimeout(resolve, 10));
2365
2579
  return yield runChatCompletionRef.current(finalMessages);
2366
- } else if ((_n = chatAbortControllerRef.current) == null ? void 0 : _n.signal.aborted) {
2580
+ } else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
2367
2581
  const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
2368
2582
  if (message.isActionExecutionMessage()) {
2369
2583
  return finalMessages.find(
@@ -2374,7 +2588,7 @@ function useChat(options) {
2374
2588
  });
2375
2589
  const repairedMessageIds = repairedMessages.map((message) => message.id);
2376
2590
  setMessages(repairedMessages);
2377
- if ((_o = agentSessionRef.current) == null ? void 0 : _o.nodeName) {
2591
+ if ((_t = agentSessionRef.current) == null ? void 0 : _t.nodeName) {
2378
2592
  setAgentSession({
2379
2593
  threadId: agentSessionRef.current.threadId,
2380
2594
  agentName: agentSessionRef.current.agentName,
@@ -2468,21 +2682,35 @@ function useChat(options) {
2468
2682
  [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
2469
2683
  );
2470
2684
  const reload = useAsyncCallback(
2471
- (messageId) => __async(this, null, function* () {
2685
+ (reloadMessageId) => __async(this, null, function* () {
2472
2686
  if (isLoading || messages.length === 0) {
2473
2687
  return;
2474
2688
  }
2475
- const index = messages.findIndex((msg) => msg.id === messageId);
2476
- if (index === -1) {
2477
- console.warn(`Message with id ${messageId} not found`);
2689
+ const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);
2690
+ if (reloadMessageIndex === -1) {
2691
+ console.warn(`Message with id ${reloadMessageId} not found`);
2478
2692
  return;
2479
2693
  }
2480
- let newMessages = messages.slice(0, index);
2481
- if (newMessages.length > 0 && newMessages[newMessages.length - 1].isAgentStateMessage()) {
2482
- newMessages = newMessages.slice(0, newMessages.length - 1);
2694
+ const reloadMessageRole = messages[reloadMessageIndex].role;
2695
+ if (reloadMessageRole !== import_runtime_client_gql6.MessageRole.Assistant) {
2696
+ console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);
2697
+ return;
2483
2698
  }
2484
- setMessages(newMessages);
2485
- return runChatCompletionAndHandleFunctionCall(newMessages);
2699
+ let historyCutoff = [];
2700
+ if (messages.length > 2) {
2701
+ const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find(
2702
+ (msg) => (
2703
+ // @ts-expect-error -- message has role
2704
+ msg.role === import_runtime_client_gql6.MessageRole.User
2705
+ )
2706
+ );
2707
+ const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
2708
+ (msg) => msg.id === lastUserMessageBeforeRegenerate.id
2709
+ );
2710
+ historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
2711
+ }
2712
+ setMessages(historyCutoff);
2713
+ return runChatCompletionAndHandleFunctionCall(historyCutoff);
2486
2714
  }),
2487
2715
  [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
2488
2716
  );
@@ -2517,20 +2745,31 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
2517
2745
  function executeAction(_0) {
2518
2746
  return __async(this, arguments, function* ({
2519
2747
  onFunctionCall,
2520
- previousMessages,
2521
2748
  message,
2522
2749
  chatAbortControllerRef,
2523
- onError
2750
+ onError,
2751
+ setMessages,
2752
+ getFinalMessages,
2753
+ isRenderAndWait
2524
2754
  }) {
2525
2755
  let result;
2526
2756
  let error = null;
2757
+ const currentMessagesForHandler = getFinalMessages();
2758
+ const handlerReturnedPromise = onFunctionCall({
2759
+ messages: currentMessagesForHandler,
2760
+ name: message.name,
2761
+ args: message.arguments
2762
+ });
2763
+ if (isRenderAndWait) {
2764
+ const currentMessagesForRender = getFinalMessages();
2765
+ (0, import_react_dom2.flushSync)(() => {
2766
+ setMessages([...currentMessagesForRender]);
2767
+ });
2768
+ }
2527
2769
  try {
2528
2770
  result = yield Promise.race([
2529
- onFunctionCall({
2530
- messages: previousMessages,
2531
- name: message.name,
2532
- args: message.arguments
2533
- }),
2771
+ handlerReturnedPromise,
2772
+ // Await the promise returned by the handler
2534
2773
  new Promise(
2535
2774
  (resolve) => {
2536
2775
  var _a;
@@ -2797,6 +3036,7 @@ function useCopilotAction(action, dependencies) {
2797
3036
  const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
2798
3037
  const idRef = (0, import_react13.useRef)((0, import_shared13.randomId)());
2799
3038
  const renderAndWaitRef = (0, import_react13.useRef)(null);
3039
+ const activatingMessageIdRef = (0, import_react13.useRef)(null);
2800
3040
  const { addToast } = useToast();
2801
3041
  action = __spreadValues({}, action);
2802
3042
  if (
@@ -2804,30 +3044,48 @@ function useCopilotAction(action, dependencies) {
2804
3044
  isFrontendAction(action) && // check if renderAndWaitForResponse is set
2805
3045
  (action.renderAndWait || action.renderAndWaitForResponse)
2806
3046
  ) {
3047
+ action._isRenderAndWait = true;
2807
3048
  const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
2808
3049
  action.renderAndWait = void 0;
2809
3050
  action.renderAndWaitForResponse = void 0;
3051
+ action._setActivatingMessageId = (id) => {
3052
+ activatingMessageIdRef.current = id;
3053
+ };
2810
3054
  action.handler = useAsyncCallback(() => __async(this, null, function* () {
3055
+ const currentActivatingId = activatingMessageIdRef.current;
2811
3056
  let resolve;
2812
3057
  let reject;
2813
3058
  const promise = new Promise((resolvePromise, rejectPromise) => {
2814
3059
  resolve = resolvePromise;
2815
3060
  reject = rejectPromise;
2816
3061
  });
2817
- renderAndWaitRef.current = { promise, resolve, reject };
2818
- return yield promise;
3062
+ renderAndWaitRef.current = {
3063
+ promise,
3064
+ resolve,
3065
+ reject,
3066
+ messageId: currentActivatingId
3067
+ };
3068
+ const result = yield promise;
3069
+ return result;
2819
3070
  }), []);
2820
3071
  action.render = (props) => {
3072
+ const currentRenderMessageId = props.messageId;
2821
3073
  let status = props.status;
2822
- if (props.status === "executing" && !renderAndWaitRef.current) {
2823
- status = "inProgress";
3074
+ if (props.status === "executing") {
3075
+ if (!renderAndWaitRef.current || !renderAndWaitRef.current.promise) {
3076
+ status = "inProgress";
3077
+ } else if (renderAndWaitRef.current.messageId !== currentRenderMessageId && activatingMessageIdRef.current !== currentRenderMessageId) {
3078
+ status = "inProgress";
3079
+ }
2824
3080
  }
2825
3081
  const waitProps = {
2826
3082
  status,
2827
3083
  args: props.args,
2828
3084
  result: props.result,
2829
- handler: status === "executing" ? renderAndWaitRef.current.resolve : void 0,
2830
- respond: status === "executing" ? renderAndWaitRef.current.resolve : void 0
3085
+ // handler and respond should only be provided if this is the truly active instance
3086
+ // and its promise infrastructure is ready.
3087
+ handler: status === "executing" && renderAndWaitRef.current && renderAndWaitRef.current.messageId === currentRenderMessageId ? renderAndWaitRef.current.resolve : void 0,
3088
+ respond: status === "executing" && renderAndWaitRef.current && renderAndWaitRef.current.messageId === currentRenderMessageId ? renderAndWaitRef.current.resolve : void 0
2831
3089
  };
2832
3090
  const isNoArgsRenderWait = (_fn) => {
2833
3091
  var _a;
@@ -3070,6 +3328,9 @@ function useCoAgent(options) {
3070
3328
  threadId,
3071
3329
  agentName: name
3072
3330
  });
3331
+ if (result.error) {
3332
+ return;
3333
+ }
3073
3334
  const newState = (_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.state;
3074
3335
  if (newState === lastLoadedState.current)
3075
3336
  return;