import { type FileSectionReference, type SubmitChatOptions } from '@xrpl/ai-core'; import React, { type ReactNode } from 'react'; import type { MarkpromptOptions } from '../types.js'; export type ChatLoadingState = 'indeterminate' | 'preload' | 'streaming-answer' | 'done' | 'cancelled'; export interface ChatViewMessage { id: string; prompt: string; promptId?: string; answer?: string; state: ChatLoadingState; references: FileSectionReference[]; } export interface ChatStoreState { abort?: () => void; projectKey: string; conversationId?: string; setConversationId: (conversationId: string) => void; selectConversation: (conversationId?: string) => void; messages: ChatViewMessage[]; setMessages: (messages: ChatViewMessage[]) => void; setMessageByIndex: (index: number, next: Partial) => void; conversationIdsByProjectKey: { [projectKey: string]: string[]; }; messagesByConversationId: { [conversationId: string]: { lastUpdated: string; messages: ChatViewMessage[]; }; }; submitChat: (prompt: string) => void; regenerateLastAnswer: () => void; } export interface CreateChatOptions { debug?: boolean; projectKey: string; persistChatHistory?: boolean; chatOptions?: Omit; } /** * Creates a chat store for a given project key. * Keeps track of messages by project key and conversation id. * * @param projectKey - Markprompt project key * @param persistChatHistory - Should chat history be persisted in local storage? */ export declare const createChatStore: ({ chatOptions, debug, persistChatHistory, projectKey, }: CreateChatOptions) => Omit, "setState"> & { setState(nextStateOrUpdater: ChatStoreState | Partial | ((state: { abort?: (() => void) | undefined; projectKey: string; conversationId?: string | undefined; setConversationId: (conversationId: string) => void; selectConversation: (conversationId?: string) => void; messages: { id: string; prompt: string; promptId?: string | undefined; answer?: string | undefined; state: ChatLoadingState; references: { file: { title?: string | undefined; path: string; meta?: object | undefined; source: { type: import("@xrpl/ai-core").SourceType; data?: { url?: string | undefined; domain?: string | undefined; } | undefined; }; }; meta?: { leadHeading?: { id?: string | undefined; depth?: number | undefined; value?: string | undefined; slug?: string | undefined; } | undefined; } | undefined; }[]; }[]; setMessages: (messages: ChatViewMessage[]) => void; setMessageByIndex: (index: number, next: Partial) => void; conversationIdsByProjectKey: { [x: string]: string[]; }; messagesByConversationId: { [x: string]: { lastUpdated: string; messages: { id: string; prompt: string; promptId?: string | undefined; answer?: string | undefined; state: ChatLoadingState; references: { file: { title?: string | undefined; path: string; meta?: object | undefined; source: { type: import("@xrpl/ai-core").SourceType; data?: { url?: string | undefined; domain?: string | undefined; } | undefined; }; }; meta?: { leadHeading?: { id?: string | undefined; depth?: number | undefined; value?: string | undefined; slug?: string | undefined; } | undefined; } | undefined; }[]; }[]; }; }; submitChat: (prompt: string) => void; regenerateLastAnswer: () => void; }) => void), shouldReplace?: boolean | undefined): void; }, "persist"> & { persist: { setOptions: (options: Partial>) => void; clearStorage: () => void; rehydrate: () => void | Promise; hasHydrated: () => boolean; onHydrate: (fn: (state: ChatStoreState) => void) => () => void; onFinishHydration: (fn: (state: ChatStoreState) => void) => () => void; getOptions: () => Partial>; }; }; export declare const ChatContext: React.Context<(Omit, "setState"> & { setState(nextStateOrUpdater: ChatStoreState | Partial | ((state: { abort?: (() => void) | undefined; projectKey: string; conversationId?: string | undefined; setConversationId: (conversationId: string) => void; selectConversation: (conversationId?: string) => void; messages: { id: string; prompt: string; promptId?: string | undefined; answer?: string | undefined; state: ChatLoadingState; references: { file: { title?: string | undefined; path: string; meta?: object | undefined; source: { type: import("@xrpl/ai-core").SourceType; data?: { url?: string | undefined; domain?: string | undefined; } | undefined; }; }; meta?: { leadHeading?: { id?: string | undefined; depth?: number | undefined; value?: string | undefined; slug?: string | undefined; } | undefined; } | undefined; }[]; }[]; setMessages: (messages: ChatViewMessage[]) => void; setMessageByIndex: (index: number, next: Partial) => void; conversationIdsByProjectKey: { [x: string]: string[]; }; messagesByConversationId: { [x: string]: { lastUpdated: string; messages: { id: string; prompt: string; promptId?: string | undefined; answer?: string | undefined; state: ChatLoadingState; references: { file: { title?: string | undefined; path: string; meta?: object | undefined; source: { type: import("@xrpl/ai-core").SourceType; data?: { url?: string | undefined; domain?: string | undefined; } | undefined; }; }; meta?: { leadHeading?: { id?: string | undefined; depth?: number | undefined; value?: string | undefined; slug?: string | undefined; } | undefined; } | undefined; }[]; }[]; }; }; submitChat: (prompt: string) => void; regenerateLastAnswer: () => void; }) => void), shouldReplace?: boolean | undefined): void; }, "persist"> & { persist: { setOptions: (options: Partial>) => void; clearStorage: () => void; rehydrate: () => void | Promise; hasHydrated: () => boolean; onHydrate: (fn: (state: ChatStoreState) => void) => () => void; onFinishHydration: (fn: (state: ChatStoreState) => void) => () => void; getOptions: () => Partial>; }; }) | null>; interface ChatProviderProps { chatOptions: MarkpromptOptions['chat']; children: ReactNode; debug?: boolean; projectKey: string; } export declare function ChatProvider(props: ChatProviderProps): JSX.Element; export declare function useChatStore(selector: (state: ChatStoreState) => T): T; export declare const selectProjectConversations: (state: ChatStoreState) => [ conversationId: string, { lastUpdated: string; messages: ChatViewMessage[]; } ][]; export {}; //# sourceMappingURL=store.d.ts.map