@copilotkit/react-core 1.54.1-next.3 → 1.54.1-next.4

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # ui
2
2
 
3
+ ## 1.54.1-next.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 8113dba: fix: race condition in RunHandler.runAgent() causes dropped runs
8
+ - Updated dependencies [8113dba]
9
+ - @copilotkitnext/core@1.54.1-next.4
10
+ - @copilotkitnext/react@1.54.1-next.4
11
+ - @copilotkit/runtime-client-gql@1.54.1-next.4
12
+ - @copilotkit/shared@1.54.1-next.4
13
+
3
14
  ## 1.54.1-next.3
4
15
 
5
16
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -45,12 +45,16 @@ function useCopilotChatInternal({ suggestions, onInProgress, onSubmitMessage, on
45
45
  const resolvedAgentId = existingConfig?.agentId ?? "default";
46
46
  const { agent } = (0, _copilotkitnext_react.useAgent)({ agentId: resolvedAgentId });
47
47
  (0, react.useEffect)(() => {
48
+ let detached = false;
49
+ const connectAbortController = new AbortController();
50
+ if (agent instanceof _ag_ui_client.HttpAgent) agent.abortController = connectAbortController;
48
51
  const connect = async (agent) => {
49
52
  setAgentAvailable(false);
50
53
  try {
51
54
  await copilotkit.connectAgent({ agent });
52
- setAgentAvailable(true);
55
+ if (!detached) setAgentAvailable(true);
53
56
  } catch (error) {
57
+ if (detached) return;
54
58
  if (error instanceof _ag_ui_client.AGUIConnectNotImplementedError) {} else console.error("CopilotChat: connectAgent failed", error);
55
59
  }
56
60
  };
@@ -58,7 +62,11 @@ function useCopilotChatInternal({ suggestions, onInProgress, onSubmitMessage, on
58
62
  agent.threadId = existingConfig.threadId;
59
63
  connect(agent);
60
64
  }
61
- return () => {};
65
+ return () => {
66
+ detached = true;
67
+ connectAbortController.abort();
68
+ agent?.detachActiveRun();
69
+ };
62
70
  }, [
63
71
  existingConfig?.threadId,
64
72
  agent,