/** @jsx createElement */ import type { ChatMessageProps, ChatMessageClassNames, ChatMessageTranslations } from './ChatMessage'; import type { ChatMessageErrorProps } from './ChatMessageError'; import type { ChatMessageLoaderPropsWithContext } from './ChatMessageLoader'; import type { ChatComponentPropsWithContext, ChatEmptyProps, ChatLayoutOwnProps, ChatLoaderContext, ChatLoaderPosition, ChatMessageBase, ChatStatus, ClientSideTools } from './types'; import type { ComponentProps, Hooks, MutableRef, Renderer, VNode } from '../../types'; export type ChatMessagesTranslations = { /** * Label for the scroll to bottom button */ scrollToBottomLabel: string; /** * Text to display in the loader. A function can label the wait by what the * turn is doing (`context.phase`). */ loaderText?: string | ((context: ChatLoaderContext) => string); /** * Label for the copy to clipboard action */ copyToClipboardLabel?: string; /** * Label for the regenerate action */ regenerateLabel?: string; /** * Label for the thumbs up action */ thumbsUpLabel?: string; /** * Label for the thumbs down action */ thumbsDownLabel?: string; /** * Text shown after submitting feedback */ feedbackThankYouText?: string; /** * Label for the feedback spinner */ sendingFeedbackLabel?: string; }; export type ChatMessagesClassNames = { /** * Class names to apply to the root element */ root: string | string[]; /** * Class names to apply to the scroll container */ scroll: string | string[]; /** * Class names to apply to the content container */ content: string | string[]; /** * Class names to apply to the scroll to bottom button */ scrollToBottom: string | string[]; /** * Class names to apply to the scroll to bottom button when hidden */ scrollToBottomHidden: string | string[]; }; type ChatMessageRoleProps = Partial, 'ref' | 'key' | 'message' | 'messages'>> & Partial>; export type ChatMessagesProps = ComponentProps<'div'> & { /** * Array of messages to display */ messages: TMessage[]; /** * Custom message renderer */ messageComponent?: (props: ChatComponentPropsWithContext<{ message: TMessage; /** * The loader, on the row hosting it while `loaderPosition` is * `'message-inline'`. Render it to keep the loader inside the message. */ loaderElement?: VNode; /** * The prompt suggestions, on the row they belong to. */ suggestionsElement?: VNode; }, TMessage>) => JSX.Element; /** * Custom loader component. Receives the turn context alongside the resolved * `translations`. */ loaderComponent?: (props: ChatMessageLoaderPropsWithContext) => JSX.Element; /** * Where the loader renders. * @default 'messages-end' */ loaderPosition?: ChatLoaderPosition; /** * Overrides when the loader shows. Receives the turn context plus the * built-in decision as `defaultValue`, so it can be narrowed or widened * instead of reimplemented. Smoothing still applies to the result. */ shouldShowLoader?: (context: ChatLoaderContext & { defaultValue: boolean; }) => boolean; /** * How long (ms) a renewed loading state must hold before the loader comes * back after having been hidden in the same turn. The turn's first loader is * never delayed. * @default 250 */ loaderShowDelay?: number; /** * Minimum time (ms) the loader stays on screen once shown, while the turn is * still running. Guards against a one-frame flash. * @default 200 */ loaderMinDuration?: number; /** * Custom error component */ errorComponent?: (props: ChatComponentPropsWithContext) => JSX.Element; /** * Custom empty component shown when there are no messages */ emptyComponent?: (props: ChatComponentPropsWithContext) => JSX.Element; /** * Custom actions component */ actionsComponent?: ChatMessageProps['actionsComponent']; /** * The index UI state */ indexUiState: object; /** * Set the index UI state */ setIndexUiState: (state: object) => void; /** * Tools available for the assistant */ tools: ClientSideTools; /** * Current chat status */ status?: ChatStatus; /** * Error from the last failed request, if any. When set, its `message` is * available to custom error components or translation functions (for example * API `message` fields on 403 responses). */ error?: Error; /** * Whether to hide the scroll to bottom button */ hideScrollToBottom?: boolean; /** * Callback for reload action */ onReload: (messageId?: string) => void; /** * Callback to start a new conversation from the default error component. * When provided (and no custom `errorComponent`/`actions` override it), * the error renders a "New conversation" button that clears the messages * and rotates the chat id. When omitted, the error renders with no action * button (recommended default for guardrails-style errors). */ onNewConversation?: () => void; /** * Function to close the chat */ onClose: () => void; /** * Function to send a message to the chat */ sendMessage?: ChatLayoutOwnProps['sendMessage']; /** * Function to regenerate the last assistant response */ regenerate?: ChatLayoutOwnProps['regenerate']; /** * Function to stop the current streaming response */ stop?: ChatLayoutOwnProps['stop']; /** * Whether the chat panel is open */ open?: boolean; /** * Whether the chat panel is maximized */ maximized?: boolean; /** * Function to set the prompt input value */ setInput?: (input: string) => void; /** * Optional class names */ classNames?: Partial; /** * Optional message class names */ messageClassNames?: Partial; /** * Optional translations */ translations?: Partial; /** * Optional message translations */ messageTranslations?: Partial; /** * Optional user message props */ userMessageProps?: ChatMessageRoleProps; /** * Optional assistant message props */ assistantMessageProps?: ChatMessageRoleProps; /** * Whether the scroll is at the bottom (controlled state) */ isScrollAtBottom?: boolean; /** * Whether the messages are clearing (for animation) */ isClearing?: boolean; /** * Callback for when clearing transition ends */ onClearTransitionEnd?: () => void; /** * Ref callback for the scroll container element */ scrollRef?: MutableRef; /** * Ref callback for the content element */ contentRef?: MutableRef; /** * Callback to scroll to bottom */ onScrollToBottom?: () => void; /** * Suggestions element to display below a message */ suggestionsElement?: VNode; /** * Callback for feedback (thumbs up/down) on a message. */ onFeedback?: (messageId: string, vote: 0 | 1) => void; /** * Map of message IDs to their feedback state. */ feedbackState?: Record; }; export declare function createChatMessagesComponent({ createElement, Fragment, useMemo, useState, useEffect, }: Renderer & Pick): (userProps: ChatMessagesProps) => JSX.Element; export {};