mcp-adr-analysis-server 2.14.0 → 2.14.2
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 +56 -41
- package/dist/.tsbuildinfo +1 -1
- package/dist/src/tools/adr-validation-tool.d.ts.map +1 -1
- package/dist/src/tools/adr-validation-tool.js +3 -9
- package/dist/src/tools/adr-validation-tool.js.map +1 -1
- package/dist/src/utils/file-system.d.ts.map +1 -1
- package/dist/src/utils/file-system.js +1 -2
- package/dist/src/utils/file-system.js.map +1 -1
- package/dist/src/utils/tiered-response-manager.d.ts +1 -1
- package/dist/src/utils/tiered-response-manager.d.ts.map +1 -1
- package/dist/src/utils/tiered-response-manager.js +1 -2
- package/dist/src/utils/tiered-response-manager.js.map +1 -1
- package/package.json +1 -1
- package/dist/src/prompts/prompt-catalog.d.ts +0 -95
- package/dist/src/prompts/prompt-catalog.d.ts.map +0 -1
- package/dist/src/prompts/prompt-catalog.js +0 -300
- package/dist/src/prompts/prompt-catalog.js.map +0 -1
- package/dist/src/utils/ai-executor.d.ts +0 -170
- package/dist/src/utils/ai-executor.d.ts.map +0 -1
- package/dist/src/utils/ai-executor.js +0 -338
- package/dist/src/utils/ai-executor.js.map +0 -1
- package/dist/src/utils/prompt-execution.d.ts +0 -116
- package/dist/src/utils/prompt-execution.d.ts.map +0 -1
- package/dist/src/utils/prompt-execution.js +0 -342
- package/dist/src/utils/prompt-execution.js.map +0 -1
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CE-MCP Prompt Catalog
|
|
3
|
-
*
|
|
4
|
-
* Provides lazy loading of prompts - instead of importing all 6,145 lines
|
|
5
|
-
* of prompt code upfront, this catalog allows on-demand loading of specific
|
|
6
|
-
* prompt sections, reducing token usage by ~96%.
|
|
7
|
-
*
|
|
8
|
-
* @see ADR-014: CE-MCP Architecture
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Prompt catalog with metadata for lazy loading
|
|
12
|
-
*
|
|
13
|
-
* Token estimates based on ~4 chars per token average
|
|
14
|
-
*/
|
|
15
|
-
export const PROMPT_CATALOG = {
|
|
16
|
-
// ADR-related prompts
|
|
17
|
-
'adr-suggestion': {
|
|
18
|
-
file: 'adr-suggestion-prompts.ts',
|
|
19
|
-
tokens: 1830,
|
|
20
|
-
category: 'adr',
|
|
21
|
-
sections: [
|
|
22
|
-
'implicit_decisions',
|
|
23
|
-
'tech_debt',
|
|
24
|
-
'security_decisions',
|
|
25
|
-
'cross_cutting',
|
|
26
|
-
'recommendation_template',
|
|
27
|
-
],
|
|
28
|
-
loadOnDemand: true,
|
|
29
|
-
},
|
|
30
|
-
// Deployment analysis prompts
|
|
31
|
-
'deployment-analysis': {
|
|
32
|
-
file: 'deployment-analysis-prompts.ts',
|
|
33
|
-
tokens: 3150,
|
|
34
|
-
category: 'deployment',
|
|
35
|
-
sections: [
|
|
36
|
-
'readiness_check',
|
|
37
|
-
'validation_criteria',
|
|
38
|
-
'rollback_plan',
|
|
39
|
-
'infrastructure_review',
|
|
40
|
-
'security_scan',
|
|
41
|
-
],
|
|
42
|
-
loadOnDemand: true,
|
|
43
|
-
},
|
|
44
|
-
// Environment analysis prompts
|
|
45
|
-
'environment-analysis': {
|
|
46
|
-
file: 'environment-analysis-prompts.ts',
|
|
47
|
-
tokens: 3050,
|
|
48
|
-
category: 'analysis',
|
|
49
|
-
sections: ['dependency_scan', 'config_validation', 'compliance_check', 'resource_assessment'],
|
|
50
|
-
loadOnDemand: true,
|
|
51
|
-
},
|
|
52
|
-
// Research question prompts
|
|
53
|
-
'research-question': {
|
|
54
|
-
file: 'research-question-prompts.ts',
|
|
55
|
-
tokens: 3120,
|
|
56
|
-
category: 'research',
|
|
57
|
-
sections: ['question_generation', 'research_plan', 'source_evaluation', 'synthesis_template'],
|
|
58
|
-
loadOnDemand: true,
|
|
59
|
-
},
|
|
60
|
-
// Rule generation prompts
|
|
61
|
-
'rule-generation': {
|
|
62
|
-
file: 'rule-generation-prompts.ts',
|
|
63
|
-
tokens: 2850,
|
|
64
|
-
category: 'rules',
|
|
65
|
-
sections: ['rule_template', 'validation_rules', 'enforcement_policy', 'exception_handling'],
|
|
66
|
-
loadOnDemand: true,
|
|
67
|
-
},
|
|
68
|
-
// General analysis prompts
|
|
69
|
-
analysis: {
|
|
70
|
-
file: 'analysis-prompts.ts',
|
|
71
|
-
tokens: 2310,
|
|
72
|
-
category: 'analysis',
|
|
73
|
-
sections: ['project_analysis', 'code_review', 'architecture_assessment', 'quality_metrics'],
|
|
74
|
-
loadOnDemand: true,
|
|
75
|
-
},
|
|
76
|
-
// Research integration prompts
|
|
77
|
-
'research-integration': {
|
|
78
|
-
file: 'research-integration-prompts.ts',
|
|
79
|
-
tokens: 1785,
|
|
80
|
-
category: 'research',
|
|
81
|
-
sections: ['integration_strategy', 'synthesis_plan', 'recommendation_format'],
|
|
82
|
-
loadOnDemand: true,
|
|
83
|
-
},
|
|
84
|
-
// Validated pattern prompts
|
|
85
|
-
'validated-pattern': {
|
|
86
|
-
file: 'validated-pattern-prompts.ts',
|
|
87
|
-
tokens: 1565,
|
|
88
|
-
category: 'deployment',
|
|
89
|
-
sections: ['pattern_detection', 'validation_criteria', 'deployment_guidance'],
|
|
90
|
-
loadOnDemand: true,
|
|
91
|
-
},
|
|
92
|
-
// Security prompts
|
|
93
|
-
security: {
|
|
94
|
-
file: 'security-prompts.ts',
|
|
95
|
-
tokens: 1270,
|
|
96
|
-
category: 'security',
|
|
97
|
-
sections: ['vulnerability_scan', 'masking_rules', 'compliance_check'],
|
|
98
|
-
loadOnDemand: true,
|
|
99
|
-
},
|
|
100
|
-
// Main index (orchestration)
|
|
101
|
-
index: {
|
|
102
|
-
file: 'index.ts',
|
|
103
|
-
tokens: 3700,
|
|
104
|
-
category: 'analysis',
|
|
105
|
-
sections: ['orchestration', 'execution_flow', 'error_handling'],
|
|
106
|
-
dependencies: ['adr-suggestion', 'deployment-analysis', 'analysis'],
|
|
107
|
-
loadOnDemand: false, // Core orchestration loaded at startup
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* Get total token count if all prompts were loaded
|
|
112
|
-
*/
|
|
113
|
-
export function getTotalPromptTokens() {
|
|
114
|
-
return Object.values(PROMPT_CATALOG).reduce((sum, entry) => sum + entry.tokens, 0);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Get prompts by category
|
|
118
|
-
*/
|
|
119
|
-
export function getPromptsByCategory(category) {
|
|
120
|
-
return Object.entries(PROMPT_CATALOG)
|
|
121
|
-
.filter(([_, entry]) => entry.category === category)
|
|
122
|
-
.map(([name]) => name);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Get prompt metadata
|
|
126
|
-
*/
|
|
127
|
-
export function getPromptMetadata(promptName) {
|
|
128
|
-
return PROMPT_CATALOG[promptName];
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Prompt Loader Service
|
|
132
|
-
*
|
|
133
|
-
* Handles lazy loading of prompts with caching
|
|
134
|
-
*/
|
|
135
|
-
export class PromptLoader {
|
|
136
|
-
cache = new Map();
|
|
137
|
-
cacheTTL;
|
|
138
|
-
constructor(cacheTTL = 3600) {
|
|
139
|
-
this.cacheTTL = cacheTTL;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Load a specific prompt section
|
|
143
|
-
*
|
|
144
|
-
* @param promptName - Name of the prompt (e.g., 'adr-suggestion')
|
|
145
|
-
* @param section - Optional section within the prompt
|
|
146
|
-
* @returns Promise resolving to the prompt content
|
|
147
|
-
*/
|
|
148
|
-
async loadPrompt(promptName, section) {
|
|
149
|
-
const metadata = PROMPT_CATALOG[promptName];
|
|
150
|
-
if (!metadata) {
|
|
151
|
-
throw new Error(`Unknown prompt: ${promptName}`);
|
|
152
|
-
}
|
|
153
|
-
// Check cache
|
|
154
|
-
const cacheKey = promptName;
|
|
155
|
-
const cached = this.cache.get(cacheKey);
|
|
156
|
-
if (cached && Date.now() < cached.expiry) {
|
|
157
|
-
if (section) {
|
|
158
|
-
const sectionContent = cached.sections.get(section);
|
|
159
|
-
if (sectionContent) {
|
|
160
|
-
return sectionContent;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return cached.content;
|
|
164
|
-
}
|
|
165
|
-
// Load prompt dynamically
|
|
166
|
-
const content = await this.loadPromptFile(metadata.file);
|
|
167
|
-
// Parse sections if needed
|
|
168
|
-
const sections = this.parseSections(content, metadata.sections);
|
|
169
|
-
// Cache the result
|
|
170
|
-
this.cache.set(cacheKey, {
|
|
171
|
-
content,
|
|
172
|
-
sections,
|
|
173
|
-
expiry: Date.now() + this.cacheTTL * 1000,
|
|
174
|
-
});
|
|
175
|
-
if (section) {
|
|
176
|
-
const sectionContent = sections.get(section);
|
|
177
|
-
if (sectionContent) {
|
|
178
|
-
return sectionContent;
|
|
179
|
-
}
|
|
180
|
-
throw new Error(`Section '${section}' not found in prompt '${promptName}'`);
|
|
181
|
-
}
|
|
182
|
-
return content;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Load prompt file content
|
|
186
|
-
*/
|
|
187
|
-
async loadPromptFile(fileName) {
|
|
188
|
-
// In production, this would use dynamic import or file system read
|
|
189
|
-
// For now, return a placeholder that indicates which file should be loaded
|
|
190
|
-
return `[PROMPT_FILE: ${fileName}]`;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Parse sections from prompt content
|
|
194
|
-
*/
|
|
195
|
-
parseSections(content, sectionNames) {
|
|
196
|
-
const sections = new Map();
|
|
197
|
-
// Basic section parsing - looks for patterns like:
|
|
198
|
-
// // SECTION: section_name
|
|
199
|
-
// or
|
|
200
|
-
// export const SECTION_NAME = ...
|
|
201
|
-
for (const sectionName of sectionNames) {
|
|
202
|
-
// Try to find section marker
|
|
203
|
-
const markerRegex = new RegExp(`(?:\\/\\/ SECTION: ${sectionName}|export const ${sectionName.toUpperCase().replace(/-/g, '_')})`, 'i');
|
|
204
|
-
const match = content.match(markerRegex);
|
|
205
|
-
if (match && match.index !== undefined) {
|
|
206
|
-
// Extract content until next section or end
|
|
207
|
-
const startIndex = match.index;
|
|
208
|
-
const nextSectionMatch = content
|
|
209
|
-
.slice(startIndex + 1)
|
|
210
|
-
.match(/(?:\/\/ SECTION:|export const [A-Z_]+)/);
|
|
211
|
-
const endIndex = nextSectionMatch
|
|
212
|
-
? startIndex + 1 + (nextSectionMatch.index || content.length)
|
|
213
|
-
: content.length;
|
|
214
|
-
sections.set(sectionName, content.slice(startIndex, endIndex).trim());
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return sections;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Preload prompts that are commonly used together
|
|
221
|
-
*/
|
|
222
|
-
async preloadPromptGroup(promptNames) {
|
|
223
|
-
await Promise.all(promptNames.map(name => this.loadPrompt(name)));
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Get estimated tokens for a prompt
|
|
227
|
-
*/
|
|
228
|
-
getEstimatedTokens(promptName, section) {
|
|
229
|
-
const metadata = PROMPT_CATALOG[promptName];
|
|
230
|
-
if (!metadata)
|
|
231
|
-
return 0;
|
|
232
|
-
if (section) {
|
|
233
|
-
// Estimate section as portion of total
|
|
234
|
-
const sectionCount = metadata.sections.length;
|
|
235
|
-
return Math.ceil(metadata.tokens / sectionCount);
|
|
236
|
-
}
|
|
237
|
-
return metadata.tokens;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Get recommendations for which prompts to load
|
|
241
|
-
*/
|
|
242
|
-
getLoadRecommendations(taskType) {
|
|
243
|
-
const recommendations = {
|
|
244
|
-
adr_analysis: ['adr-suggestion', 'analysis'],
|
|
245
|
-
deployment: ['deployment-analysis', 'validated-pattern', 'environment-analysis'],
|
|
246
|
-
security: ['security', 'analysis'],
|
|
247
|
-
research: ['research-question', 'research-integration'],
|
|
248
|
-
rules: ['rule-generation', 'analysis'],
|
|
249
|
-
};
|
|
250
|
-
return recommendations[taskType] || ['analysis'];
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Clear cache
|
|
254
|
-
*/
|
|
255
|
-
clearCache() {
|
|
256
|
-
this.cache.clear();
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Get cache statistics
|
|
260
|
-
*/
|
|
261
|
-
getCacheStats() {
|
|
262
|
-
return {
|
|
263
|
-
size: this.cache.size,
|
|
264
|
-
entries: Array.from(this.cache.keys()),
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Global prompt loader instance
|
|
270
|
-
*/
|
|
271
|
-
let globalPromptLoader = null;
|
|
272
|
-
/**
|
|
273
|
-
* Get or create the global prompt loader
|
|
274
|
-
*/
|
|
275
|
-
export function getPromptLoader(cacheTTL) {
|
|
276
|
-
if (!globalPromptLoader) {
|
|
277
|
-
globalPromptLoader = new PromptLoader(cacheTTL);
|
|
278
|
-
}
|
|
279
|
-
return globalPromptLoader;
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Reset the global prompt loader
|
|
283
|
-
*/
|
|
284
|
-
export function resetPromptLoader() {
|
|
285
|
-
globalPromptLoader = null;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Token savings calculation
|
|
289
|
-
*/
|
|
290
|
-
export function calculateTokenSavings(loadedPrompts) {
|
|
291
|
-
const total = getTotalPromptTokens();
|
|
292
|
-
const loaded = loadedPrompts.reduce((sum, name) => {
|
|
293
|
-
const metadata = PROMPT_CATALOG[name];
|
|
294
|
-
return sum + (metadata?.tokens || 0);
|
|
295
|
-
}, 0);
|
|
296
|
-
const saved = total - loaded;
|
|
297
|
-
const percentage = Math.round((saved / total) * 100);
|
|
298
|
-
return { loaded, total, saved, percentage };
|
|
299
|
-
}
|
|
300
|
-
//# sourceMappingURL=prompt-catalog.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":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,GAAG,IAAI,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,aAAuB;IAM3D,MAAM,KAAK,GAAG,oBAAoB,EAAE,CAAC;IACrC,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QAChD,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;QACtC,OAAO,GAAG,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC,CAAC,CAAC;IACvC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEN,MAAM,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;IAC7B,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC;IAErD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;AAC9C,CAAC"}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AI Executor Service for OpenRouter.ai Integration
|
|
3
|
-
*
|
|
4
|
-
* This service handles the execution of prompts using OpenRouter.ai,
|
|
5
|
-
* transforming the MCP server from returning prompts to returning actual results.
|
|
6
|
-
*
|
|
7
|
-
* @deprecated This module is part of the legacy OpenRouter execution path.
|
|
8
|
-
* As of CE-MCP Phase 4.4, tools should return OrchestrationDirectives instead
|
|
9
|
-
* of using this executor. This module is retained for:
|
|
10
|
-
* - Hybrid mode support (CE-MCP with OpenRouter fallback)
|
|
11
|
-
*
|
|
12
|
-
* For new tools, use the directive-based approach defined in ADR-014.
|
|
13
|
-
* @see src/types/ce-mcp.ts for OrchestrationDirective types
|
|
14
|
-
* @see docs/adrs/adr-014-ce-mcp-architecture.md
|
|
15
|
-
*/
|
|
16
|
-
import { AIConfig } from '../config/ai-config.js';
|
|
17
|
-
export interface AIExecutionResult {
|
|
18
|
-
/** The AI-generated response content */
|
|
19
|
-
content: string;
|
|
20
|
-
/** Model used for generation */
|
|
21
|
-
model: string;
|
|
22
|
-
/** Token usage information */
|
|
23
|
-
usage?: {
|
|
24
|
-
promptTokens: number;
|
|
25
|
-
completionTokens: number;
|
|
26
|
-
totalTokens: number;
|
|
27
|
-
};
|
|
28
|
-
/** Execution metadata */
|
|
29
|
-
metadata: {
|
|
30
|
-
executionTime: number;
|
|
31
|
-
cached: boolean;
|
|
32
|
-
retryCount: number;
|
|
33
|
-
timestamp: string;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
export interface AIExecutionError extends Error {
|
|
37
|
-
code: string;
|
|
38
|
-
retryable: boolean;
|
|
39
|
-
originalError?: unknown;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* AI Executor Service Class
|
|
43
|
-
*
|
|
44
|
-
* @description Core service for executing AI prompts through OpenRouter.ai integration.
|
|
45
|
-
* Transforms the MCP server from returning prompts to returning actual AI-generated results.
|
|
46
|
-
* Includes caching, retry logic, and comprehensive error handling.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* // Initialize with custom configuration
|
|
51
|
-
* const executor = new AIExecutor({
|
|
52
|
-
* apiKey: 'your-api-key',
|
|
53
|
-
* model: 'anthropic/claude-3-sonnet',
|
|
54
|
-
* maxTokens: 4000
|
|
55
|
-
* });
|
|
56
|
-
*
|
|
57
|
-
* // Execute a prompt
|
|
58
|
-
* const result = await executor.executePrompt({
|
|
59
|
-
* prompt: 'Analyze this ADR...',
|
|
60
|
-
* context: { projectPath: '/path/to/project' }
|
|
61
|
-
* });
|
|
62
|
-
*
|
|
63
|
-
* console.log(result.content); // AI-generated analysis
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```typescript
|
|
68
|
-
* // Use singleton instance
|
|
69
|
-
* const executor = getAIExecutor();
|
|
70
|
-
* const result = await executor.executePrompt({
|
|
71
|
-
* prompt: 'Generate ADR suggestions',
|
|
72
|
-
* maxTokens: 2000
|
|
73
|
-
* });
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
* @since 2.0.0
|
|
77
|
-
* @category AI
|
|
78
|
-
* @category Core
|
|
79
|
-
*/
|
|
80
|
-
export declare class AIExecutor {
|
|
81
|
-
private client;
|
|
82
|
-
private config;
|
|
83
|
-
private cache;
|
|
84
|
-
constructor(config?: AIConfig);
|
|
85
|
-
/**
|
|
86
|
-
* Initialize OpenAI client for OpenRouter
|
|
87
|
-
*/
|
|
88
|
-
private initializeClient;
|
|
89
|
-
/**
|
|
90
|
-
* Check if AI execution is available
|
|
91
|
-
*/
|
|
92
|
-
isAvailable(): boolean;
|
|
93
|
-
/**
|
|
94
|
-
* Reload configuration if environment variables have changed
|
|
95
|
-
*/
|
|
96
|
-
private reloadConfigIfNeeded;
|
|
97
|
-
/**
|
|
98
|
-
* Execute a prompt and return the AI response
|
|
99
|
-
*/
|
|
100
|
-
executePrompt(prompt: string, options?: {
|
|
101
|
-
model?: string;
|
|
102
|
-
temperature?: number;
|
|
103
|
-
maxTokens?: number;
|
|
104
|
-
systemPrompt?: string;
|
|
105
|
-
}): Promise<AIExecutionResult>;
|
|
106
|
-
/**
|
|
107
|
-
* Execute a structured prompt that expects JSON response
|
|
108
|
-
*/
|
|
109
|
-
executeStructuredPrompt<T = any>(prompt: string, schema?: any, options?: {
|
|
110
|
-
model?: string;
|
|
111
|
-
temperature?: number;
|
|
112
|
-
maxTokens?: number;
|
|
113
|
-
systemPrompt?: string;
|
|
114
|
-
}): Promise<{
|
|
115
|
-
data: T;
|
|
116
|
-
raw: AIExecutionResult;
|
|
117
|
-
}>;
|
|
118
|
-
/**
|
|
119
|
-
* Extract JSON content from AI response, handling markdown code blocks
|
|
120
|
-
*/
|
|
121
|
-
private extractJsonFromResponse;
|
|
122
|
-
/**
|
|
123
|
-
* Generate cache key for a prompt execution
|
|
124
|
-
*/
|
|
125
|
-
private generateCacheKey;
|
|
126
|
-
/**
|
|
127
|
-
* Get cached result if available and not expired
|
|
128
|
-
*/
|
|
129
|
-
private getCachedResult;
|
|
130
|
-
/**
|
|
131
|
-
* Cache a result
|
|
132
|
-
*/
|
|
133
|
-
private setCachedResult;
|
|
134
|
-
/**
|
|
135
|
-
* Clean up expired cache entries
|
|
136
|
-
*/
|
|
137
|
-
private cleanupCache;
|
|
138
|
-
/**
|
|
139
|
-
* Create a standardized AI execution error
|
|
140
|
-
*/
|
|
141
|
-
private createError;
|
|
142
|
-
/**
|
|
143
|
-
* Get current configuration
|
|
144
|
-
*/
|
|
145
|
-
getConfig(): AIConfig;
|
|
146
|
-
/**
|
|
147
|
-
* Update configuration
|
|
148
|
-
*/
|
|
149
|
-
updateConfig(newConfig: Partial<AIConfig>): void;
|
|
150
|
-
/**
|
|
151
|
-
* Clear cache
|
|
152
|
-
*/
|
|
153
|
-
clearCache(): void;
|
|
154
|
-
/**
|
|
155
|
-
* Get cache statistics
|
|
156
|
-
*/
|
|
157
|
-
getCacheStats(): {
|
|
158
|
-
size: number;
|
|
159
|
-
hitRate: number;
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Get or create the global AI executor instance
|
|
164
|
-
*/
|
|
165
|
-
export declare function getAIExecutor(): AIExecutor;
|
|
166
|
-
/**
|
|
167
|
-
* Reset the global AI executor (useful for testing)
|
|
168
|
-
*/
|
|
169
|
-
export declare function resetAIExecutor(): void;
|
|
170
|
-
//# sourceMappingURL=ai-executor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ai-executor.d.ts","sourceRoot":"","sources":["../../../src/utils/ai-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EACL,QAAQ,EAIT,MAAM,wBAAwB,CAAC;AAEhC,MAAM,WAAW,iBAAiB;IAChC,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,KAAK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