@superinterface/react 2.3.0 → 2.4.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 +48 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +44 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -385,6 +385,9 @@ __export(src_exports, {
|
|
|
385
385
|
},
|
|
386
386
|
useThreadContext: function() {
|
|
387
387
|
return useSuperinterfaceContext;
|
|
388
|
+
},
|
|
389
|
+
useThreadDialogContext: function() {
|
|
390
|
+
return useThreadDialogContext;
|
|
388
391
|
}
|
|
389
392
|
});
|
|
390
393
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -2982,33 +2985,57 @@ var unsupportedNames = [
|
|
|
2982
2985
|
];
|
|
2983
2986
|
var isHtmlAudioSupported = !unsupportedNames.includes(((_this = (0, import_detect_browser.detect)()) === null || _this === void 0 ? void 0 : _this.name) || "");
|
|
2984
2987
|
// src/hooks/audioThreads/useMessageAudio/index.ts
|
|
2988
|
+
var SPLIT_SENTENCE_REGEX = /[^\.\?!]+[\.\?!]/g;
|
|
2989
|
+
var FULL_SENTENCE_REGEX = /^\s*[A-Z].*[.?!]$/;
|
|
2990
|
+
var getMessageSentences = function(param) {
|
|
2991
|
+
var messageId = param.messageId, input2 = param.input;
|
|
2992
|
+
var sentences = input2.match(SPLIT_SENTENCE_REGEX) || [];
|
|
2993
|
+
return sentences.map(function(sentence) {
|
|
2994
|
+
return {
|
|
2995
|
+
messageId: messageId,
|
|
2996
|
+
sentence: sentence
|
|
2997
|
+
};
|
|
2998
|
+
});
|
|
2999
|
+
};
|
|
2985
3000
|
var useMessageAudio = function(param) {
|
|
2986
3001
|
var onEnd = param.onEnd;
|
|
2987
|
-
var _ref = _sliced_to_array((0, import_react40.useState)([]), 2),
|
|
3002
|
+
var _ref = _sliced_to_array((0, import_react40.useState)([]), 2), playedMessageSentences = _ref[0], setPlayedMessageSentences = _ref[1];
|
|
2988
3003
|
var audioPlayer = (0, import_react_use_audio_player2.useAudioPlayer)();
|
|
2989
3004
|
var superinterfaceContext = useSuperinterfaceContext();
|
|
3005
|
+
var _ref1 = _sliced_to_array((0, import_react40.useState)(false), 2), isPlaying = _ref1[0], setIsPlaying = _ref1[1];
|
|
2990
3006
|
var latestMessageProps = useLatestMessage();
|
|
2991
3007
|
(0, import_react40.useEffect)(function() {
|
|
3008
|
+
if (isPlaying) return;
|
|
2992
3009
|
if (audioPlayer.playing) return;
|
|
2993
3010
|
if (!latestMessageProps.latestMessage) return;
|
|
2994
3011
|
if (latestMessageProps.latestMessage.role !== "assistant") return;
|
|
2995
|
-
if (playedMessages.find(function(pm) {
|
|
2996
|
-
return pm.id === latestMessageProps.latestMessage.id || isOptimistic({
|
|
2997
|
-
id: pm.id
|
|
2998
|
-
}) && pm.content === latestMessageProps.latestMessage.content;
|
|
2999
|
-
})) return;
|
|
3000
|
-
if (playedMessages.includes(latestMessageProps.latestMessage)) return;
|
|
3001
3012
|
var input2 = input({
|
|
3002
3013
|
message: latestMessageProps.latestMessage
|
|
3003
3014
|
});
|
|
3004
3015
|
if (!input2) return;
|
|
3005
|
-
|
|
3016
|
+
var messageSentences = getMessageSentences({
|
|
3017
|
+
messageId: latestMessageProps.latestMessage.id,
|
|
3018
|
+
input: input2
|
|
3019
|
+
});
|
|
3020
|
+
var unplayedMessageSentences = messageSentences.filter(function(ms) {
|
|
3021
|
+
return !playedMessageSentences.find(function(pms) {
|
|
3022
|
+
return pms.messageId === ms.messageId && pms.sentence === ms.sentence;
|
|
3023
|
+
});
|
|
3024
|
+
});
|
|
3025
|
+
var firstUnplayedMessageSentence = unplayedMessageSentences[0];
|
|
3026
|
+
if (!firstUnplayedMessageSentence) {
|
|
3027
|
+
return;
|
|
3028
|
+
}
|
|
3029
|
+
var isFullSentence = FULL_SENTENCE_REGEX.test(firstUnplayedMessageSentence.sentence);
|
|
3030
|
+
if (!isFullSentence) return;
|
|
3031
|
+
setIsPlaying(true);
|
|
3032
|
+
setPlayedMessageSentences(function(prev) {
|
|
3006
3033
|
return _to_consumable_array(prev).concat([
|
|
3007
|
-
|
|
3034
|
+
firstUnplayedMessageSentence
|
|
3008
3035
|
]);
|
|
3009
3036
|
});
|
|
3010
3037
|
var searchParams = new URLSearchParams(_object_spread({
|
|
3011
|
-
input:
|
|
3038
|
+
input: firstUnplayedMessageSentence.sentence
|
|
3012
3039
|
}, isHtmlAudioSupported && superinterfaceContext.publicApiKey ? {
|
|
3013
3040
|
publicApiKey: superinterfaceContext.publicApiKey
|
|
3014
3041
|
} : {}));
|
|
@@ -3016,7 +3043,12 @@ var useMessageAudio = function(param) {
|
|
|
3016
3043
|
format: "mp3",
|
|
3017
3044
|
autoplay: true,
|
|
3018
3045
|
html5: isHtmlAudioSupported,
|
|
3019
|
-
onend:
|
|
3046
|
+
onend: function() {
|
|
3047
|
+
setIsPlaying(false);
|
|
3048
|
+
if (unplayedMessageSentences.length === 1 && latestMessageProps.latestMessage.status !== "in_progress") {
|
|
3049
|
+
onEnd();
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3020
3052
|
}, isHtmlAudioSupported ? {} : {
|
|
3021
3053
|
xhr: _object_spread_props(_object_spread({}, superinterfaceContext.publicApiKey ? {
|
|
3022
3054
|
headers: {
|
|
@@ -3027,14 +3059,15 @@ var useMessageAudio = function(param) {
|
|
|
3027
3059
|
})
|
|
3028
3060
|
}));
|
|
3029
3061
|
}, [
|
|
3062
|
+
isPlaying,
|
|
3030
3063
|
superinterfaceContext,
|
|
3031
3064
|
latestMessageProps,
|
|
3032
3065
|
audioPlayer,
|
|
3033
|
-
|
|
3066
|
+
playedMessageSentences,
|
|
3034
3067
|
onEnd
|
|
3035
3068
|
]);
|
|
3036
3069
|
var isInited = (0, import_react40.useRef)(false);
|
|
3037
|
-
var
|
|
3070
|
+
var _ref2 = _sliced_to_array((0, import_react40.useState)(null), 2), audioEngine = _ref2[0], setAudioEngine = _ref2[1];
|
|
3038
3071
|
(0, import_react40.useEffect)(function() {
|
|
3039
3072
|
if (!audioPlayer.playing) return;
|
|
3040
3073
|
if (isInited.current) return;
|
|
@@ -3563,6 +3596,7 @@ var MarkdownProvider = function(_param) {
|
|
|
3563
3596
|
useMessageContext: useMessageContext,
|
|
3564
3597
|
useMessages: useMessages,
|
|
3565
3598
|
useSuperinterfaceContext: useSuperinterfaceContext,
|
|
3566
|
-
useThreadContext: useThreadContext
|
|
3599
|
+
useThreadContext: useThreadContext,
|
|
3600
|
+
useThreadDialogContext: useThreadDialogContext
|
|
3567
3601
|
});
|
|
3568
3602
|
//# sourceMappingURL=index.cjs.map
|