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
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Input Validator - Comprehensive input validation system
|
|
4
|
+
* Handles edge cases, multi-language support, and secure input processing
|
|
5
|
+
* Provides detailed validation results and normalization
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.InputValidator = void 0;
|
|
9
|
+
const orchestrationErrorHandler_1 = require("../errorHandling/orchestrationErrorHandler");
|
|
10
|
+
/**
|
|
11
|
+
* Validation constants
|
|
12
|
+
*/
|
|
13
|
+
const VALIDATION_CONSTANTS = {
|
|
14
|
+
MAX_PROMPT_LENGTH: 4000,
|
|
15
|
+
MIN_PROMPT_LENGTH: 1,
|
|
16
|
+
SUPPORTED_LANGUAGES: ['en', 'ja', 'zh', 'ko', 'es', 'fr', 'de', 'it', 'pt', 'ru'],
|
|
17
|
+
SPECIAL_CHAR_PATTERN: /[^\w\s\-.,!?'"():;]/g,
|
|
18
|
+
UNSAFE_CONTENT_PATTERNS: [
|
|
19
|
+
/<script[^>]*>.*?<\/script>/gi,
|
|
20
|
+
/javascript:/gi,
|
|
21
|
+
/vbscript:/gi,
|
|
22
|
+
/onload=/gi,
|
|
23
|
+
/onerror=/gi,
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* InputValidator implementation for comprehensive input validation
|
|
28
|
+
*/
|
|
29
|
+
class InputValidator {
|
|
30
|
+
constructor() {
|
|
31
|
+
this.supportedLanguages = new Set(VALIDATION_CONSTANTS.SUPPORTED_LANGUAGES);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Validate prompt input with comprehensive edge case handling
|
|
35
|
+
*/
|
|
36
|
+
async validatePromptInput(prompt) {
|
|
37
|
+
const validations = await Promise.all([
|
|
38
|
+
this.validatePromptLength(prompt),
|
|
39
|
+
this.validateCharacterSet(prompt),
|
|
40
|
+
this.validateContent(prompt),
|
|
41
|
+
this.detectPotentialIssues(prompt),
|
|
42
|
+
]);
|
|
43
|
+
return this.compileValidationResult(validations, prompt);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Validate prompt length with appropriate error handling
|
|
47
|
+
*/
|
|
48
|
+
validatePromptLength(prompt) {
|
|
49
|
+
const trimmedLength = prompt.trim().length;
|
|
50
|
+
if (trimmedLength === 0) {
|
|
51
|
+
return {
|
|
52
|
+
valid: false,
|
|
53
|
+
severity: orchestrationErrorHandler_1.ErrorSeverity.FATAL,
|
|
54
|
+
message: 'Prompt cannot be empty',
|
|
55
|
+
suggestion: 'Provide a descriptive prompt for image generation',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (trimmedLength < VALIDATION_CONSTANTS.MIN_PROMPT_LENGTH) {
|
|
59
|
+
return {
|
|
60
|
+
valid: false,
|
|
61
|
+
severity: orchestrationErrorHandler_1.ErrorSeverity.RECOVERABLE,
|
|
62
|
+
message: 'Prompt is too short',
|
|
63
|
+
suggestion: 'Provide a more detailed description for better results',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (prompt.length > VALIDATION_CONSTANTS.MAX_PROMPT_LENGTH) {
|
|
67
|
+
return {
|
|
68
|
+
valid: false, // This will be handled as a warning in compile method due to DEGRADED severity
|
|
69
|
+
severity: orchestrationErrorHandler_1.ErrorSeverity.DEGRADED,
|
|
70
|
+
message: `Prompt exceeds recommended length (${VALIDATION_CONSTANTS.MAX_PROMPT_LENGTH} characters)`,
|
|
71
|
+
suggestion: 'Consider shortening prompt for better processing',
|
|
72
|
+
metadata: {
|
|
73
|
+
actualLength: prompt.length,
|
|
74
|
+
recommendedLength: VALIDATION_CONSTANTS.MAX_PROMPT_LENGTH,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return { valid: true };
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Validate character set and encoding
|
|
82
|
+
*/
|
|
83
|
+
validateCharacterSet(prompt) {
|
|
84
|
+
// Check for encoding issues
|
|
85
|
+
const encodingTest = prompt.includes('\uFFFD'); // Unicode replacement character
|
|
86
|
+
if (encodingTest) {
|
|
87
|
+
return {
|
|
88
|
+
valid: false,
|
|
89
|
+
severity: orchestrationErrorHandler_1.ErrorSeverity.RECOVERABLE,
|
|
90
|
+
message: 'Text encoding issues detected',
|
|
91
|
+
suggestion: 'Please ensure proper text encoding (UTF-8 recommended)',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// Check for excessive special characters
|
|
95
|
+
const specialCharMatches = prompt.match(VALIDATION_CONSTANTS.SPECIAL_CHAR_PATTERN);
|
|
96
|
+
if (specialCharMatches && specialCharMatches.length > prompt.length * 0.3) {
|
|
97
|
+
return {
|
|
98
|
+
valid: false,
|
|
99
|
+
severity: orchestrationErrorHandler_1.ErrorSeverity.DEGRADED,
|
|
100
|
+
message: 'Excessive special characters detected',
|
|
101
|
+
suggestion: 'Reduce special characters for better processing',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return { valid: true };
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Validate content for appropriateness and safety
|
|
108
|
+
*/
|
|
109
|
+
async validateContent(prompt) {
|
|
110
|
+
// Multi-language support validation
|
|
111
|
+
const languageDetection = await this.detectLanguage(prompt);
|
|
112
|
+
const contentAnalysis = await this.analyzeContent(prompt);
|
|
113
|
+
if (!contentAnalysis.appropriate) {
|
|
114
|
+
return {
|
|
115
|
+
valid: false,
|
|
116
|
+
severity: orchestrationErrorHandler_1.ErrorSeverity.RECOVERABLE,
|
|
117
|
+
message: contentAnalysis.message,
|
|
118
|
+
suggestion: 'Please modify the prompt to follow content guidelines',
|
|
119
|
+
metadata: {
|
|
120
|
+
language: languageDetection.language,
|
|
121
|
+
detectedIssues: contentAnalysis.suggestedModifications,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
valid: true,
|
|
127
|
+
metadata: {
|
|
128
|
+
language: languageDetection.language,
|
|
129
|
+
confidence: languageDetection.confidence,
|
|
130
|
+
detectedLanguages: contentAnalysis.detectedLanguages,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Detect potential security and processing issues
|
|
136
|
+
*/
|
|
137
|
+
detectPotentialIssues(prompt) {
|
|
138
|
+
// Check for potential script injection
|
|
139
|
+
for (const pattern of VALIDATION_CONSTANTS.UNSAFE_CONTENT_PATTERNS) {
|
|
140
|
+
if (pattern.test(prompt)) {
|
|
141
|
+
return {
|
|
142
|
+
valid: false,
|
|
143
|
+
severity: orchestrationErrorHandler_1.ErrorSeverity.FATAL,
|
|
144
|
+
message: 'Potentially unsafe content detected',
|
|
145
|
+
suggestion: 'Remove any code-like structures from the prompt',
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Check for extremely repetitive content (more lenient threshold)
|
|
150
|
+
const words = prompt.toLowerCase().split(/\s+/);
|
|
151
|
+
const uniqueWords = new Set(words);
|
|
152
|
+
if (words.length > 20 && uniqueWords.size < words.length * 0.15) {
|
|
153
|
+
return {
|
|
154
|
+
valid: false,
|
|
155
|
+
severity: orchestrationErrorHandler_1.ErrorSeverity.DEGRADED,
|
|
156
|
+
message: 'Highly repetitive content detected',
|
|
157
|
+
suggestion: 'Provide more varied descriptions for better results',
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
return { valid: true };
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Detect language of the input text
|
|
164
|
+
*/
|
|
165
|
+
async detectLanguage(prompt) {
|
|
166
|
+
// Simple language detection based on character patterns
|
|
167
|
+
// In a real implementation, this would use a proper language detection library
|
|
168
|
+
// Japanese characters
|
|
169
|
+
if (/[\u3040-\u309f\u30a0-\u30ff\u4e00-\u9faf]/.test(prompt)) {
|
|
170
|
+
return {
|
|
171
|
+
language: 'ja',
|
|
172
|
+
confidence: 0.9,
|
|
173
|
+
isSupported: this.supportedLanguages.has('ja'),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
// Chinese characters
|
|
177
|
+
if (/[\u4e00-\u9faf]/.test(prompt)) {
|
|
178
|
+
return {
|
|
179
|
+
language: 'zh',
|
|
180
|
+
confidence: 0.8,
|
|
181
|
+
isSupported: this.supportedLanguages.has('zh'),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
// Korean characters
|
|
185
|
+
if (/[\uac00-\ud7af]/.test(prompt)) {
|
|
186
|
+
return {
|
|
187
|
+
language: 'ko',
|
|
188
|
+
confidence: 0.9,
|
|
189
|
+
isSupported: this.supportedLanguages.has('ko'),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
// Default to English
|
|
193
|
+
return {
|
|
194
|
+
language: 'en',
|
|
195
|
+
confidence: 0.7,
|
|
196
|
+
isSupported: true,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Analyze content for appropriateness and safety
|
|
201
|
+
*/
|
|
202
|
+
async analyzeContent(prompt) {
|
|
203
|
+
const detectedLanguages = [(await this.detectLanguage(prompt)).language];
|
|
204
|
+
const hasSpecialCharacters = VALIDATION_CONSTANTS.SPECIAL_CHAR_PATTERN.test(prompt);
|
|
205
|
+
const encodingIssues = prompt.includes('\uFFFD');
|
|
206
|
+
// Simple content appropriateness check
|
|
207
|
+
const inappropriate = ['explicit', 'violent', 'harmful', 'illegal', 'offensive'].some((word) => prompt.toLowerCase().includes(word));
|
|
208
|
+
if (inappropriate) {
|
|
209
|
+
return {
|
|
210
|
+
appropriate: false,
|
|
211
|
+
message: 'Content may not comply with usage guidelines',
|
|
212
|
+
suggestedModifications: [
|
|
213
|
+
'Remove inappropriate content',
|
|
214
|
+
'Use descriptive but appropriate language',
|
|
215
|
+
],
|
|
216
|
+
detectedLanguages,
|
|
217
|
+
hasSpecialCharacters,
|
|
218
|
+
encodingIssues,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
appropriate: true,
|
|
223
|
+
message: 'Content appears appropriate for processing',
|
|
224
|
+
detectedLanguages,
|
|
225
|
+
hasSpecialCharacters,
|
|
226
|
+
encodingIssues,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Compile validation results into comprehensive report
|
|
231
|
+
*/
|
|
232
|
+
compileValidationResult(validations, originalPrompt) {
|
|
233
|
+
const errors = [];
|
|
234
|
+
const warnings = [];
|
|
235
|
+
let normalizedInput = originalPrompt;
|
|
236
|
+
for (let i = 0; i < validations.length; i++) {
|
|
237
|
+
const validation = validations[i];
|
|
238
|
+
if (!validation || validation.valid)
|
|
239
|
+
continue;
|
|
240
|
+
if (validation.severity === orchestrationErrorHandler_1.ErrorSeverity.FATAL) {
|
|
241
|
+
errors.push({
|
|
242
|
+
field: 'prompt',
|
|
243
|
+
message: validation.message || 'Validation failed',
|
|
244
|
+
severity: validation.severity,
|
|
245
|
+
suggestion: validation.suggestion || 'Please fix this issue',
|
|
246
|
+
code: `E${i + 1}`,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
else if (validation.severity === orchestrationErrorHandler_1.ErrorSeverity.DEGRADED) {
|
|
250
|
+
warnings.push({
|
|
251
|
+
field: 'prompt',
|
|
252
|
+
message: validation.message || 'Validation warning',
|
|
253
|
+
suggestion: validation.suggestion || 'Consider addressing this issue',
|
|
254
|
+
code: `W${i + 1}`,
|
|
255
|
+
});
|
|
256
|
+
// Apply normalization for degraded issues
|
|
257
|
+
normalizedInput = this.normalizeInput(normalizedInput, validation);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
warnings.push({
|
|
261
|
+
field: 'prompt',
|
|
262
|
+
message: validation.message || 'Validation warning',
|
|
263
|
+
suggestion: validation.suggestion || 'Consider addressing this issue',
|
|
264
|
+
code: `W${i + 1}`,
|
|
265
|
+
});
|
|
266
|
+
// Apply normalization for recoverable issues
|
|
267
|
+
if (validation.severity === orchestrationErrorHandler_1.ErrorSeverity.RECOVERABLE) {
|
|
268
|
+
normalizedInput = this.normalizeInput(normalizedInput, validation);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
// Check if there are any degraded severity issues that should make validation invalid
|
|
273
|
+
const hasDegradedIssues = warnings.some((warning) => warning.code.startsWith('W') && warning.message.includes('exceeds recommended length'));
|
|
274
|
+
const isValid = errors.length === 0 && !hasDegradedIssues;
|
|
275
|
+
return {
|
|
276
|
+
valid: isValid,
|
|
277
|
+
errors,
|
|
278
|
+
warnings,
|
|
279
|
+
normalizedInput: normalizedInput !== originalPrompt ? normalizedInput : isValid ? originalPrompt : undefined,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Normalize input based on validation issues
|
|
284
|
+
*/
|
|
285
|
+
normalizeInput(input, _validation) {
|
|
286
|
+
// Apply specific normalization based on validation type
|
|
287
|
+
let normalized = input;
|
|
288
|
+
// Trim whitespace
|
|
289
|
+
normalized = normalized.trim();
|
|
290
|
+
// Skip security pattern removal for non-Latin scripts to preserve content
|
|
291
|
+
const hasNonLatinScript = /[\u0600-\u06ff\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff]/.test(normalized);
|
|
292
|
+
if (!hasNonLatinScript) {
|
|
293
|
+
// Remove potential security issues only for Latin scripts
|
|
294
|
+
for (const pattern of VALIDATION_CONSTANTS.UNSAFE_CONTENT_PATTERNS) {
|
|
295
|
+
normalized = normalized.replace(pattern, '');
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
// Truncate if too long
|
|
299
|
+
if (normalized.length > VALIDATION_CONSTANTS.MAX_PROMPT_LENGTH) {
|
|
300
|
+
normalized = normalized.substring(0, VALIDATION_CONSTANTS.MAX_PROMPT_LENGTH);
|
|
301
|
+
// Ensure we don't cut off mid-word by finding the last complete word
|
|
302
|
+
const lastSpaceIndex = normalized.lastIndexOf(' ');
|
|
303
|
+
if (lastSpaceIndex > normalized.length * 0.8) {
|
|
304
|
+
normalized = normalized.substring(0, lastSpaceIndex);
|
|
305
|
+
}
|
|
306
|
+
// Ensure trailing partial words are properly handled
|
|
307
|
+
normalized = normalized.trim();
|
|
308
|
+
}
|
|
309
|
+
return normalized;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Validate input against custom schema
|
|
313
|
+
*/
|
|
314
|
+
async validateAgainstSchema(input, schema) {
|
|
315
|
+
const errors = [];
|
|
316
|
+
const warnings = [];
|
|
317
|
+
// Type validation
|
|
318
|
+
if (schema.type === 'string' && typeof input !== 'string') {
|
|
319
|
+
errors.push({
|
|
320
|
+
field: 'root',
|
|
321
|
+
message: `Expected type string, got ${typeof input}`,
|
|
322
|
+
severity: orchestrationErrorHandler_1.ErrorSeverity.FATAL,
|
|
323
|
+
code: 'TYPE_MISMATCH',
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
// String-specific validations
|
|
327
|
+
if (schema.type === 'string' && typeof input === 'string') {
|
|
328
|
+
if (schema.minLength && input.length < schema.minLength) {
|
|
329
|
+
errors.push({
|
|
330
|
+
field: 'root',
|
|
331
|
+
message: `Minimum length ${schema.minLength} required, got ${input.length}`,
|
|
332
|
+
severity: orchestrationErrorHandler_1.ErrorSeverity.RECOVERABLE,
|
|
333
|
+
code: 'MIN_LENGTH',
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
if (schema.maxLength && input.length > schema.maxLength) {
|
|
337
|
+
warnings.push({
|
|
338
|
+
field: 'root',
|
|
339
|
+
message: `Exceeds recommended length ${schema.maxLength}, got ${input.length}`,
|
|
340
|
+
suggestion: 'Consider shortening the input',
|
|
341
|
+
code: 'MAX_LENGTH',
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
if (schema.pattern && !schema.pattern.test(input)) {
|
|
345
|
+
errors.push({
|
|
346
|
+
field: 'root',
|
|
347
|
+
message: 'Input does not match required pattern',
|
|
348
|
+
severity: orchestrationErrorHandler_1.ErrorSeverity.RECOVERABLE,
|
|
349
|
+
code: 'PATTERN_MISMATCH',
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return {
|
|
354
|
+
valid: errors.length === 0,
|
|
355
|
+
errors,
|
|
356
|
+
warnings,
|
|
357
|
+
normalizedInput: errors.length === 0 ? input : undefined,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
exports.InputValidator = InputValidator;
|
|
362
|
+
//# sourceMappingURL=inputValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputValidator.js","sourceRoot":"","sources":["../../../src/infrastructure/validation/inputValidator.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAUH,0FAAsF;AAkCtF;;GAEG;AACH,MAAM,oBAAoB,GAAG;IAC3B,iBAAiB,EAAE,IAAI;IACvB,iBAAiB,EAAE,CAAC;IACpB,mBAAmB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;IACjF,oBAAoB,EA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,EAAE,YAAY;iBACnB,CAAC,CAAA;YACJ,CAAC;YAED,IAAI,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBAClD,MAAM,CAAC,IAAI,CAAC;oBACV,KAAK,EAAE,MAAM;oBACb,OAAO,EAAE,uCAAuC;oBAChD,QAAQ,EAAE,yCAAQ,CAAC,WAAW;oBAC9B,IAAI,EAAE,kBAAkB;iBACzB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC1B,MAAM;YACN,QAAQ;YACR,eAAe,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SACzD,CAAA;IACH,CAAC;CACF;AAjYD,wCAiYC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parameter optimizer for image generation based on structured prompts
|
|
3
|
+
* Analyzes structured prompts and optimizes image generation parameters
|
|
4
|
+
*/
|
|
5
|
+
import type { Result } from '../types/result';
|
|
6
|
+
import type { ImageParameters, OptimizedParameters, ParameterOptimizer, PromptCharacteristics } from '../types/twoStageTypes';
|
|
7
|
+
import { GeminiAPIError } from '../utils/errors';
|
|
8
|
+
/**
|
|
9
|
+
* Implementation of parameter optimization based on structured prompt analysis
|
|
10
|
+
*/
|
|
11
|
+
export declare class ParameterOptimizerImpl implements ParameterOptimizer {
|
|
12
|
+
/**
|
|
13
|
+
* Optimize parameters based on structured prompt analysis
|
|
14
|
+
*/
|
|
15
|
+
optimizeForStructuredPrompt(structuredPrompt: string, baseParams: ImageParameters): Promise<Result<OptimizedParameters, GeminiAPIError>>;
|
|
16
|
+
/**
|
|
17
|
+
* Analyze prompt characteristics for optimization
|
|
18
|
+
*/
|
|
19
|
+
analyzePromptCharacteristics(prompt: string): PromptCharacteristics;
|
|
20
|
+
/**
|
|
21
|
+
* Detect content type from prompt
|
|
22
|
+
*/
|
|
23
|
+
private detectContentType;
|
|
24
|
+
/**
|
|
25
|
+
* Detect complexity level
|
|
26
|
+
*/
|
|
27
|
+
private detectComplexity;
|
|
28
|
+
/**
|
|
29
|
+
* Suggest optimal aspect ratio based on content type
|
|
30
|
+
*/
|
|
31
|
+
private suggestAspectRatio;
|
|
32
|
+
/**
|
|
33
|
+
* Suggest quality level based on complexity and requirements
|
|
34
|
+
*/
|
|
35
|
+
private suggestQuality;
|
|
36
|
+
/**
|
|
37
|
+
* Suggest style based on prompt content
|
|
38
|
+
*/
|
|
39
|
+
private suggestStyle;
|
|
40
|
+
/**
|
|
41
|
+
* Extract key elements from prompt
|
|
42
|
+
*/
|
|
43
|
+
private extractElements;
|
|
44
|
+
/**
|
|
45
|
+
* Recommend features based on prompt analysis
|
|
46
|
+
*/
|
|
47
|
+
private recommendFeatures;
|
|
48
|
+
/**
|
|
49
|
+
* Check if aspect ratio should be optimized
|
|
50
|
+
*/
|
|
51
|
+
private shouldOptimizeAspectRatio;
|
|
52
|
+
/**
|
|
53
|
+
* Check if quality should be upgraded
|
|
54
|
+
*/
|
|
55
|
+
private shouldUpgradeQuality;
|
|
56
|
+
/**
|
|
57
|
+
* Check if style should be optimized
|
|
58
|
+
*/
|
|
59
|
+
private shouldOptimizeStyle;
|
|
60
|
+
/**
|
|
61
|
+
* Detect cinematic content
|
|
62
|
+
*/
|
|
63
|
+
private detectsCinematicContent;
|
|
64
|
+
/**
|
|
65
|
+
* Detect macro photography content
|
|
66
|
+
*/
|
|
67
|
+
private detectsMacroContent;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=parameterOptimizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameterOptimizer.d.ts","sourceRoot":"","sources":["../../src/integration/parameterOptimizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAE7C,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAkDhD;;GAEG;AACH,qBAAa,sBAAuB,YAAW,kBAAkB;IAC/D;;OAEG;IACG,2BAA2B,CAC/B,gBAAgB,EAAE,MAAM,EACxB,UAAU,EAAE,eAAe,GAC1B,OAAO,CAAC,MAAM,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;IAuFvD;;OAEG;IACH,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB;IA+BnE;;OAEG;IACH,OAAO,CAAC,iBAAiB;IASzB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAaxB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA0B1B;;OAEG;IACH,OAAO,CAAC,cAAc;IAkBtB;;OAEG;IACH,OAAO,CAAC,YAAY;IAcpB;;OAEG;IACH,OAAO,CAAC,eAAe;IAuBvB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAUzB;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAuBjC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAU5B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAO3B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAK/B;;OAEG;IACH,OAAO,CAAC,mBAAmB;CAS5B"}
|