react-instantsearch 7.42.0 → 7.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! React InstantSearch 7.
|
|
1
|
+
/*! React InstantSearch 7.44.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.44.0';
|
|
28
28
|
|
|
29
29
|
function _define_property(obj, key, value) {
|
|
30
30
|
if (key in obj) {
|
|
@@ -6278,22 +6278,29 @@
|
|
|
6278
6278
|
*
|
|
6279
6279
|
* Parameters set on a widget win, so an explicit `queryParameters.userToken`
|
|
6280
6280
|
* keeps overriding the middleware.
|
|
6281
|
+
*
|
|
6282
|
+
* The fallback query is a regular search, so it gets the same treatment — but
|
|
6283
|
+
* only merged into a `fallbackParameters` the widget already set. See below.
|
|
6281
6284
|
*/ function addInsightsToRecommendParameters(recommendParameters, param) {
|
|
6282
6285
|
var userToken = param.userToken, clickAnalytics = param.clickAnalytics;
|
|
6283
6286
|
if (userToken === undefined && clickAnalytics === undefined) {
|
|
6284
6287
|
return recommendParameters;
|
|
6285
6288
|
}
|
|
6289
|
+
var insightsParameters = _object_spread({}, clickAnalytics === undefined ? {} : {
|
|
6290
|
+
clickAnalytics: clickAnalytics
|
|
6291
|
+
}, userToken === undefined ? {} : {
|
|
6292
|
+
userToken: userToken
|
|
6293
|
+
});
|
|
6286
6294
|
return new algoliasearchHelper.RecommendParameters({
|
|
6287
6295
|
params: recommendParameters.params.map(function(params) {
|
|
6288
|
-
// v4 `TrendingFacetsQuery` doesn't include `queryParameters
|
|
6289
|
-
// API and the helper support them, like
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6294
|
-
|
|
6295
|
-
|
|
6296
|
-
}, queryParameters)
|
|
6296
|
+
// v4 `TrendingFacetsQuery` doesn't include `queryParameters` or
|
|
6297
|
+
// `fallbackParameters`, but the v5 API and the helper support them, like
|
|
6298
|
+
// `connectTrendingFacets` does.
|
|
6299
|
+
var queryParameters = params.queryParameters, fallbackParameters = params.fallbackParameters;
|
|
6300
|
+
return _object_spread(_object_spread_props(_object_spread({}, params), {
|
|
6301
|
+
queryParameters: _object_spread({}, insightsParameters, queryParameters)
|
|
6302
|
+
}), fallbackParameters && {
|
|
6303
|
+
fallbackParameters: _object_spread({}, insightsParameters, fallbackParameters)
|
|
6297
6304
|
});
|
|
6298
6305
|
})
|
|
6299
6306
|
});
|
|
@@ -9216,7 +9223,7 @@
|
|
|
9216
9223
|
});
|
|
9217
9224
|
}
|
|
9218
9225
|
|
|
9219
|
-
var version = '4.
|
|
9226
|
+
var version = '4.111.0';
|
|
9220
9227
|
|
|
9221
9228
|
var ANONYMOUS_TOKEN_COOKIE_KEY = '_ALGOLIA';
|
|
9222
9229
|
function getCookie(name) {
|
|
@@ -12093,6 +12100,10 @@
|
|
|
12093
12100
|
var ssrSearchRef = React.useRef(null);
|
|
12094
12101
|
// This is used to re-map the result index to the requesting widget
|
|
12095
12102
|
var recommendIdx = React.useRef(0);
|
|
12103
|
+
var hydrationCompleteRef = React.useRef(false);
|
|
12104
|
+
React.useEffect(function() {
|
|
12105
|
+
hydrationCompleteRef.current = true;
|
|
12106
|
+
}, []);
|
|
12096
12107
|
// When <DynamicWidgets> is mounted, a second provider is used above the user-land
|
|
12097
12108
|
// <InstantSearchSSRProvider> in `getServerState()`.
|
|
12098
12109
|
// To avoid the user's provider overriding the context value with an empty object,
|
|
@@ -12100,11 +12111,13 @@
|
|
|
12100
12111
|
if (Object.keys(props).length === 0) {
|
|
12101
12112
|
return /*#__PURE__*/ React.createElement(React.Fragment, null, children);
|
|
12102
12113
|
}
|
|
12114
|
+
var contextValue = _object_spread_props(_object_spread({}, props), {
|
|
12115
|
+
ssrSearchRef: ssrSearchRef,
|
|
12116
|
+
recommendIdx: recommendIdx,
|
|
12117
|
+
hydrationCompleteRef: hydrationCompleteRef
|
|
12118
|
+
});
|
|
12103
12119
|
return /*#__PURE__*/ React.createElement(InstantSearchSSRContext.Provider, {
|
|
12104
|
-
value:
|
|
12105
|
-
ssrSearchRef: ssrSearchRef,
|
|
12106
|
-
recommendIdx: recommendIdx
|
|
12107
|
-
})
|
|
12120
|
+
value: contextValue
|
|
12108
12121
|
}, children);
|
|
12109
12122
|
}
|
|
12110
12123
|
|
|
@@ -14148,13 +14161,17 @@
|
|
|
14148
14161
|
if (!chatRenderState) {
|
|
14149
14162
|
return false;
|
|
14150
14163
|
}
|
|
14151
|
-
(_chatRenderState_setOpen = chatRenderState.setOpen) === null || _chatRenderState_setOpen === void 0 ? void 0 : _chatRenderState_setOpen.call(chatRenderState, true);
|
|
14152
14164
|
var trimmed = (_ref1 = message === null || message === void 0 ? void 0 : message.trim()) !== null && _ref1 !== void 0 ? _ref1 : '';
|
|
14153
14165
|
if (!trimmed) {
|
|
14154
|
-
|
|
14155
|
-
|
|
14166
|
+
if (chatRenderState.focusInput) {
|
|
14167
|
+
chatRenderState.focusInput();
|
|
14168
|
+
} else {
|
|
14169
|
+
var _chatRenderState_setOpen1;
|
|
14170
|
+
(_chatRenderState_setOpen1 = chatRenderState.setOpen) === null || _chatRenderState_setOpen1 === void 0 ? void 0 : _chatRenderState_setOpen1.call(chatRenderState, true);
|
|
14171
|
+
}
|
|
14156
14172
|
return false;
|
|
14157
14173
|
}
|
|
14174
|
+
(_chatRenderState_setOpen = chatRenderState.setOpen) === null || _chatRenderState_setOpen === void 0 ? void 0 : _chatRenderState_setOpen.call(chatRenderState, true);
|
|
14158
14175
|
if (isChatBusy(chatRenderState) || !chatRenderState.sendMessage) {
|
|
14159
14176
|
return false;
|
|
14160
14177
|
}
|
|
@@ -14382,6 +14399,58 @@
|
|
|
14382
14399
|
name: 'chat',
|
|
14383
14400
|
connector: true
|
|
14384
14401
|
});
|
|
14402
|
+
var OPEN_STATE_CACHE_KEY = 'instantsearch-chat-open-state';
|
|
14403
|
+
function normalizePersistence(persistence, hasCustomChat) {
|
|
14404
|
+
if (hasCustomChat) {
|
|
14405
|
+
return {
|
|
14406
|
+
messages: false,
|
|
14407
|
+
open: persistence === undefined || (typeof persistence === "undefined" ? "undefined" : _type_of(persistence)) === 'object' && persistence.open === true
|
|
14408
|
+
};
|
|
14409
|
+
}
|
|
14410
|
+
if (persistence === undefined || persistence === true) {
|
|
14411
|
+
return {
|
|
14412
|
+
messages: true,
|
|
14413
|
+
open: true
|
|
14414
|
+
};
|
|
14415
|
+
}
|
|
14416
|
+
if (persistence === false) {
|
|
14417
|
+
return {
|
|
14418
|
+
messages: false,
|
|
14419
|
+
open: false
|
|
14420
|
+
};
|
|
14421
|
+
}
|
|
14422
|
+
return {
|
|
14423
|
+
messages: persistence.messages === true,
|
|
14424
|
+
open: persistence.open === true
|
|
14425
|
+
};
|
|
14426
|
+
}
|
|
14427
|
+
function getOpenStateCacheKey(type) {
|
|
14428
|
+
return "".concat(OPEN_STATE_CACHE_KEY, "-").concat(type);
|
|
14429
|
+
}
|
|
14430
|
+
function readPersistedOpen(type) {
|
|
14431
|
+
try {
|
|
14432
|
+
return safelyRunOnBrowser(function(param) {
|
|
14433
|
+
var browserWindow = param.window;
|
|
14434
|
+
return browserWindow.sessionStorage.getItem(getOpenStateCacheKey(type)) === 'true';
|
|
14435
|
+
}, {
|
|
14436
|
+
fallback: function fallback() {
|
|
14437
|
+
return false;
|
|
14438
|
+
}
|
|
14439
|
+
});
|
|
14440
|
+
} catch (unused) {
|
|
14441
|
+
return false;
|
|
14442
|
+
}
|
|
14443
|
+
}
|
|
14444
|
+
function writePersistedOpen(type, open) {
|
|
14445
|
+
try {
|
|
14446
|
+
safelyRunOnBrowser(function(param) {
|
|
14447
|
+
var browserWindow = param.window;
|
|
14448
|
+
browserWindow.sessionStorage.setItem(getOpenStateCacheKey(type), String(open));
|
|
14449
|
+
});
|
|
14450
|
+
} catch (unused) {
|
|
14451
|
+
// Storage availability must not block the visible state change.
|
|
14452
|
+
}
|
|
14453
|
+
}
|
|
14385
14454
|
function getAttributesToClear$1(param) {
|
|
14386
14455
|
var results = param.results, helper = param.helper;
|
|
14387
14456
|
return uniq(getRefinements(results, helper.state, true).map(function(refinement) {
|
|
@@ -14441,10 +14510,11 @@
|
|
|
14441
14510
|
var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
14442
14511
|
checkRendering(renderFn, withUsage$q());
|
|
14443
14512
|
return function(widgetParams) {
|
|
14444
|
-
var _ref = widgetParams || {}, _ref_resume = _ref.resume, resume = _ref_resume === void 0 ? false : _ref_resume, _ref_tools = _ref.tools, tools = _ref_tools === void 0 ? {} : _ref_tools, _ref_type = _ref.type, type = _ref_type === void 0 ? 'chat' : _ref_type, context = _ref.context, initialUserMessage = _ref.initialUserMessage, initialMessages = _ref.initialMessages, _ref_disableTriggerValidation = _ref.disableTriggerValidation, disableTriggerValidation = _ref_disableTriggerValidation === void 0 ? false : _ref_disableTriggerValidation, _ref_sendAutomaticallyWhen = _ref.sendAutomaticallyWhen, sendAutomaticallyWhen = _ref_sendAutomaticallyWhen === void 0 ? lastAssistantMessageIsCompleteWithToolCalls : _ref_sendAutomaticallyWhen, _ref_requiresSearch = _ref.requiresSearch, requiresSearch = _ref_requiresSearch === void 0 ? true : _ref_requiresSearch, options = _object_without_properties(_ref, [
|
|
14513
|
+
var _ref = widgetParams || {}, _ref_resume = _ref.resume, resume = _ref_resume === void 0 ? false : _ref_resume, _ref_tools = _ref.tools, tools = _ref_tools === void 0 ? {} : _ref_tools, _ref_type = _ref.type, type = _ref_type === void 0 ? 'chat' : _ref_type, 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, [
|
|
14445
14514
|
"resume",
|
|
14446
14515
|
"tools",
|
|
14447
14516
|
"type",
|
|
14517
|
+
"persistence",
|
|
14448
14518
|
"context",
|
|
14449
14519
|
"initialUserMessage",
|
|
14450
14520
|
"initialMessages",
|
|
@@ -14452,6 +14522,7 @@
|
|
|
14452
14522
|
"sendAutomaticallyWhen",
|
|
14453
14523
|
"requiresSearch"
|
|
14454
14524
|
]);
|
|
14525
|
+
var normalizedPersistence = normalizePersistence(persistence, 'chat' in options);
|
|
14455
14526
|
var _chatInstance;
|
|
14456
14527
|
var input = '';
|
|
14457
14528
|
var open = false;
|
|
@@ -14459,12 +14530,19 @@
|
|
|
14459
14530
|
var setInput;
|
|
14460
14531
|
var setOpen;
|
|
14461
14532
|
var focusInput;
|
|
14533
|
+
var inputFocusRequested = false;
|
|
14462
14534
|
var setFeedbackState;
|
|
14463
14535
|
var hasValidatedEntryPoints = false;
|
|
14464
14536
|
var agentId = 'agentId' in options ? options.agentId : undefined;
|
|
14465
14537
|
var feedbackState = {};
|
|
14466
14538
|
var _sendChatMessageFeedback;
|
|
14467
14539
|
var feedbackAbortController;
|
|
14540
|
+
var chatSubscriptionUnsubscribers = [];
|
|
14541
|
+
var unsubscribeChatCallbacks = function unsubscribeChatCallbacks() {
|
|
14542
|
+
chatSubscriptionUnsubscribers.splice(0).forEach(function(unsubscribe) {
|
|
14543
|
+
return unsubscribe();
|
|
14544
|
+
});
|
|
14545
|
+
};
|
|
14468
14546
|
// Extract suggestions from the last assistant message's data-suggestions part
|
|
14469
14547
|
var getSuggestionsFromMessages = function getSuggestionsFromMessages(messages) {
|
|
14470
14548
|
// Find the last assistant message (iterate from end)
|
|
@@ -14613,6 +14691,7 @@
|
|
|
14613
14691
|
throw new Error(withUsage$q('You need to provide either an `agentId` or a `transport`.'));
|
|
14614
14692
|
}
|
|
14615
14693
|
return new Chat$1(_object_spread_props(_object_spread({}, options), {
|
|
14694
|
+
persistence: normalizedPersistence.messages,
|
|
14616
14695
|
sendAutomaticallyWhen: sendAutomaticallyWhen,
|
|
14617
14696
|
transport: transport,
|
|
14618
14697
|
shouldRepairToolInput: function shouldRepairToolInput(toolName) {
|
|
@@ -14661,22 +14740,30 @@
|
|
|
14661
14740
|
var _this = this;
|
|
14662
14741
|
var instantSearchInstance = initOptions.instantSearchInstance;
|
|
14663
14742
|
validateEntryPoints(instantSearchInstance);
|
|
14743
|
+
open = normalizedPersistence.open ? readPersistedOpen(type) : false;
|
|
14664
14744
|
_chatInstance = makeChatInstance(instantSearchInstance);
|
|
14665
14745
|
var render = function render() {
|
|
14666
14746
|
renderFn(_object_spread_props(_object_spread({}, _this.getWidgetRenderState(initOptions)), {
|
|
14667
14747
|
instantSearchInstance: initOptions.instantSearchInstance
|
|
14668
14748
|
}), false);
|
|
14669
14749
|
};
|
|
14670
|
-
|
|
14671
|
-
open =
|
|
14750
|
+
var updateOpen = function updateOpen(nextOpen, requestFocus) {
|
|
14751
|
+
open = nextOpen;
|
|
14752
|
+
inputFocusRequested = nextOpen && (inputFocusRequested || requestFocus);
|
|
14753
|
+
if (normalizedPersistence.open) {
|
|
14754
|
+
writePersistedOpen(type, open);
|
|
14755
|
+
}
|
|
14672
14756
|
render();
|
|
14673
14757
|
// `open` is read by sibling widgets (e.g. `chatTrigger`) via the
|
|
14674
14758
|
// shared `renderState`. Schedule a full re-render so they pick up
|
|
14675
14759
|
// the new value instead of staying frozen on their initial state.
|
|
14676
14760
|
initOptions.instantSearchInstance.scheduleRender();
|
|
14677
14761
|
};
|
|
14762
|
+
setOpen = function setOpen(nextOpen) {
|
|
14763
|
+
updateOpen(nextOpen, nextOpen && !open);
|
|
14764
|
+
};
|
|
14678
14765
|
focusInput = function focusInput() {
|
|
14679
|
-
|
|
14766
|
+
updateOpen(true, true);
|
|
14680
14767
|
};
|
|
14681
14768
|
setInput = function setInput(i) {
|
|
14682
14769
|
input = i;
|
|
@@ -14710,18 +14797,21 @@
|
|
|
14710
14797
|
};
|
|
14711
14798
|
}
|
|
14712
14799
|
var hasExistingMessages = _chatInstance.messages.length > 0;
|
|
14713
|
-
//
|
|
14714
|
-
//
|
|
14715
|
-
// conversation, so it leaves the instance empty.
|
|
14800
|
+
// Unsubscribe previous callbacks before setting initialMessages, then
|
|
14801
|
+
// register the current callbacks after to avoid re-renders during init.
|
|
14802
|
+
// A server render owns no conversation, so it leaves the instance empty.
|
|
14716
14803
|
safelyRunOnBrowser(function() {
|
|
14804
|
+
unsubscribeChatCallbacks();
|
|
14717
14805
|
if ((initialMessages === null || initialMessages === void 0 ? void 0 : initialMessages.length) && !resume && !hasExistingMessages) {
|
|
14718
14806
|
_chatInstance.messages = initialMessages;
|
|
14719
14807
|
}
|
|
14720
14808
|
});
|
|
14721
14809
|
safelyRunOnBrowser(function() {
|
|
14722
|
-
|
|
14723
|
-
|
|
14724
|
-
|
|
14810
|
+
chatSubscriptionUnsubscribers = [
|
|
14811
|
+
_chatInstance['~registerErrorCallback'](render),
|
|
14812
|
+
_chatInstance['~registerMessagesCallback'](render),
|
|
14813
|
+
_chatInstance['~registerStatusCallback'](render)
|
|
14814
|
+
];
|
|
14725
14815
|
});
|
|
14726
14816
|
// Resuming and sending reach the network, which a server render must
|
|
14727
14817
|
// not: the HTML pass repeats what `getServerState` already rendered, so
|
|
@@ -14740,6 +14830,9 @@
|
|
|
14740
14830
|
renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
|
|
14741
14831
|
instantSearchInstance: instantSearchInstance
|
|
14742
14832
|
}), true);
|
|
14833
|
+
if (open) {
|
|
14834
|
+
instantSearchInstance.scheduleRender();
|
|
14835
|
+
}
|
|
14743
14836
|
},
|
|
14744
14837
|
render: function render(renderOptions) {
|
|
14745
14838
|
validateEntryPoints(renderOptions.instantSearchInstance);
|
|
@@ -14806,7 +14899,7 @@
|
|
|
14806
14899
|
})
|
|
14807
14900
|
].concat(_to_consumable_array(rest)));
|
|
14808
14901
|
};
|
|
14809
|
-
|
|
14902
|
+
var renderState = {
|
|
14810
14903
|
indexUiState: instantSearchInstance.getUiState()[parent.getIndexId()],
|
|
14811
14904
|
input: input,
|
|
14812
14905
|
open: open,
|
|
@@ -14815,6 +14908,12 @@
|
|
|
14815
14908
|
setInput: setInput,
|
|
14816
14909
|
setOpen: setOpen,
|
|
14817
14910
|
focusInput: focusInput,
|
|
14911
|
+
'~consumeInputFocus': function() {
|
|
14912
|
+
var shouldFocus = inputFocusRequested;
|
|
14913
|
+
inputFocusRequested = false;
|
|
14914
|
+
return shouldFocus;
|
|
14915
|
+
},
|
|
14916
|
+
'~isOpenStatePersistenceEnabled': normalizedPersistence.open,
|
|
14818
14917
|
setMessages: setMessages,
|
|
14819
14918
|
suggestions: getSuggestionsFromMessages(_chatInstance.messages),
|
|
14820
14919
|
clearMessages: clearMessages,
|
|
@@ -14834,9 +14933,11 @@
|
|
|
14834
14933
|
status: _chatInstance.status,
|
|
14835
14934
|
stop: _chatInstance.stop
|
|
14836
14935
|
};
|
|
14936
|
+
return renderState;
|
|
14837
14937
|
},
|
|
14838
14938
|
dispose: function dispose() {
|
|
14839
14939
|
feedbackAbortController === null || feedbackAbortController === void 0 ? void 0 : feedbackAbortController.abort();
|
|
14940
|
+
unsubscribeChatCallbacks();
|
|
14840
14941
|
unmountFn();
|
|
14841
14942
|
},
|
|
14842
14943
|
shouldRender: function shouldRender() {
|
|
@@ -14867,17 +14968,15 @@
|
|
|
14867
14968
|
// `InstantSearchSSRProvider` flow: the server context covers state collection,
|
|
14868
14969
|
// and the SSR context covers HTML rendering and hydration.
|
|
14869
14970
|
//
|
|
14870
|
-
// This can cost an extra render: a mount inside a provider that carries server
|
|
14871
|
-
// state is withheld once even when there is no server markup to reproduce. A
|
|
14872
|
-
// mount outside both contexts is never withheld.
|
|
14873
|
-
//
|
|
14874
14971
|
// The shim's React 16 and 17 fallback ignores the server snapshot, so using it
|
|
14875
|
-
// here would not
|
|
14972
|
+
// here would not distinguish initial hydration from later provider children.
|
|
14876
14973
|
function useLegacyIsHydrated() {
|
|
14974
|
+
var _ssrContext_hydrationCompleteRef;
|
|
14877
14975
|
var serverContext = useInstantSearchServerContext();
|
|
14878
14976
|
var ssrContext = useInstantSearchSSRContext();
|
|
14879
14977
|
var isServerRendered = serverContext !== null || ssrContext !== null;
|
|
14880
|
-
var
|
|
14978
|
+
var isProviderHydrated = (ssrContext === null || ssrContext === void 0 ? void 0 : (_ssrContext_hydrationCompleteRef = ssrContext.hydrationCompleteRef) === null || _ssrContext_hydrationCompleteRef === void 0 ? void 0 : _ssrContext_hydrationCompleteRef.current) === true;
|
|
14979
|
+
var _React_useState = _sliced_to_array(React__namespace.useState(!isServerRendered || isProviderHydrated), 2), isHydrated = _React_useState[0], setIsHydrated = _React_useState[1];
|
|
14881
14980
|
React__namespace.useEffect(function() {
|
|
14882
14981
|
setIsHydrated(true);
|
|
14883
14982
|
}, []);
|
|
@@ -14912,6 +15011,7 @@
|
|
|
14912
15011
|
error: undefined,
|
|
14913
15012
|
id: 'id' in props && props.id || '',
|
|
14914
15013
|
messages: [],
|
|
15014
|
+
open: false,
|
|
14915
15015
|
status: 'ready',
|
|
14916
15016
|
suggestions: undefined
|
|
14917
15017
|
});
|
|
@@ -21391,7 +21491,7 @@
|
|
|
21391
21491
|
// Keep in sync with packages/instantsearch.js/src/lib/chat/index.ts
|
|
21392
21492
|
var SearchIndexToolType = 'algolia_search_index';
|
|
21393
21493
|
function createChatMessageComponent(param) {
|
|
21394
|
-
var createElement = param.createElement;
|
|
21494
|
+
var createElement = param.createElement, Fragment = param.Fragment;
|
|
21395
21495
|
var Button = createButtonComponent({
|
|
21396
21496
|
createElement: createElement
|
|
21397
21497
|
});
|
|
@@ -21400,7 +21500,7 @@
|
|
|
21400
21500
|
});
|
|
21401
21501
|
return function ChatMessage(userProps) {
|
|
21402
21502
|
var _messages_;
|
|
21403
|
-
var _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, message = userProps.message, status = userProps.status, _userProps_side = userProps.side, side = _userProps_side === void 0 ? 'left' : _userProps_side, _userProps_variant = userProps.variant, variant = _userProps_variant === void 0 ? 'subtle' : _userProps_variant, _userProps_actions = userProps.actions, actions = _userProps_actions === void 0 ? [] : _userProps_actions, _userProps_autoHideActions = userProps.autoHideActions, autoHideActions = _userProps_autoHideActions === void 0 ? false : _userProps_autoHideActions, LeadingComponent = userProps.leadingComponent, ActionsComponent = userProps.actionsComponent, FooterComponent = userProps.footerComponent, _userProps_tools = userProps.tools, tools = _userProps_tools === void 0 ? {} : _userProps_tools, indexUiState = userProps.indexUiState, setIndexUiState = userProps.setIndexUiState, messages = userProps.messages, onClose = userProps.onClose, userTranslations = userProps.translations, suggestionsElement = userProps.suggestionsElement, _userProps_showReasoning = userProps.showReasoning, showReasoning = _userProps_showReasoning === void 0 ? false : _userProps_showReasoning, _userProps_parseMarkdown = userProps.parseMarkdown, parseMarkdown = _userProps_parseMarkdown === void 0 ? true : _userProps_parseMarkdown, props = _object_without_properties(userProps, [
|
|
21503
|
+
var _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, message = userProps.message, status = userProps.status, _userProps_side = userProps.side, side = _userProps_side === void 0 ? 'left' : _userProps_side, _userProps_variant = userProps.variant, variant = _userProps_variant === void 0 ? 'subtle' : _userProps_variant, _userProps_actions = userProps.actions, actions = _userProps_actions === void 0 ? [] : _userProps_actions, _userProps_autoHideActions = userProps.autoHideActions, autoHideActions = _userProps_autoHideActions === void 0 ? false : _userProps_autoHideActions, LeadingComponent = userProps.leadingComponent, ActionsComponent = userProps.actionsComponent, FooterComponent = userProps.footerComponent, TextComponent = userProps.textComponent, _userProps_tools = userProps.tools, tools = _userProps_tools === void 0 ? {} : _userProps_tools, indexUiState = userProps.indexUiState, setIndexUiState = userProps.setIndexUiState, messages = userProps.messages, onClose = userProps.onClose, userTranslations = userProps.translations, suggestionsElement = userProps.suggestionsElement, _userProps_showReasoning = userProps.showReasoning, showReasoning = _userProps_showReasoning === void 0 ? false : _userProps_showReasoning, _userProps_parseMarkdown = userProps.parseMarkdown, parseMarkdown = _userProps_parseMarkdown === void 0 ? true : _userProps_parseMarkdown, props = _object_without_properties(userProps, [
|
|
21404
21504
|
"classNames",
|
|
21405
21505
|
"message",
|
|
21406
21506
|
"status",
|
|
@@ -21411,6 +21511,7 @@
|
|
|
21411
21511
|
"leadingComponent",
|
|
21412
21512
|
"actionsComponent",
|
|
21413
21513
|
"footerComponent",
|
|
21514
|
+
"textComponent",
|
|
21414
21515
|
"tools",
|
|
21415
21516
|
"indexUiState",
|
|
21416
21517
|
"setIndexUiState",
|
|
@@ -21476,6 +21577,17 @@
|
|
|
21476
21577
|
if (part.text.startsWith('<context>') && part.text.endsWith('</context>')) {
|
|
21477
21578
|
return null;
|
|
21478
21579
|
}
|
|
21580
|
+
if (TextComponent) {
|
|
21581
|
+
return /*#__PURE__*/ createElement(Fragment, {
|
|
21582
|
+
key: "".concat(message.id, "-").concat(index)
|
|
21583
|
+
}, /*#__PURE__*/ createElement(TextComponent, {
|
|
21584
|
+
part: part,
|
|
21585
|
+
message: message,
|
|
21586
|
+
messages: messages,
|
|
21587
|
+
status: status,
|
|
21588
|
+
partIndex: index
|
|
21589
|
+
}));
|
|
21590
|
+
}
|
|
21479
21591
|
if (!parseMarkdown) {
|
|
21480
21592
|
// Render the literal text. The `ais-ChatMessage-text` class applies
|
|
21481
21593
|
// `white-space: pre-wrap` to preserve the newlines that markdown
|
|
@@ -21805,15 +21917,13 @@
|
|
|
21805
21917
|
}
|
|
21806
21918
|
var messageProps = message.role === 'user' ? userMessageProps : assistantMessageProps;
|
|
21807
21919
|
var defaultActions = message.role === 'user' ? undefined : defaultAssistantActions;
|
|
21808
|
-
return /*#__PURE__*/ createElement(ChatMessage, _object_spread({
|
|
21920
|
+
return /*#__PURE__*/ createElement(ChatMessage, _object_spread_props(_object_spread({
|
|
21809
21921
|
side: message.role === 'user' ? 'right' : 'left',
|
|
21810
21922
|
variant: message.role === 'user' ? 'neutral' : 'subtle',
|
|
21811
|
-
message: message,
|
|
21812
21923
|
status: status,
|
|
21813
21924
|
tools: tools,
|
|
21814
21925
|
indexUiState: indexUiState,
|
|
21815
21926
|
setIndexUiState: setIndexUiState,
|
|
21816
|
-
messages: messages,
|
|
21817
21927
|
onClose: onClose,
|
|
21818
21928
|
actions: defaultActions,
|
|
21819
21929
|
actionsComponent: actionsComponent,
|
|
@@ -21821,7 +21931,10 @@
|
|
|
21821
21931
|
classNames: classNames,
|
|
21822
21932
|
translations: messageTranslations,
|
|
21823
21933
|
suggestionsElement: suggestionsElement
|
|
21824
|
-
}, messageProps)
|
|
21934
|
+
}, messageProps), {
|
|
21935
|
+
message: message,
|
|
21936
|
+
messages: messages
|
|
21937
|
+
}));
|
|
21825
21938
|
};
|
|
21826
21939
|
}
|
|
21827
21940
|
function createChatMessagesComponent(param) {
|
|
@@ -21848,6 +21961,10 @@
|
|
|
21848
21961
|
var messageProps = props.message.role === 'user' ? props.userMessageProps : props.assistantMessageProps;
|
|
21849
21962
|
var showReasoning = messageProps === null || messageProps === void 0 ? void 0 : messageProps.showReasoning;
|
|
21850
21963
|
var parseMarkdown = messageProps === null || messageProps === void 0 ? void 0 : messageProps.parseMarkdown;
|
|
21964
|
+
var textComponent = messageProps === null || messageProps === void 0 ? void 0 : messageProps.textComponent;
|
|
21965
|
+
// Custom text components receive the conversation, so their completed rows
|
|
21966
|
+
// must update with it. Keep the default renderer's streaming optimization.
|
|
21967
|
+
var textComponentMessages = textComponent ? props.messages : undefined;
|
|
21851
21968
|
// Object-level fallback, matching the render: the spread replaces
|
|
21852
21969
|
// `translations` wholesale, and it copies a key holding `undefined` too. Both
|
|
21853
21970
|
// are why this resolves by own-key presence rather than key by key.
|
|
@@ -21874,6 +21991,8 @@
|
|
|
21874
21991
|
messageFeedback,
|
|
21875
21992
|
showReasoning,
|
|
21876
21993
|
parseMarkdown,
|
|
21994
|
+
textComponent,
|
|
21995
|
+
textComponentMessages,
|
|
21877
21996
|
reasoningLabel,
|
|
21878
21997
|
reasoningClassName,
|
|
21879
21998
|
reasoningHeaderClassName,
|
|
@@ -25244,6 +25363,7 @@
|
|
|
25244
25363
|
"disableTriggerValidation",
|
|
25245
25364
|
"showReasoning"
|
|
25246
25365
|
]), _rest1 = _sliced_to_array(_rest, 1), ref = _rest1[0];
|
|
25366
|
+
var _ref3;
|
|
25247
25367
|
var promptTranslations = translations.prompt, headerTranslations = translations.header, messageTranslations = translations.message, messagesTranslations = translations.messages;
|
|
25248
25368
|
var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, setIndexUiState = _useInstantSearch.setIndexUiState;
|
|
25249
25369
|
var _useState = _sliced_to_array(React.useState(false), 2), maximized = _useState[0], setMaximized = _useState[1];
|
|
@@ -25269,7 +25389,7 @@
|
|
|
25269
25389
|
tools: tools,
|
|
25270
25390
|
disableTriggerValidation: effectiveDisableTriggerValidation
|
|
25271
25391
|
}));
|
|
25272
|
-
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, onFeedback = chatState.sendChatMessageFeedback, feedbackState = chatState.feedbackState;
|
|
25392
|
+
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, onFeedback = chatState.sendChatMessageFeedback, feedbackState = chatState.feedbackState, consumeInputFocus = chatState['~consumeInputFocus'], isOpenStatePersistenceEnabled = chatState['~isOpenStatePersistenceEnabled'];
|
|
25273
25393
|
React.useImperativeHandle(ref, function() {
|
|
25274
25394
|
return {
|
|
25275
25395
|
setOpen: setOpen,
|
|
@@ -25279,19 +25399,14 @@
|
|
|
25279
25399
|
setInput: setInput
|
|
25280
25400
|
};
|
|
25281
25401
|
});
|
|
25282
|
-
var wasOpenRef = React.useRef(false);
|
|
25283
25402
|
React.useEffect(function() {
|
|
25284
|
-
|
|
25285
|
-
if (shouldFocusPrompt) {
|
|
25403
|
+
if (consumeInputFocus === null || consumeInputFocus === void 0 ? void 0 : consumeInputFocus()) {
|
|
25286
25404
|
window.requestAnimationFrame(function() {
|
|
25287
25405
|
var _promptRef_current;
|
|
25288
25406
|
(_promptRef_current = promptRef.current) === null || _promptRef_current === void 0 ? void 0 : _promptRef_current.focus();
|
|
25289
25407
|
});
|
|
25290
25408
|
}
|
|
25291
|
-
|
|
25292
|
-
}, [
|
|
25293
|
-
open
|
|
25294
|
-
]);
|
|
25409
|
+
});
|
|
25295
25410
|
// Keep the conversation pinned to the bottom while streaming. The stick-to-
|
|
25296
25411
|
// bottom ResizeObserver only reacts to content *height* changes, but tool
|
|
25297
25412
|
// results such as a horizontally-growing carousel stream in without changing
|
|
@@ -25312,7 +25427,7 @@
|
|
|
25312
25427
|
if (error) {
|
|
25313
25428
|
throw error;
|
|
25314
25429
|
}
|
|
25315
|
-
var
|
|
25430
|
+
var _ref4 = messagesProps !== null && messagesProps !== void 0 ? messagesProps : {}, callerAssistantMessageProps = _ref4.assistantMessageProps, callerUserMessageProps = _ref4.userMessageProps, restMessagesProps = _object_without_properties(_ref4, [
|
|
25316
25431
|
"assistantMessageProps",
|
|
25317
25432
|
"userMessageProps"
|
|
25318
25433
|
]);
|
|
@@ -25385,7 +25500,7 @@
|
|
|
25385
25500
|
}, callerUserMessageProps),
|
|
25386
25501
|
error: error
|
|
25387
25502
|
}),
|
|
25388
|
-
promptProps: _object_spread({
|
|
25503
|
+
promptProps: _object_spread_props(_object_spread({
|
|
25389
25504
|
promptRef: promptRef,
|
|
25390
25505
|
status: status,
|
|
25391
25506
|
value: input,
|
|
@@ -25404,7 +25519,9 @@
|
|
|
25404
25519
|
},
|
|
25405
25520
|
headerComponent: promptHeaderComponent,
|
|
25406
25521
|
footerComponent: promptFooterComponent
|
|
25407
|
-
}, promptProps),
|
|
25522
|
+
}, promptProps), {
|
|
25523
|
+
autoFocus: (_ref3 = promptProps === null || promptProps === void 0 ? void 0 : promptProps.autoFocus) !== null && _ref3 !== void 0 ? _ref3 : !isOpenStatePersistenceEnabled || isInlineLayoutComponent
|
|
25524
|
+
}),
|
|
25408
25525
|
suggestionsProps: {
|
|
25409
25526
|
suggestions: suggestions,
|
|
25410
25527
|
onSuggestionClick: function onSuggestionClick(suggestion) {
|