quickblox-react-ui-kit 0.3.1 → 0.4.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/README.md +0 -324
- package/dist/CommonTypes/CommonTypes.d.ts +1 -0
- package/dist/Data/source/remote/IRemoteDataSource.d.ts +3 -0
- package/dist/Data/source/remote/RemoteDataSource.d.ts +3 -0
- package/dist/Domain/use_cases/ai/AIAnswerAssistWithSDKUseCase.d.ts +11 -0
- package/dist/Domain/use_cases/ai/AITranslateWithSDKUseCase.d.ts +12 -0
- package/dist/Presentation/Views/Dialog/AIWidgets/UseDefaultAIAssistAnswerWidgetWithSDK.d.ts +3 -0
- package/dist/Presentation/Views/Dialog/AIWidgets/UseDefaultAITranslateWidgetWithSDK.d.ts +3 -0
- package/dist/Presentation/ui-components/TextField/TextField.d.ts +1 -1
- package/dist/index-ui.js +500 -3
- package/dist/index-ui.js.map +1 -1
- package/dist/qb-api-calls/index.d.ts +3 -1
- package/package.json +3 -5
- package/src/CommonTypes/CommonTypes.ts +1 -0
- package/src/Data/DefaultConfigurations.ts +3 -0
- package/src/Data/repository/ConnectionRepository.ts +2 -1
- package/src/Data/source/remote/IRemoteDataSource.ts +13 -0
- package/src/Data/source/remote/RemoteDataSource.ts +22 -0
- package/src/Domain/use_cases/ai/AIAnswerAssistWithSDKUseCase.ts +50 -0
- package/src/Domain/use_cases/ai/AITranslateWithSDKUseCase.ts +107 -0
- package/src/Presentation/Views/Dialog/AIWidgets/UseDefaultAIAssistAnswerWidgetWithSDK.tsx +74 -0
- package/src/Presentation/Views/Dialog/AIWidgets/UseDefaultAITranslateWidgetWithSDK.tsx +70 -0
- package/src/Presentation/layouts/Desktop/QuickBloxUIKitDesktopLayout.tsx +14 -2
- package/src/QBconfig.ts +3 -0
- package/src/package_artan_react_ui.json +91 -0
- package/src/package_original.json +115 -0
- package/src/qb-api-calls/index.ts +49 -0
- package/storybook-static/{703.776b9f13.iframe.bundle.js → 703.f12f2e71.iframe.bundle.js} +2 -2
- package/storybook-static/{703.776b9f13.iframe.bundle.js.map → 703.f12f2e71.iframe.bundle.js.map} +1 -1
- package/storybook-static/docs-Introduction-mdx.9dc275f1.iframe.bundle.js +10 -0
- package/storybook-static/{docs-Introduction-mdx.bcb06844.iframe.bundle.js.map → docs-Introduction-mdx.9dc275f1.iframe.bundle.js.map} +1 -1
- package/storybook-static/docs-Styling-mdx.72149f36.iframe.bundle.js +10 -0
- package/storybook-static/{docs-Styling-mdx.1d6c1212.iframe.bundle.js.map → docs-Styling-mdx.72149f36.iframe.bundle.js.map} +1 -1
- package/storybook-static/iframe.html +1 -1
- package/storybook-static/index.html +4 -8
- package/storybook-static/project.json +1 -1
- package/storybook-static/{runtime~main.3464b25a.iframe.bundle.js → runtime~main.72d6302b.iframe.bundle.js} +1 -1
- package/tsconfig.buildlib.json +33 -0
- package/storybook-static/docs-Introduction-mdx.bcb06844.iframe.bundle.js +0 -10
- package/storybook-static/docs-Styling-mdx.1d6c1212.iframe.bundle.js +0 -10
- package/storybook-static/sb-addons/onboarding-7/manager-bundle.js +0 -503
- package/storybook-static/sb-addons/onboarding-7/manager-bundle.js.LEGAL.txt +0 -48
- /package/storybook-static/sb-addons/{interactions-8 → interactions-7}/manager-bundle.js +0 -0
- /package/storybook-static/sb-addons/{interactions-8 → interactions-7}/manager-bundle.js.LEGAL.txt +0 -0
- /package/storybook-static/sb-addons/{viewport-9 → viewport-8}/manager-bundle.js +0 -0
- /package/storybook-static/sb-addons/{viewport-9 → viewport-8}/manager-bundle.js.LEGAL.txt +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChatConnectParams, GetMessagesResult, GetUserParams, ListUserParams, ListUserResponse, QBBlob, QBBlobCreateUploadParams, QBCustomObject, QBDataDeletedResponse, QBGetDialogResult, QBLoginParams, QBMediaParams, QBMessageStatusParams, QBSession, QBSystemMessage, QBUser, QBUserCreateParams, QBWebRTCSession } from 'quickblox/quickblox';
|
|
1
|
+
import { AIAnswerResponse, AIChatHistory, ChatConnectParams, GetMessagesResult, GetUserParams, ListUserParams, ListUserResponse, QBBlob, QBBlobCreateUploadParams, QBCustomObject, QBDataDeletedResponse, QBGetDialogResult, QBLoginParams, QBMediaParams, QBMessageStatusParams, QBSession, QBSystemMessage, QBUser, QBUserCreateParams, QBWebRTCSession } from 'quickblox/quickblox';
|
|
2
2
|
import { QBUIKitChatDialog, QBUIKitChatNewMessage, QBUIKitConfig } from '../CommonTypes/CommonTypes';
|
|
3
3
|
export type QBInitParams = {
|
|
4
4
|
appIdOrToken: string | number;
|
|
@@ -72,3 +72,5 @@ export declare function QBChatSendSystemMessage(to: QBUser['id'] | string, messa
|
|
|
72
72
|
export declare function QBChatMarkMessageRead(params: QBMessageStatusParams): void;
|
|
73
73
|
export declare function QBChatMarkMessageDelivered(params: QBMessageStatusParams): void;
|
|
74
74
|
export declare function QBWebRTCSessionGetUserMedia(session: QBWebRTCSession, params: QBMediaParams): Promise<MediaStream | undefined>;
|
|
75
|
+
export declare function QBAnswerAssist(smartChatAssistantId: string, messageToAssist: string, history: AIChatHistory): Promise<AIAnswerResponse>;
|
|
76
|
+
export declare function QBTranslate(smartChatAssistantId: string, textToTranslate: string, languageCode: string): Promise<AIAnswerResponse>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quickblox-react-ui-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"main": "dist/index-ui.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"qb-ai-core": "^0.1.3",
|
|
13
13
|
"qb-ai-rephrase": "^0.1.2",
|
|
14
14
|
"qb-ai-translate": "^0.1.2",
|
|
15
|
-
"quickblox": "^2.
|
|
15
|
+
"quickblox": "^2.17.0",
|
|
16
16
|
"react": "^18.2.0",
|
|
17
17
|
"react-dom": "^18.2.0",
|
|
18
18
|
"react-router-dom": "^6.11.1",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"@storybook/addon-essentials": "^7.6.12",
|
|
27
27
|
"@storybook/addon-interactions": "^7.6.12",
|
|
28
28
|
"@storybook/addon-links": "^7.6.12",
|
|
29
|
-
"@storybook/addon-onboarding": "^1.0.11",
|
|
30
29
|
"@storybook/addon-viewport": "^7.6.16",
|
|
31
30
|
"@storybook/blocks": "^7.6.12",
|
|
32
31
|
"@storybook/preset-create-react-app": "^7.6.12",
|
|
@@ -87,8 +86,7 @@
|
|
|
87
86
|
"lint": "eslint ./src",
|
|
88
87
|
"eject": "react-scripts eject",
|
|
89
88
|
"storybook": "storybook dev -p 6006",
|
|
90
|
-
"build-storybook": "storybook build"
|
|
91
|
-
"build:storybook": "storybook build"
|
|
89
|
+
"build-storybook": "storybook build"
|
|
92
90
|
},
|
|
93
91
|
"lint-staged": {
|
|
94
92
|
"src/**/*.{ts,tsx}": "eslint"
|
|
@@ -147,6 +147,7 @@ export class DefaultConfigurations {
|
|
|
147
147
|
AIAnswerAssistWidgetConfig: {
|
|
148
148
|
organizationName: 'Quickblox',
|
|
149
149
|
openAIModel: 'gpt-3.5-turbo',
|
|
150
|
+
smartChatAssistantId: '',
|
|
150
151
|
apiKey: '',
|
|
151
152
|
maxTokens: 3584,
|
|
152
153
|
useDefault: true,
|
|
@@ -159,6 +160,7 @@ export class DefaultConfigurations {
|
|
|
159
160
|
AITranslateWidgetConfig: {
|
|
160
161
|
organizationName: 'Quickblox',
|
|
161
162
|
openAIModel: 'gpt-3.5-turbo',
|
|
163
|
+
smartChatAssistantId: '',
|
|
162
164
|
apiKey: '',
|
|
163
165
|
maxTokens: 3584,
|
|
164
166
|
useDefault: true,
|
|
@@ -178,6 +180,7 @@ export class DefaultConfigurations {
|
|
|
178
180
|
AIRephraseWidgetConfig: {
|
|
179
181
|
organizationName: 'Quickblox',
|
|
180
182
|
openAIModel: 'gpt-3.5-turbo',
|
|
183
|
+
smartChatAssistantId: '',
|
|
181
184
|
apiKey: '',
|
|
182
185
|
maxTokens: 3584,
|
|
183
186
|
useDefault: true,
|
|
@@ -104,7 +104,8 @@ export default class ConnectionRepository extends SubscriptionPerformer<boolean>
|
|
|
104
104
|
const pingChat = (): Promise<string> => {
|
|
105
105
|
return new Promise<string>((resolve, reject) => {
|
|
106
106
|
try {
|
|
107
|
-
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
108
|
+
QB.chat.pingchat((error) => {
|
|
108
109
|
if (error) {
|
|
109
110
|
console.log('ping failed: ', stringifyError(error));
|
|
110
111
|
resolve('failed');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AIChatHistory, AIAnswerResponse } from 'quickblox';
|
|
1
2
|
import { RemoteDialogDTO } from '../../dto/dialog/RemoteDialogDTO';
|
|
2
3
|
import { RemoteDialogsDTO } from '../../dto/dialog/RemoteDialogsDTO';
|
|
3
4
|
import { RemoteUserDTO } from '../../dto/user/RemoteUserDTO';
|
|
@@ -111,4 +112,16 @@ export interface IRemoteDataSource extends IRemoteMessaging<RemoteMessageDTO> {
|
|
|
111
112
|
subscribeToChatConnectionEvents(fileId: string): Promise<void>;
|
|
112
113
|
|
|
113
114
|
updateCurrentDialog(dto: RemoteDialogDTO): void;
|
|
115
|
+
|
|
116
|
+
createAnswer(
|
|
117
|
+
text: string,
|
|
118
|
+
messages: AIChatHistory,
|
|
119
|
+
smartChatAssistantId: string,
|
|
120
|
+
): Promise<AIAnswerResponse>;
|
|
121
|
+
|
|
122
|
+
translate(
|
|
123
|
+
text: string,
|
|
124
|
+
languageCode: string,
|
|
125
|
+
smartChatAssistantId: string,
|
|
126
|
+
): Promise<AIAnswerResponse>;
|
|
114
127
|
}
|
|
@@ -14,6 +14,8 @@ import QB, {
|
|
|
14
14
|
QBSystemMessage,
|
|
15
15
|
QBUser,
|
|
16
16
|
QBMessageStatusParams,
|
|
17
|
+
AIChatHistory,
|
|
18
|
+
AIAnswerResponse,
|
|
17
19
|
} from 'quickblox/quickblox';
|
|
18
20
|
import { RemoteDialogDTO } from '../../dto/dialog/RemoteDialogDTO';
|
|
19
21
|
import {
|
|
@@ -34,6 +36,7 @@ import { DialogDTOMapper } from './Mapper/DialogDTOMapper';
|
|
|
34
36
|
import { IDTOMapper } from './Mapper/IDTOMapper';
|
|
35
37
|
import { Stubs } from '../../Stubs';
|
|
36
38
|
import {
|
|
39
|
+
QBAnswerAssist,
|
|
37
40
|
QBChatConnect,
|
|
38
41
|
QBChatDisconnect,
|
|
39
42
|
qbChatGetMessagesExtended,
|
|
@@ -56,6 +59,7 @@ import {
|
|
|
56
59
|
QBLogout,
|
|
57
60
|
QBSendIsStopTypingStatus,
|
|
58
61
|
QBSendIsTypingStatus,
|
|
62
|
+
QBTranslate,
|
|
59
63
|
QBUpdateDialog,
|
|
60
64
|
QBUsersGet,
|
|
61
65
|
QBUsersGetById,
|
|
@@ -179,6 +183,24 @@ export class RemoteDataSource implements IRemoteDataSource {
|
|
|
179
183
|
new SubscriptionPerformer<RemoteMessageDTO>();
|
|
180
184
|
}
|
|
181
185
|
|
|
186
|
+
// eslint-disable-next-line class-methods-use-this
|
|
187
|
+
createAnswer(
|
|
188
|
+
text: string,
|
|
189
|
+
messages: AIChatHistory,
|
|
190
|
+
smartChatAssistantId: string,
|
|
191
|
+
): Promise<AIAnswerResponse> {
|
|
192
|
+
return QBAnswerAssist(smartChatAssistantId, text, messages);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// eslint-disable-next-line class-methods-use-this
|
|
196
|
+
translate(
|
|
197
|
+
text: string,
|
|
198
|
+
languageCode: string,
|
|
199
|
+
smartChatAssistantId: string,
|
|
200
|
+
): Promise<AIAnswerResponse> {
|
|
201
|
+
return QBTranslate(smartChatAssistantId, text, languageCode);
|
|
202
|
+
}
|
|
203
|
+
|
|
182
204
|
async updateCurrentDialog(dto: RemoteDialogDTO): Promise<void> {
|
|
183
205
|
this.currentDialog = dto;
|
|
184
206
|
//
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// eslint-disable-next-line import/extensions
|
|
2
|
+
import { AIAnswerResponse, AIChatMessage, AIRole } from 'quickblox';
|
|
3
|
+
import { IChatMessage } from '../../../Data/source/AISource';
|
|
4
|
+
import { IUseCase } from '../base/IUseCase';
|
|
5
|
+
import { IRemoteDataSource } from '../../../Data/source/remote/IRemoteDataSource';
|
|
6
|
+
|
|
7
|
+
// interface AIChatMessageEx extends AIChatMessage {
|
|
8
|
+
// content: string;
|
|
9
|
+
// } // artik 19.05.2024
|
|
10
|
+
export class AIAnswerAssistWithSDKUseCase implements IUseCase<void, string> {
|
|
11
|
+
private textToSend: string;
|
|
12
|
+
|
|
13
|
+
private dialogMessages: IChatMessage[];
|
|
14
|
+
|
|
15
|
+
private dataSource: IRemoteDataSource;
|
|
16
|
+
|
|
17
|
+
private smartChatAssistantId: string;
|
|
18
|
+
|
|
19
|
+
constructor(
|
|
20
|
+
textToSend: string,
|
|
21
|
+
dialogMessages: IChatMessage[],
|
|
22
|
+
dataSource: IRemoteDataSource,
|
|
23
|
+
smartChatAssistantId: string,
|
|
24
|
+
) {
|
|
25
|
+
console.log('CONSTRUCTOR AIAnswerAssistWithSDKUseCase');
|
|
26
|
+
this.textToSend = textToSend;
|
|
27
|
+
this.dialogMessages = dialogMessages;
|
|
28
|
+
this.dataSource = dataSource;
|
|
29
|
+
this.smartChatAssistantId = smartChatAssistantId;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async execute(): Promise<string> {
|
|
33
|
+
console.log('execute AIAnswerAssistWithSDKUseCase');
|
|
34
|
+
const history: AIChatMessage[] = this.dialogMessages.map(
|
|
35
|
+
(msg: IChatMessage) => {
|
|
36
|
+
return {
|
|
37
|
+
role: msg.role as AIRole,
|
|
38
|
+
message: msg.content,
|
|
39
|
+
} as AIChatMessage;
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
const response: AIAnswerResponse = await this.dataSource.createAnswer(
|
|
43
|
+
this.textToSend,
|
|
44
|
+
history,
|
|
45
|
+
this.smartChatAssistantId,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return response.answer;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// eslint-disable-next-line import/extensions
|
|
2
|
+
import { AIAnswerResponse } from 'quickblox/quickblox';
|
|
3
|
+
import { IUseCase } from '../base/IUseCase';
|
|
4
|
+
import { IRemoteDataSource } from '../../../Data/source/remote/IRemoteDataSource';
|
|
5
|
+
|
|
6
|
+
export class AITranslateWithSDKUseCase implements IUseCase<void, string> {
|
|
7
|
+
private languageCodes: { [key: string]: string } = {
|
|
8
|
+
English: 'en',
|
|
9
|
+
Spanish: 'es',
|
|
10
|
+
'Chinese simplified': 'zh-Hans',
|
|
11
|
+
'Chinese traditional': 'zh-Hant',
|
|
12
|
+
French: 'fr',
|
|
13
|
+
German: 'de',
|
|
14
|
+
Japanese: 'ja',
|
|
15
|
+
Korean: 'ko',
|
|
16
|
+
Italian: 'it',
|
|
17
|
+
Russian: 'ru',
|
|
18
|
+
Portuguese: 'pt',
|
|
19
|
+
Arabic: 'ar',
|
|
20
|
+
Hindi: 'hi',
|
|
21
|
+
Turkish: 'tr',
|
|
22
|
+
Dutch: 'nl',
|
|
23
|
+
Polish: 'pl',
|
|
24
|
+
Ukrainian: 'uk',
|
|
25
|
+
Albanian: 'sq',
|
|
26
|
+
Armenian: 'hy',
|
|
27
|
+
Azerbaijani: 'az',
|
|
28
|
+
Basque: 'eu',
|
|
29
|
+
Belarusian: 'be',
|
|
30
|
+
Bengali: 'bn',
|
|
31
|
+
Bosnian: 'bs',
|
|
32
|
+
Bulgarian: 'bg',
|
|
33
|
+
Catalan: 'ca',
|
|
34
|
+
Croatian: 'hr',
|
|
35
|
+
Czech: 'cs',
|
|
36
|
+
Danish: 'da',
|
|
37
|
+
Estonian: 'et',
|
|
38
|
+
Finnish: 'fi',
|
|
39
|
+
Galician: 'gl',
|
|
40
|
+
Georgian: 'ka',
|
|
41
|
+
Greek: 'el',
|
|
42
|
+
Gujarati: 'gu',
|
|
43
|
+
Hungarian: 'hu',
|
|
44
|
+
Indonesian: 'id',
|
|
45
|
+
Irish: 'ga',
|
|
46
|
+
Kannada: 'kn',
|
|
47
|
+
Kazakh: 'kk',
|
|
48
|
+
Latvian: 'lv',
|
|
49
|
+
Lithuanian: 'lt',
|
|
50
|
+
Macedonian: 'mk',
|
|
51
|
+
Malay: 'ms',
|
|
52
|
+
Maltese: 'mt',
|
|
53
|
+
Mongolian: 'mn',
|
|
54
|
+
Nepali: 'ne',
|
|
55
|
+
Norwegian: 'no',
|
|
56
|
+
Pashto: 'ps',
|
|
57
|
+
Persian: 'fa',
|
|
58
|
+
Punjabi: 'pa',
|
|
59
|
+
Romanian: 'ro',
|
|
60
|
+
Sanskrit: 'sa',
|
|
61
|
+
Serbian: 'sr',
|
|
62
|
+
Sindhi: 'sd',
|
|
63
|
+
Sinhala: 'si',
|
|
64
|
+
Slovak: 'sk',
|
|
65
|
+
Slovenian: 'sl',
|
|
66
|
+
Uzbek: 'uz',
|
|
67
|
+
Vietnamese: 'vi',
|
|
68
|
+
Welsh: 'cy',
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
private textToSend: string;
|
|
72
|
+
|
|
73
|
+
private language: string;
|
|
74
|
+
|
|
75
|
+
private dataSource: IRemoteDataSource;
|
|
76
|
+
|
|
77
|
+
private smartChatAssistantId: string;
|
|
78
|
+
|
|
79
|
+
constructor(
|
|
80
|
+
textToSend: string,
|
|
81
|
+
language: string,
|
|
82
|
+
dataSource: IRemoteDataSource,
|
|
83
|
+
smartChatAssistantId: string,
|
|
84
|
+
) {
|
|
85
|
+
console.log('CONSTRUCTOR AITranslateWithSDKUseCase');
|
|
86
|
+
this.dataSource = dataSource;
|
|
87
|
+
this.textToSend = textToSend;
|
|
88
|
+
this.language = language;
|
|
89
|
+
this.smartChatAssistantId = smartChatAssistantId;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getLanguageCode(language: string): string {
|
|
93
|
+
return this.languageCodes[language] || 'en';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async execute(): Promise<string> {
|
|
97
|
+
console.log('execute AITranslateWithSDKUseCase');
|
|
98
|
+
|
|
99
|
+
const response: AIAnswerResponse = await this.dataSource.translate(
|
|
100
|
+
this.textToSend,
|
|
101
|
+
this.getLanguageCode(this.language),
|
|
102
|
+
this.smartChatAssistantId,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
return response.answer;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { AIMessageWidget } from './AIMessageWidget';
|
|
3
|
+
import AIWidgetIcon from '../../../components/UI/svgs/Icons/AIWidgets/AIWidget';
|
|
4
|
+
import ErrorMessageIcon from './ErrorMessageIcon';
|
|
5
|
+
import { IChatMessage } from '../../../../Data/source/AISource';
|
|
6
|
+
import { RemoteDataSource } from '../../../../Data/source/remote/RemoteDataSource';
|
|
7
|
+
import { AIAnswerAssistWithSDKUseCase } from '../../../../Domain/use_cases/ai/AIAnswerAssistWithSDKUseCase';
|
|
8
|
+
|
|
9
|
+
export default function UseDefaultAIAssistAnswerWidgetWithSDK(
|
|
10
|
+
dataSource: RemoteDataSource,
|
|
11
|
+
smartChatAssistantId: string,
|
|
12
|
+
): AIMessageWidget {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14
|
+
const [errorMessage, setErrorMessage] = useState<string>('');
|
|
15
|
+
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
|
|
17
|
+
const fileToWidget = (file: File, context: IChatMessage[]): void => {};
|
|
18
|
+
|
|
19
|
+
const renderWidget = (): JSX.Element => {
|
|
20
|
+
if (errorMessage && errorMessage.length > 0) {
|
|
21
|
+
const errorsDescriptions:
|
|
22
|
+
| { title: string; action: () => void }[]
|
|
23
|
+
| undefined = [];
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<ErrorMessageIcon
|
|
27
|
+
errorMessageText={errorMessage}
|
|
28
|
+
errorsDescriptions={errorsDescriptions}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return <AIWidgetIcon applyZoom color="green" />;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const [textFromWidgetToContent, setTextFromWidgetToContent] = useState('');
|
|
37
|
+
const textToWidget = async (
|
|
38
|
+
textToSend: string,
|
|
39
|
+
context: IChatMessage[],
|
|
40
|
+
): Promise<string> => {
|
|
41
|
+
if (textToSend && textToSend.length > 0) {
|
|
42
|
+
const useCaseAIAnswerAssist = new AIAnswerAssistWithSDKUseCase(
|
|
43
|
+
textToSend,
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
45
|
+
context,
|
|
46
|
+
dataSource,
|
|
47
|
+
smartChatAssistantId,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// eslint-disable-next-line no-return-await
|
|
51
|
+
return await useCaseAIAnswerAssist
|
|
52
|
+
.execute()
|
|
53
|
+
.then((data) => {
|
|
54
|
+
setTextFromWidgetToContent(data);
|
|
55
|
+
|
|
56
|
+
return data;
|
|
57
|
+
})
|
|
58
|
+
.catch((reason) => {
|
|
59
|
+
console.log('SDK: ai answer assist error: ', reason);
|
|
60
|
+
setTextFromWidgetToContent(JSON.stringify(reason));
|
|
61
|
+
|
|
62
|
+
return reason;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return '';
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
textToContent: textFromWidgetToContent,
|
|
71
|
+
renderWidget,
|
|
72
|
+
textToWidget,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import AIWidgetIcon from '../../../components/UI/svgs/Icons/AIWidgets/AIWidget';
|
|
3
|
+
import ErrorMessageIcon from './ErrorMessageIcon';
|
|
4
|
+
import { AIMessageWidget } from './AIMessageWidget';
|
|
5
|
+
import { IChatMessage } from '../../../../Data/source/AISource';
|
|
6
|
+
import { RemoteDataSource } from '../../../../Data/source/remote/RemoteDataSource';
|
|
7
|
+
import { AITranslateWithSDKUseCase } from '../../../../Domain/use_cases/ai/AITranslateWithSDKUseCase';
|
|
8
|
+
|
|
9
|
+
export default function UseDefaultAITranslateWidgetWithSDK(
|
|
10
|
+
dataSource: RemoteDataSource,
|
|
11
|
+
smartChatAssistantId: string,
|
|
12
|
+
): AIMessageWidget {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14
|
+
const [errorMessage, setErrorMessage] = useState<string>('');
|
|
15
|
+
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
|
|
17
|
+
const fileToWidget = (file: File, context: IChatMessage[]): void => {};
|
|
18
|
+
|
|
19
|
+
const renderWidget = (): JSX.Element => {
|
|
20
|
+
if (errorMessage && errorMessage.length > 0) {
|
|
21
|
+
const errorsDescriptions:
|
|
22
|
+
| { title: string; action: () => void }[]
|
|
23
|
+
| undefined = [];
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<ErrorMessageIcon
|
|
27
|
+
errorMessageText={errorMessage}
|
|
28
|
+
errorsDescriptions={errorsDescriptions}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return <AIWidgetIcon applyZoom color="green" />;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const [textFromWidgetToContent, setTextFromWidgetToContent] = useState('');
|
|
37
|
+
const textToWidget = async (
|
|
38
|
+
textToSend: string,
|
|
39
|
+
context: IChatMessage[],
|
|
40
|
+
additionalSettings?: { [key: string]: any },
|
|
41
|
+
): Promise<string> => {
|
|
42
|
+
if (textToSend && textToSend.length > 0) {
|
|
43
|
+
// eslint-disable-next-line no-return-await
|
|
44
|
+
const { language } = additionalSettings || {};
|
|
45
|
+
|
|
46
|
+
const useCaseAITranslate = new AITranslateWithSDKUseCase(
|
|
47
|
+
textToSend,
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
49
|
+
language,
|
|
50
|
+
dataSource,
|
|
51
|
+
smartChatAssistantId,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// eslint-disable-next-line no-return-await
|
|
55
|
+
return await useCaseAITranslate.execute().then((data) => {
|
|
56
|
+
setTextFromWidgetToContent(data);
|
|
57
|
+
|
|
58
|
+
return data;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return '';
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
textToContent: textFromWidgetToContent,
|
|
67
|
+
renderWidget,
|
|
68
|
+
textToWidget,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -62,6 +62,8 @@ import useQBConnection from '../../providers/QuickBloxUIKitProvider/useQBConnect
|
|
|
62
62
|
import { ProxyConfig } from '../../../CommonTypes/CommonTypes';
|
|
63
63
|
import EventMessageType from '../../../Domain/entity/EventMessageType';
|
|
64
64
|
import { formatFileSize } from '../../../utils/formatFileSize';
|
|
65
|
+
import UseDefaultAIAssistAnswerWidgetWithSDK from '../../Views/Dialog/AIWidgets/UseDefaultAIAssistAnswerWidgetWithSDK';
|
|
66
|
+
import UseDefaultAITranslateWidgetWithSDK from '../../Views/Dialog/AIWidgets/UseDefaultAITranslateWidgetWithSDK';
|
|
65
67
|
|
|
66
68
|
type AIWidgetPlaceHolder = {
|
|
67
69
|
enabled: boolean;
|
|
@@ -116,7 +118,12 @@ const QuickBloxUIKitDesktopLayout: React.FC<
|
|
|
116
118
|
let defaultAIAssistWidget = AIAssist?.AIWidget;
|
|
117
119
|
|
|
118
120
|
const getAIAssistAnswer = (): void => {
|
|
119
|
-
if (
|
|
121
|
+
if (QBConfig.configAIApi.AIAnswerAssistWidgetConfig.smartChatAssistantId) {
|
|
122
|
+
defaultAIAssistWidget = UseDefaultAIAssistAnswerWidgetWithSDK(
|
|
123
|
+
currentContext.storage.REMOTE_DATA_SOURCE,
|
|
124
|
+
QBConfig.configAIApi.AIAnswerAssistWidgetConfig.smartChatAssistantId,
|
|
125
|
+
);
|
|
126
|
+
} else if (AIAssist?.enabled && !AIAssist?.default) {
|
|
120
127
|
defaultAIAssistWidget = AIAssist.AIWidget;
|
|
121
128
|
} else if (
|
|
122
129
|
AIAssist?.enabled ||
|
|
@@ -151,7 +158,12 @@ const QuickBloxUIKitDesktopLayout: React.FC<
|
|
|
151
158
|
}
|
|
152
159
|
};
|
|
153
160
|
const getAITranslate = (): void => {
|
|
154
|
-
if (
|
|
161
|
+
if (QBConfig.configAIApi.AITranslateWidgetConfig.smartChatAssistantId) {
|
|
162
|
+
defaultAITranslateWidget = UseDefaultAITranslateWidgetWithSDK(
|
|
163
|
+
currentContext.storage.REMOTE_DATA_SOURCE,
|
|
164
|
+
QBConfig.configAIApi.AITranslateWidgetConfig.smartChatAssistantId,
|
|
165
|
+
);
|
|
166
|
+
} else if (AITranslate?.enabled && !AITranslate?.default) {
|
|
155
167
|
defaultAITranslateWidget = AITranslate.AIWidget;
|
|
156
168
|
} else if (
|
|
157
169
|
AITranslate?.enabled ||
|
package/src/QBconfig.ts
CHANGED
|
@@ -12,6 +12,7 @@ export const QBConfig: QBUIKitConfig = {
|
|
|
12
12
|
AIAnswerAssistWidgetConfig: {
|
|
13
13
|
organizationName: 'Quickblox',
|
|
14
14
|
openAIModel: 'gpt-3.5-turbo',
|
|
15
|
+
smartChatAssistantId: '',
|
|
15
16
|
apiKey: '',
|
|
16
17
|
maxTokens: 3584,
|
|
17
18
|
useDefault: true,
|
|
@@ -24,6 +25,7 @@ export const QBConfig: QBUIKitConfig = {
|
|
|
24
25
|
AITranslateWidgetConfig: {
|
|
25
26
|
organizationName: 'Quickblox',
|
|
26
27
|
openAIModel: 'gpt-3.5-turbo',
|
|
28
|
+
smartChatAssistantId: '',
|
|
27
29
|
apiKey: '',
|
|
28
30
|
maxTokens: 3584,
|
|
29
31
|
useDefault: true,
|
|
@@ -50,6 +52,7 @@ export const QBConfig: QBUIKitConfig = {
|
|
|
50
52
|
AIRephraseWidgetConfig: {
|
|
51
53
|
organizationName: 'Quickblox',
|
|
52
54
|
openAIModel: 'gpt-3.5-turbo',
|
|
55
|
+
smartChatAssistantId: '',
|
|
53
56
|
apiKey: '',
|
|
54
57
|
maxTokens: 3584,
|
|
55
58
|
useDefault: true,
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "artan-react-ui-sample",
|
|
3
|
+
"version": "0.0.55",
|
|
4
|
+
"main": "dist/index-ui.js",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@types/node": "^16.18.6",
|
|
8
|
+
"@types/react": "^18.0.26",
|
|
9
|
+
"@types/react-dom": "^18.0.9",
|
|
10
|
+
"classnames": "^2.3.2",
|
|
11
|
+
"qb-ai-answer-assistant": "^0.1.0",
|
|
12
|
+
"qb-ai-core": "^0.1.0",
|
|
13
|
+
"qb-ai-rephrase": "^0.1.0",
|
|
14
|
+
"qb-ai-translate": "^0.1.0",
|
|
15
|
+
"react": "^18.2.0",
|
|
16
|
+
"react-dom": "^18.2.0",
|
|
17
|
+
"react-router-dom": "^6.11.1",
|
|
18
|
+
"react-scripts": "5.0.1",
|
|
19
|
+
"rxjs": "^7.8.0",
|
|
20
|
+
"typescript": "^4.9.3",
|
|
21
|
+
"web-vitals": "^2.1.4"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@testing-library/jest-dom": "^5.16.5",
|
|
25
|
+
"@testing-library/react": "^13.4.0",
|
|
26
|
+
"@testing-library/user-event": "^13.5.0",
|
|
27
|
+
"@types/jest": "^27.5.2",
|
|
28
|
+
"@types/node": "^16.18.6",
|
|
29
|
+
"@types/react": "^18.0.26",
|
|
30
|
+
"@types/react-dom": "^18.0.9",
|
|
31
|
+
"@typescript-eslint/eslint-plugin-tslint": "^5.45.1",
|
|
32
|
+
"@typescript-eslint/parser": "^5.45.1",
|
|
33
|
+
"classnames": "^2.3.2",
|
|
34
|
+
"css-loader": "^6.7.3",
|
|
35
|
+
"eslint": "^8.29.0",
|
|
36
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
37
|
+
"eslint-config-prettier": "^8.5.0",
|
|
38
|
+
"eslint-import-resolver-typescript": "^3.5.2",
|
|
39
|
+
"eslint-plugin-import": "^2.26.0",
|
|
40
|
+
"eslint-plugin-jsx-a11y": "^6.6.1",
|
|
41
|
+
"eslint-plugin-no-loops": "^0.3.0",
|
|
42
|
+
"eslint-plugin-optimize-regex": "^1.2.1",
|
|
43
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
44
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
45
|
+
"eslint-plugin-react": "^7.31.11",
|
|
46
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
47
|
+
"prettier": "^2.8.0",
|
|
48
|
+
"react": "^18.2.0",
|
|
49
|
+
"react-dom": "^18.2.0",
|
|
50
|
+
"react-router-dom": "^6.4.3",
|
|
51
|
+
"react-scripts": "5.0.1",
|
|
52
|
+
"sass": "^1.62.1",
|
|
53
|
+
"sass-loader": "^13.2.2",
|
|
54
|
+
"style-loader": "^3.3.2",
|
|
55
|
+
"ts-loader": "^9.4.2",
|
|
56
|
+
"typedoc": "^0.23.22",
|
|
57
|
+
"typescript": "^4.9.3",
|
|
58
|
+
"web-vitals": "^2.1.4",
|
|
59
|
+
"webpack": "^5.82.1",
|
|
60
|
+
"webpack-cli": "^5.1.1"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"start": "react-scripts start",
|
|
64
|
+
"build": "react-scripts build",
|
|
65
|
+
"build:lib": "webpack",
|
|
66
|
+
"test": "react-scripts test",
|
|
67
|
+
"lint": "eslint ./src",
|
|
68
|
+
"eject": "react-scripts eject"
|
|
69
|
+
},
|
|
70
|
+
"lint-staged": {
|
|
71
|
+
"src/**/*.{ts,tsx}": "eslint"
|
|
72
|
+
},
|
|
73
|
+
"eslintConfig": {
|
|
74
|
+
"extends": [
|
|
75
|
+
"react-app",
|
|
76
|
+
"react-app/jest"
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
"browserslist": {
|
|
80
|
+
"production": [
|
|
81
|
+
">0.2%",
|
|
82
|
+
"not dead",
|
|
83
|
+
"not op_mini all"
|
|
84
|
+
],
|
|
85
|
+
"development": [
|
|
86
|
+
"last 1 chrome version",
|
|
87
|
+
"last 1 firefox version",
|
|
88
|
+
"last 1 safari version"
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
}
|