demo-enhanced-documentation.jsβ’4.79 kB
#!/usr/bin/env node
const { EnhancedDocumentationFetcher } = require('../dist/utils/enhanced-documentation-fetcher');
async function demoEnhancedDocumentation() {
console.log('=== Enhanced Documentation Parser Demo ===\n');
console.log('This demo shows how the enhanced DocumentationFetcher extracts rich content from n8n documentation.\n');
const fetcher = new EnhancedDocumentationFetcher();
try {
// Demo 1: Slack node (complex app node with many operations)
console.log('1. SLACK NODE DOCUMENTATION');
console.log('=' .repeat(50));
const slackDoc = await fetcher.getEnhancedNodeDocumentation('n8n-nodes-base.slack');
if (slackDoc) {
console.log('\nπ Basic Information:');
console.log(` β’ Title: ${slackDoc.title}`);
console.log(` β’ Description: ${slackDoc.description}`);
console.log(` β’ URL: ${slackDoc.url}`);
console.log('\nπ Content Statistics:');
console.log(` β’ Operations: ${slackDoc.operations?.length || 0} operations across multiple resources`);
console.log(` β’ API Methods: ${slackDoc.apiMethods?.length || 0} mapped to Slack API endpoints`);
console.log(` β’ Examples: ${slackDoc.examples?.length || 0} code examples`);
console.log(` β’ Resources: ${slackDoc.relatedResources?.length || 0} related documentation links`);
console.log(` β’ Scopes: ${slackDoc.requiredScopes?.length || 0} OAuth scopes`);
// Show operations breakdown
if (slackDoc.operations && slackDoc.operations.length > 0) {
console.log('\nπ§ Operations by Resource:');
const resourceMap = new Map();
slackDoc.operations.forEach(op => {
if (!resourceMap.has(op.resource)) {
resourceMap.set(op.resource, []);
}
resourceMap.get(op.resource).push(op);
});
for (const [resource, ops] of resourceMap) {
console.log(`\n ${resource} (${ops.length} operations):`);
ops.slice(0, 5).forEach(op => {
console.log(` β’ ${op.operation}: ${op.description}`);
});
if (ops.length > 5) {
console.log(` ... and ${ops.length - 5} more`);
}
}
}
// Show API method mappings
if (slackDoc.apiMethods && slackDoc.apiMethods.length > 0) {
console.log('\nπ API Method Mappings (sample):');
slackDoc.apiMethods.slice(0, 5).forEach(api => {
console.log(` β’ ${api.resource}.${api.operation} β ${api.apiMethod}`);
console.log(` URL: ${api.apiUrl}`);
});
if (slackDoc.apiMethods.length > 5) {
console.log(` ... and ${slackDoc.apiMethods.length - 5} more mappings`);
}
}
}
// Demo 2: If node (core node with conditions)
console.log('\n\n2. IF NODE DOCUMENTATION');
console.log('=' .repeat(50));
const ifDoc = await fetcher.getEnhancedNodeDocumentation('n8n-nodes-base.if');
if (ifDoc) {
console.log('\nπ Basic Information:');
console.log(` β’ Title: ${ifDoc.title}`);
console.log(` β’ Description: ${ifDoc.description}`);
console.log(` β’ URL: ${ifDoc.url}`);
if (ifDoc.relatedResources && ifDoc.relatedResources.length > 0) {
console.log('\nπ Related Resources:');
ifDoc.relatedResources.forEach(res => {
console.log(` β’ ${res.title} (${res.type})`);
console.log(` ${res.url}`);
});
}
}
// Demo 3: Summary of enhanced parsing capabilities
console.log('\n\n3. ENHANCED PARSING CAPABILITIES');
console.log('=' .repeat(50));
console.log('\nThe enhanced DocumentationFetcher can extract:');
console.log(' β Markdown frontmatter (metadata, tags, priority)');
console.log(' β Operations with resource grouping and descriptions');
console.log(' β API method mappings from markdown tables');
console.log(' β Code examples (JSON, JavaScript, YAML)');
console.log(' β Template references');
console.log(' β Related resources and documentation links');
console.log(' β Required OAuth scopes');
console.log('\nThis rich content enables AI agents to:');
console.log(' β’ Understand node capabilities in detail');
console.log(' β’ Map operations to actual API endpoints');
console.log(' β’ Provide accurate examples and usage patterns');
console.log(' β’ Navigate related documentation');
console.log(' β’ Understand authentication requirements');
} catch (error) {
console.error('\nError:', error);
} finally {
await fetcher.cleanup();
console.log('\n\nβ Demo completed');
}
}
// Run the demo
demoEnhancedDocumentation().catch(console.error);