@docsearch/react 4.4.0 → 4.5.0-beta.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.
@@ -1,5 +1,6 @@
1
1
  import { BaseItem, AutocompleteState, AutocompleteContext, AutocompleteInsightsApi, AutocompleteOptions } from '@algolia/autocomplete-core';
2
- import { DocSearchModalShortcuts, OnAskAiToggle } from '@docsearch/core';
2
+ import { InitialAskAiMessage, DocSearchModalShortcuts, DocSearchRef, OnAskAiToggle } from '@docsearch/core';
3
+ export { DocSearchRef } from '@docsearch/core';
3
4
  import { Hit, LiteClient, SearchParamsObject } from 'algoliasearch/lite';
4
5
  import React, { JSX } from 'react';
5
6
  import { UIMessage } from '@ai-sdk/react';
@@ -120,11 +121,26 @@ interface SearchIndexTool {
120
121
  hits?: any[];
121
122
  };
122
123
  }
124
+ interface AgentStudioSearchTool {
125
+ input: {
126
+ index: string;
127
+ query: string;
128
+ number_of_results: number;
129
+ facet_filters: any | null;
130
+ };
131
+ output: {
132
+ hits?: any[];
133
+ nbHits?: number;
134
+ queryID?: string;
135
+ };
136
+ }
137
+ type Tools = {
138
+ searchIndex: SearchIndexTool;
139
+ algolia_search_index: AgentStudioSearchTool;
140
+ };
123
141
  type AIMessage = UIMessage<{
124
142
  stopped?: boolean;
125
- }, UIDataTypes, {
126
- searchIndex: SearchIndexTool;
127
- }>;
143
+ }, UIDataTypes, Tools>;
128
144
 
129
145
  type StoredDocSearchHit = Omit<DocSearchHit, '_highlightResult' | '_snippetResult'>;
130
146
  type StoredAskAiMessage = AIMessage & {
@@ -182,7 +198,7 @@ type DocSearchAskAi = {
182
198
  /**
183
199
  * The assistant ID to use for the ask AI feature.
184
200
  */
185
- assistantId: string | null;
201
+ assistantId: string;
186
202
  /**
187
203
  * The search parameters to use for the ask AI feature.
188
204
  */
@@ -193,6 +209,7 @@ type DocSearchAskAi = {
193
209
  * @default false
194
210
  */
195
211
  suggestedQuestions?: boolean;
212
+ useStagingEnv?: boolean;
196
213
  };
197
214
  interface DocSearchIndex {
198
215
  name: string;
@@ -223,6 +240,22 @@ interface DocSearchProps {
223
240
  * Configuration or assistant id to enable ask ai mode. Pass a string assistant id or a full config object.
224
241
  */
225
242
  askAi?: DocSearchAskAi | string;
243
+ /**
244
+ * Intercept Ask AI requests (e.g. Submitting a prompt or selecting a suggested question).
245
+ *
246
+ * Return `true` to prevent the default modal Ask AI flow (no toggle, no sendMessage).
247
+ * Useful to route Ask AI into a different UI (e.g. `@docsearch/sidepanel-js`) without flicker.
248
+ */
249
+ interceptAskAiEvent?: (initialMessage: InitialAskAiMessage) => boolean | void;
250
+ /**
251
+ * **Experimental:** Whether to use Agent Studio as the chat backend.
252
+ *
253
+ * This is an experimental feature and its API may change without notice in future releases.
254
+ * Use with caution in production environments.
255
+ *
256
+ * @default false
257
+ */
258
+ agentStudio?: boolean;
226
259
  /**
227
260
  * Theme overrides applied to the modal and related components.
228
261
  */
@@ -323,7 +356,7 @@ interface DocSearchProps {
323
356
  */
324
357
  keyboardShortcuts?: DocSearchModalShortcuts;
325
358
  }
326
- declare function DocSearch(props: DocSearchProps): JSX.Element;
359
+ declare const DocSearch: React.ForwardRefExoticComponent<DocSearchProps & React.RefAttributes<DocSearchRef>>;
327
360
  declare function DocSearchInner(props: DocSearchProps): JSX.Element;
328
361
 
329
362
  type ButtonTranslations = Partial<{
@@ -467,26 +500,37 @@ type ModalTranslations = Partial<{
467
500
  type DocSearchModalProps = DocSearchProps & {
468
501
  initialScrollY: number;
469
502
  onAskAiToggle: OnAskAiToggle;
503
+ interceptAskAiEvent?: (initialMessage: InitialAskAiMessage) => boolean | void;
470
504
  onClose?: () => void;
471
505
  isAskAiActive?: boolean;
472
506
  translations?: ModalTranslations;
473
507
  isHybridModeSupported?: boolean;
474
508
  };
475
- 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, isHybridModeSupported, ...props }: DocSearchModalProps): JSX.Element;
509
+ declare function DocSearchModal({ appId, apiKey, askAi, maxResultsPerGroup, theme, onClose, transformItems, hitComponent, resultsFooterComponent, navigator, initialScrollY, transformSearchClient, disableUserPersonalization, initialQuery: initialQueryFromProp, translations, getMissingResultsUrl, insights, onAskAiToggle, interceptAskAiEvent, isAskAiActive, recentSearchesLimit, recentSearchesWithFavoritesLimit, indices, indexName, searchParameters, isHybridModeSupported, agentStudio, ...props }: DocSearchModalProps): JSX.Element;
476
510
 
477
511
  interface UseDocSearchKeyboardEventsProps {
478
512
  isOpen: boolean;
479
513
  onOpen: () => void;
480
514
  onClose: () => void;
515
+ /**
516
+ * Deprecated: Still here for backwards compat.
517
+ *
518
+ * @deprecated
519
+ */
481
520
  onInput?: (event: KeyboardEvent) => void;
482
- searchButtonRef: React.RefObject<HTMLButtonElement | null>;
521
+ /**
522
+ * Deprecated: Still here for backwards compat.
523
+ *
524
+ * @deprecated
525
+ */
526
+ searchButtonRef?: React.RefObject<HTMLButtonElement | null>;
483
527
  isAskAiActive: boolean;
484
528
  onAskAiToggle: (toggle: boolean) => void;
485
529
  keyboardShortcuts?: KeyboardShortcuts;
486
530
  }
487
- declare function useDocSearchKeyboardEvents({ isOpen, onOpen, onClose, onInput, isAskAiActive, onAskAiToggle, searchButtonRef, keyboardShortcuts, }: UseDocSearchKeyboardEventsProps): void;
531
+ declare function useDocSearchKeyboardEvents({ isOpen, onOpen, onClose, isAskAiActive, onAskAiToggle, keyboardShortcuts, }: UseDocSearchKeyboardEventsProps): void;
488
532
 
489
- declare const version = "4.4.0";
533
+ declare const version = "4.5.0-beta.1";
490
534
 
491
535
  export { DocSearch, DocSearchButton, DocSearchInner, DocSearchModal, useDocSearchKeyboardEvents, version };
492
536
  export type { AskAiSearchParameters, ButtonTranslations, DocSearchAskAi, DocSearchButtonProps, DocSearchHit, DocSearchIndex, DocSearchModalProps, DocSearchProps, DocSearchState, DocSearchTheme, DocSearchTransformClient, DocSearchTranslations, InternalDocSearchHit, KeyboardShortcuts, ModalTranslations, StoredAskAiMessage, StoredAskAiState, StoredDocSearchHit, SuggestedQuestion, SuggestedQuestionHit, UseDocSearchKeyboardEventsProps };