@copilotkit/react-core 1.5.12-next.6 → 1.5.12

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 (100) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/{chunk-5SXKKYAY.mjs → chunk-6BQUI465.mjs} +26 -5
  3. package/dist/chunk-6BQUI465.mjs.map +1 -0
  4. package/dist/{chunk-SDMANO6S.mjs → chunk-CBWNO2FP.mjs} +2 -2
  5. package/dist/{chunk-KHZO2WMR.mjs → chunk-EXX267DG.mjs} +2 -2
  6. package/dist/chunk-IFBUUIU7.mjs +53 -0
  7. package/dist/chunk-IFBUUIU7.mjs.map +1 -0
  8. package/dist/{chunk-HIUT2NLX.mjs → chunk-J6UBNKIR.mjs} +2 -2
  9. package/dist/{chunk-27ONDUGD.mjs → chunk-KGCYVAIN.mjs} +14 -8
  10. package/dist/chunk-KGCYVAIN.mjs.map +1 -0
  11. package/dist/{chunk-ANHSORJR.mjs → chunk-MF4F77OY.mjs} +3 -3
  12. package/dist/{chunk-5TSAQCRY.mjs → chunk-MYCYEMIM.mjs} +25 -7
  13. package/dist/chunk-MYCYEMIM.mjs.map +1 -0
  14. package/dist/{chunk-FQ53HQYZ.mjs → chunk-N37EFAUX.mjs} +2 -2
  15. package/dist/{chunk-NO6F42WV.mjs → chunk-VEGDEDID.mjs} +2 -2
  16. package/dist/{chunk-EUSQWVOS.mjs → chunk-X62FIPVR.mjs} +10 -7
  17. package/dist/chunk-X62FIPVR.mjs.map +1 -0
  18. package/dist/{chunk-WXREY7UP.mjs → chunk-YVQNSJ4Z.mjs} +6 -3
  19. package/dist/chunk-YVQNSJ4Z.mjs.map +1 -0
  20. package/dist/components/copilot-provider/copilot-messages.js +125 -2
  21. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  22. package/dist/components/copilot-provider/copilot-messages.mjs +2 -1
  23. package/dist/components/copilot-provider/copilotkit-props.d.ts +4 -0
  24. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  25. package/dist/components/copilot-provider/copilotkit.js +54 -7
  26. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  27. package/dist/components/copilot-provider/copilotkit.mjs +3 -3
  28. package/dist/components/copilot-provider/index.js +54 -7
  29. package/dist/components/copilot-provider/index.js.map +1 -1
  30. package/dist/components/copilot-provider/index.mjs +3 -3
  31. package/dist/components/index.js +54 -7
  32. package/dist/components/index.js.map +1 -1
  33. package/dist/components/index.mjs +3 -3
  34. package/dist/context/copilot-context.d.ts +5 -3
  35. package/dist/context/copilot-context.js +5 -2
  36. package/dist/context/copilot-context.js.map +1 -1
  37. package/dist/context/copilot-context.mjs +1 -1
  38. package/dist/context/index.js +5 -2
  39. package/dist/context/index.js.map +1 -1
  40. package/dist/context/index.mjs +1 -1
  41. package/dist/hooks/index.js +42 -13
  42. package/dist/hooks/index.js.map +1 -1
  43. package/dist/hooks/index.mjs +11 -11
  44. package/dist/hooks/use-chat.d.ts +11 -3
  45. package/dist/hooks/use-chat.js +11 -6
  46. package/dist/hooks/use-chat.js.map +1 -1
  47. package/dist/hooks/use-chat.mjs +1 -1
  48. package/dist/hooks/use-coagent-state-render.js +5 -2
  49. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  50. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  51. package/dist/hooks/use-coagent.js +42 -13
  52. package/dist/hooks/use-coagent.js.map +1 -1
  53. package/dist/hooks/use-coagent.mjs +6 -6
  54. package/dist/hooks/use-copilot-action.js +5 -2
  55. package/dist/hooks/use-copilot-action.js.map +1 -1
  56. package/dist/hooks/use-copilot-action.mjs +2 -2
  57. package/dist/hooks/use-copilot-authenticated-action.js +5 -2
  58. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  59. package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
  60. package/dist/hooks/use-copilot-chat.js +22 -11
  61. package/dist/hooks/use-copilot-chat.js.map +1 -1
  62. package/dist/hooks/use-copilot-chat.mjs +5 -5
  63. package/dist/hooks/use-copilot-readable.js +5 -2
  64. package/dist/hooks/use-copilot-readable.js.map +1 -1
  65. package/dist/hooks/use-copilot-readable.mjs +2 -2
  66. package/dist/hooks/use-make-copilot-document-readable.js +5 -2
  67. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  68. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  69. package/dist/index.js +122 -56
  70. package/dist/index.js.map +1 -1
  71. package/dist/index.mjs +12 -12
  72. package/dist/lib/copilot-task.js.map +1 -1
  73. package/dist/lib/copilot-task.mjs +4 -4
  74. package/dist/lib/index.js.map +1 -1
  75. package/dist/lib/index.mjs +4 -4
  76. package/dist/utils/extract.js.map +1 -1
  77. package/dist/utils/extract.mjs +3 -3
  78. package/dist/utils/index.js.map +1 -1
  79. package/dist/utils/index.mjs +3 -3
  80. package/package.json +3 -3
  81. package/src/components/copilot-provider/copilot-messages.tsx +24 -2
  82. package/src/components/copilot-provider/copilotkit-props.tsx +5 -0
  83. package/src/components/copilot-provider/copilotkit.tsx +30 -4
  84. package/src/context/copilot-context.tsx +13 -4
  85. package/src/hooks/use-chat.ts +27 -7
  86. package/src/hooks/use-coagent.ts +30 -4
  87. package/src/hooks/use-copilot-chat.ts +5 -2
  88. package/dist/chunk-27ONDUGD.mjs.map +0 -1
  89. package/dist/chunk-5SXKKYAY.mjs.map +0 -1
  90. package/dist/chunk-5TSAQCRY.mjs.map +0 -1
  91. package/dist/chunk-EUSQWVOS.mjs.map +0 -1
  92. package/dist/chunk-WXREY7UP.mjs.map +0 -1
  93. package/dist/chunk-XXR4QFAQ.mjs +0 -29
  94. package/dist/chunk-XXR4QFAQ.mjs.map +0 -1
  95. /package/dist/{chunk-SDMANO6S.mjs.map → chunk-CBWNO2FP.mjs.map} +0 -0
  96. /package/dist/{chunk-KHZO2WMR.mjs.map → chunk-EXX267DG.mjs.map} +0 -0
  97. /package/dist/{chunk-HIUT2NLX.mjs.map → chunk-J6UBNKIR.mjs.map} +0 -0
  98. /package/dist/{chunk-ANHSORJR.mjs.map → chunk-MF4F77OY.mjs.map} +0 -0
  99. /package/dist/{chunk-FQ53HQYZ.mjs.map → chunk-N37EFAUX.mjs.map} +0 -0
  100. /package/dist/{chunk-NO6F42WV.mjs.map → chunk-VEGDEDID.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() {
@@ -389,16 +392,18 @@ function useChat(options) {
389
392
  runId,
390
393
  setRunId,
391
394
  chatAbortControllerRef,
392
- agentLock
395
+ agentLock,
396
+ extensions,
397
+ setExtensions
393
398
  } = options;
394
399
  const runChatCompletionRef = (0, import_react6.useRef)();
395
400
  const addErrorToast = useErrorToast();
396
401
  const agentSessionRef = (0, import_react6.useRef)(agentSession);
397
402
  agentSessionRef.current = agentSession;
398
- const threadIdRef = (0, import_react6.useRef)(threadId);
399
- threadIdRef.current = threadId;
400
403
  const runIdRef = (0, import_react6.useRef)(runId);
401
404
  runIdRef.current = runId;
405
+ const extensionsRef = (0, import_react6.useRef)(extensions);
406
+ extensionsRef.current = extensions;
402
407
  const publicApiKey = copilotConfig.publicApiKey;
403
408
  const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared2.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
404
409
  const runtimeClient = useCopilotRuntimeClient({
@@ -429,8 +434,9 @@ function useChat(options) {
429
434
  actions: processActionsForRuntimeRequest(actions),
430
435
  url: window.location.href
431
436
  },
432
- threadId: threadIdRef.current,
437
+ threadId,
433
438
  runId: runIdRef.current,
439
+ extensions: extensionsRef.current,
434
440
  messages: (0, import_runtime_client_gql3.convertMessagesToGqlInput)((0, import_runtime_client_gql3.filterAgentStateMessages)(messagesWithContext))
435
441
  }, copilotConfig.cloud ? {
436
442
  cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
@@ -483,10 +489,12 @@ function useChat(options) {
483
489
  if (!(value == null ? void 0 : value.generateCopilotResponse)) {
484
490
  continue;
485
491
  }
486
- threadIdRef.current = value.generateCopilotResponse.threadId || null;
487
492
  runIdRef.current = value.generateCopilotResponse.runId || null;
488
- setThreadId(threadIdRef.current);
493
+ extensionsRef.current = import_runtime_client_gql3.CopilotRuntimeClient.removeGraphQLTypename(
494
+ value.generateCopilotResponse.extensions || {}
495
+ );
489
496
  setRunId(runIdRef.current);
497
+ setExtensions(extensionsRef.current);
490
498
  messages2 = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
491
499
  (0, import_runtime_client_gql3.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
492
500
  );
@@ -779,7 +787,9 @@ function useCopilotChat(_a = {}) {
779
787
  setThreadId,
780
788
  runId,
781
789
  setRunId,
782
- chatAbortControllerRef
790
+ chatAbortControllerRef,
791
+ extensions,
792
+ setExtensions
783
793
  } = useCopilotContext();
784
794
  const { messages, setMessages } = useCopilotMessagesContext();
785
795
  const latestGetContextString = useUpdatedRef(getContextString);
@@ -836,7 +846,9 @@ function useCopilotChat(_a = {}) {
836
846
  runId,
837
847
  setRunId,
838
848
  chatAbortControllerRef,
839
- agentLock
849
+ agentLock,
850
+ extensions,
851
+ setExtensions
840
852
  }));
841
853
  const latestAppend = useUpdatedRef(append);
842
854
  const latestAppendFunc = useAsyncCallback(
@@ -874,7 +886,6 @@ function useCopilotChat(_a = {}) {
874
886
  const reset = (0, import_react8.useCallback)(() => {
875
887
  latestStopFunc();
876
888
  setMessages([]);
877
- setThreadId(null);
878
889
  setRunId(null);
879
890
  setCoagentStatesWithRef({});
880
891
  let initialAgentSession = null;
@@ -963,7 +974,7 @@ function useCoAgent(options) {
963
974
  };
964
975
  const messagesContext = useCopilotMessagesContext();
965
976
  const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
966
- const { coagentStates, coagentStatesRef, setCoagentStatesWithRef } = context;
977
+ const { coagentStates, coagentStatesRef, setCoagentStatesWithRef, threadId, copilotApiConfig } = context;
967
978
  const { appendMessage, runChatCompletion } = useCopilotChat();
968
979
  const getCoagentState = (coagentStates2, name2) => {
969
980
  if (coagentStates2[name2]) {
@@ -980,6 +991,11 @@ function useCoAgent(options) {
980
991
  };
981
992
  }
982
993
  };
994
+ const runtimeClient = useCopilotRuntimeClient({
995
+ url: copilotApiConfig.chatApiEndpoint,
996
+ publicApiKey: copilotApiConfig.publicApiKey,
997
+ credentials: copilotApiConfig.credentials
998
+ });
983
999
  const setState = (newState) => {
984
1000
  let coagentState2 = getCoagentState(coagentStatesRef.current || {}, name);
985
1001
  const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
@@ -989,8 +1005,21 @@ function useCoAgent(options) {
989
1005
  })
990
1006
  }));
991
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]);
992
1022
  const coagentState = getCoagentState(coagentStates, name);
993
- const state = isExternalStateManagement(options) ? options.state : coagentState.state;
994
1023
  (0, import_react9.useEffect)(() => {
995
1024
  if (isExternalStateManagement(options)) {
996
1025
  setState(options.state);