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

122 lines (121 loc) 4.09 kB
const OPAQUE_MIMETYPE = "application/octet-stream"; /** * Normalize a caller-provided mimetype hint: strip any `;charset=...` * parameter, lowercase, trim. Returns undefined for empty strings or for * the opaque `application/octet-stream` sentinel so downstream code can * treat the hint as absent instead of trusting it verbatim. */ export function normalizeMimeHint(raw) { if (!raw) { return undefined; } const cleaned = raw.split(";")[0].trim().toLowerCase(); if (!cleaned || cleaned === OPAQUE_MIMETYPE) { return undefined; } return cleaned; } /** * Map a normalized mimetype hint to a NeuroLink FileType. Returns null when * the mimetype is unknown or too generic to classify confidently. */ export function mimeHintToFileType(mimetype) { const exact = { "text/csv": "csv", "application/csv": "csv", "image/svg+xml": "svg", "application/pdf": "pdf", "application/json": "text", "application/xml": "text", "text/xml": "text", "application/yaml": "text", "application/x-yaml": "text", "text/yaml": "text", "application/javascript": "text", "application/typescript": "text", "application/zip": "archive", "application/x-tar": "archive", "application/gzip": "archive", "application/x-gzip": "archive", "application/x-7z-compressed": "archive", "application/vnd.rar": "archive", "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx", "application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx", }; if (exact[mimetype]) { return exact[mimetype]; } if (mimetype.startsWith("text/")) { return "text"; } if (mimetype.startsWith("image/")) { return "image"; } if (mimetype.startsWith("audio/")) { return "audio"; } if (mimetype.startsWith("video/")) { return "video"; } return null; } /** * Map a normalized mimetype hint to the canonical file extension (without * leading dot). Returns "" when the mimetype is unknown — caller should * then fall back to magic-byte detection. */ export function mimeHintToExtension(mimetype) { const table = { // Text "text/plain": "txt", "text/html": "html", "text/css": "css", "text/javascript": "js", "application/javascript": "js", "application/typescript": "ts", "text/markdown": "md", "text/csv": "csv", "application/csv": "csv", "application/json": "json", "application/xml": "xml", "text/xml": "xml", "application/yaml": "yaml", "application/x-yaml": "yaml", "text/yaml": "yaml", // Documents "application/pdf": "pdf", "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx", "application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx", // Images "image/png": "png", "image/jpeg": "jpg", "image/gif": "gif", "image/webp": "webp", "image/bmp": "bmp", "image/tiff": "tiff", "image/svg+xml": "svg", // Video "video/mp4": "mp4", "video/webm": "webm", "video/quicktime": "mov", "video/x-matroska": "mkv", "video/x-msvideo": "avi", // Audio "audio/mpeg": "mp3", "audio/wav": "wav", "audio/ogg": "ogg", "audio/flac": "flac", "audio/mp4": "m4a", "audio/aac": "aac", // Archives "application/zip": "zip", "application/x-tar": "tar", "application/gzip": "gz", "application/x-gzip": "gz", "application/x-7z-compressed": "7z", "application/vnd.rar": "rar", }; return table[mimetype] || ""; }