@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.js
CHANGED
|
@@ -47297,8 +47297,25 @@ var hasLetters = function(s) {
|
|
|
47297
47297
|
}
|
|
47298
47298
|
return false;
|
|
47299
47299
|
};
|
|
47300
|
-
var
|
|
47301
|
-
|
|
47300
|
+
var isSentencePunct = function(ch) {
|
|
47301
|
+
return ch === "." || ch === "!" || ch === "?" || ch === "\u3002" || ch === "\uFF01" || ch === "\uFF1F";
|
|
47302
|
+
};
|
|
47303
|
+
var normalizeBoundaries = function(text) {
|
|
47304
|
+
var out = "";
|
|
47305
|
+
for(var i = 0; i < text.length; i++){
|
|
47306
|
+
var ch = text.charAt(i);
|
|
47307
|
+
out += ch;
|
|
47308
|
+
if (isSentencePunct(ch)) {
|
|
47309
|
+
var next = text.charAt(i + 1);
|
|
47310
|
+
if (next && next !== " " && hasLetters(next)) {
|
|
47311
|
+
out += " ";
|
|
47312
|
+
}
|
|
47313
|
+
}
|
|
47314
|
+
}
|
|
47315
|
+
return out;
|
|
47316
|
+
};
|
|
47317
|
+
var splitSentencesFast = function(raw) {
|
|
47318
|
+
var t = normalizeBoundaries(raw.replace(/\s+/g, " ").trim());
|
|
47302
47319
|
if (!t) return [];
|
|
47303
47320
|
var parts = t.split(RegExp("(?<=[.!?])\\s+(?=[^\\s])", "g"));
|
|
47304
47321
|
var filtered = [];
|
|
@@ -47371,23 +47388,9 @@ var useMessageAudio = function(_ref) {
|
|
|
47371
47388
|
});
|
|
47372
47389
|
var assistantsAsc = assistantsDesc.slice().reverse();
|
|
47373
47390
|
var nowTs = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
|
|
47374
|
-
var
|
|
47375
|
-
|
|
47376
|
-
|
|
47377
|
-
input: entry.input,
|
|
47378
|
-
sentences: entry.sentences,
|
|
47379
|
-
touched: nowTs
|
|
47380
|
-
});
|
|
47381
|
-
};
|
|
47382
|
-
var evictLRU = function() {
|
|
47383
|
-
if (segCache.size <= MAX_SEG_CACHE) return;
|
|
47384
|
-
var entries = Array.from(segCache.entries());
|
|
47385
|
-
entries.sort(function(a, b) {
|
|
47386
|
-
return a[1].touched - b[1].touched;
|
|
47387
|
-
});
|
|
47388
|
-
var toRemove = segCache.size - MAX_SEG_CACHE;
|
|
47389
|
-
for(var i = 0; i < toRemove; i++)segCache.delete(entries[i][0]);
|
|
47390
|
-
};
|
|
47391
|
+
var lastNIds = new Set(assistantsAsc.slice(Math.max(0, assistantsAsc.length - KEEP_FINISHED_MESSAGES)).map(function(m_0) {
|
|
47392
|
+
return m_0.id;
|
|
47393
|
+
}));
|
|
47391
47394
|
setAudioQueue(function(prev) {
|
|
47392
47395
|
var prevById = new Map(prev.map(function(p) {
|
|
47393
47396
|
return [
|
|
@@ -47395,33 +47398,71 @@ var useMessageAudio = function(_ref) {
|
|
|
47395
47398
|
p
|
|
47396
47399
|
];
|
|
47397
47400
|
}));
|
|
47401
|
+
var prevUnfinishedIds = new Set(prev.filter(function(m_1) {
|
|
47402
|
+
return !m_1.stopped && (m_1.status === "in_progress" || m_1.nextIndex < m_1.sentences.length);
|
|
47403
|
+
}).map(function(m_2) {
|
|
47404
|
+
return m_2.id;
|
|
47405
|
+
}));
|
|
47406
|
+
var streamingIds = new Set(assistantsAsc.filter(function(m_3) {
|
|
47407
|
+
return m_3.status === "in_progress";
|
|
47408
|
+
}).map(function(m_4) {
|
|
47409
|
+
return m_4.id;
|
|
47410
|
+
}));
|
|
47411
|
+
var includeIds = /* @__PURE__ */ new Set();
|
|
47412
|
+
lastNIds.forEach(function(id) {
|
|
47413
|
+
return includeIds.add(String(id));
|
|
47414
|
+
});
|
|
47415
|
+
prevUnfinishedIds.forEach(function(id_0) {
|
|
47416
|
+
return includeIds.add(id_0);
|
|
47417
|
+
});
|
|
47418
|
+
streamingIds.forEach(function(id_1) {
|
|
47419
|
+
return includeIds.add(String(id_1));
|
|
47420
|
+
});
|
|
47421
|
+
var segCache = segCacheRef.current;
|
|
47422
|
+
var touch = function(id_2, entry) {
|
|
47423
|
+
segCache.set(id_2, {
|
|
47424
|
+
input: entry.input,
|
|
47425
|
+
sentences: entry.sentences,
|
|
47426
|
+
touched: nowTs
|
|
47427
|
+
});
|
|
47428
|
+
};
|
|
47429
|
+
var evictLRU = function() {
|
|
47430
|
+
if (segCache.size <= MAX_SEG_CACHE) return;
|
|
47431
|
+
var entries = Array.from(segCache.entries());
|
|
47432
|
+
entries.sort(function(a, b) {
|
|
47433
|
+
return a[1].touched - b[1].touched;
|
|
47434
|
+
});
|
|
47435
|
+
var toRemove = segCache.size - MAX_SEG_CACHE;
|
|
47436
|
+
for(var i = 0; i < toRemove; i++)segCache.delete(entries[i][0]);
|
|
47437
|
+
};
|
|
47398
47438
|
var next = [];
|
|
47399
47439
|
var changed = false;
|
|
47400
47440
|
for(var i_0 = 0; i_0 < assistantsAsc.length; i_0++){
|
|
47401
47441
|
var _existing$nextIndex, _existing$stopped;
|
|
47402
|
-
var
|
|
47442
|
+
var m_5 = assistantsAsc[i_0];
|
|
47443
|
+
if (!includeIds.has(m_5.id)) continue;
|
|
47403
47444
|
var inp = input({
|
|
47404
|
-
message:
|
|
47445
|
+
message: m_5
|
|
47405
47446
|
});
|
|
47406
47447
|
if (inp == null) continue;
|
|
47407
|
-
var prevSeg = segCache.get(
|
|
47448
|
+
var prevSeg = segCache.get(m_5.id);
|
|
47408
47449
|
var nextSeg = getIncrementalSentences(prevSeg, inp, nowTs);
|
|
47409
47450
|
if (!prevSeg || nextSeg.input !== prevSeg.input || nextSeg.sentences !== prevSeg.sentences) {
|
|
47410
|
-
touch(
|
|
47451
|
+
touch(m_5.id, nextSeg);
|
|
47411
47452
|
} else {
|
|
47412
|
-
touch(
|
|
47453
|
+
touch(m_5.id, prevSeg);
|
|
47413
47454
|
}
|
|
47414
|
-
var existing = prevById.get(
|
|
47455
|
+
var existing = prevById.get(m_5.id);
|
|
47415
47456
|
var sentences = nextSeg.sentences;
|
|
47416
47457
|
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);
|
|
47417
47458
|
var stopped = (_existing$stopped = existing === null || existing === void 0 ? void 0 : existing.stopped) !== null && _existing$stopped !== void 0 ? _existing$stopped : false;
|
|
47418
|
-
var reuse = !!existing && existing.status ===
|
|
47459
|
+
var reuse = !!existing && existing.status === m_5.status && existing.sentences === sentences && existing.nextIndex === nextIndex && existing.stopped === stopped;
|
|
47419
47460
|
if (reuse) {
|
|
47420
47461
|
next.push(existing);
|
|
47421
47462
|
} else {
|
|
47422
47463
|
next.push({
|
|
47423
|
-
id:
|
|
47424
|
-
status:
|
|
47464
|
+
id: m_5.id,
|
|
47465
|
+
status: m_5.status,
|
|
47425
47466
|
sentences: sentences,
|
|
47426
47467
|
nextIndex: nextIndex,
|
|
47427
47468
|
stopped: stopped
|
|
@@ -47429,37 +47470,33 @@ var useMessageAudio = function(_ref) {
|
|
|
47429
47470
|
changed = true;
|
|
47430
47471
|
}
|
|
47431
47472
|
}
|
|
47432
|
-
var unfinished =
|
|
47433
|
-
|
|
47434
|
-
|
|
47435
|
-
|
|
47436
|
-
|
|
47437
|
-
|
|
47438
|
-
} else {
|
|
47439
|
-
finished.push(m_1);
|
|
47440
|
-
}
|
|
47441
|
-
}
|
|
47473
|
+
var unfinished = next.filter(function(m_6) {
|
|
47474
|
+
return !m_6.stopped && (m_6.status === "in_progress" || m_6.nextIndex < m_6.sentences.length);
|
|
47475
|
+
});
|
|
47476
|
+
var finished = next.filter(function(m_7) {
|
|
47477
|
+
return !(!m_7.stopped && (m_7.status === "in_progress" || m_7.nextIndex < m_7.sentences.length));
|
|
47478
|
+
});
|
|
47442
47479
|
var prunedFinished = finished.length > KEEP_FINISHED_MESSAGES ? finished.slice(finished.length - KEEP_FINISHED_MESSAGES) : finished;
|
|
47443
|
-
var combined = unfinished.concat(prunedFinished);
|
|
47480
|
+
var combined = _to_consumable_array(unfinished).concat(_to_consumable_array(prunedFinished));
|
|
47444
47481
|
if (!changed) {
|
|
47445
47482
|
if (combined.length !== prev.length) changed = true;
|
|
47446
47483
|
else {
|
|
47447
|
-
for(var
|
|
47448
|
-
if (combined[
|
|
47484
|
+
for(var i_1 = 0; i_1 < combined.length; i_1++){
|
|
47485
|
+
if (combined[i_1] !== prev[i_1]) {
|
|
47449
47486
|
changed = true;
|
|
47450
47487
|
break;
|
|
47451
47488
|
}
|
|
47452
47489
|
}
|
|
47453
47490
|
}
|
|
47454
47491
|
}
|
|
47455
|
-
var idsInQueue = new Set(combined.map(function(
|
|
47456
|
-
return
|
|
47492
|
+
var idsInQueue = new Set(combined.map(function(m_8) {
|
|
47493
|
+
return m_8.id;
|
|
47457
47494
|
}));
|
|
47458
47495
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
47459
47496
|
try {
|
|
47460
47497
|
for(var _iterator = Array.from(segCache.keys())[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
47461
|
-
var
|
|
47462
|
-
if (!idsInQueue.has(
|
|
47498
|
+
var id_3 = _step.value;
|
|
47499
|
+
if (!idsInQueue.has(id_3)) segCache.delete(id_3);
|
|
47463
47500
|
}
|
|
47464
47501
|
} catch (err) {
|
|
47465
47502
|
_didIteratorError = true;
|
|
@@ -47509,8 +47546,8 @@ var useMessageAudio = function(_ref) {
|
|
|
47509
47546
|
onload: function() {
|
|
47510
47547
|
var current = currentSentenceRef.current;
|
|
47511
47548
|
if (!current) return;
|
|
47512
|
-
var msg = audioQueueRef.current.find(function(
|
|
47513
|
-
return
|
|
47549
|
+
var msg = audioQueueRef.current.find(function(m_9) {
|
|
47550
|
+
return m_9.id === current.messageId;
|
|
47514
47551
|
});
|
|
47515
47552
|
if (!msg) return;
|
|
47516
47553
|
var nextSentence = msg.sentences[msg.nextIndex];
|
|
@@ -47572,10 +47609,10 @@ var useMessageAudio = function(_ref) {
|
|
|
47572
47609
|
index: candidate.index
|
|
47573
47610
|
};
|
|
47574
47611
|
setAudioQueue(function(prev_0) {
|
|
47575
|
-
return prev_0.map(function(
|
|
47576
|
-
return
|
|
47612
|
+
return prev_0.map(function(m_10) {
|
|
47613
|
+
return m_10.id === candidate.messageId ? _objectSpread47(_objectSpread47({}, m_10), {}, {
|
|
47577
47614
|
nextIndex: candidate.index + 1
|
|
47578
|
-
}) :
|
|
47615
|
+
}) : m_10;
|
|
47579
47616
|
});
|
|
47580
47617
|
});
|
|
47581
47618
|
play({
|
|
@@ -47585,10 +47622,10 @@ var useMessageAudio = function(_ref) {
|
|
|
47585
47622
|
},
|
|
47586
47623
|
onStop: function() {
|
|
47587
47624
|
setAudioQueue(function(prev_1) {
|
|
47588
|
-
return prev_1.map(function(
|
|
47589
|
-
return
|
|
47625
|
+
return prev_1.map(function(m_11) {
|
|
47626
|
+
return m_11.id === candidate.messageId ? _objectSpread47(_objectSpread47({}, m_11), {}, {
|
|
47590
47627
|
stopped: true
|
|
47591
|
-
}) :
|
|
47628
|
+
}) : m_11;
|
|
47592
47629
|
});
|
|
47593
47630
|
});
|
|
47594
47631
|
setIsPlaying(false);
|
|
@@ -47599,10 +47636,10 @@ var useMessageAudio = function(_ref) {
|
|
|
47599
47636
|
setIsPlaying(false);
|
|
47600
47637
|
currentSentenceRef.current = null;
|
|
47601
47638
|
pickLockRef.current = false;
|
|
47602
|
-
var hasPending = audioQueueRef.current.some(function(
|
|
47603
|
-
if (
|
|
47604
|
-
var hasMore =
|
|
47605
|
-
var streaming =
|
|
47639
|
+
var hasPending = audioQueueRef.current.some(function(m_12) {
|
|
47640
|
+
if (m_12.stopped) return false;
|
|
47641
|
+
var hasMore = m_12.nextIndex < m_12.sentences.length;
|
|
47642
|
+
var streaming = m_12.status === "in_progress";
|
|
47606
47643
|
return hasMore || streaming;
|
|
47607
47644
|
});
|
|
47608
47645
|
if (!hasPending) _onEnd();
|
|
@@ -47662,8 +47699,8 @@ var useMessageAudio = function(_ref) {
|
|
|
47662
47699
|
audioEngine
|
|
47663
47700
|
]);
|
|
47664
47701
|
var isPending = useMemo17(function() {
|
|
47665
|
-
return isPlaying || audioQueue.some(function(
|
|
47666
|
-
return !
|
|
47702
|
+
return isPlaying || audioQueue.some(function(m_13) {
|
|
47703
|
+
return !m_13.stopped && (m_13.nextIndex < m_13.sentences.length || m_13.status === "in_progress");
|
|
47667
47704
|
});
|
|
47668
47705
|
}, [
|
|
47669
47706
|
isPlaying,
|