react-instantsearch 7.40.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 +23 -14
- package/dist/cjs/widgets/Chat.js +33 -10
- 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 +15 -86
- package/dist/cjs/widgets/index.js +1 -0
- package/dist/es/components/Carousel.js +4 -2
- package/dist/es/index.js +2 -1
- package/dist/es/widgets/Autocomplete.d.ts +3 -1
- package/dist/es/widgets/Autocomplete.js +13 -12
- package/dist/es/widgets/Chat.d.ts +4 -0
- package/dist/es/widgets/Chat.js +42 -19
- 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 +17 -88
- package/dist/es/widgets/index.d.ts +1 -0
- package/dist/es/widgets/index.js +2 -1
- package/dist/umd/ReactInstantSearch.js +2426 -873
- 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') {
|
|
@@ -7037,7 +7069,7 @@
|
|
|
7037
7069
|
return attribute;
|
|
7038
7070
|
}
|
|
7039
7071
|
|
|
7040
|
-
function addAbsolutePosition(hits, page, hitsPerPage) {
|
|
7072
|
+
function addAbsolutePosition$1(hits, page, hitsPerPage) {
|
|
7041
7073
|
return hits.map(function(hit, idx) {
|
|
7042
7074
|
return _object_spread_props(_object_spread({}, hit), {
|
|
7043
7075
|
__position: hitsPerPage * page + idx + 1
|
|
@@ -7045,7 +7077,7 @@
|
|
|
7045
7077
|
});
|
|
7046
7078
|
}
|
|
7047
7079
|
|
|
7048
|
-
function addQueryID(hits, queryID) {
|
|
7080
|
+
function addQueryID$1(hits, queryID) {
|
|
7049
7081
|
if (!queryID) {
|
|
7050
7082
|
return hits;
|
|
7051
7083
|
}
|
|
@@ -7254,6 +7286,12 @@
|
|
|
7254
7286
|
return widget.$$type === 'ais.dynamicWidgets' || widget.$$type === 'ais.feeds';
|
|
7255
7287
|
}
|
|
7256
7288
|
|
|
7289
|
+
/**
|
|
7290
|
+
* Logs a warning when this function is called, in development environment only.
|
|
7291
|
+
*/ var deprecate = function deprecate(fn, // eslint-disable-next-line no-unused-vars
|
|
7292
|
+
message) {
|
|
7293
|
+
return fn;
|
|
7294
|
+
};
|
|
7257
7295
|
/**
|
|
7258
7296
|
* Logs a warning
|
|
7259
7297
|
* This is used to log issues in development environment only.
|
|
@@ -7757,13 +7795,13 @@
|
|
|
7757
7795
|
return null;
|
|
7758
7796
|
}
|
|
7759
7797
|
|
|
7760
|
-
var withUsage$
|
|
7798
|
+
var withUsage$w = createDocumentationMessageGenerator({
|
|
7761
7799
|
name: 'dynamic-widgets',
|
|
7762
7800
|
connector: true
|
|
7763
7801
|
});
|
|
7764
7802
|
var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
|
|
7765
7803
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
7766
|
-
checkRendering(renderFn, withUsage$
|
|
7804
|
+
checkRendering(renderFn, withUsage$w());
|
|
7767
7805
|
return function(widgetParams) {
|
|
7768
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 ? [
|
|
7769
7807
|
'*'
|
|
@@ -7773,10 +7811,10 @@
|
|
|
7773
7811
|
if (!(widgets && Array.isArray(widgets) && widgets.every(function(widget) {
|
|
7774
7812
|
return (typeof widget === "undefined" ? "undefined" : _type_of(widget)) === 'object';
|
|
7775
7813
|
}))) {
|
|
7776
|
-
throw new Error(withUsage$
|
|
7814
|
+
throw new Error(withUsage$w('The `widgets` option expects an array of widgets.'));
|
|
7777
7815
|
}
|
|
7778
7816
|
if (!Array.isArray(facets)) {
|
|
7779
|
-
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))));
|
|
7780
7818
|
}
|
|
7781
7819
|
var localWidgets = new Map();
|
|
7782
7820
|
return {
|
|
@@ -7878,7 +7916,7 @@
|
|
|
7878
7916
|
results: results
|
|
7879
7917
|
});
|
|
7880
7918
|
if (!Array.isArray(attributesToRender)) {
|
|
7881
|
-
throw new Error(withUsage$
|
|
7919
|
+
throw new Error(withUsage$w('The `transformItems` option expects a function that returns an Array.'));
|
|
7882
7920
|
}
|
|
7883
7921
|
return {
|
|
7884
7922
|
attributesToRender: attributesToRender,
|
|
@@ -8199,19 +8237,19 @@
|
|
|
8199
8237
|
return toFeedSearchResults(lastResults._state, raw);
|
|
8200
8238
|
});
|
|
8201
8239
|
}
|
|
8202
|
-
var withUsage$
|
|
8240
|
+
var withUsage$v = createDocumentationMessageGenerator({
|
|
8203
8241
|
name: 'feeds',
|
|
8204
8242
|
connector: true
|
|
8205
8243
|
});
|
|
8206
8244
|
var connectFeeds = function connectFeeds(renderFn) {
|
|
8207
8245
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
8208
|
-
checkRendering(renderFn, withUsage$
|
|
8246
|
+
checkRendering(renderFn, withUsage$v());
|
|
8209
8247
|
return function(widgetParams) {
|
|
8210
8248
|
var isolated = widgetParams.isolated, _widgetParams_transformFeeds = widgetParams.transformFeeds, transformFeeds = _widgetParams_transformFeeds === void 0 ? function(feeds) {
|
|
8211
8249
|
return feeds;
|
|
8212
8250
|
} : _widgetParams_transformFeeds;
|
|
8213
8251
|
if (isolated !== false) {
|
|
8214
|
-
throw new Error(withUsage$
|
|
8252
|
+
throw new Error(withUsage$v('The `isolated` option currently only supports `false`.'));
|
|
8215
8253
|
}
|
|
8216
8254
|
return {
|
|
8217
8255
|
$$type: 'ais.feeds',
|
|
@@ -8219,7 +8257,7 @@
|
|
|
8219
8257
|
init: function init(initOptions) {
|
|
8220
8258
|
var instantSearchInstance = initOptions.instantSearchInstance;
|
|
8221
8259
|
if (!instantSearchInstance.compositionID) {
|
|
8222
|
-
throw new Error(withUsage$
|
|
8260
|
+
throw new Error(withUsage$v('The `feeds` widget requires a composition-based InstantSearch instance (compositionID must be set).'));
|
|
8223
8261
|
}
|
|
8224
8262
|
hydrateFeedsFromInitialResultsIfNeeded(instantSearchInstance, initOptions.parent);
|
|
8225
8263
|
renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
|
|
@@ -8265,12 +8303,12 @@
|
|
|
8265
8303
|
];
|
|
8266
8304
|
feedIDs = transformFeeds(feedIDs);
|
|
8267
8305
|
if (!Array.isArray(feedIDs)) {
|
|
8268
|
-
throw new Error(withUsage$
|
|
8306
|
+
throw new Error(withUsage$v('The `transformFeeds` option expects a function that returns an Array.'));
|
|
8269
8307
|
}
|
|
8270
8308
|
if (!feedIDs.every(function(feedID) {
|
|
8271
8309
|
return typeof feedID === 'string';
|
|
8272
8310
|
})) {
|
|
8273
|
-
throw new Error(withUsage$
|
|
8311
|
+
throw new Error(withUsage$v('The `transformFeeds` option expects a function that returns an array of feed IDs (strings).'));
|
|
8274
8312
|
}
|
|
8275
8313
|
return {
|
|
8276
8314
|
feedIDs: feedIDs,
|
|
@@ -8381,7 +8419,7 @@
|
|
|
8381
8419
|
}));
|
|
8382
8420
|
}
|
|
8383
8421
|
|
|
8384
|
-
var withUsage$
|
|
8422
|
+
var withUsage$u = createDocumentationMessageGenerator({
|
|
8385
8423
|
name: 'index-widget'
|
|
8386
8424
|
});
|
|
8387
8425
|
/**
|
|
@@ -8507,12 +8545,13 @@
|
|
|
8507
8545
|
instantSearchInstance._hasRecommendWidget = hasRecommendWidget;
|
|
8508
8546
|
}
|
|
8509
8547
|
var index = function index(widgetParams) {
|
|
8510
|
-
|
|
8511
|
-
|
|
8548
|
+
var _widgetParams_EXPERIMENTAL_isolated;
|
|
8549
|
+
if (widgetParams === undefined || widgetParams.indexName === undefined && !widgetParams.isolated && !widgetParams.EXPERIMENTAL_isolated) {
|
|
8550
|
+
throw new Error(withUsage$u('The `indexName` option is required.'));
|
|
8512
8551
|
}
|
|
8513
8552
|
// When isolated=true, we use an empty string as the default indexName.
|
|
8514
8553
|
// This is intentional: isolated indices do not require a real index name.
|
|
8515
|
-
var _widgetParams_indexName = widgetParams.indexName, indexName = _widgetParams_indexName === void 0 ? '' : _widgetParams_indexName, _widgetParams_indexId = widgetParams.indexId, indexId = _widgetParams_indexId === void 0 ? indexName : _widgetParams_indexId,
|
|
8554
|
+
var _widgetParams_indexName = widgetParams.indexName, indexName = _widgetParams_indexName === void 0 ? '' : _widgetParams_indexName, _widgetParams_indexId = widgetParams.indexId, indexId = _widgetParams_indexId === void 0 ? indexName : _widgetParams_indexId, _widgetParams_isolated = widgetParams.isolated, isolated = _widgetParams_isolated === void 0 ? (_widgetParams_EXPERIMENTAL_isolated = widgetParams.EXPERIMENTAL_isolated) !== null && _widgetParams_EXPERIMENTAL_isolated !== void 0 ? _widgetParams_EXPERIMENTAL_isolated : false : _widgetParams_isolated;
|
|
8516
8555
|
var localWidgets = [];
|
|
8517
8556
|
var localUiState = {};
|
|
8518
8557
|
var localInstantSearchInstance = null;
|
|
@@ -8601,7 +8640,7 @@
|
|
|
8601
8640
|
addWidgets: function addWidgets(widgets) {
|
|
8602
8641
|
var _this = this;
|
|
8603
8642
|
if (!Array.isArray(widgets)) {
|
|
8604
|
-
throw new Error(withUsage$
|
|
8643
|
+
throw new Error(withUsage$u('The `addWidgets` method expects an array of widgets.'));
|
|
8605
8644
|
}
|
|
8606
8645
|
var flatWidgets = widgets.reduce(function(acc, w) {
|
|
8607
8646
|
return acc.concat(Array.isArray(w) ? w : [
|
|
@@ -8611,7 +8650,7 @@
|
|
|
8611
8650
|
if (flatWidgets.some(function(widget) {
|
|
8612
8651
|
return typeof widget.init !== 'function' && typeof widget.render !== 'function';
|
|
8613
8652
|
})) {
|
|
8614
|
-
throw new Error(withUsage$
|
|
8653
|
+
throw new Error(withUsage$u('The widget definition expects a `render` and/or an `init` method.'));
|
|
8615
8654
|
}
|
|
8616
8655
|
flatWidgets.forEach(function(widget) {
|
|
8617
8656
|
widget.parent = _this;
|
|
@@ -8662,7 +8701,7 @@
|
|
|
8662
8701
|
removeWidgets: function removeWidgets(widgets) {
|
|
8663
8702
|
var _this = this;
|
|
8664
8703
|
if (!Array.isArray(widgets)) {
|
|
8665
|
-
throw new Error(withUsage$
|
|
8704
|
+
throw new Error(withUsage$u('The `removeWidgets` method expects an array of widgets.'));
|
|
8666
8705
|
}
|
|
8667
8706
|
var flatWidgets = widgets.reduce(function(acc, w) {
|
|
8668
8707
|
return acc.concat(Array.isArray(w) ? w : [
|
|
@@ -8672,7 +8711,7 @@
|
|
|
8672
8711
|
if (flatWidgets.some(function(widget) {
|
|
8673
8712
|
return typeof widget.dispose !== 'function';
|
|
8674
8713
|
})) {
|
|
8675
|
-
throw new Error(withUsage$
|
|
8714
|
+
throw new Error(withUsage$u('The widget definition expects a `dispose` method.'));
|
|
8676
8715
|
}
|
|
8677
8716
|
localWidgets = localWidgets.filter(function(widget) {
|
|
8678
8717
|
return flatWidgets.indexOf(widget) === -1;
|
|
@@ -8800,7 +8839,7 @@
|
|
|
8800
8839
|
mainHelper.state
|
|
8801
8840
|
].concat(_to_consumable_array(resolveSearchParameters(_this))));
|
|
8802
8841
|
}, function() {
|
|
8803
|
-
return _this.getHelper().recommendState;
|
|
8842
|
+
return addInsightsToRecommendParameters(_this.getHelper().recommendState, mainHelper.state);
|
|
8804
8843
|
});
|
|
8805
8844
|
var indexInitialResults = (_instantSearchInstance__initialResults = instantSearchInstance._initialResults) === null || _instantSearchInstance__initialResults === void 0 ? void 0 : _instantSearchInstance__initialResults[this.getIndexId()];
|
|
8806
8845
|
if (indexInitialResults === null || indexInitialResults === void 0 ? void 0 : indexInitialResults.results) {
|
|
@@ -9177,7 +9216,7 @@
|
|
|
9177
9216
|
});
|
|
9178
9217
|
}
|
|
9179
9218
|
|
|
9180
|
-
var version = '4.
|
|
9219
|
+
var version = '4.109.0';
|
|
9181
9220
|
|
|
9182
9221
|
var ANONYMOUS_TOKEN_COOKIE_KEY = '_ALGOLIA';
|
|
9183
9222
|
function getCookie(name) {
|
|
@@ -9407,7 +9446,8 @@
|
|
|
9407
9446
|
helper.overrideStateWithoutTriggeringChangeEvent(_object_spread_props(_object_spread({}, helper.state), {
|
|
9408
9447
|
userToken: normalizedUserToken
|
|
9409
9448
|
}));
|
|
9410
|
-
if (existingToken && existingToken !==
|
|
9449
|
+
if (existingToken && existingToken !== normalizedUserToken) {
|
|
9450
|
+
helper._recommendCache = {};
|
|
9411
9451
|
instantSearchInstance.scheduleSearch();
|
|
9412
9452
|
}
|
|
9413
9453
|
}
|
|
@@ -9496,14 +9536,17 @@
|
|
|
9496
9536
|
} else if (event.insightsMethod) {
|
|
9497
9537
|
if (event.insightsMethod === 'viewedObjectIDs') {
|
|
9498
9538
|
var payload = event.payload;
|
|
9539
|
+
var getViewEventKey = function getViewEventKey(objectID) {
|
|
9540
|
+
return payload.queryID ? "".concat(payload.queryID, ":").concat(objectID) : objectID;
|
|
9541
|
+
};
|
|
9499
9542
|
var difference = payload.objectIDs.filter(function(objectID) {
|
|
9500
|
-
return !viewedObjectIDs.has(objectID);
|
|
9543
|
+
return !viewedObjectIDs.has(getViewEventKey(objectID));
|
|
9501
9544
|
});
|
|
9502
9545
|
if (difference.length === 0) {
|
|
9503
9546
|
return;
|
|
9504
9547
|
}
|
|
9505
9548
|
difference.forEach(function(objectID) {
|
|
9506
|
-
return viewedObjectIDs.add(objectID);
|
|
9549
|
+
return viewedObjectIDs.add(getViewEventKey(objectID));
|
|
9507
9550
|
});
|
|
9508
9551
|
payload.objectIDs = difference;
|
|
9509
9552
|
}
|
|
@@ -9611,10 +9654,10 @@
|
|
|
9611
9654
|
* and the ability to set credentials via extra parameters when sending events.
|
|
9612
9655
|
*/ function isModernInsightsClient(client) {
|
|
9613
9656
|
var _split_map = _sliced_to_array((client.version || '').split('.').map(Number), 2), major = _split_map[0], minor = _split_map[1];
|
|
9614
|
-
/*
|
|
9657
|
+
/* oxlint-disable instantsearch/naming-convention */ var v3 = major >= 3;
|
|
9615
9658
|
var v2_6 = major === 2 && minor >= 6;
|
|
9616
9659
|
var v1_10 = major === 1 && minor >= 10;
|
|
9617
|
-
/*
|
|
9660
|
+
/* oxlint-enable instantsearch/naming-convention */ return v3 || v2_6 || v1_10;
|
|
9618
9661
|
}
|
|
9619
9662
|
/**
|
|
9620
9663
|
* While `search-insights` supports both string and number user tokens,
|
|
@@ -11035,7 +11078,7 @@
|
|
|
11035
11078
|
};
|
|
11036
11079
|
}
|
|
11037
11080
|
|
|
11038
|
-
var withUsage$
|
|
11081
|
+
var withUsage$t = createDocumentationMessageGenerator({
|
|
11039
11082
|
name: 'instantsearch'
|
|
11040
11083
|
});
|
|
11041
11084
|
function defaultCreateURL() {
|
|
@@ -11098,7 +11141,7 @@
|
|
|
11098
11141
|
_this.setMaxListeners(100);
|
|
11099
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;
|
|
11100
11143
|
if (searchClient === null) {
|
|
11101
|
-
throw new Error(withUsage$
|
|
11144
|
+
throw new Error(withUsage$t('The `searchClient` option is required.'));
|
|
11102
11145
|
}
|
|
11103
11146
|
if (typeof searchClient.search !== 'function') {
|
|
11104
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/");
|
|
@@ -11107,7 +11150,7 @@
|
|
|
11107
11150
|
searchClient.addAlgoliaAgent("instantsearch.js (".concat(version, ")"));
|
|
11108
11151
|
}
|
|
11109
11152
|
if (insightsClient && typeof insightsClient !== 'function') {
|
|
11110
|
-
throw new Error(withUsage$
|
|
11153
|
+
throw new Error(withUsage$t('The `insightsClient` option should be a function.'));
|
|
11111
11154
|
}
|
|
11112
11155
|
_this._initialOptions = options;
|
|
11113
11156
|
_this.client = searchClient;
|
|
@@ -11256,12 +11299,12 @@
|
|
|
11256
11299
|
* @param widgets The array of widgets to add to InstantSearch.
|
|
11257
11300
|
*/ function addWidgets(widgets) {
|
|
11258
11301
|
if (!Array.isArray(widgets)) {
|
|
11259
|
-
throw new Error(withUsage$
|
|
11302
|
+
throw new Error(withUsage$t('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
|
|
11260
11303
|
}
|
|
11261
11304
|
if (this.compositionID && widgets.some(function(w) {
|
|
11262
11305
|
return !Array.isArray(w) && isIndexWidget(w) && !w._isolated;
|
|
11263
11306
|
})) {
|
|
11264
|
-
throw new Error(withUsage$
|
|
11307
|
+
throw new Error(withUsage$t('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
|
|
11265
11308
|
}
|
|
11266
11309
|
this.mainIndex.addWidgets(widgets);
|
|
11267
11310
|
return this;
|
|
@@ -11290,7 +11333,7 @@
|
|
|
11290
11333
|
* The widgets must implement a `dispose()` method to clear their states.
|
|
11291
11334
|
*/ function removeWidgets(widgets) {
|
|
11292
11335
|
if (!Array.isArray(widgets)) {
|
|
11293
|
-
throw new Error(withUsage$
|
|
11336
|
+
throw new Error(withUsage$t('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
|
|
11294
11337
|
}
|
|
11295
11338
|
this.mainIndex.removeWidgets(widgets);
|
|
11296
11339
|
return this;
|
|
@@ -11304,7 +11347,7 @@
|
|
|
11304
11347
|
*/ function start() {
|
|
11305
11348
|
var _this = this;
|
|
11306
11349
|
if (this.started) {
|
|
11307
|
-
throw new Error(withUsage$
|
|
11350
|
+
throw new Error(withUsage$t('The `start` method has already been called once.'));
|
|
11308
11351
|
}
|
|
11309
11352
|
// This Helper is used for the queries, we don't care about its state. The
|
|
11310
11353
|
// states are managed at the `index` level. We use this Helper to create
|
|
@@ -11512,7 +11555,7 @@
|
|
|
11512
11555
|
var _this = this;
|
|
11513
11556
|
var callOnStateChange = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
|
|
11514
11557
|
if (!this.mainHelper) {
|
|
11515
|
-
throw new Error(withUsage$
|
|
11558
|
+
throw new Error(withUsage$t('The `start` method needs to be called before `setUiState`.'));
|
|
11516
11559
|
}
|
|
11517
11560
|
// We refresh the index UI state to update the local UI state that the
|
|
11518
11561
|
// main index passes to the function form of `setUiState`.
|
|
@@ -11549,7 +11592,7 @@
|
|
|
11549
11592
|
value: function createURL() {
|
|
11550
11593
|
var nextState = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
11551
11594
|
if (!this.started) {
|
|
11552
|
-
throw new Error(withUsage$
|
|
11595
|
+
throw new Error(withUsage$t('The `start` method needs to be called before `createURL`.'));
|
|
11553
11596
|
}
|
|
11554
11597
|
return this._createURL(nextState);
|
|
11555
11598
|
}
|
|
@@ -11558,7 +11601,7 @@
|
|
|
11558
11601
|
key: "refresh",
|
|
11559
11602
|
value: function refresh() {
|
|
11560
11603
|
if (!this.mainHelper) {
|
|
11561
|
-
throw new Error(withUsage$
|
|
11604
|
+
throw new Error(withUsage$t('The `start` method needs to be called before `refresh`.'));
|
|
11562
11605
|
}
|
|
11563
11606
|
this.mainHelper.clearCache().search();
|
|
11564
11607
|
}
|
|
@@ -12065,13 +12108,13 @@
|
|
|
12065
12108
|
}, children);
|
|
12066
12109
|
}
|
|
12067
12110
|
|
|
12068
|
-
var withUsage$
|
|
12111
|
+
var withUsage$s = createDocumentationMessageGenerator({
|
|
12069
12112
|
name: 'autocomplete',
|
|
12070
12113
|
connector: true
|
|
12071
12114
|
});
|
|
12072
12115
|
var connectAutocomplete = function connectAutocomplete(renderFn) {
|
|
12073
12116
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
12074
|
-
checkRendering(renderFn, withUsage$
|
|
12117
|
+
checkRendering(renderFn, withUsage$s());
|
|
12075
12118
|
return function(widgetParams) {
|
|
12076
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) {
|
|
12077
12120
|
return indices;
|
|
@@ -12126,7 +12169,7 @@
|
|
|
12126
12169
|
helper: scopedResult.helper,
|
|
12127
12170
|
widgetType: _this.$$type
|
|
12128
12171
|
});
|
|
12129
|
-
var hits = scopedResult.results ? addQueryID(addAbsolutePosition(scopedResult.results.hits, scopedResult.results.page, scopedResult.results.hitsPerPage), scopedResult.results.queryID) : [];
|
|
12172
|
+
var hits = scopedResult.results ? addQueryID$1(addAbsolutePosition$1(scopedResult.results.hits, scopedResult.results.page, scopedResult.results.hitsPerPage), scopedResult.results.queryID) : [];
|
|
12130
12173
|
return {
|
|
12131
12174
|
indexId: scopedResult.indexId,
|
|
12132
12175
|
indexName: ((_scopedResult_results = scopedResult.results) === null || _scopedResult_results === void 0 ? void 0 : _scopedResult_results.index) || '',
|
|
@@ -12184,20 +12227,20 @@
|
|
|
12184
12227
|
return useConnector(connectAutocomplete, props, additionalWidgetProperties);
|
|
12185
12228
|
}
|
|
12186
12229
|
|
|
12187
|
-
var withUsage$
|
|
12230
|
+
var withUsage$r = createDocumentationMessageGenerator({
|
|
12188
12231
|
name: 'breadcrumb',
|
|
12189
12232
|
connector: true
|
|
12190
12233
|
});
|
|
12191
12234
|
var connectBreadcrumb = function connectBreadcrumb(renderFn) {
|
|
12192
12235
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
12193
|
-
checkRendering(renderFn, withUsage$
|
|
12236
|
+
checkRendering(renderFn, withUsage$r());
|
|
12194
12237
|
var connectorState = {};
|
|
12195
12238
|
return function(widgetParams) {
|
|
12196
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) {
|
|
12197
12240
|
return items;
|
|
12198
12241
|
} : _ref_transformItems;
|
|
12199
12242
|
if (!attributes || !Array.isArray(attributes) || attributes.length === 0) {
|
|
12200
|
-
throw new Error(withUsage$
|
|
12243
|
+
throw new Error(withUsage$r('The `attributes` option expects an array of strings.'));
|
|
12201
12244
|
}
|
|
12202
12245
|
var _attributes = _sliced_to_array(attributes, 1), hierarchicalFacetName = _attributes[0];
|
|
12203
12246
|
function getRefinedState(state, facetValue) {
|
|
@@ -12343,6 +12386,76 @@
|
|
|
12343
12386
|
return useConnector(connectBreadcrumb, props, additionalWidgetProperties);
|
|
12344
12387
|
}
|
|
12345
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
|
+
|
|
12346
12459
|
/**
|
|
12347
12460
|
* Stream parser for parsing SSE (Server-Sent Events) streams.
|
|
12348
12461
|
* The AI SDK 5 format uses SSE with JSON payloads prefixed by "data: ".
|
|
@@ -12623,76 +12736,10 @@
|
|
|
12623
12736
|
return undefined;
|
|
12624
12737
|
}
|
|
12625
12738
|
|
|
12626
|
-
var
|
|
12627
|
-
try {
|
|
12628
|
-
return JSON.parse(value);
|
|
12629
|
-
} catch (unused) {
|
|
12630
|
-
return undefined;
|
|
12631
|
-
}
|
|
12632
|
-
};
|
|
12633
|
-
var repairPartialJson = function repairPartialJson(value) {
|
|
12634
|
-
var repaired = value.trim();
|
|
12635
|
-
if (!repaired) {
|
|
12636
|
-
return repaired;
|
|
12637
|
-
}
|
|
12638
|
-
var inString = false;
|
|
12639
|
-
var isEscaped = false;
|
|
12640
|
-
var stack = [];
|
|
12641
|
-
for(var index = 0; index < repaired.length; index++){
|
|
12642
|
-
var char = repaired[index];
|
|
12643
|
-
if (inString) {
|
|
12644
|
-
if (isEscaped) {
|
|
12645
|
-
isEscaped = false;
|
|
12646
|
-
} else if (char === '\\') {
|
|
12647
|
-
isEscaped = true;
|
|
12648
|
-
} else if (char === '"') {
|
|
12649
|
-
inString = false;
|
|
12650
|
-
}
|
|
12651
|
-
continue;
|
|
12652
|
-
}
|
|
12653
|
-
if (char === '"') {
|
|
12654
|
-
inString = true;
|
|
12655
|
-
continue;
|
|
12656
|
-
}
|
|
12657
|
-
if (char === '{' || char === '[') {
|
|
12658
|
-
stack.push(char);
|
|
12659
|
-
continue;
|
|
12660
|
-
}
|
|
12661
|
-
if (char === '}' && stack[stack.length - 1] === '{') {
|
|
12662
|
-
stack.pop();
|
|
12663
|
-
continue;
|
|
12664
|
-
}
|
|
12665
|
-
if (char === ']' && stack[stack.length - 1] === '[') {
|
|
12666
|
-
stack.pop();
|
|
12667
|
-
}
|
|
12668
|
-
}
|
|
12669
|
-
if (inString && !isEscaped) {
|
|
12670
|
-
repaired += '"';
|
|
12671
|
-
}
|
|
12672
|
-
repaired = repaired.replace(RegExp(",\\s*$", "u"), '');
|
|
12673
|
-
if (stack.length > 0) {
|
|
12674
|
-
repaired += stack.reverse().map(function(opening) {
|
|
12675
|
-
return opening === '{' ? '}' : ']';
|
|
12676
|
-
}).join('');
|
|
12677
|
-
}
|
|
12678
|
-
return repaired.replace(RegExp(",\\s*([}\\]])", "gu"), '$1');
|
|
12679
|
-
};
|
|
12680
|
-
var parseToolInputDelta = function parseToolInputDelta(accumulatedRawInput, fallbackInput) {
|
|
12681
|
-
var normalized = accumulatedRawInput.trim();
|
|
12682
|
-
if (!normalized) {
|
|
12683
|
-
return fallbackInput;
|
|
12684
|
-
}
|
|
12685
|
-
var directParsed = tryParseJson(normalized);
|
|
12686
|
-
if (directParsed !== undefined) {
|
|
12687
|
-
return directParsed;
|
|
12688
|
-
}
|
|
12689
|
-
var repairedParsed = tryParseJson(repairPartialJson(normalized));
|
|
12690
|
-
if (repairedParsed !== undefined) {
|
|
12691
|
-
return repairedParsed;
|
|
12692
|
-
}
|
|
12693
|
-
return fallbackInput;
|
|
12694
|
-
};
|
|
12739
|
+
var _computedKey$1;
|
|
12695
12740
|
var defaultGuardrailFallbackResponse = 'Sorry, we are not able to generate a response at the moment.';
|
|
12741
|
+
_computedKey$1 = /** @internal */ '~addToolResultForMessage';
|
|
12742
|
+
var _computedKey1$1 = _computedKey$1;
|
|
12696
12743
|
/**
|
|
12697
12744
|
* Abstract base class for chat implementations.
|
|
12698
12745
|
*/ var AbstractChat = /*#__PURE__*/ function() {
|
|
@@ -12712,6 +12759,12 @@
|
|
|
12712
12759
|
_define_property(this, "sendAutomaticallyWhen", void 0);
|
|
12713
12760
|
_define_property(this, "shouldRepairToolInput", void 0);
|
|
12714
12761
|
_define_property(this, "activeResponse", null);
|
|
12762
|
+
_define_property(this, "latestResponse", null);
|
|
12763
|
+
_define_property(this, "responsesByToolCallId", new Map());
|
|
12764
|
+
_define_property(this, "responseByMessage", new WeakMap());
|
|
12765
|
+
// Once tool ownership is discarded, an identifier-only result cannot prove
|
|
12766
|
+
// which response generation submitted it. Scoped submissions remain safe.
|
|
12767
|
+
_define_property(this, "acceptsIdentifierOnlyToolResults", true);
|
|
12715
12768
|
_define_property(this, "jobExecutor", new SerialJobExecutor());
|
|
12716
12769
|
/**
|
|
12717
12770
|
* Appends or replaces a user message to the chat list. This triggers the API call to fetch
|
|
@@ -12797,13 +12850,13 @@
|
|
|
12797
12850
|
// Find the message to regenerate from
|
|
12798
12851
|
var targetIndex = -1;
|
|
12799
12852
|
if (messageId) {
|
|
12800
|
-
targetIndex = _this1.
|
|
12853
|
+
targetIndex = _this1.messages.findIndex(function(m) {
|
|
12801
12854
|
return m.id === messageId;
|
|
12802
12855
|
});
|
|
12803
12856
|
} else {
|
|
12804
12857
|
// Find the last assistant message
|
|
12805
|
-
for(var i = _this1.
|
|
12806
|
-
if (_this1.
|
|
12858
|
+
for(var i = _this1.messages.length - 1; i >= 0; i--){
|
|
12859
|
+
if (_this1.messages[i].role === 'assistant') {
|
|
12807
12860
|
targetIndex = i;
|
|
12808
12861
|
break;
|
|
12809
12862
|
}
|
|
@@ -12811,7 +12864,7 @@
|
|
|
12811
12864
|
}
|
|
12812
12865
|
if (targetIndex >= 0) {
|
|
12813
12866
|
// Remove the assistant message and all messages after it
|
|
12814
|
-
_this1.
|
|
12867
|
+
_this1.messages = _this1.messages.slice(0, targetIndex);
|
|
12815
12868
|
}
|
|
12816
12869
|
return _this1.makeRequest(_object_spread({
|
|
12817
12870
|
trigger: 'regenerate-message',
|
|
@@ -12826,23 +12879,10 @@
|
|
|
12826
12879
|
if (!_this.transport) {
|
|
12827
12880
|
return Promise.reject(new Error('Transport is required for resuming stream. Please provide a transport when initializing the chat.'));
|
|
12828
12881
|
}
|
|
12829
|
-
_this.
|
|
12830
|
-
|
|
12831
|
-
|
|
12832
|
-
|
|
12833
|
-
chatId: _this.id
|
|
12834
|
-
}, options)).then(function(stream) {
|
|
12835
|
-
if (stream) {
|
|
12836
|
-
return _this.processStreamWithCallbacks(stream);
|
|
12837
|
-
} else {
|
|
12838
|
-
_this.setStatus({
|
|
12839
|
-
status: 'ready'
|
|
12840
|
-
});
|
|
12841
|
-
return Promise.resolve();
|
|
12842
|
-
}
|
|
12843
|
-
}, function(error) {
|
|
12844
|
-
_this.handleError(error);
|
|
12845
|
-
return Promise.resolve();
|
|
12882
|
+
return _this.consume(function() {
|
|
12883
|
+
return _this.transport.reconnectToStream(_object_spread({
|
|
12884
|
+
chatId: _this.id
|
|
12885
|
+
}, options));
|
|
12846
12886
|
});
|
|
12847
12887
|
});
|
|
12848
12888
|
});
|
|
@@ -12858,53 +12898,57 @@
|
|
|
12858
12898
|
});
|
|
12859
12899
|
/**
|
|
12860
12900
|
* Add a tool result for a tool call.
|
|
12861
|
-
*/ _define_property(this, "addToolResult", function(
|
|
12862
|
-
|
|
12863
|
-
|
|
12864
|
-
|
|
12865
|
-
|
|
12866
|
-
|
|
12867
|
-
|
|
12868
|
-
|
|
12869
|
-
|
|
12870
|
-
|
|
12871
|
-
|
|
12872
|
-
|
|
12873
|
-
var message = _this.state.messages[messageIndex];
|
|
12874
|
-
var updatedParts = message.parts.map(function(part) {
|
|
12875
|
-
if ('toolCallId' in part && part.toolCallId === toolCallId && 'state' in part) {
|
|
12876
|
-
return _object_spread_props(_object_spread({}, part), {
|
|
12877
|
-
state: 'output-available',
|
|
12878
|
-
output: output
|
|
12879
|
-
});
|
|
12880
|
-
}
|
|
12881
|
-
return part;
|
|
12882
|
-
});
|
|
12883
|
-
_this.state.replaceMessage(messageIndex, _object_spread_props(_object_spread({}, message), {
|
|
12884
|
-
parts: updatedParts
|
|
12885
|
-
}));
|
|
12886
|
-
// Check if we should auto-send based on sendAutomaticallyWhen
|
|
12887
|
-
if (_this.sendAutomaticallyWhen) {
|
|
12888
|
-
return Promise.resolve(_this.sendAutomaticallyWhen({
|
|
12889
|
-
messages: _this.state.messages
|
|
12890
|
-
})).then(function(shouldSend) {
|
|
12891
|
-
if (shouldSend) {
|
|
12892
|
-
return _this.makeRequest({
|
|
12893
|
-
trigger: 'submit-message'
|
|
12894
|
-
});
|
|
12895
|
-
}
|
|
12896
|
-
return Promise.resolve();
|
|
12901
|
+
*/ _define_property(this, "addToolResult", function(options) {
|
|
12902
|
+
if (!_this.acceptsIdentifierOnlyToolResults) {
|
|
12903
|
+
return Promise.resolve();
|
|
12904
|
+
}
|
|
12905
|
+
var owners = _this.responsesByToolCallId.get(options.toolCallId);
|
|
12906
|
+
var response = (owners === null || owners === void 0 ? void 0 : owners.size) === 1 ? owners.values().next().value : undefined;
|
|
12907
|
+
if (response) return _this.submitToolResult(response, options);
|
|
12908
|
+
var findMatchingMessage = function findMatchingMessage() {
|
|
12909
|
+
var matchingMessages = _this.messages.filter(function(message) {
|
|
12910
|
+
var _message_parts;
|
|
12911
|
+
return (_message_parts = message.parts) === null || _message_parts === void 0 ? void 0 : _message_parts.some(function(part) {
|
|
12912
|
+
return 'toolCallId' in part && part.toolCallId === options.toolCallId;
|
|
12897
12913
|
});
|
|
12914
|
+
});
|
|
12915
|
+
return matchingMessages.length === 1 ? matchingMessages[0] : undefined;
|
|
12916
|
+
};
|
|
12917
|
+
if (!findMatchingMessage()) return Promise.resolve();
|
|
12918
|
+
return _this.jobExecutor.run(function() {
|
|
12919
|
+
if (!_this.acceptsIdentifierOnlyToolResults) return Promise.resolve();
|
|
12920
|
+
var message = findMatchingMessage();
|
|
12921
|
+
if (!message || !_this.commit(options.toolCallId, options.output, message.id, undefined, message)) {
|
|
12922
|
+
return Promise.resolve();
|
|
12898
12923
|
}
|
|
12899
|
-
return
|
|
12924
|
+
return _this.continueResponse();
|
|
12900
12925
|
});
|
|
12901
12926
|
});
|
|
12927
|
+
_define_property(this, _computedKey1$1, function(message, options) {
|
|
12928
|
+
var hasToolCall = function hasToolCall(candidate) {
|
|
12929
|
+
var _candidate_parts;
|
|
12930
|
+
return ((_candidate_parts = candidate.parts) === null || _candidate_parts === void 0 ? void 0 : _candidate_parts.some(function(part) {
|
|
12931
|
+
return 'toolCallId' in part && part.toolCallId === options.toolCallId;
|
|
12932
|
+
})) === true;
|
|
12933
|
+
};
|
|
12934
|
+
if (!hasToolCall(message)) {
|
|
12935
|
+
return Promise.resolve();
|
|
12936
|
+
}
|
|
12937
|
+
var response = _this.responseByMessage.get(message);
|
|
12938
|
+
var currentMessage = _this.messages.includes(message) ? message : response && !response.isRetired ? _this.messages.find(function(candidate) {
|
|
12939
|
+
return candidate.id === message.id && _this.responseByMessage.get(candidate) === response && hasToolCall(candidate);
|
|
12940
|
+
}) : undefined;
|
|
12941
|
+
if (!currentMessage) return Promise.resolve();
|
|
12942
|
+
return _this.submitToolResult(response, options, currentMessage.id, currentMessage);
|
|
12943
|
+
});
|
|
12902
12944
|
/**
|
|
12903
12945
|
* Abort the current request immediately, keep the generated tokens if any.
|
|
12904
12946
|
*/ _define_property(this, "stop", function() {
|
|
12905
12947
|
if (_this.activeResponse) {
|
|
12906
|
-
_this.activeResponse
|
|
12948
|
+
var response = _this.activeResponse;
|
|
12949
|
+
response.outcome = 'aborted';
|
|
12907
12950
|
_this.activeResponse = null;
|
|
12951
|
+
response.abortController.abort();
|
|
12908
12952
|
}
|
|
12909
12953
|
_this.setStatus({
|
|
12910
12954
|
status: 'ready'
|
|
@@ -12966,6 +13010,14 @@
|
|
|
12966
13010
|
* context.
|
|
12967
13011
|
*/ key: "resetConversationId",
|
|
12968
13012
|
value: function resetConversationId() {
|
|
13013
|
+
if (this.responsesByToolCallId.size > 0 || this.messages.some(function(message) {
|
|
13014
|
+
var _message_parts;
|
|
13015
|
+
return (_message_parts = message.parts) === null || _message_parts === void 0 ? void 0 : _message_parts.some(function(part) {
|
|
13016
|
+
return 'toolCallId' in part;
|
|
13017
|
+
});
|
|
13018
|
+
})) {
|
|
13019
|
+
this.acceptsIdentifierOnlyToolResults = false;
|
|
13020
|
+
}
|
|
12969
13021
|
this.conversationId = this.generateId();
|
|
12970
13022
|
}
|
|
12971
13023
|
},
|
|
@@ -12975,7 +13027,93 @@
|
|
|
12975
13027
|
return this.state.messages;
|
|
12976
13028
|
},
|
|
12977
13029
|
set: function set(messages) {
|
|
13030
|
+
var _this = this;
|
|
13031
|
+
var getToolOccurrences = function getToolOccurrences(message) {
|
|
13032
|
+
return message.parts.filter(function(part) {
|
|
13033
|
+
return 'toolCallId' in part;
|
|
13034
|
+
}).map(function(part) {
|
|
13035
|
+
return {
|
|
13036
|
+
type: part.type,
|
|
13037
|
+
toolCallId: part.toolCallId,
|
|
13038
|
+
state: 'state' in part ? part.state : undefined,
|
|
13039
|
+
input: 'input' in part ? part.input : undefined,
|
|
13040
|
+
output: 'output' in part ? part.output : undefined,
|
|
13041
|
+
errorText: 'errorText' in part ? part.errorText : undefined,
|
|
13042
|
+
providerExecuted: 'providerExecuted' in part ? part.providerExecuted : undefined
|
|
13043
|
+
};
|
|
13044
|
+
});
|
|
13045
|
+
};
|
|
13046
|
+
var isEquivalentRehydration = function isEquivalentRehydration(message) {
|
|
13047
|
+
var replacements = messages.filter(function(candidate) {
|
|
13048
|
+
return candidate.id === message.id;
|
|
13049
|
+
});
|
|
13050
|
+
if (replacements.length !== 1) return false;
|
|
13051
|
+
var toolOccurrences = getToolOccurrences(message);
|
|
13052
|
+
var replacementToolOccurrences = getToolOccurrences(replacements[0]);
|
|
13053
|
+
return toolOccurrences.length > 0 || replacementToolOccurrences.length > 0 ? isEqual(toolOccurrences, replacementToolOccurrences) : isEqual(message.parts, replacements[0].parts);
|
|
13054
|
+
};
|
|
13055
|
+
var detachedResponses = new Set();
|
|
13056
|
+
this.state.messages.forEach(function(message) {
|
|
13057
|
+
if (!messages.includes(message)) {
|
|
13058
|
+
var response = _this.responseByMessage.get(message);
|
|
13059
|
+
if (response && !isEquivalentRehydration(message)) {
|
|
13060
|
+
detachedResponses.add(response);
|
|
13061
|
+
}
|
|
13062
|
+
}
|
|
13063
|
+
});
|
|
13064
|
+
var removedToolOwner = this.state.messages.some(function(message) {
|
|
13065
|
+
var _message_parts;
|
|
13066
|
+
return ((_message_parts = message.parts) === null || _message_parts === void 0 ? void 0 : _message_parts.some(function(part) {
|
|
13067
|
+
return 'toolCallId' in part;
|
|
13068
|
+
})) && !messages.includes(message) && !isEquivalentRehydration(message);
|
|
13069
|
+
});
|
|
13070
|
+
var toolCallIds = new Set();
|
|
13071
|
+
var hasDuplicateToolCallId = messages.some(function(message) {
|
|
13072
|
+
var _message_parts;
|
|
13073
|
+
return ((_message_parts = message.parts) === null || _message_parts === void 0 ? void 0 : _message_parts.some(function(part) {
|
|
13074
|
+
if (!('toolCallId' in part)) {
|
|
13075
|
+
return false;
|
|
13076
|
+
}
|
|
13077
|
+
if (toolCallIds.has(part.toolCallId)) {
|
|
13078
|
+
return true;
|
|
13079
|
+
}
|
|
13080
|
+
toolCallIds.add(part.toolCallId);
|
|
13081
|
+
return false;
|
|
13082
|
+
})) === true;
|
|
13083
|
+
});
|
|
13084
|
+
if (removedToolOwner || hasDuplicateToolCallId) {
|
|
13085
|
+
this.acceptsIdentifierOnlyToolResults = false;
|
|
13086
|
+
}
|
|
12978
13087
|
this.state.messages = messages;
|
|
13088
|
+
var retainedMessageIds = new Set(messages.map(function(message) {
|
|
13089
|
+
return message.id;
|
|
13090
|
+
}));
|
|
13091
|
+
var responses = new Set();
|
|
13092
|
+
this.responsesByToolCallId.forEach(function(owners) {
|
|
13093
|
+
owners.forEach(function(response) {
|
|
13094
|
+
return responses.add(response);
|
|
13095
|
+
});
|
|
13096
|
+
});
|
|
13097
|
+
if (this.activeResponse) {
|
|
13098
|
+
responses.add(this.activeResponse);
|
|
13099
|
+
}
|
|
13100
|
+
detachedResponses.forEach(function(response) {
|
|
13101
|
+
responses.add(response);
|
|
13102
|
+
_this.retireResponse(response);
|
|
13103
|
+
});
|
|
13104
|
+
responses.forEach(function(response) {
|
|
13105
|
+
var message = response.messageId ? messages.find(function(candidate) {
|
|
13106
|
+
return candidate.id === response.messageId;
|
|
13107
|
+
}) : undefined;
|
|
13108
|
+
if (message && !response.isRetired && !detachedResponses.has(response)) {
|
|
13109
|
+
_this.responseByMessage.set(message, response);
|
|
13110
|
+
}
|
|
13111
|
+
});
|
|
13112
|
+
responses.forEach(function(response) {
|
|
13113
|
+
if (detachedResponses.has(response) || response.messageId && !retainedMessageIds.has(response.messageId)) {
|
|
13114
|
+
_this.pruneDetachedResponse(response);
|
|
13115
|
+
}
|
|
13116
|
+
});
|
|
12979
13117
|
}
|
|
12980
13118
|
},
|
|
12981
13119
|
{
|
|
@@ -12985,76 +13123,363 @@
|
|
|
12985
13123
|
}
|
|
12986
13124
|
},
|
|
12987
13125
|
{
|
|
12988
|
-
key: "
|
|
12989
|
-
value: function
|
|
12990
|
-
var
|
|
12991
|
-
|
|
12992
|
-
|
|
13126
|
+
key: "replaceMessage",
|
|
13127
|
+
value: function replaceMessage(index, message, response) {
|
|
13128
|
+
var _this_messages_index;
|
|
13129
|
+
this.state.replaceMessage(index, message);
|
|
13130
|
+
var canonicalMessage = (_this_messages_index = this.messages[index]) !== null && _this_messages_index !== void 0 ? _this_messages_index : message;
|
|
13131
|
+
if (response && this.messages.includes(canonicalMessage)) {
|
|
13132
|
+
this.responseByMessage.set(canonicalMessage, response);
|
|
12993
13133
|
}
|
|
12994
|
-
|
|
12995
|
-
|
|
12996
|
-
|
|
12997
|
-
|
|
12998
|
-
|
|
12999
|
-
|
|
13000
|
-
|
|
13134
|
+
return canonicalMessage;
|
|
13135
|
+
}
|
|
13136
|
+
},
|
|
13137
|
+
{
|
|
13138
|
+
key: "commit",
|
|
13139
|
+
value: function commit(toolCallId, output, messageId, response, expectedMessage) {
|
|
13140
|
+
var isTargetPart = function isTargetPart(part) {
|
|
13141
|
+
return 'toolCallId' in part && part.toolCallId === toolCallId;
|
|
13001
13142
|
};
|
|
13002
|
-
this.
|
|
13003
|
-
|
|
13143
|
+
var messageIndex = this.messages.findIndex(function(message) {
|
|
13144
|
+
return (!messageId || message.id === messageId) && (!expectedMessage || message === expectedMessage) && message.parts.some(isTargetPart);
|
|
13004
13145
|
});
|
|
13005
|
-
return
|
|
13006
|
-
|
|
13007
|
-
|
|
13008
|
-
|
|
13009
|
-
|
|
13010
|
-
|
|
13011
|
-
|
|
13012
|
-
|
|
13013
|
-
|
|
13014
|
-
|
|
13015
|
-
|
|
13016
|
-
|
|
13017
|
-
|
|
13018
|
-
|
|
13019
|
-
|
|
13020
|
-
|
|
13021
|
-
|
|
13022
|
-
|
|
13023
|
-
|
|
13146
|
+
if (messageIndex === -1) return false;
|
|
13147
|
+
var message = this.messages[messageIndex];
|
|
13148
|
+
var partIndex = message.parts.findIndex(isTargetPart);
|
|
13149
|
+
var part = message.parts[partIndex];
|
|
13150
|
+
if (!('state' in part) || part.state === 'output-available' && !part.preliminary || part.state === 'output-error') {
|
|
13151
|
+
return false;
|
|
13152
|
+
}
|
|
13153
|
+
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
13154
|
+
part.preliminary; // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
13155
|
+
part.rawOutput;
|
|
13156
|
+
var committedPart = _object_without_properties(part, [
|
|
13157
|
+
"preliminary",
|
|
13158
|
+
"rawOutput"
|
|
13159
|
+
]);
|
|
13160
|
+
var updatedParts = _to_consumable_array(message.parts);
|
|
13161
|
+
updatedParts[partIndex] = _object_spread_props(_object_spread({}, committedPart), {
|
|
13162
|
+
state: 'output-available',
|
|
13163
|
+
output: output
|
|
13164
|
+
});
|
|
13165
|
+
var updatedMessage = _object_spread_props(_object_spread({}, message), {
|
|
13166
|
+
parts: updatedParts
|
|
13024
13167
|
});
|
|
13168
|
+
this.replaceMessage(messageIndex, updatedMessage, response);
|
|
13169
|
+
return true;
|
|
13025
13170
|
}
|
|
13026
13171
|
},
|
|
13027
13172
|
{
|
|
13028
|
-
key: "
|
|
13029
|
-
value: function
|
|
13173
|
+
key: "continueResponse",
|
|
13174
|
+
value: function continueResponse(response) {
|
|
13030
13175
|
var _this = this;
|
|
13031
|
-
|
|
13032
|
-
|
|
13033
|
-
|
|
13034
|
-
|
|
13035
|
-
|
|
13036
|
-
|
|
13176
|
+
if (response) {
|
|
13177
|
+
this.pruneDetachedResponse(response);
|
|
13178
|
+
if (response.isRetired || response.outcome !== 'succeeded' || response.requiredToolCallIds.size === 0 || Array.from(response.requiredToolCallIds).some(function(toolCallId) {
|
|
13179
|
+
return !response.resolvedToolCallIds.has(toolCallId);
|
|
13180
|
+
}) || !response.didNotifyFinish || response.didEvaluateContinuation) {
|
|
13181
|
+
return Promise.resolve();
|
|
13182
|
+
}
|
|
13183
|
+
response.didEvaluateContinuation = true;
|
|
13184
|
+
}
|
|
13185
|
+
if (!this.sendAutomaticallyWhen) return Promise.resolve();
|
|
13186
|
+
return Promise.resolve().then(function() {
|
|
13187
|
+
return _this.sendAutomaticallyWhen({
|
|
13188
|
+
messages: _this.messages
|
|
13189
|
+
});
|
|
13190
|
+
}).then(function(shouldSend) {
|
|
13191
|
+
if (response) {
|
|
13192
|
+
_this.pruneDetachedResponse(response);
|
|
13193
|
+
if (response.isRetired) return undefined;
|
|
13194
|
+
}
|
|
13195
|
+
return shouldSend ? _this.makeRequest({
|
|
13196
|
+
trigger: 'submit-message'
|
|
13197
|
+
}) : undefined;
|
|
13198
|
+
}).catch(function(error) {
|
|
13199
|
+
if (response) {
|
|
13200
|
+
_this.pruneDetachedResponse(response);
|
|
13201
|
+
if (response.isRetired) return;
|
|
13202
|
+
_this.handleError(error, {
|
|
13203
|
+
updateState: _this.latestResponse === response
|
|
13204
|
+
});
|
|
13205
|
+
return;
|
|
13206
|
+
}
|
|
13207
|
+
_this.handleError(error);
|
|
13208
|
+
});
|
|
13209
|
+
}
|
|
13210
|
+
},
|
|
13211
|
+
{
|
|
13212
|
+
key: "retireResponse",
|
|
13213
|
+
value: function retireResponse(response) {
|
|
13214
|
+
if (response.isRetired) return;
|
|
13215
|
+
response.isRetired = true;
|
|
13216
|
+
response.didEvaluateContinuation = true;
|
|
13217
|
+
if (this.activeResponse === response) {
|
|
13218
|
+
response.outcome = 'aborted';
|
|
13219
|
+
this.activeResponse = null;
|
|
13220
|
+
response.abortController.abort();
|
|
13221
|
+
this.setStatus({
|
|
13222
|
+
status: 'ready'
|
|
13223
|
+
});
|
|
13224
|
+
}
|
|
13225
|
+
}
|
|
13226
|
+
},
|
|
13227
|
+
{
|
|
13228
|
+
key: "pruneDetachedResponse",
|
|
13229
|
+
value: function pruneDetachedResponse(response) {
|
|
13230
|
+
var _this = this;
|
|
13231
|
+
if (!response.isRetired) {
|
|
13232
|
+
if (!response.messageId || this.messages.some(function(message) {
|
|
13233
|
+
return message.id === response.messageId;
|
|
13234
|
+
})) {
|
|
13235
|
+
return;
|
|
13236
|
+
}
|
|
13237
|
+
this.retireResponse(response);
|
|
13238
|
+
}
|
|
13239
|
+
// Keep a routing tombstone while a callback is running so public
|
|
13240
|
+
// addToolResult calls settle directly instead of entering the executor.
|
|
13241
|
+
if (response.pendingToolCallbacks > 0) return;
|
|
13242
|
+
this.responsesByToolCallId.forEach(function(owners, toolCallId) {
|
|
13243
|
+
owners.delete(response);
|
|
13244
|
+
if (owners.size === 0) {
|
|
13245
|
+
_this.responsesByToolCallId.delete(toolCallId);
|
|
13246
|
+
}
|
|
13247
|
+
});
|
|
13248
|
+
}
|
|
13249
|
+
},
|
|
13250
|
+
{
|
|
13251
|
+
key: "submitToolResult",
|
|
13252
|
+
value: function submitToolResult(response, param) {
|
|
13253
|
+
var _this = this;
|
|
13254
|
+
var toolCallId = param.toolCallId, output = param.output, messageId = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : response === null || response === void 0 ? void 0 : response.messageId, expectedMessage = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : messageId ? this.messages.find(function(message) {
|
|
13255
|
+
return message.id === messageId;
|
|
13256
|
+
}) : undefined;
|
|
13257
|
+
if (response === null || response === void 0 ? void 0 : response.isRetired) return Promise.resolve();
|
|
13258
|
+
var commitResult = function commitResult() {
|
|
13259
|
+
if (!_this.commit(toolCallId, output, messageId, response, expectedMessage)) {
|
|
13260
|
+
return Promise.resolve();
|
|
13261
|
+
}
|
|
13262
|
+
if (response === null || response === void 0 ? void 0 : response.requiredToolCallIds.has(toolCallId)) {
|
|
13263
|
+
response.resolvedToolCallIds.add(toolCallId);
|
|
13264
|
+
}
|
|
13265
|
+
return _this.continueResponse(response);
|
|
13266
|
+
};
|
|
13267
|
+
if (response && (this.activeResponse === response || response.outcome !== 'succeeded' || response.didEvaluateContinuation)) {
|
|
13268
|
+
return commitResult();
|
|
13269
|
+
}
|
|
13270
|
+
return this.jobExecutor.run(commitResult);
|
|
13271
|
+
}
|
|
13272
|
+
},
|
|
13273
|
+
{
|
|
13274
|
+
key: "makeRequest",
|
|
13275
|
+
value: function makeRequest(options) {
|
|
13276
|
+
var _this = this;
|
|
13277
|
+
if (!this.transport) {
|
|
13278
|
+
return Promise.reject(new Error('Transport is required for sending messages. Please provide a transport when initializing the chat.'));
|
|
13279
|
+
}
|
|
13280
|
+
return this.consume(function(abortSignal) {
|
|
13281
|
+
return _this.transport.sendMessages({
|
|
13282
|
+
chatId: _this.id,
|
|
13283
|
+
messages: _this.messages,
|
|
13284
|
+
abortSignal: abortSignal,
|
|
13285
|
+
trigger: options.trigger,
|
|
13286
|
+
messageId: options.messageId,
|
|
13287
|
+
headers: options.headers,
|
|
13288
|
+
body: options.body,
|
|
13289
|
+
requestMetadata: options.metadata
|
|
13290
|
+
});
|
|
13291
|
+
});
|
|
13292
|
+
}
|
|
13293
|
+
},
|
|
13294
|
+
{
|
|
13295
|
+
key: "consume",
|
|
13296
|
+
value: function consume(createStream) {
|
|
13297
|
+
var _this = this;
|
|
13298
|
+
if (this.activeResponse) {
|
|
13299
|
+
this.activeResponse.outcome = 'aborted';
|
|
13300
|
+
this.activeResponse.abortController.abort();
|
|
13301
|
+
}
|
|
13302
|
+
var response = {
|
|
13303
|
+
abortController: new AbortController(),
|
|
13304
|
+
outcome: 'active',
|
|
13305
|
+
isRetired: false,
|
|
13306
|
+
requiredToolCallIds: new Set(),
|
|
13307
|
+
resolvedToolCallIds: new Set(),
|
|
13308
|
+
returnedToolCallbacks: [],
|
|
13309
|
+
pendingToolCallbacks: 0,
|
|
13310
|
+
didNotifyFinish: false,
|
|
13311
|
+
didEvaluateContinuation: false
|
|
13312
|
+
};
|
|
13313
|
+
this.activeResponse = response;
|
|
13314
|
+
this.latestResponse = response;
|
|
13315
|
+
this.setStatus({
|
|
13316
|
+
status: 'submitted'
|
|
13317
|
+
});
|
|
13318
|
+
return createStream(response.abortController.signal).then(function(stream) {
|
|
13319
|
+
if (_this.activeResponse === response) {
|
|
13320
|
+
if (stream) return _this.processStream(stream, response);
|
|
13321
|
+
response.outcome = 'succeeded';
|
|
13322
|
+
_this.activeResponse = null;
|
|
13323
|
+
_this.setStatus({
|
|
13324
|
+
status: 'ready'
|
|
13325
|
+
});
|
|
13326
|
+
}
|
|
13327
|
+
return undefined;
|
|
13328
|
+
}, function(error) {
|
|
13329
|
+
if (_this.activeResponse !== response) return;
|
|
13330
|
+
_this.activeResponse = null;
|
|
13331
|
+
if (error.name === 'AbortError') {
|
|
13332
|
+
response.outcome = 'aborted';
|
|
13333
|
+
_this.setStatus({
|
|
13334
|
+
status: 'ready'
|
|
13335
|
+
});
|
|
13336
|
+
} else {
|
|
13337
|
+
response.outcome = 'failed';
|
|
13338
|
+
_this.handleError(error);
|
|
13339
|
+
}
|
|
13340
|
+
});
|
|
13341
|
+
}
|
|
13342
|
+
},
|
|
13343
|
+
{
|
|
13344
|
+
key: "processStream",
|
|
13345
|
+
value: function processStream1(stream, response) {
|
|
13346
|
+
var _this = this;
|
|
13347
|
+
this.setStatus({
|
|
13348
|
+
status: 'streaming'
|
|
13349
|
+
});
|
|
13350
|
+
var currentMessageId;
|
|
13351
|
+
var currentMessage;
|
|
13352
|
+
var currentMessageIndex = -1;
|
|
13037
13353
|
var isAbort = false;
|
|
13038
|
-
var isDisconnect = false;
|
|
13039
13354
|
var isError = false;
|
|
13040
|
-
// Track current text/reasoning part state
|
|
13041
|
-
var currentTextPartId;
|
|
13042
|
-
var currentReasoningPartId;
|
|
13043
13355
|
var toolRawInputByCallId = {};
|
|
13044
13356
|
var toolRawOutputByCallId = {};
|
|
13045
|
-
|
|
13046
|
-
|
|
13357
|
+
var findToolPart = function findToolPart(toolCallId) {
|
|
13358
|
+
return currentMessage.parts.findIndex(function(part) {
|
|
13359
|
+
return 'toolCallId' in part && part.toolCallId === toolCallId;
|
|
13360
|
+
});
|
|
13361
|
+
};
|
|
13362
|
+
var setPart = function setPart(index, part) {
|
|
13363
|
+
var parts = _to_consumable_array(currentMessage.parts);
|
|
13364
|
+
parts[index < 0 ? parts.length : index] = part;
|
|
13365
|
+
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13366
|
+
parts: parts
|
|
13367
|
+
});
|
|
13368
|
+
currentMessage = _this.replaceMessage(currentMessageIndex, currentMessage, response);
|
|
13369
|
+
};
|
|
13370
|
+
var mergeCallProviderMetadata = function mergeCallProviderMetadata(toolCallId, metadata) {
|
|
13371
|
+
var toolIndex = findToolPart(toolCallId);
|
|
13372
|
+
if (toolIndex < 0) return;
|
|
13373
|
+
var existingPart = currentMessage.parts[toolIndex];
|
|
13374
|
+
setPart(toolIndex, _object_spread_props(_object_spread({}, existingPart), {
|
|
13375
|
+
callProviderMetadata: metadata !== null && metadata !== void 0 ? metadata : existingPart.callProviderMetadata
|
|
13376
|
+
}));
|
|
13377
|
+
};
|
|
13378
|
+
var getCanonicalMessage = function getCanonicalMessage() {
|
|
13379
|
+
var _this_messages_find;
|
|
13380
|
+
return response.messageId ? (_this_messages_find = _this.messages.find(function(message) {
|
|
13381
|
+
return message.id === response.messageId;
|
|
13382
|
+
})) !== null && _this_messages_find !== void 0 ? _this_messages_find : currentMessage : currentMessage;
|
|
13383
|
+
};
|
|
13384
|
+
var notifyFinish = function notifyFinish(param) {
|
|
13385
|
+
var isAbort = param.isAbort, isDisconnect = param.isDisconnect, isError = param.isError, message = param.message, _param_allowRetired = param.allowRetired, allowRetired = _param_allowRetired === void 0 ? false : _param_allowRetired;
|
|
13386
|
+
_this.pruneDetachedResponse(response);
|
|
13387
|
+
if (response.isRetired && !allowRetired || response.didNotifyFinish) {
|
|
13388
|
+
return;
|
|
13389
|
+
}
|
|
13390
|
+
response.didNotifyFinish = true;
|
|
13391
|
+
var canonicalMessage = message !== null && message !== void 0 ? message : getCanonicalMessage();
|
|
13392
|
+
if (_this.onFinish && canonicalMessage) {
|
|
13393
|
+
_this.onFinish({
|
|
13394
|
+
message: canonicalMessage,
|
|
13395
|
+
messages: _this.messages,
|
|
13396
|
+
isAbort: isAbort,
|
|
13397
|
+
isDisconnect: isDisconnect,
|
|
13398
|
+
isError: isError
|
|
13399
|
+
});
|
|
13400
|
+
}
|
|
13401
|
+
};
|
|
13402
|
+
var failToolCall = function failToolCall(reason) {
|
|
13403
|
+
if (response.outcome !== 'active') return;
|
|
13404
|
+
var message = getCanonicalMessage();
|
|
13405
|
+
var wasRetired = response.isRetired;
|
|
13406
|
+
var error = _instanceof(reason, Error) ? reason : new Error(String(reason));
|
|
13407
|
+
response.outcome = 'failed';
|
|
13408
|
+
response.abortController.abort();
|
|
13409
|
+
if (_this.activeResponse === response) {
|
|
13410
|
+
_this.activeResponse = null;
|
|
13411
|
+
_this.handleError(error);
|
|
13412
|
+
}
|
|
13413
|
+
notifyFinish({
|
|
13414
|
+
isAbort: false,
|
|
13415
|
+
isDisconnect: false,
|
|
13416
|
+
isError: true,
|
|
13417
|
+
message: message,
|
|
13418
|
+
allowRetired: !wasRetired
|
|
13419
|
+
});
|
|
13420
|
+
};
|
|
13421
|
+
var acceptServerToolResult = function acceptServerToolResult(toolCallId) {
|
|
13422
|
+
if (response.requiredToolCallIds.has(toolCallId)) {
|
|
13423
|
+
response.resolvedToolCallIds.add(toolCallId);
|
|
13424
|
+
}
|
|
13425
|
+
};
|
|
13047
13426
|
return new Promise(function(resolve) {
|
|
13427
|
+
var finish = function finish(error) {
|
|
13428
|
+
if (response.outcome === 'failed') {
|
|
13429
|
+
resolve();
|
|
13430
|
+
return;
|
|
13431
|
+
}
|
|
13432
|
+
isAbort || (isAbort = response.outcome === 'aborted' || !!error && error.name === 'AbortError');
|
|
13433
|
+
response.outcome = isAbort ? 'aborted' : error ? 'failed' : 'succeeded';
|
|
13434
|
+
if (_this.activeResponse === response) {
|
|
13435
|
+
_this.activeResponse = null;
|
|
13436
|
+
if (error && !isAbort) {
|
|
13437
|
+
_this.handleError(error);
|
|
13438
|
+
} else {
|
|
13439
|
+
_this.setStatus({
|
|
13440
|
+
status: 'ready'
|
|
13441
|
+
});
|
|
13442
|
+
}
|
|
13443
|
+
}
|
|
13444
|
+
notifyFinish({
|
|
13445
|
+
isAbort: isAbort,
|
|
13446
|
+
isDisconnect: !!error && !isAbort,
|
|
13447
|
+
isError: isError
|
|
13448
|
+
});
|
|
13449
|
+
resolve(isAbort || error ? undefined : _this.continueResponse(response));
|
|
13450
|
+
};
|
|
13048
13451
|
processStream(stream, function(chunk) {
|
|
13452
|
+
if (_this.activeResponse !== response || response.isRetired) return;
|
|
13453
|
+
if (currentMessageId) {
|
|
13454
|
+
var canonicalMessageIndex = _this.messages.findIndex(function(message) {
|
|
13455
|
+
return message.id === currentMessageId;
|
|
13456
|
+
});
|
|
13457
|
+
if (canonicalMessageIndex === -1) {
|
|
13458
|
+
_this.pruneDetachedResponse(response);
|
|
13459
|
+
return;
|
|
13460
|
+
}
|
|
13461
|
+
currentMessageIndex = canonicalMessageIndex;
|
|
13462
|
+
currentMessage = _this.messages[canonicalMessageIndex];
|
|
13463
|
+
_this.responseByMessage.set(currentMessage, response);
|
|
13464
|
+
}
|
|
13049
13465
|
switch(chunk.type){
|
|
13050
13466
|
case 'start':
|
|
13051
13467
|
{
|
|
13052
13468
|
currentMessageId = chunk.messageId || _this.generateId();
|
|
13469
|
+
response.messageId = currentMessageId;
|
|
13053
13470
|
// Check if we're continuing an existing message or creating a new one
|
|
13054
13471
|
var lastMessage = _this.lastMessage;
|
|
13055
13472
|
if (lastMessage && lastMessage.role === 'assistant' && lastMessage.id === currentMessageId) {
|
|
13056
|
-
|
|
13057
|
-
|
|
13473
|
+
if (lastMessage.parts.some(function(part) {
|
|
13474
|
+
return 'toolCallId' in part;
|
|
13475
|
+
})) {
|
|
13476
|
+
_this.acceptsIdentifierOnlyToolResults = false;
|
|
13477
|
+
}
|
|
13478
|
+
currentMessage = _object_spread_props(_object_spread({}, lastMessage), {
|
|
13479
|
+
parts: _to_consumable_array(lastMessage.parts)
|
|
13480
|
+
});
|
|
13481
|
+
currentMessageIndex = _this.messages.length - 1;
|
|
13482
|
+
currentMessage = _this.replaceMessage(currentMessageIndex, currentMessage, response);
|
|
13058
13483
|
} else {
|
|
13059
13484
|
currentMessage = {
|
|
13060
13485
|
id: currentMessageId,
|
|
@@ -13063,123 +13488,60 @@
|
|
|
13063
13488
|
metadata: chunk.messageMetadata
|
|
13064
13489
|
};
|
|
13065
13490
|
_this.state.pushMessage(currentMessage);
|
|
13066
|
-
currentMessageIndex = _this.
|
|
13491
|
+
currentMessageIndex = _this.messages.length - 1;
|
|
13492
|
+
_this.responseByMessage.set(currentMessage, response);
|
|
13067
13493
|
}
|
|
13068
13494
|
break;
|
|
13069
13495
|
}
|
|
13070
13496
|
case 'text-start':
|
|
13497
|
+
case 'reasoning-start':
|
|
13071
13498
|
{
|
|
13072
13499
|
if (!currentMessage) break;
|
|
13073
|
-
|
|
13074
|
-
|
|
13075
|
-
type:
|
|
13500
|
+
var type = chunk.type === 'text-start' ? 'text' : 'reasoning';
|
|
13501
|
+
setPart(-1, {
|
|
13502
|
+
type: type,
|
|
13076
13503
|
text: '',
|
|
13077
13504
|
state: 'streaming',
|
|
13078
13505
|
providerMetadata: chunk.providerMetadata
|
|
13079
|
-
};
|
|
13080
|
-
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13081
|
-
parts: _to_consumable_array(currentMessage.parts).concat([
|
|
13082
|
-
textPart
|
|
13083
|
-
])
|
|
13084
13506
|
});
|
|
13085
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13086
13507
|
break;
|
|
13087
13508
|
}
|
|
13088
13509
|
case 'text-delta':
|
|
13510
|
+
case 'reasoning-delta':
|
|
13089
13511
|
{
|
|
13090
|
-
|
|
13091
|
-
|
|
13092
|
-
|
|
13512
|
+
var type1 = chunk.type === 'text-delta' ? 'text' : 'reasoning';
|
|
13513
|
+
if (!currentMessage) break;
|
|
13514
|
+
var partIndex = currentMessage.parts.findIndex(function(part) {
|
|
13515
|
+
return part.type === type1 && part.state === 'streaming';
|
|
13093
13516
|
});
|
|
13094
13517
|
if (partIndex === -1) break;
|
|
13095
|
-
var
|
|
13096
|
-
|
|
13097
|
-
|
|
13098
|
-
|
|
13099
|
-
});
|
|
13100
|
-
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13101
|
-
parts: updatedParts
|
|
13102
|
-
});
|
|
13103
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13518
|
+
var part = currentMessage.parts[partIndex];
|
|
13519
|
+
setPart(partIndex, _object_spread_props(_object_spread({}, part), {
|
|
13520
|
+
text: part.text + chunk.delta
|
|
13521
|
+
}));
|
|
13104
13522
|
break;
|
|
13105
13523
|
}
|
|
13106
13524
|
case 'text-end':
|
|
13107
|
-
{
|
|
13108
|
-
if (!currentMessage) break;
|
|
13109
|
-
var partIndex1 = currentMessage.parts.findIndex(function(p) {
|
|
13110
|
-
return p.type === 'text' && p.state === 'streaming';
|
|
13111
|
-
});
|
|
13112
|
-
if (partIndex1 === -1) break;
|
|
13113
|
-
var updatedParts1 = _to_consumable_array(currentMessage.parts);
|
|
13114
|
-
var textPart2 = updatedParts1[partIndex1];
|
|
13115
|
-
updatedParts1[partIndex1] = _object_spread_props(_object_spread({}, textPart2), {
|
|
13116
|
-
state: 'done'
|
|
13117
|
-
});
|
|
13118
|
-
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13119
|
-
parts: updatedParts1
|
|
13120
|
-
});
|
|
13121
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13122
|
-
currentTextPartId = undefined;
|
|
13123
|
-
break;
|
|
13124
|
-
}
|
|
13125
|
-
case 'reasoning-start':
|
|
13126
|
-
{
|
|
13127
|
-
if (!currentMessage) break;
|
|
13128
|
-
currentReasoningPartId = chunk.id;
|
|
13129
|
-
var reasoningPart = {
|
|
13130
|
-
type: 'reasoning',
|
|
13131
|
-
text: '',
|
|
13132
|
-
state: 'streaming',
|
|
13133
|
-
providerMetadata: chunk.providerMetadata
|
|
13134
|
-
};
|
|
13135
|
-
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13136
|
-
parts: _to_consumable_array(currentMessage.parts).concat([
|
|
13137
|
-
reasoningPart
|
|
13138
|
-
])
|
|
13139
|
-
});
|
|
13140
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13141
|
-
break;
|
|
13142
|
-
}
|
|
13143
|
-
case 'reasoning-delta':
|
|
13144
|
-
{
|
|
13145
|
-
if (!currentMessage || !currentReasoningPartId) break;
|
|
13146
|
-
var partIndex2 = currentMessage.parts.findIndex(function(p) {
|
|
13147
|
-
return p.type === 'reasoning' && p.state === 'streaming';
|
|
13148
|
-
});
|
|
13149
|
-
if (partIndex2 === -1) break;
|
|
13150
|
-
var updatedParts2 = _to_consumable_array(currentMessage.parts);
|
|
13151
|
-
var reasoningPart1 = updatedParts2[partIndex2];
|
|
13152
|
-
updatedParts2[partIndex2] = _object_spread_props(_object_spread({}, reasoningPart1), {
|
|
13153
|
-
text: reasoningPart1.text + chunk.delta
|
|
13154
|
-
});
|
|
13155
|
-
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13156
|
-
parts: updatedParts2
|
|
13157
|
-
});
|
|
13158
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13159
|
-
break;
|
|
13160
|
-
}
|
|
13161
13525
|
case 'reasoning-end':
|
|
13162
13526
|
{
|
|
13163
13527
|
if (!currentMessage) break;
|
|
13164
|
-
var
|
|
13165
|
-
|
|
13528
|
+
var type2 = chunk.type === 'text-end' ? 'text' : 'reasoning';
|
|
13529
|
+
var partIndex1 = currentMessage.parts.findIndex(function(part) {
|
|
13530
|
+
return part.type === type2 && part.state === 'streaming';
|
|
13166
13531
|
});
|
|
13167
|
-
if (
|
|
13168
|
-
|
|
13169
|
-
var reasoningPart2 = updatedParts3[partIndex3];
|
|
13170
|
-
updatedParts3[partIndex3] = _object_spread_props(_object_spread({}, reasoningPart2), {
|
|
13532
|
+
if (partIndex1 === -1) break;
|
|
13533
|
+
setPart(partIndex1, _object_spread_props(_object_spread({}, currentMessage.parts[partIndex1]), {
|
|
13171
13534
|
state: 'done'
|
|
13172
|
-
});
|
|
13173
|
-
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13174
|
-
parts: updatedParts3
|
|
13175
|
-
});
|
|
13176
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13177
|
-
currentReasoningPartId = undefined;
|
|
13535
|
+
}));
|
|
13178
13536
|
break;
|
|
13179
13537
|
}
|
|
13180
13538
|
case 'tool-input-start':
|
|
13181
13539
|
{
|
|
13182
13540
|
if (!currentMessage) break;
|
|
13541
|
+
var completedPart = currentMessage.parts.find(function(part) {
|
|
13542
|
+
return 'toolCallId' in part && part.toolCallId === chunk.toolCallId && 'state' in part && (part.state === 'output-available' || part.state === 'output-error');
|
|
13543
|
+
});
|
|
13544
|
+
if (completedPart) break;
|
|
13183
13545
|
var initialRawInput = typeof chunk.input === 'string' ? chunk.input : chunk.input !== undefined ? JSON.stringify(chunk.input) : '';
|
|
13184
13546
|
toolRawInputByCallId[chunk.toolCallId] = initialRawInput;
|
|
13185
13547
|
var toolPart = {
|
|
@@ -13190,12 +13552,7 @@
|
|
|
13190
13552
|
rawInput: initialRawInput || undefined,
|
|
13191
13553
|
providerExecuted: chunk.providerExecuted
|
|
13192
13554
|
};
|
|
13193
|
-
|
|
13194
|
-
parts: _to_consumable_array(currentMessage.parts).concat([
|
|
13195
|
-
toolPart
|
|
13196
|
-
])
|
|
13197
|
-
});
|
|
13198
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13555
|
+
setPart(-1, toolPart);
|
|
13199
13556
|
break;
|
|
13200
13557
|
}
|
|
13201
13558
|
case 'tool-input-delta':
|
|
@@ -13203,16 +13560,17 @@
|
|
|
13203
13560
|
var _ref, _ref1, _chunk_toolName, _ref2;
|
|
13204
13561
|
var _existingPart_type, _this_shouldRepairToolInput, _this1;
|
|
13205
13562
|
if (!currentMessage) break;
|
|
13206
|
-
var toolIndex =
|
|
13207
|
-
return 'toolCallId' in p && p.toolCallId === chunk.toolCallId;
|
|
13208
|
-
});
|
|
13563
|
+
var toolIndex = findToolPart(chunk.toolCallId);
|
|
13209
13564
|
var existingPart = toolIndex >= 0 ? currentMessage.parts[toolIndex] : null;
|
|
13565
|
+
if ((existingPart === null || existingPart === void 0 ? void 0 : existingPart.state) === 'output-available' || (existingPart === null || existingPart === void 0 ? void 0 : existingPart.state) === 'output-error') {
|
|
13566
|
+
break;
|
|
13567
|
+
}
|
|
13210
13568
|
var previousRawInput = (_ref = (_ref1 = existingPart === null || existingPart === void 0 ? void 0 : existingPart.rawInput) !== null && _ref1 !== void 0 ? _ref1 : toolRawInputByCallId[chunk.toolCallId]) !== null && _ref !== void 0 ? _ref : '';
|
|
13211
13569
|
var nextRawInput = "".concat(previousRawInput).concat(chunk.inputTextDelta);
|
|
13212
13570
|
toolRawInputByCallId[chunk.toolCallId] = nextRawInput;
|
|
13213
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-', '');
|
|
13214
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;
|
|
13215
|
-
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;
|
|
13216
13574
|
var nextToolPart = _object_spread_props(_object_spread({}, existingPart !== null && existingPart !== void 0 ? existingPart : {
|
|
13217
13575
|
type: "tool-".concat(chunk.toolName),
|
|
13218
13576
|
toolCallId: chunk.toolCallId
|
|
@@ -13221,30 +13579,20 @@
|
|
|
13221
13579
|
input: parsedInput,
|
|
13222
13580
|
rawInput: nextRawInput
|
|
13223
13581
|
});
|
|
13224
|
-
|
|
13225
|
-
var updatedParts4 = _to_consumable_array(currentMessage.parts);
|
|
13226
|
-
updatedParts4[toolIndex] = nextToolPart;
|
|
13227
|
-
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13228
|
-
parts: updatedParts4
|
|
13229
|
-
});
|
|
13230
|
-
} else {
|
|
13231
|
-
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13232
|
-
parts: _to_consumable_array(currentMessage.parts).concat([
|
|
13233
|
-
nextToolPart
|
|
13234
|
-
])
|
|
13235
|
-
});
|
|
13236
|
-
}
|
|
13237
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13582
|
+
setPart(toolIndex, nextToolPart);
|
|
13238
13583
|
break;
|
|
13239
13584
|
}
|
|
13240
13585
|
case 'tool-input-available':
|
|
13241
13586
|
{
|
|
13242
13587
|
if (!currentMessage) break;
|
|
13588
|
+
if (response.requiredToolCallIds.has(chunk.toolCallId)) break;
|
|
13243
13589
|
delete toolRawInputByCallId[chunk.toolCallId];
|
|
13244
13590
|
// Find existing tool part or create new one
|
|
13245
|
-
var existingIndex =
|
|
13246
|
-
|
|
13247
|
-
|
|
13591
|
+
var existingIndex = findToolPart(chunk.toolCallId);
|
|
13592
|
+
var existingPart1 = existingIndex >= 0 ? currentMessage.parts[existingIndex] : null;
|
|
13593
|
+
if ((existingPart1 === null || existingPart1 === void 0 ? void 0 : existingPart1.state) === 'output-available' || (existingPart1 === null || existingPart1 === void 0 ? void 0 : existingPart1.state) === 'output-error') {
|
|
13594
|
+
break;
|
|
13595
|
+
}
|
|
13248
13596
|
var toolPart1 = {
|
|
13249
13597
|
type: "tool-".concat(chunk.toolName),
|
|
13250
13598
|
toolCallId: chunk.toolCallId,
|
|
@@ -13253,35 +13601,63 @@
|
|
|
13253
13601
|
callProviderMetadata: chunk.callProviderMetadata,
|
|
13254
13602
|
providerExecuted: chunk.providerExecuted
|
|
13255
13603
|
};
|
|
13256
|
-
|
|
13257
|
-
|
|
13258
|
-
|
|
13259
|
-
currentMessage
|
|
13260
|
-
|
|
13261
|
-
});
|
|
13262
|
-
}
|
|
13263
|
-
|
|
13264
|
-
parts: _to_consumable_array(currentMessage.parts).concat([
|
|
13265
|
-
toolPart1
|
|
13266
|
-
])
|
|
13267
|
-
});
|
|
13604
|
+
setPart(existingIndex, toolPart1);
|
|
13605
|
+
if (_this.messages.some(function(message) {
|
|
13606
|
+
var _message_parts;
|
|
13607
|
+
return message !== currentMessage && ((_message_parts = message.parts) === null || _message_parts === void 0 ? void 0 : _message_parts.some(function(part) {
|
|
13608
|
+
return 'toolCallId' in part && part.toolCallId === chunk.toolCallId;
|
|
13609
|
+
}));
|
|
13610
|
+
})) {
|
|
13611
|
+
_this.acceptsIdentifierOnlyToolResults = false;
|
|
13268
13612
|
}
|
|
13269
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13270
13613
|
// Trigger onToolCall callback only for client-executed tools
|
|
13271
13614
|
// (server-executed tools have providerExecuted: true and don't need client handling)
|
|
13272
13615
|
if (_this.onToolCall && !chunk.providerExecuted) {
|
|
13273
|
-
var
|
|
13274
|
-
|
|
13275
|
-
|
|
13276
|
-
|
|
13277
|
-
input: chunk.input,
|
|
13278
|
-
dynamic: 'dynamic' in chunk ? chunk.dynamic : undefined
|
|
13279
|
-
}
|
|
13616
|
+
var _this_responsesByToolCallId_get;
|
|
13617
|
+
var owners = (_this_responsesByToolCallId_get = _this.responsesByToolCallId.get(chunk.toolCallId)) !== null && _this_responsesByToolCallId_get !== void 0 ? _this_responsesByToolCallId_get : new Set();
|
|
13618
|
+
var existingOwners = Array.from(owners).filter(function(owner) {
|
|
13619
|
+
return owner !== response;
|
|
13280
13620
|
});
|
|
13281
|
-
if (
|
|
13282
|
-
|
|
13283
|
-
|
|
13621
|
+
if (existingOwners.length > 0) {
|
|
13622
|
+
_this.acceptsIdentifierOnlyToolResults = false;
|
|
13623
|
+
var conflictingOwner = existingOwners.find(function(owner) {
|
|
13624
|
+
return !owner.isRetired && (owner.outcome === 'active' || owner.outcome === 'succeeded' && (!owner.resolvedToolCallIds.has(chunk.toolCallId) || owner.pendingToolCallbacks > 0));
|
|
13284
13625
|
});
|
|
13626
|
+
if (conflictingOwner) {
|
|
13627
|
+
// Neither response may continue once ownership is ambiguous.
|
|
13628
|
+
conflictingOwner.didEvaluateContinuation = true;
|
|
13629
|
+
failToolCall(new Error('Tool call "'.concat(chunk.toolCallId, '" is already owned by another response.')));
|
|
13630
|
+
break;
|
|
13631
|
+
}
|
|
13632
|
+
}
|
|
13633
|
+
response.requiredToolCallIds.add(chunk.toolCallId);
|
|
13634
|
+
owners.add(response);
|
|
13635
|
+
_this.responsesByToolCallId.set(chunk.toolCallId, owners);
|
|
13636
|
+
response.pendingToolCallbacks++;
|
|
13637
|
+
try {
|
|
13638
|
+
var result = _this.onToolCall({
|
|
13639
|
+
toolCall: {
|
|
13640
|
+
toolName: chunk.toolName,
|
|
13641
|
+
toolCallId: chunk.toolCallId,
|
|
13642
|
+
input: chunk.input,
|
|
13643
|
+
dynamic: 'dynamic' in chunk ? chunk.dynamic : undefined
|
|
13644
|
+
}
|
|
13645
|
+
}, function(options) {
|
|
13646
|
+
return response.isRetired ? Promise.resolve() : _this.submitToolResult(response, options);
|
|
13647
|
+
});
|
|
13648
|
+
if (result) {
|
|
13649
|
+
response.returnedToolCallbacks.push(Promise.resolve(result).catch(failToolCall).then(function() {
|
|
13650
|
+
response.pendingToolCallbacks--;
|
|
13651
|
+
_this.pruneDetachedResponse(response);
|
|
13652
|
+
}));
|
|
13653
|
+
} else {
|
|
13654
|
+
response.pendingToolCallbacks--;
|
|
13655
|
+
_this.pruneDetachedResponse(response);
|
|
13656
|
+
}
|
|
13657
|
+
} catch (error) {
|
|
13658
|
+
response.pendingToolCallbacks--;
|
|
13659
|
+
failToolCall(error);
|
|
13660
|
+
_this.pruneDetachedResponse(response);
|
|
13285
13661
|
}
|
|
13286
13662
|
}
|
|
13287
13663
|
break;
|
|
@@ -13291,15 +13667,14 @@
|
|
|
13291
13667
|
var _ref3, _ref4;
|
|
13292
13668
|
if (!currentMessage) break;
|
|
13293
13669
|
var _chunk_data = chunk.data, toolCallId = _chunk_data.toolCallId, toolName1 = _chunk_data.toolName, delta = _chunk_data.delta;
|
|
13294
|
-
|
|
13295
|
-
|
|
13296
|
-
|
|
13297
|
-
var
|
|
13298
|
-
var previousRawOutput = (_ref3 = (_ref4 = existingPart1 === null || existingPart1 === void 0 ? void 0 : existingPart1.rawOutput) !== null && _ref4 !== void 0 ? _ref4 : toolRawOutputByCallId[toolCallId]) !== null && _ref3 !== void 0 ? _ref3 : '';
|
|
13670
|
+
if (response.resolvedToolCallIds.has(toolCallId)) break;
|
|
13671
|
+
var toolIndex1 = findToolPart(toolCallId);
|
|
13672
|
+
var existingPart2 = toolIndex1 >= 0 ? currentMessage.parts[toolIndex1] : null;
|
|
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 : '';
|
|
13299
13674
|
var nextRawOutput = "".concat(previousRawOutput).concat(delta);
|
|
13300
13675
|
toolRawOutputByCallId[toolCallId] = nextRawOutput;
|
|
13301
|
-
var parsedOutput =
|
|
13302
|
-
var nextToolPart1 = _object_spread_props(_object_spread({},
|
|
13676
|
+
var parsedOutput = parsePartialJson(nextRawOutput, existingPart2 === null || existingPart2 === void 0 ? void 0 : existingPart2.output);
|
|
13677
|
+
var nextToolPart1 = _object_spread_props(_object_spread({}, existingPart2 !== null && existingPart2 !== void 0 ? existingPart2 : {
|
|
13303
13678
|
type: "tool-".concat(toolName1),
|
|
13304
13679
|
toolCallId: toolCallId,
|
|
13305
13680
|
input: undefined
|
|
@@ -13309,47 +13684,34 @@
|
|
|
13309
13684
|
rawOutput: nextRawOutput,
|
|
13310
13685
|
preliminary: true
|
|
13311
13686
|
});
|
|
13312
|
-
|
|
13313
|
-
var updatedParts6 = _to_consumable_array(currentMessage.parts);
|
|
13314
|
-
updatedParts6[toolIndex1] = nextToolPart1;
|
|
13315
|
-
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13316
|
-
parts: updatedParts6
|
|
13317
|
-
});
|
|
13318
|
-
} else {
|
|
13319
|
-
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13320
|
-
parts: _to_consumable_array(currentMessage.parts).concat([
|
|
13321
|
-
nextToolPart1
|
|
13322
|
-
])
|
|
13323
|
-
});
|
|
13324
|
-
}
|
|
13325
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13687
|
+
setPart(toolIndex1, nextToolPart1);
|
|
13326
13688
|
break;
|
|
13327
13689
|
}
|
|
13328
13690
|
case 'tool-output-available':
|
|
13329
13691
|
{
|
|
13330
13692
|
if (!currentMessage) break;
|
|
13331
|
-
var toolIndex2 =
|
|
13332
|
-
return 'toolCallId' in p && p.toolCallId === chunk.toolCallId;
|
|
13333
|
-
});
|
|
13693
|
+
var toolIndex2 = findToolPart(chunk.toolCallId);
|
|
13334
13694
|
if (toolIndex2 >= 0) {
|
|
13335
13695
|
delete toolRawInputByCallId[chunk.toolCallId];
|
|
13336
13696
|
delete toolRawOutputByCallId[chunk.toolCallId];
|
|
13337
|
-
var
|
|
13338
|
-
|
|
13697
|
+
var existingPart3 = currentMessage.parts[toolIndex2];
|
|
13698
|
+
if (response.resolvedToolCallIds.has(chunk.toolCallId)) {
|
|
13699
|
+
mergeCallProviderMetadata(chunk.toolCallId, chunk.callProviderMetadata);
|
|
13700
|
+
break;
|
|
13701
|
+
}
|
|
13339
13702
|
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
13340
|
-
var _ignored =
|
|
13703
|
+
var _ignored = existingPart3.rawOutput, rest = _object_without_properties(existingPart3, [
|
|
13341
13704
|
"rawOutput"
|
|
13342
13705
|
]);
|
|
13343
|
-
|
|
13706
|
+
setPart(toolIndex2, _object_spread_props(_object_spread({}, rest), {
|
|
13344
13707
|
state: 'output-available',
|
|
13345
13708
|
output: chunk.output,
|
|
13346
13709
|
callProviderMetadata: chunk.callProviderMetadata,
|
|
13347
13710
|
preliminary: chunk.preliminary
|
|
13348
|
-
});
|
|
13349
|
-
|
|
13350
|
-
|
|
13351
|
-
}
|
|
13352
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13711
|
+
}));
|
|
13712
|
+
if (!chunk.preliminary) {
|
|
13713
|
+
acceptServerToolResult(chunk.toolCallId);
|
|
13714
|
+
}
|
|
13353
13715
|
}
|
|
13354
13716
|
break;
|
|
13355
13717
|
}
|
|
@@ -13357,13 +13719,15 @@
|
|
|
13357
13719
|
{
|
|
13358
13720
|
var _chunk_input, _chunk_providerExecuted, _chunk_providerMetadata;
|
|
13359
13721
|
if (!currentMessage) break;
|
|
13722
|
+
if (response.resolvedToolCallIds.has(chunk.toolCallId)) {
|
|
13723
|
+
mergeCallProviderMetadata(chunk.toolCallId, chunk.providerMetadata);
|
|
13724
|
+
break;
|
|
13725
|
+
}
|
|
13360
13726
|
delete toolRawInputByCallId[chunk.toolCallId];
|
|
13361
13727
|
delete toolRawOutputByCallId[chunk.toolCallId];
|
|
13362
|
-
var toolIndex3 =
|
|
13363
|
-
|
|
13364
|
-
}
|
|
13365
|
-
var existingPart3 = toolIndex3 >= 0 ? currentMessage.parts[toolIndex3] : null;
|
|
13366
|
-
var _ref5 = existingPart3 !== null && existingPart3 !== void 0 ? existingPart3 : {}, _ignoredOutput = _ref5.output, _ignoredRawOutput = _ref5.rawOutput, _ignoredPreliminary = _ref5.preliminary, carryOver = _object_without_properties(_ref5, [
|
|
13728
|
+
var toolIndex3 = findToolPart(chunk.toolCallId);
|
|
13729
|
+
var existingPart4 = toolIndex3 >= 0 ? currentMessage.parts[toolIndex3] : null;
|
|
13730
|
+
var _ref5 = existingPart4 !== null && existingPart4 !== void 0 ? existingPart4 : {}, _ignoredOutput = _ref5.output, _ignoredRawOutput = _ref5.rawOutput, _ignoredPreliminary = _ref5.preliminary, carryOver = _object_without_properties(_ref5, [
|
|
13367
13731
|
"output",
|
|
13368
13732
|
"rawOutput",
|
|
13369
13733
|
"preliminary"
|
|
@@ -13378,49 +13742,35 @@
|
|
|
13378
13742
|
providerExecuted: (_chunk_providerExecuted = chunk.providerExecuted) !== null && _chunk_providerExecuted !== void 0 ? _chunk_providerExecuted : carryOver.providerExecuted,
|
|
13379
13743
|
callProviderMetadata: (_chunk_providerMetadata = chunk.providerMetadata) !== null && _chunk_providerMetadata !== void 0 ? _chunk_providerMetadata : carryOver.callProviderMetadata
|
|
13380
13744
|
});
|
|
13381
|
-
|
|
13382
|
-
|
|
13383
|
-
updatedParts8[toolIndex3] = nextToolPart2;
|
|
13384
|
-
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13385
|
-
parts: updatedParts8
|
|
13386
|
-
});
|
|
13387
|
-
} else {
|
|
13388
|
-
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13389
|
-
parts: _to_consumable_array(currentMessage.parts).concat([
|
|
13390
|
-
nextToolPart2
|
|
13391
|
-
])
|
|
13392
|
-
});
|
|
13393
|
-
}
|
|
13394
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13745
|
+
setPart(toolIndex3, nextToolPart2);
|
|
13746
|
+
acceptServerToolResult(chunk.toolCallId);
|
|
13395
13747
|
break;
|
|
13396
13748
|
}
|
|
13397
13749
|
case 'tool-output-error':
|
|
13398
13750
|
{
|
|
13399
13751
|
var _chunk_providerExecuted1, _chunk_providerMetadata1;
|
|
13400
13752
|
if (!currentMessage) break;
|
|
13401
|
-
|
|
13402
|
-
|
|
13403
|
-
|
|
13753
|
+
if (response.resolvedToolCallIds.has(chunk.toolCallId)) {
|
|
13754
|
+
mergeCallProviderMetadata(chunk.toolCallId, chunk.providerMetadata);
|
|
13755
|
+
break;
|
|
13756
|
+
}
|
|
13757
|
+
var toolIndex4 = findToolPart(chunk.toolCallId);
|
|
13404
13758
|
if (toolIndex4 < 0) break;
|
|
13405
13759
|
delete toolRawInputByCallId[chunk.toolCallId];
|
|
13406
13760
|
delete toolRawOutputByCallId[chunk.toolCallId];
|
|
13407
|
-
var
|
|
13408
|
-
var
|
|
13409
|
-
var _ignoredRawOutput1 = existingPart4.rawOutput, _ignoredPreliminary1 = existingPart4.preliminary, _ignoredOutput1 = existingPart4.output, rest1 = _object_without_properties(existingPart4, [
|
|
13761
|
+
var existingPart5 = currentMessage.parts[toolIndex4];
|
|
13762
|
+
var _ignoredRawOutput1 = existingPart5.rawOutput, _ignoredPreliminary1 = existingPart5.preliminary, _ignoredOutput1 = existingPart5.output, rest1 = _object_without_properties(existingPart5, [
|
|
13410
13763
|
"rawOutput",
|
|
13411
13764
|
"preliminary",
|
|
13412
13765
|
"output"
|
|
13413
13766
|
]);
|
|
13414
|
-
|
|
13767
|
+
setPart(toolIndex4, _object_spread_props(_object_spread({}, rest1), {
|
|
13415
13768
|
state: 'output-error',
|
|
13416
13769
|
errorText: chunk.errorText,
|
|
13417
13770
|
providerExecuted: (_chunk_providerExecuted1 = chunk.providerExecuted) !== null && _chunk_providerExecuted1 !== void 0 ? _chunk_providerExecuted1 : rest1.providerExecuted,
|
|
13418
13771
|
callProviderMetadata: (_chunk_providerMetadata1 = chunk.providerMetadata) !== null && _chunk_providerMetadata1 !== void 0 ? _chunk_providerMetadata1 : rest1.callProviderMetadata
|
|
13419
|
-
});
|
|
13420
|
-
|
|
13421
|
-
parts: updatedParts9
|
|
13422
|
-
});
|
|
13423
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13772
|
+
}));
|
|
13773
|
+
acceptServerToolResult(chunk.toolCallId);
|
|
13424
13774
|
break;
|
|
13425
13775
|
}
|
|
13426
13776
|
case 'source-url':
|
|
@@ -13432,12 +13782,7 @@
|
|
|
13432
13782
|
url: chunk.url,
|
|
13433
13783
|
title: chunk.title
|
|
13434
13784
|
};
|
|
13435
|
-
|
|
13436
|
-
parts: _to_consumable_array(currentMessage.parts).concat([
|
|
13437
|
-
sourcePart
|
|
13438
|
-
])
|
|
13439
|
-
});
|
|
13440
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13785
|
+
setPart(-1, sourcePart);
|
|
13441
13786
|
break;
|
|
13442
13787
|
}
|
|
13443
13788
|
case 'source-document':
|
|
@@ -13451,12 +13796,7 @@
|
|
|
13451
13796
|
filename: chunk.filename,
|
|
13452
13797
|
providerMetadata: chunk.providerMetadata
|
|
13453
13798
|
};
|
|
13454
|
-
|
|
13455
|
-
parts: _to_consumable_array(currentMessage.parts).concat([
|
|
13456
|
-
docPart
|
|
13457
|
-
])
|
|
13458
|
-
});
|
|
13459
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13799
|
+
setPart(-1, docPart);
|
|
13460
13800
|
break;
|
|
13461
13801
|
}
|
|
13462
13802
|
case 'file':
|
|
@@ -13467,26 +13807,15 @@
|
|
|
13467
13807
|
url: chunk.url,
|
|
13468
13808
|
mediaType: chunk.mediaType
|
|
13469
13809
|
};
|
|
13470
|
-
|
|
13471
|
-
parts: _to_consumable_array(currentMessage.parts).concat([
|
|
13472
|
-
filePart
|
|
13473
|
-
])
|
|
13474
|
-
});
|
|
13475
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13810
|
+
setPart(-1, filePart);
|
|
13476
13811
|
break;
|
|
13477
13812
|
}
|
|
13478
13813
|
case 'start-step':
|
|
13479
13814
|
{
|
|
13480
13815
|
if (!currentMessage) break;
|
|
13481
|
-
|
|
13816
|
+
setPart(-1, {
|
|
13482
13817
|
type: 'step-start'
|
|
13483
|
-
};
|
|
13484
|
-
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13485
|
-
parts: _to_consumable_array(currentMessage.parts).concat([
|
|
13486
|
-
stepPart
|
|
13487
|
-
])
|
|
13488
13818
|
});
|
|
13489
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13490
13819
|
break;
|
|
13491
13820
|
}
|
|
13492
13821
|
case 'message-metadata':
|
|
@@ -13495,7 +13824,7 @@
|
|
|
13495
13824
|
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13496
13825
|
metadata: chunk.messageMetadata
|
|
13497
13826
|
});
|
|
13498
|
-
_this.
|
|
13827
|
+
currentMessage = _this.replaceMessage(currentMessageIndex, currentMessage, response);
|
|
13499
13828
|
break;
|
|
13500
13829
|
}
|
|
13501
13830
|
case 'error':
|
|
@@ -13515,7 +13844,7 @@
|
|
|
13515
13844
|
currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
|
|
13516
13845
|
metadata: chunk.messageMetadata
|
|
13517
13846
|
});
|
|
13518
|
-
_this.
|
|
13847
|
+
currentMessage = _this.replaceMessage(currentMessageIndex, currentMessage, response);
|
|
13519
13848
|
}
|
|
13520
13849
|
break;
|
|
13521
13850
|
}
|
|
@@ -13541,14 +13870,13 @@
|
|
|
13541
13870
|
]
|
|
13542
13871
|
};
|
|
13543
13872
|
if (currentMessageIndex >= 0) {
|
|
13544
|
-
_this.
|
|
13873
|
+
currentMessage = _this.replaceMessage(currentMessageIndex, currentMessage, response);
|
|
13545
13874
|
} else {
|
|
13546
13875
|
_this.state.pushMessage(currentMessage);
|
|
13547
|
-
currentMessageIndex = _this.
|
|
13876
|
+
currentMessageIndex = _this.messages.length - 1;
|
|
13877
|
+
_this.responseByMessage.set(currentMessage, response);
|
|
13548
13878
|
}
|
|
13549
13879
|
currentMessageId = currentMessage.id;
|
|
13550
|
-
currentTextPartId = undefined;
|
|
13551
|
-
currentReasoningPartId = undefined;
|
|
13552
13880
|
break;
|
|
13553
13881
|
}
|
|
13554
13882
|
default:
|
|
@@ -13561,12 +13889,7 @@
|
|
|
13561
13889
|
id: chunk.id,
|
|
13562
13890
|
data: chunk.data
|
|
13563
13891
|
};
|
|
13564
|
-
|
|
13565
|
-
parts: _to_consumable_array(currentMessage.parts).concat([
|
|
13566
|
-
dataPart
|
|
13567
|
-
])
|
|
13568
|
-
});
|
|
13569
|
-
_this.state.replaceMessage(currentMessageIndex, currentMessage);
|
|
13892
|
+
setPart(-1, dataPart);
|
|
13570
13893
|
// Trigger onData callback
|
|
13571
13894
|
if (_this.onData) {
|
|
13572
13895
|
_this.onData(dataPart);
|
|
@@ -13575,49 +13898,11 @@
|
|
|
13575
13898
|
}
|
|
13576
13899
|
}
|
|
13577
13900
|
}, function() {
|
|
13578
|
-
|
|
13579
|
-
|
|
13580
|
-
// Stream finished successfully
|
|
13581
|
-
_this.setStatus({
|
|
13582
|
-
status: 'ready'
|
|
13583
|
-
});
|
|
13584
|
-
_this.activeResponse = null;
|
|
13585
|
-
// Trigger onFinish callback
|
|
13586
|
-
if (_this.onFinish && currentMessage) {
|
|
13587
|
-
_this.onFinish({
|
|
13588
|
-
message: currentMessage,
|
|
13589
|
-
messages: _this.state.messages,
|
|
13590
|
-
isAbort: isAbort,
|
|
13591
|
-
isDisconnect: isDisconnect,
|
|
13592
|
-
isError: isError
|
|
13593
|
-
});
|
|
13594
|
-
}
|
|
13595
|
-
// Note: sendAutomaticallyWhen is only checked in addToolResult,
|
|
13596
|
-
// not here. For server-executed tools, the server continues the
|
|
13597
|
-
// conversation. For client-executed tools, addToolResult handles it.
|
|
13598
|
-
resolve();
|
|
13901
|
+
return Promise.all(response.returnedToolCallbacks).then(function() {
|
|
13902
|
+
return finish();
|
|
13599
13903
|
});
|
|
13600
13904
|
}, function(error) {
|
|
13601
|
-
|
|
13602
|
-
isAbort = true;
|
|
13603
|
-
_this.setStatus({
|
|
13604
|
-
status: 'ready'
|
|
13605
|
-
});
|
|
13606
|
-
} else {
|
|
13607
|
-
isDisconnect = true;
|
|
13608
|
-
_this.handleError(error);
|
|
13609
|
-
}
|
|
13610
|
-
// Still call onFinish even on error/abort
|
|
13611
|
-
if (_this.onFinish && currentMessage) {
|
|
13612
|
-
_this.onFinish({
|
|
13613
|
-
message: currentMessage,
|
|
13614
|
-
messages: _this.state.messages,
|
|
13615
|
-
isAbort: isAbort,
|
|
13616
|
-
isDisconnect: isDisconnect,
|
|
13617
|
-
isError: isError
|
|
13618
|
-
});
|
|
13619
|
-
}
|
|
13620
|
-
resolve();
|
|
13905
|
+
return finish(error);
|
|
13621
13906
|
});
|
|
13622
13907
|
});
|
|
13623
13908
|
}
|
|
@@ -13625,10 +13910,13 @@
|
|
|
13625
13910
|
{
|
|
13626
13911
|
key: "handleError",
|
|
13627
13912
|
value: function handleError(error) {
|
|
13628
|
-
|
|
13629
|
-
|
|
13630
|
-
|
|
13631
|
-
|
|
13913
|
+
var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, _ref_updateState = _ref.updateState, updateState = _ref_updateState === void 0 ? true : _ref_updateState;
|
|
13914
|
+
if (updateState) {
|
|
13915
|
+
this.setStatus({
|
|
13916
|
+
status: 'error',
|
|
13917
|
+
error: error
|
|
13918
|
+
});
|
|
13919
|
+
}
|
|
13632
13920
|
if (this.onError) {
|
|
13633
13921
|
this.onError(error);
|
|
13634
13922
|
}
|
|
@@ -13675,9 +13963,25 @@
|
|
|
13675
13963
|
|
|
13676
13964
|
var _computedKey, _computedKey1, _computedKey2, _computedKey3, _computedKey4, _computedKey5;
|
|
13677
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.
|
|
13678
13969
|
function getDefaultInitialMessages(id) {
|
|
13679
|
-
|
|
13680
|
-
|
|
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
|
+
});
|
|
13681
13985
|
}
|
|
13682
13986
|
_computedKey = '~registerMessagesCallback', _computedKey1 = '~registerStatusCallback', _computedKey2 = '~registerErrorCallback';
|
|
13683
13987
|
var _computedKey6 = _computedKey, _computedKey7 = _computedKey1, _computedKey8 = _computedKey2;
|
|
@@ -13756,11 +14060,13 @@
|
|
|
13756
14060
|
}
|
|
13757
14061
|
var saveMessagesInLocalStorage = function saveMessagesInLocalStorage() {
|
|
13758
14062
|
if (_this.status === 'ready') {
|
|
13759
|
-
|
|
13760
|
-
|
|
13761
|
-
|
|
13762
|
-
|
|
13763
|
-
|
|
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
|
+
});
|
|
13764
14070
|
}
|
|
13765
14071
|
};
|
|
13766
14072
|
this['~registerMessagesCallback'](saveMessagesInLocalStorage);
|
|
@@ -13836,7 +14142,7 @@
|
|
|
13836
14142
|
// it is non-empty and the chat is not already processing a message.
|
|
13837
14143
|
// Returns true when a message was submitted, so callers can clear their input.
|
|
13838
14144
|
function openChat(chatRenderState) {
|
|
13839
|
-
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;
|
|
13840
14146
|
var _ref1;
|
|
13841
14147
|
var _chatRenderState_setOpen;
|
|
13842
14148
|
if (!chatRenderState) {
|
|
@@ -13852,9 +14158,13 @@
|
|
|
13852
14158
|
if (isChatBusy(chatRenderState) || !chatRenderState.sendMessage) {
|
|
13853
14159
|
return false;
|
|
13854
14160
|
}
|
|
13855
|
-
chatRenderState.sendMessage({
|
|
14161
|
+
chatRenderState.sendMessage(_object_spread({
|
|
13856
14162
|
text: trimmed
|
|
13857
|
-
},
|
|
14163
|
+
}, turnContext ? {
|
|
14164
|
+
metadata: {
|
|
14165
|
+
turnContext: turnContext
|
|
14166
|
+
}
|
|
14167
|
+
} : {}), referer ? {
|
|
13858
14168
|
headers: {
|
|
13859
14169
|
'x-algolia-referer': referer
|
|
13860
14170
|
}
|
|
@@ -14068,7 +14378,7 @@
|
|
|
14068
14378
|
return DefaultChatTransport;
|
|
14069
14379
|
}(HttpChatTransport);
|
|
14070
14380
|
|
|
14071
|
-
var withUsage$
|
|
14381
|
+
var withUsage$q = createDocumentationMessageGenerator({
|
|
14072
14382
|
name: 'chat',
|
|
14073
14383
|
connector: true
|
|
14074
14384
|
});
|
|
@@ -14089,26 +14399,36 @@
|
|
|
14089
14399
|
attributesToClear: attributesToClear
|
|
14090
14400
|
}));
|
|
14091
14401
|
if (params.facetFilters) {
|
|
14092
|
-
var
|
|
14093
|
-
var
|
|
14094
|
-
|
|
14095
|
-
|
|
14096
|
-
|
|
14097
|
-
|
|
14098
|
-
|
|
14099
|
-
|
|
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) {
|
|
14100
14414
|
var attribute = param.attribute, value = param.value;
|
|
14101
|
-
|
|
14102
|
-
|
|
14103
|
-
|
|
14104
|
-
|
|
14105
|
-
|
|
14106
|
-
|
|
14107
|
-
|
|
14108
|
-
|
|
14109
|
-
|
|
14110
|
-
helper.toggleFacetRefinement(attr, value);
|
|
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;
|
|
14111
14424
|
}
|
|
14425
|
+
if (!helper.state.isConjunctiveFacet(attribute) && !helper.state.isDisjunctiveFacet(attribute)) {
|
|
14426
|
+
helper.setState(helper.state.addDisjunctiveFacet(attribute));
|
|
14427
|
+
}
|
|
14428
|
+
helper.toggleFacetRefinement(attribute, value);
|
|
14429
|
+
});
|
|
14430
|
+
hierarchicalRefinements.forEach(function(value, name) {
|
|
14431
|
+
helper.toggleFacetRefinement(name, value);
|
|
14112
14432
|
});
|
|
14113
14433
|
}
|
|
14114
14434
|
if (params.query) {
|
|
@@ -14119,7 +14439,7 @@
|
|
|
14119
14439
|
}
|
|
14120
14440
|
var connectChat = function connectChat(renderFn) {
|
|
14121
14441
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
14122
|
-
checkRendering(renderFn, withUsage$
|
|
14442
|
+
checkRendering(renderFn, withUsage$q());
|
|
14123
14443
|
return function(widgetParams) {
|
|
14124
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, [
|
|
14125
14445
|
"resume",
|
|
@@ -14197,6 +14517,11 @@
|
|
|
14197
14517
|
hasValidatedEntryPoints = true;
|
|
14198
14518
|
};
|
|
14199
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
|
+
}
|
|
14200
14525
|
var transport;
|
|
14201
14526
|
var client = instantSearchInstance.client;
|
|
14202
14527
|
var _getAppIdAndApiKey = _sliced_to_array(getAppIdAndApiKey(client), 2), appId = _getAppIdAndApiKey[0], apiKey = _getAppIdAndApiKey[1];
|
|
@@ -14246,7 +14571,7 @@
|
|
|
14246
14571
|
if ('agentId' in options && options.agentId) {
|
|
14247
14572
|
var _options_requestOptions, _options_requestOptions1;
|
|
14248
14573
|
if (!appId || !apiKey) {
|
|
14249
|
-
throw new Error(withUsage$
|
|
14574
|
+
throw new Error(withUsage$q('Could not extract Algolia credentials from the search client.'));
|
|
14250
14575
|
}
|
|
14251
14576
|
var createApi = function createApi() {
|
|
14252
14577
|
var bypassCache = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
|
|
@@ -14263,7 +14588,7 @@
|
|
|
14263
14588
|
var baseApi = createApi();
|
|
14264
14589
|
transport = new DefaultChatTransport({
|
|
14265
14590
|
api: baseApi,
|
|
14266
|
-
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), {
|
|
14267
14592
|
// Preserve the required Algolia identity headers and chat agent
|
|
14268
14593
|
// marker, even when requestOptions.headers contains the same keys.
|
|
14269
14594
|
'x-algolia-application-id': appId,
|
|
@@ -14285,10 +14610,7 @@
|
|
|
14285
14610
|
});
|
|
14286
14611
|
}
|
|
14287
14612
|
if (!transport) {
|
|
14288
|
-
throw new Error(withUsage$
|
|
14289
|
-
}
|
|
14290
|
-
if ('chat' in options) {
|
|
14291
|
-
return options.chat;
|
|
14613
|
+
throw new Error(withUsage$q('You need to provide either an `agentId` or a `transport`.'));
|
|
14292
14614
|
}
|
|
14293
14615
|
return new Chat$1(_object_spread_props(_object_spread({}, options), {
|
|
14294
14616
|
sendAutomaticallyWhen: sendAutomaticallyWhen,
|
|
@@ -14301,7 +14623,7 @@
|
|
|
14301
14623
|
if (!tool) return true;
|
|
14302
14624
|
return Boolean(tool.streamInput);
|
|
14303
14625
|
},
|
|
14304
|
-
onToolCall: function onToolCall(param) {
|
|
14626
|
+
onToolCall: function onToolCall(param, submitToolResult) {
|
|
14305
14627
|
var toolCall = param.toolCall;
|
|
14306
14628
|
var tool = tools[toolCall.toolName];
|
|
14307
14629
|
// Compatibility shim with Algolia MCP Server search tool
|
|
@@ -14309,7 +14631,7 @@
|
|
|
14309
14631
|
tool = tools[SearchIndexToolType$2];
|
|
14310
14632
|
}
|
|
14311
14633
|
if (!tool) {
|
|
14312
|
-
return
|
|
14634
|
+
return submitToolResult({
|
|
14313
14635
|
output: 'No tool implemented for "'.concat(toolCall.toolName, '".'),
|
|
14314
14636
|
tool: toolCall.toolName,
|
|
14315
14637
|
toolCallId: toolCall.toolCallId
|
|
@@ -14318,7 +14640,7 @@
|
|
|
14318
14640
|
if (tool.onToolCall) {
|
|
14319
14641
|
var addToolResult = function addToolResult(param) {
|
|
14320
14642
|
var output = param.output;
|
|
14321
|
-
return
|
|
14643
|
+
return submitToolResult({
|
|
14322
14644
|
output: output,
|
|
14323
14645
|
tool: toolCall.toolName,
|
|
14324
14646
|
toolCallId: toolCall.toolCallId
|
|
@@ -14368,7 +14690,7 @@
|
|
|
14368
14690
|
if (agentId && feedback) {
|
|
14369
14691
|
var _getAppIdAndApiKey = _sliced_to_array(getAppIdAndApiKey(initOptions.instantSearchInstance.client), 2), appId = _getAppIdAndApiKey[0], apiKey = _getAppIdAndApiKey[1];
|
|
14370
14692
|
if (!appId || !apiKey) {
|
|
14371
|
-
throw new Error(withUsage$
|
|
14693
|
+
throw new Error(withUsage$q('Could not extract Algolia credentials from the search client.'));
|
|
14372
14694
|
}
|
|
14373
14695
|
feedbackAbortController = new AbortController();
|
|
14374
14696
|
_sendChatMessageFeedback = function _sendChatMessageFeedback(messageId, vote) {
|
|
@@ -14389,21 +14711,32 @@
|
|
|
14389
14711
|
}
|
|
14390
14712
|
var hasExistingMessages = _chatInstance.messages.length > 0;
|
|
14391
14713
|
// Set initialMessages before registering callbacks to avoid
|
|
14392
|
-
// triggering re-renders during init
|
|
14393
|
-
|
|
14394
|
-
|
|
14395
|
-
|
|
14396
|
-
|
|
14397
|
-
|
|
14398
|
-
|
|
14399
|
-
|
|
14400
|
-
_chatInstance
|
|
14401
|
-
|
|
14402
|
-
|
|
14403
|
-
|
|
14404
|
-
|
|
14405
|
-
|
|
14406
|
-
|
|
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
|
+
});
|
|
14407
14740
|
renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
|
|
14408
14741
|
instantSearchInstance: instantSearchInstance
|
|
14409
14742
|
}), true);
|
|
@@ -14435,13 +14768,19 @@
|
|
|
14435
14768
|
function applyFilters(params) {
|
|
14436
14769
|
return updateStateFromSearchToolInput(params, helper);
|
|
14437
14770
|
}
|
|
14771
|
+
var insightsEventContext = {
|
|
14772
|
+
agentId: agentId,
|
|
14773
|
+
instantSearchStatus: instantSearchInstance.status
|
|
14774
|
+
};
|
|
14438
14775
|
var toolsWithAddToolResult = {};
|
|
14439
14776
|
Object.entries(tools).forEach(function(param) {
|
|
14440
14777
|
var _param = _sliced_to_array(param, 2), key = _param[0], tool = _param[1];
|
|
14441
14778
|
var toolWithAddToolResult = _object_spread_props(_object_spread({}, tool), {
|
|
14442
14779
|
addToolResult: _chatInstance.addToolResult,
|
|
14780
|
+
'~addToolResultForMessage': _chatInstance['~addToolResultForMessage'],
|
|
14443
14781
|
applyFilters: applyFilters,
|
|
14444
|
-
sendEvent: sendEvent
|
|
14782
|
+
sendEvent: sendEvent,
|
|
14783
|
+
insightsEventContext: insightsEventContext
|
|
14445
14784
|
});
|
|
14446
14785
|
toolsWithAddToolResult[key] = toolWithAddToolResult;
|
|
14447
14786
|
});
|
|
@@ -14496,22 +14835,639 @@
|
|
|
14496
14835
|
stop: _chatInstance.stop
|
|
14497
14836
|
};
|
|
14498
14837
|
},
|
|
14499
|
-
dispose: function dispose() {
|
|
14500
|
-
feedbackAbortController === null || feedbackAbortController === void 0 ? void 0 : feedbackAbortController.abort();
|
|
14838
|
+
dispose: function dispose() {
|
|
14839
|
+
feedbackAbortController === null || feedbackAbortController === void 0 ? void 0 : feedbackAbortController.abort();
|
|
14840
|
+
unmountFn();
|
|
14841
|
+
},
|
|
14842
|
+
shouldRender: function shouldRender() {
|
|
14843
|
+
return true;
|
|
14844
|
+
},
|
|
14845
|
+
get chatInstance () {
|
|
14846
|
+
return _chatInstance;
|
|
14847
|
+
}
|
|
14848
|
+
};
|
|
14849
|
+
};
|
|
14850
|
+
};
|
|
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
|
+
|
|
14893
|
+
function useChat(props, additionalWidgetProperties) {
|
|
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
|
+
});
|
|
14918
|
+
}
|
|
14919
|
+
|
|
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");
|
|
14923
|
+
}
|
|
14924
|
+
function resolveEndpoint(params) {
|
|
14925
|
+
if (params.transport) {
|
|
14926
|
+
return {
|
|
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);
|
|
14501
15457
|
unmountFn();
|
|
14502
15458
|
},
|
|
14503
|
-
|
|
14504
|
-
return
|
|
15459
|
+
getRenderState: function getRenderState(renderState, renderOptions) {
|
|
15460
|
+
return _object_spread_props(_object_spread({}, renderState), _define_property({}, RENDER_STATE_KEY, this.getWidgetRenderState(renderOptions)));
|
|
14505
15461
|
},
|
|
14506
|
-
|
|
14507
|
-
return
|
|
15462
|
+
getWidgetRenderState: function getWidgetRenderState1(renderOptions) {
|
|
15463
|
+
return getWidgetRenderState(renderOptions);
|
|
14508
15464
|
}
|
|
14509
15465
|
};
|
|
14510
15466
|
};
|
|
14511
15467
|
};
|
|
14512
15468
|
|
|
14513
|
-
function
|
|
14514
|
-
return useConnector(
|
|
15469
|
+
function usePromptSuggestions(props, additionalWidgetProperties) {
|
|
15470
|
+
return useConnector(connectPromptSuggestions, props, additionalWidgetProperties);
|
|
14515
15471
|
}
|
|
14516
15472
|
|
|
14517
15473
|
var withUsage$n = createDocumentationMessageGenerator({
|
|
@@ -14936,8 +15892,8 @@
|
|
|
14936
15892
|
if (escapeHTML && results.hits.length > 0) {
|
|
14937
15893
|
results.hits = escapeHits(results.hits);
|
|
14938
15894
|
}
|
|
14939
|
-
var itemsWithAbsolutePosition = addAbsolutePosition(results.hits, 0, 1);
|
|
14940
|
-
var itemsWithAbsolutePositionAndQueryID = addQueryID(itemsWithAbsolutePosition, results.queryID);
|
|
15895
|
+
var itemsWithAbsolutePosition = addAbsolutePosition$1(results.hits, 0, 1);
|
|
15896
|
+
var itemsWithAbsolutePositionAndQueryID = addQueryID$1(itemsWithAbsolutePosition, results.queryID);
|
|
14941
15897
|
var transformedItems = transformItems(itemsWithAbsolutePositionAndQueryID, {
|
|
14942
15898
|
results: results
|
|
14943
15899
|
});
|
|
@@ -15456,8 +16412,8 @@
|
|
|
15456
16412
|
if (escapeHTML && results.hits.length > 0) {
|
|
15457
16413
|
results.hits = escapeHits(results.hits);
|
|
15458
16414
|
}
|
|
15459
|
-
var hitsWithAbsolutePosition = addAbsolutePosition(results.hits, results.page, results.hitsPerPage);
|
|
15460
|
-
var hitsWithAbsolutePositionAndQueryID = addQueryID(hitsWithAbsolutePosition, results.queryID);
|
|
16415
|
+
var hitsWithAbsolutePosition = addAbsolutePosition$1(results.hits, results.page, results.hitsPerPage);
|
|
16416
|
+
var hitsWithAbsolutePositionAndQueryID = addQueryID$1(hitsWithAbsolutePosition, results.queryID);
|
|
15461
16417
|
var items = transformItems(hitsWithAbsolutePositionAndQueryID, {
|
|
15462
16418
|
results: results
|
|
15463
16419
|
});
|
|
@@ -15788,8 +16744,8 @@
|
|
|
15788
16744
|
if (escapeHTML && results.hits.length > 0) {
|
|
15789
16745
|
results.hits = escapeHits(results.hits);
|
|
15790
16746
|
}
|
|
15791
|
-
var hitsWithAbsolutePosition = addAbsolutePosition(results.hits, results.page, results.hitsPerPage);
|
|
15792
|
-
var hitsWithAbsolutePositionAndQueryID = addQueryID(hitsWithAbsolutePosition, results.queryID);
|
|
16747
|
+
var hitsWithAbsolutePosition = addAbsolutePosition$1(results.hits, results.page, results.hitsPerPage);
|
|
16748
|
+
var hitsWithAbsolutePositionAndQueryID = addQueryID$1(hitsWithAbsolutePosition, results.queryID);
|
|
15793
16749
|
var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID, {
|
|
15794
16750
|
results: results
|
|
15795
16751
|
});
|
|
@@ -17221,8 +18177,8 @@
|
|
|
17221
18177
|
if (escapeHTML && results.hits.length > 0) {
|
|
17222
18178
|
results.hits = escapeHits(results.hits);
|
|
17223
18179
|
}
|
|
17224
|
-
var itemsWithAbsolutePosition = addAbsolutePosition(results.hits, 0, 1);
|
|
17225
|
-
var itemsWithAbsolutePositionAndQueryID = addQueryID(itemsWithAbsolutePosition, results.queryID);
|
|
18180
|
+
var itemsWithAbsolutePosition = addAbsolutePosition$1(results.hits, 0, 1);
|
|
18181
|
+
var itemsWithAbsolutePositionAndQueryID = addQueryID$1(itemsWithAbsolutePosition, results.queryID);
|
|
17226
18182
|
var transformedItems = transformItems(itemsWithAbsolutePositionAndQueryID, {
|
|
17227
18183
|
results: results
|
|
17228
18184
|
});
|
|
@@ -17902,8 +18858,8 @@
|
|
|
17902
18858
|
if (escapeHTML && results.hits.length > 0) {
|
|
17903
18859
|
results.hits = escapeHits(results.hits);
|
|
17904
18860
|
}
|
|
17905
|
-
var itemsWithAbsolutePosition = addAbsolutePosition(results.hits, 0, 1);
|
|
17906
|
-
var itemsWithAbsolutePositionAndQueryID = addQueryID(itemsWithAbsolutePosition, results.queryID);
|
|
18861
|
+
var itemsWithAbsolutePosition = addAbsolutePosition$1(results.hits, 0, 1);
|
|
18862
|
+
var itemsWithAbsolutePositionAndQueryID = addQueryID$1(itemsWithAbsolutePosition, results.queryID);
|
|
17907
18863
|
var transformedItems = transformItems(itemsWithAbsolutePositionAndQueryID, {
|
|
17908
18864
|
results: results
|
|
17909
18865
|
});
|
|
@@ -18075,8 +19031,8 @@
|
|
|
18075
19031
|
if (escapeHTML && results.hits.length > 0) {
|
|
18076
19032
|
results.hits = escapeHits(results.hits);
|
|
18077
19033
|
}
|
|
18078
|
-
var itemsWithAbsolutePosition = addAbsolutePosition(results.hits, 0, 1);
|
|
18079
|
-
var itemsWithAbsolutePositionAndQueryID = addQueryID(itemsWithAbsolutePosition, results.queryID);
|
|
19034
|
+
var itemsWithAbsolutePosition = addAbsolutePosition$1(results.hits, 0, 1);
|
|
19035
|
+
var itemsWithAbsolutePositionAndQueryID = addQueryID$1(itemsWithAbsolutePosition, results.queryID);
|
|
18080
19036
|
var transformedItems = transformItems(itemsWithAbsolutePositionAndQueryID, {
|
|
18081
19037
|
results: results
|
|
18082
19038
|
});
|
|
@@ -19291,6 +20247,34 @@
|
|
|
19291
20247
|
d: "M17 14V2"
|
|
19292
20248
|
}));
|
|
19293
20249
|
}
|
|
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
|
+
}
|
|
19294
20278
|
function ChevronLeftIcon(param) {
|
|
19295
20279
|
var createElement = param.createElement;
|
|
19296
20280
|
return /*#__PURE__*/ createElement("svg", {
|
|
@@ -19944,6 +20928,22 @@
|
|
|
19944
20928
|
};
|
|
19945
20929
|
}
|
|
19946
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
|
+
}
|
|
19947
20947
|
var lastCarouselId = 0;
|
|
19948
20948
|
function generateCarouselId() {
|
|
19949
20949
|
return "ais-Carousel-".concat(lastCarouselId++);
|
|
@@ -19977,7 +20977,7 @@
|
|
|
19977
20977
|
}));
|
|
19978
20978
|
}
|
|
19979
20979
|
function createCarouselComponent(param) {
|
|
19980
|
-
var createElement = param.createElement, Fragment = param.Fragment;
|
|
20980
|
+
var createElement = param.createElement, Fragment = param.Fragment, useEffect = param.useEffect, useRef = param.useRef;
|
|
19981
20981
|
return function Carousel(userProps) {
|
|
19982
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({
|
|
19983
20983
|
createElement: createElement,
|
|
@@ -20008,6 +21008,7 @@
|
|
|
20008
21008
|
previousButtonLabel: 'Previous',
|
|
20009
21009
|
previousButtonTitle: 'Previous'
|
|
20010
21010
|
}, userTranslations);
|
|
21011
|
+
var previousItemsLengthRef = useRef(items.length);
|
|
20011
21012
|
var cssClasses = {
|
|
20012
21013
|
root: cx('ais-Carousel', classNames.root),
|
|
20013
21014
|
list: cx('ais-Carousel-list', classNames.list),
|
|
@@ -20026,27 +21027,33 @@
|
|
|
20026
21027
|
listRef.current.scrollLeft += listRef.current.offsetWidth * 0.75;
|
|
20027
21028
|
}
|
|
20028
21029
|
}
|
|
20029
|
-
function
|
|
20030
|
-
if (
|
|
20031
|
-
|
|
20032
|
-
|
|
20033
|
-
|
|
20034
|
-
|
|
20035
|
-
|
|
20036
|
-
|
|
20037
|
-
|
|
20038
|
-
|
|
20039
|
-
}
|
|
20040
|
-
if (nextButtonRef.current) {
|
|
20041
|
-
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;
|
|
20042
21040
|
}
|
|
20043
|
-
}
|
|
21041
|
+
}, [
|
|
21042
|
+
items.length,
|
|
21043
|
+
listRef,
|
|
21044
|
+
nextButtonRef,
|
|
21045
|
+
previousButtonRef,
|
|
21046
|
+
setCanScrollLeft,
|
|
21047
|
+
setCanScrollRight
|
|
21048
|
+
]);
|
|
20044
21049
|
if (items.length === 0) {
|
|
20045
21050
|
return null;
|
|
20046
21051
|
}
|
|
21052
|
+
var itemOccurrences = new Map();
|
|
20047
21053
|
return /*#__PURE__*/ createElement("div", _object_spread_props(_object_spread({}, props), {
|
|
20048
21054
|
className: cx(cssClasses.root)
|
|
20049
21055
|
}), HeaderComponent && /*#__PURE__*/ createElement(HeaderComponent, {
|
|
21056
|
+
nbItems: items.length,
|
|
20050
21057
|
canScrollLeft: canScrollLeft,
|
|
20051
21058
|
canScrollRight: canScrollRight,
|
|
20052
21059
|
scrollLeft: scrollLeft,
|
|
@@ -20072,7 +21079,15 @@
|
|
|
20072
21079
|
"aria-roledescription": "carousel",
|
|
20073
21080
|
"aria-label": translations.listLabel,
|
|
20074
21081
|
"aria-live": "polite",
|
|
20075
|
-
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
|
+
},
|
|
20076
21091
|
onKeyDown: function onKeyDown(event) {
|
|
20077
21092
|
if (event.key === 'ArrowLeft') {
|
|
20078
21093
|
event.preventDefault();
|
|
@@ -20083,8 +21098,14 @@
|
|
|
20083
21098
|
}
|
|
20084
21099
|
}
|
|
20085
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);
|
|
20086
21104
|
return /*#__PURE__*/ createElement("li", {
|
|
20087
|
-
key:
|
|
21105
|
+
key: JSON.stringify([
|
|
21106
|
+
item.objectID,
|
|
21107
|
+
occurrence
|
|
21108
|
+
]),
|
|
20088
21109
|
className: cx(cssClasses.item),
|
|
20089
21110
|
"aria-roledescription": "slide",
|
|
20090
21111
|
"aria-label": "".concat(index + 1, " of ").concat(items.length),
|
|
@@ -20194,7 +21215,7 @@
|
|
|
20194
21215
|
var SearchIndexToolType$1 = 'algolia_search_index';
|
|
20195
21216
|
var getTextContent = function getTextContent(message) {
|
|
20196
21217
|
return message.parts.map(function(part) {
|
|
20197
|
-
return 'text'
|
|
21218
|
+
return part.type === 'text' ? part.text : '';
|
|
20198
21219
|
}).join('');
|
|
20199
21220
|
};
|
|
20200
21221
|
var hasTextContent = function hasTextContent(message) {
|
|
@@ -20206,6 +21227,12 @@
|
|
|
20206
21227
|
var isPartTool = function isPartTool(part) {
|
|
20207
21228
|
return startsWith(part.type, 'tool-');
|
|
20208
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
|
+
}
|
|
20209
21236
|
var findTool = function findTool(partType, tools) {
|
|
20210
21237
|
var toolName = partType.replace('tool-', '');
|
|
20211
21238
|
var tool = tools[toolName];
|
|
@@ -20219,22 +21246,23 @@
|
|
|
20219
21246
|
return tool;
|
|
20220
21247
|
};
|
|
20221
21248
|
var FACET_KEY_PREFIX = 'facet_';
|
|
20222
|
-
|
|
20223
|
-
|
|
20224
|
-
|
|
20225
|
-
|
|
20226
|
-
* Algolia MCP Server search tool instead expresses refinements as individual
|
|
20227
|
-
* `facet_<attribute>` keys (e.g. `facet_categories: ['Books', 'Toys']`), which
|
|
20228
|
-
* are converted here into the `[['attribute:value']]` shape `applyFilters`
|
|
20229
|
-
* expects.
|
|
20230
|
-
*/ var getFacetFiltersFromToolInput = function getFacetFiltersFromToolInput(input) {
|
|
21249
|
+
var hasQueries = function hasQueries(input) {
|
|
21250
|
+
return Array.isArray(input.queries);
|
|
21251
|
+
};
|
|
21252
|
+
var getSearchToolQuery = function getSearchToolQuery(input) {
|
|
20231
21253
|
if (!input) {
|
|
20232
21254
|
return undefined;
|
|
20233
21255
|
}
|
|
20234
|
-
|
|
20235
|
-
|
|
21256
|
+
return hasQueries(input) ? input.queries[0] : input;
|
|
21257
|
+
};
|
|
21258
|
+
var getFacetFilters = function getFacetFilters(query) {
|
|
21259
|
+
if (!query) {
|
|
21260
|
+
return undefined;
|
|
20236
21261
|
}
|
|
20237
|
-
|
|
21262
|
+
if (Array.isArray(query.facet_filters)) {
|
|
21263
|
+
return query.facet_filters;
|
|
21264
|
+
}
|
|
21265
|
+
var facetFilters = Object.entries(query).reduce(function(acc, param) {
|
|
20238
21266
|
var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
20239
21267
|
if (!startsWith(key, FACET_KEY_PREFIX) || !Array.isArray(value)) {
|
|
20240
21268
|
return acc;
|
|
@@ -20252,6 +21280,21 @@
|
|
|
20252
21280
|
}, []);
|
|
20253
21281
|
return facetFilters.length > 0 ? facetFilters : undefined;
|
|
20254
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
|
+
};
|
|
20255
21298
|
var isSearchToolPart = function isSearchToolPart(part) {
|
|
20256
21299
|
return part.type === "tool-".concat(SearchIndexToolType$1) || // Compatibility shim with Algolia MCP Server search tool
|
|
20257
21300
|
startsWith(part.type, "tool-".concat(SearchIndexToolType$1, "_"));
|
|
@@ -20279,59 +21322,72 @@
|
|
|
20279
21322
|
* relies on this map to hydrate each result with the full record that the
|
|
20280
21323
|
* preceding search tool already fetched.
|
|
20281
21324
|
*
|
|
20282
|
-
* Pass
|
|
20283
|
-
*
|
|
20284
|
-
*
|
|
20285
|
-
*
|
|
20286
|
-
|
|
20287
|
-
|
|
20288
|
-
var
|
|
20289
|
-
|
|
20290
|
-
|
|
20291
|
-
|
|
20292
|
-
var message = _step.value;
|
|
20293
|
-
var reachedBoundary = false;
|
|
20294
|
-
message.parts.forEach(function(part) {
|
|
20295
|
-
if (!isPartTool(part)) {
|
|
20296
|
-
return;
|
|
20297
|
-
}
|
|
20298
|
-
// Note the boundary but keep processing the rest of this message's parts:
|
|
20299
|
-
// the search tool that fed this display tool lives in the same message,
|
|
20300
|
-
// so its hits must still be collected before we stop.
|
|
20301
|
-
if (untilToolCallId && part.toolCallId === untilToolCallId) {
|
|
20302
|
-
reachedBoundary = true;
|
|
20303
|
-
}
|
|
20304
|
-
if (isSearchToolPart(part)) {
|
|
20305
|
-
collectHitsFromPart(part, hitsByObjectID);
|
|
20306
|
-
}
|
|
20307
|
-
});
|
|
20308
|
-
if (reachedBoundary) {
|
|
20309
|
-
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;
|
|
20310
21335
|
}
|
|
20311
|
-
|
|
20312
|
-
|
|
20313
|
-
var _ret = _loop();
|
|
20314
|
-
if (_ret === "break") break;
|
|
20315
|
-
}
|
|
20316
|
-
} catch (err) {
|
|
20317
|
-
_didIteratorError = true;
|
|
20318
|
-
_iteratorError = err;
|
|
20319
|
-
} finally{
|
|
20320
|
-
try {
|
|
20321
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
20322
|
-
_iterator.return();
|
|
21336
|
+
if (untilToolPart && part === untilToolPart) {
|
|
21337
|
+
return true;
|
|
20323
21338
|
}
|
|
20324
|
-
|
|
20325
|
-
|
|
20326
|
-
throw _iteratorError;
|
|
21339
|
+
if (isSearchToolPart(part)) {
|
|
21340
|
+
collectHitsFromPart(part, hitsByObjectID);
|
|
20327
21341
|
}
|
|
20328
|
-
|
|
21342
|
+
return false;
|
|
21343
|
+
});
|
|
21344
|
+
});
|
|
21345
|
+
if (untilToolPart && !reachedBoundary) {
|
|
21346
|
+
return Object.create(null);
|
|
20329
21347
|
}
|
|
20330
21348
|
return hitsByObjectID;
|
|
20331
21349
|
};
|
|
20332
21350
|
|
|
20333
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}
|
|
20334
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
|
+
|
|
20335
21391
|
// Keep in sync with packages/instantsearch.js/src/lib/chat/index.ts
|
|
20336
21392
|
var SearchIndexToolType = 'algolia_search_index';
|
|
20337
21393
|
function createChatMessageComponent(param) {
|
|
@@ -20339,8 +21395,12 @@
|
|
|
20339
21395
|
var Button = createButtonComponent({
|
|
20340
21396
|
createElement: createElement
|
|
20341
21397
|
});
|
|
21398
|
+
var ChatMessageReasoning = createChatMessageReasoningComponent({
|
|
21399
|
+
createElement: createElement
|
|
21400
|
+
});
|
|
20342
21401
|
return function ChatMessage(userProps) {
|
|
20343
|
-
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, [
|
|
20344
21404
|
"classNames",
|
|
20345
21405
|
"message",
|
|
20346
21406
|
"status",
|
|
@@ -20358,13 +21418,16 @@
|
|
|
20358
21418
|
"onClose",
|
|
20359
21419
|
"translations",
|
|
20360
21420
|
"suggestionsElement",
|
|
21421
|
+
"showReasoning",
|
|
20361
21422
|
"parseMarkdown"
|
|
20362
21423
|
]);
|
|
20363
21424
|
var translations = _object_spread({
|
|
20364
21425
|
messageLabel: 'Message',
|
|
20365
|
-
actionsLabel: 'Message actions'
|
|
21426
|
+
actionsLabel: 'Message actions',
|
|
21427
|
+
reasoningLabel: 'Reasoning'
|
|
20366
21428
|
}, userTranslations);
|
|
20367
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;
|
|
20368
21431
|
var showActions = Boolean(actions.length > 0 || ActionsComponent) && status === 'ready';
|
|
20369
21432
|
var cssClasses = {
|
|
20370
21433
|
root: cx('ais-ChatMessage', "ais-ChatMessage--".concat(side), "ais-ChatMessage--".concat(variant), autoHideActions && 'ais-ChatMessage--auto-hide-actions', classNames.root),
|
|
@@ -20373,12 +21436,38 @@
|
|
|
20373
21436
|
content: cx('ais-ChatMessage-content', classNames.content),
|
|
20374
21437
|
message: cx('ais-ChatMessage-message', classNames.message),
|
|
20375
21438
|
actions: cx('ais-ChatMessage-actions', classNames.actions),
|
|
20376
|
-
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)
|
|
20377
21447
|
};
|
|
20378
21448
|
function renderMessagePart(part, index) {
|
|
20379
21449
|
if (part.type === 'step-start') {
|
|
20380
21450
|
return null;
|
|
20381
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
|
+
}
|
|
20382
21471
|
if (part.type === 'text') {
|
|
20383
21472
|
// Back-compat shim for sessions started before the move from a
|
|
20384
21473
|
// `<context>{...}</context>` text part to `metadata.turnContext`.
|
|
@@ -20420,11 +21509,15 @@
|
|
|
20420
21509
|
return null;
|
|
20421
21510
|
}
|
|
20422
21511
|
if (tool) {
|
|
21512
|
+
var _tool_insightsEventContext;
|
|
20423
21513
|
var ToolLayoutComponent = tool.layoutComponent;
|
|
20424
21514
|
var toolMessage = part;
|
|
20425
21515
|
var boundAddToolResult = function boundAddToolResult(params) {
|
|
20426
|
-
|
|
20427
|
-
|
|
21516
|
+
return tool['~addToolResultForMessage'] ? tool['~addToolResultForMessage'](message, {
|
|
21517
|
+
output: params.output,
|
|
21518
|
+
tool: part.type,
|
|
21519
|
+
toolCallId: toolMessage.toolCallId
|
|
21520
|
+
}) : tool.addToolResult({
|
|
20428
21521
|
output: params.output,
|
|
20429
21522
|
tool: part.type,
|
|
20430
21523
|
toolCallId: toolMessage.toolCallId
|
|
@@ -20436,17 +21529,33 @@
|
|
|
20436
21529
|
if (!ToolLayoutComponent) {
|
|
20437
21530
|
return null;
|
|
20438
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
|
+
};
|
|
20439
21546
|
return /*#__PURE__*/ createElement("div", {
|
|
20440
21547
|
key: "".concat(message.id, "-").concat(index),
|
|
20441
21548
|
className: "ais-ChatMessage-tool"
|
|
20442
21549
|
}, /*#__PURE__*/ createElement(ToolLayoutComponent, {
|
|
20443
21550
|
message: toolMessage,
|
|
21551
|
+
insightsEventContext: tool.insightsEventContext,
|
|
21552
|
+
status: status,
|
|
20444
21553
|
indexUiState: indexUiState,
|
|
20445
21554
|
setIndexUiState: setIndexUiState,
|
|
20446
21555
|
messages: messages,
|
|
20447
21556
|
addToolResult: boundAddToolResult,
|
|
20448
21557
|
applyFilters: tool.applyFilters,
|
|
20449
|
-
sendEvent:
|
|
21558
|
+
sendEvent: sendEvent,
|
|
20450
21559
|
onClose: onClose
|
|
20451
21560
|
}));
|
|
20452
21561
|
}
|
|
@@ -20598,20 +21707,17 @@
|
|
|
20598
21707
|
var copyToClipboard = function copyToClipboard(message) {
|
|
20599
21708
|
navigator.clipboard.writeText(getTextContent(message));
|
|
20600
21709
|
};
|
|
20601
|
-
|
|
20602
|
-
|
|
20603
|
-
|
|
20604
|
-
|
|
20605
|
-
|
|
20606
|
-
|
|
20607
|
-
|
|
20608
|
-
|
|
20609
|
-
|
|
20610
|
-
|
|
20611
|
-
|
|
20612
|
-
var _prev_feedbackState, _next_feedbackState;
|
|
20613
|
-
return prev.message === next.message && prev.status === next.status && prev.suggestionsElement === next.suggestionsElement && ((_prev_feedbackState = prev.feedbackState) === null || _prev_feedbackState === void 0 ? void 0 : _prev_feedbackState[prev.message.id]) === ((_next_feedbackState = next.feedbackState) === null || _next_feedbackState === void 0 ? void 0 : _next_feedbackState[next.message.id]);
|
|
20614
|
-
}
|
|
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
|
+
};
|
|
20615
21721
|
function createDefaultMessageComponent(param) {
|
|
20616
21722
|
var createElement = param.createElement, Fragment = param.Fragment;
|
|
20617
21723
|
var ChatMessage = createChatMessageComponent({
|
|
@@ -20719,7 +21825,7 @@
|
|
|
20719
21825
|
};
|
|
20720
21826
|
}
|
|
20721
21827
|
function createChatMessagesComponent(param) {
|
|
20722
|
-
var createElement = param.createElement, Fragment = param.Fragment,
|
|
21828
|
+
var createElement = param.createElement, Fragment = param.Fragment, useMemo = param.useMemo;
|
|
20723
21829
|
var Button = createButtonComponent({
|
|
20724
21830
|
createElement: createElement
|
|
20725
21831
|
});
|
|
@@ -20728,8 +21834,56 @@
|
|
|
20728
21834
|
Fragment: Fragment
|
|
20729
21835
|
});
|
|
20730
21836
|
// Skip re-rendering (and re-compiling the markdown of) completed messages on
|
|
20731
|
-
// every streaming delta.
|
|
20732
|
-
|
|
21837
|
+
// every streaming delta. The deps tuple matches the row's render inputs;
|
|
21838
|
+
// callbacks/`indexUiState` are intentionally excluded because `getUiState()`
|
|
21839
|
+
// returns a fresh object every render and would defeat the memo — completed
|
|
21840
|
+
// rows keep the callbacks/`indexUiState` they last rendered with until their
|
|
21841
|
+
// next genuine update.
|
|
21842
|
+
function MemoizedDefaultMessage(props) {
|
|
21843
|
+
var _props_feedbackState;
|
|
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.
|
|
21866
|
+
return useMemo(function() {
|
|
21867
|
+
return /*#__PURE__*/ createElement(DefaultMessageComponent, props);
|
|
21868
|
+
}, [
|
|
21869
|
+
props.message,
|
|
21870
|
+
props.isCurrentMessage,
|
|
21871
|
+
props.status,
|
|
21872
|
+
instantSearchStatus,
|
|
21873
|
+
props.suggestionsElement,
|
|
21874
|
+
messageFeedback,
|
|
21875
|
+
showReasoning,
|
|
21876
|
+
parseMarkdown,
|
|
21877
|
+
reasoningLabel,
|
|
21878
|
+
reasoningClassName,
|
|
21879
|
+
reasoningHeaderClassName,
|
|
21880
|
+
reasoningIconClassName,
|
|
21881
|
+
reasoningLabelClassName,
|
|
21882
|
+
reasoningChevronClassName,
|
|
21883
|
+
reasoningBodyClassName,
|
|
21884
|
+
reasoningTextClassName
|
|
21885
|
+
]);
|
|
21886
|
+
}
|
|
20733
21887
|
var DefaultLoaderComponent = createChatMessageLoaderComponent({
|
|
20734
21888
|
createElement: createElement
|
|
20735
21889
|
});
|
|
@@ -20737,7 +21891,8 @@
|
|
|
20737
21891
|
createElement: createElement
|
|
20738
21892
|
});
|
|
20739
21893
|
return function ChatMessages(userProps) {
|
|
20740
|
-
var
|
|
21894
|
+
var _ref;
|
|
21895
|
+
var _lastMessage_parts, _lastMessage_parts1;
|
|
20741
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, [
|
|
20742
21897
|
"classNames",
|
|
20743
21898
|
"messageClassNames",
|
|
@@ -20790,7 +21945,12 @@
|
|
|
20790
21945
|
};
|
|
20791
21946
|
var lastMessage = messages[messages.length - 1];
|
|
20792
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];
|
|
20793
|
-
|
|
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);
|
|
20794
21954
|
var showEmpty = messages.length === 0 && !showLoader && !isClearing && status !== 'error';
|
|
20795
21955
|
var DefaultMessage = MessageComponent || MemoizedDefaultMessage;
|
|
20796
21956
|
var DefaultLoader = LoaderComponent || DefaultLoaderComponent;
|
|
@@ -20819,6 +21979,7 @@
|
|
|
20819
21979
|
return /*#__PURE__*/ createElement(DefaultMessage, {
|
|
20820
21980
|
key: message.id,
|
|
20821
21981
|
message: message,
|
|
21982
|
+
isCurrentMessage: index === messages.length - 1,
|
|
20822
21983
|
status: status,
|
|
20823
21984
|
userMessageProps: userMessageProps,
|
|
20824
21985
|
assistantMessageProps: assistantMessageProps,
|
|
@@ -20866,10 +22027,13 @@
|
|
|
20866
22027
|
})));
|
|
20867
22028
|
};
|
|
20868
22029
|
}
|
|
20869
|
-
var getShowLoader = function getShowLoader(status, lastPart, tools) {
|
|
22030
|
+
var getShowLoader = function getShowLoader(status, lastPart, tools, showReasoning, hasActiveReasoning) {
|
|
20870
22031
|
if (status !== 'submitted' && status !== 'streaming') return false;
|
|
20871
22032
|
if (status === 'submitted') return true;
|
|
20872
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;
|
|
20873
22037
|
if (isPartText(lastPart)) return false;
|
|
20874
22038
|
if (isPartTool(lastPart) && lastPart.state === 'input-streaming') {
|
|
20875
22039
|
var tool = findTool(lastPart.type, tools);
|
|
@@ -21110,7 +22274,7 @@
|
|
|
21110
22274
|
return typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
21111
22275
|
}
|
|
21112
22276
|
function createChatComponent(param) {
|
|
21113
|
-
var createElement = param.createElement, Fragment = param.Fragment,
|
|
22277
|
+
var createElement = param.createElement, Fragment = param.Fragment, useMemo = param.useMemo, useState = param.useState;
|
|
21114
22278
|
var ChatHeader = createChatHeaderComponent({
|
|
21115
22279
|
createElement: createElement,
|
|
21116
22280
|
Fragment: Fragment
|
|
@@ -21118,7 +22282,7 @@
|
|
|
21118
22282
|
var ChatMessages = createChatMessagesComponent({
|
|
21119
22283
|
createElement: createElement,
|
|
21120
22284
|
Fragment: Fragment,
|
|
21121
|
-
|
|
22285
|
+
useMemo: useMemo
|
|
21122
22286
|
});
|
|
21123
22287
|
var ChatPrompt = createChatPromptComponent({
|
|
21124
22288
|
createElement: createElement,
|
|
@@ -21361,86 +22525,459 @@
|
|
|
21361
22525
|
}, translations.subheading));
|
|
21362
22526
|
};
|
|
21363
22527
|
}
|
|
21364
|
-
|
|
21365
|
-
function
|
|
21366
|
-
var createElement = param.createElement;
|
|
21367
|
-
var Button = createButtonComponent({
|
|
21368
|
-
createElement: createElement
|
|
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
|
+
|
|
22596
|
+
function createChatToggleButtonComponent(param) {
|
|
22597
|
+
var createElement = param.createElement;
|
|
22598
|
+
var Button = createButtonComponent({
|
|
22599
|
+
createElement: createElement
|
|
22600
|
+
});
|
|
22601
|
+
return function ChatToggleButton(userProps) {
|
|
22602
|
+
var open = userProps.open, onClick = userProps.onClick, ToggleIcon = userProps.toggleIconComponent, _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, className = userProps.className, props = _object_without_properties(userProps, [
|
|
22603
|
+
"open",
|
|
22604
|
+
"onClick",
|
|
22605
|
+
"toggleIconComponent",
|
|
22606
|
+
"classNames",
|
|
22607
|
+
"className"
|
|
22608
|
+
]);
|
|
22609
|
+
var defaultIcon = open ? /*#__PURE__*/ createElement(ChevronUpIcon, {
|
|
22610
|
+
createElement: createElement
|
|
22611
|
+
}) : /*#__PURE__*/ createElement(SparklesIcon, {
|
|
22612
|
+
createElement: createElement
|
|
22613
|
+
});
|
|
22614
|
+
return /*#__PURE__*/ createElement(Button, _object_spread({
|
|
22615
|
+
variant: "primary",
|
|
22616
|
+
size: "md",
|
|
22617
|
+
iconOnly: true,
|
|
22618
|
+
className: cx('ais-ChatToggleButton', open && 'ais-ChatToggleButton--open', classNames.root, className),
|
|
22619
|
+
onClick: onClick
|
|
22620
|
+
}, props), ToggleIcon ? /*#__PURE__*/ createElement(ToggleIcon, {
|
|
22621
|
+
isOpen: open
|
|
22622
|
+
}) : defaultIcon);
|
|
22623
|
+
};
|
|
22624
|
+
}
|
|
22625
|
+
|
|
22626
|
+
function addAbsolutePosition(hits, page, hitsPerPage) {
|
|
22627
|
+
return hits.map(function(hit, idx) {
|
|
22628
|
+
return _object_spread_props(_object_spread({}, hit), {
|
|
22629
|
+
__position: hitsPerPage * page + idx + 1
|
|
22630
|
+
});
|
|
22631
|
+
});
|
|
22632
|
+
}
|
|
22633
|
+
function addQueryID(hits, queryID) {
|
|
22634
|
+
if (!queryID) {
|
|
22635
|
+
return hits;
|
|
22636
|
+
}
|
|
22637
|
+
return hits.map(function(hit) {
|
|
22638
|
+
return _object_spread_props(_object_spread({}, hit), {
|
|
22639
|
+
__queryID: queryID
|
|
22640
|
+
});
|
|
22641
|
+
});
|
|
22642
|
+
}
|
|
22643
|
+
|
|
22644
|
+
function createHeaderComponent(param) {
|
|
22645
|
+
var createElement = param.createElement;
|
|
22646
|
+
var Button = createButtonComponent({
|
|
22647
|
+
createElement: createElement
|
|
22648
|
+
});
|
|
22649
|
+
return function HeaderComponent(param) {
|
|
22650
|
+
var showViewAll = param.showViewAll, canScrollLeft = param.canScrollLeft, canScrollRight = param.canScrollRight, scrollLeft = param.scrollLeft, scrollRight = param.scrollRight, nbHits = param.nbHits, input = param.input, nbItems = param.nbItems, applyFilters = param.applyFilters, getSearchPageURL = param.getSearchPageURL, onClose = param.onClose;
|
|
22651
|
+
if (nbItems < 1) {
|
|
22652
|
+
return null;
|
|
22653
|
+
}
|
|
22654
|
+
return /*#__PURE__*/ createElement("div", {
|
|
22655
|
+
className: "ais-ChatToolSearchIndexCarouselHeader"
|
|
22656
|
+
}, /*#__PURE__*/ createElement("div", {
|
|
22657
|
+
className: "ais-ChatToolSearchIndexCarouselHeaderResults"
|
|
22658
|
+
}, nbHits && /*#__PURE__*/ createElement("div", {
|
|
22659
|
+
className: "ais-ChatToolSearchIndexCarouselHeaderCount"
|
|
22660
|
+
}, nbItems, " of ", nbHits.toLocaleString(), " result", nbHits > 1 ? 's' : ''), showViewAll && /*#__PURE__*/ createElement(Button, {
|
|
22661
|
+
variant: "ghost",
|
|
22662
|
+
size: "sm",
|
|
22663
|
+
onClick: function onClick() {
|
|
22664
|
+
if (!input || !applyFilters) return;
|
|
22665
|
+
var params = applyFilters(getApplyFiltersParamsFromToolInput(input));
|
|
22666
|
+
if (getSearchPageURL) {
|
|
22667
|
+
var searchPageURL = getSearchPageURL(params);
|
|
22668
|
+
var resolvedURL = new URL(searchPageURL, window.location.href);
|
|
22669
|
+
if (resolvedURL.pathname !== window.location.pathname) {
|
|
22670
|
+
window.location.href = searchPageURL;
|
|
22671
|
+
}
|
|
22672
|
+
}
|
|
22673
|
+
onClose();
|
|
22674
|
+
},
|
|
22675
|
+
className: "ais-ChatToolSearchIndexCarouselHeaderViewAll"
|
|
22676
|
+
}, "View all", /*#__PURE__*/ createElement(ArrowRightIcon, {
|
|
22677
|
+
createElement: createElement
|
|
22678
|
+
}))), nbItems > 2 && /*#__PURE__*/ createElement("div", {
|
|
22679
|
+
className: "ais-ChatToolSearchIndexCarouselHeaderScrollButtons"
|
|
22680
|
+
}, /*#__PURE__*/ createElement(Button, {
|
|
22681
|
+
variant: "outline",
|
|
22682
|
+
size: "sm",
|
|
22683
|
+
iconOnly: true,
|
|
22684
|
+
onClick: scrollLeft,
|
|
22685
|
+
disabled: !canScrollLeft,
|
|
22686
|
+
className: "ais-ChatToolSearchIndexCarouselHeaderScrollButton"
|
|
22687
|
+
}, /*#__PURE__*/ createElement(ChevronLeftIcon, {
|
|
22688
|
+
createElement: createElement
|
|
22689
|
+
})), /*#__PURE__*/ createElement(Button, {
|
|
22690
|
+
variant: "outline",
|
|
22691
|
+
size: "sm",
|
|
22692
|
+
iconOnly: true,
|
|
22693
|
+
onClick: scrollRight,
|
|
22694
|
+
disabled: !canScrollRight,
|
|
22695
|
+
className: "ais-ChatToolSearchIndexCarouselHeaderScrollButton"
|
|
22696
|
+
}, /*#__PURE__*/ createElement(ChevronRightIcon, {
|
|
22697
|
+
createElement: createElement
|
|
22698
|
+
}))));
|
|
22699
|
+
};
|
|
22700
|
+
}
|
|
22701
|
+
function createCarouselToolComponent(param) {
|
|
22702
|
+
var createElement = param.createElement, Fragment = param.Fragment, useEffect = param.useEffect, useMemo = param.useMemo, useRef = param.useRef, useState = param.useState;
|
|
22703
|
+
var DefaultHeader = createHeaderComponent({
|
|
22704
|
+
createElement: createElement,
|
|
22705
|
+
Fragment: Fragment
|
|
21369
22706
|
});
|
|
21370
|
-
|
|
21371
|
-
|
|
21372
|
-
|
|
21373
|
-
|
|
21374
|
-
|
|
21375
|
-
|
|
21376
|
-
|
|
22707
|
+
var Carousel = createCarouselComponent({
|
|
22708
|
+
createElement: createElement,
|
|
22709
|
+
Fragment: Fragment,
|
|
22710
|
+
useEffect: useEffect,
|
|
22711
|
+
useRef: useRef
|
|
22712
|
+
});
|
|
22713
|
+
return function CarouselTool(userProps) {
|
|
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';
|
|
22717
|
+
var input = message === null || message === void 0 ? void 0 : message.input;
|
|
22718
|
+
var output = message === null || message === void 0 ? void 0 : message.output;
|
|
22719
|
+
var hits = (output === null || output === void 0 ? void 0 : output.hits) || [];
|
|
22720
|
+
var items = addQueryID(addAbsolutePosition(hits, 0, hits.length), output === null || output === void 0 ? void 0 : output.queryID);
|
|
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
|
|
21377
22741
|
]);
|
|
21378
|
-
var
|
|
21379
|
-
|
|
21380
|
-
|
|
21381
|
-
|
|
21382
|
-
|
|
21383
|
-
|
|
21384
|
-
|
|
21385
|
-
|
|
21386
|
-
|
|
21387
|
-
|
|
21388
|
-
|
|
21389
|
-
|
|
21390
|
-
|
|
21391
|
-
|
|
22742
|
+
var _useState = _sliced_to_array(useState(false), 2), canScrollLeft = _useState[0], setCanScrollLeft = _useState[1];
|
|
22743
|
+
var _useState1 = _sliced_to_array(useState(true), 2), canScrollRight = _useState1[0], setCanScrollRight = _useState1[1];
|
|
22744
|
+
var carouselIdRef = useRef('');
|
|
22745
|
+
if (!carouselIdRef.current) {
|
|
22746
|
+
carouselIdRef.current = generateCarouselId();
|
|
22747
|
+
}
|
|
22748
|
+
var carouselRefs = {
|
|
22749
|
+
listRef: useRef(null),
|
|
22750
|
+
nextButtonRef: useRef(null),
|
|
22751
|
+
previousButtonRef: useRef(null),
|
|
22752
|
+
carouselIdRef: carouselIdRef,
|
|
22753
|
+
canScrollLeft: canScrollLeft,
|
|
22754
|
+
canScrollRight: canScrollRight,
|
|
22755
|
+
setCanScrollLeft: setCanScrollLeft,
|
|
22756
|
+
setCanScrollRight: setCanScrollRight
|
|
22757
|
+
};
|
|
22758
|
+
var MemoedHeaderComponent = useMemo(function() {
|
|
22759
|
+
if (HeaderComponent) {
|
|
22760
|
+
return function(props) {
|
|
22761
|
+
return /*#__PURE__*/ createElement(HeaderComponent, _object_spread({
|
|
22762
|
+
showViewAll: showViewAll,
|
|
22763
|
+
nbHits: output === null || output === void 0 ? void 0 : output.nbHits,
|
|
22764
|
+
input: input,
|
|
22765
|
+
applyFilters: applyFilters,
|
|
22766
|
+
getSearchPageURL: getSearchPageURL,
|
|
22767
|
+
onClose: onClose
|
|
22768
|
+
}, props));
|
|
22769
|
+
};
|
|
22770
|
+
}
|
|
22771
|
+
return function(props) {
|
|
22772
|
+
return /*#__PURE__*/ createElement(DefaultHeader, _object_spread({
|
|
22773
|
+
showViewAll: showViewAll,
|
|
22774
|
+
nbHits: output === null || output === void 0 ? void 0 : output.nbHits,
|
|
22775
|
+
input: input,
|
|
22776
|
+
applyFilters: applyFilters,
|
|
22777
|
+
getSearchPageURL: getSearchPageURL,
|
|
22778
|
+
onClose: onClose
|
|
22779
|
+
}, props));
|
|
22780
|
+
};
|
|
22781
|
+
}, [
|
|
22782
|
+
showViewAll,
|
|
22783
|
+
HeaderComponent,
|
|
22784
|
+
output === null || output === void 0 ? void 0 : output.nbHits,
|
|
22785
|
+
input,
|
|
22786
|
+
applyFilters,
|
|
22787
|
+
getSearchPageURL,
|
|
22788
|
+
onClose
|
|
22789
|
+
]);
|
|
22790
|
+
return /*#__PURE__*/ createElement(Carousel, _object_spread_props(_object_spread({}, carouselRefs), {
|
|
22791
|
+
items: items,
|
|
22792
|
+
itemComponent: ItemComponent,
|
|
22793
|
+
headerComponent: MemoedHeaderComponent,
|
|
22794
|
+
showNavigation: false,
|
|
22795
|
+
sendEvent: sendEvent
|
|
22796
|
+
}));
|
|
21392
22797
|
};
|
|
21393
22798
|
}
|
|
21394
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
|
+
};
|
|
21395
22881
|
var DEFAULT_TRANSLATIONS$1 = {
|
|
21396
22882
|
streamingLabel: 'Curating results…'
|
|
21397
22883
|
};
|
|
21398
22884
|
function createDisplayResultsToolComponent(param) {
|
|
21399
|
-
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;
|
|
21400
22886
|
return function DisplayResultsTool(userProps) {
|
|
22887
|
+
var _ref;
|
|
21401
22888
|
var toolProps = userProps.toolProps, renderGroupCarousel = userProps.groupCarouselComponent, userTranslations = userProps.translations;
|
|
21402
|
-
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';
|
|
21403
22891
|
var translations = _object_spread({}, DEFAULT_TRANSLATIONS$1, userTranslations);
|
|
21404
|
-
var toolCallId = message === null || message === void 0 ? void 0 : message.toolCallId;
|
|
21405
22892
|
var hitsByObjectID = useMemo(function() {
|
|
21406
|
-
return messages ? getHitsByObjectID(messages,
|
|
22893
|
+
return messages ? getHitsByObjectID(messages, message) : undefined;
|
|
21407
22894
|
}, [
|
|
21408
22895
|
messages,
|
|
21409
|
-
|
|
22896
|
+
message
|
|
21410
22897
|
]);
|
|
21411
|
-
var
|
|
21412
|
-
var
|
|
21413
|
-
var
|
|
21414
|
-
var
|
|
21415
|
-
|
|
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) {
|
|
21416
22965
|
return /*#__PURE__*/ createElement(Fragment, null);
|
|
21417
22966
|
}
|
|
21418
22967
|
return /*#__PURE__*/ createElement("div", {
|
|
21419
22968
|
className: "ais-ChatToolDisplayResults"
|
|
21420
22969
|
}, intro && /*#__PURE__*/ createElement("div", {
|
|
21421
22970
|
className: "ais-ChatToolDisplayResults-intro"
|
|
21422
|
-
}, intro),
|
|
21423
|
-
var results = Array.isArray(group.results) ? group.results.filter(function(r) {
|
|
21424
|
-
return Boolean(r) && typeof r.objectID === 'string' && r.objectID !== '';
|
|
21425
|
-
}) : [];
|
|
21426
|
-
if (results.length === 0) return null;
|
|
21427
|
-
var items = results.map(function(result, idx) {
|
|
21428
|
-
var hydrated = hitsByObjectID === null || hitsByObjectID === void 0 ? void 0 : hitsByObjectID[result.objectID];
|
|
21429
|
-
return _object_spread_props(_object_spread({}, hydrated), {
|
|
21430
|
-
objectID: result.objectID,
|
|
21431
|
-
__position: idx + 1,
|
|
21432
|
-
__displayToolResult: result
|
|
21433
|
-
});
|
|
21434
|
-
});
|
|
22971
|
+
}, intro), renderableGroups.map(function(group) {
|
|
21435
22972
|
return /*#__PURE__*/ createElement("div", {
|
|
21436
|
-
key:
|
|
22973
|
+
key: group.key,
|
|
21437
22974
|
className: "ais-ChatToolDisplayResults-group"
|
|
21438
22975
|
}, group.title && /*#__PURE__*/ createElement("div", {
|
|
21439
22976
|
className: "ais-ChatToolDisplayResults-groupTitle"
|
|
21440
22977
|
}, group.title), group.why && /*#__PURE__*/ createElement("div", {
|
|
21441
22978
|
className: "ais-ChatToolDisplayResults-groupWhy"
|
|
21442
22979
|
}, group.why), renderGroupCarousel({
|
|
21443
|
-
items: items,
|
|
22980
|
+
items: group.items,
|
|
21444
22981
|
sendEvent: sendEvent
|
|
21445
22982
|
}));
|
|
21446
22983
|
}), isStreaming && /*#__PURE__*/ createElement("div", {
|
|
@@ -22580,7 +24117,7 @@
|
|
|
22580
24117
|
}));
|
|
22581
24118
|
}
|
|
22582
24119
|
|
|
22583
|
-
var
|
|
24120
|
+
var AutocompleteUiComponent = createAutocompleteComponent({
|
|
22584
24121
|
createElement: React.createElement,
|
|
22585
24122
|
Fragment: React.Fragment
|
|
22586
24123
|
});
|
|
@@ -22766,7 +24303,7 @@
|
|
|
22766
24303
|
setIsModalOpen: setIsModalOpen
|
|
22767
24304
|
};
|
|
22768
24305
|
}
|
|
22769
|
-
function
|
|
24306
|
+
function Autocomplete(props) {
|
|
22770
24307
|
var _showRecent_classNames, _showRecent_classNames1, _showRecent_classNames2, _showRecent_classNames3;
|
|
22771
24308
|
var indices = 'indices' in props ? props.indices : undefined;
|
|
22772
24309
|
var feeds = 'feeds' in props ? props.feeds : undefined;
|
|
@@ -22799,10 +24336,10 @@
|
|
|
22799
24336
|
var domId = useAutocompleteId();
|
|
22800
24337
|
var instanceKey = domId.replace(/:/g, '');
|
|
22801
24338
|
if (isFeedsMode && indices !== undefined) {
|
|
22802
|
-
throw new Error('
|
|
24339
|
+
throw new Error('Autocomplete: `feeds` and `indices` are mutually exclusive.');
|
|
22803
24340
|
}
|
|
22804
24341
|
if (isFeedsMode && !compositionID) {
|
|
22805
|
-
throw new Error('
|
|
24342
|
+
throw new Error('Autocomplete in feeds-mode requires a composition-based <InstantSearch> (compositionID must be set).');
|
|
22806
24343
|
}
|
|
22807
24344
|
var isSearchStalled = status === 'stalled';
|
|
22808
24345
|
var searchParameters = _object_spread({
|
|
@@ -23017,7 +24554,7 @@
|
|
|
23017
24554
|
}
|
|
23018
24555
|
setActivated(true);
|
|
23019
24556
|
};
|
|
23020
|
-
return /*#__PURE__*/ React.createElement(
|
|
24557
|
+
return /*#__PURE__*/ React.createElement(AutocompleteUiComponent, _object_spread_props(_object_spread({}, shellRootProps), {
|
|
23021
24558
|
classNames: classNames
|
|
23022
24559
|
}), isDetached ? /*#__PURE__*/ React.createElement(AutocompleteDetachedSearchButton, {
|
|
23023
24560
|
query: (_indexUiState_query = indexUiState.query) !== null && _indexUiState_query !== void 0 ? _indexUiState_query : '',
|
|
@@ -23060,7 +24597,7 @@
|
|
|
23060
24597
|
}));
|
|
23061
24598
|
if (isFeedsMode) {
|
|
23062
24599
|
return /*#__PURE__*/ React.createElement(Index, {
|
|
23063
|
-
|
|
24600
|
+
isolated: true,
|
|
23064
24601
|
indexName: compositionID,
|
|
23065
24602
|
indexId: "ais-autocomplete-".concat(instanceKey)
|
|
23066
24603
|
}, /*#__PURE__*/ React.createElement(Configure, searchParameters), /*#__PURE__*/ React.createElement(Feeds, {
|
|
@@ -23071,7 +24608,7 @@
|
|
|
23071
24608
|
}), innerAutocomplete);
|
|
23072
24609
|
}
|
|
23073
24610
|
return /*#__PURE__*/ React.createElement(Index, {
|
|
23074
|
-
|
|
24611
|
+
isolated: true,
|
|
23075
24612
|
indexId: "ais-autocomplete-".concat(instanceKey)
|
|
23076
24613
|
}, /*#__PURE__*/ React.createElement(Configure, searchParameters), indicesConfig.map(function(index) {
|
|
23077
24614
|
return /*#__PURE__*/ React.createElement(Index, {
|
|
@@ -23081,6 +24618,7 @@
|
|
|
23081
24618
|
}, /*#__PURE__*/ React.createElement(Configure, index.searchParameters));
|
|
23082
24619
|
}), innerAutocomplete);
|
|
23083
24620
|
}
|
|
24621
|
+
/** @deprecated use Autocomplete instead */ var EXPERIMENTAL_Autocomplete = deprecate(Autocomplete);
|
|
23084
24622
|
function InnerAutocomplete(_0) {
|
|
23085
24623
|
var indicesConfig = _0.indicesConfig, refineSearchBox = _0.refineSearchBox, isSearchStalled = _0.isSearchStalled, getSearchPageURL = _0.getSearchPageURL, userOnSelect = _0.onSelect, indexUiState = _0.indexUiState, isSearchPage = _0.isSearchPage, PanelComponent = _0.panelComponent, showRecent = _0.showRecent, recentSearchConfig = _0.recentSearchConfig, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, chatRenderState = _0.chatRenderState, transformItems = _0.transformItems, placeholder = _0.placeholder, autoFocus = _0.autoFocus, translations = _0.translations, classNames = _0.classNames, aiMode = _0.aiMode, domId = _0.domId, detached = _0.detached, props = _object_without_properties(_0, [
|
|
23086
24624
|
"indicesConfig",
|
|
@@ -23197,7 +24735,7 @@
|
|
|
23197
24735
|
if (chatRenderState) {
|
|
23198
24736
|
if (openChat(chatRenderState, {
|
|
23199
24737
|
message: item.prompt,
|
|
23200
|
-
referer: 'prompt-suggestions'
|
|
24738
|
+
referer: 'prompt-suggestions-autocomplete'
|
|
23201
24739
|
})) {
|
|
23202
24740
|
setQuery('');
|
|
23203
24741
|
}
|
|
@@ -23370,7 +24908,7 @@
|
|
|
23370
24908
|
"ref"
|
|
23371
24909
|
]);
|
|
23372
24910
|
if (isDetached) {
|
|
23373
|
-
return /*#__PURE__*/ React.createElement(
|
|
24911
|
+
return /*#__PURE__*/ React.createElement(AutocompleteUiComponent, _object_spread_props(_object_spread({}, props, rootProps), {
|
|
23374
24912
|
rootRef: rootRef,
|
|
23375
24913
|
classNames: classNames
|
|
23376
24914
|
}), /*#__PURE__*/ React.createElement(AutocompleteDetachedSearchButton, {
|
|
@@ -23396,7 +24934,7 @@
|
|
|
23396
24934
|
}, searchBoxContent), panelContent)));
|
|
23397
24935
|
}
|
|
23398
24936
|
// Normal (non-detached) rendering
|
|
23399
|
-
return /*#__PURE__*/ React.createElement(
|
|
24937
|
+
return /*#__PURE__*/ React.createElement(AutocompleteUiComponent, _object_spread_props(_object_spread({}, props, rootProps), {
|
|
23400
24938
|
rootRef: rootRef,
|
|
23401
24939
|
classNames: classNames
|
|
23402
24940
|
}), searchBoxContent, panelContent);
|
|
@@ -23512,7 +25050,9 @@
|
|
|
23512
25050
|
|
|
23513
25051
|
var CarouselUiComponent = createCarouselComponent({
|
|
23514
25052
|
createElement: React.createElement,
|
|
23515
|
-
Fragment: React.Fragment
|
|
25053
|
+
Fragment: React.Fragment,
|
|
25054
|
+
useEffect: React.useEffect,
|
|
25055
|
+
useRef: React.useRef
|
|
23516
25056
|
});
|
|
23517
25057
|
function Carousel(props) {
|
|
23518
25058
|
var _useState = _sliced_to_array(React.useState(false), 2), canScrollLeft = _useState[0], setCanScrollLeft = _useState[1];
|
|
@@ -23560,11 +25100,43 @@
|
|
|
23560
25100
|
var DisplayResultsUIComponent = createDisplayResultsToolComponent({
|
|
23561
25101
|
createElement: React.createElement,
|
|
23562
25102
|
Fragment: React.Fragment,
|
|
23563
|
-
|
|
25103
|
+
useEffect: React.useEffect,
|
|
25104
|
+
useMemo: React.useMemo,
|
|
25105
|
+
useRef: React.useRef
|
|
23564
25106
|
});
|
|
23565
25107
|
var Button = createButtonComponent({
|
|
23566
25108
|
createElement: React.createElement
|
|
23567
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
|
+
};
|
|
23568
25140
|
var DisplayResultsLayoutComponent = function DisplayResultsLayoutComponent(toolProps) {
|
|
23569
25141
|
return /*#__PURE__*/ React.createElement(DisplayResultsUIComponent, {
|
|
23570
25142
|
toolProps: toolProps,
|
|
@@ -23575,130 +25147,36 @@
|
|
|
23575
25147
|
itemComponent: itemComponent,
|
|
23576
25148
|
sendEvent: sendEvent,
|
|
23577
25149
|
showNavigation: false,
|
|
23578
|
-
headerComponent:
|
|
23579
|
-
var canScrollLeft = param.canScrollLeft, canScrollRight = param.canScrollRight, scrollLeft = param.scrollLeft, scrollRight = param.scrollRight;
|
|
23580
|
-
return /*#__PURE__*/ React.createElement("div", {
|
|
23581
|
-
className: "ais-ChatToolDisplayResultsCarouselHeader"
|
|
23582
|
-
}, /*#__PURE__*/ React.createElement("div", {
|
|
23583
|
-
className: "ais-ChatToolDisplayResultsCarouselHeaderCount"
|
|
23584
|
-
}, items.length, " result", items.length > 1 ? 's' : ''), /*#__PURE__*/ React.createElement("div", {
|
|
23585
|
-
className: "ais-ChatToolDisplayResultsCarouselHeaderScrollButtons"
|
|
23586
|
-
}, /*#__PURE__*/ React.createElement(Button, {
|
|
23587
|
-
variant: "outline",
|
|
23588
|
-
size: "sm",
|
|
23589
|
-
iconOnly: true,
|
|
23590
|
-
onClick: scrollLeft,
|
|
23591
|
-
disabled: !canScrollLeft,
|
|
23592
|
-
className: "ais-ChatToolDisplayResultsCarouselHeaderScrollButton"
|
|
23593
|
-
}, /*#__PURE__*/ React.createElement(ChevronLeftIcon, {
|
|
23594
|
-
createElement: React.createElement
|
|
23595
|
-
})), /*#__PURE__*/ React.createElement(Button, {
|
|
23596
|
-
variant: "outline",
|
|
23597
|
-
size: "sm",
|
|
23598
|
-
iconOnly: true,
|
|
23599
|
-
onClick: scrollRight,
|
|
23600
|
-
disabled: !canScrollRight,
|
|
23601
|
-
className: "ais-ChatToolDisplayResultsCarouselHeaderScrollButton"
|
|
23602
|
-
}, /*#__PURE__*/ React.createElement(ChevronRightIcon, {
|
|
23603
|
-
createElement: React.createElement
|
|
23604
|
-
}))));
|
|
23605
|
-
}
|
|
25150
|
+
headerComponent: DisplayResultsCarouselHeader
|
|
23606
25151
|
});
|
|
23607
25152
|
}
|
|
23608
25153
|
});
|
|
23609
25154
|
};
|
|
23610
25155
|
return {
|
|
23611
|
-
layoutComponent: DisplayResultsLayoutComponent
|
|
25156
|
+
layoutComponent: DisplayResultsLayoutComponent,
|
|
25157
|
+
streamInput: true
|
|
23612
25158
|
};
|
|
23613
25159
|
}
|
|
23614
25160
|
|
|
23615
25161
|
function createCarouselTool(showViewAll, itemComponent, getSearchPageURL) {
|
|
23616
|
-
var
|
|
23617
|
-
createElement: React.createElement
|
|
25162
|
+
var SearchLayoutUIComponent = createCarouselToolComponent({
|
|
25163
|
+
createElement: React.createElement,
|
|
25164
|
+
Fragment: React.Fragment,
|
|
25165
|
+
useEffect: React.useEffect,
|
|
25166
|
+
useMemo: React.useMemo,
|
|
25167
|
+
useRef: React.useRef,
|
|
25168
|
+
useState: React.useState
|
|
23618
25169
|
});
|
|
23619
|
-
function SearchLayoutComponent(
|
|
23620
|
-
|
|
23621
|
-
|
|
23622
|
-
|
|
23623
|
-
|
|
23624
|
-
|
|
23625
|
-
var hitsWithAbsolutePosition = addAbsolutePosition((output === null || output === void 0 ? void 0 : output.hits) || [], 0, ((_ref = input === null || input === void 0 ? void 0 : input.number_of_results) !== null && _ref !== void 0 ? _ref : output === null || output === void 0 ? void 0 : (_output_hits = output.hits) === null || _output_hits === void 0 ? void 0 : _output_hits.length) || 5);
|
|
23626
|
-
var items = addQueryID(hitsWithAbsolutePosition, output === null || output === void 0 ? void 0 : output.queryID);
|
|
23627
|
-
var MemoedHeaderComponent = React.useMemo(function() {
|
|
23628
|
-
return function(props) {
|
|
23629
|
-
return /*#__PURE__*/ React.createElement(HeaderComponent, _object_spread({
|
|
23630
|
-
nbHits: output === null || output === void 0 ? void 0 : output.nbHits,
|
|
23631
|
-
input: input,
|
|
23632
|
-
hitsPerPage: items.length,
|
|
23633
|
-
onClose: onClose,
|
|
23634
|
-
applyFilters: applyFilters
|
|
23635
|
-
}, props));
|
|
23636
|
-
};
|
|
23637
|
-
}, [
|
|
23638
|
-
items.length,
|
|
23639
|
-
input,
|
|
23640
|
-
output === null || output === void 0 ? void 0 : output.nbHits,
|
|
23641
|
-
applyFilters,
|
|
23642
|
-
onClose
|
|
23643
|
-
]);
|
|
23644
|
-
return /*#__PURE__*/ React.createElement(Carousel, {
|
|
23645
|
-
items: items,
|
|
25170
|
+
var SearchLayoutComponent = function SearchLayoutComponent(toolProps) {
|
|
25171
|
+
return /*#__PURE__*/ React.createElement(SearchLayoutUIComponent, {
|
|
25172
|
+
getSearchPageURL: getSearchPageURL,
|
|
25173
|
+
headerProps: {
|
|
25174
|
+
showViewAll: showViewAll
|
|
25175
|
+
},
|
|
23646
25176
|
itemComponent: itemComponent,
|
|
23647
|
-
|
|
23648
|
-
showNavigation: false,
|
|
23649
|
-
headerComponent: MemoedHeaderComponent
|
|
25177
|
+
toolProps: toolProps
|
|
23650
25178
|
});
|
|
23651
|
-
}
|
|
23652
|
-
function HeaderComponent(param) {
|
|
23653
|
-
var canScrollLeft = param.canScrollLeft, canScrollRight = param.canScrollRight, scrollLeft = param.scrollLeft, scrollRight = param.scrollRight, nbHits = param.nbHits, input = param.input, hitsPerPage = param.hitsPerPage, applyFilters = param.applyFilters, onClose = param.onClose;
|
|
23654
|
-
if ((hitsPerPage !== null && hitsPerPage !== void 0 ? hitsPerPage : 0) < 1) {
|
|
23655
|
-
return null;
|
|
23656
|
-
}
|
|
23657
|
-
return /*#__PURE__*/ React.createElement("div", {
|
|
23658
|
-
className: "ais-ChatToolSearchIndexCarouselHeader"
|
|
23659
|
-
}, /*#__PURE__*/ React.createElement("div", {
|
|
23660
|
-
className: "ais-ChatToolSearchIndexCarouselHeaderResults"
|
|
23661
|
-
}, nbHits && /*#__PURE__*/ React.createElement("div", {
|
|
23662
|
-
className: "ais-ChatToolSearchIndexCarouselHeaderCount"
|
|
23663
|
-
}, hitsPerPage !== null && hitsPerPage !== void 0 ? hitsPerPage : 0, " of ", nbHits.toLocaleString(), " result", nbHits > 1 ? 's' : ''), showViewAll && /*#__PURE__*/ React.createElement(Button, {
|
|
23664
|
-
variant: "ghost",
|
|
23665
|
-
size: "sm",
|
|
23666
|
-
onClick: function onClick() {
|
|
23667
|
-
if (!input || !applyFilters) return;
|
|
23668
|
-
var params = applyFilters({
|
|
23669
|
-
query: input.query,
|
|
23670
|
-
facetFilters: getFacetFiltersFromToolInput(input)
|
|
23671
|
-
});
|
|
23672
|
-
if (getSearchPageURL && new URL(getSearchPageURL(params)).pathname !== window.location.pathname) {
|
|
23673
|
-
window.location.href = getSearchPageURL(params);
|
|
23674
|
-
}
|
|
23675
|
-
onClose();
|
|
23676
|
-
},
|
|
23677
|
-
className: "ais-ChatToolSearchIndexCarouselHeaderViewAll"
|
|
23678
|
-
}, "View all", /*#__PURE__*/ React.createElement(ArrowRightIcon, {
|
|
23679
|
-
createElement: React.createElement
|
|
23680
|
-
}))), (hitsPerPage !== null && hitsPerPage !== void 0 ? hitsPerPage : 0) > 2 && /*#__PURE__*/ React.createElement("div", {
|
|
23681
|
-
className: "ais-ChatToolSearchIndexCarouselHeaderScrollButtons"
|
|
23682
|
-
}, /*#__PURE__*/ React.createElement(Button, {
|
|
23683
|
-
variant: "outline",
|
|
23684
|
-
size: "sm",
|
|
23685
|
-
iconOnly: true,
|
|
23686
|
-
onClick: scrollLeft,
|
|
23687
|
-
disabled: !canScrollLeft,
|
|
23688
|
-
className: "ais-ChatToolSearchIndexCarouselHeaderScrollButton"
|
|
23689
|
-
}, /*#__PURE__*/ React.createElement(ChevronLeftIcon, {
|
|
23690
|
-
createElement: React.createElement
|
|
23691
|
-
})), /*#__PURE__*/ React.createElement(Button, {
|
|
23692
|
-
variant: "outline",
|
|
23693
|
-
size: "sm",
|
|
23694
|
-
iconOnly: true,
|
|
23695
|
-
onClick: scrollRight,
|
|
23696
|
-
disabled: !canScrollRight,
|
|
23697
|
-
className: "ais-ChatToolSearchIndexCarouselHeaderScrollButton"
|
|
23698
|
-
}, /*#__PURE__*/ React.createElement(ChevronRightIcon, {
|
|
23699
|
-
createElement: React.createElement
|
|
23700
|
-
}))));
|
|
23701
|
-
}
|
|
25179
|
+
};
|
|
23702
25180
|
return {
|
|
23703
25181
|
layoutComponent: SearchLayoutComponent
|
|
23704
25182
|
};
|
|
@@ -23707,18 +25185,35 @@
|
|
|
23707
25185
|
var ChatUiComponent = createChatComponent({
|
|
23708
25186
|
createElement: React.createElement,
|
|
23709
25187
|
Fragment: React.Fragment,
|
|
23710
|
-
|
|
25188
|
+
useMemo: React.useMemo,
|
|
23711
25189
|
useState: React.useState
|
|
23712
25190
|
});
|
|
23713
25191
|
function createDefaultTools(itemComponent, getSearchPageURL) {
|
|
23714
25192
|
var _obj;
|
|
23715
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;
|
|
23716
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
|
+
}
|
|
23717
25212
|
function ChatInner(_0, _1) {
|
|
23718
25213
|
var _ref = [
|
|
23719
25214
|
_0,
|
|
23720
25215
|
_1
|
|
23721
|
-
], _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, [
|
|
23722
25217
|
"tools",
|
|
23723
25218
|
"headerProps",
|
|
23724
25219
|
"messagesProps",
|
|
@@ -23746,7 +25241,8 @@
|
|
|
23746
25241
|
"translations",
|
|
23747
25242
|
"title",
|
|
23748
25243
|
"getSearchPageURL",
|
|
23749
|
-
"disableTriggerValidation"
|
|
25244
|
+
"disableTriggerValidation",
|
|
25245
|
+
"showReasoning"
|
|
23750
25246
|
]), _rest1 = _sliced_to_array(_rest, 1), ref = _rest1[0];
|
|
23751
25247
|
var promptTranslations = translations.prompt, headerTranslations = translations.header, messageTranslations = translations.message, messagesTranslations = translations.messages;
|
|
23752
25248
|
var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, setIndexUiState = _useInstantSearch.setIndexUiState;
|
|
@@ -23758,7 +25254,7 @@
|
|
|
23758
25254
|
}), scrollRef = _useStickToBottom.scrollRef, contentRef = _useStickToBottom.contentRef, scrollToBottom = _useStickToBottom.scrollToBottom, isAtBottom = _useStickToBottom.isAtBottom;
|
|
23759
25255
|
var tools = React.useMemo(function() {
|
|
23760
25256
|
var defaults = createDefaultTools(itemComponent, getSearchPageURL);
|
|
23761
|
-
return
|
|
25257
|
+
return mergeToolOptions(defaults, userTools);
|
|
23762
25258
|
}, [
|
|
23763
25259
|
getSearchPageURL,
|
|
23764
25260
|
itemComponent,
|
|
@@ -23816,6 +25312,10 @@
|
|
|
23816
25312
|
if (error) {
|
|
23817
25313
|
throw error;
|
|
23818
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
|
+
]);
|
|
23819
25319
|
return /*#__PURE__*/ React.createElement(ChatUiComponent, {
|
|
23820
25320
|
title: title,
|
|
23821
25321
|
open: open,
|
|
@@ -23871,17 +25371,18 @@
|
|
|
23871
25371
|
errorComponent: messagesErrorComponent,
|
|
23872
25372
|
emptyComponent: emptyComponent,
|
|
23873
25373
|
actionsComponent: actionsComponent,
|
|
25374
|
+
translations: messagesTranslations,
|
|
25375
|
+
messageTranslations: messageTranslations
|
|
25376
|
+
}, restMessagesProps), {
|
|
23874
25377
|
assistantMessageProps: _object_spread({
|
|
23875
25378
|
leadingComponent: assistantMessageLeadingComponent,
|
|
23876
|
-
footerComponent: assistantMessageFooterComponent
|
|
23877
|
-
|
|
25379
|
+
footerComponent: assistantMessageFooterComponent,
|
|
25380
|
+
showReasoning: showReasoning
|
|
25381
|
+
}, callerAssistantMessageProps),
|
|
23878
25382
|
userMessageProps: _object_spread({
|
|
23879
25383
|
leadingComponent: userMessageLeadingComponent,
|
|
23880
25384
|
footerComponent: userMessageFooterComponent
|
|
23881
|
-
},
|
|
23882
|
-
translations: messagesTranslations,
|
|
23883
|
-
messageTranslations: messageTranslations
|
|
23884
|
-
}, messagesProps), {
|
|
25385
|
+
}, callerUserMessageProps),
|
|
23885
25386
|
error: error
|
|
23886
25387
|
}),
|
|
23887
25388
|
promptProps: _object_spread({
|
|
@@ -23917,6 +25418,55 @@
|
|
|
23917
25418
|
}
|
|
23918
25419
|
var Chat = /*#__PURE__*/ React.forwardRef(ChatInner);
|
|
23919
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
|
+
|
|
23920
25470
|
var ChatToggleButton = createChatToggleButtonComponent({
|
|
23921
25471
|
createElement: React.createElement,
|
|
23922
25472
|
Fragment: React.Fragment
|
|
@@ -25770,6 +27320,7 @@
|
|
|
25770
27320
|
return /*#__PURE__*/ React.createElement(FilterSuggestionsUiComponent, _object_spread({}, props, uiProps));
|
|
25771
27321
|
}
|
|
25772
27322
|
|
|
27323
|
+
exports.Autocomplete = Autocomplete;
|
|
25773
27324
|
exports.Breadcrumb = Breadcrumb;
|
|
25774
27325
|
exports.Carousel = Carousel;
|
|
25775
27326
|
exports.Chat = Chat;
|
|
@@ -25806,6 +27357,7 @@
|
|
|
25806
27357
|
exports.Pagination = Pagination;
|
|
25807
27358
|
exports.PonderToolType = PonderToolType;
|
|
25808
27359
|
exports.PoweredBy = PoweredBy;
|
|
27360
|
+
exports.PromptSuggestions = PromptSuggestions;
|
|
25809
27361
|
exports.RangeInput = RangeInput;
|
|
25810
27362
|
exports.RecommendToolType = RecommendToolType;
|
|
25811
27363
|
exports.RefinementList = RefinementList;
|
|
@@ -25845,6 +27397,7 @@
|
|
|
25845
27397
|
exports.useNumericMenu = useNumericMenu;
|
|
25846
27398
|
exports.usePagination = usePagination;
|
|
25847
27399
|
exports.usePoweredBy = usePoweredBy;
|
|
27400
|
+
exports.usePromptSuggestions = usePromptSuggestions;
|
|
25848
27401
|
exports.useQueryRules = useQueryRules;
|
|
25849
27402
|
exports.useRSCContext = useRSCContext;
|
|
25850
27403
|
exports.useRange = useRange;
|