@juspay/neurolink 10.10.12 → 10.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/adapters/imageFormatSupport.d.ts +75 -0
  3. package/dist/adapters/imageFormatSupport.js +283 -0
  4. package/dist/adapters/video/ffmpegAdapter.d.ts +6 -0
  5. package/dist/adapters/video/ffmpegAdapter.js +1 -1
  6. package/dist/browser/neurolink.min.js +399 -398
  7. package/dist/lib/adapters/imageFormatSupport.d.ts +75 -0
  8. package/dist/lib/adapters/imageFormatSupport.js +284 -0
  9. package/dist/lib/adapters/video/ffmpegAdapter.d.ts +6 -0
  10. package/dist/lib/adapters/video/ffmpegAdapter.js +1 -1
  11. package/dist/lib/processors/config/fileExtensions.d.ts +32 -15
  12. package/dist/lib/processors/config/fileExtensions.js +27 -66
  13. package/dist/lib/processors/config/fileTypeRegistry.d.ts +106 -0
  14. package/dist/lib/processors/config/fileTypeRegistry.js +702 -0
  15. package/dist/lib/processors/config/index.d.ts +2 -1
  16. package/dist/lib/processors/config/index.js +5 -1
  17. package/dist/lib/processors/config/mimeConstants.d.ts +22 -7
  18. package/dist/lib/processors/config/mimeConstants.js +45 -66
  19. package/dist/lib/processors/media/AudioProcessor.js +16 -38
  20. package/dist/lib/processors/media/VideoProcessor.js +11 -32
  21. package/dist/lib/providers/googleAiStudio/client.js +12 -1
  22. package/dist/lib/providers/googleVertex/client.js +123 -66
  23. package/dist/lib/types/file.d.ts +41 -0
  24. package/dist/lib/utils/fileDetector.js +367 -251
  25. package/dist/lib/utils/imageProcessor.js +14 -17
  26. package/dist/lib/utils/markupSniff.d.ts +37 -0
  27. package/dist/lib/utils/markupSniff.js +125 -0
  28. package/dist/lib/utils/messageBuilder.d.ts +14 -0
  29. package/dist/lib/utils/messageBuilder.js +172 -92
  30. package/dist/processors/config/fileExtensions.d.ts +32 -15
  31. package/dist/processors/config/fileExtensions.js +27 -66
  32. package/dist/processors/config/fileTypeRegistry.d.ts +106 -0
  33. package/dist/processors/config/fileTypeRegistry.js +701 -0
  34. package/dist/processors/config/index.d.ts +2 -1
  35. package/dist/processors/config/index.js +5 -1
  36. package/dist/processors/config/mimeConstants.d.ts +22 -7
  37. package/dist/processors/config/mimeConstants.js +45 -66
  38. package/dist/processors/media/AudioProcessor.js +16 -38
  39. package/dist/processors/media/VideoProcessor.js +11 -32
  40. package/dist/providers/googleAiStudio/client.js +12 -1
  41. package/dist/providers/googleVertex/client.js +123 -66
  42. package/dist/types/file.d.ts +41 -0
  43. package/dist/utils/fileDetector.js +367 -251
  44. package/dist/utils/imageProcessor.js +14 -17
  45. package/dist/utils/markupSniff.d.ts +37 -0
  46. package/dist/utils/markupSniff.js +124 -0
  47. package/dist/utils/messageBuilder.d.ts +14 -0
  48. package/dist/utils/messageBuilder.js +172 -92
  49. package/package.json +3 -2
@@ -2,31 +2,32 @@
2
2
  * File Extension Constants
3
3
  * Centralized file extension definitions organized by category for file processing
4
4
  *
5
+ * The media/document/data/archive categories are derived from
6
+ * {@link FILE_TYPE_REGISTRY} rather than typed out here — they used to be a
7
+ * second hand-maintained list that drifted from both the registry-equivalent
8
+ * MIME map and the detector, so formats appeared "supported" in one place and
9
+ * were invisible in another. Source-code and text categories, which carry no
10
+ * modality, are still enumerated below.
11
+ *
5
12
  * @module processors/config/fileTypes
6
13
  */
14
+ import { extensionsForModality } from "./fileTypeRegistry.js";
7
15
  // =============================================================================
8
16
  // IMAGE FILE EXTENSIONS
9
17
  // =============================================================================
10
18
  /**
11
- * Image file extensions supported by the platform
19
+ * Image file extensions supported by the platform.
20
+ * Includes `.svg`, which is processed as sanitized markup rather than raster.
12
21
  */
13
- export const IMAGE_EXTENSIONS = [
14
- ".jpg",
15
- ".jpeg",
16
- ".png",
17
- ".gif",
18
- ".webp",
19
- ".svg",
20
- ".bmp",
21
- ".tiff",
22
- ".tif",
23
- ".avif",
24
- ".heic",
25
- ".heif",
26
- ".ico",
27
- ];
22
+ export const IMAGE_EXTENSIONS = extensionsForModality("image");
28
23
  /**
29
- * AI vision-supported image extensions (subset that works with AI models)
24
+ * Image extensions every vision-capable provider accepts as-is.
25
+ *
26
+ * Deliberately NOT derived from the registry: this is the intersection of what
27
+ * OpenAI, Anthropic, Google and Bedrock all accept, not the set NeuroLink can
28
+ * identify. Anything else the registry knows about (BMP, TIFF, AVIF, ICO,
29
+ * HEIC/HEIF) is transcoded to PNG before dispatch — see
30
+ * `adapters/imageFormatSupport.ts`.
30
31
  */
31
32
  export const AI_VISION_EXTENSIONS = [
32
33
  ".jpg",
@@ -41,19 +42,7 @@ export const AI_VISION_EXTENSIONS = [
41
42
  /**
42
43
  * Document file extensions for office documents and PDFs
43
44
  */
44
- export const DOCUMENT_EXTENSIONS = [
45
- ".pdf",
46
- ".docx",
47
- ".doc",
48
- ".xlsx",
49
- ".xls",
50
- ".pptx",
51
- ".ppt",
52
- ".odt",
53
- ".ods",
54
- ".odp",
55
- ".rtf",
56
- ];
45
+ export const DOCUMENT_EXTENSIONS = extensionsForModality("document");
57
46
  /**
58
47
  * PDF document extensions
59
48
  */
@@ -98,14 +87,17 @@ export const CSV_EXTENSIONS = [".csv"];
98
87
  */
99
88
  export const YAML_EXTENSIONS = [".yaml", ".yml"];
100
89
  /**
101
- * All data format extensions combined
90
+ * All data format extensions combined.
91
+ *
92
+ * The tabular formats (.csv/.tsv) come from the registry; .json/.xml/.yaml are
93
+ * text formats with no modality of their own and stay listed here.
102
94
  */
103
95
  export const DATA_EXTENSIONS = [
104
96
  ".json",
105
97
  ".xml",
106
- ".csv",
107
98
  ".yaml",
108
99
  ".yml",
100
+ ...extensionsForModality("data"),
109
101
  ];
110
102
  // =============================================================================
111
103
  // TEXT FILE EXTENSIONS
@@ -346,49 +338,18 @@ export const CONFIG_EXTENSIONS = [
346
338
  /**
347
339
  * Archive and compressed file extensions
348
340
  */
349
- export const ARCHIVE_EXTENSIONS = [
350
- ".zip",
351
- ".tar",
352
- ".gz",
353
- ".tgz",
354
- ".tar.gz",
355
- ".tar.bz2",
356
- ".bz2",
357
- ".rar",
358
- ".7z",
359
- ".xz",
360
- ];
341
+ export const ARCHIVE_EXTENSIONS = extensionsForModality("archive");
361
342
  // =============================================================================
362
343
  // MULTIMEDIA FILE EXTENSIONS
363
344
  // =============================================================================
364
345
  /**
365
346
  * Video file extensions
366
347
  */
367
- export const VIDEO_EXTENSIONS = [
368
- ".mp4",
369
- ".avi",
370
- ".mov",
371
- ".mkv",
372
- ".webm",
373
- ".flv",
374
- ".wmv",
375
- ".m4v",
376
- ".mpg",
377
- ".mpeg",
378
- ];
348
+ export const VIDEO_EXTENSIONS = extensionsForModality("video");
379
349
  /**
380
350
  * Audio file extensions
381
351
  */
382
- export const AUDIO_EXTENSIONS = [
383
- ".mp3",
384
- ".wav",
385
- ".aac",
386
- ".flac",
387
- ".ogg",
388
- ".m4a",
389
- ".wma",
390
- ".opus",
391
- ];
352
+ export const AUDIO_EXTENSIONS = extensionsForModality("audio");
392
353
  // =============================================================================
393
354
  // DESIGN FILE EXTENSIONS
394
355
  // =============================================================================
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Canonical file-format registry — the single source of truth for
3
+ * extension ↔ MIME ↔ FileType ↔ modality.
4
+ *
5
+ * ## Why this exists
6
+ *
7
+ * The same knowledge used to live in five hand-maintained tables that had no
8
+ * way of agreeing with each other:
9
+ *
10
+ * 1. `EXTENSION_MIME_MAP` (config/mimeConstants.ts)
11
+ * 2. the `*_EXTENSIONS` category arrays (config/fileExtensions.ts)
12
+ * 3. `ExtensionStrategy.typeMap` + `.mimeMap` (utils/fileDetector.ts)
13
+ * 4. `EXTENSION_TYPE_MAP` (utils/messageBuilder.ts)
14
+ * 5. each processor's `supportedExtensions` / `supportedMimeTypes`
15
+ *
16
+ * They drifted, and the drift was not cosmetic — a format that a processor
17
+ * declared it supported was routinely invisible to the detector standing in
18
+ * front of it, so the file never reached the processor at all. Measured on real
19
+ * ffmpeg-generated media before this registry existed:
20
+ *
21
+ * .aiff .m2ts .mts .vob .3g2 .3gp → "unknown" (downgraded to metadata text)
22
+ * .mpg .mpeg → "csv" (binary parsed as a spreadsheet)
23
+ * .ts → "text" (MPEG-TS inlined as source code)
24
+ *
25
+ * Deriving all five consumers from one table makes that class of drift
26
+ * structurally impossible rather than merely fixed once.
27
+ *
28
+ * ## Invariants
29
+ *
30
+ * - `extensions[0]` is canonical for the format; the rest are accepted aliases.
31
+ * - `mimeTypes[0]` is canonical; the rest are aliases seen in the wild
32
+ * (`audio/x-wav`, `image/x-icon`, vendor prefixes, …).
33
+ * - Every extension and every MIME type appears in exactly one entry. The
34
+ * `assertRegistryIsUnambiguous()` check below is executed at module load, so
35
+ * a duplicate is a startup failure rather than a silent last-write-wins.
36
+ * - `fileType` is the *routing* type the detector emits (what processor to
37
+ * use); `modality` is the *category* a human means. They deliberately differ:
38
+ * an .odt is `fileType: "docx"` (the Word processor handles it) but
39
+ * `modality: "document"`, and .svg is `fileType: "svg"` (sanitised as markup,
40
+ * never sent to a vision API) but `modality: "image"`.
41
+ *
42
+ * @module processors/config/fileTypeRegistry
43
+ */
44
+ import type { FileFormatEntry, FileModality, FileType } from "../../types/index.js";
45
+ /**
46
+ * Every file format NeuroLink can identify, grouped by modality.
47
+ *
48
+ * Adding a format here is all that is required — the extension map, the MIME
49
+ * map, the detector's lookup tables, the category arrays and the media
50
+ * processors' supported-format lists are all derived from this array.
51
+ */
52
+ export declare const FILE_TYPE_REGISTRY: readonly FileFormatEntry[];
53
+ /**
54
+ * Extensions that must NOT be treated as belonging to their registry entry's
55
+ * modality when only a filename is available.
56
+ *
57
+ * Derived from {@link EXTENSION_OVERRIDES}: `extensionsForModality("video")`
58
+ * feeds both `VIDEO_EXTENSIONS` and `VideoProcessor`'s supported list, and
59
+ * `BaseFileProcessor.isFileSupported` accepts a file when the *extension*
60
+ * matches even if the supplied mimetype says otherwise. Leaving `.ts` in that
61
+ * list made `isVideoFile("text/plain", "app.ts")` return true.
62
+ */
63
+ /**
64
+ * Extension → MIME for the overridden extensions only.
65
+ *
66
+ * Exported so `EXTENSION_MIME_MAP` can apply the override as its FINAL layer.
67
+ * That map is built by spreading the registry over the text map, so without
68
+ * this the registry's `.ts → video/mp2t` won again and `getMimeTypeForExtension`
69
+ * disagreed with `mimeTypeForExtension` about the very same file.
70
+ */
71
+ export declare const EXTENSION_MIME_OVERRIDES: Readonly<Record<string, string>>;
72
+ /**
73
+ * Normalize an extension to the registry's key form: lowercased, with a leading
74
+ * dot. Accepts `"png"`, `".PNG"`, `"image.png"` and `"/tmp/a.png"` alike.
75
+ *
76
+ * Compound extensions (`.tar.gz`) are matched before the single-segment form so
77
+ * a `.tar.gz` resolves to the gzip entry rather than to `.gz` by accident —
78
+ * they happen to agree today, but the lookup should not depend on that.
79
+ */
80
+ export declare function normalizeExtension(raw: string): string;
81
+ /** Look up the registry entry for a file extension, or undefined. */
82
+ export declare function lookupByExtension(ext: string): FileFormatEntry | undefined;
83
+ /**
84
+ * Look up the registry entry for a MIME type, or undefined. Any `;charset=…`
85
+ * parameter is stripped, matching how Content-Type headers arrive.
86
+ */
87
+ export declare function lookupByMimeType(mime: string): FileFormatEntry | undefined;
88
+ /**
89
+ * Routing {@link FileType} for an extension, honouring {@link EXTENSION_OVERRIDES}.
90
+ * Returns undefined when the extension is not in the registry.
91
+ */
92
+ export declare function fileTypeForExtension(ext: string): FileType | undefined;
93
+ /** Canonical MIME type for an extension, or undefined when unknown. */
94
+ export declare function mimeTypeForExtension(ext: string): string | undefined;
95
+ /** Canonical extension (with leading dot) for a MIME type, or undefined. */
96
+ export declare function extensionForMimeType(mime: string): string | undefined;
97
+ /** Every extension registered for a modality, in registry order. */
98
+ export declare function extensionsForModality(modality: FileModality): readonly string[];
99
+ /** Every MIME type registered for a modality, in registry order. */
100
+ export declare function mimeTypesForModality(modality: FileModality): readonly string[];
101
+ /**
102
+ * True when the extension belongs to the given modality. Uses the entry's
103
+ * modality, not its routing `fileType`, so `.svg` counts as an image and `.odt`
104
+ * counts as a document.
105
+ */
106
+ export declare function isModalityExtension(ext: string, modality: FileModality): boolean;