@docsearch/react 3.9.0 → 4.0.0-beta.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.
- package/dist/esm/index.d.ts +99 -11
- package/dist/esm/index.js +1 -1
- package/dist/umd/index.js +2 -2
- package/dist/umd/index.js.map +1 -1
- package/package.json +11 -7
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BaseItem, AutocompleteState, AutocompleteContext, AutocompleteInsightsApi, AutocompleteOptions } from '@algolia/autocomplete-core';
|
|
2
2
|
import { LiteClient, SearchParamsObject } from 'algoliasearch/lite';
|
|
3
3
|
import React, { JSX } from 'react';
|
|
4
|
+
import { Message } from '@ai-sdk/react';
|
|
4
5
|
|
|
5
|
-
type ContentType = 'content' | 'lvl0' | 'lvl1' | 'lvl2' | 'lvl3' | 'lvl4' | 'lvl5' | 'lvl6';
|
|
6
|
+
type ContentType = 'askAI' | 'content' | 'lvl0' | 'lvl1' | 'lvl2' | 'lvl3' | 'lvl4' | 'lvl5' | 'lvl6';
|
|
6
7
|
interface DocSearchHitAttributeHighlightResult {
|
|
7
8
|
value: string;
|
|
8
9
|
matchLevel: 'full' | 'none' | 'partial';
|
|
@@ -35,6 +36,7 @@ interface DocSearchHitSnippetResult {
|
|
|
35
36
|
declare type DocSearchHit = {
|
|
36
37
|
objectID: string;
|
|
37
38
|
content: string | null;
|
|
39
|
+
query?: string;
|
|
38
40
|
url: string;
|
|
39
41
|
url_without_anchor: string;
|
|
40
42
|
type: ContentType;
|
|
@@ -86,11 +88,20 @@ interface DocSearchState<TItem extends BaseItem> extends AutocompleteState<TItem
|
|
|
86
88
|
context: DocSearchContext;
|
|
87
89
|
}
|
|
88
90
|
|
|
91
|
+
type DocSearchTheme = 'dark' | 'light';
|
|
92
|
+
|
|
89
93
|
type InternalDocSearchHit = DocSearchHit & {
|
|
90
94
|
__docsearch_parent: InternalDocSearchHit | null;
|
|
91
95
|
};
|
|
92
96
|
|
|
93
97
|
type StoredDocSearchHit = Omit<DocSearchHit, '_highlightResult' | '_snippetResult'>;
|
|
98
|
+
type StoredAskAiMessage = Message & {
|
|
99
|
+
/** Optional user feedback on this assistant message. */
|
|
100
|
+
feedback?: 'dislike' | 'like';
|
|
101
|
+
};
|
|
102
|
+
type StoredAskAiState = Omit<DocSearchHit, '_highlightResult' | '_snippetResult'> & {
|
|
103
|
+
messages?: StoredAskAiMessage[];
|
|
104
|
+
};
|
|
94
105
|
|
|
95
106
|
type DocSearchTranslations = Partial<{
|
|
96
107
|
button: ButtonTranslations;
|
|
@@ -101,10 +112,33 @@ type DocSearchTransformClient = {
|
|
|
101
112
|
addAlgoliaAgent: LiteClient['addAlgoliaAgent'];
|
|
102
113
|
transporter: Pick<LiteClient['transporter'], 'algoliaAgent'>;
|
|
103
114
|
};
|
|
115
|
+
type DocSearchAskAi = {
|
|
116
|
+
/**
|
|
117
|
+
* The index name to use for the ask AI feature. Your assistant will search this index for relevant documents.
|
|
118
|
+
* If not provided, the index name will be used.
|
|
119
|
+
*/
|
|
120
|
+
indexName?: string;
|
|
121
|
+
/**
|
|
122
|
+
* The API key to use for the ask AI feature. Your assistant will use this API key to search the index.
|
|
123
|
+
* If not provided, the API key will be used.
|
|
124
|
+
*/
|
|
125
|
+
apiKey?: string;
|
|
126
|
+
/**
|
|
127
|
+
* The app ID to use for the ask AI feature. Your assistant will use this app ID to search the index.
|
|
128
|
+
* If not provided, the app ID will be used.
|
|
129
|
+
*/
|
|
130
|
+
appId?: string;
|
|
131
|
+
/**
|
|
132
|
+
* The assistant ID to use for the ask AI feature.
|
|
133
|
+
*/
|
|
134
|
+
assistantId: string | null;
|
|
135
|
+
};
|
|
104
136
|
interface DocSearchProps {
|
|
105
137
|
appId: string;
|
|
106
138
|
apiKey: string;
|
|
107
139
|
indexName: string;
|
|
140
|
+
askAi?: DocSearchAskAi | string;
|
|
141
|
+
theme?: DocSearchTheme;
|
|
108
142
|
placeholder?: string;
|
|
109
143
|
searchParameters?: SearchParamsObject;
|
|
110
144
|
maxResultsPerGroup?: number;
|
|
@@ -126,26 +160,60 @@ interface DocSearchProps {
|
|
|
126
160
|
}) => string;
|
|
127
161
|
insights?: AutocompleteOptions<InternalDocSearchHit>['insights'];
|
|
128
162
|
}
|
|
129
|
-
declare function DocSearch(props: DocSearchProps): JSX.Element;
|
|
163
|
+
declare function DocSearch({ ...props }: DocSearchProps): JSX.Element;
|
|
130
164
|
|
|
131
165
|
type ButtonTranslations = Partial<{
|
|
132
166
|
buttonText: string;
|
|
133
167
|
buttonAriaLabel: string;
|
|
134
168
|
}>;
|
|
135
169
|
type DocSearchButtonProps = React.ComponentProps<'button'> & {
|
|
170
|
+
theme?: DocSearchTheme;
|
|
136
171
|
translations?: ButtonTranslations;
|
|
137
172
|
};
|
|
138
173
|
declare const DocSearchButton: React.ForwardRefExoticComponent<Omit<DocSearchButtonProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
139
174
|
|
|
140
175
|
type FooterTranslations = Partial<{
|
|
141
176
|
selectText: string;
|
|
177
|
+
submitQuestionText: string;
|
|
142
178
|
selectKeyAriaLabel: string;
|
|
143
179
|
navigateText: string;
|
|
144
180
|
navigateUpKeyAriaLabel: string;
|
|
145
181
|
navigateDownKeyAriaLabel: string;
|
|
146
182
|
closeText: string;
|
|
183
|
+
backToSearchText: string;
|
|
147
184
|
closeKeyAriaLabel: string;
|
|
148
|
-
|
|
185
|
+
poweredByText: string;
|
|
186
|
+
}>;
|
|
187
|
+
|
|
188
|
+
type AskAiScreenTranslations = Partial<{
|
|
189
|
+
disclaimerText: string;
|
|
190
|
+
relatedSourcesText: string;
|
|
191
|
+
thinkingText: string;
|
|
192
|
+
copyButtonText: string;
|
|
193
|
+
copyButtonCopiedText: string;
|
|
194
|
+
copyButtonTitle: string;
|
|
195
|
+
likeButtonTitle: string;
|
|
196
|
+
dislikeButtonTitle: string;
|
|
197
|
+
thanksForFeedbackText: string;
|
|
198
|
+
preToolCallText: string;
|
|
199
|
+
duringToolCallText: string;
|
|
200
|
+
afterToolCallText: string;
|
|
201
|
+
/**
|
|
202
|
+
* Build the full jsx element for the aggregated search block.
|
|
203
|
+
* If provided, completely overrides the default english renderer.
|
|
204
|
+
*/
|
|
205
|
+
aggregatedToolCallNode?: (queries: string[], onSearchQueryClick: (query: string) => void) => React.ReactNode;
|
|
206
|
+
/**
|
|
207
|
+
* Generate the list connective parts only (backwards compatibility).
|
|
208
|
+
* Receives full list of queries and should return translation parts for before/after/separators.
|
|
209
|
+
* Example: (qs) => ({ before: 'searched for ', separator: ', ', lastSeparator: ' and ', after: '' }).
|
|
210
|
+
*/
|
|
211
|
+
aggregatedToolCallText?: (queries: string[]) => {
|
|
212
|
+
before?: string;
|
|
213
|
+
separator?: string;
|
|
214
|
+
lastSeparator?: string;
|
|
215
|
+
after?: string;
|
|
216
|
+
};
|
|
149
217
|
}>;
|
|
150
218
|
|
|
151
219
|
type ErrorScreenTranslations = Partial<{
|
|
@@ -160,6 +228,10 @@ type NoResultsScreenTranslations = Partial<{
|
|
|
160
228
|
reportMissingResultsLinkText: string;
|
|
161
229
|
}>;
|
|
162
230
|
|
|
231
|
+
type ResultsScreenTranslations = Partial<{
|
|
232
|
+
askAiPlaceholder: string;
|
|
233
|
+
}>;
|
|
234
|
+
|
|
163
235
|
type StartScreenTranslations = Partial<{
|
|
164
236
|
recentSearchesTitle: string;
|
|
165
237
|
noRecentSearchesText: string;
|
|
@@ -167,20 +239,31 @@ type StartScreenTranslations = Partial<{
|
|
|
167
239
|
removeRecentSearchButtonTitle: string;
|
|
168
240
|
favoriteSearchesTitle: string;
|
|
169
241
|
removeFavoriteSearchButtonTitle: string;
|
|
242
|
+
recentConversationsTitle: string;
|
|
243
|
+
removeRecentConversationButtonTitle: string;
|
|
170
244
|
}>;
|
|
171
245
|
|
|
172
246
|
type ScreenStateTranslations = Partial<{
|
|
173
247
|
errorScreen: ErrorScreenTranslations;
|
|
174
248
|
startScreen: StartScreenTranslations;
|
|
175
249
|
noResultsScreen: NoResultsScreenTranslations;
|
|
250
|
+
resultsScreen: ResultsScreenTranslations;
|
|
251
|
+
askAiScreen: AskAiScreenTranslations;
|
|
176
252
|
}>;
|
|
177
253
|
|
|
178
254
|
type SearchBoxTranslations = Partial<{
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
255
|
+
clearButtonTitle: string;
|
|
256
|
+
clearButtonAriaLabel: string;
|
|
257
|
+
closeButtonText: string;
|
|
258
|
+
closeButtonAriaLabel: string;
|
|
259
|
+
placeholderText: string;
|
|
260
|
+
placeholderTextAskAi: string;
|
|
261
|
+
placeholderTextAskAiStreaming: string;
|
|
262
|
+
enterKeyHint: string;
|
|
263
|
+
enterKeyHintAskAi: string;
|
|
183
264
|
searchInputLabel: string;
|
|
265
|
+
backToKeywordSearchButtonText: string;
|
|
266
|
+
backToKeywordSearchButtonAriaLabel: string;
|
|
184
267
|
}>;
|
|
185
268
|
|
|
186
269
|
type ModalTranslations = Partial<{
|
|
@@ -189,10 +272,13 @@ type ModalTranslations = Partial<{
|
|
|
189
272
|
}> & ScreenStateTranslations;
|
|
190
273
|
type DocSearchModalProps = DocSearchProps & {
|
|
191
274
|
initialScrollY: number;
|
|
275
|
+
onAskAiToggle: (toggle: boolean) => void;
|
|
192
276
|
onClose?: () => void;
|
|
277
|
+
isAskAiActive?: boolean;
|
|
278
|
+
canHandleAskAi?: boolean;
|
|
193
279
|
translations?: ModalTranslations;
|
|
194
280
|
};
|
|
195
|
-
declare function DocSearchModal({ appId, apiKey, indexName, placeholder, searchParameters, maxResultsPerGroup, onClose, transformItems, hitComponent, resultsFooterComponent, navigator, initialScrollY, transformSearchClient, disableUserPersonalization, initialQuery: initialQueryFromProp, translations, getMissingResultsUrl, insights, }: DocSearchModalProps): JSX.Element;
|
|
281
|
+
declare function DocSearchModal({ appId, apiKey, indexName, placeholder, askAi, searchParameters, maxResultsPerGroup, theme, onClose, transformItems, hitComponent, resultsFooterComponent, navigator, initialScrollY, transformSearchClient, disableUserPersonalization, initialQuery: initialQueryFromProp, translations, getMissingResultsUrl, insights, onAskAiToggle, isAskAiActive, canHandleAskAi, }: DocSearchModalProps): JSX.Element;
|
|
196
282
|
|
|
197
283
|
interface UseDocSearchKeyboardEventsProps {
|
|
198
284
|
isOpen: boolean;
|
|
@@ -200,9 +286,11 @@ interface UseDocSearchKeyboardEventsProps {
|
|
|
200
286
|
onClose: () => void;
|
|
201
287
|
onInput?: (event: KeyboardEvent) => void;
|
|
202
288
|
searchButtonRef: React.RefObject<HTMLButtonElement | null>;
|
|
289
|
+
isAskAiActive: boolean;
|
|
290
|
+
onAskAiToggle: (toggle: boolean) => void;
|
|
203
291
|
}
|
|
204
|
-
declare function useDocSearchKeyboardEvents({ isOpen, onOpen, onClose, onInput, searchButtonRef, }: UseDocSearchKeyboardEventsProps): void;
|
|
292
|
+
declare function useDocSearchKeyboardEvents({ isOpen, onOpen, onClose, onInput, isAskAiActive, onAskAiToggle, searchButtonRef, }: UseDocSearchKeyboardEventsProps): void;
|
|
205
293
|
|
|
206
|
-
declare const version = "
|
|
294
|
+
declare const version = "4.0.0-beta.0";
|
|
207
295
|
|
|
208
|
-
export { type ButtonTranslations, DocSearch, DocSearchButton, type DocSearchButtonProps, type DocSearchHit, DocSearchModal, type DocSearchModalProps, type DocSearchProps, type DocSearchState, type DocSearchTransformClient, type DocSearchTranslations, type InternalDocSearchHit, type ModalTranslations, type StoredDocSearchHit, type UseDocSearchKeyboardEventsProps, useDocSearchKeyboardEvents, version };
|
|
296
|
+
export { type ButtonTranslations, DocSearch, type DocSearchAskAi, DocSearchButton, type DocSearchButtonProps, type DocSearchHit, DocSearchModal, type DocSearchModalProps, type DocSearchProps, type DocSearchState, type DocSearchTheme, type DocSearchTransformClient, type DocSearchTranslations, type InternalDocSearchHit, type ModalTranslations, type StoredAskAiMessage, type StoredAskAiState, type StoredDocSearchHit, type UseDocSearchKeyboardEventsProps, useDocSearchKeyboardEvents, version };
|