@memori.ai/memori-react 8.45.1 → 8.45.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/dist/components/Chat/Chat.js +4 -1
- package/dist/components/Chat/Chat.js.map +1 -1
- package/dist/components/ChatHistoryDrawer/ChatResumeDrawer.d.ts +4 -1
- package/dist/components/ChatHistoryDrawer/ChatResumeDrawer.js +7 -57
- package/dist/components/ChatHistoryDrawer/ChatResumeDrawer.js.map +1 -1
- package/dist/components/IconButton/IconButton.d.ts +1 -1
- package/dist/components/MemoriWidget/MemoriWidget.d.ts +1 -1
- package/dist/components/MemoriWidget/MemoriWidget.js +2 -1
- package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/dist/components/PositionPopover/PositionPopover.js +38 -25
- package/dist/components/PositionPopover/PositionPopover.js.map +1 -1
- package/dist/components/UploadButton/UploadButton.js +3 -0
- package/dist/components/UploadButton/UploadButton.js.map +1 -1
- package/dist/components/UploadButton/UploadDocuments/UploadDocuments.js +14 -2
- package/dist/components/UploadButton/UploadDocuments/UploadDocuments.js.map +1 -1
- package/dist/components/layouts/chat.css +27 -4
- package/dist/context/widgetSurfaceContext.js +2 -2
- package/dist/context/widgetSurfaceContext.js.map +1 -1
- package/dist/helpers/constants.d.ts +3 -2
- package/dist/helpers/constants.js +19 -20
- package/dist/helpers/constants.js.map +1 -1
- package/dist/helpers/positionPopover.d.ts +2 -1
- package/dist/helpers/positionPopover.js +12 -3
- package/dist/helpers/positionPopover.js.map +1 -1
- package/dist/helpers/tts/muteSpeaker.js +4 -3
- package/dist/helpers/tts/muteSpeaker.js.map +1 -1
- package/dist/helpers/usePressTooltip.js +2 -1
- package/dist/helpers/usePressTooltip.js.map +1 -1
- package/dist/helpers/utils.d.ts +2 -1
- package/dist/helpers/utils.js +7 -1
- package/dist/helpers/utils.js.map +1 -1
- package/dist/icons/MemoriIcon.js +1 -1
- package/dist/icons/MemoriIcon.js.map +1 -1
- package/dist/styles.css +1 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/esm/components/Chat/Chat.js +4 -1
- package/esm/components/Chat/Chat.js.map +1 -1
- package/esm/components/MemoriWidget/MemoriWidget.d.ts +1 -1
- package/esm/components/MemoriWidget/MemoriWidget.js +2 -1
- package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/esm/components/UploadButton/UploadButton.js +4 -1
- package/esm/components/UploadButton/UploadButton.js.map +1 -1
- package/esm/components/UploadButton/UploadDocuments/UploadDocuments.js +16 -4
- package/esm/components/UploadButton/UploadDocuments/UploadDocuments.js.map +1 -1
- package/esm/components/layouts/chat.css +27 -4
- package/esm/helpers/constants.d.ts +3 -2
- package/esm/helpers/constants.js +18 -19
- package/esm/helpers/constants.js.map +1 -1
- package/esm/helpers/utils.d.ts +2 -1
- package/esm/helpers/utils.js +6 -1
- package/esm/helpers/utils.js.map +1 -1
- package/esm/styles.css +1 -2
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/package.json +6 -7
- package/dist/components/MemoriArtifactSystem/components/ArtifactActions/test/CopyButtonTest.d.ts +0 -3
- package/dist/components/MemoriArtifactSystem/components/ArtifactActions/test/CopyButtonTest.js +0 -64
- package/dist/components/MemoriArtifactSystem/components/ArtifactActions/test/CopyButtonTest.js.map +0 -1
- package/dist/testUtils.d.ts +0 -5
- package/dist/testUtils.js +0 -18
- package/dist/testUtils.js.map +0 -1
- package/esm/components/MemoriArtifactSystem/components/ArtifactActions/test/CopyButtonTest.d.ts +0 -3
- package/esm/components/MemoriArtifactSystem/components/ArtifactActions/test/CopyButtonTest.js +0 -62
- package/esm/components/MemoriArtifactSystem/components/ArtifactActions/test/CopyButtonTest.js.map +0 -1
- package/src/I18nWrapper.tsx +0 -13
- package/src/__snapshots__/index.test.tsx.snap +0 -96
- package/src/components/AgeVerificationModal/AgeVerificationModal.css +0 -95
- package/src/components/AgeVerificationModal/AgeVerificationModal.stories.tsx +0 -46
- package/src/components/AgeVerificationModal/AgeVerificationModal.test.tsx +0 -33
- package/src/components/AgeVerificationModal/AgeVerificationModal.tsx +0 -99
- package/src/components/AgeVerificationModal/__snapshots__/AgeVerificationModal.test.tsx.snap +0 -19
- package/src/components/Auth/Auth.css +0 -57
- package/src/components/Auth/Auth.stories.tsx +0 -90
- package/src/components/Auth/Auth.test.tsx +0 -63
- package/src/components/Auth/Auth.tsx +0 -201
- package/src/components/Auth/__snapshots__/Auth.test.tsx.snap +0 -143
- package/src/components/Avatar/Avatar.css +0 -151
- package/src/components/Avatar/Avatar.stories.tsx +0 -160
- package/src/components/Avatar/Avatar.test.tsx +0 -158
- package/src/components/Avatar/Avatar.tsx +0 -245
- package/src/components/Avatar/AvatarView/AvatarComponent/Shadow/DynamicShadow.tsx +0 -103
- package/src/components/Avatar/AvatarView/AvatarComponent/avatarComponent.tsx +0 -105
- package/src/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.tsx +0 -338
- package/src/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/types.ts +0 -44
- package/src/components/Avatar/AvatarView/AvatarComponent/components/controllers/AvatarAnimator.ts +0 -1091
- package/src/components/Avatar/AvatarView/AvatarComponent/components/controllers/AvatarPositionController.ts +0 -83
- package/src/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.ts +0 -301
- package/src/components/Avatar/AvatarView/AvatarComponent/components/controls.tsx +0 -100
- package/src/components/Avatar/AvatarView/AvatarComponent/components/halfbodyAvatar.tsx +0 -152
- package/src/components/Avatar/AvatarView/AvatarComponent/components/loader.tsx +0 -31
- package/src/components/Avatar/AvatarView/AvatarComponent/constants.ts +0 -141
- package/src/components/Avatar/AvatarView/AvatarComponent/lights/Lights.tsx +0 -145
- package/src/components/Avatar/AvatarView/AvatarComponent/positionControls/positionControls.css +0 -111
- package/src/components/Avatar/AvatarView/AvatarComponent/positionControls/positionControls.tsx +0 -201
- package/src/components/Avatar/AvatarView/AvatarView.stories.tsx +0 -254
- package/src/components/Avatar/AvatarView/index.tsx +0 -194
- package/src/components/Avatar/AvatarView/utils/hideHands.ts +0 -11
- package/src/components/Avatar/AvatarView/utils/useEyeBlink.ts +0 -100
- package/src/components/Avatar/AvatarView/utils/useHeadMovement.ts +0 -72
- package/src/components/Avatar/AvatarView/utils/useLoadingMorphAnim.ts +0 -38
- package/src/components/Avatar/AvatarView/utils/useMouthAnimation.ts +0 -93
- package/src/components/Avatar/AvatarView/utils/useSmile.ts +0 -39
- package/src/components/Avatar/AvatarView/utils/utils.ts +0 -55
- package/src/components/Avatar/__snapshots__/Avatar.test.tsx.snap +0 -246
- package/src/components/Blob/Blob.css +0 -286
- package/src/components/Blob/Blob.stories.tsx +0 -53
- package/src/components/Blob/Blob.test.tsx +0 -18
- package/src/components/Blob/Blob.tsx +0 -26
- package/src/components/Blob/__snapshots__/Blob.test.tsx.snap +0 -80
- package/src/components/BlockedMemoriBadge/BlockedMemoriBadge.css +0 -40
- package/src/components/BlockedMemoriBadge/BlockedMemoriBadge.stories.tsx +0 -58
- package/src/components/BlockedMemoriBadge/BlockedMemoriBadge.test.tsx +0 -53
- package/src/components/BlockedMemoriBadge/BlockedMemoriBadge.tsx +0 -74
- package/src/components/BlockedMemoriBadge/__snapshots__/BlockedMemoriBadge.test.tsx.snap +0 -181
- package/src/components/ChangeMode/ChangeMode.css +0 -22
- package/src/components/ChangeMode/ChangeMode.stories.tsx +0 -50
- package/src/components/ChangeMode/ChangeMode.test.tsx +0 -24
- package/src/components/ChangeMode/ChangeMode.tsx +0 -51
- package/src/components/ChangeMode/__snapshots__/ChangeMode.test.tsx.snap +0 -107
- package/src/components/Chat/Chat.css +0 -285
- package/src/components/Chat/Chat.stories.tsx +0 -1684
- package/src/components/Chat/Chat.test.tsx +0 -372
- package/src/components/Chat/Chat.tsx +0 -778
- package/src/components/Chat/__snapshots__/Chat.test.tsx.snap +0 -6816
- package/src/components/ChatBubble/ChatBubble.css +0 -430
- package/src/components/ChatBubble/ChatBubble.stories.tsx +0 -1192
- package/src/components/ChatBubble/ChatBubble.test.tsx +0 -481
- package/src/components/ChatBubble/ChatBubble.tsx +0 -776
- package/src/components/ChatBubble/__snapshots__/ChatBubble.test.tsx.snap +0 -8734
- package/src/components/ChatHistoryDrawer/ChatHistory.css +0 -587
- package/src/components/ChatHistoryDrawer/ChatHistory.stories.tsx +0 -410
- package/src/components/ChatHistoryDrawer/ChatHistory.test.tsx +0 -107
- package/src/components/ChatHistoryDrawer/ChatHistory.tsx +0 -1298
- package/src/components/ChatHistoryDrawer/__snapshots__/ChatHistory.test.tsx.snap +0 -27
- package/src/components/ChatInputs/ChatInputs.css +0 -340
- package/src/components/ChatInputs/ChatInputs.stories.tsx +0 -251
- package/src/components/ChatInputs/ChatInputs.tsx +0 -487
- package/src/components/ChatTextArea/ChatTextArea.css +0 -185
- package/src/components/ChatTextArea/ChatTextArea.stories.tsx +0 -55
- package/src/components/ChatTextArea/ChatTextArea.test.tsx +0 -28
- package/src/components/ChatTextArea/ChatTextArea.tsx +0 -171
- package/src/components/ChatTextArea/__snapshots__/ChatTextArea.test.tsx.snap +0 -68
- package/src/components/CompletionProviderStatus/CompletionProviderStatus.css +0 -36
- package/src/components/CompletionProviderStatus/CompletionProviderStatus.stories.tsx +0 -296
- package/src/components/CompletionProviderStatus/CompletionProviderStatus.test.tsx +0 -31
- package/src/components/CompletionProviderStatus/CompletionProviderStatus.tsx +0 -232
- package/src/components/CompletionProviderStatus/__snapshots__/CompletionProviderStatus.test.tsx.snap +0 -96
- package/src/components/ContentPreviewModal/ContentPreviewModal.css +0 -128
- package/src/components/ContentPreviewModal/ContentPreviewModal.tsx +0 -67
- package/src/components/ContentPreviewModal/index.ts +0 -2
- package/src/components/CustomGLBModelViewer/ModelViewer.css +0 -11
- package/src/components/CustomGLBModelViewer/ModelViewer.stories.tsx +0 -58
- package/src/components/CustomGLBModelViewer/ModelViewer.test.tsx +0 -13
- package/src/components/CustomGLBModelViewer/ModelViewer.tsx +0 -37
- package/src/components/CustomGLBModelViewer/__snapshots__/ModelViewer.test.tsx.snap +0 -20
- package/src/components/DateSelector/DateSelector.css +0 -158
- package/src/components/DateSelector/DateSelector.stories.tsx +0 -47
- package/src/components/DateSelector/DateSelector.test.tsx +0 -149
- package/src/components/DateSelector/DateSelector.tsx +0 -251
- package/src/components/DateSelector/__snapshots__/DateSelector.test.tsx.snap +0 -1954
- package/src/components/ErrorBoundary/ErrorBoundary.tsx +0 -54
- package/src/components/ExpertsDrawer/ExpertsDrawer.css +0 -67
- package/src/components/ExpertsDrawer/ExpertsDrawer.stories.tsx +0 -54
- package/src/components/ExpertsDrawer/ExpertsDrawer.test.tsx +0 -53
- package/src/components/ExpertsDrawer/ExpertsDrawer.tsx +0 -69
- package/src/components/ExpertsDrawer/__snapshots__/ExpertsDrawer.test.tsx.snap +0 -11
- package/src/components/ExportHistoryButton/ExportHistoryButton.css +0 -22
- package/src/components/FeedbackButtons/FeedbackButtons.css +0 -107
- package/src/components/FeedbackButtons/FeedbackButtons.stories.tsx +0 -52
- package/src/components/FeedbackButtons/FeedbackButtons.test.tsx +0 -11
- package/src/components/FeedbackButtons/FeedbackButtons.tsx +0 -152
- package/src/components/FeedbackButtons/__snapshots__/FeedbackButtons.test.tsx.snap +0 -42
- package/src/components/FilePreview/FilePreview.css +0 -358
- package/src/components/FilePreview/FilePreview.stories.tsx +0 -63
- package/src/components/FilePreview/FilePreview.test.tsx +0 -26
- package/src/components/FilePreview/FilePreview.tsx +0 -277
- package/src/components/FilePreview/__snapshots__/FilePreview.test.tsx.snap +0 -185
- package/src/components/Header/ChatConsumptionDropdown.test.tsx +0 -117
- package/src/components/Header/ChatConsumptionDropdown.tsx +0 -275
- package/src/components/Header/Header.css +0 -282
- package/src/components/Header/Header.stories.tsx +0 -338
- package/src/components/Header/Header.test.tsx +0 -371
- package/src/components/Header/Header.tsx +0 -442
- package/src/components/Header/__snapshots__/Header.test.tsx.snap +0 -964
- package/src/components/KnownFacts/KnownFacts.css +0 -19
- package/src/components/KnownFacts/KnownFacts.stories.tsx +0 -80
- package/src/components/KnownFacts/KnownFacts.test.tsx +0 -57
- package/src/components/KnownFacts/KnownFacts.tsx +0 -376
- package/src/components/KnownFacts/__snapshots__/KnownFacts.test.tsx.snap +0 -19
- package/src/components/LoginDrawer/LoginDrawer.css +0 -1616
- package/src/components/LoginDrawer/LoginDrawer.stories.tsx +0 -102
- package/src/components/LoginDrawer/LoginDrawer.test.tsx +0 -199
- package/src/components/LoginDrawer/LoginDrawer.tsx +0 -600
- package/src/components/LoginDrawer/__snapshots__/LoginDrawer.test.tsx.snap +0 -91
- package/src/components/MediaWidget/DocumentCard.test.tsx +0 -45
- package/src/components/MediaWidget/DocumentCard.tsx +0 -19
- package/src/components/MediaWidget/MediaItemWidget.css +0 -1398
- package/src/components/MediaWidget/MediaItemWidget.stories.tsx +0 -423
- package/src/components/MediaWidget/MediaItemWidget.test.tsx +0 -248
- package/src/components/MediaWidget/MediaItemWidget.tsx +0 -997
- package/src/components/MediaWidget/MediaItemWidget.types.ts +0 -65
- package/src/components/MediaWidget/MediaItemWidget.utils.test.ts +0 -367
- package/src/components/MediaWidget/MediaItemWidget.utils.ts +0 -227
- package/src/components/MediaWidget/MediaPreviewModal.test.tsx +0 -271
- package/src/components/MediaWidget/MediaPreviewModal.tsx +0 -425
- package/src/components/MediaWidget/MediaWidget.css +0 -131
- package/src/components/MediaWidget/MediaWidget.stories.tsx +0 -319
- package/src/components/MediaWidget/MediaWidget.test.tsx +0 -41
- package/src/components/MediaWidget/MediaWidget.tsx +0 -107
- package/src/components/MediaWidget/__snapshots__/DocumentCard.test.tsx.snap +0 -24
- package/src/components/MediaWidget/__snapshots__/MediaItemWidget.test.tsx.snap +0 -791
- package/src/components/MediaWidget/__snapshots__/MediaWidget.test.tsx.snap +0 -154
- package/src/components/MemoriArtifactSystem/ArtifactDrawer.stories.tsx +0 -2299
- package/src/components/MemoriArtifactSystem/components/ArtifactActions/ArtifactActions.css +0 -163
- package/src/components/MemoriArtifactSystem/components/ArtifactActions/ArtifactActions.tsx +0 -250
- package/src/components/MemoriArtifactSystem/components/ArtifactActions/CopyButton.stories.tsx +0 -30
- package/src/components/MemoriArtifactSystem/components/ArtifactActions/components/CopyButtonWithDropdown.tsx +0 -467
- package/src/components/MemoriArtifactSystem/components/ArtifactActions/components/CopyMenuItem.tsx +0 -89
- package/src/components/MemoriArtifactSystem/components/ArtifactActions/hooks/useCopyArtifact.ts +0 -619
- package/src/components/MemoriArtifactSystem/components/ArtifactActions/index.ts +0 -9
- package/src/components/MemoriArtifactSystem/components/ArtifactActions/styles.css +0 -489
- package/src/components/MemoriArtifactSystem/components/ArtifactActions/test/CopyButtonTest.tsx +0 -90
- package/src/components/MemoriArtifactSystem/components/ArtifactActions/types.ts +0 -73
- package/src/components/MemoriArtifactSystem/components/ArtifactActions/utils/PDFExporter.ts +0 -454
- package/src/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.css +0 -1059
- package/src/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.tsx +0 -431
- package/src/components/MemoriArtifactSystem/components/ArtifactDrawer/components/TabSwitch.css +0 -150
- package/src/components/MemoriArtifactSystem/components/ArtifactDrawer/components/TabSwitch.tsx +0 -79
- package/src/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.css +0 -253
- package/src/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.tsx +0 -561
- package/src/components/MemoriArtifactSystem/components/ArtifactPreview/ArtifactPreview.css +0 -355
- package/src/components/MemoriArtifactSystem/components/ArtifactPreview/ArtifactPreview.tsx +0 -160
- package/src/components/MemoriArtifactSystem/context/ArtifactContext.tsx +0 -167
- package/src/components/MemoriArtifactSystem/types/artifact.types.ts +0 -35
- package/src/components/MemoriArtifactSystem/utils/ArtifactAPI.test.tsx +0 -308
- package/src/components/MemoriArtifactSystem/utils/ArtifactAPI.tsx +0 -379
- package/src/components/MemoriArtifactSystem/utils/applyEdits.test.ts +0 -85
- package/src/components/MemoriArtifactSystem/utils/applyEdits.ts +0 -173
- package/src/components/MemoriWidget/MemoriWidget.css +0 -220
- package/src/components/MemoriWidget/MemoriWidget.stories.tsx +0 -274
- package/src/components/MemoriWidget/MemoriWidget.tsx +0 -3930
- package/src/components/MicrophoneButton/MicrophoneButton.css +0 -142
- package/src/components/MicrophoneButton/MicrophoneButton.stories.tsx +0 -52
- package/src/components/MicrophoneButton/MicrophoneButton.tsx +0 -128
- package/src/components/PositionDrawer/PositionDrawer.stories.tsx +0 -51
- package/src/components/PositionDrawer/PositionDrawer.test.tsx +0 -39
- package/src/components/PositionDrawer/PositionDrawer.tsx +0 -50
- package/src/components/PositionDrawer/__snapshots__/PositionDrawer.test.tsx.snap +0 -17
- package/src/components/PoweredBy/PoweredBy.css +0 -47
- package/src/components/PoweredBy/PoweredBy.stories.tsx +0 -75
- package/src/components/PoweredBy/PoweredBy.test.tsx +0 -15
- package/src/components/PoweredBy/PoweredBy.tsx +0 -44
- package/src/components/PoweredBy/__snapshots__/PoweredBy.test.tsx.snap +0 -55
- package/src/components/SendOnEnterMenu/SendOnEnterMenu.css +0 -47
- package/src/components/SendOnEnterMenu/SendOnEnterMenu.stories.tsx +0 -58
- package/src/components/SendOnEnterMenu/SendOnEnterMenu.test.tsx +0 -17
- package/src/components/SendOnEnterMenu/SendOnEnterMenu.tsx +0 -82
- package/src/components/SendOnEnterMenu/__snapshots__/SendOnEnterMenu.test.tsx.snap +0 -57
- package/src/components/SettingsDrawer/SettingsDrawer.css +0 -24
- package/src/components/SettingsDrawer/SettingsDrawer.stories.tsx +0 -94
- package/src/components/SettingsDrawer/SettingsDrawer.test.tsx +0 -202
- package/src/components/SettingsDrawer/SettingsDrawer.tsx +0 -255
- package/src/components/SettingsDrawer/__snapshots__/SettingsDrawer.test.tsx.snap +0 -59
- package/src/components/ShareButton/ShareButton.css +0 -73
- package/src/components/ShareButton/ShareButton.stories.tsx +0 -98
- package/src/components/ShareButton/ShareButton.test.tsx +0 -53
- package/src/components/ShareButton/ShareButton.tsx +0 -395
- package/src/components/ShareButton/__snapshots__/ShareButton.test.tsx.snap +0 -316
- package/src/components/Snippet/Snippet.css +0 -142
- package/src/components/Snippet/Snippet.stories.tsx +0 -286
- package/src/components/Snippet/Snippet.test.tsx +0 -176
- package/src/components/Snippet/Snippet.tsx +0 -148
- package/src/components/Snippet/__snapshots__/Snippet.test.tsx.snap +0 -603
- package/src/components/StartPanel/StartPanel.css +0 -273
- package/src/components/StartPanel/StartPanel.stories.tsx +0 -404
- package/src/components/StartPanel/StartPanel.test.tsx +0 -360
- package/src/components/StartPanel/StartPanel.tsx +0 -426
- package/src/components/StartPanel/__snapshots__/StartPanel.test.tsx.snap +0 -1986
- package/src/components/Typing/Typing.stories.tsx +0 -130
- package/src/components/Typing/Typing.test.tsx +0 -62
- package/src/components/Typing/Typing.tsx +0 -154
- package/src/components/Typing/__snapshots__/Typing.test.tsx.snap +0 -133
- package/src/components/UploadButton/UploadButton.css +0 -542
- package/src/components/UploadButton/UploadButton.stories.tsx +0 -376
- package/src/components/UploadButton/UploadButton.test.tsx +0 -11
- package/src/components/UploadButton/UploadButton.tsx +0 -684
- package/src/components/UploadButton/UploadDocuments/UploadDocuments.tsx +0 -405
- package/src/components/UploadButton/UploadImages/UploadImages.tsx +0 -538
- package/src/components/UploadButton/__snapshots__/UploadButton.test.tsx.snap +0 -165
- package/src/components/VenueWidget/VenueWidget.css +0 -163
- package/src/components/VenueWidget/VenueWidget.stories.tsx +0 -66
- package/src/components/VenueWidget/VenueWidget.test.tsx +0 -49
- package/src/components/VenueWidget/VenueWidget.tsx +0 -458
- package/src/components/VenueWidget/__snapshots__/VenueWidget.test.tsx.snap +0 -370
- package/src/components/WhyThisAnswer/WhyThisAnswer.css +0 -171
- package/src/components/WhyThisAnswer/WhyThisAnswer.stories.tsx +0 -285
- package/src/components/WhyThisAnswer/WhyThisAnswer.test.tsx +0 -245
- package/src/components/WhyThisAnswer/WhyThisAnswer.tsx +0 -233
- package/src/components/WhyThisAnswer/__snapshots__/WhyThisAnswer.test.tsx.snap +0 -27
- package/src/components/icons/AI.tsx +0 -34
- package/src/components/icons/Alert.tsx +0 -31
- package/src/components/icons/ArrowUp.tsx +0 -28
- package/src/components/icons/Bug.tsx +0 -81
- package/src/components/icons/Chat.tsx +0 -30
- package/src/components/icons/ChevronDown.tsx +0 -26
- package/src/components/icons/ChevronLeft.tsx +0 -28
- package/src/components/icons/ChevronRight.tsx +0 -28
- package/src/components/icons/ChevronUp.tsx +0 -24
- package/src/components/icons/Clear.tsx +0 -23
- package/src/components/icons/Close.tsx +0 -30
- package/src/components/icons/Code.tsx +0 -24
- package/src/components/icons/Copy.tsx +0 -23
- package/src/components/icons/DeepThought.tsx +0 -38
- package/src/components/icons/Delete.tsx +0 -23
- package/src/components/icons/Document.tsx +0 -50
- package/src/components/icons/Download.tsx +0 -23
- package/src/components/icons/Edit.tsx +0 -17
- package/src/components/icons/Expand.tsx +0 -23
- package/src/components/icons/Eye.tsx +0 -17
- package/src/components/icons/EyeInvisible.tsx +0 -24
- package/src/components/icons/Facebook.tsx +0 -23
- package/src/components/icons/Feedback.tsx +0 -24
- package/src/components/icons/File.tsx +0 -17
- package/src/components/icons/FileExcel.tsx +0 -23
- package/src/components/icons/FilePdf.tsx +0 -23
- package/src/components/icons/FileWord.tsx +0 -23
- package/src/components/icons/Fullscreen.tsx +0 -23
- package/src/components/icons/FullscreenExit.tsx +0 -23
- package/src/components/icons/GasStation.tsx +0 -36
- package/src/components/icons/Group.tsx +0 -30
- package/src/components/icons/History.tsx +0 -33
- package/src/components/icons/Image.tsx +0 -37
- package/src/components/icons/Info.tsx +0 -31
- package/src/components/icons/Link.tsx +0 -17
- package/src/components/icons/Linkedin.tsx +0 -23
- package/src/components/icons/Loading.tsx +0 -28
- package/src/components/icons/Logout.tsx +0 -27
- package/src/components/icons/Mail.tsx +0 -17
- package/src/components/icons/MapMarker.tsx +0 -26
- package/src/components/icons/MenuHorizontal.tsx +0 -29
- package/src/components/icons/MenuVertical.tsx +0 -29
- package/src/components/icons/Message.tsx +0 -23
- package/src/components/icons/Microphone.tsx +0 -23
- package/src/components/icons/Minus.tsx +0 -23
- package/src/components/icons/MinusCircle.tsx +0 -24
- package/src/components/icons/PaperClip.tsx +0 -23
- package/src/components/icons/Picture.tsx +0 -23
- package/src/components/icons/Plus.tsx +0 -18
- package/src/components/icons/Preview.tsx +0 -29
- package/src/components/icons/Print.tsx +0 -38
- package/src/components/icons/QuestionHelp.tsx +0 -30
- package/src/components/icons/Refresh.tsx +0 -30
- package/src/components/icons/SelectIcon.tsx +0 -28
- package/src/components/icons/Send.tsx +0 -17
- package/src/components/icons/Setting.tsx +0 -23
- package/src/components/icons/Share.tsx +0 -23
- package/src/components/icons/Sound.tsx +0 -23
- package/src/components/icons/SoundDeactivated.tsx +0 -27
- package/src/components/icons/Telegram.tsx +0 -26
- package/src/components/icons/ThumbDown.tsx +0 -29
- package/src/components/icons/ThumbUp.tsx +0 -29
- package/src/components/icons/Translation.tsx +0 -24
- package/src/components/icons/Twitter.tsx +0 -23
- package/src/components/icons/Upload.tsx +0 -34
- package/src/components/icons/User.tsx +0 -17
- package/src/components/icons/Warning.tsx +0 -24
- package/src/components/icons/WhatsApp.tsx +0 -24
- package/src/components/icons/icons.stories.css +0 -5
- package/src/components/icons/icons.stories.tsx +0 -81
- package/src/components/icons/loading.css +0 -14
- package/src/components/layouts/Chat.test.tsx +0 -40
- package/src/components/layouts/Chat.tsx +0 -69
- package/src/components/layouts/FullBody/FullBody.stories.tsx +0 -110
- package/src/components/layouts/FullPage.test.tsx +0 -65
- package/src/components/layouts/FullPage.tsx +0 -80
- package/src/components/layouts/HiddenChat.test.tsx +0 -40
- package/src/components/layouts/HiddenChat.tsx +0 -233
- package/src/components/layouts/Totem/Totem.stories.tsx +0 -131
- package/src/components/layouts/Totem.test.tsx +0 -40
- package/src/components/layouts/Totem.tsx +0 -49
- package/src/components/layouts/WebsiteAssistant.test.tsx +0 -40
- package/src/components/layouts/WebsiteAssistant.tsx +0 -132
- package/src/components/layouts/ZoomedFullBody/ZoomedFullBody.stories.tsx +0 -131
- package/src/components/layouts/ZoomedFullBody.test.tsx +0 -40
- package/src/components/layouts/ZoomedFullBody.tsx +0 -81
- package/src/components/layouts/__snapshots__/Chat.test.tsx.snap +0 -457
- package/src/components/layouts/__snapshots__/FullPage.test.tsx.snap +0 -1045
- package/src/components/layouts/__snapshots__/HiddenChat.test.tsx.snap +0 -460
- package/src/components/layouts/__snapshots__/Totem.test.tsx.snap +0 -566
- package/src/components/layouts/__snapshots__/WebsiteAssistant.test.tsx.snap +0 -59
- package/src/components/layouts/__snapshots__/ZoomedFullBody.test.tsx.snap +0 -523
- package/src/components/layouts/chat.css +0 -451
- package/src/components/layouts/hidden-chat.css +0 -276
- package/src/components/layouts/layouts.stories.tsx +0 -231
- package/src/components/layouts/totem.css +0 -221
- package/src/components/layouts/website-assistant.css +0 -677
- package/src/components/layouts/zoomed-full-body.css +0 -18
- package/src/components/ui/Alert.css +0 -93
- package/src/components/ui/Alert.stories.tsx +0 -137
- package/src/components/ui/Alert.test.tsx +0 -129
- package/src/components/ui/Alert.tsx +0 -123
- package/src/components/ui/Button.css +0 -167
- package/src/components/ui/Button.stories.tsx +0 -156
- package/src/components/ui/Button.test.tsx +0 -74
- package/src/components/ui/Button.tsx +0 -107
- package/src/components/ui/Card.css +0 -65
- package/src/components/ui/Card.stories.tsx +0 -95
- package/src/components/ui/Card.test.tsx +0 -47
- package/src/components/ui/Card.tsx +0 -48
- package/src/components/ui/Checkbox.css +0 -116
- package/src/components/ui/Checkbox.stories.tsx +0 -74
- package/src/components/ui/Checkbox.test.tsx +0 -28
- package/src/components/ui/Checkbox.tsx +0 -58
- package/src/components/ui/ConfirmDialog.css +0 -42
- package/src/components/ui/ConfirmDialog.stories.tsx +0 -216
- package/src/components/ui/ConfirmDialog.test.tsx +0 -124
- package/src/components/ui/ConfirmDialog.tsx +0 -58
- package/src/components/ui/Details.css +0 -66
- package/src/components/ui/Drawer.css +0 -270
- package/src/components/ui/Drawer.stories.tsx +0 -267
- package/src/components/ui/Drawer.test.tsx +0 -130
- package/src/components/ui/Drawer.tsx +0 -293
- package/src/components/ui/Dropdown.css +0 -173
- package/src/components/ui/Dropdown.tsx +0 -63
- package/src/components/ui/Expandable.css +0 -15
- package/src/components/ui/Expandable.stories.tsx +0 -180
- package/src/components/ui/Expandable.test.tsx +0 -107
- package/src/components/ui/Expandable.tsx +0 -121
- package/src/components/ui/Modal.css +0 -98
- package/src/components/ui/Modal.stories.tsx +0 -171
- package/src/components/ui/Modal.test.tsx +0 -111
- package/src/components/ui/Modal.tsx +0 -117
- package/src/components/ui/Select.css +0 -138
- package/src/components/ui/Select.stories.tsx +0 -79
- package/src/components/ui/Select.test.tsx +0 -84
- package/src/components/ui/Select.tsx +0 -79
- package/src/components/ui/Slider.css +0 -192
- package/src/components/ui/Slider.stories.tsx +0 -63
- package/src/components/ui/Slider.tsx +0 -142
- package/src/components/ui/Spin.css +0 -31
- package/src/components/ui/Spin.stories.tsx +0 -64
- package/src/components/ui/Spin.test.tsx +0 -41
- package/src/components/ui/Spin.tsx +0 -31
- package/src/components/ui/Table.css +0 -132
- package/src/components/ui/Tooltip.css +0 -171
- package/src/components/ui/Tooltip.stories.tsx +0 -109
- package/src/components/ui/Tooltip.test.tsx +0 -102
- package/src/components/ui/Tooltip.tsx +0 -163
- package/src/components/ui/__snapshots__/Alert.test.tsx.snap +0 -59
- package/src/components/ui/__snapshots__/Button.test.tsx.snap +0 -204
- package/src/components/ui/__snapshots__/Card.test.tsx.snap +0 -321
- package/src/components/ui/__snapshots__/Checkbox.test.tsx.snap +0 -131
- package/src/components/ui/__snapshots__/ConfirmDialog.test.tsx.snap +0 -35
- package/src/components/ui/__snapshots__/Drawer.test.tsx.snap +0 -67
- package/src/components/ui/__snapshots__/Expandable.test.tsx.snap +0 -159
- package/src/components/ui/__snapshots__/Modal.test.tsx.snap +0 -59
- package/src/components/ui/__snapshots__/Select.test.tsx.snap +0 -254
- package/src/components/ui/__snapshots__/Spin.test.tsx.snap +0 -193
- package/src/components/ui/__snapshots__/Tooltip.test.tsx.snap +0 -113
- package/src/components/ui/definitions.stories.tsx +0 -139
- package/src/context/visemeContext.tsx +0 -384
- package/src/helpers/chatPdfExport.ts +0 -544
- package/src/helpers/configuration.ts +0 -42
- package/src/helpers/constants.ts +0 -267
- package/src/helpers/convertDocument.test.ts +0 -67
- package/src/helpers/convertDocument.ts +0 -35
- package/src/helpers/credits.ts +0 -54
- package/src/helpers/error.test.ts +0 -29
- package/src/helpers/error.ts +0 -278
- package/src/helpers/imageCompression.ts +0 -230
- package/src/helpers/llmUsage.ts +0 -328
- package/src/helpers/markedExtendedTables.js +0 -217
- package/src/helpers/media.test.ts +0 -169
- package/src/helpers/media.ts +0 -81
- package/src/helpers/message.test.ts +0 -126
- package/src/helpers/message.ts +0 -219
- package/src/helpers/nats/getNatsConfig.ts +0 -148
- package/src/helpers/nats/isSessionExpiredError.test.ts +0 -38
- package/src/helpers/nats/isSessionExpiredError.ts +0 -51
- package/src/helpers/nats/useNats.test.tsx +0 -81
- package/src/helpers/nats/useNats.ts +0 -204
- package/src/helpers/nats/useNatsSession.test.ts +0 -16
- package/src/helpers/nats/useNatsSession.ts +0 -460
- package/src/helpers/piiDetection.test.ts +0 -186
- package/src/helpers/piiDetection.ts +0 -91
- package/src/helpers/sanitizer.ts +0 -17
- package/src/helpers/statistics.ts +0 -58
- package/src/helpers/stt/useSTT.ts +0 -515
- package/src/helpers/translations.ts +0 -39
- package/src/helpers/tts/ttsVoiceUtility.ts +0 -275
- package/src/helpers/tts/useTTS.ts +0 -621
- package/src/helpers/utils.test.ts +0 -321
- package/src/helpers/utils.ts +0 -586
- package/src/helpers/venue.ts +0 -36
- package/src/i18n.ts +0 -39
- package/src/index.stories.tsx +0 -220
- package/src/index.test.tsx +0 -156
- package/src/index.tsx +0 -592
- package/src/locales/de.json +0 -680
- package/src/locales/en.json +0 -754
- package/src/locales/es.json +0 -682
- package/src/locales/fr.json +0 -682
- package/src/locales/it.json +0 -750
- package/src/mocks/data.ts +0 -790
- package/src/styles.css +0 -126
- package/src/types/integration.test.ts +0 -32
- package/src/types/integration.ts +0 -31
- package/src/types/layout.ts +0 -50
- package/src/version.ts +0 -2
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import type { PiiDetectionConfig, PiiDetectionRule } from '../types/layout';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* PII detection helper: runs regex rules on message text and returns whether any matched
|
|
5
|
-
* and the localized error text to show in the chat (as a system error bubble).
|
|
6
|
-
*
|
|
7
|
-
* Edge cases handled:
|
|
8
|
-
* - config disabled, null, or missing rules → no match
|
|
9
|
-
* - empty or non-array rules → no match
|
|
10
|
-
* - empty or whitespace-only regex pattern → skipped (avoid matching everything)
|
|
11
|
-
* - invalid regex (throws) → caught, treated as no match, console.warn
|
|
12
|
-
* - multiple rules with same id → deduplicated so message appears once
|
|
13
|
-
* - missing message/errorMessage for lang → fallback: lang → en → first value → default string
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Picks a localized string from a Record with fallback: lang -> 'en' -> first value -> fallback.
|
|
18
|
-
* Used for errorMessage and each rule's message so the bubble uses the chat-selected language.
|
|
19
|
-
*/
|
|
20
|
-
function getLocalized(
|
|
21
|
-
record: Record<string, string> | undefined,
|
|
22
|
-
lang: string,
|
|
23
|
-
fallback: string
|
|
24
|
-
): string {
|
|
25
|
-
if (!record || typeof record !== 'object') return fallback;
|
|
26
|
-
const normalizedLang = lang?.toLowerCase() || 'en';
|
|
27
|
-
return (
|
|
28
|
-
record[normalizedLang] ??
|
|
29
|
-
record.en ??
|
|
30
|
-
record['en'] ??
|
|
31
|
-
Object.values(record)[0] ??
|
|
32
|
-
fallback
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Runs PII detection on text: tests each rule's regex and returns matched rules and error text.
|
|
38
|
-
* - Deduplicates by rule.id so the same "kind" of PII doesn't appear twice in the message.
|
|
39
|
-
* - Invalid regexes are caught and treated as no match (with a console.warn).
|
|
40
|
-
*
|
|
41
|
-
* @param text - Full message text to check (including any attached document content).
|
|
42
|
-
* @param config - PII config from layout (enabled, rules, errorMessage).
|
|
43
|
-
* @param lang - Chat-selected language (e.g. userLang) for picking localized strings.
|
|
44
|
-
* @returns { matched: false } if no rule matches, or { matched: true, errorText } with the full error string to show.
|
|
45
|
-
*/
|
|
46
|
-
export function checkPii(
|
|
47
|
-
text: string,
|
|
48
|
-
config: PiiDetectionConfig,
|
|
49
|
-
lang: string
|
|
50
|
-
): { matched: boolean; errorText?: string } {
|
|
51
|
-
if (!config?.enabled || !Array.isArray(config.rules) || config.rules.length === 0) {
|
|
52
|
-
return { matched: false };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const normalizedLang = lang?.toLowerCase() || 'en';
|
|
56
|
-
const matchedRulesById = new Map<string, PiiDetectionRule>();
|
|
57
|
-
|
|
58
|
-
for (const rule of config.rules) {
|
|
59
|
-
if (!rule.pattern || !rule.pattern.trim()) {
|
|
60
|
-
continue; // empty pattern would match everything; skip
|
|
61
|
-
}
|
|
62
|
-
try {
|
|
63
|
-
const regex = new RegExp(rule.pattern);
|
|
64
|
-
if (regex.test(text)) {
|
|
65
|
-
if (!matchedRulesById.has(rule.id)) {
|
|
66
|
-
matchedRulesById.set(rule.id, rule);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
} catch (err) {
|
|
70
|
-
console.warn('[PII] Invalid regex for rule:', rule.id, rule.pattern, err);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (matchedRulesById.size === 0) {
|
|
75
|
-
return { matched: false };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Build one string: main errorMessage line + one line per matched rule (in selected language).
|
|
79
|
-
const mainMessage = getLocalized(
|
|
80
|
-
config.errorMessage,
|
|
81
|
-
normalizedLang,
|
|
82
|
-
'The message contains personal or sensitive data.'
|
|
83
|
-
);
|
|
84
|
-
const ruleMessages = Array.from(matchedRulesById.values()).map(rule => {
|
|
85
|
-
const labelFallback = getLocalized(rule.label, normalizedLang, rule.id);
|
|
86
|
-
return getLocalized(rule.message, normalizedLang, labelFallback);
|
|
87
|
-
});
|
|
88
|
-
const errorText = [mainMessage, ...ruleMessages].join('\n');
|
|
89
|
-
|
|
90
|
-
return { matched: true, errorText };
|
|
91
|
-
}
|
package/src/helpers/sanitizer.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// tts/TextSanitizer.ts
|
|
2
|
-
|
|
3
|
-
import { escapeHTML, stripEmojis, stripHTML, stripMarkdown, stripOutputTags, stripReasoningTags } from "./utils";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Sanitizza completamente il testo per la sintesi vocale
|
|
9
|
-
* @param text Testo da sanitizzare
|
|
10
|
-
*/
|
|
11
|
-
export function sanitizeText(text: string): string {
|
|
12
|
-
return escapeHTML(
|
|
13
|
-
stripMarkdown(
|
|
14
|
-
stripEmojis(stripHTML(stripReasoningTags(stripOutputTags(text))))
|
|
15
|
-
)
|
|
16
|
-
);
|
|
17
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { EventLog, UsersLog } from '@memori.ai/memori-api-client/dist/types';
|
|
2
|
-
|
|
3
|
-
const groupBy = <T>(array: T[], predicate: (v: T) => string) =>
|
|
4
|
-
array.reduce((acc, value) => {
|
|
5
|
-
if (!acc[predicate(value)]) {
|
|
6
|
-
acc[predicate(value)] = [];
|
|
7
|
-
}
|
|
8
|
-
acc[predicate(value)].push(value);
|
|
9
|
-
return acc;
|
|
10
|
-
}, {} as { [key: string]: T[] });
|
|
11
|
-
|
|
12
|
-
const removeDuplicates = (logs: EventLog[]): { [key: string]: number } => {
|
|
13
|
-
const filteredLogs = logs.filter(
|
|
14
|
-
log => log.eventType === 'MemoriOpened' && log.ipAddress !== null
|
|
15
|
-
);
|
|
16
|
-
const reducedLogs = filteredLogs.reduce(
|
|
17
|
-
(acc: { [key: string]: number }, o) => {
|
|
18
|
-
if (!acc[o.ipAddress as string]) {
|
|
19
|
-
acc[o.ipAddress as string] = 0;
|
|
20
|
-
}
|
|
21
|
-
acc[o.ipAddress as string] += 1;
|
|
22
|
-
return acc;
|
|
23
|
-
},
|
|
24
|
-
{}
|
|
25
|
-
);
|
|
26
|
-
return reducedLogs;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const eventLogGroupUsersByDate = (eventLogs: EventLog[]): UsersLog[] => {
|
|
30
|
-
const mapped = eventLogs.map(event => ({
|
|
31
|
-
...event,
|
|
32
|
-
timestamp: new Intl.DateTimeFormat('it', {
|
|
33
|
-
day: '2-digit',
|
|
34
|
-
month: '2-digit',
|
|
35
|
-
year: 'numeric',
|
|
36
|
-
}).format(new Date(event.timestamp)),
|
|
37
|
-
}));
|
|
38
|
-
const grouped = groupBy(mapped, v => v.timestamp);
|
|
39
|
-
|
|
40
|
-
const userLogs: UsersLog[] = Object.keys(grouped).map(key => {
|
|
41
|
-
const reducedLogs = removeDuplicates(grouped[key]);
|
|
42
|
-
let countRecurrentUsers = 0;
|
|
43
|
-
for (const [, value] of Object.entries(reducedLogs)) {
|
|
44
|
-
if (Number(value) > 1) {
|
|
45
|
-
countRecurrentUsers += 1;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
timestamp: new Intl.DateTimeFormat('it', {
|
|
50
|
-
day: '2-digit',
|
|
51
|
-
month: '2-digit',
|
|
52
|
-
}).format(new Date(key)),
|
|
53
|
-
countRecurrentUsers,
|
|
54
|
-
countUsers: Object.keys(reducedLogs).length,
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
-
return userLogs;
|
|
58
|
-
};
|
|
@@ -1,515 +0,0 @@
|
|
|
1
|
-
// hooks/useSTT.ts - Simplified version for Speech-to-Text functionality
|
|
2
|
-
// Audio format compatibility:
|
|
3
|
-
// - MediaRecorder supports: webm, mp4, ogg formats
|
|
4
|
-
// - Azure STT supported formats: WAV format (required for Azure Speech SDK)
|
|
5
|
-
// - OpenAI: Supports multiple formats including webm, mp4, ogg
|
|
6
|
-
import { useState, useCallback, useRef, useEffect } from 'react';
|
|
7
|
-
import { getLocalConfig } from '../configuration';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Configuration for STT
|
|
11
|
-
*/
|
|
12
|
-
export interface STTConfig {
|
|
13
|
-
provider: 'azure' | 'openai';
|
|
14
|
-
language?: string;
|
|
15
|
-
model?: string;
|
|
16
|
-
region?: string; // required for Azure
|
|
17
|
-
tenant?: string; // Tenant identifier for multi-tenant applications
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Result from STT transcription
|
|
22
|
-
*/
|
|
23
|
-
export interface STTResult {
|
|
24
|
-
text: string;
|
|
25
|
-
confidence?: number;
|
|
26
|
-
language?: string;
|
|
27
|
-
duration?: number;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Options for the useSTT hook
|
|
32
|
-
*/
|
|
33
|
-
export interface UseSTTOptions {
|
|
34
|
-
apiUrl?: string;
|
|
35
|
-
onTranscriptionComplete?: (result: STTResult) => void;
|
|
36
|
-
onError?: (error: Error) => void;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Recording states
|
|
41
|
-
*/
|
|
42
|
-
export type RecordingState = 'idle' | 'recording' | 'processing' | 'error';
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Convert audio blob to WAV format
|
|
46
|
-
*/
|
|
47
|
-
async function convertToWav(audioBlob: Blob): Promise<Blob> {
|
|
48
|
-
return new Promise((resolve, reject) => {
|
|
49
|
-
const AudioContextClass =
|
|
50
|
-
window.AudioContext || (window as any).webkitAudioContext;
|
|
51
|
-
if (!AudioContextClass) {
|
|
52
|
-
reject(new Error('AudioContext not supported in this browser'));
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const audioContext = new AudioContextClass();
|
|
57
|
-
const fileReader = new FileReader();
|
|
58
|
-
|
|
59
|
-
fileReader.onload = async () => {
|
|
60
|
-
try {
|
|
61
|
-
const arrayBuffer = fileReader.result as ArrayBuffer;
|
|
62
|
-
|
|
63
|
-
if (audioContext.state === 'suspended') {
|
|
64
|
-
await audioContext.resume();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
|
|
68
|
-
|
|
69
|
-
const wavBlob = audioBufferToWav(audioBuffer);
|
|
70
|
-
|
|
71
|
-
await audioContext.close();
|
|
72
|
-
|
|
73
|
-
resolve(wavBlob);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
reject(error);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
fileReader.onerror = () => {
|
|
80
|
-
reject(new Error('Failed to read audio file'));
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
fileReader.readAsArrayBuffer(audioBlob);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Convert AudioBuffer to WAV Blob
|
|
89
|
-
*/
|
|
90
|
-
function audioBufferToWav(buffer: AudioBuffer): Blob {
|
|
91
|
-
const length = buffer.length;
|
|
92
|
-
const sampleRate = buffer.sampleRate;
|
|
93
|
-
const numberOfChannels = buffer.numberOfChannels;
|
|
94
|
-
const arrayBuffer = new ArrayBuffer(44 + length * numberOfChannels * 2);
|
|
95
|
-
const view = new DataView(arrayBuffer);
|
|
96
|
-
|
|
97
|
-
// WAV header
|
|
98
|
-
const writeString = (offset: number, string: string) => {
|
|
99
|
-
for (let i = 0; i < string.length; i++) {
|
|
100
|
-
view.setUint8(offset + i, string.charCodeAt(i));
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
writeString(0, 'RIFF');
|
|
105
|
-
view.setUint32(4, 36 + length * numberOfChannels * 2, true);
|
|
106
|
-
writeString(8, 'WAVE');
|
|
107
|
-
writeString(12, 'fmt ');
|
|
108
|
-
view.setUint32(16, 16, true);
|
|
109
|
-
view.setUint16(20, 1, true);
|
|
110
|
-
view.setUint16(22, numberOfChannels, true);
|
|
111
|
-
view.setUint32(24, sampleRate, true);
|
|
112
|
-
view.setUint32(28, sampleRate * numberOfChannels * 2, true);
|
|
113
|
-
view.setUint16(32, numberOfChannels * 2, true);
|
|
114
|
-
view.setUint16(34, 16, true);
|
|
115
|
-
writeString(36, 'data');
|
|
116
|
-
view.setUint32(40, length * numberOfChannels * 2, true);
|
|
117
|
-
|
|
118
|
-
// Convert audio data
|
|
119
|
-
let offset = 44;
|
|
120
|
-
for (let i = 0; i < length; i++) {
|
|
121
|
-
for (let channel = 0; channel < numberOfChannels; channel++) {
|
|
122
|
-
const sample = Math.max(
|
|
123
|
-
-1,
|
|
124
|
-
Math.min(1, buffer.getChannelData(channel)[i])
|
|
125
|
-
);
|
|
126
|
-
view.setInt16(
|
|
127
|
-
offset,
|
|
128
|
-
sample < 0 ? sample * 0x8000 : sample * 0x7fff,
|
|
129
|
-
true
|
|
130
|
-
);
|
|
131
|
-
offset += 2;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return new Blob([arrayBuffer], { type: 'audio/wav' });
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Simplified hook for handling Speech-to-Text functionality
|
|
140
|
-
*/
|
|
141
|
-
export function useSTT(
|
|
142
|
-
config: STTConfig,
|
|
143
|
-
processSpeechAndSendMessage: (text: string) => void,
|
|
144
|
-
options: UseSTTOptions = {},
|
|
145
|
-
defaultEnableAudio: boolean = true
|
|
146
|
-
) {
|
|
147
|
-
// Local state
|
|
148
|
-
const [recordingState, setRecordingState] = useState<RecordingState>('idle');
|
|
149
|
-
const [microphoneMuted, setMicrophoneMuted] = useState(
|
|
150
|
-
getLocalConfig('muteMicrophone', !defaultEnableAudio)
|
|
151
|
-
);
|
|
152
|
-
const [hasUserActivatedRecord, setHasUserActivatedRecord] = useState(false);
|
|
153
|
-
const [lastTranscription, setLastTranscription] = useState<STTResult | null>(
|
|
154
|
-
null
|
|
155
|
-
);
|
|
156
|
-
const [isListening, setIsListening] = useState(false);
|
|
157
|
-
|
|
158
|
-
// References
|
|
159
|
-
const mediaRecorderRef = useRef<MediaRecorder | null>(null);
|
|
160
|
-
const audioStreamRef = useRef<MediaStream | null>(null);
|
|
161
|
-
const chunksRef = useRef<Blob[]>([]);
|
|
162
|
-
const isRecordingRef = useRef<boolean>(false);
|
|
163
|
-
const isMountedRef = useRef<boolean>(true);
|
|
164
|
-
const apiUrl = options.apiUrl || '/api/stt';
|
|
165
|
-
|
|
166
|
-
const initializeRecording = useCallback(async (): Promise<boolean> => {
|
|
167
|
-
try {
|
|
168
|
-
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
|
169
|
-
throw new Error('Media recording is not supported in this browser');
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const stream = await navigator.mediaDevices.getUserMedia({
|
|
173
|
-
audio: {
|
|
174
|
-
echoCancellation: true,
|
|
175
|
-
noiseSuppression: true,
|
|
176
|
-
autoGainControl: true,
|
|
177
|
-
sampleRate: 16000,
|
|
178
|
-
},
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
audioStreamRef.current = stream;
|
|
182
|
-
|
|
183
|
-
let mimeType = '';
|
|
184
|
-
|
|
185
|
-
const supportedFormats = [
|
|
186
|
-
'audio/mp4',
|
|
187
|
-
'audio/webm;codecs=opus',
|
|
188
|
-
'audio/webm',
|
|
189
|
-
'audio/ogg;codecs=opus',
|
|
190
|
-
'audio/wav',
|
|
191
|
-
];
|
|
192
|
-
|
|
193
|
-
for (const format of supportedFormats) {
|
|
194
|
-
if (MediaRecorder.isTypeSupported(format)) {
|
|
195
|
-
mimeType = format;
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const mediaRecorder = new MediaRecorder(
|
|
201
|
-
stream,
|
|
202
|
-
mimeType ? { mimeType } : {}
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
mediaRecorder.ondataavailable = (event: BlobEvent) => {
|
|
206
|
-
if (event.data.size > 0) {
|
|
207
|
-
chunksRef.current.push(event.data);
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
mediaRecorder.onstop = async () => {
|
|
212
|
-
setRecordingState('processing');
|
|
213
|
-
setIsListening(false);
|
|
214
|
-
|
|
215
|
-
try {
|
|
216
|
-
if (chunksRef.current.length === 0) {
|
|
217
|
-
throw new Error('No audio data recorded');
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
let audioBlob = new Blob(chunksRef.current, {
|
|
221
|
-
type: mediaRecorder.mimeType,
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
if (audioBlob.size === 0) {
|
|
225
|
-
throw new Error('Recorded audio is empty');
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (config.provider === 'azure') {
|
|
229
|
-
try {
|
|
230
|
-
audioBlob = await convertToWav(audioBlob);
|
|
231
|
-
} catch (conversionError) {
|
|
232
|
-
throw new Error(
|
|
233
|
-
'Failed to convert audio to WAV format for Azure'
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const result = await transcribeAudio(audioBlob);
|
|
239
|
-
|
|
240
|
-
if (result.text && result.text.trim().length > 0) {
|
|
241
|
-
if (processSpeechAndSendMessage) {
|
|
242
|
-
processSpeechAndSendMessage(result.text);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
setLastTranscription(result);
|
|
246
|
-
|
|
247
|
-
if (options.onTranscriptionComplete) {
|
|
248
|
-
options.onTranscriptionComplete(result);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
setRecordingState('idle');
|
|
253
|
-
} catch (err) {
|
|
254
|
-
const errorMsg = err instanceof Error ? err : new Error(String(err));
|
|
255
|
-
setRecordingState('error');
|
|
256
|
-
|
|
257
|
-
if (options.onError) {
|
|
258
|
-
options.onError(errorMsg);
|
|
259
|
-
}
|
|
260
|
-
} finally {
|
|
261
|
-
chunksRef.current = [];
|
|
262
|
-
isRecordingRef.current = false;
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
mediaRecorder.onerror = () => {
|
|
267
|
-
const errorMsg = new Error('Recording failed');
|
|
268
|
-
setRecordingState('error');
|
|
269
|
-
isRecordingRef.current = false;
|
|
270
|
-
|
|
271
|
-
if (options.onError) {
|
|
272
|
-
options.onError(errorMsg);
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
mediaRecorderRef.current = mediaRecorder;
|
|
277
|
-
return true;
|
|
278
|
-
} catch (err) {
|
|
279
|
-
const errorMsg =
|
|
280
|
-
err instanceof Error ? err : new Error('Failed to access microphone');
|
|
281
|
-
setRecordingState('error');
|
|
282
|
-
|
|
283
|
-
if (options.onError) {
|
|
284
|
-
options.onError(errorMsg);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return false;
|
|
288
|
-
}
|
|
289
|
-
}, [config.provider, options]);
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Transcribe audio blob using the API
|
|
294
|
-
*/
|
|
295
|
-
const transcribeAudio = useCallback(
|
|
296
|
-
async (audioBlob: Blob): Promise<STTResult> => {
|
|
297
|
-
const formData = new FormData();
|
|
298
|
-
let fileExtension = 'webm';
|
|
299
|
-
|
|
300
|
-
if (config.provider === 'azure') {
|
|
301
|
-
fileExtension = 'wav';
|
|
302
|
-
} else if (mediaRecorderRef.current?.mimeType) {
|
|
303
|
-
if (mediaRecorderRef.current.mimeType.includes('webm')) {
|
|
304
|
-
fileExtension = 'webm';
|
|
305
|
-
} else if (mediaRecorderRef.current.mimeType.includes('mp4')) {
|
|
306
|
-
fileExtension = 'mp4';
|
|
307
|
-
} else if (mediaRecorderRef.current.mimeType.includes('ogg')) {
|
|
308
|
-
fileExtension = 'ogg';
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
formData.append('audio', audioBlob, `recording.${fileExtension}`);
|
|
313
|
-
formData.append('provider', config.provider);
|
|
314
|
-
formData.append('tenant', config.tenant || 'www.aisuru.com');
|
|
315
|
-
|
|
316
|
-
if (config.language) {
|
|
317
|
-
formData.append('language', config.language);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
if (config.model) {
|
|
321
|
-
formData.append('model', config.model);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if (config.region) {
|
|
325
|
-
formData.append('region', config.region);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
const response = await fetch(apiUrl, {
|
|
329
|
-
method: 'POST',
|
|
330
|
-
body: formData,
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
if (!response.ok) {
|
|
334
|
-
const errorData = await response.json().catch(() => ({}));
|
|
335
|
-
throw new Error(errorData.error || `API error: ${response.status}`);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
const data = await response.json();
|
|
339
|
-
|
|
340
|
-
if (!data.success || !data.result) {
|
|
341
|
-
throw new Error('Invalid response from transcription service');
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return data.result;
|
|
345
|
-
},
|
|
346
|
-
[config, apiUrl]
|
|
347
|
-
);
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Start recording audio
|
|
351
|
-
*/
|
|
352
|
-
const startRecording = useCallback(async (): Promise<void> => {
|
|
353
|
-
if (microphoneMuted || recordingState === 'recording') {
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
if (!hasUserActivatedRecord) {
|
|
358
|
-
setHasUserActivatedRecord(true);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
try {
|
|
362
|
-
setRecordingState('recording');
|
|
363
|
-
|
|
364
|
-
if (!mediaRecorderRef.current) {
|
|
365
|
-
const initialized = await initializeRecording();
|
|
366
|
-
if (!initialized) {
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
chunksRef.current = [];
|
|
372
|
-
isRecordingRef.current = true;
|
|
373
|
-
|
|
374
|
-
if (
|
|
375
|
-
mediaRecorderRef.current &&
|
|
376
|
-
mediaRecorderRef.current.state === 'inactive'
|
|
377
|
-
) {
|
|
378
|
-
mediaRecorderRef.current.start();
|
|
379
|
-
setIsListening(true);
|
|
380
|
-
}
|
|
381
|
-
} catch (err) {
|
|
382
|
-
const errorMsg =
|
|
383
|
-
err instanceof Error ? err : new Error('Failed to start recording');
|
|
384
|
-
setRecordingState('error');
|
|
385
|
-
isRecordingRef.current = false;
|
|
386
|
-
|
|
387
|
-
if (options.onError) {
|
|
388
|
-
options.onError(errorMsg);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}, [
|
|
392
|
-
microphoneMuted,
|
|
393
|
-
recordingState,
|
|
394
|
-
hasUserActivatedRecord,
|
|
395
|
-
initializeRecording,
|
|
396
|
-
options,
|
|
397
|
-
]);
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Stop recording audio
|
|
401
|
-
*/
|
|
402
|
-
const stopRecording = useCallback((): void => {
|
|
403
|
-
if (!isRecordingRef.current) {
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
try {
|
|
408
|
-
setIsListening(false);
|
|
409
|
-
|
|
410
|
-
if (
|
|
411
|
-
mediaRecorderRef.current &&
|
|
412
|
-
mediaRecorderRef.current.state === 'recording'
|
|
413
|
-
) {
|
|
414
|
-
mediaRecorderRef.current.stop();
|
|
415
|
-
}
|
|
416
|
-
} catch (err) {
|
|
417
|
-
const errorMsg =
|
|
418
|
-
err instanceof Error ? err : new Error('Failed to stop recording');
|
|
419
|
-
setRecordingState('error');
|
|
420
|
-
isRecordingRef.current = false;
|
|
421
|
-
|
|
422
|
-
if (options.onError) {
|
|
423
|
-
options.onError(errorMsg);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}, [recordingState, options]);
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Toggle recording state
|
|
430
|
-
*/
|
|
431
|
-
const toggleRecording = useCallback(async (): Promise<void> => {
|
|
432
|
-
if (recordingState === 'recording') {
|
|
433
|
-
stopRecording();
|
|
434
|
-
} else if (recordingState === 'idle') {
|
|
435
|
-
await startRecording();
|
|
436
|
-
}
|
|
437
|
-
}, [recordingState, startRecording, stopRecording]);
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
* Toggle microphone mute state
|
|
441
|
-
*/
|
|
442
|
-
const toggleMute = useCallback(
|
|
443
|
-
(mute?: boolean): void => {
|
|
444
|
-
const newMuteState = mute !== undefined ? mute : !microphoneMuted;
|
|
445
|
-
setMicrophoneMuted(newMuteState);
|
|
446
|
-
|
|
447
|
-
if (newMuteState && recordingState === 'recording') {
|
|
448
|
-
stopRecording();
|
|
449
|
-
}
|
|
450
|
-
},
|
|
451
|
-
[microphoneMuted, recordingState, stopRecording]
|
|
452
|
-
);
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* Clean up resources
|
|
456
|
-
*/
|
|
457
|
-
const cleanup = useCallback((): void => {
|
|
458
|
-
isRecordingRef.current = false;
|
|
459
|
-
|
|
460
|
-
if (mediaRecorderRef.current) {
|
|
461
|
-
if (mediaRecorderRef.current.state === 'recording') {
|
|
462
|
-
mediaRecorderRef.current.stop();
|
|
463
|
-
}
|
|
464
|
-
mediaRecorderRef.current = null;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
if (audioStreamRef.current) {
|
|
468
|
-
audioStreamRef.current.getTracks().forEach(track => track.stop());
|
|
469
|
-
audioStreamRef.current = null;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
chunksRef.current = [];
|
|
473
|
-
setIsListening(false);
|
|
474
|
-
setRecordingState('idle');
|
|
475
|
-
}, []);
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Cleanup on unmount
|
|
479
|
-
*/
|
|
480
|
-
useEffect(() => {
|
|
481
|
-
return () => {
|
|
482
|
-
isMountedRef.current = false;
|
|
483
|
-
cleanup();
|
|
484
|
-
};
|
|
485
|
-
}, [cleanup]);
|
|
486
|
-
|
|
487
|
-
/**
|
|
488
|
-
* Update global variables
|
|
489
|
-
*/
|
|
490
|
-
useEffect(() => {
|
|
491
|
-
if (typeof window !== 'undefined') {
|
|
492
|
-
(window as any).memoriListening = isListening;
|
|
493
|
-
}
|
|
494
|
-
}, [isListening]);
|
|
495
|
-
|
|
496
|
-
return {
|
|
497
|
-
// State
|
|
498
|
-
recordingState,
|
|
499
|
-
microphoneMuted,
|
|
500
|
-
hasUserActivatedRecord,
|
|
501
|
-
lastTranscription,
|
|
502
|
-
isListening,
|
|
503
|
-
|
|
504
|
-
// Actions
|
|
505
|
-
startRecording,
|
|
506
|
-
stopRecording,
|
|
507
|
-
toggleRecording,
|
|
508
|
-
toggleMute,
|
|
509
|
-
transcribeAudio,
|
|
510
|
-
setHasUserActivatedRecord,
|
|
511
|
-
|
|
512
|
-
// Utils
|
|
513
|
-
cleanup,
|
|
514
|
-
};
|
|
515
|
-
}
|