@superinterface/react 5.0.0 → 5.1.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.js CHANGED
@@ -47287,7 +47287,6 @@ function _toPrimitive47(t, r) {
47287
47287
  }
47288
47288
  return ("string" === r ? String : Number)(t);
47289
47289
  }
47290
- var FULL_SENTENCE_REGEX = /[\.?!]$/;
47291
47290
  var getMessageSentences = function(_ref) {
47292
47291
  var messageId = _ref.messageId, input2 = _ref.input;
47293
47292
  var sentences = nlp(input2).sentences().json();
@@ -47299,80 +47298,110 @@ var getMessageSentences = function(_ref) {
47299
47298
  });
47300
47299
  };
47301
47300
  var useMessageAudio = function(t0) {
47302
- var _latestMessageProps$l;
47303
- var $ = _c88(49);
47304
- var _onEnd = t0.onEnd, passedPlay = t0.play;
47305
- var _useState9 = _sliced_to_array(useState9(false), 2), isAudioPlayed = _useState9[0], setIsAudioPlayed = _useState9[1];
47306
- var t1;
47307
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
47308
- t1 = [];
47309
- $[0] = t1;
47310
- } else {
47311
- t1 = $[0];
47312
- }
47313
- var _useState91 = _sliced_to_array(useState9(t1), 2), stoppedMessageIds = _useState91[0], setStoppedMessageIds = _useState91[1];
47301
+ var _latestMessageProps$l, _latestMessageProps$l4, _latestMessageProps$l5;
47302
+ var $ = _c88(68);
47303
+ var _onEnd = t0.onEnd, passedPlay = t0.play, t1 = t0.fullSentenceRegex;
47314
47304
  var t2;
47315
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
47316
- t2 = [];
47305
+ if ($[0] !== t1) {
47306
+ t2 = t1 === void 0 ? /[\.?!]$/ : t1;
47307
+ $[0] = t1;
47317
47308
  $[1] = t2;
47318
47309
  } else {
47319
47310
  t2 = $[1];
47320
47311
  }
47321
- var _useState92 = _sliced_to_array(useState9(t2), 2), playedMessageSentences = _useState92[0], setPlayedMessageSentences = _useState92[1];
47312
+ var fullSentenceRegex = t2;
47313
+ var _useState9 = _sliced_to_array(useState9(false), 2), isAudioPlayed = _useState9[0], setIsAudioPlayed = _useState9[1];
47314
+ var t3;
47315
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
47316
+ t3 = [];
47317
+ $[2] = t3;
47318
+ } else {
47319
+ t3 = $[2];
47320
+ }
47321
+ var _useState91 = _sliced_to_array(useState9(t3), 2), stoppedMessageIds = _useState91[0], setStoppedMessageIds = _useState91[1];
47322
+ var t4;
47323
+ if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
47324
+ t4 = [];
47325
+ $[3] = t4;
47326
+ } else {
47327
+ t4 = $[3];
47328
+ }
47329
+ var _useState92 = _sliced_to_array(useState9(t4), 2), playedMessageSentences = _useState92[0], setPlayedMessageSentences = _useState92[1];
47322
47330
  var audioPlayer = useAudioPlayer2();
47323
47331
  var nextAudioPlayer = useAudioPlayer2();
47324
47332
  var superinterfaceContext = useSuperinterfaceContext();
47325
47333
  var _useState93 = _sliced_to_array(useState9(false), 2), isPlaying = _useState93[0], setIsPlaying = _useState93[1];
47334
+ var isLastSentencePlayedRef = useRef8(false);
47326
47335
  var latestMessageProps = useLatestMessage();
47327
- var t3;
47336
+ var t5;
47337
+ var t6;
47338
+ if ($[4] !== isPlaying) {
47339
+ t5 = function() {
47340
+ if (!isPlaying) {
47341
+ return;
47342
+ }
47343
+ isLastSentencePlayedRef.current = false;
47344
+ };
47345
+ t6 = [
47346
+ isPlaying
47347
+ ];
47348
+ $[4] = isPlaying;
47349
+ $[5] = t5;
47350
+ $[6] = t6;
47351
+ } else {
47352
+ t5 = $[5];
47353
+ t6 = $[6];
47354
+ }
47355
+ useEffect10(t5, t6);
47356
+ var t7;
47328
47357
  bb0: {
47329
47358
  if (!latestMessageProps.latestMessage) {
47330
47359
  var _t;
47331
- if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
47360
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
47332
47361
  _t = [];
47333
- $[2] = _t;
47362
+ $[7] = _t;
47334
47363
  } else {
47335
- _t = $[2];
47364
+ _t = $[7];
47336
47365
  }
47337
- t3 = _t;
47366
+ t7 = _t;
47338
47367
  break bb0;
47339
47368
  }
47340
47369
  if (latestMessageProps.latestMessage.role !== "assistant") {
47341
47370
  var _t2;
47342
- if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
47371
+ if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
47343
47372
  _t2 = [];
47344
- $[3] = _t2;
47373
+ $[8] = _t2;
47345
47374
  } else {
47346
- _t2 = $[3];
47375
+ _t2 = $[8];
47347
47376
  }
47348
- t3 = _t2;
47377
+ t7 = _t2;
47349
47378
  break bb0;
47350
47379
  }
47351
47380
  if (stoppedMessageIds.includes(latestMessageProps.latestMessage.id)) {
47352
47381
  var _t3;
47353
- if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
47382
+ if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
47354
47383
  _t3 = [];
47355
- $[4] = _t3;
47384
+ $[9] = _t3;
47356
47385
  } else {
47357
- _t3 = $[4];
47386
+ _t3 = $[9];
47358
47387
  }
47359
- t3 = _t3;
47388
+ t7 = _t3;
47360
47389
  break bb0;
47361
47390
  }
47362
47391
  var _t4;
47363
- if ($[5] !== latestMessageProps.latestMessage || $[6] !== playedMessageSentences) {
47392
+ if ($[10] !== latestMessageProps.latestMessage || $[11] !== playedMessageSentences) {
47364
47393
  var input2 = input({
47365
47394
  message: latestMessageProps.latestMessage
47366
47395
  });
47367
47396
  if (!input2) {
47368
47397
  var _t5;
47369
- if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
47398
+ if ($[14] === Symbol.for("react.memo_cache_sentinel")) {
47370
47399
  _t5 = [];
47371
- $[9] = _t5;
47400
+ $[14] = _t5;
47372
47401
  } else {
47373
- _t5 = $[9];
47402
+ _t5 = $[14];
47374
47403
  }
47375
- t3 = _t5;
47404
+ t7 = _t5;
47376
47405
  break bb0;
47377
47406
  }
47378
47407
  var messageSentences = getMessageSentences({
@@ -47380,33 +47409,33 @@ var useMessageAudio = function(t0) {
47380
47409
  input: input2
47381
47410
  });
47382
47411
  var _t6;
47383
- if ($[10] !== playedMessageSentences) {
47412
+ if ($[15] !== playedMessageSentences) {
47384
47413
  _t6 = function(ms) {
47385
47414
  return !playedMessageSentences.find(function(pms) {
47386
47415
  return pms.messageId === ms.messageId && pms.sentence === ms.sentence;
47387
47416
  });
47388
47417
  };
47389
- $[10] = playedMessageSentences;
47390
- $[11] = _t6;
47418
+ $[15] = playedMessageSentences;
47419
+ $[16] = _t6;
47391
47420
  } else {
47392
- _t6 = $[11];
47421
+ _t6 = $[16];
47393
47422
  }
47394
47423
  _t4 = messageSentences.filter(_t6);
47395
- $[5] = latestMessageProps.latestMessage;
47396
- $[6] = playedMessageSentences;
47397
- $[7] = _t4;
47398
- $[8] = t3;
47424
+ $[10] = latestMessageProps.latestMessage;
47425
+ $[11] = playedMessageSentences;
47426
+ $[12] = _t4;
47427
+ $[13] = t7;
47399
47428
  } else {
47400
- _t4 = $[7];
47401
- t3 = $[8];
47429
+ _t4 = $[12];
47430
+ t7 = $[13];
47402
47431
  }
47403
- t3 = _t4;
47432
+ t7 = _t4;
47404
47433
  }
47405
- var unplayedMessageSentences = t3;
47406
- var t4;
47407
- if ($[12] !== audioPlayer || $[13] !== isAudioPlayed || $[14] !== nextAudioPlayer || $[15] !== superinterfaceContext || $[16] !== unplayedMessageSentences) {
47408
- t4 = function(t52) {
47409
- var input_0 = t52.input, onPlay = t52.onPlay, onStop = t52.onStop, onEnd_0 = t52.onEnd;
47434
+ var unplayedMessageSentences = t7;
47435
+ var t8;
47436
+ if ($[17] !== audioPlayer || $[18] !== fullSentenceRegex || $[19] !== isAudioPlayed || $[20] !== nextAudioPlayer || $[21] !== superinterfaceContext || $[22] !== unplayedMessageSentences[1]) {
47437
+ t8 = function(t92) {
47438
+ var input_0 = t92.input, onPlay = t92.onPlay, onStop = t92.onStop, onEnd_0 = t92.onEnd;
47410
47439
  var searchParams = new URLSearchParams(_objectSpread47({
47411
47440
  input: input_0
47412
47441
  }, superinterfaceContext.variables));
@@ -47421,7 +47450,7 @@ var useMessageAudio = function(t0) {
47421
47450
  if (!nextUnplayedMessageSentence) {
47422
47451
  return;
47423
47452
  }
47424
- var isNextFullSentence = FULL_SENTENCE_REGEX.test(nextUnplayedMessageSentence.sentence);
47453
+ var isNextFullSentence = fullSentenceRegex.test(nextUnplayedMessageSentence.sentence);
47425
47454
  if (!isNextFullSentence) {
47426
47455
  return;
47427
47456
  }
@@ -47437,22 +47466,23 @@ var useMessageAudio = function(t0) {
47437
47466
  onend: onEnd_0
47438
47467
  });
47439
47468
  };
47440
- $[12] = audioPlayer;
47441
- $[13] = isAudioPlayed;
47442
- $[14] = nextAudioPlayer;
47443
- $[15] = superinterfaceContext;
47444
- $[16] = unplayedMessageSentences;
47445
- $[17] = t4;
47469
+ $[17] = audioPlayer;
47470
+ $[18] = fullSentenceRegex;
47471
+ $[19] = isAudioPlayed;
47472
+ $[20] = nextAudioPlayer;
47473
+ $[21] = superinterfaceContext;
47474
+ $[22] = unplayedMessageSentences[1];
47475
+ $[23] = t8;
47446
47476
  } else {
47447
- t4 = $[17];
47477
+ t8 = $[23];
47448
47478
  }
47449
- var defaultPlay = t4;
47450
- var t5;
47451
- t5 = passedPlay || defaultPlay;
47452
- var play = t5;
47453
- var t6;
47454
- if ($[18] !== audioPlayer.playing || $[19] !== isPlaying || $[20] !== latestMessageProps.latestMessage || $[21] !== _onEnd || $[22] !== play || $[23] !== unplayedMessageSentences) {
47455
- t6 = function() {
47479
+ var defaultPlay = t8;
47480
+ var t9;
47481
+ t9 = passedPlay || defaultPlay;
47482
+ var play = t9;
47483
+ var t10;
47484
+ if ($[24] !== audioPlayer.playing || $[25] !== fullSentenceRegex || $[26] !== isPlaying || $[27] !== latestMessageProps.latestMessage || $[28] !== _onEnd || $[29] !== play || $[30] !== unplayedMessageSentences[0] || $[31] !== unplayedMessageSentences.length) {
47485
+ t10 = function() {
47456
47486
  if (isPlaying) {
47457
47487
  return;
47458
47488
  }
@@ -47471,7 +47501,7 @@ var useMessageAudio = function(t0) {
47471
47501
  }
47472
47502
  var isFullSentence = isOptimistic({
47473
47503
  id: latestMessageProps.latestMessage.id
47474
- }) || latestMessageProps.latestMessage.status !== "in_progress" || FULL_SENTENCE_REGEX.test(firstUnplayedMessageSentence.sentence);
47504
+ }) || latestMessageProps.latestMessage.status !== "in_progress" || fullSentenceRegex.test(firstUnplayedMessageSentence.sentence);
47475
47505
  if (!isFullSentence) {
47476
47506
  return;
47477
47507
  }
@@ -47497,25 +47527,29 @@ var useMessageAudio = function(t0) {
47497
47527
  },
47498
47528
  onEnd: function() {
47499
47529
  setIsPlaying(false);
47500
- if (unplayedMessageSentences.length === 1 && latestMessageProps.latestMessage.status !== "in_progress") {
47530
+ isLastSentencePlayedRef.current = unplayedMessageSentences.length === 1;
47531
+ if (isLastSentencePlayedRef.current && latestMessageProps.latestMessage.status !== "in_progress") {
47501
47532
  _onEnd();
47533
+ isLastSentencePlayedRef.current = false;
47502
47534
  }
47503
47535
  }
47504
47536
  });
47505
47537
  };
47506
- $[18] = audioPlayer.playing;
47507
- $[19] = isPlaying;
47508
- $[20] = latestMessageProps.latestMessage;
47509
- $[21] = _onEnd;
47510
- $[22] = play;
47511
- $[23] = unplayedMessageSentences;
47512
- $[24] = t6;
47538
+ $[24] = audioPlayer.playing;
47539
+ $[25] = fullSentenceRegex;
47540
+ $[26] = isPlaying;
47541
+ $[27] = latestMessageProps.latestMessage;
47542
+ $[28] = _onEnd;
47543
+ $[29] = play;
47544
+ $[30] = unplayedMessageSentences[0];
47545
+ $[31] = unplayedMessageSentences.length;
47546
+ $[32] = t10;
47513
47547
  } else {
47514
- t6 = $[24];
47548
+ t10 = $[32];
47515
47549
  }
47516
- var t7;
47517
- if ($[25] !== audioPlayer || $[26] !== isPlaying || $[27] !== latestMessageProps || $[28] !== nextAudioPlayer || $[29] !== _onEnd || $[30] !== play || $[31] !== playedMessageSentences || $[32] !== superinterfaceContext || $[33] !== unplayedMessageSentences) {
47518
- t7 = [
47550
+ var t11;
47551
+ if ($[33] !== audioPlayer || $[34] !== fullSentenceRegex || $[35] !== isPlaying || $[36] !== latestMessageProps || $[37] !== nextAudioPlayer || $[38] !== _onEnd || $[39] !== play || $[40] !== playedMessageSentences || $[41] !== superinterfaceContext || $[42] !== unplayedMessageSentences) {
47552
+ t11 = [
47519
47553
  unplayedMessageSentences,
47520
47554
  isPlaying,
47521
47555
  superinterfaceContext,
@@ -47524,38 +47558,76 @@ var useMessageAudio = function(t0) {
47524
47558
  nextAudioPlayer,
47525
47559
  playedMessageSentences,
47526
47560
  _onEnd,
47527
- play
47561
+ play,
47562
+ fullSentenceRegex
47528
47563
  ];
47529
- $[25] = audioPlayer;
47530
- $[26] = isPlaying;
47531
- $[27] = latestMessageProps;
47532
- $[28] = nextAudioPlayer;
47533
- $[29] = _onEnd;
47534
- $[30] = play;
47535
- $[31] = playedMessageSentences;
47536
- $[32] = superinterfaceContext;
47537
- $[33] = unplayedMessageSentences;
47538
- $[34] = t7;
47539
- } else {
47540
- t7 = $[34];
47541
- }
47542
- useEffect10(t6, t7);
47543
- var t8;
47544
- if ($[35] !== audioPlayer) {
47545
- t8 = [
47564
+ $[33] = audioPlayer;
47565
+ $[34] = fullSentenceRegex;
47566
+ $[35] = isPlaying;
47567
+ $[36] = latestMessageProps;
47568
+ $[37] = nextAudioPlayer;
47569
+ $[38] = _onEnd;
47570
+ $[39] = play;
47571
+ $[40] = playedMessageSentences;
47572
+ $[41] = superinterfaceContext;
47573
+ $[42] = unplayedMessageSentences;
47574
+ $[43] = t11;
47575
+ } else {
47576
+ t11 = $[43];
47577
+ }
47578
+ useEffect10(t10, t11);
47579
+ var t12;
47580
+ if ($[44] !== isPlaying || $[45] !== ((_latestMessageProps$l = latestMessageProps.latestMessage) === null || _latestMessageProps$l === void 0 ? void 0 : _latestMessageProps$l.status) || $[46] !== _onEnd || $[47] !== unplayedMessageSentences.length) {
47581
+ var _latestMessageProps$l3;
47582
+ t12 = function() {
47583
+ var _latestMessageProps$l2;
47584
+ if (isLastSentencePlayedRef.current && !isPlaying && unplayedMessageSentences.length === 0 && ((_latestMessageProps$l2 = latestMessageProps.latestMessage) === null || _latestMessageProps$l2 === void 0 ? void 0 : _latestMessageProps$l2.status) !== "in_progress") {
47585
+ _onEnd();
47586
+ isLastSentencePlayedRef.current = false;
47587
+ }
47588
+ };
47589
+ $[44] = isPlaying;
47590
+ $[45] = (_latestMessageProps$l3 = latestMessageProps.latestMessage) === null || _latestMessageProps$l3 === void 0 ? void 0 : _latestMessageProps$l3.status;
47591
+ $[46] = _onEnd;
47592
+ $[47] = unplayedMessageSentences.length;
47593
+ $[48] = t12;
47594
+ } else {
47595
+ t12 = $[48];
47596
+ }
47597
+ var t13 = (_latestMessageProps$l4 = latestMessageProps.latestMessage) === null || _latestMessageProps$l4 === void 0 ? void 0 : _latestMessageProps$l4.status;
47598
+ var t14;
47599
+ if ($[49] !== isPlaying || $[50] !== _onEnd || $[51] !== t13 || $[52] !== unplayedMessageSentences.length) {
47600
+ t14 = [
47601
+ isPlaying,
47602
+ unplayedMessageSentences.length,
47603
+ t13,
47604
+ _onEnd
47605
+ ];
47606
+ $[49] = isPlaying;
47607
+ $[50] = _onEnd;
47608
+ $[51] = t13;
47609
+ $[52] = unplayedMessageSentences.length;
47610
+ $[53] = t14;
47611
+ } else {
47612
+ t14 = $[53];
47613
+ }
47614
+ useEffect10(t12, t14);
47615
+ var t15;
47616
+ if ($[54] !== audioPlayer) {
47617
+ t15 = [
47546
47618
  audioPlayer
47547
47619
  ];
47548
- $[35] = audioPlayer;
47549
- $[36] = t8;
47620
+ $[54] = audioPlayer;
47621
+ $[55] = t15;
47550
47622
  } else {
47551
- t8 = $[36];
47623
+ t15 = $[55];
47552
47624
  }
47553
- useEffect10(_temp9, t8);
47625
+ useEffect10(_temp9, t15);
47554
47626
  var _useState94 = _sliced_to_array(useState9(null), 2), audioEngine = _useState94[0], setAudioEngine = _useState94[1];
47555
47627
  var isAudioEngineInited = useRef8(false);
47556
- var t9;
47557
- if ($[37] !== audioPlayer.playing) {
47558
- t9 = function() {
47628
+ var t16;
47629
+ if ($[56] !== audioPlayer.playing) {
47630
+ t16 = function() {
47559
47631
  if (!audioPlayer.playing) {
47560
47632
  return;
47561
47633
  }
@@ -47576,63 +47648,63 @@ var useMessageAudio = function(t0) {
47576
47648
  });
47577
47649
  }
47578
47650
  };
47579
- $[37] = audioPlayer.playing;
47580
- $[38] = t9;
47651
+ $[56] = audioPlayer.playing;
47652
+ $[57] = t16;
47581
47653
  } else {
47582
- t9 = $[38];
47654
+ t16 = $[57];
47583
47655
  }
47584
- var t10;
47585
- if ($[39] !== audioPlayer) {
47586
- t10 = [
47656
+ var t17;
47657
+ if ($[58] !== audioPlayer) {
47658
+ t17 = [
47587
47659
  audioPlayer,
47588
47660
  isAudioEngineInited
47589
47661
  ];
47590
- $[39] = audioPlayer;
47591
- $[40] = t10;
47662
+ $[58] = audioPlayer;
47663
+ $[59] = t17;
47592
47664
  } else {
47593
- t10 = $[40];
47665
+ t17 = $[59];
47594
47666
  }
47595
- useEffect10(t9, t10);
47596
- var t11;
47667
+ useEffect10(t16, t17);
47668
+ var t18;
47597
47669
  bb1: {
47598
47670
  if (!audioEngine) {
47599
- t11 = null;
47671
+ t18 = null;
47600
47672
  break bb1;
47601
47673
  }
47602
47674
  var result;
47603
- if ($[41] !== audioEngine.audioContext || $[42] !== audioEngine.source) {
47675
+ if ($[60] !== audioEngine.audioContext || $[61] !== audioEngine.source) {
47604
47676
  result = audioEngine.audioContext.createAnalyser();
47605
47677
  audioEngine.source.connect(audioEngine.audioContext.destination);
47606
47678
  audioEngine.source.connect(result);
47607
- $[41] = audioEngine.audioContext;
47608
- $[42] = audioEngine.source;
47609
- $[43] = result;
47679
+ $[60] = audioEngine.audioContext;
47680
+ $[61] = audioEngine.source;
47681
+ $[62] = result;
47610
47682
  } else {
47611
- result = $[43];
47683
+ result = $[62];
47612
47684
  }
47613
- t11 = result;
47685
+ t18 = result;
47614
47686
  }
47615
- var visualizationAnalyser = t11;
47616
- var t12;
47617
- t12 = isPlaying || unplayedMessageSentences.length > 0 || ((_latestMessageProps$l = latestMessageProps.latestMessage) === null || _latestMessageProps$l === void 0 ? void 0 : _latestMessageProps$l.status) === "in_progress";
47618
- var isPending = t12;
47619
- var t13;
47620
- if ($[44] !== audioPlayer || $[45] !== isAudioPlayed || $[46] !== isPending || $[47] !== visualizationAnalyser) {
47621
- t13 = _objectSpread47(_objectSpread47({
47687
+ var visualizationAnalyser = t18;
47688
+ var t19;
47689
+ t19 = isPlaying || unplayedMessageSentences.length > 0 || ((_latestMessageProps$l5 = latestMessageProps.latestMessage) === null || _latestMessageProps$l5 === void 0 ? void 0 : _latestMessageProps$l5.status) === "in_progress";
47690
+ var isPending = t19;
47691
+ var t20;
47692
+ if ($[63] !== audioPlayer || $[64] !== isAudioPlayed || $[65] !== isPending || $[66] !== visualizationAnalyser) {
47693
+ t20 = _objectSpread47(_objectSpread47({
47622
47694
  isPending: isPending,
47623
47695
  isAudioPlayed: isAudioPlayed
47624
47696
  }, audioPlayer), {}, {
47625
47697
  visualizationAnalyser: visualizationAnalyser
47626
47698
  });
47627
- $[44] = audioPlayer;
47628
- $[45] = isAudioPlayed;
47629
- $[46] = isPending;
47630
- $[47] = visualizationAnalyser;
47631
- $[48] = t13;
47699
+ $[63] = audioPlayer;
47700
+ $[64] = isAudioPlayed;
47701
+ $[65] = isPending;
47702
+ $[66] = visualizationAnalyser;
47703
+ $[67] = t20;
47632
47704
  } else {
47633
- t13 = $[48];
47705
+ t20 = $[67];
47634
47706
  }
47635
- return t13;
47707
+ return t20;
47636
47708
  };
47637
47709
  function _temp9() {
47638
47710
  if (isHtmlAudioSupported) {