@superinterface/react 5.3.0-beta.5 → 5.3.0-beta.7
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 +96 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +96 -59
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
package/dist/index.cjs
CHANGED
|
@@ -47446,8 +47446,25 @@ var hasLetters = function(s) {
|
|
|
47446
47446
|
}
|
|
47447
47447
|
return false;
|
|
47448
47448
|
};
|
|
47449
|
-
var
|
|
47450
|
-
|
|
47449
|
+
var isSentencePunct = function(ch) {
|
|
47450
|
+
return ch === "." || ch === "!" || ch === "?" || ch === "\u3002" || ch === "\uFF01" || ch === "\uFF1F";
|
|
47451
|
+
};
|
|
47452
|
+
var normalizeBoundaries = function(text) {
|
|
47453
|
+
var out = "";
|
|
47454
|
+
for(var i = 0; i < text.length; i++){
|
|
47455
|
+
var ch = text.charAt(i);
|
|
47456
|
+
out += ch;
|
|
47457
|
+
if (isSentencePunct(ch)) {
|
|
47458
|
+
var next = text.charAt(i + 1);
|
|
47459
|
+
if (next && next !== " " && hasLetters(next)) {
|
|
47460
|
+
out += " ";
|
|
47461
|
+
}
|
|
47462
|
+
}
|
|
47463
|
+
}
|
|
47464
|
+
return out;
|
|
47465
|
+
};
|
|
47466
|
+
var splitSentencesFast = function(raw) {
|
|
47467
|
+
var t = normalizeBoundaries(raw.replace(/\s+/g, " ").trim());
|
|
47451
47468
|
if (!t) return [];
|
|
47452
47469
|
var parts = t.split(RegExp("(?<=[.!?])\\s+(?=[^\\s])", "g"));
|
|
47453
47470
|
var filtered = [];
|
|
@@ -47520,23 +47537,9 @@ var useMessageAudio = function(_ref) {
|
|
|
47520
47537
|
});
|
|
47521
47538
|
var assistantsAsc = assistantsDesc.slice().reverse();
|
|
47522
47539
|
var nowTs = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
|
|
47523
|
-
var
|
|
47524
|
-
|
|
47525
|
-
|
|
47526
|
-
input: entry.input,
|
|
47527
|
-
sentences: entry.sentences,
|
|
47528
|
-
touched: nowTs
|
|
47529
|
-
});
|
|
47530
|
-
};
|
|
47531
|
-
var evictLRU = function() {
|
|
47532
|
-
if (segCache.size <= MAX_SEG_CACHE) return;
|
|
47533
|
-
var entries = Array.from(segCache.entries());
|
|
47534
|
-
entries.sort(function(a, b) {
|
|
47535
|
-
return a[1].touched - b[1].touched;
|
|
47536
|
-
});
|
|
47537
|
-
var toRemove = segCache.size - MAX_SEG_CACHE;
|
|
47538
|
-
for(var i = 0; i < toRemove; i++)segCache.delete(entries[i][0]);
|
|
47539
|
-
};
|
|
47540
|
+
var lastNIds = new Set(assistantsAsc.slice(Math.max(0, assistantsAsc.length - KEEP_FINISHED_MESSAGES)).map(function(m_0) {
|
|
47541
|
+
return m_0.id;
|
|
47542
|
+
}));
|
|
47540
47543
|
setAudioQueue(function(prev) {
|
|
47541
47544
|
var prevById = new Map(prev.map(function(p) {
|
|
47542
47545
|
return [
|
|
@@ -47544,33 +47547,71 @@ var useMessageAudio = function(_ref) {
|
|
|
47544
47547
|
p
|
|
47545
47548
|
];
|
|
47546
47549
|
}));
|
|
47550
|
+
var prevUnfinishedIds = new Set(prev.filter(function(m_1) {
|
|
47551
|
+
return !m_1.stopped && (m_1.status === "in_progress" || m_1.nextIndex < m_1.sentences.length);
|
|
47552
|
+
}).map(function(m_2) {
|
|
47553
|
+
return m_2.id;
|
|
47554
|
+
}));
|
|
47555
|
+
var streamingIds = new Set(assistantsAsc.filter(function(m_3) {
|
|
47556
|
+
return m_3.status === "in_progress";
|
|
47557
|
+
}).map(function(m_4) {
|
|
47558
|
+
return m_4.id;
|
|
47559
|
+
}));
|
|
47560
|
+
var includeIds = /* @__PURE__ */ new Set();
|
|
47561
|
+
lastNIds.forEach(function(id) {
|
|
47562
|
+
return includeIds.add(String(id));
|
|
47563
|
+
});
|
|
47564
|
+
prevUnfinishedIds.forEach(function(id_0) {
|
|
47565
|
+
return includeIds.add(id_0);
|
|
47566
|
+
});
|
|
47567
|
+
streamingIds.forEach(function(id_1) {
|
|
47568
|
+
return includeIds.add(String(id_1));
|
|
47569
|
+
});
|
|
47570
|
+
var segCache = segCacheRef.current;
|
|
47571
|
+
var touch = function(id_2, entry) {
|
|
47572
|
+
segCache.set(id_2, {
|
|
47573
|
+
input: entry.input,
|
|
47574
|
+
sentences: entry.sentences,
|
|
47575
|
+
touched: nowTs
|
|
47576
|
+
});
|
|
47577
|
+
};
|
|
47578
|
+
var evictLRU = function() {
|
|
47579
|
+
if (segCache.size <= MAX_SEG_CACHE) return;
|
|
47580
|
+
var entries = Array.from(segCache.entries());
|
|
47581
|
+
entries.sort(function(a, b) {
|
|
47582
|
+
return a[1].touched - b[1].touched;
|
|
47583
|
+
});
|
|
47584
|
+
var toRemove = segCache.size - MAX_SEG_CACHE;
|
|
47585
|
+
for(var i = 0; i < toRemove; i++)segCache.delete(entries[i][0]);
|
|
47586
|
+
};
|
|
47547
47587
|
var next = [];
|
|
47548
47588
|
var changed = false;
|
|
47549
47589
|
for(var i_0 = 0; i_0 < assistantsAsc.length; i_0++){
|
|
47550
47590
|
var _existing$nextIndex, _existing$stopped;
|
|
47551
|
-
var
|
|
47591
|
+
var m_5 = assistantsAsc[i_0];
|
|
47592
|
+
if (!includeIds.has(m_5.id)) continue;
|
|
47552
47593
|
var inp = input({
|
|
47553
|
-
message:
|
|
47594
|
+
message: m_5
|
|
47554
47595
|
});
|
|
47555
47596
|
if (inp == null) continue;
|
|
47556
|
-
var prevSeg = segCache.get(
|
|
47597
|
+
var prevSeg = segCache.get(m_5.id);
|
|
47557
47598
|
var nextSeg = getIncrementalSentences(prevSeg, inp, nowTs);
|
|
47558
47599
|
if (!prevSeg || nextSeg.input !== prevSeg.input || nextSeg.sentences !== prevSeg.sentences) {
|
|
47559
|
-
touch(
|
|
47600
|
+
touch(m_5.id, nextSeg);
|
|
47560
47601
|
} else {
|
|
47561
|
-
touch(
|
|
47602
|
+
touch(m_5.id, prevSeg);
|
|
47562
47603
|
}
|
|
47563
|
-
var existing = prevById.get(
|
|
47604
|
+
var existing = prevById.get(m_5.id);
|
|
47564
47605
|
var sentences = nextSeg.sentences;
|
|
47565
47606
|
var nextIndex = Math.min((_existing$nextIndex = existing === null || existing === void 0 ? void 0 : existing.nextIndex) !== null && _existing$nextIndex !== void 0 ? _existing$nextIndex : 0, sentences.length);
|
|
47566
47607
|
var stopped = (_existing$stopped = existing === null || existing === void 0 ? void 0 : existing.stopped) !== null && _existing$stopped !== void 0 ? _existing$stopped : false;
|
|
47567
|
-
var reuse = !!existing && existing.status ===
|
|
47608
|
+
var reuse = !!existing && existing.status === m_5.status && existing.sentences === sentences && existing.nextIndex === nextIndex && existing.stopped === stopped;
|
|
47568
47609
|
if (reuse) {
|
|
47569
47610
|
next.push(existing);
|
|
47570
47611
|
} else {
|
|
47571
47612
|
next.push({
|
|
47572
|
-
id:
|
|
47573
|
-
status:
|
|
47613
|
+
id: m_5.id,
|
|
47614
|
+
status: m_5.status,
|
|
47574
47615
|
sentences: sentences,
|
|
47575
47616
|
nextIndex: nextIndex,
|
|
47576
47617
|
stopped: stopped
|
|
@@ -47578,37 +47619,33 @@ var useMessageAudio = function(_ref) {
|
|
|
47578
47619
|
changed = true;
|
|
47579
47620
|
}
|
|
47580
47621
|
}
|
|
47581
|
-
var unfinished =
|
|
47582
|
-
|
|
47583
|
-
|
|
47584
|
-
|
|
47585
|
-
|
|
47586
|
-
|
|
47587
|
-
} else {
|
|
47588
|
-
finished.push(m_1);
|
|
47589
|
-
}
|
|
47590
|
-
}
|
|
47622
|
+
var unfinished = next.filter(function(m_6) {
|
|
47623
|
+
return !m_6.stopped && (m_6.status === "in_progress" || m_6.nextIndex < m_6.sentences.length);
|
|
47624
|
+
});
|
|
47625
|
+
var finished = next.filter(function(m_7) {
|
|
47626
|
+
return !(!m_7.stopped && (m_7.status === "in_progress" || m_7.nextIndex < m_7.sentences.length));
|
|
47627
|
+
});
|
|
47591
47628
|
var prunedFinished = finished.length > KEEP_FINISHED_MESSAGES ? finished.slice(finished.length - KEEP_FINISHED_MESSAGES) : finished;
|
|
47592
|
-
var combined = unfinished.concat(prunedFinished);
|
|
47629
|
+
var combined = _to_consumable_array(unfinished).concat(_to_consumable_array(prunedFinished));
|
|
47593
47630
|
if (!changed) {
|
|
47594
47631
|
if (combined.length !== prev.length) changed = true;
|
|
47595
47632
|
else {
|
|
47596
|
-
for(var
|
|
47597
|
-
if (combined[
|
|
47633
|
+
for(var i_1 = 0; i_1 < combined.length; i_1++){
|
|
47634
|
+
if (combined[i_1] !== prev[i_1]) {
|
|
47598
47635
|
changed = true;
|
|
47599
47636
|
break;
|
|
47600
47637
|
}
|
|
47601
47638
|
}
|
|
47602
47639
|
}
|
|
47603
47640
|
}
|
|
47604
|
-
var idsInQueue = new Set(combined.map(function(
|
|
47605
|
-
return
|
|
47641
|
+
var idsInQueue = new Set(combined.map(function(m_8) {
|
|
47642
|
+
return m_8.id;
|
|
47606
47643
|
}));
|
|
47607
47644
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
47608
47645
|
try {
|
|
47609
47646
|
for(var _iterator = Array.from(segCache.keys())[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
47610
|
-
var
|
|
47611
|
-
if (!idsInQueue.has(
|
|
47647
|
+
var id_3 = _step.value;
|
|
47648
|
+
if (!idsInQueue.has(id_3)) segCache.delete(id_3);
|
|
47612
47649
|
}
|
|
47613
47650
|
} catch (err) {
|
|
47614
47651
|
_didIteratorError = true;
|
|
@@ -47658,8 +47695,8 @@ var useMessageAudio = function(_ref) {
|
|
|
47658
47695
|
onload: function() {
|
|
47659
47696
|
var current = currentSentenceRef.current;
|
|
47660
47697
|
if (!current) return;
|
|
47661
|
-
var msg = audioQueueRef.current.find(function(
|
|
47662
|
-
return
|
|
47698
|
+
var msg = audioQueueRef.current.find(function(m_9) {
|
|
47699
|
+
return m_9.id === current.messageId;
|
|
47663
47700
|
});
|
|
47664
47701
|
if (!msg) return;
|
|
47665
47702
|
var nextSentence = msg.sentences[msg.nextIndex];
|
|
@@ -47721,10 +47758,10 @@ var useMessageAudio = function(_ref) {
|
|
|
47721
47758
|
index: candidate.index
|
|
47722
47759
|
};
|
|
47723
47760
|
setAudioQueue(function(prev_0) {
|
|
47724
|
-
return prev_0.map(function(
|
|
47725
|
-
return
|
|
47761
|
+
return prev_0.map(function(m_10) {
|
|
47762
|
+
return m_10.id === candidate.messageId ? _objectSpread47(_objectSpread47({}, m_10), {}, {
|
|
47726
47763
|
nextIndex: candidate.index + 1
|
|
47727
|
-
}) :
|
|
47764
|
+
}) : m_10;
|
|
47728
47765
|
});
|
|
47729
47766
|
});
|
|
47730
47767
|
play({
|
|
@@ -47734,10 +47771,10 @@ var useMessageAudio = function(_ref) {
|
|
|
47734
47771
|
},
|
|
47735
47772
|
onStop: function() {
|
|
47736
47773
|
setAudioQueue(function(prev_1) {
|
|
47737
|
-
return prev_1.map(function(
|
|
47738
|
-
return
|
|
47774
|
+
return prev_1.map(function(m_11) {
|
|
47775
|
+
return m_11.id === candidate.messageId ? _objectSpread47(_objectSpread47({}, m_11), {}, {
|
|
47739
47776
|
stopped: true
|
|
47740
|
-
}) :
|
|
47777
|
+
}) : m_11;
|
|
47741
47778
|
});
|
|
47742
47779
|
});
|
|
47743
47780
|
setIsPlaying(false);
|
|
@@ -47748,10 +47785,10 @@ var useMessageAudio = function(_ref) {
|
|
|
47748
47785
|
setIsPlaying(false);
|
|
47749
47786
|
currentSentenceRef.current = null;
|
|
47750
47787
|
pickLockRef.current = false;
|
|
47751
|
-
var hasPending = audioQueueRef.current.some(function(
|
|
47752
|
-
if (
|
|
47753
|
-
var hasMore =
|
|
47754
|
-
var streaming =
|
|
47788
|
+
var hasPending = audioQueueRef.current.some(function(m_12) {
|
|
47789
|
+
if (m_12.stopped) return false;
|
|
47790
|
+
var hasMore = m_12.nextIndex < m_12.sentences.length;
|
|
47791
|
+
var streaming = m_12.status === "in_progress";
|
|
47755
47792
|
return hasMore || streaming;
|
|
47756
47793
|
});
|
|
47757
47794
|
if (!hasPending) _onEnd();
|
|
@@ -47811,8 +47848,8 @@ var useMessageAudio = function(_ref) {
|
|
|
47811
47848
|
audioEngine
|
|
47812
47849
|
]);
|
|
47813
47850
|
var isPending = (0, import_react67.useMemo)(function() {
|
|
47814
|
-
return isPlaying || audioQueue.some(function(
|
|
47815
|
-
return !
|
|
47851
|
+
return isPlaying || audioQueue.some(function(m_13) {
|
|
47852
|
+
return !m_13.stopped && (m_13.nextIndex < m_13.sentences.length || m_13.status === "in_progress");
|
|
47816
47853
|
});
|
|
47817
47854
|
}, [
|
|
47818
47855
|
isPlaying,
|