@copilotkit/core 1.57.1 → 1.57.3

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
@@ -295,10 +295,22 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
295
295
  * Reconnect to an existing thread by fetching websocket credentials and
296
296
  * joining the realtime thread channel.
297
297
  */
298
+ /**
299
+ * Reconnect to an existing thread by fetching websocket credentials
300
+ * and joining the realtime thread channel.
301
+ *
302
+ * Note: this method does NOT clear the replay cursor. Whether to
303
+ * request a full historical replay vs. resume from
304
+ * `lastSeenEventId` is a decision the caller (typically
305
+ * `RunHandler.connectAgent`) makes by calling
306
+ * {@link clearReconnectCursor} ahead of time on a fresh thread
307
+ * restore. Same-thread churn re-connects preserve the cursor so the
308
+ * gateway only streams events past it instead of replaying the
309
+ * entire history every time the chat re-opens a socket.
310
+ */
298
311
  connect(input) {
299
312
  this.threadId = input.threadId;
300
313
  this.canonicalRunId = null;
301
- this.clearReconnectCursor(input.threadId);
302
314
  return (0, rxjs.defer)(() => this.requestJoinCredentials$("connect", input)).pipe((0, rxjs.switchMap)((credentials) => {
303
315
  if (credentials === null) return rxjs.EMPTY;
304
316
  const canonicalInput = this.applyCanonicalRunIdentity(input, credentials, { fallbackToInputRunId: false });
@@ -483,6 +495,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
483
495
  getReconnectCursor(input) {
484
496
  return this.getLastSeenEventId(input.threadId);
485
497
  }
498
+ /**
499
+ * Drop the cached `lastSeenEventId` cursor for `threadId` so the
500
+ * next connect to that topic asks the gateway for a full historical
501
+ * replay (rather than resuming). Public because
502
+ * `RunHandler.connectAgent` calls it on a detected thread switch
503
+ * to rebuild local state from scratch, and skips it on same-thread
504
+ * churn so the gateway can resume.
505
+ */
486
506
  clearReconnectCursor(threadId) {
487
507
  this.sharedState.lastSeenEventIds.delete(threadId);
488
508
  }
@@ -776,6 +796,24 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
776
796
  }
777
797
  return cloned;
778
798
  }
799
+ /**
800
+ * Drop the delegate's cached `lastSeenEventId` for this thread so
801
+ * the next connect requests a full historical replay from the
802
+ * gateway. Used by `RunHandler.connectAgent` on a detected thread
803
+ * switch (the chat moved between threads, so its local
804
+ * messages/state are about to be cleared and need rebuilding from
805
+ * the gateway). Skipped on same-thread churn re-connects so the
806
+ * gateway can resume from the cursor instead.
807
+ *
808
+ * No-op for non-Intelligence runtime modes — the HTTP transport
809
+ * doesn't replay.
810
+ */
811
+ clearReplayCursor(threadId) {
812
+ var _delegate$clearReconn;
813
+ if (this.runtimeMode !== _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE) return;
814
+ const delegate = this.delegate;
815
+ delegate === null || delegate === void 0 || (_delegate$clearReconn = delegate.clearReconnectCursor) === null || _delegate$clearReconn === void 0 || _delegate$clearReconn.call(delegate, threadId);
816
+ }
779
817
  async resolveDelegate() {
780
818
  await this.ensureRuntimeMode();
781
819
  if (!this.delegate) {
@@ -937,6 +975,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
937
975
  _defineProperty(this, "_a2uiEnabled", false);
938
976
  _defineProperty(this, "_openGenerativeUIEnabled", false);
939
977
  _defineProperty(this, "_licenseStatus", void 0);
978
+ _defineProperty(this, "_telemetryDisabled", false);
940
979
  }
941
980
  /**
942
981
  * Get all agents as a readonly record
@@ -974,6 +1013,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
974
1013
  get licenseStatus() {
975
1014
  return this._licenseStatus;
976
1015
  }
1016
+ get telemetryDisabled() {
1017
+ return this._telemetryDisabled;
1018
+ }
977
1019
  /**
978
1020
  * Initialize agents from configuration
979
1021
  */
@@ -1142,7 +1184,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1142
1184
  this._runtimeConnectionStatus = CopilotKitCoreRuntimeConnectionStatus.Connecting;
1143
1185
  await this.notifyRuntimeStatusChanged(CopilotKitCoreRuntimeConnectionStatus.Connecting);
1144
1186
  try {
1145
- var _runtimeInfoResponse$2, _runtimeInfoResponse$3, _runtimeInfoResponse$4, _runtimeInfoResponse$5;
1187
+ var _runtimeInfoResponse$2, _runtimeInfoResponse$3, _runtimeInfoResponse$4, _runtimeInfoResponse$5, _runtimeInfoResponse$6;
1146
1188
  const runtimeInfoResponse = await this.fetchRuntimeInfo();
1147
1189
  const { version, ...runtimeInfo } = runtimeInfoResponse;
1148
1190
  const credentials = this.core.credentials;
@@ -1175,6 +1217,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1175
1217
  this._a2uiEnabled = (_runtimeInfoResponse$4 = runtimeInfoResponse.a2uiEnabled) !== null && _runtimeInfoResponse$4 !== void 0 ? _runtimeInfoResponse$4 : false;
1176
1218
  this._openGenerativeUIEnabled = (_runtimeInfoResponse$5 = runtimeInfoResponse.openGenerativeUIEnabled) !== null && _runtimeInfoResponse$5 !== void 0 ? _runtimeInfoResponse$5 : false;
1177
1219
  this._licenseStatus = runtimeInfoResponse.licenseStatus;
1220
+ this._telemetryDisabled = (_runtimeInfoResponse$6 = runtimeInfoResponse.telemetryDisabled) !== null && _runtimeInfoResponse$6 !== void 0 ? _runtimeInfoResponse$6 : false;
1178
1221
  await this.notifyRuntimeStatusChanged(CopilotKitCoreRuntimeConnectionStatus.Connected);
1179
1222
  await this.notifyAgentsChanged();
1180
1223
  } catch (error) {
@@ -1664,6 +1707,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1664
1707
  _defineProperty(this, "_tools", []);
1665
1708
  _defineProperty(this, "_runAbortController", null);
1666
1709
  _defineProperty(this, "_runDepth", 0);
1710
+ _defineProperty(this, "_lastConnectedThreadId", null);
1667
1711
  }
1668
1712
  /**
1669
1713
  * Abort the current run. Called by `CopilotKitCore.stopAgent()` to signal
@@ -1736,9 +1780,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1736
1780
  */
1737
1781
  async connectAgent({ agent }) {
1738
1782
  try {
1783
+ var _agent$threadId;
1784
+ const incomingThreadId = (_agent$threadId = agent.threadId) !== null && _agent$threadId !== void 0 ? _agent$threadId : null;
1785
+ const isFreshRestore = incomingThreadId !== this._lastConnectedThreadId;
1786
+ this._lastConnectedThreadId = incomingThreadId;
1739
1787
  await agent.detachActiveRun();
1740
- agent.setMessages([]);
1741
- agent.setState({});
1788
+ if (isFreshRestore) {
1789
+ agent.setMessages([]);
1790
+ agent.setState({});
1791
+ const proxied = agent;
1792
+ if (incomingThreadId && typeof proxied.clearReplayCursor === "function") proxied.clearReplayCursor(incomingThreadId);
1793
+ }
1742
1794
  if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...this._internal.headers };
1743
1795
  const runAgentResult = await agent.connectAgent({
1744
1796
  forwardedProps: this._internal.properties,
@@ -2762,6 +2814,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2762
2814
  get licenseStatus() {
2763
2815
  return this.agentRegistry.licenseStatus;
2764
2816
  }
2817
+ get telemetryDisabled() {
2818
+ return this.agentRegistry.telemetryDisabled;
2819
+ }
2765
2820
  /**
2766
2821
  * Configuration updates
2767
2822
  */