@juspay/neurolink 9.94.1 → 9.94.3

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 +404 -403
  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.d.ts +12 -1
  9. package/dist/lib/rag/document/loaders.js +64 -34
  10. package/dist/lib/types/file.d.ts +43 -0
  11. package/dist/lib/types/generate.d.ts +3 -11
  12. package/dist/lib/types/rag.d.ts +7 -0
  13. package/dist/lib/types/stream.d.ts +2 -6
  14. package/dist/lib/utils/csvProcessor.d.ts +121 -5
  15. package/dist/lib/utils/csvProcessor.js +563 -114
  16. package/dist/lib/utils/csvUtils.d.ts +26 -0
  17. package/dist/lib/utils/csvUtils.js +85 -0
  18. package/dist/lib/utils/errorHandling.d.ts +23 -0
  19. package/dist/lib/utils/errorHandling.js +65 -0
  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.d.ts +12 -1
  25. package/dist/rag/document/loaders.js +64 -34
  26. package/dist/types/file.d.ts +43 -0
  27. package/dist/types/generate.d.ts +3 -11
  28. package/dist/types/rag.d.ts +7 -0
  29. package/dist/types/stream.d.ts +2 -6
  30. package/dist/utils/csvProcessor.d.ts +121 -5
  31. package/dist/utils/csvProcessor.js +562 -113
  32. package/dist/utils/csvUtils.d.ts +26 -0
  33. package/dist/utils/csvUtils.js +84 -0
  34. package/dist/utils/errorHandling.d.ts +23 -0
  35. package/dist/utils/errorHandling.js +65 -0
  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
@@ -15,7 +15,7 @@ import type { AvatarOptions, AvatarResult } from "./avatar.js";
15
15
  import type { MusicOptions, MusicResult } from "./music.js";
16
16
  import type { StandardRecord, ValidationSchema, ZodUnknownSchema } from "./aliases.js";
17
17
  import type { NeurolinkCredentials } from "./providers.js";
18
- import type { FileWithMetadata } from "./file.js";
18
+ import type { CSVProcessorOptions, FileWithMetadata } from "./file.js";
19
19
  import type { WorkflowConfig } from "./workflow.js";
20
20
  import type { Schema, Tool, ToolChoice } from "./tools.js";
21
21
  import type { StepResult, LanguageModel } from "./providers.js";
@@ -123,11 +123,7 @@ export type GenerateOptions = {
123
123
  */
124
124
  music?: MusicOptions;
125
125
  };
126
- csvOptions?: {
127
- maxRows?: number;
128
- formatStyle?: "raw" | "markdown" | "json";
129
- includeHeaders?: boolean;
130
- };
126
+ csvOptions?: CSVProcessorOptions;
131
127
  videoOptions?: {
132
128
  frames?: number;
133
129
  quality?: number;
@@ -1133,11 +1129,7 @@ export type TextGenerationOptions = {
1133
1129
  onError?: OnErrorCallback;
1134
1130
  expectedOutcome?: string;
1135
1131
  evaluationCriteria?: string[];
1136
- csvOptions?: {
1137
- maxRows?: number;
1138
- formatStyle?: "raw" | "markdown" | "json";
1139
- includeHeaders?: boolean;
1140
- };
1132
+ csvOptions?: CSVProcessorOptions;
1141
1133
  enableSummarization?: boolean;
1142
1134
  /**
1143
1135
  * Skip injecting tool schemas into the system prompt.
@@ -500,6 +500,13 @@ export type CSVLoaderOptions = LoaderOptions & {
500
500
  columns?: string[];
501
501
  /** Output format */
502
502
  outputFormat?: "text" | "json" | "markdown";
503
+ /**
504
+ * Rewrite headers into valid identifiers (#378). Opt-in; default false keeps
505
+ * the raw header strings as JSON keys / table columns.
506
+ */
507
+ sanitizeColumnNames?: boolean;
508
+ /** Case style used when `sanitizeColumnNames` is on (#378). Default "snake_case". */
509
+ columnNameCase?: "camelCase" | "snake_case";
503
510
  };
504
511
  /**
505
512
  * Abstract document loader type
@@ -14,7 +14,7 @@ import type { AIModelProviderConfig, NeurolinkCredentials } from "./providers.js
14
14
  import type { TTSChunk, TTSOptions, TTSResult } from "./tts.js";
15
15
  import type { STTOptions, STTResult } from "./stt.js";
16
16
  import type { StandardRecord, ValidationSchema } from "./aliases.js";
17
- import type { FileWithMetadata } from "./file.js";
17
+ import type { CSVProcessorOptions, FileWithMetadata } from "./file.js";
18
18
  import type { WorkflowConfig } from "./workflow.js";
19
19
  import type { LanguageModel, StepResult } from "./providers.js";
20
20
  import type { Tool, ToolChoice } from "./tools.js";
@@ -205,11 +205,7 @@ export type StreamOptions = {
205
205
  enableProgress?: boolean;
206
206
  };
207
207
  };
208
- csvOptions?: {
209
- maxRows?: number;
210
- formatStyle?: "raw" | "markdown" | "json";
211
- includeHeaders?: boolean;
212
- };
208
+ csvOptions?: CSVProcessorOptions;
213
209
  videoOptions?: {
214
210
  frames?: number;
215
211
  quality?: number;
@@ -3,7 +3,77 @@
3
3
  * Converts CSV files to LLM-friendly text formats
4
4
  * Uses streaming for memory efficiency with large files
5
5
  */
6
- import type { FileProcessingResult, CSVProcessorOptions } from "../types/index.js";
6
+ import type { FileProcessingResult, CSVProcessorOptions, CSVRow } from "../types/index.js";
7
+ /**
8
+ * Rewrite a raw header into a valid identifier. Trims, replaces non-identifier
9
+ * runs with `_`, prefixes a `col_` when it starts with a digit or is empty,
10
+ * then applies the requested case style. Never returns an empty string.
11
+ */
12
+ export declare function sanitizeColumnName(name: string, style?: "camelCase" | "snake_case", index?: number): string;
13
+ /**
14
+ * Deduplicate a list of (already sanitized) names by suffixing `_2`, `_3`, … on
15
+ * collisions, preserving order. The suffixed candidate is bumped until it does
16
+ * not collide with ANY already-emitted name — so an existing `name_2` can't be
17
+ * silently overwritten by a generated `name_2` (which the naive counter did for
18
+ * `["name","name","name_2"]`).
19
+ */
20
+ export declare function dedupeColumnNames(names: string[]): string[];
21
+ /**
22
+ * Predicate form of the row-shape invariant: a non-null, non-array object whose
23
+ * every value is a string or undefined. csv-parser's default output always
24
+ * satisfies this; the guard is defense-in-depth at the parse boundary.
25
+ */
26
+ export declare function isValidCsvRow(row: unknown): row is CSVRow;
27
+ /**
28
+ * Assertion form used inside the streaming `data` handlers. Throws a
29
+ * `[CSVProcessor]`-prefixed error (so existing `includes("CSV")` catches still
30
+ * match) when a row violates the invariant.
31
+ */
32
+ export declare function assertValidCsvRow(row: unknown, rowNumber: number): asserts row is CSVRow;
33
+ /**
34
+ * Detect if first line is CSV metadata (not actual data/headers)
35
+ * Common patterns:
36
+ * - Excel separator line: "SEP=,"
37
+ * - Lines with significantly different delimiter count than line 2
38
+ * - Lines that don't match CSV structure of subsequent lines
39
+ */
40
+ /**
41
+ * Strip a leading UTF-8 BOM (U+FEFF) if present. Exported so every entry
42
+ * point that sniffs raw text (including the RAG CSVLoader) normalizes BOMs
43
+ * the same way before metadata/delimiter detection.
44
+ */
45
+ export declare function stripBom(text: string): string;
46
+ /**
47
+ * Strip a leading metadata line (e.g. Excel's `sep=;` preamble) from
48
+ * already-split lines, and read the delimiter it explicitly declares.
49
+ * Excel semantics: an explicit `sep=<char>` always wins over frequency-based
50
+ * detection; a metadata line without a recognized delimiter character is
51
+ * simply dropped from the sample without forcing a delimiter. This is the
52
+ * single place process(), detectDelimiter(), parseCSVFile(), and
53
+ * parseCSVString() all go through, so none of them detect a delimiter over
54
+ * the raw, un-stripped lines (which lets the preamble skew detection).
55
+ * Exported so non-CSVProcessor callers (the RAG CSVLoader) share it too.
56
+ */
57
+ export declare function stripMetadataLine(lines: string[]): {
58
+ dataLines: string[];
59
+ hasMetadataLine: boolean;
60
+ explicitDelimiter?: string;
61
+ };
62
+ /**
63
+ * Split CSV text into logical rows for metadata detection and raw row limiting.
64
+ *
65
+ * Supports Unix (LF), Windows (CRLF), and classic Mac (CR) line endings, and is
66
+ * quote-aware: a line ending that appears *inside* a quoted field (RFC 4180) is
67
+ * kept as part of that field rather than treated as a row boundary. A doubled
68
+ * `""` inside quotes is the RFC-4180 escaped quote and does not toggle the quote
69
+ * state. For unquoted input this yields exactly the same result as a plain
70
+ * `split(/\r\n|\n|\r/)`.
71
+ *
72
+ * Exported so non-CSVProcessor callers (the RAG CSVLoader) get the same
73
+ * quote-aware row boundaries instead of a physical `content.split("\n")`,
74
+ * which would break rows on a newline embedded in a quoted field.
75
+ */
76
+ export declare function splitCsvLines(csvString: string): string[];
7
77
  /**
8
78
  * CSV processor for converting CSV data to LLM-optimized formats
9
79
  *
@@ -35,9 +105,14 @@ export declare class CSVProcessor {
35
105
  */
36
106
  static process(content: Buffer, options?: CSVProcessorOptions): Promise<FileProcessingResult>;
37
107
  /**
38
- * Parse CSV string into array of row objects using streaming
39
- * Memory-efficient for large files
108
+ * Detect the delimiter of DSV content (comma/tab/semicolon/pipe), respecting
109
+ * RFC-4180 quoting. An optional extension hint (`tsv` → tab, `psv` → pipe)
110
+ * breaks ambiguity. Used by callers (e.g. the RAG CSV loader) that parse
111
+ * DSV content themselves and need the same detection (#361). A leading
112
+ * Excel `sep=` metadata line is stripped before sampling so it can't skew
113
+ * detection, and an explicit `sep=<char>` value wins outright.
40
114
  */
115
+ static detectDelimiter(csvString: string, extensionHint?: string): string;
41
116
  /**
42
117
  * Parse CSV file from disk using streaming (memory efficient)
43
118
  *
@@ -45,16 +120,57 @@ export declare class CSVProcessor {
45
120
  * @param maxRows - Maximum rows to parse (default: 1000)
46
121
  * @returns Array of row objects
47
122
  */
48
- static parseCSVFile(filePath: string, maxRows?: number): Promise<unknown[]>;
123
+ static parseCSVFile(filePath: string, maxRows?: number, timeoutMs?: number): Promise<CSVRow[]>;
124
+ /**
125
+ * File-parse variant that also reports whether the parse timed out, used by
126
+ * `process()` to surface `metadata.parseTimedOut`.
127
+ */
128
+ static parseCSVFileWithMeta(filePath: string, maxRows?: number, timeoutMs?: number, encoding?: string): Promise<{
129
+ rows: CSVRow[];
130
+ timedOut: boolean;
131
+ }>;
132
+ /**
133
+ * Peek the head of a raw file stream to resolve encoding, metadata-line
134
+ * skipping, and the delimiter (#361), then return a decoded text stream
135
+ * that still delivers the whole file from byte 0 (via `unshift`) — a
136
+ * single disk read (#368/#362).
137
+ */
138
+ private static prepareFileSource;
49
139
  /**
50
140
  * Parse CSV string to array of row objects
51
141
  * Exposed for use by tools that need direct CSV parsing
52
142
  *
53
143
  * @param csvString - CSV data as string
54
144
  * @param maxRows - Maximum rows to parse (default: 1000)
145
+ * @param timeoutMs - Wall-clock parse cap; returns partial rows on timeout
55
146
  * @returns Array of row objects
56
147
  */
57
- static parseCSVString(csvString: string, maxRows?: number): Promise<unknown[]>;
148
+ static parseCSVString(csvString: string, maxRows?: number, timeoutMs?: number): Promise<CSVRow[]>;
149
+ /**
150
+ * String-parse variant that also reports whether the parse timed out, used by
151
+ * `process()` to surface `metadata.parseTimedOut`.
152
+ */
153
+ static parseCSVStringWithMeta(csvString: string, maxRows?: number, timeoutMs?: number): Promise<{
154
+ rows: CSVRow[];
155
+ timedOut: boolean;
156
+ }>;
157
+ /**
158
+ * Shared streaming consumer for both parse methods. Guarantees:
159
+ * - source, rawSource, and parser are all destroyed on ANY settle path
160
+ * (#371) — `rawSource` matters for the file-parse path, where `source`
161
+ * is a decode Transform piped FROM `rawSource`; `.pipe()` does not
162
+ * propagate `.destroy()` upstream, so without this the underlying
163
+ * `fs.createReadStream` fd would leak on abort/timeout/error,
164
+ * - a wall-clock timeout returns partial rows instead of hanging (#379),
165
+ * - every row is validated at the boundary (#384),
166
+ * - reject messages carry columns/last-row-shape/format context (#375),
167
+ * - the delimiter (#361, comma/tab/semicolon/pipe) detected by the caller
168
+ * is honored, instead of csv-parser's hard-coded comma default.
169
+ *
170
+ * @param rawSource - The original file stream `source` was piped from, when
171
+ * applicable (file-parse path only; `undefined` for string parsing).
172
+ */
173
+ private static streamParse;
58
174
  /**
59
175
  * Format parsed CSV data for LLM consumption
60
176
  * Only used for JSON and Markdown formats (raw format handled separately)