instantsearch.js 4.86.1 → 4.87.1

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.
Files changed (82) hide show
  1. package/cjs/connectors/autocomplete/connectAutocomplete.js +13 -5
  2. package/cjs/connectors/chat/connectChat.js +92 -20
  3. package/cjs/connectors/filter-suggestions/connectFilterSuggestions.js +255 -0
  4. package/cjs/connectors/index.js +7 -0
  5. package/cjs/connectors/index.umd.js +7 -0
  6. package/cjs/index.js +2 -2
  7. package/cjs/lib/ai-lite/abstract-chat.js +823 -0
  8. package/cjs/lib/ai-lite/index.js +57 -0
  9. package/cjs/lib/ai-lite/stream-parser.js +138 -0
  10. package/cjs/lib/ai-lite/transport.js +218 -0
  11. package/cjs/lib/ai-lite/types.js +1 -0
  12. package/cjs/lib/ai-lite/utils.js +85 -0
  13. package/cjs/lib/chat/chat.js +6 -6
  14. package/cjs/lib/chat/index.js +5 -2
  15. package/cjs/lib/version.js +1 -1
  16. package/cjs/widgets/autocomplete/autocomplete.js +15 -6
  17. package/cjs/widgets/chat/chat.js +32 -3
  18. package/cjs/widgets/filter-suggestions/filter-suggestions.js +131 -0
  19. package/cjs/widgets/index.js +7 -0
  20. package/cjs/widgets/index.umd.js +7 -0
  21. package/dist/instantsearch.development.d.ts +2551 -346
  22. package/dist/instantsearch.development.js +9408 -4314
  23. package/dist/instantsearch.development.js.map +1 -1
  24. package/dist/instantsearch.production.d.ts +2551 -346
  25. package/dist/instantsearch.production.min.d.ts +2551 -346
  26. package/dist/instantsearch.production.min.js +2 -2
  27. package/dist/instantsearch.production.min.js.map +1 -1
  28. package/es/connectors/autocomplete/connectAutocomplete.d.ts +10 -0
  29. package/es/connectors/autocomplete/connectAutocomplete.js +13 -5
  30. package/es/connectors/chat/connectChat.d.ts +24 -14
  31. package/es/connectors/chat/connectChat.js +90 -18
  32. package/es/connectors/filter-suggestions/connectFilterSuggestions.d.ts +95 -0
  33. package/es/connectors/filter-suggestions/connectFilterSuggestions.js +249 -0
  34. package/es/connectors/frequently-bought-together/connectFrequentlyBoughtTogether.d.ts +2 -2
  35. package/es/connectors/geo-search/connectGeoSearch.d.ts +1 -1
  36. package/es/connectors/hits/connectHits.d.ts +1 -1
  37. package/es/connectors/hits/connectHitsWithInsights.d.ts +1 -1
  38. package/es/connectors/index.d.ts +1 -0
  39. package/es/connectors/index.js +2 -1
  40. package/es/connectors/index.umd.d.ts +1 -0
  41. package/es/connectors/index.umd.js +2 -1
  42. package/es/connectors/infinite-hits/connectInfiniteHits.d.ts +1 -1
  43. package/es/connectors/infinite-hits/connectInfiniteHitsWithInsights.d.ts +1 -1
  44. package/es/connectors/looking-similar/connectLookingSimilar.d.ts +2 -2
  45. package/es/connectors/related-products/connectRelatedProducts.d.ts +2 -2
  46. package/es/connectors/trending-items/connectTrendingItems.d.ts +2 -2
  47. package/es/lib/ai-lite/abstract-chat.d.ts +89 -0
  48. package/es/lib/ai-lite/abstract-chat.js +818 -0
  49. package/es/lib/ai-lite/index.d.ts +11 -0
  50. package/es/lib/ai-lite/index.js +18 -0
  51. package/es/lib/ai-lite/stream-parser.d.ts +18 -0
  52. package/es/lib/ai-lite/stream-parser.js +131 -0
  53. package/es/lib/ai-lite/transport.d.ts +24 -0
  54. package/es/lib/ai-lite/transport.js +214 -0
  55. package/es/lib/ai-lite/types.d.ts +362 -0
  56. package/es/lib/ai-lite/types.js +1 -0
  57. package/es/lib/ai-lite/utils.d.ts +12 -0
  58. package/es/lib/ai-lite/utils.js +76 -0
  59. package/es/lib/chat/chat.d.ts +3 -3
  60. package/es/lib/chat/chat.js +4 -4
  61. package/es/lib/chat/index.d.ts +3 -0
  62. package/es/lib/chat/index.js +4 -1
  63. package/es/lib/version.d.ts +1 -1
  64. package/es/lib/version.js +1 -1
  65. package/es/widgets/autocomplete/autocomplete.d.ts +2 -1
  66. package/es/widgets/autocomplete/autocomplete.js +15 -6
  67. package/es/widgets/chat/chat.d.ts +22 -14
  68. package/es/widgets/chat/chat.js +33 -4
  69. package/es/widgets/filter-suggestions/filter-suggestions.d.ts +689 -0
  70. package/es/widgets/filter-suggestions/filter-suggestions.js +124 -0
  71. package/es/widgets/frequently-bought-together/frequently-bought-together.d.ts +3 -3
  72. package/es/widgets/geo-search/geo-search.d.ts +1 -1
  73. package/es/widgets/hits/hits.d.ts +1 -1
  74. package/es/widgets/index.d.ts +1 -0
  75. package/es/widgets/index.js +2 -1
  76. package/es/widgets/index.umd.d.ts +1 -0
  77. package/es/widgets/index.umd.js +2 -1
  78. package/es/widgets/infinite-hits/infinite-hits.d.ts +1 -1
  79. package/es/widgets/looking-similar/looking-similar.d.ts +3 -3
  80. package/es/widgets/related-products/related-products.d.ts +3 -3
  81. package/es/widgets/trending-items/trending-items.d.ts +3 -3
  82. package/package.json +6 -7
@@ -0,0 +1,362 @@
1
+ /**
2
+ * Chat status:
3
+ * - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream.
4
+ * - `streaming`: The response is actively streaming in from the API, receiving chunks of data.
5
+ * - `ready`: The full response has been received and processed; a new user message can be submitted.
6
+ * - `error`: An error occurred during the API request, preventing successful completion.
7
+ */
8
+ export type ChatStatus = 'submitted' | 'streaming' | 'ready' | 'error';
9
+ export type UIDataTypes = Record<string, unknown>;
10
+ export type UITool = {
11
+ input: unknown;
12
+ output: unknown | undefined;
13
+ };
14
+ export type UITools = Record<string, UITool>;
15
+ export type ProviderMetadata = Record<string, Record<string, unknown>>;
16
+ type ValueOf<T> = T[keyof T];
17
+ type DeepPartial<T> = T extends object ? {
18
+ [P in keyof T]?: DeepPartial<T[P]>;
19
+ } : T;
20
+ export type TextUIPart = {
21
+ type: 'text';
22
+ text: string;
23
+ state?: 'streaming' | 'done';
24
+ providerMetadata?: ProviderMetadata;
25
+ };
26
+ export type ReasoningUIPart = {
27
+ type: 'reasoning';
28
+ text: string;
29
+ state?: 'streaming' | 'done';
30
+ providerMetadata?: ProviderMetadata;
31
+ };
32
+ export type SourceUrlUIPart = {
33
+ type: 'source-url';
34
+ sourceId: string;
35
+ url: string;
36
+ title?: string;
37
+ providerMetadata?: ProviderMetadata;
38
+ };
39
+ export type SourceDocumentUIPart = {
40
+ type: 'source-document';
41
+ sourceId: string;
42
+ mediaType: string;
43
+ title: string;
44
+ filename?: string;
45
+ providerMetadata?: ProviderMetadata;
46
+ };
47
+ export type FileUIPart = {
48
+ type: 'file';
49
+ mediaType: string;
50
+ filename?: string;
51
+ url: string;
52
+ providerMetadata?: ProviderMetadata;
53
+ };
54
+ export type StepStartUIPart = {
55
+ type: 'step-start';
56
+ };
57
+ export type DataUIPart<DATA_TYPES extends UIDataTypes> = ValueOf<{
58
+ [NAME in keyof DATA_TYPES & string]: {
59
+ type: `data-${NAME}`;
60
+ id?: string;
61
+ data: DATA_TYPES[NAME];
62
+ };
63
+ }>;
64
+ export type ToolUIPart<TOOLS extends UITools = UITools> = ValueOf<{
65
+ [NAME in keyof TOOLS & string]: {
66
+ type: `tool-${NAME}`;
67
+ toolCallId: string;
68
+ } & ({
69
+ state: 'input-streaming';
70
+ input: DeepPartial<TOOLS[NAME]['input']> | undefined;
71
+ providerExecuted?: boolean;
72
+ output?: never;
73
+ errorText?: never;
74
+ } | {
75
+ state: 'input-available';
76
+ input: TOOLS[NAME]['input'];
77
+ providerExecuted?: boolean;
78
+ output?: never;
79
+ errorText?: never;
80
+ callProviderMetadata?: ProviderMetadata;
81
+ } | {
82
+ state: 'output-available';
83
+ input: TOOLS[NAME]['input'];
84
+ output: TOOLS[NAME]['output'];
85
+ errorText?: never;
86
+ providerExecuted?: boolean;
87
+ callProviderMetadata?: ProviderMetadata;
88
+ preliminary?: boolean;
89
+ } | {
90
+ state: 'output-error';
91
+ input: TOOLS[NAME]['input'] | undefined;
92
+ rawInput?: unknown;
93
+ output?: never;
94
+ errorText: string;
95
+ providerExecuted?: boolean;
96
+ callProviderMetadata?: ProviderMetadata;
97
+ });
98
+ }>;
99
+ export type DynamicToolUIPart = {
100
+ type: 'dynamic-tool';
101
+ toolName: string;
102
+ toolCallId: string;
103
+ } & ({
104
+ state: 'input-streaming';
105
+ input: unknown | undefined;
106
+ output?: never;
107
+ errorText?: never;
108
+ } | {
109
+ state: 'input-available';
110
+ input: unknown;
111
+ output?: never;
112
+ errorText?: never;
113
+ callProviderMetadata?: ProviderMetadata;
114
+ } | {
115
+ state: 'output-available';
116
+ input: unknown;
117
+ output: unknown;
118
+ errorText?: never;
119
+ callProviderMetadata?: ProviderMetadata;
120
+ preliminary?: boolean;
121
+ } | {
122
+ state: 'output-error';
123
+ input: unknown;
124
+ output?: never;
125
+ errorText: string;
126
+ callProviderMetadata?: ProviderMetadata;
127
+ });
128
+ export type UIMessagePart<DATA_TYPES extends UIDataTypes = UIDataTypes, TOOLS extends UITools = UITools> = TextUIPart | ReasoningUIPart | ToolUIPart<TOOLS> | DynamicToolUIPart | SourceUrlUIPart | SourceDocumentUIPart | FileUIPart | DataUIPart<DATA_TYPES> | StepStartUIPart;
129
+ export interface UIMessage<METADATA = unknown, DATA_PARTS extends UIDataTypes = UIDataTypes, TOOLS extends UITools = UITools> {
130
+ id: string;
131
+ role: 'system' | 'user' | 'assistant';
132
+ metadata?: METADATA;
133
+ parts: Array<UIMessagePart<DATA_PARTS, TOOLS>>;
134
+ }
135
+ export type InferUIMessageMetadata<T extends UIMessage> = T extends UIMessage<infer METADATA> ? METADATA : unknown;
136
+ export type InferUIMessageData<T extends UIMessage> = T extends UIMessage<unknown, infer DATA_TYPES> ? DATA_TYPES : UIDataTypes;
137
+ export type InferUIMessageTools<T extends UIMessage> = T extends UIMessage<unknown, UIDataTypes, infer TOOLS> ? TOOLS : UITools;
138
+ export type InferUIMessageToolCall<UI_MESSAGE extends UIMessage> = ValueOf<{
139
+ [NAME in keyof InferUIMessageTools<UI_MESSAGE>]: {
140
+ toolName: NAME & string;
141
+ toolCallId: string;
142
+ input: InferUIMessageTools<UI_MESSAGE>[NAME] extends {
143
+ input: infer INPUT;
144
+ } ? INPUT : never;
145
+ dynamic?: false;
146
+ };
147
+ }> | {
148
+ toolName: string;
149
+ toolCallId: string;
150
+ input: unknown;
151
+ dynamic: true;
152
+ };
153
+ type DataUIMessageChunk<DATA_TYPES extends UIDataTypes> = ValueOf<{
154
+ [NAME in keyof DATA_TYPES & string]: {
155
+ type: `data-${NAME}`;
156
+ id?: string;
157
+ data: DATA_TYPES[NAME];
158
+ transient?: boolean;
159
+ };
160
+ }>;
161
+ export type UIMessageChunk<METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataTypes> = {
162
+ type: 'text-start';
163
+ id: string;
164
+ providerMetadata?: ProviderMetadata;
165
+ } | {
166
+ type: 'text-delta';
167
+ delta: string;
168
+ id: string;
169
+ providerMetadata?: ProviderMetadata;
170
+ } | {
171
+ type: 'text-end';
172
+ id: string;
173
+ providerMetadata?: ProviderMetadata;
174
+ } | {
175
+ type: 'reasoning-start';
176
+ id: string;
177
+ providerMetadata?: ProviderMetadata;
178
+ } | {
179
+ type: 'reasoning-delta';
180
+ id: string;
181
+ delta: string;
182
+ providerMetadata?: ProviderMetadata;
183
+ } | {
184
+ type: 'reasoning-end';
185
+ id: string;
186
+ providerMetadata?: ProviderMetadata;
187
+ } | {
188
+ type: 'error';
189
+ errorText: string;
190
+ } | {
191
+ type: 'tool-input-available';
192
+ toolName: string;
193
+ toolCallId: string;
194
+ input: unknown;
195
+ callProviderMetadata?: ProviderMetadata;
196
+ providerExecuted?: boolean;
197
+ } | {
198
+ type: 'tool-input-start';
199
+ toolName: string;
200
+ toolCallId: string;
201
+ input?: unknown;
202
+ providerExecuted?: boolean;
203
+ } | {
204
+ type: 'tool-input-delta';
205
+ toolName: string;
206
+ toolCallId: string;
207
+ inputDelta: string;
208
+ } | {
209
+ type: 'tool-output-available';
210
+ toolName: string;
211
+ toolCallId: string;
212
+ output: unknown;
213
+ callProviderMetadata?: ProviderMetadata;
214
+ preliminary?: boolean;
215
+ } | {
216
+ type: 'tool-error';
217
+ toolName: string;
218
+ toolCallId: string;
219
+ errorText: string;
220
+ input?: unknown;
221
+ callProviderMetadata?: ProviderMetadata;
222
+ } | {
223
+ type: 'source-url';
224
+ sourceId: string;
225
+ url: string;
226
+ title?: string;
227
+ } | {
228
+ type: 'source-document';
229
+ sourceId: string;
230
+ mediaType: string;
231
+ title: string;
232
+ filename?: string;
233
+ providerMetadata?: ProviderMetadata;
234
+ } | {
235
+ type: 'file';
236
+ url: string;
237
+ mediaType: string;
238
+ } | DataUIMessageChunk<DATA_TYPES> | {
239
+ type: 'start-step';
240
+ } | {
241
+ type: 'finish-step';
242
+ } | {
243
+ type: 'start';
244
+ messageId?: string;
245
+ messageMetadata?: METADATA;
246
+ } | {
247
+ type: 'finish';
248
+ messageMetadata?: METADATA;
249
+ } | {
250
+ type: 'abort';
251
+ } | {
252
+ type: 'message-metadata';
253
+ messageMetadata: METADATA;
254
+ };
255
+ export type InferUIMessageChunk<T extends UIMessage> = UIMessageChunk<InferUIMessageMetadata<T>, InferUIMessageData<T>>;
256
+ export interface ChatState<UI_MESSAGE extends UIMessage> {
257
+ status: ChatStatus;
258
+ error: Error | undefined;
259
+ messages: UI_MESSAGE[];
260
+ pushMessage: (message: UI_MESSAGE) => void;
261
+ popMessage: () => void;
262
+ replaceMessage: (index: number, message: UI_MESSAGE) => void;
263
+ snapshot: <T>(thing: T) => T;
264
+ }
265
+ export type ChatRequestOptions = {
266
+ headers?: Record<string, string> | Headers;
267
+ body?: object;
268
+ metadata?: unknown;
269
+ };
270
+ export interface ChatTransport<UI_MESSAGE extends UIMessage> {
271
+ sendMessages: (options: {
272
+ chatId: string;
273
+ messages: UI_MESSAGE[];
274
+ abortSignal: AbortSignal;
275
+ requestMetadata?: unknown;
276
+ trigger: 'submit-message' | 'regenerate-message';
277
+ messageId?: string;
278
+ } & ChatRequestOptions) => Promise<ReadableStream<UIMessageChunk>>;
279
+ reconnectToStream: (options: {
280
+ chatId: string;
281
+ } & ChatRequestOptions) => Promise<ReadableStream<UIMessageChunk> | null>;
282
+ }
283
+ export type PrepareSendMessagesRequest<UI_MESSAGE extends UIMessage> = (options: {
284
+ id: string;
285
+ messages: UI_MESSAGE[];
286
+ requestMetadata: unknown;
287
+ body: Record<string, unknown> | undefined;
288
+ credentials: RequestCredentials | undefined;
289
+ headers: HeadersInit | undefined;
290
+ api: string;
291
+ } & {
292
+ trigger: 'submit-message' | 'regenerate-message';
293
+ messageId: string | undefined;
294
+ }) => {
295
+ body: object;
296
+ headers?: HeadersInit;
297
+ credentials?: RequestCredentials;
298
+ api?: string;
299
+ } | PromiseLike<{
300
+ body: object;
301
+ headers?: HeadersInit;
302
+ credentials?: RequestCredentials;
303
+ api?: string;
304
+ }>;
305
+ export type PrepareReconnectToStreamRequest = (options: {
306
+ id: string;
307
+ requestMetadata: unknown;
308
+ body: Record<string, unknown> | undefined;
309
+ credentials: RequestCredentials | undefined;
310
+ headers: HeadersInit | undefined;
311
+ api: string;
312
+ }) => {
313
+ headers?: HeadersInit;
314
+ credentials?: RequestCredentials;
315
+ api?: string;
316
+ } | PromiseLike<{
317
+ headers?: HeadersInit;
318
+ credentials?: RequestCredentials;
319
+ api?: string;
320
+ }>;
321
+ export type Resolvable<T> = T | (() => T) | (() => Promise<T>);
322
+ export type FetchFunction = typeof fetch;
323
+ export type HttpChatTransportInitOptions<UI_MESSAGE extends UIMessage> = {
324
+ api?: string;
325
+ credentials?: Resolvable<RequestCredentials>;
326
+ headers?: Resolvable<Record<string, string> | Headers>;
327
+ body?: Resolvable<object>;
328
+ fetch?: FetchFunction;
329
+ prepareSendMessagesRequest?: PrepareSendMessagesRequest<UI_MESSAGE>;
330
+ prepareReconnectToStreamRequest?: PrepareReconnectToStreamRequest;
331
+ };
332
+ export type IdGenerator = () => string;
333
+ export type ChatOnErrorCallback = (error: Error) => void;
334
+ export type ChatOnToolCallCallback<UI_MESSAGE extends UIMessage = UIMessage> = (options: {
335
+ toolCall: InferUIMessageToolCall<UI_MESSAGE>;
336
+ }) => void | PromiseLike<void>;
337
+ export type ChatOnFinishCallback<UI_MESSAGE extends UIMessage> = (options: {
338
+ message: UI_MESSAGE;
339
+ messages: UI_MESSAGE[];
340
+ isAbort: boolean;
341
+ isDisconnect: boolean;
342
+ isError: boolean;
343
+ }) => void;
344
+ export type ChatOnDataCallback<UI_MESSAGE extends UIMessage> = (dataPart: DataUIPart<InferUIMessageData<UI_MESSAGE>>) => void;
345
+ export interface ChatInit<UI_MESSAGE extends UIMessage> {
346
+ id?: string;
347
+ messages?: UI_MESSAGE[];
348
+ generateId?: IdGenerator;
349
+ transport?: ChatTransport<UI_MESSAGE>;
350
+ onError?: ChatOnErrorCallback;
351
+ onToolCall?: ChatOnToolCallCallback<UI_MESSAGE>;
352
+ onFinish?: ChatOnFinishCallback<UI_MESSAGE>;
353
+ onData?: ChatOnDataCallback<UI_MESSAGE>;
354
+ sendAutomaticallyWhen?: (options: {
355
+ messages: UI_MESSAGE[];
356
+ }) => boolean | PromiseLike<boolean>;
357
+ }
358
+ export type CreateUIMessage<UI_MESSAGE extends UIMessage> = Omit<UI_MESSAGE, 'id' | 'role'> & {
359
+ id?: UI_MESSAGE['id'];
360
+ role?: UI_MESSAGE['role'];
361
+ };
362
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import type { UIMessage } from './types';
2
+ export declare function generateId(): string;
3
+ export declare function lastAssistantMessageIsCompleteWithToolCalls({ messages, }: {
4
+ messages: UIMessage[];
5
+ }): boolean;
6
+ export declare class SerialJobExecutor {
7
+ private queue;
8
+ private isRunning;
9
+ run<T>(job: () => Promise<T>): Promise<T>;
10
+ private processQueue;
11
+ }
12
+ export declare function resolveValue<T>(value: T | (() => T) | (() => Promise<T>) | undefined): Promise<T | undefined>;
@@ -0,0 +1,76 @@
1
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
2
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
3
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
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
+ 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
+ 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); }
8
+ export function generateId() {
9
+ return Math.random().toString(36).substring(2, 9);
10
+ }
11
+ function isToolOrDynamicToolUIPart(part) {
12
+ if (_typeof(part) !== 'object' || part === null) return false;
13
+ var p = part;
14
+ return typeof p.type === 'string' && (p.type.startsWith('tool-') || p.type === 'dynamic-tool');
15
+ }
16
+ export function lastAssistantMessageIsCompleteWithToolCalls(_ref) {
17
+ var messages = _ref.messages;
18
+ if (messages.length === 0) return false;
19
+ var lastMessage = messages[messages.length - 1];
20
+ if (lastMessage.role !== 'assistant') return false;
21
+ if (!lastMessage.parts || lastMessage.parts.length === 0) return false;
22
+ var toolParts = lastMessage.parts.filter(isToolOrDynamicToolUIPart);
23
+ if (toolParts.length === 0) return false;
24
+ return toolParts.every(function (part) {
25
+ return part.state === 'output-available' || part.state === 'output-error';
26
+ });
27
+ }
28
+ export var SerialJobExecutor = /*#__PURE__*/function () {
29
+ function SerialJobExecutor() {
30
+ _classCallCheck(this, SerialJobExecutor);
31
+ _defineProperty(this, "queue", []);
32
+ _defineProperty(this, "isRunning", false);
33
+ }
34
+ _createClass(SerialJobExecutor, [{
35
+ key: "run",
36
+ value: function run(job) {
37
+ var _this = this;
38
+ return new Promise(function (resolve, reject) {
39
+ _this.queue.push(function () {
40
+ return job().then(function (result) {
41
+ resolve(result);
42
+ }, function (error) {
43
+ reject(error);
44
+ });
45
+ });
46
+ _this.processQueue();
47
+ });
48
+ }
49
+ }, {
50
+ key: "processQueue",
51
+ value: function processQueue() {
52
+ var _this2 = this;
53
+ if (this.isRunning) return;
54
+ this.isRunning = true;
55
+ var processNext = function processNext() {
56
+ if (_this2.queue.length === 0) {
57
+ _this2.isRunning = false;
58
+ return;
59
+ }
60
+ var job = _this2.queue.shift();
61
+ if (job) {
62
+ job().then(processNext, processNext);
63
+ }
64
+ };
65
+ processNext();
66
+ }
67
+ }]);
68
+ return SerialJobExecutor;
69
+ }();
70
+ export function resolveValue(value) {
71
+ if (value === undefined) return Promise.resolve(undefined);
72
+ if (typeof value === 'function') {
73
+ return Promise.resolve(value());
74
+ }
75
+ return Promise.resolve(value);
76
+ }
@@ -1,9 +1,9 @@
1
- import { AbstractChat } from 'ai';
2
- import type { UIMessage, ChatState as BaseChatState, ChatStatus, ChatInit } from 'ai';
1
+ import { AbstractChat } from '../ai-lite';
2
+ import type { UIMessage, ChatState as BaseChatState, ChatStatus, ChatInit } from '../ai-lite';
3
3
  export type { UIMessage };
4
4
  export { AbstractChat };
5
5
  export { ChatInit };
6
- export declare const CACHE_KEY = "instantsearch-chat-initial-messages-";
6
+ export declare const CACHE_KEY = "instantsearch-chat-initial-messages";
7
7
  export declare class ChatState<TUiMessage extends UIMessage> implements BaseChatState<TUiMessage> {
8
8
  _messages: TUiMessage[];
9
9
  _status: ChatStatus;
@@ -23,11 +23,11 @@ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r),
23
23
  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; }
24
24
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
25
25
  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
- import { AbstractChat } from 'ai';
26
+ import { AbstractChat } from "../ai-lite/index.js";
27
27
  export { AbstractChat };
28
- export var CACHE_KEY = 'instantsearch-chat-initial-messages-';
28
+ export var CACHE_KEY = 'instantsearch-chat-initial-messages';
29
29
  function getDefaultInitialMessages(id) {
30
- var initialMessages = sessionStorage.getItem(CACHE_KEY + id);
30
+ var initialMessages = sessionStorage.getItem(CACHE_KEY + (id ? "-".concat(id) : ''));
31
31
  return initialMessages ? JSON.parse(initialMessages) : [];
32
32
  }
33
33
  export var ChatState = /*#__PURE__*/function () {
@@ -97,7 +97,7 @@ export var ChatState = /*#__PURE__*/function () {
97
97
  var saveMessagesInLocalStorage = function saveMessagesInLocalStorage() {
98
98
  if (_this.status === 'ready') {
99
99
  try {
100
- sessionStorage.setItem(CACHE_KEY + id, JSON.stringify(_this.messages));
100
+ sessionStorage.setItem(CACHE_KEY + (id ? "-".concat(id) : ''), JSON.stringify(_this.messages));
101
101
  } catch (e) {
102
102
  // Do nothing if sessionStorage is not available or full
103
103
  }
@@ -5,3 +5,6 @@ export { ChatState } from './chat';
5
5
  export { Chat } from './chat';
6
6
  export declare const SearchIndexToolType = "algolia_search_index";
7
7
  export declare const RecommendToolType = "algolia_recommend";
8
+ export declare const MemorizeToolType = "algolia_memorize";
9
+ export declare const MemorySearchToolType = "algolia_memory_search";
10
+ export declare const PonderToolType = "algolia_ponder";
@@ -2,4 +2,7 @@ export { AbstractChat } from "./chat.js";
2
2
  export { ChatState } from "./chat.js";
3
3
  export { Chat } from "./chat.js";
4
4
  export var SearchIndexToolType = 'algolia_search_index';
5
- export var RecommendToolType = 'algolia_recommend';
5
+ export var RecommendToolType = 'algolia_recommend';
6
+ export var MemorizeToolType = 'algolia_memorize';
7
+ export var MemorySearchToolType = 'algolia_memory_search';
8
+ export var PonderToolType = 'algolia_ponder';
@@ -1,2 +1,2 @@
1
- declare const _default: "4.86.1";
1
+ declare const _default: "4.87.1";
2
2
  export default _default;
package/es/lib/version.js CHANGED
@@ -1 +1 @@
1
- export default '4.86.1';
1
+ export default '4.87.1';
@@ -1,5 +1,5 @@
1
1
 
2
- import type { AutocompleteConnectorParams, AutocompleteRenderState, AutocompleteWidgetDescription } from '../../connectors/autocomplete/connectAutocomplete';
2
+ import type { AutocompleteConnectorParams, AutocompleteRenderState, AutocompleteWidgetDescription, TransformItemsIndicesConfig } from '../../connectors/autocomplete/connectAutocomplete';
3
3
  import type { BaseHit, IndexUiState, IndexWidget, Template, WidgetFactory } from '../../types';
4
4
  import type { PlainSearchParameters } from 'algoliasearch-helper';
5
5
  import type { AutocompleteClassNames, AutocompleteIndexClassNames, AutocompleteIndexConfig } from 'instantsearch-ui-components';
@@ -79,6 +79,7 @@ type AutocompleteWidgetParams<TItem extends BaseHit> = {
79
79
  }>;
80
80
  cssClasses?: Partial<AutocompleteIndexClassNames>;
81
81
  };
82
+ transformItems?: (indices: TransformItemsIndicesConfig[]) => TransformItemsIndicesConfig[];
82
83
  /**
83
84
  * Search parameters to apply to the autocomplete indices.
84
85
  */
@@ -171,7 +171,8 @@ function AutocompleteWrapper(_ref4) {
171
171
  query: searchboxQuery,
172
172
  showRecent: showRecent,
173
173
  indices: indices,
174
- indicesConfig: indicesConfig
174
+ indicesConfig: indicesConfig,
175
+ suggestionsIndexName: showSuggestions === null || showSuggestions === void 0 ? void 0 : showSuggestions.indexName
175
176
  }),
176
177
  storage = _useStorage.storage,
177
178
  storageHits = _useStorage.storageHits,
@@ -255,18 +256,24 @@ function AutocompleteWrapper(_ref4) {
255
256
  });
256
257
  }
257
258
  indices.forEach(function (_ref8, i) {
258
- var _indicesConfig$i$temp;
259
+ var _currentIndexConfig$t;
259
260
  var indexId = _ref8.indexId,
260
261
  indexName = _ref8.indexName,
261
262
  hits = _ref8.hits;
263
+ var currentIndexConfig = find(indicesConfig, function (config) {
264
+ return config.indexName === indexName;
265
+ });
266
+ if (!currentIndexConfig) {
267
+ return;
268
+ }
262
269
  if (!renderState.indexTemplateProps[i]) {
263
270
  renderState.indexTemplateProps[i] = prepareTemplateProps({
264
271
  defaultTemplates: {},
265
272
  templatesConfig: instantSearchInstance.templatesConfig,
266
- templates: indicesConfig[i].templates
273
+ templates: currentIndexConfig.templates
267
274
  });
268
275
  }
269
- var headerComponent = (_indicesConfig$i$temp = indicesConfig[i].templates) !== null && _indicesConfig$i$temp !== void 0 && _indicesConfig$i$temp.header ? function (_ref9) {
276
+ var headerComponent = (_currentIndexConfig$t = currentIndexConfig.templates) !== null && _currentIndexConfig$t !== void 0 && _currentIndexConfig$t.header ? function (_ref9) {
270
277
  var items = _ref9.items;
271
278
  return h(TemplateComponent, _extends({}, renderState.indexTemplateProps[i], {
272
279
  templateKey: "header",
@@ -306,7 +313,7 @@ function AutocompleteWrapper(_ref4) {
306
313
  });
307
314
  }),
308
315
  getItemProps: getItemProps,
309
- classNames: indicesConfig[i].cssClasses
316
+ classNames: currentIndexConfig.cssClasses
310
317
  });
311
318
  });
312
319
  return h(Autocomplete, _extends({}, getRootProps(), {
@@ -346,6 +353,7 @@ export function EXPERIMENTAL_autocomplete(widgetParams) {
346
353
  onSelect = _ref1.onSelect,
347
354
  _ref1$templates = _ref1.templates,
348
355
  templates = _ref1$templates === void 0 ? {} : _ref1$templates,
356
+ transformItems = _ref1.transformItems,
349
357
  _ref1$cssClasses = _ref1.cssClasses,
350
358
  userCssClasses = _ref1$cssClasses === void 0 ? {} : _ref1$cssClasses,
351
359
  placeholder = _ref1.placeholder;
@@ -430,7 +438,8 @@ export function EXPERIMENTAL_autocomplete(widgetParams) {
430
438
  indexId: indexName
431
439
  }).addWidgets([configure(indexSearchParameters || {})]);
432
440
  })), [_objectSpread(_objectSpread({}, makeWidget({
433
- escapeHTML: escapeHTML
441
+ escapeHTML: escapeHTML,
442
+ transformItems: transformItems
434
443
  })), {}, {
435
444
  $$widgetType: 'ais.autocomplete'
436
445
  })]))];