@copilotkit/react-core 1.5.12-next.5 → 1.5.12-next.7

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 (120) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/{chunk-KOSLAM4Z.mjs → chunk-6BQUI465.mjs} +27 -6
  3. package/dist/chunk-6BQUI465.mjs.map +1 -0
  4. package/dist/{chunk-22XKTBPF.mjs → chunk-CBWNO2FP.mjs} +3 -3
  5. package/dist/{chunk-6BQVZFNO.mjs → chunk-CQWEXISS.mjs} +2 -2
  6. package/dist/{chunk-EWKJMQOF.mjs → chunk-EXX267DG.mjs} +3 -3
  7. package/dist/{chunk-LNI2Z45S.mjs → chunk-HZCROITJ.mjs} +5 -3
  8. package/dist/chunk-HZCROITJ.mjs.map +1 -0
  9. package/dist/chunk-IFBUUIU7.mjs +53 -0
  10. package/dist/chunk-IFBUUIU7.mjs.map +1 -0
  11. package/dist/{chunk-HIUT2NLX.mjs → chunk-J6UBNKIR.mjs} +2 -2
  12. package/dist/{chunk-6DQD4B23.mjs → chunk-KGCYVAIN.mjs} +16 -10
  13. package/dist/chunk-KGCYVAIN.mjs.map +1 -0
  14. package/dist/{chunk-LHKIIAUQ.mjs → chunk-MF4F77OY.mjs} +3 -3
  15. package/dist/{chunk-LZWH4OG5.mjs → chunk-MYCYEMIM.mjs} +31 -13
  16. package/dist/chunk-MYCYEMIM.mjs.map +1 -0
  17. package/dist/{chunk-FQ53HQYZ.mjs → chunk-N37EFAUX.mjs} +2 -2
  18. package/dist/{chunk-M2NT7NOO.mjs → chunk-VEGDEDID.mjs} +2 -2
  19. package/dist/{chunk-VNTDIJSG.mjs → chunk-X47CUJJT.mjs} +2 -2
  20. package/dist/{chunk-RD5XFSI4.mjs → chunk-X62FIPVR.mjs} +11 -8
  21. package/dist/chunk-X62FIPVR.mjs.map +1 -0
  22. package/dist/{chunk-WXREY7UP.mjs → chunk-YVQNSJ4Z.mjs} +6 -3
  23. package/dist/chunk-YVQNSJ4Z.mjs.map +1 -0
  24. package/dist/components/copilot-provider/copilot-messages.js +125 -2
  25. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  26. package/dist/components/copilot-provider/copilot-messages.mjs +2 -1
  27. package/dist/components/copilot-provider/copilotkit-props.d.ts +4 -0
  28. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  29. package/dist/components/copilot-provider/copilotkit.js +58 -9
  30. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  31. package/dist/components/copilot-provider/copilotkit.mjs +7 -7
  32. package/dist/components/copilot-provider/index.js +58 -9
  33. package/dist/components/copilot-provider/index.js.map +1 -1
  34. package/dist/components/copilot-provider/index.mjs +7 -7
  35. package/dist/components/error-boundary/error-boundary.js +4 -2
  36. package/dist/components/error-boundary/error-boundary.js.map +1 -1
  37. package/dist/components/error-boundary/error-boundary.mjs +2 -2
  38. package/dist/components/error-boundary/error-utils.js +14 -2
  39. package/dist/components/error-boundary/error-utils.js.map +1 -1
  40. package/dist/components/error-boundary/error-utils.mjs +1 -1
  41. package/dist/components/index.js +58 -9
  42. package/dist/components/index.js.map +1 -1
  43. package/dist/components/index.mjs +7 -7
  44. package/dist/components/toast/toast-provider.js +14 -2
  45. package/dist/components/toast/toast-provider.js.map +1 -1
  46. package/dist/components/toast/toast-provider.mjs +1 -1
  47. package/dist/context/copilot-context.d.ts +5 -3
  48. package/dist/context/copilot-context.js +5 -2
  49. package/dist/context/copilot-context.js.map +1 -1
  50. package/dist/context/copilot-context.mjs +1 -1
  51. package/dist/context/index.js +5 -2
  52. package/dist/context/index.js.map +1 -1
  53. package/dist/context/index.mjs +1 -1
  54. package/dist/hooks/index.js +46 -15
  55. package/dist/hooks/index.js.map +1 -1
  56. package/dist/hooks/index.mjs +25 -25
  57. package/dist/hooks/use-chat.d.ts +11 -3
  58. package/dist/hooks/use-chat.js +25 -8
  59. package/dist/hooks/use-chat.js.map +1 -1
  60. package/dist/hooks/use-chat.mjs +3 -3
  61. package/dist/hooks/use-coagent-state-render.js +5 -2
  62. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  63. package/dist/hooks/use-coagent-state-render.mjs +3 -3
  64. package/dist/hooks/use-coagent.js +46 -15
  65. package/dist/hooks/use-coagent.js.map +1 -1
  66. package/dist/hooks/use-coagent.mjs +11 -11
  67. package/dist/hooks/use-copilot-action.js +9 -4
  68. package/dist/hooks/use-copilot-action.js.map +1 -1
  69. package/dist/hooks/use-copilot-action.mjs +3 -3
  70. package/dist/hooks/use-copilot-authenticated-action.js +9 -4
  71. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  72. package/dist/hooks/use-copilot-authenticated-action.mjs +4 -4
  73. package/dist/hooks/use-copilot-chat.js +26 -13
  74. package/dist/hooks/use-copilot-chat.js.map +1 -1
  75. package/dist/hooks/use-copilot-chat.mjs +10 -10
  76. package/dist/hooks/use-copilot-readable.js +5 -2
  77. package/dist/hooks/use-copilot-readable.js.map +1 -1
  78. package/dist/hooks/use-copilot-readable.mjs +2 -2
  79. package/dist/hooks/use-copilot-runtime-client.js +14 -2
  80. package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
  81. package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
  82. package/dist/hooks/use-make-copilot-document-readable.js +5 -2
  83. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  84. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  85. package/dist/index.js +126 -58
  86. package/dist/index.js.map +1 -1
  87. package/dist/index.mjs +26 -26
  88. package/dist/lib/copilot-task.js.map +1 -1
  89. package/dist/lib/copilot-task.mjs +8 -8
  90. package/dist/lib/index.js.map +1 -1
  91. package/dist/lib/index.mjs +8 -8
  92. package/dist/utils/extract.js.map +1 -1
  93. package/dist/utils/extract.mjs +7 -7
  94. package/dist/utils/index.js.map +1 -1
  95. package/dist/utils/index.mjs +7 -7
  96. package/package.json +5 -4
  97. package/src/components/copilot-provider/copilot-messages.tsx +24 -2
  98. package/src/components/copilot-provider/copilotkit-props.tsx +5 -0
  99. package/src/components/copilot-provider/copilotkit.tsx +30 -4
  100. package/src/components/error-boundary/error-utils.tsx +11 -6
  101. package/src/context/copilot-context.tsx +13 -4
  102. package/src/hooks/use-chat.ts +27 -7
  103. package/src/hooks/use-coagent.ts +30 -4
  104. package/src/hooks/use-copilot-chat.ts +5 -2
  105. package/dist/chunk-6DQD4B23.mjs.map +0 -1
  106. package/dist/chunk-KOSLAM4Z.mjs.map +0 -1
  107. package/dist/chunk-LNI2Z45S.mjs.map +0 -1
  108. package/dist/chunk-LZWH4OG5.mjs.map +0 -1
  109. package/dist/chunk-RD5XFSI4.mjs.map +0 -1
  110. package/dist/chunk-WXREY7UP.mjs.map +0 -1
  111. package/dist/chunk-XXR4QFAQ.mjs +0 -29
  112. package/dist/chunk-XXR4QFAQ.mjs.map +0 -1
  113. /package/dist/{chunk-22XKTBPF.mjs.map → chunk-CBWNO2FP.mjs.map} +0 -0
  114. /package/dist/{chunk-6BQVZFNO.mjs.map → chunk-CQWEXISS.mjs.map} +0 -0
  115. /package/dist/{chunk-EWKJMQOF.mjs.map → chunk-EXX267DG.mjs.map} +0 -0
  116. /package/dist/{chunk-HIUT2NLX.mjs.map → chunk-J6UBNKIR.mjs.map} +0 -0
  117. /package/dist/{chunk-LHKIIAUQ.mjs.map → chunk-MF4F77OY.mjs.map} +0 -0
  118. /package/dist/{chunk-FQ53HQYZ.mjs.map → chunk-N37EFAUX.mjs.map} +0 -0
  119. /package/dist/{chunk-M2NT7NOO.mjs.map → chunk-VEGDEDID.mjs.map} +0 -0
  120. /package/dist/{chunk-VNTDIJSG.mjs.map → chunk-X47CUJJT.mjs.map} +0 -0
@@ -144,14 +144,17 @@ var emptyCopilotContext = {
144
144
  },
145
145
  forwardedParameters: {},
146
146
  agentLock: null,
147
- threadId: null,
147
+ threadId: "",
148
148
  setThreadId: () => {
149
149
  },
150
150
  runId: null,
151
151
  setRunId: () => {
152
152
  },
153
153
  chatAbortControllerRef: { current: null },
154
- availableAgents: []
154
+ availableAgents: [],
155
+ extensions: {},
156
+ setExtensions: () => {
157
+ }
155
158
  };
156
159
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
157
160
  function useCopilotContext() {
@@ -253,11 +256,13 @@ var ExclamationMarkIcon = ({
253
256
  );
254
257
 
255
258
  // src/components/error-boundary/error-utils.tsx
259
+ var import_react_markdown = __toESM(require("react-markdown"));
256
260
  var import_jsx_runtime2 = require("react/jsx-runtime");
257
261
  function ErrorToast({ errors }) {
258
262
  const errorsToRender = errors.map((error, idx) => {
259
263
  var _a, _b, _c;
260
- const message = "extensions" in error ? (_b = (_a = error.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message : error.message;
264
+ const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
265
+ const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
261
266
  const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
262
267
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
263
268
  "div",
@@ -282,7 +287,7 @@ function ErrorToast({ errors }) {
282
287
  ]
283
288
  }
284
289
  ),
285
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: message })
290
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_markdown.default, { children: message })
286
291
  ]
287
292
  },
288
293
  idx
@@ -387,16 +392,18 @@ function useChat(options) {
387
392
  runId,
388
393
  setRunId,
389
394
  chatAbortControllerRef,
390
- agentLock
395
+ agentLock,
396
+ extensions,
397
+ setExtensions
391
398
  } = options;
392
399
  const runChatCompletionRef = (0, import_react6.useRef)();
393
400
  const addErrorToast = useErrorToast();
394
401
  const agentSessionRef = (0, import_react6.useRef)(agentSession);
395
402
  agentSessionRef.current = agentSession;
396
- const threadIdRef = (0, import_react6.useRef)(threadId);
397
- threadIdRef.current = threadId;
398
403
  const runIdRef = (0, import_react6.useRef)(runId);
399
404
  runIdRef.current = runId;
405
+ const extensionsRef = (0, import_react6.useRef)(extensions);
406
+ extensionsRef.current = extensions;
400
407
  const publicApiKey = copilotConfig.publicApiKey;
401
408
  const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared2.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
402
409
  const runtimeClient = useCopilotRuntimeClient({
@@ -427,8 +434,9 @@ function useChat(options) {
427
434
  actions: processActionsForRuntimeRequest(actions),
428
435
  url: window.location.href
429
436
  },
430
- threadId: threadIdRef.current,
437
+ threadId,
431
438
  runId: runIdRef.current,
439
+ extensions: extensionsRef.current,
432
440
  messages: (0, import_runtime_client_gql3.convertMessagesToGqlInput)((0, import_runtime_client_gql3.filterAgentStateMessages)(messagesWithContext))
433
441
  }, copilotConfig.cloud ? {
434
442
  cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
@@ -481,10 +489,12 @@ function useChat(options) {
481
489
  if (!(value == null ? void 0 : value.generateCopilotResponse)) {
482
490
  continue;
483
491
  }
484
- threadIdRef.current = value.generateCopilotResponse.threadId || null;
485
492
  runIdRef.current = value.generateCopilotResponse.runId || null;
486
- setThreadId(threadIdRef.current);
493
+ extensionsRef.current = import_runtime_client_gql3.CopilotRuntimeClient.removeGraphQLTypename(
494
+ value.generateCopilotResponse.extensions || {}
495
+ );
487
496
  setRunId(runIdRef.current);
497
+ setExtensions(extensionsRef.current);
488
498
  messages2 = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
489
499
  (0, import_runtime_client_gql3.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
490
500
  );
@@ -777,7 +787,9 @@ function useCopilotChat(_a = {}) {
777
787
  setThreadId,
778
788
  runId,
779
789
  setRunId,
780
- chatAbortControllerRef
790
+ chatAbortControllerRef,
791
+ extensions,
792
+ setExtensions
781
793
  } = useCopilotContext();
782
794
  const { messages, setMessages } = useCopilotMessagesContext();
783
795
  const latestGetContextString = useUpdatedRef(getContextString);
@@ -834,7 +846,9 @@ function useCopilotChat(_a = {}) {
834
846
  runId,
835
847
  setRunId,
836
848
  chatAbortControllerRef,
837
- agentLock
849
+ agentLock,
850
+ extensions,
851
+ setExtensions
838
852
  }));
839
853
  const latestAppend = useUpdatedRef(append);
840
854
  const latestAppendFunc = useAsyncCallback(
@@ -872,7 +886,6 @@ function useCopilotChat(_a = {}) {
872
886
  const reset = (0, import_react8.useCallback)(() => {
873
887
  latestStopFunc();
874
888
  setMessages([]);
875
- setThreadId(null);
876
889
  setRunId(null);
877
890
  setCoagentStatesWithRef({});
878
891
  let initialAgentSession = null;
@@ -961,7 +974,7 @@ function useCoAgent(options) {
961
974
  };
962
975
  const messagesContext = useCopilotMessagesContext();
963
976
  const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
964
- const { coagentStates, coagentStatesRef, setCoagentStatesWithRef } = context;
977
+ const { coagentStates, coagentStatesRef, setCoagentStatesWithRef, threadId, copilotApiConfig } = context;
965
978
  const { appendMessage, runChatCompletion } = useCopilotChat();
966
979
  const getCoagentState = (coagentStates2, name2) => {
967
980
  if (coagentStates2[name2]) {
@@ -978,6 +991,11 @@ function useCoAgent(options) {
978
991
  };
979
992
  }
980
993
  };
994
+ const runtimeClient = useCopilotRuntimeClient({
995
+ url: copilotApiConfig.chatApiEndpoint,
996
+ publicApiKey: copilotApiConfig.publicApiKey,
997
+ credentials: copilotApiConfig.credentials
998
+ });
981
999
  const setState = (newState) => {
982
1000
  let coagentState2 = getCoagentState(coagentStatesRef.current || {}, name);
983
1001
  const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
@@ -987,8 +1005,21 @@ function useCoAgent(options) {
987
1005
  })
988
1006
  }));
989
1007
  };
1008
+ (0, import_react9.useEffect)(() => {
1009
+ const fetchAgentState = () => __async(this, null, function* () {
1010
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1011
+ const result = yield runtimeClient.loadAgentState({
1012
+ threadId,
1013
+ agentName: name
1014
+ });
1015
+ if (((_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.threadExists) && ((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.state) && ((_f = (_e = result.data) == null ? void 0 : _e.loadAgentState) == null ? void 0 : _f.state) != "{}") {
1016
+ const fetchedState = JSON.parse((_h = (_g = result.data) == null ? void 0 : _g.loadAgentState) == null ? void 0 : _h.state);
1017
+ isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
1018
+ }
1019
+ });
1020
+ void fetchAgentState();
1021
+ }, [threadId]);
990
1022
  const coagentState = getCoagentState(coagentStates, name);
991
- const state = isExternalStateManagement(options) ? options.state : coagentState.state;
992
1023
  (0, import_react9.useEffect)(() => {
993
1024
  if (isExternalStateManagement(options)) {
994
1025
  setState(options.state);