react-instantsearch 7.39.0 → 7.40.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.
@@ -215,14 +215,15 @@ function EXPERIMENTAL_Autocomplete(props) {
215
215
  var indices = 'indices' in props ? props.indices : undefined;
216
216
  var feeds = 'feeds' in props ? props.feeds : undefined;
217
217
  var isFeedsMode = feeds !== undefined;
218
- var showQuerySuggestions = props.showQuerySuggestions, showPromptSuggestions = props.showPromptSuggestions, showRecent = props.showRecent, userSearchParameters = props.searchParameters, detachedMediaQuery = props.detachedMediaQuery, tmp = props.translations, userTranslations = tmp === void 0 ? {} : tmp, transformItems = props.transformItems, restProps = _object_without_properties._(props, [
218
+ var showQuerySuggestions = props.showQuerySuggestions, showPromptSuggestions = props.showPromptSuggestions, showRecent = props.showRecent, userSearchParameters = props.searchParameters, detachedMediaQuery = props.detachedMediaQuery, tmp = props.translations, userTranslations = tmp === void 0 ? {} : tmp, transformItems = props.transformItems, _props_requiresSearch = props.requiresSearch, requiresSearch = _props_requiresSearch === void 0 ? true : _props_requiresSearch, restProps = _object_without_properties._(props, [
219
219
  "showQuerySuggestions",
220
220
  "showPromptSuggestions",
221
221
  "showRecent",
222
222
  "searchParameters",
223
223
  "detachedMediaQuery",
224
224
  "translations",
225
- "transformItems"
225
+ "transformItems",
226
+ "requiresSearch"
226
227
  ]);
227
228
  var autoFocus = restProps.autoFocus, placeholder = restProps.placeholder, classNames = restProps.classNames;
228
229
  // Eager-mount only when `autoFocus` is set — otherwise wait for first focus
@@ -231,9 +232,11 @@ function EXPERIMENTAL_Autocomplete(props) {
231
232
  var translations = _object_spread._({}, DEFAULT_TRANSLATIONS, userTranslations);
232
233
  var _useInstantSearch = (0, _reactinstantsearchcore.useInstantSearch)(), indexUiState = _useInstantSearch.indexUiState, indexRenderState = _useInstantSearch.indexRenderState, status = _useInstantSearch.status;
233
234
  var compositionID = (0, _reactinstantsearchcore.useInstantSearchContext)().compositionID;
235
+ var dependsOn = requiresSearch ? 'search' : 'none';
234
236
  var refine = (0, _reactinstantsearchcore.useSearchBox)({}, _object_spread._({
235
237
  $$type: 'ais.autocomplete',
236
- $$widgetType: 'ais.autocomplete'
238
+ $$widgetType: 'ais.autocomplete',
239
+ dependsOn: dependsOn
237
240
  }, props.aiMode ? {
238
241
  opensChat: true
239
242
  } : {})).refine;
@@ -92,6 +92,13 @@ type AutocompleteCommonProps<TItem extends BaseHit> = ComponentProps<'div'> & {
92
92
  getSearchPageURL?: (nextUiState: IndexUiState) => string;
93
93
  onSelect?: AutocompleteIndexConfig<TItem>['onSelect'];
94
94
  transformItems?: (indices: TransformItemsIndicesConfig[]) => TransformItemsIndicesConfig[];
95
+ /**
96
+ * Whether this widget should make InstantSearch require a main search request.
97
+ * If this is the only widget, and you mark `requiresSearch: false`, no search request will happen.
98
+ *
99
+ * @default true
100
+ */
101
+ requiresSearch?: boolean;
95
102
  panelComponent?: (props: {
96
103
  elements: PanelElements;
97
104
  indices: ReturnType<typeof useAutocomplete>['indices'];
@@ -204,14 +204,15 @@ function EXPERIMENTAL_Autocomplete(props) {
204
204
  var indices = 'indices' in props ? props.indices : undefined;
205
205
  var feeds = 'feeds' in props ? props.feeds : undefined;
206
206
  var isFeedsMode = feeds !== undefined;
207
- var showQuerySuggestions = props.showQuerySuggestions, showPromptSuggestions = props.showPromptSuggestions, showRecent = props.showRecent, userSearchParameters = props.searchParameters, detachedMediaQuery = props.detachedMediaQuery, tmp = props.translations, userTranslations = tmp === void 0 ? {} : tmp, transformItems = props.transformItems, restProps = _(props, [
207
+ var showQuerySuggestions = props.showQuerySuggestions, showPromptSuggestions = props.showPromptSuggestions, showRecent = props.showRecent, userSearchParameters = props.searchParameters, detachedMediaQuery = props.detachedMediaQuery, tmp = props.translations, userTranslations = tmp === void 0 ? {} : tmp, transformItems = props.transformItems, _props_requiresSearch = props.requiresSearch, requiresSearch = _props_requiresSearch === void 0 ? true : _props_requiresSearch, restProps = _(props, [
208
208
  "showQuerySuggestions",
209
209
  "showPromptSuggestions",
210
210
  "showRecent",
211
211
  "searchParameters",
212
212
  "detachedMediaQuery",
213
213
  "translations",
214
- "transformItems"
214
+ "transformItems",
215
+ "requiresSearch"
215
216
  ]);
216
217
  var autoFocus = restProps.autoFocus, placeholder = restProps.placeholder, classNames = restProps.classNames;
217
218
  // Eager-mount only when `autoFocus` is set — otherwise wait for first focus
@@ -220,9 +221,11 @@ function EXPERIMENTAL_Autocomplete(props) {
220
221
  var translations = _$2({}, DEFAULT_TRANSLATIONS, userTranslations);
221
222
  var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, indexRenderState = _useInstantSearch.indexRenderState, status = _useInstantSearch.status;
222
223
  var compositionID = useInstantSearchContext().compositionID;
224
+ var dependsOn = requiresSearch ? 'search' : 'none';
223
225
  var refine = useSearchBox({}, _$2({
224
226
  $$type: 'ais.autocomplete',
225
- $$widgetType: 'ais.autocomplete'
227
+ $$widgetType: 'ais.autocomplete',
228
+ dependsOn: dependsOn
226
229
  }, props.aiMode ? {
227
230
  opensChat: true
228
231
  } : {})).refine;
@@ -1,4 +1,4 @@
1
- /*! React InstantSearch 7.39.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! React InstantSearch 7.40.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.39.0';
27
+ var version$2 = '7.40.0';
28
28
 
29
29
  function _define_property(obj, key, value) {
30
30
  if (key in obj) {
@@ -7520,6 +7520,9 @@
7520
7520
  current: 0
7521
7521
  },
7522
7522
  waitForResultsRef: null,
7523
+ resolveWaitForResultsRef: {
7524
+ current: null
7525
+ },
7523
7526
  ignoreMultipleHooksWarning: false
7524
7527
  });
7525
7528
 
@@ -7731,7 +7734,10 @@
7731
7734
  useWidget({
7732
7735
  widget: widget,
7733
7736
  parentIndex: parentIndex,
7734
- props: stableProps,
7737
+ props: [
7738
+ stableProps,
7739
+ stableAdditionalWidgetProperties
7740
+ ],
7735
7741
  shouldSsr: Boolean(serverContext),
7736
7742
  skipSuspense: skipSuspense
7737
7743
  });
@@ -8467,6 +8473,39 @@
8467
8473
  ].concat(_to_consumable_array(resolveScopedResultsFromWidgets(current.getWidgets()))));
8468
8474
  }, []);
8469
8475
  }
8476
+ function getWidgetsRequestDependencies(widgets) {
8477
+ return widgets.reduce(function(dependencies, widget) {
8478
+ if (isIndexWidget(widget)) {
8479
+ if (widget._isolated) {
8480
+ return dependencies;
8481
+ }
8482
+ var childDependencies = getWidgetsRequestDependencies(widget.getWidgets());
8483
+ return {
8484
+ hasSearchWidget: dependencies.hasSearchWidget || childDependencies.hasSearchWidget,
8485
+ hasRecommendWidget: dependencies.hasRecommendWidget || childDependencies.hasRecommendWidget
8486
+ };
8487
+ }
8488
+ if (widget.dependsOn === 'recommend') {
8489
+ return _object_spread_props(_object_spread({}, dependencies), {
8490
+ hasRecommendWidget: true
8491
+ });
8492
+ }
8493
+ if (widget.dependsOn === 'none') {
8494
+ return dependencies;
8495
+ }
8496
+ return _object_spread_props(_object_spread({}, dependencies), {
8497
+ hasSearchWidget: true
8498
+ });
8499
+ }, {
8500
+ hasSearchWidget: false,
8501
+ hasRecommendWidget: false
8502
+ });
8503
+ }
8504
+ function recomputeInstantSearchRequestDependencies(instantSearchInstance) {
8505
+ var _getWidgetsRequestDependencies = getWidgetsRequestDependencies(instantSearchInstance.mainIndex.getWidgets()), hasSearchWidget = _getWidgetsRequestDependencies.hasSearchWidget, hasRecommendWidget = _getWidgetsRequestDependencies.hasRecommendWidget;
8506
+ instantSearchInstance._hasSearchWidget = hasSearchWidget;
8507
+ instantSearchInstance._hasRecommendWidget = hasRecommendWidget;
8508
+ }
8470
8509
  var index = function index(widgetParams) {
8471
8510
  if (widgetParams === undefined || widgetParams.indexName === undefined && !widgetParams.EXPERIMENTAL_isolated) {
8472
8511
  throw new Error(withUsage$s('The `indexName` option is required.'));
@@ -8481,8 +8520,11 @@
8481
8520
  var helper = null;
8482
8521
  var derivedHelper = null;
8483
8522
  var lastValidSearchParameters = null;
8484
- var hasRecommendWidget = false;
8485
- var hasSearchWidget = false;
8523
+ var recomputeLocalRequestDependencies = function recomputeLocalRequestDependencies() {
8524
+ if (localInstantSearchInstance) {
8525
+ recomputeInstantSearchRequestDependencies(localInstantSearchInstance);
8526
+ }
8527
+ };
8486
8528
  return {
8487
8529
  $$type: 'ais.index',
8488
8530
  $$widgetType: 'ais.index',
@@ -8573,21 +8615,12 @@
8573
8615
  }
8574
8616
  flatWidgets.forEach(function(widget) {
8575
8617
  widget.parent = _this;
8576
- if (isIndexWidget(widget)) {
8577
- return;
8578
- }
8579
- if (localInstantSearchInstance && widget.dependsOn === 'recommend') {
8580
- localInstantSearchInstance._hasRecommendWidget = true;
8581
- } else if (localInstantSearchInstance) {
8582
- localInstantSearchInstance._hasSearchWidget = true;
8583
- } else if (widget.dependsOn === 'recommend') {
8584
- hasRecommendWidget = true;
8585
- } else {
8586
- hasSearchWidget = true;
8618
+ if (!isIndexWidget(widget)) {
8619
+ addWidgetId(widget);
8587
8620
  }
8588
- addWidgetId(widget);
8589
8621
  });
8590
8622
  localWidgets = localWidgets.concat(flatWidgets);
8623
+ recomputeLocalRequestDependencies();
8591
8624
  if (localInstantSearchInstance && Boolean(flatWidgets.length)) {
8592
8625
  privateHelperSetState(helper, {
8593
8626
  state: getLocalWidgetsSearchParameters(localWidgets, {
@@ -8644,21 +8677,10 @@
8644
8677
  localWidgets = localWidgets.filter(function(widget) {
8645
8678
  return flatWidgets.indexOf(widget) === -1;
8646
8679
  });
8647
- localWidgets.forEach(function(widget) {
8680
+ flatWidgets.forEach(function(widget) {
8648
8681
  widget.parent = undefined;
8649
- if (isIndexWidget(widget)) {
8650
- return;
8651
- }
8652
- if (localInstantSearchInstance && widget.dependsOn === 'recommend') {
8653
- localInstantSearchInstance._hasRecommendWidget = true;
8654
- } else if (localInstantSearchInstance) {
8655
- localInstantSearchInstance._hasSearchWidget = true;
8656
- } else if (widget.dependsOn === 'recommend') {
8657
- hasRecommendWidget = true;
8658
- } else {
8659
- hasSearchWidget = true;
8660
- }
8661
8682
  });
8683
+ recomputeLocalRequestDependencies();
8662
8684
  if (localInstantSearchInstance && Boolean(flatWidgets.length)) {
8663
8685
  var _flatWidgets_reduce = flatWidgets.reduce(function(states, widget) {
8664
8686
  // the `dispose` method exists at this point we already assert it
@@ -8881,12 +8903,7 @@
8881
8903
  // schedule a render that will render the results injected on the helper.
8882
8904
  instantSearchInstance.scheduleRender();
8883
8905
  }
8884
- if (hasRecommendWidget) {
8885
- instantSearchInstance._hasRecommendWidget = true;
8886
- }
8887
- if (hasSearchWidget) {
8888
- instantSearchInstance._hasSearchWidget = true;
8889
- }
8906
+ recomputeLocalRequestDependencies();
8890
8907
  },
8891
8908
  render: function render(param) {
8892
8909
  var _this = this;
@@ -9160,7 +9177,7 @@
9160
9177
  });
9161
9178
  }
9162
9179
 
9163
- var version = '4.105.0';
9180
+ var version = '4.107.0';
9164
9181
 
9165
9182
  var ANONYMOUS_TOKEN_COOKIE_KEY = '_ALGOLIA';
9166
9183
  function getCookie(name) {
@@ -11301,8 +11318,11 @@
11301
11318
  mainHelper.searchForFacetValues = mainHelper.searchForCompositionFacetValues.bind(mainHelper);
11302
11319
  }
11303
11320
  mainHelper.search = function() {
11304
- _this.status = 'loading';
11305
- _this.scheduleRender(false);
11321
+ var hasSearchOrRecommendWidget = _this._hasSearchWidget || _this._hasRecommendWidget;
11322
+ if (hasSearchOrRecommendWidget) {
11323
+ _this.status = 'loading';
11324
+ }
11325
+ _this.scheduleRender(!hasSearchOrRecommendWidget);
11306
11326
  // This solution allows us to keep the exact same API for the users but
11307
11327
  // under the hood, we have a different implementation. It should be
11308
11328
  // completely transparent for the rest of the codebase. Only this module
@@ -11366,7 +11386,7 @@
11366
11386
  error.error = error;
11367
11387
  _this.error = error;
11368
11388
  _this.status = 'error';
11369
- _this.scheduleRender(false);
11389
+ _this.scheduleRender(!_this._hasSearchWidget && !_this._hasRecommendWidget);
11370
11390
  // This needs to execute last because it throws the error.
11371
11391
  _this.emit('error', error);
11372
11392
  });
@@ -12055,10 +12075,14 @@
12055
12075
  return function(widgetParams) {
12056
12076
  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) {
12057
12077
  return indices;
12058
- } : _ref_transformItems, tmp = _ref.future, _ref1 = tmp === void 0 ? {} : tmp, _ref_undefinedEmptyQuery = _ref1.undefinedEmptyQuery, undefinedEmptyQuery = _ref_undefinedEmptyQuery === void 0 ? false : _ref_undefinedEmptyQuery;
12078
+ } : _ref_transformItems, _ref_requiresSearch = _ref.requiresSearch, requiresSearch = _ref_requiresSearch === void 0 ? true : _ref_requiresSearch, tmp = _ref.future, _ref1 = tmp === void 0 ? {} : tmp, _ref_undefinedEmptyQuery = _ref1.undefinedEmptyQuery, undefinedEmptyQuery = _ref_undefinedEmptyQuery === void 0 ? false : _ref_undefinedEmptyQuery;
12059
12079
  var connectorState = {};
12060
12080
  return {
12061
12081
  $$type: 'ais.autocomplete',
12082
+ dependsOn: requiresSearch ? 'search' : 'none',
12083
+ shouldRender: requiresSearch ? undefined : function() {
12084
+ return true;
12085
+ },
12062
12086
  init: function init(initOptions) {
12063
12087
  var instantSearchInstance = initOptions.instantSearchInstance;
12064
12088
  renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
@@ -12557,15 +12581,14 @@
12557
12581
  return Promise.resolve(value);
12558
12582
  }
12559
12583
  /**
12560
- * Error raised when the upstream stream emits a `data-guardrail-violation`
12561
- * chunk. The `message` carries the service-provided `fallbackResponse`, which
12562
- * is intentionally surfaced verbatim through the chat error UI (unlike
12563
- * generic cost-control / 4xx errors, where the raw API message is hidden
12564
- * behind a friendly default).
12584
+ * Error shape for custom chat implementations that still surface a
12585
+ * `data-guardrail-violation` chunk through the error UI. The `message` carries
12586
+ * the service-provided `fallbackResponse`, which is authored for end-user
12587
+ * display.
12565
12588
  *
12566
12589
  * Detection across package boundaries should rely on `error.name` rather than
12567
12590
  * `instanceof` to avoid issues with mixed module copies in bundled apps.
12568
- */ var GuardrailViolationError = /*#__PURE__*/ function(Error1) {
12591
+ */ /*#__PURE__*/ (function(Error1) {
12569
12592
  _inherits(GuardrailViolationError, Error1);
12570
12593
  function GuardrailViolationError(message) {
12571
12594
  _class_call_check(this, GuardrailViolationError);
@@ -12577,7 +12600,7 @@
12577
12600
  return _this;
12578
12601
  }
12579
12602
  return GuardrailViolationError;
12580
- }(_wrap_native_super(Error));
12603
+ })(_wrap_native_super(Error));
12581
12604
  /**
12582
12605
  * Reads a non-empty `message` field off a JSON-serialized error envelope.
12583
12606
  *
@@ -12669,6 +12692,7 @@
12669
12692
  }
12670
12693
  return fallbackInput;
12671
12694
  };
12695
+ var defaultGuardrailFallbackResponse = 'Sorry, we are not able to generate a response at the moment.';
12672
12696
  /**
12673
12697
  * Abstract base class for chat implementations.
12674
12698
  */ var AbstractChat = /*#__PURE__*/ function() {
@@ -13495,28 +13519,37 @@
13495
13519
  }
13496
13520
  break;
13497
13521
  }
13498
- // Surface guardrail violations through the error state, but
13499
- // distinct from generic cost-control / 4xx errors: throw a
13500
- // `GuardrailViolationError` so the UI can render the
13501
- // service-provided `fallbackResponse` verbatim (it's authored for
13502
- // end-user display) instead of the friendly default used for
13503
- // opaque transport errors. Also discard any in-progress assistant
13504
- // message so no partial text lingers above the fallback, and
13505
- // clear the local cursor so the `onFinish` callback doesn't
13506
- // receive a `currentMessage` that no longer exists in state.
13507
13522
  case 'data-guardrail-violation':
13508
13523
  {
13509
- isError = true;
13510
- if (currentMessageIndex >= 0) {
13511
- _this.state.messages = _this.state.messages.slice(0, currentMessageIndex);
13512
- currentMessage = undefined;
13513
- currentMessageIndex = -1;
13514
- }
13515
13524
  // `chunk.data` widens to `unknown` here: the chunk union also
13516
13525
  // carries a generic `data-${string}` member, and the literal
13517
13526
  // matches both, so narrowing can't pick the specific shape.
13518
13527
  var fallbackResponse = chunk.data.fallbackResponse;
13519
- throw new GuardrailViolationError(fallbackResponse || 'Sorry, we are not able to generate a response at the moment.');
13528
+ var fallbackText = fallbackResponse || defaultGuardrailFallbackResponse;
13529
+ // The stream closes after a guardrail violation; keep the
13530
+ // fallback as the current message so the normal finish path runs.
13531
+ currentMessage = {
13532
+ id: (currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.id) || currentMessageId || _this.generateId(),
13533
+ role: 'assistant',
13534
+ metadata: currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.metadata,
13535
+ parts: [
13536
+ {
13537
+ type: 'text',
13538
+ text: fallbackText,
13539
+ state: 'done'
13540
+ }
13541
+ ]
13542
+ };
13543
+ if (currentMessageIndex >= 0) {
13544
+ _this.state.replaceMessage(currentMessageIndex, currentMessage);
13545
+ } else {
13546
+ _this.state.pushMessage(currentMessage);
13547
+ currentMessageIndex = _this.state.messages.length - 1;
13548
+ }
13549
+ currentMessageId = currentMessage.id;
13550
+ currentTextPartId = undefined;
13551
+ currentReasoningPartId = undefined;
13552
+ break;
13520
13553
  }
13521
13554
  default:
13522
13555
  {
@@ -13651,7 +13684,7 @@
13651
13684
  var ChatState = /*#__PURE__*/ function() {
13652
13685
  function ChatState() {
13653
13686
  var _this = this;
13654
- var id = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : undefined, initialMessages = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : getDefaultInitialMessages(id);
13687
+ var id = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : undefined, initialMessages = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : undefined, persistence = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
13655
13688
  _class_call_check(this, ChatState);
13656
13689
  _define_property(this, "_messages", void 0);
13657
13690
  _define_property(this, "_status", 'ready');
@@ -13711,7 +13744,16 @@
13711
13744
  return callback();
13712
13745
  });
13713
13746
  });
13714
- this._messages = initialMessages;
13747
+ if (initialMessages !== undefined) {
13748
+ this._messages = initialMessages;
13749
+ } else if (persistence) {
13750
+ this._messages = getDefaultInitialMessages(id);
13751
+ } else {
13752
+ this._messages = [];
13753
+ }
13754
+ if (!persistence) {
13755
+ return;
13756
+ }
13715
13757
  var saveMessagesInLocalStorage = function saveMessagesInLocalStorage() {
13716
13758
  if (_this.status === 'ready') {
13717
13759
  try {
@@ -13765,11 +13807,12 @@
13765
13807
  function Chat(_0) {
13766
13808
  _class_call_check(this, Chat);
13767
13809
  var _this;
13768
- var messages = _0.messages, agentId = _0.agentId, init = _object_without_properties(_0, [
13810
+ var messages = _0.messages, agentId = _0.agentId, _0_persistence = _0.persistence, persistence = _0_persistence === void 0 ? true : _0_persistence, init = _object_without_properties(_0, [
13769
13811
  "messages",
13770
- "agentId"
13812
+ "agentId",
13813
+ "persistence"
13771
13814
  ]);
13772
- var state = new ChatState(agentId, messages);
13815
+ var state = new ChatState(agentId, messages, persistence);
13773
13816
  _this = _call_super(this, Chat, [
13774
13817
  _object_spread_props(_object_spread({}, init), {
13775
13818
  state: state
@@ -14078,14 +14121,16 @@
14078
14121
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14079
14122
  checkRendering(renderFn, withUsage$o());
14080
14123
  return function(widgetParams) {
14081
- var _ref = widgetParams || {}, _ref_resume = _ref.resume, resume = _ref_resume === void 0 ? false : _ref_resume, _ref_tools = _ref.tools, tools = _ref_tools === void 0 ? {} : _ref_tools, _ref_type = _ref.type, type = _ref_type === void 0 ? 'chat' : _ref_type, context = _ref.context, initialUserMessage = _ref.initialUserMessage, initialMessages = _ref.initialMessages, _ref_disableTriggerValidation = _ref.disableTriggerValidation, disableTriggerValidation = _ref_disableTriggerValidation === void 0 ? false : _ref_disableTriggerValidation, options = _object_without_properties(_ref, [
14124
+ var _ref = widgetParams || {}, _ref_resume = _ref.resume, resume = _ref_resume === void 0 ? false : _ref_resume, _ref_tools = _ref.tools, tools = _ref_tools === void 0 ? {} : _ref_tools, _ref_type = _ref.type, type = _ref_type === void 0 ? 'chat' : _ref_type, 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, [
14082
14125
  "resume",
14083
14126
  "tools",
14084
14127
  "type",
14085
14128
  "context",
14086
14129
  "initialUserMessage",
14087
14130
  "initialMessages",
14088
- "disableTriggerValidation"
14131
+ "disableTriggerValidation",
14132
+ "sendAutomaticallyWhen",
14133
+ "requiresSearch"
14089
14134
  ]);
14090
14135
  var _chatInstance;
14091
14136
  var input = '';
@@ -14246,8 +14291,8 @@
14246
14291
  return options.chat;
14247
14292
  }
14248
14293
  return new Chat$1(_object_spread_props(_object_spread({}, options), {
14294
+ sendAutomaticallyWhen: sendAutomaticallyWhen,
14249
14295
  transport: transport,
14250
- sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls,
14251
14296
  shouldRepairToolInput: function shouldRepairToolInput(toolName) {
14252
14297
  var tool = tools[toolName];
14253
14298
  if (!tool && toolName.startsWith("".concat(SearchIndexToolType$2, "_"))) {
@@ -14289,6 +14334,7 @@
14289
14334
  };
14290
14335
  return {
14291
14336
  $$type: 'ais.chat',
14337
+ dependsOn: requiresSearch ? 'search' : 'none',
14292
14338
  init: function init(initOptions) {
14293
14339
  var _this = this;
14294
14340
  var instantSearchInstance = initOptions.instantSearchInstance;
@@ -14501,6 +14547,7 @@
14501
14547
  return {
14502
14548
  $$type: 'ais.chatTrigger',
14503
14549
  opensChat: true,
14550
+ dependsOn: 'none',
14504
14551
  init: function init(initOptions) {
14505
14552
  lastOptions = initOptions;
14506
14553
  renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
@@ -14529,6 +14576,9 @@
14529
14576
  return _object_spread_props(_object_spread({}, renderState), {
14530
14577
  chatTrigger: this.getWidgetRenderState(renderOptions)
14531
14578
  });
14579
+ },
14580
+ shouldRender: function shouldRender() {
14581
+ return true;
14532
14582
  }
14533
14583
  };
14534
14584
  };
@@ -18469,6 +18519,8 @@
18469
18519
  // later during hydration.
18470
18520
  var requestParamsList;
18471
18521
  var client = helper.getClient();
18522
+ var waitsForSearch = search._hasSearchWidget;
18523
+ var waitsForRecommend = !skipRecommend && search._hasRecommendWidget;
18472
18524
  if (search.compositionID) {
18473
18525
  helper.setClient(_object_spread_props(_object_spread({}, client), {
18474
18526
  search: function search(query) {
@@ -18489,17 +18541,22 @@
18489
18541
  }
18490
18542
  }));
18491
18543
  }
18492
- if (search._hasSearchWidget) {
18544
+ if (waitsForSearch) {
18493
18545
  if (search.compositionID) {
18494
18546
  helper.searchWithComposition();
18495
18547
  } else {
18496
18548
  helper.searchOnlyWithDerivedHelpers();
18497
18549
  }
18498
18550
  }
18499
- !skipRecommend && search._hasRecommendWidget && helper.recommend();
18551
+ if (waitsForRecommend) {
18552
+ helper.recommend();
18553
+ }
18554
+ if (!waitsForSearch && !waitsForRecommend) {
18555
+ return Promise.resolve([]);
18556
+ }
18500
18557
  return new Promise(function(resolve, reject) {
18501
- var searchResultsReceived = !search._hasSearchWidget;
18502
- var recommendResultsReceived = !search._hasRecommendWidget || skipRecommend;
18558
+ var searchResultsReceived = !waitsForSearch;
18559
+ var recommendResultsReceived = !waitsForRecommend;
18503
18560
  // All derived helpers resolve in the same tick so we're safe only relying
18504
18561
  // on the first one.
18505
18562
  helper.derivedHelpers[0].on('result', function() {
@@ -18539,6 +18596,13 @@
18539
18596
  var requestParamsIndex = 0;
18540
18597
  walkIndex(rootIndex, function(widget) {
18541
18598
  var _widget_getHelper;
18599
+ var currentIndex = widget;
18600
+ while(currentIndex){
18601
+ if (currentIndex._isolated) {
18602
+ return;
18603
+ }
18604
+ currentIndex = currentIndex.getParent();
18605
+ }
18542
18606
  var searchResults = widget.getResults();
18543
18607
  var recommendResults = (_widget_getHelper = widget.getHelper()) === null || _widget_getHelper === void 0 ? void 0 : _widget_getHelper.lastRecommendResults;
18544
18608
  if (searchResults || recommendResults) {
@@ -18569,7 +18633,7 @@
18569
18633
  });
18570
18634
  }
18571
18635
  });
18572
- if (Object.keys(initialResults).length === 0) {
18636
+ if (Object.keys(initialResults).length === 0 && (requestParamsList === null || requestParamsList === void 0 ? void 0 : requestParamsList.length) !== 0) {
18573
18637
  throw new Error('The root index does not have any results. Make sure you have at least one widget that provides results.');
18574
18638
  }
18575
18639
  return initialResults;
@@ -18604,6 +18668,13 @@
18604
18668
  var shouldRefetch = false;
18605
18669
  // Two-pass widgets require another query to discover and mount child widgets.
18606
18670
  walkIndex(searchRef.current.mainIndex, function(index) {
18671
+ var current = index;
18672
+ while(current){
18673
+ if (current._isolated) {
18674
+ return;
18675
+ }
18676
+ current = current.getParent();
18677
+ }
18607
18678
  shouldRefetch = shouldRefetch || index.getWidgets().some(isTwoPassWidget);
18608
18679
  });
18609
18680
  if (shouldRefetch) {
@@ -22700,14 +22771,15 @@
22700
22771
  var indices = 'indices' in props ? props.indices : undefined;
22701
22772
  var feeds = 'feeds' in props ? props.feeds : undefined;
22702
22773
  var isFeedsMode = feeds !== undefined;
22703
- var showQuerySuggestions = props.showQuerySuggestions, showPromptSuggestions = props.showPromptSuggestions, showRecent = props.showRecent, userSearchParameters = props.searchParameters, detachedMediaQuery = props.detachedMediaQuery, tmp = props.translations, userTranslations = tmp === void 0 ? {} : tmp, transformItems = props.transformItems, restProps = _object_without_properties(props, [
22774
+ var showQuerySuggestions = props.showQuerySuggestions, showPromptSuggestions = props.showPromptSuggestions, showRecent = props.showRecent, userSearchParameters = props.searchParameters, detachedMediaQuery = props.detachedMediaQuery, tmp = props.translations, userTranslations = tmp === void 0 ? {} : tmp, transformItems = props.transformItems, _props_requiresSearch = props.requiresSearch, requiresSearch = _props_requiresSearch === void 0 ? true : _props_requiresSearch, restProps = _object_without_properties(props, [
22704
22775
  "showQuerySuggestions",
22705
22776
  "showPromptSuggestions",
22706
22777
  "showRecent",
22707
22778
  "searchParameters",
22708
22779
  "detachedMediaQuery",
22709
22780
  "translations",
22710
- "transformItems"
22781
+ "transformItems",
22782
+ "requiresSearch"
22711
22783
  ]);
22712
22784
  var autoFocus = restProps.autoFocus, placeholder = restProps.placeholder, classNames = restProps.classNames;
22713
22785
  // Eager-mount only when `autoFocus` is set — otherwise wait for first focus
@@ -22716,9 +22788,11 @@
22716
22788
  var translations = _object_spread({}, DEFAULT_TRANSLATIONS, userTranslations);
22717
22789
  var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, indexRenderState = _useInstantSearch.indexRenderState, status = _useInstantSearch.status;
22718
22790
  var compositionID = useInstantSearchContext().compositionID;
22791
+ var dependsOn = requiresSearch ? 'search' : 'none';
22719
22792
  var refine = useSearchBox({}, _object_spread({
22720
22793
  $$type: 'ais.autocomplete',
22721
- $$widgetType: 'ais.autocomplete'
22794
+ $$widgetType: 'ais.autocomplete',
22795
+ dependsOn: dependsOn
22722
22796
  }, props.aiMode ? {
22723
22797
  opensChat: true
22724
22798
  } : {})).refine;