@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 +11 -0
- package/dist/index.cjs +10 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +11 -3
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +10 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +5 -5
- package/src/hooks/__tests__/use-coagent-state-render.e2e.test.tsx +1 -0
- package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +1 -0
- package/src/hooks/use-copilot-chat_internal.ts +30 -3
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"version": "1.54.1-next.
|
|
13
|
+
"version": "1.54.1-next.4",
|
|
14
14
|
"sideEffects": [
|
|
15
15
|
"**/*.css"
|
|
16
16
|
],
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
"@scarf/scarf": "^1.3.0",
|
|
60
60
|
"react-markdown": "^8.0.7",
|
|
61
61
|
"untruncate-json": "^0.0.1",
|
|
62
|
-
"@copilotkit/runtime-client-gql": "1.54.1-next.
|
|
63
|
-
"@copilotkit/shared": "1.54.1-next.
|
|
64
|
-
"@copilotkitnext/core": "1.54.1-next.
|
|
65
|
-
"@copilotkitnext/react": "1.54.1-next.
|
|
62
|
+
"@copilotkit/runtime-client-gql": "1.54.1-next.4",
|
|
63
|
+
"@copilotkit/shared": "1.54.1-next.4",
|
|
64
|
+
"@copilotkitnext/core": "1.54.1-next.4",
|
|
65
|
+
"@copilotkitnext/react": "1.54.1-next.4"
|
|
66
66
|
},
|
|
67
67
|
"keywords": [
|
|
68
68
|
"copilotkit",
|
|
@@ -26,7 +26,11 @@ import {
|
|
|
26
26
|
CopilotKitCoreRuntimeConnectionStatus,
|
|
27
27
|
} from "@copilotkitnext/core";
|
|
28
28
|
import { useLazyToolRenderer } from "./use-lazy-tool-renderer";
|
|
29
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
AbstractAgent,
|
|
31
|
+
AGUIConnectNotImplementedError,
|
|
32
|
+
HttpAgent,
|
|
33
|
+
} from "@ag-ui/client";
|
|
30
34
|
import {
|
|
31
35
|
CoAgentStateRenderBridge,
|
|
32
36
|
type CoAgentStateRenderBridgeProps,
|
|
@@ -336,12 +340,28 @@ export function useCopilotChatInternal({
|
|
|
336
340
|
const { agent } = useAgent({ agentId: resolvedAgentId });
|
|
337
341
|
|
|
338
342
|
useEffect(() => {
|
|
343
|
+
let detached = false;
|
|
344
|
+
|
|
345
|
+
// Create a fresh AbortController so we can cancel the HTTP request on cleanup.
|
|
346
|
+
// Mirrors the V2 CopilotChat pattern: HttpAgent uses abortController.signal in
|
|
347
|
+
// its fetch config. connectAgent() does NOT create a new AbortController
|
|
348
|
+
// automatically, so we must set one before connecting.
|
|
349
|
+
const connectAbortController = new AbortController();
|
|
350
|
+
if (agent instanceof HttpAgent) {
|
|
351
|
+
agent.abortController = connectAbortController;
|
|
352
|
+
}
|
|
353
|
+
|
|
339
354
|
const connect = async (agent: AbstractAgent) => {
|
|
340
355
|
setAgentAvailable(false);
|
|
341
356
|
try {
|
|
342
357
|
await copilotkit.connectAgent({ agent });
|
|
343
|
-
|
|
358
|
+
// Guard against setting state after cleanup (e.g. React StrictMode unmount)
|
|
359
|
+
if (!detached) {
|
|
360
|
+
setAgentAvailable(true);
|
|
361
|
+
}
|
|
344
362
|
} catch (error) {
|
|
363
|
+
// Ignore errors from aborted connections (e.g. React StrictMode cleanup)
|
|
364
|
+
if (detached) return;
|
|
345
365
|
if (error instanceof AGUIConnectNotImplementedError) {
|
|
346
366
|
// connect not implemented, ignore
|
|
347
367
|
} else {
|
|
@@ -360,7 +380,14 @@ export function useCopilotChatInternal({
|
|
|
360
380
|
agent.threadId = existingConfig.threadId;
|
|
361
381
|
connect(agent);
|
|
362
382
|
}
|
|
363
|
-
return () => {
|
|
383
|
+
return () => {
|
|
384
|
+
// Abort the HTTP request and detach the active run.
|
|
385
|
+
// This is critical for React StrictMode which unmounts+remounts in dev,
|
|
386
|
+
// preventing duplicate /connect requests from reaching the server.
|
|
387
|
+
detached = true;
|
|
388
|
+
connectAbortController.abort();
|
|
389
|
+
agent?.detachActiveRun();
|
|
390
|
+
};
|
|
364
391
|
}, [
|
|
365
392
|
existingConfig?.threadId,
|
|
366
393
|
agent,
|