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

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