react-instantsearch-core 7.16.3 → 7.17.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.
@@ -0,0 +1,110 @@
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"];
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
+ 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(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
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(arr) { if (Array.isArray(arr)) return arr; }
14
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
15
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
16
+ import { DefaultChatTransport } from 'ai';
17
+ import { Chat } from "instantsearch.js/es/lib/chat/index.js";
18
+ import { useCallback, useEffect, useMemo, useRef, useSyncExternalStore } from 'react';
19
+ import { useAppIdAndApiKey } from "../lib/useAppIdAndApiKey.js";
20
+ import { warn } from "../lib/warn.js";
21
+ export function useChat() {
22
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
23
+ _ref$resume = _ref.resume,
24
+ resume = _ref$resume === void 0 ? false : _ref$resume,
25
+ options = _objectWithoutProperties(_ref, _excluded);
26
+ process.env.NODE_ENV === 'development' ? warn(false, 'Chat is not yet stable and will change in the future.') : void 0;
27
+ 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;
28
+ var _useAppIdAndApiKey = useAppIdAndApiKey(),
29
+ _useAppIdAndApiKey2 = _slicedToArray(_useAppIdAndApiKey, 2),
30
+ appId = _useAppIdAndApiKey2[0],
31
+ apiKey = _useAppIdAndApiKey2[1];
32
+ var transport = useMemo(function () {
33
+ if ('transport' in options && options.transport) {
34
+ return new DefaultChatTransport(options.transport);
35
+ }
36
+ if ('agentId' in options && options.agentId) {
37
+ var agentId = options.agentId;
38
+ if (!appId || !apiKey) {
39
+ throw new Error('The `useChat` hook requires an `appId` and `apiKey` to be set on the `InstantSearch` component when using the `agentId` option.');
40
+ }
41
+ return new DefaultChatTransport({
42
+ api: "https://".concat(appId, ".algolia.net/agent-studio/1/agents/").concat(agentId, "/completions?compatibilityMode=ai-sdk-5"),
43
+ headers: {
44
+ 'x-algolia-application-id': appId,
45
+ 'x-algolia-api-Key': apiKey
46
+ }
47
+ });
48
+ }
49
+ throw new Error('You need to provide either an `agentId` or a `transport`.');
50
+ }, [apiKey, appId, options]);
51
+ var optionsWithTransport = useMemo(function () {
52
+ if ('chat' in options) {
53
+ return options;
54
+ }
55
+ return _objectSpread(_objectSpread({}, options), {}, {
56
+ transport: transport
57
+ });
58
+ }, [options, transport]);
59
+ var chatRef = useRef('chat' in optionsWithTransport ? optionsWithTransport.chat : new Chat(optionsWithTransport));
60
+ var shouldRecreateChat = 'chat' in optionsWithTransport && optionsWithTransport.chat !== chatRef.current || 'id' in optionsWithTransport && chatRef.current.id !== optionsWithTransport.id;
61
+ if (shouldRecreateChat) {
62
+ chatRef.current = 'chat' in optionsWithTransport ? optionsWithTransport.chat : new Chat(optionsWithTransport);
63
+ }
64
+ var optionsId = 'id' in optionsWithTransport ? optionsWithTransport.id : null;
65
+ var subscribeToMessages = useCallback(function (update) {
66
+ return chatRef.current['~registerMessagesCallback'](update);
67
+ },
68
+ // optionsId is required to trigger re-subscription when the chat ID changes
69
+ // eslint-disable-next-line react-hooks/exhaustive-deps
70
+ [optionsId]);
71
+ var messages = useSyncExternalStore(subscribeToMessages, function () {
72
+ return chatRef.current.messages;
73
+ }, function () {
74
+ return chatRef.current.messages;
75
+ });
76
+ var status = useSyncExternalStore(chatRef.current['~registerStatusCallback'], function () {
77
+ return chatRef.current.status;
78
+ }, function () {
79
+ return chatRef.current.status;
80
+ });
81
+ var error = useSyncExternalStore(chatRef.current['~registerErrorCallback'], function () {
82
+ return chatRef.current.error;
83
+ }, function () {
84
+ return chatRef.current.error;
85
+ });
86
+ var setMessages = useCallback(function (messagesParam) {
87
+ if (typeof messagesParam === 'function') {
88
+ messagesParam = messagesParam(chatRef.current.messages);
89
+ }
90
+ chatRef.current.messages = messagesParam;
91
+ }, [chatRef]);
92
+ useEffect(function () {
93
+ if (resume) {
94
+ chatRef.current.resumeStream();
95
+ }
96
+ }, [resume, chatRef]);
97
+ return {
98
+ id: chatRef.current.id,
99
+ messages: messages,
100
+ setMessages: setMessages,
101
+ sendMessage: chatRef.current.sendMessage,
102
+ regenerate: chatRef.current.regenerate,
103
+ clearError: chatRef.current.clearError,
104
+ stop: chatRef.current.stop,
105
+ error: error,
106
+ resumeStream: chatRef.current.resumeStream,
107
+ status: status,
108
+ addToolResult: chatRef.current.addToolResult
109
+ };
110
+ }
@@ -6,6 +6,7 @@ export * from './components/InstantSearch';
6
6
  export * from './components/InstantSearchServerContext';
7
7
  export * from './components/InstantSearchSSRProvider';
8
8
  export * from './connectors/useBreadcrumb';
9
+ export * from './connectors/useChat';
9
10
  export * from './connectors/useClearRefinements';
10
11
  export * from './connectors/useConfigure';
11
12
  export * from './connectors/useCurrentRefinements';
package/dist/es/index.js CHANGED
@@ -6,6 +6,7 @@ export * from "./components/InstantSearch.js";
6
6
  export * from "./components/InstantSearchServerContext.js";
7
7
  export * from "./components/InstantSearchSSRProvider.js";
8
8
  export * from "./connectors/useBreadcrumb.js";
9
+ export * from "./connectors/useChat.js";
9
10
  export * from "./connectors/useClearRefinements.js";
10
11
  export * from "./connectors/useConfigure.js";
11
12
  export * from "./connectors/useCurrentRefinements.js";
@@ -0,0 +1,41 @@
1
+ export { default as version } from './version';
2
+ export * from './components/Configure';
3
+ export * from './components/DynamicWidgets';
4
+ export * from './components/Index';
5
+ export * from './components/InstantSearch';
6
+ export * from './components/InstantSearchServerContext';
7
+ export * from './components/InstantSearchSSRProvider';
8
+ export * from './connectors/useBreadcrumb';
9
+ export declare const useChat: () => never;
10
+ export * from './connectors/useClearRefinements';
11
+ export * from './connectors/useConfigure';
12
+ export * from './connectors/useCurrentRefinements';
13
+ export * from './connectors/useDynamicWidgets';
14
+ export * from './connectors/useFrequentlyBoughtTogether';
15
+ export * from './connectors/useGeoSearch';
16
+ export * from './connectors/useHierarchicalMenu';
17
+ export * from './connectors/useHits';
18
+ export * from './connectors/useHitsPerPage';
19
+ export * from './connectors/useInfiniteHits';
20
+ export * from './connectors/useMenu';
21
+ export * from './connectors/useNumericMenu';
22
+ export * from './connectors/usePagination';
23
+ export * from './connectors/usePoweredBy';
24
+ export * from './connectors/useQueryRules';
25
+ export * from './connectors/useRange';
26
+ export * from './connectors/useRefinementList';
27
+ export * from './connectors/useRelatedProducts';
28
+ export * from './connectors/useSearchBox';
29
+ export * from './connectors/useSortBy';
30
+ export * from './connectors/useStats';
31
+ export * from './connectors/useToggleRefinement';
32
+ export * from './connectors/useTrendingItems';
33
+ export * from './connectors/useLookingSimilar';
34
+ export * from './hooks/useConnector';
35
+ export * from './hooks/useInstantSearch';
36
+ export * from './lib/wrapPromiseWithState';
37
+ export * from './lib/useInstantSearchContext';
38
+ export * from './lib/useRSCContext';
39
+ export * from './lib/InstantSearchRSCContext';
40
+ export * from './lib/InstantSearchSSRContext';
41
+ export * from './server';
@@ -0,0 +1,43 @@
1
+ export { default as version } from "./version.js";
2
+ export * from "./components/Configure.js";
3
+ export * from "./components/DynamicWidgets.js";
4
+ export * from "./components/Index.js";
5
+ export * from "./components/InstantSearch.js";
6
+ export * from "./components/InstantSearchServerContext.js";
7
+ export * from "./components/InstantSearchSSRProvider.js";
8
+ export * from "./connectors/useBreadcrumb.js";
9
+ export var useChat = function useChat() {
10
+ 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");
11
+ };
12
+ export * from "./connectors/useClearRefinements.js";
13
+ export * from "./connectors/useConfigure.js";
14
+ export * from "./connectors/useCurrentRefinements.js";
15
+ export * from "./connectors/useDynamicWidgets.js";
16
+ export * from "./connectors/useFrequentlyBoughtTogether.js";
17
+ export * from "./connectors/useGeoSearch.js";
18
+ export * from "./connectors/useHierarchicalMenu.js";
19
+ export * from "./connectors/useHits.js";
20
+ export * from "./connectors/useHitsPerPage.js";
21
+ export * from "./connectors/useInfiniteHits.js";
22
+ export * from "./connectors/useMenu.js";
23
+ export * from "./connectors/useNumericMenu.js";
24
+ export * from "./connectors/usePagination.js";
25
+ export * from "./connectors/usePoweredBy.js";
26
+ export * from "./connectors/useQueryRules.js";
27
+ export * from "./connectors/useRange.js";
28
+ export * from "./connectors/useRefinementList.js";
29
+ export * from "./connectors/useRelatedProducts.js";
30
+ export * from "./connectors/useSearchBox.js";
31
+ export * from "./connectors/useSortBy.js";
32
+ export * from "./connectors/useStats.js";
33
+ export * from "./connectors/useToggleRefinement.js";
34
+ export * from "./connectors/useTrendingItems.js";
35
+ export * from "./connectors/useLookingSimilar.js";
36
+ export * from "./hooks/useConnector.js";
37
+ export * from "./hooks/useInstantSearch.js";
38
+ export * from "./lib/wrapPromiseWithState.js";
39
+ export * from "./lib/useInstantSearchContext.js";
40
+ export * from "./lib/useRSCContext.js";
41
+ export * from "./lib/InstantSearchRSCContext.js";
42
+ export * from "./lib/InstantSearchSSRContext.js";
43
+ export * from "./server/index.js";
@@ -0,0 +1 @@
1
+ export declare const useAppIdAndApiKey: () => [appId: string, apiKey: string] | [appId: undefined, apiKey: undefined];
@@ -0,0 +1,7 @@
1
+ import { getAppIdAndApiKey } from "instantsearch.js/es/lib/utils/index.js";
2
+ import { useInstantSearchContext } from "./useInstantSearchContext.js";
3
+ export var useAppIdAndApiKey = function useAppIdAndApiKey() {
4
+ var _useInstantSearchCont = useInstantSearchContext(),
5
+ client = _useInstantSearchCont.client;
6
+ return getAppIdAndApiKey(client);
7
+ };
@@ -1,2 +1,2 @@
1
- declare const _default: "7.16.3";
1
+ declare const _default: "7.17.0";
2
2
  export default _default;
@@ -1 +1 @@
1
- export default '7.16.3';
1
+ export default '7.17.0';
@@ -7,7 +7,7 @@
7
7
 
8
8
  var React__default = 'default' in React ? React['default'] : React;
9
9
 
10
- var version = '7.16.3';
10
+ var version = '7.17.0';
11
11
 
12
12
  function _iterableToArrayLimit(r, l) {
13
13
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
@@ -10512,7 +10512,9 @@
10512
10512
  // This makes sure `render` is never called with `results` being `null`.
10513
10513
  // If it's an isolated index without an index name, we render all widgets,
10514
10514
  // as there are no results to display for the isolated index itself.
10515
- var widgetsToRender = this.getResults() || (_derivedHelper2 = derivedHelper) !== null && _derivedHelper2 !== void 0 && _derivedHelper2.lastRecommendResults || isolated && !indexName ? localWidgets : localWidgets.filter(isIndexWidget);
10515
+ var widgetsToRender = this.getResults() || (_derivedHelper2 = derivedHelper) !== null && _derivedHelper2 !== void 0 && _derivedHelper2.lastRecommendResults || isolated && !indexName ? localWidgets : localWidgets.filter(function (widget) {
10516
+ return widget.shouldRender;
10517
+ });
10516
10518
  widgetsToRender = widgetsToRender.filter(function (widget) {
10517
10519
  if (!widget.shouldRender) {
10518
10520
  return true;
@@ -10588,6 +10590,9 @@
10588
10590
  initialSearchParameters: searchParameters
10589
10591
  });
10590
10592
  },
10593
+ shouldRender: function shouldRender() {
10594
+ return true;
10595
+ },
10591
10596
  refreshUiState: function refreshUiState() {
10592
10597
  localUiState = getLocalWidgetsUiState(localWidgets, {
10593
10598
  searchParameters: this.getHelper().state,
@@ -12961,7 +12966,7 @@
12961
12966
  };
12962
12967
  }
12963
12968
 
12964
- var version$2 = '4.80.0';
12969
+ var version$2 = '4.81.0';
12965
12970
 
12966
12971
  function _typeof$l(o) {
12967
12972
  "@babel/helpers - typeof";
@@ -20108,6 +20113,10 @@
20108
20113
  });
20109
20114
  }
20110
20115
 
20116
+ var useChat = function useChat() {
20117
+ 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");
20118
+ };
20119
+
20111
20120
  exports.Configure = Configure;
20112
20121
  exports.DynamicWidgets = DynamicWidgets;
20113
20122
  exports.Index = Index;
@@ -20118,6 +20127,7 @@
20118
20127
  exports.InstantSearchServerContext = InstantSearchServerContext;
20119
20128
  exports.getServerState = getServerState;
20120
20129
  exports.useBreadcrumb = useBreadcrumb;
20130
+ exports.useChat = useChat;
20121
20131
  exports.useClearRefinements = useClearRefinements;
20122
20132
  exports.useConfigure = useConfigure;
20123
20133
  exports.useConnector = useConnector;