UNPKG

@cossistant/next

Version:

Next.js-ready SDK for building AI-powered support/chat widgets. Hooks + primitives, WS-driven, TypeScript-first. Next.js-ready, Tailwind optional.

86 lines 2.62 kB
//#region ../react/src/hooks/use-conversation-page.d.ts type UseConversationPageOptions = { /** * Initial conversation ID (from URL params, navigation state, etc.) * Can be PENDING_CONVERSATION_ID or a real ID. */ conversationId: string; /** * Optional initial message to send when the conversation opens. */ initialMessage?: string; /** * Callback when conversation ID changes (e.g., after creation). * Use this to update navigation state or URL. */ onConversationIdChange?: (conversationId: string) => void; /** * Optional timeline items to pass through (e.g., optimistic updates). */ items?: TimelineItem[]; /** * Whether automatic "seen" tracking should be enabled. * Set to false when the conversation isn't visible (e.g. widget closed). * Default: true */ autoSeenEnabled?: boolean; }; type UseConversationPageReturn = { conversationId: string; isPending: boolean; items: TimelineItem[]; isLoading: boolean; error: Error | null; composer: { message: string; files: File[]; isSubmitting: boolean; canSubmit: boolean; setMessage: (message: string) => void; addFiles: (files: File[]) => void; removeFile: (index: number) => void; submit: () => void; }; hasItems: boolean; lastTimelineItem: TimelineItem | null; }; /** * Main orchestrator hook for the conversation page. * * This hook combines all conversation-related logic: * - Lifecycle management (pending → real conversation) * - Message fetching and display * - Message composition and sending * - Automatic seen tracking * - Default/welcome messages before conversation is created * * It provides a clean, simple API for building conversation UIs. * * @example * ```tsx * export function ConversationPage({ conversationId: initialId }) { * const conversation = useConversationPage({ * conversationId: initialId, * onConversationIdChange: (newId) => { * // Update URL or navigation state * navigate(`/conversation/${newId}`); * }, * }); * * return ( * <> * <MessageList messages={conversation.messages} /> * <MessageInput * value={conversation.composer.message} * onChange={conversation.composer.setMessage} * onSubmit={conversation.composer.submit} * /> * </> * ); * } * ``` */ declare function useConversationPage(options: UseConversationPageOptions): UseConversationPageReturn; //#endregion export { UseConversationPageOptions, UseConversationPageReturn, useConversationPage }; //# sourceMappingURL=use-conversation-page.d.ts.map