@copilotkit/core 1.81.0 → 1.82.0

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.cjs CHANGED
@@ -1582,7 +1582,10 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui
1582
1582
  __copilotkitMcpResourceReadOnly: true
1583
1583
  }
1584
1584
  };
1585
- return this.runtimeMode === _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE ? this.clone().runAgent(resourceParameters) : this.runAgent(resourceParameters);
1585
+ if (this.runtimeMode !== _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE) return this.runAgent(resourceParameters);
1586
+ const resourceAgent = this.clone();
1587
+ resourceAgent.pendingInterrupts = [];
1588
+ return resourceAgent.runAgent(resourceParameters);
1586
1589
  }
1587
1590
  /**
1588
1591
  * Drop the delegate's cached `lastSeenEventId` for this thread so
@@ -3737,6 +3740,8 @@ function toolFailureMessage(error) {
3737
3740
  function discardAbortedResult(signal, discardOnAbort, errorMessage) {
3738
3741
  return !!(discardOnAbort && signal?.aborted && !(liveHITLStops.get(signal)?.() && errorMessage));
3739
3742
  }
3743
+ /** How many recent runs keep their request ID for a later approval resume. */
3744
+ const MAX_REMEMBERED_REQUEST_IDS = 100;
3740
3745
  /**
3741
3746
  * Absolute safety cap on the depth of recursive follow-up runs triggered by
3742
3747
  * `processAgentResult`. Without this, any scenario that keeps
@@ -3836,6 +3841,16 @@ var RunHandler = class {
3836
3841
  */
3837
3842
  _originalAbortRuns = /* @__PURE__ */ new WeakMap();
3838
3843
  /**
3844
+ * The request each agent's in-flight run belongs to. Its follow-up runs
3845
+ * send the same ID, so Intelligence counts the chain as one request.
3846
+ */
3847
+ _activeRequestIds = /* @__PURE__ */ new WeakMap();
3848
+ /**
3849
+ * Request IDs of recent logical runs, so an approval that resumes a paused
3850
+ * run sends the ID of the request that paused. Oldest entries go first.
3851
+ */
3852
+ _requestIdByRun = /* @__PURE__ */ new Map();
3853
+ /**
3839
3854
  * Keeps tools that opt in via `webmcp` registered on the page's WebMCP model
3840
3855
  * context (`document.modelContext`), in addition to the normal agent
3841
3856
  * registration. Reconciled on every tool registry mutation.
@@ -4166,6 +4181,8 @@ var RunHandler = class {
4166
4181
  const controller = followUpOf ?? new AbortController();
4167
4182
  const depth = this._runDepths.get(agent) ?? 0;
4168
4183
  this._runDepths.set(agent, depth + 1);
4184
+ const continuedRunId = resumedRunId ?? (continuationHandoff ? runId : void 0);
4185
+ const requestId = (continuationHandoff ? this._activeRequestIds.get(agent) : void 0) ?? (continuedRunId !== void 0 ? this._requestIdByRun.get(continuedRunId) : void 0) ?? (0, _copilotkit_shared.randomUUID)();
4169
4186
  if (!isFollowUp) {
4170
4187
  const controllers = this._runAbortControllers.get(agent) ?? /* @__PURE__ */ new Set();
4171
4188
  controllers.add(controller);
@@ -4179,6 +4196,8 @@ var RunHandler = class {
4179
4196
  originalAbortRun.call(agent);
4180
4197
  };
4181
4198
  }
4199
+ const previousRequestId = this._activeRequestIds.get(agent);
4200
+ this._activeRequestIds.set(agent, requestId);
4182
4201
  try {
4183
4202
  if (depth === 0) await this._internal.notifySubscribers((subscriber) => subscriber.onAgentRunStarted?.({
4184
4203
  copilotkit: this.core,
@@ -4203,7 +4222,8 @@ var RunHandler = class {
4203
4222
  const agentRunInput = {
4204
4223
  forwardedProps: {
4205
4224
  ...this._internal.getPropertiesForAgent(agent.agentId),
4206
- ...forwardedProps
4225
+ ...forwardedProps,
4226
+ __copilotkitRequestId: requestId
4207
4227
  },
4208
4228
  ...resume !== void 0 ? { resume } : {},
4209
4229
  ...pinRunIdOnWire ? { runId } : {},
@@ -4212,6 +4232,7 @@ var RunHandler = class {
4212
4232
  };
4213
4233
  const runAgentResult = await agent.runAgent(agentRunInput, agentSubscriber);
4214
4234
  if (!started) logicalHandoff?.cancel();
4235
+ if (logicalRunId !== void 0) this.rememberRequestId(logicalRunId, requestId);
4215
4236
  return await this.processAgentResult({
4216
4237
  runAgentResult,
4217
4238
  agent,
@@ -4247,6 +4268,16 @@ var RunHandler = class {
4247
4268
  this._originalAbortRuns.delete(agent);
4248
4269
  }
4249
4270
  }
4271
+ if (previousRequestId === void 0) this._activeRequestIds.delete(agent);
4272
+ else this._activeRequestIds.set(agent, previousRequestId);
4273
+ }
4274
+ }
4275
+ rememberRequestId(runId, requestId) {
4276
+ this._requestIdByRun.delete(runId);
4277
+ this._requestIdByRun.set(runId, requestId);
4278
+ if (this._requestIdByRun.size > MAX_REMEMBERED_REQUEST_IDS) {
4279
+ const oldest = this._requestIdByRun.keys().next().value;
4280
+ if (oldest !== void 0) this._requestIdByRun.delete(oldest);
4250
4281
  }
4251
4282
  }
4252
4283
  /**