@copilotkit/react-core 1.54.1-next.2 → 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/dist/index.umd.js CHANGED
@@ -2133,12 +2133,16 @@ react_markdown = __toESM(react_markdown);
2133
2133
  const resolvedAgentId = (_existingConfig$agent = existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.agentId) !== null && _existingConfig$agent !== void 0 ? _existingConfig$agent : "default";
2134
2134
  const { agent } = (0, _copilotkitnext_react.useAgent)({ agentId: resolvedAgentId });
2135
2135
  (0, react.useEffect)(() => {
2136
+ let detached = false;
2137
+ const connectAbortController = new AbortController();
2138
+ if (agent instanceof _ag_ui_client.HttpAgent) agent.abortController = connectAbortController;
2136
2139
  const connect = async (agent) => {
2137
2140
  setAgentAvailable(false);
2138
2141
  try {
2139
2142
  await copilotkit.connectAgent({ agent });
2140
- setAgentAvailable(true);
2143
+ if (!detached) setAgentAvailable(true);
2141
2144
  } catch (error) {
2145
+ if (detached) return;
2142
2146
  if (error instanceof _ag_ui_client.AGUIConnectNotImplementedError) {} else console.error("CopilotChat: connectAgent failed", error);
2143
2147
  }
2144
2148
  };
@@ -2146,7 +2150,11 @@ react_markdown = __toESM(react_markdown);
2146
2150
  agent.threadId = existingConfig.threadId;
2147
2151
  connect(agent);
2148
2152
  }
2149
- return () => {};
2153
+ return () => {
2154
+ detached = true;
2155
+ connectAbortController.abort();
2156
+ agent === null || agent === void 0 || agent.detachActiveRun();
2157
+ };
2150
2158
  }, [
2151
2159
  existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.threadId,
2152
2160
  agent,