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

155 lines (154 loc) 4.74 kB
/** * SVG File Processor * * Processes SVG files as TEXT content, not as images, because: * 1. Most AI vision models don't support SVG format directly * 2. SVG is XML-based and can be analyzed as code/markup * 3. SVG can contain security risks (scripts, XSS vectors) * * Security: Uses OWASP-compliant allowlist-based SVG sanitization * * @module processors/markup/SvgProcessor * * @example * ```typescript * import { svgProcessor, processSvg, isSvgFile } from "./markup/SvgProcessor.js"; * * // Check if file is SVG * if (isSvgFile(mimetype, filename)) { * const result = await processSvg(fileInfo); * if (result.success) { * console.log('Sanitized SVG:', result.data.textContent); * if (result.data.securityWarnings.length > 0) { * console.warn('Security warnings:', result.data.securityWarnings); * } * } * } * ``` */ import { BaseFileProcessor } from "../base/BaseFileProcessor.js"; import type { FileInfo, ProcessorFileProcessingResult, ProcessOptions, ProcessedSvg } from "../../types/index.js"; /** * SVG Processor - processes SVG as TEXT, not as image. * * Why text instead of image: * 1. Most AI vision models don't support SVG format * 2. SVG is XML-based and can be analyzed as markup * 3. Security: SVG can contain scripts and XSS vectors * * Priority: 5 (before IMAGE at priority 10) * * @example * ```typescript * const processor = new SvgProcessor(); * * const result = await processor.processFile({ * id: 'svg-123', * name: 'diagram.svg', * mimetype: 'image/svg+xml', * size: 2048, * url: 'https://example.com/diagram.svg', * }); * * if (result.success) { * // Use sanitized SVG text content * console.log(result.data.textContent); * } * ``` */ export declare class SvgProcessor extends BaseFileProcessor<ProcessedSvg> { constructor(); /** * Validate downloaded SVG file. * Checks for valid XML structure (SVG must contain <svg> element). * * @param buffer - Downloaded file content * @param fileInfo - Original file information * @returns null if valid, error message if invalid */ protected validateDownloadedFile(buffer: Buffer, _fileInfo: FileInfo): Promise<string | null>; /** * Build processed SVG result with sanitized content. * Applies security sanitization to remove potentially malicious content. * * @param buffer - Downloaded file content * @param fileInfo - Original file information * @returns Processed SVG result with sanitized text content */ protected buildProcessedResult(buffer: Buffer, fileInfo: FileInfo): ProcessedSvg; } /** * Singleton SVG processor instance. * Use this for most processing needs. * * @example * ```typescript * import { svgProcessor } from "./markup/SvgProcessor.js"; * * const result = await svgProcessor.processFile(fileInfo); * ``` */ export declare const svgProcessor: SvgProcessor; /** * Check if a file is an SVG file. * * @param mimetype - MIME type of the file * @param filename - Filename (for extension-based detection) * @returns true if the file is an SVG * * @example * ```typescript * if (isSvgFile('image/svg+xml', 'diagram.svg')) { * // Handle as SVG * } * * // Also works with just filename * if (isSvgFile('', 'icon.svg')) { * // Handle as SVG based on extension * } * ``` */ export declare function isSvgFile(mimetype: string, filename: string): boolean; /** * Validate SVG file size against configured limit. * * @param sizeBytes - File size in bytes * @returns true if size is within the allowed limit (5 MB) * * @example * ```typescript * if (!validateSvgSize(fileInfo.size)) { * console.error('SVG file is too large'); * } * ``` */ export declare function validateSvgSize(sizeBytes: number): boolean; /** * Process a single SVG file. * Convenience function that uses the singleton processor. * * @param fileInfo - File information (can include URL or buffer) * @param options - Optional processing options (auth headers, timeout, retry config) * @returns Processing result with sanitized SVG text content * * @example * ```typescript * const result = await processSvg({ * id: 'svg-123', * name: 'diagram.svg', * mimetype: 'image/svg+xml', * size: 2048, * buffer: svgBuffer, * }); * * if (result.success) { * console.log('Processed SVG:', result.data.textContent); * if (result.data.sanitized) { * console.log('Content was sanitized for security'); * } * } else { * console.error('Processing failed:', result.error.userMessage); * } * ``` */ export declare function processSvg(fileInfo: FileInfo, options?: ProcessOptions): Promise<ProcessorFileProcessingResult<ProcessedSvg>>;