@davi-ai/retorik-framework 3.2.3 → 3.2.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.
Files changed (48) hide show
  1. package/dist/{AttachmentDetail.1e06c2a5.js → AttachmentDetail.cfd86776.js} +2 -3
  2. package/dist/AttachmentDetail.cfd86776.js.map +1 -0
  3. package/dist/{AttachmentDetail.c6c297df.js → AttachmentDetail.fdcd1737.js} +2 -3
  4. package/dist/AttachmentDetail.fdcd1737.js.map +1 -0
  5. package/dist/{CustomView.080c8028.js → CustomView.ba7af9b6.js} +2 -3
  6. package/dist/CustomView.ba7af9b6.js.map +1 -0
  7. package/dist/{CustomView.90d2a13d.js → CustomView.c24a0e74.js} +2 -3
  8. package/dist/CustomView.c24a0e74.js.map +1 -0
  9. package/dist/{Emergency.a21f837c.js → Emergency.0cf005ce.js} +2 -3
  10. package/dist/Emergency.0cf005ce.js.map +1 -0
  11. package/dist/{Emergency.423214ad.js → Emergency.897ee3c7.js} +2 -3
  12. package/dist/Emergency.897ee3c7.js.map +1 -0
  13. package/dist/{HistoryList.5fd6aa12.js → HistoryList.03a56119.js} +3 -7
  14. package/dist/HistoryList.03a56119.js.map +1 -0
  15. package/dist/{HistoryList.50ff0fd9.js → HistoryList.4c303dc6.js} +3 -7
  16. package/dist/HistoryList.4c303dc6.js.map +1 -0
  17. package/dist/{LanguageChoice.61e36c1d.js → LanguageChoice.623ee802.js} +2 -5
  18. package/dist/LanguageChoice.623ee802.js.map +1 -0
  19. package/dist/{LanguageChoice.1579b654.js → LanguageChoice.ff0cd04c.js} +2 -5
  20. package/dist/LanguageChoice.ff0cd04c.js.map +1 -0
  21. package/dist/{NewsContainer.67f04b19.js → NewsContainer.05bb1b19.js} +9 -9
  22. package/dist/NewsContainer.05bb1b19.js.map +1 -0
  23. package/dist/{NewsContainer.932174e9.js → NewsContainer.5e80336b.js} +9 -9
  24. package/dist/NewsContainer.5e80336b.js.map +1 -0
  25. package/dist/{Weather.661c2cac.js → Weather.99917b66.js} +2 -3
  26. package/dist/Weather.99917b66.js.map +1 -0
  27. package/dist/{Weather.fb22fba3.js → Weather.cf58823d.js} +2 -3
  28. package/dist/Weather.cf58823d.js.map +1 -0
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +323 -544
  31. package/dist/index.js.map +1 -1
  32. package/dist/index.modern.js +309 -537
  33. package/dist/index.modern.js.map +1 -1
  34. package/package.json +1 -1
  35. package/dist/AttachmentDetail.1e06c2a5.js.map +0 -1
  36. package/dist/AttachmentDetail.c6c297df.js.map +0 -1
  37. package/dist/CustomView.080c8028.js.map +0 -1
  38. package/dist/CustomView.90d2a13d.js.map +0 -1
  39. package/dist/Emergency.423214ad.js.map +0 -1
  40. package/dist/Emergency.a21f837c.js.map +0 -1
  41. package/dist/HistoryList.50ff0fd9.js.map +0 -1
  42. package/dist/HistoryList.5fd6aa12.js.map +0 -1
  43. package/dist/LanguageChoice.1579b654.js.map +0 -1
  44. package/dist/LanguageChoice.61e36c1d.js.map +0 -1
  45. package/dist/NewsContainer.67f04b19.js.map +0 -1
  46. package/dist/NewsContainer.932174e9.js.map +0 -1
  47. package/dist/Weather.661c2cac.js.map +0 -1
  48. package/dist/Weather.fb22fba3.js.map +0 -1
package/dist/index.js CHANGED
@@ -103,7 +103,6 @@ const $2793f2455cec0982$var$initialState = {
103
103
  retorikEvent: undefined,
104
104
  displayAgent: true,
105
105
  activityToSend: undefined,
106
- currentNewsActivity: undefined,
107
106
  retorikNewsEnded: false,
108
107
  userIsTyping: false,
109
108
  userIsSwiping: false,
@@ -189,11 +188,6 @@ const $2793f2455cec0982$var$createUtilsStore = ()=>(0, $dWhh5$zustand.createStor
189
188
  activityToSend: value
190
189
  });
191
190
  },
192
- setCurrentNewsActivity: (value)=>{
193
- set({
194
- currentNewsActivity: value
195
- });
196
- },
197
191
  setRetorikNewsEnded: (value)=>{
198
192
  set({
199
193
  retorikNewsEnded: value
@@ -351,6 +345,7 @@ $parcel$export(module.exports, "Source3DEngine", () => $71c613e2e831c34c$export$
351
345
  $parcel$export(module.exports, "UIPart", () => $71c613e2e831c34c$export$63fc5f52b5b4da1e);
352
346
  $parcel$export(module.exports, "TextFrom", () => $71c613e2e831c34c$export$b685c7d489184507);
353
347
  $parcel$export(module.exports, "Theme", () => $71c613e2e831c34c$export$14faa19a0f3bbeb2);
348
+ $parcel$export(module.exports, "TraceType", () => $71c613e2e831c34c$export$d4b4ca0ba30ae29c);
354
349
  var $71c613e2e831c34c$export$e4a712fff93fb00f = /*#__PURE__*/ function(ActionType) {
355
350
  ActionType["message"] = "message";
356
351
  ActionType["event"] = "event";
@@ -576,6 +571,12 @@ var $71c613e2e831c34c$export$14faa19a0f3bbeb2 = /*#__PURE__*/ function(Theme) {
576
571
  Theme["auto"] = "auto";
577
572
  return Theme;
578
573
  }($71c613e2e831c34c$export$14faa19a0f3bbeb2 || {});
574
+ var $71c613e2e831c34c$export$d4b4ca0ba30ae29c = /*#__PURE__*/ function(TraceType) {
575
+ TraceType["message"] = "directlineMessage";
576
+ TraceType["utteranceStart"] = "utteranceStart";
577
+ TraceType["utteranceEnd"] = "utteranceEnd";
578
+ return TraceType;
579
+ }($71c613e2e831c34c$export$d4b4ca0ba30ae29c || {});
579
580
 
580
581
  });
581
582
 
@@ -2078,9 +2079,6 @@ const $df401eb9a10f9e0e$var$initialState = {
2078
2079
  visemeData: [],
2079
2080
  singleVisemeAdded: null,
2080
2081
  multiVisemesAdded: [],
2081
- currentReplyToId: undefined,
2082
- currentPlaying: undefined,
2083
- endedActivities: [],
2084
2082
  currentOrLastPlayedActivity: undefined,
2085
2083
  isMicrophoneAllowed: false,
2086
2084
  showMicrophoneModal: false,
@@ -2089,9 +2087,6 @@ const $df401eb9a10f9e0e$var$initialState = {
2089
2087
  lastRecognitionInterim: '',
2090
2088
  streamingReplyToId: null,
2091
2089
  streamingQueue: [],
2092
- streamingQueueForText: [],
2093
- currentStreaming: null,
2094
- streamingQueueFullLength: 0,
2095
2090
  streamingReplyToIdToIgnore: null,
2096
2091
  speechRecognitionDynamicGrammars: [],
2097
2092
  externalTextToSpeech: undefined
@@ -2228,22 +2223,6 @@ const $df401eb9a10f9e0e$var$createSpeechStore = (setRetorikEvent, getListStatus,
2228
2223
  if (getListStatus() !== (0, $7WHA7.ListStatus).opened) setListStatus((0, $7WHA7.ListStatus).available);
2229
2224
  }
2230
2225
  },
2231
- setCurrentReplyToId: (value)=>{
2232
- set({
2233
- currentReplyToId: value
2234
- });
2235
- },
2236
- setCurrentPlaying: (value)=>{
2237
- set({
2238
- currentPlaying: value
2239
- });
2240
- value && get().actions.setCurrentOrLastPlayedActivity(value);
2241
- },
2242
- setEndedActivities: (value)=>{
2243
- set({
2244
- endedActivities: value
2245
- });
2246
- },
2247
2226
  setIsMicrophoneAllowed: (value)=>{
2248
2227
  set({
2249
2228
  isMicrophoneAllowed: value
@@ -2305,72 +2284,45 @@ const $df401eb9a10f9e0e$var$createSpeechStore = (setRetorikEvent, getListStatus,
2305
2284
  streamingReplyToId: value
2306
2285
  });
2307
2286
  },
2308
- setStreamingQueue: (value)=>{
2309
- set({
2310
- streamingQueue: value,
2311
- streamingQueueForText: value
2312
- });
2313
- },
2314
2287
  addToStreamingQueue: (value)=>{
2315
- if (value.replyToId && value.replyToId !== get().streamingReplyToIdToIgnore) {
2316
- // Set replyToId and new queue if replyToId is different from the current one
2317
- if (get().streamingReplyToId !== value.replyToId) set({
2318
- streamingQueueFullLength: 0,
2319
- streamingReplyToId: value.replyToId,
2320
- streamingQueue: [
2321
- value
2322
- ],
2323
- streamingQueueForText: [
2324
- value
2325
- ]
2326
- });
2327
- else set({
2328
- streamingQueue: [
2329
- ...get().streamingQueue,
2330
- value
2331
- ],
2332
- streamingQueueForText: [
2333
- ...get().streamingQueueForText,
2334
- value
2335
- ]
2336
- });
2337
- }
2288
+ if (value.replyToId) {
2289
+ if (value.replyToId !== get().streamingReplyToIdToIgnore) {
2290
+ // Set replyToId and new queue if replyToId is different from the current one
2291
+ if (get().streamingReplyToId !== value.replyToId) set({
2292
+ streamingReplyToId: value.replyToId,
2293
+ streamingQueue: [
2294
+ value
2295
+ ]
2296
+ });
2297
+ else set({
2298
+ streamingQueue: [
2299
+ ...get().streamingQueue,
2300
+ value
2301
+ ]
2302
+ });
2303
+ }
2304
+ } else set({
2305
+ streamingQueue: [
2306
+ ...get().streamingQueue,
2307
+ value
2308
+ ]
2309
+ });
2338
2310
  },
2339
- removeFirstFromStreamingQueue: ()=>{
2340
- if (get().streamingQueue.length) {
2341
- const tempStreamingQueue = get().streamingQueue.slice();
2342
- tempStreamingQueue.splice(0, 1);
2343
- set({
2344
- streamingQueue: tempStreamingQueue
2345
- });
2346
- }
2311
+ // If "twice" parameter is true, let's remove 2 elements instead of one (used with the message at the end of a streaming that should not be spoken)
2312
+ removeFirstFromStreamingQueue: (twice)=>{
2313
+ set((state)=>({
2314
+ streamingQueue: state.streamingQueue.slice(twice ? 2 : 1)
2315
+ }));
2347
2316
  },
2348
2317
  killCurrentStreaming: ()=>{
2349
2318
  set({
2350
- streamingReplyToId: null,
2351
- streamingQueue: [],
2352
- streamingQueueForText: [],
2353
- currentStreaming: null,
2354
- streamingQueueFullLength: 0,
2355
- streamingReplyToIdToIgnore: get().streamingReplyToId
2319
+ streamingReplyToIdToIgnore: get().streamingReplyToId,
2320
+ streamingQueue: []
2356
2321
  });
2357
2322
  },
2358
2323
  checkActivityReplyToId: (replyToId)=>{
2359
2324
  get().streamingReplyToId !== replyToId && get().actions.killCurrentStreaming();
2360
2325
  },
2361
- setCurrentStreaming: (value)=>{
2362
- set({
2363
- currentStreaming: value
2364
- });
2365
- },
2366
- setStreamingQueueFullLength: (value, replyToId)=>{
2367
- if (replyToId) replyToId === get().streamingReplyToId && set({
2368
- streamingQueueFullLength: value
2369
- });
2370
- else set({
2371
- streamingQueueFullLength: value
2372
- });
2373
- },
2374
2326
  addSpeechRecognitionDynamicGrammar: (value)=>{
2375
2327
  const currentGrammars = get().speechRecognitionDynamicGrammars;
2376
2328
  // For each value, verifiy if it doesn't exist in the array yet
@@ -2790,7 +2742,7 @@ const $8fc061e3e1dc64cb$var$initialState = {
2790
2742
  queueLock: false
2791
2743
  };
2792
2744
  const $8fc061e3e1dc64cb$var$regexDataCommand = /(\{data-command=")[\p{L}\p{N}\p{Po}\p{Pd}\p{Pc}\s\u0027\u2019]+("\})(<br\s\/>)?/gu;
2793
- const $8fc061e3e1dc64cb$var$createActivityStore = (localeRef, isUsedOnBorneRef, inputHintBehaviourRef, setCurrentId, setRestoreInputsState, addToStreamingQueue, setStreamingQueueFullLength, setMode, unlockClickedButton, setSubmitDelayBeforeSendingMessage, setIsWaitingForResponse, setSendBoxPlaceHolder)=>{
2745
+ const $8fc061e3e1dc64cb$var$createActivityStore = (localeRef, isUsedOnBorneRef, inputHintBehaviourRef, setCurrentId, setRestoreInputsState, addToStreamingQueue, setMode, unlockClickedButton, setSubmitDelayBeforeSendingMessage, setIsWaitingForResponse, setSendBoxPlaceHolder)=>{
2794
2746
  return (0, $dWhh5$zustand.createStore)((set, get)=>{
2795
2747
  return {
2796
2748
  ...$8fc061e3e1dc64cb$var$initialState,
@@ -2855,7 +2807,7 @@ const $8fc061e3e1dc64cb$var$createActivityStore = (localeRef, isUsedOnBorneRef,
2855
2807
  currentActivity.type === 'message' ? await get().actions.processAddBotMessage(currentActivity) : await get().actions.processAddBotEvent(currentActivity);
2856
2808
  // Remove the first element from the queue (the one that got processed above) and process the queue once again
2857
2809
  set({
2858
- queue: get().queue.slice().splice(1)
2810
+ queue: get().queue.slice(1)
2859
2811
  });
2860
2812
  get().actions.processQueue();
2861
2813
  } else set({
@@ -2863,12 +2815,11 @@ const $8fc061e3e1dc64cb$var$createActivityStore = (localeRef, isUsedOnBorneRef,
2863
2815
  });
2864
2816
  },
2865
2817
  processAddBotMessage: async (value)=>{
2866
- var _value_value;
2867
2818
  setCurrentId(undefined);
2868
2819
  const processedActivity = await get().actions.processBotMessageActivity(value);
2869
- // If this activity is the one concluding a streaming, let's set the amount of streams previously generated
2870
- if (!get().retrievingConversation && ((_value_value = value.value) === null || _value_value === void 0 ? void 0 : _value_value.streamingCount)) setStreamingQueueFullLength(value.value.streamingCount, value.replyToId);
2871
2820
  const tempActivity = get().retrievingConversation ? undefined : processedActivity;
2821
+ // Add this activity to the streaming queue if we are not in conversation retrieval process
2822
+ !get().retrievingConversation && addToStreamingQueue(processedActivity);
2872
2823
  set({
2873
2824
  activities: [
2874
2825
  ...get().activities,
@@ -2910,6 +2861,29 @@ const $8fc061e3e1dc64cb$var$createActivityStore = (localeRef, isUsedOnBorneRef,
2910
2861
  }
2911
2862
  },
2912
2863
  processAddBotEvent: async (value)=>{
2864
+ var _value_name, _value_text;
2865
+ const streamingMap = new Map(get().botStreamingActivities);
2866
+ // Deal with streaming activities
2867
+ if (((_value_name = value.name) === null || _value_name === void 0 ? void 0 : _value_name.toLowerCase()) === 'davi.streammessageactivity') // Add this activity to the streaming queue if we are not in conversation retrieval process
2868
+ {
2869
+ if (((_value_text = value.text) === null || _value_text === void 0 ? void 0 : _value_text.trim().length) && !get().retrievingConversation) {
2870
+ // Create speak field from the text one
2871
+ const processedText = (0, $pFs7y.processMarkdownAndSpeechMarkdown)(value.text, true);
2872
+ value.speak = processedText.text;
2873
+ value.htmlText = processedText.htmlText;
2874
+ addToStreamingQueue(value);
2875
+ // Set data in the Map for text display
2876
+ if (value.replyToId) {
2877
+ const currentStreamingData = streamingMap.get(value.replyToId);
2878
+ currentStreamingData ? streamingMap.set(value.replyToId, [
2879
+ ...currentStreamingData,
2880
+ value
2881
+ ]) : streamingMap.set(value.replyToId, [
2882
+ value
2883
+ ]);
2884
+ }
2885
+ }
2886
+ }
2913
2887
  set({
2914
2888
  activities: [
2915
2889
  ...get().activities,
@@ -2927,38 +2901,16 @@ const $8fc061e3e1dc64cb$var$createActivityStore = (localeRef, isUsedOnBorneRef,
2927
2901
  ],
2928
2902
  lastBotEventActivity: value,
2929
2903
  lastEventActivity: value,
2904
+ botStreamingActivities: streamingMap,
2930
2905
  watermark: get().watermark + 1
2931
2906
  });
2932
2907
  Promise.resolve();
2933
2908
  },
2934
2909
  addBotEvent: async (value)=>{
2935
2910
  if (get().actions.checkCurrentConversationId(value.id)) {
2936
- var _value_name, _value_text, _value_name1;
2937
- if (((_value_name = value.name) === null || _value_name === void 0 ? void 0 : _value_name.toLowerCase()) === 'davi.streammessageactivity') {
2938
- if (((_value_text = value.text) === null || _value_text === void 0 ? void 0 : _value_text.trim().length) && !get().retrievingConversation) {
2939
- setIsWaitingForResponse(false);
2940
- // Create speak field from the text one
2941
- const processedText = (0, $pFs7y.processMarkdownAndSpeechMarkdown)(value.text, true);
2942
- value.speak = processedText.text;
2943
- value.htmlText = processedText.htmlText;
2944
- addToStreamingQueue(value);
2945
- if (value.replyToId) {
2946
- const currentStreamingMap = new Map(get().botStreamingActivities);
2947
- const currentStreamingData = currentStreamingMap.get(value.replyToId);
2948
- currentStreamingData ? currentStreamingMap.set(value.replyToId, [
2949
- ...currentStreamingData,
2950
- value
2951
- ]) : currentStreamingMap.set(value.replyToId, [
2952
- value
2953
- ]);
2954
- set({
2955
- botStreamingActivities: currentStreamingMap,
2956
- watermark: get().watermark + 1
2957
- });
2958
- }
2959
- unlockClickedButton();
2960
- }
2961
- } else if (((_value_name1 = value.name) === null || _value_name1 === void 0 ? void 0 : _value_name1.toLowerCase()) === 'switchtotextmode') {
2911
+ var _value_name;
2912
+ //
2913
+ if (((_value_name = value.name) === null || _value_name === void 0 ? void 0 : _value_name.toLowerCase()) === 'switchtotextmode') {
2962
2914
  setMode((0, $7WHA7.Mode).text);
2963
2915
  set({
2964
2916
  watermark: get().watermark + 1
@@ -3233,10 +3185,10 @@ const $8fc061e3e1dc64cb$var$ActivityProvider = ({ children: children })=>{
3233
3185
  const isUsedOnBorneRef = (0, $dWhh5$react.useRef)(false);
3234
3186
  const inputHintBehaviourRef = (0, $dWhh5$react.useRef)(undefined);
3235
3187
  const { setCurrentId: setCurrentId, setRestoreInputsState: setRestoreInputsState } = (0, $8AvjS.useAdaptiveCardStore)((state)=>state.actions);
3236
- const { addToStreamingQueue: addToStreamingQueue, setStreamingQueueFullLength: setStreamingQueueFullLength, setMode: setMode } = (0, $jgaO0.useSpeechStore)((state)=>state.actions);
3188
+ const { addToStreamingQueue: addToStreamingQueue, setMode: setMode } = (0, $jgaO0.useSpeechStore)((state)=>state.actions);
3237
3189
  const unlockClickedButton = (0, $7eio0.useUtilsStore)((state)=>state.actions.unlockClickedButton);
3238
3190
  const { setSubmitDelayBeforeSendingMessage: setSubmitDelayBeforeSendingMessage, setIsWaitingForResponse: setIsWaitingForResponse, setSendBoxPlaceHolder: setSendBoxPlaceHolder } = (0, $6EkQS.useRetorikStore)((state)=>state.actions);
3239
- const [store] = (0, $dWhh5$react.useState)(()=>$8fc061e3e1dc64cb$var$createActivityStore(localeRef, isUsedOnBorneRef, inputHintBehaviourRef, setCurrentId, setRestoreInputsState, addToStreamingQueue, setStreamingQueueFullLength, setMode, unlockClickedButton, setSubmitDelayBeforeSendingMessage, setIsWaitingForResponse, setSendBoxPlaceHolder));
3191
+ const [store] = (0, $dWhh5$react.useState)(()=>$8fc061e3e1dc64cb$var$createActivityStore(localeRef, isUsedOnBorneRef, inputHintBehaviourRef, setCurrentId, setRestoreInputsState, addToStreamingQueue, setMode, unlockClickedButton, setSubmitDelayBeforeSendingMessage, setIsWaitingForResponse, setSendBoxPlaceHolder));
3240
3192
  (0, $dWhh5$react.useEffect)(()=>{
3241
3193
  localeRef.current = locale;
3242
3194
  }, [
@@ -4164,7 +4116,7 @@ const $328a7f03b0982320$var$createDirectlineStore = (modeRef, recognitionStateRe
4164
4116
  if (get().actions.checkIfHandlerAbortsActivity((0, $3DDGn.LegacyDirectLineActivityType).SEND_MESSAGE, tempActivity)) return;
4165
4117
  (_get_directLine = get().directLine) === null || _get_directLine === void 0 ? void 0 : _get_directLine.postActivity(tempActivity).subscribe();
4166
4118
  },
4167
- sendEvent: (name, value)=>{
4119
+ sendEvent: (name, value, callback)=>{
4168
4120
  var _get_directLine;
4169
4121
  if (get().conversationPaused) return;
4170
4122
  !name.toLowerCase().includes('davi.closewindow') && !$328a7f03b0982320$var$eventsWithoutCancel.includes(name.toLowerCase()) && get().actions.checkMicrophoneAndCancel();
@@ -4184,7 +4136,10 @@ const $328a7f03b0982320$var$createDirectlineStore = (modeRef, recognitionStateRe
4184
4136
  // Check if the event should be stopped in the external activity handler if there is one
4185
4137
  if (get().actions.checkIfHandlerAbortsActivity((0, $3DDGn.LegacyDirectLineActivityType).POST_ACTIVITY, tempEvent)) return;
4186
4138
  if (get().actions.checkIfHandlerAbortsActivity((0, $3DDGn.LegacyDirectLineActivityType).SEND_EVENT, tempEvent)) return;
4187
- (_get_directLine = get().directLine) === null || _get_directLine === void 0 ? void 0 : _get_directLine.postActivity(tempEvent).subscribe();
4139
+ (_get_directLine = get().directLine) === null || _get_directLine === void 0 ? void 0 : _get_directLine.postActivity(tempEvent).subscribe({
4140
+ error: (error)=>console.log('Retorik Framework > error while sending event : ', error),
4141
+ complete: ()=>callback === null || callback === void 0 ? void 0 : callback()
4142
+ });
4188
4143
  },
4189
4144
  sendTyping: ()=>{
4190
4145
  var _get_directLine;
@@ -4392,7 +4347,7 @@ var $c8770452d727244a$export$2e2bcd8739ae039 = $c8770452d727244a$var$activityMid
4392
4347
  });
4393
4348
 
4394
4349
  parcelRegister("93cl9", function(module, exports) {
4395
- module.exports = JSON.parse("{\"name\":\"@davi-ai/retorik-framework\",\"version\":\"3.2.3\",\"description\":\"Retorik Framework package\",\"author\":\"DAVI\",\"license\":\"MIT\",\"repository\":\"none\",\"main\":\"dist/index.js\",\"module\":\"dist/index.modern.js\",\"types\":\"dist/index.d.ts\",\"source\":\"src/index.tsx\",\"standalone\":\"standalone/index.js\",\"targets\":{\"standalone\":{\"context\":\"browser\",\"outputFormat\":\"esmodule\",\"distDir\":\"standalone\"},\"module\":{\"context\":\"browser\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\"}},\"engines\":{\"node\":\">=10\"},\"scripts\":{\"build\":\"parcel build\",\"start\":\"parcel watch\",\"test\":\"jest --env=jsdom --reporters=jest-junit\",\"test-console\":\"jest --env=jsdom\",\"test-update-snapshots\":\"jest --env=jsdom --updateSnapshot\",\"test-coverage-console\":\"jest --env=jsdom --reporters=jest-junit --coverage\",\"test-coverage\":\"jest --env=jsdom --reporters=jest-junit --coverage --coverageReporters=cobertura\",\"report\":\"npx parcel build src/index.tsx --reporter @parcel/reporter-bundle-analyzer\",\"credentials\":\"vsts-npm-auth -config .npmrc\"},\"peerDependencies\":{\"react\":\"18.3.1\",\"react-dom\":\"18.3.1\"},\"devDependencies\":{\"@babel/core\":\"^7.19.1\",\"@babel/plugin-proposal-decorators\":\"^7.24.7\",\"@babel/plugin-proposal-private-property-in-object\":\"^7.21.11\",\"@babel/preset-env\":\"^7.25.4\",\"@babel/preset-react\":\"^7.24.7\",\"@babel/preset-typescript\":\"^7.24.7\",\"@babel/runtime\":\"^7.23.8\",\"@parcel/packager-ts\":\"^2.13.2\",\"@parcel/reporter-bundle-analyzer\":\"^2.13.2\",\"@parcel/reporter-sourcemap-visualiser\":\"^2.13.2\",\"@parcel/transformer-inline-string\":\"^2.13.2\",\"@parcel/transformer-typescript-types\":\"^2.13.2\",\"@parcel/validator-eslint\":\"^2.13.2\",\"@parcel/validator-typescript\":\"^2.13.2\",\"@testing-library/dom\":\"^10.4.0\",\"@testing-library/jest-dom\":\"6.5.0\",\"@testing-library/react\":\"16.0.1\",\"@testing-library/react-hooks\":\"8.0.1\",\"@testing-library/user-event\":\"14.5.2\",\"@types/jest\":\"^27.5.1\",\"@types/leaflet\":\"^1.8.0\",\"@types/node\":\"^12.12.38\",\"@types/react\":\"18.3.12\",\"@types/react-dom\":\"18.3.1\",\"@types/testing-library__jest-dom\":\"^5.14.5\",\"@types/testing-library__react\":\"latest\",\"@typescript-eslint/eslint-plugin\":\"^8.19.0\",\"@typescript-eslint/parser\":\"^8.19.0\",\"autoprefixer\":\"^10.4.7\",\"babel-eslint\":\"^10.0.3\",\"babel-jest\":\"^29.7.0\",\"babel-loader\":\"^8.2.5\",\"buffer\":\"^5.7.1\",\"canvas\":\"^2.9.0\",\"cross-env\":\"^7.0.2\",\"crypto-browserify\":\"^3.12.0\",\"eslint\":\"^9.16.0\",\"eslint-config-prettier\":\"^9.1.0\",\"eslint-config-standard\":\"^17.1.0\",\"eslint-config-standard-react\":\"^13.0.0\",\"eslint-plugin-import\":\"^2.31.0\",\"eslint-plugin-node\":\"^11.1.0\",\"eslint-plugin-prettier\":\"^5.2.1\",\"eslint-plugin-promise\":\"^7.2.1\",\"eslint-plugin-react\":\"^7.37.2\",\"https-browserify\":\"^1.0.0\",\"jest\":\"^29.7.0\",\"jest-environment-jsdom\":\"^29.7.0\",\"jest-junit\":\"16.0.0\",\"npm-run-all\":\"^4.1.5\",\"parcel\":\"^2.13.2\",\"postcss\":\"^8.4.14\",\"postcss-url\":\"^10.1.3\",\"prettier\":\"^2.0.4\",\"process\":\"^0.11.10\",\"punycode\":\"^1.4.1\",\"querystring-es3\":\"^0.2.1\",\"react\":\"^18\",\"react-docgen-typescript-plugin\":\"^1.0.5\",\"react-dom\":\"18.3.1\",\"react-test-renderer\":\"^18.3.1\",\"resize-observer-polyfill\":\"^1.5.1\",\"stream-browserify\":\"^3.0.0\",\"stream-http\":\"^3.2.0\",\"string_decoder\":\"^1.3.0\",\"tailwindcss\":\"^3.1.0\",\"typescript\":\"5.3.2\",\"url\":\"^0.11.0\",\"util\":\"^0.12.4\"},\"files\":[\"dist\"],\"dependencies\":{\"@davi-ai/body-engine-sprite\":\"3.0.0\",\"@davi-ai/react-bodyengine-three\":\"1.0.6\",\"@davi-ai/retorik-weather\":\"2.0.0\",\"@davi-ai/speechmarkdown-davi-js\":\"2.0.1\",\"@davi-ai/web-speech-cognitive-services-davi\":\"2.0.10\",\"@lottiefiles/react-lottie-player\":\"^3.4.1\",\"@opentelemetry/api\":\"^1.9.0\",\"@opentelemetry/exporter-trace-otlp-http\":\"^0.200.0\",\"@opentelemetry/instrumentation\":\"^0.200.0\",\"@opentelemetry/instrumentation-document-load\":\"^0.45.0\",\"@opentelemetry/instrumentation-fetch\":\"^0.200.0\",\"@opentelemetry/resources\":\"^2.0.0\",\"@opentelemetry/sdk-trace-web\":\"^2.0.0\",\"@opentelemetry/semantic-conventions\":\"^1.32.0\",\"@react-spring/types\":\"^9.7.3\",\"@react-spring/web\":\"^9.7.3\",\"@swc/helpers\":\"^0.5.0\",\"@types/geojson\":\"^7946.0.10\",\"@types/jsdom\":\"^16.2.14\",\"@use-gesture/react\":\"^10.2.15\",\"adaptivecards\":\"3.0.1\",\"botframework-directlinejs\":\"^0.15.5\",\"classnames\":\"^2.3.1\",\"detect-gpu\":\"^5.0.70\",\"leaflet\":\"^1.9.2\",\"markdown-it\":\"14.1.0\",\"pdfjs-dist\":\"3.11.174\",\"postcss-copy\":\"^7.1.0\",\"qrcode\":\"^1.5.1\",\"react-device-detect\":\"^2.2.3\",\"react-error-boundary\":\"^4.0.10\",\"react-leaflet\":\"^4.1.0\",\"react-pdf\":\"7.7.1\",\"react-shadow\":\"^20.5.0\",\"swiper\":\"^8.4.5\",\"zustand\":\"^5.0.3\"},\"overrides\":{\"@davi-ai/web-speech-cognitive-services-davi\":\"$@davi-ai/web-speech-cognitive-services-davi\",\"zustand\":\"$zustand\"},\"@parcel/resolver-default\":{\"packageExports\":true}}");
4350
+ module.exports = JSON.parse("{\"name\":\"@davi-ai/retorik-framework\",\"version\":\"3.2.4\",\"description\":\"Retorik Framework package\",\"author\":\"DAVI\",\"license\":\"MIT\",\"repository\":\"none\",\"main\":\"dist/index.js\",\"module\":\"dist/index.modern.js\",\"types\":\"dist/index.d.ts\",\"source\":\"src/index.tsx\",\"standalone\":\"standalone/index.js\",\"targets\":{\"standalone\":{\"context\":\"browser\",\"outputFormat\":\"esmodule\",\"distDir\":\"standalone\"},\"module\":{\"context\":\"browser\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\"}},\"engines\":{\"node\":\">=10\"},\"scripts\":{\"build\":\"parcel build\",\"start\":\"parcel watch\",\"test\":\"jest --env=jsdom --reporters=jest-junit\",\"test-console\":\"jest --env=jsdom\",\"test-update-snapshots\":\"jest --env=jsdom --updateSnapshot\",\"test-coverage-console\":\"jest --env=jsdom --reporters=jest-junit --coverage\",\"test-coverage\":\"jest --env=jsdom --reporters=jest-junit --coverage --coverageReporters=cobertura\",\"report\":\"npx parcel build src/index.tsx --reporter @parcel/reporter-bundle-analyzer\",\"credentials\":\"vsts-npm-auth -config .npmrc\"},\"peerDependencies\":{\"react\":\"18.3.1\",\"react-dom\":\"18.3.1\"},\"devDependencies\":{\"@babel/core\":\"^7.19.1\",\"@babel/plugin-proposal-decorators\":\"^7.24.7\",\"@babel/plugin-proposal-private-property-in-object\":\"^7.21.11\",\"@babel/preset-env\":\"^7.25.4\",\"@babel/preset-react\":\"^7.24.7\",\"@babel/preset-typescript\":\"^7.24.7\",\"@babel/runtime\":\"^7.23.8\",\"@parcel/packager-ts\":\"^2.13.2\",\"@parcel/reporter-bundle-analyzer\":\"^2.13.2\",\"@parcel/reporter-sourcemap-visualiser\":\"^2.13.2\",\"@parcel/transformer-inline-string\":\"^2.13.2\",\"@parcel/transformer-typescript-types\":\"^2.13.2\",\"@parcel/validator-eslint\":\"^2.13.2\",\"@parcel/validator-typescript\":\"^2.13.2\",\"@testing-library/dom\":\"^10.4.0\",\"@testing-library/jest-dom\":\"6.5.0\",\"@testing-library/react\":\"16.0.1\",\"@testing-library/react-hooks\":\"8.0.1\",\"@testing-library/user-event\":\"14.5.2\",\"@types/jest\":\"^27.5.1\",\"@types/leaflet\":\"^1.8.0\",\"@types/node\":\"^12.12.38\",\"@types/react\":\"18.3.12\",\"@types/react-dom\":\"18.3.1\",\"@types/testing-library__jest-dom\":\"^5.14.5\",\"@types/testing-library__react\":\"latest\",\"@typescript-eslint/eslint-plugin\":\"^8.19.0\",\"@typescript-eslint/parser\":\"^8.19.0\",\"autoprefixer\":\"^10.4.7\",\"babel-eslint\":\"^10.0.3\",\"babel-jest\":\"^29.7.0\",\"babel-loader\":\"^8.2.5\",\"buffer\":\"^5.7.1\",\"canvas\":\"^2.9.0\",\"cross-env\":\"^7.0.2\",\"crypto-browserify\":\"^3.12.0\",\"eslint\":\"^9.16.0\",\"eslint-config-prettier\":\"^9.1.0\",\"eslint-config-standard\":\"^17.1.0\",\"eslint-config-standard-react\":\"^13.0.0\",\"eslint-plugin-import\":\"^2.31.0\",\"eslint-plugin-node\":\"^11.1.0\",\"eslint-plugin-prettier\":\"^5.2.1\",\"eslint-plugin-promise\":\"^7.2.1\",\"eslint-plugin-react\":\"^7.37.2\",\"https-browserify\":\"^1.0.0\",\"jest\":\"^29.7.0\",\"jest-environment-jsdom\":\"^29.7.0\",\"jest-junit\":\"16.0.0\",\"npm-run-all\":\"^4.1.5\",\"parcel\":\"^2.13.2\",\"postcss\":\"^8.4.14\",\"postcss-url\":\"^10.1.3\",\"prettier\":\"^2.0.4\",\"process\":\"^0.11.10\",\"punycode\":\"^1.4.1\",\"querystring-es3\":\"^0.2.1\",\"react\":\"^18\",\"react-docgen-typescript-plugin\":\"^1.0.5\",\"react-dom\":\"18.3.1\",\"react-test-renderer\":\"^18.3.1\",\"resize-observer-polyfill\":\"^1.5.1\",\"stream-browserify\":\"^3.0.0\",\"stream-http\":\"^3.2.0\",\"string_decoder\":\"^1.3.0\",\"tailwindcss\":\"^3.1.0\",\"typescript\":\"5.3.2\",\"url\":\"^0.11.0\",\"util\":\"^0.12.4\"},\"files\":[\"dist\"],\"dependencies\":{\"@davi-ai/body-engine-sprite\":\"3.0.0\",\"@davi-ai/react-bodyengine-three\":\"1.0.6\",\"@davi-ai/retorik-weather\":\"2.0.0\",\"@davi-ai/speechmarkdown-davi-js\":\"2.0.1\",\"@davi-ai/web-speech-cognitive-services-davi\":\"2.0.10\",\"@lottiefiles/react-lottie-player\":\"^3.4.1\",\"@opentelemetry/api\":\"^1.9.0\",\"@opentelemetry/exporter-trace-otlp-http\":\"^0.200.0\",\"@opentelemetry/instrumentation\":\"^0.200.0\",\"@opentelemetry/instrumentation-document-load\":\"^0.45.0\",\"@opentelemetry/instrumentation-fetch\":\"^0.200.0\",\"@opentelemetry/resources\":\"^2.0.0\",\"@opentelemetry/sdk-trace-web\":\"^2.0.0\",\"@opentelemetry/semantic-conventions\":\"^1.32.0\",\"@react-spring/types\":\"^9.7.3\",\"@react-spring/web\":\"^9.7.3\",\"@swc/helpers\":\"^0.5.0\",\"@types/geojson\":\"^7946.0.10\",\"@types/jsdom\":\"^16.2.14\",\"@use-gesture/react\":\"^10.2.15\",\"adaptivecards\":\"3.0.1\",\"botframework-directlinejs\":\"^0.15.5\",\"classnames\":\"^2.3.1\",\"detect-gpu\":\"^5.0.70\",\"leaflet\":\"^1.9.2\",\"markdown-it\":\"14.1.0\",\"pdfjs-dist\":\"3.11.174\",\"postcss-copy\":\"^7.1.0\",\"qrcode\":\"^1.5.1\",\"react-device-detect\":\"^2.2.3\",\"react-error-boundary\":\"^4.0.10\",\"react-leaflet\":\"^4.1.0\",\"react-pdf\":\"7.7.1\",\"react-shadow\":\"^20.5.0\",\"swiper\":\"^8.4.5\",\"zustand\":\"^5.0.3\"},\"overrides\":{\"@davi-ai/web-speech-cognitive-services-davi\":\"$@davi-ai/web-speech-cognitive-services-davi\",\"zustand\":\"$zustand\"},\"@parcel/resolver-default\":{\"packageExports\":true}}");
4396
4351
 
4397
4352
  });
4398
4353
 
@@ -5506,23 +5461,24 @@ const $071bb34c9db044ce$var$SendActivityEventListener = ({ isRetorikNews: isReto
5506
5461
  document.removeEventListener('retorikSetVisibility', handleEvents);
5507
5462
  };
5508
5463
  }, []);
5509
- (0, $dWhh5$react.useEffect)(()=>{
5510
- if (isRetorikNews || hasConversationCookie) setUserAlreadySet(true);
5511
- else if (!userAlreadySet && appAvailable && !displayGDPR && characterLoaded) {
5512
- setUserAlreadySet(true);
5513
- // Send mandatory events : setUser to start conversation, Davi.GDPRConsent for GDPR module
5514
- sendEvent('setUser', {
5464
+ /**
5465
+ * Send mandatory events : setUser to start conversation, Davi.GDPRConsent for GDPR module
5466
+ */ const sendMandatoryEvents = async ()=>{
5467
+ sendEvent('Davi.GDPRConsent', {
5468
+ userConsent: userConsent
5469
+ }, ()=>sendEvent('setUser', {
5515
5470
  user: {
5516
5471
  ...userData,
5517
5472
  gdprConsent: true
5518
5473
  },
5519
5474
  skipWelcome: !!skipWelcome
5520
- });
5521
- setTimeout(()=>{
5522
- sendEvent('Davi.GDPRConsent', {
5523
- userConsent: userConsent
5524
- });
5525
- }, 100);
5475
+ }));
5476
+ };
5477
+ (0, $dWhh5$react.useEffect)(()=>{
5478
+ if (isRetorikNews || hasConversationCookie) setUserAlreadySet(true);
5479
+ else if (!userAlreadySet && appAvailable && !displayGDPR && characterLoaded) {
5480
+ setUserAlreadySet(true);
5481
+ sendMandatoryEvents();
5526
5482
  }
5527
5483
  }, [
5528
5484
  appAvailable,
@@ -7738,8 +7694,7 @@ const $7a4829033e41af4d$var$List = ({ activity: activity, onClose: onClose })=>{
7738
7694
  if (timerRef) {
7739
7695
  timerRef.current && clearTimeout(timerRef.current);
7740
7696
  timerRef.current = setTimeout(()=>{
7741
- sendEvent('Davi.CloseWindow', null);
7742
- sendEvent('Davi.CloseWindowList', null);
7697
+ sendEvent('Davi.CloseWindow', null, ()=>sendEvent('Davi.CloseWindowList', null));
7743
7698
  onClose === null || onClose === void 0 ? void 0 : onClose();
7744
7699
  setContent(undefined);
7745
7700
  }, $7a4829033e41af4d$var$springLeaveDuration);
@@ -7799,7 +7754,6 @@ const $7a4829033e41af4d$var$List = ({ activity: activity, onClose: onClose })=>{
7799
7754
  (0, $dWhh5$react.useEffect)(()=>{
7800
7755
  handleOpen();
7801
7756
  return ()=>{
7802
- console.log('in return');
7803
7757
  setListStatus((0, $7WHA7.ListStatus).closed);
7804
7758
  (timerRef === null || timerRef === void 0 ? void 0 : timerRef.current) && clearTimeout(timerRef.current);
7805
7759
  };
@@ -15367,17 +15321,17 @@ var $f0e30ad3081b61d6$export$2e2bcd8739ae039 = $f0e30ad3081b61d6$var$Grid;
15367
15321
 
15368
15322
 
15369
15323
  parcelRegister("daT1M", function(module, exports) {
15370
- module.exports = Promise.resolve(require("./HistoryList.50ff0fd9.js")).then(()=>parcelRequire('1TROp'));
15324
+ module.exports = Promise.resolve(require("./HistoryList.4c303dc6.js")).then(()=>parcelRequire('1TROp'));
15371
15325
 
15372
15326
  });
15373
15327
 
15374
15328
  parcelRegister("8A8vC", function(module, exports) {
15375
- module.exports = Promise.resolve(require("./LanguageChoice.1579b654.js")).then(()=>parcelRequire('cMcsq'));
15329
+ module.exports = Promise.resolve(require("./LanguageChoice.ff0cd04c.js")).then(()=>parcelRequire('cMcsq'));
15376
15330
 
15377
15331
  });
15378
15332
 
15379
15333
  parcelRegister("ahTaB", function(module, exports) {
15380
- module.exports = Promise.resolve(require("./AttachmentDetail.1e06c2a5.js")).then(()=>parcelRequire('27nhc'));
15334
+ module.exports = Promise.resolve(require("./AttachmentDetail.cfd86776.js")).then(()=>parcelRequire('27nhc'));
15381
15335
 
15382
15336
  });
15383
15337
 
@@ -15387,17 +15341,17 @@ module.exports = Promise.resolve(require("./FullScreenImage.9a9b978e.js")).then(
15387
15341
  });
15388
15342
 
15389
15343
  parcelRegister("jQXZd", function(module, exports) {
15390
- module.exports = Promise.resolve(require("./Weather.661c2cac.js")).then(()=>parcelRequire('j5z2A'));
15344
+ module.exports = Promise.resolve(require("./Weather.99917b66.js")).then(()=>parcelRequire('j5z2A'));
15391
15345
 
15392
15346
  });
15393
15347
 
15394
15348
  parcelRegister("kVj24", function(module, exports) {
15395
- module.exports = Promise.resolve(require("./CustomView.080c8028.js")).then(()=>parcelRequire('h8y4X'));
15349
+ module.exports = Promise.resolve(require("./CustomView.ba7af9b6.js")).then(()=>parcelRequire('h8y4X'));
15396
15350
 
15397
15351
  });
15398
15352
 
15399
15353
  parcelRegister("2J06a", function(module, exports) {
15400
- module.exports = Promise.resolve(require("./Emergency.423214ad.js")).then(()=>parcelRequire('5Osom'));
15354
+ module.exports = Promise.resolve(require("./Emergency.897ee3c7.js")).then(()=>parcelRequire('5Osom'));
15401
15355
 
15402
15356
  });
15403
15357
 
@@ -17184,6 +17138,11 @@ const $b8818a8d75b2cc14$var$MicrophoneTextBubble = ({ showLoader: showLoader })=
17184
17138
  const [text, setText] = (0, $dWhh5$react.useState)();
17185
17139
  const [textUndefined, setTextUndefined] = (0, $dWhh5$react.useState)(false);
17186
17140
  const timerRef = (0, $dWhh5$react.useRef)(null);
17141
+ (0, $dWhh5$react.useEffect)(()=>{
17142
+ return ()=>{
17143
+ timerRef.current && clearTimeout(timerRef.current);
17144
+ };
17145
+ }, []);
17187
17146
  (0, $dWhh5$react.useEffect)(()=>{
17188
17147
  setTextUndefined(speaking || showLoader || !botAnswerEnded || currentSubView !== (0, $7WHA7.CurrentSubView).none || dashboardOpened || retorikEvent === (0, $7WHA7.RetorikEvent).DetailViewOpen || listStatus === (0, $7WHA7.ListStatus).opened);
17189
17148
  }, [
@@ -17213,8 +17172,12 @@ const $b8818a8d75b2cc14$var$MicrophoneTextBubble = ({ showLoader: showLoader })=
17213
17172
  setText(isMobile || isLandscape && lastRecognitionInterim ? undefined : translation.microphone.listening);
17214
17173
  break;
17215
17174
  case (0, $7WHA7.RecognitionState).Closed:
17216
- if (useContinuousRecognition) setText(textUndefined ? undefined : `<p>${translation.microphone.trigger}${isMobile ? ' ' : '<br />'}<strong>\xab ${agentData === null || agentData === void 0 ? void 0 : agentData.name} \xbb</strong></p>`);
17217
- else setText(textUndefined ? undefined : `<p>${translation.microphone.triggerwithoutname}</p>`);
17175
+ let text = undefined;
17176
+ if (!textUndefined) text = useContinuousRecognition ? `<p>${translation.microphone.trigger}${isMobile ? ' ' : '<br />'}<strong>\xab ${agentData === null || agentData === void 0 ? void 0 : agentData.name} \xbb</strong></p>` : `<p>${translation.microphone.triggerwithoutname}</p>`;
17177
+ // Show the button only 1.5s after, to prevents it from appearing à fraction of second between several texts
17178
+ timerRef.current = setTimeout(()=>{
17179
+ setText(text);
17180
+ }, 1500);
17218
17181
  break;
17219
17182
  case (0, $7WHA7.RecognitionState).Initializing:
17220
17183
  case (0, $7WHA7.RecognitionState).Closing:
@@ -18866,7 +18829,7 @@ var $341aa389b3b9926d$export$2e2bcd8739ae039 = $341aa389b3b9926d$var$DashboardIt
18866
18829
 
18867
18830
 
18868
18831
  parcelRegister("ffoK4", function(module, exports) {
18869
- module.exports = Promise.resolve(require("./NewsContainer.932174e9.js")).then(()=>parcelRequire('dKdsa'));
18832
+ module.exports = Promise.resolve(require("./NewsContainer.5e80336b.js")).then(()=>parcelRequire('dKdsa'));
18870
18833
 
18871
18834
  });
18872
18835
 
@@ -22521,7 +22484,6 @@ const $85d8b0d1ec40dae5$export$6108075486421829 = ()=>{
22521
22484
 
22522
22485
 
22523
22486
 
22524
-
22525
22487
  var $6EkQS = parcelRequire("6EkQS");
22526
22488
 
22527
22489
  var $6QoTL = parcelRequire("6QoTL");
@@ -22530,6 +22492,8 @@ var $e53vj = parcelRequire("e53vj");
22530
22492
 
22531
22493
  var $7sZDv = parcelRequire("7sZDv");
22532
22494
 
22495
+ var $7WHA7 = parcelRequire("7WHA7");
22496
+
22533
22497
  var $93cl9 = parcelRequire("93cl9");
22534
22498
  const $6be7f5aa73e32bf5$var$TelemetryContextDefaultValues = {
22535
22499
  enabled: true,
@@ -22543,19 +22507,41 @@ function $6be7f5aa73e32bf5$export$a15d15518a3ec33d() {
22543
22507
  }
22544
22508
  function $6be7f5aa73e32bf5$export$bb3ea6dd2428edb6({ enabled: enabled, children: children }) {
22545
22509
  const userId = (0, $6QoTL.useDirectlineStore)((state)=>state.userId);
22510
+ const conversationId = (0, $e53vj.useActivityStore)((state)=>state.conversationId);
22546
22511
  const addressData = (0, $6EkQS.useRetorikStore)((state)=>state.addressData);
22547
22512
  const lastActivity = (0, $e53vj.useActivityStore)((state)=>state.lastActivity);
22548
22513
  const botStreamingActivities = (0, $e53vj.useActivityStore)((state)=>state.botStreamingActivities);
22549
- const [lastUserActivityData, setLastUserActivityData] = (0, $dWhh5$react.useState)();
22514
+ const lastUserActivityRef = (0, $dWhh5$react.useRef)(null);
22550
22515
  const tracer = (0, $dWhh5$react.useMemo)(()=>{
22551
- if (enabled && userId) {
22516
+ if (enabled && userId && conversationId) {
22552
22517
  const exporter = new (0, $dWhh5$opentelemetryexportertraceotlphttp.OTLPTraceExporter)({
22553
22518
  url: (0, $7sZDv.telemetryAddress),
22554
22519
  headers: {},
22555
22520
  concurrencyLimit: 1
22556
22521
  });
22522
+ let serviceNamespace = '';
22523
+ switch(addressData.prefix){
22524
+ case 'dev':
22525
+ serviceNamespace = 'retorik-dev';
22526
+ break;
22527
+ case 'staging':
22528
+ case 'preview':
22529
+ serviceNamespace = 'retorik-preview';
22530
+ break;
22531
+ case 'experimental':
22532
+ serviceNamespace = 'retorik-experimental';
22533
+ break;
22534
+ default:
22535
+ serviceNamespace = 'retorik-prod';
22536
+ break;
22537
+ }
22538
+ // Create resource with custom parameters used globally in uptrace
22557
22539
  const resource = (0, $dWhh5$opentelemetryresources.defaultResource)().merge((0, $dWhh5$opentelemetryresources.resourceFromAttributes)({
22558
- [(0, $dWhh5$opentelemetrysemanticconventions.ATTR_SERVICE_NAME)]: 'retorik-framework'
22540
+ [(0, $dWhh5$opentelemetrysemanticconventions.ATTR_SERVICE_NAME)]: 'retorik-framework',
22541
+ ['davi_retorik_activity_conversation_id']: conversationId,
22542
+ ['service_namespace']: serviceNamespace,
22543
+ ['retorik_framework_version']: (0, $93cl9.version),
22544
+ ['user_id']: userId
22559
22545
  }));
22560
22546
  const processor = new (0, $dWhh5$opentelemetrysdktraceweb.BatchSpanProcessor)(exporter);
22561
22547
  const provider = new (0, $dWhh5$opentelemetrysdktraceweb.WebTracerProvider)({
@@ -22568,28 +22554,8 @@ function $6be7f5aa73e32bf5$export$bb3ea6dd2428edb6({ enabled: enabled, children:
22568
22554
  // Add common attributes to each span for better tracing
22569
22555
  (0, $dWhh5$opentelemetryinstrumentation.registerInstrumentations)({
22570
22556
  instrumentations: [
22571
- new (0, $dWhh5$opentelemetryinstrumentationfetch.FetchInstrumentation)({
22572
- applyCustomAttributesOnSpan: (span)=>span.setAttributes({
22573
- ...getCommonAttributes(),
22574
- user_id: userId
22575
- })
22576
- }),
22577
- new (0, $dWhh5$opentelemetryinstrumentationdocumentload.DocumentLoadInstrumentation)({
22578
- applyCustomAttributesOnSpan: {
22579
- documentLoad: (span)=>span.setAttributes({
22580
- ...getCommonAttributes(),
22581
- user_id: userId
22582
- }),
22583
- documentFetch: (span)=>span.setAttributes({
22584
- ...getCommonAttributes(),
22585
- user_id: userId
22586
- }),
22587
- resourceFetch: (span)=>span.setAttributes({
22588
- ...getCommonAttributes(),
22589
- user_id: userId
22590
- })
22591
- }
22592
- })
22557
+ new (0, $dWhh5$opentelemetryinstrumentationfetch.FetchInstrumentation)(),
22558
+ new (0, $dWhh5$opentelemetryinstrumentationdocumentload.DocumentLoadInstrumentation)()
22593
22559
  ]
22594
22560
  });
22595
22561
  return (0, ($parcel$interopDefault($dWhh5$opentelemetryapi))).trace.getTracer('retorik-framework');
@@ -22597,7 +22563,10 @@ function $6be7f5aa73e32bf5$export$bb3ea6dd2428edb6({ enabled: enabled, children:
22597
22563
  return undefined;
22598
22564
  }, [
22599
22565
  enabled,
22600
- userId
22566
+ userId,
22567
+ conversationId,
22568
+ addressData,
22569
+ (0, $93cl9.version)
22601
22570
  ]);
22602
22571
  (0, $dWhh5$react.useEffect)(()=>{
22603
22572
  if (lastActivity) lastActivity.from.role === 'user' ? handleUserActivity(lastActivity) : handleBotActivity(lastActivity);
@@ -22605,52 +22574,49 @@ function $6be7f5aa73e32bf5$export$bb3ea6dd2428edb6({ enabled: enabled, children:
22605
22574
  lastActivity
22606
22575
  ]);
22607
22576
  (0, $dWhh5$react.useEffect)(()=>{
22608
- if (lastUserActivityData) {
22609
- const temp = botStreamingActivities.get(lastUserActivityData.id);
22577
+ if (lastUserActivityRef.current) {
22578
+ const temp = botStreamingActivities.get(lastUserActivityRef.current.id);
22610
22579
  (temp === null || temp === void 0 ? void 0 : temp.length) === 1 && handleBotActivity(temp[0]);
22611
22580
  }
22612
22581
  }, [
22613
- botStreamingActivities,
22614
- lastUserActivityData
22582
+ botStreamingActivities
22615
22583
  ]);
22616
- const getCommonAttributes = ()=>{
22617
- let tenant = '';
22618
- if (addressData.tenant) tenant = addressData.prefix ? `${addressData.tenant} (${addressData.prefix})` : addressData.tenant;
22619
- return {
22620
- tenant: tenant,
22621
- current_URL: window.location.toString(),
22622
- os: `${0, $dWhh5$reactdevicedetect.osName} ${0, $dWhh5$reactdevicedetect.osVersion}`,
22623
- browser: `${0, $dWhh5$reactdevicedetect.browserName} ${0, $dWhh5$reactdevicedetect.browserVersion}`,
22624
- retorik_framework_version: (0, $93cl9.version)
22625
- };
22626
- };
22627
22584
  const handleUserActivity = (activity)=>{
22628
22585
  // Only handle message activites and event activities waiting for an answer, nothing for typing ones
22629
22586
  if (activity.type === 'message' || activity.type === 'event' && !(0, $7sZDv.nonResponseInducingEvents).find((eventName)=>{
22630
22587
  var _activity_name;
22631
22588
  return (_activity_name = activity.name) === null || _activity_name === void 0 ? void 0 : _activity_name.toLowerCase().includes(eventName);
22632
- })) setLastUserActivityData({
22589
+ })) lastUserActivityRef.current = {
22633
22590
  id: activity.id,
22634
22591
  time: Date.now()
22635
- });
22592
+ };
22636
22593
  };
22637
22594
  const handleBotActivity = (activity)=>{
22638
22595
  var _activity_name, _activity_label;
22639
22596
  // Do nothing for bring-up messages and non-streaming events
22640
- if (lastUserActivityData && (activity.type === 'message' || ((_activity_name = activity.name) === null || _activity_name === void 0 ? void 0 : _activity_name.toLocaleLowerCase()) === 'davi.streammessageactivity') && ((_activity_label = activity.label) === null || _activity_label === void 0 ? void 0 : _activity_label.toLowerCase()) !== 'davi.bringupmessage' && activity.replyToId === lastUserActivityData.id) {
22641
- sendTrace(lastUserActivityData.time);
22642
- setLastUserActivityData(undefined);
22597
+ if (lastUserActivityRef.current && (activity.type === 'message' || ((_activity_name = activity.name) === null || _activity_name === void 0 ? void 0 : _activity_name.toLocaleLowerCase()) === 'davi.streammessageactivity') && ((_activity_label = activity.label) === null || _activity_label === void 0 ? void 0 : _activity_label.toLowerCase()) !== 'davi.bringupmessage' && activity.replyToId === lastUserActivityRef.current.id) {
22598
+ sendTrace((0, $7WHA7.TraceType).message, lastUserActivityRef.current.time);
22599
+ lastUserActivityRef.current = null;
22643
22600
  }
22644
22601
  };
22645
- const sendTrace = (beginningTimer)=>{
22646
- if (tracer) {
22647
- const span = tracer.startSpan('directlineMessage', {
22648
- startTime: beginningTimer
22649
- });
22602
+ const sendTrace = (type, data)=>{
22603
+ if (tracer && type) {
22604
+ const parameters = {};
22605
+ switch(type){
22606
+ case (0, $7WHA7.TraceType).message:
22607
+ parameters.startTime = data;
22608
+ break;
22609
+ case (0, $7WHA7.TraceType).utteranceStart:
22610
+ parameters.text = data;
22611
+ break;
22612
+ case (0, $7WHA7.TraceType).utteranceEnd:
22613
+ parameters.text = data;
22614
+ break;
22615
+ }
22616
+ const span = tracer.startSpan(type, parameters);
22650
22617
  span.setStatus({
22651
22618
  code: (0, $dWhh5$opentelemetryapi.SpanStatusCode).OK
22652
22619
  });
22653
- span.setAttributes(getCommonAttributes());
22654
22620
  span.end();
22655
22621
  }
22656
22622
  };
@@ -22662,24 +22628,21 @@ function $6be7f5aa73e32bf5$export$bb3ea6dd2428edb6({ enabled: enabled, children:
22662
22628
  code: (0, $dWhh5$opentelemetryapi.SpanStatusCode).ERROR,
22663
22629
  message: `${error.message}`
22664
22630
  });
22665
- span.setAttributes(getCommonAttributes());
22666
22631
  span.end();
22667
22632
  }
22668
22633
  };
22669
22634
  const value = (0, $dWhh5$react.useMemo)(()=>({
22670
22635
  enabled: enabled,
22671
22636
  tracer: tracer,
22672
- sendErrorTrace: sendErrorTrace,
22673
- sendTrace: sendTrace
22637
+ sendTrace: sendTrace,
22638
+ sendErrorTrace: sendErrorTrace
22674
22639
  }), [
22675
22640
  enabled,
22676
22641
  tracer
22677
22642
  ]);
22678
- return /*#__PURE__*/ (0, $dWhh5$reactjsxruntime.jsx)((0, ($parcel$interopDefault($dWhh5$react))).Fragment, {
22679
- children: /*#__PURE__*/ (0, $dWhh5$reactjsxruntime.jsx)($6be7f5aa73e32bf5$export$7b6b7bc4acb29126.Provider, {
22680
- value: value,
22681
- children: children
22682
- })
22643
+ return /*#__PURE__*/ (0, $dWhh5$reactjsxruntime.jsx)($6be7f5aa73e32bf5$export$7b6b7bc4acb29126.Provider, {
22644
+ value: value,
22645
+ children: children
22683
22646
  });
22684
22647
  }
22685
22648
 
@@ -24058,11 +24021,19 @@ var $5f568a67e3f1c45c$export$2e2bcd8739ae039 = $5f568a67e3f1c45c$var$BotResponse
24058
24021
 
24059
24022
 
24060
24023
 
24024
+
24025
+ var $6EkQS = parcelRequire("6EkQS");
24061
24026
  parcelRequire("60kUR");
24062
24027
  var $6tJr6 = parcelRequire("6tJr6");
24063
24028
  const $190fac2b3b90e52b$var$RetorikLogo = ()=>{
24064
- return /*#__PURE__*/ (0, $dWhh5$reactjsxruntime.jsx)("a", {
24065
- href: "https://davi.ai/retorik",
24029
+ const isUsedOnBorne = (0, $6EkQS.useRetorikStore)((state)=>state.configuration.isUsedOnBorne);
24030
+ return isUsedOnBorne ? /*#__PURE__*/ (0, $dWhh5$reactjsxruntime.jsx)("div", {
24031
+ className: "rf-hidden large:rf-block rf-relative rf-z-[1] ltr:rf-col-start-1 rtl:rf-col-end-1 rf-col-span-full rf-row-start-12 rf-row-span-1 ltr:rf-self-end rtl:rf-self-start rf-justify-self-start",
24032
+ children: /*#__PURE__*/ (0, $dWhh5$reactjsxruntime.jsx)((0, $6tJr6.default), {
24033
+ className: "ltr:rf-ml-4 rtl:rf-mr-4 rf-mb-4 rf-h-14"
24034
+ })
24035
+ }) : /*#__PURE__*/ (0, $dWhh5$reactjsxruntime.jsx)("a", {
24036
+ href: "https://davi.ai",
24066
24037
  title: "Retorik by Davi",
24067
24038
  target: "_blank",
24068
24039
  rel: "noreferrer",
@@ -24331,8 +24302,6 @@ var $6EkQS = parcelRequire("6EkQS");
24331
24302
 
24332
24303
  var $e53vj = parcelRequire("e53vj");
24333
24304
 
24334
- var $jgaO0 = parcelRequire("jgaO0");
24335
-
24336
24305
 
24337
24306
  var $pFs7y = parcelRequire("pFs7y");
24338
24307
 
@@ -24449,8 +24418,6 @@ const $a2a195f52aaf1332$var$DisplayStandard = ({ currentQuestionId: currentQuest
24449
24418
  const endedActivities = (0, $e53vj.useActivityStore)((state)=>state.endedActivities);
24450
24419
  const watermark = (0, $e53vj.useActivityStore)((state)=>state.watermark);
24451
24420
  const forceMobileView = (0, $6EkQS.useRetorikStore)((state)=>state.configuration.forceMobileView);
24452
- const cancel = (0, $jgaO0.useSpeechStore)((state)=>state.cancel);
24453
- const addEndedActivity = (0, $e53vj.useActivityStore)((state)=>state.actions.addEndedActivity);
24454
24421
  const [displayData, setDisplayData] = (0, $dWhh5$react.useState)([]);
24455
24422
  const [currentDisplayDataIndex, setCurrentDisplayDataIndex] = (0, $dWhh5$react.useState)(0);
24456
24423
  const [ended, setEnded] = (0, $dWhh5$react.useState)(!activities.length || endedActivities.includes((_activities_ = activities[activities.length - 1]) === null || _activities_ === void 0 ? void 0 : _activities_.id));
@@ -24466,7 +24433,7 @@ const $a2a195f52aaf1332$var$DisplayStandard = ({ currentQuestionId: currentQuest
24466
24433
  ]);
24467
24434
  (0, $dWhh5$react.useEffect)(()=>{
24468
24435
  if (isWaitingForResponse) {
24469
- // Create temporary activity with the id of the nexxt one to prevent re-renders, in order to display waiting dots
24436
+ // Create temporary activity with the id of the next one to prevent re-renders, in order to display waiting dots
24470
24437
  const nextActivityId = `${currentQuestionId.slice(0, currentQuestionId.length - watermark.toString().length)}${watermark.toString()}`;
24471
24438
  const tempActivity = {
24472
24439
  id: nextActivityId,
@@ -24481,36 +24448,14 @@ const $a2a195f52aaf1332$var$DisplayStandard = ({ currentQuestionId: currentQuest
24481
24448
  activity: tempActivity,
24482
24449
  type: (0, $7WHA7.DisplayDataTypes).text,
24483
24450
  isWaitingDots: true,
24484
- canBeEnded: true
24451
+ canBeEnded: true,
24452
+ isEnded: false
24485
24453
  }
24486
24454
  ]);
24487
24455
  }
24488
24456
  }, [
24489
24457
  isWaitingForResponse
24490
24458
  ]);
24491
- (0, $dWhh5$react.useEffect)(()=>{
24492
- if (cancel) {
24493
- activities.forEach((activity)=>{
24494
- addEndedActivity(activity.id);
24495
- });
24496
- displayData.forEach((data)=>{
24497
- addEndedActivity(data.activity.id);
24498
- });
24499
- }
24500
- }, [
24501
- cancel
24502
- ]);
24503
- (0, $dWhh5$react.useEffect)(()=>{
24504
- // End all current activities on component unmount
24505
- return ()=>{
24506
- activitiesRef.current.forEach((activity)=>{
24507
- addEndedActivity(activity.id);
24508
- });
24509
- displayDataRef.current.forEach((data)=>{
24510
- addEndedActivity(data.activity.id);
24511
- });
24512
- };
24513
- }, []);
24514
24459
  (0, $dWhh5$react.useEffect)(()=>{
24515
24460
  activitiesRef.current = [
24516
24461
  ...activities
@@ -24523,7 +24468,7 @@ const $a2a195f52aaf1332$var$DisplayStandard = ({ currentQuestionId: currentQuest
24523
24468
  activities.forEach((activity, index)=>{
24524
24469
  var _activity_attachments, _activity_name, _activity_value;
24525
24470
  let splitTextDataToAdd = [];
24526
- // Check the attachments, special case if this is the message activity after streaming : show attachments if the first streaming activcity didn't have any
24471
+ // Check the attachments, special case if this is the message activity after streaming : show attachments if the first streaming activity didn't have any
24527
24472
  let attachments = [];
24528
24473
  if ((_activity_attachments = activity.attachments) === null || _activity_attachments === void 0 ? void 0 : _activity_attachments.length) {
24529
24474
  var _activity_name1, _activity_value1;
@@ -24533,14 +24478,16 @@ const $a2a195f52aaf1332$var$DisplayStandard = ({ currentQuestionId: currentQuest
24533
24478
  {
24534
24479
  type: (0, $7WHA7.DisplayDataTypes).attachment,
24535
24480
  activity: activity,
24536
- canBeEnded: true
24481
+ canBeEnded: true,
24482
+ isEnded: true
24537
24483
  }
24538
24484
  ];
24539
24485
  } else if (!(((_activity_value1 = activity.value) === null || _activity_value1 === void 0 ? void 0 : _activity_value1.streamingCount) && streamingActivityHasAttachment) && !(0, $1a0bdae30bc87d45$export$7c55936a30618336)(activity)) attachments = [
24540
24486
  {
24541
24487
  type: (0, $7WHA7.DisplayDataTypes).attachment,
24542
24488
  activity: activity,
24543
- canBeEnded: true
24489
+ canBeEnded: true,
24490
+ isEnded: true
24544
24491
  }
24545
24492
  ];
24546
24493
  }
@@ -24559,14 +24506,20 @@ const $a2a195f52aaf1332$var$DisplayStandard = ({ currentQuestionId: currentQuest
24559
24506
  ...currentFirstStreamingActivity,
24560
24507
  htmlText: (0, $pFs7y.processMarkdownAndSpeechMarkdown)(streamingTexts.join(''), false).htmlText
24561
24508
  },
24562
- canBeEnded: false
24509
+ canBeEnded: false,
24510
+ isEnded: false
24563
24511
  }
24564
24512
  ];
24565
24513
  }
24566
24514
  } else if ((_activity_value = activity.value) === null || _activity_value === void 0 ? void 0 : _activity_value.streamingCount) {
24567
24515
  if (tempDisplayData.length) {
24568
24516
  const lastStreamingIndex = tempDisplayData.findLastIndex((d)=>d.type === (0, $7WHA7.DisplayDataTypes).text);
24569
- lastStreamingIndex !== -1 && (tempDisplayData[lastStreamingIndex].canBeEnded = true);
24517
+ if (lastStreamingIndex !== -1) {
24518
+ // Set canBeEnded for the previous streaming
24519
+ tempDisplayData[lastStreamingIndex].canBeEnded = true;
24520
+ // Set previous streaming ended if this activity is ended in speech synthesis
24521
+ tempDisplayData[lastStreamingIndex].isEnded = endedActivities.includes(activity.id);
24522
+ }
24570
24523
  }
24571
24524
  // Reset streaming data if the message containing all streaming data is received
24572
24525
  currentFirstStreamingActivity = undefined;
@@ -24581,7 +24534,8 @@ const $a2a195f52aaf1332$var$DisplayStandard = ({ currentQuestionId: currentQuest
24581
24534
  {
24582
24535
  type: (0, $7WHA7.DisplayDataTypes).text,
24583
24536
  activity: activity,
24584
- canBeEnded: true
24537
+ canBeEnded: true,
24538
+ isEnded: endedActivities.includes(activity.id)
24585
24539
  }
24586
24540
  ];
24587
24541
  }
@@ -24603,7 +24557,8 @@ const $a2a195f52aaf1332$var$DisplayStandard = ({ currentQuestionId: currentQuest
24603
24557
  }
24604
24558
  }, [
24605
24559
  currentQuestionId,
24606
- activities.length
24560
+ activities.length,
24561
+ endedActivities
24607
24562
  ]);
24608
24563
  (0, $dWhh5$react.useEffect)(()=>{
24609
24564
  displayDataRef.current = [
@@ -24626,8 +24581,6 @@ const $a2a195f52aaf1332$var$DisplayStandard = ({ currentQuestionId: currentQuest
24626
24581
  ended
24627
24582
  ]);
24628
24583
  const handleEnded = ()=>{
24629
- var _displayData_currentDisplayDataIndex_activity, _displayData_currentDisplayDataIndex;
24630
- addEndedActivity((_displayData_currentDisplayDataIndex = displayData[currentDisplayDataIndex]) === null || _displayData_currentDisplayDataIndex === void 0 ? void 0 : (_displayData_currentDisplayDataIndex_activity = _displayData_currentDisplayDataIndex.activity) === null || _displayData_currentDisplayDataIndex_activity === void 0 ? void 0 : _displayData_currentDisplayDataIndex_activity.id);
24631
24584
  setCurrentDisplayDataIndex((current)=>current + 1);
24632
24585
  !ended && triggerScroll();
24633
24586
  };
@@ -24649,7 +24602,7 @@ const $a2a195f52aaf1332$var$DisplayStandard = ({ currentQuestionId: currentQuest
24649
24602
  triggerScroll: triggerScroll,
24650
24603
  onEnded: handleEnded,
24651
24604
  canBeEnded: data.canBeEnded,
24652
- isEnded: data.canBeEnded && endedActivities.includes(data.activity.id),
24605
+ isEnded: data.isEnded,
24653
24606
  isWaitingDots: data.isWaitingDots
24654
24607
  }, `${data.activity.id}-${key}`);
24655
24608
  }
@@ -25842,8 +25795,7 @@ const $3b4c49538547c1bc$var$WarningBeforeNewsView = ()=>{
25842
25795
  const sendEvent = (0, $6QoTL.useDirectlineStore)((state)=>state.actions.sendEvent);
25843
25796
  const [waiting, setWaiting] = (0, $dWhh5$react.useState)(true);
25844
25797
  const handleClick = (goHome)=>{
25845
- sendEvent('Davi.CloseWindow', null);
25846
- sendEvent('Davi.CloseWindowNewsSoundActivated', null);
25798
+ sendEvent('Davi.CloseWindow', null, ()=>sendEvent('Davi.CloseWindowNewsSoundActivated', null));
25847
25799
  goHome ? setRoute((0, $7WHA7.Routes).Home) : setWaiting(false);
25848
25800
  };
25849
25801
  return waiting ? /*#__PURE__*/ (0, $dWhh5$reactjsxruntime.jsxs)("div", {
@@ -26215,29 +26167,6 @@ var $6EkQS = parcelRequire("6EkQS");
26215
26167
  var $6QoTL = parcelRequire("6QoTL");
26216
26168
 
26217
26169
  var $7WHA7 = parcelRequire("7WHA7");
26218
- /* Return codes:
26219
- 0 => do nothing
26220
- 1 => add to queue
26221
- 2 => stop current activity + change to the one tested
26222
- */ const $549323f244f4782c$var$checkLastbotActivity = (lastbotActivity, currentPlaying, currentReplyToId, queuedActivities, endedActivities)=>{
26223
- // Check if the activity is the one currently being played
26224
- if (lastbotActivity.id === currentPlaying.id) return 0;
26225
- // Check if the activity has already been ended
26226
- if (endedActivities.includes(lastbotActivity.id)) return 0;
26227
- // Check if the activity has the same replyToId than the one currently being played
26228
- if (lastbotActivity.replyToId === currentReplyToId) {
26229
- // Check if the activity is already in the queue
26230
- let count = 0;
26231
- if (queuedActivities.length > 0) queuedActivities.forEach((activity)=>{
26232
- if (activity.id === lastbotActivity.id) count++;
26233
- });
26234
- if (count === 0) return 1;
26235
- else return 0;
26236
- } else return 2;
26237
- };
26238
- var $549323f244f4782c$export$2e2bcd8739ae039 = $549323f244f4782c$var$checkLastbotActivity;
26239
-
26240
-
26241
26170
 
26242
26171
 
26243
26172
 
@@ -26832,7 +26761,8 @@ const $d31b268c3b702355$var$RetorikSpeech = ({ ponyfill: ponyfill, onEnd: onEnd,
26832
26761
  const microphoneCloseAudioRef = (0, $dWhh5$react.useRef)(null);
26833
26762
  const [DBReady, setDBReady] = (0, $dWhh5$react.useState)(false);
26834
26763
  const [playingBlob, setPlayingBlob] = (0, $dWhh5$react.useState)(false);
26835
- const [nextUtteranceData, setNextUtteranceData] = (0, $dWhh5$react.useState)(null);
26764
+ const nextUtteranceDataRef = (0, $dWhh5$react.useRef)(null);
26765
+ const nextUtteranceTextRef = (0, $dWhh5$react.useRef)(null);
26836
26766
  const nextUtteranceBoundariesRef = (0, $dWhh5$react.useRef)([]);
26837
26767
  const nextUtteranceVisemesRef = (0, $dWhh5$react.useRef)([]);
26838
26768
  const emptyTextUtteranceRef = (0, $dWhh5$react.useRef)(null);
@@ -26847,7 +26777,7 @@ const $d31b268c3b702355$var$RetorikSpeech = ({ ponyfill: ponyfill, onEnd: onEnd,
26847
26777
  if (appAvailable || loaderClosed) {
26848
26778
  var _audioRef_current;
26849
26779
  // Cancel synthesis if using synthesizer
26850
- if (!playingBlob) ponyfill && ponyfill.speechSynthesis.cancel();
26780
+ if (!playingBlob) ponyfill.speechSynthesis.cancel();
26851
26781
  resetNextUtteranceData();
26852
26782
  if (audioRef.current && !((_audioRef_current = audioRef.current) === null || _audioRef_current === void 0 ? void 0 : _audioRef_current.paused)) {
26853
26783
  audioRef.current.pause();
@@ -26857,7 +26787,7 @@ const $d31b268c3b702355$var$RetorikSpeech = ({ ponyfill: ponyfill, onEnd: onEnd,
26857
26787
  };
26858
26788
  const attachEvents = (tempUtterance, isMainUtterance)=>{
26859
26789
  tempUtterance.onerror = (event)=>{
26860
- isMainUtterance ? handleError(event) : setNextUtteranceData(null);
26790
+ isMainUtterance ? handleError(event) : nextUtteranceDataRef.current = null;
26861
26791
  };
26862
26792
  tempUtterance.onsynthesiscompleted = ()=>{
26863
26793
  const endBoundary = {
@@ -26924,29 +26854,34 @@ const $d31b268c3b702355$var$RetorikSpeech = ({ ponyfill: ponyfill, onEnd: onEnd,
26924
26854
  return tempUtterance;
26925
26855
  };
26926
26856
  const processNextData = (data)=>{
26927
- setNextUtteranceData((data === null || data === void 0 ? void 0 : data.byteLength) ? {
26928
- speechData: data,
26929
- boundaries: nextUtteranceBoundariesRef.current,
26930
- visemes: nextUtteranceVisemesRef.current
26931
- } : null);
26857
+ nextUtteranceDataRef.current = (data === null || data === void 0 ? void 0 : data.byteLength) && nextUtteranceTextRef.current ? {
26858
+ text: nextUtteranceTextRef.current,
26859
+ data: {
26860
+ speechData: data,
26861
+ boundaries: nextUtteranceBoundariesRef.current,
26862
+ visemes: nextUtteranceVisemesRef.current
26863
+ }
26864
+ } : null;
26932
26865
  // Reset boundary / viseme data
26933
26866
  resetNextUtteranceData(true);
26934
26867
  };
26935
26868
  const resetNextUtteranceData = (keepArrayBufferData)=>{
26936
- !keepArrayBufferData && setNextUtteranceData(null);
26869
+ !keepArrayBufferData && (nextUtteranceDataRef.current = null);
26870
+ nextUtteranceTextRef.current = null;
26937
26871
  nextUtteranceBoundariesRef.current = [];
26938
26872
  nextUtteranceVisemesRef.current = [];
26939
26873
  };
26940
26874
  (0, $dWhh5$react.useEffect)(()=>{
26941
26875
  if (utterance) {
26942
26876
  if (utterance.text) {
26943
- if (ponyfill && (audioRef === null || audioRef === void 0 ? void 0 : audioRef.current)) {
26944
- if (nextUtteranceData) {
26945
- boundaryRef.current = nextUtteranceData.boundaries;
26946
- setBoundaryData(nextUtteranceData.boundaries);
26947
- setVisemeData(nextUtteranceData.visemes);
26948
- processData(nextUtteranceData.speechData, true);
26949
- } else // Play utterance whether by asking for a speech synthesis, or by retrieving data fro indexeddb
26877
+ if (audioRef === null || audioRef === void 0 ? void 0 : audioRef.current) {
26878
+ var _nextUtteranceDataRef_current;
26879
+ if (((_nextUtteranceDataRef_current = nextUtteranceDataRef.current) === null || _nextUtteranceDataRef_current === void 0 ? void 0 : _nextUtteranceDataRef_current.text) === utterance.text && nextUtteranceDataRef.current.data) {
26880
+ boundaryRef.current = nextUtteranceDataRef.current.data.boundaries;
26881
+ setBoundaryData(nextUtteranceDataRef.current.data.boundaries);
26882
+ setVisemeData(nextUtteranceDataRef.current.data.visemes);
26883
+ processData(nextUtteranceDataRef.current.data.speechData, true);
26884
+ } else // Play utterance whether by asking for a speech synthesis, or by retrieving data from indexedDB
26950
26885
  playUtterance(attachEvents(utterance, true));
26951
26886
  } else stopCurrentPlaying();
26952
26887
  } else handleEmptyTextUtterance();
@@ -26955,8 +26890,10 @@ const $d31b268c3b702355$var$RetorikSpeech = ({ ponyfill: ponyfill, onEnd: onEnd,
26955
26890
  utterance
26956
26891
  ]);
26957
26892
  (0, $dWhh5$react.useEffect)(()=>{
26958
- if ((nextUtterance === null || nextUtterance === void 0 ? void 0 : nextUtterance.text) && ponyfill) {
26893
+ // If there are data in nextUtteranceTextRef, this means the previous synthesis data retrieval is not finished, so we don't begin a new one
26894
+ if ((nextUtterance === null || nextUtterance === void 0 ? void 0 : nextUtterance.text) && !nextUtteranceTextRef.current) {
26959
26895
  const tempUtterance = attachEvents(nextUtterance);
26896
+ nextUtteranceTextRef.current = nextUtterance.text;
26960
26897
  ponyfill.speechSynthesis.synthesizeAndGetArrayData(tempUtterance, processNextData);
26961
26898
  } else resetNextUtteranceData();
26962
26899
  }, [
@@ -26964,14 +26901,14 @@ const $d31b268c3b702355$var$RetorikSpeech = ({ ponyfill: ponyfill, onEnd: onEnd,
26964
26901
  ]);
26965
26902
  const playUtterance = async (utt)=>{
26966
26903
  if (DBReady && enableSpeechCaching !== false && utt) {
26967
- const dataFromIndexedDB = await $d31b268c3b702355$var$DBManager.getSpeechData(`${locale}.${voice === null || voice === void 0 ? void 0 : voice.name}.${utt.text.replace($d31b268c3b702355$var$tagsRemoverRegex, '').substring(0, 50)}`);
26904
+ const dataFromIndexedDB = await $d31b268c3b702355$var$DBManager.getSpeechData(`${locale}.${voice === null || voice === void 0 ? void 0 : voice.name}.${utt.text.replace($d31b268c3b702355$var$tagsRemoverRegex, '')}`);
26968
26905
  if (dataFromIndexedDB) {
26969
26906
  boundaryRef.current = dataFromIndexedDB.boundaries;
26970
26907
  setBoundaryData(dataFromIndexedDB.boundaries);
26971
26908
  setVisemeData(dataFromIndexedDB.visemes || []);
26972
26909
  processData(dataFromIndexedDB.value, true);
26973
- } else ponyfill === null || ponyfill === void 0 ? void 0 : ponyfill.speechSynthesis.synthesizeAndGetArrayData(utt, processData);
26974
- } else ponyfill === null || ponyfill === void 0 ? void 0 : ponyfill.speechSynthesis.synthesizeAndGetArrayData(utt, processData);
26910
+ } else ponyfill.speechSynthesis.synthesizeAndGetArrayData(utt, processData);
26911
+ } else ponyfill.speechSynthesis.synthesizeAndGetArrayData(utt, processData);
26975
26912
  };
26976
26913
  const processData = (data, alreadyExistsInDB)=>{
26977
26914
  if (data === null || data === void 0 ? void 0 : data.byteLength) {
@@ -26981,7 +26918,7 @@ const $d31b268c3b702355$var$RetorikSpeech = ({ ponyfill: ponyfill, onEnd: onEnd,
26981
26918
  type: 'audio/mp3'
26982
26919
  });
26983
26920
  enableSpeechCaching !== false && !alreadyExistsInDB && DBReady && (boundaryRef === null || boundaryRef === void 0 ? void 0 : boundaryRef.current) && utterance && $d31b268c3b702355$var$DBManager.addSpeechData({
26984
- id: `${locale}.${voice === null || voice === void 0 ? void 0 : voice.name}.${utterance.text.replace($d31b268c3b702355$var$tagsRemoverRegex, '').substring(0, 50)}`,
26921
+ id: `${locale}.${voice === null || voice === void 0 ? void 0 : voice.name}.${utterance.text.replace($d31b268c3b702355$var$tagsRemoverRegex, '')}`,
26985
26922
  value: data,
26986
26923
  boundaries: boundaryRef.current,
26987
26924
  visemes: visemeRef.current || []
@@ -27006,13 +26943,13 @@ const $d31b268c3b702355$var$RetorikSpeech = ({ ponyfill: ponyfill, onEnd: onEnd,
27006
26943
  };
27007
26944
  const handleEnd = ()=>{
27008
26945
  if (appAvailable || loaderClosed) {
27009
- onEnd && onEnd();
26946
+ onEnd === null || onEnd === void 0 ? void 0 : onEnd();
27010
26947
  resetData();
27011
26948
  } else setLoaderClosed(true);
27012
26949
  };
27013
26950
  const handleError = (error)=>{
27014
- console.log('Error : ', error);
27015
- onError && onError();
26951
+ console.log('Retorik Framework > speech synthesis error ', error);
26952
+ onError === null || onError === void 0 ? void 0 : onError();
27016
26953
  resetData();
27017
26954
  };
27018
26955
  const handleEmptyTextUtterance = ()=>{
@@ -27027,7 +26964,7 @@ const $d31b268c3b702355$var$RetorikSpeech = ({ ponyfill: ponyfill, onEnd: onEnd,
27027
26964
  * - play 1 second muted sound to prime audio output
27028
26965
  * - MANDATORY FOR SAFARI IN VOCAL MODE
27029
26966
  */ const primeRetorikSpeech = ()=>{
27030
- if (ponyfill && audioRef.current) {
26967
+ if (audioRef.current) {
27031
26968
  audioRef.current.play().catch((e)=>console.warn(e));
27032
26969
  (speechRecognitionAudioRef === null || speechRecognitionAudioRef === void 0 ? void 0 : speechRecognitionAudioRef.current) && speechRecognitionAudioRef.current.play().catch((e)=>console.warn(e));
27033
26970
  // Send animation start event to secure animation not playing on safari if permissions are not sufficient
@@ -27038,13 +26975,6 @@ const $d31b268c3b702355$var$RetorikSpeech = ({ ponyfill: ponyfill, onEnd: onEnd,
27038
26975
  * Play sound on speech recognition activation if it isn't disabled in configuration
27039
26976
  */ (0, $dWhh5$react.useEffect)(()=>{
27040
26977
  var _speechRecognitionAudioRef_current;
27041
- // if (
27042
- // !!speechRecognitionOptions?.enableActivationSound &&
27043
- // activeRecognitionState === RecognitionState.Listening
27044
- // ) {
27045
- // speechRecognitionAudioRef?.current &&
27046
- // speechRecognitionAudioRef.current.play().catch((e) => console.warn(e))
27047
- // }
27048
26978
  if (useOldRemote) {
27049
26979
  if (!!(speechRecognitionOptions === null || speechRecognitionOptions === void 0 ? void 0 : speechRecognitionOptions.enableActivationSound) && activeRecognitionState === (0, $7WHA7.RecognitionState).Listening) speechRecognitionAudioRef === null || speechRecognitionAudioRef === void 0 ? void 0 : (_speechRecognitionAudioRef_current = speechRecognitionAudioRef.current) === null || _speechRecognitionAudioRef_current === void 0 ? void 0 : _speechRecognitionAudioRef_current.play().catch((e)=>console.warn(e));
27050
26980
  } else if (!!(speechRecognitionOptions === null || speechRecognitionOptions === void 0 ? void 0 : speechRecognitionOptions.enableActivationSound)) switch(activeRecognitionState){
@@ -27103,11 +27033,7 @@ var $d31b268c3b702355$export$2e2bcd8739ae039 = $d31b268c3b702355$var$RetorikSpee
27103
27033
 
27104
27034
  const $ad561f5c61e38c20$var$SynthesisManager = ({ ponyfill: ponyfill, isRetorikNews: isRetorikNews })=>{
27105
27035
  const cancel = (0, $jgaO0.useSpeechStore)((state)=>state.cancel);
27106
- const streamingReplyToId = (0, $jgaO0.useSpeechStore)((state)=>state.streamingReplyToId);
27107
27036
  const streamingQueue = (0, $jgaO0.useSpeechStore)((state)=>state.streamingQueue);
27108
- const currentPlaying = (0, $jgaO0.useSpeechStore)((state)=>state.currentPlaying);
27109
- const currentReplyToId = (0, $jgaO0.useSpeechStore)((state)=>state.currentReplyToId);
27110
- const endedActivities = (0, $jgaO0.useSpeechStore)((state)=>state.endedActivities);
27111
27037
  const voice = (0, $jgaO0.useSpeechStore)((state)=>state.voice);
27112
27038
  const customVoice = (0, $jgaO0.useSpeechStore)((state)=>state.customVoice);
27113
27039
  const activeRecognitionState = (0, $jgaO0.useSpeechStore)((state)=>state.activeRecognitionState);
@@ -27120,24 +27046,17 @@ const $ad561f5c61e38c20$var$SynthesisManager = ({ ponyfill: ponyfill, isRetorikN
27120
27046
  const appAvailable = (0, $6EkQS.useRetorikStore)((state)=>state.appAvailable);
27121
27047
  const preventExpectedInputHint = (0, $6EkQS.useRetorikStore)((state)=>state.configuration.preventExpectedInputHint);
27122
27048
  const speechSynthesisOptions = (0, $6EkQS.useRetorikStore)((state)=>state.configuration.speechSynthesisOptions);
27123
- const currentNewsActivity = (0, $7eio0.useUtilsStore)((state)=>state.currentNewsActivity);
27124
- const lastBotActivity = (0, $e53vj.useActivityStore)((state)=>state.lastBotMessageActivity);
27125
27049
  const checkReplacementLocale = (0, $6Q0mk.useLocaleStore)((state)=>state.actions.checkReplacementLocale);
27126
27050
  const setRetorikNewsEnded = (0, $7eio0.useUtilsStore)((state)=>state.actions.setRetorikNewsEnded);
27127
- const { resetCancelCurrentUtterance: resetCancelCurrentUtterance, setSpeaking: setSpeaking, setCurrentPlaying: setCurrentPlaying, setCurrentReplyToId: setCurrentReplyToId, setEndedActivities: setEndedActivities, setBoundaryData: setBoundaryData, removeFirstFromStreamingQueue: removeFirstFromStreamingQueue, setCurrentStreaming: setCurrentStreaming, killCurrentStreaming: killCurrentStreaming, askPermission: askPermission, toggleMicrophone: toggleMicrophone } = (0, $jgaO0.useSpeechStore)((state)=>state.actions);
27051
+ const { setCurrentOrLastPlayedActivity: setCurrentOrLastPlayedActivity, resetCancelCurrentUtterance: resetCancelCurrentUtterance, setSpeaking: setSpeaking, setBoundaryData: setBoundaryData, removeFirstFromStreamingQueue: removeFirstFromStreamingQueue, killCurrentStreaming: killCurrentStreaming, askPermission: askPermission, toggleMicrophone: toggleMicrophone } = (0, $jgaO0.useSpeechStore)((state)=>state.actions);
27128
27052
  const addEndedActivity = (0, $e53vj.useActivityStore)((state)=>state.actions.addEndedActivity);
27129
27053
  const dispatchMarkActivity = (0, $6QoTL.useDirectlineStore)((state)=>state.actions.dispatchMarkActivity);
27130
27054
  const [utterance, setUtterance] = (0, $dWhh5$react.useState)(null);
27131
27055
  const [nextUtterance, setNextUtterance] = (0, $dWhh5$react.useState)(null);
27132
- const cancelRef = (0, $dWhh5$react.useRef)(false);
27133
- const isSpeaking = (0, $dWhh5$react.useRef)(false);
27134
27056
  const isNewsViewRef = (0, $dWhh5$react.useRef)(!!isRetorikNews);
27135
27057
  const lastListTextPlayedRef = (0, $dWhh5$react.useRef)('');
27136
- const queuedActivitiesRef = (0, $dWhh5$react.useRef)([]);
27058
+ const streamingQueueRef = (0, $dWhh5$react.useRef)([]);
27137
27059
  const currentActivityRef = (0, $dWhh5$react.useRef)(null);
27138
- const currentPlayingRef = (0, $dWhh5$react.useRef)(null);
27139
- const tempCurrentStreamingRef = (0, $dWhh5$react.useRef)(null);
27140
- const streamingRelatedMessageRef = (0, $dWhh5$react.useRef)(null);
27141
27060
  /**
27142
27061
  * Check activity locale in case of voice change during the speech, to keep the language defined in activity
27143
27062
  * instead of switching languages between answers that are written in the same language
@@ -27164,17 +27083,21 @@ const $ad561f5c61e38c20$var$SynthesisManager = ({ ponyfill: ponyfill, isRetorikN
27164
27083
  return (0, $285c8810199513ef$export$f969af62bba9a48b)(params, speechSynthesisOptions === null || speechSynthesisOptions === void 0 ? void 0 : speechSynthesisOptions.sayAs);
27165
27084
  };
27166
27085
  const resetData = ()=>{
27167
- queuedActivitiesRef.current = [];
27168
- tempCurrentStreamingRef.current = null;
27169
- streamingRelatedMessageRef.current = null;
27170
- currentPlayingRef.current = null;
27171
- isSpeaking.current = false;
27086
+ var // Set all activities curretnly in the queue as ended
27087
+ _streamingQueueRef_current;
27088
+ (_streamingQueueRef_current = streamingQueueRef.current) === null || _streamingQueueRef_current === void 0 ? void 0 : _streamingQueueRef_current.forEach((activity)=>{
27089
+ addEndedActivity(activity.id);
27090
+ });
27091
+ streamingQueueRef.current = [];
27092
+ killCurrentStreaming();
27093
+ currentActivityRef.current = null;
27172
27094
  setUtterance(null);
27173
27095
  setNextUtterance(null);
27174
27096
  resetCancelCurrentUtterance();
27097
+ setSpeaking(false);
27098
+ setBoundaryData([]);
27175
27099
  };
27176
- const checkReplacementLocaleAndGetUtterance = (activity, checkReplacement = true, setCurrent = true)=>{
27177
- setCurrent && (currentActivityRef.current = activity);
27100
+ const checkReplacementLocaleAndGetUtterance = (activity, checkReplacement = true)=>{
27178
27101
  const replacementLocale = checkReplacement ? checkReplacementLocale(activity.locale || locale) : locale;
27179
27102
  const params = {
27180
27103
  activity: activity,
@@ -27183,176 +27106,39 @@ const $ad561f5c61e38c20$var$SynthesisManager = ({ ponyfill: ponyfill, isRetorikN
27183
27106
  };
27184
27107
  return checkActivityAndCreateUtterance(params);
27185
27108
  };
27186
- const checkDictateState = ()=>{
27109
+ /**
27110
+ * Check if the microphone can be opened automatically
27111
+ */ const checkDictateState = ()=>{
27187
27112
  if (!preventExpectedInputHint && mode === (0, $7WHA7.Mode).vocal && activeRecognitionState === (0, $7WHA7.RecognitionState).Closed) {
27188
27113
  if (!isMicrophoneAllowed) askPermission();
27189
27114
  else toggleMicrophone(true);
27190
27115
  }
27191
27116
  };
27192
- (0, $dWhh5$react.useEffect)(()=>{
27193
- if (isNewsViewRef.current) {
27194
- if (currentNewsActivity) {
27195
- setUtterance(checkReplacementLocaleAndGetUtterance(currentNewsActivity));
27196
- isSpeaking.current = true;
27197
- } else {
27198
- setUtterance(null);
27199
- isSpeaking.current = false;
27200
- }
27201
- }
27202
- }, [
27203
- currentNewsActivity,
27204
- ponyfill
27205
- ]);
27206
27117
  /**
27207
- * On ViewContext's route state change :
27208
- * - when we toggle from a view to another, we reset the data related to speech
27118
+ * On route change, reset all data and check if we are on the news view
27209
27119
  */ (0, $dWhh5$react.useEffect)(()=>{
27210
- setSpeaking(false);
27211
- setBoundaryData([]);
27212
- const ended = [
27213
- ...endedActivities
27214
- ];
27215
- if (currentPlaying) {
27216
- // Add played activity id to context's endedActivities
27217
- ended.length > 10 && ended.splice(0, 1);
27218
- if (currentPlaying.id) {
27219
- ended.push(currentPlaying.id);
27220
- addEndedActivity(currentPlaying.id);
27221
- }
27222
- setEndedActivities(ended);
27223
- }
27224
- setCurrentPlaying(undefined);
27225
27120
  resetData();
27226
27121
  if (!isRetorikNews) isNewsViewRef.current = route === (0, $7WHA7.Routes).News;
27227
27122
  }, [
27228
27123
  route
27229
27124
  ]);
27230
27125
  /**
27231
- * On RetorikContext's appAvailable state change :
27232
- * - appAvailable is set to true after the user interacted with the loader and every needed element is loaded
27233
- * - no utterance is created while appAvailable isn't true
27234
- * - if during the waiting time, some activities were queued, when appAvailable comes to true, let's begin creating the utterances and playing them
27126
+ * On cancel call, reset all data and kill current streaming
27235
27127
  */ (0, $dWhh5$react.useEffect)(()=>{
27236
- var _queuedActivitiesRef_current;
27237
- if (appAvailable && ((_queuedActivitiesRef_current = queuedActivitiesRef.current) === null || _queuedActivitiesRef_current === void 0 ? void 0 : _queuedActivitiesRef_current.length)) {
27238
- setUtterance(checkReplacementLocaleAndGetUtterance(queuedActivitiesRef.current[0]));
27239
- queuedActivitiesRef.current.splice(0, 1);
27240
- isSpeaking.current = true;
27241
- }
27242
- }, [
27243
- appAvailable
27244
- ]);
27245
- /**
27246
- * On speechCancelStore's cancel state change :
27247
- * - if there is currently no utterance being played, reset cancel state to false
27248
- * - if an utterance is being played, set it to null to stop playing and prevent data in queue from being played
27249
- * - setting an utterance to null will trigger the handleUtteranceEnded method automatically
27250
- */ (0, $dWhh5$react.useEffect)(()=>{
27251
- cancelRef.current = cancel;
27252
- if (cancel) {
27253
- utterance ? setUtterance(null) : resetCancelCurrentUtterance();
27254
- isSpeaking.current = false;
27255
- setNextUtterance(null);
27256
- killCurrentStreaming();
27257
- }
27128
+ cancel && resetData();
27258
27129
  }, [
27259
27130
  cancel
27260
27131
  ]);
27261
27132
  /**
27262
- * - check if the ponyfill is created and the voices loaded
27263
- * - if the activity doesn't have a replyToId value, put it in the queue (used for reminder process)
27264
- * - if the app is not available yet, put the activity in the queue if it is not yet inside
27265
- * - NB: an activity can be received once from the directline, but can be found several times in the activities in the botframework
27266
- * this is because it is processed multiple times if there is something to speak (channelDate empty, then channelData with {speak: true})
27267
- * - if an utterance is being played, process the new one (do nothing / put it in the queue / stop the current one and play the new one)
27268
- * - if an utterance has to be created, create it and set the utterance state
27133
+ * Play external speech immediately but don't add it to the history
27269
27134
  */ (0, $dWhh5$react.useEffect)(()=>{
27270
- if (voice && (lastBotActivity === null || lastBotActivity === void 0 ? void 0 : lastBotActivity.id)) {
27271
- let createNewUtterance = false;
27272
- if (!lastBotActivity.replyToId) {
27273
- var _queuedActivitiesRef_current;
27274
- if (isNewsViewRef.current) ;
27275
- else if (currentPlaying || ((_queuedActivitiesRef_current = queuedActivitiesRef.current) === null || _queuedActivitiesRef_current === void 0 ? void 0 : _queuedActivitiesRef_current.length)) queuedActivitiesRef.current = [
27276
- ...queuedActivitiesRef.current,
27277
- lastBotActivity
27278
- ];
27279
- else if (endedActivities.length === 0 || endedActivities[endedActivities.length - 1] !== lastBotActivity.id) createNewUtterance = true;
27280
- } else if (lastBotActivity.replyToId === streamingReplyToId) {
27281
- var _lastBotActivity_value;
27282
- if ((_lastBotActivity_value = lastBotActivity.value) === null || _lastBotActivity_value === void 0 ? void 0 : _lastBotActivity_value.streamingId) {
27283
- setCurrentPlaying(lastBotActivity);
27284
- currentPlayingRef.current = lastBotActivity;
27285
- // Keep the message related to playing streaming activities to deal with when streaming is ended
27286
- streamingRelatedMessageRef.current = lastBotActivity;
27287
- } else queuedActivitiesRef.current = [
27288
- ...queuedActivitiesRef.current,
27289
- lastBotActivity
27290
- ];
27291
- } else if (!appAvailable) {
27292
- if (!currentReplyToId) {
27293
- setCurrentReplyToId(lastBotActivity.replyToId);
27294
- queuedActivitiesRef.current = [
27295
- lastBotActivity
27296
- ];
27297
- } else {
27298
- var _queuedActivitiesRef_current1;
27299
- if (currentReplyToId === lastBotActivity.replyToId) {
27300
- if (!((_queuedActivitiesRef_current1 = queuedActivitiesRef.current) === null || _queuedActivitiesRef_current1 === void 0 ? void 0 : _queuedActivitiesRef_current1.find((act)=>act.id === lastBotActivity.id))) queuedActivitiesRef.current = [
27301
- ...queuedActivitiesRef.current,
27302
- lastBotActivity
27303
- ];
27304
- } else {
27305
- setCurrentReplyToId(lastBotActivity.replyToId);
27306
- queuedActivitiesRef.current = [
27307
- lastBotActivity
27308
- ];
27309
- }
27310
- }
27311
- } else if (currentActivityRef === null || currentActivityRef === void 0 ? void 0 : currentActivityRef.current) switch((0, $549323f244f4782c$export$2e2bcd8739ae039)(lastBotActivity, currentActivityRef.current, currentReplyToId, queuedActivitiesRef.current, endedActivities)){
27312
- case 0:
27313
- break;
27314
- case 1:
27315
- // Add the activity to the queue
27316
- queuedActivitiesRef.current.push(lastBotActivity);
27317
- break;
27318
- case 2:
27319
- // Stop current activity and play the new one
27320
- queuedActivitiesRef.current = [];
27321
- createNewUtterance = true;
27322
- break;
27323
- }
27324
- else createNewUtterance = !endedActivities.includes(lastBotActivity.id);
27325
- if (createNewUtterance) {
27326
- setCurrentReplyToId(lastBotActivity.replyToId || 'customReplyToIdIfNotPresent');
27327
- setUtterance(checkReplacementLocaleAndGetUtterance(lastBotActivity));
27328
- isSpeaking.current = true;
27329
- }
27330
- }
27331
- }, [
27332
- lastBotActivity,
27333
- ponyfill,
27334
- voice
27335
- ]);
27336
- (0, $dWhh5$react.useEffect)(()=>{
27337
- if (streamingReplyToId && streamingQueue.length) {
27338
- setUtterance(checkReplacementLocaleAndGetUtterance(streamingQueue[0], false, false));
27339
- isSpeaking.current = true;
27340
- setCurrentPlaying(undefined);
27341
- currentPlayingRef.current = null;
27342
- currentActivityRef.current = null;
27343
- tempCurrentStreamingRef.current = streamingQueue[0].text || null;
27344
- removeFirstFromStreamingQueue();
27345
- }
27346
- }, [
27347
- streamingReplyToId
27348
- ]);
27349
- (0, $dWhh5$react.useEffect)(()=>{
27350
27135
  if (externalTextToSpeech) {
27351
- setUtterance(checkReplacementLocaleAndGetUtterance({
27136
+ const activity = {
27352
27137
  speak: externalTextToSpeech,
27353
27138
  locale: locale
27354
- }, false, false));
27355
- isSpeaking.current = true;
27139
+ };
27140
+ currentActivityRef.current = activity;
27141
+ setUtterance(checkReplacementLocaleAndGetUtterance(activity, false));
27356
27142
  }
27357
27143
  }, [
27358
27144
  externalTextToSpeech
@@ -27362,93 +27148,80 @@ const $ad561f5c61e38c20$var$SynthesisManager = ({ ponyfill: ponyfill, isRetorikN
27362
27148
  document.dispatchEvent(speechEvent);
27363
27149
  };
27364
27150
  /**
27365
- * On call :
27366
- * - set speaking state to true
27367
- * - clear timerref timeout
27368
- * - set currentPlaying and currentReplyToId states after a small delay to prevent make sure that the display will happen after the speech has begun
27151
+ * Called when utterance's "start" event is fired
27369
27152
  */ const handleUtteranceStart = ()=>{
27153
+ var _streamingQueueRef_current__value;
27370
27154
  setSpeaking(true);
27371
27155
  if (!isNewsViewRef.current && (currentActivityRef === null || currentActivityRef === void 0 ? void 0 : currentActivityRef.current)) {
27372
- setCurrentPlaying(currentActivityRef.current);
27373
- currentPlayingRef.current = currentActivityRef.current;
27156
+ setCurrentOrLastPlayedActivity(currentActivityRef.current);
27374
27157
  currentActivityRef.current.id && dispatchMarkActivity(currentActivityRef.current.id, true);
27375
27158
  }
27376
27159
  dispatchSpeechEvent(true);
27377
27160
  // Set next utterance to prepare synthesis data in order to improve fluidity
27378
- if (streamingReplyToId && streamingQueue.length) {
27379
- const tempActivity = streamingQueue[0];
27380
- if (tempActivity.text) {
27381
- const tempUtterance = checkReplacementLocaleAndGetUtterance(streamingQueue[0], false, false);
27382
- tempUtterance.text !== (nextUtterance === null || nextUtterance === void 0 ? void 0 : nextUtterance.text) ? setNextUtterance(tempUtterance) : setNextUtterance(null);
27383
- } else setNextUtterance(null);
27161
+ if (streamingQueueRef.current.length && !((_streamingQueueRef_current__value = streamingQueueRef.current[0].value) === null || _streamingQueueRef_current__value === void 0 ? void 0 : _streamingQueueRef_current__value.streamingCount)) {
27162
+ const utt = checkReplacementLocaleAndGetUtterance(streamingQueueRef.current[0], false);
27163
+ setNextUtterance((current)=>utt.text === (current === null || current === void 0 ? void 0 : current.text) ? null : utt);
27384
27164
  } else setNextUtterance(null);
27385
- setCurrentStreaming(tempCurrentStreamingRef === null || tempCurrentStreamingRef === void 0 ? void 0 : tempCurrentStreamingRef.current);
27386
27165
  };
27387
- const handleUtteranceEnd = ()=>{
27166
+ /**
27167
+ * Called when utterance's "end" event is fired
27168
+ */ const handleUtteranceEnd = ()=>{
27388
27169
  setSpeaking(false);
27389
27170
  dispatchSpeechEvent(false);
27390
- if (isNewsViewRef.current) setRetorikNewsEnded(true);
27391
- else if (cancelRef.current) resetData();
27392
- else handleEnded();
27171
+ if (isNewsViewRef.current) {
27172
+ setRetorikNewsEnded(true);
27173
+ currentActivityRef.current = null;
27174
+ } else handleEnded();
27393
27175
  };
27394
- /**
27395
- * On call :
27396
- * - update the states related to the ende activity
27397
- * - check if the end of the utterance was called by a cancel or not
27398
- * - if it wasn't a cancel, deal with the queue
27399
- * - if this was the last activity of the queue, check if the microphone has to be opened automatically (inputHint = expectingInput)
27400
- */ const handleEnded = ()=>{
27401
- let futureUtterance = null;
27402
- if (currentPlayingRef === null || currentPlayingRef === void 0 ? void 0 : currentPlayingRef.current) // Add played activity id to context's endedActivities
27403
- {
27404
- if (currentPlayingRef.current.id) {
27405
- addEndedActivity(currentPlayingRef.current.id);
27406
- dispatchMarkActivity(currentPlayingRef.current.id, false);
27407
- }
27176
+ const handleEnded = ()=>{
27177
+ var _currentActivityRef_current, _streamingQueueRef_current;
27178
+ // Add played activity id to context's endedActivities
27179
+ if ((_currentActivityRef_current = currentActivityRef.current) === null || _currentActivityRef_current === void 0 ? void 0 : _currentActivityRef_current.id) {
27180
+ addEndedActivity(currentActivityRef.current.id);
27181
+ dispatchMarkActivity(currentActivityRef.current.id, false);
27408
27182
  }
27409
- setCurrentPlaying(undefined);
27410
- if (streamingQueue.length) {
27411
- futureUtterance = checkReplacementLocaleAndGetUtterance(streamingQueue[0], false);
27412
- tempCurrentStreamingRef.current = streamingQueue[0].text || null;
27413
- removeFirstFromStreamingQueue();
27414
- } else {
27415
- var _queuedActivitiesRef_current, _currentPlayingRef_current;
27416
- // Launch next activity in the queue and remove it from the queue
27417
- if ((_queuedActivitiesRef_current = queuedActivitiesRef.current) === null || _queuedActivitiesRef_current === void 0 ? void 0 : _queuedActivitiesRef_current.length) {
27418
- futureUtterance = checkReplacementLocaleAndGetUtterance(queuedActivitiesRef.current[0]);
27419
- queuedActivitiesRef.current.splice(0, 1);
27420
- // If a streaming-related message activity is stored, set it as ended and flush it
27421
- if (streamingRelatedMessageRef.current) {
27422
- addEndedActivity(streamingRelatedMessageRef.current.id);
27423
- streamingRelatedMessageRef.current = null;
27183
+ if ((_streamingQueueRef_current = streamingQueueRef.current) === null || _streamingQueueRef_current === void 0 ? void 0 : _streamingQueueRef_current.length) {
27184
+ var _streamingQueueRef_current__value;
27185
+ // Check if this is the message sent after streaming activities
27186
+ if ((_streamingQueueRef_current__value = streamingQueueRef.current[0].value) === null || _streamingQueueRef_current__value === void 0 ? void 0 : _streamingQueueRef_current__value.streamingCount) {
27187
+ var _streamingQueueRef_current1;
27188
+ addEndedActivity(streamingQueueRef.current[0].id);
27189
+ // If there is another activity after this message, play it. If not, let's check if the microphone should be opened
27190
+ if (((_streamingQueueRef_current1 = streamingQueueRef.current) === null || _streamingQueueRef_current1 === void 0 ? void 0 : _streamingQueueRef_current1.length) > 1) {
27191
+ const utt = checkReplacementLocaleAndGetUtterance(streamingQueueRef.current[1]);
27192
+ currentActivityRef.current = streamingQueueRef.current[1];
27193
+ setUtterance(utt);
27194
+ removeFirstFromStreamingQueue(true);
27195
+ } else {
27196
+ streamingQueueRef.current[0].inputHint === 'expectingInput' && checkDictateState();
27197
+ currentActivityRef.current = null;
27198
+ setUtterance(null);
27199
+ setNextUtterance(null);
27200
+ removeFirstFromStreamingQueue();
27424
27201
  }
27425
- } else if (streamingRelatedMessageRef.current) {
27426
- // Streaming-related message activity stored
27427
- streamingRelatedMessageRef.current.inputHint === 'expectingInput' && checkDictateState();
27428
- addEndedActivity(streamingRelatedMessageRef.current.id);
27429
- streamingRelatedMessageRef.current = null;
27430
- } else (currentPlayingRef === null || currentPlayingRef === void 0 ? void 0 : (_currentPlayingRef_current = currentPlayingRef.current) === null || _currentPlayingRef_current === void 0 ? void 0 : _currentPlayingRef_current.inputHint) === 'expectingInput' && checkDictateState();
27202
+ } else {
27203
+ const utt = checkReplacementLocaleAndGetUtterance(streamingQueueRef.current[0]);
27204
+ currentActivityRef.current = streamingQueueRef.current[0];
27205
+ setUtterance(utt);
27206
+ removeFirstFromStreamingQueue();
27207
+ }
27208
+ } else {
27209
+ var _currentActivityRef_current1;
27210
+ ((_currentActivityRef_current1 = currentActivityRef.current) === null || _currentActivityRef_current1 === void 0 ? void 0 : _currentActivityRef_current1.inputHint) === 'expectingInput' && checkDictateState();
27211
+ currentActivityRef.current = null;
27212
+ setUtterance(null);
27213
+ setNextUtterance(null);
27431
27214
  }
27432
- currentPlayingRef.current = null;
27433
- setUtterance(futureUtterance);
27434
- isSpeaking.current = !!futureUtterance;
27435
27215
  };
27436
27216
  /**
27437
- * If the previous audio stream ends before the next one is received, we relaunch the new stream as soon as it arrives.
27217
+ * Wait for app loading and voice selection to begin playing speech
27438
27218
  */ (0, $dWhh5$react.useEffect)(()=>{
27439
- if (!isSpeaking.current) {
27440
- let futureUtterance = null;
27441
- setCurrentPlaying(undefined);
27442
- if (streamingQueue.length) {
27443
- futureUtterance = checkReplacementLocaleAndGetUtterance(streamingQueue[0], false, false);
27444
- tempCurrentStreamingRef.current = streamingQueue[0].text || null;
27445
- removeFirstFromStreamingQueue();
27446
- }
27447
- currentPlayingRef.current = null;
27448
- setUtterance(futureUtterance);
27449
- isSpeaking.current = !!futureUtterance;
27450
- }
27219
+ // Set ref from the state to use in events
27220
+ streamingQueueRef.current = streamingQueue;
27221
+ if (appAvailable && voice && streamingQueue.length && !currentActivityRef.current) handleEnded();
27451
27222
  }, [
27223
+ appAvailable,
27224
+ voice,
27452
27225
  streamingQueue
27453
27226
  ]);
27454
27227
  return /*#__PURE__*/ (0, $dWhh5$reactjsxruntime.jsx)((0, $d31b268c3b702355$export$2e2bcd8739ae039), {
@@ -27966,8 +27739,7 @@ const $4b02e31a53a4d2e7$var$typingTimer = 2000;
27966
27739
  const $4b02e31a53a4d2e7$var$SendTypingIndicator = ({ isRetorikNews: isRetorikNews })=>{
27967
27740
  const speaking = (0, $jgaO0.useSpeechStore)((state)=>state.speaking);
27968
27741
  const streamingQueue = (0, $jgaO0.useSpeechStore)((state)=>state.streamingQueue);
27969
- const streamingQueueFullLength = (0, $jgaO0.useSpeechStore)((state)=>state.streamingQueueFullLength);
27970
- const lastRecognitionInterim = (0, $jgaO0.useSpeechStore)((state)=>state.lastRecognitionInterim);
27742
+ const activeRecognitionState = (0, $jgaO0.useSpeechStore)((state)=>state.activeRecognitionState);
27971
27743
  const route = (0, $kUiCn.useViewStore)((state)=>state.route);
27972
27744
  const loaderClosed = (0, $6EkQS.useRetorikStore)((state)=>state.loaderClosed);
27973
27745
  const appAvailable = (0, $6EkQS.useRetorikStore)((state)=>state.appAvailable);
@@ -27980,17 +27752,24 @@ const $4b02e31a53a4d2e7$var$SendTypingIndicator = ({ isRetorikNews: isRetorikNew
27980
27752
  const sendTyping = (0, $6QoTL.useDirectlineStore)((state)=>state.actions.sendTyping);
27981
27753
  const dataRef = (0, $dWhh5$react.useRef)(false);
27982
27754
  (0, $dWhh5$react.useEffect)(()=>{
27755
+ // Don't send typing activity when we are receiving streaming events
27756
+ const isReceivingStreamingData = !!streamingQueue.length && !!streamingQueue.find((activity)=>{
27757
+ var _activity_name;
27758
+ return ((_activity_name = activity.name) === null || _activity_name === void 0 ? void 0 : _activity_name.toLowerCase()) === 'davi.streammessageactivity';
27759
+ }) && !streamingQueue.find((activity)=>{
27760
+ var _activity_value;
27761
+ return (_activity_value = activity.value) === null || _activity_value === void 0 ? void 0 : _activity_value.streamingCount;
27762
+ });
27983
27763
  dataRef.current = !isWaitingForResponse && // Don't send typing activity when we are receiving streaming events
27984
- !(streamingQueue.length && streamingQueueFullLength === 0) && (!loaderClosed || lastRecognitionInterim !== '' || userIsTyping || userIsSwiping || speaking || currentSubView !== (0, $7WHA7.CurrentSubView).none || route === (0, $7WHA7.Routes).News || retorikEvent === (0, $7WHA7.RetorikEvent).DetailViewOpen || listStatus === (0, $7WHA7.ListStatus).opened);
27764
+ !isReceivingStreamingData && (!loaderClosed || activeRecognitionState !== (0, $7WHA7.RecognitionState).Closed || userIsTyping || userIsSwiping || speaking || currentSubView !== (0, $7WHA7.CurrentSubView).none || route === (0, $7WHA7.Routes).News || retorikEvent === (0, $7WHA7.RetorikEvent).DetailViewOpen || listStatus === (0, $7WHA7.ListStatus).opened);
27985
27765
  }, [
27986
27766
  appAvailable,
27987
27767
  loaderClosed,
27988
- lastRecognitionInterim,
27768
+ activeRecognitionState,
27989
27769
  userIsTyping,
27990
27770
  userIsSwiping,
27991
27771
  speaking,
27992
27772
  streamingQueue,
27993
- streamingQueueFullLength,
27994
27773
  currentSubView,
27995
27774
  route,
27996
27775
  retorikEvent,