instantsearch.js 4.82.0 → 4.84.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -180,6 +180,16 @@ var connectChat = exports.default = function connectChat(renderFn) {
180
180
  widgetType: this.$$type
181
181
  });
182
182
  }
183
+ var toolsWithAddToolResult = {};
184
+ Object.entries(tools).forEach(function (_ref4) {
185
+ var _ref5 = _slicedToArray(_ref4, 2),
186
+ key = _ref5[0],
187
+ tool = _ref5[1];
188
+ var toolWithAddToolResult = _objectSpread(_objectSpread({}, tool), {}, {
189
+ addToolResult: _chatInstance.addToolResult
190
+ });
191
+ toolsWithAddToolResult[key] = toolWithAddToolResult;
192
+ });
183
193
  return {
184
194
  indexUiState: instantSearchInstance.getUiState()[parent.getIndexId()],
185
195
  input: input,
@@ -192,7 +202,7 @@ var connectChat = exports.default = function connectChat(renderFn) {
192
202
  isClearing: isClearing,
193
203
  clearMessages: clearMessages,
194
204
  onClearTransitionEnd: onClearTransitionEnd,
195
- tools: tools,
205
+ tools: toolsWithAddToolResult,
196
206
  widgetParams: widgetParams,
197
207
  // Chat instance render state
198
208
  addToolResult: _chatInstance.addToolResult,
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '4.82.0';
7
+ var _default = exports.default = '4.84.0';
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
@@ -10,6 +9,7 @@ var _preact = require("preact");
10
9
  var _hooks = require("preact/hooks");
11
10
  var _Template = _interopRequireDefault(require("../../components/Template/Template"));
12
11
  var _index = require("../../connectors/index.umd");
12
+ var _components = require("../../helpers/components");
13
13
  var _suit = require("../../lib/suit");
14
14
  var _templating = require("../../lib/templating");
15
15
  var _utils = require("../../lib/utils");
@@ -23,6 +23,7 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
23
23
  function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
24
24
  function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
25
25
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
26
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
26
27
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
27
28
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
28
29
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
@@ -56,6 +57,10 @@ var AutocompleteSearchBox = (0, _instantsearchUiComponents.createAutocompleteSea
56
57
  createElement: _preact.h,
57
58
  Fragment: _preact.Fragment
58
59
  });
60
+ var AutocompleteRecentSearch = (0, _instantsearchUiComponents.createAutocompleteRecentSearchComponent)({
61
+ createElement: _preact.h,
62
+ Fragment: _preact.Fragment
63
+ });
59
64
  var usePropGetters = (0, _instantsearchUiComponents.createAutocompletePropGetters)({
60
65
  useEffect: _hooks.useEffect,
61
66
  useId: _hooks.useId,
@@ -63,12 +68,18 @@ var usePropGetters = (0, _instantsearchUiComponents.createAutocompletePropGetter
63
68
  useRef: _hooks.useRef,
64
69
  useState: _hooks.useState
65
70
  });
71
+ var useStorage = (0, _instantsearchUiComponents.createAutocompleteStorage)({
72
+ useEffect: _hooks.useEffect,
73
+ useState: _hooks.useState,
74
+ useMemo: _hooks.useMemo
75
+ });
66
76
  var createRenderer = function createRenderer(params) {
67
77
  var instanceId = params.instanceId,
68
78
  containerNode = params.containerNode,
69
79
  rendererParams = _objectWithoutProperties(params, _excluded);
70
80
  return function (connectorParams, isFirstRendering) {
71
81
  if (isFirstRendering) {
82
+ var _targetIndex$getHelpe, _targetIndex$getHelpe2;
72
83
  var isolatedIndex = connectorParams.instantSearchInstance.mainIndex;
73
84
  var targetIndex = connectorParams.instantSearchInstance.mainIndex;
74
85
  (0, _utils.walkIndex)(targetIndex, function (childIndex) {
@@ -80,15 +91,21 @@ var createRenderer = function createRenderer(params) {
80
91
  rendererParams.renderState = {
81
92
  indexTemplateProps: [],
82
93
  isolatedIndex: isolatedIndex,
83
- targetIndex: targetIndex
94
+ targetIndex: targetIndex,
95
+ templateProps: (0, _templating.prepareTemplateProps)({
96
+ defaultTemplates: {},
97
+ templatesConfig: connectorParams.instantSearchInstance.templatesConfig,
98
+ templates: rendererParams.templates
99
+ })
84
100
  };
101
+ connectorParams.refine((_targetIndex$getHelpe = (_targetIndex$getHelpe2 = targetIndex.getHelper()) === null || _targetIndex$getHelpe2 === void 0 ? void 0 : _targetIndex$getHelpe2.state.query) !== null && _targetIndex$getHelpe !== void 0 ? _targetIndex$getHelpe : '');
85
102
  return;
86
103
  }
87
104
  (0, _preact.render)((0, _preact.h)(AutocompleteWrapper, _extends({}, rendererParams, connectorParams)), containerNode);
88
105
  };
89
106
  };
90
107
  function AutocompleteWrapper(_ref) {
91
- var _targetIndex$getWidge, _isolatedIndex$getHel;
108
+ var _isolatedIndex$getHel, _targetIndex$getWidge, _showRecent$templates;
92
109
  var indicesConfig = _ref.indicesConfig,
93
110
  indices = _ref.indices,
94
111
  getSearchPageURL = _ref.getSearchPageURL,
@@ -96,9 +113,23 @@ function AutocompleteWrapper(_ref) {
96
113
  refine = _ref.refine,
97
114
  cssClasses = _ref.cssClasses,
98
115
  renderState = _ref.renderState,
99
- instantSearchInstance = _ref.instantSearchInstance;
116
+ instantSearchInstance = _ref.instantSearchInstance,
117
+ showRecent = _ref.showRecent,
118
+ showSuggestions = _ref.showSuggestions,
119
+ templates = _ref.templates;
100
120
  var isolatedIndex = renderState.isolatedIndex,
101
121
  targetIndex = renderState.targetIndex;
122
+ var searchboxQuery = isolatedIndex === null || isolatedIndex === void 0 ? void 0 : (_isolatedIndex$getHel = isolatedIndex.getHelper()) === null || _isolatedIndex$getHel === void 0 ? void 0 : _isolatedIndex$getHel.state.query;
123
+ var _useStorage = useStorage({
124
+ query: searchboxQuery,
125
+ showRecent: showRecent,
126
+ indices: indices,
127
+ indicesConfig: indicesConfig
128
+ }),
129
+ storage = _useStorage.storage,
130
+ storageHits = _useStorage.storageHits,
131
+ indicesConfigForPropGetters = _useStorage.indicesConfigForPropGetters,
132
+ indicesForPropGetters = _useStorage.indicesForPropGetters;
102
133
  var isSearchPage = (_targetIndex$getWidge = targetIndex === null || targetIndex === void 0 ? void 0 : targetIndex.getWidgets().some(function (_ref2) {
103
134
  var $$type = _ref2.$$type;
104
135
  return ['ais.hits', 'ais.infiniteHits'].includes($$type);
@@ -112,10 +143,11 @@ function AutocompleteWrapper(_ref) {
112
143
  query: query
113
144
  }), _objectSpread2));
114
145
  });
146
+ query.length > 0 && storage.onAdd(query);
115
147
  };
116
148
  var _usePropGetters = usePropGetters({
117
- indices: indices,
118
- indicesConfig: indicesConfig,
149
+ indices: indicesForPropGetters,
150
+ indicesConfig: indicesConfigForPropGetters,
119
151
  onRefine: onRefine,
120
152
  onSelect: userOnSelect !== null && userOnSelect !== void 0 ? userOnSelect : function (_ref3) {
121
153
  var query = _ref3.query,
@@ -139,25 +171,69 @@ function AutocompleteWrapper(_ref) {
139
171
  getItemProps = _usePropGetters.getItemProps,
140
172
  getPanelProps = _usePropGetters.getPanelProps,
141
173
  getRootProps = _usePropGetters.getRootProps;
142
- var query = isolatedIndex === null || isolatedIndex === void 0 ? void 0 : (_isolatedIndex$getHel = isolatedIndex.getHelper()) === null || _isolatedIndex$getHel === void 0 ? void 0 : _isolatedIndex$getHel.state.query;
143
- return (0, _preact.h)(Autocomplete, _extends({}, getRootProps(), {
144
- classNames: cssClasses
145
- }), (0, _preact.h)(AutocompleteSearchBox, {
146
- query: query || '',
147
- inputProps: _objectSpread(_objectSpread({}, getInputProps()), {}, {
148
- // @ts-ignore - This clashes with some ambient React JSX declarations.
149
- onInput: function onInput(evt) {
150
- return refine(evt.currentTarget.value);
151
- }
152
- }),
153
- onClear: function onClear() {
154
- return onRefine('');
155
- },
156
- isSearchStalled: instantSearchInstance.status === 'stalled'
157
- }), (0, _preact.h)(AutocompletePanel, getPanelProps(), indices.map(function (_ref4, i) {
174
+ var AutocompleteRecentSearchComponent = function AutocompleteRecentSearchComponent(_ref4) {
175
+ var item = _ref4.item,
176
+ onSelect = _ref4.onSelect,
177
+ onRemoveRecentSearch = _ref4.onRemoveRecentSearch;
178
+ return (0, _preact.h)(AutocompleteRecentSearch, {
179
+ item: item,
180
+ onSelect: onSelect,
181
+ onRemoveRecentSearch: onRemoveRecentSearch
182
+ }, (0, _preact.h)(ConditionalReverseHighlight, {
183
+ item: item
184
+ }));
185
+ };
186
+ if (_typeof(showRecent) === 'object' && (_showRecent$templates = showRecent.templates) !== null && _showRecent$templates !== void 0 && _showRecent$templates.item) {
187
+ var props = (0, _templating.prepareTemplateProps)({
188
+ defaultTemplates: {},
189
+ templatesConfig: instantSearchInstance.templatesConfig,
190
+ templates: showRecent.templates
191
+ });
192
+ AutocompleteRecentSearchComponent = function AutocompleteRecentSearchComponent(_ref5) {
193
+ var item = _ref5.item,
194
+ onSelect = _ref5.onSelect,
195
+ onRemoveRecentSearch = _ref5.onRemoveRecentSearch;
196
+ return (0, _preact.h)(_Template.default, _extends({}, props, {
197
+ templateKey: "item",
198
+ rootTagName: "fragment",
199
+ data: {
200
+ item: item,
201
+ onSelect: onSelect,
202
+ onRemoveRecentSearch: onRemoveRecentSearch
203
+ }
204
+ }));
205
+ };
206
+ }
207
+ var elements = {};
208
+ if (showRecent) {
209
+ elements.recent = (0, _preact.h)(AutocompleteIndex
210
+ // @ts-ignore - there seems to be problems with React.ComponentType and this, but it's actually correct
211
+ , {
212
+ ItemComponent: function ItemComponent(_ref6) {
213
+ var item = _ref6.item,
214
+ onSelect = _ref6.onSelect;
215
+ return (0, _preact.h)(AutocompleteRecentSearchComponent, {
216
+ item: item,
217
+ onSelect: onSelect,
218
+ onRemoveRecentSearch: function onRemoveRecentSearch() {
219
+ return storage.onRemove(item.query);
220
+ }
221
+ });
222
+ },
223
+ classNames: {
224
+ root: 'ais-AutocompleteRecentSearches',
225
+ list: 'ais-AutocompleteRecentSearchesList',
226
+ item: 'ais-AutocompleteRecentSearchesItem'
227
+ },
228
+ items: storageHits,
229
+ getItemProps: getItemProps
230
+ });
231
+ }
232
+ indices.forEach(function (_ref7, i) {
158
233
  var _indicesConfig$i$temp;
159
- var indexId = _ref4.indexId,
160
- hits = _ref4.hits;
234
+ var indexId = _ref7.indexId,
235
+ indexName = _ref7.indexName,
236
+ hits = _ref7.hits;
161
237
  if (!renderState.indexTemplateProps[i]) {
162
238
  renderState.indexTemplateProps[i] = (0, _templating.prepareTemplateProps)({
163
239
  defaultTemplates: {},
@@ -165,8 +241,8 @@ function AutocompleteWrapper(_ref) {
165
241
  templates: indicesConfig[i].templates
166
242
  });
167
243
  }
168
- var headerComponent = (_indicesConfig$i$temp = indicesConfig[i].templates) !== null && _indicesConfig$i$temp !== void 0 && _indicesConfig$i$temp.header ? function (_ref5) {
169
- var items = _ref5.items;
244
+ var headerComponent = (_indicesConfig$i$temp = indicesConfig[i].templates) !== null && _indicesConfig$i$temp !== void 0 && _indicesConfig$i$temp.header ? function (_ref8) {
245
+ var items = _ref8.items;
170
246
  return (0, _preact.h)(_Template.default, _extends({}, renderState.indexTemplateProps[i], {
171
247
  templateKey: "header",
172
248
  rootTagName: "fragment",
@@ -175,9 +251,9 @@ function AutocompleteWrapper(_ref) {
175
251
  }
176
252
  }));
177
253
  } : undefined;
178
- var itemComponent = function itemComponent(_ref6) {
179
- var item = _ref6.item,
180
- onSelect = _ref6.onSelect;
254
+ var itemComponent = function itemComponent(_ref9) {
255
+ var item = _ref9.item,
256
+ onSelect = _ref9.onSelect;
181
257
  return (0, _preact.h)(_Template.default, _extends({}, renderState.indexTemplateProps[i], {
182
258
  templateKey: "item",
183
259
  rootTagName: "fragment",
@@ -187,7 +263,8 @@ function AutocompleteWrapper(_ref) {
187
263
  }
188
264
  }));
189
265
  };
190
- return (0, _preact.h)(AutocompleteIndex, {
266
+ var elementId = indexName === (showSuggestions === null || showSuggestions === void 0 ? void 0 : showSuggestions.indexName) ? 'suggestions' : indexName;
267
+ elements[elementId] = (0, _preact.h)(AutocompleteIndex, {
191
268
  key: indexId,
192
269
  HeaderComponent: headerComponent,
193
270
  ItemComponent: itemComponent,
@@ -199,25 +276,54 @@ function AutocompleteWrapper(_ref) {
199
276
  getItemProps: getItemProps,
200
277
  classNames: indicesConfig[i].cssClasses
201
278
  });
279
+ });
280
+ return (0, _preact.h)(Autocomplete, _extends({}, getRootProps(), {
281
+ classNames: cssClasses
282
+ }), (0, _preact.h)(AutocompleteSearchBox, {
283
+ query: searchboxQuery || '',
284
+ inputProps: _objectSpread(_objectSpread({}, getInputProps()), {}, {
285
+ // @ts-ignore - This clashes with some ambient React JSX declarations.
286
+ onInput: function onInput(evt) {
287
+ return refine(evt.currentTarget.value);
288
+ }
289
+ }),
290
+ onClear: function onClear() {
291
+ return onRefine('');
292
+ },
293
+ isSearchStalled: instantSearchInstance.status === 'stalled'
294
+ }), (0, _preact.h)(AutocompletePanel, getPanelProps(), templates.panel ? (0, _preact.h)(_Template.default, _extends({}, renderState.templateProps, {
295
+ templateKey: "panel",
296
+ rootTagName: "fragment",
297
+ data: {
298
+ elements: elements,
299
+ indices: indices
300
+ }
301
+ })) : Object.keys(elements).map(function (elementId) {
302
+ return elements[elementId];
202
303
  })));
203
304
  }
204
305
  function EXPERIMENTAL_autocomplete(widgetParams) {
205
- var _ref7 = widgetParams || {},
206
- container = _ref7.container,
207
- escapeHTML = _ref7.escapeHTML,
208
- _ref7$indices = _ref7.indices,
209
- indices = _ref7$indices === void 0 ? [] : _ref7$indices,
210
- showSuggestions = _ref7.showSuggestions,
211
- getSearchPageURL = _ref7.getSearchPageURL,
212
- onSelect = _ref7.onSelect,
213
- _ref7$templates = _ref7.templates,
214
- templates = _ref7$templates === void 0 ? {} : _ref7$templates,
215
- _ref7$cssClasses = _ref7.cssClasses,
216
- userCssClasses = _ref7$cssClasses === void 0 ? {} : _ref7$cssClasses;
306
+ var _ref0 = widgetParams || {},
307
+ container = _ref0.container,
308
+ escapeHTML = _ref0.escapeHTML,
309
+ _ref0$indices = _ref0.indices,
310
+ indices = _ref0$indices === void 0 ? [] : _ref0$indices,
311
+ showSuggestions = _ref0.showSuggestions,
312
+ showRecent = _ref0.showRecent,
313
+ userSearchParameters = _ref0.searchParameters,
314
+ getSearchPageURL = _ref0.getSearchPageURL,
315
+ onSelect = _ref0.onSelect,
316
+ _ref0$templates = _ref0.templates,
317
+ templates = _ref0$templates === void 0 ? {} : _ref0$templates,
318
+ _ref0$cssClasses = _ref0.cssClasses,
319
+ userCssClasses = _ref0$cssClasses === void 0 ? {} : _ref0$cssClasses;
217
320
  if (!container) {
218
321
  throw new Error(withUsage('The `container` option is required.'));
219
322
  }
220
323
  var containerNode = (0, _utils.getContainerNode)(container);
324
+ var searchParameters = _objectSpread({
325
+ hitsPerPage: 5
326
+ }, userSearchParameters);
221
327
  var cssClasses = {
222
328
  root: (0, _instantsearchUiComponents.cx)(suit(), userCssClasses.root)
223
329
  };
@@ -228,7 +334,16 @@ function EXPERIMENTAL_autocomplete(widgetParams) {
228
334
  indexName: showSuggestions.indexName,
229
335
  templates: _objectSpread({
230
336
  // @ts-expect-error
231
- item: AutocompleteSuggestion
337
+ item: function item(_ref1) {
338
+ var _item = _ref1.item,
339
+ onSelectItem = _ref1.onSelect;
340
+ return (0, _preact.h)(AutocompleteSuggestion, {
341
+ item: _item,
342
+ onSelect: onSelectItem
343
+ }, (0, _preact.h)(ConditionalReverseHighlight, {
344
+ item: _item
345
+ }));
346
+ }
232
347
  }, showSuggestions.templates),
233
348
  cssClasses: {
234
349
  root: (0, _instantsearchUiComponents.cx)('ais-AutocompleteSuggestions', (_showSuggestions$cssC = showSuggestions.cssClasses) === null || _showSuggestions$cssC === void 0 ? void 0 : _showSuggestions$cssC.root),
@@ -250,10 +365,13 @@ function EXPERIMENTAL_autocomplete(widgetParams) {
250
365
  getSearchPageURL: getSearchPageURL,
251
366
  onSelect: onSelect,
252
367
  cssClasses: cssClasses,
368
+ showRecent: showRecent,
369
+ showSuggestions: showSuggestions,
253
370
  renderState: {
254
371
  indexTemplateProps: [],
255
372
  isolatedIndex: undefined,
256
- targetIndex: undefined
373
+ targetIndex: undefined,
374
+ templateProps: undefined
257
375
  },
258
376
  templates: templates
259
377
  });
@@ -265,17 +383,29 @@ function EXPERIMENTAL_autocomplete(widgetParams) {
265
383
  })({}), (0, _index2.default)({
266
384
  indexId: "ais-autocomplete-".concat(instanceId),
267
385
  EXPERIMENTAL_isolated: true
268
- }).addWidgets([(0, _configure.default)({
269
- hitsPerPage: 5
270
- })].concat(_toConsumableArray(indicesConfig.map(function (_ref8) {
271
- var indexName = _ref8.indexName;
386
+ }).addWidgets([(0, _configure.default)(searchParameters)].concat(_toConsumableArray(indicesConfig.map(function (_ref10) {
387
+ var indexName = _ref10.indexName,
388
+ indexSearchParameters = _ref10.searchParameters;
272
389
  return (0, _index2.default)({
273
390
  indexName: indexName,
274
391
  indexId: indexName
275
- }).addWidgets([(0, _configure.default)({})]);
392
+ }).addWidgets([(0, _configure.default)(indexSearchParameters || {})]);
276
393
  })), [_objectSpread(_objectSpread({}, makeWidget({
277
394
  escapeHTML: escapeHTML
278
395
  })), {}, {
279
396
  $$widgetType: 'ais.autocomplete'
280
397
  })]))];
398
+ }
399
+ function ConditionalReverseHighlight(_ref11) {
400
+ var _item$_highlightResul;
401
+ var item = _ref11.item;
402
+ if (!((_item$_highlightResul = item._highlightResult) !== null && _item$_highlightResul !== void 0 && _item$_highlightResul.query) ||
403
+ // @ts-expect-error - we should not have matchLevel as arrays here
404
+ item._highlightResult.query.matchLevel === 'none') {
405
+ return item.query;
406
+ }
407
+ return (0, _preact.h)(_components.ReverseHighlight, {
408
+ attribute: "query",
409
+ hit: item
410
+ });
281
411
  }
@@ -269,7 +269,10 @@ function ChatWrapper(_ref0) {
269
269
  loaderComponent: messagesProps.loaderComponent,
270
270
  errorComponent: messagesProps.errorComponent,
271
271
  actionsComponent: messagesProps.actionsComponent,
272
- translations: messagesProps.translations
272
+ assistantMessageProps: messagesProps.assistantMessageProps,
273
+ userMessageProps: messagesProps.userMessageProps,
274
+ translations: messagesProps.translations,
275
+ messageTranslations: messagesProps.messageTranslations
273
276
  },
274
277
  promptProps: {
275
278
  promptRef: promptProps.promptRef,
@@ -303,8 +306,10 @@ var createRenderer = function createRenderer(_ref1) {
303
306
  var promptRef = {
304
307
  current: null
305
308
  };
309
+
310
+ // eslint-disable-next-line complexity
306
311
  return function (props, isFirstRendering) {
307
- var _templates$header, _templates$header2, _templates$header3, _templates$header4, _templates$header5, _templates$header6, _templates$header7, _templates$header8, _templates$header9, _templates$header0, _templates$messages, _templates$messages2, _templates$messages3, _templates$messages4, _templates$messages5, _templates$messages6, _templates$prompt, _templates$prompt2, _templates$prompt3, _templates$prompt4, _templates$prompt5, _templates$prompt6, _templates$prompt7, _templates$prompt8, _templates$prompt9, _templates$toggleButt, _templates$toggleButt2;
312
+ var _templates$header, _templates$header2, _templates$header3, _templates$header4, _templates$header5, _templates$header6, _templates$header7, _templates$header8, _templates$header9, _templates$header0, _templates$messages, _templates$messages2, _templates$messages3, _templates$messages4, _templates$messages5, _templates$messages6, _templates$assistantM, _templates$assistantM2, _templates$message, _templates$message2, _templates$userMessag, _templates$userMessag2, _templates$prompt, _templates$prompt2, _templates$prompt3, _templates$prompt4, _templates$prompt5, _templates$prompt6, _templates$prompt7, _templates$prompt8, _templates$prompt9, _templates$toggleButt, _templates$toggleButt2;
308
313
  var indexUiState = props.indexUiState,
309
314
  input = props.input,
310
315
  instantSearchInstance = props.instantSearchInstance,
@@ -316,7 +321,6 @@ var createRenderer = function createRenderer(_ref1) {
316
321
  setOpen = props.setOpen,
317
322
  status = props.status,
318
323
  error = props.error,
319
- addToolResult = props.addToolResult,
320
324
  regenerate = props.regenerate,
321
325
  stop = props.stop,
322
326
  isClearing = props.isClearing,
@@ -336,12 +340,12 @@ var createRenderer = function createRenderer(_ref1) {
336
340
  }
337
341
  var toolsForUi = {};
338
342
  Object.entries(toolsFromConnector).forEach(function (_ref10) {
343
+ var _widgetTool$templates;
339
344
  var _ref11 = _slicedToArray(_ref10, 2),
340
345
  key = _ref11[0],
341
346
  connectorTool = _ref11[1];
342
347
  var widgetTool = tools[key];
343
- toolsForUi[key] = _objectSpread(_objectSpread({}, connectorTool), {}, {
344
- addToolResult: addToolResult,
348
+ toolsForUi[key] = _objectSpread(_objectSpread({}, connectorTool), (widgetTool === null || widgetTool === void 0 ? void 0 : (_widgetTool$templates = widgetTool.templates) === null || _widgetTool$templates === void 0 ? void 0 : _widgetTool$templates.layout) && {
345
349
  layoutComponent: function layoutComponent(layoutComponentProps) {
346
350
  return (0, _preact.h)(_Template.default, {
347
351
  templates: widgetTool.templates,
@@ -424,6 +428,44 @@ var createRenderer = function createRenderer(_ref1) {
424
428
  copyToClipboardLabel: (_templates$messages5 = templates.messages) === null || _templates$messages5 === void 0 ? void 0 : _templates$messages5.copyToClipboardLabelText,
425
429
  regenerateLabel: (_templates$messages6 = templates.messages) === null || _templates$messages6 === void 0 ? void 0 : _templates$messages6.regenerateLabelText
426
430
  });
431
+ var assistantMessageTemplateProps = (0, _templating.prepareTemplateProps)({
432
+ defaultTemplates: {},
433
+ templatesConfig: instantSearchInstance.templatesConfig,
434
+ templates: templates.assistantMessage
435
+ });
436
+ var assistantMessageLeadingComponent = (_templates$assistantM = templates.assistantMessage) !== null && _templates$assistantM !== void 0 && _templates$assistantM.leading ? function () {
437
+ return (0, _preact.h)(_Template.default, _extends({}, assistantMessageTemplateProps, {
438
+ templateKey: "leading",
439
+ rootTagName: "fragment"
440
+ }));
441
+ } : undefined;
442
+ var assistantMessageFooterComponent = (_templates$assistantM2 = templates.assistantMessage) !== null && _templates$assistantM2 !== void 0 && _templates$assistantM2.footer ? function () {
443
+ return (0, _preact.h)(_Template.default, _extends({}, assistantMessageTemplateProps, {
444
+ templateKey: "footer",
445
+ rootTagName: "fragment"
446
+ }));
447
+ } : undefined;
448
+ var messageTranslations = getDefinedProperties({
449
+ actionsLabel: (_templates$message = templates.message) === null || _templates$message === void 0 ? void 0 : _templates$message.actionsLabelText,
450
+ messageLabel: (_templates$message2 = templates.message) === null || _templates$message2 === void 0 ? void 0 : _templates$message2.messageLabelText
451
+ });
452
+ var userMessageTemplateProps = (0, _templating.prepareTemplateProps)({
453
+ defaultTemplates: {},
454
+ templatesConfig: instantSearchInstance.templatesConfig,
455
+ templates: templates.userMessage
456
+ });
457
+ var userMessageLeadingComponent = (_templates$userMessag = templates.userMessage) !== null && _templates$userMessag !== void 0 && _templates$userMessag.leading ? function () {
458
+ return (0, _preact.h)(_Template.default, _extends({}, userMessageTemplateProps, {
459
+ templateKey: "leading",
460
+ rootTagName: "fragment"
461
+ }));
462
+ } : undefined;
463
+ var userMessageFooterComponent = (_templates$userMessag2 = templates.userMessage) !== null && _templates$userMessag2 !== void 0 && _templates$userMessag2.footer ? function () {
464
+ return (0, _preact.h)(_Template.default, _extends({}, userMessageTemplateProps, {
465
+ templateKey: "footer",
466
+ rootTagName: "fragment"
467
+ }));
468
+ } : undefined;
427
469
  var promptTemplateProps = (0, _templating.prepareTemplateProps)({
428
470
  defaultTemplates: {},
429
471
  templatesConfig: instantSearchInstance.templatesConfig,
@@ -520,7 +562,16 @@ var createRenderer = function createRenderer(_ref1) {
520
562
  loaderComponent: messagesLoaderComponent,
521
563
  errorComponent: messagesErrorComponent,
522
564
  actionsComponent: actionsComponent,
523
- translations: messagesTranslations
565
+ assistantMessageProps: {
566
+ leadingComponent: assistantMessageLeadingComponent,
567
+ footerComponent: assistantMessageFooterComponent
568
+ },
569
+ userMessageProps: {
570
+ leadingComponent: userMessageLeadingComponent,
571
+ footerComponent: userMessageFooterComponent
572
+ },
573
+ translations: messagesTranslations,
574
+ messageTranslations: messageTranslations
524
575
  },
525
576
  promptProps: {
526
577
  layoutComponent: promptLayoutComponent,
@@ -204,6 +204,12 @@ var index = function index(widgetParams) {
204
204
  helper: helper
205
205
  })));
206
206
  },
207
+ scheduleLocalSearch: (0, _utils.defer)(function () {
208
+ if (isolated) {
209
+ var _helper2;
210
+ (_helper2 = helper) === null || _helper2 === void 0 ? void 0 : _helper2.search();
211
+ }
212
+ }),
207
213
  getWidgets: function getWidgets() {
208
214
  return localWidgets;
209
215
  },
@@ -269,8 +275,7 @@ var index = function index(widgetParams) {
269
275
  }
270
276
  });
271
277
  if (isolated) {
272
- var _helper2;
273
- (_helper2 = helper) === null || _helper2 === void 0 ? void 0 : _helper2.search();
278
+ this.scheduleLocalSearch();
274
279
  } else {
275
280
  localInstantSearchInstance.scheduleSearch();
276
281
  }
@@ -349,8 +354,7 @@ var index = function index(widgetParams) {
349
354
  helper.recommendState = cleanedRecommendState;
350
355
  if (localWidgets.length) {
351
356
  if (isolated) {
352
- var _helper3;
353
- (_helper3 = helper) === null || _helper3 === void 0 ? void 0 : _helper3.search();
357
+ this.scheduleLocalSearch();
354
358
  } else {
355
359
  localInstantSearchInstance.scheduleSearch();
356
360
  }
@@ -422,12 +426,6 @@ var index = function index(widgetParams) {
422
426
  helper.searchWithoutTriggeringOnStateChange = function () {
423
427
  return mainHelper.search();
424
428
  };
425
-
426
- // We use the same pattern for the `searchForFacetValues`.
427
- helper.searchForFacetValues = function (facetName, facetValue, maxFacetHits, userState) {
428
- var state = helper.state.setQueryParameters(userState);
429
- return mainHelper.searchForFacetValues(facetName, facetValue, maxFacetHits, state);
430
- };
431
429
  var isolatedHelper = indexName ? helper : (0, _algoliasearchHelper.default)({}, '__empty_index__', {});
432
430
  var derivingHelper = isolated ? isolatedHelper : nearestIsolatedHelper(parent, mainHelper);
433
431
  derivedHelper = derivingHelper.derive(function () {
@@ -610,7 +608,7 @@ var index = function index(widgetParams) {
610
608
  },
611
609
  dispose: function dispose() {
612
610
  var _this5 = this,
613
- _helper4,
611
+ _helper3,
614
612
  _derivedHelper3;
615
613
  localWidgets.forEach(function (widget) {
616
614
  if (widget.dispose && helper) {
@@ -630,7 +628,7 @@ var index = function index(widgetParams) {
630
628
  });
631
629
  localInstantSearchInstance = null;
632
630
  localParent = null;
633
- (_helper4 = helper) === null || _helper4 === void 0 ? void 0 : _helper4.removeAllListeners();
631
+ (_helper3 = helper) === null || _helper3 === void 0 ? void 0 : _helper3.removeAllListeners();
634
632
  helper = null;
635
633
  (_derivedHelper3 = derivedHelper) === null || _derivedHelper3 === void 0 ? void 0 : _derivedHelper3.detach();
636
634
  derivedHelper = null;