instantsearch.js 4.82.0 → 4.83.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.
@@ -3,7 +3,7 @@ import { Chat } from '../../lib/chat';
3
3
  import type { AbstractChat, ChatInit as ChatInitAi, UIMessage } from '../../lib/chat';
4
4
  import type { SendEventForHits } from '../../lib/utils';
5
5
  import type { Connector, Renderer, Unmounter, UnknownWidgetParams, IndexUiState, IndexWidget } from '../../types';
6
- import type { UserClientSideTool } from 'instantsearch-ui-components';
6
+ import type { UserClientSideTool, ClientSideTools } from 'instantsearch-ui-components';
7
7
  export type ChatRenderState<TUiMessage extends UIMessage = UIMessage> = {
8
8
  indexUiState: IndexUiState;
9
9
  input: string;
@@ -34,9 +34,9 @@ export type ChatRenderState<TUiMessage extends UIMessage = UIMessage> = {
34
34
  */
35
35
  onClearTransitionEnd: () => void;
36
36
  /**
37
- * Tools configuration passed to the connector.
37
+ * Tools configuration with addToolResult bound, ready to be used by the UI.
38
38
  */
39
- tools: Record<string, Omit<UserClientSideTool, 'layoutComponent'>>;
39
+ tools: ClientSideTools;
40
40
  } & Pick<AbstractChat<TUiMessage>, 'addToolResult' | 'clearError' | 'error' | 'id' | 'messages' | 'regenerate' | 'resumeStream' | 'sendMessage' | 'status' | 'stop'>;
41
41
  export type ChatInitWithoutTransport<TUiMessage extends UIMessage> = Omit<ChatInitAi<TUiMessage>, 'transport'>;
42
42
  export type ChatTransport = {
@@ -389,7 +389,7 @@ declare const _default: <TWidgetParams extends UnknownWidgetParams>(renderFn: Re
389
389
  isClearing: boolean;
390
390
  clearMessages: () => void;
391
391
  onClearTransitionEnd: () => void;
392
- tools: Record<string, Omit<UserClientSideTool, "layoutComponent">>;
392
+ tools: ClientSideTools;
393
393
  widgetParams: TWidgetParams & ChatConnectorParams<TUiMessage>;
394
394
  addToolResult: <TOOL extends keyof (TUiMessage extends UIMessage<unknown, import("ai").UIDataTypes, infer TOOLS extends import("ai").UITools> ? TOOLS : import("ai").UITools)>({ tool, toolCallId, output, }: {
395
395
  tool: TOOL;
@@ -174,6 +174,16 @@ export default (function connectChat(renderFn) {
174
174
  widgetType: this.$$type
175
175
  });
176
176
  }
177
+ var toolsWithAddToolResult = {};
178
+ Object.entries(tools).forEach(function (_ref4) {
179
+ var _ref5 = _slicedToArray(_ref4, 2),
180
+ key = _ref5[0],
181
+ tool = _ref5[1];
182
+ var toolWithAddToolResult = _objectSpread(_objectSpread({}, tool), {}, {
183
+ addToolResult: _chatInstance.addToolResult
184
+ });
185
+ toolsWithAddToolResult[key] = toolWithAddToolResult;
186
+ });
177
187
  return {
178
188
  indexUiState: instantSearchInstance.getUiState()[parent.getIndexId()],
179
189
  input: input,
@@ -186,7 +196,7 @@ export default (function connectChat(renderFn) {
186
196
  isClearing: isClearing,
187
197
  clearMessages: clearMessages,
188
198
  onClearTransitionEnd: onClearTransitionEnd,
189
- tools: tools,
199
+ tools: toolsWithAddToolResult,
190
200
  widgetParams: widgetParams,
191
201
  // Chat instance render state
192
202
  addToolResult: _chatInstance.addToolResult,
@@ -1,2 +1,2 @@
1
- declare const _default: "4.82.0";
1
+ declare const _default: "4.83.0";
2
2
  export default _default;
package/es/lib/version.js CHANGED
@@ -1 +1 @@
1
- export default '4.82.0';
1
+ export default '4.83.0';
@@ -37,6 +37,24 @@ type AutocompleteWidgetParams<TItem extends BaseHit> = {
37
37
  showSuggestions?: Partial<Pick<IndexConfig<{
38
38
  query: string;
39
39
  }>, 'indexName' | 'getURL' | 'templates' | 'cssClasses'>>;
40
+ showRecent?: boolean | {
41
+ /**
42
+ * Storage key to use in the local storage.
43
+ */
44
+ storageKey?: string;
45
+ templates?: Partial<{
46
+ /**
47
+ * Template to use for each result. This template will receive an object containing a single record.
48
+ */
49
+ item: Template<{
50
+ item: {
51
+ query: string;
52
+ };
53
+ onSelect: () => void;
54
+ onRemoveRecentSearch: () => void;
55
+ }>;
56
+ }>;
57
+ };
40
58
  getSearchPageURL?: (nextUiState: IndexUiState) => string;
41
59
  onSelect?: AutocompleteIndexConfig<TItem>['onSelect'];
42
60
  /**
@@ -1,4 +1,3 @@
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
1
  var _excluded = ["instanceId", "containerNode"];
3
2
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
4
3
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -6,6 +5,7 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
6
5
  function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
7
6
  function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
8
7
  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; }
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
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; }
@@ -14,7 +14,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
14
14
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
15
15
  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; }
16
16
  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; }
17
- import { createAutocompleteComponent, createAutocompleteIndexComponent, createAutocompletePanelComponent, createAutocompletePropGetters, createAutocompleteSearchComponent, createAutocompleteSuggestionComponent, cx } from 'instantsearch-ui-components';
17
+ import { createAutocompleteComponent, createAutocompleteIndexComponent, createAutocompletePanelComponent, createAutocompletePropGetters, createAutocompleteRecentSearchComponent, createAutocompleteSearchComponent, createAutocompleteStorage, createAutocompleteSuggestionComponent, cx } from 'instantsearch-ui-components';
18
18
  import { Fragment, h, render } from 'preact';
19
19
  import { useEffect, useId, useMemo, useRef, useState } from 'preact/hooks';
20
20
  import TemplateComponent from "../../components/Template/Template.js";
@@ -49,6 +49,10 @@ var AutocompleteSearchBox = createAutocompleteSearchComponent({
49
49
  createElement: h,
50
50
  Fragment: Fragment
51
51
  });
52
+ var AutocompleteRecentSearch = createAutocompleteRecentSearchComponent({
53
+ createElement: h,
54
+ Fragment: Fragment
55
+ });
52
56
  var usePropGetters = createAutocompletePropGetters({
53
57
  useEffect: useEffect,
54
58
  useId: useId,
@@ -56,12 +60,18 @@ var usePropGetters = createAutocompletePropGetters({
56
60
  useRef: useRef,
57
61
  useState: useState
58
62
  });
63
+ var useStorage = createAutocompleteStorage({
64
+ useEffect: useEffect,
65
+ useState: useState,
66
+ useMemo: useMemo
67
+ });
59
68
  var createRenderer = function createRenderer(params) {
60
69
  var instanceId = params.instanceId,
61
70
  containerNode = params.containerNode,
62
71
  rendererParams = _objectWithoutProperties(params, _excluded);
63
72
  return function (connectorParams, isFirstRendering) {
64
73
  if (isFirstRendering) {
74
+ var _targetIndex$getHelpe, _targetIndex$getHelpe2;
65
75
  var isolatedIndex = connectorParams.instantSearchInstance.mainIndex;
66
76
  var targetIndex = connectorParams.instantSearchInstance.mainIndex;
67
77
  walkIndex(targetIndex, function (childIndex) {
@@ -75,13 +85,14 @@ var createRenderer = function createRenderer(params) {
75
85
  isolatedIndex: isolatedIndex,
76
86
  targetIndex: targetIndex
77
87
  };
88
+ connectorParams.refine((_targetIndex$getHelpe = (_targetIndex$getHelpe2 = targetIndex.getHelper()) === null || _targetIndex$getHelpe2 === void 0 ? void 0 : _targetIndex$getHelpe2.state.query) !== null && _targetIndex$getHelpe !== void 0 ? _targetIndex$getHelpe : '');
78
89
  return;
79
90
  }
80
91
  render(h(AutocompleteWrapper, _extends({}, rendererParams, connectorParams)), containerNode);
81
92
  };
82
93
  };
83
94
  function AutocompleteWrapper(_ref) {
84
- var _targetIndex$getWidge, _isolatedIndex$getHel;
95
+ var _isolatedIndex$getHel, _targetIndex$getWidge, _showRecent$templates;
85
96
  var indicesConfig = _ref.indicesConfig,
86
97
  indices = _ref.indices,
87
98
  getSearchPageURL = _ref.getSearchPageURL,
@@ -89,9 +100,21 @@ function AutocompleteWrapper(_ref) {
89
100
  refine = _ref.refine,
90
101
  cssClasses = _ref.cssClasses,
91
102
  renderState = _ref.renderState,
92
- instantSearchInstance = _ref.instantSearchInstance;
103
+ instantSearchInstance = _ref.instantSearchInstance,
104
+ showRecent = _ref.showRecent;
93
105
  var isolatedIndex = renderState.isolatedIndex,
94
106
  targetIndex = renderState.targetIndex;
107
+ var searchboxQuery = isolatedIndex === null || isolatedIndex === void 0 ? void 0 : (_isolatedIndex$getHel = isolatedIndex.getHelper()) === null || _isolatedIndex$getHel === void 0 ? void 0 : _isolatedIndex$getHel.state.query;
108
+ var _useStorage = useStorage({
109
+ query: searchboxQuery,
110
+ showRecent: showRecent,
111
+ indices: indices,
112
+ indicesConfig: indicesConfig
113
+ }),
114
+ storage = _useStorage.storage,
115
+ storageHits = _useStorage.storageHits,
116
+ indicesConfigForPropGetters = _useStorage.indicesConfigForPropGetters,
117
+ indicesForPropGetters = _useStorage.indicesForPropGetters;
95
118
  var isSearchPage = (_targetIndex$getWidge = targetIndex === null || targetIndex === void 0 ? void 0 : targetIndex.getWidgets().some(function (_ref2) {
96
119
  var $$type = _ref2.$$type;
97
120
  return ['ais.hits', 'ais.infiniteHits'].includes($$type);
@@ -105,10 +128,11 @@ function AutocompleteWrapper(_ref) {
105
128
  query: query
106
129
  }), _objectSpread2));
107
130
  });
131
+ query.length > 0 && storage.onAdd(query);
108
132
  };
109
133
  var _usePropGetters = usePropGetters({
110
- indices: indices,
111
- indicesConfig: indicesConfig,
134
+ indices: indicesForPropGetters,
135
+ indicesConfig: indicesConfigForPropGetters,
112
136
  onRefine: onRefine,
113
137
  onSelect: userOnSelect !== null && userOnSelect !== void 0 ? userOnSelect : function (_ref3) {
114
138
  var query = _ref3.query,
@@ -132,11 +156,32 @@ function AutocompleteWrapper(_ref) {
132
156
  getItemProps = _usePropGetters.getItemProps,
133
157
  getPanelProps = _usePropGetters.getPanelProps,
134
158
  getRootProps = _usePropGetters.getRootProps;
135
- var query = isolatedIndex === null || isolatedIndex === void 0 ? void 0 : (_isolatedIndex$getHel = isolatedIndex.getHelper()) === null || _isolatedIndex$getHel === void 0 ? void 0 : _isolatedIndex$getHel.state.query;
159
+ var AutocompleteRecentSearchComponent = AutocompleteRecentSearch;
160
+ if (_typeof(showRecent) === 'object' && (_showRecent$templates = showRecent.templates) !== null && _showRecent$templates !== void 0 && _showRecent$templates.item) {
161
+ var props = prepareTemplateProps({
162
+ defaultTemplates: {},
163
+ templatesConfig: instantSearchInstance.templatesConfig,
164
+ templates: showRecent.templates
165
+ });
166
+ AutocompleteRecentSearchComponent = function AutocompleteRecentSearchComponent(_ref4) {
167
+ var item = _ref4.item,
168
+ onSelect = _ref4.onSelect,
169
+ onRemoveRecentSearch = _ref4.onRemoveRecentSearch;
170
+ return h(TemplateComponent, _extends({}, props, {
171
+ templateKey: "item",
172
+ rootTagName: "fragment",
173
+ data: {
174
+ item: item,
175
+ onSelect: onSelect,
176
+ onRemoveRecentSearch: onRemoveRecentSearch
177
+ }
178
+ }));
179
+ };
180
+ }
136
181
  return h(Autocomplete, _extends({}, getRootProps(), {
137
182
  classNames: cssClasses
138
183
  }), h(AutocompleteSearchBox, {
139
- query: query || '',
184
+ query: searchboxQuery || '',
140
185
  inputProps: _objectSpread(_objectSpread({}, getInputProps()), {}, {
141
186
  // @ts-ignore - This clashes with some ambient React JSX declarations.
142
187
  onInput: function onInput(evt) {
@@ -147,10 +192,31 @@ function AutocompleteWrapper(_ref) {
147
192
  return onRefine('');
148
193
  },
149
194
  isSearchStalled: instantSearchInstance.status === 'stalled'
150
- }), h(AutocompletePanel, getPanelProps(), indices.map(function (_ref4, i) {
195
+ }), h(AutocompletePanel, getPanelProps(), showRecent && h(AutocompleteIndex
196
+ // @ts-ignore - there seems to be problems with React.ComponentType and this, but it's actually correct
197
+ , {
198
+ ItemComponent: function ItemComponent(_ref5) {
199
+ var item = _ref5.item,
200
+ onSelect = _ref5.onSelect;
201
+ return h(AutocompleteRecentSearchComponent, {
202
+ item: item,
203
+ onSelect: onSelect,
204
+ onRemoveRecentSearch: function onRemoveRecentSearch() {
205
+ return storage.onRemove(item.query);
206
+ }
207
+ });
208
+ },
209
+ classNames: {
210
+ root: 'ais-AutocompleteRecentSearches',
211
+ list: 'ais-AutocompleteRecentSearchesList',
212
+ item: 'ais-AutocompleteRecentSearchesItem'
213
+ },
214
+ items: storageHits,
215
+ getItemProps: getItemProps
216
+ }), indices.map(function (_ref6, i) {
151
217
  var _indicesConfig$i$temp;
152
- var indexId = _ref4.indexId,
153
- hits = _ref4.hits;
218
+ var indexId = _ref6.indexId,
219
+ hits = _ref6.hits;
154
220
  if (!renderState.indexTemplateProps[i]) {
155
221
  renderState.indexTemplateProps[i] = prepareTemplateProps({
156
222
  defaultTemplates: {},
@@ -158,8 +224,8 @@ function AutocompleteWrapper(_ref) {
158
224
  templates: indicesConfig[i].templates
159
225
  });
160
226
  }
161
- var headerComponent = (_indicesConfig$i$temp = indicesConfig[i].templates) !== null && _indicesConfig$i$temp !== void 0 && _indicesConfig$i$temp.header ? function (_ref5) {
162
- var items = _ref5.items;
227
+ var headerComponent = (_indicesConfig$i$temp = indicesConfig[i].templates) !== null && _indicesConfig$i$temp !== void 0 && _indicesConfig$i$temp.header ? function (_ref7) {
228
+ var items = _ref7.items;
163
229
  return h(TemplateComponent, _extends({}, renderState.indexTemplateProps[i], {
164
230
  templateKey: "header",
165
231
  rootTagName: "fragment",
@@ -168,9 +234,9 @@ function AutocompleteWrapper(_ref) {
168
234
  }
169
235
  }));
170
236
  } : undefined;
171
- var itemComponent = function itemComponent(_ref6) {
172
- var item = _ref6.item,
173
- onSelect = _ref6.onSelect;
237
+ var itemComponent = function itemComponent(_ref8) {
238
+ var item = _ref8.item,
239
+ onSelect = _ref8.onSelect;
174
240
  return h(TemplateComponent, _extends({}, renderState.indexTemplateProps[i], {
175
241
  templateKey: "item",
176
242
  rootTagName: "fragment",
@@ -195,18 +261,19 @@ function AutocompleteWrapper(_ref) {
195
261
  })));
196
262
  }
197
263
  export function EXPERIMENTAL_autocomplete(widgetParams) {
198
- var _ref7 = widgetParams || {},
199
- container = _ref7.container,
200
- escapeHTML = _ref7.escapeHTML,
201
- _ref7$indices = _ref7.indices,
202
- indices = _ref7$indices === void 0 ? [] : _ref7$indices,
203
- showSuggestions = _ref7.showSuggestions,
204
- getSearchPageURL = _ref7.getSearchPageURL,
205
- onSelect = _ref7.onSelect,
206
- _ref7$templates = _ref7.templates,
207
- templates = _ref7$templates === void 0 ? {} : _ref7$templates,
208
- _ref7$cssClasses = _ref7.cssClasses,
209
- userCssClasses = _ref7$cssClasses === void 0 ? {} : _ref7$cssClasses;
264
+ var _ref9 = widgetParams || {},
265
+ container = _ref9.container,
266
+ escapeHTML = _ref9.escapeHTML,
267
+ _ref9$indices = _ref9.indices,
268
+ indices = _ref9$indices === void 0 ? [] : _ref9$indices,
269
+ showSuggestions = _ref9.showSuggestions,
270
+ showRecent = _ref9.showRecent,
271
+ getSearchPageURL = _ref9.getSearchPageURL,
272
+ onSelect = _ref9.onSelect,
273
+ _ref9$templates = _ref9.templates,
274
+ templates = _ref9$templates === void 0 ? {} : _ref9$templates,
275
+ _ref9$cssClasses = _ref9.cssClasses,
276
+ userCssClasses = _ref9$cssClasses === void 0 ? {} : _ref9$cssClasses;
210
277
  if (!container) {
211
278
  throw new Error(withUsage('The `container` option is required.'));
212
279
  }
@@ -243,6 +310,7 @@ export function EXPERIMENTAL_autocomplete(widgetParams) {
243
310
  getSearchPageURL: getSearchPageURL,
244
311
  onSelect: onSelect,
245
312
  cssClasses: cssClasses,
313
+ showRecent: showRecent,
246
314
  renderState: {
247
315
  indexTemplateProps: [],
248
316
  isolatedIndex: undefined,
@@ -258,14 +326,14 @@ export function EXPERIMENTAL_autocomplete(widgetParams) {
258
326
  })({}), index({
259
327
  indexId: "ais-autocomplete-".concat(instanceId),
260
328
  EXPERIMENTAL_isolated: true
261
- }).addWidgets([configure({
262
- hitsPerPage: 5
263
- })].concat(_toConsumableArray(indicesConfig.map(function (_ref8) {
264
- var indexName = _ref8.indexName;
329
+ }).addWidgets([].concat(_toConsumableArray(indicesConfig.map(function (_ref0) {
330
+ var indexName = _ref0.indexName;
265
331
  return index({
266
332
  indexName: indexName,
267
333
  indexId: indexName
268
- }).addWidgets([configure({})]);
334
+ }).addWidgets([configure({
335
+ hitsPerPage: 5
336
+ })]);
269
337
  })), [_objectSpread(_objectSpread({}, makeWidget({
270
338
  escapeHTML: escapeHTML
271
339
  })), {}, {
@@ -2,7 +2,7 @@
2
2
  import { SearchIndexToolType, RecommendToolType } from '../../lib/chat';
3
3
  import type { ChatConnectorParams, ChatWidgetDescription } from '../../connectors/chat/connectChat';
4
4
  import type { WidgetFactory, Hit, TemplateWithBindEvent, BaseHit, Template, IndexUiState } from '../../types';
5
- import type { ChatClassNames, ChatHeaderProps, ChatMessageActionProps, ChatMessageBase, ChatMessageErrorProps, ChatMessageLoaderProps, ChatPromptProps, ChatToggleButtonProps, ClientSideToolComponentProps, RecordWithObjectID, UserClientSideTool } from 'instantsearch-ui-components';
5
+ import type { ChatClassNames, ChatHeaderProps, ChatMessageActionProps, ChatMessageBase, ChatMessageErrorProps, ChatMessageLoaderProps, ChatPromptProps, ChatToggleButtonProps, ClientSideToolComponentProps, ClientSideTools, RecordWithObjectID, UserClientSideTool } from 'instantsearch-ui-components';
6
6
  export { SearchIndexToolType, RecommendToolType };
7
7
  export type UserClientSideToolTemplates = Partial<{
8
8
  layout: TemplateWithBindEvent<ClientSideToolComponentProps>;
@@ -95,6 +95,45 @@ export type ChatTemplates<THit extends NonNullable<object> = BaseHit> = Partial<
95
95
  */
96
96
  regenerateLabelText?: string;
97
97
  }>;
98
+ /**
99
+ * Templates to use for each message.
100
+ */
101
+ message: Partial<{
102
+ /**
103
+ * Label for the message actions
104
+ */
105
+ actionsLabelText?: string;
106
+ /**
107
+ * Label for the message container
108
+ */
109
+ messageLabelText?: string;
110
+ }>;
111
+ /**
112
+ * Templates to use for the assistant message.
113
+ */
114
+ assistantMessage: Partial<{
115
+ /**
116
+ * Template to use for the assistant message leading content.
117
+ */
118
+ leading: Template;
119
+ /**
120
+ * Template to use for the assistant message footer content.
121
+ */
122
+ footer: Template;
123
+ }>;
124
+ /**
125
+ * Templates to use for the user message.
126
+ */
127
+ userMessage: Partial<{
128
+ /**
129
+ * Template to use for the user message leading content.
130
+ */
131
+ leading: Template;
132
+ /**
133
+ * Template to use for the user message footer content.
134
+ */
135
+ footer: Template;
136
+ }>;
98
137
  /**
99
138
  * Templates to use for the prompt.
100
139
  */
@@ -515,7 +554,7 @@ declare const _default: <THit extends RecordWithObjectID = RecordWithObjectID>(w
515
554
  isClearing: boolean;
516
555
  clearMessages: () => void;
517
556
  onClearTransitionEnd: () => void;
518
- tools: Record<string, Omit<UserClientSideTool, "layoutComponent">>;
557
+ tools: ClientSideTools;
519
558
  widgetParams: Partial<ChatWidgetParams<RecordWithObjectID>> & ChatConnectorParams<import("ai").UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>>;
520
559
  addToolResult: <TOOL extends string>({ tool, toolCallId, output, }: {
521
560
  tool: TOOL;
@@ -251,7 +251,10 @@ function ChatWrapper(_ref0) {
251
251
  loaderComponent: messagesProps.loaderComponent,
252
252
  errorComponent: messagesProps.errorComponent,
253
253
  actionsComponent: messagesProps.actionsComponent,
254
- translations: messagesProps.translations
254
+ assistantMessageProps: messagesProps.assistantMessageProps,
255
+ userMessageProps: messagesProps.userMessageProps,
256
+ translations: messagesProps.translations,
257
+ messageTranslations: messagesProps.messageTranslations
255
258
  },
256
259
  promptProps: {
257
260
  promptRef: promptProps.promptRef,
@@ -285,8 +288,10 @@ var createRenderer = function createRenderer(_ref1) {
285
288
  var promptRef = {
286
289
  current: null
287
290
  };
291
+
292
+ // eslint-disable-next-line complexity
288
293
  return function (props, isFirstRendering) {
289
- var _templates$header, _templates$header2, _templates$header3, _templates$header4, _templates$header5, _templates$header6, _templates$header7, _templates$header8, _templates$header9, _templates$header0, _templates$messages, _templates$messages2, _templates$messages3, _templates$messages4, _templates$messages5, _templates$messages6, _templates$prompt, _templates$prompt2, _templates$prompt3, _templates$prompt4, _templates$prompt5, _templates$prompt6, _templates$prompt7, _templates$prompt8, _templates$prompt9, _templates$toggleButt, _templates$toggleButt2;
294
+ var _templates$header, _templates$header2, _templates$header3, _templates$header4, _templates$header5, _templates$header6, _templates$header7, _templates$header8, _templates$header9, _templates$header0, _templates$messages, _templates$messages2, _templates$messages3, _templates$messages4, _templates$messages5, _templates$messages6, _templates$assistantM, _templates$assistantM2, _templates$message, _templates$message2, _templates$userMessag, _templates$userMessag2, _templates$prompt, _templates$prompt2, _templates$prompt3, _templates$prompt4, _templates$prompt5, _templates$prompt6, _templates$prompt7, _templates$prompt8, _templates$prompt9, _templates$toggleButt, _templates$toggleButt2;
290
295
  var indexUiState = props.indexUiState,
291
296
  input = props.input,
292
297
  instantSearchInstance = props.instantSearchInstance,
@@ -298,7 +303,6 @@ var createRenderer = function createRenderer(_ref1) {
298
303
  setOpen = props.setOpen,
299
304
  status = props.status,
300
305
  error = props.error,
301
- addToolResult = props.addToolResult,
302
306
  regenerate = props.regenerate,
303
307
  stop = props.stop,
304
308
  isClearing = props.isClearing,
@@ -318,12 +322,12 @@ var createRenderer = function createRenderer(_ref1) {
318
322
  }
319
323
  var toolsForUi = {};
320
324
  Object.entries(toolsFromConnector).forEach(function (_ref10) {
325
+ var _widgetTool$templates;
321
326
  var _ref11 = _slicedToArray(_ref10, 2),
322
327
  key = _ref11[0],
323
328
  connectorTool = _ref11[1];
324
329
  var widgetTool = tools[key];
325
- toolsForUi[key] = _objectSpread(_objectSpread({}, connectorTool), {}, {
326
- addToolResult: addToolResult,
330
+ toolsForUi[key] = _objectSpread(_objectSpread({}, connectorTool), (widgetTool === null || widgetTool === void 0 ? void 0 : (_widgetTool$templates = widgetTool.templates) === null || _widgetTool$templates === void 0 ? void 0 : _widgetTool$templates.layout) && {
327
331
  layoutComponent: function layoutComponent(layoutComponentProps) {
328
332
  return h(TemplateComponent, {
329
333
  templates: widgetTool.templates,
@@ -406,6 +410,44 @@ var createRenderer = function createRenderer(_ref1) {
406
410
  copyToClipboardLabel: (_templates$messages5 = templates.messages) === null || _templates$messages5 === void 0 ? void 0 : _templates$messages5.copyToClipboardLabelText,
407
411
  regenerateLabel: (_templates$messages6 = templates.messages) === null || _templates$messages6 === void 0 ? void 0 : _templates$messages6.regenerateLabelText
408
412
  });
413
+ var assistantMessageTemplateProps = prepareTemplateProps({
414
+ defaultTemplates: {},
415
+ templatesConfig: instantSearchInstance.templatesConfig,
416
+ templates: templates.assistantMessage
417
+ });
418
+ var assistantMessageLeadingComponent = (_templates$assistantM = templates.assistantMessage) !== null && _templates$assistantM !== void 0 && _templates$assistantM.leading ? function () {
419
+ return h(TemplateComponent, _extends({}, assistantMessageTemplateProps, {
420
+ templateKey: "leading",
421
+ rootTagName: "fragment"
422
+ }));
423
+ } : undefined;
424
+ var assistantMessageFooterComponent = (_templates$assistantM2 = templates.assistantMessage) !== null && _templates$assistantM2 !== void 0 && _templates$assistantM2.footer ? function () {
425
+ return h(TemplateComponent, _extends({}, assistantMessageTemplateProps, {
426
+ templateKey: "footer",
427
+ rootTagName: "fragment"
428
+ }));
429
+ } : undefined;
430
+ var messageTranslations = getDefinedProperties({
431
+ actionsLabel: (_templates$message = templates.message) === null || _templates$message === void 0 ? void 0 : _templates$message.actionsLabelText,
432
+ messageLabel: (_templates$message2 = templates.message) === null || _templates$message2 === void 0 ? void 0 : _templates$message2.messageLabelText
433
+ });
434
+ var userMessageTemplateProps = prepareTemplateProps({
435
+ defaultTemplates: {},
436
+ templatesConfig: instantSearchInstance.templatesConfig,
437
+ templates: templates.userMessage
438
+ });
439
+ var userMessageLeadingComponent = (_templates$userMessag = templates.userMessage) !== null && _templates$userMessag !== void 0 && _templates$userMessag.leading ? function () {
440
+ return h(TemplateComponent, _extends({}, userMessageTemplateProps, {
441
+ templateKey: "leading",
442
+ rootTagName: "fragment"
443
+ }));
444
+ } : undefined;
445
+ var userMessageFooterComponent = (_templates$userMessag2 = templates.userMessage) !== null && _templates$userMessag2 !== void 0 && _templates$userMessag2.footer ? function () {
446
+ return h(TemplateComponent, _extends({}, userMessageTemplateProps, {
447
+ templateKey: "footer",
448
+ rootTagName: "fragment"
449
+ }));
450
+ } : undefined;
409
451
  var promptTemplateProps = prepareTemplateProps({
410
452
  defaultTemplates: {},
411
453
  templatesConfig: instantSearchInstance.templatesConfig,
@@ -502,7 +544,16 @@ var createRenderer = function createRenderer(_ref1) {
502
544
  loaderComponent: messagesLoaderComponent,
503
545
  errorComponent: messagesErrorComponent,
504
546
  actionsComponent: actionsComponent,
505
- translations: messagesTranslations
547
+ assistantMessageProps: {
548
+ leadingComponent: assistantMessageLeadingComponent,
549
+ footerComponent: assistantMessageFooterComponent
550
+ },
551
+ userMessageProps: {
552
+ leadingComponent: userMessageLeadingComponent,
553
+ footerComponent: userMessageFooterComponent
554
+ },
555
+ translations: messagesTranslations,
556
+ messageTranslations: messageTranslations
506
557
  },
507
558
  promptProps: {
508
559
  layoutComponent: promptLayoutComponent,
@@ -415,12 +415,6 @@ var index = function index(widgetParams) {
415
415
  helper.searchWithoutTriggeringOnStateChange = function () {
416
416
  return mainHelper.search();
417
417
  };
418
-
419
- // We use the same pattern for the `searchForFacetValues`.
420
- helper.searchForFacetValues = function (facetName, facetValue, maxFacetHits, userState) {
421
- var state = helper.state.setQueryParameters(userState);
422
- return mainHelper.searchForFacetValues(facetName, facetValue, maxFacetHits, state);
423
- };
424
418
  var isolatedHelper = indexName ? helper : algoliasearchHelper({}, '__empty_index__', {});
425
419
  var derivingHelper = isolated ? isolatedHelper : nearestIsolatedHelper(parent, mainHelper);
426
420
  derivedHelper = derivingHelper.derive(function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instantsearch.js",
3
- "version": "4.82.0",
3
+ "version": "4.83.0",
4
4
  "description": "InstantSearch.js is a JavaScript library for building performant and instant search experiences with Algolia.",
5
5
  "homepage": "https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/",
6
6
  "types": "es/index.d.ts",
@@ -32,10 +32,10 @@
32
32
  "@types/hogan.js": "^3.0.0",
33
33
  "@types/qs": "^6.5.3",
34
34
  "ai": "^5.0.18",
35
- "algoliasearch-helper": "3.26.0",
35
+ "algoliasearch-helper": "3.26.1",
36
36
  "hogan.js": "^3.0.2",
37
37
  "htm": "^3.0.0",
38
- "instantsearch-ui-components": "0.13.0",
38
+ "instantsearch-ui-components": "0.14.0",
39
39
  "preact": "^10.10.0",
40
40
  "qs": "^6.5.1 < 6.10",
41
41
  "react": ">= 0.14.0",
@@ -60,9 +60,9 @@
60
60
  "watch:es": "yarn --silent build:es:base --watch"
61
61
  },
62
62
  "devDependencies": {
63
- "@instantsearch/mocks": "1.80.0",
64
- "@instantsearch/tests": "1.80.0",
65
- "@instantsearch/testutils": "1.69.0",
63
+ "@instantsearch/mocks": "1.81.0",
64
+ "@instantsearch/tests": "1.81.0",
65
+ "@instantsearch/testutils": "1.70.0",
66
66
  "@storybook/html": "5.3.9",
67
67
  "@types/scriptjs": "0.0.2",
68
68
  "algoliasearch": "5.1.1",
@@ -70,5 +70,5 @@
70
70
  "scriptjs": "2.5.9",
71
71
  "webpack": "4.47.0"
72
72
  },
73
- "gitHead": "89dc58afb61fbabb29e326d18543e51907eaea88"
73
+ "gitHead": "6e4bcd74b92f96761f514bee14824537ba36adf2"
74
74
  }