@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,135 @@
1
+ /**
2
+ * Plain Text File Processor
3
+ *
4
+ * Processes plain text files (.txt, .text, .log) with line and word counting,
5
+ * encoding detection, and automatic truncation for large files.
6
+ *
7
+ * Priority: 110 (lower priority - catch-all for text files)
8
+ *
9
+ * @module processors/markup/TextProcessor
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { textProcessor, processText, isTextFile } from "./markup/TextProcessor.js";
14
+ *
15
+ * // Check if file is a plain text file
16
+ * if (isTextFile(mimetype, filename)) {
17
+ * const result = await processText(fileInfo);
18
+ * if (result.success) {
19
+ * console.log('Content:', result.data.content);
20
+ * console.log('Lines:', result.data.lineCount);
21
+ * console.log('Words:', result.data.wordCount);
22
+ * if (result.data.truncated) {
23
+ * console.warn('File was truncated due to size');
24
+ * }
25
+ * }
26
+ * }
27
+ * ```
28
+ */
29
+ import { BaseFileProcessor } from "../base/BaseFileProcessor.js";
30
+ import type { FileInfo, FileProcessingResult, ProcessOptions } from "../base/types.js";
31
+ export type { ProcessedText } from "../base/types.js";
32
+ import type { ProcessedText } from "../base/types.js";
33
+ /**
34
+ * Text Processor - handles plain text files.
35
+ *
36
+ * Features:
37
+ * - Line and word counting
38
+ * - Automatic truncation for large files
39
+ * - UTF-8 encoding support
40
+ *
41
+ * Priority: 110 (lower priority - catch-all for text files)
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const processor = new TextProcessor();
46
+ *
47
+ * const result = await processor.processFile({
48
+ * id: 'txt-123',
49
+ * name: 'readme.txt',
50
+ * mimetype: 'text/plain',
51
+ * size: 1024,
52
+ * url: 'https://example.com/readme.txt',
53
+ * });
54
+ *
55
+ * if (result.success) {
56
+ * console.log('Content:', result.data.content);
57
+ * console.log('Lines:', result.data.lineCount);
58
+ * }
59
+ * ```
60
+ */
61
+ export declare class TextProcessor extends BaseFileProcessor<ProcessedText> {
62
+ constructor();
63
+ /**
64
+ * Build processed text result with content analysis.
65
+ * Counts lines and words, and truncates if necessary.
66
+ *
67
+ * @param buffer - Downloaded file content
68
+ * @param fileInfo - Original file information
69
+ * @returns Processed text result with content analysis
70
+ */
71
+ protected buildProcessedResult(buffer: Buffer, fileInfo: FileInfo): ProcessedText;
72
+ }
73
+ /**
74
+ * Singleton text processor instance.
75
+ * Use this for most processing needs.
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * import { textProcessor } from "./markup/TextProcessor.js";
80
+ *
81
+ * const result = await textProcessor.processFile(fileInfo);
82
+ * ```
83
+ */
84
+ export declare const textProcessor: TextProcessor;
85
+ /**
86
+ * Check if a file is a plain text file.
87
+ *
88
+ * @param mimetype - MIME type of the file
89
+ * @param filename - Filename (for extension-based detection)
90
+ * @returns true if the file is a plain text file
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * if (isTextFile('text/plain', 'readme.txt')) {
95
+ * // Handle as plain text
96
+ * }
97
+ *
98
+ * // Also works with just filename
99
+ * if (isTextFile('', 'debug.log')) {
100
+ * // Handle as text based on extension
101
+ * }
102
+ * ```
103
+ */
104
+ export declare function isTextFile(mimetype: string, filename: string): boolean;
105
+ /**
106
+ * Process a single plain text file.
107
+ * Convenience function that uses the singleton processor.
108
+ *
109
+ * @param fileInfo - File information (can include URL or buffer)
110
+ * @param options - Optional processing options (auth headers, timeout, retry config)
111
+ * @returns Processing result with text content and analysis
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const result = await processText({
116
+ * id: 'txt-123',
117
+ * name: 'notes.txt',
118
+ * mimetype: 'text/plain',
119
+ * size: 2048,
120
+ * buffer: textBuffer,
121
+ * });
122
+ *
123
+ * if (result.success) {
124
+ * console.log('Content:', result.data.content);
125
+ * console.log('Lines:', result.data.lineCount);
126
+ * console.log('Words:', result.data.wordCount);
127
+ * if (result.data.truncated) {
128
+ * console.warn('Content was truncated');
129
+ * }
130
+ * } else {
131
+ * console.error('Processing failed:', result.error.userMessage);
132
+ * }
133
+ * ```
134
+ */
135
+ export declare function processText(fileInfo: FileInfo, options?: ProcessOptions): Promise<FileProcessingResult<ProcessedText>>;
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Plain Text File Processor
3
+ *
4
+ * Processes plain text files (.txt, .text, .log) with line and word counting,
5
+ * encoding detection, and automatic truncation for large files.
6
+ *
7
+ * Priority: 110 (lower priority - catch-all for text files)
8
+ *
9
+ * @module processors/markup/TextProcessor
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { textProcessor, processText, isTextFile } from "./markup/TextProcessor.js";
14
+ *
15
+ * // Check if file is a plain text file
16
+ * if (isTextFile(mimetype, filename)) {
17
+ * const result = await processText(fileInfo);
18
+ * if (result.success) {
19
+ * console.log('Content:', result.data.content);
20
+ * console.log('Lines:', result.data.lineCount);
21
+ * console.log('Words:', result.data.wordCount);
22
+ * if (result.data.truncated) {
23
+ * console.warn('File was truncated due to size');
24
+ * }
25
+ * }
26
+ * }
27
+ * ```
28
+ */
29
+ import { BaseFileProcessor } from "../base/BaseFileProcessor.js";
30
+ import { SIZE_LIMITS } from "../config/index.js";
31
+ // =============================================================================
32
+ // CONSTANTS
33
+ // =============================================================================
34
+ /** Plain text MIME types */
35
+ const SUPPORTED_TEXT_TYPES = ["text/plain"];
36
+ /** Plain text file extensions */
37
+ const SUPPORTED_TEXT_EXTENSIONS = [".txt", ".text", ".log"];
38
+ // =============================================================================
39
+ // TEXT PROCESSOR
40
+ // =============================================================================
41
+ /**
42
+ * Text Processor - handles plain text files.
43
+ *
44
+ * Features:
45
+ * - Line and word counting
46
+ * - Automatic truncation for large files
47
+ * - UTF-8 encoding support
48
+ *
49
+ * Priority: 110 (lower priority - catch-all for text files)
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const processor = new TextProcessor();
54
+ *
55
+ * const result = await processor.processFile({
56
+ * id: 'txt-123',
57
+ * name: 'readme.txt',
58
+ * mimetype: 'text/plain',
59
+ * size: 1024,
60
+ * url: 'https://example.com/readme.txt',
61
+ * });
62
+ *
63
+ * if (result.success) {
64
+ * console.log('Content:', result.data.content);
65
+ * console.log('Lines:', result.data.lineCount);
66
+ * }
67
+ * ```
68
+ */
69
+ export class TextProcessor extends BaseFileProcessor {
70
+ constructor() {
71
+ super({
72
+ maxSizeMB: SIZE_LIMITS.TEXT_MAX_MB,
73
+ timeoutMs: 30000,
74
+ supportedMimeTypes: [...SUPPORTED_TEXT_TYPES],
75
+ supportedExtensions: [...SUPPORTED_TEXT_EXTENSIONS],
76
+ fileTypeName: "Text",
77
+ defaultFilename: "document.txt",
78
+ });
79
+ }
80
+ /**
81
+ * Build processed text result with content analysis.
82
+ * Counts lines and words, and truncates if necessary.
83
+ *
84
+ * @param buffer - Downloaded file content
85
+ * @param fileInfo - Original file information
86
+ * @returns Processed text result with content analysis
87
+ */
88
+ buildProcessedResult(buffer, fileInfo) {
89
+ const content = buffer.toString("utf-8");
90
+ const lines = content.split("\n");
91
+ const words = content.split(/\s+/).filter((w) => w.length > 0);
92
+ const filename = this.getFilename(fileInfo);
93
+ // Truncate if too many lines
94
+ let finalContent = content;
95
+ let truncated = false;
96
+ if (lines.length > SIZE_LIMITS.MAX_SOURCE_CODE_LINES) {
97
+ truncated = true;
98
+ finalContent = lines
99
+ .slice(0, SIZE_LIMITS.MAX_SOURCE_CODE_LINES)
100
+ .join("\n");
101
+ finalContent += `\n\n... [Truncated: ${lines.length - SIZE_LIMITS.MAX_SOURCE_CODE_LINES} more lines]`;
102
+ }
103
+ return {
104
+ content: finalContent,
105
+ lineCount: lines.length,
106
+ wordCount: words.length,
107
+ encoding: "utf-8",
108
+ truncated,
109
+ buffer,
110
+ mimetype: fileInfo.mimetype || "text/plain",
111
+ size: fileInfo.size,
112
+ filename,
113
+ };
114
+ }
115
+ }
116
+ // =============================================================================
117
+ // SINGLETON INSTANCE
118
+ // =============================================================================
119
+ /**
120
+ * Singleton text processor instance.
121
+ * Use this for most processing needs.
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * import { textProcessor } from "./markup/TextProcessor.js";
126
+ *
127
+ * const result = await textProcessor.processFile(fileInfo);
128
+ * ```
129
+ */
130
+ export const textProcessor = new TextProcessor();
131
+ // =============================================================================
132
+ // HELPER FUNCTIONS
133
+ // =============================================================================
134
+ /**
135
+ * Check if a file is a plain text file.
136
+ *
137
+ * @param mimetype - MIME type of the file
138
+ * @param filename - Filename (for extension-based detection)
139
+ * @returns true if the file is a plain text file
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * if (isTextFile('text/plain', 'readme.txt')) {
144
+ * // Handle as plain text
145
+ * }
146
+ *
147
+ * // Also works with just filename
148
+ * if (isTextFile('', 'debug.log')) {
149
+ * // Handle as text based on extension
150
+ * }
151
+ * ```
152
+ */
153
+ export function isTextFile(mimetype, filename) {
154
+ return textProcessor.isFileSupported(mimetype, filename);
155
+ }
156
+ /**
157
+ * Process a single plain text file.
158
+ * Convenience function that uses the singleton processor.
159
+ *
160
+ * @param fileInfo - File information (can include URL or buffer)
161
+ * @param options - Optional processing options (auth headers, timeout, retry config)
162
+ * @returns Processing result with text content and analysis
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * const result = await processText({
167
+ * id: 'txt-123',
168
+ * name: 'notes.txt',
169
+ * mimetype: 'text/plain',
170
+ * size: 2048,
171
+ * buffer: textBuffer,
172
+ * });
173
+ *
174
+ * if (result.success) {
175
+ * console.log('Content:', result.data.content);
176
+ * console.log('Lines:', result.data.lineCount);
177
+ * console.log('Words:', result.data.wordCount);
178
+ * if (result.data.truncated) {
179
+ * console.warn('Content was truncated');
180
+ * }
181
+ * } else {
182
+ * console.error('Processing failed:', result.error.userMessage);
183
+ * }
184
+ * ```
185
+ */
186
+ export async function processText(fileInfo, options) {
187
+ return textProcessor.processFile(fileInfo, options);
188
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Markup Processors Module
3
+ *
4
+ * Processors for markup-based file formats that are processed as TEXT
5
+ * rather than binary data. This includes:
6
+ * - SVG files (XML-based, despite being in image/* MIME type)
7
+ * - HTML files (web pages with text extraction)
8
+ * - Markdown files (documentation with structure analysis)
9
+ *
10
+ * @module processors/markup
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import {
15
+ * // SVG Processor
16
+ * SvgProcessor,
17
+ * svgProcessor,
18
+ * isSvgFile,
19
+ * processSvg,
20
+ * type ProcessedSvg,
21
+ *
22
+ * // HTML Processor
23
+ * HtmlProcessor,
24
+ * htmlProcessor,
25
+ * isHtmlFile,
26
+ * processHtml,
27
+ * type ProcessedHtml,
28
+ *
29
+ * // Markdown Processor
30
+ * MarkdownProcessor,
31
+ * markdownProcessor,
32
+ * isMarkdownFile,
33
+ * processMarkdown,
34
+ * type ProcessedMarkdown,
35
+ * } from "./markup/index.js";
36
+ *
37
+ * // Process an SVG file
38
+ * if (isSvgFile(mimetype, filename)) {
39
+ * const result = await processSvg(fileInfo);
40
+ * if (result.success) {
41
+ * console.log(result.data.textContent);
42
+ * }
43
+ * }
44
+ *
45
+ * // Process an HTML file
46
+ * if (isHtmlFile(mimetype, filename)) {
47
+ * const result = await processHtml(fileInfo);
48
+ * if (result.success) {
49
+ * console.log('Title:', result.data.title);
50
+ * console.log('Text:', result.data.textContent);
51
+ * }
52
+ * }
53
+ *
54
+ * // Process a Markdown file
55
+ * if (isMarkdownFile(mimetype, filename)) {
56
+ * const result = await processMarkdown(fileInfo);
57
+ * if (result.success) {
58
+ * console.log('Headings:', result.data.headings);
59
+ * }
60
+ * }
61
+ * ```
62
+ */
63
+ export { isSvgFile, type ProcessedSvg, processSvg, SvgProcessor, svgProcessor, validateSvgSize, } from "./SvgProcessor.js";
64
+ export { HtmlProcessor, htmlProcessor, isHtmlFile, type ProcessedHtml, processHtml, validateHtmlSize, } from "./HtmlProcessor.js";
65
+ export { isMarkdownFile, MarkdownProcessor, markdownProcessor, type ProcessedMarkdown, processMarkdown, validateMarkdownSize, } from "./MarkdownProcessor.js";
66
+ export { isTextFile, type ProcessedText, processText, TextProcessor, textProcessor, } from "./TextProcessor.js";
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Markup Processors Module
3
+ *
4
+ * Processors for markup-based file formats that are processed as TEXT
5
+ * rather than binary data. This includes:
6
+ * - SVG files (XML-based, despite being in image/* MIME type)
7
+ * - HTML files (web pages with text extraction)
8
+ * - Markdown files (documentation with structure analysis)
9
+ *
10
+ * @module processors/markup
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import {
15
+ * // SVG Processor
16
+ * SvgProcessor,
17
+ * svgProcessor,
18
+ * isSvgFile,
19
+ * processSvg,
20
+ * type ProcessedSvg,
21
+ *
22
+ * // HTML Processor
23
+ * HtmlProcessor,
24
+ * htmlProcessor,
25
+ * isHtmlFile,
26
+ * processHtml,
27
+ * type ProcessedHtml,
28
+ *
29
+ * // Markdown Processor
30
+ * MarkdownProcessor,
31
+ * markdownProcessor,
32
+ * isMarkdownFile,
33
+ * processMarkdown,
34
+ * type ProcessedMarkdown,
35
+ * } from "./markup/index.js";
36
+ *
37
+ * // Process an SVG file
38
+ * if (isSvgFile(mimetype, filename)) {
39
+ * const result = await processSvg(fileInfo);
40
+ * if (result.success) {
41
+ * console.log(result.data.textContent);
42
+ * }
43
+ * }
44
+ *
45
+ * // Process an HTML file
46
+ * if (isHtmlFile(mimetype, filename)) {
47
+ * const result = await processHtml(fileInfo);
48
+ * if (result.success) {
49
+ * console.log('Title:', result.data.title);
50
+ * console.log('Text:', result.data.textContent);
51
+ * }
52
+ * }
53
+ *
54
+ * // Process a Markdown file
55
+ * if (isMarkdownFile(mimetype, filename)) {
56
+ * const result = await processMarkdown(fileInfo);
57
+ * if (result.success) {
58
+ * console.log('Headings:', result.data.headings);
59
+ * }
60
+ * }
61
+ * ```
62
+ */
63
+ // =============================================================================
64
+ // SVG PROCESSOR
65
+ // =============================================================================
66
+ export {
67
+ // Helper functions
68
+ isSvgFile, processSvg,
69
+ // Processor class
70
+ SvgProcessor,
71
+ // Singleton instance
72
+ svgProcessor, validateSvgSize, } from "./SvgProcessor.js";
73
+ // =============================================================================
74
+ // HTML PROCESSOR
75
+ // =============================================================================
76
+ export {
77
+ // Processor class
78
+ HtmlProcessor,
79
+ // Singleton instance
80
+ htmlProcessor,
81
+ // Helper functions
82
+ isHtmlFile, processHtml, validateHtmlSize, } from "./HtmlProcessor.js";
83
+ // =============================================================================
84
+ // MARKDOWN PROCESSOR
85
+ // =============================================================================
86
+ export {
87
+ // Helper functions
88
+ isMarkdownFile,
89
+ // Processor class
90
+ MarkdownProcessor,
91
+ // Singleton instance
92
+ markdownProcessor, processMarkdown, validateMarkdownSize, } from "./MarkdownProcessor.js";
93
+ // =============================================================================
94
+ // TEXT PROCESSOR
95
+ // =============================================================================
96
+ export {
97
+ // Helper functions
98
+ isTextFile, processText,
99
+ // Processor class
100
+ TextProcessor,
101
+ // Singleton instance
102
+ textProcessor, } from "./TextProcessor.js";