@copilotkit/core 1.81.0 → 1.83.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.umd.js CHANGED
@@ -1515,7 +1515,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1515
1515
  __copilotkitMcpResourceReadOnly: true
1516
1516
  }
1517
1517
  };
1518
- return this.runtimeMode === _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE ? this.clone().runAgent(resourceParameters) : this.runAgent(resourceParameters);
1518
+ if (this.runtimeMode !== _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE) return this.runAgent(resourceParameters);
1519
+ const resourceAgent = this.clone();
1520
+ resourceAgent.pendingInterrupts = [];
1521
+ return resourceAgent.runAgent(resourceParameters);
1519
1522
  }
1520
1523
  /**
1521
1524
  * Drop the delegate's cached `lastSeenEventId` for this thread so
@@ -3896,6 +3899,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3896
3899
  var _liveHITLStops$get;
3897
3900
  return !!(discardOnAbort && (signal === null || signal === void 0 ? void 0 : signal.aborted) && !(((_liveHITLStops$get = liveHITLStops.get(signal)) === null || _liveHITLStops$get === void 0 ? void 0 : _liveHITLStops$get()) && errorMessage));
3898
3901
  }
3902
+ /** How many recent runs keep their request ID for a later approval resume. */
3903
+ const MAX_REMEMBERED_REQUEST_IDS = 100;
3899
3904
  /**
3900
3905
  * Absolute safety cap on the depth of recursive follow-up runs triggered by
3901
3906
  * `processAgentResult`. Without this, any scenario that keeps
@@ -3932,6 +3937,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3932
3937
  _defineProperty(this, "_runAbortControllers", /* @__PURE__ */ new WeakMap());
3933
3938
  _defineProperty(this, "_runDepths", /* @__PURE__ */ new WeakMap());
3934
3939
  _defineProperty(this, "_originalAbortRuns", /* @__PURE__ */ new WeakMap());
3940
+ _defineProperty(this, "_activeRequestIds", /* @__PURE__ */ new WeakMap());
3941
+ _defineProperty(this, "_requestIdByRun", /* @__PURE__ */ new Map());
3935
3942
  _defineProperty(this, "_webmcpRegistry", new WebMCPRegistry());
3936
3943
  _defineProperty(this, "_lastConnectedThreadIdsByAgent", /* @__PURE__ */ new Map());
3937
3944
  _defineProperty(this, "_lastActiveThreadIdsByAgent", /* @__PURE__ */ new Map());
@@ -4219,7 +4226,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4219
4226
  * Run an agent
4220
4227
  */
4221
4228
  async runAgent({ agent, forwardedProps, resume, runId }, continuationHandoff, followUpOf) {
4222
- var _this$_runDepths$get;
4229
+ var _this$_runDepths$get, _ref2, _ref3;
4223
4230
  if (agent.agentId) this._internal.suggestionEngine.clearSuggestions(agent.agentId);
4224
4231
  try {
4225
4232
  const headersApplied = this._internal.prepareAgentHeadersForRun(agent);
@@ -4247,6 +4254,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4247
4254
  const controller = followUpOf !== null && followUpOf !== void 0 ? followUpOf : new AbortController();
4248
4255
  const depth = (_this$_runDepths$get = this._runDepths.get(agent)) !== null && _this$_runDepths$get !== void 0 ? _this$_runDepths$get : 0;
4249
4256
  this._runDepths.set(agent, depth + 1);
4257
+ const continuedRunId = resumedRunId !== null && resumedRunId !== void 0 ? resumedRunId : continuationHandoff ? runId : void 0;
4258
+ const requestId = (_ref2 = (_ref3 = continuationHandoff ? this._activeRequestIds.get(agent) : void 0) !== null && _ref3 !== void 0 ? _ref3 : continuedRunId !== void 0 ? this._requestIdByRun.get(continuedRunId) : void 0) !== null && _ref2 !== void 0 ? _ref2 : (0, _copilotkit_shared.randomUUID)();
4250
4259
  if (!isFollowUp) {
4251
4260
  var _this$_runAbortContro3;
4252
4261
  const controllers = (_this$_runAbortContro3 = this._runAbortControllers.get(agent)) !== null && _this$_runAbortContro3 !== void 0 ? _this$_runAbortContro3 : /* @__PURE__ */ new Set();
@@ -4261,6 +4270,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4261
4270
  originalAbortRun.call(agent);
4262
4271
  };
4263
4272
  }
4273
+ const previousRequestId = this._activeRequestIds.get(agent);
4274
+ this._activeRequestIds.set(agent, requestId);
4264
4275
  try {
4265
4276
  if (depth === 0) await this._internal.notifySubscribers((subscriber) => {
4266
4277
  var _subscriber$onAgentRu2;
@@ -4288,7 +4299,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4288
4299
  const agentRunInput = {
4289
4300
  forwardedProps: {
4290
4301
  ...this._internal.getPropertiesForAgent(agent.agentId),
4291
- ...forwardedProps
4302
+ ...forwardedProps,
4303
+ __copilotkitRequestId: requestId
4292
4304
  },
4293
4305
  ...resume !== void 0 ? { resume } : {},
4294
4306
  ...pinRunIdOnWire ? { runId } : {},
@@ -4297,6 +4309,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4297
4309
  };
4298
4310
  const runAgentResult = await agent.runAgent(agentRunInput, agentSubscriber);
4299
4311
  if (!started) logicalHandoff === null || logicalHandoff === void 0 || logicalHandoff.cancel();
4312
+ if (logicalRunId !== void 0) this.rememberRequestId(logicalRunId, requestId);
4300
4313
  return await this.processAgentResult({
4301
4314
  runAgentResult,
4302
4315
  agent,
@@ -4333,6 +4346,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4333
4346
  this._originalAbortRuns.delete(agent);
4334
4347
  }
4335
4348
  }
4349
+ if (previousRequestId === void 0) this._activeRequestIds.delete(agent);
4350
+ else this._activeRequestIds.set(agent, previousRequestId);
4351
+ }
4352
+ }
4353
+ rememberRequestId(runId, requestId) {
4354
+ this._requestIdByRun.delete(runId);
4355
+ this._requestIdByRun.set(runId, requestId);
4356
+ if (this._requestIdByRun.size > MAX_REMEMBERED_REQUEST_IDS) {
4357
+ const oldest = this._requestIdByRun.keys().next().value;
4358
+ if (oldest !== void 0) this._requestIdByRun.delete(oldest);
4336
4359
  }
4337
4360
  }
4338
4361
  /**