UNPKG

react-instantsearch

Version:
92 lines (91 loc) 5.87 kB
import { SearchIndexToolType, RecommendToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, DisplayResultsToolType, GroupedResultsToolType } from 'instantsearch.js/es/lib/chat'; import React from 'react'; export { SearchIndexToolType, RecommendToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, DisplayResultsToolType, GroupedResultsToolType, }; import type { ChatProps as ChatUiProps, ChatLayoutOwnProps, RecommendComponentProps, RecordWithObjectID, UserClientSideTool, UserClientSideTools, ChatMessageProps } from 'instantsearch-ui-components'; import type { IndexUiState } from 'instantsearch.js'; import type { UIMessage } from 'instantsearch.js/es/lib/chat'; import type { UseChatProps } from 'react-instantsearch-core'; export declare function createDefaultTools<TObject extends RecordWithObjectID>(itemComponent?: ItemComponent<TObject>, getSearchPageURL?: (nextUiState: IndexUiState) => string): UserClientSideTools; type ItemComponent<TObject> = RecommendComponentProps<TObject>['itemComponent']; type UiProps = Pick<ChatUiProps, 'open' | 'headerProps' | 'messagesProps' | 'promptProps' | 'suggestionsProps' | 'headerComponent' | 'promptComponent' | 'suggestionsComponent' | 'layoutComponent' | 'sendMessage' | 'regenerate' | 'stop' | 'error'>; type UserHeaderProps = Omit<ChatUiProps['headerProps'], 'onClose'>; type UserMessagesProps<TUiMessage extends UIMessage = UIMessage> = Omit<ChatUiProps<TUiMessage>['messagesProps'], 'messages' | 'tools' | 'indexUiState' | 'setIndexUiState' | 'scrollRef' | 'contentRef' | 'onClose' | 'onReload' | 'messageComponent' | 'leadingComponent' | 'footerComponent' | 'suggestionsComponent' | 'translations' | 'classNames'>; type UserPromptProps = Omit<ChatUiProps['promptProps'], 'value' | 'onInput' | 'onSubmit' | 'headerComponent' | 'footerComponent'>; export type Tool = UserClientSideTool; export type Tools = UserClientSideTools; export type ChatProps<TObject, TUiMessage extends UIMessage = UIMessage> = Omit<ChatUiProps, keyof UiProps | 'ref'> & UseChatProps<TUiMessage> & { itemComponent?: ItemComponent<TObject>; tools?: UserClientSideTools; getSearchPageURL?: (nextUiState: IndexUiState) => string; headerProps?: UserHeaderProps; messagesProps?: UserMessagesProps<TUiMessage>; promptProps?: UserPromptProps; layoutComponent?: (props: ChatLayoutOwnProps) => JSX.Element; headerComponent?: ChatUiProps['headerComponent']; headerTitleIconComponent?: ChatUiProps['headerProps']['titleIconComponent']; headerCloseIconComponent?: ChatUiProps['headerProps']['closeIconComponent']; headerMinimizeIconComponent?: ChatUiProps['headerProps']['minimizeIconComponent']; headerMaximizeIconComponent?: ChatUiProps['headerProps']['maximizeIconComponent']; messagesErrorComponent?: ChatUiProps['messagesProps']['errorComponent']; promptComponent?: ChatUiProps['promptComponent']; promptHeaderComponent?: ChatUiProps['promptProps']['headerComponent']; promptFooterComponent?: ChatUiProps['promptProps']['footerComponent']; loaderComponent?: ChatUiProps['messagesProps']['loaderComponent']; /** * Where the loader renders: as its own row after the last message * (`messages-end`, the default) or inside the streaming assistant message * (`message-inline`). */ loaderPosition?: ChatUiProps['messagesProps']['loaderPosition']; /** * Overrides when the loader shows. Receives the turn context plus the * built-in decision as `defaultValue`. */ shouldShowLoader?: ChatUiProps['messagesProps']['shouldShowLoader']; /** * How long (ms) a renewed loading state must hold before the loader comes * back after having been hidden in the same turn. */ loaderShowDelay?: ChatUiProps['messagesProps']['loaderShowDelay']; /** * Minimum time (ms) the loader stays on screen once shown, while the turn is * still running. */ loaderMinDuration?: ChatUiProps['messagesProps']['loaderMinDuration']; emptyComponent?: ChatUiProps['messagesProps']['emptyComponent']; actionsComponent?: ChatUiProps['messagesProps']['actionsComponent']; assistantMessageLeadingComponent?: ChatMessageProps['leadingComponent']; assistantMessageFooterComponent?: ChatMessageProps['footerComponent']; userMessageLeadingComponent?: ChatMessageProps['leadingComponent']; userMessageFooterComponent?: ChatMessageProps['footerComponent']; suggestionsComponent?: ChatUiProps['suggestionsComponent']; /** * Whether to render the reasoning an agent sends. `true` by default, so * reasoning that arrives is shown. Pass `false` to suppress it in this * widget. It cannot make an agent send reasoning: whether reasoning reaches * the client at all is the agent's own `sendReasoning` setting. */ showReasoning?: boolean; /** * Custom reasoning renderer. It replaces the built-in disclosure rather than * enabling reasoning: reasoning renders by default, and * `showReasoning: false` suppresses this renderer along with it. */ reasoningComponent?: ChatMessageProps<TUiMessage>['reasoningComponent']; translations?: Partial<{ prompt: ChatUiProps['promptProps']['translations']; header: ChatUiProps['headerProps']['translations']; message: ChatUiProps['messagesProps']['messageTranslations']; messages: ChatUiProps['messagesProps']['translations']; }>; }; export type ChatHandle = { setOpen: (open: boolean) => void; sendMessage: (params: { text: string; }) => void; setInput: (input: string) => void; }; export declare const Chat: <TObject extends RecordWithObjectID = RecordWithObjectID, TUiMessage extends UIMessage = UIMessage>(props: ChatProps<TObject, TUiMessage> & { ref?: React.Ref<ChatHandle>; }) => React.ReactElement | null;