UNPKG

react-instantsearch

Version:
51 lines (49 loc) • 2.15 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "createCompareProductsTool", { enumerable: true, get: function() { return createCompareProductsTool; } }); var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard"); var _instantsearchuicomponents = require("instantsearch-ui-components"); var _react = /*#__PURE__*/ _interop_require_wildcard._(require("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 = (0, _instantsearchuicomponents.createCompareProductsToolComponent)({ createElement: _react.createElement, Fragment: _react.Fragment }); var CompareProductsLayoutComponent = function CompareProductsLayoutComponent(toolProps) { return /*#__PURE__*/ _react.default.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 : [] } }); } }; }