react-instantsearch 7.33.1 → 7.35.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 7.33.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! React InstantSearch 7.35.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.33.1';
27
+ var version$2 = '7.35.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$u = createDocumentationMessageGenerator({
5983
+ var withUsage$v = 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$u('The `searchParameters` option expects an object.'));
5999
+ throw new Error(withUsage$v('The `searchParameters` option expects an object.'));
6000
6000
  }
6001
6001
  var connectorState = {};
6002
6002
  function refine(helper) {
@@ -7620,13 +7620,13 @@
7620
7620
  return null;
7621
7621
  }
7622
7622
 
7623
- var withUsage$t = createDocumentationMessageGenerator({
7623
+ var withUsage$u = createDocumentationMessageGenerator({
7624
7624
  name: 'dynamic-widgets',
7625
7625
  connector: true
7626
7626
  });
7627
7627
  var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
7628
7628
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
7629
- checkRendering(renderFn, withUsage$t());
7629
+ checkRendering(renderFn, withUsage$u());
7630
7630
  return function(widgetParams) {
7631
7631
  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 ? [
7632
7632
  '*'
@@ -7636,10 +7636,10 @@
7636
7636
  if (!(widgets && Array.isArray(widgets) && widgets.every(function(widget) {
7637
7637
  return (typeof widget === "undefined" ? "undefined" : _type_of(widget)) === 'object';
7638
7638
  }))) {
7639
- throw new Error(withUsage$t('The `widgets` option expects an array of widgets.'));
7639
+ throw new Error(withUsage$u('The `widgets` option expects an array of widgets.'));
7640
7640
  }
7641
7641
  if (!Array.isArray(facets)) {
7642
- throw new Error(withUsage$t("The `facets` option only accepts an array of facets, you passed ".concat(JSON.stringify(facets))));
7642
+ throw new Error(withUsage$u("The `facets` option only accepts an array of facets, you passed ".concat(JSON.stringify(facets))));
7643
7643
  }
7644
7644
  var localWidgets = new Map();
7645
7645
  return {
@@ -7741,7 +7741,7 @@
7741
7741
  results: results
7742
7742
  });
7743
7743
  if (!Array.isArray(attributesToRender)) {
7744
- throw new Error(withUsage$t('The `transformItems` option expects a function that returns an Array.'));
7744
+ throw new Error(withUsage$u('The `transformItems` option expects a function that returns an Array.'));
7745
7745
  }
7746
7746
  return {
7747
7747
  attributesToRender: attributesToRender,
@@ -8062,19 +8062,19 @@
8062
8062
  return toFeedSearchResults(lastResults._state, raw);
8063
8063
  });
8064
8064
  }
8065
- var withUsage$s = createDocumentationMessageGenerator({
8065
+ var withUsage$t = createDocumentationMessageGenerator({
8066
8066
  name: 'feeds',
8067
8067
  connector: true
8068
8068
  });
8069
8069
  var connectFeeds = function connectFeeds(renderFn) {
8070
8070
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
8071
- checkRendering(renderFn, withUsage$s());
8071
+ checkRendering(renderFn, withUsage$t());
8072
8072
  return function(widgetParams) {
8073
8073
  var isolated = widgetParams.isolated, _widgetParams_transformFeeds = widgetParams.transformFeeds, transformFeeds = _widgetParams_transformFeeds === void 0 ? function(feeds) {
8074
8074
  return feeds;
8075
8075
  } : _widgetParams_transformFeeds;
8076
8076
  if (isolated !== false) {
8077
- throw new Error(withUsage$s('The `isolated` option currently only supports `false`.'));
8077
+ throw new Error(withUsage$t('The `isolated` option currently only supports `false`.'));
8078
8078
  }
8079
8079
  return {
8080
8080
  $$type: 'ais.feeds',
@@ -8082,7 +8082,7 @@
8082
8082
  init: function init(initOptions) {
8083
8083
  var instantSearchInstance = initOptions.instantSearchInstance;
8084
8084
  if (!instantSearchInstance.compositionID) {
8085
- throw new Error(withUsage$s('The `feeds` widget requires a composition-based InstantSearch instance (compositionID must be set).'));
8085
+ throw new Error(withUsage$t('The `feeds` widget requires a composition-based InstantSearch instance (compositionID must be set).'));
8086
8086
  }
8087
8087
  hydrateFeedsFromInitialResultsIfNeeded(instantSearchInstance, initOptions.parent);
8088
8088
  renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
@@ -8128,12 +8128,12 @@
8128
8128
  ];
8129
8129
  feedIDs = transformFeeds(feedIDs);
8130
8130
  if (!Array.isArray(feedIDs)) {
8131
- throw new Error(withUsage$s('The `transformFeeds` option expects a function that returns an Array.'));
8131
+ throw new Error(withUsage$t('The `transformFeeds` option expects a function that returns an Array.'));
8132
8132
  }
8133
8133
  if (!feedIDs.every(function(feedID) {
8134
8134
  return typeof feedID === 'string';
8135
8135
  })) {
8136
- throw new Error(withUsage$s('The `transformFeeds` option expects a function that returns an array of feed IDs (strings).'));
8136
+ throw new Error(withUsage$t('The `transformFeeds` option expects a function that returns an array of feed IDs (strings).'));
8137
8137
  }
8138
8138
  return {
8139
8139
  feedIDs: feedIDs,
@@ -8244,7 +8244,7 @@
8244
8244
  }));
8245
8245
  }
8246
8246
 
8247
- var withUsage$r = createDocumentationMessageGenerator({
8247
+ var withUsage$s = createDocumentationMessageGenerator({
8248
8248
  name: 'index-widget'
8249
8249
  });
8250
8250
  /**
@@ -8338,7 +8338,7 @@
8338
8338
  }
8339
8339
  var index = function index(widgetParams) {
8340
8340
  if (widgetParams === undefined || widgetParams.indexName === undefined && !widgetParams.EXPERIMENTAL_isolated) {
8341
- throw new Error(withUsage$r('The `indexName` option is required.'));
8341
+ throw new Error(withUsage$s('The `indexName` option is required.'));
8342
8342
  }
8343
8343
  // When isolated=true, we use an empty string as the default indexName.
8344
8344
  // This is intentional: isolated indices do not require a real index name.
@@ -8428,7 +8428,7 @@
8428
8428
  addWidgets: function addWidgets(widgets) {
8429
8429
  var _this = this;
8430
8430
  if (!Array.isArray(widgets)) {
8431
- throw new Error(withUsage$r('The `addWidgets` method expects an array of widgets.'));
8431
+ throw new Error(withUsage$s('The `addWidgets` method expects an array of widgets.'));
8432
8432
  }
8433
8433
  var flatWidgets = widgets.reduce(function(acc, w) {
8434
8434
  return acc.concat(Array.isArray(w) ? w : [
@@ -8438,7 +8438,7 @@
8438
8438
  if (flatWidgets.some(function(widget) {
8439
8439
  return typeof widget.init !== 'function' && typeof widget.render !== 'function';
8440
8440
  })) {
8441
- throw new Error(withUsage$r('The widget definition expects a `render` and/or an `init` method.'));
8441
+ throw new Error(withUsage$s('The widget definition expects a `render` and/or an `init` method.'));
8442
8442
  }
8443
8443
  flatWidgets.forEach(function(widget) {
8444
8444
  widget.parent = _this;
@@ -8498,7 +8498,7 @@
8498
8498
  removeWidgets: function removeWidgets(widgets) {
8499
8499
  var _this = this;
8500
8500
  if (!Array.isArray(widgets)) {
8501
- throw new Error(withUsage$r('The `removeWidgets` method expects an array of widgets.'));
8501
+ throw new Error(withUsage$s('The `removeWidgets` method expects an array of widgets.'));
8502
8502
  }
8503
8503
  var flatWidgets = widgets.reduce(function(acc, w) {
8504
8504
  return acc.concat(Array.isArray(w) ? w : [
@@ -8508,7 +8508,7 @@
8508
8508
  if (flatWidgets.some(function(widget) {
8509
8509
  return typeof widget.dispose !== 'function';
8510
8510
  })) {
8511
- throw new Error(withUsage$r('The widget definition expects a `dispose` method.'));
8511
+ throw new Error(withUsage$s('The widget definition expects a `dispose` method.'));
8512
8512
  }
8513
8513
  localWidgets = localWidgets.filter(function(widget) {
8514
8514
  return flatWidgets.indexOf(widget) === -1;
@@ -10821,9 +10821,9 @@
10821
10821
  };
10822
10822
  }
10823
10823
 
10824
- var version = '4.99.0';
10824
+ var version = '4.101.0';
10825
10825
 
10826
- var withUsage$q = createDocumentationMessageGenerator({
10826
+ var withUsage$r = createDocumentationMessageGenerator({
10827
10827
  name: 'instantsearch'
10828
10828
  });
10829
10829
  function defaultCreateURL() {
@@ -10879,7 +10879,7 @@
10879
10879
  _this.setMaxListeners(100);
10880
10880
  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;
10881
10881
  if (searchClient === null) {
10882
- throw new Error(withUsage$q('The `searchClient` option is required.'));
10882
+ throw new Error(withUsage$r('The `searchClient` option is required.'));
10883
10883
  }
10884
10884
  if (typeof searchClient.search !== 'function') {
10885
10885
  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/");
@@ -10888,7 +10888,7 @@
10888
10888
  searchClient.addAlgoliaAgent("instantsearch.js (".concat(version, ")"));
10889
10889
  }
10890
10890
  if (insightsClient && typeof insightsClient !== 'function') {
10891
- throw new Error(withUsage$q('The `insightsClient` option should be a function.'));
10891
+ throw new Error(withUsage$r('The `insightsClient` option should be a function.'));
10892
10892
  }
10893
10893
  _this.client = searchClient;
10894
10894
  _this.future = future;
@@ -11036,12 +11036,12 @@
11036
11036
  * @param widgets The array of widgets to add to InstantSearch.
11037
11037
  */ function addWidgets(widgets) {
11038
11038
  if (!Array.isArray(widgets)) {
11039
- throw new Error(withUsage$q('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
11039
+ throw new Error(withUsage$r('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
11040
11040
  }
11041
11041
  if (this.compositionID && widgets.some(function(w) {
11042
11042
  return !Array.isArray(w) && isIndexWidget(w) && !w._isolated;
11043
11043
  })) {
11044
- throw new Error(withUsage$q('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
11044
+ throw new Error(withUsage$r('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
11045
11045
  }
11046
11046
  this.mainIndex.addWidgets(widgets);
11047
11047
  return this;
@@ -11070,7 +11070,7 @@
11070
11070
  * The widgets must implement a `dispose()` method to clear their states.
11071
11071
  */ function removeWidgets(widgets) {
11072
11072
  if (!Array.isArray(widgets)) {
11073
- throw new Error(withUsage$q('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
11073
+ throw new Error(withUsage$r('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
11074
11074
  }
11075
11075
  this.mainIndex.removeWidgets(widgets);
11076
11076
  return this;
@@ -11084,7 +11084,7 @@
11084
11084
  */ function start() {
11085
11085
  var _this = this;
11086
11086
  if (this.started) {
11087
- throw new Error(withUsage$q('The `start` method has already been called once.'));
11087
+ throw new Error(withUsage$r('The `start` method has already been called once.'));
11088
11088
  }
11089
11089
  // This Helper is used for the queries, we don't care about its state. The
11090
11090
  // states are managed at the `index` level. We use this Helper to create
@@ -11286,7 +11286,7 @@
11286
11286
  var _this = this;
11287
11287
  var callOnStateChange = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
11288
11288
  if (!this.mainHelper) {
11289
- throw new Error(withUsage$q('The `start` method needs to be called before `setUiState`.'));
11289
+ throw new Error(withUsage$r('The `start` method needs to be called before `setUiState`.'));
11290
11290
  }
11291
11291
  // We refresh the index UI state to update the local UI state that the
11292
11292
  // main index passes to the function form of `setUiState`.
@@ -11323,7 +11323,7 @@
11323
11323
  value: function createURL() {
11324
11324
  var nextState = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
11325
11325
  if (!this.started) {
11326
- throw new Error(withUsage$q('The `start` method needs to be called before `createURL`.'));
11326
+ throw new Error(withUsage$r('The `start` method needs to be called before `createURL`.'));
11327
11327
  }
11328
11328
  return this._createURL(nextState);
11329
11329
  }
@@ -11332,7 +11332,7 @@
11332
11332
  key: "refresh",
11333
11333
  value: function refresh() {
11334
11334
  if (!this.mainHelper) {
11335
- throw new Error(withUsage$q('The `start` method needs to be called before `refresh`.'));
11335
+ throw new Error(withUsage$r('The `start` method needs to be called before `refresh`.'));
11336
11336
  }
11337
11337
  this.mainHelper.clearCache().search();
11338
11338
  }
@@ -11839,13 +11839,13 @@
11839
11839
  }, children);
11840
11840
  }
11841
11841
 
11842
- var withUsage$p = createDocumentationMessageGenerator({
11842
+ var withUsage$q = createDocumentationMessageGenerator({
11843
11843
  name: 'autocomplete',
11844
11844
  connector: true
11845
11845
  });
11846
11846
  var connectAutocomplete = function connectAutocomplete(renderFn) {
11847
11847
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
11848
- checkRendering(renderFn, withUsage$p());
11848
+ checkRendering(renderFn, withUsage$q());
11849
11849
  return function(widgetParams) {
11850
11850
  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) {
11851
11851
  return indices;
@@ -11954,20 +11954,20 @@
11954
11954
  return useConnector(connectAutocomplete, props, additionalWidgetProperties);
11955
11955
  }
11956
11956
 
11957
- var withUsage$o = createDocumentationMessageGenerator({
11957
+ var withUsage$p = createDocumentationMessageGenerator({
11958
11958
  name: 'breadcrumb',
11959
11959
  connector: true
11960
11960
  });
11961
11961
  var connectBreadcrumb = function connectBreadcrumb(renderFn) {
11962
11962
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
11963
- checkRendering(renderFn, withUsage$o());
11963
+ checkRendering(renderFn, withUsage$p());
11964
11964
  var connectorState = {};
11965
11965
  return function(widgetParams) {
11966
11966
  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) {
11967
11967
  return items;
11968
11968
  } : _ref_transformItems;
11969
11969
  if (!attributes || !Array.isArray(attributes) || attributes.length === 0) {
11970
- throw new Error(withUsage$o('The `attributes` option expects an array of strings.'));
11970
+ throw new Error(withUsage$p('The `attributes` option expects an array of strings.'));
11971
11971
  }
11972
11972
  var _attributes = _sliced_to_array(attributes, 1), hierarchicalFacetName = _attributes[0];
11973
11973
  function getRefinedState(state, facetValue) {
@@ -12211,16 +12211,21 @@
12211
12211
  onDone();
12212
12212
  return;
12213
12213
  }
12214
- var result = onChunk(value);
12215
- if (result && typeof result.then === 'function') {
12216
- result.then(function() {
12217
- return read();
12218
- }, function(error) {
12219
- reader.releaseLock();
12220
- onError(error);
12221
- });
12222
- } else {
12223
- read();
12214
+ try {
12215
+ var result = onChunk(value);
12216
+ if (result && typeof result.then === 'function') {
12217
+ result.then(function() {
12218
+ return read();
12219
+ }, function(error) {
12220
+ reader.releaseLock();
12221
+ onError(error);
12222
+ });
12223
+ } else {
12224
+ read();
12225
+ }
12226
+ } catch (error) {
12227
+ reader.releaseLock();
12228
+ onError(error);
12224
12229
  }
12225
12230
  }, function(error) {
12226
12231
  reader.releaseLock();
@@ -12230,6 +12235,49 @@
12230
12235
  read();
12231
12236
  }
12232
12237
 
12238
+ function _construct(Parent, args, Class) {
12239
+ if (_is_native_reflect_construct()) _construct = Reflect.construct;
12240
+ else {
12241
+ _construct = function construct(Parent, args, Class) {
12242
+ var a = [null];
12243
+ a.push.apply(a, args);
12244
+ var Constructor = Function.bind.apply(Parent, a);
12245
+ var instance = new Constructor();
12246
+
12247
+ if (Class) _set_prototype_of(instance, Class.prototype);
12248
+
12249
+ return instance;
12250
+ };
12251
+ }
12252
+
12253
+ return _construct.apply(null, arguments);
12254
+ }
12255
+
12256
+ function _is_native_function(fn) {
12257
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
12258
+ }
12259
+
12260
+ function _wrap_native_super(Class) {
12261
+ var _cache = typeof Map === "function" ? new Map() : undefined;
12262
+ _wrap_native_super = function(Class) {
12263
+ if (Class === null || !_is_native_function(Class)) return Class;
12264
+ if (typeof Class !== "function") throw new TypeError("Super expression must either be null or a function");
12265
+ if (typeof _cache !== "undefined") {
12266
+ if (_cache.has(Class)) return _cache.get(Class);
12267
+ _cache.set(Class, Wrapper);
12268
+ }
12269
+
12270
+ function Wrapper() {
12271
+ return _construct(Class, arguments, _get_prototype_of(this).constructor);
12272
+ }
12273
+ Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } });
12274
+
12275
+ return _set_prototype_of(Wrapper, Class);
12276
+ };
12277
+
12278
+ return _wrap_native_super(Class);
12279
+ }
12280
+
12233
12281
  function generateId() {
12234
12282
  return Math.random().toString(36).substring(2, 9);
12235
12283
  }
@@ -12302,6 +12350,49 @@
12302
12350
  }
12303
12351
  return Promise.resolve(value);
12304
12352
  }
12353
+ /**
12354
+ * Error raised when the upstream stream emits a `data-guardrail-violation`
12355
+ * chunk. The `message` carries the service-provided `fallbackResponse`, which
12356
+ * is intentionally surfaced verbatim through the chat error UI (unlike
12357
+ * generic cost-control / 4xx errors, where the raw API message is hidden
12358
+ * behind a friendly default).
12359
+ *
12360
+ * Detection across package boundaries should rely on `error.name` rather than
12361
+ * `instanceof` to avoid issues with mixed module copies in bundled apps.
12362
+ */ var GuardrailViolationError = /*#__PURE__*/ function(Error1) {
12363
+ _inherits(GuardrailViolationError, Error1);
12364
+ function GuardrailViolationError(message) {
12365
+ _class_call_check(this, GuardrailViolationError);
12366
+ var _this;
12367
+ _this = _call_super(this, GuardrailViolationError, [
12368
+ message
12369
+ ]);
12370
+ _this.name = 'GuardrailViolationError';
12371
+ return _this;
12372
+ }
12373
+ return GuardrailViolationError;
12374
+ }(_wrap_native_super(Error));
12375
+ /**
12376
+ * Reads a non-empty `message` field off a JSON-serialized error envelope.
12377
+ *
12378
+ * Both transports backing `AbstractChat` (stream `error` chunks and HTTP error
12379
+ * responses) serialize errors as `{"message": "...", ...}` — the same shape as
12380
+ * the shared `ErrorResponse` on the API side. Returns the trimmed message if
12381
+ * the input is such a JSON object, otherwise `undefined`.
12382
+ */ function tryParseErrorMessage(text) {
12383
+ try {
12384
+ var parsed = JSON.parse(text);
12385
+ if (parsed && (typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) === 'object' && !Array.isArray(parsed) && typeof parsed.message === 'string') {
12386
+ var message = parsed.message.trim();
12387
+ if (message) {
12388
+ return message;
12389
+ }
12390
+ }
12391
+ } catch (unused) {
12392
+ // Not JSON — caller falls back to its own default.
12393
+ }
12394
+ return undefined;
12395
+ }
12305
12396
 
12306
12397
  var tryParseJson = function tryParseJson(value) {
12307
12398
  try {
@@ -12380,7 +12471,7 @@
12380
12471
  var _param_generateId = param.generateId, generateId$1 = _param_generateId === void 0 ? generateId : _param_generateId, _param_id = param.id, id = _param_id === void 0 ? generateId$1() : _param_id, transport = param.transport, state = param.state, onError = param.onError, onToolCall = param.onToolCall, onFinish = param.onFinish, onData = param.onData, sendAutomaticallyWhen = param.sendAutomaticallyWhen, shouldRepairToolInput = param.shouldRepairToolInput;
12381
12472
  var _this1 = this;
12382
12473
  _class_call_check(this, AbstractChat);
12383
- _define_property(this, "id", void 0);
12474
+ _define_property(this, "conversationId", void 0);
12384
12475
  _define_property(this, "generateId", void 0);
12385
12476
  _define_property(this, "state", void 0);
12386
12477
  _define_property(this, "transport", void 0);
@@ -12536,12 +12627,6 @@
12536
12627
  }
12537
12628
  });
12538
12629
  /**
12539
- * Regenerate the chat id. Use this to start a fresh conversation on the
12540
- * server while keeping the same Chat instance and its registered listeners.
12541
- */ _define_property(this, "regenerateId", function() {
12542
- _this.id = _this.generateId();
12543
- });
12544
- /**
12545
12630
  * Add a tool result for a tool call.
12546
12631
  */ _define_property(this, "addToolResult", function(param) {
12547
12632
  var tool = param.tool, toolCallId = param.toolCallId, output = param.output;
@@ -12596,7 +12681,7 @@
12596
12681
  });
12597
12682
  return Promise.resolve();
12598
12683
  });
12599
- this.id = id;
12684
+ this.conversationId = id;
12600
12685
  this.generateId = generateId$1;
12601
12686
  this.state = state;
12602
12687
  this.transport = transport;
@@ -12608,6 +12693,12 @@
12608
12693
  this.shouldRepairToolInput = shouldRepairToolInput;
12609
12694
  }
12610
12695
  _create_class(AbstractChat, [
12696
+ {
12697
+ key: "id",
12698
+ get: function get() {
12699
+ return this.conversationId;
12700
+ }
12701
+ },
12611
12702
  {
12612
12703
  key: "status",
12613
12704
  get: /**
@@ -12637,6 +12728,17 @@
12637
12728
  return this.state.error;
12638
12729
  }
12639
12730
  },
12731
+ {
12732
+ /**
12733
+ * Starts a new server-side conversation thread by rotating the id sent as
12734
+ * `chatId` / `id` on the next request. The InstantSearch connector calls this
12735
+ * after the user clears the transcript so completions are not tied to prior
12736
+ * context.
12737
+ */ key: "resetConversationId",
12738
+ value: function resetConversationId() {
12739
+ this.conversationId = this.generateId();
12740
+ }
12741
+ },
12640
12742
  {
12641
12743
  key: "messages",
12642
12744
  get: function get() {
@@ -13005,8 +13107,7 @@
13005
13107
  var updatedParts7 = _to_consumable_array(currentMessage.parts);
13006
13108
  var existingPart2 = updatedParts7[toolIndex2];
13007
13109
  // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
13008
- existingPart2.rawOutput;
13009
- var rest = _object_without_properties(existingPart2, [
13110
+ var _ignored = existingPart2.rawOutput, rest = _object_without_properties(existingPart2, [
13010
13111
  "rawOutput"
13011
13112
  ]);
13012
13113
  updatedParts7[toolIndex2] = _object_spread_props(_object_spread({}, rest), {
@@ -13034,10 +13135,7 @@
13034
13135
  delete toolRawOutputByCallId[chunk.toolCallId];
13035
13136
  var updatedParts8 = _to_consumable_array(currentMessage.parts);
13036
13137
  var existingPart3 = updatedParts8[toolIndex3];
13037
- // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
13038
- existingPart3.rawOutput; // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
13039
- existingPart3.preliminary;
13040
- var rest1 = _object_without_properties(existingPart3, [
13138
+ var _ignoredRawOutput = existingPart3.rawOutput, _ignoredPreliminary = existingPart3.preliminary, rest1 = _object_without_properties(existingPart3, [
13041
13139
  "rawOutput",
13042
13140
  "preliminary"
13043
13141
  ]);
@@ -13132,7 +13230,8 @@
13132
13230
  case 'error':
13133
13231
  {
13134
13232
  isError = true;
13135
- throw new Error(chunk.errorText);
13233
+ var text = chunk.errorText.trim();
13234
+ throw new Error(tryParseErrorMessage(text) || text || 'Unknown error');
13136
13235
  }
13137
13236
  case 'abort':
13138
13237
  {
@@ -13149,9 +13248,32 @@
13149
13248
  }
13150
13249
  break;
13151
13250
  }
13251
+ // Surface guardrail violations through the error state, but
13252
+ // distinct from generic cost-control / 4xx errors: throw a
13253
+ // `GuardrailViolationError` so the UI can render the
13254
+ // service-provided `fallbackResponse` verbatim (it's authored for
13255
+ // end-user display) instead of the friendly default used for
13256
+ // opaque transport errors. Also discard any in-progress assistant
13257
+ // message so no partial text lingers above the fallback, and
13258
+ // clear the local cursor so the `onFinish` callback doesn't
13259
+ // receive a `currentMessage` that no longer exists in state.
13260
+ case 'data-guardrail-violation':
13261
+ {
13262
+ isError = true;
13263
+ if (currentMessageIndex >= 0) {
13264
+ _this.state.messages = _this.state.messages.slice(0, currentMessageIndex);
13265
+ currentMessage = undefined;
13266
+ currentMessageIndex = -1;
13267
+ }
13268
+ // `chunk.data` widens to `unknown` here: the chunk union also
13269
+ // carries a generic `data-${string}` member, and the literal
13270
+ // matches both, so narrowing can't pick the specific shape.
13271
+ var fallbackResponse = chunk.data.fallbackResponse;
13272
+ throw new GuardrailViolationError(fallbackResponse || 'Sorry, we are not able to generate a response at the moment.');
13273
+ }
13152
13274
  default:
13153
13275
  {
13154
- // Handle data parts (data-*)
13276
+ // Handle generic data parts (data-*)
13155
13277
  var chunkType = chunk.type;
13156
13278
  if ((chunkType === null || chunkType === void 0 ? void 0 : chunkType.startsWith('data-')) && currentMessage) {
13157
13279
  var dataPart = {
@@ -13466,6 +13588,20 @@
13466
13588
  }, []);
13467
13589
  }
13468
13590
 
13591
+ /**
13592
+ * Reads a human-readable message from a failed HTTP response body when the
13593
+ * server returns JSON such as `{ "message": "..." }` (the shared
13594
+ * `ErrorResponse` shape used by every status code), falling back to the HTTP
13595
+ * status line when the body is empty or not parseable.
13596
+ */ function getHttpErrorMessage(response) {
13597
+ var fallback = "HTTP error: ".concat(response.status, " ").concat(response.statusText);
13598
+ return response.text().then(function(text) {
13599
+ var _tryParseErrorMessage;
13600
+ return (_tryParseErrorMessage = tryParseErrorMessage(text)) !== null && _tryParseErrorMessage !== void 0 ? _tryParseErrorMessage : fallback;
13601
+ }).catch(function() {
13602
+ return fallback;
13603
+ });
13604
+ }
13469
13605
  /**
13470
13606
  * Abstract base class for HTTP-based chat transports.
13471
13607
  */ var HttpChatTransport = /*#__PURE__*/ function() {
@@ -13544,7 +13680,9 @@
13544
13680
  credentials: credentials
13545
13681
  }).then(function(response) {
13546
13682
  if (!response.ok) {
13547
- throw new Error("HTTP error: ".concat(response.status, " ").concat(response.statusText));
13683
+ return getHttpErrorMessage(response).then(function(message) {
13684
+ throw new Error(message);
13685
+ });
13548
13686
  }
13549
13687
  if (!response.body) {
13550
13688
  throw new Error('Response body is empty');
@@ -13602,7 +13740,9 @@
13602
13740
  if (response.status === 404) {
13603
13741
  return null;
13604
13742
  }
13605
- throw new Error("HTTP error: ".concat(response.status, " ").concat(response.statusText));
13743
+ return getHttpErrorMessage(response).then(function(message) {
13744
+ throw new Error(message);
13745
+ });
13606
13746
  }
13607
13747
  if (!response.body) {
13608
13748
  return null;
@@ -13638,7 +13778,7 @@
13638
13778
  return DefaultChatTransport;
13639
13779
  }(HttpChatTransport);
13640
13780
 
13641
- var withUsage$n = createDocumentationMessageGenerator({
13781
+ var withUsage$o = createDocumentationMessageGenerator({
13642
13782
  name: 'chat',
13643
13783
  connector: true
13644
13784
  });
@@ -13689,15 +13829,16 @@
13689
13829
  }
13690
13830
  var connectChat = function connectChat(renderFn) {
13691
13831
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13692
- checkRendering(renderFn, withUsage$n());
13832
+ checkRendering(renderFn, withUsage$o());
13693
13833
  return function(widgetParams) {
13694
- 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, options = _object_without_properties(_ref, [
13834
+ 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, [
13695
13835
  "resume",
13696
13836
  "tools",
13697
13837
  "type",
13698
13838
  "context",
13699
13839
  "initialUserMessage",
13700
- "initialMessages"
13840
+ "initialMessages",
13841
+ "disableTriggerValidation"
13701
13842
  ]);
13702
13843
  var _chatInstance;
13703
13844
  var input = '';
@@ -13709,6 +13850,7 @@
13709
13850
  var focusInput;
13710
13851
  var setIsClearing;
13711
13852
  var setFeedbackState;
13853
+ var hasValidatedEntryPoints = false;
13712
13854
  var agentId = 'agentId' in options ? options.agentId : undefined;
13713
13855
  var feedbackState = {};
13714
13856
  var _sendChatMessageFeedback;
@@ -13748,10 +13890,26 @@
13748
13890
  var onClearTransitionEnd = function onClearTransitionEnd() {
13749
13891
  setMessages([]);
13750
13892
  _chatInstance.clearError();
13751
- _chatInstance.regenerateId();
13893
+ _chatInstance.resetConversationId();
13752
13894
  feedbackState = {};
13753
13895
  setIsClearing(false);
13754
13896
  };
13897
+ var validateEntryPoints = function validateEntryPoints(instantSearchInstance) {
13898
+ if (disableTriggerValidation || hasValidatedEntryPoints) {
13899
+ return;
13900
+ }
13901
+ // warning only relevant once mounted
13902
+ if (!instantSearchInstance.mainIndex) {
13903
+ return;
13904
+ }
13905
+ walkIndex(instantSearchInstance.mainIndex, function(indexWidget) {
13906
+ var widgets = indexWidget.getWidgets();
13907
+ if (widgets.some(function(w) {
13908
+ return w.opensChat === true;
13909
+ })) ;
13910
+ });
13911
+ hasValidatedEntryPoints = true;
13912
+ };
13755
13913
  var makeChatInstance = function makeChatInstance(instantSearchInstance) {
13756
13914
  var transport;
13757
13915
  var client = instantSearchInstance.client;
@@ -13801,7 +13959,7 @@
13801
13959
  }
13802
13960
  if ('agentId' in options && options.agentId) {
13803
13961
  if (!appId || !apiKey) {
13804
- throw new Error(withUsage$n('Could not extract Algolia credentials from the search client.'));
13962
+ throw new Error(withUsage$o('Could not extract Algolia credentials from the search client.'));
13805
13963
  }
13806
13964
  var baseApi = "https://".concat(appId, ".algolia.net/agent-studio/1/agents/").concat(agentId, "/completions?compatibilityMode=ai-sdk-5");
13807
13965
  transport = new DefaultChatTransport({
@@ -13826,7 +13984,7 @@
13826
13984
  });
13827
13985
  }
13828
13986
  if (!transport) {
13829
- throw new Error(withUsage$n('You need to provide either an `agentId` or a `transport`.'));
13987
+ throw new Error(withUsage$o('You need to provide either an `agentId` or a `transport`.'));
13830
13988
  }
13831
13989
  if ('chat' in options) {
13832
13990
  return options.chat;
@@ -13878,6 +14036,7 @@
13878
14036
  init: function init(initOptions) {
13879
14037
  var _this = this;
13880
14038
  var instantSearchInstance = initOptions.instantSearchInstance;
14039
+ validateEntryPoints(instantSearchInstance);
13881
14040
  _chatInstance = makeChatInstance(instantSearchInstance);
13882
14041
  var render = function render() {
13883
14042
  renderFn(_object_spread_props(_object_spread({}, _this.getWidgetRenderState(initOptions)), {
@@ -13887,6 +14046,10 @@
13887
14046
  setOpen = function setOpen(o) {
13888
14047
  open = o;
13889
14048
  render();
14049
+ // `open` is read by sibling widgets (e.g. `chatTrigger`) via the
14050
+ // shared `renderState`. Schedule a full re-render so they pick up
14051
+ // the new value instead of staying frozen on their initial state.
14052
+ initOptions.instantSearchInstance.scheduleRender();
13890
14053
  };
13891
14054
  focusInput = function focusInput() {
13892
14055
  setOpen(true);
@@ -13907,7 +14070,7 @@
13907
14070
  if (agentId && feedback) {
13908
14071
  var _getAppIdAndApiKey = _sliced_to_array(getAppIdAndApiKey(initOptions.instantSearchInstance.client), 2), appId = _getAppIdAndApiKey[0], apiKey = _getAppIdAndApiKey[1];
13909
14072
  if (!appId || !apiKey) {
13910
- throw new Error(withUsage$n('Could not extract Algolia credentials from the search client.'));
14073
+ throw new Error(withUsage$o('Could not extract Algolia credentials from the search client.'));
13911
14074
  }
13912
14075
  feedbackAbortController = new AbortController();
13913
14076
  _sendChatMessageFeedback = function _sendChatMessageFeedback(messageId, vote) {
@@ -13948,6 +14111,7 @@
13948
14111
  }), true);
13949
14112
  },
13950
14113
  render: function render(renderOptions) {
14114
+ validateEntryPoints(renderOptions.instantSearchInstance);
13951
14115
  renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(renderOptions)), {
13952
14116
  instantSearchInstance: renderOptions.instantSearchInstance
13953
14117
  }), false);
@@ -14054,6 +14218,77 @@
14054
14218
  return useConnector(connectChat, props, additionalWidgetProperties);
14055
14219
  }
14056
14220
 
14221
+ var withUsage$n = createDocumentationMessageGenerator({
14222
+ name: 'chatTrigger',
14223
+ connector: true
14224
+ });
14225
+ // Reads the sibling chat widget's render state from the live cross-index
14226
+ // `instantSearchInstance.renderState` map. We resolve at call time so that
14227
+ // `toggleOpen` always sees the latest `open`/`setOpen` values.
14228
+ function getChatRenderState(options) {
14229
+ var _options_parent, _options_instantSearchInstance_renderState_indexId;
14230
+ var indexId = (_options_parent = options.parent) === null || _options_parent === void 0 ? void 0 : _options_parent.getIndexId();
14231
+ if (!indexId) return undefined;
14232
+ return (_options_instantSearchInstance_renderState_indexId = options.instantSearchInstance.renderState[indexId]) === null || _options_instantSearchInstance_renderState_indexId === void 0 ? void 0 : _options_instantSearchInstance_renderState_indexId.chat;
14233
+ }
14234
+ var connectChatTrigger = function connectChatTrigger(renderFn) {
14235
+ var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14236
+ checkRendering(renderFn, withUsage$n());
14237
+ return function(widgetParams) {
14238
+ var params = widgetParams !== null && widgetParams !== void 0 ? widgetParams : {};
14239
+ var lastOptions = null;
14240
+ function toggleOpen() {
14241
+ if (!lastOptions) return;
14242
+ var chatState = getChatRenderState(lastOptions);
14243
+ if (!chatState) return;
14244
+ if (chatState.open) {
14245
+ var _chatState_setOpen;
14246
+ (_chatState_setOpen = chatState.setOpen) === null || _chatState_setOpen === void 0 ? void 0 : _chatState_setOpen.call(chatState, false);
14247
+ } else {
14248
+ openChat(chatState);
14249
+ }
14250
+ }
14251
+ return {
14252
+ $$type: 'ais.chatTrigger',
14253
+ opensChat: true,
14254
+ init: function init(initOptions) {
14255
+ lastOptions = initOptions;
14256
+ renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
14257
+ instantSearchInstance: initOptions.instantSearchInstance
14258
+ }), true);
14259
+ },
14260
+ render: function render(renderOptions) {
14261
+ lastOptions = renderOptions;
14262
+ renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(renderOptions)), {
14263
+ instantSearchInstance: renderOptions.instantSearchInstance
14264
+ }), false);
14265
+ },
14266
+ dispose: function dispose() {
14267
+ unmountFn();
14268
+ },
14269
+ getWidgetRenderState: function getWidgetRenderState(renderOptions) {
14270
+ var _ref;
14271
+ var chatState = getChatRenderState(renderOptions);
14272
+ return {
14273
+ open: (_ref = chatState === null || chatState === void 0 ? void 0 : chatState.open) !== null && _ref !== void 0 ? _ref : false,
14274
+ toggleOpen: toggleOpen,
14275
+ widgetParams: params
14276
+ };
14277
+ },
14278
+ getRenderState: function getRenderState(renderState, renderOptions) {
14279
+ return _object_spread_props(_object_spread({}, renderState), {
14280
+ chatTrigger: this.getWidgetRenderState(renderOptions)
14281
+ });
14282
+ }
14283
+ };
14284
+ };
14285
+ };
14286
+
14287
+ function useChatTrigger() {
14288
+ var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, additionalWidgetProperties = arguments.length > 1 ? arguments[1] : void 0;
14289
+ return useConnector(connectChatTrigger, props, additionalWidgetProperties);
14290
+ }
14291
+
14057
14292
  var withUsage$m = createDocumentationMessageGenerator({
14058
14293
  name: 'clear-refinements',
14059
14294
  connector: true
@@ -19813,15 +20048,32 @@
19813
20048
  createElement: createElement
19814
20049
  });
19815
20050
  return function ChatMessageError(userProps) {
19816
- var onReload = userProps.onReload, actions = userProps.actions, userTranslations = userProps.translations, props = _object_without_properties(userProps, [
20051
+ var _ref, _ref1;
20052
+ var errorMessage = userProps.errorMessage, onReload = userProps.onReload, onNewConversation = userProps.onNewConversation, actions = userProps.actions, userTranslations = userProps.translations, props = _object_without_properties(userProps, [
20053
+ "errorMessage",
19817
20054
  "onReload",
20055
+ "onNewConversation",
19818
20056
  "actions",
19819
20057
  "translations"
19820
20058
  ]);
19821
- var translations = _object_spread({
19822
- errorMessage: 'Sorry, we are not able to generate a response at the moment. Please retry or contact support.',
19823
- retryText: 'Retry'
19824
- }, userTranslations);
20059
+ var defaultErrorMessage = 'Sorry, we are not able to generate a response at the moment. Please contact support.';
20060
+ var defaultNewConversationText = 'Start a new conversation';
20061
+ var defaultRetryText = 'Retry';
20062
+ var errorMessageTranslation = userTranslations === null || userTranslations === void 0 ? void 0 : userTranslations.errorMessage;
20063
+ var resolvedErrorMessage = typeof errorMessageTranslation === 'function' ? errorMessageTranslation({
20064
+ errorMessage: errorMessage
20065
+ }) : errorMessageTranslation !== null && errorMessageTranslation !== void 0 ? errorMessageTranslation : defaultErrorMessage;
20066
+ var newConversationText = (_ref = userTranslations === null || userTranslations === void 0 ? void 0 : userTranslations.newConversationText) !== null && _ref !== void 0 ? _ref : defaultNewConversationText;
20067
+ var retryText = (_ref1 = userTranslations === null || userTranslations === void 0 ? void 0 : userTranslations.retryText) !== null && _ref1 !== void 0 ? _ref1 : defaultRetryText;
20068
+ // Action precedence:
20069
+ // 1. `actions` (full custom)
20070
+ // 2. `onNewConversation` (recommended for permanent / guardrail errors)
20071
+ // 3. `onReload` (legacy retry, suitable for transient failures)
20072
+ // 4. nothing
20073
+ var hasCustomActions = Boolean(actions);
20074
+ var showNewConversation = !hasCustomActions && Boolean(onNewConversation);
20075
+ var showRetry = !hasCustomActions && !showNewConversation && Boolean(onReload);
20076
+ var hasActions = hasCustomActions || showNewConversation || showRetry;
19825
20077
  return /*#__PURE__*/ createElement("article", _object_spread({
19826
20078
  className: "ais-ChatMessageError ais-ChatMessage ais-ChatMessage--left ais-ChatMessage--subtle"
19827
20079
  }, props), /*#__PURE__*/ createElement("div", {
@@ -19830,15 +20082,22 @@
19830
20082
  className: "ais-ChatMessage-content"
19831
20083
  }, /*#__PURE__*/ createElement("div", {
19832
20084
  className: "ais-ChatMessage-message"
19833
- }, translations.errorMessage), (actions || onReload) && /*#__PURE__*/ createElement("div", {
20085
+ }, resolvedErrorMessage), hasActions && /*#__PURE__*/ createElement("div", {
19834
20086
  className: "ais-ChatMessage-actions"
19835
- }, actions ? actions.map(function(action, index) {
20087
+ }, hasCustomActions ? actions.map(function(action, index) {
19836
20088
  return /*#__PURE__*/ createElement(Button, _object_spread({
19837
20089
  key: index,
19838
20090
  variant: "ghost",
19839
20091
  className: "ais-ChatMessage-action"
19840
20092
  }, action), action.children);
19841
- }) : /*#__PURE__*/ createElement(Button, {
20093
+ }) : showNewConversation ? /*#__PURE__*/ createElement(Button, {
20094
+ variant: "primary",
20095
+ size: "md",
20096
+ className: "ais-ChatMessage-errorAction",
20097
+ onClick: function onClick() {
20098
+ return onNewConversation === null || onNewConversation === void 0 ? void 0 : onNewConversation();
20099
+ }
20100
+ }, newConversationText) : /*#__PURE__*/ createElement(Button, {
19842
20101
  variant: "primary",
19843
20102
  size: "md",
19844
20103
  className: "ais-ChatMessage-errorAction",
@@ -19847,7 +20106,7 @@
19847
20106
  }
19848
20107
  }, /*#__PURE__*/ createElement(ReloadIcon, {
19849
20108
  createElement: createElement
19850
- }), translations.retryText)))));
20109
+ }), retryText)))));
19851
20110
  };
19852
20111
  }
19853
20112
 
@@ -20011,7 +20270,7 @@
20011
20270
  });
20012
20271
  return function ChatMessages(userProps) {
20013
20272
  var _lastMessage_parts;
20014
- var _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, _userProps_messageClassNames = userProps.messageClassNames, messageClassNames = _userProps_messageClassNames === void 0 ? {} : _userProps_messageClassNames, messageTranslations = userProps.messageTranslations, _userProps_messages = userProps.messages, messages = _userProps_messages === void 0 ? [] : _userProps_messages, MessageComponent = userProps.messageComponent, LoaderComponent = userProps.loaderComponent, ErrorComponent = userProps.errorComponent, EmptyComponent = userProps.emptyComponent, ActionsComponent = userProps.actionsComponent, tools = userProps.tools, indexUiState = userProps.indexUiState, setIndexUiState = userProps.setIndexUiState, _userProps_status = userProps.status, status = _userProps_status === void 0 ? 'ready' : _userProps_status, _userProps_hideScrollToBottom = userProps.hideScrollToBottom, hideScrollToBottom = _userProps_hideScrollToBottom === void 0 ? false : _userProps_hideScrollToBottom, onReload = userProps.onReload, onClose = userProps.onClose, sendMessage = userProps.sendMessage, setInput = userProps.setInput, userTranslations = userProps.translations, userMessageProps = userProps.userMessageProps, assistantMessageProps = userProps.assistantMessageProps, _userProps_isClearing = userProps.isClearing, isClearing = _userProps_isClearing === void 0 ? false : _userProps_isClearing, onClearTransitionEnd = userProps.onClearTransitionEnd, isScrollAtBottom = userProps.isScrollAtBottom, scrollRef = userProps.scrollRef, contentRef = userProps.contentRef, onScrollToBottom = userProps.onScrollToBottom, suggestionsElement = userProps.suggestionsElement, onFeedback = userProps.onFeedback, feedbackState = userProps.feedbackState, props = _object_without_properties(userProps, [
20273
+ var _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, _userProps_messageClassNames = userProps.messageClassNames, messageClassNames = _userProps_messageClassNames === void 0 ? {} : _userProps_messageClassNames, messageTranslations = userProps.messageTranslations, _userProps_messages = userProps.messages, messages = _userProps_messages === void 0 ? [] : _userProps_messages, MessageComponent = userProps.messageComponent, LoaderComponent = userProps.loaderComponent, ErrorComponent = userProps.errorComponent, EmptyComponent = userProps.emptyComponent, ActionsComponent = userProps.actionsComponent, tools = userProps.tools, indexUiState = userProps.indexUiState, setIndexUiState = userProps.setIndexUiState, _userProps_status = userProps.status, status = _userProps_status === void 0 ? 'ready' : _userProps_status, error = userProps.error, _userProps_hideScrollToBottom = userProps.hideScrollToBottom, hideScrollToBottom = _userProps_hideScrollToBottom === void 0 ? false : _userProps_hideScrollToBottom, onReload = userProps.onReload, onNewConversation = userProps.onNewConversation, onClose = userProps.onClose, sendMessage = userProps.sendMessage, setInput = userProps.setInput, userTranslations = userProps.translations, userMessageProps = userProps.userMessageProps, assistantMessageProps = userProps.assistantMessageProps, _userProps_isClearing = userProps.isClearing, isClearing = _userProps_isClearing === void 0 ? false : _userProps_isClearing, onClearTransitionEnd = userProps.onClearTransitionEnd, isScrollAtBottom = userProps.isScrollAtBottom, scrollRef = userProps.scrollRef, contentRef = userProps.contentRef, onScrollToBottom = userProps.onScrollToBottom, suggestionsElement = userProps.suggestionsElement, onFeedback = userProps.onFeedback, feedbackState = userProps.feedbackState, props = _object_without_properties(userProps, [
20015
20274
  "classNames",
20016
20275
  "messageClassNames",
20017
20276
  "messageTranslations",
@@ -20025,8 +20284,10 @@
20025
20284
  "indexUiState",
20026
20285
  "setIndexUiState",
20027
20286
  "status",
20287
+ "error",
20028
20288
  "hideScrollToBottom",
20029
20289
  "onReload",
20290
+ "onNewConversation",
20030
20291
  "onClose",
20031
20292
  "sendMessage",
20032
20293
  "setInput",
@@ -20111,7 +20372,18 @@
20111
20372
  loaderText: translations.loaderText
20112
20373
  }
20113
20374
  }), status === 'error' && /*#__PURE__*/ createElement(DefaultError, {
20114
- onReload: onReload
20375
+ onNewConversation: onNewConversation,
20376
+ errorMessage: error === null || error === void 0 ? void 0 : error.message,
20377
+ translations: // `fallbackResponse` that's safe to display verbatim; for
20378
+ // every other error we keep hiding the raw `error.message`
20379
+ // behind the friendly default. Detection is by `error.name`
20380
+ // to avoid coupling this package to `instantsearch.js`.
20381
+ (error === null || error === void 0 ? void 0 : error.name) === 'GuardrailViolationError' ? {
20382
+ errorMessage: function errorMessage(param) {
20383
+ var rawMessage = param.errorMessage;
20384
+ return rawMessage !== null && rawMessage !== void 0 ? rawMessage : '';
20385
+ }
20386
+ } : undefined
20115
20387
  }))), /*#__PURE__*/ createElement(Button, {
20116
20388
  variant: "outline",
20117
20389
  size: "sm",
@@ -20130,13 +20402,9 @@
20130
20402
  if (status === 'submitted') return true;
20131
20403
  if (!lastPart) return true;
20132
20404
  if (isPartText(lastPart)) return false;
20133
- if (isPartTool(lastPart)) {
20134
- if (lastPart.state === 'output-available') return false;
20135
- if (lastPart.state === 'input-streaming') {
20136
- var tool = findTool(lastPart.type, tools);
20137
- return !(tool === null || tool === void 0 ? void 0 : tool.streamInput);
20138
- }
20139
- return true;
20405
+ if (isPartTool(lastPart) && lastPart.state === 'input-streaming') {
20406
+ var tool = findTool(lastPart.type, tools);
20407
+ return !(tool === null || tool === void 0 ? void 0 : tool.streamInput);
20140
20408
  }
20141
20409
  return true;
20142
20410
  };
@@ -20144,7 +20412,7 @@
20144
20412
  function createChatOverlayLayoutComponent(param) {
20145
20413
  var createElement = param.createElement;
20146
20414
  return function ChatOverlayLayout(userProps) {
20147
- var open = userProps.open, maximized = userProps.maximized, headerComponent = userProps.headerComponent, messagesComponent = userProps.messagesComponent, promptComponent = userProps.promptComponent, toggleButtonComponent = userProps.toggleButtonComponent, _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, className = userProps.className; // Chat state props (destructured to avoid spreading on div)
20415
+ var open = userProps.open, maximized = userProps.maximized, headerComponent = userProps.headerComponent, messagesComponent = userProps.messagesComponent, promptComponent = userProps.promptComponent, _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, className = userProps.className; // Chat state props (destructured to avoid spreading on div)
20148
20416
  userProps.messages;
20149
20417
  userProps.status;
20150
20418
  userProps.isClearing;
@@ -20162,7 +20430,6 @@
20162
20430
  "headerComponent",
20163
20431
  "messagesComponent",
20164
20432
  "promptComponent",
20165
- "toggleButtonComponent",
20166
20433
  "classNames",
20167
20434
  "className",
20168
20435
  "messages",
@@ -20181,9 +20448,7 @@
20181
20448
  className: cx('ais-Chat', 'ais-ChatOverlayLayout', maximized && 'ais-ChatOverlayLayout--maximized', classNames.root, className)
20182
20449
  }), /*#__PURE__*/ createElement("div", {
20183
20450
  className: cx('ais-Chat-container', open && 'ais-Chat-container--open', maximized && 'ais-Chat-container--maximized', classNames.container)
20184
- }, headerComponent, messagesComponent, promptComponent), /*#__PURE__*/ createElement("div", {
20185
- className: "ais-Chat-toggleButtonWrapper"
20186
- }, toggleButtonComponent));
20451
+ }, headerComponent, messagesComponent, promptComponent));
20187
20452
  };
20188
20453
  }
20189
20454
 
@@ -20372,42 +20637,8 @@
20372
20637
  };
20373
20638
  }
20374
20639
 
20375
- function createChatToggleButtonComponent(param) {
20376
- var createElement = param.createElement;
20377
- var Button = createButtonComponent({
20378
- createElement: createElement
20379
- });
20380
- return function ChatToggleButton(userProps) {
20381
- var open = userProps.open, onClick = userProps.onClick, ToggleIcon = userProps.toggleIconComponent, _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, className = userProps.className, props = _object_without_properties(userProps, [
20382
- "open",
20383
- "onClick",
20384
- "toggleIconComponent",
20385
- "classNames",
20386
- "className"
20387
- ]);
20388
- var defaultIcon = open ? /*#__PURE__*/ createElement(ChevronUpIcon, {
20389
- createElement: createElement
20390
- }) : /*#__PURE__*/ createElement(SparklesIcon, {
20391
- createElement: createElement
20392
- });
20393
- return /*#__PURE__*/ createElement(Button, _object_spread({
20394
- variant: "primary",
20395
- size: "md",
20396
- iconOnly: true,
20397
- className: cx('ais-ChatToggleButton', open && 'ais-ChatToggleButton--open', classNames.root, className),
20398
- onClick: onClick
20399
- }, props), ToggleIcon ? /*#__PURE__*/ createElement(ToggleIcon, {
20400
- isOpen: open
20401
- }) : defaultIcon);
20402
- };
20403
- }
20404
-
20405
20640
  function createChatComponent(param) {
20406
20641
  var createElement = param.createElement, Fragment = param.Fragment;
20407
- var ChatToggleButton = createChatToggleButtonComponent({
20408
- createElement: createElement,
20409
- Fragment: Fragment
20410
- });
20411
20642
  var ChatHeader = createChatHeaderComponent({
20412
20643
  createElement: createElement,
20413
20644
  Fragment: Fragment
@@ -20429,17 +20660,15 @@
20429
20660
  Fragment: Fragment
20430
20661
  });
20431
20662
  return function Chat(userProps) {
20432
- var open = userProps.open, _userProps_maximized = userProps.maximized, maximized = _userProps_maximized === void 0 ? false : _userProps_maximized, headerProps = userProps.headerProps, toggleButtonProps = userProps.toggleButtonProps, messagesProps = userProps.messagesProps, suggestionsProps = userProps.suggestionsProps, _userProps_promptProps = userProps.promptProps, promptProps = _userProps_promptProps === void 0 ? {} : _userProps_promptProps, HeaderComponent = userProps.headerComponent, PromptComponent = userProps.promptComponent, ToggleButtonComponent = userProps.toggleButtonComponent, SuggestionsComponent = userProps.suggestionsComponent, tmp = userProps.layoutComponent, LayoutComponent = tmp === void 0 ? OverlayLayout : tmp, _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, className = userProps.className, sendMessage = userProps.sendMessage, regenerate = userProps.regenerate, stop = userProps.stop, error = userProps.error, props = _object_without_properties(userProps, [
20663
+ var open = userProps.open, _userProps_maximized = userProps.maximized, maximized = _userProps_maximized === void 0 ? false : _userProps_maximized, headerProps = userProps.headerProps, messagesProps = userProps.messagesProps, suggestionsProps = userProps.suggestionsProps, _userProps_promptProps = userProps.promptProps, promptProps = _userProps_promptProps === void 0 ? {} : _userProps_promptProps, HeaderComponent = userProps.headerComponent, PromptComponent = userProps.promptComponent, SuggestionsComponent = userProps.suggestionsComponent, tmp = userProps.layoutComponent, LayoutComponent = tmp === void 0 ? OverlayLayout : tmp, _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, className = userProps.className, sendMessage = userProps.sendMessage, regenerate = userProps.regenerate, stop = userProps.stop, error = userProps.error, props = _object_without_properties(userProps, [
20433
20664
  "open",
20434
20665
  "maximized",
20435
20666
  "headerProps",
20436
- "toggleButtonProps",
20437
20667
  "messagesProps",
20438
20668
  "suggestionsProps",
20439
20669
  "promptProps",
20440
20670
  "headerComponent",
20441
20671
  "promptComponent",
20442
- "toggleButtonComponent",
20443
20672
  "suggestionsComponent",
20444
20673
  "layoutComponent",
20445
20674
  "classNames",
@@ -20454,6 +20683,7 @@
20454
20683
  maximized: maximized
20455
20684
  }));
20456
20685
  var messagesComponent = /*#__PURE__*/ createElement(ChatMessages, _object_spread_props(_object_spread({}, messagesProps), {
20686
+ error: error,
20457
20687
  classNames: classNames.messages,
20458
20688
  messageClassNames: classNames.message,
20459
20689
  suggestionsElement: createElement(SuggestionsComponent || ChatPromptSuggestions, _object_spread_props(_object_spread({}, suggestionsProps), {
@@ -20463,24 +20693,12 @@
20463
20693
  var promptComponent = createElement(PromptComponent || ChatPrompt, _object_spread_props(_object_spread({}, promptProps), {
20464
20694
  classNames: classNames.prompt
20465
20695
  }));
20466
- var toggleButtonComponent = createElement(ToggleButtonComponent || ChatToggleButton, _object_spread_props(_object_spread({}, toggleButtonProps), {
20467
- classNames: classNames.toggleButton,
20468
- onClick: function onClick() {
20469
- var _toggleButtonProps_onClick;
20470
- (_toggleButtonProps_onClick = toggleButtonProps.onClick) === null || _toggleButtonProps_onClick === void 0 ? void 0 : _toggleButtonProps_onClick.call(toggleButtonProps);
20471
- if (!open) {
20472
- var _promptProps_promptRef_current, _promptProps_promptRef;
20473
- (_promptProps_promptRef = promptProps.promptRef) === null || _promptProps_promptRef === void 0 ? void 0 : (_promptProps_promptRef_current = _promptProps_promptRef.current) === null || _promptProps_promptRef_current === void 0 ? void 0 : _promptProps_promptRef_current.focus();
20474
- }
20475
- }
20476
- }));
20477
20696
  return /*#__PURE__*/ createElement(LayoutComponent, _object_spread_props(_object_spread({}, props), {
20478
20697
  open: open,
20479
20698
  maximized: maximized,
20480
20699
  headerComponent: headerComponent,
20481
20700
  messagesComponent: messagesComponent,
20482
20701
  promptComponent: promptComponent,
20483
- toggleButtonComponent: toggleButtonComponent,
20484
20702
  classNames: {
20485
20703
  root: classNames.root,
20486
20704
  container: classNames.container
@@ -20506,8 +20724,7 @@
20506
20724
  return function ChatInlineLayout(userProps) {
20507
20725
  var headerComponent = userProps.headerComponent, messagesComponent = userProps.messagesComponent, promptComponent = userProps.promptComponent, _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, className = userProps.className;
20508
20726
  userProps.open;
20509
- userProps.maximized;
20510
- userProps.toggleButtonComponent; // Chat state props (destructured to avoid spreading on div)
20727
+ userProps.maximized; // Chat state props (destructured to avoid spreading on div)
20511
20728
  userProps.messages;
20512
20729
  userProps.status;
20513
20730
  userProps.isClearing;
@@ -20527,7 +20744,6 @@
20527
20744
  "className",
20528
20745
  "open",
20529
20746
  "maximized",
20530
- "toggleButtonComponent",
20531
20747
  "messages",
20532
20748
  "status",
20533
20749
  "isClearing",
@@ -20552,7 +20768,7 @@
20552
20768
  var createElement = param.createElement;
20553
20769
  var originalMargins = new WeakMap();
20554
20770
  return function ChatSidePanelLayout(userProps) {
20555
- var open = userProps.open, maximized = userProps.maximized, headerComponent = userProps.headerComponent, messagesComponent = userProps.messagesComponent, promptComponent = userProps.promptComponent, toggleButtonComponent = userProps.toggleButtonComponent, _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, className = userProps.className, parentElement = userProps.parentElement; // Chat state props (destructured to avoid spreading on div)
20771
+ var open = userProps.open, maximized = userProps.maximized, headerComponent = userProps.headerComponent, messagesComponent = userProps.messagesComponent, promptComponent = userProps.promptComponent, _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, className = userProps.className, parentElement = userProps.parentElement; // Chat state props (destructured to avoid spreading on div)
20556
20772
  userProps.messages;
20557
20773
  userProps.status;
20558
20774
  userProps.isClearing;
@@ -20570,7 +20786,6 @@
20570
20786
  "headerComponent",
20571
20787
  "messagesComponent",
20572
20788
  "promptComponent",
20573
- "toggleButtonComponent",
20574
20789
  "classNames",
20575
20790
  "className",
20576
20791
  "parentElement",
@@ -20607,9 +20822,7 @@
20607
20822
  className: cx('ais-Chat', 'ais-ChatSidePanelLayout', maximized && 'ais-ChatSidePanelLayout--maximized', classNames.root, className)
20608
20823
  }), /*#__PURE__*/ createElement("div", {
20609
20824
  className: cx('ais-Chat-container', open && 'ais-Chat-container--open', maximized && 'ais-Chat-container--maximized', classNames.container)
20610
- }, headerComponent, messagesComponent, promptComponent), /*#__PURE__*/ createElement("div", {
20611
- className: "ais-Chat-toggleButtonWrapper"
20612
- }, toggleButtonComponent));
20825
+ }, headerComponent, messagesComponent, promptComponent));
20613
20826
  };
20614
20827
  }
20615
20828
 
@@ -20649,6 +20862,36 @@
20649
20862
  };
20650
20863
  }
20651
20864
 
20865
+ function createChatToggleButtonComponent(param) {
20866
+ var createElement = param.createElement;
20867
+ var Button = createButtonComponent({
20868
+ createElement: createElement
20869
+ });
20870
+ return function ChatToggleButton(userProps) {
20871
+ var open = userProps.open, onClick = userProps.onClick, ToggleIcon = userProps.toggleIconComponent, _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, className = userProps.className, props = _object_without_properties(userProps, [
20872
+ "open",
20873
+ "onClick",
20874
+ "toggleIconComponent",
20875
+ "classNames",
20876
+ "className"
20877
+ ]);
20878
+ var defaultIcon = open ? /*#__PURE__*/ createElement(ChevronUpIcon, {
20879
+ createElement: createElement
20880
+ }) : /*#__PURE__*/ createElement(SparklesIcon, {
20881
+ createElement: createElement
20882
+ });
20883
+ return /*#__PURE__*/ createElement(Button, _object_spread({
20884
+ variant: "primary",
20885
+ size: "md",
20886
+ iconOnly: true,
20887
+ className: cx('ais-ChatToggleButton', open && 'ais-ChatToggleButton--open', classNames.root, className),
20888
+ onClick: onClick
20889
+ }, props), ToggleIcon ? /*#__PURE__*/ createElement(ToggleIcon, {
20890
+ isOpen: open
20891
+ }) : defaultIcon);
20892
+ };
20893
+ }
20894
+
20652
20895
  var DEFAULT_TRANSLATIONS$1 = {
20653
20896
  streamingLabel: 'Curating results…'
20654
20897
  };
@@ -22004,22 +22247,25 @@
22004
22247
  };
22005
22248
  }
22006
22249
  function EXPERIMENTAL_Autocomplete(_0) {
22007
- var _0_indices = _0.indices, indices = _0_indices === void 0 ? [] : _0_indices, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, showRecent = _0.showRecent, userSearchParameters = _0.searchParameters, detachedMediaQuery = _0.detachedMediaQuery, tmp = _0.translations, userTranslations = tmp === void 0 ? {} : tmp, props = _object_without_properties(_0, [
22250
+ var _0_indices = _0.indices, indices = _0_indices === void 0 ? [] : _0_indices, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, showRecent = _0.showRecent, userSearchParameters = _0.searchParameters, detachedMediaQuery = _0.detachedMediaQuery, tmp = _0.translations, userTranslations = tmp === void 0 ? {} : tmp, aiMode = _0.aiMode, props = _object_without_properties(_0, [
22008
22251
  "indices",
22009
22252
  "showQuerySuggestions",
22010
22253
  "showPromptSuggestions",
22011
22254
  "showRecent",
22012
22255
  "searchParameters",
22013
22256
  "detachedMediaQuery",
22014
- "translations"
22257
+ "translations",
22258
+ "aiMode"
22015
22259
  ]);
22016
22260
  var _showRecent_classNames, _showRecent_classNames1, _showRecent_classNames2, _showRecent_classNames3;
22017
22261
  var translations = _object_spread({}, DEFAULT_TRANSLATIONS, userTranslations);
22018
22262
  var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, indexRenderState = _useInstantSearch.indexRenderState, status = _useInstantSearch.status;
22019
- var refine = useSearchBox({}, {
22263
+ var refine = useSearchBox({}, _object_spread({
22020
22264
  $$type: 'ais.autocomplete',
22021
22265
  $$widgetType: 'ais.autocomplete'
22022
- }).refine;
22266
+ }, aiMode ? {
22267
+ opensChat: true
22268
+ } : {})).refine;
22023
22269
  var isSearchStalled = status === 'stalled';
22024
22270
  var searchParameters = _object_spread({
22025
22271
  hitsPerPage: 5
@@ -22108,6 +22354,7 @@
22108
22354
  indexName: index.indexName
22109
22355
  }, /*#__PURE__*/ React.createElement(Configure, index.searchParameters));
22110
22356
  }), /*#__PURE__*/ React.createElement(InnerAutocomplete, _object_spread_props(_object_spread({}, props), {
22357
+ aiMode: aiMode,
22111
22358
  indicesConfig: indicesConfig,
22112
22359
  refineSearchBox: refine,
22113
22360
  isSearchStalled: isSearchStalled,
@@ -22582,6 +22829,9 @@
22582
22829
  createElement: React.createElement,
22583
22830
  Fragment: React.Fragment
22584
22831
  });
22832
+ // Marker used by `<Chat>` to auto-exempt inline layouts from the entry-point
22833
+ // validation, since inline chats are always visible (no trigger needed).
22834
+ ChatInlineLayout.$$inlineLayout = true;
22585
22835
 
22586
22836
  var ChatSidePanelLayout = createChatSidePanelLayoutComponent({
22587
22837
  createElement: React.createElement,
@@ -22751,16 +23001,13 @@
22751
23001
  var _ref = [
22752
23002
  _0,
22753
23003
  _1
22754
- ], _ref1 = _to_array(_ref), _ref2 = _ref1[0], _rest = _ref1.slice(1), userTools = _ref2.tools, toggleButtonProps = _ref2.toggleButtonProps, headerProps = _ref2.headerProps, messagesProps = _ref2.messagesProps, promptProps = _ref2.promptProps, itemComponent = _ref2.itemComponent, layoutComponent = _ref2.layoutComponent, toggleButtonComponent = _ref2.toggleButtonComponent, toggleButtonIconComponent = _ref2.toggleButtonIconComponent, headerComponent = _ref2.headerComponent, headerTitleIconComponent = _ref2.headerTitleIconComponent, headerCloseIconComponent = _ref2.headerCloseIconComponent, headerMinimizeIconComponent = _ref2.headerMinimizeIconComponent, headerMaximizeIconComponent = _ref2.headerMaximizeIconComponent, loaderComponent = _ref2.loaderComponent, messagesErrorComponent = _ref2.messagesErrorComponent, promptComponent = _ref2.promptComponent, promptHeaderComponent = _ref2.promptHeaderComponent, promptFooterComponent = _ref2.promptFooterComponent, assistantMessageLeadingComponent = _ref2.assistantMessageLeadingComponent, assistantMessageFooterComponent = _ref2.assistantMessageFooterComponent, userMessageLeadingComponent = _ref2.userMessageLeadingComponent, userMessageFooterComponent = _ref2.userMessageFooterComponent, emptyComponent = _ref2.emptyComponent, actionsComponent = _ref2.actionsComponent, suggestionsComponent = _ref2.suggestionsComponent, classNames = _ref2.classNames, _ref_translations = _ref2.translations, translations = _ref_translations === void 0 ? {} : _ref_translations, title = _ref2.title, getSearchPageURL = _ref2.getSearchPageURL, props = _object_without_properties(_ref2, [
23004
+ ], _ref1 = _to_array(_ref), _ref2 = _ref1[0], _rest = _ref1.slice(1), userTools = _ref2.tools, headerProps = _ref2.headerProps, messagesProps = _ref2.messagesProps, promptProps = _ref2.promptProps, itemComponent = _ref2.itemComponent, layoutComponent = _ref2.layoutComponent, headerComponent = _ref2.headerComponent, headerTitleIconComponent = _ref2.headerTitleIconComponent, headerCloseIconComponent = _ref2.headerCloseIconComponent, headerMinimizeIconComponent = _ref2.headerMinimizeIconComponent, headerMaximizeIconComponent = _ref2.headerMaximizeIconComponent, loaderComponent = _ref2.loaderComponent, messagesErrorComponent = _ref2.messagesErrorComponent, promptComponent = _ref2.promptComponent, promptHeaderComponent = _ref2.promptHeaderComponent, promptFooterComponent = _ref2.promptFooterComponent, assistantMessageLeadingComponent = _ref2.assistantMessageLeadingComponent, assistantMessageFooterComponent = _ref2.assistantMessageFooterComponent, userMessageLeadingComponent = _ref2.userMessageLeadingComponent, userMessageFooterComponent = _ref2.userMessageFooterComponent, emptyComponent = _ref2.emptyComponent, actionsComponent = _ref2.actionsComponent, suggestionsComponent = _ref2.suggestionsComponent, classNames = _ref2.classNames, _ref_translations = _ref2.translations, translations = _ref_translations === void 0 ? {} : _ref_translations, title = _ref2.title, getSearchPageURL = _ref2.getSearchPageURL, _ref_disableTriggerValidation = _ref2.disableTriggerValidation, disableTriggerValidation = _ref_disableTriggerValidation === void 0 ? false : _ref_disableTriggerValidation, props = _object_without_properties(_ref2, [
22755
23005
  "tools",
22756
- "toggleButtonProps",
22757
23006
  "headerProps",
22758
23007
  "messagesProps",
22759
23008
  "promptProps",
22760
23009
  "itemComponent",
22761
23010
  "layoutComponent",
22762
- "toggleButtonComponent",
22763
- "toggleButtonIconComponent",
22764
23011
  "headerComponent",
22765
23012
  "headerTitleIconComponent",
22766
23013
  "headerCloseIconComponent",
@@ -22781,7 +23028,8 @@
22781
23028
  "classNames",
22782
23029
  "translations",
22783
23030
  "title",
22784
- "getSearchPageURL"
23031
+ "getSearchPageURL",
23032
+ "disableTriggerValidation"
22785
23033
  ]), _rest1 = _sliced_to_array(_rest, 1), ref = _rest1[0];
22786
23034
  var promptTranslations = translations.prompt, headerTranslations = translations.header, messageTranslations = translations.message, messagesTranslations = translations.messages;
22787
23035
  var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, setIndexUiState = _useInstantSearch.setIndexUiState;
@@ -22799,8 +23047,14 @@
22799
23047
  itemComponent,
22800
23048
  userTools
22801
23049
  ]);
23050
+ // Inline layouts are always visible, so they don't require a `<ChatTrigger />`
23051
+ // (or AI mode) to be present. We detect this via a `$$inlineLayout` marker
23052
+ // set on the layout component, which is consistent across flavors.
23053
+ var isInlineLayoutComponent = typeof layoutComponent === 'function' && layoutComponent.$$inlineLayout === true;
23054
+ var effectiveDisableTriggerValidation = disableTriggerValidation || isInlineLayoutComponent;
22802
23055
  var chatState = useChat(_object_spread_props(_object_spread({}, props), {
22803
- tools: tools
23056
+ tools: tools,
23057
+ disableTriggerValidation: effectiveDisableTriggerValidation
22804
23058
  }));
22805
23059
  var messages = chatState.messages, sendMessage = chatState.sendMessage, status = chatState.status, regenerate = chatState.regenerate, stop = chatState.stop, error = chatState.error, input = chatState.input, setInput = chatState.setInput, open = chatState.open, setOpen = chatState.setOpen, isClearing = chatState.isClearing, clearMessages = chatState.clearMessages, onClearTransitionEnd = chatState.onClearTransitionEnd, toolsFromConnector = chatState.tools, suggestions = chatState.suggestions, onFeedback = chatState.sendChatMessageFeedback, feedbackState = chatState.feedbackState;
22806
23060
  React.useImperativeHandle(ref, function() {
@@ -22839,15 +23093,7 @@
22839
23093
  layoutComponent: layoutComponent,
22840
23094
  headerComponent: headerComponent,
22841
23095
  promptComponent: promptComponent,
22842
- toggleButtonComponent: toggleButtonComponent,
22843
23096
  suggestionsComponent: suggestionsComponent,
22844
- toggleButtonProps: _object_spread({
22845
- open: open,
22846
- onClick: function onClick() {
22847
- return setOpen(!open);
22848
- },
22849
- toggleIconComponent: toggleButtonIconComponent
22850
- }, toggleButtonProps),
22851
23097
  headerProps: _object_spread({
22852
23098
  onClose: function onClose() {
22853
23099
  return setOpen(false);
@@ -22864,13 +23110,14 @@
22864
23110
  maximizeIconComponent: headerMaximizeIconComponent,
22865
23111
  translations: headerTranslations
22866
23112
  }, headerProps),
22867
- messagesProps: _object_spread({
23113
+ messagesProps: _object_spread_props(_object_spread({
22868
23114
  status: status,
22869
23115
  onReload: function onReload(messageId) {
22870
23116
  return regenerate({
22871
23117
  messageId: messageId
22872
23118
  });
22873
23119
  },
23120
+ onNewConversation: clearMessages,
22874
23121
  onClose: function onClose() {
22875
23122
  return setOpen(false);
22876
23123
  },
@@ -22902,7 +23149,9 @@
22902
23149
  }, messagesProps === null || messagesProps === void 0 ? void 0 : messagesProps.userMessageProps),
22903
23150
  translations: messagesTranslations,
22904
23151
  messageTranslations: messageTranslations
22905
- }, messagesProps),
23152
+ }, messagesProps), {
23153
+ error: error
23154
+ }),
22906
23155
  promptProps: _object_spread({
22907
23156
  promptRef: promptRef,
22908
23157
  status: status,
@@ -22936,6 +23185,38 @@
22936
23185
  }
22937
23186
  var Chat = /*#__PURE__*/ React.forwardRef(ChatInner);
22938
23187
 
23188
+ var ChatToggleButton = createChatToggleButtonComponent({
23189
+ createElement: React.createElement,
23190
+ Fragment: React.Fragment
23191
+ });
23192
+ function ChatTrigger(_0) {
23193
+ var classNames = _0.classNames, toggleIconComponent = _0.toggleIconComponent, onClick = _0.onClick, _0_floating = _0.floating, floating = _0_floating === void 0 ? true : _0_floating, props = _object_without_properties(_0, [
23194
+ "classNames",
23195
+ "toggleIconComponent",
23196
+ "onClick",
23197
+ "floating"
23198
+ ]);
23199
+ var _useChatTrigger = useChatTrigger({}, {
23200
+ $$widgetType: 'ais.chatTrigger'
23201
+ }), open = _useChatTrigger.open, toggleOpen = _useChatTrigger.toggleOpen;
23202
+ var handleClick = function handleClick() {
23203
+ toggleOpen();
23204
+ onClick === null || onClick === void 0 ? void 0 : onClick();
23205
+ };
23206
+ var rootClassName = [
23207
+ floating && 'ais-ChatToggleButton--floating',
23208
+ classNames === null || classNames === void 0 ? void 0 : classNames.root
23209
+ ].filter(Boolean).flat();
23210
+ return /*#__PURE__*/ React.createElement(ChatToggleButton, _object_spread({
23211
+ open: open,
23212
+ onClick: handleClick,
23213
+ classNames: _object_spread_props(_object_spread({}, classNames), {
23214
+ root: rootClassName
23215
+ }),
23216
+ toggleIconComponent: toggleIconComponent
23217
+ }, props));
23218
+ }
23219
+
22939
23220
  function ClearRefinements$1(_0) {
22940
23221
  var _0_classNames = _0.classNames, classNames = _0_classNames === void 0 ? {} : _0_classNames, _0_disabled = _0.disabled, disabled = _0_disabled === void 0 ? false : _0_disabled, _0_onClick = _0.onClick, onClick = _0_onClick === void 0 ? function() {} : _0_onClick, translations = _0.translations, props = _object_without_properties(_0, [
22941
23222
  "classNames",
@@ -24298,9 +24579,11 @@
24298
24579
  ]);
24299
24580
  var _useSearchBox = useSearchBox({
24300
24581
  queryHook: queryHook
24301
- }, {
24582
+ }, _object_spread({
24302
24583
  $$widgetType: 'ais.searchBox'
24303
- }), query = _useSearchBox.query, refine = _useSearchBox.refine, isSearchStalled = _useSearchBox.isSearchStalled;
24584
+ }, aiMode ? {
24585
+ opensChat: true
24586
+ } : {})), query = _useSearchBox.query, refine = _useSearchBox.refine, isSearchStalled = _useSearchBox.isSearchStalled;
24304
24587
  var indexRenderState = useInstantSearch().indexRenderState;
24305
24588
  var _useState = _sliced_to_array(React.useState(query), 2), inputValue = _useState[0], setInputValue = _useState[1];
24306
24589
  var inputRef = React.useRef(null);
@@ -24712,6 +24995,7 @@
24712
24995
  exports.ChatMessageLoader = ChatMessageLoader;
24713
24996
  exports.ChatOverlayLayout = ChatOverlayLayout;
24714
24997
  exports.ChatSidePanelLayout = ChatSidePanelLayout;
24998
+ exports.ChatTrigger = ChatTrigger;
24715
24999
  exports.ClearRefinements = ClearRefinements;
24716
25000
  exports.Configure = Configure;
24717
25001
  exports.CurrentRefinements = CurrentRefinements;
@@ -24757,6 +25041,7 @@
24757
25041
  exports.useAutocomplete = useAutocomplete;
24758
25042
  exports.useBreadcrumb = useBreadcrumb;
24759
25043
  exports.useChat = useChat;
25044
+ exports.useChatTrigger = useChatTrigger;
24760
25045
  exports.useClearRefinements = useClearRefinements;
24761
25046
  exports.useConfigure = useConfigure;
24762
25047
  exports.useConnector = useConnector;