UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio

177 lines (176 loc) 6.12 kB
/** * File Processor Integration * * Provides integration between the ProcessorRegistry and message building. * This module allows for automatic file type detection and processing * using the registered file processors. * * @module processors/integration/FileProcessorIntegration * * @example * ```typescript * import { * processFileWithRegistry, * processBatchWithRegistry, * getSupportedFileTypes, * isFileTypeSupported, * getProcessorForFile, * } from "./integration/index.js"; * * // Process a single file * const { processorName, result } = await processFileWithRegistry(fileInfo); * if (result?.success) { * console.log(`Processed with ${processorName}:`, result.data); * } * * // Process multiple files * const batchResult = await processBatchWithRegistry(files, { maxFiles: 50 }); * console.log(`Successful: ${batchResult.successful.length}`); * console.log(`Failed: ${batchResult.failed.length}`); * console.log(`Skipped: ${batchResult.skipped.length}`); * * // Check if a file type is supported * if (isFileTypeSupported("application/pdf", "document.pdf")) { * console.log("PDF files are supported"); * } * ``` */ import type { FileInfo, ProcessorFileProcessingResult, ProcessedFileBase, ProcessorMatch, BatchFileProcessingResult, FileProcessingOptions } from "../../types/index.js"; /** * Process a single file using the ProcessorRegistry. * Automatically detects the appropriate processor based on MIME type and filename. * * @param fileInfo - File information including content/URL * @param options - Processing options (preferred processor, auth headers, timeout) * @returns Object containing processor name (null if none found) and processing result * * @example * ```typescript * // Basic usage - auto-detect processor * const { processorName, result } = await processFileWithRegistry({ * id: "file-123", * name: "document.pdf", * mimetype: "application/pdf", * size: 1024000, * url: "https://example.com/document.pdf", * }); * * if (result?.success) { * console.log(`Processed by ${processorName}:`, result.data); * } * * // Use a specific processor * const { result } = await processFileWithRegistry(fileInfo, { * preferredProcessor: "pdf", * }); * * // With authentication and timeout * const { result } = await processFileWithRegistry(fileInfo, { * authHeaders: { Authorization: "Bearer token123" }, * timeout: 60000, * }); * ``` */ export declare function processFileWithRegistry(fileInfo: FileInfo, options?: FileProcessingOptions): Promise<{ processorName: string | null; result: ProcessorFileProcessingResult<ProcessedFileBase> | null; }>; /** * Process multiple files using the ProcessorRegistry. * Files are processed sequentially and categorized by outcome. * * @param files - Array of file information objects * @param options - Processing options (max files, auth headers, timeout) * @returns Batch result with successful, failed, and skipped files * * @example * ```typescript * const files: FileInfo[] = [ * { id: "1", name: "image.jpg", mimetype: "image/jpeg", size: 512000 }, * { id: "2", name: "doc.pdf", mimetype: "application/pdf", size: 1024000 }, * { id: "3", name: "unknown.xyz", mimetype: "application/octet-stream", size: 100 }, * ]; * * const result = await processBatchWithRegistry(files, { * maxFiles: 50, * timeout: 60000, * }); * * console.log(`Processed ${result.successful.length} files successfully`); * console.log(`Failed: ${result.failed.length}`); * console.log(`Skipped: ${result.skipped.length}`); * * // Access individual results * for (const { fileInfo, processorName, result } of result.successful) { * console.log(`${fileInfo.name}: ${result.data?.size} bytes`); * } * ``` */ export declare function processBatchWithRegistry(files: FileInfo[], options?: FileProcessingOptions): Promise<BatchFileProcessingResult>; /** * Get a list of supported file types from the registry. * Returns information about each registered processor including * supported MIME types, extensions, and priority. * * @returns Array of processor information objects * * @example * ```typescript * const supportedTypes = getSupportedFileTypes(); * * for (const { name, mimeTypes, extensions, priority } of supportedTypes) { * console.log(`${name} (priority: ${priority})`); * console.log(` MIME types: ${mimeTypes.join(", ")}`); * console.log(` Extensions: ${extensions.join(", ")}`); * } * ``` */ export declare function getSupportedFileTypes(): Promise<Array<{ name: string; mimeTypes: string[]; extensions: string[]; priority: number; }>>; /** * Check if a file type is supported by any registered processor. * * @param mimetype - MIME type of the file * @param filename - Filename (for extension-based detection) * @returns true if a processor exists for this file type * * @example * ```typescript * // Check by MIME type and filename * if (isFileTypeSupported("application/pdf", "document.pdf")) { * console.log("PDF files are supported"); * } * * // Useful for validation before upload * function validateFile(file: File): boolean { * return isFileTypeSupported(file.type, file.name); * } * ``` */ export declare function isFileTypeSupported(mimetype: string, filename: string): Promise<boolean>; /** * Get the processor that would handle a specific file. * Returns the full processor match including confidence score. * * @param mimetype - MIME type of the file * @param filename - Filename (for extension-based detection) * @returns Processor match or null if no processor found * * @example * ```typescript * const match = getProcessorForFile("image/jpeg", "photo.jpg"); * * if (match) { * console.log(`Would use ${match.name} processor`); * console.log(`Priority: ${match.priority}`); * console.log(`Confidence: ${match.confidence}%`); * } else { * console.log("No processor available for this file type"); * } * ``` */ export declare function getProcessorForFile(mimetype: string, filename: string): Promise<ProcessorMatch | null>;