@superinterface/react 3.7.1 → 3.7.3-beta.1

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
@@ -373,6 +373,9 @@ __export(src_exports, {
373
373
  useAssistant: function() {
374
374
  return useAssistant;
375
375
  },
376
+ useAudioThreadContext: function() {
377
+ return useAudioThreadContext;
378
+ },
376
379
  useComponents: function() {
377
380
  return useComponents;
378
381
  },
@@ -9300,8 +9303,8 @@ var getMessageSentences = function(_ref) {
9300
9303
  });
9301
9304
  };
9302
9305
  var useMessageAudio = function(t0) {
9303
- var $ = (0, import_react_compiler_runtime50.c)(44);
9304
- var onEnd = t0.onEnd;
9306
+ var $ = (0, import_react_compiler_runtime50.c)(50);
9307
+ var _onEnd = t0.onEnd, passedPlay = t0.play;
9305
9308
  var _ref = _sliced_to_array((0, import_react63.useState)(false), 2), isAudioPlayed = _ref[0], setIsAudioPlayed = _ref[1];
9306
9309
  var t1;
9307
9310
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
@@ -9404,8 +9407,56 @@ var useMessageAudio = function(t0) {
9404
9407
  }
9405
9408
  var unplayedMessageSentences = t3;
9406
9409
  var t4;
9407
- if ($[12] !== audioPlayer || $[13] !== isAudioPlayed || $[14] !== isPlaying || $[15] !== latestMessageProps.latestMessage || $[16] !== nextAudioPlayer || $[17] !== onEnd || $[18] !== superinterfaceContext || $[19] !== unplayedMessageSentences) {
9408
- t4 = function() {
9410
+ if ($[12] !== audioPlayer || $[13] !== isAudioPlayed || $[14] !== nextAudioPlayer || $[15] !== superinterfaceContext.baseUrl || $[16] !== superinterfaceContext.variables || $[17] !== unplayedMessageSentences) {
9411
+ t4 = function(t52) {
9412
+ var input_0 = t52.input, onPlay = t52.onPlay, onStop = t52.onStop, onEnd_0 = t52.onEnd;
9413
+ var searchParams = new URLSearchParams(_objectSpread45({
9414
+ input: input_0
9415
+ }, superinterfaceContext.variables));
9416
+ audioPlayer.load("".concat(superinterfaceContext.baseUrl, "/tts?").concat(searchParams), {
9417
+ format: "mp3",
9418
+ autoplay: isAudioPlayed,
9419
+ html5: isHtmlAudioSupported,
9420
+ onplay: onPlay,
9421
+ onstop: onStop,
9422
+ onload: function() {
9423
+ var nextUnplayedMessageSentence = unplayedMessageSentences[1];
9424
+ if (!nextUnplayedMessageSentence) {
9425
+ return;
9426
+ }
9427
+ var isNextFullSentence = FULL_SENTENCE_REGEX.test(nextUnplayedMessageSentence.sentence);
9428
+ if (!isNextFullSentence) {
9429
+ return;
9430
+ }
9431
+ var nextSearchParams = new URLSearchParams(_objectSpread45({
9432
+ input: nextUnplayedMessageSentence.sentence
9433
+ }, superinterfaceContext.variables));
9434
+ nextAudioPlayer.load("".concat(superinterfaceContext.baseUrl, "/tts?").concat(nextSearchParams), {
9435
+ format: "mp3",
9436
+ autoplay: false,
9437
+ html5: isHtmlAudioSupported
9438
+ });
9439
+ },
9440
+ onend: onEnd_0
9441
+ });
9442
+ };
9443
+ $[12] = audioPlayer;
9444
+ $[13] = isAudioPlayed;
9445
+ $[14] = nextAudioPlayer;
9446
+ $[15] = superinterfaceContext.baseUrl;
9447
+ $[16] = superinterfaceContext.variables;
9448
+ $[17] = unplayedMessageSentences;
9449
+ $[18] = t4;
9450
+ } else {
9451
+ t4 = $[18];
9452
+ }
9453
+ var defaultPlay = t4;
9454
+ var t5;
9455
+ t5 = passedPlay || defaultPlay;
9456
+ var play = t5;
9457
+ var t6;
9458
+ if ($[19] !== audioPlayer.playing || $[20] !== isPlaying || $[21] !== latestMessageProps.latestMessage || $[22] !== _onEnd || $[23] !== play || $[24] !== unplayedMessageSentences) {
9459
+ t6 = function() {
9409
9460
  if (isPlaying) {
9410
9461
  return;
9411
9462
  }
@@ -9434,17 +9485,13 @@ var useMessageAudio = function(t0) {
9434
9485
  firstUnplayedMessageSentence
9435
9486
  ]);
9436
9487
  });
9437
- var searchParams = new URLSearchParams(_objectSpread45({
9438
- input: firstUnplayedMessageSentence.sentence
9439
- }, superinterfaceContext.variables));
9440
- audioPlayer.load("".concat(superinterfaceContext.baseUrl, "/tts?").concat(searchParams), {
9441
- format: "mp3",
9442
- autoplay: isAudioPlayed,
9443
- html5: isHtmlAudioSupported,
9444
- onplay: function() {
9488
+ var input_1 = firstUnplayedMessageSentence.sentence;
9489
+ play({
9490
+ input: input_1,
9491
+ onPlay: function() {
9445
9492
  setIsAudioPlayed(true);
9446
9493
  },
9447
- onstop: function() {
9494
+ onStop: function() {
9448
9495
  setStoppedMessageIds(function(prev_0) {
9449
9496
  return _to_consumable_array(prev_0).concat([
9450
9497
  firstUnplayedMessageSentence.messageId
@@ -9452,47 +9499,27 @@ var useMessageAudio = function(t0) {
9452
9499
  });
9453
9500
  setIsPlaying(false);
9454
9501
  },
9455
- onload: function() {
9456
- var nextUnplayedMessageSentence = unplayedMessageSentences[1];
9457
- if (!nextUnplayedMessageSentence) {
9458
- return;
9459
- }
9460
- var isNextFullSentence = FULL_SENTENCE_REGEX.test(nextUnplayedMessageSentence.sentence);
9461
- if (!isNextFullSentence) {
9462
- return;
9463
- }
9464
- var nextSearchParams = new URLSearchParams(_objectSpread45({
9465
- input: nextUnplayedMessageSentence.sentence
9466
- }, superinterfaceContext.variables));
9467
- nextAudioPlayer.load("".concat(superinterfaceContext.baseUrl, "/tts?").concat(nextSearchParams), {
9468
- format: "mp3",
9469
- autoplay: false,
9470
- html5: isHtmlAudioSupported
9471
- });
9472
- },
9473
- onend: function() {
9502
+ onEnd: function() {
9474
9503
  setIsPlaying(false);
9475
9504
  if (unplayedMessageSentences.length === 1 && latestMessageProps.latestMessage.status !== "in_progress") {
9476
- onEnd();
9505
+ _onEnd();
9477
9506
  }
9478
9507
  }
9479
9508
  });
9480
9509
  };
9481
- $[12] = audioPlayer;
9482
- $[13] = isAudioPlayed;
9483
- $[14] = isPlaying;
9484
- $[15] = latestMessageProps.latestMessage;
9485
- $[16] = nextAudioPlayer;
9486
- $[17] = onEnd;
9487
- $[18] = superinterfaceContext;
9488
- $[19] = unplayedMessageSentences;
9489
- $[20] = t4;
9510
+ $[19] = audioPlayer.playing;
9511
+ $[20] = isPlaying;
9512
+ $[21] = latestMessageProps.latestMessage;
9513
+ $[22] = _onEnd;
9514
+ $[23] = play;
9515
+ $[24] = unplayedMessageSentences;
9516
+ $[25] = t6;
9490
9517
  } else {
9491
- t4 = $[20];
9518
+ t6 = $[25];
9492
9519
  }
9493
- var t5;
9494
- if ($[21] !== audioPlayer || $[22] !== isPlaying || $[23] !== latestMessageProps || $[24] !== nextAudioPlayer || $[25] !== onEnd || $[26] !== playedMessageSentences || $[27] !== superinterfaceContext || $[28] !== unplayedMessageSentences) {
9495
- t5 = [
9520
+ var t7;
9521
+ if ($[26] !== audioPlayer || $[27] !== isPlaying || $[28] !== latestMessageProps || $[29] !== nextAudioPlayer || $[30] !== _onEnd || $[31] !== play || $[32] !== playedMessageSentences || $[33] !== superinterfaceContext || $[34] !== unplayedMessageSentences) {
9522
+ t7 = [
9496
9523
  unplayedMessageSentences,
9497
9524
  isPlaying,
9498
9525
  superinterfaceContext,
@@ -9500,37 +9527,39 @@ var useMessageAudio = function(t0) {
9500
9527
  audioPlayer,
9501
9528
  nextAudioPlayer,
9502
9529
  playedMessageSentences,
9503
- onEnd
9530
+ _onEnd,
9531
+ play
9504
9532
  ];
9505
- $[21] = audioPlayer;
9506
- $[22] = isPlaying;
9507
- $[23] = latestMessageProps;
9508
- $[24] = nextAudioPlayer;
9509
- $[25] = onEnd;
9510
- $[26] = playedMessageSentences;
9511
- $[27] = superinterfaceContext;
9512
- $[28] = unplayedMessageSentences;
9513
- $[29] = t5;
9514
- } else {
9515
- t5 = $[29];
9516
- }
9517
- (0, import_react63.useEffect)(t4, t5);
9518
- var t6;
9519
- if ($[30] !== audioPlayer) {
9520
- t6 = [
9533
+ $[26] = audioPlayer;
9534
+ $[27] = isPlaying;
9535
+ $[28] = latestMessageProps;
9536
+ $[29] = nextAudioPlayer;
9537
+ $[30] = _onEnd;
9538
+ $[31] = play;
9539
+ $[32] = playedMessageSentences;
9540
+ $[33] = superinterfaceContext;
9541
+ $[34] = unplayedMessageSentences;
9542
+ $[35] = t7;
9543
+ } else {
9544
+ t7 = $[35];
9545
+ }
9546
+ (0, import_react63.useEffect)(t6, t7);
9547
+ var t8;
9548
+ if ($[36] !== audioPlayer) {
9549
+ t8 = [
9521
9550
  audioPlayer
9522
9551
  ];
9523
- $[30] = audioPlayer;
9524
- $[31] = t6;
9552
+ $[36] = audioPlayer;
9553
+ $[37] = t8;
9525
9554
  } else {
9526
- t6 = $[31];
9555
+ t8 = $[37];
9527
9556
  }
9528
- (0, import_react63.useEffect)(_temp11, t6);
9557
+ (0, import_react63.useEffect)(_temp11, t8);
9529
9558
  var _ref4 = _sliced_to_array((0, import_react63.useState)(null), 2), audioEngine = _ref4[0], setAudioEngine = _ref4[1];
9530
9559
  var isAudioEngineInited = (0, import_react63.useRef)(false);
9531
- var t7;
9532
- if ($[32] !== audioPlayer.playing) {
9533
- t7 = function() {
9560
+ var t9;
9561
+ if ($[38] !== audioPlayer.playing) {
9562
+ t9 = function() {
9534
9563
  if (!audioPlayer.playing) {
9535
9564
  return;
9536
9565
  }
@@ -9551,63 +9580,63 @@ var useMessageAudio = function(t0) {
9551
9580
  });
9552
9581
  }
9553
9582
  };
9554
- $[32] = audioPlayer.playing;
9555
- $[33] = t7;
9583
+ $[38] = audioPlayer.playing;
9584
+ $[39] = t9;
9556
9585
  } else {
9557
- t7 = $[33];
9586
+ t9 = $[39];
9558
9587
  }
9559
- var t8;
9560
- if ($[34] !== audioPlayer) {
9561
- t8 = [
9588
+ var t10;
9589
+ if ($[40] !== audioPlayer) {
9590
+ t10 = [
9562
9591
  audioPlayer,
9563
9592
  isAudioEngineInited
9564
9593
  ];
9565
- $[34] = audioPlayer;
9566
- $[35] = t8;
9594
+ $[40] = audioPlayer;
9595
+ $[41] = t10;
9567
9596
  } else {
9568
- t8 = $[35];
9597
+ t10 = $[41];
9569
9598
  }
9570
- (0, import_react63.useEffect)(t7, t8);
9571
- var t9;
9599
+ (0, import_react63.useEffect)(t9, t10);
9600
+ var t11;
9572
9601
  bb1: {
9573
9602
  if (!audioEngine) {
9574
- t9 = null;
9603
+ t11 = null;
9575
9604
  break bb1;
9576
9605
  }
9577
9606
  var result;
9578
- if ($[36] !== audioEngine.audioContext || $[37] !== audioEngine.source) {
9607
+ if ($[42] !== audioEngine.audioContext || $[43] !== audioEngine.source) {
9579
9608
  result = audioEngine.audioContext.createAnalyser();
9580
9609
  audioEngine.source.connect(audioEngine.audioContext.destination);
9581
9610
  audioEngine.source.connect(result);
9582
- $[36] = audioEngine.audioContext;
9583
- $[37] = audioEngine.source;
9584
- $[38] = result;
9611
+ $[42] = audioEngine.audioContext;
9612
+ $[43] = audioEngine.source;
9613
+ $[44] = result;
9585
9614
  } else {
9586
- result = $[38];
9615
+ result = $[44];
9587
9616
  }
9588
- t9 = result;
9617
+ t11 = result;
9589
9618
  }
9590
- var visualizationAnalyser = t9;
9591
- var t10;
9592
- t10 = isPlaying || unplayedMessageSentences.length > 0;
9593
- var isPending = t10;
9594
- var t11;
9595
- if ($[39] !== audioPlayer || $[40] !== isAudioPlayed || $[41] !== isPending || $[42] !== visualizationAnalyser) {
9596
- t11 = _objectSpread45(_objectSpread45({
9619
+ var visualizationAnalyser = t11;
9620
+ var t12;
9621
+ t12 = isPlaying || unplayedMessageSentences.length > 0;
9622
+ var isPending = t12;
9623
+ var t13;
9624
+ if ($[45] !== audioPlayer || $[46] !== isAudioPlayed || $[47] !== isPending || $[48] !== visualizationAnalyser) {
9625
+ t13 = _objectSpread45(_objectSpread45({
9597
9626
  isPending: isPending,
9598
9627
  isAudioPlayed: isAudioPlayed
9599
9628
  }, audioPlayer), {}, {
9600
9629
  visualizationAnalyser: visualizationAnalyser
9601
9630
  });
9602
- $[39] = audioPlayer;
9603
- $[40] = isAudioPlayed;
9604
- $[41] = isPending;
9605
- $[42] = visualizationAnalyser;
9606
- $[43] = t11;
9631
+ $[45] = audioPlayer;
9632
+ $[46] = isAudioPlayed;
9633
+ $[47] = isPending;
9634
+ $[48] = visualizationAnalyser;
9635
+ $[49] = t13;
9607
9636
  } else {
9608
- t11 = $[43];
9637
+ t13 = $[49];
9609
9638
  }
9610
- return t11;
9639
+ return t13;
9611
9640
  };
9612
9641
  function _temp11() {
9613
9642
  if (isHtmlAudioSupported) {
@@ -9709,8 +9738,8 @@ function _asyncToGenerator12(n) {
9709
9738
  };
9710
9739
  }
9711
9740
  var Content8 = function(t0) {
9712
- var $ = (0, import_react_compiler_runtime51.c)(21);
9713
- var children = t0.children, className = t0.className, style = t0.style;
9741
+ var $ = (0, import_react_compiler_runtime51.c)(24);
9742
+ var children = t0.children, className = t0.className, style = t0.style, play = t0.play;
9714
9743
  var addToast = useToasts().addToast;
9715
9744
  var queryClient = (0, import_react_query10.useQueryClient)();
9716
9745
  var threadContext = useSuperinterfaceContext();
@@ -9777,11 +9806,9 @@ var Content8 = function(t0) {
9777
9806
  var microphonePermission = usePermission(t2);
9778
9807
  var t3;
9779
9808
  if ($[3] !== microphonePermission || $[4] !== recorderProps) {
9780
- t3 = {
9781
- onEnd: function() {
9782
- if (microphonePermission === "granted") {
9783
- recorderProps.start();
9784
- }
9809
+ t3 = function() {
9810
+ if (microphonePermission === "granted") {
9811
+ recorderProps.start();
9785
9812
  }
9786
9813
  };
9787
9814
  $[3] = microphonePermission;
@@ -9790,41 +9817,53 @@ var Content8 = function(t0) {
9790
9817
  } else {
9791
9818
  t3 = $[5];
9792
9819
  }
9793
- var messageAudioProps = useMessageAudio(t3);
9794
- var t4 = recorderProps;
9795
- var t5;
9796
- if ($[6] !== createMessageProps || $[7] !== messageAudioProps || $[8] !== t4) {
9797
- t5 = {
9798
- recorderProps: t4,
9799
- createMessageProps: createMessageProps,
9800
- messageAudioProps: messageAudioProps
9820
+ var t4;
9821
+ if ($[6] !== play || $[7] !== t3) {
9822
+ t4 = {
9823
+ play: play,
9824
+ onEnd: t3
9801
9825
  };
9802
- $[6] = createMessageProps;
9803
- $[7] = messageAudioProps;
9826
+ $[6] = play;
9827
+ $[7] = t3;
9804
9828
  $[8] = t4;
9805
- $[9] = t5;
9806
9829
  } else {
9807
- t5 = $[9];
9830
+ t4 = $[8];
9808
9831
  }
9809
- var status = useStatus(t5).status;
9810
- var t6 = recorderProps;
9811
- var t7;
9812
- if ($[10] !== messageAudioProps || $[11] !== status || $[12] !== t6) {
9813
- t7 = {
9814
- status: status,
9815
- recorderProps: t6,
9832
+ var messageAudioProps = useMessageAudio(t4);
9833
+ var t5 = recorderProps;
9834
+ var t6;
9835
+ if ($[9] !== createMessageProps || $[10] !== messageAudioProps || $[11] !== t5) {
9836
+ t6 = {
9837
+ recorderProps: t5,
9838
+ createMessageProps: createMessageProps,
9816
9839
  messageAudioProps: messageAudioProps
9817
9840
  };
9841
+ $[9] = createMessageProps;
9818
9842
  $[10] = messageAudioProps;
9819
- $[11] = status;
9843
+ $[11] = t5;
9820
9844
  $[12] = t6;
9821
- $[13] = t7;
9822
9845
  } else {
9823
- t7 = $[13];
9846
+ t6 = $[12];
9824
9847
  }
9848
+ var status = useStatus(t6).status;
9849
+ var t7 = recorderProps;
9825
9850
  var t8;
9826
- if ($[14] !== children || $[15] !== className || $[16] !== style) {
9827
- t8 = /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(import_themes58.Flex, {
9851
+ if ($[13] !== messageAudioProps || $[14] !== status || $[15] !== t7) {
9852
+ t8 = {
9853
+ status: status,
9854
+ recorderProps: t7,
9855
+ messageAudioProps: messageAudioProps
9856
+ };
9857
+ $[13] = messageAudioProps;
9858
+ $[14] = status;
9859
+ $[15] = t7;
9860
+ $[16] = t8;
9861
+ } else {
9862
+ t8 = $[16];
9863
+ }
9864
+ var t9;
9865
+ if ($[17] !== children || $[18] !== className || $[19] !== style) {
9866
+ t9 = /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(import_themes58.Flex, {
9828
9867
  direction: "column",
9829
9868
  flexGrow: "1",
9830
9869
  p: "9",
@@ -9832,26 +9871,26 @@ var Content8 = function(t0) {
9832
9871
  style: style,
9833
9872
  children: children
9834
9873
  });
9835
- $[14] = children;
9836
- $[15] = className;
9837
- $[16] = style;
9838
- $[17] = t8;
9874
+ $[17] = children;
9875
+ $[18] = className;
9876
+ $[19] = style;
9877
+ $[20] = t9;
9839
9878
  } else {
9840
- t8 = $[17];
9879
+ t9 = $[20];
9841
9880
  }
9842
- var t9;
9843
- if ($[18] !== t7 || $[19] !== t8) {
9844
- t9 = /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(AudioThreadContext.Provider, {
9845
- value: t7,
9846
- children: t8
9881
+ var t10;
9882
+ if ($[21] !== t8 || $[22] !== t9) {
9883
+ t10 = /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(AudioThreadContext.Provider, {
9884
+ value: t8,
9885
+ children: t9
9847
9886
  });
9848
- $[18] = t7;
9849
- $[19] = t8;
9850
- $[20] = t9;
9887
+ $[21] = t8;
9888
+ $[22] = t9;
9889
+ $[23] = t10;
9851
9890
  } else {
9852
- t9 = $[20];
9891
+ t10 = $[23];
9853
9892
  }
9854
- return t9;
9893
+ return t10;
9855
9894
  };
9856
9895
  var Root12 = function(_ref) {
9857
9896
  var children = _ref.children, rest = _objectWithoutProperties4(_ref, _excluded4);
@@ -11202,6 +11241,7 @@ var AssistantProvider = function(t0) {
11202
11241
  ThreadDialogContext: ThreadDialogContext,
11203
11242
  UserAvatarContext: UserAvatarContext,
11204
11243
  useAssistant: useAssistant,
11244
+ useAudioThreadContext: useAudioThreadContext,
11205
11245
  useComponents: useComponents,
11206
11246
  useCreateMessage: useCreateMessage,
11207
11247
  useIsMutatingMessage: useIsMutatingMessage,