@copilotkit/react-core 1.3.16-mme-revert-rxjs-changes.10 → 1.3.16-mme-reset-chat.11

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 (88) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/{chunk-G2K6T2QU.mjs → chunk-24ALPG2R.mjs} +16 -8
  3. package/dist/chunk-24ALPG2R.mjs.map +1 -0
  4. package/dist/{chunk-ZM6HV22S.mjs → chunk-A6THC3F6.mjs} +2 -2
  5. package/dist/{chunk-XACBOJF5.mjs → chunk-FITKQ6YQ.mjs} +23 -5
  6. package/dist/{chunk-XACBOJF5.mjs.map → chunk-FITKQ6YQ.mjs.map} +1 -1
  7. package/dist/{chunk-RYDEG77L.mjs → chunk-FXT6XSUB.mjs} +2 -2
  8. package/dist/{chunk-7DFHFZJT.mjs → chunk-I7XLZC4D.mjs} +2 -2
  9. package/dist/{chunk-MX2OYLRS.mjs → chunk-KJ3U5SXS.mjs} +36 -6
  10. package/dist/chunk-KJ3U5SXS.mjs.map +1 -0
  11. package/dist/{chunk-TRXKPXDE.mjs → chunk-N57PDRVX.mjs} +2 -2
  12. package/dist/{chunk-27IPQFJP.mjs → chunk-PHP2YMMH.mjs} +2 -2
  13. package/dist/{chunk-6YEMNWKE.mjs → chunk-UFSLLJZY.mjs} +12 -3
  14. package/dist/{chunk-6YEMNWKE.mjs.map → chunk-UFSLLJZY.mjs.map} +1 -1
  15. package/dist/{chunk-2MPUQRAY.mjs → chunk-WBBL7MG6.mjs} +10 -2
  16. package/dist/{chunk-2MPUQRAY.mjs.map → chunk-WBBL7MG6.mjs.map} +1 -1
  17. package/dist/{chunk-ANOG3W5S.mjs → chunk-ZDYUMEE5.mjs} +2 -2
  18. package/dist/components/copilot-provider/copilotkit.js +19 -2
  19. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  20. package/dist/components/copilot-provider/copilotkit.mjs +2 -2
  21. package/dist/components/copilot-provider/index.js +19 -2
  22. package/dist/components/copilot-provider/index.js.map +1 -1
  23. package/dist/components/copilot-provider/index.mjs +2 -2
  24. package/dist/components/index.js +19 -2
  25. package/dist/components/index.js.map +1 -1
  26. package/dist/components/index.mjs +2 -2
  27. package/dist/context/copilot-context.d.ts +6 -0
  28. package/dist/context/copilot-context.js +9 -1
  29. package/dist/context/copilot-context.js.map +1 -1
  30. package/dist/context/copilot-context.mjs +1 -1
  31. package/dist/context/index.js +9 -1
  32. package/dist/context/index.js.map +1 -1
  33. package/dist/context/index.mjs +1 -1
  34. package/dist/hooks/index.d.ts +2 -1
  35. package/dist/hooks/index.js +78 -11
  36. package/dist/hooks/index.js.map +1 -1
  37. package/dist/hooks/index.mjs +15 -9
  38. package/dist/hooks/use-chat.d.ts +20 -0
  39. package/dist/hooks/use-chat.js +15 -7
  40. package/dist/hooks/use-chat.js.map +1 -1
  41. package/dist/hooks/use-chat.mjs +1 -1
  42. package/dist/hooks/use-coagent-state-render.js +9 -1
  43. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  44. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  45. package/dist/hooks/use-coagent.d.ts +14 -1
  46. package/dist/hooks/use-coagent.js +78 -11
  47. package/dist/hooks/use-coagent.js.map +1 -1
  48. package/dist/hooks/use-coagent.mjs +11 -5
  49. package/dist/hooks/use-copilot-action.js +9 -1
  50. package/dist/hooks/use-copilot-action.js.map +1 -1
  51. package/dist/hooks/use-copilot-action.mjs +2 -2
  52. package/dist/hooks/use-copilot-chat.d.ts +1 -0
  53. package/dist/hooks/use-copilot-chat.js +56 -10
  54. package/dist/hooks/use-copilot-chat.js.map +1 -1
  55. package/dist/hooks/use-copilot-chat.mjs +4 -4
  56. package/dist/hooks/use-copilot-readable.js +9 -1
  57. package/dist/hooks/use-copilot-readable.js.map +1 -1
  58. package/dist/hooks/use-copilot-readable.mjs +2 -2
  59. package/dist/hooks/use-make-copilot-document-readable.js +9 -1
  60. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  61. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  62. package/dist/index.d.ts +1 -1
  63. package/dist/index.js +88 -12
  64. package/dist/index.js.map +1 -1
  65. package/dist/index.mjs +17 -11
  66. package/dist/lib/copilot-task.js.map +1 -1
  67. package/dist/lib/copilot-task.mjs +3 -3
  68. package/dist/lib/index.js.map +1 -1
  69. package/dist/lib/index.mjs +3 -3
  70. package/dist/utils/extract.js.map +1 -1
  71. package/dist/utils/extract.mjs +3 -3
  72. package/dist/utils/index.js.map +1 -1
  73. package/dist/utils/index.mjs +3 -3
  74. package/package.json +5 -5
  75. package/src/components/copilot-provider/copilotkit.tsx +10 -0
  76. package/src/context/copilot-context.tsx +21 -0
  77. package/src/hooks/index.ts +1 -1
  78. package/src/hooks/use-chat.ts +40 -7
  79. package/src/hooks/use-coagent.ts +21 -4
  80. package/src/hooks/use-copilot-chat.ts +35 -4
  81. package/dist/chunk-G2K6T2QU.mjs.map +0 -1
  82. package/dist/chunk-MX2OYLRS.mjs.map +0 -1
  83. /package/dist/{chunk-ZM6HV22S.mjs.map → chunk-A6THC3F6.mjs.map} +0 -0
  84. /package/dist/{chunk-RYDEG77L.mjs.map → chunk-FXT6XSUB.mjs.map} +0 -0
  85. /package/dist/{chunk-7DFHFZJT.mjs.map → chunk-I7XLZC4D.mjs.map} +0 -0
  86. /package/dist/{chunk-TRXKPXDE.mjs.map → chunk-N57PDRVX.mjs.map} +0 -0
  87. /package/dist/{chunk-27IPQFJP.mjs.map → chunk-PHP2YMMH.mjs.map} +0 -0
  88. /package/dist/{chunk-ANOG3W5S.mjs.map → chunk-ZDYUMEE5.mjs.map} +0 -0
package/dist/index.js CHANGED
@@ -87,6 +87,9 @@ __export(src_exports, {
87
87
  CopilotTask: () => CopilotTask,
88
88
  defaultCopilotContextCategories: () => defaultCopilotContextCategories,
89
89
  extract: () => extract,
90
+ runAgent: () => runAgent,
91
+ startAgent: () => startAgent,
92
+ stopAgent: () => stopAgent,
90
93
  useCoAgent: () => useCoAgent,
91
94
  useCoAgentStateRender: () => useCoAgentStateRender,
92
95
  useCopilotAction: () => useCopilotAction,
@@ -151,7 +154,15 @@ var emptyCopilotContext = {
151
154
  },
152
155
  agentSession: null,
153
156
  setAgentSession: () => {
154
- }
157
+ },
158
+ agentLock: null,
159
+ threadId: null,
160
+ setThreadId: () => {
161
+ },
162
+ runId: null,
163
+ setRunId: () => {
164
+ },
165
+ chatAbortControllerRef: { current: null }
155
166
  };
156
167
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
157
168
  function useCopilotContext() {
@@ -565,6 +576,9 @@ ${nonDocumentStrings}`;
565
576
  };
566
577
  }
567
578
  const [agentSession, setAgentSession] = (0, import_react6.useState)(initialAgentSession);
579
+ const [threadId, setThreadId] = (0, import_react6.useState)(null);
580
+ const [runId, setRunId] = (0, import_react6.useState)(null);
581
+ const chatAbortControllerRef = (0, import_react6.useRef)(null);
568
582
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
569
583
  CopilotContext.Provider,
570
584
  {
@@ -595,7 +609,13 @@ ${nonDocumentStrings}`;
595
609
  coagentStates,
596
610
  setCoagentStates,
597
611
  agentSession,
598
- setAgentSession
612
+ setAgentSession,
613
+ agentLock: props.agent || null,
614
+ threadId,
615
+ setThreadId,
616
+ runId,
617
+ setRunId,
618
+ chatAbortControllerRef
599
619
  },
600
620
  children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CopilotMessages, { children })
601
621
  }
@@ -651,16 +671,22 @@ function useChat(options) {
651
671
  setCoagentStates,
652
672
  coagentStates,
653
673
  agentSession,
654
- setAgentSession
674
+ setAgentSession,
675
+ threadId,
676
+ setThreadId,
677
+ runId,
678
+ setRunId,
679
+ chatAbortControllerRef
655
680
  } = options;
656
- const abortControllerRef = (0, import_react7.useRef)();
657
- const threadIdRef = (0, import_react7.useRef)(null);
658
- const runIdRef = (0, import_react7.useRef)(null);
659
681
  const runChatCompletionRef = (0, import_react7.useRef)();
660
682
  const coagentStatesRef = (0, import_react7.useRef)(coagentStates);
661
683
  coagentStatesRef.current = coagentStates;
662
684
  const agentSessionRef = (0, import_react7.useRef)(agentSession);
663
685
  agentSessionRef.current = agentSession;
686
+ const threadIdRef = (0, import_react7.useRef)(threadId);
687
+ threadIdRef.current = threadId;
688
+ const runIdRef = (0, import_react7.useRef)(runId);
689
+ runIdRef.current = runId;
664
690
  const publicApiKey = copilotConfig.publicApiKey;
665
691
  const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared4.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
666
692
  const runtimeClient = new import_runtime_client_gql.CopilotRuntimeClient({
@@ -679,7 +705,7 @@ function useChat(options) {
679
705
  })
680
706
  ];
681
707
  const abortController = new AbortController();
682
- abortControllerRef.current = abortController;
708
+ chatAbortControllerRef.current = abortController;
683
709
  setMessages([...previousMessages, ...newMessages]);
684
710
  const systemMessage = makeSystemMessageCallback();
685
711
  const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
@@ -719,7 +745,7 @@ function useChat(options) {
719
745
  }))
720
746
  }),
721
747
  properties: copilotConfig.properties,
722
- signal: (_d = abortControllerRef.current) == null ? void 0 : _d.signal
748
+ signal: (_d = chatAbortControllerRef.current) == null ? void 0 : _d.signal
723
749
  })
724
750
  );
725
751
  const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
@@ -738,6 +764,8 @@ function useChat(options) {
738
764
  }
739
765
  threadIdRef.current = value.generateCopilotResponse.threadId || null;
740
766
  runIdRef.current = value.generateCopilotResponse.runId || null;
767
+ setThreadId(threadIdRef.current);
768
+ setRunId(runIdRef.current);
741
769
  const messages2 = (0, import_runtime_client_gql.convertGqlOutputToMessages)(
742
770
  (0, import_runtime_client_gql.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
743
771
  );
@@ -866,7 +894,7 @@ function useChat(options) {
866
894
  });
867
895
  const stop = () => {
868
896
  var _a;
869
- (_a = abortControllerRef.current) == null ? void 0 : _a.abort();
897
+ (_a = chatAbortControllerRef.current) == null ? void 0 : _a.abort();
870
898
  };
871
899
  return {
872
900
  append,
@@ -894,7 +922,13 @@ function useCopilotChat(_a = {}) {
894
922
  setCoagentStates,
895
923
  coAgentStateRenders,
896
924
  agentSession,
897
- setAgentSession
925
+ setAgentSession,
926
+ agentLock,
927
+ threadId,
928
+ setThreadId,
929
+ runId,
930
+ setRunId,
931
+ chatAbortControllerRef
898
932
  } = useCopilotContext();
899
933
  const { messages, setMessages } = useCopilotMessagesContext();
900
934
  const latestGetContextString = useUpdatedRef(getContextString);
@@ -944,7 +978,12 @@ function useCopilotChat(_a = {}) {
944
978
  coagentStates,
945
979
  setCoagentStates,
946
980
  agentSession,
947
- setAgentSession
981
+ setAgentSession,
982
+ threadId,
983
+ setThreadId,
984
+ runId,
985
+ setRunId,
986
+ chatAbortControllerRef
948
987
  }));
949
988
  const latestAppend = useUpdatedRef(append);
950
989
  const latestAppendFunc = (0, import_react8.useCallback)(
@@ -975,6 +1014,24 @@ function useCopilotChat(_a = {}) {
975
1014
  },
976
1015
  [latestSetMessages]
977
1016
  );
1017
+ const reset = (0, import_react8.useCallback)(() => {
1018
+ latestStopFunc();
1019
+ setMessages([]);
1020
+ setThreadId(null);
1021
+ setRunId(null);
1022
+ setCoagentStates({});
1023
+ let initialAgentSession = null;
1024
+ if (agentLock) {
1025
+ initialAgentSession = {
1026
+ agentName: agentLock
1027
+ };
1028
+ }
1029
+ setAgentSession(initialAgentSession);
1030
+ }, [latestStopFunc, setMessages, setThreadId, setCoagentStates, setAgentSession, agentLock]);
1031
+ const latestReset = useUpdatedRef(reset);
1032
+ const latestResetFunc = (0, import_react8.useCallback)(() => {
1033
+ return latestReset.current();
1034
+ }, [latestReset]);
978
1035
  return {
979
1036
  visibleMessages: messages,
980
1037
  appendMessage: latestAppendFunc,
@@ -982,6 +1039,7 @@ function useCopilotChat(_a = {}) {
982
1039
  reloadMessages: latestReloadFunc,
983
1040
  stopGeneration: latestStopFunc,
984
1041
  deleteMessage: latestDeleteFunc,
1042
+ reset: latestResetFunc,
985
1043
  isLoading
986
1044
  };
987
1045
  }
@@ -1206,7 +1264,11 @@ function useCoAgent(options) {
1206
1264
  } else if (coagentStates[name] === void 0) {
1207
1265
  setState(options.initialState === void 0 ? {} : options.initialState);
1208
1266
  }
1209
- }, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
1267
+ }, [
1268
+ isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
1269
+ // reset initial state on reset
1270
+ coagentStates[name] === void 0
1271
+ ]);
1210
1272
  return {
1211
1273
  name,
1212
1274
  nodeName: coagentState.nodeName,
@@ -1234,6 +1296,17 @@ function stopAgent(name, context) {
1234
1296
  const { agentSession, setAgentSession } = context;
1235
1297
  if (agentSession && agentSession.agentName === name) {
1236
1298
  setAgentSession(null);
1299
+ context.setCoagentStates((prevAgentStates) => {
1300
+ return __spreadProps(__spreadValues({}, prevAgentStates), {
1301
+ [name]: __spreadProps(__spreadValues({}, prevAgentStates[name]), {
1302
+ running: false,
1303
+ active: false,
1304
+ threadId: void 0,
1305
+ nodeName: void 0,
1306
+ runId: void 0
1307
+ })
1308
+ });
1309
+ });
1237
1310
  } else {
1238
1311
  console.warn(`No agent session found for ${name}`);
1239
1312
  }
@@ -1512,6 +1585,9 @@ This is not a conversation, so please do not ask questions. Just call the functi
1512
1585
  CopilotTask,
1513
1586
  defaultCopilotContextCategories,
1514
1587
  extract,
1588
+ runAgent,
1589
+ startAgent,
1590
+ stopAgent,
1515
1591
  useCoAgent,
1516
1592
  useCoAgentStateRender,
1517
1593
  useCopilotAction,