@juspay/neurolink 9.1.1 → 9.2.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 (237) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +54 -7
  3. package/dist/agent/directTools.d.ts +3 -3
  4. package/dist/cli/commands/config.d.ts +6 -6
  5. package/dist/image-gen/ImageGenService.d.ts +143 -0
  6. package/dist/image-gen/ImageGenService.js +345 -0
  7. package/dist/image-gen/imageGenTools.d.ts +126 -0
  8. package/dist/image-gen/imageGenTools.js +304 -0
  9. package/dist/image-gen/index.d.ts +46 -0
  10. package/dist/image-gen/index.js +48 -0
  11. package/dist/image-gen/types.d.ts +237 -0
  12. package/dist/image-gen/types.js +24 -0
  13. package/dist/lib/agent/directTools.d.ts +3 -3
  14. package/dist/lib/image-gen/ImageGenService.d.ts +143 -0
  15. package/dist/lib/image-gen/ImageGenService.js +346 -0
  16. package/dist/lib/image-gen/imageGenTools.d.ts +126 -0
  17. package/dist/lib/image-gen/imageGenTools.js +305 -0
  18. package/dist/lib/image-gen/index.d.ts +46 -0
  19. package/dist/lib/image-gen/index.js +49 -0
  20. package/dist/lib/image-gen/types.d.ts +237 -0
  21. package/dist/lib/image-gen/types.js +25 -0
  22. package/dist/lib/processors/base/BaseFileProcessor.d.ts +273 -0
  23. package/dist/lib/processors/base/BaseFileProcessor.js +614 -0
  24. package/dist/lib/processors/base/index.d.ts +14 -0
  25. package/dist/lib/processors/base/index.js +20 -0
  26. package/dist/lib/processors/base/types.d.ts +593 -0
  27. package/dist/lib/processors/base/types.js +77 -0
  28. package/dist/lib/processors/cli/fileProcessorCli.d.ts +163 -0
  29. package/dist/lib/processors/cli/fileProcessorCli.js +389 -0
  30. package/dist/lib/processors/cli/index.d.ts +37 -0
  31. package/dist/lib/processors/cli/index.js +50 -0
  32. package/dist/lib/processors/code/ConfigProcessor.d.ts +171 -0
  33. package/dist/lib/processors/code/ConfigProcessor.js +401 -0
  34. package/dist/lib/processors/code/SourceCodeProcessor.d.ts +174 -0
  35. package/dist/lib/processors/code/SourceCodeProcessor.js +305 -0
  36. package/dist/lib/processors/code/index.d.ts +44 -0
  37. package/dist/lib/processors/code/index.js +61 -0
  38. package/dist/lib/processors/config/fileTypes.d.ts +283 -0
  39. package/dist/lib/processors/config/fileTypes.js +521 -0
  40. package/dist/lib/processors/config/index.d.ts +32 -0
  41. package/dist/lib/processors/config/index.js +93 -0
  42. package/dist/lib/processors/config/languageMap.d.ts +66 -0
  43. package/dist/lib/processors/config/languageMap.js +411 -0
  44. package/dist/lib/processors/config/mimeTypes.d.ts +376 -0
  45. package/dist/lib/processors/config/mimeTypes.js +339 -0
  46. package/dist/lib/processors/config/sizeLimits.d.ts +194 -0
  47. package/dist/lib/processors/config/sizeLimits.js +247 -0
  48. package/dist/lib/processors/data/JsonProcessor.d.ts +122 -0
  49. package/dist/lib/processors/data/JsonProcessor.js +204 -0
  50. package/dist/lib/processors/data/XmlProcessor.d.ts +160 -0
  51. package/dist/lib/processors/data/XmlProcessor.js +284 -0
  52. package/dist/lib/processors/data/YamlProcessor.d.ts +163 -0
  53. package/dist/lib/processors/data/YamlProcessor.js +295 -0
  54. package/dist/lib/processors/data/index.d.ts +49 -0
  55. package/dist/lib/processors/data/index.js +77 -0
  56. package/dist/lib/processors/document/ExcelProcessor.d.ts +238 -0
  57. package/dist/lib/processors/document/ExcelProcessor.js +520 -0
  58. package/dist/lib/processors/document/OpenDocumentProcessor.d.ts +69 -0
  59. package/dist/lib/processors/document/OpenDocumentProcessor.js +211 -0
  60. package/dist/lib/processors/document/RtfProcessor.d.ts +152 -0
  61. package/dist/lib/processors/document/RtfProcessor.js +362 -0
  62. package/dist/lib/processors/document/WordProcessor.d.ts +168 -0
  63. package/dist/lib/processors/document/WordProcessor.js +354 -0
  64. package/dist/lib/processors/document/index.d.ts +54 -0
  65. package/dist/lib/processors/document/index.js +91 -0
  66. package/dist/lib/processors/errors/FileErrorCode.d.ts +98 -0
  67. package/dist/lib/processors/errors/FileErrorCode.js +256 -0
  68. package/dist/lib/processors/errors/errorHelpers.d.ts +151 -0
  69. package/dist/lib/processors/errors/errorHelpers.js +379 -0
  70. package/dist/lib/processors/errors/errorSerializer.d.ts +139 -0
  71. package/dist/lib/processors/errors/errorSerializer.js +508 -0
  72. package/dist/lib/processors/errors/index.d.ts +46 -0
  73. package/dist/lib/processors/errors/index.js +50 -0
  74. package/dist/lib/processors/index.d.ts +76 -0
  75. package/dist/lib/processors/index.js +113 -0
  76. package/dist/lib/processors/integration/FileProcessorIntegration.d.ts +244 -0
  77. package/dist/lib/processors/integration/FileProcessorIntegration.js +273 -0
  78. package/dist/lib/processors/integration/index.d.ts +42 -0
  79. package/dist/lib/processors/integration/index.js +45 -0
  80. package/dist/lib/processors/markup/HtmlProcessor.d.ts +169 -0
  81. package/dist/lib/processors/markup/HtmlProcessor.js +250 -0
  82. package/dist/lib/processors/markup/MarkdownProcessor.d.ts +165 -0
  83. package/dist/lib/processors/markup/MarkdownProcessor.js +245 -0
  84. package/dist/lib/processors/markup/SvgProcessor.d.ts +156 -0
  85. package/dist/lib/processors/markup/SvgProcessor.js +241 -0
  86. package/dist/lib/processors/markup/TextProcessor.d.ts +135 -0
  87. package/dist/lib/processors/markup/TextProcessor.js +189 -0
  88. package/dist/lib/processors/markup/index.d.ts +66 -0
  89. package/dist/lib/processors/markup/index.js +103 -0
  90. package/dist/lib/processors/registry/ProcessorRegistry.d.ts +334 -0
  91. package/dist/lib/processors/registry/ProcessorRegistry.js +609 -0
  92. package/dist/lib/processors/registry/index.d.ts +12 -0
  93. package/dist/lib/processors/registry/index.js +17 -0
  94. package/dist/lib/processors/registry/types.d.ts +53 -0
  95. package/dist/lib/processors/registry/types.js +11 -0
  96. package/dist/lib/providers/sagemaker/language-model.d.ts +2 -2
  97. package/dist/lib/server/utils/validation.d.ts +6 -6
  98. package/dist/lib/types/fileTypes.d.ts +1 -1
  99. package/dist/lib/types/index.d.ts +25 -24
  100. package/dist/lib/types/index.js +21 -20
  101. package/dist/lib/types/modelTypes.d.ts +18 -18
  102. package/dist/lib/types/pptTypes.d.ts +14 -2
  103. package/dist/lib/types/pptTypes.js +16 -0
  104. package/dist/lib/utils/async/delay.d.ts +40 -0
  105. package/dist/lib/utils/async/delay.js +43 -0
  106. package/dist/lib/utils/async/index.d.ts +23 -0
  107. package/dist/lib/utils/async/index.js +24 -0
  108. package/dist/lib/utils/async/retry.d.ts +141 -0
  109. package/dist/lib/utils/async/retry.js +172 -0
  110. package/dist/lib/utils/async/withTimeout.d.ts +73 -0
  111. package/dist/lib/utils/async/withTimeout.js +97 -0
  112. package/dist/lib/utils/fileDetector.d.ts +7 -1
  113. package/dist/lib/utils/fileDetector.js +91 -18
  114. package/dist/lib/utils/json/extract.d.ts +103 -0
  115. package/dist/lib/utils/json/extract.js +249 -0
  116. package/dist/lib/utils/json/index.d.ts +36 -0
  117. package/dist/lib/utils/json/index.js +37 -0
  118. package/dist/lib/utils/json/safeParse.d.ts +137 -0
  119. package/dist/lib/utils/json/safeParse.js +191 -0
  120. package/dist/lib/utils/messageBuilder.d.ts +2 -2
  121. package/dist/lib/utils/messageBuilder.js +15 -7
  122. package/dist/lib/utils/sanitizers/filename.d.ts +137 -0
  123. package/dist/lib/utils/sanitizers/filename.js +366 -0
  124. package/dist/lib/utils/sanitizers/html.d.ts +170 -0
  125. package/dist/lib/utils/sanitizers/html.js +326 -0
  126. package/dist/lib/utils/sanitizers/index.d.ts +26 -0
  127. package/dist/lib/utils/sanitizers/index.js +30 -0
  128. package/dist/lib/utils/sanitizers/svg.d.ts +81 -0
  129. package/dist/lib/utils/sanitizers/svg.js +483 -0
  130. package/dist/processors/base/BaseFileProcessor.d.ts +273 -0
  131. package/dist/processors/base/BaseFileProcessor.js +613 -0
  132. package/dist/processors/base/index.d.ts +14 -0
  133. package/dist/processors/base/index.js +19 -0
  134. package/dist/processors/base/types.d.ts +593 -0
  135. package/dist/processors/base/types.js +76 -0
  136. package/dist/processors/cli/fileProcessorCli.d.ts +163 -0
  137. package/dist/processors/cli/fileProcessorCli.js +388 -0
  138. package/dist/processors/cli/index.d.ts +37 -0
  139. package/dist/processors/cli/index.js +49 -0
  140. package/dist/processors/code/ConfigProcessor.d.ts +171 -0
  141. package/dist/processors/code/ConfigProcessor.js +400 -0
  142. package/dist/processors/code/SourceCodeProcessor.d.ts +174 -0
  143. package/dist/processors/code/SourceCodeProcessor.js +304 -0
  144. package/dist/processors/code/index.d.ts +44 -0
  145. package/dist/processors/code/index.js +60 -0
  146. package/dist/processors/config/fileTypes.d.ts +283 -0
  147. package/dist/processors/config/fileTypes.js +520 -0
  148. package/dist/processors/config/index.d.ts +32 -0
  149. package/dist/processors/config/index.js +92 -0
  150. package/dist/processors/config/languageMap.d.ts +66 -0
  151. package/dist/processors/config/languageMap.js +410 -0
  152. package/dist/processors/config/mimeTypes.d.ts +376 -0
  153. package/dist/processors/config/mimeTypes.js +338 -0
  154. package/dist/processors/config/sizeLimits.d.ts +194 -0
  155. package/dist/processors/config/sizeLimits.js +246 -0
  156. package/dist/processors/data/JsonProcessor.d.ts +122 -0
  157. package/dist/processors/data/JsonProcessor.js +203 -0
  158. package/dist/processors/data/XmlProcessor.d.ts +160 -0
  159. package/dist/processors/data/XmlProcessor.js +283 -0
  160. package/dist/processors/data/YamlProcessor.d.ts +163 -0
  161. package/dist/processors/data/YamlProcessor.js +294 -0
  162. package/dist/processors/data/index.d.ts +49 -0
  163. package/dist/processors/data/index.js +76 -0
  164. package/dist/processors/document/ExcelProcessor.d.ts +238 -0
  165. package/dist/processors/document/ExcelProcessor.js +519 -0
  166. package/dist/processors/document/OpenDocumentProcessor.d.ts +69 -0
  167. package/dist/processors/document/OpenDocumentProcessor.js +210 -0
  168. package/dist/processors/document/RtfProcessor.d.ts +152 -0
  169. package/dist/processors/document/RtfProcessor.js +361 -0
  170. package/dist/processors/document/WordProcessor.d.ts +168 -0
  171. package/dist/processors/document/WordProcessor.js +353 -0
  172. package/dist/processors/document/index.d.ts +54 -0
  173. package/dist/processors/document/index.js +90 -0
  174. package/dist/processors/errors/FileErrorCode.d.ts +98 -0
  175. package/dist/processors/errors/FileErrorCode.js +255 -0
  176. package/dist/processors/errors/errorHelpers.d.ts +151 -0
  177. package/dist/processors/errors/errorHelpers.js +378 -0
  178. package/dist/processors/errors/errorSerializer.d.ts +139 -0
  179. package/dist/processors/errors/errorSerializer.js +507 -0
  180. package/dist/processors/errors/index.d.ts +46 -0
  181. package/dist/processors/errors/index.js +49 -0
  182. package/dist/processors/index.d.ts +76 -0
  183. package/dist/processors/index.js +112 -0
  184. package/dist/processors/integration/FileProcessorIntegration.d.ts +244 -0
  185. package/dist/processors/integration/FileProcessorIntegration.js +272 -0
  186. package/dist/processors/integration/index.d.ts +42 -0
  187. package/dist/processors/integration/index.js +44 -0
  188. package/dist/processors/markup/HtmlProcessor.d.ts +169 -0
  189. package/dist/processors/markup/HtmlProcessor.js +249 -0
  190. package/dist/processors/markup/MarkdownProcessor.d.ts +165 -0
  191. package/dist/processors/markup/MarkdownProcessor.js +244 -0
  192. package/dist/processors/markup/SvgProcessor.d.ts +156 -0
  193. package/dist/processors/markup/SvgProcessor.js +240 -0
  194. package/dist/processors/markup/TextProcessor.d.ts +135 -0
  195. package/dist/processors/markup/TextProcessor.js +188 -0
  196. package/dist/processors/markup/index.d.ts +66 -0
  197. package/dist/processors/markup/index.js +102 -0
  198. package/dist/processors/registry/ProcessorRegistry.d.ts +334 -0
  199. package/dist/processors/registry/ProcessorRegistry.js +608 -0
  200. package/dist/processors/registry/index.d.ts +12 -0
  201. package/dist/processors/registry/index.js +16 -0
  202. package/dist/processors/registry/types.d.ts +53 -0
  203. package/dist/processors/registry/types.js +10 -0
  204. package/dist/server/utils/validation.d.ts +6 -6
  205. package/dist/types/fileTypes.d.ts +1 -1
  206. package/dist/types/index.d.ts +25 -24
  207. package/dist/types/index.js +21 -20
  208. package/dist/types/modelTypes.d.ts +10 -10
  209. package/dist/types/pptTypes.d.ts +14 -2
  210. package/dist/types/pptTypes.js +16 -0
  211. package/dist/utils/async/delay.d.ts +40 -0
  212. package/dist/utils/async/delay.js +42 -0
  213. package/dist/utils/async/index.d.ts +23 -0
  214. package/dist/utils/async/index.js +23 -0
  215. package/dist/utils/async/retry.d.ts +141 -0
  216. package/dist/utils/async/retry.js +171 -0
  217. package/dist/utils/async/withTimeout.d.ts +73 -0
  218. package/dist/utils/async/withTimeout.js +96 -0
  219. package/dist/utils/fileDetector.d.ts +7 -1
  220. package/dist/utils/fileDetector.js +91 -18
  221. package/dist/utils/json/extract.d.ts +103 -0
  222. package/dist/utils/json/extract.js +248 -0
  223. package/dist/utils/json/index.d.ts +36 -0
  224. package/dist/utils/json/index.js +36 -0
  225. package/dist/utils/json/safeParse.d.ts +137 -0
  226. package/dist/utils/json/safeParse.js +190 -0
  227. package/dist/utils/messageBuilder.d.ts +2 -2
  228. package/dist/utils/messageBuilder.js +15 -7
  229. package/dist/utils/sanitizers/filename.d.ts +137 -0
  230. package/dist/utils/sanitizers/filename.js +365 -0
  231. package/dist/utils/sanitizers/html.d.ts +170 -0
  232. package/dist/utils/sanitizers/html.js +325 -0
  233. package/dist/utils/sanitizers/index.d.ts +26 -0
  234. package/dist/utils/sanitizers/index.js +29 -0
  235. package/dist/utils/sanitizers/svg.d.ts +81 -0
  236. package/dist/utils/sanitizers/svg.js +482 -0
  237. package/package.json +2 -2
@@ -0,0 +1,163 @@
1
+ /**
2
+ * CLI Helpers for File Processors
3
+ *
4
+ * Provides utilities for CLI integration of the file processor system.
5
+ * These helpers can be used by CLI commands to process files.
6
+ *
7
+ * @module processors/cli/fileProcessorCli
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import {
12
+ * loadFileFromPath,
13
+ * processFileFromPath,
14
+ * listSupportedFileTypes,
15
+ * getCliUsage,
16
+ * } from "./processors/cli/index.js";
17
+ *
18
+ * // Process a file from the CLI
19
+ * const result = await processFileFromPath("./document.docx", {
20
+ * verbose: true,
21
+ * outputFormat: "json",
22
+ * });
23
+ *
24
+ * if (result.success) {
25
+ * console.log(result.output);
26
+ * } else {
27
+ * console.error(result.error);
28
+ * }
29
+ * ```
30
+ */
31
+ import type { FileInfo } from "../base/types.js";
32
+ /**
33
+ * Options for CLI file processing
34
+ */
35
+ export interface CliFileProcessingOptions {
36
+ /** Verbose output - shows processing details */
37
+ verbose?: boolean;
38
+ /** Processor to use (bypasses auto-detection) */
39
+ processor?: string;
40
+ /** Output format: json, text, or raw */
41
+ outputFormat?: "json" | "text" | "raw";
42
+ }
43
+ /**
44
+ * Result of CLI file processing
45
+ */
46
+ export interface CliProcessingResult {
47
+ /** Whether processing succeeded */
48
+ success: boolean;
49
+ /** Name of the processor that was used */
50
+ processorUsed: string | null;
51
+ /** Formatted output string */
52
+ output: string;
53
+ /** Error message if processing failed */
54
+ error?: string;
55
+ }
56
+ /**
57
+ * Information about a supported file type
58
+ */
59
+ export interface SupportedFileTypeInfo {
60
+ /** Processor name */
61
+ name: string;
62
+ /** Priority (lower = processed first) */
63
+ priority: number;
64
+ /** Supported file extensions */
65
+ extensions: string[];
66
+ /** Supported MIME types */
67
+ mimeTypes: string[];
68
+ /** Optional description */
69
+ description?: string;
70
+ }
71
+ /**
72
+ * Load a file from the filesystem and create a FileInfo object.
73
+ *
74
+ * @param filePath - Path to the file (relative or absolute)
75
+ * @returns FileInfo object ready for processing
76
+ * @throws Error if file doesn't exist or is not a file
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const fileInfo = await loadFileFromPath("./document.pdf");
81
+ * console.log(`Loaded: ${fileInfo.name} (${fileInfo.size} bytes)`);
82
+ * ```
83
+ */
84
+ export declare function loadFileFromPath(filePath: string): Promise<FileInfo>;
85
+ /**
86
+ * Process a file from a path using the CLI.
87
+ *
88
+ * @param filePath - Path to the file to process
89
+ * @param options - Processing options (verbose, processor, outputFormat)
90
+ * @returns Processing result with success status, output, and error info
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * const result = await processFileFromPath("./data.xlsx", {
95
+ * verbose: true,
96
+ * outputFormat: "json",
97
+ * });
98
+ *
99
+ * if (result.success) {
100
+ * console.log(result.output);
101
+ * } else {
102
+ * console.error(`Error: ${result.error}`);
103
+ * }
104
+ * ```
105
+ */
106
+ export declare function processFileFromPath(filePath: string, options?: CliFileProcessingOptions): Promise<CliProcessingResult>;
107
+ /**
108
+ * Get information about all supported file types.
109
+ *
110
+ * @returns Array of supported file type information
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const types = getSupportedFileTypes();
115
+ * for (const type of types) {
116
+ * console.log(`${type.name}: ${type.extensions.join(", ")}`);
117
+ * }
118
+ * ```
119
+ */
120
+ export declare function getSupportedFileTypes(): SupportedFileTypeInfo[];
121
+ /**
122
+ * List all supported file types formatted for CLI display.
123
+ *
124
+ * @returns Formatted string listing all supported file types
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * console.log(listSupportedFileTypes());
129
+ * ```
130
+ */
131
+ export declare function listSupportedFileTypes(): string;
132
+ /**
133
+ * Get CLI usage information for file processing commands.
134
+ *
135
+ * @returns Usage help string
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * console.log(getCliUsage());
140
+ * ```
141
+ */
142
+ export declare function getCliUsage(): string;
143
+ /**
144
+ * Check if a file exists and is readable.
145
+ *
146
+ * @param filePath - Path to check
147
+ * @returns true if file exists and is readable
148
+ */
149
+ export declare function fileExists(filePath: string): boolean;
150
+ /**
151
+ * Get file extension from a path.
152
+ *
153
+ * @param filePath - File path
154
+ * @returns Lowercase extension with leading dot, or empty string
155
+ */
156
+ export declare function getFileExtension(filePath: string): string;
157
+ /**
158
+ * Detect MIME type for a file path.
159
+ *
160
+ * @param filePath - File path
161
+ * @returns Detected MIME type
162
+ */
163
+ export declare function detectMimeType(filePath: string): string;
@@ -0,0 +1,389 @@
1
+ /**
2
+ * CLI Helpers for File Processors
3
+ *
4
+ * Provides utilities for CLI integration of the file processor system.
5
+ * These helpers can be used by CLI commands to process files.
6
+ *
7
+ * @module processors/cli/fileProcessorCli
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import {
12
+ * loadFileFromPath,
13
+ * processFileFromPath,
14
+ * listSupportedFileTypes,
15
+ * getCliUsage,
16
+ * } from "./processors/cli/index.js";
17
+ *
18
+ * // Process a file from the CLI
19
+ * const result = await processFileFromPath("./document.docx", {
20
+ * verbose: true,
21
+ * outputFormat: "json",
22
+ * });
23
+ *
24
+ * if (result.success) {
25
+ * console.log(result.output);
26
+ * } else {
27
+ * console.error(result.error);
28
+ * }
29
+ * ```
30
+ */
31
+ import * as fs from "fs";
32
+ import * as fsPromises from "fs/promises";
33
+ import * as path from "path";
34
+ import { logger } from "../../utils/logger.js";
35
+ import { getMimeTypeForExtension } from "../config/index.js";
36
+ import { getProcessorRegistry } from "../registry/index.js";
37
+ // =============================================================================
38
+ // MIME TYPE MAPPING
39
+ // =============================================================================
40
+ // Extension-to-MIME mapping is imported from the centralized config
41
+ // (../config/mimeTypes.ts) via EXTENSION_MIME_MAP and getMimeTypeForExtension.
42
+ // This avoids duplicating the ~90-entry mapping that was previously inline here.
43
+ // See EXTENSION_MIME_MAP for the single source of truth.
44
+ // =============================================================================
45
+ // FILE LOADING
46
+ // =============================================================================
47
+ /**
48
+ * Load a file from the filesystem and create a FileInfo object.
49
+ *
50
+ * @param filePath - Path to the file (relative or absolute)
51
+ * @returns FileInfo object ready for processing
52
+ * @throws Error if file doesn't exist or is not a file
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const fileInfo = await loadFileFromPath("./document.pdf");
57
+ * console.log(`Loaded: ${fileInfo.name} (${fileInfo.size} bytes)`);
58
+ * ```
59
+ */
60
+ export async function loadFileFromPath(filePath) {
61
+ const absolutePath = path.resolve(filePath);
62
+ let stats;
63
+ try {
64
+ stats = await fsPromises.stat(absolutePath);
65
+ }
66
+ catch {
67
+ throw new Error(`File not found: ${absolutePath}`);
68
+ }
69
+ if (!stats.isFile()) {
70
+ throw new Error(`Not a file: ${absolutePath}`);
71
+ }
72
+ const buffer = await fsPromises.readFile(absolutePath);
73
+ const filename = path.basename(absolutePath);
74
+ const ext = path.extname(filename).toLowerCase();
75
+ // Determine MIME type from extension
76
+ const mimeType = getMimeTypeForExtension(ext);
77
+ return {
78
+ id: absolutePath,
79
+ name: filename,
80
+ mimetype: mimeType,
81
+ size: stats.size,
82
+ buffer,
83
+ };
84
+ }
85
+ // =============================================================================
86
+ // FILE PROCESSING
87
+ // =============================================================================
88
+ /**
89
+ * Process a file from a path using the CLI.
90
+ *
91
+ * @param filePath - Path to the file to process
92
+ * @param options - Processing options (verbose, processor, outputFormat)
93
+ * @returns Processing result with success status, output, and error info
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * const result = await processFileFromPath("./data.xlsx", {
98
+ * verbose: true,
99
+ * outputFormat: "json",
100
+ * });
101
+ *
102
+ * if (result.success) {
103
+ * console.log(result.output);
104
+ * } else {
105
+ * console.error(`Error: ${result.error}`);
106
+ * }
107
+ * ```
108
+ */
109
+ export async function processFileFromPath(filePath, options) {
110
+ try {
111
+ const fileInfo = await loadFileFromPath(filePath);
112
+ if (options?.verbose) {
113
+ logger.info(`Processing: ${fileInfo.name}`);
114
+ logger.info(` Size: ${fileInfo.size} bytes`);
115
+ logger.info(` MIME: ${fileInfo.mimetype}`);
116
+ }
117
+ const registry = getProcessorRegistry();
118
+ // If a specific processor is requested, use it directly
119
+ if (options?.processor) {
120
+ const processorReg = registry.getProcessor(options.processor);
121
+ if (!processorReg) {
122
+ return {
123
+ success: false,
124
+ processorUsed: null,
125
+ output: "",
126
+ error: `Processor not found: ${options.processor}. Use 'list-file-types' to see available processors.`,
127
+ };
128
+ }
129
+ const result = await processorReg.processor.processFile(fileInfo);
130
+ if (options?.verbose) {
131
+ logger.info(` Processor: ${options.processor}`);
132
+ }
133
+ if (!result.success || !result.data) {
134
+ return {
135
+ success: false,
136
+ processorUsed: options.processor,
137
+ output: "",
138
+ error: result.error?.message || "Processing failed",
139
+ };
140
+ }
141
+ const output = formatOutput(result.data, options?.outputFormat || "text");
142
+ return {
143
+ success: true,
144
+ processorUsed: options.processor,
145
+ output,
146
+ };
147
+ }
148
+ // Auto-detect processor
149
+ const match = registry.findProcessor(fileInfo.mimetype, fileInfo.name);
150
+ if (!match) {
151
+ return {
152
+ success: false,
153
+ processorUsed: null,
154
+ output: "",
155
+ error: `No processor found for file type: ${fileInfo.mimetype} (${fileInfo.name})`,
156
+ };
157
+ }
158
+ if (options?.verbose) {
159
+ logger.info(` Processor: ${match.name}`);
160
+ logger.info(` Confidence: ${match.confidence}%`);
161
+ }
162
+ const processor = match.processor;
163
+ const result = await processor.processFile(fileInfo);
164
+ if (!result.success || !result.data) {
165
+ return {
166
+ success: false,
167
+ processorUsed: match.name,
168
+ output: "",
169
+ error: result.error?.message || "Processing failed",
170
+ };
171
+ }
172
+ // Format output based on options
173
+ const output = formatOutput(result.data, options?.outputFormat || "text");
174
+ return {
175
+ success: true,
176
+ processorUsed: match.name,
177
+ output,
178
+ };
179
+ }
180
+ catch (error) {
181
+ return {
182
+ success: false,
183
+ processorUsed: null,
184
+ output: "",
185
+ error: error instanceof Error ? error.message : String(error),
186
+ };
187
+ }
188
+ }
189
+ // =============================================================================
190
+ // OUTPUT FORMATTING
191
+ // =============================================================================
192
+ /**
193
+ * Format processed file output for display.
194
+ *
195
+ * @param data - Processed file data
196
+ * @param format - Output format (json, text, or raw)
197
+ * @returns Formatted output string
198
+ */
199
+ function formatOutput(data, format) {
200
+ if (format === "json") {
201
+ // Create a serializable version (summarize buffer)
202
+ const serializable = {
203
+ ...data,
204
+ buffer: `<Buffer ${data.buffer.length} bytes>`,
205
+ };
206
+ return JSON.stringify(serializable, null, 2);
207
+ }
208
+ if (format === "raw") {
209
+ return data.buffer.toString("utf-8");
210
+ }
211
+ // Text format - extract text content if available
212
+ const dataRecord = data;
213
+ const textFields = ["textContent", "content", "text", "parsedContent"];
214
+ for (const field of textFields) {
215
+ const value = dataRecord[field];
216
+ if (typeof value === "string") {
217
+ return value;
218
+ }
219
+ }
220
+ // Check for structured data that should be stringified
221
+ const structuredFields = ["parsedData", "data", "rows", "sheets"];
222
+ for (const field of structuredFields) {
223
+ const value = dataRecord[field];
224
+ if (value !== undefined && value !== null) {
225
+ return JSON.stringify(value, null, 2);
226
+ }
227
+ }
228
+ // Fallback to JSON representation
229
+ const serializable = {
230
+ ...data,
231
+ buffer: `<Buffer ${data.buffer.length} bytes>`,
232
+ };
233
+ return JSON.stringify(serializable, null, 2);
234
+ }
235
+ // =============================================================================
236
+ // FILE TYPE LISTING
237
+ // =============================================================================
238
+ /**
239
+ * Get information about all supported file types.
240
+ *
241
+ * @returns Array of supported file type information
242
+ *
243
+ * @example
244
+ * ```typescript
245
+ * const types = getSupportedFileTypes();
246
+ * for (const type of types) {
247
+ * console.log(`${type.name}: ${type.extensions.join(", ")}`);
248
+ * }
249
+ * ```
250
+ */
251
+ export function getSupportedFileTypes() {
252
+ const registry = getProcessorRegistry();
253
+ const processors = registry.listProcessors();
254
+ return processors.map((proc) => {
255
+ // Extract config from processor via public getConfig() method
256
+ const config = proc.processor.getConfig();
257
+ return {
258
+ name: proc.name,
259
+ priority: proc.priority,
260
+ extensions: config.supportedExtensions,
261
+ mimeTypes: config.supportedMimeTypes,
262
+ description: proc.description,
263
+ };
264
+ });
265
+ }
266
+ /**
267
+ * List all supported file types formatted for CLI display.
268
+ *
269
+ * @returns Formatted string listing all supported file types
270
+ *
271
+ * @example
272
+ * ```typescript
273
+ * console.log(listSupportedFileTypes());
274
+ * ```
275
+ */
276
+ export function listSupportedFileTypes() {
277
+ const types = getSupportedFileTypes();
278
+ if (types.length === 0) {
279
+ return "No processors registered. Initialize the processor registry first.";
280
+ }
281
+ let output = "Supported file types:\n\n";
282
+ // Sort by priority (lower = higher priority)
283
+ const sortedTypes = [...types].sort((a, b) => a.priority - b.priority);
284
+ for (const type of sortedTypes) {
285
+ output += ` ${type.name} (priority: ${type.priority})\n`;
286
+ if (type.description) {
287
+ output += ` ${type.description}\n`;
288
+ }
289
+ if (type.extensions.length > 0) {
290
+ output += ` Extensions: ${type.extensions.join(", ")}\n`;
291
+ }
292
+ if (type.mimeTypes.length > 0) {
293
+ // Show first 3 MIME types to avoid overwhelming output
294
+ const displayMimes = type.mimeTypes.slice(0, 3);
295
+ const suffix = type.mimeTypes.length > 3
296
+ ? ` (+${type.mimeTypes.length - 3} more)`
297
+ : "";
298
+ output += ` MIME types: ${displayMimes.join(", ")}${suffix}\n`;
299
+ }
300
+ output += "\n";
301
+ }
302
+ return output;
303
+ }
304
+ // =============================================================================
305
+ // CLI USAGE HELP
306
+ // =============================================================================
307
+ /**
308
+ * Get CLI usage information for file processing commands.
309
+ *
310
+ * @returns Usage help string
311
+ *
312
+ * @example
313
+ * ```typescript
314
+ * console.log(getCliUsage());
315
+ * ```
316
+ */
317
+ export function getCliUsage() {
318
+ return `
319
+ File Processor CLI Usage:
320
+
321
+ Process a file:
322
+ neurolink process-file <path> [options]
323
+
324
+ Options:
325
+ --processor <name> Use specific processor (e.g., excel, word, json)
326
+ --format <type> Output format: json, text, or raw
327
+ --verbose Show processing details
328
+
329
+ List supported types:
330
+ neurolink list-file-types
331
+
332
+ Examples:
333
+ neurolink process-file document.docx
334
+ neurolink process-file data.xlsx --format json
335
+ neurolink process-file config.yaml --processor yaml
336
+ neurolink process-file report.pdf --verbose
337
+ neurolink process-file data.csv --format raw
338
+
339
+ Output Formats:
340
+ text - Extract text content (default)
341
+ json - Full structured output as JSON
342
+ raw - Raw file content as UTF-8 string
343
+
344
+ Notes:
345
+ - Processor is auto-detected based on file extension and MIME type
346
+ - Use --processor to override auto-detection
347
+ - Use --verbose to see which processor was selected
348
+ `;
349
+ }
350
+ // =============================================================================
351
+ // UTILITY FUNCTIONS
352
+ // =============================================================================
353
+ /**
354
+ * Check if a file exists and is readable.
355
+ *
356
+ * @param filePath - Path to check
357
+ * @returns true if file exists and is readable
358
+ */
359
+ export function fileExists(filePath) {
360
+ try {
361
+ const absolutePath = path.resolve(filePath);
362
+ fs.accessSync(absolutePath, fs.constants.R_OK);
363
+ return fs.statSync(absolutePath).isFile();
364
+ }
365
+ catch {
366
+ return false;
367
+ }
368
+ }
369
+ /**
370
+ * Get file extension from a path.
371
+ *
372
+ * @param filePath - File path
373
+ * @returns Lowercase extension with leading dot, or empty string
374
+ */
375
+ export function getFileExtension(filePath) {
376
+ const ext = path.extname(filePath);
377
+ return ext.toLowerCase();
378
+ }
379
+ /**
380
+ * Detect MIME type for a file path.
381
+ *
382
+ * @param filePath - File path
383
+ * @returns Detected MIME type
384
+ */
385
+ export function detectMimeType(filePath) {
386
+ const ext = getFileExtension(filePath);
387
+ return getMimeTypeForExtension(ext);
388
+ }
389
+ //# sourceMappingURL=fileProcessorCli.js.map
@@ -0,0 +1,37 @@
1
+ /**
2
+ * CLI Helpers for File Processors
3
+ *
4
+ * Utilities for CLI integration of the file processor system.
5
+ * Provides file loading, processing, and output formatting for CLI commands.
6
+ *
7
+ * @module processors/cli
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import {
12
+ * loadFileFromPath,
13
+ * processFileFromPath,
14
+ * listSupportedFileTypes,
15
+ * getCliUsage,
16
+ * type CliFileProcessingOptions,
17
+ * } from "./processors/cli/index.js";
18
+ *
19
+ * // Process a file with verbose output
20
+ * const result = await processFileFromPath("./document.pdf", {
21
+ * verbose: true,
22
+ * outputFormat: "json",
23
+ * });
24
+ *
25
+ * if (result.success) {
26
+ * console.log(`Processed with: ${result.processorUsed}`);
27
+ * console.log(result.output);
28
+ * } else {
29
+ * console.error(`Error: ${result.error}`);
30
+ * }
31
+ *
32
+ * // List all supported file types
33
+ * console.log(listSupportedFileTypes());
34
+ * ```
35
+ */
36
+ export { detectMimeType, fileExists, getCliUsage, getFileExtension, getSupportedFileTypes, listSupportedFileTypes, loadFileFromPath, processFileFromPath, } from "./fileProcessorCli.js";
37
+ export type { CliFileProcessingOptions, CliProcessingResult, SupportedFileTypeInfo, } from "./fileProcessorCli.js";
@@ -0,0 +1,50 @@
1
+ /**
2
+ * CLI Helpers for File Processors
3
+ *
4
+ * Utilities for CLI integration of the file processor system.
5
+ * Provides file loading, processing, and output formatting for CLI commands.
6
+ *
7
+ * @module processors/cli
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import {
12
+ * loadFileFromPath,
13
+ * processFileFromPath,
14
+ * listSupportedFileTypes,
15
+ * getCliUsage,
16
+ * type CliFileProcessingOptions,
17
+ * } from "./processors/cli/index.js";
18
+ *
19
+ * // Process a file with verbose output
20
+ * const result = await processFileFromPath("./document.pdf", {
21
+ * verbose: true,
22
+ * outputFormat: "json",
23
+ * });
24
+ *
25
+ * if (result.success) {
26
+ * console.log(`Processed with: ${result.processorUsed}`);
27
+ * console.log(result.output);
28
+ * } else {
29
+ * console.error(`Error: ${result.error}`);
30
+ * }
31
+ *
32
+ * // List all supported file types
33
+ * console.log(listSupportedFileTypes());
34
+ * ```
35
+ */
36
+ // =============================================================================
37
+ // MAIN EXPORTS
38
+ // =============================================================================
39
+ export { detectMimeType,
40
+ // Utility functions
41
+ fileExists,
42
+ // CLI help
43
+ getCliUsage, getFileExtension,
44
+ // File type listing
45
+ getSupportedFileTypes, listSupportedFileTypes,
46
+ // File loading
47
+ loadFileFromPath,
48
+ // File processing
49
+ processFileFromPath, } from "./fileProcessorCli.js";
50
+ //# sourceMappingURL=index.js.map