@copilotkit/react-core 1.9.2-next.9 → 1.9.3-next.0

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 (147) hide show
  1. package/CHANGELOG.md +191 -0
  2. package/dist/{chunk-ERXWDCY6.mjs → chunk-36MGCCPZ.mjs} +2 -2
  3. package/dist/{chunk-UBNRUXEK.mjs → chunk-5BSUSFHM.mjs} +2 -2
  4. package/dist/{chunk-G7LYGERN.mjs → chunk-6ZLSC4KB.mjs} +124 -73
  5. package/dist/chunk-6ZLSC4KB.mjs.map +1 -0
  6. package/dist/{chunk-JDEWNLNP.mjs → chunk-BSAVFYRQ.mjs} +11 -11
  7. package/dist/{chunk-JDEWNLNP.mjs.map → chunk-BSAVFYRQ.mjs.map} +1 -1
  8. package/dist/{chunk-JPMIAGI6.mjs → chunk-BVK7PLK6.mjs} +2 -2
  9. package/dist/{chunk-FXK6RQIN.mjs → chunk-CUAFWKTQ.mjs} +4 -4
  10. package/dist/{chunk-XFOTNHYA.mjs → chunk-DKZTPL66.mjs} +2 -2
  11. package/dist/{chunk-XFOTNHYA.mjs.map → chunk-DKZTPL66.mjs.map} +1 -1
  12. package/dist/{chunk-EF5BNM34.mjs → chunk-FN3UA2ZE.mjs} +3 -3
  13. package/dist/{chunk-EXU7GWLC.mjs → chunk-GEE5AMYL.mjs} +9 -9
  14. package/dist/{chunk-WOGURSAL.mjs → chunk-GIMSRCVW.mjs} +64 -23
  15. package/dist/chunk-GIMSRCVW.mjs.map +1 -0
  16. package/dist/{chunk-55QZ2SVJ.mjs → chunk-JWAXDYOW.mjs} +8 -8
  17. package/dist/chunk-JWAXDYOW.mjs.map +1 -0
  18. package/dist/{chunk-3YHYWAHK.mjs → chunk-KIXKBJUV.mjs} +2 -2
  19. package/dist/{chunk-ADIITPD2.mjs → chunk-KLENTCQV.mjs} +34 -8
  20. package/dist/{chunk-ADIITPD2.mjs.map → chunk-KLENTCQV.mjs.map} +1 -1
  21. package/dist/{chunk-OF4SZTLL.mjs → chunk-NGQN3JRJ.mjs} +3 -3
  22. package/dist/{chunk-NQVCZQ5T.mjs → chunk-NJA5ZLAZ.mjs} +27 -8
  23. package/dist/chunk-NJA5ZLAZ.mjs.map +1 -0
  24. package/dist/{chunk-SJJNFYGQ.mjs → chunk-SGF6C7I6.mjs} +4 -4
  25. package/dist/{chunk-CMQV4XNY.mjs → chunk-VDADWRS3.mjs} +2 -2
  26. package/dist/components/copilot-provider/copilot-messages.js +7 -7
  27. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  28. package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
  29. package/dist/components/copilot-provider/copilotkit-props.d.ts +14 -9
  30. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  31. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  32. package/dist/components/copilot-provider/copilotkit.js +70 -29
  33. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  34. package/dist/components/copilot-provider/copilotkit.mjs +9 -9
  35. package/dist/components/copilot-provider/index.d.ts +1 -1
  36. package/dist/components/copilot-provider/index.js +70 -29
  37. package/dist/components/copilot-provider/index.js.map +1 -1
  38. package/dist/components/copilot-provider/index.mjs +9 -9
  39. package/dist/components/error-boundary/error-boundary.mjs +2 -2
  40. package/dist/components/index.d.ts +1 -1
  41. package/dist/components/index.js +70 -29
  42. package/dist/components/index.js.map +1 -1
  43. package/dist/components/index.mjs +9 -9
  44. package/dist/context/copilot-context.d.ts +1 -1
  45. package/dist/context/copilot-context.js +1 -1
  46. package/dist/context/copilot-context.js.map +1 -1
  47. package/dist/context/copilot-context.mjs +1 -1
  48. package/dist/context/index.d.ts +1 -1
  49. package/dist/context/index.js +1 -1
  50. package/dist/context/index.js.map +1 -1
  51. package/dist/context/index.mjs +4 -4
  52. package/dist/{copilot-context-3da805ab.d.ts → copilot-context-3ab4fdf5.d.ts} +3 -3
  53. package/dist/hooks/index.d.ts +1 -1
  54. package/dist/hooks/index.js +179 -83
  55. package/dist/hooks/index.js.map +1 -1
  56. package/dist/hooks/index.mjs +23 -23
  57. package/dist/hooks/use-chat.d.ts +1 -1
  58. package/dist/hooks/use-chat.js +220 -169
  59. package/dist/hooks/use-chat.js.map +1 -1
  60. package/dist/hooks/use-chat.mjs +4 -4
  61. package/dist/hooks/use-coagent-state-render.js +1 -1
  62. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  63. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  64. package/dist/hooks/use-coagent.d.ts +1 -1
  65. package/dist/hooks/use-coagent.js +154 -77
  66. package/dist/hooks/use-coagent.js.map +1 -1
  67. package/dist/hooks/use-coagent.mjs +14 -14
  68. package/dist/hooks/use-copilot-action.js +26 -7
  69. package/dist/hooks/use-copilot-action.js.map +1 -1
  70. package/dist/hooks/use-copilot-action.mjs +2 -2
  71. package/dist/hooks/use-copilot-additional-instructions.js +1 -1
  72. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
  73. package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
  74. package/dist/hooks/use-copilot-authenticated-action.js +26 -7
  75. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  76. package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
  77. package/dist/hooks/use-copilot-chat.d.ts +1 -1
  78. package/dist/hooks/use-copilot-chat.js +128 -77
  79. package/dist/hooks/use-copilot-chat.js.map +1 -1
  80. package/dist/hooks/use-copilot-chat.mjs +13 -13
  81. package/dist/hooks/use-copilot-readable.js +1 -1
  82. package/dist/hooks/use-copilot-readable.js.map +1 -1
  83. package/dist/hooks/use-copilot-readable.mjs +2 -2
  84. package/dist/hooks/use-copilot-runtime-client.d.ts +2 -2
  85. package/dist/hooks/use-copilot-runtime-client.js +7 -7
  86. package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
  87. package/dist/hooks/use-copilot-runtime-client.mjs +1 -1
  88. package/dist/hooks/use-langgraph-interrupt-render.js +1 -1
  89. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  90. package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
  91. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  92. package/dist/hooks/use-langgraph-interrupt.js +128 -77
  93. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  94. package/dist/hooks/use-langgraph-interrupt.mjs +14 -14
  95. package/dist/hooks/use-make-copilot-document-readable.js +1 -1
  96. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  97. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  98. package/dist/index.d.ts +1 -1
  99. package/dist/index.js +240 -103
  100. package/dist/index.js.map +1 -1
  101. package/dist/index.mjs +27 -27
  102. package/dist/lib/copilot-task.d.ts +1 -1
  103. package/dist/lib/copilot-task.js.map +1 -1
  104. package/dist/lib/copilot-task.mjs +11 -11
  105. package/dist/lib/index.d.ts +1 -1
  106. package/dist/lib/index.js.map +1 -1
  107. package/dist/lib/index.mjs +11 -11
  108. package/dist/setupTests.d.ts +2 -0
  109. package/dist/setupTests.js +26 -0
  110. package/dist/setupTests.js.map +1 -0
  111. package/dist/setupTests.mjs +24 -0
  112. package/dist/setupTests.mjs.map +1 -0
  113. package/dist/types/interrupt-action.d.ts +1 -1
  114. package/dist/utils/extract.d.ts +1 -1
  115. package/dist/utils/extract.js.map +1 -1
  116. package/dist/utils/extract.mjs +9 -9
  117. package/dist/utils/index.d.ts +1 -1
  118. package/dist/utils/index.js.map +1 -1
  119. package/dist/utils/index.mjs +10 -10
  120. package/jest.config.js +4 -0
  121. package/package.json +6 -3
  122. package/src/components/copilot-provider/__tests__/{copilotkit-trace.test.tsx → copilotkit-error.test.tsx} +17 -17
  123. package/src/components/copilot-provider/copilot-messages.tsx +7 -7
  124. package/src/components/copilot-provider/copilotkit-props.tsx +13 -8
  125. package/src/components/copilot-provider/copilotkit.tsx +61 -19
  126. package/src/context/copilot-context.tsx +4 -4
  127. package/src/hooks/__tests__/use-coagent-config.test.ts +284 -0
  128. package/src/hooks/use-chat.ts +149 -61
  129. package/src/hooks/use-coagent.ts +36 -0
  130. package/src/hooks/use-copilot-action.ts +51 -9
  131. package/src/hooks/use-copilot-runtime-client.ts +11 -12
  132. package/src/setupTests.ts +26 -0
  133. package/tsconfig.json +5 -2
  134. package/dist/chunk-55QZ2SVJ.mjs.map +0 -1
  135. package/dist/chunk-G7LYGERN.mjs.map +0 -1
  136. package/dist/chunk-NQVCZQ5T.mjs.map +0 -1
  137. package/dist/chunk-WOGURSAL.mjs.map +0 -1
  138. /package/dist/{chunk-ERXWDCY6.mjs.map → chunk-36MGCCPZ.mjs.map} +0 -0
  139. /package/dist/{chunk-UBNRUXEK.mjs.map → chunk-5BSUSFHM.mjs.map} +0 -0
  140. /package/dist/{chunk-JPMIAGI6.mjs.map → chunk-BVK7PLK6.mjs.map} +0 -0
  141. /package/dist/{chunk-FXK6RQIN.mjs.map → chunk-CUAFWKTQ.mjs.map} +0 -0
  142. /package/dist/{chunk-EF5BNM34.mjs.map → chunk-FN3UA2ZE.mjs.map} +0 -0
  143. /package/dist/{chunk-EXU7GWLC.mjs.map → chunk-GEE5AMYL.mjs.map} +0 -0
  144. /package/dist/{chunk-3YHYWAHK.mjs.map → chunk-KIXKBJUV.mjs.map} +0 -0
  145. /package/dist/{chunk-OF4SZTLL.mjs.map → chunk-NGQN3JRJ.mjs.map} +0 -0
  146. /package/dist/{chunk-SJJNFYGQ.mjs.map → chunk-SGF6C7I6.mjs.map} +0 -0
  147. /package/dist/{chunk-CMQV4XNY.mjs.map → chunk-VDADWRS3.mjs.map} +0 -0
@@ -2,20 +2,20 @@ import {
2
2
  CopilotKit,
3
3
  CopilotKitInternal,
4
4
  defaultCopilotContextCategories
5
- } from "../../chunk-WOGURSAL.mjs";
6
- import "../../chunk-SJJNFYGQ.mjs";
7
- import "../../chunk-JDEWNLNP.mjs";
5
+ } from "../../chunk-GIMSRCVW.mjs";
6
+ import "../../chunk-SGF6C7I6.mjs";
7
+ import "../../chunk-BSAVFYRQ.mjs";
8
+ import "../../chunk-PMAFHQ7P.mjs";
8
9
  import "../../chunk-5FHSUKQL.mjs";
9
10
  import "../../chunk-RKTVJRK7.mjs";
10
- import "../../chunk-PMAFHQ7P.mjs";
11
- import "../../chunk-57K2ZJ5F.mjs";
12
- import "../../chunk-DCTJZ742.mjs";
11
+ import "../../chunk-JWAXDYOW.mjs";
12
+ import "../../chunk-GFJW4RIM.mjs";
13
13
  import "../../chunk-3OQM3NEK.mjs";
14
14
  import "../../chunk-O7ARI5CV.mjs";
15
- import "../../chunk-55QZ2SVJ.mjs";
16
- import "../../chunk-GFJW4RIM.mjs";
17
15
  import "../../chunk-YAF2LATQ.mjs";
18
- import "../../chunk-XFOTNHYA.mjs";
16
+ import "../../chunk-57K2ZJ5F.mjs";
17
+ import "../../chunk-DKZTPL66.mjs";
18
+ import "../../chunk-DCTJZ742.mjs";
19
19
  import "../../chunk-SKC7AJIV.mjs";
20
20
  export {
21
21
  CopilotKit,
@@ -3,7 +3,7 @@ export { CopilotKitProps } from './copilotkit-props.js';
3
3
  import 'react/jsx-runtime';
4
4
  import '@copilotkit/runtime-client-gql';
5
5
  import 'react';
6
- import '../../copilot-context-3da805ab.js';
6
+ import '../../copilot-context-3ab4fdf5.js';
7
7
  import '@copilotkit/shared';
8
8
  import '../../types/frontend-action.js';
9
9
  import '../../hooks/use-tree.js';
@@ -162,7 +162,7 @@ var emptyCopilotContext = {
162
162
  langGraphInterruptAction: null,
163
163
  setLangGraphInterruptAction: () => null,
164
164
  removeLangGraphInterruptAction: () => null,
165
- onTrace: void 0
165
+ onError: void 0
166
166
  };
167
167
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
168
168
  function useCopilotContext() {
@@ -707,11 +707,11 @@ function CopilotMessages({ children }) {
707
707
  const lastLoadedThreadId = (0, import_react6.useRef)();
708
708
  const lastLoadedAgentName = (0, import_react6.useRef)();
709
709
  const lastLoadedMessages = (0, import_react6.useRef)();
710
- const { threadId, agentSession, runtimeClient, showDevConsole, onTrace, copilotApiConfig } = useCopilotContext();
710
+ const { threadId, agentSession, runtimeClient, showDevConsole, onError, copilotApiConfig } = useCopilotContext();
711
711
  const { setBannerError } = useToast();
712
712
  const traceUIError = (0, import_react6.useCallback)(
713
713
  (error, originalError) => __async(this, null, function* () {
714
- if (!onTrace || !copilotApiConfig.publicApiKey)
714
+ if (!onError || !copilotApiConfig.publicApiKey)
715
715
  return;
716
716
  try {
717
717
  const traceEvent = {
@@ -732,12 +732,12 @@ function CopilotMessages({ children }) {
732
732
  },
733
733
  error
734
734
  };
735
- yield onTrace(traceEvent);
735
+ yield onError(traceEvent);
736
736
  } catch (traceError) {
737
- console.error("Error in CopilotMessages onTrace handler:", traceError);
737
+ console.error("Error in CopilotMessages onError handler:", traceError);
738
738
  }
739
739
  }),
740
- [onTrace, copilotApiConfig.publicApiKey, copilotApiConfig.chatApiEndpoint]
740
+ [onError, copilotApiConfig.publicApiKey, copilotApiConfig.chatApiEndpoint]
741
741
  );
742
742
  const createStructuredError2 = (gqlError) => {
743
743
  const extensions = gqlError.extensions;
@@ -842,7 +842,7 @@ function CopilotMessages({ children }) {
842
842
  }
843
843
  });
844
844
  void fetchMessages();
845
- }, [threadId, agentSession == null ? void 0 : agentSession.agentName, runtimeClient]);
845
+ }, [threadId, agentSession == null ? void 0 : agentSession.agentName]);
846
846
  const memoizedChildren = (0, import_react6.useMemo)(() => children, [children]);
847
847
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
848
848
  CopilotMessagesContext.Provider,
@@ -862,13 +862,13 @@ var import_react7 = require("react");
862
862
  var import_shared5 = require("@copilotkit/shared");
863
863
  var useCopilotRuntimeClient = (options) => {
864
864
  const { setBannerError } = useToast();
865
- const _a = options, { showDevConsole, onTrace } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onTrace"]);
865
+ const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
866
866
  const lastStructuredErrorRef = (0, import_react7.useRef)(null);
867
867
  const traceUIError = (error, originalError) => __async(void 0, null, function* () {
868
- if (!onTrace || !runtimeOptions.publicApiKey)
868
+ if (!onError || !runtimeOptions.publicApiKey)
869
869
  return;
870
870
  try {
871
- const traceEvent = {
871
+ const errorEvent = {
872
872
  type: "error",
873
873
  timestamp: Date.now(),
874
874
  context: {
@@ -886,9 +886,9 @@ var useCopilotRuntimeClient = (options) => {
886
886
  },
887
887
  error
888
888
  };
889
- yield onTrace(traceEvent);
890
- } catch (traceError) {
891
- console.error("Error in onTrace handler:", traceError);
889
+ yield onError(errorEvent);
890
+ } catch (error2) {
891
+ console.error("Error in onError handler:", error2);
892
892
  }
893
893
  });
894
894
  const runtimeClient = (0, import_react7.useMemo)(() => {
@@ -952,7 +952,7 @@ var useCopilotRuntimeClient = (options) => {
952
952
  setBannerError(warningError);
953
953
  }
954
954
  }));
955
- }, [runtimeOptions, setBannerError, showDevConsole, onTrace]);
955
+ }, [runtimeOptions, setBannerError, showDevConsole, onError]);
956
956
  return runtimeClient;
957
957
  };
958
958
  function createStructuredError(gqlError) {
@@ -1722,18 +1722,24 @@ ${nonDocumentStrings}`;
1722
1722
  headers,
1723
1723
  credentials: copilotApiConfig.credentials,
1724
1724
  showDevConsole: (_b = props.showDevConsole) != null ? _b : false,
1725
- onTrace: props.onTrace
1725
+ onError: props.onError
1726
1726
  });
1727
1727
  const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react10.useState)({});
1728
- const addChatSuggestionConfiguration = (id, suggestion) => {
1729
- setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
1730
- };
1731
- const removeChatSuggestionConfiguration = (id) => {
1732
- setChatSuggestionConfiguration((prev) => {
1733
- const _a2 = prev, { [id]: _ } = _a2, rest = __objRest(_a2, [__restKey(id)]);
1734
- return rest;
1735
- });
1736
- };
1728
+ const addChatSuggestionConfiguration = (0, import_react10.useCallback)(
1729
+ (id, suggestion) => {
1730
+ setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
1731
+ },
1732
+ [setChatSuggestionConfiguration]
1733
+ );
1734
+ const removeChatSuggestionConfiguration = (0, import_react10.useCallback)(
1735
+ (id) => {
1736
+ setChatSuggestionConfiguration((prev) => {
1737
+ const _a2 = prev, { [id]: _ } = _a2, rest = __objRest(_a2, [__restKey(id)]);
1738
+ return rest;
1739
+ });
1740
+ },
1741
+ [setChatSuggestionConfiguration]
1742
+ );
1737
1743
  const [availableAgents, setAvailableAgents] = (0, import_react10.useState)([]);
1738
1744
  const [coagentStates, setCoagentStates] = (0, import_react10.useState)({});
1739
1745
  const coagentStatesRef = (0, import_react10.useRef)({});
@@ -1813,6 +1819,41 @@ ${nonDocumentStrings}`;
1813
1819
  setLangGraphInterruptAction(null);
1814
1820
  }, []);
1815
1821
  const memoizedChildren = (0, import_react10.useMemo)(() => children, [children]);
1822
+ const agentLock = (0, import_react10.useMemo)(() => {
1823
+ var _a2;
1824
+ return (_a2 = props.agent) != null ? _a2 : null;
1825
+ }, [props.agent]);
1826
+ const forwardedParameters = (0, import_react10.useMemo)(
1827
+ () => {
1828
+ var _a2;
1829
+ return (_a2 = props.forwardedParameters) != null ? _a2 : {};
1830
+ },
1831
+ [props.forwardedParameters]
1832
+ );
1833
+ const updateExtensions = (0, import_react10.useCallback)(
1834
+ (newExtensions) => {
1835
+ setExtensions((prev) => {
1836
+ const resolved = typeof newExtensions === "function" ? newExtensions(prev) : newExtensions;
1837
+ const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
1838
+ const isEqual = isSameLength && // @ts-ignore
1839
+ Object.entries(resolved).every(([key, value]) => prev[key] === value);
1840
+ return isEqual ? prev : resolved;
1841
+ });
1842
+ },
1843
+ [setExtensions]
1844
+ );
1845
+ const updateAuthStates = (0, import_react10.useCallback)(
1846
+ (newAuthStates) => {
1847
+ setAuthStates((prev) => {
1848
+ const resolved = typeof newAuthStates === "function" ? newAuthStates(prev) : newAuthStates;
1849
+ const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
1850
+ const isEqual = isSameLength && // @ts-ignore
1851
+ Object.entries(resolved).every(([key, value]) => prev[key] === value);
1852
+ return isEqual ? prev : resolved;
1853
+ });
1854
+ },
1855
+ [setAuthStates]
1856
+ );
1816
1857
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1817
1858
  CopilotContext.Provider,
1818
1859
  {
@@ -1850,8 +1891,8 @@ ${nonDocumentStrings}`;
1850
1891
  agentSession,
1851
1892
  setAgentSession,
1852
1893
  runtimeClient,
1853
- forwardedParameters: props.forwardedParameters || {},
1854
- agentLock: props.agent || null,
1894
+ forwardedParameters,
1895
+ agentLock,
1855
1896
  threadId: internalThreadId,
1856
1897
  setThreadId,
1857
1898
  runId,
@@ -1860,13 +1901,13 @@ ${nonDocumentStrings}`;
1860
1901
  availableAgents,
1861
1902
  authConfig_c: props.authConfig_c,
1862
1903
  authStates_c: authStates,
1863
- setAuthStates_c: setAuthStates,
1904
+ setAuthStates_c: updateAuthStates,
1864
1905
  extensions,
1865
- setExtensions,
1906
+ setExtensions: updateExtensions,
1866
1907
  langGraphInterruptAction,
1867
1908
  setLangGraphInterruptAction,
1868
1909
  removeLangGraphInterruptAction,
1869
- onTrace: props.onTrace
1910
+ onError: props.onError
1870
1911
  },
1871
1912
  children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotMessages, { children: memoizedChildren })
1872
1913
  }