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

348 lines (347 loc) • 11.9 kB
/** * MIME Type Constants * Centralized MIME type definitions organized by category for file processing * * @module processors/config/mimeTypes */ import { EXTENSION_MIME_OVERRIDES, FILE_TYPE_REGISTRY, normalizeExtension, } from "./fileTypeRegistry.js"; // ============================================================================= // IMAGE MIME TYPES // ============================================================================= /** * Image format MIME types supported by the platform */ export const IMAGE_MIME_TYPES = { /** JPEG image format */ JPEG: "image/jpeg", /** PNG image format */ PNG: "image/png", /** GIF image format */ GIF: "image/gif", /** WebP image format */ WEBP: "image/webp", /** SVG vector image format */ SVG: "image/svg+xml", /** BMP bitmap format */ BMP: "image/bmp", /** TIFF image format */ TIFF: "image/tiff", /** AVIF image format */ AVIF: "image/avif", /** HEIC image format (Apple) */ HEIC: "image/heic", /** HEIF image format */ HEIF: "image/heif", /** ICO icon format */ ICO: "image/x-icon", /** Microsoft ICO format */ ICO_MS: "image/vnd.microsoft.icon", }; // ============================================================================= // DOCUMENT MIME TYPES // ============================================================================= /** * Document format MIME types for office documents and PDFs */ export const DOCUMENT_MIME_TYPES = { /** PDF document format */ PDF: "application/pdf", /** Microsoft Word (DOCX) */ DOCX: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", /** Legacy Microsoft Word (DOC) */ DOC: "application/msword", /** Microsoft Excel (XLSX) */ XLSX: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", /** Legacy Microsoft Excel (XLS) */ XLS: "application/vnd.ms-excel", /** Microsoft PowerPoint (PPTX) */ PPTX: "application/vnd.openxmlformats-officedocument.presentationml.presentation", /** Legacy Microsoft PowerPoint (PPT) */ PPT: "application/vnd.ms-powerpoint", /** OpenDocument Text */ ODT: "application/vnd.oasis.opendocument.text", /** OpenDocument Spreadsheet */ ODS: "application/vnd.oasis.opendocument.spreadsheet", /** OpenDocument Presentation */ ODP: "application/vnd.oasis.opendocument.presentation", /** Rich Text Format */ RTF: "application/rtf", /** RTF as text type */ RTF_TEXT: "text/rtf", }; // ============================================================================= // DATA FORMAT MIME TYPES // ============================================================================= /** * Data interchange format MIME types */ export const DATA_MIME_TYPES = { /** JSON data format */ JSON: "application/json", /** XML data format */ XML: "application/xml", /** XML as text type */ XML_TEXT: "text/xml", /** CSV data format */ CSV: "text/csv", /** YAML data format */ YAML: "text/yaml", /** YAML as application type */ YAML_APP: "application/x-yaml", }; // ============================================================================= // TEXT MIME TYPES // ============================================================================= /** * Text format MIME types for plain text and markup */ export const TEXT_MIME_TYPES = { /** Plain text */ PLAIN: "text/plain", /** HTML markup */ HTML: "text/html", /** XHTML markup */ XHTML: "application/xhtml+xml", /** Markdown text */ MARKDOWN: "text/markdown", /** Markdown text (alternative MIME type) */ MARKDOWN_ALT: "text/x-markdown", /** CSS stylesheet */ CSS: "text/css", /** JavaScript code */ JAVASCRIPT: "text/javascript", /** JavaScript as application type */ JAVASCRIPT_APP: "application/javascript", }; // ============================================================================= // SOURCE CODE MIME TYPES // ============================================================================= /** * Programming language source code MIME types */ export const SOURCE_CODE_MIME_TYPES = { /** TypeScript code */ TYPESCRIPT: "text/typescript", /** Python code */ PYTHON: "text/x-python", /** Java code */ JAVA: "text/x-java-source", /** Go code */ GO: "text/x-go", /** Rust code */ RUST: "text/x-rustsrc", /** C code */ C: "text/x-c", /** C++ code */ CPP: "text/x-c++", /** C# code */ CSHARP: "text/x-csharp", /** Ruby code */ RUBY: "text/x-ruby", /** PHP code */ PHP: "text/x-php", /** Shell script */ SHELL: "text/x-shellscript", /** SQL query */ SQL: "text/x-sql", }; // ============================================================================= // ARCHIVE MIME TYPES // ============================================================================= /** * Archive and compressed file MIME types */ export const ARCHIVE_MIME_TYPES = { /** ZIP archive */ ZIP: "application/zip", /** ZIP compressed variant */ ZIP_COMPRESSED: "application/x-zip-compressed", /** GZIP compressed */ GZIP: "application/gzip", /** TAR archive */ TAR: "application/x-tar", /** RAR archive */ RAR: "application/x-rar-compressed", /** RAR vendor type */ RAR_VND: "application/vnd.rar", /** 7-Zip archive */ SEVEN_ZIP: "application/x-7z-compressed", /** Generic binary stream */ OCTET_STREAM: "application/octet-stream", }; // ============================================================================= // MULTIMEDIA MIME TYPES // ============================================================================= /** * Video format MIME types */ export const VIDEO_MIME_TYPES = { /** MP4 video */ MP4: "video/mp4", /** AVI video */ AVI: "video/avi", /** QuickTime video */ MOV: "video/quicktime", /** Matroska video */ MKV: "video/x-matroska", /** WebM video */ WEBM: "video/webm", /** Flash video */ FLV: "video/x-flv", /** Windows Media Video */ WMV: "video/x-ms-wmv", }; /** * Audio format MIME types */ export const AUDIO_MIME_TYPES = { /** MP3 audio */ MP3: "audio/mpeg", /** WAV audio */ WAV: "audio/wav", /** AAC audio */ AAC: "audio/aac", /** FLAC audio */ FLAC: "audio/flac", /** OGG audio */ OGG: "audio/ogg", /** M4A audio */ M4A: "audio/mp4", /** WMA audio */ WMA: "audio/x-ms-wma", }; // ============================================================================= // COMBINED MIME TYPES // ============================================================================= /** * All MIME types combined into a single object for convenience */ export const MIME_TYPES = { // Images ...IMAGE_MIME_TYPES, // Documents ...DOCUMENT_MIME_TYPES, // Data formats ...DATA_MIME_TYPES, // Text formats ...TEXT_MIME_TYPES, // Source code ...SOURCE_CODE_MIME_TYPES, // Archives ...ARCHIVE_MIME_TYPES, // Video ...VIDEO_MIME_TYPES, // Audio ...AUDIO_MIME_TYPES, }; // ============================================================================= // EXTENSION TO MIME TYPE MAP // ============================================================================= /** * Extension → MIME for text, markup, source-code and config files. * * These are the formats that carry no modality of their own — they are inlined * into the prompt as text. Binary and structured formats (image, audio, video, * document, data, archive) are NOT listed here; they come from * {@link FILE_TYPE_REGISTRY}, which is the single source of truth for * everything multimodal. See `fileTypeRegistry.ts` for why. */ export const TEXT_EXTENSION_MIME_MAP = { // Text and Markup ".txt": TEXT_MIME_TYPES.PLAIN, ".md": TEXT_MIME_TYPES.MARKDOWN, ".markdown": TEXT_MIME_TYPES.MARKDOWN, ".html": TEXT_MIME_TYPES.HTML, ".htm": TEXT_MIME_TYPES.HTML, ".xhtml": TEXT_MIME_TYPES.XHTML, ".log": TEXT_MIME_TYPES.PLAIN, ".css": TEXT_MIME_TYPES.CSS, // Structured text. // YAML uses the IANA-registered `application/yaml` (RFC 9512) rather than the // legacy `application/x-yaml`. This is also what the content heuristic already // reports for YAML bytes, so the extension path and the content path no longer // disagree about the same file. ".json": DATA_MIME_TYPES.JSON, ".xml": DATA_MIME_TYPES.XML, ".yaml": "application/yaml", ".yml": "application/yaml", // Source code ".js": TEXT_MIME_TYPES.JAVASCRIPT, ".mjs": TEXT_MIME_TYPES.JAVASCRIPT, ".cjs": TEXT_MIME_TYPES.JAVASCRIPT, ".ts": SOURCE_CODE_MIME_TYPES.TYPESCRIPT, ".tsx": SOURCE_CODE_MIME_TYPES.TYPESCRIPT, ".jsx": TEXT_MIME_TYPES.JAVASCRIPT, ".py": SOURCE_CODE_MIME_TYPES.PYTHON, ".java": SOURCE_CODE_MIME_TYPES.JAVA, ".go": SOURCE_CODE_MIME_TYPES.GO, ".rs": SOURCE_CODE_MIME_TYPES.RUST, ".rb": SOURCE_CODE_MIME_TYPES.RUBY, ".php": SOURCE_CODE_MIME_TYPES.PHP, ".c": SOURCE_CODE_MIME_TYPES.C, ".cpp": SOURCE_CODE_MIME_TYPES.CPP, ".h": SOURCE_CODE_MIME_TYPES.C, ".hpp": SOURCE_CODE_MIME_TYPES.CPP, ".cs": SOURCE_CODE_MIME_TYPES.CSHARP, ".swift": "text/x-swift", ".kt": "text/x-kotlin", ".scala": "text/x-scala", ".sh": SOURCE_CODE_MIME_TYPES.SHELL, ".bash": SOURCE_CODE_MIME_TYPES.SHELL, ".zsh": SOURCE_CODE_MIME_TYPES.SHELL, ".ps1": "text/x-powershell", ".sql": SOURCE_CODE_MIME_TYPES.SQL, ".r": "text/x-r", ".lua": "text/x-lua", ".perl": "text/x-perl", ".pl": "text/x-perl", // Config files ".env": TEXT_MIME_TYPES.PLAIN, ".ini": TEXT_MIME_TYPES.PLAIN, ".toml": TEXT_MIME_TYPES.PLAIN, ".cfg": TEXT_MIME_TYPES.PLAIN, ".conf": TEXT_MIME_TYPES.PLAIN, ".properties": TEXT_MIME_TYPES.PLAIN, ".gitignore": TEXT_MIME_TYPES.PLAIN, ".dockerignore": TEXT_MIME_TYPES.PLAIN, ".editorconfig": TEXT_MIME_TYPES.PLAIN, ".prettierrc": DATA_MIME_TYPES.JSON, ".eslintrc": DATA_MIME_TYPES.JSON, ".babelrc": DATA_MIME_TYPES.JSON, }; /** * Centralized mapping of file extensions (with leading dot) to MIME types. * * Assembled from two sources so there is exactly one place to edit per kind of * format: every image / audio / video / document / data / archive entry is * derived from {@link FILE_TYPE_REGISTRY}, and the text, markup, source-code * and config entries come from {@link TEXT_EXTENSION_MIME_MAP}. * * Registry entries are spread last so that a format which appears in both wins * from the registry — the registry is the authority for anything with a * modality. */ export const EXTENSION_MIME_MAP = { ...TEXT_EXTENSION_MIME_MAP, ...Object.fromEntries(FILE_TYPE_REGISTRY.flatMap((entry) => entry.extensions.map((ext) => [ext, entry.mimeTypes[0]]))), // Applied last: an ambiguous extension (.ts) must report the MIME type of the // format its routing was overridden to, or this map and the registry's // mimeTypeForExtension() describe the same file differently. ...EXTENSION_MIME_OVERRIDES, }; /** * Get MIME type from file extension using the centralized map. * * Accepts a bare extension (`"pdf"`), a dotted extension (`".pdf"`), a filename * or a full path — `normalizeExtension` handles all four, including compound * suffixes like `.tar.gz`. * * @param ext - File extension, filename or path * @returns MIME type string, or "application/octet-stream" if unknown */ export function getMimeTypeForExtension(ext) { return (EXTENSION_MIME_MAP[normalizeExtension(ext)] || "application/octet-stream"); } // ============================================================================= // TYPE EXPORTS // =============================================================================