@copilotkit/core 1.63.0 → 1.63.2

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
@@ -802,10 +802,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
802
802
  }
803
803
  }
804
804
  connect(input) {
805
+ 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
806
  if (this.runtimeMode === _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE) return _assertClassBrand(_ProxiedCopilotRuntimeAgent_brand, this, _connectViaDelegate).call(this, input);
806
807
  return _assertClassBrand(_ProxiedCopilotRuntimeAgent_brand, this, _connectViaHttp).call(this, input);
807
808
  }
808
809
  run(input) {
810
+ 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
811
  if (this.runtimeMode === _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE) return _assertClassBrand(_ProxiedCopilotRuntimeAgent_brand, this, _runViaDelegate).call(this, input);
810
812
  return _assertClassBrand(_ProxiedCopilotRuntimeAgent_brand, this, _runViaHttp).call(this, input);
811
813
  }
@@ -852,7 +854,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
852
854
  delegate === null || delegate === void 0 || (_delegate$clearReconn = delegate.clearReconnectCursor) === null || _delegate$clearReconn === void 0 || _delegate$clearReconn.call(delegate, threadId);
853
855
  }
854
856
  async resolveDelegate() {
855
- await this.ensureRuntimeMode();
857
+ await this.ensureRuntimeConfiguration();
856
858
  if (!this.delegate) {
857
859
  if (this.runtimeMode !== _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE) throw new Error("A delegate is only created for Intelligence mode");
858
860
  this.delegate = this.createIntelligenceDelegate();
@@ -860,16 +862,23 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
860
862
  this.syncDelegate(this.delegate);
861
863
  return this.delegate;
862
864
  }
863
- async ensureRuntimeMode() {
865
+ /** Resolve transport and runtime mode before the first outbound request. */
866
+ async ensureRuntimeConfiguration() {
864
867
  var _this$runtimeInfoProm;
865
- if (this.runtimeMode !== "pending") return;
868
+ if (this.runtimeMode === _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE || this.runtimeMode !== "pending" && this.transport !== "auto") return;
866
869
  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) => {
870
+ const runtimeInfoPromise = (_this$runtimeInfoProm = this.runtimeInfoPromise) !== null && _this$runtimeInfoProm !== void 0 ? _this$runtimeInfoProm : this.fetchRuntimeInfo().then((runtimeInfo) => {
868
871
  var _runtimeInfo$mode;
869
872
  this.runtimeMode = (_runtimeInfo$mode = runtimeInfo.mode) !== null && _runtimeInfo$mode !== void 0 ? _runtimeInfo$mode : _copilotkit_shared.RUNTIME_MODE_SSE;
870
873
  this.intelligence = runtimeInfo.intelligence;
871
- }));
872
- await this.runtimeInfoPromise;
874
+ });
875
+ this.runtimeInfoPromise = runtimeInfoPromise;
876
+ try {
877
+ await runtimeInfoPromise;
878
+ } catch (error) {
879
+ if (this.runtimeInfoPromise === runtimeInfoPromise) this.runtimeInfoPromise = void 0;
880
+ throw error;
881
+ }
873
882
  }
874
883
  async fetchRuntimeInfo() {
875
884
  const headers = { ...this.headers };
@@ -5416,6 +5425,138 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5416
5425
  return FEATURE_SET.has(name);
5417
5426
  }
5418
5427
 
5428
+ //#endregion
5429
+ //#region \0@oxc-project+runtime@0.112.0/helpers/classPrivateFieldInitSpec.js
5430
+ function _classPrivateFieldInitSpec(e, t, a) {
5431
+ _checkPrivateRedeclaration(e, t), t.set(e, a);
5432
+ }
5433
+
5434
+ //#endregion
5435
+ //#region \0@oxc-project+runtime@0.112.0/helpers/classPrivateFieldGet2.js
5436
+ function _classPrivateFieldGet2(s, a) {
5437
+ return s.get(_assertClassBrand(s, a));
5438
+ }
5439
+
5440
+ //#endregion
5441
+ //#region \0@oxc-project+runtime@0.112.0/helpers/classPrivateFieldSet2.js
5442
+ function _classPrivateFieldSet2(s, a, r) {
5443
+ return s.set(_assertClassBrand(s, a), r), r;
5444
+ }
5445
+
5446
+ //#endregion
5447
+ //#region src/interrupt-state.ts
5448
+ function toolResultContent(response) {
5449
+ var _response$payload;
5450
+ if (response.status === "cancelled") return JSON.stringify({ status: "cancelled" });
5451
+ return JSON.stringify((_response$payload = response.payload) !== null && _response$payload !== void 0 ? _response$payload : { status: "resolved" });
5452
+ }
5453
+ var _responses = /* @__PURE__ */ new WeakMap();
5454
+ var _pending = /* @__PURE__ */ new WeakMap();
5455
+ var _sealed = /* @__PURE__ */ new WeakMap();
5456
+ var _ɵInterruptState_brand = /* @__PURE__ */ new WeakSet();
5457
+ /**
5458
+ * @internal Framework-neutral interrupt response state shared by framework
5459
+ * adapters. Application authors must not depend on this API.
5460
+ */
5461
+ var ɵInterruptState = class {
5462
+ constructor() {
5463
+ _classPrivateMethodInitSpec(this, _ɵInterruptState_brand);
5464
+ _classPrivateFieldInitSpec(this, _responses, {});
5465
+ _classPrivateFieldInitSpec(this, _pending, null);
5466
+ _classPrivateFieldInitSpec(this, _sealed, false);
5467
+ }
5468
+ /** Return the active normalized interrupt without exposing mutable state. */
5469
+ get pending() {
5470
+ const pending = _classPrivateFieldGet2(_pending, this);
5471
+ if ((pending === null || pending === void 0 ? void 0 : pending.kind) === "standard") return {
5472
+ kind: "standard",
5473
+ interrupts: [...pending.interrupts]
5474
+ };
5475
+ return pending;
5476
+ }
5477
+ /** Replace the current interrupt with a legacy custom-event interrupt. */
5478
+ setLegacy(event) {
5479
+ _assertClassBrand(_ɵInterruptState_brand, this, _replace).call(this, {
5480
+ kind: "legacy",
5481
+ event
5482
+ });
5483
+ }
5484
+ /** Replace the current interrupt with an AG-UI standard interrupt set. */
5485
+ setStandard(interrupts) {
5486
+ _assertClassBrand(_ɵInterruptState_brand, this, _replace).call(this, {
5487
+ kind: "standard",
5488
+ interrupts: [...interrupts]
5489
+ });
5490
+ }
5491
+ /** Clear all pending interrupt data and accumulated responses. */
5492
+ clear() {
5493
+ _classPrivateFieldSet2(_pending, this, null);
5494
+ _classPrivateFieldSet2(_sealed, this, false);
5495
+ for (const id of Object.keys(_classPrivateFieldGet2(_responses, this))) delete _classPrivateFieldGet2(_responses, this)[id];
5496
+ }
5497
+ /** Record a resolved response and return the next framework action. */
5498
+ resolve(payload, interruptId) {
5499
+ const pending = _classPrivateFieldGet2(_pending, this);
5500
+ if (!pending || _classPrivateFieldGet2(_sealed, this)) return { kind: "ignored" };
5501
+ if (pending.kind === "legacy") {
5502
+ _classPrivateFieldSet2(_sealed, this, true);
5503
+ return {
5504
+ kind: "legacy-resume",
5505
+ payload,
5506
+ interruptValue: pending.event.value
5507
+ };
5508
+ }
5509
+ return _assertClassBrand(_ɵInterruptState_brand, this, _respond).call(this, pending.interrupts, interruptId, {
5510
+ status: "resolved",
5511
+ payload
5512
+ });
5513
+ }
5514
+ /** Record a cancelled response and return the next framework action. */
5515
+ cancel(interruptId) {
5516
+ const pending = _classPrivateFieldGet2(_pending, this);
5517
+ if (!pending || _classPrivateFieldGet2(_sealed, this)) return { kind: "ignored" };
5518
+ if (pending.kind === "legacy") {
5519
+ _classPrivateFieldSet2(_sealed, this, true);
5520
+ return { kind: "dismiss" };
5521
+ }
5522
+ return _assertClassBrand(_ɵInterruptState_brand, this, _respond).call(this, pending.interrupts, interruptId, { status: "cancelled" });
5523
+ }
5524
+ };
5525
+ function _replace(pending) {
5526
+ this.clear();
5527
+ _classPrivateFieldSet2(_pending, this, pending);
5528
+ }
5529
+ function _respond(interrupts, interruptId, response) {
5530
+ var _interrupts$;
5531
+ const id = interruptId !== null && interruptId !== void 0 ? interruptId : (_interrupts$ = interrupts[0]) === null || _interrupts$ === void 0 ? void 0 : _interrupts$.id;
5532
+ if (!id || !interrupts.some((interrupt) => interrupt.id === id)) return { kind: "ignored" };
5533
+ _classPrivateFieldGet2(_responses, this)[id] = response;
5534
+ if (!interrupts.every((interrupt) => _classPrivateFieldGet2(_responses, this)[interrupt.id])) return { kind: "waiting" };
5535
+ const expired = interrupts.find((interrupt) => (0, _ag_ui_client.isInterruptExpired)(interrupt));
5536
+ if (expired) {
5537
+ _classPrivateFieldSet2(_sealed, this, true);
5538
+ return {
5539
+ kind: "expired",
5540
+ interrupt: expired
5541
+ };
5542
+ }
5543
+ const mutableInterrupts = [...interrupts];
5544
+ const resume = (0, _ag_ui_client.buildResumeArray)(mutableInterrupts, _classPrivateFieldGet2(_responses, this));
5545
+ const toolResults = mutableInterrupts.flatMap((interrupt) => {
5546
+ if (!interrupt.toolCallId) return [];
5547
+ return [{
5548
+ toolCallId: interrupt.toolCallId,
5549
+ content: toolResultContent(_classPrivateFieldGet2(_responses, this)[interrupt.id])
5550
+ }];
5551
+ });
5552
+ _classPrivateFieldSet2(_sealed, this, true);
5553
+ return {
5554
+ kind: "resume",
5555
+ resume,
5556
+ toolResults
5557
+ };
5558
+ }
5559
+
5419
5560
  //#endregion
5420
5561
  exports.AgentRegistry = AgentRegistry;
5421
5562
  exports.AgentThreadLockedError = AgentThreadLockedError;
@@ -5447,6 +5588,7 @@ exports.parseToolArguments = parseToolArguments;
5447
5588
  exports.props = props;
5448
5589
  exports.select = select;
5449
5590
  exports.ɵCOPILOTKIT_FEATURES = ɵCOPILOTKIT_FEATURES;
5591
+ exports.ɵInterruptState = ɵInterruptState;
5450
5592
  exports.ɵMAX_SOCKET_RETRIES = ɵMAX_SOCKET_RETRIES;
5451
5593
  exports.ɵcreateMemoryStore = createMemoryStore;
5452
5594
  exports.ɵcreateThreadSelectors = ɵcreateThreadSelectors;