UNPKG

react-instantsearch

Version:
42 lines (39 loc) • 1.8 kB
import { createCompareProductsToolComponent } from 'instantsearch-ui-components'; import React, { createElement, Fragment } from 'react'; /** * Builtin comparison tool (`algolia_compare_products`). * * Registered by default in the chat widget so the agent can lay a comparison * out as a table: the compared products across the top (rendered with the * widget's `itemComponent`, from the records the chat collected) and the * agent's criteria down the side, one value per product. See * `instantsearch-ui-components` `CompareProductsTool` for the contract. */ function createCompareProductsTool(itemComponent, translations) { var CompareProductsUIComponent = createCompareProductsToolComponent({ createElement: createElement, Fragment: Fragment }); var CompareProductsLayoutComponent = function CompareProductsLayoutComponent(toolProps) { return /*#__PURE__*/ React.createElement(CompareProductsUIComponent, { toolProps: toolProps, itemComponent: itemComponent, translations: translations }); }; return { layoutComponent: CompareProductsLayoutComponent, // Client-side tool: acknowledge the call so the agent's turn can complete. // The table itself is rendered from the call's input + the chat's records. onToolCall: function onToolCall(param) { var input = param.input, addToolResult = param.addToolResult; var objectIDs = input === null || input === void 0 ? void 0 : input.objectIDs; addToolResult({ output: { status: 'displayed', objectIDs: Array.isArray(objectIDs) ? objectIDs : [] } }); } }; } export { createCompareProductsTool };