react-instantsearch 7.49.1 → 7.50.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 +12 -12
- package/dist/cjs/widgets/CompareBar.js +46 -0
- package/dist/cjs/widgets/chat/tools/CompareProductsTool.js +50 -0
- package/dist/cjs/widgets/chat/tools/ComparisonTableTool.js +40 -0
- package/dist/cjs/widgets/chat/tools/{DisplayResultsTool.js → GroupedResultsTool.js} +11 -11
- package/dist/cjs/widgets/index.js +1 -0
- package/dist/es/index.js +2 -1
- package/dist/es/widgets/Chat.d.ts +2 -2
- package/dist/es/widgets/Chat.js +10 -14
- package/dist/es/widgets/CompareBar.d.ts +27 -0
- package/dist/es/widgets/CompareBar.js +45 -0
- package/dist/es/widgets/chat/tools/CompareProductsTool.d.ts +13 -0
- package/dist/es/widgets/chat/tools/CompareProductsTool.js +41 -0
- package/dist/es/widgets/chat/tools/ComparisonTableTool.d.ts +15 -0
- package/dist/es/widgets/chat/tools/ComparisonTableTool.js +31 -0
- package/dist/es/widgets/chat/tools/{DisplayResultsTool.js → GroupedResultsTool.js} +12 -12
- package/dist/es/widgets/index.d.ts +1 -0
- package/dist/es/widgets/index.js +2 -1
- package/dist/umd/ReactInstantSearch.js +639 -95
- package/dist/umd/ReactInstantSearch.min.js +3 -3
- package/package.json +5 -5
- /package/dist/es/widgets/chat/tools/{DisplayResultsTool.d.ts → GroupedResultsTool.d.ts} +0 -0
package/dist/cjs/widgets/Chat.js
CHANGED
|
@@ -13,7 +13,11 @@ _export(exports, {
|
|
|
13
13
|
get Chat () {
|
|
14
14
|
return Chat;
|
|
15
15
|
},
|
|
16
|
-
get
|
|
16
|
+
get CompareProductsToolType () {
|
|
17
|
+
return _chat.CompareProductsToolType;
|
|
18
|
+
},
|
|
19
|
+
get // eslint-disable-next-line typescript/no-deprecated
|
|
20
|
+
DisplayResultsToolType () {
|
|
17
21
|
return _chat.DisplayResultsToolType;
|
|
18
22
|
},
|
|
19
23
|
get GroupedResultsToolType () {
|
|
@@ -56,7 +60,8 @@ var _focusAfterReveal = require("instantsearch.js/cjs/lib/chat/focusAfterReveal"
|
|
|
56
60
|
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
57
61
|
var _reactinstantsearchcore = require("react-instantsearch-core");
|
|
58
62
|
var _useStickToBottom = require("../lib/useStickToBottom");
|
|
59
|
-
var
|
|
63
|
+
var _CompareProductsTool = require("./chat/tools/CompareProductsTool");
|
|
64
|
+
var _GroupedResultsTool = require("./chat/tools/GroupedResultsTool");
|
|
60
65
|
var _SearchIndexTool = require("./chat/tools/SearchIndexTool");
|
|
61
66
|
var ChatUiComponent = (0, _instantsearchuicomponents.createChatComponent)({
|
|
62
67
|
createElement: _react.createElement,
|
|
@@ -66,20 +71,15 @@ var ChatUiComponent = (0, _instantsearchuicomponents.createChatComponent)({
|
|
|
66
71
|
useEffect: _react.useEffect
|
|
67
72
|
});
|
|
68
73
|
function createDefaultTools(itemComponent, getSearchPageURL) {
|
|
74
|
+
var groupedResultsTool = (0, _GroupedResultsTool.createGroupedResultsTool)(itemComponent);
|
|
69
75
|
var _obj;
|
|
70
76
|
return _obj = {}, _define_property._(_obj, _chat.SearchIndexToolType, _object_spread_props._(_object_spread._({}, (0, _SearchIndexTool.createCarouselTool)(true, itemComponent, getSearchPageURL)), {
|
|
71
77
|
// The agent decides per turn whether the richer Grouped Results tool
|
|
72
78
|
// takes over the rendering of the search results.
|
|
73
|
-
shouldRender:
|
|
74
|
-
})), _define_property._(_obj, _chat.RecommendToolType, (0, _SearchIndexTool.createCarouselTool)(false, itemComponent, getSearchPageURL)), _define_property._(_obj, _chat.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
* Whether the search tool renders its own results, i.e. the agent did not hand
|
|
78
|
-
* the turn to the Grouped Results tool. Set on the message by the backend.
|
|
79
|
-
*/ function isDisplayResultsDisabled(param) {
|
|
80
|
-
var parentMessage = param.parentMessage;
|
|
81
|
-
var _parentMessage_metadata;
|
|
82
|
-
return ((_parentMessage_metadata = parentMessage.metadata) === null || _parentMessage_metadata === void 0 ? void 0 : _parentMessage_metadata.displayResultsEnabled) !== true;
|
|
79
|
+
shouldRender: _instantsearchuicomponents.shouldSearchToolRenderResults
|
|
80
|
+
})), _define_property._(_obj, _chat.RecommendToolType, (0, _SearchIndexTool.createCarouselTool)(false, itemComponent, getSearchPageURL)), _define_property._(_obj, _chat.GroupedResultsToolType, groupedResultsTool), // Agents configured before the rename still emit the legacy tool name.
|
|
81
|
+
// eslint-disable-next-line typescript/no-deprecated
|
|
82
|
+
_define_property._(_obj, _chat.DisplayResultsToolType, groupedResultsTool), _define_property._(_obj, _chat.CompareProductsToolType, (0, _CompareProductsTool.createCompareProductsTool)()), _define_property._(_obj, _chat.MemorizeToolType, {}), _define_property._(_obj, _chat.MemorySearchToolType, {}), _define_property._(_obj, _chat.PonderToolType, {}), _obj;
|
|
83
83
|
}
|
|
84
84
|
function mergeToolOptions(defaultTools, userTools) {
|
|
85
85
|
if (!userTools) {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "CompareBar", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function() {
|
|
9
|
+
return CompareBar;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
13
|
+
var _object_without_properties = require("@swc/helpers/_/_object_without_properties");
|
|
14
|
+
var _instantsearchuicomponents = require("instantsearch-ui-components");
|
|
15
|
+
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
16
|
+
var _reactinstantsearchcore = require("react-instantsearch-core");
|
|
17
|
+
var CompareBarUiComponent = (0, _instantsearchuicomponents.createCompareBarComponent)({
|
|
18
|
+
createElement: _react.createElement,
|
|
19
|
+
Fragment: _react.Fragment
|
|
20
|
+
});
|
|
21
|
+
function CompareBar(_0) {
|
|
22
|
+
var classNames = _0.classNames, translations = _0.translations, itemComponent = _0.itemComponent, props = _object_without_properties._(_0, [
|
|
23
|
+
"classNames",
|
|
24
|
+
"translations",
|
|
25
|
+
"itemComponent"
|
|
26
|
+
]);
|
|
27
|
+
var _useCompare = (0, _reactinstantsearchcore.useCompare)(props, {
|
|
28
|
+
$$widgetType: 'ais.compareBar'
|
|
29
|
+
}), items = _useCompare.items, minItems = _useCompare.minItems, maxItems = _useCompare.maxItems, canCompare = _useCompare.canCompare, removeItem = _useCompare.removeItem, clearItems = _useCompare.clearItems, compare = _useCompare.compare;
|
|
30
|
+
return /*#__PURE__*/ _react.default.createElement(CompareBarUiComponent, {
|
|
31
|
+
items: items,
|
|
32
|
+
minItems: minItems,
|
|
33
|
+
maxItems: maxItems,
|
|
34
|
+
canCompare: canCompare,
|
|
35
|
+
onCompare: function onCompare() {
|
|
36
|
+
return compare();
|
|
37
|
+
},
|
|
38
|
+
onRemove: function onRemove(item) {
|
|
39
|
+
return removeItem(item.objectID);
|
|
40
|
+
},
|
|
41
|
+
onClear: clearItems,
|
|
42
|
+
itemComponent: itemComponent,
|
|
43
|
+
classNames: classNames,
|
|
44
|
+
translations: translations
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "createCompareProductsTool", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function() {
|
|
9
|
+
return createCompareProductsTool;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
13
|
+
var _instantsearchuicomponents = require("instantsearch-ui-components");
|
|
14
|
+
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
15
|
+
/**
|
|
16
|
+
* Builtin comparison tool (`algolia_compare_products`).
|
|
17
|
+
*
|
|
18
|
+
* Registered by default in the chat widget so the agent can trigger a grounded
|
|
19
|
+
* side-by-side comparison: its tool call names only the product objectIDs and
|
|
20
|
+
* the attribute keys, and every cell is hydrated client-side from the real
|
|
21
|
+
* `algolia_search_index` hits. The model never types a value, so it cannot
|
|
22
|
+
* hallucinate one. See `instantsearch-ui-components` `CompareProductsTool` for
|
|
23
|
+
* the contract, and `comparison-eval/README.md` for the study behind it.
|
|
24
|
+
*/ function createCompareProductsTool(translations) {
|
|
25
|
+
var CompareProductsUIComponent = (0, _instantsearchuicomponents.createCompareProductsToolComponent)({
|
|
26
|
+
createElement: _react.createElement,
|
|
27
|
+
Fragment: _react.Fragment
|
|
28
|
+
});
|
|
29
|
+
var CompareProductsLayoutComponent = function CompareProductsLayoutComponent(toolProps) {
|
|
30
|
+
return /*#__PURE__*/ _react.default.createElement(CompareProductsUIComponent, {
|
|
31
|
+
toolProps: toolProps,
|
|
32
|
+
translations: translations
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
layoutComponent: CompareProductsLayoutComponent,
|
|
37
|
+
// Client-side tool: acknowledge the call so the agent's turn can complete.
|
|
38
|
+
// The table itself is rendered from the call's input + real search hits.
|
|
39
|
+
onToolCall: function onToolCall(param) {
|
|
40
|
+
var input = param.input, addToolResult = param.addToolResult;
|
|
41
|
+
var objectIDs = input === null || input === void 0 ? void 0 : input.objectIDs;
|
|
42
|
+
addToolResult({
|
|
43
|
+
output: {
|
|
44
|
+
status: 'displayed',
|
|
45
|
+
objectIDs: Array.isArray(objectIDs) ? objectIDs : []
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "createComparisonTableTool", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function() {
|
|
9
|
+
return createComparisonTableTool;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
13
|
+
var _instantsearchuicomponents = require("instantsearch-ui-components");
|
|
14
|
+
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
15
|
+
/**
|
|
16
|
+
* Grounded comparison-table tool (prototype).
|
|
17
|
+
*
|
|
18
|
+
* Renders a v2 `markdownTable` display block whose every cell is hydrated from
|
|
19
|
+
* the real `algolia_search_index` hits by objectID — the agent supplies only the
|
|
20
|
+
* objectIDs and the attribute keys, never the values. See
|
|
21
|
+
* `instantsearch-ui-components` `ComparisonTableTool` for the contract.
|
|
22
|
+
*
|
|
23
|
+
* Register under the display-results tool key (or a dedicated key) in
|
|
24
|
+
* `createDefaultTools` to have comparison answers rendered as a grounded table
|
|
25
|
+
* instead of the model-authored markdown table.
|
|
26
|
+
*/ function createComparisonTableTool(translations) {
|
|
27
|
+
var ComparisonTableUIComponent = (0, _instantsearchuicomponents.createComparisonTableToolComponent)({
|
|
28
|
+
createElement: _react.createElement,
|
|
29
|
+
Fragment: _react.Fragment
|
|
30
|
+
});
|
|
31
|
+
var ComparisonTableLayoutComponent = function ComparisonTableLayoutComponent(toolProps) {
|
|
32
|
+
return /*#__PURE__*/ _react.default.createElement(ComparisonTableUIComponent, {
|
|
33
|
+
toolProps: toolProps,
|
|
34
|
+
translations: translations
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
layoutComponent: ComparisonTableLayoutComponent
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -14,7 +14,7 @@ var _instantsearchuicomponents = require("instantsearch-ui-components");
|
|
|
14
14
|
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
15
15
|
var _components = require("../../../components");
|
|
16
16
|
function createGroupedResultsTool(itemComponent) {
|
|
17
|
-
var
|
|
17
|
+
var GroupedResultsUIComponent = (0, _instantsearchuicomponents.createGroupedResultsToolComponent)({
|
|
18
18
|
createElement: _react.createElement,
|
|
19
19
|
Fragment: _react.Fragment,
|
|
20
20
|
useEffect: _react.useEffect,
|
|
@@ -23,14 +23,14 @@ function createGroupedResultsTool(itemComponent) {
|
|
|
23
23
|
var Button = (0, _instantsearchuicomponents.createButtonComponent)({
|
|
24
24
|
createElement: _react.createElement
|
|
25
25
|
});
|
|
26
|
-
var
|
|
26
|
+
var GroupedResultsCarouselHeader = function GroupedResultsCarouselHeader(param) {
|
|
27
27
|
var nbItems = param.nbItems, canScrollLeft = param.canScrollLeft, canScrollRight = param.canScrollRight, scrollLeft = param.scrollLeft, scrollRight = param.scrollRight;
|
|
28
28
|
return /*#__PURE__*/ _react.default.createElement("div", {
|
|
29
|
-
className: "ais-
|
|
29
|
+
className: "ais-ChatToolGroupedResultsCarouselHeader"
|
|
30
30
|
}, /*#__PURE__*/ _react.default.createElement("div", {
|
|
31
|
-
className: "ais-
|
|
31
|
+
className: "ais-ChatToolGroupedResultsCarouselHeaderCount"
|
|
32
32
|
}, nbItems, " result", nbItems > 1 ? 's' : ''), /*#__PURE__*/ _react.default.createElement("div", {
|
|
33
|
-
className: "ais-
|
|
33
|
+
className: "ais-ChatToolGroupedResultsCarouselHeaderScrollButtons"
|
|
34
34
|
}, /*#__PURE__*/ _react.default.createElement(Button, {
|
|
35
35
|
variant: "outline",
|
|
36
36
|
size: "sm",
|
|
@@ -38,7 +38,7 @@ function createGroupedResultsTool(itemComponent) {
|
|
|
38
38
|
"aria-label": "Previous",
|
|
39
39
|
onClick: scrollLeft,
|
|
40
40
|
disabled: !canScrollLeft,
|
|
41
|
-
className: "ais-
|
|
41
|
+
className: "ais-ChatToolGroupedResultsCarouselHeaderScrollButton"
|
|
42
42
|
}, /*#__PURE__*/ _react.default.createElement(_instantsearchuicomponents.ChevronLeftIcon, {
|
|
43
43
|
createElement: _react.createElement
|
|
44
44
|
})), /*#__PURE__*/ _react.default.createElement(Button, {
|
|
@@ -48,13 +48,13 @@ function createGroupedResultsTool(itemComponent) {
|
|
|
48
48
|
"aria-label": "Next",
|
|
49
49
|
onClick: scrollRight,
|
|
50
50
|
disabled: !canScrollRight,
|
|
51
|
-
className: "ais-
|
|
51
|
+
className: "ais-ChatToolGroupedResultsCarouselHeaderScrollButton"
|
|
52
52
|
}, /*#__PURE__*/ _react.default.createElement(_instantsearchuicomponents.ChevronRightIcon, {
|
|
53
53
|
createElement: _react.createElement
|
|
54
54
|
}))));
|
|
55
55
|
};
|
|
56
|
-
var
|
|
57
|
-
return /*#__PURE__*/ _react.default.createElement(
|
|
56
|
+
var GroupedResultsLayoutComponent = function GroupedResultsLayoutComponent(toolProps) {
|
|
57
|
+
return /*#__PURE__*/ _react.default.createElement(GroupedResultsUIComponent, {
|
|
58
58
|
toolProps: toolProps,
|
|
59
59
|
groupCarouselComponent: function groupCarouselComponent(param) {
|
|
60
60
|
var items = param.items, sendEvent = param.sendEvent;
|
|
@@ -63,13 +63,13 @@ function createGroupedResultsTool(itemComponent) {
|
|
|
63
63
|
itemComponent: itemComponent,
|
|
64
64
|
sendEvent: sendEvent,
|
|
65
65
|
showNavigation: false,
|
|
66
|
-
headerComponent:
|
|
66
|
+
headerComponent: GroupedResultsCarouselHeader
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
};
|
|
71
71
|
return {
|
|
72
|
-
layoutComponent:
|
|
72
|
+
layoutComponent: GroupedResultsLayoutComponent,
|
|
73
73
|
streamInput: true
|
|
74
74
|
};
|
|
75
75
|
}
|
|
@@ -9,6 +9,7 @@ _export_star._(require("./Breadcrumb"), exports);
|
|
|
9
9
|
_export_star._(require("./Chat"), exports);
|
|
10
10
|
_export_star._(require("./PromptSuggestions"), exports);
|
|
11
11
|
_export_star._(require("./ChatTrigger"), exports);
|
|
12
|
+
_export_star._(require("./CompareBar"), exports);
|
|
12
13
|
_export_star._(require("./ClearRefinements"), exports);
|
|
13
14
|
_export_star._(require("./CurrentRefinements"), exports);
|
|
14
15
|
_export_star._(require("./FrequentlyBoughtTogether"), exports);
|
package/dist/es/index.js
CHANGED
|
@@ -2,10 +2,11 @@ export * from 'react-instantsearch-core';
|
|
|
2
2
|
export { useStickToBottom } from './lib/useStickToBottom.js';
|
|
3
3
|
export { Autocomplete, EXPERIMENTAL_Autocomplete } from './widgets/Autocomplete.js';
|
|
4
4
|
export { Breadcrumb } from './widgets/Breadcrumb.js';
|
|
5
|
-
export { DisplayResultsToolType, GroupedResultsToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, RecommendToolType, SearchIndexToolType } from 'instantsearch.js/es/lib/chat/index.js';
|
|
5
|
+
export { CompareProductsToolType, DisplayResultsToolType, GroupedResultsToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, RecommendToolType, SearchIndexToolType } from 'instantsearch.js/es/lib/chat/index.js';
|
|
6
6
|
export { Chat, createDefaultTools } from './widgets/Chat.js';
|
|
7
7
|
export { PromptSuggestions } from './widgets/PromptSuggestions.js';
|
|
8
8
|
export { ChatTrigger } from './widgets/ChatTrigger.js';
|
|
9
|
+
export { CompareBar } from './widgets/CompareBar.js';
|
|
9
10
|
export { ClearRefinements } from './widgets/ClearRefinements.js';
|
|
10
11
|
export { CurrentRefinements } from './widgets/CurrentRefinements.js';
|
|
11
12
|
export { FrequentlyBoughtTogether } from './widgets/FrequentlyBoughtTogether.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SearchIndexToolType, RecommendToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, DisplayResultsToolType, GroupedResultsToolType } from 'instantsearch.js/es/lib/chat';
|
|
1
|
+
import { SearchIndexToolType, RecommendToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, DisplayResultsToolType, CompareProductsToolType, GroupedResultsToolType } from 'instantsearch.js/es/lib/chat';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
export { SearchIndexToolType, RecommendToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, DisplayResultsToolType, GroupedResultsToolType, };
|
|
3
|
+
export { SearchIndexToolType, RecommendToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, DisplayResultsToolType, CompareProductsToolType, GroupedResultsToolType, };
|
|
4
4
|
import type { ChatProps as ChatUiProps, ChatLayoutOwnProps, RecommendComponentProps, RecordWithObjectID, UserClientSideTool, UserClientSideTools, ChatMessageProps } from 'instantsearch-ui-components';
|
|
5
5
|
import type { IndexUiState } from 'instantsearch.js';
|
|
6
6
|
import type { UIMessage } from 'instantsearch.js/es/lib/chat';
|
package/dist/es/widgets/Chat.js
CHANGED
|
@@ -9,14 +9,15 @@ import { _ as _$8 } from '@swc/helpers/esm/_object_without_properties.js';
|
|
|
9
9
|
import { _ as _$9 } from '@swc/helpers/esm/_sliced_to_array.js';
|
|
10
10
|
import { _ as _$7 } from '@swc/helpers/esm/_to_array.js';
|
|
11
11
|
import { _ as _$a } from '@swc/helpers/esm/_to_consumable_array.js';
|
|
12
|
-
import { createChatComponent } from 'instantsearch-ui-components';
|
|
13
|
-
import { SearchIndexToolType, RecommendToolType, DisplayResultsToolType,
|
|
14
|
-
export { DisplayResultsToolType, GroupedResultsToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, RecommendToolType, SearchIndexToolType } from 'instantsearch.js/es/lib/chat/index.js';
|
|
12
|
+
import { createChatComponent, shouldSearchToolRenderResults } from 'instantsearch-ui-components';
|
|
13
|
+
import { SearchIndexToolType, RecommendToolType, GroupedResultsToolType, DisplayResultsToolType, CompareProductsToolType, MemorizeToolType, MemorySearchToolType, PonderToolType } from 'instantsearch.js/es/lib/chat/index.js';
|
|
14
|
+
export { CompareProductsToolType, DisplayResultsToolType, GroupedResultsToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, RecommendToolType, SearchIndexToolType } from 'instantsearch.js/es/lib/chat/index.js';
|
|
15
15
|
import { getActiveContainerAnimations, holdContainerInertUntilReveal, restoreContainerInertUntilReveal, focusAfterReveal } from 'instantsearch.js/es/lib/chat/focusAfterReveal.js';
|
|
16
16
|
import React, { createElement, Fragment, useMemo, useState, useEffect, useRef, useCallback, useImperativeHandle } from 'react';
|
|
17
17
|
import { useInstantSearch, useChat } from 'react-instantsearch-core';
|
|
18
18
|
import { useStickToBottom } from '../lib/useStickToBottom.js';
|
|
19
|
-
import {
|
|
19
|
+
import { createCompareProductsTool } from './chat/tools/CompareProductsTool.js';
|
|
20
|
+
import { createGroupedResultsTool } from './chat/tools/GroupedResultsTool.js';
|
|
20
21
|
import { createCarouselTool } from './chat/tools/SearchIndexTool.js';
|
|
21
22
|
|
|
22
23
|
var ChatUiComponent = createChatComponent({
|
|
@@ -27,20 +28,15 @@ var ChatUiComponent = createChatComponent({
|
|
|
27
28
|
useEffect: useEffect
|
|
28
29
|
});
|
|
29
30
|
function createDefaultTools(itemComponent, getSearchPageURL) {
|
|
31
|
+
var groupedResultsTool = createGroupedResultsTool(itemComponent);
|
|
30
32
|
var _obj;
|
|
31
33
|
return _obj = {}, _$4(_obj, SearchIndexToolType, _$5(_$6({}, createCarouselTool(true, itemComponent, getSearchPageURL)), {
|
|
32
34
|
// The agent decides per turn whether the richer Grouped Results tool
|
|
33
35
|
// takes over the rendering of the search results.
|
|
34
|
-
shouldRender:
|
|
35
|
-
})), _$4(_obj, RecommendToolType, createCarouselTool(false, itemComponent, getSearchPageURL)), _$4(_obj,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* Whether the search tool renders its own results, i.e. the agent did not hand
|
|
39
|
-
* the turn to the Grouped Results tool. Set on the message by the backend.
|
|
40
|
-
*/ function isDisplayResultsDisabled(param) {
|
|
41
|
-
var parentMessage = param.parentMessage;
|
|
42
|
-
var _parentMessage_metadata;
|
|
43
|
-
return ((_parentMessage_metadata = parentMessage.metadata) === null || _parentMessage_metadata === void 0 ? void 0 : _parentMessage_metadata.displayResultsEnabled) !== true;
|
|
36
|
+
shouldRender: shouldSearchToolRenderResults
|
|
37
|
+
})), _$4(_obj, RecommendToolType, createCarouselTool(false, itemComponent, getSearchPageURL)), _$4(_obj, GroupedResultsToolType, groupedResultsTool), // Agents configured before the rename still emit the legacy tool name.
|
|
38
|
+
// eslint-disable-next-line typescript/no-deprecated
|
|
39
|
+
_$4(_obj, DisplayResultsToolType, groupedResultsTool), _$4(_obj, CompareProductsToolType, createCompareProductsTool()), _$4(_obj, MemorizeToolType, {}), _$4(_obj, MemorySearchToolType, {}), _$4(_obj, PonderToolType, {}), _obj;
|
|
44
40
|
}
|
|
45
41
|
function mergeToolOptions(defaultTools, userTools) {
|
|
46
42
|
if (!userTools) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { CompareBarClassNames, CompareBarItemComponentProps, CompareBarTranslations } from 'instantsearch-ui-components';
|
|
3
|
+
import type { UseCompareProps } from 'react-instantsearch-core';
|
|
4
|
+
export type CompareBarProps = UseCompareProps & {
|
|
5
|
+
/**
|
|
6
|
+
* CSS classes to add to the widget elements.
|
|
7
|
+
*/
|
|
8
|
+
classNames?: Partial<CompareBarClassNames>;
|
|
9
|
+
/**
|
|
10
|
+
* Translations for the widget's texts.
|
|
11
|
+
*/
|
|
12
|
+
translations?: Partial<CompareBarTranslations>;
|
|
13
|
+
/**
|
|
14
|
+
* Custom renderer for a selected item's label.
|
|
15
|
+
*/
|
|
16
|
+
itemComponent?: (props: CompareBarItemComponentProps) => JSX.Element;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Renders the comparison selection bar: the records picked for comparison,
|
|
20
|
+
* a clear-selection action, and the "Compare" call-to-action that opens the
|
|
21
|
+
* `<Chat>` widget with the comparison message.
|
|
22
|
+
*
|
|
23
|
+
* Select records from your own UI (e.g. a "Compare" button in your hit
|
|
24
|
+
* component) with `useCompare().toggleItem(hit)` — the selection is shared
|
|
25
|
+
* with this widget.
|
|
26
|
+
*/
|
|
27
|
+
export declare function CompareBar({ classNames, translations, itemComponent, ...props }: CompareBarProps): React.JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { _ } from '@swc/helpers/esm/_object_without_properties.js';
|
|
2
|
+
import { createCompareBarComponent } from 'instantsearch-ui-components';
|
|
3
|
+
import React, { createElement, Fragment } from 'react';
|
|
4
|
+
import { useCompare } from 'react-instantsearch-core';
|
|
5
|
+
|
|
6
|
+
var CompareBarUiComponent = createCompareBarComponent({
|
|
7
|
+
createElement: createElement,
|
|
8
|
+
Fragment: Fragment
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Renders the comparison selection bar: the records picked for comparison,
|
|
12
|
+
* a clear-selection action, and the "Compare" call-to-action that opens the
|
|
13
|
+
* `<Chat>` widget with the comparison message.
|
|
14
|
+
*
|
|
15
|
+
* Select records from your own UI (e.g. a "Compare" button in your hit
|
|
16
|
+
* component) with `useCompare().toggleItem(hit)` — the selection is shared
|
|
17
|
+
* with this widget.
|
|
18
|
+
*/ function CompareBar(_0) {
|
|
19
|
+
var classNames = _0.classNames, translations = _0.translations, itemComponent = _0.itemComponent, props = _(_0, [
|
|
20
|
+
"classNames",
|
|
21
|
+
"translations",
|
|
22
|
+
"itemComponent"
|
|
23
|
+
]);
|
|
24
|
+
var _useCompare = useCompare(props, {
|
|
25
|
+
$$widgetType: 'ais.compareBar'
|
|
26
|
+
}), items = _useCompare.items, minItems = _useCompare.minItems, maxItems = _useCompare.maxItems, canCompare = _useCompare.canCompare, removeItem = _useCompare.removeItem, clearItems = _useCompare.clearItems, compare = _useCompare.compare;
|
|
27
|
+
return /*#__PURE__*/ React.createElement(CompareBarUiComponent, {
|
|
28
|
+
items: items,
|
|
29
|
+
minItems: minItems,
|
|
30
|
+
maxItems: maxItems,
|
|
31
|
+
canCompare: canCompare,
|
|
32
|
+
onCompare: function onCompare() {
|
|
33
|
+
return compare();
|
|
34
|
+
},
|
|
35
|
+
onRemove: function onRemove(item) {
|
|
36
|
+
return removeItem(item.objectID);
|
|
37
|
+
},
|
|
38
|
+
onClear: clearItems,
|
|
39
|
+
itemComponent: itemComponent,
|
|
40
|
+
classNames: classNames,
|
|
41
|
+
translations: translations
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { CompareBar };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ComparisonTableTranslations, UserClientSideTool } from 'instantsearch-ui-components';
|
|
2
|
+
/**
|
|
3
|
+
* Builtin comparison tool (`algolia_compare_products`).
|
|
4
|
+
*
|
|
5
|
+
* Registered by default in the chat widget so the agent can trigger a grounded
|
|
6
|
+
* side-by-side comparison: its tool call names only the product objectIDs and
|
|
7
|
+
* the attribute keys, and every cell is hydrated client-side from the real
|
|
8
|
+
* `algolia_search_index` hits. The model never types a value, so it cannot
|
|
9
|
+
* hallucinate one. See `instantsearch-ui-components` `CompareProductsTool` for
|
|
10
|
+
* the contract, and `comparison-eval/README.md` for the study behind it.
|
|
11
|
+
*/
|
|
12
|
+
declare function createCompareProductsTool(translations?: Partial<ComparisonTableTranslations>): UserClientSideTool;
|
|
13
|
+
export { createCompareProductsTool };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createCompareProductsToolComponent } from 'instantsearch-ui-components';
|
|
2
|
+
import React, { createElement, Fragment } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Builtin comparison tool (`algolia_compare_products`).
|
|
6
|
+
*
|
|
7
|
+
* Registered by default in the chat widget so the agent can trigger a grounded
|
|
8
|
+
* side-by-side comparison: its tool call names only the product objectIDs and
|
|
9
|
+
* the attribute keys, and every cell is hydrated client-side from the real
|
|
10
|
+
* `algolia_search_index` hits. The model never types a value, so it cannot
|
|
11
|
+
* hallucinate one. See `instantsearch-ui-components` `CompareProductsTool` for
|
|
12
|
+
* the contract, and `comparison-eval/README.md` for the study behind it.
|
|
13
|
+
*/ function createCompareProductsTool(translations) {
|
|
14
|
+
var CompareProductsUIComponent = createCompareProductsToolComponent({
|
|
15
|
+
createElement: createElement,
|
|
16
|
+
Fragment: Fragment
|
|
17
|
+
});
|
|
18
|
+
var CompareProductsLayoutComponent = function CompareProductsLayoutComponent(toolProps) {
|
|
19
|
+
return /*#__PURE__*/ React.createElement(CompareProductsUIComponent, {
|
|
20
|
+
toolProps: toolProps,
|
|
21
|
+
translations: translations
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
layoutComponent: CompareProductsLayoutComponent,
|
|
26
|
+
// Client-side tool: acknowledge the call so the agent's turn can complete.
|
|
27
|
+
// The table itself is rendered from the call's input + real search hits.
|
|
28
|
+
onToolCall: function onToolCall(param) {
|
|
29
|
+
var input = param.input, addToolResult = param.addToolResult;
|
|
30
|
+
var objectIDs = input === null || input === void 0 ? void 0 : input.objectIDs;
|
|
31
|
+
addToolResult({
|
|
32
|
+
output: {
|
|
33
|
+
status: 'displayed',
|
|
34
|
+
objectIDs: Array.isArray(objectIDs) ? objectIDs : []
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { createCompareProductsTool };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ComparisonTableTranslations, UserClientSideTool } from 'instantsearch-ui-components';
|
|
2
|
+
/**
|
|
3
|
+
* Grounded comparison-table tool (prototype).
|
|
4
|
+
*
|
|
5
|
+
* Renders a v2 `markdownTable` display block whose every cell is hydrated from
|
|
6
|
+
* the real `algolia_search_index` hits by objectID — the agent supplies only the
|
|
7
|
+
* objectIDs and the attribute keys, never the values. See
|
|
8
|
+
* `instantsearch-ui-components` `ComparisonTableTool` for the contract.
|
|
9
|
+
*
|
|
10
|
+
* Register under the display-results tool key (or a dedicated key) in
|
|
11
|
+
* `createDefaultTools` to have comparison answers rendered as a grounded table
|
|
12
|
+
* instead of the model-authored markdown table.
|
|
13
|
+
*/
|
|
14
|
+
declare function createComparisonTableTool(translations?: Partial<ComparisonTableTranslations>): UserClientSideTool;
|
|
15
|
+
export { createComparisonTableTool };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createComparisonTableToolComponent } from 'instantsearch-ui-components';
|
|
2
|
+
import React, { createElement, Fragment } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Grounded comparison-table tool (prototype).
|
|
6
|
+
*
|
|
7
|
+
* Renders a v2 `markdownTable` display block whose every cell is hydrated from
|
|
8
|
+
* the real `algolia_search_index` hits by objectID — the agent supplies only the
|
|
9
|
+
* objectIDs and the attribute keys, never the values. See
|
|
10
|
+
* `instantsearch-ui-components` `ComparisonTableTool` for the contract.
|
|
11
|
+
*
|
|
12
|
+
* Register under the display-results tool key (or a dedicated key) in
|
|
13
|
+
* `createDefaultTools` to have comparison answers rendered as a grounded table
|
|
14
|
+
* instead of the model-authored markdown table.
|
|
15
|
+
*/ function createComparisonTableTool(translations) {
|
|
16
|
+
var ComparisonTableUIComponent = createComparisonTableToolComponent({
|
|
17
|
+
createElement: createElement,
|
|
18
|
+
Fragment: Fragment
|
|
19
|
+
});
|
|
20
|
+
var ComparisonTableLayoutComponent = function ComparisonTableLayoutComponent(toolProps) {
|
|
21
|
+
return /*#__PURE__*/ React.createElement(ComparisonTableUIComponent, {
|
|
22
|
+
toolProps: toolProps,
|
|
23
|
+
translations: translations
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
layoutComponent: ComparisonTableLayoutComponent
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { createComparisonTableTool };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createGroupedResultsToolComponent, createButtonComponent, ChevronLeftIcon, ChevronRightIcon } from 'instantsearch-ui-components';
|
|
2
2
|
import React, { createElement, Fragment, useEffect, useRef } from 'react';
|
|
3
3
|
import { Carousel } from '../../../components/Carousel.js';
|
|
4
4
|
|
|
5
5
|
function createGroupedResultsTool(itemComponent) {
|
|
6
|
-
var
|
|
6
|
+
var GroupedResultsUIComponent = createGroupedResultsToolComponent({
|
|
7
7
|
createElement: createElement,
|
|
8
8
|
Fragment: Fragment,
|
|
9
9
|
useEffect: useEffect,
|
|
@@ -12,14 +12,14 @@ function createGroupedResultsTool(itemComponent) {
|
|
|
12
12
|
var Button = createButtonComponent({
|
|
13
13
|
createElement: createElement
|
|
14
14
|
});
|
|
15
|
-
var
|
|
15
|
+
var GroupedResultsCarouselHeader = function GroupedResultsCarouselHeader(param) {
|
|
16
16
|
var nbItems = param.nbItems, canScrollLeft = param.canScrollLeft, canScrollRight = param.canScrollRight, scrollLeft = param.scrollLeft, scrollRight = param.scrollRight;
|
|
17
17
|
return /*#__PURE__*/ React.createElement("div", {
|
|
18
|
-
className: "ais-
|
|
18
|
+
className: "ais-ChatToolGroupedResultsCarouselHeader"
|
|
19
19
|
}, /*#__PURE__*/ React.createElement("div", {
|
|
20
|
-
className: "ais-
|
|
20
|
+
className: "ais-ChatToolGroupedResultsCarouselHeaderCount"
|
|
21
21
|
}, nbItems, " result", nbItems > 1 ? 's' : ''), /*#__PURE__*/ React.createElement("div", {
|
|
22
|
-
className: "ais-
|
|
22
|
+
className: "ais-ChatToolGroupedResultsCarouselHeaderScrollButtons"
|
|
23
23
|
}, /*#__PURE__*/ React.createElement(Button, {
|
|
24
24
|
variant: "outline",
|
|
25
25
|
size: "sm",
|
|
@@ -27,7 +27,7 @@ function createGroupedResultsTool(itemComponent) {
|
|
|
27
27
|
"aria-label": "Previous",
|
|
28
28
|
onClick: scrollLeft,
|
|
29
29
|
disabled: !canScrollLeft,
|
|
30
|
-
className: "ais-
|
|
30
|
+
className: "ais-ChatToolGroupedResultsCarouselHeaderScrollButton"
|
|
31
31
|
}, /*#__PURE__*/ React.createElement(ChevronLeftIcon, {
|
|
32
32
|
createElement: createElement
|
|
33
33
|
})), /*#__PURE__*/ React.createElement(Button, {
|
|
@@ -37,13 +37,13 @@ function createGroupedResultsTool(itemComponent) {
|
|
|
37
37
|
"aria-label": "Next",
|
|
38
38
|
onClick: scrollRight,
|
|
39
39
|
disabled: !canScrollRight,
|
|
40
|
-
className: "ais-
|
|
40
|
+
className: "ais-ChatToolGroupedResultsCarouselHeaderScrollButton"
|
|
41
41
|
}, /*#__PURE__*/ React.createElement(ChevronRightIcon, {
|
|
42
42
|
createElement: createElement
|
|
43
43
|
}))));
|
|
44
44
|
};
|
|
45
|
-
var
|
|
46
|
-
return /*#__PURE__*/ React.createElement(
|
|
45
|
+
var GroupedResultsLayoutComponent = function GroupedResultsLayoutComponent(toolProps) {
|
|
46
|
+
return /*#__PURE__*/ React.createElement(GroupedResultsUIComponent, {
|
|
47
47
|
toolProps: toolProps,
|
|
48
48
|
groupCarouselComponent: function groupCarouselComponent(param) {
|
|
49
49
|
var items = param.items, sendEvent = param.sendEvent;
|
|
@@ -52,13 +52,13 @@ function createGroupedResultsTool(itemComponent) {
|
|
|
52
52
|
itemComponent: itemComponent,
|
|
53
53
|
sendEvent: sendEvent,
|
|
54
54
|
showNavigation: false,
|
|
55
|
-
headerComponent:
|
|
55
|
+
headerComponent: GroupedResultsCarouselHeader
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
};
|
|
60
60
|
return {
|
|
61
|
-
layoutComponent:
|
|
61
|
+
layoutComponent: GroupedResultsLayoutComponent,
|
|
62
62
|
streamInput: true
|
|
63
63
|
};
|
|
64
64
|
}
|
|
@@ -3,6 +3,7 @@ export * from './Breadcrumb';
|
|
|
3
3
|
export * from './Chat';
|
|
4
4
|
export * from './PromptSuggestions';
|
|
5
5
|
export * from './ChatTrigger';
|
|
6
|
+
export * from './CompareBar';
|
|
6
7
|
export * from './ClearRefinements';
|
|
7
8
|
export * from './CurrentRefinements';
|
|
8
9
|
export * from './FrequentlyBoughtTogether';
|
package/dist/es/widgets/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { Breadcrumb } from './Breadcrumb.js';
|
|
|
3
3
|
export { Chat, createDefaultTools } from './Chat.js';
|
|
4
4
|
export { PromptSuggestions } from './PromptSuggestions.js';
|
|
5
5
|
export { ChatTrigger } from './ChatTrigger.js';
|
|
6
|
+
export { CompareBar } from './CompareBar.js';
|
|
6
7
|
export { ClearRefinements } from './ClearRefinements.js';
|
|
7
8
|
export { CurrentRefinements } from './CurrentRefinements.js';
|
|
8
9
|
export { FrequentlyBoughtTogether } from './FrequentlyBoughtTogether.js';
|
|
@@ -27,4 +28,4 @@ export { ToggleRefinement } from './ToggleRefinement.js';
|
|
|
27
28
|
export { TrendingItems } from './TrendingItems.js';
|
|
28
29
|
export { TrendingFacets } from './TrendingFacets.js';
|
|
29
30
|
export { FilterSuggestions } from './FilterSuggestions.js';
|
|
30
|
-
export { DisplayResultsToolType, GroupedResultsToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, RecommendToolType, SearchIndexToolType } from 'instantsearch.js/es/lib/chat/index.js';
|
|
31
|
+
export { CompareProductsToolType, DisplayResultsToolType, GroupedResultsToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, RecommendToolType, SearchIndexToolType } from 'instantsearch.js/es/lib/chat/index.js';
|