react-instantsearch-core 7.49.1 → 7.50.1

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.
@@ -1,4 +1,4 @@
1
- /*! React InstantSearch Core 7.49.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! React InstantSearch Core 7.50.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
4
4
  typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
@@ -24,7 +24,7 @@
24
24
 
25
25
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
26
26
 
27
- var version$2 = '7.49.1';
27
+ var version$2 = '7.50.1';
28
28
 
29
29
  function _define_property(obj, key, value) {
30
30
  if (key in obj) {
@@ -3919,7 +3919,7 @@
3919
3919
  function requireVersion() {
3920
3920
  if (hasRequiredVersion) return version$1;
3921
3921
  hasRequiredVersion = 1;
3922
- version$1 = '3.29.3';
3922
+ version$1 = '3.29.4';
3923
3923
  return version$1;
3924
3924
  }
3925
3925
 
@@ -5259,15 +5259,45 @@
5259
5259
  return derivedStateQueries;
5260
5260
  });
5261
5261
  var queries = Array.prototype.concat.apply(mainQueries, derivedQueries);
5262
+ var uniqueQueries = [];
5263
+ var deduplicationMap = [];
5264
+ var deduplicated = false;
5265
+ var queryKeys = {};
5266
+ queries.forEach(function(query) {
5267
+ var key = JSON.stringify({
5268
+ indexName: query.indexName,
5269
+ params: query.params
5270
+ });
5271
+ if (Object.prototype.hasOwnProperty.call(queryKeys, key)) {
5272
+ var index = queryKeys[key];
5273
+ deduplicationMap.push(index);
5274
+ deduplicated = true;
5275
+ } else {
5276
+ var newIndex = uniqueQueries.length;
5277
+ uniqueQueries.push(query);
5278
+ queryKeys[key] = newIndex;
5279
+ deduplicationMap.push(newIndex);
5280
+ }
5281
+ });
5262
5282
  var queryId = this._queryId++;
5263
5283
  this._currentNbQueries++;
5264
- if (!queries.length) {
5284
+ if (!uniqueQueries.length) {
5265
5285
  return Promise.resolve({
5266
5286
  results: []
5267
5287
  }).then(this._dispatchAlgoliaResponse.bind(this, states, queryId));
5268
5288
  }
5269
5289
  try {
5270
- this.client.search(queries).then(this._dispatchAlgoliaResponse.bind(this, states, queryId)).catch(this._dispatchAlgoliaError.bind(this, queryId));
5290
+ var searchPromise = this.client.search(uniqueQueries);
5291
+ if (deduplicated) {
5292
+ searchPromise = searchPromise.then(function(res) {
5293
+ return {
5294
+ results: deduplicationMap.map(function(index) {
5295
+ return res.results[index];
5296
+ })
5297
+ };
5298
+ });
5299
+ }
5300
+ searchPromise.then(this._dispatchAlgoliaResponse.bind(this, states, queryId)).catch(this._dispatchAlgoliaError.bind(this, queryId));
5271
5301
  } catch (error) {
5272
5302
  // If we reach this part, we're in an internal error state
5273
5303
  this.emit('error', {
@@ -5980,7 +6010,7 @@
5980
6010
  }
5981
6011
  }
5982
6012
 
5983
- var withUsage$x = createDocumentationMessageGenerator({
6013
+ var withUsage$y = createDocumentationMessageGenerator({
5984
6014
  name: 'configure',
5985
6015
  connector: true
5986
6016
  });
@@ -5996,7 +6026,7 @@
5996
6026
  var renderFn = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : noop, unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
5997
6027
  return function(widgetParams) {
5998
6028
  if (!widgetParams || !isPlainObject(widgetParams.searchParameters)) {
5999
- throw new Error(withUsage$x('The `searchParameters` option expects an object.'));
6029
+ throw new Error(withUsage$y('The `searchParameters` option expects an object.'));
6000
6030
  }
6001
6031
  var connectorState = {};
6002
6032
  function refine(helper) {
@@ -7833,13 +7863,13 @@
7833
7863
  return null;
7834
7864
  }
7835
7865
 
7836
- var withUsage$w = createDocumentationMessageGenerator({
7866
+ var withUsage$x = createDocumentationMessageGenerator({
7837
7867
  name: 'dynamic-widgets',
7838
7868
  connector: true
7839
7869
  });
7840
7870
  var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
7841
7871
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
7842
- checkRendering(renderFn, withUsage$w());
7872
+ checkRendering(renderFn, withUsage$x());
7843
7873
  return function(widgetParams) {
7844
7874
  var widgets = widgetParams.widgets, _widgetParams_maxValuesPerFacet = widgetParams.maxValuesPerFacet, maxValuesPerFacet = _widgetParams_maxValuesPerFacet === void 0 ? 20 : _widgetParams_maxValuesPerFacet, _widgetParams_facets = widgetParams.facets, facets = _widgetParams_facets === void 0 ? [
7845
7875
  '*'
@@ -7849,10 +7879,10 @@
7849
7879
  if (!(widgets && Array.isArray(widgets) && widgets.every(function(widget) {
7850
7880
  return (typeof widget === "undefined" ? "undefined" : _type_of(widget)) === 'object';
7851
7881
  }))) {
7852
- throw new Error(withUsage$w('The `widgets` option expects an array of widgets.'));
7882
+ throw new Error(withUsage$x('The `widgets` option expects an array of widgets.'));
7853
7883
  }
7854
7884
  if (!Array.isArray(facets)) {
7855
- throw new Error(withUsage$w("The `facets` option only accepts an array of facets, you passed ".concat(JSON.stringify(facets))));
7885
+ throw new Error(withUsage$x("The `facets` option only accepts an array of facets, you passed ".concat(JSON.stringify(facets))));
7856
7886
  }
7857
7887
  var localWidgets = new Map();
7858
7888
  return {
@@ -7954,7 +7984,7 @@
7954
7984
  results: results
7955
7985
  });
7956
7986
  if (!Array.isArray(attributesToRender)) {
7957
- throw new Error(withUsage$w('The `transformItems` option expects a function that returns an Array.'));
7987
+ throw new Error(withUsage$x('The `transformItems` option expects a function that returns an Array.'));
7958
7988
  }
7959
7989
  return {
7960
7990
  attributesToRender: attributesToRender,
@@ -8345,19 +8375,19 @@
8345
8375
  return toFeedSearchResults(lastResults._state, raw);
8346
8376
  });
8347
8377
  }
8348
- var withUsage$v = createDocumentationMessageGenerator({
8378
+ var withUsage$w = createDocumentationMessageGenerator({
8349
8379
  name: 'feeds',
8350
8380
  connector: true
8351
8381
  });
8352
8382
  var connectFeeds = function connectFeeds(renderFn) {
8353
8383
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
8354
- checkRendering(renderFn, withUsage$v());
8384
+ checkRendering(renderFn, withUsage$w());
8355
8385
  return function(widgetParams) {
8356
8386
  var isolated = widgetParams.isolated, _widgetParams_transformFeeds = widgetParams.transformFeeds, transformFeeds = _widgetParams_transformFeeds === void 0 ? function(feeds) {
8357
8387
  return feeds;
8358
8388
  } : _widgetParams_transformFeeds;
8359
8389
  if (isolated !== false) {
8360
- throw new Error(withUsage$v('The `isolated` option currently only supports `false`.'));
8390
+ throw new Error(withUsage$w('The `isolated` option currently only supports `false`.'));
8361
8391
  }
8362
8392
  return {
8363
8393
  $$type: 'ais.feeds',
@@ -8365,7 +8395,7 @@
8365
8395
  init: function init(initOptions) {
8366
8396
  var instantSearchInstance = initOptions.instantSearchInstance;
8367
8397
  if (!instantSearchInstance.compositionID) {
8368
- throw new Error(withUsage$v('The `feeds` widget requires a composition-based InstantSearch instance (compositionID must be set).'));
8398
+ throw new Error(withUsage$w('The `feeds` widget requires a composition-based InstantSearch instance (compositionID must be set).'));
8369
8399
  }
8370
8400
  hydrateFeedsFromInitialResultsIfNeeded(instantSearchInstance, initOptions.parent);
8371
8401
  renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
@@ -8411,12 +8441,12 @@
8411
8441
  ];
8412
8442
  feedIDs = transformFeeds(feedIDs);
8413
8443
  if (!Array.isArray(feedIDs)) {
8414
- throw new Error(withUsage$v('The `transformFeeds` option expects a function that returns an Array.'));
8444
+ throw new Error(withUsage$w('The `transformFeeds` option expects a function that returns an Array.'));
8415
8445
  }
8416
8446
  if (!feedIDs.every(function(feedID) {
8417
8447
  return typeof feedID === 'string';
8418
8448
  })) {
8419
- throw new Error(withUsage$v('The `transformFeeds` option expects a function that returns an array of feed IDs (strings).'));
8449
+ throw new Error(withUsage$w('The `transformFeeds` option expects a function that returns an array of feed IDs (strings).'));
8420
8450
  }
8421
8451
  return {
8422
8452
  feedIDs: feedIDs,
@@ -8527,7 +8557,7 @@
8527
8557
  }));
8528
8558
  }
8529
8559
 
8530
- var withUsage$u = createDocumentationMessageGenerator({
8560
+ var withUsage$v = createDocumentationMessageGenerator({
8531
8561
  name: 'index-widget'
8532
8562
  });
8533
8563
  /**
@@ -8655,7 +8685,7 @@
8655
8685
  var index = function index(widgetParams) {
8656
8686
  var _widgetParams_EXPERIMENTAL_isolated;
8657
8687
  if (widgetParams === undefined || widgetParams.indexName === undefined && !widgetParams.isolated && !widgetParams.EXPERIMENTAL_isolated) {
8658
- throw new Error(withUsage$u('The `indexName` option is required.'));
8688
+ throw new Error(withUsage$v('The `indexName` option is required.'));
8659
8689
  }
8660
8690
  // When isolated=true, we use an empty string as the default indexName.
8661
8691
  // This is intentional: isolated indices do not require a real index name.
@@ -8753,7 +8783,7 @@
8753
8783
  addWidgets: function addWidgets(widgets) {
8754
8784
  var _this = this;
8755
8785
  if (!Array.isArray(widgets)) {
8756
- throw new Error(withUsage$u('The `addWidgets` method expects an array of widgets.'));
8786
+ throw new Error(withUsage$v('The `addWidgets` method expects an array of widgets.'));
8757
8787
  }
8758
8788
  var flatWidgets = widgets.reduce(function(acc, w) {
8759
8789
  return acc.concat(Array.isArray(w) ? w : [
@@ -8763,7 +8793,7 @@
8763
8793
  if (flatWidgets.some(function(widget) {
8764
8794
  return typeof widget.init !== 'function' && typeof widget.render !== 'function';
8765
8795
  })) {
8766
- throw new Error(withUsage$u('The widget definition expects a `render` and/or an `init` method.'));
8796
+ throw new Error(withUsage$v('The widget definition expects a `render` and/or an `init` method.'));
8767
8797
  }
8768
8798
  flatWidgets.forEach(function(widget) {
8769
8799
  widget.parent = _this;
@@ -8813,10 +8843,10 @@
8813
8843
  },
8814
8844
  updateWidget: function updateWidget(previousWidget, nextWidget) {
8815
8845
  if (typeof previousWidget.dispose !== 'function') {
8816
- throw new Error(withUsage$u('The widget definition expects a `dispose` method.'));
8846
+ throw new Error(withUsage$v('The widget definition expects a `dispose` method.'));
8817
8847
  }
8818
8848
  if (typeof nextWidget.init !== 'function' && typeof nextWidget.render !== 'function') {
8819
- throw new Error(withUsage$u('The widget definition expects a `render` and/or an `init` method.'));
8849
+ throw new Error(withUsage$v('The widget definition expects a `render` and/or an `init` method.'));
8820
8850
  }
8821
8851
  // The `uiState` as it is before the previous widget is detached, so that
8822
8852
  // the state it owns can be handed over to the next widget.
@@ -8900,7 +8930,7 @@
8900
8930
  removeWidgets: function removeWidgets(widgets) {
8901
8931
  var _this = this;
8902
8932
  if (!Array.isArray(widgets)) {
8903
- throw new Error(withUsage$u('The `removeWidgets` method expects an array of widgets.'));
8933
+ throw new Error(withUsage$v('The `removeWidgets` method expects an array of widgets.'));
8904
8934
  }
8905
8935
  var flatWidgets = widgets.reduce(function(acc, w) {
8906
8936
  return acc.concat(Array.isArray(w) ? w : [
@@ -8910,7 +8940,7 @@
8910
8940
  if (flatWidgets.some(function(widget) {
8911
8941
  return typeof widget.dispose !== 'function';
8912
8942
  })) {
8913
- throw new Error(withUsage$u('The widget definition expects a `dispose` method.'));
8943
+ throw new Error(withUsage$v('The widget definition expects a `dispose` method.'));
8914
8944
  }
8915
8945
  localWidgets = localWidgets.filter(function(widget) {
8916
8946
  return flatWidgets.indexOf(widget) === -1;
@@ -9418,7 +9448,7 @@
9418
9448
  });
9419
9449
  }
9420
9450
 
9421
- var version = '4.117.0';
9451
+ var version = '4.118.1';
9422
9452
 
9423
9453
  var ANONYMOUS_TOKEN_COOKIE_KEY = '_ALGOLIA';
9424
9454
  function getCookie(name) {
@@ -11280,7 +11310,7 @@
11280
11310
  };
11281
11311
  }
11282
11312
 
11283
- var withUsage$t = createDocumentationMessageGenerator({
11313
+ var withUsage$u = createDocumentationMessageGenerator({
11284
11314
  name: 'instantsearch'
11285
11315
  });
11286
11316
  function defaultCreateURL() {
@@ -11351,7 +11381,7 @@
11351
11381
  _this.setMaxListeners(100);
11352
11382
  var _options_indexName = options.indexName, indexName = _options_indexName === void 0 ? '' : _options_indexName, compositionID = options.compositionID, numberLocale = options.numberLocale, _options_initialUiState = options.initialUiState, initialUiState = _options_initialUiState === void 0 ? {} : _options_initialUiState, _options_routing = options.routing, routing = _options_routing === void 0 ? null : _options_routing, _options_insights = options.insights, insights = _options_insights === void 0 ? undefined : _options_insights, searchFunction = options.searchFunction, _options_stalledSearchDelay = options.stalledSearchDelay, stalledSearchDelay = _options_stalledSearchDelay === void 0 ? 200 : _options_stalledSearchDelay, _options_searchClient = options.searchClient, searchClient = _options_searchClient === void 0 ? null : _options_searchClient, _options_insightsClient = options.insightsClient, insightsClient = _options_insightsClient === void 0 ? null : _options_insightsClient, _options_onStateChange = options.onStateChange, onStateChange = _options_onStateChange === void 0 ? null : _options_onStateChange, _options_future1 = options.future, future = _options_future1 === void 0 ? _object_spread({}, INSTANTSEARCH_FUTURE_DEFAULTS, options.future || {}) : _options_future1;
11353
11383
  if (searchClient === null) {
11354
- throw new Error(withUsage$t('The `searchClient` option is required.'));
11384
+ throw new Error(withUsage$u('The `searchClient` option is required.'));
11355
11385
  }
11356
11386
  if (typeof searchClient.search !== 'function') {
11357
11387
  throw new Error("The `searchClient` must implement a `search` method.\n\nSee: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend-search/in-depth/backend-instantsearch/js/");
@@ -11360,7 +11390,7 @@
11360
11390
  searchClient.addAlgoliaAgent("instantsearch.js (".concat(version, ")"));
11361
11391
  }
11362
11392
  if (insightsClient && typeof insightsClient !== 'function') {
11363
- throw new Error(withUsage$t('The `insightsClient` option should be a function.'));
11393
+ throw new Error(withUsage$u('The `insightsClient` option should be a function.'));
11364
11394
  }
11365
11395
  _this._initialOptions = options;
11366
11396
  _this.client = searchClient;
@@ -11509,12 +11539,12 @@
11509
11539
  * @param widgets The array of widgets to add to InstantSearch.
11510
11540
  */ function addWidgets(widgets) {
11511
11541
  if (!Array.isArray(widgets)) {
11512
- throw new Error(withUsage$t('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
11542
+ throw new Error(withUsage$u('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
11513
11543
  }
11514
11544
  if (this.compositionID && widgets.some(function(w) {
11515
11545
  return !Array.isArray(w) && isIndexWidget(w) && !w._isolated;
11516
11546
  })) {
11517
- throw new Error(withUsage$t('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
11547
+ throw new Error(withUsage$u('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
11518
11548
  }
11519
11549
  this.mainIndex.addWidgets(widgets);
11520
11550
  return this;
@@ -11543,7 +11573,7 @@
11543
11573
  * The widgets must implement a `dispose()` method to clear their states.
11544
11574
  */ function removeWidgets(widgets) {
11545
11575
  if (!Array.isArray(widgets)) {
11546
- throw new Error(withUsage$t('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
11576
+ throw new Error(withUsage$u('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
11547
11577
  }
11548
11578
  this.mainIndex.removeWidgets(widgets);
11549
11579
  return this;
@@ -11557,7 +11587,7 @@
11557
11587
  */ function start() {
11558
11588
  var _this = this;
11559
11589
  if (this.started) {
11560
- throw new Error(withUsage$t('The `start` method has already been called once.'));
11590
+ throw new Error(withUsage$u('The `start` method has already been called once.'));
11561
11591
  }
11562
11592
  // This Helper is used for the queries, we don't care about its state. The
11563
11593
  // states are managed at the `index` level. We use this Helper to create
@@ -11765,7 +11795,7 @@
11765
11795
  var _this = this;
11766
11796
  var callOnStateChange = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
11767
11797
  if (!this.mainHelper) {
11768
- throw new Error(withUsage$t('The `start` method needs to be called before `setUiState`.'));
11798
+ throw new Error(withUsage$u('The `start` method needs to be called before `setUiState`.'));
11769
11799
  }
11770
11800
  // We refresh the index UI state to update the local UI state that the
11771
11801
  // main index passes to the function form of `setUiState`.
@@ -11802,7 +11832,7 @@
11802
11832
  value: function createURL() {
11803
11833
  var nextState = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
11804
11834
  if (!this.started) {
11805
- throw new Error(withUsage$t('The `start` method needs to be called before `createURL`.'));
11835
+ throw new Error(withUsage$u('The `start` method needs to be called before `createURL`.'));
11806
11836
  }
11807
11837
  return this._createURL(nextState);
11808
11838
  }
@@ -11811,7 +11841,7 @@
11811
11841
  key: "refresh",
11812
11842
  value: function refresh() {
11813
11843
  if (!this.mainHelper) {
11814
- throw new Error(withUsage$t('The `start` method needs to be called before `refresh`.'));
11844
+ throw new Error(withUsage$u('The `start` method needs to be called before `refresh`.'));
11815
11845
  }
11816
11846
  this.mainHelper.clearCache().search();
11817
11847
  }
@@ -12343,13 +12373,13 @@
12343
12373
  }, children);
12344
12374
  }
12345
12375
 
12346
- var withUsage$s = createDocumentationMessageGenerator({
12376
+ var withUsage$t = createDocumentationMessageGenerator({
12347
12377
  name: 'autocomplete',
12348
12378
  connector: true
12349
12379
  });
12350
12380
  var connectAutocomplete = function connectAutocomplete(renderFn) {
12351
12381
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
12352
- checkRendering(renderFn, withUsage$s());
12382
+ checkRendering(renderFn, withUsage$t());
12353
12383
  return function(widgetParams) {
12354
12384
  var _ref = widgetParams || {}, _ref_escapeHTML = _ref.escapeHTML, escapeHTML = _ref_escapeHTML === void 0 ? true : _ref_escapeHTML, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(indices) {
12355
12385
  return indices;
@@ -12462,20 +12492,20 @@
12462
12492
  return useConnector(connectAutocomplete, props, additionalWidgetProperties);
12463
12493
  }
12464
12494
 
12465
- var withUsage$r = createDocumentationMessageGenerator({
12495
+ var withUsage$s = createDocumentationMessageGenerator({
12466
12496
  name: 'breadcrumb',
12467
12497
  connector: true
12468
12498
  });
12469
12499
  var connectBreadcrumb = function connectBreadcrumb(renderFn) {
12470
12500
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
12471
- checkRendering(renderFn, withUsage$r());
12501
+ checkRendering(renderFn, withUsage$s());
12472
12502
  var connectorState = {};
12473
12503
  return function(widgetParams) {
12474
12504
  var _ref = widgetParams || {}, attributes = _ref.attributes, _ref_separator = _ref.separator, separator = _ref_separator === void 0 ? ' > ' : _ref_separator, _ref_rootPath = _ref.rootPath, rootPath = _ref_rootPath === void 0 ? null : _ref_rootPath, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
12475
12505
  return items;
12476
12506
  } : _ref_transformItems;
12477
12507
  if (!attributes || !Array.isArray(attributes) || attributes.length === 0) {
12478
- throw new Error(withUsage$r('The `attributes` option expects an array of strings.'));
12508
+ throw new Error(withUsage$s('The `attributes` option expects an array of strings.'));
12479
12509
  }
12480
12510
  var _attributes = _sliced_to_array(attributes, 1), hierarchicalFacetName = _attributes[0];
12481
12511
  function getRefinedState(state, facetValue) {
@@ -14917,7 +14947,7 @@
14917
14947
  return DefaultChatTransport;
14918
14948
  }(HttpChatTransport);
14919
14949
 
14920
- var withUsage$q = createDocumentationMessageGenerator({
14950
+ var withUsage$r = createDocumentationMessageGenerator({
14921
14951
  name: 'chat',
14922
14952
  connector: true
14923
14953
  });
@@ -15048,7 +15078,7 @@
15048
15078
  }
15049
15079
  var connectChat = function connectChat(renderFn) {
15050
15080
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15051
- checkRendering(renderFn, withUsage$q());
15081
+ checkRendering(renderFn, withUsage$r());
15052
15082
  return function(widgetParams) {
15053
15083
  var _ref = widgetParams || {}, _ref_resume = _ref.resume, resume = _ref_resume === void 0 ? false : _ref_resume, tmp = _ref.tools, tools_ = tmp === void 0 ? {} : tmp, _ref_type = _ref.type, type = _ref_type === void 0 ? 'chat' : _ref_type, persistence = _ref.persistence, context = _ref.context, initialUserMessage = _ref.initialUserMessage, initialMessages = _ref.initialMessages, _ref_disableTriggerValidation = _ref.disableTriggerValidation, disableTriggerValidation = _ref_disableTriggerValidation === void 0 ? false : _ref_disableTriggerValidation, _ref_sendAutomaticallyWhen = _ref.sendAutomaticallyWhen, sendAutomaticallyWhen = _ref_sendAutomaticallyWhen === void 0 ? lastAssistantMessageIsCompleteWithToolCalls : _ref_sendAutomaticallyWhen, _ref_requiresSearch = _ref.requiresSearch, requiresSearch = _ref_requiresSearch === void 0 ? true : _ref_requiresSearch, options = _object_without_properties(_ref, [
15054
15084
  "resume",
@@ -15208,7 +15238,7 @@
15208
15238
  if ('agentId' in options && options.agentId) {
15209
15239
  var _options_requestOptions, _options_requestOptions1;
15210
15240
  if (!appId || !apiKey) {
15211
- throw new Error(withUsage$q('Could not extract Algolia credentials from the search client.'));
15241
+ throw new Error(withUsage$r('Could not extract Algolia credentials from the search client.'));
15212
15242
  }
15213
15243
  var createApi = function createApi() {
15214
15244
  var bypassCache = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
@@ -15247,7 +15277,7 @@
15247
15277
  });
15248
15278
  }
15249
15279
  if (!transport) {
15250
- throw new Error(withUsage$q('You need to provide either an `agentId` or a `transport`.'));
15280
+ throw new Error(withUsage$r('You need to provide either an `agentId` or a `transport`.'));
15251
15281
  }
15252
15282
  var canRepairRestoredPendingToolParts = !resume;
15253
15283
  var chat = new Chat(_object_spread_props(_object_spread({}, options), {
@@ -15437,7 +15467,7 @@
15437
15467
  if (agentId && feedback) {
15438
15468
  var _getAppIdAndApiKey = _sliced_to_array(getAppIdAndApiKey(initOptions.instantSearchInstance.client), 2), appId = _getAppIdAndApiKey[0], apiKey = _getAppIdAndApiKey[1];
15439
15469
  if (!appId || !apiKey) {
15440
- throw new Error(withUsage$q('Could not extract Algolia credentials from the search client.'));
15470
+ throw new Error(withUsage$r('Could not extract Algolia credentials from the search client.'));
15441
15471
  }
15442
15472
  feedbackAbortController = new AbortController();
15443
15473
  _sendChatMessageFeedback = function _sendChatMessageFeedback(messageId, vote) {
@@ -16073,20 +16103,20 @@
16073
16103
  };
16074
16104
  }
16075
16105
 
16076
- var withUsage$p = createDocumentationMessageGenerator({
16106
+ var withUsage$q = createDocumentationMessageGenerator({
16077
16107
  name: 'tasks',
16078
16108
  connector: true
16079
16109
  });
16080
16110
  var connectTasks = function connectTasks(renderFn) {
16081
16111
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16082
- checkRendering(renderFn, withUsage$p());
16112
+ checkRendering(renderFn, withUsage$q());
16083
16113
  return function(widgetParams) {
16084
16114
  var agentId = widgetParams.agentId, transport = widgetParams.transport, task = widgetParams.task, kind = widgetParams.kind, _widgetParams_stream = widgetParams.stream, stream = _widgetParams_stream === void 0 ? true : _widgetParams_stream;
16085
16115
  if (!agentId && !transport) {
16086
- throw new Error(withUsage$p('The `agentId` option is required unless a custom `transport` is provided.'));
16116
+ throw new Error(withUsage$q('The `agentId` option is required unless a custom `transport` is provided.'));
16087
16117
  }
16088
16118
  if (!task && !kind) {
16089
- throw new Error(withUsage$p('Either the `task` or `kind` option is required.'));
16119
+ throw new Error(withUsage$q('Either the `task` or `kind` option is required.'));
16090
16120
  }
16091
16121
  var runner;
16092
16122
  var output;
@@ -16160,7 +16190,7 @@
16160
16190
  if (agentId) {
16161
16191
  var _getAppIdAndApiKey = _sliced_to_array(getAppIdAndApiKey(instantSearchInstance.client), 2), appId = _getAppIdAndApiKey[0], apiKey = _getAppIdAndApiKey[1];
16162
16192
  if (!appId || !apiKey) {
16163
- throw new Error(withUsage$p('Could not extract Algolia credentials from the search client.'));
16193
+ throw new Error(withUsage$q('Could not extract Algolia credentials from the search client.'));
16164
16194
  }
16165
16195
  var taskTransport = createTaskTransport({
16166
16196
  transport: transport,
@@ -16207,7 +16237,7 @@
16207
16237
  };
16208
16238
  };
16209
16239
 
16210
- var withUsage$o = createDocumentationMessageGenerator({
16240
+ var withUsage$p = createDocumentationMessageGenerator({
16211
16241
  name: 'prompt-suggestions',
16212
16242
  connector: true
16213
16243
  });
@@ -16304,13 +16334,13 @@
16304
16334
  }
16305
16335
  var connectPromptSuggestions = function connectPromptSuggestions(renderFn) {
16306
16336
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16307
- checkRendering(renderFn, withUsage$o());
16337
+ checkRendering(renderFn, withUsage$p());
16308
16338
  return function(widgetParams) {
16309
16339
  var agentId = widgetParams.agentId, configurationId = widgetParams.configurationId, _widgetParams_transformHits = widgetParams.transformHits, transformHits = _widgetParams_transformHits === void 0 ? DEFAULT_TRANSFORM_HITS : _widgetParams_transformHits, context = widgetParams.context, _widgetParams_transformItems = widgetParams.transformItems, transformItems = _widgetParams_transformItems === void 0 ? function(items) {
16310
16340
  return items;
16311
16341
  } : _widgetParams_transformItems, transport = widgetParams.transport;
16312
16342
  if (!agentId && !transport) {
16313
- throw new Error(withUsage$o('The `agentId` option is required unless a custom `transport` is provided.'));
16343
+ throw new Error(withUsage$p('The `agentId` option is required unless a custom `transport` is provided.'));
16314
16344
  }
16315
16345
  var tasksState;
16316
16346
  var suggestions = [];
@@ -16590,7 +16620,7 @@
16590
16620
  stream: true
16591
16621
  };
16592
16622
  } else {
16593
- throw new Error(withUsage$o('The `agentId` option is required unless a custom `transport` is provided.'));
16623
+ throw new Error(withUsage$p('The `agentId` option is required unless a custom `transport` is provided.'));
16594
16624
  }
16595
16625
  var tasksWidget = connectTasks(handleInnerRender, noop)(tasksParams);
16596
16626
  return {
@@ -16674,14 +16704,14 @@
16674
16704
  return useConnector(connectPromptSuggestions, props, additionalWidgetProperties);
16675
16705
  }
16676
16706
 
16677
- var withUsage$n = createDocumentationMessageGenerator({
16707
+ var withUsage$o = createDocumentationMessageGenerator({
16678
16708
  name: 'chatTrigger',
16679
16709
  connector: true
16680
16710
  });
16681
16711
  // Reads the sibling chat widget's render state from the live cross-index
16682
16712
  // `instantSearchInstance.renderState` map. We resolve at call time so that
16683
16713
  // `toggleOpen` always sees the latest `open`/`setOpen` values.
16684
- function getChatRenderState(options) {
16714
+ function getChatRenderState$1(options) {
16685
16715
  var _options_parent, _options_instantSearchInstance_renderState_indexId;
16686
16716
  var indexId = (_options_parent = options.parent) === null || _options_parent === void 0 ? void 0 : _options_parent.getIndexId();
16687
16717
  if (!indexId) return undefined;
@@ -16689,17 +16719,17 @@
16689
16719
  }
16690
16720
  var connectChatTrigger = function connectChatTrigger(renderFn) {
16691
16721
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16692
- checkRendering(renderFn, withUsage$n());
16722
+ checkRendering(renderFn, withUsage$o());
16693
16723
  return function(widgetParams) {
16694
16724
  var params = widgetParams !== null && widgetParams !== void 0 ? widgetParams : {};
16695
16725
  var lastOptions = null;
16696
16726
  function openChatFromTrigger(options) {
16697
16727
  if (!lastOptions) return false;
16698
- return openChat(getChatRenderState(lastOptions), options);
16728
+ return openChat(getChatRenderState$1(lastOptions), options);
16699
16729
  }
16700
16730
  function toggleOpen() {
16701
16731
  if (!lastOptions) return;
16702
- var chatState = getChatRenderState(lastOptions);
16732
+ var chatState = getChatRenderState$1(lastOptions);
16703
16733
  if (!chatState) return;
16704
16734
  if (chatState.open) {
16705
16735
  var _chatState_setOpen;
@@ -16729,7 +16759,7 @@
16729
16759
  },
16730
16760
  getWidgetRenderState: function getWidgetRenderState(renderOptions) {
16731
16761
  var _ref;
16732
- var chatState = getChatRenderState(renderOptions);
16762
+ var chatState = getChatRenderState$1(renderOptions);
16733
16763
  return {
16734
16764
  open: (_ref = chatState === null || chatState === void 0 ? void 0 : chatState.open) !== null && _ref !== void 0 ? _ref : false,
16735
16765
  toggleOpen: toggleOpen,
@@ -16755,6 +16785,235 @@
16755
16785
  return useConnector(connectChatTrigger, props, additionalWidgetProperties);
16756
16786
  }
16757
16787
 
16788
+ var withUsage$n = createDocumentationMessageGenerator({
16789
+ name: 'compare',
16790
+ connector: true
16791
+ });
16792
+ /**
16793
+ * Builds the placeholder message for a dashboard-configured comparison. The
16794
+ * Agent Studio backend resolves it against the agent's comparison
16795
+ * configuration: the LLM gets the configured instructions and the transcript
16796
+ * keeps a natural-language message naming the selection.
16797
+ */ function getComparisonPlaceholderMessage(configurationId) {
16798
+ return "__ALGOLIA_COMPARISON_".concat(configurationId, "__");
16799
+ }
16800
+ /**
16801
+ * Builds the default comparison message. It names each selected item so the
16802
+ * agent can ground the comparison: it re-retrieves the records with
16803
+ * `algolia_search_index` and renders them with the builtin
16804
+ * `algolia_compare_products` tool. Works with the default shopping assistant
16805
+ * prompt — no agent configuration required.
16806
+ */ function getDefaultComparisonMessage(items) {
16807
+ var labels = items.map(function(item) {
16808
+ var _item_name;
16809
+ var name = (_item_name = item.name) !== null && _item_name !== void 0 ? _item_name : item.title;
16810
+ return typeof name === 'string' && name !== '' ? '"'.concat(name, '" (objectID: ').concat(item.objectID, ")") : 'the product with objectID "'.concat(item.objectID, '"');
16811
+ });
16812
+ return "Compare these products: ".concat(labels.join(' vs '));
16813
+ }
16814
+ // Turn-context payload for the comparison hand-off, per the Agent Studio
16815
+ // contract: the selection rides `selected_products` (JSON-encoded records,
16816
+ // `_`-prefixed internal metadata stripped) so the agent grounds the comparison
16817
+ // in what the shopper actually selected, and `comparison_configuration_id`
16818
+ // identifies the dashboard configuration when one is set.
16819
+ function buildComparisonTurnContext(items, configurationId) {
16820
+ var records = items.map(function(item) {
16821
+ var clean = {};
16822
+ Object.keys(item).forEach(function(key) {
16823
+ if (!key.startsWith('_')) {
16824
+ clean[key] = item[key];
16825
+ }
16826
+ });
16827
+ return clean;
16828
+ });
16829
+ return _object_spread({
16830
+ selected_products: JSON.stringify(records)
16831
+ }, configurationId ? {
16832
+ comparison_configuration_id: configurationId
16833
+ } : {});
16834
+ }
16835
+ // The selection is shared by every `compare` widget of the same InstantSearch
16836
+ // instance (per-hit toggles, the compare bar, a picker modal, ...), so it
16837
+ // lives in a store keyed by the instance rather than in any single widget.
16838
+ var compareStores = new WeakMap();
16839
+ function getCompareStore(instantSearchInstance) {
16840
+ var store = compareStores.get(instantSearchInstance);
16841
+ if (!store) {
16842
+ store = {
16843
+ items: [],
16844
+ listeners: new Set()
16845
+ };
16846
+ compareStores.set(instantSearchInstance, store);
16847
+ }
16848
+ return store;
16849
+ }
16850
+ // Reads the sibling chat widget's render state from the live cross-index
16851
+ // `instantSearchInstance.renderState` map. Resolved at call time so that
16852
+ // `compare` always sees the latest `open`/`sendMessage` values.
16853
+ function getChatRenderState(options) {
16854
+ var _options_parent, _options_instantSearchInstance_renderState_indexId;
16855
+ var indexId = (_options_parent = options.parent) === null || _options_parent === void 0 ? void 0 : _options_parent.getIndexId();
16856
+ if (!indexId) return undefined;
16857
+ return (_options_instantSearchInstance_renderState_indexId = options.instantSearchInstance.renderState[indexId]) === null || _options_instantSearchInstance_renderState_indexId === void 0 ? void 0 : _options_instantSearchInstance_renderState_indexId.chat;
16858
+ }
16859
+ /**
16860
+ * Compare connector.
16861
+ *
16862
+ * Owns the "products selected for comparison" state and the hand-off into the
16863
+ * chat: `compare()` opens the sibling `chat` widget and sends a comparison
16864
+ * message naming the selected records, which the agent answers with the
16865
+ * grounded `algolia_compare_products` table.
16866
+ *
16867
+ * The selection is shared across all `compare` widgets mounted on the same
16868
+ * InstantSearch instance, so per-hit "Compare" toggles and the `compareBar`
16869
+ * widget stay in sync. The widget is marked with `opensChat`, so it satisfies
16870
+ * the `chat` widget's entry-point validation.
16871
+ */ var connectCompare = function connectCompare(renderFn) {
16872
+ var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16873
+ checkRendering(renderFn, withUsage$n());
16874
+ return function(widgetParams) {
16875
+ var _ref = widgetParams || {}, _ref_minItems = _ref.minItems, minItems = _ref_minItems === void 0 ? 2 : _ref_minItems, _ref_maxItems = _ref.maxItems, maxItems = _ref_maxItems === void 0 ? 3 : _ref_maxItems, configurationId = _ref.configurationId, _ref_getComparisonMessage = _ref.getComparisonMessage, getComparisonMessage = _ref_getComparisonMessage === void 0 ? configurationId ? function() {
16876
+ return getComparisonPlaceholderMessage(configurationId);
16877
+ } : getDefaultComparisonMessage : _ref_getComparisonMessage;
16878
+ if (minItems < 2) {
16879
+ throw new Error(withUsage$n('The `minItems` option must be at least 2.'));
16880
+ }
16881
+ if (maxItems < minItems) {
16882
+ throw new Error(withUsage$n('The `maxItems` option must be greater than `minItems`.'));
16883
+ }
16884
+ var lastOptions = null;
16885
+ var unsubscribe = null;
16886
+ function getStore() {
16887
+ if (!lastOptions) return null;
16888
+ return getCompareStore(lastOptions.instantSearchInstance);
16889
+ }
16890
+ // Re-renders every subscribed `compare` widget, then schedules a full
16891
+ // render so anything else reading `renderState.compare` catches up.
16892
+ function notify(store) {
16893
+ store.listeners.forEach(function(listener) {
16894
+ return listener();
16895
+ });
16896
+ lastOptions === null || lastOptions === void 0 ? void 0 : lastOptions.instantSearchInstance.scheduleRender();
16897
+ }
16898
+ function isSelected(objectID) {
16899
+ var store = getStore();
16900
+ return Boolean(store === null || store === void 0 ? void 0 : store.items.some(function(item) {
16901
+ return item.objectID === objectID;
16902
+ }));
16903
+ }
16904
+ function addItem(item) {
16905
+ var store = getStore();
16906
+ if (!store || store.items.length >= maxItems || isSelected(item.objectID)) {
16907
+ return;
16908
+ }
16909
+ store.items = _to_consumable_array(store.items).concat([
16910
+ item
16911
+ ]);
16912
+ notify(store);
16913
+ }
16914
+ function removeItem(objectID) {
16915
+ var store = getStore();
16916
+ if (!store || !isSelected(objectID)) return;
16917
+ store.items = store.items.filter(function(item) {
16918
+ return item.objectID !== objectID;
16919
+ });
16920
+ notify(store);
16921
+ }
16922
+ function toggleItem(item) {
16923
+ if (isSelected(item.objectID)) {
16924
+ removeItem(item.objectID);
16925
+ } else {
16926
+ addItem(item);
16927
+ }
16928
+ }
16929
+ function clearItems() {
16930
+ var store = getStore();
16931
+ if (!store || store.items.length === 0) return;
16932
+ store.items = [];
16933
+ notify(store);
16934
+ }
16935
+ function compare() {
16936
+ var store = getStore();
16937
+ if (!store || !lastOptions || store.items.length < minItems) {
16938
+ return false;
16939
+ }
16940
+ return openChat(getChatRenderState(lastOptions), {
16941
+ message: getComparisonMessage(store.items),
16942
+ referer: 'compare',
16943
+ turnContext: buildComparisonTurnContext(store.items, configurationId)
16944
+ });
16945
+ }
16946
+ return {
16947
+ $$type: 'ais.compare',
16948
+ opensChat: true,
16949
+ init: function init(initOptions) {
16950
+ var _this = this;
16951
+ lastOptions = initOptions;
16952
+ var store = getCompareStore(initOptions.instantSearchInstance);
16953
+ var listener = function listener() {
16954
+ if (!lastOptions) return;
16955
+ renderFn(_object_spread_props(_object_spread({}, _this.getWidgetRenderState(lastOptions)), {
16956
+ instantSearchInstance: lastOptions.instantSearchInstance
16957
+ }), false);
16958
+ };
16959
+ store.listeners.add(listener);
16960
+ unsubscribe = function unsubscribe() {
16961
+ return store.listeners.delete(listener);
16962
+ };
16963
+ renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
16964
+ instantSearchInstance: initOptions.instantSearchInstance
16965
+ }), true);
16966
+ },
16967
+ render: function render(renderOptions) {
16968
+ lastOptions = renderOptions;
16969
+ renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(renderOptions)), {
16970
+ instantSearchInstance: renderOptions.instantSearchInstance
16971
+ }), false);
16972
+ },
16973
+ dispose: function dispose() {
16974
+ unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe();
16975
+ unsubscribe = null;
16976
+ unmountFn();
16977
+ },
16978
+ getWidgetRenderState: function getWidgetRenderState(renderOptions) {
16979
+ lastOptions = renderOptions;
16980
+ var store = getCompareStore(renderOptions.instantSearchInstance);
16981
+ return {
16982
+ items: store.items,
16983
+ isSelected: isSelected,
16984
+ addItem: addItem,
16985
+ removeItem: removeItem,
16986
+ toggleItem: toggleItem,
16987
+ clearItems: clearItems,
16988
+ canAddItems: store.items.length < maxItems,
16989
+ canCompare: store.items.length >= minItems,
16990
+ minItems: minItems,
16991
+ maxItems: maxItems,
16992
+ compare: compare,
16993
+ widgetParams: widgetParams || {}
16994
+ };
16995
+ },
16996
+ getRenderState: function getRenderState(renderState, renderOptions) {
16997
+ return _object_spread_props(_object_spread({}, renderState), {
16998
+ compare: this.getWidgetRenderState(renderOptions)
16999
+ });
17000
+ }
17001
+ };
17002
+ };
17003
+ };
17004
+
17005
+ /**
17006
+ * Exposes the shared comparison selection and the chat hand-off.
17007
+ *
17008
+ * The selection is shared by every `useCompare` call on the same InstantSearch
17009
+ * instance, so a per-hit "Compare" toggle (`toggleItem`) and the `<CompareBar>`
17010
+ * widget stay in sync. `compare()` opens the `<Chat>` widget and sends the
17011
+ * comparison message for the current selection.
17012
+ */ function useCompare() {
17013
+ var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, additionalWidgetProperties = arguments.length > 1 ? arguments[1] : void 0;
17014
+ return useConnector(connectCompare, props, additionalWidgetProperties);
17015
+ }
17016
+
16758
17017
  var withUsage$m = createDocumentationMessageGenerator({
16759
17018
  name: 'clear-refinements',
16760
17019
  connector: true
@@ -17125,7 +17384,7 @@
17125
17384
  objectID: objectID,
17126
17385
  maxRecommendations: limit,
17127
17386
  threshold: threshold,
17128
- // @ts-expect-error until @algolia/recommend types are updated
17387
+ // @ts-ignore until @algolia/recommend types are updated
17129
17388
  fallbackParameters: fallbackParameters ? _object_spread({}, fallbackParameters, escapeHTML ? TAG_PLACEHOLDER : {}) : undefined,
17130
17389
  queryParameters: _object_spread({}, queryParameters, escapeHTML ? TAG_PLACEHOLDER : {}),
17131
17390
  $$id: _this.$$id
@@ -20903,6 +21162,7 @@
20903
21162
  exports.useChat = useChat;
20904
21163
  exports.useChatTrigger = useChatTrigger;
20905
21164
  exports.useClearRefinements = useClearRefinements;
21165
+ exports.useCompare = useCompare;
20906
21166
  exports.useConfigure = useConfigure;
20907
21167
  exports.useConnector = useConnector;
20908
21168
  exports.useCurrentRefinements = useCurrentRefinements;