3gpp-mcp-server
Version:
MCP Server for querying 3GPP telecom protocol specifications
134 lines • 5.07 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.TSpecLLMDownloader = void 0;
const child_process_1 = require("child_process");
const fs = __importStar(require("fs-extra"));
const path = __importStar(require("path"));
class TSpecLLMDownloader {
config;
constructor(config) {
this.config = config;
}
async downloadDataset() {
const { repositoryUrl, localPath } = this.config;
try {
console.log('Checking if git-lfs is installed...');
(0, child_process_1.execSync)('git lfs version', { stdio: 'inherit' });
console.log('Creating local directory...');
await fs.ensureDir(localPath);
if (!await this.isRepoCloned()) {
console.log('Cloning TSpec-LLM dataset...');
(0, child_process_1.execSync)(`git clone ${repositoryUrl} ${localPath}`, {
stdio: 'inherit',
cwd: path.dirname(localPath)
});
}
else {
console.log('Repository already exists, pulling updates...');
(0, child_process_1.execSync)('git pull', {
stdio: 'inherit',
cwd: localPath
});
}
console.log('Dataset download completed!');
}
catch (error) {
console.error('Error downloading dataset:', error);
throw error;
}
}
async analyzeStructure() {
const { localPath } = this.config;
if (!await fs.pathExists(localPath)) {
throw new Error('Dataset not found. Please download first.');
}
const structure = {
totalFiles: 0,
releases: {},
formats: { markdown: 0, docx: 0 },
sampleFiles: []
};
const files = await this.getAllFiles(localPath);
for (const filePath of files) {
const relativePath = path.relative(localPath, filePath);
const ext = path.extname(filePath);
structure.totalFiles++;
if (ext === '.md') {
structure.formats.markdown++;
}
else if (ext === '.docx') {
structure.formats.docx++;
}
const releaseMatch = relativePath.match(/Rel-(\d+)/);
if (releaseMatch) {
const release = `Rel-${releaseMatch[1]}`;
structure.releases[release] = (structure.releases[release] || 0) + 1;
}
if (structure.sampleFiles.length < 10) {
structure.sampleFiles.push({
path: relativePath,
size: (await fs.stat(filePath)).size,
format: ext.substring(1)
});
}
}
return structure;
}
async isRepoCloned() {
try {
return await fs.pathExists(path.join(this.config.localPath, '.git'));
}
catch {
return false;
}
}
async getAllFiles(dir) {
const files = [];
const items = await fs.readdir(dir, { withFileTypes: true });
for (const item of items) {
const fullPath = path.join(dir, item.name);
if (item.isDirectory() && !item.name.startsWith('.')) {
files.push(...await this.getAllFiles(fullPath));
}
else if (item.isFile() && (item.name.endsWith('.md') || item.name.endsWith('.docx'))) {
files.push(fullPath);
}
}
return files;
}
}
exports.TSpecLLMDownloader = TSpecLLMDownloader;
//# sourceMappingURL=dataset-downloader.js.map
;