gaunt-sloth-assistant
Version:
[](https://github.com/Galvanized-Pukeko/gaunt-sloth-assistant/actions/workflows/unit-tests.yml) [ {
debugLog(`Creating Anthropic prompt caching middleware with TTL: ${config.ttl || 'default'}`);
// Dynamic import for async initialization
return Promise.resolve(anthropicPromptCachingMiddleware({ ttl: config.ttl }));
}
/**
* Create summarization middleware.
* This middleware automatically condenses conversation history when approaching token limits.
*
* @param config - Configuration for the middleware
* @param gthConfig - Full Gaunt Sloth configuration
* @returns Middleware object
*/
export async function createSummarizationMiddleware(config, gthConfig) {
debugLog('Creating summarization middleware');
return Promise.resolve(summarizationMiddleware({
model: config.model || gthConfig.llm,
maxTokensBeforeSummary: config.maxTokensBeforeSummary || 10000,
messagesToKeep: config.messagesToKeep,
summaryPrompt: config.summaryPrompt,
}));
}
/**
* Resolve middleware configuration into middleware instances.
* Converts string identifiers and config objects into actual middleware.
*
* @param configs - Array of middleware configurations
* @param gthConfig - Full Gaunt Sloth configuration
* @returns Array of middleware instances
*/
export async function resolveMiddleware(configs, gthConfig) {
if (!configs || configs.length === 0) {
return [];
}
const middleware = [];
// List of predefined middleware names
const predefinedNames = ['anthropic-prompt-caching', 'summarization'];
for (const config of configs) {
try {
// Handle string configuration (predefined middleware with defaults)
if (typeof config === 'string') {
middleware.push(await createPredefinedMiddleware(config, {}, gthConfig));
}
// Handle predefined middleware with custom settings
else if (typeof config === 'object' &&
'name' in config &&
// eslint-disable-next-line @typescript-eslint/no-explicit-any
predefinedNames.includes(config.name)) {
const { name, ...settings } = config;
middleware.push(await createPredefinedMiddleware(name, settings, gthConfig));
}
// Handle custom middleware object (JS config only)
else {
debugLog('Adding custom middleware');
middleware.push(config);
}
}
catch (error) {
displayWarning(`Failed to create middleware: ${error instanceof Error ? error.message : String(error)}`);
}
}
return middleware;
}
/**
* Create a predefined middleware instance by name.
*
* @param name - Name of the predefined middleware
* @param settings - Configuration settings for the middleware
* @param gthConfig - Full Gaunt Sloth configuration
* @returns Middleware instance
*/
async function createPredefinedMiddleware(name, settings, gthConfig) {
switch (name) {
case 'anthropic-prompt-caching':
return createAnthropicPromptCachingMiddleware(settings, gthConfig);
case 'summarization':
return createSummarizationMiddleware(settings, gthConfig);
default:
throw new Error(`Unknown predefined middleware: ${name}`);
}
}
//# sourceMappingURL=registry.js.map