import { type ReactNode } from 'react'; import { type AttachmentsAdapter, type ChatAdapter, type ChatToolOption } from '../adapter/types.js'; import type { ApprovalAnswerValue, AttachmentMeta, ChatModel, ChatNavigation, ChatUser, Conversation, ConversationSummary, ChatMessage as Message, MessagePart, ProviderInfo, ProviderIssue, TokenUsage, UnreachableSession } from '../types.js'; import { type ChatUIConfig } from './config.js'; import { type SidebarPresentation, type SidebarState } from './sidebarState.js'; interface ChatContextValue { adapter: ChatAdapter; currentUser: ChatUser; navigation: ChatNavigation; activeConversationId: string | null; conversations: ConversationSummary[]; currentConversation: Conversation | null; providers: ProviderInfo[]; models: ChatModel[]; unreachableSessions: UnreachableSession[]; providerIssues: ProviderIssue[]; selectedProvider: string | null; isSelectedModelAvailable: boolean; selectedAllocation: string | null; /** The host's tools the reader may turn on or off; empty when it lists none. */ tools: ChatToolOption[]; enabledToolIds: string[]; isLoading: boolean; isLoadingConversation: boolean; isLoadingModels: boolean; hasLoadedModels: boolean; modelsError: string | null; isStreaming: boolean; sidebar: SidebarState; /** True unless the sidebar is expanded. */ sidebarCollapsed: boolean; sidebarPresentation: SidebarPresentation; drawerOpen: boolean; queuedMessages: Message[]; loadConversations: () => Promise; loadConversation: (id: string) => Promise; loadProviders: () => Promise; refreshProviders: () => Promise; refreshModels: () => Promise; createConversation: (title?: string) => Promise; deleteConversation: (id: string) => Promise; sendMessage: (content: string, attachmentIds?: string[], parentId?: string, attachmentMeta?: AttachmentMeta) => Promise; retryMessage: (messageId: string) => Promise; /** Answers a tool call waiting for approval, resuming the reply it paused. */ answerToolApproval: (approvalId: string, answer: ApprovalAnswerValue) => Promise; setSelectedProvider: (providerId: string | null) => void; setSelectedAllocation: (allocation: string | null) => void; setToolEnabled: (id: string, enabled: boolean) => void; stopStreaming: () => void; removeQueuedMessage: (id: string) => void; flushQueuedMessages: () => void; setSidebar: (sidebar: SidebarState) => void; setDrawerOpen: (open: boolean) => void; /** Opens or closes the drawer while the layout shows one; otherwise moves * between expanded and the rail. */ toggleSidebar: () => void; updateConversationTitle: (id: string, title: string) => Promise; navigateToBranch: (messageId: string) => void; clearCurrentConversation: () => void; consumeInputFocus: (conversationId?: string) => boolean; } /** The reply being written, which changes with every streamed token. It has * its own context so that only what draws the reply re-renders per token, * not the composer, the conversation list and every other `useChat` reader. */ export interface ChatStream { /** True while the model is reasoning, before its answer starts. */ isThinking: boolean; streamingContent: string; streamingReasoning: string; streamingParts: MessagePart[]; /** Tokens the streaming reply has used so far, when the stream reports them. */ streamingUsage: TokenUsage | null; thinkingStartTime: number | null; } /** A model's display name by its id, when the adapter listed one; undefined * outside a ChatProvider or for a model it doesn't list. */ export declare function useChatModelName(id: string | null | undefined): string | undefined; export declare function useChat(): ChatContextValue; /** True while the adapter lists tools of its own, which the composer's + * menu offers; false outside a ChatProvider. */ export declare function useHasChatTools(): boolean; /** The adapter's attachments; undefined outside a ChatProvider or when the * adapter has none. */ export declare function useChatAttachments(): AttachmentsAdapter | undefined; /** The reply being streamed. A component that reads it re-renders on every * token, so read it only where the reply is drawn. */ export declare function useChatStream(): ChatStream; export interface ChatProviderProps { adapter: ChatAdapter; currentUser: ChatUser; navigation: ChatNavigation; activeConversationId?: string | null; /** Resolved once per object: keep it stable (a module constant or a * `useMemo`), or every reader of the config re-renders with the provider. */ config?: ChatUIConfig; /** Owns the sidebar's state. Omit to leave it to the reader, remembered * per browser. */ sidebar?: SidebarState; onSidebarChange?: (sidebar: SidebarState) => void; /** Owns whether the drawer is open while the layout shows the sidebar as * one. Omit to leave it to the reader; it starts closed. */ drawerOpen?: boolean; onDrawerOpenChange?: (open: boolean) => void; children: ReactNode; } export declare function ChatProvider({ adapter, currentUser, navigation, activeConversationId, config, sidebar: sidebarProp, onSidebarChange, drawerOpen: drawerOpenProp, onDrawerOpenChange, children, }: ChatProviderProps): import("react").JSX.Element; export {};