funda-ui 4.7.150 → 4.7.155
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/CascadingSelect/index.js +13 -6
- package/CascadingSelectE2E/index.js +13 -6
- package/Chatbox/index.css +8 -0
- package/Chatbox/index.d.ts +8 -0
- package/Chatbox/index.js +265 -171
- package/Date/index.js +13 -6
- package/DropdownMenu/index.js +13 -6
- package/EventCalendar/index.js +42 -35
- package/EventCalendarTimeline/index.js +55 -41
- package/LiveSearch/index.js +13 -6
- package/ModalDialog/index.js +13 -6
- package/RootPortal/index.d.ts +2 -1
- package/RootPortal/index.js +13 -6
- package/Select/index.js +13 -6
- package/Toast/index.js +13 -6
- package/Tooltip/index.js +13 -6
- package/lib/cjs/CascadingSelect/index.js +13 -6
- package/lib/cjs/CascadingSelectE2E/index.js +13 -6
- package/lib/cjs/Chatbox/index.d.ts +8 -0
- package/lib/cjs/Chatbox/index.js +265 -171
- package/lib/cjs/Date/index.js +13 -6
- package/lib/cjs/DropdownMenu/index.js +13 -6
- package/lib/cjs/EventCalendar/index.js +42 -35
- package/lib/cjs/EventCalendarTimeline/index.js +55 -41
- package/lib/cjs/LiveSearch/index.js +13 -6
- package/lib/cjs/ModalDialog/index.js +13 -6
- package/lib/cjs/RootPortal/index.d.ts +2 -1
- package/lib/cjs/RootPortal/index.js +13 -6
- package/lib/cjs/Select/index.js +13 -6
- package/lib/cjs/Toast/index.js +13 -6
- package/lib/cjs/Tooltip/index.js +13 -6
- package/lib/css/Chatbox/index.css +8 -0
- package/lib/esm/Chatbox/index.scss +9 -0
- package/lib/esm/Chatbox/index.tsx +103 -15
- package/lib/esm/RootPortal/index.tsx +14 -8
- package/package.json +1 -1
package/lib/cjs/Chatbox/index.js
CHANGED
|
@@ -171,7 +171,9 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
171
171
|
var RootPortal = function RootPortal(props) {
|
|
172
172
|
var containerClassName = props.containerClassName,
|
|
173
173
|
show = props.show,
|
|
174
|
-
children = props.children
|
|
174
|
+
children = props.children,
|
|
175
|
+
_props$usePortal = props.usePortal,
|
|
176
|
+
usePortal = _props$usePortal === void 0 ? true : _props$usePortal;
|
|
175
177
|
var containerRef = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
|
|
176
178
|
|
|
177
179
|
// Move HTML templates to tag end body </body>
|
|
@@ -182,15 +184,20 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
182
184
|
// Use `containerRef.current` to ensure the correctness of the nextjs framework. It may report an error document as undefined
|
|
183
185
|
|
|
184
186
|
(0, react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
187
|
+
if (usePortal) {
|
|
188
|
+
containerRef.current = document.createElement('div');
|
|
189
|
+
containerRef.current.className = "root-portal-container ".concat(containerClassName || '');
|
|
190
|
+
document.body.appendChild(containerRef.current);
|
|
191
|
+
}
|
|
188
192
|
return function () {
|
|
189
|
-
if (containerRef.current) {
|
|
193
|
+
if (usePortal && containerRef.current) {
|
|
190
194
|
containerRef.current.remove();
|
|
191
195
|
}
|
|
192
196
|
};
|
|
193
|
-
}, []);
|
|
197
|
+
}, [usePortal]);
|
|
198
|
+
if (!usePortal) {
|
|
199
|
+
return show ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(react__WEBPACK_IMPORTED_MODULE_0___default().Fragment, null, children) : null;
|
|
200
|
+
}
|
|
194
201
|
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(react__WEBPACK_IMPORTED_MODULE_0___default().Fragment, null, containerRef.current && show && /*#__PURE__*/(0, react_dom__WEBPACK_IMPORTED_MODULE_1__.createPortal)(children, containerRef.current));
|
|
195
202
|
};
|
|
196
203
|
/* harmony default export */
|
|
@@ -4299,6 +4306,12 @@ var Chatbox = function Chatbox(props) {
|
|
|
4299
4306
|
setEnableStreamMode = _useState18[1];
|
|
4300
4307
|
var animatedMessagesRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(new Set()); // Add a ref to keep track of messages that have already been animated
|
|
4301
4308
|
|
|
4309
|
+
// Keep track of whether the default values have been initialized
|
|
4310
|
+
var _useState19 = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)({}),
|
|
4311
|
+
_useState20 = src_slicedToArray(_useState19, 2),
|
|
4312
|
+
initializedDefaults = _useState20[0],
|
|
4313
|
+
setInitializedDefaults = _useState20[1];
|
|
4314
|
+
|
|
4302
4315
|
//
|
|
4303
4316
|
var timer = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
|
|
4304
4317
|
|
|
@@ -4424,6 +4437,7 @@ var Chatbox = function Chatbox(props) {
|
|
|
4424
4437
|
toolkitButtons = currentProps.toolkitButtons,
|
|
4425
4438
|
newChatButton = currentProps.newChatButton,
|
|
4426
4439
|
maxHistoryLength = currentProps.maxHistoryLength,
|
|
4440
|
+
usePopUp = currentProps.usePopUp,
|
|
4427
4441
|
customRequest = currentProps.customRequest,
|
|
4428
4442
|
onQuestionClick = currentProps.onQuestionClick,
|
|
4429
4443
|
onCopyCallback = currentProps.onCopyCallback,
|
|
@@ -4496,6 +4510,7 @@ var Chatbox = function Chatbox(props) {
|
|
|
4496
4510
|
maxHistoryLength: maxHistoryLength,
|
|
4497
4511
|
toolkitButtons: toolkitButtons,
|
|
4498
4512
|
newChatButton: newChatButton,
|
|
4513
|
+
usePopUp: usePopUp,
|
|
4499
4514
|
customRequest: customRequest,
|
|
4500
4515
|
onQuestionClick: onQuestionClick,
|
|
4501
4516
|
onCopyCallback: onCopyCallback,
|
|
@@ -4597,10 +4612,10 @@ var Chatbox = function Chatbox(props) {
|
|
|
4597
4612
|
//================================================================
|
|
4598
4613
|
// Custom Questions
|
|
4599
4614
|
//================================================================
|
|
4600
|
-
var
|
|
4601
|
-
|
|
4602
|
-
questions =
|
|
4603
|
-
setQuestions =
|
|
4615
|
+
var _useState21 = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(props.defaultQuestions),
|
|
4616
|
+
_useState22 = src_slicedToArray(_useState21, 2),
|
|
4617
|
+
questions = _useState22[0],
|
|
4618
|
+
setQuestions = _useState22[1];
|
|
4604
4619
|
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
|
|
4605
4620
|
if (props.defaultQuestions) {
|
|
4606
4621
|
setQuestions(props.defaultQuestions);
|
|
@@ -4621,10 +4636,10 @@ var Chatbox = function Chatbox(props) {
|
|
|
4621
4636
|
// Custom buttons
|
|
4622
4637
|
//================================================================
|
|
4623
4638
|
var toolkitBtnsRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
|
|
4624
|
-
var
|
|
4625
|
-
|
|
4626
|
-
activeButtons =
|
|
4627
|
-
setActiveButtons =
|
|
4639
|
+
var _useState23 = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)({}),
|
|
4640
|
+
_useState24 = src_slicedToArray(_useState23, 2),
|
|
4641
|
+
activeButtons = _useState24[0],
|
|
4642
|
+
setActiveButtons = _useState24[1];
|
|
4628
4643
|
var closeDropdowns = function closeDropdowns() {
|
|
4629
4644
|
setActiveButtons(function (prev) {
|
|
4630
4645
|
var _args$toolkitButtons;
|
|
@@ -4639,19 +4654,48 @@ var Chatbox = function Chatbox(props) {
|
|
|
4639
4654
|
return newState;
|
|
4640
4655
|
});
|
|
4641
4656
|
};
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4657
|
+
|
|
4658
|
+
// The onClick action specifically used to perform the default options
|
|
4659
|
+
var executeDefaultOptionAction = /*#__PURE__*/function () {
|
|
4660
|
+
var _ref2 = src_asyncToGenerator( /*#__PURE__*/src_regeneratorRuntime().mark(function _callee2(actionStr, buttonId) {
|
|
4661
|
+
var actionFn;
|
|
4645
4662
|
return src_regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
4646
4663
|
while (1) switch (_context2.prev = _context2.next) {
|
|
4647
4664
|
case 0:
|
|
4648
4665
|
_context2.prev = 0;
|
|
4666
|
+
actionFn = new Function('method', 'isActive', 'button', actionStr); // To perform the action, pass false as the "isActive" parameter, as this is the default option
|
|
4667
|
+
_context2.next = 4;
|
|
4668
|
+
return actionFn(exposedMethods(), false, document.getElementById(buttonId));
|
|
4669
|
+
case 4:
|
|
4670
|
+
_context2.next = 9;
|
|
4671
|
+
break;
|
|
4672
|
+
case 6:
|
|
4673
|
+
_context2.prev = 6;
|
|
4674
|
+
_context2.t0 = _context2["catch"](0);
|
|
4675
|
+
console.error('Error executing default option action:', _context2.t0);
|
|
4676
|
+
case 9:
|
|
4677
|
+
case "end":
|
|
4678
|
+
return _context2.stop();
|
|
4679
|
+
}
|
|
4680
|
+
}, _callee2, null, [[0, 6]]);
|
|
4681
|
+
}));
|
|
4682
|
+
return function executeDefaultOptionAction(_x3, _x4) {
|
|
4683
|
+
return _ref2.apply(this, arguments);
|
|
4684
|
+
};
|
|
4685
|
+
}();
|
|
4686
|
+
var executeButtonAction = /*#__PURE__*/function () {
|
|
4687
|
+
var _ref3 = src_asyncToGenerator( /*#__PURE__*/src_regeneratorRuntime().mark(function _callee3(actionStr, buttonId, buttonElement) {
|
|
4688
|
+
var actionFn, result, options, newState;
|
|
4689
|
+
return src_regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
4690
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
4691
|
+
case 0:
|
|
4692
|
+
_context3.prev = 0;
|
|
4649
4693
|
actionFn = new Function('method', 'isActive', 'button', actionStr); // !!!REQUIRED "await"
|
|
4650
4694
|
// "customMethods" may be asynchronous
|
|
4651
|
-
|
|
4695
|
+
_context3.next = 4;
|
|
4652
4696
|
return actionFn(exposedMethods(), !activeButtons[buttonId], buttonElement);
|
|
4653
4697
|
case 4:
|
|
4654
|
-
result =
|
|
4698
|
+
result = _context3.sent;
|
|
4655
4699
|
// If the returned result is an array, it is a dynamic option
|
|
4656
4700
|
if (Array.isArray(result) && Object.keys(dynamicOptions).length === 0) {
|
|
4657
4701
|
options = result.map(function (item) {
|
|
@@ -4681,32 +4725,36 @@ var Chatbox = function Chatbox(props) {
|
|
|
4681
4725
|
setActiveButtons(function (prev) {
|
|
4682
4726
|
return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, buttonId, newState));
|
|
4683
4727
|
});
|
|
4684
|
-
return
|
|
4728
|
+
return _context3.abrupt("return", result);
|
|
4685
4729
|
case 11:
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
console.error('Error executing button action:',
|
|
4730
|
+
_context3.prev = 11;
|
|
4731
|
+
_context3.t0 = _context3["catch"](0);
|
|
4732
|
+
console.error('Error executing button action:', _context3.t0);
|
|
4689
4733
|
case 14:
|
|
4690
4734
|
case "end":
|
|
4691
|
-
return
|
|
4735
|
+
return _context3.stop();
|
|
4692
4736
|
}
|
|
4693
|
-
},
|
|
4737
|
+
}, _callee3, null, [[0, 11]]);
|
|
4694
4738
|
}));
|
|
4695
|
-
return function executeButtonAction(
|
|
4696
|
-
return
|
|
4739
|
+
return function executeButtonAction(_x5, _x6, _x7) {
|
|
4740
|
+
return _ref3.apply(this, arguments);
|
|
4697
4741
|
};
|
|
4698
4742
|
}();
|
|
4699
4743
|
|
|
4700
4744
|
// options
|
|
4701
|
-
var
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
// Store dynamic options
|
|
4706
|
-
var _useState25 = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)({}),
|
|
4745
|
+
var _useState25 = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)({
|
|
4746
|
+
curIndex: -1,
|
|
4747
|
+
curValue: ''
|
|
4748
|
+
}),
|
|
4707
4749
|
_useState26 = src_slicedToArray(_useState25, 2),
|
|
4708
|
-
|
|
4709
|
-
|
|
4750
|
+
selectedOpt = _useState26[0],
|
|
4751
|
+
setSelectedOpt = _useState26[1];
|
|
4752
|
+
|
|
4753
|
+
// Store dynamic options
|
|
4754
|
+
var _useState27 = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)({}),
|
|
4755
|
+
_useState28 = src_slicedToArray(_useState27, 2),
|
|
4756
|
+
dynamicOptions = _useState28[0],
|
|
4757
|
+
setDynamicOptions = _useState28[1];
|
|
4710
4758
|
var getButtonOptions = function getButtonOptions(btn, buttonId) {
|
|
4711
4759
|
// If you are using the dynamic option and already have a cache, return the option for caching
|
|
4712
4760
|
//---------
|
|
@@ -4738,6 +4786,7 @@ var Chatbox = function Chatbox(props) {
|
|
|
4738
4786
|
return options;
|
|
4739
4787
|
};
|
|
4740
4788
|
var handleExecuteButtonSelect = function handleExecuteButtonSelect(buttonId, option, index, value) {
|
|
4789
|
+
var isDefaultSelection = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
4741
4790
|
if (option.value === "cancel") {
|
|
4742
4791
|
setSelectedOpt(function (prev) {
|
|
4743
4792
|
var newLabels = _objectSpread({}, prev);
|
|
@@ -4753,10 +4802,14 @@ var Chatbox = function Chatbox(props) {
|
|
|
4753
4802
|
return _objectSpread(_objectSpread({}, prev), {}, (_objectSpread4 = {}, _defineProperty(_objectSpread4, buttonId, option.label), _defineProperty(_objectSpread4, "curIndex", index), _defineProperty(_objectSpread4, "curValue", value), _objectSpread4));
|
|
4754
4803
|
});
|
|
4755
4804
|
}
|
|
4756
|
-
executeButtonAction(option.onClick, buttonId, document.getElementById(buttonId));
|
|
4757
4805
|
|
|
4758
|
-
//
|
|
4759
|
-
|
|
4806
|
+
// The button action is performed and the drop-down menu is closed only when it is not the default selection
|
|
4807
|
+
if (!isDefaultSelection) {
|
|
4808
|
+
executeButtonAction(option.onClick, buttonId, document.getElementById(buttonId));
|
|
4809
|
+
|
|
4810
|
+
// Close the drop-down
|
|
4811
|
+
closeDropdowns();
|
|
4812
|
+
}
|
|
4760
4813
|
};
|
|
4761
4814
|
|
|
4762
4815
|
// click outside
|
|
@@ -4813,25 +4866,25 @@ var Chatbox = function Chatbox(props) {
|
|
|
4813
4866
|
|
|
4814
4867
|
// parse chunk data
|
|
4815
4868
|
var parseChunkData = /*#__PURE__*/function () {
|
|
4816
|
-
var
|
|
4869
|
+
var _ref4 = src_asyncToGenerator( /*#__PURE__*/src_regeneratorRuntime().mark(function _callee4(chunk, index, complete) {
|
|
4817
4870
|
var lastContent, _args$responseExtract, extractPath, lines, _iterator, _step, line, _content, result, _iterator2, _step2, path, content, parsedContent, latestRes;
|
|
4818
|
-
return src_regeneratorRuntime().wrap(function
|
|
4819
|
-
while (1) switch (
|
|
4871
|
+
return src_regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
4872
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
4820
4873
|
case 0:
|
|
4821
4874
|
// Store the final content and bind it to loading
|
|
4822
4875
|
lastContent = '';
|
|
4823
|
-
|
|
4876
|
+
_context4.prev = 1;
|
|
4824
4877
|
// Extract response using the path
|
|
4825
4878
|
extractPath = (_args$responseExtract = args().responseExtractPath) === null || _args$responseExtract === void 0 ? void 0 : _args$responseExtract.slice(1); // Streaming data is JSON split by rows
|
|
4826
4879
|
lines = chunk.split("\n").filter(function (line) {
|
|
4827
4880
|
return line.trim() !== "";
|
|
4828
4881
|
});
|
|
4829
4882
|
_iterator = _createForOfIteratorHelper(lines);
|
|
4830
|
-
|
|
4883
|
+
_context4.prev = 5;
|
|
4831
4884
|
_iterator.s();
|
|
4832
4885
|
case 7:
|
|
4833
4886
|
if ((_step = _iterator.n()).done) {
|
|
4834
|
-
|
|
4887
|
+
_context4.next = 45;
|
|
4835
4888
|
break;
|
|
4836
4889
|
}
|
|
4837
4890
|
line = _step.value;
|
|
@@ -4842,7 +4895,7 @@ var Chatbox = function Chatbox(props) {
|
|
|
4842
4895
|
|
|
4843
4896
|
// Send the streamed data to the front end
|
|
4844
4897
|
if (!(line.indexOf('[DONE]') < 0)) {
|
|
4845
|
-
|
|
4898
|
+
_context4.next = 40;
|
|
4846
4899
|
break;
|
|
4847
4900
|
}
|
|
4848
4901
|
// STEP 1:
|
|
@@ -4850,14 +4903,14 @@ var Chatbox = function Chatbox(props) {
|
|
|
4850
4903
|
// Create a JSON string
|
|
4851
4904
|
_content = "".concat(line.replace(/^data:\s*/, '')); // Determine whether it is in JSON format
|
|
4852
4905
|
if (isValidJSON(_content)) {
|
|
4853
|
-
|
|
4906
|
+
_context4.next = 16;
|
|
4854
4907
|
break;
|
|
4855
4908
|
}
|
|
4856
4909
|
console.log('--> [ERROR] Wrong JSON format');
|
|
4857
4910
|
|
|
4858
4911
|
//reset SSE
|
|
4859
4912
|
closeSSE();
|
|
4860
|
-
return
|
|
4913
|
+
return _context4.abrupt("break", 45);
|
|
4861
4914
|
case 16:
|
|
4862
4915
|
// STEP 2:
|
|
4863
4916
|
// ------
|
|
@@ -4866,18 +4919,18 @@ var Chatbox = function Chatbox(props) {
|
|
|
4866
4919
|
// for Ollama API (STREAM END)
|
|
4867
4920
|
//*******
|
|
4868
4921
|
if (!(typeof result.done !== 'undefined')) {
|
|
4869
|
-
|
|
4922
|
+
_context4.next = 22;
|
|
4870
4923
|
break;
|
|
4871
4924
|
}
|
|
4872
4925
|
if (!(result.done === true)) {
|
|
4873
|
-
|
|
4926
|
+
_context4.next = 22;
|
|
4874
4927
|
break;
|
|
4875
4928
|
}
|
|
4876
4929
|
console.log('--> [DONE]');
|
|
4877
4930
|
|
|
4878
4931
|
//reset SSE
|
|
4879
4932
|
closeSSE();
|
|
4880
|
-
return
|
|
4933
|
+
return _context4.abrupt("break", 45);
|
|
4881
4934
|
case 22:
|
|
4882
4935
|
//*******
|
|
4883
4936
|
// for OpenAI API
|
|
@@ -4899,10 +4952,10 @@ var Chatbox = function Chatbox(props) {
|
|
|
4899
4952
|
// ------
|
|
4900
4953
|
// 🚀 !! IMPORTANT: Skip the error content
|
|
4901
4954
|
if (!(typeof content === 'undefined')) {
|
|
4902
|
-
|
|
4955
|
+
_context4.next = 26;
|
|
4903
4956
|
break;
|
|
4904
4957
|
}
|
|
4905
|
-
return
|
|
4958
|
+
return _context4.abrupt("continue", 43);
|
|
4906
4959
|
case 26:
|
|
4907
4960
|
// STEP 4:
|
|
4908
4961
|
// ------
|
|
@@ -4929,13 +4982,13 @@ var Chatbox = function Chatbox(props) {
|
|
|
4929
4982
|
// ------
|
|
4930
4983
|
parsedContent = tempLastContent.current; // If a render parser exists, it is used to process the string
|
|
4931
4984
|
if (!(typeof args().renderParser === 'function')) {
|
|
4932
|
-
|
|
4985
|
+
_context4.next = 36;
|
|
4933
4986
|
break;
|
|
4934
4987
|
}
|
|
4935
|
-
|
|
4988
|
+
_context4.next = 35;
|
|
4936
4989
|
return args().renderParser(parsedContent);
|
|
4937
4990
|
case 35:
|
|
4938
|
-
parsedContent =
|
|
4991
|
+
parsedContent = _context4.sent;
|
|
4939
4992
|
case 36:
|
|
4940
4993
|
// STEP 8:
|
|
4941
4994
|
// ------
|
|
@@ -4952,55 +5005,55 @@ var Chatbox = function Chatbox(props) {
|
|
|
4952
5005
|
// ------
|
|
4953
5006
|
// Scroll to the bottom
|
|
4954
5007
|
scrollToBottom();
|
|
4955
|
-
|
|
5008
|
+
_context4.next = 43;
|
|
4956
5009
|
break;
|
|
4957
5010
|
case 40:
|
|
4958
5011
|
console.log('--> [DONE]');
|
|
4959
5012
|
|
|
4960
5013
|
//reset SSE
|
|
4961
5014
|
closeSSE();
|
|
4962
|
-
return
|
|
5015
|
+
return _context4.abrupt("break", 45);
|
|
4963
5016
|
case 43:
|
|
4964
|
-
|
|
5017
|
+
_context4.next = 7;
|
|
4965
5018
|
break;
|
|
4966
5019
|
case 45:
|
|
4967
|
-
|
|
5020
|
+
_context4.next = 50;
|
|
4968
5021
|
break;
|
|
4969
5022
|
case 47:
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
_iterator.e(
|
|
5023
|
+
_context4.prev = 47;
|
|
5024
|
+
_context4.t0 = _context4["catch"](5);
|
|
5025
|
+
_iterator.e(_context4.t0);
|
|
4973
5026
|
case 50:
|
|
4974
|
-
|
|
5027
|
+
_context4.prev = 50;
|
|
4975
5028
|
_iterator.f();
|
|
4976
|
-
return
|
|
5029
|
+
return _context4.finish(50);
|
|
4977
5030
|
case 53:
|
|
4978
|
-
|
|
5031
|
+
_context4.next = 58;
|
|
4979
5032
|
break;
|
|
4980
5033
|
case 55:
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
console.error('--> Error processing chunk:',
|
|
5034
|
+
_context4.prev = 55;
|
|
5035
|
+
_context4.t1 = _context4["catch"](1);
|
|
5036
|
+
console.error('--> Error processing chunk:', _context4.t1);
|
|
4984
5037
|
case 58:
|
|
4985
5038
|
latestRes = complete ? lastContent : tempLastContent.current; // If a render parser exists, it is used to process the string
|
|
4986
5039
|
if (!(typeof args().renderParser === 'function')) {
|
|
4987
|
-
|
|
5040
|
+
_context4.next = 63;
|
|
4988
5041
|
break;
|
|
4989
5042
|
}
|
|
4990
|
-
|
|
5043
|
+
_context4.next = 62;
|
|
4991
5044
|
return args().renderParser(latestRes);
|
|
4992
5045
|
case 62:
|
|
4993
|
-
latestRes =
|
|
5046
|
+
latestRes = _context4.sent;
|
|
4994
5047
|
case 63:
|
|
4995
|
-
return
|
|
5048
|
+
return _context4.abrupt("return", formatLatestDisplayContent(latestRes));
|
|
4996
5049
|
case 64:
|
|
4997
5050
|
case "end":
|
|
4998
|
-
return
|
|
5051
|
+
return _context4.stop();
|
|
4999
5052
|
}
|
|
5000
|
-
},
|
|
5053
|
+
}, _callee4, null, [[1, 55], [5, 47, 50, 53]]);
|
|
5001
5054
|
}));
|
|
5002
|
-
return function parseChunkData(
|
|
5003
|
-
return
|
|
5055
|
+
return function parseChunkData(_x8, _x9, _x10) {
|
|
5056
|
+
return _ref4.apply(this, arguments);
|
|
5004
5057
|
};
|
|
5005
5058
|
}();
|
|
5006
5059
|
|
|
@@ -5008,11 +5061,11 @@ var Chatbox = function Chatbox(props) {
|
|
|
5008
5061
|
var tempLastContent = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)('');
|
|
5009
5062
|
var streamController = src_useStreamController({
|
|
5010
5063
|
onChunk: function () {
|
|
5011
|
-
var _onChunk = src_asyncToGenerator( /*#__PURE__*/src_regeneratorRuntime().mark(function
|
|
5012
|
-
var _args$onChunk,
|
|
5064
|
+
var _onChunk = src_asyncToGenerator( /*#__PURE__*/src_regeneratorRuntime().mark(function _callee5(chunk, index) {
|
|
5065
|
+
var _args$onChunk, _args9;
|
|
5013
5066
|
var res;
|
|
5014
|
-
return src_regeneratorRuntime().wrap(function
|
|
5015
|
-
while (1) switch (
|
|
5067
|
+
return src_regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
5068
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
5016
5069
|
case 0:
|
|
5017
5070
|
// start (Execute it only once)
|
|
5018
5071
|
if (index === 0) {
|
|
@@ -5021,50 +5074,50 @@ var Chatbox = function Chatbox(props) {
|
|
|
5021
5074
|
}
|
|
5022
5075
|
|
|
5023
5076
|
//
|
|
5024
|
-
|
|
5077
|
+
_context5.next = 3;
|
|
5025
5078
|
return parseChunkData(chunk, index, false);
|
|
5026
5079
|
case 3:
|
|
5027
|
-
res =
|
|
5080
|
+
res = _context5.sent;
|
|
5028
5081
|
//
|
|
5029
|
-
(_args$onChunk = (
|
|
5082
|
+
(_args$onChunk = (_args9 = args()).onChunk) === null || _args$onChunk === void 0 ? void 0 : _args$onChunk.call(_args9, inputContentRef.current, res, conversationHistory.current);
|
|
5030
5083
|
case 5:
|
|
5031
5084
|
case "end":
|
|
5032
|
-
return
|
|
5085
|
+
return _context5.stop();
|
|
5033
5086
|
}
|
|
5034
|
-
},
|
|
5087
|
+
}, _callee5);
|
|
5035
5088
|
}));
|
|
5036
|
-
function onChunk(
|
|
5089
|
+
function onChunk(_x11, _x12) {
|
|
5037
5090
|
return _onChunk.apply(this, arguments);
|
|
5038
5091
|
}
|
|
5039
5092
|
return onChunk;
|
|
5040
5093
|
}(),
|
|
5041
5094
|
onComplete: function () {
|
|
5042
|
-
var _onComplete = src_asyncToGenerator( /*#__PURE__*/src_regeneratorRuntime().mark(function
|
|
5043
|
-
var _args$onComplete,
|
|
5095
|
+
var _onComplete = src_asyncToGenerator( /*#__PURE__*/src_regeneratorRuntime().mark(function _callee6(lastContent) {
|
|
5096
|
+
var _args$onComplete, _args11;
|
|
5044
5097
|
var res;
|
|
5045
|
-
return src_regeneratorRuntime().wrap(function
|
|
5046
|
-
while (1) switch (
|
|
5098
|
+
return src_regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
5099
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
5047
5100
|
case 0:
|
|
5048
5101
|
console.log('--> Stream complete');
|
|
5049
|
-
|
|
5102
|
+
_context6.next = 3;
|
|
5050
5103
|
return parseChunkData(lastContent, 0, true);
|
|
5051
5104
|
case 3:
|
|
5052
|
-
res =
|
|
5105
|
+
res = _context6.sent;
|
|
5053
5106
|
// Display AI reply
|
|
5054
5107
|
displayMessage(args().answerNameRes, res);
|
|
5055
5108
|
|
|
5056
5109
|
//
|
|
5057
|
-
(_args$onComplete = (
|
|
5110
|
+
(_args$onComplete = (_args11 = args()).onComplete) === null || _args$onComplete === void 0 ? void 0 : _args$onComplete.call(_args11, inputContentRef.current, res, conversationHistory.current);
|
|
5058
5111
|
|
|
5059
5112
|
//
|
|
5060
5113
|
closeSSE();
|
|
5061
5114
|
case 7:
|
|
5062
5115
|
case "end":
|
|
5063
|
-
return
|
|
5116
|
+
return _context6.stop();
|
|
5064
5117
|
}
|
|
5065
|
-
},
|
|
5118
|
+
}, _callee6);
|
|
5066
5119
|
}));
|
|
5067
|
-
function onComplete(
|
|
5120
|
+
function onComplete(_x13) {
|
|
5068
5121
|
return _onComplete.apply(this, arguments);
|
|
5069
5122
|
}
|
|
5070
5123
|
return onComplete;
|
|
@@ -5118,34 +5171,34 @@ var Chatbox = function Chatbox(props) {
|
|
|
5118
5171
|
}
|
|
5119
5172
|
};
|
|
5120
5173
|
var sendMessage = /*#__PURE__*/function () {
|
|
5121
|
-
var
|
|
5122
|
-
var messageInput, message, inputMsg, _res, _args$onChunk2,
|
|
5123
|
-
return src_regeneratorRuntime().wrap(function
|
|
5124
|
-
while (1) switch (
|
|
5174
|
+
var _ref5 = src_asyncToGenerator( /*#__PURE__*/src_regeneratorRuntime().mark(function _callee7() {
|
|
5175
|
+
var messageInput, message, inputMsg, _res, _args$onChunk2, _args13, _args$onComplete2, _args14, reply, replyRes;
|
|
5176
|
+
return src_regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
5177
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
5125
5178
|
case 0:
|
|
5126
5179
|
if (!(rootRef.current === null || msgContainerRef.current === null || msInput.current === null)) {
|
|
5127
|
-
|
|
5180
|
+
_context7.next = 2;
|
|
5128
5181
|
break;
|
|
5129
5182
|
}
|
|
5130
|
-
return
|
|
5183
|
+
return _context7.abrupt("return");
|
|
5131
5184
|
case 2:
|
|
5132
5185
|
messageInput = msInput.current;
|
|
5133
5186
|
message = (0,sanitize.htmlEncode)(messageInput.value); // It fires in real time as the user enters
|
|
5134
5187
|
// Sanitizing input is the process of securing/cleaning/filtering input data.
|
|
5135
5188
|
if (!(typeof args().onInputCallback === 'function')) {
|
|
5136
|
-
|
|
5189
|
+
_context7.next = 8;
|
|
5137
5190
|
break;
|
|
5138
5191
|
}
|
|
5139
|
-
|
|
5192
|
+
_context7.next = 7;
|
|
5140
5193
|
return args().onInputCallback(message);
|
|
5141
5194
|
case 7:
|
|
5142
|
-
message =
|
|
5195
|
+
message = _context7.sent;
|
|
5143
5196
|
case 8:
|
|
5144
5197
|
if (!(message.trim() === '')) {
|
|
5145
|
-
|
|
5198
|
+
_context7.next = 10;
|
|
5146
5199
|
break;
|
|
5147
5200
|
}
|
|
5148
|
-
return
|
|
5201
|
+
return _context7.abrupt("return");
|
|
5149
5202
|
case 10:
|
|
5150
5203
|
// Start the timer
|
|
5151
5204
|
setElapsedTime(0); // Reset elapsed time
|
|
@@ -5158,13 +5211,13 @@ var Chatbox = function Chatbox(props) {
|
|
|
5158
5211
|
// user message
|
|
5159
5212
|
inputMsg = "".concat(message); // If a render parser exists, it is used to process the string
|
|
5160
5213
|
if (!(typeof args().renderParser === 'function')) {
|
|
5161
|
-
|
|
5214
|
+
_context7.next = 17;
|
|
5162
5215
|
break;
|
|
5163
5216
|
}
|
|
5164
|
-
|
|
5217
|
+
_context7.next = 16;
|
|
5165
5218
|
return args().renderParser(inputMsg);
|
|
5166
5219
|
case 16:
|
|
5167
|
-
inputMsg =
|
|
5220
|
+
inputMsg = _context7.sent;
|
|
5168
5221
|
case 17:
|
|
5169
5222
|
displayMessage(args().questionNameRes, inputMsg); // Display user message
|
|
5170
5223
|
|
|
@@ -5176,48 +5229,48 @@ var Chatbox = function Chatbox(props) {
|
|
|
5176
5229
|
|
|
5177
5230
|
// clear
|
|
5178
5231
|
if (inputContentRef.current) inputContentRef.current.clear();
|
|
5179
|
-
|
|
5180
|
-
|
|
5232
|
+
_context7.prev = 21;
|
|
5233
|
+
_context7.next = 24;
|
|
5181
5234
|
return mainRequest(message);
|
|
5182
5235
|
case 24:
|
|
5183
|
-
_res =
|
|
5236
|
+
_res = _context7.sent;
|
|
5184
5237
|
if (_res.useStreamRender) {
|
|
5185
|
-
|
|
5238
|
+
_context7.next = 36;
|
|
5186
5239
|
break;
|
|
5187
5240
|
}
|
|
5188
5241
|
reply = _res.reply;
|
|
5189
5242
|
replyRes = "".concat(reply); // If a render parser exists, it is used to process the string
|
|
5190
5243
|
if (!(typeof args().renderParser === 'function')) {
|
|
5191
|
-
|
|
5244
|
+
_context7.next = 32;
|
|
5192
5245
|
break;
|
|
5193
5246
|
}
|
|
5194
|
-
|
|
5247
|
+
_context7.next = 31;
|
|
5195
5248
|
return args().renderParser(replyRes);
|
|
5196
5249
|
case 31:
|
|
5197
|
-
replyRes =
|
|
5250
|
+
replyRes = _context7.sent;
|
|
5198
5251
|
case 32:
|
|
5199
5252
|
displayMessage(args().answerNameRes, replyRes); // Display AI reply
|
|
5200
5253
|
|
|
5201
5254
|
//
|
|
5202
|
-
(_args$onChunk2 = (
|
|
5203
|
-
(_args$onComplete2 = (
|
|
5255
|
+
(_args$onChunk2 = (_args13 = args()).onChunk) === null || _args$onChunk2 === void 0 ? void 0 : _args$onChunk2.call(_args13, inputContentRef.current, replyRes, conversationHistory.current);
|
|
5256
|
+
(_args$onComplete2 = (_args14 = args()).onComplete) === null || _args$onComplete2 === void 0 ? void 0 : _args$onComplete2.call(_args14, inputContentRef.current, replyRes, conversationHistory.current);
|
|
5204
5257
|
|
|
5205
5258
|
//reset SSE
|
|
5206
5259
|
closeSSE();
|
|
5207
5260
|
case 36:
|
|
5208
|
-
|
|
5261
|
+
_context7.next = 45;
|
|
5209
5262
|
break;
|
|
5210
5263
|
case 38:
|
|
5211
|
-
|
|
5212
|
-
|
|
5264
|
+
_context7.prev = 38;
|
|
5265
|
+
_context7.t0 = _context7["catch"](21);
|
|
5213
5266
|
// loading
|
|
5214
5267
|
setLoading(false);
|
|
5215
5268
|
|
|
5216
5269
|
// Stop the timer
|
|
5217
5270
|
clearInterval(timer.current);
|
|
5218
5271
|
timer.current = null;
|
|
5219
|
-
console.error('--> Error sending message:',
|
|
5220
|
-
displayMessage(args().answerNameRes, "Error: Unable to send message: ".concat(String(
|
|
5272
|
+
console.error('--> Error sending message:', _context7.t0);
|
|
5273
|
+
displayMessage(args().answerNameRes, "Error: Unable to send message: ".concat(String(_context7.t0))); // Display AI reply
|
|
5221
5274
|
case 45:
|
|
5222
5275
|
// clear
|
|
5223
5276
|
messageInput.value = '';
|
|
@@ -5229,12 +5282,12 @@ var Chatbox = function Chatbox(props) {
|
|
|
5229
5282
|
scrollToBottom();
|
|
5230
5283
|
case 48:
|
|
5231
5284
|
case "end":
|
|
5232
|
-
return
|
|
5285
|
+
return _context7.stop();
|
|
5233
5286
|
}
|
|
5234
|
-
},
|
|
5287
|
+
}, _callee7, null, [[21, 38]]);
|
|
5235
5288
|
}));
|
|
5236
5289
|
return function sendMessage() {
|
|
5237
|
-
return
|
|
5290
|
+
return _ref5.apply(this, arguments);
|
|
5238
5291
|
};
|
|
5239
5292
|
}();
|
|
5240
5293
|
var handleClickSafe = useDebounce_default()(function () {
|
|
@@ -5246,25 +5299,25 @@ var Chatbox = function Chatbox(props) {
|
|
|
5246
5299
|
setShow(false);
|
|
5247
5300
|
};
|
|
5248
5301
|
var mainRequest = /*#__PURE__*/function () {
|
|
5249
|
-
var
|
|
5302
|
+
var _ref6 = src_asyncToGenerator( /*#__PURE__*/src_regeneratorRuntime().mark(function _callee8(msg) {
|
|
5250
5303
|
var currentStreamMode, requestBodyRes, customResponse, content, isStream, contentRes, response, _errInfo, _args$responseExtract2, extractPath, _response, _errInfo2, jsonResponse, result, _iterator3, _step3, path, _content2, _err;
|
|
5251
|
-
return src_regeneratorRuntime().wrap(function
|
|
5252
|
-
while (1) switch (
|
|
5304
|
+
return src_regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
5305
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
5253
5306
|
case 0:
|
|
5254
5307
|
currentStreamMode = args().isStream; // Update stream mode
|
|
5255
5308
|
setEnableStreamMode(currentStreamMode);
|
|
5256
|
-
|
|
5309
|
+
_context8.prev = 2;
|
|
5257
5310
|
// Parse and interpolate request body template
|
|
5258
5311
|
requestBodyRes = JSON.parse((args().requestBodyTmpl || '{}').replace(/\{model\}/g, args().model).replace(/\{message\}/g, msg).replace(/\{token\}/g, chatId)); //
|
|
5259
5312
|
// If a formatter function exists, it is used to process the request body
|
|
5260
5313
|
if (!(typeof args().requestBodyFormatter === 'function')) {
|
|
5261
|
-
|
|
5314
|
+
_context8.next = 8;
|
|
5262
5315
|
break;
|
|
5263
5316
|
}
|
|
5264
|
-
|
|
5317
|
+
_context8.next = 7;
|
|
5265
5318
|
return args().requestBodyFormatter(requestBodyRes, args().latestContextData, conversationHistory.current);
|
|
5266
5319
|
case 7:
|
|
5267
|
-
requestBodyRes =
|
|
5320
|
+
requestBodyRes = _context8.sent;
|
|
5268
5321
|
case 8:
|
|
5269
5322
|
// Scroll to the bottom
|
|
5270
5323
|
setTimeout(function () {
|
|
@@ -5272,19 +5325,19 @@ var Chatbox = function Chatbox(props) {
|
|
|
5272
5325
|
scrollToBottom();
|
|
5273
5326
|
}, 500);
|
|
5274
5327
|
if (!(typeof args().customRequest === 'function')) {
|
|
5275
|
-
|
|
5328
|
+
_context8.next = 25;
|
|
5276
5329
|
break;
|
|
5277
5330
|
}
|
|
5278
5331
|
// Update stream mode
|
|
5279
5332
|
setEnableStreamMode(false);
|
|
5280
|
-
|
|
5333
|
+
_context8.next = 13;
|
|
5281
5334
|
return args().customRequest(msg, {
|
|
5282
5335
|
requestBody: requestBodyRes,
|
|
5283
5336
|
apiUrl: args().requestApiUrl || '',
|
|
5284
5337
|
headers: args().headerConfigRes
|
|
5285
5338
|
}, customMethodsRef.current, conversationHistory.current);
|
|
5286
5339
|
case 13:
|
|
5287
|
-
customResponse =
|
|
5340
|
+
customResponse = _context8.sent;
|
|
5288
5341
|
content = customResponse.content, isStream = customResponse.isStream;
|
|
5289
5342
|
contentRes = content; // Update stream mode
|
|
5290
5343
|
setEnableStreamMode(isStream);
|
|
@@ -5292,24 +5345,24 @@ var Chatbox = function Chatbox(props) {
|
|
|
5292
5345
|
// NORMAL
|
|
5293
5346
|
//++++++++++++++++++++++++++++++++++++++++++++++++
|
|
5294
5347
|
if (!(!isStream && typeof contentRes === 'string' && contentRes.trim() !== '')) {
|
|
5295
|
-
|
|
5348
|
+
_context8.next = 20;
|
|
5296
5349
|
break;
|
|
5297
5350
|
}
|
|
5298
5351
|
// Replace with a valid label
|
|
5299
5352
|
contentRes = fixHtmlTags(contentRes, args().withReasoning, args().reasoningSwitchLabel);
|
|
5300
|
-
return
|
|
5353
|
+
return _context8.abrupt("return", {
|
|
5301
5354
|
reply: formatLatestDisplayContent(contentRes),
|
|
5302
5355
|
useStreamRender: false
|
|
5303
5356
|
});
|
|
5304
5357
|
case 20:
|
|
5305
5358
|
if (!(isStream && isStreamResponse(contentRes))) {
|
|
5306
|
-
|
|
5359
|
+
_context8.next = 24;
|
|
5307
5360
|
break;
|
|
5308
5361
|
}
|
|
5309
|
-
|
|
5362
|
+
_context8.next = 23;
|
|
5310
5363
|
return streamController.start(contentRes);
|
|
5311
5364
|
case 23:
|
|
5312
|
-
return
|
|
5365
|
+
return _context8.abrupt("return", {
|
|
5313
5366
|
reply: tempAnimText,
|
|
5314
5367
|
// The final content will be in tempAnimText
|
|
5315
5368
|
useStreamRender: true
|
|
@@ -5323,19 +5376,19 @@ var Chatbox = function Chatbox(props) {
|
|
|
5323
5376
|
}
|
|
5324
5377
|
case 25:
|
|
5325
5378
|
if (!currentStreamMode) {
|
|
5326
|
-
|
|
5379
|
+
_context8.next = 39;
|
|
5327
5380
|
break;
|
|
5328
5381
|
}
|
|
5329
|
-
|
|
5382
|
+
_context8.next = 28;
|
|
5330
5383
|
return fetch(args().requestApiUrl || '', {
|
|
5331
5384
|
method: "POST",
|
|
5332
5385
|
body: JSON.stringify(requestBodyRes),
|
|
5333
5386
|
headers: args().headerConfigRes
|
|
5334
5387
|
});
|
|
5335
5388
|
case 28:
|
|
5336
|
-
response =
|
|
5389
|
+
response = _context8.sent;
|
|
5337
5390
|
if (response.ok) {
|
|
5338
|
-
|
|
5391
|
+
_context8.next = 34;
|
|
5339
5392
|
break;
|
|
5340
5393
|
}
|
|
5341
5394
|
_errInfo = "[ERROR] HTTP Error ".concat(response.status, ": ").concat(response.statusText);
|
|
@@ -5343,15 +5396,15 @@ var Chatbox = function Chatbox(props) {
|
|
|
5343
5396
|
|
|
5344
5397
|
// hide loader
|
|
5345
5398
|
setLoaderDisplay(false);
|
|
5346
|
-
return
|
|
5399
|
+
return _context8.abrupt("return", {
|
|
5347
5400
|
reply: _errInfo,
|
|
5348
5401
|
useStreamRender: false
|
|
5349
5402
|
});
|
|
5350
5403
|
case 34:
|
|
5351
|
-
|
|
5404
|
+
_context8.next = 36;
|
|
5352
5405
|
return streamController.start(response);
|
|
5353
5406
|
case 36:
|
|
5354
|
-
return
|
|
5407
|
+
return _context8.abrupt("return", {
|
|
5355
5408
|
reply: tempAnimText,
|
|
5356
5409
|
// The final content will be in tempAnimText
|
|
5357
5410
|
useStreamRender: true
|
|
@@ -5359,7 +5412,7 @@ var Chatbox = function Chatbox(props) {
|
|
|
5359
5412
|
case 39:
|
|
5360
5413
|
// Extract response using the path
|
|
5361
5414
|
extractPath = (_args$responseExtract2 = args().responseExtractPath) === null || _args$responseExtract2 === void 0 ? void 0 : _args$responseExtract2.slice(1);
|
|
5362
|
-
|
|
5415
|
+
_context8.next = 42;
|
|
5363
5416
|
return fetch(args().requestApiUrl || '', {
|
|
5364
5417
|
method: "POST",
|
|
5365
5418
|
headers: args().headerConfigRes,
|
|
@@ -5367,22 +5420,22 @@ var Chatbox = function Chatbox(props) {
|
|
|
5367
5420
|
signal: abortController.current.signal
|
|
5368
5421
|
});
|
|
5369
5422
|
case 42:
|
|
5370
|
-
_response =
|
|
5423
|
+
_response = _context8.sent;
|
|
5371
5424
|
if (_response.ok) {
|
|
5372
|
-
|
|
5425
|
+
_context8.next = 47;
|
|
5373
5426
|
break;
|
|
5374
5427
|
}
|
|
5375
5428
|
_errInfo2 = "[ERROR] HTTP Error ".concat(_response.status, ": ").concat(_response.statusText); // hide loader
|
|
5376
5429
|
setLoaderDisplay(false);
|
|
5377
|
-
return
|
|
5430
|
+
return _context8.abrupt("return", {
|
|
5378
5431
|
reply: _errInfo2,
|
|
5379
5432
|
useStreamRender: false
|
|
5380
5433
|
});
|
|
5381
5434
|
case 47:
|
|
5382
|
-
|
|
5435
|
+
_context8.next = 49;
|
|
5383
5436
|
return _response.json();
|
|
5384
5437
|
case 49:
|
|
5385
|
-
jsonResponse =
|
|
5438
|
+
jsonResponse = _context8.sent;
|
|
5386
5439
|
// hide loader
|
|
5387
5440
|
setLoaderDisplay(false);
|
|
5388
5441
|
result = jsonResponse;
|
|
@@ -5401,33 +5454,33 @@ var Chatbox = function Chatbox(props) {
|
|
|
5401
5454
|
}
|
|
5402
5455
|
_content2 = result; // Replace with a valid label
|
|
5403
5456
|
_content2 = fixHtmlTags(_content2, args().withReasoning, args().reasoningSwitchLabel);
|
|
5404
|
-
return
|
|
5457
|
+
return _context8.abrupt("return", {
|
|
5405
5458
|
reply: formatLatestDisplayContent(_content2),
|
|
5406
5459
|
useStreamRender: false
|
|
5407
5460
|
});
|
|
5408
5461
|
case 56:
|
|
5409
|
-
|
|
5462
|
+
_context8.next = 64;
|
|
5410
5463
|
break;
|
|
5411
5464
|
case 58:
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
_err = "--> Error in mainRequest: ".concat(
|
|
5465
|
+
_context8.prev = 58;
|
|
5466
|
+
_context8.t0 = _context8["catch"](2);
|
|
5467
|
+
_err = "--> Error in mainRequest: ".concat(_context8.t0);
|
|
5415
5468
|
console.error(_err);
|
|
5416
5469
|
|
|
5417
5470
|
//reset SSE
|
|
5418
5471
|
closeSSE();
|
|
5419
|
-
return
|
|
5472
|
+
return _context8.abrupt("return", {
|
|
5420
5473
|
reply: _err,
|
|
5421
5474
|
useStreamRender: false
|
|
5422
5475
|
});
|
|
5423
5476
|
case 64:
|
|
5424
5477
|
case "end":
|
|
5425
|
-
return
|
|
5478
|
+
return _context8.stop();
|
|
5426
5479
|
}
|
|
5427
|
-
},
|
|
5480
|
+
}, _callee8, null, [[2, 58]]);
|
|
5428
5481
|
}));
|
|
5429
|
-
return function mainRequest(
|
|
5430
|
-
return
|
|
5482
|
+
return function mainRequest(_x14) {
|
|
5483
|
+
return _ref6.apply(this, arguments);
|
|
5431
5484
|
};
|
|
5432
5485
|
}();
|
|
5433
5486
|
|
|
@@ -5464,8 +5517,47 @@ var Chatbox = function Chatbox(props) {
|
|
|
5464
5517
|
// Bind chatboxCopyToClipboard to window so it can be called in HTML code
|
|
5465
5518
|
window.chatboxCopyToClipboard = chatboxCopyToClipboard;
|
|
5466
5519
|
}, []);
|
|
5520
|
+
|
|
5521
|
+
// Initialize the default value of toolkit buttons
|
|
5522
|
+
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
|
|
5523
|
+
if (args().toolkitButtons) {
|
|
5524
|
+
args().toolkitButtons.forEach(function (btn, index) {
|
|
5525
|
+
var _id = "".concat(args().prefix || 'custom-', "chatbox-btn-tools-").concat(chatId).concat(index);
|
|
5526
|
+
if (btn.isSelect) {
|
|
5527
|
+
if (!initializedDefaults[_id] && typeof btn.defaultSelected === 'number') {
|
|
5528
|
+
var options = getButtonOptions(btn, _id);
|
|
5529
|
+
|
|
5530
|
+
// If there is a default selected item, initialize the selected state
|
|
5531
|
+
if (btn.defaultSelected >= 0 && btn.defaultSelected < options.length) {
|
|
5532
|
+
var defaultOption = options[btn.defaultSelected];
|
|
5533
|
+
if (defaultOption) {
|
|
5534
|
+
// Update the selected status
|
|
5535
|
+
// console.log('--> defaultOption: ', defaultOption);
|
|
5536
|
+
|
|
5537
|
+
// Pass the "isDefaultSelection" parameter as true
|
|
5538
|
+
handleExecuteButtonSelect(_id, defaultOption, btn.defaultSelected, defaultOption.value, true);
|
|
5539
|
+
|
|
5540
|
+
// Perform the onClick action alone
|
|
5541
|
+
executeDefaultOptionAction(defaultOption.onClick, _id);
|
|
5542
|
+
|
|
5543
|
+
// Mark this button with the default value initialized
|
|
5544
|
+
setInitializedDefaults(function (prev) {
|
|
5545
|
+
return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, _id, true));
|
|
5546
|
+
});
|
|
5547
|
+
}
|
|
5548
|
+
}
|
|
5549
|
+
}
|
|
5550
|
+
} else if (btn.active) {
|
|
5551
|
+
// For non-select buttons, if defaultActive is true, execute the onClick action
|
|
5552
|
+
executeButtonAction(btn.onClick, _id, document.getElementById(_id));
|
|
5553
|
+
}
|
|
5554
|
+
});
|
|
5555
|
+
}
|
|
5556
|
+
}, [chatId, args().toolkitButtons]); // It is only executed when the component is first rendered and when toolkitButtons changes
|
|
5557
|
+
|
|
5467
5558
|
return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((dist_cjs_default()), {
|
|
5468
5559
|
show: true,
|
|
5560
|
+
usePortal: args().usePopUp,
|
|
5469
5561
|
containerClassName: "Chatbox"
|
|
5470
5562
|
}, args().bubble ? /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
|
|
5471
5563
|
className: "".concat(args().prefix || 'custom-', "chatbox-circle"),
|
|
@@ -5502,7 +5594,7 @@ var Chatbox = function Chatbox(props) {
|
|
|
5502
5594
|
style: {
|
|
5503
5595
|
display: show ? 'block' : 'none'
|
|
5504
5596
|
},
|
|
5505
|
-
className: "".concat(args().prefix || 'custom-', "chatbox-container"),
|
|
5597
|
+
className: "".concat(args().prefix || 'custom-', "chatbox-container ").concat(typeof args().usePopUp !== 'undefined' && args().usePopUp === false ? 'popup-none' : ''),
|
|
5506
5598
|
ref: rootRef
|
|
5507
5599
|
}, msgList.length === 0 ? /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
|
|
5508
5600
|
className: "d-flex flex-column align-items-center justify-content-center ".concat(hasQuestion() ? '' : 'h-50')
|
|
@@ -5551,7 +5643,7 @@ var Chatbox = function Chatbox(props) {
|
|
|
5551
5643
|
}
|
|
5552
5644
|
});
|
|
5553
5645
|
})))) : null, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
|
|
5554
|
-
className: "messages",
|
|
5646
|
+
className: "messages ".concat(msgList.length === 0 ? 'd-none' : ''),
|
|
5555
5647
|
ref: msgContainerRef
|
|
5556
5648
|
}, msgList.map(function (msg, index) {
|
|
5557
5649
|
var _msg$tag, _msg$tag2;
|
|
@@ -5693,8 +5785,8 @@ var Chatbox = function Chatbox(props) {
|
|
|
5693
5785
|
}
|
|
5694
5786
|
},
|
|
5695
5787
|
onChange: function onChange(e, el, value) {
|
|
5696
|
-
var _args$onInputChange,
|
|
5697
|
-
(_args$onInputChange = (
|
|
5788
|
+
var _args$onInputChange, _args17;
|
|
5789
|
+
(_args$onInputChange = (_args17 = args()).onInputChange) === null || _args$onInputChange === void 0 ? void 0 : _args$onInputChange.call(_args17, inputContentRef.current, value);
|
|
5698
5790
|
},
|
|
5699
5791
|
onFocus: function onFocus() {
|
|
5700
5792
|
setFocused(true);
|
|
@@ -5763,7 +5855,8 @@ var Chatbox = function Chatbox(props) {
|
|
|
5763
5855
|
className: "toolkit-select-wrapper"
|
|
5764
5856
|
}, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("button", {
|
|
5765
5857
|
id: _id,
|
|
5766
|
-
|
|
5858
|
+
"data-value": btn.value || '',
|
|
5859
|
+
className: "toolkit-select-btn ".concat(isActive ? 'active' : '', " ").concat(selectedOpt.curValue !== 'cancel' && typeof selectedOpt.curValue !== 'undefined' && selectedOpt.curValue !== '' ? 'opt-active' : ''),
|
|
5767
5860
|
onClick: function onClick(e) {
|
|
5768
5861
|
e.preventDefault();
|
|
5769
5862
|
setActiveButtons(function (prev) {
|
|
@@ -5800,7 +5893,8 @@ var Chatbox = function Chatbox(props) {
|
|
|
5800
5893
|
}, options.length > 0 ? /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, options.map(function (option, optIndex) {
|
|
5801
5894
|
return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
|
|
5802
5895
|
key: optIndex,
|
|
5803
|
-
|
|
5896
|
+
"data-value": option.value || '',
|
|
5897
|
+
className: "toolkit-select-option ".concat(selectedOpt.curIndex === optIndex ? 'selected' : ''),
|
|
5804
5898
|
onClick: function onClick() {
|
|
5805
5899
|
return handleExecuteButtonSelect(_id, option, optIndex, option.value);
|
|
5806
5900
|
}
|