@docsearch/react 5.0.2 → 5.0.4

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.
@@ -0,0 +1,270 @@
1
+ import { o as ToolCalls } from "./index-BijiN4hK.js";
2
+ import { _ as StoredSearchesSectionsTranslations, a as DocSearchProps, c as DocSearchTranslations, g as ErrorScreenTranslations, h as NoResultsScreenTranslations, m as ResultsScreenTranslations, v as FooterTranslations, y as FacetBarTranslations } from "./DocSearch-2gNxdJcC.js";
3
+ import { DocSearchRef, InitialAskAiMessage, OnAskAiToggle } from "@docsearch/core";
4
+ import React, { JSX } from "react";
5
+ import { AutocompleteState, BaseItem } from "@algolia/autocomplete-core";
6
+ import "@ai-sdk/react";
7
+ //#region src/components/ToolCall.d.ts
8
+ type ToolCallTranslations = {
9
+ /** Text shown while assistant is preparing tool call. */
10
+ preToolCallText: string;
11
+ /** Text shown while assistant is performing search tool call. */
12
+ searchingText: string;
13
+ /** Text shown while assistant is finished performing tool call. */
14
+ toolCallResultText: string;
15
+ /** Text shown when the agent saved related information to memory. */
16
+ savedMemoryToolResultText: string;
17
+ /** Text shown when the agent used the memory tool to enhance results. */
18
+ memoryToolResultText: string;
19
+ };
20
+ //#endregion
21
+ //#region src/AskAiScreen.d.ts
22
+ type AskAiScreenTranslations = Partial<Omit<ToolCallTranslations, 'searchingText' | 'toolCallResultText'> & {
23
+ disclaimerText: string;
24
+ /** Text shown describing a singular related source. */
25
+ relatedSourcesText: string;
26
+ /** Text shown describing multiple related sources. */
27
+ relatedSourcesTextPlural: string;
28
+ thinkingText: string;
29
+ copyButtonText: string;
30
+ copyButtonCopiedText: string;
31
+ copyButtonTitle: string;
32
+ likeButtonTitle: string;
33
+ dislikeButtonTitle: string;
34
+ thanksForFeedbackText: string;
35
+ feedbackPanelTitle: string;
36
+ feedbackDetailsPlaceholder: string;
37
+ feedbackDisclaimerText: string;
38
+ feedbackSubmitButtonText: string;
39
+ feedbackCloseButtonTitle: string;
40
+ feedbackTagIncorrect: string;
41
+ feedbackTagNotWhatIAsked: string;
42
+ feedbackTagSlowOrBuggy: string;
43
+ feedbackTagStyleOrTone: string;
44
+ feedbackTagSafetyOrLegal: string;
45
+ feedbackTagOther: string;
46
+ /**
47
+ * Text shown while assistant is performing search tool call. Maps to
48
+ * `ToolCallTranslations.searchingText`.
49
+ */
50
+ duringToolCallText: string;
51
+ /**
52
+ * Text shown while assistant is finished performing tool call. Maps to
53
+ * `ToolCallTranslations.toolCallResultText`.
54
+ */
55
+ afterToolCallText: string;
56
+ /**
57
+ * Build the full jsx element for the aggregated search block. If provided,
58
+ * completely overrides the default english renderer.
59
+ */
60
+ aggregatedToolCallNode?: (queries: string[], onSearchQueryClick: (query: string) => void) => React.ReactNode;
61
+ /**
62
+ * Generate the list connective parts only (backwards compatibility).
63
+ * Receives full list of queries and should return translation parts for
64
+ * before/after/separators. Example: (qs) => ({ before: 'searched for ',
65
+ * separator: ', ', lastSeparator: ' and ', after: '' }).
66
+ */
67
+ aggregatedToolCallText?: (queries: string[]) => {
68
+ before?: string;
69
+ separator?: string;
70
+ lastSeparator?: string;
71
+ after?: string;
72
+ };
73
+ /** Message that's shown when user has stopped the streaming of a message. */
74
+ stoppedStreamingText: string;
75
+ /** Error title shown if there is an error while chatting. */
76
+ errorTitleText: string;
77
+ /** Message shown when thread depth limit is exceeded (AI-217 error). */
78
+ threadDepthExceededMessage: string;
79
+ /** Button text for starting a new conversation after thread depth error. */
80
+ startNewConversationButtonText: string;
81
+ suggestedPromptsTitleText: string;
82
+ }>;
83
+ //#endregion
84
+ //#region src/components/ui/RecentConversationsResults.d.ts
85
+ type RecentConversationsResultsTranslations = Partial<{
86
+ recentConversationsTitle: string;
87
+ removeRecentConversationButtonTitle: string;
88
+ }>;
89
+ //#endregion
90
+ //#region src/components/AskAiStartScreen.d.ts
91
+ type AskAiStartScreenTranslations = RecentConversationsResultsTranslations & StoredSearchesSectionsTranslations;
92
+ //#endregion
93
+ //#region src/NewConversationScreen.d.ts
94
+ type NewConversationTranslations = Partial<{
95
+ newConversationTitle: string;
96
+ newConversationDescription: string;
97
+ }>;
98
+ //#endregion
99
+ //#region src/AskAiScreenState.d.ts
100
+ type AskAiScreenStateTranslations = Partial<{
101
+ errorScreen: ErrorScreenTranslations;
102
+ startScreen: AskAiStartScreenTranslations;
103
+ noResultsScreen: NoResultsScreenTranslations;
104
+ resultsScreen: ResultsScreenTranslations;
105
+ askAiScreen: AskAiScreenTranslations;
106
+ newConversation: NewConversationTranslations;
107
+ }>;
108
+ //#endregion
109
+ //#region src/components/AskAiSearchBox.d.ts
110
+ type AskAiSearchBoxTranslations = Partial<{
111
+ clearButtonTitle: string;
112
+ clearButtonAriaLabel: string;
113
+ closeButtonText: string;
114
+ closeButtonAriaLabel: string;
115
+ placeholderText: string;
116
+ placeholderTextAskAi: string;
117
+ placeholderTextAskAiStreaming: string;
118
+ enterKeyHint: string;
119
+ enterKeyHintAskAi: string;
120
+ searchInputLabel: string;
121
+ backToKeywordSearchButtonText: string;
122
+ backToKeywordSearchButtonAriaLabel: string;
123
+ newConversationPlaceholder: string;
124
+ conversationHistoryTitle: string;
125
+ startNewConversationText: string;
126
+ viewConversationHistoryText: string;
127
+ threadDepthErrorPlaceholder: string;
128
+ }>;
129
+ //#endregion
130
+ //#region src/DocSearchAskAiModal.d.ts
131
+ type DocSearchAskAiModalTranslations = AskAiScreenStateTranslations & Partial<{
132
+ searchBox: AskAiSearchBoxTranslations;
133
+ newConversation: NewConversationTranslations;
134
+ footer: FooterTranslations;
135
+ facets: FacetBarTranslations;
136
+ }>;
137
+ type DocSearchAskAiModalProps = DocSearchAIProps & {
138
+ initialScrollY: number;
139
+ onAskAiToggle: OnAskAiToggle;
140
+ onClose?: () => void;
141
+ isAskAiActive?: boolean;
142
+ translations?: DocSearchAskAiModalTranslations;
143
+ isHybridModeSupported?: boolean;
144
+ };
145
+ declare function DocSearchAskAiModal({ appId, apiKey, askAi, maxResultsPerGroup, theme, onClose, transformItems, hitComponent, resultsFooterComponent, navigator, initialScrollY, transformSearchClient, disableUserPersonalization, initialQuery: initialQueryFromProp, translations, getMissingResultsUrl, insights, onAskAiToggle, interceptAskAiEvent, isAskAiActive, recentSearchesLimit, recentSearchesWithFavoritesLimit, indices, facets, isHybridModeSupported, footerAction, ...props }: DocSearchAskAiModalProps): JSX.Element;
146
+ //#endregion
147
+ //#region src/DocSearchAI.d.ts
148
+ interface AskAiSearchParameters {
149
+ facetFilters?: string[];
150
+ filters?: string;
151
+ attributesToRetrieve?: string[];
152
+ restrictSearchableAttributes?: string[];
153
+ distinct?: boolean | number | string;
154
+ }
155
+ type AgentStudioSearchParameters = Record<string, Omit<AskAiSearchParameters, 'facetFilters'>>;
156
+ interface Memory {
157
+ /**
158
+ * Determines whether or not to display the memory based tool calls.
159
+ *
160
+ * @default false
161
+ */
162
+ enabled?: boolean;
163
+ /**
164
+ * The JWT used by the agent to know which user's memory to read.
165
+ *
166
+ * @see https://www.algolia.com/doc/guides/algolia-ai/agent-studio/how-to/user-authentication
167
+ */
168
+ userToken?: string;
169
+ }
170
+ interface PromptSuggestions {
171
+ /** The name of the index where the prompt suggestions are stored. */
172
+ indexName: string;
173
+ /**
174
+ * The number of prompt suggestions that are retrieved and displayed.
175
+ *
176
+ * @default 3
177
+ */
178
+ hitsPerPage?: number;
179
+ }
180
+ interface DocSearchAskAi {
181
+ /**
182
+ * The API key to use for the ask AI feature. Your assistant will use this API
183
+ * key to search the index. If not provided, the API key will be used.
184
+ */
185
+ apiKey?: string;
186
+ /**
187
+ * The app ID to use for the ask AI feature. Your assistant will use this app
188
+ * ID to search the index. If not provided, the app ID will be used.
189
+ */
190
+ appId?: string;
191
+ /** The Agent Studio Agent ID to use for the Ask AI feature. */
192
+ agentId: string;
193
+ /**
194
+ * Enables displaying suggested questions on Ask AI's new conversation screen.
195
+ *
196
+ * @default false
197
+ */
198
+ suggestedQuestions?: boolean;
199
+ /**
200
+ * The search parameters to use for the ask AI feature. Keyed by the index
201
+ * name.
202
+ *
203
+ * @example
204
+ * {
205
+ * "INDEX_NAME": { distinct: false }
206
+ * }
207
+ */
208
+ searchParameters?: AgentStudioSearchParameters;
209
+ /**
210
+ * Index names for the Agent Studio search tool on this request.
211
+ *
212
+ * Agent Studio expects names only. Put descriptions and tool defaults on the
213
+ * agent configuration. Put per-index runtime overrides in
214
+ * `searchParameters`.
215
+ */
216
+ indices?: string[];
217
+ /**
218
+ * Use custom tools driven by Agent Studio.
219
+ *
220
+ * For best performance, memoize this object with `useMemo` or define it
221
+ * outside the component. Inline object literals will be recreated every
222
+ * render but will not affect correctness.
223
+ */
224
+ tools?: ToolCalls;
225
+ /**
226
+ * Configuration for the Agent Studio memory feature.
227
+ *
228
+ * @example
229
+ * { enabled: true, userToken: '{{SERVER_GENERATED_JWT_TOKEN}}' }
230
+ *
231
+ * @see https://www.algolia.com/doc/guides/algolia-ai/agent-studio/how-to/memory/overview
232
+ */
233
+ memory?: Memory;
234
+ /**
235
+ * Enables and configures prompt suggestions that are displayed during keyword
236
+ * search.
237
+ *
238
+ * @example
239
+ * { indexName: 'docsearch-markdown_prompt_suggestions', hitsPerPage: 1 }
240
+ *
241
+ * @see https://www.algolia.com/doc/guides/algolia-ai/agent-studio/how-to/integration#prompt-suggestions
242
+ */
243
+ promptSuggestions?: PromptSuggestions;
244
+ }
245
+ type DocSearchAITranslations = Partial<{
246
+ button: DocSearchTranslations['button'];
247
+ modal: DocSearchAskAiModalTranslations;
248
+ }>;
249
+ interface DocSearchAIProps extends Omit<DocSearchProps, 'translations'> {
250
+ /**
251
+ * Configuration or assistant id to enable ask ai mode. Pass a string
252
+ * assistant id or a full config object.
253
+ */
254
+ askAi: DocSearchAskAi | string;
255
+ /**
256
+ * Intercept Ask AI requests (e.g. Submitting a prompt or selecting a
257
+ * suggested question).
258
+ *
259
+ * Return `true` to prevent the default modal Ask AI flow (no toggle, no
260
+ * sendMessage). Useful to route Ask AI into a different UI (e.g.
261
+ * `@docsearch/sidepanel-js`) without flicker.
262
+ */
263
+ interceptAskAiEvent?: (initialMessage: InitialAskAiMessage) => boolean | void;
264
+ translations?: DocSearchAITranslations;
265
+ }
266
+ declare const DocSearchAI: React.ForwardRefExoticComponent<DocSearchAIProps & React.RefAttributes<DocSearchRef>>;
267
+ declare function DocSearchAIInner(props: Omit<DocSearchAIProps, 'appId' | 'apiKey'>): JSX.Element;
268
+ //#endregion
269
+ export { DocSearchAIProps as a, Memory as c, DocSearchAskAiModalProps as d, DocSearchAskAiModalTranslations as f, DocSearchAIInner as i, PromptSuggestions as l, AskAiSearchParameters as n, DocSearchAITranslations as o, ToolCallTranslations as p, DocSearchAI as r, DocSearchAskAi as s, AgentStudioSearchParameters as t, DocSearchAskAiModal as u };
270
+ //# sourceMappingURL=DocSearchAI-DKtAqje2.d.ts.map
@@ -493,18 +493,16 @@ const EMPTY_SNIPPET_RESULT = {
493
493
  hierarchy: EMPTY_HIERARCHY_HIGHLIGHT_RESULT,
494
494
  hierarchy_camel: []
495
495
  };
496
- function buildRecentConversationSources({ conversations, disableUserPersonalization, setMessages, onAskAiToggle }) {
496
+ function buildRecentConversationSources({ conversations, disableUserPersonalization, handleSelectStoredConversation }) {
497
497
  return [{
498
498
  sourceId: SOURCE_IDS.recentConversations,
499
499
  getItems() {
500
500
  if (disableUserPersonalization) return [];
501
501
  return conversations.getAll().slice(0, MAX_RECENT_CONVERSATIONS_DISPLAYED);
502
502
  },
503
- onSelect({ item }) {
504
- if (item.messages) {
505
- setMessages(item.messages);
506
- onAskAiToggle(true);
507
- }
503
+ onSelect({ item, event }) {
504
+ if (item.type !== "askAI") return;
505
+ handleSelectStoredConversation(item, event);
508
506
  }
509
507
  }];
510
508
  }
@@ -661,7 +659,7 @@ function DocSearchAskAiModal(_ref) {
661
659
  recentSearchesWithFavoritesLimit
662
660
  });
663
661
  const [stoppedStream, setStoppedStream] = React.useState(false);
664
- const { chatId, messages, status, setMessages, sendMessage, stopAskAiStreaming, askAiError, sendFeedback, conversations, startNewConversation, restoreConversation } = useAskAi({
662
+ const { chatId, messages, status, sendMessage, stopAskAiStreaming, askAiError, sendFeedback, conversations, startNewConversation, restoreConversation } = useAskAi({
665
663
  agentId: askAiConfigurationId,
666
664
  apiKey: (askAiConfig === null || askAiConfig === void 0 ? void 0 : askAiConfig.apiKey) || apiKey,
667
665
  appId: (askAiConfig === null || askAiConfig === void 0 ? void 0 : askAiConfig.appId) || appId,
@@ -755,6 +753,25 @@ function DocSearchAskAiModal(_ref) {
755
753
  appId,
756
754
  sendFeedback
757
755
  ]);
756
+ const handleSelectStoredConversation = React.useCallback((item, event) => {
757
+ if (isQueryEmpty(item.query) || !item.messages || item.messages.length < 1) return;
758
+ const hitMessages = item.messages;
759
+ const initialMessage = {
760
+ query: item.query,
761
+ messageId: hitMessages[0].id
762
+ };
763
+ restoreConversation(hitMessages, item.chatId);
764
+ if (interceptAskAiEvent === null || interceptAskAiEvent === void 0 ? void 0 : interceptAskAiEvent(initialMessage)) {
765
+ if (autocompleteRef.current) autocompleteRef.current.setQuery("");
766
+ event.preventDefault();
767
+ return;
768
+ }
769
+ onAskAiToggle(true, initialMessage);
770
+ }, [
771
+ interceptAskAiEvent,
772
+ restoreConversation,
773
+ onAskAiToggle
774
+ ]);
758
775
  if (!autocompleteRef.current) autocompleteRef.current = createAutocomplete({
759
776
  id: "docsearch",
760
777
  defaultActiveItemId: 0,
@@ -780,8 +797,7 @@ function DocSearchAskAiModal(_ref) {
780
797
  return [...canHandleAskAi ? buildRecentConversationSources({
781
798
  conversations,
782
799
  disableUserPersonalization,
783
- setMessages,
784
- onAskAiToggle
800
+ handleSelectStoredConversation
785
801
  }) : [], ...noQuerySources];
786
802
  }
787
803
  const algoliaSourcesPromise = buildQuerySources({
@@ -937,20 +953,8 @@ function DocSearchAskAiModal(_ref) {
937
953
  onNewConversation: handleNewConversation,
938
954
  onItemClick: (item, event) => {
939
955
  if (item.type === "askAI" && item.query) {
940
- if (item.anchor === "stored" && "messages" in item) {
941
- const hitMessages = item.messages;
942
- restoreConversation(hitMessages, item.chatId);
943
- const initialMessage = {
944
- query: item.query,
945
- messageId: hitMessages[0].id
946
- };
947
- if (interceptAskAiEvent === null || interceptAskAiEvent === void 0 ? void 0 : interceptAskAiEvent(initialMessage)) {
948
- if (autocompleteRef.current) autocompleteRef.current.setQuery("");
949
- event.preventDefault();
950
- return;
951
- }
952
- onAskAiToggle(true, initialMessage);
953
- } else handleSelectAskAiQuestion(true, item.query);
956
+ if (item.anchor === "stored") handleSelectStoredConversation(item, event);
957
+ else handleSelectAskAiQuestion(true, item.query);
954
958
  setAskAiState("initial");
955
959
  event.preventDefault();
956
960
  return;
@@ -972,4 +976,4 @@ function DocSearchAskAiModal(_ref) {
972
976
 
973
977
  //#endregion
974
978
  export { DocSearchAskAiModal as t };
975
- //# sourceMappingURL=DocSearchAskAiModal-mjZ_EYK1.js.map
979
+ //# sourceMappingURL=DocSearchAskAiModal-BzQZxvTY.js.map