@aakash58/chatbot 1.1.19 → 1.1.21
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/.editorconfig +17 -0
- package/.vscode/extensions.json +4 -0
- package/.vscode/launch.json +41 -0
- package/.vscode/settings.json +14 -0
- package/.vscode/tasks.json +60 -0
- package/README.md +298 -22
- package/angular.json +132 -0
- package/docs/PUBLISHING_GUIDE.md +104 -0
- package/package.json +75 -29
- package/projects/app-doohbot/public/assets/const/app-const.json +15 -0
- package/projects/app-doohbot/public/assets/const/doohclick_license.json +6 -0
- package/projects/app-doohbot/public/favicon.ico +0 -0
- package/projects/app-doohbot/src/app/app.config.ts +13 -0
- package/projects/app-doohbot/src/app/app.html +31 -0
- package/projects/app-doohbot/src/app/app.routes.ts +3 -0
- package/projects/app-doohbot/src/app/app.scss +279 -0
- package/projects/app-doohbot/src/app/app.spec.ts +23 -0
- package/projects/app-doohbot/src/app/app.ts +72 -0
- package/projects/app-doohbot/src/index.html +15 -0
- package/projects/app-doohbot/src/main.ts +6 -0
- package/projects/app-doohbot/src/styles.scss +15 -0
- package/projects/app-doohbot/tsconfig.app.json +15 -0
- package/projects/app-doohbot/tsconfig.spec.json +14 -0
- package/projects/doohbot/README.md +64 -0
- package/projects/doohbot/docs/README.md +140 -0
- package/projects/doohbot/ng-package.json +10 -0
- package/projects/doohbot/package.json +16 -0
- package/projects/doohbot/src/lib/app/chat/chat-ui-state.service.ts +194 -0
- package/projects/doohbot/src/lib/app/chat/chat.service.ts +547 -0
- package/projects/doohbot/src/lib/app/chat/components/chat-button/chat-button.component.html +27 -0
- package/projects/doohbot/src/lib/app/chat/components/chat-button/chat-button.component.scss +115 -0
- package/projects/doohbot/src/lib/app/chat/components/chat-button/chat-button.component.ts +35 -0
- package/projects/doohbot/src/lib/app/chat/components/chat-footer/chat-footer.component.html +3 -0
- package/projects/doohbot/src/lib/app/chat/components/chat-footer/chat-footer.component.scss +20 -0
- package/projects/doohbot/src/lib/app/chat/components/chat-footer/chat-footer.component.ts +12 -0
- package/projects/doohbot/src/lib/app/chat/components/chat-header/chat-header.component.html +34 -0
- package/projects/doohbot/src/lib/app/chat/components/chat-header/chat-header.component.scss +78 -0
- package/projects/doohbot/src/lib/app/chat/components/chat-header/chat-header.component.ts +52 -0
- package/projects/doohbot/src/lib/app/chat/components/chat-history-sidebar/chat-history-sidebar.component.html +77 -0
- package/projects/doohbot/src/lib/app/chat/components/chat-history-sidebar/chat-history-sidebar.component.scss +346 -0
- package/projects/doohbot/src/lib/app/chat/components/chat-history-sidebar/chat-history-sidebar.component.ts +188 -0
- package/projects/doohbot/src/lib/app/chat/components/chat-window/chat-window.component.html +146 -0
- package/projects/doohbot/src/lib/app/chat/components/chat-window/chat-window.component.scss +187 -0
- package/projects/doohbot/src/lib/app/chat/components/chat-window/chat-window.component.ts +256 -0
- package/projects/doohbot/src/lib/app/chat/components/message-input/message-input.component.html +17 -0
- package/projects/doohbot/src/lib/app/chat/components/message-input/message-input.component.scss +59 -0
- package/projects/doohbot/src/lib/app/chat/components/message-input/message-input.component.ts +28 -0
- package/projects/doohbot/src/lib/app/chat/components/message-list/message-list.component.html +138 -0
- package/projects/doohbot/src/lib/app/chat/components/message-list/message-list.component.scss +436 -0
- package/projects/doohbot/src/lib/app/chat/components/message-list/message-list.component.ts +106 -0
- package/projects/doohbot/src/lib/app/chat/model/chat-history.model.ts +57 -0
- package/projects/doohbot/src/lib/app/chat/model/chat-request.model.ts +17 -0
- package/projects/doohbot/src/lib/app/chat/model/chat-response.model.ts +9 -0
- package/projects/doohbot/src/lib/app/chat/model/chat-session.model.ts +14 -0
- package/{lib/app/chat/model/chat-stream-message.model.d.ts → projects/doohbot/src/lib/app/chat/model/chat-stream-message.model.ts} +6 -5
- package/projects/doohbot/src/lib/app/chat/model/chat-stream-response.model.ts +12 -0
- package/projects/doohbot/src/lib/app/chat/services/chat-api.service.ts +82 -0
- package/projects/doohbot/src/lib/app/chat/services/chat-audio.service.ts +44 -0
- package/projects/doohbot/src/lib/app/chat/services/chat-history.service.ts +303 -0
- package/projects/doohbot/src/lib/app/login/login-form.component.html +80 -0
- package/projects/doohbot/src/lib/app/login/login-form.component.scss +189 -0
- package/projects/doohbot/src/lib/app/login/login-form.component.ts +45 -0
- package/projects/doohbot/src/lib/app/personalization/personalization-dialog.component.html +81 -0
- package/projects/doohbot/src/lib/app/personalization/personalization-dialog.component.scss +179 -0
- package/projects/doohbot/src/lib/app/personalization/personalization-dialog.component.ts +217 -0
- package/projects/doohbot/src/lib/app/personalization/personalization.service.ts +197 -0
- package/projects/doohbot/src/lib/app/personalization/sections/account/account-section.component.html +111 -0
- package/projects/doohbot/src/lib/app/personalization/sections/account/account-section.component.scss +218 -0
- package/projects/doohbot/src/lib/app/personalization/sections/account/account-section.component.ts +121 -0
- package/projects/doohbot/src/lib/app/personalization/sections/instructions/instructions-section.component.html +46 -0
- package/projects/doohbot/src/lib/app/personalization/sections/instructions/instructions-section.component.scss +138 -0
- package/projects/doohbot/src/lib/app/personalization/sections/instructions/instructions-section.component.ts +28 -0
- package/projects/doohbot/src/lib/app/personalization/sections/preferences/color-picker-dialog.component.ts +92 -0
- package/projects/doohbot/src/lib/app/personalization/sections/preferences/preferences-section.component.html +198 -0
- package/projects/doohbot/src/lib/app/personalization/sections/preferences/preferences-section.component.scss +107 -0
- package/projects/doohbot/src/lib/app/personalization/sections/preferences/preferences-section.component.ts +103 -0
- package/projects/doohbot/src/lib/app/personalization/sections/profile/profile-section.component.html +46 -0
- package/projects/doohbot/src/lib/app/personalization/sections/profile/profile-section.component.scss +131 -0
- package/projects/doohbot/src/lib/app/personalization/sections/profile/profile-section.component.ts +23 -0
- package/projects/doohbot/src/lib/app/personalization/sections/settings/setting-section.component.html +33 -0
- package/projects/doohbot/src/lib/app/personalization/sections/settings/setting-section.component.scss +61 -0
- package/projects/doohbot/src/lib/app/personalization/sections/settings/setting-section.component.ts +20 -0
- package/projects/doohbot/src/lib/app/personalization/sections/terms/terms-section.component.html +30 -0
- package/projects/doohbot/src/lib/app/personalization/sections/terms/terms-section.component.scss +59 -0
- package/projects/doohbot/src/lib/app/personalization/sections/terms/terms-section.component.ts +12 -0
- package/projects/doohbot/src/lib/constant/doohbot-constant.ts +40 -0
- package/projects/doohbot/src/lib/constant/html-entities.ts +8 -0
- package/projects/doohbot/src/lib/constant/utf8.ts +9 -0
- package/projects/doohbot/src/lib/core/app-const.ts +63 -0
- package/projects/doohbot/src/lib/core/auth/account-api.service.ts +53 -0
- package/projects/doohbot/src/lib/core/auth/auth.service.ts +478 -0
- package/projects/doohbot/src/lib/core/auth/models/auth-result.model.ts +4 -0
- package/projects/doohbot/src/lib/core/auth/models/federated-login-request.model.ts +5 -0
- package/projects/doohbot/src/lib/core/auth/models/login-request.model.ts +6 -0
- package/projects/doohbot/src/lib/core/auth/storage.service.ts +113 -0
- package/projects/doohbot/src/lib/core/directives/draggable/draggable-dialog.directive.ts +123 -0
- package/projects/doohbot/src/lib/core/directives/draggable/draggable-dialog.module.ts +9 -0
- package/projects/doohbot/src/lib/core/directives/fullscreen/fullscreen.directive.ts +58 -0
- package/projects/doohbot/src/lib/core/directives/fullscreen/fullscreen.module.ts +9 -0
- package/projects/doohbot/src/lib/core/directives/popout/popout.directive.ts +169 -0
- package/projects/doohbot/src/lib/core/directives/popout/popout.module.ts +9 -0
- package/projects/doohbot/src/lib/core/directives/resizable/resizable-dialog.directive.ts +197 -0
- package/projects/doohbot/src/lib/core/directives/resizable/resizable-dialog.module.ts +9 -0
- package/projects/doohbot/src/lib/core/enums/api-request-state.enum.ts +9 -0
- package/projects/doohbot/src/lib/core/environments/environment.prod.ts +14 -0
- package/projects/doohbot/src/lib/core/environments/environment.ts +14 -0
- package/projects/doohbot/src/lib/core/helpers/crypto-helper.service.ts +72 -0
- package/projects/doohbot/src/lib/core/http/http-stream.service.ts +105 -0
- package/projects/doohbot/src/lib/core/http/http.service.ts +148 -0
- package/projects/doohbot/src/lib/core/interceptors/auth.interceptor.ts +118 -0
- package/projects/doohbot/src/lib/core/interceptors/license.interceptor.ts +50 -0
- package/projects/doohbot/src/lib/core/models/api-config.model.ts +82 -0
- package/projects/doohbot/src/lib/core/models/api-request.model.ts +92 -0
- package/projects/doohbot/src/lib/core/models/api-response.model.ts +13 -0
- package/projects/doohbot/src/lib/core/models/doohbot-config.model.ts +109 -0
- package/{lib/core/models/license.model.d.ts → projects/doohbot/src/lib/core/models/license.model.ts} +27 -23
- package/projects/doohbot/src/lib/core/models/message.ts +18 -0
- package/projects/doohbot/src/lib/core/models/theme-config.model.ts +48 -0
- package/projects/doohbot/src/lib/core/services/core-config.service.ts +53 -0
- package/projects/doohbot/src/lib/core/services/doohbot-api.service.ts +207 -0
- package/projects/doohbot/src/lib/core/services/license.service.ts +171 -0
- package/projects/doohbot/src/lib/core/services/markdown.service.ts +73 -0
- package/projects/doohbot/src/lib/core/services/theme.service.ts +305 -0
- package/{lib/core/types/auth-mode.type.d.ts → projects/doohbot/src/lib/core/types/auth-mode.type.ts} +4 -4
- package/{lib/core/types/auth-status.type.d.ts → projects/doohbot/src/lib/core/types/auth-status.type.ts} +5 -4
- package/{lib/core/types/chat-stream.type.d.ts → projects/doohbot/src/lib/core/types/chat-stream.type.ts} +4 -4
- package/{lib/core/types/message-role.type.d.ts → projects/doohbot/src/lib/core/types/message-role.type.ts} +4 -4
- package/{lib/core/types/prompt-mode.type.d.ts → projects/doohbot/src/lib/core/types/prompt-mode.type.ts} +5 -4
- package/{lib/core/types/snackbar-error.type.d.ts → projects/doohbot/src/lib/core/types/snackbar-error.type.ts} +5 -4
- package/{lib/core/types/tenant-resolution-strategy.type.d.ts → projects/doohbot/src/lib/core/types/tenant-resolution-strategy.type.ts} +4 -4
- package/projects/doohbot/src/lib/core/utils/error-handler.util.ts +31 -0
- package/projects/doohbot/src/lib/core/utils/logger.service.ts +45 -0
- package/projects/doohbot/src/lib/doohbot-input.ts +19 -0
- package/projects/doohbot/src/lib/doohbot.component.html +34 -0
- package/projects/doohbot/src/lib/doohbot.component.scss +17 -0
- package/projects/doohbot/src/lib/doohbot.component.spec.ts +31 -0
- package/projects/doohbot/src/lib/doohbot.component.ts +545 -0
- package/projects/doohbot/src/lib/elements.ts +25 -0
- package/projects/doohbot/src/lib/predefined_messages.ts +14 -0
- package/projects/doohbot/src/lib/shared/chips/chips.component.html +9 -0
- package/projects/doohbot/src/lib/shared/chips/chips.component.scss +29 -0
- package/projects/doohbot/src/lib/shared/chips/chips.component.spec.ts +22 -0
- package/projects/doohbot/src/lib/shared/chips/chips.component.ts +20 -0
- package/projects/doohbot/src/lib/shared/dialog/dialog.component.html +29 -0
- package/projects/doohbot/src/lib/shared/dialog/dialog.component.scss +100 -0
- package/projects/doohbot/src/lib/shared/dialog/dialog.component.ts +42 -0
- package/projects/doohbot/src/lib/shared/dialog/dialog.service.ts +62 -0
- package/projects/doohbot/src/lib/shared/dialog/dialog.utils.ts +102 -0
- package/projects/doohbot/src/lib/shared/dropdown-menu/dropdown-menu.component.html +30 -0
- package/projects/doohbot/src/lib/shared/dropdown-menu/dropdown-menu.component.scss +53 -0
- package/projects/doohbot/src/lib/shared/dropdown-menu/dropdown-menu.component.spec.ts +22 -0
- package/projects/doohbot/src/lib/shared/dropdown-menu/dropdown-menu.component.ts +35 -0
- package/projects/doohbot/src/lib/shared/input-dialog/input-dialog.component.html +16 -0
- package/projects/doohbot/src/lib/shared/input-dialog/input-dialog.component.scss +45 -0
- package/projects/doohbot/src/lib/shared/input-dialog/input-dialog.component.ts +46 -0
- package/projects/doohbot/src/lib/shared/menu-item/menu-item.component.html +5 -0
- package/projects/doohbot/src/lib/shared/menu-item/menu-item.component.scss +0 -0
- package/projects/doohbot/src/lib/shared/menu-item/menu-item.component.spec.ts +22 -0
- package/projects/doohbot/src/lib/shared/menu-item/menu-item.component.ts +20 -0
- package/projects/doohbot/src/lib/shared/pipes/simple-markdown.pipe.ts +19 -0
- package/projects/doohbot/src/lib/shared/popout/popout.html +1 -0
- package/projects/doohbot/src/lib/shared/popout/popout.scss +0 -0
- package/projects/doohbot/src/lib/shared/popout/popout.spec.ts +23 -0
- package/projects/doohbot/src/lib/shared/popout/popout.ts +11 -0
- package/projects/doohbot/src/lib/shared/snackbar/snackbar.component.html +7 -0
- package/projects/doohbot/src/lib/shared/snackbar/snackbar.component.scss +125 -0
- package/projects/doohbot/src/lib/shared/snackbar/snackbar.component.spec.ts +21 -0
- package/projects/doohbot/src/lib/shared/snackbar/snackbar.component.ts +44 -0
- package/projects/doohbot/src/lib/shared/snackbar/snackbar.service.ts +54 -0
- package/{lib/shared/snackbar/snackbar.utils.d.ts → projects/doohbot/src/lib/shared/snackbar/snackbar.utils.ts} +49 -33
- package/projects/doohbot/src/lib/styles/_theme.scss +132 -0
- package/projects/doohbot/src/lib/styles/material-override.scss +302 -0
- package/projects/doohbot/src/lib/styles/utility.scss +588 -0
- package/projects/doohbot/src/public-api.ts +42 -0
- package/projects/doohbot/tsconfig.lib.json +15 -0
- package/projects/doohbot/tsconfig.lib.prod.json +11 -0
- package/projects/doohbot/tsconfig.spec.json +10 -0
- package/proxy.conf.json +8 -0
- package/publish.config.js +25 -0
- package/scripts/publishing/index.ts +67 -0
- package/scripts/publishing/pipeline/01-clean.ts +11 -0
- package/scripts/publishing/pipeline/02-validate-pre.ts +8 -0
- package/scripts/publishing/pipeline/03-build.ts +7 -0
- package/scripts/publishing/pipeline/04-validate-post.ts +8 -0
- package/scripts/publishing/pipeline/05-prepare-package.ts +29 -0
- package/scripts/publishing/pipeline/06-version.ts +23 -0
- package/scripts/publishing/pipeline/07-publish.ts +14 -0
- package/scripts/publishing/pipeline/08-cleanup.ts +5 -0
- package/scripts/publishing/types.ts +36 -0
- package/scripts/publishing/utils/command.ts +15 -0
- package/scripts/publishing/utils/config.ts +17 -0
- package/scripts/validate.ts +166 -0
- package/tsconfig.json +45 -0
- package/tsconfig.scripts.json +15 -0
- package/esm2022/aakash58-chatbot.mjs +0 -5
- package/esm2022/lib/app/chat/chat-ui-state.service.mjs +0 -170
- package/esm2022/lib/app/chat/chat.service.mjs +0 -445
- package/esm2022/lib/app/chat/components/chat-button/chat-button.component.mjs +0 -50
- package/esm2022/lib/app/chat/components/chat-footer/chat-footer.component.mjs +0 -12
- package/esm2022/lib/app/chat/components/chat-header/chat-header.component.mjs +0 -66
- package/esm2022/lib/app/chat/components/chat-history-sidebar/chat-history-sidebar.component.mjs +0 -186
- package/esm2022/lib/app/chat/components/chat-window/chat-window.component.mjs +0 -312
- package/esm2022/lib/app/chat/components/message-input/message-input.component.mjs +0 -36
- package/esm2022/lib/app/chat/components/message-list/message-list.component.mjs +0 -115
- package/esm2022/lib/app/chat/model/chat-history.model.mjs +0 -2
- package/esm2022/lib/app/chat/model/chat-request.model.mjs +0 -2
- package/esm2022/lib/app/chat/model/chat-response.model.mjs +0 -2
- package/esm2022/lib/app/chat/model/chat-session.model.mjs +0 -2
- package/esm2022/lib/app/chat/model/chat-stream-message.model.mjs +0 -2
- package/esm2022/lib/app/chat/model/chat-stream-response.model.mjs +0 -2
- package/esm2022/lib/app/chat/services/chat-api.service.mjs +0 -61
- package/esm2022/lib/app/chat/services/chat-audio.service.mjs +0 -50
- package/esm2022/lib/app/chat/services/chat-history.service.mjs +0 -252
- package/esm2022/lib/app/login/login-form.component.mjs +0 -46
- package/esm2022/lib/app/personalization/personalization-dialog.component.mjs +0 -194
- package/esm2022/lib/app/personalization/personalization.service.mjs +0 -149
- package/esm2022/lib/app/personalization/sections/account/account-section.component.mjs +0 -122
- package/esm2022/lib/app/personalization/sections/preferences/color-picker-dialog.component.mjs +0 -86
- package/esm2022/lib/app/personalization/sections/preferences/preferences-section.component.mjs +0 -115
- package/esm2022/lib/app/personalization/sections/profile/profile-section.component.mjs +0 -29
- package/esm2022/lib/app/personalization/sections/settings/setting-section.component.mjs +0 -30
- package/esm2022/lib/app/personalization/sections/terms/terms-section.component.mjs +0 -12
- package/esm2022/lib/constant/doohbot-constant.mjs +0 -28
- package/esm2022/lib/constant/html-entities.mjs +0 -9
- package/esm2022/lib/constant/utf8.mjs +0 -10
- package/esm2022/lib/core/app-const.mjs +0 -61
- package/esm2022/lib/core/auth/account-api.service.mjs +0 -40
- package/esm2022/lib/core/auth/auth.service.mjs +0 -391
- package/esm2022/lib/core/auth/models/auth-result.model.mjs +0 -3
- package/esm2022/lib/core/auth/models/federated-login-request.model.mjs +0 -6
- package/esm2022/lib/core/auth/models/login-request.model.mjs +0 -6
- package/esm2022/lib/core/auth/storage.service.mjs +0 -110
- package/esm2022/lib/core/directives/draggable/draggable-dialog.directive.mjs +0 -112
- package/esm2022/lib/core/directives/fullscreen/fullscreen.directive.mjs +0 -55
- package/esm2022/lib/core/directives/resizable/resizable-dialog.directive.mjs +0 -179
- package/esm2022/lib/core/environments/environment.mjs +0 -15
- package/esm2022/lib/core/environments/environment.prod.mjs +0 -15
- package/esm2022/lib/core/helpers/crypto-helper.service.mjs +0 -52
- package/esm2022/lib/core/http/http-stream.service.mjs +0 -97
- package/esm2022/lib/core/http/http.service.mjs +0 -103
- package/esm2022/lib/core/interceptors/auth.interceptor.mjs +0 -96
- package/esm2022/lib/core/interceptors/license.interceptor.mjs +0 -44
- package/esm2022/lib/core/models/api-config.model.mjs +0 -18
- package/esm2022/lib/core/models/api-request.model.mjs +0 -2
- package/esm2022/lib/core/models/api-response.model.mjs +0 -8
- package/esm2022/lib/core/models/doohbot-config.model.mjs +0 -18
- package/esm2022/lib/core/models/license.model.mjs +0 -2
- package/esm2022/lib/core/models/message.mjs +0 -2
- package/esm2022/lib/core/models/theme-config.model.mjs +0 -2
- package/esm2022/lib/core/services/core-config.service.mjs +0 -52
- package/esm2022/lib/core/services/license.service.mjs +0 -145
- package/esm2022/lib/core/services/markdown.service.mjs +0 -64
- package/esm2022/lib/core/services/theme.service.mjs +0 -248
- package/esm2022/lib/core/types/auth-mode.type.mjs +0 -2
- package/esm2022/lib/core/types/auth-status.type.mjs +0 -5
- package/esm2022/lib/core/types/chat-stream.type.mjs +0 -2
- package/esm2022/lib/core/types/message-role.type.mjs +0 -2
- package/esm2022/lib/core/types/prompt-mode.type.mjs +0 -5
- package/esm2022/lib/core/types/snackbar-error.type.mjs +0 -5
- package/esm2022/lib/core/types/tenant-resolution-strategy.type.mjs +0 -2
- package/esm2022/lib/core/utils/logger.service.mjs +0 -42
- package/esm2022/lib/doohbot-input.mjs +0 -20
- package/esm2022/lib/doohbot.component.mjs +0 -444
- package/esm2022/lib/predefined_messages.mjs +0 -15
- package/esm2022/lib/shared/chips/chips.component.mjs +0 -28
- package/esm2022/lib/shared/dialog/dialog.component.mjs +0 -36
- package/esm2022/lib/shared/dialog/dialog.service.mjs +0 -64
- package/esm2022/lib/shared/dialog/dialog.utils.mjs +0 -85
- package/esm2022/lib/shared/dropdown-menu/dropdown-menu.component.mjs +0 -29
- package/esm2022/lib/shared/input-dialog/input-dialog.component.mjs +0 -38
- package/esm2022/lib/shared/menu-item/menu-item.component.mjs +0 -24
- package/esm2022/lib/shared/pipes/simple-markdown.pipe.mjs +0 -27
- package/esm2022/lib/shared/snackbar/snackbar.component.mjs +0 -43
- package/esm2022/lib/shared/snackbar/snackbar.service.mjs +0 -46
- package/esm2022/lib/shared/snackbar/snackbar.utils.mjs +0 -43
- package/esm2022/public-api.mjs +0 -37
- package/fesm2022/aakash58-chatbot.mjs +0 -5193
- package/fesm2022/aakash58-chatbot.mjs.map +0 -1
- package/index.d.ts +0 -5
- package/lib/app/chat/chat-ui-state.service.d.ts +0 -96
- package/lib/app/chat/chat.service.d.ts +0 -88
- package/lib/app/chat/components/chat-button/chat-button.component.d.ts +0 -16
- package/lib/app/chat/components/chat-footer/chat-footer.component.d.ts +0 -5
- package/lib/app/chat/components/chat-header/chat-header.component.d.ts +0 -24
- package/lib/app/chat/components/chat-history-sidebar/chat-history-sidebar.component.d.ts +0 -49
- package/lib/app/chat/components/chat-window/chat-window.component.d.ts +0 -107
- package/lib/app/chat/components/message-input/message-input.component.d.ts +0 -12
- package/lib/app/chat/components/message-list/message-list.component.d.ts +0 -40
- package/lib/app/chat/model/chat-history.model.d.ts +0 -51
- package/lib/app/chat/model/chat-request.model.d.ts +0 -10
- package/lib/app/chat/model/chat-response.model.d.ts +0 -9
- package/lib/app/chat/model/chat-session.model.d.ts +0 -12
- package/lib/app/chat/model/chat-stream-response.model.d.ts +0 -10
- package/lib/app/chat/services/chat-api.service.d.ts +0 -30
- package/lib/app/chat/services/chat-audio.service.d.ts +0 -19
- package/lib/app/chat/services/chat-history.service.d.ts +0 -53
- package/lib/app/login/login-form.component.d.ts +0 -20
- package/lib/app/personalization/personalization-dialog.component.d.ts +0 -53
- package/lib/app/personalization/personalization.service.d.ts +0 -66
- package/lib/app/personalization/sections/account/account-section.component.d.ts +0 -30
- package/lib/app/personalization/sections/preferences/color-picker-dialog.component.d.ts +0 -17
- package/lib/app/personalization/sections/preferences/preferences-section.component.d.ts +0 -27
- package/lib/app/personalization/sections/profile/profile-section.component.d.ts +0 -17
- package/lib/app/personalization/sections/settings/setting-section.component.d.ts +0 -10
- package/lib/app/personalization/sections/terms/terms-section.component.d.ts +0 -5
- package/lib/constant/doohbot-constant.d.ts +0 -12
- package/lib/constant/html-entities.d.ts +0 -8
- package/lib/constant/utf8.d.ts +0 -9
- package/lib/core/app-const.d.ts +0 -11
- package/lib/core/auth/account-api.service.d.ts +0 -20
- package/lib/core/auth/auth.service.d.ts +0 -90
- package/lib/core/auth/models/auth-result.model.d.ts +0 -4
- package/lib/core/auth/models/federated-login-request.model.d.ts +0 -5
- package/lib/core/auth/models/login-request.model.d.ts +0 -6
- package/lib/core/auth/storage.service.d.ts +0 -21
- package/lib/core/directives/draggable/draggable-dialog.directive.d.ts +0 -23
- package/lib/core/directives/fullscreen/fullscreen.directive.d.ts +0 -14
- package/lib/core/directives/resizable/resizable-dialog.directive.d.ts +0 -30
- package/lib/core/environments/environment.d.ts +0 -7
- package/lib/core/environments/environment.prod.d.ts +0 -7
- package/lib/core/helpers/crypto-helper.service.d.ts +0 -12
- package/lib/core/http/http-stream.service.d.ts +0 -18
- package/lib/core/http/http.service.d.ts +0 -20
- package/lib/core/interceptors/auth.interceptor.d.ts +0 -18
- package/lib/core/interceptors/license.interceptor.d.ts +0 -11
- package/lib/core/models/api-config.model.d.ts +0 -58
- package/lib/core/models/api-request.model.d.ts +0 -77
- package/lib/core/models/api-response.model.d.ts +0 -6
- package/lib/core/models/doohbot-config.model.d.ts +0 -81
- package/lib/core/models/message.d.ts +0 -16
- package/lib/core/models/theme-config.model.d.ts +0 -28
- package/lib/core/services/core-config.service.d.ts +0 -23
- package/lib/core/services/license.service.d.ts +0 -33
- package/lib/core/services/markdown.service.d.ts +0 -8
- package/lib/core/services/theme.service.d.ts +0 -40
- package/lib/core/utils/logger.service.d.ts +0 -11
- package/lib/doohbot-input.d.ts +0 -19
- package/lib/doohbot.component.d.ts +0 -108
- package/lib/predefined_messages.d.ts +0 -2
- package/lib/shared/chips/chips.component.d.ts +0 -10
- package/lib/shared/dialog/dialog.component.d.ts +0 -19
- package/lib/shared/dialog/dialog.service.d.ts +0 -29
- package/lib/shared/dialog/dialog.utils.d.ts +0 -41
- package/lib/shared/dropdown-menu/dropdown-menu.component.d.ts +0 -11
- package/lib/shared/input-dialog/input-dialog.component.d.ts +0 -20
- package/lib/shared/menu-item/menu-item.component.d.ts +0 -9
- package/lib/shared/pipes/simple-markdown.pipe.d.ts +0 -10
- package/lib/shared/snackbar/snackbar.component.d.ts +0 -14
- package/lib/shared/snackbar/snackbar.service.d.ts +0 -19
- package/public-api.d.ts +0 -11
- /package/{src → projects/doohbot/src}/assets/bot.mp3 +0 -0
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
import { Injectable, signal, inject, computed } from '@angular/core';
|
|
2
|
+
import { Subscription, Subject, lastValueFrom } from 'rxjs';
|
|
3
|
+
import { ChatSession } from './model/chat-session.model';
|
|
4
|
+
import { ChatHistoryService } from './services/chat-history.service';
|
|
5
|
+
|
|
6
|
+
// Extracted Services
|
|
7
|
+
import { ChatApiService } from './services/chat-api.service';
|
|
8
|
+
import { ChatAudioService } from './services/chat-audio.service';
|
|
9
|
+
import { SnackbarUtils } from '../../shared/snackbar/snackbar.utils';
|
|
10
|
+
import { ChatApiError } from '../../core/models/api-request.model';
|
|
11
|
+
import { DOOHBOT_ADVANCED_CONFIG } from '../../core/models/doohbot-config.model';
|
|
12
|
+
import { Message } from '../../core/models/message';
|
|
13
|
+
import { PromptMode } from '../../core/types/prompt-mode.type';
|
|
14
|
+
import logger from '../../core/utils/logger.service';
|
|
15
|
+
import { ChatRequest } from './model/chat-request.model';
|
|
16
|
+
import { ChatStreamMessage } from './model/chat-stream-message.model';
|
|
17
|
+
import { AuthService } from './../../core/auth/auth.service';
|
|
18
|
+
|
|
19
|
+
import { ChatUIStateService } from './chat-ui-state.service';
|
|
20
|
+
import { PersonalizationService } from '../personalization/personalization.service';
|
|
21
|
+
|
|
22
|
+
@Injectable({
|
|
23
|
+
providedIn: 'root',
|
|
24
|
+
})
|
|
25
|
+
export class ChatService {
|
|
26
|
+
// Dependencies
|
|
27
|
+
private apiService = inject(ChatApiService);
|
|
28
|
+
private authService = inject(AuthService);
|
|
29
|
+
private audioService = inject(ChatAudioService);
|
|
30
|
+
private config = inject(DOOHBOT_ADVANCED_CONFIG, { optional: true });
|
|
31
|
+
private chatHistoryService = inject(ChatHistoryService);
|
|
32
|
+
private chatUIStateService = inject(ChatUIStateService);
|
|
33
|
+
private personalization = inject(PersonalizationService);
|
|
34
|
+
private chatSessions = this.chatHistoryService.sessions;
|
|
35
|
+
|
|
36
|
+
// Public messages signal for current context
|
|
37
|
+
public messages = signal<Message[]>([]);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Determine if suggestion chips should be shown
|
|
41
|
+
*/
|
|
42
|
+
public showSuggestionChips = computed(() => {
|
|
43
|
+
const msgs = this.messages();
|
|
44
|
+
if (msgs.length === 0) return false;
|
|
45
|
+
const lastBotMsg = [...msgs].reverse().find((m) => m.sender === 'assistant');
|
|
46
|
+
return lastBotMsg?.showSuggestions === true;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Active session
|
|
50
|
+
private activeSession: ChatSession | null = null;
|
|
51
|
+
|
|
52
|
+
// UI state signals (Keep these here as they are relevant to the Chat UI state)
|
|
53
|
+
public isLoadingApi = signal<boolean>(false);
|
|
54
|
+
public apiError = signal<ChatApiError | null>(null);
|
|
55
|
+
public isBotTyping = signal<boolean>(false);
|
|
56
|
+
public promptMode = signal<PromptMode>('markdown');
|
|
57
|
+
public isStreaming = signal<boolean>(true); //! `isStreaming` is set to true by default
|
|
58
|
+
|
|
59
|
+
messagesStream: Array<ChatStreamMessage> = [];
|
|
60
|
+
currentResponse = '';
|
|
61
|
+
|
|
62
|
+
private streamSubscription?: Subscription;
|
|
63
|
+
private cancelSubject = new Subject<void>();
|
|
64
|
+
|
|
65
|
+
getFallbackReply(): string {
|
|
66
|
+
return "I'm sorry 😔, I didn't understand that.";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
getFallbackError(): string {
|
|
70
|
+
return 'Something went wrong. Please try again.';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
constructor() {
|
|
74
|
+
logger.log('ChatService: Initialized');
|
|
75
|
+
|
|
76
|
+
// Initialize prompt mode from config if available
|
|
77
|
+
if (this.config?.promptMode) {
|
|
78
|
+
this.promptMode.set(this.config.promptMode);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//! ==================== STATE MANAGEMENT ====================
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Generate a unique session ID
|
|
86
|
+
*/
|
|
87
|
+
private generateSessionId(): string {
|
|
88
|
+
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
|
89
|
+
return `session_${crypto.randomUUID()}`;
|
|
90
|
+
}
|
|
91
|
+
return `session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Create a new chat session
|
|
96
|
+
*/
|
|
97
|
+
createSession(userId: string): ChatSession {
|
|
98
|
+
return {
|
|
99
|
+
id: this.generateSessionId(),
|
|
100
|
+
timestamp: new Date(),
|
|
101
|
+
title: 'New Conversation',
|
|
102
|
+
messages: [],
|
|
103
|
+
userId,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Start a new chat session
|
|
109
|
+
*/
|
|
110
|
+
public startNewSession(): void {
|
|
111
|
+
// this.cancelRequest(); //! Cancel any ongoing request before starting new session
|
|
112
|
+
const userId = this.authService.getUserId();
|
|
113
|
+
|
|
114
|
+
this.isBotTyping.set(false);
|
|
115
|
+
this.isLoadingApi.set(false);
|
|
116
|
+
|
|
117
|
+
this.activeSession = this.createSession(userId);
|
|
118
|
+
this.messages.set([]);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Load an existing session
|
|
123
|
+
*/
|
|
124
|
+
public loadSession(session: ChatSession): void {
|
|
125
|
+
logger.log('[ChatService] Loading session:', session.id, 'Messages:', session.messages.length);
|
|
126
|
+
this.activeSession = session;
|
|
127
|
+
this.messages.set([...session.messages]);
|
|
128
|
+
logger.log('[ChatService] Messages signal updated. Current count:', this.messages().length);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Get active session
|
|
133
|
+
*/
|
|
134
|
+
public getActiveSession(): ChatSession | null {
|
|
135
|
+
return this.activeSession;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Clear messages for current session and start new one
|
|
140
|
+
*/
|
|
141
|
+
clearMessages(): void {
|
|
142
|
+
this.messages.set([]);
|
|
143
|
+
this.startNewSession();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Add message to current session
|
|
148
|
+
*/
|
|
149
|
+
public addMessage(message: Message): void {
|
|
150
|
+
const newMessage = { ...message, timestamp: new Date() };
|
|
151
|
+
|
|
152
|
+
// Update current messages signal
|
|
153
|
+
this.messages.update((msgs) => [...msgs, newMessage]);
|
|
154
|
+
|
|
155
|
+
// Save to active session (Server handles actual storage, UI just adds to local signal for immediate feedback)
|
|
156
|
+
if (message.sender === 'assistant') {
|
|
157
|
+
this.audioService.playBotSound();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Continue a chat session
|
|
163
|
+
*/
|
|
164
|
+
public continueSession(sessionId: string): void {
|
|
165
|
+
logger.log(`[ChatService] continuing session: ${sessionId}`);
|
|
166
|
+
this.chatHistoryService.loadSessionMessages(sessionId).subscribe((messages) => {
|
|
167
|
+
const loadedMessages = messages || [];
|
|
168
|
+
const sessionFromList = this.chatSessions().find((s) => s.id === sessionId);
|
|
169
|
+
|
|
170
|
+
if (sessionFromList) {
|
|
171
|
+
sessionFromList.messages = loadedMessages;
|
|
172
|
+
this.loadSession(sessionFromList);
|
|
173
|
+
} else {
|
|
174
|
+
const timestamp =
|
|
175
|
+
loadedMessages.length > 0
|
|
176
|
+
? loadedMessages[loadedMessages.length - 1].timestamp || new Date()
|
|
177
|
+
: new Date();
|
|
178
|
+
|
|
179
|
+
const userId = this.authService.getUserId();
|
|
180
|
+
|
|
181
|
+
const newSession: ChatSession = {
|
|
182
|
+
id: sessionId,
|
|
183
|
+
timestamp: timestamp,
|
|
184
|
+
title: 'Previous Conversation',
|
|
185
|
+
messages: loadedMessages,
|
|
186
|
+
userId,
|
|
187
|
+
};
|
|
188
|
+
this.loadSession(newSession);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
this.audioService.unlockAudio();
|
|
192
|
+
this.chatUIStateService.openChat();
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
//! ==================== MESSAGE PROCESSING ====================
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Process a user message: add it, get bot reply, and add bot reply
|
|
200
|
+
*/
|
|
201
|
+
public async sendMessage(text: string, maxLength: number = 1000): Promise<void> {
|
|
202
|
+
const trimmedText = text.trim();
|
|
203
|
+
if (!trimmedText) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (trimmedText.length > maxLength) {
|
|
208
|
+
SnackbarUtils.error(`Message exceeds maximum length of ${maxLength} characters.`);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
//! Cancel any ongoing request before starting a new one
|
|
213
|
+
if (this.isBotTyping()) {
|
|
214
|
+
this.cancelRequest();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const currentSessionId = this.activeSession?.id;
|
|
218
|
+
|
|
219
|
+
this.addMessage({
|
|
220
|
+
sender: 'user',
|
|
221
|
+
text: text,
|
|
222
|
+
completed: true,
|
|
223
|
+
isHistory: false,
|
|
224
|
+
id: Date.now().toString(),
|
|
225
|
+
timestamp: new Date(),
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
this.isBotTyping.set(true);
|
|
229
|
+
|
|
230
|
+
try {
|
|
231
|
+
const response = await this.getBotReply(text);
|
|
232
|
+
|
|
233
|
+
// Check if session has changed while waiting for response
|
|
234
|
+
if (this.activeSession?.id !== currentSessionId) {
|
|
235
|
+
logger.log(
|
|
236
|
+
`[ChatService] Ignoring response for session: ${currentSessionId} as active session is now: ${this.activeSession?.id}`,
|
|
237
|
+
);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const isFallback = response === this.getFallbackReply();
|
|
242
|
+
|
|
243
|
+
// Only add completion message if it wasn't handled by streaming (response is not empty string)
|
|
244
|
+
if (response !== '') {
|
|
245
|
+
this.addMessage({
|
|
246
|
+
sender: 'assistant',
|
|
247
|
+
text: response,
|
|
248
|
+
completed: true,
|
|
249
|
+
isHistory: false,
|
|
250
|
+
id: Date.now().toString(),
|
|
251
|
+
showSuggestions: false, //! Don't show suggestions for fallback reply
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
} finally {
|
|
255
|
+
// Only reset typing if we are still in the same session, or if we want to be safe (though resetting false is usually harmless)
|
|
256
|
+
if (this.activeSession?.id === currentSessionId) {
|
|
257
|
+
this.isBotTyping.set(false);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
//! ==================== API CALLS ====================
|
|
263
|
+
|
|
264
|
+
async getBotReply(userText: string): Promise<string> {
|
|
265
|
+
logger.log('Requesting bot reply for:', userText);
|
|
266
|
+
|
|
267
|
+
try {
|
|
268
|
+
this.isLoadingApi.set(true);
|
|
269
|
+
this.apiError.set(null);
|
|
270
|
+
|
|
271
|
+
const request = this.buildChatRequest(userText);
|
|
272
|
+
|
|
273
|
+
//! chat endpoints
|
|
274
|
+
if (this.isStreaming()) {
|
|
275
|
+
return await this.stream(request);
|
|
276
|
+
} else {
|
|
277
|
+
return await this.ask(request);
|
|
278
|
+
}
|
|
279
|
+
} catch (error) {
|
|
280
|
+
SnackbarUtils.error('An error occurred while getting the bot reply.');
|
|
281
|
+
return this.getFallbackError();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Builds a chat request payload with the given user text and optional active session
|
|
287
|
+
* @param {string} userInput - The text provided by the user
|
|
288
|
+
* @returns {ChatRequest} - A chat request payload with the user text and optional active session
|
|
289
|
+
* @memberof ChatService
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
private buildChatRequest(userText: string): ChatRequest {
|
|
293
|
+
const instructions = this.personalization.getFormattedInstructions();
|
|
294
|
+
const finalQuestion = instructions ? `${instructions}\n\n${userText}` : userText;
|
|
295
|
+
|
|
296
|
+
const request: ChatRequest = {
|
|
297
|
+
question: finalQuestion,
|
|
298
|
+
organization_id: this.authService.getOrganizationId() || '',
|
|
299
|
+
prompt_mode: this.promptMode(),
|
|
300
|
+
custom_instructions: instructions,
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
if (this.activeSession && !this.activeSession.id.startsWith('session_')) {
|
|
304
|
+
request.response_id = this.activeSession.id;
|
|
305
|
+
logger.log('>>>> conversation continued:', this.activeSession.id);
|
|
306
|
+
} else {
|
|
307
|
+
logger.log('>>>> new conversation started');
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return request;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// ! Ask api endpoint
|
|
314
|
+
private async ask(request: ChatRequest): Promise<string> {
|
|
315
|
+
logger.log('>>>>Using Standard Chat Endpoint<<<<');
|
|
316
|
+
|
|
317
|
+
const responseSubject = new Subject<string>();
|
|
318
|
+
|
|
319
|
+
const currentSessionId = this.activeSession?.id;
|
|
320
|
+
|
|
321
|
+
this.streamSubscription = this.apiService.sendMessage(request, true).subscribe({
|
|
322
|
+
next: (response) => {
|
|
323
|
+
if (this.activeSession?.id === currentSessionId) {
|
|
324
|
+
this.isLoadingApi.set(false);
|
|
325
|
+
}
|
|
326
|
+
if (response?.success && response.data) {
|
|
327
|
+
if (this.activeSession?.id === currentSessionId) {
|
|
328
|
+
this.mapSessionId(response.data.id);
|
|
329
|
+
}
|
|
330
|
+
responseSubject.next(response.data.content || this.getFallbackError());
|
|
331
|
+
} else {
|
|
332
|
+
responseSubject.next(this.getFallbackError());
|
|
333
|
+
}
|
|
334
|
+
responseSubject.complete();
|
|
335
|
+
},
|
|
336
|
+
error: (error) => {
|
|
337
|
+
logger.error('Ask error:', error);
|
|
338
|
+
if (this.activeSession?.id === currentSessionId) {
|
|
339
|
+
this.isLoadingApi.set(false);
|
|
340
|
+
this.isBotTyping.set(false);
|
|
341
|
+
}
|
|
342
|
+
responseSubject.next(this.getFallbackError());
|
|
343
|
+
responseSubject.complete();
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
// Handle manual cancellation
|
|
348
|
+
const cancelSub = this.cancelSubject.subscribe(() => {
|
|
349
|
+
responseSubject.next(''); // Resolve with empty string if cancelled
|
|
350
|
+
responseSubject.complete();
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
try {
|
|
354
|
+
return await lastValueFrom(responseSubject);
|
|
355
|
+
} finally {
|
|
356
|
+
cancelSub.unsubscribe();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// ! Stream api endpoint
|
|
361
|
+
private async stream(request: ChatRequest): Promise<string> {
|
|
362
|
+
logger.log('>>>>Using Stream Chat Endpoint<<<<');
|
|
363
|
+
|
|
364
|
+
this.currentResponse = '';
|
|
365
|
+
this.isBotTyping.set(true);
|
|
366
|
+
|
|
367
|
+
const assistantMessage: Message = {
|
|
368
|
+
id: Date.now().toString(),
|
|
369
|
+
sender: 'assistant',
|
|
370
|
+
text: '',
|
|
371
|
+
chunks: [],
|
|
372
|
+
timestamp: new Date(),
|
|
373
|
+
completed: false,
|
|
374
|
+
isHistory: false,
|
|
375
|
+
showSuggestions: false,
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// Add empty bubble after first chunk has been received
|
|
379
|
+
this.addMessage(assistantMessage);
|
|
380
|
+
|
|
381
|
+
const streamComplete$ = new Subject<string>();
|
|
382
|
+
let hasStarted = false;
|
|
383
|
+
|
|
384
|
+
// Handle manual cancellation for stream
|
|
385
|
+
const cancelSub = this.cancelSubject.subscribe(() => {
|
|
386
|
+
if (!streamComplete$.closed) {
|
|
387
|
+
streamComplete$.next('');
|
|
388
|
+
streamComplete$.complete();
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
this.streamSubscription = this.apiService.sendMessageStream(request).subscribe({
|
|
393
|
+
next: (chunk) => {
|
|
394
|
+
if (!hasStarted) {
|
|
395
|
+
hasStarted = true;
|
|
396
|
+
this.isBotTyping.set(false);
|
|
397
|
+
|
|
398
|
+
// replace response_id in message id
|
|
399
|
+
this.messages.update((msgs) =>
|
|
400
|
+
msgs.map((m) =>
|
|
401
|
+
m.id === assistantMessage.id
|
|
402
|
+
? {
|
|
403
|
+
...m,
|
|
404
|
+
...{ id: chunk.id },
|
|
405
|
+
}
|
|
406
|
+
: m,
|
|
407
|
+
),
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
assistantMessage.id = chunk.id;
|
|
411
|
+
|
|
412
|
+
// Map the session ID to the backend-generated one
|
|
413
|
+
this.mapSessionId(chunk.response_id || chunk.id);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
const text = chunk.content ?? '';
|
|
417
|
+
if (!text) return;
|
|
418
|
+
|
|
419
|
+
// keep message in sync without regeneration
|
|
420
|
+
this.messages.update((msgs) =>
|
|
421
|
+
msgs.map((m) =>
|
|
422
|
+
m.id === assistantMessage.id
|
|
423
|
+
? {
|
|
424
|
+
...m,
|
|
425
|
+
chunks: [...(m.chunks ?? []), text], // immutable append
|
|
426
|
+
}
|
|
427
|
+
: m,
|
|
428
|
+
),
|
|
429
|
+
);
|
|
430
|
+
|
|
431
|
+
// const message = this.messages().find((m) => m.id === assistantMessage.id);
|
|
432
|
+
// logger.log('Appending chunk to assistant message:', message?.chunks);
|
|
433
|
+
},
|
|
434
|
+
complete: () => {
|
|
435
|
+
this.isLoadingApi.set(false);
|
|
436
|
+
|
|
437
|
+
// Mark the chunk stream compelted
|
|
438
|
+
this.messages.update((msgs) =>
|
|
439
|
+
msgs.map((m) => (m.id === assistantMessage.id ? { ...m, completed: true } : m)),
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
// const message = this.messages().find((m) => m.id === assistantMessage.id);
|
|
443
|
+
// this.currentResponse += message?.chunks?.join('') ?? '';
|
|
444
|
+
|
|
445
|
+
// logger.log('Appending chunk to assistant message:', message?.text);
|
|
446
|
+
// logger.log('Appending chunk to assistant message:', message?.chunks);
|
|
447
|
+
|
|
448
|
+
streamComplete$.next(this.currentResponse);
|
|
449
|
+
streamComplete$.complete();
|
|
450
|
+
},
|
|
451
|
+
error: (error) => {
|
|
452
|
+
logger.error('Chat error:', error);
|
|
453
|
+
SnackbarUtils.error('An error occurred during reply.');
|
|
454
|
+
|
|
455
|
+
this.isLoadingApi.set(false);
|
|
456
|
+
this.isBotTyping.set(false);
|
|
457
|
+
SnackbarUtils.error('An error occurred during reply.');
|
|
458
|
+
|
|
459
|
+
if (!hasStarted) this.addMessage(assistantMessage);
|
|
460
|
+
if (!assistantMessage.text) assistantMessage.text = this.getFallbackError();
|
|
461
|
+
|
|
462
|
+
// mark completed, do NOT rebuild content
|
|
463
|
+
this.messages.update((msgs) =>
|
|
464
|
+
msgs.map((m) =>
|
|
465
|
+
m.id === assistantMessage.id
|
|
466
|
+
? {
|
|
467
|
+
...m,
|
|
468
|
+
completed: true,
|
|
469
|
+
isHistory: false,
|
|
470
|
+
text: assistantMessage.text,
|
|
471
|
+
}
|
|
472
|
+
: m,
|
|
473
|
+
),
|
|
474
|
+
);
|
|
475
|
+
|
|
476
|
+
streamComplete$.next('');
|
|
477
|
+
streamComplete$.complete();
|
|
478
|
+
// this.finalizeStreamError(assistantMessage, hasStarted, streamComplete$);
|
|
479
|
+
},
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
try {
|
|
483
|
+
await lastValueFrom(streamComplete$);
|
|
484
|
+
} finally {
|
|
485
|
+
cancelSub.unsubscribe();
|
|
486
|
+
}
|
|
487
|
+
return '';
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
//! -----------------------------------------
|
|
491
|
+
|
|
492
|
+
cancelRequest(): void {
|
|
493
|
+
this.cancelSubject.next();
|
|
494
|
+
|
|
495
|
+
// Reset UI states immediately
|
|
496
|
+
this.isLoadingApi.set(false);
|
|
497
|
+
this.isBotTyping.set(false);
|
|
498
|
+
this.currentResponse = '';
|
|
499
|
+
|
|
500
|
+
if (this.streamSubscription) {
|
|
501
|
+
logger.log('Cancelling ongoing chat request...');
|
|
502
|
+
this.streamSubscription.unsubscribe();
|
|
503
|
+
this.streamSubscription = undefined;
|
|
504
|
+
|
|
505
|
+
// Clean up assistant messages:
|
|
506
|
+
// Remove if completely empty
|
|
507
|
+
// Mark as completed if it has content
|
|
508
|
+
this.messages.update((msgs) =>
|
|
509
|
+
msgs
|
|
510
|
+
.filter(
|
|
511
|
+
(m) =>
|
|
512
|
+
!(
|
|
513
|
+
m.sender === 'assistant' &&
|
|
514
|
+
!m.completed &&
|
|
515
|
+
!m.text &&
|
|
516
|
+
(!m.chunks || m.chunks.length === 0)
|
|
517
|
+
),
|
|
518
|
+
)
|
|
519
|
+
.map((m) => (m.sender === 'assistant' && !m.completed ? { ...m, completed: true } : m)),
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
//! ==================== AUDIO ====================
|
|
525
|
+
|
|
526
|
+
public unlockAudio(): void {
|
|
527
|
+
this.audioService.unlockAudio();
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Map local placeholder session ID to backend-generated ID
|
|
532
|
+
*/
|
|
533
|
+
private mapSessionId(responseId?: string): void {
|
|
534
|
+
if (!responseId || !this.activeSession || !this.activeSession.id.startsWith('session_')) {
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const oldId = this.activeSession.id;
|
|
539
|
+
logger.log(`[ChatService] Mapping local session ${oldId} → backend ID ${responseId}`);
|
|
540
|
+
|
|
541
|
+
// Update active session subject
|
|
542
|
+
this.activeSession.id = responseId;
|
|
543
|
+
|
|
544
|
+
// Trigger history refresh to get the server-generated title
|
|
545
|
+
this.chatHistoryService.invalidateCache();
|
|
546
|
+
}
|
|
547
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!-- fab -->
|
|
2
|
+
@if (buttonStyle === 'fab' && !isChatOpen) {
|
|
3
|
+
<button class="chat-fab" (click)="onToggle()">
|
|
4
|
+
<!-- <mat-icon>{{ chatIcon }}</mat-icon> -->
|
|
5
|
+
<img style="width: 30px; height: 30px" [src]="appLogoUrl" />
|
|
6
|
+
<!-- <div class="chat-logo"></div> -->
|
|
7
|
+
@if (unreadCount > 0) {
|
|
8
|
+
<span class="alert-badge">
|
|
9
|
+
{{ unreadCount > 9 ? '9+' : unreadCount }}
|
|
10
|
+
</span>
|
|
11
|
+
}
|
|
12
|
+
</button>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
<!-- sidebar button -->
|
|
16
|
+
@if (isSidebar && !isChatOpen) {
|
|
17
|
+
<button class="chat-sidebar" (click)="onToggle()" [ngClass]="sidebarPosition">
|
|
18
|
+
<!-- <h2 style="transform: rotate(-90deg); font-size: 16px">{{ appTitle }}</h2> -->
|
|
19
|
+
<img style="transform: rotate(-90deg); width: 100px; height: 45px" [src]="appTextLogoUrl" />
|
|
20
|
+
|
|
21
|
+
@if (unreadCount > 0) {
|
|
22
|
+
<span class="alert-badge">
|
|
23
|
+
{{ unreadCount > 9 ? '9+' : unreadCount }}
|
|
24
|
+
</span>
|
|
25
|
+
}
|
|
26
|
+
</button>
|
|
27
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/* Sidebar button */
|
|
2
|
+
.chat-sidebar {
|
|
3
|
+
position: fixed;
|
|
4
|
+
right: 0;
|
|
5
|
+
width: 40px;
|
|
6
|
+
height: 120px;
|
|
7
|
+
border-radius: 16px 0 0 16px;
|
|
8
|
+
background: var(--background-color);
|
|
9
|
+
color: var(--white);
|
|
10
|
+
border: none;
|
|
11
|
+
box-shadow: var(--border-shadow-color);
|
|
12
|
+
display: flex;
|
|
13
|
+
justify-content: center;
|
|
14
|
+
align-items: center;
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
z-index: 1000;
|
|
17
|
+
|
|
18
|
+
&.disabled {
|
|
19
|
+
background: transparent;
|
|
20
|
+
border-radius: 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
h2 {
|
|
24
|
+
margin: 0;
|
|
25
|
+
font-size: 12px;
|
|
26
|
+
transform: rotate(-90deg);
|
|
27
|
+
white-space: nowrap;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.alert-badge {
|
|
31
|
+
position: absolute;
|
|
32
|
+
bottom: 15px;
|
|
33
|
+
right: 30px;
|
|
34
|
+
width: 18px;
|
|
35
|
+
height: 18px;
|
|
36
|
+
border-radius: 50%;
|
|
37
|
+
background: var(--red);
|
|
38
|
+
color: var(--white);
|
|
39
|
+
font-size: 10px;
|
|
40
|
+
display: flex;
|
|
41
|
+
align-items: center;
|
|
42
|
+
justify-content: center;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.chat-sidebar.center {
|
|
47
|
+
top: 50%;
|
|
48
|
+
transform: translateY(-50%);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.chat-sidebar.top {
|
|
52
|
+
top: calc(50% - 45vh);
|
|
53
|
+
transform: none;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.chat-sidebar.bottom {
|
|
57
|
+
top: calc(50% + 30vh);
|
|
58
|
+
transform: none;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* Existing FAB */
|
|
62
|
+
.chat-fab {
|
|
63
|
+
position: fixed;
|
|
64
|
+
bottom: 24px;
|
|
65
|
+
right: 24px;
|
|
66
|
+
width: 56px;
|
|
67
|
+
height: 56px;
|
|
68
|
+
border-radius: 50%;
|
|
69
|
+
background: var(--background-color);
|
|
70
|
+
color: var(--white);
|
|
71
|
+
box-shadow: 0 6px 16px rgba(var(--black-rgb), 0.2);
|
|
72
|
+
border: none;
|
|
73
|
+
cursor: pointer;
|
|
74
|
+
z-index: 1000;
|
|
75
|
+
display: flex;
|
|
76
|
+
align-items: center;
|
|
77
|
+
justify-content: center;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.chat-fab svg,
|
|
81
|
+
.chat-fab mat-icon {
|
|
82
|
+
width: 24px;
|
|
83
|
+
height: 24px;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.chat-fab:hover {
|
|
87
|
+
transform: scale(1.1);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.alert-badge {
|
|
91
|
+
position: absolute;
|
|
92
|
+
top: -4px;
|
|
93
|
+
right: -4px;
|
|
94
|
+
background: var(--red);
|
|
95
|
+
color: var(--white);
|
|
96
|
+
border-radius: 50%;
|
|
97
|
+
min-width: 18px;
|
|
98
|
+
height: 18px;
|
|
99
|
+
font-size: 11px;
|
|
100
|
+
display: flex;
|
|
101
|
+
align-items: center;
|
|
102
|
+
justify-content: center;
|
|
103
|
+
font-weight: bold;
|
|
104
|
+
line-height: 1;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.chat-logo {
|
|
108
|
+
width: 45px;
|
|
109
|
+
height: 45px;
|
|
110
|
+
|
|
111
|
+
mask: url('/assets/logo.svg') no-repeat center;
|
|
112
|
+
mask-size: contain;
|
|
113
|
+
|
|
114
|
+
background-color: var(--mat-sys-on-primary);
|
|
115
|
+
}
|