@copilotkit/react-core 1.5.12-next.6 → 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 (100) hide show
  1. package/CHANGELOG.md +9 -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
@@ -153,14 +153,17 @@ var emptyCopilotContext = {
153
153
  },
154
154
  forwardedParameters: {},
155
155
  agentLock: null,
156
- threadId: null,
156
+ threadId: "",
157
157
  setThreadId: () => {
158
158
  },
159
159
  runId: null,
160
160
  setRunId: () => {
161
161
  },
162
162
  chatAbortControllerRef: { current: null },
163
- availableAgents: []
163
+ availableAgents: [],
164
+ extensions: {},
165
+ setExtensions: () => {
166
+ }
164
167
  };
165
168
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
166
169
  function useCopilotContext() {
@@ -380,16 +383,18 @@ function useChat(options) {
380
383
  runId,
381
384
  setRunId,
382
385
  chatAbortControllerRef,
383
- agentLock
386
+ agentLock,
387
+ extensions,
388
+ setExtensions
384
389
  } = options;
385
390
  const runChatCompletionRef = (0, import_react5.useRef)();
386
391
  const addErrorToast = useErrorToast();
387
392
  const agentSessionRef = (0, import_react5.useRef)(agentSession);
388
393
  agentSessionRef.current = agentSession;
389
- const threadIdRef = (0, import_react5.useRef)(threadId);
390
- threadIdRef.current = threadId;
391
394
  const runIdRef = (0, import_react5.useRef)(runId);
392
395
  runIdRef.current = runId;
396
+ const extensionsRef = (0, import_react5.useRef)(extensions);
397
+ extensionsRef.current = extensions;
393
398
  const publicApiKey = copilotConfig.publicApiKey;
394
399
  const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared2.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
395
400
  const runtimeClient = useCopilotRuntimeClient({
@@ -420,8 +425,9 @@ function useChat(options) {
420
425
  actions: processActionsForRuntimeRequest(actions),
421
426
  url: window.location.href
422
427
  },
423
- threadId: threadIdRef.current,
428
+ threadId,
424
429
  runId: runIdRef.current,
430
+ extensions: extensionsRef.current,
425
431
  messages: (0, import_runtime_client_gql3.convertMessagesToGqlInput)((0, import_runtime_client_gql3.filterAgentStateMessages)(messagesWithContext))
426
432
  }, copilotConfig.cloud ? {
427
433
  cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
@@ -474,10 +480,12 @@ function useChat(options) {
474
480
  if (!(value == null ? void 0 : value.generateCopilotResponse)) {
475
481
  continue;
476
482
  }
477
- threadIdRef.current = value.generateCopilotResponse.threadId || null;
478
483
  runIdRef.current = value.generateCopilotResponse.runId || null;
479
- setThreadId(threadIdRef.current);
484
+ extensionsRef.current = import_runtime_client_gql3.CopilotRuntimeClient.removeGraphQLTypename(
485
+ value.generateCopilotResponse.extensions || {}
486
+ );
480
487
  setRunId(runIdRef.current);
488
+ setExtensions(extensionsRef.current);
481
489
  messages2 = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
482
490
  (0, import_runtime_client_gql3.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
483
491
  );
@@ -789,7 +797,9 @@ function useCopilotChat(_a = {}) {
789
797
  setThreadId,
790
798
  runId,
791
799
  setRunId,
792
- chatAbortControllerRef
800
+ chatAbortControllerRef,
801
+ extensions,
802
+ setExtensions
793
803
  } = useCopilotContext();
794
804
  const { messages, setMessages } = useCopilotMessagesContext();
795
805
  const latestGetContextString = useUpdatedRef(getContextString);
@@ -846,7 +856,9 @@ function useCopilotChat(_a = {}) {
846
856
  runId,
847
857
  setRunId,
848
858
  chatAbortControllerRef,
849
- agentLock
859
+ agentLock,
860
+ extensions,
861
+ setExtensions
850
862
  }));
851
863
  const latestAppend = useUpdatedRef(append);
852
864
  const latestAppendFunc = useAsyncCallback(
@@ -884,7 +896,6 @@ function useCopilotChat(_a = {}) {
884
896
  const reset = (0, import_react8.useCallback)(() => {
885
897
  latestStopFunc();
886
898
  setMessages([]);
887
- setThreadId(null);
888
899
  setRunId(null);
889
900
  setCoagentStatesWithRef({});
890
901
  let initialAgentSession = null;
@@ -1151,7 +1162,7 @@ function useCoAgent(options) {
1151
1162
  };
1152
1163
  const messagesContext = useCopilotMessagesContext();
1153
1164
  const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
1154
- const { coagentStates, coagentStatesRef, setCoagentStatesWithRef } = context;
1165
+ const { coagentStates, coagentStatesRef, setCoagentStatesWithRef, threadId, copilotApiConfig } = context;
1155
1166
  const { appendMessage, runChatCompletion } = useCopilotChat();
1156
1167
  const getCoagentState = (coagentStates2, name2) => {
1157
1168
  if (coagentStates2[name2]) {
@@ -1168,6 +1179,11 @@ function useCoAgent(options) {
1168
1179
  };
1169
1180
  }
1170
1181
  };
1182
+ const runtimeClient = useCopilotRuntimeClient({
1183
+ url: copilotApiConfig.chatApiEndpoint,
1184
+ publicApiKey: copilotApiConfig.publicApiKey,
1185
+ credentials: copilotApiConfig.credentials
1186
+ });
1171
1187
  const setState = (newState) => {
1172
1188
  let coagentState2 = getCoagentState(coagentStatesRef.current || {}, name);
1173
1189
  const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
@@ -1177,8 +1193,21 @@ function useCoAgent(options) {
1177
1193
  })
1178
1194
  }));
1179
1195
  };
1196
+ (0, import_react13.useEffect)(() => {
1197
+ const fetchAgentState = () => __async(this, null, function* () {
1198
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1199
+ const result = yield runtimeClient.loadAgentState({
1200
+ threadId,
1201
+ agentName: name
1202
+ });
1203
+ 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) != "{}") {
1204
+ const fetchedState = JSON.parse((_h = (_g = result.data) == null ? void 0 : _g.loadAgentState) == null ? void 0 : _h.state);
1205
+ isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
1206
+ }
1207
+ });
1208
+ void fetchAgentState();
1209
+ }, [threadId]);
1180
1210
  const coagentState = getCoagentState(coagentStates, name);
1181
- const state = isExternalStateManagement(options) ? options.state : coagentState.state;
1182
1211
  (0, import_react13.useEffect)(() => {
1183
1212
  if (isExternalStateManagement(options)) {
1184
1213
  setState(options.state);