import { DefaultChatTransport } from '../../lib/ai-lite'; import { Chat } from '../../lib/chat'; import type { AbstractChat, ChatInit as ChatInitAi, UIMessage } from '../../lib/chat'; import type { SendEventForHits } from '../../lib/utils'; import type { Connector, Renderer, Unmounter, UnknownWidgetParams, IndexUiState, IndexWidget, WidgetRenderState, IndexRenderState } from '../../types'; import type { UserClientSideTool, ClientSideTools } from 'instantsearch-ui-components'; export type ChatRenderState = { indexUiState: IndexUiState; input: string; open: boolean; /** * Sends an event to the Insights middleware. */ sendEvent: SendEventForHits; setIndexUiState: IndexWidget['setIndexUiState']; setInput: (input: string) => void; setOpen: (open: boolean) => void; /** * Opens the chat (if needed) and focuses the prompt input. */ focusInput: () => void; /** * Updates the `messages` state locally. This is useful when you want to * edit the messages on the client, and then trigger the `reload` method * manually to regenerate the AI response. */ setMessages: (messages: TUiMessage[] | ((m: TUiMessage[]) => TUiMessage[])) => void; /** * Whether the chat is in the process of clearing messages. */ isClearing: boolean; /** * Clear all messages. */ clearMessages: () => void; /** * Callback to be called when the clear transition ends. */ onClearTransitionEnd: () => void; /** * Tools configuration with addToolResult bound, ready to be used by the UI. */ tools: ClientSideTools; /** * Suggestions received from the AI model. */ suggestions?: string[]; /** * Sends feedback (thumbs up/down) for an assistant message. * Only available when using `agentId` and `feedback` is true. * Returns `undefined` otherwise. */ sendChatMessageFeedback?: (messageId: string, vote: 0 | 1) => void; /** * Map of message IDs to their feedback state. * 'sending' means the request is in flight, 0/1 means the vote was recorded. */ feedbackState: Record; } & Pick, 'addToolResult' | 'clearError' | 'error' | 'id' | 'messages' | 'regenerate' | 'resumeStream' | 'sendMessage' | 'status' | 'stop'>; export type ChatInitWithoutTransport = Omit, 'transport'>; export type ChatTransport = { transport?: ConstructorParameters[0]; } & ({ agentId: string; /** * Whether to enable feedback (thumbs up/down) on assistant messages. */ feedback?: boolean; } | { agentId?: undefined; feedback?: never; }); export type ApplyFiltersParams = { query?: string; facetFilters?: string[][]; }; export type ChatInit = ChatInitWithoutTransport & ChatTransport; export type ChatConnectorParams = ({ chat: Chat; } | ChatInit) & { /** * Whether to resume an ongoing chat generation stream. */ resume?: boolean; /** * Configuration for client-side tools. */ tools?: Record>; /** * Identifier of this type of chat widget. This is used for the key in renderState. * @default 'chat' */ type?: string; /** * Additional context to send with each user message (e.g. current page info). * This context is included in the message parts sent to the API but is not * displayed in the chat UI. * Can be a static object or a function that returns the context at send time. */ context?: Record | (() => Record); /** * A message to send automatically when the chat is initialized. * * This message is only sent when the chat has no existing messages yet. If * messages were restored or otherwise already exist when the widget starts, * this message is not sent. * * When `resume` is enabled, this message is not sent. */ initialUserMessage?: string; }; export type ChatWidgetDescription = { $$type: 'ais.chat'; renderState: ChatRenderState; indexRenderState: { chat: WidgetRenderState, ChatConnectorParams>; }; }; export type ChatConnector = Connector, ChatConnectorParams>; declare const _default: (renderFn: Renderer, unmountFn?: Unmounter) => >(widgetParams: TWidgetParams & ChatConnectorParams) => { $$type: "ais.chat"; init(initOptions: import("../../types").InitOptions): void; render(renderOptions: import("../../types").RenderOptions): void; getRenderState(renderState: { answers?: WidgetRenderState | undefined; autocomplete?: WidgetRenderState | undefined; breadcrumb?: { [rootAttribute: string]: WidgetRenderState; } | undefined; chat?: WidgetRenderState>, ChatConnectorParams>> | undefined; clearRefinements?: WidgetRenderState | undefined; configure?: WidgetRenderState | undefined; currentRefinements?: WidgetRenderState | undefined; geoSearch?: WidgetRenderState, import("../geo-search/connectGeoSearch").GeoSearchConnectorParams> | undefined; hierarchicalMenu?: { [rootAttribute: string]: WidgetRenderState; } | undefined; hits?: WidgetRenderState, import("../hits/connectHits").HitsConnectorParams> | undefined; hitsPerPage?: WidgetRenderState | undefined; infiniteHits?: WidgetRenderState, import("../infinite-hits/connectInfiniteHits").InfiniteHitsConnectorParams> | undefined; menu?: { [attribute: string]: WidgetRenderState; } | undefined; numericMenu?: { [attribute: string]: WidgetRenderState; } | undefined; pagination?: WidgetRenderState | undefined; poweredBy?: WidgetRenderState | undefined; queryRules?: WidgetRenderState | undefined; range?: { [attribute: string]: WidgetRenderState; } | undefined; ratingMenu?: { [attribute: string]: WidgetRenderState; } | undefined; refinementList?: { [attribute: string]: WidgetRenderState; } | undefined; relevantSort?: WidgetRenderState | undefined; searchBox?: WidgetRenderState | undefined; sortBy?: WidgetRenderState | undefined; stats?: WidgetRenderState | undefined; toggleRefinement?: { [attribute: string]: WidgetRenderState; } | undefined; voiceSearch?: WidgetRenderState | undefined; analytics?: WidgetRenderState, import("../../widgets/analytics/analytics").AnalyticsWidgetParams> | undefined; places?: WidgetRenderState, import("../../widgets/places/places").PlacesWidgetParams> | undefined; }, renderOptions: import("../../types").InitOptions | import("../../types").RenderOptions): IndexRenderState & ChatWidgetDescription["indexRenderState"]; getWidgetRenderState(renderOptions: import("../../types").InitOptions | import("../../types").RenderOptions): { indexUiState: Partial<{ query: string; } & { configure: import("algoliasearch-helper").PlainSearchParameters; } & { geoSearch: { boundingBox: string; }; } & { hierarchicalMenu: { [rootAttribute: string]: string[]; }; } & { hitsPerPage: number; } & { page: number; } & { menu: { [attribute: string]: string; }; } & { numericMenu: { [attribute: string]: string; }; } & { page: number; } & { range: { [attribute: string]: string; }; } & { ratingMenu: { [attribute: string]: number | undefined; }; } & { refinementList: { [attribute: string]: string[]; }; } & { relevantSort: number; } & { query: string; } & { sortBy: string; } & { toggle: { [attribute: string]: boolean; }; } & { query: string; } & { places: { query: string; position: string; }; }>; input: string; open: boolean; sendEvent: SendEventForHits; setIndexUiState: (indexUiState: Partial<{ query: string; } & { configure: import("algoliasearch-helper").PlainSearchParameters; } & { geoSearch: { boundingBox: string; }; } & { hierarchicalMenu: { [rootAttribute: string]: string[]; }; } & { hitsPerPage: number; } & { page: number; } & { menu: { [attribute: string]: string; }; } & { numericMenu: { [attribute: string]: string; }; } & { page: number; } & { range: { [attribute: string]: string; }; } & { ratingMenu: { [attribute: string]: number | undefined; }; } & { refinementList: { [attribute: string]: string[]; }; } & { relevantSort: number; } & { query: string; } & { sortBy: string; } & { toggle: { [attribute: string]: boolean; }; } & { query: string; } & { places: { query: string; position: string; }; }> | ((previousIndexUiState: Partial<{ query: string; } & { configure: import("algoliasearch-helper").PlainSearchParameters; } & { geoSearch: { boundingBox: string; }; } & { hierarchicalMenu: { [rootAttribute: string]: string[]; }; } & { hitsPerPage: number; } & { page: number; } & { menu: { [attribute: string]: string; }; } & { numericMenu: { [attribute: string]: string; }; } & { page: number; } & { range: { [attribute: string]: string; }; } & { ratingMenu: { [attribute: string]: number | undefined; }; } & { refinementList: { [attribute: string]: string[]; }; } & { relevantSort: number; } & { query: string; } & { sortBy: string; } & { toggle: { [attribute: string]: boolean; }; } & { query: string; } & { places: { query: string; position: string; }; }>) => Partial<{ query: string; } & { configure: import("algoliasearch-helper").PlainSearchParameters; } & { geoSearch: { boundingBox: string; }; } & { hierarchicalMenu: { [rootAttribute: string]: string[]; }; } & { hitsPerPage: number; } & { page: number; } & { menu: { [attribute: string]: string; }; } & { numericMenu: { [attribute: string]: string; }; } & { page: number; } & { range: { [attribute: string]: string; }; } & { ratingMenu: { [attribute: string]: number | undefined; }; } & { refinementList: { [attribute: string]: string[]; }; } & { relevantSort: number; } & { query: string; } & { sortBy: string; } & { toggle: { [attribute: string]: boolean; }; } & { query: string; } & { places: { query: string; position: string; }; }>)) => void; setInput: (input: string) => void; setOpen: (open: boolean) => void; focusInput: () => void; setMessages: (messagesParam: TUiMessage[] | ((m: TUiMessage[]) => TUiMessage[])) => void; suggestions: string[] | undefined; isClearing: boolean; clearMessages: () => void; onClearTransitionEnd: () => void; tools: ClientSideTools; sendChatMessageFeedback: ((messageId: string, vote: 0 | 1) => void) | undefined; feedbackState: Record; widgetParams: TWidgetParams & ChatConnectorParams; addToolResult: >({ tool, toolCallId, output, }: { tool: TTool; toolCallId: string; output: import("../../lib/ai-lite").InferUIMessageTools[TTool]["output"]; }) => Promise; clearError: () => void; error: Error | undefined; id: string; messages: TUiMessage[]; regenerate: ({ messageId, ...options }?: { messageId?: string; } & import("../../lib/ai-lite").ChatRequestOptions) => Promise; resumeStream: (options?: import("../../lib/ai-lite").ChatRequestOptions) => Promise; sendMessage: (message?: (Omit & { id?: TUiMessage["id"] | undefined; role?: TUiMessage["role"] | undefined; } & { text?: never; files?: never; messageId?: string; }) | { text: string; files?: FileList | import("../../lib/ai-lite").FileUIPart[]; metadata?: import("../../lib/ai-lite").InferUIMessageMetadata | undefined; parts?: never; messageId?: string; } | { files: FileList | import("../../lib/ai-lite").FileUIPart[]; metadata?: import("../../lib/ai-lite").InferUIMessageMetadata | undefined; parts?: never; messageId?: string; } | undefined, options?: import("../../lib/ai-lite").ChatRequestOptions) => Promise; status: import("../../lib/ai-lite").ChatStatus; stop: () => Promise; }; dispose(): void; shouldRender(): true; readonly chatInstance: Chat; }; export default _default;