bibot 1.0.7 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. package/README.md +21 -36
  2. package/dist/component/bibot.d.ts +6 -5
  3. package/dist/config/appStateEnums.d.ts +3 -3
  4. package/dist/config/endpointEnums.d.ts +18 -18
  5. package/dist/config/index.d.ts +3 -3
  6. package/dist/config/statusCode.d.ts +42 -42
  7. package/dist/context/AppContext.d.ts +9 -8
  8. package/dist/context/index.d.ts +1 -1
  9. package/dist/hooks/index.d.ts +3 -3
  10. package/dist/hooks/mobileView.d.ts +1 -1
  11. package/dist/hooks/useBiBotChatBot.d.ts +29 -29
  12. package/dist/hooks/usePluginFactory.d.ts +1 -1
  13. package/dist/index.css +139 -35
  14. package/dist/index.d.ts +6 -2
  15. package/dist/index.js +649 -9
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.modern.js +646 -0
  18. package/dist/index.modern.js.map +1 -0
  19. package/dist/index.test.d.ts +1 -0
  20. package/dist/reducers/appReducer.d.ts +2 -2
  21. package/dist/reducers/index.d.ts +1 -1
  22. package/dist/services/index.d.ts +1 -1
  23. package/dist/services/plugin-api.d.ts +23 -26
  24. package/dist/types/coreInterfaces.d.ts +51 -51
  25. package/dist/types/index.d.ts +1 -1
  26. package/dist/utils/index.d.ts +2 -2
  27. package/dist/utils/sessionManager.d.ts +2 -2
  28. package/dist/utils/trimWhitespace.d.ts +2 -2
  29. package/package.json +62 -37
  30. package/.babelrc +0 -7
  31. package/.vscode/settings.json +0 -5
  32. package/dist/bibot.d.ts +0 -5
  33. package/dist/bibot.js +0 -175
  34. package/dist/bibot.js.map +0 -1
  35. package/dist/component/bibot.js +0 -170
  36. package/dist/component/bibot.js.map +0 -1
  37. package/dist/config/appStateEnums.js +0 -10
  38. package/dist/config/appStateEnums.js.map +0 -1
  39. package/dist/config/endpointEnums.js +0 -31
  40. package/dist/config/endpointEnums.js.map +0 -1
  41. package/dist/config/index.js +0 -38
  42. package/dist/config/index.js.map +0 -1
  43. package/dist/config/statusCode.js +0 -49
  44. package/dist/config/statusCode.js.map +0 -1
  45. package/dist/context/AppContext.js +0 -75
  46. package/dist/context/AppContext.js.map +0 -1
  47. package/dist/context/index.js +0 -16
  48. package/dist/context/index.js.map +0 -1
  49. package/dist/hooks/index.js +0 -38
  50. package/dist/hooks/index.js.map +0 -1
  51. package/dist/hooks/mobileView.js +0 -33
  52. package/dist/hooks/mobileView.js.map +0 -1
  53. package/dist/hooks/useBiBotChatBot.js +0 -206
  54. package/dist/hooks/useBiBotChatBot.js.map +0 -1
  55. package/dist/hooks/usePluginFactory.js +0 -62
  56. package/dist/hooks/usePluginFactory.js.map +0 -1
  57. package/dist/reducers/appReducer.js +0 -24
  58. package/dist/reducers/appReducer.js.map +0 -1
  59. package/dist/reducers/index.js +0 -16
  60. package/dist/reducers/index.js.map +0 -1
  61. package/dist/services/index.js +0 -16
  62. package/dist/services/index.js.map +0 -1
  63. package/dist/services/plugin-api.js +0 -185
  64. package/dist/services/plugin-api.js.map +0 -1
  65. package/dist/styles/RegisterPageStyle.css +0 -63
  66. package/dist/styles/adminPortal.css +0 -26
  67. package/dist/styles/appConfig.css +0 -90
  68. package/dist/styles/buttonStyle.css +0 -27
  69. package/dist/styles/chatStyle.css +0 -140
  70. package/dist/styles/index.css +0 -82
  71. package/dist/styles/predefinedStyle.css +0 -35
  72. package/dist/styles/themeStyle.css +0 -42
  73. package/dist/styles/training.css +0 -86
  74. package/dist/types/coreInterfaces.js +0 -5
  75. package/dist/types/coreInterfaces.js.map +0 -1
  76. package/dist/types/index.js +0 -16
  77. package/dist/types/index.js.map +0 -1
  78. package/dist/utils/index.js +0 -27
  79. package/dist/utils/index.js.map +0 -1
  80. package/dist/utils/sessionManager.js +0 -17
  81. package/dist/utils/sessionManager.js.map +0 -1
  82. package/dist/utils/trimWhitespace.js +0 -15
  83. package/dist/utils/trimWhitespace.js.map +0 -1
  84. package/src/component/bibot.tsx +0 -103
  85. package/src/config/appStateEnums.ts +0 -3
  86. package/src/config/endpointEnums.ts +0 -28
  87. package/src/config/index.ts +0 -5
  88. package/src/config/statusCode.ts +0 -49
  89. package/src/context/AppContext.tsx +0 -66
  90. package/src/context/index.ts +0 -3
  91. package/src/hooks/index.ts +0 -5
  92. package/src/hooks/mobileView.tsx +0 -17
  93. package/src/hooks/useBiBotChatBot.tsx +0 -107
  94. package/src/hooks/usePluginFactory.tsx +0 -38
  95. package/src/index.css +0 -36
  96. package/src/index.tsx +0 -3
  97. package/src/reducers/appReducer.ts +0 -16
  98. package/src/reducers/index.ts +0 -4
  99. package/src/services/index.ts +0 -2
  100. package/src/services/plugin-api.tsx +0 -120
  101. package/src/styles/RegisterPageStyle.css +0 -63
  102. package/src/styles/adminPortal.css +0 -26
  103. package/src/styles/appConfig.css +0 -90
  104. package/src/styles/buttonStyle.css +0 -27
  105. package/src/styles/chatStyle.css +0 -140
  106. package/src/styles/index.css +0 -82
  107. package/src/styles/predefinedStyle.css +0 -35
  108. package/src/styles/themeStyle.css +0 -42
  109. package/src/styles/training.css +0 -86
  110. package/src/types/coreInterfaces.ts +0 -69
  111. package/src/types/index.ts +0 -4
  112. package/src/utils/index.ts +0 -2
  113. package/src/utils/sessionManager.tsx +0 -15
  114. package/src/utils/trimWhitespace.ts +0 -11
  115. package/tsconfig.json +0 -25
  116. package/webpack.config.js +0 -19
@@ -0,0 +1,646 @@
1
+ import React__default, { createContext, useReducer, useEffect, useState, useContext, useRef, useCallback, createElement } from 'react';
2
+ import { Indicator, Avatar, MantineProvider } from '@mantine/core';
3
+ import { SendRounded, Close } from '@mui/icons-material';
4
+ import ChatIcon from '@mui/icons-material/Chat';
5
+ import { message, Button } from 'antd';
6
+ import axios from 'axios';
7
+
8
+ function _extends() {
9
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
10
+ for (var i = 1; i < arguments.length; i++) {
11
+ var source = arguments[i];
12
+ for (var key in source) {
13
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
14
+ target[key] = source[key];
15
+ }
16
+ }
17
+ }
18
+ return target;
19
+ };
20
+ return _extends.apply(this, arguments);
21
+ }
22
+
23
+ var baseUrls = {
24
+ inference: 'https://inference.dev.bibot.thespuka.com/v0'
25
+ };
26
+ var endpoints = {
27
+ get inference() {
28
+ return baseUrls.inference;
29
+ }
30
+ };
31
+ var domain;
32
+ (function (domain) {
33
+ domain["app"] = "/app";
34
+ domain["bibot"] = "/bibot";
35
+ domain["inference"] = "/inference";
36
+ })(domain || (domain = {}));
37
+ var resources;
38
+ (function (resources) {
39
+ resources["chatBubble"] = "/chat-bubble-config";
40
+ resources["predefinedQ"] = "/predefined-q";
41
+ resources["localQ"] = "/local-q";
42
+ resources["timedOutLocalQ"] = "/t-local-q";
43
+ resources["q"] = "/q";
44
+ })(resources || (resources = {}));
45
+
46
+ var inferenceBaseURL = endpoints.inference;
47
+ var createPluginAxiosInstance = function createPluginAxiosInstance(params, headers) {
48
+ if (params === void 0) {
49
+ params = {};
50
+ }
51
+ if (headers === void 0) {
52
+ headers = {};
53
+ }
54
+ var instance = axios.create(_extends({
55
+ baseURL: inferenceBaseURL,
56
+ timeout: 60000,
57
+ headers: _extends({
58
+ 'Content-Type': 'application/json'
59
+ }, headers)
60
+ }, params));
61
+ instance.interceptors.response.use(function (response) {
62
+ return response;
63
+ }, function (error) {
64
+ try {
65
+ var errMsg = 'An unknown error occurred';
66
+ if (error.response) {
67
+ errMsg = error.response.data.message;
68
+ } else if (error.request) {
69
+ errMsg = 'No response received from the server.';
70
+ } else {
71
+ errMsg = "Error setting up the request: " + error.message;
72
+ }
73
+ return Promise.resolve(Promise.reject(new Error(errMsg)));
74
+ } catch (e) {
75
+ return Promise.reject(e);
76
+ }
77
+ });
78
+ return instance;
79
+ };
80
+
81
+ // A type of promise-like that resolves synchronously and supports only one observer
82
+
83
+ const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
84
+
85
+ const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
86
+
87
+ // Asynchronously call a function and send errors to recovery continuation
88
+ function _catch(body, recover) {
89
+ try {
90
+ var result = body();
91
+ } catch(e) {
92
+ return recover(e);
93
+ }
94
+ if (result && result.then) {
95
+ return result.then(void 0, recover);
96
+ }
97
+ return result;
98
+ }
99
+
100
+ // Asynchronously await a promise and pass the result to a finally continuation
101
+ function _finallyRethrows(body, finalizer) {
102
+ try {
103
+ var result = body();
104
+ } catch (e) {
105
+ return finalizer(true, e);
106
+ }
107
+ if (result && result.then) {
108
+ return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
109
+ }
110
+ return finalizer(false, result);
111
+ }
112
+
113
+ var appStateEnums;
114
+ (function (appStateEnums) {
115
+ appStateEnums["BIBOT"] = "BIBOT";
116
+ })(appStateEnums || (appStateEnums = {}));
117
+
118
+ var appReducer = function appReducer(state, action) {
119
+ console.log('This is the appReducer state', state, action);
120
+ switch (action.type) {
121
+ case appStateEnums.BIBOT:
122
+ return _extends({}, state, {
123
+ chatIsOpen: action.chatIsOpen
124
+ });
125
+ default:
126
+ return state;
127
+ }
128
+ };
129
+
130
+ // Unique ID creation requires a high quality random # generator. In the browser we therefore
131
+ // require the crypto API and do not support built-in fallback to lower quality random number
132
+ // generators (like Math.random()).
133
+ let getRandomValues;
134
+ const rnds8 = new Uint8Array(16);
135
+ function rng() {
136
+ // lazy load so that environments that need to polyfill have a chance to do so
137
+ if (!getRandomValues) {
138
+ // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
139
+ getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
140
+
141
+ if (!getRandomValues) {
142
+ throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
143
+ }
144
+ }
145
+
146
+ return getRandomValues(rnds8);
147
+ }
148
+
149
+ /**
150
+ * Convert array of 16 byte values to UUID string format of the form:
151
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
152
+ */
153
+
154
+ const byteToHex = [];
155
+
156
+ for (let i = 0; i < 256; ++i) {
157
+ byteToHex.push((i + 0x100).toString(16).slice(1));
158
+ }
159
+
160
+ function unsafeStringify(arr, offset = 0) {
161
+ // Note: Be careful editing this code! It's been tuned for performance
162
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
163
+ return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
164
+ }
165
+
166
+ const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
167
+ var native = {
168
+ randomUUID
169
+ };
170
+
171
+ function v4(options, buf, offset) {
172
+ if (native.randomUUID && !buf && !options) {
173
+ return native.randomUUID();
174
+ }
175
+
176
+ options = options || {};
177
+ const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
178
+
179
+ rnds[6] = rnds[6] & 0x0f | 0x40;
180
+ rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
181
+
182
+ if (buf) {
183
+ offset = offset || 0;
184
+
185
+ for (let i = 0; i < 16; ++i) {
186
+ buf[offset + i] = rnds[i];
187
+ }
188
+
189
+ return buf;
190
+ }
191
+
192
+ return unsafeStringify(rnds);
193
+ }
194
+
195
+ var SESSION_KEY = 'bibotUserSessionId';
196
+ var getSessionId = function getSessionId() {
197
+ var sessionId = localStorage.getItem(SESSION_KEY);
198
+ if (sessionId === null) {
199
+ var newSessionId = v4();
200
+ localStorage.setItem(SESSION_KEY, newSessionId);
201
+ return newSessionId;
202
+ }
203
+ return sessionId;
204
+ };
205
+
206
+ var dummyDispatch = function dummyDispatch() {};
207
+ var defaultContextValue = {
208
+ state: {
209
+ chatIsOpen: false,
210
+ sessionId: getSessionId()
211
+ },
212
+ dispatch: dummyDispatch
213
+ };
214
+ var AppContext = createContext(defaultContextValue);
215
+ var AppProvider = function AppProvider(_ref) {
216
+ var children = _ref.children;
217
+ var APP_STATE_KEY = 'app_states';
218
+ var initialState = {
219
+ chatIsOpen: false,
220
+ sessionId: getSessionId()
221
+ };
222
+ var _useReducer = useReducer(appReducer, initialState),
223
+ state = _useReducer[0],
224
+ dispatch = _useReducer[1];
225
+ useEffect(function () {
226
+ var storedStates = localStorage.getItem(APP_STATE_KEY);
227
+ if (storedStates) {
228
+ try {
229
+ var parsedStates = JSON.parse(storedStates);
230
+ var updatedStates = _extends({}, initialState, parsedStates);
231
+ console.log(initialState, parsedStates, updatedStates);
232
+ dispatch(_extends({
233
+ type: appStateEnums.BIBOT
234
+ }, updatedStates));
235
+ } catch (error) {
236
+ console.error('Failed to parse app states from local storage:', error);
237
+ }
238
+ }
239
+ }, []);
240
+ useEffect(function () {
241
+ console.log('Changes in state: ', state);
242
+ localStorage.setItem(APP_STATE_KEY, JSON.stringify(state));
243
+ }, [state]);
244
+ return React__default.createElement(AppContext.Provider, {
245
+ value: {
246
+ state: state,
247
+ dispatch: dispatch
248
+ }
249
+ }, children);
250
+ };
251
+
252
+ var getRemoteClientChatPredefinedQuestions = function getRemoteClientChatPredefinedQuestions(params) {
253
+ return Promise.resolve(_catch(function () {
254
+ var path = "" + domain.inference + resources.predefinedQ;
255
+ return Promise.resolve(pluginAxiosInstance.get(path, {
256
+ params: params
257
+ })).then(function (response) {
258
+ return response.data.predefined_messages;
259
+ });
260
+ }, function () {
261
+ return ['These are placeholders', 'They will be removed in production', 'This will be empty if there are no predefined questions', 'So hide if there are no predefined questions'];
262
+ }));
263
+ };
264
+ var getRemoteClientChatBubbleConfig = function getRemoteClientChatBubbleConfig(params) {
265
+ try {
266
+ return Promise.resolve(_catch(function () {
267
+ var path = "" + domain.inference + resources.chatBubble;
268
+ return Promise.resolve(pluginAxiosInstance.get(path, {
269
+ params: params
270
+ })).then(function (response) {
271
+ return response.data;
272
+ });
273
+ }, function () {
274
+ return {
275
+ bgColor: 'white',
276
+ chatColor: 'blue',
277
+ title: 'ChatBot',
278
+ userImage: 'string'
279
+ };
280
+ }));
281
+ } catch (e) {
282
+ return Promise.reject(e);
283
+ }
284
+ };
285
+ var askBiBot = function askBiBot(data) {
286
+ try {
287
+ return Promise.resolve(_catch(function () {
288
+ var path = "" + domain.inference + resources.q;
289
+ return Promise.resolve(pluginAxiosInstance.post(path, data)).then(function (response) {
290
+ console.log(response);
291
+ return response.data.message;
292
+ });
293
+ }, function (error1) {
294
+ console.log(error1.message);
295
+ if (error1.code === 'ECONNABORTED' || error1.message.includes('Endpoint request timed out')) {
296
+ return _catch(function () {
297
+ return Promise.resolve(askTimedOutBiBot(_extends({}, data, {
298
+ tries: 2
299
+ })));
300
+ }, function (error2) {
301
+ if (error2.code === 'ECONNABORTED' || error2.message.includes('Endpoint request timed out')) {
302
+ return _catch(function () {
303
+ return Promise.resolve(askTimedOutBiBot(_extends({}, data, {
304
+ tries: 3
305
+ })));
306
+ }, function (error3) {
307
+ return error3.message;
308
+ });
309
+ } else {
310
+ return error2.message;
311
+ }
312
+ });
313
+ } else {
314
+ return error1.message;
315
+ }
316
+ }));
317
+ } catch (e) {
318
+ return Promise.reject(e);
319
+ }
320
+ };
321
+ var askTimedOutBiBot = function askTimedOutBiBot(data) {
322
+ try {
323
+ return Promise.resolve(_catch(function () {
324
+ var path = "" + domain.bibot + resources.timedOutLocalQ;
325
+ return Promise.resolve(pluginAxiosInstance.post(path, data)).then(function (response) {
326
+ console.log(response);
327
+ return response.data.message;
328
+ });
329
+ }, function (error) {
330
+ console.log(error.message);
331
+ return error.message;
332
+ }));
333
+ } catch (e) {
334
+ return Promise.reject(e);
335
+ }
336
+ };
337
+ var pluginAxiosInstance = createPluginAxiosInstance();
338
+
339
+ var useBiBotChatBot = function useBiBotChatBot(_ref) {
340
+ var sendInputInquiry = function sendInputInquiry() {
341
+ try {
342
+ setIsLoading(true);
343
+ setUserInput('');
344
+ return Promise.resolve(_finallyRethrows(function () {
345
+ return _catch(function () {
346
+ var _temp2 = function () {
347
+ if (userInput.trim()) {
348
+ setMessages(function (messages) {
349
+ return [].concat(messages, [{
350
+ sender: 'user',
351
+ text: userInput
352
+ }]);
353
+ });
354
+ return Promise.resolve(askBiBot({
355
+ client_id: clientId,
356
+ q: userInput.trim(),
357
+ session_id: state.sessionId,
358
+ chat_id: v4()
359
+ })).then(function (response) {
360
+ setMessages(function (messages) {
361
+ return [].concat(messages, [{
362
+ sender: 'bot',
363
+ text: response
364
+ }]);
365
+ });
366
+ });
367
+ }
368
+ }();
369
+ if (_temp2 && _temp2.then) return _temp2.then(function () {});
370
+ }, function (error) {
371
+ var _error$message;
372
+ void message.error((_error$message = error === null || error === void 0 ? void 0 : error.message) != null ? _error$message : 'Failed to get response from server');
373
+ });
374
+ }, function (_wasThrown, _result) {
375
+ setIsLoading(false);
376
+ if (_wasThrown) throw _result;
377
+ return _result;
378
+ }));
379
+ } catch (e) {
380
+ return Promise.reject(e);
381
+ }
382
+ };
383
+ var clientId = _ref.clientId;
384
+ var _useState = useState([]),
385
+ predefinedQuestions = _useState[0],
386
+ setPredefinedQuestions = _useState[1];
387
+ var _useState2 = useState(true),
388
+ showPredefinedQuestions = _useState2[0],
389
+ setShowPredefinedQuestions = _useState2[1];
390
+ var _useContext = useContext(AppContext),
391
+ state = _useContext.state;
392
+ var _useState3 = useState(false),
393
+ chatIsOpen = _useState3[0],
394
+ setChatIsOpen = _useState3[1];
395
+ var _useState4 = useState([]),
396
+ messages = _useState4[0],
397
+ setMessages = _useState4[1];
398
+ var _useState5 = useState(''),
399
+ userInput = _useState5[0],
400
+ setUserInput = _useState5[1];
401
+ var _useState6 = useState(false),
402
+ isLoading = _useState6[0],
403
+ setIsLoading = _useState6[1];
404
+ var messageEndRef = useRef(null);
405
+ var _useState7 = useState(),
406
+ chatBubbleConfig = _useState7[0],
407
+ setChatBubbleConfig = _useState7[1];
408
+ var handlePredefinedQuestionSelect = function handlePredefinedQuestionSelect(question) {
409
+ setUserInput(question);
410
+ sendInputInquiry();
411
+ setShowPredefinedQuestions(false);
412
+ };
413
+ var getChatBubbleConfig = useCallback(function () {
414
+ try {
415
+ return Promise.resolve(getRemoteClientChatPredefinedQuestions({
416
+ client_id: clientId
417
+ })).then(function (remotePredefinedQuestions) {
418
+ if (remotePredefinedQuestions) {
419
+ setPredefinedQuestions(remotePredefinedQuestions);
420
+ }
421
+ return Promise.resolve(getRemoteClientChatBubbleConfig({
422
+ client_id: clientId
423
+ })).then(function (remoteChatBubbleConfig) {
424
+ if (remoteChatBubbleConfig) {
425
+ setChatBubbleConfig(remoteChatBubbleConfig);
426
+ }
427
+ });
428
+ });
429
+ } catch (e) {
430
+ return Promise.reject(e);
431
+ }
432
+ }, [clientId]);
433
+ useEffect(function () {
434
+ void getChatBubbleConfig();
435
+ }, [getChatBubbleConfig]);
436
+ useEffect(function () {
437
+ if (messageEndRef !== null && messageEndRef !== void 0 && messageEndRef.current) {
438
+ messageEndRef.current.scrollIntoView({
439
+ behavior: 'smooth'
440
+ });
441
+ }
442
+ }, [messages]);
443
+ var toggleChat = function toggleChat() {
444
+ console.log('This is it', chatIsOpen);
445
+ setChatIsOpen(!chatIsOpen);
446
+ };
447
+ var handleUserInput = function handleUserInput(e) {
448
+ setUserInput(e.target.value);
449
+ };
450
+ var handleKeyPress = function handleKeyPress(e) {
451
+ try {
452
+ var _temp = function () {
453
+ if (e.key === 'Enter' && !isLoading) {
454
+ return Promise.resolve(sendInputInquiry()).then(function () {});
455
+ }
456
+ }();
457
+ return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
458
+ } catch (e) {
459
+ return Promise.reject(e);
460
+ }
461
+ };
462
+ return {
463
+ chatIsOpen: chatIsOpen,
464
+ messages: messages,
465
+ isLoading: isLoading,
466
+ messageEndRef: messageEndRef,
467
+ userInput: userInput,
468
+ handleUserInput: handleUserInput,
469
+ handleKeyPress: handleKeyPress,
470
+ toggleChat: toggleChat,
471
+ sendInputInquiry: sendInputInquiry,
472
+ chatBubbleConfig: chatBubbleConfig,
473
+ showPredefinedQuestions: showPredefinedQuestions,
474
+ predefinedQuestions: predefinedQuestions,
475
+ handlePredefinedQuestionSelect: handlePredefinedQuestionSelect
476
+ };
477
+ };
478
+
479
+ var styles = {"chat-bubble":"_2jyN5","chat-toggle":"_tXNYe","chat-window":"_1P2y-","chat-header":"_2UNL5","message-list":"_2v5bZ","message":"_2RbY_","user":"_1efWC","bot":"_2idRy","loader":"_3qqrl","l5":"_3cq86","input-area":"_34vFI","loading-bubbles":"_1kl6z","bubble":"_3cleF","bounce":"_UNzJX"};
480
+
481
+ var PredefinedQuestions = function PredefinedQuestions(_ref) {
482
+ var questions = _ref.questions,
483
+ onSelect = _ref.onSelect;
484
+ return createElement("div", {
485
+ className: styles['predefined-questions']
486
+ }, questions.map(function (question, index) {
487
+ return createElement("div", {
488
+ key: index,
489
+ className: styles['predefined-questions'],
490
+ onClick: function onClick() {
491
+ return onSelect(question);
492
+ }
493
+ }, question);
494
+ }));
495
+ };
496
+ var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
497
+ var _chatBubbleConfig$col, _chatBubbleConfig$col2;
498
+ var clientId = _ref2.clientId;
499
+ var _useBiBotChatBot = useBiBotChatBot({
500
+ clientId: clientId
501
+ }),
502
+ chatIsOpen = _useBiBotChatBot.chatIsOpen,
503
+ messages = _useBiBotChatBot.messages,
504
+ isLoading = _useBiBotChatBot.isLoading,
505
+ messageEndRef = _useBiBotChatBot.messageEndRef,
506
+ userInput = _useBiBotChatBot.userInput,
507
+ handleUserInput = _useBiBotChatBot.handleUserInput,
508
+ handleKeyPress = _useBiBotChatBot.handleKeyPress,
509
+ sendInputInquiry = _useBiBotChatBot.sendInputInquiry,
510
+ toggleChat = _useBiBotChatBot.toggleChat,
511
+ chatBubbleConfig = _useBiBotChatBot.chatBubbleConfig,
512
+ showPredefinedQuestions = _useBiBotChatBot.showPredefinedQuestions,
513
+ predefinedQuestions = _useBiBotChatBot.predefinedQuestions,
514
+ handlePredefinedQuestionSelect = _useBiBotChatBot.handlePredefinedQuestionSelect;
515
+ return createElement("div", {
516
+ className: "chat-bubble " + (chatIsOpen ? 'open' : '')
517
+ }, chatIsOpen && createElement("div", {
518
+ className: styles["chat-window"],
519
+ style: {
520
+ backgroundColor: chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.bgColor
521
+ }
522
+ }, createElement("div", {
523
+ className: styles["chat-header"],
524
+ style: {
525
+ backgroundColor: (_chatBubbleConfig$col = chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color) != null ? _chatBubbleConfig$col : '#dedede'
526
+ }
527
+ }, createElement("div", {
528
+ style: {
529
+ alignItems: 'center',
530
+ display: 'flex',
531
+ color: '#fff',
532
+ fontWeight: 'bold'
533
+ }
534
+ }, createElement(Indicator, {
535
+ inline: true,
536
+ size: 12,
537
+ offset: 7,
538
+ position: "bottom-end",
539
+ color: 'green'
540
+ }, createElement(Avatar, {
541
+ color: "white",
542
+ src: chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.logo_url,
543
+ alt: "profile"
544
+ }))), createElement("div", {
545
+ style: {
546
+ display: 'flex',
547
+ flexDirection: 'column',
548
+ textAlign: 'left',
549
+ paddingLeft: '10px',
550
+ justifyContent: 'flex-start',
551
+ color: '#fff'
552
+ }
553
+ }, createElement("span", {
554
+ style: {
555
+ fontWeight: 'bold'
556
+ }
557
+ }, chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.title), isLoading ? createElement("span", {
558
+ style: {
559
+ fontSize: '12px',
560
+ lineHeight: '0.5'
561
+ }
562
+ }, "Typing...") : createElement("span", {
563
+ style: {
564
+ fontSize: '12px',
565
+ lineHeight: '0.5'
566
+ }
567
+ }, 'Online'))), createElement("div", {
568
+ className: styles["message-list"]
569
+ }, messages.map(function (message, index) {
570
+ return message.sender === 'user' ? createElement("div", {
571
+ key: index,
572
+ className: "message " + message.sender
573
+ }, message.text) : createElement("div", {
574
+ key: index,
575
+ style: {
576
+ display: 'flex'
577
+ }
578
+ }, createElement(Avatar, {
579
+ color: "white",
580
+ src: chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.logo_url,
581
+ size: 25,
582
+ alt: "profile"
583
+ }), createElement("div", {
584
+ className: "message " + message.sender
585
+ }, message.text));
586
+ }), showPredefinedQuestions && predefinedQuestions && predefinedQuestions.length > 0 && createElement(PredefinedQuestions, {
587
+ questions: predefinedQuestions,
588
+ onSelect: handlePredefinedQuestionSelect
589
+ }), isLoading && createElement("div", {
590
+ style: {
591
+ marginLeft: '20px'
592
+ },
593
+ className: 'message'
594
+ }, " ", createElement("div", {
595
+ className: "loader"
596
+ }), " "), createElement("div", {
597
+ ref: messageEndRef
598
+ })), createElement("div", {
599
+ className: styles["input-area"]
600
+ }, createElement("input", {
601
+ autoFocus: true,
602
+ type: "text",
603
+ value: userInput,
604
+ onChange: handleUserInput,
605
+ onKeyDown: handleKeyPress,
606
+ placeholder: "Ask a question"
607
+ }), createElement(Button, {
608
+ disabled: isLoading != null ? isLoading : true,
609
+ style: {
610
+ backgroundColor: 'transparent',
611
+ color: isLoading ? '#dedede' : chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color
612
+ },
613
+ size: 'middle',
614
+ icon: createElement(SendRounded, null),
615
+ onClick: sendInputInquiry
616
+ }))), createElement(Button, {
617
+ type: 'link',
618
+ onClick: toggleChat,
619
+ className: styles["chat-toggle"],
620
+ style: {
621
+ backgroundColor: (_chatBubbleConfig$col2 = chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color) != null ? _chatBubbleConfig$col2 : '#dedede'
622
+ }
623
+ }, chatIsOpen ? createElement(Close, {
624
+ style: {
625
+ width: 30,
626
+ height: 30,
627
+ color: '#fff'
628
+ }
629
+ }) : createElement(ChatIcon, {
630
+ style: {
631
+ width: 30,
632
+ height: 30,
633
+ color: '#fff'
634
+ }
635
+ })));
636
+ };
637
+
638
+ var BiBot = function BiBot(_ref) {
639
+ var clientId = _ref.clientId;
640
+ return createElement(AppProvider, null, createElement(MantineProvider, null, createElement(ChatBubbleBiBot, {
641
+ clientId: clientId
642
+ })));
643
+ };
644
+
645
+ export { BiBot };
646
+ //# sourceMappingURL=index.modern.js.map