@juspay/neurolink 9.94.2 → 9.94.4

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 (39) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/agent/directTools.js +3 -1
  3. package/dist/browser/neurolink.min.js +400 -397
  4. package/dist/cli/factories/commandFactory.d.ts +6 -0
  5. package/dist/cli/factories/commandFactory.js +36 -8
  6. package/dist/lib/agent/directTools.js +3 -1
  7. package/dist/lib/neurolink.js +5 -0
  8. package/dist/lib/rag/document/loaders.js +20 -4
  9. package/dist/lib/types/file.d.ts +43 -0
  10. package/dist/lib/types/generate.d.ts +3 -11
  11. package/dist/lib/types/rag.d.ts +7 -0
  12. package/dist/lib/types/stream.d.ts +2 -6
  13. package/dist/lib/utils/csvProcessor.d.ts +68 -10
  14. package/dist/lib/utils/csvProcessor.js +499 -135
  15. package/dist/lib/utils/errorHandling.d.ts +32 -0
  16. package/dist/lib/utils/errorHandling.js +86 -0
  17. package/dist/lib/utils/imageProcessor.d.ts +42 -4
  18. package/dist/lib/utils/imageProcessor.js +96 -19
  19. package/dist/lib/utils/messageBuilder.js +49 -11
  20. package/dist/lib/utils/multimodalOptionsBuilder.d.ts +1 -5
  21. package/dist/lib/utils/textEncoding.d.ts +25 -0
  22. package/dist/lib/utils/textEncoding.js +141 -0
  23. package/dist/neurolink.js +5 -0
  24. package/dist/rag/document/loaders.js +20 -4
  25. package/dist/types/file.d.ts +43 -0
  26. package/dist/types/generate.d.ts +3 -11
  27. package/dist/types/rag.d.ts +7 -0
  28. package/dist/types/stream.d.ts +2 -6
  29. package/dist/utils/csvProcessor.d.ts +68 -10
  30. package/dist/utils/csvProcessor.js +498 -134
  31. package/dist/utils/errorHandling.d.ts +32 -0
  32. package/dist/utils/errorHandling.js +86 -0
  33. package/dist/utils/imageProcessor.d.ts +42 -4
  34. package/dist/utils/imageProcessor.js +96 -19
  35. package/dist/utils/messageBuilder.js +49 -11
  36. package/dist/utils/multimodalOptionsBuilder.d.ts +1 -5
  37. package/dist/utils/textEncoding.d.ts +25 -0
  38. package/dist/utils/textEncoding.js +140 -0
  39. package/package.json +3 -1
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Buffer → string decoding with encoding detection (#362).
3
+ *
4
+ * Order of resolution:
5
+ * 1. Explicit override (any iconv-lite label).
6
+ * 2. Deterministic BOM sniff (UTF-8 / UTF-16 LE / UTF-16 BE).
7
+ * 3. `chardet` statistical detection, mapped to an iconv-lite label.
8
+ * 4. Fallback to UTF-8 (preserves the historical hard-coded default).
9
+ *
10
+ * Decoding always goes through `iconv-lite`, and any residual BOM is stripped
11
+ * from the decoded string so it can't glue onto the first token.
12
+ */
13
+ import chardet from "chardet";
14
+ import iconv from "iconv-lite";
15
+ import { logger } from "./logger.js";
16
+ /** Strip a leading BOM (U+FEFF) from an already-decoded string. */
17
+ export function stripBomString(text) {
18
+ return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
19
+ }
20
+ /** Deterministic BOM detection from the raw bytes. Returns null when absent. */
21
+ function sniffBom(buffer) {
22
+ if (buffer.length >= 3 &&
23
+ buffer[0] === 0xef &&
24
+ buffer[1] === 0xbb &&
25
+ buffer[2] === 0xbf) {
26
+ return "utf-8";
27
+ }
28
+ if (buffer.length >= 2 && buffer[0] === 0xff && buffer[1] === 0xfe) {
29
+ return "utf-16le";
30
+ }
31
+ if (buffer.length >= 2 && buffer[0] === 0xfe && buffer[1] === 0xff) {
32
+ return "utf-16be";
33
+ }
34
+ return null;
35
+ }
36
+ /**
37
+ * Map a chardet label to an iconv-lite-supported label. Returns null when the
38
+ * label is unknown/unsupported so the caller falls back to UTF-8.
39
+ */
40
+ function toIconvLabel(detected) {
41
+ if (!detected) {
42
+ return null;
43
+ }
44
+ const normalized = detected.toLowerCase().replace(/[^a-z0-9]/g, "");
45
+ const map = {
46
+ utf8: "utf-8",
47
+ utf16le: "utf-16le",
48
+ utf16be: "utf-16be",
49
+ ascii: "utf-8", // ASCII is a strict UTF-8 subset
50
+ windows1252: "windows-1252",
51
+ iso88591: "latin1",
52
+ latin1: "latin1",
53
+ iso88592: "iso-8859-2",
54
+ windows1251: "windows-1251",
55
+ koi8r: "koi8-r",
56
+ gb18030: "gb18030",
57
+ big5: "big5",
58
+ shiftjis: "shift_jis",
59
+ euckr: "euc-kr",
60
+ eucjp: "euc-jp",
61
+ };
62
+ const label = map[normalized] ?? detected;
63
+ return iconv.encodingExists(label) ? label : null;
64
+ }
65
+ /**
66
+ * Decode a buffer to text, detecting the encoding unless overridden.
67
+ *
68
+ * @param isCompleteBuffer - Whether `buffer` is the entire source (default
69
+ * `true`). Pass `false` when `buffer` is only a peeked prefix (e.g. a
70
+ * streaming head-sniff) — the ASCII fast path still commits to "utf-8" for
71
+ * the peeked bytes (unchanged behavior), but reports a lower confidence
72
+ * since later bytes not yet seen could still be non-ASCII (#1199).
73
+ */
74
+ export function decodeBuffer(buffer, override, isCompleteBuffer = true) {
75
+ // 1. Explicit override wins outright.
76
+ if (override && iconv.encodingExists(override)) {
77
+ return {
78
+ text: stripBomString(iconv.decode(buffer, override)),
79
+ encoding: override,
80
+ confidence: 100,
81
+ };
82
+ }
83
+ if (override && !iconv.encodingExists(override)) {
84
+ logger.warn(`[textEncoding] Unsupported encoding override "${override}"; falling back to detection.`);
85
+ }
86
+ // 2. BOM is authoritative when present.
87
+ const bom = sniffBom(buffer);
88
+ if (bom) {
89
+ return {
90
+ text: stripBomString(iconv.decode(buffer, bom)),
91
+ encoding: bom,
92
+ confidence: 100,
93
+ };
94
+ }
95
+ // 2b. Pure-ASCII fast path — chardet often reports ASCII as ISO-8859-1, but
96
+ // ASCII is a strict UTF-8 subset and decodes identically, so report "utf-8"
97
+ // to preserve the historical default for plain-ASCII files.
98
+ let ascii = true;
99
+ for (let i = 0; i < buffer.length; i++) {
100
+ if (buffer[i] >= 0x80) {
101
+ ascii = false;
102
+ break;
103
+ }
104
+ }
105
+ if (ascii) {
106
+ return {
107
+ text: stripBomString(iconv.decode(buffer, "utf-8")),
108
+ encoding: "utf-8",
109
+ // A partial peek being pure-ASCII only proves the peeked prefix is
110
+ // ASCII, not the whole file — a later chunk could still switch to a
111
+ // legacy encoding. Only report full certainty when `buffer` is known
112
+ // to be the complete source.
113
+ confidence: isCompleteBuffer ? 100 : 60,
114
+ };
115
+ }
116
+ // 3. Statistical detection.
117
+ let detected = null;
118
+ try {
119
+ detected = chardet.detect(buffer);
120
+ }
121
+ catch (error) {
122
+ logger.debug(`[textEncoding] chardet failed: ${String(error)}`);
123
+ }
124
+ const label = toIconvLabel(detected);
125
+ if (label) {
126
+ return {
127
+ text: stripBomString(iconv.decode(buffer, label)),
128
+ encoding: label,
129
+ // chardet gives a winner but not a numeric score via detect(); treat a
130
+ // confident non-UTF-8 hit as reasonably (not fully) certain.
131
+ confidence: label === "utf-8" ? 100 : 80,
132
+ };
133
+ }
134
+ // 4. Fallback: historical UTF-8 default.
135
+ return {
136
+ text: stripBomString(iconv.decode(buffer, "utf-8")),
137
+ encoding: "utf-8",
138
+ confidence: 0,
139
+ };
140
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/neurolink",
3
- "version": "9.94.2",
3
+ "version": "9.94.4",
4
4
  "packageManager": "pnpm@10.15.1",
5
5
  "description": "TypeScript AI SDK with 24+ LLM providers behind one consistent API. MCP-native (connect any MCP server), voice TTS/STT/realtime, RAG, agents, memory, context compaction. OpenAI · Anthropic · Gemini · Bedrock · Azure · Ollama · DeepSeek · NVIDIA NIM and more.",
6
6
  "author": {
@@ -358,6 +358,7 @@
358
358
  "adm-zip": "^0.5.16",
359
359
  "ai": "^6.0.134",
360
360
  "chalk": "^5.6.2",
361
+ "chardet": "2.1.1",
361
362
  "croner": "^9.1.0",
362
363
  "csv-parser": "^3.2.0",
363
364
  "dotenv": "^17.3.1",
@@ -365,6 +366,7 @@
365
366
  "fast-xml-parser": "^5.7.0",
366
367
  "google-auth-library": "^10.6.1",
367
368
  "hono": "^4.12.21",
369
+ "iconv-lite": "0.7.2",
368
370
  "inquirer": "^13.3.0",
369
371
  "jose": "^6.1.3",
370
372
  "js-yaml": "^4.2.0",