react-instantsearch-core 7.17.0 → 7.18.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/components/Configure.js +2 -2
- package/dist/cjs/components/DynamicWidgets.js +3 -4
- package/dist/cjs/components/Index.js +3 -3
- package/dist/cjs/components/InstantSearch.js +3 -4
- package/dist/cjs/components/InstantSearchSSRProvider.js +5 -5
- package/dist/cjs/connectors/useAutocomplete.js +12 -0
- package/dist/cjs/connectors/useBreadcrumb.js +1 -1
- package/dist/cjs/connectors/useChat.js +100 -11
- package/dist/cjs/connectors/useClearRefinements.js +1 -1
- package/dist/cjs/connectors/useConfigure.js +1 -1
- package/dist/cjs/connectors/useCurrentRefinements.js +1 -1
- package/dist/cjs/connectors/useDynamicWidgets.js +3 -3
- package/dist/cjs/connectors/useFrequentlyBoughtTogether.js +1 -1
- package/dist/cjs/connectors/useGeoSearch.js +1 -1
- package/dist/cjs/connectors/useHierarchicalMenu.js +1 -1
- package/dist/cjs/connectors/useHits.js +1 -1
- package/dist/cjs/connectors/useHitsPerPage.js +1 -1
- package/dist/cjs/connectors/useInfiniteHits.js +1 -1
- package/dist/cjs/connectors/useLookingSimilar.js +1 -1
- package/dist/cjs/connectors/useMenu.js +1 -1
- package/dist/cjs/connectors/useNumericMenu.js +1 -1
- package/dist/cjs/connectors/usePagination.js +1 -1
- package/dist/cjs/connectors/useQueryRules.js +1 -1
- package/dist/cjs/connectors/useRange.js +1 -1
- package/dist/cjs/connectors/useRefinementList.js +1 -1
- package/dist/cjs/connectors/useRelatedProducts.js +1 -1
- package/dist/cjs/connectors/useSearchBox.js +1 -1
- package/dist/cjs/connectors/useSortBy.js +1 -1
- package/dist/cjs/connectors/useStats.js +1 -1
- package/dist/cjs/connectors/useToggleRefinement.js +1 -1
- package/dist/cjs/connectors/useTrendingItems.js +1 -1
- package/dist/cjs/hooks/useConnector.js +8 -8
- package/dist/cjs/index.js +13 -1
- package/dist/cjs/index.umd.js +13 -1
- package/dist/cjs/lib/createSearchResults.js +1 -1
- package/dist/cjs/lib/getIndexSearchResults.js +2 -2
- package/dist/cjs/lib/use.js +1 -2
- package/dist/cjs/lib/useForceUpdate.js +4 -4
- package/dist/cjs/lib/useIndex.js +1 -1
- package/dist/cjs/lib/useInstantSearchApi.js +4 -5
- package/dist/cjs/lib/useSearchResults.js +4 -4
- package/dist/cjs/lib/useSearchState.js +4 -4
- package/dist/cjs/lib/useStableValue.js +4 -4
- package/dist/cjs/server/getServerState.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/es/components/Configure.js +2 -2
- package/dist/es/components/DynamicWidgets.js +2 -2
- package/dist/es/components/Index.js +2 -2
- package/dist/es/components/InstantSearch.js +2 -2
- package/dist/es/components/InstantSearchSSRProvider.js +4 -4
- package/dist/es/connectors/useAutocomplete.d.ts +4 -0
- package/dist/es/connectors/useAutocomplete.js +5 -0
- package/dist/es/connectors/useChat.d.ts +49 -1
- package/dist/es/connectors/useChat.js +101 -12
- package/dist/es/connectors/useDynamicWidgets.js +2 -2
- package/dist/es/hooks/useConnector.js +8 -8
- package/dist/es/index.d.ts +1 -0
- package/dist/es/index.js +1 -0
- package/dist/es/index.umd.d.ts +1 -0
- package/dist/es/index.umd.js +1 -0
- package/dist/es/lib/getIndexSearchResults.js +2 -2
- package/dist/es/lib/useForceUpdate.js +4 -4
- package/dist/es/lib/useInstantSearchApi.js +2 -2
- package/dist/es/lib/useSearchResults.js +4 -4
- package/dist/es/lib/useSearchState.js +4 -4
- package/dist/es/lib/useStableValue.js +4 -4
- package/dist/es/version.d.ts +1 -1
- package/dist/es/version.js +1 -1
- package/dist/umd/ReactInstantSearchCore.js +1636 -1834
- package/dist/umd/ReactInstantSearchCore.js.map +1 -1
- package/dist/umd/ReactInstantSearchCore.min.js +1 -1
- package/dist/umd/ReactInstantSearchCore.min.js.map +1 -1
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -85,6 +85,18 @@ Object.keys(_InstantSearchSSRProvider).forEach(function (key) {
|
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
|
+
var _useAutocomplete = require("./connectors/useAutocomplete");
|
|
89
|
+
Object.keys(_useAutocomplete).forEach(function (key) {
|
|
90
|
+
if (key === "default" || key === "__esModule") return;
|
|
91
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
92
|
+
if (key in exports && exports[key] === _useAutocomplete[key]) return;
|
|
93
|
+
Object.defineProperty(exports, key, {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
get: function get() {
|
|
96
|
+
return _useAutocomplete[key];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
88
100
|
var _useBreadcrumb = require("./connectors/useBreadcrumb");
|
|
89
101
|
Object.keys(_useBreadcrumb).forEach(function (key) {
|
|
90
102
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -493,4 +505,4 @@ Object.keys(_server).forEach(function (key) {
|
|
|
493
505
|
}
|
|
494
506
|
});
|
|
495
507
|
});
|
|
496
|
-
function _interopRequireDefault(
|
|
508
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
package/dist/cjs/index.umd.js
CHANGED
|
@@ -87,6 +87,18 @@ Object.keys(_InstantSearchSSRProvider).forEach(function (key) {
|
|
|
87
87
|
}
|
|
88
88
|
});
|
|
89
89
|
});
|
|
90
|
+
var _useAutocomplete = require("./connectors/useAutocomplete");
|
|
91
|
+
Object.keys(_useAutocomplete).forEach(function (key) {
|
|
92
|
+
if (key === "default" || key === "__esModule") return;
|
|
93
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
94
|
+
if (key in exports && exports[key] === _useAutocomplete[key]) return;
|
|
95
|
+
Object.defineProperty(exports, key, {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function get() {
|
|
98
|
+
return _useAutocomplete[key];
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
90
102
|
var _useBreadcrumb = require("./connectors/useBreadcrumb");
|
|
91
103
|
Object.keys(_useBreadcrumb).forEach(function (key) {
|
|
92
104
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -483,7 +495,7 @@ Object.keys(_server).forEach(function (key) {
|
|
|
483
495
|
}
|
|
484
496
|
});
|
|
485
497
|
});
|
|
486
|
-
function _interopRequireDefault(
|
|
498
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
487
499
|
var useChat = exports.useChat = function useChat() {
|
|
488
500
|
throw new Error("\"useChat()\" is not available from the UMD build.\n\nPlease use React InstantSearch with a packaging system:\nhttps://www.algolia.com/doc/guides/building-search-ui/installation/react/#install-react-instantsearch-as-an-npm-package");
|
|
489
501
|
};
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createSearchResults = createSearchResults;
|
|
7
7
|
var _algoliasearchHelper = _interopRequireDefault(require("algoliasearch-helper"));
|
|
8
|
-
function _interopRequireDefault(
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
function createSearchResults(state) {
|
|
10
10
|
var _state$query, _state$page, _state$hitsPerPage;
|
|
11
11
|
return new _algoliasearchHelper.default.SearchResults(state, [{
|
|
@@ -8,8 +8,8 @@ var _createSearchResults = require("./createSearchResults");
|
|
|
8
8
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
9
9
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
10
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
-
function _defineProperty(
|
|
12
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i :
|
|
11
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
13
13
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
14
|
function getIndexSearchResults(indexWidget) {
|
|
15
15
|
var helper = indexWidget.getHelper();
|
package/dist/cjs/lib/use.js
CHANGED
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.use = void 0;
|
|
8
8
|
var React = _interopRequireWildcard(require("react"));
|
|
9
|
-
function
|
|
10
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
11
10
|
var useKey = 'use';
|
|
12
11
|
|
|
13
12
|
// @TODO: Remove this file and import directly from React when available.
|
|
@@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useForceUpdate = useForceUpdate;
|
|
7
7
|
var _react = require("react");
|
|
8
|
-
function _slicedToArray(
|
|
8
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
9
9
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
-
function _unsupportedIterableToArray(
|
|
11
|
-
function _arrayLikeToArray(
|
|
10
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
11
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
12
12
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
13
|
-
function _arrayWithHoles(
|
|
13
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
14
14
|
/**
|
|
15
15
|
* Forces a React update that triggers a rerender.
|
|
16
16
|
* @link https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate
|
package/dist/cjs/lib/useIndex.js
CHANGED
|
@@ -13,7 +13,7 @@ var _useInstantSearchSSRContext = require("./useInstantSearchSSRContext");
|
|
|
13
13
|
var _useIsomorphicLayoutEffect = require("./useIsomorphicLayoutEffect");
|
|
14
14
|
var _useStableValue = require("./useStableValue");
|
|
15
15
|
var _useWidget = require("./useWidget");
|
|
16
|
-
function _interopRequireDefault(
|
|
16
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
17
|
function useIndex(props) {
|
|
18
18
|
var serverContext = (0, _useInstantSearchServerContext.useInstantSearchServerContext)();
|
|
19
19
|
var ssrContext = (0, _useInstantSearchSSRContext.useInstantSearchSSRContext)();
|
|
@@ -14,14 +14,13 @@ var _useInstantSearchServerContext = require("./useInstantSearchServerContext");
|
|
|
14
14
|
var _useInstantSearchSSRContext = require("./useInstantSearchSSRContext");
|
|
15
15
|
var _useRSCContext2 = require("./useRSCContext");
|
|
16
16
|
var _warn = require("./warn");
|
|
17
|
-
function _interopRequireDefault(
|
|
18
|
-
function
|
|
19
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
20
19
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
21
20
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
22
21
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
23
|
-
function _defineProperty(
|
|
24
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i :
|
|
22
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
23
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
25
24
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
26
25
|
var defaultUserAgents = ["react (".concat(_react.version, ")"), "react-instantsearch (".concat(_version.default, ")"), "react-instantsearch-core (".concat(_version.default, ")")];
|
|
27
26
|
var serverUserAgent = "react-instantsearch-server (".concat(_version.default, ")");
|
|
@@ -9,12 +9,12 @@ var _react = require("react");
|
|
|
9
9
|
var _getIndexSearchResults = require("./getIndexSearchResults");
|
|
10
10
|
var _useIndexContext = require("./useIndexContext");
|
|
11
11
|
var _useInstantSearchContext = require("./useInstantSearchContext");
|
|
12
|
-
function _slicedToArray(
|
|
12
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
13
13
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
-
function _unsupportedIterableToArray(
|
|
15
|
-
function _arrayLikeToArray(
|
|
14
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
15
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
16
16
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
17
|
-
function _arrayWithHoles(
|
|
17
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
18
18
|
function useSearchResults() {
|
|
19
19
|
var search = (0, _useInstantSearchContext.useInstantSearchContext)();
|
|
20
20
|
var searchIndex = (0, _useIndexContext.useIndexContext)();
|
|
@@ -7,12 +7,12 @@ exports.useSearchState = useSearchState;
|
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _useIndexContext = require("./useIndexContext");
|
|
9
9
|
var _useInstantSearchContext = require("./useInstantSearchContext");
|
|
10
|
-
function _slicedToArray(
|
|
10
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
11
11
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
-
function _unsupportedIterableToArray(
|
|
13
|
-
function _arrayLikeToArray(
|
|
12
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
13
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
14
14
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
15
|
-
function _arrayWithHoles(
|
|
15
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
16
16
|
function useSearchState() {
|
|
17
17
|
var search = (0, _useInstantSearchContext.useInstantSearchContext)();
|
|
18
18
|
var searchIndex = (0, _useIndexContext.useIndexContext)();
|
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useStableValue = useStableValue;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _dequal = require("./dequal");
|
|
9
|
-
function _slicedToArray(
|
|
9
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
10
10
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
-
function _unsupportedIterableToArray(
|
|
12
|
-
function _arrayLikeToArray(
|
|
11
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
12
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
13
13
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
14
|
-
function _arrayWithHoles(
|
|
14
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
15
15
|
function useStableValue(value) {
|
|
16
16
|
var _useState = (0, _react.useState)(function () {
|
|
17
17
|
return value;
|
|
@@ -9,7 +9,7 @@ var _utils = require("instantsearch.js/cjs/lib/utils");
|
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
10
|
var _InstantSearchServerContext = require("../components/InstantSearchServerContext");
|
|
11
11
|
var _InstantSearchSSRProvider = require("../components/InstantSearchSSRProvider");
|
|
12
|
-
function _interopRequireDefault(
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
13
|
/**
|
|
14
14
|
* Returns the InstantSearch server state from a component.
|
|
15
15
|
*/
|
package/dist/cjs/version.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
function _defineProperty(
|
|
5
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i :
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
import { useConfigure } from "../connectors/useConfigure.js";
|
|
8
8
|
export function Configure(props) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var _excluded = ["children", "fallbackComponent"];
|
|
2
2
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
|
-
function _objectWithoutProperties(
|
|
4
|
-
function _objectWithoutPropertiesLoose(
|
|
3
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
4
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
5
5
|
import React, { Fragment } from 'react';
|
|
6
6
|
import { useDynamicWidgets } from "../connectors/useDynamicWidgets.js";
|
|
7
7
|
import { invariant } from "../lib/invariant.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var _excluded = ["children"];
|
|
2
|
-
function _objectWithoutProperties(
|
|
3
|
-
function _objectWithoutPropertiesLoose(
|
|
2
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { IndexContext } from "../lib/IndexContext.js";
|
|
6
6
|
import { useIndex } from "../lib/useIndex.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var _excluded = ["children"];
|
|
2
|
-
function _objectWithoutProperties(
|
|
3
|
-
function _objectWithoutPropertiesLoose(
|
|
2
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
4
|
import React, { useEffect } from 'react';
|
|
5
5
|
import { IndexContext } from "../lib/IndexContext.js";
|
|
6
6
|
import { InstantSearchContext } from "../lib/InstantSearchContext.js";
|
|
@@ -2,11 +2,11 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
2
2
|
var _excluded = ["children"];
|
|
3
3
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
-
function _defineProperty(
|
|
6
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i :
|
|
5
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
7
7
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
-
function _objectWithoutProperties(
|
|
9
|
-
function _objectWithoutPropertiesLoose(
|
|
8
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
9
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
10
10
|
import React from 'react';
|
|
11
11
|
import { InstantSearchSSRContext } from "../lib/InstantSearchSSRContext.js";
|
|
12
12
|
/**
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AdditionalWidgetProperties } from '../hooks/useConnector';
|
|
2
|
+
import type { AutocompleteConnectorParams } from 'instantsearch.js/es/connectors/autocomplete/connectAutocomplete';
|
|
3
|
+
export type UseAutocompleteProps = AutocompleteConnectorParams;
|
|
4
|
+
export declare function useAutocomplete(props?: UseAutocompleteProps, additionalWidgetProperties?: AdditionalWidgetProperties): import("instantsearch.js/es/connectors/autocomplete/connectAutocomplete").AutocompleteRenderState;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import connectAutocomplete from "instantsearch.js/es/connectors/autocomplete/connectAutocomplete.js";
|
|
2
|
+
import { useConnector } from "../hooks/useConnector.js";
|
|
3
|
+
export function useAutocomplete(props, additionalWidgetProperties) {
|
|
4
|
+
return useConnector(connectAutocomplete, props, additionalWidgetProperties);
|
|
5
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DefaultChatTransport } from 'ai';
|
|
2
2
|
import { Chat } from 'instantsearch.js/es/lib/chat';
|
|
3
|
+
import type { UserClientSideTools, ClientSideTools } from 'instantsearch-ui-components';
|
|
3
4
|
import type { AbstractChat, ChatInit as ChatInitAi, UIMessage } from 'instantsearch.js/es/lib/chat';
|
|
4
5
|
export type UseChatHelpers<TUiMessage extends UIMessage> = {
|
|
5
6
|
/**
|
|
@@ -12,6 +13,41 @@ export type UseChatHelpers<TUiMessage extends UIMessage> = {
|
|
|
12
13
|
* manually to regenerate the AI response.
|
|
13
14
|
*/
|
|
14
15
|
setMessages: (messages: TUiMessage[] | ((m: TUiMessage[]) => TUiMessage[])) => void;
|
|
16
|
+
/**
|
|
17
|
+
* The current input value.
|
|
18
|
+
*/
|
|
19
|
+
input: string;
|
|
20
|
+
/**
|
|
21
|
+
* Update the input value.
|
|
22
|
+
*/
|
|
23
|
+
setInput: (input: string) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Whether the chat is currently open.
|
|
26
|
+
*/
|
|
27
|
+
open: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Update the open state.
|
|
30
|
+
*/
|
|
31
|
+
setOpen: (open: boolean) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Whether the chat is in the process of clearing messages.
|
|
34
|
+
*/
|
|
35
|
+
isClearing: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Clear all messages.
|
|
38
|
+
*/
|
|
39
|
+
clearMessages: () => void;
|
|
40
|
+
/**
|
|
41
|
+
* Callback to be called when the clear transition ends.
|
|
42
|
+
*/
|
|
43
|
+
onClearTransitionEnd: () => void;
|
|
44
|
+
/**
|
|
45
|
+
* Tools with addToolResult injected, ready to be used by the UI.
|
|
46
|
+
*/
|
|
47
|
+
tools: ClientSideTools;
|
|
48
|
+
/**
|
|
49
|
+
* The current error.
|
|
50
|
+
*/
|
|
15
51
|
error: Error | undefined;
|
|
16
52
|
} & Pick<AbstractChat<TUiMessage>, 'sendMessage' | 'regenerate' | 'stop' | 'resumeStream' | 'addToolResult' | 'status' | 'messages' | 'clearError'>;
|
|
17
53
|
export type ChatInitWithoutTransport<TUiMessage extends UIMessage> = Omit<ChatInitAi<TUiMessage>, 'transport'>;
|
|
@@ -27,5 +63,17 @@ export type UseChatOptions<TUiMessage extends UIMessage> = ({
|
|
|
27
63
|
* Whether to resume an ongoing chat generation stream.
|
|
28
64
|
*/
|
|
29
65
|
resume?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Initial value for the input field.
|
|
68
|
+
*/
|
|
69
|
+
initialInput?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Whether the chat should be open by default.
|
|
72
|
+
*/
|
|
73
|
+
defaultOpen?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Custom tools to be used in the chat.
|
|
76
|
+
*/
|
|
77
|
+
tools?: UserClientSideTools;
|
|
30
78
|
};
|
|
31
|
-
export declare function useChat<TUiMessage extends UIMessage = UIMessage>({ resume, ...options }?: UseChatOptions<TUiMessage>): UseChatHelpers<TUiMessage>;
|
|
79
|
+
export declare function useChat<TUiMessage extends UIMessage = UIMessage>({ resume, initialInput, defaultOpen, tools, ...options }?: UseChatOptions<TUiMessage>): UseChatHelpers<TUiMessage>;
|
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
var _excluded = ["resume"];
|
|
2
|
+
var _excluded = ["resume", "initialInput", "defaultOpen", "tools"];
|
|
3
3
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
-
function _defineProperty(
|
|
6
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i :
|
|
5
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
7
7
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
-
function _slicedToArray(
|
|
8
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
9
9
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
-
function _unsupportedIterableToArray(
|
|
11
|
-
function _arrayLikeToArray(
|
|
10
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
11
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
12
12
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
13
|
-
function _arrayWithHoles(
|
|
14
|
-
function _objectWithoutProperties(
|
|
15
|
-
function _objectWithoutPropertiesLoose(
|
|
13
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
14
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
15
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
16
16
|
import { DefaultChatTransport } from 'ai';
|
|
17
17
|
import { Chat } from "instantsearch.js/es/lib/chat/index.js";
|
|
18
|
-
import { useCallback, useEffect, useMemo, useRef, useSyncExternalStore } from 'react';
|
|
18
|
+
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
19
19
|
import { useAppIdAndApiKey } from "../lib/useAppIdAndApiKey.js";
|
|
20
20
|
import { warn } from "../lib/warn.js";
|
|
21
21
|
export function useChat() {
|
|
22
22
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
23
23
|
_ref$resume = _ref.resume,
|
|
24
24
|
resume = _ref$resume === void 0 ? false : _ref$resume,
|
|
25
|
+
_ref$initialInput = _ref.initialInput,
|
|
26
|
+
initialInput = _ref$initialInput === void 0 ? '' : _ref$initialInput,
|
|
27
|
+
_ref$defaultOpen = _ref.defaultOpen,
|
|
28
|
+
defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
|
|
29
|
+
_ref$tools = _ref.tools,
|
|
30
|
+
tools = _ref$tools === void 0 ? {} : _ref$tools,
|
|
25
31
|
options = _objectWithoutProperties(_ref, _excluded);
|
|
26
32
|
process.env.NODE_ENV === 'development' ? warn(false, 'Chat is not yet stable and will change in the future.') : void 0;
|
|
27
33
|
process.env.NODE_ENV === 'development' ? warn(!('agentId' in options && 'transport' in options), "`useChat` with `agentId` and `transport` can't be used together. The `transport` option will be used.") : void 0;
|
|
@@ -29,6 +35,18 @@ export function useChat() {
|
|
|
29
35
|
_useAppIdAndApiKey2 = _slicedToArray(_useAppIdAndApiKey, 2),
|
|
30
36
|
appId = _useAppIdAndApiKey2[0],
|
|
31
37
|
apiKey = _useAppIdAndApiKey2[1];
|
|
38
|
+
var _useState = useState(initialInput),
|
|
39
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
40
|
+
input = _useState2[0],
|
|
41
|
+
setInput = _useState2[1];
|
|
42
|
+
var _useState3 = useState(defaultOpen),
|
|
43
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
44
|
+
open = _useState4[0],
|
|
45
|
+
setOpen = _useState4[1];
|
|
46
|
+
var _useState5 = useState(false),
|
|
47
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
48
|
+
isClearing = _useState6[0],
|
|
49
|
+
setIsClearing = _useState6[1];
|
|
32
50
|
var transport = useMemo(function () {
|
|
33
51
|
if ('transport' in options && options.transport) {
|
|
34
52
|
return new DefaultChatTransport(options.transport);
|
|
@@ -56,10 +74,52 @@ export function useChat() {
|
|
|
56
74
|
transport: transport
|
|
57
75
|
});
|
|
58
76
|
}, [options, transport]);
|
|
59
|
-
var
|
|
77
|
+
var createChatInstance = useCallback(function () {
|
|
78
|
+
if ('chat' in optionsWithTransport) {
|
|
79
|
+
return optionsWithTransport.chat;
|
|
80
|
+
}
|
|
81
|
+
var chatInstanceRef = {
|
|
82
|
+
current: null
|
|
83
|
+
};
|
|
84
|
+
var onToolCall = function onToolCall(_ref2) {
|
|
85
|
+
var toolCall = _ref2.toolCall;
|
|
86
|
+
var tool = tools[toolCall.toolName];
|
|
87
|
+
var chatInstance = chatInstanceRef.current;
|
|
88
|
+
if (!tool) {
|
|
89
|
+
if (process.env.NODE_ENV === 'development') {
|
|
90
|
+
throw new Error("No tool implementation found for \"".concat(toolCall.toolName, "\". Please provide a tool implementation in the `tools` prop."));
|
|
91
|
+
}
|
|
92
|
+
chatInstance.addToolResult({
|
|
93
|
+
output: "No tool implemented for \"".concat(toolCall.toolName, "\"."),
|
|
94
|
+
tool: toolCall.toolName,
|
|
95
|
+
toolCallId: toolCall.toolCallId
|
|
96
|
+
});
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (tool.onToolCall) {
|
|
100
|
+
var scopedAddToolResult = function scopedAddToolResult(_ref3) {
|
|
101
|
+
var output = _ref3.output;
|
|
102
|
+
return chatInstance.addToolResult({
|
|
103
|
+
output: output,
|
|
104
|
+
tool: toolCall.toolName,
|
|
105
|
+
toolCallId: toolCall.toolCallId
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
tool.onToolCall(_objectSpread(_objectSpread({}, toolCall), {}, {
|
|
109
|
+
addToolResult: scopedAddToolResult
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
var chatInstance = new Chat(_objectSpread(_objectSpread({}, optionsWithTransport), {}, {
|
|
114
|
+
onToolCall: onToolCall
|
|
115
|
+
}));
|
|
116
|
+
chatInstanceRef.current = chatInstance;
|
|
117
|
+
return chatInstance;
|
|
118
|
+
}, [optionsWithTransport, tools]);
|
|
119
|
+
var chatRef = useRef(createChatInstance());
|
|
60
120
|
var shouldRecreateChat = 'chat' in optionsWithTransport && optionsWithTransport.chat !== chatRef.current || 'id' in optionsWithTransport && chatRef.current.id !== optionsWithTransport.id;
|
|
61
121
|
if (shouldRecreateChat) {
|
|
62
|
-
chatRef.current =
|
|
122
|
+
chatRef.current = createChatInstance();
|
|
63
123
|
}
|
|
64
124
|
var optionsId = 'id' in optionsWithTransport ? optionsWithTransport.id : null;
|
|
65
125
|
var subscribeToMessages = useCallback(function (update) {
|
|
@@ -89,6 +149,27 @@ export function useChat() {
|
|
|
89
149
|
}
|
|
90
150
|
chatRef.current.messages = messagesParam;
|
|
91
151
|
}, [chatRef]);
|
|
152
|
+
var clearMessages = useCallback(function () {
|
|
153
|
+
if (!messages || messages.length === 0) return;
|
|
154
|
+
setIsClearing(true);
|
|
155
|
+
}, [messages]);
|
|
156
|
+
var onClearTransitionEnd = useCallback(function () {
|
|
157
|
+
setMessages([]);
|
|
158
|
+
chatRef.current.clearError();
|
|
159
|
+
setIsClearing(false);
|
|
160
|
+
}, [setMessages, chatRef]);
|
|
161
|
+
var toolsWithAddToolResult = useMemo(function () {
|
|
162
|
+
var result = {};
|
|
163
|
+
Object.entries(tools).forEach(function (_ref4) {
|
|
164
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
165
|
+
key = _ref5[0],
|
|
166
|
+
tool = _ref5[1];
|
|
167
|
+
result[key] = _objectSpread(_objectSpread({}, tool), {}, {
|
|
168
|
+
addToolResult: chatRef.current.addToolResult
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
return result;
|
|
172
|
+
}, [tools]);
|
|
92
173
|
useEffect(function () {
|
|
93
174
|
if (resume) {
|
|
94
175
|
chatRef.current.resumeStream();
|
|
@@ -98,6 +179,14 @@ export function useChat() {
|
|
|
98
179
|
id: chatRef.current.id,
|
|
99
180
|
messages: messages,
|
|
100
181
|
setMessages: setMessages,
|
|
182
|
+
input: input,
|
|
183
|
+
setInput: setInput,
|
|
184
|
+
open: open,
|
|
185
|
+
setOpen: setOpen,
|
|
186
|
+
isClearing: isClearing,
|
|
187
|
+
clearMessages: clearMessages,
|
|
188
|
+
onClearTransitionEnd: onClearTransitionEnd,
|
|
189
|
+
tools: toolsWithAddToolResult,
|
|
101
190
|
sendMessage: chatRef.current.sendMessage,
|
|
102
191
|
regenerate: chatRef.current.regenerate,
|
|
103
192
|
clearError: chatRef.current.clearError,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
function _defineProperty(
|
|
5
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i :
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
import connectDynamicWidgets from "instantsearch.js/es/connectors/dynamic-widgets/connectDynamicWidgets.js";
|
|
8
8
|
import { useConnector } from "../hooks/useConnector.js";
|