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
@@ -1,42 +0,0 @@
1
- @tailwind base;
2
- @tailwind components;
3
- @tailwind utilities;
4
-
5
- .light {
6
- /* Light mode colors */
7
- --bg-color: #f0f0f0;
8
- --text-color: #333;
9
- --bg-light: #fff;
10
- --text-light: #333;
11
- --hover-bg-light: #000;
12
- --hover-text-light: #fff;
13
- --expanded-bg-light: #f5f5f5;
14
- --sidebar-text-light: #333;
15
- --sidebar-hover-bg-light: #000;
16
- --sidebar-hover-text-light: #fff;
17
- --sidebar-expanded-bg-light: #f5f5f5;
18
- --border-color: blue;
19
- --highlight-color: #ffcc00;
20
- --bg-logo: url('/src/assets/logo/preauditai-high-resolution-logo-transparent.png')
21
- }
22
-
23
- .dark {
24
- /* Dark mode colors */
25
- --bg-color: #333;
26
- --text-color: #f0f0f0;
27
- --bg-dark: #333;
28
- --text-dark: #fff;
29
- --hover-bg-dark: #555;
30
- --hover-text-dark: #fff;
31
- --expanded-bg-dark: #444;
32
- --sidebar-bg-dark: #333;
33
- --sidebar-text-dark: #fff;
34
- --sidebar-hover-bg-dark: #555;
35
- --sidebar-hover-text-dark: #fff;
36
- --sidebar-expanded-bg-dark: #444;
37
- --border-color: blue;
38
- --highlight-color: #007bff;
39
- --bg-logo: url('/src/assets/logo/preauditai-high-resolution-logo-black-transparent.png')
40
- }
41
-
42
-
@@ -1,86 +0,0 @@
1
- .mainContainer{
2
- display: flex;
3
- flex-direction: column;
4
- align-items: flex-start;
5
- }
6
- .contentContainer{
7
- width: 100%;
8
- display: flex;
9
- justify-content: space-between;
10
- text-align: start;
11
- flex-wrap: wrap;
12
- }
13
- .fileUploadSection{
14
- width: 50%;
15
- }
16
- .fileInfoSection{
17
- display: flex;
18
- width: 40%;
19
- }
20
- .fileUploaderContainer{
21
- border: 3px dotted #929292;
22
- border-radius: 10px;
23
- padding: 30px;
24
- display: flex;
25
- align-items: center;
26
- justify-content: center;
27
- flex-direction: column;
28
- width: 100%;
29
- cursor: pointer;
30
- }
31
- .fileUploader{
32
- width: 100%;
33
- text-align: start;
34
- }
35
-
36
-
37
- /* Media query for screens smaller than 600px */
38
- @media screen and (max-width: 600px) {
39
- .fileUploaderContainer{
40
- background-color: #f2f2f2;
41
- padding: 30px;
42
- display: flex;
43
- align-items: center;
44
- width: 100%;
45
- }
46
- .btn{
47
- width: 100% !important;
48
- margin-top: 30px;
49
- }
50
- .fileUploadSection{
51
- width: 100%;
52
- margin-bottom: 30px;
53
- }
54
- .fileInfoSection{
55
- display: flex;
56
- width: 100%;
57
- }
58
- }
59
-
60
- /* Media query for screens between 600px and 900px */
61
- @media screen and (min-width: 600px) and (max-width: 900px) {
62
- .fileUploaderContainer{
63
- background-color: #f2f2f2;
64
- padding: 30px;
65
- display: flex;
66
- align-items: center;
67
- width: 100%;
68
- }
69
- .btn{
70
- width: 100% !important;
71
- margin-top: 30px;
72
- }
73
- .fileUploadSection{
74
- width: 100%;
75
- margin-bottom: 30px;
76
- }
77
- .fileInfoSection{
78
- display: flex;
79
- width: 100%;
80
- }
81
- }
82
-
83
- /* Media query for screens larger than 1200px */
84
- @media screen and (min-width: 1200px) {
85
-
86
- }
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1 +0,0 @@
1
- {"version":3,"file":"coreInterfaces.js","sourceRoot":"","sources":["../../src/types/coreInterfaces.ts"],"names":[],"mappings":""}
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _coreInterfaces = require("./coreInterfaces");
7
- Object.keys(_coreInterfaces).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _coreInterfaces[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function get() {
13
- return _coreInterfaces[key];
14
- }
15
- });
16
- });
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,iCAAiC;AAEjC,cAAc,kBAAkB,CAAA"}
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _trimWhitespace = require("./trimWhitespace");
7
- Object.keys(_trimWhitespace).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _trimWhitespace[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function get() {
13
- return _trimWhitespace[key];
14
- }
15
- });
16
- });
17
- var _sessionManager = require("./sessionManager");
18
- Object.keys(_sessionManager).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _sessionManager[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function get() {
24
- return _sessionManager[key];
25
- }
26
- });
27
- });
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA"}
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getSessionId = void 0;
7
- var _uuid = require("uuid");
8
- var SESSION_KEY = 'bibotUserSessionId';
9
- var getSessionId = exports.getSessionId = function getSessionId() {
10
- var sessionId = localStorage.getItem(SESSION_KEY);
11
- if (sessionId === null) {
12
- var newSessionId = (0, _uuid.v4)();
13
- localStorage.setItem(SESSION_KEY, newSessionId);
14
- return newSessionId;
15
- }
16
- return sessionId;
17
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"sessionManager.js","sourceRoot":"","sources":["../../src/utils/sessionManager.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AAEnC,IAAM,WAAW,GAAW,oBAAoB,CAAA;AAEhD,IAAM,YAAY,GAAG;IACnB,IAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IACnD,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;QACvB,IAAM,YAAY,GAAG,MAAM,EAAE,CAAA;QAC7B,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,YAAY,CAAC,CAAA;QAC/C,OAAO,YAAY,CAAA;IACrB,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.trimWhitespace = void 0;
7
- var trimWhitespace = exports.trimWhitespace = function trimWhitespace(e) {
8
- // Check if the event has a target (it's an input event)
9
- if (e !== null && e !== void 0 && e.target) {
10
- // If it's a string, trim the whitespace; otherwise, return the value as is
11
- return typeof e.target.value === 'string' ? e.target.value.trim() : e.target.value;
12
- }
13
- // If it's not an input event, return the value as is
14
- return e;
15
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"trimWhitespace.js","sourceRoot":"","sources":["../../src/utils/trimWhitespace.ts"],"names":[],"mappings":"AAAA,IAAM,cAAc,GAAG,UAAC,CAAM;IAC5B,wDAAwD;IACxD,IAAI,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,MAAM,EAAE,CAAC;QACd,2EAA2E;QAC3E,OAAO,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAA;IACpF,CAAC;IACD,qDAAqD;IACrD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAED,OAAO,EAAE,cAAc,EAAE,CAAA"}
@@ -1,103 +0,0 @@
1
- import { Avatar, Indicator } from '@mantine/core'
2
- import { Close, SendRounded } from '@mui/icons-material'
3
- import ChatIcon from '@mui/icons-material/Chat'
4
- import { Button } from 'antd'
5
- import { useBiBotChatBot } from '../hooks'
6
- import { AppProvider } from '../context/AppContext'
7
- interface bubbleProps {
8
- clientId: string
9
- }
10
-
11
- interface PredefinedQuestionsProps {
12
- onSelect: (question: string) => void
13
- questions: string[]
14
- }
15
-
16
- const PredefinedQuestions = ({ questions, onSelect }: PredefinedQuestionsProps) => {
17
- return (
18
- <div className="predefined-questions">
19
- {questions.map((question, index) => (
20
- <div key={index} className="predefined-question" onClick={() => onSelect(question)}>
21
- {question}
22
- </div>
23
- ))}
24
- </div>
25
- );
26
- };
27
-
28
- const BiBot = ({ clientId }: bubbleProps) => {
29
- const {
30
- chatIsOpen,
31
- messages,
32
- isLoading,
33
- messageEndRef,
34
- userInput,
35
- handleUserInput,
36
- handleKeyPress,
37
- sendInputInquiry,
38
- toggleChat,
39
- chatBubbleConfig,
40
- showPredefinedQuestions,
41
- predefinedQuestions,
42
- handlePredefinedQuestionSelect,
43
- } = useBiBotChatBot({clientId})
44
-
45
- return (
46
- <AppProvider>
47
- <div className={`chat-bubble ${chatIsOpen ? 'open' : ''}`}>
48
- {chatIsOpen && (
49
- <div className="chat-window" style={{ backgroundColor: chatBubbleConfig?.bgColor }}>
50
- <div className="chat-header" style={{ backgroundColor: chatBubbleConfig?.color ?? '#dedede' }}>
51
- <div style={{ alignItems: 'center', display: 'flex', color: '#fff', fontWeight: 'bold' }}>
52
- <Indicator inline size={12} offset={7} position="bottom-end" color={ 'green' }>
53
- <Avatar color="white" src={chatBubbleConfig?.logo_url} alt="profile" />
54
- </Indicator>
55
- </div>
56
- <div style={{ display: 'flex', flexDirection: 'column', textAlign: 'left', paddingLeft: '10px', justifyContent: 'flex-start', color: '#fff' }}>
57
- <span style={{ fontWeight: 'bold' }}>{chatBubbleConfig?.title}</span>
58
- {}
59
- {isLoading ? <span style={{ fontSize: '12px', lineHeight: '0.5' }}>Typing...</span> : <span style={{ fontSize: '12px', lineHeight: '0.5' }}>{'Online'}</span>}
60
- </div>
61
- </div>
62
- <div className="message-list">
63
- {messages.map((message: { sender: 'user' | 'bot', text: string }, index: number) => (
64
- message.sender === 'user'
65
- ? <div key={index} className={`message ${message.sender}`}>
66
- {message.text}
67
- </div>
68
- : <div key={index} style={{ display: 'flex' }}>
69
- <Avatar color="white" src={chatBubbleConfig?.logo_url} size={25} alt="profile" />
70
- <div className={`message ${message.sender}`}>
71
- {message.text}
72
- </div>
73
- </div>
74
- ))}
75
- {showPredefinedQuestions && predefinedQuestions && predefinedQuestions.length > 0 && (
76
- <PredefinedQuestions questions={predefinedQuestions} onSelect={handlePredefinedQuestionSelect} />
77
- )}
78
- {isLoading && <div style={{marginLeft: '20px'}} className='message'> <div className="loader"></div> </div> }
79
- <div ref={messageEndRef} />
80
- </div>
81
- <div className="input-area">
82
- <input
83
- autoFocus={true}
84
- type="text"
85
- value={userInput}
86
- onChange={handleUserInput}
87
- onKeyPress={handleKeyPress}
88
- placeholder="Ask a question"
89
- />
90
- <Button disabled={isLoading ?? true} style={{ backgroundColor: 'transparent', color: isLoading ? '#dedede' : chatBubbleConfig?.color }} size='middle' icon={<SendRounded />} onClick={sendInputInquiry}/>
91
- </div>
92
- </div>
93
- )}
94
- <Button type='link' onClick={toggleChat} className="chat-toggle" style={{ backgroundColor: chatBubbleConfig?.color ?? '#dedede' }}>
95
- {chatIsOpen ? <Close style={{ width: 30, height: 30, color: '#fff' }} /> : <ChatIcon style={{ width: 30, height: 30, color: '#fff' }}/>}
96
- </Button>
97
- </div>
98
- </AppProvider>
99
-
100
- )
101
- }
102
-
103
- export default BiBot
@@ -1,3 +0,0 @@
1
- export enum appStateEnums {
2
- BIBOT = 'BIBOT'
3
- }
@@ -1,28 +0,0 @@
1
-
2
- export const APP_DATA = {
3
- APP_NAME: 'Bibot'
4
- }
5
-
6
- const baseUrls = {
7
- inference: 'https://inference.dev.bibot.thespuka.com/v0',
8
- }
9
-
10
- export const endpoints = {
11
- get inference () {
12
- return baseUrls.inference
13
- },
14
- } as const
15
-
16
- export enum domain {
17
- app = '/app',
18
- bibot = '/bibot',
19
- inference = '/inference',
20
- }
21
-
22
- export enum resources {
23
- chatBubble = '/chat-bubble-config',
24
- predefinedQ = '/predefined-q',
25
- localQ = '/local-q',
26
- timedOutLocalQ = '/t-local-q',
27
- q = '/q'
28
- }
@@ -1,5 +0,0 @@
1
- // created from 'create-ts-index'
2
- export * from './appStateEnums'
3
- export * from './endpointEnums'
4
- export * from './statusCode'
5
-
@@ -1,49 +0,0 @@
1
- export enum statusCode {
2
- ok = 200
3
- , created = 201
4
- , accepted = 202
5
-
6
- // 3xx codes
7
- , unmodified = 304
8
-
9
- // 4xx Client Error
10
- , sucMsg = 'success'
11
- , badReq = 400
12
- , unauthorized = 401
13
- , paymentReq = 402
14
- , forbidden = 403
15
- , notFound = 404
16
- , methodNotAllowed = 405
17
- , notAcceptable = 406
18
- , pxyAuthReq = 407
19
- , reqTimeOut = 408
20
- , conflict = 409
21
- , gone = 410
22
- , lengthReq = 411
23
- , preConFailed = 412
24
- , payloadTooLarge = 413
25
- , urlTooLong = 414
26
- , unsupportedMediaType = 415
27
- , rangeNotSatisfiable = 416
28
- , expectationFailed = 417
29
-
30
- , misdirectedReq = 421
31
- , unprocessableEntity = 422
32
- , locked = 423
33
- , failedDependency = 424
34
- , tooLarge = 425
35
- , upgradeRequired = 426
36
- , preconReq = 428
37
- , tooManyReq = 429
38
- , reqHeaderTooLarge = 431
39
- , unavailableForLegalReasons = 451
40
-
41
- // 5xx Server Error
42
- , internalServerError = 500
43
- , notImplemented = 501
44
- , badGateway = 502
45
- , svcUnavalable = 503
46
- , gtwayTimeout = 504
47
- , httpVNotSupported = 505
48
- , networkAuthReq = 511
49
- }
@@ -1,66 +0,0 @@
1
- import { appStateEnums } from '../config/appStateEnums'
2
- import React, { type ReactNode, createContext, useReducer, useEffect } from 'react'
3
- import { appReducer } from '../reducers/appReducer'
4
- import type { AppContextProps, AppStates } from '../types/coreInterfaces'
5
- import { getSessionId } from '../utils/sessionManager'
6
-
7
- interface AppProps {
8
- children: ReactNode
9
- }
10
-
11
- const dummyDispatch = () => {} // A no-op function.
12
-
13
- const defaultContextValue: AppContextProps = {
14
- state: {
15
- chatIsOpen: false,
16
- sessionId: getSessionId()
17
- },
18
- dispatch: dummyDispatch
19
- }
20
-
21
- const AppContext = createContext<AppContextProps>(defaultContextValue)
22
-
23
- const AppProvider: React.FC<AppProps> = ({ children }) => {
24
- const APP_STATE_KEY = 'app_states'
25
- const initialState: AppStates = {
26
- chatIsOpen: false,
27
- sessionId: getSessionId()
28
- }
29
-
30
- const [state, dispatch] = useReducer(appReducer, initialState)
31
-
32
- useEffect(() => {
33
- // Pool the initial states from local storage
34
- const storedStates = localStorage.getItem(APP_STATE_KEY)
35
-
36
- if (storedStates) {
37
- try {
38
- const parsedStates = JSON.parse(storedStates)
39
-
40
- // Merge stored states with initial states
41
- const updatedStates = {
42
- ...initialState,
43
- ...parsedStates
44
- }
45
- console.log(initialState, parsedStates, updatedStates)
46
- // Dispatch action to update the states
47
- dispatch({ type: appStateEnums.BIBOT, ...updatedStates })
48
- } catch (error) {
49
- console.error('Failed to parse app states from local storage:', error)
50
- }
51
- }
52
- }, [])
53
-
54
- useEffect(() => {
55
- console.log('Changes in state: ', state)
56
- localStorage.setItem(APP_STATE_KEY, JSON.stringify(state))
57
- }, [state])
58
-
59
- return (
60
- <AppContext.Provider value={{ state, dispatch }}>
61
- {children}
62
- </AppContext.Provider>
63
- )
64
- }
65
-
66
- export { AppContext, AppProvider }
@@ -1,3 +0,0 @@
1
- // created from 'create-ts-index'
2
-
3
- export * from './AppContext'
@@ -1,5 +0,0 @@
1
- // created from 'create-ts-index'
2
-
3
- export * from './usePluginFactory'
4
- export * from './useBiBotChatBot'
5
- export * from './mobileView'
@@ -1,17 +0,0 @@
1
- import React, { useState, useEffect } from 'react'
2
- export default function MobileView () {
3
- const [isMobile, setIsMobile] = useState<boolean>(false)
4
- useEffect(() => {
5
- const isMobileDevice = () => {
6
- const screenWidth = window.innerWidth
7
- const mobileThreshold = 768
8
- setIsMobile(screenWidth < mobileThreshold)
9
- }
10
- isMobileDevice()
11
- window.addEventListener('resize', isMobileDevice)
12
- return () => { // clean up event listner on when component unmount
13
- window.removeEventListener('resize', isMobileDevice)
14
- }
15
- }, [])
16
- return isMobile
17
- }
@@ -1,107 +0,0 @@
1
- import { message } from 'antd'
2
- import { appStateEnums } from '../config/appStateEnums'
3
- import React, { useEffect, useRef, useState, useContext, useCallback } from 'react'
4
- import { AppContext } from '../context/AppContext'
5
-
6
- import { v4 as uuidv4 } from 'uuid'
7
- import { askBiBot, getRemoteClientChatBubbleConfig, getRemoteClientChatPredefinedQuestions } from '../services/plugin-api'
8
- interface UseBiBotChatBotProps {
9
- clientId: string
10
- }
11
-
12
- interface ChatBubbleConfigProps {
13
- bgColor?: string,
14
- color?: string,
15
- title?: string,
16
- logo_url?: string
17
- }
18
- const useBiBotChatBot = ({ clientId }: UseBiBotChatBotProps) => {
19
- const [predefinedQuestions, setPredefinedQuestions] = useState<string[]>([]) // State to store predefined questions
20
- const [showPredefinedQuestions, setShowPredefinedQuestions] = useState(true); // State to toggle predefined questions
21
- const { state, dispatch } = useContext(AppContext)
22
- const { chatIsOpen } = state
23
- const [messages, setMessages] = useState<Array<{ sender: 'user' | 'bot', text: string }>>([])
24
- const [userInput, setUserInput] = useState('')
25
- const [isLoading, setIsLoading] = useState(false)
26
- const messageEndRef = useRef<HTMLDivElement>(null)
27
- const [chatBubbleConfig, setChatBubbleConfig] = useState<ChatBubbleConfigProps>()
28
-
29
- // Function to handle selecting a predefined question
30
- const handlePredefinedQuestionSelect = (question: any) => {
31
- setUserInput(question);
32
- sendInputInquiry();
33
- setShowPredefinedQuestions(false); // Hide predefined questions after selection
34
- }
35
-
36
- const getChatBubbleConfig = useCallback(async()=>{
37
- const remotePredefinedQuestions = await getRemoteClientChatPredefinedQuestions({client_id: clientId})
38
- if (remotePredefinedQuestions){
39
- setPredefinedQuestions(remotePredefinedQuestions)
40
- }
41
- const remoteChatBubbleConfig = await getRemoteClientChatBubbleConfig({client_id: clientId})
42
- if (remoteChatBubbleConfig){
43
- setChatBubbleConfig(remoteChatBubbleConfig)
44
- }
45
- },[clientId])
46
-
47
- useEffect(()=>{
48
- void getChatBubbleConfig()
49
- }, [getChatBubbleConfig])
50
-
51
- useEffect(() => {
52
- if (messageEndRef?.current) { messageEndRef.current.scrollIntoView({ behavior: 'smooth' }) }
53
- }, [messages])
54
-
55
- const toggleChat = () => {
56
- dispatch({ type: appStateEnums.BIBOT, chatIsOpen: !chatIsOpen })
57
- }
58
-
59
- const handleUserInput = (e: React.ChangeEvent<HTMLInputElement>) => {
60
- setUserInput(e.target.value)
61
- }
62
-
63
- async function sendInputInquiry () {
64
- setIsLoading(true)
65
- setUserInput('')
66
- try {
67
- if (userInput.trim()) {
68
- // dispatch({ type: appStateEnums.BIBOT, chatIsOpen: true })
69
- setMessages(messages => [...messages, { sender: 'user', text: userInput }])
70
- const response = await askBiBot({
71
- client_id: clientId,
72
- q: userInput.trim(),
73
- session_id: state.sessionId,
74
- chat_id: uuidv4()
75
- })
76
- setMessages(messages => [...messages, { sender: 'bot', text: response }])
77
- }
78
- } catch (error: any) {
79
- void message.error(error?.message ?? 'Failed to get response from server')
80
- } finally {
81
- setIsLoading(false)
82
- }
83
- }
84
-
85
- const handleKeyPress = async (e: React.KeyboardEvent<HTMLInputElement>) => {
86
- if (e.key === 'Enter' && !isLoading) {
87
- await sendInputInquiry()
88
- }
89
- }
90
- return {
91
- chatIsOpen,
92
- messages,
93
- isLoading,
94
- messageEndRef,
95
- userInput,
96
- handleUserInput,
97
- handleKeyPress,
98
- toggleChat,
99
- sendInputInquiry,
100
- chatBubbleConfig,
101
- showPredefinedQuestions,
102
- predefinedQuestions,
103
- handlePredefinedQuestionSelect,
104
- }
105
- }
106
-
107
- export { useBiBotChatBot }
@@ -1,38 +0,0 @@
1
- import axios from 'axios';
2
- import { endpoints } from '../config/endpointEnums';
3
- import React from 'react';
4
- const inferenceBaseURL = endpoints.inference;
5
-
6
- export const createPluginAxiosInstance = (params = {}, headers = {}) => {
7
- const instance = axios.create({
8
- baseURL: inferenceBaseURL,
9
- timeout: 60000, // 1 minute
10
- headers: {
11
- 'Content-Type': 'application/json',
12
- ...headers
13
- },
14
- ...params
15
- });
16
-
17
-
18
- instance.interceptors.response.use(
19
- (response) => {
20
- return response
21
- },
22
- async (error) => {
23
- let errMsg = 'An unknown error occurred'
24
- if (error.response) {
25
- errMsg = error.response.data.message
26
- } else if (error.request) {
27
- errMsg = 'No response received from the server.'
28
- } else {
29
- errMsg = `Error setting up the request: ${error.message}`
30
- }
31
- return await Promise.reject(new Error(errMsg))
32
- }
33
- )
34
-
35
- return instance
36
- }
37
-
38
-