mcp-image 0.1.0 → 0.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/README.md +41 -17
- package/dist/api/geminiClient.d.ts +2 -12
- package/dist/api/geminiClient.d.ts.map +1 -1
- package/dist/api/geminiClient.js +28 -56
- package/dist/api/geminiClient.js.map +1 -1
- package/dist/api/geminiTextClient.d.ts +42 -0
- package/dist/api/geminiTextClient.d.ts.map +1 -0
- package/dist/api/geminiTextClient.js +198 -0
- package/dist/api/geminiTextClient.js.map +1 -0
- package/dist/business/__tests__/mocks/mcpSamplingClient.mock.d.ts +84 -0
- package/dist/business/__tests__/mocks/mcpSamplingClient.mock.d.ts.map +1 -0
- package/dist/business/__tests__/mocks/mcpSamplingClient.mock.js +100 -0
- package/dist/business/__tests__/mocks/mcpSamplingClient.mock.js.map +1 -0
- package/dist/business/bestPracticesEngine.d.ts +149 -0
- package/dist/business/bestPracticesEngine.d.ts.map +1 -0
- package/dist/business/bestPracticesEngine.js +781 -0
- package/dist/business/bestPracticesEngine.js.map +1 -0
- package/dist/business/complexityAssessment.d.ts +132 -0
- package/dist/business/complexityAssessment.d.ts.map +1 -0
- package/dist/business/complexityAssessment.js +488 -0
- package/dist/business/complexityAssessment.js.map +1 -0
- package/dist/business/fallbackStrategies.d.ts +177 -0
- package/dist/business/fallbackStrategies.d.ts.map +1 -0
- package/dist/business/fallbackStrategies.js +368 -0
- package/dist/business/fallbackStrategies.js.map +1 -0
- package/dist/business/imageGenerator.d.ts.map +1 -1
- package/dist/business/imageGenerator.js +26 -5
- package/dist/business/imageGenerator.js.map +1 -1
- package/dist/business/multiImage/aspectRatioController.d.ts +77 -0
- package/dist/business/multiImage/aspectRatioController.d.ts.map +1 -0
- package/dist/business/multiImage/aspectRatioController.js +580 -0
- package/dist/business/multiImage/aspectRatioController.js.map +1 -0
- package/dist/business/multiImage/multiImageCoordinator.d.ts +142 -0
- package/dist/business/multiImage/multiImageCoordinator.d.ts.map +1 -0
- package/dist/business/multiImage/multiImageCoordinator.js +801 -0
- package/dist/business/multiImage/multiImageCoordinator.js.map +1 -0
- package/dist/business/pomlTemplateEngine.d.ts +206 -0
- package/dist/business/pomlTemplateEngine.d.ts.map +1 -0
- package/dist/business/pomlTemplateEngine.js +737 -0
- package/dist/business/pomlTemplateEngine.js.map +1 -0
- package/dist/business/promptOrchestrator.d.ts +173 -0
- package/dist/business/promptOrchestrator.d.ts.map +1 -0
- package/dist/business/promptOrchestrator.js +490 -0
- package/dist/business/promptOrchestrator.js.map +1 -0
- package/dist/business/responseBuilder.d.ts +2 -2
- package/dist/business/responseBuilder.d.ts.map +1 -1
- package/dist/business/responseBuilder.js +6 -1
- package/dist/business/responseBuilder.js.map +1 -1
- package/dist/business/structuredPromptGenerator.d.ts +54 -0
- package/dist/business/structuredPromptGenerator.d.ts.map +1 -0
- package/dist/business/structuredPromptGenerator.js +208 -0
- package/dist/business/structuredPromptGenerator.js.map +1 -0
- package/dist/business/templateNormalizer.d.ts +81 -0
- package/dist/business/templateNormalizer.d.ts.map +1 -0
- package/dist/business/templateNormalizer.js +659 -0
- package/dist/business/templateNormalizer.js.map +1 -0
- package/dist/documentation/apiContractValidation.d.ts +62 -0
- package/dist/documentation/apiContractValidation.d.ts.map +1 -0
- package/dist/documentation/apiContractValidation.js +305 -0
- package/dist/documentation/apiContractValidation.js.map +1 -0
- package/dist/infrastructure/concurrency/concurrencyManager.d.ts +101 -0
- package/dist/infrastructure/concurrency/concurrencyManager.d.ts.map +1 -0
- package/dist/infrastructure/concurrency/concurrencyManager.js +345 -0
- package/dist/infrastructure/concurrency/concurrencyManager.js.map +1 -0
- package/dist/infrastructure/config/secureConfigManager.d.ts +319 -0
- package/dist/infrastructure/config/secureConfigManager.d.ts.map +1 -0
- package/dist/infrastructure/config/secureConfigManager.js +600 -0
- package/dist/infrastructure/config/secureConfigManager.js.map +1 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandler.d.ts +229 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandler.d.ts.map +1 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandler.js +61 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandler.js.map +1 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandlerImpl.d.ts +133 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandlerImpl.d.ts.map +1 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandlerImpl.js +569 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandlerImpl.js.map +1 -0
- package/dist/infrastructure/mcp/MCPSamplingClient.d.ts +19 -0
- package/dist/infrastructure/mcp/MCPSamplingClient.d.ts.map +1 -0
- package/dist/infrastructure/mcp/MCPSamplingClient.js +31 -0
- package/dist/infrastructure/mcp/MCPSamplingClient.js.map +1 -0
- package/dist/infrastructure/mcp/RealMCPSamplingClient.d.ts +59 -0
- package/dist/infrastructure/mcp/RealMCPSamplingClient.d.ts.map +1 -0
- package/dist/infrastructure/mcp/RealMCPSamplingClient.js +271 -0
- package/dist/infrastructure/mcp/RealMCPSamplingClient.js.map +1 -0
- package/dist/infrastructure/metadata/generationMetadata.d.ts +72 -0
- package/dist/infrastructure/metadata/generationMetadata.d.ts.map +1 -0
- package/dist/infrastructure/metadata/generationMetadata.js +228 -0
- package/dist/infrastructure/metadata/generationMetadata.js.map +1 -0
- package/dist/infrastructure/monitoring/OrchestrationMetrics.d.ts +106 -0
- package/dist/infrastructure/monitoring/OrchestrationMetrics.d.ts.map +1 -0
- package/dist/infrastructure/monitoring/OrchestrationMetrics.js +456 -0
- package/dist/infrastructure/monitoring/OrchestrationMetrics.js.map +1 -0
- package/dist/infrastructure/monitoring/alertingSystem.d.ts +135 -0
- package/dist/infrastructure/monitoring/alertingSystem.d.ts.map +1 -0
- package/dist/infrastructure/monitoring/alertingSystem.js +549 -0
- package/dist/infrastructure/monitoring/alertingSystem.js.map +1 -0
- package/dist/infrastructure/optimization/performanceOptimizer.d.ts +89 -0
- package/dist/infrastructure/optimization/performanceOptimizer.d.ts.map +1 -0
- package/dist/infrastructure/optimization/performanceOptimizer.js +375 -0
- package/dist/infrastructure/optimization/performanceOptimizer.js.map +1 -0
- package/dist/infrastructure/security/AdvancedContentFilter.d.ts +99 -0
- package/dist/infrastructure/security/AdvancedContentFilter.d.ts.map +1 -0
- package/dist/infrastructure/security/AdvancedContentFilter.js +363 -0
- package/dist/infrastructure/security/AdvancedContentFilter.js.map +1 -0
- package/dist/infrastructure/security/MCPSecurityValidator.d.ts +62 -0
- package/dist/infrastructure/security/MCPSecurityValidator.d.ts.map +1 -0
- package/dist/infrastructure/security/MCPSecurityValidator.js +129 -0
- package/dist/infrastructure/security/MCPSecurityValidator.js.map +1 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddleware.d.ts +304 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddleware.d.ts.map +1 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddleware.js +61 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddleware.js.map +1 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddlewareImpl.d.ts +62 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddlewareImpl.d.ts.map +1 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddlewareImpl.js +591 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddlewareImpl.js.map +1 -0
- package/dist/infrastructure/security/SecureMCPClient.d.ts +154 -0
- package/dist/infrastructure/security/SecureMCPClient.d.ts.map +1 -0
- package/dist/infrastructure/security/SecureMCPClient.js +292 -0
- package/dist/infrastructure/security/SecureMCPClient.js.map +1 -0
- package/dist/infrastructure/security/SecurityIncidentManager.d.ts +142 -0
- package/dist/infrastructure/security/SecurityIncidentManager.d.ts.map +1 -0
- package/dist/infrastructure/security/SecurityIncidentManager.js +260 -0
- package/dist/infrastructure/security/SecurityIncidentManager.js.map +1 -0
- package/dist/infrastructure/security/apiKeyManager.d.ts +297 -0
- package/dist/infrastructure/security/apiKeyManager.d.ts.map +1 -0
- package/dist/infrastructure/security/apiKeyManager.js +254 -0
- package/dist/infrastructure/security/apiKeyManager.js.map +1 -0
- package/dist/infrastructure/security/dataSanitizer.d.ts +157 -0
- package/dist/infrastructure/security/dataSanitizer.d.ts.map +1 -0
- package/dist/infrastructure/security/dataSanitizer.js +525 -0
- package/dist/infrastructure/security/dataSanitizer.js.map +1 -0
- package/dist/infrastructure/validation/inputValidator.d.ts +54 -0
- package/dist/infrastructure/validation/inputValidator.d.ts.map +1 -0
- package/dist/infrastructure/validation/inputValidator.js +362 -0
- package/dist/infrastructure/validation/inputValidator.js.map +1 -0
- package/dist/integration/parameterOptimizer.d.ts +69 -0
- package/dist/integration/parameterOptimizer.d.ts.map +1 -0
- package/dist/integration/parameterOptimizer.js +317 -0
- package/dist/integration/parameterOptimizer.js.map +1 -0
- package/dist/integration/twoStageProcessor.d.ts +66 -0
- package/dist/integration/twoStageProcessor.d.ts.map +1 -0
- package/dist/integration/twoStageProcessor.js +348 -0
- package/dist/integration/twoStageProcessor.js.map +1 -0
- package/dist/server/handlers/structuredPromptHandler.d.ts +65 -0
- package/dist/server/handlers/structuredPromptHandler.d.ts.map +1 -0
- package/dist/server/handlers/structuredPromptHandler.js +314 -0
- package/dist/server/handlers/structuredPromptHandler.js.map +1 -0
- package/dist/server/mcpServer.d.ts +16 -35
- package/dist/server/mcpServer.d.ts.map +1 -1
- package/dist/server/mcpServer.js +111 -150
- package/dist/server/mcpServer.js.map +1 -1
- package/dist/server/mcpServerWithOrchestration.d.ts +98 -0
- package/dist/server/mcpServerWithOrchestration.d.ts.map +1 -0
- package/dist/server/mcpServerWithOrchestration.js +284 -0
- package/dist/server/mcpServerWithOrchestration.js.map +1 -0
- package/dist/types/mcpOrchestrationTypes.d.ts +135 -0
- package/dist/types/mcpOrchestrationTypes.d.ts.map +1 -0
- package/dist/types/mcpOrchestrationTypes.js +28 -0
- package/dist/types/mcpOrchestrationTypes.js.map +1 -0
- package/dist/types/multiImageTypes.d.ts +328 -0
- package/dist/types/multiImageTypes.d.ts.map +1 -0
- package/dist/types/multiImageTypes.js +27 -0
- package/dist/types/multiImageTypes.js.map +1 -0
- package/dist/types/performanceTypes.d.ts +300 -0
- package/dist/types/performanceTypes.d.ts.map +1 -0
- package/dist/types/performanceTypes.js +50 -0
- package/dist/types/performanceTypes.js.map +1 -0
- package/dist/types/twoStageTypes.d.ts +123 -0
- package/dist/types/twoStageTypes.d.ts.map +1 -0
- package/dist/types/twoStageTypes.js +7 -0
- package/dist/types/twoStageTypes.js.map +1 -0
- package/dist/utils/config.d.ts +1 -0
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +1 -0
- package/dist/utils/config.js.map +1 -1
- package/package.json +11 -4
- package/vitest.config.mjs +0 -47
package/README.md
CHANGED
|
@@ -5,7 +5,13 @@ A powerful MCP (Model Context Protocol) server that enables AI assistants to gen
|
|
|
5
5
|
## ✨ Features
|
|
6
6
|
|
|
7
7
|
- **AI-Powered Image Generation**: Create images from text prompts using Gemini 2.5 Flash Image Preview
|
|
8
|
+
- **Intelligent Prompt Enhancement**: Automatically optimizes your prompts using Gemini 2.0 Flash for superior image quality
|
|
9
|
+
- Adds photographic and artistic details
|
|
10
|
+
- Enriches lighting, composition, and atmosphere descriptions
|
|
11
|
+
- Preserves your intent while maximizing generation quality
|
|
8
12
|
- **Image Editing**: Transform existing images with natural language instructions
|
|
13
|
+
- Context-aware editing that preserves original style
|
|
14
|
+
- Maintains visual consistency with source image
|
|
9
15
|
- **Advanced Options**:
|
|
10
16
|
- Multi-image blending for composite scenes
|
|
11
17
|
- Character consistency across generations
|
|
@@ -36,19 +42,19 @@ claude mcp add mcp-image --env GEMINI_API_KEY=your-api-key --env IMAGE_OUTPUT_DI
|
|
|
36
42
|
|
|
37
43
|
#### For Cursor
|
|
38
44
|
|
|
39
|
-
Add to your Cursor settings
|
|
45
|
+
Add to your Cursor settings:
|
|
46
|
+
- **Global** (all projects): `~/.cursor/mcp.json`
|
|
47
|
+
- **Project-specific**: `.cursor/mcp.json` in your project root
|
|
40
48
|
|
|
41
49
|
```json
|
|
42
50
|
{
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
"IMAGE_OUTPUT_DIR": "/absolute/path/to/images"
|
|
51
|
-
}
|
|
51
|
+
"mcpServers": {
|
|
52
|
+
"mcp-image": {
|
|
53
|
+
"command": "npx",
|
|
54
|
+
"args": ["-y", "mcp-image"],
|
|
55
|
+
"env": {
|
|
56
|
+
"GEMINI_API_KEY": "your_gemini_api_key_here",
|
|
57
|
+
"IMAGE_OUTPUT_DIR": "/absolute/path/to/images"
|
|
52
58
|
}
|
|
53
59
|
}
|
|
54
60
|
}
|
|
@@ -62,6 +68,18 @@ Add to your Cursor settings (`~/.cursor/mcp.json`):
|
|
|
62
68
|
- Defaults to `./output` in the current working directory if not specified
|
|
63
69
|
- Directory will be created automatically if it doesn't exist
|
|
64
70
|
|
|
71
|
+
### Optional: Skip Prompt Enhancement
|
|
72
|
+
|
|
73
|
+
Set `SKIP_PROMPT_ENHANCEMENT=true` to disable automatic prompt optimization and send your prompts directly to the image generator. Useful when you need full control over the exact prompt wording.
|
|
74
|
+
|
|
75
|
+
**Claude Code:**
|
|
76
|
+
```bash
|
|
77
|
+
claude mcp add mcp-image --env GEMINI_API_KEY=your-api-key --env SKIP_PROMPT_ENHANCEMENT=true -- npx -y mcp-image
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Cursor:**
|
|
81
|
+
Add `"SKIP_PROMPT_ENHANCEMENT": "true"` to the env section in your config.
|
|
82
|
+
|
|
65
83
|
## 📖 Usage Examples
|
|
66
84
|
|
|
67
85
|
Once configured, your AI assistant can generate images using natural language:
|
|
@@ -72,6 +90,8 @@ Once configured, your AI assistant can generate images using natural language:
|
|
|
72
90
|
"Generate a serene mountain landscape at sunset with a lake reflection"
|
|
73
91
|
```
|
|
74
92
|
|
|
93
|
+
The system automatically enhances this to include rich details about lighting, materials, composition, and atmosphere for optimal results.
|
|
94
|
+
|
|
75
95
|
### Image Editing
|
|
76
96
|
|
|
77
97
|
```
|
|
@@ -79,7 +99,6 @@ Once configured, your AI assistant can generate images using natural language:
|
|
|
79
99
|
(with inputImagePath: "/path/to/image.jpg")
|
|
80
100
|
```
|
|
81
101
|
|
|
82
|
-
|
|
83
102
|
### Advanced Features
|
|
84
103
|
|
|
85
104
|
```
|
|
@@ -91,7 +110,9 @@ Once configured, your AI assistant can generate images using natural language:
|
|
|
91
110
|
|
|
92
111
|
### `generate_image` Tool
|
|
93
112
|
|
|
94
|
-
The MCP server exposes a single tool for all image operations:
|
|
113
|
+
The MCP server exposes a single tool for all image operations. Internally, it uses a two-stage process:
|
|
114
|
+
1. **Prompt Optimization**: Gemini 2.0 Flash analyzes and enriches your prompt
|
|
115
|
+
2. **Image Generation**: Gemini 2.5 Flash Image Preview creates the final image
|
|
95
116
|
|
|
96
117
|
#### Parameters
|
|
97
118
|
|
|
@@ -142,17 +163,20 @@ The MCP server exposes a single tool for all image operations:
|
|
|
142
163
|
|
|
143
164
|
### Performance Tips
|
|
144
165
|
|
|
145
|
-
- Image generation: 30-60 seconds typical
|
|
146
|
-
- Image editing: 15-45 seconds typical
|
|
147
|
-
-
|
|
166
|
+
- Image generation: 30-60 seconds typical (includes prompt optimization)
|
|
167
|
+
- Image editing: 15-45 seconds typical (includes context analysis)
|
|
168
|
+
- Simple prompts work great - the AI automatically adds professional details
|
|
169
|
+
- Complex prompts are preserved and further enhanced
|
|
148
170
|
- Consider enabling `useWorldKnowledge` for historical or factual subjects
|
|
149
171
|
|
|
150
|
-
|
|
151
172
|
## 💰 Usage Notes
|
|
152
173
|
|
|
153
|
-
- This MCP server uses the paid Gemini API for image generation
|
|
174
|
+
- This MCP server uses the paid Gemini API for both prompt optimization and image generation
|
|
175
|
+
- Gemini 2.0 Flash for intelligent prompt enhancement (minimal token usage)
|
|
176
|
+
- Gemini 2.5 Flash Image Preview for actual image generation
|
|
154
177
|
- Check current pricing and rate limits at [Google AI Studio](https://aistudio.google.com/)
|
|
155
178
|
- Monitor your API usage to avoid unexpected charges
|
|
179
|
+
- The prompt optimization step adds minimal cost while significantly improving output quality
|
|
156
180
|
|
|
157
181
|
## 📄 License
|
|
158
182
|
|
|
@@ -15,23 +15,13 @@ export interface GeminiGenerationMetadata {
|
|
|
15
15
|
mimeType: string;
|
|
16
16
|
timestamp: Date;
|
|
17
17
|
inputImageProvided: boolean;
|
|
18
|
-
contextMethod: string;
|
|
19
|
-
/** Features usage metadata */
|
|
20
|
-
features?: {
|
|
21
|
-
blendImages: boolean;
|
|
22
|
-
maintainCharacterConsistency: boolean;
|
|
23
|
-
useWorldKnowledge: boolean;
|
|
24
|
-
};
|
|
25
18
|
}
|
|
26
19
|
/**
|
|
27
|
-
* Parameters for Gemini API image generation
|
|
20
|
+
* Parameters for Gemini API image generation
|
|
28
21
|
*/
|
|
29
22
|
export interface GeminiApiParams {
|
|
30
23
|
prompt: string;
|
|
31
|
-
inputImage?:
|
|
32
|
-
blendImages?: boolean;
|
|
33
|
-
maintainCharacterConsistency?: boolean;
|
|
34
|
-
useWorldKnowledge?: boolean;
|
|
24
|
+
inputImage?: string;
|
|
35
25
|
}
|
|
36
26
|
/**
|
|
37
27
|
* Result of image generation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geminiClient.d.ts","sourceRoot":"","sources":["../../src/api/geminiClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAE7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"geminiClient.d.ts","sourceRoot":"","sources":["../../src/api/geminiClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAE7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AA2C9D;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,IAAI,CAAA;IACf,kBAAkB,EAAE,OAAO,CAAA;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,wBAAwB,CAAA;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,aAAa,CACX,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,cAAc,GAAG,YAAY,CAAC,CAAC,CAAA;CACxE;AAkND;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,YAAY,EAAE,cAAc,CAAC,CAevF"}
|
package/dist/api/geminiClient.js
CHANGED
|
@@ -9,10 +9,6 @@ exports.createGeminiClient = createGeminiClient;
|
|
|
9
9
|
const genai_1 = require("@google/genai");
|
|
10
10
|
const result_1 = require("../types/result");
|
|
11
11
|
const errors_1 = require("../utils/errors");
|
|
12
|
-
/**
|
|
13
|
-
* URL pattern for automatic URL detection
|
|
14
|
-
*/
|
|
15
|
-
const URL_PATTERN = /https?:\/\/(?:[-\w.])+(?:\.[a-zA-Z]{2,})+(?:\/[-\w._~:\/?#[\]@!$&'()*+,;=]*)?/g;
|
|
16
12
|
/**
|
|
17
13
|
* Implementation of Gemini API client
|
|
18
14
|
*/
|
|
@@ -23,44 +19,39 @@ class GeminiClientImpl {
|
|
|
23
19
|
}
|
|
24
20
|
async generateImage(params) {
|
|
25
21
|
try {
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
if (params.maintainCharacterConsistency) {
|
|
30
|
-
enhancedPrompt +=
|
|
31
|
-
' [INSTRUCTION: Maintain exact character appearance, including facial features, hairstyle, clothing, and all physical characteristics consistent throughout the image]';
|
|
32
|
-
}
|
|
33
|
-
if (params.blendImages) {
|
|
34
|
-
enhancedPrompt +=
|
|
35
|
-
' [INSTRUCTION: Seamlessly blend multiple visual elements into a natural, cohesive composition with smooth transitions]';
|
|
36
|
-
}
|
|
37
|
-
if (params.useWorldKnowledge) {
|
|
38
|
-
enhancedPrompt +=
|
|
39
|
-
' [INSTRUCTION: Apply accurate real-world knowledge including historical facts, geographical accuracy, cultural contexts, and realistic depictions]';
|
|
40
|
-
}
|
|
41
|
-
// Prepare the request content with enhanced prompt
|
|
42
|
-
const requestContent = [enhancedPrompt];
|
|
43
|
-
// Add input image if provided
|
|
22
|
+
// Prepare the request content with proper structure for multimodal input
|
|
23
|
+
const requestContent = [];
|
|
24
|
+
// Structure the contents properly for image generation/editing
|
|
44
25
|
if (params.inputImage) {
|
|
26
|
+
// For image editing: provide image first, then text instructions
|
|
45
27
|
requestContent.push({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
28
|
+
parts: [
|
|
29
|
+
{
|
|
30
|
+
inlineData: {
|
|
31
|
+
data: params.inputImage,
|
|
32
|
+
mimeType: 'image/jpeg', // TODO: Dynamic MIME type support
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
text: params.prompt,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
50
39
|
});
|
|
51
40
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
41
|
+
else {
|
|
42
|
+
// For text-to-image: provide only text prompt
|
|
43
|
+
requestContent.push({
|
|
44
|
+
parts: [
|
|
45
|
+
{
|
|
46
|
+
text: params.prompt,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// Generate content using Gemini API (@google/genai v1.17.0+)
|
|
60
52
|
const response = await this.genai.models.generateContent({
|
|
61
53
|
model: this.modelName,
|
|
62
54
|
contents: requestContent,
|
|
63
|
-
config,
|
|
64
55
|
});
|
|
65
56
|
// Extract image data from response
|
|
66
57
|
if (!response || typeof response !== 'object') {
|
|
@@ -91,25 +82,14 @@ class GeminiClientImpl {
|
|
|
91
82
|
// Convert base64 image data to Buffer
|
|
92
83
|
const imageBuffer = Buffer.from(imagePart.inlineData.data, 'base64');
|
|
93
84
|
const mimeType = imagePart.inlineData.mimeType || 'image/png';
|
|
94
|
-
// Create metadata
|
|
85
|
+
// Create simplified metadata
|
|
95
86
|
const metadata = {
|
|
96
87
|
model: this.modelName,
|
|
97
|
-
prompt: params.prompt,
|
|
88
|
+
prompt: params.prompt,
|
|
98
89
|
mimeType,
|
|
99
90
|
timestamp: new Date(),
|
|
100
91
|
inputImageProvided: !!params.inputImage,
|
|
101
|
-
contextMethod: 'prompt_only',
|
|
102
92
|
};
|
|
103
|
-
// Add features usage information if any features are specified (including false)
|
|
104
|
-
if (params.blendImages !== undefined ||
|
|
105
|
-
params.maintainCharacterConsistency !== undefined ||
|
|
106
|
-
params.useWorldKnowledge !== undefined) {
|
|
107
|
-
metadata.features = {
|
|
108
|
-
blendImages: params.blendImages || false,
|
|
109
|
-
maintainCharacterConsistency: params.maintainCharacterConsistency || false,
|
|
110
|
-
useWorldKnowledge: params.useWorldKnowledge || false,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
93
|
return (0, result_1.Ok)({
|
|
114
94
|
imageData: imageBuffer,
|
|
115
95
|
metadata,
|
|
@@ -165,14 +145,6 @@ class GeminiClientImpl {
|
|
|
165
145
|
}
|
|
166
146
|
return undefined;
|
|
167
147
|
}
|
|
168
|
-
/**
|
|
169
|
-
* Detect URLs in prompt for automatic URL Context activation
|
|
170
|
-
* @param prompt The prompt text to analyze
|
|
171
|
-
* @returns True if URLs are detected, false otherwise
|
|
172
|
-
*/
|
|
173
|
-
detectUrls(prompt) {
|
|
174
|
-
return URL_PATTERN.test(prompt);
|
|
175
|
-
}
|
|
176
148
|
}
|
|
177
149
|
/**
|
|
178
150
|
* Creates a new Gemini API client
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geminiClient.js","sourceRoot":"","sources":["../../src/api/geminiClient.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;
|
|
1
|
+
{"version":3,"file":"geminiClient.js","sourceRoot":"","sources":["../../src/api/geminiClient.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AA0SH,gDAeC;AAvTD,yCAA2C;AAE3C,4CAAyC;AAEzC,4CAA8D;AA+E9D;;GAEG;AACH,MAAM,gBAAgB;IAGpB,YAA6B,KAA2B;QAA3B,UAAK,GAAL,KAAK,CAAsB;QAFvC,cAAS,GAAG,gCAAgC,CAAA;IAEF,CAAC;IAE5D,KAAK,CAAC,aAAa,CACjB,MAAuB;QAEvB,IAAI,CAAC;YACH,yEAAyE;YACzE,MAAM,cAAc,GAAc,EAAE,CAAA;YAEpC,+DAA+D;YAC/D,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;gBACtB,iEAAiE;gBACjE,cAAc,CAAC,IAAI,CAAC;oBAClB,KAAK,EAAE;wBACL;4BACE,UAAU,EAAE;gCACV,IAAI,EAAE,MAAM,CAAC,UAAU;gCACvB,QAAQ,EAAE,YAAY,EAAE,kCAAkC;6BAC3D;yBACF;wBACD;4BACE,IAAI,EAAE,MAAM,CAAC,MAAM;yBACpB;qBACF;iBACF,CAAC,CAAA;YACJ,CAAC;iBAAM,CAAC;gBACN,8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AAO,IAAA,YAAG,EACR,IAAI,uBAAc,CAChB,uCAAuC,YAAY,EAAE,EACrD,yFAAyF,CAC1F,CACF,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gemini Text Client for text generation using Gemini 2.0 Flash
|
|
3
|
+
* Pure API client for interacting with Google AI Studio
|
|
4
|
+
* Handles text generation without any prompt optimization logic
|
|
5
|
+
*/
|
|
6
|
+
import type { Result } from '../types/result';
|
|
7
|
+
import type { Config } from '../utils/config';
|
|
8
|
+
import { GeminiAPIError, NetworkError } from '../utils/errors';
|
|
9
|
+
/**
|
|
10
|
+
* Options for text generation
|
|
11
|
+
*/
|
|
12
|
+
export interface GenerationConfig {
|
|
13
|
+
temperature?: number;
|
|
14
|
+
maxTokens?: number;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
systemInstruction?: string;
|
|
17
|
+
inputImage?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Interface for Gemini Text Client - pure API client
|
|
21
|
+
*/
|
|
22
|
+
export interface GeminiTextClient {
|
|
23
|
+
/**
|
|
24
|
+
* Generate text using Gemini 2.0 Flash API
|
|
25
|
+
* @param prompt The prompt to send to the API
|
|
26
|
+
* @param config Optional configuration for generation
|
|
27
|
+
* @returns Result containing generated text or error
|
|
28
|
+
*/
|
|
29
|
+
generateText(prompt: string, config?: GenerationConfig): Promise<Result<string, GeminiAPIError | NetworkError>>;
|
|
30
|
+
/**
|
|
31
|
+
* Validate connection to Gemini 2.0 Flash API
|
|
32
|
+
* @returns Result indicating if connection is successful
|
|
33
|
+
*/
|
|
34
|
+
validateConnection(): Promise<Result<boolean, GeminiAPIError | NetworkError>>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new Gemini Text Client for prompt generation
|
|
38
|
+
* @param config Configuration containing API key and settings
|
|
39
|
+
* @returns Result containing the client or an error
|
|
40
|
+
*/
|
|
41
|
+
export declare function createGeminiTextClient(config: Config): Result<GeminiTextClient, GeminiAPIError>;
|
|
42
|
+
//# sourceMappingURL=geminiTextClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geminiTextClient.d.ts","sourceRoot":"","sources":["../../src/api/geminiTextClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAE7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,YAAY,CACV,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,gBAAgB,GACxB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,YAAY,CAAC,CAAC,CAAA;IAEzD;;;OAGG;IACH,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,YAAY,CAAC,CAAC,CAAA;CAC9E;AA8QD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAY/F"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Gemini Text Client for text generation using Gemini 2.0 Flash
|
|
4
|
+
* Pure API client for interacting with Google AI Studio
|
|
5
|
+
* Handles text generation without any prompt optimization logic
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.createGeminiTextClient = createGeminiTextClient;
|
|
9
|
+
const genai_1 = require("@google/genai");
|
|
10
|
+
const result_1 = require("../types/result");
|
|
11
|
+
const errors_1 = require("../utils/errors");
|
|
12
|
+
/**
|
|
13
|
+
* Default configuration for text generation
|
|
14
|
+
*/
|
|
15
|
+
const DEFAULT_GENERATION_CONFIG = {
|
|
16
|
+
temperature: 0.7,
|
|
17
|
+
maxTokens: 8192,
|
|
18
|
+
timeout: 15000,
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Implementation of Gemini Text Client - pure API client
|
|
22
|
+
*/
|
|
23
|
+
class GeminiTextClientImpl {
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.modelName = 'gemini-2.0-flash';
|
|
26
|
+
this.genai = new genai_1.GoogleGenAI({
|
|
27
|
+
apiKey: config.geminiApiKey,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async generateText(prompt, config = {}) {
|
|
31
|
+
// Merge with default configuration
|
|
32
|
+
const mergedConfig = {
|
|
33
|
+
...DEFAULT_GENERATION_CONFIG,
|
|
34
|
+
...config,
|
|
35
|
+
};
|
|
36
|
+
// Validate input
|
|
37
|
+
const validationResult = this.validatePromptInput(prompt);
|
|
38
|
+
if (!validationResult.success) {
|
|
39
|
+
return validationResult;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
// Call Gemini API
|
|
43
|
+
const generatedText = await this.callGeminiAPI(prompt, mergedConfig);
|
|
44
|
+
return (0, result_1.Ok)(generatedText);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return this.handleError(error, 'text generation');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Call Gemini 2.0-flash API to generate text
|
|
52
|
+
*/
|
|
53
|
+
async callGeminiAPI(prompt, config) {
|
|
54
|
+
try {
|
|
55
|
+
// Generate content with timeout
|
|
56
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
57
|
+
setTimeout(() => reject(new Error('API call timeout')), config.timeout || 15000);
|
|
58
|
+
});
|
|
59
|
+
// Build contents based on whether input image is provided (multimodal support)
|
|
60
|
+
let contents;
|
|
61
|
+
if (config.inputImage) {
|
|
62
|
+
// Multimodal request: combine image and text
|
|
63
|
+
contents = [
|
|
64
|
+
{
|
|
65
|
+
parts: [
|
|
66
|
+
{
|
|
67
|
+
inlineData: {
|
|
68
|
+
data: config.inputImage,
|
|
69
|
+
mimeType: 'image/jpeg', // Assuming JPEG for simplicity; can be enhanced later
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
text: prompt,
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// Text-only request
|
|
81
|
+
contents = prompt;
|
|
82
|
+
}
|
|
83
|
+
// Use the updated API structure for @google/genai v1.17.0+
|
|
84
|
+
const apiCall = this.genai.models.generateContent({
|
|
85
|
+
model: this.modelName,
|
|
86
|
+
contents,
|
|
87
|
+
...(config.systemInstruction && { systemInstruction: config.systemInstruction }),
|
|
88
|
+
generationConfig: {
|
|
89
|
+
temperature: config.temperature || 0.7,
|
|
90
|
+
maxOutputTokens: config.maxTokens || 8192,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
const response = await Promise.race([apiCall, timeoutPromise]);
|
|
94
|
+
// Extract text from response - handling both possible response structures
|
|
95
|
+
let responseText;
|
|
96
|
+
if (typeof response.text === 'string') {
|
|
97
|
+
responseText = response.text;
|
|
98
|
+
}
|
|
99
|
+
else if (response.response?.text && typeof response.response.text === 'function') {
|
|
100
|
+
responseText = response.response.text();
|
|
101
|
+
}
|
|
102
|
+
else if (response.response?.candidates?.[0]?.content?.parts?.[0]?.text) {
|
|
103
|
+
responseText = response.response.candidates[0].content.parts[0].text;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
throw new Error('Unable to extract text from API response');
|
|
107
|
+
}
|
|
108
|
+
if (!responseText || responseText.trim().length === 0) {
|
|
109
|
+
throw new Error('Empty response from Gemini API');
|
|
110
|
+
}
|
|
111
|
+
return responseText.trim();
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
// Re-throw with context for proper error handling
|
|
115
|
+
throw new Error(`Gemini API call failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async validateConnection() {
|
|
119
|
+
try {
|
|
120
|
+
// Validate by checking if the models object exists
|
|
121
|
+
if (!this.genai.models) {
|
|
122
|
+
return (0, result_1.Err)(new errors_1.GeminiAPIError('Failed to access Gemini models', 'Check your GEMINI_API_KEY configuration'));
|
|
123
|
+
}
|
|
124
|
+
// API key validation happens during actual API calls
|
|
125
|
+
return (0, result_1.Ok)(true);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
return this.handleError(error, 'connection validation');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
handleError(error, context) {
|
|
132
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
133
|
+
// Check for network errors
|
|
134
|
+
if (this.isNetworkError(error)) {
|
|
135
|
+
return (0, result_1.Err)(new errors_1.NetworkError(`Network error during ${context}: ${errorMessage}`, 'Check your internet connection and try again'));
|
|
136
|
+
}
|
|
137
|
+
// Check for API errors
|
|
138
|
+
if (this.isAPIError(error)) {
|
|
139
|
+
return (0, result_1.Err)(new errors_1.GeminiAPIError(`Failed during ${context}: ${errorMessage}`, this.getAPIErrorSuggestion(errorMessage)));
|
|
140
|
+
}
|
|
141
|
+
// Generic error
|
|
142
|
+
return (0, result_1.Err)(new errors_1.GeminiAPIError(`Failed during ${context}: ${errorMessage}`, 'Check your API configuration and try again'));
|
|
143
|
+
}
|
|
144
|
+
isNetworkError(error) {
|
|
145
|
+
if (error instanceof Error) {
|
|
146
|
+
const networkErrorCodes = ['ECONNRESET', 'ECONNREFUSED', 'ETIMEDOUT', 'ENOTFOUND'];
|
|
147
|
+
return networkErrorCodes.some((code) => error.message.includes(code) || error.code === code);
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
isAPIError(error) {
|
|
152
|
+
if (error instanceof Error) {
|
|
153
|
+
const apiErrorKeywords = ['quota', 'rate limit', 'unauthorized', 'forbidden', 'api key'];
|
|
154
|
+
return apiErrorKeywords.some((keyword) => error.message.toLowerCase().includes(keyword));
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
getAPIErrorSuggestion(errorMessage) {
|
|
159
|
+
const lowerMessage = errorMessage.toLowerCase();
|
|
160
|
+
if (lowerMessage.includes('quota') || lowerMessage.includes('rate limit')) {
|
|
161
|
+
return 'You have exceeded your API quota or rate limit. Wait before making more requests or upgrade your plan';
|
|
162
|
+
}
|
|
163
|
+
if (lowerMessage.includes('unauthorized') || lowerMessage.includes('api key')) {
|
|
164
|
+
return 'Check that your GEMINI_API_KEY is valid and has the necessary permissions';
|
|
165
|
+
}
|
|
166
|
+
if (lowerMessage.includes('forbidden')) {
|
|
167
|
+
return 'Your API key does not have permission for this operation';
|
|
168
|
+
}
|
|
169
|
+
return 'Check your API configuration and try again';
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Validate prompt input before processing
|
|
173
|
+
*/
|
|
174
|
+
validatePromptInput(prompt) {
|
|
175
|
+
if (!prompt || prompt.trim().length === 0) {
|
|
176
|
+
return (0, result_1.Err)(new errors_1.GeminiAPIError('Empty prompt provided', 'Please provide a non-empty prompt for generation'));
|
|
177
|
+
}
|
|
178
|
+
if (prompt.length > 100000) {
|
|
179
|
+
return (0, result_1.Err)(new errors_1.GeminiAPIError('Prompt too long', 'Please provide a shorter prompt (under 100,000 characters)'));
|
|
180
|
+
}
|
|
181
|
+
return (0, result_1.Ok)(true);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Creates a new Gemini Text Client for prompt generation
|
|
186
|
+
* @param config Configuration containing API key and settings
|
|
187
|
+
* @returns Result containing the client or an error
|
|
188
|
+
*/
|
|
189
|
+
function createGeminiTextClient(config) {
|
|
190
|
+
try {
|
|
191
|
+
return (0, result_1.Ok)(new GeminiTextClientImpl(config));
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
195
|
+
return (0, result_1.Err)(new errors_1.GeminiAPIError(`Failed to initialize Gemini Text client: ${errorMessage}`, 'Verify your GEMINI_API_KEY is valid and the @google/genai package is properly installed'));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=geminiTextClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geminiTextClient.js","sourceRoot":"","sources":["../../src/api/geminiTextClient.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AA0TH,wDAYC;AApUD,yCAA2C;AAE3C,4CAAyC;AAEzC,4CAA8D;AAmC9D;;GAEG;AACH,MAAM,yBAAyB,GAAG;IAChC,WAAW,EAAE,GAAG;IAChB,SAAS,EAAE,IAAI;IACf,OAAO,EAAE,KAAK;CACN,CAAA;AA6BV;;GAEG;AACH,MAAM,oBAAoB;IAIxB,YAAY,MAAc;QAHT,cAAS,GAAG,kBAAkB,CAAA;QAI7C,IAAI,CAAC,KAAK,GAAG,IAAI,mBAAW,CAAC;YAC3B,MAAM,EAAE,MAAM,CAAC,YAAY;SAC5B,CAAgC,CAAA;IACnC,CAAC;IAED,KAAK,CAAC,YAAY,CAChB,MAAc,EACd,SAA2B,EAAE;QAE7B,mCAAmC;QACnC,MAAM,YAAY,GAAG;YACnB,GAAG,yBAAyB;YAC5B,GAAG,MAAM;SACV,CAAA;QAED,iBAAiB;QACjB,MAAM,gBAAgB,GAAG,IAAI,CAAC,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AC;YAC9E,OAAO,2EAA2E,CAAA;QACpF,CAAC;QAED,IAAI,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YACvC,OAAO,0DAA0D,CAAA;QACnE,CAAC;QAED,OAAO,4CAA4C,CAAA;IACrD,CAAC;IAED;;OAEG;IACK,mBAAmB,CAAC,MAAc;QACxC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1C,OAAO,IAAA,YAAG,EACR,IAAI,uBAAc,CAChB,uBAAuB,EACvB,kDAAkD,CACnD,CACF,CAAA;QACH,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;YAC3B,OAAO,IAAA,YAAG,EACR,IAAI,uBAAc,CAChB,iBAAiB,EACjB,4DAA4D,CAC7D,CACF,CAAA;QACH,CAAC;QAED,OAAO,IAAA,WAAE,EAAC,IAAI,CAAC,CAAA;IACjB,CAAC;CACF;AAED;;;;GAIG;AACH,SAAgB,sBAAsB,CAAC,MAAc;IACnD,IAAI,CAAC;QACH,OAAO,IAAA,WAAE,EAAC,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAA;IAC7C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAA;QAC7E,OAAO,IAAA,YAAG,EACR,IAAI,uBAAc,CAChB,4CAA4C,YAAY,EAAE,EAC1D,yFAAyF,CAC1F,CACF,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock implementation of MCP Sampling Client for testing
|
|
3
|
+
* Provides predictable responses for testing the orchestrator
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for MCP Sampling operations
|
|
7
|
+
*/
|
|
8
|
+
export interface MCPSamplingConfig {
|
|
9
|
+
/** Timeout in milliseconds for sampling operations */
|
|
10
|
+
timeout: number;
|
|
11
|
+
/** Maximum number of sampling attempts */
|
|
12
|
+
maxAttempts: number;
|
|
13
|
+
/** Whether to enable detailed logging */
|
|
14
|
+
enableLogging: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Result from MCP Sampling process
|
|
18
|
+
*/
|
|
19
|
+
export interface MCPSamplingResult {
|
|
20
|
+
/** The sampled and refined prompt */
|
|
21
|
+
refinedPrompt: string;
|
|
22
|
+
/** Success status of the sampling process */
|
|
23
|
+
success: boolean;
|
|
24
|
+
/** Processing time in milliseconds */
|
|
25
|
+
processingTime: number;
|
|
26
|
+
/** Additional metadata from sampling */
|
|
27
|
+
metadata: {
|
|
28
|
+
/** Model used for sampling */
|
|
29
|
+
model: string;
|
|
30
|
+
/** Number of sampling iterations performed */
|
|
31
|
+
iterations: number;
|
|
32
|
+
/** Confidence in the refined prompt */
|
|
33
|
+
confidence: number;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Interface for MCP Sampling Client
|
|
38
|
+
* Defines the contract for advanced prompt refinement
|
|
39
|
+
*/
|
|
40
|
+
export interface MCPSamplingClient {
|
|
41
|
+
/**
|
|
42
|
+
* Refine a complex prompt using MCP Sampling techniques
|
|
43
|
+
* @param prompt - The input prompt to refine
|
|
44
|
+
* @returns Promise<MCPSamplingResult> - The refined result
|
|
45
|
+
*/
|
|
46
|
+
refinePrompt(prompt: string): Promise<MCPSamplingResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Check if the client is properly configured and available
|
|
49
|
+
* @returns Promise<boolean> - True if client is ready
|
|
50
|
+
*/
|
|
51
|
+
isAvailable(): Promise<boolean>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Mock implementation of MCPSamplingClient for testing purposes
|
|
55
|
+
* Provides predictable behavior for orchestrator testing
|
|
56
|
+
*/
|
|
57
|
+
export declare class MockMCPSamplingClient implements MCPSamplingClient {
|
|
58
|
+
private config;
|
|
59
|
+
private mockDelay;
|
|
60
|
+
private shouldFail;
|
|
61
|
+
constructor(_config?: Partial<MCPSamplingConfig>);
|
|
62
|
+
/**
|
|
63
|
+
* Set whether the mock should simulate failures
|
|
64
|
+
*/
|
|
65
|
+
setShouldFail(shouldFail: boolean): void;
|
|
66
|
+
/**
|
|
67
|
+
* Set mock response delay for testing timing scenarios
|
|
68
|
+
*/
|
|
69
|
+
setMockDelay(delay: number): void;
|
|
70
|
+
/**
|
|
71
|
+
* Mock implementation of prompt refinement
|
|
72
|
+
* Returns predictable enhanced prompts for testing
|
|
73
|
+
*/
|
|
74
|
+
refinePrompt(prompt: string): Promise<MCPSamplingResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Mock availability check - always returns true unless configured to fail
|
|
77
|
+
*/
|
|
78
|
+
isAvailable(): Promise<boolean>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Factory function to create a mock MCP Sampling Client with default configuration
|
|
82
|
+
*/
|
|
83
|
+
export declare function createMockMCPSamplingClient(config?: Partial<MCPSamplingConfig>): MockMCPSamplingClient;
|
|
84
|
+
//# sourceMappingURL=mcpSamplingClient.mock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpSamplingClient.mock.d.ts","sourceRoot":"","sources":["../../../../src/business/__tests__/mocks/mcpSamplingClient.mock.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAA;IACf,0CAA0C;IAC1C,WAAW,EAAE,MAAM,CAAA;IACnB,yCAAyC;IACzC,aAAa,EAAE,OAAO,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,qCAAqC;IACrC,aAAa,EAAE,MAAM,CAAA;IACrB,6CAA6C;IAC7C,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