@magmamath/students-features 0.3.2 → 0.4.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/features/chatbot/components/ChatControls/ChatControls.js +12 -4
- package/dist/commonjs/features/chatbot/components/ChatControls/ChatControls.js.map +1 -1
- package/dist/commonjs/features/chatbot/components/ChatMessage/ChatMessage.js.map +1 -1
- package/dist/commonjs/features/chatbot/components/ChatMessage/ReceivedMessage.js +6 -4
- package/dist/commonjs/features/chatbot/components/ChatMessage/ReceivedMessage.js.map +1 -1
- package/dist/commonjs/features/chatbot/components/ChatMessages/ChatbotMessages.js +12 -1
- package/dist/commonjs/features/chatbot/components/ChatMessages/ChatbotMessages.js.map +1 -1
- package/dist/commonjs/features/chatbot/components/Chatbot.js +5 -1
- package/dist/commonjs/features/chatbot/components/Chatbot.js.map +1 -1
- package/dist/commonjs/features/chatbot/context/ChatBotContext.js +17 -0
- package/dist/commonjs/features/chatbot/context/ChatBotContext.js.map +1 -0
- package/dist/commonjs/features/chatbot/errorSpotting/ErrorSpottingButton.js +58 -0
- package/dist/commonjs/features/chatbot/errorSpotting/ErrorSpottingButton.js.map +1 -0
- package/dist/commonjs/features/chatbot/errorSpotting/ErrorSpottingModel.js +99 -0
- package/dist/commonjs/features/chatbot/errorSpotting/ErrorSpottingModel.js.map +1 -0
- package/dist/commonjs/features/chatbot/index.js +0 -7
- package/dist/commonjs/features/chatbot/index.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/ChatBotModel.js +136 -117
- package/dist/commonjs/features/chatbot/model/ChatBotModel.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/{ChatBotMessageHandler.js → ChatBotThreadManager.js} +28 -17
- package/dist/commonjs/features/chatbot/model/ChatBotThreadManager.js.map +1 -0
- package/dist/commonjs/features/chatbot/model/{api.js → ChatbotApi.js} +16 -1
- package/dist/commonjs/features/chatbot/model/ChatbotApi.js.map +1 -0
- package/dist/commonjs/features/chatbot/model/ChatsCacheModel.js +110 -0
- package/dist/commonjs/features/chatbot/model/ChatsCacheModel.js.map +1 -0
- package/dist/commonjs/features/chatbot/model/DefaultMessageCreator.js +0 -1
- package/dist/commonjs/features/chatbot/model/DefaultMessageCreator.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/ThreadItem.js +21 -8
- package/dist/commonjs/features/chatbot/model/ThreadItem.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/messagesHelper.js +1 -5
- package/dist/commonjs/features/chatbot/model/messagesHelper.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/t2s.js +0 -6
- package/dist/commonjs/features/chatbot/model/t2s.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/translation.helpers.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/translation.js +54 -45
- package/dist/commonjs/features/chatbot/model/translation.js.map +1 -1
- package/dist/commonjs/features/chatbot/types/api.types.js +4 -0
- package/dist/commonjs/features/chatbot/types/model.types.js.map +1 -1
- package/dist/commonjs/features/chatbot/types/units.types.js +2 -0
- package/dist/commonjs/features/chatbot/types/units.types.js.map +1 -0
- package/dist/commonjs/features/feedback/components/TeacherFeedbackButton/colorSchemes.js +18 -9
- package/dist/commonjs/features/feedback/components/TeacherFeedbackButton/colorSchemes.js.map +1 -1
- package/dist/commonjs/lib/effector/createEntityFieldStore.js +4 -0
- package/dist/commonjs/lib/effector/createEntityFieldStore.js.map +1 -1
- package/dist/commonjs/lib/helpers/randomElements.js +24 -0
- package/dist/commonjs/lib/helpers/randomElements.js.map +1 -0
- package/dist/commonjs/shared/icons/HighlighterIcon.js +36 -0
- package/dist/commonjs/shared/icons/HighlighterIcon.js.map +1 -0
- package/dist/commonjs/shared/icons/StopIcon.js +33 -0
- package/dist/commonjs/shared/icons/StopIcon.js.map +1 -0
- package/dist/commonjs/shared/icons/icon.types.js +4 -0
- package/dist/module/features/chatbot/components/ChatControls/ChatControls.js +12 -4
- package/dist/module/features/chatbot/components/ChatControls/ChatControls.js.map +1 -1
- package/dist/module/features/chatbot/components/ChatMessage/ChatMessage.js.map +1 -1
- package/dist/module/features/chatbot/components/ChatMessage/ReceivedMessage.js +6 -4
- package/dist/module/features/chatbot/components/ChatMessage/ReceivedMessage.js.map +1 -1
- package/dist/module/features/chatbot/components/ChatMessages/ChatbotMessages.js +12 -1
- package/dist/module/features/chatbot/components/ChatMessages/ChatbotMessages.js.map +1 -1
- package/dist/module/features/chatbot/components/Chatbot.js +6 -2
- package/dist/module/features/chatbot/components/Chatbot.js.map +1 -1
- package/dist/module/features/chatbot/context/ChatBotContext.js +12 -0
- package/dist/module/features/chatbot/context/ChatBotContext.js.map +1 -0
- package/dist/module/features/chatbot/errorSpotting/ErrorSpottingButton.js +52 -0
- package/dist/module/features/chatbot/errorSpotting/ErrorSpottingButton.js.map +1 -0
- package/dist/module/features/chatbot/errorSpotting/ErrorSpottingModel.js +94 -0
- package/dist/module/features/chatbot/errorSpotting/ErrorSpottingModel.js.map +1 -0
- package/dist/module/features/chatbot/index.js +0 -1
- package/dist/module/features/chatbot/index.js.map +1 -1
- package/dist/module/features/chatbot/model/ChatBotModel.js +138 -119
- package/dist/module/features/chatbot/model/ChatBotModel.js.map +1 -1
- package/dist/module/features/chatbot/model/{ChatBotMessageHandler.js → ChatBotThreadManager.js} +26 -15
- package/dist/module/features/chatbot/model/ChatBotThreadManager.js.map +1 -0
- package/dist/module/features/chatbot/model/{api.js → ChatbotApi.js} +16 -1
- package/dist/module/features/chatbot/model/ChatbotApi.js.map +1 -0
- package/dist/module/features/chatbot/model/ChatsCacheModel.js +104 -0
- package/dist/module/features/chatbot/model/ChatsCacheModel.js.map +1 -0
- package/dist/module/features/chatbot/model/DefaultMessageCreator.js +0 -1
- package/dist/module/features/chatbot/model/DefaultMessageCreator.js.map +1 -1
- package/dist/module/features/chatbot/model/ThreadItem.js +21 -8
- package/dist/module/features/chatbot/model/ThreadItem.js.map +1 -1
- package/dist/module/features/chatbot/model/messagesHelper.js +1 -5
- package/dist/module/features/chatbot/model/messagesHelper.js.map +1 -1
- package/dist/module/features/chatbot/model/t2s.js +1 -7
- package/dist/module/features/chatbot/model/t2s.js.map +1 -1
- package/dist/module/features/chatbot/model/translation.helpers.js.map +1 -1
- package/dist/module/features/chatbot/model/translation.js +54 -45
- package/dist/module/features/chatbot/model/translation.js.map +1 -1
- package/dist/module/features/chatbot/types/api.types.js +2 -0
- package/dist/module/features/chatbot/types/model.types.js.map +1 -1
- package/dist/module/features/chatbot/types/units.types.js +2 -0
- package/dist/module/features/chatbot/types/units.types.js.map +1 -0
- package/dist/module/features/feedback/components/TeacherFeedbackButton/colorSchemes.js +18 -9
- package/dist/module/features/feedback/components/TeacherFeedbackButton/colorSchemes.js.map +1 -1
- package/dist/module/lib/effector/createEntityFieldStore.js +4 -0
- package/dist/module/lib/effector/createEntityFieldStore.js.map +1 -1
- package/dist/module/lib/helpers/randomElements.js +20 -0
- package/dist/module/lib/helpers/randomElements.js.map +1 -0
- package/dist/module/shared/icons/HighlighterIcon.js +29 -0
- package/dist/module/shared/icons/HighlighterIcon.js.map +1 -0
- package/dist/module/shared/icons/StopIcon.js +26 -0
- package/dist/module/shared/icons/StopIcon.js.map +1 -0
- package/dist/module/shared/icons/icon.types.js +2 -0
- package/dist/typescript/commonjs/features/chatbot/components/ChatControls/ChatControls.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/components/ChatMessage/ChatMessage.d.ts +1 -0
- package/dist/typescript/commonjs/features/chatbot/components/ChatMessage/ChatMessage.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/components/ChatMessage/ReceivedMessage.d.ts +1 -1
- package/dist/typescript/commonjs/features/chatbot/components/ChatMessage/ReceivedMessage.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/components/ChatMessages/ChatbotMessages.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/components/Chatbot.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/context/ChatBotContext.d.ts +8 -0
- package/dist/typescript/commonjs/features/chatbot/context/ChatBotContext.d.ts.map +1 -0
- package/dist/typescript/commonjs/features/chatbot/errorSpotting/ErrorSpottingButton.d.ts +3 -0
- package/dist/typescript/commonjs/features/chatbot/errorSpotting/ErrorSpottingButton.d.ts.map +1 -0
- package/dist/typescript/commonjs/features/chatbot/errorSpotting/ErrorSpottingModel.d.ts +28 -0
- package/dist/typescript/commonjs/features/chatbot/errorSpotting/ErrorSpottingModel.d.ts.map +1 -0
- package/dist/typescript/commonjs/features/chatbot/index.d.ts +4 -3
- package/dist/typescript/commonjs/features/chatbot/index.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/model/ChatBotModel.d.ts +19 -14
- package/dist/typescript/commonjs/features/chatbot/model/ChatBotModel.d.ts.map +1 -1
- package/dist/typescript/{module/features/chatbot/model/ChatBotMessageHandler.d.ts → commonjs/features/chatbot/model/ChatBotThreadManager.d.ts} +11 -8
- package/dist/typescript/commonjs/features/chatbot/model/ChatBotThreadManager.d.ts.map +1 -0
- package/dist/typescript/commonjs/features/chatbot/model/{api.d.ts → ChatbotApi.d.ts} +4 -3
- package/dist/typescript/commonjs/features/chatbot/model/ChatbotApi.d.ts.map +1 -0
- package/dist/typescript/commonjs/features/chatbot/model/ChatsCacheModel.d.ts +26 -0
- package/dist/typescript/commonjs/features/chatbot/model/ChatsCacheModel.d.ts.map +1 -0
- package/dist/typescript/commonjs/features/chatbot/model/DefaultMessageCreator.d.ts +3 -2
- package/dist/typescript/commonjs/features/chatbot/model/DefaultMessageCreator.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/model/ThreadItem.d.ts +12 -6
- package/dist/typescript/commonjs/features/chatbot/model/ThreadItem.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/model/messagesHelper.d.ts +3 -4
- package/dist/typescript/commonjs/features/chatbot/model/messagesHelper.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/model/t2s.d.ts +2 -4
- package/dist/typescript/commonjs/features/chatbot/model/t2s.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/model/translation.d.ts +7 -8
- package/dist/typescript/commonjs/features/chatbot/model/translation.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/model/translation.helpers.d.ts +2 -1
- package/dist/typescript/commonjs/features/chatbot/model/translation.helpers.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/types/api.types.d.ts +2 -11
- package/dist/typescript/commonjs/features/chatbot/types/api.types.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/types/model.types.d.ts +26 -19
- package/dist/typescript/commonjs/features/chatbot/types/model.types.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/types/translation.types.d.ts +2 -1
- package/dist/typescript/commonjs/features/chatbot/types/translation.types.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/types/units.types.d.ts +31 -0
- package/dist/typescript/commonjs/features/chatbot/types/units.types.d.ts.map +1 -0
- package/dist/typescript/commonjs/features/feedback/components/TeacherFeedbackButton/colorSchemes.d.ts.map +1 -1
- package/dist/typescript/commonjs/lib/effector/createEntityFieldStore.d.ts +2 -0
- package/dist/typescript/commonjs/lib/effector/createEntityFieldStore.d.ts.map +1 -1
- package/dist/typescript/commonjs/lib/helpers/randomElements.d.ts +2 -0
- package/dist/typescript/commonjs/lib/helpers/randomElements.d.ts.map +1 -0
- package/dist/typescript/commonjs/shared/icons/HighlighterIcon.d.ts +4 -0
- package/dist/typescript/commonjs/shared/icons/HighlighterIcon.d.ts.map +1 -0
- package/dist/typescript/commonjs/shared/icons/StopIcon.d.ts +4 -0
- package/dist/typescript/commonjs/shared/icons/StopIcon.d.ts.map +1 -0
- package/dist/typescript/commonjs/shared/icons/icon.types.d.ts +2 -0
- package/dist/typescript/commonjs/shared/icons/icon.types.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/components/ChatControls/ChatControls.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/components/ChatMessage/ChatMessage.d.ts +1 -0
- package/dist/typescript/module/features/chatbot/components/ChatMessage/ChatMessage.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/components/ChatMessage/ReceivedMessage.d.ts +1 -1
- package/dist/typescript/module/features/chatbot/components/ChatMessage/ReceivedMessage.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/components/ChatMessages/ChatbotMessages.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/components/Chatbot.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/context/ChatBotContext.d.ts +8 -0
- package/dist/typescript/module/features/chatbot/context/ChatBotContext.d.ts.map +1 -0
- package/dist/typescript/module/features/chatbot/errorSpotting/ErrorSpottingButton.d.ts +3 -0
- package/dist/typescript/module/features/chatbot/errorSpotting/ErrorSpottingButton.d.ts.map +1 -0
- package/dist/typescript/module/features/chatbot/errorSpotting/ErrorSpottingModel.d.ts +28 -0
- package/dist/typescript/module/features/chatbot/errorSpotting/ErrorSpottingModel.d.ts.map +1 -0
- package/dist/typescript/module/features/chatbot/index.d.ts +4 -3
- package/dist/typescript/module/features/chatbot/index.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/model/ChatBotModel.d.ts +19 -14
- package/dist/typescript/module/features/chatbot/model/ChatBotModel.d.ts.map +1 -1
- package/dist/typescript/{commonjs/features/chatbot/model/ChatBotMessageHandler.d.ts → module/features/chatbot/model/ChatBotThreadManager.d.ts} +11 -8
- package/dist/typescript/module/features/chatbot/model/ChatBotThreadManager.d.ts.map +1 -0
- package/dist/typescript/module/features/chatbot/model/{api.d.ts → ChatbotApi.d.ts} +4 -3
- package/dist/typescript/module/features/chatbot/model/ChatbotApi.d.ts.map +1 -0
- package/dist/typescript/module/features/chatbot/model/ChatsCacheModel.d.ts +26 -0
- package/dist/typescript/module/features/chatbot/model/ChatsCacheModel.d.ts.map +1 -0
- package/dist/typescript/module/features/chatbot/model/DefaultMessageCreator.d.ts +3 -2
- package/dist/typescript/module/features/chatbot/model/DefaultMessageCreator.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/model/ThreadItem.d.ts +12 -6
- package/dist/typescript/module/features/chatbot/model/ThreadItem.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/model/messagesHelper.d.ts +3 -4
- package/dist/typescript/module/features/chatbot/model/messagesHelper.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/model/t2s.d.ts +2 -4
- package/dist/typescript/module/features/chatbot/model/t2s.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/model/translation.d.ts +7 -8
- package/dist/typescript/module/features/chatbot/model/translation.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/model/translation.helpers.d.ts +2 -1
- package/dist/typescript/module/features/chatbot/model/translation.helpers.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/types/api.types.d.ts +2 -11
- package/dist/typescript/module/features/chatbot/types/api.types.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/types/model.types.d.ts +26 -19
- package/dist/typescript/module/features/chatbot/types/model.types.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/types/translation.types.d.ts +2 -1
- package/dist/typescript/module/features/chatbot/types/translation.types.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/types/units.types.d.ts +31 -0
- package/dist/typescript/module/features/chatbot/types/units.types.d.ts.map +1 -0
- package/dist/typescript/module/features/feedback/components/TeacherFeedbackButton/colorSchemes.d.ts.map +1 -1
- package/dist/typescript/module/lib/effector/createEntityFieldStore.d.ts +2 -0
- package/dist/typescript/module/lib/effector/createEntityFieldStore.d.ts.map +1 -1
- package/dist/typescript/module/lib/helpers/randomElements.d.ts +2 -0
- package/dist/typescript/module/lib/helpers/randomElements.d.ts.map +1 -0
- package/dist/typescript/module/shared/icons/HighlighterIcon.d.ts +4 -0
- package/dist/typescript/module/shared/icons/HighlighterIcon.d.ts.map +1 -0
- package/dist/typescript/module/shared/icons/StopIcon.d.ts +4 -0
- package/dist/typescript/module/shared/icons/StopIcon.d.ts.map +1 -0
- package/dist/typescript/module/shared/icons/icon.types.d.ts +2 -0
- package/dist/typescript/module/shared/icons/icon.types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/features/chatbot/components/ChatControls/ChatControls.tsx +10 -3
- package/src/features/chatbot/components/ChatMessage/ChatMessage.tsx +1 -0
- package/src/features/chatbot/components/ChatMessage/ReceivedMessage.tsx +3 -0
- package/src/features/chatbot/components/ChatMessages/ChatbotMessages.tsx +14 -0
- package/src/features/chatbot/components/Chatbot.tsx +3 -2
- package/src/features/chatbot/context/ChatBotContext.ts +18 -0
- package/src/features/chatbot/errorSpotting/ErrorSpottingButton.tsx +53 -0
- package/src/features/chatbot/errorSpotting/ErrorSpottingModel.ts +116 -0
- package/src/features/chatbot/index.ts +3 -3
- package/src/features/chatbot/model/ChatBotModel.ts +123 -124
- package/src/features/chatbot/model/{ChatBotMessageHandler.ts → ChatBotThreadManager.ts} +28 -16
- package/src/features/chatbot/model/{api.ts → ChatbotApi.ts} +19 -2
- package/src/features/chatbot/model/ChatsCacheModel.ts +94 -0
- package/src/features/chatbot/model/DefaultMessageCreator.ts +3 -3
- package/src/features/chatbot/model/ThreadItem.ts +20 -9
- package/src/features/chatbot/model/messagesHelper.ts +2 -6
- package/src/features/chatbot/model/t2s.ts +3 -10
- package/src/features/chatbot/model/translation.helpers.ts +2 -1
- package/src/features/chatbot/model/translation.ts +52 -46
- package/src/features/chatbot/types/api.types.ts +2 -12
- package/src/features/chatbot/types/model.types.ts +38 -26
- package/src/features/chatbot/types/translation.types.ts +2 -1
- package/src/features/chatbot/types/units.types.ts +34 -0
- package/src/features/feedback/components/TeacherFeedbackButton/colorSchemes.ts +9 -0
- package/src/lib/effector/createEntityFieldStore.ts +9 -1
- package/src/lib/helpers/randomElements.ts +22 -0
- package/src/shared/icons/HighlighterIcon.tsx +21 -0
- package/src/shared/icons/StopIcon.tsx +17 -0
- package/src/shared/icons/icon.types.ts +9 -6
- package/dist/commonjs/features/chatbot/model/ChatBotMessageHandler.js.map +0 -1
- package/dist/commonjs/features/chatbot/model/api.js.map +0 -1
- package/dist/module/features/chatbot/model/ChatBotMessageHandler.js.map +0 -1
- package/dist/module/features/chatbot/model/api.js.map +0 -1
- package/dist/typescript/commonjs/features/chatbot/model/ChatBotMessageHandler.d.ts.map +0 -1
- package/dist/typescript/commonjs/features/chatbot/model/api.d.ts.map +0 -1
- package/dist/typescript/module/features/chatbot/model/ChatBotMessageHandler.d.ts.map +0 -1
- package/dist/typescript/module/features/chatbot/model/api.d.ts.map +0 -1
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { attach,
|
|
4
|
-
import { createControllerEffect
|
|
5
|
-
import { ChatbotAPI } from "./
|
|
3
|
+
import { attach, combine, createEffect, createEvent, createStore, restore, sample } from 'effector';
|
|
4
|
+
import { createControllerEffect } from "../../../lib/effector/index.js";
|
|
5
|
+
import { ChatbotAPI } from "./ChatbotApi.js";
|
|
6
6
|
import { ChatbotTranslation } from "./translation.js";
|
|
7
7
|
import { ChatTextToSpeechModel } from "./t2s.js";
|
|
8
8
|
import { messagesHelper } from "./messagesHelper.js";
|
|
9
|
+
import { ChatBotThreadManager } from "./ChatBotThreadManager.js";
|
|
10
|
+
import { ChatsCacheModel, defaultChatData } from "./ChatsCacheModel.js";
|
|
11
|
+
import { ErrorSpottingModel } from "../errorSpotting/ErrorSpottingModel.js";
|
|
9
12
|
export class ChatbotModel {
|
|
10
13
|
$currentKey = createStore('');
|
|
11
14
|
resetAlternatives = createEvent();
|
|
@@ -20,84 +23,106 @@ export class ChatbotModel {
|
|
|
20
23
|
$context = restore(this.setContext, null);
|
|
21
24
|
setScrollActive = createEvent();
|
|
22
25
|
$isScrollActive = restore(this.setScrollActive, false);
|
|
23
|
-
|
|
24
|
-
threadIds = createEntityFieldStore();
|
|
25
|
-
availableChats = createEntityFieldStore();
|
|
26
|
+
cache = new ChatsCacheModel();
|
|
26
27
|
$currentChatData = combine({
|
|
27
|
-
|
|
28
|
-
threadIds: this.threadIds.$state,
|
|
29
|
-
availableChats: this.availableChats.$state,
|
|
28
|
+
data: this.cache.$data,
|
|
30
29
|
key: this.$currentKey
|
|
31
30
|
}, ({
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
data,
|
|
32
|
+
key
|
|
33
|
+
}) => data[key] ? {
|
|
34
|
+
...data[key],
|
|
35
|
+
key
|
|
36
|
+
} : {
|
|
37
|
+
...defaultChatData(),
|
|
35
38
|
key
|
|
36
|
-
}) => {
|
|
37
|
-
return {
|
|
38
|
-
messages: messages[key] ?? [],
|
|
39
|
-
threadId: threadIds[key] ?? null,
|
|
40
|
-
isAvailable: availableChats[key] ?? false,
|
|
41
|
-
key
|
|
42
|
-
};
|
|
43
39
|
});
|
|
44
40
|
constructor({
|
|
45
41
|
api,
|
|
46
42
|
messages,
|
|
47
|
-
$key
|
|
43
|
+
$key,
|
|
44
|
+
threadMessagesLimit
|
|
48
45
|
}) {
|
|
49
|
-
this.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
this.threadManager = new ChatBotThreadManager({
|
|
47
|
+
api: {
|
|
48
|
+
getHint: api.requestHint
|
|
49
|
+
},
|
|
50
|
+
messages,
|
|
51
|
+
messagesLimit: threadMessagesLimit
|
|
52
|
+
});
|
|
53
|
+
this.api = new ChatbotAPI({
|
|
54
|
+
...api,
|
|
55
|
+
postMessage: this.threadManager.postMessage
|
|
54
56
|
});
|
|
57
|
+
this.defaultMessages = messages;
|
|
55
58
|
this.$alternatives = restore(this.api.getAlternativesFx.doneData, null).on(this.setAlternatives, (_, payload) => payload).reset(this.resetAlternatives);
|
|
59
|
+
this.t2s = new ChatTextToSpeechModel({
|
|
60
|
+
api: this.api
|
|
61
|
+
});
|
|
56
62
|
this.translation = new ChatbotTranslation({
|
|
57
63
|
$context: this.$context,
|
|
58
64
|
defaultMessages: messages,
|
|
59
65
|
$key: this.$currentKey,
|
|
60
66
|
api: this.api,
|
|
61
|
-
messagesModel: this.messages,
|
|
62
67
|
alternativesModel: {
|
|
63
68
|
$store: this.$alternatives,
|
|
64
69
|
set: this.setAlternatives
|
|
65
|
-
}
|
|
70
|
+
},
|
|
71
|
+
chats: this.cache
|
|
66
72
|
});
|
|
67
|
-
this.
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
this.errorSpotting = new ErrorSpottingModel({
|
|
74
|
+
api: this.api,
|
|
75
|
+
$currentChatData: this.$currentChatData
|
|
76
|
+
});
|
|
77
|
+
if ($key) this.bindKey($key);
|
|
78
|
+
sample({
|
|
79
|
+
source: this.$isOpen.updates,
|
|
80
|
+
filter: isOpen => !isOpen,
|
|
81
|
+
target: this.t2s.reset
|
|
82
|
+
});
|
|
83
|
+
sample({
|
|
84
|
+
clock: this.removeLastMessage,
|
|
85
|
+
source: [this.$lastMessageKey, this.cache.$data],
|
|
86
|
+
fn: ([lastMessageKey, chatsData]) => {
|
|
87
|
+
const chat = chatsData[lastMessageKey ?? ''];
|
|
88
|
+
if (!chat) return {
|
|
89
|
+
key: '',
|
|
90
|
+
data: {}
|
|
91
|
+
};
|
|
92
|
+
const updatedMessages = [...chat.messages];
|
|
93
|
+
updatedMessages.pop();
|
|
94
|
+
return {
|
|
95
|
+
key: lastMessageKey ?? '',
|
|
96
|
+
data: {
|
|
97
|
+
messages: updatedMessages
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
filter: ([lastMessageKey]) => !!lastMessageKey,
|
|
102
|
+
target: this.cache.update
|
|
70
103
|
});
|
|
71
|
-
this.sendHelpRequestFx = this.createSendHelpRequestFx();
|
|
72
|
-
this.initChatReplyWatcher();
|
|
73
104
|
}
|
|
74
105
|
createSendHelpRequestFx() {
|
|
75
106
|
const effect = attach({
|
|
76
|
-
source: [this.$currentKey, this
|
|
77
|
-
mapParams: (params, [key,
|
|
107
|
+
source: [this.$currentKey, this.$context],
|
|
108
|
+
mapParams: (params, [key, context]) => ({
|
|
78
109
|
message: params.message,
|
|
79
110
|
translatedMessage: params.translatedMessage,
|
|
80
111
|
context,
|
|
81
|
-
key
|
|
82
|
-
isTranslated,
|
|
83
|
-
threadId: currentData.threadId
|
|
112
|
+
key
|
|
84
113
|
}),
|
|
85
114
|
effect: createControllerEffect(async ({
|
|
86
115
|
message,
|
|
87
116
|
translatedMessage,
|
|
88
117
|
key,
|
|
89
|
-
isTranslated,
|
|
90
|
-
threadId,
|
|
91
118
|
context
|
|
92
119
|
}) => {
|
|
93
120
|
if (!context) throw new Error('Context is required');
|
|
94
121
|
this.setLastMessageKey(key);
|
|
95
|
-
this.
|
|
96
|
-
|
|
97
|
-
fn: currentMessages => [...(currentMessages || []), messagesHelper.createOwn({
|
|
122
|
+
this.cache.addMessages(key, {
|
|
123
|
+
messages: [messagesHelper.createOwn({
|
|
98
124
|
message,
|
|
99
|
-
translatedMessage
|
|
100
|
-
threadId
|
|
125
|
+
translatedMessage
|
|
101
126
|
})]
|
|
102
127
|
});
|
|
103
128
|
const response = await this.api.postMessageFx({
|
|
@@ -105,26 +130,19 @@ export class ChatbotModel {
|
|
|
105
130
|
language: context.language,
|
|
106
131
|
problemAnswer: context.problemAnswer,
|
|
107
132
|
answer: context.answer,
|
|
108
|
-
threadId,
|
|
109
133
|
imageAltText: context.imageDescription
|
|
110
134
|
});
|
|
111
135
|
let messages = [messagesHelper.createAnswer(response)];
|
|
112
136
|
if (response.endMessage) {
|
|
113
137
|
messages.push(messagesHelper.createLast(this.defaultMessages.endMessage));
|
|
114
138
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
messages
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
this.messages.setField({
|
|
122
|
-
key,
|
|
123
|
-
fn: currentMessages => [...(currentMessages || []), ...messages]
|
|
139
|
+
messages = await this.translation.applyTranslationFx({
|
|
140
|
+
targetLanguage: context.translationTargetLanguage,
|
|
141
|
+
messages
|
|
124
142
|
});
|
|
125
|
-
this.
|
|
126
|
-
|
|
127
|
-
|
|
143
|
+
this.cache.addMessages(key, {
|
|
144
|
+
messages,
|
|
145
|
+
thread: response.thread
|
|
128
146
|
});
|
|
129
147
|
})
|
|
130
148
|
});
|
|
@@ -136,35 +154,35 @@ export class ChatbotModel {
|
|
|
136
154
|
messages
|
|
137
155
|
}) => ({
|
|
138
156
|
key,
|
|
139
|
-
data:
|
|
157
|
+
data: {
|
|
158
|
+
messages: [...messages, this.defaultMessages.error]
|
|
159
|
+
}
|
|
140
160
|
}),
|
|
141
161
|
filter: (_, {
|
|
142
162
|
error
|
|
143
163
|
}) => error.message !== 'Request aborted manually',
|
|
144
|
-
target: this.
|
|
164
|
+
target: this.cache.update
|
|
145
165
|
});
|
|
146
166
|
return effect;
|
|
147
167
|
}
|
|
148
|
-
|
|
168
|
+
bindKey($store) {
|
|
149
169
|
sample({
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
fn: ([lastMessageKey, messages]) => {
|
|
153
|
-
if (!lastMessageKey) return {
|
|
154
|
-
key: '',
|
|
155
|
-
data: []
|
|
156
|
-
};
|
|
157
|
-
const updatedMessages = [...messages[lastMessageKey]];
|
|
158
|
-
updatedMessages.pop();
|
|
159
|
-
return {
|
|
160
|
-
key: lastMessageKey,
|
|
161
|
-
data: updatedMessages
|
|
162
|
-
};
|
|
163
|
-
},
|
|
164
|
-
filter: ([lastMessageKey]) => !!lastMessageKey,
|
|
165
|
-
target: this.messages.setField
|
|
170
|
+
source: $store,
|
|
171
|
+
target: this.$currentKey
|
|
166
172
|
});
|
|
173
|
+
this.threadManager.bindKeyStore($store);
|
|
174
|
+
return this;
|
|
167
175
|
}
|
|
176
|
+
setT2SAudioProvider(audioProvider) {
|
|
177
|
+
this.t2s.setAudioProvider(audioProvider);
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
setDrawBoardAdapter(adapter) {
|
|
181
|
+
this.threadManager.setDrawBoardAdapter(adapter);
|
|
182
|
+
this.errorSpotting.bindStrokesValidation(adapter.$strokesValidationKey);
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
sendHelpRequestFx = this.createSendHelpRequestFx();
|
|
168
186
|
startConversation = attach({
|
|
169
187
|
source: this.$currentChatData,
|
|
170
188
|
mapParams: (props, source) => ({
|
|
@@ -182,13 +200,10 @@ export class ChatbotModel {
|
|
|
182
200
|
key
|
|
183
201
|
});
|
|
184
202
|
}
|
|
185
|
-
this.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
this.availableChats.setField({
|
|
190
|
-
key,
|
|
191
|
-
data: true
|
|
203
|
+
this.cache.add(key, {
|
|
204
|
+
messages: [this.defaultMessages.start],
|
|
205
|
+
isAvailable: true,
|
|
206
|
+
currentThread: null
|
|
192
207
|
});
|
|
193
208
|
})
|
|
194
209
|
});
|
|
@@ -197,48 +212,52 @@ export class ChatbotModel {
|
|
|
197
212
|
...message
|
|
198
213
|
}) {
|
|
199
214
|
const options = this.$alternatives.getState()?.options.hints ?? message.options;
|
|
200
|
-
this.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (!messages || messages.length > 1) return;
|
|
204
|
-
return [{
|
|
205
|
-
...message,
|
|
206
|
-
options
|
|
207
|
-
}];
|
|
208
|
-
}
|
|
215
|
+
this.cache.setSingleMessage(key, {
|
|
216
|
+
...message,
|
|
217
|
+
options
|
|
209
218
|
});
|
|
210
219
|
}
|
|
211
|
-
reinitConversation =
|
|
220
|
+
reinitConversation = ({
|
|
212
221
|
key
|
|
213
222
|
}) => {
|
|
214
|
-
this.
|
|
215
|
-
|
|
216
|
-
fn: messages => {
|
|
217
|
-
if (!messages?.length || messages.length === 1) return;
|
|
218
|
-
const copy = [...messages];
|
|
219
|
-
while (copy.at(-1)?.endMessage) {
|
|
220
|
-
copy.pop();
|
|
221
|
-
}
|
|
222
|
-
const lastMessage = copy.at(-1);
|
|
223
|
-
if (!lastMessage) return;
|
|
224
|
-
copy.splice(copy.length - 1, 1, {
|
|
225
|
-
...lastMessage,
|
|
226
|
-
options: [this.defaultMessages.anotherHintOption]
|
|
227
|
-
});
|
|
228
|
-
return copy;
|
|
229
|
-
}
|
|
223
|
+
this.cache.reinitChatThread(key, {
|
|
224
|
+
initialOption: this.defaultMessages.anotherHintOption
|
|
230
225
|
});
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
sample({
|
|
234
|
-
source: $store,
|
|
235
|
-
target: this.$currentKey
|
|
226
|
+
this.threadManager.resetThread({
|
|
227
|
+
key
|
|
236
228
|
});
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
this.t2s.
|
|
241
|
-
|
|
229
|
+
};
|
|
230
|
+
disableChat(key) {
|
|
231
|
+
this.t2s.stop();
|
|
232
|
+
void this.t2s.reset();
|
|
233
|
+
this.cache.disableChat(key);
|
|
242
234
|
}
|
|
235
|
+
softReset = attach({
|
|
236
|
+
source: {
|
|
237
|
+
isLoading: this.sendHelpRequestFx.pending,
|
|
238
|
+
lastMessageKey: this.$lastMessageKey
|
|
239
|
+
},
|
|
240
|
+
mapParams: (_, {
|
|
241
|
+
isLoading,
|
|
242
|
+
lastMessageKey
|
|
243
|
+
}) => !!(isLoading && lastMessageKey),
|
|
244
|
+
effect: createEffect(hasPendingMessage => {
|
|
245
|
+
if (hasPendingMessage) {
|
|
246
|
+
this.api.postMessageFx.controller.abort();
|
|
247
|
+
this.removeLastMessage();
|
|
248
|
+
}
|
|
249
|
+
this.errorSpotting.abortPendingRequest();
|
|
250
|
+
this.t2s.stop();
|
|
251
|
+
void this.t2s.reset();
|
|
252
|
+
this.translation.reset();
|
|
253
|
+
this.setScrollActive(false);
|
|
254
|
+
})
|
|
255
|
+
});
|
|
256
|
+
reset = () => {
|
|
257
|
+
this.cache.reset();
|
|
258
|
+
this.resetAlternatives();
|
|
259
|
+
this.threadManager.resetAll();
|
|
260
|
+
this.errorSpotting.reset();
|
|
261
|
+
};
|
|
243
262
|
}
|
|
244
263
|
//# sourceMappingURL=ChatBotModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["attach","
|
|
1
|
+
{"version":3,"names":["attach","combine","createEffect","createEvent","createStore","restore","sample","createControllerEffect","ChatbotAPI","ChatbotTranslation","ChatTextToSpeechModel","messagesHelper","ChatBotThreadManager","ChatsCacheModel","defaultChatData","ErrorSpottingModel","ChatbotModel","$currentKey","resetAlternatives","setAlternatives","setIsOpen","toggleOpen","$isOpen","on","isOpen","removeLastMessage","setLastMessageKey","$lastMessageKey","setContext","$context","setScrollActive","$isScrollActive","cache","$currentChatData","data","$data","key","constructor","api","messages","$key","threadMessagesLimit","threadManager","getHint","requestHint","messagesLimit","postMessage","defaultMessages","$alternatives","getAlternativesFx","doneData","_","payload","reset","t2s","translation","alternativesModel","$store","set","chats","errorSpotting","bindKey","source","updates","filter","target","clock","fn","lastMessageKey","chatsData","chat","updatedMessages","pop","update","createSendHelpRequestFx","effect","mapParams","params","context","message","translatedMessage","Error","addMessages","createOwn","response","postMessageFx","problem","language","problemAnswer","answer","imageAltText","imageDescription","createAnswer","endMessage","push","createLast","applyTranslationFx","targetLanguage","translationTargetLanguage","thread","fail","error","bindKeyStore","setT2SAudioProvider","audioProvider","setAudioProvider","setDrawBoardAdapter","adapter","bindStrokesValidation","$strokesValidationKey","sendHelpRequestFx","startConversation","props","initOnly","length","reinitConversation","add","start","isAvailable","currentThread","setHintMessage","options","getState","hints","setSingleMessage","reinitChatThread","initialOption","anotherHintOption","resetThread","disableChat","stop","softReset","isLoading","pending","hasPendingMessage","controller","abort","abortPendingRequest","resetAll"],"sourceRoot":"../../../../../src","sources":["features/chatbot/model/ChatBotModel.ts"],"mappings":";;AAAA,SACEA,MAAM,EACNC,OAAO,EACPC,YAAY,EACZC,WAAW,EACXC,WAAW,EACXC,OAAO,EACPC,MAAM,QAED,UAAU;AACjB,SAASC,sBAAsB,QAAQ,gCAAuB;AAY9D,SAASC,UAAU,QAAQ,iBAAc;AACzC,SAASC,kBAAkB,QAAQ,kBAAe;AAClD,SAASC,qB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AAC;IAC7B,IAAI,CAAC9E,aAAa,CAACP,KAAK,CAAC,CAAC;EAC5B,CAAC;AACH","ignoreList":[]}
|
package/dist/module/features/chatbot/model/{ChatBotMessageHandler.js → ChatBotThreadManager.js}
RENAMED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { ThreadItem } from "./ThreadItem.js";
|
|
4
|
-
import {
|
|
4
|
+
import { createStore } from 'effector';
|
|
5
5
|
import { CHAT_BOT_MODEL_DEFAULTS } from "./constants.js";
|
|
6
|
-
export class
|
|
6
|
+
export class ChatBotThreadManager {
|
|
7
|
+
drawBoardAdapter = null;
|
|
7
8
|
threads = new Map();
|
|
9
|
+
$threads = createStore(new Map());
|
|
8
10
|
currentKey = '';
|
|
9
11
|
currentBinding = null;
|
|
10
12
|
constructor({
|
|
@@ -14,7 +16,7 @@ export class ChatMessageHandler {
|
|
|
14
16
|
messages
|
|
15
17
|
}) {
|
|
16
18
|
this.api = api;
|
|
17
|
-
this.drawBoardAdapter = drawBoardAdapter;
|
|
19
|
+
this.drawBoardAdapter = drawBoardAdapter ?? null;
|
|
18
20
|
this.messagesLimit = messagesLimit;
|
|
19
21
|
this.defaultMessages = messages;
|
|
20
22
|
}
|
|
@@ -29,18 +31,27 @@ export class ChatMessageHandler {
|
|
|
29
31
|
const key = this.currentKey;
|
|
30
32
|
let threadItem = this.threads.get(key);
|
|
31
33
|
if (threadItem) return threadItem;
|
|
34
|
+
if (!this.drawBoardAdapter) {
|
|
35
|
+
threadItem = new ThreadItem();
|
|
36
|
+
this.threads.set(key, threadItem);
|
|
37
|
+
return threadItem;
|
|
38
|
+
}
|
|
32
39
|
try {
|
|
33
|
-
const
|
|
34
|
-
threadItem = new ThreadItem({
|
|
35
|
-
strokes
|
|
36
|
-
|
|
40
|
+
const result = await this.drawBoardAdapter.getVisibleStrokes();
|
|
41
|
+
threadItem = new ThreadItem(result ? {
|
|
42
|
+
strokes: result.strokes,
|
|
43
|
+
key: result.validationKey
|
|
44
|
+
} : null);
|
|
37
45
|
} catch {
|
|
38
46
|
threadItem = new ThreadItem();
|
|
39
47
|
}
|
|
40
48
|
this.threads.set(key, threadItem);
|
|
41
49
|
return threadItem;
|
|
42
50
|
}
|
|
43
|
-
|
|
51
|
+
setDrawBoardAdapter(adapter) {
|
|
52
|
+
this.drawBoardAdapter = adapter;
|
|
53
|
+
}
|
|
54
|
+
postMessage = async ({
|
|
44
55
|
problemAnswer,
|
|
45
56
|
problem,
|
|
46
57
|
answer,
|
|
@@ -56,22 +67,22 @@ export class ChatMessageHandler {
|
|
|
56
67
|
language,
|
|
57
68
|
imageAltText
|
|
58
69
|
});
|
|
59
|
-
threadItem.
|
|
60
|
-
const nextOptions = threadItem.
|
|
70
|
+
threadItem.history.push(result.message);
|
|
71
|
+
const nextOptions = threadItem.history.length < this.messagesLimit ? [this.defaultMessages.anotherHintOption] : [];
|
|
61
72
|
return {
|
|
62
73
|
message: result.message,
|
|
63
74
|
options: nextOptions,
|
|
64
|
-
|
|
65
|
-
|
|
75
|
+
endMessage: !nextOptions.length,
|
|
76
|
+
thread: threadItem.toObject()
|
|
66
77
|
};
|
|
67
78
|
};
|
|
68
|
-
resetThread =
|
|
79
|
+
resetThread = ({
|
|
69
80
|
key
|
|
70
81
|
}) => {
|
|
71
82
|
this.threads.delete(key);
|
|
72
|
-
}
|
|
83
|
+
};
|
|
73
84
|
resetAll() {
|
|
74
85
|
this.threads.clear();
|
|
75
86
|
}
|
|
76
87
|
}
|
|
77
|
-
//# sourceMappingURL=
|
|
88
|
+
//# sourceMappingURL=ChatBotThreadManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ThreadItem","createStore","CHAT_BOT_MODEL_DEFAULTS","ChatBotThreadManager","drawBoardAdapter","threads","Map","$threads","currentKey","currentBinding","constructor","api","messagesLimit","THREAD_MESSAGES_LIMIT","messages","defaultMessages","bindKeyStore","$store","watch","value","getThreadItem","key","threadItem","get","set","result","getVisibleStrokes","strokes","validationKey","setDrawBoardAdapter","adapter","postMessage","problemAnswer","problem","answer","language","imageAltText","getHint","getNextHintProps","correctAnswer","problemDescription","userAnswer","history","push","message","nextOptions","length","anotherHintOption","options","endMessage","thread","toObject","resetThread","delete","resetAll","clear"],"sourceRoot":"../../../../../src","sources":["features/chatbot/model/ChatBotThreadManager.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,iBAAc;AACzC,SAASC,WAAW,QAAe,UAAU;AAQ7C,SAASC,uBAAuB,QAAQ,gBAAa;AAerD,OAAO,MAAMC,oBAAoB,CAAC;EAExBC,gBAAgB,GAAiC,IAAI;EAC5CC,OAAO,GAAG,IAAIC,GAAG,CAAqB,CAAC;EAExCC,QAAQ,GAAGN,WAAW,CAAC,IAAIK,GAAG,CAAqB,CAAC,CAAC;EAG7DE,UAAU,GAAG,EAAE;EACfC,cAAc,GAAwB,IAAI;EAI3CC,WAAWA,CAAC;IACjBN,gBAAgB;IAChBO,GAAG;IACHC,aAAa,GAAGV,uBAAuB,CAACW,qBAAqB;IAC7DC;EACyB,CAAC,EAAE;IAC5B,IAAI,CAACH,GAAG,GAAGA,GAAG;IACd,IAAI,CAACP,gBAAgB,GAAGA,gBAAgB,IAAI,IAAI;IAChD,IAAI,CAACQ,aAAa,GAAGA,aAAa;IAClC,IAAI,CAACG,eAAe,GAAGD,QAAQ;EACjC;EAEOE,YAAYA,CAACC,MAAqB,EAAE;IACzC,IAAI,CAACR,cAAc,GAAG,CAAC;IACvB,IAAI,CAACA,cAAc,GAAGQ,MAAM,CAACC,KAAK,CAAEC,KAAK,IAAK;MAC5C,IAAI,CAACX,UAAU,GAAGW,KAAK;IACzB,CAAC,CAAC;IACF,OAAO,IAAI;EACb;EAEA,MAAcC,aAAaA,CAAA,EAAG;IAC5B,MAAMC,GAAG,GAAG,IAAI,CAACb,UAAU;IAC3B,IAAIc,UAAU,GAAG,IAAI,CAACjB,OAAO,CAACkB,GAAG,CAACF,GAAG,CAAC;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,UAAU,CAACoB,OAAO,CAACI,MAAM,GAAG,IAAI,CAAClC,aAAa,GAAG,CAAC,IAAI,CAACG,eAAe,CAACgC,iBAAiB,CAAC,GAAG,EAAE;IAEhG,OAAO;MACLH,OAAO,EAAEnB,MAAM,CAACmB,OAAO;MACvBI,OAAO,EAAEH,WAAW;MACpBI,UAAU,EAAE,CAACJ,WAAW,CAACC,MAAM;MAC/BI,MAAM,EAAE5B,UAAU,CAAC6B,QAAQ,CAAC;IAC9B,CAAC;EACH,CAAC;EAEMC,WAAW,GAAGA,CAAC;IAAE/B;EAAqB,CAAC,KAAK;IACjD,IAAI,CAAChB,OAAO,CAACgD,MAAM,CAAChC,GAAG,CAAC;EAC1B,CAAC;EAEMiC,QAAQA,CAAA,EAAG;IAChB,IAAI,CAACjD,OAAO,CAACkD,KAAK,CAAC,CAAC;EACtB;AACF","ignoreList":[]}
|
|
@@ -3,8 +3,23 @@
|
|
|
3
3
|
import { createEffect } from 'effector';
|
|
4
4
|
import { createControllerEffect } from "../../../lib/effector/index.js";
|
|
5
5
|
import { replaceKatexSyntax } from "../helpers.js";
|
|
6
|
+
import { getRandomElements } from "../../../lib/helpers/randomElements.js";
|
|
6
7
|
export class ChatbotAPI {
|
|
7
8
|
constructor(api) {
|
|
9
|
+
this.spotErrorFx = createControllerEffect(props => {
|
|
10
|
+
return new Promise(res => {
|
|
11
|
+
if (props.strokes.length <= 3) return res({
|
|
12
|
+
strokesIds: []
|
|
13
|
+
});
|
|
14
|
+
setTimeout(() => {
|
|
15
|
+
const randomStrokes = getRandomElements(props.strokes, 4);
|
|
16
|
+
res({
|
|
17
|
+
strokesIds: randomStrokes.map(stroke => stroke.id ?? '')
|
|
18
|
+
});
|
|
19
|
+
}, 1000);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
// this.spotErrorFx = createControllerEffect(api.spotError)
|
|
8
23
|
this.postMessageFx = createControllerEffect(api.postMessage);
|
|
9
24
|
this.getAlternativesFx = createEffect(api.getAlternatives);
|
|
10
25
|
this.translateTextFx = createEffect(async payload => {
|
|
@@ -26,4 +41,4 @@ export class ChatbotAPI {
|
|
|
26
41
|
this.textToSpeechTextFx = createEffect(api.postTextToSpeech);
|
|
27
42
|
}
|
|
28
43
|
}
|
|
29
|
-
//# sourceMappingURL=
|
|
44
|
+
//# sourceMappingURL=ChatbotApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createEffect","createControllerEffect","replaceKatexSyntax","getRandomElements","ChatbotAPI","constructor","api","spotErrorFx","props","Promise","res","strokes","length","strokesIds","setTimeout","randomStrokes","map","stroke","id","postMessageFx","postMessage","getAlternativesFx","getAlternatives","translateTextFx","payload","response","postTranslateText","text","data","translations","translation","translatedText","textToSpeechTextFx","postTextToSpeech"],"sourceRoot":"../../../../../src","sources":["features/chatbot/model/ChatbotApi.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,UAAU;AACvC,SAASC,sBAAsB,QAAQ,gCAAuB;AAG9D,SAASC,kBAAkB,QAAQ,eAAY;AAC/C,SAASC,iBAAiB,QAAQ,wCAAqC;AAEvE,OAAO,MAAMC,UAAU,CAAC;EAQtBC,WAAWA,CAACC,GAAuB,EAAE;IACnC,IAAI,CAACC,WAAW,GAAGN,sBAAsB,CACtCO,KAAuB,IAAiC;MACvD,OAAO,IAAIC,OAAO,CAAqBC,GAAG,IAAK;QAC7C,IAAIF,KAAK,CAACG,OAAO,CAACC,MAAM,IAAI,CAAC,EAAE,OAAOF,GAAG,CAAC;UAAEG,UAAU,EAAE;QAAG,CAAC,CAAC;QAC7DC,UAAU,CAAC,MAAM;UACf,MAAMC,aAAa,GAAGZ,iBAAiB,CAACK,KAAK,CAACG,OAAO,EAAE,CAAC,CAAC;UACzDD,GAAG,CAAC;YACFG,UAAU,EAAEE,aAAa,CAACC,GAAG,CAAEC,MAAM,IAAKA,MAAM,CAACC,EAAE,IAAI,EAAE;UAC3D,CAAC,CAAC;QACJ,CAAC,EAAE,IAAI,CAAC;MACV,CAAC,CAAC;IACJ,CACF,CAAC;IACD;IACA,IAAI,CAACC,aAAa,GAAGlB,sBAAsB,CAACK,GAAG,CAACc,WAAW,CAAC;IAC5D,IAAI,CAACC,iBAAiB,GAAGrB,YAAY,CAACM,GAAG,CAACgB,eAAe,CAAC;IAC1D,IAAI,CAACC,eAAe,GAAGvB,YAAY,CACjC,MAAOwB,OAA+B,IAAuC;MAC3E,MAAMC,QAAQ,GAAG,MAAMnB,GAAG,CAACoB,iBAAiB,CAAC;QAC3C,GAAGF,OAAO;QACVG,IAAI,EAAEzB,kBAAkB,CAACsB,OAAO,CAACG,IAAI;MACvC,CAAC,CAAC;MAEF,OAAO;QACL,GAAGF,QAAQ;QACXG,IAAI,EAAE;UACJ,GAAGH,QAAQ,CAACG,IAAI;UAChBC,YAAY,EAAEJ,QAAQ,CAACG,IAAI,CAACC,YAAY,CAACb,GAAG,CAAEc,WAAW,KAAM;YAC7D,GAAGA,WAAW;YACdC,cAAc,EAAE7B,kBAAkB,CAAC,CAAC4B,WAAW,CAACC,cAAc,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;UAC1E,CAAC,CAAC;QACJ;MACF,CAAC;IACH,CACF,CAAC;IACD,IAAI,CAACC,kBAAkB,GAAGhC,YAAY,CAACM,GAAG,CAAC2B,gBAAgB,CAAC;EAC9D;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { createEvent } from 'effector';
|
|
4
|
+
import { createEntityFieldStore } from "../../../lib/effector/index.js";
|
|
5
|
+
export function defaultChatData(props = {}) {
|
|
6
|
+
return {
|
|
7
|
+
messages: [],
|
|
8
|
+
isAvailable: false,
|
|
9
|
+
currentThread: null,
|
|
10
|
+
...props
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export class ChatsCacheModel {
|
|
14
|
+
update = createEvent();
|
|
15
|
+
cache = createEntityFieldStore().on(this.update, (state, {
|
|
16
|
+
key,
|
|
17
|
+
data
|
|
18
|
+
}) => {
|
|
19
|
+
const currentData = state[key] ?? defaultChatData();
|
|
20
|
+
return {
|
|
21
|
+
...state,
|
|
22
|
+
[key]: {
|
|
23
|
+
...currentData,
|
|
24
|
+
...data
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
$data = this.cache.$state;
|
|
29
|
+
reset = this.cache.reset;
|
|
30
|
+
disableChat(key) {
|
|
31
|
+
this.cache.setField({
|
|
32
|
+
key,
|
|
33
|
+
fn: current => current ? {
|
|
34
|
+
...current,
|
|
35
|
+
isAvailable: false
|
|
36
|
+
} : defaultChatData({
|
|
37
|
+
isAvailable: false
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
reinitChatThread(key, {
|
|
42
|
+
initialOption
|
|
43
|
+
}) {
|
|
44
|
+
this.cache.setField({
|
|
45
|
+
key,
|
|
46
|
+
fn: current => {
|
|
47
|
+
if (!current || current.messages.length <= 1) return;
|
|
48
|
+
const copy = [...current.messages];
|
|
49
|
+
while (copy.at(-1)?.endMessage) {
|
|
50
|
+
copy.pop();
|
|
51
|
+
}
|
|
52
|
+
const lastMessage = copy.at(-1);
|
|
53
|
+
if (!lastMessage) return;
|
|
54
|
+
copy.splice(copy.length - 1, 1, {
|
|
55
|
+
...lastMessage,
|
|
56
|
+
options: [initialOption]
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
...current,
|
|
60
|
+
messages: copy
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
setSingleMessage(key, message) {
|
|
66
|
+
this.cache.setField({
|
|
67
|
+
key,
|
|
68
|
+
fn: current => {
|
|
69
|
+
if (!current || current.messages.length > 1) return;
|
|
70
|
+
return {
|
|
71
|
+
...current,
|
|
72
|
+
messages: [message]
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
addMessages(key, {
|
|
78
|
+
messages,
|
|
79
|
+
thread = null
|
|
80
|
+
}) {
|
|
81
|
+
this.cache.setField({
|
|
82
|
+
key,
|
|
83
|
+
fn: current => {
|
|
84
|
+
if (!current) return defaultChatData({
|
|
85
|
+
messages,
|
|
86
|
+
currentThread: thread
|
|
87
|
+
});
|
|
88
|
+
const result = {
|
|
89
|
+
...current,
|
|
90
|
+
messages: [...current.messages, ...messages]
|
|
91
|
+
};
|
|
92
|
+
if (thread) result.currentThread = thread;
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
add(key, data) {
|
|
98
|
+
this.cache.setField({
|
|
99
|
+
key,
|
|
100
|
+
data
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=ChatsCacheModel.js.map
|