import { type InfiniteData, type QueryClient } from '@tanstack/react-query'; import type { Message, MessagesPage, SendMessageRequest } from '../types/api'; interface UseMessagesOptions { enabled?: boolean; staleTime?: number; } /** * Soft target of persisted message *parts* per cursor page. The route counts * parts but pages by whole user→assistant turns: it returns at least two * complete turns and keeps adding older complete turns while the total stays * under this target, so a page never splits a message and consecutive pages * never overlap. */ export declare const MESSAGE_PARTS_PAGE_TARGET = 120; export declare function getMessagesQueryKey(sessionId: string | undefined): readonly ["project", string, "messages", string]; export declare function isOptimisticMessageId(id: string): boolean; /** * True when `message` is an optimistic user message whose text matches the * server-confirmed content. Used to drop the optimistic copy once the real * message arrives (via stream event or refetch). */ export declare function optimisticMessageMatchesText(message: Message, text: string): boolean; /** Appends one server-created message and consumes at most one optimistic copy. */ export declare function appendServerCreatedMessage(messages: Message[], message: Message, content: string | null): Message[]; /** * Preserves in-flight optimistic user messages across a full refetch: entries * the server does not know about yet are re-appended so a background * invalidation cannot make a just-sent message vanish from the thread. */ export declare function mergeOptimisticMessages(cached: Message[] | undefined, fresh: Message[]): Message[]; export type MessagesInfiniteData = InfiniteData; /** * Migrates the legacy flat-array cache shape used before message pagination. * This is intentionally kept at the cache boundary because a newly-created * session may still be warmed by older application code during an upgrade. */ export declare function normalizeMessagesInfiniteData(data: MessagesInfiniteData | Message[] | undefined): MessagesInfiniteData | undefined; /** * Flattens cursor pages into one chronological thread. Pages are stored * newest-first and hold whole turns, so this is a concatenation that keeps * every already-loaded message object identical; ids that still manage to * repeat (a widened refetch of the newest page) are collapsed defensively into * one message with the newest metadata and the union of every loaded part. */ export declare function flattenMessagePages(data: MessagesInfiniteData | Message[] | undefined): Message[]; /** * Cursor the next (older) page would be fetched with. Used to dedupe repeated * prepend requests for the same page while the user sits at the top. */ export declare function getOlderMessagesCursor(queryClient: QueryClient, sessionId: string | undefined): string | null; /** Reads the current thread as one chronological array, or undefined when the * session has never been fetched. */ export declare function getMessagesFromCache(queryClient: QueryClient, sessionId: string): Message[] | undefined; /** * Updates the paged messages cache through a flat-array updater so callers * (stream engine, optimistic sends, retry) stay page-shape agnostic. Each * message is written back to the page it was loaded from, and untouched pages * are returned by identity so an edit at the live edge cannot invalidate the * older pages above it. */ export declare function updateMessagesCache(queryClient: QueryClient, sessionId: string, updater: (messages: Message[]) => Message[]): void; /** Fetches the initial paged thread cache and waits until it is ready. */ export declare function fetchSessionMessages(queryClient: QueryClient, sessionId: string): Promise>; export declare function useMessages(sessionId: string | undefined, options?: UseMessagesOptions): import("@tanstack/react-query").UseInfiniteQueryResult; /** Warms the messages and queue-state caches (e.g. on session hover) so * switching to the session renders without a loading state. */ export declare function prefetchSessionMessages(queryClient: QueryClient, sessionId: string): void; export interface OptimisticSendContext { optimisticId: string | null; queued: boolean; } export declare function useSendMessage(sessionId: string): import("@tanstack/react-query").UseMutationResult; export {}; //# sourceMappingURL=useMessages.d.ts.map