react-instantsearch-core 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.
- package/dist/cjs/connectors/useChatTrigger.js +18 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/es/connectors/useChatTrigger.d.ts +4 -0
- package/dist/es/connectors/useChatTrigger.js +9 -0
- package/dist/es/hooks/useConnector.d.ts +1 -0
- package/dist/es/index.d.ts +1 -0
- package/dist/es/index.js +1 -0
- package/dist/es/version.d.ts +1 -1
- package/dist/es/version.js +1 -1
- package/dist/umd/ReactInstantSearchCore.js +344 -73
- package/dist/umd/ReactInstantSearchCore.min.js +3 -3
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! React InstantSearch Core 7.
|
|
1
|
+
/*! React InstantSearch Core 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.
|
|
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$
|
|
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$
|
|
5999
|
+
throw new Error(withUsage$v('The `searchParameters` option expects an object.'));
|
|
6000
6000
|
}
|
|
6001
6001
|
var connectorState = {};
|
|
6002
6002
|
function refine(helper) {
|
|
@@ -7651,13 +7651,13 @@
|
|
|
7651
7651
|
return null;
|
|
7652
7652
|
}
|
|
7653
7653
|
|
|
7654
|
-
var withUsage$
|
|
7654
|
+
var withUsage$u = createDocumentationMessageGenerator({
|
|
7655
7655
|
name: 'dynamic-widgets',
|
|
7656
7656
|
connector: true
|
|
7657
7657
|
});
|
|
7658
7658
|
var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
|
|
7659
7659
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
7660
|
-
checkRendering(renderFn, withUsage$
|
|
7660
|
+
checkRendering(renderFn, withUsage$u());
|
|
7661
7661
|
return function(widgetParams) {
|
|
7662
7662
|
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 ? [
|
|
7663
7663
|
'*'
|
|
@@ -7667,10 +7667,10 @@
|
|
|
7667
7667
|
if (!(widgets && Array.isArray(widgets) && widgets.every(function(widget) {
|
|
7668
7668
|
return (typeof widget === "undefined" ? "undefined" : _type_of(widget)) === 'object';
|
|
7669
7669
|
}))) {
|
|
7670
|
-
throw new Error(withUsage$
|
|
7670
|
+
throw new Error(withUsage$u('The `widgets` option expects an array of widgets.'));
|
|
7671
7671
|
}
|
|
7672
7672
|
if (!Array.isArray(facets)) {
|
|
7673
|
-
throw new Error(withUsage$
|
|
7673
|
+
throw new Error(withUsage$u("The `facets` option only accepts an array of facets, you passed ".concat(JSON.stringify(facets))));
|
|
7674
7674
|
}
|
|
7675
7675
|
var localWidgets = new Map();
|
|
7676
7676
|
return {
|
|
@@ -7772,7 +7772,7 @@
|
|
|
7772
7772
|
results: results
|
|
7773
7773
|
});
|
|
7774
7774
|
if (!Array.isArray(attributesToRender)) {
|
|
7775
|
-
throw new Error(withUsage$
|
|
7775
|
+
throw new Error(withUsage$u('The `transformItems` option expects a function that returns an Array.'));
|
|
7776
7776
|
}
|
|
7777
7777
|
return {
|
|
7778
7778
|
attributesToRender: attributesToRender,
|
|
@@ -8094,19 +8094,19 @@
|
|
|
8094
8094
|
return toFeedSearchResults(lastResults._state, raw);
|
|
8095
8095
|
});
|
|
8096
8096
|
}
|
|
8097
|
-
var withUsage$
|
|
8097
|
+
var withUsage$t = createDocumentationMessageGenerator({
|
|
8098
8098
|
name: 'feeds',
|
|
8099
8099
|
connector: true
|
|
8100
8100
|
});
|
|
8101
8101
|
var connectFeeds = function connectFeeds(renderFn) {
|
|
8102
8102
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
8103
|
-
checkRendering(renderFn, withUsage$
|
|
8103
|
+
checkRendering(renderFn, withUsage$t());
|
|
8104
8104
|
return function(widgetParams) {
|
|
8105
8105
|
var isolated = widgetParams.isolated, _widgetParams_transformFeeds = widgetParams.transformFeeds, transformFeeds = _widgetParams_transformFeeds === void 0 ? function(feeds) {
|
|
8106
8106
|
return feeds;
|
|
8107
8107
|
} : _widgetParams_transformFeeds;
|
|
8108
8108
|
if (isolated !== false) {
|
|
8109
|
-
throw new Error(withUsage$
|
|
8109
|
+
throw new Error(withUsage$t('The `isolated` option currently only supports `false`.'));
|
|
8110
8110
|
}
|
|
8111
8111
|
return {
|
|
8112
8112
|
$$type: 'ais.feeds',
|
|
@@ -8114,7 +8114,7 @@
|
|
|
8114
8114
|
init: function init(initOptions) {
|
|
8115
8115
|
var instantSearchInstance = initOptions.instantSearchInstance;
|
|
8116
8116
|
if (!instantSearchInstance.compositionID) {
|
|
8117
|
-
throw new Error(withUsage$
|
|
8117
|
+
throw new Error(withUsage$t('The `feeds` widget requires a composition-based InstantSearch instance (compositionID must be set).'));
|
|
8118
8118
|
}
|
|
8119
8119
|
hydrateFeedsFromInitialResultsIfNeeded(instantSearchInstance, initOptions.parent);
|
|
8120
8120
|
renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
|
|
@@ -8160,12 +8160,12 @@
|
|
|
8160
8160
|
];
|
|
8161
8161
|
feedIDs = transformFeeds(feedIDs);
|
|
8162
8162
|
if (!Array.isArray(feedIDs)) {
|
|
8163
|
-
throw new Error(withUsage$
|
|
8163
|
+
throw new Error(withUsage$t('The `transformFeeds` option expects a function that returns an Array.'));
|
|
8164
8164
|
}
|
|
8165
8165
|
if (!feedIDs.every(function(feedID) {
|
|
8166
8166
|
return typeof feedID === 'string';
|
|
8167
8167
|
})) {
|
|
8168
|
-
throw new Error(withUsage$
|
|
8168
|
+
throw new Error(withUsage$t('The `transformFeeds` option expects a function that returns an array of feed IDs (strings).'));
|
|
8169
8169
|
}
|
|
8170
8170
|
return {
|
|
8171
8171
|
feedIDs: feedIDs,
|
|
@@ -8276,7 +8276,7 @@
|
|
|
8276
8276
|
}));
|
|
8277
8277
|
}
|
|
8278
8278
|
|
|
8279
|
-
var withUsage$
|
|
8279
|
+
var withUsage$s = createDocumentationMessageGenerator({
|
|
8280
8280
|
name: 'index-widget'
|
|
8281
8281
|
});
|
|
8282
8282
|
/**
|
|
@@ -8370,7 +8370,7 @@
|
|
|
8370
8370
|
}
|
|
8371
8371
|
var index = function index(widgetParams) {
|
|
8372
8372
|
if (widgetParams === undefined || widgetParams.indexName === undefined && !widgetParams.EXPERIMENTAL_isolated) {
|
|
8373
|
-
throw new Error(withUsage$
|
|
8373
|
+
throw new Error(withUsage$s('The `indexName` option is required.'));
|
|
8374
8374
|
}
|
|
8375
8375
|
// When isolated=true, we use an empty string as the default indexName.
|
|
8376
8376
|
// This is intentional: isolated indices do not require a real index name.
|
|
@@ -8460,7 +8460,7 @@
|
|
|
8460
8460
|
addWidgets: function addWidgets(widgets) {
|
|
8461
8461
|
var _this = this;
|
|
8462
8462
|
if (!Array.isArray(widgets)) {
|
|
8463
|
-
throw new Error(withUsage$
|
|
8463
|
+
throw new Error(withUsage$s('The `addWidgets` method expects an array of widgets.'));
|
|
8464
8464
|
}
|
|
8465
8465
|
var flatWidgets = widgets.reduce(function(acc, w) {
|
|
8466
8466
|
return acc.concat(Array.isArray(w) ? w : [
|
|
@@ -8470,7 +8470,7 @@
|
|
|
8470
8470
|
if (flatWidgets.some(function(widget) {
|
|
8471
8471
|
return typeof widget.init !== 'function' && typeof widget.render !== 'function';
|
|
8472
8472
|
})) {
|
|
8473
|
-
throw new Error(withUsage$
|
|
8473
|
+
throw new Error(withUsage$s('The widget definition expects a `render` and/or an `init` method.'));
|
|
8474
8474
|
}
|
|
8475
8475
|
flatWidgets.forEach(function(widget) {
|
|
8476
8476
|
widget.parent = _this;
|
|
@@ -8530,7 +8530,7 @@
|
|
|
8530
8530
|
removeWidgets: function removeWidgets(widgets) {
|
|
8531
8531
|
var _this = this;
|
|
8532
8532
|
if (!Array.isArray(widgets)) {
|
|
8533
|
-
throw new Error(withUsage$
|
|
8533
|
+
throw new Error(withUsage$s('The `removeWidgets` method expects an array of widgets.'));
|
|
8534
8534
|
}
|
|
8535
8535
|
var flatWidgets = widgets.reduce(function(acc, w) {
|
|
8536
8536
|
return acc.concat(Array.isArray(w) ? w : [
|
|
@@ -8540,7 +8540,7 @@
|
|
|
8540
8540
|
if (flatWidgets.some(function(widget) {
|
|
8541
8541
|
return typeof widget.dispose !== 'function';
|
|
8542
8542
|
})) {
|
|
8543
|
-
throw new Error(withUsage$
|
|
8543
|
+
throw new Error(withUsage$s('The widget definition expects a `dispose` method.'));
|
|
8544
8544
|
}
|
|
8545
8545
|
localWidgets = localWidgets.filter(function(widget) {
|
|
8546
8546
|
return flatWidgets.indexOf(widget) === -1;
|
|
@@ -10853,9 +10853,9 @@
|
|
|
10853
10853
|
};
|
|
10854
10854
|
}
|
|
10855
10855
|
|
|
10856
|
-
var version = '4.
|
|
10856
|
+
var version = '4.101.0';
|
|
10857
10857
|
|
|
10858
|
-
var withUsage$
|
|
10858
|
+
var withUsage$r = createDocumentationMessageGenerator({
|
|
10859
10859
|
name: 'instantsearch'
|
|
10860
10860
|
});
|
|
10861
10861
|
function defaultCreateURL() {
|
|
@@ -10911,7 +10911,7 @@
|
|
|
10911
10911
|
_this.setMaxListeners(100);
|
|
10912
10912
|
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;
|
|
10913
10913
|
if (searchClient === null) {
|
|
10914
|
-
throw new Error(withUsage$
|
|
10914
|
+
throw new Error(withUsage$r('The `searchClient` option is required.'));
|
|
10915
10915
|
}
|
|
10916
10916
|
if (typeof searchClient.search !== 'function') {
|
|
10917
10917
|
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/");
|
|
@@ -10920,7 +10920,7 @@
|
|
|
10920
10920
|
searchClient.addAlgoliaAgent("instantsearch.js (".concat(version, ")"));
|
|
10921
10921
|
}
|
|
10922
10922
|
if (insightsClient && typeof insightsClient !== 'function') {
|
|
10923
|
-
throw new Error(withUsage$
|
|
10923
|
+
throw new Error(withUsage$r('The `insightsClient` option should be a function.'));
|
|
10924
10924
|
}
|
|
10925
10925
|
_this.client = searchClient;
|
|
10926
10926
|
_this.future = future;
|
|
@@ -11068,12 +11068,12 @@
|
|
|
11068
11068
|
* @param widgets The array of widgets to add to InstantSearch.
|
|
11069
11069
|
*/ function addWidgets(widgets) {
|
|
11070
11070
|
if (!Array.isArray(widgets)) {
|
|
11071
|
-
throw new Error(withUsage$
|
|
11071
|
+
throw new Error(withUsage$r('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
|
|
11072
11072
|
}
|
|
11073
11073
|
if (this.compositionID && widgets.some(function(w) {
|
|
11074
11074
|
return !Array.isArray(w) && isIndexWidget(w) && !w._isolated;
|
|
11075
11075
|
})) {
|
|
11076
|
-
throw new Error(withUsage$
|
|
11076
|
+
throw new Error(withUsage$r('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
|
|
11077
11077
|
}
|
|
11078
11078
|
this.mainIndex.addWidgets(widgets);
|
|
11079
11079
|
return this;
|
|
@@ -11102,7 +11102,7 @@
|
|
|
11102
11102
|
* The widgets must implement a `dispose()` method to clear their states.
|
|
11103
11103
|
*/ function removeWidgets(widgets) {
|
|
11104
11104
|
if (!Array.isArray(widgets)) {
|
|
11105
|
-
throw new Error(withUsage$
|
|
11105
|
+
throw new Error(withUsage$r('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
|
|
11106
11106
|
}
|
|
11107
11107
|
this.mainIndex.removeWidgets(widgets);
|
|
11108
11108
|
return this;
|
|
@@ -11116,7 +11116,7 @@
|
|
|
11116
11116
|
*/ function start() {
|
|
11117
11117
|
var _this = this;
|
|
11118
11118
|
if (this.started) {
|
|
11119
|
-
throw new Error(withUsage$
|
|
11119
|
+
throw new Error(withUsage$r('The `start` method has already been called once.'));
|
|
11120
11120
|
}
|
|
11121
11121
|
// This Helper is used for the queries, we don't care about its state. The
|
|
11122
11122
|
// states are managed at the `index` level. We use this Helper to create
|
|
@@ -11318,7 +11318,7 @@
|
|
|
11318
11318
|
var _this = this;
|
|
11319
11319
|
var callOnStateChange = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
|
|
11320
11320
|
if (!this.mainHelper) {
|
|
11321
|
-
throw new Error(withUsage$
|
|
11321
|
+
throw new Error(withUsage$r('The `start` method needs to be called before `setUiState`.'));
|
|
11322
11322
|
}
|
|
11323
11323
|
// We refresh the index UI state to update the local UI state that the
|
|
11324
11324
|
// main index passes to the function form of `setUiState`.
|
|
@@ -11355,7 +11355,7 @@
|
|
|
11355
11355
|
value: function createURL() {
|
|
11356
11356
|
var nextState = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
11357
11357
|
if (!this.started) {
|
|
11358
|
-
throw new Error(withUsage$
|
|
11358
|
+
throw new Error(withUsage$r('The `start` method needs to be called before `createURL`.'));
|
|
11359
11359
|
}
|
|
11360
11360
|
return this._createURL(nextState);
|
|
11361
11361
|
}
|
|
@@ -11364,7 +11364,7 @@
|
|
|
11364
11364
|
key: "refresh",
|
|
11365
11365
|
value: function refresh() {
|
|
11366
11366
|
if (!this.mainHelper) {
|
|
11367
|
-
throw new Error(withUsage$
|
|
11367
|
+
throw new Error(withUsage$r('The `start` method needs to be called before `refresh`.'));
|
|
11368
11368
|
}
|
|
11369
11369
|
this.mainHelper.clearCache().search();
|
|
11370
11370
|
}
|
|
@@ -11890,13 +11890,13 @@
|
|
|
11890
11890
|
}, children);
|
|
11891
11891
|
}
|
|
11892
11892
|
|
|
11893
|
-
var withUsage$
|
|
11893
|
+
var withUsage$q = createDocumentationMessageGenerator({
|
|
11894
11894
|
name: 'autocomplete',
|
|
11895
11895
|
connector: true
|
|
11896
11896
|
});
|
|
11897
11897
|
var connectAutocomplete = function connectAutocomplete(renderFn) {
|
|
11898
11898
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
11899
|
-
checkRendering(renderFn, withUsage$
|
|
11899
|
+
checkRendering(renderFn, withUsage$q());
|
|
11900
11900
|
return function(widgetParams) {
|
|
11901
11901
|
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) {
|
|
11902
11902
|
return indices;
|
|
@@ -12005,20 +12005,20 @@
|
|
|
12005
12005
|
return useConnector(connectAutocomplete, props, additionalWidgetProperties);
|
|
12006
12006
|
}
|
|
12007
12007
|
|
|
12008
|
-
var withUsage$
|
|
12008
|
+
var withUsage$p = createDocumentationMessageGenerator({
|
|
12009
12009
|
name: 'breadcrumb',
|
|
12010
12010
|
connector: true
|
|
12011
12011
|
});
|
|
12012
12012
|
var connectBreadcrumb = function connectBreadcrumb(renderFn) {
|
|
12013
12013
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
12014
|
-
checkRendering(renderFn, withUsage$
|
|
12014
|
+
checkRendering(renderFn, withUsage$p());
|
|
12015
12015
|
var connectorState = {};
|
|
12016
12016
|
return function(widgetParams) {
|
|
12017
12017
|
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) {
|
|
12018
12018
|
return items;
|
|
12019
12019
|
} : _ref_transformItems;
|
|
12020
12020
|
if (!attributes || !Array.isArray(attributes) || attributes.length === 0) {
|
|
12021
|
-
throw new Error(withUsage$
|
|
12021
|
+
throw new Error(withUsage$p('The `attributes` option expects an array of strings.'));
|
|
12022
12022
|
}
|
|
12023
12023
|
var _attributes = _sliced_to_array(attributes, 1), hierarchicalFacetName = _attributes[0];
|
|
12024
12024
|
function getRefinedState(state, facetValue) {
|
|
@@ -12262,16 +12262,21 @@
|
|
|
12262
12262
|
onDone();
|
|
12263
12263
|
return;
|
|
12264
12264
|
}
|
|
12265
|
-
|
|
12266
|
-
|
|
12267
|
-
result.then
|
|
12268
|
-
|
|
12269
|
-
|
|
12270
|
-
|
|
12271
|
-
|
|
12272
|
-
|
|
12273
|
-
|
|
12274
|
-
|
|
12265
|
+
try {
|
|
12266
|
+
var result = onChunk(value);
|
|
12267
|
+
if (result && typeof result.then === 'function') {
|
|
12268
|
+
result.then(function() {
|
|
12269
|
+
return read();
|
|
12270
|
+
}, function(error) {
|
|
12271
|
+
reader.releaseLock();
|
|
12272
|
+
onError(error);
|
|
12273
|
+
});
|
|
12274
|
+
} else {
|
|
12275
|
+
read();
|
|
12276
|
+
}
|
|
12277
|
+
} catch (error) {
|
|
12278
|
+
reader.releaseLock();
|
|
12279
|
+
onError(error);
|
|
12275
12280
|
}
|
|
12276
12281
|
}, function(error) {
|
|
12277
12282
|
reader.releaseLock();
|
|
@@ -12281,6 +12286,49 @@
|
|
|
12281
12286
|
read();
|
|
12282
12287
|
}
|
|
12283
12288
|
|
|
12289
|
+
function _construct(Parent, args, Class) {
|
|
12290
|
+
if (_is_native_reflect_construct()) _construct = Reflect.construct;
|
|
12291
|
+
else {
|
|
12292
|
+
_construct = function construct(Parent, args, Class) {
|
|
12293
|
+
var a = [null];
|
|
12294
|
+
a.push.apply(a, args);
|
|
12295
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
12296
|
+
var instance = new Constructor();
|
|
12297
|
+
|
|
12298
|
+
if (Class) _set_prototype_of(instance, Class.prototype);
|
|
12299
|
+
|
|
12300
|
+
return instance;
|
|
12301
|
+
};
|
|
12302
|
+
}
|
|
12303
|
+
|
|
12304
|
+
return _construct.apply(null, arguments);
|
|
12305
|
+
}
|
|
12306
|
+
|
|
12307
|
+
function _is_native_function(fn) {
|
|
12308
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
12309
|
+
}
|
|
12310
|
+
|
|
12311
|
+
function _wrap_native_super(Class) {
|
|
12312
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
12313
|
+
_wrap_native_super = function(Class) {
|
|
12314
|
+
if (Class === null || !_is_native_function(Class)) return Class;
|
|
12315
|
+
if (typeof Class !== "function") throw new TypeError("Super expression must either be null or a function");
|
|
12316
|
+
if (typeof _cache !== "undefined") {
|
|
12317
|
+
if (_cache.has(Class)) return _cache.get(Class);
|
|
12318
|
+
_cache.set(Class, Wrapper);
|
|
12319
|
+
}
|
|
12320
|
+
|
|
12321
|
+
function Wrapper() {
|
|
12322
|
+
return _construct(Class, arguments, _get_prototype_of(this).constructor);
|
|
12323
|
+
}
|
|
12324
|
+
Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } });
|
|
12325
|
+
|
|
12326
|
+
return _set_prototype_of(Wrapper, Class);
|
|
12327
|
+
};
|
|
12328
|
+
|
|
12329
|
+
return _wrap_native_super(Class);
|
|
12330
|
+
}
|
|
12331
|
+
|
|
12284
12332
|
function generateId() {
|
|
12285
12333
|
return Math.random().toString(36).substring(2, 9);
|
|
12286
12334
|
}
|
|
@@ -12353,6 +12401,49 @@
|
|
|
12353
12401
|
}
|
|
12354
12402
|
return Promise.resolve(value);
|
|
12355
12403
|
}
|
|
12404
|
+
/**
|
|
12405
|
+
* Error raised when the upstream stream emits a `data-guardrail-violation`
|
|
12406
|
+
* chunk. The `message` carries the service-provided `fallbackResponse`, which
|
|
12407
|
+
* is intentionally surfaced verbatim through the chat error UI (unlike
|
|
12408
|
+
* generic cost-control / 4xx errors, where the raw API message is hidden
|
|
12409
|
+
* behind a friendly default).
|
|
12410
|
+
*
|
|
12411
|
+
* Detection across package boundaries should rely on `error.name` rather than
|
|
12412
|
+
* `instanceof` to avoid issues with mixed module copies in bundled apps.
|
|
12413
|
+
*/ var GuardrailViolationError = /*#__PURE__*/ function(Error1) {
|
|
12414
|
+
_inherits(GuardrailViolationError, Error1);
|
|
12415
|
+
function GuardrailViolationError(message) {
|
|
12416
|
+
_class_call_check(this, GuardrailViolationError);
|
|
12417
|
+
var _this;
|
|
12418
|
+
_this = _call_super(this, GuardrailViolationError, [
|
|
12419
|
+
message
|
|
12420
|
+
]);
|
|
12421
|
+
_this.name = 'GuardrailViolationError';
|
|
12422
|
+
return _this;
|
|
12423
|
+
}
|
|
12424
|
+
return GuardrailViolationError;
|
|
12425
|
+
}(_wrap_native_super(Error));
|
|
12426
|
+
/**
|
|
12427
|
+
* Reads a non-empty `message` field off a JSON-serialized error envelope.
|
|
12428
|
+
*
|
|
12429
|
+
* Both transports backing `AbstractChat` (stream `error` chunks and HTTP error
|
|
12430
|
+
* responses) serialize errors as `{"message": "...", ...}` — the same shape as
|
|
12431
|
+
* the shared `ErrorResponse` on the API side. Returns the trimmed message if
|
|
12432
|
+
* the input is such a JSON object, otherwise `undefined`.
|
|
12433
|
+
*/ function tryParseErrorMessage(text) {
|
|
12434
|
+
try {
|
|
12435
|
+
var parsed = JSON.parse(text);
|
|
12436
|
+
if (parsed && (typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) === 'object' && !Array.isArray(parsed) && typeof parsed.message === 'string') {
|
|
12437
|
+
var message = parsed.message.trim();
|
|
12438
|
+
if (message) {
|
|
12439
|
+
return message;
|
|
12440
|
+
}
|
|
12441
|
+
}
|
|
12442
|
+
} catch (unused) {
|
|
12443
|
+
// Not JSON — caller falls back to its own default.
|
|
12444
|
+
}
|
|
12445
|
+
return undefined;
|
|
12446
|
+
}
|
|
12356
12447
|
|
|
12357
12448
|
var tryParseJson = function tryParseJson(value) {
|
|
12358
12449
|
try {
|
|
@@ -12431,7 +12522,7 @@
|
|
|
12431
12522
|
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;
|
|
12432
12523
|
var _this1 = this;
|
|
12433
12524
|
_class_call_check(this, AbstractChat);
|
|
12434
|
-
_define_property(this, "
|
|
12525
|
+
_define_property(this, "conversationId", void 0);
|
|
12435
12526
|
_define_property(this, "generateId", void 0);
|
|
12436
12527
|
_define_property(this, "state", void 0);
|
|
12437
12528
|
_define_property(this, "transport", void 0);
|
|
@@ -12587,12 +12678,6 @@
|
|
|
12587
12678
|
}
|
|
12588
12679
|
});
|
|
12589
12680
|
/**
|
|
12590
|
-
* Regenerate the chat id. Use this to start a fresh conversation on the
|
|
12591
|
-
* server while keeping the same Chat instance and its registered listeners.
|
|
12592
|
-
*/ _define_property(this, "regenerateId", function() {
|
|
12593
|
-
_this.id = _this.generateId();
|
|
12594
|
-
});
|
|
12595
|
-
/**
|
|
12596
12681
|
* Add a tool result for a tool call.
|
|
12597
12682
|
*/ _define_property(this, "addToolResult", function(param) {
|
|
12598
12683
|
var tool = param.tool, toolCallId = param.toolCallId, output = param.output;
|
|
@@ -12647,7 +12732,7 @@
|
|
|
12647
12732
|
});
|
|
12648
12733
|
return Promise.resolve();
|
|
12649
12734
|
});
|
|
12650
|
-
this.
|
|
12735
|
+
this.conversationId = id;
|
|
12651
12736
|
this.generateId = generateId$1;
|
|
12652
12737
|
this.state = state;
|
|
12653
12738
|
this.transport = transport;
|
|
@@ -12659,6 +12744,12 @@
|
|
|
12659
12744
|
this.shouldRepairToolInput = shouldRepairToolInput;
|
|
12660
12745
|
}
|
|
12661
12746
|
_create_class(AbstractChat, [
|
|
12747
|
+
{
|
|
12748
|
+
key: "id",
|
|
12749
|
+
get: function get() {
|
|
12750
|
+
return this.conversationId;
|
|
12751
|
+
}
|
|
12752
|
+
},
|
|
12662
12753
|
{
|
|
12663
12754
|
key: "status",
|
|
12664
12755
|
get: /**
|
|
@@ -12688,6 +12779,17 @@
|
|
|
12688
12779
|
return this.state.error;
|
|
12689
12780
|
}
|
|
12690
12781
|
},
|
|
12782
|
+
{
|
|
12783
|
+
/**
|
|
12784
|
+
* Starts a new server-side conversation thread by rotating the id sent as
|
|
12785
|
+
* `chatId` / `id` on the next request. The InstantSearch connector calls this
|
|
12786
|
+
* after the user clears the transcript so completions are not tied to prior
|
|
12787
|
+
* context.
|
|
12788
|
+
*/ key: "resetConversationId",
|
|
12789
|
+
value: function resetConversationId() {
|
|
12790
|
+
this.conversationId = this.generateId();
|
|
12791
|
+
}
|
|
12792
|
+
},
|
|
12691
12793
|
{
|
|
12692
12794
|
key: "messages",
|
|
12693
12795
|
get: function get() {
|
|
@@ -13056,8 +13158,7 @@
|
|
|
13056
13158
|
var updatedParts7 = _to_consumable_array(currentMessage.parts);
|
|
13057
13159
|
var existingPart2 = updatedParts7[toolIndex2];
|
|
13058
13160
|
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
13059
|
-
existingPart2.rawOutput
|
|
13060
|
-
var rest = _object_without_properties(existingPart2, [
|
|
13161
|
+
var _ignored = existingPart2.rawOutput, rest = _object_without_properties(existingPart2, [
|
|
13061
13162
|
"rawOutput"
|
|
13062
13163
|
]);
|
|
13063
13164
|
updatedParts7[toolIndex2] = _object_spread_props(_object_spread({}, rest), {
|
|
@@ -13085,10 +13186,7 @@
|
|
|
13085
13186
|
delete toolRawOutputByCallId[chunk.toolCallId];
|
|
13086
13187
|
var updatedParts8 = _to_consumable_array(currentMessage.parts);
|
|
13087
13188
|
var existingPart3 = updatedParts8[toolIndex3];
|
|
13088
|
-
|
|
13089
|
-
existingPart3.rawOutput; // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
13090
|
-
existingPart3.preliminary;
|
|
13091
|
-
var rest1 = _object_without_properties(existingPart3, [
|
|
13189
|
+
var _ignoredRawOutput = existingPart3.rawOutput, _ignoredPreliminary = existingPart3.preliminary, rest1 = _object_without_properties(existingPart3, [
|
|
13092
13190
|
"rawOutput",
|
|
13093
13191
|
"preliminary"
|
|
13094
13192
|
]);
|
|
@@ -13183,7 +13281,8 @@
|
|
|
13183
13281
|
case 'error':
|
|
13184
13282
|
{
|
|
13185
13283
|
isError = true;
|
|
13186
|
-
|
|
13284
|
+
var text = chunk.errorText.trim();
|
|
13285
|
+
throw new Error(tryParseErrorMessage(text) || text || 'Unknown error');
|
|
13187
13286
|
}
|
|
13188
13287
|
case 'abort':
|
|
13189
13288
|
{
|
|
@@ -13200,9 +13299,32 @@
|
|
|
13200
13299
|
}
|
|
13201
13300
|
break;
|
|
13202
13301
|
}
|
|
13302
|
+
// Surface guardrail violations through the error state, but
|
|
13303
|
+
// distinct from generic cost-control / 4xx errors: throw a
|
|
13304
|
+
// `GuardrailViolationError` so the UI can render the
|
|
13305
|
+
// service-provided `fallbackResponse` verbatim (it's authored for
|
|
13306
|
+
// end-user display) instead of the friendly default used for
|
|
13307
|
+
// opaque transport errors. Also discard any in-progress assistant
|
|
13308
|
+
// message so no partial text lingers above the fallback, and
|
|
13309
|
+
// clear the local cursor so the `onFinish` callback doesn't
|
|
13310
|
+
// receive a `currentMessage` that no longer exists in state.
|
|
13311
|
+
case 'data-guardrail-violation':
|
|
13312
|
+
{
|
|
13313
|
+
isError = true;
|
|
13314
|
+
if (currentMessageIndex >= 0) {
|
|
13315
|
+
_this.state.messages = _this.state.messages.slice(0, currentMessageIndex);
|
|
13316
|
+
currentMessage = undefined;
|
|
13317
|
+
currentMessageIndex = -1;
|
|
13318
|
+
}
|
|
13319
|
+
// `chunk.data` widens to `unknown` here: the chunk union also
|
|
13320
|
+
// carries a generic `data-${string}` member, and the literal
|
|
13321
|
+
// matches both, so narrowing can't pick the specific shape.
|
|
13322
|
+
var fallbackResponse = chunk.data.fallbackResponse;
|
|
13323
|
+
throw new GuardrailViolationError(fallbackResponse || 'Sorry, we are not able to generate a response at the moment.');
|
|
13324
|
+
}
|
|
13203
13325
|
default:
|
|
13204
13326
|
{
|
|
13205
|
-
// Handle data parts (data-*)
|
|
13327
|
+
// Handle generic data parts (data-*)
|
|
13206
13328
|
var chunkType = chunk.type;
|
|
13207
13329
|
if ((chunkType === null || chunkType === void 0 ? void 0 : chunkType.startsWith('data-')) && currentMessage) {
|
|
13208
13330
|
var dataPart = {
|
|
@@ -13469,6 +13591,41 @@
|
|
|
13469
13591
|
return Chat;
|
|
13470
13592
|
}(AbstractChat);
|
|
13471
13593
|
|
|
13594
|
+
// Centralizes the "open the chat from an entry point" behavior shared by the
|
|
13595
|
+
// SearchBox AI button, the Autocomplete AI button, prompt suggestions, and any
|
|
13596
|
+
// future entry point. The chat is always opened; the message is only sent when
|
|
13597
|
+
// it is non-empty and the chat is not already processing a message.
|
|
13598
|
+
// Returns true when a message was submitted, so callers can clear their input.
|
|
13599
|
+
function openChat(chatRenderState) {
|
|
13600
|
+
var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, message = _ref.message, referer = _ref.referer;
|
|
13601
|
+
var _ref1;
|
|
13602
|
+
var _chatRenderState_setOpen;
|
|
13603
|
+
if (!chatRenderState) {
|
|
13604
|
+
return false;
|
|
13605
|
+
}
|
|
13606
|
+
(_chatRenderState_setOpen = chatRenderState.setOpen) === null || _chatRenderState_setOpen === void 0 ? void 0 : _chatRenderState_setOpen.call(chatRenderState, true);
|
|
13607
|
+
var trimmed = (_ref1 = message === null || message === void 0 ? void 0 : message.trim()) !== null && _ref1 !== void 0 ? _ref1 : '';
|
|
13608
|
+
if (!trimmed) {
|
|
13609
|
+
var _chatRenderState_focusInput;
|
|
13610
|
+
(_chatRenderState_focusInput = chatRenderState.focusInput) === null || _chatRenderState_focusInput === void 0 ? void 0 : _chatRenderState_focusInput.call(chatRenderState);
|
|
13611
|
+
return false;
|
|
13612
|
+
}
|
|
13613
|
+
if (isChatBusy(chatRenderState) || !chatRenderState.sendMessage) {
|
|
13614
|
+
return false;
|
|
13615
|
+
}
|
|
13616
|
+
chatRenderState.sendMessage({
|
|
13617
|
+
text: trimmed
|
|
13618
|
+
}, referer ? {
|
|
13619
|
+
headers: {
|
|
13620
|
+
'x-algolia-referer': referer
|
|
13621
|
+
}
|
|
13622
|
+
} : undefined);
|
|
13623
|
+
return true;
|
|
13624
|
+
}
|
|
13625
|
+
function isChatBusy(chatRenderState) {
|
|
13626
|
+
return (chatRenderState === null || chatRenderState === void 0 ? void 0 : chatRenderState.status) === 'submitted' || (chatRenderState === null || chatRenderState === void 0 ? void 0 : chatRenderState.status) === 'streaming';
|
|
13627
|
+
}
|
|
13628
|
+
|
|
13472
13629
|
var SearchIndexToolType = 'algolia_search_index';
|
|
13473
13630
|
|
|
13474
13631
|
function flat(arr) {
|
|
@@ -13477,6 +13634,20 @@
|
|
|
13477
13634
|
}, []);
|
|
13478
13635
|
}
|
|
13479
13636
|
|
|
13637
|
+
/**
|
|
13638
|
+
* Reads a human-readable message from a failed HTTP response body when the
|
|
13639
|
+
* server returns JSON such as `{ "message": "..." }` (the shared
|
|
13640
|
+
* `ErrorResponse` shape used by every status code), falling back to the HTTP
|
|
13641
|
+
* status line when the body is empty or not parseable.
|
|
13642
|
+
*/ function getHttpErrorMessage(response) {
|
|
13643
|
+
var fallback = "HTTP error: ".concat(response.status, " ").concat(response.statusText);
|
|
13644
|
+
return response.text().then(function(text) {
|
|
13645
|
+
var _tryParseErrorMessage;
|
|
13646
|
+
return (_tryParseErrorMessage = tryParseErrorMessage(text)) !== null && _tryParseErrorMessage !== void 0 ? _tryParseErrorMessage : fallback;
|
|
13647
|
+
}).catch(function() {
|
|
13648
|
+
return fallback;
|
|
13649
|
+
});
|
|
13650
|
+
}
|
|
13480
13651
|
/**
|
|
13481
13652
|
* Abstract base class for HTTP-based chat transports.
|
|
13482
13653
|
*/ var HttpChatTransport = /*#__PURE__*/ function() {
|
|
@@ -13555,7 +13726,9 @@
|
|
|
13555
13726
|
credentials: credentials
|
|
13556
13727
|
}).then(function(response) {
|
|
13557
13728
|
if (!response.ok) {
|
|
13558
|
-
|
|
13729
|
+
return getHttpErrorMessage(response).then(function(message) {
|
|
13730
|
+
throw new Error(message);
|
|
13731
|
+
});
|
|
13559
13732
|
}
|
|
13560
13733
|
if (!response.body) {
|
|
13561
13734
|
throw new Error('Response body is empty');
|
|
@@ -13613,7 +13786,9 @@
|
|
|
13613
13786
|
if (response.status === 404) {
|
|
13614
13787
|
return null;
|
|
13615
13788
|
}
|
|
13616
|
-
|
|
13789
|
+
return getHttpErrorMessage(response).then(function(message) {
|
|
13790
|
+
throw new Error(message);
|
|
13791
|
+
});
|
|
13617
13792
|
}
|
|
13618
13793
|
if (!response.body) {
|
|
13619
13794
|
return null;
|
|
@@ -13649,7 +13824,7 @@
|
|
|
13649
13824
|
return DefaultChatTransport;
|
|
13650
13825
|
}(HttpChatTransport);
|
|
13651
13826
|
|
|
13652
|
-
var withUsage$
|
|
13827
|
+
var withUsage$o = createDocumentationMessageGenerator({
|
|
13653
13828
|
name: 'chat',
|
|
13654
13829
|
connector: true
|
|
13655
13830
|
});
|
|
@@ -13700,15 +13875,16 @@
|
|
|
13700
13875
|
}
|
|
13701
13876
|
var connectChat = function connectChat(renderFn) {
|
|
13702
13877
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
13703
|
-
checkRendering(renderFn, withUsage$
|
|
13878
|
+
checkRendering(renderFn, withUsage$o());
|
|
13704
13879
|
return function(widgetParams) {
|
|
13705
|
-
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, [
|
|
13880
|
+
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, [
|
|
13706
13881
|
"resume",
|
|
13707
13882
|
"tools",
|
|
13708
13883
|
"type",
|
|
13709
13884
|
"context",
|
|
13710
13885
|
"initialUserMessage",
|
|
13711
|
-
"initialMessages"
|
|
13886
|
+
"initialMessages",
|
|
13887
|
+
"disableTriggerValidation"
|
|
13712
13888
|
]);
|
|
13713
13889
|
var _chatInstance;
|
|
13714
13890
|
var input = '';
|
|
@@ -13720,6 +13896,7 @@
|
|
|
13720
13896
|
var focusInput;
|
|
13721
13897
|
var setIsClearing;
|
|
13722
13898
|
var setFeedbackState;
|
|
13899
|
+
var hasValidatedEntryPoints = false;
|
|
13723
13900
|
var agentId = 'agentId' in options ? options.agentId : undefined;
|
|
13724
13901
|
var feedbackState = {};
|
|
13725
13902
|
var _sendChatMessageFeedback;
|
|
@@ -13759,10 +13936,26 @@
|
|
|
13759
13936
|
var onClearTransitionEnd = function onClearTransitionEnd() {
|
|
13760
13937
|
setMessages([]);
|
|
13761
13938
|
_chatInstance.clearError();
|
|
13762
|
-
_chatInstance.
|
|
13939
|
+
_chatInstance.resetConversationId();
|
|
13763
13940
|
feedbackState = {};
|
|
13764
13941
|
setIsClearing(false);
|
|
13765
13942
|
};
|
|
13943
|
+
var validateEntryPoints = function validateEntryPoints(instantSearchInstance) {
|
|
13944
|
+
if (disableTriggerValidation || hasValidatedEntryPoints) {
|
|
13945
|
+
return;
|
|
13946
|
+
}
|
|
13947
|
+
// warning only relevant once mounted
|
|
13948
|
+
if (!instantSearchInstance.mainIndex) {
|
|
13949
|
+
return;
|
|
13950
|
+
}
|
|
13951
|
+
walkIndex(instantSearchInstance.mainIndex, function(indexWidget) {
|
|
13952
|
+
var widgets = indexWidget.getWidgets();
|
|
13953
|
+
if (widgets.some(function(w) {
|
|
13954
|
+
return w.opensChat === true;
|
|
13955
|
+
})) ;
|
|
13956
|
+
});
|
|
13957
|
+
hasValidatedEntryPoints = true;
|
|
13958
|
+
};
|
|
13766
13959
|
var makeChatInstance = function makeChatInstance(instantSearchInstance) {
|
|
13767
13960
|
var transport;
|
|
13768
13961
|
var client = instantSearchInstance.client;
|
|
@@ -13812,7 +14005,7 @@
|
|
|
13812
14005
|
}
|
|
13813
14006
|
if ('agentId' in options && options.agentId) {
|
|
13814
14007
|
if (!appId || !apiKey) {
|
|
13815
|
-
throw new Error(withUsage$
|
|
14008
|
+
throw new Error(withUsage$o('Could not extract Algolia credentials from the search client.'));
|
|
13816
14009
|
}
|
|
13817
14010
|
var baseApi = "https://".concat(appId, ".algolia.net/agent-studio/1/agents/").concat(agentId, "/completions?compatibilityMode=ai-sdk-5");
|
|
13818
14011
|
transport = new DefaultChatTransport({
|
|
@@ -13837,7 +14030,7 @@
|
|
|
13837
14030
|
});
|
|
13838
14031
|
}
|
|
13839
14032
|
if (!transport) {
|
|
13840
|
-
throw new Error(withUsage$
|
|
14033
|
+
throw new Error(withUsage$o('You need to provide either an `agentId` or a `transport`.'));
|
|
13841
14034
|
}
|
|
13842
14035
|
if ('chat' in options) {
|
|
13843
14036
|
return options.chat;
|
|
@@ -13889,6 +14082,7 @@
|
|
|
13889
14082
|
init: function init(initOptions) {
|
|
13890
14083
|
var _this = this;
|
|
13891
14084
|
var instantSearchInstance = initOptions.instantSearchInstance;
|
|
14085
|
+
validateEntryPoints(instantSearchInstance);
|
|
13892
14086
|
_chatInstance = makeChatInstance(instantSearchInstance);
|
|
13893
14087
|
var render = function render() {
|
|
13894
14088
|
renderFn(_object_spread_props(_object_spread({}, _this.getWidgetRenderState(initOptions)), {
|
|
@@ -13898,6 +14092,10 @@
|
|
|
13898
14092
|
setOpen = function setOpen(o) {
|
|
13899
14093
|
open = o;
|
|
13900
14094
|
render();
|
|
14095
|
+
// `open` is read by sibling widgets (e.g. `chatTrigger`) via the
|
|
14096
|
+
// shared `renderState`. Schedule a full re-render so they pick up
|
|
14097
|
+
// the new value instead of staying frozen on their initial state.
|
|
14098
|
+
initOptions.instantSearchInstance.scheduleRender();
|
|
13901
14099
|
};
|
|
13902
14100
|
focusInput = function focusInput() {
|
|
13903
14101
|
setOpen(true);
|
|
@@ -13918,7 +14116,7 @@
|
|
|
13918
14116
|
if (agentId && feedback) {
|
|
13919
14117
|
var _getAppIdAndApiKey = _sliced_to_array(getAppIdAndApiKey(initOptions.instantSearchInstance.client), 2), appId = _getAppIdAndApiKey[0], apiKey = _getAppIdAndApiKey[1];
|
|
13920
14118
|
if (!appId || !apiKey) {
|
|
13921
|
-
throw new Error(withUsage$
|
|
14119
|
+
throw new Error(withUsage$o('Could not extract Algolia credentials from the search client.'));
|
|
13922
14120
|
}
|
|
13923
14121
|
feedbackAbortController = new AbortController();
|
|
13924
14122
|
_sendChatMessageFeedback = function _sendChatMessageFeedback(messageId, vote) {
|
|
@@ -13959,6 +14157,7 @@
|
|
|
13959
14157
|
}), true);
|
|
13960
14158
|
},
|
|
13961
14159
|
render: function render(renderOptions) {
|
|
14160
|
+
validateEntryPoints(renderOptions.instantSearchInstance);
|
|
13962
14161
|
renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(renderOptions)), {
|
|
13963
14162
|
instantSearchInstance: renderOptions.instantSearchInstance
|
|
13964
14163
|
}), false);
|
|
@@ -14065,6 +14264,77 @@
|
|
|
14065
14264
|
return useConnector(connectChat, props, additionalWidgetProperties);
|
|
14066
14265
|
}
|
|
14067
14266
|
|
|
14267
|
+
var withUsage$n = createDocumentationMessageGenerator({
|
|
14268
|
+
name: 'chatTrigger',
|
|
14269
|
+
connector: true
|
|
14270
|
+
});
|
|
14271
|
+
// Reads the sibling chat widget's render state from the live cross-index
|
|
14272
|
+
// `instantSearchInstance.renderState` map. We resolve at call time so that
|
|
14273
|
+
// `toggleOpen` always sees the latest `open`/`setOpen` values.
|
|
14274
|
+
function getChatRenderState(options) {
|
|
14275
|
+
var _options_parent, _options_instantSearchInstance_renderState_indexId;
|
|
14276
|
+
var indexId = (_options_parent = options.parent) === null || _options_parent === void 0 ? void 0 : _options_parent.getIndexId();
|
|
14277
|
+
if (!indexId) return undefined;
|
|
14278
|
+
return (_options_instantSearchInstance_renderState_indexId = options.instantSearchInstance.renderState[indexId]) === null || _options_instantSearchInstance_renderState_indexId === void 0 ? void 0 : _options_instantSearchInstance_renderState_indexId.chat;
|
|
14279
|
+
}
|
|
14280
|
+
var connectChatTrigger = function connectChatTrigger(renderFn) {
|
|
14281
|
+
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
14282
|
+
checkRendering(renderFn, withUsage$n());
|
|
14283
|
+
return function(widgetParams) {
|
|
14284
|
+
var params = widgetParams !== null && widgetParams !== void 0 ? widgetParams : {};
|
|
14285
|
+
var lastOptions = null;
|
|
14286
|
+
function toggleOpen() {
|
|
14287
|
+
if (!lastOptions) return;
|
|
14288
|
+
var chatState = getChatRenderState(lastOptions);
|
|
14289
|
+
if (!chatState) return;
|
|
14290
|
+
if (chatState.open) {
|
|
14291
|
+
var _chatState_setOpen;
|
|
14292
|
+
(_chatState_setOpen = chatState.setOpen) === null || _chatState_setOpen === void 0 ? void 0 : _chatState_setOpen.call(chatState, false);
|
|
14293
|
+
} else {
|
|
14294
|
+
openChat(chatState);
|
|
14295
|
+
}
|
|
14296
|
+
}
|
|
14297
|
+
return {
|
|
14298
|
+
$$type: 'ais.chatTrigger',
|
|
14299
|
+
opensChat: true,
|
|
14300
|
+
init: function init(initOptions) {
|
|
14301
|
+
lastOptions = initOptions;
|
|
14302
|
+
renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
|
|
14303
|
+
instantSearchInstance: initOptions.instantSearchInstance
|
|
14304
|
+
}), true);
|
|
14305
|
+
},
|
|
14306
|
+
render: function render(renderOptions) {
|
|
14307
|
+
lastOptions = renderOptions;
|
|
14308
|
+
renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(renderOptions)), {
|
|
14309
|
+
instantSearchInstance: renderOptions.instantSearchInstance
|
|
14310
|
+
}), false);
|
|
14311
|
+
},
|
|
14312
|
+
dispose: function dispose() {
|
|
14313
|
+
unmountFn();
|
|
14314
|
+
},
|
|
14315
|
+
getWidgetRenderState: function getWidgetRenderState(renderOptions) {
|
|
14316
|
+
var _ref;
|
|
14317
|
+
var chatState = getChatRenderState(renderOptions);
|
|
14318
|
+
return {
|
|
14319
|
+
open: (_ref = chatState === null || chatState === void 0 ? void 0 : chatState.open) !== null && _ref !== void 0 ? _ref : false,
|
|
14320
|
+
toggleOpen: toggleOpen,
|
|
14321
|
+
widgetParams: params
|
|
14322
|
+
};
|
|
14323
|
+
},
|
|
14324
|
+
getRenderState: function getRenderState(renderState, renderOptions) {
|
|
14325
|
+
return _object_spread_props(_object_spread({}, renderState), {
|
|
14326
|
+
chatTrigger: this.getWidgetRenderState(renderOptions)
|
|
14327
|
+
});
|
|
14328
|
+
}
|
|
14329
|
+
};
|
|
14330
|
+
};
|
|
14331
|
+
};
|
|
14332
|
+
|
|
14333
|
+
function useChatTrigger() {
|
|
14334
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, additionalWidgetProperties = arguments.length > 1 ? arguments[1] : void 0;
|
|
14335
|
+
return useConnector(connectChatTrigger, props, additionalWidgetProperties);
|
|
14336
|
+
}
|
|
14337
|
+
|
|
14068
14338
|
var withUsage$m = createDocumentationMessageGenerator({
|
|
14069
14339
|
name: 'clear-refinements',
|
|
14070
14340
|
connector: true
|
|
@@ -18190,6 +18460,7 @@
|
|
|
18190
18460
|
exports.useAutocomplete = useAutocomplete;
|
|
18191
18461
|
exports.useBreadcrumb = useBreadcrumb;
|
|
18192
18462
|
exports.useChat = useChat;
|
|
18463
|
+
exports.useChatTrigger = useChatTrigger;
|
|
18193
18464
|
exports.useClearRefinements = useClearRefinements;
|
|
18194
18465
|
exports.useConfigure = useConfigure;
|
|
18195
18466
|
exports.useConnector = useConnector;
|