botframework-webchat-core 4.18.2 → 4.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/activity.js +3 -0
- package/boot/deprecated/activity.js +7 -0
- package/boot/deprecated/activity.mjs +5 -0
- package/boot/deprecated/graph.js +7 -0
- package/boot/deprecated/graph.mjs +5 -0
- package/boot/deprecated/internal.js +7 -0
- package/boot/deprecated/internal.mjs +5 -0
- package/dist/WebChatActivity-CYqxBG_4.d.mts +271 -0
- package/dist/WebChatActivity-CYqxBG_4.d.ts +271 -0
- package/dist/_dtsroll-chunks/B7Whm73Q-tagged.d.ts +71 -0
- package/dist/_dtsroll-chunks/C-MxR98A-botframework-webchat-core-debug-api.d.ts +135 -0
- package/dist/_dtsroll-chunks/CAquHfZK-botframework-webchat-base.utils.d.ts +17 -0
- package/dist/_dtsroll-chunks/CDVed0Q--botframework-webchat-core.org-schema.d.ts +601 -0
- package/dist/_dtsroll-chunks/vlDgTKWF-botframework-webchat-core-graph.d.ts +239 -0
- package/dist/botframework-webchat-core.activity.d.mts +23 -0
- package/dist/botframework-webchat-core.activity.d.ts +23 -0
- package/dist/botframework-webchat-core.activity.js +2 -0
- package/dist/botframework-webchat-core.activity.js.map +1 -0
- package/dist/botframework-webchat-core.activity.mjs +2 -0
- package/dist/botframework-webchat-core.activity.mjs.map +1 -0
- package/dist/botframework-webchat-core.d.mts +267 -662
- package/dist/botframework-webchat-core.d.ts +556 -0
- package/dist/botframework-webchat-core.graph.d.mts +9 -0
- package/dist/botframework-webchat-core.graph.d.ts +9 -0
- package/dist/botframework-webchat-core.graph.js +2 -0
- package/dist/botframework-webchat-core.graph.js.map +1 -0
- package/dist/botframework-webchat-core.graph.mjs +2 -0
- package/dist/botframework-webchat-core.graph.mjs.map +1 -0
- package/dist/botframework-webchat-core.internal.d.mts +61 -0
- package/dist/botframework-webchat-core.internal.d.ts +61 -0
- package/dist/botframework-webchat-core.internal.js +2 -0
- package/dist/botframework-webchat-core.internal.js.map +1 -0
- package/dist/botframework-webchat-core.internal.mjs +2 -0
- package/dist/botframework-webchat-core.internal.mjs.map +1 -0
- package/dist/botframework-webchat-core.js +2 -0
- package/dist/botframework-webchat-core.js.map +1 -0
- package/dist/botframework-webchat-core.json-ld.d.mts +2 -0
- package/dist/botframework-webchat-core.json-ld.d.ts +2 -0
- package/dist/botframework-webchat-core.json-ld.js +2 -0
- package/dist/botframework-webchat-core.json-ld.js.map +1 -0
- package/dist/botframework-webchat-core.json-ld.mjs +2 -0
- package/dist/botframework-webchat-core.json-ld.mjs.map +1 -0
- package/dist/botframework-webchat-core.mjs +1 -2
- package/dist/botframework-webchat-core.mjs.map +1 -1
- package/dist/botframework-webchat-core.org-schema.d.mts +2 -0
- package/dist/botframework-webchat-core.org-schema.d.ts +2 -0
- package/dist/botframework-webchat-core.org-schema.js +2 -0
- package/dist/botframework-webchat-core.org-schema.js.map +1 -0
- package/dist/botframework-webchat-core.org-schema.mjs +2 -0
- package/dist/botframework-webchat-core.org-schema.mjs.map +1 -0
- package/dist/chunk-A4GEFYZJ.mjs +2 -0
- package/dist/chunk-A4GEFYZJ.mjs.map +1 -0
- package/dist/chunk-HZWWJL43.mjs +2 -0
- package/dist/chunk-HZWWJL43.mjs.map +1 -0
- package/dist/chunk-ICNZKQJW.mjs +2 -0
- package/dist/chunk-ICNZKQJW.mjs.map +1 -0
- package/dist/chunk-K6E6QQMQ.js +2 -0
- package/dist/chunk-K6E6QQMQ.js.map +1 -0
- package/dist/chunk-KPT5FBH2.mjs +2 -0
- package/dist/chunk-KPT5FBH2.mjs.map +1 -0
- package/dist/chunk-LO5BZSVE.js +2 -0
- package/dist/chunk-LO5BZSVE.js.map +1 -0
- package/dist/chunk-LP2X2JTR.js +2 -0
- package/dist/chunk-LP2X2JTR.js.map +1 -0
- package/dist/chunk-RUERYYZO.js +2 -0
- package/dist/chunk-RUERYYZO.js.map +1 -0
- package/dist/chunk-XOE3AOSM.js +2 -0
- package/dist/chunk-XOE3AOSM.js.map +1 -0
- package/dist/chunk-Y6ZDNVRT.mjs +2 -0
- package/dist/chunk-Y6ZDNVRT.mjs.map +1 -0
- package/{lib/createStore.d.ts → dist/createStore-CcvouBrW.d.mts} +29 -7
- package/dist/createStore-CcvouBrW.d.ts +65 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -1
- package/graph.js +3 -0
- package/internal.js +3 -0
- package/json-ld.js +3 -0
- package/org-schema.js +3 -0
- package/package.json +147 -73
- package/src/__tests__/activityFromBot.spec.js +2 -0
- package/src/__tests__/addMetaTag.spec.js +8 -0
- package/src/__tests__/addMetaTag.spec.mjs +8 -0
- package/src/__tests__/connectSaga.spec.js +2 -0
- package/src/__tests__/deleteKey.spec.js +2 -0
- package/src/__tests__/detectSlowConnectionSaga.spec.js +3 -1
- package/src/__tests__/observeOnce.spec.js +2 -0
- package/src/__tests__/speakableActivity.spec.js +2 -0
- package/src/__tests__/uniqueID.spec.js +2 -0
- package/src/actions/clearSuggestedActions.ts +20 -0
- package/src/actions/{connect.js → connect.ts} +9 -1
- package/src/actions/muteVoiceRecording.ts +17 -0
- package/src/actions/postVoiceActivity.ts +21 -0
- package/src/actions/registerActionSink.ts +29 -0
- package/src/actions/registerVoiceHandler.ts +24 -0
- package/src/actions/{sendEvent.js → sendEvent.ts} +1 -1
- package/src/actions/{sendMessageBack.js → sendMessageBack.ts} +1 -1
- package/src/actions/{sendPostBack.js → sendPostBack.ts} +1 -1
- package/src/actions/{setDictateInterims.js → setDictateInterims.ts} +1 -1
- package/src/actions/{setDictateState.js → setDictateState.ts} +1 -1
- package/src/actions/{setLanguage.js → setLanguage.ts} +1 -1
- package/src/actions/{setSendBox.js → setSendBox.ts} +1 -1
- package/src/actions/{setSendTimeout.js → setSendTimeout.ts} +1 -1
- package/src/actions/setSendTypingIndicator.ts +1 -1
- package/src/actions/setSuggestedActions.ts +35 -0
- package/src/actions/setVoiceState.ts +21 -0
- package/src/actions/startVoiceRecording.ts +17 -0
- package/src/actions/stopVoiceRecording.ts +17 -0
- package/src/actions/{submitSendBox.js → submitSendBox.ts} +1 -1
- package/src/actions/unmuteVoiceRecording.ts +17 -0
- package/src/actions/unregisterActionSink.ts +29 -0
- package/src/actions/unregisterVoiceHandler.ts +19 -0
- package/src/boot/activity.ts +19 -0
- package/src/boot/graph.ts +18 -0
- package/src/boot/internal.ts +11 -0
- package/src/boot/json-ld.ts +6 -0
- package/src/boot/org-schema.ts +29 -0
- package/src/buildInfo.ts +9 -0
- package/src/constants/{ActivityClientState.js → ActivityClientState.ts} +3 -3
- package/src/constants/DictateState.ts +10 -0
- package/src/createPromiseQueue.js +8 -6
- package/src/createReducer.ts +28 -20
- package/src/createSagas.ts +6 -3
- package/src/createStore.ts +26 -10
- package/src/env.d.ts +12 -0
- package/src/graph/createGraphFromStore.ts +121 -0
- package/src/index.ts +62 -45
- package/src/internal/StoreDebugAPIRegistry.ts +4 -0
- package/src/internal/actions/setRawState.ts +48 -0
- package/src/internal/types/suggestedActions.ts +11 -0
- package/src/internal/types/suggestedActionsOriginActivity.ts +16 -0
- package/src/reducers/activities/combineActivitiesReducer.ts +58 -0
- package/src/reducers/activities/createGroupedActivitiesReducer.ts +297 -0
- package/src/reducers/activities/patchActivity.ts +37 -0
- package/src/reducers/activities/sort/deleteActivityByLocalId.activity.spec.ts +144 -0
- package/src/reducers/activities/sort/deleteActivityByLocalId.howTo.spec.ts +148 -0
- package/src/reducers/activities/sort/deleteActivityByLocalId.howToWithLivestream.spec.ts +248 -0
- package/src/reducers/activities/sort/deleteActivityByLocalId.livestream.spec.ts +156 -0
- package/src/reducers/activities/sort/deleteActivityByLocalId.ts +177 -0
- package/src/reducers/activities/sort/private/computePartListTimestamp.ts +9 -0
- package/src/reducers/activities/sort/private/computeSortedActivities.ts +51 -0
- package/src/reducers/activities/sort/private/getLogicalTimestamp.spec.ts +49 -0
- package/src/reducers/activities/sort/private/getLogicalTimestamp.ts +33 -0
- package/src/reducers/activities/sort/private/getPartGroupingMetadataMap.spec.ts +92 -0
- package/src/reducers/activities/sort/private/getPartGroupingMetadataMap.ts +37 -0
- package/src/reducers/activities/sort/private/insertSorted.spec.ts +106 -0
- package/src/reducers/activities/sort/private/insertSorted.ts +18 -0
- package/src/reducers/activities/sort/property/LocalId.ts +60 -0
- package/src/reducers/activities/sort/property/Position.ts +39 -0
- package/src/reducers/activities/sort/property/ReceivedAt.ts +45 -0
- package/src/reducers/activities/sort/property/SendStatus.ts +51 -0
- package/src/reducers/activities/sort/queryLocalIdByActivityId.ts +6 -0
- package/src/reducers/activities/sort/queryLocalIdByClientActivityId.ts +6 -0
- package/src/reducers/activities/sort/types.ts +80 -0
- package/src/reducers/activities/sort/updateActivityChannelData.ts +101 -0
- package/src/reducers/activities/sort/updateSendState.ts +22 -0
- package/src/reducers/activities/sort/upsert.activity.spec.ts +500 -0
- package/src/reducers/activities/sort/upsert.howTo.spec.ts +368 -0
- package/src/reducers/activities/sort/upsert.howToWithLivestream.spec.ts +384 -0
- package/src/reducers/activities/sort/upsert.livestream.spec.ts +418 -0
- package/src/reducers/activities/sort/upsert.ts +498 -0
- package/src/reducers/activities/tsconfig.json +4 -0
- package/src/reducers/createNotificationsReducer.ts +4 -4
- package/src/reducers/suggestedActions.ts +21 -0
- package/src/reducers/suggestedActionsOriginActivity.ts +24 -0
- package/src/reducers/voiceActivity.ts +102 -0
- package/src/sagas/actionSinkSaga.ts +39 -0
- package/src/sagas/observeActivitySaga.ts +51 -1
- package/src/sagas/postActivitySaga.ts +17 -10
- package/src/sagas/postVoiceActivitySaga.ts +76 -0
- package/src/sagas/queueIncomingActivitySaga.ts +10 -4
- package/src/sagas/sendMessageToPostActivitySaga.ts +4 -1
- package/src/sagas/speakActivityAndStartDictateOnIncomingActivityFromOthersSaga.js +10 -4
- package/src/sagas/startDictateOnSpeakCompleteSaga.js +3 -3
- package/src/sagas/startSpeakActivityOnPostActivitySaga.js +15 -5
- package/src/sagas/stopDictateOnCardActionSaga.js +11 -3
- package/src/sagas/stopSpeakingActivityOnInputSaga.js +22 -4
- package/src/selectors/combineSelectors.ts +1 -1
- package/src/tsconfig.json +3 -15
- package/src/types/StoreDebugAPI.ts +25 -0
- package/src/types/WebChatActivity.ts +31 -14
- package/src/types/external/DirectLineActivity.ts +1 -1
- package/src/types/external/Observable.ts +4 -1
- package/src/types/internal/GlobalScopeClock.ts +10 -10
- package/src/types/internal/ReduxState.ts +2 -0
- package/src/types/internal/WebChatOutgoingActivity.ts +1 -1
- package/src/utils/dateToLocaleISOString.chatham.spec.js +1 -2
- package/src/utils/dateToLocaleISOString.japan.spec.js +1 -2
- package/src/utils/dateToLocaleISOString.newfoundland.spec.js +1 -2
- package/src/utils/dateToLocaleISOString.pacific.spec.js +1 -2
- package/src/utils/dateToLocaleISOString.utc.spec.js +1 -3
- package/src/utils/deleteKey.ts +1 -1
- package/src/utils/getActivityLivestreamingMetadata.spec.ts +297 -0
- package/src/utils/getActivityLivestreamingMetadata.ts +197 -0
- package/src/utils/getOrgSchemaMessage.spec.ts +4 -1
- package/src/utils/getOrgSchemaMessage.ts +16 -16
- package/src/utils/onErrorResumeNext.ts +1 -1
- package/src/utils/voiceActivity/getVoiceActivityRole.spec.ts +150 -0
- package/src/utils/voiceActivity/getVoiceActivityRole.ts +16 -0
- package/src/utils/voiceActivity/getVoiceActivityText.spec.ts +100 -0
- package/src/utils/voiceActivity/getVoiceActivityText.ts +11 -0
- package/src/utils/voiceActivity/isVoiceActivity.spec.ts +202 -0
- package/src/utils/voiceActivity/isVoiceActivity.ts +21 -0
- package/src/utils/voiceActivity/isVoiceTranscriptActivity.spec.ts +224 -0
- package/src/utils/voiceActivity/isVoiceTranscriptActivity.ts +24 -0
- package/dist/botframework-webchat-core.mjs.LEGAL.txt +0 -0
- package/lib/actions/clearSuggestedActions.js +0 -15
- package/lib/actions/connect.js +0 -33
- package/lib/actions/connectionStatusUpdate.js +0 -20
- package/lib/actions/deleteActivity.d.ts +0 -13
- package/lib/actions/deleteActivity.d.ts.map +0 -1
- package/lib/actions/deleteActivity.js +0 -19
- package/lib/actions/disconnect.js +0 -21
- package/lib/actions/dismissNotification.d.ts +0 -12
- package/lib/actions/dismissNotification.d.ts.map +0 -1
- package/lib/actions/dismissNotification.js +0 -19
- package/lib/actions/emitTypingIndicator.js +0 -15
- package/lib/actions/incomingActivity.d.ts +0 -14
- package/lib/actions/incomingActivity.d.ts.map +0 -1
- package/lib/actions/incomingActivity.js +0 -19
- package/lib/actions/markActivity.d.ts +0 -17
- package/lib/actions/markActivity.d.ts.map +0 -1
- package/lib/actions/markActivity.js +0 -22
- package/lib/actions/postActivity.d.ts +0 -64
- package/lib/actions/postActivity.d.ts.map +0 -1
- package/lib/actions/postActivity.js +0 -31
- package/lib/actions/queueIncomingActivity.js +0 -18
- package/lib/actions/reconnect.js +0 -17
- package/lib/actions/sagaError.d.ts +0 -8
- package/lib/actions/sagaError.d.ts.map +0 -1
- package/lib/actions/sagaError.js +0 -15
- package/lib/actions/sendEvent.js +0 -19
- package/lib/actions/sendFiles.d.ts +0 -19
- package/lib/actions/sendFiles.d.ts.map +0 -1
- package/lib/actions/sendFiles.js +0 -20
- package/lib/actions/sendMessage.d.ts +0 -19
- package/lib/actions/sendMessage.d.ts.map +0 -1
- package/lib/actions/sendMessage.js +0 -24
- package/lib/actions/sendMessageBack.js +0 -20
- package/lib/actions/sendPostBack.js +0 -18
- package/lib/actions/setClockSkewAdjustment.js +0 -12
- package/lib/actions/setDictateInterims.js +0 -18
- package/lib/actions/setDictateState.js +0 -18
- package/lib/actions/setLanguage.js +0 -18
- package/lib/actions/setNotification.d.ts +0 -10
- package/lib/actions/setNotification.d.ts.map +0 -1
- package/lib/actions/setNotification.js +0 -37
- package/lib/actions/setReferenceGrammarID.js +0 -18
- package/lib/actions/setSendBox.js +0 -18
- package/lib/actions/setSendBoxAttachments.d.ts +0 -13
- package/lib/actions/setSendBoxAttachments.d.ts.map +0 -1
- package/lib/actions/setSendBoxAttachments.js +0 -18
- package/lib/actions/setSendTimeout.js +0 -18
- package/lib/actions/setSendTypingIndicator.d.ts +0 -11
- package/lib/actions/setSendTypingIndicator.d.ts.map +0 -1
- package/lib/actions/setSendTypingIndicator.js +0 -18
- package/lib/actions/setSuggestedActions.js +0 -20
- package/lib/actions/startDictate.js +0 -15
- package/lib/actions/startSpeakingActivity.js +0 -15
- package/lib/actions/stopDictate.js +0 -15
- package/lib/actions/stopSpeakingActivity.js +0 -15
- package/lib/actions/submitSendBox.js +0 -22
- package/lib/actions/updateConnectionStatus.js +0 -18
- package/lib/constants/ActivityClientState.js +0 -16
- package/lib/constants/DictateState.js +0 -17
- package/lib/createPromiseQueue.js +0 -30
- package/lib/createReducer.d.ts +0 -60
- package/lib/createReducer.d.ts.map +0 -1
- package/lib/createReducer.js +0 -45
- package/lib/createSagas.d.ts +0 -8
- package/lib/createSagas.d.ts.map +0 -1
- package/lib/createSagas.js +0 -112
- package/lib/createStore.d.ts.map +0 -1
- package/lib/createStore.js +0 -131
- package/lib/definitions/activityFromBot.js +0 -11
- package/lib/definitions/speakableActivity.js +0 -10
- package/lib/definitions/speakingActivity.js +0 -13
- package/lib/index.d.ts +0 -76
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -309
- package/lib/reducers/connectivityStatus.js +0 -49
- package/lib/reducers/createActivitiesReducer.d.ts +0 -12
- package/lib/reducers/createActivitiesReducer.d.ts.map +0 -1
- package/lib/reducers/createActivitiesReducer.js +0 -267
- package/lib/reducers/createInternalReducer.d.ts +0 -10
- package/lib/reducers/createInternalReducer.d.ts.map +0 -1
- package/lib/reducers/createInternalReducer.js +0 -19
- package/lib/reducers/createNotificationsReducer.d.ts +0 -11
- package/lib/reducers/createNotificationsReducer.d.ts.map +0 -1
- package/lib/reducers/createNotificationsReducer.js +0 -55
- package/lib/reducers/createTypingReducer.d.ts +0 -14
- package/lib/reducers/createTypingReducer.d.ts.map +0 -1
- package/lib/reducers/createTypingReducer.js +0 -50
- package/lib/reducers/dictateInterims.js +0 -23
- package/lib/reducers/dictateState.js +0 -38
- package/lib/reducers/language.js +0 -23
- package/lib/reducers/private/findBeforeAfter.d.ts +0 -4
- package/lib/reducers/private/findBeforeAfter.d.ts.map +0 -1
- package/lib/reducers/private/findBeforeAfter.js +0 -24
- package/lib/reducers/readyState.js +0 -23
- package/lib/reducers/referenceGrammarID.js +0 -23
- package/lib/reducers/sendBoxAttachments.d.ts +0 -9
- package/lib/reducers/sendBoxAttachments.d.ts.map +0 -1
- package/lib/reducers/sendBoxAttachments.js +0 -23
- package/lib/reducers/sendBoxValue.js +0 -23
- package/lib/reducers/sendTimeout.js +0 -23
- package/lib/reducers/sendTypingIndicator.js +0 -23
- package/lib/reducers/shouldSpeakIncomingActivity.js +0 -25
- package/lib/reducers/suggestedActions.js +0 -32
- package/lib/sagas/clearSuggestedActionsOnPostActivitySaga.js +0 -62
- package/lib/sagas/connectSaga.js +0 -445
- package/lib/sagas/connectionStatusToNotificationSaga.js +0 -107
- package/lib/sagas/connectionStatusUpdateSaga.js +0 -63
- package/lib/sagas/detectSlowConnectionSaga.d.ts +0 -5
- package/lib/sagas/detectSlowConnectionSaga.d.ts.map +0 -1
- package/lib/sagas/detectSlowConnectionSaga.js +0 -50
- package/lib/sagas/effects/forever.js +0 -19
- package/lib/sagas/effects/forkPut.js +0 -51
- package/lib/sagas/effects/observeEach.js +0 -45
- package/lib/sagas/effects/observeOnce.d.ts +0 -3
- package/lib/sagas/effects/observeOnce.d.ts.map +0 -1
- package/lib/sagas/effects/observeOnce.js +0 -42
- package/lib/sagas/effects/whileConnected.d.ts +0 -7
- package/lib/sagas/effects/whileConnected.d.ts.map +0 -1
- package/lib/sagas/effects/whileConnected.js +0 -55
- package/lib/sagas/emitTypingIndicatorToPostActivitySaga.js +0 -63
- package/lib/sagas/markAllAsSpokenOnStopSpeakActivitySaga.js +0 -78
- package/lib/sagas/observeActivitySaga.d.ts +0 -2
- package/lib/sagas/observeActivitySaga.d.ts.map +0 -1
- package/lib/sagas/observeActivitySaga.js +0 -117
- package/lib/sagas/postActivitySaga.d.ts +0 -3
- package/lib/sagas/postActivitySaga.d.ts.map +0 -1
- package/lib/sagas/postActivitySaga.js +0 -264
- package/lib/sagas/queueIncomingActivitySaga.d.ts +0 -3
- package/lib/sagas/queueIncomingActivitySaga.d.ts.map +0 -1
- package/lib/sagas/queueIncomingActivitySaga.js +0 -197
- package/lib/sagas/sendEventToPostActivitySaga.js +0 -68
- package/lib/sagas/sendFilesToPostActivitySaga.js +0 -85
- package/lib/sagas/sendMessageBackToPostActivitySaga.js +0 -70
- package/lib/sagas/sendMessageToPostActivitySaga.d.ts +0 -2
- package/lib/sagas/sendMessageToPostActivitySaga.d.ts.map +0 -1
- package/lib/sagas/sendMessageToPostActivitySaga.js +0 -91
- package/lib/sagas/sendPostBackToPostActivitySaga.js +0 -69
- package/lib/sagas/sendTypingIndicatorOnSetSendBoxSaga.d.ts +0 -3
- package/lib/sagas/sendTypingIndicatorOnSetSendBoxSaga.d.ts.map +0 -1
- package/lib/sagas/sendTypingIndicatorOnSetSendBoxSaga.js +0 -145
- package/lib/sagas/speakActivityAndStartDictateOnIncomingActivityFromOthersSaga.js +0 -106
- package/lib/sagas/startDictateOnSpeakCompleteSaga.js +0 -65
- package/lib/sagas/startSpeakActivityOnPostActivitySaga.js +0 -62
- package/lib/sagas/stopDictateOnCardActionSaga.js +0 -65
- package/lib/sagas/stopSpeakingActivityOnInputSaga.js +0 -68
- package/lib/sagas/submitSendBoxSaga.js +0 -84
- package/lib/selectors/activities.d.ts +0 -9
- package/lib/selectors/activities.d.ts.map +0 -1
- package/lib/selectors/activities.js +0 -33
- package/lib/selectors/combineSelectors.js +0 -31
- package/lib/selectors/dictateState.js +0 -12
- package/lib/selectors/language.d.ts +0 -4
- package/lib/selectors/language.d.ts.map +0 -1
- package/lib/selectors/language.js +0 -12
- package/lib/selectors/notifications.js +0 -13
- package/lib/selectors/sendBoxAttachments.js +0 -11
- package/lib/selectors/sendBoxValue.js +0 -12
- package/lib/selectors/sendTimeout.d.ts +0 -4
- package/lib/selectors/sendTimeout.d.ts.map +0 -1
- package/lib/selectors/sendTimeout.js +0 -12
- package/lib/selectors/sendTypingIndicator.d.ts +0 -4
- package/lib/selectors/sendTypingIndicator.d.ts.map +0 -1
- package/lib/selectors/sendTypingIndicator.js +0 -12
- package/lib/selectors/shouldSpeakIncomingActivity.js +0 -12
- package/lib/types/AnyAnd.d.ts +0 -2
- package/lib/types/AnyAnd.d.ts.map +0 -1
- package/lib/types/AnyAnd.js +0 -6
- package/lib/types/GlobalScopePonyfill.d.ts +0 -8
- package/lib/types/GlobalScopePonyfill.d.ts.map +0 -1
- package/lib/types/GlobalScopePonyfill.js +0 -6
- package/lib/types/OneOrMany.d.ts +0 -3
- package/lib/types/OneOrMany.d.ts.map +0 -1
- package/lib/types/OneOrMany.js +0 -6
- package/lib/types/SendBoxAttachment.d.ts +0 -5
- package/lib/types/SendBoxAttachment.d.ts.map +0 -1
- package/lib/types/SendBoxAttachment.js +0 -6
- package/lib/types/WebChatActivity.d.ts +0 -128
- package/lib/types/WebChatActivity.d.ts.map +0 -1
- package/lib/types/WebChatActivity.js +0 -6
- package/lib/types/external/DirectLineActivity.d.ts +0 -3
- package/lib/types/external/DirectLineActivity.d.ts.map +0 -1
- package/lib/types/external/DirectLineActivity.js +0 -6
- package/lib/types/external/DirectLineAnimationCard.d.ts +0 -6
- package/lib/types/external/DirectLineAnimationCard.d.ts.map +0 -1
- package/lib/types/external/DirectLineAnimationCard.js +0 -6
- package/lib/types/external/DirectLineAttachment.d.ts +0 -9
- package/lib/types/external/DirectLineAttachment.d.ts.map +0 -1
- package/lib/types/external/DirectLineAttachment.js +0 -6
- package/lib/types/external/DirectLineAudioCard.d.ts +0 -6
- package/lib/types/external/DirectLineAudioCard.d.ts.map +0 -1
- package/lib/types/external/DirectLineAudioCard.js +0 -6
- package/lib/types/external/DirectLineBasicCardEssence.d.ts +0 -12
- package/lib/types/external/DirectLineBasicCardEssence.d.ts.map +0 -1
- package/lib/types/external/DirectLineBasicCardEssence.js +0 -6
- package/lib/types/external/DirectLineCardAction.d.ts +0 -110
- package/lib/types/external/DirectLineCardAction.d.ts.map +0 -1
- package/lib/types/external/DirectLineCardAction.js +0 -6
- package/lib/types/external/DirectLineCardImage.d.ts +0 -8
- package/lib/types/external/DirectLineCardImage.d.ts.map +0 -1
- package/lib/types/external/DirectLineCardImage.js +0 -6
- package/lib/types/external/DirectLineHeroCard.d.ts +0 -6
- package/lib/types/external/DirectLineHeroCard.d.ts.map +0 -1
- package/lib/types/external/DirectLineHeroCard.js +0 -6
- package/lib/types/external/DirectLineJSBotConnection.d.ts +0 -3
- package/lib/types/external/DirectLineJSBotConnection.d.ts.map +0 -1
- package/lib/types/external/DirectLineJSBotConnection.js +0 -6
- package/lib/types/external/DirectLineMediaCardEssence.d.ts +0 -21
- package/lib/types/external/DirectLineMediaCardEssence.d.ts.map +0 -1
- package/lib/types/external/DirectLineMediaCardEssence.js +0 -6
- package/lib/types/external/DirectLineOAuthCard.d.ts +0 -8
- package/lib/types/external/DirectLineOAuthCard.d.ts.map +0 -1
- package/lib/types/external/DirectLineOAuthCard.js +0 -6
- package/lib/types/external/DirectLineReceiptCard.d.ts +0 -28
- package/lib/types/external/DirectLineReceiptCard.d.ts.map +0 -1
- package/lib/types/external/DirectLineReceiptCard.js +0 -6
- package/lib/types/external/DirectLineSignInCard.d.ts +0 -8
- package/lib/types/external/DirectLineSignInCard.d.ts.map +0 -1
- package/lib/types/external/DirectLineSignInCard.js +0 -6
- package/lib/types/external/DirectLineSuggestedAction.d.ts +0 -7
- package/lib/types/external/DirectLineSuggestedAction.d.ts.map +0 -1
- package/lib/types/external/DirectLineSuggestedAction.js +0 -6
- package/lib/types/external/DirectLineThumbnailCard.d.ts +0 -6
- package/lib/types/external/DirectLineThumbnailCard.d.ts.map +0 -1
- package/lib/types/external/DirectLineThumbnailCard.js +0 -6
- package/lib/types/external/DirectLineVideoCard.d.ts +0 -6
- package/lib/types/external/DirectLineVideoCard.d.ts.map +0 -1
- package/lib/types/external/DirectLineVideoCard.js +0 -6
- package/lib/types/external/Observable.d.ts +0 -49
- package/lib/types/external/Observable.d.ts.map +0 -1
- package/lib/types/external/Observable.js +0 -6
- package/lib/types/external/OrgSchema/Action.d.ts +0 -29
- package/lib/types/external/OrgSchema/Action.d.ts.map +0 -1
- package/lib/types/external/OrgSchema/Action.js +0 -38
- package/lib/types/external/OrgSchema/Claim.d.ts +0 -35
- package/lib/types/external/OrgSchema/Claim.d.ts.map +0 -1
- package/lib/types/external/OrgSchema/Claim.js +0 -41
- package/lib/types/external/OrgSchema/CreativeWork.d.ts +0 -57
- package/lib/types/external/OrgSchema/CreativeWork.d.ts.map +0 -1
- package/lib/types/external/OrgSchema/CreativeWork.js +0 -52
- package/lib/types/external/OrgSchema/DefinedTerm.d.ts +0 -26
- package/lib/types/external/OrgSchema/DefinedTerm.d.ts.map +0 -1
- package/lib/types/external/OrgSchema/DefinedTerm.js +0 -33
- package/lib/types/external/OrgSchema/Project.d.ts +0 -20
- package/lib/types/external/OrgSchema/Project.d.ts.map +0 -1
- package/lib/types/external/OrgSchema/Project.js +0 -32
- package/lib/types/external/OrgSchema/Thing.d.ts +0 -53
- package/lib/types/external/OrgSchema/Thing.d.ts.map +0 -1
- package/lib/types/external/OrgSchema/Thing.js +0 -54
- package/lib/types/external/OrgSchema/VoteAction.d.ts +0 -22
- package/lib/types/external/OrgSchema/VoteAction.d.ts.map +0 -1
- package/lib/types/external/OrgSchema/VoteAction.js +0 -34
- package/lib/types/external/OrgSchema/private/orgSchemaProperties.d.ts +0 -3
- package/lib/types/external/OrgSchema/private/orgSchemaProperties.d.ts.map +0 -1
- package/lib/types/external/OrgSchema/private/orgSchemaProperties.js +0 -22
- package/lib/types/external/OrgSchema/private/orgSchemaProperty.d.ts +0 -4
- package/lib/types/external/OrgSchema/private/orgSchemaProperty.d.ts.map +0 -1
- package/lib/types/external/OrgSchema/private/orgSchemaProperty.js +0 -15
- package/lib/types/internal/GlobalScopeClock.d.ts +0 -15
- package/lib/types/internal/GlobalScopeClock.d.ts.map +0 -1
- package/lib/types/internal/GlobalScopeClock.js +0 -6
- package/lib/types/internal/Notification.d.ts +0 -10
- package/lib/types/internal/Notification.d.ts.map +0 -1
- package/lib/types/internal/Notification.js +0 -6
- package/lib/types/internal/ReduxState.d.ts +0 -19
- package/lib/types/internal/ReduxState.d.ts.map +0 -1
- package/lib/types/internal/ReduxState.js +0 -6
- package/lib/types/internal/SendStatus.d.ts +0 -7
- package/lib/types/internal/SendStatus.d.ts.map +0 -1
- package/lib/types/internal/SendStatus.js +0 -19
- package/lib/types/internal/WebChatOutgoingActivity.d.ts +0 -49
- package/lib/types/internal/WebChatOutgoingActivity.d.ts.map +0 -1
- package/lib/types/internal/WebChatOutgoingActivity.js +0 -6
- package/lib/utils/dateToLocaleISOString.d.ts +0 -2
- package/lib/utils/dateToLocaleISOString.d.ts.map +0 -1
- package/lib/utils/dateToLocaleISOString.js +0 -52
- package/lib/utils/deleteKey.d.ts +0 -2
- package/lib/utils/deleteKey.d.ts.map +0 -1
- package/lib/utils/deleteKey.js +0 -30
- package/lib/utils/getOrgSchemaMessage.d.ts +0 -4
- package/lib/utils/getOrgSchemaMessage.d.ts.map +0 -1
- package/lib/utils/getOrgSchemaMessage.js +0 -21
- package/lib/utils/isForbiddenPropertyName.d.ts +0 -2
- package/lib/utils/isForbiddenPropertyName.d.ts.map +0 -1
- package/lib/utils/isForbiddenPropertyName.js +0 -16
- package/lib/utils/onErrorResumeNext.d.ts +0 -3
- package/lib/utils/onErrorResumeNext.d.ts.map +0 -1
- package/lib/utils/onErrorResumeNext.js +0 -19
- package/lib/utils/once.d.ts +0 -2
- package/lib/utils/once.d.ts.map +0 -1
- package/lib/utils/once.js +0 -16
- package/lib/utils/singleToArray.d.ts +0 -2
- package/lib/utils/singleToArray.d.ts.map +0 -1
- package/lib/utils/singleToArray.js +0 -10
- package/lib/utils/sleep.d.ts +0 -3
- package/lib/utils/sleep.d.ts.map +0 -1
- package/lib/utils/sleep.js +0 -12
- package/lib/utils/uniqueID.d.ts +0 -2
- package/lib/utils/uniqueID.d.ts.map +0 -1
- package/lib/utils/uniqueID.js +0 -14
- package/lib/utils/warnOnce.d.ts +0 -2
- package/lib/utils/warnOnce.d.ts.map +0 -1
- package/lib/utils/warnOnce.js +0 -14
- package/src/actions/clearSuggestedActions.js +0 -9
- package/src/actions/setSuggestedActions.js +0 -12
- package/src/constants/DictateState.js +0 -7
- package/src/reducers/createActivitiesReducer.ts +0 -304
- package/src/reducers/private/findBeforeAfter.spec.ts +0 -90
- package/src/reducers/private/findBeforeAfter.ts +0 -30
- package/src/reducers/suggestedActions.js +0 -23
- package/src/types/OneOrMany.ts +0 -3
- package/src/types/external/OrgSchema/Action.spec.ts +0 -35
- package/src/types/external/OrgSchema/Action.ts +0 -52
- package/src/types/external/OrgSchema/Claim.spec.ts +0 -45
- package/src/types/external/OrgSchema/Claim.ts +0 -48
- package/src/types/external/OrgSchema/CreativeWork.parseCreativeWork.spec.ts +0 -51
- package/src/types/external/OrgSchema/CreativeWork.ts +0 -83
- package/src/types/external/OrgSchema/DefinedTerm.ts +0 -37
- package/src/types/external/OrgSchema/Project.parseProject.spec.ts +0 -17
- package/src/types/external/OrgSchema/Project.ts +0 -29
- package/src/types/external/OrgSchema/Thing.parseThing.spec.ts +0 -54
- package/src/types/external/OrgSchema/Thing.ts +0 -94
- package/src/types/external/OrgSchema/VoteAction.spec.ts +0 -35
- package/src/types/external/OrgSchema/VoteAction.ts +0 -31
- package/src/types/external/OrgSchema/private/orgSchemaProperties.spec.ts +0 -41
- package/src/types/external/OrgSchema/private/orgSchemaProperties.ts +0 -23
- package/src/types/external/OrgSchema/private/orgSchemaProperty.spec.ts +0 -21
- package/src/types/external/OrgSchema/private/orgSchemaProperty.ts +0 -6
- package/src/utils/isForbiddenPropertyName.spec.js +0 -6
- package/src/utils/isForbiddenPropertyName.ts +0 -33
- package/src/utils/singleToArray.ts +0 -3
- package/src/utils/warnOnce.ts +0 -5
- /package/src/actions/{connectionStatusUpdate.js → connectionStatusUpdate.ts} +0 -0
- /package/src/actions/{disconnect.js → disconnect.ts} +0 -0
- /package/src/actions/{emitTypingIndicator.js → emitTypingIndicator.ts} +0 -0
- /package/src/actions/{queueIncomingActivity.js → queueIncomingActivity.ts} +0 -0
- /package/src/actions/{reconnect.js → reconnect.ts} +0 -0
- /package/src/actions/{startDictate.js → startDictate.ts} +0 -0
- /package/src/actions/{startSpeakingActivity.js → startSpeakingActivity.ts} +0 -0
- /package/src/actions/{stopDictate.js → stopDictate.ts} +0 -0
- /package/src/actions/{stopSpeakingActivity.js → stopSpeakingActivity.ts} +0 -0
- /package/src/actions/{updateConnectionStatus.js → updateConnectionStatus.ts} +0 -0
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
/* eslint-disable complexity */
|
|
2
|
+
import type { GlobalScopePonyfill } from '../../../types/GlobalScopePonyfill';
|
|
3
|
+
import getActivityLivestreamingMetadata from '../../../utils/getActivityLivestreamingMetadata';
|
|
4
|
+
import computePartListTimestamp from './private/computePartListTimestamp';
|
|
5
|
+
import computeSortedActivities from './private/computeSortedActivities';
|
|
6
|
+
import getLogicalTimestamp from './private/getLogicalTimestamp';
|
|
7
|
+
import getPartGroupingMetadataMap from './private/getPartGroupingMetadataMap';
|
|
8
|
+
import insertSorted from './private/insertSorted';
|
|
9
|
+
import { toSpliced } from '@msinternal/botframework-webchat-base/utils';
|
|
10
|
+
import { getLocalIdFromActivity } from './property/LocalId';
|
|
11
|
+
import { queryPositionFromActivity, setPositionInActivity } from './property/Position';
|
|
12
|
+
import {
|
|
13
|
+
type Activity,
|
|
14
|
+
type ActivityMapEntry,
|
|
15
|
+
type HowToGroupingId,
|
|
16
|
+
type LivestreamSessionId,
|
|
17
|
+
type LivestreamSessionMapEntry,
|
|
18
|
+
type LivestreamSessionMapEntryActivityEntry,
|
|
19
|
+
type SortedChatHistoryEntry,
|
|
20
|
+
type State
|
|
21
|
+
} from './types';
|
|
22
|
+
|
|
23
|
+
// Honoring timestamp or not:
|
|
24
|
+
//
|
|
25
|
+
// - Update activity
|
|
26
|
+
// - (Should honor) every changes
|
|
27
|
+
// - Echo back activity
|
|
28
|
+
// - (Should honor) timestamp of echo back of outgoing message
|
|
29
|
+
// - Livestream activity
|
|
30
|
+
// - (Should not honor) timestamp of revisions of livestream as it could "flash" them to the bottom
|
|
31
|
+
// - Should not update session timestamp
|
|
32
|
+
// - How:
|
|
33
|
+
// - If it's 1 or Nth revision, copy the timestamp from upserting activity into session
|
|
34
|
+
// - Otherwise, it's 2...N-1, don't copy the timestamp into session
|
|
35
|
+
// - HowTo part grouping
|
|
36
|
+
// - (Should not honor) timestamp change via livestream as it could "flash" them to the bottom
|
|
37
|
+
// - Not honoring by copying the timestamp from livestream session
|
|
38
|
+
// - How: copy the timestamp from the upserting part (livestream or update) into part grouping
|
|
39
|
+
//
|
|
40
|
+
// Simplifying/concluding all rules:
|
|
41
|
+
//
|
|
42
|
+
// - Always copy timestamp, except when it's a livestream of 2...N-1 revision
|
|
43
|
+
// - Part grouping timestamp is copied from upserting entry (either livestream session or activity)
|
|
44
|
+
|
|
45
|
+
const POSITION_INCREMENT = 1_000;
|
|
46
|
+
|
|
47
|
+
const INITIAL_STATE = Object.freeze({
|
|
48
|
+
activityIdToLocalIdMap: Object.freeze(new Map()),
|
|
49
|
+
activityMap: Object.freeze(new Map()),
|
|
50
|
+
clientActivityIdToLocalIdMap: Object.freeze(new Map()),
|
|
51
|
+
livestreamSessionMap: Object.freeze(new Map()),
|
|
52
|
+
howToGroupingMap: Object.freeze(new Map()),
|
|
53
|
+
sortedActivities: Object.freeze([]),
|
|
54
|
+
sortedChatHistoryList: Object.freeze([])
|
|
55
|
+
} satisfies State);
|
|
56
|
+
|
|
57
|
+
// Question: Why insertion sort works but not quick sort?
|
|
58
|
+
// Short answer: Arrival order matters.
|
|
59
|
+
// Long answer:
|
|
60
|
+
// - Update activity: when replacing an activity, data from their previous revision matters
|
|
61
|
+
// - Duplicate timestamps: activities without timestamp can't be sort deterministically with quick sort
|
|
62
|
+
|
|
63
|
+
function upsert(ponyfill: Pick<GlobalScopePonyfill, 'Date'>, state: State, activity: Activity): State {
|
|
64
|
+
const activityLocalId = getLocalIdFromActivity(activity);
|
|
65
|
+
const logicalTimestamp = getLogicalTimestamp(activity, ponyfill);
|
|
66
|
+
const activityLivestreamingMetadata = getActivityLivestreamingMetadata(activity);
|
|
67
|
+
|
|
68
|
+
// #region Streaming fast path
|
|
69
|
+
//
|
|
70
|
+
// For revision 2..N-1 of an existing, non-finalized livestream session without HowTo grouping:
|
|
71
|
+
// avoid the heavier full rebuild path, including sortedChatHistoryList recomputation,
|
|
72
|
+
// computeSortedActivities, and full position resequencing. This is still not constant-time:
|
|
73
|
+
// the fast path continues to clone Maps and update sortedActivities, but it avoids the
|
|
74
|
+
// broader recomputation required for the general case.
|
|
75
|
+
if (activityLivestreamingMetadata) {
|
|
76
|
+
const sessionId = activityLivestreamingMetadata.sessionId as LivestreamSessionId;
|
|
77
|
+
const existingSession = state.livestreamSessionMap.get(sessionId);
|
|
78
|
+
const finalized = activityLivestreamingMetadata.type === 'final activity';
|
|
79
|
+
|
|
80
|
+
if (
|
|
81
|
+
existingSession &&
|
|
82
|
+
!existingSession.finalized &&
|
|
83
|
+
!finalized &&
|
|
84
|
+
!getPartGroupingMetadataMap(activity).has('HowTo')
|
|
85
|
+
) {
|
|
86
|
+
// Defer all Map cloning until after the position-collision check succeeds.
|
|
87
|
+
// First build the next session entry (needed to determine insertIndex), then
|
|
88
|
+
// locate the insertion point in sortedActivities, compute the new position,
|
|
89
|
+
// and only clone Maps when we know the fast path will be taken.
|
|
90
|
+
|
|
91
|
+
// 1. Compute the next session entry (needed to find insertIndex).
|
|
92
|
+
// Timestamp is NOT updated for rev 2..N-1 (only for first and final).
|
|
93
|
+
const nextSessionEntry: LivestreamSessionMapEntry = {
|
|
94
|
+
activities: Object.freeze(
|
|
95
|
+
insertSorted<LivestreamSessionMapEntryActivityEntry>(
|
|
96
|
+
existingSession.activities,
|
|
97
|
+
Object.freeze({
|
|
98
|
+
activityLocalId,
|
|
99
|
+
logicalTimestamp,
|
|
100
|
+
sequenceNumber: activityLivestreamingMetadata.sequenceNumber,
|
|
101
|
+
type: 'activity'
|
|
102
|
+
}),
|
|
103
|
+
({ sequenceNumber: x }, { sequenceNumber: y }) =>
|
|
104
|
+
typeof x === 'undefined' || typeof y === 'undefined'
|
|
105
|
+
? // eslint-disable-next-line no-magic-numbers
|
|
106
|
+
-1
|
|
107
|
+
: x - y
|
|
108
|
+
)
|
|
109
|
+
),
|
|
110
|
+
finalized: false,
|
|
111
|
+
logicalTimestamp: existingSession.logicalTimestamp
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// 2. sortedActivities: find the insertion point before cloning anything.
|
|
115
|
+
// The session's activities are sorted by sequence number via insertSorted.
|
|
116
|
+
// Find where the new activity landed in that list and locate the correct
|
|
117
|
+
// insertion point in sortedActivities relative to its session neighbors.
|
|
118
|
+
const newIndexInSession = nextSessionEntry.activities.findIndex(
|
|
119
|
+
entry => entry.activityLocalId === activityLocalId
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const successorInSession =
|
|
123
|
+
newIndexInSession + 1 < nextSessionEntry.activities.length
|
|
124
|
+
? nextSessionEntry.activities[newIndexInSession + 1]
|
|
125
|
+
: undefined;
|
|
126
|
+
|
|
127
|
+
let insertIndex = state.sortedActivities.length;
|
|
128
|
+
|
|
129
|
+
if (successorInSession) {
|
|
130
|
+
// Insert before the successor activity in sortedActivities.
|
|
131
|
+
for (let i = 0; i < state.sortedActivities.length; i++) {
|
|
132
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
133
|
+
if (getLocalIdFromActivity(state.sortedActivities[i]!) === successorInSession.activityLocalId) {
|
|
134
|
+
insertIndex = i;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
// New activity is last in the session; insert after the previous last activity.
|
|
140
|
+
// eslint-disable-next-line no-magic-numbers
|
|
141
|
+
const prevLastSessionActivity = existingSession.activities.at(-1);
|
|
142
|
+
|
|
143
|
+
if (prevLastSessionActivity) {
|
|
144
|
+
for (let i = state.sortedActivities.length - 1; i >= 0; i--) {
|
|
145
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
146
|
+
if (getLocalIdFromActivity(state.sortedActivities[i]!) === prevLastSessionActivity.activityLocalId) {
|
|
147
|
+
insertIndex = i + 1;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// 3. Position: assign the new activity a position based on its neighbors.
|
|
155
|
+
const prevPosition =
|
|
156
|
+
insertIndex > 0 ? (queryPositionFromActivity(state.sortedActivities[insertIndex - 1]!) ?? 0) : 0;
|
|
157
|
+
|
|
158
|
+
const nextSiblingPosition =
|
|
159
|
+
insertIndex < state.sortedActivities.length
|
|
160
|
+
? queryPositionFromActivity(state.sortedActivities[+insertIndex]!)
|
|
161
|
+
: undefined;
|
|
162
|
+
|
|
163
|
+
let newPosition = prevPosition + POSITION_INCREMENT;
|
|
164
|
+
|
|
165
|
+
// Squeeze if the default increment would collide with the next sibling.
|
|
166
|
+
if (typeof nextSiblingPosition !== 'undefined' && newPosition >= nextSiblingPosition) {
|
|
167
|
+
newPosition = prevPosition + 1;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// If position is valid (no collision), clone Maps and return fast path result.
|
|
171
|
+
// Otherwise fall through to slow path for full re-sequencing.
|
|
172
|
+
if (typeof nextSiblingPosition === 'undefined' || newPosition < nextSiblingPosition) {
|
|
173
|
+
const positionedActivity = setPositionInActivity(activity, newPosition);
|
|
174
|
+
|
|
175
|
+
// 4. activityIdToLocalIdMap: reuse if no activity.id, copy + add otherwise.
|
|
176
|
+
let nextActivityIdToLocalIdMap = state.activityIdToLocalIdMap;
|
|
177
|
+
|
|
178
|
+
if (typeof activity.id !== 'undefined') {
|
|
179
|
+
nextActivityIdToLocalIdMap = new Map(state.activityIdToLocalIdMap);
|
|
180
|
+
nextActivityIdToLocalIdMap.set(activity.id, activityLocalId);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// 5. activityMap: +1 entry with the positioned activity.
|
|
184
|
+
const nextActivityMap = new Map(state.activityMap);
|
|
185
|
+
|
|
186
|
+
nextActivityMap.set(
|
|
187
|
+
activityLocalId,
|
|
188
|
+
Object.freeze({ activity: positionedActivity, activityLocalId, logicalTimestamp, type: 'activity' as const })
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
// 6. clientActivityIdToLocalIdMap: reuse if no clientActivityID, copy + add otherwise.
|
|
192
|
+
const { clientActivityID } = activity.channelData;
|
|
193
|
+
let nextClientActivityIdToLocalIdMap = state.clientActivityIdToLocalIdMap;
|
|
194
|
+
|
|
195
|
+
if (typeof clientActivityID !== 'undefined') {
|
|
196
|
+
nextClientActivityIdToLocalIdMap = new Map(state.clientActivityIdToLocalIdMap);
|
|
197
|
+
nextClientActivityIdToLocalIdMap.set(clientActivityID, activityLocalId);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// 7. livestreamSessionMap: record the updated session.
|
|
201
|
+
const nextLivestreamSessionMap = new Map(state.livestreamSessionMap);
|
|
202
|
+
|
|
203
|
+
nextLivestreamSessionMap.set(sessionId, Object.freeze(nextSessionEntry));
|
|
204
|
+
|
|
205
|
+
return Object.freeze({
|
|
206
|
+
activityIdToLocalIdMap: Object.freeze(nextActivityIdToLocalIdMap),
|
|
207
|
+
activityMap: Object.freeze(nextActivityMap),
|
|
208
|
+
clientActivityIdToLocalIdMap: Object.freeze(nextClientActivityIdToLocalIdMap),
|
|
209
|
+
howToGroupingMap: state.howToGroupingMap,
|
|
210
|
+
livestreamSessionMap: Object.freeze(nextLivestreamSessionMap),
|
|
211
|
+
sortedActivities: Object.freeze(toSpliced(state.sortedActivities, insertIndex, 0, positionedActivity)),
|
|
212
|
+
sortedChatHistoryList: state.sortedChatHistoryList
|
|
213
|
+
} satisfies State);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// #endregion
|
|
219
|
+
|
|
220
|
+
// Slow path: full recalculation for non-streaming, first/final revisions, reorders, or HowTo grouping.
|
|
221
|
+
const nextActivityIdToLocalIdMap = new Map(state.activityIdToLocalIdMap);
|
|
222
|
+
const nextActivityMap = new Map(state.activityMap);
|
|
223
|
+
const nextClientActivityIdToLocalIdMap = new Map(state.clientActivityIdToLocalIdMap);
|
|
224
|
+
const nextLivestreamSessionMap = new Map(state.livestreamSessionMap);
|
|
225
|
+
const nextHowToGroupingMap = new Map(state.howToGroupingMap);
|
|
226
|
+
let nextSortedChatHistoryList = Array.from(state.sortedChatHistoryList);
|
|
227
|
+
|
|
228
|
+
if (typeof activity.id !== 'undefined') {
|
|
229
|
+
nextActivityIdToLocalIdMap.set(activity.id, activityLocalId);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const { clientActivityID } = activity.channelData;
|
|
233
|
+
|
|
234
|
+
if (typeof clientActivityID !== 'undefined') {
|
|
235
|
+
nextClientActivityIdToLocalIdMap.set(clientActivityID, activityLocalId);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
nextActivityMap.set(
|
|
239
|
+
activityLocalId,
|
|
240
|
+
Object.freeze({
|
|
241
|
+
activity,
|
|
242
|
+
activityLocalId,
|
|
243
|
+
logicalTimestamp,
|
|
244
|
+
type: 'activity'
|
|
245
|
+
})
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
let sortedChatHistoryListEntry: SortedChatHistoryEntry = {
|
|
249
|
+
activityLocalId,
|
|
250
|
+
logicalTimestamp,
|
|
251
|
+
type: 'activity'
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// #region Livestreaming
|
|
255
|
+
|
|
256
|
+
if (activityLivestreamingMetadata) {
|
|
257
|
+
const sessionId = activityLivestreamingMetadata.sessionId as LivestreamSessionId;
|
|
258
|
+
|
|
259
|
+
const livestreamSessionMapEntry = nextLivestreamSessionMap.get(sessionId);
|
|
260
|
+
|
|
261
|
+
const wasFinalized = livestreamSessionMapEntry ? livestreamSessionMapEntry.finalized : false;
|
|
262
|
+
|
|
263
|
+
if (wasFinalized) {
|
|
264
|
+
console.warn(
|
|
265
|
+
`botframework-webchat: Cannot update livestreaming session ${sessionId} because it has been concluded`
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
// This is a special case.
|
|
269
|
+
// TODO: [P1] Revisit this and see how we should process activity after the livestream is finalized.
|
|
270
|
+
// 1. Received a previous-and-valid revision while the livestream is finalized (probably should keep to maintain history)
|
|
271
|
+
// 2. Received a final activity while the livestream is already finalized (probably drop due to bad packet)
|
|
272
|
+
// Related to /__tests__/html2/livestream/concludedLivestream.html.
|
|
273
|
+
return state;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const finalized = activityLivestreamingMetadata.type === 'final activity';
|
|
277
|
+
|
|
278
|
+
const nextLivestreamSessionMapEntry = {
|
|
279
|
+
activities: Object.freeze(
|
|
280
|
+
insertSorted<LivestreamSessionMapEntryActivityEntry>(
|
|
281
|
+
livestreamSessionMapEntry ? livestreamSessionMapEntry.activities : [],
|
|
282
|
+
Object.freeze({
|
|
283
|
+
activityLocalId,
|
|
284
|
+
logicalTimestamp,
|
|
285
|
+
sequenceNumber: activityLivestreamingMetadata.sequenceNumber,
|
|
286
|
+
type: 'activity'
|
|
287
|
+
}),
|
|
288
|
+
({ sequenceNumber: x }, { sequenceNumber: y }) =>
|
|
289
|
+
typeof x === 'undefined' || typeof y === 'undefined'
|
|
290
|
+
? // eslint-disable-next-line no-magic-numbers
|
|
291
|
+
-1
|
|
292
|
+
: x - y
|
|
293
|
+
)
|
|
294
|
+
),
|
|
295
|
+
finalized,
|
|
296
|
+
// Update timestamp if the upserting activity is the first or last in the livestream session.
|
|
297
|
+
// We don't update timestamp for 2...N-1, because it would cause too much flickering.
|
|
298
|
+
logicalTimestamp:
|
|
299
|
+
finalized || !livestreamSessionMapEntry ? logicalTimestamp : livestreamSessionMapEntry.logicalTimestamp
|
|
300
|
+
} satisfies LivestreamSessionMapEntry;
|
|
301
|
+
|
|
302
|
+
nextLivestreamSessionMap.set(sessionId, Object.freeze(nextLivestreamSessionMapEntry));
|
|
303
|
+
|
|
304
|
+
sortedChatHistoryListEntry = {
|
|
305
|
+
livestreamSessionId: sessionId,
|
|
306
|
+
logicalTimestamp: nextLivestreamSessionMapEntry.logicalTimestamp,
|
|
307
|
+
type: 'livestream session'
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// #endregion
|
|
312
|
+
|
|
313
|
+
// #region How-to grouping
|
|
314
|
+
|
|
315
|
+
const howToGrouping = getPartGroupingMetadataMap(activity).get('HowTo');
|
|
316
|
+
|
|
317
|
+
if (howToGrouping) {
|
|
318
|
+
const howToGroupingId = howToGrouping.groupingId as HowToGroupingId;
|
|
319
|
+
const { position: howToGroupingPosition } = howToGrouping;
|
|
320
|
+
|
|
321
|
+
const partGroupingMapEntry = nextHowToGroupingMap.get(howToGroupingId);
|
|
322
|
+
|
|
323
|
+
let nextPartList = partGroupingMapEntry ? Array.from(partGroupingMapEntry.partList) : [];
|
|
324
|
+
|
|
325
|
+
const existingPartEntryIndex = activityLivestreamingMetadata
|
|
326
|
+
? nextPartList.findIndex(
|
|
327
|
+
entry =>
|
|
328
|
+
entry.type === 'livestream session' && entry.livestreamSessionId === activityLivestreamingMetadata.sessionId
|
|
329
|
+
)
|
|
330
|
+
: nextPartList.findIndex(entry => entry.type === 'activity' && entry.activityLocalId === activityLocalId);
|
|
331
|
+
|
|
332
|
+
const nextPartEntry = Object.freeze({ ...sortedChatHistoryListEntry, position: howToGroupingPosition });
|
|
333
|
+
|
|
334
|
+
// If the upserting activity is position-less and an earlier revision is in the grouping, update the existing entry instead of splice/insert.
|
|
335
|
+
if (~existingPartEntryIndex && typeof howToGroupingPosition === 'undefined') {
|
|
336
|
+
nextPartList[+existingPartEntryIndex] = nextPartEntry;
|
|
337
|
+
} else {
|
|
338
|
+
// The upserting activity has position, or it never exist in the grouping.
|
|
339
|
+
~existingPartEntryIndex && nextPartList.splice(existingPartEntryIndex, 1);
|
|
340
|
+
|
|
341
|
+
nextPartList = insertSorted(
|
|
342
|
+
nextPartList,
|
|
343
|
+
nextPartEntry,
|
|
344
|
+
// eslint-disable-next-line no-magic-numbers
|
|
345
|
+
({ position: x }, { position: y }) => (typeof x === 'undefined' || typeof y === 'undefined' ? -1 : x - y)
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const nextPartGroupingEntry = {
|
|
350
|
+
logicalTimestamp: computePartListTimestamp(nextPartList),
|
|
351
|
+
partList: Object.freeze(nextPartList)
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
nextHowToGroupingMap.set(howToGroupingId, Object.freeze(nextPartGroupingEntry));
|
|
355
|
+
|
|
356
|
+
sortedChatHistoryListEntry = {
|
|
357
|
+
howToGroupingId,
|
|
358
|
+
logicalTimestamp: nextPartGroupingEntry.logicalTimestamp,
|
|
359
|
+
type: 'how to grouping'
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// #endregion
|
|
364
|
+
|
|
365
|
+
// #region Sorted chat history
|
|
366
|
+
|
|
367
|
+
const existingSortedChatHistoryListEntryIndex =
|
|
368
|
+
sortedChatHistoryListEntry.type === 'how to grouping'
|
|
369
|
+
? nextSortedChatHistoryList.findIndex(
|
|
370
|
+
entry =>
|
|
371
|
+
entry.type === 'how to grouping' && entry.howToGroupingId === sortedChatHistoryListEntry.howToGroupingId
|
|
372
|
+
)
|
|
373
|
+
: sortedChatHistoryListEntry.type === 'livestream session'
|
|
374
|
+
? nextSortedChatHistoryList.findIndex(
|
|
375
|
+
entry =>
|
|
376
|
+
entry.type === 'livestream session' &&
|
|
377
|
+
entry.livestreamSessionId === sortedChatHistoryListEntry.livestreamSessionId
|
|
378
|
+
)
|
|
379
|
+
: sortedChatHistoryListEntry.type === 'activity'
|
|
380
|
+
? nextSortedChatHistoryList.findIndex(
|
|
381
|
+
entry => entry.type === 'activity' && entry.activityLocalId === activityLocalId
|
|
382
|
+
)
|
|
383
|
+
: // eslint-disable-next-line no-magic-numbers
|
|
384
|
+
-1;
|
|
385
|
+
|
|
386
|
+
~existingSortedChatHistoryListEntryIndex &&
|
|
387
|
+
nextSortedChatHistoryList.splice(existingSortedChatHistoryListEntryIndex, 1);
|
|
388
|
+
|
|
389
|
+
nextSortedChatHistoryList = insertSorted(
|
|
390
|
+
nextSortedChatHistoryList,
|
|
391
|
+
Object.freeze(sortedChatHistoryListEntry),
|
|
392
|
+
(x, y) => {
|
|
393
|
+
// Compare logical timestamp if both have it.
|
|
394
|
+
// Otherwise, compare local timestamp if both have it.
|
|
395
|
+
// Otherwise, -1.
|
|
396
|
+
const xLogicalTimestamp = x.logicalTimestamp;
|
|
397
|
+
const yLogicalTimestamp = y.logicalTimestamp;
|
|
398
|
+
|
|
399
|
+
if (typeof xLogicalTimestamp !== 'undefined' && typeof yLogicalTimestamp !== 'undefined') {
|
|
400
|
+
return xLogicalTimestamp - yLogicalTimestamp;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (x.type === 'activity' && y.type === 'activity') {
|
|
404
|
+
const xActivity = nextActivityMap.get(x.activityLocalId);
|
|
405
|
+
const yActivity = nextActivityMap.get(y.activityLocalId);
|
|
406
|
+
|
|
407
|
+
const xLocalTimestamp = xActivity?.activity.localTimestamp;
|
|
408
|
+
const yLocalTimestamp = yActivity?.activity.localTimestamp;
|
|
409
|
+
|
|
410
|
+
if (typeof xLocalTimestamp !== 'undefined' && typeof yLocalTimestamp !== 'undefined') {
|
|
411
|
+
return +new ponyfill.Date(xLocalTimestamp) - +new ponyfill.Date(yLocalTimestamp);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// eslint-disable-next-line no-magic-numbers
|
|
416
|
+
return -1;
|
|
417
|
+
}
|
|
418
|
+
);
|
|
419
|
+
// }
|
|
420
|
+
|
|
421
|
+
// #endregion
|
|
422
|
+
|
|
423
|
+
// #region Sorted activities
|
|
424
|
+
|
|
425
|
+
const nextSortedActivities = computeSortedActivities({
|
|
426
|
+
activityMap: nextActivityMap,
|
|
427
|
+
howToGroupingMap: nextHowToGroupingMap,
|
|
428
|
+
livestreamSessionMap: nextLivestreamSessionMap,
|
|
429
|
+
sortedChatHistoryList: nextSortedChatHistoryList
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
// #endregion
|
|
433
|
+
|
|
434
|
+
// #region Sequence sorted activities
|
|
435
|
+
|
|
436
|
+
let lastPosition = 0;
|
|
437
|
+
|
|
438
|
+
for (
|
|
439
|
+
let index = 0, { length: nextSortedActivitiesLength } = nextSortedActivities;
|
|
440
|
+
index < nextSortedActivitiesLength;
|
|
441
|
+
index++
|
|
442
|
+
) {
|
|
443
|
+
const currentActivity = nextSortedActivities[+index]!;
|
|
444
|
+
const currentActivityId = getLocalIdFromActivity(currentActivity);
|
|
445
|
+
const hasNextSibling = index + 1 < nextSortedActivitiesLength;
|
|
446
|
+
const position = queryPositionFromActivity(currentActivity);
|
|
447
|
+
|
|
448
|
+
let nextPosition: number;
|
|
449
|
+
|
|
450
|
+
if (typeof position === 'undefined' || position <= lastPosition) {
|
|
451
|
+
if (hasNextSibling) {
|
|
452
|
+
const nextSiblingPosition = queryPositionFromActivity(nextSortedActivities[+index + 1]!);
|
|
453
|
+
|
|
454
|
+
nextPosition = lastPosition + 1;
|
|
455
|
+
|
|
456
|
+
if (typeof nextSiblingPosition === 'undefined' || nextPosition > nextSiblingPosition) {
|
|
457
|
+
nextPosition = lastPosition + POSITION_INCREMENT;
|
|
458
|
+
}
|
|
459
|
+
} else {
|
|
460
|
+
nextPosition = lastPosition + POSITION_INCREMENT;
|
|
461
|
+
}
|
|
462
|
+
} else {
|
|
463
|
+
nextPosition = position;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (nextPosition !== position) {
|
|
467
|
+
const activityMapEntry = nextActivityMap.get(currentActivityId)!;
|
|
468
|
+
|
|
469
|
+
const nextActivityEntry: ActivityMapEntry = Object.freeze({
|
|
470
|
+
...activityMapEntry,
|
|
471
|
+
// TODO: [P0] We should freeze the activity.
|
|
472
|
+
// For backcompat, we should consider have a props that temporarily disable this behavior.
|
|
473
|
+
activity: setPositionInActivity(activityMapEntry.activity, nextPosition)
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
nextActivityMap.set(currentActivityId, nextActivityEntry);
|
|
477
|
+
|
|
478
|
+
nextSortedActivities[+index] = nextActivityEntry.activity;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
lastPosition = nextPosition;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// #endregion
|
|
485
|
+
|
|
486
|
+
return Object.freeze({
|
|
487
|
+
activityIdToLocalIdMap: Object.freeze(nextActivityIdToLocalIdMap),
|
|
488
|
+
activityMap: Object.freeze(nextActivityMap),
|
|
489
|
+
clientActivityIdToLocalIdMap: Object.freeze(nextClientActivityIdToLocalIdMap),
|
|
490
|
+
howToGroupingMap: Object.freeze(nextHowToGroupingMap),
|
|
491
|
+
livestreamSessionMap: Object.freeze(nextLivestreamSessionMap),
|
|
492
|
+
sortedActivities: Object.freeze(nextSortedActivities),
|
|
493
|
+
sortedChatHistoryList: Object.freeze(nextSortedChatHistoryList)
|
|
494
|
+
} satisfies State);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export default upsert;
|
|
498
|
+
export { INITIAL_STATE };
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
import { isForbiddenPropertyName } from '@msinternal/botframework-webchat-base/utils';
|
|
1
2
|
import updateIn from 'simple-update-in';
|
|
2
3
|
|
|
3
4
|
import { DISMISS_NOTIFICATION } from '../actions/dismissNotification';
|
|
4
5
|
import { SAGA_ERROR } from '../actions/sagaError';
|
|
5
6
|
import { SET_NOTIFICATION } from '../actions/setNotification';
|
|
6
|
-
import isForbiddenPropertyName from '../utils/isForbiddenPropertyName';
|
|
7
7
|
|
|
8
|
-
import type { DismissNotificationAction } from '../actions/dismissNotification';
|
|
9
|
-
import type { GlobalScopePonyfill } from '../types/GlobalScopePonyfill';
|
|
10
|
-
import type { Notification } from '../types/internal/Notification';
|
|
11
8
|
import type { Reducer } from 'redux';
|
|
9
|
+
import type { DismissNotificationAction } from '../actions/dismissNotification';
|
|
12
10
|
import type { SagaErrorAction } from '../actions/sagaError';
|
|
13
11
|
import type { SetNotificationAction } from '../actions/setNotification';
|
|
12
|
+
import type { GlobalScopePonyfill } from '../types/GlobalScopePonyfill';
|
|
13
|
+
import type { Notification } from '../types/internal/Notification';
|
|
14
14
|
|
|
15
15
|
type NotificationsAction = DismissNotificationAction | SagaErrorAction | SetNotificationAction;
|
|
16
16
|
type NotificationsState = Record<string, Notification>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Action } from 'redux';
|
|
2
|
+
import { parse } from 'valibot';
|
|
3
|
+
|
|
4
|
+
import { SET_RAW_STATE, setRawStateActionSchema } from '../internal/actions/setRawState';
|
|
5
|
+
import { type SuggestedActionsState } from '../internal/types/suggestedActions';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_STATE: SuggestedActionsState = Object.freeze([]);
|
|
8
|
+
|
|
9
|
+
function suggestedActions(state: SuggestedActionsState = DEFAULT_STATE, action: Action): SuggestedActionsState {
|
|
10
|
+
if (action.type === SET_RAW_STATE) {
|
|
11
|
+
const parsedAction = parse(setRawStateActionSchema, action);
|
|
12
|
+
|
|
13
|
+
if (parsedAction.payload.name === 'suggestedActions') {
|
|
14
|
+
({ state } = parsedAction.payload);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return state;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default suggestedActions;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Action } from 'redux';
|
|
2
|
+
import { parse } from 'valibot';
|
|
3
|
+
|
|
4
|
+
import { SET_RAW_STATE, setRawStateActionSchema } from '../internal/actions/setRawState';
|
|
5
|
+
import { type SuggestedActionsOriginActivityState } from '../internal/types/suggestedActionsOriginActivity';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_STATE: SuggestedActionsOriginActivityState = Object.freeze({ activity: undefined });
|
|
8
|
+
|
|
9
|
+
function suggestedActionsOriginActivity(
|
|
10
|
+
state: SuggestedActionsOriginActivityState = DEFAULT_STATE,
|
|
11
|
+
action: Action
|
|
12
|
+
): SuggestedActionsOriginActivityState {
|
|
13
|
+
if (action.type === SET_RAW_STATE) {
|
|
14
|
+
const parsedAction = parse(setRawStateActionSchema, action);
|
|
15
|
+
|
|
16
|
+
if (parsedAction.payload.name === 'suggestedActionsOriginActivity') {
|
|
17
|
+
({ state } = parsedAction.payload);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return state;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default suggestedActionsOriginActivity;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { VOICE_MUTE_RECORDING } from '../actions/muteVoiceRecording';
|
|
2
|
+
import { VOICE_REGISTER_HANDLER } from '../actions/registerVoiceHandler';
|
|
3
|
+
import { VOICE_SET_STATE } from '../actions/setVoiceState';
|
|
4
|
+
import { VOICE_START_RECORDING } from '../actions/startVoiceRecording';
|
|
5
|
+
import { VOICE_STOP_RECORDING } from '../actions/stopVoiceRecording';
|
|
6
|
+
import { VOICE_UNMUTE_RECORDING } from '../actions/unmuteVoiceRecording';
|
|
7
|
+
import { VOICE_UNREGISTER_HANDLER } from '../actions/unregisterVoiceHandler';
|
|
8
|
+
|
|
9
|
+
import type { VoiceMuteRecordingAction } from '../actions/muteVoiceRecording';
|
|
10
|
+
import type { VoiceHandler, VoiceRegisterHandlerAction } from '../actions/registerVoiceHandler';
|
|
11
|
+
import type { VoiceSetStateAction, VoiceState } from '../actions/setVoiceState';
|
|
12
|
+
import type { VoiceStartRecordingAction } from '../actions/startVoiceRecording';
|
|
13
|
+
import type { VoiceStopRecordingAction } from '../actions/stopVoiceRecording';
|
|
14
|
+
import type { VoiceUnmuteRecordingAction } from '../actions/unmuteVoiceRecording';
|
|
15
|
+
import type { VoiceUnregisterHandlerAction } from '../actions/unregisterVoiceHandler';
|
|
16
|
+
|
|
17
|
+
type VoiceActivityActions =
|
|
18
|
+
| VoiceMuteRecordingAction
|
|
19
|
+
| VoiceRegisterHandlerAction
|
|
20
|
+
| VoiceSetStateAction
|
|
21
|
+
| VoiceStartRecordingAction
|
|
22
|
+
| VoiceStopRecordingAction
|
|
23
|
+
| VoiceUnmuteRecordingAction
|
|
24
|
+
| VoiceUnregisterHandlerAction;
|
|
25
|
+
|
|
26
|
+
interface VoiceActivityState {
|
|
27
|
+
microphoneMuted: boolean;
|
|
28
|
+
voiceState: VoiceState;
|
|
29
|
+
voiceHandlers: Map<string, VoiceHandler>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const DEFAULT_STATE: VoiceActivityState = {
|
|
33
|
+
microphoneMuted: false,
|
|
34
|
+
voiceState: 'idle',
|
|
35
|
+
voiceHandlers: new Map()
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default function voiceActivity(
|
|
39
|
+
state: VoiceActivityState = DEFAULT_STATE,
|
|
40
|
+
action: VoiceActivityActions
|
|
41
|
+
): VoiceActivityState {
|
|
42
|
+
switch (action.type) {
|
|
43
|
+
case VOICE_MUTE_RECORDING:
|
|
44
|
+
return {
|
|
45
|
+
...state,
|
|
46
|
+
microphoneMuted: true
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
case VOICE_REGISTER_HANDLER: {
|
|
50
|
+
const newHandlers = new Map(state.voiceHandlers);
|
|
51
|
+
newHandlers.set(action.payload.id, action.payload.voiceHandler);
|
|
52
|
+
return {
|
|
53
|
+
...state,
|
|
54
|
+
voiceHandlers: newHandlers
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
case VOICE_UNREGISTER_HANDLER: {
|
|
59
|
+
const newHandlers = new Map(state.voiceHandlers);
|
|
60
|
+
newHandlers.delete(action.payload.id);
|
|
61
|
+
return {
|
|
62
|
+
...state,
|
|
63
|
+
voiceHandlers: newHandlers
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
case VOICE_SET_STATE:
|
|
68
|
+
return {
|
|
69
|
+
...state,
|
|
70
|
+
voiceState: action.payload.voiceState
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
case VOICE_START_RECORDING:
|
|
74
|
+
if (state.voiceState !== 'idle') {
|
|
75
|
+
console.warn(`botframework-webchat: Should not transit from "${state.voiceState}" to "listening"`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
...state,
|
|
80
|
+
microphoneMuted: false,
|
|
81
|
+
voiceState: 'listening'
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
case VOICE_STOP_RECORDING:
|
|
85
|
+
return {
|
|
86
|
+
...state,
|
|
87
|
+
microphoneMuted: false,
|
|
88
|
+
voiceState: 'idle'
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
case VOICE_UNMUTE_RECORDING:
|
|
92
|
+
return {
|
|
93
|
+
...state,
|
|
94
|
+
microphoneMuted: false
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
default:
|
|
98
|
+
return state;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type { VoiceActivityState };
|