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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/{chunk-CCESTGAM.mjs → chunk-3OQM3NEK.mjs} +2 -2
  3. package/dist/{chunk-T4ZKC4X4.mjs → chunk-3YHYWAHK.mjs} +2 -2
  4. package/dist/{chunk-ISYBUDL4.mjs → chunk-55QZ2SVJ.mjs} +4 -5
  5. package/dist/chunk-55QZ2SVJ.mjs.map +1 -0
  6. package/dist/chunk-57K2ZJ5F.mjs +348 -0
  7. package/dist/chunk-57K2ZJ5F.mjs.map +1 -0
  8. package/dist/{chunk-ZHEEHGLS.mjs → chunk-ADIITPD2.mjs} +8 -5
  9. package/dist/{chunk-ZHEEHGLS.mjs.map → chunk-ADIITPD2.mjs.map} +1 -1
  10. package/dist/{chunk-S4BOATBG.mjs → chunk-EF5BNM34.mjs} +2 -2
  11. package/dist/{chunk-I4JPQECN.mjs → chunk-EXU7GWLC.mjs} +4 -4
  12. package/dist/{chunk-7G6RR4HE.mjs → chunk-FXK6RQIN.mjs} +2 -2
  13. package/dist/{chunk-JXF732XG.mjs → chunk-G7LYGERN.mjs} +80 -13
  14. package/dist/chunk-G7LYGERN.mjs.map +1 -0
  15. package/dist/{chunk-VJCHRQ7Q.mjs → chunk-JDEWNLNP.mjs} +37 -4
  16. package/dist/chunk-JDEWNLNP.mjs.map +1 -0
  17. package/dist/{chunk-JHIZ5HAI.mjs → chunk-NQVCZQ5T.mjs} +3 -3
  18. package/dist/{chunk-VF6UPRKM.mjs → chunk-OF4SZTLL.mjs} +3 -3
  19. package/dist/{chunk-QQZLIEXK.mjs → chunk-SJJNFYGQ.mjs} +3 -3
  20. package/dist/{chunk-RN3ZRHI7.mjs → chunk-WOGURSAL.mjs} +5 -5
  21. package/dist/chunk-YAF2LATQ.mjs +310 -0
  22. package/dist/chunk-YAF2LATQ.mjs.map +1 -0
  23. package/dist/components/copilot-provider/copilot-messages.js +35 -2
  24. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  25. package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
  26. package/dist/components/copilot-provider/copilotkit.js +289 -234
  27. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  28. package/dist/components/copilot-provider/copilotkit.mjs +7 -7
  29. package/dist/components/copilot-provider/index.js +289 -234
  30. package/dist/components/copilot-provider/index.js.map +1 -1
  31. package/dist/components/copilot-provider/index.mjs +7 -7
  32. package/dist/components/error-boundary/error-boundary.js +135 -146
  33. package/dist/components/error-boundary/error-boundary.js.map +1 -1
  34. package/dist/components/error-boundary/error-boundary.mjs +4 -4
  35. package/dist/components/error-boundary/error-utils.js.map +1 -1
  36. package/dist/components/error-boundary/error-utils.mjs +2 -2
  37. package/dist/components/index.js +289 -234
  38. package/dist/components/index.js.map +1 -1
  39. package/dist/components/index.mjs +7 -7
  40. package/dist/components/toast/toast-provider.js +118 -85
  41. package/dist/components/toast/toast-provider.js.map +1 -1
  42. package/dist/components/toast/toast-provider.mjs +1 -1
  43. package/dist/components/usage-banner.js +135 -146
  44. package/dist/components/usage-banner.js.map +1 -1
  45. package/dist/components/usage-banner.mjs +1 -1
  46. package/dist/hooks/index.js +75 -10
  47. package/dist/hooks/index.js.map +1 -1
  48. package/dist/hooks/index.mjs +14 -14
  49. package/dist/hooks/use-chat.js +72 -10
  50. package/dist/hooks/use-chat.js.map +1 -1
  51. package/dist/hooks/use-chat.mjs +4 -4
  52. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  53. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  54. package/dist/hooks/use-coagent.js +75 -10
  55. package/dist/hooks/use-coagent.js.map +1 -1
  56. package/dist/hooks/use-coagent.mjs +10 -10
  57. package/dist/hooks/use-copilot-action.js.map +1 -1
  58. package/dist/hooks/use-copilot-action.mjs +3 -3
  59. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  60. package/dist/hooks/use-copilot-authenticated-action.mjs +4 -4
  61. package/dist/hooks/use-copilot-chat.js +72 -10
  62. package/dist/hooks/use-copilot-chat.js.map +1 -1
  63. package/dist/hooks/use-copilot-chat.mjs +9 -9
  64. package/dist/hooks/use-copilot-runtime-client.js +1 -1
  65. package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
  66. package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
  67. package/dist/hooks/use-langgraph-interrupt.js +72 -10
  68. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  69. package/dist/hooks/use-langgraph-interrupt.mjs +10 -10
  70. package/dist/index.js +363 -243
  71. package/dist/index.js.map +1 -1
  72. package/dist/index.mjs +15 -15
  73. package/dist/lib/copilot-task.mjs +8 -8
  74. package/dist/lib/index.mjs +8 -8
  75. package/dist/utils/extract.mjs +7 -7
  76. package/dist/utils/index.mjs +7 -7
  77. package/jest.config.js +7 -3
  78. package/package.json +4 -3
  79. package/src/components/copilot-provider/__tests__/copilotkit-trace.test.tsx +1 -0
  80. package/src/components/copilot-provider/copilot-messages.tsx +42 -3
  81. package/src/components/toast/toast-provider.tsx +49 -24
  82. package/src/components/usage-banner.tsx +144 -147
  83. package/src/hooks/use-chat.ts +106 -6
  84. package/src/hooks/use-coagent.ts +5 -0
  85. package/src/hooks/use-copilot-runtime-client.ts +2 -39
  86. package/tsconfig.json +1 -8
  87. package/dist/chunk-HD2GE3DK.mjs +0 -359
  88. package/dist/chunk-HD2GE3DK.mjs.map +0 -1
  89. package/dist/chunk-ISYBUDL4.mjs.map +0 -1
  90. package/dist/chunk-JXF732XG.mjs.map +0 -1
  91. package/dist/chunk-VJCHRQ7Q.mjs.map +0 -1
  92. package/dist/chunk-VRXANACV.mjs +0 -277
  93. package/dist/chunk-VRXANACV.mjs.map +0 -1
  94. /package/dist/{chunk-CCESTGAM.mjs.map → chunk-3OQM3NEK.mjs.map} +0 -0
  95. /package/dist/{chunk-T4ZKC4X4.mjs.map → chunk-3YHYWAHK.mjs.map} +0 -0
  96. /package/dist/{chunk-S4BOATBG.mjs.map → chunk-EF5BNM34.mjs.map} +0 -0
  97. /package/dist/{chunk-I4JPQECN.mjs.map → chunk-EXU7GWLC.mjs.map} +0 -0
  98. /package/dist/{chunk-7G6RR4HE.mjs.map → chunk-FXK6RQIN.mjs.map} +0 -0
  99. /package/dist/{chunk-JHIZ5HAI.mjs.map → chunk-NQVCZQ5T.mjs.map} +0 -0
  100. /package/dist/{chunk-VF6UPRKM.mjs.map → chunk-OF4SZTLL.mjs.map} +0 -0
  101. /package/dist/{chunk-QQZLIEXK.mjs.map → chunk-SJJNFYGQ.mjs.map} +0 -0
  102. /package/dist/{chunk-RN3ZRHI7.mjs.map → chunk-WOGURSAL.mjs.map} +0 -0
@@ -4,52 +4,52 @@ import {
4
4
  } from "../chunk-CMQV4XNY.mjs";
5
5
  import {
6
6
  useLangGraphInterrupt
7
- } from "../chunk-VF6UPRKM.mjs";
7
+ } from "../chunk-OF4SZTLL.mjs";
8
8
  import {
9
9
  useMakeCopilotDocumentReadable
10
10
  } from "../chunk-ERXWDCY6.mjs";
11
11
  import {
12
12
  useCoAgentStateRender
13
- } from "../chunk-T4ZKC4X4.mjs";
13
+ } from "../chunk-3YHYWAHK.mjs";
14
14
  import {
15
15
  runAgent,
16
16
  startAgent,
17
17
  stopAgent,
18
18
  useCoAgent
19
- } from "../chunk-ZHEEHGLS.mjs";
19
+ } from "../chunk-ADIITPD2.mjs";
20
20
  import {
21
21
  useCopilotAdditionalInstructions
22
22
  } from "../chunk-JPMIAGI6.mjs";
23
23
  import {
24
24
  useCopilotAuthenticatedAction_c
25
- } from "../chunk-S4BOATBG.mjs";
25
+ } from "../chunk-EF5BNM34.mjs";
26
26
  import {
27
27
  useCopilotAction
28
- } from "../chunk-JHIZ5HAI.mjs";
28
+ } from "../chunk-NQVCZQ5T.mjs";
29
29
  import {
30
30
  useCopilotChat
31
- } from "../chunk-I4JPQECN.mjs";
31
+ } from "../chunk-EXU7GWLC.mjs";
32
32
  import {
33
33
  useCopilotReadable
34
34
  } from "../chunk-UBNRUXEK.mjs";
35
- import "../chunk-RN3ZRHI7.mjs";
36
- import "../chunk-QQZLIEXK.mjs";
37
- import "../chunk-VJCHRQ7Q.mjs";
35
+ import "../chunk-WOGURSAL.mjs";
36
+ import "../chunk-SJJNFYGQ.mjs";
37
+ import "../chunk-JDEWNLNP.mjs";
38
38
  import "../chunk-5FHSUKQL.mjs";
39
39
  import "../chunk-RKTVJRK7.mjs";
40
40
  import "../chunk-PMAFHQ7P.mjs";
41
- import "../chunk-HD2GE3DK.mjs";
41
+ import "../chunk-57K2ZJ5F.mjs";
42
42
  import "../chunk-YPSGKPDA.mjs";
43
43
  import "../chunk-DCTJZ742.mjs";
44
- import "../chunk-JXF732XG.mjs";
44
+ import "../chunk-G7LYGERN.mjs";
45
45
  import "../chunk-4CEQJ2X6.mjs";
46
- import "../chunk-CCESTGAM.mjs";
46
+ import "../chunk-3OQM3NEK.mjs";
47
47
  import "../chunk-O7ARI5CV.mjs";
48
48
  import {
49
49
  useCopilotRuntimeClient
50
- } from "../chunk-ISYBUDL4.mjs";
50
+ } from "../chunk-55QZ2SVJ.mjs";
51
51
  import "../chunk-GFJW4RIM.mjs";
52
- import "../chunk-VRXANACV.mjs";
52
+ import "../chunk-YAF2LATQ.mjs";
53
53
  import "../chunk-XFOTNHYA.mjs";
54
54
  import "../chunk-SKC7AJIV.mjs";
55
55
  export {
@@ -156,7 +156,7 @@ var useCopilotRuntimeClient = (options) => {
156
156
  startTime: Date.now()
157
157
  },
158
158
  technical: {
159
- environment: process.env.NODE_ENV,
159
+ environment: "browser",
160
160
  userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
161
161
  stackTrace: originalError instanceof Error ? originalError.stack : void 0
162
162
  }
@@ -489,6 +489,35 @@ function useChat(options) {
489
489
  } = options;
490
490
  const runChatCompletionRef = (0, import_react5.useRef)();
491
491
  const addErrorToast = useErrorToast();
492
+ const { setBannerError } = useToast();
493
+ const { onTrace } = useCopilotContext();
494
+ const traceUIError = (error, originalError) => __async(this, null, function* () {
495
+ if (!onTrace || !(copilotConfig == null ? void 0 : copilotConfig.publicApiKey))
496
+ return;
497
+ try {
498
+ const traceEvent = {
499
+ type: "error",
500
+ timestamp: Date.now(),
501
+ context: {
502
+ source: "ui",
503
+ request: {
504
+ operation: "useChatCompletion",
505
+ url: copilotConfig.chatApiEndpoint,
506
+ startTime: Date.now()
507
+ },
508
+ technical: {
509
+ environment: "browser",
510
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
511
+ stackTrace: originalError instanceof Error ? originalError.stack : void 0
512
+ }
513
+ },
514
+ error
515
+ };
516
+ yield onTrace(traceEvent);
517
+ } catch (traceError) {
518
+ console.error("Error in use-chat onTrace handler:", traceError);
519
+ }
520
+ });
492
521
  const agentSessionRef = (0, import_react5.useRef)(agentSession);
493
522
  agentSessionRef.current = agentSession;
494
523
  const runIdRef = (0, import_react5.useRef)(runId);
@@ -508,7 +537,7 @@ function useChat(options) {
508
537
  const pendingAppendsRef = (0, import_react5.useRef)([]);
509
538
  const runChatCompletion = useAsyncCallback(
510
539
  (previousMessages) => __async(this, null, function* () {
511
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
540
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
512
541
  setIsLoading(true);
513
542
  const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
514
543
  if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
@@ -640,20 +669,53 @@ function useChat(options) {
640
669
  messages2 = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
641
670
  (0, import_runtime_client_gql3.filterAdjacentAgentStateMessages)(rawMessagesResponse)
642
671
  );
643
- if (messages2.length === 0) {
644
- continue;
645
- }
646
672
  newMessages = [];
647
673
  if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
674
+ const guardrailsReason = ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || "";
648
675
  newMessages = [
649
676
  new import_runtime_client_gql3.TextMessage({
650
677
  role: import_runtime_client_gql3.MessageRole.Assistant,
651
- content: ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || ""
678
+ content: guardrailsReason
652
679
  })
653
680
  ];
681
+ const guardrailsError = new import_shared4.CopilotKitError({
682
+ message: `Guardrails validation failed: ${guardrailsReason}`,
683
+ code: import_shared4.CopilotKitErrorCode.MISUSE
684
+ });
685
+ yield traceUIError(guardrailsError, {
686
+ statusReason: value.generateCopilotResponse.status.reason,
687
+ statusDetails: value.generateCopilotResponse.status.details
688
+ });
654
689
  setMessages([...previousMessages, ...newMessages]);
655
690
  break;
656
- } else {
691
+ }
692
+ if (((_m = value.generateCopilotResponse.status) == null ? void 0 : _m.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "UNKNOWN_ERROR") {
693
+ const errorMessage = ((_n = value.generateCopilotResponse.status.details) == null ? void 0 : _n.description) || "An unknown error occurred";
694
+ const statusDetails = value.generateCopilotResponse.status.details;
695
+ const originalError = (statusDetails == null ? void 0 : statusDetails.originalError) || (statusDetails == null ? void 0 : statusDetails.error);
696
+ const originalCode = (originalError == null ? void 0 : originalError.code) || ((_o = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _o.code);
697
+ const originalSeverity = (originalError == null ? void 0 : originalError.severity) || ((_p = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _p.severity);
698
+ const originalVisibility = (originalError == null ? void 0 : originalError.visibility) || ((_q = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _q.visibility);
699
+ let errorCode = import_shared4.CopilotKitErrorCode.NETWORK_ERROR;
700
+ if (originalCode && Object.values(import_shared4.CopilotKitErrorCode).includes(originalCode)) {
701
+ errorCode = originalCode;
702
+ }
703
+ const structuredError = new import_shared4.CopilotKitError({
704
+ message: errorMessage,
705
+ code: errorCode,
706
+ severity: originalSeverity,
707
+ visibility: originalVisibility
708
+ });
709
+ setBannerError(structuredError);
710
+ yield traceUIError(structuredError, {
711
+ statusReason: value.generateCopilotResponse.status.reason,
712
+ statusDetails: value.generateCopilotResponse.status.details,
713
+ originalErrorCode: originalCode,
714
+ preservedStructure: !!originalCode
715
+ });
716
+ setIsLoading(false);
717
+ break;
718
+ } else if (messages2.length > 0) {
657
719
  newMessages = [...messages2];
658
720
  for (const message of messages2) {
659
721
  if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
@@ -784,11 +846,11 @@ function useChat(options) {
784
846
  followUp !== false && // and we executed an action
785
847
  (didExecuteAction || // the last message is a server side result
786
848
  !isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
787
- !((_m = chatAbortControllerRef.current) == null ? void 0 : _m.signal.aborted)
849
+ !((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)
788
850
  ) {
789
851
  yield new Promise((resolve) => setTimeout(resolve, 10));
790
852
  return yield runChatCompletionRef.current(finalMessages);
791
- } else if ((_n = chatAbortControllerRef.current) == null ? void 0 : _n.signal.aborted) {
853
+ } else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
792
854
  const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
793
855
  if (message.isActionExecutionMessage()) {
794
856
  return finalMessages.find(
@@ -799,7 +861,7 @@ function useChat(options) {
799
861
  });
800
862
  const repairedMessageIds = repairedMessages.map((message) => message.id);
801
863
  setMessages(repairedMessages);
802
- if ((_o = agentSessionRef.current) == null ? void 0 : _o.nodeName) {
864
+ if ((_t = agentSessionRef.current) == null ? void 0 : _t.nodeName) {
803
865
  setAgentSession({
804
866
  threadId: agentSessionRef.current.threadId,
805
867
  agentName: agentSessionRef.current.agentName,