@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.cjs CHANGED
@@ -206,6 +206,7 @@ function ɵobservePhoenixSocketHealth$(socketSignals$, maxConsecutiveErrors) {
206
206
  const globalFetch = (...args) => fetch(...args);
207
207
  const CLIENT_AG_UI_EVENT = "ag_ui_event";
208
208
  const REPLAY_COMPLETE_EVENT = "replay_complete";
209
+ const REPLAY_FAILED_EVENT = "replay_failed";
209
210
  const STREAM_IDLE_EVENT = "stream_idle";
210
211
  const STOP_RUN_EVENT = "stop_run";
211
212
  const CONNECT_STREAM_IDLE_REPLAY_FALLBACK_MS = 100;
@@ -491,18 +492,25 @@ var IntelligenceAgent = class IntelligenceAgent extends _ag_ui_client.AbstractAg
491
492
  const threadEvents$ = this.observeThreadEvents$(input.threadId, channel$, options).pipe((0, rxjs_operators.tap)((payload) => {
492
493
  latestObservedReplayCursor = this.readEventId(payload) ?? latestObservedReplayCursor;
493
494
  }), (0, rxjs_operators.share)());
494
- const replayComplete$ = this.observeControlEvent$(input.threadId, channel$, REPLAY_COMPLETE_EVENT).pipe((0, rxjs_operators.shareReplay)({
495
+ const controlCursor = {
496
+ applied: null,
497
+ replayFailed: false
498
+ };
499
+ const replayFailed$ = channel$.pipe((0, rxjs_operators.switchMap)(({ channel }) => this.observeChannelEvent$(channel, REPLAY_FAILED_EVENT)), (0, rxjs_operators.tap)(() => {
500
+ controlCursor.replayFailed = true;
501
+ }));
502
+ const replayComplete$ = this.observeControlEvent$(input.threadId, channel$, REPLAY_COMPLETE_EVENT, controlCursor).pipe((0, rxjs_operators.shareReplay)({
495
503
  bufferSize: 1,
496
504
  refCount: true
497
505
  }));
498
- const streamIdle$ = this.observeControlEvent$(input.threadId, channel$, STREAM_IDLE_EVENT).pipe((0, rxjs_operators.shareReplay)({
506
+ const streamIdle$ = this.observeControlEvent$(input.threadId, channel$, STREAM_IDLE_EVENT, controlCursor).pipe((0, rxjs_operators.shareReplay)({
499
507
  bufferSize: 1,
500
508
  refCount: true
501
509
  }));
502
510
  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;
503
511
  const threadCompleted$ = threadEvents$.pipe((0, rxjs_operators.ignoreElements)(), (0, rxjs_operators.endWith)(null), (0, rxjs_operators.take)(1));
504
512
  const terminal$ = (0, rxjs.merge)(threadCompleted$, streamIdleCompletion$);
505
- 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)));
513
+ 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)));
506
514
  });
507
515
  }
508
516
  joinThreadChannel$(channel$) {
@@ -522,8 +530,8 @@ var IntelligenceAgent = class IntelligenceAgent extends _ag_ui_client.AbstractAg
522
530
  errorOnRunError: options.streamMode === "run"
523
531
  })), (0, rxjs.dematerialize)());
524
532
  }
525
- observeControlEvent$(threadId, channel$, eventName) {
526
- return channel$.pipe((0, rxjs_operators.switchMap)(({ channel }) => this.observeChannelEvent$(channel, eventName)), (0, rxjs_operators.tap)((payload) => this.updateLastSeenEventIdFromControl(threadId, payload)));
533
+ observeControlEvent$(threadId, channel$, eventName, controlCursor) {
534
+ return channel$.pipe((0, rxjs_operators.switchMap)(({ channel }) => this.observeChannelEvent$(channel, eventName)), (0, rxjs_operators.tap)((payload) => this.updateLastSeenEventIdFromControl(threadId, payload, controlCursor)));
527
535
  }
528
536
  observeChannelEvent$(channel, eventName) {
529
537
  return ɵobservePhoenixEvent$(channel, eventName);
@@ -572,9 +580,11 @@ var IntelligenceAgent = class IntelligenceAgent extends _ag_ui_client.AbstractAg
572
580
  if (!eventId) return;
573
581
  this.advanceLastSeenEventId(threadId, eventId);
574
582
  }
575
- updateLastSeenEventIdFromControl(threadId, payload) {
583
+ updateLastSeenEventIdFromControl(threadId, payload, controlCursor) {
576
584
  const eventId = this.readControlEventId(payload);
577
585
  if (!eventId) return;
586
+ if (eventId === controlCursor.applied && !controlCursor.replayFailed) return;
587
+ controlCursor.applied = eventId;
578
588
  this.advanceLastSeenEventId(threadId, eventId);
579
589
  }
580
590
  advanceLastSeenEventId(threadId, eventId) {