import { LanguageModel, ToolSet } from 'ai'; import { Book, RebookPlugin } from '../core/types'; import { ReadableContentCitation, ReadableContentUnitKind } from '../core/readable-content'; import { SearchResult, SearchScope } from '../search'; export type AIChatRole = 'user' | 'assistant'; export interface AIChatMessage { role: AIChatRole; content: string | readonly AIChatContentPart[]; } export type AIChatContentPart = { type: 'text'; text: string; } | { type: 'image'; image: string | Uint8Array | ArrayBuffer | URL; mediaType?: string; }; export interface AIChatAskOptions { messages: readonly AIChatMessage[]; currentUnitIndex?: number; current?: AIChatReadingContext; abortSignal?: AbortSignal; } export interface AIChatResponse { text: string; toolCalls: unknown[]; toolResults: unknown[]; usage?: unknown; finishReason?: string; } export interface AIChatStreamResponse { textStream: AsyncIterable; response: Promise; } export interface AIChatSearchOptions { scope?: SearchScope; unitIndex?: number; maxResults?: number; contextChars?: number; } export interface AIChatContentOptions { maxChars?: number; includeBlocks?: boolean; } export interface AIChatContextOptions { currentUnitIndex?: number; before?: number; after?: number; maxChars?: number; } export interface AIChatTOCItem { label: string; href: string; depth: number; unitIndex?: number; unitKind?: ReadableContentUnitKind; } export interface AIChatContent { unitIndex: number; unitId: string | number; unitKind: ReadableContentUnitKind; unitTitle?: string; sectionIndex?: number; pageIndex?: number; title?: string; text: string; blocks?: AIChatContentBlock[]; charCount: number; truncated: boolean; } export type AIChatCitation = ReadableContentCitation; export interface AIChatContentBlock { blockId?: string; blockType: string; text: string; citation: AIChatCitation; } export interface AIChatContextResult { currentUnitIndex: number; units: AIChatContent[]; } export interface AIChatToolContext { currentUnitIndex?: number; current?: AIChatReadingContext; } export interface AIChatReadingContext { unitIndex?: number; unitId?: string | number; unitKind?: ReadableContentUnitKind; unitTitle?: string; sectionIndex?: number; sectionId?: string | number; sectionTitle?: string; sectionFraction?: number; totalFraction?: number; tocLabel?: string; tocHref?: string; pageIndex?: number; pageCount?: number; } export interface AIChatController { ask(input: string | AIChatAskOptions): Promise; stream(input: string | AIChatAskOptions): AIChatStreamResponse; search(query: string, options?: AIChatSearchOptions): Promise; getTOC(maxItems?: number): AIChatTOCItem[]; getContent(unitIndex: number, options?: AIChatContentOptions): Promise; getCurrentContext(options?: AIChatContextOptions): Promise; createTools(context?: AIChatToolContext): ToolSet; } export interface AIChatBook extends Book { aiChat: AIChatController; documentEdits: AIChatDocumentEditsController; } export interface AIChatOptions { model: LanguageModel; system?: string | (() => string | undefined); maxToolSteps?: number | (() => number); maxSearchResults?: number | (() => number); maxContentChars?: number | (() => number); maxContextChars?: number | (() => number); extraTools?: ToolSet | ((context: AIChatToolContext) => ToolSet); onDocumentEdit?: (event: AIChatDocumentEditEvent) => void; } export interface AIChatDocumentRewriteInput { unitIndex?: number; rewrites: AIChatDocumentRewrite[]; } export interface AIChatDocumentRewrite { blockId: string; text: string; } export interface AIChatDocumentEdit { unitIndex: number; unitId: string | number; unitTitle?: string; blockId: string; blockType: string; previousText: string; text: string; updatedAt: number; } export interface AIChatDocumentEditResult { edits: AIChatDocumentEdit[]; version: number; } export interface AIChatDocumentEditEvent { type: 'rewrite' | 'clear'; unitIndexes: number[]; edits: AIChatDocumentEdit[]; version: number; } export interface AIChatDocumentEditsController { readonly version: number; apply(input: AIChatDocumentRewriteInput): Promise; clear(unitIndex?: number): AIChatDocumentEditResult; list(unitIndex?: number): AIChatDocumentEdit[]; subscribe(listener: (event: AIChatDocumentEditEvent) => void): () => void; } export declare function withAIChat(options: AIChatOptions): RebookPlugin; export declare function createAIChatController(book: Book, options: AIChatOptions): AIChatController; export declare function createAIChatTools(book: Book, options: AIChatOptions, context?: AIChatToolContext): ToolSet; //# sourceMappingURL=ai-chat.d.ts.map