@copilotkit/react-core 1.3.16-mme-lgc-langgraph-package.11 → 1.3.16-mme-reset-chat.10

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 (92) hide show
  1. package/CHANGELOG.md +50 -83
  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-RYDEG77L.mjs → chunk-FXT6XSUB.mjs} +2 -2
  6. package/dist/{chunk-7DFHFZJT.mjs → chunk-I7XLZC4D.mjs} +2 -2
  7. package/dist/{chunk-MX2OYLRS.mjs → chunk-KJ3U5SXS.mjs} +36 -6
  8. package/dist/chunk-KJ3U5SXS.mjs.map +1 -0
  9. package/dist/{chunk-DR6XFKOA.mjs → chunk-KNKSEGAE.mjs} +23 -5
  10. package/dist/chunk-KNKSEGAE.mjs.map +1 -0
  11. package/dist/{chunk-TRXKPXDE.mjs → chunk-N57PDRVX.mjs} +2 -2
  12. package/dist/{chunk-J6LU67YH.mjs → chunk-PHP2YMMH.mjs} +2 -2
  13. package/dist/chunk-PHP2YMMH.mjs.map +1 -0
  14. package/dist/{chunk-6YEMNWKE.mjs → chunk-UFSLLJZY.mjs} +12 -3
  15. package/dist/{chunk-6YEMNWKE.mjs.map → chunk-UFSLLJZY.mjs.map} +1 -1
  16. package/dist/{chunk-2MPUQRAY.mjs → chunk-WBBL7MG6.mjs} +10 -2
  17. package/dist/{chunk-2MPUQRAY.mjs.map → chunk-WBBL7MG6.mjs.map} +1 -1
  18. package/dist/{chunk-ANOG3W5S.mjs → chunk-ZDYUMEE5.mjs} +2 -2
  19. package/dist/components/copilot-provider/copilotkit.js +19 -2
  20. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  21. package/dist/components/copilot-provider/copilotkit.mjs +2 -2
  22. package/dist/components/copilot-provider/index.js +19 -2
  23. package/dist/components/copilot-provider/index.js.map +1 -1
  24. package/dist/components/copilot-provider/index.mjs +2 -2
  25. package/dist/components/index.js +19 -2
  26. package/dist/components/index.js.map +1 -1
  27. package/dist/components/index.mjs +2 -2
  28. package/dist/context/copilot-context.d.ts +6 -0
  29. package/dist/context/copilot-context.js +9 -1
  30. package/dist/context/copilot-context.js.map +1 -1
  31. package/dist/context/copilot-context.mjs +1 -1
  32. package/dist/context/index.js +9 -1
  33. package/dist/context/index.js.map +1 -1
  34. package/dist/context/index.mjs +1 -1
  35. package/dist/hooks/index.d.ts +2 -1
  36. package/dist/hooks/index.js +78 -11
  37. package/dist/hooks/index.js.map +1 -1
  38. package/dist/hooks/index.mjs +22 -16
  39. package/dist/hooks/use-chat.d.ts +20 -0
  40. package/dist/hooks/use-chat.js +15 -7
  41. package/dist/hooks/use-chat.js.map +1 -1
  42. package/dist/hooks/use-chat.mjs +1 -1
  43. package/dist/hooks/use-coagent-state-render.d.ts +3 -3
  44. package/dist/hooks/use-coagent-state-render.js +9 -1
  45. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  46. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  47. package/dist/hooks/use-coagent.d.ts +17 -4
  48. package/dist/hooks/use-coagent.js +78 -11
  49. package/dist/hooks/use-coagent.js.map +1 -1
  50. package/dist/hooks/use-coagent.mjs +12 -6
  51. package/dist/hooks/use-copilot-action.js +9 -1
  52. package/dist/hooks/use-copilot-action.js.map +1 -1
  53. package/dist/hooks/use-copilot-action.mjs +2 -2
  54. package/dist/hooks/use-copilot-chat.d.ts +1 -0
  55. package/dist/hooks/use-copilot-chat.js +56 -10
  56. package/dist/hooks/use-copilot-chat.js.map +1 -1
  57. package/dist/hooks/use-copilot-chat.mjs +5 -5
  58. package/dist/hooks/use-copilot-readable.js +9 -1
  59. package/dist/hooks/use-copilot-readable.js.map +1 -1
  60. package/dist/hooks/use-copilot-readable.mjs +2 -2
  61. package/dist/hooks/use-make-copilot-document-readable.js +9 -1
  62. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  63. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  64. package/dist/index.d.ts +1 -1
  65. package/dist/index.js +88 -12
  66. package/dist/index.js.map +1 -1
  67. package/dist/index.mjs +24 -18
  68. package/dist/lib/copilot-task.js.map +1 -1
  69. package/dist/lib/copilot-task.mjs +3 -3
  70. package/dist/lib/index.js.map +1 -1
  71. package/dist/lib/index.mjs +3 -3
  72. package/dist/utils/extract.js.map +1 -1
  73. package/dist/utils/extract.mjs +3 -3
  74. package/dist/utils/index.js.map +1 -1
  75. package/dist/utils/index.mjs +3 -3
  76. package/package.json +5 -5
  77. package/src/components/copilot-provider/copilotkit.tsx +10 -0
  78. package/src/context/copilot-context.tsx +21 -0
  79. package/src/hooks/index.ts +1 -1
  80. package/src/hooks/use-chat.ts +40 -7
  81. package/src/hooks/use-coagent-state-render.ts +3 -3
  82. package/src/hooks/use-coagent.ts +24 -7
  83. package/src/hooks/use-copilot-chat.ts +35 -4
  84. package/dist/chunk-DR6XFKOA.mjs.map +0 -1
  85. package/dist/chunk-G2K6T2QU.mjs.map +0 -1
  86. package/dist/chunk-J6LU67YH.mjs.map +0 -1
  87. package/dist/chunk-MX2OYLRS.mjs.map +0 -1
  88. /package/dist/{chunk-ZM6HV22S.mjs.map → chunk-A6THC3F6.mjs.map} +0 -0
  89. /package/dist/{chunk-RYDEG77L.mjs.map → chunk-FXT6XSUB.mjs.map} +0 -0
  90. /package/dist/{chunk-7DFHFZJT.mjs.map → chunk-I7XLZC4D.mjs.map} +0 -0
  91. /package/dist/{chunk-TRXKPXDE.mjs.map → chunk-N57PDRVX.mjs.map} +0 -0
  92. /package/dist/{chunk-ANOG3W5S.mjs.map → chunk-ZDYUMEE5.mjs.map} +0 -0
@@ -6,7 +6,7 @@ import {
6
6
  import {
7
7
  CopilotContext,
8
8
  useCopilotContext
9
- } from "../chunk-2MPUQRAY.mjs";
9
+ } from "../chunk-WBBL7MG6.mjs";
10
10
  import "../chunk-SKC7AJIV.mjs";
11
11
  export {
12
12
  CopilotContext,
@@ -4,7 +4,7 @@ export { useCoAgentStateRender } from './use-coagent-state-render.js';
4
4
  export { useMakeCopilotDocumentReadable } from './use-make-copilot-document-readable.js';
5
5
  export { UseChatHelpers } from './use-chat.js';
6
6
  export { useCopilotReadable } from './use-copilot-readable.js';
7
- export { useCoAgent } from './use-coagent.js';
7
+ export { HintFunction, runAgent, startAgent, stopAgent, useCoAgent } from './use-coagent.js';
8
8
  import '@copilotkit/runtime-client-gql';
9
9
  import '../types/system-message.js';
10
10
  import '../types/frontend-action.js';
@@ -16,3 +16,4 @@ import '../context/copilot-context.js';
16
16
  import './use-tree.js';
17
17
  import '../types/chat-suggestion-configuration.js';
18
18
  import '../types/coagent-state.js';
19
+ import '../context/copilot-messages-context.js';
@@ -79,6 +79,9 @@ var __async = (__this, __arguments, generator) => {
79
79
  // src/hooks/index.ts
80
80
  var hooks_exports = {};
81
81
  __export(hooks_exports, {
82
+ runAgent: () => runAgent,
83
+ startAgent: () => startAgent,
84
+ stopAgent: () => stopAgent,
82
85
  useCoAgent: () => useCoAgent,
83
86
  useCoAgentStateRender: () => useCoAgentStateRender,
84
87
  useCopilotAction: () => useCopilotAction,
@@ -141,7 +144,15 @@ var emptyCopilotContext = {
141
144
  },
142
145
  agentSession: null,
143
146
  setAgentSession: () => {
144
- }
147
+ },
148
+ agentLock: null,
149
+ threadId: null,
150
+ setThreadId: () => {
151
+ },
152
+ runId: null,
153
+ setRunId: () => {
154
+ },
155
+ chatAbortControllerRef: { current: null }
145
156
  };
146
157
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
147
158
  function useCopilotContext() {
@@ -178,16 +189,22 @@ function useChat(options) {
178
189
  setCoagentStates,
179
190
  coagentStates,
180
191
  agentSession,
181
- setAgentSession
192
+ setAgentSession,
193
+ threadId,
194
+ setThreadId,
195
+ runId,
196
+ setRunId,
197
+ chatAbortControllerRef
182
198
  } = options;
183
- const abortControllerRef = (0, import_react2.useRef)();
184
- const threadIdRef = (0, import_react2.useRef)(null);
185
- const runIdRef = (0, import_react2.useRef)(null);
186
199
  const runChatCompletionRef = (0, import_react2.useRef)();
187
200
  const coagentStatesRef = (0, import_react2.useRef)(coagentStates);
188
201
  coagentStatesRef.current = coagentStates;
189
202
  const agentSessionRef = (0, import_react2.useRef)(agentSession);
190
203
  agentSessionRef.current = agentSession;
204
+ const threadIdRef = (0, import_react2.useRef)(threadId);
205
+ threadIdRef.current = threadId;
206
+ const runIdRef = (0, import_react2.useRef)(runId);
207
+ runIdRef.current = runId;
191
208
  const publicApiKey = copilotConfig.publicApiKey;
192
209
  const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
193
210
  const runtimeClient = new import_runtime_client_gql.CopilotRuntimeClient({
@@ -206,7 +223,7 @@ function useChat(options) {
206
223
  })
207
224
  ];
208
225
  const abortController = new AbortController();
209
- abortControllerRef.current = abortController;
226
+ chatAbortControllerRef.current = abortController;
210
227
  setMessages([...previousMessages, ...newMessages]);
211
228
  const systemMessage = makeSystemMessageCallback();
212
229
  const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
@@ -246,7 +263,7 @@ function useChat(options) {
246
263
  }))
247
264
  }),
248
265
  properties: copilotConfig.properties,
249
- signal: (_d = abortControllerRef.current) == null ? void 0 : _d.signal
266
+ signal: (_d = chatAbortControllerRef.current) == null ? void 0 : _d.signal
250
267
  })
251
268
  );
252
269
  const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
@@ -265,6 +282,8 @@ function useChat(options) {
265
282
  }
266
283
  threadIdRef.current = value.generateCopilotResponse.threadId || null;
267
284
  runIdRef.current = value.generateCopilotResponse.runId || null;
285
+ setThreadId(threadIdRef.current);
286
+ setRunId(runIdRef.current);
268
287
  const messages2 = (0, import_runtime_client_gql.convertGqlOutputToMessages)(
269
288
  (0, import_runtime_client_gql.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
270
289
  );
@@ -393,7 +412,7 @@ function useChat(options) {
393
412
  });
394
413
  const stop = () => {
395
414
  var _a;
396
- (_a = abortControllerRef.current) == null ? void 0 : _a.abort();
415
+ (_a = chatAbortControllerRef.current) == null ? void 0 : _a.abort();
397
416
  };
398
417
  return {
399
418
  append,
@@ -447,7 +466,13 @@ function useCopilotChat(_a = {}) {
447
466
  setCoagentStates,
448
467
  coAgentStateRenders,
449
468
  agentSession,
450
- setAgentSession
469
+ setAgentSession,
470
+ agentLock,
471
+ threadId,
472
+ setThreadId,
473
+ runId,
474
+ setRunId,
475
+ chatAbortControllerRef
451
476
  } = useCopilotContext();
452
477
  const { messages, setMessages } = useCopilotMessagesContext();
453
478
  const latestGetContextString = useUpdatedRef(getContextString);
@@ -497,7 +522,12 @@ function useCopilotChat(_a = {}) {
497
522
  coagentStates,
498
523
  setCoagentStates,
499
524
  agentSession,
500
- setAgentSession
525
+ setAgentSession,
526
+ threadId,
527
+ setThreadId,
528
+ runId,
529
+ setRunId,
530
+ chatAbortControllerRef
501
531
  }));
502
532
  const latestAppend = useUpdatedRef(append);
503
533
  const latestAppendFunc = (0, import_react5.useCallback)(
@@ -528,6 +558,24 @@ function useCopilotChat(_a = {}) {
528
558
  },
529
559
  [latestSetMessages]
530
560
  );
561
+ const reset = (0, import_react5.useCallback)(() => {
562
+ latestStopFunc();
563
+ setMessages([]);
564
+ setThreadId(null);
565
+ setRunId(null);
566
+ setCoagentStates({});
567
+ let initialAgentSession = null;
568
+ if (agentLock) {
569
+ initialAgentSession = {
570
+ agentName: agentLock
571
+ };
572
+ }
573
+ setAgentSession(initialAgentSession);
574
+ }, [latestStopFunc, setMessages, setThreadId, setCoagentStates, setAgentSession, agentLock]);
575
+ const latestReset = useUpdatedRef(reset);
576
+ const latestResetFunc = (0, import_react5.useCallback)(() => {
577
+ return latestReset.current();
578
+ }, [latestReset]);
531
579
  return {
532
580
  visibleMessages: messages,
533
581
  appendMessage: latestAppendFunc,
@@ -535,6 +583,7 @@ function useCopilotChat(_a = {}) {
535
583
  reloadMessages: latestReloadFunc,
536
584
  stopGeneration: latestStopFunc,
537
585
  deleteMessage: latestDeleteFunc,
586
+ reset: latestResetFunc,
538
587
  isLoading
539
588
  };
540
589
  }
@@ -759,7 +808,11 @@ function useCoAgent(options) {
759
808
  } else if (coagentStates[name] === void 0) {
760
809
  setState(options.initialState === void 0 ? {} : options.initialState);
761
810
  }
762
- }, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
811
+ }, [
812
+ isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
813
+ // reset initial state on reset
814
+ coagentStates[name] === void 0
815
+ ]);
763
816
  return {
764
817
  name,
765
818
  nodeName: coagentState.nodeName,
@@ -787,6 +840,17 @@ function stopAgent(name, context) {
787
840
  const { agentSession, setAgentSession } = context;
788
841
  if (agentSession && agentSession.agentName === name) {
789
842
  setAgentSession(null);
843
+ context.setCoagentStates((prevAgentStates) => {
844
+ return __spreadProps(__spreadValues({}, prevAgentStates), {
845
+ [name]: __spreadProps(__spreadValues({}, prevAgentStates[name]), {
846
+ running: false,
847
+ active: false,
848
+ threadId: void 0,
849
+ nodeName: void 0,
850
+ runId: void 0
851
+ })
852
+ });
853
+ });
790
854
  } else {
791
855
  console.warn(`No agent session found for ${name}`);
792
856
  }
@@ -818,6 +882,9 @@ function runAgent(name, context, appendMessage, hint) {
818
882
  }
819
883
  // Annotate the CommonJS export names for ESM import in node:
820
884
  0 && (module.exports = {
885
+ runAgent,
886
+ startAgent,
887
+ stopAgent,
821
888
  useCoAgent,
822
889
  useCoAgentStateRender,
823
890
  useCopilotAction,