@superinterface/react 5.3.0-beta.11 → 5.3.0-beta.13

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
@@ -47530,6 +47530,27 @@ var getIncrementalSegments = function(prev, nextInput, now) {
47530
47530
  touched: now
47531
47531
  };
47532
47532
  };
47533
+ var getDefaultSegments = function(prev, input2, message, nowTs) {
47534
+ var base = getIncrementalSegments(prev, input2, nowTs);
47535
+ var fullSegments = base.segments;
47536
+ var readyCount = fullSegments.length;
47537
+ if (readyCount > 0 && !isOptimistic({
47538
+ id: message.id
47539
+ }) && message.status === "in_progress") {
47540
+ var last3 = fullSegments[fullSegments.length - 1];
47541
+ if (last3 && !FULL_SENTENCE_REGEX.test(last3)) readyCount -= 1;
47542
+ }
47543
+ var readySegments = fullSegments.slice(0, Math.max(0, readyCount));
47544
+ var playable = readyCount === fullSegments.length ? fullSegments : readySegments;
47545
+ return {
47546
+ entry: {
47547
+ input: base.input,
47548
+ segments: base.segments,
47549
+ touched: nowTs
47550
+ },
47551
+ playable: playable
47552
+ };
47553
+ };
47533
47554
  var segmentsEqual = function(a, b) {
47534
47555
  if (a === b) return true;
47535
47556
  if (a.length !== b.length) return false;
@@ -47568,16 +47589,6 @@ var useMessageAudio = function(_ref) {
47568
47589
  setIsAudioPlayed(true);
47569
47590
  }
47570
47591
  }, []);
47571
- var segmentToText = (0, import_react67.useCallback)(function(segment) {
47572
- if (typeof segment === "string") return segment;
47573
- if (segment && (typeof segment === "undefined" ? "undefined" : _type_of(segment)) === "object" && "text" in segment) {
47574
- var value = segment.text;
47575
- if (typeof value === "string") return value;
47576
- }
47577
- if (segment == null) return void 0;
47578
- var stringified = String(segment);
47579
- return stringified.length > 0 ? stringified : void 0;
47580
- }, []);
47581
47592
  var checkForCompletion = (0, import_react67.useCallback)(function() {
47582
47593
  if (activeSegmentsRef.current > 0) return;
47583
47594
  var hasPending = audioQueueRef.current.some(function(m) {
@@ -47600,7 +47611,7 @@ var useMessageAudio = function(_ref) {
47600
47611
  }
47601
47612
  var run = /* @__PURE__ */ function() {
47602
47613
  var _ref2 = _asyncToGenerator11(function() {
47603
- var assistantsDesc, assistantsAsc, nowTs, lastNIds, prevQueue, prevById, prevUnfinishedIds, streamingIds, includeIds, segCache, nextQueue, changed, touch, i, _existing$nextIndex, _existing$stopped, m_6, rawInput, prevEntry, nextEntry, playableSegments, customSegments, safeSegments, base, fullSegments, readyCount, last3, readySegments, existing, nextIndex, stopped, reuse, unfinished, finished, prunedFinished, combined, i_0, idsInQueue, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, id_3, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, id_4, entries, toRemove, i_1;
47614
+ var assistantsDesc, assistantsAsc, nowTs, lastNIds, prevQueue, prevById, prevUnfinishedIds, streamingIds, includeIds, segCache, nextQueue, changed, touch, i, _existing$nextIndex, _existing$stopped, m_6, input2, prevEntry, nextEntry, playableSegments, customSegments, safeSegments, _getDefaultSegments, entry_0, playable, existing, nextIndex, stopped, reuse, unfinished, finished, prunedFinished, combined, i_0, idsInQueue, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, id_3, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, id_4, entries, toRemove, i_1;
47604
47615
  return _ts_generator(this, function(_state) {
47605
47616
  switch(_state.label){
47606
47617
  case 0:
@@ -47661,10 +47672,10 @@ var useMessageAudio = function(_ref) {
47661
47672
  3,
47662
47673
  5
47663
47674
  ];
47664
- rawInput = input({
47675
+ input2 = input({
47665
47676
  message: m_6
47666
47677
  });
47667
- if (rawInput == null) {
47678
+ if (input2 == null) {
47668
47679
  segCache.delete(m_6.id);
47669
47680
  messagesByIdRef.current.delete(m_6.id);
47670
47681
  return [
@@ -47684,14 +47695,14 @@ var useMessageAudio = function(_ref) {
47684
47695
  4,
47685
47696
  Promise.resolve(providedGetSegments({
47686
47697
  message: m_6,
47687
- rawInput: rawInput
47698
+ input: input2
47688
47699
  }))
47689
47700
  ];
47690
47701
  case 2:
47691
47702
  customSegments = _state.sent();
47692
47703
  safeSegments = Array.isArray(customSegments) ? customSegments : [];
47693
47704
  nextEntry = {
47694
- input: rawInput,
47705
+ input: input2,
47695
47706
  segments: safeSegments,
47696
47707
  touched: nowTs
47697
47708
  };
@@ -47701,29 +47712,16 @@ var useMessageAudio = function(_ref) {
47701
47712
  4
47702
47713
  ];
47703
47714
  case 3:
47704
- base = getIncrementalSegments(prevEntry, rawInput, nowTs);
47705
- nextEntry = {
47706
- input: base.input,
47707
- segments: base.segments,
47708
- touched: nowTs
47709
- };
47710
- fullSegments = base.segments;
47711
- readyCount = fullSegments.length;
47712
- if (readyCount > 0 && !isOptimistic({
47713
- id: m_6.id
47714
- }) && m_6.status === "in_progress") {
47715
- last3 = fullSegments[fullSegments.length - 1];
47716
- if (last3 && !FULL_SENTENCE_REGEX.test(last3)) readyCount -= 1;
47717
- }
47718
- readySegments = fullSegments.slice(0, Math.max(0, readyCount));
47719
- playableSegments = readyCount === fullSegments.length ? fullSegments : readySegments;
47715
+ _getDefaultSegments = getDefaultSegments(prevEntry, input2, m_6, nowTs), entry_0 = _getDefaultSegments.entry, playable = _getDefaultSegments.playable;
47716
+ nextEntry = entry_0;
47717
+ playableSegments = playable;
47720
47718
  _state.label = 4;
47721
47719
  case 4:
47722
47720
  touch(m_6.id, nextEntry);
47723
47721
  existing = prevById.get(m_6.id);
47724
47722
  nextIndex = Math.min((_existing$nextIndex = existing === null || existing === void 0 ? void 0 : existing.nextIndex) !== null && _existing$nextIndex !== void 0 ? _existing$nextIndex : 0, playableSegments.length);
47725
47723
  stopped = (_existing$stopped = existing === null || existing === void 0 ? void 0 : existing.stopped) !== null && _existing$stopped !== void 0 ? _existing$stopped : false;
47726
- reuse = !!existing && existing.status === m_6.status && existing.rawInput === rawInput && existing.nextIndex === nextIndex && existing.stopped === stopped && segmentsEqual(existing.segments, playableSegments);
47724
+ reuse = !!existing && existing.status === m_6.status && existing.messageInput === input2 && existing.nextIndex === nextIndex && existing.stopped === stopped && segmentsEqual(existing.segments, playableSegments);
47727
47725
  if (reuse) {
47728
47726
  nextQueue.push(existing);
47729
47727
  } else {
@@ -47733,7 +47731,7 @@ var useMessageAudio = function(_ref) {
47733
47731
  segments: playableSegments,
47734
47732
  nextIndex: nextIndex,
47735
47733
  stopped: stopped,
47736
- rawInput: rawInput
47734
+ messageInput: input2
47737
47735
  });
47738
47736
  changed = true;
47739
47737
  }
@@ -47886,13 +47884,13 @@ var useMessageAudio = function(_ref) {
47886
47884
  ]);
47887
47885
  var defaultPlay = (0, import_react67.useCallback)(/* @__PURE__ */ function() {
47888
47886
  var _ref5 = _asyncToGenerator11(function(_ref4) {
47889
- var input2, onPlay, onStop, onEnd_0, searchParams;
47887
+ var input_0, onPlay, onStop, onEnd_0, searchParams;
47890
47888
  return _ts_generator(this, function(_state) {
47891
47889
  switch(_state.label){
47892
47890
  case 0:
47893
- input2 = _ref4.input, onPlay = _ref4.onPlay, onStop = _ref4.onStop, onEnd_0 = _ref4.onEnd;
47891
+ input_0 = _ref4.input, onPlay = _ref4.onPlay, onStop = _ref4.onStop, onEnd_0 = _ref4.onEnd;
47894
47892
  searchParams = new URLSearchParams(_objectSpread47({
47895
- input: input2
47893
+ input: input_0
47896
47894
  }, superinterfaceContext.variables));
47897
47895
  return [
47898
47896
  4,
@@ -47927,10 +47925,8 @@ var useMessageAudio = function(_ref) {
47927
47925
  if (!owner) return;
47928
47926
  var nextSegment = owner.segments[current.nextIndex];
47929
47927
  if (!nextSegment) return;
47930
- var nextText = segmentToText(nextSegment);
47931
- if (!nextText) return;
47932
47928
  var nextSearchParams = new URLSearchParams(_objectSpread47({
47933
- input: nextText
47929
+ input: nextSegment
47934
47930
  }, superinterfaceContext.variables));
47935
47931
  nextAudioPlayer.load("".concat(superinterfaceContext.baseUrl, "/audio-runtimes/tts?").concat(nextSearchParams), {
47936
47932
  format: "mp3",
@@ -47956,37 +47952,28 @@ var useMessageAudio = function(_ref) {
47956
47952
  audioPlayer,
47957
47953
  nextAudioPlayer,
47958
47954
  superinterfaceContext,
47959
- segmentToText
47955
+ markAudioPlayed
47960
47956
  ]);
47961
47957
  var playInternal = (0, import_react67.useCallback)(/* @__PURE__ */ function() {
47962
- var _ref6 = _asyncToGenerator11(function(segment_0, handlers2) {
47963
- var text, args;
47958
+ var _ref6 = _asyncToGenerator11(function(segment, handlers2) {
47964
47959
  return _ts_generator(this, function(_state) {
47965
47960
  switch(_state.label){
47966
47961
  case 0:
47967
- text = segmentToText(segment_0);
47968
- if (!text) {
47969
- handlers2.onEnd();
47970
- return [
47971
- 2
47972
- ];
47973
- }
47974
- args = {
47975
- input: text,
47976
- onPlay: function() {
47977
- markAudioPlayed();
47978
- handlers2.onPlay();
47979
- },
47980
- onStop: handlers2.onStop,
47981
- onEnd: handlers2.onEnd
47982
- };
47983
47962
  if (!providedPlay) return [
47984
47963
  3,
47985
47964
  2
47986
47965
  ];
47987
47966
  return [
47988
47967
  4,
47989
- Promise.resolve(providedPlay(args))
47968
+ Promise.resolve(providedPlay({
47969
+ input: segment,
47970
+ onPlay: function() {
47971
+ markAudioPlayed();
47972
+ handlers2.onPlay();
47973
+ },
47974
+ onStop: handlers2.onStop,
47975
+ onEnd: handlers2.onEnd
47976
+ }))
47990
47977
  ];
47991
47978
  case 1:
47992
47979
  _state.sent();
@@ -47996,7 +47983,12 @@ var useMessageAudio = function(_ref) {
47996
47983
  case 2:
47997
47984
  return [
47998
47985
  4,
47999
- defaultPlay(args)
47986
+ defaultPlay({
47987
+ input: segment,
47988
+ onPlay: handlers2.onPlay,
47989
+ onStop: handlers2.onStop,
47990
+ onEnd: handlers2.onEnd
47991
+ })
48000
47992
  ];
48001
47993
  case 3:
48002
47994
  _state.sent();
@@ -48010,7 +48002,6 @@ var useMessageAudio = function(_ref) {
48010
48002
  return _ref6.apply(this, arguments);
48011
48003
  };
48012
48004
  }(), [
48013
- segmentToText,
48014
48005
  providedPlay,
48015
48006
  defaultPlay,
48016
48007
  markAudioPlayed
@@ -48061,7 +48052,7 @@ var useMessageAudio = function(_ref) {
48061
48052
  };
48062
48053
  }(), []);
48063
48054
  var playSegmentsImpl = (0, import_react67.useCallback)(/* @__PURE__ */ function() {
48064
- var _ref9 = _asyncToGenerator11(function(args_0) {
48055
+ var _ref9 = _asyncToGenerator11(function(args) {
48065
48056
  return _ts_generator(this, function(_state) {
48066
48057
  switch(_state.label){
48067
48058
  case 0:
@@ -48071,7 +48062,7 @@ var useMessageAudio = function(_ref) {
48071
48062
  ];
48072
48063
  return [
48073
48064
  4,
48074
- Promise.resolve(providedPlaySegments(args_0))
48065
+ Promise.resolve(providedPlaySegments(args))
48075
48066
  ];
48076
48067
  case 1:
48077
48068
  _state.sent();
@@ -48081,7 +48072,7 @@ var useMessageAudio = function(_ref) {
48081
48072
  case 2:
48082
48073
  return [
48083
48074
  4,
48084
- defaultPlaySegments(args_0)
48075
+ defaultPlaySegments(args)
48085
48076
  ];
48086
48077
  case 3:
48087
48078
  _state.sent();
@@ -48139,7 +48130,7 @@ var useMessageAudio = function(_ref) {
48139
48130
  candidate = {
48140
48131
  messageId: msg.id,
48141
48132
  message: message_0,
48142
- rawInput: msg.rawInput,
48133
+ messageInput: msg.messageInput,
48143
48134
  startIndex: msg.nextIndex,
48144
48135
  segments: msg.segments.slice(msg.nextIndex)
48145
48136
  };
@@ -48177,7 +48168,7 @@ var useMessageAudio = function(_ref) {
48177
48168
  startIndex: candidate.startIndex,
48178
48169
  message: candidate.message,
48179
48170
  play: function() {
48180
- var _play = _asyncToGenerator11(function(segment_1) {
48171
+ var _play = _asyncToGenerator11(function(segment_0) {
48181
48172
  return _ts_generator(this, function(_state) {
48182
48173
  switch(_state.label){
48183
48174
  case 0:
@@ -48189,7 +48180,7 @@ var useMessageAudio = function(_ref) {
48189
48180
  };
48190
48181
  return [
48191
48182
  4,
48192
- playInternal(segment_1, {
48183
+ playInternal(segment_0, {
48193
48184
  onPlay: function() {},
48194
48185
  onStop: function() {
48195
48186
  return handleStop(candidate.messageId);