@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.cjs CHANGED
@@ -602,6 +602,12 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui
602
602
  get capabilities() {
603
603
  return this._capabilities;
604
604
  }
605
+ requestInit(input) {
606
+ return {
607
+ ...super.requestInit(input),
608
+ ...this.credentials ? { credentials: this.credentials } : {}
609
+ };
610
+ }
605
611
  async getCapabilities() {
606
612
  return this._capabilities ?? {};
607
613
  }
@@ -1747,6 +1753,19 @@ const SUGGEST_TOOL = {
1747
1753
  //#endregion
1748
1754
  //#region src/core/run-handler.ts
1749
1755
  /**
1756
+ * Absolute safety cap on the depth of recursive follow-up runs triggered by
1757
+ * `processAgentResult`. Without this, any scenario that keeps
1758
+ * `needsFollowUp = true` (e.g. the LLM repeatedly calling the same tool, a
1759
+ * backend that errors after receiving tool results, or input processors that
1760
+ * reprocess tool messages) would loop indefinitely, silently consuming API
1761
+ * quota and potentially DOS'ing the backend.
1762
+ *
1763
+ * The cap is deliberately high so that legitimate multi-step agent workflows
1764
+ * (search → fill form → confirm → update → send email, etc.) are never
1765
+ * affected; it only trips on runaway recursion.
1766
+ */
1767
+ const MAX_FOLLOW_UP_DEPTH = 100;
1768
+ /**
1750
1769
  * Handles agent execution, tool calling, and agent connectivity for CopilotKitCore.
1751
1770
  * Manages the complete lifecycle of agent runs including tool execution and follow-ups.
1752
1771
  */
@@ -2001,7 +2020,8 @@ var RunHandler = class {
2001
2020
  }
2002
2021
  }
2003
2022
  }
2004
- if (needsFollowUp && !this._runAbortController?.signal.aborted) {
2023
+ if (needsFollowUp && !this._runAbortController?.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.`);
2024
+ else {
2005
2025
  await this._internal.waitForPendingFrameworkUpdates();
2006
2026
  return await this.runAgent({ agent });
2007
2027
  }
@@ -2324,6 +2344,7 @@ var RunHandler = class {
2324
2344
  await emitAgentError(error, error instanceof AgentThreadLockedError ? CopilotKitCoreErrorCode.AGENT_THREAD_LOCKED : CopilotKitCoreErrorCode.AGENT_RUN_FAILED_EVENT, { source: "onRunFailed" });
2325
2345
  },
2326
2346
  onRunErrorEvent: async ({ event }) => {
2347
+ if (this._runAbortController?.signal.aborted === true || event?.code === "abort") return;
2327
2348
  const eventError = event?.rawEvent instanceof Error ? event.rawEvent : event?.rawEvent?.error instanceof Error ? event.rawEvent.error : void 0;
2328
2349
  const errorMessage = typeof event?.rawEvent?.error === "string" ? event.rawEvent.error : event?.message ?? "Agent run error";
2329
2350
  const rawError = eventError ?? new Error(errorMessage);