react-instantsearch 7.46.0 → 7.48.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/widgets/Chat.js +22 -9
- package/dist/cjs/widgets/PromptSuggestions.js +2 -1
- package/dist/es/widgets/Chat.d.ts +10 -1
- package/dist/es/widgets/Chat.js +23 -10
- package/dist/es/widgets/PromptSuggestions.d.ts +1 -0
- package/dist/es/widgets/PromptSuggestions.js +2 -1
- package/dist/umd/ReactInstantSearch.js +1101 -498
- 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.48.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.48.0';
|
|
28
28
|
|
|
29
29
|
function _define_property(obj, key, value) {
|
|
30
30
|
if (key in obj) {
|
|
@@ -6715,23 +6715,33 @@
|
|
|
6715
6715
|
}
|
|
6716
6716
|
|
|
6717
6717
|
var nextMicroTask = Promise.resolve();
|
|
6718
|
-
function defer(callback
|
|
6718
|
+
function defer(callback, // arguments: the first caller of the window decides what the single run
|
|
6719
|
+
// receives. Pass this to fold every later argument into the pending ones
|
|
6720
|
+
// instead.
|
|
6721
|
+
mergeArguments) {
|
|
6719
6722
|
var progress = null;
|
|
6720
6723
|
var cancelled = false;
|
|
6724
|
+
var pendingArgs = null;
|
|
6721
6725
|
var fn = function fn() {
|
|
6722
6726
|
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
6723
6727
|
args[_key] = arguments[_key];
|
|
6724
6728
|
}
|
|
6725
6729
|
if (progress !== null) {
|
|
6730
|
+
if (mergeArguments && pendingArgs !== null) {
|
|
6731
|
+
pendingArgs = mergeArguments(pendingArgs, args);
|
|
6732
|
+
}
|
|
6726
6733
|
return;
|
|
6727
6734
|
}
|
|
6735
|
+
pendingArgs = args;
|
|
6728
6736
|
progress = nextMicroTask.then(function() {
|
|
6729
6737
|
progress = null;
|
|
6738
|
+
var runArgs = pendingArgs;
|
|
6739
|
+
pendingArgs = null;
|
|
6730
6740
|
if (cancelled) {
|
|
6731
6741
|
cancelled = false;
|
|
6732
6742
|
return;
|
|
6733
6743
|
}
|
|
6734
|
-
callback.apply(void 0, _to_consumable_array(
|
|
6744
|
+
callback.apply(void 0, _to_consumable_array(runArgs));
|
|
6735
6745
|
});
|
|
6736
6746
|
};
|
|
6737
6747
|
fn.wait = function() {
|
|
@@ -7614,22 +7624,18 @@
|
|
|
7614
7624
|
clearTimeout(cleanupTimerRef.current);
|
|
7615
7625
|
// Warning: if an unstable function prop is provided, `dequal` is not able
|
|
7616
7626
|
// to keep its reference and therefore will consider that props did change.
|
|
7617
|
-
// This
|
|
7618
|
-
//
|
|
7627
|
+
// This unintentionally replaces the widget, which is wasteful (it causes
|
|
7628
|
+
// a search), even though `updateWidget` below keeps its state.
|
|
7619
7629
|
// If users face this issue, we should advise them to provide stable function
|
|
7620
7630
|
// references.
|
|
7621
7631
|
var arePropsEqual = dequal(props, prevPropsRef.current);
|
|
7622
|
-
// If props did change, then we
|
|
7623
|
-
// and then add the widget back. This lets us add the widget without
|
|
7632
|
+
// If props did change, then we replace the widget instantly instead of
|
|
7624
7633
|
// waiting for the scheduled cleanup function to finish (that we canceled
|
|
7625
|
-
// above).
|
|
7634
|
+
// above). `updateWidget` hands the previous widget's `uiState` over to the
|
|
7635
|
+
// new one, so that a parameter change doesn't reset the state the widget
|
|
7636
|
+
// still owns — which would otherwise break routing.
|
|
7626
7637
|
if (!arePropsEqual) {
|
|
7627
|
-
parentIndex.
|
|
7628
|
-
previousWidget
|
|
7629
|
-
]);
|
|
7630
|
-
parentIndex.addWidgets([
|
|
7631
|
-
widget
|
|
7632
|
-
]);
|
|
7638
|
+
parentIndex.updateWidget(previousWidget, widget);
|
|
7633
7639
|
}
|
|
7634
7640
|
}
|
|
7635
7641
|
return function() {
|
|
@@ -7988,6 +7994,11 @@
|
|
|
7988
7994
|
return undefined;
|
|
7989
7995
|
}
|
|
7990
7996
|
|
|
7997
|
+
function reduceChildrenUiState(widgets, uiState, widgetUiStateOptions) {
|
|
7998
|
+
return widgets.reduce(function(state, widget) {
|
|
7999
|
+
return widget.getWidgetUiState ? widget.getWidgetUiState(state, widgetUiStateOptions) : state;
|
|
8000
|
+
}, uiState);
|
|
8001
|
+
}
|
|
7991
8002
|
function createFeedContainer(feedID, parentIndex, instantSearchInstance) {
|
|
7992
8003
|
var localWidgets = [];
|
|
7993
8004
|
var initialized = false;
|
|
@@ -8189,13 +8200,10 @@
|
|
|
8189
8200
|
},
|
|
8190
8201
|
getWidgetUiState: function getWidgetUiState(uiState) {
|
|
8191
8202
|
var helper = parentIndex.getHelper();
|
|
8192
|
-
|
|
8203
|
+
return reduceChildrenUiState(localWidgets, uiState, {
|
|
8193
8204
|
searchParameters: helper.state,
|
|
8194
8205
|
helper: helper
|
|
8195
|
-
};
|
|
8196
|
-
return localWidgets.reduce(function(state, widget) {
|
|
8197
|
-
return widget.getWidgetUiState ? widget.getWidgetUiState(state, widgetUiStateOptions) : state;
|
|
8198
|
-
}, uiState);
|
|
8206
|
+
});
|
|
8199
8207
|
},
|
|
8200
8208
|
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, param) {
|
|
8201
8209
|
var uiState = param.uiState;
|
|
@@ -8205,6 +8213,73 @@
|
|
|
8205
8213
|
}) : params;
|
|
8206
8214
|
}, searchParameters);
|
|
8207
8215
|
},
|
|
8216
|
+
updateWidget: function updateWidget(previousWidget, nextWidget) {
|
|
8217
|
+
var helper = parentIndex.getHelper();
|
|
8218
|
+
// The `uiState` the children own, read before the previous widget is
|
|
8219
|
+
// detached, so that the state it owns can be handed over to the next one.
|
|
8220
|
+
var previousUiState = helper ? reduceChildrenUiState(localWidgets, {}, {
|
|
8221
|
+
searchParameters: helper.state,
|
|
8222
|
+
helper: helper
|
|
8223
|
+
}) : {};
|
|
8224
|
+
previousWidget.parent = undefined;
|
|
8225
|
+
nextWidget.parent = container;
|
|
8226
|
+
// The next widget takes the place of the previous one, so that the order
|
|
8227
|
+
// in which children contribute to the search parameters is unchanged.
|
|
8228
|
+
var nextWidgets = localWidgets.slice();
|
|
8229
|
+
var position = nextWidgets.indexOf(previousWidget);
|
|
8230
|
+
if (position === -1) {
|
|
8231
|
+
nextWidgets.push(nextWidget);
|
|
8232
|
+
} else {
|
|
8233
|
+
nextWidgets[position] = nextWidget;
|
|
8234
|
+
}
|
|
8235
|
+
localWidgets = nextWidgets;
|
|
8236
|
+
if (!helper || !initialized) {
|
|
8237
|
+
return container;
|
|
8238
|
+
}
|
|
8239
|
+
// We still dispose the previous widget, for its side effects and so that
|
|
8240
|
+
// it drops the search parameters it declared on the parent helper.
|
|
8241
|
+
var cleanedState = helper.state;
|
|
8242
|
+
if (previousWidget.dispose) {
|
|
8243
|
+
var next = previousWidget.dispose({
|
|
8244
|
+
helper: helper,
|
|
8245
|
+
state: cleanedState,
|
|
8246
|
+
recommendState: helper.recommendState,
|
|
8247
|
+
parent: container
|
|
8248
|
+
});
|
|
8249
|
+
if (next && !_instanceof(next, algoliasearchHelper.RecommendParameters)) {
|
|
8250
|
+
cleanedState = next;
|
|
8251
|
+
}
|
|
8252
|
+
}
|
|
8253
|
+
// We hand the previous `uiState` over to the children, then read the
|
|
8254
|
+
// `uiState` back from them, so that state no mounted child claims anymore
|
|
8255
|
+
// is dropped. This mirrors the index widget's `updateWidget`.
|
|
8256
|
+
var narrowedUiState = reduceChildrenUiState(localWidgets, {}, {
|
|
8257
|
+
searchParameters: container.getWidgetSearchParameters(cleanedState, {
|
|
8258
|
+
uiState: previousUiState
|
|
8259
|
+
}),
|
|
8260
|
+
helper: helper
|
|
8261
|
+
});
|
|
8262
|
+
// The search parameters are then computed again from that narrowed
|
|
8263
|
+
// `uiState`, so that they can't hold state the `uiState` doesn't describe.
|
|
8264
|
+
var newState = container.getWidgetSearchParameters(cleanedState, {
|
|
8265
|
+
uiState: narrowedUiState
|
|
8266
|
+
});
|
|
8267
|
+
if (nextWidget.getRenderState) {
|
|
8268
|
+
var renderState = nextWidget.getRenderState(instantSearchInstance.renderState[container.getIndexId()] || {}, createInitArgs(instantSearchInstance, container, instantSearchInstance._initialUiState));
|
|
8269
|
+
storeRenderState({
|
|
8270
|
+
renderState: renderState,
|
|
8271
|
+
instantSearchInstance: instantSearchInstance,
|
|
8272
|
+
parent: container
|
|
8273
|
+
});
|
|
8274
|
+
}
|
|
8275
|
+
if (nextWidget.init) {
|
|
8276
|
+
nextWidget.init(createInitArgs(instantSearchInstance, container, instantSearchInstance._initialUiState));
|
|
8277
|
+
}
|
|
8278
|
+
if (newState !== helper.state) {
|
|
8279
|
+
helper.setState(newState);
|
|
8280
|
+
}
|
|
8281
|
+
return container;
|
|
8282
|
+
},
|
|
8208
8283
|
refreshUiState: function refreshUiState() {
|
|
8209
8284
|
// no-op: FeedContainer doesn't own UI state
|
|
8210
8285
|
},
|
|
@@ -8566,6 +8641,11 @@
|
|
|
8566
8641
|
var helper = null;
|
|
8567
8642
|
var derivedHelper = null;
|
|
8568
8643
|
var lastValidSearchParameters = null;
|
|
8644
|
+
// The error this index has already rolled back for. Renders also happen for
|
|
8645
|
+
// reasons unrelated to a search (a chat panel opening, a recommend result,
|
|
8646
|
+
// the stalled timer), and rolling back on every one of them would discard
|
|
8647
|
+
// state written after the failed search.
|
|
8648
|
+
var restoredForError;
|
|
8569
8649
|
var recomputeLocalRequestDependencies = function recomputeLocalRequestDependencies() {
|
|
8570
8650
|
if (localInstantSearchInstance) {
|
|
8571
8651
|
recomputeInstantSearchRequestDependencies(localInstantSearchInstance);
|
|
@@ -8705,6 +8785,92 @@
|
|
|
8705
8785
|
}
|
|
8706
8786
|
return this;
|
|
8707
8787
|
},
|
|
8788
|
+
updateWidget: function updateWidget(previousWidget, nextWidget) {
|
|
8789
|
+
if (typeof previousWidget.dispose !== 'function') {
|
|
8790
|
+
throw new Error(withUsage$u('The widget definition expects a `dispose` method.'));
|
|
8791
|
+
}
|
|
8792
|
+
if (typeof nextWidget.init !== 'function' && typeof nextWidget.render !== 'function') {
|
|
8793
|
+
throw new Error(withUsage$u('The widget definition expects a `render` and/or an `init` method.'));
|
|
8794
|
+
}
|
|
8795
|
+
// The `uiState` as it is before the previous widget is detached, so that
|
|
8796
|
+
// the state it owns can be handed over to the next widget.
|
|
8797
|
+
var previousUiState = localUiState;
|
|
8798
|
+
previousWidget.parent = undefined;
|
|
8799
|
+
nextWidget.parent = this;
|
|
8800
|
+
if (!isIndexWidget(nextWidget)) {
|
|
8801
|
+
addWidgetId(nextWidget);
|
|
8802
|
+
}
|
|
8803
|
+
// The next widget takes the place of the previous one, so that the order
|
|
8804
|
+
// in which widgets contribute to the search parameters is unchanged.
|
|
8805
|
+
var nextWidgets = localWidgets.slice();
|
|
8806
|
+
var position = nextWidgets.indexOf(previousWidget);
|
|
8807
|
+
if (position === -1) {
|
|
8808
|
+
nextWidgets.push(nextWidget);
|
|
8809
|
+
} else {
|
|
8810
|
+
nextWidgets[position] = nextWidget;
|
|
8811
|
+
}
|
|
8812
|
+
localWidgets = nextWidgets;
|
|
8813
|
+
recomputeLocalRequestDependencies();
|
|
8814
|
+
if (!localInstantSearchInstance) {
|
|
8815
|
+
return this;
|
|
8816
|
+
}
|
|
8817
|
+
// We still dispose the previous widget, for its side effects. The search
|
|
8818
|
+
// state it returns is only used as a base when shared state isn't preserved
|
|
8819
|
+
// on unmount, like in `removeWidgets`.
|
|
8820
|
+
var disposedState = previousWidget.dispose({
|
|
8821
|
+
helper: helper,
|
|
8822
|
+
state: helper.state,
|
|
8823
|
+
recommendState: helper.recommendState,
|
|
8824
|
+
parent: this
|
|
8825
|
+
});
|
|
8826
|
+
var cleanedRecommendState = _instanceof(disposedState, algoliasearchHelper.RecommendParameters) ? disposedState : helper.recommendState;
|
|
8827
|
+
var cleanedSearchState = disposedState && !_instanceof(disposedState, algoliasearchHelper.RecommendParameters) ? disposedState : helper.state;
|
|
8828
|
+
var initialSearchParameters = localInstantSearchInstance.future.preserveSharedStateOnUnmount ? new algoliasearchHelper.SearchParameters({
|
|
8829
|
+
index: this.getIndexName()
|
|
8830
|
+
}) : cleanedSearchState;
|
|
8831
|
+
// We hand the previous `uiState` over to the next widgets, then read the
|
|
8832
|
+
// `uiState` back from them. Widgets only pick up the state they claim, so
|
|
8833
|
+
// this drops state that no mounted widget owns anymore (an attribute that
|
|
8834
|
+
// changed, for instance) instead of seeding it with `previousUiState`.
|
|
8835
|
+
localUiState = getLocalWidgetsUiState(localWidgets, {
|
|
8836
|
+
searchParameters: getLocalWidgetsSearchParameters(localWidgets, {
|
|
8837
|
+
uiState: previousUiState,
|
|
8838
|
+
initialSearchParameters: initialSearchParameters
|
|
8839
|
+
}),
|
|
8840
|
+
helper: helper
|
|
8841
|
+
});
|
|
8842
|
+
// The search parameters are then computed again from that narrowed
|
|
8843
|
+
// `uiState`, so that they can't hold state the `uiState` doesn't describe.
|
|
8844
|
+
var newState = getLocalWidgetsSearchParameters(localWidgets, {
|
|
8845
|
+
uiState: localUiState,
|
|
8846
|
+
initialSearchParameters: initialSearchParameters
|
|
8847
|
+
});
|
|
8848
|
+
privateHelperSetState(helper, {
|
|
8849
|
+
state: newState,
|
|
8850
|
+
recommendState: getLocalWidgetsRecommendParameters(localWidgets, {
|
|
8851
|
+
uiState: localUiState,
|
|
8852
|
+
initialRecommendParameters: cleanedRecommendState
|
|
8853
|
+
}),
|
|
8854
|
+
_uiState: localUiState
|
|
8855
|
+
});
|
|
8856
|
+
if (nextWidget.getRenderState) {
|
|
8857
|
+
var renderState = nextWidget.getRenderState(localInstantSearchInstance.renderState[this.getIndexId()] || {}, createInitArgs(localInstantSearchInstance, this, localInstantSearchInstance._initialUiState));
|
|
8858
|
+
storeRenderState({
|
|
8859
|
+
renderState: renderState,
|
|
8860
|
+
instantSearchInstance: localInstantSearchInstance,
|
|
8861
|
+
parent: this
|
|
8862
|
+
});
|
|
8863
|
+
}
|
|
8864
|
+
if (nextWidget.init) {
|
|
8865
|
+
nextWidget.init(createInitArgs(localInstantSearchInstance, this, localInstantSearchInstance._initialUiState));
|
|
8866
|
+
}
|
|
8867
|
+
if (isolated) {
|
|
8868
|
+
this.scheduleLocalSearch();
|
|
8869
|
+
} else {
|
|
8870
|
+
localInstantSearchInstance.scheduleSearch();
|
|
8871
|
+
}
|
|
8872
|
+
return this;
|
|
8873
|
+
},
|
|
8708
8874
|
removeWidgets: function removeWidgets(widgets) {
|
|
8709
8875
|
var _this = this;
|
|
8710
8876
|
if (!Array.isArray(widgets)) {
|
|
@@ -8956,7 +9122,10 @@
|
|
|
8956
9122
|
var instantSearchInstance = param.instantSearchInstance;
|
|
8957
9123
|
// we can't attach a listener to the error event of search, as the error
|
|
8958
9124
|
// then would no longer be thrown for global handlers.
|
|
8959
|
-
if (instantSearchInstance.status
|
|
9125
|
+
if (instantSearchInstance.status !== 'error') {
|
|
9126
|
+
restoredForError = undefined;
|
|
9127
|
+
} else if (instantSearchInstance.error !== restoredForError && !instantSearchInstance.mainHelper.hasPendingRequests() && lastValidSearchParameters) {
|
|
9128
|
+
restoredForError = instantSearchInstance.error;
|
|
8960
9129
|
helper.setState(lastValidSearchParameters);
|
|
8961
9130
|
}
|
|
8962
9131
|
// We only render index widgets if there are no results.
|
|
@@ -9223,7 +9392,7 @@
|
|
|
9223
9392
|
});
|
|
9224
9393
|
}
|
|
9225
9394
|
|
|
9226
|
-
var version = '4.
|
|
9395
|
+
var version = '4.115.0';
|
|
9227
9396
|
|
|
9228
9397
|
var ANONYMOUS_TOKEN_COOKIE_KEY = '_ALGOLIA';
|
|
9229
9398
|
function getCookie(name) {
|
|
@@ -11135,6 +11304,14 @@
|
|
|
11135
11304
|
instantSearchInstance: _this
|
|
11136
11305
|
});
|
|
11137
11306
|
_this.emit('render');
|
|
11307
|
+
}, // status reset accumulates instead of letting the first caller decide: a
|
|
11308
|
+
// render scheduled for a reason unrelated to the search must not cancel the
|
|
11309
|
+
// one a search result asks for, or it would strand the status on `loading`.
|
|
11310
|
+
function(param, param1) {
|
|
11311
|
+
var _param = _sliced_to_array(param, 1), tmp = _param[0], shouldResetStatus = tmp === void 0 ? true : tmp, _param1 = _sliced_to_array(param1, 1), tmp1 = _param1[0], nextShouldResetStatus = tmp1 === void 0 ? true : tmp1;
|
|
11312
|
+
return [
|
|
11313
|
+
shouldResetStatus || nextShouldResetStatus
|
|
11314
|
+
];
|
|
11138
11315
|
})), _define_property(_this, "onInternalStateChange", defer(function() {
|
|
11139
11316
|
var nextUiState = _this.mainIndex.getWidgetUiState({});
|
|
11140
11317
|
_this.middleware.forEach(function(param) {
|
|
@@ -13989,27 +14166,132 @@
|
|
|
13989
14166
|
* Resolves the tool a message part belongs to, from either a part type
|
|
13990
14167
|
* (`tool-algolia_search_index`) or a bare tool name.
|
|
13991
14168
|
*
|
|
13992
|
-
*
|
|
13993
|
-
*
|
|
13994
|
-
*
|
|
14169
|
+
* An exact registration wins. Otherwise only tools whose `matchesToolName`
|
|
14170
|
+
* claims the name are considered, most specific first, for servers that name a
|
|
14171
|
+
* call after the registered tool: the Algolia MCP Server appends the index name
|
|
14172
|
+
* (`algolia_search_index_products`).
|
|
14173
|
+
*
|
|
14174
|
+
* Generic over the tool shape: the renderer, the loader, the widget and the
|
|
14175
|
+
* connector hold different subsets of the tool contract.
|
|
13995
14176
|
*/ var findTool = function findTool(partType, tools) {
|
|
13996
14177
|
var toolName = startsWith(partType, TOOL_PART_PREFIX) ? partType.slice(TOOL_PART_PREFIX.length) : partType;
|
|
13997
14178
|
if (tools[toolName]) {
|
|
13998
14179
|
return tools[toolName];
|
|
13999
14180
|
}
|
|
14000
|
-
|
|
14001
|
-
|
|
14002
|
-
|
|
14003
|
-
|
|
14004
|
-
|
|
14005
|
-
|
|
14006
|
-
|
|
14007
|
-
|
|
14008
|
-
|
|
14181
|
+
var claimants = Object.keys(tools).filter(function(key) {
|
|
14182
|
+
var _tools_key_matchesToolName, _tools_key;
|
|
14183
|
+
return Boolean((_tools_key = tools[key]) === null || _tools_key === void 0 ? void 0 : (_tools_key_matchesToolName = _tools_key.matchesToolName) === null || _tools_key_matchesToolName === void 0 ? void 0 : _tools_key_matchesToolName.call(_tools_key, toolName));
|
|
14184
|
+
});
|
|
14185
|
+
if (claimants.length === 0) {
|
|
14186
|
+
return undefined;
|
|
14187
|
+
}
|
|
14188
|
+
// Most specific claim wins, ties by name, so the winner doesn't depend on
|
|
14189
|
+
// registration order.
|
|
14190
|
+
claimants.sort(function(a, b) {
|
|
14191
|
+
return b.length - a.length || (a < b ? -1 : 1);
|
|
14009
14192
|
});
|
|
14010
|
-
return
|
|
14193
|
+
return tools[claimants[0]];
|
|
14011
14194
|
};
|
|
14012
14195
|
var FACET_KEY_PREFIX = 'facet_';
|
|
14196
|
+
/**
|
|
14197
|
+
* A numeric facet value as the Algolia MCP Server emits it: an operator
|
|
14198
|
+
* followed by a number (`'<=1500'`). Mirrors that server's own
|
|
14199
|
+
* `NUMERIC_FILTER_REGEX` so the two sides cannot drift.
|
|
14200
|
+
*/ var NUMERIC_FACET_VALUE = /^(<=|>=|=|!=|<|>)\s*(-?\d+(\.\d+)?)$/;
|
|
14201
|
+
var isNumericFacetValues = function isNumericFacetValues(values) {
|
|
14202
|
+
return values.length > 0 && values.every(function(value) {
|
|
14203
|
+
return NUMERIC_FACET_VALUE.test(value);
|
|
14204
|
+
});
|
|
14205
|
+
};
|
|
14206
|
+
/**
|
|
14207
|
+
* The key the Algolia MCP Server attaches its resolved search parameters under,
|
|
14208
|
+
* on the tool result's `_meta`. Agent Studio forwards this one key to the
|
|
14209
|
+
* browser by allowlist, as a `data-tool-output-metadata` part correlated by
|
|
14210
|
+
* `toolCallId`.
|
|
14211
|
+
*
|
|
14212
|
+
* These params are the filters the server actually searched with, after
|
|
14213
|
+
* defaults, clamping and the allow-list — including ones the model never saw.
|
|
14214
|
+
* That makes them exact where the raw `facet_` keys are ambiguous.
|
|
14215
|
+
*/ var RESOLVED_SEARCH_PARAMS_META_KEY = 'com.algolia/resolved-search-params';
|
|
14216
|
+
var TOOL_OUTPUT_METADATA_PART_TYPE = 'data-tool-output-metadata';
|
|
14217
|
+
var isStringArray = function isStringArray(value) {
|
|
14218
|
+
return Array.isArray(value) && value.every(function(item) {
|
|
14219
|
+
return typeof item === 'string';
|
|
14220
|
+
});
|
|
14221
|
+
};
|
|
14222
|
+
var RESOLVED_SEARCH_PARAMS_KEYS = [
|
|
14223
|
+
'query',
|
|
14224
|
+
'facetFilters',
|
|
14225
|
+
'numericFilters'
|
|
14226
|
+
];
|
|
14227
|
+
/**
|
|
14228
|
+
* Recognizes a single resolved-params bag by shape.
|
|
14229
|
+
*
|
|
14230
|
+
* The server attaches the same `_meta` key in three shapes: one bag for a
|
|
14231
|
+
* single-index search, one bag per variation (an array) for a bulk search, and
|
|
14232
|
+
* a per-index map for a multi-index search. Only the single bag can be read
|
|
14233
|
+
* here. An array or a map parses to nothing, and an empty bag would still beat
|
|
14234
|
+
* the raw `facet_` keys and search with the query alone — so the other two
|
|
14235
|
+
* shapes are left to the fallback path instead.
|
|
14236
|
+
*/ var isResolvedSearchParamsBag = function isResolvedSearchParamsBag(value) {
|
|
14237
|
+
return (typeof value === "undefined" ? "undefined" : _type_of(value)) === 'object' && value !== null && !Array.isArray(value) && RESOLVED_SEARCH_PARAMS_KEYS.some(function(key) {
|
|
14238
|
+
return key in value;
|
|
14239
|
+
});
|
|
14240
|
+
};
|
|
14241
|
+
/**
|
|
14242
|
+
* Reads the resolved search params a search tool call was answered with.
|
|
14243
|
+
*
|
|
14244
|
+
* The metadata arrives as a transient data part next to the tool call. It is
|
|
14245
|
+
* read from `messages` rather than through `onData` because the chat retains
|
|
14246
|
+
* every `data-*` part on the message, which covers the live and the replayed
|
|
14247
|
+
* conversation with one path. Returns `undefined` when the part is absent —
|
|
14248
|
+
* the case whenever the server does not emit `_meta` — or when its value is
|
|
14249
|
+
* not a single params bag, so that the caller falls back to the raw
|
|
14250
|
+
* `facet_` keys instead of searching with no filters at all.
|
|
14251
|
+
*/ var getResolvedSearchParams = function getResolvedSearchParams(messages, toolCallId) {
|
|
14252
|
+
if (!messages || !toolCallId) {
|
|
14253
|
+
return undefined;
|
|
14254
|
+
}
|
|
14255
|
+
// Newest first: a re-answered tool call should win over its earlier result.
|
|
14256
|
+
for(var i = messages.length - 1; i >= 0; i--){
|
|
14257
|
+
var _messages_i;
|
|
14258
|
+
var parts = (_messages_i = messages[i]) === null || _messages_i === void 0 ? void 0 : _messages_i.parts;
|
|
14259
|
+
if (!Array.isArray(parts)) {
|
|
14260
|
+
continue;
|
|
14261
|
+
}
|
|
14262
|
+
for(var j = parts.length - 1; j >= 0; j--){
|
|
14263
|
+
var _data_metadata;
|
|
14264
|
+
var part = parts[j];
|
|
14265
|
+
if (!part || part.type !== TOOL_OUTPUT_METADATA_PART_TYPE) {
|
|
14266
|
+
continue;
|
|
14267
|
+
}
|
|
14268
|
+
var data = part.data;
|
|
14269
|
+
if ((data === null || data === void 0 ? void 0 : data.toolCallId) !== toolCallId) {
|
|
14270
|
+
continue;
|
|
14271
|
+
}
|
|
14272
|
+
var resolved = (_data_metadata = data.metadata) === null || _data_metadata === void 0 ? void 0 : _data_metadata[RESOLVED_SEARCH_PARAMS_META_KEY];
|
|
14273
|
+
if (!isResolvedSearchParamsBag(resolved)) {
|
|
14274
|
+
continue;
|
|
14275
|
+
}
|
|
14276
|
+
// Algolia reads a plain string entry as its own group, and the search
|
|
14277
|
+
// tool's schema accepts that mixed form
|
|
14278
|
+
// (`['category:Books', ['author:Alice', 'author:Bob']]`), so a flat
|
|
14279
|
+
// entry is a normal producer output.
|
|
14280
|
+
var facetFilters = Array.isArray(resolved.facetFilters) ? resolved.facetFilters.map(function(entry) {
|
|
14281
|
+
return typeof entry === 'string' ? [
|
|
14282
|
+
entry
|
|
14283
|
+
] : entry;
|
|
14284
|
+
}).filter(isStringArray) : undefined;
|
|
14285
|
+
var numericFilters = isStringArray(resolved.numericFilters) ? resolved.numericFilters : undefined;
|
|
14286
|
+
return {
|
|
14287
|
+
query: typeof resolved.query === 'string' ? resolved.query : undefined,
|
|
14288
|
+
facetFilters: facetFilters && facetFilters.length > 0 ? facetFilters : undefined,
|
|
14289
|
+
numericFilters: numericFilters && numericFilters.length > 0 ? numericFilters : undefined
|
|
14290
|
+
};
|
|
14291
|
+
}
|
|
14292
|
+
}
|
|
14293
|
+
return undefined;
|
|
14294
|
+
};
|
|
14013
14295
|
var hasQueries = function hasQueries(input) {
|
|
14014
14296
|
return Array.isArray(input.queries);
|
|
14015
14297
|
};
|
|
@@ -14028,18 +14310,41 @@
|
|
|
14028
14310
|
}
|
|
14029
14311
|
var facetFilters = Object.entries(query).reduce(function(acc, param) {
|
|
14030
14312
|
var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
14031
|
-
if (!startsWith(key, FACET_KEY_PREFIX)
|
|
14313
|
+
if (!startsWith(key, FACET_KEY_PREFIX)) {
|
|
14032
14314
|
return acc;
|
|
14033
14315
|
}
|
|
14034
14316
|
var attribute = key.slice(FACET_KEY_PREFIX.length);
|
|
14317
|
+
if (!attribute) {
|
|
14318
|
+
return acc;
|
|
14319
|
+
}
|
|
14320
|
+
// A boolean facet arrives as a primitive, not an array.
|
|
14321
|
+
if (typeof value === 'boolean') {
|
|
14322
|
+
acc.push([
|
|
14323
|
+
"".concat(attribute, ":").concat(value)
|
|
14324
|
+
]);
|
|
14325
|
+
return acc;
|
|
14326
|
+
}
|
|
14327
|
+
if (!Array.isArray(value)) {
|
|
14328
|
+
return acc;
|
|
14329
|
+
}
|
|
14035
14330
|
var values = value.filter(function(item) {
|
|
14036
14331
|
return typeof item === 'string';
|
|
14037
14332
|
});
|
|
14038
|
-
if (
|
|
14039
|
-
acc
|
|
14040
|
-
return "".concat(attribute, ":").concat(item);
|
|
14041
|
-
}));
|
|
14333
|
+
if (values.length === 0) {
|
|
14334
|
+
return acc;
|
|
14042
14335
|
}
|
|
14336
|
+
// A numeric facet needs a numeric refinement, which this shape cannot
|
|
14337
|
+
// express. `price:<=1500` would refine on a value no record holds, so the
|
|
14338
|
+
// search would quietly return the wrong results. Dropping it loses the
|
|
14339
|
+
// filter instead, which the user can see. Where the tool's resolved
|
|
14340
|
+
// search params are available, `getResolvedSearchParams` applies the
|
|
14341
|
+
// numeric refinement properly and this path is not reached.
|
|
14342
|
+
if (isNumericFacetValues(values)) {
|
|
14343
|
+
return acc;
|
|
14344
|
+
}
|
|
14345
|
+
acc.push(values.map(function(item) {
|
|
14346
|
+
return "".concat(attribute, ":").concat(item);
|
|
14347
|
+
}));
|
|
14043
14348
|
return acc;
|
|
14044
14349
|
}, []);
|
|
14045
14350
|
return facetFilters.length > 0 ? facetFilters : undefined;
|
|
@@ -14052,15 +14357,31 @@
|
|
|
14052
14357
|
* Algolia MCP Server search tool instead expresses refinements as individual
|
|
14053
14358
|
* `facet_<attribute>` keys (e.g. `facet_categories: ['Books', 'Toys']`), which
|
|
14054
14359
|
* are converted here into `[['attribute:value']]`.
|
|
14055
|
-
|
|
14360
|
+
*
|
|
14361
|
+
* Pass `resolved` (from `getResolvedSearchParams`) to use the filters the
|
|
14362
|
+
* server actually searched with instead of re-deriving them from the raw keys.
|
|
14363
|
+
* That is the only way to apply a numeric refinement.
|
|
14364
|
+
*/ var getApplyFiltersParamsFromToolInput = function getApplyFiltersParamsFromToolInput(input, resolved) {
|
|
14056
14365
|
var query = getSearchToolQuery(input);
|
|
14366
|
+
// The resolved params are what the server actually searched with, so they win
|
|
14367
|
+
// wherever they exist. Only they can express a numeric refinement: a numeric
|
|
14368
|
+
// facet and a string facet whose value is literally `'<=1500'` are identical
|
|
14369
|
+
// in the raw `facet_` keys.
|
|
14370
|
+
if (resolved) {
|
|
14371
|
+
var _resolved_query;
|
|
14372
|
+
return {
|
|
14373
|
+
query: (_resolved_query = resolved.query) !== null && _resolved_query !== void 0 ? _resolved_query : query === null || query === void 0 ? void 0 : query.query,
|
|
14374
|
+
facetFilters: resolved.facetFilters,
|
|
14375
|
+
numericFilters: resolved.numericFilters
|
|
14376
|
+
};
|
|
14377
|
+
}
|
|
14057
14378
|
return {
|
|
14058
14379
|
query: query === null || query === void 0 ? void 0 : query.query,
|
|
14059
14380
|
facetFilters: getFacetFilters(query)
|
|
14060
14381
|
};
|
|
14061
14382
|
};
|
|
14062
14383
|
|
|
14063
|
-
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}
|
|
14384
|
+
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 t={blockQuote:"0",breakLine:"1",breakThematic:"2",codeBlock:"3",codeFenced:"4",codeInline:"5",footnote:"6",footnoteReference:"7",gfmTask:"8",heading:"9",headingSetext:"10",htmlBlock:"11",htmlComment:"12",htmlSelfClosing:"13",image:"14",link:"15",linkAngleBraceStyleDetector:"16",linkBareUrlDetector:"17",linkMailtoDetector:"18",newlineCoalescer:"19",orderedList:"20",paragraph:"21",ref:"22",refImage:"23",refLink:"24",table:"25",tableSeparator:"26",text:"27",textBolded:"28",textEmphasized:"29",textEscaped:"30",textMarked:"31",textStrikethroughed:"32",unorderedList:"33"},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}
|
|
14064
14385
|
|
|
14065
14386
|
var createRecords = function createRecords() {
|
|
14066
14387
|
return Object.create(null);
|
|
@@ -14119,18 +14440,39 @@
|
|
|
14119
14440
|
function createChatMessageReasoningComponent(param) {
|
|
14120
14441
|
var createElement = param.createElement;
|
|
14121
14442
|
return function ChatMessageReasoning(userProps) {
|
|
14122
|
-
var
|
|
14123
|
-
var
|
|
14124
|
-
|
|
14125
|
-
|
|
14126
|
-
})
|
|
14127
|
-
|
|
14128
|
-
|
|
14129
|
-
|
|
14443
|
+
var parts = userProps.parts, hidden = userProps.hidden, _userProps_parseMarkdown = userProps.parseMarkdown, parseMarkdown = _userProps_parseMarkdown === void 0 ? true : _userProps_parseMarkdown, translations = userProps.translations, classNames = userProps.classNames;
|
|
14444
|
+
var activePart = parts.find(function(param) {
|
|
14445
|
+
var isStreaming = param.isStreaming;
|
|
14446
|
+
return isStreaming;
|
|
14447
|
+
});
|
|
14448
|
+
var isStreaming = Boolean(activePart);
|
|
14449
|
+
var hasActiveHint = Boolean(activePart === null || activePart === void 0 ? void 0 : activePart.part.text.trim());
|
|
14450
|
+
var renderPart = function renderPart(param) {
|
|
14451
|
+
var part = param.part;
|
|
14452
|
+
return parseMarkdown ? We(part.text, {
|
|
14453
|
+
createElement: createElement,
|
|
14454
|
+
disableParsingRawHTML: true
|
|
14455
|
+
}) : /*#__PURE__*/ createElement("p", {
|
|
14456
|
+
className: "ais-ChatMessage-text"
|
|
14457
|
+
}, part.text);
|
|
14458
|
+
};
|
|
14459
|
+
var renderHint = function renderHint(part) {
|
|
14460
|
+
return parseMarkdown ? We(part.text, {
|
|
14461
|
+
createElement: createElement,
|
|
14462
|
+
forceInline: true,
|
|
14463
|
+
renderRule: function renderRule(next, node) {
|
|
14464
|
+
if (node.type === t.htmlBlock || node.type === t.htmlComment || node.type === t.htmlSelfClosing) {
|
|
14465
|
+
return null;
|
|
14466
|
+
}
|
|
14467
|
+
return next();
|
|
14468
|
+
}
|
|
14469
|
+
}) : part.text;
|
|
14470
|
+
};
|
|
14130
14471
|
return /*#__PURE__*/ createElement("details", {
|
|
14131
14472
|
className: cx(classNames.reasoning),
|
|
14132
14473
|
"aria-label": translations.reasoningLabel,
|
|
14133
|
-
"aria-busy": isStreaming
|
|
14474
|
+
"aria-busy": isStreaming,
|
|
14475
|
+
hidden: hidden
|
|
14134
14476
|
}, /*#__PURE__*/ createElement("summary", {
|
|
14135
14477
|
className: cx(classNames.reasoningHeader)
|
|
14136
14478
|
}, /*#__PURE__*/ createElement("span", {
|
|
@@ -14140,17 +14482,29 @@
|
|
|
14140
14482
|
createElement: createElement
|
|
14141
14483
|
})), /*#__PURE__*/ createElement("span", {
|
|
14142
14484
|
className: cx(classNames.reasoningLabel)
|
|
14143
|
-
}, translations.reasoningLabel), /*#__PURE__*/ createElement("span", {
|
|
14485
|
+
}, translations.reasoningLabel), activePart && hasActiveHint && /*#__PURE__*/ createElement("span", {
|
|
14486
|
+
className: "ais-ChatMessageReasoning-status",
|
|
14487
|
+
"aria-hidden": "true"
|
|
14488
|
+
}, /*#__PURE__*/ createElement("span", {
|
|
14489
|
+
className: "ais-ChatMessageReasoning-separator"
|
|
14490
|
+
}, "\xb7"), /*#__PURE__*/ createElement("span", {
|
|
14491
|
+
className: "ais-ChatMessageReasoning-hint"
|
|
14492
|
+
}, renderHint(activePart.part))), /*#__PURE__*/ createElement("span", {
|
|
14144
14493
|
className: cx(classNames.reasoningChevron),
|
|
14145
14494
|
"aria-hidden": "true"
|
|
14146
14495
|
}, /*#__PURE__*/ createElement(ChevronDownIcon, {
|
|
14147
14496
|
createElement: createElement
|
|
14148
14497
|
}))), /*#__PURE__*/ createElement("div", {
|
|
14149
|
-
className: cx(classNames.reasoningBody)
|
|
14150
|
-
|
|
14151
|
-
}, /*#__PURE__*/ createElement("div", {
|
|
14498
|
+
className: cx(classNames.reasoningBody)
|
|
14499
|
+
}, /*#__PURE__*/ createElement("ol", {
|
|
14152
14500
|
className: cx(classNames.reasoningText)
|
|
14153
|
-
},
|
|
14501
|
+
}, parts.map(function(reasoningPart) {
|
|
14502
|
+
return /*#__PURE__*/ createElement("li", {
|
|
14503
|
+
key: reasoningPart.partIndex,
|
|
14504
|
+
className: "ais-ChatMessageReasoning-item",
|
|
14505
|
+
"aria-current": reasoningPart.isStreaming ? 'step' : undefined
|
|
14506
|
+
}, renderPart(reasoningPart));
|
|
14507
|
+
}))));
|
|
14154
14508
|
};
|
|
14155
14509
|
}
|
|
14156
14510
|
|
|
@@ -14183,8 +14537,8 @@
|
|
|
14183
14537
|
createElement: createElement
|
|
14184
14538
|
});
|
|
14185
14539
|
return function ChatMessage(userProps) {
|
|
14186
|
-
var _messages_;
|
|
14187
|
-
var _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, message = userProps.message, _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, TextComponent = userProps.textComponent, indexUiState = userProps.indexUiState, setIndexUiState = userProps.setIndexUiState, userTranslations = userProps.translations, suggestionsElement = userProps.suggestionsElement, loaderElement = userProps.loaderElement, _userProps_showReasoning = userProps.showReasoning, showReasoning = _userProps_showReasoning === void 0 ?
|
|
14540
|
+
var _messages_, _reasoningParts_;
|
|
14541
|
+
var _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, message = userProps.message, _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, TextComponent = userProps.textComponent, ReasoningComponent = userProps.reasoningComponent, indexUiState = userProps.indexUiState, setIndexUiState = userProps.setIndexUiState, userTranslations = userProps.translations, suggestionsElement = userProps.suggestionsElement, loaderElement = userProps.loaderElement, _userProps_showReasoning = userProps.showReasoning, showReasoning = _userProps_showReasoning === void 0 ? true : _userProps_showReasoning, _userProps_parseMarkdown = userProps.parseMarkdown, parseMarkdown = _userProps_parseMarkdown === void 0 ? true : _userProps_parseMarkdown, ownMessages = userProps.messages, /* eslint-disable typescript/no-deprecated -- reading the
|
|
14188
14542
|
deprecated aliases is the point: they are resolved into `context`
|
|
14189
14543
|
below so callers on the previous API keep working. */ ownStatus = userProps.status, ownTools = userProps.tools, ownOnClose = userProps.onClose, /* eslint-enable typescript/no-deprecated */ sharedContext = userProps.context, props = _object_without_properties(userProps, [
|
|
14190
14544
|
"classNames",
|
|
@@ -14197,6 +14551,7 @@
|
|
|
14197
14551
|
"actionsComponent",
|
|
14198
14552
|
"footerComponent",
|
|
14199
14553
|
"textComponent",
|
|
14554
|
+
"reasoningComponent",
|
|
14200
14555
|
"indexUiState",
|
|
14201
14556
|
"setIndexUiState",
|
|
14202
14557
|
"translations",
|
|
@@ -14236,6 +14591,30 @@
|
|
|
14236
14591
|
};
|
|
14237
14592
|
var hasLeading = Boolean(LeadingComponent);
|
|
14238
14593
|
var isCurrentMessage = messages === undefined || ((_messages_ = messages[messages.length - 1]) === null || _messages_ === void 0 ? void 0 : _messages_.id) === message.id;
|
|
14594
|
+
var reasoningParts = showReasoning ? message.parts.reduce(function(receivedParts, part, partIndex) {
|
|
14595
|
+
if (part.type !== 'reasoning') {
|
|
14596
|
+
return receivedParts;
|
|
14597
|
+
}
|
|
14598
|
+
var isStreaming = status === 'streaming' && isCurrentMessage && isReasoningPartActive(message.parts, partIndex);
|
|
14599
|
+
if (!isStreaming && part.text.trim().length === 0) {
|
|
14600
|
+
return receivedParts;
|
|
14601
|
+
}
|
|
14602
|
+
receivedParts.push({
|
|
14603
|
+
part: part,
|
|
14604
|
+
partIndex: partIndex,
|
|
14605
|
+
isStreaming: isStreaming
|
|
14606
|
+
});
|
|
14607
|
+
return receivedParts;
|
|
14608
|
+
}, []) : [];
|
|
14609
|
+
var firstReasoningPartIndex = (_reasoningParts_ = reasoningParts[0]) === null || _reasoningParts_ === void 0 ? void 0 : _reasoningParts_.partIndex;
|
|
14610
|
+
// Keep the built-in native disclosure mounted through a temporary
|
|
14611
|
+
// eligibility gap so its reader-owned state survives resumed reasoning.
|
|
14612
|
+
var reasoningPartIndex = firstReasoningPartIndex !== null && firstReasoningPartIndex !== void 0 ? firstReasoningPartIndex : showReasoning && !ReasoningComponent && status === 'streaming' && isCurrentMessage ? message.parts.findIndex(function(part) {
|
|
14613
|
+
return part.type === 'reasoning';
|
|
14614
|
+
}) : -1;
|
|
14615
|
+
var isReasoningStreaming = reasoningParts.some(function(part) {
|
|
14616
|
+
return part.isStreaming;
|
|
14617
|
+
});
|
|
14239
14618
|
var showActions = Boolean(actions.length > 0 || ActionsComponent) && status === 'ready';
|
|
14240
14619
|
var cssClasses = {
|
|
14241
14620
|
root: cx('ais-ChatMessage', "ais-ChatMessage--".concat(side), "ais-ChatMessage--".concat(variant), autoHideActions && 'ais-ChatMessage--auto-hide-actions', classNames.root),
|
|
@@ -14258,21 +14637,39 @@
|
|
|
14258
14637
|
return null;
|
|
14259
14638
|
}
|
|
14260
14639
|
if (part.type === 'reasoning') {
|
|
14261
|
-
|
|
14262
|
-
|
|
14640
|
+
// A custom component renders each step where it arrived, so the rendered
|
|
14641
|
+
// order matches the stream. The built-in disclosure below aggregates the
|
|
14642
|
+
// whole message into a single row, which is why only it is placed by
|
|
14643
|
+
// index.
|
|
14644
|
+
if (ReasoningComponent) {
|
|
14645
|
+
var receivedPart = reasoningParts.find(function(candidate) {
|
|
14646
|
+
return candidate.partIndex === index;
|
|
14647
|
+
});
|
|
14648
|
+
if (!receivedPart) {
|
|
14649
|
+
return null;
|
|
14650
|
+
}
|
|
14651
|
+
return /*#__PURE__*/ createElement(Fragment, {
|
|
14652
|
+
key: "".concat(message.id, "-reasoning-").concat(index)
|
|
14653
|
+
}, /*#__PURE__*/ createElement(ReasoningComponent, {
|
|
14654
|
+
part: receivedPart.part,
|
|
14655
|
+
partIndex: index,
|
|
14656
|
+
isStreaming: receivedPart.isStreaming,
|
|
14657
|
+
message: message,
|
|
14658
|
+
context: context
|
|
14659
|
+
}));
|
|
14263
14660
|
}
|
|
14264
|
-
|
|
14265
|
-
if (!isReasoningStreaming && part.text.trim().length === 0) {
|
|
14661
|
+
if (index !== reasoningPartIndex) {
|
|
14266
14662
|
return null;
|
|
14267
14663
|
}
|
|
14268
14664
|
return /*#__PURE__*/ createElement(ChatMessageReasoning, {
|
|
14269
|
-
key: "".concat(message.id, "-")
|
|
14270
|
-
|
|
14271
|
-
|
|
14665
|
+
key: "".concat(message.id, "-reasoning"),
|
|
14666
|
+
parts: reasoningParts,
|
|
14667
|
+
hidden: reasoningParts.length === 0,
|
|
14272
14668
|
parseMarkdown: parseMarkdown,
|
|
14273
14669
|
translations: translations,
|
|
14274
14670
|
classNames: _object_spread_props(_object_spread({}, cssClasses), {
|
|
14275
|
-
|
|
14671
|
+
reasoningIcon: cx(cssClasses.reasoningIcon, isReasoningStreaming && 'ais-ChatMessageReasoning-icon--streaming'),
|
|
14672
|
+
reasoningLabel: cx(cssClasses.reasoningLabel, isReasoningStreaming && 'ais-ChatMessageReasoning-label--streaming')
|
|
14276
14673
|
})
|
|
14277
14674
|
});
|
|
14278
14675
|
}
|
|
@@ -14800,9 +15197,10 @@
|
|
|
14800
15197
|
// Read the row's own side, mirroring `DefaultMessage`, so one role's change
|
|
14801
15198
|
// neither invalidates the other's completed rows nor goes unnoticed here.
|
|
14802
15199
|
var messageProps = props.message.role === 'user' ? props.userMessageProps : props.assistantMessageProps;
|
|
14803
|
-
var showReasoning = messageProps === null || messageProps === void 0 ? void 0 : messageProps.showReasoning;
|
|
15200
|
+
var showReasoning = (messageProps === null || messageProps === void 0 ? void 0 : messageProps.showReasoning) !== false;
|
|
14804
15201
|
var parseMarkdown = messageProps === null || messageProps === void 0 ? void 0 : messageProps.parseMarkdown;
|
|
14805
15202
|
var textComponent = messageProps === null || messageProps === void 0 ? void 0 : messageProps.textComponent;
|
|
15203
|
+
var reasoningComponent = messageProps === null || messageProps === void 0 ? void 0 : messageProps.reasoningComponent;
|
|
14806
15204
|
// A completed row is memoized against its own message, but `shouldRender`
|
|
14807
15205
|
// reads the whole `context`: a predicate can hide an older tool result once a
|
|
14808
15206
|
// newer message arrives. Track the verdicts themselves rather than
|
|
@@ -14812,6 +15210,17 @@
|
|
|
14812
15210
|
// Custom text components receive the conversation, so their completed rows
|
|
14813
15211
|
// must update with it. Keep the default renderer's streaming optimization.
|
|
14814
15212
|
var textComponentMessages = textComponent ? props.context.messages : undefined;
|
|
15213
|
+
// A custom reasoning component receives the full context, but completed
|
|
15214
|
+
// rows only need to update for its semantic state, so the memo tracks those
|
|
15215
|
+
// fields rather than `props.context`. The context's callback identities and
|
|
15216
|
+
// its scroll-only changes stay out. `reasoningComponent` is tracked, so
|
|
15217
|
+
// replacing the component still takes effect.
|
|
15218
|
+
var reasoningComponentMessages = reasoningComponent ? props.context.messages : undefined;
|
|
15219
|
+
var reasoningComponentStatus = reasoningComponent ? props.context.status : undefined;
|
|
15220
|
+
var reasoningComponentError = reasoningComponent ? props.context.error : undefined;
|
|
15221
|
+
var reasoningComponentIsClearing = reasoningComponent ? props.context.isClearing : undefined;
|
|
15222
|
+
var reasoningComponentActivePart = reasoningComponent ? props.context.activePart : undefined;
|
|
15223
|
+
var reasoningComponentTools = reasoningComponent ? props.context.tools : undefined;
|
|
14815
15224
|
// Object-level fallback, matching the render: the spread replaces
|
|
14816
15225
|
// `translations` wholesale, and it copies a key holding `undefined` too. Both
|
|
14817
15226
|
// are why this resolves by own-key presence rather than key by key.
|
|
@@ -14847,6 +15256,13 @@
|
|
|
14847
15256
|
parseMarkdown,
|
|
14848
15257
|
textComponent,
|
|
14849
15258
|
textComponentMessages,
|
|
15259
|
+
reasoningComponent,
|
|
15260
|
+
reasoningComponentMessages,
|
|
15261
|
+
reasoningComponentStatus,
|
|
15262
|
+
reasoningComponentError,
|
|
15263
|
+
reasoningComponentIsClearing,
|
|
15264
|
+
reasoningComponentActivePart,
|
|
15265
|
+
reasoningComponentTools,
|
|
14850
15266
|
reasoningLabel,
|
|
14851
15267
|
reasoningClassName,
|
|
14852
15268
|
reasoningHeaderClassName,
|
|
@@ -14930,7 +15346,7 @@
|
|
|
14930
15346
|
scrollToBottomHidden: cx('ais-ChatMessages-scrollToBottom--hidden', classNames.scrollToBottomHidden)
|
|
14931
15347
|
};
|
|
14932
15348
|
var lastMessage = messages[messages.length - 1];
|
|
14933
|
-
var showReasoning = assistantMessageProps === null || assistantMessageProps === void 0 ? void 0 : assistantMessageProps.showReasoning;
|
|
15349
|
+
var showReasoning = (assistantMessageProps === null || assistantMessageProps === void 0 ? void 0 : assistantMessageProps.showReasoning) !== false;
|
|
14934
15350
|
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];
|
|
14935
15351
|
// `activePart` means "the part currently being processed". It must clear
|
|
14936
15352
|
// when nothing is in progress: once the response settles (`ready`/`error`),
|
|
@@ -14940,7 +15356,7 @@
|
|
|
14940
15356
|
var isProcessing = status === 'submitted' || status === 'streaming';
|
|
14941
15357
|
var activePart = isProcessing && (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.role) === 'assistant' ? lastPart : undefined;
|
|
14942
15358
|
// The scan slices the remaining parts per candidate, and only the loader reads
|
|
14943
|
-
// it, so skip it entirely
|
|
15359
|
+
// it, so skip it entirely once `showReasoning` is off.
|
|
14944
15360
|
// The loader reports on the assistant's turn, so it only ever belongs to an
|
|
14945
15361
|
// assistant message. While `submitted` the last message is still the user's
|
|
14946
15362
|
// own, and the loader belongs to no message at all.
|
|
@@ -15772,7 +16188,7 @@
|
|
|
15772
16188
|
createElement: createElement
|
|
15773
16189
|
});
|
|
15774
16190
|
return function HeaderComponent(param) {
|
|
15775
|
-
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;
|
|
16191
|
+
var showViewAll = param.showViewAll, canScrollLeft = param.canScrollLeft, canScrollRight = param.canScrollRight, scrollLeft = param.scrollLeft, scrollRight = param.scrollRight, nbHits = param.nbHits, input = param.input, resolvedSearchParams = param.resolvedSearchParams, nbItems = param.nbItems, applyFilters = param.applyFilters, getSearchPageURL = param.getSearchPageURL, onClose = param.onClose;
|
|
15776
16192
|
if (nbItems < 1) {
|
|
15777
16193
|
return null;
|
|
15778
16194
|
}
|
|
@@ -15787,7 +16203,7 @@
|
|
|
15787
16203
|
size: "sm",
|
|
15788
16204
|
onClick: function onClick() {
|
|
15789
16205
|
if (!input || !applyFilters) return;
|
|
15790
|
-
var params = applyFilters(getApplyFiltersParamsFromToolInput(input));
|
|
16206
|
+
var params = applyFilters(getApplyFiltersParamsFromToolInput(input, resolvedSearchParams));
|
|
15791
16207
|
if (getSearchPageURL) {
|
|
15792
16208
|
var searchPageURL = getSearchPageURL(params);
|
|
15793
16209
|
var resolvedURL = new URL(searchPageURL, window.location.href);
|
|
@@ -15841,6 +16257,14 @@
|
|
|
15841
16257
|
var message = context.message, applyFilters = context.applyFilters, insightsEventContext = context.insightsEventContext, sendEvent = context.sendEvent, onClose = context.onClose;
|
|
15842
16258
|
var instantSearchStatus = (_ref = insightsEventContext === null || insightsEventContext === void 0 ? void 0 : insightsEventContext.instantSearchStatus) !== null && _ref !== void 0 ? _ref : 'idle';
|
|
15843
16259
|
var input = message === null || message === void 0 ? void 0 : message.input;
|
|
16260
|
+
// What the server actually searched with, when it sent it. Absent for the
|
|
16261
|
+
// default search tool and whenever the MCP server emits no `_meta`.
|
|
16262
|
+
var resolvedSearchParams = useMemo(function() {
|
|
16263
|
+
return getResolvedSearchParams(context.messages, message === null || message === void 0 ? void 0 : message.toolCallId);
|
|
16264
|
+
}, [
|
|
16265
|
+
context.messages,
|
|
16266
|
+
message === null || message === void 0 ? void 0 : message.toolCallId
|
|
16267
|
+
]);
|
|
15844
16268
|
var output = message === null || message === void 0 ? void 0 : message.output;
|
|
15845
16269
|
var hits = (output === null || output === void 0 ? void 0 : output.hits) || [];
|
|
15846
16270
|
var items = addQueryID(addAbsolutePosition(hits, 0, hits.length), output === null || output === void 0 ? void 0 : output.queryID);
|
|
@@ -15888,6 +16312,7 @@
|
|
|
15888
16312
|
showViewAll: showViewAll,
|
|
15889
16313
|
nbHits: output === null || output === void 0 ? void 0 : output.nbHits,
|
|
15890
16314
|
input: input,
|
|
16315
|
+
resolvedSearchParams: resolvedSearchParams,
|
|
15891
16316
|
applyFilters: applyFilters,
|
|
15892
16317
|
getSearchPageURL: getSearchPageURL,
|
|
15893
16318
|
onClose: onClose
|
|
@@ -15899,6 +16324,7 @@
|
|
|
15899
16324
|
showViewAll: showViewAll,
|
|
15900
16325
|
nbHits: output === null || output === void 0 ? void 0 : output.nbHits,
|
|
15901
16326
|
input: input,
|
|
16327
|
+
resolvedSearchParams: resolvedSearchParams,
|
|
15902
16328
|
applyFilters: applyFilters,
|
|
15903
16329
|
getSearchPageURL: getSearchPageURL,
|
|
15904
16330
|
onClose: onClose
|
|
@@ -15909,6 +16335,7 @@
|
|
|
15909
16335
|
HeaderComponent,
|
|
15910
16336
|
output === null || output === void 0 ? void 0 : output.nbHits,
|
|
15911
16337
|
input,
|
|
16338
|
+
resolvedSearchParams,
|
|
15912
16339
|
applyFilters,
|
|
15913
16340
|
getSearchPageURL,
|
|
15914
16341
|
onClose
|
|
@@ -16914,6 +17341,7 @@
|
|
|
16914
17341
|
}
|
|
16915
17342
|
var scrollTop1 = state.scrollTop, ignoreScrollToTop = state.ignoreScrollToTop;
|
|
16916
17343
|
var _state_lastScrollTop = state.lastScrollTop, lastScrollTop = _state_lastScrollTop === void 0 ? scrollTop1 : _state_lastScrollTop;
|
|
17344
|
+
var isNearBottom = state.isNearBottom;
|
|
16917
17345
|
state.lastScrollTop = scrollTop1;
|
|
16918
17346
|
state.ignoreScrollToTop = undefined;
|
|
16919
17347
|
if (ignoreScrollToTop && ignoreScrollToTop > scrollTop1) {
|
|
@@ -16923,7 +17351,7 @@
|
|
|
16923
17351
|
* is correct, set the lastScrollTop to the ignored event.
|
|
16924
17352
|
*/ lastScrollTop = ignoreScrollToTop;
|
|
16925
17353
|
}
|
|
16926
|
-
setIsNearBottom(
|
|
17354
|
+
setIsNearBottom(isNearBottom);
|
|
16927
17355
|
/**
|
|
16928
17356
|
* Scroll events may come before a ResizeObserver event,
|
|
16929
17357
|
* so in order to ignore resize events correctly we use a
|
|
@@ -16955,7 +17383,7 @@
|
|
|
16955
17383
|
if (isScrollingDown) {
|
|
16956
17384
|
setEscapedFromLock(false);
|
|
16957
17385
|
}
|
|
16958
|
-
if (!state.escapedFromLock &&
|
|
17386
|
+
if (!state.escapedFromLock && isNearBottom) {
|
|
16959
17387
|
setIsAtBottom(true);
|
|
16960
17388
|
}
|
|
16961
17389
|
}, 1);
|
|
@@ -17128,11 +17556,75 @@
|
|
|
17128
17556
|
return Boolean(item && (typeof item === "undefined" ? "undefined" : _type_of(item)) === 'object' && item[PROMPT_SUGGESTION_FLAG]);
|
|
17129
17557
|
}
|
|
17130
17558
|
|
|
17131
|
-
function
|
|
17132
|
-
|
|
17133
|
-
return
|
|
17134
|
-
}
|
|
17135
|
-
|
|
17559
|
+
var tryParseJson = function tryParseJson(value) {
|
|
17560
|
+
try {
|
|
17561
|
+
return JSON.parse(value);
|
|
17562
|
+
} catch (unused) {
|
|
17563
|
+
return undefined;
|
|
17564
|
+
}
|
|
17565
|
+
};
|
|
17566
|
+
var repairPartialJson = function repairPartialJson(value) {
|
|
17567
|
+
var repaired = value.trim();
|
|
17568
|
+
if (!repaired) {
|
|
17569
|
+
return repaired;
|
|
17570
|
+
}
|
|
17571
|
+
var inString = false;
|
|
17572
|
+
var isEscaped = false;
|
|
17573
|
+
var stack = [];
|
|
17574
|
+
for(var index = 0; index < repaired.length; index++){
|
|
17575
|
+
var char = repaired[index];
|
|
17576
|
+
if (inString) {
|
|
17577
|
+
if (isEscaped) {
|
|
17578
|
+
isEscaped = false;
|
|
17579
|
+
} else if (char === '\\') {
|
|
17580
|
+
isEscaped = true;
|
|
17581
|
+
} else if (char === '"') {
|
|
17582
|
+
inString = false;
|
|
17583
|
+
}
|
|
17584
|
+
continue;
|
|
17585
|
+
}
|
|
17586
|
+
if (char === '"') {
|
|
17587
|
+
inString = true;
|
|
17588
|
+
continue;
|
|
17589
|
+
}
|
|
17590
|
+
if (char === '{' || char === '[') {
|
|
17591
|
+
stack.push(char);
|
|
17592
|
+
continue;
|
|
17593
|
+
}
|
|
17594
|
+
if (char === '}' && stack[stack.length - 1] === '{') {
|
|
17595
|
+
stack.pop();
|
|
17596
|
+
continue;
|
|
17597
|
+
}
|
|
17598
|
+
if (char === ']' && stack[stack.length - 1] === '[') {
|
|
17599
|
+
stack.pop();
|
|
17600
|
+
}
|
|
17601
|
+
}
|
|
17602
|
+
if (inString && !isEscaped) {
|
|
17603
|
+
repaired += '"';
|
|
17604
|
+
}
|
|
17605
|
+
repaired = repaired.replace(RegExp(",\\s*$", "u"), '');
|
|
17606
|
+
if (stack.length > 0) {
|
|
17607
|
+
repaired += stack.reverse().map(function(opening) {
|
|
17608
|
+
return opening === '{' ? '}' : ']';
|
|
17609
|
+
}).join('');
|
|
17610
|
+
}
|
|
17611
|
+
return repaired.replace(RegExp(",\\s*([}\\]])", "gu"), '$1');
|
|
17612
|
+
};
|
|
17613
|
+
var parsePartialJson = function parsePartialJson(accumulatedRawJson, fallbackValue) {
|
|
17614
|
+
var normalized = accumulatedRawJson.trim();
|
|
17615
|
+
if (!normalized) {
|
|
17616
|
+
return fallbackValue;
|
|
17617
|
+
}
|
|
17618
|
+
var directParsed = tryParseJson(normalized);
|
|
17619
|
+
if (directParsed !== undefined) {
|
|
17620
|
+
return directParsed;
|
|
17621
|
+
}
|
|
17622
|
+
var repairedParsed = tryParseJson(repairPartialJson(normalized));
|
|
17623
|
+
if (repairedParsed !== undefined) {
|
|
17624
|
+
return repairedParsed;
|
|
17625
|
+
}
|
|
17626
|
+
return fallbackValue;
|
|
17627
|
+
};
|
|
17136
17628
|
|
|
17137
17629
|
/**
|
|
17138
17630
|
* Stream parser for parsing SSE (Server-Sent Events) streams.
|
|
@@ -17424,273 +17916,13 @@
|
|
|
17424
17916
|
return undefined;
|
|
17425
17917
|
}
|
|
17426
17918
|
|
|
17427
|
-
|
|
17428
|
-
|
|
17429
|
-
|
|
17430
|
-
|
|
17431
|
-
|
|
17432
|
-
|
|
17433
|
-
|
|
17434
|
-
return response.text().then(function(text) {
|
|
17435
|
-
var _tryParseErrorMessage;
|
|
17436
|
-
return (_tryParseErrorMessage = tryParseErrorMessage(text)) !== null && _tryParseErrorMessage !== void 0 ? _tryParseErrorMessage : fallback;
|
|
17437
|
-
}).catch(function() {
|
|
17438
|
-
return fallback;
|
|
17439
|
-
});
|
|
17440
|
-
}
|
|
17441
|
-
/**
|
|
17442
|
-
* Abstract base class for HTTP-based chat transports.
|
|
17443
|
-
*/ var HttpChatTransport = /*#__PURE__*/ function() {
|
|
17444
|
-
function HttpChatTransport(param) {
|
|
17445
|
-
var _param_api = param.api, api = _param_api === void 0 ? '/api/chat' : _param_api, credentials = param.credentials, headers = param.headers, body = param.body, customFetch = param.fetch, prepareSendMessagesRequest = param.prepareSendMessagesRequest, prepareReconnectToStreamRequest = param.prepareReconnectToStreamRequest;
|
|
17446
|
-
_class_call_check(this, HttpChatTransport);
|
|
17447
|
-
_define_property(this, "api", void 0);
|
|
17448
|
-
_define_property(this, "credentials", void 0);
|
|
17449
|
-
_define_property(this, "headers", void 0);
|
|
17450
|
-
_define_property(this, "body", void 0);
|
|
17451
|
-
_define_property(this, "fetch", void 0);
|
|
17452
|
-
_define_property(this, "prepareSendMessagesRequest", void 0);
|
|
17453
|
-
_define_property(this, "prepareReconnectToStreamRequest", void 0);
|
|
17454
|
-
this.api = api;
|
|
17455
|
-
this.credentials = credentials;
|
|
17456
|
-
this.headers = headers;
|
|
17457
|
-
this.body = body;
|
|
17458
|
-
this.fetch = customFetch;
|
|
17459
|
-
this.prepareSendMessagesRequest = prepareSendMessagesRequest;
|
|
17460
|
-
this.prepareReconnectToStreamRequest = prepareReconnectToStreamRequest;
|
|
17461
|
-
}
|
|
17462
|
-
_create_class(HttpChatTransport, [
|
|
17463
|
-
{
|
|
17464
|
-
key: "sendMessages",
|
|
17465
|
-
value: function sendMessages(param) {
|
|
17466
|
-
var _this = this;
|
|
17467
|
-
var abortSignal = param.abortSignal, chatId = param.chatId, messages = param.messages, requestMetadata = param.requestMetadata, trigger = param.trigger, messageId = param.messageId, requestHeaders = param.headers, requestBody = param.body;
|
|
17468
|
-
var _this_fetch;
|
|
17469
|
-
var fetchFn = (_this_fetch = this.fetch) !== null && _this_fetch !== void 0 ? _this_fetch : fetch;
|
|
17470
|
-
// Resolve configurable values
|
|
17471
|
-
return Promise.all([
|
|
17472
|
-
resolveValue(this.credentials),
|
|
17473
|
-
resolveValue(this.headers),
|
|
17474
|
-
resolveValue(this.body)
|
|
17475
|
-
]).then(function(param) {
|
|
17476
|
-
var _param = _sliced_to_array(param, 3), resolvedCredentials = _param[0], resolvedHeaders = _param[1], resolvedBody = _param[2];
|
|
17477
|
-
// Build default request options
|
|
17478
|
-
var api = _this.api;
|
|
17479
|
-
var body = _object_spread({
|
|
17480
|
-
id: chatId,
|
|
17481
|
-
messages: messages
|
|
17482
|
-
}, resolvedBody, requestBody);
|
|
17483
|
-
var headers = _object_spread({
|
|
17484
|
-
'Content-Type': 'application/json'
|
|
17485
|
-
}, _instanceof(resolvedHeaders, Headers) ? Object.fromEntries(resolvedHeaders.entries()) : resolvedHeaders, _instanceof(requestHeaders, Headers) ? Object.fromEntries(requestHeaders.entries()) : requestHeaders);
|
|
17486
|
-
var credentials = resolvedCredentials;
|
|
17487
|
-
// Apply custom preparation if provided
|
|
17488
|
-
var prepareRequestBody = _object_spread({}, resolvedBody, requestBody);
|
|
17489
|
-
var preparePromise = _this.prepareSendMessagesRequest ? Promise.resolve(_this.prepareSendMessagesRequest({
|
|
17490
|
-
id: chatId,
|
|
17491
|
-
messages: messages,
|
|
17492
|
-
requestMetadata: requestMetadata,
|
|
17493
|
-
body: prepareRequestBody,
|
|
17494
|
-
credentials: resolvedCredentials,
|
|
17495
|
-
headers: resolvedHeaders,
|
|
17496
|
-
api: _this.api,
|
|
17497
|
-
trigger: trigger,
|
|
17498
|
-
messageId: messageId
|
|
17499
|
-
})) : Promise.resolve(null);
|
|
17500
|
-
return preparePromise.then(function(prepared) {
|
|
17501
|
-
if (prepared) {
|
|
17502
|
-
body = prepared.body;
|
|
17503
|
-
if (prepared.api) api = prepared.api;
|
|
17504
|
-
if (prepared.headers) {
|
|
17505
|
-
headers = _object_spread({
|
|
17506
|
-
'Content-Type': 'application/json'
|
|
17507
|
-
}, _instanceof(prepared.headers, Headers) ? Object.fromEntries(prepared.headers.entries()) : prepared.headers);
|
|
17508
|
-
}
|
|
17509
|
-
if (prepared.credentials) credentials = prepared.credentials;
|
|
17510
|
-
}
|
|
17511
|
-
return fetchFn(api, {
|
|
17512
|
-
method: 'POST',
|
|
17513
|
-
headers: headers,
|
|
17514
|
-
body: JSON.stringify(body),
|
|
17515
|
-
signal: abortSignal,
|
|
17516
|
-
credentials: credentials
|
|
17517
|
-
}).then(function(response) {
|
|
17518
|
-
if (!response.ok) {
|
|
17519
|
-
return getHttpErrorMessage(response).then(function(message) {
|
|
17520
|
-
throw new Error(message);
|
|
17521
|
-
});
|
|
17522
|
-
}
|
|
17523
|
-
if (!response.body) {
|
|
17524
|
-
throw new Error('Response body is empty');
|
|
17525
|
-
}
|
|
17526
|
-
return _this.processResponseStream(response.body);
|
|
17527
|
-
});
|
|
17528
|
-
});
|
|
17529
|
-
});
|
|
17530
|
-
}
|
|
17531
|
-
},
|
|
17532
|
-
{
|
|
17533
|
-
key: "reconnectToStream",
|
|
17534
|
-
value: function reconnectToStream(param) {
|
|
17535
|
-
var _this = this;
|
|
17536
|
-
var chatId = param.chatId, requestHeaders = param.headers, requestBody = param.body;
|
|
17537
|
-
var _this_fetch;
|
|
17538
|
-
var fetchFn = (_this_fetch = this.fetch) !== null && _this_fetch !== void 0 ? _this_fetch : fetch;
|
|
17539
|
-
// Resolve configurable values
|
|
17540
|
-
return Promise.all([
|
|
17541
|
-
resolveValue(this.credentials),
|
|
17542
|
-
resolveValue(this.headers),
|
|
17543
|
-
resolveValue(this.body)
|
|
17544
|
-
]).then(function(param) {
|
|
17545
|
-
var _param = _sliced_to_array(param, 3), resolvedCredentials = _param[0], resolvedHeaders = _param[1], resolvedBody = _param[2];
|
|
17546
|
-
// Build default request options
|
|
17547
|
-
var api = _this.api;
|
|
17548
|
-
var headers = _object_spread({}, _instanceof(resolvedHeaders, Headers) ? Object.fromEntries(resolvedHeaders.entries()) : resolvedHeaders, _instanceof(requestHeaders, Headers) ? Object.fromEntries(requestHeaders.entries()) : requestHeaders);
|
|
17549
|
-
var credentials = resolvedCredentials;
|
|
17550
|
-
// Apply custom preparation if provided
|
|
17551
|
-
var prepareRequestBody = _object_spread({}, resolvedBody, requestBody);
|
|
17552
|
-
var preparePromise = _this.prepareReconnectToStreamRequest ? Promise.resolve(_this.prepareReconnectToStreamRequest({
|
|
17553
|
-
id: chatId,
|
|
17554
|
-
requestMetadata: undefined,
|
|
17555
|
-
body: prepareRequestBody,
|
|
17556
|
-
credentials: resolvedCredentials,
|
|
17557
|
-
headers: resolvedHeaders,
|
|
17558
|
-
api: _this.api
|
|
17559
|
-
})) : Promise.resolve(null);
|
|
17560
|
-
return preparePromise.then(function(prepared) {
|
|
17561
|
-
if (prepared) {
|
|
17562
|
-
if (prepared.api) api = prepared.api;
|
|
17563
|
-
if (prepared.headers) {
|
|
17564
|
-
headers = _instanceof(prepared.headers, Headers) ? Object.fromEntries(prepared.headers.entries()) : prepared.headers;
|
|
17565
|
-
}
|
|
17566
|
-
if (prepared.credentials) credentials = prepared.credentials;
|
|
17567
|
-
}
|
|
17568
|
-
// GET request for reconnection
|
|
17569
|
-
return fetchFn("".concat(api, "?chatId=").concat(chatId), {
|
|
17570
|
-
method: 'GET',
|
|
17571
|
-
headers: headers,
|
|
17572
|
-
credentials: credentials
|
|
17573
|
-
}).then(function(response) {
|
|
17574
|
-
if (!response.ok) {
|
|
17575
|
-
// 404 means no stream to reconnect to, which is not an error
|
|
17576
|
-
if (response.status === 404) {
|
|
17577
|
-
return null;
|
|
17578
|
-
}
|
|
17579
|
-
return getHttpErrorMessage(response).then(function(message) {
|
|
17580
|
-
throw new Error(message);
|
|
17581
|
-
});
|
|
17582
|
-
}
|
|
17583
|
-
if (!response.body) {
|
|
17584
|
-
return null;
|
|
17585
|
-
}
|
|
17586
|
-
return _this.processResponseStream(response.body);
|
|
17587
|
-
});
|
|
17588
|
-
});
|
|
17589
|
-
});
|
|
17590
|
-
}
|
|
17591
|
-
}
|
|
17592
|
-
]);
|
|
17593
|
-
return HttpChatTransport;
|
|
17594
|
-
}();
|
|
17595
|
-
/**
|
|
17596
|
-
* Default chat transport implementation using NDJSON streaming.
|
|
17597
|
-
*/ var DefaultChatTransport = /*#__PURE__*/ function(HttpChatTransport) {
|
|
17598
|
-
_inherits(DefaultChatTransport, HttpChatTransport);
|
|
17599
|
-
function DefaultChatTransport() {
|
|
17600
|
-
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
17601
|
-
_class_call_check(this, DefaultChatTransport);
|
|
17602
|
-
return _call_super(this, DefaultChatTransport, [
|
|
17603
|
-
options
|
|
17604
|
-
]);
|
|
17605
|
-
}
|
|
17606
|
-
_create_class(DefaultChatTransport, [
|
|
17607
|
-
{
|
|
17608
|
-
key: "processResponseStream",
|
|
17609
|
-
value: function processResponseStream(stream) {
|
|
17610
|
-
return parseJsonEventStream(stream);
|
|
17611
|
-
}
|
|
17612
|
-
}
|
|
17613
|
-
]);
|
|
17614
|
-
return DefaultChatTransport;
|
|
17615
|
-
}(HttpChatTransport);
|
|
17616
|
-
|
|
17617
|
-
var tryParseJson = function tryParseJson(value) {
|
|
17618
|
-
try {
|
|
17619
|
-
return JSON.parse(value);
|
|
17620
|
-
} catch (unused) {
|
|
17621
|
-
return undefined;
|
|
17622
|
-
}
|
|
17623
|
-
};
|
|
17624
|
-
var repairPartialJson = function repairPartialJson(value) {
|
|
17625
|
-
var repaired = value.trim();
|
|
17626
|
-
if (!repaired) {
|
|
17627
|
-
return repaired;
|
|
17628
|
-
}
|
|
17629
|
-
var inString = false;
|
|
17630
|
-
var isEscaped = false;
|
|
17631
|
-
var stack = [];
|
|
17632
|
-
for(var index = 0; index < repaired.length; index++){
|
|
17633
|
-
var char = repaired[index];
|
|
17634
|
-
if (inString) {
|
|
17635
|
-
if (isEscaped) {
|
|
17636
|
-
isEscaped = false;
|
|
17637
|
-
} else if (char === '\\') {
|
|
17638
|
-
isEscaped = true;
|
|
17639
|
-
} else if (char === '"') {
|
|
17640
|
-
inString = false;
|
|
17641
|
-
}
|
|
17642
|
-
continue;
|
|
17643
|
-
}
|
|
17644
|
-
if (char === '"') {
|
|
17645
|
-
inString = true;
|
|
17646
|
-
continue;
|
|
17647
|
-
}
|
|
17648
|
-
if (char === '{' || char === '[') {
|
|
17649
|
-
stack.push(char);
|
|
17650
|
-
continue;
|
|
17651
|
-
}
|
|
17652
|
-
if (char === '}' && stack[stack.length - 1] === '{') {
|
|
17653
|
-
stack.pop();
|
|
17654
|
-
continue;
|
|
17655
|
-
}
|
|
17656
|
-
if (char === ']' && stack[stack.length - 1] === '[') {
|
|
17657
|
-
stack.pop();
|
|
17658
|
-
}
|
|
17659
|
-
}
|
|
17660
|
-
if (inString && !isEscaped) {
|
|
17661
|
-
repaired += '"';
|
|
17662
|
-
}
|
|
17663
|
-
repaired = repaired.replace(RegExp(",\\s*$", "u"), '');
|
|
17664
|
-
if (stack.length > 0) {
|
|
17665
|
-
repaired += stack.reverse().map(function(opening) {
|
|
17666
|
-
return opening === '{' ? '}' : ']';
|
|
17667
|
-
}).join('');
|
|
17668
|
-
}
|
|
17669
|
-
return repaired.replace(RegExp(",\\s*([}\\]])", "gu"), '$1');
|
|
17670
|
-
};
|
|
17671
|
-
var parsePartialJson = function parsePartialJson(accumulatedRawJson, fallbackValue) {
|
|
17672
|
-
var normalized = accumulatedRawJson.trim();
|
|
17673
|
-
if (!normalized) {
|
|
17674
|
-
return fallbackValue;
|
|
17675
|
-
}
|
|
17676
|
-
var directParsed = tryParseJson(normalized);
|
|
17677
|
-
if (directParsed !== undefined) {
|
|
17678
|
-
return directParsed;
|
|
17679
|
-
}
|
|
17680
|
-
var repairedParsed = tryParseJson(repairPartialJson(normalized));
|
|
17681
|
-
if (repairedParsed !== undefined) {
|
|
17682
|
-
return repairedParsed;
|
|
17683
|
-
}
|
|
17684
|
-
return fallbackValue;
|
|
17685
|
-
};
|
|
17686
|
-
|
|
17687
|
-
var _computedKey$1;
|
|
17688
|
-
var defaultGuardrailFallbackResponse = 'Sorry, we are not able to generate a response at the moment.';
|
|
17689
|
-
var TOOL_CALL_CANCELLED_ERROR_TEXT = 'The tool call was cancelled: the conversation moved on before a result was provided.';
|
|
17690
|
-
function getToolName(part) {
|
|
17691
|
-
if (part.type === 'dynamic-tool') {
|
|
17692
|
-
var _part_toolName;
|
|
17693
|
-
return (_part_toolName = part.toolName) !== null && _part_toolName !== void 0 ? _part_toolName : part.type;
|
|
17919
|
+
var _computedKey$1;
|
|
17920
|
+
var defaultGuardrailFallbackResponse = 'Sorry, we are not able to generate a response at the moment.';
|
|
17921
|
+
var TOOL_CALL_CANCELLED_ERROR_TEXT = 'The tool call was cancelled: the conversation moved on before a result was provided.';
|
|
17922
|
+
function getToolName(part) {
|
|
17923
|
+
if (part.type === 'dynamic-tool') {
|
|
17924
|
+
var _part_toolName;
|
|
17925
|
+
return (_part_toolName = part.toolName) !== null && _part_toolName !== void 0 ? _part_toolName : part.type;
|
|
17694
17926
|
}
|
|
17695
17927
|
return part.type.slice('tool-'.length);
|
|
17696
17928
|
}
|
|
@@ -19142,47 +19374,300 @@
|
|
|
19142
19374
|
}
|
|
19143
19375
|
},
|
|
19144
19376
|
{
|
|
19145
|
-
key: "messages",
|
|
19146
|
-
get: function get() {
|
|
19147
|
-
return this._messages;
|
|
19148
|
-
},
|
|
19149
|
-
set: function set(newMessages) {
|
|
19150
|
-
this._messages = _to_consumable_array(newMessages);
|
|
19151
|
-
this._callMessagesCallbacks();
|
|
19377
|
+
key: "messages",
|
|
19378
|
+
get: function get() {
|
|
19379
|
+
return this._messages;
|
|
19380
|
+
},
|
|
19381
|
+
set: function set(newMessages) {
|
|
19382
|
+
this._messages = _to_consumable_array(newMessages);
|
|
19383
|
+
this._callMessagesCallbacks();
|
|
19384
|
+
}
|
|
19385
|
+
}
|
|
19386
|
+
]);
|
|
19387
|
+
return ChatState;
|
|
19388
|
+
}();
|
|
19389
|
+
_computedKey3 = '~registerMessagesCallback', _computedKey4 = '~registerStatusCallback', _computedKey5 = '~registerErrorCallback';
|
|
19390
|
+
var _computedKey9 = _computedKey3, _computedKey10 = _computedKey4, _computedKey11 = _computedKey5;
|
|
19391
|
+
var Chat$1 = /*#__PURE__*/ function(AbstractChat) {
|
|
19392
|
+
_inherits(Chat, AbstractChat);
|
|
19393
|
+
function Chat(_0) {
|
|
19394
|
+
_class_call_check(this, Chat);
|
|
19395
|
+
var _this;
|
|
19396
|
+
var messages = _0.messages, agentId = _0.agentId, _0_persistence = _0.persistence, persistence = _0_persistence === void 0 ? true : _0_persistence, init = _object_without_properties(_0, [
|
|
19397
|
+
"messages",
|
|
19398
|
+
"agentId",
|
|
19399
|
+
"persistence"
|
|
19400
|
+
]);
|
|
19401
|
+
var state = new ChatState(agentId, messages, persistence);
|
|
19402
|
+
_this = _call_super(this, Chat, [
|
|
19403
|
+
_object_spread_props(_object_spread({}, init), {
|
|
19404
|
+
state: state
|
|
19405
|
+
})
|
|
19406
|
+
]), _define_property(_this, "_state", void 0), _define_property(_this, _computedKey9, function(onChange) {
|
|
19407
|
+
return _this._state['~registerMessagesCallback'](onChange);
|
|
19408
|
+
}), _define_property(_this, _computedKey10, function(onChange) {
|
|
19409
|
+
return _this._state['~registerStatusCallback'](onChange);
|
|
19410
|
+
}), _define_property(_this, _computedKey11, function(onChange) {
|
|
19411
|
+
return _this._state['~registerErrorCallback'](onChange);
|
|
19412
|
+
});
|
|
19413
|
+
_this._state = state;
|
|
19414
|
+
return _this;
|
|
19415
|
+
}
|
|
19416
|
+
return Chat;
|
|
19417
|
+
}(AbstractChat);
|
|
19418
|
+
|
|
19419
|
+
// Centralizes the "open the chat from an entry point" behavior shared by the
|
|
19420
|
+
// SearchBox AI button, the Autocomplete AI button, prompt suggestions, and any
|
|
19421
|
+
// future entry point. The chat is always opened; the message is only sent when
|
|
19422
|
+
// it is non-empty and the chat is not already processing a message.
|
|
19423
|
+
// Returns true when a message was submitted, so callers can clear their input.
|
|
19424
|
+
function openChat(chatRenderState) {
|
|
19425
|
+
var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, message = _ref.message, referer = _ref.referer, turnContext = _ref.turnContext;
|
|
19426
|
+
var _ref1;
|
|
19427
|
+
var _chatRenderState_setOpen;
|
|
19428
|
+
if (!chatRenderState) {
|
|
19429
|
+
return false;
|
|
19430
|
+
}
|
|
19431
|
+
var trimmed = (_ref1 = message === null || message === void 0 ? void 0 : message.trim()) !== null && _ref1 !== void 0 ? _ref1 : '';
|
|
19432
|
+
if (!trimmed) {
|
|
19433
|
+
if (chatRenderState.focusInput) {
|
|
19434
|
+
chatRenderState.focusInput();
|
|
19435
|
+
} else {
|
|
19436
|
+
var _chatRenderState_setOpen1;
|
|
19437
|
+
(_chatRenderState_setOpen1 = chatRenderState.setOpen) === null || _chatRenderState_setOpen1 === void 0 ? void 0 : _chatRenderState_setOpen1.call(chatRenderState, true);
|
|
19438
|
+
}
|
|
19439
|
+
return false;
|
|
19440
|
+
}
|
|
19441
|
+
(_chatRenderState_setOpen = chatRenderState.setOpen) === null || _chatRenderState_setOpen === void 0 ? void 0 : _chatRenderState_setOpen.call(chatRenderState, true);
|
|
19442
|
+
if (isChatBusy(chatRenderState) || !chatRenderState.sendMessage) {
|
|
19443
|
+
return false;
|
|
19444
|
+
}
|
|
19445
|
+
chatRenderState.sendMessage(_object_spread({
|
|
19446
|
+
text: trimmed
|
|
19447
|
+
}, turnContext ? {
|
|
19448
|
+
metadata: {
|
|
19449
|
+
turnContext: turnContext
|
|
19450
|
+
}
|
|
19451
|
+
} : {}), referer ? {
|
|
19452
|
+
headers: {
|
|
19453
|
+
'x-algolia-referer': referer
|
|
19454
|
+
}
|
|
19455
|
+
} : undefined);
|
|
19456
|
+
return true;
|
|
19457
|
+
}
|
|
19458
|
+
function isChatBusy(chatRenderState) {
|
|
19459
|
+
return (chatRenderState === null || chatRenderState === void 0 ? void 0 : chatRenderState.status) === 'submitted' || (chatRenderState === null || chatRenderState === void 0 ? void 0 : chatRenderState.status) === 'streaming';
|
|
19460
|
+
}
|
|
19461
|
+
|
|
19462
|
+
var SearchIndexToolType = 'algolia_search_index';
|
|
19463
|
+
var RecommendToolType = 'algolia_recommend';
|
|
19464
|
+
var MemorizeToolType = 'algolia_memorize';
|
|
19465
|
+
var MemorySearchToolType = 'algolia_memory_search';
|
|
19466
|
+
var PonderToolType = 'algolia_ponder';
|
|
19467
|
+
var DisplayResultsToolType = 'algolia_display_results';
|
|
19468
|
+
/**
|
|
19469
|
+
* Whether `toolName` is the search tool as the Algolia MCP Server exposes it:
|
|
19470
|
+
* one tool per index, named after the index it searches
|
|
19471
|
+
* (`algolia_search_index_products`).
|
|
19472
|
+
*/ var matchesSearchIndexToolName = function matchesSearchIndexToolName(toolName) {
|
|
19473
|
+
return toolName.startsWith("".concat(SearchIndexToolType, "_"));
|
|
19474
|
+
};
|
|
19475
|
+
|
|
19476
|
+
function flat(arr) {
|
|
19477
|
+
return arr.reduce(function(acc, array) {
|
|
19478
|
+
return acc.concat(array);
|
|
19479
|
+
}, []);
|
|
19480
|
+
}
|
|
19481
|
+
|
|
19482
|
+
/**
|
|
19483
|
+
* Reads a human-readable message from a failed HTTP response body when the
|
|
19484
|
+
* server returns JSON such as `{ "message": "..." }` (the shared
|
|
19485
|
+
* `ErrorResponse` shape used by every status code), falling back to the HTTP
|
|
19486
|
+
* status line when the body is empty or not parseable.
|
|
19487
|
+
*/ function getHttpErrorMessage(response) {
|
|
19488
|
+
var fallback = "HTTP error: ".concat(response.status, " ").concat(response.statusText);
|
|
19489
|
+
return response.text().then(function(text) {
|
|
19490
|
+
var _tryParseErrorMessage;
|
|
19491
|
+
return (_tryParseErrorMessage = tryParseErrorMessage(text)) !== null && _tryParseErrorMessage !== void 0 ? _tryParseErrorMessage : fallback;
|
|
19492
|
+
}).catch(function() {
|
|
19493
|
+
return fallback;
|
|
19494
|
+
});
|
|
19495
|
+
}
|
|
19496
|
+
/**
|
|
19497
|
+
* Abstract base class for HTTP-based chat transports.
|
|
19498
|
+
*/ var HttpChatTransport = /*#__PURE__*/ function() {
|
|
19499
|
+
function HttpChatTransport(param) {
|
|
19500
|
+
var _param_api = param.api, api = _param_api === void 0 ? '/api/chat' : _param_api, credentials = param.credentials, headers = param.headers, body = param.body, customFetch = param.fetch, prepareSendMessagesRequest = param.prepareSendMessagesRequest, prepareReconnectToStreamRequest = param.prepareReconnectToStreamRequest;
|
|
19501
|
+
_class_call_check(this, HttpChatTransport);
|
|
19502
|
+
_define_property(this, "api", void 0);
|
|
19503
|
+
_define_property(this, "credentials", void 0);
|
|
19504
|
+
_define_property(this, "headers", void 0);
|
|
19505
|
+
_define_property(this, "body", void 0);
|
|
19506
|
+
_define_property(this, "fetch", void 0);
|
|
19507
|
+
_define_property(this, "prepareSendMessagesRequest", void 0);
|
|
19508
|
+
_define_property(this, "prepareReconnectToStreamRequest", void 0);
|
|
19509
|
+
this.api = api;
|
|
19510
|
+
this.credentials = credentials;
|
|
19511
|
+
this.headers = headers;
|
|
19512
|
+
this.body = body;
|
|
19513
|
+
this.fetch = customFetch;
|
|
19514
|
+
this.prepareSendMessagesRequest = prepareSendMessagesRequest;
|
|
19515
|
+
this.prepareReconnectToStreamRequest = prepareReconnectToStreamRequest;
|
|
19516
|
+
}
|
|
19517
|
+
_create_class(HttpChatTransport, [
|
|
19518
|
+
{
|
|
19519
|
+
key: "sendMessages",
|
|
19520
|
+
value: function sendMessages(param) {
|
|
19521
|
+
var _this = this;
|
|
19522
|
+
var abortSignal = param.abortSignal, chatId = param.chatId, messages = param.messages, requestMetadata = param.requestMetadata, trigger = param.trigger, messageId = param.messageId, requestHeaders = param.headers, requestBody = param.body;
|
|
19523
|
+
var _this_fetch;
|
|
19524
|
+
var fetchFn = (_this_fetch = this.fetch) !== null && _this_fetch !== void 0 ? _this_fetch : fetch;
|
|
19525
|
+
// Resolve configurable values
|
|
19526
|
+
return Promise.all([
|
|
19527
|
+
resolveValue(this.credentials),
|
|
19528
|
+
resolveValue(this.headers),
|
|
19529
|
+
resolveValue(this.body)
|
|
19530
|
+
]).then(function(param) {
|
|
19531
|
+
var _param = _sliced_to_array(param, 3), resolvedCredentials = _param[0], resolvedHeaders = _param[1], resolvedBody = _param[2];
|
|
19532
|
+
// Build default request options
|
|
19533
|
+
var api = _this.api;
|
|
19534
|
+
var body = _object_spread({
|
|
19535
|
+
id: chatId,
|
|
19536
|
+
messages: messages
|
|
19537
|
+
}, resolvedBody, requestBody);
|
|
19538
|
+
var headers = _object_spread({
|
|
19539
|
+
'Content-Type': 'application/json'
|
|
19540
|
+
}, _instanceof(resolvedHeaders, Headers) ? Object.fromEntries(resolvedHeaders.entries()) : resolvedHeaders, _instanceof(requestHeaders, Headers) ? Object.fromEntries(requestHeaders.entries()) : requestHeaders);
|
|
19541
|
+
var credentials = resolvedCredentials;
|
|
19542
|
+
// Apply custom preparation if provided
|
|
19543
|
+
var prepareRequestBody = _object_spread({}, resolvedBody, requestBody);
|
|
19544
|
+
var preparePromise = _this.prepareSendMessagesRequest ? Promise.resolve(_this.prepareSendMessagesRequest({
|
|
19545
|
+
id: chatId,
|
|
19546
|
+
messages: messages,
|
|
19547
|
+
requestMetadata: requestMetadata,
|
|
19548
|
+
body: prepareRequestBody,
|
|
19549
|
+
credentials: resolvedCredentials,
|
|
19550
|
+
headers: resolvedHeaders,
|
|
19551
|
+
api: _this.api,
|
|
19552
|
+
trigger: trigger,
|
|
19553
|
+
messageId: messageId
|
|
19554
|
+
})) : Promise.resolve(null);
|
|
19555
|
+
return preparePromise.then(function(prepared) {
|
|
19556
|
+
if (prepared) {
|
|
19557
|
+
body = prepared.body;
|
|
19558
|
+
if (prepared.api) api = prepared.api;
|
|
19559
|
+
if (prepared.headers) {
|
|
19560
|
+
headers = _object_spread({
|
|
19561
|
+
'Content-Type': 'application/json'
|
|
19562
|
+
}, _instanceof(prepared.headers, Headers) ? Object.fromEntries(prepared.headers.entries()) : prepared.headers);
|
|
19563
|
+
}
|
|
19564
|
+
if (prepared.credentials) credentials = prepared.credentials;
|
|
19565
|
+
}
|
|
19566
|
+
return fetchFn(api, {
|
|
19567
|
+
method: 'POST',
|
|
19568
|
+
headers: headers,
|
|
19569
|
+
body: JSON.stringify(body),
|
|
19570
|
+
signal: abortSignal,
|
|
19571
|
+
credentials: credentials
|
|
19572
|
+
}).then(function(response) {
|
|
19573
|
+
if (!response.ok) {
|
|
19574
|
+
return getHttpErrorMessage(response).then(function(message) {
|
|
19575
|
+
throw new Error(message);
|
|
19576
|
+
});
|
|
19577
|
+
}
|
|
19578
|
+
if (!response.body) {
|
|
19579
|
+
throw new Error('Response body is empty');
|
|
19580
|
+
}
|
|
19581
|
+
return _this.processResponseStream(response.body);
|
|
19582
|
+
});
|
|
19583
|
+
});
|
|
19584
|
+
});
|
|
19585
|
+
}
|
|
19586
|
+
},
|
|
19587
|
+
{
|
|
19588
|
+
key: "reconnectToStream",
|
|
19589
|
+
value: function reconnectToStream(param) {
|
|
19590
|
+
var _this = this;
|
|
19591
|
+
var chatId = param.chatId, requestHeaders = param.headers, requestBody = param.body;
|
|
19592
|
+
var _this_fetch;
|
|
19593
|
+
var fetchFn = (_this_fetch = this.fetch) !== null && _this_fetch !== void 0 ? _this_fetch : fetch;
|
|
19594
|
+
// Resolve configurable values
|
|
19595
|
+
return Promise.all([
|
|
19596
|
+
resolveValue(this.credentials),
|
|
19597
|
+
resolveValue(this.headers),
|
|
19598
|
+
resolveValue(this.body)
|
|
19599
|
+
]).then(function(param) {
|
|
19600
|
+
var _param = _sliced_to_array(param, 3), resolvedCredentials = _param[0], resolvedHeaders = _param[1], resolvedBody = _param[2];
|
|
19601
|
+
// Build default request options
|
|
19602
|
+
var api = _this.api;
|
|
19603
|
+
var headers = _object_spread({}, _instanceof(resolvedHeaders, Headers) ? Object.fromEntries(resolvedHeaders.entries()) : resolvedHeaders, _instanceof(requestHeaders, Headers) ? Object.fromEntries(requestHeaders.entries()) : requestHeaders);
|
|
19604
|
+
var credentials = resolvedCredentials;
|
|
19605
|
+
// Apply custom preparation if provided
|
|
19606
|
+
var prepareRequestBody = _object_spread({}, resolvedBody, requestBody);
|
|
19607
|
+
var preparePromise = _this.prepareReconnectToStreamRequest ? Promise.resolve(_this.prepareReconnectToStreamRequest({
|
|
19608
|
+
id: chatId,
|
|
19609
|
+
requestMetadata: undefined,
|
|
19610
|
+
body: prepareRequestBody,
|
|
19611
|
+
credentials: resolvedCredentials,
|
|
19612
|
+
headers: resolvedHeaders,
|
|
19613
|
+
api: _this.api
|
|
19614
|
+
})) : Promise.resolve(null);
|
|
19615
|
+
return preparePromise.then(function(prepared) {
|
|
19616
|
+
if (prepared) {
|
|
19617
|
+
if (prepared.api) api = prepared.api;
|
|
19618
|
+
if (prepared.headers) {
|
|
19619
|
+
headers = _instanceof(prepared.headers, Headers) ? Object.fromEntries(prepared.headers.entries()) : prepared.headers;
|
|
19620
|
+
}
|
|
19621
|
+
if (prepared.credentials) credentials = prepared.credentials;
|
|
19622
|
+
}
|
|
19623
|
+
// GET request for reconnection
|
|
19624
|
+
return fetchFn("".concat(api, "?chatId=").concat(chatId), {
|
|
19625
|
+
method: 'GET',
|
|
19626
|
+
headers: headers,
|
|
19627
|
+
credentials: credentials
|
|
19628
|
+
}).then(function(response) {
|
|
19629
|
+
if (!response.ok) {
|
|
19630
|
+
// 404 means no stream to reconnect to, which is not an error
|
|
19631
|
+
if (response.status === 404) {
|
|
19632
|
+
return null;
|
|
19633
|
+
}
|
|
19634
|
+
return getHttpErrorMessage(response).then(function(message) {
|
|
19635
|
+
throw new Error(message);
|
|
19636
|
+
});
|
|
19637
|
+
}
|
|
19638
|
+
if (!response.body) {
|
|
19639
|
+
return null;
|
|
19640
|
+
}
|
|
19641
|
+
return _this.processResponseStream(response.body);
|
|
19642
|
+
});
|
|
19643
|
+
});
|
|
19644
|
+
});
|
|
19152
19645
|
}
|
|
19153
19646
|
}
|
|
19154
19647
|
]);
|
|
19155
|
-
return
|
|
19648
|
+
return HttpChatTransport;
|
|
19156
19649
|
}();
|
|
19157
|
-
|
|
19158
|
-
|
|
19159
|
-
|
|
19160
|
-
_inherits(
|
|
19161
|
-
function
|
|
19162
|
-
|
|
19163
|
-
|
|
19164
|
-
|
|
19165
|
-
|
|
19166
|
-
"agentId",
|
|
19167
|
-
"persistence"
|
|
19650
|
+
/**
|
|
19651
|
+
* Default chat transport implementation using NDJSON streaming.
|
|
19652
|
+
*/ var DefaultChatTransport = /*#__PURE__*/ function(HttpChatTransport) {
|
|
19653
|
+
_inherits(DefaultChatTransport, HttpChatTransport);
|
|
19654
|
+
function DefaultChatTransport() {
|
|
19655
|
+
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
19656
|
+
_class_call_check(this, DefaultChatTransport);
|
|
19657
|
+
return _call_super(this, DefaultChatTransport, [
|
|
19658
|
+
options
|
|
19168
19659
|
]);
|
|
19169
|
-
var state = new ChatState(agentId, messages, persistence);
|
|
19170
|
-
_this = _call_super(this, Chat, [
|
|
19171
|
-
_object_spread_props(_object_spread({}, init), {
|
|
19172
|
-
state: state
|
|
19173
|
-
})
|
|
19174
|
-
]), _define_property(_this, "_state", void 0), _define_property(_this, _computedKey9, function(onChange) {
|
|
19175
|
-
return _this._state['~registerMessagesCallback'](onChange);
|
|
19176
|
-
}), _define_property(_this, _computedKey10, function(onChange) {
|
|
19177
|
-
return _this._state['~registerStatusCallback'](onChange);
|
|
19178
|
-
}), _define_property(_this, _computedKey11, function(onChange) {
|
|
19179
|
-
return _this._state['~registerErrorCallback'](onChange);
|
|
19180
|
-
});
|
|
19181
|
-
_this._state = state;
|
|
19182
|
-
return _this;
|
|
19183
19660
|
}
|
|
19184
|
-
|
|
19185
|
-
|
|
19661
|
+
_create_class(DefaultChatTransport, [
|
|
19662
|
+
{
|
|
19663
|
+
key: "processResponseStream",
|
|
19664
|
+
value: function processResponseStream(stream) {
|
|
19665
|
+
return parseJsonEventStream(stream);
|
|
19666
|
+
}
|
|
19667
|
+
}
|
|
19668
|
+
]);
|
|
19669
|
+
return DefaultChatTransport;
|
|
19670
|
+
}(HttpChatTransport);
|
|
19186
19671
|
|
|
19187
19672
|
var withUsage$q = createDocumentationMessageGenerator({
|
|
19188
19673
|
name: 'chat',
|
|
@@ -19246,6 +19731,11 @@
|
|
|
19246
19731
|
return refinement.attribute;
|
|
19247
19732
|
}));
|
|
19248
19733
|
}
|
|
19734
|
+
/**
|
|
19735
|
+
* One Algolia `numericFilters` entry: `'price <= 1500'`. The operators are
|
|
19736
|
+
* exactly the set `helper.addNumericRefinement` accepts, and exactly the set
|
|
19737
|
+
* the Algolia MCP Server emits.
|
|
19738
|
+
*/ var NUMERIC_FILTER = /^(.+?)\s*(<=|>=|!=|=|<|>)\s*(-?\d+(?:\.\d+)?)$/;
|
|
19249
19739
|
function updateStateFromSearchToolInput(params, helper) {
|
|
19250
19740
|
// clear all filters first
|
|
19251
19741
|
var attributesToClear = getAttributesToClear$1({
|
|
@@ -19289,6 +19779,16 @@
|
|
|
19289
19779
|
helper.toggleFacetRefinement(name, value);
|
|
19290
19780
|
});
|
|
19291
19781
|
}
|
|
19782
|
+
if (params.numericFilters) {
|
|
19783
|
+
params.numericFilters.forEach(function(filter) {
|
|
19784
|
+
var match = filter.match(NUMERIC_FILTER);
|
|
19785
|
+
if (!match) {
|
|
19786
|
+
return;
|
|
19787
|
+
}
|
|
19788
|
+
var _match = _sliced_to_array(match, 4), attribute = _match[1], operator = _match[2], value = _match[3];
|
|
19789
|
+
helper.addNumericRefinement(attribute, operator, Number(value));
|
|
19790
|
+
});
|
|
19791
|
+
}
|
|
19292
19792
|
if (params.query) {
|
|
19293
19793
|
helper.setQuery(params.query);
|
|
19294
19794
|
}
|
|
@@ -19299,7 +19799,7 @@
|
|
|
19299
19799
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
19300
19800
|
checkRendering(renderFn, withUsage$q());
|
|
19301
19801
|
return function(widgetParams) {
|
|
19302
|
-
var _ref = widgetParams || {}, _ref_resume = _ref.resume, resume = _ref_resume === void 0 ? false : _ref_resume,
|
|
19802
|
+
var _ref = widgetParams || {}, _ref_resume = _ref.resume, resume = _ref_resume === void 0 ? false : _ref_resume, tmp = _ref.tools, tools_ = tmp === void 0 ? {} : tmp, _ref_type = _ref.type, type = _ref_type === void 0 ? 'chat' : _ref_type, persistence = _ref.persistence, 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, [
|
|
19303
19803
|
"resume",
|
|
19304
19804
|
"tools",
|
|
19305
19805
|
"type",
|
|
@@ -19312,6 +19812,12 @@
|
|
|
19312
19812
|
"requiresSearch"
|
|
19313
19813
|
]);
|
|
19314
19814
|
var normalizedPersistence = normalizePersistence(persistence, 'chat' in options);
|
|
19815
|
+
// The Algolia MCP Server exposes the search tool once per index and names
|
|
19816
|
+
// it after the index (`algolia_search_index_products`). A `matchesToolName`
|
|
19817
|
+
// set by the user wins, as does a tool registered under the derived name.
|
|
19818
|
+
var tools = tools_[SearchIndexToolType] && tools_[SearchIndexToolType].matchesToolName === undefined ? _object_spread_props(_object_spread({}, tools_), _define_property({}, SearchIndexToolType, _object_spread_props(_object_spread({}, tools_[SearchIndexToolType]), {
|
|
19819
|
+
matchesToolName: matchesSearchIndexToolName
|
|
19820
|
+
}))) : tools_;
|
|
19315
19821
|
var _chatInstance;
|
|
19316
19822
|
var input = '';
|
|
19317
19823
|
var open = false;
|
|
@@ -19593,7 +20099,8 @@
|
|
|
19593
20099
|
// `open` is read by sibling widgets (e.g. `chatTrigger`) via the
|
|
19594
20100
|
// shared `renderState`. Schedule a full re-render so they pick up
|
|
19595
20101
|
// the new value instead of staying frozen on their initial state.
|
|
19596
|
-
|
|
20102
|
+
// No search runs here, so it must not settle the main search.
|
|
20103
|
+
initOptions.instantSearchInstance.scheduleRender(false);
|
|
19597
20104
|
};
|
|
19598
20105
|
setOpen = function setOpen(nextOpen) {
|
|
19599
20106
|
updateOpen(nextOpen, nextOpen && !open);
|
|
@@ -19646,14 +20153,15 @@
|
|
|
19646
20153
|
// disable themselves, so a transition has to escape this widget's own
|
|
19647
20154
|
// render. Message deltas deliberately don't: they stay local to keep
|
|
19648
20155
|
// streaming cheap. The `status` setter notifies on every write, hence
|
|
19649
|
-
// the comparison.
|
|
20156
|
+
// the comparison. A chat turn is not a search, so the render it
|
|
20157
|
+
// schedules must not settle the main search.
|
|
19650
20158
|
var lastStatus = _chatInstance.status;
|
|
19651
20159
|
var renderOnStatusChange = function renderOnStatusChange() {
|
|
19652
20160
|
var statusChanged = _chatInstance.status !== lastStatus;
|
|
19653
20161
|
lastStatus = _chatInstance.status;
|
|
19654
20162
|
render();
|
|
19655
20163
|
if (statusChanged) {
|
|
19656
|
-
initOptions.instantSearchInstance.scheduleRender();
|
|
20164
|
+
initOptions.instantSearchInstance.scheduleRender(false);
|
|
19657
20165
|
}
|
|
19658
20166
|
};
|
|
19659
20167
|
safelyRunOnBrowser(function() {
|
|
@@ -19683,8 +20191,10 @@
|
|
|
19683
20191
|
renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
|
|
19684
20192
|
instantSearchInstance: instantSearchInstance
|
|
19685
20193
|
}), true);
|
|
20194
|
+
// A restored open panel is new to the sibling entry points, but it is
|
|
20195
|
+
// not a search result.
|
|
19686
20196
|
if (open) {
|
|
19687
|
-
instantSearchInstance.scheduleRender();
|
|
20197
|
+
instantSearchInstance.scheduleRender(false);
|
|
19688
20198
|
}
|
|
19689
20199
|
},
|
|
19690
20200
|
render: function render(renderOptions) {
|
|
@@ -19851,7 +20361,11 @@
|
|
|
19851
20361
|
|
|
19852
20362
|
function useChat(props, additionalWidgetProperties) {
|
|
19853
20363
|
var isHydrated = useIsHydrated();
|
|
20364
|
+
React.useRef(props);
|
|
20365
|
+
React.useRef(null);
|
|
20366
|
+
useIsomorphicLayoutEffect(function() {});
|
|
19854
20367
|
var chatState = useConnector(connectChat, props, additionalWidgetProperties);
|
|
20368
|
+
useIsomorphicLayoutEffect(function() {});
|
|
19855
20369
|
if (isHydrated) {
|
|
19856
20370
|
return chatState;
|
|
19857
20371
|
}
|
|
@@ -19905,9 +20419,6 @@
|
|
|
19905
20419
|
function withStreamParam(url) {
|
|
19906
20420
|
return url.includes('?') ? "".concat(url, "&stream=true") : "".concat(url, "?stream=true");
|
|
19907
20421
|
}
|
|
19908
|
-
function resolveStreamedOutput(data, previous) {
|
|
19909
|
-
return typeof data === 'string' ? parsePartialJson(data, previous) : data;
|
|
19910
|
-
}
|
|
19911
20422
|
function createTaskPreparationContext(context) {
|
|
19912
20423
|
function hideProperty(key) {
|
|
19913
20424
|
var value = context[key];
|
|
@@ -19942,27 +20453,56 @@
|
|
|
19942
20453
|
}
|
|
19943
20454
|
return undefined;
|
|
19944
20455
|
}
|
|
19945
|
-
function
|
|
20456
|
+
function consumeTaskTextStream(body, onData) {
|
|
19946
20457
|
return new Promise(function(resolve, reject) {
|
|
19947
|
-
var
|
|
20458
|
+
var decoder = new TextDecoder();
|
|
20459
|
+
var reader = body.getReader();
|
|
20460
|
+
var accumulatedText = '';
|
|
19948
20461
|
var latest;
|
|
19949
|
-
|
|
19950
|
-
if (!
|
|
19951
|
-
|
|
19952
|
-
|
|
19953
|
-
|
|
19954
|
-
|
|
19955
|
-
}
|
|
19956
|
-
if (chunk.type !== 'data-task-output') {
|
|
19957
|
-
return;
|
|
19958
|
-
}
|
|
19959
|
-
latest = resolveStreamedOutput(chunk.data, latest);
|
|
19960
|
-
if (onData) {
|
|
19961
|
-
onData(latest);
|
|
20462
|
+
var publish = function publish(output) {
|
|
20463
|
+
if (!isEqual(output, latest)) {
|
|
20464
|
+
latest = output;
|
|
20465
|
+
onData === null || onData === void 0 ? void 0 : onData({
|
|
20466
|
+
output: output
|
|
20467
|
+
});
|
|
19962
20468
|
}
|
|
19963
|
-
}
|
|
19964
|
-
|
|
19965
|
-
|
|
20469
|
+
};
|
|
20470
|
+
var read = function read1() {
|
|
20471
|
+
reader.read().then(function(param) {
|
|
20472
|
+
var done = param.done, value = param.value;
|
|
20473
|
+
if (done) {
|
|
20474
|
+
accumulatedText += decoder.decode();
|
|
20475
|
+
reader.releaseLock();
|
|
20476
|
+
try {
|
|
20477
|
+
var output = JSON.parse(accumulatedText);
|
|
20478
|
+
publish(output);
|
|
20479
|
+
resolve({
|
|
20480
|
+
output: output
|
|
20481
|
+
});
|
|
20482
|
+
} catch (error) {
|
|
20483
|
+
reject(error);
|
|
20484
|
+
}
|
|
20485
|
+
return;
|
|
20486
|
+
}
|
|
20487
|
+
try {
|
|
20488
|
+
accumulatedText += decoder.decode(value, {
|
|
20489
|
+
stream: true
|
|
20490
|
+
});
|
|
20491
|
+
var partial = parsePartialJson(accumulatedText, latest);
|
|
20492
|
+
if (partial !== undefined) {
|
|
20493
|
+
publish(partial);
|
|
20494
|
+
}
|
|
20495
|
+
read();
|
|
20496
|
+
} catch (error) {
|
|
20497
|
+
reader.releaseLock();
|
|
20498
|
+
reject(error);
|
|
20499
|
+
}
|
|
20500
|
+
}, function(error) {
|
|
20501
|
+
reader.releaseLock();
|
|
20502
|
+
reject(error);
|
|
20503
|
+
});
|
|
20504
|
+
};
|
|
20505
|
+
read();
|
|
19966
20506
|
});
|
|
19967
20507
|
}
|
|
19968
20508
|
/** Default HTTP transport for named Tasks requests and task-output streams. */ var DefaultTaskTransport = /*#__PURE__*/ function() {
|
|
@@ -19986,9 +20526,10 @@
|
|
|
19986
20526
|
{
|
|
19987
20527
|
key: "sendTask",
|
|
19988
20528
|
value: function sendTask(param) {
|
|
19989
|
-
var task = param.task, input = param.input, stream = param.stream, onData = param.onData;
|
|
20529
|
+
var task = param.task, kind = param.kind, input = param.input, stream = param.stream, onData = param.onData;
|
|
19990
20530
|
return this.sendTaskRequest({
|
|
19991
20531
|
task: task,
|
|
20532
|
+
kind: kind,
|
|
19992
20533
|
input: input,
|
|
19993
20534
|
stream: stream,
|
|
19994
20535
|
onData: onData ? function(data) {
|
|
@@ -20001,7 +20542,7 @@
|
|
|
20001
20542
|
/** @internal */ key: "sendTaskRequest",
|
|
20002
20543
|
value: function sendTaskRequest(param) {
|
|
20003
20544
|
var _this = this;
|
|
20004
|
-
var task = param.task, input = param.input, stream = param.stream, onData = param.onData;
|
|
20545
|
+
var task = param.task, kind = param.kind, input = param.input, stream = param.stream, onData = param.onData;
|
|
20005
20546
|
var _this_fetch;
|
|
20006
20547
|
var fetchFn = (_this_fetch = this.fetch) !== null && _this_fetch !== void 0 ? _this_fetch : fetch;
|
|
20007
20548
|
return Promise.all([
|
|
@@ -20013,13 +20554,17 @@
|
|
|
20013
20554
|
var api = _this.api;
|
|
20014
20555
|
var credentials = resolvedCredentials;
|
|
20015
20556
|
var headers = withJsonContentType(resolvedHeaders);
|
|
20016
|
-
var body = _object_spread({
|
|
20017
|
-
task: task
|
|
20557
|
+
var body = _object_spread(_object_spread_props(_object_spread({}, task === undefined ? {} : {
|
|
20558
|
+
task: task
|
|
20559
|
+
}, kind === undefined ? {} : {
|
|
20560
|
+
kind: kind
|
|
20561
|
+
}), {
|
|
20018
20562
|
input: input
|
|
20019
|
-
}, resolvedBody);
|
|
20563
|
+
}), resolvedBody);
|
|
20020
20564
|
var preparedBody = resolvedBody ? _object_spread({}, resolvedBody) : undefined;
|
|
20021
20565
|
var preparePromise = _this.prepareSendMessagesRequest ? Promise.resolve(_this.prepareSendMessagesRequest(createTaskPreparationContext({
|
|
20022
20566
|
task: task,
|
|
20567
|
+
kind: kind,
|
|
20023
20568
|
input: input,
|
|
20024
20569
|
stream: stream,
|
|
20025
20570
|
body: preparedBody,
|
|
@@ -20054,8 +20599,11 @@
|
|
|
20054
20599
|
throw new Error("HTTP error ".concat(response.status));
|
|
20055
20600
|
}
|
|
20056
20601
|
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')) || '';
|
|
20057
|
-
if (stream &&
|
|
20058
|
-
|
|
20602
|
+
if (stream && contentType.includes('text/plain')) {
|
|
20603
|
+
if (!response.body) {
|
|
20604
|
+
throw new Error('Response body is empty');
|
|
20605
|
+
}
|
|
20606
|
+
return consumeTaskTextStream(response.body, onData);
|
|
20059
20607
|
}
|
|
20060
20608
|
return response.json();
|
|
20061
20609
|
});
|
|
@@ -20138,7 +20686,7 @@
|
|
|
20138
20686
|
}
|
|
20139
20687
|
|
|
20140
20688
|
function createTaskRunner(options) {
|
|
20141
|
-
var task = options.task, _options_stream = options.stream, stream = _options_stream === void 0 ? true : _options_stream;
|
|
20689
|
+
var task = options.task, kind = options.kind, _options_stream = options.stream, stream = _options_stream === void 0 ? true : _options_stream;
|
|
20142
20690
|
var transport;
|
|
20143
20691
|
if (options.transport !== undefined) {
|
|
20144
20692
|
transport = options.transport;
|
|
@@ -20149,11 +20697,14 @@
|
|
|
20149
20697
|
headers: options.headers,
|
|
20150
20698
|
fetch: options.fetch,
|
|
20151
20699
|
prepareSendMessagesRequest: prepareRequest ? function(param) {
|
|
20152
|
-
var requestTask = param.task, input = param.input;
|
|
20153
|
-
return prepareRequest({
|
|
20154
|
-
task: requestTask
|
|
20700
|
+
var requestTask = param.task, requestKind = param.kind, input = param.input;
|
|
20701
|
+
return prepareRequest(_object_spread_props(_object_spread({}, requestTask === undefined ? {} : {
|
|
20702
|
+
task: requestTask
|
|
20703
|
+
}, requestKind === undefined ? {} : {
|
|
20704
|
+
kind: requestKind
|
|
20705
|
+
}), {
|
|
20155
20706
|
input: input
|
|
20156
|
-
});
|
|
20707
|
+
}));
|
|
20157
20708
|
} : undefined
|
|
20158
20709
|
});
|
|
20159
20710
|
}
|
|
@@ -20162,6 +20713,7 @@
|
|
|
20162
20713
|
var onData = (arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}).onData;
|
|
20163
20714
|
return transport.sendTask({
|
|
20164
20715
|
task: task,
|
|
20716
|
+
kind: kind,
|
|
20165
20717
|
input: input,
|
|
20166
20718
|
stream: stream,
|
|
20167
20719
|
onData: onData
|
|
@@ -20178,12 +20730,12 @@
|
|
|
20178
20730
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
20179
20731
|
checkRendering(renderFn, withUsage$p());
|
|
20180
20732
|
return function(widgetParams) {
|
|
20181
|
-
var agentId = widgetParams.agentId, transport = widgetParams.transport, task = widgetParams.task, _widgetParams_stream = widgetParams.stream, stream = _widgetParams_stream === void 0 ? true : _widgetParams_stream;
|
|
20733
|
+
var agentId = widgetParams.agentId, transport = widgetParams.transport, task = widgetParams.task, kind = widgetParams.kind, _widgetParams_stream = widgetParams.stream, stream = _widgetParams_stream === void 0 ? true : _widgetParams_stream;
|
|
20182
20734
|
if (!agentId && !transport) {
|
|
20183
20735
|
throw new Error(withUsage$p('The `agentId` option is required unless a custom `transport` is provided.'));
|
|
20184
20736
|
}
|
|
20185
|
-
if (!task) {
|
|
20186
|
-
throw new Error(withUsage$p('
|
|
20737
|
+
if (!task && !kind) {
|
|
20738
|
+
throw new Error(withUsage$p('Either the `task` or `kind` option is required.'));
|
|
20187
20739
|
}
|
|
20188
20740
|
var runner;
|
|
20189
20741
|
var output;
|
|
@@ -20235,6 +20787,8 @@
|
|
|
20235
20787
|
// Bump the request id so any in-flight request's callbacks see
|
|
20236
20788
|
// `isStale()` and are ignored. The fetch itself is left to complete.
|
|
20237
20789
|
requestId += 1;
|
|
20790
|
+
output = undefined;
|
|
20791
|
+
error = undefined;
|
|
20238
20792
|
isLoading = false;
|
|
20239
20793
|
triggerRender();
|
|
20240
20794
|
};
|
|
@@ -20267,6 +20821,7 @@
|
|
|
20267
20821
|
runner = createTaskRunner({
|
|
20268
20822
|
transport: taskTransport,
|
|
20269
20823
|
task: task,
|
|
20824
|
+
kind: kind,
|
|
20270
20825
|
stream: stream
|
|
20271
20826
|
});
|
|
20272
20827
|
} else {
|
|
@@ -20275,6 +20830,7 @@
|
|
|
20275
20830
|
transport: transport
|
|
20276
20831
|
}),
|
|
20277
20832
|
task: task,
|
|
20833
|
+
kind: kind,
|
|
20278
20834
|
stream: stream
|
|
20279
20835
|
});
|
|
20280
20836
|
}
|
|
@@ -20300,55 +20856,13 @@
|
|
|
20300
20856
|
};
|
|
20301
20857
|
};
|
|
20302
20858
|
|
|
20303
|
-
// Centralizes the "open the chat from an entry point" behavior shared by the
|
|
20304
|
-
// SearchBox AI button, the Autocomplete AI button, prompt suggestions, and any
|
|
20305
|
-
// future entry point. The chat is always opened; the message is only sent when
|
|
20306
|
-
// it is non-empty and the chat is not already processing a message.
|
|
20307
|
-
// Returns true when a message was submitted, so callers can clear their input.
|
|
20308
|
-
function openChat(chatRenderState) {
|
|
20309
|
-
var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, message = _ref.message, referer = _ref.referer, turnContext = _ref.turnContext;
|
|
20310
|
-
var _ref1;
|
|
20311
|
-
var _chatRenderState_setOpen;
|
|
20312
|
-
if (!chatRenderState) {
|
|
20313
|
-
return false;
|
|
20314
|
-
}
|
|
20315
|
-
var trimmed = (_ref1 = message === null || message === void 0 ? void 0 : message.trim()) !== null && _ref1 !== void 0 ? _ref1 : '';
|
|
20316
|
-
if (!trimmed) {
|
|
20317
|
-
if (chatRenderState.focusInput) {
|
|
20318
|
-
chatRenderState.focusInput();
|
|
20319
|
-
} else {
|
|
20320
|
-
var _chatRenderState_setOpen1;
|
|
20321
|
-
(_chatRenderState_setOpen1 = chatRenderState.setOpen) === null || _chatRenderState_setOpen1 === void 0 ? void 0 : _chatRenderState_setOpen1.call(chatRenderState, true);
|
|
20322
|
-
}
|
|
20323
|
-
return false;
|
|
20324
|
-
}
|
|
20325
|
-
(_chatRenderState_setOpen = chatRenderState.setOpen) === null || _chatRenderState_setOpen === void 0 ? void 0 : _chatRenderState_setOpen.call(chatRenderState, true);
|
|
20326
|
-
if (isChatBusy(chatRenderState) || !chatRenderState.sendMessage) {
|
|
20327
|
-
return false;
|
|
20328
|
-
}
|
|
20329
|
-
chatRenderState.sendMessage(_object_spread({
|
|
20330
|
-
text: trimmed
|
|
20331
|
-
}, turnContext ? {
|
|
20332
|
-
metadata: {
|
|
20333
|
-
turnContext: turnContext
|
|
20334
|
-
}
|
|
20335
|
-
} : {}), referer ? {
|
|
20336
|
-
headers: {
|
|
20337
|
-
'x-algolia-referer': referer
|
|
20338
|
-
}
|
|
20339
|
-
} : undefined);
|
|
20340
|
-
return true;
|
|
20341
|
-
}
|
|
20342
|
-
function isChatBusy(chatRenderState) {
|
|
20343
|
-
return (chatRenderState === null || chatRenderState === void 0 ? void 0 : chatRenderState.status) === 'submitted' || (chatRenderState === null || chatRenderState === void 0 ? void 0 : chatRenderState.status) === 'streaming';
|
|
20344
|
-
}
|
|
20345
|
-
|
|
20346
20859
|
var withUsage$o = createDocumentationMessageGenerator({
|
|
20347
20860
|
name: 'prompt-suggestions',
|
|
20348
20861
|
connector: true
|
|
20349
20862
|
});
|
|
20350
20863
|
var RENDER_STATE_KEY = 'promptSuggestions';
|
|
20351
20864
|
var CHAT_RENDER_STATE_KEY = 'chat';
|
|
20865
|
+
var PROMPT_SUGGESTIONS_TASK_KIND = 'prompt_suggestions';
|
|
20352
20866
|
var DEBOUNCE_MS = 300;
|
|
20353
20867
|
function parseSuggestions(data) {
|
|
20354
20868
|
var suggestions = data === null || data === void 0 ? void 0 : data.suggestions;
|
|
@@ -20359,6 +20873,36 @@
|
|
|
20359
20873
|
return typeof s === 'string';
|
|
20360
20874
|
});
|
|
20361
20875
|
}
|
|
20876
|
+
// Key order is not significant to the request, so a plain `JSON.stringify` would
|
|
20877
|
+
// report two identical payloads as different.
|
|
20878
|
+
function stableKey(value) {
|
|
20879
|
+
if (value === null || (typeof value === "undefined" ? "undefined" : _type_of(value)) !== 'object') {
|
|
20880
|
+
var _JSON_stringify;
|
|
20881
|
+
return (_JSON_stringify = JSON.stringify(value)) !== null && _JSON_stringify !== void 0 ? _JSON_stringify : 'null';
|
|
20882
|
+
}
|
|
20883
|
+
if (Array.isArray(value)) {
|
|
20884
|
+
return "[".concat(value.map(stableKey).join(','), "]");
|
|
20885
|
+
}
|
|
20886
|
+
var record = value;
|
|
20887
|
+
return "{".concat(Object.keys(record).sort().map(function(key) {
|
|
20888
|
+
return "".concat(JSON.stringify(key), ":").concat(stableKey(record[key]));
|
|
20889
|
+
}).join(','), "}");
|
|
20890
|
+
}
|
|
20891
|
+
/**
|
|
20892
|
+
* Comparable identity of a task payload, or `null` when it cannot be compared.
|
|
20893
|
+
*/ function taskPayloadKey(payload) {
|
|
20894
|
+
try {
|
|
20895
|
+
// Round-trip first so the comparison sees what the request will actually
|
|
20896
|
+
// carry: `JSON.stringify` applies `toJSON` (a `Date` becomes its ISO string)
|
|
20897
|
+
// and drops the values the wire drops. Walking the raw object instead would
|
|
20898
|
+
// read a `Date` as a key-less object and call two different instants equal.
|
|
20899
|
+
return stableKey(JSON.parse(JSON.stringify(payload)));
|
|
20900
|
+
} catch (unused) {
|
|
20901
|
+
// Circular or otherwise unserializable. Never claim a match on a payload we
|
|
20902
|
+
// could not read; let the request go out and fail where it does today.
|
|
20903
|
+
return null;
|
|
20904
|
+
}
|
|
20905
|
+
}
|
|
20362
20906
|
function buildSuggestionMessage(suggestion) {
|
|
20363
20907
|
return "The user clicked this on-page suggestion. Use the current page context first, then search only if needed.\n\nSuggestion: ".concat(suggestion);
|
|
20364
20908
|
}
|
|
@@ -20420,14 +20964,16 @@
|
|
|
20420
20964
|
if (!agentId && !transport) {
|
|
20421
20965
|
throw new Error(withUsage$o('The `agentId` option is required unless a custom `transport` is provided.'));
|
|
20422
20966
|
}
|
|
20423
|
-
if (!configurationId) {
|
|
20424
|
-
throw new Error(withUsage$o('The `configurationId` option is required.'));
|
|
20425
|
-
}
|
|
20426
20967
|
var tasksState;
|
|
20427
20968
|
var suggestions = [];
|
|
20428
20969
|
var isLoading = false;
|
|
20970
|
+
var error;
|
|
20429
20971
|
var debounceTimer;
|
|
20430
20972
|
var lastStateSignature = null;
|
|
20973
|
+
// The payload of the last request that was actually sent. The automatic
|
|
20974
|
+
// trigger keys on the search state, which is only a proxy for the payload,
|
|
20975
|
+
// so this is what decides whether a request would ask anything new.
|
|
20976
|
+
var lastSubmittedPayload = null;
|
|
20431
20977
|
var latestRenderOptions = null;
|
|
20432
20978
|
// Set in `dispose()`. A debounced or in-flight `fetch()` can resolve after
|
|
20433
20979
|
// the widget is unmounted; this guard stops those late callbacks from
|
|
@@ -20438,6 +20984,10 @@
|
|
|
20438
20984
|
// still-in-flight request from the previous state must not paint its
|
|
20439
20985
|
// suggestions, its inner render is ignored until the new `submit` starts.
|
|
20440
20986
|
var refetchPending = false;
|
|
20987
|
+
// True when `refetchPending` made an inner render be dropped. The fetch
|
|
20988
|
+
// that dropped it was expected to render in its place; if that fetch turns
|
|
20989
|
+
// out to send nothing, it has to reconcile the dropped state instead.
|
|
20990
|
+
var droppedInnerRender = false;
|
|
20441
20991
|
var getStateSignature = function getStateSignature(results) {
|
|
20442
20992
|
var _buildFilters;
|
|
20443
20993
|
if (results.queryID) {
|
|
@@ -20524,19 +21074,62 @@
|
|
|
20524
21074
|
instantSearchInstance: renderOptions.instantSearchInstance
|
|
20525
21075
|
}), false);
|
|
20526
21076
|
};
|
|
21077
|
+
// Copies an inner render's state into this widget's and re-renders on the
|
|
21078
|
+
// client.
|
|
21079
|
+
var adoptInnerState = function adoptInnerState(renderState) {
|
|
21080
|
+
error = renderState.error;
|
|
21081
|
+
if (renderState.error) {
|
|
21082
|
+
// A failed task (including a mid-stream `error` event) must not leave
|
|
21083
|
+
// any streamed partial visible.
|
|
21084
|
+
suggestions = [];
|
|
21085
|
+
} else if (renderState.isLoading || renderState.output !== undefined) {
|
|
21086
|
+
// Only adopt the inner output once a request is loading or has
|
|
21087
|
+
// produced one, so the initial no-op render doesn't clobber pills.
|
|
21088
|
+
suggestions = parseSuggestions(renderState.output);
|
|
21089
|
+
}
|
|
21090
|
+
isLoading = renderState.isLoading;
|
|
21091
|
+
if (!latestRenderOptions) return;
|
|
21092
|
+
renderOutward(latestRenderOptions);
|
|
21093
|
+
};
|
|
20527
21094
|
var fetchAndRender = function fetchAndRender(results, renderOptions) {
|
|
21095
|
+
var _ref = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, _ref_force = _ref.force, force = _ref_force === void 0 ? false : _ref_force;
|
|
20528
21096
|
var _results_hits;
|
|
20529
21097
|
if (disposed || !tasksState) return;
|
|
21098
|
+
var hadDroppedInnerRender = droppedInnerRender;
|
|
20530
21099
|
refetchPending = false;
|
|
21100
|
+
droppedInnerRender = false;
|
|
20531
21101
|
var hasContext = context !== undefined;
|
|
20532
21102
|
if (!hasContext && !(results === null || results === void 0 ? void 0 : (_results_hits = results.hits) === null || _results_hits === void 0 ? void 0 : _results_hits.length)) {
|
|
20533
21103
|
tasksState.invalidate();
|
|
20534
21104
|
suggestions = [];
|
|
20535
21105
|
isLoading = false;
|
|
21106
|
+
// The output is gone, so the same payload must be allowed to rebuild it.
|
|
21107
|
+
lastSubmittedPayload = null;
|
|
20536
21108
|
renderOutward(renderOptions);
|
|
20537
21109
|
return;
|
|
20538
21110
|
}
|
|
20539
|
-
|
|
21111
|
+
var input = buildInput(results);
|
|
21112
|
+
var payload = taskPayloadKey(input);
|
|
21113
|
+
// A moved search state does not always mean a different question: with an
|
|
21114
|
+
// explicit `context` the payload ignores the results entirely, so a new
|
|
21115
|
+
// `queryID` or a new hit order produces a byte-identical request. Sending
|
|
21116
|
+
// it again spends a model call on an answer already on screen. Leave the
|
|
21117
|
+
// current suggestions alone and send nothing. `force` is the explicit
|
|
21118
|
+
// path (`refresh()`), which must always reach the network.
|
|
21119
|
+
if (!force && payload !== null && payload === lastSubmittedPayload) {
|
|
21120
|
+
// Nothing goes out, so nothing will render — but the state change that
|
|
21121
|
+
// scheduled this fetch also made `handleInnerRender` drop the render
|
|
21122
|
+
// that was carrying the previous request's result. Reconcile it here or
|
|
21123
|
+
// the widget keeps that request's `isLoading: true` with no
|
|
21124
|
+
// suggestions, and nothing later clears it: `refresh()` is blocked by
|
|
21125
|
+
// its own `isLoading` guard and an unchanged payload keeps skipping.
|
|
21126
|
+
if (hadDroppedInnerRender) {
|
|
21127
|
+
adoptInnerState(tasksState);
|
|
21128
|
+
}
|
|
21129
|
+
return;
|
|
21130
|
+
}
|
|
21131
|
+
lastSubmittedPayload = payload;
|
|
21132
|
+
tasksState.submit(input);
|
|
20540
21133
|
};
|
|
20541
21134
|
var refresh = function refresh() {
|
|
20542
21135
|
if (isLoading) return;
|
|
@@ -20544,7 +21137,9 @@
|
|
|
20544
21137
|
if (!results || !latestRenderOptions) return;
|
|
20545
21138
|
clearTimeout(debounceTimer);
|
|
20546
21139
|
lastStateSignature = getStateSignature(results);
|
|
20547
|
-
fetchAndRender(results, latestRenderOptions
|
|
21140
|
+
fetchAndRender(results, latestRenderOptions, {
|
|
21141
|
+
force: true
|
|
21142
|
+
});
|
|
20548
21143
|
};
|
|
20549
21144
|
var getWidgetRenderState = function getWidgetRenderState(renderOptions) {
|
|
20550
21145
|
var results = 'results' in renderOptions ? renderOptions.results : undefined;
|
|
@@ -20558,6 +21153,7 @@
|
|
|
20558
21153
|
return {
|
|
20559
21154
|
suggestions: transformed,
|
|
20560
21155
|
isLoading: isLoading,
|
|
21156
|
+
error: error,
|
|
20561
21157
|
onSuggestionClick: send,
|
|
20562
21158
|
sendToChat: send,
|
|
20563
21159
|
refresh: refresh,
|
|
@@ -20569,20 +21165,18 @@
|
|
|
20569
21165
|
// resolve/error) into this widget's state and re-renders on the client.
|
|
20570
21166
|
var handleInnerRender = function handleInnerRender(renderState) {
|
|
20571
21167
|
tasksState = renderState;
|
|
20572
|
-
if (refetchPending) return;
|
|
20573
21168
|
if (renderState.error) {
|
|
20574
|
-
//
|
|
20575
|
-
//
|
|
20576
|
-
//
|
|
20577
|
-
|
|
20578
|
-
|
|
20579
|
-
|
|
20580
|
-
|
|
20581
|
-
|
|
21169
|
+
// Keep a failed payload retryable: without this the next automatic
|
|
21170
|
+
// attempt with the same payload would be skipped as a duplicate and
|
|
21171
|
+
// the error would have no way to clear. Set before the `refetchPending`
|
|
21172
|
+
// return so a failure that lands mid-refetch is not swallowed.
|
|
21173
|
+
lastSubmittedPayload = null;
|
|
21174
|
+
}
|
|
21175
|
+
if (refetchPending) {
|
|
21176
|
+
droppedInnerRender = true;
|
|
21177
|
+
return;
|
|
20582
21178
|
}
|
|
20583
|
-
|
|
20584
|
-
if (!latestRenderOptions) return;
|
|
20585
|
-
renderOutward(latestRenderOptions);
|
|
21179
|
+
adoptInnerState(renderState);
|
|
20586
21180
|
};
|
|
20587
21181
|
var tasksParams;
|
|
20588
21182
|
if (agentId) {
|
|
@@ -20590,12 +21184,14 @@
|
|
|
20590
21184
|
agentId: agentId,
|
|
20591
21185
|
transport: transport,
|
|
20592
21186
|
task: configurationId,
|
|
21187
|
+
kind: PROMPT_SUGGESTIONS_TASK_KIND,
|
|
20593
21188
|
stream: true
|
|
20594
21189
|
};
|
|
20595
21190
|
} else if (transport) {
|
|
20596
21191
|
tasksParams = {
|
|
20597
21192
|
transport: transport,
|
|
20598
21193
|
task: configurationId,
|
|
21194
|
+
kind: PROMPT_SUGGESTIONS_TASK_KIND,
|
|
20599
21195
|
stream: true
|
|
20600
21196
|
};
|
|
20601
21197
|
} else {
|
|
@@ -20624,6 +21220,7 @@
|
|
|
20624
21220
|
if (stateSignature !== lastStateSignature) {
|
|
20625
21221
|
lastStateSignature = stateSignature;
|
|
20626
21222
|
refetchPending = true;
|
|
21223
|
+
error = undefined;
|
|
20627
21224
|
clearTimeout(debounceTimer);
|
|
20628
21225
|
debounceTimer = setTimeout(function() {
|
|
20629
21226
|
if (latestRenderOptions === null || latestRenderOptions === void 0 ? void 0 : latestRenderOptions.results) {
|
|
@@ -24868,13 +25465,6 @@
|
|
|
24868
25465
|
});
|
|
24869
25466
|
}
|
|
24870
25467
|
|
|
24871
|
-
var SearchIndexToolType = 'algolia_search_index';
|
|
24872
|
-
var RecommendToolType = 'algolia_recommend';
|
|
24873
|
-
var MemorizeToolType = 'algolia_memorize';
|
|
24874
|
-
var MemorySearchToolType = 'algolia_memory_search';
|
|
24875
|
-
var PonderToolType = 'algolia_ponder';
|
|
24876
|
-
var DisplayResultsToolType = 'algolia_display_results';
|
|
24877
|
-
|
|
24878
25468
|
var AutocompleteSearchComponent = createAutocompleteSearchComponent({
|
|
24879
25469
|
createElement: React.createElement,
|
|
24880
25470
|
Fragment: React.Fragment
|
|
@@ -26330,7 +26920,7 @@
|
|
|
26330
26920
|
var _ref = [
|
|
26331
26921
|
_0,
|
|
26332
26922
|
_1
|
|
26333
|
-
], _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, loaderPosition = _ref2.loaderPosition, shouldShowLoader = _ref2.shouldShowLoader, loaderShowDelay = _ref2.loaderShowDelay, loaderMinDuration = _ref2.loaderMinDuration, 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, [
|
|
26923
|
+
], _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, loaderPosition = _ref2.loaderPosition, shouldShowLoader = _ref2.shouldShowLoader, loaderShowDelay = _ref2.loaderShowDelay, loaderMinDuration = _ref2.loaderMinDuration, 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, reasoningComponent = _ref2.reasoningComponent, props = _object_without_properties(_ref2, [
|
|
26334
26924
|
"tools",
|
|
26335
26925
|
"headerProps",
|
|
26336
26926
|
"messagesProps",
|
|
@@ -26363,7 +26953,8 @@
|
|
|
26363
26953
|
"title",
|
|
26364
26954
|
"getSearchPageURL",
|
|
26365
26955
|
"disableTriggerValidation",
|
|
26366
|
-
"showReasoning"
|
|
26956
|
+
"showReasoning",
|
|
26957
|
+
"reasoningComponent"
|
|
26367
26958
|
]), _rest1 = _sliced_to_array(_rest, 1), ref = _rest1[0];
|
|
26368
26959
|
var _ref3;
|
|
26369
26960
|
var promptTranslations = translations.prompt, headerTranslations = translations.header, messageTranslations = translations.message, messagesTranslations = translations.messages;
|
|
@@ -26394,11 +26985,21 @@
|
|
|
26394
26985
|
disableTriggerValidation: effectiveDisableTriggerValidation
|
|
26395
26986
|
}));
|
|
26396
26987
|
var messages = chatState.messages, sendMessage = chatState.sendMessage, status = chatState.status, regenerate = chatState.regenerate, stop = chatState.stop, error = chatState.error, input = chatState.input, setInput = chatState.setInput, open = chatState.open, setOpen = chatState.setOpen, clearMessages = chatState.clearMessages, toolsFromConnector = chatState.tools, suggestions = chatState.suggestions, suggestionsStatus = chatState.suggestionsStatus, onFeedback = chatState.sendChatMessageFeedback, feedbackState = chatState.feedbackState, consumeInputFocus = chatState['~consumeInputFocus'], isOpenStatePersistenceEnabled = chatState['~isOpenStatePersistenceEnabled'];
|
|
26988
|
+
var sendMessageAndScrollToBottom = React.useCallback(function() {
|
|
26989
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
26990
|
+
args[_key] = arguments[_key];
|
|
26991
|
+
}
|
|
26992
|
+
scrollToBottom();
|
|
26993
|
+
return sendMessage.apply(void 0, _to_consumable_array(args));
|
|
26994
|
+
}, [
|
|
26995
|
+
scrollToBottom,
|
|
26996
|
+
sendMessage
|
|
26997
|
+
]);
|
|
26397
26998
|
React.useImperativeHandle(ref, function() {
|
|
26398
26999
|
return {
|
|
26399
27000
|
setOpen: setOpen,
|
|
26400
|
-
sendMessage: function
|
|
26401
|
-
return
|
|
27001
|
+
sendMessage: function sendMessage(params) {
|
|
27002
|
+
return sendMessageAndScrollToBottom(params);
|
|
26402
27003
|
},
|
|
26403
27004
|
setInput: setInput
|
|
26404
27005
|
};
|
|
@@ -26450,7 +27051,7 @@
|
|
|
26450
27051
|
title: title,
|
|
26451
27052
|
open: open,
|
|
26452
27053
|
maximized: maximized,
|
|
26453
|
-
sendMessage:
|
|
27054
|
+
sendMessage: sendMessageAndScrollToBottom,
|
|
26454
27055
|
regenerate: regenerate,
|
|
26455
27056
|
stop: stop,
|
|
26456
27057
|
error: error,
|
|
@@ -26485,7 +27086,7 @@
|
|
|
26485
27086
|
onClose: function onClose() {
|
|
26486
27087
|
return setOpen(false);
|
|
26487
27088
|
},
|
|
26488
|
-
sendMessage:
|
|
27089
|
+
sendMessage: sendMessageAndScrollToBottom,
|
|
26489
27090
|
setInput: setInput,
|
|
26490
27091
|
onFeedback: onFeedback,
|
|
26491
27092
|
feedbackState: feedbackState,
|
|
@@ -26511,7 +27112,8 @@
|
|
|
26511
27112
|
assistantMessageProps: _object_spread({
|
|
26512
27113
|
leadingComponent: assistantMessageLeadingComponent,
|
|
26513
27114
|
footerComponent: assistantMessageFooterComponent,
|
|
26514
|
-
showReasoning: showReasoning
|
|
27115
|
+
showReasoning: showReasoning,
|
|
27116
|
+
reasoningComponent: reasoningComponent
|
|
26515
27117
|
}, callerAssistantMessageProps),
|
|
26516
27118
|
userMessageProps: _object_spread({
|
|
26517
27119
|
leadingComponent: userMessageLeadingComponent,
|
|
@@ -26528,7 +27130,7 @@
|
|
|
26528
27130
|
setInput(event.currentTarget.value);
|
|
26529
27131
|
},
|
|
26530
27132
|
onSubmit: function onSubmit() {
|
|
26531
|
-
|
|
27133
|
+
sendMessageAndScrollToBottom({
|
|
26532
27134
|
text: input
|
|
26533
27135
|
});
|
|
26534
27136
|
setInput('');
|
|
@@ -26545,7 +27147,7 @@
|
|
|
26545
27147
|
suggestions: suggestions,
|
|
26546
27148
|
isLoading: suggestionsStatus === 'loading',
|
|
26547
27149
|
onSuggestionClick: function onSuggestionClick(suggestion) {
|
|
26548
|
-
|
|
27150
|
+
sendMessageAndScrollToBottom({
|
|
26549
27151
|
text: suggestion
|
|
26550
27152
|
});
|
|
26551
27153
|
}
|
|
@@ -26590,7 +27192,7 @@
|
|
|
26590
27192
|
transformItems: transformItems
|
|
26591
27193
|
}), {
|
|
26592
27194
|
$$widgetType: 'ais.promptSuggestions'
|
|
26593
|
-
}), suggestions = _usePromptSuggestions.suggestions, isLoading = _usePromptSuggestions.isLoading, onSuggestionClick = _usePromptSuggestions.onSuggestionClick, isChatBusy = _usePromptSuggestions.isChatBusy, sendToChat = _usePromptSuggestions.sendToChat;
|
|
27195
|
+
}), suggestions = _usePromptSuggestions.suggestions, isLoading = _usePromptSuggestions.isLoading, error = _usePromptSuggestions.error, onSuggestionClick = _usePromptSuggestions.onSuggestionClick, isChatBusy = _usePromptSuggestions.isChatBusy, sendToChat = _usePromptSuggestions.sendToChat;
|
|
26594
27196
|
var handleClick = onSuggestionClickOverride ? function(prompt) {
|
|
26595
27197
|
return onSuggestionClickOverride(prompt, {
|
|
26596
27198
|
sendToChat: sendToChat
|
|
@@ -26600,6 +27202,7 @@
|
|
|
26600
27202
|
return /*#__PURE__*/ React.createElement(LayoutComponent, {
|
|
26601
27203
|
suggestions: suggestions,
|
|
26602
27204
|
isLoading: isLoading,
|
|
27205
|
+
error: error,
|
|
26603
27206
|
onSuggestionClick: handleClick,
|
|
26604
27207
|
isChatBusy: isChatBusy
|
|
26605
27208
|
});
|