csvlod-ai-mcp-server
Version:
CSVLOD-AI MCP Server v3.0 with Quantum Context Intelligence - Revolutionary Context Intelligence Engine and Multimodal Processor for sovereign AI development
82 lines • 3.28 kB
JavaScript
import { z } from 'zod';
import { execSync } from 'child_process';
export const compressAnythingTool = {
name: 'sis_compress',
description: 'Extreme compression for any text using SIS compression engine',
parameters: z.object({
input: z.string(),
target_tokens: z.number().max(1000).default(50),
preserve: z.array(z.string()).optional(),
format: z.enum(['text', 'json', 'markdown']).default('text')
}),
execute: async (args) => {
// Prepare input for shell
const escapedInput = args.input.replace(/'/g, "'\"'\"'");
// Run SIS compress
const compressed = execSync(`./.sis/bin/sis compress '${escapedInput}' ${args.target_tokens}`, { encoding: 'utf-8' });
// Parse output
const lines = compressed.split('\n');
const result = {
compressed: '',
metrics: {
original_length: 0,
compressed_length: 0,
reduction_percentage: 0,
it_score: 0
}
};
// Extract compressed text and metrics
let metricsSection = false;
for (const line of lines) {
if (line === '---') {
metricsSection = true;
continue;
}
if (!metricsSection) {
result.compressed += line + '\n';
}
else {
if (line.includes('Compression:')) {
const match = line.match(/(\d+) -> (\d+) chars \((\d+\.?\d*)% reduction\)/);
if (match) {
result.metrics.original_length = parseInt(match[1]);
result.metrics.compressed_length = parseInt(match[2]);
result.metrics.reduction_percentage = parseFloat(match[3]);
}
}
else if (line.includes('IT-Score:')) {
const match = line.match(/IT-Score:\s*([\d.]+)/);
if (match) {
result.metrics.it_score = parseFloat(match[1]);
}
}
}
}
result.compressed = result.compressed.trim();
// Apply preservation rules if specified
if (args.preserve && args.preserve.length > 0) {
for (const term of args.preserve) {
// Restore preserved terms
const regex = new RegExp(term.substring(0, 3), 'gi');
result.compressed = result.compressed.replace(regex, term);
}
}
// Format output based on requested format
switch (args.format) {
case 'json':
return {
...result,
compression_ratio: result.metrics.reduction_percentage / 100,
quality_score: result.metrics.it_score
};
case 'markdown':
return {
compressed: `> ${result.compressed}\n\n*Compressed ${result.metrics.reduction_percentage}% | IT-Score: ${result.metrics.it_score}*`,
...result.metrics
};
default:
return result;
}
}
};
//# sourceMappingURL=compress-anything.js.map