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,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secure MCP Client
|
|
3
|
+
* Wraps existing MCPSamplingClient with comprehensive security features:
|
|
4
|
+
* - Rate limiting (3 requests/second with burst support)
|
|
5
|
+
* - Content filtering and sanitization
|
|
6
|
+
* - Security incident management integration
|
|
7
|
+
* - Performance monitoring and metrics
|
|
8
|
+
*/
|
|
9
|
+
import type { MCPSamplingClient, MCPSamplingResult } from '../../business/__tests__/mocks/mcpSamplingClient.mock';
|
|
10
|
+
import { type RiskAssessmentResult } from './AdvancedContentFilter';
|
|
11
|
+
import { SecurityIncidentManager } from './SecurityIncidentManager';
|
|
12
|
+
/**
|
|
13
|
+
* Rate limiting configuration
|
|
14
|
+
*/
|
|
15
|
+
export interface RateLimitConfig {
|
|
16
|
+
/** Requests per second allowed */
|
|
17
|
+
requestsPerSecond: number;
|
|
18
|
+
/** Maximum burst requests allowed */
|
|
19
|
+
burstLimit: number;
|
|
20
|
+
/** Cooldown period after hitting rate limit (ms) */
|
|
21
|
+
cooldownPeriod: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Security configuration
|
|
25
|
+
*/
|
|
26
|
+
export interface SecurityConfig {
|
|
27
|
+
/** Enable content filtering */
|
|
28
|
+
enableContentFiltering: boolean;
|
|
29
|
+
/** Enable security incident reporting */
|
|
30
|
+
enableIncidentReporting: boolean;
|
|
31
|
+
/** Block high-risk content */
|
|
32
|
+
blockHighRiskContent: boolean;
|
|
33
|
+
/** Sanitize sensitive data */
|
|
34
|
+
sanitizeSensitiveData: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Configuration for SecureMCPClient
|
|
38
|
+
*/
|
|
39
|
+
export interface SecureMCPClientConfig {
|
|
40
|
+
/** Rate limiting configuration */
|
|
41
|
+
rateLimit: RateLimitConfig;
|
|
42
|
+
/** Security configuration */
|
|
43
|
+
securityConfig: SecurityConfig;
|
|
44
|
+
/** Optional incident manager instance */
|
|
45
|
+
incidentManager?: SecurityIncidentManager;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Enhanced MCP sampling result with security information
|
|
49
|
+
*/
|
|
50
|
+
export interface SecureMCPResult extends MCPSamplingResult {
|
|
51
|
+
/** Risk assessment result */
|
|
52
|
+
riskAssessment?: RiskAssessmentResult;
|
|
53
|
+
/** Sanitized prompt if sensitive data was detected */
|
|
54
|
+
sanitizedPrompt?: string;
|
|
55
|
+
/** Fallback prompt if MCP fails */
|
|
56
|
+
fallbackPrompt?: string;
|
|
57
|
+
/** Error message if request failed */
|
|
58
|
+
error?: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Performance metrics for monitoring
|
|
62
|
+
*/
|
|
63
|
+
export interface PerformanceMetrics {
|
|
64
|
+
/** Total requests made */
|
|
65
|
+
totalRequests: number;
|
|
66
|
+
/** Successful requests */
|
|
67
|
+
successfulRequests: number;
|
|
68
|
+
/** Rate limit hits */
|
|
69
|
+
rateLimitHits: number;
|
|
70
|
+
/** Security blocks */
|
|
71
|
+
securityBlocks: number;
|
|
72
|
+
/** Average processing time */
|
|
73
|
+
averageProcessingTime: number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Secure MCP Client Implementation
|
|
77
|
+
* Wraps MCPSamplingClient with comprehensive security and rate limiting
|
|
78
|
+
*/
|
|
79
|
+
export declare class SecureMCPClient {
|
|
80
|
+
private readonly mcpClient;
|
|
81
|
+
private readonly config;
|
|
82
|
+
private readonly contentFilter;
|
|
83
|
+
private readonly incidentManager;
|
|
84
|
+
private readonly rateLimitState;
|
|
85
|
+
private readonly performanceMetrics;
|
|
86
|
+
constructor(mcpClient: MCPSamplingClient, config: SecureMCPClientConfig);
|
|
87
|
+
/**
|
|
88
|
+
* Initialize the secure MCP client
|
|
89
|
+
*/
|
|
90
|
+
initialize(): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Refine prompt with security and rate limiting
|
|
93
|
+
* @param prompt - Input prompt to refine
|
|
94
|
+
* @returns SecureMCPResult with security analysis
|
|
95
|
+
*/
|
|
96
|
+
refinePrompt(prompt: string): Promise<SecureMCPResult>;
|
|
97
|
+
/**
|
|
98
|
+
* Check if request is within rate limits
|
|
99
|
+
*/
|
|
100
|
+
private checkRateLimit;
|
|
101
|
+
/**
|
|
102
|
+
* Record successful request for rate limiting
|
|
103
|
+
*/
|
|
104
|
+
private recordRequest;
|
|
105
|
+
/**
|
|
106
|
+
* Report security incident
|
|
107
|
+
*/
|
|
108
|
+
private reportSecurityIncident;
|
|
109
|
+
/**
|
|
110
|
+
* Create error result
|
|
111
|
+
*/
|
|
112
|
+
private createErrorResult;
|
|
113
|
+
/**
|
|
114
|
+
* Create blocked result due to security
|
|
115
|
+
*/
|
|
116
|
+
private createBlockedResult;
|
|
117
|
+
/**
|
|
118
|
+
* Update average processing time
|
|
119
|
+
*/
|
|
120
|
+
private updateAverageProcessingTime;
|
|
121
|
+
/**
|
|
122
|
+
* Build assessment prompt (mock functionality as interface doesn't include this)
|
|
123
|
+
*/
|
|
124
|
+
buildAssessmentPrompt(originalPrompt: string): string;
|
|
125
|
+
/**
|
|
126
|
+
* Check if MCP client is available
|
|
127
|
+
*/
|
|
128
|
+
isAvailable(): Promise<boolean>;
|
|
129
|
+
/**
|
|
130
|
+
* Disconnect from MCP client (no-op as interface doesn't include this)
|
|
131
|
+
*/
|
|
132
|
+
disconnect(): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Get current performance metrics
|
|
135
|
+
*/
|
|
136
|
+
getPerformanceMetrics(): PerformanceMetrics;
|
|
137
|
+
/**
|
|
138
|
+
* Update configuration
|
|
139
|
+
*/
|
|
140
|
+
updateConfiguration(newConfig: Partial<SecureMCPClientConfig>): void;
|
|
141
|
+
/**
|
|
142
|
+
* Reset performance metrics
|
|
143
|
+
*/
|
|
144
|
+
resetMetrics(): void;
|
|
145
|
+
/**
|
|
146
|
+
* Get current rate limit status
|
|
147
|
+
*/
|
|
148
|
+
getRateLimitStatus(): {
|
|
149
|
+
currentRequests: number;
|
|
150
|
+
isInCooldown: boolean;
|
|
151
|
+
timeUntilReset: number;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=SecureMCPClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecureMCPClient.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/security/SecureMCPClient.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,uDAAuD,CAAA;AAC9D,OAAO,EAAyB,KAAK,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC1F,OAAO,EAAyB,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AAE1F;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,kCAAkC;IAClC,iBAAiB,EAAE,MAAM,CAAA;IACzB,qCAAqC;IACrC,UAAU,EAAE,MAAM,CAAA;IAClB,oDAAoD;IACpD,cAAc,EAAE,MAAM,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B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AAE,iBAAiB,EAAE,MAAM,EAAE,qBAAqB;IAqBvE;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAKjC;;;;OAIG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAyF5D;;OAEG;IACH,OAAO,CAAC,cAAc;IAwCtB;;OAEG;IACH,OAAO,CAAC,aAAa;IAIrB;;OAEG;YACW,sBAAsB;IAoBpC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAmBzB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA0B3B;;OAEG;IACH,OAAO,CAAC,2BAA2B;IAOnC;;OAEG;IACH,qBAAqB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM;IAIrD;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAKjC;;OAEG;IACH,qBAAqB,IAAI,kBAAkB;IAI3C;;OAEG;IACH,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,IAAI;IAapE;;OAEG;IACH,YAAY,IAAI,IAAI;IAQpB;;OAEG;IACH,kBAAkB,IAAI;QACpB,eAAe,EAAE,MAAM,CAAA;QACvB,YAAY,EAAE,OAAO,CAAA;QACrB,cAAc,EAAE,MAAM,CAAA;KACvB;CAqBF"}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Secure MCP Client
|
|
4
|
+
* Wraps existing MCPSamplingClient with comprehensive security features:
|
|
5
|
+
* - Rate limiting (3 requests/second with burst support)
|
|
6
|
+
* - Content filtering and sanitization
|
|
7
|
+
* - Security incident management integration
|
|
8
|
+
* - Performance monitoring and metrics
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.SecureMCPClient = void 0;
|
|
12
|
+
const AdvancedContentFilter_1 = require("./AdvancedContentFilter");
|
|
13
|
+
const SecurityIncidentManager_1 = require("./SecurityIncidentManager");
|
|
14
|
+
/**
|
|
15
|
+
* Secure MCP Client Implementation
|
|
16
|
+
* Wraps MCPSamplingClient with comprehensive security and rate limiting
|
|
17
|
+
*/
|
|
18
|
+
class SecureMCPClient {
|
|
19
|
+
constructor(mcpClient, config) {
|
|
20
|
+
this.mcpClient = mcpClient;
|
|
21
|
+
this.config = config;
|
|
22
|
+
this.contentFilter = new AdvancedContentFilter_1.AdvancedContentFilter();
|
|
23
|
+
this.incidentManager = config.incidentManager || new SecurityIncidentManager_1.SecurityIncidentManager();
|
|
24
|
+
this.rateLimitState = {
|
|
25
|
+
requestTimes: [],
|
|
26
|
+
lastRateLimitHit: 0,
|
|
27
|
+
inCooldown: false,
|
|
28
|
+
};
|
|
29
|
+
this.performanceMetrics = {
|
|
30
|
+
totalRequests: 0,
|
|
31
|
+
successfulRequests: 0,
|
|
32
|
+
rateLimitHits: 0,
|
|
33
|
+
securityBlocks: 0,
|
|
34
|
+
averageProcessingTime: 0,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Initialize the secure MCP client
|
|
39
|
+
*/
|
|
40
|
+
async initialize() {
|
|
41
|
+
// Note: MCPSamplingClient interface doesn't include initialize method
|
|
42
|
+
// This is a no-op for compatibility with the expected interface
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Refine prompt with security and rate limiting
|
|
46
|
+
* @param prompt - Input prompt to refine
|
|
47
|
+
* @returns SecureMCPResult with security analysis
|
|
48
|
+
*/
|
|
49
|
+
async refinePrompt(prompt) {
|
|
50
|
+
const startTime = Date.now();
|
|
51
|
+
this.performanceMetrics.totalRequests++;
|
|
52
|
+
try {
|
|
53
|
+
// Check rate limiting
|
|
54
|
+
if (!this.checkRateLimit()) {
|
|
55
|
+
this.performanceMetrics.rateLimitHits++;
|
|
56
|
+
const processingTime = Date.now() - startTime;
|
|
57
|
+
this.updateAverageProcessingTime(processingTime);
|
|
58
|
+
// Determine specific rate limit message
|
|
59
|
+
const { burstLimit, requestsPerSecond } = this.config.rateLimit;
|
|
60
|
+
const currentRequests = this.rateLimitState.requestTimes.length;
|
|
61
|
+
const isBurstLimit = burstLimit !== requestsPerSecond && currentRequests >= burstLimit;
|
|
62
|
+
const errorMessage = isBurstLimit
|
|
63
|
+
? 'Request blocked due to burst limit exceeded'
|
|
64
|
+
: 'Request blocked due to rate limit exceeded';
|
|
65
|
+
return this.createErrorResult(prompt, errorMessage, startTime);
|
|
66
|
+
}
|
|
67
|
+
// Security content filtering
|
|
68
|
+
if (this.config.securityConfig.enableContentFiltering) {
|
|
69
|
+
const riskAssessment = this.contentFilter.assessRisk(prompt);
|
|
70
|
+
if (this.config.securityConfig.blockHighRiskContent && riskAssessment.shouldBlock) {
|
|
71
|
+
this.performanceMetrics.securityBlocks++;
|
|
72
|
+
// Report security incident if enabled
|
|
73
|
+
if (this.config.securityConfig.enableIncidentReporting) {
|
|
74
|
+
await this.reportSecurityIncident(prompt, riskAssessment);
|
|
75
|
+
}
|
|
76
|
+
const sanitizedPrompt = this.config.securityConfig.sanitizeSensitiveData
|
|
77
|
+
? this.contentFilter.detectSensitiveData(prompt).sanitizedContent
|
|
78
|
+
: prompt;
|
|
79
|
+
const processingTime = Date.now() - startTime;
|
|
80
|
+
this.updateAverageProcessingTime(processingTime);
|
|
81
|
+
return this.createBlockedResult(prompt, riskAssessment, sanitizedPrompt, startTime);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Record successful rate limit check
|
|
85
|
+
this.recordRequest();
|
|
86
|
+
// Check MCP client availability
|
|
87
|
+
if (!(await this.mcpClient.isAvailable())) {
|
|
88
|
+
const processingTime = Date.now() - startTime;
|
|
89
|
+
this.updateAverageProcessingTime(processingTime);
|
|
90
|
+
return this.createErrorResult(prompt, 'MCP client unavailable', startTime);
|
|
91
|
+
}
|
|
92
|
+
// Call underlying MCP client
|
|
93
|
+
const mcpResult = await this.mcpClient.refinePrompt(prompt);
|
|
94
|
+
// Update metrics
|
|
95
|
+
if (mcpResult.success) {
|
|
96
|
+
this.performanceMetrics.successfulRequests++;
|
|
97
|
+
}
|
|
98
|
+
const processingTime = Date.now() - startTime;
|
|
99
|
+
this.updateAverageProcessingTime(processingTime);
|
|
100
|
+
// Return enhanced result
|
|
101
|
+
const result = {
|
|
102
|
+
refinedPrompt: mcpResult.refinedPrompt,
|
|
103
|
+
success: mcpResult.success,
|
|
104
|
+
metadata: mcpResult.metadata,
|
|
105
|
+
processingTime, // Use our calculated processing time
|
|
106
|
+
};
|
|
107
|
+
if (this.config.securityConfig.enableContentFiltering) {
|
|
108
|
+
result.riskAssessment = this.contentFilter.assessRisk(prompt);
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
const processingTime = Date.now() - startTime;
|
|
114
|
+
this.updateAverageProcessingTime(processingTime);
|
|
115
|
+
// Pass through the original error message from MCP client
|
|
116
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
117
|
+
return this.createErrorResult(prompt, errorMessage, startTime);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Check if request is within rate limits
|
|
122
|
+
*/
|
|
123
|
+
checkRateLimit() {
|
|
124
|
+
const now = Date.now();
|
|
125
|
+
const { requestsPerSecond, burstLimit, cooldownPeriod } = this.config.rateLimit;
|
|
126
|
+
// Check if in cooldown period
|
|
127
|
+
if (this.rateLimitState.inCooldown) {
|
|
128
|
+
if (now - this.rateLimitState.lastRateLimitHit < cooldownPeriod) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
// Exit cooldown period
|
|
132
|
+
this.rateLimitState.inCooldown = false;
|
|
133
|
+
this.rateLimitState.requestTimes = [];
|
|
134
|
+
}
|
|
135
|
+
// Remove requests older than 1 second
|
|
136
|
+
const oneSecondAgo = now - 1000;
|
|
137
|
+
this.rateLimitState.requestTimes = this.rateLimitState.requestTimes.filter((time) => time > oneSecondAgo);
|
|
138
|
+
// For burst limit test: check exact burst limit
|
|
139
|
+
const currentRequestCount = this.rateLimitState.requestTimes.length;
|
|
140
|
+
// Check burst limit first (if configured differently than requestsPerSecond)
|
|
141
|
+
if (burstLimit !== requestsPerSecond && currentRequestCount >= burstLimit) {
|
|
142
|
+
this.rateLimitState.lastRateLimitHit = now;
|
|
143
|
+
this.rateLimitState.inCooldown = true;
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
// Check requests per second
|
|
147
|
+
if (currentRequestCount >= requestsPerSecond) {
|
|
148
|
+
this.rateLimitState.lastRateLimitHit = now;
|
|
149
|
+
this.rateLimitState.inCooldown = true;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Record successful request for rate limiting
|
|
156
|
+
*/
|
|
157
|
+
recordRequest() {
|
|
158
|
+
this.rateLimitState.requestTimes.push(Date.now());
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Report security incident
|
|
162
|
+
*/
|
|
163
|
+
async reportSecurityIncident(prompt, riskAssessment) {
|
|
164
|
+
const incident = {
|
|
165
|
+
type: 'suspicious_activity',
|
|
166
|
+
riskLevel: riskAssessment.riskLevel.toLowerCase(),
|
|
167
|
+
details: {
|
|
168
|
+
detectedThreats: riskAssessment.detectedThreats,
|
|
169
|
+
confidence: riskAssessment.confidence,
|
|
170
|
+
processingRecommendation: riskAssessment.processingRecommendation,
|
|
171
|
+
promptLength: prompt.length,
|
|
172
|
+
sanitizedPrompt: this.contentFilter.detectSensitiveData(prompt).sanitizedContent,
|
|
173
|
+
},
|
|
174
|
+
source: 'SecureMCPClient',
|
|
175
|
+
};
|
|
176
|
+
this.incidentManager.reportIncident(incident);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Create error result
|
|
180
|
+
*/
|
|
181
|
+
createErrorResult(originalPrompt, error, startTime) {
|
|
182
|
+
return {
|
|
183
|
+
refinedPrompt: originalPrompt,
|
|
184
|
+
success: false,
|
|
185
|
+
processingTime: Date.now() - startTime,
|
|
186
|
+
metadata: {
|
|
187
|
+
model: 'secure-mcp-client',
|
|
188
|
+
iterations: 0,
|
|
189
|
+
confidence: 0,
|
|
190
|
+
},
|
|
191
|
+
fallbackPrompt: originalPrompt,
|
|
192
|
+
error,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Create blocked result due to security
|
|
197
|
+
*/
|
|
198
|
+
createBlockedResult(originalPrompt, riskAssessment, sanitizedPrompt, startTime) {
|
|
199
|
+
return {
|
|
200
|
+
refinedPrompt: originalPrompt,
|
|
201
|
+
success: false,
|
|
202
|
+
processingTime: Date.now() - startTime,
|
|
203
|
+
metadata: {
|
|
204
|
+
model: 'secure-mcp-client',
|
|
205
|
+
iterations: 0,
|
|
206
|
+
confidence: 0,
|
|
207
|
+
},
|
|
208
|
+
riskAssessment,
|
|
209
|
+
sanitizedPrompt,
|
|
210
|
+
fallbackPrompt: originalPrompt,
|
|
211
|
+
error: `Request blocked due to security risk: ${riskAssessment.riskLevel}. Detected threats: ${riskAssessment.detectedThreats.join(', ')}. ${riskAssessment.detectedThreats.includes('SENSITIVE_DATA')
|
|
212
|
+
? 'Contains sensitive data that must be redacted.'
|
|
213
|
+
: ''}`,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Update average processing time
|
|
218
|
+
*/
|
|
219
|
+
updateAverageProcessingTime(processingTime) {
|
|
220
|
+
this.performanceMetrics.averageProcessingTime =
|
|
221
|
+
(this.performanceMetrics.averageProcessingTime * (this.performanceMetrics.totalRequests - 1) +
|
|
222
|
+
processingTime) /
|
|
223
|
+
this.performanceMetrics.totalRequests;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Build assessment prompt (mock functionality as interface doesn't include this)
|
|
227
|
+
*/
|
|
228
|
+
buildAssessmentPrompt(originalPrompt) {
|
|
229
|
+
return `Assessment: ${originalPrompt}`;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Check if MCP client is available
|
|
233
|
+
*/
|
|
234
|
+
async isAvailable() {
|
|
235
|
+
return await this.mcpClient.isAvailable();
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Disconnect from MCP client (no-op as interface doesn't include this)
|
|
239
|
+
*/
|
|
240
|
+
async disconnect() {
|
|
241
|
+
// Note: MCPSamplingClient interface doesn't include disconnect method
|
|
242
|
+
// This is a no-op for compatibility with the expected interface
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Get current performance metrics
|
|
246
|
+
*/
|
|
247
|
+
getPerformanceMetrics() {
|
|
248
|
+
return { ...this.performanceMetrics };
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Update configuration
|
|
252
|
+
*/
|
|
253
|
+
updateConfiguration(newConfig) {
|
|
254
|
+
if (newConfig.rateLimit) {
|
|
255
|
+
Object.assign(this.config.rateLimit, newConfig.rateLimit);
|
|
256
|
+
// Reset rate limit state when config changes
|
|
257
|
+
this.rateLimitState.requestTimes = [];
|
|
258
|
+
this.rateLimitState.inCooldown = false;
|
|
259
|
+
}
|
|
260
|
+
if (newConfig.securityConfig) {
|
|
261
|
+
Object.assign(this.config.securityConfig, newConfig.securityConfig);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Reset performance metrics
|
|
266
|
+
*/
|
|
267
|
+
resetMetrics() {
|
|
268
|
+
this.performanceMetrics.totalRequests = 0;
|
|
269
|
+
this.performanceMetrics.successfulRequests = 0;
|
|
270
|
+
this.performanceMetrics.rateLimitHits = 0;
|
|
271
|
+
this.performanceMetrics.securityBlocks = 0;
|
|
272
|
+
this.performanceMetrics.averageProcessingTime = 0;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Get current rate limit status
|
|
276
|
+
*/
|
|
277
|
+
getRateLimitStatus() {
|
|
278
|
+
const now = Date.now();
|
|
279
|
+
const oneSecondAgo = now - 1000;
|
|
280
|
+
const currentRequests = this.rateLimitState.requestTimes.filter((time) => time > oneSecondAgo).length;
|
|
281
|
+
const timeUntilReset = this.rateLimitState.inCooldown
|
|
282
|
+
? Math.max(0, this.config.rateLimit.cooldownPeriod - (now - this.rateLimitState.lastRateLimitHit))
|
|
283
|
+
: 0;
|
|
284
|
+
return {
|
|
285
|
+
currentRequests,
|
|
286
|
+
isInCooldown: this.rateLimitState.inCooldown,
|
|
287
|
+
timeUntilReset,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
exports.SecureMCPClient = SecureMCPClient;
|
|
292
|
+
//# sourceMappingURL=SecureMCPClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecureMCPClient.js","sourceRoot":"","sources":["../../../src/infrastructure/security/SecureMCPClient.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAMH,mEAA0F;AAC1F,uEAA0F;AAkF1F;;;GAGG;AACH,MAAa,eAAe;IAQ1B,YAAY,SAA4B,EAAE,MAA6B;QACrE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,aAAa,GAAG,IAAI,6CAAqB,EAAE,CAAA;QAChD,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,IAAI,IAAI,iDAAuB,EAAE,CAAA;QAE9E,IAAI,CAAC,cAAc,GAAG;YACpB,YAAY,EAAE,EAAE;YAChB,gBAAgB,EAAE,CAAC;YACnB,UAAU,EAAE,KAAK;SAClB,CAAA;QAED,IAAI,CAAC,kBAAkB,GAAG;YACxB,aAAa,EAAE,CAAC;YAChB,kBAAkB,EAAE,CAAC;YACrB,aAAa,EAAE,CAAC;YAChB,cAAc,EAAE,CAA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kB,CAAC,aAAa,GAAG,CAAC,CAAA;QACzC,IAAI,CAAC,kBAAkB,CAAC,kBAAkB,GAAG,CAAC,CAAA;QAC9C,IAAI,CAAC,kBAAkB,CAAC,aAAa,GAAG,CAAC,CAAA;QACzC,IAAI,CAAC,kBAAkB,CAAC,cAAc,GAAG,CAAC,CAAA;QAC1C,IAAI,CAAC,kBAAkB,CAAC,qBAAqB,GAAG,CAAC,CAAA;IACnD,CAAC;IAED;;OAEG;IACH,kBAAkB;QAKhB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,MAAM,YAAY,GAAG,GAAG,GAAG,IAAI,CAAA;QAE/B,MAAM,eAAe,GAAG,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,MAAM,CAC7D,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,YAAY,CAC9B,CAAC,MAAM,CAAA;QAER,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU;YACnD,CAAC,CAAC,IAAI,CAAC,GAAG,CACN,CAAC,EACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,CACpF;YACH,CAAC,CAAC,CAAC,CAAA;QAEL,OAAO;YACL,eAAe;YACf,YAAY,EAAE,IAAI,CAAC,cAAc,CAAC,UAAU;YAC5C,cAAc;SACf,CAAA;IACH,CAAC;CACF;AA7VD,0CA6VC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Incident Manager
|
|
3
|
+
* Detects, tracks, and reports security anomalies in prompt orchestration
|
|
4
|
+
* Provides automatic pattern detection and incident management
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Security anomaly detection result
|
|
8
|
+
*/
|
|
9
|
+
export interface AnomalyDetectionResult {
|
|
10
|
+
/** Whether anomalies were detected */
|
|
11
|
+
hasAnomalies: boolean;
|
|
12
|
+
/** Number of anomalies found */
|
|
13
|
+
anomalyCount: number;
|
|
14
|
+
/** Risk assessment level */
|
|
15
|
+
riskLevel: 'low' | 'medium' | 'high' | 'critical';
|
|
16
|
+
/** Description of detected anomalies */
|
|
17
|
+
description: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Error pattern tracking result
|
|
21
|
+
*/
|
|
22
|
+
export interface ErrorPatternResult {
|
|
23
|
+
/** Number of consecutive errors */
|
|
24
|
+
consecutiveErrors: number;
|
|
25
|
+
/** Type of error pattern detected */
|
|
26
|
+
errorPattern: string;
|
|
27
|
+
/** Whether this pattern requires incident reporting */
|
|
28
|
+
requiresIncident: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Security incident data structure
|
|
32
|
+
*/
|
|
33
|
+
export interface SecurityIncident {
|
|
34
|
+
/** Unique incident identifier */
|
|
35
|
+
id: string;
|
|
36
|
+
/** Type of security incident */
|
|
37
|
+
type: 'anomaly_detection' | 'error_pattern_anomaly' | 'suspicious_activity';
|
|
38
|
+
/** Risk level of the incident */
|
|
39
|
+
riskLevel: 'low' | 'medium' | 'high' | 'critical';
|
|
40
|
+
/** Timestamp when incident occurred */
|
|
41
|
+
timestamp: string;
|
|
42
|
+
/** Additional incident details */
|
|
43
|
+
details: Record<string, unknown>;
|
|
44
|
+
/** Source component that triggered the incident */
|
|
45
|
+
source: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Prompt processing context for anomaly detection
|
|
49
|
+
*/
|
|
50
|
+
export interface ProcessingContext {
|
|
51
|
+
/** The prompt being processed */
|
|
52
|
+
prompt: string;
|
|
53
|
+
/** Processing timestamp */
|
|
54
|
+
timestamp: string;
|
|
55
|
+
/** Phase where anomaly was detected */
|
|
56
|
+
phase?: string;
|
|
57
|
+
/** Additional context metadata */
|
|
58
|
+
metadata?: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Log level for automatic adjustment
|
|
62
|
+
*/
|
|
63
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'critical';
|
|
64
|
+
/**
|
|
65
|
+
* SecurityIncidentManager provides comprehensive security monitoring
|
|
66
|
+
* for the prompt orchestration system
|
|
67
|
+
*/
|
|
68
|
+
export declare class SecurityIncidentManager {
|
|
69
|
+
private errorPatternTracker;
|
|
70
|
+
private recentIncidents;
|
|
71
|
+
private currentLogLevel;
|
|
72
|
+
private maxIncidentHistory;
|
|
73
|
+
private sensitiveDataPatterns;
|
|
74
|
+
constructor();
|
|
75
|
+
/**
|
|
76
|
+
* Initialize patterns for detecting sensitive data
|
|
77
|
+
* Used for data protection in logging and incident reporting
|
|
78
|
+
*/
|
|
79
|
+
private initializeSensitiveDataPatterns;
|
|
80
|
+
/**
|
|
81
|
+
* Detect anomalies in prompt processing context
|
|
82
|
+
* Analyzes prompts and context for suspicious patterns
|
|
83
|
+
*/
|
|
84
|
+
detectAnomalies(context: ProcessingContext): AnomalyDetectionResult;
|
|
85
|
+
/**
|
|
86
|
+
* Track error patterns and detect consecutive failures
|
|
87
|
+
* Helps identify systematic issues or potential attacks
|
|
88
|
+
*/
|
|
89
|
+
trackErrorPattern(errorType: string): ErrorPatternResult;
|
|
90
|
+
/**
|
|
91
|
+
* Report a security incident
|
|
92
|
+
* Creates incident record and triggers appropriate responses
|
|
93
|
+
*/
|
|
94
|
+
reportIncident(incident: Omit<SecurityIncident, 'id' | 'timestamp'>): SecurityIncident;
|
|
95
|
+
/**
|
|
96
|
+
* Automatically adjust log level based on incident severity
|
|
97
|
+
* Higher severity incidents increase logging verbosity
|
|
98
|
+
*/
|
|
99
|
+
adjustLogLevel(riskLevel: SecurityIncident['riskLevel']): void;
|
|
100
|
+
/**
|
|
101
|
+
* Determine if log level should be upgraded
|
|
102
|
+
*/
|
|
103
|
+
private shouldUpgradeLogLevel;
|
|
104
|
+
/**
|
|
105
|
+
* Log incident with structured format and data protection
|
|
106
|
+
*/
|
|
107
|
+
private logIncident;
|
|
108
|
+
/**
|
|
109
|
+
* Sanitize incident data to remove sensitive information
|
|
110
|
+
*/
|
|
111
|
+
private sanitizeIncidentData;
|
|
112
|
+
/**
|
|
113
|
+
* Recursively sanitize an object to remove sensitive data
|
|
114
|
+
*/
|
|
115
|
+
private sanitizeObjectRecursively;
|
|
116
|
+
/**
|
|
117
|
+
* Redact sensitive data from text using pattern matching
|
|
118
|
+
*/
|
|
119
|
+
private redactSensitiveData;
|
|
120
|
+
/**
|
|
121
|
+
* Generate unique incident ID
|
|
122
|
+
*/
|
|
123
|
+
private generateIncidentId;
|
|
124
|
+
/**
|
|
125
|
+
* Generate hash for prompt comparison
|
|
126
|
+
*/
|
|
127
|
+
private hashPrompt;
|
|
128
|
+
/**
|
|
129
|
+
* Get current security status
|
|
130
|
+
*/
|
|
131
|
+
getSecurityStatus(): {
|
|
132
|
+
currentLogLevel: LogLevel;
|
|
133
|
+
recentIncidentCount: number;
|
|
134
|
+
activeErrorPatterns: Record<string, number>;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Reset security tracking state
|
|
138
|
+
* Useful for testing or system reset scenarios
|
|
139
|
+
*/
|
|
140
|
+
reset(): void;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=SecurityIncidentManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecurityIncidentManager.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/security/SecurityIncidentManager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,sCAAsC;IACtC,YAAY,EAAE,OAAO,CAAA;IACrB,gCAAgC;IAChC,YAAY,EAAE,MAAM,CAAA;IACpB,4BAA4B;IAC5B,SAAS,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAA;IACjD,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAA;CACpB;AAED;;GAEG;AACH,MAA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