@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
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { ChatbotAPI } from '../model/ChatbotApi'
|
|
2
|
+
import { createEvent, createStore, sample, createEffect, Store } from 'effector'
|
|
3
|
+
import { ChatItem } from '../types/units.types'
|
|
4
|
+
|
|
5
|
+
type ErrorSpottingProps = {
|
|
6
|
+
api: ChatbotAPI
|
|
7
|
+
$currentChatData: Store<ChatItem>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type ActiveErrorSpottingData = {
|
|
11
|
+
isActive: boolean
|
|
12
|
+
isDisabled: boolean
|
|
13
|
+
strokesIds: string[]
|
|
14
|
+
validationKey: null | string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type ErrorSpottingReducerProps = {
|
|
18
|
+
chatData: ChatItem
|
|
19
|
+
activeSpotting: ActiveErrorSpottingData | null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class ErrorSpottingModel {
|
|
23
|
+
private readonly api: ChatbotAPI
|
|
24
|
+
|
|
25
|
+
public readonly errorSpottingPressed = createEvent()
|
|
26
|
+
private readonly activeDataChanged = createEvent<
|
|
27
|
+
| ((state: ActiveErrorSpottingData | null) => ActiveErrorSpottingData | null | void)
|
|
28
|
+
| ActiveErrorSpottingData
|
|
29
|
+
| null
|
|
30
|
+
>()
|
|
31
|
+
|
|
32
|
+
public readonly $validationKey = createStore<string | null>(null)
|
|
33
|
+
public readonly $activeData = createStore<ActiveErrorSpottingData | null>(null)
|
|
34
|
+
.on(this.activeDataChanged, (state, payload) => {
|
|
35
|
+
if (typeof payload === 'function') return payload(state)
|
|
36
|
+
return payload
|
|
37
|
+
})
|
|
38
|
+
.on(this.$validationKey, (state, payload) => {
|
|
39
|
+
if (!state || payload === null) return state
|
|
40
|
+
const isDisabled = payload !== state.validationKey
|
|
41
|
+
return { ...state, isDisabled, isActive: isDisabled ? false : state.isActive }
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
public readonly $isLoading
|
|
45
|
+
|
|
46
|
+
public constructor({ api, $currentChatData }: ErrorSpottingProps) {
|
|
47
|
+
this.api = api
|
|
48
|
+
|
|
49
|
+
this.$isLoading = api.spotErrorFx.pending
|
|
50
|
+
|
|
51
|
+
this.$activeData.on($currentChatData, (state, payload) => {
|
|
52
|
+
if (!state || state.validationKey !== payload.currentThread?.key) return null
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
sample({
|
|
56
|
+
clock: api.spotErrorFx.doneData,
|
|
57
|
+
source: {
|
|
58
|
+
chatData: $currentChatData,
|
|
59
|
+
activeSpotting: this.$activeData,
|
|
60
|
+
validationKey: this.$validationKey,
|
|
61
|
+
},
|
|
62
|
+
fn: (source, result) => {
|
|
63
|
+
const key = source.chatData.currentThread?.key || null
|
|
64
|
+
const currentKey = source.validationKey
|
|
65
|
+
const isDisabled = !!currentKey && currentKey !== key
|
|
66
|
+
return {
|
|
67
|
+
validationKey: key,
|
|
68
|
+
strokesIds: result.strokesIds,
|
|
69
|
+
isActive: !isDisabled,
|
|
70
|
+
isDisabled,
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
target: this.$activeData,
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
sample({
|
|
77
|
+
clock: this.errorSpottingPressed,
|
|
78
|
+
source: {
|
|
79
|
+
chatData: $currentChatData,
|
|
80
|
+
activeSpotting: this.$activeData,
|
|
81
|
+
},
|
|
82
|
+
fn: (source) => source,
|
|
83
|
+
target: createEffect(({ chatData, activeSpotting }: ErrorSpottingReducerProps) => {
|
|
84
|
+
if (!chatData.currentThread?.strokes) return
|
|
85
|
+
if (!activeSpotting) {
|
|
86
|
+
return this.api.spotErrorFx({ strokes: chatData.currentThread.strokes })
|
|
87
|
+
}
|
|
88
|
+
this.toggleActiveSpotting()
|
|
89
|
+
}),
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private toggleActiveSpotting() {
|
|
94
|
+
this.activeDataChanged((state) => {
|
|
95
|
+
if (state) return { ...state, isActive: !state.isActive }
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public bindStrokesValidation($store: Store<string | null>) {
|
|
100
|
+
sample({
|
|
101
|
+
source: $store,
|
|
102
|
+
target: this.$validationKey,
|
|
103
|
+
})
|
|
104
|
+
return this
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public abortPendingRequest() {
|
|
108
|
+
const isPending = this.api.spotErrorFx.pending.getState()
|
|
109
|
+
if (isPending) this.api.spotErrorFx.controller.abort()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public reset() {
|
|
113
|
+
this.activeDataChanged(null)
|
|
114
|
+
this.abortPendingRequest()
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -3,11 +3,11 @@ export { ChatbotModel } from './model/ChatBotModel'
|
|
|
3
3
|
export { AudioStatus, type AudioProvider } from './types/t2s.types'
|
|
4
4
|
export {
|
|
5
5
|
MessageVariant,
|
|
6
|
-
type ConversationMessage,
|
|
7
6
|
type ChatbotRenderer,
|
|
8
7
|
type ChatbotModelProps,
|
|
9
8
|
type IChatDrawBoardAdapter,
|
|
10
9
|
} from './types/model.types'
|
|
11
|
-
export type { PostMessageResponse
|
|
12
|
-
export { ChatMessageHandler } from './model/ChatBotMessageHandler'
|
|
10
|
+
export type { PostMessageResponse } from './types/api.types'
|
|
13
11
|
export { DefaultMessagesCreator } from './model/DefaultMessageCreator'
|
|
12
|
+
export type { ChatAnswer } from './types/units.types'
|
|
13
|
+
export type { ConversationMessage } from './types/units.types'
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
attach,
|
|
3
|
+
combine,
|
|
4
|
+
createEffect,
|
|
3
5
|
createEvent,
|
|
6
|
+
createStore,
|
|
4
7
|
restore,
|
|
5
8
|
sample,
|
|
6
9
|
type Store,
|
|
7
|
-
createStore,
|
|
8
|
-
createEffect,
|
|
9
|
-
combine,
|
|
10
10
|
} from 'effector'
|
|
11
|
-
import { createControllerEffect
|
|
11
|
+
import { createControllerEffect } from '../../../lib/effector'
|
|
12
12
|
import {
|
|
13
13
|
ChatbotContext,
|
|
14
14
|
ChatbotModelProps,
|
|
15
|
-
|
|
15
|
+
IChatDrawBoardAdapter,
|
|
16
16
|
SendHelpParams,
|
|
17
17
|
SendHelpProps,
|
|
18
18
|
SetHintMessageProps,
|
|
@@ -20,20 +20,26 @@ import {
|
|
|
20
20
|
StartConversationProps,
|
|
21
21
|
} from '../types/model.types'
|
|
22
22
|
import { GetAlternativesResponse } from '../types/api.types'
|
|
23
|
-
import { ChatbotAPI } from './
|
|
23
|
+
import { ChatbotAPI } from './ChatbotApi'
|
|
24
24
|
import { ChatbotTranslation } from './translation'
|
|
25
25
|
import { ChatTextToSpeechModel } from './t2s'
|
|
26
26
|
import { AudioProvider } from '../types/t2s.types'
|
|
27
27
|
import { messagesHelper } from './messagesHelper'
|
|
28
|
+
import { ChatBotThreadManager } from './ChatBotThreadManager'
|
|
29
|
+
import { ChatsCacheModel, defaultChatData } from './ChatsCacheModel'
|
|
30
|
+
import { ErrorSpottingModel } from '../errorSpotting/ErrorSpottingModel'
|
|
28
31
|
|
|
29
32
|
type ReinitConversationProps = {
|
|
30
33
|
key: string
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
export class ChatbotModel {
|
|
34
|
-
readonly
|
|
35
|
-
readonly
|
|
36
|
-
|
|
37
|
+
public readonly threadManager: ChatBotThreadManager
|
|
38
|
+
public readonly api: ChatbotAPI
|
|
39
|
+
|
|
40
|
+
public readonly translation: ChatbotTranslation
|
|
41
|
+
public readonly t2s: ChatTextToSpeechModel
|
|
42
|
+
public readonly errorSpotting
|
|
37
43
|
|
|
38
44
|
public readonly $currentKey = createStore('')
|
|
39
45
|
|
|
@@ -55,92 +61,82 @@ export class ChatbotModel {
|
|
|
55
61
|
readonly setScrollActive = createEvent<boolean>()
|
|
56
62
|
readonly $isScrollActive = restore(this.setScrollActive, false)
|
|
57
63
|
|
|
58
|
-
readonly sendHelpRequestFx
|
|
59
|
-
|
|
60
64
|
readonly defaultMessages: ChatbotModelProps['messages']
|
|
61
|
-
|
|
62
|
-
readonly messages = createEntityFieldStore<ConversationMessage[]>()
|
|
63
|
-
readonly threadIds = createEntityFieldStore<string>()
|
|
64
|
-
readonly availableChats = createEntityFieldStore<boolean>()
|
|
65
|
+
private readonly cache = new ChatsCacheModel()
|
|
65
66
|
|
|
66
67
|
public readonly $currentChatData = combine(
|
|
67
|
-
{
|
|
68
|
-
|
|
69
|
-
threadIds: this.threadIds.$state,
|
|
70
|
-
availableChats: this.availableChats.$state,
|
|
71
|
-
key: this.$currentKey,
|
|
72
|
-
},
|
|
73
|
-
({ messages, threadIds, availableChats, key }) => {
|
|
74
|
-
return {
|
|
75
|
-
messages: messages[key] ?? [],
|
|
76
|
-
threadId: threadIds[key] ?? null,
|
|
77
|
-
isAvailable: availableChats[key] ?? false,
|
|
78
|
-
key,
|
|
79
|
-
}
|
|
80
|
-
},
|
|
68
|
+
{ data: this.cache.$data, key: this.$currentKey },
|
|
69
|
+
({ data, key }) => (data[key] ? { ...data[key], key } : { ...defaultChatData(), key }),
|
|
81
70
|
)
|
|
82
71
|
|
|
83
|
-
constructor({ api, messages, $key }: ChatbotModelProps) {
|
|
84
|
-
this.
|
|
72
|
+
constructor({ api, messages, $key, threadMessagesLimit }: ChatbotModelProps) {
|
|
73
|
+
this.threadManager = new ChatBotThreadManager({
|
|
74
|
+
api: { getHint: api.requestHint },
|
|
75
|
+
messages,
|
|
76
|
+
messagesLimit: threadMessagesLimit,
|
|
77
|
+
})
|
|
78
|
+
this.api = new ChatbotAPI({ ...api, postMessage: this.threadManager.postMessage })
|
|
85
79
|
|
|
86
80
|
this.defaultMessages = messages
|
|
87
|
-
if ($key) sample({ source: $key, target: this.$currentKey })
|
|
88
|
-
|
|
89
81
|
this.$alternatives = restore(this.api.getAlternativesFx.doneData, null)
|
|
90
82
|
.on(this.setAlternatives, (_, payload) => payload)
|
|
91
83
|
.reset(this.resetAlternatives)
|
|
92
84
|
|
|
85
|
+
this.t2s = new ChatTextToSpeechModel({ api: this.api })
|
|
93
86
|
this.translation = new ChatbotTranslation({
|
|
94
87
|
$context: this.$context,
|
|
95
88
|
defaultMessages: messages,
|
|
96
89
|
$key: this.$currentKey,
|
|
97
90
|
api: this.api,
|
|
98
|
-
messagesModel: this.messages,
|
|
99
91
|
alternativesModel: {
|
|
100
92
|
$store: this.$alternatives,
|
|
101
93
|
set: this.setAlternatives,
|
|
102
94
|
},
|
|
95
|
+
chats: this.cache,
|
|
96
|
+
})
|
|
97
|
+
this.errorSpotting = new ErrorSpottingModel({
|
|
98
|
+
api: this.api,
|
|
99
|
+
$currentChatData: this.$currentChatData,
|
|
103
100
|
})
|
|
104
101
|
|
|
105
|
-
|
|
102
|
+
if ($key) this.bindKey($key)
|
|
106
103
|
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
sample({
|
|
105
|
+
source: this.$isOpen.updates,
|
|
106
|
+
filter: (isOpen) => !isOpen,
|
|
107
|
+
target: this.t2s.reset,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
sample({
|
|
111
|
+
clock: this.removeLastMessage,
|
|
112
|
+
source: [this.$lastMessageKey, this.cache.$data] as const,
|
|
113
|
+
fn: ([lastMessageKey, chatsData]) => {
|
|
114
|
+
const chat = chatsData[lastMessageKey ?? '']
|
|
115
|
+
if (!chat) return { key: '', data: {} }
|
|
116
|
+
const updatedMessages = [...chat.messages]
|
|
117
|
+
updatedMessages.pop()
|
|
118
|
+
return { key: lastMessageKey ?? '', data: { messages: updatedMessages } }
|
|
119
|
+
},
|
|
120
|
+
filter: ([lastMessageKey]) => !!lastMessageKey,
|
|
121
|
+
target: this.cache.update,
|
|
122
|
+
})
|
|
109
123
|
}
|
|
110
124
|
|
|
111
125
|
private createSendHelpRequestFx() {
|
|
112
126
|
const effect = attach({
|
|
113
|
-
source: [
|
|
114
|
-
|
|
115
|
-
this.translation.$isTranslated,
|
|
116
|
-
this.$currentChatData,
|
|
117
|
-
this.$context,
|
|
118
|
-
],
|
|
119
|
-
mapParams: (params: SendHelpParams, [key, isTranslated, currentData, context]) => ({
|
|
127
|
+
source: [this.$currentKey, this.$context],
|
|
128
|
+
mapParams: (params: SendHelpParams, [key, context]) => ({
|
|
120
129
|
message: params.message,
|
|
121
130
|
translatedMessage: params.translatedMessage,
|
|
122
131
|
context,
|
|
123
132
|
key,
|
|
124
|
-
isTranslated,
|
|
125
|
-
threadId: currentData.threadId,
|
|
126
133
|
}),
|
|
127
134
|
effect: createControllerEffect(
|
|
128
|
-
async ({
|
|
129
|
-
message,
|
|
130
|
-
translatedMessage,
|
|
131
|
-
key,
|
|
132
|
-
isTranslated,
|
|
133
|
-
threadId,
|
|
134
|
-
context,
|
|
135
|
-
}: SendHelpProps) => {
|
|
135
|
+
async ({ message, translatedMessage, key, context }: SendHelpProps) => {
|
|
136
136
|
if (!context) throw new Error('Context is required')
|
|
137
137
|
this.setLastMessageKey(key)
|
|
138
|
-
this.
|
|
139
|
-
|
|
140
|
-
fn: (currentMessages) => [
|
|
141
|
-
...(currentMessages || []),
|
|
142
|
-
messagesHelper.createOwn({ message, translatedMessage, threadId }),
|
|
143
|
-
],
|
|
138
|
+
this.cache.addMessages(key, {
|
|
139
|
+
messages: [messagesHelper.createOwn({ message, translatedMessage })],
|
|
144
140
|
})
|
|
145
141
|
|
|
146
142
|
const response = await this.api.postMessageFx({
|
|
@@ -148,25 +144,18 @@ export class ChatbotModel {
|
|
|
148
144
|
language: context.language,
|
|
149
145
|
problemAnswer: context.problemAnswer,
|
|
150
146
|
answer: context.answer,
|
|
151
|
-
threadId,
|
|
152
147
|
imageAltText: context.imageDescription,
|
|
153
148
|
})
|
|
154
149
|
let messages = [messagesHelper.createAnswer(response)]
|
|
155
150
|
if (response.endMessage) {
|
|
156
151
|
messages.push(messagesHelper.createLast(this.defaultMessages.endMessage))
|
|
157
152
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
messages,
|
|
162
|
-
})
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
this.messages.setField({
|
|
166
|
-
key,
|
|
167
|
-
fn: (currentMessages) => [...(currentMessages || []), ...messages],
|
|
153
|
+
messages = await this.translation.applyTranslationFx({
|
|
154
|
+
targetLanguage: context.translationTargetLanguage,
|
|
155
|
+
messages,
|
|
168
156
|
})
|
|
169
|
-
|
|
157
|
+
|
|
158
|
+
this.cache.addMessages(key, { messages, thread: response.thread })
|
|
170
159
|
},
|
|
171
160
|
),
|
|
172
161
|
})
|
|
@@ -174,29 +163,39 @@ export class ChatbotModel {
|
|
|
174
163
|
sample({
|
|
175
164
|
clock: effect.fail,
|
|
176
165
|
source: this.$currentChatData,
|
|
177
|
-
fn: ({ key, messages }) => ({
|
|
166
|
+
fn: ({ key, messages }) => ({
|
|
167
|
+
key,
|
|
168
|
+
data: { messages: [...messages, this.defaultMessages.error] },
|
|
169
|
+
}),
|
|
178
170
|
filter: (_, { error }) => error.message !== 'Request aborted manually',
|
|
179
|
-
target: this.
|
|
171
|
+
target: this.cache.update,
|
|
180
172
|
})
|
|
181
173
|
|
|
182
174
|
return effect
|
|
183
175
|
}
|
|
184
176
|
|
|
185
|
-
|
|
177
|
+
public bindKey($store: Store<string>) {
|
|
186
178
|
sample({
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
fn: ([lastMessageKey, messages]) => {
|
|
190
|
-
if (!lastMessageKey) return { key: '', data: [] }
|
|
191
|
-
const updatedMessages = [...messages[lastMessageKey]]
|
|
192
|
-
updatedMessages.pop()
|
|
193
|
-
return { key: lastMessageKey, data: updatedMessages }
|
|
194
|
-
},
|
|
195
|
-
filter: ([lastMessageKey]) => !!lastMessageKey,
|
|
196
|
-
target: this.messages.setField,
|
|
179
|
+
source: $store,
|
|
180
|
+
target: this.$currentKey,
|
|
197
181
|
})
|
|
182
|
+
this.threadManager.bindKeyStore($store)
|
|
183
|
+
return this
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public setT2SAudioProvider(audioProvider: AudioProvider) {
|
|
187
|
+
this.t2s.setAudioProvider(audioProvider)
|
|
188
|
+
return this
|
|
198
189
|
}
|
|
199
190
|
|
|
191
|
+
public setDrawBoardAdapter(adapter: IChatDrawBoardAdapter) {
|
|
192
|
+
this.threadManager.setDrawBoardAdapter(adapter)
|
|
193
|
+
this.errorSpotting.bindStrokesValidation(adapter.$strokesValidationKey)
|
|
194
|
+
return this
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
public readonly sendHelpRequestFx = this.createSendHelpRequestFx()
|
|
198
|
+
|
|
200
199
|
public readonly startConversation = attach({
|
|
201
200
|
source: this.$currentChatData,
|
|
202
201
|
mapParams: (props: StartConversationProps | void, source) => ({
|
|
@@ -208,54 +207,54 @@ export class ChatbotModel {
|
|
|
208
207
|
if (initOnly) return
|
|
209
208
|
return this.reinitConversation({ key })
|
|
210
209
|
}
|
|
211
|
-
this.
|
|
212
|
-
|
|
210
|
+
this.cache.add(key, {
|
|
211
|
+
messages: [this.defaultMessages.start],
|
|
212
|
+
isAvailable: true,
|
|
213
|
+
currentThread: null,
|
|
214
|
+
})
|
|
213
215
|
}),
|
|
214
216
|
})
|
|
215
217
|
|
|
216
218
|
public setHintMessage({ key, ...message }: SetHintMessageProps) {
|
|
217
219
|
const options = this.$alternatives.getState()?.options.hints ?? message.options
|
|
218
|
-
this.
|
|
219
|
-
key,
|
|
220
|
-
fn: (messages) => {
|
|
221
|
-
if (!messages || messages.length > 1) return
|
|
222
|
-
return [{ ...message, options }]
|
|
223
|
-
},
|
|
224
|
-
})
|
|
220
|
+
this.cache.setSingleMessage(key, { ...message, options })
|
|
225
221
|
}
|
|
226
222
|
|
|
227
|
-
public readonly reinitConversation =
|
|
228
|
-
this.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (!messages?.length || messages.length === 1) return
|
|
232
|
-
const copy = [...messages]
|
|
233
|
-
while (copy.at(-1)?.endMessage) {
|
|
234
|
-
copy.pop()
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const lastMessage = copy.at(-1)
|
|
238
|
-
if (!lastMessage) return
|
|
239
|
-
|
|
240
|
-
copy.splice(copy.length - 1, 1, {
|
|
241
|
-
...lastMessage,
|
|
242
|
-
options: [this.defaultMessages.anotherHintOption],
|
|
243
|
-
})
|
|
244
|
-
return copy
|
|
245
|
-
},
|
|
246
|
-
})
|
|
247
|
-
})
|
|
223
|
+
public readonly reinitConversation = ({ key }: ReinitConversationProps) => {
|
|
224
|
+
this.cache.reinitChatThread(key, { initialOption: this.defaultMessages.anotherHintOption })
|
|
225
|
+
this.threadManager.resetThread({ key })
|
|
226
|
+
}
|
|
248
227
|
|
|
249
|
-
public
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
})
|
|
254
|
-
return this
|
|
228
|
+
public disableChat(key: string) {
|
|
229
|
+
this.t2s.stop()
|
|
230
|
+
void this.t2s.reset()
|
|
231
|
+
this.cache.disableChat(key)
|
|
255
232
|
}
|
|
256
233
|
|
|
257
|
-
public
|
|
258
|
-
|
|
259
|
-
|
|
234
|
+
public softReset = attach({
|
|
235
|
+
source: {
|
|
236
|
+
isLoading: this.sendHelpRequestFx.pending,
|
|
237
|
+
lastMessageKey: this.$lastMessageKey,
|
|
238
|
+
},
|
|
239
|
+
mapParams: (_: void, { isLoading, lastMessageKey }) => !!(isLoading && lastMessageKey),
|
|
240
|
+
effect: createEffect((hasPendingMessage: boolean) => {
|
|
241
|
+
if (hasPendingMessage) {
|
|
242
|
+
this.api.postMessageFx.controller.abort()
|
|
243
|
+
this.removeLastMessage()
|
|
244
|
+
}
|
|
245
|
+
this.errorSpotting.abortPendingRequest()
|
|
246
|
+
|
|
247
|
+
this.t2s.stop()
|
|
248
|
+
void this.t2s.reset()
|
|
249
|
+
this.translation.reset()
|
|
250
|
+
this.setScrollActive(false)
|
|
251
|
+
}),
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
public readonly reset = () => {
|
|
255
|
+
this.cache.reset()
|
|
256
|
+
this.resetAlternatives()
|
|
257
|
+
this.threadManager.resetAll()
|
|
258
|
+
this.errorSpotting.reset()
|
|
260
259
|
}
|
|
261
260
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ThreadItem } from './ThreadItem'
|
|
2
|
-
import { Store } from 'effector'
|
|
3
|
-
import { createEffect } from 'effector/effector.umd'
|
|
2
|
+
import { createStore, Store } from 'effector'
|
|
4
3
|
import {
|
|
5
4
|
ChatHintPayload,
|
|
6
5
|
ChatHintResponse,
|
|
@@ -10,10 +9,10 @@ import {
|
|
|
10
9
|
import { ChatbotMessages, IChatDrawBoardAdapter } from '../types/model.types'
|
|
11
10
|
import { CHAT_BOT_MODEL_DEFAULTS } from './constants'
|
|
12
11
|
|
|
13
|
-
type
|
|
12
|
+
type ChatBotThreadManagerProps = {
|
|
14
13
|
messagesLimit?: number
|
|
14
|
+
drawBoardAdapter?: IChatDrawBoardAdapter
|
|
15
15
|
messages: ChatbotMessages
|
|
16
|
-
drawBoardAdapter: IChatDrawBoardAdapter
|
|
17
16
|
api: {
|
|
18
17
|
getHint: (props: ChatHintPayload) => Promise<ChatHintResponse>
|
|
19
18
|
}
|
|
@@ -23,11 +22,13 @@ type ResetCacheProps = {
|
|
|
23
22
|
key: string
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
export class
|
|
25
|
+
export class ChatBotThreadManager {
|
|
27
26
|
private readonly api
|
|
28
|
-
private
|
|
27
|
+
private drawBoardAdapter: IChatDrawBoardAdapter | null = null
|
|
29
28
|
private readonly threads = new Map<string, ThreadItem>()
|
|
30
29
|
|
|
30
|
+
public readonly $threads = createStore(new Map<string, ThreadItem>())
|
|
31
|
+
|
|
31
32
|
private readonly messagesLimit
|
|
32
33
|
private currentKey = ''
|
|
33
34
|
private currentBinding: null | (() => void) = null
|
|
@@ -39,9 +40,9 @@ export class ChatMessageHandler {
|
|
|
39
40
|
api,
|
|
40
41
|
messagesLimit = CHAT_BOT_MODEL_DEFAULTS.THREAD_MESSAGES_LIMIT,
|
|
41
42
|
messages,
|
|
42
|
-
}:
|
|
43
|
+
}: ChatBotThreadManagerProps) {
|
|
43
44
|
this.api = api
|
|
44
|
-
this.drawBoardAdapter = drawBoardAdapter
|
|
45
|
+
this.drawBoardAdapter = drawBoardAdapter ?? null
|
|
45
46
|
this.messagesLimit = messagesLimit
|
|
46
47
|
this.defaultMessages = messages
|
|
47
48
|
}
|
|
@@ -58,9 +59,16 @@ export class ChatMessageHandler {
|
|
|
58
59
|
const key = this.currentKey
|
|
59
60
|
let threadItem = this.threads.get(key)
|
|
60
61
|
if (threadItem) return threadItem
|
|
62
|
+
if (!this.drawBoardAdapter) {
|
|
63
|
+
threadItem = new ThreadItem()
|
|
64
|
+
this.threads.set(key, threadItem)
|
|
65
|
+
return threadItem
|
|
66
|
+
}
|
|
61
67
|
try {
|
|
62
|
-
const
|
|
63
|
-
threadItem = new ThreadItem(
|
|
68
|
+
const result = await this.drawBoardAdapter.getVisibleStrokes()
|
|
69
|
+
threadItem = new ThreadItem(
|
|
70
|
+
result ? { strokes: result.strokes, key: result.validationKey } : null,
|
|
71
|
+
)
|
|
64
72
|
} catch {
|
|
65
73
|
threadItem = new ThreadItem()
|
|
66
74
|
}
|
|
@@ -68,7 +76,11 @@ export class ChatMessageHandler {
|
|
|
68
76
|
return threadItem
|
|
69
77
|
}
|
|
70
78
|
|
|
71
|
-
public
|
|
79
|
+
public setDrawBoardAdapter(adapter: IChatDrawBoardAdapter) {
|
|
80
|
+
this.drawBoardAdapter = adapter
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public readonly postMessage = async ({
|
|
72
84
|
problemAnswer,
|
|
73
85
|
problem,
|
|
74
86
|
answer,
|
|
@@ -86,21 +98,21 @@ export class ChatMessageHandler {
|
|
|
86
98
|
imageAltText,
|
|
87
99
|
})
|
|
88
100
|
|
|
89
|
-
threadItem.
|
|
101
|
+
threadItem.history.push(result.message)
|
|
90
102
|
const nextOptions =
|
|
91
|
-
threadItem.
|
|
103
|
+
threadItem.history.length < this.messagesLimit ? [this.defaultMessages.anotherHintOption] : []
|
|
92
104
|
|
|
93
105
|
return {
|
|
94
106
|
message: result.message,
|
|
95
107
|
options: nextOptions,
|
|
96
|
-
threadId: '',
|
|
97
108
|
endMessage: !nextOptions.length,
|
|
109
|
+
thread: threadItem.toObject(),
|
|
98
110
|
}
|
|
99
111
|
}
|
|
100
112
|
|
|
101
|
-
public resetThread =
|
|
113
|
+
public resetThread = ({ key }: ResetCacheProps) => {
|
|
102
114
|
this.threads.delete(key)
|
|
103
|
-
}
|
|
115
|
+
}
|
|
104
116
|
|
|
105
117
|
public resetAll() {
|
|
106
118
|
this.threads.clear()
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createEffect } from 'effector'
|
|
2
2
|
import { createControllerEffect } from '../../../lib/effector'
|
|
3
|
-
import {
|
|
3
|
+
import { ChatbotApiRequests, SpotErrorPayload, SpotErrorResponse } from '../types/model.types'
|
|
4
4
|
import { GoogleTranslatePayload, GoogleTranslateResponse } from '../types/api.types'
|
|
5
5
|
import { replaceKatexSyntax } from '../helpers'
|
|
6
|
+
import { getRandomElements } from '../../../lib/helpers/randomElements'
|
|
6
7
|
|
|
7
8
|
export class ChatbotAPI {
|
|
8
9
|
public readonly postMessageFx
|
|
@@ -10,7 +11,23 @@ export class ChatbotAPI {
|
|
|
10
11
|
public readonly translateTextFx
|
|
11
12
|
public readonly textToSpeechTextFx
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
public readonly spotErrorFx
|
|
15
|
+
|
|
16
|
+
constructor(api: ChatbotApiRequests) {
|
|
17
|
+
this.spotErrorFx = createControllerEffect(
|
|
18
|
+
(props: SpotErrorPayload): Promise<SpotErrorResponse> => {
|
|
19
|
+
return new Promise<SpotErrorResponse>((res) => {
|
|
20
|
+
if (props.strokes.length <= 3) return res({ strokesIds: [] })
|
|
21
|
+
setTimeout(() => {
|
|
22
|
+
const randomStrokes = getRandomElements(props.strokes, 4)
|
|
23
|
+
res({
|
|
24
|
+
strokesIds: randomStrokes.map((stroke) => stroke.id ?? ''),
|
|
25
|
+
})
|
|
26
|
+
}, 1000)
|
|
27
|
+
})
|
|
28
|
+
},
|
|
29
|
+
)
|
|
30
|
+
// this.spotErrorFx = createControllerEffect(api.spotError)
|
|
14
31
|
this.postMessageFx = createControllerEffect(api.postMessage)
|
|
15
32
|
this.getAlternativesFx = createEffect(api.getAlternatives)
|
|
16
33
|
this.translateTextFx = createEffect(
|