@magmamath/students-features 0.3.3 → 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.
Files changed (234) hide show
  1. package/dist/commonjs/features/chatbot/components/ChatMessage/ChatMessage.js.map +1 -1
  2. package/dist/commonjs/features/chatbot/components/ChatMessage/ReceivedMessage.js +6 -4
  3. package/dist/commonjs/features/chatbot/components/ChatMessage/ReceivedMessage.js.map +1 -1
  4. package/dist/commonjs/features/chatbot/components/ChatMessages/ChatbotMessages.js +12 -1
  5. package/dist/commonjs/features/chatbot/components/ChatMessages/ChatbotMessages.js.map +1 -1
  6. package/dist/commonjs/features/chatbot/components/Chatbot.js +5 -1
  7. package/dist/commonjs/features/chatbot/components/Chatbot.js.map +1 -1
  8. package/dist/commonjs/features/chatbot/context/ChatBotContext.js +17 -0
  9. package/dist/commonjs/features/chatbot/context/ChatBotContext.js.map +1 -0
  10. package/dist/commonjs/features/chatbot/errorSpotting/ErrorSpottingButton.js +58 -0
  11. package/dist/commonjs/features/chatbot/errorSpotting/ErrorSpottingButton.js.map +1 -0
  12. package/dist/commonjs/features/chatbot/errorSpotting/ErrorSpottingModel.js +99 -0
  13. package/dist/commonjs/features/chatbot/errorSpotting/ErrorSpottingModel.js.map +1 -0
  14. package/dist/commonjs/features/chatbot/index.js +0 -7
  15. package/dist/commonjs/features/chatbot/index.js.map +1 -1
  16. package/dist/commonjs/features/chatbot/model/ChatBotModel.js +136 -117
  17. package/dist/commonjs/features/chatbot/model/ChatBotModel.js.map +1 -1
  18. package/dist/commonjs/features/chatbot/model/{ChatBotMessageHandler.js → ChatBotThreadManager.js} +28 -17
  19. package/dist/commonjs/features/chatbot/model/ChatBotThreadManager.js.map +1 -0
  20. package/dist/commonjs/features/chatbot/model/{api.js → ChatbotApi.js} +16 -1
  21. package/dist/commonjs/features/chatbot/model/ChatbotApi.js.map +1 -0
  22. package/dist/commonjs/features/chatbot/model/ChatsCacheModel.js +110 -0
  23. package/dist/commonjs/features/chatbot/model/ChatsCacheModel.js.map +1 -0
  24. package/dist/commonjs/features/chatbot/model/DefaultMessageCreator.js +0 -1
  25. package/dist/commonjs/features/chatbot/model/DefaultMessageCreator.js.map +1 -1
  26. package/dist/commonjs/features/chatbot/model/ThreadItem.js +21 -8
  27. package/dist/commonjs/features/chatbot/model/ThreadItem.js.map +1 -1
  28. package/dist/commonjs/features/chatbot/model/messagesHelper.js +1 -5
  29. package/dist/commonjs/features/chatbot/model/messagesHelper.js.map +1 -1
  30. package/dist/commonjs/features/chatbot/model/t2s.js +0 -6
  31. package/dist/commonjs/features/chatbot/model/t2s.js.map +1 -1
  32. package/dist/commonjs/features/chatbot/model/translation.helpers.js.map +1 -1
  33. package/dist/commonjs/features/chatbot/model/translation.js +54 -45
  34. package/dist/commonjs/features/chatbot/model/translation.js.map +1 -1
  35. package/dist/commonjs/features/chatbot/types/api.types.js +4 -0
  36. package/dist/commonjs/features/chatbot/types/model.types.js.map +1 -1
  37. package/dist/commonjs/features/chatbot/types/units.types.js +2 -0
  38. package/dist/commonjs/features/chatbot/types/units.types.js.map +1 -0
  39. package/dist/commonjs/lib/effector/createEntityFieldStore.js +4 -0
  40. package/dist/commonjs/lib/effector/createEntityFieldStore.js.map +1 -1
  41. package/dist/commonjs/lib/helpers/randomElements.js +24 -0
  42. package/dist/commonjs/lib/helpers/randomElements.js.map +1 -0
  43. package/dist/commonjs/shared/icons/HighlighterIcon.js +36 -0
  44. package/dist/commonjs/shared/icons/HighlighterIcon.js.map +1 -0
  45. package/dist/commonjs/shared/icons/StopIcon.js +33 -0
  46. package/dist/commonjs/shared/icons/StopIcon.js.map +1 -0
  47. package/dist/commonjs/shared/icons/icon.types.js +4 -0
  48. package/dist/module/features/chatbot/components/ChatMessage/ChatMessage.js.map +1 -1
  49. package/dist/module/features/chatbot/components/ChatMessage/ReceivedMessage.js +6 -4
  50. package/dist/module/features/chatbot/components/ChatMessage/ReceivedMessage.js.map +1 -1
  51. package/dist/module/features/chatbot/components/ChatMessages/ChatbotMessages.js +12 -1
  52. package/dist/module/features/chatbot/components/ChatMessages/ChatbotMessages.js.map +1 -1
  53. package/dist/module/features/chatbot/components/Chatbot.js +6 -2
  54. package/dist/module/features/chatbot/components/Chatbot.js.map +1 -1
  55. package/dist/module/features/chatbot/context/ChatBotContext.js +12 -0
  56. package/dist/module/features/chatbot/context/ChatBotContext.js.map +1 -0
  57. package/dist/module/features/chatbot/errorSpotting/ErrorSpottingButton.js +52 -0
  58. package/dist/module/features/chatbot/errorSpotting/ErrorSpottingButton.js.map +1 -0
  59. package/dist/module/features/chatbot/errorSpotting/ErrorSpottingModel.js +94 -0
  60. package/dist/module/features/chatbot/errorSpotting/ErrorSpottingModel.js.map +1 -0
  61. package/dist/module/features/chatbot/index.js +0 -1
  62. package/dist/module/features/chatbot/index.js.map +1 -1
  63. package/dist/module/features/chatbot/model/ChatBotModel.js +138 -119
  64. package/dist/module/features/chatbot/model/ChatBotModel.js.map +1 -1
  65. package/dist/module/features/chatbot/model/{ChatBotMessageHandler.js → ChatBotThreadManager.js} +26 -15
  66. package/dist/module/features/chatbot/model/ChatBotThreadManager.js.map +1 -0
  67. package/dist/module/features/chatbot/model/{api.js → ChatbotApi.js} +16 -1
  68. package/dist/module/features/chatbot/model/ChatbotApi.js.map +1 -0
  69. package/dist/module/features/chatbot/model/ChatsCacheModel.js +104 -0
  70. package/dist/module/features/chatbot/model/ChatsCacheModel.js.map +1 -0
  71. package/dist/module/features/chatbot/model/DefaultMessageCreator.js +0 -1
  72. package/dist/module/features/chatbot/model/DefaultMessageCreator.js.map +1 -1
  73. package/dist/module/features/chatbot/model/ThreadItem.js +21 -8
  74. package/dist/module/features/chatbot/model/ThreadItem.js.map +1 -1
  75. package/dist/module/features/chatbot/model/messagesHelper.js +1 -5
  76. package/dist/module/features/chatbot/model/messagesHelper.js.map +1 -1
  77. package/dist/module/features/chatbot/model/t2s.js +1 -7
  78. package/dist/module/features/chatbot/model/t2s.js.map +1 -1
  79. package/dist/module/features/chatbot/model/translation.helpers.js.map +1 -1
  80. package/dist/module/features/chatbot/model/translation.js +54 -45
  81. package/dist/module/features/chatbot/model/translation.js.map +1 -1
  82. package/dist/module/features/chatbot/types/api.types.js +2 -0
  83. package/dist/module/features/chatbot/types/model.types.js.map +1 -1
  84. package/dist/module/features/chatbot/types/units.types.js +2 -0
  85. package/dist/module/features/chatbot/types/units.types.js.map +1 -0
  86. package/dist/module/lib/effector/createEntityFieldStore.js +4 -0
  87. package/dist/module/lib/effector/createEntityFieldStore.js.map +1 -1
  88. package/dist/module/lib/helpers/randomElements.js +20 -0
  89. package/dist/module/lib/helpers/randomElements.js.map +1 -0
  90. package/dist/module/shared/icons/HighlighterIcon.js +29 -0
  91. package/dist/module/shared/icons/HighlighterIcon.js.map +1 -0
  92. package/dist/module/shared/icons/StopIcon.js +26 -0
  93. package/dist/module/shared/icons/StopIcon.js.map +1 -0
  94. package/dist/module/shared/icons/icon.types.js +2 -0
  95. package/dist/typescript/commonjs/features/chatbot/components/ChatMessage/ChatMessage.d.ts +1 -0
  96. package/dist/typescript/commonjs/features/chatbot/components/ChatMessage/ChatMessage.d.ts.map +1 -1
  97. package/dist/typescript/commonjs/features/chatbot/components/ChatMessage/ReceivedMessage.d.ts +1 -1
  98. package/dist/typescript/commonjs/features/chatbot/components/ChatMessage/ReceivedMessage.d.ts.map +1 -1
  99. package/dist/typescript/commonjs/features/chatbot/components/ChatMessages/ChatbotMessages.d.ts.map +1 -1
  100. package/dist/typescript/commonjs/features/chatbot/components/Chatbot.d.ts.map +1 -1
  101. package/dist/typescript/commonjs/features/chatbot/context/ChatBotContext.d.ts +8 -0
  102. package/dist/typescript/commonjs/features/chatbot/context/ChatBotContext.d.ts.map +1 -0
  103. package/dist/typescript/commonjs/features/chatbot/errorSpotting/ErrorSpottingButton.d.ts +3 -0
  104. package/dist/typescript/commonjs/features/chatbot/errorSpotting/ErrorSpottingButton.d.ts.map +1 -0
  105. package/dist/typescript/commonjs/features/chatbot/errorSpotting/ErrorSpottingModel.d.ts +28 -0
  106. package/dist/typescript/commonjs/features/chatbot/errorSpotting/ErrorSpottingModel.d.ts.map +1 -0
  107. package/dist/typescript/commonjs/features/chatbot/index.d.ts +4 -3
  108. package/dist/typescript/commonjs/features/chatbot/index.d.ts.map +1 -1
  109. package/dist/typescript/commonjs/features/chatbot/model/ChatBotModel.d.ts +19 -14
  110. package/dist/typescript/commonjs/features/chatbot/model/ChatBotModel.d.ts.map +1 -1
  111. package/dist/typescript/{module/features/chatbot/model/ChatBotMessageHandler.d.ts → commonjs/features/chatbot/model/ChatBotThreadManager.d.ts} +11 -8
  112. package/dist/typescript/commonjs/features/chatbot/model/ChatBotThreadManager.d.ts.map +1 -0
  113. package/dist/typescript/commonjs/features/chatbot/model/{api.d.ts → ChatbotApi.d.ts} +4 -3
  114. package/dist/typescript/commonjs/features/chatbot/model/ChatbotApi.d.ts.map +1 -0
  115. package/dist/typescript/commonjs/features/chatbot/model/ChatsCacheModel.d.ts +26 -0
  116. package/dist/typescript/commonjs/features/chatbot/model/ChatsCacheModel.d.ts.map +1 -0
  117. package/dist/typescript/commonjs/features/chatbot/model/DefaultMessageCreator.d.ts +3 -2
  118. package/dist/typescript/commonjs/features/chatbot/model/DefaultMessageCreator.d.ts.map +1 -1
  119. package/dist/typescript/commonjs/features/chatbot/model/ThreadItem.d.ts +12 -6
  120. package/dist/typescript/commonjs/features/chatbot/model/ThreadItem.d.ts.map +1 -1
  121. package/dist/typescript/commonjs/features/chatbot/model/messagesHelper.d.ts +3 -4
  122. package/dist/typescript/commonjs/features/chatbot/model/messagesHelper.d.ts.map +1 -1
  123. package/dist/typescript/commonjs/features/chatbot/model/t2s.d.ts +2 -4
  124. package/dist/typescript/commonjs/features/chatbot/model/t2s.d.ts.map +1 -1
  125. package/dist/typescript/commonjs/features/chatbot/model/translation.d.ts +7 -8
  126. package/dist/typescript/commonjs/features/chatbot/model/translation.d.ts.map +1 -1
  127. package/dist/typescript/commonjs/features/chatbot/model/translation.helpers.d.ts +2 -1
  128. package/dist/typescript/commonjs/features/chatbot/model/translation.helpers.d.ts.map +1 -1
  129. package/dist/typescript/commonjs/features/chatbot/types/api.types.d.ts +2 -11
  130. package/dist/typescript/commonjs/features/chatbot/types/api.types.d.ts.map +1 -1
  131. package/dist/typescript/commonjs/features/chatbot/types/model.types.d.ts +26 -19
  132. package/dist/typescript/commonjs/features/chatbot/types/model.types.d.ts.map +1 -1
  133. package/dist/typescript/commonjs/features/chatbot/types/translation.types.d.ts +2 -1
  134. package/dist/typescript/commonjs/features/chatbot/types/translation.types.d.ts.map +1 -1
  135. package/dist/typescript/commonjs/features/chatbot/types/units.types.d.ts +31 -0
  136. package/dist/typescript/commonjs/features/chatbot/types/units.types.d.ts.map +1 -0
  137. package/dist/typescript/commonjs/lib/effector/createEntityFieldStore.d.ts +2 -0
  138. package/dist/typescript/commonjs/lib/effector/createEntityFieldStore.d.ts.map +1 -1
  139. package/dist/typescript/commonjs/lib/helpers/randomElements.d.ts +2 -0
  140. package/dist/typescript/commonjs/lib/helpers/randomElements.d.ts.map +1 -0
  141. package/dist/typescript/commonjs/shared/icons/HighlighterIcon.d.ts +4 -0
  142. package/dist/typescript/commonjs/shared/icons/HighlighterIcon.d.ts.map +1 -0
  143. package/dist/typescript/commonjs/shared/icons/StopIcon.d.ts +4 -0
  144. package/dist/typescript/commonjs/shared/icons/StopIcon.d.ts.map +1 -0
  145. package/dist/typescript/commonjs/shared/icons/icon.types.d.ts +2 -0
  146. package/dist/typescript/commonjs/shared/icons/icon.types.d.ts.map +1 -1
  147. package/dist/typescript/module/features/chatbot/components/ChatMessage/ChatMessage.d.ts +1 -0
  148. package/dist/typescript/module/features/chatbot/components/ChatMessage/ChatMessage.d.ts.map +1 -1
  149. package/dist/typescript/module/features/chatbot/components/ChatMessage/ReceivedMessage.d.ts +1 -1
  150. package/dist/typescript/module/features/chatbot/components/ChatMessage/ReceivedMessage.d.ts.map +1 -1
  151. package/dist/typescript/module/features/chatbot/components/ChatMessages/ChatbotMessages.d.ts.map +1 -1
  152. package/dist/typescript/module/features/chatbot/components/Chatbot.d.ts.map +1 -1
  153. package/dist/typescript/module/features/chatbot/context/ChatBotContext.d.ts +8 -0
  154. package/dist/typescript/module/features/chatbot/context/ChatBotContext.d.ts.map +1 -0
  155. package/dist/typescript/module/features/chatbot/errorSpotting/ErrorSpottingButton.d.ts +3 -0
  156. package/dist/typescript/module/features/chatbot/errorSpotting/ErrorSpottingButton.d.ts.map +1 -0
  157. package/dist/typescript/module/features/chatbot/errorSpotting/ErrorSpottingModel.d.ts +28 -0
  158. package/dist/typescript/module/features/chatbot/errorSpotting/ErrorSpottingModel.d.ts.map +1 -0
  159. package/dist/typescript/module/features/chatbot/index.d.ts +4 -3
  160. package/dist/typescript/module/features/chatbot/index.d.ts.map +1 -1
  161. package/dist/typescript/module/features/chatbot/model/ChatBotModel.d.ts +19 -14
  162. package/dist/typescript/module/features/chatbot/model/ChatBotModel.d.ts.map +1 -1
  163. package/dist/typescript/{commonjs/features/chatbot/model/ChatBotMessageHandler.d.ts → module/features/chatbot/model/ChatBotThreadManager.d.ts} +11 -8
  164. package/dist/typescript/module/features/chatbot/model/ChatBotThreadManager.d.ts.map +1 -0
  165. package/dist/typescript/module/features/chatbot/model/{api.d.ts → ChatbotApi.d.ts} +4 -3
  166. package/dist/typescript/module/features/chatbot/model/ChatbotApi.d.ts.map +1 -0
  167. package/dist/typescript/module/features/chatbot/model/ChatsCacheModel.d.ts +26 -0
  168. package/dist/typescript/module/features/chatbot/model/ChatsCacheModel.d.ts.map +1 -0
  169. package/dist/typescript/module/features/chatbot/model/DefaultMessageCreator.d.ts +3 -2
  170. package/dist/typescript/module/features/chatbot/model/DefaultMessageCreator.d.ts.map +1 -1
  171. package/dist/typescript/module/features/chatbot/model/ThreadItem.d.ts +12 -6
  172. package/dist/typescript/module/features/chatbot/model/ThreadItem.d.ts.map +1 -1
  173. package/dist/typescript/module/features/chatbot/model/messagesHelper.d.ts +3 -4
  174. package/dist/typescript/module/features/chatbot/model/messagesHelper.d.ts.map +1 -1
  175. package/dist/typescript/module/features/chatbot/model/t2s.d.ts +2 -4
  176. package/dist/typescript/module/features/chatbot/model/t2s.d.ts.map +1 -1
  177. package/dist/typescript/module/features/chatbot/model/translation.d.ts +7 -8
  178. package/dist/typescript/module/features/chatbot/model/translation.d.ts.map +1 -1
  179. package/dist/typescript/module/features/chatbot/model/translation.helpers.d.ts +2 -1
  180. package/dist/typescript/module/features/chatbot/model/translation.helpers.d.ts.map +1 -1
  181. package/dist/typescript/module/features/chatbot/types/api.types.d.ts +2 -11
  182. package/dist/typescript/module/features/chatbot/types/api.types.d.ts.map +1 -1
  183. package/dist/typescript/module/features/chatbot/types/model.types.d.ts +26 -19
  184. package/dist/typescript/module/features/chatbot/types/model.types.d.ts.map +1 -1
  185. package/dist/typescript/module/features/chatbot/types/translation.types.d.ts +2 -1
  186. package/dist/typescript/module/features/chatbot/types/translation.types.d.ts.map +1 -1
  187. package/dist/typescript/module/features/chatbot/types/units.types.d.ts +31 -0
  188. package/dist/typescript/module/features/chatbot/types/units.types.d.ts.map +1 -0
  189. package/dist/typescript/module/lib/effector/createEntityFieldStore.d.ts +2 -0
  190. package/dist/typescript/module/lib/effector/createEntityFieldStore.d.ts.map +1 -1
  191. package/dist/typescript/module/lib/helpers/randomElements.d.ts +2 -0
  192. package/dist/typescript/module/lib/helpers/randomElements.d.ts.map +1 -0
  193. package/dist/typescript/module/shared/icons/HighlighterIcon.d.ts +4 -0
  194. package/dist/typescript/module/shared/icons/HighlighterIcon.d.ts.map +1 -0
  195. package/dist/typescript/module/shared/icons/StopIcon.d.ts +4 -0
  196. package/dist/typescript/module/shared/icons/StopIcon.d.ts.map +1 -0
  197. package/dist/typescript/module/shared/icons/icon.types.d.ts +2 -0
  198. package/dist/typescript/module/shared/icons/icon.types.d.ts.map +1 -1
  199. package/package.json +2 -2
  200. package/src/features/chatbot/components/ChatMessage/ChatMessage.tsx +1 -0
  201. package/src/features/chatbot/components/ChatMessage/ReceivedMessage.tsx +3 -0
  202. package/src/features/chatbot/components/ChatMessages/ChatbotMessages.tsx +14 -0
  203. package/src/features/chatbot/components/Chatbot.tsx +3 -2
  204. package/src/features/chatbot/context/ChatBotContext.ts +18 -0
  205. package/src/features/chatbot/errorSpotting/ErrorSpottingButton.tsx +53 -0
  206. package/src/features/chatbot/errorSpotting/ErrorSpottingModel.ts +116 -0
  207. package/src/features/chatbot/index.ts +3 -3
  208. package/src/features/chatbot/model/ChatBotModel.ts +123 -124
  209. package/src/features/chatbot/model/{ChatBotMessageHandler.ts → ChatBotThreadManager.ts} +28 -16
  210. package/src/features/chatbot/model/{api.ts → ChatbotApi.ts} +19 -2
  211. package/src/features/chatbot/model/ChatsCacheModel.ts +94 -0
  212. package/src/features/chatbot/model/DefaultMessageCreator.ts +3 -3
  213. package/src/features/chatbot/model/ThreadItem.ts +20 -9
  214. package/src/features/chatbot/model/messagesHelper.ts +2 -6
  215. package/src/features/chatbot/model/t2s.ts +3 -10
  216. package/src/features/chatbot/model/translation.helpers.ts +2 -1
  217. package/src/features/chatbot/model/translation.ts +52 -46
  218. package/src/features/chatbot/types/api.types.ts +2 -12
  219. package/src/features/chatbot/types/model.types.ts +38 -26
  220. package/src/features/chatbot/types/translation.types.ts +2 -1
  221. package/src/features/chatbot/types/units.types.ts +34 -0
  222. package/src/lib/effector/createEntityFieldStore.ts +9 -1
  223. package/src/lib/helpers/randomElements.ts +22 -0
  224. package/src/shared/icons/HighlighterIcon.tsx +21 -0
  225. package/src/shared/icons/StopIcon.tsx +17 -0
  226. package/src/shared/icons/icon.types.ts +9 -6
  227. package/dist/commonjs/features/chatbot/model/ChatBotMessageHandler.js.map +0 -1
  228. package/dist/commonjs/features/chatbot/model/api.js.map +0 -1
  229. package/dist/module/features/chatbot/model/ChatBotMessageHandler.js.map +0 -1
  230. package/dist/module/features/chatbot/model/api.js.map +0 -1
  231. package/dist/typescript/commonjs/features/chatbot/model/ChatBotMessageHandler.d.ts.map +0 -1
  232. package/dist/typescript/commonjs/features/chatbot/model/api.d.ts.map +0 -1
  233. package/dist/typescript/module/features/chatbot/model/ChatBotMessageHandler.d.ts.map +0 -1
  234. package/dist/typescript/module/features/chatbot/model/api.d.ts.map +0 -1
@@ -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, createEntityFieldStore } from '../../../lib/effector'
11
+ import { createControllerEffect } from '../../../lib/effector'
12
12
  import {
13
13
  ChatbotContext,
14
14
  ChatbotModelProps,
15
- ConversationMessage,
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 './api'
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 api: ChatbotAPI
35
- readonly translation: ChatbotTranslation
36
- readonly t2s: ChatTextToSpeechModel
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
- messages: this.messages.$state,
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.api = new ChatbotAPI(api)
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
- this.t2s = new ChatTextToSpeechModel({ $isOpen: this.$isOpen, api: this.api })
102
+ if ($key) this.bindKey($key)
106
103
 
107
- this.sendHelpRequestFx = this.createSendHelpRequestFx()
108
- this.initChatReplyWatcher()
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
- this.$currentKey,
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.messages.setField({
139
- key,
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
- if (isTranslated) {
159
- messages = await this.translation.translateMessagesFx({
160
- targetLanguage: context.translationTargetLanguage,
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
- this.threadIds.setField({ key, data: response.threadId })
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 }) => ({ key, data: [...messages, this.defaultMessages.error] }),
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.messages.setField,
171
+ target: this.cache.update,
180
172
  })
181
173
 
182
174
  return effect
183
175
  }
184
176
 
185
- private initChatReplyWatcher() {
177
+ public bindKey($store: Store<string>) {
186
178
  sample({
187
- clock: this.removeLastMessage,
188
- source: [this.$lastMessageKey, this.messages.$state] as const,
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.messages.setField({ key, data: [this.defaultMessages.start] })
212
- this.availableChats.setField({ key, data: true })
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.messages.setField({
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 = createEffect(({ key }: ReinitConversationProps) => {
228
- this.messages.setField({
229
- key,
230
- fn: (messages) => {
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 bindKey($store: Store<string>) {
250
- sample({
251
- source: $store,
252
- target: this.$currentKey,
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 setT2SAudioProvider(audioProvider: AudioProvider) {
258
- this.t2s.setAudioProvider(audioProvider)
259
- return this
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 ChatMessageHandlerProps = {
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 ChatMessageHandler {
25
+ export class ChatBotThreadManager {
27
26
  private readonly api
28
- private readonly drawBoardAdapter: IChatDrawBoardAdapter
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
- }: ChatMessageHandlerProps) {
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 strokes = await this.drawBoardAdapter.getVisibleStrokes()
63
- threadItem = new ThreadItem({ strokes })
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 readonly postMessageFx = async ({
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.hints.push(result.message)
101
+ threadItem.history.push(result.message)
90
102
  const nextOptions =
91
- threadItem.hints.length < this.messagesLimit ? [this.defaultMessages.anotherHintOption] : []
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 = createEffect(({ key }: ResetCacheProps) => {
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 { ChatbotModelProps } from '../types/model.types'
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
- constructor(api: ChatbotModelProps['api']) {
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(
@@ -0,0 +1,94 @@
1
+ import { createEvent } from 'effector'
2
+ import { createEntityFieldStore } from '../../../lib/effector'
3
+ import { ChatAnswer, ChatItem, ConversationMessage, IThreadItem } from '../types/units.types'
4
+
5
+ type ReinitChatThreadSettings = {
6
+ initialOption: ChatAnswer
7
+ }
8
+
9
+ type UpdateProps = {
10
+ key: string
11
+ data: Partial<ChatItem>
12
+ }
13
+
14
+ type AddMessagesProps = {
15
+ messages: ConversationMessage[]
16
+ thread?: IThreadItem | null
17
+ }
18
+
19
+ export function defaultChatData(props: Partial<ChatItem> = {}): ChatItem {
20
+ return {
21
+ messages: [],
22
+ isAvailable: false,
23
+ currentThread: null,
24
+ ...props,
25
+ }
26
+ }
27
+
28
+ export class ChatsCacheModel {
29
+ public readonly update = createEvent<UpdateProps>()
30
+ private readonly cache = createEntityFieldStore<ChatItem>().on(
31
+ this.update,
32
+ (state, { key, data }) => {
33
+ const currentData = state[key] ?? defaultChatData()
34
+ return { ...state, [key]: { ...currentData, ...data } }
35
+ },
36
+ )
37
+
38
+ public readonly $data = this.cache.$state
39
+ public readonly reset = this.cache.reset
40
+
41
+ public disableChat(key: string) {
42
+ this.cache.setField({
43
+ key,
44
+ fn: (current) =>
45
+ current ? { ...current, isAvailable: false } : defaultChatData({ isAvailable: false }),
46
+ })
47
+ }
48
+
49
+ public reinitChatThread(key: string, { initialOption }: ReinitChatThreadSettings) {
50
+ this.cache.setField({
51
+ key,
52
+ fn: (current) => {
53
+ if (!current || current.messages.length <= 1) return
54
+ const copy = [...current.messages]
55
+ while (copy.at(-1)?.endMessage) {
56
+ copy.pop()
57
+ }
58
+ const lastMessage = copy.at(-1)
59
+ if (!lastMessage) return
60
+ copy.splice(copy.length - 1, 1, {
61
+ ...lastMessage,
62
+ options: [initialOption],
63
+ })
64
+ return { ...current, messages: copy }
65
+ },
66
+ })
67
+ }
68
+
69
+ public setSingleMessage(key: string, message: ConversationMessage) {
70
+ this.cache.setField({
71
+ key,
72
+ fn: (current) => {
73
+ if (!current || current.messages.length > 1) return
74
+ return { ...current, messages: [message] }
75
+ },
76
+ })
77
+ }
78
+
79
+ public addMessages(key: string, { messages, thread = null }: AddMessagesProps) {
80
+ this.cache.setField({
81
+ key,
82
+ fn: (current) => {
83
+ if (!current) return defaultChatData({ messages, currentThread: thread })
84
+ const result = { ...current, messages: [...current.messages, ...messages] }
85
+ if (thread) result.currentThread = thread
86
+ return result
87
+ },
88
+ })
89
+ }
90
+
91
+ public add(key: string, data: ChatItem) {
92
+ this.cache.setField({ key, data })
93
+ }
94
+ }
@@ -1,7 +1,8 @@
1
- import { ChatAnswer, PostMessageResponse } from '../types/api.types'
1
+ import { PostMessageResponse } from '../types/api.types'
2
2
  import { createEvent } from 'effector'
3
+ import { ChatAnswer } from '../types/units.types'
3
4
 
4
- type ChatMessage = PostMessageResponse & {
5
+ type ChatMessage = Omit<PostMessageResponse, 'thread'> & {
5
6
  id: string
6
7
  isOwnMessage: boolean
7
8
  }
@@ -38,7 +39,6 @@ export class DefaultMessagesCreator<K extends string> {
38
39
  const message: ChatMessage = {
39
40
  id: this.list.size.toString(),
40
41
  message: this.getter(key),
41
- threadId: '',
42
42
  options: [],
43
43
  isOwnMessage: isOwn,
44
44
  }
@@ -1,28 +1,39 @@
1
- import { Stroke } from '../types/api.types'
1
+ import { FullStrokeData, IThreadItem } from '../types/units.types'
2
2
 
3
3
  type ThreadItemProps = {
4
- strokes?: Stroke[] | null
4
+ strokes: FullStrokeData[]
5
+ key: string
5
6
  }
6
7
 
7
8
  export class ThreadItem {
8
- public readonly strokes: Stroke[] | null
9
- public readonly hints: string[] = []
9
+ public readonly key: string | null = null
10
+ public readonly strokes: FullStrokeData[] | null
11
+ public readonly history: string[] = []
10
12
 
11
- public constructor({ strokes }: ThreadItemProps = {}) {
12
- this.strokes = strokes ?? null
13
+ public constructor(props?: ThreadItemProps | null) {
14
+ this.strokes = props?.strokes ?? null
15
+ this.key = props?.key ?? null
13
16
  }
14
17
 
15
18
  public getNextHintProps() {
16
- if (this.hints.length) {
19
+ if (this.history.length) {
17
20
  return {
18
- previousHint: this.hints[this.hints.length - 1],
21
+ previousHint: this.history[this.history.length - 1],
19
22
  }
20
23
  }
21
24
 
22
25
  if (this.strokes) {
23
- return { stroke: this.strokes }
26
+ return { stroke: this.strokes.map(({ x, y }) => ({ x, y })) }
24
27
  }
25
28
 
26
29
  return {}
27
30
  }
31
+
32
+ public toObject(): IThreadItem {
33
+ return {
34
+ key: this.key,
35
+ strokes: this.strokes,
36
+ history: [...this.history],
37
+ }
38
+ }
28
39
  }