quickblox-react-ui-kit 0.2.2 → 0.2.3

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 (32) hide show
  1. package/dist/Data/source/remote/Mapper/MessageDTOMapper.d.ts +3 -1
  2. package/dist/Domain/use_cases/ai/AIRephraseUseCase.d.ts +15 -0
  3. package/dist/Domain/use_cases/ai/AIRephraseWithProxyUseCase.d.ts +15 -0
  4. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/AIMessageWidget.d.ts +6 -0
  5. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIAssistAnswerWidget.d.ts +2 -10
  6. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIAssistAnswerWidgetWithProxy.d.ts +2 -0
  7. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIRephraseMessageWidget.d.ts +2 -10
  8. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIRephraseMessageWidgetWithProxy.d.ts +2 -0
  9. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAITranslateWidget.d.ts +2 -10
  10. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAITranslateWidgetWithProxy.d.ts +2 -0
  11. package/dist/index-ui.js +79 -13
  12. package/package.json +1 -1
  13. package/src/App.tsx +3 -1
  14. package/src/Data/source/remote/Mapper/DialogDTOMapper.ts +3 -0
  15. package/src/Data/source/remote/Mapper/MessageDTOMapper.ts +55 -2
  16. package/src/Data/source/remote/RemoteDataSource.ts +2 -1
  17. package/src/Domain/use_cases/ai/AIRephraseUseCase.ts +87 -0
  18. package/src/Domain/use_cases/ai/AIRephraseWithProxyUseCase.ts +71 -0
  19. package/src/Presentation/Views/Dialogs/Dialogs.tsx +1 -1
  20. package/src/Presentation/Views/Dialogs/useDialogsViewModel.ts +4 -1
  21. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/AIMessageWidget.ts +11 -0
  22. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIAssistAnswerWidget.tsx +15 -35
  23. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIAssistAnswerWidgetWithProxy.tsx +79 -0
  24. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIRephraseMessageWidget.tsx +23 -41
  25. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIRephraseMessageWidgetWithProxy.tsx +86 -0
  26. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAITranslateWidget.tsx +15 -33
  27. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAITranslateWidgetWithProxy.tsx +88 -0
  28. package/src/Presentation/components/UI/Dialogs/MessagesView/MessagesView.tsx +19 -17
  29. package/src/Presentation/components/UI/Dialogs/MessagesView/VideoAttachmentComponent/VideoAttachmentComponent.scss +6 -2
  30. package/src/Presentation/components/UI/Dialogs/MessagesView/useMessagesViewModel.ts +13 -3
  31. package/src/Presentation/components/layouts/Desktop/QuickBloxUIKitDesktopLayout.tsx +38 -27
  32. package/src/Presentation/components/providers/QuickBloxUIKitProvider/QuickBloxUIKitProvider.tsx +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quickblox-react-ui-kit",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "main": "dist/index-ui.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
package/src/App.tsx CHANGED
@@ -191,7 +191,9 @@ function App() {
191
191
 
192
192
  useEffect(() => {
193
193
  console.log('0. APP INIT');
194
- prepareSDK(currentUser).catch();
194
+ prepareSDK(currentUser).catch((er) => {
195
+ console.log(er);
196
+ });
195
197
  }, []);
196
198
  //
197
199
  // const { proxyConfig } = QBConfig.configAIApi.AIAnswerAssistWidgetConfig;
@@ -61,6 +61,9 @@ export class DialogDTOMapper implements IDTOMapper {
61
61
  dto.lastMessageId = qbDialog.last_message_id || '';
62
62
  dto.lastMessageText = qbDialog.last_message as string;
63
63
  dto.lastMessageDateSent = qbDialog.last_message_date_sent as string;
64
+ // dto.lastMessageDateSent = (
65
+ // parseInt(qbDialog.last_message_date_sent || '0', 10) * 1000
66
+ // ).toString();
64
67
  dto.lastMessageUserId =
65
68
  qbDialog.last_message_user_id === null
66
69
  ? ''
@@ -39,7 +39,10 @@ export class MessageDTOMapper implements IDTOMapper {
39
39
  }
40
40
 
41
41
  // eslint-disable-next-line class-methods-use-this
42
- public static transformAttachment(qbAtts: ChatMessageAttachment[]) {
42
+ public static transformAttachment(
43
+ qbMessage: string,
44
+ qbAtts: ChatMessageAttachment[],
45
+ ) {
43
46
  const result: ChatMessageAttachmentEntity[] = qbAtts.map((item) => {
44
47
  const newItem: ChatMessageAttachmentEntity = {
45
48
  id: item.id,
@@ -57,6 +60,25 @@ export class MessageDTOMapper implements IDTOMapper {
57
60
  url: item.uid && QB.content.privateUrl(item.uid),
58
61
  },
59
62
  };
63
+ const messageParts = MessageDTOMapper.getMessageParts(qbMessage);
64
+
65
+ if (messageParts && messageParts.length > 0) {
66
+ // val messageBody = "${MediaContentEntity::class.java.simpleName}|$fileName|$uid|$fileMimeType"
67
+ // 0, 1, 2, 3
68
+ // eslint-disable-next-line prefer-destructuring
69
+ newItem.uid = messageParts[2];
70
+ // eslint-disable-next-line prefer-destructuring
71
+ newItem.name = messageParts[1];
72
+ // eslint-disable-next-line prefer-destructuring
73
+ newItem.type = messageParts[3];
74
+ newItem.url = newItem.uid && QB.content.privateUrl(newItem.uid);
75
+ if (newItem.file) {
76
+ newItem.file.uid = newItem.uid;
77
+ newItem.file.name = newItem.name;
78
+ newItem.file.url = newItem.uid && QB.content.privateUrl(newItem.uid);
79
+ newItem.file.type = newItem.type;
80
+ }
81
+ }
60
82
 
61
83
  return newItem;
62
84
  });
@@ -74,7 +96,7 @@ export class MessageDTOMapper implements IDTOMapper {
74
96
 
75
97
  dto.id = qbMessage._id;
76
98
  dto.dialogId = qbMessage.chat_dialog_id;
77
- dto.message = qbMessage.message;
99
+ dto.message = MessageDTOMapper.formatMessage(qbMessage.message);
78
100
  dto.created_at = qbMessage.created_at;
79
101
  dto.date_sent = qbMessage.date_sent * 1000;
80
102
  dto.delivered_ids = qbMessage.delivered_ids ? qbMessage.delivered_ids : [];
@@ -82,6 +104,7 @@ export class MessageDTOMapper implements IDTOMapper {
82
104
 
83
105
  dto.recipient_id = qbMessage.recipient_id ? qbMessage.recipient_id : 0;
84
106
  dto.attachments = MessageDTOMapper.transformAttachment(
107
+ qbMessage.message,
85
108
  qbMessage.attachments ? qbMessage.attachments : [],
86
109
  );
87
110
  dto.read = qbMessage.read;
@@ -98,6 +121,36 @@ export class MessageDTOMapper implements IDTOMapper {
98
121
  return Promise.resolve(dto as TResult);
99
122
  }
100
123
 
124
+ public static formatMessage(qbMessage: string) {
125
+ if (
126
+ qbMessage.includes('MediaContentEntity') ||
127
+ qbMessage.includes('[Attachment]')
128
+ ) {
129
+ const messageParts = qbMessage.split('|');
130
+
131
+ // val messageBody = "${MediaContentEntity::class.java.simpleName}|$fileName|$uid|$fileMimeType"
132
+ // 0, 1, 2, 3
133
+ return messageParts[1] || '';
134
+ }
135
+
136
+ return qbMessage;
137
+ }
138
+
139
+ private static getMessageParts(qbMessage: string) {
140
+ if (
141
+ qbMessage.includes('MediaContentEntity') ||
142
+ qbMessage.includes('[Attachment]')
143
+ ) {
144
+ const messageParts = qbMessage.split('|');
145
+
146
+ // val messageBody = "${MediaContentEntity::class.java.simpleName}|$fileName|$uid|$fileMimeType"
147
+ // 0, 1, 2, 3
148
+ return messageParts;
149
+ }
150
+
151
+ return [];
152
+ }
153
+
101
154
  private static validateDTO(messageDTO: RemoteMessageDTO) {
102
155
  const messageDTOValidator: DtoValidator<RemoteMessageDTO> = {
103
156
  created_at(v: unknown): v is RemoteMessageDTO['created_at'] {
@@ -371,7 +371,7 @@ export class RemoteDataSource implements IRemoteDataSource {
371
371
  const resultMessage = new RemoteMessageDTO();
372
372
 
373
373
  resultMessage.id = message.id;
374
- resultMessage.message = message.body;
374
+ resultMessage.message = MessageDTOMapper.formatMessage(message.body);
375
375
  resultMessage.markable = message.markable
376
376
  ? message.markable.toString()
377
377
  : '0';
@@ -394,6 +394,7 @@ export class RemoteDataSource implements IRemoteDataSource {
394
394
 
395
395
  // resultMessage.attachments = message.extension.attachments || [];
396
396
  resultMessage.attachments = MessageDTOMapper.transformAttachment(
397
+ message.body,
397
398
  message.extension.attachments ? message.extension.attachments : [],
398
399
  );
399
400
 
@@ -0,0 +1,87 @@
1
+ // eslint-disable-next-line import/extensions
2
+ import { AISource, IChatMessage } from '../../../Data/source/AISource';
3
+ import { IUseCase } from '../base/IUseCase';
4
+ import {
5
+ Tone,
6
+ toneToString,
7
+ } from '../../../Presentation/components/UI/Dialogs/MessagesView/AIWidgets/Tone';
8
+
9
+ export class AIRephraseUseCase implements IUseCase<void, string> {
10
+ private textToSend: string;
11
+
12
+ private tone: Tone;
13
+
14
+ private dialogMessages: IChatMessage[];
15
+
16
+ private servername: string;
17
+
18
+ private api: string;
19
+
20
+ private port: string;
21
+
22
+ private sessionToken: string;
23
+
24
+ private openAIModel: string;
25
+
26
+ constructor(
27
+ textToSend: string,
28
+ tone: Tone,
29
+ dialogMessages: IChatMessage[],
30
+ servername: string,
31
+ api: string,
32
+ port: string,
33
+ sessionToken: string,
34
+ openAIModel = 'gpt-3.5-turbo',
35
+ ) {
36
+ console.log('CONSTRUCTOR AIRephraseUseCase');
37
+ this.api = api;
38
+ this.openAIModel = openAIModel;
39
+ this.port = port;
40
+ this.sessionToken = sessionToken;
41
+ this.textToSend = textToSend;
42
+ this.tone = tone;
43
+ this.servername = servername;
44
+ this.dialogMessages = dialogMessages;
45
+ }
46
+
47
+ async execute(): Promise<string> {
48
+ console.log('execute AIRephraseUseCase');
49
+
50
+ let prompt = `Analyze the entire context of our conversation – all the messages – and create a brief summary of our discussion. Based on this analysis, rephrase the following text in a style and tone that is typical for most of the dialogue messages. Provide only the rephrased text in as the message text to rephrase and nothing more.Give me only rephrase text in brackets and nothing more. Here is the message text to rephrase:"${this.textToSend}"`;
51
+
52
+ if (this.tone) {
53
+ prompt = `Analyze the entire context of our conversation – all the messages – and create a brief summary of our discussion. Based on this analysis, rephrase the following text in a ${toneToString(
54
+ this.tone,
55
+ )} style. Provide only the rephrased text in the same language as the message text to rephrase and nothing more.Give me only rephrase text in brackets and nothing more. Here is the message text to rephrase:"${
56
+ this.textToSend
57
+ }"`;
58
+ }
59
+ //
60
+
61
+ // return await AISource.getData(
62
+ // prompt,
63
+ // // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
64
+ // context,
65
+ // servername,
66
+ // api,
67
+ // port,
68
+ // apiKeyOrSessionToken,
69
+ // ).then((data) => {
70
+ // setTextFromWidgetToContent(data);
71
+ //
72
+ // return data;
73
+ // });
74
+
75
+ //
76
+ return AISource.getData(
77
+ prompt,
78
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
79
+ this.dialogMessages,
80
+ this.servername,
81
+ this.api,
82
+ this.port,
83
+ this.sessionToken,
84
+ this.openAIModel,
85
+ );
86
+ }
87
+ }
@@ -0,0 +1,71 @@
1
+ // eslint-disable-next-line import/extensions
2
+ import { AISource, IChatMessage } from '../../../Data/source/AISource';
3
+ import { IUseCase } from '../base/IUseCase';
4
+ import {
5
+ Tone,
6
+ toneToString,
7
+ } from '../../../Presentation/components/UI/Dialogs/MessagesView/AIWidgets/Tone';
8
+
9
+ export class AIRephraseWithProxyUseCase implements IUseCase<void, string> {
10
+ private textToSend: string;
11
+
12
+ private tone: Tone;
13
+
14
+ private dialogMessages: IChatMessage[];
15
+
16
+ private servername: string;
17
+
18
+ private api: string;
19
+
20
+ private port: string;
21
+
22
+ private sessionToken: string;
23
+
24
+ private openAIModel: string;
25
+
26
+ constructor(
27
+ textToSend: string,
28
+ tone: Tone,
29
+ dialogMessages: IChatMessage[],
30
+ servername: string,
31
+ api: string,
32
+ port: string,
33
+ sessionToken: string,
34
+ openAIModel = 'gpt-3.5-turbo',
35
+ ) {
36
+ console.log('CONSTRUCTOR AIRephraseUseCase');
37
+ this.api = api;
38
+ this.openAIModel = openAIModel;
39
+ this.port = port;
40
+ this.sessionToken = sessionToken;
41
+ this.textToSend = textToSend;
42
+ this.tone = tone;
43
+ this.servername = servername;
44
+ this.dialogMessages = dialogMessages;
45
+ }
46
+
47
+ async execute(): Promise<string> {
48
+ console.log('execute AIRephraseUseCase');
49
+
50
+ let prompt = `Analyze the entire context of our conversation – all the messages – and create a brief summary of our discussion. Based on this analysis, rephrase the following text in a style and tone that is typical for most of the dialogue messages. Provide only the rephrased text in as the message text to rephrase and nothing more.Give me only rephrase text in brackets and nothing more. Here is the message text to rephrase:"${this.textToSend}"`;
51
+
52
+ if (this.tone) {
53
+ prompt = `Analyze the entire context of our conversation – all the messages – and create a brief summary of our discussion. Based on this analysis, rephrase the following text in a ${toneToString(
54
+ this.tone,
55
+ )} style. Provide only the rephrased text in the same language as the message text to rephrase and nothing more.Give me only rephrase text in brackets and nothing more. Here is the message text to rephrase:"${
56
+ this.textToSend
57
+ }"`;
58
+ }
59
+
60
+ return AISource.getDataWithProxyServer(
61
+ prompt,
62
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
63
+ this.dialogMessages,
64
+ this.servername,
65
+ this.api,
66
+ this.port,
67
+ this.sessionToken,
68
+ this.openAIModel,
69
+ );
70
+ }
71
+ }
@@ -191,7 +191,7 @@ const DialogsComponent: React.FC<DialogsProps> = ({
191
191
  if (Number.isNaN(dateInt)) {
192
192
  return formattedValue;
193
193
  }
194
- formattedValue = getTimeShort24hFormat(dateInt);
194
+ formattedValue = getTimeShort24hFormat(dateInt * 1000);
195
195
  }
196
196
 
197
197
  return formattedValue;
@@ -67,7 +67,10 @@ export default function useDialogsViewModel(
67
67
 
68
68
  const dialogUpdateHandler = (dialogInfo: DialogEventInfo) => {
69
69
  console.log('call dialogUpdateHandler in useDialogsViewModel');
70
- if (dialogInfo.eventMessageType === EventMessageType.SystemMessage) {
70
+ if (
71
+ dialogInfo.eventMessageType === EventMessageType.SystemMessage
72
+ // || dialogInfo.eventMessageType === EventMessageType.RegularMessage
73
+ ) {
71
74
  if (dialogInfo.notificationTypes === NotificationTypes.UPDATE_DIALOG) {
72
75
  if (dialogInfo.messageInfo) {
73
76
  const { dialogId } = dialogInfo.messageInfo;
@@ -4,6 +4,17 @@ import {
4
4
  FunctionTypeStringWithContextToString,
5
5
  } from '../../../../../Views/Base/BaseViewModel';
6
6
 
7
+ export interface MessageWidgetProps {
8
+ // https://api.openai.com/v1/chat/completions'
9
+ // api: 'v1/chat/completions',
10
+ // servername: 'https://myproxy.com',
11
+ // https://func270519800.azurewebsites.net/api/TranslateTextToEng
12
+ servername: string;
13
+ api: string;
14
+ port: string;
15
+ apiKeyOrSessionToken: string;
16
+ }
17
+
7
18
  export interface AIWidget {
8
19
  renderWidget: FunctionTypeJSXElement;
9
20
  }
@@ -1,26 +1,25 @@
1
1
  import { useState } from 'react';
2
- import { AIMessageWidget } from './AIMessageWidget';
2
+ import { AIMessageWidget, MessageWidgetProps } from './AIMessageWidget';
3
3
  import AIWidgetIcon from '../../../svgs/Icons/AIWidgets/AIWidget';
4
4
  import ErrorMessageIcon from './ErrorMessageIcon';
5
5
  import { AISource, IChatMessage } from '../../../../../../Data/source/AISource';
6
6
 
7
- interface MessageWidgetProps {
8
- // https://api.openai.com/v1/chat/completions'
9
- // api: 'v1/chat/completions',
10
- // servername: 'https://myproxy.com',
11
- // https://func270519800.azurewebsites.net/api/TranslateTextToEng
12
- servername: string;
13
- api: string;
14
- port: string;
15
- sessionToken: string;
16
- apiKey: string;
17
- }
7
+ // interface MessageWidgetProps {
8
+ // // https://api.openai.com/v1/chat/completions'
9
+ // // api: 'v1/chat/completions',
10
+ // // servername: 'https://myproxy.com',
11
+ // // https://func270519800.azurewebsites.net/api/TranslateTextToEng
12
+ // servername: string;
13
+ // api: string;
14
+ // port: string;
15
+ // apiKeyOrSessionToken: string;
16
+ // apiKey: string;
17
+ // }
18
18
  export default function UseDefaultAIAssistAnswerWidget({
19
19
  servername,
20
20
  api,
21
21
  port,
22
- sessionToken,
23
- apiKey,
22
+ apiKeyOrSessionToken,
24
23
  }: MessageWidgetProps): AIMessageWidget {
25
24
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
26
25
  const [errorMessage, setErrorMessage] = useState<string>('');
@@ -53,39 +52,20 @@ export default function UseDefaultAIAssistAnswerWidget({
53
52
  if (textToSend && textToSend.length > 0) {
54
53
  const prompt = `You are a customer support chat operator. Your goal is to provide helpful and informative responses to customer inquiries. Give a response to the next user's query, considering the entire conversation context, and use grammar and vocabulary at the A2-B2 level. Answer in the format of simple sentences. Do not include question in answer. Please, provide answer for this issue:"${textToSend}"`;
55
54
 
56
- if (apiKey.length > 0) {
57
- // eslint-disable-next-line no-return-await
58
- return await AISource.getData(
59
- prompt,
60
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
61
- context,
62
- servername,
63
- api,
64
- port,
65
- sessionToken,
66
- ).then((data) => {
67
- setTextFromWidgetToContent(data);
68
-
69
- return data;
70
- });
71
- }
72
-
73
55
  // eslint-disable-next-line no-return-await
74
- return await AISource.getDataWithProxyServer(
56
+ return await AISource.getData(
75
57
  prompt,
76
58
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
77
59
  context,
78
60
  servername,
79
61
  api,
80
62
  port,
81
- sessionToken,
63
+ apiKeyOrSessionToken,
82
64
  ).then((data) => {
83
65
  setTextFromWidgetToContent(data);
84
66
 
85
67
  return data;
86
68
  });
87
-
88
- // eslint-disable-next-line no-return-await
89
69
  }
90
70
 
91
71
  return '';
@@ -0,0 +1,79 @@
1
+ import { useState } from 'react';
2
+ import { AIMessageWidget, MessageWidgetProps } from './AIMessageWidget';
3
+ import AIWidgetIcon from '../../../svgs/Icons/AIWidgets/AIWidget';
4
+ import ErrorMessageIcon from './ErrorMessageIcon';
5
+ import { AISource, IChatMessage } from '../../../../../../Data/source/AISource';
6
+
7
+ // interface MessageWidgetProps {
8
+ // // https://api.openai.com/v1/chat/completions'
9
+ // // api: 'v1/chat/completions',
10
+ // // servername: 'https://myproxy.com',
11
+ // // https://func270519800.azurewebsites.net/api/TranslateTextToEng
12
+ // servername: string;
13
+ // api: string;
14
+ // port: string;
15
+ // apiKeyOrSessionToken: string;
16
+ // apiKey: string;
17
+ // }
18
+ export default function UseDefaultAIAssistAnswerWidgetWithProxy({
19
+ servername,
20
+ api,
21
+ port,
22
+ apiKeyOrSessionToken,
23
+ }: MessageWidgetProps): AIMessageWidget {
24
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
25
+ const [errorMessage, setErrorMessage] = useState<string>('');
26
+
27
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
28
+ const fileToWidget = (file: File, context: IChatMessage[]): void => {};
29
+
30
+ const renderWidget = (): JSX.Element => {
31
+ if (errorMessage && errorMessage.length > 0) {
32
+ const errorsDescriptions:
33
+ | { title: string; action: () => void }[]
34
+ | undefined = [];
35
+
36
+ return (
37
+ <ErrorMessageIcon
38
+ errorMessageText={errorMessage}
39
+ errorsDescriptions={errorsDescriptions}
40
+ />
41
+ );
42
+ }
43
+
44
+ return <AIWidgetIcon applyZoom color="green" />;
45
+ };
46
+
47
+ const [textFromWidgetToContent, setTextFromWidgetToContent] = useState('');
48
+ const textToWidget = async (
49
+ textToSend: string,
50
+ context: IChatMessage[],
51
+ ): Promise<string> => {
52
+ if (textToSend && textToSend.length > 0) {
53
+ const prompt = `You are a customer support chat operator. Your goal is to provide helpful and informative responses to customer inquiries. Give a response to the next user's query, considering the entire conversation context, and use grammar and vocabulary at the A2-B2 level. Answer in the format of simple sentences. Do not include question in answer. Please, provide answer for this issue:"${textToSend}"`;
54
+
55
+ // eslint-disable-next-line no-return-await
56
+ return await AISource.getDataWithProxyServer(
57
+ prompt,
58
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
59
+ context,
60
+ servername,
61
+ api,
62
+ port,
63
+ apiKeyOrSessionToken,
64
+ ).then((data) => {
65
+ setTextFromWidgetToContent(data);
66
+
67
+ return data;
68
+ });
69
+ }
70
+
71
+ return '';
72
+ };
73
+
74
+ return {
75
+ textToContent: textFromWidgetToContent,
76
+ renderWidget,
77
+ textToWidget,
78
+ };
79
+ }
@@ -1,24 +1,24 @@
1
1
  import { useState } from 'react';
2
- import { AIMessageWidget } from './AIMessageWidget';
2
+ import { AIMessageWidget, MessageWidgetProps } from './AIMessageWidget';
3
3
  import ErrorMessageIcon from './ErrorMessageIcon';
4
4
  import AIWidgetIcon from '../../../svgs/Icons/AIWidgets/AIWidget';
5
- import { Tone, toneToString } from './Tone';
6
- import { AISource, IChatMessage } from '../../../../../../Data/source/AISource';
5
+ import { Tone } from './Tone';
6
+ import { IChatMessage } from '../../../../../../Data/source/AISource';
7
+ import { AIRephraseUseCase } from '../../../../../../Domain/use_cases/ai/AIRephraseUseCase';
7
8
 
8
- interface MessageWidgetProps {
9
- servername: string;
10
- api: string;
11
- port: string;
12
- sessionToken: string;
13
- apiKey: string;
14
- }
9
+ // interface MessageWidgetProps {
10
+ // servername: string;
11
+ // api: string;
12
+ // port: string;
13
+ // apiKeyOrSessionToken: string;
14
+ // apiKey: string;
15
+ // }
15
16
 
16
17
  export default function UseDefaultAIRephraseMessageWidget({
17
18
  servername,
18
19
  api,
19
20
  port,
20
- sessionToken,
21
- apiKey,
21
+ apiKeyOrSessionToken,
22
22
  }: MessageWidgetProps): AIMessageWidget {
23
23
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
24
24
  const [errorMessage, setErrorMessage] = useState<string>('');
@@ -51,42 +51,24 @@ export default function UseDefaultAIRephraseMessageWidget({
51
51
  additionalSettings?: { [key: string]: any },
52
52
  ): Promise<string> => {
53
53
  if (textToSend && textToSend.length > 0) {
54
- let prompt = `Analyze the entire context of our conversation – all the messages – and create a brief summary of our discussion. Based on this analysis, rephrase the following text in a style and tone that is typical for most of the dialogue messages. Provide only the rephrased text in as the message text to rephrase and nothing more.Give me only rephrase text in brackets and nothing more. Here is the message text to rephrase:"${textToSend}"`;
55
54
  const { tone } = additionalSettings || {};
56
55
 
57
- if (tone) {
58
- prompt = `Analyze the entire context of our conversation – all the messages – and create a brief summary of our discussion. Based on this analysis, rephrase the following text in a ${toneToString(
59
- tone as Tone,
60
- )} style. Provide only the rephrased text in the same language as the message text to rephrase and nothing more.Give me only rephrase text in brackets and nothing more. Here is the message text to rephrase:"${textToSend}"`;
61
- }
62
-
63
- if (apiKey.length > 0) {
64
- // eslint-disable-next-line no-return-await
65
- return await AISource.getData(
66
- prompt,
67
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
68
- context,
69
- servername,
70
- api,
71
- port,
72
- sessionToken,
73
- ).then((data) => {
74
- setTextFromWidgetToContent(data);
56
+ const openAIModel = 'gpt-3.5-turbo';
75
57
 
76
- return data;
77
- });
78
- }
79
-
80
- // eslint-disable-next-line no-return-await
81
- return await AISource.getDataWithProxyServer(
82
- prompt,
83
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
58
+ // AIRephraseWithProxyUseCase
59
+ const useCaseAIRephrase = new AIRephraseUseCase(
60
+ textToSend,
61
+ tone as Tone,
84
62
  context,
85
63
  servername,
86
64
  api,
87
65
  port,
88
- sessionToken,
89
- ).then((data) => {
66
+ apiKeyOrSessionToken,
67
+ openAIModel,
68
+ );
69
+
70
+ // eslint-disable-next-line no-return-await
71
+ return await useCaseAIRephrase.execute().then((data) => {
90
72
  setTextFromWidgetToContent(data);
91
73
 
92
74
  return data;