import type { ChatInit, ChatRequestOptions, ChatState, ChatStatus, CreateUIMessage, FileUIPart, IdGenerator, InferUIMessageMetadata, ToolResultSubmission, UIMessage } from './types'; /** * Abstract base class for chat implementations. */ export declare abstract class AbstractChat { private conversationId; readonly generateId: IdGenerator; get id(): string; protected state: ChatState; private readonly transport?; private onError?; private onToolCall?; private onFinish?; private onData?; private sendAutomaticallyWhen?; private shouldRepairToolInput?; private shouldRepairRestoredPendingToolPart?; private resolveCancelledToolOutput?; private activeResponse; private latestResponse; private responsesByToolCallId; private responseByMessage; private restoredToolCalls; private acceptsIdentifierOnlyToolResults; private jobExecutor; constructor({ generateId, id, transport, state, onError, onToolCall, onFinish, onData, sendAutomaticallyWhen, shouldRepairToolInput, shouldRepairRestoredPendingToolPart, resolveCancelledToolOutput, }: Omit, 'messages'> & { state: ChatState; }); /** * Hook status: * * - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream. * - `streaming`: The response is actively streaming in from the API, receiving chunks of data. * - `ready`: The full response has been received and processed; a new user message can be submitted. * - `error`: An error occurred during the API request, preventing successful completion. */ get status(): ChatStatus; protected setStatus({ status, error, }: { status: ChatStatus; error?: Error; }): void; get error(): Error | undefined; /** * Starts a new server-side conversation thread by rotating the id sent as * `chatId` / `id` on the next request. The InstantSearch connector calls this * after the user clears the transcript so completions are not tied to prior * context. */ resetConversationId(): void; get messages(): TUIMessage[]; set messages(messages: TUIMessage[]); get lastMessage(): TUIMessage | undefined; /** * Appends or replaces a user message to the chat list. This triggers the API call to fetch * the assistant's response. */ sendMessage: (message?: (CreateUIMessage & { text?: never; files?: never; messageId?: string; }) | { text: string; files?: FileList | FileUIPart[]; metadata?: InferUIMessageMetadata; parts?: never; messageId?: string; } | { files: FileList | FileUIPart[]; metadata?: InferUIMessageMetadata; parts?: never; messageId?: string; }, options?: ChatRequestOptions) => Promise; /** * Regenerate the assistant message with the provided message id. * If no message id is provided, the last assistant message will be regenerated. */ regenerate: ({ messageId, ...options }?: { messageId?: string; } & ChatRequestOptions) => Promise; /** * Attempt to resume an ongoing streaming response. */ resumeStream: (options?: ChatRequestOptions) => Promise; /** * Clear the error state and set the status to ready if the chat is in an error state. */ clearError: () => void; private replaceMessage; private commit; protected captureRestoredToolCalls(): void; protected clearRestoredToolCalls(): void; protected repairRestoredPendingToolParts(): void; /** * The transcript to send, with every tool call still awaiting an output * reported as cancelled — a provider rejects a turn holding a tool call with * no matching result. * * The repair stays on this copy rather than being committed to `messages`: * the card is still mounted, so a result submitted after the send must still * land, and is sent as the real output from then on. */ private getOutboundMessages; private resolveToolCallCancellation; private continueResponse; private retireResponse; private pruneDetachedResponse; private submitToolResult; /** * Add a tool result for a tool call. */ addToolResult: ToolResultSubmission; /** * Abort the current request immediately, keep the generated tokens if any. */ stop: () => Promise; private makeRequest; private consume; private processStream; private handleError; private convertFilesToParts; private fileToDataUrl; }