mcp-hydrocoder-image 1.0.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/LICENSE +21 -0
- package/README.md +454 -0
- package/bin/install-skills.js +115 -0
- package/dist/api/geminiClient.d.ts +57 -0
- package/dist/api/geminiClient.d.ts.map +1 -0
- package/dist/api/geminiClient.js +341 -0
- package/dist/api/geminiClient.js.map +1 -0
- package/dist/api/geminiTextClient.d.ts +44 -0
- package/dist/api/geminiTextClient.d.ts.map +1 -0
- package/dist/api/geminiTextClient.js +202 -0
- package/dist/api/geminiTextClient.js.map +1 -0
- package/dist/business/fileManager.d.ts +20 -0
- package/dist/business/fileManager.d.ts.map +1 -0
- package/dist/business/fileManager.js +76 -0
- package/dist/business/fileManager.js.map +1 -0
- package/dist/business/inputValidator.d.ts +44 -0
- package/dist/business/inputValidator.d.ts.map +1 -0
- package/dist/business/inputValidator.js +213 -0
- package/dist/business/inputValidator.js.map +1 -0
- package/dist/business/responseBuilder.d.ts +21 -0
- package/dist/business/responseBuilder.d.ts.map +1 -0
- package/dist/business/responseBuilder.js +166 -0
- package/dist/business/responseBuilder.js.map +1 -0
- package/dist/business/structuredPromptGenerator.d.ts +56 -0
- package/dist/business/structuredPromptGenerator.d.ts.map +1 -0
- package/dist/business/structuredPromptGenerator.js +218 -0
- package/dist/business/structuredPromptGenerator.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/server/errorHandler.d.ts +29 -0
- package/dist/server/errorHandler.d.ts.map +1 -0
- package/dist/server/errorHandler.js +99 -0
- package/dist/server/errorHandler.js.map +1 -0
- package/dist/server/mcpServer.d.ts +159 -0
- package/dist/server/mcpServer.d.ts.map +1 -0
- package/dist/server/mcpServer.js +434 -0
- package/dist/server/mcpServer.js.map +1 -0
- package/dist/server-main.d.ts +5 -0
- package/dist/server-main.d.ts.map +1 -0
- package/dist/server-main.js +37 -0
- package/dist/server-main.js.map +1 -0
- package/dist/types/mcp.d.ts +121 -0
- package/dist/types/mcp.d.ts.map +1 -0
- package/dist/types/mcp.js +22 -0
- package/dist/types/mcp.js.map +1 -0
- package/dist/types/result.d.ts +27 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +27 -0
- package/dist/types/result.js.map +1 -0
- package/dist/utils/config.d.ts +29 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +56 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/errors.d.ts +84 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +215 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/logger.d.ts +80 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +186 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/security.d.ts +50 -0
- package/dist/utils/security.d.ts.map +1 -0
- package/dist/utils/security.js +116 -0
- package/dist/utils/security.js.map +1 -0
- package/package.json +89 -0
- package/skills/image-generation/SKILL.md +131 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/types/mcp.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAsCH;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA4B;IAC3D,MAAM;IACN,UAAU;IACV,SAAS;CACD,CAAA;AAEV;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,uDAAuD;IACvD,KAAK,EAAE,gCAAgC;IACvC,+CAA+C;IAC/C,GAAG,EAAE,4BAA4B;CACzB,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result type for operations that may fail
|
|
3
|
+
* Provides type-safe error handling with discriminated unions
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Result type that represents either success with data or failure with error
|
|
7
|
+
*/
|
|
8
|
+
export type Result<T, E extends Error> = {
|
|
9
|
+
success: true;
|
|
10
|
+
data: T;
|
|
11
|
+
} | {
|
|
12
|
+
success: false;
|
|
13
|
+
error: E;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Helper function to create a successful Result
|
|
17
|
+
* @param data The data to wrap in a successful Result
|
|
18
|
+
* @returns A successful Result containing the data
|
|
19
|
+
*/
|
|
20
|
+
export declare function Ok<T>(data: T): Result<T, never>;
|
|
21
|
+
/**
|
|
22
|
+
* Helper function to create an error Result
|
|
23
|
+
* @param error The error to wrap in a failed Result
|
|
24
|
+
* @returns A failed Result containing the error
|
|
25
|
+
*/
|
|
26
|
+
export declare function Err<E extends Error>(error: E): Result<never, E>;
|
|
27
|
+
//# sourceMappingURL=result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/types/result.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,KAAK,IACjC;IACE,OAAO,EAAE,IAAI,CAAA;IACb,IAAI,EAAE,CAAC,CAAA;CACR,GACD;IACE,OAAO,EAAE,KAAK,CAAA;IACd,KAAK,EAAE,CAAC,CAAA;CACT,CAAA;AAEL;;;;GAIG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAK/C;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,KAAK,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAK/D"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result type for operations that may fail
|
|
3
|
+
* Provides type-safe error handling with discriminated unions
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Helper function to create a successful Result
|
|
7
|
+
* @param data The data to wrap in a successful Result
|
|
8
|
+
* @returns A successful Result containing the data
|
|
9
|
+
*/
|
|
10
|
+
export function Ok(data) {
|
|
11
|
+
return {
|
|
12
|
+
success: true,
|
|
13
|
+
data,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Helper function to create an error Result
|
|
18
|
+
* @param error The error to wrap in a failed Result
|
|
19
|
+
* @returns A failed Result containing the error
|
|
20
|
+
*/
|
|
21
|
+
export function Err(error) {
|
|
22
|
+
return {
|
|
23
|
+
success: false,
|
|
24
|
+
error,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/types/result.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH;;;;GAIG;AACH,MAAM,UAAU,EAAE,CAAI,IAAO;IAC3B,OAAO;QACL,OAAO,EAAE,IAAI;QACb,IAAI;KACL,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,GAAG,CAAkB,KAAQ;IAC3C,OAAO;QACL,OAAO,EAAE,KAAK;QACd,KAAK;KACN,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration management for MCP server
|
|
3
|
+
* Handles environment variables and configuration validation
|
|
4
|
+
*/
|
|
5
|
+
import type { ImageQuality } from '../types/mcp.js';
|
|
6
|
+
import type { Result } from '../types/result.js';
|
|
7
|
+
import { ConfigError } from './errors.js';
|
|
8
|
+
/**
|
|
9
|
+
* Configuration interface
|
|
10
|
+
*/
|
|
11
|
+
export interface Config {
|
|
12
|
+
geminiApiKey: string;
|
|
13
|
+
imageOutputDir: string;
|
|
14
|
+
apiTimeout: number;
|
|
15
|
+
skipPromptEnhancement: boolean;
|
|
16
|
+
imageQuality: ImageQuality;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Validates the configuration
|
|
20
|
+
* @param config The configuration to validate
|
|
21
|
+
* @returns Result containing validated config or ConfigError
|
|
22
|
+
*/
|
|
23
|
+
export declare function validateConfig(config: Config): Result<Config, ConfigError>;
|
|
24
|
+
/**
|
|
25
|
+
* Loads configuration from environment variables
|
|
26
|
+
* @returns Result containing config or ConfigError
|
|
27
|
+
*/
|
|
28
|
+
export declare function getConfig(): Result<Config, ConfigError>;
|
|
29
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,qBAAqB,EAAE,OAAO,CAAA;IAC9B,YAAY,EAAE,YAAY,CAAA;CAC3B;AAUD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAmD1E;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAUvD"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration management for MCP server
|
|
3
|
+
* Handles environment variables and configuration validation
|
|
4
|
+
*/
|
|
5
|
+
import { IMAGE_QUALITY_VALUES } from '../types/mcp.js';
|
|
6
|
+
import { Err, Ok } from '../types/result.js';
|
|
7
|
+
import { ConfigError } from './errors.js';
|
|
8
|
+
/**
|
|
9
|
+
* Default configuration values
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_CONFIG = {
|
|
12
|
+
imageOutputDir: './output',
|
|
13
|
+
apiTimeout: 30000, // 30 seconds
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Validates the configuration
|
|
17
|
+
* @param config The configuration to validate
|
|
18
|
+
* @returns Result containing validated config or ConfigError
|
|
19
|
+
*/
|
|
20
|
+
export function validateConfig(config) {
|
|
21
|
+
// Validate GEMINI_API_KEY
|
|
22
|
+
if (!config.geminiApiKey || config.geminiApiKey.trim().length === 0) {
|
|
23
|
+
return Err(new ConfigError('GEMINI_API_KEY is required but not provided', 'Set GEMINI_API_KEY environment variable with your Google AI API key'));
|
|
24
|
+
}
|
|
25
|
+
if (config.geminiApiKey.length < 10) {
|
|
26
|
+
return Err(new ConfigError('GEMINI_API_KEY appears to be invalid - must be at least 10 characters', 'Set the GEMINI_API_KEY environment variable to your valid Google AI API key'));
|
|
27
|
+
}
|
|
28
|
+
// Validate apiTimeout
|
|
29
|
+
if (config.apiTimeout <= 0) {
|
|
30
|
+
return Err(new ConfigError('API timeout must be a positive number', 'Set a positive timeout value in milliseconds (e.g., 30000 for 30 seconds)'));
|
|
31
|
+
}
|
|
32
|
+
// Validate imageOutputDir (basic check - non-empty string)
|
|
33
|
+
if (!config.imageOutputDir || config.imageOutputDir.trim().length === 0) {
|
|
34
|
+
return Err(new ConfigError('IMAGE_OUTPUT_DIR cannot be empty', 'Set IMAGE_OUTPUT_DIR to a valid directory path'));
|
|
35
|
+
}
|
|
36
|
+
// Validate imageQuality
|
|
37
|
+
if (!IMAGE_QUALITY_VALUES.includes(config.imageQuality)) {
|
|
38
|
+
return Err(new ConfigError(`Invalid IMAGE_QUALITY value: "${config.imageQuality}". Valid options: ${IMAGE_QUALITY_VALUES.join(', ')}`, `Set IMAGE_QUALITY to one of: ${IMAGE_QUALITY_VALUES.join(', ')}`));
|
|
39
|
+
}
|
|
40
|
+
return Ok(config);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Loads configuration from environment variables
|
|
44
|
+
* @returns Result containing config or ConfigError
|
|
45
|
+
*/
|
|
46
|
+
export function getConfig() {
|
|
47
|
+
const config = {
|
|
48
|
+
geminiApiKey: process.env['GEMINI_API_KEY'] || '',
|
|
49
|
+
imageOutputDir: process.env['IMAGE_OUTPUT_DIR'] || DEFAULT_CONFIG.imageOutputDir,
|
|
50
|
+
apiTimeout: DEFAULT_CONFIG.apiTimeout,
|
|
51
|
+
skipPromptEnhancement: process.env['SKIP_PROMPT_ENHANCEMENT'] === 'true',
|
|
52
|
+
imageQuality: (process.env['IMAGE_QUALITY'] || 'fast'),
|
|
53
|
+
};
|
|
54
|
+
return validateConfig(config);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAEtD,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAazC;;GAEG;AACH,MAAM,cAAc,GAAG;IACrB,cAAc,EAAE,UAAU;IAC1B,UAAU,EAAE,KAAK,EAAE,aAAa;CACxB,CAAA;AAEV;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,0BAA0B;IAC1B,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpE,OAAO,GAAG,CACR,IAAI,WAAW,CACb,6CAA6C,EAC7C,qEAAqE,CACtE,CACF,CAAA;IACH,CAAC;IAED,IAAI,MAAM,CAAC,YAAY,CAAC,MAAM,GAAG,EA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AiB;KACvE,CAAA;IAED,OAAO,cAAc,CAAC,MAAM,CAAC,CAAA;AAC/B,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error classes for MCP server
|
|
3
|
+
* Provides specific error types with structured error codes and suggestions
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Structured error format for consistent error reporting
|
|
7
|
+
*/
|
|
8
|
+
export interface StructuredError {
|
|
9
|
+
code: string;
|
|
10
|
+
message: string;
|
|
11
|
+
suggestion: string;
|
|
12
|
+
timestamp: string;
|
|
13
|
+
context?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Result type pattern for explicit error handling
|
|
17
|
+
*/
|
|
18
|
+
export type Result<T, E> = {
|
|
19
|
+
ok: true;
|
|
20
|
+
value: T;
|
|
21
|
+
} | {
|
|
22
|
+
ok: false;
|
|
23
|
+
error: E;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Base class for all application errors with structured error support
|
|
27
|
+
*/
|
|
28
|
+
export declare abstract class BaseError extends Error {
|
|
29
|
+
abstract readonly code: string;
|
|
30
|
+
abstract readonly suggestion: string;
|
|
31
|
+
readonly timestamp: string;
|
|
32
|
+
readonly context: Record<string, unknown> | undefined;
|
|
33
|
+
constructor(message: string, context?: Record<string, unknown>);
|
|
34
|
+
toStructuredError(): StructuredError;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Error for input validation failures
|
|
38
|
+
*/
|
|
39
|
+
export declare class InputValidationError extends BaseError {
|
|
40
|
+
readonly suggestion: string;
|
|
41
|
+
readonly code = "INPUT_VALIDATION_ERROR";
|
|
42
|
+
constructor(message: string, suggestion: string);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Error for file operation failures with intelligent suggestion system
|
|
46
|
+
*/
|
|
47
|
+
export declare class FileOperationError extends BaseError {
|
|
48
|
+
readonly code = "FILE_OPERATION_ERROR";
|
|
49
|
+
get suggestion(): string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Error for Gemini API failures with intelligent suggestion system
|
|
53
|
+
*/
|
|
54
|
+
export declare class GeminiAPIError extends BaseError {
|
|
55
|
+
readonly code = "GEMINI_API_ERROR";
|
|
56
|
+
private customSuggestion?;
|
|
57
|
+
constructor(message: string, suggestionOrContext?: string | Record<string, unknown>, statusCodeOrContext?: number | Record<string, unknown>);
|
|
58
|
+
get suggestion(): string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Error for network-related failures with intelligent suggestion system
|
|
62
|
+
*/
|
|
63
|
+
export declare class NetworkError extends BaseError {
|
|
64
|
+
readonly code = "NETWORK_ERROR";
|
|
65
|
+
private customSuggestion?;
|
|
66
|
+
constructor(message: string, suggestionOrContext?: string | Record<string, unknown>, causeOrContext?: Error | Record<string, unknown>);
|
|
67
|
+
get suggestion(): string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Error for configuration failures
|
|
71
|
+
*/
|
|
72
|
+
export declare class ConfigError extends BaseError {
|
|
73
|
+
readonly suggestion: string;
|
|
74
|
+
readonly code = "CONFIG_ERROR";
|
|
75
|
+
constructor(message: string, suggestion: string);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Error for security violations and attacks with intelligent suggestion system
|
|
79
|
+
*/
|
|
80
|
+
export declare class SecurityError extends BaseError {
|
|
81
|
+
readonly code = "SECURITY_ERROR";
|
|
82
|
+
get suggestion(): string;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,C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C,EACtD,mBAAmB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAwBxD,IAAI,UAAU,IAAI,MAAM,CAmCvB;CACF;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,SAAS;IACzC,QAAQ,CAAC,IAAI,mBAAkB;IAC/B,OAAO,CAAC,gBAAgB,CAAC,CAAQ;gBAG/B,OAAO,EAAE,MAAM,EACf,mBAAmB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtD,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAwBlD,IAAI,UAAU,IAAI,MAAM,CA2BvB;CACF;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,SAAS;aAKtB,UAAU,EAAE,MAAM;IAJpC,QAAQ,CAAC,IAAI,kBAAiB;gBAG5B,OAAO,EAAE,MAAM,EACC,UAAU,EAAE,MAAM;CAIrC;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,SAAS;IAC1C,QAAQ,CAAC,IAAI,oBAAmB;IAEhC,IAAI,UAAU,IAAI,MAAM,CAwBvB;CACF"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error classes for MCP server
|
|
3
|
+
* Provides specific error types with structured error codes and suggestions
|
|
4
|
+
*/
|
|
5
|
+
import { GEMINI_MODELS } from '../types/mcp.js';
|
|
6
|
+
/**
|
|
7
|
+
* Base class for all application errors with structured error support
|
|
8
|
+
*/
|
|
9
|
+
export class BaseError extends Error {
|
|
10
|
+
constructor(message, context) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = this.constructor.name;
|
|
13
|
+
this.timestamp = new Date().toISOString();
|
|
14
|
+
this.context = context;
|
|
15
|
+
}
|
|
16
|
+
toStructuredError() {
|
|
17
|
+
return {
|
|
18
|
+
code: this.code,
|
|
19
|
+
message: this.message,
|
|
20
|
+
suggestion: this.suggestion,
|
|
21
|
+
timestamp: this.timestamp,
|
|
22
|
+
...(this.context && { context: this.context }),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Error for input validation failures
|
|
28
|
+
*/
|
|
29
|
+
export class InputValidationError extends BaseError {
|
|
30
|
+
constructor(message, suggestion) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.suggestion = suggestion;
|
|
33
|
+
this.code = 'INPUT_VALIDATION_ERROR';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Error for file operation failures with intelligent suggestion system
|
|
38
|
+
*/
|
|
39
|
+
export class FileOperationError extends BaseError {
|
|
40
|
+
constructor() {
|
|
41
|
+
super(...arguments);
|
|
42
|
+
this.code = 'FILE_OPERATION_ERROR';
|
|
43
|
+
}
|
|
44
|
+
get suggestion() {
|
|
45
|
+
const message = this.message.toLowerCase();
|
|
46
|
+
if (message.includes('permission') ||
|
|
47
|
+
message.includes('eacces') ||
|
|
48
|
+
message.includes('access denied')) {
|
|
49
|
+
return 'Check file and directory permissions for the output path';
|
|
50
|
+
}
|
|
51
|
+
if (message.includes('space') || message.includes('enospc') || message.includes('disk full')) {
|
|
52
|
+
return 'Free up disk space or choose a different output directory';
|
|
53
|
+
}
|
|
54
|
+
if (message.includes('enoent') ||
|
|
55
|
+
message.includes('no such file') ||
|
|
56
|
+
message.includes('not found')) {
|
|
57
|
+
return 'Ensure the output directory exists and is accessible';
|
|
58
|
+
}
|
|
59
|
+
if (message.includes('emfile') ||
|
|
60
|
+
message.includes('too many') ||
|
|
61
|
+
message.includes('file descriptor')) {
|
|
62
|
+
return 'Close unused files or restart the application to free file handles';
|
|
63
|
+
}
|
|
64
|
+
if (message.includes('readonly') || message.includes('read-only')) {
|
|
65
|
+
return 'Choose a writable directory for file output';
|
|
66
|
+
}
|
|
67
|
+
return 'Check file system permissions and available disk space';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Error for Gemini API failures with intelligent suggestion system
|
|
72
|
+
*/
|
|
73
|
+
export class GeminiAPIError extends BaseError {
|
|
74
|
+
constructor(message, suggestionOrContext, statusCodeOrContext) {
|
|
75
|
+
let context;
|
|
76
|
+
let statusCode;
|
|
77
|
+
// Handle backward compatibility with old constructor signature
|
|
78
|
+
if (typeof suggestionOrContext === 'string') {
|
|
79
|
+
// Old signature: (message, suggestion, statusCode?)
|
|
80
|
+
statusCode = typeof statusCodeOrContext === 'number' ? statusCodeOrContext : undefined;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// New signature: (message, context?, statusCode?)
|
|
84
|
+
context = suggestionOrContext;
|
|
85
|
+
statusCode = typeof statusCodeOrContext === 'number' ? statusCodeOrContext : undefined;
|
|
86
|
+
}
|
|
87
|
+
super(message, context);
|
|
88
|
+
this.code = 'GEMINI_API_ERROR';
|
|
89
|
+
if (typeof suggestionOrContext === 'string') {
|
|
90
|
+
this.customSuggestion = suggestionOrContext;
|
|
91
|
+
}
|
|
92
|
+
Object.defineProperty(this, 'statusCode', { value: statusCode, writable: false });
|
|
93
|
+
}
|
|
94
|
+
get suggestion() {
|
|
95
|
+
// Use custom suggestion if provided (backward compatibility)
|
|
96
|
+
if (this.customSuggestion) {
|
|
97
|
+
return this.customSuggestion;
|
|
98
|
+
}
|
|
99
|
+
// Check if suggestion is in context
|
|
100
|
+
if (this.context &&
|
|
101
|
+
'suggestion' in this.context &&
|
|
102
|
+
typeof this.context['suggestion'] === 'string') {
|
|
103
|
+
return this.context['suggestion'];
|
|
104
|
+
}
|
|
105
|
+
// Otherwise use intelligent suggestion system
|
|
106
|
+
const message = this.message.toLowerCase();
|
|
107
|
+
if (message.includes('authentication') || message.includes('unauthorized')) {
|
|
108
|
+
return 'Check GEMINI_API_KEY environment variable and ensure it has proper permissions';
|
|
109
|
+
}
|
|
110
|
+
if (message.includes('rate limit') || message.includes('quota') || message.includes('429')) {
|
|
111
|
+
return 'Wait before retrying or upgrade API quota limits';
|
|
112
|
+
}
|
|
113
|
+
if (message.includes('model') || message.includes('access') || message.includes('permission')) {
|
|
114
|
+
return `Ensure you have access to the Gemini image generation models (${GEMINI_MODELS.FLASH} or ${GEMINI_MODELS.PRO})`;
|
|
115
|
+
}
|
|
116
|
+
if (message.includes('timeout') || message.includes('503') || message.includes('502')) {
|
|
117
|
+
return 'The service is temporarily unavailable. Please retry after a few moments';
|
|
118
|
+
}
|
|
119
|
+
if (message.includes('payload') || message.includes('request') || message.includes('400')) {
|
|
120
|
+
return 'Check request format and parameters according to API specification';
|
|
121
|
+
}
|
|
122
|
+
return 'Check API configuration and retry the request';
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Error for network-related failures with intelligent suggestion system
|
|
127
|
+
*/
|
|
128
|
+
export class NetworkError extends BaseError {
|
|
129
|
+
constructor(message, suggestionOrContext, causeOrContext) {
|
|
130
|
+
let context;
|
|
131
|
+
let cause;
|
|
132
|
+
// Handle backward compatibility with old constructor signature
|
|
133
|
+
if (typeof suggestionOrContext === 'string') {
|
|
134
|
+
// Old signature: (message, suggestion, cause?)
|
|
135
|
+
cause = causeOrContext instanceof Error ? causeOrContext : undefined;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
// New signature: (message, context?, cause?)
|
|
139
|
+
context = suggestionOrContext;
|
|
140
|
+
cause = causeOrContext instanceof Error ? causeOrContext : undefined;
|
|
141
|
+
}
|
|
142
|
+
super(message, context);
|
|
143
|
+
this.code = 'NETWORK_ERROR';
|
|
144
|
+
if (typeof suggestionOrContext === 'string') {
|
|
145
|
+
this.customSuggestion = suggestionOrContext;
|
|
146
|
+
}
|
|
147
|
+
Object.defineProperty(this, 'cause', { value: cause, writable: false });
|
|
148
|
+
}
|
|
149
|
+
get suggestion() {
|
|
150
|
+
// Use custom suggestion if provided (backward compatibility)
|
|
151
|
+
if (this.customSuggestion) {
|
|
152
|
+
return this.customSuggestion;
|
|
153
|
+
}
|
|
154
|
+
// Otherwise use intelligent suggestion system
|
|
155
|
+
const message = this.message.toLowerCase();
|
|
156
|
+
const stack = this.stack?.toLowerCase() || '';
|
|
157
|
+
if (message.includes('timeout') || message.includes('etimedout')) {
|
|
158
|
+
return 'Check network connection stability and retry with higher timeout';
|
|
159
|
+
}
|
|
160
|
+
if (message.includes('dns') || message.includes('enotfound') || stack.includes('getaddrinfo')) {
|
|
161
|
+
return 'Check internet connection and DNS settings';
|
|
162
|
+
}
|
|
163
|
+
if (message.includes('econnrefused') || message.includes('connection refused')) {
|
|
164
|
+
return 'Service may be temporarily unavailable, please retry later';
|
|
165
|
+
}
|
|
166
|
+
if (message.includes('econnreset') || message.includes('connection reset')) {
|
|
167
|
+
return 'Network connection was interrupted, please retry';
|
|
168
|
+
}
|
|
169
|
+
if (message.includes('proxy') || message.includes('tunnel')) {
|
|
170
|
+
return 'Check proxy settings and firewall configuration';
|
|
171
|
+
}
|
|
172
|
+
return 'Check network connectivity and firewall settings';
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Error for configuration failures
|
|
177
|
+
*/
|
|
178
|
+
export class ConfigError extends BaseError {
|
|
179
|
+
constructor(message, suggestion) {
|
|
180
|
+
super(message);
|
|
181
|
+
this.suggestion = suggestion;
|
|
182
|
+
this.code = 'CONFIG_ERROR';
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Error for security violations and attacks with intelligent suggestion system
|
|
187
|
+
*/
|
|
188
|
+
export class SecurityError extends BaseError {
|
|
189
|
+
constructor() {
|
|
190
|
+
super(...arguments);
|
|
191
|
+
this.code = 'SECURITY_ERROR';
|
|
192
|
+
}
|
|
193
|
+
get suggestion() {
|
|
194
|
+
const message = this.message.toLowerCase();
|
|
195
|
+
if (message.includes('null byte')) {
|
|
196
|
+
return 'Ensure your request meets security requirements';
|
|
197
|
+
}
|
|
198
|
+
if (message.includes('path') || message.includes('traversal') || message.includes('..')) {
|
|
199
|
+
return 'Use valid file paths within allowed directories only';
|
|
200
|
+
}
|
|
201
|
+
if (message.includes('extension') ||
|
|
202
|
+
message.includes('filetype') ||
|
|
203
|
+
message.includes('format')) {
|
|
204
|
+
return 'Use supported file extensions: .png, .jpg, .jpeg, .webp';
|
|
205
|
+
}
|
|
206
|
+
if (message.includes('size') || message.includes('large') || message.includes('limit')) {
|
|
207
|
+
return 'Ensure file size is within allowed limits (max 10MB)';
|
|
208
|
+
}
|
|
209
|
+
if (message.includes('malicious') || message.includes('suspicious')) {
|
|
210
|
+
return 'The request contains potentially harmful content. Please review and try again';
|
|
211
|
+
}
|
|
212
|
+
return 'Ensure your request meets security requirements';
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAkB/C;;GAEG;AACH,MAAM,OAAgB,SAAU,SAAQ,KAAK;IAM3C,YAAY,OAAe,EAAE,OAAiC;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;QACjC,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,iBAAiB;QACf,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;SAC/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AAE,CAAC;YACxF,OAAO,sDAAsD,CAAA;QAC/D,CAAC;QACD,IACE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC;YAC7B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC;YAC5B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAC1B,CAAC;YACD,OAAO,yDAAyD,CAAA;QAClE,CAAC;QACD,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACvF,OAAO,sDAAsD,CAAA;QAC/D,CAAC;QACD,IAAI,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;YACpE,OAAO,+EAA+E,CAAA;QACxF,CAAC;QAED,OAAO,iDAAiD,CAAA;IAC1D,CAAC;CACF"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger utility for structured logging with sensitive data filtering
|
|
3
|
+
* Provides consistent logging format across the application
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Logger class for structured logging with sensitive data protection
|
|
7
|
+
*/
|
|
8
|
+
export declare class Logger {
|
|
9
|
+
private readonly sensitivePatterns;
|
|
10
|
+
private readonly urlPatterns;
|
|
11
|
+
private readonly filterPatterns;
|
|
12
|
+
private readonly keyBasedSensitivePatterns;
|
|
13
|
+
private currentTraceId?;
|
|
14
|
+
private currentSessionId?;
|
|
15
|
+
constructor();
|
|
16
|
+
/**
|
|
17
|
+
* Log a debug message (only in development mode)
|
|
18
|
+
* @param context Context or module where the log originates
|
|
19
|
+
* @param message Log message
|
|
20
|
+
* @param metadata Optional metadata object
|
|
21
|
+
*/
|
|
22
|
+
debug(context: string, message: string, metadata?: Record<string, unknown>): void;
|
|
23
|
+
/**
|
|
24
|
+
* Log an info message
|
|
25
|
+
* @param context Context or module where the log originates
|
|
26
|
+
* @param message Log message
|
|
27
|
+
* @param metadata Optional metadata object
|
|
28
|
+
*/
|
|
29
|
+
info(context: string, message: string, metadata?: Record<string, unknown>): void;
|
|
30
|
+
/**
|
|
31
|
+
* Log a warning message
|
|
32
|
+
* @param context Context or module where the log originates
|
|
33
|
+
* @param message Log message
|
|
34
|
+
* @param metadata Optional metadata object
|
|
35
|
+
*/
|
|
36
|
+
warn(context: string, message: string, metadata?: Record<string, unknown>): void;
|
|
37
|
+
/**
|
|
38
|
+
* Log an error message
|
|
39
|
+
* @param context Context or module where the log originates
|
|
40
|
+
* @param message Log message
|
|
41
|
+
* @param error Optional error object
|
|
42
|
+
* @param metadata Optional metadata object
|
|
43
|
+
*/
|
|
44
|
+
error(context: string, message: string, error?: Error, metadata?: Record<string, unknown>): void;
|
|
45
|
+
/**
|
|
46
|
+
* Core log writing method with structured format
|
|
47
|
+
*/
|
|
48
|
+
private writeLog;
|
|
49
|
+
/**
|
|
50
|
+
* Sanitize string content by redacting sensitive information
|
|
51
|
+
* @param input String to sanitize
|
|
52
|
+
* @returns Sanitized string
|
|
53
|
+
*/
|
|
54
|
+
private sanitizeString;
|
|
55
|
+
/**
|
|
56
|
+
* Sanitize metadata by redacting sensitive information
|
|
57
|
+
* @param metadata Metadata object to sanitize
|
|
58
|
+
* @returns Sanitized metadata object
|
|
59
|
+
*/
|
|
60
|
+
private sanitizeMetadata;
|
|
61
|
+
/**
|
|
62
|
+
* Check if a key contains sensitive information
|
|
63
|
+
* @param key Object key to check
|
|
64
|
+
* @returns True if the key contains sensitive information
|
|
65
|
+
*/
|
|
66
|
+
private isSensitiveKey;
|
|
67
|
+
/**
|
|
68
|
+
* Generate unique ID for trace/session tracking
|
|
69
|
+
*/
|
|
70
|
+
private generateId;
|
|
71
|
+
/**
|
|
72
|
+
* Get or generate current trace ID
|
|
73
|
+
*/
|
|
74
|
+
private getCurrentTraceId;
|
|
75
|
+
/**
|
|
76
|
+
* Get current session ID
|
|
77
|
+
*/
|
|
78
|
+
private getCurrentSessionId;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiBH;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAOjC;IAED,OAAO,CAAC,QAAQ,CAAC,WAAW,CAE3B;IAED,OAAO,CAAC,QAAQ,CAAC,cAAc,CAK9B;IAED,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAQzC;IAED,OAAO,CAAC,cAAc,CAAC,CAAQ;IAC/B,OAAO,CAAC,gBAAgB,CAAC,CAAQ;;IAOjC;;;;;OAKG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAKjF;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAIhF;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAIhF;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAYhG;;OAEG;IACH,OAAO,CAAC,QAAQ;IAwBhB;;;;OAIG;IACH,OAAO,CAAC,cAAc;IA6Bt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