@checksum-ai/runtime 1.1.32 → 1.1.34

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/checksumlib.js CHANGED
@@ -9714,9 +9714,6 @@
9714
9714
  this.restoreNodeAttributes(node2, removedAttributes);
9715
9715
  const result2 = await this.getElementWindowPlaywright(node2).$(selector);
9716
9716
  if (result2 !== node2) {
9717
- console.log(
9718
- `Selector ${selector} is not valid, trying to generate new one`
9719
- );
9720
9717
  ({ selector, locator } = await this.safeGetSelectorAndLocator(
9721
9718
  nodeHTML
9722
9719
  ));
@@ -29390,8 +29387,9 @@
29390
29387
  var SessionReplayer = class {
29391
29388
  constructor(config = {}) {
29392
29389
  this.events = [];
29393
- this.castedEvents = [];
29390
+ this.numberOfCastedEvents = 0;
29394
29391
  this.isLive = true;
29392
+ this.liveEvents = [];
29395
29393
  // private currentTraveledTimestamp: number = undefined;
29396
29394
  this.currentTraveledNumberOfEvents = void 0;
29397
29395
  this.config = {
@@ -29420,8 +29418,8 @@
29420
29418
  this.events = [...this.events, ...sortedNewEvents];
29421
29419
  const promise = new Promise((resolve2) => {
29422
29420
  this.onEventCast = (event) => {
29423
- this.castedEvents.push(event);
29424
- if (this.castedEvents.length === this.events.length) {
29421
+ this.numberOfCastedEvents++;
29422
+ if (this.numberOfCastedEvents === this.events.length) {
29425
29423
  this.onEventCast = void 0;
29426
29424
  resolve2();
29427
29425
  }
@@ -29438,6 +29436,20 @@
29438
29436
  this.getOriginalTimestamp = /* @__PURE__ */ __name((event) => {
29439
29437
  return event.originalTimestamp ?? event.timestamp;
29440
29438
  }, "getOriginalTimestamp");
29439
+ this.trimEventsToLastCheckout = /* @__PURE__ */ __name((events) => {
29440
+ const lastCheckoutEventIndex = events.reduce(
29441
+ (lastCheckoutEventIndex2, event, index2) => {
29442
+ return event.isCheckout && event.type === EventType.Meta ? index2 : lastCheckoutEventIndex2;
29443
+ },
29444
+ void 0
29445
+ );
29446
+ let trimmedEvents = events;
29447
+ if (lastCheckoutEventIndex !== void 0) {
29448
+ trimmedEvents = events.slice(lastCheckoutEventIndex);
29449
+ }
29450
+ const castedEvents = lastCheckoutEventIndex !== void 0 ? this.liveEvents.slice(0, lastCheckoutEventIndex) : [];
29451
+ return { trimmedEvents, castedEvents, lastCheckoutEventIndex };
29452
+ }, "trimEventsToLastCheckout");
29441
29453
  this.getNodeById = /* @__PURE__ */ __name((id) => {
29442
29454
  return this.replayer.getMirror().getNode(id);
29443
29455
  }, "getNodeById");
@@ -29445,36 +29457,49 @@
29445
29457
  return this.replayer.getMirror().getMeta(node2);
29446
29458
  }, "getMeta");
29447
29459
  this.config = { ...this.config, ...config };
29460
+ this.goBackWithEvents = this.goBackWithEvents_native;
29448
29461
  }
29449
29462
  static {
29450
29463
  __name(this, "SessionReplayer");
29451
29464
  }
29452
- start(options) {
29453
- this.startOptions = options;
29454
- const {
29455
- firstEventTimestamp,
29456
- speed = 8,
29457
- useTimestampCompression = true
29458
- } = options;
29465
+ makeReplayerConfig(live, { speed = 8 } = {}) {
29459
29466
  const playerConfig = {
29460
29467
  mouseTail: false,
29461
29468
  pauseAnimation: false,
29462
29469
  speed,
29463
29470
  triggerFocus: true,
29464
29471
  UNSAFE_replayCanvas: true,
29465
- liveMode: true,
29472
+ liveMode: live,
29466
29473
  showDebug: false,
29467
- skipInactive: true
29474
+ skipInactive: true,
29475
+ inactivePeriodThreshold: 100
29468
29476
  };
29469
29477
  if (this.config.root) {
29470
29478
  playerConfig.root = this.config.root;
29471
29479
  }
29472
- this.replayer = new Replayer([], playerConfig);
29480
+ return playerConfig;
29481
+ }
29482
+ makeReplayer(events, live, { speed = 8 } = {}) {
29483
+ this.replayer = new Replayer(
29484
+ events,
29485
+ this.makeReplayerConfig(live, { speed })
29486
+ );
29473
29487
  if (this.config.enableInteract) {
29474
29488
  this.replayer.enableInteract();
29475
29489
  } else {
29476
29490
  this.replayer.disableInteract();
29477
29491
  }
29492
+ }
29493
+ start(options, castedEvents = []) {
29494
+ this.startOptions = options;
29495
+ const {
29496
+ firstEventTimestamp,
29497
+ speed = 8,
29498
+ useTimestampCompression = true
29499
+ } = options;
29500
+ this.events = castedEvents;
29501
+ this.numberOfCastedEvents = castedEvents.length;
29502
+ this.makeReplayer([], true, { speed });
29478
29503
  this.useTimestampCompression = useTimestampCompression;
29479
29504
  this.replayer.startLive(
29480
29505
  this.useTimestampCompression ? Date.now() : firstEventTimestamp
@@ -29485,20 +29510,23 @@
29485
29510
  }
29486
29511
  });
29487
29512
  }
29488
- getCurrentReplayPoint() {
29489
- return this.isLive ? this.events.length : this.currentTraveledNumberOfEvents;
29490
- }
29491
- // private beforeGoBack() {
29492
- // if (this.isLive) {
29493
- // this.liveEvents = this.events;
29494
- // }
29495
- // this.stop();
29496
- // this.events = [];
29497
- // this.castedEvents = [];
29498
- // this.start(this.startOptions);
29499
- // this.isLive = false;
29500
- // }
29501
- async goBackWithEvents(getEvents2, { sleepAfter = 1e3 }) {
29513
+ async goLive(sleepAfter = 1e3) {
29514
+ if (this.isLive) {
29515
+ return;
29516
+ }
29517
+ this.stop();
29518
+ this.currentTraveledNumberOfEvents = void 0;
29519
+ const { trimmedEvents, castedEvents } = this.trimEventsToLastCheckout(
29520
+ this.liveEvents
29521
+ );
29522
+ this.start(this.startOptions, castedEvents);
29523
+ this.isLive = true;
29524
+ await this.fastForward(trimmedEvents);
29525
+ if (sleepAfter) {
29526
+ await (0, import_await_sleep3.default)(sleepAfter);
29527
+ }
29528
+ }
29529
+ async goBackWithEvents_native(getEvents2, { sleepAfter = 1e3 }) {
29502
29530
  if (this.isLive) {
29503
29531
  this.liveEvents = this.events;
29504
29532
  }
@@ -29506,38 +29534,65 @@
29506
29534
  if (events.length === this.currentTraveledNumberOfEvents) {
29507
29535
  return;
29508
29536
  }
29509
- const lastCheckoutEventIndex = events.reduce(
29510
- (lastCheckoutEventIndex2, event, index2) => {
29511
- return event.isCheckout && event.type === EventType.Meta ? index2 : lastCheckoutEventIndex2;
29512
- },
29513
- void 0
29514
- );
29515
- if (lastCheckoutEventIndex !== void 0) {
29516
- console.log(
29517
- "lastCheckoutEventIndex:",
29518
- lastCheckoutEventIndex,
29519
- "number of events to render:",
29520
- events.length - lastCheckoutEventIndex
29521
- );
29522
- events.splice(lastCheckoutEventIndex);
29523
- }
29524
29537
  this.stop();
29525
29538
  this.events = [];
29526
- this.castedEvents = [];
29527
- this.start(this.startOptions);
29539
+ this.numberOfCastedEvents = 0;
29528
29540
  this.isLive = false;
29529
29541
  this.currentTraveledNumberOfEvents = events.length;
29530
- await this.fastForward(events, true);
29542
+ const { trimmedEvents } = this.trimEventsToLastCheckout(events);
29543
+ this.makeReplayer(trimmedEvents, false, { speed: 360 });
29544
+ this.replayer.play(trimmedEvents[trimmedEvents.length - 1].timestamp);
29531
29545
  if (sleepAfter) {
29532
29546
  await (0, import_await_sleep3.default)(sleepAfter);
29533
29547
  }
29534
29548
  }
29535
- async goBackToReplayPoint(replayPoint, {
29536
- sleepAfter = 1e3
29537
- } = {}) {
29538
- return this.goBackWithEvents(() => this.liveEvents.slice(0, replayPoint), {
29539
- sleepAfter
29540
- });
29549
+ async goBackWithEvents_native2(getEvents2, { sleepAfter = 1e3 }) {
29550
+ try {
29551
+ const events = getEvents2();
29552
+ const targetTimestamp = events[events.length - 1]?.timestamp ?? 0;
29553
+ const getTimeForPause = /* @__PURE__ */ __name(() => {
29554
+ return targetTimestamp - (this.events[0].timestamp ?? 0);
29555
+ }, "getTimeForPause");
29556
+ if (!this.isLive && targetTimestamp <= this.events[this.events.length - 1].timestamp) {
29557
+ const timeForPause2 = getTimeForPause();
29558
+ this.replayer.pause(timeForPause2);
29559
+ return;
29560
+ }
29561
+ if (this.isLive) {
29562
+ this.liveEvents = this.events;
29563
+ }
29564
+ this.stop();
29565
+ this.events = this.liveEvents;
29566
+ this.numberOfCastedEvents = this.liveEvents.length;
29567
+ this.isLive = false;
29568
+ this.makeReplayer(this.events, false, { speed: 360 });
29569
+ const timeForPause = getTimeForPause();
29570
+ this.replayer.pause(timeForPause);
29571
+ } finally {
29572
+ if (sleepAfter) {
29573
+ await (0, import_await_sleep3.default)(sleepAfter);
29574
+ }
29575
+ }
29576
+ }
29577
+ async goBackWithEvents_FFwd(getEvents2, { sleepAfter = 1e3 }) {
29578
+ if (this.isLive) {
29579
+ this.liveEvents = this.events;
29580
+ }
29581
+ const events = getEvents2();
29582
+ if (events.length === this.currentTraveledNumberOfEvents) {
29583
+ return;
29584
+ }
29585
+ this.currentTraveledNumberOfEvents = events.length;
29586
+ this.stop();
29587
+ const { trimmedEvents, castedEvents } = this.trimEventsToLastCheckout(
29588
+ this.liveEvents
29589
+ );
29590
+ this.start(this.startOptions, castedEvents);
29591
+ this.isLive = false;
29592
+ await this.fastForward(trimmedEvents, true);
29593
+ if (sleepAfter) {
29594
+ await (0, import_await_sleep3.default)(sleepAfter);
29595
+ }
29541
29596
  }
29542
29597
  async goBack(timestamp, {
29543
29598
  sleepAfter = 1e3,
@@ -29577,21 +29632,6 @@
29577
29632
  sleepAfter
29578
29633
  });
29579
29634
  }
29580
- async goLive(sleepAfter = 1e3) {
29581
- if (this.isLive) {
29582
- return;
29583
- }
29584
- this.stop();
29585
- this.currentTraveledNumberOfEvents = void 0;
29586
- this.events = [];
29587
- this.castedEvents = [];
29588
- this.start(this.startOptions);
29589
- this.isLive = true;
29590
- await this.fastForward(this.liveEvents);
29591
- if (sleepAfter) {
29592
- await (0, import_await_sleep3.default)(sleepAfter);
29593
- }
29594
- }
29595
29635
  getLastEventTimestamps() {
29596
29636
  const lastEvent = this.events[this.events.length - 1];
29597
29637
  return {