botframework-webchat-core 4.18.1 → 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,177 @@
|
|
|
1
|
+
import computePartListTimestamp from './private/computePartListTimestamp';
|
|
2
|
+
import computeSortedActivities from './private/computeSortedActivities';
|
|
3
|
+
import type { LocalId } from './property/LocalId';
|
|
4
|
+
import type { LivestreamSessionMapEntry, State } from './types';
|
|
5
|
+
|
|
6
|
+
export default function deleteActivityByLocalId(state: State, localId: LocalId): State {
|
|
7
|
+
const nextActivityIdToLocalIdMap = new Map(state.activityIdToLocalIdMap);
|
|
8
|
+
const nextActivityMap = new Map(state.activityMap);
|
|
9
|
+
const nextClientActivityIdToLocalIdMap = new Map(state.clientActivityIdToLocalIdMap);
|
|
10
|
+
const nextHowToGroupingMap = new Map(state.howToGroupingMap);
|
|
11
|
+
const nextLivestreamSessionMap = new Map(state.livestreamSessionMap);
|
|
12
|
+
let nextSortedChatHistoryList = Array.from(state.sortedChatHistoryList);
|
|
13
|
+
|
|
14
|
+
if (!nextActivityMap.delete(localId)) {
|
|
15
|
+
throw new Error(`botframework-webchat: Cannot find activity with local ID "${localId}" to delete`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
for (const entry of nextActivityIdToLocalIdMap) {
|
|
19
|
+
if (entry[1] === localId) {
|
|
20
|
+
nextActivityIdToLocalIdMap.delete(entry[0]);
|
|
21
|
+
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
for (const entry of nextClientActivityIdToLocalIdMap) {
|
|
27
|
+
if (entry[1] === localId) {
|
|
28
|
+
nextClientActivityIdToLocalIdMap.delete(entry[0]);
|
|
29
|
+
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
for (const [howToGroupingId, entry] of nextHowToGroupingMap) {
|
|
35
|
+
const partIndex = entry.partList.findIndex(part => part.type === 'activity' && part.activityLocalId === localId);
|
|
36
|
+
|
|
37
|
+
if (~partIndex) {
|
|
38
|
+
const nextPartList = Array.from(entry.partList);
|
|
39
|
+
|
|
40
|
+
nextPartList.splice(partIndex, 1);
|
|
41
|
+
|
|
42
|
+
if (nextPartList.length) {
|
|
43
|
+
const nextHowToGroupingMapEntry = Object.freeze({
|
|
44
|
+
...entry,
|
|
45
|
+
logicalTimestamp: computePartListTimestamp(nextPartList),
|
|
46
|
+
partList: Object.freeze(nextPartList)
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
nextHowToGroupingMap.set(howToGroupingId, nextHowToGroupingMapEntry);
|
|
50
|
+
|
|
51
|
+
nextSortedChatHistoryList = nextSortedChatHistoryList.map(entry => {
|
|
52
|
+
if (entry.type === 'how to grouping' && entry.howToGroupingId === howToGroupingId) {
|
|
53
|
+
return {
|
|
54
|
+
howToGroupingId,
|
|
55
|
+
logicalTimestamp: nextHowToGroupingMapEntry.logicalTimestamp,
|
|
56
|
+
type: 'how to grouping'
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return entry;
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
nextHowToGroupingMap.delete(howToGroupingId);
|
|
64
|
+
|
|
65
|
+
const sortedChatHistoryListIndex = nextSortedChatHistoryList.findIndex(
|
|
66
|
+
entry => entry.type === 'how to grouping' && entry.howToGroupingId === howToGroupingId
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
~sortedChatHistoryListIndex && nextSortedChatHistoryList.splice(sortedChatHistoryListIndex, 1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for (const [livestreamSessionId, livestreamSessionMapEntry] of nextLivestreamSessionMap) {
|
|
75
|
+
const activityIndex = livestreamSessionMapEntry.activities.findIndex(
|
|
76
|
+
activity => activity.activityLocalId === localId
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
if (~activityIndex) {
|
|
80
|
+
const nextActivities = Array.from(livestreamSessionMapEntry.activities);
|
|
81
|
+
|
|
82
|
+
nextActivities.splice(activityIndex, 1);
|
|
83
|
+
|
|
84
|
+
if (nextActivities.length) {
|
|
85
|
+
// eslint-disable-next-line no-magic-numbers
|
|
86
|
+
const lastActivity = nextActivities.at(-1);
|
|
87
|
+
const finalActivity = lastActivity?.sequenceNumber === Infinity ? lastActivity : undefined;
|
|
88
|
+
|
|
89
|
+
const logicalTimestamp = finalActivity
|
|
90
|
+
? finalActivity.logicalTimestamp
|
|
91
|
+
: nextActivities.at(0)?.logicalTimestamp;
|
|
92
|
+
|
|
93
|
+
const nextLivestreamSessionMapEntry: LivestreamSessionMapEntry = {
|
|
94
|
+
...livestreamSessionMapEntry,
|
|
95
|
+
activities: nextActivities,
|
|
96
|
+
finalized: !!finalActivity,
|
|
97
|
+
logicalTimestamp
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
nextLivestreamSessionMap.set(livestreamSessionId, nextLivestreamSessionMapEntry);
|
|
101
|
+
|
|
102
|
+
for (const [howToGroupingId, entry] of nextHowToGroupingMap) {
|
|
103
|
+
let changed = false;
|
|
104
|
+
|
|
105
|
+
const nextPartList = entry.partList.map(part => {
|
|
106
|
+
if (part.type === 'livestream session' && part.livestreamSessionId === livestreamSessionId) {
|
|
107
|
+
changed = true;
|
|
108
|
+
|
|
109
|
+
return { ...part, logicalTimestamp };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return part;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
if (changed) {
|
|
116
|
+
nextHowToGroupingMap.set(howToGroupingId, {
|
|
117
|
+
...entry,
|
|
118
|
+
logicalTimestamp: computePartListTimestamp(nextPartList),
|
|
119
|
+
partList: nextPartList
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
nextLivestreamSessionMap.delete(livestreamSessionId);
|
|
125
|
+
|
|
126
|
+
const sortedChatHistoryListIndex = nextSortedChatHistoryList.findIndex(
|
|
127
|
+
entry => entry.type === 'livestream session' && entry.livestreamSessionId === livestreamSessionId
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
~sortedChatHistoryListIndex && nextSortedChatHistoryList.splice(sortedChatHistoryListIndex, 1);
|
|
131
|
+
|
|
132
|
+
for (const [howToGroupingId, entry] of nextHowToGroupingMap) {
|
|
133
|
+
const partIndex = entry.partList.findIndex(
|
|
134
|
+
part => part.type === 'livestream session' && part.livestreamSessionId === livestreamSessionId
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
if (~partIndex) {
|
|
138
|
+
const nextPartList = Array.from(entry.partList);
|
|
139
|
+
|
|
140
|
+
nextPartList.splice(partIndex, 1);
|
|
141
|
+
|
|
142
|
+
nextHowToGroupingMap.set(howToGroupingId, {
|
|
143
|
+
...entry,
|
|
144
|
+
logicalTimestamp: computePartListTimestamp(nextPartList),
|
|
145
|
+
partList: nextPartList
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
nextSortedChatHistoryList = nextSortedChatHistoryList.filter(entry => {
|
|
154
|
+
if (entry.type === 'activity' && entry.activityLocalId === localId) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return true;
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const nextSortedActivities = computeSortedActivities({
|
|
162
|
+
activityMap: nextActivityMap,
|
|
163
|
+
howToGroupingMap: nextHowToGroupingMap,
|
|
164
|
+
livestreamSessionMap: nextLivestreamSessionMap,
|
|
165
|
+
sortedChatHistoryList: nextSortedChatHistoryList
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return Object.freeze({
|
|
169
|
+
activityIdToLocalIdMap: Object.freeze(nextActivityIdToLocalIdMap),
|
|
170
|
+
activityMap: Object.freeze(nextActivityMap),
|
|
171
|
+
clientActivityIdToLocalIdMap: Object.freeze(nextClientActivityIdToLocalIdMap),
|
|
172
|
+
howToGroupingMap: Object.freeze(nextHowToGroupingMap),
|
|
173
|
+
livestreamSessionMap: Object.freeze(nextLivestreamSessionMap),
|
|
174
|
+
sortedActivities: Object.freeze(nextSortedActivities),
|
|
175
|
+
sortedChatHistoryList: Object.freeze(nextSortedChatHistoryList)
|
|
176
|
+
} satisfies State);
|
|
177
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HowToGroupingMapPartEntry } from '../types';
|
|
2
|
+
|
|
3
|
+
export default function computePartListTimestamp(partList: readonly HowToGroupingMapPartEntry[]): number | undefined {
|
|
4
|
+
return partList.reduce<number | undefined>(
|
|
5
|
+
(max, { logicalTimestamp }) =>
|
|
6
|
+
typeof logicalTimestamp === 'undefined' ? max : Math.max(max ?? -Infinity, logicalTimestamp),
|
|
7
|
+
undefined
|
|
8
|
+
);
|
|
9
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Activity, LivestreamSessionMap, State } from '../types';
|
|
2
|
+
|
|
3
|
+
function* yieldSessionActivities(
|
|
4
|
+
session: NonNullable<ReturnType<LivestreamSessionMap['get']>>,
|
|
5
|
+
activityMap: State['activityMap']
|
|
6
|
+
): Generator<Activity> {
|
|
7
|
+
if (session.finalized) {
|
|
8
|
+
// After finalization, only yield the final revision — intermediate revisions are pruned.
|
|
9
|
+
// eslint-disable-next-line no-magic-numbers
|
|
10
|
+
const lastEntry = session.activities.at(-1);
|
|
11
|
+
|
|
12
|
+
lastEntry && (yield activityMap.get(lastEntry.activityLocalId)!.activity);
|
|
13
|
+
} else {
|
|
14
|
+
for (const activityEntry of session.activities) {
|
|
15
|
+
yield activityMap.get(activityEntry.activityLocalId)!.activity;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default function computeSortedActivities(
|
|
21
|
+
temporalState: Pick<State, 'activityMap' | 'howToGroupingMap' | 'livestreamSessionMap' | 'sortedChatHistoryList'>
|
|
22
|
+
): Activity[] {
|
|
23
|
+
const { activityMap, howToGroupingMap, livestreamSessionMap, sortedChatHistoryList } = temporalState;
|
|
24
|
+
|
|
25
|
+
return Array.from<Activity>(
|
|
26
|
+
(function* () {
|
|
27
|
+
for (const sortedEntry of sortedChatHistoryList) {
|
|
28
|
+
if (sortedEntry.type === 'activity') {
|
|
29
|
+
// TODO: [P*] Instead of deferencing using internal ID, use pointer instead.
|
|
30
|
+
yield activityMap.get(sortedEntry.activityLocalId)!.activity;
|
|
31
|
+
} else if (sortedEntry.type === 'how to grouping') {
|
|
32
|
+
const howToGrouping = howToGroupingMap.get(sortedEntry.howToGroupingId)!;
|
|
33
|
+
|
|
34
|
+
for (const howToPartEntry of howToGrouping.partList) {
|
|
35
|
+
if (howToPartEntry.type === 'activity') {
|
|
36
|
+
yield activityMap.get(howToPartEntry.activityLocalId)!.activity;
|
|
37
|
+
} else {
|
|
38
|
+
howToPartEntry.type satisfies 'livestream session';
|
|
39
|
+
|
|
40
|
+
yield* yieldSessionActivities(livestreamSessionMap.get(howToPartEntry.livestreamSessionId)!, activityMap);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
sortedEntry.type satisfies 'livestream session';
|
|
45
|
+
|
|
46
|
+
yield* yieldSessionActivities(livestreamSessionMap.get(sortedEntry.livestreamSessionId)!, activityMap);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
})()
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-globals */
|
|
2
|
+
|
|
3
|
+
import { scenario } from '@testduet/given-when-then';
|
|
4
|
+
import type { WebChatActivity } from '../../../../types/WebChatActivity';
|
|
5
|
+
import type { LocalId } from '../property/LocalId';
|
|
6
|
+
import getLogicalTimestamp from './getLogicalTimestamp';
|
|
7
|
+
|
|
8
|
+
scenario('get logical timestamp', bdd => {
|
|
9
|
+
bdd
|
|
10
|
+
.given(
|
|
11
|
+
'an activity with timestamp property of new Date(123)',
|
|
12
|
+
() =>
|
|
13
|
+
({
|
|
14
|
+
channelData: {
|
|
15
|
+
'webchat:internal:local-id': '_:a-00001' as LocalId,
|
|
16
|
+
'webchat:internal:position': 1,
|
|
17
|
+
'webchat:send-status': undefined
|
|
18
|
+
},
|
|
19
|
+
from: { id: 'bot', role: 'bot' },
|
|
20
|
+
id: 'a-00001',
|
|
21
|
+
text: 'Hello, World!',
|
|
22
|
+
timestamp: new Date(123).toISOString(),
|
|
23
|
+
type: 'message'
|
|
24
|
+
}) satisfies WebChatActivity
|
|
25
|
+
)
|
|
26
|
+
.when('getting its logical timestamp', activity => getLogicalTimestamp(activity, { Date }))
|
|
27
|
+
.then('should get 123', (_, actual) => expect(actual).toBe(123));
|
|
28
|
+
|
|
29
|
+
bdd
|
|
30
|
+
.given(
|
|
31
|
+
'an activity with sequence ID of 123',
|
|
32
|
+
() =>
|
|
33
|
+
({
|
|
34
|
+
channelData: {
|
|
35
|
+
'webchat:internal:local-id': '_:a-00001' as LocalId,
|
|
36
|
+
'webchat:internal:position': 1,
|
|
37
|
+
'webchat:sequence-id': 123,
|
|
38
|
+
'webchat:send-status': 'sent'
|
|
39
|
+
},
|
|
40
|
+
from: { id: 'bot', role: 'bot' },
|
|
41
|
+
id: 'a-00001',
|
|
42
|
+
text: 'Hello, World!',
|
|
43
|
+
timestamp: undefined as any,
|
|
44
|
+
type: 'message'
|
|
45
|
+
}) satisfies WebChatActivity
|
|
46
|
+
)
|
|
47
|
+
.when('getting its logical timestamp', activity => getLogicalTimestamp(activity, { Date }))
|
|
48
|
+
.then('should get 123', (_, actual) => expect(actual).toBe(123));
|
|
49
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { GlobalScopePonyfill } from '../../../../types/GlobalScopePonyfill';
|
|
2
|
+
import type { Activity } from '../types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Get sequence ID from `activity.channelData['webchat:sequence-id']` and fallback to `+new Date(activity.timestamp)`.
|
|
6
|
+
*
|
|
7
|
+
* Chat adapter may send sequence ID to affect activity reordering. Sequence ID is supposed to be Unix timestamp.
|
|
8
|
+
*
|
|
9
|
+
* @param activity Activity to get sequence ID from.
|
|
10
|
+
* @returns Sequence ID.
|
|
11
|
+
*/
|
|
12
|
+
export default function getLogicalTimestamp(
|
|
13
|
+
activity: Activity,
|
|
14
|
+
ponyfill: Pick<GlobalScopePonyfill, 'Date'>
|
|
15
|
+
): number | undefined {
|
|
16
|
+
const sequenceId = activity.channelData?.['webchat:sequence-id'];
|
|
17
|
+
|
|
18
|
+
if (typeof sequenceId === 'number') {
|
|
19
|
+
return sequenceId;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { timestamp } = activity;
|
|
23
|
+
|
|
24
|
+
if (typeof timestamp === 'string') {
|
|
25
|
+
return +new ponyfill.Date(timestamp);
|
|
26
|
+
} else if (typeof timestamp !== 'undefined' && (timestamp as any) instanceof ponyfill.Date) {
|
|
27
|
+
console.warn('botframework-webchat: "timestamp" must be of type string, instead of Date.');
|
|
28
|
+
|
|
29
|
+
return +timestamp;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-globals */
|
|
2
|
+
|
|
3
|
+
import { expect } from '@jest/globals';
|
|
4
|
+
import { scenario } from '@testduet/given-when-then';
|
|
5
|
+
import type { WebChatActivity } from '../../../../types/WebChatActivity';
|
|
6
|
+
import type { LocalId } from '../property/LocalId';
|
|
7
|
+
import getPartGroupingMetadataMap, { type PartGroupingMetadataMapEntry } from './getPartGroupingMetadataMap';
|
|
8
|
+
|
|
9
|
+
scenario('getPartGroupingMetadataMap', bdd => {
|
|
10
|
+
bdd
|
|
11
|
+
.given(
|
|
12
|
+
'an activity with isPartOf[@type="HowTo"]',
|
|
13
|
+
() =>
|
|
14
|
+
({
|
|
15
|
+
channelData: {
|
|
16
|
+
'webchat:internal:local-id': '_:a-00001' as LocalId,
|
|
17
|
+
'webchat:internal:position': 0
|
|
18
|
+
},
|
|
19
|
+
entities: [
|
|
20
|
+
{
|
|
21
|
+
'@context': 'https://schema.org',
|
|
22
|
+
'@id': '',
|
|
23
|
+
'@type': 'Message',
|
|
24
|
+
type: 'https://schema.org/Message',
|
|
25
|
+
isPartOf: { '@id': '_:c-00001', '@type': 'HowTo' },
|
|
26
|
+
position: 1
|
|
27
|
+
} as any // TODO: [P0] We need to redo the typing of `WebChatActivity`.
|
|
28
|
+
],
|
|
29
|
+
from: {
|
|
30
|
+
id: 'bot',
|
|
31
|
+
role: 'bot'
|
|
32
|
+
},
|
|
33
|
+
id: 'a-00001',
|
|
34
|
+
text: 'Hello, World!',
|
|
35
|
+
timestamp: new Date(0).toISOString(),
|
|
36
|
+
type: 'message'
|
|
37
|
+
}) satisfies WebChatActivity
|
|
38
|
+
)
|
|
39
|
+
.when('getPartGroupingMetadataMap() is called', activity => getPartGroupingMetadataMap(activity))
|
|
40
|
+
.then('should return part grouping metadata', (_, actual) => {
|
|
41
|
+
expect(actual).toEqual(
|
|
42
|
+
new Map<string, PartGroupingMetadataMapEntry>([
|
|
43
|
+
['HowTo', { groupingId: '_:c-00001', position: 1 }]
|
|
44
|
+
]) satisfies ReturnType<typeof getPartGroupingMetadataMap>
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// TODO: [P0] Enable multiple part grouping once the schema behind `parseThing()` supports multiple part grouping.
|
|
50
|
+
scenario('getPartGroupingMetadataMap with multiple part grouping', bdd => {
|
|
51
|
+
bdd
|
|
52
|
+
.given(
|
|
53
|
+
'an activity with isPartOf[@type="Conversation"][@type="HowTo"]',
|
|
54
|
+
() =>
|
|
55
|
+
({
|
|
56
|
+
channelData: {
|
|
57
|
+
'webchat:internal:local-id': '_:a-00001' as LocalId,
|
|
58
|
+
'webchat:internal:position': 0
|
|
59
|
+
},
|
|
60
|
+
entities: [
|
|
61
|
+
{
|
|
62
|
+
'@context': 'https://schema.org',
|
|
63
|
+
'@id': '',
|
|
64
|
+
'@type': 'Message',
|
|
65
|
+
type: 'https://schema.org/Message',
|
|
66
|
+
isPartOf: [
|
|
67
|
+
{ '@id': '_:conv:00001', '@type': 'Conversation' },
|
|
68
|
+
{ '@id': '_:how-to:00001', '@type': 'HowTo' }
|
|
69
|
+
],
|
|
70
|
+
position: 1
|
|
71
|
+
} as any // TODO: [P0] We need to redo the typing of `WebChatActivity`.
|
|
72
|
+
],
|
|
73
|
+
from: {
|
|
74
|
+
id: 'bot',
|
|
75
|
+
role: 'bot'
|
|
76
|
+
},
|
|
77
|
+
id: 'a-00001',
|
|
78
|
+
text: 'Hello, World!',
|
|
79
|
+
timestamp: new Date(0).toISOString(),
|
|
80
|
+
type: 'message'
|
|
81
|
+
}) satisfies WebChatActivity
|
|
82
|
+
)
|
|
83
|
+
.when('getPartGroupingMetadataMap() is called', activity => getPartGroupingMetadataMap(activity))
|
|
84
|
+
.then('should return part grouping metadata', (_, actual) => {
|
|
85
|
+
expect(actual).toEqual(
|
|
86
|
+
new Map<string, PartGroupingMetadataMapEntry>([
|
|
87
|
+
['Conversation', { groupingId: '_:conv:00001', position: 1 }],
|
|
88
|
+
['HowTo', { groupingId: '_:how-to:00001', position: 1 }]
|
|
89
|
+
]) satisfies ReturnType<typeof getPartGroupingMetadataMap>
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { WebChatActivity } from '../../../../types/WebChatActivity';
|
|
2
|
+
import getOrgSchemaMessage from '../../../../utils/getOrgSchemaMessage';
|
|
3
|
+
|
|
4
|
+
type PartGroupingMetadataMapEntry = {
|
|
5
|
+
readonly groupingId: string;
|
|
6
|
+
readonly position: number | undefined;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
function getPartGroupingMetadataMap(activity: WebChatActivity): ReadonlyMap<string, PartGroupingMetadataMapEntry> {
|
|
10
|
+
const metadataMap = new Map<string, PartGroupingMetadataMapEntry>();
|
|
11
|
+
|
|
12
|
+
const message = getOrgSchemaMessage(activity.entities || []);
|
|
13
|
+
|
|
14
|
+
if (message) {
|
|
15
|
+
for (const item of message.isPartOf) {
|
|
16
|
+
if (item['@id']) {
|
|
17
|
+
const [firstPosition] = message.position;
|
|
18
|
+
|
|
19
|
+
for (const type of item['@type']) {
|
|
20
|
+
metadataMap.set(
|
|
21
|
+
type,
|
|
22
|
+
Object.freeze({
|
|
23
|
+
groupingId: item['@id'],
|
|
24
|
+
// We do not support non-number position.
|
|
25
|
+
position: typeof firstPosition === 'number' ? firstPosition : undefined
|
|
26
|
+
})
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return metadataMap;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default getPartGroupingMetadataMap;
|
|
37
|
+
export type { PartGroupingMetadataMapEntry };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { scenario } from '@testduet/given-when-then';
|
|
2
|
+
import insertSorted from './insertSorted';
|
|
3
|
+
|
|
4
|
+
scenario('insert to sorted array', bdd => {
|
|
5
|
+
bdd
|
|
6
|
+
.given('a sorted array of [1, 3, 5]', () => [1, 3, 5])
|
|
7
|
+
.when('inserting 2', array => insertSorted(array, 2, (x, y) => x - y))
|
|
8
|
+
.then('should return [1, 2, 3, 5]', (_, actual) => {
|
|
9
|
+
expect(actual).toEqual([1, 2, 3, 5]);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
bdd
|
|
13
|
+
.given('a sorted array of [1, 3, 5]', () => [1, 3, 5])
|
|
14
|
+
.when('inserting 6', array => insertSorted(array, 6, (x, y) => x - y))
|
|
15
|
+
.then('should return [1, 3, 5, 6]', (_, actual) => {
|
|
16
|
+
expect(actual).toEqual([1, 3, 5, 6]);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
bdd
|
|
20
|
+
.given('a sorted array of [1, 3, 5]', () => [1, 3, 5])
|
|
21
|
+
.when('inserting 0', array => insertSorted(array, 0, (x, y) => x - y))
|
|
22
|
+
.then('should return [0, 1, 3, 5]', (_, actual) => {
|
|
23
|
+
expect(actual).toEqual([0, 1, 3, 5]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
bdd
|
|
27
|
+
.given('an empty array', () => [])
|
|
28
|
+
.when('inserting 0', array => insertSorted(array, 0, (x, y) => x - y))
|
|
29
|
+
.then('should return [0]', (_, actual) => {
|
|
30
|
+
expect(actual).toEqual([0]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
bdd
|
|
34
|
+
.given("a sorted array of ['1b', '2b', '3b']", () => ['1b', '2b', '3b'])
|
|
35
|
+
.when('inserting 2c with a parseInt comparer', array =>
|
|
36
|
+
insertSorted(array, '2c', (x, y) => parseInt(x, 10) - parseInt(y, 10))
|
|
37
|
+
)
|
|
38
|
+
.then("should return ['1b', '2b', '2c', '3b']", (_, actual) => {
|
|
39
|
+
expect(actual).toEqual(['1b', '2b', '2c', '3b']);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
bdd
|
|
43
|
+
.given("a sorted array of ['1b', '2b', '3b']", () => ['1b', '2b', '3b'])
|
|
44
|
+
.when('inserting 2a with a parseInt comparer', array =>
|
|
45
|
+
insertSorted(array, '2a', (x, y) => parseInt(x, 10) - parseInt(y, 10))
|
|
46
|
+
)
|
|
47
|
+
.then("should return ['1b', '2b', '2a', '3b']", (_, actual) => {
|
|
48
|
+
// For items with same weight, the new item should be appended.
|
|
49
|
+
expect(actual).toEqual(['1b', '2b', '2a', '3b']);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
scenario('insert to sorted array ignoring undefined elements with a custom compareFn', bdd => {
|
|
54
|
+
function compareFn(x: number | undefined, y: number | undefined): number {
|
|
55
|
+
return typeof x === 'undefined' || typeof y === 'undefined' ? -1 : x - y;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
bdd
|
|
59
|
+
.given('a sorted array of [1, undefined, 3, undefined, 5]', () => [1, undefined, 3, undefined, 5])
|
|
60
|
+
.when('inserting 2', array => insertSorted(array, 2, compareFn))
|
|
61
|
+
.then('should return [1, undefined, 2, 3, undefined, 5]', (_, actual) => {
|
|
62
|
+
expect(actual).toEqual([1, undefined, 2, 3, undefined, 5]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
bdd
|
|
66
|
+
.given('a sorted array of [1, undefined, 3, undefined, 5]', () => [1, undefined, 3, undefined, 5])
|
|
67
|
+
.when('inserting 4', array => insertSorted(array, 4, compareFn))
|
|
68
|
+
.then('should return [1, undefined, 3, undefined, 4, 5]', (_, actual) => {
|
|
69
|
+
expect(actual).toEqual([1, undefined, 3, undefined, 4, 5]);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
bdd
|
|
73
|
+
.given('a sorted array of [undefined, 3, undefined]', () => [undefined, 3, undefined])
|
|
74
|
+
.when('inserting 2', array => insertSorted(array, 2, compareFn))
|
|
75
|
+
.then('should return [undefined, 2, 3, undefined]', (_, actual) => {
|
|
76
|
+
expect(actual).toEqual([undefined, 2, 3, undefined]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
bdd
|
|
80
|
+
.given('a sorted array of [undefined, 3, undefined]', () => [undefined, 3, undefined])
|
|
81
|
+
.when('inserting 4', array => insertSorted(array, 4, compareFn))
|
|
82
|
+
.then('should return [undefined, 3, undefined, 4]', (_, actual) => {
|
|
83
|
+
expect(actual).toEqual([undefined, 3, undefined, 4]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
bdd
|
|
87
|
+
.given('a sorted array of [1, 3, 5]', () => [1, 3, 5])
|
|
88
|
+
.when('inserting undefined', array => insertSorted(array, undefined, compareFn))
|
|
89
|
+
.then('should return [1, 3, 5, undefined]', (_, actual) => {
|
|
90
|
+
expect(actual).toEqual([1, 3, 5, undefined]);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
bdd
|
|
94
|
+
.given('a sorted array of [1, undefined, 3, undefined, 5]', () => [1, undefined, 3, undefined, 5])
|
|
95
|
+
.when('inserting undefined', array => insertSorted(array, undefined, compareFn))
|
|
96
|
+
.then('should return [1, undefined, 3, undefined, 5, undefined]', (_, actual) => {
|
|
97
|
+
expect(actual).toEqual([1, undefined, 3, undefined, 5, undefined]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
bdd
|
|
101
|
+
.given('an array of [undefined]', () => [undefined])
|
|
102
|
+
.when('inserting undefined', array => insertSorted(array, undefined, compareFn))
|
|
103
|
+
.then('should return [undefined, undefined]', (_, actual) => {
|
|
104
|
+
expect(actual).toEqual([undefined, undefined]);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { toSpliced } from '@msinternal/botframework-webchat-base/utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Inserts a single item into a sorted array.
|
|
5
|
+
*
|
|
6
|
+
* For multiple items, consider other options for efficiency.
|
|
7
|
+
*
|
|
8
|
+
* @param sortedArray A sorted array.
|
|
9
|
+
* @param item Item to be inserted.
|
|
10
|
+
* @param compareFn Function used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise.
|
|
11
|
+
* @returns A new sorted array with the new item.
|
|
12
|
+
*/
|
|
13
|
+
export default function insertSorted<T>(sortedArray: readonly T[], item: T, compareFn: (x: T, y: T) => number): T[] {
|
|
14
|
+
// TODO: Implements `binaryFindIndex()` for better performance.
|
|
15
|
+
const indexToInsert = sortedArray.findIndex(i => compareFn(i, item) > 0);
|
|
16
|
+
|
|
17
|
+
return toSpliced(sortedArray, ~indexToInsert ? indexToInsert : sortedArray.length, 0, item);
|
|
18
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { IdentifierSchema, type Identifier } from '@msinternal/botframework-webchat-core-graph';
|
|
2
|
+
import type { Tagged } from 'type-fest';
|
|
3
|
+
import { v4 } from 'uuid';
|
|
4
|
+
import { object, parse, pipe, safeParse, transform, type InferOutput } from 'valibot';
|
|
5
|
+
import type { Activity } from '../types';
|
|
6
|
+
|
|
7
|
+
const LocalIdSchema = pipe(
|
|
8
|
+
IdentifierSchema,
|
|
9
|
+
transform(value => value as Tagged<Identifier, 'local id'>)
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
type LocalId = InferOutput<typeof LocalIdSchema>;
|
|
13
|
+
|
|
14
|
+
const ActivityWithLocalIdSchema = object({
|
|
15
|
+
channelData: object({
|
|
16
|
+
'webchat:internal:local-id': LocalIdSchema
|
|
17
|
+
})
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function getLocalIdFromActivity(activity: Readonly<Activity>): LocalId {
|
|
21
|
+
return parse(ActivityWithLocalIdSchema, activity).channelData['webchat:internal:local-id'];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function queryLocalIdFromActivity(activity: Readonly<Activity>): LocalId | undefined {
|
|
25
|
+
const result = safeParse(ActivityWithLocalIdSchema, activity);
|
|
26
|
+
|
|
27
|
+
return result.success ? result.output.channelData['webchat:internal:local-id'] : undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function setLocalIdInActivity(activity: Readonly<Activity>, value: LocalId | undefined): Activity {
|
|
31
|
+
const nextChannelData = { ...activity.channelData };
|
|
32
|
+
|
|
33
|
+
if (typeof value === 'undefined') {
|
|
34
|
+
delete (nextChannelData as any)['webchat:internal:local-id'];
|
|
35
|
+
} else {
|
|
36
|
+
nextChannelData['webchat:internal:local-id'] = parse(LocalIdSchema, value);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
...activity,
|
|
41
|
+
channelData: nextChannelData as any
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// TODO: [P1] We can use a UUID v6 (reorder). Then, we can drop `receivedAt`.
|
|
46
|
+
function generateLocalId(): LocalId {
|
|
47
|
+
return parse(LocalIdSchema, `_:${v4()}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function generateLocalIdInActivity(activity: Readonly<Activity>): Activity {
|
|
51
|
+
if (queryLocalIdFromActivity(activity)) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
'botframework-webchat: Cannot generate a new local ID for activity because the activity already has a local ID'
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return setLocalIdInActivity(activity, generateLocalId());
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { generateLocalIdInActivity, getLocalIdFromActivity, LocalIdSchema, setLocalIdInActivity, type LocalId };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { number, object, parse, safeParse, type InferOutput } from 'valibot';
|
|
2
|
+
import type { Activity } from '../types';
|
|
3
|
+
|
|
4
|
+
const PositionSchema = number('position must be a number');
|
|
5
|
+
|
|
6
|
+
type Position = InferOutput<typeof PositionSchema>;
|
|
7
|
+
|
|
8
|
+
const ActivityWithPositionSchema = object({
|
|
9
|
+
channelData: object({
|
|
10
|
+
'webchat:internal:position': PositionSchema
|
|
11
|
+
})
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
function getPositionFromActivity(activity: Readonly<Activity>): Position {
|
|
15
|
+
return parse(ActivityWithPositionSchema, activity).channelData['webchat:internal:position'];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function queryPositionFromActivity(activity: Readonly<Activity>): Position | undefined {
|
|
19
|
+
const result = safeParse(ActivityWithPositionSchema, activity);
|
|
20
|
+
|
|
21
|
+
return result.success ? result.output.channelData['webchat:internal:position'] : undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function setPositionInActivity(activity: Readonly<Activity>, value: Position | undefined): Activity {
|
|
25
|
+
const nextChannelData = { ...activity.channelData };
|
|
26
|
+
|
|
27
|
+
if (typeof value === 'undefined') {
|
|
28
|
+
delete (nextChannelData as any)['webchat:internal:position'];
|
|
29
|
+
} else {
|
|
30
|
+
nextChannelData['webchat:internal:position'] = parse(PositionSchema, value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
...activity,
|
|
35
|
+
channelData: nextChannelData as any
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { getPositionFromActivity, PositionSchema, queryPositionFromActivity, setPositionInActivity, type Position };
|