@copilotkit/core 1.63.0 → 1.63.2-canary.1784918757

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 : {};
@@ -802,10 +808,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
802
808
  }
803
809
  }
804
810
  connect(input) {
811
+ if (this.runtimeMode === "pending" || this.transport === "auto" && this.runtimeMode !== _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE) return (0, rxjs.defer)(() => (0, rxjs.from)(this.ensureRuntimeConfiguration())).pipe((0, rxjs_operators.switchMap)(() => this.connect(input)));
805
812
  if (this.runtimeMode === _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE) return _assertClassBrand(_ProxiedCopilotRuntimeAgent_brand, this, _connectViaDelegate).call(this, input);
806
813
  return _assertClassBrand(_ProxiedCopilotRuntimeAgent_brand, this, _connectViaHttp).call(this, input);
807
814
  }
808
815
  run(input) {
816
+ if (this.runtimeMode === "pending" || this.transport === "auto" && this.runtimeMode !== _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE) return (0, rxjs.defer)(() => (0, rxjs.from)(this.ensureRuntimeConfiguration())).pipe((0, rxjs_operators.switchMap)(() => this.run(input)));
809
817
  if (this.runtimeMode === _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE) return _assertClassBrand(_ProxiedCopilotRuntimeAgent_brand, this, _runViaDelegate).call(this, input);
810
818
  return _assertClassBrand(_ProxiedCopilotRuntimeAgent_brand, this, _runViaHttp).call(this, input);
811
819
  }
@@ -852,7 +860,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
852
860
  delegate === null || delegate === void 0 || (_delegate$clearReconn = delegate.clearReconnectCursor) === null || _delegate$clearReconn === void 0 || _delegate$clearReconn.call(delegate, threadId);
853
861
  }
854
862
  async resolveDelegate() {
855
- await this.ensureRuntimeMode();
863
+ await this.ensureRuntimeConfiguration();
856
864
  if (!this.delegate) {
857
865
  if (this.runtimeMode !== _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE) throw new Error("A delegate is only created for Intelligence mode");
858
866
  this.delegate = this.createIntelligenceDelegate();
@@ -860,16 +868,23 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
860
868
  this.syncDelegate(this.delegate);
861
869
  return this.delegate;
862
870
  }
863
- async ensureRuntimeMode() {
871
+ /** Resolve transport and runtime mode before the first outbound request. */
872
+ async ensureRuntimeConfiguration() {
864
873
  var _this$runtimeInfoProm;
865
- if (this.runtimeMode !== "pending") return;
874
+ if (this.runtimeMode === _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE || this.runtimeMode !== "pending" && this.transport !== "auto") return;
866
875
  if (!this.runtimeUrl) throw new Error("Runtime URL is not set");
867
- (_this$runtimeInfoProm = this.runtimeInfoPromise) !== null && _this$runtimeInfoProm !== void 0 || (this.runtimeInfoPromise = this.fetchRuntimeInfo().then((runtimeInfo) => {
876
+ const runtimeInfoPromise = (_this$runtimeInfoProm = this.runtimeInfoPromise) !== null && _this$runtimeInfoProm !== void 0 ? _this$runtimeInfoProm : this.fetchRuntimeInfo().then((runtimeInfo) => {
868
877
  var _runtimeInfo$mode;
869
878
  this.runtimeMode = (_runtimeInfo$mode = runtimeInfo.mode) !== null && _runtimeInfo$mode !== void 0 ? _runtimeInfo$mode : _copilotkit_shared.RUNTIME_MODE_SSE;
870
879
  this.intelligence = runtimeInfo.intelligence;
871
- }));
872
- await this.runtimeInfoPromise;
880
+ });
881
+ this.runtimeInfoPromise = runtimeInfoPromise;
882
+ try {
883
+ await runtimeInfoPromise;
884
+ } catch (error) {
885
+ if (this.runtimeInfoPromise === runtimeInfoPromise) this.runtimeInfoPromise = void 0;
886
+ throw error;
887
+ }
873
888
  }
874
889
  async fetchRuntimeInfo() {
875
890
  const headers = { ...this.headers };
@@ -1876,6 +1891,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1876
1891
  //#endregion
1877
1892
  //#region src/core/run-handler.ts
1878
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
+ /**
1879
1907
  * Handles agent execution, tool calling, and agent connectivity for CopilotKitCore.
1880
1908
  * Manages the complete lifecycle of agent runs including tool execution and follow-ups.
1881
1909
  */
@@ -2112,7 +2140,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2112
2140
  }
2113
2141
  }
2114
2142
  }
2115
- 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 {
2116
2145
  await this._internal.waitForPendingFrameworkUpdates();
2117
2146
  return await this.runAgent({ agent });
2118
2147
  }
@@ -2451,7 +2480,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2451
2480
  await emitAgentError(error, error instanceof AgentThreadLockedError ? CopilotKitCoreErrorCode.AGENT_THREAD_LOCKED : CopilotKitCoreErrorCode.AGENT_RUN_FAILED_EVENT, { source: "onRunFailed" });
2452
2481
  },
2453
2482
  onRunErrorEvent: async ({ event }) => {
2454
- 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;
2455
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;
2456
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";
2457
2487
  const rawError = eventError !== null && eventError !== void 0 ? eventError : new Error(errorMessage);
@@ -5416,6 +5446,138 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5416
5446
  return FEATURE_SET.has(name);
5417
5447
  }
5418
5448
 
5449
+ //#endregion
5450
+ //#region \0@oxc-project+runtime@0.112.0/helpers/classPrivateFieldInitSpec.js
5451
+ function _classPrivateFieldInitSpec(e, t, a) {
5452
+ _checkPrivateRedeclaration(e, t), t.set(e, a);
5453
+ }
5454
+
5455
+ //#endregion
5456
+ //#region \0@oxc-project+runtime@0.112.0/helpers/classPrivateFieldGet2.js
5457
+ function _classPrivateFieldGet2(s, a) {
5458
+ return s.get(_assertClassBrand(s, a));
5459
+ }
5460
+
5461
+ //#endregion
5462
+ //#region \0@oxc-project+runtime@0.112.0/helpers/classPrivateFieldSet2.js
5463
+ function _classPrivateFieldSet2(s, a, r) {
5464
+ return s.set(_assertClassBrand(s, a), r), r;
5465
+ }
5466
+
5467
+ //#endregion
5468
+ //#region src/interrupt-state.ts
5469
+ function toolResultContent(response) {
5470
+ var _response$payload;
5471
+ if (response.status === "cancelled") return JSON.stringify({ status: "cancelled" });
5472
+ return JSON.stringify((_response$payload = response.payload) !== null && _response$payload !== void 0 ? _response$payload : { status: "resolved" });
5473
+ }
5474
+ var _responses = /* @__PURE__ */ new WeakMap();
5475
+ var _pending = /* @__PURE__ */ new WeakMap();
5476
+ var _sealed = /* @__PURE__ */ new WeakMap();
5477
+ var _ɵInterruptState_brand = /* @__PURE__ */ new WeakSet();
5478
+ /**
5479
+ * @internal Framework-neutral interrupt response state shared by framework
5480
+ * adapters. Application authors must not depend on this API.
5481
+ */
5482
+ var ɵInterruptState = class {
5483
+ constructor() {
5484
+ _classPrivateMethodInitSpec(this, _ɵInterruptState_brand);
5485
+ _classPrivateFieldInitSpec(this, _responses, {});
5486
+ _classPrivateFieldInitSpec(this, _pending, null);
5487
+ _classPrivateFieldInitSpec(this, _sealed, false);
5488
+ }
5489
+ /** Return the active normalized interrupt without exposing mutable state. */
5490
+ get pending() {
5491
+ const pending = _classPrivateFieldGet2(_pending, this);
5492
+ if ((pending === null || pending === void 0 ? void 0 : pending.kind) === "standard") return {
5493
+ kind: "standard",
5494
+ interrupts: [...pending.interrupts]
5495
+ };
5496
+ return pending;
5497
+ }
5498
+ /** Replace the current interrupt with a legacy custom-event interrupt. */
5499
+ setLegacy(event) {
5500
+ _assertClassBrand(_ɵInterruptState_brand, this, _replace).call(this, {
5501
+ kind: "legacy",
5502
+ event
5503
+ });
5504
+ }
5505
+ /** Replace the current interrupt with an AG-UI standard interrupt set. */
5506
+ setStandard(interrupts) {
5507
+ _assertClassBrand(_ɵInterruptState_brand, this, _replace).call(this, {
5508
+ kind: "standard",
5509
+ interrupts: [...interrupts]
5510
+ });
5511
+ }
5512
+ /** Clear all pending interrupt data and accumulated responses. */
5513
+ clear() {
5514
+ _classPrivateFieldSet2(_pending, this, null);
5515
+ _classPrivateFieldSet2(_sealed, this, false);
5516
+ for (const id of Object.keys(_classPrivateFieldGet2(_responses, this))) delete _classPrivateFieldGet2(_responses, this)[id];
5517
+ }
5518
+ /** Record a resolved response and return the next framework action. */
5519
+ resolve(payload, interruptId) {
5520
+ const pending = _classPrivateFieldGet2(_pending, this);
5521
+ if (!pending || _classPrivateFieldGet2(_sealed, this)) return { kind: "ignored" };
5522
+ if (pending.kind === "legacy") {
5523
+ _classPrivateFieldSet2(_sealed, this, true);
5524
+ return {
5525
+ kind: "legacy-resume",
5526
+ payload,
5527
+ interruptValue: pending.event.value
5528
+ };
5529
+ }
5530
+ return _assertClassBrand(_ɵInterruptState_brand, this, _respond).call(this, pending.interrupts, interruptId, {
5531
+ status: "resolved",
5532
+ payload
5533
+ });
5534
+ }
5535
+ /** Record a cancelled response and return the next framework action. */
5536
+ cancel(interruptId) {
5537
+ const pending = _classPrivateFieldGet2(_pending, this);
5538
+ if (!pending || _classPrivateFieldGet2(_sealed, this)) return { kind: "ignored" };
5539
+ if (pending.kind === "legacy") {
5540
+ _classPrivateFieldSet2(_sealed, this, true);
5541
+ return { kind: "dismiss" };
5542
+ }
5543
+ return _assertClassBrand(_ɵInterruptState_brand, this, _respond).call(this, pending.interrupts, interruptId, { status: "cancelled" });
5544
+ }
5545
+ };
5546
+ function _replace(pending) {
5547
+ this.clear();
5548
+ _classPrivateFieldSet2(_pending, this, pending);
5549
+ }
5550
+ function _respond(interrupts, interruptId, response) {
5551
+ var _interrupts$;
5552
+ const id = interruptId !== null && interruptId !== void 0 ? interruptId : (_interrupts$ = interrupts[0]) === null || _interrupts$ === void 0 ? void 0 : _interrupts$.id;
5553
+ if (!id || !interrupts.some((interrupt) => interrupt.id === id)) return { kind: "ignored" };
5554
+ _classPrivateFieldGet2(_responses, this)[id] = response;
5555
+ if (!interrupts.every((interrupt) => _classPrivateFieldGet2(_responses, this)[interrupt.id])) return { kind: "waiting" };
5556
+ const expired = interrupts.find((interrupt) => (0, _ag_ui_client.isInterruptExpired)(interrupt));
5557
+ if (expired) {
5558
+ _classPrivateFieldSet2(_sealed, this, true);
5559
+ return {
5560
+ kind: "expired",
5561
+ interrupt: expired
5562
+ };
5563
+ }
5564
+ const mutableInterrupts = [...interrupts];
5565
+ const resume = (0, _ag_ui_client.buildResumeArray)(mutableInterrupts, _classPrivateFieldGet2(_responses, this));
5566
+ const toolResults = mutableInterrupts.flatMap((interrupt) => {
5567
+ if (!interrupt.toolCallId) return [];
5568
+ return [{
5569
+ toolCallId: interrupt.toolCallId,
5570
+ content: toolResultContent(_classPrivateFieldGet2(_responses, this)[interrupt.id])
5571
+ }];
5572
+ });
5573
+ _classPrivateFieldSet2(_sealed, this, true);
5574
+ return {
5575
+ kind: "resume",
5576
+ resume,
5577
+ toolResults
5578
+ };
5579
+ }
5580
+
5419
5581
  //#endregion
5420
5582
  exports.AgentRegistry = AgentRegistry;
5421
5583
  exports.AgentThreadLockedError = AgentThreadLockedError;
@@ -5447,6 +5609,7 @@ exports.parseToolArguments = parseToolArguments;
5447
5609
  exports.props = props;
5448
5610
  exports.select = select;
5449
5611
  exports.ɵCOPILOTKIT_FEATURES = ɵCOPILOTKIT_FEATURES;
5612
+ exports.ɵInterruptState = ɵInterruptState;
5450
5613
  exports.ɵMAX_SOCKET_RETRIES = ɵMAX_SOCKET_RETRIES;
5451
5614
  exports.ɵcreateMemoryStore = createMemoryStore;
5452
5615
  exports.ɵcreateThreadSelectors = ɵcreateThreadSelectors;