UNPKG

@ai2070/l0

Version:

L0: The Missing Reliability Substrate for AI

85 lines 2.79 kB
import type { L0Options, L0Result } from "./l0"; export interface WindowOptions { size?: number; overlap?: number; strategy?: ChunkStrategy; estimateTokens?: (text: string) => number; preserveParagraphs?: boolean; preserveSentences?: boolean; metadata?: Record<string, any>; } export type ChunkStrategy = "token" | "char" | "paragraph" | "sentence"; export interface DocumentChunk { index: number; content: string; startPos: number; endPos: number; tokenCount: number; charCount: number; isFirst: boolean; isLast: boolean; totalChunks: number; metadata?: Record<string, any>; } export interface DocumentWindow { readonly document: string; readonly totalChunks: number; readonly currentIndex: number; readonly options: Required<WindowOptions>; get(index: number): DocumentChunk | null; current(): DocumentChunk | null; next(): DocumentChunk | null; prev(): DocumentChunk | null; jump(index: number): DocumentChunk | null; reset(): DocumentChunk | null; getAllChunks(): DocumentChunk[]; getRange(start: number, end: number): DocumentChunk[]; hasNext(): boolean; hasPrev(): boolean; processAll(processFn: (chunk: DocumentChunk) => L0Options): Promise<WindowProcessResult[]>; processSequential(processFn: (chunk: DocumentChunk) => L0Options): Promise<WindowProcessResult[]>; processParallel(processFn: (chunk: DocumentChunk) => L0Options, options?: { concurrency?: number; }): Promise<WindowProcessResult[]>; getStats(): WindowStats; } export interface WindowProcessResult { chunk: DocumentChunk; result?: L0Result; status: "success" | "error"; error?: Error; duration: number; } export interface WindowStats { totalChunks: number; totalChars: number; totalTokens: number; avgChunkSize: number; avgChunkTokens: number; overlapSize: number; strategy: ChunkStrategy; } export interface ContextRestorationOptions { enabled?: boolean; strategy?: ContextRestorationStrategy; maxAttempts?: number; onRestore?: (from: number, to: number) => void; } export type ContextRestorationStrategy = "adjacent" | "overlap" | "full"; export interface L0WindowOptions extends L0Options { window?: DocumentWindow; chunkIndex?: number; contextRestoration?: ContextRestorationOptions; } export interface WindowPreset { name: string; size: number; overlap: number; strategy: ChunkStrategy; } export declare const smallWindow: WindowPreset; export declare const mediumWindow: WindowPreset; export declare const largeWindow: WindowPreset; export declare const paragraphWindow: WindowPreset; export declare const sentenceWindow: WindowPreset; //# sourceMappingURL=window.d.ts.map