react-instantsearch 7.44.1 → 7.46.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 +95 -10
- package/dist/cjs/widgets/PromptSuggestions.js +7 -3
- package/dist/cjs/widgets/chat/tools/DisplayResultsTool.js +0 -1
- package/dist/es/components/ChatGreeting.d.ts +1 -1
- package/dist/es/components/ChatMessageLoader.d.ts +1 -1
- package/dist/es/widgets/Chat.d.ts +21 -0
- package/dist/es/widgets/Chat.js +112 -27
- package/dist/es/widgets/PromptSuggestions.js +7 -3
- package/dist/es/widgets/chat/tools/DisplayResultsTool.js +1 -2
- package/dist/umd/ReactInstantSearch.js +12304 -11281
- package/dist/umd/ReactInstantSearch.min.js +3 -3
- package/package.json +5 -5
package/dist/cjs/widgets/Chat.js
CHANGED
|
@@ -35,7 +35,11 @@ _export(exports, {
|
|
|
35
35
|
return createDefaultTools;
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
+
var _call_super = require("@swc/helpers/_/_call_super");
|
|
39
|
+
var _class_call_check = require("@swc/helpers/_/_class_call_check");
|
|
40
|
+
var _create_class = require("@swc/helpers/_/_create_class");
|
|
38
41
|
var _define_property = require("@swc/helpers/_/_define_property");
|
|
42
|
+
var _inherits = require("@swc/helpers/_/_inherits");
|
|
39
43
|
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
40
44
|
var _object_spread = require("@swc/helpers/_/_object_spread");
|
|
41
45
|
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
|
|
@@ -44,6 +48,7 @@ var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
|
|
|
44
48
|
var _to_array = require("@swc/helpers/_/_to_array");
|
|
45
49
|
var _instantsearchuicomponents = require("instantsearch-ui-components");
|
|
46
50
|
var _chat = require("instantsearch.js/cjs/lib/chat");
|
|
51
|
+
var _focusAfterReveal = require("instantsearch.js/cjs/lib/chat/focusAfterReveal");
|
|
47
52
|
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
48
53
|
var _reactinstantsearchcore = require("react-instantsearch-core");
|
|
49
54
|
var _useStickToBottom = require("../lib/useStickToBottom");
|
|
@@ -53,11 +58,24 @@ var ChatUiComponent = (0, _instantsearchuicomponents.createChatComponent)({
|
|
|
53
58
|
createElement: _react.createElement,
|
|
54
59
|
Fragment: _react.Fragment,
|
|
55
60
|
useMemo: _react.useMemo,
|
|
56
|
-
useState: _react.useState
|
|
61
|
+
useState: _react.useState,
|
|
62
|
+
useEffect: _react.useEffect
|
|
57
63
|
});
|
|
58
64
|
function createDefaultTools(itemComponent, getSearchPageURL) {
|
|
59
65
|
var _obj;
|
|
60
|
-
return _obj = {}, _define_property._(_obj, _chat.SearchIndexToolType,
|
|
66
|
+
return _obj = {}, _define_property._(_obj, _chat.SearchIndexToolType, _object_spread_props._(_object_spread._({}, (0, _SearchIndexTool.createCarouselTool)(true, itemComponent, getSearchPageURL)), {
|
|
67
|
+
// The agent decides per turn whether the richer display-results tool
|
|
68
|
+
// takes over the rendering of the search results.
|
|
69
|
+
shouldRender: isDisplayResultsDisabled
|
|
70
|
+
})), _define_property._(_obj, _chat.RecommendToolType, (0, _SearchIndexTool.createCarouselTool)(false, itemComponent, getSearchPageURL)), _define_property._(_obj, _chat.DisplayResultsToolType, (0, _DisplayResultsTool.createDisplayResultsTool)(itemComponent)), _define_property._(_obj, _chat.MemorizeToolType, {}), _define_property._(_obj, _chat.MemorySearchToolType, {}), _define_property._(_obj, _chat.PonderToolType, {}), _obj;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Whether the search tool renders its own results, i.e. the agent did not hand
|
|
74
|
+
* the turn to the display-results tool. Set on the message by the backend.
|
|
75
|
+
*/ function isDisplayResultsDisabled(param) {
|
|
76
|
+
var parentMessage = param.parentMessage;
|
|
77
|
+
var _parentMessage_metadata;
|
|
78
|
+
return ((_parentMessage_metadata = parentMessage.metadata) === null || _parentMessage_metadata === void 0 ? void 0 : _parentMessage_metadata.displayResultsEnabled) !== true;
|
|
61
79
|
}
|
|
62
80
|
function mergeToolOptions(defaultTools, userTools) {
|
|
63
81
|
if (!userTools) {
|
|
@@ -65,22 +83,62 @@ function mergeToolOptions(defaultTools, userTools) {
|
|
|
65
83
|
}
|
|
66
84
|
var tools = _object_spread._({}, defaultTools, userTools);
|
|
67
85
|
Object.keys(userTools).forEach(function(toolName) {
|
|
68
|
-
var _defaultTools_toolName;
|
|
69
86
|
var userTool = userTools[toolName];
|
|
70
|
-
var
|
|
87
|
+
var defaultTool = defaultTools[toolName];
|
|
88
|
+
var defaultStreamInput = defaultTool === null || defaultTool === void 0 ? void 0 : defaultTool.streamInput;
|
|
71
89
|
if (userTool.layoutComponent !== undefined && userTool.streamInput === undefined && defaultStreamInput !== undefined) {
|
|
72
|
-
tools[toolName] = _object_spread_props._(_object_spread._({},
|
|
90
|
+
tools[toolName] = _object_spread_props._(_object_spread._({}, tools[toolName]), {
|
|
73
91
|
streamInput: defaultStreamInput
|
|
74
92
|
});
|
|
75
93
|
}
|
|
94
|
+
// Overriding a tool's rendering shouldn't opt it out of the conditions
|
|
95
|
+
// under which the default renders at all.
|
|
96
|
+
if (userTool.shouldRender === undefined && (defaultTool === null || defaultTool === void 0 ? void 0 : defaultTool.shouldRender)) {
|
|
97
|
+
tools[toolName] = _object_spread_props._(_object_spread._({}, tools[toolName]), {
|
|
98
|
+
shouldRender: defaultTool.shouldRender
|
|
99
|
+
});
|
|
100
|
+
}
|
|
76
101
|
});
|
|
77
102
|
return tools;
|
|
78
103
|
}
|
|
104
|
+
var AnimationSnapshot = /*#__PURE__*/ function(_React_Component) {
|
|
105
|
+
_inherits._(AnimationSnapshot, _React_Component);
|
|
106
|
+
function AnimationSnapshot() {
|
|
107
|
+
_class_call_check._(this, AnimationSnapshot);
|
|
108
|
+
return _call_super._(this, AnimationSnapshot, arguments);
|
|
109
|
+
}
|
|
110
|
+
_create_class._(AnimationSnapshot, [
|
|
111
|
+
{
|
|
112
|
+
key: "getSnapshotBeforeUpdate",
|
|
113
|
+
value: function getSnapshotBeforeUpdate() {
|
|
114
|
+
return (0, _focusAfterReveal.getActiveContainerAnimations)(this.props.promptRef.current);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
key: "componentDidUpdate",
|
|
119
|
+
value: function componentDidUpdate(_previousProps, _previousState, animationsBeforeReveal) {
|
|
120
|
+
this.props.animationsBeforeReveal.current = animationsBeforeReveal;
|
|
121
|
+
if (!_previousProps.open && this.props.open) {
|
|
122
|
+
(0, _focusAfterReveal.holdContainerInertUntilReveal)(this.props.promptRef.current);
|
|
123
|
+
} else if (this.props.open) {
|
|
124
|
+
(0, _focusAfterReveal.restoreContainerInertUntilReveal)(this.props.promptRef.current);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
key: "render",
|
|
130
|
+
value: function render() {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
]);
|
|
135
|
+
return AnimationSnapshot;
|
|
136
|
+
}(_react.default.Component);
|
|
79
137
|
function ChatInner(_0, _1) {
|
|
80
138
|
var _ref = [
|
|
81
139
|
_0,
|
|
82
140
|
_1
|
|
83
|
-
], _ref1 = _to_array._(_ref), _ref2 = _ref1[0], _rest = _ref1.slice(1), userTools = _ref2.tools, headerProps = _ref2.headerProps, messagesProps = _ref2.messagesProps, promptProps = _ref2.promptProps, itemComponent = _ref2.itemComponent, layoutComponent = _ref2.layoutComponent, headerComponent = _ref2.headerComponent, headerTitleIconComponent = _ref2.headerTitleIconComponent, headerCloseIconComponent = _ref2.headerCloseIconComponent, headerMinimizeIconComponent = _ref2.headerMinimizeIconComponent, headerMaximizeIconComponent = _ref2.headerMaximizeIconComponent, loaderComponent = _ref2.loaderComponent, messagesErrorComponent = _ref2.messagesErrorComponent, promptComponent = _ref2.promptComponent, promptHeaderComponent = _ref2.promptHeaderComponent, promptFooterComponent = _ref2.promptFooterComponent, assistantMessageLeadingComponent = _ref2.assistantMessageLeadingComponent, assistantMessageFooterComponent = _ref2.assistantMessageFooterComponent, userMessageLeadingComponent = _ref2.userMessageLeadingComponent, userMessageFooterComponent = _ref2.userMessageFooterComponent, emptyComponent = _ref2.emptyComponent, actionsComponent = _ref2.actionsComponent, suggestionsComponent = _ref2.suggestionsComponent, classNames = _ref2.classNames, _ref_translations = _ref2.translations, translations = _ref_translations === void 0 ? {} : _ref_translations, title = _ref2.title, getSearchPageURL = _ref2.getSearchPageURL, _ref_disableTriggerValidation = _ref2.disableTriggerValidation, disableTriggerValidation = _ref_disableTriggerValidation === void 0 ? false : _ref_disableTriggerValidation, showReasoning = _ref2.showReasoning, props = _object_without_properties._(_ref2, [
|
|
141
|
+
], _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, [
|
|
84
142
|
"tools",
|
|
85
143
|
"headerProps",
|
|
86
144
|
"messagesProps",
|
|
@@ -93,6 +151,10 @@ function ChatInner(_0, _1) {
|
|
|
93
151
|
"headerMinimizeIconComponent",
|
|
94
152
|
"headerMaximizeIconComponent",
|
|
95
153
|
"loaderComponent",
|
|
154
|
+
"loaderPosition",
|
|
155
|
+
"shouldShowLoader",
|
|
156
|
+
"loaderShowDelay",
|
|
157
|
+
"loaderMinDuration",
|
|
96
158
|
"messagesErrorComponent",
|
|
97
159
|
"promptComponent",
|
|
98
160
|
"promptHeaderComponent",
|
|
@@ -116,6 +178,8 @@ function ChatInner(_0, _1) {
|
|
|
116
178
|
var _useInstantSearch = (0, _reactinstantsearchcore.useInstantSearch)(), indexUiState = _useInstantSearch.indexUiState, setIndexUiState = _useInstantSearch.setIndexUiState;
|
|
117
179
|
var _useState = _sliced_to_array._((0, _react.useState)(false), 2), maximized = _useState[0], setMaximized = _useState[1];
|
|
118
180
|
var promptRef = (0, _react.useRef)(null);
|
|
181
|
+
var focusRequestId = (0, _react.useRef)(0);
|
|
182
|
+
var animationsBeforeReveal = (0, _react.useRef)([]);
|
|
119
183
|
var _useStickToBottom1 = (0, _useStickToBottom.useStickToBottom)({
|
|
120
184
|
initial: 'smooth',
|
|
121
185
|
resize: 'smooth'
|
|
@@ -137,7 +201,7 @@ function ChatInner(_0, _1) {
|
|
|
137
201
|
tools: tools,
|
|
138
202
|
disableTriggerValidation: effectiveDisableTriggerValidation
|
|
139
203
|
}));
|
|
140
|
-
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'];
|
|
204
|
+
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'];
|
|
141
205
|
(0, _react.useImperativeHandle)(ref, function() {
|
|
142
206
|
return {
|
|
143
207
|
setOpen: setOpen,
|
|
@@ -148,10 +212,21 @@ function ChatInner(_0, _1) {
|
|
|
148
212
|
};
|
|
149
213
|
});
|
|
150
214
|
(0, _react.useEffect)(function() {
|
|
215
|
+
if (!open) {
|
|
216
|
+
focusRequestId.current++;
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
151
219
|
if (consumeInputFocus === null || consumeInputFocus === void 0 ? void 0 : consumeInputFocus()) {
|
|
220
|
+
var currentFocusRequestId = ++focusRequestId.current;
|
|
221
|
+
var previousAnimations = animationsBeforeReveal.current;
|
|
222
|
+
(0, _focusAfterReveal.holdContainerInertUntilReveal)(promptRef.current);
|
|
152
223
|
window.requestAnimationFrame(function() {
|
|
153
|
-
var
|
|
154
|
-
(
|
|
224
|
+
var prompt = promptRef.current;
|
|
225
|
+
(0, _focusAfterReveal.focusAfterReveal)(prompt, previousAnimations, function() {
|
|
226
|
+
return focusRequestId.current === currentFocusRequestId && promptRef.current === prompt;
|
|
227
|
+
}, function() {
|
|
228
|
+
return focusRequestId.current === currentFocusRequestId;
|
|
229
|
+
});
|
|
155
230
|
});
|
|
156
231
|
}
|
|
157
232
|
});
|
|
@@ -176,7 +251,7 @@ function ChatInner(_0, _1) {
|
|
|
176
251
|
"assistantMessageProps",
|
|
177
252
|
"userMessageProps"
|
|
178
253
|
]);
|
|
179
|
-
|
|
254
|
+
var chat = /*#__PURE__*/ _react.default.createElement(ChatUiComponent, {
|
|
180
255
|
title: title,
|
|
181
256
|
open: open,
|
|
182
257
|
maximized: maximized,
|
|
@@ -228,6 +303,10 @@ function ChatInner(_0, _1) {
|
|
|
228
303
|
contentRef: contentRef,
|
|
229
304
|
onScrollToBottom: scrollToBottom,
|
|
230
305
|
loaderComponent: loaderComponent,
|
|
306
|
+
loaderPosition: loaderPosition,
|
|
307
|
+
shouldShowLoader: shouldShowLoader,
|
|
308
|
+
loaderShowDelay: loaderShowDelay,
|
|
309
|
+
loaderMinDuration: loaderMinDuration,
|
|
231
310
|
errorComponent: messagesErrorComponent,
|
|
232
311
|
emptyComponent: emptyComponent,
|
|
233
312
|
actionsComponent: actionsComponent,
|
|
@@ -269,6 +348,7 @@ function ChatInner(_0, _1) {
|
|
|
269
348
|
}),
|
|
270
349
|
suggestionsProps: {
|
|
271
350
|
suggestions: suggestions,
|
|
351
|
+
isLoading: suggestionsStatus === 'loading',
|
|
272
352
|
onSuggestionClick: function onSuggestionClick(suggestion) {
|
|
273
353
|
sendMessage({
|
|
274
354
|
text: suggestion
|
|
@@ -277,5 +357,10 @@ function ChatInner(_0, _1) {
|
|
|
277
357
|
},
|
|
278
358
|
classNames: classNames
|
|
279
359
|
});
|
|
360
|
+
return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement(AnimationSnapshot, {
|
|
361
|
+
promptRef: promptRef,
|
|
362
|
+
animationsBeforeReveal: animationsBeforeReveal,
|
|
363
|
+
open: open
|
|
364
|
+
}), chat);
|
|
280
365
|
}
|
|
281
366
|
var Chat = /*#__PURE__*/ _react.default.forwardRef(ChatInner);
|
|
@@ -33,14 +33,18 @@ function PromptSuggestions(_0) {
|
|
|
33
33
|
"context",
|
|
34
34
|
"transformItems"
|
|
35
35
|
]);
|
|
36
|
-
var
|
|
36
|
+
var source = agentId !== undefined ? {
|
|
37
37
|
agentId: agentId,
|
|
38
|
-
transport: transport
|
|
38
|
+
transport: transport
|
|
39
|
+
} : {
|
|
40
|
+
transport: transport
|
|
41
|
+
};
|
|
42
|
+
var _usePromptSuggestions = (0, _reactinstantsearchcore.usePromptSuggestions)(_object_spread_props._(_object_spread._({}, source), {
|
|
39
43
|
configurationId: configurationId,
|
|
40
44
|
transformHits: transformHits,
|
|
41
45
|
context: context,
|
|
42
46
|
transformItems: transformItems
|
|
43
|
-
}, {
|
|
47
|
+
}), {
|
|
44
48
|
$$widgetType: 'ais.promptSuggestions'
|
|
45
49
|
}), suggestions = _usePromptSuggestions.suggestions, isLoading = _usePromptSuggestions.isLoading, onSuggestionClick = _usePromptSuggestions.onSuggestionClick, isChatBusy = _usePromptSuggestions.isChatBusy, sendToChat = _usePromptSuggestions.sendToChat;
|
|
46
50
|
var handleClick = onSuggestionClickOverride ? function(prompt) {
|
|
@@ -18,7 +18,6 @@ function createDisplayResultsTool(itemComponent) {
|
|
|
18
18
|
createElement: _react.createElement,
|
|
19
19
|
Fragment: _react.Fragment,
|
|
20
20
|
useEffect: _react.useEffect,
|
|
21
|
-
useMemo: _react.useMemo,
|
|
22
21
|
useRef: _react.useRef
|
|
23
22
|
});
|
|
24
23
|
var Button = (0, _instantsearchuicomponents.createButtonComponent)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ChatGreeting: (userProps: import("instantsearch-ui-components").ChatGreetingProps) => JSX.Element;
|
|
1
|
+
export declare const ChatGreeting: (userProps: import("instantsearch-ui-components").ChatComponentPropsWithContext<import("instantsearch-ui-components").ChatGreetingProps & import("instantsearch-ui-components").ChatEmptyProps>) => JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ChatMessageLoader: (userProps: import("instantsearch-ui-components").
|
|
1
|
+
export declare const ChatMessageLoader: <TMessage extends import("instantsearch-ui-components").ChatMessageBase = import("instantsearch-ui-components").ChatMessageBase>(userProps: import("instantsearch-ui-components").ChatMessageLoaderPropsWithContext<TMessage>) => JSX.Element;
|
|
@@ -31,6 +31,27 @@ export type ChatProps<TObject, TUiMessage extends UIMessage = UIMessage> = Omit<
|
|
|
31
31
|
promptHeaderComponent?: ChatUiProps['promptProps']['headerComponent'];
|
|
32
32
|
promptFooterComponent?: ChatUiProps['promptProps']['footerComponent'];
|
|
33
33
|
loaderComponent?: ChatUiProps['messagesProps']['loaderComponent'];
|
|
34
|
+
/**
|
|
35
|
+
* Where the loader renders: as its own row after the last message
|
|
36
|
+
* (`messages-end`, the default) or inside the streaming assistant message
|
|
37
|
+
* (`message-inline`).
|
|
38
|
+
*/
|
|
39
|
+
loaderPosition?: ChatUiProps['messagesProps']['loaderPosition'];
|
|
40
|
+
/**
|
|
41
|
+
* Overrides when the loader shows. Receives the turn context plus the
|
|
42
|
+
* built-in decision as `defaultValue`.
|
|
43
|
+
*/
|
|
44
|
+
shouldShowLoader?: ChatUiProps['messagesProps']['shouldShowLoader'];
|
|
45
|
+
/**
|
|
46
|
+
* How long (ms) a renewed loading state must hold before the loader comes
|
|
47
|
+
* back after having been hidden in the same turn.
|
|
48
|
+
*/
|
|
49
|
+
loaderShowDelay?: ChatUiProps['messagesProps']['loaderShowDelay'];
|
|
50
|
+
/**
|
|
51
|
+
* Minimum time (ms) the loader stays on screen once shown, while the turn is
|
|
52
|
+
* still running.
|
|
53
|
+
*/
|
|
54
|
+
loaderMinDuration?: ChatUiProps['messagesProps']['loaderMinDuration'];
|
|
34
55
|
emptyComponent?: ChatUiProps['messagesProps']['emptyComponent'];
|
|
35
56
|
actionsComponent?: ChatUiProps['messagesProps']['actionsComponent'];
|
|
36
57
|
assistantMessageLeadingComponent?: ChatMessageProps['leadingComponent'];
|
package/dist/es/widgets/Chat.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { _ } from '@swc/helpers/esm/
|
|
2
|
-
import { _ as _$
|
|
3
|
-
import { _ as _$
|
|
4
|
-
import { _ as _$
|
|
5
|
-
import { _
|
|
6
|
-
import { _ as _$
|
|
1
|
+
import { _ as _$2 } from '@swc/helpers/esm/_call_super.js';
|
|
2
|
+
import { _ as _$1 } from '@swc/helpers/esm/_class_call_check.js';
|
|
3
|
+
import { _ as _$3 } from '@swc/helpers/esm/_create_class.js';
|
|
4
|
+
import { _ as _$4 } from '@swc/helpers/esm/_define_property.js';
|
|
5
|
+
import { _ } from '@swc/helpers/esm/_inherits.js';
|
|
6
|
+
import { _ as _$6 } from '@swc/helpers/esm/_object_spread.js';
|
|
7
|
+
import { _ as _$5 } from '@swc/helpers/esm/_object_spread_props.js';
|
|
8
|
+
import { _ as _$8 } from '@swc/helpers/esm/_object_without_properties.js';
|
|
9
|
+
import { _ as _$9 } from '@swc/helpers/esm/_sliced_to_array.js';
|
|
10
|
+
import { _ as _$7 } from '@swc/helpers/esm/_to_array.js';
|
|
7
11
|
import { createChatComponent } from 'instantsearch-ui-components';
|
|
8
12
|
import { SearchIndexToolType, RecommendToolType, DisplayResultsToolType, MemorizeToolType, MemorySearchToolType, PonderToolType } from 'instantsearch.js/es/lib/chat/index.js';
|
|
9
13
|
export { DisplayResultsToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, RecommendToolType, SearchIndexToolType } from 'instantsearch.js/es/lib/chat/index.js';
|
|
10
|
-
import
|
|
14
|
+
import { getActiveContainerAnimations, holdContainerInertUntilReveal, restoreContainerInertUntilReveal, focusAfterReveal } from 'instantsearch.js/es/lib/chat/focusAfterReveal.js';
|
|
15
|
+
import React, { createElement, Fragment, useMemo, useState, useEffect, useRef, useImperativeHandle } from 'react';
|
|
11
16
|
import { useInstantSearch, useChat } from 'react-instantsearch-core';
|
|
12
17
|
import { useStickToBottom } from '../lib/useStickToBottom.js';
|
|
13
18
|
import { createDisplayResultsTool } from './chat/tools/DisplayResultsTool.js';
|
|
@@ -17,34 +22,87 @@ var ChatUiComponent = createChatComponent({
|
|
|
17
22
|
createElement: createElement,
|
|
18
23
|
Fragment: Fragment,
|
|
19
24
|
useMemo: useMemo,
|
|
20
|
-
useState: useState
|
|
25
|
+
useState: useState,
|
|
26
|
+
useEffect: useEffect
|
|
21
27
|
});
|
|
22
28
|
function createDefaultTools(itemComponent, getSearchPageURL) {
|
|
23
29
|
var _obj;
|
|
24
|
-
return _obj = {}, _(_obj, SearchIndexToolType,
|
|
30
|
+
return _obj = {}, _$4(_obj, SearchIndexToolType, _$5(_$6({}, createCarouselTool(true, itemComponent, getSearchPageURL)), {
|
|
31
|
+
// The agent decides per turn whether the richer display-results tool
|
|
32
|
+
// takes over the rendering of the search results.
|
|
33
|
+
shouldRender: isDisplayResultsDisabled
|
|
34
|
+
})), _$4(_obj, RecommendToolType, createCarouselTool(false, itemComponent, getSearchPageURL)), _$4(_obj, DisplayResultsToolType, createDisplayResultsTool(itemComponent)), _$4(_obj, MemorizeToolType, {}), _$4(_obj, MemorySearchToolType, {}), _$4(_obj, PonderToolType, {}), _obj;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Whether the search tool renders its own results, i.e. the agent did not hand
|
|
38
|
+
* the turn to the display-results tool. Set on the message by the backend.
|
|
39
|
+
*/ function isDisplayResultsDisabled(param) {
|
|
40
|
+
var parentMessage = param.parentMessage;
|
|
41
|
+
var _parentMessage_metadata;
|
|
42
|
+
return ((_parentMessage_metadata = parentMessage.metadata) === null || _parentMessage_metadata === void 0 ? void 0 : _parentMessage_metadata.displayResultsEnabled) !== true;
|
|
25
43
|
}
|
|
26
44
|
function mergeToolOptions(defaultTools, userTools) {
|
|
27
45
|
if (!userTools) {
|
|
28
46
|
return defaultTools;
|
|
29
47
|
}
|
|
30
|
-
var tools = _$
|
|
48
|
+
var tools = _$6({}, defaultTools, userTools);
|
|
31
49
|
Object.keys(userTools).forEach(function(toolName) {
|
|
32
|
-
var _defaultTools_toolName;
|
|
33
50
|
var userTool = userTools[toolName];
|
|
34
|
-
var
|
|
51
|
+
var defaultTool = defaultTools[toolName];
|
|
52
|
+
var defaultStreamInput = defaultTool === null || defaultTool === void 0 ? void 0 : defaultTool.streamInput;
|
|
35
53
|
if (userTool.layoutComponent !== undefined && userTool.streamInput === undefined && defaultStreamInput !== undefined) {
|
|
36
|
-
tools[toolName] = _$
|
|
54
|
+
tools[toolName] = _$5(_$6({}, tools[toolName]), {
|
|
37
55
|
streamInput: defaultStreamInput
|
|
38
56
|
});
|
|
39
57
|
}
|
|
58
|
+
// Overriding a tool's rendering shouldn't opt it out of the conditions
|
|
59
|
+
// under which the default renders at all.
|
|
60
|
+
if (userTool.shouldRender === undefined && (defaultTool === null || defaultTool === void 0 ? void 0 : defaultTool.shouldRender)) {
|
|
61
|
+
tools[toolName] = _$5(_$6({}, tools[toolName]), {
|
|
62
|
+
shouldRender: defaultTool.shouldRender
|
|
63
|
+
});
|
|
64
|
+
}
|
|
40
65
|
});
|
|
41
66
|
return tools;
|
|
42
67
|
}
|
|
68
|
+
var AnimationSnapshot = /*#__PURE__*/ function(_React_Component) {
|
|
69
|
+
_(AnimationSnapshot, _React_Component);
|
|
70
|
+
function AnimationSnapshot() {
|
|
71
|
+
_$1(this, AnimationSnapshot);
|
|
72
|
+
return _$2(this, AnimationSnapshot, arguments);
|
|
73
|
+
}
|
|
74
|
+
_$3(AnimationSnapshot, [
|
|
75
|
+
{
|
|
76
|
+
key: "getSnapshotBeforeUpdate",
|
|
77
|
+
value: function getSnapshotBeforeUpdate() {
|
|
78
|
+
return getActiveContainerAnimations(this.props.promptRef.current);
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
key: "componentDidUpdate",
|
|
83
|
+
value: function componentDidUpdate(_previousProps, _previousState, animationsBeforeReveal) {
|
|
84
|
+
this.props.animationsBeforeReveal.current = animationsBeforeReveal;
|
|
85
|
+
if (!_previousProps.open && this.props.open) {
|
|
86
|
+
holdContainerInertUntilReveal(this.props.promptRef.current);
|
|
87
|
+
} else if (this.props.open) {
|
|
88
|
+
restoreContainerInertUntilReveal(this.props.promptRef.current);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
key: "render",
|
|
94
|
+
value: function render() {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
]);
|
|
99
|
+
return AnimationSnapshot;
|
|
100
|
+
}(React.Component);
|
|
43
101
|
function ChatInner(_0, _1) {
|
|
44
102
|
var _ref = [
|
|
45
103
|
_0,
|
|
46
104
|
_1
|
|
47
|
-
], _ref1 = _$
|
|
105
|
+
], _ref1 = _$7(_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 = _$8(_ref2, [
|
|
48
106
|
"tools",
|
|
49
107
|
"headerProps",
|
|
50
108
|
"messagesProps",
|
|
@@ -57,6 +115,10 @@ function ChatInner(_0, _1) {
|
|
|
57
115
|
"headerMinimizeIconComponent",
|
|
58
116
|
"headerMaximizeIconComponent",
|
|
59
117
|
"loaderComponent",
|
|
118
|
+
"loaderPosition",
|
|
119
|
+
"shouldShowLoader",
|
|
120
|
+
"loaderShowDelay",
|
|
121
|
+
"loaderMinDuration",
|
|
60
122
|
"messagesErrorComponent",
|
|
61
123
|
"promptComponent",
|
|
62
124
|
"promptHeaderComponent",
|
|
@@ -74,12 +136,14 @@ function ChatInner(_0, _1) {
|
|
|
74
136
|
"getSearchPageURL",
|
|
75
137
|
"disableTriggerValidation",
|
|
76
138
|
"showReasoning"
|
|
77
|
-
]), _rest1 = _$
|
|
139
|
+
]), _rest1 = _$9(_rest, 1), ref = _rest1[0];
|
|
78
140
|
var _ref3;
|
|
79
141
|
var promptTranslations = translations.prompt, headerTranslations = translations.header, messageTranslations = translations.message, messagesTranslations = translations.messages;
|
|
80
142
|
var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, setIndexUiState = _useInstantSearch.setIndexUiState;
|
|
81
|
-
var _useState = _$
|
|
143
|
+
var _useState = _$9(useState(false), 2), maximized = _useState[0], setMaximized = _useState[1];
|
|
82
144
|
var promptRef = useRef(null);
|
|
145
|
+
var focusRequestId = useRef(0);
|
|
146
|
+
var animationsBeforeReveal = useRef([]);
|
|
83
147
|
var _useStickToBottom = useStickToBottom({
|
|
84
148
|
initial: 'smooth',
|
|
85
149
|
resize: 'smooth'
|
|
@@ -97,11 +161,11 @@ function ChatInner(_0, _1) {
|
|
|
97
161
|
// set on the layout component, which is consistent across flavors.
|
|
98
162
|
var isInlineLayoutComponent = typeof layoutComponent === 'function' && layoutComponent.$$inlineLayout === true;
|
|
99
163
|
var effectiveDisableTriggerValidation = disableTriggerValidation || isInlineLayoutComponent;
|
|
100
|
-
var chatState = useChat(_$
|
|
164
|
+
var chatState = useChat(_$5(_$6({}, props), {
|
|
101
165
|
tools: tools,
|
|
102
166
|
disableTriggerValidation: effectiveDisableTriggerValidation
|
|
103
167
|
}));
|
|
104
|
-
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'];
|
|
168
|
+
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'];
|
|
105
169
|
useImperativeHandle(ref, function() {
|
|
106
170
|
return {
|
|
107
171
|
setOpen: setOpen,
|
|
@@ -112,10 +176,21 @@ function ChatInner(_0, _1) {
|
|
|
112
176
|
};
|
|
113
177
|
});
|
|
114
178
|
useEffect(function() {
|
|
179
|
+
if (!open) {
|
|
180
|
+
focusRequestId.current++;
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
115
183
|
if (consumeInputFocus === null || consumeInputFocus === void 0 ? void 0 : consumeInputFocus()) {
|
|
184
|
+
var currentFocusRequestId = ++focusRequestId.current;
|
|
185
|
+
var previousAnimations = animationsBeforeReveal.current;
|
|
186
|
+
holdContainerInertUntilReveal(promptRef.current);
|
|
116
187
|
window.requestAnimationFrame(function() {
|
|
117
|
-
var
|
|
118
|
-
(
|
|
188
|
+
var prompt = promptRef.current;
|
|
189
|
+
focusAfterReveal(prompt, previousAnimations, function() {
|
|
190
|
+
return focusRequestId.current === currentFocusRequestId && promptRef.current === prompt;
|
|
191
|
+
}, function() {
|
|
192
|
+
return focusRequestId.current === currentFocusRequestId;
|
|
193
|
+
});
|
|
119
194
|
});
|
|
120
195
|
}
|
|
121
196
|
});
|
|
@@ -136,11 +211,11 @@ function ChatInner(_0, _1) {
|
|
|
136
211
|
status,
|
|
137
212
|
scrollToBottom
|
|
138
213
|
]);
|
|
139
|
-
var _ref4 = messagesProps !== null && messagesProps !== void 0 ? messagesProps : {}, callerAssistantMessageProps = _ref4.assistantMessageProps, callerUserMessageProps = _ref4.userMessageProps, restMessagesProps = _$
|
|
214
|
+
var _ref4 = messagesProps !== null && messagesProps !== void 0 ? messagesProps : {}, callerAssistantMessageProps = _ref4.assistantMessageProps, callerUserMessageProps = _ref4.userMessageProps, restMessagesProps = _$8(_ref4, [
|
|
140
215
|
"assistantMessageProps",
|
|
141
216
|
"userMessageProps"
|
|
142
217
|
]);
|
|
143
|
-
|
|
218
|
+
var chat = /*#__PURE__*/ React.createElement(ChatUiComponent, {
|
|
144
219
|
title: title,
|
|
145
220
|
open: open,
|
|
146
221
|
maximized: maximized,
|
|
@@ -152,7 +227,7 @@ function ChatInner(_0, _1) {
|
|
|
152
227
|
headerComponent: headerComponent,
|
|
153
228
|
promptComponent: promptComponent,
|
|
154
229
|
suggestionsComponent: suggestionsComponent,
|
|
155
|
-
headerProps: _$
|
|
230
|
+
headerProps: _$6({
|
|
156
231
|
onClose: function onClose() {
|
|
157
232
|
return setOpen(false);
|
|
158
233
|
},
|
|
@@ -168,7 +243,7 @@ function ChatInner(_0, _1) {
|
|
|
168
243
|
maximizeIconComponent: headerMaximizeIconComponent,
|
|
169
244
|
translations: headerTranslations
|
|
170
245
|
}, headerProps),
|
|
171
|
-
messagesProps: _$
|
|
246
|
+
messagesProps: _$5(_$6({
|
|
172
247
|
status: status,
|
|
173
248
|
onReload: function onReload(messageId) {
|
|
174
249
|
return regenerate({
|
|
@@ -192,24 +267,28 @@ function ChatInner(_0, _1) {
|
|
|
192
267
|
contentRef: contentRef,
|
|
193
268
|
onScrollToBottom: scrollToBottom,
|
|
194
269
|
loaderComponent: loaderComponent,
|
|
270
|
+
loaderPosition: loaderPosition,
|
|
271
|
+
shouldShowLoader: shouldShowLoader,
|
|
272
|
+
loaderShowDelay: loaderShowDelay,
|
|
273
|
+
loaderMinDuration: loaderMinDuration,
|
|
195
274
|
errorComponent: messagesErrorComponent,
|
|
196
275
|
emptyComponent: emptyComponent,
|
|
197
276
|
actionsComponent: actionsComponent,
|
|
198
277
|
translations: messagesTranslations,
|
|
199
278
|
messageTranslations: messageTranslations
|
|
200
279
|
}, restMessagesProps), {
|
|
201
|
-
assistantMessageProps: _$
|
|
280
|
+
assistantMessageProps: _$6({
|
|
202
281
|
leadingComponent: assistantMessageLeadingComponent,
|
|
203
282
|
footerComponent: assistantMessageFooterComponent,
|
|
204
283
|
showReasoning: showReasoning
|
|
205
284
|
}, callerAssistantMessageProps),
|
|
206
|
-
userMessageProps: _$
|
|
285
|
+
userMessageProps: _$6({
|
|
207
286
|
leadingComponent: userMessageLeadingComponent,
|
|
208
287
|
footerComponent: userMessageFooterComponent
|
|
209
288
|
}, callerUserMessageProps),
|
|
210
289
|
error: error
|
|
211
290
|
}),
|
|
212
|
-
promptProps: _$
|
|
291
|
+
promptProps: _$5(_$6({
|
|
213
292
|
promptRef: promptRef,
|
|
214
293
|
status: status,
|
|
215
294
|
value: input,
|
|
@@ -233,6 +312,7 @@ function ChatInner(_0, _1) {
|
|
|
233
312
|
}),
|
|
234
313
|
suggestionsProps: {
|
|
235
314
|
suggestions: suggestions,
|
|
315
|
+
isLoading: suggestionsStatus === 'loading',
|
|
236
316
|
onSuggestionClick: function onSuggestionClick(suggestion) {
|
|
237
317
|
sendMessage({
|
|
238
318
|
text: suggestion
|
|
@@ -241,6 +321,11 @@ function ChatInner(_0, _1) {
|
|
|
241
321
|
},
|
|
242
322
|
classNames: classNames
|
|
243
323
|
});
|
|
324
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(AnimationSnapshot, {
|
|
325
|
+
promptRef: promptRef,
|
|
326
|
+
animationsBeforeReveal: animationsBeforeReveal,
|
|
327
|
+
open: open
|
|
328
|
+
}), chat);
|
|
244
329
|
}
|
|
245
330
|
var Chat = /*#__PURE__*/ React.forwardRef(ChatInner);
|
|
246
331
|
|
|
@@ -22,14 +22,18 @@ function PromptSuggestions(_0) {
|
|
|
22
22
|
"context",
|
|
23
23
|
"transformItems"
|
|
24
24
|
]);
|
|
25
|
-
var
|
|
25
|
+
var source = agentId !== undefined ? {
|
|
26
26
|
agentId: agentId,
|
|
27
|
-
transport: transport
|
|
27
|
+
transport: transport
|
|
28
|
+
} : {
|
|
29
|
+
transport: transport
|
|
30
|
+
};
|
|
31
|
+
var _usePromptSuggestions = usePromptSuggestions(_$1(_$2({}, source), {
|
|
28
32
|
configurationId: configurationId,
|
|
29
33
|
transformHits: transformHits,
|
|
30
34
|
context: context,
|
|
31
35
|
transformItems: transformItems
|
|
32
|
-
}, {
|
|
36
|
+
}), {
|
|
33
37
|
$$widgetType: 'ais.promptSuggestions'
|
|
34
38
|
}), suggestions = _usePromptSuggestions.suggestions, isLoading = _usePromptSuggestions.isLoading, onSuggestionClick = _usePromptSuggestions.onSuggestionClick, isChatBusy = _usePromptSuggestions.isChatBusy, sendToChat = _usePromptSuggestions.sendToChat;
|
|
35
39
|
var handleClick = onSuggestionClickOverride ? function(prompt) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createDisplayResultsToolComponent, createButtonComponent, ChevronLeftIcon, ChevronRightIcon } from 'instantsearch-ui-components';
|
|
2
|
-
import React, { createElement, Fragment, useEffect,
|
|
2
|
+
import React, { createElement, Fragment, useEffect, useRef } from 'react';
|
|
3
3
|
import { Carousel } from '../../../components/Carousel.js';
|
|
4
4
|
|
|
5
5
|
function createDisplayResultsTool(itemComponent) {
|
|
@@ -7,7 +7,6 @@ function createDisplayResultsTool(itemComponent) {
|
|
|
7
7
|
createElement: createElement,
|
|
8
8
|
Fragment: Fragment,
|
|
9
9
|
useEffect: useEffect,
|
|
10
|
-
useMemo: useMemo,
|
|
11
10
|
useRef: useRef
|
|
12
11
|
});
|
|
13
12
|
var Button = createButtonComponent({
|