@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.
- package/CHANGELOG.md +12 -0
- package/README.md +54 -7
- package/dist/agent/directTools.d.ts +3 -3
- package/dist/cli/commands/config.d.ts +6 -6
- package/dist/image-gen/ImageGenService.d.ts +143 -0
- package/dist/image-gen/ImageGenService.js +345 -0
- package/dist/image-gen/imageGenTools.d.ts +126 -0
- package/dist/image-gen/imageGenTools.js +304 -0
- package/dist/image-gen/index.d.ts +46 -0
- package/dist/image-gen/index.js +48 -0
- package/dist/image-gen/types.d.ts +237 -0
- package/dist/image-gen/types.js +24 -0
- package/dist/lib/agent/directTools.d.ts +3 -3
- package/dist/lib/image-gen/ImageGenService.d.ts +143 -0
- package/dist/lib/image-gen/ImageGenService.js +346 -0
- package/dist/lib/image-gen/imageGenTools.d.ts +126 -0
- package/dist/lib/image-gen/imageGenTools.js +305 -0
- package/dist/lib/image-gen/index.d.ts +46 -0
- package/dist/lib/image-gen/index.js +49 -0
- package/dist/lib/image-gen/types.d.ts +237 -0
- package/dist/lib/image-gen/types.js +25 -0
- package/dist/lib/processors/base/BaseFileProcessor.d.ts +273 -0
- package/dist/lib/processors/base/BaseFileProcessor.js +614 -0
- package/dist/lib/processors/base/index.d.ts +14 -0
- package/dist/lib/processors/base/index.js +20 -0
- package/dist/lib/processors/base/types.d.ts +593 -0
- package/dist/lib/processors/base/types.js +77 -0
- package/dist/lib/processors/cli/fileProcessorCli.d.ts +163 -0
- package/dist/lib/processors/cli/fileProcessorCli.js +389 -0
- package/dist/lib/processors/cli/index.d.ts +37 -0
- package/dist/lib/processors/cli/index.js +50 -0
- package/dist/lib/processors/code/ConfigProcessor.d.ts +171 -0
- package/dist/lib/processors/code/ConfigProcessor.js +401 -0
- package/dist/lib/processors/code/SourceCodeProcessor.d.ts +174 -0
- package/dist/lib/processors/code/SourceCodeProcessor.js +305 -0
- package/dist/lib/processors/code/index.d.ts +44 -0
- package/dist/lib/processors/code/index.js +61 -0
- package/dist/lib/processors/config/fileTypes.d.ts +283 -0
- package/dist/lib/processors/config/fileTypes.js +521 -0
- package/dist/lib/processors/config/index.d.ts +32 -0
- package/dist/lib/processors/config/index.js +93 -0
- package/dist/lib/processors/config/languageMap.d.ts +66 -0
- package/dist/lib/processors/config/languageMap.js +411 -0
- package/dist/lib/processors/config/mimeTypes.d.ts +376 -0
- package/dist/lib/processors/config/mimeTypes.js +339 -0
- package/dist/lib/processors/config/sizeLimits.d.ts +194 -0
- package/dist/lib/processors/config/sizeLimits.js +247 -0
- package/dist/lib/processors/data/JsonProcessor.d.ts +122 -0
- package/dist/lib/processors/data/JsonProcessor.js +204 -0
- package/dist/lib/processors/data/XmlProcessor.d.ts +160 -0
- package/dist/lib/processors/data/XmlProcessor.js +284 -0
- package/dist/lib/processors/data/YamlProcessor.d.ts +163 -0
- package/dist/lib/processors/data/YamlProcessor.js +295 -0
- package/dist/lib/processors/data/index.d.ts +49 -0
- package/dist/lib/processors/data/index.js +77 -0
- package/dist/lib/processors/document/ExcelProcessor.d.ts +238 -0
- package/dist/lib/processors/document/ExcelProcessor.js +520 -0
- package/dist/lib/processors/document/OpenDocumentProcessor.d.ts +69 -0
- package/dist/lib/processors/document/OpenDocumentProcessor.js +211 -0
- package/dist/lib/processors/document/RtfProcessor.d.ts +152 -0
- package/dist/lib/processors/document/RtfProcessor.js +362 -0
- package/dist/lib/processors/document/WordProcessor.d.ts +168 -0
- package/dist/lib/processors/document/WordProcessor.js +354 -0
- package/dist/lib/processors/document/index.d.ts +54 -0
- package/dist/lib/processors/document/index.js +91 -0
- package/dist/lib/processors/errors/FileErrorCode.d.ts +98 -0
- package/dist/lib/processors/errors/FileErrorCode.js +256 -0
- package/dist/lib/processors/errors/errorHelpers.d.ts +151 -0
- package/dist/lib/processors/errors/errorHelpers.js +379 -0
- package/dist/lib/processors/errors/errorSerializer.d.ts +139 -0
- package/dist/lib/processors/errors/errorSerializer.js +508 -0
- package/dist/lib/processors/errors/index.d.ts +46 -0
- package/dist/lib/processors/errors/index.js +50 -0
- package/dist/lib/processors/index.d.ts +76 -0
- package/dist/lib/processors/index.js +113 -0
- package/dist/lib/processors/integration/FileProcessorIntegration.d.ts +244 -0
- package/dist/lib/processors/integration/FileProcessorIntegration.js +273 -0
- package/dist/lib/processors/integration/index.d.ts +42 -0
- package/dist/lib/processors/integration/index.js +45 -0
- package/dist/lib/processors/markup/HtmlProcessor.d.ts +169 -0
- package/dist/lib/processors/markup/HtmlProcessor.js +250 -0
- package/dist/lib/processors/markup/MarkdownProcessor.d.ts +165 -0
- package/dist/lib/processors/markup/MarkdownProcessor.js +245 -0
- package/dist/lib/processors/markup/SvgProcessor.d.ts +156 -0
- package/dist/lib/processors/markup/SvgProcessor.js +241 -0
- package/dist/lib/processors/markup/TextProcessor.d.ts +135 -0
- package/dist/lib/processors/markup/TextProcessor.js +189 -0
- package/dist/lib/processors/markup/index.d.ts +66 -0
- package/dist/lib/processors/markup/index.js +103 -0
- package/dist/lib/processors/registry/ProcessorRegistry.d.ts +334 -0
- package/dist/lib/processors/registry/ProcessorRegistry.js +609 -0
- package/dist/lib/processors/registry/index.d.ts +12 -0
- package/dist/lib/processors/registry/index.js +17 -0
- package/dist/lib/processors/registry/types.d.ts +53 -0
- package/dist/lib/processors/registry/types.js +11 -0
- package/dist/lib/providers/sagemaker/language-model.d.ts +2 -2
- package/dist/lib/server/utils/validation.d.ts +6 -6
- package/dist/lib/types/fileTypes.d.ts +51 -1
- package/dist/lib/types/index.d.ts +25 -24
- package/dist/lib/types/index.js +21 -20
- package/dist/lib/types/modelTypes.d.ts +18 -18
- package/dist/lib/types/pptTypes.d.ts +14 -2
- package/dist/lib/types/pptTypes.js +16 -0
- package/dist/lib/utils/async/delay.d.ts +40 -0
- package/dist/lib/utils/async/delay.js +43 -0
- package/dist/lib/utils/async/index.d.ts +23 -0
- package/dist/lib/utils/async/index.js +24 -0
- package/dist/lib/utils/async/retry.d.ts +141 -0
- package/dist/lib/utils/async/retry.js +172 -0
- package/dist/lib/utils/async/withTimeout.d.ts +73 -0
- package/dist/lib/utils/async/withTimeout.js +97 -0
- package/dist/lib/utils/csvProcessor.js +442 -0
- package/dist/lib/utils/fileDetector.d.ts +7 -1
- package/dist/lib/utils/fileDetector.js +91 -18
- package/dist/lib/utils/json/extract.d.ts +103 -0
- package/dist/lib/utils/json/extract.js +249 -0
- package/dist/lib/utils/json/index.d.ts +36 -0
- package/dist/lib/utils/json/index.js +37 -0
- package/dist/lib/utils/json/safeParse.d.ts +137 -0
- package/dist/lib/utils/json/safeParse.js +191 -0
- package/dist/lib/utils/messageBuilder.d.ts +2 -2
- package/dist/lib/utils/messageBuilder.js +15 -7
- package/dist/lib/utils/sanitizers/filename.d.ts +137 -0
- package/dist/lib/utils/sanitizers/filename.js +366 -0
- package/dist/lib/utils/sanitizers/html.d.ts +170 -0
- package/dist/lib/utils/sanitizers/html.js +326 -0
- package/dist/lib/utils/sanitizers/index.d.ts +26 -0
- package/dist/lib/utils/sanitizers/index.js +30 -0
- package/dist/lib/utils/sanitizers/svg.d.ts +81 -0
- package/dist/lib/utils/sanitizers/svg.js +483 -0
- package/dist/processors/base/BaseFileProcessor.d.ts +273 -0
- package/dist/processors/base/BaseFileProcessor.js +613 -0
- package/dist/processors/base/index.d.ts +14 -0
- package/dist/processors/base/index.js +19 -0
- package/dist/processors/base/types.d.ts +593 -0
- package/dist/processors/base/types.js +76 -0
- package/dist/processors/cli/fileProcessorCli.d.ts +163 -0
- package/dist/processors/cli/fileProcessorCli.js +388 -0
- package/dist/processors/cli/index.d.ts +37 -0
- package/dist/processors/cli/index.js +49 -0
- package/dist/processors/code/ConfigProcessor.d.ts +171 -0
- package/dist/processors/code/ConfigProcessor.js +400 -0
- package/dist/processors/code/SourceCodeProcessor.d.ts +174 -0
- package/dist/processors/code/SourceCodeProcessor.js +304 -0
- package/dist/processors/code/index.d.ts +44 -0
- package/dist/processors/code/index.js +60 -0
- package/dist/processors/config/fileTypes.d.ts +283 -0
- package/dist/processors/config/fileTypes.js +520 -0
- package/dist/processors/config/index.d.ts +32 -0
- package/dist/processors/config/index.js +92 -0
- package/dist/processors/config/languageMap.d.ts +66 -0
- package/dist/processors/config/languageMap.js +410 -0
- package/dist/processors/config/mimeTypes.d.ts +376 -0
- package/dist/processors/config/mimeTypes.js +338 -0
- package/dist/processors/config/sizeLimits.d.ts +194 -0
- package/dist/processors/config/sizeLimits.js +246 -0
- package/dist/processors/data/JsonProcessor.d.ts +122 -0
- package/dist/processors/data/JsonProcessor.js +203 -0
- package/dist/processors/data/XmlProcessor.d.ts +160 -0
- package/dist/processors/data/XmlProcessor.js +283 -0
- package/dist/processors/data/YamlProcessor.d.ts +163 -0
- package/dist/processors/data/YamlProcessor.js +294 -0
- package/dist/processors/data/index.d.ts +49 -0
- package/dist/processors/data/index.js +76 -0
- package/dist/processors/document/ExcelProcessor.d.ts +238 -0
- package/dist/processors/document/ExcelProcessor.js +519 -0
- package/dist/processors/document/OpenDocumentProcessor.d.ts +69 -0
- package/dist/processors/document/OpenDocumentProcessor.js +210 -0
- package/dist/processors/document/RtfProcessor.d.ts +152 -0
- package/dist/processors/document/RtfProcessor.js +361 -0
- package/dist/processors/document/WordProcessor.d.ts +168 -0
- package/dist/processors/document/WordProcessor.js +353 -0
- package/dist/processors/document/index.d.ts +54 -0
- package/dist/processors/document/index.js +90 -0
- package/dist/processors/errors/FileErrorCode.d.ts +98 -0
- package/dist/processors/errors/FileErrorCode.js +255 -0
- package/dist/processors/errors/errorHelpers.d.ts +151 -0
- package/dist/processors/errors/errorHelpers.js +378 -0
- package/dist/processors/errors/errorSerializer.d.ts +139 -0
- package/dist/processors/errors/errorSerializer.js +507 -0
- package/dist/processors/errors/index.d.ts +46 -0
- package/dist/processors/errors/index.js +49 -0
- package/dist/processors/index.d.ts +76 -0
- package/dist/processors/index.js +112 -0
- package/dist/processors/integration/FileProcessorIntegration.d.ts +244 -0
- package/dist/processors/integration/FileProcessorIntegration.js +272 -0
- package/dist/processors/integration/index.d.ts +42 -0
- package/dist/processors/integration/index.js +44 -0
- package/dist/processors/markup/HtmlProcessor.d.ts +169 -0
- package/dist/processors/markup/HtmlProcessor.js +249 -0
- package/dist/processors/markup/MarkdownProcessor.d.ts +165 -0
- package/dist/processors/markup/MarkdownProcessor.js +244 -0
- package/dist/processors/markup/SvgProcessor.d.ts +156 -0
- package/dist/processors/markup/SvgProcessor.js +240 -0
- package/dist/processors/markup/TextProcessor.d.ts +135 -0
- package/dist/processors/markup/TextProcessor.js +188 -0
- package/dist/processors/markup/index.d.ts +66 -0
- package/dist/processors/markup/index.js +102 -0
- package/dist/processors/registry/ProcessorRegistry.d.ts +334 -0
- package/dist/processors/registry/ProcessorRegistry.js +608 -0
- package/dist/processors/registry/index.d.ts +12 -0
- package/dist/processors/registry/index.js +16 -0
- package/dist/processors/registry/types.d.ts +53 -0
- package/dist/processors/registry/types.js +10 -0
- package/dist/server/utils/validation.d.ts +6 -6
- package/dist/types/fileTypes.d.ts +51 -1
- package/dist/types/index.d.ts +25 -24
- package/dist/types/index.js +21 -20
- package/dist/types/modelTypes.d.ts +10 -10
- package/dist/types/pptTypes.d.ts +14 -2
- package/dist/types/pptTypes.js +16 -0
- package/dist/utils/async/delay.d.ts +40 -0
- package/dist/utils/async/delay.js +42 -0
- package/dist/utils/async/index.d.ts +23 -0
- package/dist/utils/async/index.js +23 -0
- package/dist/utils/async/retry.d.ts +141 -0
- package/dist/utils/async/retry.js +171 -0
- package/dist/utils/async/withTimeout.d.ts +73 -0
- package/dist/utils/async/withTimeout.js +96 -0
- package/dist/utils/csvProcessor.js +442 -0
- package/dist/utils/fileDetector.d.ts +7 -1
- package/dist/utils/fileDetector.js +91 -18
- package/dist/utils/json/extract.d.ts +103 -0
- package/dist/utils/json/extract.js +248 -0
- package/dist/utils/json/index.d.ts +36 -0
- package/dist/utils/json/index.js +36 -0
- package/dist/utils/json/safeParse.d.ts +137 -0
- package/dist/utils/json/safeParse.js +190 -0
- package/dist/utils/messageBuilder.d.ts +2 -2
- package/dist/utils/messageBuilder.js +15 -7
- package/dist/utils/sanitizers/filename.d.ts +137 -0
- package/dist/utils/sanitizers/filename.js +365 -0
- package/dist/utils/sanitizers/html.d.ts +170 -0
- package/dist/utils/sanitizers/html.js +325 -0
- package/dist/utils/sanitizers/index.d.ts +26 -0
- package/dist/utils/sanitizers/index.js +29 -0
- package/dist/utils/sanitizers/svg.d.ts +81 -0
- package/dist/utils/sanitizers/svg.js +482 -0
- package/package.json +2 -2
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image Generation Tools
|
|
3
|
+
*
|
|
4
|
+
* Tool definitions for AI model use - enables AI models to generate
|
|
5
|
+
* images as part of their response workflow.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
* @module @juspay/neurolink/image-gen
|
|
9
|
+
* @category ImageGeneration
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { getImageGenTools } from '@juspay/neurolink';
|
|
14
|
+
*
|
|
15
|
+
* // Get tools for AI model registration
|
|
16
|
+
* const tools = getImageGenTools();
|
|
17
|
+
*
|
|
18
|
+
* // Use with NeuroLink
|
|
19
|
+
* const neurolink = new NeuroLink();
|
|
20
|
+
* neurolink.registerCustomTools(tools);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
import { ImageGenService } from "./ImageGenService.js";
|
|
24
|
+
import type { ImageGenConfig, ImageGenToolContext, ImageGenToolParams, ImageGenToolResponse } from "./types.js";
|
|
25
|
+
/**
|
|
26
|
+
* Tool definition interface compatible with AI SDK / MCP
|
|
27
|
+
*/
|
|
28
|
+
export interface ImageGenToolDefinition {
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
inputSchema: {
|
|
32
|
+
type: "object";
|
|
33
|
+
properties: Record<string, {
|
|
34
|
+
type: string;
|
|
35
|
+
description: string;
|
|
36
|
+
enum?: string[];
|
|
37
|
+
}>;
|
|
38
|
+
required: string[];
|
|
39
|
+
};
|
|
40
|
+
execute: (params: ImageGenToolParams, context?: ImageGenToolContext) => Promise<ImageGenToolResponse>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create an image generation tool for use with AI models
|
|
44
|
+
*
|
|
45
|
+
* This tool allows AI models to generate images based on text prompts.
|
|
46
|
+
* It integrates with the ImageGenService for actual generation.
|
|
47
|
+
*
|
|
48
|
+
* @param service - ImageGenService instance to use
|
|
49
|
+
* @returns Tool definition compatible with MCP/AI SDK
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const service = new ImageGenService();
|
|
54
|
+
* const tool = createImageGenTool(service);
|
|
55
|
+
*
|
|
56
|
+
* // Tool can now be registered with NeuroLink
|
|
57
|
+
* neurolink.registerTool(tool.name, {
|
|
58
|
+
* description: tool.description,
|
|
59
|
+
* parameters: tool.inputSchema,
|
|
60
|
+
* execute: tool.execute
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function createImageGenTool(service: ImageGenService): ImageGenToolDefinition;
|
|
65
|
+
/**
|
|
66
|
+
* Create an image editing/variation tool for use with AI models
|
|
67
|
+
*
|
|
68
|
+
* This tool allows AI models to create variations of existing images
|
|
69
|
+
* or edit images based on reference images and prompts.
|
|
70
|
+
*
|
|
71
|
+
* @param service - ImageGenService instance to use
|
|
72
|
+
* @returns Tool definition compatible with MCP/AI SDK
|
|
73
|
+
*/
|
|
74
|
+
export declare function createImageVariationTool(service: ImageGenService): ImageGenToolDefinition;
|
|
75
|
+
/**
|
|
76
|
+
* Get all image generation tools as an array
|
|
77
|
+
*
|
|
78
|
+
* Creates a shared ImageGenService instance and returns all
|
|
79
|
+
* image generation tools configured to use it.
|
|
80
|
+
*
|
|
81
|
+
* @param config - Optional configuration for the ImageGenService
|
|
82
|
+
* @returns Array of tool definitions
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* import { getImageGenTools, NeuroLink } from '@juspay/neurolink';
|
|
87
|
+
*
|
|
88
|
+
* const tools = getImageGenTools({
|
|
89
|
+
* defaultProvider: 'openai',
|
|
90
|
+
* defaultModel: 'dall-e-3'
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* const neurolink = new NeuroLink();
|
|
94
|
+
* for (const tool of tools) {
|
|
95
|
+
* neurolink.registerTool(tool.name, {
|
|
96
|
+
* description: tool.description,
|
|
97
|
+
* parameters: tool.inputSchema,
|
|
98
|
+
* execute: tool.execute
|
|
99
|
+
* });
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function getImageGenTools(configOrService?: Partial<ImageGenConfig> | ImageGenService): ImageGenToolDefinition[];
|
|
104
|
+
/**
|
|
105
|
+
* Get only the basic image generation tool
|
|
106
|
+
*
|
|
107
|
+
* @param config - Optional configuration for the ImageGenService
|
|
108
|
+
* @returns Single tool definition for basic image generation
|
|
109
|
+
*/
|
|
110
|
+
export declare function getBasicImageGenTool(configOrService?: Partial<ImageGenConfig> | ImageGenService): ImageGenToolDefinition;
|
|
111
|
+
/**
|
|
112
|
+
* Create a custom image generation tool with specific service configuration
|
|
113
|
+
*
|
|
114
|
+
* @param serviceConfig - Configuration for the ImageGenService
|
|
115
|
+
* @param toolConfig - Optional customizations for the tool definition
|
|
116
|
+
* @returns Customized tool definition
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const customTool = createCustomImageGenTool(
|
|
121
|
+
* { defaultProvider: 'vertex', defaultModel: 'imagen-3.0-generate-001' },
|
|
122
|
+
* { name: 'vertex_generate_image', description: 'Generate images using Vertex AI Imagen' }
|
|
123
|
+
* );
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function createCustomImageGenTool(serviceConfig?: Partial<ImageGenConfig>, toolConfig?: Partial<Pick<ImageGenToolDefinition, "name" | "description">>): ImageGenToolDefinition;
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image Generation Tools
|
|
3
|
+
*
|
|
4
|
+
* Tool definitions for AI model use - enables AI models to generate
|
|
5
|
+
* images as part of their response workflow.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
* @module @juspay/neurolink/image-gen
|
|
9
|
+
* @category ImageGeneration
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { getImageGenTools } from '@juspay/neurolink';
|
|
14
|
+
*
|
|
15
|
+
* // Get tools for AI model registration
|
|
16
|
+
* const tools = getImageGenTools();
|
|
17
|
+
*
|
|
18
|
+
* // Use with NeuroLink
|
|
19
|
+
* const neurolink = new NeuroLink();
|
|
20
|
+
* neurolink.registerCustomTools(tools);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
import { ImageGenService } from "./ImageGenService.js";
|
|
24
|
+
/**
|
|
25
|
+
* Create an image generation tool for use with AI models
|
|
26
|
+
*
|
|
27
|
+
* This tool allows AI models to generate images based on text prompts.
|
|
28
|
+
* It integrates with the ImageGenService for actual generation.
|
|
29
|
+
*
|
|
30
|
+
* @param service - ImageGenService instance to use
|
|
31
|
+
* @returns Tool definition compatible with MCP/AI SDK
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const service = new ImageGenService();
|
|
36
|
+
* const tool = createImageGenTool(service);
|
|
37
|
+
*
|
|
38
|
+
* // Tool can now be registered with NeuroLink
|
|
39
|
+
* neurolink.registerTool(tool.name, {
|
|
40
|
+
* description: tool.description,
|
|
41
|
+
* parameters: tool.inputSchema,
|
|
42
|
+
* execute: tool.execute
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function createImageGenTool(service) {
|
|
47
|
+
return {
|
|
48
|
+
name: "generate_image",
|
|
49
|
+
description: `Generate an image from a text prompt using AI. Use this tool to create images, illustrations, diagrams, or visual content based on detailed descriptions.
|
|
50
|
+
|
|
51
|
+
Tips for better prompts:
|
|
52
|
+
- Be specific and detailed about what you want
|
|
53
|
+
- Include style preferences (photorealistic, cartoon, watercolor, etc.)
|
|
54
|
+
- Mention colors, lighting, and composition if important
|
|
55
|
+
- Describe the mood or atmosphere desired
|
|
56
|
+
|
|
57
|
+
The tool returns the generated image as a data URI that can be displayed or saved.`,
|
|
58
|
+
inputSchema: {
|
|
59
|
+
type: "object",
|
|
60
|
+
properties: {
|
|
61
|
+
prompt: {
|
|
62
|
+
type: "string",
|
|
63
|
+
description: "Detailed description of the image to generate. Be specific about content, style, colors, and composition for best results.",
|
|
64
|
+
},
|
|
65
|
+
negativePrompt: {
|
|
66
|
+
type: "string",
|
|
67
|
+
description: "What to avoid in the generated image (optional). E.g., 'blurry, low quality, text, watermarks'",
|
|
68
|
+
},
|
|
69
|
+
aspectRatio: {
|
|
70
|
+
type: "string",
|
|
71
|
+
description: "Aspect ratio for the image (optional). Common values: '1:1' (square), '16:9' (widescreen), '9:16' (portrait), '4:3', '3:2'",
|
|
72
|
+
enum: ["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3"],
|
|
73
|
+
},
|
|
74
|
+
style: {
|
|
75
|
+
type: "string",
|
|
76
|
+
description: "Style preset for the image (optional). E.g., 'realistic', 'photorealistic', 'artistic', 'cartoon', 'anime', 'watercolor', 'oil-painting', 'sketch', 'digital-art', '3d-render'",
|
|
77
|
+
enum: [
|
|
78
|
+
"realistic",
|
|
79
|
+
"photorealistic",
|
|
80
|
+
"artistic",
|
|
81
|
+
"cartoon",
|
|
82
|
+
"anime",
|
|
83
|
+
"watercolor",
|
|
84
|
+
"oil-painting",
|
|
85
|
+
"sketch",
|
|
86
|
+
"digital-art",
|
|
87
|
+
"3d-render",
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
required: ["prompt"],
|
|
92
|
+
},
|
|
93
|
+
execute: async (params, context) => {
|
|
94
|
+
// Check if service is enabled
|
|
95
|
+
if (!service.isEnabled()) {
|
|
96
|
+
return {
|
|
97
|
+
success: false,
|
|
98
|
+
message: "Image generation is disabled on this server",
|
|
99
|
+
error: "IMAGE_GEN_DISABLED",
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
// Build generation options
|
|
104
|
+
const result = await service.generate({
|
|
105
|
+
prompt: params.prompt,
|
|
106
|
+
negativePrompt: params.negativePrompt,
|
|
107
|
+
aspectRatio: params.aspectRatio,
|
|
108
|
+
style: params.style,
|
|
109
|
+
images: context?.referenceImages,
|
|
110
|
+
pdfFiles: context?.referencePdfs,
|
|
111
|
+
});
|
|
112
|
+
if (result.success && result.base64) {
|
|
113
|
+
const mimeType = result.mimeType ?? "image/png";
|
|
114
|
+
return {
|
|
115
|
+
success: true,
|
|
116
|
+
image: `data:${mimeType};base64,${result.base64}`,
|
|
117
|
+
message: `Image generated successfully using ${result.model ?? "default model"}`,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
success: false,
|
|
122
|
+
message: result.error ?? "Failed to generate image",
|
|
123
|
+
error: result.error ?? "GENERATION_FAILED",
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
128
|
+
return {
|
|
129
|
+
success: false,
|
|
130
|
+
message: `Image generation failed: ${errorMessage}`,
|
|
131
|
+
error: errorMessage,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Create an image editing/variation tool for use with AI models
|
|
139
|
+
*
|
|
140
|
+
* This tool allows AI models to create variations of existing images
|
|
141
|
+
* or edit images based on reference images and prompts.
|
|
142
|
+
*
|
|
143
|
+
* @param service - ImageGenService instance to use
|
|
144
|
+
* @returns Tool definition compatible with MCP/AI SDK
|
|
145
|
+
*/
|
|
146
|
+
export function createImageVariationTool(service) {
|
|
147
|
+
return {
|
|
148
|
+
name: "create_image_variation",
|
|
149
|
+
description: `Create a variation or modification of an existing image. Use this when you need to:
|
|
150
|
+
- Create variations of a reference image
|
|
151
|
+
- Modify an existing image based on a description
|
|
152
|
+
- Generate images in a similar style to a reference
|
|
153
|
+
|
|
154
|
+
Note: Requires reference images to be provided in the context.`,
|
|
155
|
+
inputSchema: {
|
|
156
|
+
type: "object",
|
|
157
|
+
properties: {
|
|
158
|
+
prompt: {
|
|
159
|
+
type: "string",
|
|
160
|
+
description: "Description of the desired variation or modification. Describe what changes you want from the reference.",
|
|
161
|
+
},
|
|
162
|
+
style: {
|
|
163
|
+
type: "string",
|
|
164
|
+
description: "Style to apply to the variation (optional)",
|
|
165
|
+
enum: [
|
|
166
|
+
"realistic",
|
|
167
|
+
"photorealistic",
|
|
168
|
+
"artistic",
|
|
169
|
+
"cartoon",
|
|
170
|
+
"anime",
|
|
171
|
+
"watercolor",
|
|
172
|
+
"oil-painting",
|
|
173
|
+
"sketch",
|
|
174
|
+
"digital-art",
|
|
175
|
+
"3d-render",
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
aspectRatio: {
|
|
179
|
+
type: "string",
|
|
180
|
+
description: "Aspect ratio for the output (optional)",
|
|
181
|
+
enum: ["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3"],
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
required: ["prompt"],
|
|
185
|
+
},
|
|
186
|
+
execute: async (params, context) => {
|
|
187
|
+
// Check if service is enabled
|
|
188
|
+
if (!service.isEnabled()) {
|
|
189
|
+
return {
|
|
190
|
+
success: false,
|
|
191
|
+
message: "Image generation is disabled on this server",
|
|
192
|
+
error: "IMAGE_GEN_DISABLED",
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
// Require reference images for variations
|
|
196
|
+
if (!context?.referenceImages?.length) {
|
|
197
|
+
return {
|
|
198
|
+
success: false,
|
|
199
|
+
message: "No reference images provided. This tool requires reference images to create variations.",
|
|
200
|
+
error: "NO_REFERENCE_IMAGES",
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
const result = await service.generate({
|
|
205
|
+
prompt: `Create a variation based on the reference image(s): ${params.prompt}`,
|
|
206
|
+
style: params.style,
|
|
207
|
+
aspectRatio: params.aspectRatio,
|
|
208
|
+
images: context.referenceImages,
|
|
209
|
+
pdfFiles: context.referencePdfs,
|
|
210
|
+
});
|
|
211
|
+
if (result.success && result.base64) {
|
|
212
|
+
const mimeType = result.mimeType ?? "image/png";
|
|
213
|
+
return {
|
|
214
|
+
success: true,
|
|
215
|
+
image: `data:${mimeType};base64,${result.base64}`,
|
|
216
|
+
message: "Image variation created successfully",
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
success: false,
|
|
221
|
+
message: result.error ?? "Failed to create image variation",
|
|
222
|
+
error: result.error ?? "VARIATION_FAILED",
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
227
|
+
return {
|
|
228
|
+
success: false,
|
|
229
|
+
message: `Image variation failed: ${errorMessage}`,
|
|
230
|
+
error: errorMessage,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get all image generation tools as an array
|
|
238
|
+
*
|
|
239
|
+
* Creates a shared ImageGenService instance and returns all
|
|
240
|
+
* image generation tools configured to use it.
|
|
241
|
+
*
|
|
242
|
+
* @param config - Optional configuration for the ImageGenService
|
|
243
|
+
* @returns Array of tool definitions
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* import { getImageGenTools, NeuroLink } from '@juspay/neurolink';
|
|
248
|
+
*
|
|
249
|
+
* const tools = getImageGenTools({
|
|
250
|
+
* defaultProvider: 'openai',
|
|
251
|
+
* defaultModel: 'dall-e-3'
|
|
252
|
+
* });
|
|
253
|
+
*
|
|
254
|
+
* const neurolink = new NeuroLink();
|
|
255
|
+
* for (const tool of tools) {
|
|
256
|
+
* neurolink.registerTool(tool.name, {
|
|
257
|
+
* description: tool.description,
|
|
258
|
+
* parameters: tool.inputSchema,
|
|
259
|
+
* execute: tool.execute
|
|
260
|
+
* });
|
|
261
|
+
* }
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
export function getImageGenTools(configOrService) {
|
|
265
|
+
const service = configOrService instanceof ImageGenService
|
|
266
|
+
? configOrService
|
|
267
|
+
: new ImageGenService(configOrService);
|
|
268
|
+
return [createImageGenTool(service), createImageVariationTool(service)];
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Get only the basic image generation tool
|
|
272
|
+
*
|
|
273
|
+
* @param config - Optional configuration for the ImageGenService
|
|
274
|
+
* @returns Single tool definition for basic image generation
|
|
275
|
+
*/
|
|
276
|
+
export function getBasicImageGenTool(configOrService) {
|
|
277
|
+
const service = configOrService instanceof ImageGenService
|
|
278
|
+
? configOrService
|
|
279
|
+
: new ImageGenService(configOrService);
|
|
280
|
+
return createImageGenTool(service);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Create a custom image generation tool with specific service configuration
|
|
284
|
+
*
|
|
285
|
+
* @param serviceConfig - Configuration for the ImageGenService
|
|
286
|
+
* @param toolConfig - Optional customizations for the tool definition
|
|
287
|
+
* @returns Customized tool definition
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```typescript
|
|
291
|
+
* const customTool = createCustomImageGenTool(
|
|
292
|
+
* { defaultProvider: 'vertex', defaultModel: 'imagen-3.0-generate-001' },
|
|
293
|
+
* { name: 'vertex_generate_image', description: 'Generate images using Vertex AI Imagen' }
|
|
294
|
+
* );
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
export function createCustomImageGenTool(serviceConfig, toolConfig) {
|
|
298
|
+
const service = new ImageGenService(serviceConfig);
|
|
299
|
+
const baseTool = createImageGenTool(service);
|
|
300
|
+
return {
|
|
301
|
+
...baseTool,
|
|
302
|
+
...toolConfig,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image Generation Module
|
|
3
|
+
*
|
|
4
|
+
* AI-powered image generation with support for multiple providers,
|
|
5
|
+
* reference images, and configurable styles.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
* @module @juspay/neurolink/image-gen
|
|
9
|
+
* @category ImageGeneration
|
|
10
|
+
*
|
|
11
|
+
* @example Basic usage
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { ImageGenService } from '@juspay/neurolink';
|
|
14
|
+
*
|
|
15
|
+
* const service = new ImageGenService();
|
|
16
|
+
* const result = await service.generate({
|
|
17
|
+
* prompt: 'A beautiful sunset over mountains',
|
|
18
|
+
* style: 'photorealistic'
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* if (result.success) {
|
|
22
|
+
* console.log('Generated image:', result.base64?.substring(0, 50) + '...');
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example With AI tools
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { getImageGenTools, NeuroLink } from '@juspay/neurolink';
|
|
29
|
+
*
|
|
30
|
+
* const tools = getImageGenTools();
|
|
31
|
+
* const neurolink = new NeuroLink();
|
|
32
|
+
*
|
|
33
|
+
* // Register tools for AI model use
|
|
34
|
+
* for (const tool of tools) {
|
|
35
|
+
* neurolink.registerTool(tool.name, {
|
|
36
|
+
* description: tool.description,
|
|
37
|
+
* parameters: tool.inputSchema,
|
|
38
|
+
* execute: tool.execute
|
|
39
|
+
* });
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export { ImageGenService } from "./ImageGenService.js";
|
|
44
|
+
export type { ImageGenToolDefinition } from "./imageGenTools.js";
|
|
45
|
+
export { createCustomImageGenTool, createImageGenTool, createImageVariationTool, getBasicImageGenTool, getImageGenTools, } from "./imageGenTools.js";
|
|
46
|
+
export * from "./types.js";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image Generation Module
|
|
3
|
+
*
|
|
4
|
+
* AI-powered image generation with support for multiple providers,
|
|
5
|
+
* reference images, and configurable styles.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
* @module @juspay/neurolink/image-gen
|
|
9
|
+
* @category ImageGeneration
|
|
10
|
+
*
|
|
11
|
+
* @example Basic usage
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { ImageGenService } from '@juspay/neurolink';
|
|
14
|
+
*
|
|
15
|
+
* const service = new ImageGenService();
|
|
16
|
+
* const result = await service.generate({
|
|
17
|
+
* prompt: 'A beautiful sunset over mountains',
|
|
18
|
+
* style: 'photorealistic'
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* if (result.success) {
|
|
22
|
+
* console.log('Generated image:', result.base64?.substring(0, 50) + '...');
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example With AI tools
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { getImageGenTools, NeuroLink } from '@juspay/neurolink';
|
|
29
|
+
*
|
|
30
|
+
* const tools = getImageGenTools();
|
|
31
|
+
* const neurolink = new NeuroLink();
|
|
32
|
+
*
|
|
33
|
+
* // Register tools for AI model use
|
|
34
|
+
* for (const tool of tools) {
|
|
35
|
+
* neurolink.registerTool(tool.name, {
|
|
36
|
+
* description: tool.description,
|
|
37
|
+
* parameters: tool.inputSchema,
|
|
38
|
+
* execute: tool.execute
|
|
39
|
+
* });
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
// Export service
|
|
44
|
+
export { ImageGenService } from "./ImageGenService.js";
|
|
45
|
+
// Export tools
|
|
46
|
+
export { createCustomImageGenTool, createImageGenTool, createImageVariationTool, getBasicImageGenTool, getImageGenTools, } from "./imageGenTools.js";
|
|
47
|
+
// Export types
|
|
48
|
+
export * from "./types.js";
|