@copilotkit/core 1.63.2 → 1.63.3-canary.rc-1

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
@@ -708,6 +708,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
708
708
  get capabilities() {
709
709
  return this._capabilities;
710
710
  }
711
+ requestInit(input) {
712
+ return {
713
+ ...super.requestInit(input),
714
+ ...this.credentials ? { credentials: this.credentials } : {}
715
+ };
716
+ }
711
717
  async getCapabilities() {
712
718
  var _this$_capabilities;
713
719
  return (_this$_capabilities = this._capabilities) !== null && _this$_capabilities !== void 0 ? _this$_capabilities : {};
@@ -1885,6 +1891,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1885
1891
  //#endregion
1886
1892
  //#region src/core/run-handler.ts
1887
1893
  /**
1894
+ * Absolute safety cap on the depth of recursive follow-up runs triggered by
1895
+ * `processAgentResult`. Without this, any scenario that keeps
1896
+ * `needsFollowUp = true` (e.g. the LLM repeatedly calling the same tool, a
1897
+ * backend that errors after receiving tool results, or input processors that
1898
+ * reprocess tool messages) would loop indefinitely, silently consuming API
1899
+ * quota and potentially DOS'ing the backend.
1900
+ *
1901
+ * The cap is deliberately high so that legitimate multi-step agent workflows
1902
+ * (search → fill form → confirm → update → send email, etc.) are never
1903
+ * affected; it only trips on runaway recursion.
1904
+ */
1905
+ const MAX_FOLLOW_UP_DEPTH = 100;
1906
+ /**
1888
1907
  * Handles agent execution, tool calling, and agent connectivity for CopilotKitCore.
1889
1908
  * Manages the complete lifecycle of agent runs including tool execution and follow-ups.
1890
1909
  */
@@ -2121,7 +2140,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2121
2140
  }
2122
2141
  }
2123
2142
  }
2124
- if (needsFollowUp && !((_this$_runAbortContro2 = this._runAbortController) === null || _this$_runAbortContro2 === void 0 ? void 0 : _this$_runAbortContro2.signal.aborted)) {
2143
+ if (needsFollowUp && !((_this$_runAbortContro2 = this._runAbortController) === null || _this$_runAbortContro2 === void 0 ? void 0 : _this$_runAbortContro2.signal.aborted)) if (this._runDepth >= MAX_FOLLOW_UP_DEPTH) _copilotkit_shared.logger.warn(`[CopilotKit] Follow-up depth limit (${MAX_FOLLOW_UP_DEPTH}) reached for agent "${agentId}". Stopping recursive follow-up runs to prevent an infinite loop. This usually indicates a tool that keeps requesting a follow-up (e.g. the LLM repeatedly calling the same tool). Consider setting "followUp: false" on the offending tool.`);
2144
+ else {
2125
2145
  await this._internal.waitForPendingFrameworkUpdates();
2126
2146
  return await this.runAgent({ agent });
2127
2147
  }
@@ -2460,7 +2480,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2460
2480
  await emitAgentError(error, error instanceof AgentThreadLockedError ? CopilotKitCoreErrorCode.AGENT_THREAD_LOCKED : CopilotKitCoreErrorCode.AGENT_RUN_FAILED_EVENT, { source: "onRunFailed" });
2461
2481
  },
2462
2482
  onRunErrorEvent: async ({ event }) => {
2463
- var _event$rawEvent, _event$rawEvent2, _event$message;
2483
+ var _this$_runAbortContro4, _event$rawEvent, _event$rawEvent2, _event$message;
2484
+ if (((_this$_runAbortContro4 = this._runAbortController) === null || _this$_runAbortContro4 === void 0 ? void 0 : _this$_runAbortContro4.signal.aborted) === true || (event === null || event === void 0 ? void 0 : event.code) === "abort") return;
2464
2485
  const eventError = (event === null || event === void 0 ? void 0 : event.rawEvent) instanceof Error ? event.rawEvent : (event === null || event === void 0 || (_event$rawEvent = event.rawEvent) === null || _event$rawEvent === void 0 ? void 0 : _event$rawEvent.error) instanceof Error ? event.rawEvent.error : void 0;
2465
2486
  const errorMessage = typeof (event === null || event === void 0 || (_event$rawEvent2 = event.rawEvent) === null || _event$rawEvent2 === void 0 ? void 0 : _event$rawEvent2.error) === "string" ? event.rawEvent.error : (_event$message = event === null || event === void 0 ? void 0 : event.message) !== null && _event$message !== void 0 ? _event$message : "Agent run error";
2466
2487
  const rawError = eventError !== null && eventError !== void 0 ? eventError : new Error(errorMessage);