babylon-mcp/scripts/index-source.ts
Michael Mainguy e6a3329c9b Add Editor source code tools and expand indexed Babylon.js packages
Adds search_babylon_editor_source and get_babylon_editor_source MCP tools
for searching and retrieving Editor source code. Expands source indexing
to include inspector, viewer, addons, accessibility, node-editor, and
procedural-textures packages. Improves pathToDocId to handle Editor paths
and adds Editor URL construction fallback in getDocumentByPath.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 09:02:20 -06:00

55 lines
1.5 KiB
TypeScript

// MUST set environment variable before any imports that use @xenova/transformers
// This prevents onnxruntime-node from being loaded on Alpine Linux (musl libc)
if (process.env.TRANSFORMERS_BACKEND === 'wasm' || process.env.TRANSFORMERS_BACKEND === 'onnxruntime-web') {
process.env.ONNXRUNTIME_BACKEND = 'wasm';
}
import { SourceCodeIndexer } from '../src/search/source-code-indexer.js';
async function main() {
// Define packages to index
const packages = [
'core',
'gui',
'materials',
'loaders',
'serializers',
'inspector',
'inspector-v2',
'ui-controls',
'viewer',
'addons',
'accessibility',
'node-editor',
'node-particle-editor',
'procedural-textures'
];
console.log('Starting source code indexing for Babylon.js packages...');
console.log(`Indexing ${packages.length} packages:`, packages.join(', '));
console.log();
const indexer = new SourceCodeIndexer(
'./data/lancedb',
'babylon_source_code',
'./data/repositories/Babylon.js',
200, // chunk size (lines)
20 // chunk overlap (lines)
);
try {
await indexer.initialize();
await indexer.indexSourceCode(packages);
await indexer.close();
console.log('\n✓ Source code indexing completed successfully!');
} catch (error) {
console.error('Error during source code indexing:', error);
if (error instanceof Error) {
console.error('Stack trace:', error.stack);
}
process.exit(1);
}
}
main().catch(console.error);