@docsearch/react 4.6.2 → 4.7.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,10 +1,10 @@
1
+ import { UIMessage } from '@ai-sdk/react';
2
+ import { UIDataTypes } from 'ai';
1
3
  import { BaseItem, AutocompleteState, AutocompleteContext, AutocompleteInsightsApi, AutocompleteOptions } from '@algolia/autocomplete-core';
2
4
  import { InitialAskAiMessage, DocSearchModalShortcuts, DocSearchRef, OnAskAiToggle } from '@docsearch/core';
3
5
  export { DocSearchRef } from '@docsearch/core';
4
6
  import { Hit, SearchParamsObject, LiteClient } from 'algoliasearch/lite';
5
7
  import React, { JSX } from 'react';
6
- import { UIMessage } from '@ai-sdk/react';
7
- import { UIDataTypes } from 'ai';
8
8
 
9
9
  type ContentType = 'askAI' | 'content' | 'lvl0' | 'lvl1' | 'lvl2' | 'lvl3' | 'lvl4' | 'lvl5' | 'lvl6';
10
10
  interface DocSearchHitAttributeHighlightResult {
@@ -174,6 +174,98 @@ type SuggestedQuestion = {
174
174
  };
175
175
  type SuggestedQuestionHit = Hit<SuggestedQuestion>;
176
176
 
177
+ type ExchangeWithOptionalAssistant = {
178
+ assistantMessage: AIMessage | null;
179
+ };
180
+ /**
181
+ * Pass-through: keep all exchanges when thread depth fails so the last user message stays visible
182
+ * (there is often no assistant reply for that turn).
183
+ */
184
+ declare function filterExchangesForThreadDepthError<T extends ExchangeWithOptionalAssistant>(exchanges: T[], _hasThreadDepthError: boolean): T[];
185
+ /**
186
+ * Whether the error is conversation depth exceeded (AI-217), including JSON-shaped Agent Studio payloads.
187
+ */
188
+ declare function isThreadDepthError(error?: Error): boolean;
189
+ /**
190
+ * Whether further prompts should be blocked: thread depth (all backends) or Agent Studio cost controls.
191
+ */
192
+ declare function isAskAiPromptBlockingError(error: Error | undefined, agentStudio: boolean): boolean;
193
+ /**
194
+ * Agent Studio stream hit the completion token ceiling (`TokenOutputLimitError`).
195
+ * This case uses a message-only banner (no “Start a new conversation” row).
196
+ */
197
+ declare function isAgentStudioTokenOutputLimitError(error?: Error): boolean;
198
+ /**
199
+ * Whether the blocking banner should include “Start a new conversation … to continue”.
200
+ * Thread depth and most Agent Studio limits keep it; token output limit and “request blocked for this domain” omit it.
201
+ */
202
+ declare function showAskAiBlockingBannerNewConversationLink(error: Error | undefined, agentStudio: boolean): boolean;
203
+ /**
204
+ * Pulls `message` or `error` from Agent Studio JSON payloads, including double-encoded JSON
205
+ * and objects serialized with escaped quotes (`{\"error\": \"...\"}`).
206
+ */
207
+ declare function extractAgentStudioErrorFieldMessage(raw: string): string | undefined;
208
+ /**
209
+ * Prefer the API `message` when the body was JSON; otherwise the thrown message (without a trailing `(AI-xxx)` suffix).
210
+ * Only meaningful when {@link isAskAiPromptBlockingError} would return true for this error.
211
+ */
212
+ declare function getAskAiPromptBlockingUserFacingMessage(error?: Error): string | undefined;
213
+ /**
214
+ * Message shown in the top blocking banner (parsed API text, never raw JSON when avoidable).
215
+ */
216
+ declare function getAskAiBlockingBannerMessage(error?: Error): string | undefined;
217
+ /**
218
+ * Prefer the API `message` field when the error body is JSON; otherwise the thrown message string.
219
+ * Only meaningful when {@link isThreadDepthError} is true.
220
+ */
221
+ declare function getThreadDepthErrorUserFacingMessage(error?: Error): string | undefined;
222
+
223
+ /**
224
+ * Registry of Agent Studio prompt-blocking matchers (cost controls, access, limits).
225
+ * Add cases here instead of scattering regex across call sites.
226
+ * Set `showNewConversationLink` to false to omit the “Start a new conversation … to continue” row when starting over does not fix the issue (for example, domain allowlisting).
227
+ */
228
+ type AgentStudioBlockingMatchContext = {
229
+ message: string;
230
+ messageLower: string;
231
+ parsedJson: Record<string, unknown> | null;
232
+ extractedCodeUpper: string | undefined;
233
+ };
234
+ type AgentStudioPromptBlockingMatcher = {
235
+ matches: (ctx: AgentStudioBlockingMatchContext) => boolean;
236
+ showNewConversationLink?: boolean;
237
+ };
238
+ /** Agent Studio cost / access control codes that block further input. */
239
+ declare const AGENT_STUDIO_PROMPT_BLOCKING_CODES: Set<string>;
240
+ declare function readAgentStudioJsonStringField(o: Record<string, unknown>, key: string): string | undefined;
241
+ declare function extractAiErrorCodeFromMessage(message: string): string | undefined;
242
+ /** Plain-text / stringified JSON heuristic; JSON-shaped payloads still use `isThreadDepthError` in `ai.ts`. */
243
+ declare function matchesThreadDepthLimitError(normalizedMessage: string): boolean;
244
+ /** API copy for domain allowlisting — starting a new conversation does not resolve it. */
245
+ declare function matchesRequestBlockedForThisDomainMessage(normalizedMessage: string): boolean;
246
+ declare function matchesAgentStudioMaxStepsMessage(normalizedMessage: string): boolean;
247
+ declare function matchesAgentStudioRateLimitMessage(normalizedMessage: string): boolean;
248
+ declare function matchesAgentStudioTokenOutputLimitPlainMessage(message: string): boolean;
249
+ declare function matchesAgentStudioWhitelistOrNotAllowedDomainPlainMessage(normalizedMessage: string): boolean;
250
+ declare function matchesAgentStudioContextOrTokenLimitsPlainMessage(normalizedMessage: string): boolean;
251
+ /**
252
+ * Ordered registry: first match does not win alone — `resolveAgentStudioPromptBlocking`
253
+ * OR-combines blocking and AND-combines “show new conversation” (any `false` hides the row).
254
+ */
255
+ declare const agentStudioPromptBlockingMatchers: AgentStudioPromptBlockingMatcher[];
256
+ declare function resolveAgentStudioPromptBlocking(error: Error): {
257
+ blocking: boolean;
258
+ showNewConversationLink: boolean;
259
+ };
260
+ /**
261
+ * Plain-text matchers over `Error.message.toLowerCase()` (callers pass `error.message.toLowerCase()`).
262
+ * Conversation depth / AI-217: first entry mirrors common plain cases; JSON-shaped payloads still need `isThreadDepthError` in `ai.ts`.
263
+ *
264
+ * Blocking UX and “Start new conversation” visibility are driven by `agentStudioPromptBlockingMatchers`.
265
+ */
266
+ type NewConversationErrorMatcher = (normalizedMessage: string) => boolean;
267
+ declare const newConversationErrorMatchers: NewConversationErrorMatcher[];
268
+
177
269
  type DocSearchTranslations = Partial<{
178
270
  button: ButtonTranslations;
179
271
  modal: ModalTranslations;
@@ -278,6 +370,8 @@ interface DocSearchProps {
278
370
  indices?: Array<DocSearchIndex | string>;
279
371
  /**
280
372
  * Configuration or assistant id to enable ask ai mode. Pass a string assistant id or a full config object.
373
+ *
374
+ * @deprecated Ask AI is being migrated from a standalone DocSearch feature into Algolia's Agent Studio. The `askAi` prop will be removed in DocSearch v5.
281
375
  */
282
376
  askAi?: DocSearchAskAi | string;
283
377
  /**
@@ -457,11 +551,7 @@ type AskAiScreenTranslations = Partial<{
457
551
  */
458
552
  errorTitleText: string;
459
553
  /**
460
- * Message shown when thread depth limit is exceeded (AI-217 error).
461
- */
462
- threadDepthExceededMessage: string;
463
- /**
464
- * Button text for starting a new conversation after thread depth error.
554
+ * Button text for starting a new conversation after a blocking Ask AI error.
465
555
  */
466
556
  startNewConversationButtonText: string;
467
557
  }>;
@@ -561,7 +651,7 @@ interface UseDocSearchKeyboardEventsProps {
561
651
  }
562
652
  declare function useDocSearchKeyboardEvents({ isOpen, onOpen, onClose, isAskAiActive, onAskAiToggle, keyboardShortcuts, }: UseDocSearchKeyboardEventsProps): void;
563
653
 
564
- declare const version = "4.6.2";
654
+ declare const version = "4.7.0";
565
655
 
566
- export { DocSearch, DocSearchButton, DocSearchInner, DocSearchModal, useDocSearchKeyboardEvents, version };
567
- export type { AgentStudioSearchParameters, AskAiSearchParameters, ButtonTranslations, DocSearchAskAi, DocSearchButtonProps, DocSearchHit, DocSearchIndex, DocSearchModalProps, DocSearchProps, DocSearchState, DocSearchTheme, DocSearchTransformClient, DocSearchTranslations, InternalDocSearchHit, KeyboardShortcuts, ModalTranslations, StoredAskAiMessage, StoredAskAiState, StoredDocSearchHit, SuggestedQuestion, SuggestedQuestionHit, UseDocSearchKeyboardEventsProps };
656
+ export { AGENT_STUDIO_PROMPT_BLOCKING_CODES, DocSearch, DocSearchButton, DocSearchInner, DocSearchModal, agentStudioPromptBlockingMatchers, extractAgentStudioErrorFieldMessage, extractAiErrorCodeFromMessage, filterExchangesForThreadDepthError, getAskAiBlockingBannerMessage, getAskAiPromptBlockingUserFacingMessage, getThreadDepthErrorUserFacingMessage, isAgentStudioTokenOutputLimitError, isAskAiPromptBlockingError, isThreadDepthError, matchesAgentStudioContextOrTokenLimitsPlainMessage, matchesAgentStudioMaxStepsMessage, matchesAgentStudioRateLimitMessage, matchesAgentStudioTokenOutputLimitPlainMessage, matchesAgentStudioWhitelistOrNotAllowedDomainPlainMessage, matchesRequestBlockedForThisDomainMessage, matchesThreadDepthLimitError, newConversationErrorMatchers, readAgentStudioJsonStringField, resolveAgentStudioPromptBlocking, showAskAiBlockingBannerNewConversationLink, useDocSearchKeyboardEvents, version };
657
+ export type { AgentStudioBlockingMatchContext, AgentStudioPromptBlockingMatcher, AgentStudioSearchParameters, AskAiSearchParameters, ButtonTranslations, DocSearchAskAi, DocSearchButtonProps, DocSearchHit, DocSearchIndex, DocSearchModalProps, DocSearchProps, DocSearchState, DocSearchTheme, DocSearchTransformClient, DocSearchTranslations, InternalDocSearchHit, KeyboardShortcuts, ModalTranslations, NewConversationErrorMatcher, StoredAskAiMessage, StoredAskAiState, StoredDocSearchHit, SuggestedQuestion, SuggestedQuestionHit, UseDocSearchKeyboardEventsProps };