react-instantsearch-core 7.49.0 → 7.50.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.
@@ -1,4 +1,4 @@
1
- /*! React InstantSearch Core 7.49.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! React InstantSearch Core 7.50.0 | © 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.0';
27
+ var version$2 = '7.50.0';
28
28
 
29
29
  function _define_property(obj, key, value) {
30
30
  if (key in obj) {
@@ -5980,7 +5980,7 @@
5980
5980
  }
5981
5981
  }
5982
5982
 
5983
- var withUsage$x = createDocumentationMessageGenerator({
5983
+ var withUsage$y = createDocumentationMessageGenerator({
5984
5984
  name: 'configure',
5985
5985
  connector: true
5986
5986
  });
@@ -5996,7 +5996,7 @@
5996
5996
  var renderFn = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : noop, unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
5997
5997
  return function(widgetParams) {
5998
5998
  if (!widgetParams || !isPlainObject(widgetParams.searchParameters)) {
5999
- throw new Error(withUsage$x('The `searchParameters` option expects an object.'));
5999
+ throw new Error(withUsage$y('The `searchParameters` option expects an object.'));
6000
6000
  }
6001
6001
  var connectorState = {};
6002
6002
  function refine(helper) {
@@ -7833,13 +7833,13 @@
7833
7833
  return null;
7834
7834
  }
7835
7835
 
7836
- var withUsage$w = createDocumentationMessageGenerator({
7836
+ var withUsage$x = createDocumentationMessageGenerator({
7837
7837
  name: 'dynamic-widgets',
7838
7838
  connector: true
7839
7839
  });
7840
7840
  var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
7841
7841
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
7842
- checkRendering(renderFn, withUsage$w());
7842
+ checkRendering(renderFn, withUsage$x());
7843
7843
  return function(widgetParams) {
7844
7844
  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
7845
  '*'
@@ -7849,10 +7849,10 @@
7849
7849
  if (!(widgets && Array.isArray(widgets) && widgets.every(function(widget) {
7850
7850
  return (typeof widget === "undefined" ? "undefined" : _type_of(widget)) === 'object';
7851
7851
  }))) {
7852
- throw new Error(withUsage$w('The `widgets` option expects an array of widgets.'));
7852
+ throw new Error(withUsage$x('The `widgets` option expects an array of widgets.'));
7853
7853
  }
7854
7854
  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))));
7855
+ throw new Error(withUsage$x("The `facets` option only accepts an array of facets, you passed ".concat(JSON.stringify(facets))));
7856
7856
  }
7857
7857
  var localWidgets = new Map();
7858
7858
  return {
@@ -7954,7 +7954,7 @@
7954
7954
  results: results
7955
7955
  });
7956
7956
  if (!Array.isArray(attributesToRender)) {
7957
- throw new Error(withUsage$w('The `transformItems` option expects a function that returns an Array.'));
7957
+ throw new Error(withUsage$x('The `transformItems` option expects a function that returns an Array.'));
7958
7958
  }
7959
7959
  return {
7960
7960
  attributesToRender: attributesToRender,
@@ -8345,19 +8345,19 @@
8345
8345
  return toFeedSearchResults(lastResults._state, raw);
8346
8346
  });
8347
8347
  }
8348
- var withUsage$v = createDocumentationMessageGenerator({
8348
+ var withUsage$w = createDocumentationMessageGenerator({
8349
8349
  name: 'feeds',
8350
8350
  connector: true
8351
8351
  });
8352
8352
  var connectFeeds = function connectFeeds(renderFn) {
8353
8353
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
8354
- checkRendering(renderFn, withUsage$v());
8354
+ checkRendering(renderFn, withUsage$w());
8355
8355
  return function(widgetParams) {
8356
8356
  var isolated = widgetParams.isolated, _widgetParams_transformFeeds = widgetParams.transformFeeds, transformFeeds = _widgetParams_transformFeeds === void 0 ? function(feeds) {
8357
8357
  return feeds;
8358
8358
  } : _widgetParams_transformFeeds;
8359
8359
  if (isolated !== false) {
8360
- throw new Error(withUsage$v('The `isolated` option currently only supports `false`.'));
8360
+ throw new Error(withUsage$w('The `isolated` option currently only supports `false`.'));
8361
8361
  }
8362
8362
  return {
8363
8363
  $$type: 'ais.feeds',
@@ -8365,7 +8365,7 @@
8365
8365
  init: function init(initOptions) {
8366
8366
  var instantSearchInstance = initOptions.instantSearchInstance;
8367
8367
  if (!instantSearchInstance.compositionID) {
8368
- throw new Error(withUsage$v('The `feeds` widget requires a composition-based InstantSearch instance (compositionID must be set).'));
8368
+ throw new Error(withUsage$w('The `feeds` widget requires a composition-based InstantSearch instance (compositionID must be set).'));
8369
8369
  }
8370
8370
  hydrateFeedsFromInitialResultsIfNeeded(instantSearchInstance, initOptions.parent);
8371
8371
  renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
@@ -8411,12 +8411,12 @@
8411
8411
  ];
8412
8412
  feedIDs = transformFeeds(feedIDs);
8413
8413
  if (!Array.isArray(feedIDs)) {
8414
- throw new Error(withUsage$v('The `transformFeeds` option expects a function that returns an Array.'));
8414
+ throw new Error(withUsage$w('The `transformFeeds` option expects a function that returns an Array.'));
8415
8415
  }
8416
8416
  if (!feedIDs.every(function(feedID) {
8417
8417
  return typeof feedID === 'string';
8418
8418
  })) {
8419
- throw new Error(withUsage$v('The `transformFeeds` option expects a function that returns an array of feed IDs (strings).'));
8419
+ throw new Error(withUsage$w('The `transformFeeds` option expects a function that returns an array of feed IDs (strings).'));
8420
8420
  }
8421
8421
  return {
8422
8422
  feedIDs: feedIDs,
@@ -8527,7 +8527,7 @@
8527
8527
  }));
8528
8528
  }
8529
8529
 
8530
- var withUsage$u = createDocumentationMessageGenerator({
8530
+ var withUsage$v = createDocumentationMessageGenerator({
8531
8531
  name: 'index-widget'
8532
8532
  });
8533
8533
  /**
@@ -8655,7 +8655,7 @@
8655
8655
  var index = function index(widgetParams) {
8656
8656
  var _widgetParams_EXPERIMENTAL_isolated;
8657
8657
  if (widgetParams === undefined || widgetParams.indexName === undefined && !widgetParams.isolated && !widgetParams.EXPERIMENTAL_isolated) {
8658
- throw new Error(withUsage$u('The `indexName` option is required.'));
8658
+ throw new Error(withUsage$v('The `indexName` option is required.'));
8659
8659
  }
8660
8660
  // When isolated=true, we use an empty string as the default indexName.
8661
8661
  // This is intentional: isolated indices do not require a real index name.
@@ -8753,7 +8753,7 @@
8753
8753
  addWidgets: function addWidgets(widgets) {
8754
8754
  var _this = this;
8755
8755
  if (!Array.isArray(widgets)) {
8756
- throw new Error(withUsage$u('The `addWidgets` method expects an array of widgets.'));
8756
+ throw new Error(withUsage$v('The `addWidgets` method expects an array of widgets.'));
8757
8757
  }
8758
8758
  var flatWidgets = widgets.reduce(function(acc, w) {
8759
8759
  return acc.concat(Array.isArray(w) ? w : [
@@ -8763,7 +8763,7 @@
8763
8763
  if (flatWidgets.some(function(widget) {
8764
8764
  return typeof widget.init !== 'function' && typeof widget.render !== 'function';
8765
8765
  })) {
8766
- throw new Error(withUsage$u('The widget definition expects a `render` and/or an `init` method.'));
8766
+ throw new Error(withUsage$v('The widget definition expects a `render` and/or an `init` method.'));
8767
8767
  }
8768
8768
  flatWidgets.forEach(function(widget) {
8769
8769
  widget.parent = _this;
@@ -8813,10 +8813,10 @@
8813
8813
  },
8814
8814
  updateWidget: function updateWidget(previousWidget, nextWidget) {
8815
8815
  if (typeof previousWidget.dispose !== 'function') {
8816
- throw new Error(withUsage$u('The widget definition expects a `dispose` method.'));
8816
+ throw new Error(withUsage$v('The widget definition expects a `dispose` method.'));
8817
8817
  }
8818
8818
  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.'));
8819
+ throw new Error(withUsage$v('The widget definition expects a `render` and/or an `init` method.'));
8820
8820
  }
8821
8821
  // The `uiState` as it is before the previous widget is detached, so that
8822
8822
  // the state it owns can be handed over to the next widget.
@@ -8900,7 +8900,7 @@
8900
8900
  removeWidgets: function removeWidgets(widgets) {
8901
8901
  var _this = this;
8902
8902
  if (!Array.isArray(widgets)) {
8903
- throw new Error(withUsage$u('The `removeWidgets` method expects an array of widgets.'));
8903
+ throw new Error(withUsage$v('The `removeWidgets` method expects an array of widgets.'));
8904
8904
  }
8905
8905
  var flatWidgets = widgets.reduce(function(acc, w) {
8906
8906
  return acc.concat(Array.isArray(w) ? w : [
@@ -8910,7 +8910,7 @@
8910
8910
  if (flatWidgets.some(function(widget) {
8911
8911
  return typeof widget.dispose !== 'function';
8912
8912
  })) {
8913
- throw new Error(withUsage$u('The widget definition expects a `dispose` method.'));
8913
+ throw new Error(withUsage$v('The widget definition expects a `dispose` method.'));
8914
8914
  }
8915
8915
  localWidgets = localWidgets.filter(function(widget) {
8916
8916
  return flatWidgets.indexOf(widget) === -1;
@@ -9418,7 +9418,7 @@
9418
9418
  });
9419
9419
  }
9420
9420
 
9421
- var version = '4.116.0';
9421
+ var version = '4.118.0';
9422
9422
 
9423
9423
  var ANONYMOUS_TOKEN_COOKIE_KEY = '_ALGOLIA';
9424
9424
  function getCookie(name) {
@@ -11280,7 +11280,7 @@
11280
11280
  };
11281
11281
  }
11282
11282
 
11283
- var withUsage$t = createDocumentationMessageGenerator({
11283
+ var withUsage$u = createDocumentationMessageGenerator({
11284
11284
  name: 'instantsearch'
11285
11285
  });
11286
11286
  function defaultCreateURL() {
@@ -11351,7 +11351,7 @@
11351
11351
  _this.setMaxListeners(100);
11352
11352
  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
11353
  if (searchClient === null) {
11354
- throw new Error(withUsage$t('The `searchClient` option is required.'));
11354
+ throw new Error(withUsage$u('The `searchClient` option is required.'));
11355
11355
  }
11356
11356
  if (typeof searchClient.search !== 'function') {
11357
11357
  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 +11360,7 @@
11360
11360
  searchClient.addAlgoliaAgent("instantsearch.js (".concat(version, ")"));
11361
11361
  }
11362
11362
  if (insightsClient && typeof insightsClient !== 'function') {
11363
- throw new Error(withUsage$t('The `insightsClient` option should be a function.'));
11363
+ throw new Error(withUsage$u('The `insightsClient` option should be a function.'));
11364
11364
  }
11365
11365
  _this._initialOptions = options;
11366
11366
  _this.client = searchClient;
@@ -11509,12 +11509,12 @@
11509
11509
  * @param widgets The array of widgets to add to InstantSearch.
11510
11510
  */ function addWidgets(widgets) {
11511
11511
  if (!Array.isArray(widgets)) {
11512
- throw new Error(withUsage$t('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
11512
+ throw new Error(withUsage$u('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
11513
11513
  }
11514
11514
  if (this.compositionID && widgets.some(function(w) {
11515
11515
  return !Array.isArray(w) && isIndexWidget(w) && !w._isolated;
11516
11516
  })) {
11517
- throw new Error(withUsage$t('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
11517
+ throw new Error(withUsage$u('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
11518
11518
  }
11519
11519
  this.mainIndex.addWidgets(widgets);
11520
11520
  return this;
@@ -11543,7 +11543,7 @@
11543
11543
  * The widgets must implement a `dispose()` method to clear their states.
11544
11544
  */ function removeWidgets(widgets) {
11545
11545
  if (!Array.isArray(widgets)) {
11546
- throw new Error(withUsage$t('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
11546
+ throw new Error(withUsage$u('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
11547
11547
  }
11548
11548
  this.mainIndex.removeWidgets(widgets);
11549
11549
  return this;
@@ -11557,7 +11557,7 @@
11557
11557
  */ function start() {
11558
11558
  var _this = this;
11559
11559
  if (this.started) {
11560
- throw new Error(withUsage$t('The `start` method has already been called once.'));
11560
+ throw new Error(withUsage$u('The `start` method has already been called once.'));
11561
11561
  }
11562
11562
  // This Helper is used for the queries, we don't care about its state. The
11563
11563
  // states are managed at the `index` level. We use this Helper to create
@@ -11765,7 +11765,7 @@
11765
11765
  var _this = this;
11766
11766
  var callOnStateChange = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
11767
11767
  if (!this.mainHelper) {
11768
- throw new Error(withUsage$t('The `start` method needs to be called before `setUiState`.'));
11768
+ throw new Error(withUsage$u('The `start` method needs to be called before `setUiState`.'));
11769
11769
  }
11770
11770
  // We refresh the index UI state to update the local UI state that the
11771
11771
  // main index passes to the function form of `setUiState`.
@@ -11802,7 +11802,7 @@
11802
11802
  value: function createURL() {
11803
11803
  var nextState = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
11804
11804
  if (!this.started) {
11805
- throw new Error(withUsage$t('The `start` method needs to be called before `createURL`.'));
11805
+ throw new Error(withUsage$u('The `start` method needs to be called before `createURL`.'));
11806
11806
  }
11807
11807
  return this._createURL(nextState);
11808
11808
  }
@@ -11811,7 +11811,7 @@
11811
11811
  key: "refresh",
11812
11812
  value: function refresh() {
11813
11813
  if (!this.mainHelper) {
11814
- throw new Error(withUsage$t('The `start` method needs to be called before `refresh`.'));
11814
+ throw new Error(withUsage$u('The `start` method needs to be called before `refresh`.'));
11815
11815
  }
11816
11816
  this.mainHelper.clearCache().search();
11817
11817
  }
@@ -12343,13 +12343,13 @@
12343
12343
  }, children);
12344
12344
  }
12345
12345
 
12346
- var withUsage$s = createDocumentationMessageGenerator({
12346
+ var withUsage$t = createDocumentationMessageGenerator({
12347
12347
  name: 'autocomplete',
12348
12348
  connector: true
12349
12349
  });
12350
12350
  var connectAutocomplete = function connectAutocomplete(renderFn) {
12351
12351
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
12352
- checkRendering(renderFn, withUsage$s());
12352
+ checkRendering(renderFn, withUsage$t());
12353
12353
  return function(widgetParams) {
12354
12354
  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
12355
  return indices;
@@ -12462,20 +12462,20 @@
12462
12462
  return useConnector(connectAutocomplete, props, additionalWidgetProperties);
12463
12463
  }
12464
12464
 
12465
- var withUsage$r = createDocumentationMessageGenerator({
12465
+ var withUsage$s = createDocumentationMessageGenerator({
12466
12466
  name: 'breadcrumb',
12467
12467
  connector: true
12468
12468
  });
12469
12469
  var connectBreadcrumb = function connectBreadcrumb(renderFn) {
12470
12470
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
12471
- checkRendering(renderFn, withUsage$r());
12471
+ checkRendering(renderFn, withUsage$s());
12472
12472
  var connectorState = {};
12473
12473
  return function(widgetParams) {
12474
12474
  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
12475
  return items;
12476
12476
  } : _ref_transformItems;
12477
12477
  if (!attributes || !Array.isArray(attributes) || attributes.length === 0) {
12478
- throw new Error(withUsage$r('The `attributes` option expects an array of strings.'));
12478
+ throw new Error(withUsage$s('The `attributes` option expects an array of strings.'));
12479
12479
  }
12480
12480
  var _attributes = _sliced_to_array(attributes, 1), hierarchicalFacetName = _attributes[0];
12481
12481
  function getRefinedState(state, facetValue) {
@@ -14917,7 +14917,7 @@
14917
14917
  return DefaultChatTransport;
14918
14918
  }(HttpChatTransport);
14919
14919
 
14920
- var withUsage$q = createDocumentationMessageGenerator({
14920
+ var withUsage$r = createDocumentationMessageGenerator({
14921
14921
  name: 'chat',
14922
14922
  connector: true
14923
14923
  });
@@ -15048,7 +15048,7 @@
15048
15048
  }
15049
15049
  var connectChat = function connectChat(renderFn) {
15050
15050
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15051
- checkRendering(renderFn, withUsage$q());
15051
+ checkRendering(renderFn, withUsage$r());
15052
15052
  return function(widgetParams) {
15053
15053
  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
15054
  "resume",
@@ -15081,7 +15081,7 @@
15081
15081
  var hasValidatedEntryPoints = false;
15082
15082
  var agentId = 'agentId' in options ? options.agentId : undefined;
15083
15083
  // Collected here rather than by the tool that searched: that tool renders
15084
- // nothing while display-results presents its records, and a record has to
15084
+ // nothing while Grouped Results presents its records, and a record has to
15085
15085
  // outlive the render that produced it.
15086
15086
  var records = createChatRecordsStore();
15087
15087
  var collectRecords = function collectRecords() {
@@ -15113,28 +15113,6 @@
15113
15113
  var _findSuggestionsPart;
15114
15114
  return (_findSuggestionsPart = findSuggestionsPart(findLastAssistantMessage(messages))) === null || _findSuggestionsPart === void 0 ? void 0 : _findSuggestionsPart.data.suggestions;
15115
15115
  };
15116
- // "Still coming" has to be inferred: the turn is running and has no
15117
- // `data-suggestions` part yet. Expecting any at all needs evidence, or an
15118
- // agent that never sends them would sit under a placeholder forever.
15119
- var getSuggestionsStatus = function getSuggestionsStatus(messages) {
15120
- var _lastAssistantMessage_metadata;
15121
- var status = _chatInstance.status;
15122
- if (status !== 'submitted' && status !== 'streaming') {
15123
- return 'idle';
15124
- }
15125
- var lastAssistantMessage = findLastAssistantMessage(messages);
15126
- if (findSuggestionsPart(lastAssistantMessage)) {
15127
- return 'idle';
15128
- }
15129
- var declaresSuggestions = (lastAssistantMessage === null || lastAssistantMessage === void 0 ? void 0 : (_lastAssistantMessage_metadata = lastAssistantMessage.metadata) === null || _lastAssistantMessage_metadata === void 0 ? void 0 : _lastAssistantMessage_metadata.suggestionsEnabled) === true;
15130
- if (declaresSuggestions) {
15131
- return 'loading';
15132
- }
15133
- var hasSuggestionsHistory = messages.some(function(message) {
15134
- return message !== lastAssistantMessage && message.role === 'assistant' && Boolean(findSuggestionsPart(message));
15135
- });
15136
- return hasSuggestionsHistory ? 'loading' : 'idle';
15137
- };
15138
15116
  var setMessages = function setMessages(messagesParam) {
15139
15117
  if (typeof messagesParam === 'function') {
15140
15118
  messagesParam = messagesParam(_chatInstance.messages);
@@ -15230,7 +15208,7 @@
15230
15208
  if ('agentId' in options && options.agentId) {
15231
15209
  var _options_requestOptions, _options_requestOptions1;
15232
15210
  if (!appId || !apiKey) {
15233
- throw new Error(withUsage$q('Could not extract Algolia credentials from the search client.'));
15211
+ throw new Error(withUsage$r('Could not extract Algolia credentials from the search client.'));
15234
15212
  }
15235
15213
  var createApi = function createApi() {
15236
15214
  var bypassCache = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
@@ -15269,7 +15247,7 @@
15269
15247
  });
15270
15248
  }
15271
15249
  if (!transport) {
15272
- throw new Error(withUsage$q('You need to provide either an `agentId` or a `transport`.'));
15250
+ throw new Error(withUsage$r('You need to provide either an `agentId` or a `transport`.'));
15273
15251
  }
15274
15252
  var canRepairRestoredPendingToolParts = !resume;
15275
15253
  var chat = new Chat(_object_spread_props(_object_spread({}, options), {
@@ -15459,7 +15437,7 @@
15459
15437
  if (agentId && feedback) {
15460
15438
  var _getAppIdAndApiKey = _sliced_to_array(getAppIdAndApiKey(initOptions.instantSearchInstance.client), 2), appId = _getAppIdAndApiKey[0], apiKey = _getAppIdAndApiKey[1];
15461
15439
  if (!appId || !apiKey) {
15462
- throw new Error(withUsage$q('Could not extract Algolia credentials from the search client.'));
15440
+ throw new Error(withUsage$r('Could not extract Algolia credentials from the search client.'));
15463
15441
  }
15464
15442
  feedbackAbortController = new AbortController();
15465
15443
  _sendChatMessageFeedback = function _sendChatMessageFeedback(messageId, vote) {
@@ -15622,7 +15600,6 @@
15622
15600
  '~isOpenStatePersistenceEnabled': normalizedPersistence.open,
15623
15601
  setMessages: setMessages,
15624
15602
  suggestions: getSuggestionsFromMessages(_chatInstance.messages),
15625
- suggestionsStatus: getSuggestionsStatus(_chatInstance.messages),
15626
15603
  clearMessages: clearMessages,
15627
15604
  tools: toolsWithAddToolResult,
15628
15605
  records: records,
@@ -16096,20 +16073,20 @@
16096
16073
  };
16097
16074
  }
16098
16075
 
16099
- var withUsage$p = createDocumentationMessageGenerator({
16076
+ var withUsage$q = createDocumentationMessageGenerator({
16100
16077
  name: 'tasks',
16101
16078
  connector: true
16102
16079
  });
16103
16080
  var connectTasks = function connectTasks(renderFn) {
16104
16081
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16105
- checkRendering(renderFn, withUsage$p());
16082
+ checkRendering(renderFn, withUsage$q());
16106
16083
  return function(widgetParams) {
16107
16084
  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;
16108
16085
  if (!agentId && !transport) {
16109
- throw new Error(withUsage$p('The `agentId` option is required unless a custom `transport` is provided.'));
16086
+ throw new Error(withUsage$q('The `agentId` option is required unless a custom `transport` is provided.'));
16110
16087
  }
16111
16088
  if (!task && !kind) {
16112
- throw new Error(withUsage$p('Either the `task` or `kind` option is required.'));
16089
+ throw new Error(withUsage$q('Either the `task` or `kind` option is required.'));
16113
16090
  }
16114
16091
  var runner;
16115
16092
  var output;
@@ -16183,7 +16160,7 @@
16183
16160
  if (agentId) {
16184
16161
  var _getAppIdAndApiKey = _sliced_to_array(getAppIdAndApiKey(instantSearchInstance.client), 2), appId = _getAppIdAndApiKey[0], apiKey = _getAppIdAndApiKey[1];
16185
16162
  if (!appId || !apiKey) {
16186
- throw new Error(withUsage$p('Could not extract Algolia credentials from the search client.'));
16163
+ throw new Error(withUsage$q('Could not extract Algolia credentials from the search client.'));
16187
16164
  }
16188
16165
  var taskTransport = createTaskTransport({
16189
16166
  transport: transport,
@@ -16230,7 +16207,7 @@
16230
16207
  };
16231
16208
  };
16232
16209
 
16233
- var withUsage$o = createDocumentationMessageGenerator({
16210
+ var withUsage$p = createDocumentationMessageGenerator({
16234
16211
  name: 'prompt-suggestions',
16235
16212
  connector: true
16236
16213
  });
@@ -16327,13 +16304,13 @@
16327
16304
  }
16328
16305
  var connectPromptSuggestions = function connectPromptSuggestions(renderFn) {
16329
16306
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16330
- checkRendering(renderFn, withUsage$o());
16307
+ checkRendering(renderFn, withUsage$p());
16331
16308
  return function(widgetParams) {
16332
16309
  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) {
16333
16310
  return items;
16334
16311
  } : _widgetParams_transformItems, transport = widgetParams.transport;
16335
16312
  if (!agentId && !transport) {
16336
- throw new Error(withUsage$o('The `agentId` option is required unless a custom `transport` is provided.'));
16313
+ throw new Error(withUsage$p('The `agentId` option is required unless a custom `transport` is provided.'));
16337
16314
  }
16338
16315
  var tasksState;
16339
16316
  var suggestions = [];
@@ -16613,7 +16590,7 @@
16613
16590
  stream: true
16614
16591
  };
16615
16592
  } else {
16616
- throw new Error(withUsage$o('The `agentId` option is required unless a custom `transport` is provided.'));
16593
+ throw new Error(withUsage$p('The `agentId` option is required unless a custom `transport` is provided.'));
16617
16594
  }
16618
16595
  var tasksWidget = connectTasks(handleInnerRender, noop)(tasksParams);
16619
16596
  return {
@@ -16697,14 +16674,14 @@
16697
16674
  return useConnector(connectPromptSuggestions, props, additionalWidgetProperties);
16698
16675
  }
16699
16676
 
16700
- var withUsage$n = createDocumentationMessageGenerator({
16677
+ var withUsage$o = createDocumentationMessageGenerator({
16701
16678
  name: 'chatTrigger',
16702
16679
  connector: true
16703
16680
  });
16704
16681
  // Reads the sibling chat widget's render state from the live cross-index
16705
16682
  // `instantSearchInstance.renderState` map. We resolve at call time so that
16706
16683
  // `toggleOpen` always sees the latest `open`/`setOpen` values.
16707
- function getChatRenderState(options) {
16684
+ function getChatRenderState$1(options) {
16708
16685
  var _options_parent, _options_instantSearchInstance_renderState_indexId;
16709
16686
  var indexId = (_options_parent = options.parent) === null || _options_parent === void 0 ? void 0 : _options_parent.getIndexId();
16710
16687
  if (!indexId) return undefined;
@@ -16712,17 +16689,17 @@
16712
16689
  }
16713
16690
  var connectChatTrigger = function connectChatTrigger(renderFn) {
16714
16691
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16715
- checkRendering(renderFn, withUsage$n());
16692
+ checkRendering(renderFn, withUsage$o());
16716
16693
  return function(widgetParams) {
16717
16694
  var params = widgetParams !== null && widgetParams !== void 0 ? widgetParams : {};
16718
16695
  var lastOptions = null;
16719
16696
  function openChatFromTrigger(options) {
16720
16697
  if (!lastOptions) return false;
16721
- return openChat(getChatRenderState(lastOptions), options);
16698
+ return openChat(getChatRenderState$1(lastOptions), options);
16722
16699
  }
16723
16700
  function toggleOpen() {
16724
16701
  if (!lastOptions) return;
16725
- var chatState = getChatRenderState(lastOptions);
16702
+ var chatState = getChatRenderState$1(lastOptions);
16726
16703
  if (!chatState) return;
16727
16704
  if (chatState.open) {
16728
16705
  var _chatState_setOpen;
@@ -16752,7 +16729,7 @@
16752
16729
  },
16753
16730
  getWidgetRenderState: function getWidgetRenderState(renderOptions) {
16754
16731
  var _ref;
16755
- var chatState = getChatRenderState(renderOptions);
16732
+ var chatState = getChatRenderState$1(renderOptions);
16756
16733
  return {
16757
16734
  open: (_ref = chatState === null || chatState === void 0 ? void 0 : chatState.open) !== null && _ref !== void 0 ? _ref : false,
16758
16735
  toggleOpen: toggleOpen,
@@ -16778,6 +16755,235 @@
16778
16755
  return useConnector(connectChatTrigger, props, additionalWidgetProperties);
16779
16756
  }
16780
16757
 
16758
+ var withUsage$n = createDocumentationMessageGenerator({
16759
+ name: 'compare',
16760
+ connector: true
16761
+ });
16762
+ /**
16763
+ * Builds the placeholder message for a dashboard-configured comparison. The
16764
+ * Agent Studio backend resolves it against the agent's comparison
16765
+ * configuration: the LLM gets the configured instructions and the transcript
16766
+ * keeps a natural-language message naming the selection.
16767
+ */ function getComparisonPlaceholderMessage(configurationId) {
16768
+ return "__ALGOLIA_COMPARISON_".concat(configurationId, "__");
16769
+ }
16770
+ /**
16771
+ * Builds the default comparison message. It names each selected item so the
16772
+ * agent can ground the comparison: it re-retrieves the records with
16773
+ * `algolia_search_index` and renders them with the builtin
16774
+ * `algolia_compare_products` tool. Works with the default shopping assistant
16775
+ * prompt — no agent configuration required.
16776
+ */ function getDefaultComparisonMessage(items) {
16777
+ var labels = items.map(function(item) {
16778
+ var _item_name;
16779
+ var name = (_item_name = item.name) !== null && _item_name !== void 0 ? _item_name : item.title;
16780
+ return typeof name === 'string' && name !== '' ? '"'.concat(name, '" (objectID: ').concat(item.objectID, ")") : 'the product with objectID "'.concat(item.objectID, '"');
16781
+ });
16782
+ return "Compare these products: ".concat(labels.join(' vs '));
16783
+ }
16784
+ // Turn-context payload for the comparison hand-off, per the Agent Studio
16785
+ // contract: the selection rides `selected_products` (JSON-encoded records,
16786
+ // `_`-prefixed internal metadata stripped) so the agent grounds the comparison
16787
+ // in what the shopper actually selected, and `comparison_configuration_id`
16788
+ // identifies the dashboard configuration when one is set.
16789
+ function buildComparisonTurnContext(items, configurationId) {
16790
+ var records = items.map(function(item) {
16791
+ var clean = {};
16792
+ Object.keys(item).forEach(function(key) {
16793
+ if (!key.startsWith('_')) {
16794
+ clean[key] = item[key];
16795
+ }
16796
+ });
16797
+ return clean;
16798
+ });
16799
+ return _object_spread({
16800
+ selected_products: JSON.stringify(records)
16801
+ }, configurationId ? {
16802
+ comparison_configuration_id: configurationId
16803
+ } : {});
16804
+ }
16805
+ // The selection is shared by every `compare` widget of the same InstantSearch
16806
+ // instance (per-hit toggles, the compare bar, a picker modal, ...), so it
16807
+ // lives in a store keyed by the instance rather than in any single widget.
16808
+ var compareStores = new WeakMap();
16809
+ function getCompareStore(instantSearchInstance) {
16810
+ var store = compareStores.get(instantSearchInstance);
16811
+ if (!store) {
16812
+ store = {
16813
+ items: [],
16814
+ listeners: new Set()
16815
+ };
16816
+ compareStores.set(instantSearchInstance, store);
16817
+ }
16818
+ return store;
16819
+ }
16820
+ // Reads the sibling chat widget's render state from the live cross-index
16821
+ // `instantSearchInstance.renderState` map. Resolved at call time so that
16822
+ // `compare` always sees the latest `open`/`sendMessage` values.
16823
+ function getChatRenderState(options) {
16824
+ var _options_parent, _options_instantSearchInstance_renderState_indexId;
16825
+ var indexId = (_options_parent = options.parent) === null || _options_parent === void 0 ? void 0 : _options_parent.getIndexId();
16826
+ if (!indexId) return undefined;
16827
+ return (_options_instantSearchInstance_renderState_indexId = options.instantSearchInstance.renderState[indexId]) === null || _options_instantSearchInstance_renderState_indexId === void 0 ? void 0 : _options_instantSearchInstance_renderState_indexId.chat;
16828
+ }
16829
+ /**
16830
+ * Compare connector.
16831
+ *
16832
+ * Owns the "products selected for comparison" state and the hand-off into the
16833
+ * chat: `compare()` opens the sibling `chat` widget and sends a comparison
16834
+ * message naming the selected records, which the agent answers with the
16835
+ * grounded `algolia_compare_products` table.
16836
+ *
16837
+ * The selection is shared across all `compare` widgets mounted on the same
16838
+ * InstantSearch instance, so per-hit "Compare" toggles and the `compareBar`
16839
+ * widget stay in sync. The widget is marked with `opensChat`, so it satisfies
16840
+ * the `chat` widget's entry-point validation.
16841
+ */ var connectCompare = function connectCompare(renderFn) {
16842
+ var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16843
+ checkRendering(renderFn, withUsage$n());
16844
+ return function(widgetParams) {
16845
+ 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() {
16846
+ return getComparisonPlaceholderMessage(configurationId);
16847
+ } : getDefaultComparisonMessage : _ref_getComparisonMessage;
16848
+ if (minItems < 2) {
16849
+ throw new Error(withUsage$n('The `minItems` option must be at least 2.'));
16850
+ }
16851
+ if (maxItems < minItems) {
16852
+ throw new Error(withUsage$n('The `maxItems` option must be greater than `minItems`.'));
16853
+ }
16854
+ var lastOptions = null;
16855
+ var unsubscribe = null;
16856
+ function getStore() {
16857
+ if (!lastOptions) return null;
16858
+ return getCompareStore(lastOptions.instantSearchInstance);
16859
+ }
16860
+ // Re-renders every subscribed `compare` widget, then schedules a full
16861
+ // render so anything else reading `renderState.compare` catches up.
16862
+ function notify(store) {
16863
+ store.listeners.forEach(function(listener) {
16864
+ return listener();
16865
+ });
16866
+ lastOptions === null || lastOptions === void 0 ? void 0 : lastOptions.instantSearchInstance.scheduleRender();
16867
+ }
16868
+ function isSelected(objectID) {
16869
+ var store = getStore();
16870
+ return Boolean(store === null || store === void 0 ? void 0 : store.items.some(function(item) {
16871
+ return item.objectID === objectID;
16872
+ }));
16873
+ }
16874
+ function addItem(item) {
16875
+ var store = getStore();
16876
+ if (!store || store.items.length >= maxItems || isSelected(item.objectID)) {
16877
+ return;
16878
+ }
16879
+ store.items = _to_consumable_array(store.items).concat([
16880
+ item
16881
+ ]);
16882
+ notify(store);
16883
+ }
16884
+ function removeItem(objectID) {
16885
+ var store = getStore();
16886
+ if (!store || !isSelected(objectID)) return;
16887
+ store.items = store.items.filter(function(item) {
16888
+ return item.objectID !== objectID;
16889
+ });
16890
+ notify(store);
16891
+ }
16892
+ function toggleItem(item) {
16893
+ if (isSelected(item.objectID)) {
16894
+ removeItem(item.objectID);
16895
+ } else {
16896
+ addItem(item);
16897
+ }
16898
+ }
16899
+ function clearItems() {
16900
+ var store = getStore();
16901
+ if (!store || store.items.length === 0) return;
16902
+ store.items = [];
16903
+ notify(store);
16904
+ }
16905
+ function compare() {
16906
+ var store = getStore();
16907
+ if (!store || !lastOptions || store.items.length < minItems) {
16908
+ return false;
16909
+ }
16910
+ return openChat(getChatRenderState(lastOptions), {
16911
+ message: getComparisonMessage(store.items),
16912
+ referer: 'compare',
16913
+ turnContext: buildComparisonTurnContext(store.items, configurationId)
16914
+ });
16915
+ }
16916
+ return {
16917
+ $$type: 'ais.compare',
16918
+ opensChat: true,
16919
+ init: function init(initOptions) {
16920
+ var _this = this;
16921
+ lastOptions = initOptions;
16922
+ var store = getCompareStore(initOptions.instantSearchInstance);
16923
+ var listener = function listener() {
16924
+ if (!lastOptions) return;
16925
+ renderFn(_object_spread_props(_object_spread({}, _this.getWidgetRenderState(lastOptions)), {
16926
+ instantSearchInstance: lastOptions.instantSearchInstance
16927
+ }), false);
16928
+ };
16929
+ store.listeners.add(listener);
16930
+ unsubscribe = function unsubscribe() {
16931
+ return store.listeners.delete(listener);
16932
+ };
16933
+ renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
16934
+ instantSearchInstance: initOptions.instantSearchInstance
16935
+ }), true);
16936
+ },
16937
+ render: function render(renderOptions) {
16938
+ lastOptions = renderOptions;
16939
+ renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(renderOptions)), {
16940
+ instantSearchInstance: renderOptions.instantSearchInstance
16941
+ }), false);
16942
+ },
16943
+ dispose: function dispose() {
16944
+ unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe();
16945
+ unsubscribe = null;
16946
+ unmountFn();
16947
+ },
16948
+ getWidgetRenderState: function getWidgetRenderState(renderOptions) {
16949
+ lastOptions = renderOptions;
16950
+ var store = getCompareStore(renderOptions.instantSearchInstance);
16951
+ return {
16952
+ items: store.items,
16953
+ isSelected: isSelected,
16954
+ addItem: addItem,
16955
+ removeItem: removeItem,
16956
+ toggleItem: toggleItem,
16957
+ clearItems: clearItems,
16958
+ canAddItems: store.items.length < maxItems,
16959
+ canCompare: store.items.length >= minItems,
16960
+ minItems: minItems,
16961
+ maxItems: maxItems,
16962
+ compare: compare,
16963
+ widgetParams: widgetParams || {}
16964
+ };
16965
+ },
16966
+ getRenderState: function getRenderState(renderState, renderOptions) {
16967
+ return _object_spread_props(_object_spread({}, renderState), {
16968
+ compare: this.getWidgetRenderState(renderOptions)
16969
+ });
16970
+ }
16971
+ };
16972
+ };
16973
+ };
16974
+
16975
+ /**
16976
+ * Exposes the shared comparison selection and the chat hand-off.
16977
+ *
16978
+ * The selection is shared by every `useCompare` call on the same InstantSearch
16979
+ * instance, so a per-hit "Compare" toggle (`toggleItem`) and the `<CompareBar>`
16980
+ * widget stay in sync. `compare()` opens the `<Chat>` widget and sends the
16981
+ * comparison message for the current selection.
16982
+ */ function useCompare() {
16983
+ var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, additionalWidgetProperties = arguments.length > 1 ? arguments[1] : void 0;
16984
+ return useConnector(connectCompare, props, additionalWidgetProperties);
16985
+ }
16986
+
16781
16987
  var withUsage$m = createDocumentationMessageGenerator({
16782
16988
  name: 'clear-refinements',
16783
16989
  connector: true
@@ -20926,6 +21132,7 @@
20926
21132
  exports.useChat = useChat;
20927
21133
  exports.useChatTrigger = useChatTrigger;
20928
21134
  exports.useClearRefinements = useClearRefinements;
21135
+ exports.useCompare = useCompare;
20929
21136
  exports.useConfigure = useConfigure;
20930
21137
  exports.useConnector = useConnector;
20931
21138
  exports.useCurrentRefinements = useCurrentRefinements;