@superinterface/react 2.4.2 → 2.4.4
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 +39 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2792,16 +2792,20 @@ var blobToData = function(blob) {
|
|
|
2792
2792
|
var import_react38 = require("react");
|
|
2793
2793
|
var useStatus = function(param) {
|
|
2794
2794
|
var messageAudioProps = param.messageAudioProps, recorderProps = param.recorderProps, createMessageProps = param.createMessageProps;
|
|
2795
|
+
var latestMessageProps = useLatestMessage();
|
|
2795
2796
|
var status = (0, import_react38.useMemo)(function() {
|
|
2797
|
+
var _latestMessageProps_latestMessage;
|
|
2796
2798
|
if (recorderProps.status === "recording") return "recording";
|
|
2797
2799
|
if (createMessageProps.isPending) return "creatingMessage";
|
|
2798
|
-
if (messageAudioProps.playing) return "playing";
|
|
2800
|
+
if (messageAudioProps.playing || messageAudioProps.isPending) return "playing";
|
|
2799
2801
|
if (messageAudioProps.paused) return "playerPaused";
|
|
2800
2802
|
if (!messageAudioProps.isReady) return "loading";
|
|
2803
|
+
if (((_latestMessageProps_latestMessage = latestMessageProps.latestMessage) === null || _latestMessageProps_latestMessage === void 0 ? void 0 : _latestMessageProps_latestMessage.status) === "in_progress") return "creatingMessage";
|
|
2801
2804
|
if (recorderProps.status === "idle") return "idle";
|
|
2802
2805
|
if (recorderProps.status === "paused") return "recorderPaused";
|
|
2803
2806
|
return "loading";
|
|
2804
2807
|
}, [
|
|
2808
|
+
latestMessageProps,
|
|
2805
2809
|
messageAudioProps,
|
|
2806
2810
|
recorderProps,
|
|
2807
2811
|
createMessageProps
|
|
@@ -3004,24 +3008,31 @@ var useMessageAudio = function(param) {
|
|
|
3004
3008
|
var superinterfaceContext = useSuperinterfaceContext();
|
|
3005
3009
|
var _ref1 = _sliced_to_array((0, import_react40.useState)(false), 2), isPlaying = _ref1[0], setIsPlaying = _ref1[1];
|
|
3006
3010
|
var latestMessageProps = useLatestMessage();
|
|
3007
|
-
(0, import_react40.
|
|
3008
|
-
if (
|
|
3009
|
-
if (
|
|
3010
|
-
if (!latestMessageProps.latestMessage) return;
|
|
3011
|
-
if (latestMessageProps.latestMessage.role !== "assistant") return;
|
|
3011
|
+
var unplayedMessageSentences = (0, import_react40.useMemo)(function() {
|
|
3012
|
+
if (!latestMessageProps.latestMessage) return [];
|
|
3013
|
+
if (latestMessageProps.latestMessage.role !== "assistant") return [];
|
|
3012
3014
|
var input2 = input({
|
|
3013
3015
|
message: latestMessageProps.latestMessage
|
|
3014
3016
|
});
|
|
3015
|
-
if (!input2) return;
|
|
3017
|
+
if (!input2) return [];
|
|
3016
3018
|
var messageSentences = getMessageSentences({
|
|
3017
3019
|
messageId: latestMessageProps.latestMessage.id,
|
|
3018
3020
|
input: input2
|
|
3019
3021
|
});
|
|
3020
|
-
|
|
3022
|
+
return messageSentences.filter(function(ms) {
|
|
3021
3023
|
return !playedMessageSentences.find(function(pms) {
|
|
3022
3024
|
return pms.messageId === ms.messageId && pms.sentence === ms.sentence;
|
|
3023
3025
|
});
|
|
3024
3026
|
});
|
|
3027
|
+
}, [
|
|
3028
|
+
latestMessageProps,
|
|
3029
|
+
playedMessageSentences
|
|
3030
|
+
]);
|
|
3031
|
+
(0, import_react40.useEffect)(function() {
|
|
3032
|
+
if (isPlaying) return;
|
|
3033
|
+
if (audioPlayer.playing) return;
|
|
3034
|
+
if (!latestMessageProps.latestMessage) return;
|
|
3035
|
+
if (latestMessageProps.latestMessage.role !== "assistant") return;
|
|
3025
3036
|
var firstUnplayedMessageSentence = unplayedMessageSentences[0];
|
|
3026
3037
|
if (!firstUnplayedMessageSentence) {
|
|
3027
3038
|
return;
|
|
@@ -3059,6 +3070,7 @@ var useMessageAudio = function(param) {
|
|
|
3059
3070
|
})
|
|
3060
3071
|
}));
|
|
3061
3072
|
}, [
|
|
3073
|
+
unplayedMessageSentences,
|
|
3062
3074
|
isPlaying,
|
|
3063
3075
|
superinterfaceContext,
|
|
3064
3076
|
latestMessageProps,
|
|
@@ -3068,13 +3080,22 @@ var useMessageAudio = function(param) {
|
|
|
3068
3080
|
]);
|
|
3069
3081
|
var isInited = (0, import_react40.useRef)(false);
|
|
3070
3082
|
var _ref2 = _sliced_to_array((0, import_react40.useState)(null), 2), audioEngine = _ref2[0], setAudioEngine = _ref2[1];
|
|
3083
|
+
(0, import_react40.useEffect)(function() {
|
|
3084
|
+
if (isHtmlAudioSupported) {
|
|
3085
|
+
var _import_howler_Howler__howls___sounds_, _import_howler_Howler__howls_, _import_howler_Howler;
|
|
3086
|
+
if (!((_import_howler_Howler = import_howler.Howler) === null || _import_howler_Howler === void 0 ? void 0 : (_import_howler_Howler__howls_ = _import_howler_Howler._howls[0]) === null || _import_howler_Howler__howls_ === void 0 ? void 0 : (_import_howler_Howler__howls___sounds_ = _import_howler_Howler__howls_._sounds[0]) === null || _import_howler_Howler__howls___sounds_ === void 0 ? void 0 : _import_howler_Howler__howls___sounds_._node)) return;
|
|
3087
|
+
if (!import_howler.Howler._howls[0]._sounds[0]._node.crossOrigin) return;
|
|
3088
|
+
import_howler.Howler._howls[0]._sounds[0]._node.crossOrigin = "anonymous";
|
|
3089
|
+
}
|
|
3090
|
+
}, [
|
|
3091
|
+
audioPlayer
|
|
3092
|
+
]);
|
|
3071
3093
|
(0, import_react40.useEffect)(function() {
|
|
3072
3094
|
if (!audioPlayer.playing) return;
|
|
3073
3095
|
if (isInited.current) return;
|
|
3074
3096
|
isInited.current = true;
|
|
3075
3097
|
if (isHtmlAudioSupported) {
|
|
3076
3098
|
var audioContext = new AudioContext();
|
|
3077
|
-
import_howler.Howler._howls[0]._sounds[0]._node.crossOrigin = "anonymous";
|
|
3078
3099
|
setAudioEngine({
|
|
3079
3100
|
// @ts-ignore-next-line
|
|
3080
3101
|
source: audioContext.createMediaElementSource(import_howler.Howler._howls[0]._sounds[0]._node),
|
|
@@ -3099,7 +3120,15 @@ var useMessageAudio = function(param) {
|
|
|
3099
3120
|
}, [
|
|
3100
3121
|
audioEngine
|
|
3101
3122
|
]);
|
|
3102
|
-
|
|
3123
|
+
var isPending = (0, import_react40.useMemo)(function() {
|
|
3124
|
+
return isPlaying || unplayedMessageSentences.length > 0;
|
|
3125
|
+
}, [
|
|
3126
|
+
isPlaying,
|
|
3127
|
+
unplayedMessageSentences
|
|
3128
|
+
]);
|
|
3129
|
+
return _object_spread_props(_object_spread({
|
|
3130
|
+
isPending: isPending
|
|
3131
|
+
}, audioPlayer), {
|
|
3103
3132
|
visualizationAnalyser: visualizationAnalyser
|
|
3104
3133
|
});
|
|
3105
3134
|
};
|