react-instantsearch 7.41.0 → 7.42.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/components/Carousel.js +3 -1
- package/dist/cjs/widgets/Autocomplete.js +1 -1
- package/dist/cjs/widgets/Chat.js +32 -9
- package/dist/cjs/widgets/PromptSuggestions.js +66 -0
- package/dist/cjs/widgets/chat/tools/DisplayResultsTool.js +36 -30
- package/dist/cjs/widgets/chat/tools/SearchIndexTool.js +1 -0
- package/dist/cjs/widgets/index.js +1 -0
- package/dist/es/components/Carousel.js +4 -2
- package/dist/es/index.js +1 -0
- package/dist/es/widgets/Autocomplete.js +1 -1
- package/dist/es/widgets/Chat.d.ts +4 -0
- package/dist/es/widgets/Chat.js +40 -17
- package/dist/es/widgets/PromptSuggestions.d.ts +23 -0
- package/dist/es/widgets/PromptSuggestions.js +57 -0
- package/dist/es/widgets/chat/tools/DisplayResultsTool.js +37 -31
- package/dist/es/widgets/chat/tools/SearchIndexTool.js +2 -1
- package/dist/es/widgets/index.d.ts +1 -0
- package/dist/es/widgets/index.js +1 -0
- package/dist/umd/ReactInstantSearch.js +1570 -362
- package/dist/umd/ReactInstantSearch.min.js +3 -3
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! React InstantSearch 7.
|
|
1
|
+
/*! React InstantSearch 7.42.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.42.0';
|
|
28
28
|
|
|
29
29
|
function _define_property(obj, key, value) {
|
|
30
30
|
if (key in obj) {
|
|
@@ -3919,7 +3919,7 @@
|
|
|
3919
3919
|
function requireVersion() {
|
|
3920
3920
|
if (hasRequiredVersion) return version$1;
|
|
3921
3921
|
hasRequiredVersion = 1;
|
|
3922
|
-
version$1 = '3.29.
|
|
3922
|
+
version$1 = '3.29.3';
|
|
3923
3923
|
return version$1;
|
|
3924
3924
|
}
|
|
3925
3925
|
|
|
@@ -5980,7 +5980,7 @@
|
|
|
5980
5980
|
}
|
|
5981
5981
|
}
|
|
5982
5982
|
|
|
5983
|
-
var withUsage$
|
|
5983
|
+
var withUsage$x = 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$x('The `searchParameters` option expects an object.'));
|
|
6000
6000
|
}
|
|
6001
6001
|
var connectorState = {};
|
|
6002
6002
|
function refine(helper) {
|
|
@@ -6267,6 +6267,38 @@
|
|
|
6267
6267
|
return stableValue;
|
|
6268
6268
|
}
|
|
6269
6269
|
|
|
6270
|
+
/**
|
|
6271
|
+
* Forwards the insights-related search parameters to every Recommend query.
|
|
6272
|
+
*
|
|
6273
|
+
* The insights middleware writes `userToken` and `clickAnalytics` on the main
|
|
6274
|
+
* helper's search state, which only feeds search queries: Recommend queries are
|
|
6275
|
+
* built from their own parameters and never read the search state. Without this,
|
|
6276
|
+
* recommendations can't be personalized, and their responses carry no `queryID`
|
|
6277
|
+
* for the connectors to attribute click and conversion events with.
|
|
6278
|
+
*
|
|
6279
|
+
* Parameters set on a widget win, so an explicit `queryParameters.userToken`
|
|
6280
|
+
* keeps overriding the middleware.
|
|
6281
|
+
*/ function addInsightsToRecommendParameters(recommendParameters, param) {
|
|
6282
|
+
var userToken = param.userToken, clickAnalytics = param.clickAnalytics;
|
|
6283
|
+
if (userToken === undefined && clickAnalytics === undefined) {
|
|
6284
|
+
return recommendParameters;
|
|
6285
|
+
}
|
|
6286
|
+
return new algoliasearchHelper.RecommendParameters({
|
|
6287
|
+
params: recommendParameters.params.map(function(params) {
|
|
6288
|
+
// v4 `TrendingFacetsQuery` doesn't include `queryParameters`, but the v5
|
|
6289
|
+
// API and the helper support them, like `connectTrendingFacets` does.
|
|
6290
|
+
var queryParameters = params.queryParameters;
|
|
6291
|
+
return _object_spread_props(_object_spread({}, params), {
|
|
6292
|
+
queryParameters: _object_spread({}, clickAnalytics === undefined ? {} : {
|
|
6293
|
+
clickAnalytics: clickAnalytics
|
|
6294
|
+
}, userToken === undefined ? {} : {
|
|
6295
|
+
userToken: userToken
|
|
6296
|
+
}, queryParameters)
|
|
6297
|
+
});
|
|
6298
|
+
})
|
|
6299
|
+
});
|
|
6300
|
+
}
|
|
6301
|
+
|
|
6270
6302
|
var id$1 = 0;
|
|
6271
6303
|
function addWidgetId(widget) {
|
|
6272
6304
|
if (widget.dependsOn !== 'recommend') {
|
|
@@ -7763,13 +7795,13 @@
|
|
|
7763
7795
|
return null;
|
|
7764
7796
|
}
|
|
7765
7797
|
|
|
7766
|
-
var withUsage$
|
|
7798
|
+
var withUsage$w = createDocumentationMessageGenerator({
|
|
7767
7799
|
name: 'dynamic-widgets',
|
|
7768
7800
|
connector: true
|
|
7769
7801
|
});
|
|
7770
7802
|
var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
|
|
7771
7803
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
7772
|
-
checkRendering(renderFn, withUsage$
|
|
7804
|
+
checkRendering(renderFn, withUsage$w());
|
|
7773
7805
|
return function(widgetParams) {
|
|
7774
7806
|
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 ? [
|
|
7775
7807
|
'*'
|
|
@@ -7779,10 +7811,10 @@
|
|
|
7779
7811
|
if (!(widgets && Array.isArray(widgets) && widgets.every(function(widget) {
|
|
7780
7812
|
return (typeof widget === "undefined" ? "undefined" : _type_of(widget)) === 'object';
|
|
7781
7813
|
}))) {
|
|
7782
|
-
throw new Error(withUsage$
|
|
7814
|
+
throw new Error(withUsage$w('The `widgets` option expects an array of widgets.'));
|
|
7783
7815
|
}
|
|
7784
7816
|
if (!Array.isArray(facets)) {
|
|
7785
|
-
throw new Error(withUsage$
|
|
7817
|
+
throw new Error(withUsage$w("The `facets` option only accepts an array of facets, you passed ".concat(JSON.stringify(facets))));
|
|
7786
7818
|
}
|
|
7787
7819
|
var localWidgets = new Map();
|
|
7788
7820
|
return {
|
|
@@ -7884,7 +7916,7 @@
|
|
|
7884
7916
|
results: results
|
|
7885
7917
|
});
|
|
7886
7918
|
if (!Array.isArray(attributesToRender)) {
|
|
7887
|
-
throw new Error(withUsage$
|
|
7919
|
+
throw new Error(withUsage$w('The `transformItems` option expects a function that returns an Array.'));
|
|
7888
7920
|
}
|
|
7889
7921
|
return {
|
|
7890
7922
|
attributesToRender: attributesToRender,
|
|
@@ -8205,19 +8237,19 @@
|
|
|
8205
8237
|
return toFeedSearchResults(lastResults._state, raw);
|
|
8206
8238
|
});
|
|
8207
8239
|
}
|
|
8208
|
-
var withUsage$
|
|
8240
|
+
var withUsage$v = createDocumentationMessageGenerator({
|
|
8209
8241
|
name: 'feeds',
|
|
8210
8242
|
connector: true
|
|
8211
8243
|
});
|
|
8212
8244
|
var connectFeeds = function connectFeeds(renderFn) {
|
|
8213
8245
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
8214
|
-
checkRendering(renderFn, withUsage$
|
|
8246
|
+
checkRendering(renderFn, withUsage$v());
|
|
8215
8247
|
return function(widgetParams) {
|
|
8216
8248
|
var isolated = widgetParams.isolated, _widgetParams_transformFeeds = widgetParams.transformFeeds, transformFeeds = _widgetParams_transformFeeds === void 0 ? function(feeds) {
|
|
8217
8249
|
return feeds;
|
|
8218
8250
|
} : _widgetParams_transformFeeds;
|
|
8219
8251
|
if (isolated !== false) {
|
|
8220
|
-
throw new Error(withUsage$
|
|
8252
|
+
throw new Error(withUsage$v('The `isolated` option currently only supports `false`.'));
|
|
8221
8253
|
}
|
|
8222
8254
|
return {
|
|
8223
8255
|
$$type: 'ais.feeds',
|
|
@@ -8225,7 +8257,7 @@
|
|
|
8225
8257
|
init: function init(initOptions) {
|
|
8226
8258
|
var instantSearchInstance = initOptions.instantSearchInstance;
|
|
8227
8259
|
if (!instantSearchInstance.compositionID) {
|
|
8228
|
-
throw new Error(withUsage$
|
|
8260
|
+
throw new Error(withUsage$v('The `feeds` widget requires a composition-based InstantSearch instance (compositionID must be set).'));
|
|
8229
8261
|
}
|
|
8230
8262
|
hydrateFeedsFromInitialResultsIfNeeded(instantSearchInstance, initOptions.parent);
|
|
8231
8263
|
renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
|
|
@@ -8271,12 +8303,12 @@
|
|
|
8271
8303
|
];
|
|
8272
8304
|
feedIDs = transformFeeds(feedIDs);
|
|
8273
8305
|
if (!Array.isArray(feedIDs)) {
|
|
8274
|
-
throw new Error(withUsage$
|
|
8306
|
+
throw new Error(withUsage$v('The `transformFeeds` option expects a function that returns an Array.'));
|
|
8275
8307
|
}
|
|
8276
8308
|
if (!feedIDs.every(function(feedID) {
|
|
8277
8309
|
return typeof feedID === 'string';
|
|
8278
8310
|
})) {
|
|
8279
|
-
throw new Error(withUsage$
|
|
8311
|
+
throw new Error(withUsage$v('The `transformFeeds` option expects a function that returns an array of feed IDs (strings).'));
|
|
8280
8312
|
}
|
|
8281
8313
|
return {
|
|
8282
8314
|
feedIDs: feedIDs,
|
|
@@ -8387,7 +8419,7 @@
|
|
|
8387
8419
|
}));
|
|
8388
8420
|
}
|
|
8389
8421
|
|
|
8390
|
-
var withUsage$
|
|
8422
|
+
var withUsage$u = createDocumentationMessageGenerator({
|
|
8391
8423
|
name: 'index-widget'
|
|
8392
8424
|
});
|
|
8393
8425
|
/**
|
|
@@ -8515,7 +8547,7 @@
|
|
|
8515
8547
|
var index = function index(widgetParams) {
|
|
8516
8548
|
var _widgetParams_EXPERIMENTAL_isolated;
|
|
8517
8549
|
if (widgetParams === undefined || widgetParams.indexName === undefined && !widgetParams.isolated && !widgetParams.EXPERIMENTAL_isolated) {
|
|
8518
|
-
throw new Error(withUsage$
|
|
8550
|
+
throw new Error(withUsage$u('The `indexName` option is required.'));
|
|
8519
8551
|
}
|
|
8520
8552
|
// When isolated=true, we use an empty string as the default indexName.
|
|
8521
8553
|
// This is intentional: isolated indices do not require a real index name.
|
|
@@ -8608,7 +8640,7 @@
|
|
|
8608
8640
|
addWidgets: function addWidgets(widgets) {
|
|
8609
8641
|
var _this = this;
|
|
8610
8642
|
if (!Array.isArray(widgets)) {
|
|
8611
|
-
throw new Error(withUsage$
|
|
8643
|
+
throw new Error(withUsage$u('The `addWidgets` method expects an array of widgets.'));
|
|
8612
8644
|
}
|
|
8613
8645
|
var flatWidgets = widgets.reduce(function(acc, w) {
|
|
8614
8646
|
return acc.concat(Array.isArray(w) ? w : [
|
|
@@ -8618,7 +8650,7 @@
|
|
|
8618
8650
|
if (flatWidgets.some(function(widget) {
|
|
8619
8651
|
return typeof widget.init !== 'function' && typeof widget.render !== 'function';
|
|
8620
8652
|
})) {
|
|
8621
|
-
throw new Error(withUsage$
|
|
8653
|
+
throw new Error(withUsage$u('The widget definition expects a `render` and/or an `init` method.'));
|
|
8622
8654
|
}
|
|
8623
8655
|
flatWidgets.forEach(function(widget) {
|
|
8624
8656
|
widget.parent = _this;
|
|
@@ -8669,7 +8701,7 @@
|
|
|
8669
8701
|
removeWidgets: function removeWidgets(widgets) {
|
|
8670
8702
|
var _this = this;
|
|
8671
8703
|
if (!Array.isArray(widgets)) {
|
|
8672
|
-
throw new Error(withUsage$
|
|
8704
|
+
throw new Error(withUsage$u('The `removeWidgets` method expects an array of widgets.'));
|
|
8673
8705
|
}
|
|
8674
8706
|
var flatWidgets = widgets.reduce(function(acc, w) {
|
|
8675
8707
|
return acc.concat(Array.isArray(w) ? w : [
|
|
@@ -8679,7 +8711,7 @@
|
|
|
8679
8711
|
if (flatWidgets.some(function(widget) {
|
|
8680
8712
|
return typeof widget.dispose !== 'function';
|
|
8681
8713
|
})) {
|
|
8682
|
-
throw new Error(withUsage$
|
|
8714
|
+
throw new Error(withUsage$u('The widget definition expects a `dispose` method.'));
|
|
8683
8715
|
}
|
|
8684
8716
|
localWidgets = localWidgets.filter(function(widget) {
|
|
8685
8717
|
return flatWidgets.indexOf(widget) === -1;
|
|
@@ -8807,7 +8839,7 @@
|
|
|
8807
8839
|
mainHelper.state
|
|
8808
8840
|
].concat(_to_consumable_array(resolveSearchParameters(_this))));
|
|
8809
8841
|
}, function() {
|
|
8810
|
-
return _this.getHelper().recommendState;
|
|
8842
|
+
return addInsightsToRecommendParameters(_this.getHelper().recommendState, mainHelper.state);
|
|
8811
8843
|
});
|
|
8812
8844
|
var indexInitialResults = (_instantSearchInstance__initialResults = instantSearchInstance._initialResults) === null || _instantSearchInstance__initialResults === void 0 ? void 0 : _instantSearchInstance__initialResults[this.getIndexId()];
|
|
8813
8845
|
if (indexInitialResults === null || indexInitialResults === void 0 ? void 0 : indexInitialResults.results) {
|
|
@@ -9184,7 +9216,7 @@
|
|
|
9184
9216
|
});
|
|
9185
9217
|
}
|
|
9186
9218
|
|
|
9187
|
-
var version = '4.
|
|
9219
|
+
var version = '4.109.0';
|
|
9188
9220
|
|
|
9189
9221
|
var ANONYMOUS_TOKEN_COOKIE_KEY = '_ALGOLIA';
|
|
9190
9222
|
function getCookie(name) {
|
|
@@ -9414,7 +9446,8 @@
|
|
|
9414
9446
|
helper.overrideStateWithoutTriggeringChangeEvent(_object_spread_props(_object_spread({}, helper.state), {
|
|
9415
9447
|
userToken: normalizedUserToken
|
|
9416
9448
|
}));
|
|
9417
|
-
if (existingToken && existingToken !==
|
|
9449
|
+
if (existingToken && existingToken !== normalizedUserToken) {
|
|
9450
|
+
helper._recommendCache = {};
|
|
9418
9451
|
instantSearchInstance.scheduleSearch();
|
|
9419
9452
|
}
|
|
9420
9453
|
}
|
|
@@ -9503,14 +9536,17 @@
|
|
|
9503
9536
|
} else if (event.insightsMethod) {
|
|
9504
9537
|
if (event.insightsMethod === 'viewedObjectIDs') {
|
|
9505
9538
|
var payload = event.payload;
|
|
9539
|
+
var getViewEventKey = function getViewEventKey(objectID) {
|
|
9540
|
+
return payload.queryID ? "".concat(payload.queryID, ":").concat(objectID) : objectID;
|
|
9541
|
+
};
|
|
9506
9542
|
var difference = payload.objectIDs.filter(function(objectID) {
|
|
9507
|
-
return !viewedObjectIDs.has(objectID);
|
|
9543
|
+
return !viewedObjectIDs.has(getViewEventKey(objectID));
|
|
9508
9544
|
});
|
|
9509
9545
|
if (difference.length === 0) {
|
|
9510
9546
|
return;
|
|
9511
9547
|
}
|
|
9512
9548
|
difference.forEach(function(objectID) {
|
|
9513
|
-
return viewedObjectIDs.add(objectID);
|
|
9549
|
+
return viewedObjectIDs.add(getViewEventKey(objectID));
|
|
9514
9550
|
});
|
|
9515
9551
|
payload.objectIDs = difference;
|
|
9516
9552
|
}
|
|
@@ -9618,10 +9654,10 @@
|
|
|
9618
9654
|
* and the ability to set credentials via extra parameters when sending events.
|
|
9619
9655
|
*/ function isModernInsightsClient(client) {
|
|
9620
9656
|
var _split_map = _sliced_to_array((client.version || '').split('.').map(Number), 2), major = _split_map[0], minor = _split_map[1];
|
|
9621
|
-
/*
|
|
9657
|
+
/* oxlint-disable instantsearch/naming-convention */ var v3 = major >= 3;
|
|
9622
9658
|
var v2_6 = major === 2 && minor >= 6;
|
|
9623
9659
|
var v1_10 = major === 1 && minor >= 10;
|
|
9624
|
-
/*
|
|
9660
|
+
/* oxlint-enable instantsearch/naming-convention */ return v3 || v2_6 || v1_10;
|
|
9625
9661
|
}
|
|
9626
9662
|
/**
|
|
9627
9663
|
* While `search-insights` supports both string and number user tokens,
|
|
@@ -11042,7 +11078,7 @@
|
|
|
11042
11078
|
};
|
|
11043
11079
|
}
|
|
11044
11080
|
|
|
11045
|
-
var withUsage$
|
|
11081
|
+
var withUsage$t = createDocumentationMessageGenerator({
|
|
11046
11082
|
name: 'instantsearch'
|
|
11047
11083
|
});
|
|
11048
11084
|
function defaultCreateURL() {
|
|
@@ -11105,7 +11141,7 @@
|
|
|
11105
11141
|
_this.setMaxListeners(100);
|
|
11106
11142
|
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;
|
|
11107
11143
|
if (searchClient === null) {
|
|
11108
|
-
throw new Error(withUsage$
|
|
11144
|
+
throw new Error(withUsage$t('The `searchClient` option is required.'));
|
|
11109
11145
|
}
|
|
11110
11146
|
if (typeof searchClient.search !== 'function') {
|
|
11111
11147
|
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/");
|
|
@@ -11114,7 +11150,7 @@
|
|
|
11114
11150
|
searchClient.addAlgoliaAgent("instantsearch.js (".concat(version, ")"));
|
|
11115
11151
|
}
|
|
11116
11152
|
if (insightsClient && typeof insightsClient !== 'function') {
|
|
11117
|
-
throw new Error(withUsage$
|
|
11153
|
+
throw new Error(withUsage$t('The `insightsClient` option should be a function.'));
|
|
11118
11154
|
}
|
|
11119
11155
|
_this._initialOptions = options;
|
|
11120
11156
|
_this.client = searchClient;
|
|
@@ -11263,12 +11299,12 @@
|
|
|
11263
11299
|
* @param widgets The array of widgets to add to InstantSearch.
|
|
11264
11300
|
*/ function addWidgets(widgets) {
|
|
11265
11301
|
if (!Array.isArray(widgets)) {
|
|
11266
|
-
throw new Error(withUsage$
|
|
11302
|
+
throw new Error(withUsage$t('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
|
|
11267
11303
|
}
|
|
11268
11304
|
if (this.compositionID && widgets.some(function(w) {
|
|
11269
11305
|
return !Array.isArray(w) && isIndexWidget(w) && !w._isolated;
|
|
11270
11306
|
})) {
|
|
11271
|
-
throw new Error(withUsage$
|
|
11307
|
+
throw new Error(withUsage$t('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
|
|
11272
11308
|
}
|
|
11273
11309
|
this.mainIndex.addWidgets(widgets);
|
|
11274
11310
|
return this;
|
|
@@ -11297,7 +11333,7 @@
|
|
|
11297
11333
|
* The widgets must implement a `dispose()` method to clear their states.
|
|
11298
11334
|
*/ function removeWidgets(widgets) {
|
|
11299
11335
|
if (!Array.isArray(widgets)) {
|
|
11300
|
-
throw new Error(withUsage$
|
|
11336
|
+
throw new Error(withUsage$t('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
|
|
11301
11337
|
}
|
|
11302
11338
|
this.mainIndex.removeWidgets(widgets);
|
|
11303
11339
|
return this;
|
|
@@ -11311,7 +11347,7 @@
|
|
|
11311
11347
|
*/ function start() {
|
|
11312
11348
|
var _this = this;
|
|
11313
11349
|
if (this.started) {
|
|
11314
|
-
throw new Error(withUsage$
|
|
11350
|
+
throw new Error(withUsage$t('The `start` method has already been called once.'));
|
|
11315
11351
|
}
|
|
11316
11352
|
// This Helper is used for the queries, we don't care about its state. The
|
|
11317
11353
|
// states are managed at the `index` level. We use this Helper to create
|
|
@@ -11519,7 +11555,7 @@
|
|
|
11519
11555
|
var _this = this;
|
|
11520
11556
|
var callOnStateChange = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
|
|
11521
11557
|
if (!this.mainHelper) {
|
|
11522
|
-
throw new Error(withUsage$
|
|
11558
|
+
throw new Error(withUsage$t('The `start` method needs to be called before `setUiState`.'));
|
|
11523
11559
|
}
|
|
11524
11560
|
// We refresh the index UI state to update the local UI state that the
|
|
11525
11561
|
// main index passes to the function form of `setUiState`.
|
|
@@ -11556,7 +11592,7 @@
|
|
|
11556
11592
|
value: function createURL() {
|
|
11557
11593
|
var nextState = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
11558
11594
|
if (!this.started) {
|
|
11559
|
-
throw new Error(withUsage$
|
|
11595
|
+
throw new Error(withUsage$t('The `start` method needs to be called before `createURL`.'));
|
|
11560
11596
|
}
|
|
11561
11597
|
return this._createURL(nextState);
|
|
11562
11598
|
}
|
|
@@ -11565,7 +11601,7 @@
|
|
|
11565
11601
|
key: "refresh",
|
|
11566
11602
|
value: function refresh() {
|
|
11567
11603
|
if (!this.mainHelper) {
|
|
11568
|
-
throw new Error(withUsage$
|
|
11604
|
+
throw new Error(withUsage$t('The `start` method needs to be called before `refresh`.'));
|
|
11569
11605
|
}
|
|
11570
11606
|
this.mainHelper.clearCache().search();
|
|
11571
11607
|
}
|
|
@@ -12072,13 +12108,13 @@
|
|
|
12072
12108
|
}, children);
|
|
12073
12109
|
}
|
|
12074
12110
|
|
|
12075
|
-
var withUsage$
|
|
12111
|
+
var withUsage$s = createDocumentationMessageGenerator({
|
|
12076
12112
|
name: 'autocomplete',
|
|
12077
12113
|
connector: true
|
|
12078
12114
|
});
|
|
12079
12115
|
var connectAutocomplete = function connectAutocomplete(renderFn) {
|
|
12080
12116
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
12081
|
-
checkRendering(renderFn, withUsage$
|
|
12117
|
+
checkRendering(renderFn, withUsage$s());
|
|
12082
12118
|
return function(widgetParams) {
|
|
12083
12119
|
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) {
|
|
12084
12120
|
return indices;
|
|
@@ -12191,20 +12227,20 @@
|
|
|
12191
12227
|
return useConnector(connectAutocomplete, props, additionalWidgetProperties);
|
|
12192
12228
|
}
|
|
12193
12229
|
|
|
12194
|
-
var withUsage$
|
|
12230
|
+
var withUsage$r = createDocumentationMessageGenerator({
|
|
12195
12231
|
name: 'breadcrumb',
|
|
12196
12232
|
connector: true
|
|
12197
12233
|
});
|
|
12198
12234
|
var connectBreadcrumb = function connectBreadcrumb(renderFn) {
|
|
12199
12235
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
12200
|
-
checkRendering(renderFn, withUsage$
|
|
12236
|
+
checkRendering(renderFn, withUsage$r());
|
|
12201
12237
|
var connectorState = {};
|
|
12202
12238
|
return function(widgetParams) {
|
|
12203
12239
|
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) {
|
|
12204
12240
|
return items;
|
|
12205
12241
|
} : _ref_transformItems;
|
|
12206
12242
|
if (!attributes || !Array.isArray(attributes) || attributes.length === 0) {
|
|
12207
|
-
throw new Error(withUsage$
|
|
12243
|
+
throw new Error(withUsage$r('The `attributes` option expects an array of strings.'));
|
|
12208
12244
|
}
|
|
12209
12245
|
var _attributes = _sliced_to_array(attributes, 1), hierarchicalFacetName = _attributes[0];
|
|
12210
12246
|
function getRefinedState(state, facetValue) {
|
|
@@ -12350,6 +12386,76 @@
|
|
|
12350
12386
|
return useConnector(connectBreadcrumb, props, additionalWidgetProperties);
|
|
12351
12387
|
}
|
|
12352
12388
|
|
|
12389
|
+
var tryParseJson = function tryParseJson(value) {
|
|
12390
|
+
try {
|
|
12391
|
+
return JSON.parse(value);
|
|
12392
|
+
} catch (unused) {
|
|
12393
|
+
return undefined;
|
|
12394
|
+
}
|
|
12395
|
+
};
|
|
12396
|
+
var repairPartialJson = function repairPartialJson(value) {
|
|
12397
|
+
var repaired = value.trim();
|
|
12398
|
+
if (!repaired) {
|
|
12399
|
+
return repaired;
|
|
12400
|
+
}
|
|
12401
|
+
var inString = false;
|
|
12402
|
+
var isEscaped = false;
|
|
12403
|
+
var stack = [];
|
|
12404
|
+
for(var index = 0; index < repaired.length; index++){
|
|
12405
|
+
var char = repaired[index];
|
|
12406
|
+
if (inString) {
|
|
12407
|
+
if (isEscaped) {
|
|
12408
|
+
isEscaped = false;
|
|
12409
|
+
} else if (char === '\\') {
|
|
12410
|
+
isEscaped = true;
|
|
12411
|
+
} else if (char === '"') {
|
|
12412
|
+
inString = false;
|
|
12413
|
+
}
|
|
12414
|
+
continue;
|
|
12415
|
+
}
|
|
12416
|
+
if (char === '"') {
|
|
12417
|
+
inString = true;
|
|
12418
|
+
continue;
|
|
12419
|
+
}
|
|
12420
|
+
if (char === '{' || char === '[') {
|
|
12421
|
+
stack.push(char);
|
|
12422
|
+
continue;
|
|
12423
|
+
}
|
|
12424
|
+
if (char === '}' && stack[stack.length - 1] === '{') {
|
|
12425
|
+
stack.pop();
|
|
12426
|
+
continue;
|
|
12427
|
+
}
|
|
12428
|
+
if (char === ']' && stack[stack.length - 1] === '[') {
|
|
12429
|
+
stack.pop();
|
|
12430
|
+
}
|
|
12431
|
+
}
|
|
12432
|
+
if (inString && !isEscaped) {
|
|
12433
|
+
repaired += '"';
|
|
12434
|
+
}
|
|
12435
|
+
repaired = repaired.replace(RegExp(",\\s*$", "u"), '');
|
|
12436
|
+
if (stack.length > 0) {
|
|
12437
|
+
repaired += stack.reverse().map(function(opening) {
|
|
12438
|
+
return opening === '{' ? '}' : ']';
|
|
12439
|
+
}).join('');
|
|
12440
|
+
}
|
|
12441
|
+
return repaired.replace(RegExp(",\\s*([}\\]])", "gu"), '$1');
|
|
12442
|
+
};
|
|
12443
|
+
var parsePartialJson = function parsePartialJson(accumulatedRawJson, fallbackValue) {
|
|
12444
|
+
var normalized = accumulatedRawJson.trim();
|
|
12445
|
+
if (!normalized) {
|
|
12446
|
+
return fallbackValue;
|
|
12447
|
+
}
|
|
12448
|
+
var directParsed = tryParseJson(normalized);
|
|
12449
|
+
if (directParsed !== undefined) {
|
|
12450
|
+
return directParsed;
|
|
12451
|
+
}
|
|
12452
|
+
var repairedParsed = tryParseJson(repairPartialJson(normalized));
|
|
12453
|
+
if (repairedParsed !== undefined) {
|
|
12454
|
+
return repairedParsed;
|
|
12455
|
+
}
|
|
12456
|
+
return fallbackValue;
|
|
12457
|
+
};
|
|
12458
|
+
|
|
12353
12459
|
/**
|
|
12354
12460
|
* Stream parser for parsing SSE (Server-Sent Events) streams.
|
|
12355
12461
|
* The AI SDK 5 format uses SSE with JSON payloads prefixed by "data: ".
|
|
@@ -12631,75 +12737,6 @@
|
|
|
12631
12737
|
}
|
|
12632
12738
|
|
|
12633
12739
|
var _computedKey$1;
|
|
12634
|
-
var tryParseJson = function tryParseJson(value) {
|
|
12635
|
-
try {
|
|
12636
|
-
return JSON.parse(value);
|
|
12637
|
-
} catch (unused) {
|
|
12638
|
-
return undefined;
|
|
12639
|
-
}
|
|
12640
|
-
};
|
|
12641
|
-
var repairPartialJson = function repairPartialJson(value) {
|
|
12642
|
-
var repaired = value.trim();
|
|
12643
|
-
if (!repaired) {
|
|
12644
|
-
return repaired;
|
|
12645
|
-
}
|
|
12646
|
-
var inString = false;
|
|
12647
|
-
var isEscaped = false;
|
|
12648
|
-
var stack = [];
|
|
12649
|
-
for(var index = 0; index < repaired.length; index++){
|
|
12650
|
-
var char = repaired[index];
|
|
12651
|
-
if (inString) {
|
|
12652
|
-
if (isEscaped) {
|
|
12653
|
-
isEscaped = false;
|
|
12654
|
-
} else if (char === '\\') {
|
|
12655
|
-
isEscaped = true;
|
|
12656
|
-
} else if (char === '"') {
|
|
12657
|
-
inString = false;
|
|
12658
|
-
}
|
|
12659
|
-
continue;
|
|
12660
|
-
}
|
|
12661
|
-
if (char === '"') {
|
|
12662
|
-
inString = true;
|
|
12663
|
-
continue;
|
|
12664
|
-
}
|
|
12665
|
-
if (char === '{' || char === '[') {
|
|
12666
|
-
stack.push(char);
|
|
12667
|
-
continue;
|
|
12668
|
-
}
|
|
12669
|
-
if (char === '}' && stack[stack.length - 1] === '{') {
|
|
12670
|
-
stack.pop();
|
|
12671
|
-
continue;
|
|
12672
|
-
}
|
|
12673
|
-
if (char === ']' && stack[stack.length - 1] === '[') {
|
|
12674
|
-
stack.pop();
|
|
12675
|
-
}
|
|
12676
|
-
}
|
|
12677
|
-
if (inString && !isEscaped) {
|
|
12678
|
-
repaired += '"';
|
|
12679
|
-
}
|
|
12680
|
-
repaired = repaired.replace(RegExp(",\\s*$", "u"), '');
|
|
12681
|
-
if (stack.length > 0) {
|
|
12682
|
-
repaired += stack.reverse().map(function(opening) {
|
|
12683
|
-
return opening === '{' ? '}' : ']';
|
|
12684
|
-
}).join('');
|
|
12685
|
-
}
|
|
12686
|
-
return repaired.replace(RegExp(",\\s*([}\\]])", "gu"), '$1');
|
|
12687
|
-
};
|
|
12688
|
-
var parseToolInputDelta = function parseToolInputDelta(accumulatedRawInput, fallbackInput) {
|
|
12689
|
-
var normalized = accumulatedRawInput.trim();
|
|
12690
|
-
if (!normalized) {
|
|
12691
|
-
return fallbackInput;
|
|
12692
|
-
}
|
|
12693
|
-
var directParsed = tryParseJson(normalized);
|
|
12694
|
-
if (directParsed !== undefined) {
|
|
12695
|
-
return directParsed;
|
|
12696
|
-
}
|
|
12697
|
-
var repairedParsed = tryParseJson(repairPartialJson(normalized));
|
|
12698
|
-
if (repairedParsed !== undefined) {
|
|
12699
|
-
return repairedParsed;
|
|
12700
|
-
}
|
|
12701
|
-
return fallbackInput;
|
|
12702
|
-
};
|
|
12703
12740
|
var defaultGuardrailFallbackResponse = 'Sorry, we are not able to generate a response at the moment.';
|
|
12704
12741
|
_computedKey$1 = /** @internal */ '~addToolResultForMessage';
|
|
12705
12742
|
var _computedKey1$1 = _computedKey$1;
|
|
@@ -13533,7 +13570,7 @@
|
|
|
13533
13570
|
toolRawInputByCallId[chunk.toolCallId] = nextRawInput;
|
|
13534
13571
|
var toolName = (_chunk_toolName = chunk.toolName) !== null && _chunk_toolName !== void 0 ? _chunk_toolName : existingPart === null || existingPart === void 0 ? void 0 : (_existingPart_type = existingPart.type) === null || _existingPart_type === void 0 ? void 0 : _existingPart_type.replace('tool-', '');
|
|
13535
13572
|
var shouldRepair = toolName ? (_ref2 = (_this_shouldRepairToolInput = (_this1 = _this).shouldRepairToolInput) === null || _this_shouldRepairToolInput === void 0 ? void 0 : _this_shouldRepairToolInput.call(_this1, toolName)) !== null && _ref2 !== void 0 ? _ref2 : true : true;
|
|
13536
|
-
var parsedInput = shouldRepair ?
|
|
13573
|
+
var parsedInput = shouldRepair ? parsePartialJson(nextRawInput, existingPart === null || existingPart === void 0 ? void 0 : existingPart.input) : existingPart === null || existingPart === void 0 ? void 0 : existingPart.input;
|
|
13537
13574
|
var nextToolPart = _object_spread_props(_object_spread({}, existingPart !== null && existingPart !== void 0 ? existingPart : {
|
|
13538
13575
|
type: "tool-".concat(chunk.toolName),
|
|
13539
13576
|
toolCallId: chunk.toolCallId
|
|
@@ -13636,7 +13673,7 @@
|
|
|
13636
13673
|
var previousRawOutput = (_ref3 = (_ref4 = existingPart2 === null || existingPart2 === void 0 ? void 0 : existingPart2.rawOutput) !== null && _ref4 !== void 0 ? _ref4 : toolRawOutputByCallId[toolCallId]) !== null && _ref3 !== void 0 ? _ref3 : '';
|
|
13637
13674
|
var nextRawOutput = "".concat(previousRawOutput).concat(delta);
|
|
13638
13675
|
toolRawOutputByCallId[toolCallId] = nextRawOutput;
|
|
13639
|
-
var parsedOutput =
|
|
13676
|
+
var parsedOutput = parsePartialJson(nextRawOutput, existingPart2 === null || existingPart2 === void 0 ? void 0 : existingPart2.output);
|
|
13640
13677
|
var nextToolPart1 = _object_spread_props(_object_spread({}, existingPart2 !== null && existingPart2 !== void 0 ? existingPart2 : {
|
|
13641
13678
|
type: "tool-".concat(toolName1),
|
|
13642
13679
|
toolCallId: toolCallId,
|
|
@@ -13926,9 +13963,25 @@
|
|
|
13926
13963
|
|
|
13927
13964
|
var _computedKey, _computedKey1, _computedKey2, _computedKey3, _computedKey4, _computedKey5;
|
|
13928
13965
|
var CACHE_KEY = 'instantsearch-chat-initial-messages';
|
|
13966
|
+
// Message history is a browser concern, and a server render constructs a Chat
|
|
13967
|
+
// too. Reading storage there throws during rendering; the write below only
|
|
13968
|
+
// throws into its own `catch`, so gating it just stops a pointless attempt.
|
|
13929
13969
|
function getDefaultInitialMessages(id) {
|
|
13930
|
-
|
|
13931
|
-
|
|
13970
|
+
return safelyRunOnBrowser(function() {
|
|
13971
|
+
try {
|
|
13972
|
+
// `sessionStorage` is not available in every environment with a
|
|
13973
|
+
// `window` (e.g. React Native), and some browsers throw on access
|
|
13974
|
+
// when storage is disabled.
|
|
13975
|
+
var initialMessages = sessionStorage.getItem(CACHE_KEY + (id ? "-".concat(id) : ''));
|
|
13976
|
+
return initialMessages ? JSON.parse(initialMessages) : [];
|
|
13977
|
+
} catch (e) {
|
|
13978
|
+
return [];
|
|
13979
|
+
}
|
|
13980
|
+
}, {
|
|
13981
|
+
fallback: function fallback() {
|
|
13982
|
+
return [];
|
|
13983
|
+
}
|
|
13984
|
+
});
|
|
13932
13985
|
}
|
|
13933
13986
|
_computedKey = '~registerMessagesCallback', _computedKey1 = '~registerStatusCallback', _computedKey2 = '~registerErrorCallback';
|
|
13934
13987
|
var _computedKey6 = _computedKey, _computedKey7 = _computedKey1, _computedKey8 = _computedKey2;
|
|
@@ -14007,11 +14060,13 @@
|
|
|
14007
14060
|
}
|
|
14008
14061
|
var saveMessagesInLocalStorage = function saveMessagesInLocalStorage() {
|
|
14009
14062
|
if (_this.status === 'ready') {
|
|
14010
|
-
|
|
14011
|
-
|
|
14012
|
-
|
|
14013
|
-
|
|
14014
|
-
|
|
14063
|
+
safelyRunOnBrowser(function() {
|
|
14064
|
+
try {
|
|
14065
|
+
sessionStorage.setItem(CACHE_KEY + (id ? "-".concat(id) : ''), JSON.stringify(_this.messages));
|
|
14066
|
+
} catch (e) {
|
|
14067
|
+
// Do nothing if sessionStorage is not available or full
|
|
14068
|
+
}
|
|
14069
|
+
});
|
|
14015
14070
|
}
|
|
14016
14071
|
};
|
|
14017
14072
|
this['~registerMessagesCallback'](saveMessagesInLocalStorage);
|
|
@@ -14087,7 +14142,7 @@
|
|
|
14087
14142
|
// it is non-empty and the chat is not already processing a message.
|
|
14088
14143
|
// Returns true when a message was submitted, so callers can clear their input.
|
|
14089
14144
|
function openChat(chatRenderState) {
|
|
14090
|
-
var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, message = _ref.message, referer = _ref.referer;
|
|
14145
|
+
var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, message = _ref.message, referer = _ref.referer, turnContext = _ref.turnContext;
|
|
14091
14146
|
var _ref1;
|
|
14092
14147
|
var _chatRenderState_setOpen;
|
|
14093
14148
|
if (!chatRenderState) {
|
|
@@ -14103,9 +14158,13 @@
|
|
|
14103
14158
|
if (isChatBusy(chatRenderState) || !chatRenderState.sendMessage) {
|
|
14104
14159
|
return false;
|
|
14105
14160
|
}
|
|
14106
|
-
chatRenderState.sendMessage({
|
|
14161
|
+
chatRenderState.sendMessage(_object_spread({
|
|
14107
14162
|
text: trimmed
|
|
14108
|
-
},
|
|
14163
|
+
}, turnContext ? {
|
|
14164
|
+
metadata: {
|
|
14165
|
+
turnContext: turnContext
|
|
14166
|
+
}
|
|
14167
|
+
} : {}), referer ? {
|
|
14109
14168
|
headers: {
|
|
14110
14169
|
'x-algolia-referer': referer
|
|
14111
14170
|
}
|
|
@@ -14319,7 +14378,7 @@
|
|
|
14319
14378
|
return DefaultChatTransport;
|
|
14320
14379
|
}(HttpChatTransport);
|
|
14321
14380
|
|
|
14322
|
-
var withUsage$
|
|
14381
|
+
var withUsage$q = createDocumentationMessageGenerator({
|
|
14323
14382
|
name: 'chat',
|
|
14324
14383
|
connector: true
|
|
14325
14384
|
});
|
|
@@ -14340,26 +14399,36 @@
|
|
|
14340
14399
|
attributesToClear: attributesToClear
|
|
14341
14400
|
}));
|
|
14342
14401
|
if (params.facetFilters) {
|
|
14343
|
-
var
|
|
14344
|
-
var
|
|
14345
|
-
|
|
14346
|
-
|
|
14347
|
-
|
|
14348
|
-
|
|
14349
|
-
|
|
14350
|
-
|
|
14402
|
+
var refinements = flat(params.facetFilters).reduce(function(acc, filter) {
|
|
14403
|
+
var separatorIndex = filter.indexOf(':');
|
|
14404
|
+
if (separatorIndex > 0) {
|
|
14405
|
+
acc.push({
|
|
14406
|
+
attribute: filter.slice(0, separatorIndex),
|
|
14407
|
+
value: filter.slice(separatorIndex + 1)
|
|
14408
|
+
});
|
|
14409
|
+
}
|
|
14410
|
+
return acc;
|
|
14411
|
+
}, []);
|
|
14412
|
+
var hierarchicalRefinements = new Map();
|
|
14413
|
+
refinements.forEach(function(param) {
|
|
14351
14414
|
var attribute = param.attribute, value = param.value;
|
|
14352
|
-
|
|
14353
|
-
|
|
14354
|
-
|
|
14355
|
-
|
|
14356
|
-
|
|
14357
|
-
|
|
14358
|
-
|
|
14359
|
-
|
|
14360
|
-
|
|
14361
|
-
|
|
14415
|
+
var hierarchicalFacet = helper.state.hierarchicalFacets.find(function(facet) {
|
|
14416
|
+
return facet.name === attribute || facet.attributes.includes(attribute);
|
|
14417
|
+
});
|
|
14418
|
+
if (hierarchicalFacet) {
|
|
14419
|
+
var currentValue = hierarchicalRefinements.get(hierarchicalFacet.name);
|
|
14420
|
+
if (currentValue === undefined || value.length > currentValue.length) {
|
|
14421
|
+
hierarchicalRefinements.set(hierarchicalFacet.name, value);
|
|
14422
|
+
}
|
|
14423
|
+
return;
|
|
14424
|
+
}
|
|
14425
|
+
if (!helper.state.isConjunctiveFacet(attribute) && !helper.state.isDisjunctiveFacet(attribute)) {
|
|
14426
|
+
helper.setState(helper.state.addDisjunctiveFacet(attribute));
|
|
14362
14427
|
}
|
|
14428
|
+
helper.toggleFacetRefinement(attribute, value);
|
|
14429
|
+
});
|
|
14430
|
+
hierarchicalRefinements.forEach(function(value, name) {
|
|
14431
|
+
helper.toggleFacetRefinement(name, value);
|
|
14363
14432
|
});
|
|
14364
14433
|
}
|
|
14365
14434
|
if (params.query) {
|
|
@@ -14370,7 +14439,7 @@
|
|
|
14370
14439
|
}
|
|
14371
14440
|
var connectChat = function connectChat(renderFn) {
|
|
14372
14441
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
14373
|
-
checkRendering(renderFn, withUsage$
|
|
14442
|
+
checkRendering(renderFn, withUsage$q());
|
|
14374
14443
|
return function(widgetParams) {
|
|
14375
14444
|
var _ref = widgetParams || {}, _ref_resume = _ref.resume, resume = _ref_resume === void 0 ? false : _ref_resume, _ref_tools = _ref.tools, tools = _ref_tools === void 0 ? {} : _ref_tools, _ref_type = _ref.type, type = _ref_type === void 0 ? 'chat' : _ref_type, context = _ref.context, initialUserMessage = _ref.initialUserMessage, initialMessages = _ref.initialMessages, _ref_disableTriggerValidation = _ref.disableTriggerValidation, disableTriggerValidation = _ref_disableTriggerValidation === void 0 ? false : _ref_disableTriggerValidation, _ref_sendAutomaticallyWhen = _ref.sendAutomaticallyWhen, sendAutomaticallyWhen = _ref_sendAutomaticallyWhen === void 0 ? lastAssistantMessageIsCompleteWithToolCalls : _ref_sendAutomaticallyWhen, _ref_requiresSearch = _ref.requiresSearch, requiresSearch = _ref_requiresSearch === void 0 ? true : _ref_requiresSearch, options = _object_without_properties(_ref, [
|
|
14376
14445
|
"resume",
|
|
@@ -14448,6 +14517,11 @@
|
|
|
14448
14517
|
hasValidatedEntryPoints = true;
|
|
14449
14518
|
};
|
|
14450
14519
|
var makeChatInstance = function makeChatInstance(instantSearchInstance) {
|
|
14520
|
+
// A caller supplied `chat` already owns its transport, so it bypasses the
|
|
14521
|
+
// connector's transport construction and validation below.
|
|
14522
|
+
if ('chat' in options) {
|
|
14523
|
+
return options.chat;
|
|
14524
|
+
}
|
|
14451
14525
|
var transport;
|
|
14452
14526
|
var client = instantSearchInstance.client;
|
|
14453
14527
|
var _getAppIdAndApiKey = _sliced_to_array(getAppIdAndApiKey(client), 2), appId = _getAppIdAndApiKey[0], apiKey = _getAppIdAndApiKey[1];
|
|
@@ -14497,7 +14571,7 @@
|
|
|
14497
14571
|
if ('agentId' in options && options.agentId) {
|
|
14498
14572
|
var _options_requestOptions, _options_requestOptions1;
|
|
14499
14573
|
if (!appId || !apiKey) {
|
|
14500
|
-
throw new Error(withUsage$
|
|
14574
|
+
throw new Error(withUsage$q('Could not extract Algolia credentials from the search client.'));
|
|
14501
14575
|
}
|
|
14502
14576
|
var createApi = function createApi() {
|
|
14503
14577
|
var bypassCache = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
|
|
@@ -14514,7 +14588,7 @@
|
|
|
14514
14588
|
var baseApi = createApi();
|
|
14515
14589
|
transport = new DefaultChatTransport({
|
|
14516
14590
|
api: baseApi,
|
|
14517
|
-
headers: _object_spread_props(_object_spread({}, _instanceof((_options_requestOptions = options.requestOptions) === null || _options_requestOptions === void 0 ? void 0 : _options_requestOptions.headers, Headers) ? Object.fromEntries(options.requestOptions.headers.entries()) : (_options_requestOptions1 = options.requestOptions) === null || _options_requestOptions1 === void 0 ? void 0 : _options_requestOptions1.headers), {
|
|
14591
|
+
headers: _object_spread_props(_object_spread({}, typeof Headers !== 'undefined' && _instanceof((_options_requestOptions = options.requestOptions) === null || _options_requestOptions === void 0 ? void 0 : _options_requestOptions.headers, Headers) ? Object.fromEntries(options.requestOptions.headers.entries()) : (_options_requestOptions1 = options.requestOptions) === null || _options_requestOptions1 === void 0 ? void 0 : _options_requestOptions1.headers), {
|
|
14518
14592
|
// Preserve the required Algolia identity headers and chat agent
|
|
14519
14593
|
// marker, even when requestOptions.headers contains the same keys.
|
|
14520
14594
|
'x-algolia-application-id': appId,
|
|
@@ -14536,10 +14610,7 @@
|
|
|
14536
14610
|
});
|
|
14537
14611
|
}
|
|
14538
14612
|
if (!transport) {
|
|
14539
|
-
throw new Error(withUsage$
|
|
14540
|
-
}
|
|
14541
|
-
if ('chat' in options) {
|
|
14542
|
-
return options.chat;
|
|
14613
|
+
throw new Error(withUsage$q('You need to provide either an `agentId` or a `transport`.'));
|
|
14543
14614
|
}
|
|
14544
14615
|
return new Chat$1(_object_spread_props(_object_spread({}, options), {
|
|
14545
14616
|
sendAutomaticallyWhen: sendAutomaticallyWhen,
|
|
@@ -14619,7 +14690,7 @@
|
|
|
14619
14690
|
if (agentId && feedback) {
|
|
14620
14691
|
var _getAppIdAndApiKey = _sliced_to_array(getAppIdAndApiKey(initOptions.instantSearchInstance.client), 2), appId = _getAppIdAndApiKey[0], apiKey = _getAppIdAndApiKey[1];
|
|
14621
14692
|
if (!appId || !apiKey) {
|
|
14622
|
-
throw new Error(withUsage$
|
|
14693
|
+
throw new Error(withUsage$q('Could not extract Algolia credentials from the search client.'));
|
|
14623
14694
|
}
|
|
14624
14695
|
feedbackAbortController = new AbortController();
|
|
14625
14696
|
_sendChatMessageFeedback = function _sendChatMessageFeedback(messageId, vote) {
|
|
@@ -14640,21 +14711,32 @@
|
|
|
14640
14711
|
}
|
|
14641
14712
|
var hasExistingMessages = _chatInstance.messages.length > 0;
|
|
14642
14713
|
// Set initialMessages before registering callbacks to avoid
|
|
14643
|
-
// triggering re-renders during init
|
|
14644
|
-
|
|
14645
|
-
|
|
14646
|
-
|
|
14647
|
-
|
|
14648
|
-
|
|
14649
|
-
|
|
14650
|
-
|
|
14651
|
-
_chatInstance
|
|
14652
|
-
|
|
14653
|
-
|
|
14654
|
-
|
|
14655
|
-
|
|
14656
|
-
|
|
14657
|
-
|
|
14714
|
+
// triggering re-renders during init. A server render owns no
|
|
14715
|
+
// conversation, so it leaves the instance empty.
|
|
14716
|
+
safelyRunOnBrowser(function() {
|
|
14717
|
+
if ((initialMessages === null || initialMessages === void 0 ? void 0 : initialMessages.length) && !resume && !hasExistingMessages) {
|
|
14718
|
+
_chatInstance.messages = initialMessages;
|
|
14719
|
+
}
|
|
14720
|
+
});
|
|
14721
|
+
safelyRunOnBrowser(function() {
|
|
14722
|
+
_chatInstance['~registerErrorCallback'](render);
|
|
14723
|
+
_chatInstance['~registerMessagesCallback'](render);
|
|
14724
|
+
_chatInstance['~registerStatusCallback'](render);
|
|
14725
|
+
});
|
|
14726
|
+
// Resuming and sending reach the network, which a server render must
|
|
14727
|
+
// not: the HTML pass repeats what `getServerState` already rendered, so
|
|
14728
|
+
// each send happens at least twice, and each failure resolves into chat
|
|
14729
|
+
// state well after the render that started it has finished.
|
|
14730
|
+
safelyRunOnBrowser(function() {
|
|
14731
|
+
if (resume) {
|
|
14732
|
+
_chatInstance.resumeStream();
|
|
14733
|
+
}
|
|
14734
|
+
if (initialUserMessage && !resume && !hasExistingMessages) {
|
|
14735
|
+
_chatInstance.sendMessage({
|
|
14736
|
+
text: initialUserMessage
|
|
14737
|
+
});
|
|
14738
|
+
}
|
|
14739
|
+
});
|
|
14658
14740
|
renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
|
|
14659
14741
|
instantSearchInstance: instantSearchInstance
|
|
14660
14742
|
}), true);
|
|
@@ -14686,6 +14768,10 @@
|
|
|
14686
14768
|
function applyFilters(params) {
|
|
14687
14769
|
return updateStateFromSearchToolInput(params, helper);
|
|
14688
14770
|
}
|
|
14771
|
+
var insightsEventContext = {
|
|
14772
|
+
agentId: agentId,
|
|
14773
|
+
instantSearchStatus: instantSearchInstance.status
|
|
14774
|
+
};
|
|
14689
14775
|
var toolsWithAddToolResult = {};
|
|
14690
14776
|
Object.entries(tools).forEach(function(param) {
|
|
14691
14777
|
var _param = _sliced_to_array(param, 2), key = _param[0], tool = _param[1];
|
|
@@ -14693,7 +14779,8 @@
|
|
|
14693
14779
|
addToolResult: _chatInstance.addToolResult,
|
|
14694
14780
|
'~addToolResultForMessage': _chatInstance['~addToolResultForMessage'],
|
|
14695
14781
|
applyFilters: applyFilters,
|
|
14696
|
-
sendEvent: sendEvent
|
|
14782
|
+
sendEvent: sendEvent,
|
|
14783
|
+
insightsEventContext: insightsEventContext
|
|
14697
14784
|
});
|
|
14698
14785
|
toolsWithAddToolResult[key] = toolWithAddToolResult;
|
|
14699
14786
|
});
|
|
@@ -14762,45 +14849,662 @@
|
|
|
14762
14849
|
};
|
|
14763
14850
|
};
|
|
14764
14851
|
|
|
14852
|
+
var subscribe = function subscribe() {
|
|
14853
|
+
return function() {};
|
|
14854
|
+
};
|
|
14855
|
+
var getClientSnapshot = function getClientSnapshot() {
|
|
14856
|
+
return true;
|
|
14857
|
+
};
|
|
14858
|
+
var getServerSnapshot = function getServerSnapshot() {
|
|
14859
|
+
return false;
|
|
14860
|
+
};
|
|
14861
|
+
function useNativeIsHydrated() {
|
|
14862
|
+
return React__namespace.useSyncExternalStore(subscribe, getClientSnapshot, getServerSnapshot);
|
|
14863
|
+
}
|
|
14864
|
+
// React 16 and 17 have no `useSyncExternalStore`, so the flip waits for an
|
|
14865
|
+
// effect and the render itself cannot tell hydration from a plain mount. These
|
|
14866
|
+
// contexts provide that signal for the supported `getServerState` and
|
|
14867
|
+
// `InstantSearchSSRProvider` flow: the server context covers state collection,
|
|
14868
|
+
// and the SSR context covers HTML rendering and hydration.
|
|
14869
|
+
//
|
|
14870
|
+
// This can cost an extra render: a mount inside a provider that carries server
|
|
14871
|
+
// state is withheld once even when there is no server markup to reproduce. A
|
|
14872
|
+
// mount outside both contexts is never withheld.
|
|
14873
|
+
//
|
|
14874
|
+
// The shim's React 16 and 17 fallback ignores the server snapshot, so using it
|
|
14875
|
+
// here would not change this limitation.
|
|
14876
|
+
function useLegacyIsHydrated() {
|
|
14877
|
+
var serverContext = useInstantSearchServerContext();
|
|
14878
|
+
var ssrContext = useInstantSearchSSRContext();
|
|
14879
|
+
var isServerRendered = serverContext !== null || ssrContext !== null;
|
|
14880
|
+
var _React_useState = _sliced_to_array(React__namespace.useState(!isServerRendered), 2), isHydrated = _React_useState[0], setIsHydrated = _React_useState[1];
|
|
14881
|
+
React__namespace.useEffect(function() {
|
|
14882
|
+
setIsHydrated(true);
|
|
14883
|
+
}, []);
|
|
14884
|
+
return isHydrated;
|
|
14885
|
+
}
|
|
14886
|
+
/**
|
|
14887
|
+
* Whether this render can use browser state, or has to reproduce the markup a
|
|
14888
|
+
* server produced without it.
|
|
14889
|
+
*
|
|
14890
|
+
* @internal
|
|
14891
|
+
*/ var useIsHydrated = typeof React__namespace.useSyncExternalStore === 'function' ? useNativeIsHydrated : useLegacyIsHydrated;
|
|
14892
|
+
|
|
14765
14893
|
function useChat(props, additionalWidgetProperties) {
|
|
14766
|
-
|
|
14894
|
+
var isHydrated = useIsHydrated();
|
|
14895
|
+
var chatState = useConnector(connectChat, props, additionalWidgetProperties);
|
|
14896
|
+
if (isHydrated) {
|
|
14897
|
+
return chatState;
|
|
14898
|
+
}
|
|
14899
|
+
// Server rendering only promises the closed Chat shell, so a render that has
|
|
14900
|
+
// to reproduce that markup shows no conversation either. `status` is pinned
|
|
14901
|
+
// with `messages` because it diverges two ways: a server render suppresses
|
|
14902
|
+
// `resumeStream()`, which the browser runs synchronously while initialising,
|
|
14903
|
+
// and a caller-owned chat can already be streaming. `error` is pinned because
|
|
14904
|
+
// a caller-owned chat can already have failed, which a connector-built one
|
|
14905
|
+
// cannot, since its failures arrive in a microtask. `suggestions` is pinned
|
|
14906
|
+
// because the connector derives them from those messages. Only an `id` given
|
|
14907
|
+
// as a connector option passes through, because that value is the same on
|
|
14908
|
+
// both sides. Anything else is withheld: the default is random per Chat, and
|
|
14909
|
+
// an `id` carried by a caller-owned instance is no safer, since the server and
|
|
14910
|
+
// the browser each construct their own.
|
|
14911
|
+
return _object_spread_props(_object_spread({}, chatState), {
|
|
14912
|
+
error: undefined,
|
|
14913
|
+
id: 'id' in props && props.id || '',
|
|
14914
|
+
messages: [],
|
|
14915
|
+
status: 'ready',
|
|
14916
|
+
suggestions: undefined
|
|
14917
|
+
});
|
|
14767
14918
|
}
|
|
14768
14919
|
|
|
14769
|
-
|
|
14770
|
-
|
|
14771
|
-
|
|
14772
|
-
});
|
|
14773
|
-
// Reads the sibling chat widget's render state from the live cross-index
|
|
14774
|
-
// `instantSearchInstance.renderState` map. We resolve at call time so that
|
|
14775
|
-
// `toggleOpen` always sees the latest `open`/`setOpen` values.
|
|
14776
|
-
function getChatRenderState(options) {
|
|
14777
|
-
var _options_parent, _options_instantSearchInstance_renderState_indexId;
|
|
14778
|
-
var indexId = (_options_parent = options.parent) === null || _options_parent === void 0 ? void 0 : _options_parent.getIndexId();
|
|
14779
|
-
if (!indexId) return undefined;
|
|
14780
|
-
return (_options_instantSearchInstance_renderState_indexId = options.instantSearchInstance.renderState[indexId]) === null || _options_instantSearchInstance_renderState_indexId === void 0 ? void 0 : _options_instantSearchInstance_renderState_indexId.chat;
|
|
14920
|
+
function buildEndpoint(param) {
|
|
14921
|
+
var appId = param.appId, agentId = param.agentId;
|
|
14922
|
+
return "https://".concat(appId, ".algolia.net/agent-studio/1/agents/").concat(agentId, "/tasks");
|
|
14781
14923
|
}
|
|
14782
|
-
|
|
14783
|
-
|
|
14784
|
-
checkRendering(renderFn, withUsage$n());
|
|
14785
|
-
return function(widgetParams) {
|
|
14786
|
-
var params = widgetParams !== null && widgetParams !== void 0 ? widgetParams : {};
|
|
14787
|
-
var lastOptions = null;
|
|
14788
|
-
function toggleOpen() {
|
|
14789
|
-
if (!lastOptions) return;
|
|
14790
|
-
var chatState = getChatRenderState(lastOptions);
|
|
14791
|
-
if (!chatState) return;
|
|
14792
|
-
if (chatState.open) {
|
|
14793
|
-
var _chatState_setOpen;
|
|
14794
|
-
(_chatState_setOpen = chatState.setOpen) === null || _chatState_setOpen === void 0 ? void 0 : _chatState_setOpen.call(chatState, false);
|
|
14795
|
-
} else {
|
|
14796
|
-
openChat(chatState);
|
|
14797
|
-
}
|
|
14798
|
-
}
|
|
14924
|
+
function resolveEndpoint(params) {
|
|
14925
|
+
if (params.transport) {
|
|
14799
14926
|
return {
|
|
14800
|
-
|
|
14801
|
-
|
|
14802
|
-
|
|
14803
|
-
|
|
14927
|
+
endpoint: params.transport.api,
|
|
14928
|
+
headers: params.transport.headers || {},
|
|
14929
|
+
prepareSendMessagesRequest: params.transport.prepareSendMessagesRequest
|
|
14930
|
+
};
|
|
14931
|
+
}
|
|
14932
|
+
if (!params.appId || !params.apiKey || !params.agentId) {
|
|
14933
|
+
throw new Error('[tasks] Either `transport` or `{ appId, apiKey, agentId }` is required.');
|
|
14934
|
+
}
|
|
14935
|
+
var headers = {
|
|
14936
|
+
'x-algolia-application-id': params.appId,
|
|
14937
|
+
'x-algolia-api-key': params.apiKey
|
|
14938
|
+
};
|
|
14939
|
+
if (params.algoliaAgent) {
|
|
14940
|
+
headers['x-algolia-agent'] = "".concat(params.algoliaAgent, "; tasks");
|
|
14941
|
+
}
|
|
14942
|
+
return {
|
|
14943
|
+
endpoint: buildEndpoint({
|
|
14944
|
+
appId: params.appId,
|
|
14945
|
+
agentId: params.agentId
|
|
14946
|
+
}),
|
|
14947
|
+
headers: headers
|
|
14948
|
+
};
|
|
14949
|
+
}
|
|
14950
|
+
|
|
14951
|
+
function buildTaskPayload(param) {
|
|
14952
|
+
var task = param.task, input = param.input, prepareRequest = param.prepareRequest;
|
|
14953
|
+
var payload = {
|
|
14954
|
+
task: task,
|
|
14955
|
+
input: input
|
|
14956
|
+
};
|
|
14957
|
+
return prepareRequest ? prepareRequest(payload).body : payload;
|
|
14958
|
+
}
|
|
14959
|
+
function withStreamParam(url) {
|
|
14960
|
+
return url.includes('?') ? "".concat(url, "&stream=true") : "".concat(url, "?stream=true");
|
|
14961
|
+
}
|
|
14962
|
+
function resolveStreamedOutput(data, previous) {
|
|
14963
|
+
return typeof data === 'string' ? parsePartialJson(data, previous) : data;
|
|
14964
|
+
}
|
|
14965
|
+
function consumeTaskStream(body, onData) {
|
|
14966
|
+
return new Promise(function(resolve, reject) {
|
|
14967
|
+
var chunkStream = parseJsonEventStream(body);
|
|
14968
|
+
var latest;
|
|
14969
|
+
processStream(chunkStream, function(chunk) {
|
|
14970
|
+
if (!chunk) {
|
|
14971
|
+
return;
|
|
14972
|
+
}
|
|
14973
|
+
// A terminal `error` event aborts the task: reject rather than let the
|
|
14974
|
+
// stream close and resolve the last partial snapshot as a success.
|
|
14975
|
+
// Throwing here lets `processStream` release the reader and stop
|
|
14976
|
+
// consuming; the rejection propagates to the caller's `.catch`.
|
|
14977
|
+
if (chunk.type === 'error') {
|
|
14978
|
+
throw new Error(chunk.errorText || 'Task stream error');
|
|
14979
|
+
}
|
|
14980
|
+
if (chunk.type !== 'data-task-output') {
|
|
14981
|
+
return;
|
|
14982
|
+
}
|
|
14983
|
+
latest = resolveStreamedOutput(chunk.data, latest);
|
|
14984
|
+
if (onData) {
|
|
14985
|
+
onData(latest);
|
|
14986
|
+
}
|
|
14987
|
+
}, function() {
|
|
14988
|
+
return resolve(latest);
|
|
14989
|
+
}, reject);
|
|
14990
|
+
});
|
|
14991
|
+
}
|
|
14992
|
+
function fetchTask(param) {
|
|
14993
|
+
var endpoint = param.endpoint, headers = param.headers, payload = param.payload, onData = param.onData, _param_stream = param.stream, stream = _param_stream === void 0 ? true : _param_stream;
|
|
14994
|
+
return fetch(stream ? withStreamParam(endpoint) : endpoint, {
|
|
14995
|
+
method: 'POST',
|
|
14996
|
+
headers: _object_spread_props(_object_spread({}, headers), {
|
|
14997
|
+
'Content-Type': 'application/json'
|
|
14998
|
+
}),
|
|
14999
|
+
body: JSON.stringify(payload)
|
|
15000
|
+
}).then(function(response) {
|
|
15001
|
+
var _response_headers_get, _response_headers;
|
|
15002
|
+
if (!response.ok) {
|
|
15003
|
+
throw new Error("HTTP error ".concat(response.status));
|
|
15004
|
+
}
|
|
15005
|
+
var contentType = ((_response_headers = response.headers) === null || _response_headers === void 0 ? void 0 : (_response_headers_get = _response_headers.get) === null || _response_headers_get === void 0 ? void 0 : _response_headers_get.call(_response_headers, 'content-type')) || '';
|
|
15006
|
+
if (stream && response.body && contentType.includes('text/event-stream')) {
|
|
15007
|
+
return consumeTaskStream(response.body, onData);
|
|
15008
|
+
}
|
|
15009
|
+
return response.json();
|
|
15010
|
+
});
|
|
15011
|
+
}
|
|
15012
|
+
function unwrap(envelope) {
|
|
15013
|
+
return envelope === null || envelope === void 0 ? void 0 : envelope.output;
|
|
15014
|
+
}
|
|
15015
|
+
function createTaskRunner(param) {
|
|
15016
|
+
var endpoint = param.endpoint, headers = param.headers, task = param.task, _param_stream = param.stream, stream = _param_stream === void 0 ? true : _param_stream, prepareRequest = param.prepareRequest;
|
|
15017
|
+
return {
|
|
15018
|
+
submit: function submit(variables) {
|
|
15019
|
+
var onData = (arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}).onData;
|
|
15020
|
+
var payload = buildTaskPayload({
|
|
15021
|
+
task: task,
|
|
15022
|
+
input: variables,
|
|
15023
|
+
prepareRequest: prepareRequest
|
|
15024
|
+
});
|
|
15025
|
+
return fetchTask({
|
|
15026
|
+
endpoint: endpoint,
|
|
15027
|
+
headers: headers,
|
|
15028
|
+
payload: payload,
|
|
15029
|
+
stream: stream,
|
|
15030
|
+
onData: onData ? function(partial) {
|
|
15031
|
+
return onData(unwrap(partial));
|
|
15032
|
+
} : undefined
|
|
15033
|
+
}).then(unwrap);
|
|
15034
|
+
}
|
|
15035
|
+
};
|
|
15036
|
+
}
|
|
15037
|
+
|
|
15038
|
+
var withUsage$p = createDocumentationMessageGenerator({
|
|
15039
|
+
name: 'tasks',
|
|
15040
|
+
connector: true
|
|
15041
|
+
});
|
|
15042
|
+
var connectTasks = function connectTasks(renderFn) {
|
|
15043
|
+
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
15044
|
+
checkRendering(renderFn, withUsage$p());
|
|
15045
|
+
return function(widgetParams) {
|
|
15046
|
+
var agentId = widgetParams.agentId, transport = widgetParams.transport, task = widgetParams.task, _widgetParams_stream = widgetParams.stream, stream = _widgetParams_stream === void 0 ? true : _widgetParams_stream;
|
|
15047
|
+
if (!agentId && !transport) {
|
|
15048
|
+
throw new Error(withUsage$p('The `agentId` option is required unless a custom `transport` is provided.'));
|
|
15049
|
+
}
|
|
15050
|
+
if (!task) {
|
|
15051
|
+
throw new Error(withUsage$p('The `task` option is required.'));
|
|
15052
|
+
}
|
|
15053
|
+
var runner;
|
|
15054
|
+
var output;
|
|
15055
|
+
var isLoading = false;
|
|
15056
|
+
var error;
|
|
15057
|
+
var disposed = false;
|
|
15058
|
+
var triggerRender = noop;
|
|
15059
|
+
var requestId = 0;
|
|
15060
|
+
var submit = function submit(variables) {
|
|
15061
|
+
if (disposed) return Promise.resolve(undefined);
|
|
15062
|
+
var currentRequestId = requestId += 1;
|
|
15063
|
+
var isStale = function isStale() {
|
|
15064
|
+
return disposed || currentRequestId !== requestId;
|
|
15065
|
+
};
|
|
15066
|
+
// Clear the previous output so consumers can show a loading state
|
|
15067
|
+
// rather than stale data while the new request is in flight.
|
|
15068
|
+
output = undefined;
|
|
15069
|
+
error = undefined;
|
|
15070
|
+
isLoading = true;
|
|
15071
|
+
triggerRender();
|
|
15072
|
+
return Promise.resolve().then(function() {
|
|
15073
|
+
return runner.submit(variables, {
|
|
15074
|
+
onData: stream ? function(partial) {
|
|
15075
|
+
if (isStale()) return;
|
|
15076
|
+
output = partial;
|
|
15077
|
+
triggerRender();
|
|
15078
|
+
} : undefined
|
|
15079
|
+
});
|
|
15080
|
+
}).then(function(next) {
|
|
15081
|
+
var result = next;
|
|
15082
|
+
if (!isStale()) {
|
|
15083
|
+
output = result;
|
|
15084
|
+
}
|
|
15085
|
+
return result;
|
|
15086
|
+
}).catch(function(err) {
|
|
15087
|
+
if (!isStale()) {
|
|
15088
|
+
output = undefined;
|
|
15089
|
+
error = _instanceof(err, Error) ? err : new Error(String(err));
|
|
15090
|
+
}
|
|
15091
|
+
return undefined;
|
|
15092
|
+
}).finally(function() {
|
|
15093
|
+
if (isStale()) return;
|
|
15094
|
+
isLoading = false;
|
|
15095
|
+
triggerRender();
|
|
15096
|
+
});
|
|
15097
|
+
};
|
|
15098
|
+
var invalidate = function invalidate() {
|
|
15099
|
+
if (disposed) return;
|
|
15100
|
+
// Bump the request id so any in-flight request's callbacks see
|
|
15101
|
+
// `isStale()` and are ignored. The fetch itself is left to complete.
|
|
15102
|
+
requestId += 1;
|
|
15103
|
+
isLoading = false;
|
|
15104
|
+
triggerRender();
|
|
15105
|
+
};
|
|
15106
|
+
var getWidgetRenderState = function getWidgetRenderState() {
|
|
15107
|
+
return {
|
|
15108
|
+
output: output,
|
|
15109
|
+
isLoading: isLoading,
|
|
15110
|
+
error: error,
|
|
15111
|
+
submit: submit,
|
|
15112
|
+
invalidate: invalidate,
|
|
15113
|
+
widgetParams: widgetParams
|
|
15114
|
+
};
|
|
15115
|
+
};
|
|
15116
|
+
return {
|
|
15117
|
+
$$type: 'ais.tasks',
|
|
15118
|
+
init: function init(initOptions) {
|
|
15119
|
+
var instantSearchInstance = initOptions.instantSearchInstance;
|
|
15120
|
+
if (transport) {
|
|
15121
|
+
var resolved = resolveEndpoint({
|
|
15122
|
+
transport: transport
|
|
15123
|
+
});
|
|
15124
|
+
runner = createTaskRunner({
|
|
15125
|
+
endpoint: resolved.endpoint,
|
|
15126
|
+
headers: resolved.headers,
|
|
15127
|
+
task: task,
|
|
15128
|
+
stream: stream,
|
|
15129
|
+
prepareRequest: resolved.prepareSendMessagesRequest
|
|
15130
|
+
});
|
|
15131
|
+
} else {
|
|
15132
|
+
var _getAppIdAndApiKey = _sliced_to_array(getAppIdAndApiKey(instantSearchInstance.client), 2), appId = _getAppIdAndApiKey[0], apiKey = _getAppIdAndApiKey[1];
|
|
15133
|
+
if (!appId || !apiKey) {
|
|
15134
|
+
throw new Error(withUsage$p('Could not extract Algolia credentials from the search client.'));
|
|
15135
|
+
}
|
|
15136
|
+
var resolved1 = resolveEndpoint({
|
|
15137
|
+
appId: appId,
|
|
15138
|
+
apiKey: apiKey,
|
|
15139
|
+
agentId: agentId,
|
|
15140
|
+
algoliaAgent: getAlgoliaAgent(instantSearchInstance.client)
|
|
15141
|
+
});
|
|
15142
|
+
runner = createTaskRunner({
|
|
15143
|
+
endpoint: resolved1.endpoint,
|
|
15144
|
+
headers: resolved1.headers,
|
|
15145
|
+
task: task,
|
|
15146
|
+
stream: stream
|
|
15147
|
+
});
|
|
15148
|
+
}
|
|
15149
|
+
triggerRender = function triggerRender() {
|
|
15150
|
+
renderFn(_object_spread_props(_object_spread({}, getWidgetRenderState()), {
|
|
15151
|
+
instantSearchInstance: instantSearchInstance
|
|
15152
|
+
}), false);
|
|
15153
|
+
};
|
|
15154
|
+
renderFn(_object_spread_props(_object_spread({}, getWidgetRenderState()), {
|
|
15155
|
+
instantSearchInstance: instantSearchInstance
|
|
15156
|
+
}), true);
|
|
15157
|
+
},
|
|
15158
|
+
render: function render(renderOptions) {
|
|
15159
|
+
renderFn(_object_spread_props(_object_spread({}, getWidgetRenderState()), {
|
|
15160
|
+
instantSearchInstance: renderOptions.instantSearchInstance
|
|
15161
|
+
}), false);
|
|
15162
|
+
},
|
|
15163
|
+
dispose: function dispose() {
|
|
15164
|
+
disposed = true;
|
|
15165
|
+
unmountFn();
|
|
15166
|
+
}
|
|
15167
|
+
};
|
|
15168
|
+
};
|
|
15169
|
+
};
|
|
15170
|
+
|
|
15171
|
+
var withUsage$o = createDocumentationMessageGenerator({
|
|
15172
|
+
name: 'prompt-suggestions',
|
|
15173
|
+
connector: true
|
|
15174
|
+
});
|
|
15175
|
+
var RENDER_STATE_KEY = 'promptSuggestions';
|
|
15176
|
+
var CHAT_RENDER_STATE_KEY = 'chat';
|
|
15177
|
+
var DEBOUNCE_MS = 300;
|
|
15178
|
+
function parseSuggestions(data) {
|
|
15179
|
+
var suggestions = data === null || data === void 0 ? void 0 : data.suggestions;
|
|
15180
|
+
if (!Array.isArray(suggestions)) {
|
|
15181
|
+
return [];
|
|
15182
|
+
}
|
|
15183
|
+
return suggestions.filter(function(s) {
|
|
15184
|
+
return typeof s === 'string';
|
|
15185
|
+
});
|
|
15186
|
+
}
|
|
15187
|
+
function buildSuggestionMessage(suggestion) {
|
|
15188
|
+
return "The user clicked this on-page suggestion. Use the current page context first, then search only if needed.\n\nSuggestion: ".concat(suggestion);
|
|
15189
|
+
}
|
|
15190
|
+
function stripInternalHitMetadata(hit) {
|
|
15191
|
+
var clean = {};
|
|
15192
|
+
Object.keys(hit).forEach(function(key) {
|
|
15193
|
+
// Strip internal metadata, which is `_`-prefixed
|
|
15194
|
+
// (`_highlightResult`, `_rankingInfo`, `__position`, …).
|
|
15195
|
+
if (!key.startsWith('_')) {
|
|
15196
|
+
clean[key] = hit[key];
|
|
15197
|
+
}
|
|
15198
|
+
});
|
|
15199
|
+
return clean;
|
|
15200
|
+
}
|
|
15201
|
+
var DEFAULT_TRANSFORM_HITS = function DEFAULT_TRANSFORM_HITS(hits) {
|
|
15202
|
+
return hits.slice(0, 5).map(stripInternalHitMetadata);
|
|
15203
|
+
};
|
|
15204
|
+
function buildFilters(results) {
|
|
15205
|
+
var state = results._state;
|
|
15206
|
+
if (!state) {
|
|
15207
|
+
return undefined;
|
|
15208
|
+
}
|
|
15209
|
+
var groups = [];
|
|
15210
|
+
var disjunctiveGroups = {};
|
|
15211
|
+
getRefinements(results, state).forEach(function(refinement) {
|
|
15212
|
+
if (refinement.type === 'numeric') {
|
|
15213
|
+
groups.push([
|
|
15214
|
+
"".concat(refinement.attribute).concat(refinement.operator).concat(refinement.numericValue)
|
|
15215
|
+
]);
|
|
15216
|
+
return;
|
|
15217
|
+
}
|
|
15218
|
+
var value = refinement.type === 'exclude' ? "".concat(refinement.attribute, ":-").concat(refinement.name) : "".concat(refinement.attribute, ":").concat(refinement.name);
|
|
15219
|
+
if (refinement.type === 'disjunctive') {
|
|
15220
|
+
var group = disjunctiveGroups[refinement.attribute];
|
|
15221
|
+
if (group) {
|
|
15222
|
+
group.push(value);
|
|
15223
|
+
} else {
|
|
15224
|
+
var newGroup = [
|
|
15225
|
+
value
|
|
15226
|
+
];
|
|
15227
|
+
disjunctiveGroups[refinement.attribute] = newGroup;
|
|
15228
|
+
groups.push(newGroup);
|
|
15229
|
+
}
|
|
15230
|
+
return;
|
|
15231
|
+
}
|
|
15232
|
+
groups.push([
|
|
15233
|
+
value
|
|
15234
|
+
]);
|
|
15235
|
+
});
|
|
15236
|
+
return groups.length > 0 ? groups : undefined;
|
|
15237
|
+
}
|
|
15238
|
+
var connectPromptSuggestions = function connectPromptSuggestions(renderFn) {
|
|
15239
|
+
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
15240
|
+
checkRendering(renderFn, withUsage$o());
|
|
15241
|
+
return function(widgetParams) {
|
|
15242
|
+
var agentId = widgetParams.agentId, configurationId = widgetParams.configurationId, _widgetParams_transformHits = widgetParams.transformHits, transformHits = _widgetParams_transformHits === void 0 ? DEFAULT_TRANSFORM_HITS : _widgetParams_transformHits, context = widgetParams.context, _widgetParams_transformItems = widgetParams.transformItems, transformItems = _widgetParams_transformItems === void 0 ? function(items) {
|
|
15243
|
+
return items;
|
|
15244
|
+
} : _widgetParams_transformItems, transport = widgetParams.transport;
|
|
15245
|
+
if (!agentId && !transport) {
|
|
15246
|
+
throw new Error(withUsage$o('The `agentId` option is required unless a custom `transport` is provided.'));
|
|
15247
|
+
}
|
|
15248
|
+
if (!configurationId) {
|
|
15249
|
+
throw new Error(withUsage$o('The `configurationId` option is required.'));
|
|
15250
|
+
}
|
|
15251
|
+
var tasksState;
|
|
15252
|
+
var suggestions = [];
|
|
15253
|
+
var isLoading = false;
|
|
15254
|
+
var debounceTimer;
|
|
15255
|
+
var lastStateSignature = null;
|
|
15256
|
+
var latestRenderOptions = null;
|
|
15257
|
+
// Set in `dispose()`. A debounced or in-flight `fetch()` can resolve after
|
|
15258
|
+
// the widget is unmounted; this guard stops those late callbacks from
|
|
15259
|
+
// calling `renderFn` into a torn-down container.
|
|
15260
|
+
var disposed = false;
|
|
15261
|
+
// True between a state-signature change and the debounced refetch that
|
|
15262
|
+
// follows it. While pending, the search state has already moved on, so a
|
|
15263
|
+
// still-in-flight request from the previous state must not paint its
|
|
15264
|
+
// suggestions, its inner render is ignored until the new `submit` starts.
|
|
15265
|
+
var refetchPending = false;
|
|
15266
|
+
var getStateSignature = function getStateSignature(results) {
|
|
15267
|
+
var _buildFilters;
|
|
15268
|
+
if (results.queryID) {
|
|
15269
|
+
return results.queryID;
|
|
15270
|
+
}
|
|
15271
|
+
var query = results.query || '';
|
|
15272
|
+
var filters = JSON.stringify((_buildFilters = buildFilters(results)) !== null && _buildFilters !== void 0 ? _buildFilters : []);
|
|
15273
|
+
var hitIds = (results.hits || []).map(function(hit) {
|
|
15274
|
+
return hit.objectID;
|
|
15275
|
+
}).join(',');
|
|
15276
|
+
return "".concat(query, "|").concat(filters, "|").concat(hitIds);
|
|
15277
|
+
};
|
|
15278
|
+
var getChatRenderState = function getChatRenderState(renderOptions) {
|
|
15279
|
+
var _instantSearchInstance_renderState;
|
|
15280
|
+
var instantSearchInstance = renderOptions.instantSearchInstance, parent = renderOptions.parent;
|
|
15281
|
+
var indexId = parent ? parent.getIndexId() : '';
|
|
15282
|
+
if (!indexId || !((_instantSearchInstance_renderState = instantSearchInstance.renderState) === null || _instantSearchInstance_renderState === void 0 ? void 0 : _instantSearchInstance_renderState[indexId])) {
|
|
15283
|
+
return undefined;
|
|
15284
|
+
}
|
|
15285
|
+
return instantSearchInstance.renderState[indexId][CHAT_RENDER_STATE_KEY];
|
|
15286
|
+
};
|
|
15287
|
+
var sendToChat = function sendToChat(renderOptions) {
|
|
15288
|
+
return function(prompt) {
|
|
15289
|
+
var _ref, _ref1;
|
|
15290
|
+
var chatRenderState = getChatRenderState(renderOptions);
|
|
15291
|
+
if (!chatRenderState || !chatRenderState.sendMessage) {
|
|
15292
|
+
return false;
|
|
15293
|
+
}
|
|
15294
|
+
var results = (_ref = (_ref1 = latestRenderOptions === null || latestRenderOptions === void 0 ? void 0 : latestRenderOptions.results) !== null && _ref1 !== void 0 ? _ref1 : 'results' in renderOptions ? renderOptions.results : null) !== null && _ref !== void 0 ? _ref : null;
|
|
15295
|
+
return openChat(chatRenderState, {
|
|
15296
|
+
message: buildSuggestionMessage(prompt),
|
|
15297
|
+
referer: 'prompt-suggestions-widget',
|
|
15298
|
+
turnContext: buildTurnContext(results)
|
|
15299
|
+
});
|
|
15300
|
+
};
|
|
15301
|
+
};
|
|
15302
|
+
var resolvePageContext = function resolvePageContext(results) {
|
|
15303
|
+
var resolvedContext = typeof context === 'function' ? context() : context;
|
|
15304
|
+
// Explicit context replaces auto-extraction; otherwise derive it from
|
|
15305
|
+
// the current search state. The task's server-owned instructions decide
|
|
15306
|
+
// how to interpret the shape — the client doesn't label it.
|
|
15307
|
+
if (resolvedContext) {
|
|
15308
|
+
return _object_spread({}, resolvedContext);
|
|
15309
|
+
}
|
|
15310
|
+
if (!results) {
|
|
15311
|
+
return undefined;
|
|
15312
|
+
}
|
|
15313
|
+
var filters = buildFilters(results);
|
|
15314
|
+
return _object_spread_props(_object_spread({
|
|
15315
|
+
query: results.query || ''
|
|
15316
|
+
}, filters ? {
|
|
15317
|
+
filters: filters
|
|
15318
|
+
} : {}), {
|
|
15319
|
+
hitsSample: transformHits(results.hits)
|
|
15320
|
+
});
|
|
15321
|
+
};
|
|
15322
|
+
var buildInput = function buildInput(results) {
|
|
15323
|
+
var _resolvePageContext;
|
|
15324
|
+
return (_resolvePageContext = resolvePageContext(results)) !== null && _resolvePageContext !== void 0 ? _resolvePageContext : {};
|
|
15325
|
+
};
|
|
15326
|
+
// The same page context, flattened for the chat handoff: `turnContext` is
|
|
15327
|
+
// a flat `Record<string, string>` per the Agent Studio contract, so
|
|
15328
|
+
// non-string values (e.g. `hitsSample`) are serialized.
|
|
15329
|
+
var buildTurnContext = function buildTurnContext(results) {
|
|
15330
|
+
var pageContext = resolvePageContext(results);
|
|
15331
|
+
if (!pageContext) {
|
|
15332
|
+
return undefined;
|
|
15333
|
+
}
|
|
15334
|
+
var entries = Object.entries(pageContext).map(function(param) {
|
|
15335
|
+
var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
15336
|
+
return [
|
|
15337
|
+
key,
|
|
15338
|
+
typeof value === 'string' ? value : JSON.stringify(value)
|
|
15339
|
+
];
|
|
15340
|
+
}).filter(function(param) {
|
|
15341
|
+
var _param = _sliced_to_array(param, 2), value = _param[1];
|
|
15342
|
+
return value.trim() !== '';
|
|
15343
|
+
});
|
|
15344
|
+
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
15345
|
+
};
|
|
15346
|
+
var renderOutward = function renderOutward(renderOptions) {
|
|
15347
|
+
if (disposed) return;
|
|
15348
|
+
renderFn(_object_spread_props(_object_spread({}, getWidgetRenderState(renderOptions)), {
|
|
15349
|
+
instantSearchInstance: renderOptions.instantSearchInstance
|
|
15350
|
+
}), false);
|
|
15351
|
+
};
|
|
15352
|
+
var fetchAndRender = function fetchAndRender(results, renderOptions) {
|
|
15353
|
+
var _results_hits;
|
|
15354
|
+
if (disposed || !tasksState) return;
|
|
15355
|
+
refetchPending = false;
|
|
15356
|
+
var hasContext = context !== undefined;
|
|
15357
|
+
if (!hasContext && !(results === null || results === void 0 ? void 0 : (_results_hits = results.hits) === null || _results_hits === void 0 ? void 0 : _results_hits.length)) {
|
|
15358
|
+
tasksState.invalidate();
|
|
15359
|
+
suggestions = [];
|
|
15360
|
+
isLoading = false;
|
|
15361
|
+
renderOutward(renderOptions);
|
|
15362
|
+
return;
|
|
15363
|
+
}
|
|
15364
|
+
tasksState.submit(buildInput(results));
|
|
15365
|
+
};
|
|
15366
|
+
var refresh = function refresh() {
|
|
15367
|
+
if (isLoading) return;
|
|
15368
|
+
var results = latestRenderOptions === null || latestRenderOptions === void 0 ? void 0 : latestRenderOptions.results;
|
|
15369
|
+
if (!results || !latestRenderOptions) return;
|
|
15370
|
+
clearTimeout(debounceTimer);
|
|
15371
|
+
lastStateSignature = getStateSignature(results);
|
|
15372
|
+
fetchAndRender(results, latestRenderOptions);
|
|
15373
|
+
};
|
|
15374
|
+
var getWidgetRenderState = function getWidgetRenderState(renderOptions) {
|
|
15375
|
+
var results = 'results' in renderOptions ? renderOptions.results : undefined;
|
|
15376
|
+
var transformed = transformItems(suggestions, {
|
|
15377
|
+
query: (results === null || results === void 0 ? void 0 : results.query) || '',
|
|
15378
|
+
results: results || null
|
|
15379
|
+
});
|
|
15380
|
+
var chatRenderState = getChatRenderState(renderOptions);
|
|
15381
|
+
var isChatBusy$1 = chatRenderState ? !chatRenderState.sendMessage || isChatBusy(chatRenderState) : false;
|
|
15382
|
+
var send = sendToChat(renderOptions);
|
|
15383
|
+
return {
|
|
15384
|
+
suggestions: transformed,
|
|
15385
|
+
isLoading: isLoading,
|
|
15386
|
+
onSuggestionClick: send,
|
|
15387
|
+
sendToChat: send,
|
|
15388
|
+
refresh: refresh,
|
|
15389
|
+
isChatBusy: isChatBusy$1,
|
|
15390
|
+
widgetParams: widgetParams
|
|
15391
|
+
};
|
|
15392
|
+
};
|
|
15393
|
+
// Mirrors each inner render (submit start → skeleton, stream partials,
|
|
15394
|
+
// resolve/error) into this widget's state and re-renders on the client.
|
|
15395
|
+
var handleInnerRender = function handleInnerRender(renderState) {
|
|
15396
|
+
tasksState = renderState;
|
|
15397
|
+
if (refetchPending) return;
|
|
15398
|
+
if (renderState.error) {
|
|
15399
|
+
// A failed task (including a mid-stream `error` event) must not leave
|
|
15400
|
+
// any streamed partial visible. There's no error UI for now, so fall
|
|
15401
|
+
// back to a blank suggestions state.
|
|
15402
|
+
suggestions = [];
|
|
15403
|
+
} else if (renderState.isLoading || renderState.output !== undefined) {
|
|
15404
|
+
// Only adopt the inner output once a request is loading or has
|
|
15405
|
+
// produced one, so the initial no-op render doesn't clobber pills.
|
|
15406
|
+
suggestions = parseSuggestions(renderState.output);
|
|
15407
|
+
}
|
|
15408
|
+
isLoading = renderState.isLoading;
|
|
15409
|
+
if (!latestRenderOptions) return;
|
|
15410
|
+
renderOutward(latestRenderOptions);
|
|
15411
|
+
};
|
|
15412
|
+
var tasksWidget = connectTasks(handleInnerRender, noop)(_object_spread_props(_object_spread({}, transport ? {
|
|
15413
|
+
transport: transport
|
|
15414
|
+
} : {
|
|
15415
|
+
agentId: agentId
|
|
15416
|
+
}), {
|
|
15417
|
+
task: configurationId,
|
|
15418
|
+
stream: true
|
|
15419
|
+
}));
|
|
15420
|
+
return {
|
|
15421
|
+
$$type: 'ais.promptSuggestions',
|
|
15422
|
+
init: function init(initOptions) {
|
|
15423
|
+
var instantSearchInstance = initOptions.instantSearchInstance;
|
|
15424
|
+
tasksWidget.init(initOptions);
|
|
15425
|
+
renderFn(_object_spread_props(_object_spread({}, getWidgetRenderState(initOptions)), {
|
|
15426
|
+
instantSearchInstance: instantSearchInstance
|
|
15427
|
+
}), true);
|
|
15428
|
+
},
|
|
15429
|
+
render: function render(renderOptions) {
|
|
15430
|
+
var results = renderOptions.results, instantSearchInstance = renderOptions.instantSearchInstance;
|
|
15431
|
+
latestRenderOptions = renderOptions;
|
|
15432
|
+
if (!results) {
|
|
15433
|
+
renderFn(_object_spread_props(_object_spread({}, getWidgetRenderState(renderOptions)), {
|
|
15434
|
+
instantSearchInstance: instantSearchInstance
|
|
15435
|
+
}), false);
|
|
15436
|
+
return;
|
|
15437
|
+
}
|
|
15438
|
+
var stateSignature = getStateSignature(results);
|
|
15439
|
+
if (stateSignature !== lastStateSignature) {
|
|
15440
|
+
lastStateSignature = stateSignature;
|
|
15441
|
+
refetchPending = true;
|
|
15442
|
+
clearTimeout(debounceTimer);
|
|
15443
|
+
debounceTimer = setTimeout(function() {
|
|
15444
|
+
if (latestRenderOptions === null || latestRenderOptions === void 0 ? void 0 : latestRenderOptions.results) {
|
|
15445
|
+
fetchAndRender(latestRenderOptions.results, latestRenderOptions);
|
|
15446
|
+
}
|
|
15447
|
+
}, DEBOUNCE_MS);
|
|
15448
|
+
}
|
|
15449
|
+
renderFn(_object_spread_props(_object_spread({}, getWidgetRenderState(renderOptions)), {
|
|
15450
|
+
instantSearchInstance: instantSearchInstance
|
|
15451
|
+
}), false);
|
|
15452
|
+
},
|
|
15453
|
+
dispose: function dispose(disposeOptions) {
|
|
15454
|
+
disposed = true;
|
|
15455
|
+
clearTimeout(debounceTimer);
|
|
15456
|
+
tasksWidget.dispose(disposeOptions);
|
|
15457
|
+
unmountFn();
|
|
15458
|
+
},
|
|
15459
|
+
getRenderState: function getRenderState(renderState, renderOptions) {
|
|
15460
|
+
return _object_spread_props(_object_spread({}, renderState), _define_property({}, RENDER_STATE_KEY, this.getWidgetRenderState(renderOptions)));
|
|
15461
|
+
},
|
|
15462
|
+
getWidgetRenderState: function getWidgetRenderState1(renderOptions) {
|
|
15463
|
+
return getWidgetRenderState(renderOptions);
|
|
15464
|
+
}
|
|
15465
|
+
};
|
|
15466
|
+
};
|
|
15467
|
+
};
|
|
15468
|
+
|
|
15469
|
+
function usePromptSuggestions(props, additionalWidgetProperties) {
|
|
15470
|
+
return useConnector(connectPromptSuggestions, props, additionalWidgetProperties);
|
|
15471
|
+
}
|
|
15472
|
+
|
|
15473
|
+
var withUsage$n = createDocumentationMessageGenerator({
|
|
15474
|
+
name: 'chatTrigger',
|
|
15475
|
+
connector: true
|
|
15476
|
+
});
|
|
15477
|
+
// Reads the sibling chat widget's render state from the live cross-index
|
|
15478
|
+
// `instantSearchInstance.renderState` map. We resolve at call time so that
|
|
15479
|
+
// `toggleOpen` always sees the latest `open`/`setOpen` values.
|
|
15480
|
+
function getChatRenderState(options) {
|
|
15481
|
+
var _options_parent, _options_instantSearchInstance_renderState_indexId;
|
|
15482
|
+
var indexId = (_options_parent = options.parent) === null || _options_parent === void 0 ? void 0 : _options_parent.getIndexId();
|
|
15483
|
+
if (!indexId) return undefined;
|
|
15484
|
+
return (_options_instantSearchInstance_renderState_indexId = options.instantSearchInstance.renderState[indexId]) === null || _options_instantSearchInstance_renderState_indexId === void 0 ? void 0 : _options_instantSearchInstance_renderState_indexId.chat;
|
|
15485
|
+
}
|
|
15486
|
+
var connectChatTrigger = function connectChatTrigger(renderFn) {
|
|
15487
|
+
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
15488
|
+
checkRendering(renderFn, withUsage$n());
|
|
15489
|
+
return function(widgetParams) {
|
|
15490
|
+
var params = widgetParams !== null && widgetParams !== void 0 ? widgetParams : {};
|
|
15491
|
+
var lastOptions = null;
|
|
15492
|
+
function toggleOpen() {
|
|
15493
|
+
if (!lastOptions) return;
|
|
15494
|
+
var chatState = getChatRenderState(lastOptions);
|
|
15495
|
+
if (!chatState) return;
|
|
15496
|
+
if (chatState.open) {
|
|
15497
|
+
var _chatState_setOpen;
|
|
15498
|
+
(_chatState_setOpen = chatState.setOpen) === null || _chatState_setOpen === void 0 ? void 0 : _chatState_setOpen.call(chatState, false);
|
|
15499
|
+
} else {
|
|
15500
|
+
openChat(chatState);
|
|
15501
|
+
}
|
|
15502
|
+
}
|
|
15503
|
+
return {
|
|
15504
|
+
$$type: 'ais.chatTrigger',
|
|
15505
|
+
opensChat: true,
|
|
15506
|
+
dependsOn: 'none',
|
|
15507
|
+
init: function init(initOptions) {
|
|
14804
15508
|
lastOptions = initOptions;
|
|
14805
15509
|
renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
|
|
14806
15510
|
instantSearchInstance: initOptions.instantSearchInstance
|
|
@@ -19543,7 +20247,35 @@
|
|
|
19543
20247
|
d: "M17 14V2"
|
|
19544
20248
|
}));
|
|
19545
20249
|
}
|
|
19546
|
-
function
|
|
20250
|
+
function BrainIcon(param) {
|
|
20251
|
+
var createElement = param.createElement;
|
|
20252
|
+
return /*#__PURE__*/ createElement("svg", {
|
|
20253
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
20254
|
+
viewBox: "0 0 24 24",
|
|
20255
|
+
fill: "none",
|
|
20256
|
+
stroke: "currentColor",
|
|
20257
|
+
strokeLinecap: "round",
|
|
20258
|
+
strokeLinejoin: "round",
|
|
20259
|
+
"aria-hidden": "true"
|
|
20260
|
+
}, /*#__PURE__*/ createElement("path", {
|
|
20261
|
+
d: "M12 18V5"
|
|
20262
|
+
}), /*#__PURE__*/ createElement("path", {
|
|
20263
|
+
d: "M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4"
|
|
20264
|
+
}), /*#__PURE__*/ createElement("path", {
|
|
20265
|
+
d: "M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5"
|
|
20266
|
+
}), /*#__PURE__*/ createElement("path", {
|
|
20267
|
+
d: "M17.997 5.125a4 4 0 0 1 2.526 5.77"
|
|
20268
|
+
}), /*#__PURE__*/ createElement("path", {
|
|
20269
|
+
d: "M18 18a4 4 0 0 0 2-7.464"
|
|
20270
|
+
}), /*#__PURE__*/ createElement("path", {
|
|
20271
|
+
d: "M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517"
|
|
20272
|
+
}), /*#__PURE__*/ createElement("path", {
|
|
20273
|
+
d: "M6 18a4 4 0 0 1-2-7.464"
|
|
20274
|
+
}), /*#__PURE__*/ createElement("path", {
|
|
20275
|
+
d: "M6.003 5.125a4 4 0 0 0-2.526 5.77"
|
|
20276
|
+
}));
|
|
20277
|
+
}
|
|
20278
|
+
function ChevronLeftIcon(param) {
|
|
19547
20279
|
var createElement = param.createElement;
|
|
19548
20280
|
return /*#__PURE__*/ createElement("svg", {
|
|
19549
20281
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -20196,6 +20928,22 @@
|
|
|
20196
20928
|
};
|
|
20197
20929
|
}
|
|
20198
20930
|
|
|
20931
|
+
function updateNavigationButtonsProps(param) {
|
|
20932
|
+
var listRef = param.listRef, nextButtonRef = param.nextButtonRef, previousButtonRef = param.previousButtonRef, setCanScrollLeft = param.setCanScrollLeft, setCanScrollRight = param.setCanScrollRight;
|
|
20933
|
+
if (!listRef.current) {
|
|
20934
|
+
return;
|
|
20935
|
+
}
|
|
20936
|
+
var isLeftHidden = listRef.current.scrollLeft <= 0;
|
|
20937
|
+
var isRightHidden = listRef.current.scrollLeft + listRef.current.clientWidth >= listRef.current.scrollWidth;
|
|
20938
|
+
setCanScrollLeft(!isLeftHidden);
|
|
20939
|
+
setCanScrollRight(!isRightHidden);
|
|
20940
|
+
if (previousButtonRef.current) {
|
|
20941
|
+
previousButtonRef.current.hidden = isLeftHidden;
|
|
20942
|
+
}
|
|
20943
|
+
if (nextButtonRef.current) {
|
|
20944
|
+
nextButtonRef.current.hidden = isRightHidden;
|
|
20945
|
+
}
|
|
20946
|
+
}
|
|
20199
20947
|
var lastCarouselId = 0;
|
|
20200
20948
|
function generateCarouselId() {
|
|
20201
20949
|
return "ais-Carousel-".concat(lastCarouselId++);
|
|
@@ -20229,7 +20977,7 @@
|
|
|
20229
20977
|
}));
|
|
20230
20978
|
}
|
|
20231
20979
|
function createCarouselComponent(param) {
|
|
20232
|
-
var createElement = param.createElement, Fragment = param.Fragment;
|
|
20980
|
+
var createElement = param.createElement, Fragment = param.Fragment, useEffect = param.useEffect, useRef = param.useRef;
|
|
20233
20981
|
return function Carousel(userProps) {
|
|
20234
20982
|
var listRef = userProps.listRef, nextButtonRef = userProps.nextButtonRef, previousButtonRef = userProps.previousButtonRef, carouselIdRef = userProps.carouselIdRef, canScrollLeft = userProps.canScrollLeft, canScrollRight = userProps.canScrollRight, setCanScrollLeft = userProps.setCanScrollLeft, setCanScrollRight = userProps.setCanScrollRight, _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, tmp = userProps.itemComponent, ItemComponent = tmp === void 0 ? createDefaultItemComponent({
|
|
20235
20983
|
createElement: createElement,
|
|
@@ -20260,6 +21008,7 @@
|
|
|
20260
21008
|
previousButtonLabel: 'Previous',
|
|
20261
21009
|
previousButtonTitle: 'Previous'
|
|
20262
21010
|
}, userTranslations);
|
|
21011
|
+
var previousItemsLengthRef = useRef(items.length);
|
|
20263
21012
|
var cssClasses = {
|
|
20264
21013
|
root: cx('ais-Carousel', classNames.root),
|
|
20265
21014
|
list: cx('ais-Carousel-list', classNames.list),
|
|
@@ -20278,27 +21027,33 @@
|
|
|
20278
21027
|
listRef.current.scrollLeft += listRef.current.offsetWidth * 0.75;
|
|
20279
21028
|
}
|
|
20280
21029
|
}
|
|
20281
|
-
function
|
|
20282
|
-
if (
|
|
20283
|
-
|
|
20284
|
-
|
|
20285
|
-
|
|
20286
|
-
|
|
20287
|
-
|
|
20288
|
-
|
|
20289
|
-
|
|
20290
|
-
|
|
20291
|
-
}
|
|
20292
|
-
if (nextButtonRef.current) {
|
|
20293
|
-
nextButtonRef.current.hidden = isRightHidden;
|
|
21030
|
+
useEffect(function() {
|
|
21031
|
+
if (previousItemsLengthRef.current !== items.length) {
|
|
21032
|
+
updateNavigationButtonsProps({
|
|
21033
|
+
listRef: listRef,
|
|
21034
|
+
nextButtonRef: nextButtonRef,
|
|
21035
|
+
previousButtonRef: previousButtonRef,
|
|
21036
|
+
setCanScrollLeft: setCanScrollLeft,
|
|
21037
|
+
setCanScrollRight: setCanScrollRight
|
|
21038
|
+
});
|
|
21039
|
+
previousItemsLengthRef.current = items.length;
|
|
20294
21040
|
}
|
|
20295
|
-
}
|
|
21041
|
+
}, [
|
|
21042
|
+
items.length,
|
|
21043
|
+
listRef,
|
|
21044
|
+
nextButtonRef,
|
|
21045
|
+
previousButtonRef,
|
|
21046
|
+
setCanScrollLeft,
|
|
21047
|
+
setCanScrollRight
|
|
21048
|
+
]);
|
|
20296
21049
|
if (items.length === 0) {
|
|
20297
21050
|
return null;
|
|
20298
21051
|
}
|
|
21052
|
+
var itemOccurrences = new Map();
|
|
20299
21053
|
return /*#__PURE__*/ createElement("div", _object_spread_props(_object_spread({}, props), {
|
|
20300
21054
|
className: cx(cssClasses.root)
|
|
20301
21055
|
}), HeaderComponent && /*#__PURE__*/ createElement(HeaderComponent, {
|
|
21056
|
+
nbItems: items.length,
|
|
20302
21057
|
canScrollLeft: canScrollLeft,
|
|
20303
21058
|
canScrollRight: canScrollRight,
|
|
20304
21059
|
scrollLeft: scrollLeft,
|
|
@@ -20324,7 +21079,15 @@
|
|
|
20324
21079
|
"aria-roledescription": "carousel",
|
|
20325
21080
|
"aria-label": translations.listLabel,
|
|
20326
21081
|
"aria-live": "polite",
|
|
20327
|
-
onScroll:
|
|
21082
|
+
onScroll: function onScroll() {
|
|
21083
|
+
return updateNavigationButtonsProps({
|
|
21084
|
+
listRef: listRef,
|
|
21085
|
+
nextButtonRef: nextButtonRef,
|
|
21086
|
+
previousButtonRef: previousButtonRef,
|
|
21087
|
+
setCanScrollLeft: setCanScrollLeft,
|
|
21088
|
+
setCanScrollRight: setCanScrollRight
|
|
21089
|
+
});
|
|
21090
|
+
},
|
|
20328
21091
|
onKeyDown: function onKeyDown(event) {
|
|
20329
21092
|
if (event.key === 'ArrowLeft') {
|
|
20330
21093
|
event.preventDefault();
|
|
@@ -20335,8 +21098,14 @@
|
|
|
20335
21098
|
}
|
|
20336
21099
|
}
|
|
20337
21100
|
}, items.map(function(item, index) {
|
|
21101
|
+
var _itemOccurrences_get;
|
|
21102
|
+
var occurrence = (_itemOccurrences_get = itemOccurrences.get(item.objectID)) !== null && _itemOccurrences_get !== void 0 ? _itemOccurrences_get : 0;
|
|
21103
|
+
itemOccurrences.set(item.objectID, occurrence + 1);
|
|
20338
21104
|
return /*#__PURE__*/ createElement("li", {
|
|
20339
|
-
key:
|
|
21105
|
+
key: JSON.stringify([
|
|
21106
|
+
item.objectID,
|
|
21107
|
+
occurrence
|
|
21108
|
+
]),
|
|
20340
21109
|
className: cx(cssClasses.item),
|
|
20341
21110
|
"aria-roledescription": "slide",
|
|
20342
21111
|
"aria-label": "".concat(index + 1, " of ").concat(items.length),
|
|
@@ -20446,7 +21215,7 @@
|
|
|
20446
21215
|
var SearchIndexToolType$1 = 'algolia_search_index';
|
|
20447
21216
|
var getTextContent = function getTextContent(message) {
|
|
20448
21217
|
return message.parts.map(function(part) {
|
|
20449
|
-
return 'text'
|
|
21218
|
+
return part.type === 'text' ? part.text : '';
|
|
20450
21219
|
}).join('');
|
|
20451
21220
|
};
|
|
20452
21221
|
var hasTextContent = function hasTextContent(message) {
|
|
@@ -20458,6 +21227,12 @@
|
|
|
20458
21227
|
var isPartTool = function isPartTool(part) {
|
|
20459
21228
|
return startsWith(part.type, 'tool-');
|
|
20460
21229
|
};
|
|
21230
|
+
function isReasoningPartActive(parts, index) {
|
|
21231
|
+
var part = parts[index];
|
|
21232
|
+
return (part === null || part === void 0 ? void 0 : part.type) === 'reasoning' && part.state === 'streaming' && !parts.slice(index + 1).some(function(laterPart) {
|
|
21233
|
+
return laterPart.type !== 'reasoning' || laterPart.state === 'streaming';
|
|
21234
|
+
});
|
|
21235
|
+
}
|
|
20461
21236
|
var findTool = function findTool(partType, tools) {
|
|
20462
21237
|
var toolName = partType.replace('tool-', '');
|
|
20463
21238
|
var tool = tools[toolName];
|
|
@@ -20471,22 +21246,23 @@
|
|
|
20471
21246
|
return tool;
|
|
20472
21247
|
};
|
|
20473
21248
|
var FACET_KEY_PREFIX = 'facet_';
|
|
20474
|
-
|
|
20475
|
-
|
|
20476
|
-
|
|
20477
|
-
|
|
20478
|
-
* Algolia MCP Server search tool instead expresses refinements as individual
|
|
20479
|
-
* `facet_<attribute>` keys (e.g. `facet_categories: ['Books', 'Toys']`), which
|
|
20480
|
-
* are converted here into the `[['attribute:value']]` shape `applyFilters`
|
|
20481
|
-
* expects.
|
|
20482
|
-
*/ var getFacetFiltersFromToolInput = function getFacetFiltersFromToolInput(input) {
|
|
21249
|
+
var hasQueries = function hasQueries(input) {
|
|
21250
|
+
return Array.isArray(input.queries);
|
|
21251
|
+
};
|
|
21252
|
+
var getSearchToolQuery = function getSearchToolQuery(input) {
|
|
20483
21253
|
if (!input) {
|
|
20484
21254
|
return undefined;
|
|
20485
21255
|
}
|
|
20486
|
-
|
|
20487
|
-
|
|
21256
|
+
return hasQueries(input) ? input.queries[0] : input;
|
|
21257
|
+
};
|
|
21258
|
+
var getFacetFilters = function getFacetFilters(query) {
|
|
21259
|
+
if (!query) {
|
|
21260
|
+
return undefined;
|
|
21261
|
+
}
|
|
21262
|
+
if (Array.isArray(query.facet_filters)) {
|
|
21263
|
+
return query.facet_filters;
|
|
20488
21264
|
}
|
|
20489
|
-
var facetFilters = Object.entries(
|
|
21265
|
+
var facetFilters = Object.entries(query).reduce(function(acc, param) {
|
|
20490
21266
|
var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
20491
21267
|
if (!startsWith(key, FACET_KEY_PREFIX) || !Array.isArray(value)) {
|
|
20492
21268
|
return acc;
|
|
@@ -20504,6 +21280,21 @@
|
|
|
20504
21280
|
}, []);
|
|
20505
21281
|
return facetFilters.length > 0 ? facetFilters : undefined;
|
|
20506
21282
|
};
|
|
21283
|
+
/**
|
|
21284
|
+
* Extracts the refinements a search tool searched with, in the shape
|
|
21285
|
+
* `applyFilters` expects.
|
|
21286
|
+
*
|
|
21287
|
+
* The default search tool provides a ready-to-use `facet_filters` array. The
|
|
21288
|
+
* Algolia MCP Server search tool instead expresses refinements as individual
|
|
21289
|
+
* `facet_<attribute>` keys (e.g. `facet_categories: ['Books', 'Toys']`), which
|
|
21290
|
+
* are converted here into `[['attribute:value']]`.
|
|
21291
|
+
*/ var getApplyFiltersParamsFromToolInput = function getApplyFiltersParamsFromToolInput(input) {
|
|
21292
|
+
var query = getSearchToolQuery(input);
|
|
21293
|
+
return {
|
|
21294
|
+
query: query === null || query === void 0 ? void 0 : query.query,
|
|
21295
|
+
facetFilters: getFacetFilters(query)
|
|
21296
|
+
};
|
|
21297
|
+
};
|
|
20507
21298
|
var isSearchToolPart = function isSearchToolPart(part) {
|
|
20508
21299
|
return part.type === "tool-".concat(SearchIndexToolType$1) || // Compatibility shim with Algolia MCP Server search tool
|
|
20509
21300
|
startsWith(part.type, "tool-".concat(SearchIndexToolType$1, "_"));
|
|
@@ -20531,59 +21322,72 @@
|
|
|
20531
21322
|
* relies on this map to hydrate each result with the full record that the
|
|
20532
21323
|
* preceding search tool already fetched.
|
|
20533
21324
|
*
|
|
20534
|
-
* Pass
|
|
20535
|
-
*
|
|
20536
|
-
*
|
|
20537
|
-
*
|
|
20538
|
-
|
|
20539
|
-
|
|
20540
|
-
var
|
|
20541
|
-
|
|
20542
|
-
|
|
20543
|
-
|
|
20544
|
-
var message = _step.value;
|
|
20545
|
-
var reachedBoundary = false;
|
|
20546
|
-
message.parts.forEach(function(part) {
|
|
20547
|
-
if (!isPartTool(part)) {
|
|
20548
|
-
return;
|
|
20549
|
-
}
|
|
20550
|
-
// Note the boundary but keep processing the rest of this message's parts:
|
|
20551
|
-
// the search tool that fed this display tool lives in the same message,
|
|
20552
|
-
// so its hits must still be collected before we stop.
|
|
20553
|
-
if (untilToolCallId && part.toolCallId === untilToolCallId) {
|
|
20554
|
-
reachedBoundary = true;
|
|
20555
|
-
}
|
|
20556
|
-
if (isSearchToolPart(part)) {
|
|
20557
|
-
collectHitsFromPart(part, hitsByObjectID);
|
|
20558
|
-
}
|
|
20559
|
-
});
|
|
20560
|
-
if (reachedBoundary) {
|
|
20561
|
-
return "break";
|
|
21325
|
+
* Pass the display tool's own message part to scope collection to that exact
|
|
21326
|
+
* occurrence. This prevents reused tool call IDs and later searches from
|
|
21327
|
+
* changing another display tool's records or per-query metadata like
|
|
21328
|
+
* `__queryID`.
|
|
21329
|
+
*/ var getHitsByObjectID = function getHitsByObjectID(messages, untilToolPart) {
|
|
21330
|
+
var hitsByObjectID = Object.create(null);
|
|
21331
|
+
var reachedBoundary = messages.some(function(message) {
|
|
21332
|
+
return message.parts.some(function(part) {
|
|
21333
|
+
if (!isPartTool(part)) {
|
|
21334
|
+
return false;
|
|
20562
21335
|
}
|
|
20563
|
-
|
|
20564
|
-
|
|
20565
|
-
var _ret = _loop();
|
|
20566
|
-
if (_ret === "break") break;
|
|
20567
|
-
}
|
|
20568
|
-
} catch (err) {
|
|
20569
|
-
_didIteratorError = true;
|
|
20570
|
-
_iteratorError = err;
|
|
20571
|
-
} finally{
|
|
20572
|
-
try {
|
|
20573
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
20574
|
-
_iterator.return();
|
|
21336
|
+
if (untilToolPart && part === untilToolPart) {
|
|
21337
|
+
return true;
|
|
20575
21338
|
}
|
|
20576
|
-
|
|
20577
|
-
|
|
20578
|
-
throw _iteratorError;
|
|
21339
|
+
if (isSearchToolPart(part)) {
|
|
21340
|
+
collectHitsFromPart(part, hitsByObjectID);
|
|
20579
21341
|
}
|
|
20580
|
-
|
|
21342
|
+
return false;
|
|
21343
|
+
});
|
|
21344
|
+
});
|
|
21345
|
+
if (untilToolPart && !reachedBoundary) {
|
|
21346
|
+
return Object.create(null);
|
|
20581
21347
|
}
|
|
20582
21348
|
return hitsByObjectID;
|
|
20583
21349
|
};
|
|
20584
21350
|
|
|
20585
21351
|
function n(){return n=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t]);}return e},n.apply(this,arguments)}const o=["allowFullScreen","allowTransparency","autoComplete","autoFocus","autoPlay","cellPadding","cellSpacing","charSet","classId","colSpan","contentEditable","contextMenu","crossOrigin","encType","formAction","formEncType","formMethod","formNoValidate","formTarget","frameBorder","hrefLang","inputMode","keyParams","keyType","marginHeight","marginWidth","maxLength","mediaGroup","minLength","noValidate","radioGroup","readOnly","rowSpan","spellCheck","srcDoc","srcLang","srcSet","tabIndex","useMap"].reduce((e,n)=>(e[n.toLowerCase()]=n,e),{class:"className",for:"htmlFor"}),a={amp:"&",apos:"'",gt:">",lt:"<",nbsp:" ",quot:"“"},c=["style","script","pre"],i=["src","href","data","formAction","srcDoc","action"],u=/([-A-Z0-9_:]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|(?:\{((?:\\.|{[^}]*?}|[^}])*)\})))?/gi,l=/\n{2,}$/,s=/^(\s*>[\s\S]*?)(?=\n\n|$)/,f=/^ *> ?/gm,_=/^(?:\[!([^\]]*)\]\n)?([\s\S]*)/,d=/^ {2,}\n/,p=/^(?:([-*_])( *\1){2,}) *(?:\n *)+\n/,y=/^(?: {1,3})?(`{3,}|~{3,}) *(\S+)? *([^\n]*?)?\n([\s\S]*?)(?:\1\n?|$)/,h=/^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/,g=/^(`+)((?:\\`|(?!\1)`|[^`])+)\1/,m=/^(?:\n *)*\n/,k=/\r\n?/g,x=/^\[\^([^\]]+)](:(.*)((\n+ {4,}.*)|(\n(?!\[\^).+))*)/,q=/^\[\^([^\]]+)]/,v=/\f/g,b=/^---[ \t]*\n(.|\n)*\n---[ \t]*\n/,$=/^\s*?\[(x|\s)\]/,S=/^ *(#{1,6}) *([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/,z=/^ *(#{1,6}) +([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/,E=/^([^\n]+)\n *(=|-)\2{2,} *\n/,A=/^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?((?:[^>]*[^/])?)>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1\b)[\s\S])*?)<\/\1>(?!<\/\1>)\n*/i,R=/&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/gi,B=/^<!--[\s\S]*?(?:-->)/,L=/^(data|aria|x)-[a-z_][a-z\d_.-]*$/,O=/^ *<([a-z][a-z0-9:]*)(?:\s+((?:<.*?>|[^>])*))?\/?>(?!<\/\1>)(\s*\n)?/i,j=/^\{.*\}$/,C=/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,I=/^<([^ >]+[:@\/][^ >]+)>/,T=/-([a-z])?/gi,M=/^(\|.*)\n(?: *(\|? *[-:]+ *\|[-| :]*)\n((?:.*\|.*\n)*))?\n?/,w=/^[^\n]+(?: \n|\n{2,})/,D=/^\[([^\]]*)\]:\s+<?([^\s>]+)>?\s*("([^"]*)")?/,F=/^!\[([^\]]*)\] ?\[([^\]]*)\]/,P=/^\[([^\]]*)\] ?\[([^\]]*)\]/,Z=/(\n|^[-*]\s|^#|^ {2,}|^-{2,}|^>\s)/,N=/\t/g,G=/(^ *\||\| *$)/g,U=/^ *:-+: *$/,V=/^ *:-+ *$/,H=/^ *-+: *$/,Q=e=>`(?=[\\s\\S]+?\\1${e?"\\1":""})`,W="((?:\\[.*?\\][([].*?[)\\]]|<.*?>(?:.*?<.*?>)?|`.*?`|\\\\\\1|[\\s\\S])+?)",J=RegExp(`^([*_])\\1${Q(1)}${W}\\1\\1(?!\\1)`),K=RegExp(`^([*_])${Q(0)}${W}\\1(?!\\1)`),X=RegExp(`^(==)${Q(0)}${W}\\1`),Y=RegExp(`^(~~)${Q(0)}${W}\\1`),ee=/^(:[a-zA-Z0-9-_]+:)/,ne=/^\\([^0-9A-Za-z\s])/,re=/\\([^0-9A-Za-z\s])/g,te=/^[\s\S](?:(?! \n|[0-9]\.|http)[^=*_~\-\n:<`\\\[!])*/,oe=/^\n+/,ae=/^([ \t]*)/,ce=/(?:^|\n)( *)$/,ie="(?:\\d+\\.)",ue="(?:[*+-])";function le(e){return "( *)("+(1===e?ie:ue)+") +"}const se=le(1),fe=le(2);function _e(e){return RegExp("^"+(1===e?se:fe))}const de=_e(1),pe=_e(2);function ye(e){return RegExp("^"+(1===e?se:fe)+"[^\\n]*(?:\\n(?!\\1"+(1===e?ie:ue)+" )[^\\n]*)*(\\n|$)","gm")}const he=ye(1),ge=ye(2);function me(e){const n=1===e?ie:ue;return RegExp("^( *)("+n+") [\\s\\S]+?(?:\\n{2,}(?! )(?!\\1"+n+" (?!"+n+" ))\\n*|\\s*\\n*$)")}const ke=me(1),xe=me(2);function qe(e,n){const r=1===n,t=r?ke:xe,o=r?he:ge,a=r?de:pe;return {t:e=>a.test(e),o:je(function(e,n){const r=ce.exec(n.prevCapture);return r&&(n.list||!n.inline&&!n.simple)?t.exec(e=r[1]+e):null}),i:1,u(e,n,t){const c=r?+e[2]:void 0,i=e[0].replace(l,"\n").match(o);let u=!1;return {items:i.map(function(e,r){const o=a.exec(e)[0].length,c=RegExp("^ {1,"+o+"}","gm"),l=e.replace(c,"").replace(a,""),s=r===i.length-1,f=-1!==l.indexOf("\n\n")||s&&u;u=f;const _=t.inline,d=t.list;let p;t.list=!0,f?(t.inline=!1,p=Se(l)+"\n\n"):(t.inline=!0,p=Se(l));const y=n(p,t);return t.inline=_,t.list=d,y}),ordered:r,start:c}},l:(n,r,t)=>e(n.ordered?"ol":"ul",{key:t.key,start:"20"===n.type?n.start:void 0},n.items.map(function(n,o){return e("li",{key:o},r(n,t))}))}}const ve=RegExp("^\\[((?:\\[[^\\[\\]]*(?:\\[[^\\[\\]]*\\][^\\[\\]]*)*\\]|[^\\[\\]])*)\\]\\(\\s*<?((?:\\([^)]*\\)|[^\\s\\\\]|\\\\.)*?)>?(?:\\s+['\"]([\\s\\S]*?)['\"])?\\s*\\)"),be=/^!\[(.*?)\]\( *((?:\([^)]*\)|[^() ])*) *"?([^)"]*)?"?\)/;function $e(e){return "string"==typeof e}function Se(e){let n=e.length;for(;n>0&&e[n-1]<=" ";)n--;return e.slice(0,n)}function ze(e,n){return e.startsWith(n)}function Ee(e,n,r){if(Array.isArray(r)){for(let n=0;n<r.length;n++)if(ze(e,r[n]))return !0;return !1}return r(e,n)}function Ae(e){return e.replace(/[ÀÁÂÃÄÅàáâãä忯]/g,"a").replace(/[çÇ]/g,"c").replace(/[ðÐ]/g,"d").replace(/[ÈÉÊËéèêë]/g,"e").replace(/[ÏïÎîÍíÌì]/g,"i").replace(/[Ññ]/g,"n").replace(/[øØœŒÕõÔôÓóÒò]/g,"o").replace(/[ÜüÛûÚúÙù]/g,"u").replace(/[ŸÿÝý]/g,"y").replace(/[^a-z0-9- ]/gi,"").replace(/ /gi,"-").toLowerCase()}function Re(e){return H.test(e)?"right":U.test(e)?"center":V.test(e)?"left":null}function Be(e,n,r,t){const o=r.inTable;r.inTable=!0;let a=[[]],c="";function i(){if(!c)return;const e=a[a.length-1];e.push.apply(e,n(c,r)),c="";}return e.trim().split(/(`[^`]*`|\\\||\|)/).filter(Boolean).forEach((e,n,r)=>{"|"===e.trim()&&(i(),t)?0!==n&&n!==r.length-1&&a.push([]):c+=e;}),i(),r.inTable=o,a}function Le(e,n,r){r.inline=!0;const t=e[2]?e[2].replace(G,"").split("|").map(Re):[],o=e[3]?function(e,n,r){return e.trim().split("\n").map(function(e){return Be(e,n,r,!0)})}(e[3],n,r):[],a=Be(e[1],n,r,!!o.length);return r.inline=!1,o.length?{align:t,cells:o,header:a,type:"25"}:{children:a,type:"21"}}function Oe(e,n){return null==e.align[n]?{}:{textAlign:e.align[n]}}function je(e){return e.inline=1,e}function Ce(e){return je(function(n,r){return r.inline?e.exec(n):null})}function Ie(e){return je(function(n,r){return r.inline||r.simple?e.exec(n):null})}function Te(e){return function(n,r){return r.inline||r.simple?null:e.exec(n)}}function Me(e){return je(function(n){return e.exec(n)})}const we=/(javascript|vbscript|data(?!:image)):/i;function De(e){try{const n=decodeURIComponent(e).replace(/[^A-Za-z0-9/:]/g,"");if(we.test(n))return null}catch(e){return null}return e}function Fe(e){return e?e.replace(re,"$1"):e}function Pe(e,n,r){const t=r.inline||!1,o=r.simple||!1;r.inline=!0,r.simple=!0;const a=e(n,r);return r.inline=t,r.simple=o,a}function Ze(e,n,r){const t=r.inline||!1,o=r.simple||!1;r.inline=!1,r.simple=!0;const a=e(n,r);return r.inline=t,r.simple=o,a}function Ne(e,n,r){const t=r.inline||!1;r.inline=!1;const o=e(n,r);return r.inline=t,o}const Ge=(e,n,r)=>({children:Pe(n,e[2],r)});function Ue(){return {}}function Ve(){return null}function He(...e){return e.filter(Boolean).join(" ")}function Qe(e,n,r){let t=e;const o=n.split(".");for(;o.length&&(t=t[o[0]],void 0!==t);)o.shift();return t||r}function We(r="",t={}){t.overrides=t.overrides||{},t.namedCodesToUnicode=t.namedCodesToUnicode?n({},a,t.namedCodesToUnicode):a;const l=t.slugify||Ae,G=t.sanitizer||De,U=t.createElement||React__namespace.createElement,V=[s,y,h,t.enforceAtxHeadings?z:S,E,M,ke,xe],H=[...V,w,A,B,O];function Q(e,n){for(let r=0;r<e.length;r++)if(e[r].test(n))return !0;return !1}function W(e,r,...o){const a=Qe(t.overrides,e+".props",{});return U(function(e,n){const r=Qe(n,e);return r?"function"==typeof r||"object"==typeof r&&"render"in r?r:Qe(n,e+".component",e):e}(e,t.overrides),n({},r,a,{className:He(null==r?void 0:r.className,a.className)||void 0}),...o)}function re(e){e=e.replace(b,"");let n=!1;t.forceInline?n=!0:t.forceBlock||(n=!1===Z.test(e));const r=fe(se(n?e:Se(e).replace(oe,"")+"\n\n",{inline:n}));for(;$e(r[r.length-1])&&!r[r.length-1].trim();)r.pop();if(null===t.wrapper)return r;const o=t.wrapper||(n?"span":"div");let a;if(r.length>1||t.forceWrapper)a=r;else {if(1===r.length)return a=r[0],"string"==typeof a?W("span",{key:"outer"},a):a;a=null;}return U(o,{key:"outer"},a)}function ce(e,n){if(!n||!n.trim())return null;const r=n.match(u);return r?r.reduce(function(n,r){const t=r.indexOf("=");if(-1!==t){const a=function(e){return -1!==e.indexOf("-")&&null===e.match(L)&&(e=e.replace(T,function(e,n){return n.toUpperCase()})),e}(r.slice(0,t)).trim(),c=function(e){const n=e[0];return ('"'===n||"'"===n)&&e.length>=2&&e[e.length-1]===n?e.slice(1,-1):e}(r.slice(t+1).trim()),u=o[a]||a;if("ref"===u)return n;const l=n[u]=function(e,n,r,t){return "style"===n?function(e){const n=[];let r="",t=!1,o=!1,a="";if(!e)return n;for(let c=0;c<e.length;c++){const i=e[c];if('"'!==i&&"'"!==i||t||(o?i===a&&(o=!1,a=""):(o=!0,a=i)),"("===i&&r.endsWith("url")?t=!0:")"===i&&t&&(t=!1),";"!==i||o||t)r+=i;else {const e=r.trim();if(e){const r=e.indexOf(":");if(r>0){const t=e.slice(0,r).trim(),o=e.slice(r+1).trim();n.push([t,o]);}}r="";}}const c=r.trim();if(c){const e=c.indexOf(":");if(e>0){const r=c.slice(0,e).trim(),t=c.slice(e+1).trim();n.push([r,t]);}}return n}(r).reduce(function(n,[r,o]){return n[r.replace(/(-[a-z])/g,e=>e[1].toUpperCase())]=t(o,e,r),n},{}):-1!==i.indexOf(n)?t(Fe(r),e,n):(r.match(j)&&(r=Fe(r.slice(1,r.length-1))),"true"===r||"false"!==r&&r)}(e,a,c,G);"string"==typeof l&&(A.test(l)||O.test(l))&&(n[u]=re(l.trim()));}else "style"!==r&&(n[o[r]||r]=!0);return n},{}):null}const ie=[],ue={},le={0:{t:[">"],o:Te(s),i:1,u(e,n,r){const[,t,o]=e[0].replace(f,"").match(_);return {alert:t,children:n(o,r)}},l(e,n,r){const t={key:r.key};return e.alert&&(t.className="markdown-alert-"+l(e.alert.toLowerCase(),Ae),e.children.unshift({attrs:{},children:[{type:"27",text:e.alert}],noInnerParse:!0,type:"11",tag:"header"})),W("blockquote",t,n(e.children,r))}},1:{t:[" "],o:Me(d),i:1,u:Ue,l:(e,n,r)=>W("br",{key:r.key})},2:{t:["--","__","**","- ","* ","_ "],o:Te(p),i:1,u:Ue,l:(e,n,r)=>W("hr",{key:r.key})},3:{t:[" "],o:Te(h),i:0,u:e=>({lang:void 0,text:Fe(Se(e[0].replace(/^ {4}/gm,"")))}),l:(e,r,t)=>W("pre",{key:t.key},W("code",n({},e.attrs,{className:e.lang?"lang-"+e.lang:""}),e.text))},4:{t:["```","~~~"],o:Te(y),i:0,u:e=>({attrs:ce("code",e[3]||""),lang:e[2]||void 0,text:e[4],type:"3"})},5:{t:["`"],o:Ie(g),i:3,u:e=>({text:Fe(e[2])}),l:(e,n,r)=>W("code",{key:r.key},e.text)},6:{t:["[^"],o:Te(x),i:0,u:e=>(ie.push({footnote:e[2],identifier:e[1]}),{}),l:Ve},7:{t:["[^"],o:Ce(q),i:1,u:e=>({target:"#"+l(e[1],Ae),text:e[1]}),l:(e,n,r)=>W("a",{key:r.key,href:G(e.target,"a","href")},W("sup",{key:r.key},e.text))},8:{t:["[ ]","[x]"],o:Ce($),i:1,u:e=>({completed:"x"===e[1].toLowerCase()}),l:(e,n,r)=>W("input",{checked:e.completed,key:r.key,readOnly:!0,type:"checkbox"})},9:{t:["#"],o:Te(t.enforceAtxHeadings?z:S),i:1,u:(e,n,r)=>({children:Pe(n,e[2],r),id:l(e[2],Ae),level:e[1].length}),l:(e,n,r)=>W("h"+e.level,{id:e.id,key:r.key},n(e.children,r))},10:{t:e=>{const n=e.indexOf("\n");return n>0&&n<e.length-1&&("="===e[n+1]||"-"===e[n+1])},o:Te(E),i:0,u:(e,n,r)=>({children:Pe(n,e[1],r),level:"="===e[2]?1:2,type:"9"})},11:{t:["<"],o:Me(A),i:1,u(e,n,r){const[,t]=e[3].match(ae),o=RegExp("^"+t,"gm"),a=e[3].replace(o,""),i=Q(H,a)?Ne:Pe,u=e[1].toLowerCase(),l=-1!==c.indexOf(u),s=(l?u:e[1]).trim(),f={attrs:ce(s,e[2]),noInnerParse:l,tag:s};if(r.inAnchor=r.inAnchor||"a"===u,l)f.text=e[3];else {const e=r.inHTML;r.inHTML=!0,f.children=i(n,a,r),r.inHTML=e;}return r.inAnchor=!1,f},l:(e,r,t)=>W(e.tag,n({key:t.key},e.attrs),e.text||(e.children?r(e.children,t):""))},13:{t:["<"],o:Me(O),i:1,u(e){const n=e[1].trim();return {attrs:ce(n,e[2]||""),tag:n}},l:(e,r,t)=>W(e.tag,n({},e.attrs,{key:t.key}))},12:{t:["\x3c!--"],o:Me(B),i:1,u:()=>({}),l:Ve},14:{t:["!["],o:Ie(be),i:1,u:e=>({alt:Fe(e[1]),target:Fe(e[2]),title:Fe(e[3])}),l:(e,n,r)=>W("img",{key:r.key,alt:e.alt||void 0,title:e.title||void 0,src:G(e.target,"img","src")})},15:{t:["["],o:Ce(ve),i:3,u:(e,n,r)=>({children:Ze(n,e[1],r),target:Fe(e[2]),title:Fe(e[3])}),l:(e,n,r)=>W("a",{key:r.key,href:G(e.target,"a","href"),title:e.title},n(e.children,r))},16:{t:["<"],o:Ce(I),i:0,u(e){let n=e[1],r=!1;return -1!==n.indexOf("@")&&-1===n.indexOf("//")&&(r=!0,n=n.replace("mailto:","")),{children:[{text:n,type:"27"}],target:r?"mailto:"+n:n,type:"15"}}},17:{t:(e,n)=>!n.inAnchor&&!t.disableAutoLink&&(ze(e,"http://")||ze(e,"https://")),o:Ce(C),i:0,u:e=>({children:[{text:e[1],type:"27"}],target:e[1],title:void 0,type:"15"})},20:qe(W,1),33:qe(W,2),19:{t:["\n"],o:Te(m),i:3,u:Ue,l:()=>"\n"},21:{o:je(function(e,n){if(n.inline||n.simple||n.inHTML&&-1===e.indexOf("\n\n")&&-1===n.prevCapture.indexOf("\n\n"))return null;let r="",t=0;for(;;){const n=e.indexOf("\n",t),o=e.slice(t,-1===n?void 0:n+1);if(Q(V,o))break;if(r+=o,-1===n||!o.trim())break;t=n+1;}const o=Se(r);return ""===o?null:[r,,o]}),i:3,u:Ge,l:(e,n,r)=>W("p",{key:r.key},n(e.children,r))},22:{t:["["],o:Ce(D),i:0,u:e=>(ue[e[1]]={target:e[2],title:e[4]},{}),l:Ve},23:{t:["!["],o:Ie(F),i:0,u:e=>({alt:e[1]?Fe(e[1]):void 0,ref:e[2]}),l:(e,n,r)=>ue[e.ref]?W("img",{key:r.key,alt:e.alt,src:G(ue[e.ref].target,"img","src"),title:ue[e.ref].title}):null},24:{t:e=>"["===e[0]&&-1===e.indexOf("]("),o:Ce(P),i:0,u:(e,n,r)=>({children:n(e[1],r),fallbackChildren:e[0],ref:e[2]}),l:(e,n,r)=>ue[e.ref]?W("a",{key:r.key,href:G(ue[e.ref].target,"a","href"),title:ue[e.ref].title},n(e.children,r)):W("span",{key:r.key},e.fallbackChildren)},25:{t:["|"],o:Te(M),i:1,u:Le,l(e,n,r){const t=e;return W("table",{key:r.key},W("thead",null,W("tr",null,t.header.map(function(e,o){return W("th",{key:o,style:Oe(t,o)},n(e,r))}))),W("tbody",null,t.cells.map(function(e,o){return W("tr",{key:o},e.map(function(e,o){return W("td",{key:o,style:Oe(t,o)},n(e,r))}))})))}},27:{o:je(function(e,n){let r;return ze(e,":")&&(r=ee.exec(e)),r||te.exec(e)}),i:4,u(e){const n=e[0];return {text:-1===n.indexOf("&")?n:n.replace(R,(e,n)=>t.namedCodesToUnicode[n]||e)}},l:e=>e.text},28:{t:["**","__"],o:Ie(J),i:2,u:(e,n,r)=>({children:n(e[2],r)}),l:(e,n,r)=>W("strong",{key:r.key},n(e.children,r))},29:{t:e=>{const n=e[0];return ("*"===n||"_"===n)&&e[1]!==n},o:Ie(K),i:3,u:(e,n,r)=>({children:n(e[2],r)}),l:(e,n,r)=>W("em",{key:r.key},n(e.children,r))},30:{t:["\\"],o:Ie(ne),i:1,u:e=>({text:e[1],type:"27"})},31:{t:["=="],o:Ie(X),i:3,u:Ge,l:(e,n,r)=>W("mark",{key:r.key},n(e.children,r))},32:{t:["~~"],o:Ie(Y),i:3,u:Ge,l:(e,n,r)=>W("del",{key:r.key},n(e.children,r))}};!0===t.disableParsingRawHTML&&(delete le[11],delete le[13]);const se=function(e){var n=Object.keys(e);function r(t,o){var a=[];if(o.prevCapture=o.prevCapture||"",t.trim())for(;t;)for(var c=0;c<n.length;){var i=n[c],u=e[i];if(!u.t||Ee(t,o,u.t)){var l=u.o(t,o);if(l&&l[0]){t=t.substring(l[0].length);var s=u.u(l,r,o);o.prevCapture+=l[0],s.type||(s.type=i),a.push(s);break}c++;}else c++;}return o.prevCapture="",a}return n.sort(function(n,r){return e[n].i-e[r].i||(n<r?-1:1)}),function(e,n){return r(function(e){return e.replace(k,"\n").replace(v,"").replace(N," ")}(e),n)}}(le),fe=function(e,n){return function r(t,o={}){if(Array.isArray(t)){const e=o.key,n=[];let a=!1;for(let e=0;e<t.length;e++){o.key=e;const c=r(t[e],o),i=$e(c);i&&a?n[n.length-1]+=c:null!==c&&n.push(c),a=i;}return o.key=e,n}return function(r,t,o){const a=e[r.type].l;return n?n(()=>a(r,t,o),r,t,o):a(r,t,o)}(t,r,o)}}(le,t.renderRule),_e=re(r);return ie.length?W("div",null,_e,W("footer",{key:"footer"},ie.map(function(e){return W("div",{id:l(e.identifier,Ae),key:e.identifier},e.identifier,fe(se(e.footnote,{inline:!0})))}))):_e}
|
|
20586
21352
|
|
|
21353
|
+
function createChatMessageReasoningComponent(param) {
|
|
21354
|
+
var createElement = param.createElement;
|
|
21355
|
+
return function ChatMessageReasoning(userProps) {
|
|
21356
|
+
var part = userProps.part, isStreaming = userProps.isStreaming, _userProps_parseMarkdown = userProps.parseMarkdown, parseMarkdown = _userProps_parseMarkdown === void 0 ? true : _userProps_parseMarkdown, translations = userProps.translations, classNames = userProps.classNames;
|
|
21357
|
+
var body = parseMarkdown ? We(part.text, {
|
|
21358
|
+
createElement: createElement,
|
|
21359
|
+
disableParsingRawHTML: true
|
|
21360
|
+
}) : // newlines markdown would collapse.
|
|
21361
|
+
/*#__PURE__*/ createElement("p", {
|
|
21362
|
+
className: "ais-ChatMessage-text"
|
|
21363
|
+
}, part.text);
|
|
21364
|
+
return /*#__PURE__*/ createElement("details", {
|
|
21365
|
+
className: cx(classNames.reasoning),
|
|
21366
|
+
"aria-label": translations.reasoningLabel,
|
|
21367
|
+
"aria-busy": isStreaming
|
|
21368
|
+
}, /*#__PURE__*/ createElement("summary", {
|
|
21369
|
+
className: cx(classNames.reasoningHeader)
|
|
21370
|
+
}, /*#__PURE__*/ createElement("span", {
|
|
21371
|
+
className: cx(classNames.reasoningIcon),
|
|
21372
|
+
"aria-hidden": "true"
|
|
21373
|
+
}, /*#__PURE__*/ createElement(BrainIcon, {
|
|
21374
|
+
createElement: createElement
|
|
21375
|
+
})), /*#__PURE__*/ createElement("span", {
|
|
21376
|
+
className: cx(classNames.reasoningLabel)
|
|
21377
|
+
}, translations.reasoningLabel), /*#__PURE__*/ createElement("span", {
|
|
21378
|
+
className: cx(classNames.reasoningChevron),
|
|
21379
|
+
"aria-hidden": "true"
|
|
21380
|
+
}, /*#__PURE__*/ createElement(ChevronDownIcon, {
|
|
21381
|
+
createElement: createElement
|
|
21382
|
+
}))), /*#__PURE__*/ createElement("div", {
|
|
21383
|
+
className: cx(classNames.reasoningBody),
|
|
21384
|
+
tabIndex: 0
|
|
21385
|
+
}, /*#__PURE__*/ createElement("div", {
|
|
21386
|
+
className: cx(classNames.reasoningText)
|
|
21387
|
+
}, body)));
|
|
21388
|
+
};
|
|
21389
|
+
}
|
|
21390
|
+
|
|
20587
21391
|
// Keep in sync with packages/instantsearch.js/src/lib/chat/index.ts
|
|
20588
21392
|
var SearchIndexToolType = 'algolia_search_index';
|
|
20589
21393
|
function createChatMessageComponent(param) {
|
|
@@ -20591,8 +21395,12 @@
|
|
|
20591
21395
|
var Button = createButtonComponent({
|
|
20592
21396
|
createElement: createElement
|
|
20593
21397
|
});
|
|
21398
|
+
var ChatMessageReasoning = createChatMessageReasoningComponent({
|
|
21399
|
+
createElement: createElement
|
|
21400
|
+
});
|
|
20594
21401
|
return function ChatMessage(userProps) {
|
|
20595
|
-
var
|
|
21402
|
+
var _messages_;
|
|
21403
|
+
var _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, message = userProps.message, status = userProps.status, _userProps_side = userProps.side, side = _userProps_side === void 0 ? 'left' : _userProps_side, _userProps_variant = userProps.variant, variant = _userProps_variant === void 0 ? 'subtle' : _userProps_variant, _userProps_actions = userProps.actions, actions = _userProps_actions === void 0 ? [] : _userProps_actions, _userProps_autoHideActions = userProps.autoHideActions, autoHideActions = _userProps_autoHideActions === void 0 ? false : _userProps_autoHideActions, LeadingComponent = userProps.leadingComponent, ActionsComponent = userProps.actionsComponent, FooterComponent = userProps.footerComponent, _userProps_tools = userProps.tools, tools = _userProps_tools === void 0 ? {} : _userProps_tools, indexUiState = userProps.indexUiState, setIndexUiState = userProps.setIndexUiState, messages = userProps.messages, onClose = userProps.onClose, userTranslations = userProps.translations, suggestionsElement = userProps.suggestionsElement, _userProps_showReasoning = userProps.showReasoning, showReasoning = _userProps_showReasoning === void 0 ? false : _userProps_showReasoning, _userProps_parseMarkdown = userProps.parseMarkdown, parseMarkdown = _userProps_parseMarkdown === void 0 ? true : _userProps_parseMarkdown, props = _object_without_properties(userProps, [
|
|
20596
21404
|
"classNames",
|
|
20597
21405
|
"message",
|
|
20598
21406
|
"status",
|
|
@@ -20610,13 +21418,16 @@
|
|
|
20610
21418
|
"onClose",
|
|
20611
21419
|
"translations",
|
|
20612
21420
|
"suggestionsElement",
|
|
21421
|
+
"showReasoning",
|
|
20613
21422
|
"parseMarkdown"
|
|
20614
21423
|
]);
|
|
20615
21424
|
var translations = _object_spread({
|
|
20616
21425
|
messageLabel: 'Message',
|
|
20617
|
-
actionsLabel: 'Message actions'
|
|
21426
|
+
actionsLabel: 'Message actions',
|
|
21427
|
+
reasoningLabel: 'Reasoning'
|
|
20618
21428
|
}, userTranslations);
|
|
20619
21429
|
var hasLeading = Boolean(LeadingComponent);
|
|
21430
|
+
var isCurrentMessage = messages === undefined || ((_messages_ = messages[messages.length - 1]) === null || _messages_ === void 0 ? void 0 : _messages_.id) === message.id;
|
|
20620
21431
|
var showActions = Boolean(actions.length > 0 || ActionsComponent) && status === 'ready';
|
|
20621
21432
|
var cssClasses = {
|
|
20622
21433
|
root: cx('ais-ChatMessage', "ais-ChatMessage--".concat(side), "ais-ChatMessage--".concat(variant), autoHideActions && 'ais-ChatMessage--auto-hide-actions', classNames.root),
|
|
@@ -20625,12 +21436,38 @@
|
|
|
20625
21436
|
content: cx('ais-ChatMessage-content', classNames.content),
|
|
20626
21437
|
message: cx('ais-ChatMessage-message', classNames.message),
|
|
20627
21438
|
actions: cx('ais-ChatMessage-actions', classNames.actions),
|
|
20628
|
-
footer: cx('ais-ChatMessage-footer', classNames.footer)
|
|
21439
|
+
footer: cx('ais-ChatMessage-footer', classNames.footer),
|
|
21440
|
+
reasoning: cx('ais-ChatMessageReasoning', classNames.reasoning),
|
|
21441
|
+
reasoningHeader: cx('ais-ChatMessageReasoning-header', classNames.reasoningHeader),
|
|
21442
|
+
reasoningIcon: cx('ais-ChatMessageReasoning-icon', classNames.reasoningIcon),
|
|
21443
|
+
reasoningLabel: cx('ais-ChatMessageReasoning-label', classNames.reasoningLabel),
|
|
21444
|
+
reasoningChevron: cx('ais-ChatMessageReasoning-chevron', classNames.reasoningChevron),
|
|
21445
|
+
reasoningBody: cx('ais-ChatMessageReasoning-body', classNames.reasoningBody),
|
|
21446
|
+
reasoningText: cx('ais-ChatMessageReasoning-text', classNames.reasoningText)
|
|
20629
21447
|
};
|
|
20630
21448
|
function renderMessagePart(part, index) {
|
|
20631
21449
|
if (part.type === 'step-start') {
|
|
20632
21450
|
return null;
|
|
20633
21451
|
}
|
|
21452
|
+
if (part.type === 'reasoning') {
|
|
21453
|
+
if (!showReasoning) {
|
|
21454
|
+
return null;
|
|
21455
|
+
}
|
|
21456
|
+
var isReasoningStreaming = status === 'streaming' && isCurrentMessage && isReasoningPartActive(message.parts, index);
|
|
21457
|
+
if (!isReasoningStreaming && part.text.trim().length === 0) {
|
|
21458
|
+
return null;
|
|
21459
|
+
}
|
|
21460
|
+
return /*#__PURE__*/ createElement(ChatMessageReasoning, {
|
|
21461
|
+
key: "".concat(message.id, "-").concat(index),
|
|
21462
|
+
part: part,
|
|
21463
|
+
isStreaming: isReasoningStreaming,
|
|
21464
|
+
parseMarkdown: parseMarkdown,
|
|
21465
|
+
translations: translations,
|
|
21466
|
+
classNames: _object_spread_props(_object_spread({}, cssClasses), {
|
|
21467
|
+
reasoningLabel: cx('ais-ChatMessageReasoning-label', isReasoningStreaming && 'ais-ChatMessageReasoning-label--streaming', classNames.reasoningLabel)
|
|
21468
|
+
})
|
|
21469
|
+
});
|
|
21470
|
+
}
|
|
20634
21471
|
if (part.type === 'text') {
|
|
20635
21472
|
// Back-compat shim for sessions started before the move from a
|
|
20636
21473
|
// `<context>{...}</context>` text part to `metadata.turnContext`.
|
|
@@ -20672,6 +21509,7 @@
|
|
|
20672
21509
|
return null;
|
|
20673
21510
|
}
|
|
20674
21511
|
if (tool) {
|
|
21512
|
+
var _tool_insightsEventContext;
|
|
20675
21513
|
var ToolLayoutComponent = tool.layoutComponent;
|
|
20676
21514
|
var toolMessage = part;
|
|
20677
21515
|
var boundAddToolResult = function boundAddToolResult(params) {
|
|
@@ -20691,17 +21529,33 @@
|
|
|
20691
21529
|
if (!ToolLayoutComponent) {
|
|
20692
21530
|
return null;
|
|
20693
21531
|
}
|
|
21532
|
+
var toolSendEvent = tool.sendEvent || function() {};
|
|
21533
|
+
var agentId = (_tool_insightsEventContext = tool.insightsEventContext) === null || _tool_insightsEventContext === void 0 ? void 0 : _tool_insightsEventContext.agentId;
|
|
21534
|
+
var sendEvent = function sendEvent(eventType, hits, eventName, additionalData) {
|
|
21535
|
+
if (hits === undefined && eventName === undefined && additionalData === undefined) {
|
|
21536
|
+
return toolSendEvent(eventType);
|
|
21537
|
+
}
|
|
21538
|
+
return toolSendEvent(eventType, hits, eventName, _object_spread_props(_object_spread(_object_spread_props(_object_spread({}, additionalData || {}), {
|
|
21539
|
+
queryID: 'message_' + message.id
|
|
21540
|
+
}), agentId ? {
|
|
21541
|
+
agentId: agentId
|
|
21542
|
+
} : {}), {
|
|
21543
|
+
toolCallId: toolMessage.toolCallId
|
|
21544
|
+
}));
|
|
21545
|
+
};
|
|
20694
21546
|
return /*#__PURE__*/ createElement("div", {
|
|
20695
21547
|
key: "".concat(message.id, "-").concat(index),
|
|
20696
21548
|
className: "ais-ChatMessage-tool"
|
|
20697
21549
|
}, /*#__PURE__*/ createElement(ToolLayoutComponent, {
|
|
20698
21550
|
message: toolMessage,
|
|
21551
|
+
insightsEventContext: tool.insightsEventContext,
|
|
21552
|
+
status: status,
|
|
20699
21553
|
indexUiState: indexUiState,
|
|
20700
21554
|
setIndexUiState: setIndexUiState,
|
|
20701
21555
|
messages: messages,
|
|
20702
21556
|
addToolResult: boundAddToolResult,
|
|
20703
21557
|
applyFilters: tool.applyFilters,
|
|
20704
|
-
sendEvent:
|
|
21558
|
+
sendEvent: sendEvent,
|
|
20705
21559
|
onClose: onClose
|
|
20706
21560
|
}));
|
|
20707
21561
|
}
|
|
@@ -20853,6 +21707,17 @@
|
|
|
20853
21707
|
var copyToClipboard = function copyToClipboard(message) {
|
|
20854
21708
|
navigator.clipboard.writeText(getTextContent(message));
|
|
20855
21709
|
};
|
|
21710
|
+
function getInstantSearchStatus(tools) {
|
|
21711
|
+
var _Object_values_find_insightsEventContext, _Object_values_find;
|
|
21712
|
+
return (_Object_values_find = Object.values(tools).find(function(tool) {
|
|
21713
|
+
return tool.insightsEventContext;
|
|
21714
|
+
})) === null || _Object_values_find === void 0 ? void 0 : (_Object_values_find_insightsEventContext = _Object_values_find.insightsEventContext) === null || _Object_values_find_insightsEventContext === void 0 ? void 0 : _Object_values_find_insightsEventContext.instantSearchStatus;
|
|
21715
|
+
}
|
|
21716
|
+
// Own-key presence is what a JSX spread copies; `in` would also answer for
|
|
21717
|
+
// inherited keys the spread leaves behind.
|
|
21718
|
+
var hasOwnKey = function hasOwnKey(target, key) {
|
|
21719
|
+
return target !== undefined && Object.prototype.hasOwnProperty.call(target, key);
|
|
21720
|
+
};
|
|
20856
21721
|
function createDefaultMessageComponent(param) {
|
|
20857
21722
|
var createElement = param.createElement, Fragment = param.Fragment;
|
|
20858
21723
|
var ChatMessage = createChatMessageComponent({
|
|
@@ -20977,13 +21842,46 @@
|
|
|
20977
21842
|
function MemoizedDefaultMessage(props) {
|
|
20978
21843
|
var _props_feedbackState;
|
|
20979
21844
|
var messageFeedback = (_props_feedbackState = props.feedbackState) === null || _props_feedbackState === void 0 ? void 0 : _props_feedbackState[props.message.id];
|
|
21845
|
+
var instantSearchStatus = getInstantSearchStatus(props.tools);
|
|
21846
|
+
// Read the row's own side, mirroring `DefaultMessage`, so one role's change
|
|
21847
|
+
// neither invalidates the other's completed rows nor goes unnoticed here.
|
|
21848
|
+
var messageProps = props.message.role === 'user' ? props.userMessageProps : props.assistantMessageProps;
|
|
21849
|
+
var showReasoning = messageProps === null || messageProps === void 0 ? void 0 : messageProps.showReasoning;
|
|
21850
|
+
var parseMarkdown = messageProps === null || messageProps === void 0 ? void 0 : messageProps.parseMarkdown;
|
|
21851
|
+
// Object-level fallback, matching the render: the spread replaces
|
|
21852
|
+
// `translations` wholesale, and it copies a key holding `undefined` too. Both
|
|
21853
|
+
// are why this resolves by own-key presence rather than key by key.
|
|
21854
|
+
var reasoningTranslations = hasOwnKey(messageProps, 'translations') ? messageProps === null || messageProps === void 0 ? void 0 : messageProps.translations : props.messageTranslations;
|
|
21855
|
+
var reasoningLabel = reasoningTranslations === null || reasoningTranslations === void 0 ? void 0 : reasoningTranslations.reasoningLabel;
|
|
21856
|
+
var reasoningClassNames = hasOwnKey(messageProps, 'classNames') ? messageProps === null || messageProps === void 0 ? void 0 : messageProps.classNames : props.classNames;
|
|
21857
|
+
var reasoningClassName = cx(reasoningClassNames === null || reasoningClassNames === void 0 ? void 0 : reasoningClassNames.reasoning);
|
|
21858
|
+
var reasoningHeaderClassName = cx(reasoningClassNames === null || reasoningClassNames === void 0 ? void 0 : reasoningClassNames.reasoningHeader);
|
|
21859
|
+
var reasoningIconClassName = cx(reasoningClassNames === null || reasoningClassNames === void 0 ? void 0 : reasoningClassNames.reasoningIcon);
|
|
21860
|
+
var reasoningLabelClassName = cx(reasoningClassNames === null || reasoningClassNames === void 0 ? void 0 : reasoningClassNames.reasoningLabel);
|
|
21861
|
+
var reasoningChevronClassName = cx(reasoningClassNames === null || reasoningClassNames === void 0 ? void 0 : reasoningClassNames.reasoningChevron);
|
|
21862
|
+
var reasoningBodyClassName = cx(reasoningClassNames === null || reasoningClassNames === void 0 ? void 0 : reasoningClassNames.reasoningBody);
|
|
21863
|
+
var reasoningTextClassName = cx(reasoningClassNames === null || reasoningClassNames === void 0 ? void 0 : reasoningClassNames.reasoningText);
|
|
21864
|
+
// The row comparator. The full props object would recompile every completed
|
|
21865
|
+
// message on each streaming update.
|
|
20980
21866
|
return useMemo(function() {
|
|
20981
21867
|
return /*#__PURE__*/ createElement(DefaultMessageComponent, props);
|
|
20982
21868
|
}, [
|
|
20983
21869
|
props.message,
|
|
21870
|
+
props.isCurrentMessage,
|
|
20984
21871
|
props.status,
|
|
21872
|
+
instantSearchStatus,
|
|
20985
21873
|
props.suggestionsElement,
|
|
20986
|
-
messageFeedback
|
|
21874
|
+
messageFeedback,
|
|
21875
|
+
showReasoning,
|
|
21876
|
+
parseMarkdown,
|
|
21877
|
+
reasoningLabel,
|
|
21878
|
+
reasoningClassName,
|
|
21879
|
+
reasoningHeaderClassName,
|
|
21880
|
+
reasoningIconClassName,
|
|
21881
|
+
reasoningLabelClassName,
|
|
21882
|
+
reasoningChevronClassName,
|
|
21883
|
+
reasoningBodyClassName,
|
|
21884
|
+
reasoningTextClassName
|
|
20987
21885
|
]);
|
|
20988
21886
|
}
|
|
20989
21887
|
var DefaultLoaderComponent = createChatMessageLoaderComponent({
|
|
@@ -20993,7 +21891,8 @@
|
|
|
20993
21891
|
createElement: createElement
|
|
20994
21892
|
});
|
|
20995
21893
|
return function ChatMessages(userProps) {
|
|
20996
|
-
var
|
|
21894
|
+
var _ref;
|
|
21895
|
+
var _lastMessage_parts, _lastMessage_parts1;
|
|
20997
21896
|
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, [
|
|
20998
21897
|
"classNames",
|
|
20999
21898
|
"messageClassNames",
|
|
@@ -21046,7 +21945,12 @@
|
|
|
21046
21945
|
};
|
|
21047
21946
|
var lastMessage = messages[messages.length - 1];
|
|
21048
21947
|
var lastPart = lastMessage === null || lastMessage === void 0 ? void 0 : (_lastMessage_parts = lastMessage.parts) === null || _lastMessage_parts === void 0 ? void 0 : _lastMessage_parts[lastMessage.parts.length - 1];
|
|
21049
|
-
|
|
21948
|
+
// The scan slices the remaining parts per candidate, and only the loader reads
|
|
21949
|
+
// it, so skip it entirely while the opt-in is off.
|
|
21950
|
+
var hasActiveReasoning = (assistantMessageProps === null || assistantMessageProps === void 0 ? void 0 : assistantMessageProps.showReasoning) ? (_ref = lastMessage === null || lastMessage === void 0 ? void 0 : (_lastMessage_parts1 = lastMessage.parts) === null || _lastMessage_parts1 === void 0 ? void 0 : _lastMessage_parts1.some(function(_, index, parts) {
|
|
21951
|
+
return isReasoningPartActive(parts, index);
|
|
21952
|
+
})) !== null && _ref !== void 0 ? _ref : false : false;
|
|
21953
|
+
var showLoader = getShowLoader(status, lastPart, tools, assistantMessageProps === null || assistantMessageProps === void 0 ? void 0 : assistantMessageProps.showReasoning, hasActiveReasoning);
|
|
21050
21954
|
var showEmpty = messages.length === 0 && !showLoader && !isClearing && status !== 'error';
|
|
21051
21955
|
var DefaultMessage = MessageComponent || MemoizedDefaultMessage;
|
|
21052
21956
|
var DefaultLoader = LoaderComponent || DefaultLoaderComponent;
|
|
@@ -21075,6 +21979,7 @@
|
|
|
21075
21979
|
return /*#__PURE__*/ createElement(DefaultMessage, {
|
|
21076
21980
|
key: message.id,
|
|
21077
21981
|
message: message,
|
|
21982
|
+
isCurrentMessage: index === messages.length - 1,
|
|
21078
21983
|
status: status,
|
|
21079
21984
|
userMessageProps: userMessageProps,
|
|
21080
21985
|
assistantMessageProps: assistantMessageProps,
|
|
@@ -21122,10 +22027,13 @@
|
|
|
21122
22027
|
})));
|
|
21123
22028
|
};
|
|
21124
22029
|
}
|
|
21125
|
-
var getShowLoader = function getShowLoader(status, lastPart, tools) {
|
|
22030
|
+
var getShowLoader = function getShowLoader(status, lastPart, tools, showReasoning, hasActiveReasoning) {
|
|
21126
22031
|
if (status !== 'submitted' && status !== 'streaming') return false;
|
|
21127
22032
|
if (status === 'submitted') return true;
|
|
21128
22033
|
if (!lastPart) return true;
|
|
22034
|
+
// An active disclosure carries its own progress affordance, so the loader would
|
|
22035
|
+
// double it. Settled reasoning still shows it: the answer has not started.
|
|
22036
|
+
if (showReasoning && hasActiveReasoning) return false;
|
|
21129
22037
|
if (isPartText(lastPart)) return false;
|
|
21130
22038
|
if (isPartTool(lastPart) && lastPart.state === 'input-streaming') {
|
|
21131
22039
|
var tool = findTool(lastPart.type, tools);
|
|
@@ -21618,6 +22526,73 @@
|
|
|
21618
22526
|
};
|
|
21619
22527
|
}
|
|
21620
22528
|
|
|
22529
|
+
function createPromptSuggestionsComponent(param) {
|
|
22530
|
+
var createElement = param.createElement;
|
|
22531
|
+
var Button = createButtonComponent({
|
|
22532
|
+
createElement: createElement
|
|
22533
|
+
});
|
|
22534
|
+
function DefaultHeader(param) {
|
|
22535
|
+
var classNames = param.classNames, translations = param.translations;
|
|
22536
|
+
return /*#__PURE__*/ createElement("div", {
|
|
22537
|
+
className: cx('ais-PromptSuggestions-header', classNames.header)
|
|
22538
|
+
}, /*#__PURE__*/ createElement("span", {
|
|
22539
|
+
className: cx('ais-PromptSuggestions-headerTitle', classNames.headerTitle)
|
|
22540
|
+
}, translations.headerTitle));
|
|
22541
|
+
}
|
|
22542
|
+
return function PromptSuggestions(userProps) {
|
|
22543
|
+
var _userProps_suggestions = userProps.suggestions, suggestions = _userProps_suggestions === void 0 ? [] : _userProps_suggestions, onSuggestionClick = userProps.onSuggestionClick, _userProps_isLoading = userProps.isLoading, isLoading = _userProps_isLoading === void 0 ? false : _userProps_isLoading, _userProps_skeletonCount = userProps.skeletonCount, skeletonCount = _userProps_skeletonCount === void 0 ? 3 : _userProps_skeletonCount, _userProps_disabled = userProps.disabled, disabled = _userProps_disabled === void 0 ? false : _userProps_disabled, headerComponent = userProps.headerComponent, userTranslations = userProps.translations, _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, props = _object_without_properties(userProps, [
|
|
22544
|
+
"suggestions",
|
|
22545
|
+
"onSuggestionClick",
|
|
22546
|
+
"isLoading",
|
|
22547
|
+
"skeletonCount",
|
|
22548
|
+
"disabled",
|
|
22549
|
+
"headerComponent",
|
|
22550
|
+
"translations",
|
|
22551
|
+
"classNames"
|
|
22552
|
+
]);
|
|
22553
|
+
var translations = _object_spread({
|
|
22554
|
+
headerTitle: 'Suggestions'
|
|
22555
|
+
}, userTranslations);
|
|
22556
|
+
var HeaderComponent = headerComponent === false ? null : headerComponent !== null && headerComponent !== void 0 ? headerComponent : DefaultHeader;
|
|
22557
|
+
var visibleSuggestions = suggestions.filter(function(suggestion) {
|
|
22558
|
+
return suggestion.trim() !== '';
|
|
22559
|
+
});
|
|
22560
|
+
var hasContent = visibleSuggestions.length > 0 || isLoading;
|
|
22561
|
+
return /*#__PURE__*/ createElement("div", _object_spread_props(_object_spread({}, props), {
|
|
22562
|
+
className: cx('ais-PromptSuggestions', classNames.root, props.className)
|
|
22563
|
+
}), HeaderComponent && hasContent && /*#__PURE__*/ createElement(HeaderComponent, {
|
|
22564
|
+
classNames: {
|
|
22565
|
+
header: classNames.header,
|
|
22566
|
+
headerTitle: classNames.headerTitle
|
|
22567
|
+
},
|
|
22568
|
+
translations: translations
|
|
22569
|
+
}), isLoading && visibleSuggestions.length === 0 ? /*#__PURE__*/ createElement("div", {
|
|
22570
|
+
className: cx('ais-PromptSuggestions-skeleton', classNames.skeleton)
|
|
22571
|
+
}, _to_consumable_array(new Array(skeletonCount)).map(function(_, i) {
|
|
22572
|
+
return /*#__PURE__*/ createElement("div", {
|
|
22573
|
+
key: i,
|
|
22574
|
+
className: cx('ais-PromptSuggestions-skeletonItem', classNames.skeletonItem)
|
|
22575
|
+
});
|
|
22576
|
+
})) : visibleSuggestions.map(function(suggestion, index) {
|
|
22577
|
+
return /*#__PURE__*/ createElement(Button, {
|
|
22578
|
+
key: index,
|
|
22579
|
+
size: "sm",
|
|
22580
|
+
variant: "primary",
|
|
22581
|
+
className: cx('ais-PromptSuggestions-suggestion', classNames.suggestion),
|
|
22582
|
+
// Ignore clicks while streaming so an unfinished prompt (e.g.
|
|
22583
|
+
// `Wh..`) can't be sent before generation settles — without
|
|
22584
|
+
// toggling `disabled`, which would swap the pill's styling
|
|
22585
|
+
// mid-stream.
|
|
22586
|
+
onClick: function onClick() {
|
|
22587
|
+
if (isLoading) return;
|
|
22588
|
+
onSuggestionClick(suggestion);
|
|
22589
|
+
},
|
|
22590
|
+
disabled: disabled
|
|
22591
|
+
}, suggestion);
|
|
22592
|
+
}));
|
|
22593
|
+
};
|
|
22594
|
+
}
|
|
22595
|
+
|
|
21621
22596
|
function createChatToggleButtonComponent(param) {
|
|
21622
22597
|
var createElement = param.createElement;
|
|
21623
22598
|
var Button = createButtonComponent({
|
|
@@ -21687,10 +22662,7 @@
|
|
|
21687
22662
|
size: "sm",
|
|
21688
22663
|
onClick: function onClick() {
|
|
21689
22664
|
if (!input || !applyFilters) return;
|
|
21690
|
-
var params = applyFilters(
|
|
21691
|
-
query: input.query,
|
|
21692
|
-
facetFilters: getFacetFiltersFromToolInput(input)
|
|
21693
|
-
});
|
|
22665
|
+
var params = applyFilters(getApplyFiltersParamsFromToolInput(input));
|
|
21694
22666
|
if (getSearchPageURL) {
|
|
21695
22667
|
var searchPageURL = getSearchPageURL(params);
|
|
21696
22668
|
var resolvedURL = new URL(searchPageURL, window.location.href);
|
|
@@ -21727,22 +22699,46 @@
|
|
|
21727
22699
|
};
|
|
21728
22700
|
}
|
|
21729
22701
|
function createCarouselToolComponent(param) {
|
|
21730
|
-
var createElement = param.createElement, Fragment = param.Fragment, useMemo = param.useMemo, useRef = param.useRef, useState = param.useState;
|
|
22702
|
+
var createElement = param.createElement, Fragment = param.Fragment, useEffect = param.useEffect, useMemo = param.useMemo, useRef = param.useRef, useState = param.useState;
|
|
21731
22703
|
var DefaultHeader = createHeaderComponent({
|
|
21732
22704
|
createElement: createElement,
|
|
21733
22705
|
Fragment: Fragment
|
|
21734
22706
|
});
|
|
21735
22707
|
var Carousel = createCarouselComponent({
|
|
21736
22708
|
createElement: createElement,
|
|
21737
|
-
Fragment: Fragment
|
|
22709
|
+
Fragment: Fragment,
|
|
22710
|
+
useEffect: useEffect,
|
|
22711
|
+
useRef: useRef
|
|
21738
22712
|
});
|
|
21739
22713
|
return function CarouselTool(userProps) {
|
|
21740
|
-
var
|
|
22714
|
+
var _ref;
|
|
22715
|
+
var ItemComponent = userProps.itemComponent, HeaderComponent = userProps.headerComponent, getSearchPageURL = userProps.getSearchPageURL, _userProps_toolProps = userProps.toolProps, message = _userProps_toolProps.message, applyFilters = _userProps_toolProps.applyFilters, onClose = _userProps_toolProps.onClose, insightsEventContext = _userProps_toolProps.insightsEventContext, sendEvent = _userProps_toolProps.sendEvent, showViewAll = userProps.headerProps.showViewAll;
|
|
22716
|
+
var instantSearchStatus = (_ref = insightsEventContext === null || insightsEventContext === void 0 ? void 0 : insightsEventContext.instantSearchStatus) !== null && _ref !== void 0 ? _ref : 'idle';
|
|
21741
22717
|
var input = message === null || message === void 0 ? void 0 : message.input;
|
|
21742
22718
|
var output = message === null || message === void 0 ? void 0 : message.output;
|
|
21743
22719
|
var hits = (output === null || output === void 0 ? void 0 : output.hits) || [];
|
|
21744
22720
|
var items = addQueryID(addAbsolutePosition(hits, 0, hits.length), output === null || output === void 0 ? void 0 : output.queryID);
|
|
21745
|
-
var
|
|
22721
|
+
var viewedItemsSignature = items.map(function(item) {
|
|
22722
|
+
return "".concat(item.objectID, ":").concat(item.__position);
|
|
22723
|
+
}).join('|');
|
|
22724
|
+
var lastViewedItemsSignatureRef = useRef(undefined);
|
|
22725
|
+
useEffect(function() {
|
|
22726
|
+
if (instantSearchStatus !== 'idle' || items.length === 0 || viewedItemsSignature === lastViewedItemsSignatureRef.current) {
|
|
22727
|
+
return;
|
|
22728
|
+
}
|
|
22729
|
+
var timer = setTimeout(function() {
|
|
22730
|
+
lastViewedItemsSignatureRef.current = viewedItemsSignature;
|
|
22731
|
+
sendEvent('view:internal', items, 'items_shown');
|
|
22732
|
+
}, 0);
|
|
22733
|
+
return function() {
|
|
22734
|
+
clearTimeout(timer);
|
|
22735
|
+
};
|
|
22736
|
+
}, [
|
|
22737
|
+
instantSearchStatus,
|
|
22738
|
+
items,
|
|
22739
|
+
sendEvent,
|
|
22740
|
+
viewedItemsSignature
|
|
22741
|
+
]);
|
|
21746
22742
|
var _useState = _sliced_to_array(useState(false), 2), canScrollLeft = _useState[0], setCanScrollLeft = _useState[1];
|
|
21747
22743
|
var _useState1 = _sliced_to_array(useState(true), 2), canScrollRight = _useState1[0], setCanScrollRight = _useState1[1];
|
|
21748
22744
|
var carouselIdRef = useRef('');
|
|
@@ -21766,7 +22762,6 @@
|
|
|
21766
22762
|
showViewAll: showViewAll,
|
|
21767
22763
|
nbHits: output === null || output === void 0 ? void 0 : output.nbHits,
|
|
21768
22764
|
input: input,
|
|
21769
|
-
nbItems: nbItems,
|
|
21770
22765
|
applyFilters: applyFilters,
|
|
21771
22766
|
getSearchPageURL: getSearchPageURL,
|
|
21772
22767
|
onClose: onClose
|
|
@@ -21778,7 +22773,6 @@
|
|
|
21778
22773
|
showViewAll: showViewAll,
|
|
21779
22774
|
nbHits: output === null || output === void 0 ? void 0 : output.nbHits,
|
|
21780
22775
|
input: input,
|
|
21781
|
-
nbItems: nbItems,
|
|
21782
22776
|
applyFilters: applyFilters,
|
|
21783
22777
|
getSearchPageURL: getSearchPageURL,
|
|
21784
22778
|
onClose: onClose
|
|
@@ -21789,7 +22783,6 @@
|
|
|
21789
22783
|
HeaderComponent,
|
|
21790
22784
|
output === null || output === void 0 ? void 0 : output.nbHits,
|
|
21791
22785
|
input,
|
|
21792
|
-
nbItems,
|
|
21793
22786
|
applyFilters,
|
|
21794
22787
|
getSearchPageURL,
|
|
21795
22788
|
onClose
|
|
@@ -21804,55 +22797,187 @@
|
|
|
21804
22797
|
};
|
|
21805
22798
|
}
|
|
21806
22799
|
|
|
22800
|
+
var isObject = function isObject(value) {
|
|
22801
|
+
return value !== null && (typeof value === "undefined" ? "undefined" : _type_of(value)) === 'object';
|
|
22802
|
+
};
|
|
22803
|
+
var hasOwn = function hasOwn(value, key) {
|
|
22804
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
22805
|
+
};
|
|
22806
|
+
var claimsDisplayResultsPayload = function claimsDisplayResultsPayload(value) {
|
|
22807
|
+
return isObject(value) && (hasOwn(value, 'intro') || hasOwn(value, 'groups'));
|
|
22808
|
+
};
|
|
22809
|
+
/**
|
|
22810
|
+
* Decodes a raw property-key body with JSON string semantics, so an escaped
|
|
22811
|
+
* spelling of `objectID` compares equal to the name `JSON.parse` produces.
|
|
22812
|
+
* An undecodable key is kept verbatim: it matches no name below, and the
|
|
22813
|
+
* document holding it cannot parse either.
|
|
22814
|
+
*/ var decodeJsonKey = function decodeJsonKey(rawKey) {
|
|
22815
|
+
if (rawKey.indexOf('\\') === -1) {
|
|
22816
|
+
return rawKey;
|
|
22817
|
+
}
|
|
22818
|
+
try {
|
|
22819
|
+
return JSON.parse('"'.concat(rawKey, '"'));
|
|
22820
|
+
} catch (unused) {
|
|
22821
|
+
return rawKey;
|
|
22822
|
+
}
|
|
22823
|
+
};
|
|
22824
|
+
/**
|
|
22825
|
+
* Reports whether the raw input ends inside an unterminated
|
|
22826
|
+
* `groups[].results[].objectID` value.
|
|
22827
|
+
*
|
|
22828
|
+
* Partial input is parsed with repair that closes an open string literal, so an
|
|
22829
|
+
* identifier still mid-delta reaches `input` looking complete and can hydrate a
|
|
22830
|
+
* different record whose identifier is a prefix of the real one.
|
|
22831
|
+
*/ var endsInsideResultObjectId = function endsInsideResultObjectId(rawInput) {
|
|
22832
|
+
var _frames_, _frames_1, _frames_2;
|
|
22833
|
+
var frames = [];
|
|
22834
|
+
var inString = false;
|
|
22835
|
+
var isEscaped = false;
|
|
22836
|
+
var isKey = false;
|
|
22837
|
+
var expectValue = false;
|
|
22838
|
+
var stringStart = 0;
|
|
22839
|
+
for(var index = 0; index < rawInput.length; index++){
|
|
22840
|
+
var char = rawInput[index];
|
|
22841
|
+
if (inString) {
|
|
22842
|
+
if (isEscaped) {
|
|
22843
|
+
isEscaped = false;
|
|
22844
|
+
} else if (char === '\\') {
|
|
22845
|
+
isEscaped = true;
|
|
22846
|
+
} else if (char === '"') {
|
|
22847
|
+
inString = false;
|
|
22848
|
+
if (isKey) {
|
|
22849
|
+
frames[frames.length - 1].lastKey = decodeJsonKey(rawInput.slice(stringStart, index));
|
|
22850
|
+
} else {
|
|
22851
|
+
expectValue = false;
|
|
22852
|
+
}
|
|
22853
|
+
}
|
|
22854
|
+
continue;
|
|
22855
|
+
}
|
|
22856
|
+
if (char === '"') {
|
|
22857
|
+
var _frames_3;
|
|
22858
|
+
inString = true;
|
|
22859
|
+
stringStart = index + 1;
|
|
22860
|
+
isKey = !expectValue && ((_frames_3 = frames[frames.length - 1]) === null || _frames_3 === void 0 ? void 0 : _frames_3.isObject) === true;
|
|
22861
|
+
} else if (char === ':') {
|
|
22862
|
+
expectValue = true;
|
|
22863
|
+
} else if (char === ',') {
|
|
22864
|
+
expectValue = false;
|
|
22865
|
+
} else if (char === '{' || char === '[') {
|
|
22866
|
+
var _ref;
|
|
22867
|
+
var _frames_4;
|
|
22868
|
+
frames.push({
|
|
22869
|
+
key: expectValue ? (_ref = (_frames_4 = frames[frames.length - 1]) === null || _frames_4 === void 0 ? void 0 : _frames_4.lastKey) !== null && _ref !== void 0 ? _ref : '' : '',
|
|
22870
|
+
lastKey: '',
|
|
22871
|
+
isObject: char === '{'
|
|
22872
|
+
});
|
|
22873
|
+
expectValue = false;
|
|
22874
|
+
} else if (char === '}' || char === ']') {
|
|
22875
|
+
frames.pop();
|
|
22876
|
+
expectValue = false;
|
|
22877
|
+
}
|
|
22878
|
+
}
|
|
22879
|
+
return inString && !isKey && ((_frames_ = frames[frames.length - 1]) === null || _frames_ === void 0 ? void 0 : _frames_.lastKey) === 'objectID' && ((_frames_1 = frames[frames.length - 2]) === null || _frames_1 === void 0 ? void 0 : _frames_1.key) === 'results' && ((_frames_2 = frames[frames.length - 4]) === null || _frames_2 === void 0 ? void 0 : _frames_2.key) === 'groups';
|
|
22880
|
+
};
|
|
21807
22881
|
var DEFAULT_TRANSLATIONS$1 = {
|
|
21808
22882
|
streamingLabel: 'Curating results…'
|
|
21809
22883
|
};
|
|
21810
22884
|
function createDisplayResultsToolComponent(param) {
|
|
21811
|
-
var createElement = param.createElement, Fragment = param.Fragment, useMemo = param.useMemo;
|
|
22885
|
+
var createElement = param.createElement, Fragment = param.Fragment, useEffect = param.useEffect, useMemo = param.useMemo, useRef = param.useRef;
|
|
21812
22886
|
return function DisplayResultsTool(userProps) {
|
|
22887
|
+
var _ref;
|
|
21813
22888
|
var toolProps = userProps.toolProps, renderGroupCarousel = userProps.groupCarouselComponent, userTranslations = userProps.translations;
|
|
21814
|
-
var message = toolProps.message, messages = toolProps.messages, sendEvent = toolProps.sendEvent;
|
|
22889
|
+
var message = toolProps.message, messages = toolProps.messages, insightsEventContext = toolProps.insightsEventContext, sendEvent = toolProps.sendEvent, status = toolProps.status;
|
|
22890
|
+
var instantSearchStatus = (_ref = insightsEventContext === null || insightsEventContext === void 0 ? void 0 : insightsEventContext.instantSearchStatus) !== null && _ref !== void 0 ? _ref : 'idle';
|
|
21815
22891
|
var translations = _object_spread({}, DEFAULT_TRANSLATIONS$1, userTranslations);
|
|
21816
|
-
var toolCallId = message === null || message === void 0 ? void 0 : message.toolCallId;
|
|
21817
22892
|
var hitsByObjectID = useMemo(function() {
|
|
21818
|
-
return messages ? getHitsByObjectID(messages,
|
|
22893
|
+
return messages ? getHitsByObjectID(messages, message) : undefined;
|
|
21819
22894
|
}, [
|
|
21820
22895
|
messages,
|
|
21821
|
-
|
|
22896
|
+
message
|
|
21822
22897
|
]);
|
|
21823
|
-
var
|
|
21824
|
-
var
|
|
21825
|
-
var
|
|
21826
|
-
var
|
|
21827
|
-
|
|
22898
|
+
var inputClaimsPayload = claimsDisplayResultsPayload(message === null || message === void 0 ? void 0 : message.input);
|
|
22899
|
+
var legacyOutput = (message === null || message === void 0 ? void 0 : message.state) === 'output-available' && message.preliminary !== true && !inputClaimsPayload ? message.output : undefined;
|
|
22900
|
+
var payload = inputClaimsPayload ? message === null || message === void 0 ? void 0 : message.input : claimsDisplayResultsPayload(legacyOutput) ? legacyOutput : undefined;
|
|
22901
|
+
var intro = typeof (payload === null || payload === void 0 ? void 0 : payload.intro) === 'string' ? payload.intro : undefined;
|
|
22902
|
+
var groups = Array.isArray(payload === null || payload === void 0 ? void 0 : payload.groups) ? payload.groups.filter(isObject) : [];
|
|
22903
|
+
var latestMessage = messages === null || messages === void 0 ? void 0 : messages[messages.length - 1];
|
|
22904
|
+
var isStreaming = status === 'streaming' && (message === null || message === void 0 ? void 0 : message.state) === 'input-streaming' && (latestMessage === null || latestMessage === void 0 ? void 0 : latestMessage.parts.some(function(part) {
|
|
22905
|
+
return part === message;
|
|
22906
|
+
})) === true;
|
|
22907
|
+
// Only the last result of the last group can still be mid-delta, so it is
|
|
22908
|
+
// the only one ever withheld.
|
|
22909
|
+
var rawInput = (message === null || message === void 0 ? void 0 : message.state) === 'input-streaming' ? message.rawInput : undefined;
|
|
22910
|
+
var withholdsTrailingResult = typeof rawInput === 'string' && endsInsideResultObjectId(rawInput);
|
|
22911
|
+
var lastGroupIndex = groups.length - 1;
|
|
22912
|
+
var renderableGroups = groups.reduce(function(renderedGroups, group, groupIndex) {
|
|
22913
|
+
var suppliedResults = Array.isArray(group.results) ? withholdsTrailingResult && groupIndex === lastGroupIndex ? group.results.slice(0, -1) : group.results : [];
|
|
22914
|
+
var results = suppliedResults.filter(function(result) {
|
|
22915
|
+
return isObject(result) && typeof result.objectID === 'string' && result.objectID !== '';
|
|
22916
|
+
});
|
|
22917
|
+
var items = results.reduce(function(renderedItems, result) {
|
|
22918
|
+
if (!hitsByObjectID || !hasOwn(hitsByObjectID, result.objectID)) {
|
|
22919
|
+
return renderedItems;
|
|
22920
|
+
}
|
|
22921
|
+
var hydrated = hitsByObjectID[result.objectID];
|
|
22922
|
+
renderedItems.push(_object_spread_props(_object_spread({}, hydrated), {
|
|
22923
|
+
objectID: result.objectID,
|
|
22924
|
+
__position: renderedItems.length + 1,
|
|
22925
|
+
__displayToolResult: result
|
|
22926
|
+
}));
|
|
22927
|
+
return renderedItems;
|
|
22928
|
+
}, []);
|
|
22929
|
+
if (items.length === 0) {
|
|
22930
|
+
return renderedGroups;
|
|
22931
|
+
}
|
|
22932
|
+
renderedGroups.push({
|
|
22933
|
+
key: groupIndex,
|
|
22934
|
+
title: typeof group.title === 'string' ? group.title : undefined,
|
|
22935
|
+
why: typeof group.why === 'string' ? group.why : undefined,
|
|
22936
|
+
items: items
|
|
22937
|
+
});
|
|
22938
|
+
return renderedGroups;
|
|
22939
|
+
}, []);
|
|
22940
|
+
var viewedItems = renderableGroups.flatMap(function(group) {
|
|
22941
|
+
return group.items;
|
|
22942
|
+
});
|
|
22943
|
+
var viewedItemsSignature = viewedItems.map(function(item) {
|
|
22944
|
+
return "".concat(item.objectID, ":").concat(item.__position);
|
|
22945
|
+
}).join('|');
|
|
22946
|
+
var lastViewedItemsSignatureRef = useRef(undefined);
|
|
22947
|
+
useEffect(function() {
|
|
22948
|
+
if (instantSearchStatus !== 'idle' || viewedItems.length === 0 || viewedItemsSignature === lastViewedItemsSignatureRef.current) {
|
|
22949
|
+
return;
|
|
22950
|
+
}
|
|
22951
|
+
var timer = setTimeout(function() {
|
|
22952
|
+
lastViewedItemsSignatureRef.current = viewedItemsSignature;
|
|
22953
|
+
sendEvent('view:internal', viewedItems, 'items_shown');
|
|
22954
|
+
}, 0);
|
|
22955
|
+
return function() {
|
|
22956
|
+
clearTimeout(timer);
|
|
22957
|
+
};
|
|
22958
|
+
}, [
|
|
22959
|
+
instantSearchStatus,
|
|
22960
|
+
sendEvent,
|
|
22961
|
+
viewedItems,
|
|
22962
|
+
viewedItemsSignature
|
|
22963
|
+
]);
|
|
22964
|
+
if (!intro && renderableGroups.length === 0 && !isStreaming) {
|
|
21828
22965
|
return /*#__PURE__*/ createElement(Fragment, null);
|
|
21829
22966
|
}
|
|
21830
22967
|
return /*#__PURE__*/ createElement("div", {
|
|
21831
22968
|
className: "ais-ChatToolDisplayResults"
|
|
21832
22969
|
}, intro && /*#__PURE__*/ createElement("div", {
|
|
21833
22970
|
className: "ais-ChatToolDisplayResults-intro"
|
|
21834
|
-
}, intro),
|
|
21835
|
-
var results = Array.isArray(group.results) ? group.results.filter(function(r) {
|
|
21836
|
-
return Boolean(r) && typeof r.objectID === 'string' && r.objectID !== '';
|
|
21837
|
-
}) : [];
|
|
21838
|
-
if (results.length === 0) return null;
|
|
21839
|
-
var items = results.map(function(result, idx) {
|
|
21840
|
-
var hydrated = hitsByObjectID === null || hitsByObjectID === void 0 ? void 0 : hitsByObjectID[result.objectID];
|
|
21841
|
-
return _object_spread_props(_object_spread({}, hydrated), {
|
|
21842
|
-
objectID: result.objectID,
|
|
21843
|
-
__position: idx + 1,
|
|
21844
|
-
__displayToolResult: result
|
|
21845
|
-
});
|
|
21846
|
-
});
|
|
22971
|
+
}, intro), renderableGroups.map(function(group) {
|
|
21847
22972
|
return /*#__PURE__*/ createElement("div", {
|
|
21848
|
-
key:
|
|
22973
|
+
key: group.key,
|
|
21849
22974
|
className: "ais-ChatToolDisplayResults-group"
|
|
21850
22975
|
}, group.title && /*#__PURE__*/ createElement("div", {
|
|
21851
22976
|
className: "ais-ChatToolDisplayResults-groupTitle"
|
|
21852
22977
|
}, group.title), group.why && /*#__PURE__*/ createElement("div", {
|
|
21853
22978
|
className: "ais-ChatToolDisplayResults-groupWhy"
|
|
21854
22979
|
}, group.why), renderGroupCarousel({
|
|
21855
|
-
items: items,
|
|
22980
|
+
items: group.items,
|
|
21856
22981
|
sendEvent: sendEvent
|
|
21857
22982
|
}));
|
|
21858
22983
|
}), isStreaming && /*#__PURE__*/ createElement("div", {
|
|
@@ -23610,7 +24735,7 @@
|
|
|
23610
24735
|
if (chatRenderState) {
|
|
23611
24736
|
if (openChat(chatRenderState, {
|
|
23612
24737
|
message: item.prompt,
|
|
23613
|
-
referer: 'prompt-suggestions'
|
|
24738
|
+
referer: 'prompt-suggestions-autocomplete'
|
|
23614
24739
|
})) {
|
|
23615
24740
|
setQuery('');
|
|
23616
24741
|
}
|
|
@@ -23925,7 +25050,9 @@
|
|
|
23925
25050
|
|
|
23926
25051
|
var CarouselUiComponent = createCarouselComponent({
|
|
23927
25052
|
createElement: React.createElement,
|
|
23928
|
-
Fragment: React.Fragment
|
|
25053
|
+
Fragment: React.Fragment,
|
|
25054
|
+
useEffect: React.useEffect,
|
|
25055
|
+
useRef: React.useRef
|
|
23929
25056
|
});
|
|
23930
25057
|
function Carousel(props) {
|
|
23931
25058
|
var _useState = _sliced_to_array(React.useState(false), 2), canScrollLeft = _useState[0], setCanScrollLeft = _useState[1];
|
|
@@ -23973,11 +25100,43 @@
|
|
|
23973
25100
|
var DisplayResultsUIComponent = createDisplayResultsToolComponent({
|
|
23974
25101
|
createElement: React.createElement,
|
|
23975
25102
|
Fragment: React.Fragment,
|
|
23976
|
-
|
|
25103
|
+
useEffect: React.useEffect,
|
|
25104
|
+
useMemo: React.useMemo,
|
|
25105
|
+
useRef: React.useRef
|
|
23977
25106
|
});
|
|
23978
25107
|
var Button = createButtonComponent({
|
|
23979
25108
|
createElement: React.createElement
|
|
23980
25109
|
});
|
|
25110
|
+
var DisplayResultsCarouselHeader = function DisplayResultsCarouselHeader(param) {
|
|
25111
|
+
var nbItems = param.nbItems, canScrollLeft = param.canScrollLeft, canScrollRight = param.canScrollRight, scrollLeft = param.scrollLeft, scrollRight = param.scrollRight;
|
|
25112
|
+
return /*#__PURE__*/ React.createElement("div", {
|
|
25113
|
+
className: "ais-ChatToolDisplayResultsCarouselHeader"
|
|
25114
|
+
}, /*#__PURE__*/ React.createElement("div", {
|
|
25115
|
+
className: "ais-ChatToolDisplayResultsCarouselHeaderCount"
|
|
25116
|
+
}, nbItems, " result", nbItems > 1 ? 's' : ''), /*#__PURE__*/ React.createElement("div", {
|
|
25117
|
+
className: "ais-ChatToolDisplayResultsCarouselHeaderScrollButtons"
|
|
25118
|
+
}, /*#__PURE__*/ React.createElement(Button, {
|
|
25119
|
+
variant: "outline",
|
|
25120
|
+
size: "sm",
|
|
25121
|
+
iconOnly: true,
|
|
25122
|
+
"aria-label": "Previous",
|
|
25123
|
+
onClick: scrollLeft,
|
|
25124
|
+
disabled: !canScrollLeft,
|
|
25125
|
+
className: "ais-ChatToolDisplayResultsCarouselHeaderScrollButton"
|
|
25126
|
+
}, /*#__PURE__*/ React.createElement(ChevronLeftIcon, {
|
|
25127
|
+
createElement: React.createElement
|
|
25128
|
+
})), /*#__PURE__*/ React.createElement(Button, {
|
|
25129
|
+
variant: "outline",
|
|
25130
|
+
size: "sm",
|
|
25131
|
+
iconOnly: true,
|
|
25132
|
+
"aria-label": "Next",
|
|
25133
|
+
onClick: scrollRight,
|
|
25134
|
+
disabled: !canScrollRight,
|
|
25135
|
+
className: "ais-ChatToolDisplayResultsCarouselHeaderScrollButton"
|
|
25136
|
+
}, /*#__PURE__*/ React.createElement(ChevronRightIcon, {
|
|
25137
|
+
createElement: React.createElement
|
|
25138
|
+
}))));
|
|
25139
|
+
};
|
|
23981
25140
|
var DisplayResultsLayoutComponent = function DisplayResultsLayoutComponent(toolProps) {
|
|
23982
25141
|
return /*#__PURE__*/ React.createElement(DisplayResultsUIComponent, {
|
|
23983
25142
|
toolProps: toolProps,
|
|
@@ -23988,40 +25147,14 @@
|
|
|
23988
25147
|
itemComponent: itemComponent,
|
|
23989
25148
|
sendEvent: sendEvent,
|
|
23990
25149
|
showNavigation: false,
|
|
23991
|
-
headerComponent:
|
|
23992
|
-
var canScrollLeft = param.canScrollLeft, canScrollRight = param.canScrollRight, scrollLeft = param.scrollLeft, scrollRight = param.scrollRight;
|
|
23993
|
-
return /*#__PURE__*/ React.createElement("div", {
|
|
23994
|
-
className: "ais-ChatToolDisplayResultsCarouselHeader"
|
|
23995
|
-
}, /*#__PURE__*/ React.createElement("div", {
|
|
23996
|
-
className: "ais-ChatToolDisplayResultsCarouselHeaderCount"
|
|
23997
|
-
}, items.length, " result", items.length > 1 ? 's' : ''), /*#__PURE__*/ React.createElement("div", {
|
|
23998
|
-
className: "ais-ChatToolDisplayResultsCarouselHeaderScrollButtons"
|
|
23999
|
-
}, /*#__PURE__*/ React.createElement(Button, {
|
|
24000
|
-
variant: "outline",
|
|
24001
|
-
size: "sm",
|
|
24002
|
-
iconOnly: true,
|
|
24003
|
-
onClick: scrollLeft,
|
|
24004
|
-
disabled: !canScrollLeft,
|
|
24005
|
-
className: "ais-ChatToolDisplayResultsCarouselHeaderScrollButton"
|
|
24006
|
-
}, /*#__PURE__*/ React.createElement(ChevronLeftIcon, {
|
|
24007
|
-
createElement: React.createElement
|
|
24008
|
-
})), /*#__PURE__*/ React.createElement(Button, {
|
|
24009
|
-
variant: "outline",
|
|
24010
|
-
size: "sm",
|
|
24011
|
-
iconOnly: true,
|
|
24012
|
-
onClick: scrollRight,
|
|
24013
|
-
disabled: !canScrollRight,
|
|
24014
|
-
className: "ais-ChatToolDisplayResultsCarouselHeaderScrollButton"
|
|
24015
|
-
}, /*#__PURE__*/ React.createElement(ChevronRightIcon, {
|
|
24016
|
-
createElement: React.createElement
|
|
24017
|
-
}))));
|
|
24018
|
-
}
|
|
25150
|
+
headerComponent: DisplayResultsCarouselHeader
|
|
24019
25151
|
});
|
|
24020
25152
|
}
|
|
24021
25153
|
});
|
|
24022
25154
|
};
|
|
24023
25155
|
return {
|
|
24024
|
-
layoutComponent: DisplayResultsLayoutComponent
|
|
25156
|
+
layoutComponent: DisplayResultsLayoutComponent,
|
|
25157
|
+
streamInput: true
|
|
24025
25158
|
};
|
|
24026
25159
|
}
|
|
24027
25160
|
|
|
@@ -24029,6 +25162,7 @@
|
|
|
24029
25162
|
var SearchLayoutUIComponent = createCarouselToolComponent({
|
|
24030
25163
|
createElement: React.createElement,
|
|
24031
25164
|
Fragment: React.Fragment,
|
|
25165
|
+
useEffect: React.useEffect,
|
|
24032
25166
|
useMemo: React.useMemo,
|
|
24033
25167
|
useRef: React.useRef,
|
|
24034
25168
|
useState: React.useState
|
|
@@ -24058,11 +25192,28 @@
|
|
|
24058
25192
|
var _obj;
|
|
24059
25193
|
return _obj = {}, _define_property(_obj, SearchIndexToolType$2, createCarouselTool(true, itemComponent, getSearchPageURL)), _define_property(_obj, RecommendToolType, createCarouselTool(false, itemComponent, getSearchPageURL)), _define_property(_obj, DisplayResultsToolType, createDisplayResultsTool(itemComponent)), _define_property(_obj, MemorizeToolType, {}), _define_property(_obj, MemorySearchToolType, {}), _define_property(_obj, PonderToolType, {}), _obj;
|
|
24060
25194
|
}
|
|
25195
|
+
function mergeToolOptions(defaultTools, userTools) {
|
|
25196
|
+
if (!userTools) {
|
|
25197
|
+
return defaultTools;
|
|
25198
|
+
}
|
|
25199
|
+
var tools = _object_spread({}, defaultTools, userTools);
|
|
25200
|
+
Object.keys(userTools).forEach(function(toolName) {
|
|
25201
|
+
var _defaultTools_toolName;
|
|
25202
|
+
var userTool = userTools[toolName];
|
|
25203
|
+
var defaultStreamInput = (_defaultTools_toolName = defaultTools[toolName]) === null || _defaultTools_toolName === void 0 ? void 0 : _defaultTools_toolName.streamInput;
|
|
25204
|
+
if (userTool.layoutComponent !== undefined && userTool.streamInput === undefined && defaultStreamInput !== undefined) {
|
|
25205
|
+
tools[toolName] = _object_spread_props(_object_spread({}, userTool), {
|
|
25206
|
+
streamInput: defaultStreamInput
|
|
25207
|
+
});
|
|
25208
|
+
}
|
|
25209
|
+
});
|
|
25210
|
+
return tools;
|
|
25211
|
+
}
|
|
24061
25212
|
function ChatInner(_0, _1) {
|
|
24062
25213
|
var _ref = [
|
|
24063
25214
|
_0,
|
|
24064
25215
|
_1
|
|
24065
|
-
], _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, [
|
|
25216
|
+
], _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, showReasoning = _ref2.showReasoning, props = _object_without_properties(_ref2, [
|
|
24066
25217
|
"tools",
|
|
24067
25218
|
"headerProps",
|
|
24068
25219
|
"messagesProps",
|
|
@@ -24090,7 +25241,8 @@
|
|
|
24090
25241
|
"translations",
|
|
24091
25242
|
"title",
|
|
24092
25243
|
"getSearchPageURL",
|
|
24093
|
-
"disableTriggerValidation"
|
|
25244
|
+
"disableTriggerValidation",
|
|
25245
|
+
"showReasoning"
|
|
24094
25246
|
]), _rest1 = _sliced_to_array(_rest, 1), ref = _rest1[0];
|
|
24095
25247
|
var promptTranslations = translations.prompt, headerTranslations = translations.header, messageTranslations = translations.message, messagesTranslations = translations.messages;
|
|
24096
25248
|
var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, setIndexUiState = _useInstantSearch.setIndexUiState;
|
|
@@ -24102,7 +25254,7 @@
|
|
|
24102
25254
|
}), scrollRef = _useStickToBottom.scrollRef, contentRef = _useStickToBottom.contentRef, scrollToBottom = _useStickToBottom.scrollToBottom, isAtBottom = _useStickToBottom.isAtBottom;
|
|
24103
25255
|
var tools = React.useMemo(function() {
|
|
24104
25256
|
var defaults = createDefaultTools(itemComponent, getSearchPageURL);
|
|
24105
|
-
return
|
|
25257
|
+
return mergeToolOptions(defaults, userTools);
|
|
24106
25258
|
}, [
|
|
24107
25259
|
getSearchPageURL,
|
|
24108
25260
|
itemComponent,
|
|
@@ -24160,6 +25312,10 @@
|
|
|
24160
25312
|
if (error) {
|
|
24161
25313
|
throw error;
|
|
24162
25314
|
}
|
|
25315
|
+
var _ref3 = messagesProps !== null && messagesProps !== void 0 ? messagesProps : {}, callerAssistantMessageProps = _ref3.assistantMessageProps, callerUserMessageProps = _ref3.userMessageProps, restMessagesProps = _object_without_properties(_ref3, [
|
|
25316
|
+
"assistantMessageProps",
|
|
25317
|
+
"userMessageProps"
|
|
25318
|
+
]);
|
|
24163
25319
|
return /*#__PURE__*/ React.createElement(ChatUiComponent, {
|
|
24164
25320
|
title: title,
|
|
24165
25321
|
open: open,
|
|
@@ -24215,17 +25371,18 @@
|
|
|
24215
25371
|
errorComponent: messagesErrorComponent,
|
|
24216
25372
|
emptyComponent: emptyComponent,
|
|
24217
25373
|
actionsComponent: actionsComponent,
|
|
25374
|
+
translations: messagesTranslations,
|
|
25375
|
+
messageTranslations: messageTranslations
|
|
25376
|
+
}, restMessagesProps), {
|
|
24218
25377
|
assistantMessageProps: _object_spread({
|
|
24219
25378
|
leadingComponent: assistantMessageLeadingComponent,
|
|
24220
|
-
footerComponent: assistantMessageFooterComponent
|
|
24221
|
-
|
|
25379
|
+
footerComponent: assistantMessageFooterComponent,
|
|
25380
|
+
showReasoning: showReasoning
|
|
25381
|
+
}, callerAssistantMessageProps),
|
|
24222
25382
|
userMessageProps: _object_spread({
|
|
24223
25383
|
leadingComponent: userMessageLeadingComponent,
|
|
24224
25384
|
footerComponent: userMessageFooterComponent
|
|
24225
|
-
},
|
|
24226
|
-
translations: messagesTranslations,
|
|
24227
|
-
messageTranslations: messageTranslations
|
|
24228
|
-
}, messagesProps), {
|
|
25385
|
+
}, callerUserMessageProps),
|
|
24229
25386
|
error: error
|
|
24230
25387
|
}),
|
|
24231
25388
|
promptProps: _object_spread({
|
|
@@ -24261,6 +25418,55 @@
|
|
|
24261
25418
|
}
|
|
24262
25419
|
var Chat = /*#__PURE__*/ React.forwardRef(ChatInner);
|
|
24263
25420
|
|
|
25421
|
+
var PromptSuggestionsUi = createPromptSuggestionsComponent({
|
|
25422
|
+
createElement: React.createElement,
|
|
25423
|
+
Fragment: React.Fragment
|
|
25424
|
+
});
|
|
25425
|
+
function PromptSuggestions(_0) {
|
|
25426
|
+
var _0_classNames = _0.classNames, classNames = _0_classNames === void 0 ? {} : _0_classNames, LayoutComponent = _0.layoutComponent, onSuggestionClickOverride = _0.onSuggestionClick, // Connector params — forwarded to the hook, not the UI root.
|
|
25427
|
+
agentId = _0.agentId, transport = _0.transport, configurationId = _0.configurationId, transformHits = _0.transformHits, context = _0.context, transformItems = _0.transformItems, props = _object_without_properties(_0, [
|
|
25428
|
+
"classNames",
|
|
25429
|
+
"layoutComponent",
|
|
25430
|
+
"onSuggestionClick",
|
|
25431
|
+
"agentId",
|
|
25432
|
+
"transport",
|
|
25433
|
+
"configurationId",
|
|
25434
|
+
"transformHits",
|
|
25435
|
+
"context",
|
|
25436
|
+
"transformItems"
|
|
25437
|
+
]);
|
|
25438
|
+
var _usePromptSuggestions = usePromptSuggestions({
|
|
25439
|
+
agentId: agentId,
|
|
25440
|
+
transport: transport,
|
|
25441
|
+
configurationId: configurationId,
|
|
25442
|
+
transformHits: transformHits,
|
|
25443
|
+
context: context,
|
|
25444
|
+
transformItems: transformItems
|
|
25445
|
+
}, {
|
|
25446
|
+
$$widgetType: 'ais.promptSuggestions'
|
|
25447
|
+
}), suggestions = _usePromptSuggestions.suggestions, isLoading = _usePromptSuggestions.isLoading, onSuggestionClick = _usePromptSuggestions.onSuggestionClick, isChatBusy = _usePromptSuggestions.isChatBusy, sendToChat = _usePromptSuggestions.sendToChat;
|
|
25448
|
+
var handleClick = onSuggestionClickOverride ? function(prompt) {
|
|
25449
|
+
return onSuggestionClickOverride(prompt, {
|
|
25450
|
+
sendToChat: sendToChat
|
|
25451
|
+
});
|
|
25452
|
+
} : onSuggestionClick;
|
|
25453
|
+
if (LayoutComponent) {
|
|
25454
|
+
return /*#__PURE__*/ React.createElement(LayoutComponent, {
|
|
25455
|
+
suggestions: suggestions,
|
|
25456
|
+
isLoading: isLoading,
|
|
25457
|
+
onSuggestionClick: handleClick,
|
|
25458
|
+
isChatBusy: isChatBusy
|
|
25459
|
+
});
|
|
25460
|
+
}
|
|
25461
|
+
return /*#__PURE__*/ React.createElement(PromptSuggestionsUi, _object_spread_props(_object_spread({}, props), {
|
|
25462
|
+
classNames: classNames,
|
|
25463
|
+
suggestions: suggestions,
|
|
25464
|
+
isLoading: isLoading,
|
|
25465
|
+
onSuggestionClick: handleClick,
|
|
25466
|
+
disabled: isChatBusy
|
|
25467
|
+
}));
|
|
25468
|
+
}
|
|
25469
|
+
|
|
24264
25470
|
var ChatToggleButton = createChatToggleButtonComponent({
|
|
24265
25471
|
createElement: React.createElement,
|
|
24266
25472
|
Fragment: React.Fragment
|
|
@@ -26151,6 +27357,7 @@
|
|
|
26151
27357
|
exports.Pagination = Pagination;
|
|
26152
27358
|
exports.PonderToolType = PonderToolType;
|
|
26153
27359
|
exports.PoweredBy = PoweredBy;
|
|
27360
|
+
exports.PromptSuggestions = PromptSuggestions;
|
|
26154
27361
|
exports.RangeInput = RangeInput;
|
|
26155
27362
|
exports.RecommendToolType = RecommendToolType;
|
|
26156
27363
|
exports.RefinementList = RefinementList;
|
|
@@ -26190,6 +27397,7 @@
|
|
|
26190
27397
|
exports.useNumericMenu = useNumericMenu;
|
|
26191
27398
|
exports.usePagination = usePagination;
|
|
26192
27399
|
exports.usePoweredBy = usePoweredBy;
|
|
27400
|
+
exports.usePromptSuggestions = usePromptSuggestions;
|
|
26193
27401
|
exports.useQueryRules = useQueryRules;
|
|
26194
27402
|
exports.useRSCContext = useRSCContext;
|
|
26195
27403
|
exports.useRange = useRange;
|