@appbaseio/reactivesearch-vue 3.0.0-rc.16 → 3.0.0-rc.18

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.
@@ -25,8 +25,8 @@ var Flex = require('./Flex-ddde6d26.js');
25
25
  var analytics = require('@appbaseio/reactivecore/lib/actions/analytics');
26
26
  var ReactiveBase = require('./ReactiveBase.js');
27
27
  var hotkeys = _interopDefault(require('hotkeys-js'));
28
- var remarkable = require('remarkable');
29
28
  var xss = _interopDefault(require('xss'));
29
+ var remarkable = require('remarkable');
30
30
  var DropDown = require('./DropDown-e8216602.js');
31
31
  var Input = require('./Input-3ecdb905.js');
32
32
  var Container = require('./Container-29f049b2.js');
@@ -808,7 +808,7 @@ var HorizontalSkeletonLoader = vue.defineComponent({
808
808
  });
809
809
 
810
810
  var _templateObject$7, _templateObject2$2, _templateObject3$1, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11;
811
- var Chatbox = vueEmotion.styled('div')(_templateObject$7 || (_templateObject$7 = _rollupPluginBabelHelpers._taggedTemplateLiteralLoose(["\n\tposition: relative;\n\tmargin: 0 auto;\n\tpadding: 10px;\n\tbackground-color: #fafafa;\n\twidth: 100%;\n\tbox-shadow: rgb(0 0 0 / 20%) 0px 0px 6px;\n\tborder-radius: 6px;\n\tmargin-bottom: 20px;\n\tbackground-color: ", ";\n"])), function (props) {
811
+ var Chatbox = vueEmotion.styled('div')(_templateObject$7 || (_templateObject$7 = _rollupPluginBabelHelpers._taggedTemplateLiteralLoose(["\n\tposition: relative;\n\tmargin: 0 auto;\n\tpadding: 10px;\n\tbackground-color: #fafafa;\n\twidth: 100%;\n\tbox-shadow: rgb(0 0 0 / 20%) 0px 0px 6px;\n\tborder-radius: 6px;\n\tmargin-bottom: 20px;\n\tbackground-color: ", ";\n\n\t.--trigger-message-wrapper {\n\t\tcursor: pointer;\n\t}\n"])), function (props) {
812
812
  return props.theme && props.theme.colors ? props.theme.colors.backgroundColor : '#fff';
813
813
  });
814
814
  var ChatContainer = vueEmotion.styled('div')(_templateObject2$2 || (_templateObject2$2 = _rollupPluginBabelHelpers._taggedTemplateLiteralLoose(["\n\tdisplay: flex;\n\tflex-direction: column;\n\theight: 100%;\n\tposition: relative;\n\t.--ai-answer-error-container {\n\t\ttext-align: center;\n\t\tposition: absolute;\n\t\tbottom: 0px;\n\t\t", ";\n\t\tz-index: 1;\n\t\tleft: 50%;\n\t\ttransform: translateX(-50%);\n\t\twidth: 100%;\n\n\t\t.--default-error-element {\n\t\t\tdisplay: flex;\n\t\t\tflex-direction: column;\n\t\t\talign-items: center;\n\t\t\tpadding: 10px;\n\t\t\tbackground-color: ", ";\n\t\t\tbox-shadow: 0 -5px 5px -2px\n\t\t\t\t", ";\n\n\t\t\tspan {\n\t\t\t\tmargin-bottom: 5px;\n\t\t\t}\n\n\t\t\tbutton {\n\t\t\t}\n\t\t}\n\t}\n\n\t", ";\n"])), function (props) {
@@ -833,11 +833,15 @@ var TypingDot = vueEmotion.styled('div')(_templateObject6 || (_templateObject6 =
833
833
  return finalColor;
834
834
  }, typingDots);
835
835
  var resetCSS = function resetCSS(props) {
836
- return "\n\thtml,\n\tbody,\n\tdiv,\n\tspan,\n\tapplet,\n\tobject,\n\tiframe,\n\th1,\n\th2,\n\th3,\n\th4,\n\th5,\n\th6,\n\tp,\n\tblockquote,\n\tpre,\n\ta,\n\tabbr,\n\tacronym,\n\taddress,\n\tbig,\n\tcite,\n\tcode,\n\tdel,\n\tdfn,\n\tem,\n\timg,\n\tins,\n\tkbd,\n\tq,\n\ts,\n\tsamp,\n\tsmall,\n\tstrike,\n\tstrong,\n\tsub,\n\tsup,\n\ttt,\n\tvar,\n\tb,\n\tu,\n\ti,\n\tcenter,\n\tdl,\n\tdt,\n\tdd,\n\tol,\n\tul,\n\tli,\n\tfieldset,\n\tform,\n\tlabel,\n\tlegend,\n\ttable,\n\tcaption,\n\ttbody,\n\ttfoot,\n\tthead,\n\ttr,\n\tth,\n\ttd,\n\tarticle,\n\taside,\n\tcanvas,\n\tdetails,\n\tembed,\n\tfigure,\n\tfigcaption,\n\tfooter,\n\theader,\n\thgroup,\n\tmenu,\n\tnav,\n\toutput,\n\truby,\n\tsection,\n\tsummary,\n\ttime,\n\tmark,\n\taudio,\n\tvideo {\n\t\tmargin: 0;\n\t\tpadding: 0;\n\t\tborder: 0;\n\t\tfont-size: 100%;\n\t\tfont: inherit;\n\t\tvertical-align: baseline;\n\t\toverflow-wrap: anywhere;\n\t}\n\tpre {\n\t\tmargin: 10px auto;\n\t}\n\ttable {\n\t\tmargin: 10px auto;\n\t\tborder-collapse: collapse;\n\t\tborder-spacing: 0;\n\t}\n\ttr {\n\t\tborder-bottom: 1px solid #ccc;\n\t}\n\tth,\n\ttd {\n\t\ttext-align: left;\n\t\tpadding: 4px;\n\t\tborder: 1px solid;\n\t\tborder-collapse: collapse;\n\t}\n\tpre,\n\tcode {\n\t\tpadding: 0.6em 0.4em;\n\t\tbackground: " + (
836
+ return "\n\thtml,\n\tbody,\n\tdiv,\n\tspan,\n\tapplet,\n\tobject,\n\tiframe,\n\th1,\n\th2,\n\th3,\n\th4,\n\th5,\n\th6,\n\tp,\n\tblockquote,\n\tpre,\n\ta,\n\tabbr,\n\tacronym,\n\taddress,\n\tbig,\n\tcite,\n\tcode,\n\tdel,\n\tdfn,\n\tem,\n\timg,\n\tins,\n\tkbd,\n\tq,\n\ts,\n\tsamp,\n\tsmall,\n\tstrike,\n\tstrong,\n\tsub,\n\tsup,\n\ttt,\n\tvar,\n\tb,\n\tu,\n\ti,\n\tcenter,\n\tdl,\n\tdt,\n\tdd,\n\tol,\n\tul,\n\tli,\n\tfieldset,\n\tform,\n\tlabel,\n\tlegend,\n\ttable,\n\tcaption,\n\ttbody,\n\ttfoot,\n\tthead,\n\ttr,\n\tth,\n\ttd,\n\tarticle,\n\taside,\n\tcanvas,\n\tdetails,\n\tembed,\n\tfigure,\n\tfigcaption,\n\tfooter,\n\theader,\n\thgroup,\n\tmenu,\n\tnav,\n\toutput,\n\truby,\n\tsection,\n\tsummary,\n\ttime,\n\tmark,\n\taudio,\n\tvideo {\n\t\tmargin: 0;\n\t\tpadding: 0;\n\t\tborder: 0;\n\t\tfont-size: 100%;\n\t\tfont: inherit;\n\t\tvertical-align: baseline;\n\t\toverflow-wrap: anywhere;\n\t}\n\tpre {\n\t\tmargin: 10px auto;\n\t\twhite-space: pre-wrap;\n\n\t}\n\ttable {\n\t\tmargin: 10px auto;\n\t\tborder-collapse: collapse;\n\t\tborder-spacing: 0;\n\t}\n\ttr {\n\t\tborder-bottom: 1px solid #ccc;\n\t}\n\tth,\n\ttd {\n\t\ttext-align: left;\n\t\tpadding: 4px;\n\t\tborder: 1px solid;\n\t\tborder-collapse: collapse;\n\t}\n\tpre,\n\tcode {\n\t\tpadding: 0.6em 0.4em;\n\t\tbackground: " + (
837
+ // eslint-disable-next-line no-nested-ternary
838
+ props.isSender ? props.themePreset !== 'dark' ? props.theme.colors.primaryColor : props.theme.colors.borderColor : props.theme.colors.borderColor) + ";\n\n\t}\n\n\tpre{\n\t\tcolor: " + (
837
839
  // eslint-disable-next-line no-nested-ternary
838
- props.isSender ? props.themePreset !== 'dark' ? props.theme.colors.primaryColor : props.theme.colors.borderColor : props.theme.colors.borderColor) + ";\n\t}\n\n\tcode {\n\t\tline-height: normal;\n\n\t\tcolor: " + (
840
+ props.isSender ? props.themePreset !== 'dark' ? props.theme.colors.primaryTextColor : props.theme.colors.textColor : props.theme.colors.primaryTextColor) + ";}\n\n\tcode {\n\t\tline-height: normal;\n\n\t\tcolor: " + (
839
841
  // eslint-disable-next-line no-nested-ternary
840
- props.isSender ? props.themePreset !== 'dark' ? props.theme.colors.primaryTextColor : props.theme.colors.textColor : props.theme.colors.primaryTextColor) + ";\n\t\tborder-radius: 3px;\n\t\tfont-size: 85%;\n\t\tpadding: 0.2em 0.4em;\n\t\tmargin-top: 5px;\n\t\tdisplay: inline-block;\n\t\toverflow: auto;\n\t\twidth: fit-content;\n\t\tmax-width: 100%;\n\t}\n\tul,\n\tol {\n\t\tlist-style-position: inside;\n\t\tpadding-left: 10px;\n\n\t}\n\n\tli{\n\t\tdisplay: list-item;\n\t\tcursor: default;\n\t\tpadding: initial;\n\n\t\t&:hover{\n\t\t\tbackground-color: initial;\n\t\t}\n\t}\n\tp {\n\t\tmargin: inherit;\n\t}\n";
842
+ props.isSender ? props.themePreset !== 'dark' ? props.theme.colors.primaryTextColor : props.theme.colors.textColor : props.theme.colors.primaryTextColor) + ";\n\t\tborder-radius: 3px;\n\t\tfont-size: 85%;\n\t\tpadding: 0.2em 0.4em;\n\t\tmargin-top: 5px;\n\t\tdisplay: inline-block;\n\t\toverflow: auto;\n\t\twidth: fit-content;\n\t\tmax-width: 100%;\n\t}\n\ncode[class*='language-'],\n\tpre[class*='language-'] {\n\t\tcolor: " + (
843
+ // eslint-disable-next-line no-nested-ternary
844
+ props.isSender ? props.themePreset !== 'dark' ? props.theme.colors.primaryTextColor : props.theme.colors.textColor : props.theme.colors.primaryTextColor) + ";\n\t\ttext-shadow: none;\n\t}\n\n\tul,\n\tol {\n\t\tlist-style-position: inside;\n\t\tpadding-left: 10px;\n\n\t}\n\n\tli{\n\t\tdisplay: list-item;\n\t\tcursor: default;\n\t\tpadding: initial;\n\n\t\t&:hover{\n\t\t\tbackground-color: initial;\n\t\t}\n\t}\n\tp {\n\t\tmargin: inherit;\n\t}\n";
841
845
  };
842
846
  var messageBGColor = function messageBGColor(props) {
843
847
  var finalBGColor;
@@ -1088,7 +1092,9 @@ var md = new remarkable.Remarkable();
1088
1092
  md.set({
1089
1093
  html: true,
1090
1094
  breaks: true,
1091
- xhtmlOut: true
1095
+ xhtmlOut: true,
1096
+ linkify: true,
1097
+ linkTarget: '_blank'
1092
1098
  });
1093
1099
  var _dropdownULRef = 'dropdownULRef';
1094
1100
  var _inputGroupRef = 'inputGroupRef';
@@ -1116,7 +1122,9 @@ var SearchBox = vue.defineComponent({
1116
1122
  showAIScreen: false,
1117
1123
  showAIScreenFooter: false,
1118
1124
  showFeedbackComponent: false,
1119
- feedbackState: null
1125
+ feedbackState: null,
1126
+ faqAnswer: '',
1127
+ faqQuestion: ''
1120
1128
  };
1121
1129
  this.internalComponent = props.componentId + "__internal";
1122
1130
  return this.__state;
@@ -1152,17 +1160,33 @@ var SearchBox = vue.defineComponent({
1152
1160
  }
1153
1161
  },
1154
1162
  computed: {
1163
+ currentTriggerMode: function currentTriggerMode() {
1164
+ return this.$props.AIUIConfig && this.$props.AIUIConfig.triggerOn || constants.AI_TRIGGER_MODES.MANUAL;
1165
+ },
1155
1166
  hasCustomRenderer: function hasCustomRenderer() {
1156
1167
  return index.hasCustomRenderer(this);
1157
1168
  },
1158
1169
  stats: function stats() {
1159
1170
  return getResultStats(this);
1160
1171
  },
1172
+ mergedAIQuestion: function mergedAIQuestion() {
1173
+ return this.faqQuestion || this.AIResponse && this.AIResponse.response && this.AIResponse.response.question;
1174
+ },
1175
+ mergedAIAnswer: function mergedAIAnswer() {
1176
+ return this.faqAnswer || this.AIResponse && this.AIResponse.response && this.AIResponse.response.answer && this.AIResponse.response.answer.text;
1177
+ },
1161
1178
  parsedSuggestions: function parsedSuggestions() {
1162
1179
  var suggestionsArray = [];
1163
1180
  if (Array.isArray(this.suggestions) && this.suggestions.length) {
1164
1181
  suggestionsArray = [].concat(withClickIds(this.suggestions));
1165
1182
  }
1183
+ if (this.renderTriggerMessage() && this.currentValue && !this.isLoading) {
1184
+ suggestionsArray.unshift({
1185
+ label: this.renderTriggerMessage(),
1186
+ value: 'AI_TRIGGER_MESSAGE',
1187
+ _suggestion_type: '_internal_a_i_trigger'
1188
+ });
1189
+ }
1166
1190
  suggestionsArray = suggestionsArray.map(function (s) {
1167
1191
  if (s.sectionId) {
1168
1192
  return s;
@@ -1216,6 +1240,11 @@ var SearchBox = vue.defineComponent({
1216
1240
  enableQuerySuggestions: VueTypes.bool.def(false),
1217
1241
  enablePopularSuggestions: VueTypes.bool.def(false),
1218
1242
  enableRecentSuggestions: VueTypes.bool.def(false),
1243
+ enableFAQSuggestions: VueTypes.bool.def(false),
1244
+ FAQSuggestionsConfig: VueTypes.shape({
1245
+ sectionLabel: VueTypes.string,
1246
+ size: VueTypes.number
1247
+ }),
1219
1248
  fieldWeights: vueTypes.types.fieldWeights,
1220
1249
  filterLabel: vueTypes.types.string,
1221
1250
  fuzziness: vueTypes.types.fuzziness,
@@ -1339,7 +1368,11 @@ var SearchBox = vue.defineComponent({
1339
1368
  if (this.$options.isTagsMode) {
1340
1369
  cause = reactivecore.causes.SUGGESTION_SELECT;
1341
1370
  }
1342
- this.setValue(newVal || '', true, this.$props, cause);
1371
+ if (this.$props.value === undefined) {
1372
+ this.setValue(newVal, newVal === '', this.$props, cause, false);
1373
+ } else {
1374
+ this.setValue(newVal || '', true, this.$props, cause);
1375
+ }
1343
1376
  }
1344
1377
  },
1345
1378
  focusShortcuts: function focusShortcuts() {
@@ -1427,6 +1460,20 @@ var SearchBox = vue.defineComponent({
1427
1460
  }
1428
1461
  },
1429
1462
  methods: {
1463
+ renderTriggerMessage: function renderTriggerMessage() {
1464
+ if (this.$props.enableAI) {
1465
+ if (this.$props.AIUIConfig && this.$props.AIUIConfig.renderTriggerMessage) {
1466
+ return this.$props.AIUIConfig.renderTriggerMessage;
1467
+ }
1468
+ if (this.$slots.renderTriggerMessage) {
1469
+ return this.$slots.renderTriggerMessage();
1470
+ }
1471
+ if (this.currentTriggerMode === constants.AI_TRIGGER_MODES.MANUAL && (this.$props.AIUIConfig ? !this.$props.AIUIConfig.askButton : true)) {
1472
+ return 'Click to trigger AIAnswer';
1473
+ }
1474
+ }
1475
+ return null;
1476
+ },
1430
1477
  handleText: function handleText(value, cause) {
1431
1478
  if (cause === reactivecore.causes.CLEAR_VALUE) {
1432
1479
  this.triggerCustomQuery(value);
@@ -1451,8 +1498,8 @@ var SearchBox = vue.defineComponent({
1451
1498
  value: currentValue,
1452
1499
  resultStats: this.stats,
1453
1500
  AIData: {
1454
- question: this.AIResponse && this.AIResponse.response && this.AIResponse.response.question,
1455
- answer: this.AIResponse && this.AIResponse.response && this.AIResponse.response.answer && this.AIResponse.response.answer.text,
1501
+ question: this.mergedAIQuestion,
1502
+ answer: this.mergedAIAnswer,
1456
1503
  documentIds: this.AIResponse && this.AIResponse.response && this.AIResponse.response.answer && this.AIResponse.response.answer.documentIds || [],
1457
1504
  showAIScreen: this.showAIScreen,
1458
1505
  sources: this.getAISourceObjects(),
@@ -1483,7 +1530,7 @@ var SearchBox = vue.defineComponent({
1483
1530
  this.onValueSelectedHandler(currentValue, reactivecore.causes.SEARCH_ICON_CLICK);
1484
1531
  }
1485
1532
  },
1486
- setValue: function setValue(value, isDefaultValue, props, cause, toggleIsOpen, categoryValue) {
1533
+ setValue: function setValue(value, isDefaultValue, props, cause, toggleIsOpen, categoryValue, shouldExecuteQuery) {
1487
1534
  var _this2 = this;
1488
1535
  if (isDefaultValue === void 0) {
1489
1536
  isDefaultValue = false;
@@ -1497,6 +1544,9 @@ var SearchBox = vue.defineComponent({
1497
1544
  if (categoryValue === void 0) {
1498
1545
  categoryValue = undefined;
1499
1546
  }
1547
+ if (shouldExecuteQuery === void 0) {
1548
+ shouldExecuteQuery = true;
1549
+ }
1500
1550
  var performUpdate = function performUpdate() {
1501
1551
  if (_this2.$options.isTagsMode && isEqual(value, _this2.selectedTags)) {
1502
1552
  return;
@@ -1525,24 +1575,31 @@ var SearchBox = vue.defineComponent({
1525
1575
  if (_this2.$options.isTagsMode && cause === reactivecore.causes.SUGGESTION_SELECT) {
1526
1576
  queryHandlerValue = Array.isArray(_this2.selectedTags) && _this2.selectedTags.length ? _this2.selectedTags : undefined;
1527
1577
  }
1578
+ if ((_this2.faqAnswer || _this2.faqQuestion) && value === '') {
1579
+ // Empty the previous state
1580
+ _this2.faqAnswer = '';
1581
+ _this2.faqQuestion = '';
1582
+ _this2.showAIScreen = false;
1583
+ }
1528
1584
  if (isDefaultValue) {
1529
1585
  if (_this2.$props.autosuggest) {
1530
1586
  if (toggleIsOpen) {
1531
1587
  _this2.isOpen = false;
1532
1588
  }
1533
- if (typeof _this2.currentValue === 'string') _this2.triggerDefaultQuery(_this2.currentValue, props.enableAI ? {
1589
+ if (typeof _this2.currentValue === 'string') _this2.triggerDefaultQuery(_this2.currentValue, props.enableAI && _this2.currentTriggerMode === constants.AI_TRIGGER_MODES.QUESTION && _this2.currentValue.endsWith('?') ? {
1534
1590
  enableAI: true
1535
- } : {});
1591
+ } : {}, shouldExecuteQuery);
1536
1592
  } // in case of strict selection only SUGGESTION_SELECT should be able
1537
1593
  // to set the query otherwise the value should reset
1538
1594
  if (props.strictSelection) {
1539
1595
  if (cause === reactivecore.causes.SUGGESTION_SELECT || (_this2.$options.isTagsMode ? _this2.selectedTags.length === 0 : value === '')) {
1540
- _this2.triggerCustomQuery(queryHandlerValue, _this2.$options.isTagsMode ? undefined : categoryValue);
1596
+ _this2.triggerCustomQuery(queryHandlerValue, _this2.$options.isTagsMode ? undefined : categoryValue, shouldExecuteQuery);
1541
1597
  } else {
1542
1598
  _this2.setValue('', true);
1543
1599
  }
1544
1600
  } else if (props.value === undefined || cause === reactivecore.causes.SUGGESTION_SELECT || cause === reactivecore.causes.CLEAR_VALUE) {
1545
- _this2.triggerCustomQuery(queryHandlerValue, _this2.$options.isTagsMode ? undefined : categoryValue);
1601
+ _this2.showAIScreen = false;
1602
+ _this2.triggerCustomQuery(queryHandlerValue, _this2.$options.isTagsMode ? undefined : categoryValue, shouldExecuteQuery);
1546
1603
  }
1547
1604
  } else {
1548
1605
  // debounce for handling text while typing
@@ -1553,10 +1610,13 @@ var SearchBox = vue.defineComponent({
1553
1610
  };
1554
1611
  checkValueChange(props.componentId, value, props.beforeValueChange, performUpdate);
1555
1612
  },
1556
- triggerDefaultQuery: function triggerDefaultQuery(paramValue, meta) {
1613
+ triggerDefaultQuery: function triggerDefaultQuery(paramValue, meta, shouldExecuteQuery) {
1557
1614
  if (meta === void 0) {
1558
1615
  meta = {};
1559
1616
  }
1617
+ if (shouldExecuteQuery === void 0) {
1618
+ shouldExecuteQuery = true;
1619
+ }
1560
1620
  if (!this.$props.autosuggest) {
1561
1621
  return;
1562
1622
  }
@@ -1577,12 +1637,15 @@ var SearchBox = vue.defineComponent({
1577
1637
  value: value,
1578
1638
  componentType: constants.componentTypes.searchBox,
1579
1639
  meta: meta
1580
- });
1640
+ }, shouldExecuteQuery);
1581
1641
  },
1582
- triggerCustomQuery: function triggerCustomQuery(paramValue, categoryValue) {
1642
+ triggerCustomQuery: function triggerCustomQuery(paramValue, categoryValue, shouldExecuteQuery) {
1583
1643
  if (categoryValue === void 0) {
1584
1644
  categoryValue = undefined;
1585
1645
  }
1646
+ if (shouldExecuteQuery === void 0) {
1647
+ shouldExecuteQuery = true;
1648
+ }
1586
1649
  var _this$$props = this.$props,
1587
1650
  customQuery = _this$$props.customQuery,
1588
1651
  filterLabel = _this$$props.filterLabel,
@@ -1611,7 +1674,7 @@ var SearchBox = vue.defineComponent({
1611
1674
  URLParams: URLParams,
1612
1675
  componentType: constants.componentTypes.searchBox,
1613
1676
  category: categoryValue
1614
- });
1677
+ }, shouldExecuteQuery);
1615
1678
  },
1616
1679
  handleFocus: function handleFocus(event) {
1617
1680
  if (this.$props.autosuggest) {
@@ -1622,7 +1685,9 @@ var SearchBox = vue.defineComponent({
1622
1685
  handleVoiceResults: function handleVoiceResults(_ref) {
1623
1686
  var results = _ref.results;
1624
1687
  if (results && results[0] && results[0].isFinal && results[0][0] && results[0][0].transcript && results[0][0].transcript.trim()) {
1688
+ var _this$$refs2;
1625
1689
  this.setValue(results[0][0].transcript.trim(), true);
1690
+ (_this$$refs2 = this.$refs) == null || (_this$$refs2 = _this$$refs2[this.$props.innerRef]) == null || (_this$$refs2 = _this$$refs2.$el) == null ? void 0 : _this$$refs2.focus(); // eslint-disable-line
1626
1691
  }
1627
1692
  },
1628
1693
  triggerQuery: function triggerQuery(_ref2) {
@@ -1662,6 +1727,8 @@ var SearchBox = vue.defineComponent({
1662
1727
  clearValue: function clearValue() {
1663
1728
  this.setValue('', false, this.$props, !this.$options.isTagsMode ? reactivecore.causes.CLEAR_VALUE : undefined, false);
1664
1729
  this.onValueSelectedHandler('', !this.$options.isTagsMode ? reactivecore.causes.CLEAR_VALUE : undefined);
1730
+ this.showAIScreen = false;
1731
+ this.isOpen = false;
1665
1732
  },
1666
1733
  handleKeyDown: function handleKeyDown(event, highlightedIndex) {
1667
1734
  if (highlightedIndex === void 0) {
@@ -1674,9 +1741,10 @@ var SearchBox = vue.defineComponent({
1674
1741
  } else if (highlightedIndex === null) {
1675
1742
  this.setValue(event.target.value, true, this.$props, this.$options.isTagsMode ? reactivecore.causes.SUGGESTION_SELECT : undefined,
1676
1743
  // to handle tags
1677
- !this.$props.enableAI);
1678
- if (this.$props.enableAI && !this.showAIScreen) {
1744
+ !(this.$props.enableAI && this.currentTriggerMode === constants.AI_TRIGGER_MODES.QUESTION && event.target.value.endsWith('?')));
1745
+ if (this.$props.enableAI && !this.showAIScreen && this.currentTriggerMode === constants.AI_TRIGGER_MODES.QUESTION && event.target.value.endsWith('?')) {
1679
1746
  this.showAIScreen = true;
1747
+ this.isOpen = true;
1680
1748
  }
1681
1749
  this.onValueSelectedHandler(event.target.value, reactivecore.causes.ENTER_PRESS);
1682
1750
  }
@@ -1697,7 +1765,7 @@ var SearchBox = vue.defineComponent({
1697
1765
  }
1698
1766
  var value = this.$props.value;
1699
1767
  if (value === undefined) {
1700
- this.setValue(inputValue, false, this.$props, undefined);
1768
+ this.setValue(inputValue, inputValue === '', this.$props, undefined, false);
1701
1769
  } else {
1702
1770
  this.$emit('change', inputValue, function (_ref3) {
1703
1771
  var isOpen = _ref3.isOpen;
@@ -1712,7 +1780,7 @@ var SearchBox = vue.defineComponent({
1712
1780
  },
1713
1781
  handleFeaturedSuggestionClicked: function handleFeaturedSuggestionClicked(suggestion) {
1714
1782
  try {
1715
- var _this$$refs2;
1783
+ var _this$$refs3;
1716
1784
  if (suggestion.action === helper.featuredSuggestionsActionTypes.NAVIGATE) {
1717
1785
  var _JSON$parse = JSON.parse(suggestion.subAction),
1718
1786
  _JSON$parse$target = _JSON$parse.target,
@@ -1731,7 +1799,7 @@ var SearchBox = vue.defineComponent({
1731
1799
  func(suggestion, this.$data.currentValue, this.$props.customEvents);
1732
1800
  }
1733
1801
  if (suggestion.action === helper.featuredSuggestionsActionTypes.SELECT) {
1734
- this.setValue(suggestion.value, true, this.$props, this.$options.isTagsMode.current ? reactivecore.causes.SUGGESTION_SELECT : reactivecore.causes.ENTER_PRESS);
1802
+ this.setValue(suggestion.value, true, this.$props, this.$options.isTagsMode.current ? reactivecore.causes.SUGGESTION_SELECT : reactivecore.causes.ENTER_PRESS, false);
1735
1803
  this.onValueSelectedHandler(suggestion.value, reactivecore.causes.SUGGESTION_SELECT);
1736
1804
  }
1737
1805
  // blur is important to close the dropdown
@@ -1739,21 +1807,41 @@ var SearchBox = vue.defineComponent({
1739
1807
  // else Downshift probably is focusing the dropdown
1740
1808
  // and not letting it close
1741
1809
  // eslint-disable-next-line no-unused-expressions
1742
- (_this$$refs2 = this.$refs) == null || (_this$$refs2 = _this$$refs2[this.$props.innerRef]) == null ? void 0 : _this$$refs2.blur();
1810
+ (_this$$refs3 = this.$refs) == null || (_this$$refs3 = _this$$refs3[this.$props.innerRef]) == null || (_this$$refs3 = _this$$refs3.el) == null ? void 0 : _this$$refs3.blur();
1743
1811
  } catch (e) {
1744
1812
  console.error("Error: There was an error parsing the subAction for the featured suggestion with label, \"" + suggestion.label + "\"", e);
1745
1813
  }
1746
1814
  },
1747
1815
  onSuggestionSelected: function onSuggestionSelected(suggestion) {
1748
1816
  var _this4 = this;
1749
- if (!this.$props.enableAI) this.isOpen = false;else {
1817
+ var value = this.$props.value;
1818
+ // The state of the suggestion is open by the time it reaches here. i.e. isOpen = true
1819
+ // handle when FAQ suggestion is clicked
1820
+ if (suggestion && suggestion._suggestion_type === helper.suggestionTypes.FAQ) {
1821
+ this.currentValue = suggestion.value;
1822
+ // Handle AI
1823
+ // Independent of enableAI.
1824
+ this.faqAnswer = suggestion._answer;
1825
+ this.faqQuestion = suggestion.value;
1826
+ this.isOpen = true;
1750
1827
  this.showAIScreen = true;
1828
+ if (value !== undefined) this.$emit('change', suggestion.value, function () {});
1829
+ this.onValueSelectedHandler(suggestion.value);
1830
+ return;
1831
+ }
1832
+ if (suggestion && suggestion._suggestion_type === '_internal_a_i_trigger') {
1833
+ this.showAIScreen = true;
1834
+ this.askButtonOnClick();
1835
+ return;
1751
1836
  }
1752
- var value = this.$props.value;
1753
1837
 
1754
1838
  // handle featured suggestions click event
1755
1839
  if (suggestion._suggestion_type === helper.suggestionTypes.Featured) {
1756
1840
  this.handleFeaturedSuggestionClicked(suggestion);
1841
+ // Handle AI
1842
+ if (!this.$props.enableAI) this.isOpen = false;else {
1843
+ this.showAIScreen = true;
1844
+ }
1757
1845
  return;
1758
1846
  }
1759
1847
  // Record analytics for selected suggestions
@@ -1783,6 +1871,11 @@ var SearchBox = vue.defineComponent({
1783
1871
  });
1784
1872
  }
1785
1873
  this.onValueSelectedHandler(suggestion.value, reactivecore.causes.SUGGESTION_SELECT, suggestion.source);
1874
+
1875
+ // Handle AI
1876
+ if (!this.$props.enableAI) this.isOpen = false;else if (this.currentTriggerMode === constants.AI_TRIGGER_MODES.QUESTION && suggestion.value.endsWith('?')) {
1877
+ this.showAIScreen = true;
1878
+ }
1786
1879
  },
1787
1880
  onValueSelectedHandler: function onValueSelectedHandler(currentValue) {
1788
1881
  if (currentValue === void 0) {
@@ -2026,14 +2119,14 @@ var SearchBox = vue.defineComponent({
2026
2119
  })]);
2027
2120
  },
2028
2121
  focusSearchBox: function focusSearchBox(event) {
2029
- var _this$$refs3;
2122
+ var _this$$refs4;
2030
2123
  var elt = event.target || event.srcElement;
2031
2124
  var tagName = elt.tagName;
2032
2125
  if (elt.isContentEditable || tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA') {
2033
2126
  // already in an input
2034
2127
  return;
2035
2128
  }
2036
- (_this$$refs3 = this.$refs) == null || (_this$$refs3 = _this$$refs3[this.$props.innerRef]) == null || (_this$$refs3 = _this$$refs3.$el) == null ? void 0 : _this$$refs3.focus(); // eslint-disable-line
2129
+ (_this$$refs4 = this.$refs) == null || (_this$$refs4 = _this$$refs4[this.$props.innerRef]) == null || (_this$$refs4 = _this$$refs4.$el) == null ? void 0 : _this$$refs4.focus(); // eslint-disable-line
2037
2130
  },
2038
2131
  listenForFocusShortcuts: function listenForFocusShortcuts() {
2039
2132
  var _this9 = this;
@@ -2252,8 +2345,8 @@ var SearchBox = vue.defineComponent({
2252
2345
  var customAIRenderer = this.$props.renderAIAnswer || this.$slots.renderAIAnswer;
2253
2346
  if (customAIRenderer) {
2254
2347
  return customAIRenderer({
2255
- question: this.AIResponse && this.AIResponse.response && this.AIResponse.response.question,
2256
- answer: this.AIResponse && this.AIResponse.response && this.AIResponse.response.answer && this.AIResponse.response.answer.text,
2348
+ question: this.mergedAIQuestion,
2349
+ answer: this.mergedAIAnswer,
2257
2350
  documentIds: this.AIResponse && this.AIResponse.response && this.AIResponse.response.answer && this.AIResponse.response.answer.documentIds || [],
2258
2351
  loading: this.isAIResponseLoading || this.isLoading,
2259
2352
  sources: this.getAISourceObjects(),
@@ -2264,7 +2357,7 @@ var SearchBox = vue.defineComponent({
2264
2357
  return this.renderAIScreenLoader();
2265
2358
  }
2266
2359
  return vue.createVNode("div", null, [vue.createVNode(Answer, {
2267
- "innerHTML": md.render(this.AIResponse && this.AIResponse.response && this.AIResponse.response.answer && this.AIResponse.response.answer.text)
2360
+ "innerHTML": md.render(this.mergedAIAnswer)
2268
2361
  }, null), this.renderAIScreenFooter(), this.showFeedbackComponent && vue.createVNode("div", {
2269
2362
  "class": "" + (getClassName$1(this.$props.innerClass, 'ai-feedback') || '')
2270
2363
  }, [vue.createVNode(AIFeedback, {
@@ -2450,23 +2543,43 @@ var SearchBox = vue.defineComponent({
2450
2543
  var suggestionsHaveIcon = item.some(function (s) {
2451
2544
  return s.icon || s.iconURL;
2452
2545
  });
2453
- return renderItem ? vue.createVNode("li", vue.mergeProps(getItemProps({
2454
- item: sectionItem
2455
- }), _transformOn(getItemEvents({
2456
- item: sectionItem
2457
- })), {
2458
- "key": index + sectionIndex,
2459
- "style": {
2460
- justifyContent: 'flex-start',
2461
- alignItems: 'center'
2462
- },
2463
- "class": "" + (highlightedIndex === index + sectionIndex ? "active-li-item " + getClassName$1(_this16.$props.innerClass, 'active-suggestion-item') : "li-item " + getClassName$1(_this16.$props.innerClass, 'suggestion-item'))
2464
- }), [renderItem(sectionItem)]) : vue.createVNode("li", vue.mergeProps(getItemProps({
2546
+ if (renderItem) {
2547
+ return vue.createVNode("li", vue.mergeProps(getItemProps({
2548
+ item: sectionItem
2549
+ }), _transformOn(getItemEvents({
2550
+ item: sectionItem
2551
+ })), {
2552
+ "key": sectionItem._id + "_" + index + "_" + sectionIndex,
2553
+ "style": {
2554
+ justifyContent: 'flex-start',
2555
+ alignItems: 'center'
2556
+ },
2557
+ "class": "" + (highlightedIndex === index + sectionIndex ? "active-li-item " + getClassName$1(_this16.$props.innerClass, 'active-suggestion-item') : "li-item " + getClassName$1(_this16.$props.innerClass, 'suggestion-item'))
2558
+ }), [renderItem(sectionItem)]);
2559
+ }
2560
+ if (sectionItem._suggestion_type === '_internal_a_i_trigger') {
2561
+ return vue.createVNode("li", vue.mergeProps(getItemProps({
2562
+ item: sectionItem
2563
+ }), _transformOn(getItemEvents({
2564
+ item: sectionItem
2565
+ })), {
2566
+ "key": sectionItem._id + "_" + index + "_" + sectionIndex,
2567
+ "style": {
2568
+ justifyContent: 'flex-start',
2569
+ alignItems: 'center'
2570
+ },
2571
+ "class": "" + (highlightedIndex === index + sectionIndex ? "active-li-item " + getClassName$1(_this16.$props.innerClass, 'active-suggestion-item') : "li-item " + getClassName$1(_this16.$props.innerClass, 'suggestion-item'))
2572
+ }), [vue.createVNode(SuggestionItem, {
2573
+ "currentValue": _this16.currentValue,
2574
+ "suggestion": sectionItem
2575
+ }, null)]);
2576
+ }
2577
+ return vue.createVNode("li", vue.mergeProps(getItemProps({
2465
2578
  item: sectionItem
2466
2579
  }), _transformOn(getItemEvents({
2467
2580
  item: sectionItem
2468
2581
  })), {
2469
- "key": index + sectionIndex,
2582
+ "key": sectionItem._id + "_" + index + "_" + sectionIndex,
2470
2583
  "style": {
2471
2584
  justifyContent: 'flex-start',
2472
2585
  alignItems: 'center'
@@ -2681,6 +2794,7 @@ SBConnected.install = function (Vue) {
2681
2794
  // Add componentType for SSR
2682
2795
  SBConnected.componentType = constants.componentTypes.searchBox;
2683
2796
 
2797
+ var _excluded$1 = ["_source"];
2684
2798
  function _isSlot$1(s) {
2685
2799
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
2686
2800
  }
@@ -2688,7 +2802,9 @@ var md$1 = new remarkable.Remarkable();
2688
2802
  md$1.set({
2689
2803
  html: true,
2690
2804
  breaks: true,
2691
- xhtmlOut: true
2805
+ xhtmlOut: true,
2806
+ linkify: true,
2807
+ linkTarget: '_blank'
2692
2808
  });
2693
2809
  var _inputWrapperRef = 'inputWrapperRef';
2694
2810
  var _inputRef = 'inputRef';
@@ -2701,7 +2817,10 @@ var AIAnswer = vue.defineComponent({
2701
2817
  messages: [],
2702
2818
  inputMessage: '',
2703
2819
  AISessionId: '',
2704
- error: null
2820
+ error: null,
2821
+ sourceDocIds: null,
2822
+ initialHits: null,
2823
+ isTriggered: false
2705
2824
  };
2706
2825
  this.internalComponent = props.componentId + "__internal";
2707
2826
  return this.__state;
@@ -2711,7 +2830,16 @@ var AIAnswer = vue.defineComponent({
2711
2830
  from: 'theme_reactivesearch'
2712
2831
  }
2713
2832
  },
2714
- created: function created() {},
2833
+ created: function created() {
2834
+ if (this.$props.triggerOn === constants.AI_TRIGGER_MODES.ALWAYS) {
2835
+ this.isTriggered = true;
2836
+ } else if (this.$props.triggerOn === constants.AI_TRIGGER_MODES.QUESTION && this.dependentComponentValue && this.dependentComponentValue.endsWith('?')) {
2837
+ this.isTriggered = true;
2838
+ if (this.AISessionId) {
2839
+ this.handleSendMessage(null, false, '', true);
2840
+ }
2841
+ }
2842
+ },
2715
2843
  computed: {
2716
2844
  hasCustomRenderer: function hasCustomRenderer() {
2717
2845
  return index.hasCustomRenderer(this);
@@ -2724,6 +2852,9 @@ var AIAnswer = vue.defineComponent({
2724
2852
  },
2725
2853
  errorMessageForMissingSessionId: function errorMessageForMissingSessionId() {
2726
2854
  return "AISessionId for " + this.$props.componentId + " is missing! AIAnswer component requires an AISessionId to function. Try reloading the App.";
2855
+ },
2856
+ hasTriggered: function hasTriggered() {
2857
+ return this.isTriggered;
2727
2858
  }
2728
2859
  },
2729
2860
  props: {
@@ -2762,13 +2893,26 @@ var AIAnswer = vue.defineComponent({
2762
2893
  sessionIdFromStore: VueTypes.string,
2763
2894
  showComponent: vueTypes.types.boolRequired,
2764
2895
  componentError: vueTypes.types.componentObject,
2765
- style: vueTypes.types.style
2896
+ style: vueTypes.types.style,
2897
+ showSourceDocuments: VueTypes.bool.def(false),
2898
+ renderSourceDocument: vueTypes.types.func,
2899
+ onSourceClick: vueTypes.types.func,
2900
+ isAITyping: vueTypes.types.boolRequired,
2901
+ triggerOn: VueTypes.string.def(constants.AI_TRIGGER_MODES.ALWAYS),
2902
+ renderTriggerMessage: vueTypes.types.func
2766
2903
  },
2767
2904
  mounted: function mounted() {},
2768
2905
  watch: {
2769
2906
  AIResponse: function AIResponse(newVal) {
2770
2907
  if (newVal) {
2771
- this.AISessionId = ((helper.getObjectFromLocalStorage(constants.AI_LOCAL_CACHE_KEY) || {})[this.$props.componentId] || {}).sessionId || null;
2908
+ if (this.$props.showSourceDocuments && newVal.response && newVal.response.answer && Array.isArray(newVal.response.answer.documentIds)) {
2909
+ this.sourceDocIds = newVal.response.answer.documentIds;
2910
+ var localCache = helper.getObjectFromLocalStorage(constants.AI_LOCAL_CACHE_KEY) && helper.getObjectFromLocalStorage(constants.AI_LOCAL_CACHE_KEY)[this.$props.componentId];
2911
+ if (localCache && localCache.meta && localCache.meta.hits) {
2912
+ this.initialHits = localCache.meta.hits;
2913
+ }
2914
+ }
2915
+ this.AISessionId = ((helper.getObjectFromLocalStorage(constants.AI_LOCAL_CACHE_KEY) || {})[this.$props.componentId] || {}).sessionId || (((helper.getObjectFromLocalStorage(constants.AI_LOCAL_CACHE_KEY) || {})[this.$props.componentId] || {}).response || {}).sessionId;
2772
2916
  var messagesHistory = newVal.messages,
2773
2917
  response = newVal.response;
2774
2918
  var finalMessages = [];
@@ -2779,7 +2923,7 @@ var AIAnswer = vue.defineComponent({
2779
2923
  }
2780
2924
 
2781
2925
  // pushing message history so far
2782
- if (messagesHistory && messagesHistory && Array.isArray(messagesHistory)) {
2926
+ if (messagesHistory && Array.isArray(messagesHistory)) {
2783
2927
  finalMessages.push.apply(finalMessages, messagesHistory.filter(function (msg) {
2784
2928
  return msg.role !== constants.AI_ROLES.SYSTEM;
2785
2929
  }));
@@ -2804,6 +2948,9 @@ var AIAnswer = vue.defineComponent({
2804
2948
  loading: this.$props.isAIResponseLoading || this.$props.isLoading,
2805
2949
  error: this.$props.AIResponseError
2806
2950
  });
2951
+ if (newVal && newVal.hits && newVal.hits.hits) {
2952
+ this.initialHits = newVal.hits.hits;
2953
+ }
2807
2954
  },
2808
2955
  isAIResponseLoading: function isAIResponseLoading(newVal) {
2809
2956
  this.$emit('on-data', {
@@ -2828,7 +2975,7 @@ var AIAnswer = vue.defineComponent({
2828
2975
  },
2829
2976
  AIResponseError: function AIResponseError(newVal) {
2830
2977
  this.error = newVal;
2831
- this.AISessionId = ((helper.getObjectFromLocalStorage(constants.AI_LOCAL_CACHE_KEY) || {})[this.$props.componentId] || {}).sessionId || null;
2978
+ this.AISessionId = ((helper.getObjectFromLocalStorage(constants.AI_LOCAL_CACHE_KEY) || {})[this.$props.componentId] || {}).sessionId || (((helper.getObjectFromLocalStorage(constants.AI_LOCAL_CACHE_KEY) || {})[this.$props.componentId] || {}).response || {}).sessionId;
2832
2979
  if (this.error && !this.AISessionId) {
2833
2980
  var errorMessage = this.errorMessageForMissingSessionId;
2834
2981
  this.error = {
@@ -2849,7 +2996,7 @@ var AIAnswer = vue.defineComponent({
2849
2996
  componentError: function componentError(newVal) {
2850
2997
  var _this = this;
2851
2998
  if (newVal && newVal._bodyBlob) {
2852
- this.AISessionId = ((helper.getObjectFromLocalStorage(constants.AI_LOCAL_CACHE_KEY) || {})[this.$props.componentId] || {}).sessionId || null;
2999
+ this.AISessionId = ((helper.getObjectFromLocalStorage(constants.AI_LOCAL_CACHE_KEY) || {})[this.$props.componentId] || {}).sessionId || (((helper.getObjectFromLocalStorage(constants.AI_LOCAL_CACHE_KEY) || {})[this.$props.componentId] || {}).response || {}).sessionId;
2853
3000
  if (!this.AISessionId) {
2854
3001
  this.generateNewSessionId();
2855
3002
  }
@@ -2872,23 +3019,154 @@ var AIAnswer = vue.defineComponent({
2872
3019
  console.error('Error reading component error text data:', error);
2873
3020
  });
2874
3021
  }
3022
+ },
3023
+ showComponent: function showComponent() {
3024
+ if (this.$props.triggerOn === constants.AI_TRIGGER_MODES.QUESTION && this.$props.dependentComponentValue.endsWith('?')) {
3025
+ this.isTriggered = true;
3026
+ }
3027
+ },
3028
+ dependentComponentValue: function dependentComponentValue(newVal) {
3029
+ if (this.$props.triggerOn === constants.AI_TRIGGER_MODES.QUESTION && newVal && newVal.endsWith('?')) {
3030
+ this.isTriggered = true;
3031
+ if (this.AISessionId) {
3032
+ this.handleSendMessage(null, false, '', true);
3033
+ }
3034
+ } else if (this.hasTriggered && this.$props.triggerOn !== constants.AI_TRIGGER_MODES.ALWAYS) {
3035
+ this.isTriggered = false;
3036
+ }
3037
+ },
3038
+ AISessionId: function AISessionId(newVal) {
3039
+ if (newVal) {
3040
+ if (this.$props.triggerOn === constants.AI_TRIGGER_MODES.QUESTION && this.dependentComponentValue && this.dependentComponentValue.endsWith('?') || this.$props.triggerOn === constants.AI_TRIGGER_MODES.ALWAYS) {
3041
+ this.handleSendMessage(null, false, '', true);
3042
+ }
3043
+ }
3044
+ },
3045
+ triggerOn: function triggerOn(newVal) {
3046
+ if (newVal === constants.AI_TRIGGER_MODES.ALWAYS) {
3047
+ this.isTriggered = true;
3048
+ }
2875
3049
  }
2876
3050
  },
2877
3051
  methods: {
2878
- generateNewSessionId: function generateNewSessionId() {
3052
+ renderTriggerMessageFunc: function renderTriggerMessageFunc() {
3053
+ var triggerOn = this.$props.triggerOn;
3054
+ if (this.$props.renderTriggerMessage) {
3055
+ return this.$props.renderTriggerMessage;
3056
+ }
3057
+ if (this.$slots.renderTriggerMessage) {
3058
+ return this.$slots.renderTriggerMessage();
3059
+ }
3060
+ if (triggerOn === constants.AI_TRIGGER_MODES.QUESTION) {
3061
+ if (!this.dependentComponentValue.endsWith('?')) {
3062
+ return vue.createVNode("span", null, [vue.createVNode("span", {
3063
+ "role": "img",
3064
+ "aria-label": "bulb"
3065
+ }, [vue.createTextVNode("\uD83D\uDCA1")]), vue.createTextVNode("End your question with a question mark (?)")]);
3066
+ }
3067
+ } else if (triggerOn === constants.AI_TRIGGER_MODES.MANUAL) {
3068
+ return vue.createVNode("span", null, [vue.createTextVNode("Click here to ask AI"), ' ', vue.createVNode("span", {
3069
+ "role": "img",
3070
+ "aria-label": "bulb"
3071
+ }, [vue.createTextVNode("\uD83E\uDD16")])]);
3072
+ }
3073
+ return null;
3074
+ },
3075
+ handleTriggerClick: function handleTriggerClick() {
3076
+ if (this.$props.triggerOn === constants.AI_TRIGGER_MODES.MANUAL) {
3077
+ this.handleSendMessage(null, false, '', true);
3078
+ this.isTriggered = true;
3079
+ }
3080
+ },
3081
+ getAISourceObjects: function getAISourceObjects() {
2879
3082
  var _this2 = this;
3083
+ var sourceObjects = [];
3084
+ if (!this.AIResponse) return sourceObjects;
3085
+ var docIds = this.sourceDocIds || [];
3086
+ if (this.initialHits) {
3087
+ docIds.forEach(function (id) {
3088
+ var foundSourceObj = _this2.initialHits.find(function (hit) {
3089
+ return hit._id === id;
3090
+ }) || {};
3091
+ if (foundSourceObj) {
3092
+ var _foundSourceObj$_sour = foundSourceObj._source,
3093
+ _source = _foundSourceObj$_sour === void 0 ? {} : _foundSourceObj$_sour,
3094
+ rest = _rollupPluginBabelHelpers._objectWithoutPropertiesLoose(foundSourceObj, _excluded$1);
3095
+ sourceObjects.push(_rollupPluginBabelHelpers._extends({}, rest, _source));
3096
+ }
3097
+ });
3098
+ } else {
3099
+ sourceObjects.push.apply(sourceObjects, docIds.map(function (id) {
3100
+ return {
3101
+ _id: id
3102
+ };
3103
+ }));
3104
+ }
3105
+ return sourceObjects;
3106
+ },
3107
+ renderAIScreenFooter: function renderAIScreenFooter() {
3108
+ var _slot2;
3109
+ var _this3 = this;
3110
+ var _ref = this.$props || {},
3111
+ _ref$showSourceDocume = _ref.showSourceDocuments,
3112
+ showSourceDocuments = _ref$showSourceDocume === void 0 ? true : _ref$showSourceDocume,
3113
+ _ref$onSourceClick = _ref.onSourceClick,
3114
+ onSourceClick = _ref$onSourceClick === void 0 ? function () {} : _ref$onSourceClick,
3115
+ renderSourceDocument = _ref.renderSourceDocument;
3116
+ var customRenderSourceDoc = renderSourceDocument || this.$slots.renderSourceDocument;
3117
+ if (this.isLoadingState || this.isAITyping) {
3118
+ return null;
3119
+ }
3120
+ var renderSourceDocumentLabel = function renderSourceDocumentLabel(sourceObj) {
3121
+ if (customRenderSourceDoc) {
3122
+ return customRenderSourceDoc(sourceObj);
3123
+ }
3124
+ return sourceObj._id;
3125
+ };
3126
+ return showSourceDocuments && Array.isArray(this.sourceDocIds) && this.sourceDocIds.length ? vue.createVNode(Footer, {
3127
+ "themePreset": this.$props.themePreset,
3128
+ "style": {
3129
+ marginTop: '1.5rem',
3130
+ background: 'inherit'
3131
+ }
3132
+ }, {
3133
+ "default": function _default() {
3134
+ return [vue.createTextVNode("Summary generated using the following sources:"), ' ', vue.createVNode(SourceTags, null, _isSlot$1(_slot2 = _this3.getAISourceObjects().map(function (el) {
3135
+ var _slot;
3136
+ return vue.createVNode(Button.Button, {
3137
+ "class": "--ai-source-tag " + (helper.getClassName(_this3.$props.innerClass, 'ai-source-tag') || ''),
3138
+ "info": true,
3139
+ "onClick": function onClick() {
3140
+ return onSourceClick && onSourceClick(el);
3141
+ },
3142
+ "key": el._id
3143
+ }, _isSlot$1(_slot = renderSourceDocumentLabel(el)) ? _slot : {
3144
+ "default": function _default() {
3145
+ return [_slot];
3146
+ }
3147
+ });
3148
+ })) ? _slot2 : {
3149
+ "default": function _default() {
3150
+ return [_slot2];
3151
+ }
3152
+ })];
3153
+ }
3154
+ }) : null;
3155
+ },
3156
+ generateNewSessionId: function generateNewSessionId() {
3157
+ var _this4 = this;
2880
3158
  var newSessionPromise = this.createAISession();
2881
3159
  newSessionPromise.then(function (res) {
2882
- _this2.AISessionId = res.AIsessionId;
3160
+ _this4.AISessionId = res.AIsessionId;
2883
3161
  })["catch"](function (e) {
2884
3162
  console.error(e);
2885
3163
  });
2886
3164
  },
2887
3165
  scrollToBottom: function scrollToBottom() {
2888
- var _this3 = this;
3166
+ var _this5 = this;
2889
3167
  this.$nextTick(function () {
2890
- var _this3$$refs;
2891
- var messageContainer = (_this3$$refs = _this3.$refs) == null ? void 0 : _this3$$refs[_this3.$props.innerRef];
3168
+ var _this5$$refs;
3169
+ var messageContainer = (_this5$$refs = _this5.$refs) == null ? void 0 : _this5$$refs[_this5.$props.innerRef];
2892
3170
  if (messageContainer && messageContainer.$el) {
2893
3171
  messageContainer.$el.scrollTo({
2894
3172
  top: messageContainer.$el.scrollHeight,
@@ -2901,24 +3179,33 @@ var AIAnswer = vue.defineComponent({
2901
3179
  this.inputMessage = e.target.value;
2902
3180
  this.handleTextAreaHeightChange();
2903
3181
  },
2904
- handleSendMessage: function handleSendMessage(e, isRetry, text) {
3182
+ handleSendMessage: function handleSendMessage(e, isRetry, text, fetchMeta) {
2905
3183
  if (isRetry === void 0) {
2906
3184
  isRetry = false;
2907
3185
  }
2908
3186
  if (text === void 0) {
2909
3187
  text = this.inputMessage;
2910
3188
  }
3189
+ if (fetchMeta === void 0) {
3190
+ fetchMeta = false;
3191
+ }
2911
3192
  if (typeof e === 'object' && e !== null) e.preventDefault();
2912
- if (text.trim()) {
3193
+ if (text.trim() || !text && !e) {
2913
3194
  if (this.isLoadingState) {
2914
3195
  return;
2915
3196
  }
2916
3197
  if (this.AISessionId) {
2917
- if (!isRetry) this.messages = [].concat(this.messages, [{
2918
- content: text,
2919
- role: constants.AI_ROLES.USER
2920
- }]);
2921
- this.getAIResponse(this.AISessionId, this.componentId, text);
3198
+ if (!isRetry) {
3199
+ var finalMessages = [].concat(this.messages);
3200
+ if (text) {
3201
+ finalMessages.push({
3202
+ content: text,
3203
+ role: constants.AI_ROLES.USER
3204
+ });
3205
+ }
3206
+ this.messages = [].concat(finalMessages);
3207
+ }
3208
+ this.getAIResponse(this.AISessionId, this.componentId, text, fetchMeta);
2922
3209
  } else {
2923
3210
  console.error(this.errorMessageForMissingSessionId);
2924
3211
  this.error = {
@@ -2967,7 +3254,6 @@ var AIAnswer = vue.defineComponent({
2967
3254
  return null;
2968
3255
  },
2969
3256
  handleKeyPress: function handleKeyPress(e) {
2970
- window.console.log('e', e);
2971
3257
  if (e.key === 'Enter') {
2972
3258
  this.handleSendMessage(e);
2973
3259
  this.inputMessage = '';
@@ -2999,15 +3285,15 @@ var AIAnswer = vue.defineComponent({
2999
3285
  if (typeof window === 'undefined') return false;
3000
3286
  return showVoiceSearch && (window.webkitSpeechRecognition || window.SpeechRecognition);
3001
3287
  },
3002
- handleVoiceResults: function handleVoiceResults(_ref) {
3003
- var results = _ref.results;
3288
+ handleVoiceResults: function handleVoiceResults(_ref2) {
3289
+ var results = _ref2.results;
3004
3290
  if (results && results[0] && results[0].isFinal && results[0][0] && results[0][0].transcript && results[0][0].transcript.trim()) {
3005
3291
  this.handleSendMessage(null, false, results[0][0].transcript.trim());
3006
3292
  }
3007
3293
  },
3008
3294
  renderIcons: function renderIcons() {
3009
- var _this4 = this;
3010
- var _slot, _slot2;
3295
+ var _this6 = this;
3296
+ var _slot3, _slot4;
3011
3297
  var _this$$props = this.$props,
3012
3298
  getMicInstance = _this$$props.getMicInstance,
3013
3299
  showVoiceInput = _this$$props.showVoiceInput,
@@ -3020,14 +3306,14 @@ var AIAnswer = vue.defineComponent({
3020
3306
  "positionType": "absolute"
3021
3307
  }, {
3022
3308
  "default": function _default() {
3023
- return [!_this4.isLoadingState && _this4.AISessionId && _this4.shouldMicRender(showVoiceInput) && vue.createVNode(Mic, {
3309
+ return [!_this6.isLoadingState && _this6.AISessionId && _this6.shouldMicRender(showVoiceInput) && vue.createVNode(Mic, {
3024
3310
  "getInstance": getMicInstance,
3025
3311
  "render": renderMic,
3026
- "handleResult": _this4.handleVoiceResults,
3312
+ "handleResult": _this6.handleVoiceResults,
3027
3313
  "class": helper.getClassName(innerClass, 'ai-search-mic') || null
3028
- }, null), iconPosition === 'right' && vue.createVNode(DropDown.IconWrapper, null, _isSlot$1(_slot = _this4.renderIcon()) ? _slot : {
3314
+ }, null), iconPosition === 'right' && vue.createVNode(DropDown.IconWrapper, null, _isSlot$1(_slot3 = _this6.renderIcon()) ? _slot3 : {
3029
3315
  "default": function _default() {
3030
- return [_slot];
3316
+ return [_slot3];
3031
3317
  }
3032
3318
  })];
3033
3319
  }
@@ -3037,9 +3323,9 @@ var AIAnswer = vue.defineComponent({
3037
3323
  "positionType": "absolute"
3038
3324
  }, {
3039
3325
  "default": function _default() {
3040
- return [iconPosition === 'left' && vue.createVNode(DropDown.IconWrapper, null, _isSlot$1(_slot2 = _this4.renderIcon()) ? _slot2 : {
3326
+ return [iconPosition === 'left' && vue.createVNode(DropDown.IconWrapper, null, _isSlot$1(_slot4 = _this6.renderIcon()) ? _slot4 : {
3041
3327
  "default": function _default() {
3042
- return [_slot2];
3328
+ return [_slot4];
3043
3329
  }
3044
3330
  })];
3045
3331
  }
@@ -3049,7 +3335,7 @@ var AIAnswer = vue.defineComponent({
3049
3335
  this.handleSendMessage(e);
3050
3336
  },
3051
3337
  renderEnterButtonElement: function renderEnterButtonElement() {
3052
- var _this5 = this;
3338
+ var _this7 = this;
3053
3339
  var _this$$props2 = this.$props,
3054
3340
  enterButton = _this$$props2.enterButton,
3055
3341
  innerClass = _this$$props2.innerClass;
@@ -3057,16 +3343,16 @@ var AIAnswer = vue.defineComponent({
3057
3343
  if (enterButton) {
3058
3344
  var getEnterButtonMarkup = function getEnterButtonMarkup() {
3059
3345
  if (renderEnterButton) {
3060
- return renderEnterButton(_this5.enterButtonOnClick);
3346
+ return renderEnterButton(_this7.enterButtonOnClick);
3061
3347
  }
3062
3348
  return vue.createVNode(SendButton, {
3063
3349
  "primary": true,
3064
3350
  "type": "submit",
3065
3351
  "tabIndex": 0,
3066
- "onClick": _this5.handleSendMessage,
3067
- "onKeyPress": _this5.handleKeyPress,
3352
+ "onClick": _this7.handleSendMessage,
3353
+ "onKeyPress": _this7.handleKeyPress,
3068
3354
  "class": "ask-btn " + helper.getClassName(innerClass, 'ai-enter-button'),
3069
- "disabled": _this5.isLoadingState || !_this5.AISessionId
3355
+ "disabled": _this7.isLoadingState || !_this7.AISessionId
3070
3356
  }, {
3071
3357
  "default": function _default() {
3072
3358
  return [vue.createTextVNode("Send")];
@@ -3109,6 +3395,20 @@ var AIAnswer = vue.defineComponent({
3109
3395
  }
3110
3396
  this.$forceUpdate();
3111
3397
  }
3398
+ },
3399
+ getTitle: function getTitle() {
3400
+ var _this8 = this;
3401
+ var hasTitle = this.$props.title || this.$slots.title || null;
3402
+ if (hasTitle) {
3403
+ return vue.createVNode(Title.Title, {
3404
+ "class": helper.getClassName(this.$props.innerClass, 'ai-title') || null
3405
+ }, {
3406
+ "default": function _default() {
3407
+ return [_this8.$props.title || _this8.$slots.title()];
3408
+ }
3409
+ });
3410
+ }
3411
+ return null;
3112
3412
  }
3113
3413
  },
3114
3414
  beforeUnmount: function beforeUnmount() {
@@ -3123,55 +3423,62 @@ var AIAnswer = vue.defineComponent({
3123
3423
  }
3124
3424
  },
3125
3425
  render: function render() {
3126
- var _slot3;
3127
- var _this6 = this;
3426
+ var _slot5;
3427
+ var _this9 = this;
3128
3428
  var props = this.$props;
3129
3429
  if (!this.shouldShowComponent) {
3130
3430
  return null;
3131
3431
  }
3432
+ if (!this.isTriggered) {
3433
+ return vue.createVNode(Chatbox, {
3434
+ "style": props.style || {}
3435
+ }, {
3436
+ "default": function _default() {
3437
+ return [_this9.getTitle(), vue.createVNode("div", {
3438
+ "class": "--trigger-message-wrapper",
3439
+ "onClick": _this9.handleTriggerClick,
3440
+ "aria-hidden": "true"
3441
+ }, [_this9.renderTriggerMessageFunc()])];
3442
+ }
3443
+ });
3444
+ }
3132
3445
  return vue.createVNode(Chatbox, {
3133
3446
  "style": props.style || {}
3134
3447
  }, {
3135
3448
  "default": function _default() {
3136
- return [_this6.$props.title && vue.createVNode(Title.Title, {
3137
- "class": helper.getClassName(_this6.$props.innerClass, 'title') || ''
3138
- }, {
3139
- "default": function _default() {
3140
- return [_this6.$props.title];
3141
- }
3142
- }), vue.createVNode(ChatContainer, {
3449
+ return [_this9.getTitle(), vue.createVNode(ChatContainer, {
3143
3450
  "class": "--ai-chat-container",
3144
3451
  "theme": props.theme,
3145
3452
  "showInput": props.showInput
3146
3453
  }, {
3147
3454
  "default": function _default() {
3148
- return [_this6.hasCustomRenderer && vue.createVNode(MessagesContainer, {
3149
- "themePreset": _this6.themePreset,
3455
+ return [_this9.hasCustomRenderer && vue.createVNode(MessagesContainer, {
3456
+ "themePreset": _this9.themePreset,
3150
3457
  "theme": props.theme,
3151
- "ref": _this6.$props.innerRef,
3458
+ "ref": _this9.$props.innerRef,
3152
3459
  "class": "--ai-message-container " + (helper.getClassName(props.innerClass, 'ai-message-container') || '')
3153
- }, _isSlot$1(_slot3 = _this6.getComponent()) ? _slot3 : {
3460
+ }, _isSlot$1(_slot5 = _this9.getComponent()) ? _slot5 : {
3154
3461
  "default": function _default() {
3155
- return [_slot3];
3462
+ return [_slot5];
3156
3463
  }
3157
- }), !_this6.hasCustomRenderer && vue.createVNode(MessagesContainer, {
3158
- "themePreset": _this6.themePreset,
3464
+ }), !_this9.hasCustomRenderer && vue.createVNode(MessagesContainer, {
3465
+ "themePreset": _this9.themePreset,
3159
3466
  "theme": props.theme,
3160
- "ref": _this6.$props.innerRef,
3467
+ "ref": _this9.$props.innerRef,
3161
3468
  "class": "--ai-message-container " + (helper.getClassName(props.innerClass, 'ai-message-container') || '')
3162
3469
  }, {
3163
3470
  "default": function _default() {
3164
- return [_this6.messages.map(function (message, index) {
3471
+ return [_this9.messages.map(function (message, index) {
3165
3472
  return vue.createVNode(Message, {
3166
3473
  "key": index,
3167
3474
  "isSender": message.role === constants.AI_ROLES.USER,
3168
3475
  "innerHTML": md$1.render(message.content),
3169
- "themePreset": _this6.themePreset,
3476
+ "themePreset": _this9.themePreset,
3170
3477
  "theme": props.theme,
3171
3478
  "class": "--ai-answer-message " + (helper.getClassName(props.innerClass, 'ai-message') || '')
3172
3479
  }, null);
3173
- }), _this6.isLoadingState && vue.createVNode(Message, {
3174
- "themePreset": _this6.themePreset,
3480
+ }), _this9.isLoadingState && vue.createVNode(Message, {
3481
+ "themePreset": _this9.themePreset,
3175
3482
  "theme": props.theme,
3176
3483
  "isSender": false,
3177
3484
  "class": "--ai-answer-message " + (helper.getClassName(props.innerClass, 'ai-message') || null)
@@ -3180,31 +3487,31 @@ var AIAnswer = vue.defineComponent({
3180
3487
  return [vue.createVNode(TypingIndicator, null, {
3181
3488
  "default": function _default() {
3182
3489
  return [vue.createVNode(TypingDot, {
3183
- "themePreset": _this6.themePreset
3490
+ "themePreset": _this9.themePreset
3184
3491
  }, null), vue.createVNode(TypingDot, {
3185
- "themePreset": _this6.themePreset
3492
+ "themePreset": _this9.themePreset
3186
3493
  }, null), vue.createVNode(TypingDot, {
3187
- "themePreset": _this6.themePreset
3494
+ "themePreset": _this9.themePreset
3188
3495
  }, null)];
3189
3496
  }
3190
3497
  })];
3191
3498
  }
3192
3499
  })];
3193
3500
  }
3194
- }), _this6.renderErrorComponent(), ' ', props.showFeedback && vue.createVNode("div", {
3501
+ }), _this9.renderErrorComponent(), ' ', props.showFeedback && !_this9.isLoadingState && !_this9.isAITyping && vue.createVNode("div", {
3195
3502
  "class": "--ai-answer-feedback-container " + (helper.getClassName(props.innerClass, 'ai-feedback') || '')
3196
3503
  }, [vue.createVNode(AIFeedback, {
3197
- "hideUI": _this6.isLoadingState || !_this6.sessionId,
3198
- "key": _this6.sessionId,
3504
+ "hideUI": _this9.isLoadingState || !_this9.sessionId,
3505
+ "key": _this9.sessionId,
3199
3506
  "onFeedbackSubmit": function onFeedbackSubmit(useful, reason) {
3200
- _this6.trackUsefullness(_this6.sessionId, {
3507
+ _this9.trackUsefullness(_this9.sessionId, {
3201
3508
  useful: useful,
3202
3509
  reason: reason
3203
3510
  });
3204
3511
  }
3205
- }, null)]), props.showInput && vue.createVNode(MessageInputContainer, {
3512
+ }, null)]), ' ', _this9.renderAIScreenFooter(), props.showInput && !_this9.isLoadingState && !_this9.isAITyping && vue.createVNode(MessageInputContainer, {
3206
3513
  "class": "--ai-input-container",
3207
- "onSubmit": _this6.handleSendMessage
3514
+ "onSubmit": _this9.handleSendMessage
3208
3515
  }, {
3209
3516
  "default": function _default() {
3210
3517
  return [vue.createVNode(InputGroup, {
@@ -3220,19 +3527,19 @@ var AIAnswer = vue.defineComponent({
3220
3527
  "ref": _inputRef,
3221
3528
  "placeholder": props.placeholder,
3222
3529
  "enterButton": props.enterButton,
3223
- "value": _this6.inputMessage,
3224
- "onInput": _this6.handleMessageInputChange,
3530
+ "value": _this9.inputMessage,
3531
+ "onInput": _this9.handleMessageInputChange,
3225
3532
  "id": props.componentId + "-ai-input",
3226
3533
  "showIcon": props.showIcon,
3227
3534
  "iconPosition": props.iconPosition,
3228
- "themePreset": _this6.themePreset,
3229
- "disabled": _this6.isLoadingState || !_this6.AISessionId,
3535
+ "themePreset": _this9.themePreset,
3536
+ "disabled": _this9.isLoadingState || !_this9.AISessionId,
3230
3537
  "class": helper.getClassName(props.innerClass, 'ai-input') || null
3231
- }, null), ' ', _this6.renderIcons()];
3538
+ }, null), ' ', _this9.renderIcons()];
3232
3539
  }
3233
3540
  })];
3234
3541
  }
3235
- }), _this6.renderEnterButtonElement()];
3542
+ }), _this9.renderEnterButtonElement()];
3236
3543
  }
3237
3544
  }), ' '];
3238
3545
  }
@@ -3250,9 +3557,11 @@ var mapStateToProps$1 = function mapStateToProps(state, props) {
3250
3557
  // eslint-disable-next-line prefer-destructuring
3251
3558
  dependencyComponent = dependencyComponent[0];
3252
3559
  }
3253
- var showComponent = state.selectedValues[dependencyComponent] && state.selectedValues[dependencyComponent].value;
3560
+ var showComponent = !!(state.selectedValues[dependencyComponent] && state.selectedValues[dependencyComponent].value);
3561
+ var dependentComponentValue = state.selectedValues[dependencyComponent] && state.selectedValues[dependencyComponent].value || '';
3254
3562
  return {
3255
3563
  showComponent: showComponent,
3564
+ dependentComponentValue: dependentComponentValue,
3256
3565
  AIResponse: state.AIResponses[props.componentId] && state.AIResponses[props.componentId].response,
3257
3566
  isAIResponseLoading: state.AIResponses[props.componentId] && state.AIResponses[props.componentId].isLoading,
3258
3567
  AIResponseError: state.AIResponses[props.componentId] && state.AIResponses[props.componentId].error,
@@ -3260,11 +3569,17 @@ var mapStateToProps$1 = function mapStateToProps(state, props) {
3260
3569
  themePreset: state.config.themePreset,
3261
3570
  isLoading: state.isLoading[props.componentId] || false,
3262
3571
  sessionIdFromStore: state.AIResponses[props.componentId] && state.AIResponses[props.componentId].response && state.AIResponses[props.componentId].response.sessionId || '',
3263
- componentError: state.error[props.componentId]
3572
+ componentError: state.error[props.componentId] || null,
3573
+ isAITyping: state.AIResponses[props.componentId] && state.AIResponses[props.componentId].response && state.AIResponses[props.componentId].response.isTyping || false
3264
3574
  };
3265
3575
  };
3266
3576
  var mapDispatchToProps$1 = {
3267
- getAIResponse: query.fetchAIResponse,
3577
+ getAIResponse: function getAIResponse(sessionId, componentId, message, shouldFetchMeta) {
3578
+ if (shouldFetchMeta === void 0) {
3579
+ shouldFetchMeta = false;
3580
+ }
3581
+ return query.fetchAIResponse(sessionId, componentId, message, null, shouldFetchMeta);
3582
+ },
3268
3583
  trackUsefullness: analytics.recordAISessionUsefulness,
3269
3584
  createAISession: query.createAISession
3270
3585
  };