@juspay/neurolink 7.48.1 → 7.50.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.
- package/CHANGELOG.md +19 -0
- package/README.md +215 -16
- package/dist/agent/directTools.d.ts +55 -0
- package/dist/agent/directTools.js +266 -0
- package/dist/cli/factories/commandFactory.d.ts +6 -0
- package/dist/cli/factories/commandFactory.js +149 -16
- package/dist/cli/index.js +13 -2
- package/dist/cli/loop/conversationSelector.d.ts +45 -0
- package/dist/cli/loop/conversationSelector.js +222 -0
- package/dist/cli/loop/optionsSchema.d.ts +1 -1
- package/dist/cli/loop/session.d.ts +36 -8
- package/dist/cli/loop/session.js +257 -61
- package/dist/core/baseProvider.d.ts +9 -0
- package/dist/core/baseProvider.js +45 -5
- package/dist/core/evaluation.js +5 -2
- package/dist/factories/providerRegistry.js +2 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +11 -10
- package/dist/lib/agent/directTools.d.ts +55 -0
- package/dist/lib/agent/directTools.js +266 -0
- package/dist/lib/core/baseProvider.d.ts +9 -0
- package/dist/lib/core/baseProvider.js +45 -5
- package/dist/lib/core/evaluation.js +5 -2
- package/dist/lib/factories/providerRegistry.js +2 -2
- package/dist/lib/index.d.ts +8 -2
- package/dist/lib/index.js +11 -10
- package/dist/lib/mcp/factory.d.ts +2 -157
- package/dist/lib/mcp/flexibleToolValidator.d.ts +1 -5
- package/dist/lib/mcp/index.d.ts +3 -2
- package/dist/lib/mcp/mcpCircuitBreaker.d.ts +1 -75
- package/dist/lib/mcp/mcpClientFactory.d.ts +1 -20
- package/dist/lib/mcp/mcpClientFactory.js +1 -0
- package/dist/lib/mcp/registry.d.ts +3 -10
- package/dist/lib/mcp/servers/agent/directToolsServer.d.ts +1 -1
- package/dist/lib/mcp/servers/aiProviders/aiCoreServer.d.ts +1 -1
- package/dist/lib/mcp/servers/utilities/utilityServer.d.ts +1 -1
- package/dist/lib/mcp/toolDiscoveryService.d.ts +3 -84
- package/dist/lib/mcp/toolRegistry.d.ts +2 -24
- package/dist/lib/middleware/builtin/guardrails.d.ts +5 -16
- package/dist/lib/middleware/builtin/guardrails.js +44 -39
- package/dist/lib/middleware/utils/guardrailsUtils.d.ts +64 -0
- package/dist/lib/middleware/utils/guardrailsUtils.js +387 -0
- package/dist/lib/neurolink.d.ts +36 -7
- package/dist/lib/neurolink.js +141 -0
- package/dist/lib/providers/anthropic.js +47 -3
- package/dist/lib/providers/azureOpenai.js +9 -2
- package/dist/lib/providers/googleAiStudio.js +9 -2
- package/dist/lib/providers/googleVertex.js +12 -2
- package/dist/lib/providers/huggingFace.js +1 -1
- package/dist/lib/providers/litellm.js +1 -1
- package/dist/lib/providers/mistral.js +1 -1
- package/dist/lib/providers/openAI.js +47 -3
- package/dist/lib/services/server/ai/observability/instrumentation.d.ts +57 -0
- package/dist/lib/services/server/ai/observability/instrumentation.js +170 -0
- package/dist/lib/session/globalSessionState.d.ts +26 -0
- package/dist/lib/session/globalSessionState.js +86 -1
- package/dist/lib/telemetry/index.d.ts +1 -0
- package/dist/lib/telemetry/telemetryService.d.ts +2 -0
- package/dist/lib/telemetry/telemetryService.js +7 -7
- package/dist/lib/types/cli.d.ts +28 -0
- package/dist/lib/types/content.d.ts +18 -5
- package/dist/lib/types/contextTypes.d.ts +1 -1
- package/dist/lib/types/conversation.d.ts +57 -4
- package/dist/lib/types/fileTypes.d.ts +65 -0
- package/dist/lib/types/fileTypes.js +4 -0
- package/dist/lib/types/generateTypes.d.ts +12 -0
- package/dist/lib/types/guardrails.d.ts +103 -0
- package/dist/lib/types/guardrails.js +1 -0
- package/dist/lib/types/index.d.ts +4 -2
- package/dist/lib/types/index.js +4 -0
- package/dist/lib/types/mcpTypes.d.ts +407 -14
- package/dist/lib/types/modelTypes.d.ts +6 -6
- package/dist/lib/types/observability.d.ts +49 -0
- package/dist/lib/types/observability.js +6 -0
- package/dist/lib/types/streamTypes.d.ts +7 -0
- package/dist/lib/types/tools.d.ts +132 -35
- package/dist/lib/utils/csvProcessor.d.ts +68 -0
- package/dist/lib/utils/csvProcessor.js +277 -0
- package/dist/lib/utils/fileDetector.d.ts +57 -0
- package/dist/lib/utils/fileDetector.js +457 -0
- package/dist/lib/utils/imageProcessor.d.ts +10 -0
- package/dist/lib/utils/imageProcessor.js +22 -0
- package/dist/lib/utils/loopUtils.d.ts +71 -0
- package/dist/lib/utils/loopUtils.js +262 -0
- package/dist/lib/utils/messageBuilder.d.ts +2 -1
- package/dist/lib/utils/messageBuilder.js +197 -2
- package/dist/lib/utils/optionsUtils.d.ts +1 -1
- package/dist/mcp/factory.d.ts +2 -157
- package/dist/mcp/flexibleToolValidator.d.ts +1 -5
- package/dist/mcp/index.d.ts +3 -2
- package/dist/mcp/mcpCircuitBreaker.d.ts +1 -75
- package/dist/mcp/mcpClientFactory.d.ts +1 -20
- package/dist/mcp/mcpClientFactory.js +1 -0
- package/dist/mcp/registry.d.ts +3 -10
- package/dist/mcp/servers/agent/directToolsServer.d.ts +1 -1
- package/dist/mcp/servers/aiProviders/aiCoreServer.d.ts +1 -1
- package/dist/mcp/servers/utilities/utilityServer.d.ts +1 -1
- package/dist/mcp/toolDiscoveryService.d.ts +3 -84
- package/dist/mcp/toolRegistry.d.ts +2 -24
- package/dist/middleware/builtin/guardrails.d.ts +5 -16
- package/dist/middleware/builtin/guardrails.js +44 -39
- package/dist/middleware/utils/guardrailsUtils.d.ts +64 -0
- package/dist/middleware/utils/guardrailsUtils.js +387 -0
- package/dist/neurolink.d.ts +36 -7
- package/dist/neurolink.js +141 -0
- package/dist/providers/anthropic.js +47 -3
- package/dist/providers/azureOpenai.js +9 -2
- package/dist/providers/googleAiStudio.js +9 -2
- package/dist/providers/googleVertex.js +12 -2
- package/dist/providers/huggingFace.js +1 -1
- package/dist/providers/litellm.js +1 -1
- package/dist/providers/mistral.js +1 -1
- package/dist/providers/openAI.js +47 -3
- package/dist/services/server/ai/observability/instrumentation.d.ts +57 -0
- package/dist/services/server/ai/observability/instrumentation.js +170 -0
- package/dist/session/globalSessionState.d.ts +26 -0
- package/dist/session/globalSessionState.js +86 -1
- package/dist/telemetry/index.d.ts +1 -0
- package/dist/telemetry/telemetryService.d.ts +2 -0
- package/dist/telemetry/telemetryService.js +7 -7
- package/dist/types/cli.d.ts +28 -0
- package/dist/types/content.d.ts +18 -5
- package/dist/types/contextTypes.d.ts +1 -1
- package/dist/types/conversation.d.ts +57 -4
- package/dist/types/fileTypes.d.ts +65 -0
- package/dist/types/fileTypes.js +4 -0
- package/dist/types/generateTypes.d.ts +12 -0
- package/dist/types/guardrails.d.ts +103 -0
- package/dist/types/guardrails.js +1 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/index.js +4 -0
- package/dist/types/mcpTypes.d.ts +407 -14
- package/dist/types/modelTypes.d.ts +6 -6
- package/dist/types/observability.d.ts +49 -0
- package/dist/types/observability.js +6 -0
- package/dist/types/streamTypes.d.ts +7 -0
- package/dist/types/tools.d.ts +132 -35
- package/dist/utils/csvProcessor.d.ts +68 -0
- package/dist/utils/csvProcessor.js +277 -0
- package/dist/utils/fileDetector.d.ts +57 -0
- package/dist/utils/fileDetector.js +457 -0
- package/dist/utils/imageProcessor.d.ts +10 -0
- package/dist/utils/imageProcessor.js +22 -0
- package/dist/utils/loopUtils.d.ts +71 -0
- package/dist/utils/loopUtils.js +262 -0
- package/dist/utils/messageBuilder.d.ts +2 -1
- package/dist/utils/messageBuilder.js +197 -2
- package/dist/utils/optionsUtils.d.ts +1 -1
- package/package.json +18 -16
- package/dist/lib/mcp/contracts/mcpContract.d.ts +0 -106
- package/dist/lib/mcp/contracts/mcpContract.js +0 -5
- package/dist/mcp/contracts/mcpContract.d.ts +0 -106
- package/dist/mcp/contracts/mcpContract.js +0 -5
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSV Processing Utility
|
|
3
|
+
* Converts CSV files to LLM-friendly text formats
|
|
4
|
+
* Uses streaming for memory efficiency with large files
|
|
5
|
+
*/
|
|
6
|
+
import csvParser from "csv-parser";
|
|
7
|
+
import { Readable } from "stream";
|
|
8
|
+
import { logger } from "./logger.js";
|
|
9
|
+
/**
|
|
10
|
+
* Detect if first line is CSV metadata (not actual data/headers)
|
|
11
|
+
* Common patterns:
|
|
12
|
+
* - Excel separator line: "SEP=,"
|
|
13
|
+
* - Lines with significantly different delimiter count than line 2
|
|
14
|
+
* - Lines that don't match CSV structure of subsequent lines
|
|
15
|
+
*/
|
|
16
|
+
function isMetadataLine(lines) {
|
|
17
|
+
if (!lines[0] || lines.length < 2) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const firstLine = lines[0].trim();
|
|
21
|
+
const secondLine = lines[1].trim();
|
|
22
|
+
if (firstLine.match(/^sep=/i)) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
const firstCommaCount = (firstLine.match(/,/g) || []).length;
|
|
26
|
+
const secondCommaCount = (secondLine.match(/,/g) || []).length;
|
|
27
|
+
if (firstCommaCount === 0 && secondCommaCount > 0) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if (secondCommaCount > 0 && firstCommaCount !== secondCommaCount) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* CSV processor for converting CSV data to LLM-optimized formats
|
|
37
|
+
*
|
|
38
|
+
* Supports three output formats:
|
|
39
|
+
* - raw: Original CSV format with proper escaping (RECOMMENDED for best LLM performance)
|
|
40
|
+
* - json: JSON array format (best for structured data processing)
|
|
41
|
+
* - markdown: Markdown table format (best for small datasets <100 rows)
|
|
42
|
+
*
|
|
43
|
+
* All formats use csv-parser for reliable parsing, then convert to the target format.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const csvBuffer = Buffer.from('name,age\nAlice,30\nBob,25');
|
|
48
|
+
* const result = await CSVProcessor.process(csvBuffer, {
|
|
49
|
+
* maxRows: 1000,
|
|
50
|
+
* formatStyle: 'raw'
|
|
51
|
+
* });
|
|
52
|
+
* console.log(result.content); // CSV string with proper escaping
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export class CSVProcessor {
|
|
56
|
+
/**
|
|
57
|
+
* Process CSV Buffer to LLM-friendly format
|
|
58
|
+
* Content already loaded by FileDetector
|
|
59
|
+
*
|
|
60
|
+
* @param content - CSV file as Buffer
|
|
61
|
+
* @param options - Processing options
|
|
62
|
+
* @returns Formatted CSV data ready for LLM (JSON or Markdown)
|
|
63
|
+
*/
|
|
64
|
+
static async process(content, options) {
|
|
65
|
+
const { maxRows: rawMaxRows = 1000, formatStyle = "raw", includeHeaders = true, } = options || {};
|
|
66
|
+
const maxRows = Math.max(1, Math.min(10000, rawMaxRows));
|
|
67
|
+
const csvString = content.toString("utf-8");
|
|
68
|
+
// For raw format, return original CSV with row limit (no parsing needed)
|
|
69
|
+
// This preserves the exact original format which works best for LLMs
|
|
70
|
+
if (formatStyle === "raw") {
|
|
71
|
+
const lines = csvString.split("\n");
|
|
72
|
+
const hasMetadataLine = isMetadataLine(lines);
|
|
73
|
+
// Skip metadata line if present, then take header + maxRows data rows
|
|
74
|
+
const csvLines = hasMetadataLine
|
|
75
|
+
? lines.slice(1) // Skip metadata line
|
|
76
|
+
: lines;
|
|
77
|
+
const limitedLines = csvLines.slice(0, 1 + maxRows); // header + data rows
|
|
78
|
+
const limitedCSV = limitedLines.join("\n");
|
|
79
|
+
const rowCount = limitedLines.length - 1; // Subtract header
|
|
80
|
+
const originalRowCount = csvLines.length - 1; // Subtract header from original
|
|
81
|
+
logger.debug(`[CSVProcessor] raw format: ${rowCount} rows (original: ${originalRowCount}) → ${limitedCSV.length} chars`, {
|
|
82
|
+
formatStyle: "raw",
|
|
83
|
+
originalSize: csvString.length,
|
|
84
|
+
limitedSize: limitedCSV.length,
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
type: "csv",
|
|
88
|
+
content: limitedCSV,
|
|
89
|
+
mimeType: "text/csv",
|
|
90
|
+
metadata: {
|
|
91
|
+
confidence: 100,
|
|
92
|
+
size: content.length,
|
|
93
|
+
rowCount,
|
|
94
|
+
columnCount: (limitedLines[0] || "").split(",").length,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// Parse CSV for JSON and Markdown formats only
|
|
99
|
+
const rows = await this.parseCSVString(csvString, maxRows);
|
|
100
|
+
// Extract metadata from parsed results
|
|
101
|
+
const rowCount = rows.length;
|
|
102
|
+
const columnNames = rows.length > 0 ? Object.keys(rows[0]) : [];
|
|
103
|
+
const columnCount = columnNames.length;
|
|
104
|
+
const hasEmptyColumns = columnNames.some((col) => !col || col.trim() === "");
|
|
105
|
+
const sampleRows = rows.slice(0, 3);
|
|
106
|
+
const sampleData = sampleRows.length > 0
|
|
107
|
+
? JSON.stringify(sampleRows, null, 2)
|
|
108
|
+
: "No data rows";
|
|
109
|
+
// Format parsed data
|
|
110
|
+
const formatted = this.formatForLLM(rows, formatStyle, includeHeaders);
|
|
111
|
+
logger.info(`[CSVProcessor] ${formatStyle} format: ${rowCount} rows × ${columnCount} columns → ${formatted.length} chars`, { rowCount, columnCount, columns: columnNames, hasEmptyColumns });
|
|
112
|
+
return {
|
|
113
|
+
type: "csv",
|
|
114
|
+
content: formatted,
|
|
115
|
+
mimeType: "text/csv",
|
|
116
|
+
metadata: {
|
|
117
|
+
confidence: 100,
|
|
118
|
+
size: content.length,
|
|
119
|
+
rowCount,
|
|
120
|
+
columnCount,
|
|
121
|
+
columnNames,
|
|
122
|
+
sampleData,
|
|
123
|
+
hasEmptyColumns,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Parse CSV string into array of row objects using streaming
|
|
129
|
+
* Memory-efficient for large files
|
|
130
|
+
*/
|
|
131
|
+
/**
|
|
132
|
+
* Parse CSV file from disk using streaming (memory efficient)
|
|
133
|
+
*
|
|
134
|
+
* @param filePath - Path to CSV file
|
|
135
|
+
* @param maxRows - Maximum rows to parse (default: 1000)
|
|
136
|
+
* @returns Array of row objects
|
|
137
|
+
*/
|
|
138
|
+
static async parseCSVFile(filePath, maxRows = 1000) {
|
|
139
|
+
const clampedMaxRows = Math.max(1, Math.min(10000, maxRows));
|
|
140
|
+
const fs = await import("fs");
|
|
141
|
+
// Read first 2 lines to detect metadata
|
|
142
|
+
const fileHandle = await fs.promises.open(filePath, "r");
|
|
143
|
+
const firstLines = [];
|
|
144
|
+
const lineReader = fileHandle.createReadStream({ encoding: "utf-8" });
|
|
145
|
+
await new Promise((resolve) => {
|
|
146
|
+
let buffer = "";
|
|
147
|
+
lineReader.on("data", (chunk) => {
|
|
148
|
+
buffer += chunk.toString();
|
|
149
|
+
const lines = buffer.split("\n");
|
|
150
|
+
if (lines.length >= 2) {
|
|
151
|
+
firstLines.push(lines[0], lines[1]);
|
|
152
|
+
lineReader.destroy();
|
|
153
|
+
resolve();
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
lineReader.on("end", () => resolve());
|
|
157
|
+
});
|
|
158
|
+
await fileHandle.close();
|
|
159
|
+
const hasMetadataLine = isMetadataLine(firstLines);
|
|
160
|
+
const skipLines = hasMetadataLine ? 1 : 0;
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
const rows = [];
|
|
163
|
+
let count = 0;
|
|
164
|
+
let lineCount = 0;
|
|
165
|
+
const source = fs.createReadStream(filePath, { encoding: "utf-8" });
|
|
166
|
+
const parser = csvParser();
|
|
167
|
+
const abort = () => {
|
|
168
|
+
source.destroy();
|
|
169
|
+
parser.destroy();
|
|
170
|
+
};
|
|
171
|
+
source
|
|
172
|
+
.pipe(parser)
|
|
173
|
+
.on("data", (row) => {
|
|
174
|
+
lineCount++;
|
|
175
|
+
if (lineCount <= skipLines) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
rows.push(row);
|
|
179
|
+
count++;
|
|
180
|
+
if (count >= clampedMaxRows) {
|
|
181
|
+
logger.debug(`[CSVProcessor] Reached row limit ${clampedMaxRows}, stopping parse`);
|
|
182
|
+
abort();
|
|
183
|
+
resolve(rows);
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
.on("end", () => {
|
|
187
|
+
resolve(rows);
|
|
188
|
+
})
|
|
189
|
+
.on("error", (error) => {
|
|
190
|
+
logger.error("[CSVProcessor] File parsing failed:", error);
|
|
191
|
+
reject(error);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Parse CSV string to array of row objects
|
|
197
|
+
* Exposed for use by tools that need direct CSV parsing
|
|
198
|
+
*
|
|
199
|
+
* @param csvString - CSV data as string
|
|
200
|
+
* @param maxRows - Maximum rows to parse (default: 1000)
|
|
201
|
+
* @returns Array of row objects
|
|
202
|
+
*/
|
|
203
|
+
static async parseCSVString(csvString, maxRows = 1000) {
|
|
204
|
+
const clampedMaxRows = Math.max(1, Math.min(10000, maxRows));
|
|
205
|
+
// Detect and skip metadata line
|
|
206
|
+
const lines = csvString.split("\n");
|
|
207
|
+
const hasMetadataLine = isMetadataLine(lines);
|
|
208
|
+
const csvData = hasMetadataLine ? lines.slice(1).join("\n") : csvString;
|
|
209
|
+
return new Promise((resolve, reject) => {
|
|
210
|
+
const rows = [];
|
|
211
|
+
let count = 0;
|
|
212
|
+
const source = Readable.from([csvData]);
|
|
213
|
+
const parser = csvParser();
|
|
214
|
+
const abort = () => {
|
|
215
|
+
source.destroy();
|
|
216
|
+
parser.destroy();
|
|
217
|
+
};
|
|
218
|
+
source
|
|
219
|
+
.pipe(parser)
|
|
220
|
+
.on("data", (row) => {
|
|
221
|
+
rows.push(row);
|
|
222
|
+
count++;
|
|
223
|
+
if (count >= clampedMaxRows) {
|
|
224
|
+
logger.debug(`[CSVProcessor] Reached row limit ${clampedMaxRows}, stopping parse`);
|
|
225
|
+
abort();
|
|
226
|
+
resolve(rows);
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
.on("end", () => {
|
|
230
|
+
resolve(rows);
|
|
231
|
+
})
|
|
232
|
+
.on("error", (error) => {
|
|
233
|
+
logger.error("[CSVProcessor] Parsing failed:", error);
|
|
234
|
+
reject(error);
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Format parsed CSV data for LLM consumption
|
|
240
|
+
* Only used for JSON and Markdown formats (raw format handled separately)
|
|
241
|
+
*/
|
|
242
|
+
static formatForLLM(rows, formatStyle, includeHeaders) {
|
|
243
|
+
if (rows.length === 0) {
|
|
244
|
+
return "CSV file is empty or contains no data.";
|
|
245
|
+
}
|
|
246
|
+
if (formatStyle === "json") {
|
|
247
|
+
return JSON.stringify(rows, null, 2);
|
|
248
|
+
}
|
|
249
|
+
return this.toMarkdownTable(rows, includeHeaders);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Format as markdown table
|
|
253
|
+
* Best for small datasets (<100 rows)
|
|
254
|
+
*/
|
|
255
|
+
static toMarkdownTable(rows, includeHeaders) {
|
|
256
|
+
if (rows.length === 0) {
|
|
257
|
+
return "CSV file is empty or contains no data.";
|
|
258
|
+
}
|
|
259
|
+
const headers = Object.keys(rows[0]);
|
|
260
|
+
// Escape backslashes, pipes, and sanitize newlines to keep rows intact
|
|
261
|
+
const escapePipe = (str) => str.replace(/\\/g, "\\\\").replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
|
|
262
|
+
let markdown = "";
|
|
263
|
+
if (includeHeaders) {
|
|
264
|
+
markdown = "| " + headers.map(escapePipe).join(" | ") + " |\n";
|
|
265
|
+
markdown += "|" + headers.map(() => " --- ").join("|") + "|\n";
|
|
266
|
+
}
|
|
267
|
+
rows.forEach((row) => {
|
|
268
|
+
markdown +=
|
|
269
|
+
"| " +
|
|
270
|
+
headers
|
|
271
|
+
.map((h) => escapePipe(String(row[h] || "")))
|
|
272
|
+
.join(" | ") +
|
|
273
|
+
" |\n";
|
|
274
|
+
});
|
|
275
|
+
return markdown;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Type Detection Utility
|
|
3
|
+
* Centralized file detection for all multimodal file types
|
|
4
|
+
* Uses multi-strategy approach for reliable type identification
|
|
5
|
+
*/
|
|
6
|
+
import type { FileInput, FileProcessingResult, FileDetectorOptions } from "../types/fileTypes.js";
|
|
7
|
+
/**
|
|
8
|
+
* Centralized file type detection and processing
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Auto-detect and process any file
|
|
13
|
+
* const result = await FileDetector.detectAndProcess("data.csv");
|
|
14
|
+
* console.log(result.type); // 'csv'
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class FileDetector {
|
|
18
|
+
/**
|
|
19
|
+
* Auto-detect file type and process in one call
|
|
20
|
+
*
|
|
21
|
+
* Runs detection strategies in priority order:
|
|
22
|
+
* 1. MagicBytesStrategy (95% confidence) - Binary file headers
|
|
23
|
+
* 2. MimeTypeStrategy (85% confidence) - HTTP Content-Type for URLs
|
|
24
|
+
* 3. ExtensionStrategy (70% confidence) - File extension
|
|
25
|
+
* 4. ContentHeuristicStrategy (75% confidence) - Content analysis
|
|
26
|
+
*
|
|
27
|
+
* @param input - File path, URL, Buffer, or data URI
|
|
28
|
+
* @param options - Detection and processing options
|
|
29
|
+
* @returns Processed file result with type and content
|
|
30
|
+
*/
|
|
31
|
+
static detectAndProcess(input: FileInput, options?: FileDetectorOptions): Promise<FileProcessingResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Detect file type using multi-strategy approach
|
|
34
|
+
* Stops at first strategy with confidence >= threshold (default: 80%)
|
|
35
|
+
*/
|
|
36
|
+
private static detect;
|
|
37
|
+
/**
|
|
38
|
+
* Load file content from various sources
|
|
39
|
+
*/
|
|
40
|
+
private static loadContent;
|
|
41
|
+
/**
|
|
42
|
+
* Route to appropriate processor
|
|
43
|
+
*/
|
|
44
|
+
private static processFile;
|
|
45
|
+
/**
|
|
46
|
+
* Load file from URL
|
|
47
|
+
*/
|
|
48
|
+
private static loadFromURL;
|
|
49
|
+
/**
|
|
50
|
+
* Load file from filesystem path
|
|
51
|
+
*/
|
|
52
|
+
private static loadFromPath;
|
|
53
|
+
/**
|
|
54
|
+
* Load file from data URI
|
|
55
|
+
*/
|
|
56
|
+
private static loadFromDataURI;
|
|
57
|
+
}
|