@juspay/neurolink 9.1.0 → 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 (239) hide show
  1. package/CHANGELOG.md +12 -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 +51 -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/csvProcessor.js +442 -0
  113. package/dist/lib/utils/fileDetector.d.ts +7 -1
  114. package/dist/lib/utils/fileDetector.js +91 -18
  115. package/dist/lib/utils/json/extract.d.ts +103 -0
  116. package/dist/lib/utils/json/extract.js +249 -0
  117. package/dist/lib/utils/json/index.d.ts +36 -0
  118. package/dist/lib/utils/json/index.js +37 -0
  119. package/dist/lib/utils/json/safeParse.d.ts +137 -0
  120. package/dist/lib/utils/json/safeParse.js +191 -0
  121. package/dist/lib/utils/messageBuilder.d.ts +2 -2
  122. package/dist/lib/utils/messageBuilder.js +15 -7
  123. package/dist/lib/utils/sanitizers/filename.d.ts +137 -0
  124. package/dist/lib/utils/sanitizers/filename.js +366 -0
  125. package/dist/lib/utils/sanitizers/html.d.ts +170 -0
  126. package/dist/lib/utils/sanitizers/html.js +326 -0
  127. package/dist/lib/utils/sanitizers/index.d.ts +26 -0
  128. package/dist/lib/utils/sanitizers/index.js +30 -0
  129. package/dist/lib/utils/sanitizers/svg.d.ts +81 -0
  130. package/dist/lib/utils/sanitizers/svg.js +483 -0
  131. package/dist/processors/base/BaseFileProcessor.d.ts +273 -0
  132. package/dist/processors/base/BaseFileProcessor.js +613 -0
  133. package/dist/processors/base/index.d.ts +14 -0
  134. package/dist/processors/base/index.js +19 -0
  135. package/dist/processors/base/types.d.ts +593 -0
  136. package/dist/processors/base/types.js +76 -0
  137. package/dist/processors/cli/fileProcessorCli.d.ts +163 -0
  138. package/dist/processors/cli/fileProcessorCli.js +388 -0
  139. package/dist/processors/cli/index.d.ts +37 -0
  140. package/dist/processors/cli/index.js +49 -0
  141. package/dist/processors/code/ConfigProcessor.d.ts +171 -0
  142. package/dist/processors/code/ConfigProcessor.js +400 -0
  143. package/dist/processors/code/SourceCodeProcessor.d.ts +174 -0
  144. package/dist/processors/code/SourceCodeProcessor.js +304 -0
  145. package/dist/processors/code/index.d.ts +44 -0
  146. package/dist/processors/code/index.js +60 -0
  147. package/dist/processors/config/fileTypes.d.ts +283 -0
  148. package/dist/processors/config/fileTypes.js +520 -0
  149. package/dist/processors/config/index.d.ts +32 -0
  150. package/dist/processors/config/index.js +92 -0
  151. package/dist/processors/config/languageMap.d.ts +66 -0
  152. package/dist/processors/config/languageMap.js +410 -0
  153. package/dist/processors/config/mimeTypes.d.ts +376 -0
  154. package/dist/processors/config/mimeTypes.js +338 -0
  155. package/dist/processors/config/sizeLimits.d.ts +194 -0
  156. package/dist/processors/config/sizeLimits.js +246 -0
  157. package/dist/processors/data/JsonProcessor.d.ts +122 -0
  158. package/dist/processors/data/JsonProcessor.js +203 -0
  159. package/dist/processors/data/XmlProcessor.d.ts +160 -0
  160. package/dist/processors/data/XmlProcessor.js +283 -0
  161. package/dist/processors/data/YamlProcessor.d.ts +163 -0
  162. package/dist/processors/data/YamlProcessor.js +294 -0
  163. package/dist/processors/data/index.d.ts +49 -0
  164. package/dist/processors/data/index.js +76 -0
  165. package/dist/processors/document/ExcelProcessor.d.ts +238 -0
  166. package/dist/processors/document/ExcelProcessor.js +519 -0
  167. package/dist/processors/document/OpenDocumentProcessor.d.ts +69 -0
  168. package/dist/processors/document/OpenDocumentProcessor.js +210 -0
  169. package/dist/processors/document/RtfProcessor.d.ts +152 -0
  170. package/dist/processors/document/RtfProcessor.js +361 -0
  171. package/dist/processors/document/WordProcessor.d.ts +168 -0
  172. package/dist/processors/document/WordProcessor.js +353 -0
  173. package/dist/processors/document/index.d.ts +54 -0
  174. package/dist/processors/document/index.js +90 -0
  175. package/dist/processors/errors/FileErrorCode.d.ts +98 -0
  176. package/dist/processors/errors/FileErrorCode.js +255 -0
  177. package/dist/processors/errors/errorHelpers.d.ts +151 -0
  178. package/dist/processors/errors/errorHelpers.js +378 -0
  179. package/dist/processors/errors/errorSerializer.d.ts +139 -0
  180. package/dist/processors/errors/errorSerializer.js +507 -0
  181. package/dist/processors/errors/index.d.ts +46 -0
  182. package/dist/processors/errors/index.js +49 -0
  183. package/dist/processors/index.d.ts +76 -0
  184. package/dist/processors/index.js +112 -0
  185. package/dist/processors/integration/FileProcessorIntegration.d.ts +244 -0
  186. package/dist/processors/integration/FileProcessorIntegration.js +272 -0
  187. package/dist/processors/integration/index.d.ts +42 -0
  188. package/dist/processors/integration/index.js +44 -0
  189. package/dist/processors/markup/HtmlProcessor.d.ts +169 -0
  190. package/dist/processors/markup/HtmlProcessor.js +249 -0
  191. package/dist/processors/markup/MarkdownProcessor.d.ts +165 -0
  192. package/dist/processors/markup/MarkdownProcessor.js +244 -0
  193. package/dist/processors/markup/SvgProcessor.d.ts +156 -0
  194. package/dist/processors/markup/SvgProcessor.js +240 -0
  195. package/dist/processors/markup/TextProcessor.d.ts +135 -0
  196. package/dist/processors/markup/TextProcessor.js +188 -0
  197. package/dist/processors/markup/index.d.ts +66 -0
  198. package/dist/processors/markup/index.js +102 -0
  199. package/dist/processors/registry/ProcessorRegistry.d.ts +334 -0
  200. package/dist/processors/registry/ProcessorRegistry.js +608 -0
  201. package/dist/processors/registry/index.d.ts +12 -0
  202. package/dist/processors/registry/index.js +16 -0
  203. package/dist/processors/registry/types.d.ts +53 -0
  204. package/dist/processors/registry/types.js +10 -0
  205. package/dist/server/utils/validation.d.ts +6 -6
  206. package/dist/types/fileTypes.d.ts +51 -1
  207. package/dist/types/index.d.ts +25 -24
  208. package/dist/types/index.js +21 -20
  209. package/dist/types/modelTypes.d.ts +10 -10
  210. package/dist/types/pptTypes.d.ts +14 -2
  211. package/dist/types/pptTypes.js +16 -0
  212. package/dist/utils/async/delay.d.ts +40 -0
  213. package/dist/utils/async/delay.js +42 -0
  214. package/dist/utils/async/index.d.ts +23 -0
  215. package/dist/utils/async/index.js +23 -0
  216. package/dist/utils/async/retry.d.ts +141 -0
  217. package/dist/utils/async/retry.js +171 -0
  218. package/dist/utils/async/withTimeout.d.ts +73 -0
  219. package/dist/utils/async/withTimeout.js +96 -0
  220. package/dist/utils/csvProcessor.js +442 -0
  221. package/dist/utils/fileDetector.d.ts +7 -1
  222. package/dist/utils/fileDetector.js +91 -18
  223. package/dist/utils/json/extract.d.ts +103 -0
  224. package/dist/utils/json/extract.js +248 -0
  225. package/dist/utils/json/index.d.ts +36 -0
  226. package/dist/utils/json/index.js +36 -0
  227. package/dist/utils/json/safeParse.d.ts +137 -0
  228. package/dist/utils/json/safeParse.js +190 -0
  229. package/dist/utils/messageBuilder.d.ts +2 -2
  230. package/dist/utils/messageBuilder.js +15 -7
  231. package/dist/utils/sanitizers/filename.d.ts +137 -0
  232. package/dist/utils/sanitizers/filename.js +365 -0
  233. package/dist/utils/sanitizers/html.d.ts +170 -0
  234. package/dist/utils/sanitizers/html.js +325 -0
  235. package/dist/utils/sanitizers/index.d.ts +26 -0
  236. package/dist/utils/sanitizers/index.js +29 -0
  237. package/dist/utils/sanitizers/svg.d.ts +81 -0
  238. package/dist/utils/sanitizers/svg.js +482 -0
  239. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [9.2.0](https://github.com/juspay/neurolink/compare/v9.1.1...v9.2.0) (2026-02-06)
2
+
3
+ ### Features
4
+
5
+ - **(multimodal):** add file processor system with 17+ file types and SVG text injection ([9a7b585](https://github.com/juspay/neurolink/commit/9a7b5851e562f7bd55164d1c3dca42d8f18cc827))
6
+
7
+ ## [9.1.1](https://github.com/juspay/neurolink/compare/v9.1.0...v9.1.1) (2026-02-05)
8
+
9
+ ### Bug Fixes
10
+
11
+ - **(csv-processor):** enhance metadata detection with data types and quality analysis ([2d27c5c](https://github.com/juspay/neurolink/commit/2d27c5cc4cd99b52da079fba741006216c0282ea))
12
+
1
13
  ## [9.1.0](https://github.com/juspay/neurolink/compare/v9.0.1...v9.1.0) (2026-02-05)
2
14
 
3
15
  ### Features
package/README.md CHANGED
@@ -55,6 +55,7 @@ Extracted from production systems at Juspay and battle-tested at enterprise scal
55
55
  - **Structured Output with Zod Schemas** – Type-safe JSON generation with automatic validation using `schema` + `output.format: "json"` in `generate()`. → [Structured Output Guide](docs/features/structured-output.md)
56
56
  - **CSV File Support** – Attach CSV files to prompts for AI-powered data analysis with auto-detection. → [CSV Guide](docs/features/multimodal-chat.md#csv-file-support)
57
57
  - **PDF File Support** – Process PDF documents with native visual analysis for Vertex AI, Anthropic, Bedrock, AI Studio. → [PDF Guide](docs/features/pdf-support.md)
58
+ - **50+ File Types** – Process Excel, Word, RTF, JSON, YAML, XML, HTML, SVG, Markdown, and 50+ code languages with intelligent content extraction. → [File Processors Guide](docs/features/file-processors.md)
58
59
  - **LiteLLM Integration** – Access 100+ AI models from all major providers through unified interface. → [Setup Guide](docs/litellm-integration.md)
59
60
  - **SageMaker Integration** – Deploy and use custom trained models on AWS infrastructure. → [Setup Guide](docs/sagemaker-integration.md)
60
61
  - **OpenRouter Integration** – Access 300+ models from OpenAI, Anthropic, Google, Meta, and more through a single unified API. → [Setup Guide](docs/getting-started/providers/openrouter.md)
@@ -242,6 +243,48 @@ const result = await neurolink.generate({
242
243
 
243
244
  ---
244
245
 
246
+ ### 📁 Multimodal & File Processing
247
+
248
+ **17+ file categories supported** (50+ total file types including code languages) with intelligent content extraction and provider-agnostic processing:
249
+
250
+ | Category | Supported Types | Processing |
251
+ | ------------- | ---------------------------------------------------------- | ----------------------------------- |
252
+ | **Documents** | Excel (`.xlsx`, `.xls`), Word (`.docx`), RTF, OpenDocument | Sheet extraction, text extraction |
253
+ | **Data** | JSON, YAML, XML | Validation, syntax highlighting |
254
+ | **Markup** | HTML, SVG, Markdown, Text | OWASP-compliant sanitization |
255
+ | **Code** | 50+ languages (TypeScript, Python, Java, Go, etc.) | Language detection, syntax metadata |
256
+ | **Config** | `.env`, `.ini`, `.toml`, `.cfg` | Secure parsing |
257
+ | **Media** | Images (PNG, JPEG, WebP, GIF), PDFs, CSV | Provider-specific formatting |
258
+
259
+ ```typescript
260
+ // Process any supported file type
261
+ const result = await neurolink.generate({
262
+ input: {
263
+ text: "Analyze this data and code",
264
+ files: [
265
+ "./data.xlsx", // Excel spreadsheet
266
+ "./config.yaml", // YAML configuration
267
+ "./diagram.svg", // SVG (injected as sanitized text)
268
+ "./main.py", // Python source code
269
+ ],
270
+ },
271
+ });
272
+
273
+ // CLI: Use --file for any supported type
274
+ // neurolink generate "Analyze this" --file ./report.xlsx --file ./config.json
275
+ ```
276
+
277
+ **Key Features:**
278
+
279
+ - **ProcessorRegistry** - Priority-based processor selection with fallback
280
+ - **OWASP Security** - HTML/SVG sanitization prevents XSS attacks
281
+ - **Auto-detection** - FileDetector identifies file types by extension and content
282
+ - **Provider-agnostic** - All processors work across all 13 AI providers
283
+
284
+ **[📖 File Processors Guide](docs/features/file-processors.md)** - Complete reference for all file types
285
+
286
+ ---
287
+
245
288
  ### 🏢 Enterprise & Production Features
246
289
 
247
290
  **Production-ready capabilities for regulated industries:**
@@ -373,13 +416,13 @@ Run AI-powered workflows directly in GitHub Actions with 13 provider support and
373
416
  post_comment: true
374
417
  ```
375
418
 
376
- | Feature | Description |
377
- | ---------------------- | ----------------------------------------------- |
378
- | **Multi-Provider** | 13 providers with unified interface |
379
- | **PR/Issue Comments** | Auto-post AI responses with intelligent updates |
380
- | **Multimodal Support** | Attach images, PDFs, CSVs to prompts |
381
- | **Cost Tracking** | Built-in analytics and quality evaluation |
382
- | **Extended Thinking** | Deep reasoning with thinking tokens |
419
+ | Feature | Description |
420
+ | ---------------------- | ----------------------------------------------------------------------------------------- |
421
+ | **Multi-Provider** | 13 providers with unified interface |
422
+ | **PR/Issue Comments** | Auto-post AI responses with intelligent updates |
423
+ | **Multimodal Support** | Attach images, PDFs, CSVs, Excel, Word, JSON, YAML, XML, HTML, SVG, code files to prompts |
424
+ | **Cost Tracking** | Built-in analytics and quality evaluation |
425
+ | **Extended Thinking** | Deep reasoning with thinking tokens |
383
426
 
384
427
  **[📖 GitHub Action Guide](docs/guides/github-action.md)** - Complete setup and examples
385
428
 
@@ -506,6 +549,10 @@ const result = await neurolink.generate({
506
549
  "./sales_data.csv", // Auto-detected as CSV
507
550
  "examples/data/invoice.pdf", // Auto-detected as PDF
508
551
  "./diagrams/architecture.png", // Auto-detected as image
552
+ "./report.xlsx", // Auto-detected as Excel
553
+ "./config.json", // Auto-detected as JSON
554
+ "./diagram.svg", // Auto-detected as SVG (injected as text)
555
+ "./app.ts", // Auto-detected as TypeScript code
509
556
  ],
510
557
  },
511
558
  provider: "vertex", // PDF-capable provider (see docs/features/pdf-support.md)
@@ -219,12 +219,12 @@ export declare const directAgentTools: {
219
219
  content: z.ZodString;
220
220
  mode: z.ZodDefault<z.ZodEnum<["create", "overwrite", "append"]>>;
221
221
  }, "strip", z.ZodTypeAny, {
222
- content: string;
223
222
  path: string;
223
+ content: string;
224
224
  mode: "create" | "overwrite" | "append";
225
225
  }, {
226
- content: string;
227
226
  path: string;
227
+ content: string;
228
228
  mode?: "create" | "overwrite" | "append" | undefined;
229
229
  }>, {
230
230
  success: boolean;
@@ -249,8 +249,8 @@ export declare const directAgentTools: {
249
249
  written?: undefined;
250
250
  }> & {
251
251
  execute: (args: {
252
- content: string;
253
252
  path: string;
253
+ content: string;
254
254
  mode: "create" | "overwrite" | "append";
255
255
  }, options: import("ai").ToolExecutionOptions) => PromiseLike<{
256
256
  success: boolean;
@@ -54,17 +54,17 @@ declare const ConfigSchema: z.ZodObject<{
54
54
  location: string;
55
55
  projectId?: string | undefined;
56
56
  credentials?: string | undefined;
57
+ privateKey?: string | undefined;
57
58
  serviceAccountKey?: string | undefined;
58
59
  clientEmail?: string | undefined;
59
- privateKey?: string | undefined;
60
60
  }, {
61
61
  model?: string | undefined;
62
62
  projectId?: string | undefined;
63
63
  credentials?: string | undefined;
64
+ privateKey?: string | undefined;
64
65
  location?: string | undefined;
65
66
  serviceAccountKey?: string | undefined;
66
67
  clientEmail?: string | undefined;
67
- privateKey?: string | undefined;
68
68
  }>>;
69
69
  anthropic: z.ZodOptional<z.ZodObject<{
70
70
  apiKey: z.ZodOptional<z.ZodString>;
@@ -153,9 +153,9 @@ declare const ConfigSchema: z.ZodObject<{
153
153
  location: string;
154
154
  projectId?: string | undefined;
155
155
  credentials?: string | undefined;
156
+ privateKey?: string | undefined;
156
157
  serviceAccountKey?: string | undefined;
157
158
  clientEmail?: string | undefined;
158
- privateKey?: string | undefined;
159
159
  } | undefined;
160
160
  anthropic?: {
161
161
  model: string;
@@ -201,10 +201,10 @@ declare const ConfigSchema: z.ZodObject<{
201
201
  model?: string | undefined;
202
202
  projectId?: string | undefined;
203
203
  credentials?: string | undefined;
204
+ privateKey?: string | undefined;
204
205
  location?: string | undefined;
205
206
  serviceAccountKey?: string | undefined;
206
207
  clientEmail?: string | undefined;
207
- privateKey?: string | undefined;
208
208
  } | undefined;
209
209
  anthropic?: {
210
210
  model?: string | undefined;
@@ -473,9 +473,9 @@ declare const ConfigSchema: z.ZodObject<{
473
473
  location: string;
474
474
  projectId?: string | undefined;
475
475
  credentials?: string | undefined;
476
+ privateKey?: string | undefined;
476
477
  serviceAccountKey?: string | undefined;
477
478
  clientEmail?: string | undefined;
478
- privateKey?: string | undefined;
479
479
  } | undefined;
480
480
  anthropic?: {
481
481
  model: string;
@@ -570,10 +570,10 @@ declare const ConfigSchema: z.ZodObject<{
570
570
  model?: string | undefined;
571
571
  projectId?: string | undefined;
572
572
  credentials?: string | undefined;
573
+ privateKey?: string | undefined;
573
574
  location?: string | undefined;
574
575
  serviceAccountKey?: string | undefined;
575
576
  clientEmail?: string | undefined;
576
- privateKey?: string | undefined;
577
577
  } | undefined;
578
578
  anthropic?: {
579
579
  model?: string | undefined;
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Image Generation Service
3
+ *
4
+ * Handles AI image generation using NeuroLink SDK with configurable providers
5
+ * and models. Supports reference images and PDFs for contextual generation.
6
+ *
7
+ * @packageDocumentation
8
+ * @module @juspay/neurolink/image-gen
9
+ * @category ImageGeneration
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { ImageGenService } from '@juspay/neurolink';
14
+ *
15
+ * const service = new ImageGenService();
16
+ *
17
+ * const result = await service.generate({
18
+ * prompt: 'A serene mountain landscape at sunset',
19
+ * style: 'photorealistic',
20
+ * aspectRatio: '16:9'
21
+ * });
22
+ *
23
+ * if (result.success && result.imageBuffer) {
24
+ * fs.writeFileSync('output.png', result.imageBuffer);
25
+ * }
26
+ * ```
27
+ */
28
+ import type { ImageGenConfig, ImageGenOptions, ImageGenResult } from "./types.js";
29
+ /**
30
+ * Image generation service for AI-powered image creation
31
+ *
32
+ * Uses NeuroLink SDK to generate images with support for:
33
+ * - Multiple providers (Vertex AI, OpenAI, etc.)
34
+ * - Reference images for style guidance
35
+ * - PDF documents for contextual generation
36
+ * - Configurable aspect ratios and styles
37
+ *
38
+ * @example Basic usage
39
+ * ```typescript
40
+ * const service = new ImageGenService();
41
+ * const result = await service.generate({
42
+ * prompt: 'A cute robot playing chess'
43
+ * });
44
+ * ```
45
+ *
46
+ * @example With custom configuration
47
+ * ```typescript
48
+ * const service = new ImageGenService({
49
+ * defaultProvider: 'openai',
50
+ * defaultModel: 'dall-e-3',
51
+ * timeout: 60000
52
+ * });
53
+ * ```
54
+ */
55
+ export declare class ImageGenService {
56
+ private config;
57
+ private neurolinkInstance;
58
+ private instanceId;
59
+ /**
60
+ * Create a new ImageGenService instance
61
+ *
62
+ * @param config - Optional configuration overrides
63
+ */
64
+ constructor(config?: Partial<ImageGenConfig>);
65
+ /**
66
+ * Get or create the NeuroLink instance
67
+ * Uses dynamic import to avoid circular dependencies
68
+ *
69
+ * @returns NeuroLink instance for image generation
70
+ */
71
+ private getNeuroLink;
72
+ /**
73
+ * Generate an image from a text prompt
74
+ *
75
+ * @param options - Generation options including prompt, style, etc.
76
+ * @returns Promise resolving to generation result
77
+ *
78
+ * @example Simple generation
79
+ * ```typescript
80
+ * const result = await service.generate({
81
+ * prompt: 'A futuristic cityscape'
82
+ * });
83
+ * ```
84
+ *
85
+ * @example With reference images
86
+ * ```typescript
87
+ * const referenceImage = fs.readFileSync('style-reference.jpg');
88
+ * const result = await service.generate({
89
+ * prompt: 'A portrait in this style',
90
+ * images: [referenceImage],
91
+ * aspectRatio: '1:1'
92
+ * });
93
+ * ```
94
+ */
95
+ generate(options: ImageGenOptions): Promise<ImageGenResult>;
96
+ /**
97
+ * Extract image data from various result formats
98
+ *
99
+ * Handles multiple output formats:
100
+ * - result.imageOutput?.base64
101
+ * - result.images?.[0]
102
+ * - data:image URI in content
103
+ * - Buffer directly
104
+ *
105
+ * @param result - Raw result from NeuroLink generate
106
+ * @returns Extracted image data or null
107
+ */
108
+ private extractImageFromResult;
109
+ /**
110
+ * Check if image generation is enabled
111
+ */
112
+ isEnabled(): boolean;
113
+ /**
114
+ * Get the default model
115
+ */
116
+ getModel(): string;
117
+ /**
118
+ * Get the default provider
119
+ */
120
+ getProvider(): string;
121
+ /**
122
+ * Get the service configuration
123
+ */
124
+ getConfig(): Readonly<ImageGenConfig>;
125
+ /**
126
+ * Get the service instance ID (for debugging)
127
+ */
128
+ getInstanceId(): string;
129
+ /**
130
+ * Update service configuration
131
+ *
132
+ * @param config - Partial configuration to merge
133
+ */
134
+ updateConfig(config: Partial<ImageGenConfig>): void;
135
+ /**
136
+ * Enable image generation
137
+ */
138
+ enable(): void;
139
+ /**
140
+ * Disable image generation
141
+ */
142
+ disable(): void;
143
+ }
@@ -0,0 +1,345 @@
1
+ /**
2
+ * Image Generation Service
3
+ *
4
+ * Handles AI image generation using NeuroLink SDK with configurable providers
5
+ * and models. Supports reference images and PDFs for contextual generation.
6
+ *
7
+ * @packageDocumentation
8
+ * @module @juspay/neurolink/image-gen
9
+ * @category ImageGeneration
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { ImageGenService } from '@juspay/neurolink';
14
+ *
15
+ * const service = new ImageGenService();
16
+ *
17
+ * const result = await service.generate({
18
+ * prompt: 'A serene mountain landscape at sunset',
19
+ * style: 'photorealistic',
20
+ * aspectRatio: '16:9'
21
+ * });
22
+ *
23
+ * if (result.success && result.imageBuffer) {
24
+ * fs.writeFileSync('output.png', result.imageBuffer);
25
+ * }
26
+ * ```
27
+ */
28
+ import { withTimeout } from "../utils/errorHandling.js";
29
+ import { DEFAULT_IMAGE_GEN_CONFIG } from "./types.js";
30
+ /**
31
+ * Image generation service for AI-powered image creation
32
+ *
33
+ * Uses NeuroLink SDK to generate images with support for:
34
+ * - Multiple providers (Vertex AI, OpenAI, etc.)
35
+ * - Reference images for style guidance
36
+ * - PDF documents for contextual generation
37
+ * - Configurable aspect ratios and styles
38
+ *
39
+ * @example Basic usage
40
+ * ```typescript
41
+ * const service = new ImageGenService();
42
+ * const result = await service.generate({
43
+ * prompt: 'A cute robot playing chess'
44
+ * });
45
+ * ```
46
+ *
47
+ * @example With custom configuration
48
+ * ```typescript
49
+ * const service = new ImageGenService({
50
+ * defaultProvider: 'openai',
51
+ * defaultModel: 'dall-e-3',
52
+ * timeout: 60000
53
+ * });
54
+ * ```
55
+ */
56
+ export class ImageGenService {
57
+ config;
58
+ neurolinkInstance = null;
59
+ instanceId;
60
+ /**
61
+ * Create a new ImageGenService instance
62
+ *
63
+ * @param config - Optional configuration overrides
64
+ */
65
+ constructor(config) {
66
+ this.config = {
67
+ ...DEFAULT_IMAGE_GEN_CONFIG,
68
+ ...config,
69
+ };
70
+ this.instanceId = `ImageGenService-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
71
+ }
72
+ /**
73
+ * Get or create the NeuroLink instance
74
+ * Uses dynamic import to avoid circular dependencies
75
+ *
76
+ * @returns NeuroLink instance for image generation
77
+ */
78
+ async getNeuroLink() {
79
+ if (!this.neurolinkInstance) {
80
+ // Dynamically import to avoid circular dependencies
81
+ const { NeuroLink } = await import("../neurolink.js");
82
+ this.neurolinkInstance = new NeuroLink({
83
+ conversationMemory: { enabled: false },
84
+ enableOrchestration: false,
85
+ });
86
+ }
87
+ return this.neurolinkInstance;
88
+ }
89
+ /**
90
+ * Generate an image from a text prompt
91
+ *
92
+ * @param options - Generation options including prompt, style, etc.
93
+ * @returns Promise resolving to generation result
94
+ *
95
+ * @example Simple generation
96
+ * ```typescript
97
+ * const result = await service.generate({
98
+ * prompt: 'A futuristic cityscape'
99
+ * });
100
+ * ```
101
+ *
102
+ * @example With reference images
103
+ * ```typescript
104
+ * const referenceImage = fs.readFileSync('style-reference.jpg');
105
+ * const result = await service.generate({
106
+ * prompt: 'A portrait in this style',
107
+ * images: [referenceImage],
108
+ * aspectRatio: '1:1'
109
+ * });
110
+ * ```
111
+ */
112
+ async generate(options) {
113
+ const startTime = Date.now();
114
+ // Check if service is enabled
115
+ if (!this.config.enabled) {
116
+ return {
117
+ success: false,
118
+ error: "Image generation is disabled",
119
+ };
120
+ }
121
+ // Validate prompt
122
+ if (!options.prompt || options.prompt.trim().length === 0) {
123
+ return {
124
+ success: false,
125
+ error: "Prompt is required for image generation",
126
+ };
127
+ }
128
+ try {
129
+ const neurolink = await this.getNeuroLink();
130
+ // Build enhanced prompt with style and negative prompt
131
+ let enhancedPrompt = options.prompt;
132
+ if (options.style) {
133
+ enhancedPrompt = `${options.style} style: ${enhancedPrompt}`;
134
+ }
135
+ if (options.negativePrompt) {
136
+ enhancedPrompt = `${enhancedPrompt}. Avoid: ${options.negativePrompt}`;
137
+ }
138
+ // Build input with optional reference images/PDFs
139
+ const input = { text: enhancedPrompt };
140
+ // Process reference images
141
+ if (options.images?.length) {
142
+ const maxImages = this.config.maxReferenceImages ?? 5;
143
+ const imagesToUse = options.images.slice(0, maxImages);
144
+ // Convert Buffers to base64 strings if needed
145
+ input.images = imagesToUse.map((img) => Buffer.isBuffer(img) ? img.toString("base64") : img);
146
+ }
147
+ // Process reference PDFs
148
+ if (options.pdfFiles?.length) {
149
+ const maxPdfs = this.config.maxReferencePdfs ?? 1;
150
+ input.pdfFiles = options.pdfFiles.slice(0, maxPdfs);
151
+ }
152
+ // Determine provider and model
153
+ const provider = options.provider ?? this.config.defaultProvider;
154
+ const model = options.model ?? this.config.defaultModel;
155
+ const region = options.region ?? this.config.defaultRegion;
156
+ // Build generation parameters
157
+ const generateParams = {
158
+ input,
159
+ provider,
160
+ model,
161
+ disableTools: true,
162
+ temperature: options.temperature ?? this.config.defaultTemperature ?? 0.75,
163
+ timeout: this.config.timeout,
164
+ };
165
+ // Add region if specified (for Vertex AI)
166
+ if (region) {
167
+ generateParams.region = region;
168
+ }
169
+ // Add number of images
170
+ const maxImages = this.config.maxImages ?? 4;
171
+ const numberOfImages = Math.min(options.numberOfImages ?? 1, maxImages);
172
+ generateParams.numberOfImages = numberOfImages;
173
+ // Add aspect ratio if specified
174
+ if (options.aspectRatio) {
175
+ generateParams.aspectRatio = options.aspectRatio;
176
+ }
177
+ // Call NeuroLink generate with timeout protection
178
+ const result = await withTimeout(neurolink.generate(generateParams), this.config.timeout, new Error(`Image generation timed out after ${this.config.timeout}ms`));
179
+ // Extract image from result
180
+ const imageOutput = this.extractImageFromResult(result);
181
+ const generationTimeMs = Date.now() - startTime;
182
+ if (imageOutput) {
183
+ return {
184
+ success: true,
185
+ imageBuffer: imageOutput.imageBuffer,
186
+ base64: imageOutput.base64,
187
+ mimeType: imageOutput.mimeType,
188
+ model,
189
+ provider,
190
+ generationTimeMs,
191
+ };
192
+ }
193
+ return {
194
+ success: false,
195
+ error: "No image generated",
196
+ model,
197
+ provider,
198
+ generationTimeMs,
199
+ };
200
+ }
201
+ catch (error) {
202
+ const errorMessage = error instanceof Error ? error.message : String(error);
203
+ return {
204
+ success: false,
205
+ error: `Generation failed: ${errorMessage}`,
206
+ generationTimeMs: Date.now() - startTime,
207
+ };
208
+ }
209
+ }
210
+ /**
211
+ * Extract image data from various result formats
212
+ *
213
+ * Handles multiple output formats:
214
+ * - result.imageOutput?.base64
215
+ * - result.images?.[0]
216
+ * - data:image URI in content
217
+ * - Buffer directly
218
+ *
219
+ * @param result - Raw result from NeuroLink generate
220
+ * @returns Extracted image data or null
221
+ */
222
+ extractImageFromResult(result) {
223
+ if (!result || typeof result !== "object") {
224
+ return null;
225
+ }
226
+ const res = result;
227
+ // Check for imageOutput with base64
228
+ const imageOutput = res.imageOutput ?? res.images?.[0];
229
+ if (imageOutput && typeof imageOutput === "object") {
230
+ const img = imageOutput;
231
+ if (typeof img.base64 === "string") {
232
+ const base64 = img.base64;
233
+ const mimeType = img.mimeType ?? "image/png";
234
+ return {
235
+ imageBuffer: Buffer.from(base64, "base64"),
236
+ base64,
237
+ mimeType,
238
+ };
239
+ }
240
+ }
241
+ // Check if imageOutput is a Buffer
242
+ if (Buffer.isBuffer(imageOutput)) {
243
+ const base64 = imageOutput.toString("base64");
244
+ return {
245
+ imageBuffer: imageOutput,
246
+ base64,
247
+ mimeType: "image/png",
248
+ };
249
+ }
250
+ // Check for data URI format in content
251
+ const content = res.content;
252
+ if (typeof content === "string" && content.startsWith("data:image")) {
253
+ const match = content.match(/^data:image\/(\w+);base64,(.+)$/);
254
+ if (match?.[2]) {
255
+ const mimeType = `image/${match[1]}`;
256
+ const base64 = match[2];
257
+ return {
258
+ imageBuffer: Buffer.from(base64, "base64"),
259
+ base64,
260
+ mimeType,
261
+ };
262
+ }
263
+ }
264
+ // Check for raw base64 in content
265
+ if (typeof content === "string" && !content.startsWith("data:")) {
266
+ // Try to detect if it's base64 encoded image data
267
+ try {
268
+ const buffer = Buffer.from(content, "base64");
269
+ // Check for PNG magic bytes
270
+ if (buffer[0] === 0x89 && buffer[1] === 0x50) {
271
+ return {
272
+ imageBuffer: buffer,
273
+ base64: content,
274
+ mimeType: "image/png",
275
+ };
276
+ }
277
+ // Check for JPEG magic bytes
278
+ if (buffer[0] === 0xff && buffer[1] === 0xd8) {
279
+ return {
280
+ imageBuffer: buffer,
281
+ base64: content,
282
+ mimeType: "image/jpeg",
283
+ };
284
+ }
285
+ }
286
+ catch {
287
+ // Not valid base64, ignore
288
+ }
289
+ }
290
+ return null;
291
+ }
292
+ /**
293
+ * Check if image generation is enabled
294
+ */
295
+ isEnabled() {
296
+ return this.config.enabled;
297
+ }
298
+ /**
299
+ * Get the default model
300
+ */
301
+ getModel() {
302
+ return this.config.defaultModel;
303
+ }
304
+ /**
305
+ * Get the default provider
306
+ */
307
+ getProvider() {
308
+ return this.config.defaultProvider;
309
+ }
310
+ /**
311
+ * Get the service configuration
312
+ */
313
+ getConfig() {
314
+ return { ...this.config };
315
+ }
316
+ /**
317
+ * Get the service instance ID (for debugging)
318
+ */
319
+ getInstanceId() {
320
+ return this.instanceId;
321
+ }
322
+ /**
323
+ * Update service configuration
324
+ *
325
+ * @param config - Partial configuration to merge
326
+ */
327
+ updateConfig(config) {
328
+ this.config = {
329
+ ...this.config,
330
+ ...config,
331
+ };
332
+ }
333
+ /**
334
+ * Enable image generation
335
+ */
336
+ enable() {
337
+ this.config.enabled = true;
338
+ }
339
+ /**
340
+ * Disable image generation
341
+ */
342
+ disable() {
343
+ this.config.enabled = false;
344
+ }
345
+ }