@1mcp/agent 0.23.0 → 0.23.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/build/commands/mcp/tokens.d.ts.map +1 -1
- package/build/commands/mcp/tokens.js +0 -2
- package/build/commands/mcp/tokens.js.map +1 -1
- package/build/commands/preset/interactive.js +1 -2
- package/build/commands/preset/interactive.js.map +1 -1
- package/build/commands/preset/list.js +3 -6
- package/build/commands/preset/list.js.map +1 -1
- package/build/commands/preset/show.js +0 -1
- package/build/commands/preset/show.js.map +1 -1
- package/build/commands/serve/serve.d.ts.map +1 -1
- package/build/commands/serve/serve.js +12 -6
- package/build/commands/serve/serve.js.map +1 -1
- package/build/config/mcpConfigManager.d.ts.map +1 -1
- package/build/config/mcpConfigManager.js +15 -6
- package/build/config/mcpConfigManager.js.map +1 -1
- package/build/constants.d.ts +1 -1
- package/build/constants.js +1 -1
- package/build/core/capabilities/asyncLoadingOrchestrator.d.ts.map +1 -1
- package/build/core/capabilities/asyncLoadingOrchestrator.js +11 -8
- package/build/core/capabilities/asyncLoadingOrchestrator.js.map +1 -1
- package/build/core/capabilities/capabilityAggregator.js +8 -8
- package/build/core/capabilities/capabilityAggregator.js.map +1 -1
- package/build/{capabilities → core/capabilities}/capabilityManager.d.ts +1 -1
- package/build/core/capabilities/capabilityManager.d.ts.map +1 -0
- package/build/{capabilities → core/capabilities}/capabilityManager.js +3 -3
- package/build/core/capabilities/capabilityManager.js.map +1 -0
- package/build/core/client/clientManager.d.ts.map +1 -1
- package/build/core/client/clientManager.js +6 -3
- package/build/core/client/clientManager.js.map +1 -1
- package/build/core/filtering/filteringService.d.ts.map +1 -1
- package/build/core/filtering/filteringService.js +89 -55
- package/build/core/filtering/filteringService.js.map +1 -1
- package/build/core/instructions/instructionAggregator.d.ts +4 -38
- package/build/core/instructions/instructionAggregator.d.ts.map +1 -1
- package/build/core/instructions/instructionAggregator.js +91 -171
- package/build/core/instructions/instructionAggregator.js.map +1 -1
- package/build/core/instructions/templateHelpers.d.ts +7 -0
- package/build/core/instructions/templateHelpers.d.ts.map +1 -0
- package/build/core/instructions/templateHelpers.js +116 -0
- package/build/core/instructions/templateHelpers.js.map +1 -0
- package/build/core/instructions/templateTypes.d.ts +16 -4
- package/build/core/instructions/templateTypes.d.ts.map +1 -1
- package/build/core/instructions/templateTypes.js +7 -0
- package/build/core/instructions/templateTypes.js.map +1 -1
- package/build/core/instructions/templateValidator.d.ts +29 -0
- package/build/core/instructions/templateValidator.d.ts.map +1 -1
- package/build/core/instructions/templateValidator.js +138 -36
- package/build/core/instructions/templateValidator.js.map +1 -1
- package/build/core/loading/loadingStateTracker.js +2 -2
- package/build/core/loading/loadingStateTracker.js.map +1 -1
- package/build/core/loading/mcpLoadingManager.js +2 -2
- package/build/core/loading/mcpLoadingManager.js.map +1 -1
- package/build/core/notifications/notificationManager.d.ts.map +1 -1
- package/build/core/notifications/notificationManager.js +9 -6
- package/build/core/notifications/notificationManager.js.map +1 -1
- package/build/core/server/serverManager.js +6 -6
- package/build/core/server/serverManager.js.map +1 -1
- package/build/logger/logger.d.ts +39 -0
- package/build/logger/logger.d.ts.map +1 -1
- package/build/logger/logger.js +133 -0
- package/build/logger/logger.js.map +1 -1
- package/build/server.d.ts.map +1 -1
- package/build/server.js +5 -2
- package/build/server.js.map +1 -1
- package/build/services/configReloadService.js +1 -1
- package/build/services/configReloadService.js.map +1 -1
- package/build/transport/http/middlewares/mcpAvailabilityMiddleware.d.ts.map +1 -1
- package/build/transport/http/middlewares/mcpAvailabilityMiddleware.js +10 -4
- package/build/transport/http/middlewares/mcpAvailabilityMiddleware.js.map +1 -1
- package/build/transport/http/middlewares/tagsExtractor.d.ts.map +1 -1
- package/build/transport/http/middlewares/tagsExtractor.js +9 -6
- package/build/transport/http/middlewares/tagsExtractor.js.map +1 -1
- package/build/transport/http/routes/sseRoutes.d.ts +1 -1
- package/build/transport/http/routes/sseRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/sseRoutes.js +2 -1
- package/build/transport/http/routes/sseRoutes.js.map +1 -1
- package/build/transport/http/routes/streamableHttpRoutes.d.ts +1 -1
- package/build/transport/http/routes/streamableHttpRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/streamableHttpRoutes.js +2 -1
- package/build/transport/http/routes/streamableHttpRoutes.js.map +1 -1
- package/build/transport/http/server.d.ts +3 -1
- package/build/transport/http/server.d.ts.map +1 -1
- package/build/transport/http/server.js +6 -3
- package/build/transport/http/server.js.map +1 -1
- package/build/transport/restartableStdioTransport.d.ts.map +1 -1
- package/build/transport/restartableStdioTransport.js +7 -4
- package/build/transport/restartableStdioTransport.js.map +1 -1
- package/build/transport/transportFactory.d.ts.map +1 -1
- package/build/transport/transportFactory.js +14 -11
- package/build/transport/transportFactory.js.map +1 -1
- package/build/utils/clientFiltering.d.ts.map +1 -1
- package/build/utils/clientFiltering.js +64 -36
- package/build/utils/clientFiltering.js.map +1 -1
- package/build/utils/envProcessor.d.ts.map +1 -1
- package/build/utils/envProcessor.js +9 -7
- package/build/utils/envProcessor.js.map +1 -1
- package/build/utils/presetManager.d.ts +0 -4
- package/build/utils/presetManager.d.ts.map +1 -1
- package/build/utils/presetManager.js +0 -16
- package/build/utils/presetManager.js.map +1 -1
- package/build/utils/presetTypes.d.ts +0 -3
- package/build/utils/presetTypes.d.ts.map +1 -1
- package/package.json +1 -2
- package/build/capabilities/capabilityManager.d.ts.map +0 -1
- package/build/capabilities/capabilityManager.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import Handlebars from 'handlebars';
|
|
3
|
-
import {
|
|
4
|
-
import logger from '../../logger/logger.js';
|
|
3
|
+
import logger, { debugIf } from '../../logger/logger.js';
|
|
5
4
|
import { FilteringService } from '../filtering/filteringService.js';
|
|
6
5
|
import { DEFAULT_TEMPLATE_CONFIG, DEFAULT_INSTRUCTION_TEMPLATE, } from './templateTypes.js';
|
|
6
|
+
import { registerTemplateHelpers } from './templateHelpers.js';
|
|
7
7
|
/**
|
|
8
8
|
* Aggregates instructions from multiple MCP servers into a single instruction string.
|
|
9
9
|
* Provides both simple concatenation and filtered instructions with educational templates.
|
|
@@ -26,24 +26,11 @@ import { DEFAULT_TEMPLATE_CONFIG, DEFAULT_INSTRUCTION_TEMPLATE, } from './templa
|
|
|
26
26
|
export class InstructionAggregator extends EventEmitter {
|
|
27
27
|
serverInstructions = new Map();
|
|
28
28
|
isInitialized = false;
|
|
29
|
-
templateCache;
|
|
30
29
|
constructor() {
|
|
31
30
|
super();
|
|
32
31
|
this.setMaxListeners(50);
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
max: 100, // Maximum 100 compiled templates
|
|
36
|
-
maxSize: 10 * 1024 * 1024, // 10MB total size limit
|
|
37
|
-
sizeCalculation: (template, key) => {
|
|
38
|
-
// Estimate size based on template string length (key) plus overhead
|
|
39
|
-
return key.length + 1024; // Template overhead estimate
|
|
40
|
-
},
|
|
41
|
-
ttl: 1000 * 60 * 60, // 1 hour TTL to prevent indefinite growth
|
|
42
|
-
});
|
|
43
|
-
// Set up cache invalidation on instruction changes
|
|
44
|
-
this.on('instructions-changed', () => {
|
|
45
|
-
this.invalidateTemplateCache('instructions-changed');
|
|
46
|
-
});
|
|
32
|
+
// Register custom Handlebars helpers for template processing
|
|
33
|
+
registerTemplateHelpers();
|
|
47
34
|
}
|
|
48
35
|
/**
|
|
49
36
|
* Set or update instructions for a specific server
|
|
@@ -55,15 +42,15 @@ export class InstructionAggregator extends EventEmitter {
|
|
|
55
42
|
const hasChanges = previousInstructions !== instructions;
|
|
56
43
|
if (instructions?.trim()) {
|
|
57
44
|
this.serverInstructions.set(serverName, instructions.trim());
|
|
58
|
-
|
|
45
|
+
debugIf(() => ({ message: `Updated instructions for server: ${serverName}`, meta: { serverName } }));
|
|
59
46
|
}
|
|
60
47
|
else {
|
|
61
48
|
this.serverInstructions.delete(serverName);
|
|
62
|
-
|
|
49
|
+
debugIf(() => ({ message: `Removed instructions for server: ${serverName}`, meta: { serverName } }));
|
|
63
50
|
}
|
|
64
51
|
if (!this.isInitialized) {
|
|
65
52
|
this.isInitialized = true;
|
|
66
|
-
|
|
53
|
+
debugIf('InstructionAggregator initialized');
|
|
67
54
|
}
|
|
68
55
|
if (hasChanges) {
|
|
69
56
|
logger.info(`Instructions changed. Total servers with instructions: ${this.serverInstructions.size}`);
|
|
@@ -91,20 +78,41 @@ export class InstructionAggregator extends EventEmitter {
|
|
|
91
78
|
* @returns Formatted instruction string with educational template or custom template
|
|
92
79
|
*/
|
|
93
80
|
getFilteredInstructions(config, connections) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
81
|
+
debugIf(() => ({
|
|
82
|
+
message: 'InstructionAggregator: Getting filtered instructions',
|
|
83
|
+
meta: {
|
|
84
|
+
filterMode: config.tagFilterMode,
|
|
85
|
+
totalConnections: connections.size,
|
|
86
|
+
totalInstructions: this.serverInstructions.size,
|
|
87
|
+
hasCustomTemplate: !!config.customTemplate,
|
|
88
|
+
},
|
|
89
|
+
}));
|
|
100
90
|
// Filter connections based on client configuration
|
|
101
91
|
const filteredConnections = FilteringService.getFilteredConnections(connections, config);
|
|
102
92
|
// Get filtering summary for logging
|
|
103
93
|
const filteringSummary = FilteringService.getFilteringSummary(connections, filteredConnections, config);
|
|
104
94
|
logger.info('InstructionAggregator: Filtering applied', filteringSummary);
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
95
|
+
// Try custom template first, fall back to default if it fails
|
|
96
|
+
if (config.customTemplate) {
|
|
97
|
+
logger.info('InstructionAggregator: Trying custom template', { templateLength: config.customTemplate.length });
|
|
98
|
+
try {
|
|
99
|
+
return this.renderTemplate(config.customTemplate, filteredConnections, config);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
103
|
+
// Log detailed error for debugging
|
|
104
|
+
logger.error('InstructionAggregator: Custom template failed, falling back to default template', {
|
|
105
|
+
error: errorMessage,
|
|
106
|
+
templateLength: config.customTemplate.length,
|
|
107
|
+
});
|
|
108
|
+
// Fall back to default template
|
|
109
|
+
return this.renderTemplate(DEFAULT_INSTRUCTION_TEMPLATE, filteredConnections, config);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// Use default template directly
|
|
114
|
+
return this.renderTemplate(DEFAULT_INSTRUCTION_TEMPLATE, filteredConnections, config);
|
|
115
|
+
}
|
|
108
116
|
}
|
|
109
117
|
/**
|
|
110
118
|
* Get the number of servers that have provided instructions
|
|
@@ -143,7 +151,7 @@ export class InstructionAggregator extends EventEmitter {
|
|
|
143
151
|
const hadInstructions = this.serverInstructions.size > 0;
|
|
144
152
|
this.serverInstructions.clear();
|
|
145
153
|
if (hadInstructions) {
|
|
146
|
-
|
|
154
|
+
debugIf('Cleared all server instructions');
|
|
147
155
|
this.emit('instructions-changed');
|
|
148
156
|
}
|
|
149
157
|
}
|
|
@@ -174,100 +182,38 @@ export class InstructionAggregator extends EventEmitter {
|
|
|
174
182
|
return `${serverCount} servers with instructions: ${serverNames.join(', ')}`;
|
|
175
183
|
}
|
|
176
184
|
/**
|
|
177
|
-
* Render a
|
|
178
|
-
* @param template
|
|
185
|
+
* Render a Handlebars template with template variables
|
|
186
|
+
* @param template Template string (custom or default)
|
|
179
187
|
* @param filteredConnections Filtered server connections
|
|
180
188
|
* @param config Client configuration
|
|
181
189
|
* @returns Rendered template string
|
|
182
190
|
*/
|
|
183
|
-
|
|
184
|
-
try {
|
|
185
|
-
// Get or compile template
|
|
186
|
-
const compiledTemplate = this.getCompiledTemplate(template);
|
|
187
|
-
// Generate template variables
|
|
188
|
-
const variables = this.generateTemplateVariables(filteredConnections, config);
|
|
189
|
-
// Render template
|
|
190
|
-
const rendered = compiledTemplate(variables);
|
|
191
|
-
logger.debug('InstructionAggregator: Custom template rendered successfully', {
|
|
192
|
-
templateLength: template.length,
|
|
193
|
-
variableCount: Object.keys(variables).length,
|
|
194
|
-
renderedLength: rendered.length,
|
|
195
|
-
});
|
|
196
|
-
return rendered;
|
|
197
|
-
}
|
|
198
|
-
catch (error) {
|
|
199
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
200
|
-
logger.error('InstructionAggregator: Failed to render custom template', {
|
|
201
|
-
error: errorMessage,
|
|
202
|
-
templateLength: template.length,
|
|
203
|
-
});
|
|
204
|
-
// Provide actionable guidance for template errors
|
|
205
|
-
logger.warn('InstructionAggregator: Template rendering failed, returning error instructions with guidance');
|
|
206
|
-
const serverCount = Array.from(filteredConnections.keys()).filter((name) => this.serverInstructions.has(name)).length;
|
|
207
|
-
// Generate helpful error message with troubleshooting steps
|
|
208
|
-
return `# 1MCP - Template Rendering Error
|
|
209
|
-
|
|
210
|
-
⚠️ **Template rendering failed:** ${errorMessage}
|
|
211
|
-
|
|
212
|
-
## Available Resources
|
|
213
|
-
- **${serverCount} server(s)** are connected and have instructions
|
|
214
|
-
- **Built-in template** is available as fallback
|
|
215
|
-
|
|
216
|
-
## Troubleshooting Steps
|
|
217
|
-
|
|
218
|
-
1. **Check Template Syntax**:
|
|
219
|
-
- Verify all Handlebars expressions use correct syntax: \`{{variable}}\`
|
|
220
|
-
- Ensure block helpers are properly closed: \`{{#if}}...{{/if}}\`
|
|
221
|
-
- Check for unmatched braces or quotes
|
|
222
|
-
|
|
223
|
-
2. **Validate Template Variables**:
|
|
224
|
-
- Use only supported variables: \`serverCount\`, \`serverNames\`, \`hasServers\`, etc.
|
|
225
|
-
- Check template documentation for full variable list
|
|
226
|
-
|
|
227
|
-
3. **Test Template**:
|
|
228
|
-
- Start with a simple template: \`# {{title}}\\n{{serverCount}} servers available\`
|
|
229
|
-
- Add complexity gradually
|
|
230
|
-
|
|
231
|
-
4. **Get Help**:
|
|
232
|
-
- Remove custom template to use built-in version
|
|
233
|
-
- Check server logs for detailed error information
|
|
234
|
-
- Consult 1MCP documentation for template examples
|
|
235
|
-
|
|
236
|
-
---
|
|
237
|
-
*To restore normal operation, remove or fix the custom template file*`;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Get or compile a Handlebars template with caching
|
|
242
|
-
* @param template Template string
|
|
243
|
-
* @returns Compiled template function
|
|
244
|
-
*/
|
|
245
|
-
getCompiledTemplate(template) {
|
|
191
|
+
renderTemplate(template, filteredConnections, config) {
|
|
246
192
|
// Validate template size before processing
|
|
247
|
-
|
|
248
|
-
|
|
193
|
+
// Priority: config > default
|
|
194
|
+
const templateSizeLimit = config.templateSizeLimit || DEFAULT_TEMPLATE_CONFIG.templateSizeLimit;
|
|
195
|
+
if (template.length > templateSizeLimit) {
|
|
249
196
|
const sizeMB = (template.length / 1024 / 1024).toFixed(1);
|
|
250
|
-
|
|
197
|
+
const limitMB = (templateSizeLimit / 1024 / 1024).toFixed(1);
|
|
198
|
+
throw new Error(`Template too large: ${sizeMB}MB (max ${limitMB}MB). ` +
|
|
251
199
|
'Consider splitting into smaller files or removing unnecessary content. ' +
|
|
252
200
|
'Large templates can cause memory issues and slow performance.');
|
|
253
201
|
}
|
|
254
|
-
//
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
//
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
this.templateCache.set(cacheKey, compiledTemplate);
|
|
264
|
-
logger.debug('InstructionAggregator: Compiled and cached new template', {
|
|
202
|
+
// Compile template directly
|
|
203
|
+
const compiledTemplate = Handlebars.compile(template, { noEscape: true });
|
|
204
|
+
// Generate template variables
|
|
205
|
+
const variables = this.generateTemplateVariables(filteredConnections, config);
|
|
206
|
+
// Render template
|
|
207
|
+
const rendered = compiledTemplate(variables);
|
|
208
|
+
debugIf(() => ({
|
|
209
|
+
message: 'InstructionAggregator: Compiled and cached new template',
|
|
210
|
+
meta: {
|
|
265
211
|
templateLength: template.length,
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return
|
|
212
|
+
variableCount: Object.keys(variables).length,
|
|
213
|
+
renderedLength: rendered.length,
|
|
214
|
+
},
|
|
215
|
+
}));
|
|
216
|
+
return rendered;
|
|
271
217
|
}
|
|
272
218
|
/**
|
|
273
219
|
* Generate template variables for rendering
|
|
@@ -277,26 +223,39 @@ export class InstructionAggregator extends EventEmitter {
|
|
|
277
223
|
*/
|
|
278
224
|
generateTemplateVariables(filteredConnections, config) {
|
|
279
225
|
// Get server data for both arrays and individual server objects
|
|
280
|
-
const availableServers = [];
|
|
281
226
|
const serverInstructionSections = [];
|
|
282
227
|
const servers = [];
|
|
283
228
|
// Sort filtered connections by name for consistent output
|
|
284
229
|
const sortedConnections = Array.from(filteredConnections.entries()).sort(([a], [b]) => a.localeCompare(b));
|
|
285
230
|
for (const [serverName, _connection] of sortedConnections) {
|
|
286
231
|
const serverInstructions = this.serverInstructions.get(serverName);
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
232
|
+
const instructions = serverInstructions?.trim() || '';
|
|
233
|
+
if (instructions) {
|
|
234
|
+
// Wrap instructions in XML-like tags
|
|
235
|
+
const wrappedInstructions = `<${serverName}>\n${instructions}\n</${serverName}>`;
|
|
236
|
+
serverInstructionSections.push(wrappedInstructions);
|
|
290
237
|
// Add individual server data for iteration
|
|
291
238
|
servers.push({
|
|
292
239
|
name: serverName,
|
|
293
|
-
instructions:
|
|
240
|
+
instructions: instructions,
|
|
294
241
|
hasInstructions: true,
|
|
295
242
|
});
|
|
296
243
|
}
|
|
244
|
+
else {
|
|
245
|
+
servers.push({
|
|
246
|
+
name: serverName,
|
|
247
|
+
instructions: '',
|
|
248
|
+
hasInstructions: false,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
297
251
|
}
|
|
298
|
-
const
|
|
299
|
-
const
|
|
252
|
+
const connectedServerCount = filteredConnections.size;
|
|
253
|
+
const hasInstructionalServers = serverInstructionSections.length > 0;
|
|
254
|
+
const serverCount = serverInstructionSections.length;
|
|
255
|
+
const hasServers = serverInstructionSections.length > 0;
|
|
256
|
+
// Generate server lists (only servers with instructions)
|
|
257
|
+
const serverNames = servers.filter((server) => server.hasInstructions).map((server) => server.name);
|
|
258
|
+
const serverList = serverNames.join('\n');
|
|
300
259
|
// Merge configuration with defaults
|
|
301
260
|
const templateConfig = {
|
|
302
261
|
...DEFAULT_TEMPLATE_CONFIG,
|
|
@@ -306,13 +265,19 @@ export class InstructionAggregator extends EventEmitter {
|
|
|
306
265
|
};
|
|
307
266
|
return {
|
|
308
267
|
// Server state
|
|
268
|
+
connectedServerCount,
|
|
269
|
+
hasInstructionalServers,
|
|
309
270
|
serverCount,
|
|
271
|
+
instructionalServerCount: serverCount, // Alias for clarity
|
|
310
272
|
hasServers,
|
|
311
|
-
serverList
|
|
312
|
-
serverNames
|
|
273
|
+
serverList,
|
|
274
|
+
serverNames,
|
|
313
275
|
servers,
|
|
314
276
|
pluralServers: serverCount === 1 ? 'server' : 'servers',
|
|
315
277
|
isAre: serverCount === 1 ? 'is' : 'are',
|
|
278
|
+
// Grammar helpers for connected servers
|
|
279
|
+
connectedPluralServers: connectedServerCount === 1 ? 'server' : 'servers',
|
|
280
|
+
connectedIsAre: connectedServerCount === 1 ? 'is' : 'are',
|
|
316
281
|
// Content
|
|
317
282
|
instructions: serverInstructionSections.join('\n\n'),
|
|
318
283
|
filterContext: this.getFilterContext(config),
|
|
@@ -323,63 +288,18 @@ export class InstructionAggregator extends EventEmitter {
|
|
|
323
288
|
};
|
|
324
289
|
}
|
|
325
290
|
/**
|
|
326
|
-
*
|
|
327
|
-
*/
|
|
328
|
-
clearTemplateCache() {
|
|
329
|
-
this.templateCache.clear();
|
|
330
|
-
logger.debug('InstructionAggregator: Template cache cleared');
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Get template cache statistics for monitoring
|
|
334
|
-
*/
|
|
335
|
-
getTemplateCacheStats() {
|
|
336
|
-
return {
|
|
337
|
-
size: this.templateCache.size,
|
|
338
|
-
maxSize: this.templateCache.max,
|
|
339
|
-
calculatedSize: this.templateCache.calculatedSize || 0,
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Invalidate template cache with reason logging
|
|
344
|
-
* @param reason Reason for cache invalidation
|
|
345
|
-
*/
|
|
346
|
-
invalidateTemplateCache(reason) {
|
|
347
|
-
const sizeBefore = this.templateCache.size;
|
|
348
|
-
this.templateCache.clear();
|
|
349
|
-
logger.debug(`InstructionAggregator: Template cache invalidated due to ${reason}`, {
|
|
350
|
-
clearedTemplates: sizeBefore,
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Force template cache invalidation (for external triggers)
|
|
355
|
-
* @param reason Reason for forced invalidation
|
|
356
|
-
*/
|
|
357
|
-
forceTemplateCacheInvalidation(reason = 'external-trigger') {
|
|
358
|
-
this.invalidateTemplateCache(reason);
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Cryptographically secure hash function for template cache keys
|
|
362
|
-
* Uses SHA-256 to prevent collision attacks
|
|
363
|
-
*/
|
|
364
|
-
hashString(str) {
|
|
365
|
-
const crypto = require('crypto');
|
|
366
|
-
return crypto.createHash('sha256').update(str, 'utf8').digest('hex').substring(0, 16);
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* Cleanup method to remove all event listeners and clear caches
|
|
291
|
+
* Cleanup method to remove all event listeners
|
|
370
292
|
* Should be called when the aggregator is no longer needed
|
|
371
293
|
*/
|
|
372
294
|
cleanup() {
|
|
373
|
-
|
|
295
|
+
debugIf('InstructionAggregator: Starting cleanup');
|
|
374
296
|
// Clear all event listeners
|
|
375
297
|
this.removeAllListeners();
|
|
376
|
-
// Clear template cache
|
|
377
|
-
this.templateCache.clear();
|
|
378
298
|
// Clear server instructions
|
|
379
299
|
this.serverInstructions.clear();
|
|
380
300
|
// Reset initialization state
|
|
381
301
|
this.isInitialized = false;
|
|
382
|
-
logger.info('InstructionAggregator: Cleanup completed - all listeners
|
|
302
|
+
logger.info('InstructionAggregator: Cleanup completed - all listeners cleared');
|
|
383
303
|
}
|
|
384
304
|
}
|
|
385
305
|
//# sourceMappingURL=instructionAggregator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructionAggregator.js","sourceRoot":"","sources":["../../../src/core/instructions/instructionAggregator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"instructionAggregator.js","sourceRoot":"","sources":["../../../src/core/instructions/instructionAggregator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEpE,OAAO,EAGL,uBAAuB,EACvB,4BAA4B,GAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAS/D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,qBAAsB,SAAQ,YAAY;IAC7C,kBAAkB,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC/C,aAAa,GAAY,KAAK,CAAC;IAEvC;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;QAEzB,6DAA6D;QAC7D,uBAAuB,EAAE,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,eAAe,CAAC,UAAkB,EAAE,YAAgC;QACzE,MAAM,oBAAoB,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACrE,MAAM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SAC9D,CAAC;QAEF,OAAO;YACL,eAAe;YACf,oBAAoB;YACpB,uBAAuB;YACvB,WAAW;YACX,wBAAwB,EAAE,WAAW,EAAE,oBAAoB;YAC3D,UAAU;YACV,UAAU;YACV,WAAW;YACX,OAAO;YACP,aAAa,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;YACvD,KAAK,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK;YAEvC,wCAAwC;YACxC,sBAAsB,EAAE,oBAAoB,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;YACzE,cAAc,EAAE,oBAAoB,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK;YAEzD,UAAU;YACV,YAAY,EAAE,yBAAyB,CAAC,IAAI,CAAC,MAAM,CAAC;YACpD,aAAa,EAAE,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;YAE5C,gBAAgB;YAChB,WAAW,EAAE,cAAc,CAAC,WAAW;YACvC,KAAK,EAAE,cAAc,CAAC,KAAK;YAC3B,QAAQ,EAAE,cAAc,CAAC,QAAQ;SAClC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACI,OAAO;QACZ,OAAO,CAAC,yCAAyC,CAAC,CAAC;QAEnD,4BAA4B;QAC5B,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAE1B,4BAA4B;QAC5B,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAEhC,6BAA6B;QAC7B,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAE3B,MAAM,CAAC,IAAI,CAAC,kEAAkE,CAAC,CAAC;IAClF,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register custom Handlebars helpers for template processing
|
|
3
|
+
* These helpers provide mathematical, comparison, and string operations
|
|
4
|
+
* that are commonly needed in instruction templates
|
|
5
|
+
*/
|
|
6
|
+
export declare function registerTemplateHelpers(): void;
|
|
7
|
+
//# sourceMappingURL=templateHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templateHelpers.d.ts","sourceRoot":"","sources":["../../../src/core/instructions/templateHelpers.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CA6H9C"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import Handlebars from 'handlebars';
|
|
2
|
+
/**
|
|
3
|
+
* Register custom Handlebars helpers for template processing
|
|
4
|
+
* These helpers provide mathematical, comparison, and string operations
|
|
5
|
+
* that are commonly needed in instruction templates
|
|
6
|
+
*/
|
|
7
|
+
export function registerTemplateHelpers() {
|
|
8
|
+
// Math helpers - handles chained operations like "a '/' b '*' 100"
|
|
9
|
+
Handlebars.registerHelper('math', function (...args) {
|
|
10
|
+
// Remove the last argument (options object)
|
|
11
|
+
const values = args.slice(0, -1);
|
|
12
|
+
if (values.length < 3) {
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
let result = parseFloat(values[0]);
|
|
16
|
+
// Process operations in pairs (operator, value)
|
|
17
|
+
for (let i = 1; i < values.length; i += 2) {
|
|
18
|
+
const operator = values[i];
|
|
19
|
+
const value = parseFloat(values[i + 1]);
|
|
20
|
+
switch (operator) {
|
|
21
|
+
case '+':
|
|
22
|
+
result = result + value;
|
|
23
|
+
break;
|
|
24
|
+
case '-':
|
|
25
|
+
result = result - value;
|
|
26
|
+
break;
|
|
27
|
+
case '*':
|
|
28
|
+
result = result * value;
|
|
29
|
+
break;
|
|
30
|
+
case '/':
|
|
31
|
+
result = result / value;
|
|
32
|
+
break;
|
|
33
|
+
case '%':
|
|
34
|
+
result = result % value;
|
|
35
|
+
break;
|
|
36
|
+
case '**':
|
|
37
|
+
result = result ** value;
|
|
38
|
+
break;
|
|
39
|
+
default:
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Round to nearest integer for percentage calculations
|
|
44
|
+
return Math.round(result);
|
|
45
|
+
});
|
|
46
|
+
// Comparison helpers
|
|
47
|
+
Handlebars.registerHelper('eq', function (a, b) {
|
|
48
|
+
return a === b;
|
|
49
|
+
});
|
|
50
|
+
Handlebars.registerHelper('ne', function (a, b) {
|
|
51
|
+
return a !== b;
|
|
52
|
+
});
|
|
53
|
+
Handlebars.registerHelper('gt', function (a, b) {
|
|
54
|
+
return a > b;
|
|
55
|
+
});
|
|
56
|
+
Handlebars.registerHelper('lt', function (a, b) {
|
|
57
|
+
return a < b;
|
|
58
|
+
});
|
|
59
|
+
// Logical helpers
|
|
60
|
+
Handlebars.registerHelper('and', function (...args) {
|
|
61
|
+
// Remove the last argument (options object)
|
|
62
|
+
const values = args.slice(0, -1);
|
|
63
|
+
return values.every((value) => !!value);
|
|
64
|
+
});
|
|
65
|
+
Handlebars.registerHelper('or', function (...args) {
|
|
66
|
+
// Remove the last argument (options object)
|
|
67
|
+
const values = args.slice(0, -1);
|
|
68
|
+
return values.some((value) => !!value);
|
|
69
|
+
});
|
|
70
|
+
// String helpers
|
|
71
|
+
Handlebars.registerHelper('contains', function (str, substring) {
|
|
72
|
+
if (typeof str !== 'string' || typeof substring !== 'string') {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return str.includes(substring);
|
|
76
|
+
});
|
|
77
|
+
Handlebars.registerHelper('startsWith', function (str, prefix) {
|
|
78
|
+
if (typeof str !== 'string' || typeof prefix !== 'string') {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
return str.startsWith(prefix);
|
|
82
|
+
});
|
|
83
|
+
Handlebars.registerHelper('endsWith', function (str, suffix) {
|
|
84
|
+
if (typeof str !== 'string' || typeof suffix !== 'string') {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return str.endsWith(suffix);
|
|
88
|
+
});
|
|
89
|
+
// Math operation helpers
|
|
90
|
+
Handlebars.registerHelper('subtract', function (a, b) {
|
|
91
|
+
return (a || 0) - (b || 0);
|
|
92
|
+
});
|
|
93
|
+
Handlebars.registerHelper('div', function (a, b) {
|
|
94
|
+
if (b === 0)
|
|
95
|
+
return 0;
|
|
96
|
+
return (a || 0) / (b || 1);
|
|
97
|
+
});
|
|
98
|
+
// String length helper
|
|
99
|
+
Handlebars.registerHelper('len', function (str) {
|
|
100
|
+
if (typeof str !== 'string') {
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
return str.length;
|
|
104
|
+
});
|
|
105
|
+
// String substring helper
|
|
106
|
+
Handlebars.registerHelper('substring', function (str, start, end) {
|
|
107
|
+
if (typeof str !== 'string') {
|
|
108
|
+
return '';
|
|
109
|
+
}
|
|
110
|
+
if (end !== undefined) {
|
|
111
|
+
return str.substring(start, end);
|
|
112
|
+
}
|
|
113
|
+
return str.substring(start);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=templateHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templateHelpers.js","sourceRoot":"","sources":["../../../src/core/instructions/templateHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC;;;;GAIG;AACH,MAAM,UAAU,uBAAuB;IACrC,mEAAmE;IACnE,UAAU,CAAC,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,IAAW;QACxD,4CAA4C;QAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAEjC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,OAAO,CAAC,CAAC;QACX,CAAC;QAED,IAAI,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAEnC,gDAAgD;QAChD,KAAK,IAAI,CAAC,GAAG,CAAC,E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,KAAK,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -14,10 +14,16 @@ export interface ServerData {
|
|
|
14
14
|
* These variables are provided by 1MCP and can be used in Handlebars templates
|
|
15
15
|
*/
|
|
16
16
|
export interface TemplateVariables {
|
|
17
|
-
/** Number of connected servers (e.g., 3) */
|
|
17
|
+
/** Number of connected servers with instructions (e.g., 3) - LEGACY: kept for backward compatibility */
|
|
18
18
|
serverCount: number;
|
|
19
|
-
/**
|
|
19
|
+
/** Number of connected servers with instructions (same as serverCount, clearer name) */
|
|
20
|
+
instructionalServerCount: number;
|
|
21
|
+
/** Total number of connected servers (including those without instructions) */
|
|
22
|
+
connectedServerCount: number;
|
|
23
|
+
/** Boolean indicating if any servers with instructions are connected */
|
|
20
24
|
hasServers: boolean;
|
|
25
|
+
/** Boolean indicating if any servers with instructions are connected */
|
|
26
|
+
hasInstructionalServers: boolean;
|
|
21
27
|
/** Newline-separated list of server names */
|
|
22
28
|
serverList: string;
|
|
23
29
|
/** Array of server names for iteration with {{#each}} */
|
|
@@ -26,8 +32,12 @@ export interface TemplateVariables {
|
|
|
26
32
|
servers: ServerData[];
|
|
27
33
|
/** "server" or "servers" based on count */
|
|
28
34
|
pluralServers: string;
|
|
29
|
-
/** "is" or "are" based on count */
|
|
35
|
+
/** "is" or "are" based on instructional server count */
|
|
30
36
|
isAre: string;
|
|
37
|
+
/** "server" or "servers" based on connected server count */
|
|
38
|
+
connectedPluralServers: string;
|
|
39
|
+
/** "is" or "are" based on connected server count */
|
|
40
|
+
connectedIsAre: string;
|
|
31
41
|
/** All server instructions wrapped in XML-like tags */
|
|
32
42
|
instructions: string;
|
|
33
43
|
/** Filter description (e.g., " (filtered by tags: backend)") or empty string */
|
|
@@ -60,6 +70,8 @@ export interface TemplateConfig {
|
|
|
60
70
|
toolPattern?: string;
|
|
61
71
|
/** Custom tool examples */
|
|
62
72
|
examples?: TemplateExample[];
|
|
73
|
+
/** Maximum template size in bytes (default: 1MB) */
|
|
74
|
+
templateSizeLimit?: number;
|
|
63
75
|
}
|
|
64
76
|
/**
|
|
65
77
|
* Default template examples
|
|
@@ -73,5 +85,5 @@ export declare const DEFAULT_TEMPLATE_CONFIG: Required<Omit<TemplateConfig, 'cus
|
|
|
73
85
|
* Default instruction template using Handlebars syntax
|
|
74
86
|
* This template is used when no custom template is provided
|
|
75
87
|
*/
|
|
76
|
-
export declare const DEFAULT_INSTRUCTION_TEMPLATE = "# {{title}}\n\n{{#if hasServers}}\nYou are interacting with 1MCP, a proxy server that aggregates capabilities from multiple MCP (Model Context Protocol) servers. 1MCP acts as a unified gateway, allowing you to access tools and resources from various specialized MCP servers through a single connection.\n\n## How 1MCP Works\n\n- **Unified Access**: Connect to multiple MCP servers through one proxy\n- **Tool Aggregation**: All tools are available with the naming pattern `{{toolPattern}}`\n- **Resource Sharing**: Access files, data, and capabilities across different servers\n- **Intelligent Routing**: Your requests are automatically routed to the appropriate servers\n\n## Currently Connected Servers\n\n{{serverCount}} MCP {{pluralServers}} {{isAre}} currently available{{filterContext}}:\n\n{{serverList}}\n\n## Available Capabilities\n\nAll tools from connected servers are accessible using the format: `{{toolPattern}}`\n\nExamples:\n{{#each examples}}\n- `{{name}}` - {{description}}\n{{/each}}\n\n## Server-Specific Instructions\n\nThe following sections contain instructions from each connected MCP server. Each server's instructions are wrapped in XML-like tags (e.g., `<server-name>instructions</server-name>`) to clearly identify their source and scope.\n\n{{#each servers}}\n{{#if hasInstructions}}\n<{{name}}>\n{{instructions}}\n</{{name}}>\n\n{{/if}}\n{{/each}}\n\n## Tips for Using 1MCP\n\n- Tools are namespaced by server to avoid conflicts\n\n{{else}}\nYou are interacting with 1MCP, a proxy server that aggregates capabilities from multiple MCP (Model Context Protocol) servers.\n\n## Current Status\n\nNo MCP servers are currently connected. 1MCP is ready to connect to servers and provide unified access to their capabilities once they become available.\n\n## What 1MCP Provides\n\n- **Unified Access**: Connect to multiple MCP servers through one proxy\n- **Tool Aggregation**: Access tools using the pattern `{{toolPattern}}`\n- **Resource Sharing**: Share files, data, and capabilities across servers\n- **Intelligent Routing**: Automatic request routing to appropriate servers\n\n1MCP will automatically detect and connect to available MCP servers. Once connected, their tools and capabilities will become available through the unified interface.\n{{/if}}";
|
|
88
|
+
export declare const DEFAULT_INSTRUCTION_TEMPLATE = "# {{title}}\n\n{{#if hasServers}}\nYou are interacting with 1MCP, a proxy server that aggregates capabilities from multiple MCP (Model Context Protocol) servers. 1MCP acts as a unified gateway, allowing you to access tools and resources from various specialized MCP servers through a single connection.\n\n## How 1MCP Works\n\n- **Unified Access**: Connect to multiple MCP servers through one proxy\n- **Tool Aggregation**: All tools are available with the naming pattern `{{toolPattern}}`\n- **Resource Sharing**: Access files, data, and capabilities across different servers\n- **Intelligent Routing**: Your requests are automatically routed to the appropriate servers\n\n## Currently Connected Servers\n\n{{serverCount}} MCP {{pluralServers}} {{isAre}} currently available{{filterContext}}:\n\n{{serverList}}\n\n{{#if hasInstructionalServers}}\n## Available Capabilities\n\nAll tools from connected servers are accessible using the format: `{{toolPattern}}`\n\nExamples:\n{{#each examples}}\n- `{{name}}` - {{description}}\n{{/each}}\n\n## Server-Specific Instructions\n\nThe following sections contain instructions from each connected MCP server. Each server's instructions are wrapped in XML-like tags (e.g., `<server-name>instructions</server-name>`) to clearly identify their source and scope.\n\n{{#each servers}}\n{{#if hasInstructions}}\n<{{name}}>\n{{instructions}}\n</{{name}}>\n\n{{/if}}\n{{/each}}\n\n## Tips for Using 1MCP\n\n- Tools are namespaced by server to avoid conflicts\n\n{{else}}\n## Status\n\nConnected servers are available but have not provided instructions yet. Tools and capabilities will become available once servers provide their instructions.\n{{/if}}\n{{else}}\nYou are interacting with 1MCP, a proxy server that aggregates capabilities from multiple MCP (Model Context Protocol) servers.\n\n## Current Status\n\nNo MCP servers are currently connected. 1MCP is ready to connect to servers and provide unified access to their capabilities once they become available.\n\n## What 1MCP Provides\n\n- **Unified Access**: Connect to multiple MCP servers through one proxy\n- **Tool Aggregation**: Access tools using the pattern `{{toolPattern}}`\n- **Resource Sharing**: Share files, data, and capabilities across servers\n- **Intelligent Routing**: Automatic request routing to appropriate servers\n\n1MCP will automatically detect and connect to available MCP servers. Once connected, their tools and capabilities will become available through the unified interface.\n{{/if}}";
|
|
77
89
|
//# sourceMappingURL=templateTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateTypes.d.ts","sourceRoot":"","sources":["../../../src/core/instructions/templateTypes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IAEb,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAC;IAErB,2CAA2C;IAC3C,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAEhC,
|
|
1
|
+
{"version":3,"file":"templateTypes.d.ts","sourceRoot":"","sources":["../../../src/core/instructions/templateTypes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IAEb,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAC;IAErB,2CAA2C;IAC3C,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAEhC,wGAAwG;IACxG,WAAW,EAAE,MAAM,CAAC;IAEpB,wFAAwF;IACxF,wBAAwB,EAAE,MAAM,CAAC;IAEjC,+EAA+E;IAC/E,oBAAoB,EAAE,MAAM,CAAC;IAE7B,wEAAwE;IACxE,UAAU,EAAE,OAAO,CAAC;IAEpB,wEAAwE;IACxE,uBAAuB,EAAE,OAAO,CAAC;IAEjC,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAC;IAEnB,yDAAyD;IACzD,WAAW,EAAE,MAAM,EAAE,CAAC;IAEtB,oEAAoE;IACpE,OAAO,EAAE,UAAU,EAAE,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