@copilotkit/core 1.74.0 → 1.75.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
@@ -247,6 +247,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
247
247
  const globalFetch = (...args) => fetch(...args);
248
248
  const CLIENT_AG_UI_EVENT = "ag_ui_event";
249
249
  const REPLAY_COMPLETE_EVENT = "replay_complete";
250
+ const REPLAY_FAILED_EVENT = "replay_failed";
250
251
  const STREAM_IDLE_EVENT = "stream_idle";
251
252
  const STOP_RUN_EVENT = "stop_run";
252
253
  const CONNECT_STREAM_IDLE_REPLAY_FALLBACK_MS = 100;
@@ -535,18 +536,25 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
535
536
  var _this$readEventId;
536
537
  latestObservedReplayCursor = (_this$readEventId = this.readEventId(payload)) !== null && _this$readEventId !== void 0 ? _this$readEventId : latestObservedReplayCursor;
537
538
  }), (0, rxjs_operators.share)());
538
- const replayComplete$ = this.observeControlEvent$(input.threadId, channel$, REPLAY_COMPLETE_EVENT).pipe((0, rxjs_operators.shareReplay)({
539
+ const controlCursor = {
540
+ applied: null,
541
+ replayFailed: false
542
+ };
543
+ const replayFailed$ = channel$.pipe((0, rxjs_operators.switchMap)(({ channel }) => this.observeChannelEvent$(channel, REPLAY_FAILED_EVENT)), (0, rxjs_operators.tap)(() => {
544
+ controlCursor.replayFailed = true;
545
+ }));
546
+ const replayComplete$ = this.observeControlEvent$(input.threadId, channel$, REPLAY_COMPLETE_EVENT, controlCursor).pipe((0, rxjs_operators.shareReplay)({
539
547
  bufferSize: 1,
540
548
  refCount: true
541
549
  }));
542
- const streamIdle$ = this.observeControlEvent$(input.threadId, channel$, STREAM_IDLE_EVENT).pipe((0, rxjs_operators.shareReplay)({
550
+ const streamIdle$ = this.observeControlEvent$(input.threadId, channel$, STREAM_IDLE_EVENT, controlCursor).pipe((0, rxjs_operators.shareReplay)({
543
551
  bufferSize: 1,
544
552
  refCount: true
545
553
  }));
546
554
  const streamIdleCompletion$ = options.streamMode === "connect" ? (0, rxjs.merge)((0, rxjs.combineLatest)([replayComplete$.pipe((0, rxjs_operators.take)(1)), streamIdle$.pipe((0, rxjs_operators.take)(1))]), streamIdle$.pipe((0, rxjs_operators.take)(1), (0, rxjs_operators.filter)((payload) => this.canFallbackCompleteConnect(payload, reconnectCursor, latestObservedReplayCursor)), (0, rxjs_operators.delay)(CONNECT_STREAM_IDLE_REPLAY_FALLBACK_MS))).pipe((0, rxjs_operators.take)(1)) : rxjs.EMPTY;
547
555
  const threadCompleted$ = threadEvents$.pipe((0, rxjs_operators.ignoreElements)(), (0, rxjs_operators.endWith)(null), (0, rxjs_operators.take)(1));
548
556
  const terminal$ = (0, rxjs.merge)(threadCompleted$, streamIdleCompletion$);
549
- return (0, rxjs.merge)(this.joinThreadChannel$(channel$), this.observeSocketHealth$(socket$, options.onSocketOpen).pipe((0, rxjs_operators.takeUntil)(terminal$)), threadEvents$.pipe((0, rxjs_operators.takeUntil)(streamIdleCompletion$)), replayComplete$.pipe((0, rxjs_operators.ignoreElements)(), (0, rxjs_operators.takeUntil)(terminal$)), streamIdleCompletion$.pipe((0, rxjs_operators.ignoreElements)(), (0, rxjs_operators.takeUntil)(threadCompleted$))).pipe((0, rxjs_operators.finalize)(() => this.cleanupOwned(ownChannel, ownSocket)));
557
+ return (0, rxjs.merge)(this.joinThreadChannel$(channel$), this.observeSocketHealth$(socket$, options.onSocketOpen).pipe((0, rxjs_operators.takeUntil)(terminal$)), threadEvents$.pipe((0, rxjs_operators.takeUntil)(streamIdleCompletion$)), replayFailed$.pipe((0, rxjs_operators.ignoreElements)(), (0, rxjs_operators.takeUntil)(terminal$)), replayComplete$.pipe((0, rxjs_operators.ignoreElements)(), (0, rxjs_operators.takeUntil)(terminal$)), streamIdleCompletion$.pipe((0, rxjs_operators.ignoreElements)(), (0, rxjs_operators.takeUntil)(threadCompleted$))).pipe((0, rxjs_operators.finalize)(() => this.cleanupOwned(ownChannel, ownSocket)));
550
558
  });
551
559
  }
552
560
  joinThreadChannel$(channel$) {
@@ -566,8 +574,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
566
574
  errorOnRunError: options.streamMode === "run"
567
575
  })), (0, rxjs.dematerialize)());
568
576
  }
569
- observeControlEvent$(threadId, channel$, eventName) {
570
- return channel$.pipe((0, rxjs_operators.switchMap)(({ channel }) => this.observeChannelEvent$(channel, eventName)), (0, rxjs_operators.tap)((payload) => this.updateLastSeenEventIdFromControl(threadId, payload)));
577
+ observeControlEvent$(threadId, channel$, eventName, controlCursor) {
578
+ return channel$.pipe((0, rxjs_operators.switchMap)(({ channel }) => this.observeChannelEvent$(channel, eventName)), (0, rxjs_operators.tap)((payload) => this.updateLastSeenEventIdFromControl(threadId, payload, controlCursor)));
571
579
  }
572
580
  observeChannelEvent$(channel, eventName) {
573
581
  return ɵobservePhoenixEvent$(channel, eventName);
@@ -618,9 +626,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
618
626
  if (!eventId) return;
619
627
  this.advanceLastSeenEventId(threadId, eventId);
620
628
  }
621
- updateLastSeenEventIdFromControl(threadId, payload) {
629
+ updateLastSeenEventIdFromControl(threadId, payload, controlCursor) {
622
630
  const eventId = this.readControlEventId(payload);
623
631
  if (!eventId) return;
632
+ if (eventId === controlCursor.applied && !controlCursor.replayFailed) return;
633
+ controlCursor.applied = eventId;
624
634
  this.advanceLastSeenEventId(threadId, eventId);
625
635
  }
626
636
  advanceLastSeenEventId(threadId, eventId) {