@docsearch/react 4.1.0 → 4.3.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.
@@ -1,5 +1,5 @@
1
1
  import { BaseItem, AutocompleteState, AutocompleteContext, AutocompleteInsightsApi, AutocompleteOptions } from '@algolia/autocomplete-core';
2
- import { LiteClient, SearchParamsObject } from 'algoliasearch/lite';
2
+ import { Hit, LiteClient, SearchParamsObject } from 'algoliasearch/lite';
3
3
  import React, { JSX } from 'react';
4
4
  import { UIMessage } from '@ai-sdk/react';
5
5
  import { UIDataTypes } from 'ai';
@@ -119,7 +119,9 @@ interface SearchIndexTool {
119
119
  hits?: any[];
120
120
  };
121
121
  }
122
- type AIMessage = UIMessage<unknown, UIDataTypes, {
122
+ type AIMessage = UIMessage<{
123
+ stopped?: boolean;
124
+ }, UIDataTypes, {
123
125
  searchIndex: SearchIndexTool;
124
126
  }>;
125
127
 
@@ -128,10 +130,22 @@ type StoredAskAiMessage = AIMessage & {
128
130
  /** Optional user feedback on this assistant message. */
129
131
  feedback?: 'dislike' | 'like';
130
132
  };
131
- type StoredAskAiState = Omit<DocSearchHit, '_highlightResult' | '_snippetResult'> & {
133
+ type StoredAskAiState = StoredDocSearchHit & {
134
+ stopped?: boolean;
132
135
  messages?: StoredAskAiMessage[];
133
136
  };
134
137
 
138
+ type SuggestedQuestion = {
139
+ appId: string;
140
+ assistantId: string;
141
+ question: string;
142
+ locale?: string;
143
+ state: 'published';
144
+ source: string;
145
+ order: number;
146
+ };
147
+ type SuggestedQuestionHit = Hit<SuggestedQuestion>;
148
+
135
149
  type DocSearchTranslations = Partial<{
136
150
  button: ButtonTranslations;
137
151
  modal: ModalTranslations;
@@ -141,6 +155,13 @@ type DocSearchTransformClient = {
141
155
  addAlgoliaAgent: LiteClient['addAlgoliaAgent'];
142
156
  transporter: Pick<LiteClient['transporter'], 'algoliaAgent'>;
143
157
  };
158
+ type AskAiSearchParameters = {
159
+ facetFilters?: string[];
160
+ filters?: string;
161
+ attributesToRetrieve?: string[];
162
+ restrictSearchableAttributes?: string[];
163
+ distinct?: boolean;
164
+ };
144
165
  type DocSearchAskAi = {
145
166
  /**
146
167
  * The index name to use for the ask AI feature. Your assistant will search this index for relevant documents.
@@ -164,9 +185,13 @@ type DocSearchAskAi = {
164
185
  /**
165
186
  * The search parameters to use for the ask AI feature.
166
187
  */
167
- searchParameters?: {
168
- facetFilters?: SearchParamsObject['facetFilters'];
169
- };
188
+ searchParameters?: AskAiSearchParameters;
189
+ /**
190
+ * Enables displaying suggested questions on Ask AI's new conversation screen.
191
+ *
192
+ * @default false
193
+ */
194
+ suggestedQuestions?: boolean;
170
195
  };
171
196
  interface DocSearchIndex {
172
197
  name: string;
@@ -221,16 +246,28 @@ interface DocSearchProps {
221
246
  transformItems?: (items: DocSearchHit[]) => DocSearchHit[];
222
247
  /**
223
248
  * Custom component to render an individual hit.
249
+ * Supports template patterns:
250
+ * - HTML strings with html helper: (props, { html }) => html`<div>...</div>`
251
+ * - JSX templates: (props) => <div>...</div>
252
+ * - Function-based templates: (props) => string | JSX.Element | Function.
224
253
  */
225
254
  hitComponent?: (props: {
226
255
  hit: InternalDocSearchHit | StoredDocSearchHit;
227
256
  children: React.ReactNode;
257
+ }, helpers?: {
258
+ html: (template: TemplateStringsArray, ...values: any[]) => any;
228
259
  }) => JSX.Element;
229
260
  /**
230
261
  * Custom component rendered at the bottom of the results panel.
262
+ * Supports template patterns:
263
+ * - HTML strings with html helper: (props, { html }) => html`<div>...</div>`
264
+ * - JSX templates: (props) => <div>...</div>
265
+ * - Function-based templates: (props) => string | JSX.Element | Function.
231
266
  */
232
267
  resultsFooterComponent?: (props: {
233
268
  state: AutocompleteState<InternalDocSearchHit>;
269
+ }, helpers?: {
270
+ html: (template: TemplateStringsArray, ...values: any[]) => any;
234
271
  }) => JSX.Element | null;
235
272
  /**
236
273
  * Hook to wrap or modify the algolia search client.
@@ -284,6 +321,7 @@ interface DocSearchProps {
284
321
  keyboardShortcuts?: KeyboardShortcuts;
285
322
  }
286
323
  declare function DocSearch(props: DocSearchProps): JSX.Element;
324
+ declare function DocSearchInner(props: DocSearchProps): JSX.Element;
287
325
 
288
326
  type ButtonTranslations = Partial<{
289
327
  buttonText: string;
@@ -309,6 +347,11 @@ type FooterTranslations = Partial<{
309
347
  poweredByText: string;
310
348
  }>;
311
349
 
350
+ type NewConversationTranslations = Partial<{
351
+ newConversationTitle: string;
352
+ newConversationDescription: string;
353
+ }>;
354
+
312
355
  type AskAiScreenTranslations = Partial<{
313
356
  disclaimerText: string;
314
357
  relatedSourcesText: string;
@@ -338,6 +381,10 @@ type AskAiScreenTranslations = Partial<{
338
381
  lastSeparator?: string;
339
382
  after?: string;
340
383
  };
384
+ /**
385
+ * Message that's shown when user has stopped the streaming of a message.
386
+ */
387
+ stoppedStreamingText: string;
341
388
  }>;
342
389
 
343
390
  type ErrorScreenTranslations = Partial<{
@@ -354,6 +401,7 @@ type NoResultsScreenTranslations = Partial<{
354
401
 
355
402
  type ResultsScreenTranslations = Partial<{
356
403
  askAiPlaceholder: string;
404
+ noResultsAskAiPlaceholder: string;
357
405
  }>;
358
406
 
359
407
  type StartScreenTranslations = Partial<{
@@ -373,6 +421,7 @@ type ScreenStateTranslations = Partial<{
373
421
  noResultsScreen: NoResultsScreenTranslations;
374
422
  resultsScreen: ResultsScreenTranslations;
375
423
  askAiScreen: AskAiScreenTranslations;
424
+ newConversation: NewConversationTranslations;
376
425
  }>;
377
426
 
378
427
  type SearchBoxTranslations = Partial<{
@@ -388,10 +437,15 @@ type SearchBoxTranslations = Partial<{
388
437
  searchInputLabel: string;
389
438
  backToKeywordSearchButtonText: string;
390
439
  backToKeywordSearchButtonAriaLabel: string;
440
+ newConversationPlaceholder: string;
441
+ conversationHistoryTitle: string;
442
+ startNewConversationText: string;
443
+ viewConversationHistoryText: string;
391
444
  }>;
392
445
 
393
446
  type ModalTranslations = Partial<{
394
447
  searchBox: SearchBoxTranslations;
448
+ newConversation: NewConversationTranslations;
395
449
  footer: FooterTranslations;
396
450
  }> & ScreenStateTranslations;
397
451
  type DocSearchModalProps = DocSearchProps & {
@@ -399,10 +453,9 @@ type DocSearchModalProps = DocSearchProps & {
399
453
  onAskAiToggle: (toggle: boolean) => void;
400
454
  onClose?: () => void;
401
455
  isAskAiActive?: boolean;
402
- canHandleAskAi?: boolean;
403
456
  translations?: ModalTranslations;
404
457
  };
405
- declare function DocSearchModal({ appId, apiKey, placeholder, askAi, maxResultsPerGroup, theme, onClose, transformItems, hitComponent, resultsFooterComponent, navigator, initialScrollY, transformSearchClient, disableUserPersonalization, initialQuery: initialQueryFromProp, translations, getMissingResultsUrl, insights, onAskAiToggle, isAskAiActive, canHandleAskAi, recentSearchesLimit, recentSearchesWithFavoritesLimit, indices, indexName, searchParameters, }: DocSearchModalProps): JSX.Element;
458
+ declare function DocSearchModal({ appId, apiKey, askAi, maxResultsPerGroup, theme, onClose, transformItems, hitComponent, resultsFooterComponent, navigator, initialScrollY, transformSearchClient, disableUserPersonalization, initialQuery: initialQueryFromProp, translations, getMissingResultsUrl, insights, onAskAiToggle, isAskAiActive, recentSearchesLimit, recentSearchesWithFavoritesLimit, indices, indexName, searchParameters, ...props }: DocSearchModalProps): JSX.Element;
406
459
 
407
460
  interface UseDocSearchKeyboardEventsProps {
408
461
  isOpen: boolean;
@@ -416,7 +469,7 @@ interface UseDocSearchKeyboardEventsProps {
416
469
  }
417
470
  declare function useDocSearchKeyboardEvents({ isOpen, onOpen, onClose, onInput, isAskAiActive, onAskAiToggle, searchButtonRef, keyboardShortcuts, }: UseDocSearchKeyboardEventsProps): void;
418
471
 
419
- declare const version = "4.1.0";
472
+ declare const version = "4.3.0";
420
473
 
421
- export { DocSearch, DocSearchButton, DocSearchModal, useDocSearchKeyboardEvents, version };
422
- export type { ButtonTranslations, DocSearchAskAi, DocSearchButtonProps, DocSearchHit, DocSearchIndex, DocSearchModalProps, DocSearchProps, DocSearchState, DocSearchTheme, DocSearchTransformClient, DocSearchTranslations, InternalDocSearchHit, KeyboardShortcuts, ModalTranslations, StoredAskAiMessage, StoredAskAiState, StoredDocSearchHit, UseDocSearchKeyboardEventsProps };
474
+ export { DocSearch, DocSearchButton, DocSearchInner, DocSearchModal, useDocSearchKeyboardEvents, version };
475
+ export type { AskAiSearchParameters, ButtonTranslations, DocSearchAskAi, DocSearchButtonProps, DocSearchHit, DocSearchIndex, DocSearchModalProps, DocSearchProps, DocSearchState, DocSearchTheme, DocSearchTransformClient, DocSearchTranslations, InternalDocSearchHit, KeyboardShortcuts, ModalTranslations, StoredAskAiMessage, StoredAskAiState, StoredDocSearchHit, SuggestedQuestion, SuggestedQuestionHit, UseDocSearchKeyboardEventsProps };