UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

143 lines (142 loc) • 4.52 kB
/** * Document Loaders * * Provides loaders for various document formats including: * - Text files * - Markdown files * - HTML files and web pages * - JSON files * - CSV files * - PDF files * * @example * ```typescript * import { loadDocument, WebLoader, PDFLoader } from 'neurolink/rag'; * * // Load from file path * const doc = await loadDocument('/path/to/document.md'); * * // Load from URL * const webDoc = await WebLoader.load('https://example.com/article'); * * // Load PDF * const pdfDoc = await PDFLoader.load('/path/to/document.pdf'); * ``` */ import type { LoaderOptions, WebLoaderOptions, PDFLoaderOptions, CSVLoaderOptions, DocumentLoader } from "../../types/index.js"; import { MDocument } from "./MDocument.js"; /** * Text file loader */ export declare class TextLoader implements DocumentLoader { load(source: string, options?: LoaderOptions): Promise<MDocument>; canHandle(source: string): boolean; protected loadContent(source: string, encoding?: BufferEncoding): Promise<string>; protected getSourceName(source: string): string; } /** * Markdown file loader */ export declare class MarkdownLoader extends TextLoader { load(source: string, options?: LoaderOptions): Promise<MDocument>; canHandle(source: string): boolean; } /** * HTML file loader */ export declare class HTMLLoader extends TextLoader { load(source: string, options?: LoaderOptions): Promise<MDocument>; canHandle(source: string): boolean; } /** * JSON file loader */ export declare class JSONLoader extends TextLoader { load(source: string, options?: LoaderOptions): Promise<MDocument>; canHandle(source: string): boolean; } /** * CSV file loader */ export declare class CSVLoader extends TextLoader { load(source: string, options?: CSVLoaderOptions): Promise<MDocument>; canHandle(source: string): boolean; private toMarkdownTable; private toTextTable; /** * Collapse embedded newlines to a single space so one logical CSV row * renders as exactly one line in the text/markdown table output. * * The shared quote-aware parser (`splitCsvLines` + `splitCSVFields`) * preserves newlines embedded inside a quoted field verbatim — correct * for the `json` output format (where `JSON.stringify` escapes them), but * left as-is here it would split a single record across multiple * physical table rows. Mirrors the same normalization `CSVProcessor` * already applies in its own markdown formatter. */ private collapseEmbeddedNewlines; } /** * PDF file loader * * Note: Requires external PDF processing library for full functionality. * Falls back to placeholder implementation if pdf-parse is not available. */ export declare class PDFLoader implements DocumentLoader { load(source: string, options?: PDFLoaderOptions): Promise<MDocument>; canHandle(source: string): boolean; private loadPdfParser; private parsePageRange; } /** * Web page loader * * Fetches and extracts content from web pages. * Supports basic HTML parsing without external dependencies. */ export declare class WebLoader implements DocumentLoader { private defaultUserAgent; load(source: string, options?: WebLoaderOptions): Promise<MDocument>; canHandle(source: string): boolean; /** * Extract main content from HTML */ private extractMainContent; /** * Convert HTML to plain text */ private htmlToText; } /** * Load document from file path, URL, or content * * Automatically detects the document type and uses the appropriate loader. * * @param source - File path, URL, or raw content * @param options - Loader options * @returns Promise resolving to MDocument * * @example * ```typescript * // Load from file * const doc = await loadDocument('/path/to/document.md'); * * // Load from URL * const webDoc = await loadDocument('https://example.com/article'); * * // Load with options * const pdfDoc = await loadDocument('/path/to/doc.pdf', { * pageRange: '1-5', * metadata: { project: 'research' } * }); * ``` */ export declare function loadDocument(source: string, options?: LoaderOptions): Promise<MDocument>; /** * Load multiple documents * * @param sources - Array of file paths, URLs, or content * @param options - Loader options (applied to all) * @returns Promise resolving to array of MDocuments */ export declare function loadDocuments(sources: string[], options?: LoaderOptions): Promise<MDocument[]>;