@magmamath/students-features 0.7.0 → 0.8.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/{ChatMessages/ChatbotMessages.js → Chat/Chat.js} +8 -15
- package/dist/commonjs/features/chatbot/components/Chat/Chat.js.map +1 -0
- package/dist/commonjs/features/chatbot/components/ChatControls/ChatControls.js +1 -1
- package/dist/commonjs/features/chatbot/components/ChatControls/ChatControls.js.map +1 -1
- package/dist/commonjs/features/chatbot/components/ChatInput/ChatInput.js +74 -0
- package/dist/commonjs/features/chatbot/components/ChatInput/ChatInput.js.map +1 -0
- package/dist/commonjs/features/chatbot/components/ChatInput/RequestHintButton.js +144 -0
- package/dist/commonjs/features/chatbot/components/ChatInput/RequestHintButton.js.map +1 -0
- package/dist/commonjs/features/chatbot/components/ChatInput/freeText/ChatTextInput.js +138 -0
- package/dist/commonjs/features/chatbot/components/ChatInput/freeText/ChatTextInput.js.map +1 -0
- package/dist/commonjs/features/chatbot/components/ChatInput/freeText/FreeTextInputBlock.js +66 -0
- package/dist/commonjs/features/chatbot/components/ChatInput/freeText/FreeTextInputBlock.js.map +1 -0
- package/dist/commonjs/features/chatbot/components/ChatInput/freeText/SendMessageButton.js +106 -0
- package/dist/commonjs/features/chatbot/components/ChatInput/freeText/SendMessageButton.js.map +1 -0
- package/dist/commonjs/features/chatbot/components/ChatMessage/MessageLoader.js +7 -4
- package/dist/commonjs/features/chatbot/components/ChatMessage/MessageLoader.js.map +1 -1
- package/dist/commonjs/features/chatbot/components/Chatbot.js +2 -2
- package/dist/commonjs/features/chatbot/components/Chatbot.js.map +1 -1
- package/dist/commonjs/features/chatbot/constants.js +6 -1
- package/dist/commonjs/features/chatbot/constants.js.map +1 -1
- package/dist/commonjs/features/chatbot/helpers.js +75 -1
- package/dist/commonjs/features/chatbot/helpers.js.map +1 -1
- package/dist/commonjs/features/chatbot/index.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/ChatBotModel.js +49 -11
- package/dist/commonjs/features/chatbot/model/ChatBotModel.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/ChatBotTextInput.js +16 -0
- package/dist/commonjs/features/chatbot/model/ChatBotTextInput.js.map +1 -0
- package/dist/commonjs/features/chatbot/model/ChatBotThreadManager.js +11 -19
- package/dist/commonjs/features/chatbot/model/ChatBotThreadManager.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/{translation.js → ChatbotTranslation.js} +29 -1
- package/dist/commonjs/features/chatbot/model/ChatbotTranslation.js.map +1 -0
- package/dist/commonjs/features/chatbot/types/model.types.js +6 -1
- package/dist/commonjs/features/chatbot/types/model.types.js.map +1 -1
- package/dist/commonjs/features/chatbot/types/units.types.js +10 -0
- package/dist/commonjs/features/chatbot/types/units.types.js.map +1 -1
- package/dist/commonjs/shared/hooks/useKeyDownListener.js +3 -2
- package/dist/commonjs/shared/hooks/useKeyDownListener.js.map +1 -1
- package/dist/commonjs/shared/translation/localization/ca.json +3 -2
- package/dist/commonjs/shared/translation/localization/en.json +3 -2
- package/dist/commonjs/shared/translation/localization/gb.json +3 -2
- package/dist/commonjs/shared/translation/localization/sct.json +3 -2
- package/dist/commonjs/shared/translation/localization/sw.json +3 -2
- package/dist/module/features/chatbot/components/{ChatMessages/ChatbotMessages.js → Chat/Chat.js} +6 -13
- package/dist/module/features/chatbot/components/Chat/Chat.js.map +1 -0
- package/dist/module/features/chatbot/components/ChatControls/ChatControls.js +1 -1
- package/dist/module/features/chatbot/components/ChatControls/ChatControls.js.map +1 -1
- package/dist/module/features/chatbot/components/ChatInput/ChatInput.js +67 -0
- package/dist/module/features/chatbot/components/ChatInput/ChatInput.js.map +1 -0
- package/dist/module/features/chatbot/components/ChatInput/RequestHintButton.js +138 -0
- package/dist/module/features/chatbot/components/ChatInput/RequestHintButton.js.map +1 -0
- package/dist/module/features/chatbot/components/ChatInput/freeText/ChatTextInput.js +131 -0
- package/dist/module/features/chatbot/components/ChatInput/freeText/ChatTextInput.js.map +1 -0
- package/dist/module/features/chatbot/components/ChatInput/freeText/FreeTextInputBlock.js +60 -0
- package/dist/module/features/chatbot/components/ChatInput/freeText/FreeTextInputBlock.js.map +1 -0
- package/dist/module/features/chatbot/components/ChatInput/freeText/SendMessageButton.js +98 -0
- package/dist/module/features/chatbot/components/ChatInput/freeText/SendMessageButton.js.map +1 -0
- package/dist/module/features/chatbot/components/ChatMessage/MessageLoader.js +7 -4
- package/dist/module/features/chatbot/components/ChatMessage/MessageLoader.js.map +1 -1
- package/dist/module/features/chatbot/components/Chatbot.js +2 -2
- package/dist/module/features/chatbot/components/Chatbot.js.map +1 -1
- package/dist/module/features/chatbot/constants.js +5 -0
- package/dist/module/features/chatbot/constants.js.map +1 -1
- package/dist/module/features/chatbot/helpers.js +71 -0
- package/dist/module/features/chatbot/helpers.js.map +1 -1
- package/dist/module/features/chatbot/index.js.map +1 -1
- package/dist/module/features/chatbot/model/ChatBotModel.js +49 -11
- package/dist/module/features/chatbot/model/ChatBotModel.js.map +1 -1
- package/dist/module/features/chatbot/model/ChatBotTextInput.js +11 -0
- package/dist/module/features/chatbot/model/ChatBotTextInput.js.map +1 -0
- package/dist/module/features/chatbot/model/ChatBotThreadManager.js +11 -19
- package/dist/module/features/chatbot/model/ChatBotThreadManager.js.map +1 -1
- package/dist/module/features/chatbot/model/{translation.js → ChatbotTranslation.js} +29 -1
- package/dist/module/features/chatbot/model/ChatbotTranslation.js.map +1 -0
- package/dist/module/features/chatbot/types/model.types.js +5 -0
- package/dist/module/features/chatbot/types/model.types.js.map +1 -1
- package/dist/module/features/chatbot/types/units.types.js +6 -0
- package/dist/module/features/chatbot/types/units.types.js.map +1 -1
- package/dist/module/shared/hooks/useKeyDownListener.js +3 -2
- package/dist/module/shared/hooks/useKeyDownListener.js.map +1 -1
- package/dist/module/shared/translation/localization/ca.json +3 -2
- package/dist/module/shared/translation/localization/en.json +3 -2
- package/dist/module/shared/translation/localization/gb.json +3 -2
- package/dist/module/shared/translation/localization/sct.json +3 -2
- package/dist/module/shared/translation/localization/sw.json +3 -2
- package/dist/typescript/{module/features/chatbot/components/ChatMessages/ChatbotMessages.d.ts → commonjs/features/chatbot/components/Chat/Chat.d.ts} +3 -3
- package/dist/typescript/commonjs/features/chatbot/components/Chat/Chat.d.ts.map +1 -0
- package/dist/typescript/commonjs/features/chatbot/components/ChatControls/ChatControls.d.ts +1 -1
- package/dist/typescript/commonjs/features/chatbot/components/ChatControls/ChatControls.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/components/ChatInput/ChatInput.d.ts +9 -0
- package/dist/typescript/commonjs/features/chatbot/components/ChatInput/ChatInput.d.ts.map +1 -0
- package/dist/typescript/commonjs/features/chatbot/components/ChatInput/RequestHintButton.d.ts +16 -0
- package/dist/typescript/commonjs/features/chatbot/components/ChatInput/RequestHintButton.d.ts.map +1 -0
- package/dist/typescript/commonjs/features/chatbot/components/ChatInput/freeText/ChatTextInput.d.ts +16 -0
- package/dist/typescript/commonjs/features/chatbot/components/ChatInput/freeText/ChatTextInput.d.ts.map +1 -0
- package/dist/typescript/commonjs/features/chatbot/components/ChatInput/freeText/FreeTextInputBlock.d.ts +11 -0
- package/dist/typescript/commonjs/features/chatbot/components/ChatInput/freeText/FreeTextInputBlock.d.ts.map +1 -0
- package/dist/typescript/commonjs/features/chatbot/components/ChatInput/freeText/SendMessageButton.d.ts +10 -0
- package/dist/typescript/commonjs/features/chatbot/components/ChatInput/freeText/SendMessageButton.d.ts.map +1 -0
- package/dist/typescript/commonjs/features/chatbot/components/ChatMessage/MessageLoader.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/components/Chatbot.d.ts +3 -1
- package/dist/typescript/commonjs/features/chatbot/components/Chatbot.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/constants.d.ts +5 -0
- package/dist/typescript/commonjs/features/chatbot/constants.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/helpers.d.ts +5 -0
- package/dist/typescript/commonjs/features/chatbot/helpers.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/index.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/model/ChatBotModel.d.ts +5 -6
- package/dist/typescript/commonjs/features/chatbot/model/ChatBotModel.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/model/ChatBotTextInput.d.ts +8 -0
- package/dist/typescript/commonjs/features/chatbot/model/ChatBotTextInput.d.ts.map +1 -0
- package/dist/typescript/commonjs/features/chatbot/model/ChatBotThreadManager.d.ts +3 -2
- package/dist/typescript/commonjs/features/chatbot/model/ChatBotThreadManager.d.ts.map +1 -1
- package/dist/typescript/{module/features/chatbot/model/translation.d.ts → commonjs/features/chatbot/model/ChatbotTranslation.d.ts} +3 -2
- package/dist/typescript/commonjs/features/chatbot/model/ChatbotTranslation.d.ts.map +1 -0
- package/dist/typescript/commonjs/features/chatbot/types/api.types.d.ts +28 -6
- 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 +28 -3
- 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 +5 -0
- 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 +5 -0
- package/dist/typescript/commonjs/features/chatbot/types/units.types.d.ts.map +1 -1
- package/dist/typescript/commonjs/shared/hooks/useKeyDownListener.d.ts +1 -1
- package/dist/typescript/commonjs/shared/hooks/useKeyDownListener.d.ts.map +1 -1
- package/dist/typescript/commonjs/shared/hooks/useKeyboard.d.ts +1 -1
- package/dist/typescript/commonjs/shared/hooks/useKeyboard.d.ts.map +1 -1
- package/dist/typescript/commonjs/shared/translation/constants.d.ts +5 -0
- package/dist/typescript/commonjs/shared/translation/constants.d.ts.map +1 -1
- package/dist/typescript/commonjs/shared/translation/model.d.ts +2 -0
- package/dist/typescript/commonjs/shared/translation/model.d.ts.map +1 -1
- package/dist/typescript/{commonjs/features/chatbot/components/ChatMessages/ChatbotMessages.d.ts → module/features/chatbot/components/Chat/Chat.d.ts} +3 -3
- package/dist/typescript/module/features/chatbot/components/Chat/Chat.d.ts.map +1 -0
- package/dist/typescript/module/features/chatbot/components/ChatControls/ChatControls.d.ts +1 -1
- package/dist/typescript/module/features/chatbot/components/ChatControls/ChatControls.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/components/ChatInput/ChatInput.d.ts +9 -0
- package/dist/typescript/module/features/chatbot/components/ChatInput/ChatInput.d.ts.map +1 -0
- package/dist/typescript/module/features/chatbot/components/ChatInput/RequestHintButton.d.ts +16 -0
- package/dist/typescript/module/features/chatbot/components/ChatInput/RequestHintButton.d.ts.map +1 -0
- package/dist/typescript/module/features/chatbot/components/ChatInput/freeText/ChatTextInput.d.ts +16 -0
- package/dist/typescript/module/features/chatbot/components/ChatInput/freeText/ChatTextInput.d.ts.map +1 -0
- package/dist/typescript/module/features/chatbot/components/ChatInput/freeText/FreeTextInputBlock.d.ts +11 -0
- package/dist/typescript/module/features/chatbot/components/ChatInput/freeText/FreeTextInputBlock.d.ts.map +1 -0
- package/dist/typescript/module/features/chatbot/components/ChatInput/freeText/SendMessageButton.d.ts +10 -0
- package/dist/typescript/module/features/chatbot/components/ChatInput/freeText/SendMessageButton.d.ts.map +1 -0
- package/dist/typescript/module/features/chatbot/components/ChatMessage/MessageLoader.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/components/Chatbot.d.ts +3 -1
- package/dist/typescript/module/features/chatbot/components/Chatbot.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/constants.d.ts +5 -0
- package/dist/typescript/module/features/chatbot/constants.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/helpers.d.ts +5 -0
- package/dist/typescript/module/features/chatbot/helpers.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/index.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/model/ChatBotModel.d.ts +5 -6
- package/dist/typescript/module/features/chatbot/model/ChatBotModel.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/model/ChatBotTextInput.d.ts +8 -0
- package/dist/typescript/module/features/chatbot/model/ChatBotTextInput.d.ts.map +1 -0
- package/dist/typescript/module/features/chatbot/model/ChatBotThreadManager.d.ts +3 -2
- package/dist/typescript/module/features/chatbot/model/ChatBotThreadManager.d.ts.map +1 -1
- package/dist/typescript/{commonjs/features/chatbot/model/translation.d.ts → module/features/chatbot/model/ChatbotTranslation.d.ts} +3 -2
- package/dist/typescript/module/features/chatbot/model/ChatbotTranslation.d.ts.map +1 -0
- package/dist/typescript/module/features/chatbot/types/api.types.d.ts +28 -6
- 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 +28 -3
- 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 +5 -0
- 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 +5 -0
- package/dist/typescript/module/features/chatbot/types/units.types.d.ts.map +1 -1
- package/dist/typescript/module/shared/hooks/useKeyDownListener.d.ts +1 -1
- package/dist/typescript/module/shared/hooks/useKeyDownListener.d.ts.map +1 -1
- package/dist/typescript/module/shared/hooks/useKeyboard.d.ts +1 -1
- package/dist/typescript/module/shared/hooks/useKeyboard.d.ts.map +1 -1
- package/dist/typescript/module/shared/translation/constants.d.ts +5 -0
- package/dist/typescript/module/shared/translation/constants.d.ts.map +1 -1
- package/dist/typescript/module/shared/translation/model.d.ts +2 -0
- package/dist/typescript/module/shared/translation/model.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/features/chatbot/components/{ChatMessages/ChatbotMessages.tsx → Chat/Chat.tsx} +13 -18
- package/src/features/chatbot/components/ChatControls/ChatControls.tsx +2 -2
- package/src/features/chatbot/components/ChatInput/ChatInput.tsx +88 -0
- package/src/features/chatbot/components/ChatInput/RequestHintButton.tsx +156 -0
- package/src/features/chatbot/components/ChatInput/freeText/ChatTextInput.tsx +156 -0
- package/src/features/chatbot/components/ChatInput/freeText/FreeTextInputBlock.tsx +71 -0
- package/src/features/chatbot/components/ChatInput/freeText/SendMessageButton.tsx +111 -0
- package/src/features/chatbot/components/ChatMessage/MessageLoader.tsx +6 -2
- package/src/features/chatbot/components/Chatbot.tsx +5 -3
- package/src/features/chatbot/constants.ts +7 -0
- package/src/features/chatbot/helpers.ts +70 -1
- package/src/features/chatbot/index.ts +1 -0
- package/src/features/chatbot/model/ChatBotModel.ts +82 -37
- package/src/features/chatbot/model/ChatBotTextInput.ts +10 -0
- package/src/features/chatbot/model/ChatBotThreadManager.ts +17 -19
- package/src/features/chatbot/model/{translation.ts → ChatbotTranslation.ts} +32 -2
- package/src/features/chatbot/types/api.types.ts +31 -6
- package/src/features/chatbot/types/model.types.ts +35 -2
- package/src/features/chatbot/types/translation.types.ts +6 -0
- package/src/features/chatbot/types/units.types.ts +6 -0
- package/src/shared/hooks/useKeyDownListener.ts +3 -1
- package/src/shared/translation/localization/ca.json +3 -2
- package/src/shared/translation/localization/en.json +3 -2
- package/src/shared/translation/localization/gb.json +3 -2
- package/src/shared/translation/localization/sct.json +3 -2
- package/src/shared/translation/localization/sw.json +3 -2
- package/dist/commonjs/features/chatbot/components/Alternatives/Alternatives.js +0 -59
- package/dist/commonjs/features/chatbot/components/Alternatives/Alternatives.js.map +0 -1
- package/dist/commonjs/features/chatbot/components/Alternatives/HelpRequestOption.js +0 -99
- package/dist/commonjs/features/chatbot/components/Alternatives/HelpRequestOption.js.map +0 -1
- package/dist/commonjs/features/chatbot/components/ChatMessages/ChatbotMessages.js.map +0 -1
- package/dist/commonjs/features/chatbot/model/translation.js.map +0 -1
- package/dist/module/features/chatbot/components/Alternatives/Alternatives.js +0 -53
- package/dist/module/features/chatbot/components/Alternatives/Alternatives.js.map +0 -1
- package/dist/module/features/chatbot/components/Alternatives/HelpRequestOption.js +0 -92
- package/dist/module/features/chatbot/components/Alternatives/HelpRequestOption.js.map +0 -1
- package/dist/module/features/chatbot/components/ChatMessages/ChatbotMessages.js.map +0 -1
- package/dist/module/features/chatbot/model/translation.js.map +0 -1
- package/dist/typescript/commonjs/features/chatbot/components/Alternatives/Alternatives.d.ts +0 -11
- package/dist/typescript/commonjs/features/chatbot/components/Alternatives/Alternatives.d.ts.map +0 -1
- package/dist/typescript/commonjs/features/chatbot/components/Alternatives/HelpRequestOption.d.ts +0 -10
- package/dist/typescript/commonjs/features/chatbot/components/Alternatives/HelpRequestOption.d.ts.map +0 -1
- package/dist/typescript/commonjs/features/chatbot/components/ChatMessages/ChatbotMessages.d.ts.map +0 -1
- package/dist/typescript/commonjs/features/chatbot/model/translation.d.ts.map +0 -1
- package/dist/typescript/module/features/chatbot/components/Alternatives/Alternatives.d.ts +0 -11
- package/dist/typescript/module/features/chatbot/components/Alternatives/Alternatives.d.ts.map +0 -1
- package/dist/typescript/module/features/chatbot/components/Alternatives/HelpRequestOption.d.ts +0 -10
- package/dist/typescript/module/features/chatbot/components/Alternatives/HelpRequestOption.d.ts.map +0 -1
- package/dist/typescript/module/features/chatbot/components/ChatMessages/ChatbotMessages.d.ts.map +0 -1
- package/dist/typescript/module/features/chatbot/model/translation.d.ts.map +0 -1
- package/src/features/chatbot/components/Alternatives/Alternatives.tsx +0 -60
- package/src/features/chatbot/components/Alternatives/HelpRequestOption.tsx +0 -91
|
@@ -2,11 +2,12 @@ import React, { ComponentType, PropsWithChildren } from 'react'
|
|
|
2
2
|
import { useStoreMap, useUnit } from 'effector-react'
|
|
3
3
|
|
|
4
4
|
import { ChatbotModel } from '../model/ChatBotModel'
|
|
5
|
-
import {
|
|
5
|
+
import { Chat } from './Chat/Chat'
|
|
6
6
|
import { ChatControls } from './ChatControls/ChatControls'
|
|
7
7
|
import { AUDIO_CONFIG, DEFAULT_VOICE } from '../constants'
|
|
8
8
|
import { ChatBotModelContext } from '../context/ChatBotModelContext'
|
|
9
9
|
import { ColorScheme } from '../types/style.types'
|
|
10
|
+
import { ChatInputMode } from '../types/units.types'
|
|
10
11
|
|
|
11
12
|
type ChatbotProps = {
|
|
12
13
|
model: ChatbotModel
|
|
@@ -16,7 +17,8 @@ type ChatbotProps = {
|
|
|
16
17
|
voice: typeof DEFAULT_VOICE
|
|
17
18
|
audioConfig: typeof AUDIO_CONFIG
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
inputMode?: ChatInputMode
|
|
21
|
+
ButtonWrapper?: ComponentType<PropsWithChildren>
|
|
20
22
|
iconSize?: { width: number; height: number } // TODO: use number instead
|
|
21
23
|
colorScheme?: ColorScheme
|
|
22
24
|
}
|
|
@@ -43,7 +45,7 @@ export const Chatbot = ({
|
|
|
43
45
|
|
|
44
46
|
return (
|
|
45
47
|
<ChatBotModelContext.Provider value={model}>
|
|
46
|
-
<
|
|
48
|
+
<Chat
|
|
47
49
|
model={model}
|
|
48
50
|
colorScheme={colorScheme}
|
|
49
51
|
isHintFeedback={isHintFeedback}
|
|
@@ -2,6 +2,7 @@ import { ButtonColor, COLORS } from '@magmamath/react-native-ui'
|
|
|
2
2
|
import { Platform } from 'react-native'
|
|
3
3
|
import { MessageVariant } from './types/model.types'
|
|
4
4
|
import { ColorScheme } from './types/style.types'
|
|
5
|
+
import { ANIMATION_DURATION } from '../gifCelebrations/constants'
|
|
5
6
|
|
|
6
7
|
export const AUDIO_CONFIG = {
|
|
7
8
|
audioEncoding: 'LINEAR16',
|
|
@@ -44,20 +45,24 @@ export const MESSAGE_COLORS_MAP = {
|
|
|
44
45
|
[ColorScheme.Blue]: {
|
|
45
46
|
[MessageVariant.RECEIVED]: {
|
|
46
47
|
background: COLORS.NEUTRAL_3,
|
|
48
|
+
border: COLORS.NEUTRAL_3,
|
|
47
49
|
icon: ButtonColor.BLUE,
|
|
48
50
|
},
|
|
49
51
|
[MessageVariant.SENT]: {
|
|
50
52
|
background: COLORS.PRIMARY_BLUE,
|
|
53
|
+
border: COLORS.PRIMARY_BLUE,
|
|
51
54
|
icon: ButtonColor.BLUE,
|
|
52
55
|
},
|
|
53
56
|
},
|
|
54
57
|
[ColorScheme.Yellow]: {
|
|
55
58
|
[MessageVariant.RECEIVED]: {
|
|
56
59
|
background: COLORS.NEUTRAL_3,
|
|
60
|
+
border: COLORS.NEUTRAL_3,
|
|
57
61
|
icon: ButtonColor.YELLOW,
|
|
58
62
|
},
|
|
59
63
|
[MessageVariant.SENT]: {
|
|
60
64
|
background: COLORS.PRIMARY_YELLOW,
|
|
65
|
+
border: COLORS.PRIMARY_YELLOW,
|
|
61
66
|
icon: ButtonColor.YELLOW,
|
|
62
67
|
},
|
|
63
68
|
},
|
|
@@ -73,3 +78,5 @@ export const CONTROLS_COLORS_MAP = {
|
|
|
73
78
|
background: COLORS.PRIMARY_YELLOW,
|
|
74
79
|
},
|
|
75
80
|
}
|
|
81
|
+
|
|
82
|
+
export const HOVER_ANIMATION_DURATION = 200
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// https://stackoverflow.com/questions/56575859/google-translate-api-does-not-return-apostrophe-as-apostrophe-in-python
|
|
2
2
|
import { KATEX_REPLACEMENTS, KATEX_REPLACEMENTS_REVERSE } from './constants'
|
|
3
|
+
import { GetAlternativesResponse, PostMessagePayload } from './types/api.types'
|
|
4
|
+
import { t } from '../../shared/translation'
|
|
5
|
+
import { ThreadItem } from './model/ThreadItem'
|
|
6
|
+
import { ChatRequestPayload, ChatRequestType } from './types/model.types'
|
|
3
7
|
|
|
4
8
|
export const decodeHTMLEntities = (input: string) => {
|
|
5
9
|
return input.replace(/'/g, "'")
|
|
@@ -10,10 +14,75 @@ export const replaceKatexSyntax = (texts: string[], reverse = false) => {
|
|
|
10
14
|
? Object.entries(KATEX_REPLACEMENTS_REVERSE)
|
|
11
15
|
: Object.entries(KATEX_REPLACEMENTS)
|
|
12
16
|
|
|
13
|
-
return texts.map(text =>
|
|
17
|
+
return texts.map((text) =>
|
|
14
18
|
replacements.reduce(
|
|
15
19
|
(newText, [pattern, placeholder]) => newText.replace(new RegExp(pattern, 'g'), placeholder),
|
|
16
20
|
text,
|
|
17
21
|
),
|
|
18
22
|
)
|
|
19
23
|
}
|
|
24
|
+
|
|
25
|
+
export const transformAlternatives = (payload: GetAlternativesResponse | null) => {
|
|
26
|
+
if (!payload) return payload
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
...payload,
|
|
30
|
+
options: {
|
|
31
|
+
...payload.options,
|
|
32
|
+
hints: [
|
|
33
|
+
{
|
|
34
|
+
text: payload.isOpenChatEnabled ? t('chat.giveHint') : t('chat.anotherHint'),
|
|
35
|
+
promptKey: payload.options.hints[0].promptKey,
|
|
36
|
+
translatedText: payload.options.hints[0].translatedText,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
} as GetAlternativesResponse
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function prepareChatRequestPayload(
|
|
44
|
+
payload: PostMessagePayload,
|
|
45
|
+
threadItem: ThreadItem,
|
|
46
|
+
): ChatRequestPayload {
|
|
47
|
+
const {
|
|
48
|
+
conversationId,
|
|
49
|
+
freeTextMessage,
|
|
50
|
+
problemDescription,
|
|
51
|
+
problemAnswer,
|
|
52
|
+
language,
|
|
53
|
+
imageCdnId,
|
|
54
|
+
imageAltText,
|
|
55
|
+
answerOptions,
|
|
56
|
+
answer,
|
|
57
|
+
} = payload
|
|
58
|
+
|
|
59
|
+
if (freeTextMessage) {
|
|
60
|
+
return conversationId
|
|
61
|
+
? { type: ChatRequestType.Freetext, data: { conversationId, message: freeTextMessage } }
|
|
62
|
+
: {
|
|
63
|
+
type: ChatRequestType.Freetext,
|
|
64
|
+
data: {
|
|
65
|
+
message: freeTextMessage,
|
|
66
|
+
correctAnswer: problemAnswer,
|
|
67
|
+
problemDescription,
|
|
68
|
+
language,
|
|
69
|
+
...(imageCdnId && { imageCdnId }),
|
|
70
|
+
...(imageAltText && { altText: imageAltText }),
|
|
71
|
+
...(!!answerOptions?.length && { answerOptions }),
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
type: ChatRequestType.Hint,
|
|
78
|
+
data: {
|
|
79
|
+
...threadItem.getNextHintProps(),
|
|
80
|
+
correctAnswer: problemAnswer,
|
|
81
|
+
problemDescription,
|
|
82
|
+
userAnswer: answer,
|
|
83
|
+
language,
|
|
84
|
+
...(imageCdnId && { imageCdnId }),
|
|
85
|
+
...(imageAltText && { altText: imageAltText }),
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -9,5 +9,6 @@ export {
|
|
|
9
9
|
export type { PostMessageResponse } from './types/api.types'
|
|
10
10
|
export { DefaultMessagesCreator } from './model/DefaultMessageCreator'
|
|
11
11
|
export type { ChatAnswer } from './types/units.types'
|
|
12
|
+
|
|
12
13
|
export type { ConversationMessage } from './types/units.types'
|
|
13
14
|
export { ColorScheme } from './types/style.types'
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
attach,
|
|
3
|
+
combine,
|
|
4
|
+
createEffect,
|
|
5
|
+
createEvent,
|
|
6
|
+
createStore,
|
|
7
|
+
restore,
|
|
8
|
+
sample,
|
|
9
|
+
type Store,
|
|
10
|
+
} from 'effector'
|
|
11
|
+
import { IS_WEB } from '@magmamath/react-native-ui'
|
|
2
12
|
import {
|
|
3
13
|
ChatbotContext,
|
|
4
14
|
ChatbotModelProps,
|
|
5
15
|
IChatDrawBoardAdapter,
|
|
16
|
+
ReinitConversationProps,
|
|
6
17
|
SendHelpParams,
|
|
7
18
|
SendHelpProps,
|
|
8
19
|
SetHintMessageProps,
|
|
@@ -11,19 +22,17 @@ import {
|
|
|
11
22
|
} from '../types/model.types'
|
|
12
23
|
import { GetAlternativesResponse } from '../types/api.types'
|
|
13
24
|
import { ChatbotAPI } from './ChatbotApi'
|
|
14
|
-
import { ChatbotTranslation } from './
|
|
25
|
+
import { ChatbotTranslation } from './ChatbotTranslation'
|
|
15
26
|
import { ChatTextToSpeechModel, T2SConfig } from './t2s'
|
|
16
27
|
import { messagesHelper } from './messagesHelper'
|
|
17
28
|
import { ChatBotThreadManager } from './ChatBotThreadManager'
|
|
18
29
|
import { ChatsCacheModel, defaultChatData } from './ChatsCacheModel'
|
|
19
30
|
import { ErrorSpottingModel } from '../errorSpotting/ErrorSpottingModel'
|
|
31
|
+
import { ChatBotTextInput } from './ChatBotTextInput'
|
|
20
32
|
import { withEvent } from '../../../lib/effector/withEvent'
|
|
21
33
|
import { ChatBotTextManager } from './ChatBoxTextManager'
|
|
22
34
|
import { ControlledSample } from '../../../lib/effector/ControlledSample'
|
|
23
|
-
|
|
24
|
-
type ReinitConversationProps = {
|
|
25
|
-
key: string
|
|
26
|
-
}
|
|
35
|
+
import { transformAlternatives } from '../helpers'
|
|
27
36
|
|
|
28
37
|
export class ChatbotModel {
|
|
29
38
|
public readonly textManager = new ChatBotTextManager()
|
|
@@ -37,6 +46,7 @@ export class ChatbotModel {
|
|
|
37
46
|
public readonly translation: ChatbotTranslation
|
|
38
47
|
public readonly t2s: ChatTextToSpeechModel
|
|
39
48
|
public readonly errorSpotting: ErrorSpottingModel
|
|
49
|
+
public readonly textInput = new ChatBotTextInput()
|
|
40
50
|
|
|
41
51
|
private readonly setCurrentKey = createEvent<string>()
|
|
42
52
|
public readonly $currentKey = restore(this.setCurrentKey, '')
|
|
@@ -72,13 +82,14 @@ export class ChatbotModel {
|
|
|
72
82
|
constructor({ api, $key, threadMessagesLimit, settings = {} }: ChatbotModelProps) {
|
|
73
83
|
this.api = new ChatbotAPI({ ...api, postMessage: this.threadManager.postMessage })
|
|
74
84
|
|
|
75
|
-
this.threadManager.setApi({ getHint: api.requestHint })
|
|
85
|
+
this.threadManager.setApi({ getHint: api.requestHint, sendMessage: api.sendMessage })
|
|
76
86
|
if (threadMessagesLimit) {
|
|
77
87
|
this.threadManager.setMessagesLimit(threadMessagesLimit)
|
|
78
88
|
}
|
|
79
89
|
|
|
80
|
-
this.$alternatives =
|
|
81
|
-
.on(this.
|
|
90
|
+
this.$alternatives = createStore<GetAlternativesResponse | null>(null)
|
|
91
|
+
.on(this.api.getAlternativesFx.doneData, (_, payload) => transformAlternatives(payload))
|
|
92
|
+
.on(this.setAlternatives, (_, payload) => transformAlternatives(payload))
|
|
82
93
|
.reset(this.resetAlternatives)
|
|
83
94
|
|
|
84
95
|
this.t2s = new ChatTextToSpeechModel({ api: this.api })
|
|
@@ -120,6 +131,11 @@ export class ChatbotModel {
|
|
|
120
131
|
target: this.cache.update,
|
|
121
132
|
})
|
|
122
133
|
|
|
134
|
+
sample({
|
|
135
|
+
clock: this.resetAlternatives,
|
|
136
|
+
target: this.textInput.reset,
|
|
137
|
+
})
|
|
138
|
+
|
|
123
139
|
if (settings.closeOnKeyChange) {
|
|
124
140
|
sample({
|
|
125
141
|
clock: this.$currentKey.updates,
|
|
@@ -152,43 +168,70 @@ export class ChatbotModel {
|
|
|
152
168
|
},
|
|
153
169
|
),
|
|
154
170
|
})
|
|
171
|
+
|
|
172
|
+
this.api.getAlternativesFx.doneData.watch((alternatives) => {
|
|
173
|
+
// Use short text for another hint option if openChatEnabled
|
|
174
|
+
if (alternatives?.chatAccess && alternatives?.isOpenChatEnabled && IS_WEB) {
|
|
175
|
+
this.textManager.update((creator) => ({
|
|
176
|
+
anotherHintOption: creator.createOption('chat.giveHint'),
|
|
177
|
+
}))
|
|
178
|
+
}
|
|
179
|
+
})
|
|
155
180
|
}
|
|
156
181
|
|
|
157
182
|
private createSendHelpRequestFx() {
|
|
158
183
|
const effect = attach({
|
|
159
|
-
source: [this.$currentKey, this.$context],
|
|
160
|
-
mapParams: (params: SendHelpParams, [key, context]) => ({
|
|
184
|
+
source: [this.$currentKey, this.$context, this.cache.$data],
|
|
185
|
+
mapParams: (params: SendHelpParams, [key, context, cache]) => ({
|
|
161
186
|
message: params.message,
|
|
162
187
|
translatedMessage: params.translatedMessage,
|
|
188
|
+
isFreeText: params.isFreeText,
|
|
189
|
+
cache,
|
|
163
190
|
context,
|
|
164
191
|
key,
|
|
165
192
|
}),
|
|
166
|
-
effect: createEffect(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
effect: createEffect(
|
|
194
|
+
async ({ message, translatedMessage, key, context, isFreeText, cache }: SendHelpProps) => {
|
|
195
|
+
if (!context) throw new Error('Trying to send message in chat without context')
|
|
196
|
+
this.setLastMessageKey(key)
|
|
197
|
+
this.cache.addMessages(key, {
|
|
198
|
+
messages: [messagesHelper.createOwn({ message, translatedMessage })],
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
// Request is overridden by ThreadManager.postMessage (delegates to sendMessage/getHint)
|
|
202
|
+
const response = await this.api.postMessageFx({
|
|
203
|
+
answer: context.answer,
|
|
204
|
+
answerOptions: context.answerOptions,
|
|
205
|
+
problemDescription: context.problem,
|
|
206
|
+
problemAnswer: context.problemAnswer,
|
|
207
|
+
language: context.language,
|
|
208
|
+
imageAltText: context.imageDescription,
|
|
209
|
+
imageCdnId: context.imageCdnId,
|
|
210
|
+
conversationId: cache[key].conversationId,
|
|
211
|
+
...(isFreeText && { freeTextMessage: message }),
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
const thread = this.threadManager.get(key)
|
|
215
|
+
const messages = [
|
|
216
|
+
messagesHelper.createAnswer(response, { isInitial: thread?.history.length === 1 }),
|
|
217
|
+
]
|
|
218
|
+
|
|
219
|
+
if (response.endMessage) {
|
|
220
|
+
messages.push(messagesHelper.createLast(this.defaultMessages.endMessage))
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const translatedMessages = await this.translation.applyTranslationFx(messages)
|
|
224
|
+
|
|
225
|
+
this.cache.addMessages(key, {
|
|
226
|
+
messages: translatedMessages,
|
|
227
|
+
thread,
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
if (response.conversationId) {
|
|
231
|
+
this.cache.update({ key, data: { conversationId: response.conversationId } })
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
),
|
|
192
235
|
})
|
|
193
236
|
|
|
194
237
|
sample({
|
|
@@ -272,6 +315,7 @@ export class ChatbotModel {
|
|
|
272
315
|
this.api.postMessageFx.controller.abort()
|
|
273
316
|
this.removeLastMessage()
|
|
274
317
|
}
|
|
318
|
+
this.textInput.reset()
|
|
275
319
|
|
|
276
320
|
this.t2s.stop()
|
|
277
321
|
void this.t2s.reset()
|
|
@@ -284,6 +328,7 @@ export class ChatbotModel {
|
|
|
284
328
|
this.resetAlternatives()
|
|
285
329
|
this.threadManager.reset()
|
|
286
330
|
this.errorSpotting.reset()
|
|
331
|
+
this.textInput.reset()
|
|
287
332
|
})
|
|
288
333
|
|
|
289
334
|
public unbindKey() {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createEvent, restore } from 'effector'
|
|
2
|
+
|
|
3
|
+
export class ChatBotTextInput {
|
|
4
|
+
public readonly setValue = createEvent<string>()
|
|
5
|
+
public readonly setIsFocused = createEvent<boolean>()
|
|
6
|
+
public readonly reset = createEvent()
|
|
7
|
+
|
|
8
|
+
public readonly $value = restore(this.setValue, '').reset(this.reset)
|
|
9
|
+
public readonly $isFocused = restore(this.setIsFocused, false).reset(this.reset)
|
|
10
|
+
}
|
|
@@ -4,12 +4,16 @@ import {
|
|
|
4
4
|
ChatHintResponse,
|
|
5
5
|
PostMessagePayload,
|
|
6
6
|
PostMessageResponse,
|
|
7
|
+
SendMessagePayload,
|
|
8
|
+
SendMessageResponse,
|
|
7
9
|
} from '../types/api.types'
|
|
8
|
-
import { ChatbotMessages, IChatDrawBoardAdapter } from '../types/model.types'
|
|
10
|
+
import { ChatbotMessages, ChatRequestType, IChatDrawBoardAdapter } from '../types/model.types'
|
|
9
11
|
import { CHAT_BOT_MODEL_DEFAULTS } from './constants'
|
|
12
|
+
import { prepareChatRequestPayload } from '../helpers'
|
|
10
13
|
|
|
11
14
|
type ThreadManagerApi = {
|
|
12
15
|
getHint: (props: ChatHintPayload) => Promise<ChatHintResponse>
|
|
16
|
+
sendMessage: (props: SendMessagePayload) => Promise<SendMessageResponse>
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
type ChatBotThreadManagerProps = {
|
|
@@ -63,35 +67,28 @@ export class ChatBotThreadManager {
|
|
|
63
67
|
this.drawBoardAdapter = adapter
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
public readonly postMessage = async (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
answer,
|
|
70
|
-
language,
|
|
71
|
-
imageAltText,
|
|
72
|
-
imageCdnId,
|
|
73
|
-
}: PostMessagePayload): Promise<PostMessageResponse> => {
|
|
70
|
+
public readonly postMessage = async (
|
|
71
|
+
payload: PostMessagePayload,
|
|
72
|
+
): Promise<PostMessageResponse> => {
|
|
74
73
|
if (!this.api) {
|
|
75
74
|
throw new Error(
|
|
76
75
|
'API is not set in ThreadManagersApi, pls provide API before sending requests',
|
|
77
76
|
)
|
|
78
77
|
}
|
|
79
78
|
const threadItem = await this.getThreadItem()
|
|
79
|
+
const { type, data } = prepareChatRequestPayload(payload, threadItem)
|
|
80
80
|
|
|
81
|
-
const result
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
userAnswer: answer,
|
|
86
|
-
language,
|
|
87
|
-
imageAltText,
|
|
88
|
-
imageCdnId,
|
|
89
|
-
})
|
|
81
|
+
const result: SendMessageResponse | ChatHintResponse =
|
|
82
|
+
type === ChatRequestType.Freetext
|
|
83
|
+
? await this.api.sendMessage(data)
|
|
84
|
+
: await this.api.getHint(data)
|
|
90
85
|
|
|
91
86
|
threadItem.history.push(result.message)
|
|
92
|
-
|
|
87
|
+
|
|
88
|
+
if ('errorStrokeIds' in result && result?.errorStrokeIds) {
|
|
93
89
|
threadItem.setErrorStrokesIds(result.errorStrokeIds)
|
|
94
90
|
}
|
|
91
|
+
|
|
95
92
|
const nextOptions =
|
|
96
93
|
threadItem.history.length < this.messagesLimit ? [this.defaultMessages.anotherHintOption] : []
|
|
97
94
|
|
|
@@ -100,6 +97,7 @@ export class ChatBotThreadManager {
|
|
|
100
97
|
options: nextOptions,
|
|
101
98
|
endMessage: !nextOptions.length,
|
|
102
99
|
threadId: threadItem.id,
|
|
100
|
+
conversationId: result?.conversationId ?? null,
|
|
103
101
|
}
|
|
104
102
|
}
|
|
105
103
|
|
|
@@ -4,9 +4,11 @@ import {
|
|
|
4
4
|
ApplyTranslationProps,
|
|
5
5
|
TranslateBatchFxProps,
|
|
6
6
|
TranslateRequestProps,
|
|
7
|
+
TranslateSingleMessageFxParams,
|
|
7
8
|
} from '../types/translation.types'
|
|
8
9
|
import { ChatbotContext, ChatbotMessages } from '../types/model.types'
|
|
9
10
|
import { GetAlternativesResponse } from '../types/api.types'
|
|
11
|
+
import { ConversationMessage } from '../types/units.types'
|
|
10
12
|
import { decodeHTMLEntities } from '../helpers'
|
|
11
13
|
import { ChatbotAPI } from './ChatbotApi'
|
|
12
14
|
import {
|
|
@@ -14,9 +16,7 @@ import {
|
|
|
14
16
|
addTranslationToOptions,
|
|
15
17
|
getOptionsForTranslation,
|
|
16
18
|
} from './translation.helpers'
|
|
17
|
-
|
|
18
19
|
import { ChatsCacheModel } from './ChatsCacheModel'
|
|
19
|
-
import { ConversationMessage } from '../types/units.types'
|
|
20
20
|
|
|
21
21
|
type ChatbotTranslationProps = {
|
|
22
22
|
api: ChatbotAPI
|
|
@@ -41,6 +41,7 @@ export class ChatbotTranslation {
|
|
|
41
41
|
readonly $isTranslated = restore(this.setIsTranslated, false)
|
|
42
42
|
|
|
43
43
|
public readonly translateAllMessagesFx
|
|
44
|
+
public readonly translateSingleMessageFx
|
|
44
45
|
public readonly applyTranslationFx
|
|
45
46
|
|
|
46
47
|
constructor({
|
|
@@ -77,6 +78,35 @@ export class ChatbotTranslation {
|
|
|
77
78
|
effect: this.translateBatchFx,
|
|
78
79
|
})
|
|
79
80
|
|
|
81
|
+
this.translateSingleMessageFx = attach({
|
|
82
|
+
source: { context: this.$context, isTranslationActive: this.$isTranslated },
|
|
83
|
+
mapParams: (message: string, { context, isTranslationActive }) => ({
|
|
84
|
+
message,
|
|
85
|
+
targetLanguage: context?.translationTargetLanguage ?? null,
|
|
86
|
+
isTranslationActive,
|
|
87
|
+
}),
|
|
88
|
+
effect: createEffect(
|
|
89
|
+
async ({
|
|
90
|
+
message,
|
|
91
|
+
targetLanguage,
|
|
92
|
+
isTranslationActive,
|
|
93
|
+
}: TranslateSingleMessageFxParams) => {
|
|
94
|
+
if (!isTranslationActive || !targetLanguage || !message.trim().length) return message
|
|
95
|
+
|
|
96
|
+
const response = await this.api.translateTextFx({
|
|
97
|
+
text: [message],
|
|
98
|
+
targetLanguage,
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
response.data.translations.map(({ translatedText }) =>
|
|
103
|
+
decodeHTMLEntities(translatedText),
|
|
104
|
+
)?.[0] ?? ''
|
|
105
|
+
)
|
|
106
|
+
},
|
|
107
|
+
),
|
|
108
|
+
})
|
|
109
|
+
|
|
80
110
|
sample({
|
|
81
111
|
clock: this.translateAllMessagesFx.doneData,
|
|
82
112
|
filter: (_, translatedMessages) => !!translatedMessages.length,
|
|
@@ -5,28 +5,52 @@ export type GetAlternativesPayload = {
|
|
|
5
5
|
assignmentClassGrade: number
|
|
6
6
|
} | null
|
|
7
7
|
|
|
8
|
+
export type AlternativesOptions = {
|
|
9
|
+
default: ChatAnswer[]
|
|
10
|
+
hints: ChatAnswer[]
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
export type GetAlternativesResponse = {
|
|
9
14
|
chatAccess?: boolean
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
isOpenChatEnabled?: boolean
|
|
16
|
+
version: string
|
|
17
|
+
options: AlternativesOptions
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type SendMessagePayload = {
|
|
21
|
+
problemDescription?: string
|
|
22
|
+
correctAnswer?: string | string[]
|
|
23
|
+
answerOptions?: string[]
|
|
24
|
+
altText?: string
|
|
25
|
+
language?: string
|
|
26
|
+
message: string
|
|
27
|
+
conversationId?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type SendMessageResponse = {
|
|
31
|
+
message: string
|
|
32
|
+
conversationId?: string | null
|
|
14
33
|
}
|
|
15
34
|
|
|
16
35
|
export type PostMessagePayload = {
|
|
17
36
|
language: string
|
|
18
37
|
problemAnswer: string[]
|
|
38
|
+
problemDescription: string
|
|
19
39
|
answer?: string | string[]
|
|
20
|
-
|
|
40
|
+
answerOptions?: string[]
|
|
21
41
|
imageAltText?: string
|
|
22
42
|
imageCdnId?: string
|
|
43
|
+
freeTextMessage?: string
|
|
44
|
+
conversationId?: string | null
|
|
23
45
|
}
|
|
24
46
|
|
|
25
47
|
export type PostMessageResponse = {
|
|
26
48
|
message: string
|
|
27
49
|
options: ChatAnswer[]
|
|
28
|
-
endMessage?: boolean
|
|
29
50
|
threadId: string
|
|
51
|
+
endMessage?: boolean
|
|
52
|
+
conversationId?: string | null
|
|
53
|
+
errorStrokeIds?: string[]
|
|
30
54
|
}
|
|
31
55
|
|
|
32
56
|
export type GoogleTranslatePayload = {
|
|
@@ -71,6 +95,7 @@ export type ChatHintPayload = {
|
|
|
71
95
|
|
|
72
96
|
export type ChatHintResponse = {
|
|
73
97
|
message: string
|
|
98
|
+
conversationId?: string | null
|
|
74
99
|
errorStrokeIds?: string[]
|
|
75
100
|
}
|
|
76
101
|
export type ErrorSpottingPayload = {
|
|
@@ -12,9 +12,11 @@ import {
|
|
|
12
12
|
GoogleTranslateResponse,
|
|
13
13
|
PostMessagePayload,
|
|
14
14
|
PostMessageResponse,
|
|
15
|
+
SendMessagePayload,
|
|
16
|
+
SendMessageResponse,
|
|
15
17
|
} from './api.types'
|
|
16
18
|
import { ExtendWithOptional } from '../../../lib/helpers/types'
|
|
17
|
-
import { ChatAnswer, ConversationMessage, FullStrokeData } from './units.types'
|
|
19
|
+
import { ChatAnswer, ChatItem, ConversationMessage, FullStrokeData } from './units.types'
|
|
18
20
|
|
|
19
21
|
export type ChatbotMessages = {
|
|
20
22
|
error: ConversationMessage
|
|
@@ -25,6 +27,7 @@ export type ChatbotMessages = {
|
|
|
25
27
|
|
|
26
28
|
export type ChatbotApiRequests = {
|
|
27
29
|
getAlternatives: (props: GetAlternativesPayload) => Promise<GetAlternativesResponse>
|
|
30
|
+
sendMessage: (props: SendMessagePayload) => Promise<SendMessageResponse>
|
|
28
31
|
postMessage: (props: PostMessagePayload) => Promise<PostMessageResponse>
|
|
29
32
|
postTranslateText: (props: GoogleTranslatePayload) => Promise<GoogleTranslateResponse>
|
|
30
33
|
postTextToSpeech: (props: GoogleText2SpeechPayload) => Promise<GoogleText2SpeechResponse>
|
|
@@ -50,11 +53,14 @@ export type ChatbotModelProps = {
|
|
|
50
53
|
export type SendHelpParams = {
|
|
51
54
|
message: string
|
|
52
55
|
translatedMessage?: string
|
|
56
|
+
isFreeText?: boolean
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
export type SendHelpProps = SendHelpParams & {
|
|
56
60
|
key: string
|
|
57
61
|
context: ChatbotContext | null
|
|
62
|
+
cache: Record<string, ChatItem>
|
|
63
|
+
isFreeText?: boolean
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
export type SetHintMessageProps = {
|
|
@@ -108,7 +114,34 @@ export type ChatbotContext = {
|
|
|
108
114
|
problem: string
|
|
109
115
|
problemAnswer: string[]
|
|
110
116
|
answer?: string | string[]
|
|
117
|
+
answerOptions?: string[]
|
|
111
118
|
translationTargetLanguage: string
|
|
112
119
|
imageDescription?: string
|
|
113
|
-
|
|
120
|
+
imageCdnId?: string
|
|
114
121
|
}
|
|
122
|
+
|
|
123
|
+
export type ReinitConversationProps = {
|
|
124
|
+
key: string
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export enum ChatRequestType {
|
|
128
|
+
Freetext = 'sendMessage',
|
|
129
|
+
Hint = 'getHint',
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
type FreeTextWithConversationId = {
|
|
133
|
+
type: ChatRequestType.Freetext
|
|
134
|
+
data: Pick<SendMessagePayload, 'message' | 'conversationId'>
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
type FreeTextNewConversation = {
|
|
138
|
+
type: ChatRequestType.Freetext
|
|
139
|
+
data: SendMessagePayload
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export type HintRequest = {
|
|
143
|
+
type: ChatRequestType.Hint
|
|
144
|
+
data: ChatHintPayload
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type ChatRequestPayload = FreeTextWithConversationId | FreeTextNewConversation | HintRequest
|
|
@@ -34,3 +34,9 @@ export type TranslateRequestProps<List extends Record<string, string[]>> = {
|
|
|
34
34
|
textList: List
|
|
35
35
|
targetLanguage: string
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
export type TranslateSingleMessageFxParams = {
|
|
39
|
+
message: string
|
|
40
|
+
targetLanguage: string | null
|
|
41
|
+
isTranslationActive: boolean
|
|
42
|
+
}
|